1 | #include "ProjectionModel.h" |
---|
2 | #include <QMessageBox> |
---|
3 | #include <QGLPixelBuffer> |
---|
4 | |
---|
5 | #include "Scene.h" |
---|
6 | #include "Screen.h" |
---|
7 | #include "Channel.h" |
---|
8 | #pragma warning(disable: 4003) |
---|
9 | #include "gmtl/gmtl.h" |
---|
10 | #include "gui/QDesignViewWidget.h" |
---|
11 | |
---|
12 | using namespace projection; |
---|
13 | using namespace gmtl; |
---|
14 | |
---|
15 | QDesignViewWidget::QDesignViewWidget(QWidget* pParent, const QGLWidget* pSharedWidget, Qt::WFlags flags) |
---|
16 | : QGLViewerWidget(pParent, pSharedWidget, flags) |
---|
17 | { |
---|
18 | m_pModel = NULL; |
---|
19 | |
---|
20 | m_viewMode = DESIGN_VIEWMODE_PERSPECTIVE; |
---|
21 | m_opMode = DESIGN_OPMODE_PROJECTOR; |
---|
22 | m_transMode = DESIGN_TRANSMODE_LOCAL; |
---|
23 | |
---|
24 | m_bAxisVisible = true; |
---|
25 | m_bGridVisible = true; |
---|
26 | m_bInfoVisible = true; |
---|
27 | |
---|
28 | m_gridSize = 2.0f; |
---|
29 | |
---|
30 | m_infoFont.setFamily("Helvetica"); |
---|
31 | m_infoFont.setPointSize(14); |
---|
32 | |
---|
33 | if (!QGLPixelBuffer::hasOpenGLPbuffers()) |
---|
34 | QMessageBox::critical(this, APPLICATION_NAME, |
---|
35 | tr("%1 requires OpenGL P-Buffer feature.").arg(APPLICATION_NAME)); |
---|
36 | } |
---|
37 | |
---|
38 | void QDesignViewWidget::init() |
---|
39 | { |
---|
40 | } |
---|
41 | |
---|
42 | QDesignViewWidget::~QDesignViewWidget() |
---|
43 | { |
---|
44 | } |
---|
45 | |
---|
46 | void QDesignViewWidget::setModel(ProjectionModel* pModel) |
---|
47 | { |
---|
48 | m_pModel = pModel; |
---|
49 | |
---|
50 | setSceneSize(m_pModel->getScreen()->getSize() * 5.0f); |
---|
51 | setView(Vec3f(), |
---|
52 | makeRot<Quatf>(AxisAnglef(Math::deg2Rad(45.0f), Vec3f(0.0f, 1.0f, 0.0f))) * |
---|
53 | makeRot<Quatf>(AxisAnglef(Math::deg2Rad(-30.0f), Vec3f(1.0f, 0.0f, 0.0f))), |
---|
54 | sceneSize()*0.5f); |
---|
55 | } |
---|
56 | |
---|
57 | void QDesignViewWidget::draw() |
---|
58 | { |
---|
59 | if (!isVisible()) return; |
---|
60 | |
---|
61 | m_pModel->setRenderContext(this); |
---|
62 | |
---|
63 | m_sceneSize = m_pModel->getScreen()->getSize() * 5.0f; |
---|
64 | |
---|
65 | glViewport(0, 0, width(), height()); |
---|
66 | |
---|
67 | glEnable(GL_COLOR_MATERIAL); |
---|
68 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
69 | |
---|
70 | if (m_pModel->getScene()->getShowInDesignView()) |
---|
71 | { |
---|
72 | glPushMatrix(); |
---|
73 | |
---|
74 | // |
---|
75 | // Sigh: Too clever. Split this line in two. [ben 27Sep13] |
---|
76 | // glMultMatrixf(invert(m_pModel->getScene()->getCameraMatrix()).getData()); |
---|
77 | // |
---|
78 | gmtl::Matrix<float, 4u, 4u> a = m_pModel->getScene()->getCameraMatrix(); |
---|
79 | glMultMatrixf(invert(a).getData()); |
---|
80 | |
---|
81 | |
---|
82 | m_pModel->getScene()->draw(); |
---|
83 | glPopMatrix(); |
---|
84 | } |
---|
85 | |
---|
86 | glPushMatrix(); |
---|
87 | m_pModel->getScreen()->draw(); |
---|
88 | m_pModel->getScreen()->drawFrame(); |
---|
89 | for (unsigned int i=0; i<m_pModel->getNumChannels(); ++i) |
---|
90 | { |
---|
91 | if (m_pModel->getChannel(i)->getProjector()->getShowArea()) |
---|
92 | m_pModel->getScreen()->draw(PROJECT_SOURCE_PROJECTORAREA, m_pModel->getChannel(i)); |
---|
93 | if (m_pModel->getChannel(i)->getView()->getShowArea()) |
---|
94 | m_pModel->getScreen()->draw(PROJECT_SOURCE_VIEWAREA, m_pModel->getChannel(i)); |
---|
95 | if (m_pModel->getChannel(i)->getShowProjectedScene()) |
---|
96 | m_pModel->getScreen()->draw(PROJECT_SOURCE_SCENE, m_pModel->getChannel(i)); |
---|
97 | makeCurrent(); |
---|
98 | } |
---|
99 | glPopMatrix(); |
---|
100 | |
---|
101 | for (unsigned int i=0; i<m_pModel->getNumChannels(); ++i) |
---|
102 | { |
---|
103 | glPushMatrix(); |
---|
104 | m_pModel->getChannel(i)->drawFrustums(m_pModel->getChannel(i)==m_pModel->getSelectedChannel()); |
---|
105 | glPopMatrix(); |
---|
106 | } |
---|
107 | |
---|
108 | glPushAttrib(GL_ENABLE_BIT); |
---|
109 | glDisable(GL_LIGHTING); |
---|
110 | for (unsigned int i=0; i<m_pModel->getNumChannels(); ++i) |
---|
111 | { |
---|
112 | if (m_pModel->getChannel(i)->getProjector()->getShow()) |
---|
113 | { |
---|
114 | glPushMatrix(); |
---|
115 | glMultMatrixf(m_pModel->getChannel(i)->getProjectorTransformMatrix().getMatrix().getData()); |
---|
116 | glTranslatef(0.0f, 0.0f, 0.05f); |
---|
117 | renderText(0, 0, 0, m_pModel->getChannel(i)->getName(), m_infoFont, 5000); |
---|
118 | glPopMatrix(); |
---|
119 | } |
---|
120 | if (m_pModel->getChannel(i)->getView()->getShow()) |
---|
121 | { |
---|
122 | glPushMatrix(); |
---|
123 | glMultMatrixf(m_pModel->getChannel(i)->getView()->getTransformMatrix().getMatrix().getData()); |
---|
124 | glTranslatef(0.0f, 0.0f, 0.05f); |
---|
125 | renderText(0, 0, 0, m_pModel->getChannel(i)->getName(), m_infoFont, 5000); |
---|
126 | glPopMatrix(); |
---|
127 | } |
---|
128 | } |
---|
129 | glPopAttrib(); |
---|
130 | |
---|
131 | if (m_bInfoVisible) |
---|
132 | { |
---|
133 | glDisable(GL_LIGHTING); |
---|
134 | |
---|
135 | int x = int(m_infoFont.pointSize() * 0.5); |
---|
136 | int y = int(m_infoFont.pointSize() * 1.5); |
---|
137 | int yoffset = int(m_infoFont.pointSize() * 1.5); |
---|
138 | switch (m_viewMode) |
---|
139 | { |
---|
140 | case DESIGN_VIEWMODE_PERSPECTIVE: |
---|
141 | renderText(x, y, QString("View Mode: Perspective"), m_infoFont); y += yoffset; break; |
---|
142 | case DESIGN_VIEWMODE_CENTER: |
---|
143 | renderText(x, y, QString("View Mode: Center"), m_infoFont); y += yoffset; break; |
---|
144 | case DESIGN_VIEWMODE_TOP: |
---|
145 | renderText(x, y, QString("View Mode: Top"), m_infoFont); y += yoffset; break; |
---|
146 | case DESIGN_VIEWMODE_SIDE: |
---|
147 | renderText(x, y, QString("View Mode: Side"), m_infoFont); y += yoffset; break; |
---|
148 | case DESIGN_VIEWMODE_FRONT: |
---|
149 | renderText(x, y, QString("View Mode: Front"), m_infoFont); y += yoffset; break; |
---|
150 | } |
---|
151 | renderText(x, y, QString("Operation Mode: %1").arg(m_opMode==DESIGN_OPMODE_PROJECTOR?"Projector":"View"), m_infoFont); y += yoffset; |
---|
152 | renderText(x, y, QString("Translation Mode: %1").arg(m_transMode==DESIGN_TRANSMODE_LOCAL?"Local":"World"), m_infoFont); y += yoffset; |
---|
153 | if (m_pModel->getSelectedChannel()) |
---|
154 | renderText(x, y, QString("Channel: %1").arg(m_pModel->getSelectedChannel()->getName()), m_infoFont); y += yoffset; |
---|
155 | |
---|
156 | #ifdef _DEBUG |
---|
157 | renderText(x, y, QString("UpdateViews: %1").arg(m_pModel->m_updateViewsCount), m_infoFont); y += yoffset; |
---|
158 | renderText(x, y, QString("UpdateOffscreen: %1").arg(m_pModel->m_updateOffscreenCount), m_infoFont); y += yoffset; |
---|
159 | #endif // _DEBUG |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | void QDesignViewWidget::setViewMode(DESIGN_VIEWMODE viewMode) |
---|
164 | { |
---|
165 | if (m_viewMode == viewMode) |
---|
166 | return; |
---|
167 | |
---|
168 | if (viewMode == DESIGN_VIEWMODE_PERSPECTIVE) |
---|
169 | { |
---|
170 | setPerspective(true); |
---|
171 | viewAll(); |
---|
172 | } |
---|
173 | else if (viewMode == DESIGN_VIEWMODE_CENTER) |
---|
174 | { |
---|
175 | setPerspective(true); |
---|
176 | setView(Vec3f(), Quatf(), 0.0f); |
---|
177 | } |
---|
178 | else |
---|
179 | { |
---|
180 | switch (viewMode) |
---|
181 | { |
---|
182 | case DESIGN_VIEWMODE_TOP: |
---|
183 | setView(Vec3f(), makeRot<Quatf>(AxisAnglef(Math::deg2Rad(-90.0f), Vec3f(1.0f, 0.0f, 0.0f))), 0.0f); |
---|
184 | break; |
---|
185 | case DESIGN_VIEWMODE_SIDE: |
---|
186 | setView(Vec3f(), makeRot<Quatf>(AxisAnglef(Math::deg2Rad(90.0f), Vec3f(0.0f, 1.0f, 0.0f))), 0.0f); |
---|
187 | break; |
---|
188 | case DESIGN_VIEWMODE_FRONT: |
---|
189 | setView(Vec3f(), Quatf(), 0.0f); |
---|
190 | break; |
---|
191 | // |
---|
192 | // Handle Missing Cases. Not sure. Maybe do nothing, or do FRONT mode? |
---|
193 | // [ben 27Sep13] |
---|
194 | // |
---|
195 | case DESIGN_VIEWMODE_PERSPECTIVE: |
---|
196 | case DESIGN_VIEWMODE_CENTER: |
---|
197 | default: |
---|
198 | // setView(Vec3f(), Quatf(), 0.0f); |
---|
199 | break;; |
---|
200 | } |
---|
201 | setPerspective(false); |
---|
202 | viewAll(); |
---|
203 | } |
---|
204 | |
---|
205 | m_viewMode = viewMode; |
---|
206 | |
---|
207 | updateGL(); |
---|
208 | } |
---|
209 | |
---|
210 | DESIGN_VIEWMODE QDesignViewWidget::getViewMode() const |
---|
211 | { |
---|
212 | return m_viewMode; |
---|
213 | } |
---|
214 | |
---|
215 | void QDesignViewWidget::setOpMode(DESIGN_OPMODE opMode) |
---|
216 | { |
---|
217 | m_opMode = opMode; |
---|
218 | updateGL(); |
---|
219 | } |
---|
220 | |
---|
221 | DESIGN_OPMODE QDesignViewWidget::getOpMode() const |
---|
222 | { |
---|
223 | return m_opMode; |
---|
224 | } |
---|
225 | |
---|
226 | void QDesignViewWidget::setTransMode(DESIGN_TRANSMODE transMode) |
---|
227 | { |
---|
228 | m_transMode = transMode; |
---|
229 | updateGL(); |
---|
230 | } |
---|
231 | |
---|
232 | DESIGN_TRANSMODE QDesignViewWidget::getTransMode() const |
---|
233 | { |
---|
234 | return m_transMode; |
---|
235 | } |
---|
236 | |
---|
237 | void QDesignViewWidget::setInfoVisible(bool bVisible) |
---|
238 | { |
---|
239 | if (m_bInfoVisible != bVisible) |
---|
240 | { |
---|
241 | m_bInfoVisible = bVisible; |
---|
242 | updateGL(); |
---|
243 | infoVisibilityChanged(bVisible); |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | bool QDesignViewWidget::isInfoVisible() const |
---|
248 | { |
---|
249 | return m_bInfoVisible; |
---|
250 | } |
---|
251 | |
---|
252 | void QDesignViewWidget::keyReleaseEvent(QKeyEvent* pEvent) |
---|
253 | { |
---|
254 | QGLViewerWidget::keyReleaseEvent(pEvent); |
---|
255 | |
---|
256 | switch (pEvent->key()) |
---|
257 | { |
---|
258 | case Qt::Key_I: |
---|
259 | setInfoVisible(!isInfoVisible()); |
---|
260 | break; |
---|
261 | case Qt::Key_F1: |
---|
262 | setViewMode(DESIGN_VIEWMODE_PERSPECTIVE); |
---|
263 | break; |
---|
264 | case Qt::Key_F2: |
---|
265 | setViewMode(DESIGN_VIEWMODE_CENTER); |
---|
266 | break; |
---|
267 | case Qt::Key_F3: |
---|
268 | setViewMode(DESIGN_VIEWMODE_TOP); |
---|
269 | break; |
---|
270 | case Qt::Key_F4: |
---|
271 | setViewMode(DESIGN_VIEWMODE_SIDE); |
---|
272 | break; |
---|
273 | case Qt::Key_F5: |
---|
274 | setViewMode(DESIGN_VIEWMODE_FRONT); |
---|
275 | break; |
---|
276 | case Qt::Key_Space: |
---|
277 | m_pModel->selectNextChannel(); |
---|
278 | break; |
---|
279 | default: |
---|
280 | break; |
---|
281 | } |
---|
282 | |
---|
283 | if (!m_pModel->getSelectedChannel()) |
---|
284 | return; |
---|
285 | |
---|
286 | processChannelKeyEvent(m_pModel->getSelectedChannel(), pEvent); |
---|
287 | } |
---|
288 | |
---|
289 | void QDesignViewWidget::processChannelKeyEvent(Channel* pChannel, QKeyEvent* pEvent) |
---|
290 | { |
---|
291 | #if 1 |
---|
292 | Q_UNUSED(pChannel); |
---|
293 | Q_UNUSED(pEvent); |
---|
294 | #else |
---|
295 | if (!pChannel) |
---|
296 | return; |
---|
297 | |
---|
298 | bool bShift = (pEvent->modifiers() & Qt::ShiftModifier); |
---|
299 | #ifdef WIN32 |
---|
300 | bShift = (GetAsyncKeyState(VK_SHIFT)<0); |
---|
301 | #endif // WIN32 |
---|
302 | bool bCtrl = (pEvent->modifiers() & Qt::ControlModifier); |
---|
303 | // bool bAlt = (pEvent->modifiers() & Qt::AltModifier); |
---|
304 | bool bKeypad = (pEvent->modifiers() & Qt::KeypadModifier); |
---|
305 | #ifdef WIN32 |
---|
306 | bool bCapsLock = false; // <-- Careful, bCapsLock is not used. |
---|
307 | bCapsLock = (GetAsyncKeyState(VK_CAPITAL) < 0); |
---|
308 | #endif // WIN32 |
---|
309 | |
---|
310 | float step = 1.0f; |
---|
311 | if (bShift && bCtrl) |
---|
312 | step = 0.01f; |
---|
313 | else if (bShift || bCtrl) |
---|
314 | step = 0.1f; |
---|
315 | |
---|
316 | Frustum* pFrustum = pChannel->getProjector(); |
---|
317 | if (m_opMode == DESIGN_OPMODE_VIEW) |
---|
318 | pFrustum = pChannel->getView(); |
---|
319 | |
---|
320 | ProjectionMatrix projMatrix = pFrustum->getProjectionMatrix(); |
---|
321 | TransformMatrix xformMatrix = pFrustum->getTransformMatrix(); |
---|
322 | gmtl::Vec3f pos = xformMatrix.getPosition(); |
---|
323 | gmtl::Vec3f rot = xformMatrix.getRotation(); |
---|
324 | gmtl::Quatf quatRot = gmtl::makeRot<gmtl::Quatf>(xformMatrix.getMatrix()); |
---|
325 | |
---|
326 | if (bKeypad) |
---|
327 | { |
---|
328 | switch (pEvent->key()) |
---|
329 | { |
---|
330 | case Qt::Key_8: |
---|
331 | case Qt::Key_Up: |
---|
332 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
333 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1], pos[2]-0.1f*step)); |
---|
334 | else |
---|
335 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(0.0f, 0.0f, -0.1f*step)); |
---|
336 | pFrustum->setTransformMatrix(xformMatrix); |
---|
337 | break; |
---|
338 | case Qt::Key_2: |
---|
339 | case Qt::Key_Down: |
---|
340 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
341 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1], pos[2]+0.1f*step)); |
---|
342 | else |
---|
343 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(0.0f, 0.0f, 0.1f*step)); |
---|
344 | pFrustum->setTransformMatrix(xformMatrix); |
---|
345 | break; |
---|
346 | case Qt::Key_6: |
---|
347 | case Qt::Key_Right: |
---|
348 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
349 | xformMatrix.setPosition(gmtl::Vec3f(pos[0]+0.1f*step, pos[1], pos[2])); |
---|
350 | else |
---|
351 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(0.1f*step, 0.0f, 0.0f)); |
---|
352 | pFrustum->setTransformMatrix(xformMatrix); |
---|
353 | break; |
---|
354 | case Qt::Key_4: |
---|
355 | case Qt::Key_Left: |
---|
356 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
357 | xformMatrix.setPosition(gmtl::Vec3f(pos[0]-0.1f*step, pos[1], pos[2])); |
---|
358 | else |
---|
359 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(-0.1f*step, 0.0f, 0.0f)); |
---|
360 | pFrustum->setTransformMatrix(xformMatrix); |
---|
361 | break; |
---|
362 | case Qt::Key_9: |
---|
363 | case Qt::Key_PageUp: |
---|
364 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
365 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1]+0.1f*step, pos[2])); |
---|
366 | else |
---|
367 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(0.0f, 0.1f*step, 0.0f)); |
---|
368 | pFrustum->setTransformMatrix(xformMatrix); |
---|
369 | break; |
---|
370 | case Qt::Key_3: |
---|
371 | case Qt::Key_PageDown: |
---|
372 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
373 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1]-0.1f*step, pos[2])); |
---|
374 | else |
---|
375 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(0.0f, -0.1f*step, 0.0f)); |
---|
376 | pFrustum->setTransformMatrix(xformMatrix); |
---|
377 | break; |
---|
378 | case Qt::Key_Plus: |
---|
379 | projMatrix.setOffaxisY(projMatrix.getOffaxisY()-0.01f*step); |
---|
380 | pFrustum->setProjectionMatrix(projMatrix); |
---|
381 | break; |
---|
382 | case Qt::Key_Minus: |
---|
383 | projMatrix.setOffaxisY(projMatrix.getOffaxisY()+0.01f*step); |
---|
384 | pFrustum->setProjectionMatrix(projMatrix); |
---|
385 | break; |
---|
386 | case Qt::Key_Asterisk: |
---|
387 | projMatrix.setOffaxisX(projMatrix.getOffaxisX()+0.01f*step); |
---|
388 | pFrustum->setProjectionMatrix(projMatrix); |
---|
389 | break; |
---|
390 | case Qt::Key_Slash: |
---|
391 | projMatrix.setOffaxisX(projMatrix.getOffaxisX()-0.01f*step); |
---|
392 | pFrustum->setProjectionMatrix(projMatrix); |
---|
393 | break; |
---|
394 | } |
---|
395 | } |
---|
396 | else |
---|
397 | { |
---|
398 | switch (pEvent->key()) |
---|
399 | { |
---|
400 | case Qt::Key_PageUp: |
---|
401 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1]+0.1f*step, pos[2])); |
---|
402 | pFrustum->setTransformMatrix(xformMatrix); |
---|
403 | break; |
---|
404 | case Qt::Key_PageDown: |
---|
405 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1]-0.1f*step, pos[2])); |
---|
406 | pFrustum->setTransformMatrix(xformMatrix); |
---|
407 | break; |
---|
408 | case Qt::Key_Left: |
---|
409 | xformMatrix.setRotation(gmtl::Vec3f(rot[0]+1.0f*step, rot[1], rot[2])); |
---|
410 | pFrustum->setTransformMatrix(xformMatrix); |
---|
411 | break; |
---|
412 | case Qt::Key_Right: |
---|
413 | xformMatrix.setRotation(gmtl::Vec3f(rot[0]-1.0f*step, rot[1], rot[2])); |
---|
414 | pFrustum->setTransformMatrix(xformMatrix); |
---|
415 | break; |
---|
416 | case Qt::Key_Up: |
---|
417 | xformMatrix.setRotation(gmtl::Vec3f(rot[0], rot[1]+1.0f*step, rot[2])); |
---|
418 | pFrustum->setTransformMatrix(xformMatrix); |
---|
419 | break; |
---|
420 | case Qt::Key_Down: |
---|
421 | xformMatrix.setRotation(gmtl::Vec3f(rot[0], rot[1]-1.0f*step, rot[2])); |
---|
422 | pFrustum->setTransformMatrix(xformMatrix); |
---|
423 | break; |
---|
424 | case Qt::Key_Home: |
---|
425 | xformMatrix.setRotation(gmtl::Vec3f(rot[0], rot[1], rot[2]-1.0f*step)); |
---|
426 | pFrustum->setTransformMatrix(xformMatrix); |
---|
427 | break; |
---|
428 | case Qt::Key_End: |
---|
429 | xformMatrix.setRotation(gmtl::Vec3f(rot[0], rot[1], rot[2]+1.0f*step)); |
---|
430 | pFrustum->setTransformMatrix(xformMatrix); |
---|
431 | break; |
---|
432 | case Qt::Key_Comma: |
---|
433 | projMatrix.setFOV(projMatrix.getFOV()-1.0f*step); |
---|
434 | pFrustum->setProjectionMatrix(projMatrix); |
---|
435 | break; |
---|
436 | case Qt::Key_Period: |
---|
437 | projMatrix.setFOV(projMatrix.getFOV()+1.0f*step); |
---|
438 | pFrustum->setProjectionMatrix(projMatrix); |
---|
439 | break; |
---|
440 | case Qt::Key_Q: |
---|
441 | if (m_opMode == DESIGN_OPMODE_PROJECTOR) |
---|
442 | setOpMode(DESIGN_OPMODE_VIEW); |
---|
443 | else |
---|
444 | setOpMode(DESIGN_OPMODE_PROJECTOR); |
---|
445 | break; |
---|
446 | case Qt::Key_T: |
---|
447 | if (m_transMode == DESIGN_TRANSMODE_LOCAL) |
---|
448 | setTransMode(DESIGN_TRANSMODE_WORLD); |
---|
449 | else |
---|
450 | setTransMode(DESIGN_TRANSMODE_LOCAL); |
---|
451 | break; |
---|
452 | } |
---|
453 | } |
---|
454 | #endif |
---|
455 | } |
---|
456 | |
---|
457 | void QDesignViewWidget::initFromDOMElement(const QDomElement& element) |
---|
458 | { |
---|
459 | QGLViewerWidget::initFromDOMElement(element); |
---|
460 | |
---|
461 | QDomElement display = element.firstChildElement("Display"); |
---|
462 | if (!display.isNull()) { |
---|
463 | QString viewMode = display.attribute("viewMode", "projector"); |
---|
464 | if (viewMode == "perspective") |
---|
465 | m_viewMode = DESIGN_VIEWMODE_PERSPECTIVE; |
---|
466 | else if (viewMode == "center") |
---|
467 | m_viewMode = DESIGN_VIEWMODE_CENTER; |
---|
468 | else if (viewMode == "top") |
---|
469 | m_viewMode = DESIGN_VIEWMODE_TOP; |
---|
470 | else if (viewMode == "side") |
---|
471 | m_viewMode = DESIGN_VIEWMODE_SIDE; |
---|
472 | else if (viewMode == "front") |
---|
473 | m_viewMode = DESIGN_VIEWMODE_FRONT; |
---|
474 | if (display.attribute("opMode", "projector")=="projector") |
---|
475 | m_opMode = DESIGN_OPMODE_PROJECTOR; |
---|
476 | else |
---|
477 | m_opMode = DESIGN_OPMODE_VIEW; |
---|
478 | if (display.attribute("transMode", "local")=="local") |
---|
479 | m_transMode = DESIGN_TRANSMODE_LOCAL; |
---|
480 | else |
---|
481 | m_transMode = DESIGN_TRANSMODE_WORLD; |
---|
482 | m_bInfoVisible = (display.attribute("info", "true")=="true"); |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | QDomElement QDesignViewWidget::domElement(QDomDocument& doc) const |
---|
487 | { |
---|
488 | QDomElement de = QGLViewerWidget::domElement("DesignView", doc); |
---|
489 | QDomElement display = de.firstChildElement("Display"); |
---|
490 | if (!display.isNull()) { |
---|
491 | switch (m_viewMode) { |
---|
492 | case DESIGN_VIEWMODE_PERSPECTIVE: display.setAttribute("viewMode", "perspective"); break; |
---|
493 | case DESIGN_VIEWMODE_CENTER: display.setAttribute("viewMode", "center"); break; |
---|
494 | case DESIGN_VIEWMODE_TOP: display.setAttribute("viewMode", "top"); break; |
---|
495 | case DESIGN_VIEWMODE_SIDE: display.setAttribute("viewMode", "side"); break; |
---|
496 | case DESIGN_VIEWMODE_FRONT: display.setAttribute("viewMode", "front"); break; |
---|
497 | } |
---|
498 | display.setAttribute("opMode", m_opMode==DESIGN_OPMODE_PROJECTOR?"projector":"view"); |
---|
499 | display.setAttribute("transMode", m_transMode==DESIGN_TRANSMODE_LOCAL?"local":"world"); |
---|
500 | display.setAttribute("info", m_bInfoVisible?"true":"false"); |
---|
501 | } |
---|
502 | return de; |
---|
503 | } |
---|