Salome HOME
d77aa8bc0412609effdc16efb19b8890bff17bf9
[modules/hexablock.git] / src / HEXABLOCK / HexEltBase.cxx
1
2 // C++ : Element de base 
3
4 // Copyright (C) 2009-2012  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     = el_root->doc_nbr_elt [type];
33
34    el_next   = NULL;
35    el_assoc  = NULL;
36    el_status = HOK;
37    el_mark   = 0;
38
39    el_root->doc_nbr_elt  [type] ++;
40    el_root->doc_last_elt [type] -> el_next = this;
41    el_root->doc_last_elt [type] = this;
42    el_root->setDeprecated (1);
43
44    // EL_NONE, EL_VERTEX, EL_EDGE, EL_QUAD, EL_HEXA, EL_REMOVED
45    char buffer [16];
46    sprintf (buffer, "%c%04d", ABR_TYPES[el_type], el_id);
47    el_name = buffer;
48 }
49 // =================================================== Destructeur
50 EltBase::~EltBase ()
51 {
52    //  printf (" delete ");
53    //  dump ();
54 }
55 // =================================================== Constructeur Bis
56 // Utilise uniquement dans le constructeur de Document
57 // Creation d'un premier element fictif pour accelerer les chainages
58 EltBase::EltBase (EnumElt type)
59 {
60    el_root   = NULL;
61    el_type   = type;
62    el_id     = -1;
63
64    el_next   = NULL;
65    el_status = HOK;
66    el_mark   = 0;
67 }
68 // =================================================== remove
69 void EltBase::remove ()
70 {
71    if (el_type == EL_REMOVED)
72       return;
73
74    el_root->setDeprecated (2);
75    el_type = EL_REMOVED;
76    int nbp = el_parent.size();
77    for (int nro=0 ; nro<nbp ; nro++)
78        {
79        EltBase* elt = el_parent[nro];
80        if (elt != NULL && elt->isHere())
81            elt->remove ();
82        }           
83 }
84 // =================================================== suppress
85 void EltBase::suppress ()
86 {
87    if (el_type == EL_REMOVED)
88       return;
89
90    el_root->setDeprecated (2);
91    el_type = EL_REMOVED;
92 }
93 // ========================================================= replaceAssociation 
94 void EltBase::replaceAssociation (EltBase* orig)
95 {
96    if (   orig == NULL || orig->el_assoc == NULL
97        || orig == this || orig->el_assoc == el_assoc)
98       return;
99
100    if (el_assoc==NULL)
101       el_assoc = orig->el_assoc;
102    else 
103       el_root->hputError (W_REPL_ASSOC, this, orig);
104 }
105 // ========================================================= copyAssociation 
106 void EltBase::copyAssociation (EltBase* orig)
107 {
108    if (   orig == NULL || orig->el_assoc == NULL
109        || orig == this || orig->el_assoc == el_assoc)
110       return;
111
112    el_assoc = orig->el_assoc;
113    el_root->hputError (W_DISCO_ASSOC, orig);
114 }
115 // ========================================================= getName 
116 cpchar EltBase::getName  ()
117 {
118    return el_name.c_str() ;
119 }
120 // ========================================================= getName 
121 char* EltBase::getName  (pchar buffer)
122 {
123 // EL_NONE, EL_VERTEX, EL_EDGE, EL_QUAD, EL_HEXA, EL_REMOVED
124    sprintf (buffer, "%c%04d", ABR_TYPES[el_type], el_id);
125    return   buffer;
126 }
127 // ========================================================= printName 
128 void EltBase::printName  (cpchar sep)
129 {
130    char nom[12];
131
132    printf ("%s%s", getName(nom), sep);
133 }
134 // ========================================================= setAssociation
135 void EltBase::setAssociation (Shape* forme)
136 {
137    el_assoc = forme;
138
139    if (el_root->debug (2))
140        cout << "  Vertex " << el_name << " : setAssociation" << endl;
141 }
142 // ========================================================= dumpRef 
143 void EltBase::dumpRef ()
144 {
145    int nbp = el_parent.size();
146    bool prems = true;
147
148    if (nbp==0)
149       {
150       printf ("\n");
151       }
152
153    for (int nro=0 ; nro<nbp ; nro++)          
154        {
155        if (el_parent[nro]->isHere ())
156           {
157           if (prems) 
158               printf ("\t isin ");
159           prems = false;
160           el_parent[nro]->printName(", ");
161           }
162        }
163
164    printf ("\n");
165 }
166
167 END_NAMESPACE_HEXA
168