Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYLinearMaillage.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 
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  _densite = 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;
53  }
54  return *this;
55 }
56 
58 {
59  if (this != &other)
60  {
61  if (TYMaillage::operator!=(other))
62  {
63  return false;
64  }
65  if (!(_pSeg == other._pSeg))
66  {
67  return false;
68  }
69  if (!(_densite == other._densite))
70  {
71  return false;
72  }
73  }
74  return true;
75 }
76 
78 {
79  return !operator==(other);
80 }
81 
82 bool TYLinearMaillage::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
83 {
84  if (!TYMaillage::deepCopy(pOther, copyId))
85  {
86  return false;
87  }
88 
89  TYLinearMaillage* pOtherMaillage = (TYLinearMaillage*)pOther;
90 
91  _densite = pOtherMaillage->_densite;
92 
93  _pSeg->deepCopy(pOtherMaillage->_pSeg, copyId);
94 
95  return true;
96 }
97 
98 std::string TYLinearMaillage::toString() const
99 {
100  return "TYLinearMaillage";
101 }
102 
104 {
105  DOM_Element domNewElem = TYMaillage::toXML(domElement);
106 
107  TYXMLTools::addElementDoubleValue(domNewElem, "densite", _densite);
108 
109  _pSeg->toXML(domNewElem);
110 
111  for (unsigned int i = 0; i < _ptsCalcul.size(); i++)
112  {
113  _ptsCalcul[i]->getSpectre()->toXML(domNewElem);
114  }
115 
116  return domNewElem;
117 }
118 
120 {
121  TYMaillage::fromXML(domElement);
122 
123  bool densiteOk = false;
124  bool bOldDatas = false;
125 
126  LPTYSpectre pSpectre = new TYSpectre();
127  TYTabLPSpectre* compatibilityVector = new TYTabLPSpectre();
128 
129  DOM_Element elemCur;
130 
131  QDomNodeList childs = domElement.childNodes();
132  for (unsigned int i = 0; i < childs.length(); i++)
133  {
134  elemCur = childs.item(i).toElement();
135  TYXMLTools::getElementDoubleValue(elemCur, "densite", _densite, densiteOk);
136 
137  _pSeg->callFromXMLIfEqual(elemCur);
138 
139  // Old version : if we encounter spectra
140  if (pSpectre->callFromXMLIfEqual(elemCur))
141  {
142  bOldDatas = true;
143  compatibilityVector->push_back(pSpectre);
144  pSpectre = new TYSpectre();
145  }
146  }
147 
148  if (bOldDatas == true)
149  {
150  setAllUses((void*)compatibilityVector);
151  }
152  else
153  {
154  delete compatibilityVector;
155  }
156 
157  make(_pSeg, _densite);
159 
160  return 1;
161 }
162 
163 bool TYLinearMaillage::toXML(const std::string& sFilePath)
164 {
165  bool bRet = false;
166  QString fileName = QString(sFilePath.c_str());
167  int i = fileName.lastIndexOf('/');
168  QDir fileDirectory = QDir(fileName.mid(0, i));
169  if (!fileDirectory.exists())
170  {
171  fileDirectory.mkdir(fileName.mid(0, i));
172  }
173 
174  if (!fileName.isEmpty())
175  {
176  if (!fileName.endsWith(".xml"))
177  {
178  fileName += ".xml";
179  }
180  }
181  else
182  {
183  return false;
184  }
185 
186  TYXMLManager xmlManager;
187 
188  xmlManager.createDoc(TY_PRODUCT_XMLTAG_, TY_PRODUCT_VERSION_);
189  xmlManager.addElement(this);
190 
191  if (xmlManager.save(fileName) == 0)
192  {
193  bRet = true;
194  }
195 
196  return bRet;
197 }
198 
199 bool TYLinearMaillage::fromXML(const std::string& sFilePath)
200 {
201  bool bRet = false;
202  QString fileName = QString(sFilePath.c_str());
203 
204  if (fileName.isEmpty())
205  {
206  return false;
207  }
208 
209  TYXMLManager xmlManager;
210  LPTYElementArray elements;
211  if (xmlManager.load(fileName, elements))
212  {
213  if (elements.size() == 1)
214  {
215  LPTYElement elt = elements[0];
216  if (strcmp(elt->getClassName(), "TYLinearMaillage") == 0)
217  {
218  TYLinearMaillage* pTmpMaillage = static_cast<TYLinearMaillage*>(elt.getRealPointer());
219  TYLinearMaillage::operator=(*pTmpMaillage);
220  bRet = true;
221  }
222  }
223  }
224 
225  return bRet;
226 }
227 
229 {
230  TYXMLManager xmlManager;
231 
232  xmlManager.createDoc(TY_PRODUCT_XMLTAG_, TY_PRODUCT_VERSION_);
233  xmlManager.addElement(this);
234 
235  QString retString = xmlManager.saveToString();
236 
237  return retString.toStdString();
238 }
239 
240 bool TYLinearMaillage::fromXMLString(const std::string& sXMLString)
241 {
242  bool bRet = false;
243 
244  TYXMLManager xmlManager;
245  LPTYElementArray elements;
246  if (xmlManager.loadFromString(QString(sXMLString.c_str()), elements))
247  {
248  if (elements.size() == 1)
249  {
250  LPTYElement elt = elements[0];
251  if (strcmp(elt->getClassName(), "TYLinearMaillage") == 0)
252  {
253  TYLinearMaillage* pTmpMaillage = static_cast<TYLinearMaillage*>(elt.getRealPointer());
254  TYLinearMaillage::operator=(*pTmpMaillage);
255  bRet = true;
256  }
257  }
258  }
259 
260  return bRet;
261 }
262 
264 {
266 }
267 
268 void TYLinearMaillage::make(LPTYSegment pSeg, double densite)
269 {
270  assert(pSeg);
271 
272  // Reset
274 
275  // Param
276  _pSeg = pSeg;
277  _densite = densite;
278 
279  OVector3D vec(pSeg->_ptA, pSeg->_ptB);
280 
281  // On calcul le nb de points
282  int nbPts = (int)(densite * vec.norme());
283 
284  // Calcul du vecteur pas (ecart entre chaque point)
285  vec = vec * (1.0 / (double)nbPts);
286 
287  // Calcul du pt de depart pour le placement des points
288  OVector3D startPt = OVector3D(pSeg->_ptA);
289 
290  // Scan
291  for (int i = 0; i < nbPts; i++)
292  {
293  // Position du point
294  OPoint3D pos = startPt + (vec * i);
295 
296  // Ajout du point au maillage
297  LPTYPointCalcul pPoint = new TYPointCalcul(pos);
298  pPoint->setSpectre(new TYSpectre());
299  addPointCalcul(pPoint);
300  }
301 
302  setIsGeometryModified(true);
303 }
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:345
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:249
OPoint3D _ptA
Point A of the segment.
Definition: 3d.h:1201
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1203
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:966
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
void setAllUses(void *allUses)
Definition: TYElement.h:936
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.
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)
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