Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSourceEditor.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 
32 #include "TYSourceEditor.h"
33 #include "TYCameraEditor.h"
34 
35 #define TR(id) OLocalizator::getString("TYSourceEditor", (id))
36 
38  : TYAbstractSceneEditor(pModeler, pCameraEditor)
39 {
40  _active = false;
41 
43 }
44 
46 
48 
50 
52 {
53  if (view == TYModelerFrame::TopView)
54  {
55  _active = true;
56  }
57  else
58  {
59  _active = false;
60  }
61 }
62 
63 void TYSourceEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
64 {
65  if ((button == Qt::LeftButton) && _active)
66  {
67  }
68 }
69 
70 void TYSourceEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
71 {
72  if ((button == Qt::LeftButton) && _active)
73  {
74  }
75 }
76 
77 void TYSourceEditor::slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
78 {
79  if ((button == Qt::LeftButton) && _active)
80  {
82  {
83  return;
84  }
85 
86  // Hauteur pour ce point de controle
87  bool ok = false;
88  double hauteur = TYModelerFrame::getDouble("", TR("id_msg_gethauteur"), -1000.0, 1000.0, 2.0, ok);
89 
90  if (ok)
91  {
92  double point[4];
94 
95  // Pos
96  displayToWorld(x, _pInteractor->getViewport().height() - y, 0.0, point);
97 
98  // Si la grille magnetique est activee
100  {
101  snapToGrid(point[0], point[1], point[2], _gridMagnStep);
102  }
103 
104  // Init source
105  pSrcPonct->setHauteur(hauteur);
106  pSrcPonct->getPos()->setFromOGL(point);
107  pSrcPonct->getPos()->_z = 0.0 + _pModeler->getDefaultZCoord();
108  pSrcPonct->getOrientation()._x = 1.0;
109 
110  if (QString(_pModeler->metaObject()->className()).compare("TYSiteModelerFrame") == 0)
111  {
112  TYSiteNode* pSite = ((TYSiteModelerFrame*)_pModeler)->getSite();
113 
114  // Ajout
115  if (pSite->getInfrastructure()->addSrc(pSrcPonct))
116  {
117  // On ajoute cette source a la selection du calcul courant
118  if (getTYApp()->getCurProjet() && (getTYApp()->getCurProjet()->getSite() == pSite))
119  {
121 
122  if (pCalcul)
123  {
124  pCalcul->addToSelection(pSrcPonct);
125  }
126  }
127 
128  // Action
129  TYAction* pAction =
130  new TYAddElementToInfraAction((LPTYElement&)pSrcPonct, pSite->getInfrastructure(),
131  _pModeler, TR("id_action_addsource"));
132  _pModeler->getActionManager()->addAction(pAction);
133 
135 
136  // Update
137  pSite->getInfrastructure()->updateGraphicTree();
139  updateSiteFrame(); // Mise a jour de l'arborescence de site
140  }
141  }
142  else if (QString(_pModeler->metaObject()->className()).compare("TYBatimentModelerFrame") == 0)
143  {
144  pSrcPonct->getPos()->_z = hauteur + _pModeler->getDefaultZCoord();
145 
146  TYBatiment* pBat = ((TYBatimentModelerFrame*)_pModeler)->getBatiment();
147  LPTYEtage pEtage = (TYEtage*)pBat->getAcousticVol(0).getRealPointer();
148 
149  if (pEtage)
150  {
151  bool addOk = pEtage->addSource(pSrcPonct);
152 
153  if (addOk) // Si l'action d'ajouter a ete effectuee sans probleme
154  {
155  // Action
156  TYAction* pAction = new TYAddElementToEtageAction(
157  (LPTYElement&)pSrcPonct, pEtage, _pModeler, TR("id_action_addsource"));
158  _pModeler->getActionManager()->addAction(pAction);
159  }
160 
161  // Update
162  pEtage->updateGraphicTree();
163  updateSiteFrame();
166  }
167  }
168 
170  }
171  }
172 }
173 
174 void TYSourceEditor::slotWheeled(int x, int y, int delta, Qt::KeyboardModifiers state)
175 {
176  _pCameraEditor->slotWheeled(x, y, delta, state);
177 }
fichier contenant differents types d'actions (fichier header)
TYApplication * getTYApp()
Retourne le pointeur sur l'application.
pour l'application Tympan (fichier header)
Modeler specialisee pour l'edition des batiments (fichier header)
gestion de l'edition de la camera (fichier header)
Classe generique pour une fenetre de modeleur (fichier header)
Classe Modeler specialisee pour l'edition des sites (fichier header)
#define TR(id)
gestion de l'edition d'une source (fichier header)
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
virtual void setFromOGL(double x, double y, double z)
Definition: 3d.cpp:340
T * getRealPointer()
Definition: smartptr.h:291
Classe abstraite pour la gestion de l'interaction entre la vue graphique (2D ou 3D) et le clavier et ...
double _gridMagnStep
Pas de la grille magnétique de positionnement.
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...
void updateSiteFrame()
Reconstruit l'arborescence du TYSiteFrame.
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.
TYRenderWindowInteractor * _pInteractor
La vue graphique associee a cet editor.
LPTYAcousticVolume getAcousticVol(int index)
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
ajout d'un element a un etage
Definition: TYActions.h:271
Ajout d'un element a une infrastructure.
Definition: TYActions.h:399
LPTYProjet getCurProjet()
Set/Get du projet courant.
Classe Modeler specialisee pour l'edition des batiments.
bool addToSelection(TYUUID id)
Adds the item to the selection of this Calculation.
Definition: TYCalcul.cpp:873
Gestion de l'edition en mode camera.
virtual void slotWheeled(int x, int y, int delta, Qt::KeyboardModifiers state)
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:914
bool addSource(LPTYUserSourcePonctuelleGeoNode pSourceGeoNode)
Definition: TYEtage.cpp:1239
bool addSrc(LPTYUserSourcePonctuelle pSrc)
Generic class for a modeler window.
TYRenderWindowInteractor * getView()
bool getSnapGridActive()
TYActionManager * getActionManager()
virtual float getDefaultZCoord()
Returns default Z coordinate for editors This value will depend on the type of modeler and of the fix...
bool askForResetResultat()
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 invalidateScene(void)
LPTYSiteNode getSite()
Get du site.
Definition: TYProjet.h:169
LPTYCalcul getCurrentCalcul()
Set/Get du pointeur du Calcul courant.
Definition: TYProjet.h:426
const TYRenderViewport & getViewport() const
TYOpenGLRenderer * getRenderer()
Classe Modeler specialisee pour l'edition des sites.
LPTYInfrastructure getInfrastructure()
Definition: TYSiteNode.h:174
TYSourceEditor(TYModelerFrame *pModeler, TYCameraEditor *pCameraEditor)
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
virtual void slotViewTypeChanged(int view)
virtual void init()
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
virtual void slotWheeled(int x, int y, int delta, Qt::KeyboardModifiers state)
bool _active
Indique si cet editor est actif.
virtual void close()
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
OVector3D & getOrientation()
void setHauteur(double hauteur)