0029873: Data Exchange - STEPCAFControl_Reader::Transfer() returns TRUE even when...
[occt.git] / src / STEPConstruct / STEPConstruct_ExternRefs.cxx
CommitLineData
b311480e 1// Created on: 2000-09-29
2// Created by: Andrey BETENEV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
17#include <Interface_EntityIterator.hxx>
42cf5bc1 18#include <StepAP203_ApprovedItem.hxx>
19#include <StepAP203_CcDesignApproval.hxx>
20#include <StepAP203_CcDesignDateAndTimeAssignment.hxx>
21#include <StepAP203_CcDesignPersonAndOrganizationAssignment.hxx>
22#include <StepAP203_DateTimeItem.hxx>
23#include <StepAP203_HArray1OfApprovedItem.hxx>
24#include <StepAP203_HArray1OfDateTimeItem.hxx>
25#include <StepAP203_HArray1OfPersonOrganizationItem.hxx>
26#include <StepAP203_PersonOrganizationItem.hxx>
7fd59977 27#include <StepAP214_AppliedDocumentReference.hxx>
28#include <StepAP214_AppliedExternalIdentificationAssignment.hxx>
29#include <StepAP214_ExternalIdentificationItem.hxx>
7fd59977 30#include <StepAP214_HArray1OfDocumentReferenceItem.hxx>
42cf5bc1 31#include <StepAP214_HArray1OfExternalIdentificationItem.hxx>
7fd59977 32#include <StepBasic_ApplicationContext.hxx>
42cf5bc1 33#include <StepBasic_ApplicationProtocolDefinition.hxx>
34#include <StepBasic_Document.hxx>
35#include <StepBasic_DocumentFile.hxx>
7fd59977 36#include <StepBasic_DocumentProductEquivalence.hxx>
42cf5bc1 37#include <StepBasic_DocumentRepresentationType.hxx>
7fd59977 38#include <StepBasic_DocumentType.hxx>
42cf5bc1 39#include <StepBasic_ExternalSource.hxx>
40#include <StepBasic_HArray1OfDocument.hxx>
7fd59977 41#include <StepBasic_HArray1OfProduct.hxx>
42cf5bc1 42#include <StepBasic_HArray1OfProductContext.hxx>
43#include <StepBasic_IdentificationRole.hxx>
44#include <StepBasic_ObjectRole.hxx>
45#include <StepBasic_Product.hxx>
46#include <StepBasic_ProductContext.hxx>
47#include <StepBasic_ProductDefinition.hxx>
48#include <StepBasic_ProductDefinitionContext.hxx>
49#include <StepBasic_ProductDefinitionFormation.hxx>
50#include <StepBasic_ProductDefinitionWithAssociatedDocuments.hxx>
7fd59977 51#include <StepBasic_ProductOrFormationOrDefinition.hxx>
52#include <StepBasic_ProductRelatedProductCategory.hxx>
42cf5bc1 53#include <StepBasic_RoleAssociation.hxx>
54#include <StepBasic_SourceItem.hxx>
55#include <STEPConstruct_ExternRefs.hxx>
56#include <StepData_SelectNamed.hxx>
57#include <StepRepr_CharacterizedDefinition.hxx>
58#include <StepRepr_DescriptiveRepresentationItem.hxx>
59#include <StepRepr_HArray1OfRepresentationItem.hxx>
60#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
61#include <StepRepr_ProductDefinitionShape.hxx>
62#include <StepRepr_PropertyDefinition.hxx>
63#include <StepRepr_PropertyDefinitionRepresentation.hxx>
64#include <StepRepr_RepresentationContext.hxx>
65#include <StepRepr_RepresentedDefinition.hxx>
66#include <StepShape_ShapeRepresentation.hxx>
67#include <TCollection_HAsciiString.hxx>
68#include <XSControl_WorkSession.hxx>
3b7f55e9 69#include <XSControl_TransferReader.hxx>
70#include <OSD_File.hxx>
71#include <OSD_Path.hxx>
7fd59977 72
73//=======================================================================
74//function : STEPConstruct_ExternRefs
75//purpose :
76//=======================================================================
7fd59977 77STEPConstruct_ExternRefs::STEPConstruct_ExternRefs ()
78{
79}
80
81//=======================================================================
82//function : STEPConstruct_ExternRefs
83//purpose :
84//=======================================================================
85
86STEPConstruct_ExternRefs::STEPConstruct_ExternRefs (const Handle(XSControl_WorkSession) &WS)
87 : STEPConstruct_Tool ( WS )
88{
89}
90
91//=======================================================================
92//function : Init
93//purpose :
94//=======================================================================
95
96Standard_Boolean STEPConstruct_ExternRefs::Init (const Handle(XSControl_WorkSession) &WS)
97{
98 Clear();
99 return SetWS ( WS );
100}
101
102//=======================================================================
103//function : Clear
104//purpose :
105//=======================================================================
106
107void STEPConstruct_ExternRefs::Clear ()
108{
109 myAEIAs.Clear();
110 myRoles.Clear();
111 myFormats.Clear();
112 myShapes.Clear();
113 myTypes.Clear();
114 myIsAP214.Clear();
115 // PTV 30.01.2003 TRJ11
116 myDocFiles.Clear();
117 mySharedPRPC.Nullify();
118 mySharedDocType.Nullify();
119 mySharedPDC.Nullify();
120 mySharedPC.Nullify();
121 myAPD.Nullify();
122}
123
124//=======================================================================
125//function : LoadExternRefs
126//purpose :
127//=======================================================================
128
129static Standard_Boolean findPDWADandExcludeExcess (Handle(StepAP214_AppliedDocumentReference)& ADR,
130 TColStd_SequenceOfTransient& aSeqOfPDWAD,
131 const Interface_Graph& Graph,
132 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments)& aPDWAD)
133{
134 // WARNING! do not add check for aSeqOfPDWAD.Length() and exit if it < 1,
135 // because this methods invokes with an empty sequence too to find PDWAD by ADR
136 Interface_EntityIterator subsADR = Graph.Shareds(ADR);
137 for ( subsADR.Start(); subsADR.More(); subsADR.Next() ) {
138 if ( !subsADR.Value()->IsKind (STANDARD_TYPE(StepBasic_Document)) )
139 continue;
140 Handle(StepBasic_Document) aDoc = Handle(StepBasic_Document)::DownCast(subsADR.Value());
141 // looking for Document Product Equivalence
142 Interface_EntityIterator subsD = Graph.Sharings(aDoc);
143 for ( subsD.Start(); subsD.More(); subsD.Next() ) {
144 if ( !subsD.Value()->IsKind (STANDARD_TYPE(StepBasic_DocumentProductEquivalence)) )
145 continue;
146 Handle(StepBasic_DocumentProductEquivalence) aDPE =
147 Handle(StepBasic_DocumentProductEquivalence)::DownCast(subsD.Value());
148 // take PDF and search the same PDF by PDWAD chain
149 Interface_EntityIterator subsDPE = Graph.Shareds(aDPE);
150 for ( subsDPE.Start(); subsDPE.More(); subsDPE.Next() ) {
151 if ( !subsDPE.Value()->IsKind (STANDARD_TYPE(StepBasic_ProductDefinitionFormation)) )
152 continue;
153 Handle(StepBasic_ProductDefinitionFormation) aPDF =
154 Handle(StepBasic_ProductDefinitionFormation)::DownCast(subsDPE.Value());
155 Interface_EntityIterator subs = Graph.Sharings(aPDF);
156 for ( subs.Start(); subs.More(); subs.Next() ) {
157 if ( !subs.Value()->IsKind (STANDARD_TYPE(StepBasic_ProductDefinitionWithAssociatedDocuments)) )
158 continue;
159 aPDWAD = Handle(StepBasic_ProductDefinitionWithAssociatedDocuments)::DownCast(subs.Value());
160 }
161 // now searching for PDWAD that refer to the same PDF
162 for (Standard_Integer pdwadi = 1; pdwadi <= aSeqOfPDWAD.Length(); pdwadi++) {
163 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) aCurPDWAD =
164 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments)::DownCast(aSeqOfPDWAD(pdwadi));
165 if ( !aCurPDWAD.IsNull() && aPDWAD == aCurPDWAD ) {
166 // found the same Product Definition Formation
167 aSeqOfPDWAD.Remove( pdwadi );
168 return Standard_True;
169 }
170 }
171 } // end of looking for PDF by ADR chain
172 } // end of looking for DPE
173 } // end iterations on Shareds(ADR)
174 return Standard_False;
175}
176
177
178Standard_Boolean STEPConstruct_ExternRefs::LoadExternRefs ()
179{
180 // iterate on entities in the model and find AEIAs
181 // or PDWADs (for AP203)
182 Handle(Interface_InterfaceModel) model = Model();
183 Handle(Standard_Type) tADR = STANDARD_TYPE(StepAP214_AppliedDocumentReference);
184 Handle(Standard_Type) tPDWAD = STANDARD_TYPE(StepBasic_ProductDefinitionWithAssociatedDocuments);
185 Standard_Integer nb = model->NbEntities();
186
187 // PTV 28.01.2003 CAX-IF TRJ11, file ext_ref_master.stp
188 // search all ADR and PDWAD and exclude excess PDWADs
189 TColStd_SequenceOfTransient aSeqOfADR, aSeqOfPDWAD;
190 for (Standard_Integer ient = 1; ient <= nb; ient ++) {
191 Handle(Standard_Transient) enti = model->Value(ient);
192 if ( enti->DynamicType() == tPDWAD )
193 aSeqOfPDWAD.Append( enti );
194 else if ( enti->DynamicType() == tADR )
195 aSeqOfADR.Append( enti );
196 }
197 Standard_Integer IsAP214 = 0;
198 // run on sequence aSeqOfADR of ADR and remove excess PDWAD from aSeqOfPDWAD
199 for (Standard_Integer adri = 1; adri <= aSeqOfADR.Length(); adri++) {
200 Handle(StepAP214_AppliedDocumentReference) ADR =
201 Handle(StepAP214_AppliedDocumentReference)::DownCast(aSeqOfADR.Value(adri));
202 // looking for Product Definition Formation and exlude excess PDWAD from aSeqOfPDWAD
203 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) aPDWAD;
204 findPDWADandExcludeExcess( ADR, aSeqOfPDWAD, Graph(), aPDWAD );
205
206 // now add all necessary information as original implementation.
207 IsAP214 = 1;
208 Handle(StepBasic_RoleAssociation) Role;
209 Handle(StepBasic_ProductDefinition) Shape;
210 Handle(StepRepr_PropertyDefinitionRepresentation) Format;
211 Handle(StepBasic_DocumentRepresentationType) Type;
212 // AppliedDocumentReference with RoleAssociation...
213 Interface_EntityIterator subs4 = Graph().Sharings(ADR);
214 for (subs4.Start(); subs4.More(); subs4.Next()) {
215 if ( subs4.Value()->IsKind ( STANDARD_TYPE(StepBasic_RoleAssociation) ) )
216 Role = Handle(StepBasic_RoleAssociation)::DownCast(subs4.Value());
217 }
218
219 subs4 = Graph().Shareds(ADR);
220 for (subs4.Start(); subs4.More(); subs4.Next()) {
221 if ( subs4.Value()->IsKind ( STANDARD_TYPE(StepBasic_ProductDefinition) ) )
222 Shape = Handle(StepBasic_ProductDefinition)::DownCast(subs4.Value());
223 }
224 // search for Document file
225 Handle(StepBasic_DocumentFile) DocFile;
226 if ( aPDWAD.IsNull() ) { // shoudnot be begin from TRJ11
7fd59977 227 // lookinf from ADR
228 subs4 = Graph().Shareds(ADR);
229 } else
230 // looking from PDWAD
231 subs4 = Graph().Shareds(aPDWAD);
232
233 for (subs4.Start(); subs4.More(); subs4.Next()) {
234 if ( !subs4.Value()->IsKind ( STANDARD_TYPE(StepBasic_DocumentFile) ) )
235 continue;
236 DocFile = Handle(StepBasic_DocumentFile)::DownCast(subs4.Value());
237 if ( DocFile.IsNull() )
238 continue;
239 // for each DocumentFile, find associated with it data:
240 Interface_EntityIterator subs = Graph().Sharings(DocFile);
241 for (subs.Start(); subs.More(); subs.Next()) {
242 Handle(Standard_Transient) sub = subs.Value();
243
244 // FORMAT - ???????
245 //
246 // PDRs of a shape and of a file format
247 if ( sub->IsKind ( STANDARD_TYPE(StepRepr_PropertyDefinition) ) ) {
248 Handle(StepRepr_PropertyDefinition) PD = Handle(StepRepr_PropertyDefinition)::DownCast(sub);
249 Interface_EntityIterator subs2 = Graph().Sharings(PD);
250 for (subs2.Start(); subs2.More(); subs2.Next()) {
251 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
252 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs2.Value());
253 if ( PDR.IsNull() ) continue;
254 if ( PDR->UsedRepresentation()->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation)) )
255 Format = PDR;
256 }
257 }
258 // DocumentRepresentationType
259 if ( sub->IsKind ( STANDARD_TYPE(StepBasic_DocumentRepresentationType) ) ) {
260 Type = Handle(StepBasic_DocumentRepresentationType)::DownCast(sub);
261 }
262 if ( !Type.IsNull() && !Format.IsNull() )
263 break;
264 }
265 if ( !Type.IsNull() && !Format.IsNull() )
266 break;
267 }
268 if ( DocFile.IsNull() )
269 continue;
270 myAEIAs.Append ( ADR );
271 myRoles.Append ( Role );
272 myFormats.Append ( Format );
273 myShapes.Append ( Shape );
274 myTypes.Append ( Type );
275 myIsAP214.Append ( IsAP214 );
276 myDocFiles.Append( DocFile );
277 } // end iterations on aSeqOfADR
278
279 // now iterates on sequence aSeqOfPDWAD of Product Definition With Associated Documents
280 for (Standard_Integer pdwadi = 1; pdwadi <= aSeqOfPDWAD.Length(); pdwadi++) {
281 IsAP214 = 0;
282 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) aPDWAD =
283 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments)::DownCast(aSeqOfPDWAD(pdwadi));
284 myShapes.Append(aPDWAD);
285 myIsAP214.Append ( IsAP214 );
286 Handle(StepAP214_AppliedExternalIdentificationAssignment) AEIA;
287 Handle(StepBasic_RoleAssociation) Role;
288 Handle(StepRepr_PropertyDefinitionRepresentation) Format;
289 Handle(StepBasic_DocumentRepresentationType) Type;
290 Handle(StepBasic_DocumentFile) DocFile;
291 myAEIAs.Append ( AEIA );
292 myRoles.Append ( Role );
293 myFormats.Append ( Format );
294 myTypes.Append ( Type );
295 myDocFiles.Append( DocFile );
296 }
297
298 return myShapes.Length() >0;
299}
300
301//=======================================================================
302//function : NbExternRefs
303//purpose :
304//=======================================================================
305
306Standard_Integer STEPConstruct_ExternRefs::NbExternRefs () const
307{
308 return myShapes.Length();
309}
310
311//=======================================================================
312//function : FileName
313//purpose :
314//=======================================================================
315
487bf1ce 316Standard_CString STEPConstruct_ExternRefs::FileName (const Standard_Integer num) const
7fd59977 317{
318 Handle(StepBasic_DocumentFile) DocFile;
319 Handle(StepAP214_AppliedExternalIdentificationAssignment) AEIA;
320 Standard_CString aCStringFileName = 0;
321 if ( myDocFiles.Length() >= num && !myDocFiles.Value(num).IsNull() )
322 DocFile = Handle(StepBasic_DocumentFile)::DownCast(myDocFiles.Value( num ));
323 else if (myIsAP214(num)==1)
324 {
325 Handle(StepAP214_AppliedDocumentReference) ADR =
326 Handle(StepAP214_AppliedDocumentReference)::DownCast ( myAEIAs(num) );
327
328 // PTV 28.01.2003 CAX-IF TRJ11, file ext_ref_master.stp
329 // serach document file name by long chain ADR->D<-DPE->PDF<-PDWAD->DF
330 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) aPDWAD;
331 // create an empty aSeqOfPDWAD
332 TColStd_SequenceOfTransient aSeqOfPDWAD;
333 // we do not need to exclude, just find PDWAD
334 findPDWADandExcludeExcess( ADR, aSeqOfPDWAD, Graph(), aPDWAD );
335
336 // search for Document file
337 Interface_EntityIterator subs4;
338 if ( aPDWAD.IsNull() ) { // shoudnot be begin from TRJ11
7fd59977 339 // lookinf from ADR
340 subs4 = Graph().Shareds(ADR);
341 } else
342 // looking from PDWAD
343 subs4 = Graph().Shareds(aPDWAD);
344 for (subs4.Start(); subs4.More(); subs4.Next()) {
345 if ( !subs4.Value()->IsKind ( STANDARD_TYPE(StepBasic_DocumentFile) ) )
346 continue;
347 DocFile = Handle(StepBasic_DocumentFile)::DownCast(subs4.Value());
348 if ( DocFile.IsNull() ) continue;
349 }
350 }
351 else {
352 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) aPDWAD =
353 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments)::DownCast(myShapes(num));
354 if ( aPDWAD.IsNull() || aPDWAD->DocIds().IsNull() )
355 return "";
356 Standard_Integer i;
357 for ( i=1; i <= aPDWAD->NbDocIds(); i++ ) {
358 Handle(StepBasic_Document) Doc = aPDWAD->DocIdsValue(i);
359 Handle(TCollection_HAsciiString) aFilename = Doc->Name();
360 if (!aFilename.IsNull() && !aFilename->IsEmpty()) return aFilename->ToCString();
361 }
362 return "";
363 }
364 // take name from AEIA and from DF
365 if(!DocFile.IsNull()) {
366 Interface_EntityIterator subs3 = Graph().Sharings(DocFile);
367 for (subs3.Start(); subs3.More(); subs3.Next()) {
368 if (subs3.Value()->IsKind(STANDARD_TYPE(StepAP214_AppliedExternalIdentificationAssignment))) {
369 AEIA = Handle(StepAP214_AppliedExternalIdentificationAssignment)::DownCast(subs3.Value());
370 if (!AEIA.IsNull())
371 break;
372 }
373 }
374 }
375 if(!AEIA.IsNull()) {
376 Handle(TCollection_HAsciiString) aFilename;
377 aFilename = AEIA->AssignedId();
378 if (!aFilename.IsNull() && !aFilename->IsEmpty()) {
379 aCStringFileName = aFilename->ToCString();
380 // ptv 29.01.2003 file trj4_xr1-tc-214.stp entity #71 have id "#71"
381 if ( aCStringFileName && aCStringFileName[0] == '#')
382 aCStringFileName = 0;
383 }
384 if ( ! aCStringFileName || ! aCStringFileName[0] ) {
385 // try to take name from external source
386 Handle(StepBasic_ExternalSource) theSource = AEIA->Source();
387 if (!theSource.IsNull()) {
388 StepBasic_SourceItem theSourceId = theSource->SourceId();
389 if (!theSourceId.IsNull()) {
390 Handle(StepData_SelectNamed) theFileName;
391 theFileName = Handle(StepData_SelectNamed)::DownCast (theSourceId.Value());
392 if (theFileName.IsNull() || theFileName->Kind()!=6 ) {
393 // nothing to do, hope could take name later.
394 }
395 else
396 aCStringFileName = theFileName->String();
397 }
398 }
399 }
400 }
3b7f55e9 401 Standard_CString oldFileName = 0;
402 // compute true path to the extern file
403 OSD_Path mainfile(WS()->LoadedFile());
404 mainfile.SetName("");
405 mainfile.SetExtension("");
406 TCollection_AsciiString dpath;
407 mainfile.SystemName(dpath);
408 if (aCStringFileName && aCStringFileName[0]) {
409 TCollection_AsciiString fullname = OSD_Path::AbsolutePath(dpath, aCStringFileName);
410 if (fullname.Length() <= 0) fullname = aCStringFileName;
411 if (!OSD_File(fullname).Exists()) {
412 oldFileName = aCStringFileName;
413 aCStringFileName = 0;
414 }
415 }
416 if (!aCStringFileName || !aCStringFileName[0]) {
417 // try to find name of the directory from DocFile
7fd59977 418 if ( !DocFile.IsNull() ) {
419 Handle(TCollection_HAsciiString) aFilename = DocFile->Id();
420 if (!aFilename.IsNull() && !aFilename->IsEmpty())
421 aCStringFileName = aFilename->ToCString();
422 if ( ! aCStringFileName || ! aCStringFileName[0] ) {
423 aFilename = DocFile->Name();
424 if (!aFilename.IsNull() && !aFilename->IsEmpty())
425 aCStringFileName = aFilename->ToCString();
426 }
427 if ( ! aCStringFileName || ! aCStringFileName[0] ) {
3b7f55e9 428 if (oldFileName) {
429 aCStringFileName = oldFileName;
430 }
431 else {
432 return "";
433 }
7fd59977 434 }
3b7f55e9 435 }
436 }
437 TCollection_AsciiString fullname = OSD_Path::AbsolutePath(dpath, aCStringFileName);
438 if (fullname.Length() <= 0) fullname = aCStringFileName;
439 if (!OSD_File(fullname).Exists()) {
440 if (oldFileName) {
441 aCStringFileName = oldFileName;
442 }
443 Handle(Transfer_TransientProcess) aTP = WS()->TransferReader()->TransientProcess();
444 TCollection_AsciiString aMess("Can not read external file ");
445 aMess.AssignCat(aCStringFileName);
446 aTP->AddFail(DocFile, aMess.ToCString());
447 }
448 else {
449 if (oldFileName && strcmp(oldFileName, aCStringFileName) != 0) {
450 Handle(Transfer_TransientProcess) aTP = WS()->TransferReader()->TransientProcess();
451 TCollection_AsciiString aMess("External file with name from entity AEIA (");
452 aMess.AssignCat(oldFileName);
453 aMess.AssignCat(") not existed => use file name from DocumentFile entity - ");
454 aMess.AssignCat(aCStringFileName);
455 aTP->AddWarning(DocFile, aMess.ToCString());
7fd59977 456 }
457 }
458 return aCStringFileName;
459}
460
461//=======================================================================
462//function : ProdDef
463//purpose :
464//=======================================================================
465
466Handle(StepBasic_ProductDefinition) STEPConstruct_ExternRefs::ProdDef (const Standard_Integer num) const
467{
468 return Handle(StepBasic_ProductDefinition)::DownCast( myShapes(num) );
469}
470
471//=======================================================================
472//function : Format
473//purpose :
474//=======================================================================
475
476Handle(TCollection_HAsciiString) STEPConstruct_ExternRefs::Format (const Standard_Integer num) const
477{
478 Handle(TCollection_HAsciiString) Format;
479
480 if (myIsAP214(num)==0) return Format;
481
482 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
483 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast ( myFormats(num) );
484 if (PDR.IsNull()) return Format;
485
486 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
487 for ( Standard_Integer i=1; i <= rep->NbItems(); i++ ) {
488 if ( rep->ItemsValue(i)->IsKind ( STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem) ) ) {
489 Handle(StepRepr_DescriptiveRepresentationItem) DRI =
490 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast ( rep->ItemsValue(i) );
491 Format = DRI->Description();
492 break;
493 }
494 }
495
496 return Format;
497}
498
499//=======================================================================
500//function : AddExternRef
501//purpose :
502//=======================================================================
503
504Standard_Integer STEPConstruct_ExternRefs::AddExternRef (const Standard_CString filename,
505 const Handle(StepBasic_ProductDefinition) &PD,
506 const Standard_CString format)
507{
508 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
509 Handle(TCollection_HAsciiString) fmt = new TCollection_HAsciiString(format);
510 Handle(TCollection_HAsciiString) tmp = new TCollection_HAsciiString("203");
511 Standard_Integer np = fmt->Location(tmp,1,fmt->Length());
512
513// if( !(fmt==tmp) ) {
514 if( !(np>0) ) {
515
516 // create core entity DocumentFile
517 Handle(StepBasic_DocumentType) DT = new StepBasic_DocumentType;
518 DT->Init(EmptyString);
519 Handle(TCollection_HAsciiString) DFid = new TCollection_HAsciiString(filename);
520 // PTV 30.01.2003 TRJ11 - copy external filename as is
521// DFid->AssignCat ( " file id" );
522 Handle(StepBasic_DocumentFile) DF = new StepBasic_DocumentFile;
523 DF->Init(DFid, EmptyString, Standard_False, EmptyString, DT, EmptyString, Standard_False, EmptyString);
524
525 // create AppliedExternalIdentificationAssignment et al
526 Handle(StepBasic_IdentificationRole) IR = new StepBasic_IdentificationRole;
527 // PTV 30.01.2003 TRJ11
528 // - set the ("external document id and location", $) without unmeaning description
529 Handle(TCollection_HAsciiString) aName =
530 new TCollection_HAsciiString("external document id and location");
531 IR->SetName( aName );
532// Handle(TCollection_HAsciiString) aIRdescr = new TCollection_HAsciiString("source system");
533// IR->Init(aName, Standard_True, aIRdescr);
534
535 Handle(StepData_SelectNamed) SDS = new StepData_SelectNamed;
536 SDS->SetString ( filename );
537 SDS->SetName("IDENTIFIER");
538 StepBasic_SourceItem SID;
539 SID.SetValue(SDS);
540 Handle(StepBasic_ExternalSource) ES = new StepBasic_ExternalSource;
541 ES->Init(SID);
542
543 StepAP214_ExternalIdentificationItem Item;
544 Item.SetValue(DF);
545 Handle(StepAP214_HArray1OfExternalIdentificationItem) Items =
546 new StepAP214_HArray1OfExternalIdentificationItem(1,1);
547 Items->SetValue(1, Item);
548
549 Handle(StepAP214_AppliedExternalIdentificationAssignment) ExtIdent =
550 new StepAP214_AppliedExternalIdentificationAssignment;
551// ExtIdent->Init(EmptyString, IR, ES, Items);
552 // PTV 30.01.2003 TRJ11 - store filename in AEIA
553 Handle(TCollection_HAsciiString) aFName = new TCollection_HAsciiString(filename);
554 ExtIdent->Init(aFName, IR, ES, Items);
555 // create DocumentRepresentationType
556 Handle(TCollection_HAsciiString) Dig = new TCollection_HAsciiString("digital");
557 Handle(StepBasic_DocumentRepresentationType) Type = new StepBasic_DocumentRepresentationType;
558 Type->Init(Dig, DF);
559
560 // create AppliedDocumentReference,
561 Handle(StepAP214_AppliedDocumentReference) ADR = new StepAP214_AppliedDocumentReference;
562 // PTV 30.01.2003 TRJ11 - create additional entities for AP214
563 addAP214ExterRef( ADR, PD, DF, filename );
564
565 // create RoleAssociation etc.
566 Handle(StepBasic_ObjectRole) OR = new StepBasic_ObjectRole;
567 Handle(TCollection_HAsciiString) mandatory = new TCollection_HAsciiString("mandatory");
568 OR->Init(mandatory, Standard_False, EmptyString);
569 StepBasic_RoleSelect RS;
570 RS.SetValue(ADR);
571 Handle(StepBasic_RoleAssociation) Role = new StepBasic_RoleAssociation;
572 Role->Init(OR, RS);
573
574 // create PDR for association with SR
575 StepRepr_CharacterizedDefinition CD;
576 CD.SetValue(DF);
577 Handle(TCollection_HAsciiString) PDname = new TCollection_HAsciiString("external definition");
578 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
579 PropD->Init(PDname, Standard_True, EmptyString, CD);
580 StepRepr_RepresentedDefinition RD;
581 RD.SetValue(PropD);
582// Handle(StepRepr_PropertyDefinitionRepresentation) PDRshape = new StepRepr_PropertyDefinitionRepresentation;
583// PDRshape->Init ( RD, SDR->UsedRepresentation() );
584
585 // create PDR for definition of document format (if defined)
586 Handle(StepRepr_PropertyDefinitionRepresentation) PDRformat;
587 if ( format && format[0] ) {
588
589 Handle(TCollection_HAsciiString) RCftype = new TCollection_HAsciiString ( "document parameters" );
590 Handle(StepRepr_RepresentationContext) RCf = new StepRepr_RepresentationContext;
591 RCf->Init ( EmptyString, RCftype );
592
593 Handle(TCollection_HAsciiString) DRIname = new TCollection_HAsciiString ( "data format" );
594 Handle(TCollection_HAsciiString) DRIdscr = new TCollection_HAsciiString ( format );
595 Handle(StepRepr_DescriptiveRepresentationItem) DRI = new StepRepr_DescriptiveRepresentationItem;
596 DRI->Init ( DRIname, DRIdscr );
597 Handle(StepRepr_HArray1OfRepresentationItem) fItems = new StepRepr_HArray1OfRepresentationItem(1,1);
598 fItems->SetValue ( 1, DRI );
599
600 Handle(TCollection_HAsciiString) SRfname = new TCollection_HAsciiString ( "document format" );
601 Handle(StepRepr_Representation) SRformat = new StepRepr_Representation;
602 SRformat->Init(SRfname, fItems, RCf);
603
604 StepRepr_CharacterizedDefinition CDf;
605 CDf.SetValue(DF);
606 Handle(TCollection_HAsciiString) PDfname = new TCollection_HAsciiString("document property");
607 Handle(StepRepr_PropertyDefinition) PDf = new StepRepr_PropertyDefinition;
608 PDf->Init(PDfname, Standard_True, EmptyString, CDf);
609 StepRepr_RepresentedDefinition RDf;
610 RDf.SetValue(PDf);
611
612 PDRformat = new StepRepr_PropertyDefinitionRepresentation;
613 PDRformat->Init ( RDf, SRformat );
614 }
615
616 // add all the created root entities to sequences
617 myAEIAs.Append ( ExtIdent ); //StepAP214_AppliedExternalIdentificationAssignment
618 myRoles.Append ( Role ); //StepBasic_RoleAssociation
619 myFormats.Append ( PDRformat ); //StepRepr_PropertyDefinitionRepresentation
620// myShapes.Append ( PDRshape ); //StepRepr_PropertyDefinitionRepresentation
621 myShapes.Append ( PD ); //StepBasic_ProductDefinition
622 myTypes.Append ( Type ); //StepBasic_DocumentRepresentationType
623
624 }
625
626 else { // format=="AP203"
627
628// StepRepr_RepresentedDefinition aRD = SDR->Definition();
629// Handle(StepRepr_PropertyDefinition) aPD = aRD.PropertyDefinition();
630// StepRepr_CharacterizedDefinition aCD = aPD->Definition();
631// Handle(StepBasic_ProductDefinition) aProdDef = aCD.ProductDefinition();
632 Handle(StepBasic_ProductDefinitionFormation) ProdDefForm = PD->Formation();
633 Handle(StepBasic_ProductDefinitionContext) ProdDefCont = PD->FrameOfReference();
634
635 // create document
636 Handle(TCollection_HAsciiString) fname = new TCollection_HAsciiString(filename);
637 Handle(StepBasic_DocumentType) aDocType = new StepBasic_DocumentType;
638 Handle(TCollection_HAsciiString) aDT = new TCollection_HAsciiString("cad_filename");
639 aDocType->Init(aDT);
640 Handle(StepBasic_Document) aDoc = new StepBasic_Document;
641 Handle(TCollection_HAsciiString) aDescription =
642 new TCollection_HAsciiString("CAD Model associated to the part");
643 aDoc->Init(EmptyString,fname,Standard_True,aDescription,aDocType);
644 Handle(StepBasic_HArray1OfDocument) aDocIds = new StepBasic_HArray1OfDocument(1,1);
645 aDocIds->SetValue(1,aDoc);
646
647 // create ProductDefinitionWithAssociatedDocuments
648 aDescription = PD->Description();
649 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) PDWAD =
650 new StepBasic_ProductDefinitionWithAssociatedDocuments;
651 PDWAD->Init(EmptyString,aDescription,ProdDefForm,ProdDefCont,aDocIds);
652 //Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) PDWAD =
653 // Handle(StepBasic_ProductDefinitionWithAssociatedDocuments)::DownCast(PD);
654
655 // searh in graph for replace
656// Standard_Integer numProdDef;
657// Interface_EntityIterator subs = Graph().Shareds(SDR);
658// for (subs.Start(); subs.More(); subs.Next()) {
659// Handle(Standard_Transient) sub = subs.Value();
660 Interface_EntityIterator subs = Graph().Sharings(PD);
661 for (subs.Start(); subs.More(); subs.Next()) {
662 Handle(Standard_Transient) sub = subs.Value();
663 if (!sub->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) continue;
664 Handle(StepRepr_ProductDefinitionShape) ProdDefSh =
665 Handle(StepRepr_ProductDefinitionShape)::DownCast ( sub );
666 if(ProdDefSh.IsNull()) continue;
667 StepRepr_CharacterizedDefinition CDf;
668 CDf.SetValue(PDWAD);
669 ProdDefSh->SetDefinition(CDf);
670 }
671
672// Interface_EntityIterator subs1 = Graph().Shareds(ProdDefSh);
673// for (subs1.Start(); subs1.More(); subs1.Next()) {
674
675// Handle(Standard_Transient) sub1 = subs1.Value();
676// if (!sub1->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) continue;
677// Handle(StepBasic_ProductDefinition) ProdDef =
678// Handle(StepBasic_ProductDefinition)::DownCast ( sub1 );
679// numProdDef = Model()->Number(ProdDef);
680 Standard_Integer numProdDef = Model()->Number(PD);
681
682// Interface_EntityIterator subs2 = Graph().Sharings(ProdDef);
683 Interface_EntityIterator subs2 = Graph().Sharings(PD);
684 for (subs2.Start(); subs2.More(); subs2.Next()) {
685 Handle(Standard_Transient) sub2 = subs2.Value();
686
687 if (sub2->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence))) {
688 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
689 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast ( sub2 );
690 NAUO->SetRelatedProductDefinition(PDWAD);
691 }
692
693 if (sub2->IsKind(STANDARD_TYPE(StepAP203_CcDesignPersonAndOrganizationAssignment))) {
694 Handle(StepAP203_CcDesignPersonAndOrganizationAssignment) CDPAOA =
695 Handle(StepAP203_CcDesignPersonAndOrganizationAssignment)::DownCast ( sub2 );
696 Handle(StepAP203_HArray1OfPersonOrganizationItem) HAPOI = CDPAOA->Items();
697 for(Standard_Integer i=1; i<=HAPOI->Length(); i++) {
698 StepAP203_PersonOrganizationItem POI = HAPOI->Value(i);
699 Handle(StepBasic_ProductDefinition) PDtmp = POI.ProductDefinition();
700 Standard_Integer numPDtmp = Model()->Number(PDtmp);
701 if(numProdDef==numPDtmp) {
702 POI.SetValue(PDWAD);
703 HAPOI->SetValue(i,POI);
704 }
705 }
706 }
707
708 if (sub2->IsKind(STANDARD_TYPE(StepAP203_CcDesignDateAndTimeAssignment))) {
709 Handle(StepAP203_CcDesignDateAndTimeAssignment) CDDATA =
710 Handle(StepAP203_CcDesignDateAndTimeAssignment)::DownCast ( sub2 );
711 Handle(StepAP203_HArray1OfDateTimeItem) HADTI = CDDATA->Items();
712 for(Standard_Integer i=1; i<=HADTI->Length(); i++) {
713 StepAP203_DateTimeItem DTI = HADTI->Value(i);
714 Handle(StepBasic_ProductDefinition) PDtmp = DTI.ProductDefinition();
715 Standard_Integer numPDtmp = Model()->Number(PDtmp);
716 if(numProdDef==numPDtmp) {
717 DTI.SetValue(PDWAD);
718 HADTI->SetValue(i,DTI);
719 }
720 }
721 }
722
723 if (sub2->IsKind(STANDARD_TYPE(StepAP203_CcDesignApproval))) {
724 Handle(StepAP203_CcDesignApproval) CDA =
725 Handle(StepAP203_CcDesignApproval)::DownCast ( sub2 );
726 Handle(StepAP203_HArray1OfApprovedItem) HAAI = CDA->Items();
727 for(Standard_Integer i=1; i<=HAAI->Length(); i++) {
728 StepAP203_ApprovedItem AI = HAAI->Value(i);
729 Handle(StepBasic_ProductDefinition) PDtmp = AI.ProductDefinition();
730 Standard_Integer numPDtmp = Model()->Number(PDtmp);
731 if(numProdDef==numPDtmp) {
732 AI.SetValue(PDWAD);
733 HAAI->SetValue(i,AI);
734 }
735 }
736 }
737 }
738// }
739//
740// StepRepr_CharacterizedDefinition ChartDef;
741// ChartDef.SetValue(PDWAD);
742// ProdDefSh->SetDefinition(ChartDef);
743// }
744
745 myAEIAs.Append ( PDWAD );
746 myReplaceNum.Append(numProdDef);
747 myRoles.Append ( aDoc );
748 myTypes.Append ( aDocType );
749
750 }
751
752 return myAEIAs.Length();
753
754}
755
756//=======================================================================
757//function : WriteExternRefs
758//purpose :
759//=======================================================================
760
761Standard_Integer STEPConstruct_ExternRefs::WriteExternRefs (const Standard_Integer num) const
762{
763 if(num==3) {
764 for ( Standard_Integer i=1; i <= myAEIAs.Length(); i++ ) {
765 Model()->ReplaceEntity(myReplaceNum(i),myAEIAs(i));
766 if ( ! myRoles(i).IsNull() )
767 Model()->AddWithRefs ( myRoles(i) );
768 if ( ! myTypes(i).IsNull() )
769 Model()->AddWithRefs ( myTypes(i) );
770 }
771 }
772 else {
773 for ( Standard_Integer i=1; i <= myAEIAs.Length(); i++ ) {
774 Model()->AddWithRefs ( myAEIAs(i) );
775 if ( ! myRoles(i).IsNull() )
776 Model()->AddWithRefs ( myRoles(i) );
777 if ( ! myFormats(i).IsNull() )
778 Model()->AddWithRefs ( myFormats(i) );
779 if ( ! myShapes(i).IsNull() )
780 Model()->AddWithRefs ( myShapes(i) );
781 if ( ! myTypes(i).IsNull() )
782 Model()->AddWithRefs ( myTypes(i) );
783 }
784 }
785 // PTV 30.01.2003 TRJ11
786 if ( !myAPD.IsNull() )
787 Model()->AddWithRefs( myAPD );
788 if ( !mySharedPRPC.IsNull() )
789 Model()->AddWithRefs( mySharedPRPC );
790
791 return myAEIAs.Length();
792}
793
794//=======================================================================
795//function : addAP214ExterRef
796//purpose : PTV 30.01.2003 TRJ11
797//=======================================================================
798
799Standard_Boolean STEPConstruct_ExternRefs::addAP214ExterRef (const Handle(StepAP214_AppliedDocumentReference)& ADR,
800 const Handle(StepBasic_ProductDefinition)& PD,
801 const Handle(StepBasic_DocumentFile)& DF,
802 const Standard_CString filename )
803{
804 Handle(StepAP214_HArray1OfDocumentReferenceItem) DRIs = new StepAP214_HArray1OfDocumentReferenceItem(1,1);
805 StepAP214_DocumentReferenceItem aDRI;
806 aDRI.SetValue(PD);
807 DRIs->SetValue(1, aDRI);
808 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
809
810 // create/get created shared entities:
811 // DocumentType, ProductDefinitionContext, ProductRelatedProductCategory, ProductContext
812 checkAP214Shared();
813
814 // create document
815 Handle(StepBasic_Document) aDocument = new StepBasic_Document;
816 aDocument->Init( EmptyString, EmptyString, Standard_False, EmptyString, mySharedDocType );
817 ADR->Init(aDocument, EmptyString, DRIs);
818
819 // create new product
820 Handle(StepBasic_Product) Product = new StepBasic_Product;
821 Handle(StepBasic_HArray1OfProduct) HProducts = mySharedPRPC->Products();
822 Standard_Integer nbProducts = 0;
823 if (!HProducts.IsNull())
824 nbProducts = HProducts->Length();
825 Standard_Integer intProdId = 20001 + nbProducts;
826 Handle(TCollection_HAsciiString) ProductID = new TCollection_HAsciiString( intProdId );
827 Handle(TCollection_HAsciiString) ProductName = new TCollection_HAsciiString(filename);
828 ProductName->AssignCat( "-Doc" );
829 Handle(StepBasic_HArray1OfProductContext) aHProdContext = new StepBasic_HArray1OfProductContext(1, 1);
830 aHProdContext->SetValue( 1, mySharedPC );
831 Product->Init( ProductID, ProductName, EmptyString, aHProdContext );
832
833 // create new product definition formation
834 Handle(StepBasic_ProductDefinitionFormation) PDF = new StepBasic_ProductDefinitionFormation;
835 // name id taked from exapmle Standard_ExtString_ref_master.stp
836 Handle(TCollection_HAsciiString) PDF_ID = new TCollection_HAsciiString("1");
837 PDF->Init( PDF_ID, EmptyString, Product );
838
839 Handle(StepBasic_DocumentProductEquivalence) DPE = new StepBasic_DocumentProductEquivalence;
840 Handle(TCollection_HAsciiString) DPEname = new TCollection_HAsciiString("equivalence");
841 StepBasic_ProductOrFormationOrDefinition aPOFOD;
842 aPOFOD.SetValue( PDF );
843 DPE->Init( DPEname, Standard_False, EmptyString, aDocument, aPOFOD );
844 // add to the model with references
845 Model()->AddWithRefs( DPE );
846
847 // add products to shared PRPC
848 Handle(StepBasic_HArray1OfProduct) newHProducts = new StepBasic_HArray1OfProduct(1, nbProducts + 1);
849 for (Standard_Integer pi = 1; pi <= nbProducts; pi++)
850 newHProducts->SetValue( pi, HProducts->Value( pi ) );
851 newHProducts->SetValue( nbProducts + 1, Product );
852 // set the hArray to the PRPC
853 mySharedPRPC->SetProducts( newHProducts );
854
855 // create new PDWAD
856 Handle(StepBasic_ProductDefinitionWithAssociatedDocuments) PDWAD =
857 new StepBasic_ProductDefinitionWithAssociatedDocuments;
858 Handle(StepBasic_HArray1OfDocument) aDocIds = new StepBasic_HArray1OfDocument(1,1);
859 aDocIds->SetValue( 1, DF );
860 Handle(TCollection_HAsciiString) PDWAD_ID = new TCollection_HAsciiString("1");
861 PDWAD->Init( PDWAD_ID, EmptyString, PDF, mySharedPDC, aDocIds );
862 // add to the model with references
863 Model()->AddWithRefs( PDWAD );
864
865 return Standard_True;
866}
867
868//=======================================================================
869//function : SetAP214APD
870//purpose :
871//=======================================================================
872
873void STEPConstruct_ExternRefs::SetAP214APD (const Handle(StepBasic_ApplicationProtocolDefinition)& APD)
874{
875 myAPD = APD;
876}
877
878//=======================================================================
879//function : GetAP214APD
880//purpose :
881//=======================================================================
882
883Handle(StepBasic_ApplicationProtocolDefinition) STEPConstruct_ExternRefs::GetAP214APD()
884{
885 if (myAPD.IsNull()) {
886 // create new APD with new Application Context
887 myAPD = new StepBasic_ApplicationProtocolDefinition;
888 // examples of the values taken from ext_ref_master.stp
889 Handle(TCollection_HAsciiString) status =
890 new TCollection_HAsciiString("version 1.1");
891 Handle(TCollection_HAsciiString) appSchemaName =
892 new TCollection_HAsciiString("pdm_schema");
893 Standard_Integer intProtocolYear = 1999;
894 Handle(StepBasic_ApplicationContext) aApplication = new StepBasic_ApplicationContext;
895 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
896 aApplication->Init( EmptyString );
897 myAPD->Init( status, appSchemaName, intProtocolYear, aApplication );
898 }
899 return myAPD;
900}
901
902void STEPConstruct_ExternRefs::checkAP214Shared ()
903{
904 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
905 if ( mySharedPRPC.IsNull() ) {
906 // create new ProductRelatedProductCategory for all extern files.
907 Handle(TCollection_HAsciiString) PRPCname = new TCollection_HAsciiString("document");
908 mySharedPRPC = new StepBasic_ProductRelatedProductCategory;
18f7c9a5 909 mySharedPRPC->Init( PRPCname, Standard_False, EmptyString, 0 );
7fd59977 910 }
911 if ( mySharedDocType.IsNull() ) {
912 // create new shared Document Type
913 mySharedDocType = new StepBasic_DocumentType;
914 Handle(TCollection_HAsciiString) prod_dat_type =
915 new TCollection_HAsciiString("configuration controlled document version");
916 mySharedDocType->Init( prod_dat_type );
917 }
918 if ( mySharedPDC.IsNull() ) {
919 // create new shared Product Definition Context
920 mySharedPDC = new StepBasic_ProductDefinitionContext;
921 Handle(TCollection_HAsciiString) aPDCname =
922 new TCollection_HAsciiString("digital document definition");
923 Handle(StepBasic_ApplicationContext) anAppContext = GetAP214APD()->Application();
924 mySharedPDC->Init( aPDCname, anAppContext, EmptyString );
925 }
926 if ( mySharedPC.IsNull() ) {
927 // create new shared ProductContext
928 mySharedPC = new StepBasic_ProductContext;
929 Handle(StepBasic_ApplicationContext) anAppContext = GetAP214APD()->Application();
930 mySharedPC->Init( EmptyString, anAppContext, EmptyString );
931 }
932
933}