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