Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticSurfaceNodeWidget.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 <qmenu.h>
24 #include <qtablewidget.h>
25 // Added by qt3to4:
26 #include <QGridLayout>
27 #include <QHeaderView>
28 
33 
35 
37 #define TR(id) OLocalizator::getString("TYAcousticSurfaceNodeWidget", (id))
38 
40  QWidget* _pParent /*=NULL*/)
41  : TYWidget(pElement, _pParent)
42 {
43 
44  _elmW = new TYElementWidget(pElement, this);
45  _colorW = new TYColorInterfaceWidget(dynamic_cast<TYColorInterface*>(pElement), this);
46  _interW = new TYAcousticInterfaceWidget(dynamic_cast<TYAcousticInterface*>(pElement), this);
47  _surfaceW = new TYSurfaceInterfaceWidget(dynamic_cast<TYSurfaceInterface*>(pElement), this);
48 
49  resize(300, 480);
50  setWindowTitle(TR("id_caption"));
51  _acousticSurfacenodeLayout = new QGridLayout();
52  setLayout(_acousticSurfacenodeLayout);
53 
54  unsigned short numLine = 0;
55 
56  _acousticSurfacenodeLayout->addWidget(_elmW, numLine, 0);
57  _acousticSurfacenodeLayout->addWidget(_colorW, ++numLine, 0);
58  _acousticSurfacenodeLayout->addWidget(_surfaceW, ++numLine, 0);
59  _acousticSurfacenodeLayout->addWidget(_interW, ++numLine, 0);
60  /*
61  _groupBoxRect = new QGroupBox( this );
62  _groupBoxRect->setTitle( TR( "id_rect" ) );
63  _groupBoxRect->setColumnLayout(0, Qt::Vertical );
64  _groupBoxRect->layout()->setSpacing( 6 );
65  _groupBoxRect->layout()->setContentsMargins(11, 11, 11, 11);
66  _groupBoxRectLayout = new QGridLayout( _groupBoxRect->layout() );
67  _groupBoxRectLayout->setAlignment( Qt::AlignTop );
68 
69  _lineEditNomRect = new QLineEdit( _groupBoxRect );
70  _lineEditNomRect->setEnabled( false );
71  _groupBoxRectLayout->addWidget( _lineEditNomRect, 0, 0 );
72 
73  _pushButtonRect = new QPushButton( _groupBoxRect );
74  _pushButtonRect->setText( TR( "id_proprietes_button" ) );
75  _groupBoxRectLayout->addWidget( _pushButtonRect, 0, 1 );
76 
77  _acousticSurfacenodeLayout->addWidget( _groupBoxRect, 4, 0 );
78  */
79  _groupBox = new QGroupBox(this);
80  _groupBox->setTitle(TR("id_tabaccsurf_box"));
81  _groupBoxLayout = new QGridLayout();
82  _groupBox->setLayout(_groupBoxLayout);
83 
84  _tableFaces = new QTableWidget();
85  _tableFaces->setColumnCount(2);
86  _tableFaces->setHorizontalHeaderItem(0, new QTableWidgetItem(TR("id_nom")));
87  _tableFaces->setHorizontalHeaderItem(1, new QTableWidgetItem(TR("id_emission")));
88 
89  _groupBoxLayout->addWidget(_tableFaces, 0, 0);
90  _acousticSurfacenodeLayout->addWidget(_groupBox, ++numLine, 0);
91 
92  updateContent();
93 
94  // connect( _pushButtonRect,&QPushButton::clicked,this, &TYAcousticSurfaceNodeWidget::editRect);
95 }
96 
98 
100 {
101  _elmW->updateContent();
104 
105  // _lineEditNomRect->setText( getElement()->getBoundingRect()->getName() );
106 
107  for (int i = 0, row = 0; i < getElement()->getTabAcousticSurf().size(); i++, row++)
108  {
109  LPTYAcousticSurface pSurf = getElement()->getAcousticSurf(i);
110 
111  if (pSurf->getIsSub())
112  {
113  _tableFaces->setRowCount(i + 1);
114  QTableWidgetItem* pItem = new QTableWidgetItem(pSurf->getName());
115  _tableFaces->setItem(row, 0, pItem);
116  QTableWidgetItem* pCheckItemEmit = new QTableWidgetItem(" ");
117  pCheckItemEmit->setCheckState(pSurf->getIsRayonnant() ? Qt::Checked : Qt::Unchecked);
118  _tableFaces->setItem(row, 1, pCheckItemEmit);
119  }
120  }
121 }
122 
124 {
125  unsigned int i = 0;
126 
127  _elmW->apply();
128  _colorW->apply();
129  _surfaceW->apply();
130 
131  TYTabAcousticSurfaceGeoNode* pTab = &getElement()->getTabAcousticSurf();
132  for (i = 0; i < pTab->size(); ++i)
133  if (!TYAcousticSurface::safeDownCast(pTab->operator[](i)->getElement())->getIsSub())
134  {
135  TYAcousticSurface::safeDownCast(pTab->operator[](i)->getElement())
136  ->setColor(getElement()->getColor());
137  }
138 
139  for (i = 0; i < _tableFaces->rowCount(); i++)
140  {
141  LPTYAcousticSurface pSurf = getElement()->getAcousticSurf(i);
142  QTableWidgetItem* pCheck = (QTableWidgetItem*)_tableFaces->item(i, 1);
143  pSurf->setIsRayonnant(pCheck->checkState() == Qt::Checked);
144  QTableWidgetItem* pText = (QTableWidgetItem*)_tableFaces->item(i, 0);
145  pSurf->setName(pText->text());
146  }
147 
148  _interW->apply();
149 
151 
152  emit modified();
153 }
154 
156 {
157  LPTYAcousticSurface pSurf = getElement()->getAcousticSurf(item);
158  QTableWidgetItem* pCheck = (QTableWidgetItem*)_tableFaces->item(item, 1);
159  pSurf->setIsRayonnant(pCheck->checkState() == Qt::Checked);
160  QTableWidgetItem* pText = (QTableWidgetItem*)_tableFaces->item(item, 0);
161  pSurf->setName(pText->text());
162 
163  int ret = getElement()->getAcousticSurf(item)->edit(this);
164 
165  if (ret == QDialog::Accepted)
166  {
167  pCheck->setCheckState(pSurf->getIsRayonnant() ? Qt::Checked : Qt::Unchecked);
168  pText->setText(pSurf->getName());
169  }
170 }
171 
173 {
174  LPTYAcousticSurfaceGeoNode pSurfNode = getElement()->getTabAcousticSurf()[item];
175 
176  bool ret = getElement()->remAcousticSurf(pSurfNode);
177 
178  _tableFaces->removeRow(item);
179 
180  if (ret)
181  {
182  updateContent();
183  }
184 }
185 /*
186 void TYAcousticSurfaceNodeWidget::editRect()
187 {
188  int ret = getElement()->getBoundingRect()->edit(this);
189 
190  if (ret == QDialog::Accepted) {
191  _lineEditNomRect->setText( getElement()->getBoundingRect()->getName() );
192  }
193 }
194 */
195 /*
196 void TYAcousticSurfaceNodeWidget::selectionChanged( int index)
197 {
198  switch (index) {
199  case 0: resize( 300, 700 );
200  _interW->show();
201  _groupBoxRect->show();
202  _groupBox->show();
203  break;
204  case 1: resize( 300, 200 );
205  _interW->hide();
206  _groupBoxRect->show();
207  _groupBox->show();
208  break;
209  case 2: resize( 300, 300);
210  _interW->show();
211  _groupBoxRect->hide();
212  _groupBox->hide();
213  break;
214  }
215 }
216 */
217 
219 {
220  QPoint point = _tableFaces->mapFrom(this, e->pos());
221 
222  if ((point.x() >= 0) && (point.y() >= 0) && (point.x() <= _tableFaces->width()) &&
223  (point.y() <= _tableFaces->height()))
224  {
225  QPoint resPoint = QPoint(point.x(), point.y() - _tableFaces->horizontalHeader()->height());
226  QTableWidgetItem* item = _tableFaces->itemAt(resPoint);
227  if (item)
228  {
229  QMenu* pMenu = new QMenu(this);
230 
231  QAction* prop = pMenu->addAction(TR("id_property"));
232  QAction* del = pMenu->addAction(TR("id_delete_surf"));
233 
234  QAction* ret = pMenu->exec(_tableFaces->mapToGlobal(point));
235 
236  if (ret)
237  {
238  if (ret == prop)
239  {
240  editAccSurf(_tableFaces->indexAt(resPoint).row());
241  }
242  else if (ret == del)
243  {
244  delAccSurf(_tableFaces->indexAt(resPoint).row());
245  }
246  }
247  }
248  }
249 }
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 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:671
virtual QString getName() const
Definition: TYElement.h:684
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()