1 // Copyright (C) 2007-2008 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
27 #include <GEOMAlgo_Tools.ixx>
30 #include <gp_Pnt2d.hxx>
32 #include <Geom_Surface.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom2d_Curve.hxx>
35 #include <GeomAdaptor_Surface.hxx>
37 #include <GeomAPI_ProjectPointOnSurf.hxx>
39 #include <TopAbs_ShapeEnum.hxx>
42 #include <TopoDS_Shape.hxx>
43 #include <TopoDS_Edge.hxx>
44 #include <TopoDS_Iterator.hxx>
46 #include <TopTools_ListOfShape.hxx>
47 #include <TopTools_ListIteratorOfListOfShape.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <BRep_Tool.hxx>
51 #include <BRep_Builder.hxx>
52 #include <BRepTools.hxx>
54 #include <BOPTools_Tools2D.hxx>
55 #include <IntTools_Context.hxx>
57 #include <GEOMAlgo_PassKeyShape.hxx>//qft
58 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>//qft
61 void GetCount(const TopoDS_Shape& aS,
62 Standard_Integer& iCnt);
64 //=======================================================================
65 //function : IsCompositeShape
67 //=======================================================================
68 Standard_Boolean GEOMAlgo_Tools::IsCompositeShape(const TopoDS_Shape& aS)
70 Standard_Boolean bRet;
71 Standard_Integer iCnt;
81 //=======================================================================
84 //=======================================================================
85 void GetCount(const TopoDS_Shape& aS,
86 Standard_Integer& iCnt)
93 if (aTS==TopAbs_SHAPE) {
96 if (aTS!=TopAbs_COMPOUND) {
102 for (; aIt.More(); aIt.Next()) {
103 const TopoDS_Shape& aSx=aIt.Value();
108 //=======================================================================
109 //function : RefineSDShapes
111 //=======================================================================
112 Standard_Integer GEOMAlgo_Tools::RefineSDShapes(GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape& aMPKLE,
113 const Standard_Real aTol,
114 IntTools_Context& aCtx)
116 Standard_Integer i, aNbE, iErr, j, aNbEE, aNbToAdd;
117 TopTools_IndexedDataMapOfShapeListOfShape aMEE, aMSDE, aMEToAdd;
121 aNbE=aMPKLE.Extent();
122 for (i=1; i<=aNbE; ++i) {
123 TopTools_ListOfShape& aLSDE=aMPKLE.ChangeFromIndex(i);
126 iErr=GEOMAlgo_Tools::FindSDShapes(aLSDE, aTol, aMEE, aCtx);
133 continue; // nothing to do
136 for (j=1; j<=aNbEE; ++j) {
137 TopTools_ListOfShape& aLEE=aMEE.ChangeFromIndex(j);
144 const TopoDS_Shape& aE1=aLEE.First();
145 aMEToAdd.Add(aE1, aLEE);
150 aNbToAdd=aMEToAdd.Extent();
155 for (i=1; i<=aNbToAdd; ++i) {
156 GEOMAlgo_PassKeyShape aPKE1;
158 const TopoDS_Shape& aE1=aMEToAdd.FindKey(i);
159 const TopTools_ListOfShape& aLE=aMEToAdd(i);
163 aPKE1.SetShapes(aE1);
165 aMPKLE.Add(aPKE1, aLE);
170 //=======================================================================
171 //function : FindSDShapes
173 //=======================================================================
174 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopTools_ListOfShape& aLE,
175 const Standard_Real aTol,
176 TopTools_IndexedDataMapOfShapeListOfShape& aMEE,
177 IntTools_Context& aCtx)
179 Standard_Integer aNbE, aNbEProcessed, aNbESD, iErr;
180 TopTools_ListOfShape aLESD;
181 TopTools_ListIteratorOfListOfShape aIt, aIt1;
182 TopTools_IndexedMapOfShape aMProcessed;
183 TopAbs_ShapeEnum aType;
189 //modified by NIZNHY-PKV Thu Dec 30 10:56:52 2004 f
191 return 0; // Nothing to do
193 //modified by NIZNHY-PKV Thu Dec 30 10:56:56 2004 t
196 aNbEProcessed=aMProcessed.Extent();
197 if (aNbEProcessed==aNbE) {
202 for (; aIt.More(); aIt.Next()) {
203 const TopoDS_Shape& aS=aIt.Value();
205 if (aMProcessed.Contains(aS)) {
209 //modified by NIZNHY-PKV Thu Dec 30 10:57:01 2004 f
210 aType=aS.ShapeType();
211 if (aType==TopAbs_EDGE) {
212 const TopoDS_Edge& aE=TopoDS::Edge(aS);
213 if (BRep_Tool::Degenerated(aE)) {
218 //modified by NIZNHY-PKV Thu Dec 30 10:57:03 2004 t
221 iErr=GEOMAlgo_Tools::FindSDShapes(aS, aLE, aTol, aLESD, aCtx);
226 aNbESD=aLESD.Extent();
233 aIt1.Initialize(aLESD);
234 for (; aIt1.More(); aIt1.Next()) {
235 const TopoDS_Shape& aE1=aIt1.Value();
236 aMProcessed.Add(aE1);
242 //=======================================================================
243 //function : FindSDShapes
245 //=======================================================================
246 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopoDS_Shape& aE1,
247 const TopTools_ListOfShape& aLE,
248 const Standard_Real aTol,
249 TopTools_ListOfShape& aLESD,
250 IntTools_Context& aCtx)
252 Standard_Boolean bIsDone;
253 Standard_Real aTol2, aD2;
255 TopTools_ListIteratorOfListOfShape aIt;
258 GEOMAlgo_Tools::PointOnShape(aE1, aP1);
261 for (; aIt.More(); aIt.Next()) {
262 const TopoDS_Shape& aE2=aIt.Value();
263 if (aE2.IsSame(aE1)) {
267 bIsDone=GEOMAlgo_Tools::ProjectPointOnShape(aP1, aE2, aP2, aCtx);
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();
296 const TopoDS_Edge& aE2=TopoDS::Edge(aS);
298 bIsDone=aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
303 GEOMAlgo_Tools::PointOnEdge(aE2, aT2, aP2);
308 const TopoDS_Face& aF2=TopoDS::Face(aS);
309 GeomAPI_ProjectPointOnSurf& aProj=aCtx.ProjPS(aF2);
312 bIsDone=aProj.IsDone();
317 aP2=aProj.NearestPoint();
326 //=======================================================================
327 //function : PointOnShape
329 //=======================================================================
330 void GEOMAlgo_Tools::PointOnShape(const TopoDS_Shape& aS,
333 TopAbs_ShapeEnum aType;
335 aP3D.SetCoord(99.,99.,99.);
336 aType=aS.ShapeType();
339 const TopoDS_Edge& aE=TopoDS::Edge(aS);
340 GEOMAlgo_Tools::PointOnEdge(aE, aP3D);
345 const TopoDS_Face& aF=TopoDS::Face(aS);
346 GEOMAlgo_Tools::PointOnFace(aF, aP3D);
354 //=======================================================================
355 //function : PointOnFace
357 //=======================================================================
358 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
361 Standard_Real aU, aV, aUMin, aUMax, aVMin, aVMax;
363 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
365 aU=BOPTools_Tools2D::IntermediatePoint(aUMin, aUMax);
366 aV=BOPTools_Tools2D::IntermediatePoint(aVMin, aVMax);
368 GEOMAlgo_Tools::PointOnFace(aF, aU, aV, aP3D);
370 //=======================================================================
371 //function : PointOnFace
373 //=======================================================================
374 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
375 const Standard_Real aU,
376 const Standard_Real aV,
379 Handle(Geom_Surface) aS;
381 aS=BRep_Tool::Surface(aF);
382 aS->D0(aU, aV, aP3D);
384 //=======================================================================
385 //function : PointOnEdge
387 //=======================================================================
388 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
391 Standard_Real aTx, aT1, aT2;
393 BRep_Tool::Curve(aE, aT1, aT2);
394 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
395 GEOMAlgo_Tools::PointOnEdge(aE, aTx, aP3D);
397 //=======================================================================
398 //function : PointOnEdge
400 //=======================================================================
401 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
402 const Standard_Real aT,
405 Standard_Real aT1, aT2;
406 Handle(Geom_Curve) aC3D;
408 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
411 //=======================================================================
412 //function : RefinePCurveForEdgeOnFace
414 //=======================================================================
415 void GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(const TopoDS_Edge& aE,
416 const TopoDS_Face& aF,
417 const Standard_Real aUMin,
418 const Standard_Real aUMax)
420 Standard_Real aT1, aT2, aTx, aUx, aTol, aTwoPI;
422 Handle(Geom_Surface) aS;
423 Handle(Geom2d_Curve) aC2D;
428 aC2D=BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
429 if (!aC2D.IsNull()) {
430 if (BRep_Tool::IsClosed(aE, aF)) {
433 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
436 if (aUx < aUMin || aUx > aUMax) {
438 Handle(Geom2d_Curve) aC2Dx;
440 aTol=BRep_Tool::Tolerance(aE);
441 aBB.UpdateEdge(aE, aC2Dx, aF, aTol);
445 //=======================================================================
446 //function : IsUPeriodic
448 //=======================================================================
449 Standard_Boolean GEOMAlgo_Tools::IsUPeriodic(const Handle(Geom_Surface) &aS)
451 Standard_Boolean bRet;
452 GeomAbs_SurfaceType aType;
453 GeomAdaptor_Surface aGAS;
456 aType=aGAS.GetType();
457 bRet=(aType==GeomAbs_Cylinder||
458 aType==GeomAbs_Cone ||
459 aType==GeomAbs_Sphere);