Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYEchelleEditor.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 <qinputdialog.h>
22 #include <qvector3d.h>
23 
31 #include "TYEchelleEditor.h"
32 
33 #define TR(id) OLocalizator::getString("TYEchelleEditor", (id))
34 
36 {
37  _active = false;
38 
41  OColor oLineColor;
42  oLineColor.r = 1.0;
43  oLineColor.g = 0.0;
44  oLineColor.b = 0.0;
45  _pOGLLineElement->setColor(oLineColor);
47 
49 }
50 
52 {
54  delete _pOGLLineElement;
55 }
56 
58 {
59  // Init seg a 0
60  _pOGLLineElement->setPoint1(QVector3D(0.0, 0.0, 0.0));
61  _pOGLLineElement->setPoint2(QVector3D(0.0, 0.0, 0.0));
62 }
63 
65 {
67  _pInteractor->update();
68 }
69 
71 {
72  if (view == TYModelerFrame::TopView)
73  {
74  _active = true;
75  }
76  else
77  {
78  _active = false;
79  }
80 }
81 
82 void TYEchelleEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
83 {
84  if ((button == Qt::LeftButton) && _active)
85  {
86  _pOGLLineElement->setPoint1(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
87  _pOGLLineElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
88  }
89 }
90 
91 void TYEchelleEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
92 {
93  if ((button == Qt::LeftButton) && _active)
94  {
95  _pOGLLineElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
97  _pInteractor->update();
98  }
99 }
100 
101 void TYEchelleEditor::slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
102 {
103  if ((button == Qt::LeftButton) && _active)
104  {
105  double point[4];
106  TYSegment segEchelle;
107  LPTYSiteNode pSite = ((TYSiteModelerFrame*)_pModeler)->getSite();
108 
109  // Pt 1
111  _pOGLLineElement->getPoint1()[2], point);
112  segEchelle._ptA.setFromOGL(point[0], point[1], point[2]);
113 
114  // Pt 2
116  _pOGLLineElement->getPoint2()[2], point);
117  segEchelle._ptB.setFromOGL(point[0], point[1], point[2]);
118 
119  // Longueur actuelle en coord World
120  double size = segEchelle.longueur();
121  // Longueur en prenant compte l'ancienne echelle
122  size /= pSite->getEchelle();
123 
124  // Obtention de la longeur reelle World
125  bool ok = false;
126  double distance = TYModelerFrame::getDouble("Tympan", "Distance", 0, 2000000, 0, ok);
127  if (ok && size)
128  {
129  // Calcul de la nouvelle echelle
130  float echelle = distance / size;
131 
132  TYAction* pAction = new TYSetEchelleSiteAction(pSite, pSite->getEchelle(), echelle, _pModeler,
133  TR("id_action_setechelle"));
134  _pModeler->getActionManager()->addAction(pAction);
135 
136  pSite->setEchelle(echelle);
137  pSite->updateGraphic();
138  }
139 
141 
143 
145 
146  // La scene a ete modifiee
148  }
149 }
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:36
float b
Definition: color.h:38
float r
Definition: color.h:38
float g
Definition: color.h:38
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)
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:1253
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1255
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:905
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 addOGLElement(OGLElement *pOGLElement)
void invalidateScene(void)
void removeOGLElement(OGLElement *pOGLElement)
const TYRenderViewport & getViewport() const
TYOpenGLRenderer * getRenderer()
Action de mise a l'echelle d'un site.
Definition: TYActions.h:822
Classe Modeler specialisee pour l'edition des sites.
void setEchelle(float e)
Definition: TYSiteNode.h:288
float getEchelle() const
Definition: TYSiteNode.h:281