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/ or email : webmaster.salome@opencascade.com
23 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
25 #include "HexEdgeShape.hxx"
30 #include <TopoDS_Edge.hxx>
33 #include <BRep_Builder.hxx>
34 #include <BRepAdaptor_Curve.hxx>
36 #include <GCPnts_AbscissaPoint.hxx>
38 #include <GeomAPI_ProjectPointOnCurve.hxx>
42 static bool db = on_debug (); // == getenv ("HEXA_DB") > 0
44 // ====================================================== Constructeur
45 EdgeShape::EdgeShape (NewShape* dad, int id)
46 : SubShape (dad, id, 1)
51 lin_start [dir_x] = lin_start [dir_y] = lin_start [dir_z] = 0;
52 lin_end [dir_x] = lin_end [dir_y] = lin_end [dir_z] = 0;
56 // ====================================================== getCurve
57 BRepAdaptor_Curve* EdgeShape::getCurve ()
64 // ====================================================== makeCurve
65 BRepAdaptor_Curve* EdgeShape::makeCurve ()
70 TopoDS_Edge geo_line = TopoDS::Edge (geo_shape);
71 BRepAdaptor_Curve* curve = new BRepAdaptor_Curve (geo_line);
74 // ====================================================== getCoords
75 void EdgeShape::getCoords (double* pstart, double* pend)
80 for (int nc=0 ; nc<DIM3 ; nc++)
82 pstart [nc] = lin_start [nc];
83 pend [nc] = lin_end [nc];
86 // ====================================================== getLength
87 double EdgeShape::getLength ()
94 // ====================================================== getPoint
95 int EdgeShape::getPoint (double param, double* point)
97 if (param < -0.01 || param > 1.01)
99 point [dir_x] = point [dir_y] = point [dir_z] = 0;
102 else if (param < 0.01)
104 else if (param > 0.99)
110 GCPnts_AbscissaPoint s1 (*lin_curve, param*lin_length,
111 lin_curve->FirstParameter());
113 double para1 = s1.Parameter ();
114 gp_Pnt gpnt = lin_curve->Value (para1);
116 point [dir_x] = gpnt.X();
117 point [dir_y] = gpnt.Y();
118 point [dir_z] = gpnt.Z();
121 // ========================================================= samePoints
122 bool EdgeShape::samePoints (double* point1, double* point2)
124 const double Epsilon2 = 1e-4;
125 bool rep = same_coords (point1, point2, Epsilon2);
128 // ========================================================= onExtremity
129 int EdgeShape::onExtremity (double* point)
134 if (samePoints (point, lin_start))
136 else if (samePoints (point, lin_end))
141 // ========================================================= getParam
142 double EdgeShape::getParam (double* coord)
147 if (samePoints (coord, lin_start))
149 else if (samePoints (coord, lin_end))
152 double umin = 0, umax = 0;
153 gp_Pnt gpoint (coord[dir_x], coord[dir_y], coord[dir_z]);
155 TopoDS_Edge geo_line = TopoDS::Edge (geo_shape);
156 Handle(Geom_Curve) handle = BRep_Tool::Curve (geo_line, umin, umax);
158 GeomAPI_ProjectPointOnCurve projector (gpoint, handle);
159 if ( projector.NbPoints() == 0 )
162 double gparam = projector.LowerDistanceParameter();
163 if (gparam <par_mini || gparam>par_maxi)
166 gp_Pnt rpoint = lin_curve->Value (gparam);
167 Real3 rcoord = { rpoint.X(), rpoint.Y(), rpoint.Z() };
169 if (NOT samePoints (coord, rcoord))
172 GeomAdaptor_Curve adapt_curve (handle);
173 double abscis = GCPnts_AbscissaPoint::Length (adapt_curve, umin, gparam);
174 double hparam = abscis/lin_length;
176 // gparam = (gparam-par_mini) / (par_maxi-par_mini);
179 // ====================================================== getAssociation
180 Edge* EdgeShape::getAssociation (int nro)
182 if (nro>0 && nro<tab_assoc.size())
183 return tab_assoc[nro];
187 // ========================================================== addAssociation
188 void EdgeShape::addAssociation (Edge* edge)
190 tab_assoc.push_back (edge);
191 is_associated = true;
193 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
194 // ====================================================== updateCurve
195 void EdgeShape::updateCurve ()
203 TopoDS_Edge geo_line = TopoDS::Edge (geo_shape);
204 lin_curve = new BRepAdaptor_Curve (geo_line);
205 // Longueur de la ligne
206 double umin = 0, umax = 0;
208 Handle(Geom_Curve) handle = BRep_Tool::Curve (geo_line, loc, umin, umax);
209 GeomAdaptor_Curve adapt_curve (handle);
210 lin_length = GCPnts_AbscissaPoint::Length(adapt_curve, umin, umax);
213 GCPnts_AbscissaPoint s1(*lin_curve, 0, lin_curve->FirstParameter());
214 GCPnts_AbscissaPoint s2(*lin_curve, lin_length, lin_curve->FirstParameter());
216 par_mini = s1.Parameter ();
217 par_maxi = s2.Parameter ();
219 getPoint (0, lin_start);
220 getPoint (1, lin_end);