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 {
53  _active = false;
54  _noCalcul = true;
55 
58  OColor oLineColor;
59  oLineColor.r = 1.0;
60  oLineColor.g = 0.0;
61  oLineColor.b = 0.0;
62  _pOGLLineElement->setColor(oLineColor);
64 
66 }
67 
69 {
71  delete _pOGLLineElement;
72 }
73 
75 
77 {
78  close();
79 }
80 
82 {
83  _active = false;
84  showText(false);
85 
87  _pInteractor->update();
88 }
89 
91 {
92  switch (key)
93  {
94  case Qt::Key_Escape:
95  if (_active)
96  {
97  cancel();
98  }
99  break;
100  }
101 }
102 
104 {
105  if (view == TYModelerFrame::PerspView)
106  {
107  _active = false;
108  cancel();
109  }
110  else
111  {
112  _active = true;
113  }
114 }
115 
116 void TYLinearMaillageEditor::slotMousePressed(int x, int y, Qt::MouseButton button,
117  Qt::KeyboardModifiers state)
118 {
119  if (_active && (button == Qt::LeftButton))
120  {
121  if (getTYApp()->getCurProjet() && getTYApp()->getCurProjet()->getCurrentCalcul())
122  {
123  _noCalcul = false;
124 
125  // 1er point
126  _pOGLLineElement->setPoint1(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
127 
128  // On peut dessiner la ligne
130  }
131  else
132  {
133  _noCalcul = true;
134 
135  // Msg "Pas de calcul courant..."
136  QString msg(TR("id_warning_no_curcalcul"));
137  writeOutputMsg(msg);
138  QMessageBox::warning(_pModeler, "Tympan", msg, QMessageBox::Ok, QMessageBox::NoButton);
139  }
140  }
141 }
142 
143 void TYLinearMaillageEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button,
144  Qt::KeyboardModifiers state)
145 {
146  if (_active && (button == Qt::LeftButton) && !_noCalcul)
147  {
148  // On recupere la position du curseur
149 
150  // 2eme point
151  _pOGLLineElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
152 
155 
156  // Calcul de la distance
157  double dist = point1.distanceToPoint(point2);
158 
159  // Msg Dist
160  QString msg = QString(TR("id_output_dist")).arg(dist, 0, 'f', 2);
161 
162  updateText(msg,
163  (int)(_pOGLLineElement->getPoint1()[0] +
164  (_pOGLLineElement->getPoint2()[0] - _pOGLLineElement->getPoint1()[0]) / 2.0),
165  (int)(_pOGLLineElement->getPoint2()[1] +
166  (_pOGLLineElement->getPoint1()[1] - _pOGLLineElement->getPoint2()[1]) / 2.0));
167 
168  _pInteractor->update();
169  }
170 }
171 
172 void TYLinearMaillageEditor::slotMouseReleased(int x, int y, Qt::MouseButton button,
173  Qt::KeyboardModifiers state)
174 {
175  if (_active && (button == Qt::LeftButton) && !_noCalcul)
176  {
177  // Calcul de la ligne
178  LPTYSegment pSeg = new TYSegment();
179 
180  float pt1[3], pt2[3];
181  QVector3D point1 = _pInteractor->getViewport().displayToWorld(
182  QVector3D(_pOGLLineElement->getPoint1()[0], _pOGLLineElement->getPoint1()[1],
183  _pOGLLineElement->getPoint1()[2]));
184  QVector3D point2 = _pInteractor->getViewport().displayToWorld(
185  QVector3D(_pOGLLineElement->getPoint2()[0], _pOGLLineElement->getPoint2()[1],
186  _pOGLLineElement->getPoint2()[2]));
187  pt1[0] = point1.x();
188  pt1[1] = point1.y();
189  pt1[2] = point1.z();
190  pt2[0] = point2.x();
191  pt2[1] = point2.y();
192  pt2[2] = point2.z();
193  pSeg->_ptA.setFromOGL(pt1);
194  pSeg->_ptA._z = 0 + _pModeler->getDefaultZCoord();
195  pSeg->_ptB.setFromOGL(pt2);
196  pSeg->_ptB._z = 0 + _pModeler->getDefaultZCoord();
197 
198  // Si la grille magnetique est activee
200  {
201  snapToGrid(pSeg->_ptA._x, pSeg->_ptA._y, pSeg->_ptA._z, _gridMagnStep);
202  snapToGrid(pSeg->_ptB._x, pSeg->_ptB._y, pSeg->_ptB._z, _gridMagnStep);
203  }
204 
205  // Si la taille est valide
206  if (pSeg->longueur() > 0.0)
207  {
209  {
210  TYFormDialog* pDlg = new TYFormDialog(_pModeler);
211  pDlg->setWindowTitle(TR("id_caption"));
212 
213  QGridLayout* pLayout = new QGridLayout();
214  pDlg->setLayout(pLayout);
215 
216  QGridLayout* pEditLayout = new QGridLayout();
217  pEditLayout->setContentsMargins(10, 10, 10, 10);
218  pLayout->addLayout(pEditLayout, 0, 0);
219 
220  // Hauteur
221  QLabel* pHauteurLabelName = new QLabel(TR("id_hauteur_label"));
222  TYLineEdit* pHauteurLineEdit = new TYLineEdit();
223  pHauteurLineEdit->setFixedWidth(60);
224  pHauteurLineEdit->setText(QString().setNum(2.0, 'f', 2));
225  pEditLayout->addWidget(pHauteurLabelName, 0, 0);
226  pEditLayout->addWidget(pHauteurLineEdit, 0, 1);
227 
228  // Densite
229  QLabel* pDistanceLabelName = new QLabel(TR("id_distance_label"));
230  TYLineEdit* pDistanceLineEdit = new TYLineEdit();
231  pDistanceLineEdit->setFixedWidth(60);
232  pDistanceLineEdit->setText(QString().setNum(1.0f / TY_MAILLAGE_DEFAULT_DENSITE, 'f', 2));
233  pEditLayout->addWidget(pDistanceLabelName, 1, 0);
234  pEditLayout->addWidget(pDistanceLineEdit, 1, 1);
235 
236  QBoxLayout* pBtnLayout = new QHBoxLayout();
237  pLayout->addLayout(pBtnLayout, 1, 0);
238 
239  pBtnLayout->addStretch(1);
240 
241  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), pDlg);
242  pButtonOK->setDefault(true);
243  QObject::connect(pButtonOK, &QPushButton::clicked, pDlg, &QDialog::accept);
244  pBtnLayout->addWidget(pButtonOK);
245 
246  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), pDlg);
247  pButtonCancel->setShortcut(Qt::Key_Escape);
248  QObject::connect(pButtonCancel, &QPushButton::clicked, pDlg, &QDialog::reject);
249  pBtnLayout->addWidget(pButtonCancel);
250 
251  // Affiche la boite de dialogue
252  int ret = pDlg->exec();
253 
254  TYApplication::setOverrideCursor(Qt::WaitCursor);
255 
256  // Applique les modificatins si necessaire
257  if (ret == QDialog::Accepted)
258  {
260 
261  // Nouveau maillage
262  LPTYLinearMaillage pMaillage = new TYLinearMaillage();
263  LPTYLinearMaillageGeoNode pMaillageGeoNode =
264  new TYLinearMaillageGeoNode((LPTYElement)pMaillage);
265 
266  TYProjet* pProjet = pSiteModeler->getProjet();
267  if (pProjet)
268  {
269  // Init
270  pMaillage->setHauteur(pHauteurLineEdit->text().toDouble());
271  pMaillage->make(pSeg, 1.0f / (pDistanceLineEdit->text().toDouble()));
272 
273  // Ajout au Calcul courant
274  TYAction* pAction =
275  new TYAddMaillageToProjetAction((LPTYMaillageGeoNode&)pMaillageGeoNode, pProjet,
276  _pModeler, TR("id_action_addlinearmaillage"));
277  _pModeler->getActionManager()->addAction(pAction);
278 
279  pProjet->addMaillage((LPTYMaillageGeoNode&)pMaillageGeoNode);
280  if (pProjet->getSite()->getAltimetry()->containsData())
281  {
282  // Altimetrisation du maillage
283  pProjet->updateAltiMaillage(pMaillageGeoNode);
284  }
285 
286  pMaillage->updateGraphicTree();
287  }
288  }
289 
290  delete pEditLayout;
291  delete pBtnLayout;
292  }
293 
295  }
296 
297  showText(false);
298 
300 
303 
305  dynamic_cast<TYSiteModelerFrame*>(_pModeler)->updateSelectMaillageBox();
306 
307  TYApplication::restoreOverrideCursor();
308  }
309 }
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
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: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)
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:827
bool updateAltiMaillage(TYMaillageGeoNode *pMaillageGeoNode, const TYAltimetrie *pAlti)
Met a niveau l'altimetrie d'un maillage.
Definition: TYProjet.cpp:950
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