Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYLinearMaillageEditor.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 <qdialog.h>
22 #include <qmessagebox.h>
23 #include <qpushbutton.h>
24 #include <qlabel.h>
25 #include <qlayout.h>
26 #include <qcursor.h>
27 // Added by qt3to4:
28 #include <QHBoxLayout>
29 #include <QBoxLayout>
30 #include <QGridLayout>
31 #include <QVBoxLayout>
32 #include <QBoxLayout>
33 #include <QGroupBox>
34 
39 
48 #include "TYLinearMaillageEditor.h"
49 
50 #define TR(id) OLocalizator::getString("TYLinearMaillageEditor", (id))
51 
53 {
54  _active = false;
55  _noCalcul = true;
56 
59  OColor oLineColor;
60  oLineColor.r = 1.0;
61  oLineColor.g = 0.0;
62  oLineColor.b = 0.0;
63  _pOGLLineElement->setColor(oLineColor);
65 
67 }
68 
70 {
72  delete _pOGLLineElement;
73 }
74 
76 
78 {
79  close();
80 }
81 
83 {
84  _active = false;
85  showText(false);
86 
89 }
90 
92 {
93  switch (key)
94  {
95  case Qt::Key_Escape:
96  if (_active)
97  {
98  cancel();
99  }
100  break;
101  }
102 }
103 
105 {
106  if (view == TYModelerFrame::PerspView)
107  {
108  _active = false;
109  cancel();
110  }
111  else
112  {
113  _active = true;
114  }
115 }
116 
117 void TYLinearMaillageEditor::slotMousePressed(int x, int y, Qt::MouseButton button,
118  Qt::KeyboardModifiers state)
119 {
120  if (_active && (button == Qt::LeftButton))
121  {
122  if (getTYApp()->getCurProjet() && getTYApp()->getCurProjet()->getCurrentCalcul())
123  {
124  _noCalcul = false;
125 
126  // 1er point
127  _pOGLLineElement->setPoint1(OPoint3D(x, _pInteractor->height() - y, 0.0));
128 
129  // On peut dessiner la ligne
131  }
132  else
133  {
134  _noCalcul = true;
135 
136  // Msg "Pas de calcul courant..."
137  QString msg(TR("id_warning_no_curcalcul"));
138  writeOutputMsg(msg);
139  QMessageBox::warning(_pModeler, "Tympan", msg, QMessageBox::Ok, QMessageBox::NoButton);
140  }
141  }
142 }
143 
144 void TYLinearMaillageEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button,
145  Qt::KeyboardModifiers state)
146 {
147  if (_active && (button == Qt::LeftButton) && !_noCalcul)
148  {
149  // On recupere la position du curseur
150  QPoint pos = _pInteractor->mapFromGlobal(QCursor::pos());
151 
152  // 2eme point
153  _pOGLLineElement->setPoint2(OPoint3D(pos.x(), _pInteractor->height() - y, 0.0));
154 
157  _pOGLLineElement->getPoint1()[2]));
160  _pOGLLineElement->getPoint2()[2]));
161 
162  // Calcul de la distance
163  double dist = point1.distance(point2);
164 
165  // Msg Dist
166  QString msg = QString(TR("id_output_dist")).arg(dist, 0, 'f', 2);
167 
168  updateText(msg,
169  (int)(_pOGLLineElement->getPoint1()[0] +
170  (_pOGLLineElement->getPoint2()[0] - _pOGLLineElement->getPoint1()[0]) / 2.0),
171  (int)(_pOGLLineElement->getPoint2()[1] +
172  (_pOGLLineElement->getPoint1()[1] - _pOGLLineElement->getPoint2()[1]) / 2.0));
173 
175  }
176 }
177 
178 void TYLinearMaillageEditor::slotMouseReleased(int x, int y, Qt::MouseButton button,
179  Qt::KeyboardModifiers state)
180 {
181  if (_active && (button == Qt::LeftButton) && !_noCalcul)
182  {
183  // Calcul de la ligne
184  LPTYSegment pSeg = new TYSegment();
185 
186  float pt1[3], pt2[3];
189  _pOGLLineElement->getPoint1()[2]));
192  _pOGLLineElement->getPoint2()[2]));
193  pt1[0] = point1.x;
194  pt1[1] = point1.y;
195  pt1[2] = point1.z;
196  pt2[0] = point2.x;
197  pt2[1] = point2.y;
198  pt2[2] = point2.z;
199  pSeg->_ptA.setFromOGL(pt1);
200  pSeg->_ptA._z = 0;
201  pSeg->_ptB.setFromOGL(pt2);
202  pSeg->_ptB._z = 0;
203 
204  // Si la grille magnetique est activee
206  {
207  snapToGrid(pSeg->_ptA._x, pSeg->_ptA._y, pSeg->_ptA._z, _gridMagnStep);
208  snapToGrid(pSeg->_ptB._x, pSeg->_ptB._y, pSeg->_ptB._z, _gridMagnStep);
209  }
210 
211  // Si la taille est valide
212  if (pSeg->longueur() > 0.0)
213  {
215  {
216  TYFormDialog* pDlg = new TYFormDialog(_pModeler);
217  pDlg->setWindowTitle(TR("id_caption"));
218 
219  QGridLayout* pLayout = new QGridLayout();
220  pDlg->setLayout(pLayout);
221 
222  QGridLayout* pEditLayout = new QGridLayout();
223  pEditLayout->setContentsMargins(10, 10, 10, 10);
224  pLayout->addLayout(pEditLayout, 0, 0);
225 
226  // Hauteur
227  QLabel* pHauteurLabelName = new QLabel(TR("id_hauteur_label"));
228  TYLineEdit* pHauteurLineEdit = new TYLineEdit();
229  pHauteurLineEdit->setFixedWidth(60);
230  pHauteurLineEdit->setText(QString().setNum(2.0, 'f', 2));
231  pEditLayout->addWidget(pHauteurLabelName, 0, 0);
232  pEditLayout->addWidget(pHauteurLineEdit, 0, 1);
233 
234  // Densite
235  QLabel* pDensiteLabelName = new QLabel(TR("id_densite_label"));
236  TYLineEdit* pDensiteLineEdit = new TYLineEdit();
237  pDensiteLineEdit->setFixedWidth(60);
238  pDensiteLineEdit->setText(QString().setNum(TY_MAILLAGE_DEFAULT_DENSITE, 'f', 4));
239  pEditLayout->addWidget(pDensiteLabelName, 1, 0);
240  pEditLayout->addWidget(pDensiteLineEdit, 1, 1);
241 
242  QBoxLayout* pBtnLayout = new QHBoxLayout();
243  pLayout->addLayout(pBtnLayout, 1, 0);
244 
245  pBtnLayout->addStretch(1);
246 
247  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), pDlg);
248  pButtonOK->setDefault(true);
249  QObject::connect(pButtonOK, &QPushButton::clicked, pDlg, &QDialog::accept);
250  pBtnLayout->addWidget(pButtonOK);
251 
252  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), pDlg);
253  pButtonCancel->setShortcut(Qt::Key_Escape);
254  QObject::connect(pButtonCancel, &QPushButton::clicked, pDlg, &QDialog::reject);
255  pBtnLayout->addWidget(pButtonCancel);
256 
257  // Affiche la boite de dialogue
258  int ret = pDlg->exec();
259 
260  TYApplication::setOverrideCursor(Qt::WaitCursor);
261 
262  // Applique les modificatins si necessaire
263  if (ret == QDialog::Accepted)
264  {
266 
267  // Nouveau maillage
268  LPTYLinearMaillage pMaillage = new TYLinearMaillage();
269  LPTYLinearMaillageGeoNode pMaillageGeoNode =
270  new TYLinearMaillageGeoNode((LPTYElement)pMaillage);
271 
272  TYProjet* pProjet = pSiteModeler->getProjet();
273  if (pProjet)
274  {
275  // Init
276  pMaillage->setHauteur(pHauteurLineEdit->text().toDouble());
277  pMaillage->make(pSeg, pDensiteLineEdit->text().toDouble());
278 
279  // Ajout au Calcul courant
280  TYAction* pAction =
281  new TYAddMaillageToProjetAction((LPTYMaillageGeoNode&)pMaillageGeoNode, pProjet,
282  _pModeler, TR("id_action_addlinearmaillage"));
283  _pModeler->getActionManager()->addAction(pAction);
284 
285  pProjet->addMaillage((LPTYMaillageGeoNode&)pMaillageGeoNode);
286  if (pProjet->getSite()->getAltimetry()->containsData())
287  {
288  // Altimetrisation du maillage
289  pProjet->updateAltiMaillage(pMaillageGeoNode);
290  }
291 
292  pMaillage->updateGraphicTree();
293  }
294  }
295 
296  delete pEditLayout;
297  delete pBtnLayout;
298  }
299 
301  }
302 
303  showText(false);
304 
306 
309 
311  dynamic_cast<TYSiteModelerFrame*>(_pModeler)->updateSelectMaillageBox();
312 
313  TYApplication::restoreOverrideCursor();
314  }
315 }
fichier contenant differents types d'actions (fichier header)
void writeOutputMsg(QString msg)
Affiche un message dans la fenetre de sortie.
TYApplication * getTYApp()
Retourne le pointeur sur l'application.
pour l'application Tympan (fichier header)
Parent class of Tympan Qt dialogs of type form (geader file)
outil IHM pour une entrée utilisateur (fichier header)
#define TR(id)
Indique si cet editor est actif (fichier header)
TYGeometryNode TYLinearMaillageGeoNode
Noeud geometrique de type TYLinearMaillage.
Classe generique pour une fenetre de modeleur (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: NxVec3.h:23
NxReal z
Definition: NxVec3.h:80
NxReal y
Definition: NxVec3.h:80
NxReal distance(const NxVec3 &) const
Definition: NxVec3.cpp:199
NxReal x
Definition: NxVec3.h:80
Definition: color.h:31
float b
Definition: color.h:33
float r
Definition: color.h:33
float g
Definition: color.h:33
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
static NxVec3 displayToWorld(NxVec3 display)
Definition: OGLCamera.cpp:699
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 ...
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 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.
TYModelerFrame * _pModeler
Le modeler associe a cet editor.
void showText(bool show=true)
Affiche ou pas le texte informatif sur la vue 3D.
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
bool containsData()
Definition: TYAltimetrie.h:237
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:915
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 slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
bool _noCalcul
Indique l'absence de calcul courant.
OGLLineElement * _pOGLLineElement
La ligne courante.
TYLinearMaillageEditor(TYSiteModelerFrame *pModeler)
virtual void slotKeyPressed(int key)
virtual void slotViewTypeChanged(int view)
bool _active
Indique si cet editor est actif.
Classe de definition d'un maillage lineaire.
TYRenderWindowInteractor * getView()
bool getSnapGridActive()
TYActionManager * getActionManager()
bool askForResetResultat()
virtual void updateView(bool clipping=true, bool axesAndGrid=true)
void updateDisplayList(void)
void addOGLElement(OGLElement *pOGLElement)
void removeOGLElement(OGLElement *pOGLElement)
classe de definition d'un projet.
Definition: TYProjet.h:45
bool addMaillage(LPTYMaillageGeoNode pMaillageGeoNode)
Ajout d'un maillage.
Definition: TYProjet.cpp:783
bool updateAltiMaillage(TYMaillageGeoNode *pMaillageGeoNode, const TYAltimetrie *pAlti)
Met a niveau l'altimetrie d'un maillage.
Definition: TYProjet.cpp:906
LPTYSiteNode getSite()
Get du site.
Definition: TYProjet.h:169
virtual void updateGL()
TYOpenGLRenderer * getRenderer()
Classe Modeler specialisee pour l'edition des sites.
LPTYAltimetrie getAltimetry() const