Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYModelerFrame.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
22 #include "models/common/3d.h"
23 #include <qvector3d.h>
24 #ifdef _MSC_VER
25  #pragma warning(disable : 4503)
26 #endif
27 
28 #include <math.h>
29 #include <qlayout.h>
30 #include <qstring.h>
31 #include <qcursor.h>
32 #include <qcombobox.h>
33 #include <qcheckbox.h>
34 #include <qlineedit.h>
35 #include <qstatusbar.h>
36 #include <qimage.h>
37 #include <qpixmap.h>
38 #include <qmenu.h>
39 #include <qfiledialog.h>
40 #include <qslider.h>
41 #include <qlabel.h>
42 #include <qprinter.h>
43 #include <qpainter.h>
44 #include <qgroupbox.h>
45 #include <qclipboard.h>
46 #include <qmessagebox.h>
47 #include <qtoolbutton.h>
48 // Added by qt3to4:
49 #include <QResizeEvent>
50 #include <QWheelEvent>
51 #include <QFocusEvent>
52 #include <QMouseEvent>
53 #include <QCloseEvent>
54 #include <QGridLayout>
55 #include <QShowEvent>
56 #include <QKeyEvent>
57 #include <QHBoxLayout>
58 #include <QEvent>
59 #include <QImageWriter>
60 #include <QPrintDialog>
61 
89 #include "TYModelerFrame.h"
90 
91 #define TR(id) OLocalizator::getString("TYModelerFrame", (id))
92 #define IMG(id) OLocalizator::getPicture("TYModelerFrame", (id))
93 
94 // using namespace Qt;
95 
96 // Couleurs
97 static double gridColor[] = {0.59, 0.41, 0.42};
98 static double fontColor[] = {0.1, 0.43, 0.37};
99 static double rendererColor[] = {0.91, 0.91, 0.91};
100 
101 TYModelerFrame::TYModelerFrame(QWidget* parent, const char* name, Qt::WindowFlags f)
102  : QWidget(parent, f), _actionManager(10)
103 {
104  setObjectName(name);
105 
106  setAttribute(Qt::WA_DeleteOnClose);
107 
108  // L'element associe a ce modeler
109  _pElement = NULL;
110 
111  // Flag pour la sauvegarde des settings
112  _firstTimeShown = true;
113 
114  // Init des membres pour les editors
115  _pCurrentEditor = NULL;
117  _editorModeAccepted = false;
118 
119  // Init des membres pour la grille
120  _showGrid = false;
121 
123 
124  _defaultZCoord = 0.0f;
125 
126  // Le focus se fait avec la touche tab ou la souris
127  setFocusPolicy(Qt::StrongFocus);
128 
129  // Pour pouvoir afficher la position courante du curseur
130  setMouseTracking(true);
131 
132  // Layout
133  _pLayout = new QGridLayout();
134  _pLayout->setRowStretch(0, 0);
135  _pLayout->setRowStretch(1, 1);
136  _pLayout->setRowStretch(2, 0);
137  setLayout(_pLayout);
138 
139  // Initialisation des parametres de la grille.
140  _gridDimX = 200;
141  _gridDimY = 200;
142  _gridStep = 5;
143  _gridMagnStep = 1;
144 
145  // Widgets
146  _pCtrlLayout = new QHBoxLayout();
147  _pLayout->addLayout(_pCtrlLayout, 0, 0);
148  _pCtrlLayout->setSpacing(5);
149 
150  // Disambiguate the overloaded signal QComboBox::activated
151  void (QComboBox::*_qComboBox_activated)(int) = &QComboBox::activated;
152 
153  // Combo box type de Vue
154  _pViewTypeBox = new QComboBox(this);
155  _pCtrlLayout->addWidget(_pViewTypeBox, 0);
156  _pViewTypeBox->insertItem(TopView, TR("id_top_view"));
157  _pViewTypeBox->insertItem(BottomView, TR("id_bottom_view"));
158  _pViewTypeBox->insertItem(LeftView, TR("id_left_view"));
159  _pViewTypeBox->insertItem(RightView, TR("id_right_view"));
160  _pViewTypeBox->insertItem(FrontView, TR("id_front_view"));
161  _pViewTypeBox->insertItem(RearView, TR("id_rear_view"));
162  _pViewTypeBox->insertItem(PerspView, TR("id_3d_view"));
163  _pViewTypeBox->insertItem(FreeView, TR("id_free_view"));
164  connect(_pViewTypeBox, _qComboBox_activated, this, &TYModelerFrame::setViewType);
165 
166  // Combo box mode de Rendu
167  _pRenderModeBox = new QComboBox(this);
168  _pCtrlLayout->addWidget(_pRenderModeBox, 0);
169  _pRenderModeBox->insertItem(TYOpenGLRenderer::Points, TR("id_points_mode"));
170  _pRenderModeBox->insertItem(TYOpenGLRenderer::Wireframe, TR("id_wireframe_mode"));
171  _pRenderModeBox->insertItem(TYOpenGLRenderer::Surface, TR("id_surface_mode"));
172  connect(_pRenderModeBox, _qComboBox_activated, this, &TYModelerFrame::setRenderModeSlot);
173 
174  _pCtrlLayout->addSpacing(7);
175 
176  // Btn Fit
177  QToolButton* pFitBtn = new QToolButton(this);
178  pFitBtn->setIcon(QPixmap(IMG("id_icon_fit_btn")));
179  pFitBtn->setText(TR("id_fit_btn"));
180  pFitBtn->setToolTip(TR("id_fit_btn"));
181  pFitBtn->setFixedSize(24, 24);
182  connect(pFitBtn, &QToolButton::clicked, this, &TYModelerFrame::fit);
183  _pCtrlLayout->addWidget(pFitBtn, 0);
184 
185  // Btn Grille
186  _pGridBtn = new QToolButton(this);
187  _pGridBtn->setIcon(QPixmap(IMG("id_icon_grid_btn")));
188  _pGridBtn->setText(TR("id_grid_btn"));
189  _pGridBtn->setToolTip(TR("id_grid_btn"));
190  _pGridBtn->setCheckable(true);
191  _pGridBtn->setChecked(true);
192  _pGridBtn->setFixedSize(24, 24);
193  _pCtrlLayout->addWidget(_pGridBtn, 0);
194  connect(_pGridBtn, &QToolButton::toggled, this, &TYModelerFrame::showGrid);
195 
196  // Btn Show echelle.
197  // L'echelle est mise a jour a la fin de chaque deplacement de camera (cf. TYCameraEditor)
198  _showScale = true;
199  _pShowScale = new QToolButton(this);
200  _pShowScale->setIcon(QPixmap(IMG("id_icon_show_scale_btn")));
201  _pShowScale->setText(TR("id_show_scale_btn"));
202  _pShowScale->setToolTip(TR("id_show_scale_btn"));
203  _pShowScale->setCheckable(true);
204  _pShowScale->setChecked(_showScale);
205  _pShowScale->setFixedSize(24, 24);
206  _pCtrlLayout->addWidget(_pShowScale, 0);
207  connect(_pShowScale, &QToolButton::toggled, this, &TYModelerFrame::showScale);
208 
209  // Btn Grille Magnetique
210  _pSnapGridBtn = new QToolButton(this);
211  _pSnapGridBtn->setIcon(QPixmap(IMG("id_icon_snapgrid_btn")));
212  _pSnapGridBtn->setText(TR("id_snapgrid_btn"));
213  _pSnapGridBtn->setToolTip(TR("id_snapgrid_btn"));
214  _pSnapGridBtn->setCheckable(true);
215  _pSnapGridBtn->setFixedSize(24, 24);
216  _pCtrlLayout->addWidget(_pSnapGridBtn, 0);
217  connect(_pSnapGridBtn, &QToolButton::toggled, this, &TYModelerFrame::setSnapGridActive);
218  setSnapGridActive(true);
219 
220  // Btn set camera coordinates
221  _pSetCameraCoordinatesBtn = new QToolButton(this);
222  _pSetCameraCoordinatesBtn->setIcon(QPixmap(IMG("id_icon_setcameracoordinates_btn")));
223  _pSetCameraCoordinatesBtn->setText(TR("id_setcameracoordinates_btn"));
224  _pSetCameraCoordinatesBtn->setToolTip(TR("id_setcameracoordinates_btn"));
225  _pSetCameraCoordinatesBtn->setFixedSize(24, 24);
227  connect(_pSetCameraCoordinatesBtn, &QToolButton::clicked, this, &TYModelerFrame::setCameraCoordinates);
228 
229  _pCtrlLayout->addSpacing(7);
230 
231  // Btn Screenshot
232  _pScreenShotBtn = new QToolButton(this);
233  _pScreenShotBtn->setIcon(QPixmap(IMG("id_icon_screenshot_btn")));
234  _pScreenShotBtn->setText(TR("id_screenshot_btn"));
235  _pScreenShotBtn->setToolTip(TR("id_screenshot_btn"));
236  _pScreenShotBtn->setFixedSize(24, 24);
237  connect(_pScreenShotBtn, &QToolButton::clicked, this, &TYModelerFrame::screenShot);
238  // _pCtrlLayout->addWidget(_pScreenShotBtn, 0);
239 
240  // Btn Copy
241  _pCopyBtn = new QToolButton(this);
242  _pCopyBtn->setIcon(QPixmap(IMG("id_icon_copy_btn")));
243  _pCopyBtn->setText(TR("id_copy_btn"));
244  _pCopyBtn->setToolTip(TR("id_copy_btn"));
245  _pCopyBtn->setFixedSize(24, 24);
246  connect(_pCopyBtn, &QToolButton::clicked, this, &TYModelerFrame::copy);
247  //_pCtrlLayout->addWidget(_pCopyBtn, 0);
248 
249  // _pCtrlLayout->addSpacing(7);
250 
251  // Btn Show Sources
252  _pShowSourcesBtn = new QToolButton(this);
253  _pShowSourcesBtn->setIcon(QPixmap(IMG("id_icon_source")));
254  _pShowSourcesBtn->setText(TR("id_show_source_btn"));
255  _pShowSourcesBtn->setToolTip(TR("id_show_source_btn"));
256  _pShowSourcesBtn->setCheckable(true);
257  _pShowSourcesBtn->setChecked(false);
258  _pShowSourcesBtn->setFixedSize(24, 24);
259  _pCtrlLayout->addWidget(_pShowSourcesBtn, 0);
260  connect(_pShowSourcesBtn, &QToolButton::toggled, this, &TYModelerFrame::showSources);
261  showSources();
262 
263  // Btn Show Normals
264  _pShowNormalsBtn = new QToolButton(this);
265  _pShowNormalsBtn->setIcon(QPixmap(IMG("id_icon_normals")));
266  _pShowNormalsBtn->setText(TR("id_show_normals_btn"));
267  _pShowNormalsBtn->setToolTip(TR("id_show_normals_btn"));
268  _pShowNormalsBtn->setCheckable(true);
269  _pShowNormalsBtn->setChecked(false);
270  _pShowNormalsBtn->setFixedSize(24, 24);
271  _pCtrlLayout->addWidget(_pShowNormalsBtn, 0);
272  connect(_pShowNormalsBtn, &QToolButton::toggled, this, &TYModelerFrame::showNormals);
273  showNormals(_pShowNormalsBtn->isChecked());
274 
275  // Btn Show Plafond
276  _pShowPlafondBtn = new QToolButton(this);
277  _pShowPlafondBtn->setIcon(QPixmap(IMG("id_icon_plafond")));
278  _pShowPlafondBtn->setText(TR("id_show_plafond_btn"));
279  _pShowPlafondBtn->setToolTip(TR("id_show_plafond_btn"));
280  _pShowPlafondBtn->setCheckable(true);
281  _pShowPlafondBtn->setChecked(false);
282  _pShowPlafondBtn->setFixedSize(24, 24);
283  _pCtrlLayout->addWidget(_pShowPlafondBtn, 0);
284  connect(_pShowPlafondBtn, &QToolButton::toggled, this, &TYModelerFrame::showPlafond);
285  showPlafond(_pShowPlafondBtn->isChecked());
286 
287  // Btn Show Rayons
288  _pShowRaysBtn = new QToolButton(this);
289  _pShowRaysBtn->setIcon(QPixmap(IMG("id_icon_rays")));
290  _pShowRaysBtn->setText(TR("id_show_rays_btn"));
291  _pShowRaysBtn->setToolTip(TR("id_show_rays_btn"));
292 
293  _pShowRaysBtn->setCheckable(true);
294  _pShowRaysBtn->setChecked(false);
295  _pShowRaysBtn->setFixedSize(24, 24);
296  _pCtrlLayout->addWidget(_pShowRaysBtn, 0);
297  connect(_pShowRaysBtn, &QToolButton::toggled, this, &TYModelerFrame::showRays);
298  showRays(_pShowRaysBtn->isChecked());
299 
300  // Vue graphique
301  _pView = new TYRenderWindowInteractor(this, "vue graphique");
302  _pLayout->addWidget(_pView, 1, 0);
303 
305 
306  // Status bar
307  _pStatusBar = new QStatusBar(this);
308  _pLayout->addWidget(_pStatusBar, 2, 0);
309 
310  // Cameras pour chaque type de vue
311  QVector3D fromTop{0, 10000, 0};
312  QVector3D toTop{0, 0, 0};
313  QVector3D upTop{0, 0, -1};
314  _pOGLCameras[TopView] = new OGLCamera(fromTop, toTop, upTop, 100, 100, PARALLEL);
315 
316  QVector3D fromBottom{0, -10000, 0};
317  QVector3D toBottom{0, 0, 0};
318  QVector3D upBottom{0, 0, -1};
319  _pOGLCameras[BottomView] = new OGLCamera(fromBottom, toBottom, upBottom, 100, 100, PARALLEL);
320 
321  QVector3D fromLeft{-500, 0, 0};
322  QVector3D toLeft{0, 0, 0};
323  QVector3D upLeft{0, 1, 0};
324  _pOGLCameras[LeftView] = new OGLCamera(fromLeft, toLeft, upLeft, 100, 100, PARALLEL);
325 
326  QVector3D fromRight{500, 0, 0};
327  QVector3D toRight{0, 0, 0};
328  QVector3D upRight{0, 1, 0};
329  _pOGLCameras[RightView] = new OGLCamera(fromRight, toRight, upRight, 100, 100, PARALLEL);
330 
331  QVector3D fromFront{0, 0, 500};
332  QVector3D toFront{0, 0, 0};
333  QVector3D upFront{0, 1, 0};
334  _pOGLCameras[FrontView] = new OGLCamera(fromFront, toFront, upFront, 100, 100, PARALLEL);
335 
336  QVector3D fromRear{0, 0, -500};
337  QVector3D toRear{0, 0, 0};
338  QVector3D upRear{0, 1, 0};
339  _pOGLCameras[RearView] = new OGLCamera(fromRear, toRear, upRear, 100, 100, PARALLEL);
340 
341  QVector3D fromPersp{0, 10000, 10000};
342  QVector3D toPersp{0, 0, 0};
343  QVector3D upPersp{0, 1, 0};
344  _pOGLCameras[PerspView] = new OGLCamera(fromPersp, toPersp, upPersp, 100, 100, PERSPECTIVE);
345 
346  QVector3D fromFree{0, 0, 0};
347  QVector3D toFree{0, 0, 0.1};
348  QVector3D upFree{0, 1, 0};
349  _pOGLCameras[FreeView] = new OGLCamera(fromFree, toFree, upFree, 100, 100, FREE);
350 
351  // Triedre XYZ
364 
367  _pOGLTextElementLabelX->setFont(IMG("id_font_bold"));
368  OColor oColor;
369  oColor.r = fontColor[0];
370  oColor.g = fontColor[1];
371  oColor.b = fontColor[2];
374 
377  _pOGLTextElementLabelY->setFont(IMG("id_font_bold"));
380 
383  _pOGLTextElementLabelZ->setFont(IMG("id_font_bold"));
386 
393 
394  // Label
397  _pOGLTextElement->setFont(IMG("id_font_bold"));
398  _pOGLTextElement->setColor(oColor);
401 
402 #ifndef NO_GRID
403  // Construction de la grille
405  _pOGLGridElement->setColor(OColor(gridColor[0], gridColor[1], gridColor[2]));
407  _pOGLGridElement->setIs3D(true);
409 #endif // NO_GRID
410 
411  // Axes de la grille
413  _pOGLLineElementX->setPoint1(QVector3D(-100, 0, 0));
414  _pOGLLineElementX->setPoint2(QVector3D(100, 0, 0));
415  _pOGLLineElementX->setColor(OColor(0, 0, 0));
417  _pOGLLineElementX->setIs3D(true);
419 
421  _pOGLLineElementY->setPoint1(QVector3D(0, -100, 0));
422  _pOGLLineElementY->setPoint2(QVector3D(0, 100, 0));
423  _pOGLLineElementY->setColor(OColor(0, 0, 0));
425  _pOGLLineElementY->setIs3D(true);
427 
430 
431  // Echelle
433  _pOGLScalarBarElement->setPosition(QVector3D(100, 50, 0));
436  _pOGLScalarBarElement->setFont(IMG("id_font"));
438  _pOGLScalarBarElement->setTexts("0", "0", "0");
441 
442  // Lumieres
444  _pLightElement->init(0, OPoint3D(0.0, 400.0, 0.0), 1.0f);
446 
447  // Couleur de fond
448  getRenderer()->setBackground(rendererColor);
449 
450  // Type de rendu
452 
453  _wireframeOnMovingCamera = false;
455 
456  // Gestion du picking
457  _pPicker = new TYElementPicker(this);
458 
459  // Passage en vue de dessus.
461 
462  // Editors
463  _pCameraEditor = new TYCameraEditor(this);
467 
468  // Le pick editor
469  _pPickEditor = new TYPickEditor(this);
471 
472  // Mode d'edition
474 
475  resizeGrid();
476  showGrid(_pGridBtn->isChecked());
477  showScale(_pShowScale->isChecked());
478 
479  // Chargement des preferences
481 
482  showMaximized();
483 }
484 
486 {
487 
488  // Disambiguate the overloaded signal QComboBox::activated
489  void (QComboBox::*_qComboBox_activated)(int) = &QComboBox::activated;
490 
491  disconnect(_pViewTypeBox, _qComboBox_activated, this, &TYModelerFrame::setViewType);
492  disconnect(_pRenderModeBox, _qComboBox_activated, this, &TYModelerFrame::setRenderModeSlot);
493  disconnect(_pGridBtn, &QToolButton::toggled, this, &TYModelerFrame::showGrid);
494  disconnect(_pShowScale, &QToolButton::toggled, this, &TYModelerFrame::showScale);
495  disconnect(_pSnapGridBtn, &QToolButton::toggled, this, &TYModelerFrame::setSnapGridActive);
496  disconnect(_pSetCameraCoordinatesBtn, &QToolButton::clicked, this, &TYModelerFrame::setCameraCoordinates);
497  disconnect(_pScreenShotBtn, &QToolButton::clicked, this, &TYModelerFrame::screenShot);
498  disconnect(_pShowSourcesBtn, &QToolButton::toggled, this, &TYModelerFrame::showSources);
499  disconnect(_pShowNormalsBtn, &QToolButton::toggled, this, &TYModelerFrame::showNormals);
500  disconnect(_pShowPlafondBtn, &QToolButton::toggled, this, &TYModelerFrame::showPlafond);
501  disconnect(_pShowRaysBtn, &QToolButton::toggled, this, &TYModelerFrame::showRays);
503 
504  delete _pCameraEditor;
505  delete _pCameraZoneEditor;
506  delete _pDistanceEditor;
507  delete _pPositionEditor;
508  delete _pPickEditor;
509  delete _pPicker;
510 
511  for (int i = 0; i < NbOfViews; i++)
512  {
513  delete _pOGLCameras[i];
514  _pOGLCameras[i] = NULL;
515  }
516 
518  delete _pOGLLineElementAxeX;
520  delete _pOGLLineElementAxeY;
522  delete _pOGLLineElementAxeZ;
524  delete _pOGLTextElementLabelX;
526  delete _pOGLTextElementLabelY;
528  delete _pOGLTextElementLabelZ;
529 
531  delete _pOGLTextElement;
533  delete _pOGLScalarBarElement;
535  delete _pOGLLineElementX;
537  delete _pOGLLineElementY;
538 
539 #ifndef NO_GRID
541  delete _pOGLGridElement;
542 #endif // NO_GRID
544  delete _pLightElement;
545  delete _pView;
546  _pView = nullptr;
547 }
548 
550 {
551  _pCtrlLayout->addSpacing(7);
552  _pCtrlLayout->addWidget(_pScreenShotBtn, 0);
553  _pCtrlLayout->addWidget(_pCopyBtn, 0);
554 }
555 
557 {
558  return QWidget::close();
559 }
560 
562 {
563  bool ret = false;
564 
565  if (getTYApp()->getCurProjet() && getTYApp()->getCurProjet()->getCurrentCalcul() && _pElement)
566  {
567  // L'element fait-il parti de la selection du calcul courant ?
569  }
570 
571  return ret;
572 }
573 
575 {
576  bool ret = false;
577 
578  if (getTYApp()->getCurProjet() && _pElement)
579  {
580  // On commence directement a partir de l'element lui-meme
581  TYElement* pParent = _pElement;
582 
583  while (pParent)
584  {
585  // Le parent est le projet courant ?
586  if (pParent == getTYApp()->getCurProjet())
587  {
588  ret = true;
589  break;
590  }
591  // Parent du parent
592  pParent = pParent->getParent();
593  }
594  }
595 
596  return ret;
597 }
598 
600 {
601  bool ret = true;
602 
604  {
606  }
607 
608  return ret;
609 }
610 
612 {
613  if (view >= NbOfViews)
614  {
615  return;
616  }
617 
618  // View type
619  _curViewType = view;
620 
621  bool showGridXY = false;
622  bool showGridXZ = false;
623  bool showGridZY = false;
624  QString labelStr;
625 
626  // Pre traitement selon la vue activee
627  switch (view)
628  {
629  case TopView:
630  showGridXZ = _showGrid;
631  labelStr = TR("id_top_view");
632  _pSetCameraCoordinatesBtn->setEnabled(false);
633  break;
634  case BottomView:
635  showGridXZ = _showGrid;
636  labelStr = TR("id_bottom_view");
637  _pSetCameraCoordinatesBtn->setEnabled(false);
638  break;
639  case LeftView:
640  showGridZY = _showGrid;
641  labelStr = TR("id_left_view");
642  _pSetCameraCoordinatesBtn->setEnabled(false);
643  break;
644  case RightView:
645  showGridZY = _showGrid;
646  labelStr = TR("id_right_view");
647  _pSetCameraCoordinatesBtn->setEnabled(false);
648  break;
649  case FrontView:
650  showGridXY = _showGrid;
651  labelStr = TR("id_front_view");
652  _pSetCameraCoordinatesBtn->setEnabled(false);
653  break;
654  case RearView:
655  showGridXY = _showGrid;
656  labelStr = TR("id_rear_view");
657  _pSetCameraCoordinatesBtn->setEnabled(false);
658  break;
659  case PerspView:
660  showGridXZ = _showGrid;
661  labelStr = TR("id_3d_view");
662  _pSetCameraCoordinatesBtn->setEnabled(false);
663  break;
664  case FreeView:
665  showGridXZ = _showGrid;
666  labelStr = TR("id_free_view");
667  _pSetCameraCoordinatesBtn->setEnabled(true);
668  break;
669  default:
670  break;
671  }
672 
673  //_pView->setFocus();
674 
675  // Affichage de la grille correspondant au type de vue
676  setGridLinesActorsVisibility(showGridXY, showGridXZ, showGridZY);
677 
678  // Label
680 
681  // Camera
682  OGLCamera* camera = _pOGLCameras[view];
683  _pView->setActiveCamera(camera);
684 
685  // Update l'element associe a ce modeler
686  if (_pElement)
687  {
688  _pElement->updateGraphicTree();
689  _pElement->getGraphicObject()->update(true);
690  }
691 
693  // Updates
694  updateView();
695 
696  _pViewTypeBox->setCurrentIndex(_curViewType);
698 }
699 
701 {
702  setRenderMode(static_cast<TYOpenGLRenderer::RenderMode>(mode), true);
703 }
704 
706 {
708  {
709  return;
710  }
711 
712  _pView->getRenderer()->setRenderMode(mode);
713 
714  _pRenderModeBox->setCurrentIndex(mode);
715 
716  if (bUpdateGL == true)
717  {
718  _pView->update();
719  }
720 }
721 
723 {
724  if (!_editorModeAccepted)
725  {
726  getPickEditor()->usePopup(true);
727  getPickEditor()->useHighlight(false);
728 
729  if (_pCurrentEditor)
730  {
731  // We want to be sure that Camera will not zoom unwillingly before disconnecting signals
735  }
736 
737  _editorModeAccepted = true;
738 
739  switch (mode)
740  {
741  case CameraMode:
742  // fit();
743  getPickEditor()->useHighlight(true);
745  break;
746  case CameraZoneMode:
747  getPickEditor()->useHighlight(true);
749  break;
750  case DistanceMode:
752  break;
753  case MovingMode:
756  break;
757  case RotationMode:
760  break;
761  case EditionMode:
764  break;
765  case NoMode:
766  default:
767  getPickEditor()->useHighlight(true);
768  _pCurrentEditor = NULL;
769  mode = NoMode;
770  _editorModeAccepted = false;
771  break;
772  }
773  }
774 
775  // On sauve le mode courant
776  _lastEditorMode = mode;
777 
778  // Init
779  if (_pCurrentEditor)
780  {
783  }
784 
785  // Pour la prochaine requete
786  _editorModeAccepted = false;
787 
788  // The bug goes by here...
789  emit(editorModeChanged(mode));
790 }
791 
793 {
794  _showGrid = show;
795 
798 
799  _pGridBtn->setChecked(_showGrid);
800 
802  // Update
804 }
805 
807 {
808  if (_showSources != _pShowSourcesBtn->isChecked())
809  {
810  _showSources = _pShowSourcesBtn->isChecked();
811  TYApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
812 
813  if (_pElement && _pElement->getGraphicObject())
814  {
815  // Update l'element associe a ce modeler
816  _pElement->getGraphicObject()->update(true);
817 
819 
820  // Update view
821  updateView();
822  }
823 
824  TYApplication::restoreOverrideCursor();
825  }
826 }
827 
829 {
830  _showRays = show;
832  {
833 
834  TYApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
835 
837 
838  if (_pElement && _pElement->getGraphicObject())
839  {
840  // Update l'element associe a ce modeler
841  _pElement->getGraphicObject()->update(true);
842 
844 
845  // Update view
846  updateView();
847  }
848 
849  TYApplication::restoreOverrideCursor();
850  }
851 
852  _pShowRaysBtn->setChecked(_showRays);
853 }
854 
855 void TYModelerFrame::setKeepRays(bool keepRays)
856 {
857  _pShowRaysBtn->setEnabled(keepRays);
858 }
859 
861 {
862  _showNormals = show;
863 
865  {
866 
867  TYApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
868 
870 
871  if (_pElement && _pElement->getGraphicObject())
872  {
873  // Update l'element associe a ce modeler
874  _pElement->getGraphicObject()->update(true);
875 
877 
878  // Update view
879  updateView();
880  }
881 
882  TYApplication::restoreOverrideCursor();
883  }
884 
885  _pShowNormalsBtn->setChecked(_showNormals);
886 }
887 
889 {
890  _showPlafond = !show; // inversion entre l'etat variable et du bouton
891 
893  {
894 
895  TYApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
896 
898 
899  if (_pElement && _pElement->getGraphicObject())
900  {
901  // Update l'element associe a ce modeler
902  _pElement->getGraphicObject()->update(true);
903 
905 
906  // Update view
907  updateView();
908  }
909 
910  TYApplication::restoreOverrideCursor();
911  }
912 
913  _pShowPlafondBtn->setChecked(!_showPlafond);
914 }
915 
917 {
918  _snapGridActive = state;
919  _pSnapGridBtn->setChecked(_snapGridActive);
920 }
921 
923 {
925  {
926  TYSetCameraCoordinates* pSetCameraCoordinates = new TYSetCameraCoordinates(this);
927  double x = NAN, y = NAN, z = NAN;
929  pSetCameraCoordinates->setXCoord(x);
930  pSetCameraCoordinates->setYCoord(-z);
931  pSetCameraCoordinates->setZCoord(y);
932  pSetCameraCoordinates->exec();
933 
934  if (pSetCameraCoordinates->result() == QDialog::Accepted)
935  {
936  if (_pView->getActiveCamera())
937  {
938  _pView->getActiveCamera()->setTranslation(pSetCameraCoordinates->getXCoord(),
939  pSetCameraCoordinates->getZCoord(),
940  -pSetCameraCoordinates->getYCoord());
941 
942  // Update view
943  updateView();
944  }
945  }
946  }
947 }
948 
950 {
951  QString filename = QFileDialog::getSaveFileName(this, tr("Save Image"), "",
952  tr("Images PNG (*.png);;Images JPEG (*.jpg *.jpeg)"));
953  if (!filename.isEmpty())
954  {
955  // Snap
956  QImage img = _pView->grabFramebuffer();
957 
958  // Save
959  QPixmap pix = QPixmap::fromImage(img);
960  pix.save(filename);
961  }
962 }
963 
965 {
966  // Snap
967  QImage img = _pView->grabFramebuffer();
968 
969  // Copie dans le presse papier
970  QClipboard* clipboard = QApplication::clipboard();
971  clipboard->setImage(img);
972 }
973 
975 {
976  LPTYProjet pProjet = getTYApp()->getCurProjet();
977  LPTYCalcul pCalcul = NULL;
978  if (pProjet)
979  {
980  pCalcul = pProjet->getCurrentCalcul();
981  }
982 
983  // Print dialog
984  TYPrintDialog* pDialog = new TYPrintDialog(this);
985 
986  if (pProjet == NULL)
987  {
988  pDialog->_groupBoxProjet->setEnabled(false);
989  }
990  if (pCalcul == NULL)
991  {
992  pDialog->_groupBoxCalcul->setEnabled(false);
993  }
994 
995  if (_pElement)
996  {
997  if (dynamic_cast<TYBatiment*>(_pElement._pObj) != nullptr)
998  {
999  pDialog->_groupBoxBatiment->show();
1000  }
1001  else if (dynamic_cast<TYMachine*>(_pElement._pObj) != nullptr)
1002  {
1003  pDialog->_groupBoxMachine->show();
1004  }
1005  else if (dynamic_cast<TYSiteNode*>(_pElement._pObj) != nullptr)
1006  {
1007  pDialog->_groupBoxSite->show();
1008  }
1009  }
1010 
1011  if (pDialog->exec() == QDialog::Accepted)
1012  {
1013  QPrinter* printer = new QPrinter();
1014 
1015  QPrintDialog dialog(printer, this);
1016  if (dialog.exec())
1017  {
1018  QPainter paint(printer);
1019 
1020  double w = double(printer->width());
1021  double h = double(printer->height());
1022  double scalew = w / 700;
1023  double scaleh = h / 700;
1024 
1025  // Snap
1026  QImage img = _pView->grabFramebuffer();
1027  img = img.scaled(int(w * 9 / 10), int(h * 2 / 3), Qt::KeepAspectRatio, Qt::SmoothTransformation);
1028  int x = int(double(printer->width() - img.width()) / 2);
1029  int y = int(double(printer->height() - img.height()) * 1 / 3);
1030  QPixmap pm = QPixmap::fromImage(img);
1031  paint.drawPixmap(x, y, pm);
1032 
1033  paint.setFont(QFont("Times", (int)(10 * scaleh)));
1034  int mid =
1035  int(w / 2) - int(paint.fontMetrics().horizontalAdvance(pDialog->_lineEditTete->text()) / 2);
1036  paint.drawText(mid, 20, pDialog->_lineEditTete->text());
1037 
1038  mid = int(w / 2) - int(paint.fontMetrics().horizontalAdvance(pDialog->_lineEditPied->text()) / 2);
1039  paint.drawText(mid, printer->height() - 20, pDialog->_lineEditPied->text());
1040 
1041  paint.setFont(QFont("Times", (int)(15 * scaleh), QFont::Bold));
1042  mid =
1043  int(w / 2) - int(paint.fontMetrics().horizontalAdvance(pDialog->_lineEditTitre->text()) / 2);
1044  paint.drawText(mid, y - 20, pDialog->_lineEditTitre->text());
1045 
1046  x = int(50 * scalew);
1047  int x1 = int(w / 2);
1048  y = int(double(printer->height()) * 2 / 3 + 20 * scaleh);
1049  int stepy = int(10 * scaleh);
1050  paint.setFont(QFont("Times", (int)(10 * scaleh)));
1051 
1052  if (pProjet)
1053  {
1054  if (pDialog->_checkBoxNomProjet->isChecked())
1055  {
1056  paint.drawText(x, y, TR("id_print_nom_projet"));
1057  paint.drawText(x1, y, pProjet->getName());
1058  y += stepy;
1059  }
1060  if (pDialog->_checkBoxAuteurProjet->isChecked())
1061  {
1062  paint.drawText(x, y, TR("id_print_auteur_projet"));
1063  paint.drawText(x1, y, pProjet->getAuteur());
1064  y += stepy;
1065  }
1066  if (pDialog->_checkBoxDateProjet->isChecked())
1067  {
1068  paint.drawText(x, y, TR("id_print_date_creation"));
1069  paint.drawText(x1, y, pProjet->getDateCreation());
1070  y += stepy;
1071  paint.drawText(x, y, TR("id_print_date_modif"));
1072  paint.drawText(x1, y, pProjet->getDateModif());
1073  y += stepy;
1074  }
1075  if (pDialog->_checkBoxCommentProjet->isChecked())
1076  {
1077  paint.drawText(x, y, TR("id_print_comment"));
1078  paint.drawText(x1, y, pProjet->getComment());
1079  y += stepy;
1080  }
1081  }
1082 
1083  if (pCalcul)
1084  {
1085  y += int(double(stepy) * 1.5);
1086  if (pDialog->_checkBoxNomCalcul->isChecked())
1087  {
1088  paint.drawText(x, y, TR("id_print_nom_calcul"));
1089  paint.drawText(x1, y, pCalcul->getName());
1090  y += stepy;
1091  }
1092  if (pDialog->_checkBoxDateCalcul->isChecked())
1093  {
1094  paint.drawText(x, y, TR("id_print_date_creation"));
1095  paint.drawText(x1, y, pCalcul->getDateCreation());
1096  y += stepy;
1097  paint.drawText(x, y, TR("id_print_date_modif"));
1098  paint.drawText(x1, y, pCalcul->getDateModif());
1099  y += stepy;
1100  }
1101  if (pDialog->_checkBoxCommentCalcul->isChecked())
1102  {
1103  paint.drawText(x, y, TR("id_print_comment"));
1104  paint.drawText(x1, y, pCalcul->getComment());
1105  y += stepy;
1106  }
1107  }
1108 
1109  if (_pElement)
1110  {
1111  y += int(double(stepy) * 1.5);
1112  TYElement* pElement = (TYElement*)_pElement;
1113  if (strcmp(_pElement->getClassName(), "TYBatiment") == 0)
1114  {
1115  TYBatiment* pBatiment = (TYBatiment*)pElement;
1116  if (pDialog->_checkBoxNomBatiment->isChecked())
1117  {
1118  paint.drawText(x, y, TR("id_print_nom_batiment"));
1119  paint.drawText(x1, y, pBatiment->getName());
1120  }
1121  }
1122  else if (strcmp(_pElement->getClassName(), "TYMachine") == 0)
1123  {
1124  TYMachine* pMachine = (TYMachine*)pElement;
1125  if (pDialog->_checkBoxNomMachine->isChecked())
1126  {
1127  paint.drawText(x, y, TR("id_print_nom_machine"));
1128  paint.drawText(x1, y, pMachine->getName());
1129  y += stepy;
1130  }
1131  if (pDialog->_checkBoxConstrMachine->isChecked())
1132  {
1133  paint.drawText(x, y, TR("id_print_constr"));
1134  paint.drawText(x1, y, pMachine->getConstructeur());
1135  y += stepy;
1136  }
1137  if (pDialog->_checkBoxModelMachine->isChecked())
1138  {
1139  paint.drawText(x, y, TR("id_print_model"));
1140  paint.drawText(x1, y, pMachine->getModele());
1141  y += stepy;
1142  }
1143  if (pDialog->_checkBoxCatMachine->isChecked())
1144  {
1145  paint.drawText(x, y, TR("id_print_cat"));
1146  paint.drawText(x1, y, QString().setNum(pMachine->getCategorie()));
1147  y += stepy;
1148  }
1149  if (pDialog->_checkBoxCommentProjet->isChecked())
1150  {
1151  paint.drawText(x, y, TR("id_print_comment"));
1152  paint.drawText(x1, y, pMachine->getCommentaire());
1153  }
1154  }
1155  else
1156  {
1157  TYSiteNode* pSite = dynamic_cast<TYSiteNode*>(pElement);
1158  if (pSite != nullptr)
1159  {
1160  if (pDialog->_checkBoxNomSite->isChecked())
1161  {
1162  paint.drawText(x, y, TR("id_print_nom_site"));
1163  paint.drawText(x1, y, pSite->getName());
1164  }
1165  }
1166  }
1167  }
1168  }
1169 
1170  delete printer;
1171  }
1172 }
1173 
1175 {
1176  if (_pElement)
1177  {
1178  if (_pElement->edit(this) == QDialog::Accepted)
1179  {
1180  emit eltModified(_pElement);
1181  }
1182 
1183  // On update ds ts les cas si un child a ete modifie...
1184  _pElement->getGraphicObject()->update(true);
1186  updateView(false, false);
1187  }
1188 }
1189 
1191 {
1192  // XBH: version simplifiee et +logique...
1193 
1194  OBox boundingBox;
1195  LPTYElementGraphic pTYElementGraphic = pElement->getGraphicObject();
1196 
1197  if (pTYElementGraphic != NULL)
1198  {
1199  boundingBox = pTYElementGraphic->boundingBox();
1200  }
1201 
1202  return boundingBox;
1203 }
1204 
1206 {
1207  OBox globalBoundingBox;
1208  if (_pElement)
1209  {
1210  TYElement* pTYElement = (TYElement*)_pElement;
1211  TYProjet* pTYProjet = dynamic_cast<TYProjet*>(pTYElement);
1212  if (pTYProjet != nullptr)
1213  {
1214  TYSiteNode* pTYSiteNode = (TYSiteNode*)pTYProjet->getSite();
1215  pTYElement = pTYSiteNode;
1216  }
1217 
1218  globalBoundingBox = getBoundingBox(pTYElement);
1219  }
1220  return globalBoundingBox;
1221 }
1222 
1224 {
1225  for (auto camera : _pOGLCameras)
1226  {
1227  camera->setSize(_pView->getViewport().width(), _pView->getViewport().height());
1228  }
1229 
1230  int visibilityStates[9];
1231 
1232  // Sauvegarde des etats de visibilite des objets graphiques
1233  // de "decoration", ils ne doivent pas participer au recadrage
1234 #ifndef NO_GRID
1235  visibilityStates[0] = _pOGLGridElement->getShowGridXY();
1236  visibilityStates[1] = _pOGLGridElement->getShowGridXZ();
1237  visibilityStates[2] = _pOGLGridElement->getShowGridZY();
1238 #endif // NO_GRID
1239 
1240  setGridLinesActorsVisibility(false, false, false);
1241 
1242  visibilityStates[3] = _pOGLLineElementAxeX->getVisibility();
1246  visibilityStates[4] = _pOGLTextElementLabelX->getVisibility();
1248  visibilityStates[5] = _pOGLTextElementLabelY->getVisibility();
1250  visibilityStates[6] = _pOGLTextElementLabelZ->getVisibility();
1252 
1253  visibilityStates[7] = _pOGLLineElementX->getVisibility();
1255  visibilityStates[8] = _pOGLLineElementY->getVisibility();
1257 
1258  // az-- : pour tests reperes machines:
1259  OBox globalBoundingBox = getGlobalBoundingBox();
1260 
1261  float xMin = globalBoundingBox._min._x;
1262  float xMax = globalBoundingBox._max._x;
1263  float yMin = globalBoundingBox._min._y;
1264  float yMax = globalBoundingBox._max._y;
1265  float zMin = globalBoundingBox._min._z;
1266  float zMax = globalBoundingBox._max._z;
1267  float xDist = std::max(abs(xMin), abs(xMax)) * 2;
1268  float yDist = std::max(abs(yMin), abs(yMax)) * 2;
1269  float zDist = std::max(abs(zMin), abs(zMax)) * 2;
1270 
1271  // Cameras pour chaque type de vue
1272  QVector3D fromTop{0, 10000, 0};
1273  QVector3D toTop{0, 0, 0};
1274  QVector3D upTop{0, 0, -1};
1275  _pOGLCameras[TopView]->setFromToUp(fromTop, toTop, upTop);
1277  _pOGLCameras[TopView]->resetZoom(xDist, yDist);
1278 
1279  QVector3D fromBottom{0, -10000, 0};
1280  QVector3D toBottom{0, 0, 0};
1281  QVector3D upBottom{0, 0, 1};
1282  _pOGLCameras[BottomView]->setFromToUp(fromBottom, toBottom, upBottom);
1284  _pOGLCameras[BottomView]->resetZoom(xDist, yDist);
1285 
1286  QVector3D fromLeft{-500, 0, 0};
1287  QVector3D toLeft{0, 0, 0};
1288  QVector3D upLeft{0, 1, 0};
1289  _pOGLCameras[LeftView]->setFromToUp(fromLeft, toLeft, upLeft);
1290  _pOGLCameras[LeftView]->resetZoom(yDist, zDist);
1291 
1292  QVector3D fromRight{500, 0, 0};
1293  QVector3D toRight{0, 0, 0};
1294  QVector3D upRight{0, 1, 0};
1295  _pOGLCameras[RightView]->setFromToUp(fromRight, toRight, upRight);
1296  _pOGLCameras[RightView]->resetZoom(yDist, zDist);
1297 
1298  QVector3D fromFront{0, 0, 500};
1299  QVector3D toFront{0, 0, 0};
1300  QVector3D upFront{0, 1, 0};
1301  _pOGLCameras[FrontView]->setFromToUp(fromFront, toFront, upFront);
1302  _pOGLCameras[FrontView]->resetZoom(xDist, zDist);
1303 
1304  QVector3D fromRear{0, 0, -500};
1305  QVector3D toRear{0, 0, 0};
1306  QVector3D upRear{0, 1, 0};
1307  _pOGLCameras[RearView]->setFromToUp(fromRear, toRear, upRear);
1308  _pOGLCameras[RearView]->resetZoom(xDist, zDist);
1309 
1310  QVector3D fromPersp{0, 1000, 1000};
1311  QVector3D toPersp{0, 0, 0};
1312  QVector3D upPersp{0, 1, 0};
1313  _pOGLCameras[PerspView]->setFromToUp(fromPersp, toPersp, upPersp);
1314  _pOGLCameras[PerspView]->resetZoom(xDist, yDist);
1316  _pOGLCameras[PerspView]->setDistanceStep(30, 70, 30);
1317 
1318  QVector3D fromFree{0, 0, 0};
1319  QVector3D toFree{0, 0, 0.1};
1320  QVector3D upFree{0, 1, 0};
1321  _pOGLCameras[FreeView]->setFromToUp(fromFree, toFree, upFree);
1326 
1327  // Restauration des etats de visibilite des objets graphiques
1328 #ifndef NO_GRID
1329  setGridLinesActorsVisibility(visibilityStates[0], visibilityStates[1], visibilityStates[2]);
1330 #endif // NO_GRID
1331  _pOGLLineElementAxeX->setVisibility(visibilityStates[3]);
1332  _pOGLLineElementAxeY->setVisibility(visibilityStates[3]);
1333  _pOGLLineElementAxeZ->setVisibility(visibilityStates[3]);
1334  _pOGLTextElementLabelX->setVisibility(visibilityStates[4]);
1335  _pOGLTextElementLabelY->setVisibility(visibilityStates[5]);
1336  _pOGLTextElementLabelZ->setVisibility(visibilityStates[6]);
1337  _pOGLLineElementX->setVisibility(visibilityStates[7]);
1338  _pOGLLineElementY->setVisibility(visibilityStates[8]);
1339 
1341  updateView();
1342 }
1343 
1344 void TYModelerFrame::updateView(bool clipping /*=true*/, bool axesAndGrid /*=true*/)
1345 {
1346  OGLCamera* activeCamera = _pView->getActiveCamera();
1347  if (activeCamera)
1348  {
1349  QRect viewport = _pView->getViewport();
1350  activeCamera->setSize(viewport.width(), viewport.height());
1351  if (axesAndGrid)
1352  {
1353  updateAxes();
1354  updateGrid();
1355  updateCurPosInfo(0, 0);
1356  updateScale();
1357  }
1358 
1359  if (clipping)
1360  {
1361  // Update le render mode
1362  setRenderMode(getRenderMode(), false);
1363  }
1364  _pOGLTextElement->setDisplayPosition(7, viewport.height() - 20);
1366  QVector3D(viewport.width() - _pOGLScalarBarElement->getWidth() * 0.5 - 50, 50, 0));
1368 
1369  // RNU
1370  //_pView->getRenderer()->invalidateScene();
1371 
1372  // Update la vue 3D
1373  _pView->update();
1374  }
1375 }
1376 
1378 {
1385 
1386  QVector3D org = _pView->getViewport().displayToWorld(QVector3D(50, 50, 0.1));
1387 
1391 
1392  QVector3D extX, extY, extZ;
1393 
1394  switch (getCurrentView())
1395  {
1396  case TopView:
1397  {
1398  extX = _pView->getViewport().displayToWorld(QVector3D(90, 50, 0.1));
1399  extY = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1400  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 50, 40.1));
1404  }
1405  break;
1406  case BottomView:
1407  {
1408  extX = _pView->getViewport().displayToWorld(QVector3D(10, 50, 0.1));
1409  extY = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1410  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 50, -40.1));
1414  }
1415  break;
1416  case LeftView:
1417  {
1418  extX = _pView->getViewport().displayToWorld(QVector3D(50, 50, 40.1));
1419  extY = _pView->getViewport().displayToWorld(QVector3D(10, 50, 0.1));
1420  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1424  }
1425  break;
1426  case RightView:
1427  {
1428  extX = _pView->getViewport().displayToWorld(QVector3D(50, 50, -40.1));
1429  extY = _pView->getViewport().displayToWorld(QVector3D(90, 50, 0.1));
1430  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1434  }
1435  break;
1436  case FrontView:
1437  {
1438  extX = _pView->getViewport().displayToWorld(QVector3D(90, 50, 0.1));
1439  extY = _pView->getViewport().displayToWorld(QVector3D(50, 50, 40.1));
1440  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1444  }
1445  break;
1446  case RearView:
1447  {
1448  extX = _pView->getViewport().displayToWorld(QVector3D(10, 50, 0.1));
1449  extY = _pView->getViewport().displayToWorld(QVector3D(50, 50, -40.1));
1450  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1454  }
1455  break;
1456  case PerspView:
1457  case FreeView:
1458  {
1459  QVector3D org2 = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1460  double dist = org.distanceToPoint(org2);
1461  extX.setX(org.x() + dist);
1462  extX.setY(org.y());
1463  extX.setZ(org.z());
1464  extY.setX(org.x());
1465  extY.setY(org.y());
1466  extY.setZ(org.z() - dist);
1467  extZ.setX(org.x());
1468  extZ.setY(org.y() + dist);
1469  extZ.setZ(org.z());
1470 
1471  QVector3D dispX = _pView->getViewport().worldToDisplay(extX);
1472  QVector3D dispY = _pView->getViewport().worldToDisplay(extY);
1473  QVector3D dispZ = _pView->getViewport().worldToDisplay(extZ);
1474 
1475  _pOGLTextElementLabelX->setDisplayPosition(dispX.x(), dispX.y());
1476  _pOGLTextElementLabelY->setDisplayPosition(dispY.x(), dispY.y());
1477  _pOGLTextElementLabelZ->setDisplayPosition(dispZ.x(), dispZ.y());
1478  }
1479  break;
1480  }
1481 
1485 }
1486 
1487 void TYModelerFrame::keyPressEvent(QKeyEvent* pEvent)
1488 {
1489  switch (pEvent->key())
1490  {
1491  case Qt::Key_1:
1493  break;
1494  case Qt::Key_2:
1496  break;
1497  case Qt::Key_3:
1499  break;
1500  case Qt::Key_4:
1502  break;
1503  case Qt::Key_5:
1505  break;
1506  case Qt::Key_V:
1508  break;
1509  case Qt::Key_I:
1511  break;
1512  case Qt::Key_G:
1513  showGrid(!_showGrid);
1514  break;
1515  case Qt::Key_R:
1516  {
1517  int nextRenderMode = (getRenderMode() + 1) % TYOpenGLRenderer::NbOfRenderMode;
1518  setRenderMode(static_cast<TYOpenGLRenderer::RenderMode>(nextRenderMode), true);
1519  break;
1520  }
1521  case Qt::Key_W:
1523  break;
1524  case Qt::Key_S:
1526  break;
1527  case Qt::Key_Control:
1528  setSnapGridActive(false);
1529  break;
1530  case Qt::Key_C:
1531  if (pEvent->modifiers() == Qt::ControlModifier)
1532  {
1533  copy();
1534  }
1535  else
1536  {
1538  }
1539  break;
1540  case Qt::Key_F:
1541  case Qt::Key_F5:
1542  fit();
1543  break;
1544  default:
1545  TYApplication::sendEvent(_pView, pEvent);
1546  }
1547 }
1548 
1549 void TYModelerFrame::keyReleaseEvent(QKeyEvent* pEvent)
1550 {
1551  switch (pEvent->key())
1552  {
1553  case Qt::Key_Control:
1554  setSnapGridActive(true);
1555  break;
1556  default:
1557  TYApplication::sendEvent(_pView, pEvent);
1558  }
1559 }
1560 
1561 void TYModelerFrame::mouseMoveEvent(QMouseEvent* pEvent) {}
1562 
1564 {
1565  // On recupere la pos du curseur
1566 
1567  // Calcul des coords
1568  float* pos = new float[3];
1569 
1570  if (computeCurPos(x, y, pos))
1571  {
1572  // Si la grille magnetique est activee
1573  if (getSnapGridActive())
1574  {
1575  TYAbstractSceneEditor::snapToGrid(pos[0], pos[1], pos[2], _gridMagnStep);
1576  }
1577 
1578  // Formatage du msg
1579  QString msg("pos : (%1, %2, %3)");
1580  // On inverse y et z, et -y... (VTK to TY)
1581  msg = msg.arg(pos[0], 0, 'f', 2).arg(-pos[2], 0, 'f', 2).arg(pos[1], 0, 'f', 2);
1582  // Affichage
1583  statusBar()->showMessage(msg);
1584  }
1585  else
1586  {
1587  if (getCurrentView() == FreeView)
1588  {
1589  double x = NAN, y = NAN, z = NAN;
1590  _pView->getActiveCamera()->getTranslation(x, y, z);
1591  QString msg = QString("camera pos : (%1, %2, %3)").arg(x).arg(-z).arg(y);
1592  statusBar()->showMessage(msg);
1593  }
1594  else
1595  {
1596  statusBar()->showMessage("");
1597  }
1598  }
1599 
1600  delete[] pos;
1601 }
1602 
1603 // float* TYModelerFrame::computeCurPos(int x, int y)
1604 bool TYModelerFrame::computeCurPos(int x, int y, float* ret)
1605 {
1606  int view = getCurrentView();
1607  if ((view != PerspView) && (view != FreeView))
1608  {
1609  // Position du curseur
1610  QVector3D pos =
1611  _pView->getViewport().displayToWorld(QVector3D(x, _pView->getViewport().height() - y, 0));
1612  ret[0] = pos.x();
1613  ret[1] = pos.y();
1614  ret[2] = pos.z();
1615 
1616  switch (getCurrentView())
1617  {
1618  case TopView:
1619  ret[1] = 0.0;
1620  break;
1621  case BottomView:
1622  ret[1] = 0.0;
1623  break;
1624  case LeftView:
1625  ret[0] = 0.0;
1626  break;
1627  case RightView:
1628  ret[0] = 0.0;
1629  break;
1630  case FrontView:
1631  ret[2] = 0.0;
1632  break;
1633  case RearView:
1634  ret[2] = 0.0;
1635  break;
1636  }
1637 
1638  return true;
1639  }
1640 
1641  return false;
1642 }
1643 
1645 {
1646  return _defaultZCoord;
1647 }
1648 
1649 void TYModelerFrame::setGridLinesActorsVisibility(bool showGridXY, bool showGridXZ, bool showGridZY)
1650 {
1651 #ifndef NO_GRID
1652  _pOGLGridElement->setShowGridXY(showGridXY);
1653  _pOGLGridElement->setShowGridXZ(showGridXZ);
1654  _pOGLGridElement->setShowGridZY(showGridZY);
1655 #endif // NO_GRID
1656 }
1657 
1658 void TYModelerFrame::wheelEvent(QWheelEvent* pEvent)
1659 {
1660  // Reroute l'event sur le TYRenderWindowInteractor
1661  TYApplication::sendEvent(_pView, pEvent);
1662 }
1663 
1664 void TYModelerFrame::resizeEvent(QResizeEvent* pEvent)
1665 {
1666  // CLM-NT33 : maximized handling and main window title
1667  emit frameResized();
1668  updateView();
1669 }
1670 
1671 void TYModelerFrame::focusInEvent(QFocusEvent* pEvent)
1672 {
1673  updateView();
1674 }
1675 
1676 void TYModelerFrame::showEvent(QShowEvent* pEvent)
1677 {
1678  if (_firstTimeShown)
1679  {
1680  TYPreferenceManager::loadGeometryFromPreferences(metaObject()->className(), this);
1681  _firstTimeShown = false;
1682  }
1683  updateView();
1684 }
1685 
1686 void TYModelerFrame::closeEvent(QCloseEvent* pEvent)
1687 {
1688  TYPreferenceManager::saveGeometryToPreferences(metaObject()->className(), this);
1689  pEvent->accept();
1690  emit frameResized();
1691  emit aboutToClose();
1692 
1693  // CLM-NT35 : Gestion du maximized et titre fenetre principal
1694 }
1695 
1696 void TYModelerFrame::enterEvent(QEvent* pEvent)
1697 {
1698  /* _pView->getRenderer()->invalidateScene();
1699  updateView();
1700  _pView->getRenderer()->invalidateScene();
1701  updateView();*/
1702  emit mouseEnter();
1703 }
1704 
1705 void TYModelerFrame::leaveEvent(QEvent* pEvent)
1706 {
1707  emit mouseLeave();
1708 }
1709 
1711 {
1712  if ((getCurrentView() == PerspView) || (getCurrentView() == FreeView))
1713  {
1714  _pOGLLineElementX->setPoint1(QVector3D(0, 0, _gridDimY / 2));
1715  _pOGLLineElementX->setPoint2(QVector3D(0, 0, -_gridDimY / 2));
1716 
1717  _pOGLLineElementY->setPoint1(QVector3D(_gridDimX / 2, 0, 0));
1718  _pOGLLineElementY->setPoint2(QVector3D(-_gridDimX / 2, 0, 0));
1719  }
1720  else
1721  {
1722  QRect viewport = _pView->getViewport();
1723  int gridXMax = viewport.width();
1724  int gridYMax = viewport.height();
1725  if (gridXMax == 0)
1726  {
1727  gridXMax = 100;
1728  }
1729  if (gridYMax == 0)
1730  {
1731  gridYMax = 100;
1732  }
1733 
1734  // getCenter
1735  QVector3D center = _pView->getViewport().worldToDisplay(QVector3D(0, 0, 0));
1736 
1737  // X
1738  QVector3D xAxisPoint1 = _pView->getViewport().displayToWorld(QVector3D(center.x(), 0, 0));
1739  QVector3D xAxisPoint2 = _pView->getViewport().displayToWorld(QVector3D(center.x(), gridYMax, 0));
1740  _pOGLLineElementX->setPoint1(xAxisPoint1);
1741  if (xAxisPoint1 != xAxisPoint2)
1742  {
1743  _pOGLLineElementX->setPoint2(xAxisPoint2);
1744  }
1745 
1746  // Y
1747  QVector3D yAxisPoint1 = _pView->getViewport().displayToWorld(QVector3D(0, center.y(), 0));
1748  QVector3D yAxisPoint2 = _pView->getViewport().displayToWorld(QVector3D(gridXMax, center.y(), 0));
1749  _pOGLLineElementY->setPoint1(yAxisPoint1);
1750  if (yAxisPoint1 != yAxisPoint2)
1751  {
1752  _pOGLLineElementY->setPoint2(yAxisPoint2);
1753  }
1754  }
1755 }
1756 
1757 void TYModelerFrame::updateElementGraphic(bool force /* = false */)
1758 {
1759  if (_pElement && _pElement->getGraphicObject())
1760  {
1761  _pElement->getGraphicObject()->update(force);
1762  }
1763 }
1764 
1766 {
1770 
1771  _pOGLLineElementX->setColor(OColor(gridColor[0], gridColor[1], gridColor[2]));
1772  _pOGLLineElementY->setColor(OColor(gridColor[0], gridColor[1], gridColor[2]));
1773 }
1774 
1776 {
1777  // Mise a jour de la taille de l'historique de l'Action Manager
1778  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "HistoSize"))
1779  {
1780  _actionManager.setHistorySize(TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "HistoSize"));
1781  }
1782  else
1783  {
1784  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "HistoSize", _actionManager.getHistorySize());
1785  }
1786 
1787  // Mise a jour de l'etat d'activation du delplacement de camera en mode Wireframe
1788  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "WireframeOnMovingCamera"))
1789  {
1791  TYPreferenceManager::getBool(TYDIRPREFERENCEMANAGER, "WireframeOnMovingCamera"));
1792  }
1793  else
1794  {
1795  TYPreferenceManager::setBool(TYDIRPREFERENCEMANAGER, "WireframeOnMovingCamera", false);
1797  }
1798 
1799  // Mise a jour des couleurs a partir des preferences.
1800  // Couleur de fond
1801  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "BackgroundColorR"))
1802  {
1803  float r = NAN, g = NAN, b = NAN;
1804  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "BackgroundColor", r, g, b);
1805  rendererColor[0] = r / 255;
1806  rendererColor[1] = g / 255;
1807  rendererColor[2] = b / 255;
1808  }
1809  else
1810  {
1811  float r = rendererColor[0] * 255;
1812  float g = rendererColor[1] * 255;
1813  float b = rendererColor[2] * 255;
1814  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "BackgroundColor", r, g, b);
1815  }
1816 
1817  getRenderer()->setBackground(rendererColor);
1818 
1819  // Couleur de la grille
1820  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridColorR"))
1821  {
1822  float r = NAN, g = NAN, b = NAN;
1823  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "GridColor", r, g, b);
1824  gridColor[0] = r / 255;
1825  gridColor[1] = g / 255;
1826  gridColor[2] = b / 255;
1827  }
1828  else
1829  {
1830  float r = gridColor[0] * 255;
1831  float g = gridColor[1] * 255;
1832  float b = gridColor[2] * 255;
1833  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "GridColor", r, g, b);
1834  }
1835 
1836  // Couleur de la police
1837  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "FontColorR"))
1838  {
1839  float r = NAN, g = NAN, b = NAN;
1840  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "FontColor", r, g, b);
1841  fontColor[0] = r / 255;
1842  fontColor[1] = g / 255;
1843  fontColor[2] = b / 255;
1844  }
1845  else
1846  {
1847  float r = fontColor[0] * 255;
1848  float g = fontColor[1] * 255;
1849  float b = fontColor[2] * 255;
1850  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "FontColor", r, g, b);
1851  }
1852 
1856  _pOGLScalarBarElement->setFontColor(OColor(fontColor[0], fontColor[1], fontColor[2]));
1857 
1858  // Mise a jour de l'eclairage de la scene.
1859  float intensity = 0.83f;
1860  if ((TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "Luminosite")))
1861  {
1862  intensity = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "Luminosite");
1863  }
1864  else
1865  {
1866  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "Luminosite", intensity);
1867  }
1868 
1869  if (intensity < 0.1f)
1870  {
1871  intensity = 0.1f;
1872  }
1873  _pLightElement->setIntensity(intensity);
1874 
1875  // Mise a jour de la tolerance du picking.
1876  float precisPick = 3.0;
1877  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "PrecisPick"))
1878  {
1879  precisPick = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "PrecisPick");
1880  }
1881  else
1882  {
1883  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "PrecisPick", precisPick);
1884  }
1885  _pPickEditor->setPickTolerance(precisPick);
1887 
1888  // Mise a jour du pas de zoom de la mollette de la souris.
1889  float zoomStep = 1.0f;
1890  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "ZoomStep"))
1891  {
1892  zoomStep = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "ZoomStep");
1893  }
1894  else
1895  {
1896  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "ZoomStep", zoomStep);
1897  }
1898  _pCameraEditor->setWheelStep(zoomStep);
1899  _pDistanceEditor->setWheelStep(zoomStep);
1900  _pPositionEditor->setWheelStep(zoomStep);
1901 
1902  // Mise a jour du pas de l'angle du positionEditor
1903  float angle = 15.0;
1904  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "Angle"))
1905  {
1906  angle = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "Angle");
1907  }
1908  else
1909  {
1910  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "Angle", angle);
1911  }
1912 
1914 
1915  // Mise a jour des fonctions attachees a la souris.
1916  // 2D
1917  // bouton gauche
1918  int mouseLeftButtonFunct2D = 1;
1919  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct2D"))
1920  {
1921  mouseLeftButtonFunct2D =
1922  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct2D");
1923  }
1924 
1925  else
1926  {
1927  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct2D", mouseLeftButtonFunct2D);
1928  }
1929 
1930  switch (mouseLeftButtonFunct2D)
1931  {
1932  case 0:
1934  break;
1935  case 1:
1937  break;
1938  }
1939 
1940  // bouton droit
1941  int mouseRightButtonFunct2D = 0;
1942  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct2D"))
1943  {
1944  mouseRightButtonFunct2D =
1945  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct2D");
1946  }
1947  else
1948  {
1949  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct2D",
1950  mouseRightButtonFunct2D);
1951  }
1952 
1953  switch (mouseRightButtonFunct2D)
1954  {
1955  case 0:
1957  break;
1958  case 1:
1960  break;
1961  }
1962 
1963  // bouton central
1964  int mouseMiddleButtonFunct2D = 0;
1965  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct2D"))
1966  {
1967  mouseMiddleButtonFunct2D =
1968  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct2D");
1969  }
1970  else
1971  {
1972  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct2D",
1973  mouseMiddleButtonFunct2D);
1974  }
1975 
1976  switch (mouseMiddleButtonFunct2D)
1977  {
1978  case 0:
1980  break;
1981  case 1:
1983  break;
1984  }
1985 
1986  // en 3D
1987  // bouton gauche
1988  int mouseLeftButtonFunct3D = 3;
1989  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct3D"))
1990  {
1991  mouseLeftButtonFunct3D =
1992  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct3D");
1993  }
1994  else
1995  {
1996  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct3D", mouseLeftButtonFunct3D);
1997  }
1998 
1999  switch (mouseLeftButtonFunct3D)
2000  {
2001  case 0:
2003  break;
2004  case 1:
2006  break;
2007  case 2:
2009  break;
2010  case 3:
2012  break;
2013  }
2014 
2015  // bouton droit
2016  int mouseRightButtonFunct3D = 0;
2017  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct3D"))
2018  {
2019  mouseRightButtonFunct3D =
2020  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct3D");
2021  }
2022  else
2023  {
2024  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct3D",
2025  mouseRightButtonFunct3D);
2026  }
2027 
2028  switch (mouseRightButtonFunct3D)
2029  {
2030  case 0:
2032  break;
2033  case 1:
2035  break;
2036  case 2:
2038  break;
2039  case 3:
2041  break;
2042  }
2043 
2044  // bouton central
2045  int mouseMiddleButtonFunct3D = 2;
2046  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct3D"))
2047  {
2048  mouseMiddleButtonFunct3D =
2049  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct3D");
2050  }
2051  else
2052  {
2053  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct3D",
2054  mouseMiddleButtonFunct3D);
2055  }
2056 
2057  switch (mouseMiddleButtonFunct3D)
2058  {
2059  case 0:
2061  break;
2062  case 1:
2064  break;
2065  case 2:
2067  break;
2068  case 3:
2070  break;
2071  }
2072 
2073  // Mode shift.
2074  // 2D
2075  // bouton gauche
2076  int mouseShiftLeftButtonFunct2D = 1;
2077  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct2D"))
2078  {
2079  mouseShiftLeftButtonFunct2D =
2080  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct2D");
2081  }
2082  else
2083  {
2084  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct2D",
2085  mouseShiftLeftButtonFunct2D);
2086  }
2087 
2088  switch (mouseShiftLeftButtonFunct2D)
2089  {
2090  case 0:
2092  break;
2093  case 1:
2095  break;
2096  }
2097 
2098  // bouton droit
2099  int mouseShiftRightButtonFunct2D = 0;
2100  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct2D"))
2101  {
2102  mouseShiftRightButtonFunct2D =
2103  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct2D");
2104  }
2105  else
2106  {
2107  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct2D",
2108  mouseShiftRightButtonFunct2D);
2109  }
2110 
2111  switch (mouseShiftRightButtonFunct2D)
2112  {
2113  case 0:
2115  break;
2116  case 1:
2118  break;
2119  }
2120 
2121  // en 3D
2122  // bouton gauche
2123  int mouseShiftLeftButtonFunct3D = 1;
2124  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct3D"))
2125  {
2126  mouseShiftLeftButtonFunct3D =
2127  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct3D");
2128  }
2129  else
2130  {
2131  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct3D",
2132  mouseShiftLeftButtonFunct3D);
2133  }
2134 
2135  switch (mouseShiftLeftButtonFunct3D)
2136  {
2137  case 0:
2139  break;
2140  case 1:
2142  break;
2143  case 2:
2145  break;
2146  case 3:
2148  break;
2149  }
2150 
2151  // bouton droit
2152  int mouseShiftRightButtonFunct3D = 2;
2153  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct3D"))
2154  {
2155  mouseShiftRightButtonFunct3D =
2156  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct3D");
2157  }
2158  else
2159  {
2160  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct3D",
2161  mouseShiftRightButtonFunct3D);
2162  }
2163 
2164  switch (mouseShiftRightButtonFunct3D)
2165  {
2166  case 0:
2168  break;
2169  case 1:
2171  break;
2172  case 2:
2174  break;
2175  case 3:
2177  break;
2178  }
2179 
2180  // Force un update de la camera
2182 
2183  // Update de l'editor courant
2184  // setEditorMode(_lastEditorMode); // DTn : Correction du bug #0009661
2185 
2186  // Mets a jour la structure graphique de l'element
2187  updateElementGraphic(true);
2188 
2189  // Refresh
2190  updateView(false);
2191 }
2192 
2194 {
2196  // On passe en mode Wireframe si l'option est activee et qu'on est
2197  // pas deja dans ce mode
2198  if (_wireframeOnMovingCamera && (currentMode != TYOpenGLRenderer::Wireframe))
2199  {
2200  // On conserve le mode courant
2201  _lastRenderMode = currentMode;
2202  // On passe en Wireframe
2204  }
2205 }
2206 
2208 {
2210  {
2211  // On revient dans le mode courant
2213  }
2214 }
2215 
2217 {
2218  if (_showScale)
2219  {
2220  QVector3D pt0 = _pView->getViewport().displayToWorld(QVector3D(0.0, 0.0, 0.1));
2221  QVector3D pt1 = _pView->getViewport().displayToWorld(QVector3D(200.0, 0.0, 0.1));
2222 
2223  double value = pt0.distanceToPoint(pt1);
2224 
2225  int i = floor(log10(value));
2226  int n = floor(value / pow(10, i));
2227  if (n == 3 || n == 4)
2228  {
2229  n = 5;
2230  }
2231  else if (n >= 6 && n <= 9)
2232  {
2233  n = 1;
2234  i++;
2235  }
2236  double distanceInRealWorld = n * pow(10, i);
2237  double distanceInDisplayWorld = 200.0 * distanceInRealWorld / value;
2238  QString max = QString().setNum(distanceInRealWorld, 'g', 3);
2239  QString mid = QString().setNum(distanceInRealWorld / 2, 'g', 3);
2240  _pOGLScalarBarElement->setTexts("0", mid.toStdString(), max.toStdString());
2241  _pOGLScalarBarElement->setSizes(distanceInDisplayWorld, 8);
2242  }
2243 }
2244 
2246 {
2247  _showScale = show;
2248 
2250 
2252  updateView(false, true);
2253 }
2254 
2255 double TYModelerFrame::getDouble(const QString& title, const QString& txt, double min, double max, double val,
2256  bool& ok, int dec)
2257 {
2258  QLocale loc = QLocale(QLocale::English);
2259  TYInputDialog dialog{};
2260  dialog.setLocale(loc); // Will use a dot
2261  dialog.setWindowTitle(title);
2262  dialog.setLabelText(txt);
2263  dialog.setDoubleRange(min, max);
2264  dialog.setTextValue(QString::number(val));
2265  dialog.setDoubleValue(val);
2266  dialog.setDoubleDecimals(dec);
2267  dialog.setInputMode(QInputDialog::TextInput);
2268  ok = dialog.exec();
2269  return dialog.doubleValue();
2270 }
2271 
2273 {
2274  TYRenderContext renderContext(TYRenderType::Display, TYRenderPass::Default, getView()->getViewport(),
2275  getElement());
2276  renderContext.showDistributedSources = getShowSources();
2277 
2278  return renderContext;
2279 }
All base classes related to 3D manipulation.
@ PERSPECTIVE
Definition: OGLCamera.h:42
@ PARALLEL
Definition: OGLCamera.h:41
@ FREE
Definition: OGLCamera.h:43
gestion de l'interaction entre la vue graphique (2D ou 3D) et le clavier et la souris (fichier header...
TYApplication * getTYApp()
Retourne le pointeur sur l'application.
pour l'application Tympan (fichier header)
gestion de l'edition de la camera (fichier header)
#define min(a, b)
gestion de zoom par zone selectionnee (fichier obsolete)(fichier header)
outil de mesure des distances (fichier header)
gestion des elements selectionnes par picking (fichier header)
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
outil IHM pour une entrée utilisateur (fichier header)
#define IMG(id)
OBox getBoundingBox(TYElement *pElement)
#define TR(id)
Classe generique pour une fenetre de modeleur (fichier header)
Realise le rendu VTK et le rendu OpenGL (fichier header)
gestion de l'element actionne par picking (fichier header)
gestion de la position selon les modes 'moving', 'rotation', 'edition' (fichier header)
Boite de dialogue des parametres d'impression (fichier header)
@ Display
The current render is intended to be displayed on screen.
@ Default
The current render pass is for 3D elements.
const char * name
Repositionnement de la camera en fonction de coordonnees specifiees (fichier header)
Representation graphique d'une source lineique (fichier header)
Representation graphique d'une surface de source (fichier header)
The box class.
Definition: 3d.h:1346
OPoint3D _min
Minimal coordinates of the OBox.
Definition: 3d.h:1423
OPoint3D _max
Maximal coordinates of the OBox.
Definition: 3d.h:1424
Definition: color.h:36
float b
Definition: color.h:38
float r
Definition: color.h:38
float g
Definition: color.h:38
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
void setFromToUp(const QVector3D &_from, const QVector3D &_to, const QVector3D &_up)
Definition: OGLCamera.cpp:296
void getTranslation(double &x, double &y, double &z)
Definition: OGLCamera.cpp:474
void resetZoom(int w=-1, int h=-1)
Definition: OGLCamera.cpp:417
void resetRotations()
Definition: OGLCamera.cpp:458
void setTranslation(double x, double y, double z)
Definition: OGLCamera.cpp:467
CameraType cameraType() const
Definition: OGLCamera.cpp:92
void setSize(int w, int h)
Definition: OGLCamera.cpp:78
void setDistanceStep(NxReal _magnitudeStepUp, NxReal _magnitudeStepFront, NxReal _magnitudeStepLeft)
Definition: OGLCamera.cpp:237
bool getVisibility()
Definition: OGLElement.h:55
void setVisibility(bool bVisible)
Definition: OGLElement.h:51
void setIs3D(bool bIs3D)
Definition: OGLElement.h:59
void setDisplayPosition(double displayPositionX, double displayPositionY)
Definition: OGLElement.h:46
bool getShowGridXZ()
bool getShowGridZY()
void setShowGridXZ(bool bShow)
void setGridDimX(const float gridDimX)
void setShowGridXY(bool bShow)
bool getShowGridXY()
void setGridDimY(const float gridDimY)
void setColor(const OColor &oColor)
void setShowGridZY(bool bShow)
void setGridStep(const float gridStep)
void setIntensity(const float intensity)
void init(int index, OPoint3D position, float intensity)
void setPoint2(const QVector3D &point2)
void setColor(const OColor &oColor)
void setLineWidth(float lineWidth)
void setPoint1(const QVector3D &point1)
void setSizes(float width, float height)
void setTexts(const std::string &text0, const std::string &text1, const std::string &text2)
void setFontColor(const OColor &oFontColor)
void setFont(const QString &qsFontPath)
void setPosition(const QVector3D &position)
void setColor(const OColor &oColor)
void setTextToDisplay(const QString &qsText)
void setFont(const QString &qsFontPath)
The 3D point class.
Definition: 3d.h:487
virtual const char * getClassName() const
Definition: TYElement.h:248
T * _pObj
The real pointer, must derived IRefCount.
Definition: smartptr.h:307
void setWheelStep(float step=1.0)
Met Ã&#160; jour le pas de zoom de la caméra.
virtual void close()
Appeler apres l'utilisation de l'editor.
static void snapToGrid(float &x, float &y, float &z, float &gridMagnStep)
Methode utilitaire qui adapte les coordonnees d'un point pour que celui-ci soit aligne avec la grille...
virtual void disconnect()
Deconnecte cet editor a l'interactor associe.
virtual void init()
Appeler avant l'utilisation de l'editor.
virtual void connect()
Connecte cet editor a l'interactor associe.
int getHistorySize()
Retourne la taille de l'historique.
void setHistorySize(int size)
Definit la taille de l'historique.
LPTYProjet getCurProjet()
Set/Get du projet courant.
TYCalculManager * getCalculManager()
Get du gestionnaire de calculs.
Definition: TYApplication.h:99
bool askForResetResultat()
Previent l'utilisateur que le resultat va etre efface, si celui-ci est valide.
QString getDateModif() const
Get modification date.
Definition: TYCalcul.h:199
bool isInSelection(TYUUID id)
Tests if the element is present in the selection of this Calculation.
Definition: TYCalcul.cpp:1004
QString getDateCreation() const
Set/Get of creation date.
Definition: TYCalcul.h:185
QString getComment() const
Get comments.
Definition: TYCalcul.h:218
Gestion de l'edition en mode camera.
void setMiddleButtonFunction3D(void(TYCameraEditor::*function)())
void setRightButtonFunction3D(void(TYCameraEditor::*function)())
void setShiftRightButtonFunction3D(void(TYCameraEditor::*function)())
void setLeftButtonFunction2D(void(TYCameraEditor::*function)())
void setNavigationOnViewType(int view)
Switch auto entre navi 2D ou 3D.
void setMiddleButtonFunction2D(void(TYCameraEditor::*function)())
void setRightButtonFunction2D(void(TYCameraEditor::*function)())
void setShiftRightButtonFunction2D(void(TYCameraEditor::*function)())
void setLeftButtonFunction3D(void(TYCameraEditor::*function)())
void setShiftLeftButtonFunction2D(void(TYCameraEditor::*function)())
void stopCameraZoom()
Force l'arrêt du mode zoom de la caméra.
void setShiftLeftButtonFunction3D(void(TYCameraEditor::*function)())
void setWheelStep(float step)
gestion de zoom par zone selectionnee (obsolete)
outil de mesure des distances
static bool _gDrawNormals
Indique si les normals doivent etre visible.
OBox boundingBox() const
static bool _gDrawPlafond
Indique si les plafonds doivent etre visible.
gestion des elements selectionnes par picking
TYElement * getParent() const
Definition: TYElement.h:697
virtual QString getName() const
Definition: TYElement.h:682
QString getModele() const
Definition: TYMachine.h:124
QString getCommentaire() const
Definition: TYMachine.h:139
int getCategorie() const
Definition: TYMachine.h:94
QString getConstructeur() const
Definition: TYMachine.h:109
virtual void wheelEvent(QWheelEvent *pEvent)
QToolButton * _pSnapGridBtn
Button to activate the magnetic grid.
void setSnapGridActive(bool state)
virtual void closeEvent(QCloseEvent *pEvent)
void updateElementGraphic(bool force=false)
virtual void leaveEvent(QEvent *pEvent)
int _curViewType
The type of the current view.
QStatusBar * _pStatusBar
Status bar.
LPTYElement getElement()
virtual bool computeCurPos(int x, int y, float *pos)
TYCameraEditor * _pCameraEditor
Manages the camera.
void showScale(bool show)
bool _editorModeAccepted
Indicates if the editing mode has been processed.
OGLScalarBarElement * _pOGLScalarBarElement
Graphic object for representing the scale.
QToolButton * _pShowRaysBtn
Button for displaying rays calculated by ray tracing.
virtual void setRenderModeSlot(int mode)
LPTYElement _pElement
A pointer to the element to edit.
void showPlafond(bool show)
TYRenderWindowInteractor * getView()
QToolButton * _pShowScale
Button for displaying the scale.
virtual void enterEvent(QEvent *pEvent)
TYPositionEditor * _pPositionEditor
Editor for moving elements.
void setEditorModeToCamera()
TYCameraZoneEditor * _pCameraZoneEditor
Editor to define a zoom area for the camera.
OGLTextElement * _pOGLTextElement
2D label to display the type of view.
virtual void resizeEvent(QResizeEvent *pEvent)
TYAbstractSceneEditor * _pCurrentEditor
The current editor.
void setKeepRays(bool keepRays)
virtual ~TYModelerFrame()
void editorModeChanged(int mode)
OGLLineElement * _pOGLLineElementAxeX
Geometry of the Axes.
void setGridLinesActorsVisibility(bool showGridXY, bool showGridXZ, bool showGridZY)
QToolButton * _pShowPlafondBtn
Button for displaying the ceiling of buildings.
void showRays(bool show)
void viewTypeChanged(int)
bool _wireframeOnMovingCamera
Indicates whether to switch to wireframe rendering during camera movement.
QToolButton * _pShowNormalsBtn
Button for displaying normals.
virtual void focusInEvent(QFocusEvent *pEvent)
bool _snapGridActive
Indicates whether or not to activate the magnetic grid.
void setWireframeOnMovingCamera(bool state)
TYActionManager _actionManager
For managing the history.
void aboutToClose()
OGLLightElement * _pLightElement
The default light.
bool getSnapGridActive()
QBoxLayout * _pCtrlLayout
The layout where buttons, etc., are located.
virtual void mouseMoveEvent(QMouseEvent *pEvent)
QGridLayout * _pLayout
The layout of this frame.
QToolButton * _pShowSourcesBtn
Button for displaying point sources.
OGLTextElement * _pOGLTextElementLabelY
virtual void setViewType(int view)
OGLLineElement * _pOGLLineElementX
X and Y axes of the grid.
QStatusBar * statusBar()
QToolButton * _pGridBtn
Button to activate the grid.
bool isElementInCurrentProjet()
OGLGridElement * _pOGLGridElement
TYRenderWindowInteractor * _pView
The graphics window.
void frameResized()
QToolButton * _pCopyBtn
Button for taking a screenshot.
virtual bool close()
virtual float getDefaultZCoord()
Returns default Z coordinate for editors This value will depend on the type of modeler and of the fix...
bool _showPlafond
Indicates whether or not to display or hide the ceiling of buildings.
void showNormals(bool show)
OGLLineElement * _pOGLLineElementAxeZ
QComboBox * _pRenderModeBox
Combo box for rendering mode.
OGLTextElement * _pOGLTextElementLabelX
TYOpenGLRenderer::RenderMode getRenderMode()
bool _showGrid
Indicates whether to display the grid or not.
TYModelerFrame(QWidget *parent=0, const char *name=0, Qt::WindowFlags f=Qt::SubWindow)
bool _showNormals
Indicates whether or not to display or hide normals.
void setCameraCoordinates()
OGLTextElement * _pOGLTextElementLabelZ
virtual TYRenderContext createRenderContext()
bool isElementInCurrentCalcul()
bool askForResetResultat()
bool _showScale
Indicates whether to display the scale or not.
void eltModified(LPTYElement pElt)
int _lastEditorMode
To keep track of the last editing mode.
QToolButton * _pSetCameraCoordinatesBtn
Button to specify camera coordinates.
TYOpenGLRenderer::RenderMode _lastRenderMode
The last current rendering mode.
OGLLineElement * _pOGLLineElementAxeY
void updateCurPosInfo(int x, int y)
float _gridDimX
Grid dimension in X.
float _gridDimY
Grid dimension in Y.
void startMovingRenderMode()
TYElementPicker * _pPicker
For picking.
virtual void setRenderMode(TYOpenGLRenderer::RenderMode mode, bool bUpdateGL)
OGLCamera * _pOGLCameras[NbOfViews]
Cameras for each type of view.
float _gridStep
Grid step.
virtual void updatePreferences()
bool _showRays
Indicates whether or not to display rays.
TYPickEditor * _pPickEditor
Manages the context menu.
OGLLineElement * _pOGLLineElementY
float _gridMagnStep
Magnetic grid step.
QToolButton * _pScreenShotBtn
Button for saving a screenshot.
TYPickEditor * getPickEditor()
virtual void keyPressEvent(QKeyEvent *pEvent)
TYDistanceEditor * _pDistanceEditor
Tools for measuring.
virtual void setEditorMode(int mode)
void showGrid(bool show)
virtual void updateView(bool clipping=true, bool axesAndGrid=true)
virtual void showEvent(QShowEvent *pEvent)
virtual void keyReleaseEvent(QKeyEvent *pEvent)
static double getDouble(const QString &title, const QString &txt, double min, double max, double val, bool &ok, int dec=2)
float _defaultZCoord
Default Z coordinate for editors.
TYOpenGLRenderer * getRenderer()
bool _showSources
Indicates whether or not to display point sources.
QComboBox * _pViewTypeBox
Combo box for selecting the current camera.
void addLight(OGLLightElement *pOGLElementLight)
void addOGLElement(OGLElement *pOGLElement)
void invalidateScene(void)
void removeOGLElement(OGLElement *pOGLElement)
void setBackground(double *bgColor)
void setRenderMode(RenderMode mode)
gestion de l'element actionne par picking
Definition: TYPickEditor.h:40
void usePopup(bool state)
Definition: TYPickEditor.h:104
void setPickTolerance(float tolerance)
Definition: TYPickEditor.h:59
void useHighlight(bool state)
Definition: TYPickEditor.h:97
gestion de la position selon les modes 'moving', 'rotation', 'edition'
void setMode(int mode)
void setPickPointPrecision(float precision)
void setAngleStep(float step)
classe pour une boite de dialogue des parametres d'impression.
Definition: TYPrintDialog.h:51
QGroupBox * _groupBoxSite
Definition: TYPrintDialog.h:80
QCheckBox * _checkBoxCatMachine
Definition: TYPrintDialog.h:73
QCheckBox * _checkBoxDateProjet
Definition: TYPrintDialog.h:64
QCheckBox * _checkBoxNomProjet
Definition: TYPrintDialog.h:65
QCheckBox * _checkBoxNomBatiment
Definition: TYPrintDialog.h:77
QCheckBox * _checkBoxNomSite
Definition: TYPrintDialog.h:75
QCheckBox * _checkBoxDateCalcul
Definition: TYPrintDialog.h:68
QCheckBox * _checkBoxCommentCalcul
Definition: TYPrintDialog.h:67
QGroupBox * _groupBoxMachine
Definition: TYPrintDialog.h:78
QCheckBox * _checkBoxNomCalcul
Definition: TYPrintDialog.h:69
QGroupBox * _groupBoxCalcul
Definition: TYPrintDialog.h:66
QLineEdit * _lineEditPied
Definition: TYPrintDialog.h:83
QLineEdit * _lineEditTete
Definition: TYPrintDialog.h:84
QCheckBox * _checkBoxCommentProjet
Definition: TYPrintDialog.h:62
QCheckBox * _checkBoxNomMachine
Definition: TYPrintDialog.h:72
QCheckBox * _checkBoxModelMachine
Definition: TYPrintDialog.h:74
QGroupBox * _groupBoxProjet
Definition: TYPrintDialog.h:61
QGroupBox * _groupBoxBatiment
Definition: TYPrintDialog.h:79
QLineEdit * _lineEditTitre
Definition: TYPrintDialog.h:86
QCheckBox * _checkBoxAuteurProjet
Definition: TYPrintDialog.h:63
QCheckBox * _checkBoxConstrMachine
Definition: TYPrintDialog.h:71
classe de definition d'un projet.
Definition: TYProjet.h:45
QString getDateModif() const
Get de la date de modification.
Definition: TYProjet.h:131
QString getAuteur() const
Get du nom de l'auteur.
Definition: TYProjet.h:93
QString getComment() const
Get des commentaires.
Definition: TYProjet.h:150
QString getDateCreation() const
Get de la date de creation.
Definition: TYProjet.h:112
LPTYSiteNode getSite()
Get du site.
Definition: TYProjet.h:169
LPTYCalcul getCurrentCalcul()
Set/Get du pointeur du Calcul courant.
Definition: TYProjet.h:426
static bool _gVisible
Indique si toutes les instances sont visibles.
Definition: TYRayGraphic.h:75
QVector3D worldToDisplay(const QVector3D &world) const
QVector3D displayToWorld(const QVector3D &display) const
Le role de cette classe est limite a emettre des signaux pouvant etre utilise pour interagir sur le r...
void mouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
void setActiveCamera(OGLCamera *pCamera)
const TYRenderViewport & getViewport() const
void showInfos(bool state)
TYOpenGLRenderer * getRenderer()
OGLCamera * getActiveCamera()
Repositionnement de la camera en fonction de coordonnees specifiees.