1 // File: STEPCAFControl_Writer.cxx
2 // Created: Tue Aug 15 17:35:36 2000
3 // Author: Andrey BETENEV
4 // <abv@doomox.nnov.matra-dtv.fr>
6 // CURRENT LIMITATIONS:
8 // when val props and names assigned to instance of
9 // component in assembly, it is in fact supposed that only one CDSR corresponds
10 // to such shape. This can be wrong and should be handled more carefully
11 // (analysis of SDRs which the CDSR links should be done)
13 // Names and validation props are supported for top-level shapes only
15 #include <STEPCAFControl_Writer.ixx>
16 #include <STEPControl_StepModelType.hxx>
17 #include <XCAFDoc_ShapeTool.hxx>
18 #include <TDF_LabelSequence.hxx>
19 #include <TopoDS_Shape.hxx>
20 #include <XCAFPrs_DataMapOfShapeStyle.hxx>
21 #include <XCAFPrs.hxx>
22 #include <XCAFPrs_DataMapOfStyleShape.hxx>
23 #include <XCAFPrs_Style.hxx>
24 #include <XCAFPrs_DataMapIteratorOfDataMapOfStyleShape.hxx>
25 #include <TopTools_SequenceOfShape.hxx>
26 #include <TopoDS_Iterator.hxx>
27 #include <STEPConstruct_Styles.hxx>
28 #include <XCAFDoc_ColorTool.hxx>
29 #include <STEPConstruct.hxx>
30 #include <TopTools_MapOfShape.hxx>
31 #include <XSControl_TransferWriter.hxx>
32 #include <TDataStd_Name.hxx>
33 #include <StepShape_ShapeDefinitionRepresentation.hxx>
34 #include <TransferBRep_ShapeMapper.hxx>
35 #include <TransferBRep.hxx>
36 #include <StepRepr_PropertyDefinition.hxx>
37 #include <StepBasic_ProductDefinition.hxx>
38 #include <StepBasic_Product.hxx>
39 #include <TCollection_HAsciiString.hxx>
40 #include <TCollection_AsciiString.hxx>
41 #include <Transfer_FinderProcess.hxx>
42 #include <StepBasic_ProductDefinitionFormation.hxx>
43 #include <XCAFDoc_DocumentTool.hxx>
44 #include <TDF_Label.hxx>
45 #include <STEPCAFControl_Controller.hxx>
46 #include <STEPCAFControl_IteratorOfDictionaryOfExternFile.hxx>
47 #include <STEPConstruct_ExternRefs.hxx>
48 #include <Interface_Static.hxx>
49 #include <TopoDS_Compound.hxx>
50 #include <BRep_Builder.hxx>
51 #include <Transfer_ActorOfFinderProcess.hxx>
52 #include <STEPCAFControl_ActorWrite.hxx>
53 #include <STEPConstruct_ValidationProps.hxx>
54 #include <XCAFDoc_Area.hxx>
55 #include <XCAFDoc_Volume.hxx>
56 #include <XCAFDoc_Centroid.hxx>
57 #include <StepShape_ContextDependentShapeRepresentation.hxx>
58 #include <StepRepr_ProductDefinitionShape.hxx>
59 #include <StepBasic_ProductDefinitionRelationship.hxx>
60 #include <XCAFDoc_GraphNode.hxx>
61 #include <XCAFDoc_LayerTool.hxx>
62 #include <StepVisual_PresentationLayerAssignment.hxx>
63 #include <XCAFDoc.hxx>
64 #include <StepVisual_HArray1OfLayeredItem.hxx>
65 #include <TColStd_HSequenceOfTransient.hxx>
66 #include <TDF_Tool.hxx>
67 #include <Message_Messenger.hxx>
69 #include <Transfer_Binder.hxx>
70 #include <Transfer_TransientListBinder.hxx>
71 #include <StepVisual_InvisibleItem.hxx>
72 #include <TDataStd_UAttribute.hxx>
73 #include <StepVisual_Invisibility.hxx>
74 #include <StepVisual_HArray1OfInvisibleItem.hxx>
75 #include <HeaderSection_FileSchema.hxx>
76 #include <StepData_StepModel.hxx>
77 #include <StepAP214_Protocol.hxx>
78 #include <OSD_Path.hxx>
79 #include <XSControl_WorkSession.hxx>
80 #include <StepRepr_HArray1OfRepresentationItem.hxx>
81 #include <MoniTool_DataMapIteratorOfDataMapOfShapeTransient.hxx>
82 #include <StepRepr_Representation.hxx>
83 #include <StepVisual_MechanicalDesignGeometricPresentationRepresentation.hxx>
84 #include <Quantity_TypeOfColor.hxx>
85 #include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
86 #include <StepVisual_PresentationStyleAssignment.hxx>
87 #include <StepVisual_StyledItem.hxx>
88 #include <StepVisual_PresentationStyleByContext.hxx>
89 #include <StepVisual_HArray1OfPresentationStyleSelect.hxx>
90 #include <TDF_AttributeSequence.hxx>
91 #include <TColStd_MapOfTransient.hxx>
92 // #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
93 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
94 #include <Interface_EntityIterator.hxx>
95 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
97 // added by skl 15.01.2004 for D> writing
98 #include <XCAFDoc_DimTolTool.hxx>
99 #include <XCAFDoc_DimTol.hxx>
100 #include <XCAFDoc_Datum.hxx>
101 #include <STEPConstruct_DataMapOfAsciiStringTransient.hxx>
102 #include <STEPConstruct_DataMapOfPointTransient.hxx>
103 #include <StepBasic_MeasureValueMember.hxx>
104 #include <StepBasic_SiUnitAndLengthUnit.hxx>
105 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
106 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
107 #include <StepBasic_LengthMeasureWithUnit.hxx>
108 #include <StepShape_EdgeCurve.hxx>
109 #include <StepShape_AdvancedFace.hxx>
110 #include <StepShape_OrientedEdge.hxx>
111 #include <StepShape_EdgeLoop.hxx>
112 #include <StepShape_FaceBound.hxx>
113 #include <StepShape_ConnectedFaceSet.hxx>
114 #include <StepShape_ShapeRepresentation.hxx>
115 #include <StepShape_DimensionalSize.hxx>
116 #include <StepShape_ShapeDimensionRepresentation.hxx>
117 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
118 #include <StepRepr_ShapeAspect.hxx>
119 #include <StepRepr_ShapeAspectRelationship.hxx>
120 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
121 //#include <StepRepr_CompoundItemDefinition.hxx>
122 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
123 #include <StepRepr_ValueRange.hxx>
124 #include <StepData_Logical.hxx>
125 #include <StepDimTol_DatumFeature.hxx>
126 #include <StepDimTol_Datum.hxx>
127 #include <StepDimTol_DatumReference.hxx>
128 #include <StepDimTol_HArray1OfDatumReference.hxx>
129 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
130 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
131 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
132 #include <StepDimTol_AngularityTolerance.hxx>
133 #include <StepDimTol_CircularRunoutTolerance.hxx>
134 #include <StepDimTol_CoaxialityTolerance.hxx>
135 #include <StepDimTol_ConcentricityTolerance.hxx>
136 #include <StepDimTol_ParallelismTolerance.hxx>
137 #include <StepDimTol_PerpendicularityTolerance.hxx>
138 #include <StepDimTol_SymmetryTolerance.hxx>
139 #include <StepDimTol_TotalRunoutTolerance.hxx>
140 #include <StepDimTol_CylindricityTolerance.hxx>
141 #include <StepDimTol_FlatnessTolerance.hxx>
142 #include <StepDimTol_LineProfileTolerance.hxx>
143 #include <StepDimTol_PositionTolerance.hxx>
144 #include <StepDimTol_RoundnessTolerance.hxx>
145 #include <StepDimTol_StraightnessTolerance.hxx>
146 #include <StepDimTol_SurfaceProfileTolerance.hxx>
147 #include <TColStd_HArray1OfReal.hxx>
148 #include <TColStd_HArray1OfTransient.hxx>
150 // added by skl 12.02.2004 for writing materials
151 #include <XCAFDoc_MaterialTool.hxx>
152 #include <XCAFDoc_Material.hxx>
153 #include <TDataStd_TreeNode.hxx>
154 #include <StepRepr_DescriptiveRepresentationItem.hxx>
155 #include <StepBasic_SiUnitAndMassUnit.hxx>
156 #include <StepBasic_DerivedUnitElement.hxx>
157 #include <StepBasic_HArray1OfDerivedUnitElement.hxx>
158 #include <StepBasic_DerivedUnit.hxx>
159 #include <StepRepr_MeasureRepresentationItem.hxx>
162 //=======================================================================
163 //function : GetLabelName
164 //purpose : auxilary function: take name of label and append it to str
165 //=======================================================================
166 static Standard_Boolean GetLabelName (const TDF_Label &L, Handle(TCollection_HAsciiString) &str)
168 Handle(TDataStd_Name) N;
169 if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) return Standard_False;
170 TCollection_ExtendedString name = N->Get();
171 if ( name.Length() <=0 ) return Standard_False;
173 // set name, converting it to Ascii and removing spaces
174 TCollection_AsciiString buf ( name, '?' );
177 buf.ChangeAll(' ','_');
178 str->AssignCat ( buf.ToCString() );
179 return Standard_True;
183 //=======================================================================
184 //function : STEPCAFControl_Writer
186 //=======================================================================
188 STEPCAFControl_Writer::STEPCAFControl_Writer () :
189 myColorMode( Standard_True ),
190 myNameMode ( Standard_True ),
191 myLayerMode( Standard_True ),
192 myPropsMode( Standard_True ),
193 mySHUOMode ( Standard_True ),
194 myDGTMode ( Standard_True ),
195 myMatMode ( Standard_True )
197 STEPCAFControl_Controller::Init();
198 Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
203 //=======================================================================
204 //function : STEPCAFControl_Writer
206 //=======================================================================
208 STEPCAFControl_Writer::STEPCAFControl_Writer (const Handle(XSControl_WorkSession)& WS,
209 const Standard_Boolean scratch)
211 STEPCAFControl_Controller::Init();
212 Init ( WS, scratch );
213 myColorMode = Standard_True;
214 myNameMode = Standard_True;
215 myLayerMode = Standard_True;
216 myPropsMode = Standard_True;
217 mySHUOMode = Standard_True;
221 //=======================================================================
224 //=======================================================================
226 void STEPCAFControl_Writer::Init (const Handle(XSControl_WorkSession)& WS,
227 const Standard_Boolean scratch)
229 WS->SelectNorm ( "STEP" );
230 myWriter.SetWS (WS,scratch);
231 myFiles = new STEPCAFControl_DictionaryOfExternFile;
237 //=======================================================================
240 //=======================================================================
242 IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filename)
244 IFSelect_ReturnStatus status = myWriter.Write ( filename );
246 // get directory name of the main file
247 OSD_Path mainfile ( filename );
248 mainfile.SetName ( "" );
249 mainfile.SetExtension ( "" );
250 TCollection_AsciiString dpath;
251 mainfile.SystemName ( dpath );
253 STEPCAFControl_IteratorOfDictionaryOfExternFile it ( myFiles );
254 for ( ; it.More(); it.Next() ) {
255 Handle(STEPCAFControl_ExternFile) EF = it.Value();
256 if ( EF->GetWriteStatus() != IFSelect_RetVoid ) continue;
258 // construct extern file name
259 TCollection_AsciiString fname = OSD_Path::AbsolutePath ( dpath, EF->GetName()->String() );
260 if ( fname.Length() <= 0 ) fname = EF->GetName()->String();
262 cout << "Writing external file: " << fname.ToCString() << endl;
265 EF->SetWriteStatus ( EF->GetWS()->SendAll ( fname.ToCString() ) );
272 //=======================================================================
273 //function : Transfer
275 //=======================================================================
277 Standard_Boolean STEPCAFControl_Writer::Transfer (const Handle(TDocStd_Document) &doc,
278 const STEPControl_StepModelType mode,
279 const Standard_CString multi)
281 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
282 if ( STool.IsNull() ) return Standard_False;
284 TDF_LabelSequence labels;
285 STool->GetFreeShapes ( labels );
286 return Transfer ( myWriter, labels, mode, multi );
290 //=======================================================================
291 //function : Transfer
293 //=======================================================================
295 Standard_Boolean STEPCAFControl_Writer::Transfer (const TDF_Label &L,
296 const STEPControl_StepModelType mode,
297 const Standard_CString multi)
299 TDF_LabelSequence labels;
301 return Transfer ( myWriter, labels, mode, multi );
305 //=======================================================================
308 //=======================================================================
310 Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
311 const Standard_CString filename)
313 if ( ! Transfer ( doc ) ) return Standard_False;
314 return Write ( filename ) == IFSelect_RetDone;
318 //=======================================================================
321 //=======================================================================
323 Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
324 const TCollection_AsciiString &filename)
326 if ( ! Transfer ( doc ) ) return Standard_False;
327 return Write ( filename.ToCString() ) == IFSelect_RetDone;
331 //=======================================================================
332 //function : ExternFiles
334 //=======================================================================
336 const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Writer::ExternFiles () const
342 //=======================================================================
343 //function : ExternFile
345 //=======================================================================
347 Standard_Boolean STEPCAFControl_Writer::ExternFile (const TDF_Label &L,
348 Handle(STEPCAFControl_ExternFile) &ef) const
351 if ( ! myLabEF.IsBound ( L ) ) return Standard_False;
352 ef = myLabEF.Find ( L );
353 return Standard_True;
357 //=======================================================================
358 //function : ExternFile
360 //=======================================================================
362 Standard_Boolean STEPCAFControl_Writer::ExternFile (const Standard_CString name,
363 Handle(STEPCAFControl_ExternFile) &ef) const
366 if ( ! myFiles.IsNull() || ! myFiles->HasItem ( name ) )
367 return Standard_False;
368 ef = myFiles->Item ( name );
369 return Standard_True;
373 //=======================================================================
376 //=======================================================================
378 STEPControl_Writer &STEPCAFControl_Writer::ChangeWriter ()
384 //=======================================================================
387 //=======================================================================
389 const STEPControl_Writer &STEPCAFControl_Writer::Writer () const
395 //=======================================================================
396 //function : Transfer
398 //=======================================================================
400 Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
401 const TDF_LabelSequence &labels,
402 const STEPControl_StepModelType mode,
403 const Standard_CString multi,
404 const Standard_Boolean isExternFile)
406 if ( labels.Length() <=0 ) return Standard_False;
408 Handle(STEPCAFControl_ActorWrite) Actor =
409 Handle(STEPCAFControl_ActorWrite)::DownCast ( writer.WS()->NormAdaptor()->ActorWrite() );
411 // translate free top-level shapes of the DECAF document
412 #ifdef DEB // includes Transfer_ActorOfFinderProcess
413 // cout << "Actor is " << writer.WS()->NormAdaptor()->ActorWrite()->DynamicType()->Name() << endl;
415 Standard_Integer ap = Interface_Static::IVal ("write.step.schema");
416 TDF_LabelSequence sublabels;
417 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
418 TDF_Label L = labels.Value(i);
420 if ( myLabels.IsBound ( L ) ) continue; // already processed
422 TopoDS_Shape shape = XCAFDoc_ShapeTool::GetShape ( L );
423 if ( shape.IsNull() ) continue;
425 // write shape either as a whole, or as multifile (with extern refs)
426 if ( ! multi /* || ! XCAFDoc_ShapeTool::IsAssembly ( L ) */ ) {
427 Actor->SetStdMode ( Standard_False );
429 // fill sequence of (sub) shapes for which attributes should be written
430 // and set actor to handle assemblies in a proper way
431 TDF_LabelSequence comp;
432 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_True );
433 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
435 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( comp(k), ref ) ) continue;
436 if ( ! myLabels.IsBound ( ref ) ) {
437 TopoDS_Shape refS = XCAFDoc_ShapeTool::GetShape ( ref );
438 myLabels.Bind ( ref, refS );
439 sublabels.Append ( ref );
440 if ( XCAFDoc_ShapeTool::IsAssembly ( ref ) )
441 Actor->RegisterAssembly ( refS );
444 myLabels.Bind ( L, shape );
445 sublabels.Append ( L );
446 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) )
447 Actor->RegisterAssembly ( shape );
449 writer.Transfer(shape,mode,Standard_False);
450 Actor->SetStdMode ( Standard_True ); // restore default behaviour
453 // translate final solids
454 TopoDS_Shape Sass = TransferExternFiles ( L, mode, sublabels, multi );
456 // translate main assembly structure
458 if ( ap == 3 ) { // if AP203, switch to AP214
459 Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
460 Handle(StepData_StepModel) model =
461 Handle(StepData_StepModel)::DownCast ( writer.WS()->Model() );
462 if ( model->HasHeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) ) {
463 Handle(HeaderSection_FileSchema) fs =
464 Handle(HeaderSection_FileSchema)::DownCast ( model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) );
465 Handle(TCollection_HAsciiString) str = fs->SchemaIdentifiersValue ( 1 );
466 Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "AUTOMOTIVE_DESIGN" );
467 if ( str->Search ( ap214 ) <0 ) {
469 str->AssignCat ( ap214 );
474 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
475 Interface_Static::SetCVal ("write.step.assembly", "On");
476 writer.Transfer ( Sass, STEPControl_AsIs );
477 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
478 Interface_Static::SetIVal ("write.step.schema", ap);
482 writer.WS()->ComputeGraph(Standard_True );// added by skl 03.11.2003 since we use
483 // writer.Transfer() wihtout compute graph
487 WriteNames ( writer.WS(), sublabels );
491 if ( GetColorMode() )
492 WriteColors ( writer.WS(), sublabels );
495 if ( GetLayerMode() )
496 WriteLayers ( writer.WS(), sublabels );
498 // write SHUO entities
499 if ( GetSHUOMode() && !isExternFile )
500 // do not store SHUO for extern reference for the moment
501 WriteSHUOs ( writer.WS(), sublabels );
505 WriteDGTs(writer.WS(),sublabels);
508 if(GetMaterialMode())
509 WriteMaterials(writer.WS(),sublabels);
511 // register all MDGPRs in model
512 MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR);
513 for (; anItr.More(); anItr.Next()) {
514 Handle(Interface_InterfaceModel) Model = writer.WS()->Model();
515 Model->AddWithRefs( anItr.Value() );
519 if ( multi ) { // external refs
520 WriteExternRefs ( writer.WS(), sublabels );
523 // write validation props
524 // if ( multi && ap ==3 ) {
525 // Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
527 if ( GetPropsMode() )
528 WriteValProps ( writer.WS(), sublabels, multi );
530 Interface_Static::SetIVal ("write.step.schema", ap);
533 writer.WS()->ComputeGraph ( Standard_True );
535 return Standard_True;
539 //=======================================================================
540 //function : TransferExternFiles
542 //=======================================================================
544 TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L,
545 const STEPControl_StepModelType mode,
546 TDF_LabelSequence &labels,
547 const Standard_CString prefix)
549 // if label already translated, just return the shape
550 if ( myLabels.IsBound ( L ) ) {
551 return myLabels.Find ( L );
556 B.MakeCompound ( C );
559 // if not assembly, write to separate file
560 if ( ! XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
562 // prepare for transfer
563 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
564 newWS->SelectNorm ( "STEP" );
565 STEPControl_Writer sw ( newWS, Standard_True );
566 TDF_LabelSequence Lseq;
569 // construct the name for extern file
570 Handle(TCollection_HAsciiString) basename = new TCollection_HAsciiString;
571 if ( prefix && prefix[0] ) basename->AssignCat ( prefix );
572 GetLabelName ( L, basename );
573 Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString ( basename );
574 name->AssignCat ( ".stp" );
575 if ( myFiles->HasItem ( name->ToCString() ) ) { // avoid confusions
576 for ( Standard_Integer k=1; k < 32000; k++ ) {
577 name = new TCollection_HAsciiString ( basename );
578 name->AssignCat ( "_" );
579 name->AssignCat ( TCollection_AsciiString ( k ).ToCString() );
580 name->AssignCat ( ".stp" );
581 if ( ! myFiles->HasItem ( name->ToCString() ) ) break;
585 // translate and record extern file
586 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
588 EF->SetName ( name );
590 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
591 Interface_Static::SetCVal ("write.step.assembly", "Off");
592 const Standard_CString multi = 0;
593 EF->SetTransferStatus ( Transfer ( sw, Lseq, mode, multi, Standard_True ) );
594 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
595 myLabEF.Bind ( L, EF );
596 myFiles->SetItem ( name->ToCString(), EF );
598 // return empty compound as replacement for the shape
599 myLabels.Bind ( L, C );
603 // else iterate on components add create structure of empty compounds
604 // representing the assembly
605 TDF_LabelSequence comp;
606 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_False );
607 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
608 TDF_Label lab = comp(k);
610 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, ref ) ) continue;
611 TopoDS_Shape Scomp = TransferExternFiles ( ref, mode, labels, prefix );
612 Scomp.Location ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
615 myLabels.Bind ( L, C );
620 //=======================================================================
621 //function : WriteExternRefs
623 //=======================================================================
625 Standard_Boolean STEPCAFControl_Writer::WriteExternRefs (const Handle(XSControl_WorkSession) &WS,
626 const TDF_LabelSequence &labels) const
628 if ( labels.Length() <=0 ) return Standard_False;
630 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
631 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
632 STEPConstruct_ExternRefs EFTool ( WS );
633 Standard_Integer schema = Interface_Static::IVal("write.step.schema");
634 for ( Standard_Integer k=1; k <= labels.Length(); k++ ) {
635 TDF_Label lab = labels(k);
636 if ( XCAFDoc_ShapeTool::IsAssembly ( lab ) ) continue; // skip assemblies
639 Handle(STEPCAFControl_ExternFile) EF;
640 if ( ! ExternFile ( lab, EF ) ) continue; // should never be
643 if ( ! myLabels.IsBound ( lab ) ) continue; // not recorded as translated, skip
644 TopoDS_Shape S = myLabels.Find ( lab );
646 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
647 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
648 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
650 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
656 const Standard_CString format = (const Standard_CString) ( schema == 3 ? "STEP AP203" : "STEP AP214" );
657 // try to get PD from SDR
658 StepRepr_RepresentedDefinition RD = SDR->Definition();
659 Handle(StepRepr_PropertyDefinition) aPropDef = RD.PropertyDefinition();
660 if (aPropDef.IsNull()) {
662 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepRepr_PropertyDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
666 StepRepr_CharacterizedDefinition CharDef = aPropDef->Definition();
667 Handle(StepBasic_ProductDefinition) PD = CharDef.ProductDefinition();
670 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepBasic_ProductDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
674 EFTool.AddExternRef ( EF->GetName()->ToCString(), PD, format );
676 EFTool.WriteExternRefs(schema);
677 return Standard_True;
681 //=======================================================================
682 //function : FindEntities
684 //=======================================================================
685 static Standard_Integer FindEntities (const Handle(Transfer_FinderProcess) &FP,
686 const TopoDS_Shape &S,
688 TColStd_SequenceOfTransient &seqRI)
690 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, S, L );
692 if ( ! item.IsNull() ) {
693 seqRI.Append ( item );
697 // may be S was splited during shape processing
698 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
699 Handle(Transfer_Binder) bnd = FP->Find ( mapper );
700 if ( bnd.IsNull() ) return 0;
702 Handle(Transfer_TransientListBinder) TransientListBinder =
703 //Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) );
704 Handle(Transfer_TransientListBinder)::DownCast( bnd );
705 Standard_Integer nres=0;
706 if ( TransientListBinder.IsNull() && S.ShapeType() == TopAbs_COMPOUND)
708 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
709 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, it.Value(), L );
710 if ( item.IsNull() ) continue;
712 seqRI.Append ( item );
717 const Standard_Integer nb = TransientListBinder->NbTransients();
718 for (Standard_Integer i=1; i<=nb; i++) {
719 Handle(Standard_Transient) t = TransientListBinder->Transient(i);
720 item = Handle(StepRepr_RepresentationItem)::DownCast(t);
721 if ( item.IsNull() ) continue;
723 seqRI.Append ( item );
726 /* works but is obsolete: another approach
728 TopoDS_Shape comp = TransferBRep::ShapeResult(bnd);
729 if ( ! comp.IsNull() && comp.ShapeType() < S.ShapeType() ) {
730 for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) {
731 MakeSTEPStyles(Styles, it.Value(), settings, STEPstyle,
732 Map, ( hasOwn ? &style : 0 ) );
741 //=======================================================================
742 //function : getStyledItem
744 //=======================================================================
745 static Standard_Boolean getStyledItem(const TopoDS_Shape& S,
746 const Handle(XCAFDoc_ShapeTool)& STool,
747 const STEPConstruct_Styles &Styles,
748 Handle(StepVisual_StyledItem) &resSelItem,
749 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
751 TDF_Label aTopShL = STool->FindShape(S, Standard_False);
752 TopoDS_Shape aTopLevSh = STool->GetShape( aTopShL );
753 Standard_Boolean found = Standard_False;
754 if ( !aTopLevSh.IsNull() && myMapCompMDGPR.IsBound( aTopLevSh ) ) {
755 Handle(StepVisual_PresentationRepresentation) aMDGPR =
756 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopLevSh ) );
757 Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items();
758 // search for PSA of Monifold solid
759 if ( !anSelItmHArr.IsNull() )
761 for (Standard_Integer si = 1; si <= anSelItmHArr->Length(); si++) {
762 Handle(StepVisual_StyledItem) aSelItm =
763 Handle(StepVisual_StyledItem)::DownCast(anSelItmHArr->Value(si));
765 if ( aSelItm.IsNull() )
768 // check that it is a stiled item for monifold solid brep
770 TColStd_SequenceOfTransient aNewseqRI;
771 FindEntities ( Styles.FinderProcess(), aTopLevSh, Loc, aNewseqRI );
772 if ( aNewseqRI.Length() > 0 )
775 Handle(StepRepr_RepresentationItem) anItem = aSelItm->Item();
776 Standard_Boolean isSameMonSolBR = Standard_False;
777 for (Standard_Integer mi = 1; mi <= aNewseqRI.Length(); mi++) {
778 if ( !anItem.IsNull() && anItem == aNewseqRI.Value( mi ) ) {
779 isSameMonSolBR = Standard_True;
788 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
789 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA =
790 Handle(StepVisual_PresentationStyleAssignment)::DownCast(aSelItm->StylesValue(jsi));
791 // check for PSA for top-level (not Presentation style by contex for NAUO)
792 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
794 resSelItem = aSelItm;
795 found = Standard_True;
804 //=======================================================================
805 //function : setDefaultInstanceColor
807 //=======================================================================
808 static Standard_Boolean setDefaultInstanceColor (const Handle(StepVisual_StyledItem) &aSelItm,
809 Handle(StepVisual_PresentationStyleAssignment)& PSA)
811 Standard_Boolean found = Standard_False;
812 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
813 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA =
814 Handle(StepVisual_PresentationStyleAssignment)::DownCast(aSelItm->StylesValue(jsi));
815 // check for PSA for top-level (not Presentation style by contex for NAUO)
816 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
817 return Standard_False;
819 // get style select from father PSA
820 if (aFatherPSA->NbStyles() > 0) {
821 Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles =
822 new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles());
823 for (Standard_Integer k = 1; k <= aFatherPSA->NbStyles(); k++) {
824 StepVisual_PresentationStyleSelect PSS;
825 StepVisual_PresentationStyleSelect olDPSS = aFatherPSA->StylesValue(k);
826 if (!olDPSS.PointStyle().IsNull())
827 PSS.SetValue (olDPSS.PointStyle());
828 else if (!olDPSS.CurveStyle().IsNull())
829 PSS.SetValue (olDPSS.CurveStyle());
830 else if (!olDPSS.SurfaceStyleUsage().IsNull())
831 PSS.SetValue (olDPSS.SurfaceStyleUsage());
833 found = Standard_False;
836 //aFatherStyles->SetValue( k, PSS );
837 aFatherStyles->SetValue( k, olDPSS );
838 found = Standard_True;
842 PSA->Init( aFatherStyles );
851 //=======================================================================
852 //function : MakeSTEPStyles
854 //=======================================================================
855 static void MakeSTEPStyles (STEPConstruct_Styles &Styles,
856 const TopoDS_Shape &S,
857 const XCAFPrs_DataMapOfShapeStyle &settings,
858 Handle(StepVisual_StyledItem) &override,
859 TopTools_MapOfShape &Map,
860 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR,
861 STEPConstruct_DataMapOfAsciiStringTransient &DPDCs,
862 STEPConstruct_DataMapOfPointTransient &ColRGBs,
863 const Handle(XCAFDoc_ColorTool)& CTool,
864 const XCAFPrs_Style *inherit = 0,
865 const Standard_Boolean isComponent = Standard_False)
867 // skip already processed shapes
868 if ( ! Map.Add ( S ) ) return;
870 // check if shape has its own style (r inherits from ancestor)
872 if ( inherit ) style = *inherit;
873 if ( settings.IsBound(S) ) {
874 XCAFPrs_Style own = settings.Find(S);
875 if ( !own.IsVisible() ) style.SetVisibility ( Standard_False );
876 if ( own.IsSetColorCurv() ) style.SetColorCurv ( own.GetColorCurv() );
877 if ( own.IsSetColorSurf() ) style.SetColorSurf ( own.GetColorSurf() );
880 // translate colors to STEP
881 Handle(StepVisual_Colour) surfColor, curvColor;
882 if ( style.IsSetColorSurf() )
883 surfColor = Styles.EncodeColor(style.GetColorSurf(),DPDCs,ColRGBs);
884 if ( style.IsSetColorCurv() )
885 curvColor = Styles.EncodeColor(style.GetColorCurv(),DPDCs,ColRGBs);
887 Standard_Boolean hasOwn = ( ! surfColor.IsNull() ||
888 ! curvColor.IsNull() ||
889 ! style.IsVisible() );
891 // find target item and assign style to it
892 Handle(StepVisual_StyledItem) STEPstyle = override;
894 if ( S.ShapeType() != TopAbs_COMPOUND || isComponent ) { // skip compounds, let subshapes inherit its colors
896 TColStd_SequenceOfTransient seqRI;
897 Standard_Integer nb = FindEntities ( Styles.FinderProcess(), S, L, seqRI );
899 if ( nb <=0 ) cout << "Warning: Cannot find RI for " << S.TShape()->DynamicType()->Name() << endl;
901 //Get overridden style gka 10.06.03
902 if ( isComponent && nb)
903 getStyledItem(S, CTool->ShapeTool(), Styles, override,myMapCompMDGPR);
906 for ( Standard_Integer i=1; i <= nb; i++ ) {
907 Handle(StepRepr_RepresentationItem) item =
908 Handle(StepRepr_RepresentationItem)::DownCast(seqRI(i));
909 Handle(StepVisual_PresentationStyleAssignment) PSA;
910 if ( style.IsVisible() || !surfColor.IsNull() || !curvColor.IsNull() ) {
911 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
914 // default white color
915 surfColor = Styles.EncodeColor(Quantity_Color(1,1,1,Quantity_TOC_RGB),DPDCs,ColRGBs);
916 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
918 setDefaultInstanceColor( override, PSA);
920 } // end of component case
922 STEPstyle = Styles.AddStyle ( item, PSA, override );
923 hasOwn = Standard_False;
928 // iterate on subshapes (except vertices :)
929 if ( S.ShapeType() == TopAbs_EDGE ) return;
930 if ( !isComponent ) // PTV 10.02.2003
931 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
932 MakeSTEPStyles ( Styles, it.Value(), settings, STEPstyle,
933 Map, myMapCompMDGPR, DPDCs, ColRGBs, CTool,
934 ( hasOwn ? &style : 0 ) );
939 static Standard_Boolean getFatherColor (const TDF_Label& L,
940 const Handle(XCAFDoc_ColorTool)& CTool,
941 XCAFPrs_Style& style)
943 Standard_Boolean done = Standard_False;
944 TopoDS_Shape aSh = CTool->ShapeTool()->GetShape( L );
945 TDF_Label aFL = CTool->ShapeTool()->FindShape( aSh );
946 if (aFL.IsNull() || aFL == L)
949 if ( CTool->GetColor ( aFL, XCAFDoc_ColorGen, C ) ) {
950 style.SetColorCurv ( C );
951 style.SetColorSurf ( C );
952 done = Standard_True;
954 if ( CTool->GetColor ( aFL, XCAFDoc_ColorSurf, C ) ) {
955 style.SetColorSurf ( C );
956 done = Standard_True;
958 if ( CTool->GetColor ( aFL, XCAFDoc_ColorCurv, C ) ) {
959 style.SetColorCurv ( C );
960 done = Standard_True;
968 //=======================================================================
969 //function : WriteColors
971 //=======================================================================
973 Standard_Boolean STEPCAFControl_Writer::WriteColors (const Handle(XSControl_WorkSession) &WS,
974 const TDF_LabelSequence &labels)
976 if ( labels.Length() <=0 ) return Standard_False;
978 // Iterate on shapes in the document
979 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
980 if ( CTool.IsNull() ) return Standard_False;
982 STEPConstruct_Styles Styles ( WS );
983 STEPConstruct_DataMapOfAsciiStringTransient DPDCs;
984 STEPConstruct_DataMapOfPointTransient ColRGBs;
985 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
986 TDF_Label L = labels.Value(i);
988 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
989 // Skip assemblies: colors assigned to assemblies and their instances
990 // are not supported (it is not clear how to encode that in STEP)
991 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
993 cout << "Warning: Cannot write color for Assembly" << endl;
994 cout << "Info: Check for colors assigned to components in assembly" << endl;
996 // PTV 22.01.2003 Write color for instances.
997 TDF_LabelSequence compLabels;
998 if ( aSTool.IsNull() )
1000 if (!aSTool->GetComponents(L, compLabels))
1002 WriteColors(WS, compLabels);
1005 Styles.ClearStyles();
1007 // get a target shape and try to find corresponding context
1008 // (all the colors set under that label will be put into that context)
1010 if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1011 Standard_Boolean isComponent = aSTool->IsComponent( L );
1012 TopoDS_Shape aTopSh = S;
1013 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext ( S );
1014 if ( isComponent ) {
1015 TDF_Label aTopShL = aSTool->FindShape(S, Standard_False);
1016 if (aTopShL.IsNull())
1018 aTopSh = aSTool->GetShape( aTopShL );
1019 Context = Styles.FindContext ( aTopSh );
1021 if ( Context.IsNull() )
1024 // collect settings set on that label
1025 XCAFPrs_DataMapOfShapeStyle settings;
1026 TDF_LabelSequence seq;
1028 XCAFDoc_ShapeTool::GetSubShapes ( L, seq );
1029 Standard_Boolean isVisible = Standard_True;
1030 for ( Standard_Integer j = 1; j <= seq.Length(); j++ ) {
1031 TDF_Label lab = seq.Value(j);
1032 XCAFPrs_Style style;
1034 if ( isComponent && lab == L ) {
1035 // check for invisible status of object on label
1036 if ( !CTool->IsVisible( lab ) ) {
1037 isVisible = Standard_False;
1038 style.SetVisibility( Standard_False );
1041 if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) {
1042 style.SetColorCurv ( C );
1043 style.SetColorSurf ( C );
1045 if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) )
1046 style.SetColorSurf ( C );
1047 if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) )
1048 style.SetColorCurv ( C );
1049 // commented, cause we are need to take reference from
1050 // if ( isComponent && lab == L && !isVisible)
1051 // if ( !style.IsSetColorSurf() && !style.IsSetColorCurv() ) {
1052 // getFatherColor ( L, CTool, style);
1054 if ( ! style.IsSetColorCurv() && ! style.IsSetColorSurf() && isVisible ) continue;
1056 TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab );
1057 settings.Bind ( sub, style );
1060 if ( settings.Extent() <=0 ) continue;
1062 // iterate on subshapes and create STEP styles
1063 Handle(StepVisual_StyledItem) override;
1064 TopTools_MapOfShape Map;
1066 MakeSTEPStyles(Styles,S,settings,override,Map,myMapCompMDGPR,DPDCs,ColRGBs,CTool,0,isComponent);
1068 // create MDGPR and record it in model
1069 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1072 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1074 cerr << "Error: Current Top-Level shape have MDGPR already " << endl;
1077 Styles.CreateMDGPR ( Context, aMDGPR );
1078 if (!aMDGPR.IsNull())
1079 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1082 // create SDR and add to model.
1083 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1084 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1085 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1086 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1087 if ( FP->FindTypedTransient(mapper,
1088 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1090 // create SDR for NAUO
1091 Handle(StepRepr_ProductDefinitionShape) nullPDS; // important to be NULL
1092 Styles.CreateNAUOSRD( Context, CDSR, nullPDS );
1094 // search for MDGPR of the component top-level shape
1095 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1096 aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1098 aMDGPR = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
1099 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
1100 aMDGPR->SetName( ReprName );
1101 aMDGPR->SetContextOfItems( Context );
1102 myMapCompMDGPR.Bind ( aTopSh, aMDGPR );
1104 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1105 Standard_Integer oldLengthlen = 0;
1106 if (!oldItems.IsNull())
1107 oldLengthlen = oldItems->Length();
1108 const Standard_Integer nbIt = oldLengthlen + Styles.NbStyles();
1111 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1112 new StepRepr_HArray1OfRepresentationItem(1, nbIt);
1113 Standard_Integer si;
1114 Standard_Integer el = 1;
1115 for ( si=1; si <= oldLengthlen; si++ )
1116 newItems->SetValue( el++, oldItems->Value( si ) );
1117 for ( si=1; si <= Styles.NbStyles(); si++ ) {
1118 newItems->SetValue( el++, Handle(StepRepr_RepresentationItem)::DownCast(Styles.Style(si)));
1119 // WP->Model()->AddWithRefs ( Handle(StepRepr_RepresentationItem)::DownCast (Styles.Style(si)));
1122 // create invisibility item and refer for stiledItem
1123 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1124 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1125 new StepVisual_HArray1OfInvisibleItem (1,Styles.NbStyles());
1126 // put all style item into the harray
1127 for ( si=1; si <= Styles.NbStyles(); si++ ) {
1128 Handle(StepRepr_RepresentationItem) styledItm =
1129 Handle(StepRepr_RepresentationItem)::DownCast(Styles.Style(si));
1130 StepVisual_InvisibleItem anInvItem;
1131 anInvItem.SetValue( styledItm );
1132 HInvsblItm->SetValue( si, anInvItem );
1134 // set the invisibility of items
1135 Invsblt->Init( HInvsblItm );
1136 WS->Model()->AddWithRefs( Invsblt );
1139 if (newItems->Length() > 0)
1140 aMDGPR->SetItems( newItems );
1141 } //end of work with CDSR
1145 return Standard_True;
1149 //=======================================================================
1150 //function : WriteNames
1152 //=======================================================================
1154 Standard_Boolean STEPCAFControl_Writer::WriteNames (const Handle(XSControl_WorkSession) &WS,
1155 const TDF_LabelSequence &labels) const
1157 if ( labels.Length() <=0 ) return Standard_False;
1160 Handle(Interface_InterfaceModel) Model = WS->Model();
1161 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1162 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1163 // Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1164 // if ( STool.IsNull() ) return Standard_False;
1166 // Iterate on requested shapes
1167 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1168 TDF_Label L = labels.Value(i);
1171 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1172 if ( ! GetLabelName (L, hName) ) continue;
1173 // Handle(TDataStd_Name) N;
1174 // if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) continue;
1175 // TCollection_ExtendedString name = N->Get();
1176 // if ( name.Length() <=0 ) continue;
1178 // find target STEP entity for the current shape
1180 // if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1181 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1182 TopoDS_Shape S = myLabels.Find ( L );
1184 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
1185 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1186 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
1188 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
1193 // set the name to the PRODUCT
1194 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
1195 if ( PropD.IsNull() ) continue;
1196 Handle(StepBasic_ProductDefinition) PD = PropD->Definition().ProductDefinition();
1197 if ( PD.IsNull() ) continue;
1198 Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
1200 Prod->SetId ( hName );
1201 Prod->SetName ( hName );
1203 // write names for components of assemblies
1204 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1205 TDF_LabelSequence seq;
1206 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1207 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1208 TDF_Label lab = seq(k);
1210 // get shape with correct location
1212 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1213 ! myLabels.IsBound ( Lref ) ) continue;
1214 S = myLabels.Find ( Lref );
1215 S.Move ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
1217 hName = new TCollection_HAsciiString;
1218 if ( ! GetLabelName (lab, hName) ) continue;
1220 // find the target CDSR corresponding to a shape
1221 mapper = TransferBRep::ShapeMapper ( FP, S );
1222 Handle(Transfer_Binder) binder = FP->Find ( mapper );
1223 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1224 if ( ! FP->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), CDSR) )
1226 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1227 Handle(StepBasic_ProductDefinitionRelationship) NAUO = PDS->Definition().ProductDefinitionRelationship();
1228 if ( ! NAUO.IsNull() ) NAUO->SetName ( hName );
1233 return Standard_True;
1237 //=======================================================================
1238 //function : WritePropsForLabel
1240 //=======================================================================
1241 static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession) &WS,
1242 const Handle(XCAFDoc_ShapeTool) &aSTool,
1243 const STEPCAFControl_DataMapOfLabelShape &myLabels,
1245 const Standard_CString multi)
1247 if(L.IsNull()) return Standard_False;
1249 STEPConstruct_ValidationProps Props ( WS );
1251 TopoDS_Shape S = aSTool->GetShape(L);
1252 if(S.IsNull()) return Standard_False;
1254 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1256 Handle(XCAFDoc_Area) A;
1257 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1258 if ( ! A.IsNull() ) {
1259 Props.AddArea ( S, A->Get() );
1262 Handle(XCAFDoc_Volume) V;
1263 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1264 if ( ! V.IsNull() ) {
1265 Props.AddVolume ( S, V->Get() );
1269 Handle(XCAFDoc_Centroid) C;
1270 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1271 if ( ! C.IsNull() ) {
1272 Props.AddCentroid ( S, C->Get() );
1275 if( XCAFDoc_ShapeTool::IsCompound(L) || XCAFDoc_ShapeTool::IsAssembly(L) ) {
1277 for(Standard_Integer ich=1; ich<=L.NbChildren(); ich++) {
1278 WritePropsForLabel(WS,aSTool,myLabels,L.FindChild(ich),multi);
1283 return Standard_True;
1287 //=======================================================================
1288 //function : WriteValProps
1290 //=======================================================================
1292 Standard_Boolean STEPCAFControl_Writer::WriteValProps (const Handle(XSControl_WorkSession) &WS,
1293 const TDF_LabelSequence &labels,
1294 const Standard_CString multi) const
1296 if ( labels.Length() <=0 ) return Standard_False;
1299 // STEPConstruct_ValidationProps Props ( WS );
1300 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1302 // Iterate on requested shapes
1303 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1304 TDF_Label L = labels.Value(i);
1306 WritePropsForLabel(WS,aSTool,myLabels,L,multi);
1308 // find target STEP entity for the current shape
1309 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1310 TopoDS_Shape S = myLabels.Find ( L );
1312 // write area and volume (except for components in multifile mode)
1313 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1314 Handle(XCAFDoc_Area) A;
1315 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1316 if ( ! A.IsNull() ) Props.AddArea ( S, A->Get() );
1318 Handle(XCAFDoc_Volume) V;
1319 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1320 if ( ! V.IsNull() ) Props.AddVolume ( S, V->Get() );
1324 Handle(XCAFDoc_Centroid) C;
1325 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1326 if ( ! C.IsNull() ) Props.AddCentroid ( S, C->Get() );
1328 // write centroid for components of assemblies
1329 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1330 TDF_LabelSequence seq;
1331 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1332 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1333 TDF_Label lab = seq(k);
1335 // get shape with correct location
1337 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1338 ! myLabels.IsBound ( Lref ) ) continue;
1339 TopLoc_Location Loc = XCAFDoc_ShapeTool::GetLocation ( lab );
1340 S = myLabels.Find ( Lref );
1344 lab.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1345 // if centroid is not assigned to an instance,
1346 // use (shifted) centroid of original shape
1349 Lref.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1350 if ( C.IsNull() ) continue;
1351 center = C->Get().Transformed ( Loc.Transformation() );
1353 else center = C->Get();
1355 Props.AddCentroid ( S, center, Standard_True );
1361 return Standard_True;
1365 //=======================================================================
1366 //function : WriteLayers
1368 //=======================================================================
1370 Standard_Boolean STEPCAFControl_Writer::WriteLayers (const Handle(XSControl_WorkSession) &WS,
1371 const TDF_LabelSequence &labels ) const
1374 if ( labels.Length() <=0 ) return Standard_False;
1377 Handle(Interface_InterfaceModel) Model = WS->Model();
1378 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1379 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1380 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( labels(1) );
1381 if (LTool.IsNull() ) return Standard_False;
1383 TDF_LabelSequence LayerLS;
1384 LTool->GetLayerLabels(LayerLS);
1385 if ( LayerLS.Length() <=0 ) return Standard_False;
1387 // Iterate on requested layers and for each layer take set of shapes.
1388 for ( Standard_Integer i=1; i <= LayerLS.Length(); i++ ) {
1389 TDF_Label L = LayerLS.Value(i);
1391 // get labels of shapes in that layer
1392 TDF_LabelSequence ShapeLs;
1393 LTool->GetShapesOfLayer(L, ShapeLs);
1394 if ( ShapeLs.Length() <=0 ) continue;
1396 // name of layer: if not set, is considered as being empty
1397 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1398 GetLabelName ( L, hName );
1400 // Find target STEP entity for each shape and add to StepVisual_PresentationLayerAssignment items.
1401 TColStd_SequenceOfTransient seqRI;
1402 for ( Standard_Integer j=1; j <= ShapeLs.Length(); j++) {
1403 TDF_Label shLabel = ShapeLs.Value(j);
1404 if ( shLabel.IsNull() ) continue;
1406 // there is no way to assign layer to instance in STEP
1407 if ( XCAFDoc_ShapeTool::IsAssembly ( shLabel ) ||
1408 XCAFDoc_ShapeTool::IsReference ( shLabel ) )
1411 // check that the shape is one of (uub)labels written during current transfer
1412 Standard_Integer k = 1;
1413 for ( ; k <= labels.Length(); k++ )
1414 if ( shLabel.IsDescendant ( labels(k) ) ) break;
1415 if ( k > labels.Length() ) continue;
1417 // get target STEP entity
1418 TopoDS_Shape oneShape = XCAFDoc_ShapeTool::GetShape(shLabel);
1420 TopLoc_Location Loc;
1421 Standard_Integer nb =
1422 FindEntities ( FP, oneShape, Loc, seqRI );
1424 FP->Messenger() << "Warning: Cannot find RI for " << oneShape.TShape()->DynamicType()->Name() << endl;
1426 if ( seqRI.Length() <= 0 ) continue;
1428 // analyze visibility
1429 Handle(StepVisual_PresentationLayerAssignment) StepLayerAs = new StepVisual_PresentationLayerAssignment;
1430 Handle(TCollection_HAsciiString) descr;
1431 Handle(TDataStd_UAttribute) aUAttr;
1432 Standard_Boolean isLinv = Standard_False;
1433 if (L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr)) {
1434 descr = new TCollection_HAsciiString ("invisible");
1436 FP->Messenger() << "\tLayer \"" << hName->String().ToCString() << "\" is invisible"<<endl;
1438 isLinv = Standard_True;
1440 else descr = new TCollection_HAsciiString ("visible");
1442 // create layer entity
1443 Handle(StepVisual_HArray1OfLayeredItem) HArrayOfLItem =
1444 new StepVisual_HArray1OfLayeredItem ( 1, seqRI.Length() );
1445 for (Standard_Integer i1 = 1; i1<=seqRI.Length(); i1++) {
1446 StepVisual_LayeredItem LI;
1447 LI.SetValue ( seqRI.Value(i1) );
1448 HArrayOfLItem->SetValue( i1, LI );
1450 StepLayerAs->Init(hName, descr, HArrayOfLItem);
1451 Model->AddWithRefs( StepLayerAs );
1452 // PTV 23.01.2003 add the invisibility AFTER adding layer into the model.
1453 // add the invisibility for the layer
1455 // Invisibility Item for containig invisible layers.
1456 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm = new StepVisual_HArray1OfInvisibleItem (1,1);
1457 StepVisual_InvisibleItem InvIt;
1458 InvIt.SetValue( StepLayerAs );
1459 HInvsblItm->SetValue( 1, InvIt);
1461 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1462 Invsblt->Init( HInvsblItm );
1463 Model->AddWithRefs( Invsblt );
1466 return Standard_True;
1470 //=======================================================================
1471 //function : getSHUOstyle
1472 //purpose : auxilary
1473 //=======================================================================
1474 static Standard_Boolean getSHUOstyle(const TDF_Label& aSHUOlab,
1475 const Handle(XCAFDoc_ColorTool)& CTool,
1476 XCAFPrs_Style& SHUOstyle)
1479 if (!CTool->IsVisible( aSHUOlab ) )
1480 SHUOstyle.SetVisibility(Standard_False);
1482 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) {
1483 SHUOstyle.SetColorCurv ( C );
1484 SHUOstyle.SetColorSurf ( C );
1486 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) )
1487 SHUOstyle.SetColorSurf ( C );
1488 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) )
1489 SHUOstyle.SetColorCurv ( C );
1491 if ( !SHUOstyle.IsSetColorCurv() &&
1492 !SHUOstyle.IsSetColorSurf() &&
1493 SHUOstyle.IsVisible() )
1494 return Standard_False;
1495 return Standard_True;
1499 //=======================================================================
1500 //function : getProDefinitionOfNAUO
1501 //purpose : auxilary
1502 //=======================================================================
1503 static Standard_Boolean getProDefinitionOfNAUO(const Handle(XSControl_WorkSession)& WS,
1504 const TopoDS_Shape& theShape,
1505 Handle(StepBasic_ProductDefinition)& PD,
1506 Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO,
1507 Standard_Boolean IsRelating)
1509 if ( theShape.IsNull() )
1510 return Standard_False;
1512 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1513 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1514 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1515 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, theShape );
1516 if (!FP->FindTypedTransient(mapper,
1517 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1519 return Standard_False;
1521 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1523 return Standard_False;
1524 // get the NAUO entity
1525 Interface_Graph aGraph = WS->HGraph()->Graph();
1526 Interface_EntityIterator subs = aGraph.Shareds(PDS);
1527 for ( subs.Start(); subs.More(); subs.Next() ) {
1528 if (!subs.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)))
1530 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value());
1533 if ( NAUO.IsNull() )
1534 return Standard_False;
1535 // get Relatinf or Related product definition
1537 PD = NAUO->RelatedProductDefinition();
1539 PD = NAUO->RelatingProductDefinition();
1541 return Standard_False;
1542 return Standard_True;
1546 //=======================================================================
1547 //function : writeSHUO
1548 //purpose : auxilary
1549 //=======================================================================
1550 static Standard_Boolean writeSHUO (const Handle(XCAFDoc_GraphNode)& theSHUO,
1551 const Handle(XCAFDoc_ShapeTool)& theSTool,
1552 const Handle(XSControl_WorkSession)& WS,
1553 Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO,
1554 TopoDS_Shape& NAUOShape,
1555 Handle(StepBasic_ProductDefinition)& theRelatingPD,
1556 Standard_Boolean& isDeepest)
1558 // set the ProductDefinitionRelationship descriptin information as empty strings.
1559 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
1561 TDF_LabelSequence aNextUsageLabs;
1562 theSTool->GetSHUONextUsage( theSHUO->Label(), aNextUsageLabs );
1563 Handle(XCAFDoc_GraphNode) NuSHUO;
1564 if ( theTopSHUO.IsNull() ) {
1566 if (aNextUsageLabs.Length() < 1)
1567 return Standard_False;
1568 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1569 if (NuSHUO.IsNull())
1570 return Standard_False;
1571 // get relating product definition
1572 TopoDS_Shape aTopCompShape = theSTool->GetShape( theSHUO->Label().Father() );
1573 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO;
1574 if (!getProDefinitionOfNAUO( WS, aTopCompShape,
1575 theRelatingPD, UUNAUO, Standard_True ))
1576 return Standard_False;
1577 // get related product definition
1578 TopoDS_Shape aNUShape = theSTool->GetShape( NuSHUO->Label().Father() );
1579 Handle(StepBasic_ProductDefinition) aRelatedPD;
1580 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO;
1581 if (!getProDefinitionOfNAUO( WS, aNUShape,
1582 aRelatedPD, NUNAUO, Standard_False ))
1583 return Standard_False;
1585 theTopSHUO = new StepRepr_SpecifiedHigherUsageOccurrence;
1586 // create deepest shuo EmptyString
1587 theTopSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1588 /*no description*/Standard_False,/*description*/EmptyString,
1589 theRelatingPD, aRelatedPD,
1590 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1591 /*upper_usage*/UUNAUO, /*next_usage*/NUNAUO);
1592 // write the other SHUO.
1593 if(!writeSHUO( NuSHUO, theSTool, WS, theTopSHUO, NAUOShape, theRelatingPD, isDeepest )) {
1594 theTopSHUO.Nullify();
1595 return Standard_False;
1598 return Standard_True;
1600 // Handle(XCAFDoc_GraphNode) NuSHUO;
1601 if ( aNextUsageLabs.Length() > 0) {
1602 // store SHUO recursive
1604 if ( aNextUsageLabs.Length() > 1 )
1605 cout << "Warning: store only one next_usage of current SHUO" << endl;
1607 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1608 Handle(StepRepr_SpecifiedHigherUsageOccurrence) aNUEntSHUO =
1609 new StepRepr_SpecifiedHigherUsageOccurrence;
1610 if (!writeSHUO( NuSHUO, theSTool, WS, aNUEntSHUO, NAUOShape, theRelatingPD, isDeepest ))
1611 return Standard_False;
1613 // store the deepest SHUO to the dociment
1614 TopoDS_Shape aNUSh, aUUSh;
1615 aNUSh = theSTool->GetShape( NuSHUO->Label().Father() );
1616 aUUSh = theSTool->GetShape( theSHUO->Label().Father() );
1617 // get relating PD with upper_usage and related PD with next_usage
1618 Handle(StepBasic_ProductDefinition) nullPD;// no need to use,case have shared <theRelatingPD>
1619 Handle(StepBasic_ProductDefinition) aRelatedPD;
1620 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO, NUNAUO;
1621 if (!getProDefinitionOfNAUO( WS, aUUSh, nullPD, UUNAUO, Standard_True ) ||
1622 !getProDefinitionOfNAUO( WS, aNUSh, aRelatedPD, NUNAUO, Standard_False )) {
1624 cout << "Warning: cannot get related or relating PD" << endl;
1626 return Standard_False;
1628 aNUEntSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1629 /*no description*/Standard_False,/*description*/EmptyString,
1630 theRelatingPD, aRelatedPD,
1631 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1632 /*upper_usage*/theTopSHUO, /*next_usage*/NUNAUO);
1634 isDeepest = Standard_False;
1636 WS->Model()->AddWithRefs ( aNUEntSHUO );
1637 return Standard_True;
1638 } // end of recurse storing
1641 TDF_Label aShapeL = theSHUO->Label().Father();
1642 NAUOShape = theSTool->GetShape( aShapeL );
1643 // return to the deepest level from SHUO shape level
1644 // it is because SHUO is attribute on deep level and shape level.
1645 isDeepest = Standard_True;
1646 return Standard_True;
1650 //=======================================================================
1651 //function : createSHUOStyledItem
1652 //purpose : auxilary
1653 //=======================================================================
1654 static Standard_Boolean createSHUOStyledItem (const XCAFPrs_Style& style,
1655 const Handle(StepRepr_ProductDefinitionShape)& PDS,
1656 const Handle(XSControl_WorkSession) &WS,
1657 const TopoDS_Shape& Sh,
1658 const Handle(XCAFDoc_ShapeTool)& STool,
1659 MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
1661 // create styled item for the indicated SHUO and store to the model
1662 STEPConstruct_Styles Styles( WS );
1663 // translate colors to STEP
1664 Handle(StepVisual_Colour) surfColor, curvColor;
1665 if ( style.IsSetColorSurf() )
1666 surfColor = Styles.EncodeColor ( style.GetColorSurf() );
1667 if ( style.IsSetColorCurv() )
1668 curvColor = Styles.EncodeColor ( style.GetColorCurv() );
1669 Standard_Boolean isComponent = Standard_True;// cause need to get PSBC
1670 Handle(StepRepr_RepresentationItem) item;
1671 // set default color for invisible SHUO.
1672 Standard_Boolean isSetDefaultColor = Standard_False;
1673 if (surfColor.IsNull() && curvColor.IsNull() && !style.IsVisible() ) {
1674 surfColor = Styles.EncodeColor ( Quantity_Color( 1, 1, 1, Quantity_TOC_RGB ) );
1675 isSetDefaultColor = Standard_True;
1677 Handle(StepVisual_PresentationStyleAssignment) PSA =
1678 Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1679 Handle(StepVisual_StyledItem) override; //null styled item
1681 // find the repr item of the shape
1682 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1683 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1684 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, Sh );
1685 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1686 FP->FindTypedTransient(mapper,
1687 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1689 if ( CDSR.IsNull() )
1690 return Standard_False;
1692 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext( Sh );
1693 TopoDS_Shape aTopSh = Sh;
1694 if (Context.IsNull()) {
1695 TDF_Label aTopShL = STool->FindShape(Sh, Standard_False);
1696 if (aTopShL.IsNull())
1697 return Standard_False;
1698 aTopSh = STool->GetShape( aTopShL );
1699 Context = Styles.FindContext ( aTopSh );
1701 if (Context.IsNull())
1702 return Standard_False;
1703 // get representation item of the shape
1705 TColStd_SequenceOfTransient seqRI;
1706 FindEntities ( FP, Sh, L, seqRI );
1708 if ( seqRI.Length() <=0 )
1709 FP->Messenger() << "Warning: Cannot find RI for " << Sh.TShape()->DynamicType()->Name() << endl;
1711 item = Handle(StepRepr_RepresentationItem)::DownCast(seqRI(1));
1712 //get overridden styled item
1713 getStyledItem(Sh,STool, Styles, override,myMapCompMDGPR);
1715 // get STEP STYLED ITEM
1716 Handle(StepVisual_StyledItem) STEPstyle = Styles.AddStyle ( item, PSA, override );
1717 // create SR, SDR and all necessary references between them and ST, PDS, PSBC, GRC
1718 Styles.CreateNAUOSRD( Context, CDSR, PDS );
1720 // add step styled item of SHUO to the model
1721 // do it by additing styled item to the MDGPR
1722 if ( !aTopSh.IsNull() && !myMapCompMDGPR.IsBound( aTopSh ) ) {
1723 // create MDGPR and record it in model
1725 cout << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance" << endl;
1727 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1728 Styles.CreateMDGPR ( Context, aMDGPR );
1729 if (!aMDGPR.IsNull())
1730 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1732 else if ( !aTopSh.IsNull() && myMapCompMDGPR.IsBound( aTopSh ) ) {
1733 // get MDGPR of the top-level shape
1734 Handle(StepVisual_PresentationRepresentation) aMDGPR =
1735 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1736 // get old styled items to not lose it
1737 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1738 Standard_Integer oldLengthlen = 0;
1739 if (!oldItems.IsNull())
1740 oldLengthlen = oldItems->Length();
1741 // create new array of styled items by an olds and new one
1742 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1743 new StepRepr_HArray1OfRepresentationItem(1, oldLengthlen + 1);
1744 Standard_Integer si;
1745 Standard_Integer el = 1;
1746 for ( si=1; si <= oldLengthlen; si++ )
1747 newItems->SetValue( el++, oldItems->Value( si ) );
1748 newItems->SetValue( el++, Handle(StepRepr_RepresentationItem)::DownCast(STEPstyle) );
1749 // init MDGPR be new array of styled items
1750 if (newItems->Length() > 0)
1751 aMDGPR->SetItems( newItems );
1754 WS->Model()->AddWithRefs ( STEPstyle ); // add as root to the model, but it is not good
1756 cout << "Warning: " << __FILE__ << ": adds styled item of SHUO as root, casue cannot find MDGPR" << endl;
1759 // create invisibility item for the styled item
1760 if ( !style.IsVisible() ) {
1761 if (isSetDefaultColor) {
1762 // try to set default color from top-level shape
1764 setDefaultInstanceColor(override, PSA);
1766 // create invisibility item and refer for stiledItem
1767 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1768 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1769 new StepVisual_HArray1OfInvisibleItem (1,1);
1770 // put all style item into the harray
1771 StepVisual_InvisibleItem anInvItem;
1772 anInvItem.SetValue( STEPstyle );
1773 HInvsblItm->SetValue( 1, anInvItem );
1774 Invsblt->Init( HInvsblItm );
1775 WS->Model()->AddWithRefs( Invsblt );
1778 return Standard_True;
1782 //=======================================================================
1783 //function : WriteSHUOs
1785 //=======================================================================
1787 Standard_Boolean STEPCAFControl_Writer::WriteSHUOs (const Handle(XSControl_WorkSession) &WS,
1788 const TDF_LabelSequence &labels )
1790 if ( labels.Length() <=0 ) return Standard_False;
1793 Handle(Interface_InterfaceModel) Model = WS->Model();
1794 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1795 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1796 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1797 if (CTool.IsNull() )
1798 return Standard_False;
1799 // map of transfered SHUO
1800 TColStd_MapOfTransient aMapOfMainSHUO;
1801 // TColStd_IndexedDataMapOfTransientTransient aIndxMapOfSHUOEnt;
1802 // Iterate on requested shapes
1803 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1804 TDF_Label L = labels.Value(i);
1805 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1806 // TopoDS_Shape S = myLabels.Find ( L );
1807 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1808 TDF_LabelSequence seq;
1809 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1810 // iterates on components of assembly
1811 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1812 TDF_Label lab = seq(k);
1813 TDF_AttributeSequence anAttrSeq;
1814 CTool->ShapeTool()->GetAllComponentSHUO( lab, anAttrSeq );
1816 for (Standard_Integer j = 1; j <= anAttrSeq.Length(); j++) {
1817 Handle(XCAFDoc_GraphNode) aSHUO =
1818 Handle(XCAFDoc_GraphNode)::DownCast(anAttrSeq.Value( j ));
1819 // take label of SHUO
1820 TDF_Label aSHUOlab = aSHUO->Label();
1821 TDF_LabelSequence aUpLabels;
1822 // check is it SHUO of upper_usage
1823 CTool->ShapeTool()->GetSHUOUpperUsage( aSHUOlab, aUpLabels );
1824 if ( aUpLabels.Length() > 0 )
1825 continue; // transfer only main SHUO
1826 if ( aMapOfMainSHUO.Contains( aSHUO ) )
1827 continue; // do not try to transfer SHUO twice
1828 aMapOfMainSHUO.Add( aSHUO );
1829 // check if it is styled SHUO
1830 XCAFPrs_Style SHUOstyle;
1831 if ( !getSHUOstyle ( aSHUOlab, CTool, SHUOstyle ) ) {
1833 cout << "Warning: " << __FILE__ << ": do not store SHUO without any style to the STEP model" << endl;
1837 // write SHUO to the model amd then add structure type.
1838 TopoDS_Shape NAUOShape; // shape of the deepest NAUO in the SHUO structure
1839 Standard_Boolean isDeepest = Standard_False;
1840 Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO;
1841 Handle(StepBasic_ProductDefinition) aRelatingPD;
1842 // create the top SHUO and all other.
1843 writeSHUO( aSHUO, CTool->ShapeTool(), WS, anEntOfSHUO, NAUOShape, aRelatingPD, isDeepest );
1844 if ( anEntOfSHUO.IsNull() || NAUOShape.IsNull() ) {
1846 cout << "Warning: " << __FILE__ << ": Cannot store SHUO" << endl;
1850 // create new Product Definition Shape for TOP SHUO
1852 cout << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO " << endl;
1854 Handle(StepRepr_ProductDefinitionShape) PDS = new StepRepr_ProductDefinitionShape;
1855 Handle(TCollection_HAsciiString) aPDSname = new TCollection_HAsciiString("SHUO");
1856 Handle(TCollection_HAsciiString) descrStr = new TCollection_HAsciiString("");
1857 StepRepr_CharacterizedDefinition aCharDef;
1858 aCharDef.SetValue( anEntOfSHUO );
1859 PDS->Init( aPDSname, Standard_False, descrStr, aCharDef );
1861 // create styled item for SHUO and add to the model
1862 createSHUOStyledItem ( SHUOstyle, PDS, WS, NAUOShape, CTool->ShapeTool(), myMapCompMDGPR );
1864 } // end work with SHUO
1865 } // end of an assembly components
1866 } // end of IsAssembly case
1867 // nothing to do if it is not assembly
1869 } // end of iterates on indicated labels
1870 return Standard_True;
1874 //=======================================================================
1875 //function : FindPDSforDGT
1876 //purpose : auxilary: find PDS for AdvancedFace or EdgeCurve for creation
1877 // needed ShapeAspect in D> structure
1878 //=======================================================================
1879 static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph,
1880 const Handle(Standard_Transient) &ent,
1881 Handle(StepRepr_ProductDefinitionShape) &PDS,
1882 Handle(StepRepr_RepresentationContext) &RC,
1883 Handle(StepShape_AdvancedFace) &AF,
1884 Handle(StepShape_EdgeCurve) &EC)
1886 if( !ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) &&
1887 !ent->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)) )
1888 return Standard_False;
1890 AF = Handle(StepShape_AdvancedFace)::DownCast(ent);
1891 if( ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) ) {
1892 EC = Handle(StepShape_EdgeCurve)::DownCast(ent);
1893 Interface_EntityIterator subs = aGraph.Sharings(EC);
1894 for(subs.Start(); subs.More() && AF.IsNull(); subs.Next()) {
1895 Handle(StepShape_OrientedEdge) OE = Handle(StepShape_OrientedEdge)::DownCast(subs.Value());
1896 if(OE.IsNull()) continue;
1897 Interface_EntityIterator subs1 = aGraph.Sharings(OE);
1898 for(subs1.Start(); subs1.More() && AF.IsNull(); subs1.Next()) {
1899 Handle(StepShape_EdgeLoop) EL = Handle(StepShape_EdgeLoop)::DownCast(subs1.Value());
1900 if(EL.IsNull()) continue;
1901 Interface_EntityIterator subs2 = aGraph.Sharings(EL);
1902 for(subs2.Start(); subs2.More() && AF.IsNull(); subs2.Next()) {
1903 Handle(StepShape_FaceBound) FB = Handle(StepShape_FaceBound)::DownCast(subs2.Value());
1904 if(FB.IsNull()) continue;
1905 Interface_EntityIterator subs3 = aGraph.Sharings(FB);
1906 for(subs3.Start(); subs3.More() && AF.IsNull(); subs3.Next()) {
1907 AF = Handle(StepShape_AdvancedFace)::DownCast(subs3.Value());
1913 if(AF.IsNull()) return Standard_False;
1915 Interface_EntityIterator subs = aGraph.Sharings(AF);
1916 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
1917 Handle(StepShape_ConnectedFaceSet) CFS =
1918 Handle(StepShape_ConnectedFaceSet)::DownCast(subs.Value());
1919 if(CFS.IsNull()) continue;
1920 Interface_EntityIterator subs1 = aGraph.Sharings(CFS);
1921 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
1922 Handle(StepRepr_RepresentationItem) RI =
1923 Handle(StepRepr_RepresentationItem)::DownCast(subs1.Value());
1924 if(RI.IsNull()) continue;
1925 Interface_EntityIterator subs2 = aGraph.Sharings(RI);
1926 for(subs2.Start(); subs2.More() && PDS.IsNull(); subs2.Next()) {
1927 Handle(StepShape_ShapeRepresentation) SR =
1928 Handle(StepShape_ShapeRepresentation)::DownCast(subs2.Value());
1929 if(SR.IsNull()) continue;
1930 RC = SR->ContextOfItems();
1931 Interface_EntityIterator subs3 = aGraph.Sharings(SR);
1932 for(subs3.Start(); subs3.More() && PDS.IsNull(); subs3.Next()) {
1933 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1934 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs3.Value());
1935 if(SDR.IsNull()) continue;
1936 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
1937 if(PropD.IsNull()) continue;
1938 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
1944 return Standard_True;
1948 //=======================================================================
1949 //function : WriteDGTs
1951 //=======================================================================
1953 Standard_Boolean STEPCAFControl_Writer::WriteDGTs (const Handle(XSControl_WorkSession) &WS,
1954 const TDF_LabelSequence &labels ) const
1957 if ( labels.Length() <=0 ) return Standard_False;
1960 Handle(Interface_InterfaceModel) Model = WS->Model();
1961 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1962 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1963 Interface_Graph aGraph = WS->HGraph()->Graph();
1964 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( labels(1) );
1965 if(DGTTool.IsNull() ) return Standard_False;
1967 TDF_LabelSequence DGTLabels;
1968 STEPConstruct_DataMapOfAsciiStringTransient DatumMap;
1971 DGTTool->GetDatumLabels(DGTLabels);
1972 if(DGTLabels.Length()<=0) return Standard_False;
1974 for(i=1; i<=DGTLabels.Length(); i++) {
1975 TDF_Label DatumL = DGTLabels.Value(i);
1977 if(!DGTTool->GetRefShapeLabel(DatumL,ShapeL)) continue;
1978 // find target shape
1979 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL);
1980 TopLoc_Location Loc;
1981 TColStd_SequenceOfTransient seqRI;
1982 FindEntities( FP, aShape, Loc, seqRI );
1983 if ( seqRI.Length() <= 0 ) {
1984 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
1987 Handle(StepRepr_ProductDefinitionShape) PDS;
1988 Handle(StepRepr_RepresentationContext) RC;
1989 Handle(Standard_Transient) ent = seqRI.Value(1);
1990 Handle(StepShape_AdvancedFace) AF;
1991 Handle(StepShape_EdgeCurve) EC;
1992 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
1993 if(PDS.IsNull()) continue;
1994 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
1995 Handle(XCAFDoc_Datum) DatumAttr;
1996 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
1997 Handle(TCollection_HAsciiString) aName = DatumAttr->GetName();
1998 Handle(TCollection_HAsciiString) aDescription = DatumAttr->GetDescription();
1999 Handle(TCollection_HAsciiString) anIdentification = DatumAttr->GetIdentification();
2000 Handle(StepDimTol_DatumFeature) DF = new StepDimTol_DatumFeature;
2001 Handle(StepDimTol_Datum) aDatum = new StepDimTol_Datum;
2002 DF->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
2003 Model->AddWithRefs(DF);
2004 aDatum->Init(aName, new TCollection_HAsciiString, PDS, StepData_LFalse, anIdentification);
2005 Model->AddWithRefs(aDatum);
2006 Handle(StepRepr_ShapeAspectRelationship) SAR = new StepRepr_ShapeAspectRelationship;
2007 SAR->SetName(aName);
2008 SAR->SetRelatingShapeAspect(DF);
2009 SAR->SetRelatedShapeAspect(aDatum);
2010 Model->AddWithRefs(SAR);
2011 // write chain for DatumFeature
2012 StepRepr_CharacterizedDefinition CD;
2014 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
2015 PropD->Init(aName,Standard_True,aDescription,CD);
2016 Model->AddWithRefs(PropD);
2017 StepRepr_RepresentedDefinition RD;
2019 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
2020 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
2021 new StepRepr_HArray1OfRepresentationItem(1,1);
2022 HARI->SetValue(1,AF);
2023 SR->Init(aName,HARI,RC);
2024 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
2026 Model->AddWithRefs(SDR);
2027 // write chain for Datum
2028 StepRepr_CharacterizedDefinition CD1;
2029 CD1.SetValue(aDatum);
2030 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
2031 PropD1->Init(aName,Standard_True,aDescription,CD1);
2032 Model->AddWithRefs(PropD1);
2033 StepRepr_RepresentedDefinition RD1;
2034 RD1.SetValue(PropD1);
2035 Handle(StepShape_ShapeRepresentation) SR1 = new StepShape_ShapeRepresentation;
2036 Handle(StepRepr_HArray1OfRepresentationItem) HARI1 =
2037 new StepRepr_HArray1OfRepresentationItem(1,1);
2038 HARI1->SetValue(1,AF->FaceGeometry());
2039 SR1->Init(aName,HARI1,RC);
2040 Model->AddWithRefs(SR1);
2041 Handle(StepShape_ShapeDefinitionRepresentation) SDR1 = new StepShape_ShapeDefinitionRepresentation;
2042 SDR1->Init(RD1,SR1);
2043 Model->AddWithRefs(SDR1);
2044 // add created Datum into Map
2045 TCollection_AsciiString stmp(aName->ToCString());
2046 stmp.AssignCat(aDescription->ToCString());
2047 stmp.AssignCat(anIdentification->ToCString());
2048 DatumMap.Bind(stmp,aDatum);
2051 // write Tolerances and Dimensions
2053 DGTTool->GetDimTolLabels(DGTLabels);
2054 if(DGTLabels.Length()<=0) return Standard_False;
2055 for(i=1; i<=DGTLabels.Length(); i++) {
2056 TDF_Label DimTolL = DGTLabels.Value(i);
2058 if(!DGTTool->GetRefShapeLabel(DimTolL,ShapeL)) continue;
2059 // find target shape
2060 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL);
2061 TopLoc_Location Loc;
2062 TColStd_SequenceOfTransient seqRI;
2063 FindEntities( FP, aShape, Loc, seqRI );
2064 if ( seqRI.Length() <= 0 ) {
2065 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
2068 Handle(StepRepr_ProductDefinitionShape) PDS;
2069 Handle(StepRepr_RepresentationContext) RC;
2070 Handle(Standard_Transient) ent = seqRI.Value(1);
2071 Handle(StepShape_AdvancedFace) AF;
2072 Handle(StepShape_EdgeCurve) EC;
2073 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
2074 if(PDS.IsNull()) continue;
2075 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
2077 Handle(XCAFDoc_DimTol) DimTolAttr;
2078 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) continue;
2079 Standard_Integer kind = DimTolAttr->GetKind();
2080 Handle(TColStd_HArray1OfReal) aVal = DimTolAttr->GetVal();
2081 Handle(TCollection_HAsciiString) aName = DimTolAttr->GetName();
2082 Handle(TCollection_HAsciiString) aDescription = DimTolAttr->GetDescription();
2084 // common part of writing D> entities
2085 StepRepr_CharacterizedDefinition CD;
2086 Handle(StepRepr_ShapeAspect) SA = new StepRepr_ShapeAspect;
2087 SA->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
2088 Model->AddWithRefs(SA);
2090 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
2091 PropD->Init(aName,Standard_True,aDescription,CD);
2092 Model->AddWithRefs(PropD);
2093 StepRepr_RepresentedDefinition RD;
2095 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
2096 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
2097 new StepRepr_HArray1OfRepresentationItem(1,1);
2099 HARI->SetValue(1,EC);
2101 HARI->SetValue(1,AF);
2102 SR->Init(aName,HARI,RC);
2103 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
2105 Model->AddWithRefs(SDR);
2106 // define aUnit for creation LengthMeasureWithUnit (common for all)
2107 StepBasic_Unit aUnit;
2108 Handle(StepBasic_SiUnitAndLengthUnit) SLU;
2109 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) Ctx =
2110 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(RC);
2112 for(Standard_Integer j=1; j<=Ctx->NbUnits(); j++) {
2113 if(Ctx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2114 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx->UnitsValue(j));
2120 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) Ctx1 =
2121 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(RC);
2122 if(!Ctx1.IsNull()) {
2123 for(Standard_Integer j=1; j<=Ctx1->NbUnits(); j++) {
2124 if(Ctx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2125 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx1->UnitsValue(j));
2132 SLU = new StepBasic_SiUnitAndLengthUnit;
2134 aUnit.SetValue(SLU);
2136 // specific part of writing D> entities
2137 if(kind<20) { //dimension
2138 Handle(StepShape_DimensionalSize) DimSize = new StepShape_DimensionalSize;
2139 DimSize->Init(SA,aDescription);
2140 Model->AddWithRefs(DimSize);
2141 if(aVal->Length()>1) {
2142 // create MeasureWithUnits
2143 Handle(StepBasic_MeasureValueMember) MVM1 = new StepBasic_MeasureValueMember;
2144 MVM1->SetName("POSITIVE_LENGTH_MEASURE");
2145 MVM1->SetReal(aVal->Value(1));
2146 Handle(StepBasic_MeasureWithUnit) MWU1 = new StepBasic_MeasureWithUnit;
2147 MWU1->Init(MVM1,aUnit);
2148 Handle(StepBasic_MeasureValueMember) MVM2 = new StepBasic_MeasureValueMember;
2149 MVM2->SetName("POSITIVE_LENGTH_MEASURE");
2150 MVM2->SetReal(aVal->Value(2));
2151 Handle(StepBasic_MeasureWithUnit) MWU2 = new StepBasic_MeasureWithUnit;
2152 MWU2->Init(MVM2,aUnit);
2153 Handle(StepRepr_RepresentationItem) RI1 = new StepRepr_RepresentationItem;
2154 RI1->Init(new TCollection_HAsciiString("lower limit"));
2155 Handle(StepRepr_RepresentationItem) RI2 = new StepRepr_RepresentationItem;
2156 RI2->Init(new TCollection_HAsciiString("upper limit"));
2157 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU1 =
2158 new StepRepr_ReprItemAndLengthMeasureWithUnit;
2159 RILMU1->Init(MWU1,RI1);
2160 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU2 =
2161 new StepRepr_ReprItemAndLengthMeasureWithUnit;
2162 RILMU2->Init(MWU2,RI2);
2163 Model->AddWithRefs(RILMU1);
2164 Model->AddWithRefs(RILMU2);
2165 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
2166 // new StepRepr_CompoundItemDefinitionMember;
2167 //Handle(TColStd_HArray1OfTransient) ArrTr = new TColStd_HArray1OfTransient(1,2);
2168 //ArrTr->SetValue(1,RILMU1);
2169 //ArrTr->SetValue(2,RILMU2);
2170 //CIDM->SetArrTransient(ArrTr);
2171 //CIDM->SetName("SET_REPRESENTATION_ITEM");
2172 //StepRepr_CompoundItemDefinition CID;
2173 //CID.SetValue(CIDM);
2174 Handle(StepRepr_HArray1OfRepresentationItem) HARIVR =
2175 new StepRepr_HArray1OfRepresentationItem(1,2);
2176 HARIVR->SetValue(1,RILMU1);
2177 HARIVR->SetValue(2,RILMU2);
2178 Handle(StepRepr_ValueRange) VR = new StepRepr_ValueRange;
2179 //VR->Init(aName,CID);
2180 VR->Init(aName,HARIVR);
2181 Model->AddEntity(VR);
2182 Handle(StepShape_ShapeDimensionRepresentation) SDimR =
2183 new StepShape_ShapeDimensionRepresentation;
2184 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
2185 new StepRepr_HArray1OfRepresentationItem(1,1);
2186 HARI->SetValue(1,VR);
2187 SDimR->Init(aName,HARI,RC);
2188 Model->AddWithRefs(SDimR);
2189 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
2190 new StepShape_DimensionalCharacteristicRepresentation;
2191 StepShape_DimensionalCharacteristic DimChar;
2192 DimChar.SetValue(DimSize);
2193 DimCharR->Init(DimChar,SDimR);
2194 Model->AddEntity(DimCharR);
2197 else if(kind<50) { //tolerance
2198 if(kind<35) { // tolerance with datum system
2199 TDF_LabelSequence DatumLabels;
2200 DGTTool->GetDatumTolerLabels(DimTolL,DatumLabels);
2201 Standard_Integer NbDR = DatumLabels.Length();
2202 Handle(StepDimTol_HArray1OfDatumReference) HADR = new StepDimTol_HArray1OfDatumReference(1,NbDR);
2203 for(Standard_Integer j=1; j<=NbDR; j++) {
2204 Handle(XCAFDoc_Datum) DatumAttr;
2205 TDF_Label DatumL = DatumLabels.Value(j);
2206 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
2207 Handle(TCollection_HAsciiString) aNameD = DatumAttr->GetName();
2208 Handle(TCollection_HAsciiString) aDescriptionD = DatumAttr->GetDescription();
2209 Handle(TCollection_HAsciiString) anIdentificationD = DatumAttr->GetIdentification();
2210 TCollection_AsciiString stmp(aNameD->ToCString());
2211 stmp.AssignCat(aDescriptionD->ToCString());
2212 stmp.AssignCat(anIdentificationD->ToCString());
2213 if(DatumMap.IsBound(stmp)) {
2214 Handle(StepDimTol_Datum) aDatum =
2215 Handle(StepDimTol_Datum)::DownCast(DatumMap.Find(stmp));
2216 Handle(StepDimTol_DatumReference) DR = new StepDimTol_DatumReference;
2218 Model->AddWithRefs(DR);
2219 HADR->SetValue(j,DR);
2222 // create LengthMeasureWithUnit
2223 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
2224 MVM->SetName("LENGTH_MEASURE");
2225 MVM->SetReal(aVal->Value(1));
2226 Handle(StepBasic_LengthMeasureWithUnit) LMWU = new StepBasic_LengthMeasureWithUnit;
2227 LMWU->Init(MVM,aUnit);
2228 // create tolerance by it's type
2230 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2231 new StepDimTol_GeometricToleranceWithDatumReference;
2232 GTWDR->SetDatumSystem(HADR);
2233 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2234 new StepDimTol_ModifiedGeometricTolerance;
2235 if(kind==21) MGT->SetModifier(StepDimTol_MaximumMaterialCondition);
2236 else if(kind==22) MGT->SetModifier(StepDimTol_LeastMaterialCondition);
2237 else if(kind==23) MGT->SetModifier(StepDimTol_RegardlessOfFeatureSize);
2238 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
2239 new StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol;
2240 GTComplex->Init(aName,aDescription,LMWU,SA,GTWDR,MGT);
2241 Model->AddWithRefs(GTComplex);
2244 Handle(StepDimTol_AngularityTolerance) aToler =
2245 new StepDimTol_AngularityTolerance;
2246 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2247 Model->AddWithRefs(aToler);
2250 Handle(StepDimTol_CircularRunoutTolerance) aToler =
2251 new StepDimTol_CircularRunoutTolerance;
2252 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2253 Model->AddWithRefs(aToler);
2256 Handle(StepDimTol_CoaxialityTolerance) aToler =
2257 new StepDimTol_CoaxialityTolerance;
2258 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2259 Model->AddWithRefs(aToler);
2262 Handle(StepDimTol_ConcentricityTolerance) aToler =
2263 new StepDimTol_ConcentricityTolerance;
2264 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2265 Model->AddWithRefs(aToler);
2268 Handle(StepDimTol_ParallelismTolerance) aToler =
2269 new StepDimTol_ParallelismTolerance;
2270 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2271 Model->AddWithRefs(aToler);
2274 Handle(StepDimTol_PerpendicularityTolerance) aToler =
2275 new StepDimTol_PerpendicularityTolerance;
2276 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2277 Model->AddWithRefs(aToler);
2280 Handle(StepDimTol_SymmetryTolerance) aToler =
2281 new StepDimTol_SymmetryTolerance;
2282 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2283 Model->AddWithRefs(aToler);
2286 Handle(StepDimTol_TotalRunoutTolerance) aToler =
2287 new StepDimTol_TotalRunoutTolerance;
2288 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2289 Model->AddWithRefs(aToler);
2295 return Standard_True;
2299 //=======================================================================
2300 //function : FindPDSforRI
2301 //purpose : auxilary:
2302 //=======================================================================
2303 static Standard_Boolean FindPDSforRI(const Interface_Graph &aGraph,
2304 const Handle(Standard_Transient) &ent,
2305 Handle(StepRepr_ProductDefinitionShape) &PDS,
2306 Handle(StepRepr_RepresentationContext) &RC)
2308 if(!ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem))) return Standard_False;
2309 Interface_EntityIterator subs = aGraph.Sharings(ent);
2310 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
2311 Handle(StepShape_ShapeRepresentation) SR =
2312 Handle(StepShape_ShapeRepresentation)::DownCast(subs.Value());
2313 if(SR.IsNull()) continue;
2314 RC = SR->ContextOfItems();
2315 Interface_EntityIterator subs1 = aGraph.Sharings(SR);
2316 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
2317 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2318 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs1.Value());
2319 if(SDR.IsNull()) continue;
2320 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
2321 if(PropD.IsNull()) continue;
2322 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
2325 return Standard_True;
2329 //=======================================================================
2330 //function : WriteMaterials
2332 //=======================================================================
2334 Standard_Boolean STEPCAFControl_Writer::WriteMaterials (const Handle(XSControl_WorkSession) &WS,
2335 const TDF_LabelSequence &labels ) const
2338 if ( labels.Length() <=0 ) return Standard_False;
2341 Handle(Interface_InterfaceModel) Model = WS->Model();
2342 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
2343 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
2344 Interface_Graph aGraph = WS->HGraph()->Graph();
2345 Handle(XCAFDoc_ShapeTool) ShTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
2346 if(ShTool.IsNull() ) return Standard_False;
2347 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( labels(1) );
2348 if(MatTool.IsNull() ) return Standard_False;
2350 STEPConstruct_DataMapOfAsciiStringTransient MapDRI,MapMRI;
2351 TDF_LabelSequence TopLabels;
2352 ShTool->GetShapes(TopLabels);
2353 for(Standard_Integer i=1; i<=TopLabels.Length(); i++) {
2354 TDF_Label ShL = TopLabels.Value(i);
2355 Handle(TDataStd_TreeNode) Node;
2356 if( ShL.FindAttribute(XCAFDoc::MaterialRefGUID(),Node) && Node->HasFather() ) {
2357 // find PDS for current shape
2358 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShL);
2359 TopLoc_Location Loc;
2360 TColStd_SequenceOfTransient seqRI;
2361 FindEntities( FP, aShape, Loc, seqRI );
2362 if(seqRI.Length()<=0) continue;
2363 Handle(StepRepr_ProductDefinitionShape) PDS;
2364 Handle(StepRepr_RepresentationContext) RC;
2365 Handle(Standard_Transient) ent = seqRI.Value(1);
2366 FindPDSforRI(aGraph,ent,PDS,RC);
2367 if(PDS.IsNull()) continue;
2368 // write material entities
2369 TDF_Label MatL = Node->Father()->Label();
2370 Handle(TCollection_HAsciiString) aName;
2371 Handle(TCollection_HAsciiString) aDescription;
2372 Standard_Real aDensity;
2373 Handle(TCollection_HAsciiString) aDensName;
2374 Handle(TCollection_HAsciiString) aDensValType;
2375 Handle(StepRepr_Representation) RepDRI = new StepRepr_Representation;
2376 Handle(StepRepr_Representation) RepMRI = new StepRepr_Representation;
2377 if(MatTool->GetMaterial(MatL,aName,aDescription,aDensity,aDensName,aDensValType)) {
2378 if(aName->Length()==0) continue;
2379 TCollection_AsciiString aKey(aName->ToCString());
2380 if(MapDRI.IsBound(aKey)) {
2381 RepDRI = Handle(StepRepr_Representation)::DownCast(MapDRI.Find(aKey));
2382 if(MapMRI.IsBound(aKey)) {
2383 RepMRI = Handle(StepRepr_Representation)::DownCast(MapMRI.Find(aKey));
2388 Handle(StepRepr_DescriptiveRepresentationItem) DRI = new StepRepr_DescriptiveRepresentationItem;
2389 DRI->Init(aName,aDescription);
2390 Handle(StepRepr_HArray1OfRepresentationItem) HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
2391 HARI->SetValue(1,DRI);
2392 RepDRI->Init(new TCollection_HAsciiString("material name"),HARI,RC);
2393 Model->AddWithRefs(RepDRI);
2397 Handle(StepBasic_SiUnitAndMassUnit) SMU = new StepBasic_SiUnitAndMassUnit;
2398 SMU->SetName(StepBasic_sunGram);
2399 Handle(StepBasic_DerivedUnitElement) DUE1 = new StepBasic_DerivedUnitElement;
2400 DUE1->Init(SMU,3.0);
2402 Handle(StepBasic_SiUnitAndLengthUnit) SLU = new StepBasic_SiUnitAndLengthUnit;
2403 SLU->Init(Standard_True,StepBasic_spCenti,StepBasic_sunMetre);
2404 Handle(StepBasic_DerivedUnitElement) DUE2 = new StepBasic_DerivedUnitElement;
2405 DUE2->Init(SLU,2.0);
2407 Handle(StepBasic_HArray1OfDerivedUnitElement) HADUE = new StepBasic_HArray1OfDerivedUnitElement(1,2);
2408 HADUE->SetValue(1,DUE1);
2409 HADUE->SetValue(2,DUE2);
2410 Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit;
2412 Model->AddWithRefs(DU);
2413 StepBasic_Unit aUnit;
2415 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
2416 MVM->SetName(aDensValType->ToCString());
2417 MVM->SetReal(aDensity);
2418 Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem;
2419 MRI->Init(aDensName,MVM,aUnit);
2420 HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
2421 HARI->SetValue(1,MRI);
2422 RepMRI->Init(new TCollection_HAsciiString("density"),HARI,RC);
2423 Model->AddWithRefs(RepMRI);
2425 //WriteNewMaterial(Model,aName,aDescription,aDensity,aDensName,aDensValType,RC,RepDRI,RepMRI);
2426 MapDRI.Bind(aKey,RepDRI);
2427 if(!RepMRI.IsNull()) MapMRI.Bind(aKey,RepMRI);
2430 // write chain PDS---(DRI,MRI)
2431 StepRepr_CharacterizedDefinition CD1;
2433 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
2434 PropD1->Init(new TCollection_HAsciiString("material property"),Standard_True,
2435 new TCollection_HAsciiString("material name"),CD1);
2436 Model->AddWithRefs(PropD1);
2437 StepRepr_RepresentedDefinition RD1;
2438 RD1.SetValue(PropD1);
2439 Handle(StepRepr_PropertyDefinitionRepresentation) PDR1 =
2440 new StepRepr_PropertyDefinitionRepresentation;
2441 PDR1->Init(RD1,RepDRI);
2442 Model->AddWithRefs(PDR1);
2443 StepRepr_CharacterizedDefinition CD2;
2445 Handle(StepRepr_PropertyDefinition) PropD2 = new StepRepr_PropertyDefinition;
2446 PropD2->Init(new TCollection_HAsciiString("material property"),Standard_True,
2447 new TCollection_HAsciiString("density"),CD2);
2448 Model->AddWithRefs(PropD2);
2449 StepRepr_RepresentedDefinition RD2;
2450 RD2.SetValue(PropD2);
2451 Handle(StepRepr_PropertyDefinitionRepresentation) PDR2 =
2452 new StepRepr_PropertyDefinitionRepresentation;
2453 PDR2->Init(RD2,RepMRI);
2454 Model->AddWithRefs(PDR2);
2458 return Standard_True;
2462 //=======================================================================
2463 //function : SetColorMode
2465 //=======================================================================
2467 void STEPCAFControl_Writer::SetColorMode (const Standard_Boolean colormode)
2469 myColorMode = colormode;
2473 //=======================================================================
2474 //function : GetColorMode
2476 //=======================================================================
2478 Standard_Boolean STEPCAFControl_Writer::GetColorMode () const
2484 //=======================================================================
2485 //function : SetNameMode
2487 //=======================================================================
2489 void STEPCAFControl_Writer::SetNameMode (const Standard_Boolean namemode)
2491 myNameMode = namemode;
2495 //=======================================================================
2496 //function : GetNameMode
2498 //=======================================================================
2500 Standard_Boolean STEPCAFControl_Writer::GetNameMode () const
2506 //=======================================================================
2507 //function : SetLayerMode
2509 //=======================================================================
2511 void STEPCAFControl_Writer::SetLayerMode (const Standard_Boolean layermode)
2513 myLayerMode = layermode;
2517 //=======================================================================
2518 //function : GetLayerMode
2520 //=======================================================================
2522 Standard_Boolean STEPCAFControl_Writer::GetLayerMode () const
2528 //=======================================================================
2529 //function : SetPropsMode
2531 //=======================================================================
2533 void STEPCAFControl_Writer::SetPropsMode (const Standard_Boolean propsmode)
2535 myPropsMode = propsmode;
2539 //=======================================================================
2540 //function : GetPropsMode
2542 //=======================================================================
2544 Standard_Boolean STEPCAFControl_Writer::GetPropsMode () const
2550 //=======================================================================
2551 //function : SetSHUOMode
2553 //=======================================================================
2555 void STEPCAFControl_Writer::SetSHUOMode (const Standard_Boolean mode)
2561 //=======================================================================
2562 //function : GetSHUOMode
2564 //=======================================================================
2566 Standard_Boolean STEPCAFControl_Writer::GetSHUOMode () const
2572 //=======================================================================
2573 //function : SetDimTolMode
2575 //=======================================================================
2577 void STEPCAFControl_Writer::SetDimTolMode(const Standard_Boolean dimtolmode)
2579 myDGTMode = dimtolmode;
2583 //=======================================================================
2584 //function : GetDimTolMode
2586 //=======================================================================
2588 Standard_Boolean STEPCAFControl_Writer::GetDimTolMode() const
2594 //=======================================================================
2595 //function : SetMaterialMode
2597 //=======================================================================
2599 void STEPCAFControl_Writer::SetMaterialMode(const Standard_Boolean matmode)
2601 myMatMode = matmode;
2605 //=======================================================================
2606 //function : GetMaterialMode
2608 //=======================================================================
2610 Standard_Boolean STEPCAFControl_Writer::GetMaterialMode() const