1 #include <GEOMAlgo_ShapeInfoFiller.ixx>
3 #include <Precision.hxx>
9 #include <Geom_Curve.hxx>
10 #include <GeomAdaptor_Curve.hxx>
12 #include <TopoDS_Vertex.hxx>
14 #include <TopoDS_Edge.hxx>
16 #include <BRep_Tool.hxx>
19 #include <TopTools_IndexedMapOfShape.hxx>
20 #include <gp_Circ.hxx>
22 #include <gp_Elips.hxx>
23 #include <TopoDS_Iterator.hxx>
24 #include <TopoDS_Wire.hxx>
26 #include <Geom_Surface.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <GeomAdaptor_Surface.hxx>
30 #include <gp_Sphere.hxx>
32 #include <BRepTools.hxx>
33 #include <gp_Cylinder.hxx>
34 #include <gp_Cone.hxx>
35 #include <gp_Torus.hxx>
36 #include <TopoDS_Solid.hxx>
42 Standard_Boolean IsAllowedType(const GeomAbs_CurveType aCT);
44 Standard_Boolean IsAllowedType(const GeomAbs_SurfaceType aST);
46 Standard_Integer NbWires(const TopoDS_Face& aF);
48 Standard_Integer NbShells(const TopoDS_Solid& aS);
50 //=======================================================================
53 //=======================================================================
54 GEOMAlgo_ShapeInfoFiller::GEOMAlgo_ShapeInfoFiller()
60 //=======================================================================
63 //=======================================================================
64 GEOMAlgo_ShapeInfoFiller::~GEOMAlgo_ShapeInfoFiller()
67 //=======================================================================
68 //function : SetTolerance
70 //=======================================================================
71 void GEOMAlgo_ShapeInfoFiller::SetTolerance(const Standard_Real aT)
75 //=======================================================================
76 //function : Tolerance
78 //=======================================================================
79 Standard_Real GEOMAlgo_ShapeInfoFiller::Tolerance()const
83 //=======================================================================
86 //=======================================================================
87 void GEOMAlgo_ShapeInfoFiller::SetShape(const TopoDS_Shape& aS)
91 //=======================================================================
94 //=======================================================================
95 const TopoDS_Shape& GEOMAlgo_ShapeInfoFiller::Shape() const
99 //=======================================================================
102 //=======================================================================
103 const GEOMAlgo_ShapeInfo& GEOMAlgo_ShapeInfoFiller::Info() const
105 return Info(myShape);
107 //=======================================================================
110 //=======================================================================
111 const GEOMAlgo_ShapeInfo& GEOMAlgo_ShapeInfoFiller::Info(const TopoDS_Shape& aS) const
114 if (myMapInfo.Contains(aS)) {
115 const GEOMAlgo_ShapeInfo& aInfo=myMapInfo.FindFromKey(aS);
122 //=======================================================================
123 //function : CheckData
125 //=======================================================================
126 void GEOMAlgo_ShapeInfoFiller::CheckData()
130 if (myShape.IsNull()) {
135 //=======================================================================
138 //=======================================================================
139 void GEOMAlgo_ShapeInfoFiller::Perform()
152 //=======================================================================
153 //function :FillShape
155 //=======================================================================
156 void GEOMAlgo_ShapeInfoFiller::FillShape(const TopoDS_Shape& aS)
158 TopAbs_ShapeEnum aType;
160 aType=aS.ShapeType();
181 case TopAbs_COMPSOLID:
182 case TopAbs_COMPOUND:
190 //=======================================================================
191 //function :FillSubShapes
193 //=======================================================================
194 void GEOMAlgo_ShapeInfoFiller::FillSubShapes(const TopoDS_Shape& aS)
199 for (; aIt.More(); aIt.Next()){
200 const TopoDS_Shape& aSx=aIt.Value();
204 //=======================================================================
205 //function : FillContainer
207 //=======================================================================
208 void GEOMAlgo_ShapeInfoFiller::FillContainer(const TopoDS_Shape& aS)
212 Standard_Boolean bIsClosed;
213 TopAbs_ShapeEnum aType;
214 GEOMAlgo_KindOfClosed aKC;
216 aType=aS.ShapeType();
217 //----------------------------------------------------
218 if (myMapInfo.Contains(aS)) {
222 GEOMAlgo_ShapeInfo aInfoX;
223 myMapInfo.Add(aS, aInfoX);
225 GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
226 //----------------------------------------------------
227 aInfo.SetType(aType);
228 FillNbSubShapes(aS, aInfo);
230 if (aType==TopAbs_SHELL) {
231 bIsClosed=BRep_Tool::IsClosed(aS);
232 aKC=(bIsClosed) ? GEOMAlgo_KC_CLOSED :GEOMAlgo_KC_NOTCLOSED;
233 aInfo.SetKindOfClosed(aKC);
235 else if (aType==TopAbs_WIRE) {
237 TopoDS_Vertex aV1, aV2;
240 TopExp::Vertices(aW, aV1, aV2);
242 bIsClosed=aV1.IsSame(aV2);
243 aKC=(bIsClosed) ? GEOMAlgo_KC_CLOSED :GEOMAlgo_KC_NOTCLOSED;
244 aInfo.SetKindOfClosed(aKC);
249 //=======================================================================
250 //function : FillSolid
252 //=======================================================================
253 void GEOMAlgo_ShapeInfoFiller::FillSolid(const TopoDS_Shape& aS)
255 Standard_Integer aNbShells;
259 //----------------------------------------------------
260 if (myMapInfo.Contains(aS)) {
264 GEOMAlgo_ShapeInfo aInfoX;
265 myMapInfo.Add(aS, aInfoX);
267 GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
268 //----------------------------------------------------
269 aInfo.SetType(TopAbs_SOLID);
270 FillNbSubShapes(aS, aInfo);
273 aSd=TopoDS::Solid(aS);
275 aNbShells=NbShells(aSd);
282 //=======================================================================
285 //=======================================================================
286 void GEOMAlgo_ShapeInfoFiller::FillFace(const TopoDS_Shape& aS)
290 Standard_Boolean bIsAllowedType;
291 Standard_Integer aNbWires;//, iRet
292 Standard_Boolean bInf, bInfU1, bInfU2, bInfV1, bInfV2;
293 Standard_Real aUMin, aUMax, aVMin, aVMax, aR1, aR2;
297 GeomAbs_SurfaceType aST;
298 Handle(Geom_Surface) aSurf;
300 //GEOMAlgo_KindOfName aKindOfName;
301 //----------------------------------------------------
302 if (myMapInfo.Contains(aS)) {
306 GEOMAlgo_ShapeInfo aInfoX;
307 myMapInfo.Add(aS, aInfoX);
309 GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
310 //----------------------------------------------------
311 aInfo.SetType(TopAbs_FACE);
313 FillNbSubShapes(aS, aInfo);
319 aNbWires=NbWires(aF);
321 aSurf=BRep_Tool::Surface(aF);
322 GeomAdaptor_Surface aGAS(aSurf);
324 bIsAllowedType=IsAllowedType(aST);
325 if (!bIsAllowedType) {
330 if (aST==GeomAbs_Plane) {
335 aAx3=aPln.Position();
337 aInfo.SetKindOfShape(GEOMAlgo_KS_PLANE);
338 aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
339 aInfo.SetLocation(aP0);
340 aInfo.SetPosition(aAx3);
342 if (aNbWires>1) return;
344 //aSurf->Bounds(aUMin, aUMax, aVMin, aVMax);
345 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
346 bInfU1=Precision::IsNegativeInfinite(aUMin);
347 bInfU2=Precision::IsPositiveInfinite(aUMax);
348 bInfV1=Precision::IsNegativeInfinite(aVMin);
349 bInfV2=Precision::IsPositiveInfinite(aVMax);
351 bInf=(bInfU1 || bInfU2 || bInfV1 || bInfV2);
353 aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
356 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
359 FillDetails(aF, aPln);
360 }// if (aCT==GeomAbs_Line) {
363 else if (aST==GeomAbs_Sphere) {
366 aSphere=aGAS.Sphere();
367 aP0=aSphere.Location();
368 aAx3=aSphere.Position();
369 aR1=aSphere.Radius();
371 aInfo.SetKindOfShape(GEOMAlgo_KS_SPHERE);
372 aInfo.SetLocation(aP0);
373 aInfo.SetPosition(aAx3);
374 aInfo.SetRadius1(aR1);
376 if (aNbWires>1) return;
378 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
379 aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
381 FillDetails(aF, aSphere);
382 }// else if (aST==GeomAbs_Sphere) {
385 else if (aST==GeomAbs_Cylinder) {
388 aCyl=aGAS.Cylinder();
390 aAx3=aCyl.Position();
393 aInfo.SetKindOfShape(GEOMAlgo_KS_CYLINDER);
394 aInfo.SetLocation(aP0);
395 aInfo.SetPosition(aAx3);
396 aInfo.SetRadius1(aR1);
398 if (aNbWires>1) return;
400 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
401 bInfU1=Precision::IsNegativeInfinite(aUMin);
402 bInfU2=Precision::IsPositiveInfinite(aUMax);
403 bInfV1=Precision::IsNegativeInfinite(aVMin);
404 bInfV2=Precision::IsPositiveInfinite(aVMax);
406 bInf=(bInfU1 || bInfU2 || bInfV1 || bInfV2);
408 aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
411 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
413 FillDetails(aF, aCyl);
417 else if (aST==GeomAbs_Cone) {
421 aP0=aCone.Location();
422 aAx3=aCone.Position();
425 aInfo.SetKindOfShape(GEOMAlgo_KS_CONE);
426 aInfo.SetLocation(aP0);
427 aInfo.SetPosition(aAx3);
428 //aInfo.SetRadius1(aR1);
430 if (aNbWires>1) return;
432 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
433 bInfU1=Precision::IsNegativeInfinite(aUMin);
434 bInfU2=Precision::IsPositiveInfinite(aUMax);
435 bInfV1=Precision::IsNegativeInfinite(aVMin);
436 bInfV2=Precision::IsPositiveInfinite(aVMax);
438 bInf=(bInfU1 || bInfU2 || bInfV1 || bInfV2);
440 aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
443 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
445 FillDetails(aF, aCone);
449 else if (aST==GeomAbs_Torus) {
453 aP0=aTorus.Location();
454 aAx3=aTorus.Position();
455 aR1=aTorus.MajorRadius();
456 aR2=aTorus.MinorRadius();
458 aInfo.SetKindOfShape(GEOMAlgo_KS_TORUS);
459 aInfo.SetLocation(aP0);
460 aInfo.SetPosition(aAx3);
461 aInfo.SetRadius1(aR1);
462 aInfo.SetRadius2(aR2);
464 if (aNbWires>1) return;
466 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
468 FillDetails(aF, aTorus);
471 //=======================================================================
474 //=======================================================================
475 void GEOMAlgo_ShapeInfoFiller::FillEdge(const TopoDS_Shape& aS)
479 Standard_Boolean bDegenerated, bIsAllowedType;
480 Standard_Integer aNbV;
481 Standard_Real aR1, aR2;
482 gp_Pnt aP, aP1, aP2, aPc;
485 Standard_Real aT1, aT2;
486 GeomAbs_CurveType aCT;
487 Handle(Geom_Curve) aC3D;
489 //----------------------------------------------------
490 if (myMapInfo.Contains(aS)) {
494 GEOMAlgo_ShapeInfo aInfoX;
495 myMapInfo.Add(aS, aInfoX);
497 GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
498 //----------------------------------------------------
499 aInfo.SetType(TopAbs_EDGE);
501 FillNbSubShapes(aS, aInfo);
505 bDegenerated=BRep_Tool::Degenerated(aE);
507 aInfo.SetKindOfShape(GEOMAlgo_KS_DEGENERATED);
512 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
513 GeomAdaptor_Curve aGAC(aC3D);
515 bIsAllowedType=IsAllowedType(aCT);
516 if (!bIsAllowedType) {
521 if (aCT==GeomAbs_Line) {
522 Standard_Boolean bInf1, bInf2;
523 Standard_Real aLength;
525 gp_XYZ aXYZ1, aXYZ2, aXYZc;
531 aInfo.SetKindOfShape(GEOMAlgo_KS_LINE);
532 aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
533 aInfo.SetLocation(aP);
534 aInfo.SetDirection(aD);
536 bInf1=Precision::IsNegativeInfinite(aT1);
537 bInf2=Precision::IsPositiveInfinite(aT2);
539 aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
540 aInfo.SetKindOfName(GEOMAlgo_KN_LINE);
543 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
544 aInfo.SetKindOfName(GEOMAlgo_KN_SEGMENT);
550 aLength=aP1.Distance(aP2);
557 gp_Vec aVec(aPc, aP2);
560 aInfo.SetLocation(aPc);
561 aInfo.SetDirection(aDir);
562 aInfo.SetLength(aLength);
564 }// if (aCT==GeomAbs_Line) {
567 else if (aCT==GeomAbs_Circle) {
572 aAx2=aCirc.Position();
575 aInfo.SetKindOfShape(GEOMAlgo_KS_CIRCLE);
576 aInfo.SetLocation(aP);
577 aInfo.SetPosition(aAx2);
578 aInfo.SetRadius1(aR1);
580 aNbV=aInfo.NbSubShapes(TopAbs_VERTEX);
582 myErrorStatus=11; // circle edge without vertices
585 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
592 aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
593 aInfo.SetKindOfName(GEOMAlgo_KN_CIRCLE);
596 aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
597 aInfo.SetKindOfName(GEOMAlgo_KN_ARCCIRCLE);
599 gp_Vec aVecX(aP, aP1);
601 gp_Ax2 aAx2new(aP, aAx2.Direction(), aDirX);
602 aInfo.SetPosition(aAx2new);
604 }// else if (aCT==GeomAbs_Circle) {
607 else if (aCT==GeomAbs_Ellipse) {
610 aElips=aGAC.Ellipse();
611 aP=aElips.Location();
612 aAx2=aElips.Position();
613 aR1=aElips.MajorRadius();
614 aR2=aElips.MinorRadius();
616 aInfo.SetKindOfShape(GEOMAlgo_KS_ELLIPSE);
617 aInfo.SetLocation(aP);
618 aInfo.SetPosition(aAx2);
619 aInfo.SetRadius1(aR1);
620 aInfo.SetRadius2(aR2);
622 aNbV=aInfo.NbSubShapes(TopAbs_VERTEX);
624 myErrorStatus=11; // ellipse edge without vertices
627 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
634 aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
635 aInfo.SetKindOfName(GEOMAlgo_KN_ELLIPSE);
638 aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
639 aInfo.SetKindOfName(GEOMAlgo_KN_ARCELLIPSE);
641 gp_Vec aVecX(aP, aP1);
643 gp_Ax2 aAx2new(aP, aAx2.Direction(), aDirX);
644 aInfo.SetPosition(aAx2new);
646 }// else if (aCT==GeomAbs_Ellipse) {
650 //=======================================================================
651 //function :FillVertex
653 //=======================================================================
654 void GEOMAlgo_ShapeInfoFiller::FillVertex(const TopoDS_Shape& aS)
661 if (myMapInfo.Contains(aS)) {
665 GEOMAlgo_ShapeInfo aInfoX;
666 myMapInfo.Add(aS, aInfoX);
668 GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
670 aV=TopoDS::Vertex(aS);
671 aP=BRep_Tool::Pnt(aV);
673 aInfo.SetType(TopAbs_VERTEX);
674 aInfo.SetLocation(aP);
675 myMapInfo.Add(aS, aInfo);
677 //=======================================================================
678 //function : FillNbSubshapes
680 //=======================================================================
681 void GEOMAlgo_ShapeInfoFiller::FillNbSubShapes(const TopoDS_Shape& aS,
682 GEOMAlgo_ShapeInfo& aInfo)
686 Standard_Integer i, aNb, aNbS;
687 TopTools_IndexedMapOfShape aM;
688 TopAbs_ShapeEnum aST;
689 TopAbs_ShapeEnum aTypes[]= {
690 //TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX
703 aNb=sizeof(aTypes)/sizeof(aTypes[0]);
704 for (i=0; i<aNb; ++i) {
705 if (aTypes[i]==aST) {
709 TopExp::MapShapes(aS, aTypes[i], aM);
711 aInfo.SetNbSubShapes(aTypes[i], aNbS);
714 //=======================================================================
717 //=======================================================================
718 Standard_Integer NbShells(const TopoDS_Solid& aSd)
720 Standard_Integer iCnt;
726 for (; aIt.More(); aIt.Next()){
727 //const TopoDS_Shape& aSh=aIt.Value();
732 //=======================================================================
735 //=======================================================================
736 Standard_Integer NbWires(const TopoDS_Face& aF)
738 Standard_Integer iCnt;
744 for (; aIt.More(); aIt.Next()){
745 //const TopoDS_Shape& aW=aIt.Value();
750 //=======================================================================
751 //function : IsAllowedType
753 //=======================================================================
754 Standard_Boolean IsAllowedType(const GeomAbs_CurveType aCT)
756 Standard_Boolean bRet;
757 Standard_Integer i, aNb;
758 GeomAbs_CurveType aTypes[]={
759 GeomAbs_Line, GeomAbs_Circle, GeomAbs_Ellipse
763 aNb=sizeof(aTypes)/sizeof(aTypes[0]);
764 for (i=0; i<aNb && !bRet; ++i) {
765 bRet=(aCT==aTypes[i]);
770 //=======================================================================
771 //function : IsAllowedType
773 //=======================================================================
774 Standard_Boolean IsAllowedType(const GeomAbs_SurfaceType aST)
776 Standard_Boolean bRet;
777 Standard_Integer i, aNb;
778 GeomAbs_SurfaceType aTypes[]={
779 GeomAbs_Plane, GeomAbs_Cylinder,
780 GeomAbs_Cone, GeomAbs_Sphere,
785 aNb=sizeof(aTypes)/sizeof(aTypes[0]);
786 for (i=0; i<aNb && !bRet; ++i) {
787 bRet=(aST==aTypes[i]);
796 // 1 - The object is just initialized
799 // 11 - circle/ellipse edge without vertices