Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/hexablock.git] / src / HEXABLOCK / HexEdge.hxx
1
2 // class : Gestion des aretes
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 __EDGE_H
23 #define __EDGE_H
24
25 #include "HexVertex.hxx"
26
27 BEGIN_NAMESPACE_HEXA
28
29 class Edge : public EltBase
30 {
31 public:
32     virtual int     countVertex () { return V_TWO; }
33     virtual Vertex* getVertex (int  nro);
34     bool    getWay ()              { return e_way ; }
35
36 public:
37     virtual void saveXml (XmlWriter* xml);
38     virtual void replaceVertex (Vertex* old, Vertex* nouveau);
39     virtual void clearAssociation  ()      { tab_assoc.clear() ; }
40     virtual void setAssociation (Shape* forme);
41     int    addAssociation (Shape* forme);
42
43     Edge (Vertex* va, Vertex* vb);
44     Edge (Edge* other);
45     int  anaMerge  (Vertex* orig, Vertex* couple[]);
46     bool definedBy (Vertex* v1,   Vertex* v2);
47
48     void  propager (Propagation* prop, int nro, int sens=1);
49
50     void  setPropag (int nro, bool sens) { e_propag = nro; e_way=sens; }
51     int   getPropag ()                   { return e_propag ; }
52
53     Quad* getParent (int nro);
54     virtual void dump ();
55     void         dumpPlus ();
56     void         dumpAsso ();
57
58     virtual void majReferences();
59
60     int  inter (Edge* other, int& nother);
61     int  inter (Edge* other);
62     int  index (Vertex* node);
63     Vertex* commonVertex  (Edge* other);
64     Vertex* opposedVertex (Vertex* sommet);
65     double* commonPoint   (Edge* other, double point[]);
66
67     Vertex* getAmont ()       { return e_vertex [NOT e_way] ; }
68     Vertex* getAval  ()       { return e_vertex [e_way] ; }
69
70     Law* getLaw ()            { return e_law ; }
71     void setLaw (Law* law)    { e_law =  law ; }
72
73     void setScalar (double valeur);
74     void setColor  (double valeur)          { setScalar (valeur) ; }
75
76     const Shapes & getAssociations ()       { return tab_assoc ;  }
77
78     virtual void duplicate ();
79     Edge*   getClone ()                     {  return e_clone ;   }
80     double* getVector (double vecteur[]);
81
82 private:
83     friend class Cloner;
84     Vertex* e_vertex [V_TWO];
85     Edge*   e_clone;
86     int     e_propag;
87     bool    e_way;     // Sens de propagation
88     Law*    e_law;     // Le soleil brille, brille, brille
89
90     Shapes tab_assoc;
91 };
92
93 // ----------------------------------------------- Inlining
94 // =============================================================== getVertex
95 inline Vertex* Edge::getVertex(int nro)
96 {
97    Vertex* elt = NULL;
98    if (nro >=0 && nro < V_TWO  && el_status == HOK
99                && e_vertex [nro]->isValid())
100       elt = e_vertex [nro];
101
102    return elt;
103 }
104 // =============================================================== index
105 inline int Edge::index (Vertex* node)
106 {
107    return  node == NULL ? NOTHING
108          : node == e_vertex[V_AMONT] ? V_AMONT
109          : node == e_vertex[V_AVAL ] ? V_AVAL : NOTHING;
110 }
111 // ============================================================= opposedVertex
112 inline Vertex* Edge::opposedVertex (Vertex* sommet)
113 {
114    int nro = index (sommet);
115    return nro<0 ? NULL : e_vertex[1-nro];
116 }
117 // ============================================================= commonVertex
118 inline Vertex* Edge::commonVertex (Edge* other)
119 {
120    int nro = inter (other);
121    return nro<0 ? NULL : e_vertex[nro];
122 }
123 // ============================================================= commonPoint
124 inline double* Edge::commonPoint (Edge* other, double point[])
125 {
126    Vertex* commun = commonVertex (other);
127    if (commun==NULL)
128       {
129       point[dir_x] = point[dir_y] = point[dir_z] =  0;
130       return NULL;
131       }
132
133    commun->getPoint (point);
134    return point;
135 }
136 // =============================================================== inter
137 inline int Edge::inter (Edge* other)
138 {
139    int nro;
140    return inter (other, nro);
141 }
142 // =============================================================== inter
143 inline int Edge::inter (Edge* other, int& nother)
144 {
145    for (int ni=0 ; ni<V_TWO ; ni++)
146         for (int nj=0 ; nj<V_TWO ; nj++)
147             if (e_vertex[ni] == other->e_vertex[nj])
148                {
149                nother =  nj;
150                return ni;
151                }
152
153    nother = NOTHING;
154    return   NOTHING;
155 }
156 // =============================================================== definedBy
157 inline bool Edge::definedBy  (Vertex* v1, Vertex* v2)
158 {
159    bool   rep =    (v1 == e_vertex[V_AMONT] && v2 == e_vertex[V_AVAL ])
160                 || (v1 == e_vertex[V_AVAL ] && v2 == e_vertex[V_AMONT]);
161    return rep;
162 }
163 // =============================================================== setScalar
164 inline void Edge::setScalar  (double val)
165 {
166    e_vertex [V_AMONT]->setScalar (val);
167    e_vertex [V_AVAL ]->setScalar (val);
168 }
169 // =============================================================== duplicate
170 inline void Edge::duplicate  ()
171 {
172    e_clone = new Edge (GetClone (e_vertex [V_AMONT]),
173                        GetClone (e_vertex [V_AVAL ]));
174
175    e_clone->tab_assoc = tab_assoc;
176 }
177 // =============================================================== getVector
178 inline double* Edge::getVector (double vecteur[])
179 {
180
181    if (e_vertex[V_AMONT]==NULL ||  e_vertex[V_AVAL]==NULL)
182       {
183       vecteur [dir_x] = vecteur [dir_y] = vecteur [dir_z] = 0;
184       return NULL;
185       }
186
187    vecteur[dir_x] = e_vertex[V_AVAL]->getX() - e_vertex[V_AMONT]->getX();
188    vecteur[dir_y] = e_vertex[V_AVAL]->getY() - e_vertex[V_AMONT]->getY();
189    vecteur[dir_z] = e_vertex[V_AVAL]->getZ() - e_vertex[V_AMONT]->getZ();
190
191    return vecteur;
192 }
193 END_NAMESPACE_HEXA
194 #endif
195