Salome HOME
Merge from V6_main 13/12/2012
[modules/hexablock.git] / src / HEXABLOCK / HexQuad.hxx
1
2 // class : Les Quadrangles
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 #ifndef __QUAD_H
23 #define __QUAD_H
24
25 #include "HexEdge.hxx"
26
27 BEGIN_NAMESPACE_HEXA
28
29 struct StrOrient
30 {
31    Vertex* v11;     // 1er sommet 1er quad
32    Vertex* v12;     // 2eme
33    Vertex* v21;     // 1er sommet 2eme quad
34    Vertex* v22;     // 2eme
35    int dir;         // direction element suivant
36
37 StrOrient ( Vertex* n11, Vertex* n12, Vertex* n21, Vertex* n22, int d=0)
38     : v11 (n11), v12 (n12), v21 (n21), v22 (n22), dir (d) {}
39
40 StrOrient ( StrOrient* s)
41     : v11 (s->v11), v12(s->v12), v21(s->v21), v22(s->v22), dir(s->dir){}
42
43 };
44
45 class Quad : public EltBase
46 {
47 public:
48     virtual Edge*   getEdge   (int  nro);
49     virtual Vertex* getVertex (int  nro);
50
51     virtual int countEdge   () { return QUAD4; }
52     virtual int countVertex () { return QUAD4; }
53
54 public:
55     Quad (Vertex* va, Vertex* vb, Vertex* vc, Vertex* vd);
56     Quad (Edge* ea, Edge* eb, Edge* ec, Edge* ed);
57     Quad (Quad* other);
58
59     Hexa* getParent (int nro);
60
61     Edge* findEdge   (Vertex* v1, Vertex*v2);
62     Edge* commonEdge (Quad* other);
63     int   anaMerge (Vertex* v1, Vertex* v2, Vertex* tv[], Edge* te[]);
64
65     int   ordoVertex (Vertex* v1, Vertex* v2, Vertex* tv[]);
66     int   prepaMerge (Vertex* tv1[], Vertex* tv2[], Edge* te1[]);
67
68     int   inter     (Quad* other, int& nro);
69     bool  definedBy (Vertex* v1, Vertex* v2);
70     bool  definedBy (Edge*   e1,  Edge*   e2);
71
72     int   indexVertex (Vertex* elt);
73     int   indexEdge   (Edge*   elt);
74
75     int   accoupler (Quad* other, StrOrient* orient);
76     int   coupler (Quad* other, StrOrient* orient, Elements* table);
77
78     Edge*   getOpposEdge   (Edge* arete, int &sens);
79     Vertex* getOpposVertex (Vertex* sommet);
80
81     virtual void majReferences();            // M.A.J relation "utilise par"
82     virtual void dump ();
83     virtual void dumpPlus ();
84     virtual void saveXml (XmlWriter* xml);
85     void setScalar (double valeur);
86     void setColor  (double valeur)          { setScalar (valeur) ; }
87
88     void         replace (Quad* old);
89     virtual void replaceEdge   (Edge*   old, Edge*   nouveau);
90     virtual void replaceVertex (Vertex* old, Vertex* nouveau);
91
92     virtual void  setAssociation (Shape* forme) {}              // PERIME
93     virtual int   addAssociation (Shape* forme) {return HOK ; } // PERIME
94
95     virtual void  clearAssociation  ();
96
97     // const Shapes& getAssociations ()        { return tab_shapes ; }
98
99
100     virtual void duplicate ();
101     Quad* getClone ()               {  return q_clone ; }
102
103     Edge* getOpposEdge     (Edge* arete);   // Version simplifiee
104     Edge* getPerpendicular (Edge* arete, Vertex* node);
105     int   getOrientation ()            { return q_orientation; }
106     int   setOrientation ();
107     void  setOrientation (int ori);
108                                                       // Hexa5
109     int   addAssociation (NewShape*  forme, int subid);
110     int   addAssociation (FaceShape* forme);
111     int   countAssociation ()                     { return tab_assoc.size () ; }
112     FaceShape* getAssociation (int nro);
113
114 private:
115     friend class Cloner;
116     Quad* getBrother (StrOrient* orient);
117
118 private:
119     Edge*   q_edge   [QUAD4];
120     Vertex* q_vertex [QUAD4];
121     Quad*   q_clone;
122     int     q_orientation;
123
124     FaceShapes tab_assoc;
125 };
126 // ----------------------------------------------- Inlining
127 // ======================================================== commonEdge
128 inline Edge* Quad::commonEdge (Quad* other)
129 {
130    for (int ne1=0 ; ne1<QUAD4 ; ne1++)
131        for (int ne2=0 ; ne2<QUAD4 ; ne2++)
132            if (q_edge [ne1] == other->q_edge [ne2])
133               return q_edge [ne1];
134
135    return NULL;
136 }
137
138 // ======================================================== Inter
139 inline int Quad::inter (Quad* other, int& nother)
140 {
141    for (int ne1=0 ; ne1<QUAD4 ; ne1++)
142        for (int ne2=0 ; ne2<QUAD4 ; ne2++)
143            if (q_edge [ne1] == other->q_edge [ne2])
144               {
145               nother = ne2;
146               return  ne1;
147               }
148
149    nother = NOTHING;
150    return NOTHING;
151 }
152 // ============================================================ definedBy (v)
153 inline bool Quad::definedBy  (Vertex* v1, Vertex* v2)
154 {
155    for (int n1=0 ; n1< QUAD4 ; n1++)
156        if (v1 == q_vertex[n1] && v2 == q_vertex[(n1+2) MODULO QUAD4])
157           return true;
158
159    return false;
160 }
161 // ============================================================ definedBy (e)
162 inline bool Quad::definedBy  (Edge* e1, Edge* e2)
163 {
164    for (int n1=0 ; n1< QUAD4 ; n1++)
165        if (e1 == q_edge[n1] && e2 == q_edge[(n1+2) MODULO QUAD4])
166           return true;
167
168    return false;
169 }
170 // =============================================================== findEdge
171 inline Edge* Quad::findEdge (Vertex* v1, Vertex* v2)
172 {
173    for (int nro=0 ; nro< QUAD4 ; nro++)
174        {
175        Vertex* va = q_edge[nro]->getVertex(V_AMONT) ;
176        Vertex* vb = q_edge[nro]->getVertex(V_AVAL) ;
177        if ((v1==va && v2==vb) || (v1==vb && v2==va))
178            return q_edge [nro];
179        }
180
181    return NULL;
182 }
183 // =============================================================== indexVertex
184 inline int Quad::indexVertex  (Vertex* elt)
185 {
186    for (int n1=0 ; n1< QUAD4 ; n1++)
187        if (elt == q_vertex[n1])
188           return n1;
189
190    return NOTHING;
191 }
192 // =============================================================== indexEdge
193 inline int Quad::indexEdge  (Edge* elt)
194 {
195    for (int n1=0 ; n1< QUAD4 ; n1++)
196        if (elt == q_edge[n1])
197           return n1;
198
199    return NOTHING;
200 }
201 // =============================================================== setScalar
202 inline void Quad::setScalar  (double val)
203 {
204    for (int n1=0 ; n1< QUAD4 ; n1++)
205        q_vertex[n1] -> setScalar (val);
206 }
207 // =============================================================== duplicate
208 inline void Quad::duplicate  ()
209 {
210    q_orientation  = Q_UNDEFINED;
211    q_clone = new Quad (GetClone (q_edge [E_A]),
212                        GetClone (q_edge [E_B]),
213                        GetClone (q_edge [E_C]),
214                        GetClone (q_edge [E_D]));
215    q_clone->tab_assoc  = tab_assoc;
216 }
217 END_NAMESPACE_HEXA
218 #endif
219