7fd59977 |
1 | #include <STEPControl_Reader.ixx> |
2 | #include <STEPControl_Controller.hxx> |
3 | #include <XSControl_Controller.hxx> |
4 | #include <XSControl_TransferReader.hxx> |
5 | #include <Interface_ShareFlags.hxx> |
6 | |
7 | #include <STEPControl_ActorRead.hxx> |
8 | |
9 | #include <StepBasic_ProductDefinition.hxx> |
10 | #include <Interface_EntityIterator.hxx> |
11 | #include <Interface_Graph.hxx> |
12 | #include <Interface_Static.hxx> |
13 | #include <StepRepr_NextAssemblyUsageOccurrence.hxx> |
14 | #include <StepBasic_ProductDefinitionContext.hxx> |
15 | #include <StepBasic_ApplicationContext.hxx> |
16 | #include <TCollection_AsciiString.hxx> |
17 | #include <StepBasic_ProductDefinitionWithAssociatedDocuments.hxx> |
18 | #include <StepBasic_DocumentProductEquivalence.hxx> |
19 | #include <StepShape_ShapeDefinitionRepresentation.hxx> |
20 | #include <StepShape_ShapeRepresentation.hxx> |
21 | #include <StepRepr_PropertyDefinition.hxx> |
22 | #include <StepRepr_RepresentationRelationship.hxx> |
23 | #include <StepRepr_ShapeAspect.hxx> |
24 | #include <StepRepr_ProductDefinitionShape.hxx> |
25 | #include <StepRepr_NextAssemblyUsageOccurrence.hxx> |
26 | #include <StepRepr_RepresentationMap.hxx> |
27 | #include <StepRepr_MappedItem.hxx> |
28 | #include <Transfer_TransientProcess.hxx> |
29 | #include <TColStd_HSequenceOfTransient.hxx> |
30 | |
31 | //======================================================================= |
32 | //function : STEPControl_Reader |
33 | //purpose : |
34 | //======================================================================= |
35 | |
36 | STEPControl_Reader::STEPControl_Reader () |
37 | { |
38 | STEPControl_Controller::Init(); |
39 | SetNorm ("STEP"); |
40 | } |
41 | |
42 | //======================================================================= |
43 | //function : STEPControl_Reader |
44 | //purpose : |
45 | //======================================================================= |
46 | |
47 | STEPControl_Reader::STEPControl_Reader |
48 | (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch) |
49 | { |
50 | STEPControl_Controller::Init(); |
51 | SetWS (WS,scratch); |
52 | SetNorm ("STEP"); |
53 | } |
54 | |
55 | //======================================================================= |
56 | //function : StepModel |
57 | //purpose : |
58 | //======================================================================= |
59 | |
60 | Handle(StepData_StepModel) STEPControl_Reader::StepModel () const |
61 | { |
62 | return Handle(StepData_StepModel)::DownCast(Model()); |
63 | } |
64 | |
65 | //======================================================================= |
66 | //function : TransferRoot |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | Standard_Boolean STEPControl_Reader::TransferRoot (const Standard_Integer num) |
71 | { |
72 | return TransferOneRoot (num); |
73 | } |
74 | |
75 | //======================================================================= |
76 | //function : NbRootsForTransfer |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | Standard_Integer STEPControl_Reader::NbRootsForTransfer() |
81 | { |
82 | if (therootsta) return theroots.Length(); |
83 | therootsta = Standard_True; |
84 | |
85 | //theroots.Clear(); |
86 | Standard_Integer nb = Model()->NbEntities(); |
87 | for (Standard_Integer i = 1; i <= nb; i ++) { |
88 | Handle(Standard_Transient) ent = Model()->Value(i); |
89 | if(ent->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) { |
90 | // PTV 31.01.2003 TRJ11 exclude Product Definition With Associated Document from roots |
91 | if (ent->IsKind(STANDARD_TYPE(StepBasic_ProductDefinitionWithAssociatedDocuments))) { |
92 | // check if PDWAD-> PDF <-Document_Product_Equivalence. |
93 | Standard_Boolean iSexclude = Standard_False; |
94 | Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) PDWAD = |
95 | Handle(StepBasic_ProductDefinitionWithAssociatedDocuments)::DownCast(ent); |
96 | Interface_EntityIterator PDWADsubs = WS()->Graph().Shareds(PDWAD); |
97 | for (PDWADsubs.Start(); PDWADsubs.More(); PDWADsubs.Next()) { |
98 | if ( !PDWADsubs.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinitionFormation))) |
99 | continue; |
100 | Handle(StepBasic_ProductDefinitionFormation) localPDF = |
101 | Handle(StepBasic_ProductDefinitionFormation)::DownCast(PDWADsubs.Value()); |
102 | Interface_EntityIterator PDFsubs = WS()->Graph().Sharings(localPDF); |
103 | for( PDFsubs.Start(); PDFsubs.More(); PDFsubs.Next() ) |
104 | if (PDFsubs.Value()->IsKind(STANDARD_TYPE(StepBasic_DocumentProductEquivalence))) { |
105 | iSexclude = Standard_True; |
106 | break; |
107 | } |
108 | if (iSexclude) |
109 | break; |
110 | } |
111 | if (iSexclude) { |
112 | #ifdef DEB |
113 | cout << "Warning: STEPControl_Reader::NbRootsForTransfer exclude PDWAD from roots" << endl; |
114 | #endif |
115 | continue; |
116 | } |
117 | } |
118 | Handle(StepBasic_ProductDefinition) PD = |
119 | Handle(StepBasic_ProductDefinition)::DownCast(ent); |
120 | Standard_Boolean IsRoot = Standard_True; |
121 | const Interface_Graph& graph = WS()->Graph(); |
122 | // determinate roots used NextAssemblyUsageOccurrence |
123 | Interface_EntityIterator subs = graph.Sharings(PD); |
124 | for(subs.Start(); subs.More(); subs.Next()) { |
125 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = |
126 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value()); |
127 | if (NAUO.IsNull()) continue; |
128 | if (PD==NAUO->RelatedProductDefinition()) IsRoot=Standard_False; |
129 | } |
130 | // determinate roots used ProductDefinitionContext |
131 | if(IsRoot) { |
132 | const char *str1 = Interface_Static::CVal("read.step.product.context"); |
133 | Standard_Integer ICS = Interface_Static::IVal("read.step.product.context"); |
134 | if(ICS>1) { |
135 | subs = graph.Shareds(PD); |
136 | for(subs.Start(); subs.More(); subs.Next()) { |
137 | Handle(StepBasic_ProductDefinitionContext) PDC = |
138 | Handle(StepBasic_ProductDefinitionContext)::DownCast(subs.Value()); |
139 | if (PDC.IsNull()) continue; |
140 | const char *str2 = PDC->LifeCycleStage()->String().ToCString(); |
141 | const char *str3 = PDC->Name()->String().ToCString(); |
142 | if( !( strcasecmp(str1,str2)==0 || strcasecmp(str1,str3)==0 ) ) |
143 | IsRoot=Standard_False; |
144 | } |
145 | } |
146 | } |
147 | // determinate roots used ProductDefinitionFormationRelationship |
148 | //subs = graph.Shareds(PD); |
149 | //for(subs.Start(); subs.More(); subs.Next()) { |
150 | // Handle(StepBasic_ProductDefinitionFormation) PDF = |
151 | // Handle(StepBasic_ProductDefinitionFormation)::DownCast(subs.Value()); |
152 | // if (PDF.IsNull()) continue; |
153 | // Interface_EntityIterator subs1 = graph.Sharings(PDF); |
154 | // for(subs1.Start(); subs1.More(); subs1.Next()) { |
155 | // Handle(StepBasic_ProductDefinitionFormationRelationship) PDFR = |
156 | // Handle(StepBasic_ProductDefinitionFormationRelationship)::DownCast(subs1.Value()); |
157 | // if (PDFR.IsNull()) continue; |
158 | // if (PDF==PDFR->RelatedProductDefinition()) IsRoot=Standard_False; |
159 | // } |
160 | //} |
161 | if (IsRoot) { |
162 | theroots.Append(ent); |
163 | WS()->MapReader()->RootsForTransfer()->Append(ent); |
164 | } |
165 | } |
166 | TCollection_AsciiString aProdMode = Interface_Static::CVal("read.step.product.mode"); |
167 | if(!aProdMode.IsEqual("ON")) { |
168 | if(ent->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) { |
169 | Standard_Boolean IsRoot = Standard_True; |
170 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
171 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(ent); |
172 | Handle(StepRepr_PropertyDefinition) PropDef = SDR->Definition().PropertyDefinition(); |
173 | if(!PropDef.IsNull()) { |
174 | Handle(StepBasic_ProductDefinition) PD = PropDef->Definition().ProductDefinition(); |
175 | if(!PD.IsNull()) IsRoot = Standard_False; |
176 | if(IsRoot) { |
177 | Handle(StepRepr_ShapeAspect) SA = PropDef->Definition().ShapeAspect(); |
178 | if(!SA.IsNull()) { |
179 | Handle(StepRepr_ProductDefinitionShape) PDS = SA->OfShape(); |
180 | PD = PDS->Definition().ProductDefinition(); |
181 | if(!PD.IsNull()) IsRoot = Standard_False; |
182 | } |
183 | } |
184 | if(IsRoot) { |
185 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = |
186 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(PropDef->Definition().ProductDefinitionRelationship()); |
187 | if(!NAUO.IsNull()) IsRoot = Standard_False; |
188 | } |
189 | if(IsRoot) { |
190 | Handle(StepShape_ShapeRepresentation) SR = |
191 | Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation()); |
192 | if(SR.IsNull()) IsRoot = Standard_False; |
193 | } |
194 | } |
195 | if(IsRoot) { |
196 | theroots.Append(ent); |
197 | WS()->MapReader()->RootsForTransfer()->Append(ent); |
198 | } |
199 | } |
200 | if(ent->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) { |
201 | Standard_Boolean IsRoot = Standard_True; |
202 | Handle(StepShape_ShapeRepresentation) SR = |
203 | Handle(StepShape_ShapeRepresentation)::DownCast(ent); |
204 | const Interface_Graph& graph = WS()->Graph(); |
205 | Interface_EntityIterator subs = graph.Sharings(SR); |
206 | for(subs.Start(); subs.More() && IsRoot; subs.Next()) { |
207 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
208 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value()); |
209 | if(!SDR.IsNull()) IsRoot = Standard_False; |
210 | if(IsRoot) { |
211 | Handle(StepRepr_RepresentationRelationship) RR = |
212 | Handle(StepRepr_RepresentationRelationship)::DownCast(subs.Value()); |
213 | if(!RR.IsNull()) { |
214 | Handle(StepShape_ShapeRepresentation) SR2 = |
215 | Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1()); |
216 | if(SR==SR2) |
217 | SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2()); |
218 | Interface_EntityIterator subs2 = graph.Sharings(SR2); |
219 | for(subs2.Start(); subs2.More(); subs2.Next()) { |
220 | Handle(StepShape_ShapeDefinitionRepresentation) SDR2 = |
221 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value()); |
222 | if(!SDR2.IsNull()) IsRoot = Standard_False; |
223 | //else { |
224 | // if(SR==SRR->Rep2()) IsRoot = Standard_False; |
225 | //} |
226 | } |
227 | } |
228 | } |
229 | if(IsRoot) { |
230 | Handle(StepRepr_RepresentationMap) RM = |
231 | Handle(StepRepr_RepresentationMap)::DownCast(subs.Value()); |
232 | if(!RM.IsNull()) { |
233 | Interface_EntityIterator subs2 = graph.Sharings(RM); |
234 | for(subs2.Start(); subs2.More(); subs2.Next()) { |
235 | Handle(StepRepr_MappedItem) MI = Handle(StepRepr_MappedItem)::DownCast(subs2.Value()); |
236 | if(!MI.IsNull()) { |
237 | Interface_EntityIterator subs3 = graph.Sharings(MI); |
238 | for(subs3.Start(); subs3.More(); subs3.Next()) { |
239 | Handle(StepShape_ShapeRepresentation) SR2 = |
240 | Handle(StepShape_ShapeRepresentation)::DownCast(subs3.Value()); |
241 | if(!SR2.IsNull()) IsRoot = Standard_False; |
242 | } |
243 | } |
244 | } |
245 | } |
246 | } |
247 | } |
248 | if(IsRoot) { |
249 | theroots.Append(ent); |
250 | WS()->MapReader()->RootsForTransfer()->Append(ent); |
251 | } |
252 | } |
253 | } |
254 | |
255 | } |
256 | |
257 | |
258 | return theroots.Length(); |
259 | } |
260 | |