Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYCylinderEditor.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 <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(QVector3D(0.0, 0.0, 0.0));
50  _pOGLRectangleElement->setPoint1(QVector3D(0.0, 0.0, 0.0));
51  _pOGLRectangleElement->setPoint2(QVector3D(0.0, 0.0, 0.0));
52  _pOGLRectangleElement->setPoint3(QVector3D(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 
76  _pInteractor->update();
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(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
104  _pOGLRectangleElement->setPoint1(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
105  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
106  _pOGLRectangleElement->setPoint3(QVector3D(x, _pInteractor->getViewport().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];
121  pt0[0] = point0.x();
122  pt0[1] = point0.z();
123  pt1[0] = point1.x();
124  pt1[1] = point1.z();
125  pt2[0] = point2.x();
126  pt2[1] = point2.z();
127 
128  double diameter = ABS(pt1[0] - pt0[0]);
129 
130  // Si la grille magnetique est activee
132  {
133  double dummy = NAN;
134  snapToGrid(diameter, dummy, dummy, _gridMagnStep);
135  }
136 
137  if (diameter != 0.0)
138  {
140  {
141  // Nouveau cylindre
142  LPTYAcousticCylinderGeoNode pCylGeoNode =
144  TYAcousticCylinder::safeDownCast(pCylGeoNode->getElement())->setDiameter(diameter);
145  TYAcousticCylinder::safeDownCast(pCylGeoNode->getElement())->setHauteur(2.0);
146 
147  // Position
148  TYPoint org((pt0[0] + (pt1[0] - pt0[0]) / 2.0), -(pt1[1] + (pt2[1] - pt1[1]) / 2.0),
149  TYAcousticCylinder::safeDownCast(pCylGeoNode->getElement())->getHauteur() / 2.0);
150 
151  // Si la grille magnetique est activee
153  {
154  snapToGrid(org._x, org._y, org._z, _gridMagnStep);
155  }
156 
157  pCylGeoNode->getORepere3D()._origin = org;
158 
159  // Ajout a la machine
161  getMachine()->updateGraphicTree();
162 
164  (LPTYAcousticVolumeGeoNode&)pCylGeoNode, getMachine(), _pModeler, TR("id_action_addcyl"));
165  _pModeler->getActionManager()->addAction(pAction);
166 
167  /* Desactivation DT 20070903
168  //az++ temporairement,avant refonte mecanisme de selection
169  // On ajoute cette machine a la selection du calcul courant
170  if (getTYApp()->getCurProjet() && _pModeler->isElementInCurrentProjet())
171  {
172  LPTYCalcul pCalcul = getTYApp()->getCurProjet()->getCurrentCalcul();
173  if (pCalcul) {
174  pCalcul->addToSelection(getMachine());
175  }
176  }
177  */
179 
180  // repasse en mode camera selection
182  }
183  }
184 
185  showText(false);
186 
188 
190 
192  }
193 }
194 
195 void TYCylinderEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
196 {
197  if (_active && _moving)
198  {
200  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
202  QVector3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->getViewport().height() - y, 0.0));
203 
204  float pt0[3], pt1[3];
207  pt0[0] = point0.x();
208  pt0[1] = point0.z();
209  pt1[0] = point1.x();
210  pt1[1] = point1.z();
211 
212  double diameter = ABS(pt1[0] - pt0[0]);
213 
214  // Si la grille magnetique est activee
216  {
217  double dummy = NAN;
218  snapToGrid(diameter, dummy, dummy, _gridMagnStep);
219  }
220 
221  updateText(
222  QString(TR("id_diameter_info")).arg(diameter, 0, 'f', 2),
223  (int)(_pOGLRectangleElement->getPoint0()[0] +
225  (int)(_pOGLRectangleElement->getPoint1()[1] +
227 
229  _pInteractor->update();
230  }
231 }
232 
234 {
235  Q_CHECK_PTR(_pModeler);
236 
237  LPTYMachine pMachine = ((TYMachineModelerFrame*)_pModeler)->getMachine();
238  Q_CHECK_PTR(pMachine);
239 
240  return pMachine;
241 }
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: 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 * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
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:147
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:914
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)
Super-class for editors performing object construction.
void addOGLElement(OGLElement *pOGLElement)
void invalidateScene(void)
void removeOGLElement(OGLElement *pOGLElement)
QVector3D displayToWorld(const QVector3D &display) const
const TYRenderViewport & getViewport() const
TYOpenGLRenderer * getRenderer()