2 // C++ : La clase principale de Hexa
4 // Copyright (C) 2009-2012 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
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
43 int nbre = liste_documents.size();
44 for (int nd=0 ; nd<nbre ; nd++)
45 delete liste_documents [nd];
48 // ======================================================== countDocument
49 int Hex::countDocument ()
51 return liste_documents.size();
53 // ======================================================== getDocument
54 Document* Hex::getDocument (int nro)
56 if (nro<0 || nro>=(int)liste_documents.size())
59 return liste_documents [nro];
61 // ======================================================== removeDocument
62 void Hex::removeDocument (Document* doc)
64 bool actif = glob->dump.start ("hexablock", "removeDocument");
68 int nbre = liste_documents.size();
69 for (int nd=0 ; nd<nbre ; nd++)
71 if (doc == liste_documents [nd])
73 liste_documents.erase (liste_documents.begin()+nd);
75 glob->dump.close (actif);
79 // Pas trouve dans la liste. On detruit quand meme
80 glob->dump.close (actif);
83 // ======================================================== addDocument
84 Document* Hex::addDocument (cpchar nomdoc)
86 bool actif = glob->dump.start ("hexablock", "addDocument");
91 makeName (nomdoc, name);
92 Document* doc = new Document (name.c_str(), this);
94 liste_documents.push_back (doc);
96 glob->dump.close (actif, doc);
99 // ======================================================== loadDocument
100 Document* Hex::loadDocument (cpchar filename)
102 bool actif = glob->dump.start ("hexablock", "loadDocument");
104 glob->dump << filename;
106 Document* doc = addDocument ("default");
107 doc->loadXml (filename);
109 glob->dump.close (actif, doc);
112 // ======================================================== loadAllDocs
113 int Hex::loadAllDocs (cpchar stream)
119 while ( (car=stream[posit++]) != '>')
120 if (car>='0' && car <='9')
121 nbdocs = 10*nbdocs + car - '0';
123 for (int nro = 0; nro<nbdocs ; nro++)
125 Document* doc = addDocument ("xxxx");
126 doc->setXml (stream, posit);
132 // ======================================================== saveAllDocs
133 int Hex::saveAllDocs (cpchar filename)
135 FILE* fic = fopen (filename, "w");
139 int nbdocs = countDocument ();
140 fprintf (fic, "<%d>", nbdocs);
142 for (int nro = 0; nro<nbdocs ; nro++)
144 Document* doc = getDocument (nro);
146 doc->appendXml (fic);
152 // ======================================================== findDocument
153 Document* Hex::findDocument (cpchar name)
155 int nbdocs = liste_documents.size();
156 for (int nro = 0; nro<nbdocs ; nro++)
158 Document* doc = getDocument (nro);
159 if (doc!=NULL && Cestegal (name, doc->getName ()))
164 // ======================================================== makeName
165 void Hex::makeName (cpchar radical, string& name)
174 sprintf (cnum, "_%d", numero);
178 if (findDocument (name)==NULL)
182 // ======================================================== lockDump
183 void Hex::lockDump ()
187 // ======================================================== restoreDump
188 void Hex::restoreDump ()
190 glob->dump.restore (DumpActif);
192 // ====================================================== getInstance
193 Hex* Hex::getInstance ()
195 if (first_instance==NULL)
196 first_instance = new Hex ();
198 return first_instance;