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