Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYCourbeNiveauWidget.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 
23 #include <qradiobutton.h>
24 #include <QGridLayout>
25 #include <QLabel>
26 #include <QTreeWidget>
27 #include <QTreeWidgetItem>
28 #include <QCheckBox>
29 
35 #include "TabPointsWidget.h"
36 #include "TYCourbeNiveauWidget.h"
37 
38 #define TR(id) OLocalizator::getString("TYCourbeNiveauWidget", (id))
39 
40 TYCourbeNiveauWidget::TYCourbeNiveauWidget(TYCourbeNiveau* pElement, QWidget* _pParent /*=NULL*/)
41  : TYWidget(pElement, _pParent)
42 {
43  _statusDMax = false;
44 
45  _elmW = new TYElementWidget(pElement, this);
46  _colorW = new TYColorInterfaceWidget(pElement, this);
47 
48  resize(300, 260);
49  setWindowTitle(TR("id_caption"));
50  _courbeNiveauLayout = new QGridLayout();
51  setLayout(_courbeNiveauLayout);
52 
53  _courbeNiveauLayout->addWidget(_elmW, 0, 0);
54  _courbeNiveauLayout->addWidget(_colorW, 1, 0);
55 
56  // Tableau des points de la courbe de niveau
57  _groupBox = new QGroupBox(this);
58  _groupBox->setTitle(TR("id_pts"));
59  _groupBoxLayout = new QGridLayout();
60  _groupBox->setLayout(_groupBoxLayout);
61 
63  _tabPoints->setEnabled(true);
64 
65  _groupBoxLayout->addWidget(_tabPoints, 0, 0);
66 
67  // Gestion de la cloture de la courbe de niveau
68  _pClosedCheckBox = new QCheckBox();
69  _groupBoxLayout->addWidget(new QLabel(TR("id_closed_label")), 1, 0);
70  _groupBoxLayout->addWidget(_pClosedCheckBox, 1, 1);
71 
72  _courbeNiveauLayout->addWidget(_groupBox, 2, 0);
73 
74  // Choix de l'altitude de la courbe de niveau
75  _groupBoxAlt = new QGroupBox(this);
76  _groupBoxAlt->setTitle(TR(""));
77  _groupBoxAltLayout = new QGridLayout();
78  _groupBoxAlt->setLayout(_groupBoxAltLayout);
79 
80  _labelAltitude = new QLabel(_groupBoxAlt);
81  _labelAltitude->setText(TR("id_altitude_label"));
82  _groupBoxAltLayout->addWidget(_labelAltitude, 0, 0);
83 
85  _groupBoxAltLayout->addWidget(_lineEditAltitude, 0, 1);
86  QLabel* pUnitAlt = new QLabel(_groupBoxAlt);
87  pUnitAlt->setText(TR("id_unite_altitude"));
88  _groupBoxAltLayout->addWidget(pUnitAlt, 0, 2);
89 
90  _courbeNiveauLayout->addWidget(_groupBoxAlt, 3, 0);
91 
92  // Gestion de la distance max entre deux points de la courbe de niveau
93  _groupBoxDistMax = new QGroupBox(this);
94  _groupBoxDistMax->setTitle(TR(""));
95  _groupBoxDistLayout = new QGridLayout();
97 
98  _labelDistMax = new QLabel(_groupBoxDistMax);
99  _labelDistMax->setText(TR("id_distmax_label"));
100  _groupBoxDistLayout->addWidget(_labelDistMax, 0, 0);
101 
103  _groupBoxDistLayout->addWidget(_lineEditDistMax, 0, 1);
104  QLabel* pUnitDist = new QLabel(_groupBoxDistMax);
105  pUnitDist->setText(TR("id_unite_altitude"));
106  _groupBoxDistLayout->addWidget(pUnitDist, 0, 2);
107 
108  _labelUseDefault = new QLabel(_groupBoxDistMax);
109  _labelUseDefault->setText(TR("id_use_default_label"));
110  QPushButton* _pushButtonUseDefault = new QPushButton(_groupBoxDistMax);
111  _pushButtonUseDefault->setText(TR("id_default_button"));
112 
113  _groupBoxDistLayout->addWidget(_labelUseDefault, 1, 0);
114  _groupBoxDistLayout->addWidget(_pushButtonUseDefault, 1, 1);
115 
116  _courbeNiveauLayout->addWidget(_groupBoxDistMax, 4, 0);
117 
118  connect(_pushButtonUseDefault, &QPushButton::clicked, this, &TYCourbeNiveauWidget::setDefaultValue);
119  connect(_lineEditDistMax, &QLineEdit::textChanged, this, &TYCourbeNiveauWidget::updateUseDefault);
120 
121  updateContent();
122 }
123 
125 
127 {
128  _elmW->updateContent();
130 
131  _statusDMax = getElement()->getIsDMaxDefault();
132 
133  _lineEditAltitude->setText(QString().setNum(getElement()->getAltitude()));
134 
135  // On deconnecte la detection de modification du texte
136  disconnect(_lineEditDistMax, &QLineEdit::textChanged, this, &TYCourbeNiveauWidget::updateUseDefault);
137 
138  _lineEditDistMax->setText(QString().setNum(getElement()->getDistMax()));
140 
141  // On reconnecte apres modification
142  connect(_lineEditDistMax, &QLineEdit::textChanged, this, &TYCourbeNiveauWidget::updateUseDefault);
143 
144  bool closed = dynamic_cast<TYCourbeNiveau*>(_pElement)->isClosed();
145  // If closed, remove the last point (== 1st point)
146  cleanTabPoints(dynamic_cast<TYCourbeNiveau*>(_pElement)->getListPoints(), closed);
147  _pClosedCheckBox->setChecked(closed);
148  _tabPoints->update();
149 }
150 
152 {
153  _elmW->apply();
154  _colorW->apply();
155  _tabPoints->apply();
156 
157  getElement()->setAltitude(_lineEditAltitude->text().toDouble());
158 
159  double valeur = _lineEditDistMax->text().toDouble();
160 
161  if (valeur > 0) // Pas de valeur negative ou nulle
162  {
163  getElement()->setDistMax(valeur);
164  getElement()->setIsDMaxDefault(_statusDMax);
165  }
166 
167  getElement()->setIsGeometryModified(true);
168 
169  if (_pClosedCheckBox->isChecked())
170  {
171  dynamic_cast<TYCourbeNiveau*>(_pElement)->close(true);
172  }
173  else
174  {
175  dynamic_cast<TYCourbeNiveau*>(_pElement)->close(false);
176  }
177 
178  emit modified();
179 }
180 
182 {
183  TYCourbeNiveau* pCourbe = dynamic_cast<TYCourbeNiveau*>(_pElement);
184  if ((pCourbe != nullptr) && (pCourbe->isClosed()))
185  {
186  pCourbe->close(true);
187  }
188 }
189 
191 {
192  // On deconnecte la detection de modification du texte
193  disconnect(_lineEditDistMax, &QLineEdit::textChanged, this, &TYCourbeNiveauWidget::updateUseDefault);
194 
195  // Recuperation de la valeur par defaut
196  _lineEditDistMax->setText(
197  QString().setNum(TYCourbeNiveau::getDefaultDistMax())); // getElement()->getDistMax()) );
198  _statusDMax = false;
199 
201 
202  // On reconnecte apres modification
203  connect(_lineEditDistMax, &QLineEdit::textChanged, this, &TYCourbeNiveauWidget::updateUseDefault);
204 }
205 
207 {
208  // Recuperation de la valeur par defaut
209  _statusDMax = true;
210 }
211 
213 {
214  if (closed)
215  {
216  tabPts.pop_back();
217  }
218 }
outil IHM pour l'objet ColorInterface (fichier header)
#define TR(id)
Outil IHM pour une courbe de niveau (fichier header)
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
Definition: TYDefines.h:340
outil IHM pour une entrée utilisateur (fichier header)
classe de l'objet IHM pour l'objet ColorInterface
TYColorInterfaceWidget * _colorW
QGridLayout * _courbeNiveauLayout
void cleanTabPoints(TYTabPoint &tabPts, bool closed)
TYCourbeNiveauWidget(TYCourbeNiveau *pElement, QWidget *_pParent=NULL)
TabPointsWidget * _tabPoints
QPushButton * _pushButtonUseDefault
QGridLayout * _groupBoxDistLayout
QGridLayout * _groupBoxAltLayout
bool isClosed() const
static double getDefaultDistMax()
void close(bool closed)
TYTabPoint & getListPoints()
classe de l'objet IHM pour un element
virtual void apply()
virtual void updateContent()
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43
TYElement * _pElement
Definition: TYWidget.h:114
void modified()
virtual void apply()
virtual void update()