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