2 // C++ : Extraction des brep d'un fichier XML
4 // Copyright (C) 2009-2011 CEA/DEN, EDF R&D and My Apple
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.
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.
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
20 // See http://www.salome-platform.org/
21 // or email : webmaster.salome@opencascade.com
24 #include "HexXmlTree.hxx"
28 void parse_brep (XmlTree& xml);
30 // ======================================================== test_brep
31 int test_brep (int nbargs, cpchar tabargs[])
35 string filename = "restore";
37 filename = tabargs [1];
39 static const int NbExt = 3;
40 static cpchar t_ext [NbExt] = { ".xml", ".XML", ".Xml" };
43 for (int nx = 0; nx < NbExt && noext ; nx++)
45 ici = filename.rfind (t_ext[nx]);
46 noext = ici < 0 || ici > filename.size();
52 int ier = xml.parseFile (filename);
59 // ======================================================== get_names
60 void get_names (const string& chaine, vector<string>& table)
63 int lg = chaine.size();
67 for (int nc=0 ; nc<lg ; nc++)
69 char car = chaine[nc];
77 table.push_back (mot);
84 table.push_back (mot);
86 // ======================================================== save_file_brep
87 void save_file_brep (string& nom, string& brep)
89 string filename = nom + ".brep";
90 FILE* fic = fopen (filename.c_str(), "w");
94 cout << " *** Echec a l'ouverture du fichier " << filename << endl;
98 cout << " +++ Ouverture du fichier " << filename << endl;
99 fprintf (fic, "%s\n", brep.c_str());
103 // ======================================================== parse_brep
104 void parse_brep (XmlTree& xml)
108 XmlTree* rubrique = xml.findChild ("ListVertices");
109 int nbrelts = rubrique->getNbrChildren ();
111 string nom, brep, filename;
112 XmlTree* node = NULL;
113 vector <string> tname;
115 for (int nro=0 ; nro < nbrelts ; nro++)
117 node = rubrique->getChild (nro);
118 nom = node->findValue ("id");
119 brep = node->findValue ("shape");
120 if (NOT brep.empty ())
121 save_file_brep (nom, brep);
124 rubrique = xml.findChild ("ListEdges");
125 nbrelts = rubrique->getNbrChildren ();
127 for (int nro=0 ; nro < nbrelts ; nro++)
129 node = rubrique->getChild (nro);
130 const string& type = node->getName();
133 nom = node->findValue ("id");
134 const string& vertices = node->findValue ("vertices");
135 get_names (vertices, tname);
137 else if (type=="Shape")
139 brep = node->findValue ("brep");
140 save_file_brep (nom, brep);
144 rubrique = xml.findChild ("ListQuads");
145 nbrelts = rubrique->getNbrChildren ();
147 for (int nro=0 ; nro < nbrelts ; nro++)
149 node = rubrique->getChild (nro);
150 const string& type = node->getName();
153 nom = node->findValue ("id");
154 const string& edges = node->findValue ("edges");
155 get_names (edges, tname);
157 else if (type=="Shape")
159 brep = node->findValue ("brep");
160 save_file_brep (nom, brep);