Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSiteNodeWidget.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 
26 
27 #include <qmenu.h>
28 #include <qcombobox.h>
29 // Added by qt3to4:
30 #include <QGridLayout>
31 #include <QLabel>
32 #include <QTreeWidget>
33 #include <QTreeWidgetItem>
34 #include <QHeaderView>
35 #include <qfiledialog.h>
36 #include <QtWidgets>
37 
38 #include "TYSiteNodeWidget.h"
39 #include "TYElementWidget.h"
40 
41 #define TR(id) OLocalizator::getString("TYSiteNodeWidget", (id))
42 
43 TYSiteNodeWidget::TYSiteNodeWidget(TYSiteNode* pElement, QWidget* _pParent /*=NULL*/)
44  : TYWidget(pElement, _pParent)
45 {
46  unsigned short wPos = 0; // Position du widget
47 
48  resize(300, 600);
49  setWindowTitle(TR("id_caption"));
50 
51  _sitenodeLayout = new QGridLayout();
52  setLayout(_sitenodeLayout);
53 
54  _elmW = new TYElementWidget(pElement, this);
55 
56  _sitenodeLayout->addWidget(_elmW, wPos, 0);
57 
58  // Code de TYSiteWidget
59  _groupBox_0 = new QGroupBox(this);
60  _groupBox_0->setTitle(TR(""));
61  _groupBox_0Layout = new QGridLayout();
62  _groupBox_0->setLayout(_groupBox_0Layout);
63 
64  _labelEchelle = new QLabel(_groupBox_0);
65  _labelEchelle->setText(TR("id_echelle_label"));
66  _groupBox_0Layout->addWidget(_labelEchelle, 0, 0);
67 
69  _groupBox_0Layout->addWidget(_lineEditEchelle, 0, 1);
70  QLabel* pUnitEchelle = new QLabel(_groupBox_0);
71  pUnitEchelle->setText(TR("id_unite_echelle"));
72  _groupBox_0Layout->addWidget(pUnitEchelle, 0, 2);
73 
74  _checkBoxUseTopoFile = new QCheckBox(_groupBox_0);
75  _checkBoxUseTopoFile->setText(TR("id_use_topo_file"));
76  _groupBox_0Layout->addWidget(_checkBoxUseTopoFile, 1, 0);
77 
78  _lineEditTopoFile = new QLineEdit(_groupBox_0);
79  _lineEditTopoFile->setEnabled(true);
80  _groupBox_0Layout->addWidget(_lineEditTopoFile, 1, 1);
81 
82  _pushButtonTopoFile = new QPushButton(TR("id_select_topo_file"), _groupBox_0);
83  _groupBox_0Layout->addWidget(_pushButtonTopoFile, 1, 2);
84 
85  _sitenodeLayout->addWidget(_groupBox_0, ++wPos, 0);
86 
87  _groupBoxInfra = new QGroupBox(this);
88  _groupBoxInfra->setTitle(TR("id_infra"));
89  _groupBoxInfraLayout = new QGridLayout();
91 
92  _pushButtonInfra = new QPushButton(_groupBoxInfra);
93  _pushButtonInfra->setText(TR("id_proprietes_button"));
94  _groupBoxInfraLayout->addWidget(_pushButtonInfra, 0, 1);
95 
96  _lineEditNomInfra = new QLineEdit(_groupBoxInfra);
97  _lineEditNomInfra->setText(getElement()->getInfrastructure()->getName());
98  _lineEditNomInfra->setEnabled(false);
99  _groupBoxInfraLayout->addWidget(_lineEditNomInfra, 0, 0);
100 
101  _sitenodeLayout->addWidget(_groupBoxInfra, ++wPos, 0);
102 
103  _groupBoxTopo = new QGroupBox(this);
104  _groupBoxTopo->setTitle(TR("id_topo"));
105  _groupBoxTopoLayout = new QGridLayout();
107 
108  _lineEditNomTopo = new QLineEdit(_groupBoxTopo);
109  _lineEditNomTopo->setText(getElement()->getTopographie()->getName());
110  _lineEditNomTopo->setEnabled(false);
111  _groupBoxTopoLayout->addWidget(_lineEditNomTopo, 0, 0);
112 
113  _pushButtonTopo = new QPushButton(_groupBoxTopo);
114  _pushButtonTopo->setText(TR("id_proprietes_button"));
115  _groupBoxTopoLayout->addWidget(_pushButtonTopo, 0, 1);
116 
117  _sitenodeLayout->addWidget(_groupBoxTopo, ++wPos, 0);
118 
119  // Code de TYSiteNodeWidget
120 
121  // =============================================================================================
122 
123  // Choix du systeme de SIG
124  QGroupBox* pGroupBoxData = new QGroupBox(this);
125  pGroupBoxData->setTitle(TR("id_SIG"));
126  QGridLayout* pGroupBoxDataLayout = new QGridLayout();
127  pGroupBoxData->setLayout(pGroupBoxDataLayout);
128 
129  pGroupBoxDataLayout->setColumnStretch(0, 1);
130  pGroupBoxDataLayout->setColumnStretch(1, 0);
131 
132  // Choix du systeme de coordonnees
133  _labelModeCoord = new QLabel(pGroupBoxData);
134  _labelModeCoord->setText(TR("id_system_coord"));
135  pGroupBoxDataLayout->addWidget(_labelModeCoord, 0, 0);
136  _comboSIG = new QComboBox(pGroupBoxData);
137  pGroupBoxDataLayout->addWidget(_comboSIG, 0, 1);
138  updateSIGList();
139 
140  // Saisie des coordonnees
141  _labelSIG_X = new QLabel(pGroupBoxData);
142  _labelSIG_X->setText(TR("id_SIG_X"));
143  pGroupBoxDataLayout->addWidget(_labelSIG_X, 0, 2);
144  _lineEditSIG_X = new QLineEdit(pGroupBoxData);
145  pGroupBoxDataLayout->addWidget(_lineEditSIG_X, 0, 3);
146 
147  _labelSIG_Y = new QLabel(pGroupBoxData);
148  _labelSIG_Y->setText(TR("id_SIG_Y"));
149  pGroupBoxDataLayout->addWidget(_labelSIG_Y, 0, 4);
150  _lineEditSIG_Y = new QLineEdit(pGroupBoxData);
151  pGroupBoxDataLayout->addWidget(_lineEditSIG_Y, 0, 5);
152 
153  _labelSIG_OFFSET = new QLabel(pGroupBoxData);
154  _labelSIG_OFFSET->setText(TR("id_SIG_OFFSET"));
155  pGroupBoxDataLayout->addWidget(_labelSIG_OFFSET, 0, 6);
156  _lineEditSIG_OFFSET = new QLineEdit(pGroupBoxData);
157  pGroupBoxDataLayout->addWidget(_lineEditSIG_OFFSET, 0, 7);
158 
159  // Disambiguate the overloaded signal QComboBox:activated
160  void (QComboBox::*_qComboBox_activated)(int) = &QComboBox::activated;
161 
162  connect(_comboSIG, _qComboBox_activated, this, &TYSiteNodeWidget::setSIGCoord);
163 
164  _sitenodeLayout->addWidget(pGroupBoxData, ++wPos, 0);
165 
166  // ==============================================================================================
167 
168  _groupBox_3 = new QGroupBox(this);
169  _groupBox_3->setTitle(TR(""));
170  _groupBox_3Layout = new QGridLayout();
171  _groupBox_3->setLayout(_groupBox_3Layout);
172 
173  _labelRoot = new QLabel(_groupBox_3);
174  _labelRoot->setText(TR("id_root_label"));
175  _groupBox_3Layout->addWidget(_labelRoot, 0, 0);
176 
177  _checkBoxRoot = new QCheckBox(_groupBox_3);
178  _checkBoxRoot->setText(TR(""));
179  _checkBoxRoot->setEnabled(false);
180  _groupBox_3Layout->addWidget(_checkBoxRoot, 0, 1);
181 
182  _labelUseEmprise = new QLabel(_groupBox_3);
183  _labelUseEmprise->setText(TR("id_emprise_label"));
184  _groupBox_3Layout->addWidget(_labelUseEmprise, 1, 0);
185 
186  _checkBoxUseEmprise = new QCheckBox(_groupBox_3);
187  _checkBoxUseEmprise->setText(TR(""));
188  _checkBoxUseEmprise->setEnabled(true);
189  _groupBox_3Layout->addWidget(_checkBoxUseEmprise, 1, 1);
190 
191  _labelAltiEmprise = new QLabel(_groupBox_3);
192  _labelAltiEmprise->setText(TR("id_alti_emprise"));
193  _groupBox_3Layout->addWidget(_labelAltiEmprise, 1, 2);
194 
195  _lineEditAltiEmprise = new QLineEdit(_groupBox_3);
196  _lineEditAltiEmprise->setText(TR(""));
197  _lineEditAltiEmprise->setEnabled(false);
198  _groupBox_3Layout->addWidget(_lineEditAltiEmprise, 1, 3);
199 
200  _sitenodeLayout->addWidget(_groupBox_3, ++wPos, 0);
201 
202  _groupBox = new QGroupBox(this);
203  _groupBox->setTitle(TR("id_tabsiterepere_box"));
204  _groupBoxLayout = new QGridLayout();
205  _groupBox->setLayout(_groupBoxLayout);
206 
207  _listViewListSite = new QTreeWidget(_groupBox);
208  _listViewListSite->setColumnCount(2);
209  QStringList stringList;
210  stringList.append(TR(""));
211  stringList.append(TR("id_site"));
212  _listViewListSite->setHeaderLabels(stringList);
213  _listViewListSite->setRootIsDecorated(true);
214 
215  _groupBoxLayout->addWidget(_listViewListSite, 0, 0);
216 
217  _sitenodeLayout->addWidget(_groupBox, ++wPos, 0);
218 
219  connect(_pushButtonInfra, &QPushButton::clicked, this, &TYSiteNodeWidget::editInfra);
220  connect(_pushButtonTopoFile, &QPushButton::clicked, this, &TYSiteNodeWidget::chooseTopoFile);
221  connect(_pushButtonTopo, &QPushButton::clicked, this, &TYSiteNodeWidget::editTopo);
222  connect(_checkBoxUseTopoFile, &QPushButton::clicked, this, &TYSiteNodeWidget::changeStateTopoFile);
223  connect(_checkBoxUseEmprise, &QPushButton::clicked, this, &TYSiteNodeWidget::updateEditAlti);
224 
225  updateContent();
226 }
227 
229 
231 {
232  // Code de TYSiteWidget
233  QString num;
234 
235  _elmW->updateContent();
236 
237  _checkBoxUseTopoFile->setChecked(getElement()->getUseTopoFile());
238  _lineEditTopoFile->setText(getElement()->getTopoFileName());
239  if (!_checkBoxUseTopoFile->isChecked())
240  {
241  _pushButtonTopoFile->setEnabled(false);
242  }
243 
244  _lineEditEchelle->setText(num.setNum(getElement()->getEchelle(), 'f', 2));
245  _lineEditNomTopo->setText(getElement()->getTopographie()->getName());
246  _lineEditNomInfra->setText(getElement()->getInfrastructure()->getName());
247 
248  // Code de TYSiteNodeWidget
249  _checkBoxRoot->setChecked(getElement()->getRoot());
250  _checkBoxUseEmprise->setChecked(getElement()->getUseEmpriseAsCrbNiv());
251 
252  _lineEditAltiEmprise->setText(QString().setNum(getElement()->getAltiEmprise()));
253  if (_checkBoxUseEmprise->isChecked())
254  {
255  _lineEditAltiEmprise->setEnabled(true);
256  }
257 
258  _listViewListSite->clear();
259  for (unsigned int i = 0; i < getElement()->getListSiteNode().size(); i++)
260  {
261  QTreeWidgetItem* item = new QTreeWidgetItem(_listViewListSite);
262  item->setText(0, QString().setNum(i));
263  item->setText(1, getElement()->getListSiteNode()[i]->getElement()->getName());
264  }
265 
266  updateSIGData();
267 }
268 
270 {
271  // Code de TYSiteWidget
272  _elmW->apply();
273 
274  getElement()->setEchelle(_lineEditEchelle->text().toDouble());
275  getElement()->updateGraphic();
276  getElement()->setUseTopoFile(_checkBoxUseTopoFile->isChecked());
277 
278  if ((_checkBoxUseTopoFile->isChecked()) && (!_lineEditTopoFile->text().isEmpty()))
279  {
280  getElement()->setTopoFileName(_lineEditTopoFile->text());
281  getElement()->loadTopoFile(_lineEditTopoFile->text());
282  }
283 
284  // Code de TYSiteNodeWidget
285  getElement()->setRoot(_checkBoxRoot->isChecked());
286  getElement()->setUseEmpriseAsCrbNiv(_checkBoxUseEmprise->isChecked());
287  if (_checkBoxUseEmprise->isChecked())
288  {
289  getElement()->setAltiEmprise(_lineEditAltiEmprise->text().toDouble());
290  }
291  else
292  {
293  getElement()->setAltiEmprise(0.0);
294  }
295 
296  getElement()->setSIGType(_comboSIG->currentIndex());
297  getElement()->setSIG_X(_lineEditSIG_X->text().toFloat());
298  getElement()->setSIG_Y(_lineEditSIG_Y->text().toFloat());
299  getElement()->setSIG_OFFSET(_lineEditSIG_OFFSET->text().toFloat());
300 
301  getElement()->setIsGeometryModified(true);
302 
303  emit modified();
304 }
305 
306 void TYSiteNodeWidget::editSite(QTreeWidgetItem* item)
307 {
308  int ret = getElement()->getListSiteNode()[item->text(0).toInt()]->getElement()->edit(this);
309 
310  if (ret == QDialog::Accepted)
311  {
312  _listViewListSite->clear();
313  for (unsigned int i = 0; i < getElement()->getListSiteNode().size(); i++)
314  {
315  QTreeWidgetItem* item = new QTreeWidgetItem(_listViewListSite);
316  item->setText(0, QString().setNum(i));
317  item->setText(1, getElement()->getListSiteNode()[i]->getElement()->getName());
318  }
319  }
320 }
321 
322 void TYSiteNodeWidget::contextMenuEvent(QContextMenuEvent* e)
323 {
324  // si on trouve un item associe
325  QPoint point = _listViewListSite->mapFrom(this, e->pos());
326  QTreeWidgetItem* item =
327  _listViewListSite->itemAt(point.x(), point.y() - _listViewListSite->header()->height());
328 
329  if (item != NULL)
330  {
331  QMenu* pMenu = new QMenu(this);
332 
333  QAction* prop = pMenu->addAction(TR("id_property"));
334  QAction* ret = pMenu->exec(_listViewListSite->mapToGlobal(point));
335 
336  if ((ret) && (ret == prop))
337  {
338  editSite(item);
339  }
340  }
341 }
342 
344 {
345  if (_checkBoxUseEmprise->isChecked())
346  {
347  _lineEditAltiEmprise->setEnabled(true);
348  }
349  else
350  {
351  _lineEditAltiEmprise->setEnabled(false);
352  }
353 
355 }
356 
358 {
359  QString str = "TYMPAN";
360  _comboSIG->insertItem(0, str);
361 
362  str = "LAMBERT IIe";
363  _comboSIG->insertItem(1, str);
364 
365  str = "GPS (UTM)";
366  _comboSIG->insertItem(2, str);
367 }
368 
370 {
371  // SIG - Actif si le site est root
372  if (getElement()->getRoot() && (getElement()->getSIGType() != 0))
373  {
374  _comboSIG->setEnabled(true);
375  _lineEditSIG_X->setEnabled(true);
376  _lineEditSIG_Y->setEnabled(true);
377  _lineEditSIG_OFFSET->setEnabled(true);
378  _comboSIG->setCurrentIndex(getElement()->getSIGType());
379  _lineEditSIG_X->setText(QString().setNum(getElement()->getSIG_X()));
380  _lineEditSIG_Y->setText(QString().setNum(getElement()->getSIG_Y()));
381  _lineEditSIG_OFFSET->setText(QString().setNum(getElement()->getSIG_OFFSET()));
382  }
383  else if (!getElement()->getRoot())
384  {
385  _comboSIG->setEnabled(false);
386  _lineEditSIG_X->setText(QString().setNum(0.000));
387  _lineEditSIG_X->setEnabled(false);
388  _lineEditSIG_Y->setText(QString().setNum(0.000));
389  _lineEditSIG_Y->setEnabled(false);
390  _lineEditSIG_OFFSET->setText(QString().setNum(0.000));
391  _lineEditSIG_OFFSET->setEnabled(false);
392  }
393  else
394  {
395  _comboSIG->setEnabled(true);
396  _lineEditSIG_X->setText(QString().setNum(0.000));
397  _lineEditSIG_X->setEnabled(false);
398  _lineEditSIG_Y->setText(QString().setNum(0.000));
399  _lineEditSIG_Y->setEnabled(false);
400  _lineEditSIG_OFFSET->setText(QString().setNum(0.000));
401  _lineEditSIG_OFFSET->setEnabled(false);
402  }
403 }
404 
405 void TYSiteNodeWidget::setSIGCoord(int typeCoord)
406 {
407  getElement()->setSIGType(typeCoord);
408 
409  updateSIGData();
410 }
411 
413 {
414  if (!_checkBoxUseTopoFile->isChecked())
415  {
416  _pushButtonTopoFile->setEnabled(false);
417  getElement()->setUseTopoFile(false);
418  }
419  else
420  {
421  _pushButtonTopoFile->setEnabled(true);
422  getElement()->setUseTopoFile(true);
423  }
424 }
425 
427 {
428  QString file = QFileDialog::getOpenFileName(this, "Choose a file", "Fichier image",
429  "Images (*.bmp *.jpg *.png *.tif)");
430 
431  if (!file.isNull())
432  {
433  _lineEditTopoFile->setText(file);
434  }
435 }
436 
438 {
439  int ret = getElement()->getInfrastructure()->edit(this);
440 
441  if (ret == QDialog::Accepted)
442  {
443  _lineEditNomInfra->setText(getElement()->getInfrastructure()->getName());
444  }
445 }
446 
448 {
449  int ret = getElement()->getTopographie()->edit(this);
450 
451  if (ret == QDialog::Accepted)
452  {
453  _lineEditNomTopo->setText(getElement()->getTopographie()->getName());
454  }
455 }
outil IHM pour un element (fichier header)
outil IHM pour une entrée utilisateur (fichier header)
#define TR(id)
outil IHM pour un ensemble de sites (fichier header)
classe de l'objet IHM pour un element
virtual void apply()
virtual void updateContent()
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
QComboBox * _comboSIG
QGroupBox * _groupBox
virtual void updateContent()
void updateEditAlti()
Active/desactive la boite de saisie de l'altitude de la courbe de niveau.
void updateSIGList()
Mise a jour de la liste des systemes de coordonnees SIG.
QGridLayout * _groupBox_3Layout
virtual void contextMenuEvent(QContextMenuEvent *e)
QCheckBox * _checkBoxUseTopoFile
QLineEdit * _lineEditAltiEmprise
QGroupBox * _groupBox_0
TYElementWidget * _elmW
QGridLayout * _groupBoxInfraLayout
QLineEdit * _lineEditSIG_X
QPushButton * _pushButtonTopoFile
QLineEdit * _lineEditSIG_Y
void setSIGCoord(int typeCoord)
Changement du systeme de coordonnees.
QLineEdit * _lineEditNomInfra
QCheckBox * _checkBoxUseEmprise
QPushButton * _pushButtonTopo
virtual void apply()
QGroupBox * _groupBoxTopo
QGridLayout * _groupBoxLayout
QTreeWidget * _listViewListSite
QGridLayout * _groupBox_0Layout
void editSite(QTreeWidgetItem *item)
QLineEdit * _lineEditTopoFile
QLineEdit * _lineEditNomTopo
QGroupBox * _groupBox_3
QGridLayout * _groupBoxTopoLayout
QCheckBox * _checkBoxRoot
QGroupBox * _groupBoxInfra
TYSiteNodeWidget(TYSiteNode *pElement, QWidget *_pParent=NULL)
void updateSIGData()
Mise a jour des widgets lies au SIG.
QGridLayout * _sitenodeLayout
QLabel * _labelAltiEmprise
QPushButton * _pushButtonInfra
TYLineEdit * _lineEditEchelle
QLineEdit * _lineEditSIG_OFFSET
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43
TYElement * _pElement
Definition: TYWidget.h:114
void modified()