1 // Created on: 2000-08-15
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // CURRENT LIMITATIONS:
17 // when val props and names assigned to instance of
18 // component in assembly, it is in fact supposed that only one CDSR corresponds
19 // to such shape. This can be wrong and should be handled more carefully
20 // (analysis of SDRs which the CDSR links should be done)
21 // Names and validation props are supported for top-level shapes only
23 #include <BRep_Builder.hxx>
24 #include <HeaderSection_FileSchema.hxx>
25 #include <Interface_EntityIterator.hxx>
26 #include <Interface_Static.hxx>
27 #include <Message_Messenger.hxx>
28 #include <MoniTool_DataMapIteratorOfDataMapOfShapeTransient.hxx>
29 #include <OSD_Path.hxx>
30 #include <Quantity_TypeOfColor.hxx>
31 #include <StepAP214_Protocol.hxx>
32 #include <StepBasic_DerivedUnit.hxx>
33 #include <StepBasic_DerivedUnitElement.hxx>
34 #include <StepBasic_HArray1OfDerivedUnitElement.hxx>
35 #include <StepBasic_LengthMeasureWithUnit.hxx>
36 #include <StepBasic_MeasureValueMember.hxx>
37 #include <StepBasic_Product.hxx>
38 #include <StepBasic_ProductDefinition.hxx>
39 #include <StepBasic_ProductDefinitionFormation.hxx>
40 #include <StepBasic_ProductDefinitionRelationship.hxx>
41 #include <StepBasic_SiUnitAndLengthUnit.hxx>
42 #include <StepBasic_SiUnitAndMassUnit.hxx>
43 #include <STEPCAFControl_ActorWrite.hxx>
44 #include <STEPCAFControl_Controller.hxx>
45 #include <STEPCAFControl_DictionaryOfExternFile.hxx>
46 #include <STEPCAFControl_ExternFile.hxx>
47 #include <STEPCAFControl_IteratorOfDictionaryOfExternFile.hxx>
48 #include <STEPCAFControl_Writer.hxx>
49 #include <STEPConstruct.hxx>
50 #include <STEPConstruct_DataMapOfAsciiStringTransient.hxx>
51 #include <STEPConstruct_DataMapOfPointTransient.hxx>
52 #include <STEPConstruct_ExternRefs.hxx>
53 #include <STEPConstruct_Styles.hxx>
54 #include <STEPConstruct_ValidationProps.hxx>
55 #include <STEPControl_StepModelType.hxx>
56 #include <STEPControl_Writer.hxx>
57 #include <StepData_Logical.hxx>
58 #include <StepData_StepModel.hxx>
59 #include <StepDimTol_AngularityTolerance.hxx>
60 #include <StepDimTol_CircularRunoutTolerance.hxx>
61 #include <StepDimTol_CoaxialityTolerance.hxx>
62 #include <StepDimTol_ConcentricityTolerance.hxx>
63 #include <StepDimTol_CylindricityTolerance.hxx>
64 #include <StepDimTol_Datum.hxx>
65 #include <StepDimTol_DatumFeature.hxx>
66 #include <StepDimTol_DatumReference.hxx>
67 #include <StepDimTol_FlatnessTolerance.hxx>
68 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
69 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
70 #include <StepDimTol_HArray1OfDatumReference.hxx>
71 #include <StepDimTol_LineProfileTolerance.hxx>
72 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
73 #include <StepDimTol_ParallelismTolerance.hxx>
74 #include <StepDimTol_PerpendicularityTolerance.hxx>
75 #include <StepDimTol_PositionTolerance.hxx>
76 #include <StepDimTol_RoundnessTolerance.hxx>
77 #include <StepDimTol_StraightnessTolerance.hxx>
78 #include <StepDimTol_SurfaceProfileTolerance.hxx>
79 #include <StepDimTol_SymmetryTolerance.hxx>
80 #include <StepDimTol_TotalRunoutTolerance.hxx>
81 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
82 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
83 #include <StepGeom_Surface.hxx>
84 #include <StepRepr_DescriptiveRepresentationItem.hxx>
85 #include <StepRepr_HArray1OfRepresentationItem.hxx>
86 #include <StepRepr_MeasureRepresentationItem.hxx>
87 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
88 #include <StepRepr_ProductDefinitionShape.hxx>
89 #include <StepRepr_PropertyDefinition.hxx>
90 #include <StepRepr_Representation.hxx>
91 #include <StepRepr_RepresentationItem.hxx>
92 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
93 #include <StepRepr_ShapeAspect.hxx>
94 #include <StepRepr_ShapeAspectRelationship.hxx>
95 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
96 #include <StepRepr_ValueRange.hxx>
97 #include <StepShape_AdvancedFace.hxx>
98 #include <StepShape_ConnectedFaceSet.hxx>
99 #include <StepShape_ContextDependentShapeRepresentation.hxx>
100 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
101 #include <StepShape_DimensionalSize.hxx>
102 #include <StepShape_EdgeCurve.hxx>
103 #include <StepShape_EdgeLoop.hxx>
104 #include <StepShape_FaceBound.hxx>
105 #include <StepShape_OrientedEdge.hxx>
106 #include <StepShape_ShapeDefinitionRepresentation.hxx>
107 #include <StepShape_ShapeDimensionRepresentation.hxx>
108 #include <StepShape_ShapeRepresentation.hxx>
109 #include <StepVisual_CurveStyle.hxx>
110 #include <StepVisual_HArray1OfInvisibleItem.hxx>
111 #include <StepVisual_HArray1OfLayeredItem.hxx>
112 #include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
113 #include <StepVisual_HArray1OfPresentationStyleSelect.hxx>
114 #include <StepVisual_Invisibility.hxx>
115 #include <StepVisual_InvisibleItem.hxx>
116 #include <StepVisual_MechanicalDesignGeometricPresentationRepresentation.hxx>
117 #include <StepVisual_PointStyle.hxx>
118 #include <StepVisual_PresentationLayerAssignment.hxx>
119 #include <StepVisual_PresentationRepresentation.hxx>
120 #include <StepVisual_PresentationStyleAssignment.hxx>
121 #include <StepVisual_PresentationStyleByContext.hxx>
122 #include <StepVisual_StyledItem.hxx>
123 #include <StepVisual_SurfaceStyleUsage.hxx>
124 #include <TCollection_AsciiString.hxx>
125 #include <TCollection_HAsciiString.hxx>
126 #include <TColStd_HArray1OfReal.hxx>
127 #include <TColStd_HArray1OfTransient.hxx>
128 #include <TColStd_HSequenceOfTransient.hxx>
129 #include <TColStd_MapOfTransient.hxx>
130 #include <TDataStd_Name.hxx>
131 #include <TDataStd_TreeNode.hxx>
132 #include <TDataStd_UAttribute.hxx>
133 #include <TDF_AttributeSequence.hxx>
134 #include <TDF_ChildIterator.hxx>
135 #include <TDF_Label.hxx>
136 #include <TDF_LabelSequence.hxx>
137 #include <TDF_Tool.hxx>
138 #include <TDocStd_Document.hxx>
139 #include <TopoDS_Compound.hxx>
140 #include <TopoDS_Iterator.hxx>
141 #include <TopoDS_Shape.hxx>
142 #include <TopTools_MapOfShape.hxx>
143 #include <TopTools_SequenceOfShape.hxx>
144 #include <Transfer_ActorOfFinderProcess.hxx>
145 #include <Transfer_Binder.hxx>
146 #include <Transfer_FinderProcess.hxx>
147 #include <Transfer_TransientListBinder.hxx>
148 #include <TransferBRep.hxx>
149 #include <TransferBRep_ShapeMapper.hxx>
150 #include <XCAFDoc.hxx>
151 #include <XCAFDoc_Area.hxx>
152 #include <XCAFDoc_Centroid.hxx>
153 #include <XCAFDoc_ColorTool.hxx>
154 #include <XCAFDoc_Datum.hxx>
155 #include <XCAFDoc_DimTol.hxx>
156 #include <XCAFDoc_DimTolTool.hxx>
157 #include <XCAFDoc_DocumentTool.hxx>
158 #include <XCAFDoc_GraphNode.hxx>
159 #include <XCAFDoc_LayerTool.hxx>
160 #include <XCAFDoc_Material.hxx>
161 #include <XCAFDoc_MaterialTool.hxx>
162 #include <XCAFDoc_ShapeTool.hxx>
163 #include <XCAFDoc_Volume.hxx>
164 #include <XCAFPrs.hxx>
165 #include <XCAFPrs_DataMapIteratorOfDataMapOfStyleShape.hxx>
166 #include <XCAFPrs_DataMapOfShapeStyle.hxx>
167 #include <XCAFPrs_DataMapOfStyleShape.hxx>
168 #include <XCAFPrs_Style.hxx>
169 #include <XSControl_TransferWriter.hxx>
170 #include <XSControl_WorkSession.hxx>
172 // added by skl 15.01.2004 for D> writing
173 //#include <StepRepr_CompoundItemDefinition.hxx>
174 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
175 // added by skl 12.02.2004 for writing materials
176 //=======================================================================
177 //function : GetLabelName
178 //purpose : auxilary function: take name of label and append it to str
179 //=======================================================================
180 static Standard_Boolean GetLabelName (const TDF_Label &L, Handle(TCollection_HAsciiString) &str)
182 Handle(TDataStd_Name) N;
183 if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) return Standard_False;
184 TCollection_ExtendedString name = N->Get();
185 if ( name.Length() <=0 ) return Standard_False;
187 // set name, converting it to Ascii and removing spaces
188 TCollection_AsciiString buf ( name, '?' );
191 buf.ChangeAll(' ','_');
192 str->AssignCat ( buf.ToCString() );
193 return Standard_True;
197 //=======================================================================
198 //function : STEPCAFControl_Writer
200 //=======================================================================
202 STEPCAFControl_Writer::STEPCAFControl_Writer () :
203 myColorMode( Standard_True ),
204 myNameMode ( Standard_True ),
205 myLayerMode( Standard_True ),
206 myPropsMode( Standard_True ),
207 mySHUOMode ( Standard_True ),
208 myDGTMode ( Standard_True ),
209 myMatMode ( Standard_True )
211 STEPCAFControl_Controller::Init();
212 Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
217 //=======================================================================
218 //function : STEPCAFControl_Writer
220 //=======================================================================
222 STEPCAFControl_Writer::STEPCAFControl_Writer (const Handle(XSControl_WorkSession)& WS,
223 const Standard_Boolean scratch)
225 STEPCAFControl_Controller::Init();
226 Init ( WS, scratch );
227 myColorMode = Standard_True;
228 myNameMode = Standard_True;
229 myLayerMode = Standard_True;
230 myPropsMode = Standard_True;
231 mySHUOMode = Standard_True;
235 //=======================================================================
238 //=======================================================================
240 void STEPCAFControl_Writer::Init (const Handle(XSControl_WorkSession)& WS,
241 const Standard_Boolean scratch)
243 WS->SelectNorm ( "STEP" );
244 myWriter.SetWS (WS,scratch);
245 myFiles = new STEPCAFControl_DictionaryOfExternFile;
251 //=======================================================================
254 //=======================================================================
256 IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filename)
258 IFSelect_ReturnStatus status = myWriter.Write ( filename );
260 // get directory name of the main file
261 OSD_Path mainfile ( filename );
262 mainfile.SetName ( "" );
263 mainfile.SetExtension ( "" );
264 TCollection_AsciiString dpath;
265 mainfile.SystemName ( dpath );
267 STEPCAFControl_IteratorOfDictionaryOfExternFile it ( myFiles );
268 for ( ; it.More(); it.Next() ) {
269 Handle(STEPCAFControl_ExternFile) EF = it.Value();
270 if ( EF->GetWriteStatus() != IFSelect_RetVoid ) continue;
272 // construct extern file name
273 TCollection_AsciiString fname = OSD_Path::AbsolutePath ( dpath, EF->GetName()->String() );
274 if ( fname.Length() <= 0 ) fname = EF->GetName()->String();
276 cout << "Writing external file: " << fname.ToCString() << endl;
279 EF->SetWriteStatus ( EF->GetWS()->SendAll ( fname.ToCString() ) );
286 //=======================================================================
287 //function : Transfer
289 //=======================================================================
291 Standard_Boolean STEPCAFControl_Writer::Transfer( const Handle(TDocStd_Document) &doc,
292 const STEPControl_StepModelType mode,
293 const Standard_CString multi )
295 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
296 if ( STool.IsNull() ) return Standard_False;
298 TDF_LabelSequence labels;
299 STool->GetFreeShapes ( labels );
300 return Transfer ( myWriter, labels, mode, multi );
304 //=======================================================================
305 //function : Transfer
307 //=======================================================================
309 Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_Label& L,
310 const STEPControl_StepModelType mode,
311 const Standard_CString multi )
313 TDF_LabelSequence labels;
315 return Transfer ( myWriter, labels, mode, multi );
318 //=======================================================================
319 //function : Transfer
321 //=======================================================================
323 Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_LabelSequence& labels,
324 const STEPControl_StepModelType mode,
325 const Standard_CString multi )
327 return Transfer( myWriter, labels, mode, multi );
330 //=======================================================================
333 //=======================================================================
335 Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
336 const Standard_CString filename)
338 if ( ! Transfer ( doc ) ) return Standard_False;
339 return Write ( filename ) == IFSelect_RetDone;
343 //=======================================================================
346 //=======================================================================
348 Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
349 const TCollection_AsciiString &filename)
351 if ( ! Transfer ( doc ) ) return Standard_False;
352 return Write ( filename.ToCString() ) == IFSelect_RetDone;
356 //=======================================================================
357 //function : ExternFiles
359 //=======================================================================
361 const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Writer::ExternFiles () const
367 //=======================================================================
368 //function : ExternFile
370 //=======================================================================
372 Standard_Boolean STEPCAFControl_Writer::ExternFile (const TDF_Label &L,
373 Handle(STEPCAFControl_ExternFile) &ef) const
376 if ( ! myLabEF.IsBound ( L ) ) return Standard_False;
377 ef = myLabEF.Find ( L );
378 return Standard_True;
382 //=======================================================================
383 //function : ExternFile
385 //=======================================================================
387 Standard_Boolean STEPCAFControl_Writer::ExternFile (const Standard_CString name,
388 Handle(STEPCAFControl_ExternFile) &ef) const
391 if ( ! myFiles.IsNull() || ! myFiles->HasItem ( name ) )
392 return Standard_False;
393 ef = myFiles->Item ( name );
394 return Standard_True;
398 //=======================================================================
401 //=======================================================================
403 STEPControl_Writer &STEPCAFControl_Writer::ChangeWriter ()
409 //=======================================================================
412 //=======================================================================
414 const STEPControl_Writer &STEPCAFControl_Writer::Writer () const
420 //=======================================================================
421 //function : Transfer
423 //=======================================================================
425 Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
426 const TDF_LabelSequence &labels,
427 const STEPControl_StepModelType mode,
428 const Standard_CString multi,
429 const Standard_Boolean isExternFile)
431 if ( labels.Length() <=0 ) return Standard_False;
433 Handle(STEPCAFControl_ActorWrite) Actor =
434 Handle(STEPCAFControl_ActorWrite)::DownCast ( writer.WS()->NormAdaptor()->ActorWrite() );
436 // translate free top-level shapes of the DECAF document
437 Standard_Integer ap = Interface_Static::IVal ("write.step.schema");
438 TDF_LabelSequence sublabels;
439 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
440 TDF_Label L = labels.Value(i);
442 if ( myLabels.IsBound ( L ) ) continue; // already processed
444 TopoDS_Shape shape = XCAFDoc_ShapeTool::GetShape ( L );
445 if ( shape.IsNull() ) continue;
447 // write shape either as a whole, or as multifile (with extern refs)
448 if ( ! multi /* || ! XCAFDoc_ShapeTool::IsAssembly ( L ) */ ) {
449 Actor->SetStdMode ( Standard_False );
451 // fill sequence of (sub) shapes for which attributes should be written
452 // and set actor to handle assemblies in a proper way
453 TDF_LabelSequence comp;
454 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_True );
455 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
457 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( comp(k), ref ) ) continue;
458 if ( ! myLabels.IsBound ( ref ) ) {
459 TopoDS_Shape refS = XCAFDoc_ShapeTool::GetShape ( ref );
460 myLabels.Bind ( ref, refS );
461 sublabels.Append ( ref );
462 if ( XCAFDoc_ShapeTool::IsAssembly ( ref ) )
463 Actor->RegisterAssembly ( refS );
466 myLabels.Bind ( L, shape );
467 sublabels.Append ( L );
468 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) )
469 Actor->RegisterAssembly ( shape );
471 writer.Transfer(shape,mode,Standard_False);
472 Actor->SetStdMode ( Standard_True ); // restore default behaviour
475 // translate final solids
476 TopoDS_Shape Sass = TransferExternFiles ( L, mode, sublabels, multi );
478 // translate main assembly structure
480 if ( ap == 3 ) { // if AP203, switch to AP214
481 Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
482 Handle(StepData_StepModel) model =
483 Handle(StepData_StepModel)::DownCast ( writer.WS()->Model() );
484 if ( model->HasHeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) ) {
485 Handle(HeaderSection_FileSchema) fs =
486 Handle(HeaderSection_FileSchema)::DownCast ( model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) );
487 Handle(TCollection_HAsciiString) str = fs->SchemaIdentifiersValue ( 1 );
488 Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "AUTOMOTIVE_DESIGN" );
489 if ( str->Search ( ap214 ) <0 ) {
491 str->AssignCat ( ap214 );
496 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
497 Interface_Static::SetCVal ("write.step.assembly", "On");
498 writer.Transfer ( Sass, STEPControl_AsIs );
499 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
500 Interface_Static::SetIVal ("write.step.schema", ap);
504 writer.WS()->ComputeGraph(Standard_True );// added by skl 03.11.2003 since we use
505 // writer.Transfer() wihtout compute graph
509 WriteNames ( writer.WS(), sublabels );
513 if ( GetColorMode() )
514 WriteColors ( writer.WS(), sublabels );
517 if ( GetLayerMode() )
518 WriteLayers ( writer.WS(), sublabels );
520 // write SHUO entities
521 if ( GetSHUOMode() && !isExternFile )
522 // do not store SHUO for extern reference for the moment
523 WriteSHUOs ( writer.WS(), sublabels );
527 WriteDGTs(writer.WS(),sublabels);
530 if(GetMaterialMode())
531 WriteMaterials(writer.WS(),sublabels);
533 // register all MDGPRs in model
534 MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR);
535 for (; anItr.More(); anItr.Next()) {
536 Handle(Interface_InterfaceModel) Model = writer.WS()->Model();
537 Model->AddWithRefs( anItr.Value() );
541 if ( multi ) { // external refs
542 WriteExternRefs ( writer.WS(), sublabels );
545 // write validation props
546 // if ( multi && ap ==3 ) {
547 // Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
549 if ( GetPropsMode() )
550 WriteValProps ( writer.WS(), sublabels, multi );
552 Interface_Static::SetIVal ("write.step.schema", ap);
555 writer.WS()->ComputeGraph ( Standard_True );
557 /* ================================
558 * Write names for the sub-shapes
559 * ================================ */
561 if ( Interface_Static::IVal("write.stepcaf.subshapes.name") )
563 Handle(XSControl_TransferWriter) TW = this->ChangeWriter().WS()->TransferWriter();
564 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
566 for ( int i = 1; i <= labels.Length(); i++ )
568 TDF_Label L = labels.Value(i);
570 for ( TDF_ChildIterator it(L, Standard_True); it.More(); it.Next() )
572 TDF_Label SubL = it.Value();
574 // Access name recorded in OCAF TDataStd_Name attribute
575 Handle(TCollection_HAsciiString) hSubName = new TCollection_HAsciiString;
576 if ( !GetLabelName(SubL, hSubName) )
579 // Access topological data
580 TopoDS_Shape SubS = XCAFDoc_ShapeTool::GetShape(SubL);
584 // Access the correspondent STEP Representation Item
585 Handle(StepRepr_RepresentationItem) RI;
586 Handle(TransferBRep_ShapeMapper) aShMapper = TransferBRep::ShapeMapper(FP, SubS);
587 if ( !FP->FindTypedTransient(aShMapper, STANDARD_TYPE(StepRepr_RepresentationItem), RI) )
591 RI->SetName(hSubName);
596 return Standard_True;
600 //=======================================================================
601 //function : TransferExternFiles
603 //=======================================================================
605 TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L,
606 const STEPControl_StepModelType mode,
607 TDF_LabelSequence &labels,
608 const Standard_CString prefix)
610 // if label already translated, just return the shape
611 if ( myLabels.IsBound ( L ) ) {
612 return myLabels.Find ( L );
617 B.MakeCompound ( C );
620 // if not assembly, write to separate file
621 if ( ! XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
623 // prepare for transfer
624 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
625 newWS->SelectNorm ( "STEP" );
626 STEPControl_Writer sw ( newWS, Standard_True );
627 TDF_LabelSequence Lseq;
630 // construct the name for extern file
631 Handle(TCollection_HAsciiString) basename = new TCollection_HAsciiString;
632 if ( prefix && prefix[0] ) basename->AssignCat ( prefix );
633 GetLabelName ( L, basename );
634 Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString ( basename );
635 name->AssignCat ( ".stp" );
636 if ( myFiles->HasItem ( name->ToCString() ) ) { // avoid confusions
637 for ( Standard_Integer k=1; k < 32000; k++ ) {
638 name = new TCollection_HAsciiString ( basename );
639 name->AssignCat ( "_" );
640 name->AssignCat ( TCollection_AsciiString ( k ).ToCString() );
641 name->AssignCat ( ".stp" );
642 if ( ! myFiles->HasItem ( name->ToCString() ) ) break;
646 // translate and record extern file
647 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
649 EF->SetName ( name );
651 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
652 Interface_Static::SetCVal ("write.step.assembly", "Off");
653 const Standard_CString multi = 0;
654 EF->SetTransferStatus ( Transfer ( sw, Lseq, mode, multi, Standard_True ) );
655 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
656 myLabEF.Bind ( L, EF );
657 myFiles->SetItem ( name->ToCString(), EF );
659 // return empty compound as replacement for the shape
660 myLabels.Bind ( L, C );
664 // else iterate on components add create structure of empty compounds
665 // representing the assembly
666 TDF_LabelSequence comp;
667 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_False );
668 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
669 TDF_Label lab = comp(k);
671 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, ref ) ) continue;
672 TopoDS_Shape Scomp = TransferExternFiles ( ref, mode, labels, prefix );
673 Scomp.Location ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
676 myLabels.Bind ( L, C );
681 //=======================================================================
682 //function : WriteExternRefs
684 //=======================================================================
686 Standard_Boolean STEPCAFControl_Writer::WriteExternRefs (const Handle(XSControl_WorkSession) &WS,
687 const TDF_LabelSequence &labels) const
689 if ( labels.Length() <=0 ) return Standard_False;
691 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
692 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
693 STEPConstruct_ExternRefs EFTool ( WS );
694 Standard_Integer schema = Interface_Static::IVal("write.step.schema");
695 for ( Standard_Integer k=1; k <= labels.Length(); k++ ) {
696 TDF_Label lab = labels(k);
697 if ( XCAFDoc_ShapeTool::IsAssembly ( lab ) ) continue; // skip assemblies
700 Handle(STEPCAFControl_ExternFile) EF;
701 if ( ! ExternFile ( lab, EF ) ) continue; // should never be
704 if ( ! myLabels.IsBound ( lab ) ) continue; // not recorded as translated, skip
705 TopoDS_Shape S = myLabels.Find ( lab );
707 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
708 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
709 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
711 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
717 const Standard_CString format = (const Standard_CString) ( schema == 3 ? "STEP AP203" : "STEP AP214" );
718 // try to get PD from SDR
719 StepRepr_RepresentedDefinition RD = SDR->Definition();
720 Handle(StepRepr_PropertyDefinition) aPropDef = RD.PropertyDefinition();
721 if (aPropDef.IsNull()) {
723 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepRepr_PropertyDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
727 StepRepr_CharacterizedDefinition CharDef = aPropDef->Definition();
728 Handle(StepBasic_ProductDefinition) PD = CharDef.ProductDefinition();
731 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepBasic_ProductDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
735 EFTool.AddExternRef ( EF->GetName()->ToCString(), PD, format );
737 EFTool.WriteExternRefs(schema);
738 return Standard_True;
742 //=======================================================================
743 //function : FindEntities
745 //=======================================================================
746 static Standard_Integer FindEntities (const Handle(Transfer_FinderProcess) &FP,
747 const TopoDS_Shape &S,
749 TColStd_SequenceOfTransient &seqRI)
751 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, S, L );
753 if ( ! item.IsNull() ) {
754 seqRI.Append ( item );
758 // may be S was splited during shape processing
759 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
760 Handle(Transfer_Binder) bnd = FP->Find ( mapper );
761 if ( bnd.IsNull() ) return 0;
763 Handle(Transfer_TransientListBinder) TransientListBinder =
764 //Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) );
765 Handle(Transfer_TransientListBinder)::DownCast( bnd );
766 Standard_Integer nres=0;
767 if ( TransientListBinder.IsNull() && S.ShapeType() == TopAbs_COMPOUND)
769 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
770 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, it.Value(), L );
771 if ( item.IsNull() ) continue;
773 seqRI.Append ( item );
778 const Standard_Integer nb = TransientListBinder->NbTransients();
779 for (Standard_Integer i=1; i<=nb; i++) {
780 Handle(Standard_Transient) t = TransientListBinder->Transient(i);
781 item = Handle(StepRepr_RepresentationItem)::DownCast(t);
782 if ( item.IsNull() ) continue;
784 seqRI.Append ( item );
787 /* works but is obsolete: another approach
789 TopoDS_Shape comp = TransferBRep::ShapeResult(bnd);
790 if ( ! comp.IsNull() && comp.ShapeType() < S.ShapeType() ) {
791 for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) {
792 MakeSTEPStyles(Styles, it.Value(), settings, STEPstyle,
793 Map, ( hasOwn ? &style : 0 ) );
802 //=======================================================================
803 //function : getStyledItem
805 //=======================================================================
806 static Standard_Boolean getStyledItem(const TopoDS_Shape& S,
807 const Handle(XCAFDoc_ShapeTool)& STool,
808 const STEPConstruct_Styles &Styles,
809 Handle(StepVisual_StyledItem) &resSelItem,
810 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
812 TDF_Label aTopShL = STool->FindShape(S, Standard_False);
813 TopoDS_Shape aTopLevSh = STool->GetShape( aTopShL );
814 Standard_Boolean found = Standard_False;
815 if ( !aTopLevSh.IsNull() && myMapCompMDGPR.IsBound( aTopLevSh ) ) {
816 Handle(StepVisual_PresentationRepresentation) aMDGPR =
817 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopLevSh ) );
818 Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items();
819 // search for PSA of Monifold solid
820 if ( !anSelItmHArr.IsNull() )
822 for (Standard_Integer si = 1; si <= anSelItmHArr->Length(); si++) {
823 Handle(StepVisual_StyledItem) aSelItm =
824 Handle(StepVisual_StyledItem)::DownCast(anSelItmHArr->Value(si));
826 if ( aSelItm.IsNull() )
829 // check that it is a stiled item for monifold solid brep
831 TColStd_SequenceOfTransient aNewseqRI;
832 FindEntities ( Styles.FinderProcess(), aTopLevSh, Loc, aNewseqRI );
833 if ( aNewseqRI.Length() > 0 )
836 Handle(StepRepr_RepresentationItem) anItem = aSelItm->Item();
837 Standard_Boolean isSameMonSolBR = Standard_False;
838 for (Standard_Integer mi = 1; mi <= aNewseqRI.Length(); mi++) {
839 if ( !anItem.IsNull() && anItem == aNewseqRI.Value( mi ) ) {
840 isSameMonSolBR = Standard_True;
849 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
850 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA =
851 Handle(StepVisual_PresentationStyleAssignment)::DownCast(aSelItm->StylesValue(jsi));
852 // check for PSA for top-level (not Presentation style by contex for NAUO)
853 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
855 resSelItem = aSelItm;
856 found = Standard_True;
865 //=======================================================================
866 //function : setDefaultInstanceColor
868 //=======================================================================
869 static Standard_Boolean setDefaultInstanceColor (const Handle(StepVisual_StyledItem) &aSelItm,
870 Handle(StepVisual_PresentationStyleAssignment)& PSA)
872 Standard_Boolean found = Standard_False;
873 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
874 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA =
875 Handle(StepVisual_PresentationStyleAssignment)::DownCast(aSelItm->StylesValue(jsi));
876 // check for PSA for top-level (not Presentation style by contex for NAUO)
877 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
878 return Standard_False;
880 // get style select from father PSA
881 if (aFatherPSA->NbStyles() > 0) {
882 Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles =
883 new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles());
884 for (Standard_Integer k = 1; k <= aFatherPSA->NbStyles(); k++) {
885 StepVisual_PresentationStyleSelect PSS;
886 StepVisual_PresentationStyleSelect olDPSS = aFatherPSA->StylesValue(k);
887 if (!olDPSS.PointStyle().IsNull())
888 PSS.SetValue (olDPSS.PointStyle());
889 else if (!olDPSS.CurveStyle().IsNull())
890 PSS.SetValue (olDPSS.CurveStyle());
891 else if (!olDPSS.SurfaceStyleUsage().IsNull())
892 PSS.SetValue (olDPSS.SurfaceStyleUsage());
894 found = Standard_False;
897 //aFatherStyles->SetValue( k, PSS );
898 aFatherStyles->SetValue( k, olDPSS );
899 found = Standard_True;
903 PSA->Init( aFatherStyles );
912 //=======================================================================
913 //function : MakeSTEPStyles
915 //=======================================================================
916 static void MakeSTEPStyles (STEPConstruct_Styles &Styles,
917 const TopoDS_Shape &S,
918 const XCAFPrs_DataMapOfShapeStyle &settings,
919 Handle(StepVisual_StyledItem) &override,
920 TopTools_MapOfShape &Map,
921 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR,
922 STEPConstruct_DataMapOfAsciiStringTransient &DPDCs,
923 STEPConstruct_DataMapOfPointTransient &ColRGBs,
924 const Handle(XCAFDoc_ColorTool)& CTool,
925 const XCAFPrs_Style *inherit = 0,
926 const Standard_Boolean isComponent = Standard_False)
928 // skip already processed shapes
929 if ( ! Map.Add ( S ) ) return;
931 // check if shape has its own style (r inherits from ancestor)
933 if ( inherit ) style = *inherit;
934 if ( settings.IsBound(S) ) {
935 XCAFPrs_Style own = settings.Find(S);
936 if ( !own.IsVisible() ) style.SetVisibility ( Standard_False );
937 if ( own.IsSetColorCurv() ) style.SetColorCurv ( own.GetColorCurv() );
938 if ( own.IsSetColorSurf() ) style.SetColorSurf ( own.GetColorSurf() );
941 // translate colors to STEP
942 Handle(StepVisual_Colour) surfColor, curvColor;
943 if ( style.IsSetColorSurf() )
944 surfColor = Styles.EncodeColor(style.GetColorSurf(),DPDCs,ColRGBs);
945 if ( style.IsSetColorCurv() )
946 curvColor = Styles.EncodeColor(style.GetColorCurv(),DPDCs,ColRGBs);
948 Standard_Boolean hasOwn = ( ! surfColor.IsNull() ||
949 ! curvColor.IsNull() ||
950 ! style.IsVisible() );
952 // find target item and assign style to it
953 Handle(StepVisual_StyledItem) STEPstyle = override;
955 if ( S.ShapeType() != TopAbs_COMPOUND || isComponent ) { // skip compounds, let subshapes inherit its colors
957 TColStd_SequenceOfTransient seqRI;
958 Standard_Integer nb = FindEntities ( Styles.FinderProcess(), S, L, seqRI );
960 if ( nb <=0 ) cout << "Warning: Cannot find RI for " << S.TShape()->DynamicType()->Name() << endl;
962 //Get overridden style gka 10.06.03
963 if ( isComponent && nb)
964 getStyledItem(S, CTool->ShapeTool(), Styles, override,myMapCompMDGPR);
967 for ( Standard_Integer i=1; i <= nb; i++ ) {
968 Handle(StepRepr_RepresentationItem) item =
969 Handle(StepRepr_RepresentationItem)::DownCast(seqRI(i));
970 Handle(StepVisual_PresentationStyleAssignment) PSA;
971 if ( style.IsVisible() || !surfColor.IsNull() || !curvColor.IsNull() ) {
972 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
975 // default white color
976 surfColor = Styles.EncodeColor(Quantity_Color(1,1,1,Quantity_TOC_RGB),DPDCs,ColRGBs);
977 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
979 setDefaultInstanceColor( override, PSA);
981 } // end of component case
983 STEPstyle = Styles.AddStyle ( item, PSA, override );
984 hasOwn = Standard_False;
989 // iterate on subshapes (except vertices :)
990 if ( S.ShapeType() == TopAbs_EDGE ) return;
991 if ( !isComponent ) // PTV 10.02.2003
992 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
993 MakeSTEPStyles ( Styles, it.Value(), settings, STEPstyle,
994 Map, myMapCompMDGPR, DPDCs, ColRGBs, CTool,
995 ( hasOwn ? &style : 0 ) );
1000 static Standard_Boolean getFatherColor (const TDF_Label& L,
1001 const Handle(XCAFDoc_ColorTool)& CTool,
1002 XCAFPrs_Style& style)
1004 Standard_Boolean done = Standard_False;
1005 TopoDS_Shape aSh = CTool->ShapeTool()->GetShape( L );
1006 TDF_Label aFL = CTool->ShapeTool()->FindShape( aSh );
1007 if (aFL.IsNull() || aFL == L)
1010 if ( CTool->GetColor ( aFL, XCAFDoc_ColorGen, C ) ) {
1011 style.SetColorCurv ( C );
1012 style.SetColorSurf ( C );
1013 done = Standard_True;
1015 if ( CTool->GetColor ( aFL, XCAFDoc_ColorSurf, C ) ) {
1016 style.SetColorSurf ( C );
1017 done = Standard_True;
1019 if ( CTool->GetColor ( aFL, XCAFDoc_ColorCurv, C ) ) {
1020 style.SetColorCurv ( C );
1021 done = Standard_True;
1029 //=======================================================================
1030 //function : WriteColors
1032 //=======================================================================
1034 Standard_Boolean STEPCAFControl_Writer::WriteColors (const Handle(XSControl_WorkSession) &WS,
1035 const TDF_LabelSequence &labels)
1037 if ( labels.Length() <=0 ) return Standard_False;
1039 // Iterate on shapes in the document
1040 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1041 if ( CTool.IsNull() ) return Standard_False;
1043 STEPConstruct_Styles Styles ( WS );
1044 STEPConstruct_DataMapOfAsciiStringTransient DPDCs;
1045 STEPConstruct_DataMapOfPointTransient ColRGBs;
1046 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1047 TDF_Label L = labels.Value(i);
1049 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1050 // Skip assemblies: colors assigned to assemblies and their instances
1051 // are not supported (it is not clear how to encode that in STEP)
1052 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1054 cout << "Warning: Cannot write color for Assembly" << endl;
1055 cout << "Info: Check for colors assigned to components in assembly" << endl;
1057 // PTV 22.01.2003 Write color for instances.
1058 TDF_LabelSequence compLabels;
1059 if ( aSTool.IsNull() )
1061 if (!aSTool->GetComponents(L, compLabels))
1063 WriteColors(WS, compLabels);
1066 Styles.ClearStyles();
1068 // get a target shape and try to find corresponding context
1069 // (all the colors set under that label will be put into that context)
1071 if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1072 Standard_Boolean isComponent = aSTool->IsComponent( L );
1073 TopoDS_Shape aTopSh = S;
1074 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext ( S );
1075 if ( isComponent ) {
1076 TDF_Label aTopShL = aSTool->FindShape(S, Standard_False);
1077 if (aTopShL.IsNull())
1079 aTopSh = aSTool->GetShape( aTopShL );
1080 Context = Styles.FindContext ( aTopSh );
1082 if ( Context.IsNull() )
1085 // collect settings set on that label
1086 XCAFPrs_DataMapOfShapeStyle settings;
1087 TDF_LabelSequence seq;
1089 XCAFDoc_ShapeTool::GetSubShapes ( L, seq );
1090 Standard_Boolean isVisible = Standard_True;
1091 for ( Standard_Integer j = 1; j <= seq.Length(); j++ ) {
1092 TDF_Label lab = seq.Value(j);
1093 XCAFPrs_Style style;
1096 // check for invisible status of object on label
1097 if ( !CTool->IsVisible( lab ) ) {
1098 isVisible = Standard_False;
1099 style.SetVisibility( Standard_False );
1102 if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) {
1103 style.SetColorCurv ( C );
1104 style.SetColorSurf ( C );
1106 if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) )
1107 style.SetColorSurf ( C );
1108 if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) )
1109 style.SetColorCurv ( C );
1111 // commented, cause we are need to take reference from
1112 // if ( isComponent && lab == L && !isVisible)
1113 // if ( !style.IsSetColorSurf() && !style.IsSetColorCurv() ) {
1114 // getFatherColor ( L, CTool, style);
1116 if ( ! style.IsSetColorCurv() && ! style.IsSetColorSurf() && isVisible ) continue;
1118 TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab );
1119 settings.Bind ( sub, style );
1122 if ( settings.Extent() <=0 ) continue;
1124 // iterate on subshapes and create STEP styles
1125 Handle(StepVisual_StyledItem) override;
1126 TopTools_MapOfShape Map;
1128 MakeSTEPStyles(Styles,S,settings,override,Map,myMapCompMDGPR,DPDCs,ColRGBs,CTool,0,isComponent);
1130 // create MDGPR and record it in model
1131 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1134 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1136 cerr << "Error: Current Top-Level shape have MDGPR already " << endl;
1139 Styles.CreateMDGPR ( Context, aMDGPR );
1140 if (!aMDGPR.IsNull())
1141 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1144 // create SDR and add to model.
1145 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1146 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1147 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1148 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1149 if ( FP->FindTypedTransient(mapper,
1150 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1152 // create SDR for NAUO
1153 Handle(StepRepr_ProductDefinitionShape) nullPDS; // important to be NULL
1154 Styles.CreateNAUOSRD( Context, CDSR, nullPDS );
1156 // search for MDGPR of the component top-level shape
1157 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1158 aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1160 aMDGPR = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
1161 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
1162 aMDGPR->SetName( ReprName );
1163 aMDGPR->SetContextOfItems( Context );
1164 myMapCompMDGPR.Bind ( aTopSh, aMDGPR );
1166 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1167 Standard_Integer oldLengthlen = 0;
1168 if (!oldItems.IsNull())
1169 oldLengthlen = oldItems->Length();
1170 const Standard_Integer nbIt = oldLengthlen + Styles.NbStyles();
1173 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1174 new StepRepr_HArray1OfRepresentationItem(1, nbIt);
1175 Standard_Integer si;
1176 Standard_Integer el = 1;
1177 for ( si=1; si <= oldLengthlen; si++ )
1178 newItems->SetValue( el++, oldItems->Value( si ) );
1179 for ( si=1; si <= Styles.NbStyles(); si++ ) {
1180 newItems->SetValue( el++, Handle(StepRepr_RepresentationItem)::DownCast(Styles.Style(si)));
1181 // WP->Model()->AddWithRefs ( Handle(StepRepr_RepresentationItem)::DownCast (Styles.Style(si)));
1184 if (newItems->Length() > 0)
1185 aMDGPR->SetItems( newItems );
1186 } //end of work with CDSR
1189 // create invisibility item and refer for stiledItem
1190 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1191 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1192 new StepVisual_HArray1OfInvisibleItem (1,Styles.NbStyles());
1193 // put all style item into the harray
1194 for ( Standard_Integer si=1; si <= Styles.NbStyles(); si++ ) {
1195 Handle(StepRepr_RepresentationItem) styledItm =
1196 Handle(StepRepr_RepresentationItem)::DownCast(Styles.Style(si));
1197 StepVisual_InvisibleItem anInvItem;
1198 anInvItem.SetValue( styledItm );
1199 HInvsblItm->SetValue( si, anInvItem );
1201 // set the invisibility of items
1202 Invsblt->Init( HInvsblItm );
1203 WS->Model()->AddWithRefs( Invsblt );
1207 return Standard_True;
1211 //=======================================================================
1212 //function : WriteNames
1214 //=======================================================================
1216 Standard_Boolean STEPCAFControl_Writer::WriteNames (const Handle(XSControl_WorkSession) &WS,
1217 const TDF_LabelSequence &labels) const
1219 if ( labels.Length() <=0 ) return Standard_False;
1222 Handle(Interface_InterfaceModel) Model = WS->Model();
1223 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1224 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1225 // Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1226 // if ( STool.IsNull() ) return Standard_False;
1228 // Iterate on requested shapes
1229 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1230 TDF_Label L = labels.Value(i);
1233 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1234 if ( ! GetLabelName (L, hName) ) continue;
1235 // Handle(TDataStd_Name) N;
1236 // if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) continue;
1237 // TCollection_ExtendedString name = N->Get();
1238 // if ( name.Length() <=0 ) continue;
1240 // find target STEP entity for the current shape
1242 // if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1243 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1244 TopoDS_Shape S = myLabels.Find ( L );
1246 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
1247 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1248 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
1250 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
1255 // set the name to the PRODUCT
1256 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
1257 if ( PropD.IsNull() ) continue;
1258 Handle(StepBasic_ProductDefinition) PD = PropD->Definition().ProductDefinition();
1259 if ( PD.IsNull() ) continue;
1260 Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
1262 Prod->SetId ( hName );
1263 Prod->SetName ( hName );
1265 // write names for components of assemblies
1266 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1267 TDF_LabelSequence seq;
1268 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1269 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1270 TDF_Label lab = seq(k);
1272 // get shape with correct location
1274 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1275 ! myLabels.IsBound ( Lref ) ) continue;
1276 S = myLabels.Find ( Lref );
1277 S.Move ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
1279 hName = new TCollection_HAsciiString;
1280 if ( ! GetLabelName (lab, hName) ) continue;
1282 // find the target CDSR corresponding to a shape
1283 mapper = TransferBRep::ShapeMapper ( FP, S );
1284 Handle(Transfer_Binder) binder = FP->Find ( mapper );
1285 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1286 if ( ! FP->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), CDSR) )
1288 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1289 Handle(StepBasic_ProductDefinitionRelationship) NAUO = PDS->Definition().ProductDefinitionRelationship();
1290 if ( ! NAUO.IsNull() ) NAUO->SetName ( hName );
1295 return Standard_True;
1299 //=======================================================================
1300 //function : WritePropsForLabel
1302 //=======================================================================
1303 static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession) &WS,
1304 const Handle(XCAFDoc_ShapeTool) &aSTool,
1305 const STEPCAFControl_DataMapOfLabelShape &myLabels,
1307 const Standard_CString multi)
1309 if(L.IsNull()) return Standard_False;
1311 STEPConstruct_ValidationProps Props ( WS );
1313 TopoDS_Shape S = aSTool->GetShape(L);
1314 if(S.IsNull()) return Standard_False;
1316 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1318 Handle(XCAFDoc_Area) A;
1319 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1320 if ( ! A.IsNull() ) {
1321 Props.AddArea ( S, A->Get() );
1324 Handle(XCAFDoc_Volume) V;
1325 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1326 if ( ! V.IsNull() ) {
1327 Props.AddVolume ( S, V->Get() );
1331 Handle(XCAFDoc_Centroid) C;
1332 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1333 if ( ! C.IsNull() ) {
1334 Props.AddCentroid ( S, C->Get() );
1337 if( XCAFDoc_ShapeTool::IsCompound(L) || XCAFDoc_ShapeTool::IsAssembly(L) ) {
1339 for(Standard_Integer ich=1; ich<=L.NbChildren(); ich++) {
1340 WritePropsForLabel(WS,aSTool,myLabels,L.FindChild(ich),multi);
1345 return Standard_True;
1349 //=======================================================================
1350 //function : WriteValProps
1352 //=======================================================================
1354 Standard_Boolean STEPCAFControl_Writer::WriteValProps (const Handle(XSControl_WorkSession) &WS,
1355 const TDF_LabelSequence &labels,
1356 const Standard_CString multi) const
1358 if ( labels.Length() <=0 ) return Standard_False;
1361 // STEPConstruct_ValidationProps Props ( WS );
1362 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1364 // Iterate on requested shapes
1365 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1366 TDF_Label L = labels.Value(i);
1368 WritePropsForLabel(WS,aSTool,myLabels,L,multi);
1370 // find target STEP entity for the current shape
1371 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1372 TopoDS_Shape S = myLabels.Find ( L );
1374 // write area and volume (except for components in multifile mode)
1375 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1376 Handle(XCAFDoc_Area) A;
1377 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1378 if ( ! A.IsNull() ) Props.AddArea ( S, A->Get() );
1380 Handle(XCAFDoc_Volume) V;
1381 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1382 if ( ! V.IsNull() ) Props.AddVolume ( S, V->Get() );
1386 Handle(XCAFDoc_Centroid) C;
1387 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1388 if ( ! C.IsNull() ) Props.AddCentroid ( S, C->Get() );
1390 // write centroid for components of assemblies
1391 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1392 TDF_LabelSequence seq;
1393 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1394 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1395 TDF_Label lab = seq(k);
1397 // get shape with correct location
1399 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1400 ! myLabels.IsBound ( Lref ) ) continue;
1401 TopLoc_Location Loc = XCAFDoc_ShapeTool::GetLocation ( lab );
1402 S = myLabels.Find ( Lref );
1406 lab.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1407 // if centroid is not assigned to an instance,
1408 // use (shifted) centroid of original shape
1411 Lref.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1412 if ( C.IsNull() ) continue;
1413 center = C->Get().Transformed ( Loc.Transformation() );
1415 else center = C->Get();
1417 Props.AddCentroid ( S, center, Standard_True );
1423 return Standard_True;
1427 //=======================================================================
1428 //function : WriteLayers
1430 //=======================================================================
1432 Standard_Boolean STEPCAFControl_Writer::WriteLayers (const Handle(XSControl_WorkSession) &WS,
1433 const TDF_LabelSequence &labels ) const
1436 if ( labels.Length() <=0 ) return Standard_False;
1439 Handle(Interface_InterfaceModel) Model = WS->Model();
1440 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1441 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1442 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( labels(1) );
1443 if (LTool.IsNull() ) return Standard_False;
1445 TDF_LabelSequence LayerLS;
1446 LTool->GetLayerLabels(LayerLS);
1447 if ( LayerLS.Length() <=0 ) return Standard_False;
1449 // Iterate on requested layers and for each layer take set of shapes.
1450 for ( Standard_Integer i=1; i <= LayerLS.Length(); i++ ) {
1451 TDF_Label L = LayerLS.Value(i);
1453 // get labels of shapes in that layer
1454 TDF_LabelSequence ShapeLs;
1455 LTool->GetShapesOfLayer(L, ShapeLs);
1456 if ( ShapeLs.Length() <=0 ) continue;
1458 // name of layer: if not set, is considered as being empty
1459 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1460 GetLabelName ( L, hName );
1462 // Find target STEP entity for each shape and add to StepVisual_PresentationLayerAssignment items.
1463 TColStd_SequenceOfTransient seqRI;
1464 for ( Standard_Integer j=1; j <= ShapeLs.Length(); j++) {
1465 TDF_Label shLabel = ShapeLs.Value(j);
1466 if ( shLabel.IsNull() ) continue;
1468 // there is no way to assign layer to instance in STEP
1469 if ( XCAFDoc_ShapeTool::IsAssembly ( shLabel ) ||
1470 XCAFDoc_ShapeTool::IsReference ( shLabel ) )
1473 // check that the shape is one of (uub)labels written during current transfer
1474 Standard_Integer k = 1;
1475 for ( ; k <= labels.Length(); k++ )
1476 if ( shLabel.IsDescendant ( labels(k) ) ) break;
1477 if ( k > labels.Length() ) continue;
1479 // get target STEP entity
1480 TopoDS_Shape oneShape = XCAFDoc_ShapeTool::GetShape(shLabel);
1482 TopLoc_Location Loc;
1483 Standard_Integer nb =
1484 FindEntities ( FP, oneShape, Loc, seqRI );
1486 FP->Messenger() << "Warning: Cannot find RI for " << oneShape.TShape()->DynamicType()->Name() << endl;
1488 if ( seqRI.Length() <= 0 ) continue;
1490 // analyze visibility
1491 Handle(StepVisual_PresentationLayerAssignment) StepLayerAs = new StepVisual_PresentationLayerAssignment;
1492 Handle(TCollection_HAsciiString) descr;
1493 Handle(TDataStd_UAttribute) aUAttr;
1494 Standard_Boolean isLinv = Standard_False;
1495 if (L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr)) {
1496 descr = new TCollection_HAsciiString ("invisible");
1498 FP->Messenger() << "\tLayer \"" << hName->String().ToCString() << "\" is invisible"<<endl;
1500 isLinv = Standard_True;
1502 else descr = new TCollection_HAsciiString ("visible");
1504 // create layer entity
1505 Handle(StepVisual_HArray1OfLayeredItem) HArrayOfLItem =
1506 new StepVisual_HArray1OfLayeredItem ( 1, seqRI.Length() );
1507 for (Standard_Integer i1 = 1; i1<=seqRI.Length(); i1++) {
1508 StepVisual_LayeredItem LI;
1509 LI.SetValue ( seqRI.Value(i1) );
1510 HArrayOfLItem->SetValue( i1, LI );
1512 StepLayerAs->Init(hName, descr, HArrayOfLItem);
1513 Model->AddWithRefs( StepLayerAs );
1514 // PTV 23.01.2003 add the invisibility AFTER adding layer into the model.
1515 // add the invisibility for the layer
1517 // Invisibility Item for containig invisible layers.
1518 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm = new StepVisual_HArray1OfInvisibleItem (1,1);
1519 StepVisual_InvisibleItem InvIt;
1520 InvIt.SetValue( StepLayerAs );
1521 HInvsblItm->SetValue( 1, InvIt);
1523 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1524 Invsblt->Init( HInvsblItm );
1525 Model->AddWithRefs( Invsblt );
1528 return Standard_True;
1532 //=======================================================================
1533 //function : getSHUOstyle
1534 //purpose : auxilary
1535 //=======================================================================
1536 static Standard_Boolean getSHUOstyle(const TDF_Label& aSHUOlab,
1537 const Handle(XCAFDoc_ColorTool)& CTool,
1538 XCAFPrs_Style& SHUOstyle)
1541 if (!CTool->IsVisible( aSHUOlab ) )
1542 SHUOstyle.SetVisibility(Standard_False);
1544 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) {
1545 SHUOstyle.SetColorCurv ( C );
1546 SHUOstyle.SetColorSurf ( C );
1548 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) )
1549 SHUOstyle.SetColorSurf ( C );
1550 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) )
1551 SHUOstyle.SetColorCurv ( C );
1553 if ( !SHUOstyle.IsSetColorCurv() &&
1554 !SHUOstyle.IsSetColorSurf() &&
1555 SHUOstyle.IsVisible() )
1556 return Standard_False;
1557 return Standard_True;
1561 //=======================================================================
1562 //function : getProDefinitionOfNAUO
1563 //purpose : auxilary
1564 //=======================================================================
1565 static Standard_Boolean getProDefinitionOfNAUO(const Handle(XSControl_WorkSession)& WS,
1566 const TopoDS_Shape& theShape,
1567 Handle(StepBasic_ProductDefinition)& PD,
1568 Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO,
1569 Standard_Boolean IsRelating)
1571 if ( theShape.IsNull() )
1572 return Standard_False;
1574 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1575 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1576 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1577 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, theShape );
1578 if (!FP->FindTypedTransient(mapper,
1579 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1581 return Standard_False;
1583 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1585 return Standard_False;
1586 // get the NAUO entity
1587 Interface_Graph aGraph = WS->HGraph()->Graph();
1588 Interface_EntityIterator subs = aGraph.Shareds(PDS);
1589 for ( subs.Start(); subs.More(); subs.Next() ) {
1590 if (!subs.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)))
1592 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value());
1595 if ( NAUO.IsNull() )
1596 return Standard_False;
1597 // get Relatinf or Related product definition
1599 PD = NAUO->RelatedProductDefinition();
1601 PD = NAUO->RelatingProductDefinition();
1603 return Standard_False;
1604 return Standard_True;
1608 //=======================================================================
1609 //function : writeSHUO
1610 //purpose : auxilary
1611 //=======================================================================
1612 static Standard_Boolean writeSHUO (const Handle(XCAFDoc_GraphNode)& theSHUO,
1613 const Handle(XCAFDoc_ShapeTool)& theSTool,
1614 const Handle(XSControl_WorkSession)& WS,
1615 Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO,
1616 TopoDS_Shape& NAUOShape,
1617 Handle(StepBasic_ProductDefinition)& theRelatingPD,
1618 Standard_Boolean& isDeepest)
1620 // set the ProductDefinitionRelationship descriptin information as empty strings.
1621 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
1623 TDF_LabelSequence aNextUsageLabs;
1624 theSTool->GetSHUONextUsage( theSHUO->Label(), aNextUsageLabs );
1625 Handle(XCAFDoc_GraphNode) NuSHUO;
1626 if ( theTopSHUO.IsNull() ) {
1628 if (aNextUsageLabs.Length() < 1)
1629 return Standard_False;
1630 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1631 if (NuSHUO.IsNull())
1632 return Standard_False;
1633 // get relating product definition
1634 TopoDS_Shape aTopCompShape = theSTool->GetShape( theSHUO->Label().Father() );
1635 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO;
1636 if (!getProDefinitionOfNAUO( WS, aTopCompShape,
1637 theRelatingPD, UUNAUO, Standard_True ))
1638 return Standard_False;
1639 // get related product definition
1640 TopoDS_Shape aNUShape = theSTool->GetShape( NuSHUO->Label().Father() );
1641 Handle(StepBasic_ProductDefinition) aRelatedPD;
1642 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO;
1643 if (!getProDefinitionOfNAUO( WS, aNUShape,
1644 aRelatedPD, NUNAUO, Standard_False ))
1645 return Standard_False;
1647 theTopSHUO = new StepRepr_SpecifiedHigherUsageOccurrence;
1648 // create deepest shuo EmptyString
1649 theTopSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1650 /*no description*/Standard_False,/*description*/EmptyString,
1651 theRelatingPD, aRelatedPD,
1652 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1653 /*upper_usage*/UUNAUO, /*next_usage*/NUNAUO);
1654 // write the other SHUO.
1655 if(!writeSHUO( NuSHUO, theSTool, WS, theTopSHUO, NAUOShape, theRelatingPD, isDeepest )) {
1656 theTopSHUO.Nullify();
1657 return Standard_False;
1660 return Standard_True;
1662 // Handle(XCAFDoc_GraphNode) NuSHUO;
1663 if ( aNextUsageLabs.Length() > 0) {
1664 // store SHUO recursive
1666 if ( aNextUsageLabs.Length() > 1 )
1667 cout << "Warning: store only one next_usage of current SHUO" << endl;
1669 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1670 Handle(StepRepr_SpecifiedHigherUsageOccurrence) aNUEntSHUO =
1671 new StepRepr_SpecifiedHigherUsageOccurrence;
1672 if (!writeSHUO( NuSHUO, theSTool, WS, aNUEntSHUO, NAUOShape, theRelatingPD, isDeepest ))
1673 return Standard_False;
1675 // store the deepest SHUO to the dociment
1676 TopoDS_Shape aNUSh, aUUSh;
1677 aNUSh = theSTool->GetShape( NuSHUO->Label().Father() );
1678 aUUSh = theSTool->GetShape( theSHUO->Label().Father() );
1679 // get relating PD with upper_usage and related PD with next_usage
1680 Handle(StepBasic_ProductDefinition) nullPD;// no need to use,case have shared <theRelatingPD>
1681 Handle(StepBasic_ProductDefinition) aRelatedPD;
1682 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO, NUNAUO;
1683 if (!getProDefinitionOfNAUO( WS, aUUSh, nullPD, UUNAUO, Standard_True ) ||
1684 !getProDefinitionOfNAUO( WS, aNUSh, aRelatedPD, NUNAUO, Standard_False )) {
1686 cout << "Warning: cannot get related or relating PD" << endl;
1688 return Standard_False;
1690 aNUEntSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1691 /*no description*/Standard_False,/*description*/EmptyString,
1692 theRelatingPD, aRelatedPD,
1693 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1694 /*upper_usage*/theTopSHUO, /*next_usage*/NUNAUO);
1696 isDeepest = Standard_False;
1698 WS->Model()->AddWithRefs ( aNUEntSHUO );
1699 return Standard_True;
1700 } // end of recurse storing
1703 TDF_Label aShapeL = theSHUO->Label().Father();
1704 NAUOShape = theSTool->GetShape( aShapeL );
1705 // return to the deepest level from SHUO shape level
1706 // it is because SHUO is attribute on deep level and shape level.
1707 isDeepest = Standard_True;
1708 return Standard_True;
1712 //=======================================================================
1713 //function : createSHUOStyledItem
1714 //purpose : auxilary
1715 //=======================================================================
1716 static Standard_Boolean createSHUOStyledItem (const XCAFPrs_Style& style,
1717 const Handle(StepRepr_ProductDefinitionShape)& PDS,
1718 const Handle(XSControl_WorkSession) &WS,
1719 const TopoDS_Shape& Sh,
1720 const Handle(XCAFDoc_ShapeTool)& STool,
1721 MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
1723 // create styled item for the indicated SHUO and store to the model
1724 STEPConstruct_Styles Styles( WS );
1725 // translate colors to STEP
1726 Handle(StepVisual_Colour) surfColor, curvColor;
1727 if ( style.IsSetColorSurf() )
1728 surfColor = Styles.EncodeColor ( style.GetColorSurf() );
1729 if ( style.IsSetColorCurv() )
1730 curvColor = Styles.EncodeColor ( style.GetColorCurv() );
1731 Standard_Boolean isComponent = Standard_True;// cause need to get PSBC
1732 Handle(StepRepr_RepresentationItem) item;
1733 // set default color for invisible SHUO.
1734 Standard_Boolean isSetDefaultColor = Standard_False;
1735 if (surfColor.IsNull() && curvColor.IsNull() && !style.IsVisible() ) {
1736 surfColor = Styles.EncodeColor ( Quantity_Color( 1, 1, 1, Quantity_TOC_RGB ) );
1737 isSetDefaultColor = Standard_True;
1739 Handle(StepVisual_PresentationStyleAssignment) PSA =
1740 Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1741 Handle(StepVisual_StyledItem) override; //null styled item
1743 // find the repr item of the shape
1744 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1745 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1746 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, Sh );
1747 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1748 FP->FindTypedTransient(mapper,
1749 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1751 if ( CDSR.IsNull() )
1752 return Standard_False;
1754 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext( Sh );
1755 TopoDS_Shape aTopSh = Sh;
1756 if (Context.IsNull()) {
1757 TDF_Label aTopShL = STool->FindShape(Sh, Standard_False);
1758 if (aTopShL.IsNull())
1759 return Standard_False;
1760 aTopSh = STool->GetShape( aTopShL );
1761 Context = Styles.FindContext ( aTopSh );
1763 if (Context.IsNull())
1764 return Standard_False;
1765 // get representation item of the shape
1767 TColStd_SequenceOfTransient seqRI;
1768 FindEntities ( FP, Sh, L, seqRI );
1770 if ( seqRI.Length() <=0 )
1771 FP->Messenger() << "Warning: Cannot find RI for " << Sh.TShape()->DynamicType()->Name() << endl;
1773 item = Handle(StepRepr_RepresentationItem)::DownCast(seqRI(1));
1774 //get overridden styled item
1775 getStyledItem(Sh,STool, Styles, override,myMapCompMDGPR);
1777 // get STEP STYLED ITEM
1778 Handle(StepVisual_StyledItem) STEPstyle = Styles.AddStyle ( item, PSA, override );
1779 // create SR, SDR and all necessary references between them and ST, PDS, PSBC, GRC
1780 Styles.CreateNAUOSRD( Context, CDSR, PDS );
1782 // add step styled item of SHUO to the model
1783 // do it by additing styled item to the MDGPR
1784 if ( !aTopSh.IsNull() && !myMapCompMDGPR.IsBound( aTopSh ) ) {
1785 // create MDGPR and record it in model
1787 cout << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance" << endl;
1789 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1790 Styles.CreateMDGPR ( Context, aMDGPR );
1791 if (!aMDGPR.IsNull())
1792 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1794 else if ( !aTopSh.IsNull() && myMapCompMDGPR.IsBound( aTopSh ) ) {
1795 // get MDGPR of the top-level shape
1796 Handle(StepVisual_PresentationRepresentation) aMDGPR =
1797 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1798 // get old styled items to not lose it
1799 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1800 Standard_Integer oldLengthlen = 0;
1801 if (!oldItems.IsNull())
1802 oldLengthlen = oldItems->Length();
1803 // create new array of styled items by an olds and new one
1804 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1805 new StepRepr_HArray1OfRepresentationItem(1, oldLengthlen + 1);
1806 Standard_Integer si;
1807 Standard_Integer el = 1;
1808 for ( si=1; si <= oldLengthlen; si++ )
1809 newItems->SetValue( el++, oldItems->Value( si ) );
1810 newItems->SetValue( el++, Handle(StepRepr_RepresentationItem)::DownCast(STEPstyle) );
1811 // init MDGPR be new array of styled items
1812 if (newItems->Length() > 0)
1813 aMDGPR->SetItems( newItems );
1816 WS->Model()->AddWithRefs ( STEPstyle ); // add as root to the model, but it is not good
1818 cout << "Warning: " << __FILE__ << ": adds styled item of SHUO as root, casue cannot find MDGPR" << endl;
1821 // create invisibility item for the styled item
1822 if ( !style.IsVisible() ) {
1823 if (isSetDefaultColor) {
1824 // try to set default color from top-level shape
1826 setDefaultInstanceColor(override, PSA);
1828 // create invisibility item and refer for stiledItem
1829 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1830 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1831 new StepVisual_HArray1OfInvisibleItem (1,1);
1832 // put all style item into the harray
1833 StepVisual_InvisibleItem anInvItem;
1834 anInvItem.SetValue( STEPstyle );
1835 HInvsblItm->SetValue( 1, anInvItem );
1836 Invsblt->Init( HInvsblItm );
1837 WS->Model()->AddWithRefs( Invsblt );
1840 return Standard_True;
1844 //=======================================================================
1845 //function : WriteSHUOs
1847 //=======================================================================
1849 Standard_Boolean STEPCAFControl_Writer::WriteSHUOs (const Handle(XSControl_WorkSession) &WS,
1850 const TDF_LabelSequence &labels )
1852 if ( labels.Length() <=0 ) return Standard_False;
1855 Handle(Interface_InterfaceModel) Model = WS->Model();
1856 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1857 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1858 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1859 if (CTool.IsNull() )
1860 return Standard_False;
1861 // map of transfered SHUO
1862 TColStd_MapOfTransient aMapOfMainSHUO;
1863 // TColStd_IndexedDataMapOfTransientTransient aIndxMapOfSHUOEnt;
1864 // Iterate on requested shapes
1865 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1866 TDF_Label L = labels.Value(i);
1867 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1868 // TopoDS_Shape S = myLabels.Find ( L );
1869 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1870 TDF_LabelSequence seq;
1871 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1872 // iterates on components of assembly
1873 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1874 TDF_Label lab = seq(k);
1875 TDF_AttributeSequence anAttrSeq;
1876 CTool->ShapeTool()->GetAllComponentSHUO( lab, anAttrSeq );
1878 for (Standard_Integer j = 1; j <= anAttrSeq.Length(); j++) {
1879 Handle(XCAFDoc_GraphNode) aSHUO =
1880 Handle(XCAFDoc_GraphNode)::DownCast(anAttrSeq.Value( j ));
1881 // take label of SHUO
1882 TDF_Label aSHUOlab = aSHUO->Label();
1883 TDF_LabelSequence aUpLabels;
1884 // check is it SHUO of upper_usage
1885 CTool->ShapeTool()->GetSHUOUpperUsage( aSHUOlab, aUpLabels );
1886 if ( aUpLabels.Length() > 0 )
1887 continue; // transfer only main SHUO
1888 if ( aMapOfMainSHUO.Contains( aSHUO ) )
1889 continue; // do not try to transfer SHUO twice
1890 aMapOfMainSHUO.Add( aSHUO );
1891 // check if it is styled SHUO
1892 XCAFPrs_Style SHUOstyle;
1893 if ( !getSHUOstyle ( aSHUOlab, CTool, SHUOstyle ) ) {
1895 cout << "Warning: " << __FILE__ << ": do not store SHUO without any style to the STEP model" << endl;
1899 // write SHUO to the model amd then add structure type.
1900 TopoDS_Shape NAUOShape; // shape of the deepest NAUO in the SHUO structure
1901 Standard_Boolean isDeepest = Standard_False;
1902 Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO;
1903 Handle(StepBasic_ProductDefinition) aRelatingPD;
1904 // create the top SHUO and all other.
1905 writeSHUO( aSHUO, CTool->ShapeTool(), WS, anEntOfSHUO, NAUOShape, aRelatingPD, isDeepest );
1906 if ( anEntOfSHUO.IsNull() || NAUOShape.IsNull() ) {
1908 cout << "Warning: " << __FILE__ << ": Cannot store SHUO" << endl;
1912 // create new Product Definition Shape for TOP SHUO
1914 cout << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO " << endl;
1916 Handle(StepRepr_ProductDefinitionShape) PDS = new StepRepr_ProductDefinitionShape;
1917 Handle(TCollection_HAsciiString) aPDSname = new TCollection_HAsciiString("SHUO");
1918 Handle(TCollection_HAsciiString) descrStr = new TCollection_HAsciiString("");
1919 StepRepr_CharacterizedDefinition aCharDef;
1920 aCharDef.SetValue( anEntOfSHUO );
1921 PDS->Init( aPDSname, Standard_False, descrStr, aCharDef );
1923 // create styled item for SHUO and add to the model
1924 createSHUOStyledItem ( SHUOstyle, PDS, WS, NAUOShape, CTool->ShapeTool(), myMapCompMDGPR );
1926 } // end work with SHUO
1927 } // end of an assembly components
1928 } // end of IsAssembly case
1929 // nothing to do if it is not assembly
1931 } // end of iterates on indicated labels
1932 return Standard_True;
1936 //=======================================================================
1937 //function : FindPDSforDGT
1938 //purpose : auxilary: find PDS for AdvancedFace or EdgeCurve for creation
1939 // needed ShapeAspect in D> structure
1940 //=======================================================================
1941 static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph,
1942 const Handle(Standard_Transient) &ent,
1943 Handle(StepRepr_ProductDefinitionShape) &PDS,
1944 Handle(StepRepr_RepresentationContext) &RC,
1945 Handle(StepShape_AdvancedFace) &AF,
1946 Handle(StepShape_EdgeCurve) &EC)
1948 if( !ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) &&
1949 !ent->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)) )
1950 return Standard_False;
1952 AF = Handle(StepShape_AdvancedFace)::DownCast(ent);
1953 if( ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) ) {
1954 EC = Handle(StepShape_EdgeCurve)::DownCast(ent);
1955 Interface_EntityIterator subs = aGraph.Sharings(EC);
1956 for(subs.Start(); subs.More() && AF.IsNull(); subs.Next()) {
1957 Handle(StepShape_OrientedEdge) OE = Handle(StepShape_OrientedEdge)::DownCast(subs.Value());
1958 if(OE.IsNull()) continue;
1959 Interface_EntityIterator subs1 = aGraph.Sharings(OE);
1960 for(subs1.Start(); subs1.More() && AF.IsNull(); subs1.Next()) {
1961 Handle(StepShape_EdgeLoop) EL = Handle(StepShape_EdgeLoop)::DownCast(subs1.Value());
1962 if(EL.IsNull()) continue;
1963 Interface_EntityIterator subs2 = aGraph.Sharings(EL);
1964 for(subs2.Start(); subs2.More() && AF.IsNull(); subs2.Next()) {
1965 Handle(StepShape_FaceBound) FB = Handle(StepShape_FaceBound)::DownCast(subs2.Value());
1966 if(FB.IsNull()) continue;
1967 Interface_EntityIterator subs3 = aGraph.Sharings(FB);
1968 for(subs3.Start(); subs3.More() && AF.IsNull(); subs3.Next()) {
1969 AF = Handle(StepShape_AdvancedFace)::DownCast(subs3.Value());
1975 if(AF.IsNull()) return Standard_False;
1977 Interface_EntityIterator subs = aGraph.Sharings(AF);
1978 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
1979 Handle(StepShape_ConnectedFaceSet) CFS =
1980 Handle(StepShape_ConnectedFaceSet)::DownCast(subs.Value());
1981 if(CFS.IsNull()) continue;
1982 Interface_EntityIterator subs1 = aGraph.Sharings(CFS);
1983 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
1984 Handle(StepRepr_RepresentationItem) RI =
1985 Handle(StepRepr_RepresentationItem)::DownCast(subs1.Value());
1986 if(RI.IsNull()) continue;
1987 Interface_EntityIterator subs2 = aGraph.Sharings(RI);
1988 for(subs2.Start(); subs2.More() && PDS.IsNull(); subs2.Next()) {
1989 Handle(StepShape_ShapeRepresentation) SR =
1990 Handle(StepShape_ShapeRepresentation)::DownCast(subs2.Value());
1991 if(SR.IsNull()) continue;
1992 RC = SR->ContextOfItems();
1993 Interface_EntityIterator subs3 = aGraph.Sharings(SR);
1994 for(subs3.Start(); subs3.More() && PDS.IsNull(); subs3.Next()) {
1995 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1996 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs3.Value());
1997 if(SDR.IsNull()) continue;
1998 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
1999 if(PropD.IsNull()) continue;
2000 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
2006 return Standard_True;
2010 //=======================================================================
2011 //function : WriteDGTs
2013 //=======================================================================
2015 Standard_Boolean STEPCAFControl_Writer::WriteDGTs (const Handle(XSControl_WorkSession) &WS,
2016 const TDF_LabelSequence &labels ) const
2019 if ( labels.Length() <=0 ) return Standard_False;
2022 Handle(Interface_InterfaceModel) Model = WS->Model();
2023 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
2024 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
2026 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2027 if(aHGraph.IsNull())
2028 return Standard_False;
2030 Interface_Graph aGraph = aHGraph->Graph();
2031 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( labels(1) );
2032 if(DGTTool.IsNull() ) return Standard_False;
2034 TDF_LabelSequence DGTLabels;
2035 STEPConstruct_DataMapOfAsciiStringTransient DatumMap;
2038 DGTTool->GetDatumLabels(DGTLabels);
2039 if(DGTLabels.Length()<=0) return Standard_False;
2041 for(i=1; i<=DGTLabels.Length(); i++) {
2042 TDF_Label DatumL = DGTLabels.Value(i);
2043 TDF_LabelSequence ShapeL;
2044 if(!DGTTool->GetRefShapeLabel(DatumL,ShapeL)) continue;
2045 // find target shape
2046 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
2047 TopLoc_Location Loc;
2048 TColStd_SequenceOfTransient seqRI;
2049 FindEntities( FP, aShape, Loc, seqRI );
2050 if ( seqRI.Length() <= 0 ) {
2051 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
2054 Handle(StepRepr_ProductDefinitionShape) PDS;
2055 Handle(StepRepr_RepresentationContext) RC;
2056 Handle(Standard_Transient) ent = seqRI.Value(1);
2057 Handle(StepShape_AdvancedFace) AF;
2058 Handle(StepShape_EdgeCurve) EC;
2059 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
2060 if(PDS.IsNull()) continue;
2061 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
2062 Handle(XCAFDoc_Datum) DatumAttr;
2063 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
2064 Handle(TCollection_HAsciiString) aName = DatumAttr->GetName();
2065 Handle(TCollection_HAsciiString) aDescription = DatumAttr->GetDescription();
2066 Handle(TCollection_HAsciiString) anIdentification = DatumAttr->GetIdentification();
2067 Handle(StepDimTol_DatumFeature) DF = new StepDimTol_DatumFeature;
2068 Handle(StepDimTol_Datum) aDatum = new StepDimTol_Datum;
2069 DF->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
2070 Model->AddWithRefs(DF);
2071 aDatum->Init(aName, new TCollection_HAsciiString, PDS, StepData_LFalse, anIdentification);
2072 Model->AddWithRefs(aDatum);
2073 Handle(StepRepr_ShapeAspectRelationship) SAR = new StepRepr_ShapeAspectRelationship;
2074 SAR->SetName(aName);
2075 SAR->SetRelatingShapeAspect(DF);
2076 SAR->SetRelatedShapeAspect(aDatum);
2077 Model->AddWithRefs(SAR);
2078 // write chain for DatumFeature
2079 StepRepr_CharacterizedDefinition CD;
2081 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
2082 PropD->Init(aName,Standard_True,aDescription,CD);
2083 Model->AddWithRefs(PropD);
2084 StepRepr_RepresentedDefinition RD;
2086 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
2087 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
2088 new StepRepr_HArray1OfRepresentationItem(1,1);
2089 HARI->SetValue(1,AF);
2090 SR->Init(aName,HARI,RC);
2091 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
2093 Model->AddWithRefs(SDR);
2094 // write chain for Datum
2095 StepRepr_CharacterizedDefinition CD1;
2096 CD1.SetValue(aDatum);
2097 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
2098 PropD1->Init(aName,Standard_True,aDescription,CD1);
2099 Model->AddWithRefs(PropD1);
2100 StepRepr_RepresentedDefinition RD1;
2101 RD1.SetValue(PropD1);
2102 Handle(StepShape_ShapeRepresentation) SR1 = new StepShape_ShapeRepresentation;
2103 Handle(StepRepr_HArray1OfRepresentationItem) HARI1 =
2104 new StepRepr_HArray1OfRepresentationItem(1,1);
2105 HARI1->SetValue(1,AF->FaceGeometry());
2106 SR1->Init(aName,HARI1,RC);
2107 Model->AddWithRefs(SR1);
2108 Handle(StepShape_ShapeDefinitionRepresentation) SDR1 = new StepShape_ShapeDefinitionRepresentation;
2109 SDR1->Init(RD1,SR1);
2110 Model->AddWithRefs(SDR1);
2111 // add created Datum into Map
2112 TCollection_AsciiString stmp(aName->ToCString());
2113 stmp.AssignCat(aDescription->ToCString());
2114 stmp.AssignCat(anIdentification->ToCString());
2115 DatumMap.Bind(stmp,aDatum);
2118 // write Tolerances and Dimensions
2120 DGTTool->GetDimTolLabels(DGTLabels);
2121 if(DGTLabels.Length()<=0) return Standard_False;
2122 for(i=1; i<=DGTLabels.Length(); i++) {
2123 TDF_Label DimTolL = DGTLabels.Value(i);
2124 TDF_LabelSequence ShapeL;
2125 if(!DGTTool->GetRefShapeLabel(DimTolL,ShapeL)) continue;
2126 // find target shape
2127 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
2128 TopLoc_Location Loc;
2129 TColStd_SequenceOfTransient seqRI;
2130 FindEntities( FP, aShape, Loc, seqRI );
2131 if ( seqRI.Length() <= 0 ) {
2132 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
2135 Handle(StepRepr_ProductDefinitionShape) PDS;
2136 Handle(StepRepr_RepresentationContext) RC;
2137 Handle(Standard_Transient) ent = seqRI.Value(1);
2138 Handle(StepShape_AdvancedFace) AF;
2139 Handle(StepShape_EdgeCurve) EC;
2140 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
2141 if(PDS.IsNull()) continue;
2142 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
2144 Handle(XCAFDoc_DimTol) DimTolAttr;
2145 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) continue;
2146 Standard_Integer kind = DimTolAttr->GetKind();
2147 Handle(TColStd_HArray1OfReal) aVal = DimTolAttr->GetVal();
2148 Handle(TCollection_HAsciiString) aName = DimTolAttr->GetName();
2149 Handle(TCollection_HAsciiString) aDescription = DimTolAttr->GetDescription();
2151 // common part of writing D> entities
2152 StepRepr_CharacterizedDefinition CD;
2153 Handle(StepRepr_ShapeAspect) SA = new StepRepr_ShapeAspect;
2154 SA->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
2155 Model->AddWithRefs(SA);
2157 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
2158 PropD->Init(aName,Standard_True,aDescription,CD);
2159 Model->AddWithRefs(PropD);
2160 StepRepr_RepresentedDefinition RD;
2162 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
2163 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
2164 new StepRepr_HArray1OfRepresentationItem(1,1);
2166 HARI->SetValue(1,EC);
2168 HARI->SetValue(1,AF);
2169 SR->Init(aName,HARI,RC);
2170 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
2172 Model->AddWithRefs(SDR);
2173 // define aUnit for creation LengthMeasureWithUnit (common for all)
2174 StepBasic_Unit aUnit;
2175 Handle(StepBasic_SiUnitAndLengthUnit) SLU;
2176 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) Ctx =
2177 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(RC);
2179 for(Standard_Integer j=1; j<=Ctx->NbUnits(); j++) {
2180 if(Ctx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2181 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx->UnitsValue(j));
2187 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) Ctx1 =
2188 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(RC);
2189 if(!Ctx1.IsNull()) {
2190 for(Standard_Integer j=1; j<=Ctx1->NbUnits(); j++) {
2191 if(Ctx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2192 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx1->UnitsValue(j));
2199 SLU = new StepBasic_SiUnitAndLengthUnit;
2201 aUnit.SetValue(SLU);
2203 // specific part of writing D> entities
2204 if(kind<20) { //dimension
2205 Handle(StepShape_DimensionalSize) DimSize = new StepShape_DimensionalSize;
2206 DimSize->Init(SA,aDescription);
2207 Model->AddWithRefs(DimSize);
2208 if(aVal->Length()>1) {
2209 // create MeasureWithUnits
2210 Handle(StepBasic_MeasureValueMember) MVM1 = new StepBasic_MeasureValueMember;
2211 MVM1->SetName("POSITIVE_LENGTH_MEASURE");
2212 MVM1->SetReal(aVal->Value(1));
2213 Handle(StepBasic_MeasureWithUnit) MWU1 = new StepBasic_MeasureWithUnit;
2214 MWU1->Init(MVM1,aUnit);
2215 Handle(StepBasic_MeasureValueMember) MVM2 = new StepBasic_MeasureValueMember;
2216 MVM2->SetName("POSITIVE_LENGTH_MEASURE");
2217 MVM2->SetReal(aVal->Value(2));
2218 Handle(StepBasic_MeasureWithUnit) MWU2 = new StepBasic_MeasureWithUnit;
2219 MWU2->Init(MVM2,aUnit);
2220 Handle(StepRepr_RepresentationItem) RI1 = new StepRepr_RepresentationItem;
2221 RI1->Init(new TCollection_HAsciiString("lower limit"));
2222 Handle(StepRepr_RepresentationItem) RI2 = new StepRepr_RepresentationItem;
2223 RI2->Init(new TCollection_HAsciiString("upper limit"));
2224 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU1 =
2225 new StepRepr_ReprItemAndLengthMeasureWithUnit;
2226 RILMU1->Init(MWU1,RI1);
2227 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU2 =
2228 new StepRepr_ReprItemAndLengthMeasureWithUnit;
2229 RILMU2->Init(MWU2,RI2);
2230 Model->AddWithRefs(RILMU1);
2231 Model->AddWithRefs(RILMU2);
2232 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
2233 // new StepRepr_CompoundItemDefinitionMember;
2234 //Handle(TColStd_HArray1OfTransient) ArrTr = new TColStd_HArray1OfTransient(1,2);
2235 //ArrTr->SetValue(1,RILMU1);
2236 //ArrTr->SetValue(2,RILMU2);
2237 //CIDM->SetArrTransient(ArrTr);
2238 //CIDM->SetName("SET_REPRESENTATION_ITEM");
2239 //StepRepr_CompoundItemDefinition CID;
2240 //CID.SetValue(CIDM);
2241 Handle(StepRepr_HArray1OfRepresentationItem) HARIVR =
2242 new StepRepr_HArray1OfRepresentationItem(1,2);
2243 HARIVR->SetValue(1,RILMU1);
2244 HARIVR->SetValue(2,RILMU2);
2245 Handle(StepRepr_ValueRange) VR = new StepRepr_ValueRange;
2246 //VR->Init(aName,CID);
2247 VR->Init(aName,HARIVR);
2248 Model->AddEntity(VR);
2249 Handle(StepShape_ShapeDimensionRepresentation) SDimR =
2250 new StepShape_ShapeDimensionRepresentation;
2251 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
2252 new StepRepr_HArray1OfRepresentationItem(1,1);
2253 HARI->SetValue(1,VR);
2254 SDimR->Init(aName,HARI,RC);
2255 Model->AddWithRefs(SDimR);
2256 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
2257 new StepShape_DimensionalCharacteristicRepresentation;
2258 StepShape_DimensionalCharacteristic DimChar;
2259 DimChar.SetValue(DimSize);
2260 DimCharR->Init(DimChar,SDimR);
2261 Model->AddEntity(DimCharR);
2264 else if(kind<50) { //tolerance
2265 if(kind<35) { // tolerance with datum system
2266 TDF_LabelSequence DatumLabels;
2267 DGTTool->GetDatumOfTolerLabels(DimTolL,DatumLabels);
2268 Standard_Integer NbDR = DatumLabels.Length();
2269 Handle(StepDimTol_HArray1OfDatumReference) HADR = new StepDimTol_HArray1OfDatumReference(1,NbDR);
2270 for(Standard_Integer j=1; j<=NbDR; j++) {
2271 Handle(XCAFDoc_Datum) DatumAttr;
2272 TDF_Label DatumL = DatumLabels.Value(j);
2273 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
2274 Handle(TCollection_HAsciiString) aNameD = DatumAttr->GetName();
2275 Handle(TCollection_HAsciiString) aDescriptionD = DatumAttr->GetDescription();
2276 Handle(TCollection_HAsciiString) anIdentificationD = DatumAttr->GetIdentification();
2277 TCollection_AsciiString stmp(aNameD->ToCString());
2278 stmp.AssignCat(aDescriptionD->ToCString());
2279 stmp.AssignCat(anIdentificationD->ToCString());
2280 if(DatumMap.IsBound(stmp)) {
2281 Handle(StepDimTol_Datum) aDatum =
2282 Handle(StepDimTol_Datum)::DownCast(DatumMap.Find(stmp));
2283 Handle(StepDimTol_DatumReference) DR = new StepDimTol_DatumReference;
2285 Model->AddWithRefs(DR);
2286 HADR->SetValue(j,DR);
2289 // create LengthMeasureWithUnit
2290 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
2291 MVM->SetName("LENGTH_MEASURE");
2292 MVM->SetReal(aVal->Value(1));
2293 Handle(StepBasic_LengthMeasureWithUnit) LMWU = new StepBasic_LengthMeasureWithUnit;
2294 LMWU->Init(MVM,aUnit);
2295 // create tolerance by it's type
2297 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2298 new StepDimTol_GeometricToleranceWithDatumReference;
2299 GTWDR->SetDatumSystem(HADR);
2300 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2301 new StepDimTol_ModifiedGeometricTolerance;
2302 if(kind==21) MGT->SetModifier(StepDimTol_MaximumMaterialCondition);
2303 else if(kind==22) MGT->SetModifier(StepDimTol_LeastMaterialCondition);
2304 else if(kind==23) MGT->SetModifier(StepDimTol_RegardlessOfFeatureSize);
2305 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
2306 new StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol;
2307 GTComplex->Init(aName,aDescription,LMWU,SA,GTWDR,MGT);
2308 Model->AddWithRefs(GTComplex);
2311 Handle(StepDimTol_AngularityTolerance) aToler =
2312 new StepDimTol_AngularityTolerance;
2313 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2314 Model->AddWithRefs(aToler);
2317 Handle(StepDimTol_CircularRunoutTolerance) aToler =
2318 new StepDimTol_CircularRunoutTolerance;
2319 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2320 Model->AddWithRefs(aToler);
2323 Handle(StepDimTol_CoaxialityTolerance) aToler =
2324 new StepDimTol_CoaxialityTolerance;
2325 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2326 Model->AddWithRefs(aToler);
2329 Handle(StepDimTol_ConcentricityTolerance) aToler =
2330 new StepDimTol_ConcentricityTolerance;
2331 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2332 Model->AddWithRefs(aToler);
2335 Handle(StepDimTol_ParallelismTolerance) aToler =
2336 new StepDimTol_ParallelismTolerance;
2337 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2338 Model->AddWithRefs(aToler);
2341 Handle(StepDimTol_PerpendicularityTolerance) aToler =
2342 new StepDimTol_PerpendicularityTolerance;
2343 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2344 Model->AddWithRefs(aToler);
2347 Handle(StepDimTol_SymmetryTolerance) aToler =
2348 new StepDimTol_SymmetryTolerance;
2349 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2350 Model->AddWithRefs(aToler);
2353 Handle(StepDimTol_TotalRunoutTolerance) aToler =
2354 new StepDimTol_TotalRunoutTolerance;
2355 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2356 Model->AddWithRefs(aToler);
2362 return Standard_True;
2366 //=======================================================================
2367 //function : FindPDSforRI
2368 //purpose : auxilary:
2369 //=======================================================================
2370 static Standard_Boolean FindPDSforRI(const Interface_Graph &aGraph,
2371 const Handle(Standard_Transient) &ent,
2372 Handle(StepRepr_ProductDefinitionShape) &PDS,
2373 Handle(StepRepr_RepresentationContext) &RC)
2375 if(!ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem))) return Standard_False;
2376 Interface_EntityIterator subs = aGraph.Sharings(ent);
2377 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
2378 Handle(StepShape_ShapeRepresentation) SR =
2379 Handle(StepShape_ShapeRepresentation)::DownCast(subs.Value());
2380 if(SR.IsNull()) continue;
2381 RC = SR->ContextOfItems();
2382 Interface_EntityIterator subs1 = aGraph.Sharings(SR);
2383 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
2384 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2385 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs1.Value());
2386 if(SDR.IsNull()) continue;
2387 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
2388 if(PropD.IsNull()) continue;
2389 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
2392 return Standard_True;
2396 //=======================================================================
2397 //function : WriteMaterials
2399 //=======================================================================
2401 Standard_Boolean STEPCAFControl_Writer::WriteMaterials (const Handle(XSControl_WorkSession) &WS,
2402 const TDF_LabelSequence &labels ) const
2405 if ( labels.Length() <=0 ) return Standard_False;
2408 Handle(Interface_InterfaceModel) Model = WS->Model();
2409 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
2410 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
2412 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2413 if(aHGraph.IsNull())
2414 return Standard_False;
2416 Interface_Graph aGraph = WS->HGraph()->Graph();
2417 Handle(XCAFDoc_ShapeTool) ShTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
2418 if(ShTool.IsNull() ) return Standard_False;
2419 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( labels(1) );
2420 if(MatTool.IsNull() ) return Standard_False;
2422 STEPConstruct_DataMapOfAsciiStringTransient MapDRI,MapMRI;
2423 TDF_LabelSequence TopLabels;
2424 ShTool->GetShapes(TopLabels);
2425 for(Standard_Integer i=1; i<=TopLabels.Length(); i++) {
2426 TDF_Label ShL = TopLabels.Value(i);
2427 Handle(TDataStd_TreeNode) Node;
2428 if( ShL.FindAttribute(XCAFDoc::MaterialRefGUID(),Node) && Node->HasFather() ) {
2429 // find PDS for current shape
2430 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShL);
2431 TopLoc_Location Loc;
2432 TColStd_SequenceOfTransient seqRI;
2433 FindEntities( FP, aShape, Loc, seqRI );
2434 if(seqRI.Length()<=0) continue;
2435 Handle(StepRepr_ProductDefinitionShape) PDS;
2436 Handle(StepRepr_RepresentationContext) RC;
2437 Handle(Standard_Transient) ent = seqRI.Value(1);
2438 FindPDSforRI(aGraph,ent,PDS,RC);
2439 if(PDS.IsNull()) continue;
2440 Handle(StepBasic_ProductDefinition) aProdDef =
2441 PDS->Definition().ProductDefinition();
2442 if(aProdDef.IsNull())
2444 // write material entities
2445 TDF_Label MatL = Node->Father()->Label();
2446 Handle(TCollection_HAsciiString) aName;
2447 Handle(TCollection_HAsciiString) aDescription;
2448 Standard_Real aDensity;
2449 Handle(TCollection_HAsciiString) aDensName;
2450 Handle(TCollection_HAsciiString) aDensValType;
2451 Handle(StepRepr_Representation) RepDRI;
2452 Handle(StepRepr_Representation) RepMRI;
2453 if(MatTool->GetMaterial(MatL,aName,aDescription,aDensity,aDensName,aDensValType)) {
2454 if(aName->Length()==0) continue;
2455 TCollection_AsciiString aKey(aName->ToCString());
2456 if(MapDRI.IsBound(aKey)) {
2457 RepDRI = Handle(StepRepr_Representation)::DownCast(MapDRI.Find(aKey));
2458 if(MapMRI.IsBound(aKey)) {
2459 RepMRI = Handle(StepRepr_Representation)::DownCast(MapMRI.Find(aKey));
2464 Handle(StepRepr_DescriptiveRepresentationItem) DRI = new StepRepr_DescriptiveRepresentationItem;
2465 DRI->Init(aName,aDescription);
2466 Handle(StepRepr_HArray1OfRepresentationItem) HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
2467 HARI->SetValue(1,DRI);
2468 RepDRI = new StepRepr_Representation();
2469 RepDRI->Init(new TCollection_HAsciiString("material name"),HARI,RC);
2470 Model->AddWithRefs(RepDRI);
2472 if( aDensity > 0 ) {
2474 Handle(StepBasic_SiUnitAndMassUnit) SMU = new StepBasic_SiUnitAndMassUnit;
2475 SMU->SetName(StepBasic_sunGram);
2476 Handle(StepBasic_DerivedUnitElement) DUE1 = new StepBasic_DerivedUnitElement;
2477 DUE1->Init(SMU,3.0);
2479 Handle(StepBasic_SiUnitAndLengthUnit) SLU = new StepBasic_SiUnitAndLengthUnit;
2480 SLU->Init(Standard_True,StepBasic_spCenti,StepBasic_sunMetre);
2481 Handle(StepBasic_DerivedUnitElement) DUE2 = new StepBasic_DerivedUnitElement;
2482 DUE2->Init(SLU,2.0);
2484 Handle(StepBasic_HArray1OfDerivedUnitElement) HADUE = new StepBasic_HArray1OfDerivedUnitElement(1,2);
2485 HADUE->SetValue(1,DUE1);
2486 HADUE->SetValue(2,DUE2);
2487 Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit;
2489 Model->AddWithRefs(DU);
2490 StepBasic_Unit aUnit;
2492 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
2493 MVM->SetName(aDensValType->ToCString());
2494 MVM->SetReal(aDensity);
2495 Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem;
2496 MRI->Init(aDensName,MVM,aUnit);
2497 HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
2498 HARI->SetValue(1,MRI);
2499 RepMRI = new StepRepr_Representation();
2500 RepMRI->Init(new TCollection_HAsciiString("density"),HARI,RC);
2501 Model->AddWithRefs(RepMRI);
2503 //WriteNewMaterial(Model,aName,aDescription,aDensity,aDensName,aDensValType,RC,RepDRI,RepMRI);
2504 MapDRI.Bind(aKey,RepDRI);
2505 if ( !RepMRI.IsNull() ) MapMRI.Bind (aKey, RepMRI);
2509 if( !RepDRI.IsNull() )
2511 StepRepr_CharacterizedDefinition CD1;
2512 CD1.SetValue(aProdDef);
2513 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
2514 PropD1->Init(new TCollection_HAsciiString("material property"),Standard_True,
2515 new TCollection_HAsciiString("material name"),CD1);
2516 Model->AddWithRefs(PropD1);
2517 StepRepr_RepresentedDefinition RD1;
2518 RD1.SetValue(PropD1);
2519 Handle(StepRepr_PropertyDefinitionRepresentation) PDR1 =
2520 new StepRepr_PropertyDefinitionRepresentation;
2521 PDR1->Init(RD1,RepDRI);
2522 Model->AddWithRefs(PDR1);
2524 if( !RepMRI.IsNull() )
2526 StepRepr_CharacterizedDefinition CD2;
2527 CD2.SetValue (aProdDef);
2528 Handle (StepRepr_PropertyDefinition) PropD2 = new StepRepr_PropertyDefinition;
2529 PropD2->Init (new TCollection_HAsciiString ("material property"), Standard_True,
2530 new TCollection_HAsciiString ("density"), CD2);
2531 Model->AddWithRefs (PropD2);
2532 StepRepr_RepresentedDefinition RD2;
2533 RD2.SetValue (PropD2);
2534 Handle (StepRepr_PropertyDefinitionRepresentation) PDR2 =
2535 new StepRepr_PropertyDefinitionRepresentation;
2536 PDR2->Init (RD2, RepMRI);
2537 Model->AddWithRefs (PDR2);
2543 return Standard_True;
2547 //=======================================================================
2548 //function : SetColorMode
2550 //=======================================================================
2552 void STEPCAFControl_Writer::SetColorMode (const Standard_Boolean colormode)
2554 myColorMode = colormode;
2558 //=======================================================================
2559 //function : GetColorMode
2561 //=======================================================================
2563 Standard_Boolean STEPCAFControl_Writer::GetColorMode () const
2569 //=======================================================================
2570 //function : SetNameMode
2572 //=======================================================================
2574 void STEPCAFControl_Writer::SetNameMode (const Standard_Boolean namemode)
2576 myNameMode = namemode;
2580 //=======================================================================
2581 //function : GetNameMode
2583 //=======================================================================
2585 Standard_Boolean STEPCAFControl_Writer::GetNameMode () const
2591 //=======================================================================
2592 //function : SetLayerMode
2594 //=======================================================================
2596 void STEPCAFControl_Writer::SetLayerMode (const Standard_Boolean layermode)
2598 myLayerMode = layermode;
2602 //=======================================================================
2603 //function : GetLayerMode
2605 //=======================================================================
2607 Standard_Boolean STEPCAFControl_Writer::GetLayerMode () const
2613 //=======================================================================
2614 //function : SetPropsMode
2616 //=======================================================================
2618 void STEPCAFControl_Writer::SetPropsMode (const Standard_Boolean propsmode)
2620 myPropsMode = propsmode;
2624 //=======================================================================
2625 //function : GetPropsMode
2627 //=======================================================================
2629 Standard_Boolean STEPCAFControl_Writer::GetPropsMode () const
2635 //=======================================================================
2636 //function : SetSHUOMode
2638 //=======================================================================
2640 void STEPCAFControl_Writer::SetSHUOMode (const Standard_Boolean mode)
2646 //=======================================================================
2647 //function : GetSHUOMode
2649 //=======================================================================
2651 Standard_Boolean STEPCAFControl_Writer::GetSHUOMode () const
2657 //=======================================================================
2658 //function : SetDimTolMode
2660 //=======================================================================
2662 void STEPCAFControl_Writer::SetDimTolMode(const Standard_Boolean dimtolmode)
2664 myDGTMode = dimtolmode;
2668 //=======================================================================
2669 //function : GetDimTolMode
2671 //=======================================================================
2673 Standard_Boolean STEPCAFControl_Writer::GetDimTolMode() const
2679 //=======================================================================
2680 //function : SetMaterialMode
2682 //=======================================================================
2684 void STEPCAFControl_Writer::SetMaterialMode(const Standard_Boolean matmode)
2686 myMatMode = matmode;
2690 //=======================================================================
2691 //function : GetMaterialMode
2693 //=======================================================================
2695 Standard_Boolean STEPCAFControl_Writer::GetMaterialMode() const