2 // C++ : Gestion des soous-shapes
4 // Copyright (C) 2009-2013 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/
21 // or email : webmaster.salome@opencascade.com
23 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
25 #include "HexEdgeShape.hxx"
28 #include <TopoDS_Edge.hxx>
31 #include <BRep_Builder.hxx>
32 #include <BRepAdaptor_Curve.hxx>
34 #include <GCPnts_AbscissaPoint.hxx>
36 #include <GeomAPI_ProjectPointOnCurve.hxx>
40 static bool db = on_debug (); // == getenv ("HEXA_DB") > 0
42 // ====================================================== Constructeur
43 EdgeShape::EdgeShape (NewShape* dad, int id)
44 : SubShape (dad, id, 1)
49 lin_start [dir_x] = lin_start [dir_y] = lin_start [dir_z] = 0;
50 lin_end [dir_x] = lin_end [dir_y] = lin_end [dir_z] = 0;
54 // ====================================================== getCurve
55 BRepAdaptor_Curve* EdgeShape::getCurve ()
62 // ====================================================== makeCurve
63 BRepAdaptor_Curve* EdgeShape::makeCurve ()
68 TopoDS_Edge geo_line = TopoDS::Edge (geo_shape);
69 BRepAdaptor_Curve* curve = new BRepAdaptor_Curve (geo_line);
72 // ====================================================== getCoords
73 void EdgeShape::getCoords (double* pstart, double* pend)
78 for (int nc=0 ; nc<DIM3 ; nc++)
80 pstart [nc] = lin_start [nc];
81 pend [nc] = lin_end [nc];
84 // ====================================================== getLength
85 double EdgeShape::getLength ()
92 // ====================================================== getPoint
93 int EdgeShape::getPoint (double param, double* point)
95 if (param < -0.01 || param > 1.01)
97 point [dir_x] = point [dir_y] = point [dir_z] = 0;
100 else if (param < 0.01)
102 else if (param > 0.99)
108 GCPnts_AbscissaPoint s1 (*lin_curve, param*lin_length,
109 lin_curve->FirstParameter());
111 double para1 = s1.Parameter ();
112 gp_Pnt gpnt = lin_curve->Value (para1);
114 point [dir_x] = gpnt.X();
115 point [dir_y] = gpnt.Y();
116 point [dir_z] = gpnt.Z();
119 // ========================================================= samePoints
120 bool EdgeShape::samePoints (double* point1, double* point2)
122 const double Epsilon2 = 1e-4;
123 bool rep = same_coords (point1, point2, Epsilon2);
126 // ========================================================= onExtremity
127 int EdgeShape::onExtremity (double* point)
132 if (samePoints (point, lin_start))
134 else if (samePoints (point, lin_end))
139 // ========================================================= getParam
140 double EdgeShape::getParam (double* coord)
145 if (samePoints (coord, lin_start))
147 else if (samePoints (coord, lin_end))
150 double umin = 0, umax = 0;
151 gp_Pnt gpoint (coord[dir_x], coord[dir_y], coord[dir_z]);
153 TopoDS_Edge geo_line = TopoDS::Edge (geo_shape);
154 Handle(Geom_Curve) handle = BRep_Tool::Curve (geo_line, umin, umax);
156 GeomAPI_ProjectPointOnCurve projector (gpoint, handle);
157 if ( projector.NbPoints() == 0 )
160 double gparam = projector.LowerDistanceParameter();
161 if (gparam <par_mini || gparam>par_maxi)
164 gp_Pnt rpoint = lin_curve->Value (gparam);
165 Real3 rcoord = { rpoint.X(), rpoint.Y(), rpoint.Z() };
167 if (NOT samePoints (coord, rcoord))
170 GeomAdaptor_Curve adapt_curve (handle);
171 double abscis = GCPnts_AbscissaPoint::Length (adapt_curve, umin, gparam);
172 double hparam = abscis/lin_length;
174 // gparam = (gparam-par_mini) / (par_maxi-par_mini);
177 // ====================================================== getAssociation
178 Edge* EdgeShape::getAssociation (int nro)
180 if (nro>0 && nro<(int)tab_assoc.size())
181 return tab_assoc[nro];
185 // ==================================================== addAssociation
186 void EdgeShape::addAssociation (Edge* edge)
188 tab_assoc.push_back (edge);
189 is_associated = true;
191 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
192 // ====================================================== updateCurve
193 void EdgeShape::updateCurve ()
201 TopoDS_Edge geo_line = TopoDS::Edge (geo_shape);
202 lin_curve = new BRepAdaptor_Curve (geo_line);
203 // Longueur de la ligne
204 double umin = 0, umax = 0;
206 Handle(Geom_Curve) handle = BRep_Tool::Curve (geo_line, loc, umin, umax);
207 GeomAdaptor_Curve adapt_curve (handle);
208 lin_length = GCPnts_AbscissaPoint::Length(adapt_curve, umin, umax);
211 GCPnts_AbscissaPoint s1(*lin_curve, 0, lin_curve->FirstParameter());
212 GCPnts_AbscissaPoint s2(*lin_curve, lin_length, lin_curve->FirstParameter());
214 par_mini = s1.Parameter ();
215 par_maxi = s2.Parameter ();
217 getPoint (0, lin_start);
218 getPoint (1, lin_end);