Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAbstractSceneEditor.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 
31 #include "TYAbstractSceneEditor.h"
32 #include <qvector3d.h>
33 
34 #define IMG(id) OLocalizator::getPicture("TYAbstractSceneEditor", (id))
35 
37  : _pCameraEditor(pCameraEditor)
38 {
39  Q_CHECK_PTR(pModeler);
40  _pModeler = pModeler;
41  _gridMagnStep = 1.0;
43 
44  // Text
48  _pOGLTextElement->setFont(IMG("id_font"));
51 }
52 
54 {
56  delete _pOGLTextElement;
57 }
58 
60 {
62 }
63 
65 {
67 }
68 
70 {
72 }
74 {
75  // Connections...
82  QObject::connect(_pInteractor, &TYRenderWindowInteractor::mouseMoved, this,
84  QObject::connect(_pInteractor, &TYRenderWindowInteractor::wheeled, this,
86  QObject::connect(_pInteractor, &TYRenderWindowInteractor::keyPressed, this,
88  QObject::connect(_pInteractor, &TYRenderWindowInteractor::keyReleased, this,
90  QObject::connect(_pModeler, &TYModelerFrame::viewTypeChanged, this,
94 
95  float r = 94.0f, g = 110.0f, b = 255.0f;
96 
97  // Couleur de la police
98  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "FontColorR"))
99  {
100  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "FontColor", r, g, b);
101  }
102  else
103  {
104  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "FontColor", r, g, b);
105  }
106 
107  OColor oColor;
108  oColor.r = r / 255.0f;
109  oColor.g = g / 255.0f;
110  oColor.b = b / 255.0f;
111  _pOGLTextElement->setColor(oColor);
112 
113  // Update du type de vue actif
115 }
116 
118 {
119  // Deconnections...
120  QObject::disconnect(_pInteractor, &TYRenderWindowInteractor::mousePressed, this,
122  QObject::disconnect(_pInteractor, &TYRenderWindowInteractor::mouseReleased, this,
126  QObject::disconnect(_pInteractor, &TYRenderWindowInteractor::mouseMoved, this,
128  QObject::disconnect(_pInteractor, &TYRenderWindowInteractor::wheeled, this,
130  QObject::disconnect(_pInteractor, &TYRenderWindowInteractor::keyPressed, this,
132  QObject::disconnect(_pInteractor, &TYRenderWindowInteractor::keyReleased, this,
134  QObject::disconnect(_pModeler, &TYModelerFrame::viewTypeChanged, this,
138 }
139 
140 void TYAbstractSceneEditor::updateText(QString msg, int posX, int posY, bool show)
141 {
144 
145  if (show)
146  {
148  }
149 }
150 
152 {
154 }
155 
156 void TYAbstractSceneEditor::displayToWorld(double x, double y, double z, double* worldPoint)
157 {
158  QVector3D ret = _pInteractor->getViewport().displayToWorld(QVector3D(x, y, z));
159  worldPoint[0] = ret.x();
160  worldPoint[1] = ret.y();
161  worldPoint[2] = ret.z();
162 }
163 
164 void TYAbstractSceneEditor::worldToDisplay(double x, double y, double z, double* displayPoint)
165 {
166  QVector3D ret = _pInteractor->getViewport().worldToDisplay(QVector3D(x, y, z));
167  displayPoint[0] = ret.x();
168  displayPoint[1] = ret.y();
169  displayPoint[2] = ret.z();
170 }
171 
172 void TYAbstractSceneEditor::snapToGrid(float& x, float& y, float& z, float& gridMagnStep)
173 {
174  x = ROUND(x / gridMagnStep) * gridMagnStep;
175  y = ROUND(y / gridMagnStep) * gridMagnStep;
176  z = ROUND(z / gridMagnStep) * gridMagnStep;
177 }
178 
179 void TYAbstractSceneEditor::snapToGrid(double& x, double& y, double& z, double& gridMagnStep)
180 {
181  x = ROUND(x / gridMagnStep) * gridMagnStep;
182  y = ROUND(y / gridMagnStep) * gridMagnStep;
183  z = ROUND(z / gridMagnStep) * gridMagnStep;
184 }
185 
187 {
188  _gridMagnStep = gridMagnStep;
189 }
190 
191 void TYAbstractSceneEditor::setWheelStep(float step /* = 1.0*/)
192 {
193  if (_pCameraEditor)
194  {
196  }
197 }
int ROUND(double a)
Compute the rounded value of a number.
Definition: 3d.h:192
#define IMG(id)
gestion de l'interaction entre la vue graphique (2D ou 3D) et le clavier et la souris (fichier header...
TYMainWindow * getTYMainWnd()
Retourne le pointeur sur la fenetre principale.
pour l'application Tympan (fichier header)
gestion de l'edition de la camera (fichier header)
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
Fenetre principale de l'application Tympan (fichier header)
Classe generique pour une fenetre de modeleur (fichier header)
Frame pour la gestion de projet (fichier header)
Le role de cette classe est limite a emettre des signaux pouvant etre utilise pour interagir sur le r...
Frame pour la gestion de site (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
void setDisplayPosition(double displayPositionX, double displayPositionY)
Definition: OGLElement.h:46
void setColor(const OColor &oColor)
void setTextToDisplay(const QString &qsText)
void setFont(const QString &qsFontPath)
double _gridMagnStep
Pas de la grille magnétique de positionnement.
void setWheelStep(float step=1.0)
Met Ã&#160; jour le pas de zoom de la caméra.
TYAbstractSceneEditor(TYModelerFrame *pModeler, TYCameraEditor *pCameraEditor=nullptr)
Constructeur par defaut.
void refreshSiteFrame()
Rafraichit l'arborescence du TYSiteFrame.
virtual void slotViewTypeChanged(int view)
La vue courante du modeler a change.
void worldToDisplay(double x, double y, double z, double *displayPoint)
Methode utilitaire pour convertir un point en coordonnees globale en coordonnees ecran.
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...
virtual void disconnect()
Deconnecte cet editor a l'interactor associe.
void refreshProjectFrame()
Rafraichit l'arborescence du TYProjectFrame.
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.
void updateSiteFrame()
Reconstruit l'arborescence du TYSiteFrame.
virtual void slotMouseLeave()
Le curseur de souris est sortie dans la widget.
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
Une touche de la souris a ete enfoncee.
virtual void slotWheeled(int x, int y, int delta, Qt::KeyboardModifiers state)
La molette de la souris a ete utilisee.
virtual void slotMouseDoubleClicked(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
Une touche de la souris a ete double clickee.
TYModelerFrame * _pModeler
Le modeler associe a cet editor.
TYCameraEditor * _pCameraEditor
Le caméra editor associé Ã&#160; cet éditor.
void displayToWorld(double x, double y, double z, double *worldPoint)
Methode utilitaire pour convertir un point en coordonnees ecran en coordonnees globale.
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
Une touche de la souris a ete relachee.
virtual void connect()
Connecte cet editor a l'interactor associe.
virtual void slotMouseEnter()
Le curseur de souris est entree dans la widget.
virtual void slotKeyPressed(int key)
Une touche a ete relachee.
virtual ~TYAbstractSceneEditor()
Destructeur.
void setGridMagnStep(float gridMagnStep=1.0)
Met Ã&#160; jour le pas de la grille magnétique.
void showText(bool show=true)
Affiche ou pas le texte informatif sur la vue 3D.
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
La souris a ete deplacee.
virtual void slotKeyReleased(int key)
Une touche a ete relachee.
TYRenderWindowInteractor * _pInteractor
La vue graphique associee a cet editor.
Gestion de l'edition en mode camera.
void setWheelStep(float step)
TYProjetFrame * getProjetFrame()
Definition: TYMainWindow.h:73
TYSiteFrame * getSiteFrame()
Definition: TYMainWindow.h:77
Generic class for a modeler window.
TYRenderWindowInteractor * getView()
void viewTypeChanged(int)
void addOGLElement(OGLElement *pOGLElement)
void removeOGLElement(OGLElement *pOGLElement)
QVector3D worldToDisplay(const QVector3D &world) const
QVector3D displayToWorld(const QVector3D &display) const
void mouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
void mouseDoubleClicked(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
void keyPressed(int key)
void wheeled(int x, int y, int delta, Qt::KeyboardModifiers state)
void mousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
void mouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
void keyReleased(int key)
const TYRenderViewport & getViewport() const
TYOpenGLRenderer * getRenderer()
void updateList()