Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYDistanceEditor.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 <qstatusbar.h>
22 #include <qvector3d.h>
23 
31 #include "TYDistanceEditor.h"
32 
33 #define TR(id) OLocalizator::getString("TYDistanceEditor", (id))
34 
36 {
37  _pCameraEditor = 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 _pCameraEditor;
65 }
66 
68 {
70 
72 }
73 
75 {
77 
79 }
80 
82 
84 {
85  close();
86 }
87 
89 {
90  showText(false);
91 
93 
94  _pInteractor->update();
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(QVector3D(x, _pInteractor->getViewport().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  {
156  updateMovingLine(x, y);
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 
184  // 2eme point
185  _pOGLLineElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
186 
187  // Calcul de la distance
188  QVector3D world0 = _pInteractor->getViewport().displayToWorld(
189  QVector3D(_pOGLLineElement->getPoint1()[0], _pOGLLineElement->getPoint1()[1],
190  _pOGLLineElement->getPoint1()[2]));
191  QVector3D world1 = _pInteractor->getViewport().displayToWorld(
192  QVector3D(_pOGLLineElement->getPoint2()[0], _pOGLLineElement->getPoint2()[1],
193  _pOGLLineElement->getPoint2()[2]));
194 
195  double dist = world0.distanceToPoint(world1);
196 
197  // Msg Dist
198  QString msg = QString(TR("id_output_dist")).arg(dist, 0, 'f', 2);
199 
200  updateText(msg,
201  (int)(_pOGLLineElement->getPoint1()[0] +
202  (_pOGLLineElement->getPoint2()[0] - _pOGLLineElement->getPoint1()[0]) / 2.0),
203  (int)(_pOGLLineElement->getPoint2()[1] +
204  (_pOGLLineElement->getPoint1()[1] - _pOGLLineElement->getPoint2()[1]) / 2.0));
205 
206  _pInteractor->update();
207 
208  return true;
209 }
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: 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
const QVector3D & getPoint1()
void setPoint2(const QVector3D &point2)
const QVector3D & getPoint2()
void setColor(const OColor &oColor)
void setPoint1(const QVector3D &point1)
QString getText()
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.
TYCameraEditor * _pCameraEditor
Le caméra editor associé Ã&#160; cet éditor.
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)
OGLLineElement * _pOGLLineElement
La ligne courante.
virtual void init()
bool updateMovingLine(int x, int y)
Mets a jour la ligne courante.
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()
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
bool _shiftOn
Indique si le bouton Shift est enfonce.
Generic class for a modeler window.
void addOGLElement(OGLElement *pOGLElement)
void removeOGLElement(OGLElement *pOGLElement)
QVector3D displayToWorld(const QVector3D &display) const
const TYRenderViewport & getViewport() const
TYOpenGLRenderer * getRenderer()