Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYCameraZoneEditor.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 <cmath>
22 
23 #include <qdialog.h>
24 #include <qmessagebox.h>
25 #include <qpushbutton.h>
26 #include <qlineedit.h>
27 #include <qlabel.h>
28 #include <qlayout.h>
29 #include <qcursor.h>
30 
39 #include "TYCameraZoneEditor.h"
40 
41 #ifndef min
42  #define min(a, b) (((a) < (b)) ? (a) : (b))
43 #endif
44 
45 #define TR(id) OLocalizator::getString("TYCameraZoneEditor", (id))
46 
48 {
51  OColor oLineColor;
52  oLineColor.r = 1.0;
53  oLineColor.g = 0.0;
54  oLineColor.b = 0.0;
55  _pOGLRectangleElement->setColor(oLineColor);
56  _pOGLRectangleElement->setPoint0(QVector3D(0.0, 0.0, 0.0));
57  _pOGLRectangleElement->setPoint1(QVector3D(0.0, 0.0, 0.0));
58  _pOGLRectangleElement->setPoint2(QVector3D(0.0, 0.0, 0.0));
59  _pOGLRectangleElement->setPoint3(QVector3D(0.0, 0.0, 0.0));
61 
62  _moving = false;
63  _active = false;
65 }
66 
68 {
70  delete _pOGLRectangleElement;
71 }
72 
74 
76 {
77  _moving = false;
78  _active = false;
79 
80  showText(false);
81 
83  _pInteractor->update();
84 }
85 
87 {
88  cancel();
89 }
90 
92 {
93  if (view != TYModelerFrame::PerspView)
94  {
95  _active = true;
96  }
97  else
98  {
99  _active = false;
100  }
101 }
102 
103 void TYCameraZoneEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
104 {
105  if ((button == Qt::LeftButton) && _active)
106  {
107  if (getTYApp()->getCurProjet() && getTYApp()->getCurProjet()->getCurrentCalcul())
108  {
109  // Init points
110  _pOGLRectangleElement->setPoint0(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
111  _pOGLRectangleElement->setPoint1(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
112  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
113  _pOGLRectangleElement->setPoint3(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
114 
115  _moving = true;
116  }
117  else
118  {
119  _moving = false;
120 
121  // Msg "Pas de calcul courant..."
122  QString msg(TR("id_warning_no_curcalcul"));
123  writeOutputMsg(msg);
124  QMessageBox::warning(_pModeler, "Tympan", msg, QMessageBox::Ok, QMessageBox::NoButton);
125  }
126  }
127 }
128 
129 void TYCameraZoneEditor::slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
130 {
131  if ((button == Qt::LeftButton) && _active && _moving)
132  {
133  _moving = false;
134 
135  QVector3D world0 = _pInteractor->getViewport().displayToWorld(
138  QVector3D world1 = _pInteractor->getViewport().displayToWorld(
141  QVector3D world2 = _pInteractor->getViewport().displayToWorld(
144  TYPoint pt0(world0.x(), world0.y(), world0.z());
145  TYPoint pt1(world1.x(), world1.y(), world1.z());
146  TYPoint pt2(world2.x(), world2.y(), world2.z());
147 
148  double sizeX = OVector3D(pt0, pt1).norme();
149  double sizeY = OVector3D(pt1, pt2).norme();
150  double sizeZ = 0;
151 
152  // Si la grille magnetique est activee
154  {
155  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
156  }
157 
158  // Si la taille est valide
159  if (sizeX && sizeY)
160  {
162  {
164 
165  float focalPoint[3];
166  focalPoint[0] =
169  focalPoint[1] =
172  focalPoint[2] =
175 
176  double factor = 1;
177  QRect viewport = _pInteractor->getViewport();
178  factor =
179  min(viewport.width() /
181  viewport.height() /
183  pCameraEditor->cameraZoneZoom(QVector3D(focalPoint[0], focalPoint[1], focalPoint[2]),
184  fabs(factor));
185  }
186  }
187 
188  showText(false);
189 
192 
193  TYApplication::restoreOverrideCursor();
194  }
195 }
196 
197 void TYCameraZoneEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
198 {
199  if (_active && _moving)
200  {
202  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
204  QVector3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->getViewport().height() - y, 0.0));
205 
206  QVector3D world0 = _pInteractor->getViewport().displayToWorld(
207  QVector3D(_pOGLRectangleElement->getPoint0()[0],
208  -_pOGLRectangleElement->getPoint0()[1] + _pInteractor->getViewport().height(), 0));
209  QVector3D world1 = _pInteractor->getViewport().displayToWorld(
210  QVector3D(_pOGLRectangleElement->getPoint1()[0],
211  -_pOGLRectangleElement->getPoint1()[1] + _pInteractor->getViewport().height(), 0));
212  QVector3D world2 = _pInteractor->getViewport().displayToWorld(
213  QVector3D(_pOGLRectangleElement->getPoint2()[0], y, 0));
214  TYPoint pt0(world0.x(), world0.z(), 0);
215  TYPoint pt1(world1.x(), world1.z(), 0);
216  TYPoint pt2(world2.x(), world2.z(), 0);
217 
218  double sizeX = OVector3D(pt0, pt1).norme();
219  double sizeY = OVector3D(pt1, pt2).norme();
220  double sizeZ = 0;
221 
222  // Si la grille magnetique est activee
224  {
225  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
226  }
227  updateText(
228  QString(TR("id_size_info")).arg(sizeX, 0, 'f', 2).arg(sizeY, 0, 'f', 2),
229  (int)(_pOGLRectangleElement->getPoint0()[0] +
231  (int)(_pOGLRectangleElement->getPoint1()[1] +
233 
235  _pInteractor->update();
236  }
237 }
void writeOutputMsg(QString msg)
Affiche un message dans la fenetre de sortie.
TYApplication * getTYApp()
Retourne le pointeur sur l'application.
pour l'application Tympan (fichier header)
gestion de l'edition de la camera (fichier header)
#define min(a, b)
#define TR(id)
gestion de zoom par zone selectionnee (fichier obsolete)(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
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()
The 3D vector class.
Definition: 3d.h:298
double norme() const
Computes the length of this vector.
Definition: 3d.cpp:215
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.
Gestion de l'edition en mode camera.
void cameraZoneZoom(const QVector3D &focalPoint2D, double factor)
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
bool _active
Indique si cet editor est actif.
OGLRectangleElement * _pOGLRectangleElement
TYCameraZoneEditor(TYModelerFrame *pModeler)
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
virtual void slotViewTypeChanged(int view)
Generic class for a modeler window.
bool getSnapGridActive()
bool askForResetResultat()
TYCameraEditor * getCameraEditor()
virtual void updateView(bool clipping=true, bool axesAndGrid=true)
void addOGLElement(OGLElement *pOGLElement)
void removeOGLElement(OGLElement *pOGLElement)
QVector3D displayToWorld(const QVector3D &display) const
const TYRenderViewport & getViewport() const
TYOpenGLRenderer * getRenderer()