Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSilosEditor.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 <math.h>
22 #include <qinputdialog.h>
23 
24 #include "Tympan/core/logging.h"
37 #include "TYSilosEditor.h"
38 
39 #define TR(id) OLocalizator::getString("TYSilosEditor", (id))
40 
42 {
45  OColor oLineColor;
46  oLineColor.r = 1.0;
47  oLineColor.g = 0.0;
48  oLineColor.b = 0.0;
49  _pOGLRectangleElement->setColor(oLineColor);
50  _pOGLRectangleElement->setPoint0(QVector3D(0.0, 0.0, 0.0));
51  _pOGLRectangleElement->setPoint1(QVector3D(0.0, 0.0, 0.0));
52  _pOGLRectangleElement->setPoint2(QVector3D(0.0, 0.0, 0.0));
53  _pOGLRectangleElement->setPoint3(QVector3D(0.0, 0.0, 0.0));
55 
56  _moving = false;
57  _active = false;
59 }
60 
62 {
64  delete _pOGLRectangleElement;
65 }
66 
68 
70 {
71  _moving = false;
72  _active = false;
73 
74  showText(false);
75 
77  _pInteractor->update();
78 }
79 
81 {
82  cancel();
83 }
84 
86 
88 {
89  if (view == TYModelerFrame::TopView)
90  {
91  _active = true;
92  }
93  else
94  {
95  _active = false;
96  }
97 }
98 
99 void TYSilosEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
100 {
101  if ((button == Qt::LeftButton) && _active)
102  {
103  // Init points
104  _pOGLRectangleElement->setPoint0(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
105  _pOGLRectangleElement->setPoint1(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
106  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
107  _pOGLRectangleElement->setPoint3(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
108  _moving = true;
109  }
110 }
111 
112 void TYSilosEditor::slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
113 {
114  if ((button == Qt::LeftButton) && _active && _moving)
115  {
116  _moving = false;
117 
118  float pt0[2], pt1[2], pt2[2];
122  pt0[0] = point0.x();
123  pt0[1] = point0.z();
124  pt1[0] = point1.x();
125  pt1[1] = point1.z();
126  pt2[0] = point2.x();
127  pt2[1] = point2.z();
128 
129  double diameter = point0.distanceToPoint(point1);
130 
131  // Si la grille magnetique est activee
133  {
134  double dummy = NAN;
135  snapToGrid(diameter, dummy, dummy, _gridMagnStep);
136  }
137 
138  if (diameter == 0.0)
139  {
140  return;
141  }
142  else if (diameter != 0.0)
143  {
144  TYAction* pAction = NULL;
145  // 2 cas :
146  // - le modeleur est un modeleur de site
147  // - le modeleur est un modeleur de batiment
148  if (QString(_pModeler->metaObject()->className()).compare("TYBatimentModelerFrame") == 0)
149  {
150  // Nouveau cylindre
151  LPTYAcousticCylinderGeoNode pCylGeoNode =
153  LPTYAcousticCylinder pCyl = TYAcousticCylinder::safeDownCast(pCylGeoNode->getElement());
154  pCyl->setDiameter(diameter);
155  pCyl->setHauteur(2.0);
156 
157  // Position
158  TYPoint org((pt0[0] + (pt1[0] - pt0[0]) / 2.0), -(pt1[1] + (pt2[1] - pt1[1]) / 2.0),
159  pCyl->getHauteur() / 2.0);
160 
161  // Si la grille magnetique est activee
163  {
164  snapToGrid(org._x, org._y, org._z, _gridMagnStep);
165  }
166 
167  pCylGeoNode->getORepere3D()._origin = org;
168 
169  // Ajout au batiment
170  LPTYBatiment pBat = getBatiment();
171  if (pBat != NULL)
172  {
173  pBat->addAcousticVol((LPTYAcousticVolumeGeoNode&)pCylGeoNode);
174  pBat->updateGraphicTree();
175  }
176 
177  pAction = new TYAddAccVolToAccVolNodeAction((LPTYAcousticVolumeGeoNode&)pCylGeoNode,
178  getBatiment(), _pModeler, TR("id_action_addcyl"));
179  }
180  else if (QString(_pModeler->metaObject()->className()).compare("TYSiteModelerFrame") == 0)
181  {
182  // Creation du cylindre
183  LPTYAcousticCylinderGeoNode pCylGeoNode =
185  LPTYAcousticCylinder pCyl = TYAcousticCylinder::safeDownCast(pCylGeoNode->getElement());
186  pCyl->setDiameter(diameter);
187  pCyl->setHauteur(2.0);
188 
189  // Creation d'un nouveau batiment a partir du silos
190  LPTYBatimentGeoNode pBatNode = new TYBatimentGeoNode(new TYBatiment());
191 
192  // Ajout du cylindre au batiment
193  TYBatiment::safeDownCast(pBatNode->getElement())->addAcousticVol(pCylGeoNode, false);
194 
195  // Gestion de la position de l'objet
196  // Position
197  TYPoint org((pt0[0] + (pt1[0] - pt0[0]) / 2.0), -(pt1[1] + (pt2[1] - pt1[1]) / 2.0),
198  pCyl->getHauteur() / 2.0);
199 
200  // Si la grille magnetique est activee
202  {
203  snapToGrid(org._x, org._y, org._z, _gridMagnStep);
204  }
205 
206  ORepere3D repere = pBatNode->getORepere3D();
207 
208  org._z = org._z + _pModeler->getDefaultZCoord();
209  repere._origin = org;
210 
211  pBatNode->setRepere(repere);
212 
213  // Ajout dans l'infrastructure
214  LPTYSiteNode pSite = getSite();
215  if (pSite != NULL)
216  {
217  // Ajout du atiment dans l'infrastructure
218  pSite->getInfrastructure()->addBatiment(pBatNode);
219 
220  pSite->updateGraphicTree();
221  }
222 
223  pAction = new TYAddElementToInfraAction(pBatNode, pSite->getInfrastructure(), _pModeler,
224  TR("id_action_addetage"));
225  }
226 
227  if (pAction != NULL)
228  {
229  _pModeler->getActionManager()->addAction(pAction);
230  }
232 
233  // repasse en mode _pInteractor selection
235  }
236 
237  showText(false);
238 
241 
243 
245  }
246 }
247 
248 void TYSilosEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
249 {
250  if (_active && _moving)
251  {
252  float w = NAN;
253 
254  w = ABS(x - _pOGLRectangleElement->getPoint0()[0]);
255 
257  _pOGLRectangleElement->setPoint2(QVector3D(x, _pOGLRectangleElement->getPoint0().y() - w, 0.0));
259  QVector3D(_pOGLRectangleElement->getPoint0()[0], _pOGLRectangleElement->getPoint0()[1] - w, 0.0));
260 
264  point0.setY(0);
265  point1.setY(0);
266  point2.setY(0);
267 
268  double diameter = point0.distanceToPoint(point1);
269 
270  // Si la grille magnetique est activee
272  {
273  double dummy = NAN;
274  snapToGrid(diameter, dummy, dummy, _gridMagnStep);
275  }
276 
277  updateText(
278  QString(TR("id_diameter_info")).arg(diameter, 0, 'f', 2),
279  (int)(_pOGLRectangleElement->getPoint0()[0] +
281  (int)(_pOGLRectangleElement->getPoint1()[1] +
283 
285  _pInteractor->update();
286  }
287 }
288 
290 {
291  Q_CHECK_PTR(_pModeler);
292  LPTYBatiment pBatiment = NULL;
293 
294  if (QString(_pModeler->metaObject()->className()).compare("TYBatimentModelerFrame") == 0)
295  {
296  pBatiment = ((TYBatimentModelerFrame*)_pModeler)->getBatiment();
297  }
298 
299  Q_CHECK_PTR(pBatiment);
300 
301  return pBatiment;
302 }
303 
305 {
306  Q_CHECK_PTR(_pModeler);
307 
308  LPTYSiteNode pSite = NULL;
309 
310  if (QString(_pModeler->metaObject()->className()).compare("TYSiteModelerFrame") == 0)
311  {
312  pSite = ((TYSiteModelerFrame*)_pModeler)->getSite();
313  }
314 
315  Q_CHECK_PTR(pSite);
316 
317  return pSite;
318 }
double ABS(double a)
Return the absolute value.
Definition: 3d.h:67
TYGeometryNode TYAcousticCylinderGeoNode
Noeud geometrique de type TYAcousticCylinder.
fichier contenant differents types d'actions (fichier header)
TYMainWindow * getTYMainWnd()
Retourne le pointeur sur la fenetre principale.
pour l'application Tympan (fichier header)
Modeler specialisee pour l'edition des batiments (fichier header)
TYGeometryNode TYBatimentGeoNode
Noeud geometrique de type TYBatiment.
Definition: TYBatiment.h:90
Fenetre principale de l'application Tympan (fichier header)
Classe generique pour une fenetre de modeleur (fichier header)
Le role de cette classe est limite a emettre des signaux pouvant etre utilise pour interagir sur le r...
#define TR(id)
gestion de l'edition d'un silo (fichier header)
Classe Modeler specialisee pour l'edition des sites (fichier header)
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 setVisibility(bool bVisible)
Definition: OGLElement.h:51
void setPoint2(const QVector3D &point2)
void setColor(const OColor &oColor)
void setPoint3(const QVector3D &point3)
void setPoint0(const QVector3D &point0)
void setPoint1(const QVector3D &point1)
const QVector3D & getPoint1()
const QVector3D & getPoint0()
const QVector3D & getPoint2()
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
3D frame with a point and 3 vectors.
Definition: 3d.h:1263
OPoint3D _origin
The origin point.
Definition: 3d.h:1331
double _gridMagnStep
Pas de la grille magnétique de positionnement.
void refreshSiteFrame()
Rafraichit l'arborescence du TYSiteFrame.
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...
void updateText(QString msg="", int posX=0, int posY=0, bool show=true)
Mets a jour le texte informatif sur la vue 3D.
TYModelerFrame * _pModeler
Le modeler associe a cet editor.
void showText(bool show=true)
Affiche ou pas le texte informatif sur la vue 3D.
TYRenderWindowInteractor * _pInteractor
La vue graphique associee a cet editor.
void setHauteur(double hauteur)
void setDiameter(double diameter)
bool addAcousticVol(LPTYAcousticVolumeGeoNode pAccVolGeoNode, bool recursif=true)
void addAction(TYAction *pAction)
Ajoute une nouvelle action a l'historique.
Definit une action, necessaire pour la gestion de l'undo.
Definition: TYAction.h:37
ajout d'un volume acoustique a un ensemble de volumes acoustiques
Definition: TYActions.h:147
Ajout d'un element a une infrastructure.
Definition: TYActions.h:399
Classe Modeler specialisee pour l'edition des batiments.
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:914
bool addBatiment(LPTYBatimentGeoNode pBatimentGeoNode)
void setDefaultCameraMode()
Generic class for a modeler window.
TYRenderWindowInteractor * getView()
bool getSnapGridActive()
TYActionManager * getActionManager()
virtual float getDefaultZCoord()
Returns default Z coordinate for editors This value will depend on the type of modeler and of the fix...
virtual void updateView(bool clipping=true, bool axesAndGrid=true)
Super-class for editors performing object construction.
void addOGLElement(OGLElement *pOGLElement)
void invalidateScene(void)
void removeOGLElement(OGLElement *pOGLElement)
QVector3D displayToWorld(const QVector3D &display) const
const TYRenderViewport & getViewport() const
TYOpenGLRenderer * getRenderer()
virtual void close()
virtual void slotKeyPressed(int key)
TYSilosEditor(TYModelerFrame *pModeler)
OGLRectangleElement * _pOGLRectangleElement
Pour le dessin de construction.
Definition: TYSilosEditor.h:62
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
LPTYSiteNode getSite()
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
LPTYBatiment getBatiment()
virtual void cancel()
virtual void init()
virtual void slotViewTypeChanged(int view)
bool _active
Indique si cet editor est actif.
Definition: TYSilosEditor.h:59
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
Classe Modeler specialisee pour l'edition des sites.
LPTYInfrastructure getInfrastructure()
Definition: TYSiteNode.h:174