Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYMachineModelerFrame.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 
21 #include <qlayout.h>
22 #include <qcursor.h>
23 #include <QtWidgets>
24 
34 #include "TYMachineModelerFrame.h"
35 
36 #define TR(id) OLocalizator::getString("TYMachineModelerFrame", (id))
37 #define IMG(id) OLocalizator::getPicture("TYMachineModelerFrame", (id))
38 
40 
41 TYMachineModelerFrame::TYMachineModelerFrame(LPTYMachine pMachine, QWidget* parent, const char* name,
42  Qt::WindowFlags f)
43  : TYModelerFrame(parent, name, f)
44 {
45  _nbInstance++;
46  setWindowTitle(TR("id_caption") + " " + QString("%1").arg(_nbInstance));
47 
48  _pCtrlLayout->addSpacing(10);
49 
51  _pCtrlLayout->addStretch(1);
52 
53  // Editors
54  _pBoxEditor = new TYBoxEditor(this);
57 
58  // Cadrage
63 
64  if (pMachine)
65  {
66  setMachine(pMachine);
67  }
68  else
69  {
70  setMachine(new TYMachine());
71  }
72 
74 }
75 
77 {
78  _nbInstance--;
79 
80  if (_pMachine)
81  {
82  _pMachine->drawGraphic(false);
83  }
84 
85  delete _pBoxEditor;
86  delete _pCylinderEditor;
87  delete _pSemiCylinderEditor;
88 }
89 
91 {
93  bool ret = true;
94  if (_pMachine->getNbChild() > 0)
95  {
96  ret = TYModelerFrame::close();
97  }
98  getView()->update();
99  return ret;
100 }
101 
103 {
104  QString caption(TR("id_caption") + " " + QString("%1").arg(_nbInstance));
105 
106  if (_pMachine)
107  {
108  _pMachine->drawGraphic(false);
109  }
110 
111  _pMachine = pMachine;
112 
113  if (_pMachine)
114  {
115  if (!_pMachine->getName().isEmpty())
116  {
117  caption += QString(" : %1").arg(_pMachine->getName());
118  }
119 
120  // On affiche la machine dans ce renderer
121  _pMachine->drawGraphic();
122 
123  // On recadre
124  // fit();
125  }
126 
128  setWindowTitle(caption);
129 
131 }
132 
134 {
135  if (!_editorModeAccepted)
136  {
137  getPickEditor()->usePopup(true);
138  getPickEditor()->useHighlight(false);
139 
140  if (_pCurrentEditor)
141  {
144  }
145 
146  _editorModeAccepted = true;
147 
148  switch (mode)
149  {
150  case AddBoxMode:
152  break;
153  case AddCylMode:
155  break;
156  case AddSemiCylMode:
158  break;
159  default:
160  _editorModeAccepted = false;
161  }
162  }
163 
165 }
166 
168 {
169  if (_pMachine)
170  {
172  }
173 }
174 
175 void TYMachineModelerFrame::closeEvent(QCloseEvent* pEvent)
176 {
177  TYPreferenceManager::saveGeometryToPreferences(metaObject()->className(), this);
178  // If there is no volume in the modeler
179  if (_pMachine->getNbChild() == 0)
180  {
181  // Displaying a warning message
182  QMessageBox::StandardButton msgBox =
183  QMessageBox::warning(this, "", "Le modeleur est vide. Etes-vous sûr de vouloir le fermer ?",
184  QMessageBox::Yes | QMessageBox::No);
185  switch (msgBox)
186  {
187  // The user aborts the closing event
188  case QMessageBox::No:
189  pEvent->ignore();
190  break;
191  // The user ignores the warning
192  case QMessageBox::Yes:
193  emit frameResized();
194  emit aboutToClose();
195  break;
196  default:
197  pEvent->ignore();
198  return;
199  }
200  }
201  // If there are volumes, the signal is emited and the event accepted
202  else
203  {
204  pEvent->accept();
205  emit frameResized();
206  emit aboutToClose();
207  }
208 }
209 
211 {
212  // Grille
213  _gridDimX = 100.0f;
214  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridDimXMachine"))
215  {
216  _gridDimX = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridDimXMachine");
217  }
218  else
219  {
220  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridDimXMachine", _gridDimX);
221  }
222 
223  _gridDimY = 100.0f;
224  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridDimYMachine"))
225  {
226  _gridDimY = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridDimYMachine");
227  }
228  else
229  {
230  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridDimYMachine", _gridDimY);
231  }
232 
233  _gridStep = 5.0f;
234  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridStepMachine"))
235  {
236  _gridStep = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridStepMachine");
237  }
238  else
239  {
240  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridStepMachine", _gridStep);
241  }
242 
243  _gridMagnStep = 1.0f;
244  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine"))
245  {
246  _gridMagnStep = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine");
247  }
248  else
249  {
250  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine", _gridMagnStep);
251  }
255 
256  resizeGrid();
259  (_curViewType == LeftView));
260 
262 }
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 d'une box (fichier header)
gestion de l'edition d'un cylindre (fichier header)
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
Representation graphique d'une machine (fichier header)
#define TR(id)
Modeler specialisee pour l'edition des machines (fichier header)
gestion de l'element actionne par picking (fichier header)
const char * name
gestion de l'edition d'un 1/2 cylindre (fichier header)
void setDefaultZoomFactor(double defaultZoomFactor)
Definition: OGLCamera.cpp:453
virtual void close()
Appeler apres l'utilisation de l'editor.
virtual void disconnect()
Deconnecte cet editor a l'interactor associe.
void setGridMagnStep(float gridMagnStep=1.0)
Met Ã&#160; jour le pas de la grille magnétique.
TYCalculManager * getCalculManager()
Get du gestionnaire de calculs.
Definition: TYApplication.h:99
Gestion de l'edition d'un boite.
Definition: TYBoxEditor.h:41
bool updateAcoustic(TYElement *pElement)
Appelle la methode de calcul acoustique du volume node passe.
gestion de l'edition d'un cylindre
virtual QString getName() const
Definition: TYElement.h:691
static int _nbInstance
Nombre d'instance de type TYMachineModelerFrame.
void setMachine(LPTYMachine pMachine)
TYMachineModelerFrame(LPTYMachine pMachine=0, QWidget *parent=0, const char *name=0, Qt::WindowFlags f=Qt::SubWindow)
virtual void setEditorMode(int mode)
TYBoxEditor * _pBoxEditor
Box editor.
LPTYMachine _pMachine
Un pointeur sur la machine a editer.
virtual void closeEvent(QCloseEvent *pEvent)
TYSemiCylinderEditor * _pSemiCylinderEditor
Semi cylinder editor.
TYCylinderEditor * _pCylinderEditor
Cylinder editor.
virtual void distriSrcs()
Definition: TYMachine.cpp:155
Generic class for a modeler window.
int _curViewType
The type of the current view.
bool _editorModeAccepted
Indicates if the editing mode has been processed.
LPTYElement _pElement
A pointer to the element to edit.
TYRenderWindowInteractor * getView()
TYAbstractSceneEditor * _pCurrentEditor
The current editor.
void setGridLinesActorsVisibility(bool showGridXY, bool showGridXZ, bool showGridZY)
void aboutToClose()
QBoxLayout * _pCtrlLayout
The layout where buttons, etc., are located.
void frameResized()
virtual bool close()
float _gridDimX
Grid dimension in X.
float _gridDimY
Grid dimension in Y.
OGLCamera * _pOGLCameras[NbOfViews]
Cameras for each type of view.
float _gridStep
Grid step.
virtual void updatePreferences()
float _gridMagnStep
Magnetic grid step.
TYPickEditor * getPickEditor()
virtual void setEditorMode(int mode)
void invalidateScene(void)
void usePopup(bool state)
Definition: TYPickEditor.h:104
void useHighlight(bool state)
Definition: TYPickEditor.h:97
TYOpenGLRenderer * getRenderer()
gestion de l'edition d'un 1/2 cylindre