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)
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 // ========================================================= replaceAssociation
102 void EltBase::replaceAssociation (EltBase* orig)
104 if ( orig == NULL || orig->el_assoc == NULL
105 || orig == this || orig->el_assoc == el_assoc)
109 el_assoc = orig->el_assoc;
111 el_root->hputError (W_REPL_ASSOC, this, orig);
113 // ========================================================= copyAssociation
114 void EltBase::copyAssociation (EltBase* orig)
116 if ( orig == NULL || orig->el_assoc == NULL
117 || orig == this || orig->el_assoc == el_assoc)
120 el_assoc = orig->el_assoc;
121 el_root->hputError (W_DISCO_ASSOC, orig);
123 // ========================================================= getName
124 cpchar EltBase::getName ()
126 return el_name.c_str() ;
128 // ========================================================= getName
129 char* EltBase::getName (pchar buffer)
131 // EL_NONE, EL_VERTEX, EL_EDGE, EL_QUAD, EL_HEXA, EL_REMOVED
132 sprintf (buffer, "%c%04d", ABR_TYPES[el_type], el_id);
135 // ========================================================= printName
136 void EltBase::printName (cpchar sep)
140 printf ("%s%s", getName(nom), sep);
142 // ========================================================= setAssociation
143 void EltBase::setAssociation (Shape* forme)
147 if (el_root->debug (2))
148 cout << " Vertex " << el_name << " : setAssociation" << endl;
150 // ========================================================= addAssociation
151 int EltBase::addAssociation (Shape* forme)
153 setAssociation (forme);
156 // ========================================================= dumpRef
157 void EltBase::dumpRef ()
159 int nbp = el_parent.size();
167 for (int nro=0 ; nro<nbp ; nro++)
169 if (el_parent[nro]->isHere ())
174 el_parent[nro]->printName(", ");
180 // ========================================================= addAssociation
181 bool EltBase::canBeAssociated ()
183 bool rep = isValid() && isHere()
184 && (el_type==EL_VERTEX || el_type==EL_EDGE || el_type==EL_QUAD);
187 // ========================================================= addAssociation
188 void EltBase::setId (int ln)
191 bool defname = el_name == getName (buffer);
194 int maxid = std::max (el_root->doc_nbr_elt[el_type], ln+1);
196 el_root->doc_nbr_elt[el_type] = maxid;
198 el_name = getName (buffer);