0028417: Using PRECOMPILED HEADER to speed up compilation time
[occt.git] / src / IGESSelect / IGESSelect_SelectBasicGeom.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <IGESBasic_Group.hxx>
16 #include <IGESBasic_SingleParent.hxx>
17 #include <IGESData_IGESEntity.hxx>
18 #include <IGESGeom_Boundary.hxx>
19 #include <IGESGeom_BoundedSurface.hxx>
20 #include <IGESGeom_CompositeCurve.hxx>
21 #include <IGESGeom_CurveOnSurface.hxx>
22 #include <IGESGeom_Plane.hxx>
23 #include <IGESGeom_TrimmedSurface.hxx>
24 #include <IGESSelect_SelectBasicGeom.hxx>
25 #include <IGESSolid_EdgeList.hxx>
26 #include <IGESSolid_Face.hxx>
27 #include <IGESSolid_Loop.hxx>
28 #include <IGESSolid_ManifoldSolid.hxx>
29 #include <IGESSolid_Shell.hxx>
30 #include <Interface_EntityIterator.hxx>
31 #include <Interface_Graph.hxx>
32 #include <Interface_Macros.hxx>
33 #include <Standard_Transient.hxx>
34 #include <Standard_Type.hxx>
35 #include <TCollection_AsciiString.hxx>
36
37 IMPLEMENT_STANDARD_RTTIEXT(IGESSelect_SelectBasicGeom,IFSelect_SelectExplore)
38
39 IGESSelect_SelectBasicGeom::IGESSelect_SelectBasicGeom
40   (const Standard_Integer mode)
41     : IFSelect_SelectExplore (-1)    {  thegeom = mode;  }
42
43     Standard_Boolean  IGESSelect_SelectBasicGeom::Explore
44   (const Standard_Integer /*level*/, const Handle(Standard_Transient)& ent,
45    const Interface_Graph& /*G*/, Interface_EntityIterator& explored) const
46 {
47 //  thegeom > 0 : curves3d   < 0 : surfaces   == 0 : curves3d + surfaces libres
48
49   DeclareAndCast(IGESData_IGESEntity,igesent,ent);
50   if (igesent.IsNull()) return Standard_False;
51   Standard_Integer igt = igesent->TypeNumber();
52
53 //   CompositeCurve : a decomposer ?
54   if (igt == 102 && thegeom == 2) {
55     DeclareAndCast(IGESGeom_CompositeCurve,cmc,ent);
56     Standard_Integer i, nb = cmc->NbCurves();
57     for (i = 1; i <= nb; i ++) explored.AddItem (cmc->Curve(i));
58     return Standard_True;
59   }
60
61 //   Lignes en general. Attention CopiousData, aux variantes "habillage"
62   if (igt == 106) return (igesent->FormNumber() < 20);
63   if ( (igt >= 100 && igt <= 106) || igt == 110 || igt == 112 || igt == 116 ||
64       igt == 126 || igt == 130) return (thegeom >= 0);
65
66 //   Surfaces LIBRES, car il n y a pas d autre moyen de les reperer
67 //   (l ideal serait de prendre les bords naturels)
68 //   Ou surfaces debarassees de leurs contours
69   if (igt == 114 || igt == 118 || igt == 120 || igt == 122 || igt == 128 || igt == 140 || igt == 190)
70     return (thegeom <= 0);
71
72 //   Plan 108
73 //   mode surface : on retourne tout le Plane sinon c est inexploitable
74   if (igt == 108) {
75     DeclareAndCast(IGESGeom_Plane,pln,ent);
76     if (thegeom >= 0) explored.AddItem(pln->BoundingCurve());
77     return pln->HasBoundingCurve();
78   }
79
80   if (igt == 116) return (thegeom >= 0);  // on point, ca va bien ...
81
82 //   TrimmedSurface 144
83   if (igt == 144) {
84     DeclareAndCast(IGESGeom_TrimmedSurface,trs,ent);
85     if (thegeom >= 0) {
86       explored.AddItem(trs->OuterContour());
87       Standard_Integer i, nb = trs->NbInnerContours();
88       for (i = 1; i <= nb; i ++) explored.AddItem (trs->InnerContour(i));
89     }
90     else explored.AddItem (trs->Surface());
91     return Standard_True;
92   }
93
94 //   CurveOnSurface 142
95   if (igt == 142 && thegeom >= 0) {
96     DeclareAndCast(IGESGeom_CurveOnSurface,crf,ent);
97     explored.AddItem(crf->Curve3D());
98     return Standard_True;
99   }
100
101 //   Boundary 141
102   if (igt == 141 && thegeom >= 0) {
103     DeclareAndCast(IGESGeom_Boundary,bnd,ent);
104     Standard_Integer i, nb = bnd->NbModelSpaceCurves();
105     for (i = 1; i <= nb; i ++) explored.AddItem (bnd->ModelSpaceCurve(i));
106     return (nb > 0);
107   }
108
109 //   BoundedSurface 143
110   if (igt == 143) {
111     DeclareAndCast(IGESGeom_BoundedSurface,bns,ent);
112     Standard_Integer i, nb = 0;
113     if (thegeom >= 0) {
114       nb = bns->NbBoundaries();
115       for (i = 1; i <= nb; i ++) explored.AddItem (bns->Boundary(i));
116       return (nb != 0);
117     }
118     else explored.AddItem (bns->Surface());
119     return Standard_True;
120   }
121
122 //  SingleParent
123   if (igt == 402 && igesent->FormNumber() == 9) {
124     DeclareAndCast(IGESBasic_SingleParent,sp,ent);
125     if (sp.IsNull()) return Standard_False;
126     explored.AddItem (sp->SingleParent());
127     Standard_Integer i,nb = sp->NbChildren();
128     for (i = 1; i <= nb; i ++) explored.AddItem (sp->Child(i));
129     return Standard_True;
130   }
131
132 //  Groups ... en dernier de la serie 402
133   if (igt == 402) {
134     DeclareAndCast(IGESBasic_Group,gr,ent);
135     if (gr.IsNull()) return Standard_False;
136     Standard_Integer i, nb = gr->NbEntities();
137     for (i = 1; i <= nb; i ++)  explored.AddItem (gr->Entity(i));
138     return Standard_True;
139   }
140
141 //  ManifoldSolid 186  -> Shells
142   if (igt == 186) {
143     DeclareAndCast(IGESSolid_ManifoldSolid,msb,ent);
144     explored.AddItem (msb->Shell());
145     Standard_Integer i, nb = msb->NbVoidShells();
146     for (i = 1; i <= nb; i ++)  explored.AddItem (msb->VoidShell(i));
147     return Standard_True;
148   }
149
150 //  Shell 514 -> Faces
151   if (igt == 514) {
152     DeclareAndCast(IGESSolid_Shell,sh,ent);
153     Standard_Integer i, nb = sh->NbFaces();
154     for (i = 1; i <= nb; i ++)  explored.AddItem (sh->Face(i));
155     return Standard_True;
156   }
157
158 //  Face 510 -> Loops
159   if (igt == 510) {
160     DeclareAndCast(IGESSolid_Face,fc,ent);
161     if (thegeom >= 0) {
162       Standard_Integer i, nb = fc->NbLoops();
163       for (i = 1; i <= nb; i ++)  explored.AddItem (fc->Loop(i));
164     }
165     else explored.AddItem (fc->Surface());
166     return Standard_True;
167   }
168
169 //  Loop 508 -> Curves 3D (enfin !)  mais via EdgeList ...
170   if (igt == 508 && thegeom >= 0) {
171     DeclareAndCast(IGESSolid_Loop,lp,ent);
172     Standard_Integer i, nb = lp->NbEdges();
173     for (i = 1; i <= nb; i ++)  {
174       DeclareAndCast(IGESSolid_EdgeList,edl,lp->Edge(i));
175       Standard_Integer ind = lp->ListIndex(i);
176       if (edl.IsNull()) continue;
177       explored.AddItem(edl->Curve(ind));
178     }
179     return Standard_True;
180   }
181
182 //  Pas trouve
183   return Standard_False;
184 }
185
186
187     TCollection_AsciiString IGESSelect_SelectBasicGeom::ExploreLabel () const
188 {
189   if (thegeom == 2) return TCollection_AsciiString ("Basic Curves 3d");
190   else if (thegeom > 0) return TCollection_AsciiString ("Curves 3d");
191   else if (thegeom < 0) return TCollection_AsciiString ("Surfaces");
192   else  return TCollection_AsciiString ("Basic Geometry");
193 }
194
195
196     Standard_Boolean  IGESSelect_SelectBasicGeom::SubCurves
197   (const Handle(IGESData_IGESEntity)& ent,
198    Interface_EntityIterator& explored)
199 {
200   if (ent.IsNull()) return Standard_False;
201   Standard_Integer igt = ent->TypeNumber();
202
203 //   CompositeCurve : a decomposer ?
204   if (igt == 102) {
205     DeclareAndCast(IGESGeom_CompositeCurve,cmc,ent);
206     Standard_Integer i, nb = cmc->NbCurves();
207     for (i = 1; i <= nb; i ++) explored.AddItem (cmc->Curve(i));
208     return Standard_True;
209   }
210
211 //   Lignes en general. Attention CopiousData, aux variantes "habillage"
212   if (igt == 106) return (ent->FormNumber() < 20);
213   if ( (igt >= 100 && igt <= 106) || igt == 110 || igt == 112 || igt == 116 ||
214       igt == 126 || igt == 130) return Standard_True;
215
216 //  Sinon
217   return Standard_False;
218 }