Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYLinearMaillage.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 
16 #include <qdir.h>
17 
18 #include "Tympan/core/config.h"
19 #include "Tympan/core/logging.h"
21 #include "TYLinearMaillage.h"
22 
23 #if TY_USE_IHM
26 #endif
27 
30 
32 {
34 
35  _pSeg = new TYSegment();
36  setDensite(0.1);
37 }
38 
40 {
41  *this = other;
42 }
43 
45 
47 {
48  if (this != &other)
49  {
50  TYMaillage::operator=(other);
51  _pSeg = other._pSeg;
52  _densite = other._densite;
54  }
55  return *this;
56 }
57 
59 {
60  if (this != &other)
61  {
62  if (TYMaillage::operator!=(other))
63  {
64  return false;
65  }
66  if (!(_pSeg == other._pSeg))
67  {
68  return false;
69  }
70  if (!(_densite == other._densite))
71  {
72  return false;
73  }
75  {
76  return false;
77  }
78  }
79  return true;
80 }
81 
83 {
84  return !operator==(other);
85 }
86 
87 bool TYLinearMaillage::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
88 {
89  if (!TYMaillage::deepCopy(pOther, copyId))
90  {
91  return false;
92  }
93 
94  TYLinearMaillage* pOtherMaillage = (TYLinearMaillage*)pOther;
95 
96  _densite = pOtherMaillage->_densite;
98 
99  _pSeg->deepCopy(pOtherMaillage->_pSeg, copyId);
100 
101  return true;
102 }
103 
104 std::string TYLinearMaillage::toString() const
105 {
106  return "TYLinearMaillage";
107 }
108 
110 {
111  DOM_Element domNewElem = TYMaillage::toXML(domElement);
112 
113  TYXMLTools::addElementDoubleValue(domNewElem, "densite", _densite);
114 
115  _pSeg->toXML(domNewElem);
116 
117  for (unsigned int i = 0; i < _ptsCalcul.size(); i++)
118  {
119  _ptsCalcul[i]->getSpectre()->toXML(domNewElem);
120  }
121 
122  return domNewElem;
123 }
124 
126 {
127  TYMaillage::fromXML(domElement);
128 
129  bool densiteOk = false;
130  bool bOldDatas = false;
131  double densite = 0.0;
132 
133  LPTYSpectre pSpectre = new TYSpectre();
134  TYTabLPSpectre* compatibilityVector = new TYTabLPSpectre();
135 
136  DOM_Element elemCur;
137 
138  QDomNodeList childs = domElement.childNodes();
139  for (unsigned int i = 0; i < childs.length(); i++)
140  {
141  elemCur = childs.item(i).toElement();
142  TYXMLTools::getElementDoubleValue(elemCur, "densite", densite, densiteOk);
143 
144  _pSeg->callFromXMLIfEqual(elemCur);
145 
146  // Old version : if we encounter spectra
147  if (pSpectre->callFromXMLIfEqual(elemCur))
148  {
149  bOldDatas = true;
150  compatibilityVector->push_back(pSpectre);
151  pSpectre = new TYSpectre();
152  }
153  }
154  setDensite(densite);
155 
156  if (bOldDatas == true)
157  {
158  setAllUses((void*)compatibilityVector);
159  }
160  else
161  {
162  delete compatibilityVector;
163  }
164 
165  make(_pSeg, _densite);
167 
168  return 1;
169 }
170 
171 bool TYLinearMaillage::toXML(const std::string& sFilePath)
172 {
173  bool bRet = false;
174  QString fileName = QString(sFilePath.c_str());
175  int i = fileName.lastIndexOf('/');
176  QDir fileDirectory = QDir(fileName.mid(0, i));
177  if (!fileDirectory.exists())
178  {
179  fileDirectory.mkdir(fileName.mid(0, i));
180  }
181 
182  if (!fileName.isEmpty())
183  {
184  if (!fileName.endsWith(".xml"))
185  {
186  fileName += ".xml";
187  }
188  }
189  else
190  {
191  return false;
192  }
193 
194  TYXMLManager xmlManager;
195 
196  xmlManager.createDoc(TY_PRODUCT_XMLTAG_, TY_PRODUCT_VERSION_);
197  xmlManager.addElement(this);
198 
199  if (xmlManager.save(fileName) == 0)
200  {
201  bRet = true;
202  }
203 
204  return bRet;
205 }
206 
207 bool TYLinearMaillage::fromXML(const std::string& sFilePath)
208 {
209  bool bRet = false;
210  QString fileName = QString(sFilePath.c_str());
211 
212  if (fileName.isEmpty())
213  {
214  return false;
215  }
216 
217  TYXMLManager xmlManager;
218  LPTYElementArray elements;
219  if (xmlManager.load(fileName, elements))
220  {
221  if (elements.size() == 1)
222  {
223  LPTYElement elt = elements[0];
224  if (strcmp(elt->getClassName(), "TYLinearMaillage") == 0)
225  {
226  TYLinearMaillage* pTmpMaillage = static_cast<TYLinearMaillage*>(elt.getRealPointer());
227  TYLinearMaillage::operator=(*pTmpMaillage);
228  bRet = true;
229  }
230  }
231  }
232 
233  return bRet;
234 }
235 
237 {
238  TYXMLManager xmlManager;
239 
240  xmlManager.createDoc(TY_PRODUCT_XMLTAG_, TY_PRODUCT_VERSION_);
241  xmlManager.addElement(this);
242 
243  QString retString = xmlManager.saveToString();
244 
245  return retString.toStdString();
246 }
247 
248 bool TYLinearMaillage::fromXMLString(const std::string& sXMLString)
249 {
250  bool bRet = false;
251 
252  TYXMLManager xmlManager;
253  LPTYElementArray elements;
254  if (xmlManager.loadFromString(QString(sXMLString.c_str()), elements))
255  {
256  if (elements.size() == 1)
257  {
258  LPTYElement elt = elements[0];
259  if (strcmp(elt->getClassName(), "TYLinearMaillage") == 0)
260  {
261  TYLinearMaillage* pTmpMaillage = static_cast<TYLinearMaillage*>(elt.getRealPointer());
262  TYLinearMaillage::operator=(*pTmpMaillage);
263  bRet = true;
264  }
265  }
266  }
267 
268  return bRet;
269 }
270 
272 {
274 }
275 
276 void TYLinearMaillage::make(LPTYSegment pSeg, double densite)
277 {
278  assert(pSeg);
279 
280  // Reset
282 
283  // Param
284  _pSeg = pSeg;
285  setDensite(densite);
286 
287  OVector3D vec(pSeg->_ptA, pSeg->_ptB);
288 
289  // On calcul le nb de points
290  int nbPts = (int)(densite * vec.norme());
291 
292  // Calcul du vecteur pas (ecart entre chaque point)
293  vec = vec * (1.0 / (double)nbPts);
294 
295  // Calcul du pt de depart pour le placement des points
296  OVector3D startPt = OVector3D(pSeg->_ptA);
297 
298  // Scan
299  for (int i = 0; i < nbPts; i++)
300  {
301  // Position du point
302  OPoint3D pos = startPt + (vec * i);
303 
304  // Ajout du point au maillage
305  LPTYPointCalcul pPoint = new TYPointCalcul(pos);
306  pPoint->setSpectre(new TYSpectre());
307  addPointCalcul(pPoint);
308  }
309 
310  setIsGeometryModified(true);
311 }
QDomElement DOM_Element
Definition: QT2DOM.h:30
std::vector< LPTYSpectre > TYTabLPSpectre
Collection de TYSpectre.
Definition: TYDefines.h:337
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:344
Representation graphique d'un maillage lineaire (fichier header)
Outil IHM pour un maillage lineaire (fichier header)
TY_EXTENSION_INST(TYLinearMaillage)
TY_EXT_GRAPHIC_INST(TYLinearMaillage)
The 3D point class.
Definition: 3d.h:487
virtual const char * getClassName() const
Definition: TYElement.h:248
OPoint3D _ptA
Point A of the segment.
Definition: 3d.h:1253
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1255
The 3D vector class.
Definition: 3d.h:298
double norme() const
Computes the length of this vector.
Definition: 3d.cpp:215
T * getRealPointer()
Definition: smartptr.h:291
QString _name
Nom courant de l'element.
Definition: TYElement.h:956
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:545
void setAllUses(void *allUses)
Definition: TYElement.h:926
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
Classe de definition d'un maillage lineaire.
bool operator!=(const TYLinearMaillage &other) const
Operateur !=.
virtual void clearResult()
LPTYSegment _pSeg
Le segment associe a ce maillage.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
TYLinearMaillage & operator=(const TYLinearMaillage &other)
Operateur =.
virtual void make(LPTYSegment pSeg, double densite=TY_MAILLAGE_DEFAULT_DENSITE)
Rempli la structure de points de calcul a partir d'un segment et d'une densite de points.
double _distancePointsCalcul
La distance entre 2 points de calcul consécutifs.
virtual DOM_Element toXML(DOM_Element &domElement)
bool fromXMLString(const std::string &sXMLString)
double _densite
La densite de points de calcul.
virtual ~TYLinearMaillage()
Destructeur. Destructeur de la classe TYLinearMaillage.
bool operator==(const TYLinearMaillage &other) const
Operateur ==.
TYLinearMaillage()
Constructeur. Constructeur de la classe TYLinearMaillage.
virtual std::string toString() const
std::string toXMLString()
virtual int fromXML(DOM_Element domElement)
void setDensite(double densite)
Fixe la densite de points de calcul.
virtual void clearResult()
Definition: TYMaillage.cpp:334
bool addPointCalcul(LPTYPointCalcul pPtCalcul)
Ajoute un nouveau point de calcul.
Definition: TYMaillage.cpp:342
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYMaillage.cpp:133
TYTabLPPointCalcul _ptsCalcul
Liste des points de calcul.
Definition: TYMaillage.h:409
virtual int fromXML(DOM_Element domElement)
Definition: TYMaillage.cpp:191
TYMaillage & operator=(const TYMaillage &other)
Operateur =.
Definition: TYMaillage.cpp:77
void remAllPointCalcul()
Suppression de tous les elements.
Definition: TYMaillage.cpp:396
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYMaillage.cpp:165
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
Classe de definition d'un point de calcul.C'est une classe derivee a TYPoint avec en plus un spectrep...
Definition: TYPointCalcul.h:33
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYSegment.cpp:97
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYSegment.cpp:120
int save(QString fileName)
int load(const QString &fileName, LPTYElementArray &eltCollection)
void createDoc(QString docName, QString version)
QString saveToString()
int addElement(TYElement *pElt)
int loadFromString(const QString &xmlString, LPTYElementArray &eltCollection)
static void addElementDoubleValue(DOM_Element &parentElem, DOMString nodeName, double nodeValue)
Definition: TYXMLTools.cpp:87
static bool getElementDoubleValue(DOM_Element parentElem, DOMString nodeName, double &nodeValue)
Definition: TYXMLTools.cpp:243