1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: GEOMAlgo_Tools.cxx
21 // Created: Mon Dec 6 11:35:29 2004
22 // Author: Peter KURNEV
25 #include <GEOMAlgo_Tools.ixx>
28 #include <gp_Pnt2d.hxx>
30 #include <Geom_Surface.hxx>
31 #include <Geom_Curve.hxx>
32 #include <Geom2d_Curve.hxx>
33 #include <GeomAdaptor_Surface.hxx>
35 #include <GeomAPI_ProjectPointOnSurf.hxx>
37 #include <TopAbs_ShapeEnum.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TopoDS_Iterator.hxx>
44 #include <TopTools_ListOfShape.hxx>
45 #include <TopTools_ListIteratorOfListOfShape.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <BRep_Tool.hxx>
49 #include <BRep_Builder.hxx>
50 #include <BRepTools.hxx>
52 #include <BOPTools_Tools2D.hxx>
53 #include <IntTools_Context.hxx>
55 #include <GEOMAlgo_PassKeyShape.hxx>//qft
56 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>//qft
59 void GetCount(const TopoDS_Shape& aS,
60 Standard_Integer& iCnt);
62 //=======================================================================
63 //function : IsCompositeShape
65 //=======================================================================
66 Standard_Boolean GEOMAlgo_Tools::IsCompositeShape(const TopoDS_Shape& aS)
68 Standard_Boolean bRet;
69 Standard_Integer iCnt;
79 //=======================================================================
82 //=======================================================================
83 void GetCount(const TopoDS_Shape& aS,
84 Standard_Integer& iCnt)
91 if (aTS==TopAbs_SHAPE) {
94 if (aTS!=TopAbs_COMPOUND) {
100 for (; aIt.More(); aIt.Next()) {
101 const TopoDS_Shape& aSx=aIt.Value();
106 //=======================================================================
107 //function : RefineSDShapes
109 //=======================================================================
110 Standard_Integer GEOMAlgo_Tools::RefineSDShapes(GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape& aMPKLE,
111 const Standard_Real aTol,
112 IntTools_Context& aCtx)
114 Standard_Integer i, aNbE, iErr, j, aNbEE, aNbToAdd;
115 TopTools_IndexedDataMapOfShapeListOfShape aMEE, aMSDE, aMEToAdd;
119 aNbE=aMPKLE.Extent();
120 for (i=1; i<=aNbE; ++i) {
121 TopTools_ListOfShape& aLSDE=aMPKLE.ChangeFromIndex(i);
124 iErr=GEOMAlgo_Tools::FindSDShapes(aLSDE, aTol, aMEE, aCtx);
131 continue; // nothing to do
134 for (j=1; j<=aNbEE; ++j) {
135 TopTools_ListOfShape& aLEE=aMEE.ChangeFromIndex(j);
142 const TopoDS_Shape& aE1=aLEE.First();
143 aMEToAdd.Add(aE1, aLEE);
148 aNbToAdd=aMEToAdd.Extent();
153 for (i=1; i<=aNbToAdd; ++i) {
154 GEOMAlgo_PassKeyShape aPKE1;
156 const TopoDS_Shape& aE1=aMEToAdd.FindKey(i);
157 const TopTools_ListOfShape& aLE=aMEToAdd(i);
161 aPKE1.SetShapes(aE1);
163 aMPKLE.Add(aPKE1, aLE);
168 //=======================================================================
169 //function : FindSDShapes
171 //=======================================================================
172 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopTools_ListOfShape& aLE,
173 const Standard_Real aTol,
174 TopTools_IndexedDataMapOfShapeListOfShape& aMEE,
175 IntTools_Context& aCtx)
177 Standard_Integer aNbE, aNbEProcessed, aNbESD, iErr;
178 TopTools_ListOfShape aLESD;
179 TopTools_ListIteratorOfListOfShape aIt, aIt1;
180 TopTools_IndexedMapOfShape aMProcessed;
181 TopAbs_ShapeEnum aType;
187 //modified by NIZNHY-PKV Thu Dec 30 10:56:52 2004 f
189 return 0; // Nothing to do
191 //modified by NIZNHY-PKV Thu Dec 30 10:56:56 2004 t
194 aNbEProcessed=aMProcessed.Extent();
195 if (aNbEProcessed==aNbE) {
200 for (; aIt.More(); aIt.Next()) {
201 const TopoDS_Shape& aS=aIt.Value();
203 if (aMProcessed.Contains(aS)) {
207 //modified by NIZNHY-PKV Thu Dec 30 10:57:01 2004 f
208 aType=aS.ShapeType();
209 if (aType==TopAbs_EDGE) {
210 const TopoDS_Edge& aE=TopoDS::Edge(aS);
211 if (BRep_Tool::Degenerated(aE)) {
216 //modified by NIZNHY-PKV Thu Dec 30 10:57:03 2004 t
219 iErr=GEOMAlgo_Tools::FindSDShapes(aS, aLE, aTol, aLESD, aCtx);
224 aNbESD=aLESD.Extent();
231 aIt1.Initialize(aLESD);
232 for (; aIt1.More(); aIt1.Next()) {
233 const TopoDS_Shape& aE1=aIt1.Value();
234 aMProcessed.Add(aE1);
240 //=======================================================================
241 //function : FindSDShapes
243 //=======================================================================
244 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopoDS_Shape& aE1,
245 const TopTools_ListOfShape& aLE,
246 const Standard_Real aTol,
247 TopTools_ListOfShape& aLESD,
248 IntTools_Context& aCtx)
250 Standard_Boolean bIsDone;
251 Standard_Real aTol2, aD2;
253 TopTools_ListIteratorOfListOfShape aIt;
256 GEOMAlgo_Tools::PointOnShape(aE1, aP1);
259 for (; aIt.More(); aIt.Next()) {
260 const TopoDS_Shape& aE2=aIt.Value();
261 if (aE2.IsSame(aE1)) {
265 bIsDone=GEOMAlgo_Tools::ProjectPointOnShape(aP1, aE2, aP2, aCtx);
269 aD2=aP1.SquareDistance(aP2);
278 //=======================================================================
279 //function : ProjectPointOnShape
281 //=======================================================================
282 Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
283 const TopoDS_Shape& aS,
285 IntTools_Context& aCtx)
287 Standard_Boolean bIsDone=Standard_False;
289 TopAbs_ShapeEnum aType;
291 aType=aS.ShapeType();
294 const TopoDS_Edge& aE2=TopoDS::Edge(aS);
296 bIsDone=aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
301 GEOMAlgo_Tools::PointOnEdge(aE2, aT2, aP2);
306 const TopoDS_Face& aF2=TopoDS::Face(aS);
307 GeomAPI_ProjectPointOnSurf& aProj=aCtx.ProjPS(aF2);
310 bIsDone=aProj.IsDone();
315 aP2=aProj.NearestPoint();
324 //=======================================================================
325 //function : PointOnShape
327 //=======================================================================
328 void GEOMAlgo_Tools::PointOnShape(const TopoDS_Shape& aS,
331 TopAbs_ShapeEnum aType;
333 aP3D.SetCoord(99.,99.,99.);
334 aType=aS.ShapeType();
337 const TopoDS_Edge& aE=TopoDS::Edge(aS);
338 GEOMAlgo_Tools::PointOnEdge(aE, aP3D);
343 const TopoDS_Face& aF=TopoDS::Face(aS);
344 GEOMAlgo_Tools::PointOnFace(aF, aP3D);
352 //=======================================================================
353 //function : PointOnFace
355 //=======================================================================
356 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
359 Standard_Real aU, aV, aUMin, aUMax, aVMin, aVMax;
361 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
363 aU=BOPTools_Tools2D::IntermediatePoint(aUMin, aUMax);
364 aV=BOPTools_Tools2D::IntermediatePoint(aVMin, aVMax);
366 GEOMAlgo_Tools::PointOnFace(aF, aU, aV, aP3D);
368 //=======================================================================
369 //function : PointOnFace
371 //=======================================================================
372 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
373 const Standard_Real aU,
374 const Standard_Real aV,
377 Handle(Geom_Surface) aS;
379 aS=BRep_Tool::Surface(aF);
380 aS->D0(aU, aV, aP3D);
382 //=======================================================================
383 //function : PointOnEdge
385 //=======================================================================
386 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
389 Standard_Real aTx, aT1, aT2;
391 BRep_Tool::Curve(aE, aT1, aT2);
392 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
393 GEOMAlgo_Tools::PointOnEdge(aE, aTx, aP3D);
395 //=======================================================================
396 //function : PointOnEdge
398 //=======================================================================
399 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
400 const Standard_Real aT,
403 Standard_Real aT1, aT2;
404 Handle(Geom_Curve) aC3D;
406 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
409 //=======================================================================
410 //function : RefinePCurveForEdgeOnFace
412 //=======================================================================
413 void GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(const TopoDS_Edge& aE,
414 const TopoDS_Face& aF,
415 const Standard_Real aUMin,
416 const Standard_Real aUMax)
418 Standard_Real aT1, aT2, aTx, aUx, aTol, aTwoPI;
420 Handle(Geom_Surface) aS;
421 Handle(Geom2d_Curve) aC2D;
426 aC2D=BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
427 if (!aC2D.IsNull()) {
428 if (BRep_Tool::IsClosed(aE, aF)) {
431 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
434 if (aUx < aUMin || aUx > aUMax) {
436 Handle(Geom2d_Curve) aC2Dx;
438 aTol=BRep_Tool::Tolerance(aE);
439 aBB.UpdateEdge(aE, aC2Dx, aF, aTol);
443 //=======================================================================
444 //function : IsUPeriodic
446 //=======================================================================
447 Standard_Boolean GEOMAlgo_Tools::IsUPeriodic(const Handle(Geom_Surface) &aS)
449 Standard_Boolean bRet;
450 GeomAbs_SurfaceType aType;
451 GeomAdaptor_Surface aGAS;
454 aType=aGAS.GetType();
455 bRet=(aType==GeomAbs_Cylinder||
456 aType==GeomAbs_Cone ||
457 aType==GeomAbs_Sphere);