2 // C++ : Element de base
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
22 #include "HexEltBase.hxx"
23 #include "HexDocument.hxx"
24 #include "HexDiagnostics.hxx"
27 // =================================================== Constructeur
28 EltBase::EltBase (Document* doc, EnumElt type)
37 is_associated = false;
39 // EL_NONE, EL_VERTEX, EL_EDGE, EL_QUAD, EL_HEXA, EL_REMOVED
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);
55 el_name = getName (buffer);
57 // =================================================== Destructeur
60 // printf (" delete ");
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)
76 // =================================================== remove
77 void EltBase::remove ()
79 if (el_type == EL_REMOVED)
82 el_root->setDeprecated (2);
84 int nbp = el_parent.size();
85 for (int nro=0 ; nro<nbp ; nro++)
87 EltBase* elt = el_parent[nro];
88 if (elt != NULL && elt->isHere())
92 // =================================================== suppress
93 void EltBase::suppress ()
95 if (el_type == EL_REMOVED)
98 el_root->setDeprecated (2);
101 // ========================================================= getName
102 cpchar EltBase::getName ()
104 return el_name.c_str() ;
106 // ========================================================= getName
107 char* EltBase::getName (pchar buffer)
109 return makeName (el_type, el_id, buffer);
111 // ========================================================= makeName
112 char* EltBase::makeName (int type, int id, char* name)
114 // EL_NONE, EL_VERTEX, EL_EDGE, EL_QUAD, EL_HEXA, EL_REMOVED
115 sprintf (name, "%c%04d", ABR_TYPES[type], id);
119 // ========================================================= printName
120 void EltBase::printName (cpchar sep)
124 printf ("%s%s", getName(nom), sep);
126 // ========================================================= dumpRef
127 void EltBase::dumpRef ()
129 int nbp = el_parent.size();
137 for (int nro=0 ; nro<nbp ; nro++)
139 if (el_parent[nro]->isHere ())
144 el_parent[nro]->printName(", ");
150 // ========================================================= setId
151 void EltBase::setId (int ln)
154 bool defname = el_name == getName (buffer);
157 int maxid = std::max (el_root->doc_nbr_elt[el_type], ln+1);
159 el_root->doc_nbr_elt[el_type] = maxid;
161 el_name = getName (buffer);
163 // ========================================================= makeVarName
164 char* EltBase::makeVarName (char* nom)
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);
172 // ========================================================= debug
173 bool EltBase::debug (int niv)
175 return el_root != NULL && el_root->getLevel() > niv ;