1 // Copyright (C) 2007-2010 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
23 // File: GEOMAlgo_Tools.cxx
24 // Created: Mon Dec 6 11:35:29 2004
25 // Author: Peter KURNEV
28 #include <GEOMAlgo_Tools.ixx>
31 #include <gp_Pnt2d.hxx>
33 #include <Geom_Surface.hxx>
34 #include <Geom_Curve.hxx>
35 #include <Geom2d_Curve.hxx>
36 #include <GeomAdaptor_Surface.hxx>
38 #include <GeomAPI_ProjectPointOnSurf.hxx>
40 #include <TopAbs_ShapeEnum.hxx>
43 #include <TopoDS_Shape.hxx>
44 #include <TopoDS_Edge.hxx>
45 #include <TopoDS_Iterator.hxx>
47 #include <TopTools_ListOfShape.hxx>
48 #include <TopTools_ListIteratorOfListOfShape.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <BRep_Tool.hxx>
52 #include <BRep_Builder.hxx>
53 #include <BRepTools.hxx>
55 #include <BOPTools_Tools2D.hxx>
56 #include <IntTools_Context.hxx>
58 #include <GEOMAlgo_PassKeyShape.hxx>//qft
59 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>//qft
62 void GetCount(const TopoDS_Shape& aS,
63 Standard_Integer& iCnt);
65 //=======================================================================
66 //function : IsCompositeShape
68 //=======================================================================
69 Standard_Boolean GEOMAlgo_Tools::IsCompositeShape(const TopoDS_Shape& aS)
71 Standard_Boolean bRet;
72 Standard_Integer iCnt;
82 //=======================================================================
85 //=======================================================================
86 void GetCount(const TopoDS_Shape& aS,
87 Standard_Integer& iCnt)
94 if (aTS==TopAbs_SHAPE) {
97 if (aTS!=TopAbs_COMPOUND) {
103 for (; aIt.More(); aIt.Next()) {
104 const TopoDS_Shape& aSx=aIt.Value();
109 //=======================================================================
110 //function : RefineSDShapes
112 //=======================================================================
113 Standard_Integer GEOMAlgo_Tools::RefineSDShapes(GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape& aMPKLE,
114 const Standard_Real aTol,
115 IntTools_Context& aCtx)
117 Standard_Integer i, aNbE, iErr, j, aNbEE, aNbToAdd;
118 TopTools_IndexedDataMapOfShapeListOfShape aMEE, aMSDE, aMEToAdd;
122 aNbE=aMPKLE.Extent();
123 for (i=1; i<=aNbE; ++i) {
124 TopTools_ListOfShape& aLSDE=aMPKLE.ChangeFromIndex(i);
127 iErr=GEOMAlgo_Tools::FindSDShapes(aLSDE, aTol, aMEE, aCtx);
134 continue; // nothing to do
137 for (j=1; j<=aNbEE; ++j) {
138 TopTools_ListOfShape& aLEE=aMEE.ChangeFromIndex(j);
145 const TopoDS_Shape& aE1=aLEE.First();
146 aMEToAdd.Add(aE1, aLEE);
151 aNbToAdd=aMEToAdd.Extent();
156 for (i=1; i<=aNbToAdd; ++i) {
157 GEOMAlgo_PassKeyShape aPKE1;
159 const TopoDS_Shape& aE1=aMEToAdd.FindKey(i);
160 const TopTools_ListOfShape& aLE=aMEToAdd(i);
164 aPKE1.SetShapes(aE1);
166 aMPKLE.Add(aPKE1, aLE);
171 //=======================================================================
172 //function : FindSDShapes
174 //=======================================================================
175 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopTools_ListOfShape& aLE,
176 const Standard_Real aTol,
177 TopTools_IndexedDataMapOfShapeListOfShape& aMEE,
178 IntTools_Context& aCtx)
180 Standard_Integer aNbE, aNbEProcessed, aNbESD, iErr;
181 TopTools_ListOfShape aLESD;
182 TopTools_ListIteratorOfListOfShape aIt, aIt1;
183 TopTools_IndexedMapOfShape aMProcessed;
184 TopAbs_ShapeEnum aType;
190 //modified by NIZNHY-PKV Thu Dec 30 10:56:52 2004 f
192 return 0; // Nothing to do
194 //modified by NIZNHY-PKV Thu Dec 30 10:56:56 2004 t
197 aNbEProcessed=aMProcessed.Extent();
198 if (aNbEProcessed==aNbE) {
203 for (; aIt.More(); aIt.Next()) {
204 const TopoDS_Shape& aS=aIt.Value();
206 if (aMProcessed.Contains(aS)) {
210 //modified by NIZNHY-PKV Thu Dec 30 10:57:01 2004 f
211 aType=aS.ShapeType();
212 if (aType==TopAbs_EDGE) {
213 const TopoDS_Edge& aE=TopoDS::Edge(aS);
214 if (BRep_Tool::Degenerated(aE)) {
219 //modified by NIZNHY-PKV Thu Dec 30 10:57:03 2004 t
222 iErr=GEOMAlgo_Tools::FindSDShapes(aS, aLE, aTol, aLESD, aCtx);
227 aNbESD=aLESD.Extent();
234 aIt1.Initialize(aLESD);
235 for (; aIt1.More(); aIt1.Next()) {
236 const TopoDS_Shape& aE1=aIt1.Value();
237 aMProcessed.Add(aE1);
243 //=======================================================================
244 //function : FindSDShapes
246 //=======================================================================
247 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopoDS_Shape& aE1,
248 const TopTools_ListOfShape& aLE,
249 const Standard_Real aTol,
250 TopTools_ListOfShape& aLESD,
251 IntTools_Context& aCtx)
253 Standard_Boolean bIsDone;
254 Standard_Real aTol2, aD2;
256 TopTools_ListIteratorOfListOfShape aIt;
259 GEOMAlgo_Tools::PointOnShape(aE1, aP1);
262 for (; aIt.More(); aIt.Next()) {
263 const TopoDS_Shape& aE2=aIt.Value();
264 if (aE2.IsSame(aE1)) {
268 bIsDone=GEOMAlgo_Tools::ProjectPointOnShape(aP1, aE2, aP2, aCtx);
271 continue; // jfa BUG 20361
273 aD2=aP1.SquareDistance(aP2);
282 //=======================================================================
283 //function : ProjectPointOnShape
285 //=======================================================================
286 Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
287 const TopoDS_Shape& aS,
289 IntTools_Context& aCtx)
291 Standard_Boolean bIsDone = Standard_False;
293 TopAbs_ShapeEnum aType;
295 aType = aS.ShapeType();
300 const TopoDS_Edge& aE2 = TopoDS::Edge(aS);
302 if (BRep_Tool::Degenerated(aE2)) { // jfa
303 return Standard_True;
307 Handle(Geom_Curve) aC3D = BRep_Tool::Curve (aE2, f, l);
309 return Standard_True;
311 bIsDone = aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
317 GEOMAlgo_Tools::PointOnEdge(aE2, aT2, aP2);
323 const TopoDS_Face& aF2 = TopoDS::Face(aS);
324 GeomAPI_ProjectPointOnSurf& aProj = aCtx.ProjPS(aF2);
327 bIsDone = aProj.IsDone();
332 aP2 = aProj.NearestPoint();
341 //=======================================================================
342 //function : PointOnShape
344 //=======================================================================
345 void GEOMAlgo_Tools::PointOnShape(const TopoDS_Shape& aS,
348 TopAbs_ShapeEnum aType;
350 aP3D.SetCoord(99.,99.,99.);
351 aType=aS.ShapeType();
354 const TopoDS_Edge& aE=TopoDS::Edge(aS);
355 GEOMAlgo_Tools::PointOnEdge(aE, aP3D);
360 const TopoDS_Face& aF=TopoDS::Face(aS);
361 GEOMAlgo_Tools::PointOnFace(aF, aP3D);
369 //=======================================================================
370 //function : PointOnFace
372 //=======================================================================
373 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
376 Standard_Real aU, aV, aUMin, aUMax, aVMin, aVMax;
378 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
380 aU=BOPTools_Tools2D::IntermediatePoint(aUMin, aUMax);
381 aV=BOPTools_Tools2D::IntermediatePoint(aVMin, aVMax);
383 GEOMAlgo_Tools::PointOnFace(aF, aU, aV, aP3D);
385 //=======================================================================
386 //function : PointOnFace
388 //=======================================================================
389 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
390 const Standard_Real aU,
391 const Standard_Real aV,
394 Handle(Geom_Surface) aS;
396 aS=BRep_Tool::Surface(aF);
397 aS->D0(aU, aV, aP3D);
399 //=======================================================================
400 //function : PointOnEdge
402 //=======================================================================
403 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
406 Standard_Real aTx, aT1, aT2;
408 BRep_Tool::Curve(aE, aT1, aT2);
409 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
410 GEOMAlgo_Tools::PointOnEdge(aE, aTx, aP3D);
412 //=======================================================================
413 //function : PointOnEdge
415 //=======================================================================
416 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
417 const Standard_Real aT,
420 Standard_Real aT1, aT2;
421 Handle(Geom_Curve) aC3D;
423 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
426 //=======================================================================
427 //function : RefinePCurveForEdgeOnFace
429 //=======================================================================
430 void GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(const TopoDS_Edge& aE,
431 const TopoDS_Face& aF,
432 const Standard_Real aUMin,
433 const Standard_Real aUMax)
435 Standard_Real aT1, aT2, aTx, aUx, aTol, aTwoPI;
437 Handle(Geom_Surface) aS;
438 Handle(Geom2d_Curve) aC2D;
443 aC2D=BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
444 if (!aC2D.IsNull()) {
445 if (BRep_Tool::IsClosed(aE, aF)) {
448 aTx=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
451 if (aUx < aUMin || aUx > aUMax) {
453 Handle(Geom2d_Curve) aC2Dx;
455 aTol=BRep_Tool::Tolerance(aE);
456 aBB.UpdateEdge(aE, aC2Dx, aF, aTol);
460 //=======================================================================
461 //function : IsUPeriodic
463 //=======================================================================
464 Standard_Boolean GEOMAlgo_Tools::IsUPeriodic(const Handle(Geom_Surface) &aS)
466 Standard_Boolean bRet;
467 GeomAbs_SurfaceType aType;
468 GeomAdaptor_Surface aGAS;
471 aType=aGAS.GetType();
472 bRet=(aType==GeomAbs_Cylinder||
473 aType==GeomAbs_Cone ||
474 aType==GeomAbs_Sphere);