Salome HOME
Merge from V6_main 13/12/2012
[modules/hexablock.git] / src / HEXABLOCK / HexEltBase.hxx
1
2 // Class : Element de base des Vertex/Edge/Quad, etc...
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
23 #ifndef __ELT_BASE_H
24 #define __ELT_BASE_H
25
26 #include "hexa_base.hxx"
27 #include <vector>
28
29 #define HexDump(x) {printf(#x " = "); if (x) x->dump(); else printf("NULL\n");}
30 #define PrintName(x) if (x) x->printName(); else printf ("NULL, ")
31 #define PutName(x) { printf(#x " = "); if (x) x->printName("\n"); else printf("NULL\n"); }
32
33 #define GetClone(elt) ((elt)==NULL ? NULL : elt->getClone())
34 #define BadElement(elt) (elt)==NULL || (elt)->isBad()
35
36 BEGIN_NAMESPACE_HEXA
37
38 class EltBase
39 {
40 public :
41    virtual int     countHexa   ()  { return 0; }
42    virtual int     countQuad   ()  { return 0; }
43    virtual int     countEdge   ()  { return 0; }
44    virtual int     countVertex ()  { return 0; }
45
46    virtual void    setError    (int kod=HERR)  { el_status = kod; }
47    virtual int     getError    ()              { return el_status; }
48    virtual bool    isValid     ()              { return el_status==HOK; }
49    virtual bool    isBad       ()              { return el_status!=HOK; }
50
51    virtual void    duplicate ()                   {}
52    virtual void    clearAssociation ()            {}
53
54    // void copyAssociation    (EltBase* orig);
55    // void replaceAssociation (EltBase* orig);
56
57 public :
58    virtual void replaceEdge   (Edge* old, Edge* nouveau)
59                                { printf ("rep-edge\n") ; }
60    virtual void replaceVertex (Vertex* old, Vertex* nouveau)
61                                { printf ("rep-vertex\n") ; }
62
63    EltBase (Document* doc, EnumElt type=EL_NONE);
64    EltBase (EnumElt type=EL_NONE);
65
66    virtual ~EltBase ();
67    virtual  void remove ();
68    virtual  void suppress ();
69    virtual  void dump ();
70    virtual  void saveXml (XmlWriter* xml)   {}
71    virtual  void majReferences () { }
72    virtual  char*  makeVarName (char* nom);
73
74    static   char* makeName  (int type, int id, char* name);
75
76    EltBase*  next ()                        { return el_next; }
77    void      setNext (EltBase* suivant)     { el_next = suivant; }
78    int       getId ()                       { return el_id; }
79    void      setId (int ln);
80    Document* dad ()                         { return el_root; }
81    EnumElt   getType ()                     { return el_type; }
82    bool      isHere ()                      { return el_type!=EL_REMOVED; }
83    bool      isDeleted ()                   { return el_type==EL_REMOVED; }
84
85                  // On s'occupe des parents
86
87    void  razReferences ()         { el_parent.clear() ; }
88    void  addParent (EltBase* dad) { if (dad) el_parent.push_back(dad) ; }
89    int   getNbrParents ()         { return el_parent.size() ; }
90    bool  hasParents ();
91    EltBase* getFather  (int nro);
92
93    int   getMark ()                   { return el_mark; }
94    void  setMark (int ln)             { el_mark = ln ; }
95    char* getName   (pchar nom);
96    void  printName (cpchar sep=" ");
97    void  dumpRef ();
98
99    cpchar getName ();
100    void   setName (const string& nom) { el_name = nom ; }
101    void   setName (cpchar nom)        { el_name = nom ; }
102
103    bool   debug (int niv=0);
104    bool   isAssociated ()             { return is_associated ; }
105
106 protected :
107    EnumElt   el_type;
108    EltBase*  el_next;
109    int       el_id;
110    Document* el_root;
111    string    el_name;
112
113    int       el_status;
114    int       el_mark;
115    bool      is_associated;
116    std::vector <EltBase*> el_parent;
117 };
118 // ========================================================= dump
119 inline void EltBase::dump ()
120 {
121    printf ("Elt%d  Nro=%04d", el_type, el_id);
122    dumpRef() ;
123 }
124
125 // ========================================================= getFather
126 inline EltBase* EltBase::getFather  (int nro)
127 {
128    EltBase* elt = NULL;
129    if (nro >= 0 && nro < (int) el_parent.size() && isHere()
130                 && el_parent[nro]->isHere())
131       elt = el_parent[nro];
132
133    return elt;
134 }
135 // ========================================================= hasParents
136 inline bool EltBase::hasParents ()
137 {
138    int nbp = el_parent.size();
139    for (int nro=0 ; nro<nbp ; nro++)
140        if (el_parent[nro]!=NULL && el_parent[nro]->isHere())
141           return true;
142
143    return false;
144 }
145 END_NAMESPACE_HEXA
146 #endif