X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHEXABLOCK%2FHexDocument_Xml.cxx;h=92039da360c54b279cb457a8fc3aa1d34a38c52a;hb=b871c3e20e331915e4534dcaffc1f0eab8f809d5;hp=3f6fd993ae74506531635b3c18f2d8dcee9888e1;hpb=e60536c6f881b7718fd28765294a00f7969a7dfd;p=modules%2Fhexablock.git diff --git a/src/HEXABLOCK/HexDocument_Xml.cxx b/src/HEXABLOCK/HexDocument_Xml.cxx index 3f6fd99..92039da 100755 --- a/src/HEXABLOCK/HexDocument_Xml.cxx +++ b/src/HEXABLOCK/HexDocument_Xml.cxx @@ -1,12 +1,12 @@ // C++ : Classe Document : methodes internes -// Copyright (C) 2009-2012 CEA/DEN, EDF R&D +// Copyright (C) 2009-2016 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,7 +20,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "HexDocument.hxx" -#include // Pour basename +// #include #include // Pour atoi et atof #include "Hex.hxx" @@ -32,8 +32,6 @@ #include "HexElements.hxx" #include "HexVector.hxx" -#include "HexCylinder.hxx" -#include "HexPipe.hxx" #include "HexMatrix.hxx" #include "HexCloner.hxx" #include "HexPropagation.hxx" @@ -47,6 +45,7 @@ #include "HexXmlWriter.hxx" #include "HexXmlTree.hxx" +#include "HexGlobale.hxx" BEGIN_NAMESPACE_HEXA @@ -67,8 +66,8 @@ int get_coords (const string& chaine, double& x, double& y) if (nv!=2) return HERR; return HOK; } -// ======================================================== parseName -int parseName (XmlTree* node, const string& nom, EltBase* elt) +// ======================================================== parse_name +int parse_name (XmlTree* node, const string& nom, EltBase* elt) { int lg = nom.size(); int nroid = 0; @@ -111,12 +110,19 @@ void get_names (const string& chaine, int size, vector& table) if (encours) table.push_back (mot); } +// ======================================================== count_children +int count_children (XmlTree* dad) +{ + int nbre = dad==NULL ? 0 : dad->getNbrChildren (); + return nbre; +} // ======================================================== loadXml int Document::loadXml (cpchar ficname) { XmlTree xml(""); string filename = ficname; - el_name = basename ((pchar)ficname); + //el_name = Kernel_Utils::GetBaseName ((pchar)ficname); + make_basename (ficname, el_name); static const int NbExt = 3; static cpchar t_ext [NbExt] = { ".xml", ".XML", ".Xml" }; @@ -188,7 +194,7 @@ int Document::parseXml (XmlTree& xml) parseShapes (xml); XmlTree* rubrique = xml.findChild ("ListVertices"); - int nbrelts = rubrique->getNbrChildren (); + int nbrelts = count_children (rubrique); Vertex* vertex = NULL; for (int nro=0 ; nro < nbrelts ; nro++) @@ -203,7 +209,7 @@ int Document::parseXml (XmlTree& xml) get_coords (coords, px, py, pz); vertex = addVertex (px, py, pz); - parseName (node, nom, vertex); + parse_name (node, nom, vertex); t_vertex [nom] = vertex; } else if (type=="Asso") @@ -213,7 +219,7 @@ int Document::parseXml (XmlTree& xml) } rubrique = xml.findChild ("ListEdges"); - nbrelts = rubrique->getNbrChildren (); + nbrelts = count_children (rubrique); Edge* edge = NULL; for (int nro=0 ; nro < nbrelts ; nro++) @@ -227,7 +233,7 @@ int Document::parseXml (XmlTree& xml) get_names (vertices, V_TWO, tname); edge = new Edge (t_vertex [tname[0]], t_vertex [tname[1]]); t_edge [nom] = edge; - parseName (node, nom, edge); + parse_name (node, nom, edge); } else if (type=="Asso") { @@ -236,7 +242,7 @@ int Document::parseXml (XmlTree& xml) } rubrique = xml.findChild ("ListQuads"); - nbrelts = rubrique->getNbrChildren (); + nbrelts = count_children (rubrique); Quad* quad = NULL; for (int nro=0 ; nro < nbrelts ; nro++) @@ -252,7 +258,7 @@ int Document::parseXml (XmlTree& xml) quad = new Quad (t_edge [tname[0]], t_edge [tname[1]], t_edge [tname[2]], t_edge [tname[3]]); t_quad [nom] = quad; - parseName (node, nom, quad); + parse_name (node, nom, quad); } else if (type=="Asso") { @@ -261,7 +267,7 @@ int Document::parseXml (XmlTree& xml) } rubrique = xml.findChild ("ListHexas"); - nbrelts = rubrique->getNbrChildren (); + nbrelts = count_children (rubrique); for (int nro=0 ; nro < nbrelts ; nro++) { @@ -274,11 +280,11 @@ int Document::parseXml (XmlTree& xml) t_quad [tname[2]], t_quad [tname[3]], t_quad [tname[4]], t_quad [tname[5]]); t_hexa [nom] = hexa; - parseName (node, nom, hexa); + parse_name (node, nom, hexa); } rubrique = xml.findChild ("ListVectors"); - nbrelts = rubrique == NULL ? 0 : rubrique->getNbrChildren (); + nbrelts = count_children (rubrique); for (int nro=0 ; nro < nbrelts ; nro++) { @@ -290,11 +296,11 @@ int Document::parseXml (XmlTree& xml) Vector* vector = addVector (px, py, pz); t_vector [nom] = vector; - parseName (node, nom, vector); + parse_name (node, nom, vector); } rubrique = xml.findChild ("ListDicretizationLaws"); - nbrelts = rubrique == NULL ? 0 : rubrique->getNbrChildren (); + nbrelts = count_children (rubrique); for (int nro=0 ; nro < nbrelts ; nro++) { @@ -315,7 +321,7 @@ int Document::parseXml (XmlTree& xml) } rubrique = xml.findChild ("ListPropagations"); - nbrelts = rubrique == NULL ? 0 : rubrique->getNbrChildren (); + nbrelts = count_children (rubrique); for (int nro=0 ; nro < nbrelts ; nro++) { @@ -332,41 +338,8 @@ int Document::parseXml (XmlTree& xml) edge->setLaw (law); } - for (int pipe=0 ; pipe<2 ; pipe++) - { - rubrique = pipe ? xml.findChild ("ListPipes") - : xml.findChild ("ListCylinders"); - - nbrelts = rubrique == NULL ? 0 : rubrique->getNbrChildren (); - - for (int nro=0 ; nro < nbrelts ; nro++) - { - XmlTree* node = rubrique->getChild (nro); - const string& cbase = node->findValue ("c_base" ); - const string& cdir = node->findValue ("c_dir" ); - const string& cradius = node->findValue ("c_radius"); - const string& cheight = node->findValue ("c_height"); - - Vertex* base = t_vertex [cbase]; - Vector* dir = t_vector [cdir]; - double radius = atof (cradius.c_str()); - double height = atof (cheight.c_str()); - - if (pipe) - { - const string& cradius1 = node->findValue ("c_int_radius"); - double radius1 = atof (cradius1.c_str()); - addPipe (base, dir, radius1, radius, height); - } - else - { - addCylinder (base, dir, radius, height); - } - } - } - rubrique = xml.findChild ("ListGroups"); - int nbrgroups = rubrique == NULL ? 0 : rubrique->getNbrChildren (); + int nbrgroups = count_children (rubrique); for (int nro=0 ; nro < nbrgroups ; nro++) { @@ -379,7 +352,7 @@ int Document::parseXml (XmlTree& xml) Group* groupe = addGroup (nom.c_str(), kind); EnumElt type = groupe->getTypeElt (); - nbrelts = ndgroup->getNbrChildren (); + nbrelts = count_children (ndgroup); for (int nelt=1 ; nelt < nbrelts ; nelt++) { node = ndgroup ->getChild (nelt); @@ -405,14 +378,16 @@ int Document::parseXml (XmlTree& xml) // ======================================================== save int Document::save (const char* ficxml) { + DumpStart ("save", ficxml); + if (doc_xml==NULL) doc_xml = new XmlWriter (); int ier = doc_xml->setFileName (ficxml); - if (ier != HOK) - return ier; + if (ier == HOK) + ier = genXml (); - ier = genXml (); + DumpReturn (ier); return ier; } // ======================================================== appendXml @@ -483,19 +458,7 @@ int Document::genXml () doc_propagation[nro]->saveXml (doc_xml); doc_xml->closeMark (true); - int nombre = countCylinder(); - doc_xml->addMark ("ListCylinders"); - for (int nro=0 ; nrosaveXml (doc_xml); - doc_xml->closeMark (true); - - nombre = countPipe(); - doc_xml->addMark ("ListPipes"); - for (int nro=0 ; nrosaveXml (doc_xml); - doc_xml->closeMark (true); - - nombre = countGroup(); + int nombre = countGroup(); doc_xml->addMark ("ListGroups"); for (int nro=0 ; nrosaveXml (doc_xml); @@ -604,9 +567,10 @@ int Document::saveVtk0 (cpchar nomfic) } // ====================================================== saveVtk -// ==== Nouvelle formule +// ==== Nouvelle formule qui conserve les numeros de vertex int Document::saveVtk (cpchar nomfic) { + DumpStart ("saveVtk", nomfic); int nbnodes = doc_nbr_elt [EL_VERTEX]; int nbcells = countHexa (); @@ -630,26 +594,18 @@ int Document::saveVtk (cpchar nomfic) static const double minvtk = 1e-30; #define Koord(p) koord[p]-minvtk ? 0 : koord[p] - int last_nro = 0; for (EltBase* elt = doc_first_elt[EL_VERTEX]->next (); elt!=NULL; elt = elt->next()) { Vertex* node = static_cast (elt); if (node->isHere()) { - int nro = node->getId (); - for (int np = last_nro ; np < nro ; np++) - fprintf (vtk, "0 0 0\n"); - node->getPoint (koord); fprintf (vtk, "%g %g %g\n", Koord(dir_x), Koord(dir_y), Koord(dir_z)); - last_nro = nro+1; } + else + fprintf (vtk, "0 0 0\n"); } - - for (int np = last_nro ; np < nbnodes ; np++) - fprintf (vtk, "0 0 0\n"); - // -- 2) Les hexas fprintf (vtk, "CELLS %d %d\n", nbcells, nbcells*(HV_MAXI+1)); @@ -666,20 +622,24 @@ int Document::saveVtk (cpchar nomfic) for (int nro=0 ; nronext (); elt!=NULL; + for (EltBase* elt = doc_first_elt[EL_VERTEX]->next (); elt!=NULL; elt = elt->next()) { - Hexa* cell = static_cast (elt); - if (cell!=NULL && cell->isHere()) - cell->colorNodes (vtk); + Vertex* node = static_cast (elt); + if (node->isHere()) + { + double color = 100*(node->getScalar()+1); + fprintf (vtk, "%g\n", color); + } + else + fprintf (vtk, "100\n"); } -*********************************/ + fclose (vtk); + DumpReturn (HOK); return HOK; } // ====================================================== purge @@ -864,7 +824,7 @@ void Document::parseAssociation (XmlTree* node, Quad* quad) void Document::parseShapes (XmlTree& root) { XmlTree* rubrique = root.findChild ("ListShapes"); - int nbrelts = rubrique==NULL ? 0 : rubrique->getNbrChildren (); + int nbrelts = count_children (rubrique); for (int nro=0 ; nro < nbrelts ; nro++) { @@ -877,13 +837,13 @@ void Document::parseShapes (XmlTree& root) const string& brep = node->findValue ("brep"); NewShape* shape = new NewShape (this, (EnumShape)orig); - parseName (node, nom, shape); + parse_name (node, nom, shape); shape->setBrep (brep); doc_tab_shape.push_back (shape); } else if (type=="Cloud") { - int nbvert = node->getNbrChildren (); + int nbvert = count_children (node); for (int nv=0 ; nv < nbvert ; nv++) { Real3 point;