1 // Created on: 1999-03-23
2 // Created by: data exchange team
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Interface_EntityIterator.hxx>
19 #include <Interface_Graph.hxx>
20 #include <Interface_HGraph.hxx>
21 #include <Interface_Macros.hxx>
22 #include <Standard_Transient.hxx>
23 #include <Standard_Type.hxx>
24 #include <STEPConstruct_Assembly.hxx>
25 #include <StepRepr_MappedItem.hxx>
26 #include <StepRepr_RepresentationItem.hxx>
27 #include <StepRepr_ShapeRepresentationRelationship.hxx>
28 #include <STEPSelections_SelectInstances.hxx>
29 #include <StepShape_BrepWithVoids.hxx>
30 #include <StepShape_ContextDependentShapeRepresentation.hxx>
31 #include <StepShape_FaceSurface.hxx>
32 #include <StepShape_FacetedBrep.hxx>
33 #include <StepShape_FacetedBrepAndBrepWithVoids.hxx>
34 #include <StepShape_GeometricSet.hxx>
35 #include <StepShape_ManifoldSolidBrep.hxx>
36 #include <StepShape_ShapeDefinitionRepresentation.hxx>
37 #include <StepShape_ShapeRepresentation.hxx>
38 #include <StepShape_ShellBasedSurfaceModel.hxx>
39 #include <TCollection_AsciiString.hxx>
40 #include <TColStd_IndexedMapOfTransient.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(STEPSelections_SelectInstances,IFSelect_SelectExplore)
44 static Handle(Interface_HGraph) myGraph;
45 static Interface_EntityIterator myEntities;
47 STEPSelections_SelectInstances::STEPSelections_SelectInstances():IFSelect_SelectExplore (-1){ }
49 static void AddAllSharings(const Handle(Standard_Transient)& start,
50 const Interface_Graph& graph,
51 Interface_EntityIterator& explored)
53 if(start.IsNull()) return;
54 Interface_EntityIterator subs = graph.Shareds(start);
55 for (subs.Start(); subs.More(); subs.Next()) {
56 explored.AddItem(subs.Value());
57 AddAllSharings(subs.Value(), graph, explored);
62 static void AddInstances(const Handle(Standard_Transient)& start,
63 const Interface_Graph& graph,
64 Interface_EntityIterator& explored)
66 if(start.IsNull()) return;
68 explored.AddItem(start);
69 if (start->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
70 DeclareAndCast(StepShape_ShapeDefinitionRepresentation,sdr,start);
71 AddInstances(sdr->UsedRepresentation(),graph,explored);
72 Interface_EntityIterator subs = graph.Shareds(start);
73 for (subs.Start(); subs.More(); subs.Next()) {
74 DeclareAndCast(StepShape_ContextDependentShapeRepresentation,anitem,subs.Value());
75 if (anitem.IsNull()) continue;
76 AddInstances(anitem,graph,explored);
81 if (start->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) {
82 DeclareAndCast(StepShape_ShapeRepresentation,sr,start);
83 Standard_Integer nb = sr->NbItems();
84 for (Standard_Integer i = 1; i <= nb; i++) {
85 Handle(StepRepr_RepresentationItem) anitem = sr->ItemsValue(i);
86 AddInstances(anitem,graph,explored);
91 if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrep))||
92 start->IsKind(STANDARD_TYPE(StepShape_BrepWithVoids))||
93 start->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep))||
94 start->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))||
95 start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepAndBrepWithVoids))||
96 start->IsKind(STANDARD_TYPE(StepShape_GeometricSet))||
97 start->IsKind(STANDARD_TYPE(StepShape_FaceSurface))||
98 start->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
99 AddAllSharings(start, graph, explored);
103 if (start->IsKind(STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation))) {
104 DeclareAndCast(StepShape_ContextDependentShapeRepresentation,CDSR,start);
105 Handle(StepRepr_RepresentationRelationship) SRR = CDSR->RepresentationRelation();
106 if ( SRR.IsNull() ) return ;
108 Handle(StepRepr_Representation) rep;
109 Standard_Boolean SRRReversed = STEPConstruct_Assembly::CheckSRRReversesNAUO ( graph, CDSR );
115 Interface_EntityIterator subs = graph.Sharings(rep);
116 for (subs.Start(); subs.More(); subs.Next())
117 if ( subs.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
118 DeclareAndCast(StepShape_ShapeDefinitionRepresentation,SDR,subs.Value());
119 AddInstances(SDR,graph,explored);
125 if (start->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship)) ) {
126 DeclareAndCast(StepRepr_ShapeRepresentationRelationship,und,start);
127 for (Standard_Integer i = 1; i <= 2; i ++) {
128 Handle(Standard_Transient) anitem;
129 if (i == 1) anitem = und->Rep1();
130 if (i == 2) anitem = und->Rep2();
131 AddInstances(anitem,graph,explored);
139 Interface_EntityIterator STEPSelections_SelectInstances::RootResult(const Interface_Graph &G) const
141 if(myGraph.IsNull()||(G.Model()!=myGraph->Graph().Model()))
144 Interface_EntityIterator roots = G.RootEntities();
145 myGraph = new Interface_HGraph(G);
146 myEntities.Destroy();
147 for (roots.Start(); roots.More(); roots.Next())
148 AddInstances(roots.Value(), G, myEntities);
151 if(HasInput()||HasAlternate()) {
152 Interface_EntityIterator select = InputResult(G);
153 Standard_Integer nbSelected = select.NbEntities();
154 TColStd_IndexedMapOfTransient filter (nbSelected);
155 for(select.Start(); select.More(); select.Next())
156 filter.Add(select.Value());
157 Interface_EntityIterator result;
158 for(myEntities.Start(); myEntities.More(); myEntities.Next())
159 if(filter.Contains(myEntities.Value()))
160 result.AddItem(myEntities.Value());
168 Standard_Boolean STEPSelections_SelectInstances::Explore(const Standard_Integer,
169 const Handle(Standard_Transient)&,
170 const Interface_Graph&,
171 Interface_EntityIterator&) const
173 return Standard_False;
176 Standard_Boolean STEPSelections_SelectInstances::HasUniqueResult() const
178 return Standard_True;
181 TCollection_AsciiString STEPSelections_SelectInstances::ExploreLabel() const
183 return TCollection_AsciiString ("Instances");