Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRectangleEditor.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 <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  : TYAbstractSceneEditor(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(OPoint3D(0.0, 0.0, 0.0));
60  _pOGLRectangleElement->setPoint1(OPoint3D(0.0, 0.0, 0.0));
61  _pOGLRectangleElement->setPoint2(OPoint3D(0.0, 0.0, 0.0));
62  _pOGLRectangleElement->setPoint3(OPoint3D(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 
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(OPoint3D(x, _pInteractor->height() - y, 0.0));
115  _pOGLRectangleElement->setPoint1(OPoint3D(x, _pInteractor->height() - y, 0.0));
116  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
117  _pOGLRectangleElement->setPoint3(OPoint3D(x, _pInteractor->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;
140  pt0._x = point0.x;
141  pt0._y = -point0.z;
142  pt0._z = point0.y;
143  pt1._x = point1.x;
144  pt1._y = -point1.z;
145  pt1._z = point1.y;
146  pt2._x = point2.x;
147  pt2._y = -point2.z;
148  pt2._z = point2.y;
149 
150  double sizeX = OVector3D(pt0, pt1).norme();
151  double sizeY = OVector3D(pt1, pt2).norme();
152  double sizeZ = 0;
153 
154  // Si la grille magnetique est activee
156  {
157  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
158  }
159 
160  if (sizeX <= 0.0001 || sizeY <= 0.0001)
161  {
162  return;
163  } // Securite : eviter les surfaces nulles.
164 
165  // Position
166  TYPoint org = OVector3D(OVector3D(pt0) + (OVector3D(pt2) - OVector3D(pt0)) * 0.5);
167  org._z = 0.0;
168 
169  // Si la grille magnetique est activee
171  {
172  snapToGrid(org._x, org._y, org._z, _gridMagnStep);
173  }
174 
175  TYRepere rep;
176  rep._origin = org;
177 
178  // Necessaire pr Prototype Factory...
179  {
180  TYBoucheSurface dummyBouche;
181  TYChemineeSurface dummyCheminee;
182  }
183 
184  // Nouvelle sous-face
185  const char* childType = NULL;
186  switch (_mode)
187  {
188  case Bouche:
189  childType = "TYBoucheSurface";
190  break;
191  case Cheminee:
192  childType = "TYChemineeSurface";
193  break;
194  case Fenetre:
195  childType = "TYMurElement";
196  break;
197  default:
198  childType = "";
199  }
200 
201  // Instanciation du type choisi
202  _pRectangle = NULL;
203  try
204  {
205  _pRectangle = dynamic_cast<TYAcousticRectangle*>(TYElement::findAndClone(childType));
206  }
207  catch (tympan::invalid_data&)
208  {
209  };
210 
211  if (_pRectangle != nullptr)
212  {
213  _pRectangle->getBoundingRect()->setDimension(sizeX, sizeY);
214 
215  // Ajout a l'AcousticRectangleNode
216  bool ret = getAcousticRectangleNode()->addSubRect(_pRectangle, rep);
217 
218  if (ret)
219  {
220  // Update
221  getAcousticRectangleNode()->updateGraphicTree();
222 
225  TR("id_action_remface"));
226  _pModeler->getActionManager()->addAction(pAction);
227  }
228 
230  }
231  }
232 
233  showText(false);
234 
238  }
239 }
240 
241 void TYRectangleEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
242 {
243  if (_active && _moving)
244  {
246  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
248  OPoint3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->height() - y, 0.0));
249 
250  float pt0[3], pt1[3], pt2[3];
260  pt0[0] = point0.x;
261  pt0[1] = point0.z;
262  pt0[2] = -point0.y;
263  pt1[0] = point1.x;
264  pt1[1] = point1.z;
265  pt1[2] = -point1.y;
266  pt2[0] = point2.x;
267  pt2[1] = point2.z;
268  pt2[2] = -point2.y;
269 
270  double sizeX = ABS(pt1[0] - pt0[0]);
271  double sizeY = ABS(pt2[1] - pt0[1]);
272  double sizeZ = ABS(pt2[2] - pt0[2]);
273 
274  // Si la grille magnetique est activee
276  {
277  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
278  }
279 
280  updateText(
281  QString(TR("id_size_info")).arg(sizeX, 0, 'f', 2).arg(sizeY, 0, 'f', 2),
282  (int)(_pOGLRectangleElement->getPoint0()[0] +
284  (int)(_pOGLRectangleElement->getPoint1()[1] +
286 
289  }
290 }
291 
293 {
294  Q_CHECK_PTR(_pModeler);
295 
296  LPTYAcousticRectangleNode pAcousticRectangleNode = ((TYFaceModelerFrame*)_pModeler)->getFace();
297  Q_CHECK_PTR(pAcousticRectangleNode);
298 
299  return pAcousticRectangleNode;
300 }
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: NxVec3.h:23
NxReal z
Definition: NxVec3.h:80
NxReal y
Definition: NxVec3.h:80
NxReal x
Definition: NxVec3.h:80
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
static NxVec3 displayToWorld(NxVec3 display)
Definition: OGLCamera.cpp:699
void setVisibility(bool bVisible)
Definition: OGLElement.h:51
void setColor(const OColor &oColor)
void setPoint2(const OPoint3D &point2)
void setPoint3(const OPoint3D &point3)
void setPoint0(const OPoint3D &point0)
void setPoint1(const OPoint3D &point1)
The 3D point class.
Definition: 3d.h:487
static OPrototype * findAndClone(const char *className)
Definition: TYElement.cpp:37
OPoint3D _origin
The origin point.
Definition: 3d.h:1279
The 3D vector class.
Definition: 3d.h:298
double norme() const
Computes the length of this vector.
Definition: 3d.cpp:215
Classe abstraite pour la gestion de l'interaction entre la vue graphique (2D ou 3D) et le clavier et ...
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:70
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:915
Classe Modeler specialisee pour l'edition des faces.
TYRenderWindowInteractor * getView()
bool getSnapGridActive()
TYActionManager * getActionManager()
bool askForResetResultat()
void updateDisplayList(void)
void addOGLElement(OGLElement *pOGLElement)
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)
virtual void updateGL()
TYOpenGLRenderer * getRenderer()
Utilities to handle exceptions and to pretty-print value.
The base exception class for errors due to invalid data.
Definition: exceptions.h:60