Salome HOME
08a672d34410b8badb9b9629c112f9f693229066
[modules/hexablock.git] / src / HEXABLOCK / Hex.cxx
1
2 // C++ : La clase principale de Hexa
3
4 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "Hex.hxx"
23
24 #include "HexDocument.hxx"
25 #include <clocale>
26
27 BEGIN_NAMESPACE_HEXA
28
29 // ======================================================== Constructeur
30 Hex::Hex ()
31 {
32    setlocale (LC_NUMERIC, "C");
33 }
34 // ======================================================== Destructeur
35 Hex::~Hex ()
36 {
37 #ifndef NO_CASCADE
38    int nbre = liste_documents.size();
39    for (int nd=0 ; nd<nbre ; nd++) 
40        delete liste_documents [nd];
41 #endif
42 }
43 // ======================================================== countDocument
44 int Hex::countDocument ()
45 {
46    return liste_documents.size();
47 }
48 // ======================================================== getDocument
49 Document* Hex::getDocument (int nro)
50 {
51    if (nro<0 || nro>=(int)liste_documents.size())
52       return NULL;
53    
54    return liste_documents [nro];
55 }
56 // ======================================================== removeDocument
57 void Hex::removeDocument (Document* doc)
58 {
59    int nbre = liste_documents.size();
60    for (int nd=0 ; nd<nbre ; nd++) 
61        {
62        if (doc == liste_documents [nd])
63           {
64           liste_documents.erase (liste_documents.begin()+nd);
65           delete doc;
66           return;
67           }
68        }
69                       // Pas trouve dans la liste. On detruit quand meme
70     delete doc;
71 }
72 // ======================================================== addDocument
73 Document* Hex::addDocument (cpchar nomdoc)
74 {
75    Document* doc = new Document (nomdoc);
76    liste_documents.push_back (doc);
77    return doc;
78 }
79 // ======================================================== loadDocument
80 Document* Hex::loadDocument (const char* filename)
81 {
82    Document* doc = addDocument ("xxxx");
83    doc->loadXml (filename);
84    return doc;
85 }
86 END_NAMESPACE_HEXA