0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / STEPSelections / STEPSelections_SelectInstances.cxx
1 // Created on: 1999-03-23
2 // Created by: data exchange team
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <STEPSelections_SelectInstances.ixx>
24 #include <Interface_Macros.hxx>
25 #include <StepShape_ShapeDefinitionRepresentation.hxx>
26 #include <StepShape_ContextDependentShapeRepresentation.hxx>
27 #include <StepShape_ShapeRepresentation.hxx>
28 #include <StepRepr_RepresentationItem.hxx>
29 #include <StepShape_FacetedBrep.hxx>
30 #include <StepShape_BrepWithVoids.hxx>
31 #include <StepShape_ManifoldSolidBrep.hxx>
32 #include <StepShape_ShellBasedSurfaceModel.hxx>
33 #include <StepShape_FacetedBrepAndBrepWithVoids.hxx>
34 #include <StepShape_GeometricSet.hxx>
35 #include <StepShape_FaceSurface.hxx>
36 #include <StepRepr_MappedItem.hxx>
37 #include <STEPConstruct_Assembly.hxx>
38 #include <StepRepr_ShapeRepresentationRelationship.hxx>
39 #include <TColStd_IndexedMapOfTransient.hxx>
40 #include <Interface_HGraph.hxx>
41
42 static Handle(Interface_HGraph) myGraph;
43 static Interface_EntityIterator myEntities;
44
45 STEPSelections_SelectInstances::STEPSelections_SelectInstances():IFSelect_SelectExplore (-1){ }
46
47 static void AddAllSharings(const Handle(Standard_Transient)& start,
48                             const Interface_Graph& graph,
49                             Interface_EntityIterator& explored) 
50 {
51   if(start.IsNull()) return;
52   Interface_EntityIterator subs = graph.Shareds(start);
53   for (subs.Start(); subs.More(); subs.Next()) {
54     explored.AddItem(subs.Value()); 
55     AddAllSharings(subs.Value(), graph, explored);
56   }
57 }
58     
59
60 static void AddInstances(const Handle(Standard_Transient)& start,
61                          const Interface_Graph& graph,
62                          Interface_EntityIterator& explored)
63 {
64   if(start.IsNull()) return;
65   
66   explored.AddItem(start);
67   if (start->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
68     DeclareAndCast(StepShape_ShapeDefinitionRepresentation,sdr,start);
69     AddInstances(sdr->UsedRepresentation(),graph,explored);
70     Interface_EntityIterator subs = graph.Shareds(start);
71     for (subs.Start(); subs.More(); subs.Next()) {
72       DeclareAndCast(StepShape_ContextDependentShapeRepresentation,anitem,subs.Value());
73       if (anitem.IsNull()) continue;
74       AddInstances(anitem,graph,explored);
75     }
76     return;
77   }
78   
79   if (start->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) {
80     DeclareAndCast(StepShape_ShapeRepresentation,sr,start);
81     Standard_Integer nb = sr->NbItems();
82     for (Standard_Integer i = 1; i <= nb; i++) {
83       Handle(StepRepr_RepresentationItem) anitem = sr->ItemsValue(i);
84       AddInstances(anitem,graph,explored);
85     }
86     return;
87   }
88   
89   if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrep))||
90       start->IsKind(STANDARD_TYPE(StepShape_BrepWithVoids))||
91       start->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep))||
92       start->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))||
93       start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepAndBrepWithVoids))||
94       start->IsKind(STANDARD_TYPE(StepShape_GeometricSet))||
95       start->IsKind(STANDARD_TYPE(StepShape_FaceSurface))||
96       start->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
97     AddAllSharings(start, graph, explored);
98     return;
99   }
100
101   if (start->IsKind(STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation))) {
102     DeclareAndCast(StepShape_ContextDependentShapeRepresentation,CDSR,start);
103     DeclareAndCast(StepRepr_RepresentationRelationship,SRR,CDSR->RepresentationRelation());
104     if ( SRR.IsNull() ) return ;
105     
106     Handle(StepRepr_Representation) rep;
107     Standard_Boolean SRRReversed = STEPConstruct_Assembly::CheckSRRReversesNAUO ( graph.Model(), CDSR );
108     if(SRRReversed)
109       rep = SRR->Rep2();
110     else
111       rep = SRR->Rep1();
112     
113     Interface_EntityIterator subs = graph.Sharings(rep);
114     for (subs.Start(); subs.More(); subs.Next()) 
115       if ( subs.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
116         DeclareAndCast(StepShape_ShapeDefinitionRepresentation,SDR,subs.Value());
117         AddInstances(SDR,graph,explored);
118       }
119     //???
120     return;
121   } 
122   
123   if (start->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship)) ) {
124     DeclareAndCast(StepRepr_ShapeRepresentationRelationship,und,start);
125     for (Standard_Integer i = 1; i <= 2; i ++) {
126       Handle(Standard_Transient) anitem;
127       if (i == 1) anitem = und->Rep1();
128       if (i == 2) anitem = und->Rep2();
129       AddInstances(anitem,graph,explored);
130     } 
131     return;
132   }
133   
134 }
135      
136      
137 Interface_EntityIterator STEPSelections_SelectInstances::RootResult(const Interface_Graph &G) const
138 {
139   if(myGraph.IsNull()||(G.Model()!=myGraph->Graph().Model()))
140     {
141       
142       Interface_EntityIterator roots = G.RootEntities();
143       myGraph = new Interface_HGraph(G);
144       myEntities.Destroy();
145       for (roots.Start(); roots.More(); roots.Next())
146         AddInstances(roots.Value(), G, myEntities);
147     }
148
149   if(HasInput()||HasAlternate()) {
150     Interface_EntityIterator select = InputResult(G);
151     Standard_Integer nbSelected = select.NbEntities();
152     TColStd_IndexedMapOfTransient filter (nbSelected);
153     for(select.Start(); select.More(); select.Next())
154       filter.Add(select.Value());
155     Interface_EntityIterator result;
156     for(myEntities.Start(); myEntities.More(); myEntities.Next()) 
157       if(filter.Contains(myEntities.Value()))
158         result.AddItem(myEntities.Value());
159     return result;
160   }
161   else
162     return myEntities;
163 }
164
165
166 Standard_Boolean STEPSelections_SelectInstances::Explore(const Standard_Integer,
167                                                         const Handle(Standard_Transient)&,
168                                                         const Interface_Graph&,
169                                                         Interface_EntityIterator&) const
170 {
171   return Standard_False;
172 }
173
174 Standard_Boolean STEPSelections_SelectInstances::HasUniqueResult() const
175 {
176   return Standard_True;
177 }
178
179 TCollection_AsciiString STEPSelections_SelectInstances::ExploreLabel() const
180 {
181   return TCollection_AsciiString ("Instances");
182 }