Salome HOME
Hexa6 : Mise ajour des sources
[modules/hexablock.git] / src / HEXABLOCK / HexEltBase.cxx
1
2 // C++ : Element de base
3
4 // Copyright (C) 2009-2013  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 "HexEltBase.hxx"
23 #include "HexDocument.hxx"
24 #include "HexDiagnostics.hxx"
25
26 BEGIN_NAMESPACE_HEXA
27 // =================================================== Constructeur
28 EltBase::EltBase (Document* doc, EnumElt type)
29 {
30    el_root   = doc;
31    el_type   = type;
32    el_id     = 0;
33
34    el_next   = NULL;
35    el_status = HOK;
36    el_mark   = 0;
37    is_associated = false;
38
39    // EL_NONE, EL_VERTEX, EL_EDGE, EL_QUAD, EL_HEXA, EL_REMOVED
40
41    if (el_root==NULL)
42       {
43       el_name  = "NoValid";
44       setError ();
45       return;
46       }
47
48    el_id    = el_root->doc_nbr_elt [el_type];
49    el_root->doc_nbr_elt  [el_type] ++;
50    el_root->doc_last_elt [el_type] -> el_next = this;
51    el_root->doc_last_elt [el_type] = this;
52    el_root->setDeprecated (1);
53
54    char buffer [16];
55    el_name = getName (buffer);
56 }
57 // =================================================== Destructeur
58 EltBase::~EltBase ()
59 {
60    //  printf (" delete ");
61    //  dump ();
62 }
63 // =================================================== Constructeur Bis
64 // Utilise uniquement dans le constructeur de Document
65 // Creation d'un premier element fictif pour accelerer les chainages
66 EltBase::EltBase (EnumElt type)
67 {
68    el_root   = NULL;
69    el_type   = type;
70    el_id     = -1;
71
72    el_next   = NULL;
73    el_status = HOK;
74    el_mark   = 0;
75 }
76 // =================================================== remove
77 void EltBase::remove ()
78 {
79    if (el_type == EL_REMOVED)
80       return;
81
82    el_root->setDeprecated (2);
83    el_type   = EL_REMOVED;
84    el_status = HERR;
85    int nbp = el_parent.size();
86    for (int nro=0 ; nro<nbp ; nro++)
87        {
88        EltBase* elt = el_parent[nro];
89        if (elt != NULL && elt->isHere())
90            elt->remove ();
91        }
92 }
93 // =================================================== suppress
94 void EltBase::suppress ()
95 {
96    if (el_type == EL_REMOVED)
97       return;
98
99    el_root->setDeprecated (2);
100    el_type   = EL_REMOVED;
101    el_status = HERR;
102 }
103 // ========================================================= getName
104 cpchar EltBase::getName  ()
105 {
106    return el_name.c_str() ;
107 }
108 // ========================================================= getName
109 char* EltBase::getName  (pchar buffer)
110 {
111    return makeName (el_type, el_id, buffer);
112 }
113 // ========================================================= makeName
114 char* EltBase::makeName  (int type, int id, char* name)
115 {
116 // EL_NONE, EL_VERTEX, EL_EDGE, EL_QUAD, EL_HEXA, EL_REMOVED
117    sprintf (name, "%c%04d", ABR_TYPES[type], id);
118    return   name;
119 }
120
121 // ========================================================= printName
122 void EltBase::printName  (cpchar sep)
123 {
124    char nom[12];
125
126    printf ("%s%s", getName(nom), sep);
127 }
128 // ========================================================= dumpRef
129 void EltBase::dumpRef ()
130 {
131    int nbp = el_parent.size();
132    bool prems = true;
133
134    if (nbp==0)
135       {
136       printf ("\n");
137       }
138
139    for (int nro=0 ; nro<nbp ; nro++)
140        {
141        if (el_parent[nro]->isHere ())
142           {
143           if (prems)
144               printf ("\t isin ");
145           prems = false;
146           el_parent[nro]->printName(", ");
147           }
148        }
149
150    printf ("\n");
151 }
152 // ========================================================= setId
153 void EltBase::setId (int ln)
154 {
155    char buffer [16];
156    bool defname = el_name == getName (buffer);
157
158    el_id     = ln;
159    int maxid = std::max (el_root->doc_nbr_elt[el_type], ln+1);
160
161    el_root->doc_nbr_elt[el_type] = maxid;
162    if (defname)
163       el_name = getName (buffer);
164 }
165 // ========================================================= makeVarName
166 char* EltBase::makeVarName (char* nom)
167 {
168    static cpchar PREFIX [EL_MAXI] = {"undef", "ver",   "edge",  "quad",  "hexa",
169                                      "vect",  "grid",  "cyl",  "pipe", "group",
170                                      "law", "shape", "subsh", "prop",
171                                      "doc",  "Xxxx" };
172    sprintf (nom, "%s%d", PREFIX[el_type], el_id);
173    return   nom;
174 }
175 // ========================================================= debug
176 bool EltBase::debug (int niv)
177 {
178    return el_root != NULL && el_root->getLevel() > niv ;
179 }
180 // ========================================================= getNextName
181 string EltBase::getNextName ()
182 {
183    if (el_root != NULL)
184       return el_root->getNextName (el_type);
185
186    char name [16];
187    makeName  (el_type, 0, name);
188    return string (name);
189 }
190 END_NAMESPACE_HEXA
191