// C++ : Classe Document : methodes internes
-// Copyright (C) 2009-2013 CEA/DEN, EDF R&D
+// Copyright (C) 2009-2024 CEA, EDF
//
// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "HexDocument.hxx"
-#include <libgen.h> // Pour basename
+// #include <Basics_DirUtils.hxx>
#include <cstdlib> // Pour atoi et atof
#include "Hex.hxx"
#include "HexElements.hxx"
#include "HexVector.hxx"
-#include "HexCylinder.hxx"
-#include "HexPipe.hxx"
#include "HexMatrix.hxx"
#include "HexCloner.hxx"
#include "HexPropagation.hxx"
#include "HexXmlWriter.hxx"
#include "HexXmlTree.hxx"
+#include "HexGlobale.hxx"
BEGIN_NAMESPACE_HEXA
// ======================================================== get_coords
-int get_coords (const string& chaine, double& x, double& y, double& z)
+int get_coords (const std::string& chaine, double& x, double& y, double& z)
{
// int nv = sscanf (chaine.c_str (), "%lg %lg %lg", &x, &y, &z);
cpchar buffer = chaine.c_str ();
return HOK;
}
// ======================================================== get_coords
-int get_coords (const string& chaine, double& x, double& y)
+int get_coords (const std::string& chaine, double& x, double& y)
{
cpchar buffer = chaine.c_str ();
int nv = sscanf (buffer, "%lg %lg", &x, &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 std::string& nom, EltBase* elt)
{
int lg = nom.size();
int nroid = 0;
elt->setId (nroid);
- const string& name = node->findValue ("name");
+ const std::string& name = node->findValue ("name");
if (name=="")
return HERR;
return HOK;
}
// ======================================================== get_names
-void get_names (const string& chaine, int size, vector<string>& table)
+void get_names (const std::string& chaine, int size, std::vector<std::string>& table)
{
table.clear ();
int lg = chaine.size();
- string mot = "";
+ std::string mot = "";
bool encours = false;
for (int nc=0 ; nc<lg ; nc++)
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);
+ std::string filename = 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" };
{
// xml.dump ();
- map <std::string, Vertex*> t_vertex;
- map <std::string, Edge*> t_edge;
- map <std::string, Quad*> t_quad;
- map <std::string, Hexa*> t_hexa;
- map <std::string, Vector*> t_vector;
- vector <string> tname;
+ std::map <std::string, Vertex*> t_vertex;
+ std::map <std::string, Edge*> t_edge;
+ std::map <std::string, Quad*> t_quad;
+ std::map <std::string, Hexa*> t_hexa;
+ std::map <std::string, Vector*> t_vector;
+ std::vector <std::string> tname;
- const string& version = xml.findValue ("version");
+ const std::string& version = xml.findValue ("version");
if (version == "")
{
- cout << " **** Format du fichier XML perime"
- << endl;
+ std::cout << " **** Format du fichier XML perime"
+ << std::endl;
return HERR;
}
- const string& name = xml.findValue ("name");
+ const std::string& name = xml.findValue ("name");
if (name != el_name)
setName (name.c_str());
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++)
{
XmlTree* node = rubrique->getChild (nro);
- const string& type = node->getName();
+ const std::string& type = node->getName();
double px, py, pz;
if (type=="Vertex")
{
- const string& nom = node->findValue ("id");
- const string& coords = node->findValue ("coord");
+ const std::string& nom = node->findValue ("id");
+ const std::string& coords = node->findValue ("coord");
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")
}
rubrique = xml.findChild ("ListEdges");
- nbrelts = rubrique->getNbrChildren ();
+ nbrelts = count_children (rubrique);
Edge* edge = NULL;
for (int nro=0 ; nro < nbrelts ; nro++)
{
XmlTree* node = rubrique->getChild (nro);
- const string& type = node->getName();
+ const std::string& type = node->getName();
if (type=="Edge")
{
- const string& nom = node->findValue ("id");
- const string& vertices = node->findValue ("vertices");
+ const std::string& nom = node->findValue ("id");
+ const std::string& vertices = node->findValue ("vertices");
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")
{
}
rubrique = xml.findChild ("ListQuads");
- nbrelts = rubrique->getNbrChildren ();
+ nbrelts = count_children (rubrique);
Quad* quad = NULL;
for (int nro=0 ; nro < nbrelts ; nro++)
{
XmlTree* node = rubrique->getChild (nro);
- const string& type = node->getName();
+ const std::string& type = node->getName();
if (type=="Quad")
{
- const string& nom = node->findValue ("id");
- const string& edges = node->findValue ("edges");
+ const std::string& nom = node->findValue ("id");
+ const std::string& edges = node->findValue ("edges");
get_names (edges, V_TWO, tname);
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")
{
}
rubrique = xml.findChild ("ListHexas");
- nbrelts = rubrique->getNbrChildren ();
+ nbrelts = count_children (rubrique);
for (int nro=0 ; nro < nbrelts ; nro++)
{
XmlTree* node = rubrique->getChild (nro);
- const string& nom = node->findValue ("id");
- const string& quads = node->findValue ("quads");
+ const std::string& nom = node->findValue ("id");
+ const std::string& quads = node->findValue ("quads");
get_names (quads, V_TWO, tname);
Hexa* hexa = new Hexa (t_quad [tname[0]], t_quad [tname[1]],
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++)
{
XmlTree* node = rubrique->getChild (nro);
double px, py, pz;
- const string& nom = node->findValue ("id");
- const string& coords = node->findValue ("coord");
+ const std::string& nom = node->findValue ("id");
+ const std::string& coords = node->findValue ("coord");
get_coords (coords, px, py, pz);
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++)
{
XmlTree* node = rubrique->getChild (nro);
- const string& id = node->findValue ("id");
- const string& kind = node->findValue ("kind");
- const string& nodes = node->findValue ("nodes");
- const string& coeff = node->findValue ("coeff");
+ const std::string& id = node->findValue ("id");
+ const std::string& kind = node->findValue ("kind");
+ const std::string& nodes = node->findValue ("nodes");
+ const std::string& coeff = node->findValue ("coeff");
int nbnodes = atoi (nodes.c_str());
double koeff = atof (coeff.c_str());
}
rubrique = xml.findChild ("ListPropagations");
- nbrelts = rubrique == NULL ? 0 : rubrique->getNbrChildren ();
+ nbrelts = count_children (rubrique);
for (int nro=0 ; nro < nbrelts ; nro++)
{
XmlTree* node = rubrique->getChild (nro);
- const string& nmedge = node->findValue ("edge");
- const string& nmlaw = node->findValue ("law");
- // const string& nmway = node->findValue ("way");
+ const std::string& nmedge = node->findValue ("edge");
+ const std::string& nmlaw = node->findValue ("law");
+ // const std::string& nmway = node->findValue ("way");
edge = t_edge [nmedge];
Law* law = findLaw (nmlaw.c_str());
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++)
{
XmlTree* ndgroup = rubrique->getChild (nro);
XmlTree* node = ndgroup ->getChild (0);
- const string& nom = node->findValue ("name");
- const string& ckind = node->findValue ("kind");
+ const std::string& nom = node->findValue ("name");
+ const std::string& ckind = node->findValue ("kind");
EnumGroup kind = Group::getKind (ckind);
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);
- const string& id = node->findValue ("id");
+ const std::string& id = node->findValue ("id");
switch (type)
{
case EL_HEXA : groupe->addElement (t_hexa [id]);
// ======================================================== 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
doc_propagation[nro]->saveXml (doc_xml);
doc_xml->closeMark (true);
- int nombre = countCylinder();
- doc_xml->addMark ("ListCylinders");
- for (int nro=0 ; nro<nombre ; nro++)
- doc_cylinder[nro]->saveXml (doc_xml);
- doc_xml->closeMark (true);
-
- nombre = countPipe();
- doc_xml->addMark ("ListPipes");
- for (int nro=0 ; nro<nombre ; nro++)
- doc_pipe[nro]->saveXml (doc_xml);
- doc_xml->closeMark (true);
-
- nombre = countGroup();
+ int nombre = countGroup();
doc_xml->addMark ("ListGroups");
for (int nro=0 ; nro<nombre ; nro++)
doc_group[nro]->saveXml (doc_xml);
pfile vtk = fopen (nomfic, "w");
if (vtk==NULL)
{
- cout << " ****" << endl;
- cout << " **** Document::saveVtk : " << endl;
- cout << " **** Can't open file " << endl;
- cout << " ****" << endl;
+ std::cout << " ****" << std::endl;
+ std::cout << " **** Document::saveVtk : " << std::endl;
+ std::cout << " **** Can't open file " << std::endl;
+ std::cout << " ****" << std::endl;
}
fprintf (vtk, "# vtk DataFile Version 3.1\n");
}
// ====================================================== 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 ();
pfile vtk = fopen (nomfic, "w");
if (vtk==NULL)
{
- cout << " ****" << endl;
- cout << " **** Document::saveVtk : " << endl;
- cout << " **** Can't open file " << endl;
- cout << " ****" << endl;
+ std::cout << " ****" << std::endl;
+ std::cout << " **** Document::saveVtk : " << std::endl;
+ std::cout << " **** Can't open file " << std::endl;
+ std::cout << " ****" << std::endl;
}
fprintf (vtk, "# vtk DataFile Version 3.1\n");
static const double minvtk = 1e-30;
#define Koord(p) koord[p]<minvtk && 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 <Vertex*> (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));
for (int nro=0 ; nro<nbcells ; nro++)
fprintf (vtk, "%d\n", HE_MAXI);
-/****************************
fprintf (vtk, "POINT_DATA %d \n", nbnodes);
fprintf (vtk, "SCALARS A float\n");
fprintf (vtk, "LOOKUP_TABLE default\n");
-
- for (EltBase* elt = doc_first_elt[EL_HEXA]->next (); elt!=NULL;
+ for (EltBase* elt = doc_first_elt[EL_VERTEX]->next (); elt!=NULL;
elt = elt->next())
{
- Hexa* cell = static_cast <Hexa*> (elt);
- if (cell!=NULL && cell->isHere())
- cell->colorNodes (vtk);
+ Vertex* node = static_cast <Vertex*> (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
// ======================================================== parseSubShape
SubShape* Document::parseSubShape (XmlTree* node)
{
- const string& name = node->findValue ("shape");
+ const std::string& name = node->findValue ("shape");
int subid = node->findInteger ("subid");
NewShape* shape = findShape (name);
if (shape==NULL)
if (shape->getDim()!=1)
return;
- const string& inter = node->findValue ("interval");
+ const std::string& inter = node->findValue ("interval");
double pdeb, pfin;
get_coords (inter, pdeb, pfin);
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++)
{
XmlTree* node = rubrique->getChild (nro);
- const string& type = node->getName();
+ const std::string& type = node->getName();
if (type=="Shape")
{
- const string& nom = node->findValue ("id" );
+ const std::string& nom = node->findValue ("id" );
int orig = node->findInteger ("type");
- const string& brep = node->findValue ("brep");
+ const std::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;
XmlTree* sommet = node->getChild (nv);
- const string& coords = sommet->findValue ("coord");
+ const std::string& coords = sommet->findValue ("coord");
get_coords (coords, point[dir_x], point[dir_y], point[dir_z]);
doc_cloud->addPoint (point);
}