src/toolsets/viewtoolset.cpp

changeset 1390
3eace926af7f
parent 1369
1e2391b78d17
child 1436
241d3e452b32
equal deleted inserted replaced
1389:3fb8ad4d27b1 1390:3eace926af7f
24 #include "../canvas.h" 24 #include "../canvas.h"
25 #include "../primitives.h" 25 #include "../primitives.h"
26 #include "../colors.h" 26 #include "../colors.h"
27 #include "../glcompiler.h" 27 #include "../glcompiler.h"
28 #include "../documentmanager.h" 28 #include "../documentmanager.h"
29 #include "../linetypes/quadrilateral.h"
29 #include "viewtoolset.h" 30 #include "viewtoolset.h"
30 31
31 ViewToolset::ViewToolset (MainWindow *parent) : 32 ViewToolset::ViewToolset (MainWindow *parent) :
32 Toolset (parent) {} 33 Toolset (parent) {}
33 34
166 { 167 {
167 config::toggleDrawAngles(); 168 config::toggleDrawAngles();
168 m_window->renderer()->update(); 169 m_window->renderer()->update();
169 } 170 }
170 171
171 void ViewToolset::setDrawDepth() 172 /*
172 { 173 * If the given object is within a single plane, returns that plane.
173 if (m_window->renderer()->camera() == Camera::Free) 174 * Should probably be smarter than this.
174 return; 175 */
175 176 static Plane drawPlaneFromObject(LDObject* object)
176 bool ok; 177 {
177 double depth = QInputDialog::getDouble( 178 switch (object->type())
178 m_window, 179 {
179 tr("Set draw depth"), 180 case LDObjectType::Quadrilateral:
180 format( 181 if (not static_cast<LDQuadrilateral*>(object)->isCoPlanar())
181 tr("Depth value for %1:"), 182 return {};
182 m_window->renderer()->currentCamera().name() 183 case LDObjectType::Triangle:
183 ), 184 return Plane::fromPoints(object->vertex(0), object->vertex(1), object->vertex(2));
184 m_window->renderer()->getDepthValue(), 185
185 -10000.0f, 186 default:
186 10000.0f, 187 return {};
187 4, 188 }
188 &ok 189 }
189 ); 190
190 191 void ViewToolset::setDrawPlane()
191 if (ok) 192 {
192 m_window->renderer()->setDepthValue(depth); 193 QSet<LDObject*> objects = selectedObjects();
194
195 if (objects.size() == 1)
196 {
197 LDObject* object = *objects.begin();
198 Plane plane = drawPlaneFromObject(object);
199
200 if (plane.isValid())
201 {
202 m_window->renderer()->setDrawPlane(plane);
203 }
204 else
205 {
206 QMessageBox::critical(
207 m_window,
208 tr("Error"),
209 tr("This object does not define a single plane"),
210 QMessageBox::Ok,
211 QMessageBox::Ok);
212 }
213 }
214 }
215
216 void ViewToolset::clearDrawPlane()
217 {
218 m_window->renderer()->setDrawPlane({});
193 } 219 }
194 220
195 void ViewToolset::setCullDepth() 221 void ViewToolset::setCullDepth()
196 { 222 {
197 if (m_window->renderer()->camera() == Camera::Free) 223 if (m_window->renderer()->camera() == Camera::Free)

mercurial