Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticSurfaceNodeWidget.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 
23 #include <qmenu.h>
24 #include <qtablewidget.h>
25 // Added by qt3to4:
26 #include <QGridLayout>
27 #include <QHeaderView>
28 #include <QtWidgets>
29 
31 #include "TYElementWidget.h"
35 
37 
39 #define TR(id) OLocalizator::getString("TYAcousticSurfaceNodeWidget", (id))
40 
42  QWidget* _pParent /*=NULL*/)
43  : TYWidget(pElement, _pParent)
44 {
45 
46  _elmW = new TYElementWidget(pElement, this);
47  _colorW = new TYColorInterfaceWidget(dynamic_cast<TYColorInterface*>(pElement), this);
48  _interW = new TYAcousticInterfaceWidget(dynamic_cast<TYAcousticInterface*>(pElement), this);
49  _surfaceW = new TYSurfaceInterfaceWidget(dynamic_cast<TYSurfaceInterface*>(pElement), this);
50 
51  resize(300, 480);
52  setWindowTitle(TR("id_caption"));
53  _acousticSurfacenodeLayout = new QGridLayout();
54  setLayout(_acousticSurfacenodeLayout);
55 
56  unsigned short numLine = 0;
57 
58  _acousticSurfacenodeLayout->addWidget(_elmW, numLine, 0);
59  _acousticSurfacenodeLayout->addWidget(_colorW, ++numLine, 0);
60  _acousticSurfacenodeLayout->addWidget(_surfaceW, ++numLine, 0);
61  _acousticSurfacenodeLayout->addWidget(_interW, ++numLine, 0);
62  /*
63  _groupBoxRect = new QGroupBox( this );
64  _groupBoxRect->setTitle( TR( "id_rect" ) );
65  _groupBoxRect->setColumnLayout(0, Qt::Vertical );
66  _groupBoxRect->layout()->setSpacing( 6 );
67  _groupBoxRect->layout()->setContentsMargins(11, 11, 11, 11);
68  _groupBoxRectLayout = new QGridLayout( _groupBoxRect->layout() );
69  _groupBoxRectLayout->setAlignment( Qt::AlignTop );
70 
71  _lineEditNomRect = new QLineEdit( _groupBoxRect );
72  _lineEditNomRect->setEnabled( false );
73  _groupBoxRectLayout->addWidget( _lineEditNomRect, 0, 0 );
74 
75  _pushButtonRect = new QPushButton( _groupBoxRect );
76  _pushButtonRect->setText( TR( "id_proprietes_button" ) );
77  _groupBoxRectLayout->addWidget( _pushButtonRect, 0, 1 );
78 
79  _acousticSurfacenodeLayout->addWidget( _groupBoxRect, 4, 0 );
80  */
81  _groupBox = new QGroupBox(this);
82  _groupBox->setTitle(TR("id_tabaccsurf_box"));
83  _groupBoxLayout = new QGridLayout();
84  _groupBox->setLayout(_groupBoxLayout);
85 
86  _tableFaces = new QTableWidget();
87  _tableFaces->setColumnCount(2);
88  _tableFaces->setHorizontalHeaderItem(0, new QTableWidgetItem(TR("id_nom")));
89  _tableFaces->setHorizontalHeaderItem(1, new QTableWidgetItem(TR("id_emission")));
90 
91  _groupBoxLayout->addWidget(_tableFaces, 0, 0);
92  _acousticSurfacenodeLayout->addWidget(_groupBox, ++numLine, 0);
93 
94  updateContent();
95 
96  // connect( _pushButtonRect,&QPushButton::clicked,this, &TYAcousticSurfaceNodeWidget::editRect);
97 }
98 
100 
102 {
103  _elmW->updateContent();
106 
107  // _lineEditNomRect->setText( getElement()->getBoundingRect()->getName() );
108 
109  for (int i = 0, row = 0; i < getElement()->getTabAcousticSurf().size(); i++, row++)
110  {
111  LPTYAcousticSurface pSurf = getElement()->getAcousticSurf(i);
112 
113  if (pSurf->getIsSub())
114  {
115  _tableFaces->setRowCount(i + 1);
116  QTableWidgetItem* pItem = new QTableWidgetItem(pSurf->getName());
117  _tableFaces->setItem(row, 0, pItem);
118  QTableWidgetItem* pCheckItemEmit = new QTableWidgetItem(" ");
119  pCheckItemEmit->setCheckState(pSurf->getIsRayonnant() ? Qt::Checked : Qt::Unchecked);
120  _tableFaces->setItem(row, 1, pCheckItemEmit);
121  }
122  }
123 }
124 
126 {
127  unsigned int i = 0;
128 
129  _elmW->apply();
130  _colorW->apply();
131  _surfaceW->apply();
132 
133  TYTabAcousticSurfaceGeoNode* pTab = &getElement()->getTabAcousticSurf();
134  for (i = 0; i < pTab->size(); ++i)
135  if (!TYAcousticSurface::safeDownCast(pTab->operator[](i)->getElement())->getIsSub())
136  {
137  TYAcousticSurface::safeDownCast(pTab->operator[](i)->getElement())
138  ->setColor(getElement()->getColor());
139  }
140 
141  for (i = 0; i < _tableFaces->rowCount(); i++)
142  {
143  LPTYAcousticSurface pSurf = getElement()->getAcousticSurf(i);
144  QTableWidgetItem* pCheck = (QTableWidgetItem*)_tableFaces->item(i, 1);
145  pSurf->setIsRayonnant(pCheck->checkState() == Qt::Checked);
146  QTableWidgetItem* pText = (QTableWidgetItem*)_tableFaces->item(i, 0);
147  pSurf->setName(pText->text());
148  }
149 
150  _interW->apply();
151 
153 
154  emit modified();
155 }
156 
158 {
159  LPTYAcousticSurface pSurf = getElement()->getAcousticSurf(item);
160  QTableWidgetItem* pCheck = (QTableWidgetItem*)_tableFaces->item(item, 1);
161  pSurf->setIsRayonnant(pCheck->checkState() == Qt::Checked);
162  QTableWidgetItem* pText = (QTableWidgetItem*)_tableFaces->item(item, 0);
163  pSurf->setName(pText->text());
164 
165  int ret = getElement()->getAcousticSurf(item)->edit(this);
166 
167  if (ret == QDialog::Accepted)
168  {
169  pCheck->setCheckState(pSurf->getIsRayonnant() ? Qt::Checked : Qt::Unchecked);
170  pText->setText(pSurf->getName());
171  }
172 }
173 
175 {
176  LPTYAcousticSurfaceGeoNode pSurfNode = getElement()->getTabAcousticSurf()[item];
177 
178  bool ret = getElement()->remAcousticSurf(pSurfNode);
179 
180  _tableFaces->removeRow(item);
181 
182  if (ret)
183  {
184  updateContent();
185  }
186 }
187 /*
188 void TYAcousticSurfaceNodeWidget::editRect()
189 {
190  int ret = getElement()->getBoundingRect()->edit(this);
191 
192  if (ret == QDialog::Accepted) {
193  _lineEditNomRect->setText( getElement()->getBoundingRect()->getName() );
194  }
195 }
196 */
197 /*
198 void TYAcousticSurfaceNodeWidget::selectionChanged( int index)
199 {
200  switch (index) {
201  case 0: resize( 300, 700 );
202  _interW->show();
203  _groupBoxRect->show();
204  _groupBox->show();
205  break;
206  case 1: resize( 300, 200 );
207  _interW->hide();
208  _groupBoxRect->show();
209  _groupBox->show();
210  break;
211  case 2: resize( 300, 300);
212  _interW->show();
213  _groupBoxRect->hide();
214  _groupBox->hide();
215  break;
216  }
217 }
218 */
219 
221 {
222  QPoint point = _tableFaces->mapFrom(this, e->pos());
223 
224  if ((point.x() >= 0) && (point.y() >= 0) && (point.x() <= _tableFaces->width()) &&
225  (point.y() <= _tableFaces->height()))
226  {
227  // It is not very explicit in Qt's QTableView documentation, but coordinates given to itemAt must be
228  // in the viewport's coordinate system (viewport = cells displayed on screen -- headers excluded)
229  QPoint resPoint = _tableFaces->viewport()->mapFrom(_tableFaces, point);
230  QTableWidgetItem* item = _tableFaces->itemAt(resPoint);
231  if (item)
232  {
233  QMenu* pMenu = new QMenu(this);
234 
235  QAction* prop = pMenu->addAction(TR("id_property"));
236  QAction* del = pMenu->addAction(TR("id_delete_surf"));
237 
238  QAction* ret = pMenu->exec(_tableFaces->mapToGlobal(point));
239 
240  if (ret)
241  {
242  if (ret == prop)
243  {
244  editAccSurf(_tableFaces->indexAt(resPoint).row());
245  }
246  else if (ret == del)
247  {
248  delAccSurf(_tableFaces->indexAt(resPoint).row());
249  }
250  }
251  }
252  }
253 }
QColor getColor
Outil IHM pour une interface acoustique (fichier header)
#define TR(id)
outil IHM pour un ensemble de surfaces acoustiques (fichier header)
std::vector< LPTYAcousticSurfaceGeoNode > TYTabAcousticSurfaceGeoNode
Collection de noeuds geometriques de type TYAcousticSurface.
outil IHM pour l'objet ColorInterface (fichier header)
outil IHM pour un element (fichier header)
outil IHM pour la gestion des objets de type SurfaceInterface (fichier header)
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
classe de l'objet IHM pour une interface acoustique
TYSurfaceInterfaceWidget * _surfaceW
TYAcousticInterfaceWidget * _interW
virtual void contextMenuEvent(QContextMenuEvent *e)
TYAcousticSurfaceNodeWidget(TYAcousticSurfaceNode *pElement, QWidget *_pParent=NULL)
virtual void setIsRayonnant(bool rayonnant=true, bool recursif=true)
Get/set de l'etat rayonnant ou pas.
classe de l'objet IHM pour l'objet ColorInterface
classe de l'objet IHM pour un element
virtual void apply()
virtual void updateContent()
void setName(QString name)
Definition: TYElement.h:678
virtual QString getName() const
Definition: TYElement.h:691
virtual void setIsAcousticModified(bool isModified)
Definition: TYElement.cpp:248
classe de l'objet IHM pour la gestion des objets de type SurfaceInterface
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43
TYElement * _pElement
Definition: TYWidget.h:114
void modified()