Salome HOME
Merge from V6_main 13/12/2012
[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 ();
40
41     Edge (Vertex* va, Vertex* vb);
42     Edge (Edge* other);
43     int  anaMerge  (Vertex* orig, Vertex* couple[]);
44     bool definedBy (Vertex* v1,   Vertex* v2);
45
46     void  propager (Propagation* prop, int nro, int sens=1);
47
48     void  setPropag (int nro, bool sens) { e_propag = nro; e_way=sens; }
49     int   getPropag ()                   { return e_propag ; }
50
51     Quad* getParent (int nro);
52     virtual void dump ();
53     void         dumpPlus ();
54     void         dumpAsso ();
55
56     virtual void majReferences();
57
58     int  inter (Edge* other, int& nother);
59     int  inter (Edge* other);
60     int  index (Vertex* node);
61     Vertex* commonVertex  (Edge* other);
62     Vertex* opposedVertex (Vertex* sommet);
63     double* commonPoint   (Edge* other, double point[]);
64
65     Vertex* getAmont ()       { return e_vertex [NOT e_way] ; }
66     Vertex* getAval  ()       { return e_vertex [e_way] ; }
67
68     Law* getLaw ()            { return e_law ; }
69     void setLaw (Law* law)    { e_law =  law ; }
70
71     void setScalar (double valeur);
72     void setColor  (double valeur)          { setScalar (valeur) ; }
73
74     const Shapes & getAssociations ()       { return tab_shapes ;  }
75
76     virtual void duplicate ();
77     Edge*   getClone  ()                    { return e_clone ;   }
78     double* getVector (double vecteur[]);
79     string  makeDefinition ();
80
81     virtual int  addAssociation (Shape* forme) {return HOK;}   // Perime Hexa5
82     virtual void setAssociation (Shape* forme) {}              // Perime Hexa5
83
84     int addAssociation (NewShape*  geom,   int subid, double deb, double fin);
85     int addAssociation (EdgeShape* gline, double deb, double fin);
86     int checkAssociation ();
87     int countAssociation () { return tab_assoc.size () ; }
88     AssoEdge* getAssociation (int nro);
89
90 private:
91     friend class Cloner;
92     Vertex* e_vertex [V_TWO];
93     Edge*   e_clone;
94     int     e_propag;
95     bool    e_way;     // Sens de propagation
96     Law*    e_law;     // Le soleil brille, brille, brille
97
98     Shapes    tab_shapes;
99     AssoEdges tab_assoc;
100 };
101
102 // ----------------------------------------------- Inlining
103 // =============================================================== getVertex
104 inline Vertex* Edge::getVertex(int nro)
105 {
106    Vertex* elt = NULL;
107    if (nro >=0 && nro < V_TWO  && el_status == HOK
108                && e_vertex [nro]->isValid())
109       elt = e_vertex [nro];
110
111    return elt;
112 }
113 // =============================================================== index
114 inline int Edge::index (Vertex* node)
115 {
116    return  node == NULL ? NOTHING
117          : node == e_vertex[V_AMONT] ? V_AMONT
118          : node == e_vertex[V_AVAL ] ? V_AVAL : NOTHING;
119 }
120 // ============================================================= opposedVertex
121 inline Vertex* Edge::opposedVertex (Vertex* sommet)
122 {
123    int nro = index (sommet);
124    return nro<0 ? NULL : e_vertex[1-nro];
125 }
126 // ============================================================= commonVertex
127 inline Vertex* Edge::commonVertex (Edge* other)
128 {
129    int nro = inter (other);
130    return nro<0 ? NULL : e_vertex[nro];
131 }
132 // ============================================================= commonPoint
133 inline double* Edge::commonPoint (Edge* other, double point[])
134 {
135    Vertex* commun = commonVertex (other);
136    if (commun==NULL)
137       {
138       point[dir_x] = point[dir_y] = point[dir_z] =  0;
139       return NULL;
140       }
141
142    commun->getPoint (point);
143    return point;
144 }
145 // =============================================================== inter
146 inline int Edge::inter (Edge* other)
147 {
148    int nro;
149    return inter (other, nro);
150 }
151 // =============================================================== inter
152 inline int Edge::inter (Edge* other, int& nother)
153 {
154    for (int ni=0 ; ni<V_TWO ; ni++)
155         for (int nj=0 ; nj<V_TWO ; nj++)
156             if (e_vertex[ni] == other->e_vertex[nj])
157                {
158                nother =  nj;
159                return ni;
160                }
161
162    nother = NOTHING;
163    return   NOTHING;
164 }
165 // =============================================================== definedBy
166 inline bool Edge::definedBy  (Vertex* v1, Vertex* v2)
167 {
168    bool   rep =    (v1 == e_vertex[V_AMONT] && v2 == e_vertex[V_AVAL ])
169                 || (v1 == e_vertex[V_AVAL ] && v2 == e_vertex[V_AMONT]);
170    return rep;
171 }
172 // =============================================================== setScalar
173 inline void Edge::setScalar  (double val)
174 {
175    e_vertex [V_AMONT]->setScalar (val);
176    e_vertex [V_AVAL ]->setScalar (val);
177 }
178 // =============================================================== duplicate
179 inline void Edge::duplicate  ()
180 {
181    e_clone = new Edge (GetClone (e_vertex [V_AMONT]),
182                        GetClone (e_vertex [V_AVAL ]));
183
184    e_clone->tab_shapes = tab_shapes;
185    e_clone->tab_assoc  = tab_assoc;
186 }
187 // =============================================================== getVector
188 inline double* Edge::getVector (double vecteur[])
189 {
190
191    if (e_vertex[V_AMONT]==NULL ||  e_vertex[V_AVAL]==NULL)
192       {
193       vecteur [dir_x] = vecteur [dir_y] = vecteur [dir_z] = 0;
194       return NULL;
195       }
196
197    vecteur[dir_x] = e_vertex[V_AVAL]->getX() - e_vertex[V_AMONT]->getX();
198    vecteur[dir_y] = e_vertex[V_AVAL]->getY() - e_vertex[V_AMONT]->getY();
199    vecteur[dir_z] = e_vertex[V_AVAL]->getZ() - e_vertex[V_AMONT]->getZ();
200
201    return vecteur;
202 }
203 END_NAMESPACE_HEXA
204 #endif
205