Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYElementListItem.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 
21 #include <qpixmap.h>
22 
29 #include "TYElementListItem.h"
30 
31 #define TR(id) OLocalizator::getString("TYElementListItem", (id))
32 #define IMG(id) OLocalizator::getPicture("TYElementListItem", (id))
33 
34 TYElementListItem::TYElementListItem(QTreeWidget* parent, LPTYElement pElement, LPTYCalcul pCalcul,
35  const QStringList& labels /*=QStringList()*/, bool checkable)
36  : QTreeWidgetItem(parent)
37 {
38  initItem(pElement, pCalcul, labels, checkable);
39 }
40 
41 TYElementListItem::TYElementListItem(QTreeWidgetItem* parent, LPTYElement pElement, LPTYCalcul pCalcul,
42  const QStringList& labels /*=QStringList()*/, bool checkable)
43  : QTreeWidgetItem(parent)
44 {
45  initItem(pElement, pCalcul, labels, checkable);
46 }
47 
48 TYElementListItem::TYElementListItem(QTreeWidget* parent, const QStringList& labels, LPTYCalcul pCalcul,
49  bool checkable)
50  : QTreeWidgetItem(parent, labels)
51 {
52  initItem(NULL, pCalcul, labels, checkable);
53 }
54 
55 TYElementListItem::TYElementListItem(QTreeWidgetItem* parent, const QStringList& labels, LPTYCalcul pCalcul,
56  bool checkable)
57  : QTreeWidgetItem(parent, labels)
58 {
59  initItem(NULL, pCalcul, labels, checkable);
60 }
61 
63 
65  const QStringList& labels /*=QStringList()*/, bool checkable)
66 {
67  _pElement = pElement;
68  _pCurrentCalcul = pCalcul;
69  _checkable = checkable;
70  _elementItem = _pElement ? true : false;
71 
72  if (labels.isEmpty())
73  {
74  // setText(0, TYWidget::getDisplayName(_pElement)); // Commente en VERSION 3.6.2
75  }
76  else
77  {
78  setText(0, labels[0]);
79  }
80 
81  updateContent();
82 }
83 
85 {
86  if (_pElement)
87  {
88  setText(0, _pElement->getName()); // VERSION 3.6.2
89  // setText(1, _pElement->getName());
90 
91  bool bInCurrentCalcul = false;
92 
93  if (_pElement->isA("TYCalcul"))
94  {
95  // Nom du solveur utilisé par le calcul
96  OGenID currentId = TYCalcul::safeDownCast(_pElement)->getSolverId();
97 
98  setText(1, TYPluginManager::get()->getInfo("name", currentId));
99  }
100  else if (dynamic_cast<TYPointCalcul*>(_pElement._pObj) != nullptr)
101  {
102  TYPointControl* pPoint = dynamic_cast<TYPointControl*>(_pElement.getRealPointer());
103  bInCurrentCalcul = pPoint->etat();
104  }
105  else if (dynamic_cast<TYMaillage*>(_pElement.getRealPointer()) != nullptr)
106  {
107  TYMaillage* pMaillage = dynamic_cast<TYMaillage*>(_pElement.getRealPointer());
108  bInCurrentCalcul = pMaillage->etat();
109  }
110  else
111  {
112  if (_pCurrentCalcul)
113  {
114  bInCurrentCalcul = _pCurrentCalcul->isInSelection(_pElement);
115  }
116  else
117  {
118  bInCurrentCalcul = _pElement->isInCurrentCalcul();
119  }
120  }
121 
122  if (_checkable)
123  {
124  QTreeWidgetItem::setCheckState(0, bInCurrentCalcul ? Qt::Checked : Qt::Unchecked);
125  }
126 
127  // Mise a jour des items des parents
128  QTreeWidgetItem* pParentItem = this->parent();
129  bInCurrentCalcul = false;
130  while (pParentItem)
131  {
132  TYElementListItem* pCheckItem = (TYElementListItem*)pParentItem;
133  TYElement* pChkElt = pCheckItem->getElement();
134  if (pChkElt && pCheckItem->isCheckable())
135  {
136  if (_pCurrentCalcul)
137  {
138  bInCurrentCalcul = _pCurrentCalcul->isInSelection(pChkElt);
139  }
140  else
141  {
142  bInCurrentCalcul = pChkElt->isInCurrentCalcul();
143  }
144 
145  pCheckItem->QTreeWidgetItem::setCheckState(0, bInCurrentCalcul ? Qt::Checked : Qt::Unchecked);
146  }
147 
148  pParentItem = pParentItem->parent();
149  }
150 
151  // Mise à jour des enfant aussi ...
152  updateChilds();
153  }
154 }
155 
157 {
158  if (childCount() == 0)
159  {
160  if (parent() != NULL)
161  {
162  return;
163  }
164  }
165  else
166  {
167  TYElementListItem* childItem = nullptr;
168 
169  while (childCount() > 0)
170  {
171  childItem = (TYElementListItem*)child(0);
172  childItem->remove();
173  delete childItem;
174  }
175 
176  // Appel recursif
177  remove();
178  }
179 }
180 
181 void TYElementListItem::setOn(bool state, bool UpdateModelers)
182 {
184  {
185  // Si le calcul courant est bloque, on empeche le changement d'etat
186  // if (_pCurrentCalcul->getState()==TYCalcul::Locked) // DTn : Desactive 20110915
187  //{
188  // updateContent(); // On met a jour a tout hasard ...
189  // return;
190  //}
191 
192  // On traite a part le cas des points de controle ...
193  if (dynamic_cast<TYPointCalcul*>(_pElement._pObj) != nullptr)
194  {
195  TYPointControl* pPoint = dynamic_cast<TYPointControl*>(_pElement.getRealPointer());
196  if ((pPoint->etat() != state) && (getTYApp()->getCalculManager()->askForResetResultat()))
197  {
198  bool need_to_rebuild_result(false);
199  if (state) // Ajout d'un point de controle
200  {
201  need_to_rebuild_result |= _pCurrentCalcul->addPtCtrlToResult(pPoint);
202  }
203  else // Suppression d'un point de controle
204  {
205  need_to_rebuild_result |= _pCurrentCalcul->remPtCtrlFromResult(pPoint);
206  }
207 
208  if (need_to_rebuild_result)
209  {
211  }
212  if (UpdateModelers)
213  {
214  if (_pElement->getParent())
215  {
217  _pElement->getParent()->updateGraphicTree();
218  }
219  else
220  {
221  _pElement->updateGraphic();
222  }
223 
224  getTYMainWnd()->updateModelers(false, false, true);
225  }
226  }
227  }
228  else if (dynamic_cast<TYMaillage*>(_pElement._pObj) != nullptr) // ... et les maillages
229  {
230  TYMaillage* pMaillage = dynamic_cast<TYMaillage*>(_pElement.getRealPointer());
231  if ((pMaillage->etat() != state) && (getTYApp()->getCalculManager()->askForResetResultat()))
232  {
233  if (state) // Ajout d'un point de controle
234  {
235  _pCurrentCalcul->addMaillage(pMaillage);
236  }
237  else // Suppression d'un point de controle
238  {
239  _pCurrentCalcul->remMaillage(pMaillage);
240  }
241 
242  if (UpdateModelers)
243  {
244  if (_pElement->getParent())
245  {
247  _pElement->getParent()->updateGraphicTree();
248  }
249  else
250  {
251  _pElement->updateGraphic();
252  }
253 
254  getTYMainWnd()->updateModelers(false, false, true);
255  }
256  }
257  }
258  else if (_pCurrentCalcul->isInSelection(_pElement) != state)
259  {
260  if (getTYApp()->getCalculManager()->askForResetResultat())
261  {
262  if (state)
263  {
267  }
268  else
269  {
271  }
272 
273  if (_pElement->isA("TYSiteNode"))
274  {
275  TYSiteNode* pSite = dynamic_cast<TYSiteNode*>(_pElement.getRealPointer());
276  LPTYCalcul pCalc = NULL;
277  if (getTYApp()->getCurProjet() && pSite)
278  {
279  pCalc = getTYApp()->getCurProjet()->getCurrentCalcul();
280  if (pCalc)
281  {
282  pCalc->getCalculElements(pSite);
283  }
284  }
285  }
286 
287  if (UpdateModelers)
288  {
289  if (_pElement->getParent())
290  {
292  _pElement->getParent()->updateGraphicTree();
293  }
294  else
295  {
296  _pElement->updateGraphic();
297  }
298 
299  getTYMainWnd()->updateModelers(false, false, true);
300  }
301  }
302  }
303  }
304  else
305  {
306  // Toujours actif quand il n'y a pas de calcul courant
307  state = true;
308  }
309 
310  // Mise a jour de l'item
311  updateContent();
312 }
313 
314 void TYElementListItem::setCheckState(int column, Qt::CheckState state)
315 {
316  if (_checkable)
317  {
318  setOn(state == Qt::Checked, true);
319 
320  QTreeWidgetItem::setCheckState(column, state);
321  }
322 }
323 
325 {
326  int nbchilds = this->childCount();
327  for (int i = 0; i < nbchilds; i++)
328  {
329  TYElementListItem* childItem = (TYElementListItem*)child(i);
330  TYElement* pChkElt = childItem->getElement();
331  bool bInCurrentCalcul = false;
332  if (pChkElt && childItem->isCheckable())
333  {
334  if (TYPointControl* pPoint = dynamic_cast<TYPointControl*>(pChkElt))
335  {
336  childItem->QTreeWidgetItem::setCheckState(0, pPoint->etat() ? Qt::Checked : Qt::Unchecked);
337  continue;
338  }
339 
340  if (_pCurrentCalcul)
341  {
342  bInCurrentCalcul = _pCurrentCalcul->isInSelection(pChkElt);
343  }
344  else
345  {
346  bInCurrentCalcul = pChkElt->isInCurrentCalcul();
347  }
348 
349  childItem->QTreeWidgetItem::setCheckState(0, bInCurrentCalcul ? Qt::Checked : Qt::Unchecked);
350  }
351 
352  childItem->updateChilds();
353  }
354 }
TYApplication * getTYApp()
Retourne le pointeur sur l'application.
TYMainWindow * getTYMainWnd()
Retourne le pointeur sur la fenetre principale.
pour l'application Tympan (fichier header)
Frame pour les messages de retour (fichier header)
Fenetre principale de l'application Tympan (fichier header)
outil IHM pour un objet metier de type TYElement (fichier header)
Definition: idgen.h:28
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
bool isA(const char *className) const
Definition: TYElement.cpp:65
T * getRealPointer()
Definition: smartptr.h:291
T * _pObj
The real pointer, must derived IRefCount.
Definition: smartptr.h:307
LPTYProjet getCurProjet()
Set/Get du projet courant.
TYCalculManager * getCalculManager()
Get du gestionnaire de calculs.
Definition: TYApplication.h:99
bool askForResetResultat()
Previent l'utilisateur que le resultat va etre efface, si celui-ci est valide.
bool addPtCtrlToResult(LPTYPointControl pPoint)
Add a checkpoint to the results array.
Definition: TYCalcul.cpp:1140
void getCalculElements(LPTYSiteNode pSite)
Recover all the elements of the scene which take part in the calculation.
Definition: TYCalcul.cpp:1037
bool remMaillage(TYMaillage *pMaillage)
Remove a maillage from calcul.
Definition: TYCalcul.cpp:1358
bool remToSelection(TYUUID id)
Removes the item from the selection of this Calculation.
Definition: TYCalcul.cpp:961
bool isInSelection(TYUUID id)
Tests if the element is present in the selection of this Calculation.
Definition: TYCalcul.cpp:1003
bool addMaillage(TYMaillage *pMaillage)
Add this maillage to calcul.
Definition: TYCalcul.cpp:1312
bool remPtCtrlFromResult(LPTYPointControl pPoint)
Deletes a checkpoint from the results table.
Definition: TYCalcul.cpp:1163
const LPTYResultat getResultat() const
Get result.
Definition: TYCalcul.h:367
bool addToSelection(TYUUID id)
Adds the item to the selection of this Calculation.
Definition: TYCalcul.cpp:872
Frame pour les messages de retour.
void updateContent()
Mets a jour le contenu des colonnes.
void initItem(LPTYElement pElement, LPTYCalcul pCalcul, const QStringList &labels=QStringList(), bool checkable=false)
bool isCheckable()
Indique si de type checkbox.
void updateChilds()
update child status
void setOn(bool state, bool UpdateModelers)
ajouter a la liste
TYElementListItem(QTreeWidget *parent, LPTYElement pElement, LPTYCalcul pCalcul=NULL, const QStringList &labels=QStringList(), bool checkable=false)
Constructeur.
LPTYElement _pElement
L'element associe a cet item.
virtual ~TYElementListItem()
Destructeur.
LPTYElement getElement()
Retourne l'element associe a cet item.
void remove()
Supprime l'item de la liste.
bool _checkable
element de type checkbox ?
void setCheckState(int column, Qt::CheckState state)
Reimplementation.
bool _elementItem
Indique si un element est associe a cet item.
LPTYCalcul _pCurrentCalcul
Le Calcul courant.
TYElement * getParent() const
Definition: TYElement.h:699
virtual bool isInCurrentCalcul()
Definition: TYElement.h:541
virtual QString getName() const
Definition: TYElement.h:684
virtual void setIsAcousticModified(bool isModified)
Definition: TYElement.cpp:248
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
Classe de definition d'un maillage.
Definition: TYMaillage.h:51
virtual bool etat()
Definition: TYMaillage.cpp:647
void updateModelers(bool clipping=true, bool axesAndGrid=true, bool displayList=true)
static LPTYPluginManager get()
Classe de definition d'un point de calcul.C'est une classe derivee a TYPoint avec en plus un spectrep...
Definition: TYPointCalcul.h:33
Classe de definition d'un point de controle.Le point de controle est un point de calcul avec une haut...
virtual bool etat()
LPTYCalcul getCurrentCalcul()
Set/Get du pointeur du Calcul courant.
Definition: TYProjet.h:426
void buildMatrix()
Construit la matrice resultat a partir des sources et recepteurs entres.
Definition: TYResultat.cpp:427