Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYVerticalMaillageEditor.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 <qlineedit.h>
25 #include <qlabel.h>
26 #include <qlayout.h>
27 #include <qcursor.h>
28 // Added by qt3to4:
29 #include <QHBoxLayout>
30 #include <QBoxLayout>
31 #include <QGridLayout>
32 #include <QVBoxLayout>
33 #include <QGroupBox>
34 
50 
51 #define TR(id) OLocalizator::getString("TYVerticalMaillageEditor", (id))
52 
54  : TYAbstractSceneEditor(pModeler)
55 {
56  _active = false;
57  _noCalcul = true;
58 
61  OColor oLineColor;
62  oLineColor.r = 1.0;
63  oLineColor.g = 0.0;
64  oLineColor.b = 0.0;
65  _pOGLLineElement->setColor(oLineColor);
67 
69 }
70 
72 {
74  delete _pOGLLineElement;
75 }
76 
78 
80 {
81  _active = false;
82 
83  showText(false);
84 
86  _pInteractor->update();
87 }
88 
90 {
91  cancel();
92 }
93 
95 {
96  if (view == TYModelerFrame::TopView)
97  {
98  _active = true;
99  }
100  else
101  {
102  _active = false;
103  cancel();
104  }
105 }
106 
107 void TYVerticalMaillageEditor::slotMousePressed(int x, int y, Qt::MouseButton button,
108  Qt::KeyboardModifiers state)
109 {
110  if (_active && (button == Qt::LeftButton))
111  {
112  if (getTYApp()->getCurProjet() && getTYApp()->getCurProjet()->getCurrentCalcul())
113  {
114  _noCalcul = false;
115 
116  // 1er point
117  _pOGLLineElement->setPoint1(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
118 
119  // On peut dessiner la ligne
121  }
122  else
123  {
124  _noCalcul = true;
125 
126  // Msg "Pas de calcul courant..."
127  QString msg(TR("id_warning_no_curcalcul"));
128  writeOutputMsg(msg);
129  QMessageBox::warning(_pModeler, "Tympan", msg, QMessageBox::Ok, QMessageBox::NoButton);
130  }
131  }
132 }
133 
134 void TYVerticalMaillageEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button,
135  Qt::KeyboardModifiers state)
136 {
137  if (_active && (button == Qt::LeftButton) && !_noCalcul)
138  {
139  // 2eme point
140  _pOGLLineElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
141 
144 
145  // Calcul de la distance
146  double dist = point1.distanceToPoint(point2);
147 
148  // Msg Dist
149  QString msg = QString(TR("id_size_info")).arg(dist, 0, 'f', 2);
150 
151  updateText(msg, (int)(_pOGLLineElement->getPoint1().x() + _pOGLLineElement->getPoint2().x()) / 2.0,
152  (int)(_pOGLLineElement->getPoint2().y() + _pOGLLineElement->getPoint1().y()) / 2.0);
153 
154  _pInteractor->update();
155  }
156 }
157 
158 void TYVerticalMaillageEditor::slotMouseReleased(int x, int y, Qt::MouseButton button,
159  Qt::KeyboardModifiers state)
160 {
161  if ((button == Qt::LeftButton) && _active && !_noCalcul)
162  {
163  // Calcul de la ligne
164  LPTYSegment pSeg = new TYSegment();
165 
166  float pt1[3], pt2[3];
167  QVector3D point1 = _pInteractor->getViewport().displayToWorld(
168  QVector3D(_pOGLLineElement->getPoint1()[0], _pOGLLineElement->getPoint1()[1],
169  _pOGLLineElement->getPoint1()[2]));
170  QVector3D point2 = _pInteractor->getViewport().displayToWorld(
171  QVector3D(_pOGLLineElement->getPoint2()[0], _pOGLLineElement->getPoint2()[1],
172  _pOGLLineElement->getPoint2()[2]));
173  pt1[0] = point1.x();
174  pt1[1] = point1.y();
175  pt1[2] = point1.z();
176  pt2[0] = point2.x();
177  pt2[1] = point2.y();
178  pt2[2] = point2.z();
179  pSeg->_ptA.setFromOGL(pt1);
180  pSeg->_ptA._z = 0;
181  pSeg->_ptB.setFromOGL(pt2);
182  pSeg->_ptB._z = 0;
183 
184  // Si la grille magnetique est activee
186  {
187  snapToGrid(pSeg->_ptA._x, pSeg->_ptA._y, pSeg->_ptA._z, _gridMagnStep);
188  snapToGrid(pSeg->_ptB._x, pSeg->_ptB._y, pSeg->_ptB._z, _gridMagnStep);
189  }
190 
191  // Si la taille est valide
192  if (pSeg->longueur() > 0.0)
193  {
195  {
196  QDialog* pDlg = new QDialog(_pModeler);
197  pDlg->setWindowTitle(TR("id_caption"));
198 
199  QGridLayout* pLayout = new QGridLayout();
200  pDlg->setLayout(pLayout);
201 
202  QGridLayout* pEditLayout = new QGridLayout();
203  pEditLayout->setContentsMargins(10, 10, 10, 10);
204  pLayout->addLayout(pEditLayout, 0, 0);
205 
206  // Hauteur au sol
207  QLabel* pHauteurSolLabelName = new QLabel(TR("id_hauteursol_label"));
208  TYLineEdit* pHauteurSolLineEdit = new TYLineEdit();
209  pHauteurSolLineEdit->setFixedWidth(60);
210  pHauteurSolLineEdit->setText(QString().setNum(2.0, 'f', 2));
211  pEditLayout->addWidget(pHauteurSolLabelName, 0, 0);
212  pEditLayout->addWidget(pHauteurSolLineEdit, 0, 1);
213 
214  // Hauteur maillage
215  QLabel* pHauteurLabelName = new QLabel(TR("id_hauteur_label"));
216  TYLineEdit* pHauteurLineEdit = new TYLineEdit();
217  pHauteurLineEdit->setFixedWidth(60);
218  pHauteurLineEdit->setText(QString().setNum(2.0, 'f', 2));
219  pEditLayout->addWidget(pHauteurLabelName, 1, 0);
220  pEditLayout->addWidget(pHauteurLineEdit, 1, 1);
221 
222  // Densite X
223  QLabel* pDistanceXLabelName = new QLabel(TR("id_distancex_label"));
224  TYLineEdit* pDistanceXLineEdit = new TYLineEdit();
225  pDistanceXLineEdit->setFixedWidth(60);
226  pDistanceXLineEdit->setText(QString().setNum(1.0f / TY_MAILLAGE_DEFAULT_DENSITE, 'f', 2));
227  pEditLayout->addWidget(pDistanceXLabelName, 2, 0);
228  pEditLayout->addWidget(pDistanceXLineEdit, 2, 1);
229 
230  // Densite Y
231  QLabel* pDistanceYLabelName = new QLabel(TR("id_distancey_label"));
232  TYLineEdit* pDistanceYLineEdit = new TYLineEdit();
233  pDistanceYLineEdit->setFixedWidth(60);
234  pDistanceYLineEdit->setText(QString().setNum(1.0f / TY_MAILLAGE_DEFAULT_DENSITE, 'f', 2));
235  pEditLayout->addWidget(pDistanceYLabelName, 3, 0);
236  pEditLayout->addWidget(pDistanceYLineEdit, 3, 1);
237 
238  QBoxLayout* pBtnLayout = new QHBoxLayout();
239  pLayout->addLayout(pBtnLayout, 1, 0);
240 
241  pBtnLayout->addStretch(1);
242 
243  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), pDlg);
244  pButtonOK->setDefault(true);
245  QObject::connect(pButtonOK, &QPushButton::clicked, pDlg, &QDialog::accept);
246  pBtnLayout->addWidget(pButtonOK);
247 
248  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), pDlg);
249  pButtonCancel->setShortcut(Qt::Key_Escape);
250  QObject::connect(pButtonCancel, &QPushButton::clicked, pDlg, &QDialog::reject);
251  pBtnLayout->addWidget(pButtonCancel);
252 
253  // Affiche la boite de dialogue
254  int ret = pDlg->exec();
255 
256  TYApplication::setOverrideCursor(Qt::WaitCursor);
257 
258  // Applique les modificatins si necessaire
259  if (ret == QDialog::Accepted)
260  {
262 
263  // Position
264  TYPoint org = pSeg->centreOf();
265  org._z = _pModeler->getDefaultZCoord();
266 
267  // Si la grille magnetique est activee
269  {
270  snapToGrid(org._x, org._y, org._z, _gridMagnStep);
271  }
272 
273  TYRepere rep;
274  rep._origin = org;
275  rep._vecI = pSeg->toVector3D();
276  rep._vecI.normalize();
277  rep._vecJ.setCoords(0.0, 0.0, 1.0);
278  rep._vecK = rep._vecI.cross(rep._vecJ);
279 
280  // Construction du rectangle
281  LPTYRectangle pRectangle = new TYRectangle();
282  pRectangle->setSize(pSeg->longueur(), pHauteurLineEdit->text().toDouble());
283 
284  // Nouveau maillage
286  LPTYRectangularMaillageGeoNode pMaillageGeoNode =
287  new TYRectangularMaillageGeoNode(rep, (LPTYElement)pMaillage);
288 
289  TYProjet* pProjet = pSiteModeler->getProjet();
290  if (pProjet)
291  {
292  // Init
293  pMaillage->setHauteur(pHauteurSolLineEdit->text().toDouble());
294  pMaillage->make(pRectangle, 1.0f / (pDistanceXLineEdit->text().toDouble()),
295  1.0f / (pDistanceYLineEdit->text().toDouble()));
296 
297  // On ne calcule pas l'alti des points pour ce type de maillage
298  pMaillage->setComputeAlti(false);
299 
300  TYAction* pAction =
301  new TYAddMaillageToProjetAction((LPTYMaillageGeoNode&)pMaillageGeoNode, pProjet,
302  _pModeler, TR("id_action_addrectmaillage"));
303  _pModeler->getActionManager()->addAction(pAction);
304 
305  pProjet->addMaillage((LPTYMaillageGeoNode&)pMaillageGeoNode);
306  if (pProjet->getSite()->getAltimetry()->containsData())
307  {
308  // Altimetrisation du maillage
309  pProjet->updateAltiMaillage(pMaillageGeoNode);
310  }
311 
312  pMaillage->updateGraphicTree();
313  }
314  }
315 
316  delete pEditLayout;
317  delete pBtnLayout;
318  }
319 
321  }
322 
323  showText(false);
324 
329 
330  TYApplication::restoreOverrideCursor();
331  }
332 }
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)
outil IHM pour une entrée utilisateur (fichier header)
Classe generique pour une fenetre de modeleur (fichier header)
Representation graphique d'un point (fichier header)
TYGeometryNode TYRectangularMaillageGeoNode
Noeud geometrique de type TYRectangularMaillage.
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)
#define TR(id)
gestion de l'edition d'un maillage verticale (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 setCoords(double x, double y, double z)
Sets the coordinates as an array of double.
Definition: 3d.cpp:76
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
OVector3D _vecK
Vector K for the Z axis.
Definition: 3d.h:1337
OVector3D _vecJ
Vector J for the Y axis.
Definition: 3d.h:1335
OVector3D _vecI
Vector I for the X axis.
Definition: 3d.h:1333
OPoint3D _origin
The origin point.
Definition: 3d.h:1331
virtual double longueur() const
Return the segment length.
Definition: 3d.cpp:1238
virtual OPoint3D centreOf() const
Return the position of the segment middle.
Definition: 3d.cpp:1294
OPoint3D _ptA
Point A of the segment.
Definition: 3d.h:1253
virtual OVector3D toVector3D() const
Build a OVector3D from a segment used for the direction of the sources.
Definition: 3d.h:1240
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1255
void normalize()
Normalizes this vector.
Definition: 3d.cpp:225
OVector3D cross(const OVector3D &vector) const
Cross product.
Definition: 3d.cpp:196
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
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
void setSize(float sizeX, float sizeY)
Classe de definition d'un maillage rectangulaire.
QVector3D displayToWorld(const QVector3D &display) const
const TYRenderViewport & getViewport() const
TYOpenGLRenderer * getRenderer()
Classe Modeler specialisee pour l'edition des sites.
LPTYAltimetrie getAltimetry() const
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
bool _active
Indique si cet editor est actif.
OGLLineElement * _pOGLLineElement
La ligne courante.
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
virtual void slotViewTypeChanged(int view)
TYVerticalMaillageEditor(TYSiteModelerFrame *pModeler)
bool _noCalcul
Indique l'absence de calcul courant.
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)