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