Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRectangularMaillage.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"
22 #include "TYRectangularMaillage.h"
23 
24 #if TY_USE_IHM
27 #endif
28 
31 
33 {
35 
36  _pRect = new TYRectangle();
37  setDensiteX(0.1);
38  setDensiteY(0.1);
39  _nbPointsX = 0;
40  _posLabel = TYPoint(0, 0, 0);
41 }
42 
44 {
45  *this = other;
46 }
47 
49 
51 {
52  if (this != &other)
53  {
54  TYMaillage::operator=(other);
55  _pRect = other._pRect;
56  _densiteX = other._densiteX;
57  _densiteY = other._densiteY;
60  _nbPointsX = other._nbPointsX;
61  }
62  return *this;
63 }
64 
66 {
67  if (this != &other)
68  {
69  if (TYMaillage::operator!=(other))
70  {
71  return false;
72  }
73  if (!(*_pRect == *(other._pRect)))
74  {
75  return false;
76  }
77  if (!(_densiteX == other._densiteX))
78  {
79  return false;
80  }
81  if (!(_densiteY == other._densiteY))
82  {
83  return false;
84  }
86  {
87  return false;
88  }
90  {
91  return false;
92  }
93  }
94  return true;
95 }
96 
98 {
99  return !operator==(other);
100 }
101 
102 bool TYRectangularMaillage::deepCopy(const TYElement* pOther, bool copyId /*=true*/,
103  bool pUseCopyTag /*=false*/)
104 {
105  if (!TYMaillage::deepCopy(pOther, copyId))
106  {
107  return false;
108  }
109 
110  TYRectangularMaillage* pOtherMaillage = (TYRectangularMaillage*)pOther;
111 
112  _densiteX = pOtherMaillage->_densiteX;
113  _densiteY = pOtherMaillage->_densiteY;
116 
117  _pRect->deepCopy(pOtherMaillage->_pRect, copyId);
118 
119  return true;
120 }
121 
123 {
124  return "TYRectangularMaillage";
125 }
126 
128 {
129  DOM_Element domNewElem = TYMaillage::toXML(domElement);
130 
131  TYXMLTools::addElementDoubleValue(domNewElem, "densiteX", _densiteX);
132  TYXMLTools::addElementDoubleValue(domNewElem, "densiteY", _densiteY);
133 
134  _pRect->toXML(domNewElem);
135 
136  return domNewElem;
137 }
138 
140 {
141  TYMaillage::fromXML(domElement);
142 
143  bool densiteXOk = false;
144  bool densiteYOk = false;
145  bool bOldDatas = false;
146  double densiteX = 0.0;
147  double densiteY = 0.0;
148 
149  LPTYSpectre pSpectre = new TYSpectre();
150  TYTabLPSpectre* compatibilityVector = new TYTabLPSpectre();
151 
152  DOM_Element elemCur;
153 
154  QDomNodeList childs = domElement.childNodes();
155  for (unsigned int i = 0; i < childs.length(); i++)
156  {
157  elemCur = childs.item(i).toElement();
158 
159  TYXMLTools::getElementDoubleValue(elemCur, "densiteX", densiteX, densiteXOk);
160  TYXMLTools::getElementDoubleValue(elemCur, "densiteY", densiteY, densiteYOk);
161 
162  _pRect->callFromXMLIfEqual(elemCur);
163 
164  // Old version : if we encounter spectra
165  if (pSpectre->callFromXMLIfEqual(elemCur))
166  {
167  bOldDatas = true;
168  compatibilityVector->push_back(pSpectre);
169  pSpectre = new TYSpectre();
170  }
171  }
172  setDensiteX(densiteX);
173  setDensiteY(densiteY);
174 
175  if (bOldDatas == true)
176  {
177  setAllUses((void*)compatibilityVector);
178  }
179  else
180  {
181  delete compatibilityVector;
182  }
183 
186 
187  return 1;
188 }
189 
190 bool TYRectangularMaillage::toXML(const std::string& sFilePath)
191 {
192  bool bRet = false;
193  QString fileName = QString(sFilePath.c_str());
194  int i = fileName.lastIndexOf('/');
195  QDir fileDirectory = QDir(fileName.mid(0, i));
196  if (!fileDirectory.exists())
197  {
198  fileDirectory.mkdir(fileName.mid(0, i));
199  }
200 
201  if (!fileName.isEmpty())
202  {
203  if (!fileName.endsWith(".xml"))
204  {
205  fileName += ".xml";
206  }
207  }
208  else
209  {
210  return false;
211  }
212 
213  TYXMLManager xmlManager;
214 
215  xmlManager.createDoc(TY_PRODUCT_XMLTAG_, TY_PRODUCT_VERSION_);
216  xmlManager.addElement(this);
217 
218  if (xmlManager.save(fileName) == 0)
219  {
220  bRet = true;
221  }
222 
223  return bRet;
224 }
225 
226 bool TYRectangularMaillage::fromXML(const std::string& sFilePath)
227 {
228  bool bRet = false;
229  QString fileName = QString(sFilePath.c_str());
230 
231  if (fileName.isEmpty())
232  {
233  return false;
234  }
235 
236  TYXMLManager xmlManager;
237  LPTYElementArray elements;
238  if (xmlManager.load(fileName, elements))
239  {
240  if (elements.size() == 1)
241  {
242  LPTYElement elt = elements[0];
243  if (strcmp(elt->getClassName(), "TYRectangularMaillage") == 0)
244  {
245  TYRectangularMaillage* pTmpMaillage =
246  static_cast<TYRectangularMaillage*>(elt.getRealPointer());
247  TYRectangularMaillage::operator=(*pTmpMaillage);
248  bRet = true;
249  }
250  }
251  }
252 
253  return bRet;
254 }
255 
257 {
258  TYXMLManager xmlManager;
259 
260  xmlManager.createDoc(TY_PRODUCT_XMLTAG_, TY_PRODUCT_VERSION_);
261  xmlManager.addElement(this);
262 
263  QString retString = xmlManager.saveToString();
264 
265  return retString.toStdString();
266 }
267 
268 bool TYRectangularMaillage::fromXMLString(const std::string& sXMLString)
269 {
270  bool bRet = false;
271 
272  TYXMLManager xmlManager;
273  LPTYElementArray elements;
274  if (xmlManager.loadFromString(QString(sXMLString.c_str()), elements))
275  {
276  if (elements.size() == 1)
277  {
278  LPTYElement elt = elements[0];
279  if (strcmp(elt->getClassName(), "TYRectangularMaillage") == 0)
280  {
281  TYRectangularMaillage* pTmpMaillage =
282  static_cast<TYRectangularMaillage*>(elt.getRealPointer());
283  TYRectangularMaillage::operator=(*pTmpMaillage);
284  bRet = true;
285  }
286  }
287  }
288 
289  return bRet;
290 }
291 
293 {
296 }
297 
298 void TYRectangularMaillage::make(LPTYRectangle pRect, double densiteX, double densiteY)
299 {
300  OVector3D vecX, vecY;
301  unsigned long nbPtsX = 0, nbPtsY = 0;
302 
303  assert(pRect);
304 
305  // Reset
307 
308  // Param
309  _pRect = pRect;
310  setDensiteX(densiteX);
311  setDensiteY(densiteY);
312 
313  getDimensionsAndSteps(nbPtsX, nbPtsY, vecX, vecY);
314  _nbPointsX = nbPtsX;
315 
316  // Calcul du pt de depart pour le placement des points
317  OVector3D startPt = OVector3D(pRect->_pts[0]);
318 
319  _posLabel = startPt;
320 
321  // Scan Y
322  for (unsigned int iY = 0; iY < nbPtsY; iY++)
323  {
324  // Scan X
325  for (unsigned int iX = 0; iX < nbPtsX; iX++)
326  {
327  // Position du point
328  OPoint3D pos = startPt + (vecX * iX) + (vecY * iY);
329 
330  // Ajout du point au maillage
331  LPTYPointCalcul pPoint = new TYPointCalcul(pos);
332  pPoint->setSpectre(new TYSpectre());
333  addPointCalcul(pPoint);
334  }
335  }
336 
337  setIsGeometryModified(true);
338 }
339 
340 void TYRectangularMaillage::getDimensionsAndSteps(unsigned long& x, unsigned long& y, OVector3D& stepx,
341  OVector3D& stepy) const
342 {
343  assert(_pRect);
344 
345  // On cherche les vecteurs des cotes X et Y du rectangle
346  OVector3D vecX(_pRect->_pts[0], _pRect->_pts[1]);
347  OVector3D vecY(_pRect->_pts[0], _pRect->_pts[3]);
348 
349  // On calcul le nb de points en X et Y
350  unsigned long nbPtsX = (unsigned long)(_densiteX * vecX.norme());
351  unsigned long nbPtsY = (unsigned long)(_densiteY * vecY.norme());
352 
353  // On essaye de se rapprocher au mieux de la densite totale (H*V)
354  // (On veut au moins 1 point a l'interieur)
355  if ((nbPtsX * nbPtsY) != (_pRect->surface() * _densiteX * _densiteY))
356  {
357  nbPtsX ? nbPtsX : nbPtsX++;
358  nbPtsY ? nbPtsY : nbPtsY++;
359  }
360 
361  x = nbPtsX + 1;
362  y = nbPtsY + 1;
363 
364  // Calcul des vecteurs pas en X et Y (ecart entre chaque point)
365  stepx = vecX * (1.0 / (double)nbPtsX);
366  stepy = vecY * (1.0 / (double)nbPtsY);
367 }
368 
370 {
371  return x + y * _nbPointsX;
372 }
373 
374 void TYRectangularMaillage::getDimensions(int& x, int& y) const
375 {
376  unsigned long longx = 0, longy = 0;
377  OVector3D stepx, stepy;
378  getDimensionsAndSteps(longx, longy, stepx, stepy);
379  x = longx;
380  y = longy;
381 }
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 rectangulaire (fichier header)
outil IHM pour un maillage rectangulaire (fichier header)
TY_EXT_GRAPHIC_INST(TYRectangularMaillage)
TY_EXTENSION_INST(TYRectangularMaillage)
The 3D point class.
Definition: 3d.h:487
virtual const char * getClassName() const
Definition: TYElement.h:248
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:965
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:542
void setAllUses(void *allUses)
Definition: TYElement.h:935
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
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
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
void setSpectre(const LPTYSpectre spectre)
Set du spectre resultat d'un calcul donne.
virtual DOM_Element toXML(DOM_Element &domElement)
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
TYPoint _pts[4]
Sommets.
Definition: TYRectangle.h:278
virtual double surface() const
Classe de definition d'un maillage rectangulaire.
double _distancePointsCalculX
La distance entre 2 points de calcul consécutifs en X.
virtual DOM_Element toXML(DOM_Element &domElement)
bool fromXMLString(const std::string &sXMLString)
virtual int fromXML(DOM_Element domElement)
virtual ~TYRectangularMaillage()
Destructeur. Le destructeur de la classe TYRectangularMaillage.
double _distancePointsCalculY
La distance entre 2 points de calcul consécutifs en Y.
bool operator==(const TYRectangularMaillage &other) const
Operateur ==.
virtual void getDimensions(int &x, int &y) const
Return the dimensions in x and y.
void getDimensionsAndSteps(unsigned long &x, unsigned long &y, OVector3D &stepx, OVector3D &stepy) const
Renvoie le nombre de lignes et de colonnes du maillage.En fonction de ses dimensions en 3D et de la d...
double _nbPointsX
Numbers of point in row.
virtual std::string toString() const
void setDensiteY(double densiteY)
Fixe la densite de points de calcul en Y.
LPTYRectangle _pRect
Le rectangle associe a ce maillage.
bool operator!=(const TYRectangularMaillage &other) const
Operateur !=.
virtual int getIndexPtCalcul(int x, int y) const
Return the index.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
TYRectangularMaillage & operator=(const TYRectangularMaillage &other)
Operateur =.
void setDensiteX(double densiteX)
Fixe la densite de points de calcul en X.
double _densiteX
La densite de points de calcul en X.
double _densiteY
La densite de points de calcul en Y.
virtual void make(LPTYRectangle pRect, double densiteX=TY_MAILLAGE_DEFAULT_DENSITE, double densiteY=TY_MAILLAGE_DEFAULT_DENSITE)
Rempli la structure de points de calcul a partir d'un rectangle et de densites de points.
TYRectangularMaillage()
Constructeur. Le constructeur de la classe TYRectangularMaillage.
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