Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRectangleEditor.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 <iostream>
22 #include <qmessagebox.h>
23 
24 #include "Tympan/core/exceptions.h"
42 #include "TYRectangleEditor.h"
43 
44 #define TR(id) OLocalizator::getString("TYRectangleEditor", (id))
45 
47  : TYObjectConstructionEditor(pModeler)
48 {
49  setMode(mode);
50  _pRectangle = NULL;
51 
54  OColor oLineColor;
55  oLineColor.r = 1.0;
56  oLineColor.g = 0.0;
57  oLineColor.b = 0.0;
58  _pOGLRectangleElement->setColor(oLineColor);
59  _pOGLRectangleElement->setPoint0(QVector3D(0.0, 0.0, 0.0));
60  _pOGLRectangleElement->setPoint1(QVector3D(0.0, 0.0, 0.0));
61  _pOGLRectangleElement->setPoint2(QVector3D(0.0, 0.0, 0.0));
62  _pOGLRectangleElement->setPoint3(QVector3D(0.0, 0.0, 0.0));
64 
65  _moving = false;
66  _active = false;
68 }
69 
71 {
73  delete _pOGLRectangleElement;
74 }
75 
77 
79 {
80  _moving = false;
81  _active = false;
82 
83  showText(false);
84 
86  _pInteractor->update();
87 }
88 
90 {
91  cancel();
92 }
93 
95 
97 {
98  if (view == TYModelerFrame::TopView)
99  {
100  _active = true;
101  }
102  else
103  {
104  _active = false;
105  }
106  _active = true;
107 }
108 
109 void TYRectangleEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
110 {
111  if ((button == Qt::LeftButton) && _active)
112  {
113  // Init points
114  _pOGLRectangleElement->setPoint0(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
115  _pOGLRectangleElement->setPoint1(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
116  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
117  _pOGLRectangleElement->setPoint3(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
118  _moving = true;
119  }
120 }
121 
122 void TYRectangleEditor::slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
123 {
124  if ((button == Qt::LeftButton) && _active && _moving)
125  {
127  {
128  _moving = false;
129 
130  TYPoint pt0, pt1, pt2;
134  pt0._x = point0.x();
135  pt0._y = -point0.z();
136  pt0._z = point0.y();
137  pt1._x = point1.x();
138  pt1._y = -point1.z();
139  pt1._z = point1.y();
140  pt2._x = point2.x();
141  pt2._y = -point2.z();
142  pt2._z = point2.y();
143 
144  double sizeX = OVector3D(pt0, pt1).norme();
145  double sizeY = OVector3D(pt1, pt2).norme();
146  double sizeZ = 0;
147 
148  // Si la grille magnetique est activee
150  {
151  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
152  }
153 
154  if (sizeX <= 0.0001 || sizeY <= 0.0001)
155  {
156  return;
157  } // Securite : eviter les surfaces nulles.
158 
159  // Position
160  TYPoint org = OVector3D(OVector3D(pt0) + (OVector3D(pt2) - OVector3D(pt0)) * 0.5);
161  org._z = 0.0;
162 
163  // Si la grille magnetique est activee
165  {
166  snapToGrid(org._x, org._y, org._z, _gridMagnStep);
167  }
168 
169  TYRepere rep;
170  rep._origin = org;
171 
172  // Necessaire pr Prototype Factory...
173  {
174  TYBoucheSurface dummyBouche;
175  TYChemineeSurface dummyCheminee;
176  }
177 
178  // Nouvelle sous-face
179  const char* childType = NULL;
180  switch (_mode)
181  {
182  case Bouche:
183  childType = "TYBoucheSurface";
184  break;
185  case Cheminee:
186  childType = "TYChemineeSurface";
187  break;
188  case Fenetre:
189  childType = "TYMurElement";
190  break;
191  default:
192  childType = "";
193  }
194 
195  // Instanciation du type choisi
196  _pRectangle = NULL;
197  try
198  {
199  _pRectangle = dynamic_cast<TYAcousticRectangle*>(TYElement::findAndClone(childType));
200  }
201  catch (tympan::invalid_data&)
202  {
203  };
204 
205  if (_pRectangle != nullptr)
206  {
207  _pRectangle->getBoundingRect()->setDimension(sizeX, sizeY);
208 
209  // Ajout a l'AcousticRectangleNode
210  bool ret = getAcousticRectangleNode()->addSubRect(_pRectangle, rep);
211 
212  if (ret)
213  {
214  // Update
215  getAcousticRectangleNode()->updateGraphicTree();
216 
219  TR("id_action_remface"));
220  _pModeler->getActionManager()->addAction(pAction);
221  }
222 
224  }
225  }
226 
227  showText(false);
228 
231  _pInteractor->update();
232  }
233 }
234 
235 void TYRectangleEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
236 {
237  if (_active && _moving)
238  {
240  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
242  QVector3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->getViewport().height() - y, 0.0));
243 
244  float pt0[3], pt1[3], pt2[3];
248  pt0[0] = point0.x();
249  pt0[1] = point0.z();
250  pt0[2] = -point0.y();
251  pt1[0] = point1.x();
252  pt1[1] = point1.z();
253  pt1[2] = -point1.y();
254  pt2[0] = point2.x();
255  pt2[1] = point2.z();
256  pt2[2] = -point2.y();
257 
258  double sizeX = ABS(pt1[0] - pt0[0]);
259  double sizeY = ABS(pt2[1] - pt0[1]);
260  double sizeZ = ABS(pt2[2] - pt0[2]);
261 
262  // Si la grille magnetique est activee
264  {
265  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
266  }
267 
268  updateText(
269  QString(TR("id_size_info")).arg(sizeX, 0, 'f', 2).arg(sizeY, 0, 'f', 2),
270  (int)(_pOGLRectangleElement->getPoint0()[0] +
272  (int)(_pOGLRectangleElement->getPoint1()[1] +
274 
276  _pInteractor->update();
277  }
278 }
279 
281 {
282  Q_CHECK_PTR(_pModeler);
283 
284  LPTYAcousticRectangleNode pAcousticRectangleNode = ((TYFaceModelerFrame*)_pModeler)->getFace();
285  Q_CHECK_PTR(pAcousticRectangleNode);
286 
287  return pAcousticRectangleNode;
288 }
double ABS(double a)
Return the absolute value.
Definition: 3d.h:67
fichier contenant differents types d'actions (fichier header)
Classe Modeler specialisee pour l'edition des faces (fichier header)
Classe generique pour une fenetre de modeleur (fichier header)
Representation graphique d'un point (fichier header)
#define TR(id)
gestion de l'edition d'un rectangle (fichier header)
Le role de cette classe est limite a emettre des signaux pouvant etre utilise pour interagir sur le r...
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 * findAndClone(const char *className)
Definition: TYElement.cpp:37
OPoint3D _origin
The origin point.
Definition: 3d.h:1331
The 3D vector class.
Definition: 3d.h:298
double norme() const
Computes the length of this vector.
Definition: 3d.cpp:215
double _gridMagnStep
Pas de la grille magnétique de positionnement.
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.
bool addSubRect(LPTYAcousticRectangleGeoNode pAccRectGeoNode)
TYRectangle * getBoundingRect()
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'une surface acoustique a un ensemble de surfaces acoustiques
Definition: TYActions.h:71
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:914
Classe Modeler specialisee pour l'edition des faces.
TYRenderWindowInteractor * getView()
bool getSnapGridActive()
TYActionManager * getActionManager()
bool askForResetResultat()
Super-class for editors performing object construction.
void addOGLElement(OGLElement *pOGLElement)
void invalidateScene(void)
void removeOGLElement(OGLElement *pOGLElement)
virtual void cancel()
void setMode(int mode)
virtual void slotKeyPressed(int key)
TYRectangleEditor(TYFaceModelerFrame *pModeler, int mode=Bouche)
virtual void slotViewTypeChanged(int view)
int _mode
Le mode pour cet editor.
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
bool _active
Indique si cet editor est actif.
virtual void close()
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
LPTYAcousticRectangle _pRectangle
Le rectangle.
LPTYAcousticRectangleNode getAcousticRectangleNode()
OGLRectangleElement * _pOGLRectangleElement
Pour le dessin de construction.
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
void setDimension(float lon, float haut)
QVector3D displayToWorld(const QVector3D &display) const
const TYRenderViewport & getViewport() const
TYOpenGLRenderer * getRenderer()
Utilities to handle exceptions and to pretty-print value.
The base exception class for errors due to invalid data.
Definition: exceptions.h:75