Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRectangularMaillageEditor.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("TYRectangularMaillageEditor", (id))
52 
54  : TYAbstractSceneEditor(pModeler)
55 {
58  OColor oLineColor;
59  oLineColor.r = 1.0;
60  oLineColor.g = 0.0;
61  oLineColor.b = 0.0;
62  _pOGLRectangleElement->setColor(oLineColor);
63  _pOGLRectangleElement->setPoint0(QVector3D(0.0, 0.0, 0.0));
64  _pOGLRectangleElement->setPoint1(QVector3D(0.0, 0.0, 0.0));
65  _pOGLRectangleElement->setPoint2(QVector3D(0.0, 0.0, 0.0));
66  _pOGLRectangleElement->setPoint3(QVector3D(0.0, 0.0, 0.0));
68 
69  _moving = false;
70  _active = false;
72 }
73 
75 {
77  delete _pOGLRectangleElement;
78 }
79 
81 
83 {
84  _moving = false;
85  _active = false;
86 
87  showText(false);
88 
90  _pInteractor->update();
91 }
92 
94 {
95  cancel();
96 }
97 
99 {
100  if (view == TYModelerFrame::TopView)
101  {
102  _active = true;
103  }
104  else
105  {
106  _active = false;
107  }
108 }
109 
110 void TYRectangularMaillageEditor::slotMousePressed(int x, int y, Qt::MouseButton button,
111  Qt::KeyboardModifiers state)
112 {
113  if ((button == Qt::LeftButton) && _active)
114  {
115  if (getTYApp()->getCurProjet() && getTYApp()->getCurProjet()->getCurrentCalcul())
116  {
117  // Init points
118  _pOGLRectangleElement->setPoint0(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
119  _pOGLRectangleElement->setPoint1(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
120  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
121  _pOGLRectangleElement->setPoint3(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
122  _moving = true;
123  }
124  else
125  {
126  _moving = false;
127 
128  // Msg "Pas de calcul courant..."
129  QString msg(TR("id_warning_no_curcalcul"));
130  writeOutputMsg(msg);
131  QMessageBox::warning(_pModeler, "Tympan", msg, QMessageBox::Ok, QMessageBox::NoButton);
132  }
133  }
134 }
135 
136 void TYRectangularMaillageEditor::slotMouseReleased(int x, int y, Qt::MouseButton button,
137  Qt::KeyboardModifiers state)
138 {
139  if ((button == Qt::LeftButton) && _active && _moving)
140  {
141  _moving = false;
142 
143  TYPoint pt0, pt1, pt2;
144  QVector3D point0 = _pInteractor->getViewport().displayToWorld(
147  QVector3D point1 = _pInteractor->getViewport().displayToWorld(
150  QVector3D point2 = _pInteractor->getViewport().displayToWorld(
153  pt0._x = point0.x();
154  pt0._y = -point0.z();
155  pt0._z = point0.y();
156  pt1._x = point1.x();
157  pt1._y = -point1.z();
158  pt1._z = point1.y();
159  pt2._x = point2.x();
160  pt2._y = -point2.z();
161  pt2._z = point2.y();
162 
163  double sizeX = OVector3D(pt0, pt1).norme();
164  double sizeY = OVector3D(pt1, pt2).norme();
165  double sizeZ = 0;
166 
167  // Si la grille magnetique est activee
169  {
170  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
171  }
172 
173  // Si la taille est valide
174  if (sizeX && sizeY)
175  {
177  {
178  TYFormDialog* pDlg = new TYFormDialog(_pModeler);
179  pDlg->setWindowTitle(TR("id_caption"));
180 
181  QGridLayout* pLayout = new QGridLayout();
182  pDlg->setLayout(pLayout);
183 
184  QGridLayout* pEditLayout = new QGridLayout();
185  pEditLayout->setContentsMargins(10, 10, 10, 10);
186  pLayout->addLayout(pEditLayout, 0, 0);
187 
188  // Hauteur
189  QLabel* pHauteurLabelName = new QLabel(TR("id_hauteur_label"));
190  TYLineEdit* pHauteurLineEdit = new TYLineEdit();
191  pHauteurLineEdit->setFixedWidth(60);
192  pHauteurLineEdit->setText(QString().setNum(2.0, 'f', 2));
193  pEditLayout->addWidget(pHauteurLabelName, 0, 0);
194  pEditLayout->addWidget(pHauteurLineEdit, 0, 1);
195 
196  // Densite X
197  QLabel* pDistanceXLabelName = new QLabel(TR("id_distancex_label"));
198  TYLineEdit* pDistanceXLineEdit = new TYLineEdit();
199  pDistanceXLineEdit->setFixedWidth(60);
200  pDistanceXLineEdit->setText(QString().setNum(1.0f / TY_MAILLAGE_DEFAULT_DENSITE, 'f', 2));
201  pEditLayout->addWidget(pDistanceXLabelName, 1, 0);
202  pEditLayout->addWidget(pDistanceXLineEdit, 1, 1);
203 
204  // Densite Y
205  QLabel* pDistanceYLabelName = new QLabel(TR("id_distancey_label"));
206  TYLineEdit* pDistanceYLineEdit = new TYLineEdit();
207  pDistanceYLineEdit->setFixedWidth(60);
208  pDistanceYLineEdit->setText(QString().setNum(1.0f / TY_MAILLAGE_DEFAULT_DENSITE, 'f', 2));
209  pEditLayout->addWidget(pDistanceYLabelName, 2, 0);
210  pEditLayout->addWidget(pDistanceYLineEdit, 2, 1);
211 
212  QBoxLayout* pBtnLayout = new QHBoxLayout();
213  pLayout->addLayout(pBtnLayout, 1, 0);
214 
215  pBtnLayout->addStretch(1);
216 
217  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), pDlg);
218  pButtonOK->setDefault(true);
219  QObject::connect(pButtonOK, &QPushButton::clicked, pDlg, &QDialog::accept);
220  pBtnLayout->addWidget(pButtonOK);
221 
222  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), pDlg);
223  pButtonCancel->setShortcut(Qt::Key_Escape);
224  QObject::connect(pButtonCancel, &QPushButton::clicked, pDlg, &QDialog::reject);
225  pBtnLayout->addWidget(pButtonCancel);
226 
227  // Affiche la boite de dialogue
228  int ret = pDlg->exec();
229 
230  TYApplication::setOverrideCursor(Qt::WaitCursor);
231 
232  // Applique les modificatins si necessaire
233  if (ret == QDialog::Accepted)
234  {
236 
237  // Position
238  TYPoint org = OVector3D(OVector3D(pt0) + (OVector3D(pt2) - OVector3D(pt0)) * 0.5);
239  org._z = _pModeler->getDefaultZCoord();
240 
241  // Si la grille magnetique est activee
243  {
244  snapToGrid(org._x, org._y, org._z, _gridMagnStep);
245  }
246 
247  TYRepere rep;
248  rep._origin = org;
249 
250  // Nouveau rectangle
251  LPTYRectangle pRectangle = new TYRectangle();
252  pRectangle->setSize(sizeX, sizeY);
253 
254  // Nouveau maillage
256  LPTYRectangularMaillageGeoNode pMaillageGeoNode =
257  new TYRectangularMaillageGeoNode(rep, (LPTYElement)pMaillage);
258 
259  TYProjet* pProjet = pSiteModeler->getProjet();
260  if (pProjet != nullptr)
261  {
262  pMaillage->setHauteur(pHauteurLineEdit->text().toDouble());
263  pMaillage->make(pRectangle, 1.0f / (pDistanceXLineEdit->text().toDouble()),
264  1.0f / (pDistanceYLineEdit->text().toDouble()));
265 
266  TYAction* pAction =
267  new TYAddMaillageToProjetAction((LPTYMaillageGeoNode&)pMaillageGeoNode, pProjet,
268  _pModeler, TR("id_action_addrectmaillage"));
269 
270  // Ajout de l'action creation de maillage pour mettre le undo
271  _pModeler->getActionManager()->addAction(pAction);
272 
273  // Ajoute le maillage dans le calcul courant
274  pProjet->addMaillage((LPTYMaillageGeoNode&)pMaillageGeoNode);
275  if (pProjet->getSite()->getAltimetry()->containsData())
276  {
277  // Mise a jour de l'altimetrie du maillage
278  pProjet->updateAltiMaillage(pMaillageGeoNode);
279  }
280  // Genere les objets graphiques representant le maillage
281  pMaillage->updateGraphicTree();
282  }
283  }
284 
285  delete pBtnLayout;
286  delete pEditLayout;
287  }
288 
290  }
291 
292  showText(false);
293 
298  dynamic_cast<TYSiteModelerFrame*>(_pModeler)->updateSelectMaillageBox();
299 
300  TYApplication::restoreOverrideCursor();
301  }
302 }
303 
304 void TYRectangularMaillageEditor::slotMouseMoved(int x, int y, Qt::MouseButtons button,
305  Qt::KeyboardModifiers state)
306 {
307  if (_active && _moving)
308  {
310  _pOGLRectangleElement->setPoint2(QVector3D(x, _pInteractor->getViewport().height() - y, 0.0));
312  QVector3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->getViewport().height() - y, 0.0));
313 
314  float pt0[3], pt1[3], pt2[3];
318  pt0[0] = point0.x();
319  pt0[1] = point0.z();
320  pt1[0] = point1.x();
321  pt1[1] = point1.z();
322  pt2[0] = point2.x();
323  pt2[1] = point2.z();
324 
325  double sizeX = ABS(pt1[0] - pt0[0]);
326  double sizeY = ABS(pt2[1] - pt1[1]);
327  double sizeZ = (sizeX + sizeY) / 2.0;
328 
329  // Si la grille magnetique est activee
331  {
332  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
333  }
334 
335  updateText(
336  QString(TR("id_size_info")).arg(sizeX, 0, 'f', 2).arg(sizeY, 0, 'f', 2),
337  (int)(_pOGLRectangleElement->getPoint0()[0] +
339  (int)(_pOGLRectangleElement->getPoint1()[1] +
341 
343  _pInteractor->update();
344  }
345 }
double ABS(double a)
Return the absolute value.
Definition: 3d.h:67
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)
Classe generique pour une fenetre de modeleur (fichier header)
Representation graphique d'un point (fichier header)
#define TR(id)
gestion de l'edition d'un maillage rectangulaire (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)
Definition: color.h:36
float b
Definition: color.h:38
float r
Definition: color.h:38
float g
Definition: color.h:38
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
void setPoint2(const QVector3D &point2)
void setColor(const OColor &oColor)
void setPoint3(const QVector3D &point3)
void setPoint0(const QVector3D &point0)
void setPoint1(const QVector3D &point1)
const QVector3D & getPoint1()
const QVector3D & getPoint0()
const QVector3D & getPoint2()
OPoint3D _origin
The origin point.
Definition: 3d.h:1331
The 3D vector class.
Definition: 3d.h:298
double norme() const
Computes the length of this vector.
Definition: 3d.cpp:215
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:905
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:816
bool updateAltiMaillage(TYMaillageGeoNode *pMaillageGeoNode, const TYAltimetrie *pAlti)
Met a niveau l'altimetrie d'un maillage.
Definition: TYProjet.cpp:939
LPTYSiteNode getSite()
Get du site.
Definition: TYProjet.h:169
void setSize(float sizeX, float sizeY)
virtual void slotMousePressed(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
bool _active
Indique si cet editor est actif.
virtual void slotMouseMoved(int x, int y, Qt::MouseButtons button, Qt::KeyboardModifiers state)
TYRectangularMaillageEditor(TYSiteModelerFrame *pModeler)
virtual void slotMouseReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers state)
OGLRectangleElement * _pOGLRectangleElement
Pour le dessin de construction.
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