Salome HOME
419edc70b0aaef141717114fcfa9d583598eb194
[modules/hexablock.git] / src / HEXABLOCK / HexEltBase.cxx
1
2 // C++ : Element de base
3
4 // Copyright (C) 2009-2023  CEA, EDF
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, or (at your option) any later version.
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    for (int nro=0 ; nro<nbp ; nro++)
135        {
136        if (el_parent[nro]->isHere ())
137           {
138           if (prems)
139               printf ("\t isin ");
140           prems = false;
141           el_parent[nro]->printName(", ");
142           }
143        }
144
145    printf ("\n");
146 }
147 // ========================================================= setId
148 void EltBase::setId (int ln)
149 {
150    char buffer [16];
151    bool defname = el_name == getName (buffer);
152
153    el_id     = ln;
154    int maxid = std::max (el_root->doc_nbr_elt[el_type], ln+1);
155
156    el_root->doc_nbr_elt[el_type] = maxid;
157    if (defname)
158       el_name = getName (buffer);
159 }
160 // ========================================================= makeVarName
161 char* EltBase::makeVarName (char* nom)
162 {
163    static cpchar PREFIX [EL_MAXI] = {"undef", "ver",   "edge",  "quad",  "hexa",
164                                      "vect",  "grid",  "cyl",  "pipe", "group",
165                                      "law", "shape", "subsh", "prop",
166                                      "doc",  "Xxxx" };
167    sprintf (nom, "%s%d", PREFIX[el_type], el_id);
168    return   nom;
169 }
170 // ========================================================= debug
171 bool EltBase::debug (int niv)
172 {
173    return el_root != NULL && el_root->getLevel() > niv ;
174 }
175 // ========================================================= getNextName
176 std::string EltBase::getNextName ()
177 {
178    if (el_root != NULL)
179       return el_root->getNextName (el_type);
180
181    char name [16];
182    makeName  (el_type, 0, name);
183    return std::string (name);
184 }
185 END_NAMESPACE_HEXA
186