0022913: Clean up source repository from unused files
[occt.git] / src / STEPControl / STEPControl_Reader.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18#include <STEPControl_Reader.ixx>
19#include <STEPControl_Controller.hxx>
20#include <XSControl_Controller.hxx>
21#include <XSControl_TransferReader.hxx>
22#include <Interface_ShareFlags.hxx>
23
24#include <STEPControl_ActorRead.hxx>
25
26#include <StepBasic_ProductDefinition.hxx>
27#include <Interface_EntityIterator.hxx>
28#include <Interface_Graph.hxx>
29#include <Interface_Static.hxx>
30#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
31#include <StepBasic_ProductDefinitionContext.hxx>
32#include <StepBasic_ApplicationContext.hxx>
33#include <TCollection_AsciiString.hxx>
34#include <StepBasic_ProductDefinitionWithAssociatedDocuments.hxx>
35#include <StepBasic_DocumentProductEquivalence.hxx>
36#include <StepShape_ShapeDefinitionRepresentation.hxx>
37#include <StepShape_ShapeRepresentation.hxx>
38#include <StepRepr_PropertyDefinition.hxx>
39#include <StepRepr_RepresentationRelationship.hxx>
40#include <StepRepr_ShapeAspect.hxx>
41#include <StepRepr_ProductDefinitionShape.hxx>
42#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
43#include <StepRepr_RepresentationMap.hxx>
44#include <StepRepr_MappedItem.hxx>
45#include <Transfer_TransientProcess.hxx>
46#include <TColStd_HSequenceOfTransient.hxx>
47
48//=======================================================================
49//function : STEPControl_Reader
50//purpose :
51//=======================================================================
52
53STEPControl_Reader::STEPControl_Reader ()
54{
55 STEPControl_Controller::Init();
56 SetNorm ("STEP");
57}
58
59//=======================================================================
60//function : STEPControl_Reader
61//purpose :
62//=======================================================================
63
64STEPControl_Reader::STEPControl_Reader
65 (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch)
66{
67 STEPControl_Controller::Init();
68 SetWS (WS,scratch);
69 SetNorm ("STEP");
70}
71
72//=======================================================================
73//function : StepModel
74//purpose :
75//=======================================================================
76
77Handle(StepData_StepModel) STEPControl_Reader::StepModel () const
78{
79 return Handle(StepData_StepModel)::DownCast(Model());
80}
81
82//=======================================================================
83//function : TransferRoot
84//purpose :
85//=======================================================================
86
87Standard_Boolean STEPControl_Reader::TransferRoot (const Standard_Integer num)
88{
89 return TransferOneRoot (num);
90}
91
92//=======================================================================
93//function : NbRootsForTransfer
94//purpose :
95//=======================================================================
96
97Standard_Integer STEPControl_Reader::NbRootsForTransfer()
98{
99 if (therootsta) return theroots.Length();
100 therootsta = Standard_True;
101
102 //theroots.Clear();
103 Standard_Integer nb = Model()->NbEntities();
104 for (Standard_Integer i = 1; i <= nb; i ++) {
105 Handle(Standard_Transient) ent = Model()->Value(i);
106 if(ent->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) {
107 // PTV 31.01.2003 TRJ11 exclude Product Definition With Associated Document from roots
108 if (ent->IsKind(STANDARD_TYPE(StepBasic_ProductDefinitionWithAssociatedDocuments))) {
109 // check if PDWAD-> PDF <-Document_Product_Equivalence.
110 Standard_Boolean iSexclude = Standard_False;
111 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) PDWAD =
112 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments)::DownCast(ent);
113 Interface_EntityIterator PDWADsubs = WS()->Graph().Shareds(PDWAD);
114 for (PDWADsubs.Start(); PDWADsubs.More(); PDWADsubs.Next()) {
115 if ( !PDWADsubs.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinitionFormation)))
116 continue;
117 Handle(StepBasic_ProductDefinitionFormation) localPDF =
118 Handle(StepBasic_ProductDefinitionFormation)::DownCast(PDWADsubs.Value());
119 Interface_EntityIterator PDFsubs = WS()->Graph().Sharings(localPDF);
120 for( PDFsubs.Start(); PDFsubs.More(); PDFsubs.Next() )
121 if (PDFsubs.Value()->IsKind(STANDARD_TYPE(StepBasic_DocumentProductEquivalence))) {
122 iSexclude = Standard_True;
123 break;
124 }
125 if (iSexclude)
126 break;
127 }
128 if (iSexclude) {
129#ifdef DEB
130 cout << "Warning: STEPControl_Reader::NbRootsForTransfer exclude PDWAD from roots" << endl;
131#endif
132 continue;
133 }
134 }
135 Handle(StepBasic_ProductDefinition) PD =
136 Handle(StepBasic_ProductDefinition)::DownCast(ent);
137 Standard_Boolean IsRoot = Standard_True;
138 const Interface_Graph& graph = WS()->Graph();
139 // determinate roots used NextAssemblyUsageOccurrence
140 Interface_EntityIterator subs = graph.Sharings(PD);
141 for(subs.Start(); subs.More(); subs.Next()) {
142 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
143 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value());
144 if (NAUO.IsNull()) continue;
145 if (PD==NAUO->RelatedProductDefinition()) IsRoot=Standard_False;
146 }
147 // determinate roots used ProductDefinitionContext
148 if(IsRoot) {
149 const char *str1 = Interface_Static::CVal("read.step.product.context");
150 Standard_Integer ICS = Interface_Static::IVal("read.step.product.context");
151 if(ICS>1) {
152 subs = graph.Shareds(PD);
153 for(subs.Start(); subs.More(); subs.Next()) {
154 Handle(StepBasic_ProductDefinitionContext) PDC =
155 Handle(StepBasic_ProductDefinitionContext)::DownCast(subs.Value());
156 if (PDC.IsNull()) continue;
157 const char *str2 = PDC->LifeCycleStage()->String().ToCString();
158 const char *str3 = PDC->Name()->String().ToCString();
159 if( !( strcasecmp(str1,str2)==0 || strcasecmp(str1,str3)==0 ) )
160 IsRoot=Standard_False;
161 }
162 }
163 }
164 // determinate roots used ProductDefinitionFormationRelationship
165 //subs = graph.Shareds(PD);
166 //for(subs.Start(); subs.More(); subs.Next()) {
167 // Handle(StepBasic_ProductDefinitionFormation) PDF =
168 // Handle(StepBasic_ProductDefinitionFormation)::DownCast(subs.Value());
169 // if (PDF.IsNull()) continue;
170 // Interface_EntityIterator subs1 = graph.Sharings(PDF);
171 // for(subs1.Start(); subs1.More(); subs1.Next()) {
172 // Handle(StepBasic_ProductDefinitionFormationRelationship) PDFR =
173 // Handle(StepBasic_ProductDefinitionFormationRelationship)::DownCast(subs1.Value());
174 // if (PDFR.IsNull()) continue;
175 // if (PDF==PDFR->RelatedProductDefinition()) IsRoot=Standard_False;
176 // }
177 //}
178 if (IsRoot) {
179 theroots.Append(ent);
180 WS()->MapReader()->RootsForTransfer()->Append(ent);
181 }
182 }
183 TCollection_AsciiString aProdMode = Interface_Static::CVal("read.step.product.mode");
184 if(!aProdMode.IsEqual("ON")) {
185 if(ent->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
186 Standard_Boolean IsRoot = Standard_True;
187 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
188 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(ent);
189 Handle(StepRepr_PropertyDefinition) PropDef = SDR->Definition().PropertyDefinition();
190 if(!PropDef.IsNull()) {
191 Handle(StepBasic_ProductDefinition) PD = PropDef->Definition().ProductDefinition();
192 if(!PD.IsNull()) IsRoot = Standard_False;
193 if(IsRoot) {
194 Handle(StepRepr_ShapeAspect) SA = PropDef->Definition().ShapeAspect();
195 if(!SA.IsNull()) {
196 Handle(StepRepr_ProductDefinitionShape) PDS = SA->OfShape();
197 PD = PDS->Definition().ProductDefinition();
198 if(!PD.IsNull()) IsRoot = Standard_False;
199 }
200 }
201 if(IsRoot) {
202 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
203 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(PropDef->Definition().ProductDefinitionRelationship());
204 if(!NAUO.IsNull()) IsRoot = Standard_False;
205 }
206 if(IsRoot) {
207 Handle(StepShape_ShapeRepresentation) SR =
208 Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
209 if(SR.IsNull()) IsRoot = Standard_False;
210 }
211 }
212 if(IsRoot) {
213 theroots.Append(ent);
214 WS()->MapReader()->RootsForTransfer()->Append(ent);
215 }
216 }
217 if(ent->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) {
218 Standard_Boolean IsRoot = Standard_True;
219 Handle(StepShape_ShapeRepresentation) SR =
220 Handle(StepShape_ShapeRepresentation)::DownCast(ent);
221 const Interface_Graph& graph = WS()->Graph();
222 Interface_EntityIterator subs = graph.Sharings(SR);
223 for(subs.Start(); subs.More() && IsRoot; subs.Next()) {
224 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
225 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
226 if(!SDR.IsNull()) IsRoot = Standard_False;
227 if(IsRoot) {
228 Handle(StepRepr_RepresentationRelationship) RR =
229 Handle(StepRepr_RepresentationRelationship)::DownCast(subs.Value());
230 if(!RR.IsNull()) {
231 Handle(StepShape_ShapeRepresentation) SR2 =
232 Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1());
233 if(SR==SR2)
234 SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2());
235 Interface_EntityIterator subs2 = graph.Sharings(SR2);
236 for(subs2.Start(); subs2.More(); subs2.Next()) {
237 Handle(StepShape_ShapeDefinitionRepresentation) SDR2 =
238 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
239 if(!SDR2.IsNull()) IsRoot = Standard_False;
240 //else {
241 // if(SR==SRR->Rep2()) IsRoot = Standard_False;
242 //}
243 }
244 }
245 }
246 if(IsRoot) {
247 Handle(StepRepr_RepresentationMap) RM =
248 Handle(StepRepr_RepresentationMap)::DownCast(subs.Value());
249 if(!RM.IsNull()) {
250 Interface_EntityIterator subs2 = graph.Sharings(RM);
251 for(subs2.Start(); subs2.More(); subs2.Next()) {
252 Handle(StepRepr_MappedItem) MI = Handle(StepRepr_MappedItem)::DownCast(subs2.Value());
253 if(!MI.IsNull()) {
254 Interface_EntityIterator subs3 = graph.Sharings(MI);
255 for(subs3.Start(); subs3.More(); subs3.Next()) {
256 Handle(StepShape_ShapeRepresentation) SR2 =
257 Handle(StepShape_ShapeRepresentation)::DownCast(subs3.Value());
258 if(!SR2.IsNull()) IsRoot = Standard_False;
259 }
260 }
261 }
262 }
263 }
264 }
265 if(IsRoot) {
266 theroots.Append(ent);
267 WS()->MapReader()->RootsForTransfer()->Append(ent);
268 }
269 }
270 }
271
272 }
273
274
275 return theroots.Length();
276}
277