2 // C++ : La clase principale de Hexa
4 // Copyright (C) 2009-2014 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, or (at your option) any later version.
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
24 #include "HexEltBase.hxx"
25 #include "HexDocument.hxx"
26 #include "HexGlobale.hxx"
31 Hex* Hex::first_instance = NULL;
33 // ======================================================== Constructeur
36 setlocale (LC_NUMERIC, "C");
37 glob = Globale::getInstance ();
39 // ======================================================== Destructeur
42 int nbre = liste_documents.size();
43 for (int nd=0 ; nd<nbre ; nd++)
44 delete liste_documents [nd];
46 // ======================================================== countDocument
47 int Hex::countDocument ()
49 return liste_documents.size();
51 // ======================================================== getDocument
52 Document* Hex::getDocument (int nro)
54 if (nro<0 || nro>=(int)liste_documents.size())
57 return liste_documents [nro];
59 // ======================================================== removeDocument
60 void Hex::removeDocument (Document* doc)
62 bool actif = glob->dump.start ("hexablock", "removeDocument");
66 int nbre = liste_documents.size();
67 for (int nd=0 ; nd<nbre ; nd++)
69 if (doc == liste_documents [nd])
71 liste_documents.erase (liste_documents.begin()+nd);
73 glob->dump.close (actif);
77 // Pas trouve dans la liste. On detruit quand meme
78 glob->dump.close (actif);
81 // ======================================================== addDocument
82 Document* Hex::addDocument (cpchar nomdoc)
84 bool actif = glob->dump.start ("hexablock", "addDocument");
89 makeName (nomdoc, name);
90 Document* doc = new Document (name.c_str(), this);
92 liste_documents.push_back (doc);
94 glob->dump.close (actif, doc);
97 // ======================================================== loadDocument
98 Document* Hex::loadDocument (cpchar filename)
100 bool actif = glob->dump.start ("hexablock", "loadDocument");
102 glob->dump << filename;
104 Document* doc = addDocument ("default");
105 doc->loadXml (filename);
107 glob->dump.close (actif, doc);
110 // ======================================================== loadAllDocs
111 int Hex::loadAllDocs (cpchar stream)
117 while ( (car=stream[posit++]) != '>')
118 if (car>='0' && car <='9')
119 nbdocs = 10*nbdocs + car - '0';
121 for (int nro = 0; nro<nbdocs ; nro++)
123 Document* doc = addDocument ("xxxx");
124 doc->setXml (stream, posit);
130 // ======================================================== saveAllDocs
131 int Hex::saveAllDocs (cpchar filename)
133 FILE* fic = fopen (filename, "w");
137 int nbdocs = countDocument ();
138 fprintf (fic, "<%d>", nbdocs);
140 for (int nro = 0; nro<nbdocs ; nro++)
142 Document* doc = getDocument (nro);
144 doc->appendXml (fic);
150 // ======================================================== findDocument
151 Document* Hex::findDocument (cpchar name)
153 int nbdocs = liste_documents.size();
154 for (int nro = 0; nro<nbdocs ; nro++)
156 Document* doc = getDocument (nro);
157 if (doc!=NULL && Cestegal (name, doc->getName ()))
162 // ======================================================== makeName
163 void Hex::makeName (cpchar radical, string& name)
172 sprintf (cnum, "_%d", numero);
176 if (findDocument (name)==NULL)
180 // ======================================================== lockDump
181 void Hex::lockDump ()
185 // ======================================================== restoreDump
186 void Hex::restoreDump ()
188 glob->dump.restore (DumpActif);
190 // ====================================================== getInstance
191 Hex* Hex::getInstance ()
193 if (first_instance==NULL)
194 first_instance = new Hex ();
196 return first_instance;
198 // ======================================================== what (?)
201 bool actif = glob->dump.start ("hexablock", "what", false);
203 Globale* glob = Globale::getInstance ();
204 glob->mess.printMessage();
206 glob->dump.close (actif);
208 // ======================================================== sizeofMessage
209 int Hex::sizeofMessage ()
211 return glob->mess.sizeofMessage ();
213 // ======================================================== getMessageLine
214 cpchar Hex::getMessageLine (int nlig)
216 return glob->mess.getLine (nlig);
218 // ======================================================== hex_instance
221 Hex* hexa = Hex::getInstance ();
224 // ======================================================== what (fonction)
227 Hex* hexa = Hex::getInstance ();