Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYLinearMaillageEditor.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 <qdialog.h>
22 #include <qmessagebox.h>
23 #include <qpushbutton.h>
24 #include <qlabel.h>
25 #include <qlayout.h>
26 // Added by qt3to4:
27 #include <QHBoxLayout>
28 #include <QBoxLayout>
29 #include <QGridLayout>
30 #include <QVBoxLayout>
31 #include <QGroupBox>
32 #include <qvector3d.h>
33 
38 
47 #include "TYLinearMaillageEditor.h"
48 
49 #define TR(id) OLocalizator::getString("TYLinearMaillageEditor", (id))
50 
52  : TYObjectConstructionEditor(pModeler)
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 
88  _pInteractor->update();
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(QVector3D(x, _pInteractor->getViewport().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 
151  // 2eme point
152  _pOGLLineElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
153 
156 
157  // Calcul de la distance
158  double dist = point1.distanceToPoint(point2);
159 
160  // Msg Dist
161  QString msg = QString(TR("id_output_dist")).arg(dist, 0, 'f', 2);
162 
163  updateText(msg,
164  (int)(_pOGLLineElement->getPoint1()[0] +
165  (_pOGLLineElement->getPoint2()[0] - _pOGLLineElement->getPoint1()[0]) / 2.0),
166  (int)(_pOGLLineElement->getPoint2()[1] +
167  (_pOGLLineElement->getPoint1()[1] - _pOGLLineElement->getPoint2()[1]) / 2.0));
168 
169  _pInteractor->update();
170  }
171 }
172 
173 void TYLinearMaillageEditor::slotMouseReleased(int x, int y, Qt::MouseButton button,
174  Qt::KeyboardModifiers state)
175 {
176  if (_active && (button == Qt::LeftButton) && !_noCalcul)
177  {
178  // Calcul de la ligne
179  LPTYSegment pSeg = new TYSegment();
180 
181  float pt1[3], pt2[3];
182  QVector3D point1 = _pInteractor->getViewport().displayToWorld(
183  QVector3D(_pOGLLineElement->getPoint1()[0], _pOGLLineElement->getPoint1()[1],
184  _pOGLLineElement->getPoint1()[2]));
185  QVector3D point2 = _pInteractor->getViewport().displayToWorld(
186  QVector3D(_pOGLLineElement->getPoint2()[0], _pOGLLineElement->getPoint2()[1],
187  _pOGLLineElement->getPoint2()[2]));
188  pt1[0] = point1.x();
189  pt1[1] = point1.y();
190  pt1[2] = point1.z();
191  pt2[0] = point2.x();
192  pt2[1] = point2.y();
193  pt2[2] = point2.z();
194  pSeg->_ptA.setFromOGL(pt1);
195  pSeg->_ptA._z = 0 + _pModeler->getDefaultZCoord();
196  pSeg->_ptB.setFromOGL(pt2);
197  pSeg->_ptB._z = 0 + _pModeler->getDefaultZCoord();
198 
199  // Si la grille magnetique est activee
201  {
202  snapToGrid(pSeg->_ptA._x, pSeg->_ptA._y, pSeg->_ptA._z, _gridMagnStep);
203  snapToGrid(pSeg->_ptB._x, pSeg->_ptB._y, pSeg->_ptB._z, _gridMagnStep);
204  }
205 
206  // Si la taille est valide
207  if (pSeg->longueur() > 0.0)
208  {
210  {
211  TYFormDialog* pDlg = new TYFormDialog(_pModeler);
212  pDlg->setWindowTitle(TR("id_caption"));
213 
214  QGridLayout* pLayout = new QGridLayout();
215  pDlg->setLayout(pLayout);
216 
217  QGridLayout* pEditLayout = new QGridLayout();
218  pEditLayout->setContentsMargins(10, 10, 10, 10);
219  pLayout->addLayout(pEditLayout, 0, 0);
220 
221  // Hauteur
222  QLabel* pHauteurLabelName = new QLabel(TR("id_hauteur_label"));
223  TYLineEdit* pHauteurLineEdit = new TYLineEdit();
224  pHauteurLineEdit->setFixedWidth(60);
225  pHauteurLineEdit->setText(QString().setNum(2.0, 'f', 2));
226  pEditLayout->addWidget(pHauteurLabelName, 0, 0);
227  pEditLayout->addWidget(pHauteurLineEdit, 0, 1);
228 
229  // Densite
230  QLabel* pDistanceLabelName = new QLabel(TR("id_distance_label"));
231  TYLineEdit* pDistanceLineEdit = new TYLineEdit();
232  pDistanceLineEdit->setFixedWidth(60);
233  pDistanceLineEdit->setText(QString().setNum(1.0f / TY_MAILLAGE_DEFAULT_DENSITE, 'f', 2));
234  pEditLayout->addWidget(pDistanceLabelName, 1, 0);
235  pEditLayout->addWidget(pDistanceLineEdit, 1, 1);
236 
237  QBoxLayout* pBtnLayout = new QHBoxLayout();
238  pLayout->addLayout(pBtnLayout, 1, 0);
239 
240  pBtnLayout->addStretch(1);
241 
242  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), pDlg);
243  pButtonOK->setDefault(true);
244  QObject::connect(pButtonOK, &QPushButton::clicked, pDlg, &QDialog::accept);
245  pBtnLayout->addWidget(pButtonOK);
246 
247  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), pDlg);
248  pButtonCancel->setShortcut(Qt::Key_Escape);
249  QObject::connect(pButtonCancel, &QPushButton::clicked, pDlg, &QDialog::reject);
250  pBtnLayout->addWidget(pButtonCancel);
251 
252  // Affiche la boite de dialogue
253  int ret = pDlg->exec();
254 
255  TYApplication::setOverrideCursor(Qt::WaitCursor);
256 
257  // Applique les modificatins si necessaire
258  if (ret == QDialog::Accepted)
259  {
261 
262  // Nouveau maillage
263  LPTYLinearMaillage pMaillage = new TYLinearMaillage();
264  LPTYLinearMaillageGeoNode pMaillageGeoNode =
265  new TYLinearMaillageGeoNode((LPTYElement)pMaillage);
266 
267  TYProjet* pProjet = pSiteModeler->getProjet();
268  if (pProjet)
269  {
270  // Init
271  pMaillage->setHauteur(pHauteurLineEdit->text().toDouble());
272  pMaillage->make(pSeg, 1.0f / (pDistanceLineEdit->text().toDouble()));
273 
274  // Ajout au Calcul courant
275  TYAction* pAction =
276  new TYAddMaillageToProjetAction((LPTYMaillageGeoNode&)pMaillageGeoNode, pProjet,
277  _pModeler, TR("id_action_addlinearmaillage"));
278  _pModeler->getActionManager()->addAction(pAction);
279 
280  pProjet->addMaillage((LPTYMaillageGeoNode&)pMaillageGeoNode);
281  if (pProjet->getSite()->getAltimetry()->containsData())
282  {
283  // Altimetrisation du maillage
284  pProjet->updateAltiMaillage(pMaillageGeoNode);
285  }
286 
287  pMaillage->updateGraphicTree();
288  }
289  }
290 
291  delete pEditLayout;
292  delete pBtnLayout;
293  }
294 
296  }
297 
298  showText(false);
299 
301 
304 
306  dynamic_cast<TYSiteModelerFrame*>(_pModeler)->updateSelectMaillageBox();
307 
308  TYApplication::restoreOverrideCursor();
309  }
310 }
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: 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
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
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:251
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:914
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()
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)
Super-class for editors performing object construction.
void addOGLElement(OGLElement *pOGLElement)
void invalidateScene(void)
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:837
bool updateAltiMaillage(TYMaillageGeoNode *pMaillageGeoNode, const TYAltimetrie *pAlti)
Met a niveau l'altimetrie d'un maillage.
Definition: TYProjet.cpp:960
LPTYSiteNode getSite()
Get du site.
Definition: TYProjet.h:169
QVector3D displayToWorld(const QVector3D &display) const
const TYRenderViewport & getViewport() const
TYOpenGLRenderer * getRenderer()
Classe Modeler specialisee pour l'edition des sites.
LPTYAltimetrie getAltimetry() const