2 // C++ : Gestion des soous-shapes
4 // Copyright (C) 2009-2016 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, or (at your option) any later version.
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
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>
37 #include <Geom_Circle.hxx>
40 #include <Standard_Stream.hxx>
41 #include <GEOMImpl_IMeasureOperations.hxx>
42 #include <GEOMImpl_Types.hxx>
43 #include <GEOMImpl_MeasureDriver.hxx>
44 #include <GEOMImpl_IMeasure.hxx>
45 #include <GEOMImpl_IShapesOperations.hxx>
46 #include <GEOMUtils.hxx>
47 #include <GEOMAlgo_ShapeInfo.hxx>
48 #include <GEOMAlgo_ShapeInfoFiller.hxx>
49 *********************************/
53 static bool db = on_debug (); // == getenv ("HEXA_DB") > 0
55 // ====================================================== Constructeur
56 EdgeShape::EdgeShape (NewShape* dad, int id)
57 : SubShape (dad, id, 1)
62 lin_start [dir_x] = lin_start [dir_y] = lin_start [dir_z] = 0;
63 lin_end [dir_x] = lin_end [dir_y] = lin_end [dir_z] = 0;
69 // ====================================================== getCurve
70 BRepAdaptor_Curve* EdgeShape::getCurve ()
77 // ====================================================== makeCurve
78 BRepAdaptor_Curve* EdgeShape::makeCurve ()
83 TopoDS_Edge geo_line = TopoDS::Edge (geo_shape);
84 BRepAdaptor_Curve* curve = new BRepAdaptor_Curve (geo_line);
87 // ====================================================== getCoords
88 void EdgeShape::getCoords (double* pstart, double* pend)
93 for (int nc=0 ; nc<DIM3 ; nc++)
95 pstart [nc] = lin_start [nc];
96 pend [nc] = lin_end [nc];
99 // ====================================================== getLength
100 double EdgeShape::getLength ()
107 // ====================================================== getPoint
108 int EdgeShape::getPoint (double param, double* point)
110 if (param < -0.01 || param > 1.01)
112 point [dir_x] = point [dir_y] = point [dir_z] = 0;
115 else if (param < 0.01)
117 else if (param > 0.99)
123 GCPnts_AbscissaPoint s1 (*lin_curve, param*lin_length,
124 lin_curve->FirstParameter());
126 double para1 = s1.Parameter ();
127 gp_Pnt gpnt = lin_curve->Value (para1);
129 point [dir_x] = gpnt.X();
130 point [dir_y] = gpnt.Y();
131 point [dir_z] = gpnt.Z();
134 // ========================================================= samePoints
135 bool EdgeShape::samePoints (double* point1, double* point2)
137 const double Epsilon2 = 1e-4;
138 bool rep = same_coords (point1, point2, Epsilon2);
141 // ========================================================= onExtremity
142 int EdgeShape::onExtremity (double* point)
147 if (samePoints (point, lin_start))
149 else if (samePoints (point, lin_end))
154 // ========================================================= definedBy
155 bool EdgeShape::definedBy (double p1[], double p2[])
161 if (samePoints (p1, lin_start))
162 rep = samePoints (p2, lin_end);
163 else if (samePoints (p1, lin_end))
164 rep = samePoints (p2, lin_start);
167 // ========================================================= getParam
168 double EdgeShape::getParam (double* coord)
173 if (samePoints (coord, lin_start))
175 else if (samePoints (coord, lin_end))
178 double umin = 0, umax = 0;
179 gp_Pnt gpoint (coord[dir_x], coord[dir_y], coord[dir_z]);
181 TopoDS_Edge geo_line = TopoDS::Edge (geo_shape);
182 Handle(Geom_Curve) handle = BRep_Tool::Curve (geo_line, umin, umax);
184 GeomAPI_ProjectPointOnCurve projector (gpoint, handle);
185 if ( projector.NbPoints() == 0 )
188 double gparam = projector.LowerDistanceParameter();
189 if (gparam <par_mini || gparam>par_maxi)
192 gp_Pnt rpoint = lin_curve->Value (gparam);
193 Real3 rcoord = { rpoint.X(), rpoint.Y(), rpoint.Z() };
195 if (NOT samePoints (coord, rcoord))
198 GeomAdaptor_Curve adapt_curve (handle);
201 enum GeomAbs_CurveType { GeomAbs_Line, GeomAbs_Circle, GeomAbs_Ellipse,
202 GeomAbs_Hyperbola, GeomAbs_Parabola, GeomAbs_BezierCurve,
203 GeomAbs_BSplineCurve, GeomAbs_OtherCurve };
204 **********************/
206 double abscis = GCPnts_AbscissaPoint::Length (adapt_curve, umin, gparam);
207 double hparam = abscis/lin_length;
209 // gparam = (gparam-par_mini) / (par_maxi-par_mini);
212 // ====================================================== getAssociation
213 Edge* EdgeShape::getAssociation (int nro)
215 if (nro>0 && nro<(int)tab_assoc.size())
216 return tab_assoc[nro];
220 // ==================================================== addAssociation
221 void EdgeShape::addAssociation (Edge* edge)
223 tab_assoc.push_back (edge);
224 is_associated = true;
226 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
228 // ------- Cf GEOMImpl_IMeasureOperations.cxx
230 // ====================================================== updateCurve
231 void EdgeShape::updateCurve ()
239 TopoDS_Edge geo_line = TopoDS::Edge (geo_shape);
240 lin_curve = new BRepAdaptor_Curve (geo_line);
241 // Longueur de la ligne
242 double umin = 0, umax = 0;
244 Handle(Geom_Curve) handle = BRep_Tool::Curve (geo_line, loc, umin, umax);
245 GeomAdaptor_Curve adapt_curve (handle);
246 lin_length = GCPnts_AbscissaPoint::Length(adapt_curve, umin, umax);
249 GCPnts_AbscissaPoint s1(*lin_curve, 0, lin_curve->FirstParameter());
250 GCPnts_AbscissaPoint s2(*lin_curve, lin_length, lin_curve->FirstParameter());
252 par_mini = s1.Parameter ();
253 par_maxi = s2.Parameter ();
255 getPoint (0, lin_start);
256 getPoint (1, lin_end);
258 lin_radius = lin_angle = 0;
259 kind_of = (EnumKindOfShape) adapt_curve.GetType();
261 if (kind_of==KS_Circle)
263 Handle(Geom_Circle) hgc = Handle(Geom_Circle)::DownCast (handle);
264 lin_radius = hgc->Radius ();
265 lin_angle = (par_maxi-par_mini)*180/M_PI;
269 // ====================================================== getAngle
270 double EdgeShape::getAngle ()
277 // ====================================================== getRadius
278 double EdgeShape::getRadius ()
285 // ====================================================== getRadius
286 EnumKindOfShape EdgeShape::kindOf ()