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  _showSources = _pShowSourcesBtn->isChecked();
809 
812  {
813 
814  TYApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
815 
818 
819  if (_pElement && _pElement->getGraphicObject())
820  {
821  // Update l'element associe a ce modeler
822  _pElement->getGraphicObject()->update(true);
823 
825 
826  // Update view
827  updateView();
828  }
829 
830  TYApplication::restoreOverrideCursor();
831  }
832 
833  _pShowSourcesBtn->setChecked(_showSources);
834 }
835 
837 {
838  _showRays = show;
840  {
841 
842  TYApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
843 
845 
846  if (_pElement && _pElement->getGraphicObject())
847  {
848  // Update l'element associe a ce modeler
849  _pElement->getGraphicObject()->update(true);
850 
852 
853  // Update view
854  updateView();
855  }
856 
857  TYApplication::restoreOverrideCursor();
858  }
859 
860  _pShowRaysBtn->setChecked(_showRays);
861 }
862 
863 void TYModelerFrame::setKeepRays(bool keepRays)
864 {
865  _pShowRaysBtn->setEnabled(keepRays);
866 }
867 
869 {
870  _showNormals = show;
871 
873  {
874 
875  TYApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
876 
878 
879  if (_pElement && _pElement->getGraphicObject())
880  {
881  // Update l'element associe a ce modeler
882  _pElement->getGraphicObject()->update(true);
883 
885 
886  // Update view
887  updateView();
888  }
889 
890  TYApplication::restoreOverrideCursor();
891  }
892 
893  _pShowNormalsBtn->setChecked(_showNormals);
894 }
895 
897 {
898  _showPlafond = !show; // inversion entre l'etat variable et du bouton
899 
901  {
902 
903  TYApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
904 
906 
907  if (_pElement && _pElement->getGraphicObject())
908  {
909  // Update l'element associe a ce modeler
910  _pElement->getGraphicObject()->update(true);
911 
913 
914  // Update view
915  updateView();
916  }
917 
918  TYApplication::restoreOverrideCursor();
919  }
920 
921  _pShowPlafondBtn->setChecked(!_showPlafond);
922 }
923 
925 {
926  _snapGridActive = state;
927  _pSnapGridBtn->setChecked(_snapGridActive);
928 }
929 
931 {
933  {
934  TYSetCameraCoordinates* pSetCameraCoordinates = new TYSetCameraCoordinates(this);
935  double x = NAN, y = NAN, z = NAN;
937  pSetCameraCoordinates->setXCoord(x);
938  pSetCameraCoordinates->setYCoord(-z);
939  pSetCameraCoordinates->setZCoord(y);
940  pSetCameraCoordinates->exec();
941 
942  if (pSetCameraCoordinates->result() == QDialog::Accepted)
943  {
944  if (_pView->getActiveCamera())
945  {
946  _pView->getActiveCamera()->setTranslation(pSetCameraCoordinates->getXCoord(),
947  pSetCameraCoordinates->getZCoord(),
948  -pSetCameraCoordinates->getYCoord());
949 
950  // Update view
951  updateView();
952  }
953  }
954  }
955 }
956 
958 {
959  QString filename = QFileDialog::getSaveFileName(this, tr("Save Image"), "",
960  tr("Images PNG (*.png);;Images JPEG (*.jpg *.jpeg)"));
961  if (!filename.isEmpty())
962  {
963  // Snap
964  QImage img = _pView->grabFramebuffer();
965 
966  // Save
967  QPixmap pix = QPixmap::fromImage(img);
968  pix.save(filename);
969  }
970 }
971 
973 {
974  // Snap
975  QImage img = _pView->grabFramebuffer();
976 
977  // Copie dans le presse papier
978  QClipboard* clipboard = QApplication::clipboard();
979  clipboard->setImage(img);
980 }
981 
983 {
984  LPTYProjet pProjet = getTYApp()->getCurProjet();
985  LPTYCalcul pCalcul = NULL;
986  if (pProjet)
987  {
988  pCalcul = pProjet->getCurrentCalcul();
989  }
990 
991  // Print dialog
992  TYPrintDialog* pDialog = new TYPrintDialog(this);
993 
994  if (pProjet == NULL)
995  {
996  pDialog->_groupBoxProjet->setEnabled(false);
997  }
998  if (pCalcul == NULL)
999  {
1000  pDialog->_groupBoxCalcul->setEnabled(false);
1001  }
1002 
1003  if (_pElement)
1004  {
1005  if (dynamic_cast<TYBatiment*>(_pElement._pObj) != nullptr)
1006  {
1007  pDialog->_groupBoxBatiment->show();
1008  }
1009  else if (dynamic_cast<TYMachine*>(_pElement._pObj) != nullptr)
1010  {
1011  pDialog->_groupBoxMachine->show();
1012  }
1013  else if (dynamic_cast<TYSiteNode*>(_pElement._pObj) != nullptr)
1014  {
1015  pDialog->_groupBoxSite->show();
1016  }
1017  }
1018 
1019  if (pDialog->exec() == QDialog::Accepted)
1020  {
1021  QPrinter* printer = new QPrinter();
1022 
1023  QPrintDialog dialog(printer, this);
1024  if (dialog.exec())
1025  {
1026  QPainter paint(printer);
1027 
1028  double w = double(printer->width());
1029  double h = double(printer->height());
1030  double scalew = w / 700;
1031  double scaleh = h / 700;
1032 
1033  // Snap
1034  QImage img = _pView->grabFramebuffer();
1035  img = img.scaled(int(w * 9 / 10), int(h * 2 / 3), Qt::KeepAspectRatio, Qt::SmoothTransformation);
1036  int x = int(double(printer->width() - img.width()) / 2);
1037  int y = int(double(printer->height() - img.height()) * 1 / 3);
1038  QPixmap pm = QPixmap::fromImage(img);
1039  paint.drawPixmap(x, y, pm);
1040 
1041  paint.setFont(QFont("Times", (int)(10 * scaleh)));
1042  int mid =
1043  int(w / 2) - int(paint.fontMetrics().horizontalAdvance(pDialog->_lineEditTete->text()) / 2);
1044  paint.drawText(mid, 20, pDialog->_lineEditTete->text());
1045 
1046  mid = int(w / 2) - int(paint.fontMetrics().horizontalAdvance(pDialog->_lineEditPied->text()) / 2);
1047  paint.drawText(mid, printer->height() - 20, pDialog->_lineEditPied->text());
1048 
1049  paint.setFont(QFont("Times", (int)(15 * scaleh), QFont::Bold));
1050  mid =
1051  int(w / 2) - int(paint.fontMetrics().horizontalAdvance(pDialog->_lineEditTitre->text()) / 2);
1052  paint.drawText(mid, y - 20, pDialog->_lineEditTitre->text());
1053 
1054  x = int(50 * scalew);
1055  int x1 = int(w / 2);
1056  y = int(double(printer->height()) * 2 / 3 + 20 * scaleh);
1057  int stepy = int(10 * scaleh);
1058  paint.setFont(QFont("Times", (int)(10 * scaleh)));
1059 
1060  if (pProjet)
1061  {
1062  if (pDialog->_checkBoxNomProjet->isChecked())
1063  {
1064  paint.drawText(x, y, TR("id_print_nom_projet"));
1065  paint.drawText(x1, y, pProjet->getName());
1066  y += stepy;
1067  }
1068  if (pDialog->_checkBoxAuteurProjet->isChecked())
1069  {
1070  paint.drawText(x, y, TR("id_print_auteur_projet"));
1071  paint.drawText(x1, y, pProjet->getAuteur());
1072  y += stepy;
1073  }
1074  if (pDialog->_checkBoxDateProjet->isChecked())
1075  {
1076  paint.drawText(x, y, TR("id_print_date_creation"));
1077  paint.drawText(x1, y, pProjet->getDateCreation());
1078  y += stepy;
1079  paint.drawText(x, y, TR("id_print_date_modif"));
1080  paint.drawText(x1, y, pProjet->getDateModif());
1081  y += stepy;
1082  }
1083  if (pDialog->_checkBoxCommentProjet->isChecked())
1084  {
1085  paint.drawText(x, y, TR("id_print_comment"));
1086  paint.drawText(x1, y, pProjet->getComment());
1087  y += stepy;
1088  }
1089  }
1090 
1091  if (pCalcul)
1092  {
1093  y += int(double(stepy) * 1.5);
1094  if (pDialog->_checkBoxNomCalcul->isChecked())
1095  {
1096  paint.drawText(x, y, TR("id_print_nom_calcul"));
1097  paint.drawText(x1, y, pCalcul->getName());
1098  y += stepy;
1099  }
1100  if (pDialog->_checkBoxDateCalcul->isChecked())
1101  {
1102  paint.drawText(x, y, TR("id_print_date_creation"));
1103  paint.drawText(x1, y, pCalcul->getDateCreation());
1104  y += stepy;
1105  paint.drawText(x, y, TR("id_print_date_modif"));
1106  paint.drawText(x1, y, pCalcul->getDateModif());
1107  y += stepy;
1108  }
1109  if (pDialog->_checkBoxCommentCalcul->isChecked())
1110  {
1111  paint.drawText(x, y, TR("id_print_comment"));
1112  paint.drawText(x1, y, pCalcul->getComment());
1113  y += stepy;
1114  }
1115  }
1116 
1117  if (_pElement)
1118  {
1119  y += int(double(stepy) * 1.5);
1120  TYElement* pElement = (TYElement*)_pElement;
1121  if (strcmp(_pElement->getClassName(), "TYBatiment") == 0)
1122  {
1123  TYBatiment* pBatiment = (TYBatiment*)pElement;
1124  if (pDialog->_checkBoxNomBatiment->isChecked())
1125  {
1126  paint.drawText(x, y, TR("id_print_nom_batiment"));
1127  paint.drawText(x1, y, pBatiment->getName());
1128  }
1129  }
1130  else if (strcmp(_pElement->getClassName(), "TYMachine") == 0)
1131  {
1132  TYMachine* pMachine = (TYMachine*)pElement;
1133  if (pDialog->_checkBoxNomMachine->isChecked())
1134  {
1135  paint.drawText(x, y, TR("id_print_nom_machine"));
1136  paint.drawText(x1, y, pMachine->getName());
1137  y += stepy;
1138  }
1139  if (pDialog->_checkBoxConstrMachine->isChecked())
1140  {
1141  paint.drawText(x, y, TR("id_print_constr"));
1142  paint.drawText(x1, y, pMachine->getConstructeur());
1143  y += stepy;
1144  }
1145  if (pDialog->_checkBoxModelMachine->isChecked())
1146  {
1147  paint.drawText(x, y, TR("id_print_model"));
1148  paint.drawText(x1, y, pMachine->getModele());
1149  y += stepy;
1150  }
1151  if (pDialog->_checkBoxCatMachine->isChecked())
1152  {
1153  paint.drawText(x, y, TR("id_print_cat"));
1154  paint.drawText(x1, y, QString().setNum(pMachine->getCategorie()));
1155  y += stepy;
1156  }
1157  if (pDialog->_checkBoxCommentProjet->isChecked())
1158  {
1159  paint.drawText(x, y, TR("id_print_comment"));
1160  paint.drawText(x1, y, pMachine->getCommentaire());
1161  }
1162  }
1163  else
1164  {
1165  TYSiteNode* pSite = dynamic_cast<TYSiteNode*>(pElement);
1166  if (pSite != nullptr)
1167  {
1168  if (pDialog->_checkBoxNomSite->isChecked())
1169  {
1170  paint.drawText(x, y, TR("id_print_nom_site"));
1171  paint.drawText(x1, y, pSite->getName());
1172  }
1173  }
1174  }
1175  }
1176  }
1177 
1178  delete printer;
1179  }
1180 }
1181 
1183 {
1184  if (_pElement)
1185  {
1186  if (_pElement->edit(this) == QDialog::Accepted)
1187  {
1188  emit eltModified(_pElement);
1189  }
1190 
1191  // On update ds ts les cas si un child a ete modifie...
1192  _pElement->getGraphicObject()->update(true);
1194  updateView(false, false);
1195  }
1196 }
1197 
1199 {
1200  // XBH: version simplifiee et +logique...
1201 
1202  OBox boundingBox;
1203  LPTYElementGraphic pTYElementGraphic = pElement->getGraphicObject();
1204 
1205  if (pTYElementGraphic != NULL)
1206  {
1207  boundingBox = pTYElementGraphic->boundingBox();
1208  }
1209 
1210  return boundingBox;
1211 }
1212 
1214 {
1215  OBox globalBoundingBox;
1216  if (_pElement)
1217  {
1218  TYElement* pTYElement = (TYElement*)_pElement;
1219  TYProjet* pTYProjet = dynamic_cast<TYProjet*>(pTYElement);
1220  if (pTYProjet != nullptr)
1221  {
1222  TYSiteNode* pTYSiteNode = (TYSiteNode*)pTYProjet->getSite();
1223  pTYElement = pTYSiteNode;
1224  }
1225 
1226  globalBoundingBox = getBoundingBox(pTYElement);
1227  }
1228  return globalBoundingBox;
1229 }
1230 
1232 {
1233  for (auto camera : _pOGLCameras)
1234  {
1235  camera->setSize(_pView->getViewport().width(), _pView->getViewport().height());
1236  }
1237 
1238  int visibilityStates[9];
1239 
1240  // Sauvegarde des etats de visibilite des objets graphiques
1241  // de "decoration", ils ne doivent pas participer au recadrage
1242 #ifndef NO_GRID
1243  visibilityStates[0] = _pOGLGridElement->getShowGridXY();
1244  visibilityStates[1] = _pOGLGridElement->getShowGridXZ();
1245  visibilityStates[2] = _pOGLGridElement->getShowGridZY();
1246 #endif // NO_GRID
1247 
1248  setGridLinesActorsVisibility(false, false, false);
1249 
1250  visibilityStates[3] = _pOGLLineElementAxeX->getVisibility();
1254  visibilityStates[4] = _pOGLTextElementLabelX->getVisibility();
1256  visibilityStates[5] = _pOGLTextElementLabelY->getVisibility();
1258  visibilityStates[6] = _pOGLTextElementLabelZ->getVisibility();
1260 
1261  visibilityStates[7] = _pOGLLineElementX->getVisibility();
1263  visibilityStates[8] = _pOGLLineElementY->getVisibility();
1265 
1266  // az-- : pour tests reperes machines:
1267  OBox globalBoundingBox = getGlobalBoundingBox();
1268 
1269  float xMin = globalBoundingBox._min._x;
1270  float xMax = globalBoundingBox._max._x;
1271  float yMin = globalBoundingBox._min._y;
1272  float yMax = globalBoundingBox._max._y;
1273  float zMin = globalBoundingBox._min._z;
1274  float zMax = globalBoundingBox._max._z;
1275  float xDist = std::max(abs(xMin), abs(xMax)) * 2;
1276  float yDist = std::max(abs(yMin), abs(yMax)) * 2;
1277  float zDist = std::max(abs(zMin), abs(zMax)) * 2;
1278 
1279  // Cameras pour chaque type de vue
1280  QVector3D fromTop{0, 10000, 0};
1281  QVector3D toTop{0, 0, 0};
1282  QVector3D upTop{0, 0, -1};
1283  _pOGLCameras[TopView]->setFromToUp(fromTop, toTop, upTop);
1285  _pOGLCameras[TopView]->resetZoom(xDist, yDist);
1286 
1287  QVector3D fromBottom{0, -10000, 0};
1288  QVector3D toBottom{0, 0, 0};
1289  QVector3D upBottom{0, 0, 1};
1290  _pOGLCameras[BottomView]->setFromToUp(fromBottom, toBottom, upBottom);
1292  _pOGLCameras[BottomView]->resetZoom(xDist, yDist);
1293 
1294  QVector3D fromLeft{-500, 0, 0};
1295  QVector3D toLeft{0, 0, 0};
1296  QVector3D upLeft{0, 1, 0};
1297  _pOGLCameras[LeftView]->setFromToUp(fromLeft, toLeft, upLeft);
1298  _pOGLCameras[LeftView]->resetZoom(yDist, zDist);
1299 
1300  QVector3D fromRight{500, 0, 0};
1301  QVector3D toRight{0, 0, 0};
1302  QVector3D upRight{0, 1, 0};
1303  _pOGLCameras[RightView]->setFromToUp(fromRight, toRight, upRight);
1304  _pOGLCameras[RightView]->resetZoom(yDist, zDist);
1305 
1306  QVector3D fromFront{0, 0, 500};
1307  QVector3D toFront{0, 0, 0};
1308  QVector3D upFront{0, 1, 0};
1309  _pOGLCameras[FrontView]->setFromToUp(fromFront, toFront, upFront);
1310  _pOGLCameras[FrontView]->resetZoom(xDist, zDist);
1311 
1312  QVector3D fromRear{0, 0, -500};
1313  QVector3D toRear{0, 0, 0};
1314  QVector3D upRear{0, 1, 0};
1315  _pOGLCameras[RearView]->setFromToUp(fromRear, toRear, upRear);
1316  _pOGLCameras[RearView]->resetZoom(xDist, zDist);
1317 
1318  QVector3D fromPersp{0, 1000, 1000};
1319  QVector3D toPersp{0, 0, 0};
1320  QVector3D upPersp{0, 1, 0};
1321  _pOGLCameras[PerspView]->setFromToUp(fromPersp, toPersp, upPersp);
1322  _pOGLCameras[PerspView]->resetZoom(xDist, yDist);
1324  _pOGLCameras[PerspView]->setDistanceStep(30, 70, 30);
1325 
1326  QVector3D fromFree{0, 0, 0};
1327  QVector3D toFree{0, 0, 0.1};
1328  QVector3D upFree{0, 1, 0};
1329  _pOGLCameras[FreeView]->setFromToUp(fromFree, toFree, upFree);
1334 
1335  // Restauration des etats de visibilite des objets graphiques
1336 #ifndef NO_GRID
1337  setGridLinesActorsVisibility(visibilityStates[0], visibilityStates[1], visibilityStates[2]);
1338 #endif // NO_GRID
1339  _pOGLLineElementAxeX->setVisibility(visibilityStates[3]);
1340  _pOGLLineElementAxeY->setVisibility(visibilityStates[3]);
1341  _pOGLLineElementAxeZ->setVisibility(visibilityStates[3]);
1342  _pOGLTextElementLabelX->setVisibility(visibilityStates[4]);
1343  _pOGLTextElementLabelY->setVisibility(visibilityStates[5]);
1344  _pOGLTextElementLabelZ->setVisibility(visibilityStates[6]);
1345  _pOGLLineElementX->setVisibility(visibilityStates[7]);
1346  _pOGLLineElementY->setVisibility(visibilityStates[8]);
1347 
1349  updateView();
1350 }
1351 
1352 void TYModelerFrame::updateView(bool clipping /*=true*/, bool axesAndGrid /*=true*/)
1353 {
1354  OGLCamera* activeCamera = _pView->getActiveCamera();
1355  if (activeCamera)
1356  {
1357  QRect viewport = _pView->getViewport();
1358  activeCamera->setSize(viewport.width(), viewport.height());
1359  if (axesAndGrid)
1360  {
1361  updateAxes();
1362  updateGrid();
1363  updateCurPosInfo(0, 0);
1364  updateScale();
1365  }
1366 
1367  if (clipping)
1368  {
1369  // Update le render mode
1370  setRenderMode(getRenderMode(), false);
1371  }
1372  _pOGLTextElement->setDisplayPosition(7, viewport.height() - 20);
1374  QVector3D(viewport.width() - _pOGLScalarBarElement->getWidth() * 0.5 - 50, 50, 0));
1376 
1377  // RNU
1378  //_pView->getRenderer()->invalidateScene();
1379 
1380  // Update la vue 3D
1381  _pView->update();
1382  }
1383 }
1384 
1386 {
1393 
1394  QVector3D org = _pView->getViewport().displayToWorld(QVector3D(50, 50, 0.1));
1395 
1399 
1400  QVector3D extX, extY, extZ;
1401 
1402  switch (getCurrentView())
1403  {
1404  case TopView:
1405  {
1406  extX = _pView->getViewport().displayToWorld(QVector3D(90, 50, 0.1));
1407  extY = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1408  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 50, 40.1));
1412  }
1413  break;
1414  case BottomView:
1415  {
1416  extX = _pView->getViewport().displayToWorld(QVector3D(10, 50, 0.1));
1417  extY = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1418  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 50, -40.1));
1422  }
1423  break;
1424  case LeftView:
1425  {
1426  extX = _pView->getViewport().displayToWorld(QVector3D(50, 50, 40.1));
1427  extY = _pView->getViewport().displayToWorld(QVector3D(10, 50, 0.1));
1428  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1432  }
1433  break;
1434  case RightView:
1435  {
1436  extX = _pView->getViewport().displayToWorld(QVector3D(50, 50, -40.1));
1437  extY = _pView->getViewport().displayToWorld(QVector3D(90, 50, 0.1));
1438  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1442  }
1443  break;
1444  case FrontView:
1445  {
1446  extX = _pView->getViewport().displayToWorld(QVector3D(90, 50, 0.1));
1447  extY = _pView->getViewport().displayToWorld(QVector3D(50, 50, 40.1));
1448  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1452  }
1453  break;
1454  case RearView:
1455  {
1456  extX = _pView->getViewport().displayToWorld(QVector3D(10, 50, 0.1));
1457  extY = _pView->getViewport().displayToWorld(QVector3D(50, 50, -40.1));
1458  extZ = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1462  }
1463  break;
1464  case PerspView:
1465  case FreeView:
1466  {
1467  QVector3D org2 = _pView->getViewport().displayToWorld(QVector3D(50, 90, 0.1));
1468  double dist = org.distanceToPoint(org2);
1469  extX.setX(org.x() + dist);
1470  extX.setY(org.y());
1471  extX.setZ(org.z());
1472  extY.setX(org.x());
1473  extY.setY(org.y());
1474  extY.setZ(org.z() - dist);
1475  extZ.setX(org.x());
1476  extZ.setY(org.y() + dist);
1477  extZ.setZ(org.z());
1478 
1479  QVector3D dispX = _pView->getViewport().worldToDisplay(extX);
1480  QVector3D dispY = _pView->getViewport().worldToDisplay(extY);
1481  QVector3D dispZ = _pView->getViewport().worldToDisplay(extZ);
1482 
1483  _pOGLTextElementLabelX->setDisplayPosition(dispX.x(), dispX.y());
1484  _pOGLTextElementLabelY->setDisplayPosition(dispY.x(), dispY.y());
1485  _pOGLTextElementLabelZ->setDisplayPosition(dispZ.x(), dispZ.y());
1486  }
1487  break;
1488  }
1489 
1493 }
1494 
1495 void TYModelerFrame::keyPressEvent(QKeyEvent* pEvent)
1496 {
1497  switch (pEvent->key())
1498  {
1499  case Qt::Key_1:
1501  break;
1502  case Qt::Key_2:
1504  break;
1505  case Qt::Key_3:
1507  break;
1508  case Qt::Key_4:
1510  break;
1511  case Qt::Key_5:
1513  break;
1514  case Qt::Key_V:
1516  break;
1517  case Qt::Key_I:
1519  break;
1520  case Qt::Key_G:
1521  showGrid(!_showGrid);
1522  break;
1523  case Qt::Key_R:
1524  {
1525  int nextRenderMode = (getRenderMode() + 1) % TYOpenGLRenderer::NbOfRenderMode;
1526  setRenderMode(static_cast<TYOpenGLRenderer::RenderMode>(nextRenderMode), true);
1527  break;
1528  }
1529  case Qt::Key_W:
1531  break;
1532  case Qt::Key_S:
1534  break;
1535  case Qt::Key_Control:
1536  setSnapGridActive(false);
1537  break;
1538  case Qt::Key_C:
1539  if (pEvent->modifiers() == Qt::ControlModifier)
1540  {
1541  copy();
1542  }
1543  else
1544  {
1546  }
1547  break;
1548  case Qt::Key_F:
1549  case Qt::Key_F5:
1550  fit();
1551  break;
1552  default:
1553  TYApplication::sendEvent(_pView, pEvent);
1554  }
1555 }
1556 
1557 void TYModelerFrame::keyReleaseEvent(QKeyEvent* pEvent)
1558 {
1559  switch (pEvent->key())
1560  {
1561  case Qt::Key_Control:
1562  setSnapGridActive(true);
1563  break;
1564  default:
1565  TYApplication::sendEvent(_pView, pEvent);
1566  }
1567 }
1568 
1569 void TYModelerFrame::mouseMoveEvent(QMouseEvent* pEvent) {}
1570 
1572 {
1573  // On recupere la pos du curseur
1574 
1575  // Calcul des coords
1576  float* pos = new float[3];
1577 
1578  if (computeCurPos(x, y, pos))
1579  {
1580  // Si la grille magnetique est activee
1581  if (getSnapGridActive())
1582  {
1583  TYAbstractSceneEditor::snapToGrid(pos[0], pos[1], pos[2], _gridMagnStep);
1584  }
1585 
1586  // Formatage du msg
1587  QString msg("pos : (%1, %2, %3)");
1588  // On inverse y et z, et -y... (VTK to TY)
1589  msg = msg.arg(pos[0], 0, 'f', 2).arg(-pos[2], 0, 'f', 2).arg(pos[1], 0, 'f', 2);
1590  // Affichage
1591  statusBar()->showMessage(msg);
1592  }
1593  else
1594  {
1595  if (getCurrentView() == FreeView)
1596  {
1597  double x = NAN, y = NAN, z = NAN;
1598  _pView->getActiveCamera()->getTranslation(x, y, z);
1599  QString msg = QString("camera pos : (%1, %2, %3)").arg(x).arg(-z).arg(y);
1600  statusBar()->showMessage(msg);
1601  }
1602  else
1603  {
1604  statusBar()->showMessage("");
1605  }
1606  }
1607 
1608  delete[] pos;
1609 }
1610 
1611 // float* TYModelerFrame::computeCurPos(int x, int y)
1612 bool TYModelerFrame::computeCurPos(int x, int y, float* ret)
1613 {
1614  int view = getCurrentView();
1615  if ((view != PerspView) && (view != FreeView))
1616  {
1617  // Position du curseur
1618  QVector3D pos =
1619  _pView->getViewport().displayToWorld(QVector3D(x, _pView->getViewport().height() - y, 0));
1620  ret[0] = pos.x();
1621  ret[1] = pos.y();
1622  ret[2] = pos.z();
1623 
1624  switch (getCurrentView())
1625  {
1626  case TopView:
1627  ret[1] = 0.0;
1628  break;
1629  case BottomView:
1630  ret[1] = 0.0;
1631  break;
1632  case LeftView:
1633  ret[0] = 0.0;
1634  break;
1635  case RightView:
1636  ret[0] = 0.0;
1637  break;
1638  case FrontView:
1639  ret[2] = 0.0;
1640  break;
1641  case RearView:
1642  ret[2] = 0.0;
1643  break;
1644  }
1645 
1646  return true;
1647  }
1648 
1649  return false;
1650 }
1651 
1653 {
1654  return _defaultZCoord;
1655 }
1656 
1657 void TYModelerFrame::setGridLinesActorsVisibility(bool showGridXY, bool showGridXZ, bool showGridZY)
1658 {
1659 #ifndef NO_GRID
1660  _pOGLGridElement->setShowGridXY(showGridXY);
1661  _pOGLGridElement->setShowGridXZ(showGridXZ);
1662  _pOGLGridElement->setShowGridZY(showGridZY);
1663 #endif // NO_GRID
1664 }
1665 
1666 void TYModelerFrame::wheelEvent(QWheelEvent* pEvent)
1667 {
1668  // Reroute l'event sur le TYRenderWindowInteractor
1669  TYApplication::sendEvent(_pView, pEvent);
1670 }
1671 
1672 void TYModelerFrame::resizeEvent(QResizeEvent* pEvent)
1673 {
1674  // CLM-NT33 : maximized handling and main window title
1675  emit frameResized();
1676  updateView();
1677 }
1678 
1679 void TYModelerFrame::focusInEvent(QFocusEvent* pEvent)
1680 {
1681  updateView();
1682 }
1683 
1684 void TYModelerFrame::showEvent(QShowEvent* pEvent)
1685 {
1686  if (_firstTimeShown)
1687  {
1688  TYPreferenceManager::loadGeometryFromPreferences(metaObject()->className(), this);
1689  _firstTimeShown = false;
1690  }
1691  updateView();
1692 }
1693 
1694 void TYModelerFrame::closeEvent(QCloseEvent* pEvent)
1695 {
1696  TYPreferenceManager::saveGeometryToPreferences(metaObject()->className(), this);
1697  pEvent->accept();
1698  emit frameResized();
1699  emit aboutToClose();
1700 
1701  // CLM-NT35 : Gestion du maximized et titre fenetre principal
1702 }
1703 
1704 void TYModelerFrame::enterEvent(QEvent* pEvent)
1705 {
1706  /* _pView->getRenderer()->invalidateScene();
1707  updateView();
1708  _pView->getRenderer()->invalidateScene();
1709  updateView();*/
1710  emit mouseEnter();
1711 }
1712 
1713 void TYModelerFrame::leaveEvent(QEvent* pEvent)
1714 {
1715  emit mouseLeave();
1716 }
1717 
1719 {
1720  if ((getCurrentView() == PerspView) || (getCurrentView() == FreeView))
1721  {
1722  _pOGLLineElementX->setPoint1(QVector3D(0, 0, _gridDimY / 2));
1723  _pOGLLineElementX->setPoint2(QVector3D(0, 0, -_gridDimY / 2));
1724 
1725  _pOGLLineElementY->setPoint1(QVector3D(_gridDimX / 2, 0, 0));
1726  _pOGLLineElementY->setPoint2(QVector3D(-_gridDimX / 2, 0, 0));
1727  }
1728  else
1729  {
1730  QRect viewport = _pView->getViewport();
1731  int gridXMax = viewport.width();
1732  int gridYMax = viewport.height();
1733  if (gridXMax == 0)
1734  {
1735  gridXMax = 100;
1736  }
1737  if (gridYMax == 0)
1738  {
1739  gridYMax = 100;
1740  }
1741 
1742  // getCenter
1743  QVector3D center = _pView->getViewport().worldToDisplay(QVector3D(0, 0, 0));
1744 
1745  // X
1746  QVector3D xAxisPoint1 = _pView->getViewport().displayToWorld(QVector3D(center.x(), 0, 0));
1747  QVector3D xAxisPoint2 = _pView->getViewport().displayToWorld(QVector3D(center.x(), gridYMax, 0));
1748  _pOGLLineElementX->setPoint1(xAxisPoint1);
1749  if (xAxisPoint1 != xAxisPoint2)
1750  {
1751  _pOGLLineElementX->setPoint2(xAxisPoint2);
1752  }
1753 
1754  // Y
1755  QVector3D yAxisPoint1 = _pView->getViewport().displayToWorld(QVector3D(0, center.y(), 0));
1756  QVector3D yAxisPoint2 = _pView->getViewport().displayToWorld(QVector3D(gridXMax, center.y(), 0));
1757  _pOGLLineElementY->setPoint1(yAxisPoint1);
1758  if (yAxisPoint1 != yAxisPoint2)
1759  {
1760  _pOGLLineElementY->setPoint2(yAxisPoint2);
1761  }
1762  }
1763 }
1764 
1765 void TYModelerFrame::updateElementGraphic(bool force /* = false */)
1766 {
1767  if (_pElement && _pElement->getGraphicObject())
1768  {
1769  _pElement->getGraphicObject()->update(force);
1770  }
1771 }
1772 
1774 {
1778 
1779  _pOGLLineElementX->setColor(OColor(gridColor[0], gridColor[1], gridColor[2]));
1780  _pOGLLineElementY->setColor(OColor(gridColor[0], gridColor[1], gridColor[2]));
1781 }
1782 
1784 {
1785  // Mise a jour de la taille de l'historique de l'Action Manager
1786  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "HistoSize"))
1787  {
1788  _actionManager.setHistorySize(TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "HistoSize"));
1789  }
1790  else
1791  {
1792  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "HistoSize", _actionManager.getHistorySize());
1793  }
1794 
1795  // Mise a jour de l'etat d'activation du delplacement de camera en mode Wireframe
1796  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "WireframeOnMovingCamera"))
1797  {
1799  TYPreferenceManager::getBool(TYDIRPREFERENCEMANAGER, "WireframeOnMovingCamera"));
1800  }
1801  else
1802  {
1803  TYPreferenceManager::setBool(TYDIRPREFERENCEMANAGER, "WireframeOnMovingCamera", false);
1805  }
1806 
1807  // Mise a jour des couleurs a partir des preferences.
1808  // Couleur de fond
1809  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "BackgroundColorR"))
1810  {
1811  float r = NAN, g = NAN, b = NAN;
1812  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "BackgroundColor", r, g, b);
1813  rendererColor[0] = r / 255;
1814  rendererColor[1] = g / 255;
1815  rendererColor[2] = b / 255;
1816  }
1817  else
1818  {
1819  float r = rendererColor[0] * 255;
1820  float g = rendererColor[1] * 255;
1821  float b = rendererColor[2] * 255;
1822  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "BackgroundColor", r, g, b);
1823  }
1824 
1825  getRenderer()->setBackground(rendererColor);
1826 
1827  // Couleur de la grille
1828  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridColorR"))
1829  {
1830  float r = NAN, g = NAN, b = NAN;
1832  gridColor[0] = r / 255;
1833  gridColor[1] = g / 255;
1834  gridColor[2] = b / 255;
1835  }
1836  else
1837  {
1838  float r = gridColor[0] * 255;
1839  float g = gridColor[1] * 255;
1840  float b = gridColor[2] * 255;
1841  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "GridColor", r, g, b);
1842  }
1843 
1844  // Couleur de la police
1845  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "FontColorR"))
1846  {
1847  float r = NAN, g = NAN, b = NAN;
1849  fontColor[0] = r / 255;
1850  fontColor[1] = g / 255;
1851  fontColor[2] = b / 255;
1852  }
1853  else
1854  {
1855  float r = fontColor[0] * 255;
1856  float g = fontColor[1] * 255;
1857  float b = fontColor[2] * 255;
1858  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "FontColor", r, g, b);
1859  }
1860 
1864  _pOGLScalarBarElement->setFontColor(OColor(fontColor[0], fontColor[1], fontColor[2]));
1865 
1866  // Mise a jour de l'eclairage de la scene.
1867  float intensity = 0.83f;
1868  if ((TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "Luminosite")))
1869  {
1870  intensity = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "Luminosite");
1871  }
1872  else
1873  {
1874  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "Luminosite", intensity);
1875  }
1876 
1877  if (intensity < 0.1f)
1878  {
1879  intensity = 0.1f;
1880  }
1881  _pLightElement->setIntensity(intensity);
1882 
1883  // Mise a jour de la tolerance du picking.
1884  float precisPick = 3.0;
1885  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "PrecisPick"))
1886  {
1887  precisPick = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "PrecisPick");
1888  }
1889  else
1890  {
1891  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "PrecisPick", precisPick);
1892  }
1893  _pPickEditor->setPickTolerance(precisPick);
1895 
1896  // Mise a jour du pas de zoom de la mollette de la souris.
1897  float zoomStep = 1.0f;
1898  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "ZoomStep"))
1899  {
1900  zoomStep = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "ZoomStep");
1901  }
1902  else
1903  {
1904  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "ZoomStep", zoomStep);
1905  }
1906  _pCameraEditor->setWheelStep(zoomStep);
1907  _pDistanceEditor->setWheelStep(zoomStep);
1908  _pPositionEditor->setWheelStep(zoomStep);
1909 
1910  // Mise a jour du pas de l'angle du positionEditor
1911  float angle = 15.0;
1912  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "Angle"))
1913  {
1914  angle = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "Angle");
1915  }
1916  else
1917  {
1918  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "Angle", angle);
1919  }
1920 
1922 
1923  // Mise a jour des fonctions attachees a la souris.
1924  // 2D
1925  // bouton gauche
1926  int mouseLeftButtonFunct2D = 1;
1927  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct2D"))
1928  {
1929  mouseLeftButtonFunct2D =
1930  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct2D");
1931  }
1932 
1933  else
1934  {
1935  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct2D", mouseLeftButtonFunct2D);
1936  }
1937 
1938  switch (mouseLeftButtonFunct2D)
1939  {
1940  case 0:
1942  break;
1943  case 1:
1945  break;
1946  }
1947 
1948  // bouton droit
1949  int mouseRightButtonFunct2D = 0;
1950  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct2D"))
1951  {
1952  mouseRightButtonFunct2D =
1953  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct2D");
1954  }
1955  else
1956  {
1957  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct2D",
1958  mouseRightButtonFunct2D);
1959  }
1960 
1961  switch (mouseRightButtonFunct2D)
1962  {
1963  case 0:
1965  break;
1966  case 1:
1968  break;
1969  }
1970 
1971  // bouton central
1972  int mouseMiddleButtonFunct2D = 0;
1973  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct2D"))
1974  {
1975  mouseMiddleButtonFunct2D =
1976  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct2D");
1977  }
1978  else
1979  {
1980  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct2D",
1981  mouseMiddleButtonFunct2D);
1982  }
1983 
1984  switch (mouseMiddleButtonFunct2D)
1985  {
1986  case 0:
1988  break;
1989  case 1:
1991  break;
1992  }
1993 
1994  // en 3D
1995  // bouton gauche
1996  int mouseLeftButtonFunct3D = 3;
1997  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct3D"))
1998  {
1999  mouseLeftButtonFunct3D =
2000  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct3D");
2001  }
2002  else
2003  {
2004  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseLeftButtonFunct3D", mouseLeftButtonFunct3D);
2005  }
2006 
2007  switch (mouseLeftButtonFunct3D)
2008  {
2009  case 0:
2011  break;
2012  case 1:
2014  break;
2015  case 2:
2017  break;
2018  case 3:
2020  break;
2021  }
2022 
2023  // bouton droit
2024  int mouseRightButtonFunct3D = 0;
2025  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct3D"))
2026  {
2027  mouseRightButtonFunct3D =
2028  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct3D");
2029  }
2030  else
2031  {
2032  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseRightButtonFunct3D",
2033  mouseRightButtonFunct3D);
2034  }
2035 
2036  switch (mouseRightButtonFunct3D)
2037  {
2038  case 0:
2040  break;
2041  case 1:
2043  break;
2044  case 2:
2046  break;
2047  case 3:
2049  break;
2050  }
2051 
2052  // bouton central
2053  int mouseMiddleButtonFunct3D = 2;
2054  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct3D"))
2055  {
2056  mouseMiddleButtonFunct3D =
2057  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct3D");
2058  }
2059  else
2060  {
2061  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseMiddleButtonFunct3D",
2062  mouseMiddleButtonFunct3D);
2063  }
2064 
2065  switch (mouseMiddleButtonFunct3D)
2066  {
2067  case 0:
2069  break;
2070  case 1:
2072  break;
2073  case 2:
2075  break;
2076  case 3:
2078  break;
2079  }
2080 
2081  // Mode shift.
2082  // 2D
2083  // bouton gauche
2084  int mouseShiftLeftButtonFunct2D = 1;
2085  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct2D"))
2086  {
2087  mouseShiftLeftButtonFunct2D =
2088  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct2D");
2089  }
2090  else
2091  {
2092  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct2D",
2093  mouseShiftLeftButtonFunct2D);
2094  }
2095 
2096  switch (mouseShiftLeftButtonFunct2D)
2097  {
2098  case 0:
2100  break;
2101  case 1:
2103  break;
2104  }
2105 
2106  // bouton droit
2107  int mouseShiftRightButtonFunct2D = 0;
2108  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct2D"))
2109  {
2110  mouseShiftRightButtonFunct2D =
2111  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct2D");
2112  }
2113  else
2114  {
2115  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct2D",
2116  mouseShiftRightButtonFunct2D);
2117  }
2118 
2119  switch (mouseShiftRightButtonFunct2D)
2120  {
2121  case 0:
2123  break;
2124  case 1:
2126  break;
2127  }
2128 
2129  // en 3D
2130  // bouton gauche
2131  int mouseShiftLeftButtonFunct3D = 1;
2132  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct3D"))
2133  {
2134  mouseShiftLeftButtonFunct3D =
2135  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct3D");
2136  }
2137  else
2138  {
2139  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseShiftLeftButtonFunct3D",
2140  mouseShiftLeftButtonFunct3D);
2141  }
2142 
2143  switch (mouseShiftLeftButtonFunct3D)
2144  {
2145  case 0:
2147  break;
2148  case 1:
2150  break;
2151  case 2:
2153  break;
2154  case 3:
2156  break;
2157  }
2158 
2159  // bouton droit
2160  int mouseShiftRightButtonFunct3D = 2;
2161  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct3D"))
2162  {
2163  mouseShiftRightButtonFunct3D =
2164  TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct3D");
2165  }
2166  else
2167  {
2168  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "MouseShiftRightButtonFunct3D",
2169  mouseShiftRightButtonFunct3D);
2170  }
2171 
2172  switch (mouseShiftRightButtonFunct3D)
2173  {
2174  case 0:
2176  break;
2177  case 1:
2179  break;
2180  case 2:
2182  break;
2183  case 3:
2185  break;
2186  }
2187 
2188  // Force un update de la camera
2190 
2191  // Update de l'editor courant
2192  // setEditorMode(_lastEditorMode); // DTn : Correction du bug #0009661
2193 
2194  // Mets a jour la structure graphique de l'element
2195  updateElementGraphic(true);
2196 
2197  // Refresh
2198  updateView(false);
2199 }
2200 
2202 {
2204  // On passe en mode Wireframe si l'option est activee et qu'on est
2205  // pas deja dans ce mode
2206  if (_wireframeOnMovingCamera && (currentMode != TYOpenGLRenderer::Wireframe))
2207  {
2208  // On conserve le mode courant
2209  _lastRenderMode = currentMode;
2210  // On passe en Wireframe
2212  }
2213 }
2214 
2216 {
2218  {
2219  // On revient dans le mode courant
2221  }
2222 }
2223 
2225 {
2226  if (_showScale)
2227  {
2228  QVector3D pt0 = _pView->getViewport().displayToWorld(QVector3D(0.0, 0.0, 0.1));
2229  QVector3D pt1 = _pView->getViewport().displayToWorld(QVector3D(200.0, 0.0, 0.1));
2230 
2231  double value = pt0.distanceToPoint(pt1);
2232 
2233  int i = floor(log10(value));
2234  int n = floor(value / pow(10, i));
2235  if (n == 3 || n == 4)
2236  {
2237  n = 5;
2238  }
2239  else if (n >= 6 && n <= 9)
2240  {
2241  n = 1;
2242  i++;
2243  }
2244  double distanceInRealWorld = n * pow(10, i);
2245  double distanceInDisplayWorld = 200.0 * distanceInRealWorld / value;
2246  QString max = QString().setNum(distanceInRealWorld, 'g', 3);
2247  QString mid = QString().setNum(distanceInRealWorld / 2, 'g', 3);
2248  _pOGLScalarBarElement->setTexts("0", mid.toStdString(), max.toStdString());
2249  _pOGLScalarBarElement->setSizes(distanceInDisplayWorld, 8);
2250  }
2251 }
2252 
2254 {
2255  _showScale = show;
2256 
2258 
2260  updateView(false, true);
2261 }
2262 
2263 double TYModelerFrame::getDouble(const QString& title, const QString& txt, double min, double max, double val,
2264  bool& ok, int dec)
2265 {
2266  QLocale loc = QLocale(QLocale::English);
2267  TYInputDialog dialog{};
2268  dialog.setLocale(loc); // Will use a dot
2269  dialog.setWindowTitle(title);
2270  dialog.setLabelText(txt);
2271  dialog.setDoubleRange(min, max);
2272  dialog.setTextValue(QString::number(val));
2273  dialog.setDoubleValue(val);
2274  dialog.setDoubleDecimals(dec);
2275  dialog.setInputMode(QInputDialog::TextInput);
2276  ok = dialog.exec();
2277  return dialog.doubleValue();
2278 }
All base classes related to 3D manipulation.
@ PERSPECTIVE
Definition: OGLCamera.h:42
@ PARALLEL
Definition: OGLCamera.h:41
@ FREE
Definition: OGLCamera.h:43
QColor getColor
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)
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:31
float b
Definition: color.h:33
float r
Definition: color.h:33
float g
Definition: color.h:33
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:706
virtual QString getName() const
Definition: TYElement.h:691
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.
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)
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
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.
static bool _gVisible
Indique si toutes les instances sont visibles.
static bool _gVisible
Indique si toutes les instances sont visibles.