Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYVerticalMaillageEditor.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("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 
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(OPoint3D(x, _pInteractor->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  // On recupere la position du curseur
140  QPoint pos = _pInteractor->mapFromGlobal(QCursor::pos());
141 
142  // 2eme point
143  _pOGLLineElement->setPoint2(OPoint3D(pos.x(), _pInteractor->height() - y, 0.0));
144 
147  _pOGLLineElement->getPoint1()[2]));
150  _pOGLLineElement->getPoint2()[2]));
151 
152  // Calcul de la distance
153  double dist = point1.distance(point2);
154 
155  // Msg Dist
156  QString msg = QString(TR("id_size_info")).arg(dist, 0, 'f', 2);
157 
158  updateText(msg,
159  (int)(_pOGLLineElement->getPoint1()[0] +
160  (_pOGLLineElement->getPoint2()[0] - _pOGLLineElement->getPoint1()[0]) / 2.0),
161  (int)(_pOGLLineElement->getPoint2()[1] +
162  (_pOGLLineElement->getPoint1()[1] - _pOGLLineElement->getPoint2()[1]) / 2.0));
163 
165  }
166 }
167 
168 void TYVerticalMaillageEditor::slotMouseReleased(int x, int y, Qt::MouseButton button,
169  Qt::KeyboardModifiers state)
170 {
171  if ((button == Qt::LeftButton) && _active && !_noCalcul)
172  {
173  // Calcul de la ligne
174  LPTYSegment pSeg = new TYSegment();
175 
176  float pt1[3], pt2[3];
179  _pOGLLineElement->getPoint1()[2]));
182  _pOGLLineElement->getPoint2()[2]));
183  pt1[0] = point1.x;
184  pt1[1] = point1.y;
185  pt1[2] = point1.z;
186  pt2[0] = point2.x;
187  pt2[1] = point2.y;
188  pt2[2] = point2.z;
189  pSeg->_ptA.setFromOGL(pt1);
190  pSeg->_ptA._z = 0;
191  pSeg->_ptB.setFromOGL(pt2);
192  pSeg->_ptB._z = 0;
193 
194  // Si la grille magnetique est activee
196  {
197  snapToGrid(pSeg->_ptA._x, pSeg->_ptA._y, pSeg->_ptA._z, _gridMagnStep);
198  snapToGrid(pSeg->_ptB._x, pSeg->_ptB._y, pSeg->_ptB._z, _gridMagnStep);
199  }
200 
201  // Si la taille est valide
202  if (pSeg->longueur() > 0.0)
203  {
205  {
206  QDialog* pDlg = new QDialog(_pModeler);
207  pDlg->setWindowTitle(TR("id_caption"));
208 
209  QGridLayout* pLayout = new QGridLayout();
210  pDlg->setLayout(pLayout);
211 
212  QGridLayout* pEditLayout = new QGridLayout();
213  pEditLayout->setContentsMargins(10, 10, 10, 10);
214  pLayout->addLayout(pEditLayout, 0, 0);
215 
216  // Hauteur au sol
217  QLabel* pHauteurSolLabelName = new QLabel(TR("id_hauteursol_label"));
218  TYLineEdit* pHauteurSolLineEdit = new TYLineEdit();
219  pHauteurSolLineEdit->setFixedWidth(60);
220  pHauteurSolLineEdit->setText(QString().setNum(2.0, 'f', 2));
221  pEditLayout->addWidget(pHauteurSolLabelName, 0, 0);
222  pEditLayout->addWidget(pHauteurSolLineEdit, 0, 1);
223 
224  // Hauteur maillage
225  QLabel* pHauteurLabelName = new QLabel(TR("id_hauteur_label"));
226  TYLineEdit* pHauteurLineEdit = new TYLineEdit();
227  pHauteurLineEdit->setFixedWidth(60);
228  pHauteurLineEdit->setText(QString().setNum(2.0, 'f', 2));
229  pEditLayout->addWidget(pHauteurLabelName, 1, 0);
230  pEditLayout->addWidget(pHauteurLineEdit, 1, 1);
231 
232  // Densite X
233  QLabel* pDensiteXLabelName = new QLabel(TR("id_densitex_label"));
234  TYLineEdit* pDensiteXLineEdit = new TYLineEdit();
235  pDensiteXLineEdit->setFixedWidth(60);
236  pDensiteXLineEdit->setText(QString().setNum(TY_MAILLAGE_DEFAULT_DENSITE, 'f', 4));
237  pEditLayout->addWidget(pDensiteXLabelName, 2, 0);
238  pEditLayout->addWidget(pDensiteXLineEdit, 2, 1);
239 
240  // Densite Y
241  QLabel* pDensiteYLabelName = new QLabel(TR("id_densitey_label"));
242  TYLineEdit* pDensiteYLineEdit = new TYLineEdit();
243  pDensiteYLineEdit->setFixedWidth(60);
244  pDensiteYLineEdit->setText(QString().setNum(TY_MAILLAGE_DEFAULT_DENSITE, 'f', 4));
245  pEditLayout->addWidget(pDensiteYLabelName, 3, 0);
246  pEditLayout->addWidget(pDensiteYLineEdit, 3, 1);
247 
248  QBoxLayout* pBtnLayout = new QHBoxLayout();
249  pLayout->addLayout(pBtnLayout, 1, 0);
250 
251  pBtnLayout->addStretch(1);
252 
253  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), pDlg);
254  pButtonOK->setDefault(true);
255  QObject::connect(pButtonOK, &QPushButton::clicked, pDlg, &QDialog::accept);
256  pBtnLayout->addWidget(pButtonOK);
257 
258  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), pDlg);
259  pButtonCancel->setShortcut(Qt::Key_Escape);
260  QObject::connect(pButtonCancel, &QPushButton::clicked, pDlg, &QDialog::reject);
261  pBtnLayout->addWidget(pButtonCancel);
262 
263  // Affiche la boite de dialogue
264  int ret = pDlg->exec();
265 
266  TYApplication::setOverrideCursor(Qt::WaitCursor);
267 
268  // Applique les modificatins si necessaire
269  if (ret == QDialog::Accepted)
270  {
272 
273  // Position
274  TYPoint org = pSeg->centreOf();
275  org._z = 0.0;
276 
277  // Si la grille magnetique est activee
279  {
280  snapToGrid(org._x, org._y, org._z, _gridMagnStep);
281  }
282 
283  TYRepere rep;
284  rep._origin = org;
285  rep._vecI = pSeg->toVector3D();
286  rep._vecI.normalize();
287  rep._vecJ.setCoords(0.0, 0.0, 1.0);
288  rep._vecK = rep._vecI.cross(rep._vecJ);
289 
290  // Construction du rectangle
291  LPTYRectangle pRectangle = new TYRectangle();
292  pRectangle->setSize(pSeg->longueur(), pHauteurLineEdit->text().toDouble());
293 
294  // Nouveau maillage
296  LPTYRectangularMaillageGeoNode pMaillageGeoNode =
297  new TYRectangularMaillageGeoNode(rep, (LPTYElement)pMaillage);
298 
299  TYProjet* pProjet = pSiteModeler->getProjet();
300  if (pProjet)
301  {
302  // Init
303  pMaillage->setHauteur(pHauteurSolLineEdit->text().toDouble());
304  pMaillage->make(pRectangle, pDensiteXLineEdit->text().toDouble(),
305  pDensiteYLineEdit->text().toDouble());
306 
307  // On ne calcule pas l'alti des points pour ce type de maillage
308  pMaillage->setComputeAlti(false);
309 
310  TYAction* pAction =
311  new TYAddMaillageToProjetAction((LPTYMaillageGeoNode&)pMaillageGeoNode, pProjet,
312  _pModeler, TR("id_action_addrectmaillage"));
313  _pModeler->getActionManager()->addAction(pAction);
314 
315  pProjet->addMaillage((LPTYMaillageGeoNode&)pMaillageGeoNode);
316  if (pProjet->getSite()->getAltimetry()->containsData())
317  {
318  // Altimetrisation du maillage
319  pProjet->updateAltiMaillage(pMaillageGeoNode);
320  }
321 
322  pMaillage->updateGraphicTree();
323  }
324  }
325 
326  delete pEditLayout;
327  delete pBtnLayout;
328  }
329 
331  }
332 
333  showText(false);
334 
339 
340  TYApplication::restoreOverrideCursor();
341  }
342 }
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: NxVec3.h:23
NxReal z
Definition: NxVec3.h:80
NxReal y
Definition: NxVec3.h:80
NxReal distance(const NxVec3 &) const
Definition: NxVec3.cpp:199
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
void setCoords(double x, double y, double z)
Sets the coordinates as an array of double.
Definition: 3d.cpp:76
static NxVec3 displayToWorld(NxVec3 display)
Definition: OGLCamera.cpp:699
void setVisibility(bool bVisible)
Definition: OGLElement.h:51
double * getPoint2()
void setPoint1(const OPoint3D &point1)
void setColor(const OColor &oColor)
double * getPoint1()
void setPoint2(const OPoint3D &point2)
The 3D point class.
Definition: 3d.h:487
virtual void setFromOGL(double x, double y, double z)
Definition: 3d.cpp:340
OVector3D _vecK
Vector K for the Z axis.
Definition: 3d.h:1285
OVector3D _vecJ
Vector J for the Y axis.
Definition: 3d.h:1283
OVector3D _vecI
Vector I for the X axis.
Definition: 3d.h:1281
OPoint3D _origin
The origin point.
Definition: 3d.h:1279
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:1201
virtual OVector3D toVector3D() const
Build a OVector3D from a segment used for the direction of the sources.
Definition: 3d.h:1188
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1203
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: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)
Classe de definition d'un maillage rectangulaire.
virtual void updateGL()
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)