Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYDistanceEditor.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 <qcursor.h>
22 #include <qstatusbar.h>
23 
31 #include "TYDistanceEditor.h"
32 
33 #define TR(id) OLocalizator::getString("TYDistanceEditor", (id))
34 
36 {
37  _pCamEditor = new TYCameraEditor(pModeler);
38 
44 
45  _shiftOn = false;
46  _active = false;
47 
50  OColor oLineColor;
51  oLineColor.r = 1.0;
52  oLineColor.g = 0.0;
53  oLineColor.b = 0.0;
54  _pOGLLineElement->setColor(oLineColor);
55 
57 }
58 
60 {
62  delete _pOGLLineElement;
63 
64  delete _pCamEditor;
65 }
66 
68 {
70 
72 }
73 
75 {
77 
79 }
80 
82 
84 {
85  close();
86 }
87 
89 {
90  showText(false);
91 
93 
95 }
96 
98 {
99  switch (key)
100  {
101  case Qt::Key_Shift:
102  _shiftOn = true;
103  break;
104  case Qt::Key_Escape:
105  if (_active)
106  {
107  cancel();
108  }
109  break;
110  }
111 }
112 
114 {
115  if (key == Qt::Key_Shift)
116  {
117  _shiftOn = false;
118  }
119 }
120 
122 {
123  if ((view == TYModelerFrame::PerspView) || (view == TYModelerFrame::FreeView))
124  {
125  _active = false;
126  cancel();
127  }
128  else
129  {
130  _active = true;
131  }
132 
133  // On relaie le signal au CameraEditor
135 }
136 
137 void TYDistanceEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
138 {
139  if (_active && !_shiftOn)
140  {
141  if (button == Qt::LeftButton)
142  {
143  // 1er point
144  _pOGLLineElement->setPoint1(OPoint3D(x, _pInteractor->height() - y, 0.0));
145 
146  // On peut dessiner la ligne
148  }
149  }
150 }
151 
152 void TYDistanceEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
153 {
154  if (button == Qt::LeftButton)
155  {
157  }
158 }
159 
160 void TYDistanceEditor::slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
161 {
162  if (_active && !_shiftOn)
163  {
164  if (button == Qt::LeftButton)
165  {
166  // Affichage Distance dans le output
168 
169  // Fin
170  close();
171  }
172  }
173 }
174 
176 {
177  if (!_active || _shiftOn)
178  {
179  return false;
180  }
181 
182  // On recupere la position du curseur
183  QPoint pos = _pInteractor->mapFromGlobal(QCursor::pos());
184 
185  // 2eme point
186  _pOGLLineElement->setPoint2(OPoint3D(pos.x(), _pInteractor->height() - pos.y(), 0.0));
187 
188  // Calcul de la distance
189  NxVec3 world0 =
191  _pOGLLineElement->getPoint1()[2]));
192  NxVec3 world1 =
194  _pOGLLineElement->getPoint2()[2]));
195 
196  double dist = world0.distance(world1);
197 
198  // Msg Dist
199  QString msg = QString(TR("id_output_dist")).arg(dist, 0, 'f', 2);
200 
201  updateText(msg,
202  (int)(_pOGLLineElement->getPoint1()[0] +
203  (_pOGLLineElement->getPoint2()[0] - _pOGLLineElement->getPoint1()[0]) / 2.0),
204  (int)(_pOGLLineElement->getPoint2()[1] +
205  (_pOGLLineElement->getPoint1()[1] - _pOGLLineElement->getPoint2()[1]) / 2.0));
206 
208 
209  return true;
210 }
void writeOutputMsg(QString msg)
Affiche un message dans la fenetre de sortie.
pour l'application Tympan (fichier header)
gestion de l'edition de la camera (fichier header)
#define TR(id)
outil de mesure des distances (fichier header)
Classe generique pour une fenetre de modeleur (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 distance(const NxVec3 &) const
Definition: NxVec3.cpp:199
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
double * getPoint2()
void setPoint1(const OPoint3D &point1)
void setColor(const OColor &oColor)
double * getPoint1()
void setPoint2(const OPoint3D &point2)
QString getText()
The 3D point class.
Definition: 3d.h:487
Classe abstraite pour la gestion de l'interaction entre la vue graphique (2D ou 3D) et le clavier et ...
virtual void disconnect()
Deconnecte cet editor a l'interactor associe.
void updateText(QString msg="", int posX=0, int posY=0, bool show=true)
Mets a jour le texte informatif sur la vue 3D.
OGLTextElement * _pOGLTextElement
Affichage du texte 2D sur la vue 3D.
virtual void connect()
Connecte cet editor a l'interactor associe.
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 setLeftButtonFunction2D(void(TYCameraEditor::*function)())
void setMiddleButtonFunction2D(void(TYCameraEditor::*function)())
void setRightButtonFunction2D(void(TYCameraEditor::*function)())
void setShiftRightButtonFunction2D(void(TYCameraEditor::*function)())
void setShiftLeftButtonFunction2D(void(TYCameraEditor::*function)())
virtual void slotViewTypeChanged(int view)
virtual void slotKeyPressed(int key)
bool _active
Indique si cet editor est actif.
virtual void slotViewTypeChanged(int view)
virtual void disconnect()
virtual void slotKeyReleased(int key)
bool updateMovingLine()
Mets a jour la ligne courante.
OGLLineElement * _pOGLLineElement
La ligne courante.
virtual void init()
TYDistanceEditor(TYModelerFrame *pModeler)
virtual void close()
virtual ~TYDistanceEditor()
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)
virtual void connect()
virtual void cancel()
TYCameraEditor * _pCamEditor
Un CameraEditor associe a cet editor.
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
bool _shiftOn
Indique si le bouton Shift est enfonce.
Classe generique pour une fenetre de modeleur.
void addOGLElement(OGLElement *pOGLElement)
void removeOGLElement(OGLElement *pOGLElement)
virtual void updateGL()
TYOpenGLRenderer * getRenderer()