Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSemiCylinderEditor.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 
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(QVector3D(0.0, 0.0, 0.0));
54  _pOGLRectangleElement->setPoint1(QVector3D(0.0, 0.0, 0.0));
55  _pOGLRectangleElement->setPoint2(QVector3D(0.0, 0.0, 0.0));
56  _pOGLRectangleElement->setPoint3(QVector3D(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 
80  _pInteractor->update();
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(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
108  _pOGLRectangleElement->setPoint1(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
109  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
110  _pOGLRectangleElement->setPoint3(QVector3D(x, _pInteractor->getViewport().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];
126  pt0[0] = point0.x();
127  pt0[1] = point0.z();
128  pt1[0] = point1.x();
129  pt1[1] = point1.z();
130  pt2[0] = point2.x();
131  pt2[1] = point2.z();
132 
133  double diameter = ABS(pt1[0] - pt0[0]);
134 
135  // Si la grille magnetique est activee
137  {
138  double dummy = NAN;
139  snapToGrid(diameter, dummy, dummy, _gridMagnStep);
140  }
141 
142  if (diameter != 0.0)
143  {
145  {
146  // Nouveau demi-cylindre
147  LPTYAcousticSemiCylinderGeoNode pSemiCylGeoNode =
149  TYAcousticSemiCylinder::safeDownCast(pSemiCylGeoNode->getElement())->setDiameter(diameter);
150  TYAcousticSemiCylinder::safeDownCast(pSemiCylGeoNode->getElement())->setHauteur(2.0);
151 
152  // Position
153  TYPoint org(
154  (pt0[0] + (pt1[0] - pt0[0]) / 2.0), -(pt1[1] + (pt2[1] - pt1[1]) / 2.0),
155  TYAcousticSemiCylinder::safeDownCast(pSemiCylGeoNode->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  // Ajout a la machine
165  getMachine()->updateGraphicTree();
166  pSemiCylGeoNode->setPosition(org);
167 
168  TYAction* pAction =
170  getMachine(), _pModeler, TR("id_action_addsemicyl"));
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  */
184 
185  // repasse en mode camera selection
187  }
189  }
190 
191  showText(false);
192 
194 
196 
198  }
199 }
200 
201 void TYSemiCylinderEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
202 {
203  if (_active && _moving)
204  {
206  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
208  QVector3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->getViewport().height() - y, 0.0));
209 
210  float pt0[3], pt1[3];
216  pt0[0] = point0.x();
217  pt0[1] = point0.z();
218  pt1[0] = point1.x();
219  pt1[1] = point1.z();
220 
221  double diameter = ABS(pt1[0] - pt0[0]);
222 
223  // Si la grille magnetique est activee
225  {
226  double dummy = 0.0;
227  snapToGrid(diameter, dummy, dummy, _gridMagnStep);
228  }
229 
230  updateText(
231  QString(TR("id_diameter_info")).arg(diameter, 0, 'f', 2),
232  (int)(_pOGLRectangleElement->getPoint0()[0] +
234  (int)(_pOGLRectangleElement->getPoint1()[1] +
236 
238  _pInteractor->update();
239  }
240 }
241 
243 {
244  Q_CHECK_PTR(_pModeler);
245 
246  LPTYMachine pMachine = ((TYMachineModelerFrame*)_pModeler)->getMachine();
247  Q_CHECK_PTR(pMachine);
248 
249  return pMachine;
250 }
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: color.h:36
float b
Definition: color.h:38
float r
Definition: color.h:38
float g
Definition: color.h:38
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
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:147
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:905
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 addOGLElement(OGLElement *pOGLElement)
void invalidateScene(void)
void removeOGLElement(OGLElement *pOGLElement)
QVector3D displayToWorld(const QVector3D &display) const
const TYRenderViewport & getViewport() const
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.