Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYBoxEditor.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 <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(QVector3D(0.0, 0.0, 0.0));
53  _pOGLRectangleElement->setPoint1(QVector3D(0.0, 0.0, 0.0));
54  _pOGLRectangleElement->setPoint2(QVector3D(0.0, 0.0, 0.0));
55  _pOGLRectangleElement->setPoint3(QVector3D(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 
79  _pInteractor->update();
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(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
107  _pOGLRectangleElement->setPoint1(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
108  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
109  _pOGLRectangleElement->setPoint3(QVector3D(x, _pInteractor->getViewport().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];
124  pt0[0] = point0.x();
125  pt0[1] = point0.z();
126  pt1[0] = point1.x();
127  pt1[1] = point1.z();
128  pt2[0] = point2.x();
129  pt2[1] = point2.z();
130 
131  double sizeX = ABS(pt1[0] - pt0[0]);
132  double sizeY = ABS(pt2[1] - pt1[1]);
133  double sizeZ = (sizeX + sizeY) / 2.0;
134 
135  // Si la grille magnetique est activee
137  {
138  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
139  }
140 
141  if ((sizeX != 0.0) && (sizeY != 0.0))
142  {
144  {
145  // Nouvelle box
147  TYAcousticBox::safeDownCast(pBoxGeoNode->getElement())->setDimension(sizeX, sizeY, sizeZ);
148 
149  // Position (on "pose" l'element au sol)
150  TYPoint org((pt0[0] + (pt1[0] - pt0[0]) / 2.0), -(pt1[1] + (pt2[1] - pt1[1]) / 2.0),
151  sizeZ / 2.0);
152 
153  // Si la grille magnetique est activee
155  {
156  // On ne modifie pas la hauteur
157  double dummy = 0.0;
158  snapToGrid(org._x, org._y, dummy, _gridMagnStep);
159  }
160 
161  pBoxGeoNode->getORepere3D()._origin = org;
162 
163  // Ajout a la machine
165  getMachine()->updateGraphicTree();
166 
168  (LPTYAcousticVolumeGeoNode&)pBoxGeoNode, getMachine(), _pModeler, TR("id_action_addbox"));
169  _pModeler->getActionManager()->addAction(pAction);
170 
171  /* Desactivation DT 20070903
172  //az++ temporairement,avant refonte mecanisme de selection
173  // On ajoute cette machine a la selection du calcul courant
174  if (getTYApp()->getCurProjet() && _pModeler->isElementInCurrentProjet())
175  {
176  LPTYCalcul pCalcul = getTYApp()->getCurProjet()->getCurrentCalcul();
177  if (pCalcul) {
178  pCalcul->addToSelection(getMachine());
179  }
180  }
181  */
182  // repasse en mode camera selection
184  }
185 
187  }
188 
189  showText(false);
190 
192 
195  }
196 }
197 
198 void TYBoxEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
199 {
200  if (_active && _moving)
201  {
203  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
205  QVector3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->getViewport().height() - y, 0.0));
206 
207  float pt0[3], pt1[3], pt2[3];
211  pt0[0] = point0.x();
212  pt0[1] = point0.z();
213  pt1[0] = point1.x();
214  pt1[1] = point1.z();
215  pt2[0] = point2.x();
216  pt2[1] = point2.z();
217 
218  double sizeX = ABS(pt1[0] - pt0[0]);
219  double sizeY = ABS(pt2[1] - pt1[1]);
220  double sizeZ = (sizeX + sizeY) / 2.0;
221 
222  // Si la grille magnetique est activee
224  {
225  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
226  }
227 
228  updateText(
229  QString(TR("id_size_info")).arg(sizeX, 0, 'f', 2).arg(sizeY, 0, 'f', 2),
230  (int)(_pOGLRectangleElement->getPoint0()[0] +
232  (int)(_pOGLRectangleElement->getPoint1()[1] +
234 
236  _pInteractor->update();
237  }
238 }
239 
241 {
242  Q_CHECK_PTR(_pModeler);
243 
244  LPTYMachine pMachine = ((TYMachineModelerFrame*)_pModeler)->getMachine();
245  Q_CHECK_PTR(pMachine);
246 
247  return pMachine;
248 }
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: 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
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
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: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()