Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYEchelleEditor.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 <qinputdialog.h>
22 
30 #include "TYEchelleEditor.h"
31 
32 #define TR(id) OLocalizator::getString("TYEchelleEditor", (id))
33 
35 {
36  _active = false;
37 
40  OColor oLineColor;
41  oLineColor.r = 1.0;
42  oLineColor.g = 0.0;
43  oLineColor.b = 0.0;
44  _pOGLLineElement->setColor(oLineColor);
46 
48 }
49 
51 {
53  delete _pOGLLineElement;
54 }
55 
57 {
58  // Init seg a 0
59  _pOGLLineElement->setPoint1(OPoint3D(0.0, 0.0, 0.0));
60  _pOGLLineElement->setPoint2(OPoint3D(0.0, 0.0, 0.0));
61 }
62 
64 {
67 }
68 
70 {
71  if (view == TYModelerFrame::TopView)
72  {
73  _active = true;
74  }
75  else
76  {
77  _active = false;
78  }
79 }
80 
81 void TYEchelleEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
82 {
83  if ((button == Qt::LeftButton) && _active)
84  {
85  _pOGLLineElement->setPoint1(OPoint3D(x, _pInteractor->height() - y, 0.0));
86  _pOGLLineElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
87  }
88 }
89 
90 void TYEchelleEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
91 {
92  if ((button == Qt::LeftButton) && _active)
93  {
94  _pOGLLineElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
97  }
98 }
99 
100 void TYEchelleEditor::slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
101 {
102  if ((button == Qt::LeftButton) && _active)
103  {
104  double point[4];
105  TYSegment segEchelle;
106  LPTYSiteNode pSite = ((TYSiteModelerFrame*)_pModeler)->getSite();
107 
108  // Pt 1
110  _pOGLLineElement->getPoint1()[2], point);
111  segEchelle._ptA.setFromOGL(point[0], point[1], point[2]);
112 
113  // Pt 2
115  _pOGLLineElement->getPoint2()[2], point);
116  segEchelle._ptB.setFromOGL(point[0], point[1], point[2]);
117 
118  // Longueur actuelle en coord World
119  double size = segEchelle.longueur();
120  // Longueur en prenant compte l'ancienne echelle
121  size /= pSite->getEchelle();
122 
123  // Obtention de la longeur reelle World
124  bool ok = false;
125  double distance = TYModelerFrame::getDouble("Tympan", "Distance", 0, 2000000, 0, ok);
126  if (ok && size)
127  {
128  // Calcul de la nouvelle echelle
129  float echelle = distance / size;
130 
131  TYAction* pAction = new TYSetEchelleSiteAction(pSite, pSite->getEchelle(), echelle, _pModeler,
132  TR("id_action_setechelle"));
133  _pModeler->getActionManager()->addAction(pAction);
134 
135  pSite->setEchelle(echelle);
136  pSite->updateGraphic();
137  }
138 
140 
142 
144 
145  // La scene a ete modifiee
147  }
148 }
gestion de l'interaction entre la vue graphique (2D ou 3D) et le clavier et la souris (fichier header...
fichier contenant differents types d'actions (fichier header)
#define TR(id)
gestion de l'edition de l'echelle (fichier header)
Le role de cette classe est limite a emettre des signaux pouvant etre utilise pour interagir sur le r...
Classe Modeler specialisee pour l'edition des sites (fichier header)
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
double * getPoint2()
void setPoint1(const OPoint3D &point1)
void setColor(const OColor &oColor)
double * getPoint1()
void setPoint2(const OPoint3D &point2)
The 3D point class.
Definition: 3d.h:487
virtual void setFromOGL(double x, double y, double z)
Definition: 3d.cpp:340
virtual double longueur() const
Return the segment length.
Definition: 3d.cpp:1238
OPoint3D _ptA
Point A of the segment.
Definition: 3d.h:1201
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1203
Classe abstraite pour la gestion de l'interaction entre la vue graphique (2D ou 3D) et le clavier et ...
TYModelerFrame * _pModeler
Le modeler associe a cet editor.
void displayToWorld(double x, double y, double z, double *worldPoint)
Methode utilitaire pour convertir un point en coordonnees ecran en coordonnees globale.
TYRenderWindowInteractor * _pInteractor
La vue graphique associee a cet editor.
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
TYEchelleEditor(TYSiteModelerFrame *pModeler)
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
virtual void slotViewTypeChanged(int view)
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
virtual void close()
bool _active
Indique si cet editor est actif.
OGLLineElement * _pOGLLineElement
L'objet graphique representant l'echelle.
virtual void init()
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:915
TYRenderWindowInteractor * getView()
TYActionManager * getActionManager()
virtual void updateView(bool clipping=true, bool axesAndGrid=true)
static double getDouble(const QString &title, const QString &txt, double min, double max, double val, bool &ok, int dec=2)
void updateDisplayList(void)
void addOGLElement(OGLElement *pOGLElement)
void removeOGLElement(OGLElement *pOGLElement)
virtual void updateGL()
TYOpenGLRenderer * getRenderer()
Action de mise a l'echelle d'un site.
Definition: TYActions.h:821
Classe Modeler specialisee pour l'edition des sites.
void setEchelle(float e)
Definition: TYSiteNode.h:278
float getEchelle() const
Definition: TYSiteNode.h:271