src/canvas.cpp

changeset 1437
1a77c6156db7
parent 1436
241d3e452b32
equal deleted inserted replaced
1436:241d3e452b32 1437:1a77c6156db7
22 #include "lddocument.h" 22 #include "lddocument.h"
23 #include "primitives.h" 23 #include "primitives.h"
24 #include "algorithms/geometry.h" 24 #include "algorithms/geometry.h"
25 #include "generics/ring.h" 25 #include "generics/ring.h"
26 26
27 Canvas::Canvas(LDDocument* document, QWidget* parent) : 27 Canvas::Canvas(LDDocument* document, gl::CameraType cameraType, QWidget* parent) :
28 gl::Renderer {document, parent}, 28 gl::Renderer {document, cameraType, parent},
29 m_document {*document}, 29 m_document {*document},
30 m_currentEditMode {AbstractEditMode::createByType (this, EditModeType::Select)} {} 30 m_currentEditMode {AbstractEditMode::createByType (this, EditModeType::Select)} {}
31 31
32 Canvas::~Canvas() 32 Canvas::~Canvas()
33 { 33 {
37 void Canvas::overpaint(QPainter& painter) 37 void Canvas::overpaint(QPainter& painter)
38 { 38 {
39 gl::Renderer::overpaint(painter); 39 gl::Renderer::overpaint(painter);
40 QFontMetrics metrics {QFont {}}; 40 QFontMetrics metrics {QFont {}};
41 41
42 if (camera() != gl::FreeCamera) 42 if (not currentCamera().isModelview())
43 { 43 {
44 // Paint the coordinates onto the screen. 44 // Paint the coordinates onto the screen.
45 Vertex idealized = currentCamera().idealize(m_position3D); 45 Vertex idealized = currentCamera().idealize(m_position3D);
46 QString text = format(tr("X: %1, Y: %2, Z: %3, %4"), m_position3D[X], m_position3D[Y], m_position3D[Z], 46 QString text = format(tr("X: %1, Y: %2, Z: %3, %4"), m_position3D[X], m_position3D[Y], m_position3D[Z],
47 idealized.toString(true)); 47 idealized.toString(true));
184 } 184 }
185 185
186 glEnd(); 186 glEnd();
187 glDisable(GL_LINE_STIPPLE); 187 glDisable(GL_LINE_STIPPLE);
188 188
189 if (this->camera() < gl::FreeCamera) 189 if (not currentCamera().isModelview())
190 { 190 {
191 GLfloat cullz = this->cullValues[static_cast<int>(this->camera())]; 191 GLfloat cullz = this->cullValue;
192 QMatrix4x4 matrix = { 192 QMatrix4x4 const matrix = {
193 1, 0, 0, cullz, 193 1, 0, 0, cullz,
194 0, 1, 0, 0, 194 0, 1, 0, 0,
195 0, 0, 1, 0, 195 0, 0, 1, 0,
196 0, 0, 0, 1, 196 0, 0, 0, 1,
197 }; 197 };
209 if (m_currentEditMode and m_currentEditMode->type() == a) 209 if (m_currentEditMode and m_currentEditMode->type() == a)
210 return; 210 return;
211 211
212 delete m_currentEditMode; 212 delete m_currentEditMode;
213 m_currentEditMode = AbstractEditMode::createByType(this, a); 213 m_currentEditMode = AbstractEditMode::createByType(this, a);
214
215 // If we cannot use the free camera, use the top one instead.
216 if (camera() == gl::FreeCamera and not m_currentEditMode->allowFreeCamera())
217 setCamera(gl::TopCamera);
218
219 m_window->updateEditModeActions(); 214 m_window->updateEditModeActions();
220 update(); 215 update();
221 } 216 }
222 217
223 EditModeType Canvas::currentEditModeType() const 218 EditModeType Canvas::currentEditModeType() const
372 */ 367 */
373 } 368 }
374 369
375 double Canvas::currentCullValue() const 370 double Canvas::currentCullValue() const
376 { 371 {
377 if (this->camera() < gl::FreeCamera) 372 return gl::far - this->cullValue;
378 return gl::far - this->cullValues[static_cast<int>(this->camera())];
379 else
380 return 0.0;
381 } 373 }
382 374
383 void Canvas::setCullValue(double value) 375 void Canvas::setCullValue(double value)
384 { 376 {
385 if (this->camera() < gl::FreeCamera) 377 this->cullValue = gl::far - value;
386 this->cullValues[static_cast<int>(this->camera())] = gl::far - value;
387 } 378 }
388 379
389 void Canvas::clearCurrentCullValue() 380 void Canvas::clearCurrentCullValue()
390 { 381 {
391 if (this->camera() < gl::FreeCamera) 382 this->cullValue = 0.0;
392 this->cullValues[static_cast<int>(this->camera())] = 0.0; 383 }
393 }

mercurial