Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSourceEditor.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 
32 #include "TYSourceEditor.h"
33 
34 #define TR(id) OLocalizator::getString("TYSourceEditor", (id))
35 
37 {
38  _active = false;
39 
41 }
42 
44 
46 
48 
50 {
51  if (view == TYModelerFrame::TopView)
52  {
53  _active = true;
54  }
55  else
56  {
57  _active = false;
58  }
59 }
60 
61 void TYSourceEditor::slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
62 {
63  if ((button == Qt::LeftButton) && _active)
64  {
65  }
66 }
67 
68 void TYSourceEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
69 {
70  if ((button == Qt::LeftButton) && _active)
71  {
72  }
73 }
74 
75 void TYSourceEditor::slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
76 {
77  if ((button == Qt::LeftButton) && _active)
78  {
80  {
81  return;
82  }
83 
84  // Hauteur pour ce point de controle
85  bool ok = false;
86  double hauteur = TYModelerFrame::getDouble("", TR("id_msg_gethauteur"), -1000.0, 1000.0, 2.0, ok);
87 
88  if (ok)
89  {
90  double point[4];
92 
93  // Pos
94  displayToWorld(x, _pInteractor->height() - y, 0.0, point);
95 
96  // Si la grille magnetique est activee
98  {
99  snapToGrid(point[0], point[1], point[2], _gridMagnStep);
100  }
101 
102  // Init source
103  pSrcPonct->setHauteur(hauteur);
104  pSrcPonct->getPos()->setFromOGL(point);
105  pSrcPonct->getPos()->_z = 0.0;
106  pSrcPonct->getOrientation()._x = 1.0;
107 
108  if (QString(_pModeler->metaObject()->className()).compare("TYSiteModelerFrame") == 0)
109  {
110  TYSiteNode* pSite = ((TYSiteModelerFrame*)_pModeler)->getSite();
111 
112  // Ajout
113  if (pSite->getInfrastructure()->addSrc(pSrcPonct))
114  {
115  // On ajoute cette source a la selection du calcul courant
116  if (getTYApp()->getCurProjet() && (getTYApp()->getCurProjet()->getSite() == pSite))
117  {
119 
120  if (pCalcul)
121  {
122  pCalcul->addToSelection(pSrcPonct);
123  }
124  }
125 
126  // Action
127  TYAction* pAction =
128  new TYAddElementToInfraAction((LPTYElement&)pSrcPonct, pSite->getInfrastructure(),
129  _pModeler, TR("id_action_addsource"));
130  _pModeler->getActionManager()->addAction(pAction);
131 
133 
134  // Update
135  pSite->getInfrastructure()->updateGraphicTree();
137  updateSiteFrame(); // Mise a jour de l'arborescence de site
138  }
139  }
140  else if (QString(_pModeler->metaObject()->className()).compare("TYBatimentModelerFrame") == 0)
141  {
142  pSrcPonct->getPos()->_z = hauteur;
143 
144  TYBatiment* pBat = ((TYBatimentModelerFrame*)_pModeler)->getBatiment();
145  LPTYEtage pEtage = (TYEtage*)pBat->getAcousticVol(0).getRealPointer();
146 
147  if (pEtage)
148  {
149  bool addOk = pEtage->addSource(pSrcPonct);
150 
151  if (addOk) // Si l'action d'ajouter a ete effectuee sans probleme
152  {
153  // Action
154  TYAction* pAction = new TYAddElementToEtageAction(
155  (LPTYElement&)pSrcPonct, pEtage, _pModeler, TR("id_action_addsource"));
156  _pModeler->getActionManager()->addAction(pAction);
157  }
158 
159  // Update
160  pEtage->updateGraphicTree();
161  updateSiteFrame();
164  }
165  }
166 
168  }
169  }
170 }
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)
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.
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:270
Ajout d'un element a une infrastructure.
Definition: TYActions.h:398
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:872
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:915
bool addSource(LPTYUserSourcePonctuelleGeoNode pSourceGeoNode)
Definition: TYEtage.cpp:1218
bool addSrc(LPTYUserSourcePonctuelle pSrc)
Classe generique pour une fenetre de modeleur.
TYRenderWindowInteractor * getView()
bool getSnapGridActive()
TYActionManager * getActionManager()
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 updateDisplayList(void)
LPTYSiteNode getSite()
Get du site.
Definition: TYProjet.h:169
LPTYCalcul getCurrentCalcul()
Set/Get du pointeur du Calcul courant.
Definition: TYProjet.h:426
TYOpenGLRenderer * getRenderer()
Classe Modeler specialisee pour l'edition des sites.
LPTYInfrastructure getInfrastructure()
Definition: TYSiteNode.h:173
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
TYSourceEditor(TYModelerFrame *pModeler)
virtual void slotViewTypeChanged(int view)
virtual void init()
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, 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)