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