Salome HOME
797ceb6110b82e5b4a085f4e51a42b5e47989fcf
[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    int nbp = el_parent.size();
85    for (int nro=0 ; nro<nbp ; nro++)
86        {
87        EltBase* elt = el_parent[nro];
88        if (elt != NULL && elt->isHere())
89            elt->remove ();
90        }
91 }
92 // =================================================== suppress
93 void EltBase::suppress ()
94 {
95    if (el_type == EL_REMOVED)
96       return;
97
98    el_root->setDeprecated (2);
99    el_type = EL_REMOVED;
100 }
101 // ========================================================= getName
102 cpchar EltBase::getName  ()
103 {
104    return el_name.c_str() ;
105 }
106 // ========================================================= getName
107 char* EltBase::getName  (pchar buffer)
108 {
109    return makeName (el_type, el_id, buffer);
110 }
111 // ========================================================= makeName
112 char* EltBase::makeName  (int type, int id, char* name)
113 {
114 // EL_NONE, EL_VERTEX, EL_EDGE, EL_QUAD, EL_HEXA, EL_REMOVED
115    sprintf (name, "%c%04d", ABR_TYPES[type], id);
116    return   name;
117 }
118
119 // ========================================================= printName
120 void EltBase::printName  (cpchar sep)
121 {
122    char nom[12];
123
124    printf ("%s%s", getName(nom), sep);
125 }
126 // ========================================================= dumpRef
127 void EltBase::dumpRef ()
128 {
129    int nbp = el_parent.size();
130    bool prems = true;
131
132    if (nbp==0)
133       {
134       printf ("\n");
135       }
136
137    for (int nro=0 ; nro<nbp ; nro++)
138        {
139        if (el_parent[nro]->isHere ())
140           {
141           if (prems)
142               printf ("\t isin ");
143           prems = false;
144           el_parent[nro]->printName(", ");
145           }
146        }
147
148    printf ("\n");
149 }
150 // ========================================================= setId
151 void EltBase::setId (int ln)
152 {
153    char buffer [16];
154    bool defname = el_name == getName (buffer);
155
156    el_id     = ln;
157    int maxid = std::max (el_root->doc_nbr_elt[el_type], ln+1);
158
159    el_root->doc_nbr_elt[el_type] = maxid;
160    if (defname)
161       el_name = getName (buffer);
162 }
163 // ========================================================= makeVarName
164 char* EltBase::makeVarName (char* nom)
165 {
166    static cpchar PREFIX[]  = {"Undef", "Node",  "Edge",  "Quad",  "Hexa",
167                               "Vect",  "Grid",  "Cyl",  "Pipe", "Group", "Law",
168                               "Xxxx",  "Xxxx",  "Xxxx" };
169    sprintf (nom, "%s%d", PREFIX[el_type], el_id);
170    return   nom;
171 }
172 // ========================================================= debug
173 bool EltBase::debug (int niv)
174 {
175    return el_root != NULL && el_root->getLevel() > niv ;
176 }
177 END_NAMESPACE_HEXA
178