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);
324 aSurf=BRep_Tool::Surface(aF);
325 GeomAdaptor_Surface aGAS(aSurf);
327 bIsAllowedType=IsAllowedType(aST);
328 if (!bIsAllowedType) {
333 if (aST==GeomAbs_Plane) {
338 aAx3=aPln.Position();
340 aInfo.SetKindOfShape(GEOMAlgo_KS_PLANE);
341 aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
342 aInfo.SetLocation(aP0);
343 aInfo.SetPosition(aAx3);
345 //aSurf->Bounds(aUMin, aUMax, aVMin, aVMax);
346 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
347 bInfU1=Precision::IsNegativeInfinite(aUMin);
348 bInfU2=Precision::IsPositiveInfinite(aUMax);
349 bInfV1=Precision::IsNegativeInfinite(aVMin);
350 bInfV2=Precision::IsPositiveInfinite(aVMax);
352 bInf=(bInfU1 || bInfU2 || bInfV1 || bInfV2);
354 aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
357 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
360 FillDetails(aF, aPln);
361 }// if (aCT==GeomAbs_Line) {
364 else if (aST==GeomAbs_Sphere) {
367 aSphere=aGAS.Sphere();
368 aP0=aSphere.Location();
369 aAx3=aSphere.Position();
370 aR1=aSphere.Radius();
372 aInfo.SetKindOfShape(GEOMAlgo_KS_SPHERE);
373 aInfo.SetLocation(aP0);
374 aInfo.SetPosition(aAx3);
375 aInfo.SetRadius1(aR1);
377 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
378 aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
380 FillDetails(aF, aSphere);
381 }// else if (aST==GeomAbs_Sphere) {
384 else if (aST==GeomAbs_Cylinder) {
387 aCyl=aGAS.Cylinder();
389 aAx3=aCyl.Position();
392 aInfo.SetKindOfShape(GEOMAlgo_KS_CYLINDER);
393 aInfo.SetLocation(aP0);
394 aInfo.SetPosition(aAx3);
395 aInfo.SetRadius1(aR1);
397 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
398 bInfU1=Precision::IsNegativeInfinite(aUMin);
399 bInfU2=Precision::IsPositiveInfinite(aUMax);
400 bInfV1=Precision::IsNegativeInfinite(aVMin);
401 bInfV2=Precision::IsPositiveInfinite(aVMax);
403 bInf=(bInfU1 || bInfU2 || bInfV1 || bInfV2);
405 aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
408 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
410 FillDetails(aF, aCyl);
414 else if (aST==GeomAbs_Cone) {
418 aP0=aCone.Location();
419 aAx3=aCone.Position();
422 aInfo.SetKindOfShape(GEOMAlgo_KS_CONE);
423 aInfo.SetLocation(aP0);
424 aInfo.SetPosition(aAx3);
425 //aInfo.SetRadius1(aR1);
427 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
428 bInfU1=Precision::IsNegativeInfinite(aUMin);
429 bInfU2=Precision::IsPositiveInfinite(aUMax);
430 bInfV1=Precision::IsNegativeInfinite(aVMin);
431 bInfV2=Precision::IsPositiveInfinite(aVMax);
433 bInf=(bInfU1 || bInfU2 || bInfV1 || bInfV2);
435 aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
438 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
440 FillDetails(aF, aCone);
444 else if (aST==GeomAbs_Torus) {
448 aP0=aTorus.Location();
449 aAx3=aTorus.Position();
450 aR1=aTorus.MajorRadius();
451 aR2=aTorus.MinorRadius();
453 aInfo.SetKindOfShape(GEOMAlgo_KS_TORUS);
454 aInfo.SetLocation(aP0);
455 aInfo.SetPosition(aAx3);
456 aInfo.SetRadius1(aR1);
457 aInfo.SetRadius2(aR2);
459 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
461 FillDetails(aF, aTorus);
464 //=======================================================================
467 //=======================================================================
468 void GEOMAlgo_ShapeInfoFiller::FillEdge(const TopoDS_Shape& aS)
472 Standard_Boolean bDegenerated, bIsAllowedType;
473 Standard_Integer aNbV;
474 Standard_Real aR1, aR2;
475 gp_Pnt aP, aP1, aP2, aPc;
478 Standard_Real aT1, aT2;
479 GeomAbs_CurveType aCT;
480 Handle(Geom_Curve) aC3D;
482 //----------------------------------------------------
483 if (myMapInfo.Contains(aS)) {
487 GEOMAlgo_ShapeInfo aInfoX;
488 myMapInfo.Add(aS, aInfoX);
490 GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
491 //----------------------------------------------------
492 aInfo.SetType(TopAbs_EDGE);
494 FillNbSubShapes(aS, aInfo);
498 bDegenerated=BRep_Tool::Degenerated(aE);
500 aInfo.SetKindOfShape(GEOMAlgo_KS_DEGENERATED);
505 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
506 GeomAdaptor_Curve aGAC(aC3D);
508 bIsAllowedType=IsAllowedType(aCT);
509 if (!bIsAllowedType) {
514 if (aCT==GeomAbs_Line) {
515 Standard_Boolean bInf1, bInf2;
516 Standard_Real aLength;
518 gp_XYZ aXYZ1, aXYZ2, aXYZc;
524 aInfo.SetKindOfShape(GEOMAlgo_KS_LINE);
525 aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
526 aInfo.SetLocation(aP);
527 aInfo.SetDirection(aD);
529 bInf1=Precision::IsNegativeInfinite(aT1);
530 bInf2=Precision::IsPositiveInfinite(aT2);
532 aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
533 aInfo.SetKindOfName(GEOMAlgo_KN_LINE);
536 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
537 aInfo.SetKindOfName(GEOMAlgo_KN_SEGMENT);
543 aLength=aP1.Distance(aP2);
550 gp_Vec aVec(aPc, aP2);
553 aInfo.SetLocation(aPc);
554 aInfo.SetDirection(aDir);
555 aInfo.SetLength(aLength);
557 }// if (aCT==GeomAbs_Line) {
560 else if (aCT==GeomAbs_Circle) {
565 aAx2=aCirc.Position();
568 aInfo.SetKindOfShape(GEOMAlgo_KS_CIRCLE);
569 aInfo.SetLocation(aP);
570 aInfo.SetPosition(aAx2);
571 aInfo.SetRadius1(aR1);
573 aNbV=aInfo.NbSubShapes(TopAbs_VERTEX);
575 myErrorStatus=11; // circle edge without vertices
578 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
585 aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
586 aInfo.SetKindOfName(GEOMAlgo_KN_CIRCLE);
589 aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
590 aInfo.SetKindOfName(GEOMAlgo_KN_ARCCIRCLE);
592 gp_Vec aVecX(aP, aP1);
594 gp_Ax2 aAx2new(aP, aAx2.Direction(), aDirX);
595 aInfo.SetPosition(aAx2new);
597 }// else if (aCT==GeomAbs_Circle) {
600 else if (aCT==GeomAbs_Ellipse) {
603 aElips=aGAC.Ellipse();
604 aP=aElips.Location();
605 aAx2=aElips.Position();
606 aR1=aElips.MajorRadius();
607 aR2=aElips.MinorRadius();
609 aInfo.SetKindOfShape(GEOMAlgo_KS_ELLIPSE);
610 aInfo.SetLocation(aP);
611 aInfo.SetPosition(aAx2);
612 aInfo.SetRadius1(aR1);
613 aInfo.SetRadius2(aR2);
615 aNbV=aInfo.NbSubShapes(TopAbs_VERTEX);
617 myErrorStatus=11; // ellipse edge without vertices
620 aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
627 aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
628 aInfo.SetKindOfName(GEOMAlgo_KN_ELLIPSE);
631 aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
632 aInfo.SetKindOfName(GEOMAlgo_KN_ARCELLIPSE);
634 gp_Vec aVecX(aP, aP1);
636 gp_Ax2 aAx2new(aP, aAx2.Direction(), aDirX);
637 aInfo.SetPosition(aAx2new);
639 }// else if (aCT==GeomAbs_Ellipse) {
643 //=======================================================================
644 //function :FillVertex
646 //=======================================================================
647 void GEOMAlgo_ShapeInfoFiller::FillVertex(const TopoDS_Shape& aS)
654 if (myMapInfo.Contains(aS)) {
658 GEOMAlgo_ShapeInfo aInfoX;
659 myMapInfo.Add(aS, aInfoX);
661 GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
663 aV=TopoDS::Vertex(aS);
664 aP=BRep_Tool::Pnt(aV);
666 aInfo.SetType(TopAbs_VERTEX);
667 aInfo.SetLocation(aP);
668 myMapInfo.Add(aS, aInfo);
670 //=======================================================================
671 //function : FillNbSubshapes
673 //=======================================================================
674 void GEOMAlgo_ShapeInfoFiller::FillNbSubShapes(const TopoDS_Shape& aS,
675 GEOMAlgo_ShapeInfo& aInfo)
679 Standard_Integer i, aNb, aNbS;
680 TopTools_IndexedMapOfShape aM;
681 TopAbs_ShapeEnum aST;
682 TopAbs_ShapeEnum aTypes[]= {
683 //TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX
696 aNb=sizeof(aTypes)/sizeof(aTypes[0]);
697 for (i=0; i<aNb; ++i) {
698 if (aTypes[i]==aST) {
702 TopExp::MapShapes(aS, aTypes[i], aM);
704 aInfo.SetNbSubShapes(aTypes[i], aNbS);
707 //=======================================================================
710 //=======================================================================
711 Standard_Integer NbShells(const TopoDS_Solid& aSd)
713 Standard_Integer iCnt;
719 for (; aIt.More(); aIt.Next()){
720 //const TopoDS_Shape& aSh=aIt.Value();
725 //=======================================================================
728 //=======================================================================
729 Standard_Integer NbWires(const TopoDS_Face& aF)
731 Standard_Integer iCnt;
737 for (; aIt.More(); aIt.Next()){
738 //const TopoDS_Shape& aW=aIt.Value();
743 //=======================================================================
744 //function : IsAllowedType
746 //=======================================================================
747 Standard_Boolean IsAllowedType(const GeomAbs_CurveType aCT)
749 Standard_Boolean bRet;
750 Standard_Integer i, aNb;
751 GeomAbs_CurveType aTypes[]={
752 GeomAbs_Line, GeomAbs_Circle, GeomAbs_Ellipse
756 aNb=sizeof(aTypes)/sizeof(aTypes[0]);
757 for (i=0; i<aNb && !bRet; ++i) {
758 bRet=(aCT==aTypes[i]);
763 //=======================================================================
764 //function : IsAllowedType
766 //=======================================================================
767 Standard_Boolean IsAllowedType(const GeomAbs_SurfaceType aST)
769 Standard_Boolean bRet;
770 Standard_Integer i, aNb;
771 GeomAbs_SurfaceType aTypes[]={
772 GeomAbs_Plane, GeomAbs_Cylinder,
773 GeomAbs_Cone, GeomAbs_Sphere,
778 aNb=sizeof(aTypes)/sizeof(aTypes[0]);
779 for (i=0; i<aNb && !bRet; ++i) {
780 bRet=(aST==aTypes[i]);
789 // 1 - The object is just initialized
792 // 11 - circle/ellipse edge without vertices