Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYMachineModelerFrame.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
21 #include <qlayout.h>
22 #include <qpushbutton.h>
23 #include <qcursor.h>
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 
50  // Btn Calculer
51  QPushButton* pCalculBtn =
52  new QPushButton(QPixmap(IMG("id_icon_calcul_btn")), "", /*TR("id_calcul_btn"),*/ this);
53  pCalculBtn->setFixedSize(24, 24);
54  _pCtrlLayout->addWidget(pCalculBtn, 0);
55  _pCtrlLayout->addStretch(1);
56  connect(pCalculBtn, &QPushButton::clicked, this, &TYMachineModelerFrame::calculDistribution);
57 
58  // Editors
59  _pBoxEditor = new TYBoxEditor(this);
62 
63  // Cadrage
68 
69  if (pMachine)
70  {
71  setMachine(pMachine);
72  }
73  else
74  {
75  setMachine(new TYMachine());
76  }
77 
79 }
80 
82 {
83  _nbInstance--;
84 
85  if (_pMachine)
86  {
87  _pMachine->drawGraphic(false);
88  }
89 
90  delete _pBoxEditor;
91  delete _pCylinderEditor;
92  delete _pSemiCylinderEditor;
93 }
94 
96 {
98  bool ret = true;
99  if (_pMachine->getNbChild() > 0)
100  {
101  ret = TYModelerFrame::close();
102  }
103  return ret;
104 }
105 
107 {
108  QString caption(TR("id_caption") + " " + QString("%1").arg(_nbInstance));
109 
110  if (_pMachine)
111  {
112  _pMachine->drawGraphic(false);
113  }
114 
115  _pMachine = pMachine;
116 
117  if (_pMachine)
118  {
119  if (!_pMachine->getName().isEmpty())
120  {
121  caption += QString(" : %1").arg(_pMachine->getName());
122  }
123 
124  // On affiche la machine dans ce renderer
125  _pMachine->drawGraphic();
126 
127  // On recadre
128  // fit();
129  }
130 
132  setWindowTitle(caption);
133 
136 }
137 
139 {
140  if (!_editorModeAccepted)
141  {
142  getPickEditor()->usePopup(true);
143  getPickEditor()->useHighlight(false);
144 
145  if (_pCurrentEditor)
146  {
149  }
150 
151  _editorModeAccepted = true;
152 
153  switch (mode)
154  {
155  case AddBoxMode:
157  break;
158  case AddCylMode:
160  break;
161  case AddSemiCylMode:
163  break;
164  default:
165  _editorModeAccepted = false;
166  }
167  }
168 
170 }
171 
173 {
174  if (_pMachine)
175  {
177  }
178 }
179 
180 void TYMachineModelerFrame::closeEvent(QCloseEvent* pEvent)
181 {
182  TYPreferenceManager::saveGeometryToPreferences(metaObject()->className(), this);
183  // If there is no volume in the modeler
184  if (_pMachine->getNbChild() == 0)
185  {
186  // Displaying a warning message
187  QMessageBox::StandardButton msgBox =
188  QMessageBox::warning(this, "", "Le modeleur est vide. Etes-vous sûr de vouloir le fermer ?",
189  QMessageBox::Yes | QMessageBox::No);
190  switch (msgBox)
191  {
192  // The user aborts the closing event
193  case QMessageBox::No:
194  pEvent->ignore();
195  break;
196  // The user ignores the warning
197  case QMessageBox::Yes:
198  emit frameResized();
199  emit aboutToClose();
200  break;
201  default:
202  pEvent->ignore();
203  return;
204  }
205  }
206  // If there are volumes, the signal is emited and the event accepted
207  else
208  {
209  pEvent->accept();
210  emit frameResized();
211  emit aboutToClose();
212  }
213 }
214 
216 {
217  // Grille
218  _gridDimX = 100.0f;
219  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridDimXMachine"))
220  {
221  _gridDimX = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridDimXMachine");
222  }
223  else
224  {
225  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridDimXMachine", _gridDimX);
226  }
227 
228  _gridDimY = 100.0f;
229  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridDimYMachine"))
230  {
231  _gridDimY = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridDimYMachine");
232  }
233  else
234  {
235  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridDimYMachine", _gridDimY);
236  }
237 
238  _gridStep = 5.0f;
239  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridStepMachine"))
240  {
241  _gridStep = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridStepMachine");
242  }
243  else
244  {
245  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridStepMachine", _gridStep);
246  }
247 
248  _gridMagnStep = 1.0f;
249  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine"))
250  {
251  _gridMagnStep = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine");
252  }
253  else
254  {
255  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "GridMagnStepMachine", _gridMagnStep);
256  }
260 
261  resizeGrid();
264  (_curViewType == LeftView));
265 
267 }
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:52
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:835
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:684
static int _nbInstance
Nombre d'instance de type TYMachineModelerFrame.
void setMachine(LPTYMachine pMachine)
virtual void setEditorMode(int mode)
TYBoxEditor * _pBoxEditor
Box editor.
LPTYMachine _pMachine
Un pointeur sur la machine a editer.
TYMachineModelerFrame(LPTYMachine pMachine=0, QWidget *parent=0, const char *name=0, Qt::WindowFlags f=QFlag(0))
virtual void closeEvent(QCloseEvent *pEvent)
TYSemiCylinderEditor * _pSemiCylinderEditor
Semi cylinder editor.
TYCylinderEditor * _pCylinderEditor
Cylinder editor.
virtual void distriSrcs()
Definition: TYMachine.cpp:155
Classe generique pour une fenetre de modeleur.
int _curViewType
Le type de la vue courante.
bool _editorModeAccepted
Indique si le mode d'edition a ete traite.
LPTYElement _pElement
Un pointeur sur l'element a editer.
TYRenderWindowInteractor * getView()
TYAbstractSceneEditor * _pCurrentEditor
L'editor courant.
void setGridLinesActorsVisibility(bool showGridXY, bool showGridXZ, bool showGridZY)
void aboutToClose()
QBoxLayout * _pCtrlLayout
Le layout ou se trouvent les boutons, etc.
TYRenderWindowInteractor * _pView
La fenetre graphique.
void frameResized()
virtual bool close()
float _gridDimX
Dimension de la grille en X.
float _gridDimY
Dimension de la grille en Y.
OGLCamera * _pOGLCameras[NbOfViews]
Les cameras pour chaque type de vue.
float _gridStep
Pas de la grille.
virtual void updatePreferences()
float _gridMagnStep
Pas de la grille magnetique.
TYPickEditor * getPickEditor()
virtual void setEditorMode(int mode)
void updateDisplayList(void)
void setElement(LPTYElement pElt)
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