Salome HOME
7694d98f136aaa0e57d66b6357a2f33bbcd23618
[modules/hexablock.git] / src / HEXABLOCK / HexDocument_Xml.cxx
1
2 // C++ : Classe Document : methodes internes
3
4 // Copyright (C) 2009-2023  CEA, EDF
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "HexDocument.hxx"
23 // #include <Basics_DirUtils.hxx>   
24 #include <cstdlib>               // Pour atoi et atof
25
26 #include "Hex.hxx"
27 #include "HexVertex.hxx"
28 #include "HexEdge.hxx"
29 #include "HexQuad.hxx"
30 #include "HexHexa.hxx"
31
32 #include "HexElements.hxx"
33
34 #include "HexVector.hxx"
35 #include "HexMatrix.hxx"
36 #include "HexCloner.hxx"
37 #include "HexPropagation.hxx"
38 #include "HexLaw.hxx"
39 #include "HexGroup.hxx"
40
41 #include "HexNewShape.hxx"
42 #include "HexVertexShape.hxx"
43 #include "HexEdgeShape.hxx"
44 #include "HexFaceShape.hxx"
45
46 #include "HexXmlWriter.hxx"
47 #include "HexXmlTree.hxx"
48 #include "HexGlobale.hxx"
49
50 BEGIN_NAMESPACE_HEXA
51
52 // ======================================================== get_coords
53 int get_coords (const std::string& chaine, double& x, double& y, double& z)
54 {
55    // int nv = sscanf (chaine.c_str (), "%lg %lg %lg", &x, &y, &z);
56    cpchar buffer = chaine.c_str ();
57    int nv = sscanf (buffer, "%lg %lg %lg", &x, &y, &z);
58    if (nv!=3) return HERR;
59    return HOK;
60 }
61 // ======================================================== get_coords
62 int get_coords (const std::string& chaine, double& x, double& y)
63 {
64    cpchar buffer = chaine.c_str ();
65    int nv = sscanf (buffer, "%lg %lg", &x, &y);
66    if (nv!=2) return HERR;
67    return HOK;
68 }
69 // ======================================================== parse_name
70 int parse_name (XmlTree* node, const std::string& nom, EltBase* elt)
71 {
72    int lg    = nom.size();
73    int nroid = 0;
74    for (int nc=1 ; nc<lg ; nc++)
75        nroid = 10*nroid + nom[nc] - '0';
76
77    elt->setId (nroid);
78
79    const  std::string& name = node->findValue ("name");
80    if (name=="")
81       return HERR;
82
83    elt->setName (name);
84    return HOK;
85 }
86 // ======================================================== get_names
87 void get_names (const std::string& chaine, int size, std::vector<std::string>& table)
88 {
89    table.clear ();
90    int    lg    = chaine.size();
91    std::string mot   = "";
92    bool encours = false;
93
94    for (int nc=0 ; nc<lg ; nc++)
95        {
96        char car  = chaine[nc];
97        if (isalnum (car))
98           {
99           mot += car;
100           encours = true;
101           }
102        else if (encours)
103           {
104           table.push_back (mot);
105           encours = false;
106           mot     = "";
107           }
108        }
109
110    if (encours)
111       table.push_back (mot);
112 }
113 // ======================================================== count_children
114 int count_children (XmlTree* dad)
115 {
116    int    nbre = dad==NULL ? 0 : dad->getNbrChildren ();
117    return nbre;
118 }
119 // ======================================================== loadXml
120 int Document::loadXml (cpchar ficname)
121 {
122    XmlTree xml("");
123    std::string filename = ficname;
124    //el_name         = Kernel_Utils::GetBaseName ((pchar)ficname);
125    make_basename (ficname, el_name);
126
127    static const int NbExt = 3;
128    static cpchar t_ext [NbExt] = { ".xml", ".XML", ".Xml" };
129    size_t ici   = 0;
130    bool   noext = true;
131    for (int nx = 0; nx < NbExt && noext ; nx++)
132        {
133        ici   = el_name.rfind (t_ext[nx]);
134        noext = ici < 0 || ici > el_name.size();
135        }
136
137    if (noext)
138       filename += ".xml";
139    else
140       el_name.erase (ici, 4);
141
142    int ier = xml.parseFile (filename);
143    if (ier!=HOK)
144       return ier;
145
146    ier = parseXml (xml);
147    return ier;
148 }
149 // ======================================================== setXml
150 int Document::setXml (cpchar flux)
151 {
152    int posit = 0;
153    int ier   = setXml (flux, posit);
154    return ier;
155 }
156 // ======================================================== setXml
157 int Document::setXml (cpchar flux, int& posit)
158 {
159    XmlTree xml("");
160
161    int ier = xml.parseStream (flux, posit);
162    if (ier!=HOK)
163       return ier;
164
165    ier = parseXml (xml);
166    if (ier==HOK)
167       doc_saved = true;
168
169    return ier;
170 }
171 // ======================================================== parseXml
172 int Document::parseXml (XmlTree& xml)
173 {
174    // xml.dump ();
175
176    std::map <std::string, Vertex*> t_vertex;
177    std::map <std::string, Edge*>   t_edge;
178    std::map <std::string, Quad*>   t_quad;
179    std::map <std::string, Hexa*>   t_hexa;
180    std::map <std::string, Vector*> t_vector;
181    std::vector <std::string> tname;
182
183    const  std::string& version = xml.findValue ("version");
184    if (version == "")
185        {
186        std::cout << " **** Format du fichier XML perime"
187                  << std::endl;
188        return HERR;
189        }
190    const  std::string& name = xml.findValue ("name");
191    if (name != el_name)
192        setName (name.c_str());
193
194    parseShapes (xml);
195
196    XmlTree* rubrique = xml.findChild ("ListVertices");
197    int nbrelts       = count_children (rubrique);
198
199    Vertex* vertex = NULL;
200    for (int nro=0 ; nro < nbrelts ; nro++)
201        {
202        XmlTree* node = rubrique->getChild (nro);
203        const std::string& type = node->getName();
204        double px, py, pz;
205        if (type=="Vertex")
206           {
207           const  std::string& nom    = node->findValue ("id");
208           const  std::string& coords = node->findValue ("coord");
209           get_coords (coords, px, py, pz);
210
211           vertex = addVertex (px, py, pz);
212           parse_name (node, nom, vertex);
213           t_vertex [nom] = vertex;
214           }
215        else if (type=="Asso")
216           {
217           parseAssociation (node, vertex);
218           }
219        }
220
221    rubrique = xml.findChild ("ListEdges");
222    nbrelts  = count_children (rubrique);
223    Edge* edge = NULL;
224
225    for (int nro=0 ; nro < nbrelts ; nro++)
226        {
227        XmlTree*      node = rubrique->getChild (nro);
228        const std::string& type = node->getName();
229        if (type=="Edge")
230           {
231           const  std::string& nom      = node->findValue ("id");
232           const  std::string& vertices = node->findValue ("vertices");
233           get_names (vertices, V_TWO, tname);
234           edge = new Edge (t_vertex [tname[0]], t_vertex [tname[1]]);
235           t_edge [nom] = edge;
236           parse_name (node, nom, edge);
237           }
238        else if (type=="Asso")
239           {
240           parseAssociation (node, edge);
241           }
242        }
243
244    rubrique = xml.findChild ("ListQuads");
245    nbrelts  = count_children (rubrique);
246    Quad* quad = NULL;
247
248    for (int nro=0 ; nro < nbrelts ; nro++)
249        {
250        XmlTree*      node = rubrique->getChild (nro);
251        const std::string& type = node->getName();
252        if (type=="Quad")
253           {
254           const std::string& nom   = node->findValue ("id");
255           const std::string& edges = node->findValue ("edges");
256           get_names (edges, V_TWO, tname);
257
258           quad = new Quad (t_edge [tname[0]], t_edge [tname[1]],
259                            t_edge [tname[2]], t_edge [tname[3]]);
260           t_quad [nom] = quad;
261           parse_name (node, nom, quad);
262           }
263        else if (type=="Asso")
264           {
265           parseAssociation (node, quad);
266           }
267        }
268
269    rubrique = xml.findChild ("ListHexas");
270    nbrelts  = count_children (rubrique);
271
272    for (int nro=0 ; nro < nbrelts ; nro++)
273        {
274        XmlTree* node = rubrique->getChild (nro);
275        const  std::string& nom   = node->findValue ("id");
276        const  std::string& quads = node->findValue ("quads");
277        get_names (quads, V_TWO, tname);
278
279        Hexa* hexa =  new Hexa (t_quad [tname[0]], t_quad [tname[1]],
280                                 t_quad [tname[2]], t_quad [tname[3]],
281                                 t_quad [tname[4]], t_quad [tname[5]]);
282        t_hexa [nom] = hexa;
283        parse_name (node, nom, hexa);
284        }
285
286    rubrique = xml.findChild ("ListVectors");
287    nbrelts  = count_children (rubrique);
288
289    for (int nro=0 ; nro < nbrelts ; nro++)
290        {
291        XmlTree* node = rubrique->getChild (nro);
292        double px, py, pz;
293        const  std::string& nom    = node->findValue ("id");
294        const  std::string& coords = node->findValue ("coord");
295        get_coords (coords, px, py, pz);
296
297        Vector* vector = addVector (px, py, pz);
298        t_vector [nom] = vector;
299        parse_name (node, nom, vector);
300        }
301
302    rubrique = xml.findChild ("ListDicretizationLaws");
303    nbrelts  = count_children (rubrique);
304
305    for (int nro=0 ; nro < nbrelts ; nro++)
306        {
307        XmlTree* node = rubrique->getChild (nro);
308        const  std::string& id    = node->findValue ("id");
309        const  std::string& kind  = node->findValue ("kind");
310        const  std::string& nodes = node->findValue ("nodes");
311        const  std::string& coeff = node->findValue ("coeff");
312
313        int    nbnodes = atoi (nodes.c_str());
314        double koeff   = atof (coeff.c_str());
315        if (id != "DefaultLaw")
316           {
317           Law*   law  = addLaw (id.c_str(), nbnodes);
318           law->setCoefficient (koeff);
319           law->setKind (kind.c_str());
320           }
321        }
322
323    rubrique = xml.findChild ("ListPropagations");
324    nbrelts  = count_children (rubrique);
325
326    for (int nro=0 ; nro < nbrelts ; nro++)
327        {
328        XmlTree* node = rubrique->getChild (nro);
329        const  std::string& nmedge  = node->findValue ("edge");
330        const  std::string& nmlaw   = node->findValue ("law");
331        //  const  std::string& nmway   = node->findValue ("way");
332
333        edge     = t_edge [nmedge];
334        Law* law = findLaw (nmlaw.c_str());
335        //  bool way = nmway == "true";
336
337        if (edge != NULL)
338            edge->setLaw (law);
339        }
340
341    rubrique = xml.findChild ("ListGroups");
342    int nbrgroups  = count_children (rubrique);
343
344    for (int nro=0 ; nro < nbrgroups ; nro++)
345        {
346        XmlTree*  ndgroup = rubrique->getChild (nro);
347        XmlTree*  node    = ndgroup ->getChild (0);
348        const  std::string& nom   = node->findValue ("name");
349        const  std::string& ckind = node->findValue ("kind");
350
351        EnumGroup kind   = Group::getKind (ckind);
352        Group*    groupe = addGroup (nom.c_str(), kind);
353        EnumElt   type   = groupe->getTypeElt ();
354
355        nbrelts = count_children (ndgroup);
356        for (int nelt=1 ; nelt < nbrelts ; nelt++)
357            {
358            node = ndgroup ->getChild (nelt);
359            const std::string& id = node->findValue ("id");
360            switch (type)
361               {
362               case EL_HEXA : groupe->addElement (t_hexa [id]);
363                    break;
364               case EL_QUAD : groupe->addElement (t_quad [id]);
365                    break;
366               case EL_EDGE : groupe->addElement (t_edge [id]);
367                    break;
368               case EL_VERTEX :
369               default      : groupe->addElement (t_vertex [id]);
370                    break;
371               }
372            }
373        }
374
375
376    return HOK;
377 }
378 // ======================================================== save
379 int Document::save (const char* ficxml)
380 {
381    DumpStart ("save", ficxml);
382
383    if (doc_xml==NULL)
384        doc_xml = new XmlWriter ();
385
386    int ier  = doc_xml->setFileName (ficxml);
387    if (ier == HOK)
388        ier =  genXml ();
389
390    DumpReturn (ier);
391    return ier;
392 }
393 // ======================================================== appendXml
394 int Document::appendXml (pfile fstudy)
395 {
396    if (doc_xml==NULL)
397        doc_xml = new XmlWriter ();
398
399    doc_xml->setFile (fstudy);
400
401    int    ier = genXml ();
402    return ier;
403 }
404 // ======================================================== getXml
405 cpchar Document::getXml ()
406 {
407    if (doc_xml==NULL)
408        doc_xml = new XmlWriter ();
409
410    doc_xml->setStream ();
411    int ier = genXml ();
412    if (ier!=HOK)
413       return NULL;
414
415    return doc_xml->getXml ();
416 }
417 // ======================================================== genXml
418 int Document::genXml ()
419 {
420    const int HexVersion = 1;
421                                        // -- 1) Raz numerotation precedente
422    markAll (NO_COUNTED);
423    if (maj_propagation)
424        majPropagation ();
425
426    if (doc_xml==NULL)
427        doc_xml = new XmlWriter ();
428
429    doc_xml->startXml ();
430    doc_xml->openMark ("Document");
431    doc_xml->addAttribute ("name",    el_name);
432    doc_xml->addAttribute ("version", HexVersion);
433    doc_xml->endMark ();
434
435    cpchar balise [] = {"ListXXXX",
436           "ListVertices", "ListEdges", "ListQuads", "ListHexas", "ListVectors",
437           "ListXXXX" };
438
439    for (int type=EL_VERTEX ; type <= EL_VECTOR ; type++)
440        {
441        doc_xml->addMark (balise [type]);
442        for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
443                      elt = elt->next())
444            {
445            if (elt !=NULL && elt->isHere())
446               elt->saveXml (doc_xml);
447            }
448        doc_xml->closeMark (true);
449        }
450
451    doc_xml->addMark ("ListDicretizationLaws");
452    for (int nro=0 ; nro<nbr_laws ; nro++)
453        doc_laws [nro]->saveXml (doc_xml);
454    doc_xml->closeMark (true);
455
456    doc_xml->addMark ("ListPropagations");
457    for (int nro=0 ; nro<nbr_propagations ; nro++)
458        doc_propagation[nro]->saveXml (doc_xml);
459    doc_xml->closeMark (true);
460
461    int nombre = countGroup();
462    doc_xml->addMark ("ListGroups");
463    for (int nro=0 ; nro<nombre ; nro++)
464        doc_group[nro]->saveXml (doc_xml);
465    doc_xml->closeMark (true);
466
467    nombre = countShape ();
468    doc_xml->addMark ("ListShapes");
469    for (int nro=0 ; nro<nombre ; nro++)
470        doc_tab_shape[nro]->saveXml (doc_xml);
471    doc_xml->closeMark ();
472
473    doc_xml->closeMark ();
474    doc_xml->closeXml  ();
475    doc_saved = true;
476    return  HOK;
477 }
478 // ======================================================== markAll
479 void Document::markAll (int marque, int type)
480 {
481    int debut = EL_VERTEX;
482    int fin   = EL_HEXA;
483    if (type>=0 && type<EL_MAXI)
484       debut = fin = type;
485
486    for (int type=debut ; type <= fin ; type++)
487        {
488        for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
489                      elt = elt->next())
490            elt->setMark (marque);
491        }
492 }
493 // ====================================================== saveVtk
494 int Document::saveVtk0 (cpchar nomfic)
495 {
496                                            // -- 1) Raz numerotation precedente
497    markAll (NO_COUNTED, EL_VERTEX);
498
499    int nbnodes = 0;
500    int nbcells = 0;
501
502    for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
503                  elt = elt->next())
504        {
505        Hexa* cell = static_cast <Hexa*> (elt);
506        if (cell!=NULL && cell->isHere())
507           {
508           nbcells ++;
509           nbnodes += cell->countNodes ();
510           }
511        }
512
513    pfile vtk = fopen (nomfic, "w");
514    if (vtk==NULL)
515       {
516       std::cout << " ****" << std::endl;
517       std::cout << " **** Document::saveVtk : " << std::endl;
518       std::cout << " **** Can't open file "     << std::endl;
519       std::cout << " ****" << std::endl;
520
521       }
522    fprintf (vtk, "# vtk DataFile Version 3.1\n");
523    fprintf (vtk, "%s \n", nomfic);
524    fprintf (vtk, "ASCII\n");
525    fprintf (vtk, "DATASET UNSTRUCTURED_GRID\n");
526    fprintf (vtk, "POINTS %d float\n", nbnodes);
527
528                                            // -- 2) Les noeuds
529    int nronode = 0;
530    for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
531                  elt = elt->next())
532        {
533        Hexa* cell = static_cast <Hexa*> (elt);
534        if (cell!=NULL && cell->isHere())
535           cell->printNodes (vtk, nronode);
536        }
537                                            // -- 2) Les hexas
538
539    fprintf (vtk, "CELLS %d %d\n", nbcells, nbcells*(HV_MAXI+1));
540
541    for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
542                  elt = elt->next())
543        {
544        Hexa* cell = static_cast <Hexa*> (elt);
545        if (cell!=NULL && cell->isHere())
546           cell->printHexa (vtk);
547        }
548
549    fprintf (vtk, "CELL_TYPES %d\n", nbcells);
550    for (int nro=0 ; nro<nbcells ; nro++)
551        fprintf (vtk, "%d\n", HE_MAXI);
552
553    fprintf (vtk, "POINT_DATA %d \n", nbnodes);
554    fprintf (vtk, "SCALARS A float\n");
555    fprintf (vtk, "LOOKUP_TABLE default\n");
556
557    for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
558                  elt = elt->next())
559        {
560        Hexa* cell = static_cast <Hexa*> (elt);
561        if (cell!=NULL && cell->isHere())
562           cell->colorNodes (vtk);
563        }
564
565    fclose (vtk);
566    return HOK;
567 }
568
569 // ====================================================== saveVtk
570 // ==== Nouvelle formule qui conserve les numeros de vertex
571 int Document::saveVtk (cpchar nomfic)
572 {
573    DumpStart ("saveVtk", nomfic);
574    int nbnodes = doc_nbr_elt [EL_VERTEX];
575    int nbcells = countHexa ();
576
577    pfile vtk = fopen (nomfic, "w");
578    if (vtk==NULL)
579       {
580       std::cout << " ****" << std::endl;
581       std::cout << " **** Document::saveVtk : " << std::endl;
582       std::cout << " **** Can't open file "     << std::endl;
583       std::cout << " ****" << std::endl;
584
585       }
586    fprintf (vtk, "# vtk DataFile Version 3.1\n");
587    fprintf (vtk, "%s \n", nomfic);
588    fprintf (vtk, "ASCII\n");
589    fprintf (vtk, "DATASET UNSTRUCTURED_GRID\n");
590    fprintf (vtk, "POINTS %d float\n", nbnodes);
591
592                                            // -- 1) Les noeuds
593    Real3 koord;
594    static const double minvtk = 1e-30;
595 #define Koord(p) koord[p]<minvtk && koord[p]>-minvtk ? 0 : koord[p]
596
597    for (EltBase* elt = doc_first_elt[EL_VERTEX]->next (); elt!=NULL;
598                  elt = elt->next())
599        {
600        Vertex* node = static_cast <Vertex*> (elt);
601        if (node->isHere())
602           {
603           node->getPoint (koord);
604           fprintf (vtk, "%g %g %g\n", Koord(dir_x), Koord(dir_y), Koord(dir_z));
605           }
606        else
607           fprintf (vtk, "0 0 0\n");
608        }
609                                            // -- 2) Les hexas
610
611    fprintf (vtk, "CELLS %d %d\n", nbcells, nbcells*(HV_MAXI+1));
612
613    for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
614                  elt = elt->next())
615        {
616        Hexa* cell = static_cast <Hexa*> (elt);
617        if (cell!=NULL && cell->isHere())
618           cell->printHexaVtk (vtk);
619        }
620
621    fprintf (vtk, "CELL_TYPES %d\n", nbcells);
622    for (int nro=0 ; nro<nbcells ; nro++)
623        fprintf (vtk, "%d\n", HE_MAXI);
624
625    fprintf (vtk, "POINT_DATA %d \n", nbnodes);
626    fprintf (vtk, "SCALARS A float\n");
627    fprintf (vtk, "LOOKUP_TABLE default\n");
628    for (EltBase* elt = doc_first_elt[EL_VERTEX]->next (); elt!=NULL;
629                  elt = elt->next())
630        {
631        Vertex* node = static_cast <Vertex*> (elt);
632        if (node->isHere())
633           {
634           double color = 100*(node->getScalar()+1);
635           fprintf (vtk, "%g\n", color);
636           }
637        else 
638           fprintf (vtk, "100\n");
639        }
640
641    fclose (vtk);
642    DumpReturn (HOK);
643    return HOK;
644 }
645 // ====================================================== purge
646 void Document::purge ()
647 {
648    purge_elements = false;
649                        // ------------------- Raz marques
650    markAll (NO_USED);
651
652                        // ------------------- Marquage elements utilises
653    for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
654                  elt = elt->next())
655        {
656        Hexa* cell = static_cast <Hexa*> (elt);
657        if (cell!=NULL && cell->isHere())
658           cell->markElements (IS_USED);
659        }
660                        // ------------------- Elimination elements inutilises
661    for (int type=EL_VERTEX ; type <= EL_QUAD ; type++)
662        {
663        for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
664                      elt = elt->next())
665            {
666            if (elt->getMark  () == NO_USED)
667                elt->suppress ();
668            }
669        }
670                        // ------------------- Sortie elements inutilises
671
672 /* ****************************************************************
673    EltBase* trash = doc_last_elt [EL_REMOVED];
674
675    for (int type=EL_VERTEX ; type <= EL_HEXA ; type++)
676        {
677        doc_nbr_elt [type] = 0;
678        EltBase* last = doc_first_elt [type];
679        for (EltBase* elt = last->next (); elt!=NULL; elt = last->next())
680            {
681            if (elt->isHere  ())
682                {
683                doc_nbr_elt  [type] ++;
684                last = elt;
685                }
686            else
687                {
688                last  -> setNext (elt -> next());
689                trash -> setNext (elt);
690                trash = elt;
691                trash -> setNext (NULL);
692                }
693            }
694        doc_last_elt [type] = last;
695        }
696
697    doc_last_elt [EL_REMOVED] = trash;
698    **************************************************************** */
699    update ();
700 }
701 // ======================================================== majReferences
702 void Document::majReferences ()
703 {
704    maj_connection = false;
705
706    for (int type=EL_VERTEX ; type <= EL_QUAD ; type++)
707        {
708        for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
709                      elt = elt->next())
710            {
711            elt->razReferences ();
712            }
713        }
714
715    for (int type=EL_EDGE ; type <= EL_HEXA ; type++)
716        {
717        for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
718                      elt = elt->next())
719            {
720            if (elt->isHere ())
721                elt->majReferences ();
722            }
723        }
724 }
725 // ======================================================== dump
726 void Document::dump ()
727 {
728    cpchar nom_type [] = { "Elments non classes",
729           "Sommets", "Aretes", "Faces", "Hexaedres", "Elements detruits" };
730
731    for (int type=EL_VERTEX ; type <= EL_HEXA ; type++)
732        {
733        printf ("\n");
734        printf (" ++++ Liste des %s\n", nom_type[type]);
735        printf ("\n");
736
737        for (EltBase* elt = doc_first_elt[type]->next (); elt!=NULL;
738                      elt = elt->next())
739            {
740            if (elt->isHere())
741                elt->dump ();
742            }
743        }
744
745    printf (" ++++ End od dump\n");
746 }
747 // ======================================================== putError
748 void Document::putError (cpchar mess, cpchar info1, cpchar info2)
749 {
750      nbr_errors ++;
751      printf (" ********************************************************** \n");
752      printf (" ****  HexaBlocks Error nro %d :\n", nbr_errors);
753      printf (" **** ");
754      printf (mess, info1, info2);
755      printf ("\n");
756      printf (" **** \n");
757      printf (" ********************************************************** \n");
758 }
759 // ======================================================== hputError
760 void Document::hputError (cpchar mess, EltBase* e1, EltBase* e2)
761 {
762    char name1 [32] = { 0 };
763    char name2 [32] = { 0 };
764
765    if (e1!=NULL) e1->getName (name1);
766    if (e2!=NULL) e2->getName (name2);
767
768    putError (mess, name1, name2);
769 }
770 // ======================================================== parseSubShape
771 SubShape* Document::parseSubShape (XmlTree* node)
772 {
773    const std::string& name  = node->findValue   ("shape");
774    int           subid = node->findInteger ("subid");
775    NewShape*     shape = findShape (name);
776    if (shape==NULL)
777        return NULL;
778
779    SubShape* sub_shape = shape->findSubShape (subid);
780    return    sub_shape;
781 }
782 // ======================================================== parseAssociation (v)
783 void Document::parseAssociation (XmlTree* node, Vertex* vertex)
784 {
785    SubShape* shape = parseSubShape (node);
786    if (shape==NULL || vertex==NULL)
787        return;
788
789    if (shape->getDim()!=0)
790       return;
791    VertexShape* vshape = static_cast <VertexShape*> (shape);
792    vertex->setAssociation (vshape);
793 }
794 // ======================================================== parseAssociation (e)
795 void Document::parseAssociation (XmlTree* node, Edge* edge)
796 {
797    SubShape* shape = parseSubShape (node);
798    if (shape==NULL || edge==NULL)
799        return;
800
801    if (shape->getDim()!=1)
802       return;
803
804    const  std::string& inter = node->findValue ("interval");
805    double pdeb, pfin;
806    get_coords (inter, pdeb, pfin);
807
808    EdgeShape* line = static_cast <EdgeShape*> (shape);
809    edge->addAssociation (line, pdeb, pfin);
810 }
811 // ======================================================== parseAssociation (q)
812 void Document::parseAssociation (XmlTree* node, Quad* quad)
813 {
814    SubShape* shape = parseSubShape (node);
815    if (shape==NULL || quad==NULL)
816        return;
817
818    if (shape->getDim()!=2)
819       return;
820    FaceShape* face = static_cast <FaceShape*> (shape);
821    quad->addAssociation (face);
822 }
823 // ======================================================== parseShapes
824 void Document::parseShapes (XmlTree& root)
825 {
826    XmlTree* rubrique = root.findChild ("ListShapes");
827    int nbrelts       = count_children (rubrique);
828
829    for (int nro=0 ; nro < nbrelts ; nro++)
830        {
831        XmlTree*      node = rubrique->getChild (nro);
832        const std::string& type = node->getName();
833        if (type=="Shape")
834           {
835           const std::string& nom   = node->findValue   ("id"  );
836           int           orig  = node->findInteger ("type");
837           const std::string& brep  = node->findValue   ("brep");
838           NewShape*     shape = new NewShape (this, (EnumShape)orig);
839
840           parse_name (node, nom, shape);
841           shape->setBrep (brep);
842           doc_tab_shape.push_back (shape);
843           }
844        else if (type=="Cloud")
845           {
846           int nbvert = count_children (node);
847           for (int nv=0 ; nv < nbvert ; nv++)
848               {
849               Real3    point;
850               XmlTree* sommet = node->getChild (nv);
851               const  std::string& coords = sommet->findValue ("coord");
852               get_coords (coords, point[dir_x], point[dir_y], point[dir_z]);
853               doc_cloud->addPoint (point);
854               }
855           }
856        }
857 }
858 END_NAMESPACE_HEXA