Salome HOME
a599ca89e864feb4378383859ca32c5eb1487344
[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     gp_Vec aVec(aPc, aP2);
574     gp_Dir aDir(aVec);
575     aInfo.SetDirection(aDir);
576   }
577   //modified by NIZNHY-PKV Tue Jul 03 10:19:06 2012t
578   // Line
579   else if (aCT==GeomAbs_Line) {
580     Standard_Boolean bInf1, bInf2;
581     Standard_Real aLength;
582     gp_Lin aLin;
583     gp_XYZ aXYZ1, aXYZ2, aXYZc;
584     //
585     aLin=aGAC.Line();
586     aP=aLin.Location();
587     aD=aLin.Direction();
588     //
589     aInfo.SetKindOfShape(GEOMAlgo_KS_LINE);
590     aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
591     aInfo.SetLocation(aP);
592     aInfo.SetDirection(aD);
593     //
594     bInf1=Precision::IsNegativeInfinite(aT1);
595     bInf2=Precision::IsPositiveInfinite(aT2);
596     if (bInf1||bInf2) {
597       aInfo.SetKindOfBounds(GEOMAlgo_KB_INFINITE);
598       aInfo.SetKindOfName(GEOMAlgo_KN_LINE);
599     }
600     else {
601       aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
602       aInfo.SetKindOfName(GEOMAlgo_KN_SEGMENT);
603       aGAC.D0(aT1, aP1);
604       aGAC.D0(aT2, aP2);
605       aInfo.SetPnt1(aP1);
606       aInfo.SetPnt2(aP2);
607       //
608       aLength=aP1.Distance(aP2);
609       aXYZ1=aP1.XYZ();
610       aXYZ2=aP2.XYZ();
611       aXYZc=aXYZ1+aXYZ2;
612       aXYZc.Multiply(0.5);
613       //
614       aPc.SetXYZ(aXYZc);
615       gp_Vec aVec(aPc, aP2);
616       gp_Dir aDir(aVec);
617       //
618       aInfo.SetLocation(aPc);
619       aInfo.SetDirection(aDir);
620       aInfo.SetLength(aLength);
621     }
622   }// if (aCT==GeomAbs_Line) {
623   //
624   // Circle
625   else if (aCT==GeomAbs_Circle) {
626     gp_Circ aCirc;
627     //
628     aCirc=aGAC.Circle();
629     aP=aCirc.Location();
630     aAx2=aCirc.Position();
631     aR1=aCirc.Radius();
632     //
633     aInfo.SetKindOfShape(GEOMAlgo_KS_CIRCLE);
634     aInfo.SetLocation(aP);
635     aInfo.SetPosition(aAx2);
636     aInfo.SetRadius1(aR1);
637     //
638     aNbV=aInfo.NbSubShapes(TopAbs_VERTEX);
639     if (!aNbV) {
640       myErrorStatus=11; // circle edge without vertices
641       return;
642     }
643     aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
644     aGAC.D0(aT1, aP1);
645     aGAC.D0(aT2, aP2);
646     aInfo.SetPnt1(aP1);
647     aInfo.SetPnt2(aP2);
648     //
649     if (aNbV==1) {
650       aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
651       aInfo.SetKindOfName(GEOMAlgo_KN_CIRCLE);
652     }
653     else {
654       aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
655       aInfo.SetKindOfName(GEOMAlgo_KN_ARCCIRCLE);
656       //
657       gp_Vec aVecX(aP, aP1);
658       gp_Dir aDirX(aVecX);
659       gp_Ax2 aAx2new(aP, aAx2.Direction(), aDirX);
660       aInfo.SetPosition(aAx2new);
661     }
662   }// else if (aCT==GeomAbs_Circle) {
663   //
664   // Ellipse
665   else if (aCT==GeomAbs_Ellipse) {
666     gp_Elips aElips;
667     //
668     aElips=aGAC.Ellipse();
669     aP=aElips.Location();
670     aAx2=aElips.Position();
671     aR1=aElips.MajorRadius();
672     aR2=aElips.MinorRadius();
673     //
674     aInfo.SetKindOfShape(GEOMAlgo_KS_ELLIPSE);
675     aInfo.SetLocation(aP);
676     aInfo.SetPosition(aAx2);
677     aInfo.SetRadius1(aR1);
678     aInfo.SetRadius2(aR2);
679     //
680     aNbV=aInfo.NbSubShapes(TopAbs_VERTEX);
681     if (!aNbV) {
682       myErrorStatus=11; // ellipse edge without vertices
683       return;
684     }
685     aInfo.SetKindOfBounds(GEOMAlgo_KB_TRIMMED);
686     aGAC.D0(aT1, aP1);
687     aGAC.D0(aT2, aP2);
688     aInfo.SetPnt1(aP1);
689     aInfo.SetPnt2(aP2);
690     //
691     if (aNbV==1) {
692       aInfo.SetKindOfClosed(GEOMAlgo_KC_CLOSED);
693       aInfo.SetKindOfName(GEOMAlgo_KN_ELLIPSE);
694     }
695     else {
696       aInfo.SetKindOfClosed(GEOMAlgo_KC_NOTCLOSED);
697       aInfo.SetKindOfName(GEOMAlgo_KN_ARCELLIPSE);
698       //
699       gp_Vec aVecX(aP, aP1);
700       gp_Dir aDirX(aVecX);
701       gp_Ax2 aAx2new(aP, aAx2.Direction(), aDirX);
702       aInfo.SetPosition(aAx2new);
703     }
704   }// else if (aCT==GeomAbs_Ellipse) {
705   //
706   FillSubShapes(aS);
707 }
708 //=======================================================================
709 //function :FillVertex
710 //purpose  :
711 //=======================================================================
712   void GEOMAlgo_ShapeInfoFiller::FillVertex(const TopoDS_Shape& aS)
713 {
714   myErrorStatus=0;
715   //
716   gp_Pnt aP;
717   TopoDS_Vertex aV;
718   //
719   if (myMapInfo.Contains(aS)) {
720     return;
721   }
722   else {
723     GEOMAlgo_ShapeInfo aInfoX;
724     myMapInfo.Add(aS, aInfoX);
725   }
726   GEOMAlgo_ShapeInfo& aInfo=myMapInfo.ChangeFromKey(aS);
727   //
728   aV=TopoDS::Vertex(aS);
729   aP=BRep_Tool::Pnt(aV);
730   //
731   aInfo.SetType(TopAbs_VERTEX);
732   aInfo.SetLocation(aP);
733   myMapInfo.Add(aS, aInfo);
734 }
735 //=======================================================================
736 //function : FillNbSubshapes
737 //purpose  :
738 //=======================================================================
739   void GEOMAlgo_ShapeInfoFiller::FillNbSubShapes(const TopoDS_Shape& aS,
740                                                  GEOMAlgo_ShapeInfo& aInfo)
741 {
742   myErrorStatus=0;
743   //
744   Standard_Integer i, aNb, aNbS;
745   TopTools_IndexedMapOfShape aM;
746   TopAbs_ShapeEnum aST;
747   TopAbs_ShapeEnum aTypes[]= {
748     //TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX
749     TopAbs_COMPOUND,
750     TopAbs_COMPSOLID,
751     TopAbs_SOLID,
752     TopAbs_SHELL,
753     TopAbs_FACE,
754     TopAbs_WIRE,
755     TopAbs_EDGE,
756     TopAbs_VERTEX
757   };
758
759   //
760   aST=aS.ShapeType();
761   aNb=sizeof(aTypes)/sizeof(aTypes[0]);
762   for (i=0; i<aNb; ++i) {
763     if (aTypes[i]==aST) {
764       continue;
765     }
766     aM.Clear();
767     TopExp::MapShapes(aS, aTypes[i], aM);
768     aNbS=aM.Extent();
769     aInfo.SetNbSubShapes(aTypes[i], aNbS);
770   }
771 }
772 //=======================================================================
773 //function :NbShells
774 //purpose  :
775 //=======================================================================
776 Standard_Integer GEOMAlgo_ShapeInfoFiller::NbShells(const TopoDS_Solid& aSd)
777 {
778   Standard_Integer iCnt;
779   TopoDS_Iterator aIt;
780   //
781   iCnt=0;
782   //
783   aIt.Initialize(aSd);
784   for (; aIt.More(); aIt.Next()) {
785     //const TopoDS_Shape& aSh=aIt.Value();
786     ++iCnt;
787   }
788   return iCnt;
789 }
790 //=======================================================================
791 //function : NbWires
792 //purpose  :
793 //=======================================================================
794 Standard_Integer GEOMAlgo_ShapeInfoFiller::NbWires(const TopoDS_Face& aF)
795 {
796   Standard_Integer iCnt;
797   TopoDS_Iterator aIt;
798   //
799   iCnt=0;
800   //
801   aIt.Initialize(aF);
802   for (; aIt.More(); aIt.Next()) {
803     //const TopoDS_Shape& aW=aIt.Value();
804     ++iCnt;
805   }
806   return iCnt;
807 }
808 //=======================================================================
809 //function : IsAllowedType
810 //purpose  :
811 //=======================================================================
812 Standard_Boolean GEOMAlgo_ShapeInfoFiller::IsAllowedType(const GeomAbs_CurveType aCT)
813 {
814   Standard_Boolean bRet;
815   Standard_Integer i, aNb;
816   GeomAbs_CurveType aTypes[]={
817     GeomAbs_Line,
818     GeomAbs_Circle,
819     GeomAbs_Ellipse,
820     GeomAbs_BSplineCurve //modified by NIZNHY-PKV Tue Jul 03 10:18:01 2012ft
821   };
822   //
823   bRet=Standard_False;
824   aNb=sizeof(aTypes)/sizeof(aTypes[0]);
825   for (i=0; i<aNb && !bRet; ++i) {
826     bRet=(aCT==aTypes[i]);
827   }
828   return bRet;
829 }
830 //=======================================================================
831 //function : IsAllowedType
832 //purpose  :
833 //=======================================================================
834 Standard_Boolean GEOMAlgo_ShapeInfoFiller::IsAllowedType(const GeomAbs_SurfaceType aST)
835 {
836   Standard_Boolean bRet;
837   Standard_Integer i, aNb;
838   GeomAbs_SurfaceType aTypes[]={
839     GeomAbs_Plane, GeomAbs_Cylinder,
840     GeomAbs_Cone,  GeomAbs_Sphere,
841     GeomAbs_Torus
842   };
843   //
844   bRet=Standard_False;
845   aNb=sizeof(aTypes)/sizeof(aTypes[0]);
846   for (i=0; i<aNb && !bRet; ++i) {
847     bRet=(aST==aTypes[i]);
848   }
849   //
850   return bRet;
851 }
852 //
853 // myErrorStatus
854 //
855 // 0  - Ok
856 // 1  - The object is just initialized
857 //
858 // 10 - Null shape
859 // 11 - circle/ellipse edge without vertices