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  delete _pBoxEditor;
89  delete _pCylinderEditor;
90  delete _pSemiCylinderEditor;
91 }
92 
94 {
96  bool ret = true;
97  if (_pMachine->getNbChild() > 0)
98  {
99  ret = TYModelerFrame::close();
100  }
101  getView()->update();
102  return ret;
103 }
104 
106 {
107  QString caption(TR("id_caption") + " " + QString("%1").arg(_nbInstance));
108 
109  if (_pMachine)
110  {
111  _pMachine->drawGraphic(false);
112  }
113 
114  _pMachine = pMachine;
115 
116  if (_pMachine)
117  {
118  if (!_pMachine->getName().isEmpty())
119  {
120  caption += QString(" : %1").arg(_pMachine->getName());
121  }
122 
123  // On affiche la machine dans ce renderer
124  _pMachine->drawGraphic();
125 
126  // On recadre
127  // fit();
128  }
129 
131  setWindowTitle(caption);
132 
134 }
135 
137 {
138  if (!_editorModeAccepted)
139  {
140  getPickEditor()->usePopup(true);
141  getPickEditor()->useHighlight(false);
142 
143  if (_pCurrentEditor)
144  {
147  }
148 
149  _editorModeAccepted = true;
150 
151  switch (mode)
152  {
153  case AddBoxMode:
155  break;
156  case AddCylMode:
158  break;
159  case AddSemiCylMode:
161  break;
162  default:
163  _editorModeAccepted = false;
164  }
165  }
166 
168 }
169 
171 {
172  if (_pMachine)
173  {
175  }
176 }
177 
178 void TYMachineModelerFrame::closeEvent(QCloseEvent* pEvent)
179 {
180  TYPreferenceManager::saveGeometryToPreferences(metaObject()->className(), this);
181  // If there is no volume in the modeler
182  if (_pMachine->getNbChild() == 0)
183  {
184  // Displaying a warning message
185  QMessageBox::StandardButton msgBox =
186  QMessageBox::warning(this, "", "Le modeleur est vide. Etes-vous sûr de vouloir le fermer ?",
187  QMessageBox::Yes | QMessageBox::No);
188  switch (msgBox)
189  {
190  // The user aborts the closing event
191  case QMessageBox::No:
192  pEvent->ignore();
193  break;
194  // The user ignores the warning
195  case QMessageBox::Yes:
196  emit frameResized();
197  emit aboutToClose();
198  break;
199  default:
200  pEvent->ignore();
201  return;
202  }
203  }
204  // If there are volumes, the signal is emited and the event accepted
205  else
206  {
207  pEvent->accept();
208  emit frameResized();
209  emit aboutToClose();
210  }
211 }
212 
214 {
215  // Grille
216  _gridDimX = 100.0f;
217  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridDimXMachine"))
218  {
219  _gridDimX = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridDimXMachine");
220  }
221  else
222  {
223  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridDimXMachine", _gridDimX);
224  }
225 
226  _gridDimY = 100.0f;
227  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridDimYMachine"))
228  {
229  _gridDimY = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridDimYMachine");
230  }
231  else
232  {
233  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridDimYMachine", _gridDimY);
234  }
235 
236  _gridStep = 5.0f;
237  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridStepMachine"))
238  {
239  _gridStep = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridStepMachine");
240  }
241  else
242  {
243  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridStepMachine", _gridStep);
244  }
245 
246  _gridMagnStep = 1.0f;
247  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine"))
248  {
249  _gridMagnStep = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine");
250  }
251  else
252  {
253  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine", _gridMagnStep);
254  }
258 
259  resizeGrid();
262  (_curViewType == LeftView));
263 
265 }
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:682
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