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
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.
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.
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.
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>
42 static Handle(Interface_HGraph) myGraph;
43 static Interface_EntityIterator myEntities;
45 STEPSelections_SelectInstances::STEPSelections_SelectInstances():IFSelect_SelectExplore (-1){ }
47 static void AddAllSharings(const Handle(Standard_Transient)& start,
48 const Interface_Graph& graph,
49 Interface_EntityIterator& explored)
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);
60 static void AddInstances(const Handle(Standard_Transient)& start,
61 const Interface_Graph& graph,
62 Interface_EntityIterator& explored)
64 if(start.IsNull()) return;
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);
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);
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);
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 ;
106 Handle(StepRepr_Representation) rep;
107 Standard_Boolean SRRReversed = STEPConstruct_Assembly::CheckSRRReversesNAUO ( graph.Model(), CDSR );
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);
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);
137 Interface_EntityIterator STEPSelections_SelectInstances::RootResult(const Interface_Graph &G) const
139 if(myGraph.IsNull()||(G.Model()!=myGraph->Graph().Model()))
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);
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());
166 Standard_Boolean STEPSelections_SelectInstances::Explore(const Standard_Integer,
167 const Handle(Standard_Transient)&,
168 const Interface_Graph&,
169 Interface_EntityIterator&) const
171 return Standard_False;
174 Standard_Boolean STEPSelections_SelectInstances::HasUniqueResult() const
176 return Standard_True;
179 TCollection_AsciiString STEPSelections_SelectInstances::ExploreLabel() const
181 return TCollection_AsciiString ("Instances");