Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYElementListItem.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 
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  // Identifiant stable pour sauvegarder/restaurer l’expansion
82  if (_pElement)
83  {
84  if (_pElement->isA("TYCalcul"))
85  {
86  OGenID currentId = TYCalcul::safeDownCast(_pElement)->getSolverId();
87  setData(0, Qt::UserRole, currentId.toString()); // identifiant unique pour un calcul
88  }
89  else
90  {
91  setData(0, Qt::UserRole, _pElement->getID().toString()); // identifiant unique générique
92  }
93  }
94 
95  updateContent();
96 }
97 
99 {
100  if (_pElement)
101  {
102  setText(0, _pElement->getName()); // VERSION 3.6.2
103  // setText(1, _pElement->getName());
104 
105  bool bInCurrentCalcul = false;
106 
107  if (_pElement->isA("TYCalcul"))
108  {
109  // Nom du solveur utilisé par le calcul
111  if (pCalcul->getState() == TYCalcul::Locked)
112  {
113  setText(1, TR("id_locked"));
114  }
115  else
116  {
117  OGenID currentId = pCalcul->getSolverId();
118  setText(1, TYPluginManager::get()->getInfo("name", currentId));
119  }
120  }
121  else if (dynamic_cast<TYPointCalcul*>(_pElement._pObj) != nullptr)
122  {
123  TYPointControl* pPoint = dynamic_cast<TYPointControl*>(_pElement.getRealPointer());
124  bInCurrentCalcul = pPoint->etat();
125  }
126  else if (dynamic_cast<TYMaillage*>(_pElement.getRealPointer()) != nullptr)
127  {
128  TYMaillage* pMaillage = dynamic_cast<TYMaillage*>(_pElement.getRealPointer());
129  bInCurrentCalcul = pMaillage->etat();
130  }
131  else
132  {
133  if (_pCurrentCalcul)
134  {
135  bInCurrentCalcul = _pCurrentCalcul->isInSelection(_pElement);
136  }
137  else
138  {
139  bInCurrentCalcul = _pElement->isInCurrentCalcul();
140  }
141  }
142 
143  if (_checkable)
144  {
145  QTreeWidgetItem::setCheckState(0, bInCurrentCalcul ? Qt::Checked : Qt::Unchecked);
146  }
147 
148  // Mise a jour des items des parents
149  QTreeWidgetItem* pParentItem = this->parent();
150  bInCurrentCalcul = false;
151  while (pParentItem)
152  {
153  TYElementListItem* pCheckItem = (TYElementListItem*)pParentItem;
154  TYElement* pChkElt = pCheckItem->getElement();
155  if (pChkElt && pCheckItem->isCheckable())
156  {
157  if (_pCurrentCalcul)
158  {
159  bInCurrentCalcul = _pCurrentCalcul->isInSelection(pChkElt);
160  }
161  else
162  {
163  bInCurrentCalcul = pChkElt->isInCurrentCalcul();
164  }
165 
166  pCheckItem->QTreeWidgetItem::setCheckState(0, bInCurrentCalcul ? Qt::Checked : Qt::Unchecked);
167  }
168 
169  pParentItem = pParentItem->parent();
170  }
171 
172  // Mise à jour des enfant aussi ...
173  updateChilds();
174  }
175 }
176 
178 {
179  if (childCount() == 0)
180  {
181  if (parent() != NULL)
182  {
183  return;
184  }
185  }
186  else
187  {
188  TYElementListItem* childItem = nullptr;
189 
190  while (childCount() > 0)
191  {
192  childItem = (TYElementListItem*)child(0);
193  childItem->remove();
194  delete childItem;
195  }
196 
197  // Appel recursif
198  remove();
199  }
200 }
201 
202 void TYElementListItem::setOn(bool state, bool UpdateModelers)
203 {
205  {
206  // Si le calcul courant est bloque, on empeche le changement d'etat
207  // if (_pCurrentCalcul->getState()==TYCalcul::Locked) // DTn : Desactive 20110915
208  //{
209  // updateContent(); // On met a jour a tout hasard ...
210  // return;
211  //}
212 
213  // On traite a part le cas des points de controle ...
214  if (dynamic_cast<TYPointCalcul*>(_pElement._pObj) != nullptr)
215  {
216  TYPointControl* pPoint = dynamic_cast<TYPointControl*>(_pElement.getRealPointer());
217  if ((pPoint->etat() != state) && (getTYApp()->getCalculManager()->askForResetResultat()))
218  {
219  bool need_to_rebuild_result(false);
220  if (state) // Ajout d'un point de controle
221  {
222  need_to_rebuild_result |= _pCurrentCalcul->addPtCtrlToResult(pPoint);
223  }
224  else // Suppression d'un point de controle
225  {
226  need_to_rebuild_result |= _pCurrentCalcul->remPtCtrlFromResult(pPoint);
227  }
228 
229  if (need_to_rebuild_result)
230  {
232  }
233  if (UpdateModelers)
234  {
235  if (_pElement->getParent())
236  {
238  _pElement->getParent()->updateGraphicTree();
239  }
240  else
241  {
242  _pElement->updateGraphic();
243  }
244 
245  getTYMainWnd()->updateModelers(false, false, true);
246  }
247  }
248  }
249  else if (dynamic_cast<TYMaillage*>(_pElement._pObj) != nullptr) // ... et les maillages
250  {
251  TYMaillage* pMaillage = dynamic_cast<TYMaillage*>(_pElement.getRealPointer());
252  if ((pMaillage->etat() != state) && (getTYApp()->getCalculManager()->askForResetResultat()))
253  {
254  if (state) // Ajout d'un point de controle
255  {
256  _pCurrentCalcul->addMaillage(pMaillage);
257  }
258  else // Suppression d'un point de controle
259  {
260  _pCurrentCalcul->remMaillage(pMaillage);
261  }
262 
263  if (UpdateModelers)
264  {
265  if (_pElement->getParent())
266  {
268  _pElement->getParent()->updateGraphicTree();
269  }
270  else
271  {
272  _pElement->updateGraphic();
273  }
274 
275  getTYMainWnd()->updateModelers(false, false, true);
276  }
277  }
278  }
279  else if (_pCurrentCalcul->isInSelection(_pElement) != state)
280  {
281  if (getTYApp()->getCalculManager()->askForResetResultat())
282  {
283  if (state)
284  {
288  }
289  else
290  {
292  }
293 
294  if (_pElement->isA("TYSiteNode"))
295  {
296  TYSiteNode* pSite = dynamic_cast<TYSiteNode*>(_pElement.getRealPointer());
297  LPTYCalcul pCalc = NULL;
298  if (getTYApp()->getCurProjet() && pSite)
299  {
300  pCalc = getTYApp()->getCurProjet()->getCurrentCalcul();
301  if (pCalc)
302  {
303  pCalc->getCalculElements(pSite);
304  }
305  }
306  }
307 
308  if (UpdateModelers)
309  {
310  if (_pElement->getParent())
311  {
313  _pElement->getParent()->updateGraphicTree();
314  }
315  else
316  {
317  _pElement->updateGraphic();
318  }
319 
320  getTYMainWnd()->updateModelers(false, false, true);
321  }
322  }
323  }
324  }
325  else
326  {
327  // Toujours actif quand il n'y a pas de calcul courant
328  state = true;
329  }
330 
331  // Mise a jour de l'item
332  updateContent();
333 }
334 
335 void TYElementListItem::setCheckState(int column, Qt::CheckState state)
336 {
337  if (_checkable)
338  {
339  setOn(state == Qt::Checked, true);
340 
341  QTreeWidgetItem::setCheckState(column, state);
342  }
343 }
344 
346 {
347  int nbchilds = this->childCount();
348  for (int i = 0; i < nbchilds; i++)
349  {
350  TYElementListItem* childItem = (TYElementListItem*)child(i);
351  TYElement* pChkElt = childItem->getElement();
352  bool bInCurrentCalcul = false;
353  if (pChkElt && childItem->isCheckable())
354  {
355  if (TYPointControl* pPoint = dynamic_cast<TYPointControl*>(pChkElt))
356  {
357  childItem->QTreeWidgetItem::setCheckState(0, pPoint->etat() ? Qt::Checked : Qt::Unchecked);
358  continue;
359  }
360 
361  if (_pCurrentCalcul)
362  {
363  bInCurrentCalcul = _pCurrentCalcul->isInSelection(pChkElt);
364  }
365  else
366  {
367  bInCurrentCalcul = pChkElt->isInCurrentCalcul();
368  }
369 
370  childItem->QTreeWidgetItem::setCheckState(0, bInCurrentCalcul ? Qt::Checked : Qt::Unchecked);
371  }
372 
373  childItem->updateChilds();
374  }
375 }
TYApplication * getTYApp()
Retourne le pointeur sur l'application.
TYMainWindow * getTYMainWnd()
Retourne le pointeur sur la fenetre principale.
pour l'application Tympan (fichier header)
#define TR(id)
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
const QString toString() const
Definition: idgen.h:78
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.
Calculation program.
Definition: TYCalcul.h:50
int getState()
Get calculation state.
Definition: TYCalcul.h:416
bool addPtCtrlToResult(LPTYPointControl pPoint)
Add a checkpoint to the results array.
Definition: TYCalcul.cpp:1141
@ Locked
Definition: TYCalcul.h:62
void getCalculElements(LPTYSiteNode pSite)
Recover all the elements of the scene which take part in the calculation.
Definition: TYCalcul.cpp:1038
bool remMaillage(TYMaillage *pMaillage)
Remove a maillage from calcul.
Definition: TYCalcul.cpp:1364
bool remToSelection(TYUUID id)
Removes the item from the selection of this Calculation.
Definition: TYCalcul.cpp:962
bool isInSelection(TYUUID id)
Tests if the element is present in the selection of this Calculation.
Definition: TYCalcul.cpp:1004
const OGenID getSolverId() const
Get solver ID.
Definition: TYCalcul.h:465
bool addMaillage(TYMaillage *pMaillage)
Add this maillage to calcul.
Definition: TYCalcul.cpp:1318
bool remPtCtrlFromResult(LPTYPointControl pPoint)
Deletes a checkpoint from the results table.
Definition: TYCalcul.cpp:1164
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:873
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:706
virtual bool isInCurrentCalcul()
Definition: TYElement.h:539
const TYUUID & getID() const
Definition: TYElement.cpp:176
virtual QString getName() const
Definition: TYElement.h:691
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:616
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