Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYCylinderEditor.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 <math.h>
22 #include <qinputdialog.h>
23 
36 #include "TYCylinderEditor.h"
37 
38 #define TR(id) OLocalizator::getString("TYCylinderEditor", (id))
39 
41 {
44  OColor oLineColor;
45  oLineColor.r = 1.0;
46  oLineColor.g = 0.0;
47  oLineColor.b = 0.0;
48  _pOGLRectangleElement->setColor(oLineColor);
49  _pOGLRectangleElement->setPoint0(OPoint3D(0.0, 0.0, 0.0));
50  _pOGLRectangleElement->setPoint1(OPoint3D(0.0, 0.0, 0.0));
51  _pOGLRectangleElement->setPoint2(OPoint3D(0.0, 0.0, 0.0));
52  _pOGLRectangleElement->setPoint3(OPoint3D(0.0, 0.0, 0.0));
54 
55  _moving = false;
56  _active = false;
58 }
59 
61 {
63  delete _pOGLRectangleElement;
64 }
65 
67 
69 {
70  _moving = false;
71  _active = false;
72 
73  showText(false);
74 
77 }
78 
80 {
81  cancel();
82 }
83 
85 
87 {
88  if (view == TYModelerFrame::TopView)
89  {
90  _active = true;
91  }
92  else
93  {
94  _active = false;
95  }
96 }
97 
98 void TYCylinderEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
99 {
100  if ((button == Qt::LeftButton) && _active)
101  {
102  // Init points
103  _pOGLRectangleElement->setPoint0(OPoint3D(x, _pInteractor->height() - y, 0.0));
104  _pOGLRectangleElement->setPoint1(OPoint3D(x, _pInteractor->height() - y, 0.0));
105  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
106  _pOGLRectangleElement->setPoint3(OPoint3D(x, _pInteractor->height() - y, 0.0));
107  _moving = true;
108  }
109 }
110 
111 void TYCylinderEditor::slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
112 {
113  if ((button == Qt::LeftButton) && _active && _moving)
114  {
115  _moving = false;
116 
117  float pt0[3], pt1[3], pt2[3];
127  pt0[0] = point0.x;
128  pt0[1] = point0.z;
129  pt1[0] = point1.x;
130  pt1[1] = point1.z;
131  pt2[0] = point2.x;
132  pt2[1] = point2.z;
133 
134  double diameter = ABS(pt1[0] - pt0[0]);
135 
136  // Si la grille magnetique est activee
138  {
139  double dummy = NAN;
140  snapToGrid(diameter, dummy, dummy, _gridMagnStep);
141  }
142 
143  if (diameter != 0.0)
144  {
146  {
147  // Nouveau cylindre
148  LPTYAcousticCylinderGeoNode pCylGeoNode =
150  TYAcousticCylinder::safeDownCast(pCylGeoNode->getElement())->setDiameter(diameter);
151  TYAcousticCylinder::safeDownCast(pCylGeoNode->getElement())->setHauteur(2.0);
152 
153  // Position
154  TYPoint org((pt0[0] + (pt1[0] - pt0[0]) / 2.0), -(pt1[1] + (pt2[1] - pt1[1]) / 2.0),
155  TYAcousticCylinder::safeDownCast(pCylGeoNode->getElement())->getHauteur() / 2.0);
156 
157  // Si la grille magnetique est activee
159  {
160  snapToGrid(org._x, org._y, org._z, _gridMagnStep);
161  }
162 
163  pCylGeoNode->getORepere3D()._origin = org;
164 
165  // Ajout a la machine
167  getMachine()->updateGraphicTree();
168 
170  (LPTYAcousticVolumeGeoNode&)pCylGeoNode, getMachine(), _pModeler, TR("id_action_addcyl"));
171  _pModeler->getActionManager()->addAction(pAction);
172 
173  /* Desactivation DT 20070903
174  //az++ temporairement,avant refonte mecanisme de selection
175  // On ajoute cette machine a la selection du calcul courant
176  if (getTYApp()->getCurProjet() && _pModeler->isElementInCurrentProjet())
177  {
178  LPTYCalcul pCalcul = getTYApp()->getCurProjet()->getCurrentCalcul();
179  if (pCalcul) {
180  pCalcul->addToSelection(getMachine());
181  }
182  }
183  */
185 
186  // repasse en mode camera selection
188  }
189  }
190 
191  showText(false);
192 
194 
196 
198  }
199 }
200 
201 void TYCylinderEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
202 {
203  if (_active && _moving)
204  {
206  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
208  OPoint3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->height() - y, 0.0));
209 
210  float pt0[3], pt1[3];
220  pt0[0] = point0.x;
221  pt0[1] = point0.z;
222  pt1[0] = point1.x;
223  pt1[1] = point1.z;
224 
225  double diameter = ABS(pt1[0] - pt0[0]);
226 
227  // Si la grille magnetique est activee
229  {
230  double dummy = NAN;
231  snapToGrid(diameter, dummy, dummy, _gridMagnStep);
232  }
233 
234  updateText(
235  QString(TR("id_diameter_info")).arg(diameter, 0, 'f', 2),
236  (int)(_pOGLRectangleElement->getPoint0()[0] +
238  (int)(_pOGLRectangleElement->getPoint1()[1] +
240 
243  }
244 }
245 
247 {
248  Q_CHECK_PTR(_pModeler);
249 
250  LPTYMachine pMachine = ((TYMachineModelerFrame*)_pModeler)->getMachine();
251  Q_CHECK_PTR(pMachine);
252 
253  return pMachine;
254 }
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)
#define TR(id)
gestion de l'edition d'un cylindre (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 _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 * 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
bool _active
Indique si cet editor est actif.
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
OGLRectangleElement * _pOGLRectangleElement
virtual void init()
virtual void cancel()
LPTYMachine getMachine()
TYCylinderEditor(TYMachineModelerFrame *pModeler)
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
virtual void slotKeyPressed(int key)
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
virtual void close()
virtual void slotViewTypeChanged(int view)
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()