Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYBoxEditor.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 <qinputdialog.h>
22 
39 #include "TYBoxEditor.h"
40 
41 #define TR(id) OLocalizator::getString("TYBoxEditor", (id))
42 
44 {
47  OColor oLineColor;
48  oLineColor.r = 1.0;
49  oLineColor.g = 0.0;
50  oLineColor.b = 0.0;
51  _pOGLRectangleElement->setColor(oLineColor);
52  _pOGLRectangleElement->setPoint0(OPoint3D(0.0, 0.0, 0.0));
53  _pOGLRectangleElement->setPoint1(OPoint3D(0.0, 0.0, 0.0));
54  _pOGLRectangleElement->setPoint2(OPoint3D(0.0, 0.0, 0.0));
55  _pOGLRectangleElement->setPoint3(OPoint3D(0.0, 0.0, 0.0));
57 
58  _moving = false;
59  _active = false;
61 }
62 
64 {
66  delete _pOGLRectangleElement;
67 }
68 
70 
72 {
73  _moving = false;
74  _active = false;
75 
76  showText(false);
77 
80 }
81 
83 {
84  cancel();
85 }
86 
88 
90 {
91  if (view == TYModelerFrame::TopView)
92  {
93  _active = true;
94  }
95  else
96  {
97  _active = false;
98  }
99 }
100 
101 void TYBoxEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
102 {
103  if ((button == Qt::LeftButton) && _active)
104  {
105  // Init points
106  _pOGLRectangleElement->setPoint0(OPoint3D(x, _pInteractor->height() - y, 0.0));
107  _pOGLRectangleElement->setPoint1(OPoint3D(x, _pInteractor->height() - y, 0.0));
108  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
109  _pOGLRectangleElement->setPoint3(OPoint3D(x, _pInteractor->height() - y, 0.0));
110  _moving = true;
111  }
112 }
113 
114 void TYBoxEditor::slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
115 {
116  if ((button == Qt::LeftButton) && _active && _moving)
117  {
118  _moving = false;
119 
120  float pt0[3], pt1[3], pt2[3];
130  pt0[0] = point0.x;
131  pt0[1] = point0.z;
132  pt1[0] = point1.x;
133  pt1[1] = point1.z;
134  pt2[0] = point2.x;
135  pt2[1] = point2.z;
136 
137  double sizeX = ABS(pt1[0] - pt0[0]);
138  double sizeY = ABS(pt2[1] - pt1[1]);
139  double sizeZ = (sizeX + sizeY) / 2.0;
140 
141  // Si la grille magnetique est activee
143  {
144  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
145  }
146 
147  if ((sizeX != 0.0) && (sizeY != 0.0))
148  {
150  {
151  // Nouvelle box
153  TYAcousticBox::safeDownCast(pBoxGeoNode->getElement())->setDimension(sizeX, sizeY, sizeZ);
154 
155  // Position (on "pose" l'element au sol)
156  TYPoint org((pt0[0] + (pt1[0] - pt0[0]) / 2.0), -(pt1[1] + (pt2[1] - pt1[1]) / 2.0),
157  sizeZ / 2.0);
158 
159  // Si la grille magnetique est activee
161  {
162  // On ne modifie pas la hauteur
163  double dummy = 0.0;
164  snapToGrid(org._x, org._y, dummy, _gridMagnStep);
165  }
166 
167  pBoxGeoNode->getORepere3D()._origin = org;
168 
169  // Ajout a la machine
171  getMachine()->updateGraphicTree();
172 
174  (LPTYAcousticVolumeGeoNode&)pBoxGeoNode, getMachine(), _pModeler, TR("id_action_addbox"));
175  _pModeler->getActionManager()->addAction(pAction);
176 
177  /* Desactivation DT 20070903
178  //az++ temporairement,avant refonte mecanisme de selection
179  // On ajoute cette machine a la selection du calcul courant
180  if (getTYApp()->getCurProjet() && _pModeler->isElementInCurrentProjet())
181  {
182  LPTYCalcul pCalcul = getTYApp()->getCurProjet()->getCurrentCalcul();
183  if (pCalcul) {
184  pCalcul->addToSelection(getMachine());
185  }
186  }
187  */
188  // repasse en mode camera selection
190  }
191 
193  }
194 
195  showText(false);
196 
198 
201  }
202 }
203 
204 void TYBoxEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
205 {
206  if (_active && _moving)
207  {
209  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
211  OPoint3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->height() - y, 0.0));
212 
213  float pt0[3], pt1[3], pt2[3];
223  pt0[0] = point0.x;
224  pt0[1] = point0.z;
225  pt1[0] = point1.x;
226  pt1[1] = point1.z;
227  pt2[0] = point2.x;
228  pt2[1] = point2.z;
229 
230  double sizeX = ABS(pt1[0] - pt0[0]);
231  double sizeY = ABS(pt2[1] - pt1[1]);
232  double sizeZ = (sizeX + sizeY) / 2.0;
233 
234  // Si la grille magnetique est activee
236  {
237  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
238  }
239 
240  updateText(
241  QString(TR("id_size_info")).arg(sizeX, 0, 'f', 2).arg(sizeY, 0, 'f', 2),
242  (int)(_pOGLRectangleElement->getPoint0()[0] +
244  (int)(_pOGLRectangleElement->getPoint1()[1] +
246 
249  }
250 }
251 
253 {
254  Q_CHECK_PTR(_pModeler);
255 
256  LPTYMachine pMachine = ((TYMachineModelerFrame*)_pModeler)->getMachine();
257  Q_CHECK_PTR(pMachine);
258 
259  return pMachine;
260 }
double ABS(double a)
Return the absolute value.
Definition: 3d.h:67
TYGeometryNode TYAcousticBoxGeoNode
Noeud geometrique de type TYAcousticBox.
fichier contenant differents types d'actions (fichier header)
TYMainWindow * getTYMainWnd()
Retourne le pointeur sur la fenetre principale.
pour l'application Tympan (fichier header)
#define TR(id)
Definition: TYBoxEditor.cpp:41
gestion de l'edition d'une box (fichier header)
Modeler specialisee pour l'edition des machines (fichier header)
Fenetre principale de l'application Tympan (fichier header)
Classe generique pour une fenetre de modeleur (fichier header)
Representation graphique d'un point (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 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 _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 * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
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 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:146
virtual void slotViewTypeChanged(int view)
Definition: TYBoxEditor.cpp:89
virtual void cancel()
Definition: TYBoxEditor.cpp:71
bool _moving
Definition: TYBoxEditor.h:67
OGLRectangleElement * _pOGLRectangleElement
Pour le dessin de construction.
Definition: TYBoxEditor.h:66
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
TYBoxEditor(TYMachineModelerFrame *pModeler)
Definition: TYBoxEditor.cpp:43
virtual void close()
Definition: TYBoxEditor.cpp:82
virtual void init()
Definition: TYBoxEditor.cpp:69
bool _active
Indique si cet editor est actif.
Definition: TYBoxEditor.h:63
LPTYMachine getMachine()
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
virtual void slotKeyPressed(int key)
Definition: TYBoxEditor.cpp:87
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:915
Classe Modeler specialisee pour l'edition des machines.
void setDefaultCameraMode()
TYRenderWindowInteractor * getView()
bool getSnapGridActive()
TYActionManager * getActionManager()
bool askForResetResultat()
virtual void updateView(bool clipping=true, bool axesAndGrid=true)
void updateDisplayList(void)
void addOGLElement(OGLElement *pOGLElement)
void removeOGLElement(OGLElement *pOGLElement)
virtual void updateGL()
TYOpenGLRenderer * getRenderer()