Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYFaceModelerPickEditor.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 <math.h>
22 #include <qdialog.h>
23 #include <qpushbutton.h>
24 #include <qlabel.h>
25 #include <qlayout.h>
26 #include <qmenu.h>
27 #include <qcursor.h>
28 #include <qinputdialog.h>
29 #include <QMessageBox>
30 // Added by qt3to4:
31 #include <QHBoxLayout>
32 #include <QBoxLayout>
33 #include <QGridLayout>
34 #include <QPixmap>
35 
50 
51 #define TR(id) OLocalizator::getString("TYFaceModelerPickEditor", (id))
52 #define IMG(id) OLocalizator::getPicture("TYPickEditor", (id))
53 
55 
57 
58 void TYFaceModelerPickEditor::showPopupMenu(std::shared_ptr<LPTYElementArray> pElts)
59 {
60  if (!pElts)
61  {
62  return;
63  }
64 
65  QMenu* pPopup = new QMenu(NULL);
66  TYAcousticRectangleNode* pParent = NULL;
67  std::map<QAction*, int> retCodes;
68  std::map<QAction*, LPTYGeometryNode> posRetCodes;
69  std::map<QAction*, TYAcousticRectangle*> dupRetCodes;
70  std::map<QAction*, TYAcousticRectangle*> dimAccRectRetCodes;
71  std::map<QAction*, TYAcousticRectangle*> remAccRectRetCodes;
72  QAction* code = NULL;
73  unsigned int i = 0;
74 
75  while ((i < pElts->size()) && (i + 1 < pElts->size()))
76  {
77  if (dynamic_cast<TYAcousticRectangle*>(pElts->at(i)._pObj) != nullptr)
78  {
79  // Proprietes
80  QFont font = pPopup->font();
81  code = pPopup->addAction(QIcon(QPixmap(IMG("id_icon_editeelt"))),
82  TYWidget::getDisplayName(pElts->at(i)));
83  font.setBold(true);
84  code->setFont(font);
85 
86  retCodes[code] = i;
87 
88  // Dimensions
89  if (dynamic_cast<TYAcousticSurfaceNode*>(pElts->at(i + 1)._pObj) != nullptr)
90  {
91  pParent = (LPTYAcousticRectangleNode&)pElts->at(i + 1);
92  code = pPopup->addAction(TR("id_popup_dimension"));
93  dimAccRectRetCodes[code] = (LPTYAcousticRectangle&)pElts->at(i);
94  }
95 
96  // Position via le parent (GeoNode)
97  if (dynamic_cast<TYAcousticSurfaceNode*>(pElts->at(i + 1)._pObj) != nullptr)
98  {
99  pParent = (LPTYAcousticRectangleNode&)pElts->at(i + 1);
100  code = pPopup->addAction(QIcon(IMG("id_icon_moving")), TR("id_popup_position"));
101  posRetCodes[code] =
102  (TYGeometryNode*)pParent->findAcousticSurf((LPTYAcousticSurface&)pElts->at(i));
103  }
104 
105  // Duplication
106  if (dynamic_cast<TYAcousticSurfaceNode*>(pElts->at(i + 1)._pObj) != nullptr)
107  {
108  pParent = (LPTYAcousticRectangleNode&)pElts->at(i + 1);
109  code = pPopup->addAction(QIcon(QPixmap(IMG("id_icon_duplicate"))), TR("id_popup_duplicate"));
110  dupRetCodes[code] = (LPTYAcousticRectangle&)pElts->at(i);
111  }
112 
113  // Suppression
114  code = pPopup->addAction(QIcon(QPixmap(IMG("id_icon_del"))), TR("id_popup_remove"));
115  remAccRectRetCodes[code] = (LPTYAcousticRectangle&)pElts->at(i);
116 
117  pPopup->addSeparator();
118  }
119  else if (dynamic_cast<TYAcousticRectangleNode*>(pElts->at(i)._pObj) != nullptr)
120  {
121  // Face parent
122  code = pPopup->addAction(QIcon(QPixmap(IMG("id_icon_editeelt"))),
123  TYWidget::getDisplayName(pElts->at(i)));
124  retCodes[code] = i;
125 
126  // On a la sous-face et son parent
127  break;
128  }
129 
130  // Increment
131  i++;
132  }
133 
134  QAction* popupRet = pPopup->exec(QCursor::pos());
135 
136  if (retCodes.find(popupRet) != retCodes.end())
137  {
138  pElts->at(retCodes[popupRet])->edit(_pModeler);
139  }
140  else if (dimAccRectRetCodes.find(popupRet) != dimAccRectRetCodes.end())
141  {
142  showDimensionsDialog(dimAccRectRetCodes[popupRet]->getShape(), pParent);
143  }
144  else if (posRetCodes.find(popupRet) != posRetCodes.end())
145  {
146  showPositionDialog(posRetCodes[popupRet].getRealPointer(), false);
147  if (pParent)
148  {
149  pParent->updateGrid();
150  }
151  }
152  else if (remAccRectRetCodes.find(popupRet) != remAccRectRetCodes.end())
153  {
155  {
156  LPTYAcousticSurfaceGeoNode pGeoNode = pParent->findAcousticSurf(remAccRectRetCodes[popupRet]);
157 
158  pParent->remAcousticSurf(remAccRectRetCodes[popupRet]);
159  pParent->setIsGeometryModified(true);
160  pParent->updateGraphicTree();
161 
162  TYAction* pAction =
163  new TYRemAccSurfToAccSurfNodeAction(pGeoNode, pParent, _pModeler, TR("id_action_remface"));
164  _pModeler->getActionManager()->addAction(pAction);
165  }
166  }
167  else if (dupRetCodes.find(popupRet) != dupRetCodes.end())
168  {
169  dupRetCodes[popupRet]->setParent(pParent);
170  copyRectangle(dupRetCodes[popupRet]);
171  }
172 
173  // Deselection
174  resetPicker();
175 
176  // Update
177  getTYMainWnd()->updateModelers(false, false);
178 
179  delete pPopup;
180 }
181 
183 {
184  if (pElement == nullptr)
185  {
186  return;
187  }
188 
189  TYAcousticRectangleNode* pVolParent = dynamic_cast<TYAcousticRectangleNode*>(pElement->getParent());
190  if (pVolParent == nullptr)
191  {
192  return;
193  }
194 
196  if (pGeoNode == nullptr)
197  {
198  return;
199  }
200 
201  // Nouvel element du meme type que l'objet a dupliquer (clone)
203  new TYAcousticRectangleGeoNode(dynamic_cast<TYAcousticRectangle*>(pElement->clone()));
204 
205  // Duplication
206  pCopy->deepCopy(pGeoNode, false);
207 
208  // Ajout
209  if (pVolParent->addSubRect(pCopy))
210  {
211  // Offset
212  ORepere3D repere = pCopy->getORepere3D();
213 
214  repere._origin._x += 10.0;
215  repere._origin._y += 10.0;
216 
217  pCopy->setRepere(repere);
218  // Update Graphic
219  pCopy->updateGraphicTree();
220 
221  // Action
222  TYAction* pAction =
223  new TYAddAccSurfToAccSurfNodeAction(pCopy, pVolParent, _pModeler, TR("id_action_addrect"));
224  _pModeler->getActionManager()->addAction(pAction);
225  }
226 
227  updateSiteFrame();
228 
229  // La scene a ete modifiee
231 }
232 
234  TYAcousticRectangleNode* pParent /*=NULL*/)
235 {
236  if (!pRect)
237  {
238  return;
239  }
240 
241  TYFormDialog* pDlg = new TYFormDialog(_pModeler);
242  pDlg->setWindowTitle(TR("id_popup_dimension"));
243 
244  QGridLayout* pLayout = new QGridLayout();
245  pDlg->setLayout(pLayout);
246 
247  QBoxLayout* pEditLayout = new QHBoxLayout();
248  pEditLayout->setContentsMargins(10, 10, 10, 10);
249  pLayout->addLayout(pEditLayout, 0, 1);
250 
251  TYLineEdit* pXLineEdit = NULL;
252  TYLineEdit* pYLineEdit = NULL;
253 
254  float sizeX = NAN, sizeY = NAN;
255  pRect->getSize(sizeX, sizeY);
256 
257  // Size X
258  QLabel* pXLabelName = new QLabel(pDlg);
259  pXLabelName->setText(TR("id_x_label"));
260  pEditLayout->addWidget(pXLabelName);
261  pXLineEdit = new TYLineEdit(pDlg);
262  pXLineEdit->setFixedWidth(60);
263  pXLineEdit->setText(QString().setNum(sizeX, 'f', 2));
264  pEditLayout->addWidget(pXLineEdit);
265 
266  // Size Y
267  pEditLayout->addSpacing(10);
268  QLabel* pYLabelName = new QLabel(pDlg);
269  pYLabelName->setText(TR("id_y_label"));
270  pEditLayout->addWidget(pYLabelName);
271  pYLineEdit = new TYLineEdit(pDlg);
272  pYLineEdit->setFixedWidth(60);
273  pYLineEdit->setText(QString().setNum(sizeY, 'f', 2));
274  pEditLayout->addWidget(pYLineEdit);
275 
276  QBoxLayout* pBtnLayout = new QHBoxLayout();
277  pLayout->addLayout(pBtnLayout, 1, 1);
278 
279  pBtnLayout->addStretch(1);
280 
281  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), pDlg);
282  pButtonOK->setDefault(true);
283  QObject::connect(pButtonOK, &QPushButton::clicked, pDlg, &QDialog::accept);
284  pBtnLayout->addWidget(pButtonOK);
285 
286  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), pDlg);
287  pButtonCancel->setShortcut(Qt::Key_Escape);
288  QObject::connect(pButtonCancel, &QPushButton::clicked, pDlg, &QDialog::reject);
289  pBtnLayout->addWidget(pButtonCancel);
290 
291  // Affiche la boite de dialogue
292  int ret = pDlg->exec();
293 
294  // Applique les modificatins si necessaire
295  if (ret == QDialog::Accepted)
296  {
298  {
299  float sizeX = pXLineEdit->text().toDouble();
300  float sizeY = pYLineEdit->text().toDouble();
301 
302  if (sizeX <= 1E-4 || sizeY <= 1.E-4) // Eviter les surfaces nulles
303  {
304  QMessageBox::warning(_pModeler, "Tympan", TR("id_warning_size_not_ok"),
305  QMessageBox::Yes); //, QMessageBox::No);
306  return;
307  }
308 
309  TYAction* pAction =
310  new TYResizeRectAction(pRect, sizeX, sizeY, _pModeler, TR("id_action_resizeface"));
311  _pModeler->getActionManager()->addAction(pAction);
312 
313  pRect->setSize(sizeX, sizeY);
314 
315  if (pParent)
316  {
317  pParent->updateGrid();
318  }
319 
320  // Refresh
321  pRect->updateGraphicTree();
322  }
323  }
324 
325  delete pBtnLayout;
326  delete pEditLayout;
327 }
TYGeometryNode TYAcousticRectangleGeoNode
Noeud geometrique de type TYAcousticRectangle.
fichier contenant differents types d'actions (fichier header)
TYMainWindow * getTYMainWnd()
Retourne le pointeur sur la fenetre principale.
pour l'application Tympan (fichier header)
#define IMG(id)
#define TR(id)
gestion du picking des faces (fichier header)
Parent class of Tympan Qt dialogs of type form (geader file)
outil IHM pour une entrée utilisateur (fichier header)
Fenetre principale de l'application Tympan (fichier header)
Classe generique pour une fenetre de modeleur (fichier header)
Objet pour le picking graphique (fichier header)
outil IHM pour un objet metier de type TYElement (fichier header)
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
virtual OPrototype * clone() const =0
3D frame with a point and 3 vectors.
Definition: 3d.h:1263
OPoint3D _origin
The origin point.
Definition: 3d.h:1331
void updateSiteFrame()
Reconstruit l'arborescence du TYSiteFrame.
TYModelerFrame * _pModeler
Le modeler associe a cet editor.
bool addSubRect(LPTYAcousticRectangleGeoNode pAccRectGeoNode)
virtual bool remAcousticSurf(const LPTYAcousticSurfaceGeoNode pAccSurfGeoNode)
LPTYAcousticSurfaceGeoNode findAcousticSurf(const LPTYAcousticSurface pAccSurf)
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
ajout d'une surface acoustique a un ensemble de surfaces acoustiques
Definition: TYActions.h:71
TYElement * getParent() const
Definition: TYElement.h:706
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:914
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
TYFaceModelerPickEditor(TYModelerFrame *pModeler)
void showDimensionsDialog(TYRectangle *pRect, TYAcousticRectangleNode *pParent=NULL)
void copyRectangle(TYElement *pElement)
virtual void showPopupMenu(std::shared_ptr< LPTYElementArray > pElts)
static TYGeometryNode * GetGeoNode(TYElement *pElement)
void updateModelers(bool clipping=true, bool axesAndGrid=true, bool displayList=true)
Generic class for a modeler window.
TYActionManager * getActionManager()
bool askForResetResultat()
gestion de l'element actionne par picking
Definition: TYPickEditor.h:40
void resetPicker()
Definition: TYPickEditor.h:112
void showPositionDialog(TYGeometryNode *pGeoNode, bool activeHeight)
void setSize(float sizeX, float sizeY)
void getSize(float &sizeX, float &sizeY)
suppression d'une surface acoustique a un ensemble de surfaces acoustiques
Definition: TYActions.h:109
Action de redimensionnement d'un rectangle.
Definition: TYActions.h:463
static QString getDisplayName(TYElement *pElt)
Definition: TYWidget.cpp:125