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 <GeomToStep_MakeCartesianPoint.hxx>
25 #include <HeaderSection_FileSchema.hxx>
26 #include <Interface_EntityIterator.hxx>
27 #include <Interface_Static.hxx>
28 #include <Message_Messenger.hxx>
29 #include <MoniTool_DataMapIteratorOfDataMapOfShapeTransient.hxx>
30 #include <NCollection_Vector.hxx>
31 #include <OSD_Path.hxx>
32 #include <Quantity_TypeOfColor.hxx>
33 #include <StepAP214_Protocol.hxx>
34 #include <StepAP242_DraughtingModelItemAssociation.hxx>
35 #include <StepAP242_GeometricItemSpecificUsage.hxx>
36 #include <StepBasic_DerivedUnit.hxx>
37 #include <StepBasic_DerivedUnitElement.hxx>
38 #include <StepBasic_HArray1OfDerivedUnitElement.hxx>
39 #include <StepBasic_LengthMeasureWithUnit.hxx>
40 #include <StepBasic_MeasureValueMember.hxx>
41 #include <StepBasic_Product.hxx>
42 #include <StepBasic_ProductDefinition.hxx>
43 #include <StepBasic_ProductDefinitionFormation.hxx>
44 #include <StepBasic_ProductDefinitionRelationship.hxx>
45 #include <StepBasic_SiUnitAndLengthUnit.hxx>
46 #include <StepBasic_SiUnitAndMassUnit.hxx>
47 #include <StepBasic_SiUnitAndPlaneAngleUnit.hxx>
48 #include <STEPCAFControl_ActorWrite.hxx>
49 #include <STEPCAFControl_Controller.hxx>
50 #include <STEPCAFControl_ExternFile.hxx>
51 #include <STEPCAFControl_Writer.hxx>
52 #include <STEPConstruct.hxx>
53 #include <STEPConstruct_DataMapOfAsciiStringTransient.hxx>
54 #include <STEPConstruct_DataMapOfPointTransient.hxx>
55 #include <STEPConstruct_ExternRefs.hxx>
56 #include <STEPCAFControl_GDTProperty.hxx>
57 #include <STEPConstruct_Styles.hxx>
58 #include <STEPConstruct_ValidationProps.hxx>
59 #include <STEPControl_StepModelType.hxx>
60 #include <STEPControl_Writer.hxx>
61 #include <StepData_Logical.hxx>
62 #include <StepData_StepModel.hxx>
63 #include <StepDimTol_AngularityTolerance.hxx>
64 #include <StepDimTol_CircularRunoutTolerance.hxx>
65 #include <StepDimTol_CoaxialityTolerance.hxx>
66 #include <StepDimTol_ConcentricityTolerance.hxx>
67 #include <StepDimTol_CylindricityTolerance.hxx>
68 #include <StepDimTol_Datum.hxx>
69 #include <StepDimTol_DatumFeature.hxx>
70 #include <StepDimTol_DatumReference.hxx>
71 #include <StepDimTol_DatumReferenceElement.hxx>
72 #include <StepDimTol_DatumSystem.hxx>
73 #include <StepDimTol_DatumSystemOrReference.hxx>
74 #include <StepDimTol_DatumTarget.hxx>
75 #include <StepDimTol_FlatnessTolerance.hxx>
76 #include <StepDimTol_GeometricToleranceType.hxx>
77 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
78 #include <StepDimTol_GeometricToleranceWithModifiers.hxx>
79 #include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx>
80 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
81 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
82 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
83 #include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx>
84 #include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
85 #include <StepDimTol_HArray1OfDatumReference.hxx>
86 #include <StepDimTol_HArray1OfDatumReferenceElement.hxx>
87 #include <StepDimTol_HArray1OfDatumReferenceModifier.hxx>
88 #include <StepDimTol_HArray1OfDatumSystemOrReference.hxx>
89 #include <StepDimTol_LineProfileTolerance.hxx>
90 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
91 #include <StepDimTol_ParallelismTolerance.hxx>
92 #include <StepDimTol_PerpendicularityTolerance.hxx>
93 #include <StepDimTol_PlacedDatumTargetFeature.hxx>
94 #include <StepDimTol_PositionTolerance.hxx>
95 #include <StepDimTol_RoundnessTolerance.hxx>
96 #include <StepDimTol_RunoutZoneDefinition.hxx>
97 #include <StepDimTol_RunoutZoneOrientation.hxx>
98 #include <StepDimTol_StraightnessTolerance.hxx>
99 #include <StepDimTol_SurfaceProfileTolerance.hxx>
100 #include <StepDimTol_SymmetryTolerance.hxx>
101 #include <StepDimTol_ToleranceZone.hxx>
102 #include <StepDimTol_ToleranceZoneForm.hxx>
103 #include <StepDimTol_TotalRunoutTolerance.hxx>
104 #include <StepGeom_Axis2Placement3d.hxx>
105 #include <StepGeom_CartesianPoint.hxx>
106 #include <StepGeom_Direction.hxx>
107 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
108 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
109 #include <StepGeom_Plane.hxx>
110 #include <StepGeom_Surface.hxx>
111 #include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx>
112 #include <StepRepr_CompositeShapeAspect.hxx>
113 #include <StepRepr_ConstructiveGeometryRepresentation.hxx>
114 #include <StepRepr_ConstructiveGeometryRepresentationRelationship.hxx>
115 #include <StepRepr_DerivedShapeAspect.hxx>
116 #include <StepRepr_DescriptiveRepresentationItem.hxx>
117 #include <StepRepr_FeatureForDatumTargetRelationship.hxx>
118 #include <StepRepr_HArray1OfRepresentationItem.hxx>
119 #include <StepRepr_MeasureRepresentationItem.hxx>
120 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
121 #include <StepRepr_ProductDefinitionShape.hxx>
122 #include <StepRepr_PropertyDefinition.hxx>
123 #include <StepRepr_RepresentedDefinition.hxx>
124 #include <StepRepr_Representation.hxx>
125 #include <StepRepr_RepresentationItem.hxx>
126 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
127 #include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx>
128 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
129 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx>
130 #include <StepRepr_ShapeAspect.hxx>
131 #include <StepRepr_ShapeAspectDerivingRelationship.hxx>
132 #include <StepRepr_ShapeAspectRelationship.hxx>
133 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
134 #include <StepRepr_ValueRange.hxx>
135 #include <StepShape_AdvancedFace.hxx>
136 #include <StepShape_AngleRelator.hxx>
137 #include <StepShape_AngularLocation.hxx>
138 #include <StepShape_AngularSize.hxx>
139 #include <StepShape_ConnectedFaceSet.hxx>
140 #include <StepShape_ContextDependentShapeRepresentation.hxx>
141 #include <StepShape_DimensionalCharacteristic.hxx>
142 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
143 #include <StepShape_DimensionalLocation.hxx>
144 #include <StepShape_DimensionalLocationWithPath.hxx>
145 #include <StepShape_DimensionalSize.hxx>
146 #include <StepShape_DimensionalSizeWithPath.hxx>
147 #include <StepShape_EdgeCurve.hxx>
148 #include <StepShape_EdgeLoop.hxx>
149 #include <StepShape_FaceBound.hxx>
150 #include <StepShape_LimitsAndFits.hxx>
151 #include <StepShape_OrientedEdge.hxx>
152 #include <StepShape_PlusMinusTolerance.hxx>
153 #include <StepShape_QualifiedRepresentationItem.hxx>
154 #include <StepShape_ShapeDefinitionRepresentation.hxx>
155 #include <StepShape_ShapeDimensionRepresentation.hxx>
156 #include <StepShape_ShapeRepresentation.hxx>
157 #include <StepShape_ShapeRepresentationWithParameters.hxx>
158 #include <StepShape_ToleranceValue.hxx>
159 #include <StepShape_TypeQualifier.hxx>
160 #include <StepShape_ValueFormatTypeQualifier.hxx>
161 #include <StepVisual_AnnotationPlane.hxx>
162 #include <StepVisual_CurveStyle.hxx>
163 #include <StepVisual_DraughtingCallout.hxx>
164 #include <StepVisual_DraughtingModel.hxx>
165 #include <StepVisual_HArray1OfInvisibleItem.hxx>
166 #include <StepVisual_HArray1OfLayeredItem.hxx>
167 #include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
168 #include <StepVisual_HArray1OfPresentationStyleSelect.hxx>
169 #include <StepVisual_Invisibility.hxx>
170 #include <StepVisual_InvisibleItem.hxx>
171 #include <StepVisual_MechanicalDesignGeometricPresentationRepresentation.hxx>
172 #include <StepVisual_NullStyleMember.hxx>
173 #include <StepVisual_PointStyle.hxx>
174 #include <StepVisual_PresentationLayerAssignment.hxx>
175 #include <StepVisual_PresentationRepresentation.hxx>
176 #include <StepVisual_PresentationStyleAssignment.hxx>
177 #include <StepVisual_PresentationStyleByContext.hxx>
178 #include <StepVisual_StyledItem.hxx>
179 #include <StepVisual_SurfaceStyleUsage.hxx>
180 #include <StepVisual_TessellatedAnnotationOccurrence.hxx>
181 #include <StepVisual_TessellatedGeometricSet.hxx>
182 #include <TCollection_AsciiString.hxx>
183 #include <TCollection_HAsciiString.hxx>
184 #include <TColStd_HArray1OfReal.hxx>
185 #include <TColStd_HArray1OfTransient.hxx>
186 #include <TColStd_HSequenceOfTransient.hxx>
187 #include <TColStd_MapOfAsciiString.hxx>
188 #include <TColStd_MapOfTransient.hxx>
189 #include <TDataStd_Name.hxx>
190 #include <TDataStd_TreeNode.hxx>
191 #include <TDataStd_UAttribute.hxx>
192 #include <TDF_AttributeSequence.hxx>
193 #include <TDF_ChildIterator.hxx>
194 #include <TDF_Label.hxx>
195 #include <TDF_LabelSequence.hxx>
196 #include <TDF_Tool.hxx>
197 #include <TDocStd_Document.hxx>
198 #include <TopoDS_Compound.hxx>
199 #include <TopoDS_Iterator.hxx>
200 #include <TopoDS_Shape.hxx>
201 #include <TopTools_MapOfShape.hxx>
202 #include <TopTools_SequenceOfShape.hxx>
203 #include <Transfer_ActorOfFinderProcess.hxx>
204 #include <Transfer_Binder.hxx>
205 #include <Transfer_FinderProcess.hxx>
206 #include <Transfer_TransientListBinder.hxx>
207 #include <TransferBRep.hxx>
208 #include <TransferBRep_ShapeMapper.hxx>
209 #include <XCAFDimTolObjects_DatumObject.hxx>
210 #include <XCAFDimTolObjects_DimensionFormVariance.hxx>
211 #include <XCAFDimTolObjects_DimensionGrade.hxx>
212 #include <XCAFDimTolObjects_DimensionObject.hxx>
213 #include <XCAFDimTolObjects_DimensionModif.hxx>
214 #include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
215 #include <XCAFDimTolObjects_DimensionQualifier.hxx>
216 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
217 #include <XCAFDoc.hxx>
218 #include <XCAFDoc_Area.hxx>
219 #include <XCAFDoc_Centroid.hxx>
220 #include <XCAFDoc_ColorTool.hxx>
221 #include <XCAFDoc_Datum.hxx>
222 #include <XCAFDoc_Dimension.hxx>
223 #include <XCAFDoc_DimTol.hxx>
224 #include <XCAFDoc_DimTolTool.hxx>
225 #include <XCAFDoc_DocumentTool.hxx>
226 #include <XCAFDoc_GeomTolerance.hxx>
227 #include <XCAFDoc_GraphNode.hxx>
228 #include <XCAFDoc_LayerTool.hxx>
229 #include <XCAFDoc_Material.hxx>
230 #include <XCAFDoc_MaterialTool.hxx>
231 #include <XCAFDoc_ShapeTool.hxx>
232 #include <XCAFDoc_Volume.hxx>
233 #include <XCAFPrs.hxx>
234 #include <XCAFPrs_DataMapIteratorOfDataMapOfStyleShape.hxx>
235 #include <XCAFPrs_DataMapOfShapeStyle.hxx>
236 #include <XCAFPrs_DataMapOfStyleShape.hxx>
237 #include <XCAFPrs_Style.hxx>
238 #include <XSControl_TransferWriter.hxx>
239 #include <XSControl_WorkSession.hxx>
241 static NCollection_Vector<Handle(StepVisual_AnnotationPlane)> gdtAnnotationPlanes;
242 static Handle(StepVisual_DraughtingModel) gdtPresentationDM;
243 static Handle(StepVisual_HArray1OfPresentationStyleAssignment) gdtPrsCurveStyle;
245 // added by skl 15.01.2004 for D> writing
246 //#include <StepRepr_CompoundItemDefinition.hxx>
247 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
248 // added by skl 12.02.2004 for writing materials
249 //=======================================================================
250 //function : GetLabelName
251 //purpose : auxilary function: take name of label and append it to str
252 //=======================================================================
253 static Standard_Boolean GetLabelName (const TDF_Label &L, Handle(TCollection_HAsciiString) &str)
255 Handle(TDataStd_Name) N;
256 if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) return Standard_False;
257 TCollection_ExtendedString name = N->Get();
258 if ( name.Length() <=0 ) return Standard_False;
260 // set name, converting it to Ascii and removing spaces
261 TCollection_AsciiString buf ( name, '?' );
264 buf.ChangeAll(' ','_');
265 str->AssignCat ( buf.ToCString() );
266 return Standard_True;
270 //=======================================================================
271 //function : STEPCAFControl_Writer
273 //=======================================================================
275 STEPCAFControl_Writer::STEPCAFControl_Writer () :
276 myColorMode( Standard_True ),
277 myNameMode ( Standard_True ),
278 myLayerMode( Standard_True ),
279 myPropsMode( Standard_True ),
280 mySHUOMode ( Standard_True ),
281 myDGTMode ( Standard_True ),
282 myMatMode ( Standard_True )
284 STEPCAFControl_Controller::Init();
285 Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
290 //=======================================================================
291 //function : STEPCAFControl_Writer
293 //=======================================================================
295 STEPCAFControl_Writer::STEPCAFControl_Writer (const Handle(XSControl_WorkSession)& WS,
296 const Standard_Boolean scratch)
298 STEPCAFControl_Controller::Init();
299 Init ( WS, scratch );
300 myColorMode = Standard_True;
301 myNameMode = Standard_True;
302 myLayerMode = Standard_True;
303 myPropsMode = Standard_True;
304 mySHUOMode = Standard_True;
308 //=======================================================================
311 //=======================================================================
313 void STEPCAFControl_Writer::Init (const Handle(XSControl_WorkSession)& WS,
314 const Standard_Boolean scratch)
316 WS->SelectNorm ( "STEP" );
317 myWriter.SetWS (WS,scratch);
324 //=======================================================================
327 //=======================================================================
329 IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filename)
331 IFSelect_ReturnStatus status = myWriter.Write ( filename );
333 // get directory name of the main file
334 OSD_Path mainfile ( filename );
335 mainfile.SetName ( "" );
336 mainfile.SetExtension ( "" );
337 TCollection_AsciiString dpath;
338 mainfile.SystemName ( dpath );
340 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator it(myFiles);
341 for ( ; it.More(); it.Next() ) {
342 Handle(STEPCAFControl_ExternFile) EF = it.Value();
343 if ( EF->GetWriteStatus() != IFSelect_RetVoid ) continue;
345 // construct extern file name
346 TCollection_AsciiString fname = OSD_Path::AbsolutePath ( dpath, EF->GetName()->String() );
347 if ( fname.Length() <= 0 ) fname = EF->GetName()->String();
349 cout << "Writing external file: " << fname.ToCString() << endl;
352 EF->SetWriteStatus ( EF->GetWS()->SendAll ( fname.ToCString() ) );
359 //=======================================================================
360 //function : Transfer
362 //=======================================================================
364 Standard_Boolean STEPCAFControl_Writer::Transfer( const Handle(TDocStd_Document) &doc,
365 const STEPControl_StepModelType mode,
366 const Standard_CString multi )
368 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
369 if ( STool.IsNull() ) return Standard_False;
371 TDF_LabelSequence labels;
372 STool->GetFreeShapes ( labels );
373 return Transfer ( myWriter, labels, mode, multi );
377 //=======================================================================
378 //function : Transfer
380 //=======================================================================
382 Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_Label& L,
383 const STEPControl_StepModelType mode,
384 const Standard_CString multi )
386 TDF_LabelSequence labels;
388 return Transfer ( myWriter, labels, mode, multi );
391 //=======================================================================
392 //function : Transfer
394 //=======================================================================
396 Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_LabelSequence& labels,
397 const STEPControl_StepModelType mode,
398 const Standard_CString multi )
400 return Transfer( myWriter, labels, mode, multi );
403 //=======================================================================
406 //=======================================================================
408 Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
409 const Standard_CString filename)
411 if ( ! Transfer ( doc ) ) return Standard_False;
412 return Write ( filename ) == IFSelect_RetDone;
416 //=======================================================================
419 //=======================================================================
421 Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
422 const TCollection_AsciiString &filename)
424 if ( ! Transfer ( doc ) ) return Standard_False;
425 return Write ( filename.ToCString() ) == IFSelect_RetDone;
429 //=======================================================================
430 //function : ExternFiles
432 //=======================================================================
434 const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& STEPCAFControl_Writer::ExternFiles () const
440 //=======================================================================
441 //function : ExternFile
443 //=======================================================================
445 Standard_Boolean STEPCAFControl_Writer::ExternFile (const TDF_Label &L,
446 Handle(STEPCAFControl_ExternFile) &ef) const
449 if ( ! myLabEF.IsBound ( L ) ) return Standard_False;
450 ef = myLabEF.Find ( L );
451 return Standard_True;
455 //=======================================================================
456 //function : ExternFile
458 //=======================================================================
460 Standard_Boolean STEPCAFControl_Writer::ExternFile (const Standard_CString name,
461 Handle(STEPCAFControl_ExternFile) &ef) const
464 if ( ! myFiles.IsEmpty() || ! myFiles.IsBound ( name ) )
465 return Standard_False;
466 ef = myFiles.Find( name );
467 return Standard_True;
471 //=======================================================================
474 //=======================================================================
476 STEPControl_Writer &STEPCAFControl_Writer::ChangeWriter ()
482 //=======================================================================
485 //=======================================================================
487 const STEPControl_Writer &STEPCAFControl_Writer::Writer () const
493 //=======================================================================
494 //function : Transfer
496 //=======================================================================
498 Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
499 const TDF_LabelSequence &labels,
500 const STEPControl_StepModelType mode,
501 const Standard_CString multi,
502 const Standard_Boolean isExternFile)
504 if ( labels.Length() <=0 ) return Standard_False;
506 Handle(STEPCAFControl_ActorWrite) Actor =
507 Handle(STEPCAFControl_ActorWrite)::DownCast ( writer.WS()->NormAdaptor()->ActorWrite() );
509 // translate free top-level shapes of the DECAF document
510 Standard_Integer ap = Interface_Static::IVal ("write.step.schema");
511 TDF_LabelSequence sublabels;
512 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
513 TDF_Label L = labels.Value(i);
515 if ( myLabels.IsBound ( L ) ) continue; // already processed
517 TopoDS_Shape shape = XCAFDoc_ShapeTool::GetShape ( L );
518 if ( shape.IsNull() ) continue;
520 // write shape either as a whole, or as multifile (with extern refs)
522 Actor->SetStdMode ( Standard_False );
524 TDF_LabelSequence comp;
526 //for case when only part of assemby structure should be written in the document
527 //if specified label is component of the assembly then
528 //in order to save location of this component in the high-level assembly
529 //and save name of high-level assembly it is necessary to represent structure of high-level assembly
530 //as assembly with one component specified by current label.
531 //For that compound containing only specified component is binded to the label of the high-level assembly.
532 //The such way full structure of high-level assembly was replaced on the assembly contaning one component.
533 if ( XCAFDoc_ShapeTool::IsComponent ( L ) )
535 TopoDS_Compound aComp;
537 aB.MakeCompound(aComp);
538 aB.Add(aComp, shape);
542 if ( XCAFDoc_ShapeTool::GetReferredShape ( L, ref ) )
544 if(XCAFDoc_ShapeTool::IsAssembly ( ref))
545 XCAFDoc_ShapeTool::GetComponents ( ref, comp, Standard_True );
551 // fill sequence of (sub) shapes for which attributes should be written
552 // and set actor to handle assemblies in a proper way
553 if(XCAFDoc_ShapeTool::IsAssembly ( L ))
554 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_True );
557 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
559 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( comp(k), ref ) ) continue;
560 if ( ! myLabels.IsBound ( ref ) ) {
561 TopoDS_Shape refS = XCAFDoc_ShapeTool::GetShape ( ref );
562 myLabels.Bind ( ref, refS );
563 sublabels.Append ( ref );
564 if ( XCAFDoc_ShapeTool::IsAssembly ( ref ) )
565 Actor->RegisterAssembly ( refS );
568 myLabels.Bind ( L, shape );
569 sublabels.Append ( L );
570 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) )
571 Actor->RegisterAssembly ( shape );
573 writer.Transfer(shape,mode,Standard_False);
574 Actor->SetStdMode ( Standard_True ); // restore default behaviour
577 // translate final solids
578 TopoDS_Shape Sass = TransferExternFiles ( L, mode, sublabels, multi );
580 // translate main assembly structure
582 if ( ap == 3 ) { // if AP203, switch to AP214
583 Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
584 Handle(StepData_StepModel) model =
585 Handle(StepData_StepModel)::DownCast ( writer.WS()->Model() );
586 if ( model->HasHeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) ) {
587 Handle(HeaderSection_FileSchema) fs =
588 Handle(HeaderSection_FileSchema)::DownCast ( model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) );
589 Handle(TCollection_HAsciiString) str = fs->SchemaIdentifiersValue ( 1 );
590 Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "AUTOMOTIVE_DESIGN" );
591 if ( str->Search ( ap214 ) <0 ) {
593 str->AssignCat ( ap214 );
598 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
599 Interface_Static::SetCVal ("write.step.assembly", "On");
600 writer.Transfer ( Sass, STEPControl_AsIs );
601 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
602 Interface_Static::SetIVal ("write.step.schema", ap);
606 writer.WS()->ComputeGraph(Standard_True );// added by skl 03.11.2003 since we use
607 // writer.Transfer() wihtout compute graph
611 WriteNames ( writer.WS(), sublabels );
615 if ( GetColorMode() )
616 WriteColors ( writer.WS(), sublabels );
619 if ( GetLayerMode() )
620 WriteLayers ( writer.WS(), sublabels );
622 // write SHUO entities
623 if ( GetSHUOMode() && !isExternFile )
624 // do not store SHUO for extern reference for the moment
625 WriteSHUOs ( writer.WS(), sublabels );
628 if(GetDimTolMode()) {
630 WriteDGTsAP242(writer.WS(), sublabels);
633 WriteDGTs(writer.WS(), sublabels);
638 if(GetMaterialMode())
639 WriteMaterials(writer.WS(),sublabels);
641 // register all MDGPRs in model
642 const Handle(Interface_InterfaceModel) &Model = writer.WS()->Model();
643 MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR);
644 for (; anItr.More(); anItr.Next())
645 Model->AddWithRefs( anItr.Value() );
648 if ( multi ) { // external refs
649 WriteExternRefs ( writer.WS(), sublabels );
652 // write validation props
653 // if ( multi && ap ==3 ) {
654 // Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
656 if ( GetPropsMode() )
657 WriteValProps ( writer.WS(), sublabels, multi );
659 Interface_Static::SetIVal ("write.step.schema", ap);
662 writer.WS()->ComputeGraph ( Standard_True );
664 /* ================================
665 * Write names for the sub-shapes
666 * ================================ */
668 if (Interface_Static::IVal("write.stepcaf.subshapes.name") != 0)
670 const Handle(XSControl_TransferWriter) &TW = this->ChangeWriter().WS()->TransferWriter();
671 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
673 for ( int i = 1; i <= labels.Length(); i++ )
675 TDF_Label L = labels.Value(i);
677 for ( TDF_ChildIterator it(L, Standard_True); it.More(); it.Next() )
679 TDF_Label SubL = it.Value();
681 // Access name recorded in OCAF TDataStd_Name attribute
682 Handle(TCollection_HAsciiString) hSubName = new TCollection_HAsciiString;
683 if ( !GetLabelName(SubL, hSubName) )
686 // Access topological data
687 TopoDS_Shape SubS = XCAFDoc_ShapeTool::GetShape(SubL);
691 // Access the correspondent STEP Representation Item
692 Handle(StepRepr_RepresentationItem) RI;
693 Handle(TransferBRep_ShapeMapper) aShMapper = TransferBRep::ShapeMapper(FP, SubS);
694 if ( !FP->FindTypedTransient(aShMapper, STANDARD_TYPE(StepRepr_RepresentationItem), RI) )
698 RI->SetName(hSubName);
703 return Standard_True;
707 //=======================================================================
708 //function : TransferExternFiles
710 //=======================================================================
712 TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L,
713 const STEPControl_StepModelType mode,
714 TDF_LabelSequence &labels,
715 const Standard_CString prefix)
717 // if label already translated, just return the shape
718 if ( myLabels.IsBound ( L ) ) {
719 return myLabels.Find ( L );
724 B.MakeCompound ( C );
725 //labels.Append ( L );
726 // if not assembly, write to separate file
727 if ( ! XCAFDoc_ShapeTool::IsAssembly ( L ) && !XCAFDoc_ShapeTool::IsComponent ( L )) {
729 // prepare for transfer
730 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
731 newWS->SelectNorm ( "STEP" );
732 STEPControl_Writer sw ( newWS, Standard_True );
733 TDF_LabelSequence Lseq;
736 // construct the name for extern file
737 Handle(TCollection_HAsciiString) basename = new TCollection_HAsciiString;
738 if ( prefix && prefix[0] ) basename->AssignCat ( prefix );
739 GetLabelName ( L, basename );
740 Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString ( basename );
741 name->AssignCat ( ".stp" );
742 if ( myFiles.IsBound( name->ToCString() ) ) { // avoid confusions
743 for ( Standard_Integer k=1; k < 32000; k++ ) {
744 name = new TCollection_HAsciiString ( basename );
745 name->AssignCat ( "_" );
746 name->AssignCat ( TCollection_AsciiString ( k ).ToCString() );
747 name->AssignCat ( ".stp" );
748 if ( ! myFiles.IsBound ( name->ToCString() ) ) break;
752 // translate and record extern file
753 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
755 EF->SetName ( name );
757 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
758 Interface_Static::SetCVal ("write.step.assembly", "Off");
759 const Standard_CString multi = 0;
760 EF->SetTransferStatus ( Transfer ( sw, Lseq, mode, multi, Standard_True ) );
761 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
762 myLabEF.Bind ( L, EF );
763 myFiles.Bind ( name->ToCString(), EF );
765 // return empty compound as replacement for the shape
766 myLabels.Bind ( L, C );
769 TDF_LabelSequence comp;
771 //if specified shape is component then high-level assembly is considered
772 //to get valid structure with location
773 if ( XCAFDoc_ShapeTool::IsComponent ( L ) )
778 // else iterate on components add create structure of empty compounds
779 // representing the assembly
780 else if (XCAFDoc_ShapeTool::IsAssembly ( L ))
781 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_False );
783 labels.Append ( aCurL );
784 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
785 TDF_Label lab = comp(k);
787 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, ref ) ) continue;
788 TopoDS_Shape Scomp = TransferExternFiles ( ref, mode, labels, prefix );
789 Scomp.Location ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
792 myLabels.Bind ( aCurL, C );
797 //=======================================================================
798 //function : WriteExternRefs
800 //=======================================================================
802 Standard_Boolean STEPCAFControl_Writer::WriteExternRefs (const Handle(XSControl_WorkSession) &WS,
803 const TDF_LabelSequence &labels) const
805 if ( labels.Length() <=0 ) return Standard_False;
807 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
808 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
809 STEPConstruct_ExternRefs EFTool ( WS );
810 Standard_Integer schema = Interface_Static::IVal("write.step.schema");
811 for ( Standard_Integer k=1; k <= labels.Length(); k++ ) {
812 TDF_Label lab = labels(k);
813 if ( XCAFDoc_ShapeTool::IsAssembly ( lab ) ) continue; // skip assemblies
816 Handle(STEPCAFControl_ExternFile) EF;
817 if ( ! ExternFile ( lab, EF ) ) continue; // should never be
820 if ( ! myLabels.IsBound ( lab ) ) continue; // not recorded as translated, skip
821 TopoDS_Shape S = myLabels.Find ( lab );
823 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
824 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
825 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
827 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
833 const Standard_CString format = (const Standard_CString) ( schema == 3 ? "STEP AP203" : "STEP AP214" );
834 // try to get PD from SDR
835 StepRepr_RepresentedDefinition RD = SDR->Definition();
836 Handle(StepRepr_PropertyDefinition) aPropDef = RD.PropertyDefinition();
837 if (aPropDef.IsNull()) {
839 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepRepr_PropertyDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
843 StepRepr_CharacterizedDefinition CharDef = aPropDef->Definition();
844 Handle(StepBasic_ProductDefinition) PD = CharDef.ProductDefinition();
847 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepBasic_ProductDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
851 EFTool.AddExternRef ( EF->GetName()->ToCString(), PD, format );
853 EFTool.WriteExternRefs(schema);
854 return Standard_True;
858 //=======================================================================
859 //function : FindEntities
861 //=======================================================================
862 static Standard_Integer FindEntities (const Handle(Transfer_FinderProcess) &FP,
863 const TopoDS_Shape &S,
865 TColStd_SequenceOfTransient &seqRI)
867 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, S, L );
869 if ( ! item.IsNull() ) {
870 seqRI.Append ( item );
874 // may be S was splited during shape processing
875 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
876 Handle(Transfer_Binder) bnd = FP->Find ( mapper );
877 if ( bnd.IsNull() ) return 0;
879 Handle(Transfer_TransientListBinder) TransientListBinder =
880 //Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) );
881 Handle(Transfer_TransientListBinder)::DownCast( bnd );
882 Standard_Integer nres=0;
883 if ( TransientListBinder.IsNull() && S.ShapeType() == TopAbs_COMPOUND)
885 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
886 Handle(StepRepr_RepresentationItem) aLocalItem = STEPConstruct::FindEntity ( FP, it.Value(), L );
887 if (aLocalItem.IsNull() ) continue;
889 seqRI.Append (aLocalItem);
892 else if(!TransientListBinder.IsNull())
895 const Standard_Integer nb = TransientListBinder->NbTransients();
896 for (Standard_Integer i=1; i<=nb; i++) {
897 Handle(Standard_Transient) t = TransientListBinder->Transient(i);
898 item = Handle(StepRepr_RepresentationItem)::DownCast(t);
899 if ( item.IsNull() ) continue;
901 seqRI.Append ( item );
904 /* works but is obsolete: another approach
906 TopoDS_Shape comp = TransferBRep::ShapeResult(bnd);
907 if ( ! comp.IsNull() && comp.ShapeType() < S.ShapeType() ) {
908 for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) {
909 MakeSTEPStyles(Styles, it.Value(), settings, STEPstyle,
910 Map, ( hasOwn ? &style : 0 ) );
919 //=======================================================================
920 //function : getStyledItem
922 //=======================================================================
923 static Standard_Boolean getStyledItem(const TopoDS_Shape& S,
924 const Handle(XCAFDoc_ShapeTool)& STool,
925 const STEPConstruct_Styles &Styles,
926 Handle(StepVisual_StyledItem) &resSelItem,
927 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
929 TDF_Label aTopShL = STool->FindShape(S, Standard_False);
930 TopoDS_Shape aTopLevSh = STool->GetShape( aTopShL );
931 Standard_Boolean found = Standard_False;
932 if ( !aTopLevSh.IsNull() && myMapCompMDGPR.IsBound( aTopLevSh ) ) {
933 Handle(StepVisual_PresentationRepresentation) aMDGPR =
934 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopLevSh ) );
935 Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items();
936 // search for PSA of Monifold solid
937 if ( !anSelItmHArr.IsNull() )
939 for (Standard_Integer si = 1; si <= anSelItmHArr->Length(); si++) {
940 Handle(StepVisual_StyledItem) aSelItm =
941 Handle(StepVisual_StyledItem)::DownCast(anSelItmHArr->Value(si));
943 if ( aSelItm.IsNull() )
946 // check that it is a stiled item for monifold solid brep
948 TColStd_SequenceOfTransient aNewseqRI;
949 FindEntities ( Styles.FinderProcess(), aTopLevSh, Loc, aNewseqRI );
950 if ( aNewseqRI.Length() > 0 )
953 Handle(StepRepr_RepresentationItem) anItem = aSelItm->Item();
954 Standard_Boolean isSameMonSolBR = Standard_False;
955 for (Standard_Integer mi = 1; mi <= aNewseqRI.Length(); mi++) {
956 if ( !anItem.IsNull() && anItem == aNewseqRI.Value( mi ) ) {
957 isSameMonSolBR = Standard_True;
966 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
967 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA = aSelItm->StylesValue(jsi);
968 // check for PSA for top-level (not Presentation style by contex for NAUO)
969 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
971 resSelItem = aSelItm;
972 found = Standard_True;
981 //=======================================================================
982 //function : setDefaultInstanceColor
984 //=======================================================================
985 static Standard_Boolean setDefaultInstanceColor (const Handle(StepVisual_StyledItem) &aSelItm,
986 Handle(StepVisual_PresentationStyleAssignment)& PSA)
988 Standard_Boolean found = Standard_False;
989 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
990 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA = aSelItm->StylesValue(jsi);
991 // check for PSA for top-level (not Presentation style by contex for NAUO)
992 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
993 return Standard_False;
995 // get style select from father PSA
996 if (aFatherPSA->NbStyles() > 0) {
997 Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles =
998 new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles());
999 for (Standard_Integer k = 1; k <= aFatherPSA->NbStyles(); k++) {
1000 StepVisual_PresentationStyleSelect PSS;
1001 StepVisual_PresentationStyleSelect olDPSS = aFatherPSA->StylesValue(k);
1002 if (!olDPSS.PointStyle().IsNull())
1003 PSS.SetValue (olDPSS.PointStyle());
1004 else if (!olDPSS.CurveStyle().IsNull())
1005 PSS.SetValue (olDPSS.CurveStyle());
1006 else if (!olDPSS.SurfaceStyleUsage().IsNull())
1007 PSS.SetValue (olDPSS.SurfaceStyleUsage());
1009 found = Standard_False;
1012 //aFatherStyles->SetValue( k, PSS );
1013 aFatherStyles->SetValue( k, olDPSS );
1014 found = Standard_True;
1018 PSA->Init( aFatherStyles );
1027 //=======================================================================
1028 //function : MakeSTEPStyles
1029 //purpose : auxilary
1030 //=======================================================================
1031 static void MakeSTEPStyles (STEPConstruct_Styles &Styles,
1032 const TopoDS_Shape &S,
1033 const XCAFPrs_DataMapOfShapeStyle &settings,
1034 Handle(StepVisual_StyledItem) &override,
1035 TopTools_MapOfShape &Map,
1036 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR,
1037 STEPConstruct_DataMapOfAsciiStringTransient &DPDCs,
1038 STEPConstruct_DataMapOfPointTransient &ColRGBs,
1039 const Handle(XCAFDoc_ColorTool)& CTool,
1040 const XCAFPrs_Style *inherit = 0,
1041 const Standard_Boolean isComponent = Standard_False)
1043 // skip already processed shapes
1044 if ( ! Map.Add ( S ) ) return;
1046 // check if shape has its own style (r inherits from ancestor)
1047 XCAFPrs_Style style;
1048 if ( inherit ) style = *inherit;
1049 if ( settings.IsBound(S) ) {
1050 XCAFPrs_Style own = settings.Find(S);
1051 if ( !own.IsVisible() ) style.SetVisibility ( Standard_False );
1052 if ( own.IsSetColorCurv() ) style.SetColorCurv ( own.GetColorCurv() );
1053 if ( own.IsSetColorSurf() ) style.SetColorSurf ( own.GetColorSurf() );
1056 // translate colors to STEP
1057 Handle(StepVisual_Colour) surfColor, curvColor;
1058 if ( style.IsSetColorSurf() )
1059 surfColor = Styles.EncodeColor(style.GetColorSurf(),DPDCs,ColRGBs);
1060 if ( style.IsSetColorCurv() )
1061 curvColor = Styles.EncodeColor(style.GetColorCurv(),DPDCs,ColRGBs);
1063 Standard_Boolean hasOwn = ( ! surfColor.IsNull() ||
1064 ! curvColor.IsNull() ||
1065 ! style.IsVisible() );
1067 // find target item and assign style to it
1068 Handle(StepVisual_StyledItem) STEPstyle = override;
1070 if ( S.ShapeType() != TopAbs_COMPOUND || isComponent ) { // skip compounds, let subshapes inherit its colors
1072 TColStd_SequenceOfTransient seqRI;
1073 Standard_Integer nb = FindEntities ( Styles.FinderProcess(), S, L, seqRI );
1075 if ( nb <=0 ) cout << "Warning: Cannot find RI for " << S.TShape()->DynamicType()->Name() << endl;
1077 //Get overridden style gka 10.06.03
1078 if ( isComponent && nb)
1079 getStyledItem(S, CTool->ShapeTool(), Styles, override,myMapCompMDGPR);
1082 for ( Standard_Integer i=1; i <= nb; i++ ) {
1083 Handle(StepRepr_RepresentationItem) item =
1084 Handle(StepRepr_RepresentationItem)::DownCast(seqRI(i));
1085 Handle(StepVisual_PresentationStyleAssignment) PSA;
1086 if ( style.IsVisible() || !surfColor.IsNull() || !curvColor.IsNull() ) {
1087 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1090 // default white color
1091 surfColor = Styles.EncodeColor(Quantity_Color(1,1,1,Quantity_TOC_RGB),DPDCs,ColRGBs);
1092 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1094 setDefaultInstanceColor( override, PSA);
1096 } // end of component case
1098 STEPstyle = Styles.AddStyle ( item, PSA, override );
1099 hasOwn = Standard_False;
1104 // iterate on subshapes (except vertices :)
1105 if ( S.ShapeType() == TopAbs_EDGE ) return;
1106 if ( !isComponent ) // PTV 10.02.2003
1107 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
1108 MakeSTEPStyles ( Styles, it.Value(), settings, STEPstyle,
1109 Map, myMapCompMDGPR, DPDCs, ColRGBs, CTool,
1110 ( hasOwn ? &style : 0 ) );
1115 static Standard_Boolean getFatherColor (const TDF_Label& L,
1116 const Handle(XCAFDoc_ColorTool)& CTool,
1117 XCAFPrs_Style& style)
1119 Standard_Boolean done = Standard_False;
1120 TopoDS_Shape aSh = CTool->ShapeTool()->GetShape( L );
1121 TDF_Label aFL = CTool->ShapeTool()->FindShape( aSh );
1122 if (aFL.IsNull() || aFL == L)
1125 if ( CTool->GetColor ( aFL, XCAFDoc_ColorGen, C ) ) {
1126 style.SetColorCurv ( C );
1127 style.SetColorSurf ( C );
1128 done = Standard_True;
1130 if ( CTool->GetColor ( aFL, XCAFDoc_ColorSurf, C ) ) {
1131 style.SetColorSurf ( C );
1132 done = Standard_True;
1134 if ( CTool->GetColor ( aFL, XCAFDoc_ColorCurv, C ) ) {
1135 style.SetColorCurv ( C );
1136 done = Standard_True;
1144 //=======================================================================
1145 //function : WriteColors
1147 //=======================================================================
1149 Standard_Boolean STEPCAFControl_Writer::WriteColors (const Handle(XSControl_WorkSession) &WS,
1150 const TDF_LabelSequence &labels)
1152 if ( labels.Length() <=0 ) return Standard_False;
1154 // Iterate on shapes in the document
1155 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1156 if ( CTool.IsNull() ) return Standard_False;
1158 STEPConstruct_Styles Styles ( WS );
1159 STEPConstruct_DataMapOfAsciiStringTransient DPDCs;
1160 STEPConstruct_DataMapOfPointTransient ColRGBs;
1161 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1162 TDF_Label L = labels.Value(i);
1164 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1165 // Skip assemblies: colors assigned to assemblies and their instances
1166 // are not supported (it is not clear how to encode that in STEP)
1167 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1169 cout << "Warning: Cannot write color for Assembly" << endl;
1170 cout << "Info: Check for colors assigned to components in assembly" << endl;
1172 // PTV 22.01.2003 Write color for instances.
1173 TDF_LabelSequence compLabels;
1174 if ( aSTool.IsNull() )
1176 if (!aSTool->GetComponents(L, compLabels))
1178 WriteColors(WS, compLabels);
1181 Styles.ClearStyles();
1183 // get a target shape and try to find corresponding context
1184 // (all the colors set under that label will be put into that context)
1186 if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1187 Standard_Boolean isComponent = aSTool->IsComponent( L );
1188 TopoDS_Shape aTopSh = S;
1189 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext ( S );
1190 if ( isComponent ) {
1191 TDF_Label aTopShL = aSTool->FindShape(S, Standard_False);
1192 if (aTopShL.IsNull())
1194 aTopSh = aSTool->GetShape( aTopShL );
1195 Context = Styles.FindContext ( aTopSh );
1197 if ( Context.IsNull() )
1200 // collect settings set on that label
1201 XCAFPrs_DataMapOfShapeStyle settings;
1202 TDF_LabelSequence seq;
1204 XCAFDoc_ShapeTool::GetSubShapes ( L, seq );
1205 Standard_Boolean isVisible = Standard_True;
1206 for ( Standard_Integer j = 1; j <= seq.Length(); j++ ) {
1207 TDF_Label lab = seq.Value(j);
1208 XCAFPrs_Style style;
1211 // check for invisible status of object on label
1212 if ( !CTool->IsVisible( lab ) ) {
1213 isVisible = Standard_False;
1214 style.SetVisibility( Standard_False );
1217 if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) {
1218 style.SetColorCurv ( C );
1219 style.SetColorSurf ( C );
1221 if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) )
1222 style.SetColorSurf ( C );
1223 if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) )
1224 style.SetColorCurv ( C );
1226 // commented, cause we are need to take reference from
1227 // if ( isComponent && lab == L && !isVisible)
1228 // if ( !style.IsSetColorSurf() && !style.IsSetColorCurv() ) {
1229 // getFatherColor ( L, CTool, style);
1231 if ( ! style.IsSetColorCurv() && ! style.IsSetColorSurf() && isVisible ) continue;
1233 TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab );
1234 settings.Bind ( sub, style );
1237 if ( settings.Extent() <=0 ) continue;
1239 // iterate on subshapes and create STEP styles
1240 Handle(StepVisual_StyledItem) override;
1241 TopTools_MapOfShape Map;
1243 MakeSTEPStyles(Styles,S,settings,override,Map,myMapCompMDGPR,DPDCs,ColRGBs,CTool,0,isComponent);
1245 // create MDGPR and record it in model
1246 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1249 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1251 cerr << "Error: Current Top-Level shape have MDGPR already " << endl;
1254 Styles.CreateMDGPR ( Context, aMDGPR );
1255 if (!aMDGPR.IsNull())
1256 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1259 // create SDR and add to model.
1260 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1261 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1262 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1263 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1264 if ( FP->FindTypedTransient(mapper,
1265 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1267 // create SDR for NAUO
1268 Handle(StepRepr_ProductDefinitionShape) nullPDS; // important to be NULL
1269 Styles.CreateNAUOSRD( Context, CDSR, nullPDS );
1271 // search for MDGPR of the component top-level shape
1272 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1273 aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1275 aMDGPR = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
1276 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
1277 aMDGPR->SetName( ReprName );
1278 aMDGPR->SetContextOfItems( Context );
1279 myMapCompMDGPR.Bind ( aTopSh, aMDGPR );
1281 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1282 Standard_Integer oldLengthlen = 0;
1283 if (!oldItems.IsNull())
1284 oldLengthlen = oldItems->Length();
1285 const Standard_Integer nbIt = oldLengthlen + Styles.NbStyles();
1288 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1289 new StepRepr_HArray1OfRepresentationItem(1, nbIt);
1290 Standard_Integer si;
1291 Standard_Integer el = 1;
1292 for ( si=1; si <= oldLengthlen; si++ )
1293 newItems->SetValue( el++, oldItems->Value( si ) );
1294 for ( si=1; si <= Styles.NbStyles(); si++ ) {
1295 newItems->SetValue( el++, Styles.Style(si));
1298 if (newItems->Length() > 0)
1299 aMDGPR->SetItems( newItems );
1300 } //end of work with CDSR
1303 // create invisibility item and refer for stiledItem
1304 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1305 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1306 new StepVisual_HArray1OfInvisibleItem (1,Styles.NbStyles());
1307 // put all style item into the harray
1308 for ( Standard_Integer si=1; si <= Styles.NbStyles(); si++ ) {
1309 Handle(StepRepr_RepresentationItem) styledItm = Styles.Style(si);
1310 StepVisual_InvisibleItem anInvItem;
1311 anInvItem.SetValue( styledItm );
1312 HInvsblItm->SetValue( si, anInvItem );
1314 // set the invisibility of items
1315 Invsblt->Init( HInvsblItm );
1316 WS->Model()->AddWithRefs( Invsblt );
1320 return Standard_True;
1324 //=======================================================================
1325 //function : WriteNames
1327 //=======================================================================
1329 Standard_Boolean STEPCAFControl_Writer::WriteNames (const Handle(XSControl_WorkSession) &WS,
1330 const TDF_LabelSequence &labels) const
1332 if ( labels.Length() <=0 ) return Standard_False;
1335 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1336 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1338 // Iterate on requested shapes
1339 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1340 TDF_Label L = labels.Value(i);
1343 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1344 if ( ! GetLabelName (L, hName) ) continue;
1345 // Handle(TDataStd_Name) N;
1346 // if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) continue;
1347 // TCollection_ExtendedString name = N->Get();
1348 // if ( name.Length() <=0 ) continue;
1350 // find target STEP entity for the current shape
1352 // if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1353 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1354 TopoDS_Shape S = myLabels.Find ( L );
1356 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
1357 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1358 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
1360 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
1365 // set the name to the PRODUCT
1366 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
1367 if ( PropD.IsNull() ) continue;
1368 Handle(StepBasic_ProductDefinition) PD = PropD->Definition().ProductDefinition();
1369 if ( PD.IsNull() ) continue;
1370 Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
1372 Prod->SetId ( hName );
1373 Prod->SetName ( hName );
1375 // write names for components of assemblies
1376 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1377 TDF_LabelSequence seq;
1378 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1379 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1380 TDF_Label lab = seq(k);
1382 // get shape with correct location
1384 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1385 ! myLabels.IsBound ( Lref ) ) continue;
1386 S = myLabels.Find ( Lref );
1387 S.Move ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
1389 hName = new TCollection_HAsciiString;
1390 if ( ! GetLabelName (lab, hName) ) continue;
1392 // find the target CDSR corresponding to a shape
1393 mapper = TransferBRep::ShapeMapper ( FP, S );
1394 Handle(Transfer_Binder) binder = FP->Find ( mapper );
1395 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1396 if ( ! FP->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), CDSR) )
1398 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1399 Handle(StepBasic_ProductDefinitionRelationship) NAUO = PDS->Definition().ProductDefinitionRelationship();
1400 if ( ! NAUO.IsNull() ) NAUO->SetName ( hName );
1405 return Standard_True;
1409 //=======================================================================
1410 //function : WritePropsForLabel
1412 //=======================================================================
1413 static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession) &WS,
1414 const Handle(XCAFDoc_ShapeTool) &aSTool,
1415 const STEPCAFControl_DataMapOfLabelShape &myLabels,
1417 const Standard_CString multi)
1419 if(L.IsNull()) return Standard_False;
1421 STEPConstruct_ValidationProps Props ( WS );
1423 TopoDS_Shape S = aSTool->GetShape(L);
1424 if(S.IsNull()) return Standard_False;
1426 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1428 Handle(XCAFDoc_Area) A;
1429 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1430 if ( ! A.IsNull() ) {
1431 Props.AddArea ( S, A->Get() );
1434 Handle(XCAFDoc_Volume) V;
1435 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1436 if ( ! V.IsNull() ) {
1437 Props.AddVolume ( S, V->Get() );
1441 Handle(XCAFDoc_Centroid) C;
1442 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1443 if ( ! C.IsNull() ) {
1444 Props.AddCentroid ( S, C->Get() );
1447 if( XCAFDoc_ShapeTool::IsCompound(L) || XCAFDoc_ShapeTool::IsAssembly(L) ) {
1449 for(Standard_Integer ich=1; ich<=L.NbChildren(); ich++) {
1450 WritePropsForLabel(WS,aSTool,myLabels,L.FindChild(ich),multi);
1455 return Standard_True;
1459 //=======================================================================
1460 //function : WriteValProps
1462 //=======================================================================
1464 Standard_Boolean STEPCAFControl_Writer::WriteValProps (const Handle(XSControl_WorkSession) &WS,
1465 const TDF_LabelSequence &labels,
1466 const Standard_CString multi) const
1468 if ( labels.Length() <=0 ) return Standard_False;
1471 // STEPConstruct_ValidationProps Props ( WS );
1472 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1474 // Iterate on requested shapes
1475 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1476 TDF_Label L = labels.Value(i);
1478 WritePropsForLabel(WS,aSTool,myLabels,L,multi);
1480 // find target STEP entity for the current shape
1481 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1482 TopoDS_Shape S = myLabels.Find ( L );
1484 // write area and volume (except for components in multifile mode)
1485 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1486 Handle(XCAFDoc_Area) A;
1487 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1488 if ( ! A.IsNull() ) Props.AddArea ( S, A->Get() );
1490 Handle(XCAFDoc_Volume) V;
1491 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1492 if ( ! V.IsNull() ) Props.AddVolume ( S, V->Get() );
1496 Handle(XCAFDoc_Centroid) C;
1497 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1498 if ( ! C.IsNull() ) Props.AddCentroid ( S, C->Get() );
1500 // write centroid for components of assemblies
1501 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1502 TDF_LabelSequence seq;
1503 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1504 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1505 TDF_Label lab = seq(k);
1507 // get shape with correct location
1509 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1510 ! myLabels.IsBound ( Lref ) ) continue;
1511 TopLoc_Location Loc = XCAFDoc_ShapeTool::GetLocation ( lab );
1512 S = myLabels.Find ( Lref );
1516 lab.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1517 // if centroid is not assigned to an instance,
1518 // use (shifted) centroid of original shape
1521 Lref.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1522 if ( C.IsNull() ) continue;
1523 center = C->Get().Transformed ( Loc.Transformation() );
1525 else center = C->Get();
1527 Props.AddCentroid ( S, center, Standard_True );
1533 return Standard_True;
1537 //=======================================================================
1538 //function : WriteLayers
1540 //=======================================================================
1542 Standard_Boolean STEPCAFControl_Writer::WriteLayers (const Handle(XSControl_WorkSession) &WS,
1543 const TDF_LabelSequence &labels ) const
1546 if ( labels.Length() <=0 ) return Standard_False;
1549 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1550 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1551 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1552 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( labels(1) );
1553 if (LTool.IsNull() ) return Standard_False;
1555 TDF_LabelSequence LayerLS;
1556 LTool->GetLayerLabels(LayerLS);
1557 if ( LayerLS.Length() <=0 ) return Standard_False;
1559 // Iterate on requested layers and for each layer take set of shapes.
1560 for ( Standard_Integer i=1; i <= LayerLS.Length(); i++ ) {
1561 TDF_Label L = LayerLS.Value(i);
1563 // get labels of shapes in that layer
1564 TDF_LabelSequence ShapeLs;
1565 LTool->GetShapesOfLayer(L, ShapeLs);
1566 if ( ShapeLs.Length() <=0 ) continue;
1568 // name of layer: if not set, is considered as being empty
1569 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1570 GetLabelName ( L, hName );
1572 // Find target STEP entity for each shape and add to StepVisual_PresentationLayerAssignment items.
1573 TColStd_SequenceOfTransient seqRI;
1574 for ( Standard_Integer j=1; j <= ShapeLs.Length(); j++) {
1575 TDF_Label shLabel = ShapeLs.Value(j);
1576 if ( shLabel.IsNull() ) continue;
1578 // there is no way to assign layer to instance in STEP
1579 if ( XCAFDoc_ShapeTool::IsAssembly ( shLabel ) ||
1580 XCAFDoc_ShapeTool::IsReference ( shLabel ) )
1583 // check that the shape is one of (uub)labels written during current transfer
1584 Standard_Integer k = 1;
1585 for ( ; k <= labels.Length(); k++ )
1586 if ( shLabel.IsDescendant ( labels(k) ) ) break;
1587 if ( k > labels.Length() ) continue;
1589 // get target STEP entity
1590 TopoDS_Shape oneShape = XCAFDoc_ShapeTool::GetShape(shLabel);
1592 TopLoc_Location Loc;
1593 Standard_Integer nb =
1594 FindEntities ( FP, oneShape, Loc, seqRI );
1596 FP->Messenger() << "Warning: Cannot find RI for " << oneShape.TShape()->DynamicType()->Name() << endl;
1598 if ( seqRI.Length() <= 0 ) continue;
1600 // analyze visibility
1601 Handle(StepVisual_PresentationLayerAssignment) StepLayerAs = new StepVisual_PresentationLayerAssignment;
1602 Handle(TCollection_HAsciiString) descr;
1603 Handle(TDataStd_UAttribute) aUAttr;
1604 Standard_Boolean isLinv = Standard_False;
1605 if (L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr)) {
1606 descr = new TCollection_HAsciiString ("invisible");
1608 FP->Messenger() << "\tLayer \"" << hName->String().ToCString() << "\" is invisible"<<endl;
1610 isLinv = Standard_True;
1612 else descr = new TCollection_HAsciiString ("visible");
1614 // create layer entity
1615 Handle(StepVisual_HArray1OfLayeredItem) HArrayOfLItem =
1616 new StepVisual_HArray1OfLayeredItem ( 1, seqRI.Length() );
1617 for (Standard_Integer i1 = 1; i1<=seqRI.Length(); i1++) {
1618 StepVisual_LayeredItem LI;
1619 LI.SetValue ( seqRI.Value(i1) );
1620 HArrayOfLItem->SetValue( i1, LI );
1622 StepLayerAs->Init(hName, descr, HArrayOfLItem);
1623 Model->AddWithRefs( StepLayerAs );
1624 // PTV 23.01.2003 add the invisibility AFTER adding layer into the model.
1625 // add the invisibility for the layer
1627 // Invisibility Item for containig invisible layers.
1628 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm = new StepVisual_HArray1OfInvisibleItem (1,1);
1629 StepVisual_InvisibleItem InvIt;
1630 InvIt.SetValue( StepLayerAs );
1631 HInvsblItm->SetValue( 1, InvIt);
1633 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1634 Invsblt->Init( HInvsblItm );
1635 Model->AddWithRefs( Invsblt );
1638 return Standard_True;
1642 //=======================================================================
1643 //function : getSHUOstyle
1644 //purpose : auxilary
1645 //=======================================================================
1646 static Standard_Boolean getSHUOstyle(const TDF_Label& aSHUOlab,
1647 const Handle(XCAFDoc_ColorTool)& CTool,
1648 XCAFPrs_Style& SHUOstyle)
1651 if (!CTool->IsVisible( aSHUOlab ) )
1652 SHUOstyle.SetVisibility(Standard_False);
1654 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) {
1655 SHUOstyle.SetColorCurv ( C );
1656 SHUOstyle.SetColorSurf ( C );
1658 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) )
1659 SHUOstyle.SetColorSurf ( C );
1660 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) )
1661 SHUOstyle.SetColorCurv ( C );
1663 if ( !SHUOstyle.IsSetColorCurv() &&
1664 !SHUOstyle.IsSetColorSurf() &&
1665 SHUOstyle.IsVisible() )
1666 return Standard_False;
1667 return Standard_True;
1671 //=======================================================================
1672 //function : getProDefinitionOfNAUO
1673 //purpose : auxilary
1674 //=======================================================================
1675 static Standard_Boolean getProDefinitionOfNAUO(const Handle(XSControl_WorkSession)& WS,
1676 const TopoDS_Shape& theShape,
1677 Handle(StepBasic_ProductDefinition)& PD,
1678 Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO,
1679 Standard_Boolean IsRelating)
1681 if ( theShape.IsNull() )
1682 return Standard_False;
1684 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1685 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1686 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1687 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, theShape );
1688 if (!FP->FindTypedTransient(mapper,
1689 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1691 return Standard_False;
1693 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1695 return Standard_False;
1696 // get the NAUO entity
1697 Interface_Graph aGraph = WS->HGraph()->Graph();
1698 Interface_EntityIterator subs = aGraph.Shareds(PDS);
1699 for ( subs.Start(); subs.More(); subs.Next() ) {
1700 if (!subs.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)))
1702 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value());
1705 if ( NAUO.IsNull() )
1706 return Standard_False;
1707 // get Relatinf or Related product definition
1709 PD = NAUO->RelatedProductDefinition();
1711 PD = NAUO->RelatingProductDefinition();
1713 return Standard_False;
1714 return Standard_True;
1718 //=======================================================================
1719 //function : writeSHUO
1720 //purpose : auxilary
1721 //=======================================================================
1722 static Standard_Boolean writeSHUO (const Handle(XCAFDoc_GraphNode)& theSHUO,
1723 const Handle(XCAFDoc_ShapeTool)& theSTool,
1724 const Handle(XSControl_WorkSession)& WS,
1725 Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO,
1726 TopoDS_Shape& NAUOShape,
1727 Handle(StepBasic_ProductDefinition)& theRelatingPD,
1728 Standard_Boolean& isDeepest)
1730 // set the ProductDefinitionRelationship descriptin information as empty strings.
1731 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
1733 TDF_LabelSequence aNextUsageLabs;
1734 theSTool->GetSHUONextUsage( theSHUO->Label(), aNextUsageLabs );
1735 Handle(XCAFDoc_GraphNode) NuSHUO;
1736 if ( theTopSHUO.IsNull() ) {
1738 if (aNextUsageLabs.Length() < 1)
1739 return Standard_False;
1740 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1741 if (NuSHUO.IsNull())
1742 return Standard_False;
1743 // get relating product definition
1744 TopoDS_Shape aTopCompShape = theSTool->GetShape( theSHUO->Label().Father() );
1745 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO;
1746 if (!getProDefinitionOfNAUO( WS, aTopCompShape,
1747 theRelatingPD, UUNAUO, Standard_True ))
1748 return Standard_False;
1749 // get related product definition
1750 TopoDS_Shape aNUShape = theSTool->GetShape( NuSHUO->Label().Father() );
1751 Handle(StepBasic_ProductDefinition) aRelatedPD;
1752 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO;
1753 if (!getProDefinitionOfNAUO( WS, aNUShape,
1754 aRelatedPD, NUNAUO, Standard_False ))
1755 return Standard_False;
1757 theTopSHUO = new StepRepr_SpecifiedHigherUsageOccurrence;
1758 // create deepest shuo EmptyString
1759 theTopSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1760 /*no description*/Standard_False,/*description*/EmptyString,
1761 theRelatingPD, aRelatedPD,
1762 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1763 /*upper_usage*/UUNAUO, /*next_usage*/NUNAUO);
1764 // write the other SHUO.
1765 if(!writeSHUO( NuSHUO, theSTool, WS, theTopSHUO, NAUOShape, theRelatingPD, isDeepest )) {
1766 theTopSHUO.Nullify();
1767 return Standard_False;
1770 return Standard_True;
1772 // Handle(XCAFDoc_GraphNode) NuSHUO;
1773 if ( aNextUsageLabs.Length() > 0) {
1774 // store SHUO recursive
1776 if ( aNextUsageLabs.Length() > 1 )
1777 cout << "Warning: store only one next_usage of current SHUO" << endl;
1779 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1780 Handle(StepRepr_SpecifiedHigherUsageOccurrence) aNUEntSHUO =
1781 new StepRepr_SpecifiedHigherUsageOccurrence;
1782 if (!writeSHUO( NuSHUO, theSTool, WS, aNUEntSHUO, NAUOShape, theRelatingPD, isDeepest ))
1783 return Standard_False;
1785 // store the deepest SHUO to the dociment
1786 TopoDS_Shape aNUSh, aUUSh;
1787 aNUSh = theSTool->GetShape( NuSHUO->Label().Father() );
1788 aUUSh = theSTool->GetShape( theSHUO->Label().Father() );
1789 // get relating PD with upper_usage and related PD with next_usage
1790 Handle(StepBasic_ProductDefinition) nullPD;// no need to use,case have shared <theRelatingPD>
1791 Handle(StepBasic_ProductDefinition) aRelatedPD;
1792 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO, NUNAUO;
1793 if (!getProDefinitionOfNAUO( WS, aUUSh, nullPD, UUNAUO, Standard_True ) ||
1794 !getProDefinitionOfNAUO( WS, aNUSh, aRelatedPD, NUNAUO, Standard_False )) {
1796 cout << "Warning: cannot get related or relating PD" << endl;
1798 return Standard_False;
1800 aNUEntSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1801 /*no description*/Standard_False,/*description*/EmptyString,
1802 theRelatingPD, aRelatedPD,
1803 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1804 /*upper_usage*/theTopSHUO, /*next_usage*/NUNAUO);
1806 isDeepest = Standard_False;
1808 WS->Model()->AddWithRefs ( aNUEntSHUO );
1809 return Standard_True;
1810 } // end of recurse storing
1813 TDF_Label aShapeL = theSHUO->Label().Father();
1814 NAUOShape = theSTool->GetShape( aShapeL );
1815 // return to the deepest level from SHUO shape level
1816 // it is because SHUO is attribute on deep level and shape level.
1817 isDeepest = Standard_True;
1818 return Standard_True;
1822 //=======================================================================
1823 //function : createSHUOStyledItem
1824 //purpose : auxilary
1825 //=======================================================================
1826 static Standard_Boolean createSHUOStyledItem (const XCAFPrs_Style& style,
1827 const Handle(StepRepr_ProductDefinitionShape)& PDS,
1828 const Handle(XSControl_WorkSession) &WS,
1829 const TopoDS_Shape& Sh,
1830 const Handle(XCAFDoc_ShapeTool)& STool,
1831 MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
1833 // create styled item for the indicated SHUO and store to the model
1834 STEPConstruct_Styles Styles( WS );
1835 // translate colors to STEP
1836 Handle(StepVisual_Colour) surfColor, curvColor;
1837 if ( style.IsSetColorSurf() )
1838 surfColor = Styles.EncodeColor ( style.GetColorSurf() );
1839 if ( style.IsSetColorCurv() )
1840 curvColor = Styles.EncodeColor ( style.GetColorCurv() );
1841 Standard_Boolean isComponent = Standard_True;// cause need to get PSBC
1842 Handle(StepRepr_RepresentationItem) item;
1843 // set default color for invisible SHUO.
1844 Standard_Boolean isSetDefaultColor = Standard_False;
1845 if (surfColor.IsNull() && curvColor.IsNull() && !style.IsVisible() ) {
1846 surfColor = Styles.EncodeColor ( Quantity_Color( 1, 1, 1, Quantity_TOC_RGB ) );
1847 isSetDefaultColor = Standard_True;
1849 Handle(StepVisual_PresentationStyleAssignment) PSA =
1850 Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1851 Handle(StepVisual_StyledItem) override; //null styled item
1853 // find the repr item of the shape
1854 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1855 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1856 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, Sh );
1857 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1858 FP->FindTypedTransient(mapper,
1859 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1861 if ( CDSR.IsNull() )
1862 return Standard_False;
1864 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext( Sh );
1865 TopoDS_Shape aTopSh = Sh;
1866 if (Context.IsNull()) {
1867 TDF_Label aTopShL = STool->FindShape(Sh, Standard_False);
1868 if (aTopShL.IsNull())
1869 return Standard_False;
1870 aTopSh = STool->GetShape( aTopShL );
1871 Context = Styles.FindContext ( aTopSh );
1873 if (Context.IsNull())
1874 return Standard_False;
1875 // get representation item of the shape
1877 TColStd_SequenceOfTransient seqRI;
1878 FindEntities ( FP, Sh, L, seqRI );
1880 if ( seqRI.Length() <=0 )
1881 FP->Messenger() << "Warning: Cannot find RI for " << Sh.TShape()->DynamicType()->Name() << endl;
1883 item = Handle(StepRepr_RepresentationItem)::DownCast(seqRI(1));
1884 //get overridden styled item
1885 getStyledItem(Sh,STool, Styles, override,myMapCompMDGPR);
1887 // get STEP STYLED ITEM
1888 Handle(StepVisual_StyledItem) STEPstyle = Styles.AddStyle ( item, PSA, override );
1889 // create SR, SDR and all necessary references between them and ST, PDS, PSBC, GRC
1890 Styles.CreateNAUOSRD( Context, CDSR, PDS );
1892 // add step styled item of SHUO to the model
1893 // do it by additing styled item to the MDGPR
1894 if ( !aTopSh.IsNull() && !myMapCompMDGPR.IsBound( aTopSh ) ) {
1895 // create MDGPR and record it in model
1897 cout << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance" << endl;
1899 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1900 Styles.CreateMDGPR ( Context, aMDGPR );
1901 if (!aMDGPR.IsNull())
1902 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1904 else if ( !aTopSh.IsNull() && myMapCompMDGPR.IsBound( aTopSh ) ) {
1905 // get MDGPR of the top-level shape
1906 Handle(StepVisual_PresentationRepresentation) aMDGPR =
1907 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1908 // get old styled items to not lose it
1909 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1910 Standard_Integer oldLengthlen = 0;
1911 if (!oldItems.IsNull())
1912 oldLengthlen = oldItems->Length();
1913 // create new array of styled items by an olds and new one
1914 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1915 new StepRepr_HArray1OfRepresentationItem(1, oldLengthlen + 1);
1916 Standard_Integer si;
1917 Standard_Integer el = 1;
1918 for ( si=1; si <= oldLengthlen; si++ )
1919 newItems->SetValue( el++, oldItems->Value( si ) );
1920 newItems->SetValue (el++, STEPstyle);
1921 // init MDGPR be new array of styled items
1922 if (newItems->Length() > 0)
1923 aMDGPR->SetItems( newItems );
1926 WS->Model()->AddWithRefs ( STEPstyle ); // add as root to the model, but it is not good
1928 cout << "Warning: " << __FILE__ << ": adds styled item of SHUO as root, casue cannot find MDGPR" << endl;
1931 // create invisibility item for the styled item
1932 if ( !style.IsVisible() ) {
1933 if (isSetDefaultColor) {
1934 // try to set default color from top-level shape
1936 setDefaultInstanceColor(override, PSA);
1938 // create invisibility item and refer for stiledItem
1939 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1940 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1941 new StepVisual_HArray1OfInvisibleItem (1,1);
1942 // put all style item into the harray
1943 StepVisual_InvisibleItem anInvItem;
1944 anInvItem.SetValue( STEPstyle );
1945 HInvsblItm->SetValue( 1, anInvItem );
1946 Invsblt->Init( HInvsblItm );
1947 WS->Model()->AddWithRefs( Invsblt );
1950 return Standard_True;
1954 //=======================================================================
1955 //function : WriteSHUOs
1957 //=======================================================================
1959 Standard_Boolean STEPCAFControl_Writer::WriteSHUOs (const Handle(XSControl_WorkSession) &WS,
1960 const TDF_LabelSequence &labels )
1962 if ( labels.Length() <=0 ) return Standard_False;
1965 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1966 if (CTool.IsNull() )
1967 return Standard_False;
1968 // map of transfered SHUO
1969 TColStd_MapOfTransient aMapOfMainSHUO;
1970 // Iterate on requested shapes
1971 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1972 TDF_Label L = labels.Value(i);
1973 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1974 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1975 TDF_LabelSequence seq;
1976 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1977 // iterates on components of assembly
1978 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1979 TDF_Label lab = seq(k);
1980 TDF_AttributeSequence anAttrSeq;
1981 CTool->ShapeTool()->GetAllComponentSHUO( lab, anAttrSeq );
1983 for (Standard_Integer j = 1; j <= anAttrSeq.Length(); j++) {
1984 Handle(XCAFDoc_GraphNode) aSHUO =
1985 Handle(XCAFDoc_GraphNode)::DownCast(anAttrSeq.Value( j ));
1986 // take label of SHUO
1987 TDF_Label aSHUOlab = aSHUO->Label();
1988 TDF_LabelSequence aUpLabels;
1989 // check is it SHUO of upper_usage
1990 CTool->ShapeTool()->GetSHUOUpperUsage( aSHUOlab, aUpLabels );
1991 if ( aUpLabels.Length() > 0 )
1992 continue; // transfer only main SHUO
1993 if ( aMapOfMainSHUO.Contains( aSHUO ) )
1994 continue; // do not try to transfer SHUO twice
1995 aMapOfMainSHUO.Add( aSHUO );
1996 // check if it is styled SHUO
1997 XCAFPrs_Style SHUOstyle;
1998 if ( !getSHUOstyle ( aSHUOlab, CTool, SHUOstyle ) ) {
2000 cout << "Warning: " << __FILE__ << ": do not store SHUO without any style to the STEP model" << endl;
2004 // write SHUO to the model amd then add structure type.
2005 TopoDS_Shape NAUOShape; // shape of the deepest NAUO in the SHUO structure
2006 Standard_Boolean isDeepest = Standard_False;
2007 Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO;
2008 Handle(StepBasic_ProductDefinition) aRelatingPD;
2009 // create the top SHUO and all other.
2010 writeSHUO( aSHUO, CTool->ShapeTool(), WS, anEntOfSHUO, NAUOShape, aRelatingPD, isDeepest );
2011 if ( anEntOfSHUO.IsNull() || NAUOShape.IsNull() ) {
2013 cout << "Warning: " << __FILE__ << ": Cannot store SHUO" << endl;
2017 // create new Product Definition Shape for TOP SHUO
2019 cout << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO " << endl;
2021 Handle(StepRepr_ProductDefinitionShape) PDS = new StepRepr_ProductDefinitionShape;
2022 Handle(TCollection_HAsciiString) aPDSname = new TCollection_HAsciiString("SHUO");
2023 Handle(TCollection_HAsciiString) descrStr = new TCollection_HAsciiString("");
2024 StepRepr_CharacterizedDefinition aCharDef;
2025 aCharDef.SetValue( anEntOfSHUO );
2026 PDS->Init( aPDSname, Standard_False, descrStr, aCharDef );
2028 // create styled item for SHUO and add to the model
2029 createSHUOStyledItem ( SHUOstyle, PDS, WS, NAUOShape, CTool->ShapeTool(), myMapCompMDGPR );
2031 } // end work with SHUO
2032 } // end of an assembly components
2033 } // end of IsAssembly case
2034 // nothing to do if it is not assembly
2036 } // end of iterates on indicated labels
2037 return Standard_True;
2041 //=======================================================================
2042 //function : FindPDSforDGT
2043 //purpose : auxilary: find PDS for AdvancedFace or EdgeCurve for creation
2044 // needed ShapeAspect in D> structure
2045 //=======================================================================
2046 static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph,
2047 const Handle(Standard_Transient) &ent,
2048 Handle(StepRepr_ProductDefinitionShape) &PDS,
2049 Handle(StepRepr_RepresentationContext) &RC,
2050 Handle(StepShape_AdvancedFace) &AF,
2051 Handle(StepShape_EdgeCurve) &EC)
2053 if( !ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) &&
2054 !ent->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)) )
2055 return Standard_False;
2057 AF = Handle(StepShape_AdvancedFace)::DownCast(ent);
2058 if( ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) ) {
2059 EC = Handle(StepShape_EdgeCurve)::DownCast(ent);
2060 Interface_EntityIterator subs = aGraph.Sharings(EC);
2061 for(subs.Start(); subs.More() && AF.IsNull(); subs.Next()) {
2062 Handle(StepShape_OrientedEdge) OE = Handle(StepShape_OrientedEdge)::DownCast(subs.Value());
2063 if(OE.IsNull()) continue;
2064 Interface_EntityIterator subs1 = aGraph.Sharings(OE);
2065 for(subs1.Start(); subs1.More() && AF.IsNull(); subs1.Next()) {
2066 Handle(StepShape_EdgeLoop) EL = Handle(StepShape_EdgeLoop)::DownCast(subs1.Value());
2067 if(EL.IsNull()) continue;
2068 Interface_EntityIterator subs2 = aGraph.Sharings(EL);
2069 for(subs2.Start(); subs2.More() && AF.IsNull(); subs2.Next()) {
2070 Handle(StepShape_FaceBound) FB = Handle(StepShape_FaceBound)::DownCast(subs2.Value());
2071 if(FB.IsNull()) continue;
2072 Interface_EntityIterator subs3 = aGraph.Sharings(FB);
2073 for(subs3.Start(); subs3.More() && AF.IsNull(); subs3.Next()) {
2074 AF = Handle(StepShape_AdvancedFace)::DownCast(subs3.Value());
2080 if(AF.IsNull()) return Standard_False;
2082 Interface_EntityIterator subs = aGraph.Sharings(AF);
2083 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
2084 Handle(StepShape_ConnectedFaceSet) CFS =
2085 Handle(StepShape_ConnectedFaceSet)::DownCast(subs.Value());
2086 if(CFS.IsNull()) continue;
2087 Interface_EntityIterator subs1 = aGraph.Sharings(CFS);
2088 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
2089 Handle(StepRepr_RepresentationItem) RI =
2090 Handle(StepRepr_RepresentationItem)::DownCast(subs1.Value());
2091 if(RI.IsNull()) continue;
2092 Interface_EntityIterator subs2 = aGraph.Sharings(RI);
2093 for(subs2.Start(); subs2.More() && PDS.IsNull(); subs2.Next()) {
2094 Handle(StepShape_ShapeRepresentation) SR =
2095 Handle(StepShape_ShapeRepresentation)::DownCast(subs2.Value());
2096 if(SR.IsNull()) continue;
2097 RC = SR->ContextOfItems();
2098 Interface_EntityIterator subs3 = aGraph.Sharings(SR);
2099 for(subs3.Start(); subs3.More() && PDS.IsNull(); subs3.Next()) {
2100 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2101 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs3.Value());
2102 if(SDR.IsNull()) continue;
2103 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
2104 if(PropD.IsNull()) continue;
2105 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
2111 return Standard_True;
2114 //=======================================================================
2115 //function : FindPDS
2116 //purpose : auxilary: find Product_definition_shape entity for given entity
2117 //=======================================================================
2118 static Handle(StepRepr_ProductDefinitionShape) FindPDS(const Interface_Graph &theGraph,
2119 const Handle(Standard_Transient) &theEnt,
2120 Handle(StepRepr_RepresentationContext) &theRC)
2122 if (theEnt.IsNull())
2124 Handle(StepRepr_ProductDefinitionShape) aPDS;
2126 // try to find shape_representation in sharings
2127 Interface_EntityIterator anIter = theGraph.Sharings(theEnt);
2128 for (anIter.Start(); anIter.More() && aPDS.IsNull(); anIter.Next()) {
2129 Handle(StepShape_ShapeRepresentation) aSR = Handle(StepShape_ShapeRepresentation)::DownCast(anIter.Value());
2132 theRC = aSR->ContextOfItems();
2133 Interface_EntityIterator aSDRIt = theGraph.Sharings(aSR);
2134 for (aSDRIt.Start(); aSDRIt.More() && aPDS.IsNull(); aSDRIt.Next()) {
2135 Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
2136 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value());
2137 if (aSDR.IsNull()) continue;
2138 Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition();
2139 if (aPropD.IsNull()) continue;
2140 aPDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aPropD);
2146 anIter = theGraph.Sharings(theEnt);
2147 for (anIter.Start(); anIter.More(); anIter.Next()) {
2148 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)) ||
2149 anIter.Value()->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem)))
2151 aPDS = FindPDS(theGraph, anIter.Value(), theRC);
2160 //=======================================================================
2161 //function : GetUnit
2162 //purpose : auxiliary
2163 //=======================================================================
2164 static StepBasic_Unit GetUnit(const Handle(StepRepr_RepresentationContext)& theRC,
2165 const Standard_Boolean isAngle = Standard_False)
2167 StepBasic_Unit aUnit;
2169 Handle(StepBasic_SiUnitAndPlaneAngleUnit) aSiPAU;
2170 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
2171 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
2172 if(!aCtx.IsNull()) {
2173 for(Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) {
2174 if(aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))) {
2175 aSiPAU = Handle(StepBasic_SiUnitAndPlaneAngleUnit)::DownCast(aCtx->UnitsValue(j));
2180 if(aSiPAU.IsNull()) {
2181 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
2182 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
2183 if(!aCtx1.IsNull()) {
2184 for(Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) {
2185 if(aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))) {
2186 aSiPAU = Handle(StepBasic_SiUnitAndPlaneAngleUnit)::DownCast(aCtx1->UnitsValue(j));
2193 aSiPAU = new StepBasic_SiUnitAndPlaneAngleUnit;
2194 aUnit.SetValue(aSiPAU);
2197 Handle(StepBasic_SiUnitAndLengthUnit) aSiLU;
2198 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
2199 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
2200 if(!aCtx.IsNull()) {
2201 for(Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) {
2202 if(aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2203 aSiLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(aCtx->UnitsValue(j));
2208 if(aSiLU.IsNull()) {
2209 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
2210 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
2211 if(!aCtx1.IsNull()) {
2212 for(Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) {
2213 if(aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2214 aSiLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(aCtx1->UnitsValue(j));
2221 aSiLU = new StepBasic_SiUnitAndLengthUnit;
2222 aUnit.SetValue(aSiLU);
2227 //=======================================================================
2228 //function : CreateDimValue
2229 //purpose : auxiliary
2230 //======================================================================
2231 static Handle(StepRepr_ReprItemAndMeasureWithUnit) CreateDimValue(const Standard_Real theValue,
2232 const StepBasic_Unit theUnit,
2233 const Handle(TCollection_HAsciiString)& theName,
2234 const Standard_CString theMeasureName,
2235 const Standard_Boolean isAngle,
2236 const Standard_Boolean isQualified = Standard_False,
2237 const Handle(StepShape_QualifiedRepresentationItem)& theQRI = NULL)
2239 Handle(StepRepr_RepresentationItem) aReprItem = new StepRepr_RepresentationItem();
2240 aReprItem->Init(new TCollection_HAsciiString(theName));
2241 Handle(StepBasic_MeasureWithUnit) aMWU = new StepBasic_MeasureWithUnit();
2242 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
2243 aValueMember->SetName(theMeasureName);
2244 aValueMember->SetReal(theValue);
2245 aMWU->Init(aValueMember, theUnit);
2248 // Angle & with qualifiers
2249 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI) anItem =
2250 new StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI();
2251 anItem->Init(aMWU, aReprItem, theQRI);
2255 // Length & with qualifiers
2256 Handle(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI) anItem =
2257 new StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI();
2258 anItem->Init(aMWU, aReprItem, theQRI);
2264 // Angle & without qualifiers
2265 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) anItem =
2266 new StepRepr_ReprItemAndPlaneAngleMeasureWithUnit();
2267 anItem->Init(aMWU, aReprItem);
2271 // Length & without qualifiers
2272 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) anItem =
2273 new StepRepr_ReprItemAndLengthMeasureWithUnit();
2274 anItem->Init(aMWU, aReprItem);
2280 //=======================================================================
2281 //function : WriteShapeAspect
2282 //purpose : auxiliary (write Shape_Aspect entity for given shape)
2283 //=======================================================================
2285 static Handle(StepRepr_ShapeAspect) WriteShapeAspect (const Handle(XSControl_WorkSession) &WS,
2286 const TDF_Label theLabel,
2287 const TopoDS_Shape theShape,
2288 Handle(StepRepr_RepresentationContext)& theRC,
2289 Handle(StepAP242_GeometricItemSpecificUsage)& theGISU)
2292 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2293 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
2294 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
2295 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2296 if (aHGraph.IsNull())
2298 Interface_Graph aGraph = aHGraph->Graph();
2300 TopLoc_Location aLoc;
2301 TColStd_SequenceOfTransient aSeqRI;
2302 FindEntities( FP, theShape, aLoc, aSeqRI );
2303 if ( aSeqRI.Length() <= 0 ) {
2304 FP->Messenger() << "Warning: Cannot find RI for "<<theShape.TShape()->DynamicType()->Name()<<endl;
2308 Handle(StepRepr_ProductDefinitionShape) aPDS;
2309 Handle(StepRepr_RepresentationContext) aRC;
2310 Handle(Standard_Transient) anEnt = aSeqRI.Value(1);
2311 aPDS = FindPDS(aGraph, anEnt, aRC);
2317 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString();
2318 Handle(TDataStd_Name) aNameAttr;
2319 if (theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) {
2320 aName = new TCollection_HAsciiString(TCollection_AsciiString(aNameAttr->Get(), '?'));
2321 Standard_Integer aFirstSpace = aName->Search(" ");
2322 if (aFirstSpace != -1)
2323 aName = aName->SubString(aFirstSpace + 1, aName->Length());
2325 aName = new TCollection_HAsciiString();
2327 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString();
2328 Handle(StepRepr_ShapeAspect) aSA = new StepRepr_ShapeAspect;
2329 aSA->Init(aName, aDescription, aPDS, StepData_LTrue);
2331 // Geometric_Item_Specific_Usage
2332 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2333 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2334 aDefinition.SetValue(aSA);
2335 Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
2336 Handle(StepRepr_RepresentationItem) anIdentifiedItem = Handle(StepRepr_RepresentationItem)::DownCast(anEnt);
2337 anReprItems->SetValue(1, anIdentifiedItem);
2338 Interface_EntityIterator subs = aGraph.Sharings(aPDS);
2339 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2340 for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) {
2341 Handle(Standard_Transient) anEntity = subs.Value();
2342 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity);
2347 // Set entities to model
2348 aGISU->Init(aName, aDescription, aDefinition, aSDR->UsedRepresentation(), anReprItems);
2349 Model->AddWithRefs(aSA);
2350 Model->AddWithRefs(aGISU);
2355 //=======================================================================
2356 //function : WritePresentation
2357 //purpose : auxiliary (write annotation plane and presentation)
2358 //======================================================================
2359 static void WritePresentation(const Handle(XSControl_WorkSession) &WS,
2360 const TopoDS_Shape thePresentation,
2361 const Handle(TCollection_HAsciiString)& thePrsName,
2362 const gp_Ax2 theAnnotationPlane,
2363 const gp_Pnt theTextPosition,
2364 const Handle(Standard_Transient) theDimension)
2366 if (thePresentation.IsNull())
2369 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2372 Handle(StepVisual_TessellatedGeometricSet) aGeomSet = STEPCAFControl_GDTProperty::GetTessellation(thePresentation);
2373 Handle(StepVisual_TessellatedAnnotationOccurrence) aTAO = new StepVisual_TessellatedAnnotationOccurrence();
2374 aTAO->Init(new TCollection_HAsciiString(), gdtPrsCurveStyle, aGeomSet);
2375 StepVisual_DraughtingCalloutElement aDCElement;
2376 aDCElement.SetValue(aTAO);
2377 Handle(StepVisual_HArray1OfDraughtingCalloutElement) aTAOs = new StepVisual_HArray1OfDraughtingCalloutElement(1, 1);
2378 aTAOs->SetValue(1, aDCElement);
2379 Handle(StepVisual_DraughtingCallout) aDCallout = new StepVisual_DraughtingCallout();
2380 Handle(TCollection_HAsciiString) aPrsName = thePrsName.IsNull() ? new TCollection_HAsciiString() : thePrsName;
2381 aDCallout->Init(aPrsName, aTAOs);
2382 Handle(StepRepr_HArray1OfRepresentationItem) aDCsForDMIA = new StepRepr_HArray1OfRepresentationItem(1, 1);
2383 aDCsForDMIA->SetValue(1, aDCallout);
2384 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDimension;
2385 aDimension.SetValue(theDimension);
2386 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
2387 new StepAP242_DraughtingModelItemAssociation();
2388 aDMIA->Init(new TCollection_HAsciiString("PMI representation to presentation link"),
2389 new TCollection_HAsciiString(), aDimension, gdtPresentationDM, aDCsForDMIA);
2390 aModel->AddWithRefs(aDMIA);
2393 // Presentation Style
2394 Handle(StepVisual_NullStyleMember) aNullStyle = new StepVisual_NullStyleMember();
2395 aNullStyle->SetEnumText(0, ".NULL.");
2396 StepVisual_PresentationStyleSelect aStyleItem;
2397 aStyleItem.SetValue(aNullStyle);
2398 Handle(StepVisual_HArray1OfPresentationStyleSelect) aStyles = new StepVisual_HArray1OfPresentationStyleSelect(1, 1);
2399 aStyles->SetValue(1, aStyleItem);
2400 Handle(StepVisual_PresentationStyleAssignment) aPrsStyle = new StepVisual_PresentationStyleAssignment();
2401 aPrsStyle->Init(aStyles);
2402 Handle(StepVisual_HArray1OfPresentationStyleAssignment) aPrsStyles =
2403 new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
2404 aPrsStyles->SetValue(1, aPrsStyle);
2406 Handle(StepGeom_Plane) aPlane = new StepGeom_Plane();
2407 Handle(StepGeom_Axis2Placement3d) anAxis = STEPCAFControl_GDTProperty::GetAxis2Placement3D(theAnnotationPlane);
2408 // Set text position to plane origin
2409 Handle(StepGeom_CartesianPoint) aTextPos = new StepGeom_CartesianPoint();
2410 Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
2411 for (Standard_Integer i = 1; i <= 3; i++)
2412 aCoords->SetValue(i, theTextPosition.Coord(i));
2413 aTextPos->Init(new TCollection_HAsciiString(), aCoords);
2414 anAxis->SetLocation(aTextPos);
2415 aPlane->Init(new TCollection_HAsciiString(), anAxis);
2416 // Annotation plane element
2417 StepVisual_AnnotationPlaneElement aPlaneElement;
2418 aPlaneElement.SetValue(aDCallout);
2419 Handle(StepVisual_HArray1OfAnnotationPlaneElement) aDCsForAnnPln = new StepVisual_HArray1OfAnnotationPlaneElement(1, 1);
2420 aDCsForAnnPln->SetValue(1, aPlaneElement);
2421 // Init AnnotationPlane entity
2422 Handle(StepVisual_AnnotationPlane) anAnnPlane = new StepVisual_AnnotationPlane();
2423 anAnnPlane->Init(new TCollection_HAsciiString(), aPrsStyles, aPlane, aDCsForAnnPln);
2424 gdtAnnotationPlanes.Append(anAnnPlane);
2425 aModel->AddWithRefs(anAnnPlane);
2428 //======================================================================
2429 //function : WritePresentation
2430 //purpose : auxiliary (write annotation plane and presentation for common labels)
2431 //======================================================================
2432 static void WritePresentation(const Handle(XSControl_WorkSession) &WS,
2433 const TopoDS_Shape thePresentation,
2434 const Handle(TCollection_HAsciiString)& thePrsName,
2435 const gp_Ax2 theAnnotationPlane)
2437 if (thePresentation.IsNull())
2440 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2443 Handle(StepVisual_TessellatedGeometricSet) aGeomSet = STEPCAFControl_GDTProperty::GetTessellation(thePresentation);
2444 Handle(StepVisual_TessellatedAnnotationOccurrence) aTAO = new StepVisual_TessellatedAnnotationOccurrence();
2445 aTAO->Init(new TCollection_HAsciiString(), gdtPrsCurveStyle, aGeomSet);
2446 StepVisual_DraughtingCalloutElement aDCElement;
2447 aDCElement.SetValue(aTAO);
2448 Handle(StepVisual_HArray1OfDraughtingCalloutElement) aTAOs = new StepVisual_HArray1OfDraughtingCalloutElement(1, 1);
2449 aTAOs->SetValue(1, aDCElement);
2450 Handle(StepVisual_DraughtingCallout) aDCallout = new StepVisual_DraughtingCallout();
2451 Handle(TCollection_HAsciiString) aPrsName = thePrsName.IsNull() ? new TCollection_HAsciiString() : thePrsName;
2452 aDCallout->Init(aPrsName, aTAOs);
2453 aModel->AddWithRefs(aDCallout);
2456 // Presentation Style
2457 Handle(StepVisual_NullStyleMember) aNullStyle = new StepVisual_NullStyleMember();
2458 aNullStyle->SetEnumText(0, ".NULL.");
2459 StepVisual_PresentationStyleSelect aStyleItem;
2460 aStyleItem.SetValue(aNullStyle);
2461 Handle(StepVisual_HArray1OfPresentationStyleSelect) aStyles = new StepVisual_HArray1OfPresentationStyleSelect(1, 1);
2462 aStyles->SetValue(1, aStyleItem);
2463 Handle(StepVisual_PresentationStyleAssignment) aPrsStyle = new StepVisual_PresentationStyleAssignment();
2464 aPrsStyle->Init(aStyles);
2465 Handle(StepVisual_HArray1OfPresentationStyleAssignment) aPrsStyles =
2466 new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
2467 aPrsStyles->SetValue(1, aPrsStyle);
2469 Handle(StepGeom_Plane) aPlane = new StepGeom_Plane();
2470 Handle(StepGeom_Axis2Placement3d) anAxis = STEPCAFControl_GDTProperty::GetAxis2Placement3D(theAnnotationPlane);
2471 aPlane->Init(new TCollection_HAsciiString(), anAxis);
2472 // Annotation plane element
2473 StepVisual_AnnotationPlaneElement aPlaneElement;
2474 aPlaneElement.SetValue(aDCallout);
2475 Handle(StepVisual_HArray1OfAnnotationPlaneElement) aDCsForAnnPln = new StepVisual_HArray1OfAnnotationPlaneElement(1, 1);
2476 aDCsForAnnPln->SetValue(1, aPlaneElement);
2477 // Init AnnotationPlane entity
2478 Handle(StepVisual_AnnotationPlane) anAnnPlane = new StepVisual_AnnotationPlane();
2479 anAnnPlane->Init(new TCollection_HAsciiString(), aPrsStyles, aPlane, aDCsForAnnPln);
2480 gdtAnnotationPlanes.Append(anAnnPlane);
2481 aModel->AddWithRefs(anAnnPlane);
2484 //=======================================================================
2485 //function : WriteDatumAP242
2486 //purpose : auxiliary (write Datum entity for given shape or write all
2487 // necessary entities and link them to already written datum
2488 // in case of multiple features association)
2489 //=======================================================================
2490 static Handle(StepDimTol_Datum) WriteDatumAP242(const Handle(XSControl_WorkSession) &WS,
2491 const TDF_Label theShapeL,
2492 const TDF_Label theDatumL,
2493 const Standard_Boolean isFirstDTarget,
2494 const Handle(StepDimTol_Datum) theWrittenDatum)
2497 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2498 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
2499 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
2500 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2501 if (aHGraph.IsNull())
2503 Interface_Graph aGraph = aHGraph->Graph();
2505 Handle(StepRepr_ShapeAspect) aSA;
2506 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2507 // Link with datum feature
2508 Handle(StepRepr_ProductDefinitionShape) aPDS;
2509 Handle(StepRepr_RepresentationContext) aRC;
2510 Handle(Standard_Transient) anEnt;
2511 TopoDS_Shape aShape;
2512 TopLoc_Location aLoc;
2513 TColStd_SequenceOfTransient aSeqRI;
2515 aShape = XCAFDoc_ShapeTool::GetShape(theShapeL);
2516 FindEntities( FP, aShape, aLoc, aSeqRI );
2517 if ( aSeqRI.Length() <= 0 ) {
2518 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
2521 anEnt = aSeqRI.Value(1);
2522 aPDS = FindPDS(aGraph, anEnt, aRC);
2526 aSA = WriteShapeAspect(WS, theDatumL, aShape, aRC, aGISU);
2529 Standard_Integer aSANum = Model->Number(aSA);
2530 Standard_Integer aGISUNum = Model->Number(aGISU);
2531 // Find if datum has datum targets and get common datum attributes
2532 Handle(XCAFDoc_Datum) aDatumAttr;
2533 if (!theDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
2535 Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject();
2536 if (anObject.IsNull())
2538 Standard_Boolean isSimpleDatum = !anObject->IsDatumTarget();
2539 Handle(TCollection_HAsciiString) anIdentifier = anObject->GetName();
2540 Handle(TCollection_HAsciiString) aTargetId = (anObject->GetDatumTargetNumber() == 0 ?
2541 new TCollection_HAsciiString() : new TCollection_HAsciiString(anObject->GetDatumTargetNumber()));
2543 // If datum type is area, but there is no area in object, write as simple datum
2544 if (anObject->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Area &&
2545 anObject->GetDatumTarget().IsNull())
2546 isSimpleDatum = Standard_True;
2549 if (isSimpleDatum) {
2550 Handle(StepDimTol_DatumFeature) aDF = new StepDimTol_DatumFeature();
2551 aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aSA->OfShape(), aSA->ProductDefinitional());
2552 Model->ReplaceEntity(aSANum, aDF);
2554 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2555 aDefinition.SetValue(aDF);
2556 aGISU->SetDefinition(aDefinition);
2557 Model->ReplaceEntity(aGISUNum, aGISU);
2559 // Datum with datum targets
2561 XCAFDimTolObjects_DatumTargetType aDatumType = anObject->GetDatumTargetType();
2562 Handle(StepDimTol_DatumTarget) aDatumTarget;
2563 // Note: the given way to write such datum type may be incorrect (too little information)
2564 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Area) {
2565 TopoDS_Shape aDTShape = anObject->GetDatumTarget();
2566 Handle(StepAP242_GeometricItemSpecificUsage) anAreaGISU;
2567 Handle(StepRepr_ShapeAspect) anAreaSA = WriteShapeAspect(WS, theDatumL, aDTShape, aRC, anAreaGISU);
2568 aSANum = Model->Number(anAreaSA);
2569 aGISUNum = Model->Number(anAreaGISU);
2570 Handle(StepDimTol_DatumTarget) aDT = new StepDimTol_DatumTarget();
2571 aDT->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString("area"), anAreaSA->OfShape(),
2572 anAreaSA->ProductDefinitional(), aTargetId);
2573 Model->ReplaceEntity(aSANum, aDT);
2574 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2575 aDefinition.SetValue(aDT);
2576 anAreaGISU->SetDefinition(aDefinition);
2577 Model->ReplaceEntity(aGISUNum, anAreaGISU);
2580 Handle(StepDimTol_PlacedDatumTargetFeature) aPDTF = new StepDimTol_PlacedDatumTargetFeature();
2581 aPDTF->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDatumTargetName(aDatumType),
2582 aPDS, StepData_LTrue, aTargetId);
2583 Model->AddWithRefs(aPDTF);
2584 aDatumTarget = aPDTF;
2586 Handle(StepRepr_PropertyDefinition) aPD = new StepRepr_PropertyDefinition();
2587 StepRepr_CharacterizedDefinition aCDefinition;
2588 aCDefinition.SetValue(aPDTF);
2589 aPD->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCDefinition);
2590 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP = new StepShape_ShapeRepresentationWithParameters();
2591 // Common for all datum targets
2592 StepBasic_Unit aUnit = GetUnit(aRC);
2593 gp_Ax2 aDTAxis = anObject->GetDatumTargetAxis();
2594 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2595 STEPCAFControl_GDTProperty::GetAxis2Placement3D(aDTAxis);
2596 anA2P3D->SetName(new TCollection_HAsciiString("orientation"));
2597 Handle(StepRepr_HArray1OfRepresentationItem) anItems;
2598 // Process each datum target type
2599 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Point) {
2600 anItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
2603 Handle(TCollection_HAsciiString) aTargetValueName;
2604 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Line) {
2605 anItems = new StepRepr_HArray1OfRepresentationItem(1, 2);
2606 aTargetValueName = new TCollection_HAsciiString("target length");
2608 else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Rectangle) {
2609 anItems = new StepRepr_HArray1OfRepresentationItem(1, 3);
2610 aTargetValueName = new TCollection_HAsciiString("target length");
2612 Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue = CreateDimValue(anObject->GetDatumTargetWidth(),
2613 aUnit, new TCollection_HAsciiString("target width"), "POSITIVE_LENGTH_MEASURE", Standard_False);
2614 anItems->SetValue(2, aTargetValue);
2615 Model->AddWithRefs(aTargetValue);
2617 else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Circle) {
2618 anItems = new StepRepr_HArray1OfRepresentationItem(1, 2);
2619 aTargetValueName = new TCollection_HAsciiString("target diameter");
2622 Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue= CreateDimValue(anObject->GetDatumTargetLength(),
2623 aUnit, aTargetValueName, "POSITIVE_LENGTH_MEASURE", Standard_False);
2624 anItems->SetValue(1, aTargetValue);
2625 Model->AddWithRefs(aTargetValue);
2627 anItems->SetValue(anItems->Length(), anA2P3D);
2628 aSRWP->Init(new TCollection_HAsciiString(), anItems, aRC);
2630 // Create and write auxiliary entities
2631 Handle (StepShape_ShapeDefinitionRepresentation) aSDR = new StepShape_ShapeDefinitionRepresentation();
2632 StepRepr_RepresentedDefinition aRDefinition;
2633 aRDefinition.SetValue(aPD);
2634 aSDR->Init(aRDefinition, aSRWP);
2635 Model->AddWithRefs(aPD);
2636 Model->AddWithRefs(aSRWP);
2637 Model->AddWithRefs(aSDR);
2639 // Link datum target to datum feature
2640 Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR = new StepRepr_FeatureForDatumTargetRelationship();
2641 aFFDTR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aDatumTarget, aSA);
2642 Model->AddWithRefs(aFFDTR);
2647 Handle(StepDimTol_Datum) aDatum = theWrittenDatum;
2648 if (isFirstDTarget) {
2649 aDatum = new StepDimTol_Datum();
2650 aDatum->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue, anIdentifier);
2651 Model->AddWithRefs(aDatum);
2654 // Shape_Aspect_Relationship
2655 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
2656 aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aSA, aDatum);
2657 Model->AddWithRefs(aSAR);
2659 // Auxiliary entities
2660 // Property_Definition
2661 Handle(StepRepr_PropertyDefinition) aPD = new StepRepr_PropertyDefinition();
2662 Handle(TCollection_HAsciiString) aPDName = new TCollection_HAsciiString("Datum Feature Symbol ");
2663 aPDName = aPDName->Cat(anIdentifier)->Cat(aTargetId);
2664 StepRepr_CharacterizedDefinition aCD;
2666 aPD->Init(aPDName, Standard_False, NULL, aCD);
2667 Model->AddWithRefs(aPD);
2668 // Shape_Representation
2669 Handle(StepShape_ShapeRepresentation) aShapeRepr = new StepShape_ShapeRepresentation();
2670 aShapeRepr->Init(aPDName, aGISU->IdentifiedItem(), aRC);
2671 Model->AddWithRefs(aShapeRepr);
2672 // Shape_Definition_Representation
2673 Handle (StepShape_ShapeDefinitionRepresentation) aSDR = new StepShape_ShapeDefinitionRepresentation();
2674 StepRepr_RepresentedDefinition aRDefinition;
2675 aRDefinition.SetValue(aPD);
2676 aSDR->Init(aRDefinition, aShapeRepr);
2677 Model->AddWithRefs(aSDR);
2679 //Annotation plane and Presentation
2680 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->GetPlane(), anObject->GetPointTextAttach(), aSA);
2685 //=======================================================================
2686 //function : WriteDimValues
2687 //purpose : auxiliary (write all data for given dimension: values,
2688 // qualifiers, modifiers, orientation and tolerance class)
2689 //======================================================================
2690 static void WriteDimValues(const Handle(XSControl_WorkSession) &WS,
2691 const Handle(XCAFDimTolObjects_DimensionObject) theObject,
2692 const Handle(StepRepr_RepresentationContext) theRC,
2693 const StepShape_DimensionalCharacteristic theDimension)
2696 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2697 XCAFDimTolObjects_DimensionModifiersSequence aModifiers = theObject->GetModifiers();
2698 Handle(Standard_Transient) aDim = theDimension.Value();
2699 Standard_Boolean isAngle = aDim->IsKind(STANDARD_TYPE(StepShape_AngularLocation)) ||
2700 aDim->IsKind(STANDARD_TYPE(StepShape_AngularSize));
2703 StepBasic_Unit aUnit = GetUnit(theRC, isAngle);
2704 Standard_CString aMeasureName;
2706 aMeasureName = "POSITIVE_PLANE_ANGLE_MEASURE";
2708 aMeasureName = "POSITIVE_LENGTH_MEASURE";
2711 Handle(StepRepr_HArray1OfRepresentationItem) aValues;
2712 Standard_Integer aNbItems = 1, aValIt = 1;
2713 if (theObject->IsDimWithRange())
2715 if (aModifiers.Length() > 0)
2717 if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented)
2719 aNbItems += theObject->NbDescriptions();
2720 aValues = new StepRepr_HArray1OfRepresentationItem(1, aNbItems);
2723 Standard_Real aNominal = theObject->GetValue();
2724 Standard_Integer aLeftNbDigits, aRightNbDigits;
2725 theObject->GetNbOfDecimalPlaces(aLeftNbDigits, aRightNbDigits);
2726 Standard_Integer aNbQualifiers = 0;
2727 if (theObject->HasQualifier() && !isAngle)
2729 if (aLeftNbDigits > 0 || aRightNbDigits > 0)
2732 if (aNbQualifiers > 0) {
2733 Handle(StepShape_QualifiedRepresentationItem) aQRI = new StepShape_QualifiedRepresentationItem();
2734 Handle(StepShape_HArray1OfValueQualifier) aQualifiers = new StepShape_HArray1OfValueQualifier(1, aNbQualifiers);
2736 if (theObject->HasQualifier() && !isAngle) {
2737 StepShape_ValueQualifier anItem;
2738 Handle(StepShape_TypeQualifier) aType = new StepShape_TypeQualifier();
2739 XCAFDimTolObjects_DimensionQualifier aQualifier = theObject->GetQualifier();
2740 aType->Init(STEPCAFControl_GDTProperty::GetDimQualifierName(aQualifier));
2741 aModel->AddWithRefs(aType);
2742 anItem.SetValue(aType);
2743 aQualifiers->SetValue(1, anItem);
2745 // Number of decimal places
2746 if (aLeftNbDigits > 0 || aRightNbDigits > 0) {
2747 StepShape_ValueQualifier anItem;
2748 Handle(StepShape_ValueFormatTypeQualifier) aType = new StepShape_ValueFormatTypeQualifier();
2749 Handle(TCollection_HAsciiString) aFormatType = new TCollection_HAsciiString("NR2 ");
2750 aFormatType->AssignCat(new TCollection_HAsciiString(aLeftNbDigits));
2751 aFormatType->AssignCat(new TCollection_HAsciiString("."));
2752 aFormatType->AssignCat(new TCollection_HAsciiString(aRightNbDigits));
2753 aType->Init(aFormatType);
2754 aModel->AddWithRefs(aType);
2755 anItem.SetValue(aType);
2756 aQualifiers->SetValue(aNbQualifiers, anItem);
2759 aQRI->SetQualifiers(aQualifiers);
2760 Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
2761 new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle, Standard_True, aQRI);
2762 aValues->SetValue(aValIt, anItem);
2765 // Without qualifiers
2767 Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
2768 new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle);
2769 aValues->SetValue(aValIt, anItem);
2774 if (theObject->IsDimWithRange()) {
2775 Handle(StepRepr_ReprItemAndMeasureWithUnit) aLowerItem = CreateDimValue(theObject->GetLowerBound(), aUnit,
2776 new TCollection_HAsciiString("lower limit"), aMeasureName, isAngle);
2777 Handle(StepRepr_ReprItemAndMeasureWithUnit) anUpperItem = CreateDimValue(theObject->GetUpperBound(), aUnit,
2778 new TCollection_HAsciiString("upper limit"), aMeasureName, isAngle);
2779 aValues->SetValue(aValIt, aLowerItem);
2781 aValues->SetValue(aValIt, anUpperItem);
2786 if (aModifiers.Length() > 0) {
2787 Handle(StepRepr_CompoundRepresentationItem) aCompoundRI = new StepRepr_CompoundRepresentationItem();
2788 Handle (StepRepr_HArray1OfRepresentationItem) aModifItems =
2789 new StepRepr_HArray1OfRepresentationItem(1, aModifiers.Length());
2790 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) {
2791 XCAFDimTolObjects_DimensionModif aModif = aModifiers.Value(i);
2792 Handle(StepRepr_DescriptiveRepresentationItem) aModifItem =
2793 new StepRepr_DescriptiveRepresentationItem();
2794 aModifItem->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDimModifierName(aModif));
2795 aModel->AddWithRefs(aModifItem);
2796 aModifItems->SetValue(i, aModifItem);
2798 aCompoundRI->Init(new TCollection_HAsciiString(), aModifItems);
2799 aValues->SetValue(aValIt, aCompoundRI);
2804 if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented) {
2805 Handle(StepGeom_Axis2Placement3d) anOrientation = new StepGeom_Axis2Placement3d();
2807 theObject->GetDirection(aDir);
2808 GeomToStep_MakeCartesianPoint MkPoint(gp_Pnt(0, 0, 0));
2809 Handle(StepGeom_CartesianPoint) aLoc = MkPoint.Value();
2810 Handle(StepGeom_Direction) anAxis = new StepGeom_Direction();
2811 Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
2812 aCoords->SetValue(1, aDir.X());
2813 aCoords->SetValue(2, aDir.Y());
2814 aCoords->SetValue(3, aDir.Z());
2815 anAxis->Init(new TCollection_HAsciiString(), aCoords);
2816 anOrientation->Init(new TCollection_HAsciiString("orientation"), aLoc, Standard_True, anAxis, Standard_False, NULL);
2817 aValues->SetValue(aValIt, anOrientation);
2822 if (theObject->HasDescriptions()) {
2823 for (Standard_Integer i = 0; i < theObject->NbDescriptions(); i++) {
2824 Handle(StepRepr_DescriptiveRepresentationItem) aDRI = new StepRepr_DescriptiveRepresentationItem();
2825 aDRI->Init(theObject->GetDescriptionName(i), theObject->GetDescription(i));
2826 aValues->SetValue(aValIt, aDRI);
2831 for (Standard_Integer i = 1; i <= aValues->Length(); i++)
2832 aModel->AddWithRefs(aValues->Value(i));
2834 // Create resulting Shape_Dimension_Representation
2835 Handle(StepShape_ShapeDimensionRepresentation) aSDR = new StepShape_ShapeDimensionRepresentation();
2836 aSDR->Init(new TCollection_HAsciiString(), aValues, theRC);
2837 aModel->AddWithRefs(aSDR);
2838 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR = new StepShape_DimensionalCharacteristicRepresentation();
2839 aDCR->Init(theDimension, aSDR);
2840 aModel->AddWithRefs(aDCR);
2842 // Plus_Minus_Tolerance
2843 if (theObject->IsDimWithPlusMinusTolerance()) {
2844 Handle(TCollection_HAsciiString) aDummyName = new TCollection_HAsciiString(aMeasureName);
2845 aDummyName = aDummyName->SubString(9, aDummyName->Length()); //delete "POSITIVE_"
2846 aMeasureName = aDummyName->ToCString();
2847 Standard_Real aLowerTolValue = -theObject->GetLowerTolValue(),
2848 anUpperTolValue = theObject->GetUpperTolValue();
2850 Handle(StepBasic_MeasureWithUnit) anUpperMWU = new StepBasic_MeasureWithUnit();
2851 Handle(StepBasic_MeasureValueMember) anUpperValue = new StepBasic_MeasureValueMember();
2852 anUpperValue->SetName(aMeasureName);
2853 anUpperValue->SetReal(anUpperTolValue);
2854 anUpperMWU->Init(anUpperValue, aUnit);
2855 aModel->AddWithRefs(anUpperMWU);
2857 Handle(StepBasic_MeasureWithUnit) aLowerMWU = new StepBasic_MeasureWithUnit();
2858 Handle(StepBasic_MeasureValueMember) aLowerValue = new StepBasic_MeasureValueMember();
2859 aLowerValue->SetName(aMeasureName);
2860 aLowerValue->SetReal(aLowerTolValue);
2861 aLowerMWU->Init(aLowerValue, aUnit);
2862 aModel->AddWithRefs(aLowerMWU);
2864 Handle(StepShape_ToleranceValue) aTolValue = new StepShape_ToleranceValue();
2865 aTolValue->Init(aLowerMWU, anUpperMWU);
2866 aModel->AddWithRefs(aTolValue);
2867 StepShape_ToleranceMethodDefinition aMethod;
2868 aMethod.SetValue(aTolValue);
2869 Handle(StepShape_PlusMinusTolerance) aPlusMinusTol = new StepShape_PlusMinusTolerance();
2870 aPlusMinusTol->Init(aMethod, theDimension);
2871 aModel->AddWithRefs(aPlusMinusTol);
2874 if (theObject->IsDimWithClassOfTolerance()) {
2875 Standard_Boolean isHole;
2876 XCAFDimTolObjects_DimensionFormVariance aFormVariance;
2877 XCAFDimTolObjects_DimensionGrade aGrade;
2878 if (!theObject->GetClassOfTolerance(isHole, aFormVariance, aGrade))
2880 Handle(StepShape_LimitsAndFits) aLAF = STEPCAFControl_GDTProperty::GetLimitsAndFits(isHole, aFormVariance, aGrade);
2881 aModel->AddWithRefs(aLAF);
2882 StepShape_ToleranceMethodDefinition aMethod;
2883 aMethod.SetValue(aLAF);
2884 Handle(StepShape_PlusMinusTolerance) aPlusMinusTol = new StepShape_PlusMinusTolerance();
2885 aPlusMinusTol->Init(aMethod, theDimension);
2886 aModel->AddWithRefs(aPlusMinusTol);
2890 //=======================================================================
2891 //function : WriteDerivedGeometry
2892 //purpose : auxiliary (write connection point for dimensions)
2893 //======================================================================
2894 static void WriteDerivedGeometry (const Handle(XSControl_WorkSession) &WS,
2895 const Handle(XCAFDimTolObjects_DimensionObject)& theObject,
2896 const Handle(StepRepr_ConstructiveGeometryRepresentation) theRepr,
2897 Handle(StepRepr_ShapeAspect)& theFirstSA,
2898 Handle(StepRepr_ShapeAspect)& theSecondSA,
2899 NCollection_Vector<Handle(StepGeom_CartesianPoint)>& thePnts)
2901 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2903 if (theObject->HasPoint()) {
2904 GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint());
2905 Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
2906 thePnts.Append(aPoint);
2907 Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
2908 aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse);
2909 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2910 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2911 aDefinition.SetValue(aDSA);
2912 Handle(StepRepr_HArray1OfRepresentationItem) anItem = new StepRepr_HArray1OfRepresentationItem(1, 1);
2913 anItem->SetValue(1, aPoint);
2914 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDefinition, theRepr, anItem);
2915 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = new StepRepr_ShapeAspectDerivingRelationship();
2916 aSADR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDSA, theFirstSA);
2918 aModel->AddWithRefs(aGISU);
2919 aModel->AddWithRefs(aSADR);
2922 // Second point (for locations)
2923 if (theObject->HasPoint2()) {
2924 GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint2());
2925 Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
2926 thePnts.Append(aPoint);
2927 Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
2928 aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse);
2929 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2930 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2931 aDefinition.SetValue(aDSA);
2932 Handle(StepRepr_HArray1OfRepresentationItem) anItem = new StepRepr_HArray1OfRepresentationItem(1, 1);
2933 anItem->SetValue(1, aPoint);
2934 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDefinition, theRepr, anItem);
2935 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = new StepRepr_ShapeAspectDerivingRelationship();
2936 aSADR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDSA, theSecondSA);
2938 aModel->AddWithRefs(aGISU);
2939 aModel->AddWithRefs(aSADR);
2943 //=======================================================================
2944 //function : WriteDatumSystem
2945 //purpose : auxiliary (write Write datum system for given
2946 // geometric_tolerance)
2947 //======================================================================
2948 static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const Handle(XSControl_WorkSession) &WS,
2949 const TDF_Label theGeomTolL,
2950 const TDF_LabelSequence theDatumSeq,
2951 const STEPConstruct_DataMapOfAsciiStringTransient theDatumMap,
2952 const Handle(StepRepr_RepresentationContext)& theRC)
2955 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2956 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2957 if (aHGraph.IsNull())
2959 Interface_Graph aGraph = aHGraph->Graph();
2960 Handle(XCAFDoc_GeomTolerance) aGTAttr;
2961 if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr))
2963 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
2964 if (anObject.IsNull())
2968 StepBasic_Unit aUnit = GetUnit(theRC);
2970 XCAFDimTolObjects_DatumObjectSequence aDatums;
2971 Standard_Integer aMaxDatumNum = 0;
2972 for (Standard_Integer i = 1; i <= theDatumSeq.Length(); i++) {
2973 Handle(XCAFDoc_Datum) aDatumAttr;
2974 if (!theDatumSeq.Value(i).FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
2976 Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject();
2977 if (aDatumObj.IsNull())
2979 aDatums.Append(aDatumObj);
2980 aMaxDatumNum = Max(aMaxDatumNum, aDatumObj->GetPosition());
2982 if (aMaxDatumNum == 0)
2985 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aConstituents =
2986 new StepDimTol_HArray1OfDatumReferenceCompartment(1, aMaxDatumNum);
2987 // Auxiliary datum to initialize attributes in Datum_System
2988 Handle(StepDimTol_Datum) aFirstDatum;
2989 Standard_Integer aConstituentsNum = 0;
2990 for (Standard_Integer i = 1; i <= aMaxDatumNum; i++) {
2991 // Collect datums with i-th position
2992 XCAFDimTolObjects_DatumObjectSequence aDatumSeqPos;
2993 for (Standard_Integer j = 1; j <= aDatums.Length(); j++)
2994 if (aDatums.Value(j)->GetPosition() == i)
2995 aDatumSeqPos.Append(aDatums.Value(j));
2996 if (aDatumSeqPos.Length() < 1)
3000 // Initialize Datum_Reference_Compartment
3001 StepDimTol_DatumOrCommonDatum aDatumRef;
3002 Handle(StepDimTol_DatumReferenceCompartment) aCompartment =
3003 new StepDimTol_DatumReferenceCompartment();
3004 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifiers;
3005 if (aDatumSeqPos.Length() == 1) {
3007 Handle(Standard_Transient) aFDValue;
3008 if (theDatumMap.Find(aDatumSeqPos.Value(1)->GetName()->String(), aFDValue) && !aFDValue.IsNull())
3009 aFirstDatum = Handle(StepDimTol_Datum)::DownCast (aFDValue);
3010 aDatumRef.SetValue(aFirstDatum);
3012 XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(1)->GetModifiers();
3013 XCAFDimTolObjects_DatumModifWithValue aModifWithVal;
3014 Standard_Real aValue = 0;
3015 aDatumSeqPos.Value(1)->GetModifierWithValue(aModifWithVal, aValue);
3016 aModifiers = STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit);
3017 // Add Datum_Reference_Modifier_With_Value
3018 if (!aModifiers.IsNull()) {
3019 Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV =
3020 aModifiers->Value(aModifiers->Length()).DatumReferenceModifierWithValue();
3021 if (!aDRMWV.IsNull()) {
3022 Model->AddWithRefs(aDRMWV);
3027 Handle(StepDimTol_HArray1OfDatumReferenceElement) aCommonDatumList = new StepDimTol_HArray1OfDatumReferenceElement(1, aDatumSeqPos.Length());
3028 for (Standard_Integer j = 1; j <= aDatumSeqPos.Length(); j++) {
3030 Handle(StepDimTol_Datum) aDatum;
3031 Handle(Standard_Transient) aDValue;
3032 if (theDatumMap.Find(aDatumSeqPos.Value(j)->GetName()->String(), aDValue))
3033 aDatum = Handle(StepDimTol_Datum)::DownCast (aDValue);
3034 StepDimTol_DatumOrCommonDatum anElemDatumRef;
3035 anElemDatumRef.SetValue(aDatum);
3036 if (aFirstDatum.IsNull())
3037 aFirstDatum = aDatum;
3039 XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(j)->GetModifiers();
3040 XCAFDimTolObjects_DatumModifWithValue aModifWithVal;
3041 Standard_Real aValue = 0;
3042 aDatumSeqPos.Value(j)->GetModifierWithValue(aModifWithVal, aValue);
3043 Handle(StepDimTol_HArray1OfDatumReferenceModifier) anElemModifiers =
3044 STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit);
3045 // Add Datum_Reference_Modifier_With_Value
3046 if (!anElemModifiers.IsNull()) {
3047 Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV =
3048 anElemModifiers->Value(anElemModifiers->Length()).DatumReferenceModifierWithValue();
3049 if (!aDRMWV.IsNull()) {
3050 Model->AddWithRefs(aDRMWV);
3053 // Datum_Reference_Element
3054 Handle(StepDimTol_DatumReferenceElement) anElement = new StepDimTol_DatumReferenceElement();
3055 anElement->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDatum->OfShape(),
3056 aDatum->ProductDefinitional(), anElemDatumRef, !anElemModifiers.IsNull(), anElemModifiers);
3057 Model->AddWithRefs(anElement);
3058 aCommonDatumList->SetValue(j, anElement);
3060 aDatumRef.SetValue(aCommonDatumList);
3062 aCompartment->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(),
3063 aFirstDatum->ProductDefinitional(), aDatumRef, !aModifiers.IsNull(), aModifiers);
3064 Model->AddWithRefs(aCompartment);
3065 aConstituents->SetValue(aConstituentsNum, aCompartment);
3067 // Remove null elements from aConstituents
3068 Standard_Integer aNbConstituents = 0;
3069 for (Standard_Integer i = 1; i <= aConstituents->Length(); i++)
3070 if (!aConstituents->Value(i).IsNull())
3072 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aResConstituents =
3073 new StepDimTol_HArray1OfDatumReferenceCompartment(1, aNbConstituents);
3074 Standard_Integer aConstituentsIt = 0;
3075 for (Standard_Integer i = 1; i <= aConstituents->Length(); i++)
3076 if (!aConstituents->Value(i).IsNull()) {
3078 aResConstituents->SetValue(aConstituentsIt, aConstituents->Value(i));
3081 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
3082 Handle(StepDimTol_DatumSystem) aDS = new StepDimTol_DatumSystem();
3083 aDS->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(),
3084 aFirstDatum->ProductDefinitional(), aResConstituents);
3085 Model->AddWithRefs(aDS);
3086 StepDimTol_DatumSystemOrReference anArrayValue;
3087 anArrayValue.SetValue(aDS);
3088 aDatumSystem = new StepDimTol_HArray1OfDatumSystemOrReference(1, 1);
3089 aDatumSystem->SetValue(1, anArrayValue);
3092 if (anObject->HasAxis()) {
3093 Handle(StepGeom_Axis2Placement3d) anAxis =
3094 STEPCAFControl_GDTProperty::GetAxis2Placement3D(anObject->GetAxis());
3095 anAxis->SetName(new TCollection_HAsciiString("orientation"));
3096 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
3097 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
3098 aDefinition.SetValue(aDS);
3099 Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
3100 Handle(StepRepr_RepresentationItem) anIdentifiedItem = anAxis;
3101 anReprItems->SetValue(1, anIdentifiedItem);
3102 Interface_EntityIterator subs = aGraph.Sharings(aFirstDatum->OfShape());
3103 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
3104 for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) {
3105 Handle(Standard_Transient) anEntity = subs.Value();
3106 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity);
3109 return aDatumSystem;
3111 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(),
3112 aDefinition, aSDR->UsedRepresentation(), anReprItems);
3113 Model->AddWithRefs(anAxis);
3114 Model->AddWithRefs(aGISU);
3117 return aDatumSystem;
3120 //=======================================================================
3121 //function : WriteToleranceZone
3122 //purpose : auxiliary (write tolerace zones)
3123 //=======================================================================
3124 static void WriteToleranceZone (const Handle(XSControl_WorkSession) &WS,
3125 const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject,
3126 const Handle(StepDimTol_GeometricTolerance)& theEntity,
3127 const Handle(StepRepr_RepresentationContext)& theRC)
3130 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3131 if (theEntity.IsNull() || theObject.IsNull())
3134 // Return if there is no tolerance zones
3135 if (theObject->GetTypeOfValue() == XCAFDimTolObjects_GeomToleranceTypeValue_None &&
3136 theObject->GetZoneModifier() != XCAFDimTolObjects_GeomToleranceZoneModif_Runout)
3139 // Create Tolerance_Zone
3140 Handle(StepDimTol_ToleranceZoneForm) aForm = new StepDimTol_ToleranceZoneForm();
3141 Model->AddWithRefs(aForm);
3142 aForm->Init(STEPCAFControl_GDTProperty::GetTolValueType(theObject->GetTypeOfValue()));
3143 Handle(StepDimTol_HArray1OfToleranceZoneTarget) aZoneTargetArray = new StepDimTol_HArray1OfToleranceZoneTarget(1, 1);
3144 StepDimTol_ToleranceZoneTarget aTarget;
3145 aTarget.SetValue(theEntity);
3146 aZoneTargetArray->SetValue(1, aTarget);
3147 Handle(StepDimTol_ToleranceZone) aZone = new StepDimTol_ToleranceZone();
3148 aZone->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(),
3149 theEntity->TolerancedShapeAspect().ShapeAspect()->OfShape(), StepData_LFalse,
3150 aZoneTargetArray, aForm);
3151 Model->AddWithRefs(aZone);
3153 // Runout_Tolerance_Zone
3154 Handle(StepBasic_PlaneAngleMeasureWithUnit) aPAMWU = new StepBasic_PlaneAngleMeasureWithUnit();
3155 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
3156 aValueMember->SetName("PLANE_ANGLE_MEASURE");
3157 aValueMember->SetReal(theObject->GetValueOfZoneModifier());
3158 aPAMWU->Init(aValueMember, GetUnit(theRC, Standard_True));
3159 Handle(StepDimTol_RunoutZoneOrientation) anOrientation = new StepDimTol_RunoutZoneOrientation();
3160 anOrientation->Init(aPAMWU);
3161 Handle(StepDimTol_RunoutZoneDefinition) aDefinition = new StepDimTol_RunoutZoneDefinition();
3162 aDefinition->Init(aZone, NULL, anOrientation);
3163 Model->AddWithRefs(aDefinition);
3164 Model->AddWithRefs(anOrientation);
3165 Model->AddWithRefs(aPAMWU);
3168 //=======================================================================
3169 //function : WriteGeomTolerance
3170 //purpose : auxiliary (write Geometric_Tolerance entity for given shapes,
3171 // label and datum system)
3172 //======================================================================
3173 static void WriteGeomTolerance (const Handle(XSControl_WorkSession) &WS,
3174 const TDF_LabelSequence theShapeSeqL,
3175 const TDF_Label theGeomTolL,
3176 const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem,
3177 const Handle(StepRepr_RepresentationContext)& theRC)
3180 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3181 Handle(XCAFDoc_GeomTolerance) aGTAttr;
3182 if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr))
3184 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
3185 if (anObject.IsNull())
3189 Handle(StepBasic_LengthMeasureWithUnit) aLMWU = new StepBasic_LengthMeasureWithUnit();
3190 StepBasic_Unit aUnit = GetUnit(theRC);
3191 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
3192 aValueMember->SetName("LENGTH_MEASURE");
3193 aValueMember->SetReal(anObject->GetValue());
3194 aLMWU->Init(aValueMember, aUnit);
3195 Model->AddWithRefs(aLMWU);
3197 // Geometric_Tolerance target
3198 Handle(StepRepr_ShapeAspect) aMainSA;
3199 Handle(StepRepr_RepresentationContext) dummyRC;
3200 Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
3201 if (theShapeSeqL.Length() == 1) {
3202 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(1));
3203 aMainSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU);
3204 Model->AddWithRefs(aMainSA);
3207 Handle(StepRepr_CompositeShapeAspect) aCSA;
3208 for (Standard_Integer i = 1; i <= theShapeSeqL.Length(); i++) {
3209 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(i));
3210 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU);
3213 if (aCSA.IsNull()) {
3214 aCSA = new StepRepr_CompositeShapeAspect();
3215 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3216 Model->AddWithRefs(aCSA);
3218 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3219 aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCSA, aSA);
3220 Model->AddWithRefs(aSAR);
3224 StepDimTol_GeometricToleranceTarget aGTTarget;
3225 aGTTarget.SetValue(aMainSA);
3227 Standard_Boolean isWithModif = Standard_False,
3228 isWithDatRef = Standard_False,
3229 isWithMaxTol = Standard_False;
3232 XCAFDimTolObjects_GeomToleranceModifiersSequence aModifiers = anObject->GetModifiers();
3233 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifArray;
3234 Handle(StepBasic_LengthMeasureWithUnit) aMaxLMWU;
3235 Standard_Integer aModifNb = aModifiers.Length();
3236 if (anObject->GetMaterialRequirementModifier() != XCAFDimTolObjects_GeomToleranceMatReqModif_None)
3238 for (Standard_Integer i = 1; i < aModifiers.Length(); i++)
3239 if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around ||
3240 aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over)
3243 isWithModif = Standard_True;
3244 aModifArray = new StepDimTol_HArray1OfGeometricToleranceModifier(1, aModifNb);
3245 Standard_Integer k = 1;
3246 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) {
3247 if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around ||
3248 aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over)
3250 StepDimTol_GeometricToleranceModifier aModif =
3251 STEPCAFControl_GDTProperty::GetGeomToleranceModifier(aModifiers.Value(i));
3252 aModifArray->SetValue(k, aModif);
3255 if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_L) {
3256 aModifArray->SetValue(aModifNb, StepDimTol_GTMLeastMaterialRequirement);
3258 else if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_M) {
3259 aModifArray->SetValue(aModifNb, StepDimTol_GTMMaximumMaterialRequirement);
3261 // Modifier with value
3262 if (anObject->GetMaxValueModifier() != 0) {
3263 isWithMaxTol = Standard_True;
3264 aMaxLMWU = new StepBasic_LengthMeasureWithUnit();
3265 Handle(StepBasic_MeasureValueMember) aModifierValueMember = new StepBasic_MeasureValueMember();
3266 aModifierValueMember->SetName("LENGTH_MEASURE");
3267 aModifierValueMember->SetReal(anObject->GetMaxValueModifier());
3268 aMaxLMWU->Init(aModifierValueMember, aUnit);
3269 Model->AddWithRefs(aMaxLMWU);
3274 isWithDatRef = !theDatumSystem.IsNull();
3276 // Collect all attributes
3277 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(),
3278 aDescription = new TCollection_HAsciiString();
3279 Handle(StepDimTol_GeometricToleranceWithDatumReference) aGTWDR =
3280 new StepDimTol_GeometricToleranceWithDatumReference();
3281 aGTWDR->SetDatumSystem(theDatumSystem);
3282 Handle(StepDimTol_GeometricToleranceWithModifiers) aGTWM =
3283 new StepDimTol_GeometricToleranceWithModifiers();
3284 aGTWM->SetModifiers(aModifArray);
3285 StepDimTol_GeometricToleranceType aType =
3286 STEPCAFControl_GDTProperty::GetGeomToleranceType(anObject->GetType());
3288 // Init and write necessary subtype of Geometric_Tolerance entity
3289 Handle(StepDimTol_GeometricTolerance) aGeomTol;
3293 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference &
3294 //Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers
3295 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aResult =
3296 new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol();
3297 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aMaxLMWU, aType);
3301 // Geometric_Tolerance & Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers
3302 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aResult =
3303 new StepDimTol_GeoTolAndGeoTolWthMaxTol();
3304 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWM, aMaxLMWU, aType);
3310 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference & Geometric_Tolerance_With_Modifiers
3311 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) aResult =
3312 new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod();
3313 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aType);
3317 // Geometric_Tolerance & Geometric_Tolerance_With_Modifiers
3318 Handle(StepDimTol_GeoTolAndGeoTolWthMod) aResult =
3319 new StepDimTol_GeoTolAndGeoTolWthMod();
3320 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWM, aType);
3327 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference
3328 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) aResult =
3329 new StepDimTol_GeoTolAndGeoTolWthDatRef();
3330 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aType);
3334 // Geometric_Tolerance
3335 Handle(StepDimTol_GeometricTolerance) aResult =
3336 STEPCAFControl_GDTProperty::GetGeomTolerance(anObject->GetType());
3337 if (!aResult.IsNull()) {
3338 aResult->Init(aName, aDescription, aLMWU, aGTTarget);
3343 Model->AddWithRefs(aGeomTol);
3344 WriteToleranceZone(WS, anObject, aGeomTol, theRC);
3345 //Annotation plane and Presentation
3346 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->GetPlane(), anObject->GetPointTextAttach(), aGeomTol);
3349 //=======================================================================
3350 //function : WriteDGTs
3352 //=======================================================================
3353 Standard_Boolean STEPCAFControl_Writer::WriteDGTs (const Handle(XSControl_WorkSession) &WS,
3354 const TDF_LabelSequence &labels ) const
3357 if ( labels.Length() <=0 ) return Standard_False;
3360 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3361 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
3362 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
3364 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3365 if(aHGraph.IsNull())
3366 return Standard_False;
3368 Interface_Graph aGraph = aHGraph->Graph();
3369 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( labels(1) );
3370 if(DGTTool.IsNull() ) return Standard_False;
3372 TDF_LabelSequence DGTLabels;
3374 STEPConstruct_DataMapOfAsciiStringTransient DatumMap;
3378 DGTTool->GetDatumLabels(DGTLabels);
3379 if(DGTLabels.Length()<=0) return Standard_False;
3381 for(i=1; i<=DGTLabels.Length(); i++) {
3382 TDF_Label DatumL = DGTLabels.Value(i);
3383 TDF_LabelSequence ShapeL;
3384 TDF_LabelSequence aNullSeq;
3385 if(!DGTTool->GetRefShapeLabel(DatumL,ShapeL,aNullSeq)) continue;
3386 // find target shape
3387 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
3388 TopLoc_Location Loc;
3389 TColStd_SequenceOfTransient seqRI;
3390 FindEntities( FP, aShape, Loc, seqRI );
3391 if ( seqRI.Length() <= 0 ) {
3392 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
3395 Handle(StepRepr_ProductDefinitionShape) PDS;
3396 Handle(StepRepr_RepresentationContext) RC;
3397 Handle(Standard_Transient) ent = seqRI.Value(1);
3398 Handle(StepShape_AdvancedFace) AF;
3399 Handle(StepShape_EdgeCurve) EC;
3400 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
3401 if(PDS.IsNull()) continue;
3402 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
3403 Handle(XCAFDoc_Datum) DatumAttr;
3404 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
3405 Handle(TCollection_HAsciiString) aName = DatumAttr->GetName();
3406 Handle(TCollection_HAsciiString) aDescription = DatumAttr->GetDescription();
3407 Handle(TCollection_HAsciiString) anIdentification = DatumAttr->GetIdentification();
3408 Handle(StepDimTol_DatumFeature) DF = new StepDimTol_DatumFeature;
3409 Handle(StepDimTol_Datum) aDatum = new StepDimTol_Datum;
3410 DF->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
3411 Model->AddWithRefs(DF);
3412 aDatum->Init(aName, new TCollection_HAsciiString, PDS, StepData_LFalse, anIdentification);
3413 Model->AddWithRefs(aDatum);
3414 Handle(StepRepr_ShapeAspectRelationship) SAR = new StepRepr_ShapeAspectRelationship;
3415 SAR->SetName(aName);
3416 SAR->SetRelatingShapeAspect(DF);
3417 SAR->SetRelatedShapeAspect(aDatum);
3418 Model->AddWithRefs(SAR);
3419 // write chain for DatumFeature
3420 StepRepr_CharacterizedDefinition CD;
3422 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
3423 PropD->Init(aName,Standard_True,aDescription,CD);
3424 Model->AddWithRefs(PropD);
3425 StepRepr_RepresentedDefinition RD;
3427 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
3428 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
3429 new StepRepr_HArray1OfRepresentationItem(1,1);
3430 HARI->SetValue(1,AF);
3431 SR->Init(aName,HARI,RC);
3432 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
3434 Model->AddWithRefs(SDR);
3435 // write chain for Datum
3436 StepRepr_CharacterizedDefinition CD1;
3437 CD1.SetValue(aDatum);
3438 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
3439 PropD1->Init(aName,Standard_True,aDescription,CD1);
3440 Model->AddWithRefs(PropD1);
3441 StepRepr_RepresentedDefinition RD1;
3442 RD1.SetValue(PropD1);
3443 Handle(StepShape_ShapeRepresentation) SR1 = new StepShape_ShapeRepresentation;
3444 Handle(StepRepr_HArray1OfRepresentationItem) HARI1 =
3445 new StepRepr_HArray1OfRepresentationItem(1,1);
3446 HARI1->SetValue(1,AF->FaceGeometry());
3447 SR1->Init(aName,HARI1,RC);
3448 Model->AddWithRefs(SR1);
3449 Handle(StepShape_ShapeDefinitionRepresentation) SDR1 = new StepShape_ShapeDefinitionRepresentation;
3450 SDR1->Init(RD1,SR1);
3451 Model->AddWithRefs(SDR1);
3452 // add created Datum into Map
3453 TCollection_AsciiString stmp(aName->ToCString());
3454 stmp.AssignCat(aDescription->ToCString());
3455 stmp.AssignCat(anIdentification->ToCString());
3456 DatumMap.Bind(stmp,aDatum);
3459 // write Tolerances and Dimensions
3461 DGTTool->GetDimTolLabels(DGTLabels);
3462 if(DGTLabels.Length()<=0) return Standard_False;
3463 for(i=1; i<=DGTLabels.Length(); i++) {
3464 TDF_Label DimTolL = DGTLabels.Value(i);
3465 TDF_LabelSequence ShapeL;
3466 TDF_LabelSequence aNullSeq;
3467 if(!DGTTool->GetRefShapeLabel(DimTolL,ShapeL,aNullSeq)) continue;
3468 // find target shape
3469 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
3470 TopLoc_Location Loc;
3471 TColStd_SequenceOfTransient seqRI;
3472 FindEntities( FP, aShape, Loc, seqRI );
3473 if ( seqRI.Length() <= 0 ) {
3474 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
3477 Handle(StepRepr_ProductDefinitionShape) PDS;
3478 Handle(StepRepr_RepresentationContext) RC;
3479 Handle(Standard_Transient) ent = seqRI.Value(1);
3480 Handle(StepShape_AdvancedFace) AF;
3481 Handle(StepShape_EdgeCurve) EC;
3482 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
3483 if(PDS.IsNull()) continue;
3484 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
3486 Handle(XCAFDoc_DimTol) DimTolAttr;
3487 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) continue;
3488 Standard_Integer kind = DimTolAttr->GetKind();
3489 Handle(TColStd_HArray1OfReal) aVal = DimTolAttr->GetVal();
3490 Handle(TCollection_HAsciiString) aName = DimTolAttr->GetName();
3491 Handle(TCollection_HAsciiString) aDescription = DimTolAttr->GetDescription();
3493 // common part of writing D> entities
3494 StepRepr_CharacterizedDefinition CD;
3495 Handle(StepRepr_ShapeAspect) SA = new StepRepr_ShapeAspect;
3496 SA->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
3497 Model->AddWithRefs(SA);
3499 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
3500 PropD->Init(aName,Standard_True,aDescription,CD);
3501 Model->AddWithRefs(PropD);
3502 StepRepr_RepresentedDefinition RD;
3504 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
3505 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
3506 new StepRepr_HArray1OfRepresentationItem(1,1);
3508 HARI->SetValue(1,EC);
3510 HARI->SetValue(1,AF);
3511 SR->Init(aName,HARI,RC);
3512 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
3514 Model->AddWithRefs(SDR);
3515 // define aUnit for creation LengthMeasureWithUnit (common for all)
3516 StepBasic_Unit aUnit;
3517 Handle(StepBasic_SiUnitAndLengthUnit) SLU;
3518 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) Ctx =
3519 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(RC);
3521 for(Standard_Integer j=1; j<=Ctx->NbUnits(); j++) {
3522 if(Ctx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
3523 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx->UnitsValue(j));
3529 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) Ctx1 =
3530 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(RC);
3531 if(!Ctx1.IsNull()) {
3532 for(Standard_Integer j=1; j<=Ctx1->NbUnits(); j++) {
3533 if(Ctx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
3534 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx1->UnitsValue(j));
3541 SLU = new StepBasic_SiUnitAndLengthUnit;
3543 aUnit.SetValue(SLU);
3545 // specific part of writing D> entities
3546 if(kind<20) { //dimension
3547 Handle(StepShape_DimensionalSize) DimSize = new StepShape_DimensionalSize;
3548 DimSize->Init(SA,aDescription);
3549 Model->AddWithRefs(DimSize);
3550 if(aVal->Length()>1) {
3551 // create MeasureWithUnits
3552 Handle(StepBasic_MeasureValueMember) MVM1 = new StepBasic_MeasureValueMember;
3553 MVM1->SetName("POSITIVE_LENGTH_MEASURE");
3554 MVM1->SetReal(aVal->Value(1));
3555 Handle(StepBasic_MeasureWithUnit) MWU1 = new StepBasic_MeasureWithUnit;
3556 MWU1->Init(MVM1,aUnit);
3557 Handle(StepBasic_MeasureValueMember) MVM2 = new StepBasic_MeasureValueMember;
3558 MVM2->SetName("POSITIVE_LENGTH_MEASURE");
3559 MVM2->SetReal(aVal->Value(2));
3560 Handle(StepBasic_MeasureWithUnit) MWU2 = new StepBasic_MeasureWithUnit;
3561 MWU2->Init(MVM2,aUnit);
3562 Handle(StepRepr_RepresentationItem) RI1 = new StepRepr_RepresentationItem;
3563 RI1->Init(new TCollection_HAsciiString("lower limit"));
3564 Handle(StepRepr_RepresentationItem) RI2 = new StepRepr_RepresentationItem;
3565 RI2->Init(new TCollection_HAsciiString("upper limit"));
3566 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU1 =
3567 new StepRepr_ReprItemAndLengthMeasureWithUnit;
3568 RILMU1->Init(MWU1,RI1);
3569 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU2 =
3570 new StepRepr_ReprItemAndLengthMeasureWithUnit;
3571 RILMU2->Init(MWU2,RI2);
3572 Model->AddWithRefs(RILMU1);
3573 Model->AddWithRefs(RILMU2);
3574 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
3575 // new StepRepr_CompoundItemDefinitionMember;
3576 //Handle(TColStd_HArray1OfTransient) ArrTr = new TColStd_HArray1OfTransient(1,2);
3577 //ArrTr->SetValue(1,RILMU1);
3578 //ArrTr->SetValue(2,RILMU2);
3579 //CIDM->SetArrTransient(ArrTr);
3580 //CIDM->SetName("SET_REPRESENTATION_ITEM");
3581 //StepRepr_CompoundItemDefinition CID;
3582 //CID.SetValue(CIDM);
3583 Handle(StepRepr_HArray1OfRepresentationItem) HARIVR =
3584 new StepRepr_HArray1OfRepresentationItem(1,2);
3585 HARIVR->SetValue(1,RILMU1);
3586 HARIVR->SetValue(2,RILMU2);
3587 Handle(StepRepr_ValueRange) VR = new StepRepr_ValueRange;
3588 //VR->Init(aName,CID);
3589 VR->Init(aName,HARIVR);
3590 Model->AddEntity(VR);
3591 Handle(StepShape_ShapeDimensionRepresentation) SDimR =
3592 new StepShape_ShapeDimensionRepresentation;
3593 Handle(StepRepr_HArray1OfRepresentationItem) aHARI =
3594 new StepRepr_HArray1OfRepresentationItem(1,1);
3595 aHARI->SetValue(1,VR);
3596 SDimR->Init(aName,aHARI,RC);
3597 Model->AddWithRefs(SDimR);
3598 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
3599 new StepShape_DimensionalCharacteristicRepresentation;
3600 StepShape_DimensionalCharacteristic DimChar;
3601 DimChar.SetValue(DimSize);
3602 DimCharR->Init(DimChar,SDimR);
3603 Model->AddEntity(DimCharR);
3606 else if(kind<50) { //tolerance
3607 if(kind<35) { // tolerance with datum system
3608 TDF_LabelSequence DatumLabels;
3609 DGTTool->GetDatumOfTolerLabels(DimTolL,DatumLabels);
3610 Standard_Integer NbDR = DatumLabels.Length();
3611 Handle(StepDimTol_HArray1OfDatumReference) HADR = new StepDimTol_HArray1OfDatumReference(1,NbDR);
3612 for(Standard_Integer j=1; j<=NbDR; j++) {
3613 Handle(XCAFDoc_Datum) DatumAttr;
3614 TDF_Label DatumL = DatumLabels.Value(j);
3615 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
3616 Handle(TCollection_HAsciiString) aNameD = DatumAttr->GetName();
3617 Handle(TCollection_HAsciiString) aDescriptionD = DatumAttr->GetDescription();
3618 Handle(TCollection_HAsciiString) anIdentificationD = DatumAttr->GetIdentification();
3619 TCollection_AsciiString stmp(aNameD->ToCString());
3620 stmp.AssignCat(aDescriptionD->ToCString());
3621 stmp.AssignCat(anIdentificationD->ToCString());
3622 if(DatumMap.IsBound(stmp)) {
3623 Handle(StepDimTol_Datum) aDatum =
3624 Handle(StepDimTol_Datum)::DownCast(DatumMap.Find(stmp));
3625 Handle(StepDimTol_DatumReference) DR = new StepDimTol_DatumReference;
3627 Model->AddWithRefs(DR);
3628 HADR->SetValue(j,DR);
3631 // create LengthMeasureWithUnit
3632 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
3633 MVM->SetName("LENGTH_MEASURE");
3634 MVM->SetReal(aVal->Value(1));
3635 Handle(StepBasic_LengthMeasureWithUnit) LMWU = new StepBasic_LengthMeasureWithUnit;
3636 LMWU->Init(MVM,aUnit);
3637 // create tolerance by it's type
3639 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
3640 new StepDimTol_GeometricToleranceWithDatumReference;
3641 GTWDR->SetDatumSystem(HADR);
3642 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
3643 new StepDimTol_ModifiedGeometricTolerance;
3644 if(kind==21) MGT->SetModifier(StepDimTol_MaximumMaterialCondition);
3645 else if(kind==22) MGT->SetModifier(StepDimTol_LeastMaterialCondition);
3646 else if(kind==23) MGT->SetModifier(StepDimTol_RegardlessOfFeatureSize);
3647 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
3648 new StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol;
3649 GTComplex->Init(aName,aDescription,LMWU,SA,GTWDR,MGT);
3650 Model->AddWithRefs(GTComplex);
3653 Handle(StepDimTol_AngularityTolerance) aToler =
3654 new StepDimTol_AngularityTolerance;
3655 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3656 Model->AddWithRefs(aToler);
3659 Handle(StepDimTol_CircularRunoutTolerance) aToler =
3660 new StepDimTol_CircularRunoutTolerance;
3661 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3662 Model->AddWithRefs(aToler);
3665 Handle(StepDimTol_CoaxialityTolerance) aToler =
3666 new StepDimTol_CoaxialityTolerance;
3667 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3668 Model->AddWithRefs(aToler);
3671 Handle(StepDimTol_ConcentricityTolerance) aToler =
3672 new StepDimTol_ConcentricityTolerance;
3673 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3674 Model->AddWithRefs(aToler);
3677 Handle(StepDimTol_ParallelismTolerance) aToler =
3678 new StepDimTol_ParallelismTolerance;
3679 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3680 Model->AddWithRefs(aToler);
3683 Handle(StepDimTol_PerpendicularityTolerance) aToler =
3684 new StepDimTol_PerpendicularityTolerance;
3685 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3686 Model->AddWithRefs(aToler);
3689 Handle(StepDimTol_SymmetryTolerance) aToler =
3690 new StepDimTol_SymmetryTolerance;
3691 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3692 Model->AddWithRefs(aToler);
3695 Handle(StepDimTol_TotalRunoutTolerance) aToler =
3696 new StepDimTol_TotalRunoutTolerance;
3697 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3698 Model->AddWithRefs(aToler);
3704 return Standard_True;
3707 //=======================================================================
3708 //function : WriteDGTsAP242
3710 //=======================================================================
3712 Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_WorkSession) &WS,
3713 const TDF_LabelSequence &labels ) const
3716 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
3718 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3719 if(aHGraph.IsNull())
3720 return Standard_False;
3722 Interface_Graph aGraph = aHGraph->Graph();
3723 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool(labels(1));
3724 if(DGTTool.IsNull())
3725 return Standard_False;
3727 // Common entities for presentation
3728 gdtPresentationDM = new StepVisual_DraughtingModel();
3729 STEPConstruct_Styles aStyles (WS);
3730 Handle(StepVisual_Colour) aCurvColor = aStyles.EncodeColor(Quantity_NOC_WHITE);
3731 Handle(StepRepr_RepresentationItem) anItem = NULL;
3732 gdtPrsCurveStyle = new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
3733 gdtPrsCurveStyle->SetValue(1, aStyles.MakeColorPSA(anItem, aCurvColor, aCurvColor));
3735 TDF_LabelSequence aDGTLabels;
3736 STEPConstruct_DataMapOfAsciiStringTransient aDatumMap;
3737 Handle(StepRepr_RepresentationContext) aRC;
3742 DGTTool->GetDatumLabels(aDGTLabels);
3743 // Find all shapes with datums
3744 TColStd_MapOfAsciiString aNameIdMap;
3745 for(Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3746 TDF_Label aDatumL = aDGTLabels.Value(i);
3747 TDF_LabelSequence aShapeL;
3748 TDF_LabelSequence aNullSeq;
3749 if(!DGTTool->GetRefShapeLabel(aDatumL, aShapeL, aNullSeq))
3751 Handle(XCAFDoc_Datum) aDatumAttr;
3752 aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr);
3753 Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject();
3754 TCollection_AsciiString aDatumName = anObject->GetName()->String();
3755 TCollection_AsciiString aDatumTargetId = TCollection_AsciiString(anObject->GetDatumTargetNumber());
3756 if (!aNameIdMap.Add(aDatumName.Cat(aDatumTargetId)))
3758 Handle(Standard_Transient) aWrittenDatum;
3759 Standard_Boolean isFirstDT = !aDatumMap.Find(aDatumName, aWrittenDatum);
3760 Handle(StepDimTol_Datum) aDatum = WriteDatumAP242(WS, aShapeL.First(), aDatumL, isFirstDT,
3761 Handle(StepDimTol_Datum)::DownCast (aWrittenDatum));
3762 // Add created Datum into Map
3763 aDatumMap.Bind(aDatumName, aDatum);
3766 //----------------- //
3767 // write Dimensions //
3768 //------------------//
3770 DGTTool->GetDimensionLabels(aDGTLabels);
3771 // Auxiliary entities for derived geometry
3772 Handle(StepRepr_ConstructiveGeometryRepresentation) aCGRepr =
3773 new StepRepr_ConstructiveGeometryRepresentation();
3774 Handle(StepRepr_ConstructiveGeometryRepresentationRelationship) aCGReprRel =
3775 new StepRepr_ConstructiveGeometryRepresentationRelationship();
3776 NCollection_Vector<Handle(StepGeom_CartesianPoint)> aConnectionPnts;
3777 Handle(StepRepr_RepresentationContext) dummyRC;
3778 Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
3779 for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3780 TDF_Label aDimensionL = aDGTLabels.Value(i);
3781 TDF_LabelSequence aFirstShapeL, aSecondShapeL;
3782 Handle(XCAFDoc_Dimension) aDimAttr;
3783 if (!aDimensionL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttr))
3785 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject();
3786 if (anObject.IsNull())
3788 if (anObject->GetType() == XCAFDimTolObjects_DimensionType_CommonLabel)
3790 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->GetPlane());
3793 if (!DGTTool->GetRefShapeLabel(aDimensionL, aFirstShapeL, aSecondShapeL))
3796 // Write links with shapes
3797 Handle(StepRepr_ShapeAspect) aFirstSA, aSecondSA;
3798 if (aFirstShapeL.Length() == 1) {
3799 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(1));
3800 aFirstSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3801 if (aRC.IsNull() && !dummyRC.IsNull())
3804 else if (aFirstShapeL.Length() > 1) {
3805 Handle(StepRepr_CompositeShapeAspect) aCSA;
3806 for (Standard_Integer shIt = 1; shIt <= aFirstShapeL.Length(); shIt++) {
3807 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(shIt));
3808 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3811 if (aCSA.IsNull()) {
3812 aCSA = new StepRepr_CompositeShapeAspect();
3813 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3814 aModel->AddWithRefs(aCSA);
3816 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3817 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA);
3818 aModel->AddWithRefs(aSAR);
3819 if (aRC.IsNull() && !dummyRC.IsNull())
3824 if (aSecondShapeL.Length() == 1) {
3825 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(1));
3826 aSecondSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3827 if (aRC.IsNull() && !dummyRC.IsNull())
3830 else if (aSecondShapeL.Length() > 1) {
3831 Handle(StepRepr_CompositeShapeAspect) aCSA;
3832 for (Standard_Integer shIt = 1; shIt <= aSecondShapeL.Length(); shIt++) {
3833 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(shIt));
3834 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3835 if (aCSA.IsNull() && !aSA.IsNull())
3836 aCSA = new StepRepr_CompositeShapeAspect();
3837 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3838 if (!aSA.IsNull()) {
3839 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3840 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA);
3841 aModel->AddWithRefs(aSAR);
3843 if (aRC.IsNull() && !dummyRC.IsNull())
3850 StepShape_DimensionalCharacteristic aDimension;
3851 if (anObject->HasPoint() || anObject->HasPoint2())
3852 WriteDerivedGeometry(WS, anObject, aCGRepr, aFirstSA, aSecondSA, aConnectionPnts);
3853 XCAFDimTolObjects_DimensionType aDimType = anObject->GetType();
3854 if (STEPCAFControl_GDTProperty::IsDimensionalLocation(aDimType)) {
3855 // Dimensional_Location
3856 Handle(StepShape_DimensionalLocation) aDim = new StepShape_DimensionalLocation();
3857 aDim->Init(STEPCAFControl_GDTProperty::GetDimTypeName(aDimType), Standard_False, NULL, aFirstSA, aSecondSA);
3858 aDimension.SetValue(aDim);
3860 else if (aDimType == XCAFDimTolObjects_DimensionType_Location_Angular) {
3862 Handle(StepShape_AngularLocation) aDim = new StepShape_AngularLocation();
3863 StepShape_AngleRelator aRelator = StepShape_Equal;
3864 if (anObject->HasQualifier()) {
3865 XCAFDimTolObjects_DimensionQualifier aQualifier = anObject->GetQualifier();
3866 switch (aQualifier) {
3867 case XCAFDimTolObjects_DimensionQualifier_Min: aRelator = StepShape_Small;
3869 case XCAFDimTolObjects_DimensionQualifier_Max: aRelator = StepShape_Large;
3871 default: aRelator = StepShape_Equal;
3874 aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aRelator);
3875 aDimension.SetValue(aDim);
3877 else if (aDimType == XCAFDimTolObjects_DimensionType_Location_WithPath) {
3878 // Dimensional_Location_With_Path
3879 Handle(StepShape_DimensionalLocationWithPath) aDim = new StepShape_DimensionalLocationWithPath();
3880 Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU);
3881 aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aPathSA);
3882 aDimension.SetValue(aDim);
3884 else if (STEPCAFControl_GDTProperty::IsDimensionalSize(aDimType)) {
3886 Handle(StepShape_DimensionalSize) aDim = new StepShape_DimensionalSize();
3887 aDim->Init(aFirstSA, STEPCAFControl_GDTProperty::GetDimTypeName(aDimType));
3888 aDimension.SetValue(aDim);
3890 else if (aDimType == XCAFDimTolObjects_DimensionType_Size_Angular) {
3892 Handle(StepShape_AngularSize) aDim = new StepShape_AngularSize();
3893 StepShape_AngleRelator aRelator = StepShape_Equal;
3894 if (anObject->HasQualifier()) {
3895 XCAFDimTolObjects_DimensionQualifier aQualifier = anObject->GetQualifier();
3896 switch (aQualifier) {
3897 case XCAFDimTolObjects_DimensionQualifier_Min: aRelator = StepShape_Small;
3899 case XCAFDimTolObjects_DimensionQualifier_Max: aRelator = StepShape_Large;
3901 default: aRelator = StepShape_Equal;
3904 aDim->Init(aFirstSA, new TCollection_HAsciiString(), aRelator);
3905 aDimension.SetValue(aDim);
3907 else if (aDimType == XCAFDimTolObjects_DimensionType_Size_WithPath) {
3908 // Dimensional_Size_With_Path
3909 Handle(StepShape_DimensionalSizeWithPath) aDim = new StepShape_DimensionalSizeWithPath();
3910 Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU);
3911 aDim->Init(aFirstSA, new TCollection_HAsciiString(), aPathSA);
3912 aDimension.SetValue(aDim);
3916 WriteDimValues(WS, anObject, aRC, aDimension);
3917 //Annotation plane and Presentation
3918 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->GetPlane(), anObject->GetPointTextAttach(), aDimension.Value());
3920 // Write Derived geometry
3921 if (aConnectionPnts.Length() > 0) {
3922 Handle(StepRepr_HArray1OfRepresentationItem) anItems = new StepRepr_HArray1OfRepresentationItem(1, aConnectionPnts.Length());
3923 for (Standard_Integer i = 0; i < aConnectionPnts.Length(); i++)
3924 anItems->SetValue(i + 1, aConnectionPnts(i));
3925 aCGRepr->Init(new TCollection_HAsciiString(), anItems, dummyRC);
3926 aCGReprRel->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), dummyGISU->UsedRepresentation(), aCGRepr);
3927 aModel->AddWithRefs(aCGReprRel);
3930 //----------------------------//
3931 // write Geometric Tolerances //
3932 //----------------------------//
3934 DGTTool->GetGeomToleranceLabels(aDGTLabels);
3935 for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3936 TDF_Label aGeomTolL = aDGTLabels.Value(i);
3937 TDF_LabelSequence aFirstShapeL, aNullSeqL;
3938 if (!DGTTool->GetRefShapeLabel(aGeomTolL, aFirstShapeL, aNullSeqL))
3940 TDF_LabelSequence aDatumSeq;
3941 DGTTool->GetDatumWithObjectOfTolerLabels(aGeomTolL, aDatumSeq);
3942 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
3943 if (aDatumSeq.Length() > 0)
3944 aDatumSystem = WriteDatumSystem(WS, aGeomTolL, aDatumSeq, aDatumMap, aRC);
3945 WriteGeomTolerance(WS, aFirstShapeL, aGeomTolL, aDatumSystem, aRC);
3948 // Write Draughting model for Annotation Planes
3949 if (gdtAnnotationPlanes.Length() == 0)
3950 return Standard_True;
3952 Handle(StepRepr_HArray1OfRepresentationItem) aItems =
3953 new StepRepr_HArray1OfRepresentationItem(1, gdtAnnotationPlanes.Length());
3954 for (Standard_Integer i = 1; i <= aItems->Length(); i++) {
3955 aItems->SetValue(i, gdtAnnotationPlanes.Value(i - 1));
3957 gdtPresentationDM->Init(new TCollection_HAsciiString(), aItems, aRC);
3958 aModel->AddWithRefs(gdtPresentationDM);
3960 return Standard_True;
3963 //=======================================================================
3964 //function : FindPDSforRI
3965 //purpose : auxilary:
3966 //=======================================================================
3967 static Standard_Boolean FindPDSforRI(const Interface_Graph &aGraph,
3968 const Handle(Standard_Transient) &ent,
3969 Handle(StepRepr_ProductDefinitionShape) &PDS,
3970 Handle(StepRepr_RepresentationContext) &RC)
3972 if(!ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem))) return Standard_False;
3973 Interface_EntityIterator subs = aGraph.Sharings(ent);
3974 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
3975 Handle(StepShape_ShapeRepresentation) SR =
3976 Handle(StepShape_ShapeRepresentation)::DownCast(subs.Value());
3977 if(SR.IsNull()) continue;
3978 RC = SR->ContextOfItems();
3979 Interface_EntityIterator subs1 = aGraph.Sharings(SR);
3980 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
3981 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
3982 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs1.Value());
3983 if(SDR.IsNull()) continue;
3984 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
3985 if(PropD.IsNull()) continue;
3986 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
3989 return Standard_True;
3993 //=======================================================================
3994 //function : WriteMaterials
3996 //=======================================================================
3998 Standard_Boolean STEPCAFControl_Writer::WriteMaterials (const Handle(XSControl_WorkSession) &WS,
3999 const TDF_LabelSequence &labels ) const
4002 if ( labels.Length() <=0 ) return Standard_False;
4005 const Handle(Interface_InterfaceModel) &Model = WS->Model();
4006 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
4007 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
4009 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
4010 if(aHGraph.IsNull())
4011 return Standard_False;
4013 Interface_Graph aGraph = WS->HGraph()->Graph();
4014 Handle(XCAFDoc_ShapeTool) ShTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
4015 if(ShTool.IsNull() ) return Standard_False;
4016 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( labels(1) );
4017 if(MatTool.IsNull() ) return Standard_False;
4019 STEPConstruct_DataMapOfAsciiStringTransient MapDRI,MapMRI;
4020 TDF_LabelSequence TopLabels;
4021 ShTool->GetShapes(TopLabels);
4022 for(Standard_Integer i=1; i<=TopLabels.Length(); i++) {
4023 TDF_Label ShL = TopLabels.Value(i);
4024 Handle(TDataStd_TreeNode) Node;
4025 if( ShL.FindAttribute(XCAFDoc::MaterialRefGUID(),Node) && Node->HasFather() ) {
4026 // find PDS for current shape
4027 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShL);
4028 TopLoc_Location Loc;
4029 TColStd_SequenceOfTransient seqRI;
4030 FindEntities( FP, aShape, Loc, seqRI );
4031 if(seqRI.Length()<=0) continue;
4032 Handle(StepRepr_ProductDefinitionShape) PDS;
4033 Handle(StepRepr_RepresentationContext) RC;
4034 Handle(Standard_Transient) ent = seqRI.Value(1);
4035 FindPDSforRI(aGraph,ent,PDS,RC);
4036 if(PDS.IsNull()) continue;
4037 Handle(StepBasic_ProductDefinition) aProdDef =
4038 PDS->Definition().ProductDefinition();
4039 if(aProdDef.IsNull())
4041 // write material entities
4042 TDF_Label MatL = Node->Father()->Label();
4043 Handle(TCollection_HAsciiString) aName;
4044 Handle(TCollection_HAsciiString) aDescription;
4045 Standard_Real aDensity;
4046 Handle(TCollection_HAsciiString) aDensName;
4047 Handle(TCollection_HAsciiString) aDensValType;
4048 Handle(StepRepr_Representation) RepDRI;
4049 Handle(StepRepr_Representation) RepMRI;
4050 if(MatTool->GetMaterial(MatL,aName,aDescription,aDensity,aDensName,aDensValType)) {
4051 if(aName->Length()==0) continue;
4052 TCollection_AsciiString aKey(aName->ToCString());
4053 if(MapDRI.IsBound(aKey)) {
4054 RepDRI = Handle(StepRepr_Representation)::DownCast(MapDRI.Find(aKey));
4055 if(MapMRI.IsBound(aKey)) {
4056 RepMRI = Handle(StepRepr_Representation)::DownCast(MapMRI.Find(aKey));
4061 Handle(StepRepr_DescriptiveRepresentationItem) DRI = new StepRepr_DescriptiveRepresentationItem;
4062 DRI->Init(aName,aDescription);
4063 Handle(StepRepr_HArray1OfRepresentationItem) HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
4064 HARI->SetValue(1,DRI);
4065 RepDRI = new StepRepr_Representation();
4066 RepDRI->Init(new TCollection_HAsciiString("material name"),HARI,RC);
4067 Model->AddWithRefs(RepDRI);
4069 if( aDensity > 0 ) {
4071 Handle(StepBasic_SiUnitAndMassUnit) SMU = new StepBasic_SiUnitAndMassUnit;
4072 SMU->SetName(StepBasic_sunGram);
4073 Handle(StepBasic_DerivedUnitElement) DUE1 = new StepBasic_DerivedUnitElement;
4074 DUE1->Init(SMU,3.0);
4076 Handle(StepBasic_SiUnitAndLengthUnit) SLU = new StepBasic_SiUnitAndLengthUnit;
4077 SLU->Init(Standard_True,StepBasic_spCenti,StepBasic_sunMetre);
4078 Handle(StepBasic_DerivedUnitElement) DUE2 = new StepBasic_DerivedUnitElement;
4079 DUE2->Init(SLU,2.0);
4081 Handle(StepBasic_HArray1OfDerivedUnitElement) HADUE = new StepBasic_HArray1OfDerivedUnitElement(1,2);
4082 HADUE->SetValue(1,DUE1);
4083 HADUE->SetValue(2,DUE2);
4084 Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit;
4086 Model->AddWithRefs(DU);
4087 StepBasic_Unit aUnit;
4089 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
4090 MVM->SetName(aDensValType->ToCString());
4091 MVM->SetReal(aDensity);
4092 Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem;
4093 MRI->Init(aDensName,MVM,aUnit);
4094 HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
4095 HARI->SetValue(1,MRI);
4096 RepMRI = new StepRepr_Representation();
4097 RepMRI->Init(new TCollection_HAsciiString("density"),HARI,RC);
4098 Model->AddWithRefs(RepMRI);
4100 //WriteNewMaterial(Model,aName,aDescription,aDensity,aDensName,aDensValType,RC,RepDRI,RepMRI);
4101 MapDRI.Bind(aKey,RepDRI);
4102 if ( !RepMRI.IsNull() ) MapMRI.Bind (aKey, RepMRI);
4106 if( !RepDRI.IsNull() )
4108 StepRepr_CharacterizedDefinition CD1;
4109 CD1.SetValue(aProdDef);
4110 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
4111 PropD1->Init(new TCollection_HAsciiString("material property"),Standard_True,
4112 new TCollection_HAsciiString("material name"),CD1);
4113 Model->AddWithRefs(PropD1);
4114 StepRepr_RepresentedDefinition RD1;
4115 RD1.SetValue(PropD1);
4116 Handle(StepRepr_PropertyDefinitionRepresentation) PDR1 =
4117 new StepRepr_PropertyDefinitionRepresentation;
4118 PDR1->Init(RD1,RepDRI);
4119 Model->AddWithRefs(PDR1);
4121 if( !RepMRI.IsNull() )
4123 StepRepr_CharacterizedDefinition CD2;
4124 CD2.SetValue (aProdDef);
4125 Handle (StepRepr_PropertyDefinition) PropD2 = new StepRepr_PropertyDefinition;
4126 PropD2->Init (new TCollection_HAsciiString ("material property"), Standard_True,
4127 new TCollection_HAsciiString ("density"), CD2);
4128 Model->AddWithRefs (PropD2);
4129 StepRepr_RepresentedDefinition RD2;
4130 RD2.SetValue (PropD2);
4131 Handle (StepRepr_PropertyDefinitionRepresentation) PDR2 =
4132 new StepRepr_PropertyDefinitionRepresentation;
4133 PDR2->Init (RD2, RepMRI);
4134 Model->AddWithRefs (PDR2);
4140 return Standard_True;
4144 //=======================================================================
4145 //function : SetColorMode
4147 //=======================================================================
4149 void STEPCAFControl_Writer::SetColorMode (const Standard_Boolean colormode)
4151 myColorMode = colormode;
4155 //=======================================================================
4156 //function : GetColorMode
4158 //=======================================================================
4160 Standard_Boolean STEPCAFControl_Writer::GetColorMode () const
4166 //=======================================================================
4167 //function : SetNameMode
4169 //=======================================================================
4171 void STEPCAFControl_Writer::SetNameMode (const Standard_Boolean namemode)
4173 myNameMode = namemode;
4177 //=======================================================================
4178 //function : GetNameMode
4180 //=======================================================================
4182 Standard_Boolean STEPCAFControl_Writer::GetNameMode () const
4188 //=======================================================================
4189 //function : SetLayerMode
4191 //=======================================================================
4193 void STEPCAFControl_Writer::SetLayerMode (const Standard_Boolean layermode)
4195 myLayerMode = layermode;
4199 //=======================================================================
4200 //function : GetLayerMode
4202 //=======================================================================
4204 Standard_Boolean STEPCAFControl_Writer::GetLayerMode () const
4210 //=======================================================================
4211 //function : SetPropsMode
4213 //=======================================================================
4215 void STEPCAFControl_Writer::SetPropsMode (const Standard_Boolean propsmode)
4217 myPropsMode = propsmode;
4221 //=======================================================================
4222 //function : GetPropsMode
4224 //=======================================================================
4226 Standard_Boolean STEPCAFControl_Writer::GetPropsMode () const
4232 //=======================================================================
4233 //function : SetSHUOMode
4235 //=======================================================================
4237 void STEPCAFControl_Writer::SetSHUOMode (const Standard_Boolean mode)
4243 //=======================================================================
4244 //function : GetSHUOMode
4246 //=======================================================================
4248 Standard_Boolean STEPCAFControl_Writer::GetSHUOMode () const
4254 //=======================================================================
4255 //function : SetDimTolMode
4257 //=======================================================================
4259 void STEPCAFControl_Writer::SetDimTolMode(const Standard_Boolean dimtolmode)
4261 myDGTMode = dimtolmode;
4265 //=======================================================================
4266 //function : GetDimTolMode
4268 //=======================================================================
4270 Standard_Boolean STEPCAFControl_Writer::GetDimTolMode() const
4276 //=======================================================================
4277 //function : SetMaterialMode
4279 //=======================================================================
4281 void STEPCAFControl_Writer::SetMaterialMode(const Standard_Boolean matmode)
4283 myMatMode = matmode;
4287 //=======================================================================
4288 //function : GetMaterialMode
4290 //=======================================================================
4292 Standard_Boolean STEPCAFControl_Writer::GetMaterialMode() const