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 <qpushbutton.h>
23 #include <qcursor.h>
24 #include <QtWidgets>
25 
35 #include "TYMachineModelerFrame.h"
36 
37 #define TR(id) OLocalizator::getString("TYMachineModelerFrame", (id))
38 #define IMG(id) OLocalizator::getPicture("TYMachineModelerFrame", (id))
39 
41 
42 TYMachineModelerFrame::TYMachineModelerFrame(LPTYMachine pMachine, QWidget* parent, const char* name,
43  Qt::WindowFlags f)
44  : TYModelerFrame(parent, name, f)
45 {
46  _nbInstance++;
47  setWindowTitle(TR("id_caption") + " " + QString("%1").arg(_nbInstance));
48 
49  _pCtrlLayout->addSpacing(10);
50 
51  // Btn Calculer
52  QPushButton* pCalculBtn =
53  new QPushButton(QPixmap(IMG("id_icon_calcul_btn")), "", /*TR("id_calcul_btn"),*/ this);
54  pCalculBtn->setFixedSize(24, 24);
55  _pCtrlLayout->addWidget(pCalculBtn, 0);
56  connect(pCalculBtn, &QPushButton::clicked, this, &TYMachineModelerFrame::calculDistribution);
57 
59  _pCtrlLayout->addStretch(1);
60 
61  // Editors
62  _pBoxEditor = new TYBoxEditor(this);
65 
66  // Cadrage
71 
72  if (pMachine)
73  {
74  setMachine(pMachine);
75  }
76  else
77  {
78  setMachine(new TYMachine());
79  }
80 
82 }
83 
85 {
86  _nbInstance--;
87 
88  if (_pMachine)
89  {
90  _pMachine->drawGraphic(false);
91  }
92 
93  delete _pBoxEditor;
94  delete _pCylinderEditor;
95  delete _pSemiCylinderEditor;
96 }
97 
99 {
101  bool ret = true;
102  if (_pMachine->getNbChild() > 0)
103  {
104  ret = TYModelerFrame::close();
105  }
106  getView()->update();
107  return ret;
108 }
109 
111 {
112  QString caption(TR("id_caption") + " " + QString("%1").arg(_nbInstance));
113 
114  if (_pMachine)
115  {
116  _pMachine->drawGraphic(false);
117  }
118 
119  _pMachine = pMachine;
120 
121  if (_pMachine)
122  {
123  if (!_pMachine->getName().isEmpty())
124  {
125  caption += QString(" : %1").arg(_pMachine->getName());
126  }
127 
128  // On affiche la machine dans ce renderer
129  _pMachine->drawGraphic();
130 
131  // On recadre
132  // fit();
133  }
134 
136  setWindowTitle(caption);
137 
139 }
140 
142 {
143  if (!_editorModeAccepted)
144  {
145  getPickEditor()->usePopup(true);
146  getPickEditor()->useHighlight(false);
147 
148  if (_pCurrentEditor)
149  {
152  }
153 
154  _editorModeAccepted = true;
155 
156  switch (mode)
157  {
158  case AddBoxMode:
160  break;
161  case AddCylMode:
163  break;
164  case AddSemiCylMode:
166  break;
167  default:
168  _editorModeAccepted = false;
169  }
170  }
171 
173 }
174 
176 {
177  if (_pMachine)
178  {
180  }
181 }
182 
183 void TYMachineModelerFrame::closeEvent(QCloseEvent* pEvent)
184 {
185  TYPreferenceManager::saveGeometryToPreferences(metaObject()->className(), this);
186  // If there is no volume in the modeler
187  if (_pMachine->getNbChild() == 0)
188  {
189  // Displaying a warning message
190  QMessageBox::StandardButton msgBox =
191  QMessageBox::warning(this, "", "Le modeleur est vide. Etes-vous sûr de vouloir le fermer ?",
192  QMessageBox::Yes | QMessageBox::No);
193  switch (msgBox)
194  {
195  // The user aborts the closing event
196  case QMessageBox::No:
197  pEvent->ignore();
198  break;
199  // The user ignores the warning
200  case QMessageBox::Yes:
201  emit frameResized();
202  emit aboutToClose();
203  break;
204  default:
205  pEvent->ignore();
206  return;
207  }
208  }
209  // If there are volumes, the signal is emited and the event accepted
210  else
211  {
212  pEvent->accept();
213  emit frameResized();
214  emit aboutToClose();
215  }
216 }
217 
219 {
220  // Grille
221  _gridDimX = 100.0f;
222  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridDimXMachine"))
223  {
224  _gridDimX = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridDimXMachine");
225  }
226  else
227  {
228  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridDimXMachine", _gridDimX);
229  }
230 
231  _gridDimY = 100.0f;
232  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridDimYMachine"))
233  {
234  _gridDimY = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridDimYMachine");
235  }
236  else
237  {
238  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridDimYMachine", _gridDimY);
239  }
240 
241  _gridStep = 5.0f;
242  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridStepMachine"))
243  {
244  _gridStep = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridStepMachine");
245  }
246  else
247  {
248  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridStepMachine", _gridStep);
249  }
250 
251  _gridMagnStep = 1.0f;
252  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine"))
253  {
254  _gridMagnStep = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine");
255  }
256  else
257  {
258  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine", _gridMagnStep);
259  }
263 
264  resizeGrid();
267  (_curViewType == LeftView));
268 
270 }
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 IMG(id)
#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