4 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
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/ or email : webmaster.salome@opencascade.com
22 #include "HexDumpStudy.hxx"
23 #include "HexWitness.hxx"
24 #include "HexEltBase.hxx"
25 #include "HexDocument.hxx"
29 enum {EL_REAL=EL_NONE};
32 tab_name [EL_MAXI] = {"TReals", "TNodes", "TEdges", "TQuads", "THexas",
33 "TxxxA", "TxxxB", "TxxxC", "TxxxD", "TxxxE", "TxxxF" };
35 // =================================================== Constructeur
36 DumpStudy::DumpStudy ()
38 map_name [NULL] = "None";
39 is_open = NOT DumpActif;
44 for (int nc=0 ; nc<EL_MAXI ; nc++) tab_count [nc] = 0;
48 fic_dump = fopen ("tmp_dump.py", "w");
53 cpchar when = get_time (buff);
55 fprintf (fic_dump, "\n");
56 fprintf (fic_dump, "# Dump generated by HEXABLOCK at %s\n", when);
57 fprintf (fic_dump, "\n");
58 fprintf (fic_dump, "import hexablock\n");
59 fprintf (fic_dump, "\n");
62 // =================================================== start (EltBase*)
63 bool DumpStudy::start (EltBase* obj, cpchar method)
65 if (is_open || obj==NULL)
68 cpchar name = findName (obj);
69 return start (name, method);
71 // =================================================== start (name)
72 bool DumpStudy::start (cpchar obj, cpchar method, bool raz)
74 if (is_open || obj==NULL)
90 // =================================================== operator << (int)
91 DumpStudy& DumpStudy::operator << (int val)
97 sprintf (valeur, "%d", val);
102 // =================================================== operator << (double)
103 DumpStudy& DumpStudy::operator << (double val)
109 sprintf (valeur, "%g", val);
111 addArgument (valeur);
114 // =================================================== operator << (cpchar)
115 DumpStudy& DumpStudy::operator << (cpchar val)
124 addArgument (valeur);
127 // =================================================== operator << (elt)
128 DumpStudy& DumpStudy::operator << (EltBase* elt)
133 cpchar name = findName (elt);
137 // =================================================== operator << (Quads)
138 DumpStudy& DumpStudy::operator << (Quads& tab)
143 TabElts& tabelt = (TabElts&) tab;
144 addArgVector (EL_QUAD, tabelt) ;
147 // =================================================== operator << (Edges)
148 DumpStudy& DumpStudy::operator << (Edges& tab)
153 TabElts& tabelt = (TabElts&) tab;
154 addArgVector (EL_EDGE, tabelt) ;
157 // =================================================== operator << (Hexas)
158 DumpStudy& DumpStudy::operator << (Hexas& tab)
163 TabElts& tabelt = (TabElts&) tab;
164 addArgVector (EL_HEXA, tabelt) ;
167 // =================================================== operator << (Reals)
168 DumpStudy& DumpStudy::operator << (RealVector& tab)
173 char name [20], valeur [30];
175 sprintf (name, "%s%d", tab_name[EL_REAL], ++tab_count[EL_REAL]);
178 int lg = tab.size ();
179 for (int nv=0 ; nv<lg ; nv++)
181 sprintf (valeur, "%g", tab[nv]);
188 // =================================================== close + return
189 void DumpStudy::close (bool reactive, EltBase* result)
200 sprintf (name, "null%03d", nbr_nulls);
204 map_name [result] = result->makeVarName (name);
209 fprintf (fic_dump, "%s = %s\n", name, right_part.c_str());
211 // =================================================== close + return int
212 void DumpStudy::close (bool reactive, int result)
214 static int nbr_values = 0;
222 sprintf (name, "rep%03d", nbr_values);
226 fprintf (fic_dump, "%s = %s\n", name, right_part.c_str());
228 // =================================================== close + return double
229 void DumpStudy::close (bool reactive, double result)
231 static int nbr_values = 0;
239 sprintf (name, "val%03d", nbr_values);
243 fprintf (fic_dump, "%s = %s\n", name, right_part.c_str());
245 // =================================================== close
246 void DumpStudy::close (bool reactive)
255 fprintf (fic_dump, "%s\n", right_part.c_str());
257 // =================================================== lock
258 bool DumpStudy::lock ()
266 // =================================================== restore
267 void DumpStudy::restore (bool reactive)
272 // =================================================== getBegin
273 void DumpStudy::getBegin (string& begin)
278 // -------------------------------------------------------------
279 // ------------ Private
280 // ------------ For members only
281 // -------------------------------------------------------------
282 // =================================================== addArgument
283 void DumpStudy::addArgument (cpchar arg)
291 // =================================================== addArgVector
292 void DumpStudy::addArgVector (EnumElt type, TabElts& table)
295 sprintf (name, "%s%d", tab_name[type], ++tab_count[type]);
299 int lg = table.size ();
301 for (int nv=0 ; nv<lg ; nv++)
303 EltBase* elt = table[nv];
304 cpchar nom = findName (elt);
310 // =================================================== declareVectors
311 void DumpStudy::declareVectors ()
313 int lg = tab_declar.size();
317 for (int nd=0 ; nd<lg ; nd++)
319 fprintf (fic_dump, "%s\n", tab_declar[nd].c_str());
322 // =================================================== addVector
323 void DumpStudy::addVector (cpchar name)
329 curr_vector += " = ";
331 // =================================================== majVector
332 void DumpStudy::majVector (cpchar value)
336 else if ((nbr_values MODULO 7) == 0)
337 curr_vector += ",\n ";
341 curr_vector += value;
344 // =================================================== closeVector
345 void DumpStudy::closeVector ()
348 tab_declar.push_back (curr_vector);
350 // =================================================== findName
351 cpchar DumpStudy::findName (EltBase* elt)
353 cpchar name = "Unknown";
354 map <EltBase*, string> :: iterator iter = map_name.find (elt);
355 if (iter != map_name.end())
356 name = iter->second.c_str();