Salome HOME
*** empty log message ***
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_ShapeInfoFiller.cxx
1 #include <GEOMAlgo_ShapeInfoFiller.ixx>
2
3 #include <Precision.hxx>
4
5 #include <gp_Lin.hxx>
6 #include <gp_Pnt.hxx>
7 #include <gp_Dir.hxx>
8
9 #include <Geom_Curve.hxx>
10 #include <GeomAdaptor_Curve.hxx>
11
12 #include <TopoDS_Vertex.hxx>
13 #include <TopoDS.hxx>
14 #include <TopoDS_Edge.hxx>
15
16 #include <BRep_Tool.hxx>
17 #include <TopExp.hxx>
18
19 #include <TopTools_IndexedMapOfShape.hxx>
20 #include <gp_Circ.hxx>
21 #include <gp_Ax2.hxx>
22 #include <gp_Elips.hxx>
23 #include <TopoDS_Iterator.hxx>
24 #include <TopoDS_Wire.hxx>
25 #include <TopExp.hxx>
26 #include <Geom_Surface.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <GeomAdaptor_Surface.hxx>
29 #include <gp_Pln.hxx>
30 #include <gp_Sphere.hxx>
31 #include <gp_Ax3.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>
37
38
39
40
41 static 
42   Standard_Boolean IsAllowedType(const GeomAbs_CurveType aCT);
43 static
44   Standard_Boolean IsAllowedType(const GeomAbs_SurfaceType aST);
45 static
46   Standard_Integer NbWires(const TopoDS_Face& aF);
47 static
48   Standard_Integer NbShells(const TopoDS_Solid& aS);
49
50 //=======================================================================
51 //function : 
52 //purpose  : 
53 //=======================================================================
54   GEOMAlgo_ShapeInfoFiller::GEOMAlgo_ShapeInfoFiller()
55 :
56   GEOMAlgo_Algo()
57 {
58   myTolerance=0.0001;
59 }
60 //=======================================================================
61 //function : ~
62 //purpose  : 
63 //=======================================================================
64   GEOMAlgo_ShapeInfoFiller::~GEOMAlgo_ShapeInfoFiller()
65 {
66 }
67 //=======================================================================
68 //function : SetTolerance
69 //purpose  : 
70 //=======================================================================
71   void GEOMAlgo_ShapeInfoFiller::SetTolerance(const Standard_Real aT)
72 {
73   myTolerance=aT;
74 }
75 //=======================================================================
76 //function : Tolerance
77 //purpose  : 
78 //=======================================================================
79   Standard_Real GEOMAlgo_ShapeInfoFiller::Tolerance()const
80 {
81   return myTolerance;
82 }
83 //=======================================================================
84 //function : SetShape
85 //purpose  : 
86 //=======================================================================
87   void GEOMAlgo_ShapeInfoFiller::SetShape(const TopoDS_Shape& aS) 
88 {
89   myShape=aS;
90 }
91 //=======================================================================
92 //function : Shape
93 //purpose  : 
94 //=======================================================================
95   const TopoDS_Shape& GEOMAlgo_ShapeInfoFiller::Shape() const
96 {
97   return myShape;
98 }
99 //=======================================================================
100 //function : Info
101 //purpose  : 
102 //=======================================================================
103   const GEOMAlgo_ShapeInfo& GEOMAlgo_ShapeInfoFiller::Info() const
104 {
105   return Info(myShape); 
106 }
107 //=======================================================================
108 //function : Info
109 //purpose  : 
110 //=======================================================================
111   const GEOMAlgo_ShapeInfo& GEOMAlgo_ShapeInfoFiller::Info(const TopoDS_Shape& aS) const
112 {
113   if (!aS.IsNull()) {
114     if (myMapInfo.Contains(aS)) {
115       const GEOMAlgo_ShapeInfo& aInfo=myMapInfo.FindFromKey(aS);
116       return aInfo;
117     }
118   }
119   return myEmptyInfo; 
120 }
121
122 //=======================================================================
123 //function : CheckData
124 //purpose  : 
125 //=======================================================================
126   void GEOMAlgo_ShapeInfoFiller::CheckData()
127 {
128   myErrorStatus=0;
129   //
130   if (myShape.IsNull()) {
131     myErrorStatus=10;
132     return;
133   }
134 }
135 //=======================================================================
136 //function : Perform
137 //purpose  : 
138 //=======================================================================
139   void GEOMAlgo_ShapeInfoFiller::Perform() 
140 {
141   myErrorStatus=0;
142   //
143   myMapInfo.Clear();
144   //
145   CheckData();
146   if (myErrorStatus) {
147     return;
148   }
149   //
150   FillShape(myShape);
151 }
152 //=======================================================================
153 //function :FillShape 
154 //purpose  : 
155 //=======================================================================
156   void GEOMAlgo_ShapeInfoFiller::FillShape(const TopoDS_Shape& aS)
157 {
158   TopAbs_ShapeEnum aType;
159   //
160   aType=aS.ShapeType();
161   switch(aType) {
162     //
163     case TopAbs_VERTEX:
164       FillVertex(aS);
165       break;
166     //  
167     case TopAbs_EDGE:
168       FillEdge(aS);
169       break;
170     //
171     case TopAbs_FACE:
172       FillFace(aS);
173       break;
174     //
175     case TopAbs_SOLID:
176       FillSolid(aS);
177       break;
178     //
179     case TopAbs_WIRE:
180     case TopAbs_SHELL:
181     case TopAbs_COMPSOLID:
182     case TopAbs_COMPOUND:
183       FillContainer(aS);
184       break;
185     // 
186     default:
187       break;
188   }
189 }
190 //=======================================================================
191 //function :FillSubShapes 
192 //purpose  : 
193 //=======================================================================
194   void GEOMAlgo_ShapeInfoFiller::FillSubShapes(const TopoDS_Shape& aS)
195 {
196   TopoDS_Iterator aIt;
197   //
198   aIt.Initialize(aS);
199   for (; aIt.More(); aIt.Next()){
200     const TopoDS_Shape& aSx=aIt.Value();
201     FillShape(aSx);
202   }
203 }
204 //=======================================================================
205 //function : FillContainer
206 //purpose  : 
207 //=======================================================================
208   void GEOMAlgo_ShapeInfoFiller::FillContainer(const TopoDS_Shape& aS) 
209 {
210   myErrorStatus=0;
211   //
212   Standard_Boolean bIsClosed;
213   TopAbs_ShapeEnum aType;
214   GEOMAlgo_KindOfClosed aKC;
215   //
216   aType=aS.ShapeType();
217   //----------------------------------------------------
218   if (myMapInfo.Contains(aS)) {
219     return;
220   }
221   else {
222     GEOMAlgo_ShapeInfo aInfoX;
223     myMapInfo.Add(aS, aInfoX);
224   }
225   GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
226   //----------------------------------------------------
227   aInfo.SetType(aType);
228   FillNbSubShapes(aS, aInfo);
229   //
230   if (aType==TopAbs_SHELL) {
231     bIsClosed=BRep_Tool::IsClosed(aS);
232     aKC=(bIsClosed) ? GEOMAlgo_KC_CLOSED :GEOMAlgo_KC_NOTCLOSED;
233     aInfo.SetKindOfClosed(aKC);
234   }
235   else if (aType==TopAbs_WIRE) {
236     TopoDS_Wire aW;
237     TopoDS_Vertex aV1, aV2;
238     //
239     aW=TopoDS::Wire(aS);
240     TopExp::Vertices(aW, aV1, aV2);
241     //
242     bIsClosed=aV1.IsSame(aV2);
243     aKC=(bIsClosed) ? GEOMAlgo_KC_CLOSED :GEOMAlgo_KC_NOTCLOSED;
244     aInfo.SetKindOfClosed(aKC);
245   }
246   //
247   FillSubShapes(aS);
248 }
249 //=======================================================================
250 //function : FillSolid
251 //purpose  : 
252 //=======================================================================
253   void GEOMAlgo_ShapeInfoFiller::FillSolid(const TopoDS_Shape& aS) 
254 {
255   Standard_Integer aNbShells;
256   TopoDS_Solid aSd;
257   //
258   myErrorStatus=0;
259   //----------------------------------------------------
260   if (myMapInfo.Contains(aS)) {
261     return;
262   }
263   else {
264     GEOMAlgo_ShapeInfo aInfoX;
265     myMapInfo.Add(aS, aInfoX);
266   }
267   GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
268   //----------------------------------------------------
269   aInfo.SetType(TopAbs_SOLID);
270   FillNbSubShapes(aS, aInfo);
271   FillSubShapes(aS);
272   //
273   aSd=TopoDS::Solid(aS);
274   //
275   aNbShells=NbShells(aSd);
276   if (aNbShells>1) {
277     return;
278   }
279   //
280   FillDetails(aSd);
281 }
282 //=======================================================================
283 //function :FillFace 
284 //purpose  : 
285 //=======================================================================
286   void GEOMAlgo_ShapeInfoFiller::FillFace(const TopoDS_Shape& aS) 
287 {
288   myErrorStatus=0;
289   //
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;
294   gp_Pnt aP0; 
295   gp_Dir aDN;
296   gp_Ax3 aAx3;
297   GeomAbs_SurfaceType aST;
298   Handle(Geom_Surface) aSurf;
299   TopoDS_Face aF;
300   //GEOMAlgo_KindOfName aKindOfName;
301   //----------------------------------------------------
302   if (myMapInfo.Contains(aS)) {
303     return;
304   }
305   else {
306     GEOMAlgo_ShapeInfo aInfoX;
307     myMapInfo.Add(aS, aInfoX);
308   }
309   GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
310   //----------------------------------------------------
311   aInfo.SetType(TopAbs_FACE);
312   //
313   FillNbSubShapes(aS, aInfo);
314   //
315   FillSubShapes(aS);
316   //
317   aF=TopoDS::Face(aS);
318   //
319   aNbWires=NbWires(aF);
320   if (aNbWires>1) {
321     return;
322   }
323   //
324   aSurf=BRep_Tool::Surface(aF);
325   GeomAdaptor_Surface aGAS(aSurf);
326   aST=aGAS.GetType();
327   bIsAllowedType=IsAllowedType(aST);
328   if (!bIsAllowedType) {
329     return;
330   }
331   //
332   // 1. Plane
333   if (aST==GeomAbs_Plane) {
334     gp_Pln aPln;
335     //
336     aPln=aGAS.Plane();
337     aP0=aPln.Location();
338     aAx3=aPln.Position();
339     //
340     aInfo.SetKindOfShape(GEOMAlgo_KS_PLANE);
341     aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
342     aInfo.SetLocation(aP0);
343     aInfo.SetPosition(aAx3);
344     //
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);
351     //
352     bInf=(bInfU1 || bInfU2 || bInfV1 || bInfV2);
353     if (bInf) {
354       aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
355     }
356     else {
357       aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
358     }
359     //
360     FillDetails(aF, aPln);
361   }// if (aCT==GeomAbs_Line) {
362   //
363   // 2. Sphere
364   else if (aST==GeomAbs_Sphere) {
365     gp_Sphere aSphere;
366     //
367     aSphere=aGAS.Sphere();
368     aP0=aSphere.Location();
369     aAx3=aSphere.Position();
370     aR1=aSphere.Radius();
371     //
372     aInfo.SetKindOfShape(GEOMAlgo_KS_SPHERE);
373     aInfo.SetLocation(aP0);
374     aInfo.SetPosition(aAx3);
375     aInfo.SetRadius1(aR1);
376     //
377     aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
378     aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
379     //
380     FillDetails(aF, aSphere);
381   }// else if (aST==GeomAbs_Sphere) {
382   // 
383   // 3. Cylinder
384   else if (aST==GeomAbs_Cylinder) {
385     gp_Cylinder aCyl;
386     //
387     aCyl=aGAS.Cylinder();
388     aP0=aCyl.Location();
389     aAx3=aCyl.Position();
390     aR1=aCyl.Radius();
391     //
392     aInfo.SetKindOfShape(GEOMAlgo_KS_CYLINDER);
393     aInfo.SetLocation(aP0);
394     aInfo.SetPosition(aAx3);
395     aInfo.SetRadius1(aR1);
396     //
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);
402     //
403     bInf=(bInfU1 || bInfU2 || bInfV1 || bInfV2);
404     if (bInf) {
405       aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
406     }
407     else {
408       aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
409     }
410     FillDetails(aF, aCyl);
411   }
412   // 
413   // 4. Cone
414   else if (aST==GeomAbs_Cone) {
415     gp_Cone aCone;
416     //
417     aCone=aGAS.Cone();
418     aP0=aCone.Location();
419     aAx3=aCone.Position();
420     //aR1=aCyl.Radius();
421     //
422     aInfo.SetKindOfShape(GEOMAlgo_KS_CONE);
423     aInfo.SetLocation(aP0);
424     aInfo.SetPosition(aAx3);
425     //aInfo.SetRadius1(aR1);
426     //
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);
432     //
433     bInf=(bInfU1 || bInfU2 || bInfV1 || bInfV2);
434     if (bInf) {
435       aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
436     }
437     else {
438       aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
439     }
440     FillDetails(aF, aCone);
441   }
442   // 
443   // 5. Torus
444   else if (aST==GeomAbs_Torus) {
445     gp_Torus aTorus;
446     //
447     aTorus=aGAS.Torus();
448     aP0=aTorus.Location();
449     aAx3=aTorus.Position();
450     aR1=aTorus.MajorRadius();
451     aR2=aTorus.MinorRadius();
452     //
453     aInfo.SetKindOfShape(GEOMAlgo_KS_TORUS);
454     aInfo.SetLocation(aP0);
455     aInfo.SetPosition(aAx3);
456     aInfo.SetRadius1(aR1);
457     aInfo.SetRadius2(aR2);
458     //
459     aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
460     
461     FillDetails(aF, aTorus);
462   }
463 }
464 //=======================================================================
465 //function :FillEdge 
466 //purpose  : 
467 //=======================================================================
468   void GEOMAlgo_ShapeInfoFiller::FillEdge(const TopoDS_Shape& aS) 
469 {
470   myErrorStatus=0;
471   //
472   Standard_Boolean bDegenerated, bIsAllowedType;
473   Standard_Integer aNbV;
474   Standard_Real aR1, aR2;
475   gp_Pnt aP, aP1, aP2, aPc;
476   gp_Dir aD;
477   gp_Ax2 aAx2;
478   Standard_Real aT1, aT2;
479   GeomAbs_CurveType aCT;
480   Handle(Geom_Curve) aC3D;
481   TopoDS_Edge aE;
482   //----------------------------------------------------
483   if (myMapInfo.Contains(aS)) {
484     return;
485   }
486   else {
487     GEOMAlgo_ShapeInfo aInfoX;
488     myMapInfo.Add(aS, aInfoX);
489   }
490   GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
491   //----------------------------------------------------
492   aInfo.SetType(TopAbs_EDGE);
493   //
494   FillNbSubShapes(aS, aInfo);
495   //
496   aE=TopoDS::Edge(aS);
497   //
498   bDegenerated=BRep_Tool::Degenerated(aE);
499   if (bDegenerated) {
500     aInfo.SetKindOfShape(GEOMAlgo_KS_DEGENERATED);
501     FillSubShapes(aS);
502     return;
503   }
504   //
505   aC3D=BRep_Tool::Curve(aE, aT1, aT2);
506   GeomAdaptor_Curve aGAC(aC3D);
507   aCT=aGAC.GetType();
508   bIsAllowedType=IsAllowedType(aCT);
509   if (!bIsAllowedType) {
510     FillSubShapes(aS);
511     return;
512   }
513   // Line
514   if (aCT==GeomAbs_Line) {
515     Standard_Boolean bInf1, bInf2;
516     Standard_Real aLength;
517     gp_Lin aLin;
518     gp_XYZ aXYZ1, aXYZ2, aXYZc;
519     //
520     aLin=aGAC.Line();
521     aP=aLin.Location();
522     aD=aLin.Direction();
523     //
524     aInfo.SetKindOfShape(GEOMAlgo_KS_LINE);
525     aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
526     aInfo.SetLocation(aP);
527     aInfo.SetDirection(aD);
528     //
529     bInf1=Precision::IsNegativeInfinite(aT1);
530     bInf2=Precision::IsPositiveInfinite(aT2);
531     if (bInf1||bInf2) {
532       aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
533       aInfo.SetKindOfName(GEOMAlgo_KN_LINE);
534     }
535     else {
536       aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
537       aInfo.SetKindOfName(GEOMAlgo_KN_SEGMENT);
538       aGAC.D0(aT1, aP1);
539       aGAC.D0(aT2, aP2);
540       aInfo.SetPnt1(aP1);
541       aInfo.SetPnt2(aP2);
542       //
543       aLength=aP1.Distance(aP2);
544       aXYZ1=aP1.XYZ();
545       aXYZ2=aP2.XYZ();
546       aXYZc=aXYZ1+aXYZ2;
547       aXYZc.Multiply(0.5);
548       //
549       aPc.SetXYZ(aXYZc);
550       gp_Vec aVec(aPc, aP2);
551       gp_Dir aDir(aVec);
552       //
553       aInfo.SetLocation(aPc);
554       aInfo.SetDirection(aDir);
555       aInfo.SetLength(aLength);
556     }
557   }// if (aCT==GeomAbs_Line) {
558   //
559   // Circle
560   else if (aCT==GeomAbs_Circle) {
561     gp_Circ aCirc;
562     //
563     aCirc=aGAC.Circle();
564     aP=aCirc.Location();
565     aAx2=aCirc.Position();
566     aR1=aCirc.Radius();
567     //
568     aInfo.SetKindOfShape(GEOMAlgo_KS_CIRCLE);
569     aInfo.SetLocation(aP);
570     aInfo.SetPosition(aAx2);
571     aInfo.SetRadius1(aR1);
572     //
573     aNbV=aInfo.NbSubShapes(TopAbs_VERTEX);
574     if (!aNbV) {
575       myErrorStatus=11; // circle edge without vertices
576       return;
577     }
578     aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
579     aGAC.D0(aT1, aP1);
580     aGAC.D0(aT2, aP2);
581     aInfo.SetPnt1(aP1);
582     aInfo.SetPnt2(aP2);
583     //
584     if (aNbV==1) {
585       aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
586       aInfo.SetKindOfName(GEOMAlgo_KN_CIRCLE);
587     }
588     else {
589       aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
590       aInfo.SetKindOfName(GEOMAlgo_KN_ARCCIRCLE);
591       //
592       gp_Vec aVecX(aP, aP1);
593       gp_Dir aDirX(aVecX); 
594       gp_Ax2 aAx2new(aP, aAx2.Direction(), aDirX);
595       aInfo.SetPosition(aAx2new);
596     }
597   }// else if (aCT==GeomAbs_Circle) {
598   //
599   // Ellipse
600   else if (aCT==GeomAbs_Ellipse) {
601     gp_Elips aElips;
602     //
603     aElips=aGAC.Ellipse();
604     aP=aElips.Location();
605     aAx2=aElips.Position();
606     aR1=aElips.MajorRadius();
607     aR2=aElips.MinorRadius();
608     //
609     aInfo.SetKindOfShape(GEOMAlgo_KS_ELLIPSE);
610     aInfo.SetLocation(aP);
611     aInfo.SetPosition(aAx2);
612     aInfo.SetRadius1(aR1);
613     aInfo.SetRadius2(aR2);
614     //
615     aNbV=aInfo.NbSubShapes(TopAbs_VERTEX);
616     if (!aNbV) {
617       myErrorStatus=11; // ellipse edge without vertices
618       return;
619     }
620     aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
621     aGAC.D0(aT1, aP1);
622     aGAC.D0(aT2, aP2);
623     aInfo.SetPnt1(aP1);
624     aInfo.SetPnt2(aP2);
625     //
626     if (aNbV==1) {
627       aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
628       aInfo.SetKindOfName(GEOMAlgo_KN_ELLIPSE);
629     }
630     else {
631       aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
632       aInfo.SetKindOfName(GEOMAlgo_KN_ARCELLIPSE);
633       //
634       gp_Vec aVecX(aP, aP1);
635       gp_Dir aDirX(aVecX); 
636       gp_Ax2 aAx2new(aP, aAx2.Direction(), aDirX);
637       aInfo.SetPosition(aAx2new);
638     }
639   }// else if (aCT==GeomAbs_Ellipse) {
640   //
641   FillSubShapes(aS);
642 }
643 //=======================================================================
644 //function :FillVertex 
645 //purpose  : 
646 //=======================================================================
647   void GEOMAlgo_ShapeInfoFiller::FillVertex(const TopoDS_Shape& aS) 
648 {
649   myErrorStatus=0;
650   //
651   gp_Pnt aP;
652   TopoDS_Vertex aV;
653   //
654   if (myMapInfo.Contains(aS)) {
655     return;
656   }
657   else {
658     GEOMAlgo_ShapeInfo aInfoX;
659     myMapInfo.Add(aS, aInfoX);
660   }
661   GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
662   //
663   aV=TopoDS::Vertex(aS);
664   aP=BRep_Tool::Pnt(aV);
665   //
666   aInfo.SetType(TopAbs_VERTEX);
667   aInfo.SetLocation(aP);
668   myMapInfo.Add(aS, aInfo);
669 }
670 //=======================================================================
671 //function : FillNbSubshapes
672 //purpose  : 
673 //=======================================================================
674   void GEOMAlgo_ShapeInfoFiller::FillNbSubShapes(const TopoDS_Shape& aS,
675                                                  GEOMAlgo_ShapeInfo& aInfo)
676 {
677   myErrorStatus=0;
678   //
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
684     TopAbs_COMPOUND,
685     TopAbs_COMPSOLID,
686     TopAbs_SOLID,
687     TopAbs_SHELL,
688     TopAbs_FACE,
689     TopAbs_WIRE,
690     TopAbs_EDGE,
691     TopAbs_VERTEX
692   };
693   
694   //
695   aST=aS.ShapeType();
696   aNb=sizeof(aTypes)/sizeof(aTypes[0]);
697   for (i=0; i<aNb; ++i) {
698     if (aTypes[i]==aST) {
699       continue;
700     }
701     aM.Clear();
702     TopExp::MapShapes(aS, aTypes[i], aM);
703     aNbS=aM.Extent();
704     aInfo.SetNbSubShapes(aTypes[i], aNbS);
705   }
706 }
707 //=======================================================================
708 //function :NbShells 
709 //purpose  : 
710 //=======================================================================
711 Standard_Integer NbShells(const TopoDS_Solid& aSd)
712 {
713   Standard_Integer iCnt;
714   TopoDS_Iterator aIt;
715   //
716   iCnt=0;
717   //
718   aIt.Initialize(aSd);
719   for (; aIt.More(); aIt.Next()){
720     //const TopoDS_Shape& aSh=aIt.Value();
721     ++iCnt;
722   }
723   return iCnt;
724 }
725 //=======================================================================
726 //function : NbWires
727 //purpose  : 
728 //=======================================================================
729 Standard_Integer NbWires(const TopoDS_Face& aF)
730 {
731   Standard_Integer iCnt;
732   TopoDS_Iterator aIt;
733   //
734   iCnt=0;
735   //
736   aIt.Initialize(aF);
737   for (; aIt.More(); aIt.Next()){
738     //const TopoDS_Shape& aW=aIt.Value();
739     ++iCnt;
740   }
741   return iCnt;
742 }
743 //=======================================================================
744 //function : IsAllowedType
745 //purpose  : 
746 //=======================================================================
747 Standard_Boolean IsAllowedType(const GeomAbs_CurveType aCT)
748 {
749   Standard_Boolean bRet;
750   Standard_Integer i, aNb;
751   GeomAbs_CurveType aTypes[]={
752     GeomAbs_Line, GeomAbs_Circle, GeomAbs_Ellipse
753   };
754   //
755   bRet=Standard_False;
756   aNb=sizeof(aTypes)/sizeof(aTypes[0]);
757   for (i=0; i<aNb && !bRet; ++i) {
758     bRet=(aCT==aTypes[i]);
759   }
760   //
761   return bRet;
762 }
763 //=======================================================================
764 //function : IsAllowedType
765 //purpose  : 
766 //=======================================================================
767 Standard_Boolean IsAllowedType(const GeomAbs_SurfaceType aST)
768 {
769   Standard_Boolean bRet;
770   Standard_Integer i, aNb;
771   GeomAbs_SurfaceType aTypes[]={
772     GeomAbs_Plane, GeomAbs_Cylinder, 
773     GeomAbs_Cone,  GeomAbs_Sphere,
774     GeomAbs_Torus
775   };
776   //
777   bRet=Standard_False;
778   aNb=sizeof(aTypes)/sizeof(aTypes[0]);
779   for (i=0; i<aNb && !bRet; ++i) {
780     bRet=(aST==aTypes[i]);
781   }
782   //
783   return bRet;
784 }
785 //
786 // myErrorStatus
787 // 
788 // 0  - Ok
789 // 1  - The object is just initialized
790 //
791 // 10 - Null shape 
792 // 11 - circle/ellipse edge without vertices