Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSemiCylinderEditor.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 
40 #include "TYSemiCylinderEditor.h"
41 
42 #define TR(id) OLocalizator::getString("TYSemiCylinderEditor", (id))
43 
45 {
48  OColor oLineColor;
49  oLineColor.r = 1.0;
50  oLineColor.g = 0.0;
51  oLineColor.b = 0.0;
52  _pOGLRectangleElement->setColor(oLineColor);
53  _pOGLRectangleElement->setPoint0(OPoint3D(0.0, 0.0, 0.0));
54  _pOGLRectangleElement->setPoint1(OPoint3D(0.0, 0.0, 0.0));
55  _pOGLRectangleElement->setPoint2(OPoint3D(0.0, 0.0, 0.0));
56  _pOGLRectangleElement->setPoint3(OPoint3D(0.0, 0.0, 0.0));
58 
59  _moving = false;
60  _active = false;
62 }
63 
65 {
67  delete _pOGLRectangleElement;
68 }
69 
71 
73 {
74  _moving = false;
75  _active = false;
76 
77  showText(false);
78 
81 }
82 
84 {
85  cancel();
86 }
87 
89 
91 {
92  if (view == TYModelerFrame::TopView)
93  {
94  _active = true;
95  }
96  else
97  {
98  _active = false;
99  }
100 }
101 
102 void TYSemiCylinderEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
103 {
104  if ((button == Qt::LeftButton) && _active)
105  {
106  // Init points
107  _pOGLRectangleElement->setPoint0(OPoint3D(x, _pInteractor->height() - y, 0.0));
108  _pOGLRectangleElement->setPoint1(OPoint3D(x, _pInteractor->height() - y, 0.0));
109  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
110  _pOGLRectangleElement->setPoint3(OPoint3D(x, _pInteractor->height() - y, 0.0));
111  _moving = true;
112  }
113 }
114 
115 void TYSemiCylinderEditor::slotMouseReleased(int x, int y, Qt::MouseButton button,
116  Qt::KeyboardModifiers state)
117 {
118  if ((button == Qt::LeftButton) && _active && _moving)
119  {
120  _moving = false;
121 
122  float pt0[3], pt1[3], pt2[3];
132  pt0[0] = point0.x;
133  pt0[1] = point0.z;
134  pt1[0] = point1.x;
135  pt1[1] = point1.z;
136  pt2[0] = point2.x;
137  pt2[1] = point2.z;
138 
139  double diameter = ABS(pt1[0] - pt0[0]);
140 
141  // Si la grille magnetique est activee
143  {
144  double dummy = NAN;
145  snapToGrid(diameter, dummy, dummy, _gridMagnStep);
146  }
147 
148  if (diameter != 0.0)
149  {
151  {
152  // Nouveau demi-cylindre
153  LPTYAcousticSemiCylinderGeoNode pSemiCylGeoNode =
155  TYAcousticSemiCylinder::safeDownCast(pSemiCylGeoNode->getElement())->setDiameter(diameter);
156  TYAcousticSemiCylinder::safeDownCast(pSemiCylGeoNode->getElement())->setHauteur(2.0);
157 
158  // Position
159  TYPoint org(
160  (pt0[0] + (pt1[0] - pt0[0]) / 2.0), -(pt1[1] + (pt2[1] - pt1[1]) / 2.0),
161  TYAcousticSemiCylinder::safeDownCast(pSemiCylGeoNode->getElement())->getHauteur() / 2.0);
162 
163  // Si la grille magnetique est activee
165  {
166  snapToGrid(org._x, org._y, org._z, _gridMagnStep);
167  }
168 
169  pSemiCylGeoNode->getORepere3D()._origin = org;
170 
171  // Ajout a la machine
173  getMachine()->updateGraphicTree();
174 
175  TYAction* pAction =
177  getMachine(), _pModeler, TR("id_action_addsemicyl"));
178  _pModeler->getActionManager()->addAction(pAction);
179 
180  /* Desactivation DT 20070903
181  //az++ temporairement,avant refonte mecanisme de selection
182  // On ajoute cette machine a la selection du calcul courant
183  if (getTYApp()->getCurProjet() && _pModeler->isElementInCurrentProjet())
184  {
185  LPTYCalcul pCalcul = getTYApp()->getCurProjet()->getCurrentCalcul();
186  if (pCalcul) {
187  pCalcul->addToSelection(getMachine());
188  }
189  }
190  */
191 
192  // repasse en mode camera selection
194  }
196  }
197 
198  showText(false);
199 
201 
203 
205  }
206 }
207 
208 void TYSemiCylinderEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
209 {
210  if (_active && _moving)
211  {
213  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
215  OPoint3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->height() - y, 0.0));
216 
217  float pt0[3], pt1[3];
227  pt0[0] = point0.x;
228  pt0[1] = point0.z;
229  pt1[0] = point1.x;
230  pt1[1] = point1.z;
231 
232  double diameter = ABS(pt1[0] - pt0[0]);
233 
234  // Si la grille magnetique est activee
236  {
237  double dummy = 0.0;
238  snapToGrid(diameter, dummy, dummy, _gridMagnStep);
239  }
240 
241  updateText(
242  QString(TR("id_diameter_info")).arg(diameter, 0, 'f', 2),
243  (int)(_pOGLRectangleElement->getPoint0()[0] +
245  (int)(_pOGLRectangleElement->getPoint1()[1] +
247 
250  }
251 }
252 
254 {
255  Q_CHECK_PTR(_pModeler);
256 
257  LPTYMachine pMachine = ((TYMachineModelerFrame*)_pModeler)->getMachine();
258  Q_CHECK_PTR(pMachine);
259 
260  return pMachine;
261 }
double ABS(double a)
Return the absolute value.
Definition: 3d.h:67
TYGeometryNode TYAcousticSemiCylinderGeoNode
Noeud geometrique de type TYAcousticSemiCylinder.
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 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...
#define TR(id)
gestion de l'edition d'un 1/2 cylindre (fichier header)
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
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()
virtual void slotKeyPressed(int key)
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
OGLRectangleElement * _pOGLRectangleElement
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
TYSemiCylinderEditor(TYMachineModelerFrame *pModeler)
virtual void slotViewTypeChanged(int view)
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
bool _active
Indique si cet editor est actif.