Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYCameraZoneEditor.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 <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(OPoint3D(0.0, 0.0, 0.0));
57  _pOGLRectangleElement->setPoint1(OPoint3D(0.0, 0.0, 0.0));
58  _pOGLRectangleElement->setPoint2(OPoint3D(0.0, 0.0, 0.0));
59  _pOGLRectangleElement->setPoint3(OPoint3D(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 
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(OPoint3D(x, _pInteractor->height() - y, 0.0));
111  _pOGLRectangleElement->setPoint1(OPoint3D(x, _pInteractor->height() - y, 0.0));
112  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
113  _pOGLRectangleElement->setPoint3(OPoint3D(x, _pInteractor->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 
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  factor =
178  min(_pInteractor->width() /
180  _pInteractor->height() /
182  pCameraEditor->cameraZoneZoom(focalPoint, fabs(factor));
183  }
184  }
185 
186  showText(false);
187 
190 
191  TYApplication::restoreOverrideCursor();
192  }
193 }
194 
195 void TYCameraZoneEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
196 {
197  if (_active && _moving)
198  {
200  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
202  OPoint3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->height() - y, 0.0));
203 
206  -_pOGLRectangleElement->getPoint0()[1] + _pInteractor->height(), 0));
209  -_pOGLRectangleElement->getPoint1()[1] + _pInteractor->height(), 0));
211  TYPoint pt0(world0.x, world0.z, 0);
212  TYPoint pt1(world1.x, world1.z, 0);
213  TYPoint pt2(world2.x, world2.z, 0);
214 
215  double sizeX = OVector3D(pt0, pt1).norme();
216  double sizeY = OVector3D(pt1, pt2).norme();
217  double sizeZ = 0;
218 
219  // Si la grille magnetique est activee
221  {
222  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
223  }
224  updateText(
225  QString(TR("id_size_info")).arg(sizeX, 0, 'f', 2).arg(sizeY, 0, 'f', 2),
226  (int)(_pOGLRectangleElement->getPoint0()[0] +
228  (int)(_pOGLRectangleElement->getPoint1()[1] +
230 
233  }
234 }
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: NxVec3.h:23
NxReal z
Definition: NxVec3.h:80
NxReal y
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
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
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 float focalPoint2D[3], 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)
Classe generique pour une fenetre de modeleur.
bool getSnapGridActive()
bool askForResetResultat()
TYCameraEditor * getCameraEditor()
virtual void updateView(bool clipping=true, bool axesAndGrid=true)
void addOGLElement(OGLElement *pOGLElement)
void removeOGLElement(OGLElement *pOGLElement)
virtual void updateGL()
TYOpenGLRenderer * getRenderer()