2 // C++ : Classe Document : methodes internes
4 #include "HexDocument.hxx"
6 #include "HexEltBase.hxx"
7 #include "HexVertex.hxx"
10 #include "HexHexa.hxx"
12 #include "HexElements.hxx"
14 #include "HexVector.hxx"
15 #include "HexCylinder.hxx"
16 #include "HexPipe.hxx"
17 #include "HexMatrix.hxx"
18 #include "HexCloner.hxx"
19 #include "HexPropagation.hxx"
22 #include "HexXmlWriter.hxx"
23 #include "HexXmlTree.hxx"
27 // ======================================================== get_coords
28 int get_coords (const string& chaine, double& x, double& y, double& z)
30 // int nv = sscanf (chaine.c_str (), "%lg %lg %lg", &x, &y, &z);
31 cpchar buffer = chaine.c_str ();
32 int nv = sscanf (buffer, "%lg %lg %lg", &x, &y, &z);
33 if (nv!=3) return HERR;
36 // ======================================================== get_values
37 int get_values (const string& chaine, int size, int table[])
39 int lg = chaine.size();
44 for (int nc=0 ; nc<lg ; nc++)
46 char car = chaine[nc];
47 if (car >= '0' && car <= '9')
49 val = 10* val + car - '0';
67 // ======================================================== get_int
68 int get_int (const string& chaine)
71 get_values (chaine, 1, val);
74 // ======================================================== loadXml
75 int Document::loadXml ()
78 xml.parseFile (doc_name + ".xml");
81 vector <Vertex*> t_vertex;
82 vector <Edge*> t_edge;
83 vector <Quad*> t_quad;
84 vector <Hexa*> t_hexa;
87 XmlTree* rubrique = xml.findChild ("ListVertices");
88 int nbrelts = rubrique->getNbrChildren ();
89 t_vertex.resize (nbrelts);
91 for (int nro=0 ; nro < nbrelts ; nro++)
93 XmlTree* node = rubrique->getChild (nro);
95 const string& nom = node->findValue ("id");
96 const string& coords = node->findValue ("coord");
97 get_coords (coords, px, py, pz);
99 int nver = get_int (nom);
100 t_vertex [nver] = addVertex (px, py, pz);
105 rubrique = xml.findChild ("ListEdges");
106 nbrelts = rubrique->getNbrChildren ();
107 t_edge.resize (nbrelts);
109 for (int nro=0 ; nro < nbrelts ; nro++)
111 XmlTree* node = rubrique->getChild (nro);
112 const string& nom = node->findValue ("id");
113 const string& vertices = node->findValue ("vertices");
114 get_values (vertices, V_TWO, table);
116 int ned = get_int (nom);
117 t_edge [ned] = new Edge (t_vertex [table[0]], t_vertex [table[1]]);
121 rubrique = xml.findChild ("ListQuads");
122 nbrelts = rubrique->getNbrChildren ();
123 t_quad.resize (nbrelts);
125 for (int nro=0 ; nro < nbrelts ; nro++)
127 XmlTree* node = rubrique->getChild (nro);
128 const string& nom = node->findValue ("id");
129 const string& edges = node->findValue ("edges");
130 get_values (edges, QUAD4, table);
132 int nquad = get_int (nom);
133 t_quad [nquad] = new Quad (t_edge [table[0]], t_edge [table[1]],
134 t_edge [table[2]], t_edge [table[3]]);
138 rubrique = xml.findChild ("ListHexas");
139 nbrelts = rubrique->getNbrChildren ();
140 t_hexa.resize (nbrelts);
142 for (int nro=0 ; nro < nbrelts ; nro++)
144 XmlTree* node = rubrique->getChild (nro);
145 const string& nom = node->findValue ("id");
146 const string& quads = node->findValue ("quads");
147 get_values (quads, HQ_MAXI, table);
149 int nhexa = get_int (nom);
150 t_hexa [nhexa] = new Hexa (t_quad [table[0]], t_quad [table[1]],
151 t_quad [table[2]], t_quad [table[3]],
152 t_quad [table[4]], t_quad [table[5]]);
159 // ======================================================== renumeroter
160 void Document::renumeroter ()
163 // -- 1) Raz numerotation precedente
164 markAll (NO_COUNTED);
166 // ======================================================== saveFile
167 int Document::saveFile ()
169 // -- 1) Raz numerotation precedente
174 doc_modified = false;
176 xml.openXml (doc_name);
177 xml.openMark ("Document");
178 xml.addAttribute ("name", doc_name);
181 cpchar balise [] = {"ListXXX",
182 "ListVertices", "ListEdges", "ListQuads", "ListHexas", "ListXXXX" };
184 for (int type=EL_VERTEX ; type <= EL_HEXA ; type++)
186 xml.addMark (balise [type]);
187 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
190 if (elt !=NULL && elt->isHere())
193 xml.closeMark (true);
196 xml.addMark ("ListDicretizationLaws");
197 for (int nro=0 ; nro<nbr_laws ; nro++)
198 doc_laws [nro]->saveXml (xml);
199 xml.closeMark (true);
201 xml.addMark ("ListPropagations");
202 for (int nro=0 ; nro<nbr_propagations ; nro++)
203 doc_propagation[nro]->saveXml (xml);
210 // ======================================================== markAll
211 void Document::markAll (int marque, int type)
213 int debut = EL_VERTEX;
215 if (type>=0 && type<EL_MAXI)
218 for (int type=debut ; type <= fin ; type++)
220 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
222 elt->setMark (marque);
225 // ====================================================== saveVtk
226 int Document::saveVtk (cpchar nomfic)
228 // -- 1) Raz numerotation precedente
229 markAll (NO_COUNTED, EL_VERTEX);
234 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
237 Hexa* cell = static_cast <Hexa*> (elt);
238 if (cell!=NULL && cell->isHere())
241 nbnodes += cell->countNodes ();
245 pfile vtk = fopen (nomfic, "w");
246 fprintf (vtk, "# vtk DataFile Version 3.1\n");
247 fprintf (vtk, "%s \n", nomfic);
248 fprintf (vtk, "ASCII\n");
249 fprintf (vtk, "DATASET UNSTRUCTURED_GRID\n");
250 fprintf (vtk, "POINTS %d float\n", nbnodes);
254 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
257 Hexa* cell = static_cast <Hexa*> (elt);
258 if (cell!=NULL && cell->isHere())
259 cell->printNodes (vtk, nronode);
263 fprintf (vtk, "CELLS %d %d\n", nbcells, nbcells*(HV_MAXI+1));
265 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
268 Hexa* cell = static_cast <Hexa*> (elt);
269 if (cell!=NULL && cell->isHere())
270 cell->printHexa (vtk);
273 fprintf (vtk, "CELL_TYPES %d\n", nbcells);
274 for (int nro=0 ; nro<nbcells ; nro++)
275 fprintf (vtk, "%d\n", HE_MAXI);
277 fprintf (vtk, "POINT_DATA %d \n", nbnodes);
278 fprintf (vtk, "SCALARS A float\n");
279 fprintf (vtk, "LOOKUP_TABLE default\n");
281 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
284 Hexa* cell = static_cast <Hexa*> (elt);
285 if (cell!=NULL && cell->isHere())
286 cell->colorNodes (vtk);
292 // ====================================================== purge
293 void Document::purge ()
295 purge_elements = true;
296 // ------------------- Raz marques
299 // ------------------- Marquage elements utilises
300 for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
303 Hexa* cell = static_cast <Hexa*> (elt);
304 if (cell!=NULL && cell->isHere())
305 cell->markElements (IS_USED);
307 // ------------------- Elimination elements inutilises
308 for (int type=EL_VERTEX ; type <= EL_QUAD ; type++)
310 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
313 if (elt->getMark () == NO_USED)
317 // ------------------- Sortie elements inutilises
319 EltBase* trash = doc_last_elt [EL_REMOVED];
321 for (int type=EL_VERTEX ; type <= EL_HEXA ; type++)
323 doc_nbr_elt [type] = 0;
324 EltBase* last = doc_first_elt [type];
325 for (EltBase* elt = last->next (); elt!=NULL; elt = last->next())
329 doc_nbr_elt [type] ++;
334 last -> setNext (elt -> next());
335 trash -> setNext (elt);
337 trash -> setNext (NULL);
340 doc_last_elt [type] = last;
343 doc_last_elt [EL_REMOVED] = trash;
346 // ======================================================== majReferences
347 void Document::majReferences ()
349 maj_connection = false;
351 for (int type=EL_VERTEX ; type <= EL_QUAD ; type++)
353 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
356 elt->razReferences ();
360 for (int type=EL_EDGE ; type <= EL_HEXA ; type++)
362 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
366 elt->majReferences ();
370 // ======================================================== dump
371 void Document::dump ()
373 cpchar nom_type [] = { "Elments non classes",
374 "Sommets", "Aretes", "Faces", "Hexaedres", "Elements detruits" };
376 for (int type=EL_VERTEX ; type <= EL_HEXA ; type++)
379 printf (" ++++ Liste des %s\n", nom_type[type]);
382 for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
389 printf (" ++++ End od dump\n");
391 // ======================================================== putError
392 void Document::putError (cpchar mess, cpchar info1, cpchar info2)
395 printf (" ********************************************************** \n");
396 printf (" **** HexaBlocks Error nro %d :\n", nbr_errors);
398 printf (mess, info1, info2);
401 printf (" ********************************************************** \n");