Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRectangularMaillageEditor.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 <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(OPoint3D(0.0, 0.0, 0.0));
64  _pOGLRectangleElement->setPoint1(OPoint3D(0.0, 0.0, 0.0));
65  _pOGLRectangleElement->setPoint2(OPoint3D(0.0, 0.0, 0.0));
66  _pOGLRectangleElement->setPoint3(OPoint3D(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 
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(OPoint3D(x, _pInteractor->height() - y, 0.0));
119  _pOGLRectangleElement->setPoint1(OPoint3D(x, _pInteractor->height() - y, 0.0));
120  _pOGLRectangleElement->setPoint2(OPoint3D(x, _pInteractor->height() - y, 0.0));
121  _pOGLRectangleElement->setPoint3(OPoint3D(x, _pInteractor->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;
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* pDensiteXLabelName = new QLabel(TR("id_densitex_label"));
198  TYLineEdit* pDensiteXLineEdit = new TYLineEdit();
199  pDensiteXLineEdit->setFixedWidth(60);
200  pDensiteXLineEdit->setText(QString().setNum(TY_MAILLAGE_DEFAULT_DENSITE, 'f', 4));
201  pEditLayout->addWidget(pDensiteXLabelName, 1, 0);
202  pEditLayout->addWidget(pDensiteXLineEdit, 1, 1);
203 
204  // Densite Y
205  QLabel* pDensiteYLabelName = new QLabel(TR("id_densitey_label"));
206  TYLineEdit* pDensiteYLineEdit = new TYLineEdit();
207  pDensiteYLineEdit->setFixedWidth(60);
208  pDensiteYLineEdit->setText(QString().setNum(TY_MAILLAGE_DEFAULT_DENSITE, 'f', 4));
209  pEditLayout->addWidget(pDensiteYLabelName, 2, 0);
210  pEditLayout->addWidget(pDensiteYLineEdit, 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 = 0.0;
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, pDensiteXLineEdit->text().toDouble(),
264  pDensiteYLineEdit->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(OPoint3D(x, _pInteractor->height() - y, 0.0));
312  OPoint3D(_pOGLRectangleElement->getPoint0()[0], _pInteractor->height() - y, 0.0));
313 
314  float pt0[3], pt1[3], pt2[3];
324  pt0[0] = point0.x;
325  pt0[1] = point0.z;
326  pt1[0] = point1.x;
327  pt1[1] = point1.z;
328  pt2[0] = point2.x;
329  pt2[1] = point2.z;
330 
331  double sizeX = ABS(pt1[0] - pt0[0]);
332  double sizeY = ABS(pt2[1] - pt1[1]);
333  double sizeZ = (sizeX + sizeY) / 2.0;
334 
335  // Si la grille magnetique est activee
337  {
338  snapToGrid(sizeX, sizeY, sizeZ, _gridMagnStep);
339  }
340 
341  updateText(
342  QString(TR("id_size_info")).arg(sizeX, 0, 'f', 2).arg(sizeY, 0, 'f', 2),
343  (int)(_pOGLRectangleElement->getPoint0()[0] +
345  (int)(_pOGLRectangleElement->getPoint1()[1] +
347 
350  }
351 }
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: NxVec3.h:23
NxReal z
Definition: NxVec3.h:80
NxReal y
Definition: NxVec3.h:80
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
void setColor(const OColor &oColor)
void setPoint2(const OPoint3D &point2)
void setPoint3(const OPoint3D &point3)
void setPoint0(const OPoint3D &point0)
void setPoint1(const OPoint3D &point1)
The 3D point class.
Definition: 3d.h:487
OPoint3D _origin
The origin point.
Definition: 3d.h:1279
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:237
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:915
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
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.
virtual void updateGL()
TYOpenGLRenderer * getRenderer()
Classe Modeler specialisee pour l'edition des sites.
LPTYAltimetrie getAltimetry() const