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>
56 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
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);
160 aMPKLE.Add(aPKE1, aLE);
165 //=======================================================================
166 //function : FindSDShapes
168 //=======================================================================
169 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopTools_ListOfShape& aLE,
170 const Standard_Real aTol,
171 TopTools_IndexedDataMapOfShapeListOfShape& aMEE,
172 IntTools_Context& aCtx)
174 Standard_Integer aNbE, aNbEProcessed, aNbESD, iErr;
175 TopTools_ListOfShape aLESD;
176 TopTools_ListIteratorOfListOfShape aIt, aIt1;
177 TopTools_IndexedMapOfShape aMProcessed;
178 TopAbs_ShapeEnum aType;
184 //modified by NIZNHY-PKV Thu Dec 30 10:56:52 2004 f
186 return 0; // Nothing to do
188 //modified by NIZNHY-PKV Thu Dec 30 10:56:56 2004 t
191 aNbEProcessed=aMProcessed.Extent();
192 if (aNbEProcessed==aNbE) {
197 for (; aIt.More(); aIt.Next()) {
198 const TopoDS_Shape& aS=aIt.Value();
200 if (aMProcessed.Contains(aS)) {
204 //modified by NIZNHY-PKV Thu Dec 30 10:57:01 2004 f
205 aType=aS.ShapeType();
206 if (aType==TopAbs_EDGE) {
207 const TopoDS_Edge& aE=TopoDS::Edge(aS);
208 if (BRep_Tool::Degenerated(aE)) {
213 //modified by NIZNHY-PKV Thu Dec 30 10:57:03 2004 t
216 iErr=GEOMAlgo_Tools::FindSDShapes(aS, aLE, aTol, aLESD, aCtx);
221 aNbESD=aLESD.Extent();
228 aIt1.Initialize(aLESD);
229 for (; aIt1.More(); aIt1.Next()) {
230 const TopoDS_Shape& aE1=aIt1.Value();
231 aMProcessed.Add(aE1);
237 //=======================================================================
238 //function : FindSDShapes
240 //=======================================================================
241 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopoDS_Shape& aE1,
242 const TopTools_ListOfShape& aLE,
243 const Standard_Real aTol,
244 TopTools_ListOfShape& aLESD,
245 IntTools_Context& aCtx)
247 Standard_Boolean bIsDone;
248 Standard_Real aTol2, aD2;
250 TopTools_ListIteratorOfListOfShape aIt;
253 GEOMAlgo_Tools::PointOnShape(aE1, aP1);
256 for (; aIt.More(); aIt.Next()) {
257 const TopoDS_Shape& aE2=aIt.Value();
258 if (aE2.IsSame(aE1)) {
262 bIsDone=GEOMAlgo_Tools::ProjectPointOnShape(aP1, aE2, aP2, aCtx);
266 aD2=aP1.SquareDistance(aP2);
275 //=======================================================================
276 //function : ProjectPointOnShape
278 //=======================================================================
279 Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
280 const TopoDS_Shape& aS,
282 IntTools_Context& aCtx)
284 Standard_Boolean bIsDone=Standard_False;
286 TopAbs_ShapeEnum aType;
288 aType=aS.ShapeType();
291 const TopoDS_Edge& aE2=TopoDS::Edge(aS);
293 bIsDone=aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
298 GEOMAlgo_Tools::PointOnEdge(aE2, aT2, aP2);
303 const TopoDS_Face& aF2=TopoDS::Face(aS);
304 GeomAPI_ProjectPointOnSurf& aProj=aCtx.ProjPS(aF2);
307 bIsDone=aProj.IsDone();
312 aP2=aProj.NearestPoint();
321 //=======================================================================
322 //function : PointOnShape
324 //=======================================================================
325 void GEOMAlgo_Tools::PointOnShape(const TopoDS_Shape& aS,
328 TopAbs_ShapeEnum aType;
330 aP3D.SetCoord(99.,99.,99.);
331 aType=aS.ShapeType();
334 const TopoDS_Edge& aE=TopoDS::Edge(aS);
335 GEOMAlgo_Tools::PointOnEdge(aE, aP3D);
340 const TopoDS_Face& aF=TopoDS::Face(aS);
341 GEOMAlgo_Tools::PointOnFace(aF, aP3D);
349 //=======================================================================
350 //function : PointOnFace
352 //=======================================================================
353 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
356 Standard_Real aU, aV, aUMin, aUMax, aVMin, aVMax;
358 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
360 aU=BOPTools_Tools2D::IntermediatePoint(aUMin, aUMax);
361 aV=BOPTools_Tools2D::IntermediatePoint(aVMin, aVMax);
363 GEOMAlgo_Tools::PointOnFace(aF, aU, aV, aP3D);
365 //=======================================================================
366 //function : PointOnFace
368 //=======================================================================
369 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
370 const Standard_Real aU,
371 const Standard_Real aV,
374 Handle(Geom_Surface) aS;
376 aS=BRep_Tool::Surface(aF);
377 aS->D0(aU, aV, aP3D);
379 //=======================================================================
380 //function : PointOnEdge
382 //=======================================================================
383 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
386 Standard_Real aTx, aT1, aT2;
388 BRep_Tool::Curve(aE, aT1, aT2);
389 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
390 GEOMAlgo_Tools::PointOnEdge(aE, aTx, aP3D);
392 //=======================================================================
393 //function : PointOnEdge
395 //=======================================================================
396 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
397 const Standard_Real aT,
400 Standard_Real aT1, aT2;
401 Handle(Geom_Curve) aC3D;
403 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
406 //=======================================================================
407 //function : RefinePCurveForEdgeOnFace
409 //=======================================================================
410 void GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(const TopoDS_Edge& aE,
411 const TopoDS_Face& aF,
412 const Standard_Real aUMin,
413 const Standard_Real aUMax)
415 Standard_Real aT1, aT2, aTx, aUx, aTol, aTwoPI;
417 Handle(Geom_Surface) aS;
418 Handle(Geom2d_Curve) aC2D;
423 aC2D=BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
424 if (!aC2D.IsNull()) {
425 if (BRep_Tool::IsClosed(aE, aF)) {
428 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
431 if (aUx < aUMin || aUx > aUMax) {
433 Handle(Geom2d_Curve) aC2Dx;
435 aTol=BRep_Tool::Tolerance(aE);
436 aBB.UpdateEdge(aE, aC2Dx, aF, aTol);
440 //=======================================================================
441 //function : IsUPeriodic
443 //=======================================================================
444 Standard_Boolean GEOMAlgo_Tools::IsUPeriodic(const Handle(Geom_Surface) &aS)
446 Standard_Boolean bRet;
447 GeomAbs_SurfaceType aType;
448 GeomAdaptor_Surface aGAS;
451 aType=aGAS.GetType();
452 bRet=(aType==GeomAbs_Cylinder||
453 aType==GeomAbs_Cone ||
454 aType==GeomAbs_Sphere);