2 // class : Gestion des aretes
4 // Copyright (C) 2009-2012 CEA/DEN, EDF R&D
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 #include "HexVertex.hxx"
29 class Edge : public EltBase
32 virtual int countVertex () { return V_TWO; }
33 virtual Vertex* getVertex (int nro);
34 bool getWay () { return e_way ; }
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);
43 Edge (Vertex* va, Vertex* vb);
45 int anaMerge (Vertex* orig, Vertex* couple[]);
46 bool definedBy (Vertex* v1, Vertex* v2);
48 void propager (Propagation* prop, int nro, int sens=1);
50 void setPropag (int nro, bool sens) { e_propag = nro; e_way=sens; }
51 int getPropag () { return e_propag ; }
53 Quad* getParent (int nro);
58 virtual void majReferences();
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[]);
67 Vertex* getAmont () { return e_vertex [NOT e_way] ; }
68 Vertex* getAval () { return e_vertex [e_way] ; }
70 Law* getLaw () { return e_law ; }
71 void setLaw (Law* law) { e_law = law ; }
73 void setScalar (double valeur);
74 void setColor (double valeur) { setScalar (valeur) ; }
76 const Shapes & getAssociations () { return tab_assoc ; }
78 virtual void duplicate ();
79 Edge* getClone () { return e_clone ; }
80 double* getVector (double vecteur[]);
84 Vertex* e_vertex [V_TWO];
87 bool e_way; // Sens de propagation
88 Law* e_law; // Le soleil brille, brille, brille
93 // ----------------------------------------------- Inlining
94 // =============================================================== getVertex
95 inline Vertex* Edge::getVertex(int nro)
98 if (nro >=0 && nro < V_TWO && el_status == HOK
99 && e_vertex [nro]->isValid())
100 elt = e_vertex [nro];
104 // =============================================================== index
105 inline int Edge::index (Vertex* node)
107 return node == NULL ? NOTHING
108 : node == e_vertex[V_AMONT] ? V_AMONT
109 : node == e_vertex[V_AVAL ] ? V_AVAL : NOTHING;
111 // ============================================================= opposedVertex
112 inline Vertex* Edge::opposedVertex (Vertex* sommet)
114 int nro = index (sommet);
115 return nro<0 ? NULL : e_vertex[1-nro];
117 // ============================================================= commonVertex
118 inline Vertex* Edge::commonVertex (Edge* other)
120 int nro = inter (other);
121 return nro<0 ? NULL : e_vertex[nro];
123 // ============================================================= commonPoint
124 inline double* Edge::commonPoint (Edge* other, double point[])
126 Vertex* commun = commonVertex (other);
129 point[dir_x] = point[dir_y] = point[dir_z] = 0;
133 commun->getPoint (point);
136 // =============================================================== inter
137 inline int Edge::inter (Edge* other)
140 return inter (other, nro);
142 // =============================================================== inter
143 inline int Edge::inter (Edge* other, int& nother)
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])
156 // =============================================================== definedBy
157 inline bool Edge::definedBy (Vertex* v1, Vertex* v2)
159 bool rep = (v1 == e_vertex[V_AMONT] && v2 == e_vertex[V_AVAL ])
160 || (v1 == e_vertex[V_AVAL ] && v2 == e_vertex[V_AMONT]);
163 // =============================================================== setScalar
164 inline void Edge::setScalar (double val)
166 e_vertex [V_AMONT]->setScalar (val);
167 e_vertex [V_AVAL ]->setScalar (val);
169 // =============================================================== duplicate
170 inline void Edge::duplicate ()
172 e_clone = new Edge (GetClone (e_vertex [V_AMONT]),
173 GetClone (e_vertex [V_AVAL ]));
175 e_clone->tab_assoc = tab_assoc;
177 // =============================================================== getVector
178 inline double* Edge::getVector (double vecteur[])
181 if (e_vertex[V_AMONT]==NULL || e_vertex[V_AVAL]==NULL)
183 vecteur [dir_x] = vecteur [dir_y] = vecteur [dir_z] = 0;
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();