1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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
22 // File: GEOMAlgo_Tools.cxx
23 // Created: Mon Dec 6 11:35:29 2004
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_Tools.ixx>
29 #include <gp_Pnt2d.hxx>
31 #include <Geom_Surface.hxx>
32 #include <Geom_Curve.hxx>
33 #include <Geom2d_Curve.hxx>
34 #include <GeomAdaptor_Surface.hxx>
36 #include <GeomAPI_ProjectPointOnSurf.hxx>
38 #include <TopAbs_ShapeEnum.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <TopoDS_Iterator.hxx>
45 #include <TopTools_ListOfShape.hxx>
46 #include <TopTools_ListIteratorOfListOfShape.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <BRep_Tool.hxx>
50 #include <BRep_Builder.hxx>
51 #include <BRepTools.hxx>
53 #include <BOPTools_Tools2D.hxx>
54 #include <IntTools_Context.hxx>
56 #include <GEOMAlgo_PassKeyShape.hxx>//qft
57 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>//qft
60 void GetCount(const TopoDS_Shape& aS,
61 Standard_Integer& iCnt);
63 //=======================================================================
64 //function : IsCompositeShape
66 //=======================================================================
67 Standard_Boolean GEOMAlgo_Tools::IsCompositeShape(const TopoDS_Shape& aS)
69 Standard_Boolean bRet;
70 Standard_Integer iCnt;
80 //=======================================================================
83 //=======================================================================
84 void GetCount(const TopoDS_Shape& aS,
85 Standard_Integer& iCnt)
92 if (aTS==TopAbs_SHAPE) {
95 if (aTS!=TopAbs_COMPOUND) {
101 for (; aIt.More(); aIt.Next()) {
102 const TopoDS_Shape& aSx=aIt.Value();
107 //=======================================================================
108 //function : RefineSDShapes
110 //=======================================================================
111 Standard_Integer GEOMAlgo_Tools::RefineSDShapes(GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape& aMPKLE,
112 const Standard_Real aTol,
113 IntTools_Context& aCtx)
115 Standard_Integer i, aNbE, iErr, j, aNbEE, aNbToAdd;
116 TopTools_IndexedDataMapOfShapeListOfShape aMEE, aMSDE, aMEToAdd;
120 aNbE=aMPKLE.Extent();
121 for (i=1; i<=aNbE; ++i) {
122 TopTools_ListOfShape& aLSDE=aMPKLE.ChangeFromIndex(i);
125 iErr=GEOMAlgo_Tools::FindSDShapes(aLSDE, aTol, aMEE, aCtx);
132 continue; // nothing to do
135 for (j=1; j<=aNbEE; ++j) {
136 TopTools_ListOfShape& aLEE=aMEE.ChangeFromIndex(j);
143 const TopoDS_Shape& aE1=aLEE.First();
144 aMEToAdd.Add(aE1, aLEE);
149 aNbToAdd=aMEToAdd.Extent();
154 for (i=1; i<=aNbToAdd; ++i) {
155 GEOMAlgo_PassKeyShape aPKE1;
157 const TopoDS_Shape& aE1=aMEToAdd.FindKey(i);
158 const TopTools_ListOfShape& aLE=aMEToAdd(i);
162 aPKE1.SetShapes(aE1);
164 aMPKLE.Add(aPKE1, aLE);
169 //=======================================================================
170 //function : FindSDShapes
172 //=======================================================================
173 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopTools_ListOfShape& aLE,
174 const Standard_Real aTol,
175 TopTools_IndexedDataMapOfShapeListOfShape& aMEE,
176 IntTools_Context& aCtx)
178 Standard_Integer aNbE, aNbEProcessed, aNbESD, iErr;
179 TopTools_ListOfShape aLESD;
180 TopTools_ListIteratorOfListOfShape aIt, aIt1;
181 TopTools_IndexedMapOfShape aMProcessed;
182 TopAbs_ShapeEnum aType;
188 //modified by NIZNHY-PKV Thu Dec 30 10:56:52 2004 f
190 return 0; // Nothing to do
192 //modified by NIZNHY-PKV Thu Dec 30 10:56:56 2004 t
195 aNbEProcessed=aMProcessed.Extent();
196 if (aNbEProcessed==aNbE) {
201 for (; aIt.More(); aIt.Next()) {
202 const TopoDS_Shape& aS=aIt.Value();
204 if (aMProcessed.Contains(aS)) {
208 //modified by NIZNHY-PKV Thu Dec 30 10:57:01 2004 f
209 aType=aS.ShapeType();
210 if (aType==TopAbs_EDGE) {
211 const TopoDS_Edge& aE=TopoDS::Edge(aS);
212 if (BRep_Tool::Degenerated(aE)) {
217 //modified by NIZNHY-PKV Thu Dec 30 10:57:03 2004 t
220 iErr=GEOMAlgo_Tools::FindSDShapes(aS, aLE, aTol, aLESD, aCtx);
225 aNbESD=aLESD.Extent();
232 aIt1.Initialize(aLESD);
233 for (; aIt1.More(); aIt1.Next()) {
234 const TopoDS_Shape& aE1=aIt1.Value();
235 aMProcessed.Add(aE1);
241 //=======================================================================
242 //function : FindSDShapes
244 //=======================================================================
245 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopoDS_Shape& aE1,
246 const TopTools_ListOfShape& aLE,
247 const Standard_Real aTol,
248 TopTools_ListOfShape& aLESD,
249 IntTools_Context& aCtx)
251 Standard_Boolean bIsDone;
252 Standard_Real aTol2, aD2;
254 TopTools_ListIteratorOfListOfShape aIt;
257 GEOMAlgo_Tools::PointOnShape(aE1, aP1);
260 for (; aIt.More(); aIt.Next()) {
261 const TopoDS_Shape& aE2=aIt.Value();
262 if (aE2.IsSame(aE1)) {
266 bIsDone=GEOMAlgo_Tools::ProjectPointOnShape(aP1, aE2, aP2, aCtx);
269 continue; // jfa BUG 20361
271 aD2=aP1.SquareDistance(aP2);
280 //=======================================================================
281 //function : ProjectPointOnShape
283 //=======================================================================
284 Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
285 const TopoDS_Shape& aS,
287 IntTools_Context& aCtx)
289 Standard_Boolean bIsDone = Standard_False;
291 TopAbs_ShapeEnum aType;
293 aType = aS.ShapeType();
298 const TopoDS_Edge& aE2 = TopoDS::Edge(aS);
300 if (BRep_Tool::Degenerated(aE2)) { // jfa
301 return Standard_True;
305 Handle(Geom_Curve) aC3D = BRep_Tool::Curve (aE2, f, l);
307 return Standard_True;
309 bIsDone = aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
315 GEOMAlgo_Tools::PointOnEdge(aE2, aT2, aP2);
321 const TopoDS_Face& aF2 = TopoDS::Face(aS);
322 GeomAPI_ProjectPointOnSurf& aProj = aCtx.ProjPS(aF2);
325 bIsDone = aProj.IsDone();
330 aP2 = aProj.NearestPoint();
339 //=======================================================================
340 //function : PointOnShape
342 //=======================================================================
343 void GEOMAlgo_Tools::PointOnShape(const TopoDS_Shape& aS,
346 TopAbs_ShapeEnum aType;
348 aP3D.SetCoord(99.,99.,99.);
349 aType=aS.ShapeType();
352 const TopoDS_Edge& aE=TopoDS::Edge(aS);
353 GEOMAlgo_Tools::PointOnEdge(aE, aP3D);
358 const TopoDS_Face& aF=TopoDS::Face(aS);
359 GEOMAlgo_Tools::PointOnFace(aF, aP3D);
367 //=======================================================================
368 //function : PointOnFace
370 //=======================================================================
371 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
374 Standard_Real aU, aV, aUMin, aUMax, aVMin, aVMax;
376 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
378 aU=BOPTools_Tools2D::IntermediatePoint(aUMin, aUMax);
379 aV=BOPTools_Tools2D::IntermediatePoint(aVMin, aVMax);
381 GEOMAlgo_Tools::PointOnFace(aF, aU, aV, aP3D);
383 //=======================================================================
384 //function : PointOnFace
386 //=======================================================================
387 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
388 const Standard_Real aU,
389 const Standard_Real aV,
392 Handle(Geom_Surface) aS;
394 aS=BRep_Tool::Surface(aF);
395 aS->D0(aU, aV, aP3D);
397 //=======================================================================
398 //function : PointOnEdge
400 //=======================================================================
401 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
404 Standard_Real aTx, aT1, aT2;
406 BRep_Tool::Curve(aE, aT1, aT2);
407 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
408 GEOMAlgo_Tools::PointOnEdge(aE, aTx, aP3D);
410 //=======================================================================
411 //function : PointOnEdge
413 //=======================================================================
414 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
415 const Standard_Real aT,
418 Standard_Real aT1, aT2;
419 Handle(Geom_Curve) aC3D;
421 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
424 //=======================================================================
425 //function : RefinePCurveForEdgeOnFace
427 //=======================================================================
428 void GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(const TopoDS_Edge& aE,
429 const TopoDS_Face& aF,
430 const Standard_Real aUMin,
431 const Standard_Real aUMax)
433 Standard_Real aT1, aT2, aTx, aUx, aTol;
435 Handle(Geom_Surface) aS;
436 Handle(Geom2d_Curve) aC2D;
439 aC2D=BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
440 if (!aC2D.IsNull()) {
441 if (BRep_Tool::IsClosed(aE, aF)) {
444 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
447 if (aUx < aUMin || aUx > aUMax) {
449 Handle(Geom2d_Curve) aC2Dx;
451 aTol=BRep_Tool::Tolerance(aE);
452 aBB.UpdateEdge(aE, aC2Dx, aF, aTol);
456 //=======================================================================
457 //function : IsUPeriodic
459 //=======================================================================
460 Standard_Boolean GEOMAlgo_Tools::IsUPeriodic(const Handle(Geom_Surface) &aS)
462 Standard_Boolean bRet;
463 GeomAbs_SurfaceType aType;
464 GeomAdaptor_Surface aGAS;
467 aType=aGAS.GetType();
468 bRet=(aType==GeomAbs_Cylinder||
469 aType==GeomAbs_Cone ||
470 aType==GeomAbs_Sphere);