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_MakeAxis2Placement3d.hxx>
25 #include <GeomToStep_MakeCartesianPoint.hxx>
26 #include <HeaderSection_FileSchema.hxx>
27 #include <Interface_EntityIterator.hxx>
28 #include <Interface_Static.hxx>
29 #include <Message_Messenger.hxx>
30 #include <MoniTool_DataMapIteratorOfDataMapOfShapeTransient.hxx>
31 #include <NCollection_Vector.hxx>
32 #include <OSD_Path.hxx>
33 #include <Quantity_TypeOfColor.hxx>
34 #include <StepAP214_Protocol.hxx>
35 #include <StepAP242_DraughtingModelItemAssociation.hxx>
36 #include <StepAP242_GeometricItemSpecificUsage.hxx>
37 #include <StepBasic_ConversionBasedUnitAndLengthUnit.hxx>
38 #include <StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx>
39 #include <StepBasic_DerivedUnit.hxx>
40 #include <StepBasic_DerivedUnitElement.hxx>
41 #include <StepBasic_HArray1OfDerivedUnitElement.hxx>
42 #include <StepBasic_LengthMeasureWithUnit.hxx>
43 #include <StepBasic_MeasureValueMember.hxx>
44 #include <StepBasic_Product.hxx>
45 #include <StepBasic_ProductDefinition.hxx>
46 #include <StepBasic_ProductDefinitionFormation.hxx>
47 #include <StepBasic_ProductDefinitionRelationship.hxx>
48 #include <StepBasic_SiUnitAndLengthUnit.hxx>
49 #include <StepBasic_SiUnitAndMassUnit.hxx>
50 #include <StepBasic_SiUnitAndPlaneAngleUnit.hxx>
51 #include <STEPCAFControl_ActorWrite.hxx>
52 #include <STEPCAFControl_Controller.hxx>
53 #include <STEPCAFControl_ExternFile.hxx>
54 #include <STEPCAFControl_Writer.hxx>
55 #include <STEPConstruct.hxx>
56 #include <STEPConstruct_DataMapOfAsciiStringTransient.hxx>
57 #include <STEPConstruct_DataMapOfPointTransient.hxx>
58 #include <STEPConstruct_ExternRefs.hxx>
59 #include <STEPCAFControl_GDTProperty.hxx>
60 #include <STEPConstruct_Styles.hxx>
61 #include <STEPConstruct_ValidationProps.hxx>
62 #include <STEPControl_StepModelType.hxx>
63 #include <STEPControl_Writer.hxx>
64 #include <StepData_Logical.hxx>
65 #include <StepData_StepModel.hxx>
66 #include <StepDimTol_AngularityTolerance.hxx>
67 #include <StepDimTol_CircularRunoutTolerance.hxx>
68 #include <StepDimTol_CoaxialityTolerance.hxx>
69 #include <StepDimTol_ConcentricityTolerance.hxx>
70 #include <StepDimTol_CylindricityTolerance.hxx>
71 #include <StepDimTol_Datum.hxx>
72 #include <StepDimTol_DatumFeature.hxx>
73 #include <StepDimTol_DatumReference.hxx>
74 #include <StepDimTol_DatumReferenceElement.hxx>
75 #include <StepDimTol_DatumSystem.hxx>
76 #include <StepDimTol_DatumSystemOrReference.hxx>
77 #include <StepDimTol_DatumTarget.hxx>
78 #include <StepDimTol_FlatnessTolerance.hxx>
79 #include <StepDimTol_GeometricToleranceType.hxx>
80 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
81 #include <StepDimTol_GeometricToleranceWithModifiers.hxx>
82 #include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx>
83 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
84 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
85 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
86 #include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx>
87 #include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
88 #include <StepDimTol_HArray1OfDatumReference.hxx>
89 #include <StepDimTol_HArray1OfDatumReferenceElement.hxx>
90 #include <StepDimTol_HArray1OfDatumReferenceModifier.hxx>
91 #include <StepDimTol_HArray1OfDatumSystemOrReference.hxx>
92 #include <StepDimTol_LineProfileTolerance.hxx>
93 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
94 #include <StepDimTol_ParallelismTolerance.hxx>
95 #include <StepDimTol_PerpendicularityTolerance.hxx>
96 #include <StepDimTol_PlacedDatumTargetFeature.hxx>
97 #include <StepDimTol_PositionTolerance.hxx>
98 #include <StepDimTol_RoundnessTolerance.hxx>
99 #include <StepDimTol_RunoutZoneDefinition.hxx>
100 #include <StepDimTol_RunoutZoneOrientation.hxx>
101 #include <StepDimTol_StraightnessTolerance.hxx>
102 #include <StepDimTol_SurfaceProfileTolerance.hxx>
103 #include <StepDimTol_SymmetryTolerance.hxx>
104 #include <StepDimTol_ToleranceZone.hxx>
105 #include <StepDimTol_ToleranceZoneForm.hxx>
106 #include <StepDimTol_TotalRunoutTolerance.hxx>
107 #include <StepGeom_Axis2Placement3d.hxx>
108 #include <StepGeom_CartesianPoint.hxx>
109 #include <StepGeom_Direction.hxx>
110 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
111 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
112 #include <StepGeom_Plane.hxx>
113 #include <StepGeom_Surface.hxx>
114 #include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx>
115 #include <StepRepr_CompositeShapeAspect.hxx>
116 #include <StepRepr_ConstructiveGeometryRepresentation.hxx>
117 #include <StepRepr_ConstructiveGeometryRepresentationRelationship.hxx>
118 #include <StepRepr_DerivedShapeAspect.hxx>
119 #include <StepRepr_DescriptiveRepresentationItem.hxx>
120 #include <StepRepr_FeatureForDatumTargetRelationship.hxx>
121 #include <StepRepr_HArray1OfRepresentationItem.hxx>
122 #include <StepRepr_MeasureRepresentationItem.hxx>
123 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
124 #include <StepRepr_ProductDefinitionShape.hxx>
125 #include <StepRepr_PropertyDefinition.hxx>
126 #include <StepRepr_RepresentedDefinition.hxx>
127 #include <StepRepr_Representation.hxx>
128 #include <StepRepr_RepresentationItem.hxx>
129 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
130 #include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx>
131 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
132 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx>
133 #include <StepRepr_ShapeAspect.hxx>
134 #include <StepRepr_ShapeAspectDerivingRelationship.hxx>
135 #include <StepRepr_ShapeAspectRelationship.hxx>
136 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
137 #include <StepRepr_ValueRange.hxx>
138 #include <StepShape_AdvancedFace.hxx>
139 #include <StepShape_AngleRelator.hxx>
140 #include <StepShape_AngularLocation.hxx>
141 #include <StepShape_AngularSize.hxx>
142 #include <StepShape_ConnectedFaceSet.hxx>
143 #include <StepShape_ContextDependentShapeRepresentation.hxx>
144 #include <StepShape_DimensionalCharacteristic.hxx>
145 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
146 #include <StepShape_DimensionalLocation.hxx>
147 #include <StepShape_DimensionalLocationWithPath.hxx>
148 #include <StepShape_DimensionalSize.hxx>
149 #include <StepShape_DimensionalSizeWithPath.hxx>
150 #include <StepShape_EdgeCurve.hxx>
151 #include <StepShape_EdgeLoop.hxx>
152 #include <StepShape_FaceBound.hxx>
153 #include <StepShape_LimitsAndFits.hxx>
154 #include <StepShape_OrientedEdge.hxx>
155 #include <StepShape_PlusMinusTolerance.hxx>
156 #include <StepShape_QualifiedRepresentationItem.hxx>
157 #include <StepShape_ShapeDefinitionRepresentation.hxx>
158 #include <StepShape_ShapeDimensionRepresentation.hxx>
159 #include <StepShape_ShapeRepresentation.hxx>
160 #include <StepShape_ShapeRepresentationWithParameters.hxx>
161 #include <StepShape_ToleranceValue.hxx>
162 #include <StepShape_TypeQualifier.hxx>
163 #include <StepShape_ValueFormatTypeQualifier.hxx>
164 #include <StepVisual_AnnotationPlane.hxx>
165 #include <StepVisual_CurveStyle.hxx>
166 #include <StepVisual_DraughtingCallout.hxx>
167 #include <StepVisual_DraughtingModel.hxx>
168 #include <StepVisual_HArray1OfInvisibleItem.hxx>
169 #include <StepVisual_HArray1OfLayeredItem.hxx>
170 #include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
171 #include <StepVisual_HArray1OfPresentationStyleSelect.hxx>
172 #include <StepVisual_Invisibility.hxx>
173 #include <StepVisual_InvisibleItem.hxx>
174 #include <StepVisual_MechanicalDesignGeometricPresentationRepresentation.hxx>
175 #include <StepVisual_NullStyleMember.hxx>
176 #include <StepVisual_PointStyle.hxx>
177 #include <StepVisual_PresentationLayerAssignment.hxx>
178 #include <StepVisual_PresentationRepresentation.hxx>
179 #include <StepVisual_PresentationStyleAssignment.hxx>
180 #include <StepVisual_PresentationStyleByContext.hxx>
181 #include <StepVisual_StyledItem.hxx>
182 #include <StepVisual_SurfaceStyleUsage.hxx>
183 #include <StepVisual_TessellatedAnnotationOccurrence.hxx>
184 #include <StepVisual_TessellatedGeometricSet.hxx>
185 #include <TCollection_AsciiString.hxx>
186 #include <TCollection_HAsciiString.hxx>
187 #include <TColStd_HArray1OfReal.hxx>
188 #include <TColStd_HArray1OfTransient.hxx>
189 #include <TColStd_HSequenceOfTransient.hxx>
190 #include <TColStd_MapOfAsciiString.hxx>
191 #include <TColStd_MapOfTransient.hxx>
192 #include <TDataStd_Name.hxx>
193 #include <TDataStd_TreeNode.hxx>
194 #include <TDataStd_UAttribute.hxx>
195 #include <TDF_AttributeSequence.hxx>
196 #include <TDF_ChildIterator.hxx>
197 #include <TDF_Label.hxx>
198 #include <TDF_LabelSequence.hxx>
199 #include <TDF_Tool.hxx>
200 #include <TDocStd_Document.hxx>
201 #include <TopoDS_Compound.hxx>
202 #include <TopoDS_Iterator.hxx>
203 #include <TopoDS_Shape.hxx>
204 #include <TopTools_MapOfShape.hxx>
205 #include <TopTools_SequenceOfShape.hxx>
206 #include <Transfer_ActorOfFinderProcess.hxx>
207 #include <Transfer_Binder.hxx>
208 #include <Transfer_FinderProcess.hxx>
209 #include <Transfer_TransientListBinder.hxx>
210 #include <TransferBRep.hxx>
211 #include <TransferBRep_ShapeMapper.hxx>
212 #include <XCAFDimTolObjects_DatumObject.hxx>
213 #include <XCAFDimTolObjects_DimensionFormVariance.hxx>
214 #include <XCAFDimTolObjects_DimensionGrade.hxx>
215 #include <XCAFDimTolObjects_DimensionObject.hxx>
216 #include <XCAFDimTolObjects_DimensionModif.hxx>
217 #include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
218 #include <XCAFDimTolObjects_DimensionQualifier.hxx>
219 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
220 #include <XCAFDoc.hxx>
221 #include <XCAFDoc_Area.hxx>
222 #include <XCAFDoc_Centroid.hxx>
223 #include <XCAFDoc_ColorTool.hxx>
224 #include <XCAFDoc_Datum.hxx>
225 #include <XCAFDoc_Dimension.hxx>
226 #include <XCAFDoc_DimTol.hxx>
227 #include <XCAFDoc_DimTolTool.hxx>
228 #include <XCAFDoc_DocumentTool.hxx>
229 #include <XCAFDoc_GeomTolerance.hxx>
230 #include <XCAFDoc_GraphNode.hxx>
231 #include <XCAFDoc_LayerTool.hxx>
232 #include <XCAFDoc_Material.hxx>
233 #include <XCAFDoc_MaterialTool.hxx>
234 #include <XCAFDoc_ShapeTool.hxx>
235 #include <XCAFDoc_Volume.hxx>
236 #include <XCAFDoc_VisMaterial.hxx>
237 #include <XCAFDoc_VisMaterialTool.hxx>
238 #include <XCAFPrs.hxx>
239 #include <XCAFPrs_DataMapIteratorOfDataMapOfStyleShape.hxx>
240 #include <XCAFPrs_IndexedDataMapOfShapeStyle.hxx>
241 #include <XCAFPrs_DataMapOfStyleShape.hxx>
242 #include <XCAFPrs_Style.hxx>
243 #include <XSControl_TransferWriter.hxx>
244 #include <XSControl_WorkSession.hxx>
246 // added by skl 15.01.2004 for D> writing
247 //#include <StepRepr_CompoundItemDefinition.hxx>
248 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
249 // added by skl 12.02.2004 for writing materials
250 //=======================================================================
251 //function : GetLabelName
252 //purpose : auxilary function: take name of label and append it to str
253 //=======================================================================
254 static Standard_Boolean GetLabelName (const TDF_Label &L, Handle(TCollection_HAsciiString) &str)
256 Handle(TDataStd_Name) N;
257 if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) return Standard_False;
258 TCollection_ExtendedString name = N->Get();
259 if ( name.Length() <=0 ) return Standard_False;
261 // set name, converting it to Ascii and removing spaces
262 TCollection_AsciiString buf ( name, '?' );
265 buf.ChangeAll(' ','_');
266 str->AssignCat ( buf.ToCString() );
267 return Standard_True;
271 //=======================================================================
272 //function : STEPCAFControl_Writer
274 //=======================================================================
276 STEPCAFControl_Writer::STEPCAFControl_Writer () :
277 myColorMode( Standard_True ),
278 myNameMode ( Standard_True ),
279 myLayerMode( Standard_True ),
280 myPropsMode( Standard_True ),
281 mySHUOMode ( Standard_True ),
282 myGDTMode ( Standard_True ),
283 myMatMode ( Standard_True )
285 STEPCAFControl_Controller::Init();
286 Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
291 //=======================================================================
292 //function : STEPCAFControl_Writer
294 //=======================================================================
296 STEPCAFControl_Writer::STEPCAFControl_Writer (const Handle(XSControl_WorkSession)& WS,
297 const Standard_Boolean scratch) :
298 myColorMode(Standard_True),
299 myNameMode(Standard_True),
300 myLayerMode(Standard_True),
301 myPropsMode(Standard_True),
302 mySHUOMode(Standard_True),
303 myGDTMode(Standard_True),
304 myMatMode(Standard_True)
306 STEPCAFControl_Controller::Init();
307 Init ( WS, scratch );
311 //=======================================================================
314 //=======================================================================
316 void STEPCAFControl_Writer::Init (const Handle(XSControl_WorkSession)& WS,
317 const Standard_Boolean scratch)
319 WS->SelectNorm ( "STEP" );
320 myWriter.SetWS (WS,scratch);
324 myGDTPresentationDM = new StepVisual_DraughtingModel();
325 myGDTPrsCurveStyle = new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
329 //=======================================================================
332 //=======================================================================
334 IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filename)
336 IFSelect_ReturnStatus status = myWriter.Write ( filename );
338 // get directory name of the main file
339 OSD_Path mainfile ( filename );
340 mainfile.SetName ( "" );
341 mainfile.SetExtension ( "" );
342 TCollection_AsciiString dpath;
343 mainfile.SystemName ( dpath );
345 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator it(myFiles);
346 for ( ; it.More(); it.Next() ) {
347 Handle(STEPCAFControl_ExternFile) EF = it.Value();
348 if ( EF->GetWriteStatus() != IFSelect_RetVoid ) continue;
350 // construct extern file name
351 TCollection_AsciiString fname = OSD_Path::AbsolutePath ( dpath, EF->GetName()->String() );
352 if ( fname.Length() <= 0 ) fname = EF->GetName()->String();
354 std::cout << "Writing external file: " << fname.ToCString() << std::endl;
357 EF->SetWriteStatus ( EF->GetWS()->SendAll ( fname.ToCString() ) );
364 //=======================================================================
365 //function : Transfer
367 //=======================================================================
369 Standard_Boolean STEPCAFControl_Writer::Transfer( const Handle(TDocStd_Document) &doc,
370 const STEPControl_StepModelType mode,
371 const Standard_CString multi )
373 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
374 if ( STool.IsNull() ) return Standard_False;
376 TDF_LabelSequence labels;
377 STool->GetFreeShapes ( labels );
378 return Transfer ( myWriter, labels, mode, multi );
382 //=======================================================================
383 //function : Transfer
385 //=======================================================================
387 Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_Label& L,
388 const STEPControl_StepModelType mode,
389 const Standard_CString multi )
391 TDF_LabelSequence labels;
393 return Transfer ( myWriter, labels, mode, multi );
396 //=======================================================================
397 //function : Transfer
399 //=======================================================================
401 Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_LabelSequence& labels,
402 const STEPControl_StepModelType mode,
403 const Standard_CString multi )
405 return Transfer( myWriter, labels, mode, multi );
408 //=======================================================================
411 //=======================================================================
413 Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
414 const Standard_CString filename)
416 if ( ! Transfer ( doc ) ) return Standard_False;
417 return Write ( filename ) == IFSelect_RetDone;
421 //=======================================================================
424 //=======================================================================
426 Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
427 const TCollection_AsciiString &filename)
429 if ( ! Transfer ( doc ) ) return Standard_False;
430 return Write ( filename.ToCString() ) == IFSelect_RetDone;
434 //=======================================================================
435 //function : ExternFiles
437 //=======================================================================
439 const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& STEPCAFControl_Writer::ExternFiles () const
445 //=======================================================================
446 //function : ExternFile
448 //=======================================================================
450 Standard_Boolean STEPCAFControl_Writer::ExternFile (const TDF_Label &L,
451 Handle(STEPCAFControl_ExternFile) &ef) const
454 if ( ! myLabEF.IsBound ( L ) ) return Standard_False;
455 ef = myLabEF.Find ( L );
456 return Standard_True;
460 //=======================================================================
461 //function : ExternFile
463 //=======================================================================
465 Standard_Boolean STEPCAFControl_Writer::ExternFile (const Standard_CString name,
466 Handle(STEPCAFControl_ExternFile) &ef) const
469 if ( ! myFiles.IsEmpty() || ! myFiles.IsBound ( name ) )
470 return Standard_False;
471 ef = myFiles.Find( name );
472 return Standard_True;
476 //=======================================================================
479 //=======================================================================
481 STEPControl_Writer &STEPCAFControl_Writer::ChangeWriter ()
487 //=======================================================================
490 //=======================================================================
492 const STEPControl_Writer &STEPCAFControl_Writer::Writer () const
498 //=======================================================================
499 //function : Transfer
501 //=======================================================================
503 Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
504 const TDF_LabelSequence &labels,
505 const STEPControl_StepModelType mode,
506 const Standard_CString multi,
507 const Standard_Boolean isExternFile)
509 if ( labels.Length() <=0 ) return Standard_False;
511 Handle(STEPCAFControl_ActorWrite) Actor =
512 Handle(STEPCAFControl_ActorWrite)::DownCast ( writer.WS()->NormAdaptor()->ActorWrite() );
514 // translate free top-level shapes of the DECAF document
515 Standard_Integer ap = Interface_Static::IVal ("write.step.schema");
516 TDF_LabelSequence sublabels;
517 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
518 TDF_Label L = labels.Value(i);
519 if ( myLabels.IsBound ( L ) ) continue; // already processed
521 TopoDS_Shape shape = XCAFDoc_ShapeTool::GetShape ( L );
522 if ( shape.IsNull() ) continue;
524 // write shape either as a whole, or as multifile (with extern refs)
526 Actor->SetStdMode ( Standard_False );
528 TDF_LabelSequence comp;
530 //For case when only part of assemby structure should be written in the document
531 //if specified label is component of the assembly then
532 //in order to save location of this component in the high-level assembly
533 //and save name of high-level assembly it is necessary to represent structure of high-level assembly
534 //as assembly with one component specified by current label.
535 //For that compound containing only specified component is binded to the label of the high-level assembly.
536 //The such way full structure of high-level assembly was replaced on the assembly contaning one component.
537 //For case when free shape reference is (located root) also create an auxiliary assembly.
538 if ( XCAFDoc_ShapeTool::IsReference ( L ) )
540 TopoDS_Compound aComp;
542 aB.MakeCompound(aComp);
543 aB.Add(aComp, shape);
547 if ( XCAFDoc_ShapeTool::GetReferredShape ( L, ref ) )
549 if(XCAFDoc_ShapeTool::IsAssembly ( ref))
550 XCAFDoc_ShapeTool::GetComponents ( ref, comp, Standard_True );
552 if ( !XCAFDoc_ShapeTool::IsFree ( L ) )
557 // fill sequence of (sub) shapes for which attributes should be written
558 // and set actor to handle assemblies in a proper way
559 if(XCAFDoc_ShapeTool::IsAssembly ( L ))
560 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_True );
563 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
565 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( comp(k), ref ) ) continue;
566 if ( ! myLabels.IsBound ( ref ) ) {
567 TopoDS_Shape refS = XCAFDoc_ShapeTool::GetShape ( ref );
568 myLabels.Bind ( ref, refS );
569 sublabels.Append ( ref );
570 if ( XCAFDoc_ShapeTool::IsAssembly ( ref ) )
571 Actor->RegisterAssembly ( refS );
574 myLabels.Bind ( L, shape );
575 sublabels.Append ( L );
577 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) || XCAFDoc_ShapeTool::IsReference ( L ) )
578 Actor->RegisterAssembly ( shape );
580 writer.Transfer(shape,mode,Standard_False);
581 Actor->SetStdMode ( Standard_True ); // restore default behaviour
584 // translate final solids
585 TopoDS_Shape Sass = TransferExternFiles ( L, mode, sublabels, multi );
587 // translate main assembly structure
589 if ( ap == 3 ) { // if AP203, switch to AP214
590 Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
591 Handle(StepData_StepModel) model =
592 Handle(StepData_StepModel)::DownCast ( writer.WS()->Model() );
593 if ( model->HasHeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) ) {
594 Handle(HeaderSection_FileSchema) fs =
595 Handle(HeaderSection_FileSchema)::DownCast ( model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) );
596 Handle(TCollection_HAsciiString) str = fs->SchemaIdentifiersValue ( 1 );
597 Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "AUTOMOTIVE_DESIGN" );
598 if ( str->Search ( ap214 ) <0 ) {
600 str->AssignCat ( ap214 );
605 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
606 Interface_Static::SetCVal ("write.step.assembly", "On");
607 writer.Transfer ( Sass, STEPControl_AsIs );
608 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
609 Interface_Static::SetIVal ("write.step.schema", ap);
613 writer.WS()->ComputeGraph(Standard_True );// added by skl 03.11.2003 since we use
614 // writer.Transfer() wihtout compute graph
618 WriteNames ( writer.WS(), sublabels );
622 if ( GetColorMode() )
623 WriteColors ( writer.WS(), sublabels );
626 if ( GetLayerMode() )
627 WriteLayers ( writer.WS(), sublabels );
629 // write SHUO entities
630 if ( GetSHUOMode() && !isExternFile )
631 // do not store SHUO for extern reference for the moment
632 WriteSHUOs ( writer.WS(), sublabels );
635 if(GetDimTolMode()) {
637 WriteDGTsAP242(writer.WS(), sublabels);
640 WriteDGTs(writer.WS(), sublabels);
645 if(GetMaterialMode())
646 WriteMaterials(writer.WS(),sublabels);
648 // register all MDGPRs in model
649 const Handle(Interface_InterfaceModel) &Model = writer.WS()->Model();
650 MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR);
651 for (; anItr.More(); anItr.Next())
652 Model->AddWithRefs( anItr.Value() );
655 if ( multi ) { // external refs
656 WriteExternRefs ( writer.WS(), sublabels );
659 // write validation props
660 // if ( multi && ap ==3 ) {
661 // Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
663 if ( GetPropsMode() )
664 WriteValProps ( writer.WS(), sublabels, multi );
666 Interface_Static::SetIVal ("write.step.schema", ap);
669 writer.WS()->ComputeGraph ( Standard_True );
671 /* ================================
672 * Write names for the sub-shapes
673 * ================================ */
675 if (Interface_Static::IVal("write.stepcaf.subshapes.name") != 0)
677 const Handle(XSControl_TransferWriter) &TW = this->ChangeWriter().WS()->TransferWriter();
678 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
680 for ( int i = 1; i <= sublabels.Length(); i++ )
682 TDF_Label L = sublabels.Value(i);
684 for ( TDF_ChildIterator it(L, Standard_True); it.More(); it.Next() )
686 TDF_Label SubL = it.Value();
688 // Access name recorded in OCAF TDataStd_Name attribute
689 Handle(TCollection_HAsciiString) hSubName = new TCollection_HAsciiString;
690 if ( !GetLabelName(SubL, hSubName) )
693 // Access topological data
694 TopoDS_Shape SubS = XCAFDoc_ShapeTool::GetShape(SubL);
698 // Access the correspondent STEP Representation Item
699 Handle(StepRepr_RepresentationItem) RI;
700 Handle(TransferBRep_ShapeMapper) aShMapper = TransferBRep::ShapeMapper(FP, SubS);
701 if ( !FP->FindTypedTransient(aShMapper, STANDARD_TYPE(StepRepr_RepresentationItem), RI) )
705 RI->SetName(hSubName);
710 return Standard_True;
714 //=======================================================================
715 //function : TransferExternFiles
717 //=======================================================================
719 TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L,
720 const STEPControl_StepModelType mode,
721 TDF_LabelSequence &labels,
722 const Standard_CString prefix)
724 // if label already translated, just return the shape
725 if ( myLabels.IsBound ( L ) ) {
726 return myLabels.Find ( L );
731 B.MakeCompound ( C );
732 //labels.Append ( L );
733 // if not assembly, write to separate file
734 if ( ! XCAFDoc_ShapeTool::IsAssembly ( L ) && !XCAFDoc_ShapeTool::IsComponent ( L )) {
736 // prepare for transfer
737 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
738 newWS->SelectNorm ( "STEP" );
739 STEPControl_Writer sw ( newWS, Standard_True );
740 TDF_LabelSequence Lseq;
743 // construct the name for extern file
744 Handle(TCollection_HAsciiString) basename = new TCollection_HAsciiString;
745 if ( prefix && prefix[0] ) basename->AssignCat ( prefix );
746 GetLabelName ( L, basename );
747 Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString ( basename );
748 name->AssignCat ( ".stp" );
749 if ( myFiles.IsBound( name->ToCString() ) ) { // avoid confusions
750 for ( Standard_Integer k=1; k < 32000; k++ ) {
751 name = new TCollection_HAsciiString ( basename );
752 name->AssignCat ( "_" );
753 name->AssignCat ( TCollection_AsciiString ( k ).ToCString() );
754 name->AssignCat ( ".stp" );
755 if ( ! myFiles.IsBound ( name->ToCString() ) ) break;
759 // translate and record extern file
760 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
762 EF->SetName ( name );
764 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
765 Interface_Static::SetCVal ("write.step.assembly", "Off");
766 const Standard_CString multi = 0;
767 EF->SetTransferStatus ( Transfer ( sw, Lseq, mode, multi, Standard_True ) );
768 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
769 myLabEF.Bind ( L, EF );
770 myFiles.Bind ( name->ToCString(), EF );
772 // return empty compound as replacement for the shape
773 myLabels.Bind ( L, C );
776 TDF_LabelSequence comp;
778 //if specified shape is component then high-level assembly is considered
779 //to get valid structure with location
780 if ( XCAFDoc_ShapeTool::IsComponent ( L ) )
785 // else iterate on components add create structure of empty compounds
786 // representing the assembly
787 else if (XCAFDoc_ShapeTool::IsAssembly ( L ))
788 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_False );
790 labels.Append ( aCurL );
791 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
792 TDF_Label lab = comp(k);
794 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, ref ) ) continue;
795 TopoDS_Shape Scomp = TransferExternFiles ( ref, mode, labels, prefix );
796 Scomp.Location ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
799 myLabels.Bind ( aCurL, C );
804 //=======================================================================
805 //function : WriteExternRefs
807 //=======================================================================
809 Standard_Boolean STEPCAFControl_Writer::WriteExternRefs (const Handle(XSControl_WorkSession) &WS,
810 const TDF_LabelSequence &labels) const
812 if ( labels.Length() <=0 ) return Standard_False;
814 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
815 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
816 STEPConstruct_ExternRefs EFTool ( WS );
817 Standard_Integer schema = Interface_Static::IVal("write.step.schema");
818 for ( Standard_Integer k=1; k <= labels.Length(); k++ ) {
819 TDF_Label lab = labels(k);
820 if ( XCAFDoc_ShapeTool::IsAssembly ( lab ) ) continue; // skip assemblies
823 Handle(STEPCAFControl_ExternFile) EF;
824 if ( ! ExternFile ( lab, EF ) ) continue; // should never be
827 if ( ! myLabels.IsBound ( lab ) ) continue; // not recorded as translated, skip
828 TopoDS_Shape S = myLabels.Find ( lab );
830 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
831 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
832 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
834 std::cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << std::endl;
840 const char* format = (schema == 3 ? "STEP AP203" : "STEP AP214");
841 // try to get PD from SDR
842 StepRepr_RepresentedDefinition RD = SDR->Definition();
843 Handle(StepRepr_PropertyDefinition) aPropDef = RD.PropertyDefinition();
844 if (aPropDef.IsNull()) {
846 std::cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepRepr_PropertyDefinition is null for " << S.TShape()->DynamicType()->Name() << std::endl;
850 StepRepr_CharacterizedDefinition CharDef = aPropDef->Definition();
851 Handle(StepBasic_ProductDefinition) PD = CharDef.ProductDefinition();
854 std::cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepBasic_ProductDefinition is null for " << S.TShape()->DynamicType()->Name() << std::endl;
858 EFTool.AddExternRef ( EF->GetName()->ToCString(), PD, format );
860 EFTool.WriteExternRefs(schema);
861 return Standard_True;
865 //=======================================================================
866 //function : FindEntities
868 //=======================================================================
869 static Standard_Integer FindEntities (const Handle(Transfer_FinderProcess) &FP,
870 const TopoDS_Shape &S,
872 TColStd_SequenceOfTransient &seqRI)
874 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, S, L );
876 if ( ! item.IsNull() ) {
877 seqRI.Append ( item );
881 // may be S was splited during shape processing
882 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
883 Handle(Transfer_Binder) bnd = FP->Find ( mapper );
884 if ( bnd.IsNull() ) return 0;
886 Handle(Transfer_TransientListBinder) TransientListBinder =
887 //Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) );
888 Handle(Transfer_TransientListBinder)::DownCast( bnd );
889 Standard_Integer nres=0;
890 if ( TransientListBinder.IsNull() && S.ShapeType() == TopAbs_COMPOUND)
892 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
893 Handle(StepRepr_RepresentationItem) aLocalItem = STEPConstruct::FindEntity ( FP, it.Value(), L );
894 if (aLocalItem.IsNull() ) continue;
896 seqRI.Append (aLocalItem);
899 else if(!TransientListBinder.IsNull())
902 const Standard_Integer nb = TransientListBinder->NbTransients();
903 for (Standard_Integer i=1; i<=nb; i++) {
904 Handle(Standard_Transient) t = TransientListBinder->Transient(i);
905 item = Handle(StepRepr_RepresentationItem)::DownCast(t);
906 if ( item.IsNull() ) continue;
908 seqRI.Append ( item );
911 /* works but is obsolete: another approach
913 TopoDS_Shape comp = TransferBRep::ShapeResult(bnd);
914 if ( ! comp.IsNull() && comp.ShapeType() < S.ShapeType() ) {
915 for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) {
916 MakeSTEPStyles(Styles, it.Value(), settings, STEPstyle,
917 Map, ( hasOwn ? &style : 0 ) );
926 //=======================================================================
927 //function : getStyledItem
929 //=======================================================================
930 static Standard_Boolean getStyledItem(const TopoDS_Shape& S,
931 const Handle(XCAFDoc_ShapeTool)& STool,
932 const STEPConstruct_Styles &Styles,
933 Handle(StepVisual_StyledItem) &resSelItem,
934 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
936 TDF_Label aTopShL = STool->FindShape(S, Standard_False);
937 TopoDS_Shape aTopLevSh = STool->GetShape( aTopShL );
938 Standard_Boolean found = Standard_False;
939 if ( !aTopLevSh.IsNull() && myMapCompMDGPR.IsBound( aTopLevSh ) ) {
940 Handle(StepVisual_PresentationRepresentation) aMDGPR =
941 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopLevSh ) );
942 Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items();
943 // search for PSA of Monifold solid
944 if ( !anSelItmHArr.IsNull() )
946 TColStd_SequenceOfTransient aNewseqRI;
947 Standard_Boolean isFilled = Standard_False;
948 for (Standard_Integer si = 1; si <= anSelItmHArr->Length() && !found; si++) {
949 Handle(StepVisual_StyledItem) aSelItm =
950 Handle(StepVisual_StyledItem)::DownCast(anSelItmHArr->Value(si));
952 if ( aSelItm.IsNull() )
955 // check that it is a stiled item for monifold solid brep
959 FindEntities(Styles.FinderProcess(), aTopLevSh, Loc, aNewseqRI);
960 isFilled = Standard_True;
962 if ( aNewseqRI.Length() > 0 )
965 const Handle(StepRepr_RepresentationItem)& anItem = aSelItm->Item();
966 Standard_Boolean isSameMonSolBR = Standard_False;
967 for (Standard_Integer mi = 1; mi <= aNewseqRI.Length(); mi++) {
968 if ( !anItem.IsNull() && anItem == aNewseqRI.Value( mi ) ) {
969 isSameMonSolBR = Standard_True;
978 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
979 const Handle(StepVisual_PresentationStyleAssignment)& aFatherPSA = aSelItm->StylesValue(jsi);
980 // check for PSA for top-level (not Presentation style by contex for NAUO)
981 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
983 resSelItem = aSelItm;
984 found = Standard_True;
993 //=======================================================================
994 //function : setDefaultInstanceColor
996 //=======================================================================
997 static Standard_Boolean setDefaultInstanceColor (const Handle(StepVisual_StyledItem) &aSelItm,
998 Handle(StepVisual_PresentationStyleAssignment)& PSA)
1000 Standard_Boolean found = Standard_False;
1001 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
1002 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA = aSelItm->StylesValue(jsi);
1003 // check for PSA for top-level (not Presentation style by contex for NAUO)
1004 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
1005 return Standard_False;
1007 // get style select from father PSA
1008 if (aFatherPSA->NbStyles() > 0) {
1009 Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles =
1010 new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles());
1011 for (Standard_Integer k = 1; k <= aFatherPSA->NbStyles(); k++) {
1012 StepVisual_PresentationStyleSelect PSS;
1013 StepVisual_PresentationStyleSelect olDPSS = aFatherPSA->StylesValue(k);
1014 if (!olDPSS.PointStyle().IsNull())
1015 PSS.SetValue (olDPSS.PointStyle());
1016 else if (!olDPSS.CurveStyle().IsNull())
1017 PSS.SetValue (olDPSS.CurveStyle());
1018 else if (!olDPSS.SurfaceStyleUsage().IsNull())
1019 PSS.SetValue (olDPSS.SurfaceStyleUsage());
1021 found = Standard_False;
1024 //aFatherStyles->SetValue( k, PSS );
1025 aFatherStyles->SetValue( k, olDPSS );
1026 found = Standard_True;
1030 PSA->Init( aFatherStyles );
1039 //=======================================================================
1040 //function : MakeSTEPStyles
1041 //purpose : auxilary
1042 //=======================================================================
1043 static void MakeSTEPStyles (STEPConstruct_Styles &Styles,
1044 const TopoDS_Shape &S,
1045 const XCAFPrs_IndexedDataMapOfShapeStyle &settings,
1046 Handle(StepVisual_StyledItem) &override,
1047 TopTools_MapOfShape &Map,
1048 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR,
1049 STEPConstruct_DataMapOfAsciiStringTransient &DPDCs,
1050 STEPConstruct_DataMapOfPointTransient &ColRGBs,
1051 const Handle(XCAFDoc_ColorTool)& CTool,
1052 const XCAFPrs_Style *inherit = 0,
1053 const Standard_Boolean isComponent = Standard_False)
1055 // skip already processed shapes
1056 if ( ! Map.Add ( S ) ) return;
1058 // check if shape has its own style (r inherits from ancestor)
1059 XCAFPrs_Style style;
1060 if ( inherit ) style = *inherit;
1061 if ( settings.Contains(S) ) {
1062 XCAFPrs_Style own = settings.FindFromKey(S);
1063 if ( !own.IsVisible() ) style.SetVisibility ( Standard_False );
1064 if ( own.IsSetColorCurv() ) style.SetColorCurv ( own.GetColorCurv() );
1065 if ( own.IsSetColorSurf() ) style.SetColorSurf ( own.GetColorSurf() );
1068 // translate colors to STEP
1069 Handle(StepVisual_Colour) surfColor, curvColor;
1070 if ( style.IsSetColorSurf() )
1071 surfColor = Styles.EncodeColor(style.GetColorSurf(),DPDCs,ColRGBs);
1072 if ( style.IsSetColorCurv() )
1073 curvColor = Styles.EncodeColor(style.GetColorCurv(),DPDCs,ColRGBs);
1075 Standard_Boolean hasOwn = ( ! surfColor.IsNull() ||
1076 ! curvColor.IsNull() ||
1077 ! style.IsVisible() );
1079 // find target item and assign style to it
1080 Handle(StepVisual_StyledItem) STEPstyle = override;
1082 if ( S.ShapeType() != TopAbs_COMPOUND || isComponent ) { // skip compounds, let subshapes inherit its colors
1084 TColStd_SequenceOfTransient seqRI;
1085 Standard_Integer nb = FindEntities ( Styles.FinderProcess(), S, L, seqRI );
1087 if ( nb <=0 ) std::cout << "Warning: Cannot find RI for " << S.TShape()->DynamicType()->Name() << std::endl;
1089 //Get overridden style gka 10.06.03
1090 if ( isComponent && nb)
1091 getStyledItem(S, CTool->ShapeTool(), Styles, override,myMapCompMDGPR);
1094 for ( Standard_Integer i=1; i <= nb; i++ ) {
1095 Handle(StepRepr_RepresentationItem) item =
1096 Handle(StepRepr_RepresentationItem)::DownCast(seqRI(i));
1097 Handle(StepVisual_PresentationStyleAssignment) PSA;
1098 if ( style.IsVisible() || !surfColor.IsNull() || !curvColor.IsNull() ) {
1099 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1102 // default white color
1103 surfColor = Styles.EncodeColor(Quantity_Color(Quantity_NOC_WHITE),DPDCs,ColRGBs);
1104 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1106 setDefaultInstanceColor( override, PSA);
1108 } // end of component case
1110 STEPstyle = Styles.AddStyle ( item, PSA, override );
1111 hasOwn = Standard_False;
1116 // iterate on subshapes (except vertices :)
1117 if ( S.ShapeType() == TopAbs_EDGE ) return;
1118 if ( !isComponent ) // PTV 10.02.2003
1119 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
1120 MakeSTEPStyles ( Styles, it.Value(), settings, STEPstyle,
1121 Map, myMapCompMDGPR, DPDCs, ColRGBs, CTool,
1122 ( hasOwn ? &style : 0 ) );
1127 static Standard_Boolean getFatherColor (const TDF_Label& L,
1128 const Handle(XCAFDoc_ColorTool)& CTool,
1129 XCAFPrs_Style& style)
1131 Standard_Boolean done = Standard_False;
1132 TopoDS_Shape aSh = CTool->ShapeTool()->GetShape( L );
1133 TDF_Label aFL = CTool->ShapeTool()->FindShape( aSh );
1134 if (aFL.IsNull() || aFL == L)
1137 if ( CTool->GetColor ( aFL, XCAFDoc_ColorGen, C ) ) {
1138 style.SetColorCurv ( C );
1139 style.SetColorSurf ( C );
1140 done = Standard_True;
1142 if ( CTool->GetColor ( aFL, XCAFDoc_ColorSurf, C ) ) {
1143 style.SetColorSurf ( C );
1144 done = Standard_True;
1146 if ( CTool->GetColor ( aFL, XCAFDoc_ColorCurv, C ) ) {
1147 style.SetColorCurv ( C );
1148 done = Standard_True;
1156 //=======================================================================
1157 //function : WriteColors
1159 //=======================================================================
1161 Standard_Boolean STEPCAFControl_Writer::WriteColors (const Handle(XSControl_WorkSession) &WS,
1162 const TDF_LabelSequence &labels)
1164 if ( labels.Length() <=0 ) return Standard_False;
1166 // Iterate on shapes in the document
1167 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1168 Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool( labels(1) );
1169 if ( CTool.IsNull() ) return Standard_False;
1171 STEPConstruct_Styles Styles ( WS );
1172 STEPConstruct_DataMapOfAsciiStringTransient DPDCs;
1173 STEPConstruct_DataMapOfPointTransient ColRGBs;
1174 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1175 TDF_Label L = labels.Value(i);
1177 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1178 // Skip assemblies: colors assigned to assemblies and their instances
1179 // are not supported (it is not clear how to encode that in STEP)
1180 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1182 std::cout << "Warning: Cannot write color for Assembly" << std::endl;
1183 std::cout << "Info: Check for colors assigned to components in assembly" << std::endl;
1185 // PTV 22.01.2003 Write color for instances.
1186 TDF_LabelSequence compLabels;
1187 if ( aSTool.IsNull() )
1189 if (!aSTool->GetComponents(L, compLabels))
1191 WriteColors(WS, compLabels);
1194 Styles.ClearStyles();
1196 // get a target shape and try to find corresponding context
1197 // (all the colors set under that label will be put into that context)
1199 if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1200 Standard_Boolean isComponent = aSTool->IsComponent( L );
1201 TopoDS_Shape aTopSh = S;
1202 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext ( S );
1203 if ( isComponent ) {
1204 TDF_Label aTopShL = aSTool->FindShape(S, Standard_False);
1205 if (aTopShL.IsNull())
1207 aTopSh = aSTool->GetShape( aTopShL );
1208 Context = Styles.FindContext ( aTopSh );
1210 if ( Context.IsNull() )
1213 // collect settings set on that label
1214 XCAFPrs_IndexedDataMapOfShapeStyle settings;
1215 TDF_LabelSequence seq;
1217 XCAFDoc_ShapeTool::GetSubShapes ( L, seq );
1218 Standard_Boolean isVisible = Standard_True;
1219 for ( Standard_Integer j = 1; j <= seq.Length(); j++ ) {
1220 TDF_Label lab = seq.Value(j);
1221 XCAFPrs_Style style;
1224 // check for invisible status of object on label
1225 if ( !CTool->IsVisible( lab ) ) {
1226 isVisible = Standard_False;
1227 style.SetVisibility( Standard_False );
1230 if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) {
1231 style.SetColorCurv ( C );
1232 style.SetColorSurf ( C );
1234 if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) )
1235 style.SetColorSurf ( C );
1236 if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) )
1237 style.SetColorCurv ( C );
1238 if (!style.IsSetColorSurf())
1240 Handle(XCAFDoc_VisMaterial) aVisMat = aMatTool->GetShapeMaterial (lab);
1241 if (!aVisMat.IsNull()
1242 && !aVisMat->IsEmpty())
1244 // only color can be stored in STEP
1245 style.SetColorSurf (aVisMat->BaseColor());
1249 // commented, cause we are need to take reference from
1250 // if ( isComponent && lab == L && !isVisible)
1251 // if ( !style.IsSetColorSurf() && !style.IsSetColorCurv() ) {
1252 // getFatherColor ( L, CTool, style);
1254 if ( ! style.IsSetColorCurv() && ! style.IsSetColorSurf() && isVisible ) continue;
1256 TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab );
1257 XCAFPrs_Style* aMapStyle = settings.ChangeSeek (sub);
1258 if (aMapStyle == NULL)
1259 settings.Add ( sub, style );
1264 if ( settings.Extent() <=0 ) continue;
1266 // iterate on subshapes and create STEP styles
1267 Handle(StepVisual_StyledItem) override;
1268 TopTools_MapOfShape Map;
1270 MakeSTEPStyles(Styles,S,settings,override,Map,myMapCompMDGPR,DPDCs,ColRGBs,CTool,0,isComponent);
1272 // create MDGPR and record it in model
1273 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1276 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1278 std::cerr << "Error: Current Top-Level shape have MDGPR already " << std::endl;
1281 Styles.CreateMDGPR ( Context, aMDGPR );
1282 if (!aMDGPR.IsNull())
1283 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1286 // create SDR and add to model.
1287 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1288 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1289 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1290 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1291 if ( FP->FindTypedTransient(mapper,
1292 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1294 // create SDR for NAUO
1295 Handle(StepRepr_ProductDefinitionShape) nullPDS; // important to be NULL
1296 Styles.CreateNAUOSRD( Context, CDSR, nullPDS );
1298 // search for MDGPR of the component top-level shape
1299 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1300 aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1302 aMDGPR = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
1303 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
1304 aMDGPR->SetName( ReprName );
1305 aMDGPR->SetContextOfItems( Context );
1306 myMapCompMDGPR.Bind ( aTopSh, aMDGPR );
1308 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1309 Standard_Integer oldLengthlen = 0;
1310 if (!oldItems.IsNull())
1311 oldLengthlen = oldItems->Length();
1312 const Standard_Integer nbIt = oldLengthlen + Styles.NbStyles();
1315 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1316 new StepRepr_HArray1OfRepresentationItem(1, nbIt);
1317 Standard_Integer si;
1318 Standard_Integer el = 1;
1319 for ( si=1; si <= oldLengthlen; si++ )
1320 newItems->SetValue( el++, oldItems->Value( si ) );
1321 for ( si=1; si <= Styles.NbStyles(); si++ ) {
1322 newItems->SetValue( el++, Styles.Style(si));
1325 if (newItems->Length() > 0)
1326 aMDGPR->SetItems( newItems );
1327 } //end of work with CDSR
1330 // create invisibility item and refer for stiledItem
1331 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1332 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1333 new StepVisual_HArray1OfInvisibleItem (1,Styles.NbStyles());
1334 // put all style item into the harray
1335 for ( Standard_Integer si=1; si <= Styles.NbStyles(); si++ ) {
1336 Handle(StepRepr_RepresentationItem) styledItm = Styles.Style(si);
1337 StepVisual_InvisibleItem anInvItem;
1338 anInvItem.SetValue( styledItm );
1339 HInvsblItm->SetValue( si, anInvItem );
1341 // set the invisibility of items
1342 Invsblt->Init( HInvsblItm );
1343 WS->Model()->AddWithRefs( Invsblt );
1347 return Standard_True;
1351 //=======================================================================
1352 //function : WriteNames
1354 //=======================================================================
1356 Standard_Boolean STEPCAFControl_Writer::WriteNames (const Handle(XSControl_WorkSession) &WS,
1357 const TDF_LabelSequence &labels) const
1359 if ( labels.Length() <=0 ) return Standard_False;
1362 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1363 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1365 // Iterate on requested shapes
1366 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1367 TDF_Label L = labels.Value(i);
1370 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1371 if ( ! GetLabelName (L, hName) ) continue;
1372 // Handle(TDataStd_Name) N;
1373 // if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) continue;
1374 // TCollection_ExtendedString name = N->Get();
1375 // if ( name.Length() <=0 ) continue;
1377 // find target STEP entity for the current shape
1379 // if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1380 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1381 TopoDS_Shape S = myLabels.Find ( L );
1383 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
1384 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1385 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
1387 std::cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << std::endl;
1392 // set the name to the PRODUCT
1393 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
1394 if ( PropD.IsNull() ) continue;
1395 Handle(StepBasic_ProductDefinition) PD = PropD->Definition().ProductDefinition();
1396 if ( PD.IsNull() ) continue;
1397 Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
1399 Prod->SetId ( hName );
1400 Prod->SetName ( hName );
1402 // write names for components of assemblies
1403 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1404 TDF_LabelSequence seq;
1405 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1406 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1407 TDF_Label lab = seq(k);
1409 // get shape with correct location
1411 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1412 ! myLabels.IsBound ( Lref ) ) continue;
1413 S = myLabels.Find ( Lref );
1414 S.Move ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
1416 hName = new TCollection_HAsciiString;
1417 if ( ! GetLabelName (lab, hName) ) continue;
1419 // find the target CDSR corresponding to a shape
1420 mapper = TransferBRep::ShapeMapper ( FP, S );
1421 Handle(Transfer_Binder) binder = FP->Find ( mapper );
1422 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1423 if ( ! FP->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), CDSR) )
1425 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1426 Handle(StepBasic_ProductDefinitionRelationship) NAUO = PDS->Definition().ProductDefinitionRelationship();
1427 if ( ! NAUO.IsNull() ) NAUO->SetName ( hName );
1432 return Standard_True;
1436 //=======================================================================
1437 //function : WritePropsForLabel
1439 //=======================================================================
1440 static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession) &WS,
1441 const Handle(XCAFDoc_ShapeTool) &aSTool,
1442 const STEPCAFControl_DataMapOfLabelShape &myLabels,
1444 const Standard_CString multi)
1446 if(L.IsNull()) return Standard_False;
1448 STEPConstruct_ValidationProps Props ( WS );
1450 TopoDS_Shape S = aSTool->GetShape(L);
1451 if(S.IsNull()) return Standard_False;
1453 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1455 Handle(XCAFDoc_Area) A;
1456 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1457 if ( ! A.IsNull() ) {
1458 Props.AddArea ( S, A->Get() );
1461 Handle(XCAFDoc_Volume) V;
1462 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1463 if ( ! V.IsNull() ) {
1464 Props.AddVolume ( S, V->Get() );
1468 Handle(XCAFDoc_Centroid) C;
1469 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1470 if ( ! C.IsNull() ) {
1471 Props.AddCentroid ( S, C->Get() );
1474 if( XCAFDoc_ShapeTool::IsCompound(L) || XCAFDoc_ShapeTool::IsAssembly(L) ) {
1476 for(Standard_Integer ich=1; ich<=L.NbChildren(); ich++) {
1477 WritePropsForLabel(WS,aSTool,myLabels,L.FindChild(ich),multi);
1482 return Standard_True;
1486 //=======================================================================
1487 //function : WriteValProps
1489 //=======================================================================
1491 Standard_Boolean STEPCAFControl_Writer::WriteValProps (const Handle(XSControl_WorkSession) &WS,
1492 const TDF_LabelSequence &labels,
1493 const Standard_CString multi) const
1495 if ( labels.Length() <=0 ) return Standard_False;
1498 // STEPConstruct_ValidationProps Props ( WS );
1499 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1501 // Iterate on requested shapes
1502 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1503 TDF_Label L = labels.Value(i);
1505 WritePropsForLabel(WS,aSTool,myLabels,L,multi);
1507 // find target STEP entity for the current shape
1508 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1509 TopoDS_Shape S = myLabels.Find ( L );
1511 // write area and volume (except for components in multifile mode)
1512 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1513 Handle(XCAFDoc_Area) A;
1514 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1515 if ( ! A.IsNull() ) Props.AddArea ( S, A->Get() );
1517 Handle(XCAFDoc_Volume) V;
1518 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1519 if ( ! V.IsNull() ) Props.AddVolume ( S, V->Get() );
1523 Handle(XCAFDoc_Centroid) C;
1524 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1525 if ( ! C.IsNull() ) Props.AddCentroid ( S, C->Get() );
1527 // write centroid for components of assemblies
1528 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1529 TDF_LabelSequence seq;
1530 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1531 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1532 TDF_Label lab = seq(k);
1534 // get shape with correct location
1536 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1537 ! myLabels.IsBound ( Lref ) ) continue;
1538 TopLoc_Location Loc = XCAFDoc_ShapeTool::GetLocation ( lab );
1539 S = myLabels.Find ( Lref );
1543 lab.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1544 // if centroid is not assigned to an instance,
1545 // use (shifted) centroid of original shape
1548 Lref.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1549 if ( C.IsNull() ) continue;
1550 center = C->Get().Transformed ( Loc.Transformation() );
1552 else center = C->Get();
1554 Props.AddCentroid ( S, center, Standard_True );
1560 return Standard_True;
1564 //=======================================================================
1565 //function : WriteLayers
1567 //=======================================================================
1569 Standard_Boolean STEPCAFControl_Writer::WriteLayers (const Handle(XSControl_WorkSession) &WS,
1570 const TDF_LabelSequence &labels ) const
1573 if ( labels.Length() <=0 ) return Standard_False;
1576 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1577 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1578 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1579 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( labels(1) );
1580 if (LTool.IsNull() ) return Standard_False;
1582 TDF_LabelSequence LayerLS;
1583 LTool->GetLayerLabels(LayerLS);
1584 if ( LayerLS.Length() <=0 ) return Standard_False;
1586 // Iterate on requested layers and for each layer take set of shapes.
1587 for ( Standard_Integer i=1; i <= LayerLS.Length(); i++ ) {
1588 TDF_Label L = LayerLS.Value(i);
1590 // get labels of shapes in that layer
1591 TDF_LabelSequence ShapeLs;
1592 LTool->GetShapesOfLayer(L, ShapeLs);
1593 if ( ShapeLs.Length() <=0 ) continue;
1595 // name of layer: if not set, is considered as being empty
1596 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1597 GetLabelName ( L, hName );
1599 // Find target STEP entity for each shape and add to StepVisual_PresentationLayerAssignment items.
1600 TColStd_SequenceOfTransient seqRI;
1601 for ( Standard_Integer j=1; j <= ShapeLs.Length(); j++) {
1602 TDF_Label shLabel = ShapeLs.Value(j);
1603 if ( shLabel.IsNull() ) continue;
1605 // there is no way to assign layer to instance in STEP
1606 if ( XCAFDoc_ShapeTool::IsAssembly ( shLabel ) ||
1607 XCAFDoc_ShapeTool::IsReference ( shLabel ) )
1610 // check that the shape is one of (uub)labels written during current transfer
1611 Standard_Integer k = 1;
1612 for ( ; k <= labels.Length(); k++ )
1613 if ( shLabel.IsDescendant ( labels(k) ) ) break;
1614 if ( k > labels.Length() ) continue;
1616 // get target STEP entity
1617 TopoDS_Shape oneShape = XCAFDoc_ShapeTool::GetShape(shLabel);
1619 TopLoc_Location Loc;
1620 Standard_Integer nb =
1621 FindEntities ( FP, oneShape, Loc, seqRI );
1623 FP->Messenger()->SendInfo() << "Warning: Cannot find RI for " << oneShape.TShape()->DynamicType()->Name() << std::endl;
1625 if ( seqRI.Length() <= 0 ) continue;
1627 // analyze visibility
1628 Handle(StepVisual_PresentationLayerAssignment) StepLayerAs = new StepVisual_PresentationLayerAssignment;
1629 Handle(TCollection_HAsciiString) descr;
1630 Handle(TDataStd_UAttribute) aUAttr;
1631 Standard_Boolean isLinv = Standard_False;
1632 if (L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr)) {
1633 descr = new TCollection_HAsciiString ("invisible");
1635 std::cout << "\tLayer \"" << hName->String().ToCString() << "\" is invisible"<<std::endl;
1637 isLinv = Standard_True;
1639 else descr = new TCollection_HAsciiString ("visible");
1641 // create layer entity
1642 Handle(StepVisual_HArray1OfLayeredItem) HArrayOfLItem =
1643 new StepVisual_HArray1OfLayeredItem ( 1, seqRI.Length() );
1644 for (Standard_Integer i1 = 1; i1<=seqRI.Length(); i1++) {
1645 StepVisual_LayeredItem LI;
1646 LI.SetValue ( seqRI.Value(i1) );
1647 HArrayOfLItem->SetValue( i1, LI );
1649 StepLayerAs->Init(hName, descr, HArrayOfLItem);
1650 Model->AddWithRefs( StepLayerAs );
1651 // PTV 23.01.2003 add the invisibility AFTER adding layer into the model.
1652 // add the invisibility for the layer
1654 // Invisibility Item for containig invisible layers.
1655 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm = new StepVisual_HArray1OfInvisibleItem (1,1);
1656 StepVisual_InvisibleItem InvIt;
1657 InvIt.SetValue( StepLayerAs );
1658 HInvsblItm->SetValue( 1, InvIt);
1660 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1661 Invsblt->Init( HInvsblItm );
1662 Model->AddWithRefs( Invsblt );
1665 return Standard_True;
1669 //=======================================================================
1670 //function : getSHUOstyle
1671 //purpose : auxilary
1672 //=======================================================================
1673 static Standard_Boolean getSHUOstyle(const TDF_Label& aSHUOlab,
1674 const Handle(XCAFDoc_ColorTool)& CTool,
1675 const Handle(XCAFDoc_VisMaterialTool)& theMatTool,
1676 XCAFPrs_Style& SHUOstyle)
1679 if (!CTool->IsVisible( aSHUOlab ) )
1680 SHUOstyle.SetVisibility(Standard_False);
1682 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) {
1683 SHUOstyle.SetColorCurv ( C );
1684 SHUOstyle.SetColorSurf ( C );
1686 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) )
1687 SHUOstyle.SetColorSurf ( C );
1688 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) )
1689 SHUOstyle.SetColorCurv ( C );
1690 if (!SHUOstyle.IsSetColorSurf())
1692 Handle(XCAFDoc_VisMaterial) aVisMat = theMatTool->GetShapeMaterial (aSHUOlab);
1693 if (!aVisMat.IsNull()
1694 && !aVisMat->IsEmpty())
1696 // only color can be stored in STEP
1697 SHUOstyle.SetColorSurf (aVisMat->BaseColor());
1701 if ( !SHUOstyle.IsSetColorCurv() &&
1702 !SHUOstyle.IsSetColorSurf() &&
1703 SHUOstyle.IsVisible() )
1704 return Standard_False;
1705 return Standard_True;
1709 //=======================================================================
1710 //function : getProDefinitionOfNAUO
1711 //purpose : auxilary
1712 //=======================================================================
1713 static Standard_Boolean getProDefinitionOfNAUO(const Handle(XSControl_WorkSession)& WS,
1714 const TopoDS_Shape& theShape,
1715 Handle(StepBasic_ProductDefinition)& PD,
1716 Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO,
1717 Standard_Boolean IsRelating)
1719 if ( theShape.IsNull() )
1720 return Standard_False;
1722 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1723 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1724 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1725 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, theShape );
1726 if (!FP->FindTypedTransient(mapper,
1727 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1729 return Standard_False;
1731 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1733 return Standard_False;
1734 // get the NAUO entity
1735 Interface_Graph aGraph = WS->HGraph()->Graph();
1736 Interface_EntityIterator subs = aGraph.Shareds(PDS);
1737 for ( subs.Start(); subs.More(); subs.Next() ) {
1738 if (!subs.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)))
1740 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value());
1743 if ( NAUO.IsNull() )
1744 return Standard_False;
1745 // get Relatinf or Related product definition
1747 PD = NAUO->RelatedProductDefinition();
1749 PD = NAUO->RelatingProductDefinition();
1751 return Standard_False;
1752 return Standard_True;
1756 //=======================================================================
1757 //function : writeSHUO
1758 //purpose : auxilary
1759 //=======================================================================
1760 static Standard_Boolean writeSHUO (const Handle(XCAFDoc_GraphNode)& theSHUO,
1761 const Handle(XCAFDoc_ShapeTool)& theSTool,
1762 const Handle(XSControl_WorkSession)& WS,
1763 Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO,
1764 TopoDS_Shape& NAUOShape,
1765 Handle(StepBasic_ProductDefinition)& theRelatingPD,
1766 Standard_Boolean& isDeepest)
1768 // set the ProductDefinitionRelationship descriptin information as empty strings.
1769 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
1771 TDF_LabelSequence aNextUsageLabs;
1772 theSTool->GetSHUONextUsage( theSHUO->Label(), aNextUsageLabs );
1773 Handle(XCAFDoc_GraphNode) NuSHUO;
1774 if ( theTopSHUO.IsNull() ) {
1776 if (aNextUsageLabs.Length() < 1)
1777 return Standard_False;
1778 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1779 if (NuSHUO.IsNull())
1780 return Standard_False;
1781 // get relating product definition
1782 TopoDS_Shape aTopCompShape = theSTool->GetShape( theSHUO->Label().Father() );
1783 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO;
1784 if (!getProDefinitionOfNAUO( WS, aTopCompShape,
1785 theRelatingPD, UUNAUO, Standard_True ))
1786 return Standard_False;
1787 // get related product definition
1788 TopoDS_Shape aNUShape = theSTool->GetShape( NuSHUO->Label().Father() );
1789 Handle(StepBasic_ProductDefinition) aRelatedPD;
1790 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO;
1791 if (!getProDefinitionOfNAUO( WS, aNUShape,
1792 aRelatedPD, NUNAUO, Standard_False ))
1793 return Standard_False;
1795 theTopSHUO = new StepRepr_SpecifiedHigherUsageOccurrence;
1796 // create deepest shuo EmptyString
1797 theTopSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1798 /*no description*/Standard_False,/*description*/EmptyString,
1799 theRelatingPD, aRelatedPD,
1800 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1801 /*upper_usage*/UUNAUO, /*next_usage*/NUNAUO);
1802 // write the other SHUO.
1803 if(!writeSHUO( NuSHUO, theSTool, WS, theTopSHUO, NAUOShape, theRelatingPD, isDeepest )) {
1804 theTopSHUO.Nullify();
1805 return Standard_False;
1808 return Standard_True;
1810 // Handle(XCAFDoc_GraphNode) NuSHUO;
1811 if ( aNextUsageLabs.Length() > 0) {
1812 // store SHUO recursive
1814 if ( aNextUsageLabs.Length() > 1 )
1815 std::cout << "Warning: store only one next_usage of current SHUO" << std::endl;
1817 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1818 Handle(StepRepr_SpecifiedHigherUsageOccurrence) aNUEntSHUO =
1819 new StepRepr_SpecifiedHigherUsageOccurrence;
1820 if (!writeSHUO( NuSHUO, theSTool, WS, aNUEntSHUO, NAUOShape, theRelatingPD, isDeepest ))
1821 return Standard_False;
1823 // store the deepest SHUO to the dociment
1824 TopoDS_Shape aNUSh, aUUSh;
1825 aNUSh = theSTool->GetShape( NuSHUO->Label().Father() );
1826 aUUSh = theSTool->GetShape( theSHUO->Label().Father() );
1827 // get relating PD with upper_usage and related PD with next_usage
1828 Handle(StepBasic_ProductDefinition) nullPD;// no need to use,case have shared <theRelatingPD>
1829 Handle(StepBasic_ProductDefinition) aRelatedPD;
1830 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO, NUNAUO;
1831 if (!getProDefinitionOfNAUO( WS, aUUSh, nullPD, UUNAUO, Standard_True ) ||
1832 !getProDefinitionOfNAUO( WS, aNUSh, aRelatedPD, NUNAUO, Standard_False )) {
1834 std::cout << "Warning: cannot get related or relating PD" << std::endl;
1836 return Standard_False;
1838 aNUEntSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1839 /*no description*/Standard_False,/*description*/EmptyString,
1840 theRelatingPD, aRelatedPD,
1841 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1842 /*upper_usage*/theTopSHUO, /*next_usage*/NUNAUO);
1844 isDeepest = Standard_False;
1846 WS->Model()->AddWithRefs ( aNUEntSHUO );
1847 return Standard_True;
1848 } // end of recurse storing
1851 TDF_Label aShapeL = theSHUO->Label().Father();
1852 NAUOShape = theSTool->GetShape( aShapeL );
1853 // return to the deepest level from SHUO shape level
1854 // it is because SHUO is attribute on deep level and shape level.
1855 isDeepest = Standard_True;
1856 return Standard_True;
1860 //=======================================================================
1861 //function : createSHUOStyledItem
1862 //purpose : auxilary
1863 //=======================================================================
1864 static Standard_Boolean createSHUOStyledItem (const XCAFPrs_Style& style,
1865 const Handle(StepRepr_ProductDefinitionShape)& PDS,
1866 const Handle(XSControl_WorkSession) &WS,
1867 const TopoDS_Shape& Sh,
1868 const Handle(XCAFDoc_ShapeTool)& STool,
1869 MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
1871 // create styled item for the indicated SHUO and store to the model
1872 STEPConstruct_Styles Styles( WS );
1873 // translate colors to STEP
1874 Handle(StepVisual_Colour) surfColor, curvColor;
1875 if ( style.IsSetColorSurf() )
1876 surfColor = Styles.EncodeColor ( style.GetColorSurf() );
1877 if ( style.IsSetColorCurv() )
1878 curvColor = Styles.EncodeColor ( style.GetColorCurv() );
1879 Standard_Boolean isComponent = Standard_True;// cause need to get PSBC
1880 Handle(StepRepr_RepresentationItem) item;
1881 // set default color for invisible SHUO.
1882 Standard_Boolean isSetDefaultColor = Standard_False;
1883 if (surfColor.IsNull() && curvColor.IsNull() && !style.IsVisible() ) {
1884 surfColor = Styles.EncodeColor ( Quantity_Color(Quantity_NOC_WHITE) );
1885 isSetDefaultColor = Standard_True;
1887 Handle(StepVisual_PresentationStyleAssignment) PSA =
1888 Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1889 Handle(StepVisual_StyledItem) override; //null styled item
1891 // find the repr item of the shape
1892 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1893 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1894 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, Sh );
1895 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1896 FP->FindTypedTransient(mapper,
1897 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1899 if ( CDSR.IsNull() )
1900 return Standard_False;
1902 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext( Sh );
1903 TopoDS_Shape aTopSh = Sh;
1904 if (Context.IsNull()) {
1905 TDF_Label aTopShL = STool->FindShape(Sh, Standard_False);
1906 if (aTopShL.IsNull())
1907 return Standard_False;
1908 aTopSh = STool->GetShape( aTopShL );
1909 Context = Styles.FindContext ( aTopSh );
1911 if (Context.IsNull())
1912 return Standard_False;
1913 // get representation item of the shape
1915 TColStd_SequenceOfTransient seqRI;
1916 FindEntities ( FP, Sh, L, seqRI );
1918 if ( seqRI.Length() <=0 )
1919 std::cout << "Warning: Cannot find RI for " << Sh.TShape()->DynamicType()->Name() << std::endl;
1921 item = Handle(StepRepr_RepresentationItem)::DownCast(seqRI(1));
1922 //get overridden styled item
1923 getStyledItem(Sh,STool, Styles, override,myMapCompMDGPR);
1925 // get STEP STYLED ITEM
1926 Handle(StepVisual_StyledItem) STEPstyle = Styles.AddStyle ( item, PSA, override );
1927 // create SR, SDR and all necessary references between them and ST, PDS, PSBC, GRC
1928 Styles.CreateNAUOSRD( Context, CDSR, PDS );
1930 // add step styled item of SHUO to the model
1931 // do it by additing styled item to the MDGPR
1932 if ( !aTopSh.IsNull() && !myMapCompMDGPR.IsBound( aTopSh ) ) {
1933 // create MDGPR and record it in model
1935 std::cout << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance" << std::endl;
1937 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1938 Styles.CreateMDGPR ( Context, aMDGPR );
1939 if (!aMDGPR.IsNull())
1940 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1942 else if ( !aTopSh.IsNull() && myMapCompMDGPR.IsBound( aTopSh ) ) {
1943 // get MDGPR of the top-level shape
1944 Handle(StepVisual_PresentationRepresentation) aMDGPR =
1945 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1946 // get old styled items to not lose it
1947 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1948 Standard_Integer oldLengthlen = 0;
1949 if (!oldItems.IsNull())
1950 oldLengthlen = oldItems->Length();
1951 // create new array of styled items by an olds and new one
1952 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1953 new StepRepr_HArray1OfRepresentationItem(1, oldLengthlen + 1);
1954 Standard_Integer si;
1955 Standard_Integer el = 1;
1956 for ( si=1; si <= oldLengthlen; si++ )
1957 newItems->SetValue( el++, oldItems->Value( si ) );
1958 newItems->SetValue (el++, STEPstyle);
1959 // init MDGPR be new array of styled items
1960 if (newItems->Length() > 0)
1961 aMDGPR->SetItems( newItems );
1964 WS->Model()->AddWithRefs ( STEPstyle ); // add as root to the model, but it is not good
1966 std::cout << "Warning: " << __FILE__ << ": adds styled item of SHUO as root, casue cannot find MDGPR" << std::endl;
1969 // create invisibility item for the styled item
1970 if ( !style.IsVisible() ) {
1971 if (isSetDefaultColor) {
1972 // try to set default color from top-level shape
1974 setDefaultInstanceColor(override, PSA);
1976 // create invisibility item and refer for stiledItem
1977 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1978 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1979 new StepVisual_HArray1OfInvisibleItem (1,1);
1980 // put all style item into the harray
1981 StepVisual_InvisibleItem anInvItem;
1982 anInvItem.SetValue( STEPstyle );
1983 HInvsblItm->SetValue( 1, anInvItem );
1984 Invsblt->Init( HInvsblItm );
1985 WS->Model()->AddWithRefs( Invsblt );
1988 return Standard_True;
1992 //=======================================================================
1993 //function : WriteSHUOs
1995 //=======================================================================
1997 Standard_Boolean STEPCAFControl_Writer::WriteSHUOs (const Handle(XSControl_WorkSession) &WS,
1998 const TDF_LabelSequence &labels )
2000 if ( labels.Length() <=0 ) return Standard_False;
2003 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
2004 Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool( labels(1) );
2005 if (CTool.IsNull() )
2006 return Standard_False;
2007 // map of transfered SHUO
2008 TColStd_MapOfTransient aMapOfMainSHUO;
2009 // Iterate on requested shapes
2010 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
2011 TDF_Label L = labels.Value(i);
2012 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
2013 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
2014 TDF_LabelSequence seq;
2015 XCAFDoc_ShapeTool::GetComponents ( L, seq );
2016 // iterates on components of assembly
2017 for (Standard_Integer k=1; k <= seq.Length(); k++) {
2018 TDF_Label lab = seq(k);
2019 TDF_AttributeSequence anAttrSeq;
2020 CTool->ShapeTool()->GetAllComponentSHUO( lab, anAttrSeq );
2022 for (Standard_Integer j = 1; j <= anAttrSeq.Length(); j++) {
2023 Handle(XCAFDoc_GraphNode) aSHUO =
2024 Handle(XCAFDoc_GraphNode)::DownCast(anAttrSeq.Value( j ));
2025 // take label of SHUO
2026 TDF_Label aSHUOlab = aSHUO->Label();
2027 TDF_LabelSequence aUpLabels;
2028 // check is it SHUO of upper_usage
2029 CTool->ShapeTool()->GetSHUOUpperUsage( aSHUOlab, aUpLabels );
2030 if ( aUpLabels.Length() > 0 )
2031 continue; // transfer only main SHUO
2032 if ( aMapOfMainSHUO.Contains( aSHUO ) )
2033 continue; // do not try to transfer SHUO twice
2034 aMapOfMainSHUO.Add( aSHUO );
2035 // check if it is styled SHUO
2036 XCAFPrs_Style SHUOstyle;
2037 if ( !getSHUOstyle ( aSHUOlab, CTool, aMatTool, SHUOstyle ) ) {
2039 std::cout << "Warning: " << __FILE__ << ": do not store SHUO without any style to the STEP model" << std::endl;
2043 // write SHUO to the model amd then add structure type.
2044 TopoDS_Shape NAUOShape; // shape of the deepest NAUO in the SHUO structure
2045 Standard_Boolean isDeepest = Standard_False;
2046 Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO;
2047 Handle(StepBasic_ProductDefinition) aRelatingPD;
2048 // create the top SHUO and all other.
2049 writeSHUO( aSHUO, CTool->ShapeTool(), WS, anEntOfSHUO, NAUOShape, aRelatingPD, isDeepest );
2050 if ( anEntOfSHUO.IsNull() || NAUOShape.IsNull() ) {
2052 std::cout << "Warning: " << __FILE__ << ": Cannot store SHUO" << std::endl;
2056 // create new Product Definition Shape for TOP SHUO
2058 std::cout << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO " << std::endl;
2060 Handle(StepRepr_ProductDefinitionShape) PDS = new StepRepr_ProductDefinitionShape;
2061 Handle(TCollection_HAsciiString) aPDSname = new TCollection_HAsciiString("SHUO");
2062 Handle(TCollection_HAsciiString) descrStr = new TCollection_HAsciiString("");
2063 StepRepr_CharacterizedDefinition aCharDef;
2064 aCharDef.SetValue( anEntOfSHUO );
2065 PDS->Init( aPDSname, Standard_False, descrStr, aCharDef );
2067 // create styled item for SHUO and add to the model
2068 createSHUOStyledItem ( SHUOstyle, PDS, WS, NAUOShape, CTool->ShapeTool(), myMapCompMDGPR );
2070 } // end work with SHUO
2071 } // end of an assembly components
2072 } // end of IsAssembly case
2073 // nothing to do if it is not assembly
2075 } // end of iterates on indicated labels
2076 return Standard_True;
2080 //=======================================================================
2081 //function : FindPDSforDGT
2082 //purpose : auxilary: find PDS for AdvancedFace or EdgeCurve for creation
2083 // needed ShapeAspect in D> structure
2084 //=======================================================================
2085 static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph,
2086 const Handle(Standard_Transient) &ent,
2087 Handle(StepRepr_ProductDefinitionShape) &PDS,
2088 Handle(StepRepr_RepresentationContext) &RC,
2089 Handle(StepShape_AdvancedFace) &AF,
2090 Handle(StepShape_EdgeCurve) &EC)
2093 return Standard_False;
2094 if( !ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) &&
2095 !ent->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)) )
2096 return Standard_False;
2098 AF = Handle(StepShape_AdvancedFace)::DownCast(ent);
2100 EC = Handle(StepShape_EdgeCurve)::DownCast(ent);
2101 Interface_EntityIterator subs = aGraph.Sharings(EC);
2102 for(subs.Start(); subs.More() && AF.IsNull(); subs.Next()) {
2103 Handle(StepShape_OrientedEdge) OE = Handle(StepShape_OrientedEdge)::DownCast(subs.Value());
2104 if(OE.IsNull()) continue;
2105 Interface_EntityIterator subs1 = aGraph.Sharings(OE);
2106 for(subs1.Start(); subs1.More() && AF.IsNull(); subs1.Next()) {
2107 Handle(StepShape_EdgeLoop) EL = Handle(StepShape_EdgeLoop)::DownCast(subs1.Value());
2108 if(EL.IsNull()) continue;
2109 Interface_EntityIterator subs2 = aGraph.Sharings(EL);
2110 for(subs2.Start(); subs2.More() && AF.IsNull(); subs2.Next()) {
2111 Handle(StepShape_FaceBound) FB = Handle(StepShape_FaceBound)::DownCast(subs2.Value());
2112 if(FB.IsNull()) continue;
2113 Interface_EntityIterator subs3 = aGraph.Sharings(FB);
2114 for(subs3.Start(); subs3.More() && AF.IsNull(); subs3.Next()) {
2115 AF = Handle(StepShape_AdvancedFace)::DownCast(subs3.Value());
2121 if(AF.IsNull()) return Standard_False;
2123 Interface_EntityIterator subs = aGraph.Sharings(AF);
2124 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
2125 Handle(StepShape_ConnectedFaceSet) CFS =
2126 Handle(StepShape_ConnectedFaceSet)::DownCast(subs.Value());
2127 if(CFS.IsNull()) continue;
2128 Interface_EntityIterator subs1 = aGraph.Sharings(CFS);
2129 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
2130 Handle(StepRepr_RepresentationItem) RI =
2131 Handle(StepRepr_RepresentationItem)::DownCast(subs1.Value());
2132 if(RI.IsNull()) continue;
2133 Interface_EntityIterator subs2 = aGraph.Sharings(RI);
2134 for(subs2.Start(); subs2.More() && PDS.IsNull(); subs2.Next()) {
2135 Handle(StepShape_ShapeRepresentation) SR =
2136 Handle(StepShape_ShapeRepresentation)::DownCast(subs2.Value());
2137 if(SR.IsNull()) continue;
2138 RC = SR->ContextOfItems();
2139 Interface_EntityIterator subs3 = aGraph.Sharings(SR);
2140 for(subs3.Start(); subs3.More() && PDS.IsNull(); subs3.Next()) {
2141 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2142 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs3.Value());
2143 if(SDR.IsNull()) continue;
2144 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
2145 if(PropD.IsNull()) continue;
2146 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
2152 return Standard_True;
2155 //=======================================================================
2156 //function : FindPDS
2157 //purpose : auxilary: find Product_definition_shape entity for given entity
2158 //=======================================================================
2159 static Handle(StepRepr_ProductDefinitionShape) FindPDS(const Interface_Graph &theGraph,
2160 const Handle(Standard_Transient) &theEnt,
2161 Handle(StepRepr_RepresentationContext) &theRC)
2163 if (theEnt.IsNull())
2165 Handle(StepRepr_ProductDefinitionShape) aPDS;
2167 // try to find shape_representation in sharings
2168 Interface_EntityIterator anIter = theGraph.Sharings(theEnt);
2169 for (anIter.Start(); anIter.More() && aPDS.IsNull(); anIter.Next()) {
2170 Handle(StepShape_ShapeRepresentation) aSR = Handle(StepShape_ShapeRepresentation)::DownCast(anIter.Value());
2173 theRC = aSR->ContextOfItems();
2174 Interface_EntityIterator aSDRIt = theGraph.Sharings(aSR);
2175 for (aSDRIt.Start(); aSDRIt.More() && aPDS.IsNull(); aSDRIt.Next()) {
2176 Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
2177 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value());
2178 if (aSDR.IsNull()) continue;
2179 Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition();
2180 if (aPropD.IsNull()) continue;
2181 aPDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aPropD);
2187 anIter = theGraph.Sharings(theEnt);
2188 for (anIter.Start(); anIter.More(); anIter.Next()) {
2189 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)) ||
2190 anIter.Value()->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem)))
2192 aPDS = FindPDS(theGraph, anIter.Value(), theRC);
2201 //=======================================================================
2202 //function : GetUnit
2203 //purpose : auxiliary
2204 //=======================================================================
2205 static StepBasic_Unit GetUnit(const Handle(StepRepr_RepresentationContext)& theRC,
2206 const Standard_Boolean isAngle = Standard_False)
2208 StepBasic_Unit aUnit;
2209 Handle(StepBasic_NamedUnit) aCurrentUnit;
2211 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
2212 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
2213 if(!aCtx.IsNull()) {
2214 for(Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) {
2215 if (aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit)) ||
2216 aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit))) {
2217 aCurrentUnit = aCtx->UnitsValue(j);
2222 if (aCurrentUnit.IsNull()) {
2223 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
2224 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
2225 if(!aCtx1.IsNull()) {
2226 for(Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) {
2227 if (aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit)) ||
2228 aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit))) {
2229 aCurrentUnit = aCtx1->UnitsValue(j);
2235 if (aCurrentUnit.IsNull())
2236 aCurrentUnit = new StepBasic_SiUnitAndPlaneAngleUnit;
2239 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
2240 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
2241 if(!aCtx.IsNull()) {
2242 for(Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) {
2243 if (aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)) ||
2244 aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) {
2245 aCurrentUnit = aCtx->UnitsValue(j);
2250 if (aCurrentUnit.IsNull()) {
2251 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
2252 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
2253 if(!aCtx1.IsNull()) {
2254 for(Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) {
2255 if (aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)) ||
2256 aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) {
2257 aCurrentUnit = aCtx1->UnitsValue(j);
2263 if (aCurrentUnit.IsNull())
2264 aCurrentUnit = new StepBasic_SiUnitAndLengthUnit;
2267 aUnit.SetValue(aCurrentUnit);
2271 //=======================================================================
2272 //function : CreateDimValue
2273 //purpose : auxiliary
2274 //======================================================================
2275 static Handle(StepRepr_ReprItemAndMeasureWithUnit) CreateDimValue(const Standard_Real theValue,
2276 const StepBasic_Unit theUnit,
2277 const Handle(TCollection_HAsciiString)& theName,
2278 const Standard_CString theMeasureName,
2279 const Standard_Boolean isAngle,
2280 const Standard_Boolean isQualified = Standard_False,
2281 const Handle(StepShape_QualifiedRepresentationItem)& theQRI = NULL)
2283 Handle(StepRepr_RepresentationItem) aReprItem = new StepRepr_RepresentationItem();
2284 aReprItem->Init(new TCollection_HAsciiString(theName));
2285 Handle(StepBasic_MeasureWithUnit) aMWU = new StepBasic_MeasureWithUnit();
2286 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
2287 aValueMember->SetName(theMeasureName);
2288 aValueMember->SetReal(theValue);
2289 aMWU->Init(aValueMember, theUnit);
2292 // Angle & with qualifiers
2293 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI) anItem =
2294 new StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI();
2295 anItem->Init(aMWU, aReprItem, theQRI);
2299 // Length & with qualifiers
2300 Handle(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI) anItem =
2301 new StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI();
2302 anItem->Init(aMWU, aReprItem, theQRI);
2308 // Angle & without qualifiers
2309 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) anItem =
2310 new StepRepr_ReprItemAndPlaneAngleMeasureWithUnit();
2311 anItem->Init(aMWU, aReprItem);
2315 // Length & without qualifiers
2316 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) anItem =
2317 new StepRepr_ReprItemAndLengthMeasureWithUnit();
2318 anItem->Init(aMWU, aReprItem);
2324 //=======================================================================
2325 //function : WriteShapeAspect
2326 //purpose : auxiliary (write Shape_Aspect entity for given shape)
2327 //=======================================================================
2329 Handle(StepRepr_ShapeAspect) STEPCAFControl_Writer::WriteShapeAspect (const Handle(XSControl_WorkSession) &WS,
2330 const TDF_Label theLabel,
2331 const TopoDS_Shape theShape,
2332 Handle(StepRepr_RepresentationContext)& theRC,
2333 Handle(StepAP242_GeometricItemSpecificUsage)& theGISU)
2336 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2337 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
2338 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
2339 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2340 if (aHGraph.IsNull())
2342 Interface_Graph aGraph = aHGraph->Graph();
2344 TopLoc_Location aLoc;
2345 TColStd_SequenceOfTransient aSeqRI;
2346 FindEntities( FP, theShape, aLoc, aSeqRI );
2347 if ( aSeqRI.Length() <= 0 ) {
2348 FP->Messenger()->SendInfo() << "Warning: Cannot find RI for "<<theShape.TShape()->DynamicType()->Name()<<std::endl;
2352 Handle(StepRepr_ProductDefinitionShape) aPDS;
2353 Handle(StepRepr_RepresentationContext) aRC;
2354 Handle(Standard_Transient) anEnt = aSeqRI.Value(1);
2355 aPDS = FindPDS(aGraph, anEnt, aRC);
2361 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString();
2362 Handle(TDataStd_Name) aNameAttr;
2363 if (theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) {
2364 aName = new TCollection_HAsciiString(TCollection_AsciiString(aNameAttr->Get(), '?'));
2365 Standard_Integer aFirstSpace = aName->Search(" ");
2366 if (aFirstSpace != -1)
2367 aName = aName->SubString(aFirstSpace + 1, aName->Length());
2369 aName = new TCollection_HAsciiString();
2371 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString();
2372 Handle(StepRepr_ShapeAspect) aSA = new StepRepr_ShapeAspect;
2373 aSA->Init(aName, aDescription, aPDS, StepData_LTrue);
2375 // Geometric_Item_Specific_Usage
2376 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2377 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2378 aDefinition.SetValue(aSA);
2379 Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
2380 Handle(StepRepr_RepresentationItem) anIdentifiedItem = Handle(StepRepr_RepresentationItem)::DownCast(anEnt);
2381 anReprItems->SetValue(1, anIdentifiedItem);
2382 Interface_EntityIterator subs = aGraph.Sharings(aPDS);
2383 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2384 for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) {
2385 Handle(Standard_Transient) anEntity = subs.Value();
2386 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity);
2391 // Set entities to model
2392 aGISU->Init(aName, aDescription, aDefinition, aSDR->UsedRepresentation(), anReprItems);
2393 Model->AddWithRefs(aSA);
2394 Model->AddWithRefs(aGISU);
2399 //=======================================================================
2400 //function : WritePresentation
2401 //purpose : auxiliary (write annotation plane and presentation)
2402 //======================================================================
2403 void STEPCAFControl_Writer::WritePresentation(const Handle(XSControl_WorkSession) &WS,
2404 const TopoDS_Shape thePresentation,
2405 const Handle(TCollection_HAsciiString)& thePrsName,
2406 const Standard_Boolean hasSemantic,
2407 const Standard_Boolean hasPlane,
2408 const gp_Ax2 theAnnotationPlane,
2409 const gp_Pnt theTextPosition,
2410 const Handle(Standard_Transient) theDimension)
2412 if (thePresentation.IsNull())
2415 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2418 Handle(StepVisual_TessellatedGeometricSet) aGeomSet = STEPCAFControl_GDTProperty::GetTessellation(thePresentation);
2419 Handle(StepVisual_TessellatedAnnotationOccurrence) aTAO = new StepVisual_TessellatedAnnotationOccurrence();
2420 aTAO->Init(new TCollection_HAsciiString(), myGDTPrsCurveStyle, aGeomSet);
2421 StepVisual_DraughtingCalloutElement aDCElement;
2422 aDCElement.SetValue(aTAO);
2423 Handle(StepVisual_HArray1OfDraughtingCalloutElement) aTAOs = new StepVisual_HArray1OfDraughtingCalloutElement(1, 1);
2424 aTAOs->SetValue(1, aDCElement);
2425 Handle(StepVisual_DraughtingCallout) aDCallout = new StepVisual_DraughtingCallout();
2426 Handle(TCollection_HAsciiString) aPrsName = thePrsName.IsNull() ? new TCollection_HAsciiString() : thePrsName;
2427 aDCallout->Init(aPrsName, aTAOs);
2428 Handle(StepRepr_HArray1OfRepresentationItem) aDCsForDMIA = new StepRepr_HArray1OfRepresentationItem(1, 1);
2429 aDCsForDMIA->SetValue(1, aDCallout);
2430 myGDTAnnotations.Append(aDCallout);
2431 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDimension;
2432 aDimension.SetValue(theDimension);
2433 Handle(TCollection_HAsciiString) aDMIAName;
2435 aDMIAName = new TCollection_HAsciiString("PMI representation to presentation link");
2437 aDMIAName = new TCollection_HAsciiString();
2438 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
2439 new StepAP242_DraughtingModelItemAssociation();
2440 aDMIA->Init(aDMIAName, new TCollection_HAsciiString(), aDimension, myGDTPresentationDM, aDCsForDMIA);
2441 aModel->AddWithRefs(aDMIA);
2447 // Presentation Style
2448 Handle(StepVisual_NullStyleMember) aNullStyle = new StepVisual_NullStyleMember();
2449 aNullStyle->SetEnumText(0, ".NULL.");
2450 StepVisual_PresentationStyleSelect aStyleItem;
2451 aStyleItem.SetValue(aNullStyle);
2452 Handle(StepVisual_HArray1OfPresentationStyleSelect) aStyles = new StepVisual_HArray1OfPresentationStyleSelect(1, 1);
2453 aStyles->SetValue(1, aStyleItem);
2454 Handle(StepVisual_PresentationStyleAssignment) aPrsStyle = new StepVisual_PresentationStyleAssignment();
2455 aPrsStyle->Init(aStyles);
2456 Handle(StepVisual_HArray1OfPresentationStyleAssignment) aPrsStyles =
2457 new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
2458 aPrsStyles->SetValue(1, aPrsStyle);
2460 Handle(StepGeom_Plane) aPlane = new StepGeom_Plane();
2461 GeomToStep_MakeAxis2Placement3d anAxisMaker(theAnnotationPlane);
2462 Handle(StepGeom_Axis2Placement3d) anAxis = anAxisMaker.Value();
2463 // Set text position to plane origin
2464 Handle(StepGeom_CartesianPoint) aTextPos = new StepGeom_CartesianPoint();
2465 Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
2466 for (Standard_Integer i = 1; i <= 3; i++)
2467 aCoords->SetValue(i, theTextPosition.Coord(i));
2468 aTextPos->Init(new TCollection_HAsciiString(), aCoords);
2469 anAxis->SetLocation(aTextPos);
2470 aPlane->Init(new TCollection_HAsciiString(), anAxis);
2471 // Annotation plane element
2472 StepVisual_AnnotationPlaneElement aPlaneElement;
2473 aPlaneElement.SetValue(aDCallout);
2474 Handle(StepVisual_HArray1OfAnnotationPlaneElement) aDCsForAnnPln = new StepVisual_HArray1OfAnnotationPlaneElement(1, 1);
2475 aDCsForAnnPln->SetValue(1, aPlaneElement);
2476 // Init AnnotationPlane entity
2477 Handle(StepVisual_AnnotationPlane) anAnnPlane = new StepVisual_AnnotationPlane();
2478 anAnnPlane->Init(new TCollection_HAsciiString(), aPrsStyles, aPlane, aDCsForAnnPln);
2479 myGDTAnnotations.Append(anAnnPlane);
2480 aModel->AddWithRefs(anAnnPlane);
2483 //=======================================================================
2484 //function : WriteDatumAP242
2485 //purpose : auxiliary (write Datum entity for given shape or write all
2486 // necessary entities and link them to already written datum
2487 // in case of multiple features association)
2488 //=======================================================================
2489 Handle(StepDimTol_Datum) STEPCAFControl_Writer::WriteDatumAP242(const Handle(XSControl_WorkSession) &WS,
2490 const TDF_LabelSequence theShapeL,
2491 const TDF_Label theDatumL,
2492 const Standard_Boolean isFirstDTarget,
2493 const Handle(StepDimTol_Datum) theWrittenDatum)
2496 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2497 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
2498 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
2499 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2500 if (aHGraph.IsNull())
2502 Interface_Graph aGraph = aHGraph->Graph();
2504 Handle(StepRepr_ShapeAspect) aSA;
2505 Handle(StepRepr_RepresentationContext) aRC;
2506 Handle(StepRepr_ProductDefinitionShape) aPDS;
2507 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSASeq;
2508 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2509 Standard_Integer aSANum = 0, aGISUNum = 0;
2510 // Link with datum feature
2511 for (Standard_Integer i = 1; i <= theShapeL.Length(); i++) {
2512 Handle(Standard_Transient) anEnt;
2513 TopoDS_Shape aShape;
2514 TopLoc_Location aLoc;
2515 TColStd_SequenceOfTransient aSeqRI;
2517 aShape = XCAFDoc_ShapeTool::GetShape(theShapeL.Value(i));
2518 FindEntities(FP, aShape, aLoc, aSeqRI);
2519 if (aSeqRI.Length() <= 0) {
2520 FP->Messenger()->SendInfo() << "Warning: Cannot find RI for " << aShape.TShape()->DynamicType()->Name() << std::endl;
2523 anEnt = aSeqRI.Value(1);
2524 aPDS = FindPDS(aGraph, anEnt, aRC);
2528 Handle(StepRepr_ShapeAspect) aCurrentSA = WriteShapeAspect(WS, theDatumL, aShape, aRC, aGISU);
2529 if (aCurrentSA.IsNull())
2531 aSASeq.Append(aCurrentSA);
2532 aSANum = Model->Number(aCurrentSA);
2533 aGISUNum = Model->Number(aGISU);
2535 if (aPDS.IsNull()) {
2536 // Workaround for datums without shape
2537 aPDS = myGDTCommonPDS;
2538 Interface_EntityIterator aSDRIt = aGraph.Sharings(aPDS);
2539 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2540 for (aSDRIt.Start(); aSDRIt.More() && aSDR.IsNull(); aSDRIt.Next())
2541 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value());
2542 if (!aSDR.IsNull()) {
2543 Handle(StepRepr_Representation) aRepr = aSDR->UsedRepresentation();
2544 if (!aRepr.IsNull())
2545 aRC = aRepr->ContextOfItems();
2550 // Find if datum has datum targets and get common datum attributes
2551 Handle(XCAFDoc_Datum) aDatumAttr;
2552 if (!theDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
2554 Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject();
2555 if (anObject.IsNull())
2557 Standard_Boolean isSimpleDatum = !anObject->IsDatumTarget();
2558 Handle(TCollection_HAsciiString) anIdentifier = anObject->GetName();
2559 Handle(TCollection_HAsciiString) aTargetId = (anObject->GetDatumTargetNumber() == 0 ?
2560 new TCollection_HAsciiString() : new TCollection_HAsciiString(anObject->GetDatumTargetNumber()));
2562 // If datum type is area, but there is no area in object, write as simple datum
2563 if (anObject->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Area &&
2564 anObject->GetDatumTarget().IsNull())
2565 isSimpleDatum = Standard_True;
2568 if (isSimpleDatum) {
2569 if (aSASeq.Length() == 0) {
2570 // Create empty datum with name and presentation only
2571 Handle(StepDimTol_DatumFeature) aDF = new StepDimTol_DatumFeature();
2572 aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue);
2574 Model->AddWithRefs(aDF);
2576 else if (aSASeq.Length() == 1) {
2577 Handle(StepDimTol_DatumFeature) aDF = new StepDimTol_DatumFeature();
2578 aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue);
2579 Model->ReplaceEntity(aSANum, aDF);
2581 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2582 aDefinition.SetValue(aDF);
2583 aGISU->SetDefinition(aDefinition);
2584 Model->ReplaceEntity(aGISUNum, aGISU);
2586 else if (aSASeq.Length() > 1) {
2587 Handle(StepRepr_CompShAspAndDatumFeatAndShAsp) aDF = new StepRepr_CompShAspAndDatumFeatAndShAsp();
2588 aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue);
2589 for (Standard_Integer i = 1; i <= aSASeq.Length(); i++) {
2590 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
2591 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDF, aSASeq.Value(i));
2592 Model->AddWithRefs(aSAR);
2595 Model->AddWithRefs(aDF);
2598 // Datum with datum targets
2600 XCAFDimTolObjects_DatumTargetType aDatumType = anObject->GetDatumTargetType();
2601 Handle(StepDimTol_DatumTarget) aDatumTarget;
2602 // Note: the given way to write such datum type may be incorrect (too little information)
2603 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Area) {
2604 TopoDS_Shape aDTShape = anObject->GetDatumTarget();
2605 Handle(StepAP242_GeometricItemSpecificUsage) anAreaGISU;
2606 Handle(StepRepr_ShapeAspect) anAreaSA = WriteShapeAspect(WS, theDatumL, aDTShape, aRC, anAreaGISU);
2607 aSANum = Model->Number(anAreaSA);
2608 aGISUNum = Model->Number(anAreaGISU);
2609 Handle(StepDimTol_DatumTarget) aDT = new StepDimTol_DatumTarget();
2610 aDT->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString("area"), anAreaSA->OfShape(),
2611 StepData_LTrue, aTargetId);
2612 Model->ReplaceEntity(aSANum, aDT);
2613 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2614 aDefinition.SetValue(aDT);
2615 anAreaGISU->SetDefinition(aDefinition);
2616 Model->ReplaceEntity(aGISUNum, anAreaGISU);
2619 Handle(StepDimTol_PlacedDatumTargetFeature) aPDTF = new StepDimTol_PlacedDatumTargetFeature();
2620 aPDTF->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDatumTargetName(aDatumType),
2621 aPDS, StepData_LTrue, aTargetId);
2622 Model->AddWithRefs(aPDTF);
2623 aDatumTarget = aPDTF;
2625 Handle(StepRepr_PropertyDefinition) aPD = new StepRepr_PropertyDefinition();
2626 StepRepr_CharacterizedDefinition aCDefinition;
2627 aCDefinition.SetValue(aPDTF);
2628 aPD->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCDefinition);
2629 if (anObject->HasDatumTargetParams()) {
2630 // write all parameters of datum target
2631 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP = new StepShape_ShapeRepresentationWithParameters();
2632 // Common for all datum targets
2633 StepBasic_Unit aUnit = GetUnit(aRC);
2634 gp_Ax2 aDTAxis = anObject->GetDatumTargetAxis();
2635 GeomToStep_MakeAxis2Placement3d anAxisMaker(aDTAxis);
2636 Handle(StepGeom_Axis2Placement3d) anA2P3D = anAxisMaker.Value();
2637 anA2P3D->SetName(new TCollection_HAsciiString("orientation"));
2638 Handle(StepRepr_HArray1OfRepresentationItem) anItems;
2639 // Process each datum target type
2640 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Point) {
2641 anItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
2644 Handle(TCollection_HAsciiString) aTargetValueName;
2645 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Line) {
2646 anItems = new StepRepr_HArray1OfRepresentationItem(1, 2);
2647 aTargetValueName = new TCollection_HAsciiString("target length");
2649 else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Rectangle) {
2650 anItems = new StepRepr_HArray1OfRepresentationItem(1, 3);
2651 aTargetValueName = new TCollection_HAsciiString("target length");
2653 Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue = CreateDimValue(anObject->GetDatumTargetWidth(),
2654 aUnit, new TCollection_HAsciiString("target width"), "POSITIVE_LENGTH_MEASURE", Standard_False);
2655 anItems->SetValue(2, aTargetValue);
2656 Model->AddWithRefs(aTargetValue);
2658 else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Circle) {
2659 anItems = new StepRepr_HArray1OfRepresentationItem(1, 2);
2660 aTargetValueName = new TCollection_HAsciiString("target diameter");
2663 Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue = CreateDimValue(anObject->GetDatumTargetLength(),
2664 aUnit, aTargetValueName, "POSITIVE_LENGTH_MEASURE", Standard_False);
2665 anItems->SetValue(1, aTargetValue);
2666 Model->AddWithRefs(aTargetValue);
2668 anItems->SetValue(anItems->Length(), anA2P3D);
2669 aSRWP->Init(new TCollection_HAsciiString(), anItems, aRC);
2670 // Create and write auxiliary entities
2671 Handle(StepShape_ShapeDefinitionRepresentation) aSDR = new StepShape_ShapeDefinitionRepresentation();
2672 StepRepr_RepresentedDefinition aRDefinition;
2673 aRDefinition.SetValue(aPD);
2674 aSDR->Init(aRDefinition, aSRWP);
2675 Model->AddWithRefs(aPD);
2676 Model->AddWithRefs(aSRWP);
2677 Model->AddWithRefs(aSDR);
2680 // Link datum target to datum feature
2681 // if aSASeq.Length() == 0 nothing to do
2682 if (aSASeq.Length() == 1) {
2683 Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR = new StepRepr_FeatureForDatumTargetRelationship();
2684 aFFDTR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aSASeq.Value(1), aDatumTarget);
2685 Model->AddWithRefs(aFFDTR);
2687 else if (aSASeq.Length() > 1) {
2688 Handle(StepRepr_CompositeShapeAspect) aCompSA = new StepRepr_CompositeShapeAspect();
2689 aCompSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, aSASeq.Value(1)->ProductDefinitional());
2690 for (Standard_Integer i = 1; i <= aSASeq.Length(); i++) {
2691 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
2692 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCompSA, aSASeq.Value(i));
2693 Model->AddWithRefs(aSAR);
2695 Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR = new StepRepr_FeatureForDatumTargetRelationship();
2696 aFFDTR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCompSA, aDatumTarget);
2697 Model->AddWithRefs(aFFDTR);
2703 Handle(StepDimTol_Datum) aDatum = theWrittenDatum;
2704 if (isFirstDTarget) {
2705 aDatum = new StepDimTol_Datum();
2706 aDatum->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LFalse, anIdentifier);
2707 Model->AddWithRefs(aDatum);
2710 // Shape_Aspect_Relationship
2711 if (!aSA.IsNull()) {
2712 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
2713 aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aSA, aDatum);
2714 Model->AddWithRefs(aSAR);
2717 //Annotation plane and Presentation
2718 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(),
2719 anObject->GetPlane(), anObject->GetPointTextAttach(), aSA);
2724 //=======================================================================
2725 //function : WriteDimValues
2726 //purpose : auxiliary (write all data for given dimension: values,
2727 // qualifiers, modifiers, orientation and tolerance class)
2728 //======================================================================
2729 static void WriteDimValues(const Handle(XSControl_WorkSession) &WS,
2730 const Handle(XCAFDimTolObjects_DimensionObject) theObject,
2731 const Handle(StepRepr_RepresentationContext) theRC,
2732 const StepShape_DimensionalCharacteristic theDimension)
2735 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2736 XCAFDimTolObjects_DimensionModifiersSequence aModifiers = theObject->GetModifiers();
2737 Handle(Standard_Transient) aDim = theDimension.Value();
2738 Standard_Boolean isAngle = aDim->IsKind(STANDARD_TYPE(StepShape_AngularLocation)) ||
2739 aDim->IsKind(STANDARD_TYPE(StepShape_AngularSize));
2742 StepBasic_Unit aUnit = GetUnit(theRC, isAngle);
2743 Standard_CString aMeasureName;
2745 aMeasureName = "POSITIVE_PLANE_ANGLE_MEASURE";
2747 aMeasureName = "POSITIVE_LENGTH_MEASURE";
2750 Handle(StepRepr_HArray1OfRepresentationItem) aValues;
2751 Standard_Integer aNbItems = 1, aValIt = 1;
2752 if (theObject->IsDimWithRange())
2754 if (aModifiers.Length() > 0)
2756 if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented)
2758 aNbItems += theObject->NbDescriptions();
2759 aValues = new StepRepr_HArray1OfRepresentationItem(1, aNbItems);
2762 Standard_Real aNominal = theObject->GetValue();
2763 Standard_Integer aLeftNbDigits, aRightNbDigits;
2764 theObject->GetNbOfDecimalPlaces(aLeftNbDigits, aRightNbDigits);
2765 Standard_Integer aNbQualifiers = 0;
2766 if (theObject->HasQualifier() && !isAngle)
2768 if (aLeftNbDigits > 0 || aRightNbDigits > 0)
2771 if (aNbQualifiers > 0) {
2772 Handle(StepShape_QualifiedRepresentationItem) aQRI = new StepShape_QualifiedRepresentationItem();
2773 Handle(StepShape_HArray1OfValueQualifier) aQualifiers = new StepShape_HArray1OfValueQualifier(1, aNbQualifiers);
2775 if (theObject->HasQualifier() && !isAngle) {
2776 StepShape_ValueQualifier anItem;
2777 Handle(StepShape_TypeQualifier) aType = new StepShape_TypeQualifier();
2778 XCAFDimTolObjects_DimensionQualifier aQualifier = theObject->GetQualifier();
2779 aType->Init(STEPCAFControl_GDTProperty::GetDimQualifierName(aQualifier));
2780 aModel->AddWithRefs(aType);
2781 anItem.SetValue(aType);
2782 aQualifiers->SetValue(1, anItem);
2784 // Number of decimal places
2785 if (aLeftNbDigits > 0 || aRightNbDigits > 0) {
2786 StepShape_ValueQualifier anItem;
2787 Handle(StepShape_ValueFormatTypeQualifier) aType = new StepShape_ValueFormatTypeQualifier();
2788 Handle(TCollection_HAsciiString) aFormatType = new TCollection_HAsciiString("NR2 ");
2789 aFormatType->AssignCat(new TCollection_HAsciiString(aLeftNbDigits));
2790 aFormatType->AssignCat(new TCollection_HAsciiString("."));
2791 aFormatType->AssignCat(new TCollection_HAsciiString(aRightNbDigits));
2792 aType->Init(aFormatType);
2793 aModel->AddWithRefs(aType);
2794 anItem.SetValue(aType);
2795 aQualifiers->SetValue(aNbQualifiers, anItem);
2798 aQRI->SetQualifiers(aQualifiers);
2799 Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
2800 new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle, Standard_True, aQRI);
2801 aValues->SetValue(aValIt, anItem);
2804 // Without qualifiers
2806 Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
2807 new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle);
2808 aValues->SetValue(aValIt, anItem);
2813 if (theObject->IsDimWithRange()) {
2814 Handle(StepRepr_ReprItemAndMeasureWithUnit) aLowerItem = CreateDimValue(theObject->GetLowerBound(), aUnit,
2815 new TCollection_HAsciiString("lower limit"), aMeasureName, isAngle);
2816 Handle(StepRepr_ReprItemAndMeasureWithUnit) anUpperItem = CreateDimValue(theObject->GetUpperBound(), aUnit,
2817 new TCollection_HAsciiString("upper limit"), aMeasureName, isAngle);
2818 aValues->SetValue(aValIt, aLowerItem);
2820 aValues->SetValue(aValIt, anUpperItem);
2825 if (aModifiers.Length() > 0) {
2826 Handle(StepRepr_CompoundRepresentationItem) aCompoundRI = new StepRepr_CompoundRepresentationItem();
2827 Handle (StepRepr_HArray1OfRepresentationItem) aModifItems =
2828 new StepRepr_HArray1OfRepresentationItem(1, aModifiers.Length());
2829 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) {
2830 XCAFDimTolObjects_DimensionModif aModif = aModifiers.Value(i);
2831 Handle(StepRepr_DescriptiveRepresentationItem) aModifItem =
2832 new StepRepr_DescriptiveRepresentationItem();
2833 aModifItem->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDimModifierName(aModif));
2834 aModel->AddWithRefs(aModifItem);
2835 aModifItems->SetValue(i, aModifItem);
2837 aCompoundRI->Init(new TCollection_HAsciiString(), aModifItems);
2838 aValues->SetValue(aValIt, aCompoundRI);
2843 if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented) {
2844 Handle(StepGeom_Axis2Placement3d) anOrientation = new StepGeom_Axis2Placement3d();
2846 theObject->GetDirection(aDir);
2847 GeomToStep_MakeCartesianPoint MkPoint(gp_Pnt(0, 0, 0));
2848 Handle(StepGeom_CartesianPoint) aLoc = MkPoint.Value();
2849 Handle(StepGeom_Direction) anAxis = new StepGeom_Direction();
2850 Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
2851 aCoords->SetValue(1, aDir.X());
2852 aCoords->SetValue(2, aDir.Y());
2853 aCoords->SetValue(3, aDir.Z());
2854 anAxis->Init(new TCollection_HAsciiString(), aCoords);
2855 anOrientation->Init(new TCollection_HAsciiString("orientation"), aLoc, Standard_True, anAxis, Standard_False, NULL);
2856 aValues->SetValue(aValIt, anOrientation);
2861 if (theObject->HasDescriptions()) {
2862 for (Standard_Integer i = 0; i < theObject->NbDescriptions(); i++) {
2863 Handle(StepRepr_DescriptiveRepresentationItem) aDRI = new StepRepr_DescriptiveRepresentationItem();
2864 aDRI->Init(theObject->GetDescriptionName(i), theObject->GetDescription(i));
2865 aValues->SetValue(aValIt, aDRI);
2870 for (Standard_Integer i = 1; i <= aValues->Length(); i++)
2871 aModel->AddWithRefs(aValues->Value(i));
2873 // Create resulting Shape_Dimension_Representation
2874 Handle(StepShape_ShapeDimensionRepresentation) aSDR = new StepShape_ShapeDimensionRepresentation();
2875 aSDR->Init(new TCollection_HAsciiString(), aValues, theRC);
2876 aModel->AddWithRefs(aSDR);
2877 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR = new StepShape_DimensionalCharacteristicRepresentation();
2878 aDCR->Init(theDimension, aSDR);
2879 aModel->AddWithRefs(aDCR);
2881 // Plus_Minus_Tolerance
2882 if (theObject->IsDimWithPlusMinusTolerance()) {
2883 Handle(TCollection_HAsciiString) aDummyName = new TCollection_HAsciiString(aMeasureName);
2884 aDummyName = aDummyName->SubString(9, aDummyName->Length()); //delete "POSITIVE_"
2885 aMeasureName = aDummyName->ToCString();
2886 Standard_Real aLowerTolValue = -theObject->GetLowerTolValue(),
2887 anUpperTolValue = theObject->GetUpperTolValue();
2889 Handle(StepBasic_MeasureWithUnit) anUpperMWU = new StepBasic_MeasureWithUnit();
2890 Handle(StepBasic_MeasureValueMember) anUpperValue = new StepBasic_MeasureValueMember();
2891 anUpperValue->SetName(aMeasureName);
2892 anUpperValue->SetReal(anUpperTolValue);
2893 anUpperMWU->Init(anUpperValue, aUnit);
2894 aModel->AddWithRefs(anUpperMWU);
2896 Handle(StepBasic_MeasureWithUnit) aLowerMWU = new StepBasic_MeasureWithUnit();
2897 Handle(StepBasic_MeasureValueMember) aLowerValue = new StepBasic_MeasureValueMember();
2898 aLowerValue->SetName(aMeasureName);
2899 aLowerValue->SetReal(aLowerTolValue);
2900 aLowerMWU->Init(aLowerValue, aUnit);
2901 aModel->AddWithRefs(aLowerMWU);
2903 Handle(StepShape_ToleranceValue) aTolValue = new StepShape_ToleranceValue();
2904 aTolValue->Init(aLowerMWU, anUpperMWU);
2905 aModel->AddWithRefs(aTolValue);
2906 StepShape_ToleranceMethodDefinition aMethod;
2907 aMethod.SetValue(aTolValue);
2908 Handle(StepShape_PlusMinusTolerance) aPlusMinusTol = new StepShape_PlusMinusTolerance();
2909 aPlusMinusTol->Init(aMethod, theDimension);
2910 aModel->AddWithRefs(aPlusMinusTol);
2913 if (theObject->IsDimWithClassOfTolerance()) {
2914 Standard_Boolean isHole;
2915 XCAFDimTolObjects_DimensionFormVariance aFormVariance;
2916 XCAFDimTolObjects_DimensionGrade aGrade;
2917 if (!theObject->GetClassOfTolerance(isHole, aFormVariance, aGrade))
2919 Handle(StepShape_LimitsAndFits) aLAF = STEPCAFControl_GDTProperty::GetLimitsAndFits(isHole, aFormVariance, aGrade);
2920 aModel->AddWithRefs(aLAF);
2921 StepShape_ToleranceMethodDefinition aMethod;
2922 aMethod.SetValue(aLAF);
2923 Handle(StepShape_PlusMinusTolerance) aPlusMinusTol = new StepShape_PlusMinusTolerance();
2924 aPlusMinusTol->Init(aMethod, theDimension);
2925 aModel->AddWithRefs(aPlusMinusTol);
2929 //=======================================================================
2930 //function : WriteDerivedGeometry
2931 //purpose : auxiliary (write connection point for dimensions)
2932 //======================================================================
2933 static void WriteDerivedGeometry (const Handle(XSControl_WorkSession) &WS,
2934 const Handle(XCAFDimTolObjects_DimensionObject)& theObject,
2935 const Handle(StepRepr_ConstructiveGeometryRepresentation) theRepr,
2936 Handle(StepRepr_ShapeAspect)& theFirstSA,
2937 Handle(StepRepr_ShapeAspect)& theSecondSA,
2938 NCollection_Vector<Handle(StepGeom_CartesianPoint)>& thePnts)
2940 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2942 if (theObject->HasPoint()) {
2943 GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint());
2944 Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
2945 thePnts.Append(aPoint);
2946 Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
2947 aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse);
2948 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2949 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2950 aDefinition.SetValue(aDSA);
2951 Handle(StepRepr_HArray1OfRepresentationItem) anItem = new StepRepr_HArray1OfRepresentationItem(1, 1);
2952 anItem->SetValue(1, aPoint);
2953 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDefinition, theRepr, anItem);
2954 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = new StepRepr_ShapeAspectDerivingRelationship();
2955 aSADR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDSA, theFirstSA);
2957 aModel->AddWithRefs(aGISU);
2958 aModel->AddWithRefs(aSADR);
2961 // Second point (for locations)
2962 if (theObject->HasPoint2()) {
2963 GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint2());
2964 Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
2965 thePnts.Append(aPoint);
2966 Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
2967 aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse);
2968 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2969 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2970 aDefinition.SetValue(aDSA);
2971 Handle(StepRepr_HArray1OfRepresentationItem) anItem = new StepRepr_HArray1OfRepresentationItem(1, 1);
2972 anItem->SetValue(1, aPoint);
2973 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDefinition, theRepr, anItem);
2974 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = new StepRepr_ShapeAspectDerivingRelationship();
2975 aSADR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDSA, theSecondSA);
2977 aModel->AddWithRefs(aGISU);
2978 aModel->AddWithRefs(aSADR);
2982 //=======================================================================
2983 //function : WriteDatumSystem
2984 //purpose : auxiliary (write Write datum system for given
2985 // geometric_tolerance)
2986 //======================================================================
2987 static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const Handle(XSControl_WorkSession) &WS,
2988 const TDF_Label theGeomTolL,
2989 const TDF_LabelSequence theDatumSeq,
2990 const STEPConstruct_DataMapOfAsciiStringTransient theDatumMap,
2991 const Handle(StepRepr_RepresentationContext)& theRC)
2994 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2995 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2996 if (aHGraph.IsNull())
2998 Interface_Graph aGraph = aHGraph->Graph();
2999 Handle(XCAFDoc_GeomTolerance) aGTAttr;
3000 if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr))
3002 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
3003 if (anObject.IsNull())
3007 StepBasic_Unit aUnit = GetUnit(theRC);
3009 XCAFDimTolObjects_DatumObjectSequence aDatums;
3010 Standard_Integer aMaxDatumNum = 0;
3011 for (Standard_Integer i = 1; i <= theDatumSeq.Length(); i++) {
3012 Handle(XCAFDoc_Datum) aDatumAttr;
3013 if (!theDatumSeq.Value(i).FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
3015 Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject();
3016 if (aDatumObj.IsNull())
3018 aDatums.Append(aDatumObj);
3019 aMaxDatumNum = Max(aMaxDatumNum, aDatumObj->GetPosition());
3021 if (aMaxDatumNum == 0)
3024 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aConstituents =
3025 new StepDimTol_HArray1OfDatumReferenceCompartment(1, aMaxDatumNum);
3026 // Auxiliary datum to initialize attributes in Datum_System
3027 Handle(StepDimTol_Datum) aFirstDatum;
3028 Standard_Integer aConstituentsNum = 0;
3029 for (Standard_Integer i = 1; i <= aMaxDatumNum; i++) {
3030 // Collect datums with i-th position
3031 XCAFDimTolObjects_DatumObjectSequence aDatumSeqPos;
3032 for (Standard_Integer j = 1; j <= aDatums.Length(); j++)
3033 if (aDatums.Value(j)->GetPosition() == i)
3034 aDatumSeqPos.Append(aDatums.Value(j));
3035 if (aDatumSeqPos.Length() < 1)
3039 // Initialize Datum_Reference_Compartment
3040 StepDimTol_DatumOrCommonDatum aDatumRef;
3041 Handle(StepDimTol_DatumReferenceCompartment) aCompartment =
3042 new StepDimTol_DatumReferenceCompartment();
3043 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifiers;
3044 if (aDatumSeqPos.Length() == 1) {
3046 Handle(Standard_Transient) aFDValue;
3047 if (theDatumMap.Find(aDatumSeqPos.Value(1)->GetName()->String(), aFDValue) && !aFDValue.IsNull())
3048 aFirstDatum = Handle(StepDimTol_Datum)::DownCast (aFDValue);
3049 aDatumRef.SetValue(aFirstDatum);
3051 XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(1)->GetModifiers();
3052 XCAFDimTolObjects_DatumModifWithValue aModifWithVal;
3053 Standard_Real aValue = 0;
3054 aDatumSeqPos.Value(1)->GetModifierWithValue(aModifWithVal, aValue);
3055 aModifiers = STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit);
3056 // Add Datum_Reference_Modifier_With_Value
3057 if (!aModifiers.IsNull()) {
3058 Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV =
3059 aModifiers->Value(aModifiers->Length()).DatumReferenceModifierWithValue();
3060 if (!aDRMWV.IsNull()) {
3061 Model->AddWithRefs(aDRMWV);
3066 Handle(StepDimTol_HArray1OfDatumReferenceElement) aCommonDatumList = new StepDimTol_HArray1OfDatumReferenceElement(1, aDatumSeqPos.Length());
3067 for (Standard_Integer j = 1; j <= aDatumSeqPos.Length(); j++) {
3069 Handle(StepDimTol_Datum) aDatum;
3070 Handle(Standard_Transient) aDValue;
3071 if (theDatumMap.Find(aDatumSeqPos.Value(j)->GetName()->String(), aDValue))
3072 aDatum = Handle(StepDimTol_Datum)::DownCast (aDValue);
3073 StepDimTol_DatumOrCommonDatum anElemDatumRef;
3074 anElemDatumRef.SetValue(aDatum);
3075 if (aFirstDatum.IsNull())
3076 aFirstDatum = aDatum;
3078 XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(j)->GetModifiers();
3079 XCAFDimTolObjects_DatumModifWithValue aModifWithVal;
3080 Standard_Real aValue = 0;
3081 aDatumSeqPos.Value(j)->GetModifierWithValue(aModifWithVal, aValue);
3082 Handle(StepDimTol_HArray1OfDatumReferenceModifier) anElemModifiers =
3083 STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit);
3084 // Add Datum_Reference_Modifier_With_Value
3085 if (!anElemModifiers.IsNull()) {
3086 Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV =
3087 anElemModifiers->Value(anElemModifiers->Length()).DatumReferenceModifierWithValue();
3088 if (!aDRMWV.IsNull()) {
3089 Model->AddWithRefs(aDRMWV);
3092 // Datum_Reference_Element
3093 Handle(StepDimTol_DatumReferenceElement) anElement = new StepDimTol_DatumReferenceElement();
3094 anElement->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDatum->OfShape(),
3095 aDatum->ProductDefinitional(), anElemDatumRef, !anElemModifiers.IsNull(), anElemModifiers);
3096 Model->AddWithRefs(anElement);
3097 aCommonDatumList->SetValue(j, anElement);
3099 aDatumRef.SetValue(aCommonDatumList);
3101 aCompartment->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(),
3102 aFirstDatum->ProductDefinitional(), aDatumRef, !aModifiers.IsNull(), aModifiers);
3103 Model->AddWithRefs(aCompartment);
3104 aConstituents->SetValue(aConstituentsNum, aCompartment);
3106 // Remove null elements from aConstituents
3107 Standard_Integer aNbConstituents = 0;
3108 for (Standard_Integer i = 1; i <= aConstituents->Length(); i++)
3109 if (!aConstituents->Value(i).IsNull())
3111 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aResConstituents =
3112 new StepDimTol_HArray1OfDatumReferenceCompartment(1, aNbConstituents);
3113 Standard_Integer aConstituentsIt = 0;
3114 for (Standard_Integer i = 1; i <= aConstituents->Length(); i++)
3115 if (!aConstituents->Value(i).IsNull()) {
3117 aResConstituents->SetValue(aConstituentsIt, aConstituents->Value(i));
3120 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
3121 Handle(StepDimTol_DatumSystem) aDS = new StepDimTol_DatumSystem();
3122 aDS->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(),
3123 aFirstDatum->ProductDefinitional(), aResConstituents);
3124 Model->AddWithRefs(aDS);
3125 StepDimTol_DatumSystemOrReference anArrayValue;
3126 anArrayValue.SetValue(aDS);
3127 aDatumSystem = new StepDimTol_HArray1OfDatumSystemOrReference(1, 1);
3128 aDatumSystem->SetValue(1, anArrayValue);
3131 if (anObject->HasAxis()) {
3132 GeomToStep_MakeAxis2Placement3d anAxisMaker(anObject->GetAxis());
3133 Handle(StepGeom_Axis2Placement3d) anAxis = anAxisMaker.Value();
3134 anAxis->SetName(new TCollection_HAsciiString("orientation"));
3135 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
3136 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
3137 aDefinition.SetValue(aDS);
3138 Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
3139 Handle(StepRepr_RepresentationItem) anIdentifiedItem = anAxis;
3140 anReprItems->SetValue(1, anIdentifiedItem);
3141 Interface_EntityIterator subs = aGraph.Sharings(aFirstDatum->OfShape());
3142 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
3143 for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) {
3144 Handle(Standard_Transient) anEntity = subs.Value();
3145 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity);
3148 return aDatumSystem;
3150 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(),
3151 aDefinition, aSDR->UsedRepresentation(), anReprItems);
3152 Model->AddWithRefs(anAxis);
3153 Model->AddWithRefs(aGISU);
3156 return aDatumSystem;
3159 //=======================================================================
3160 //function : WriteToleranceZone
3161 //purpose : auxiliary (write tolerace zones)
3162 //=======================================================================
3163 void STEPCAFControl_Writer::WriteToleranceZone (const Handle(XSControl_WorkSession) &WS,
3164 const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject,
3165 const Handle(StepDimTol_GeometricTolerance)& theEntity,
3166 const Handle(StepRepr_RepresentationContext)& theRC)
3169 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3170 if (theEntity.IsNull() || theObject.IsNull())
3173 // Return if there is no tolerance zones
3174 if (theObject->GetTypeOfValue() == XCAFDimTolObjects_GeomToleranceTypeValue_None &&
3175 theObject->GetZoneModifier() != XCAFDimTolObjects_GeomToleranceZoneModif_Runout)
3178 // Create Tolerance_Zone
3179 Handle(StepDimTol_ToleranceZoneForm) aForm = new StepDimTol_ToleranceZoneForm();
3180 Model->AddWithRefs(aForm);
3181 aForm->Init(STEPCAFControl_GDTProperty::GetTolValueType(theObject->GetTypeOfValue()));
3182 Handle(StepDimTol_HArray1OfToleranceZoneTarget) aZoneTargetArray = new StepDimTol_HArray1OfToleranceZoneTarget(1, 1);
3183 StepDimTol_ToleranceZoneTarget aTarget;
3184 aTarget.SetValue(theEntity);
3185 aZoneTargetArray->SetValue(1, aTarget);
3186 Handle(StepDimTol_ToleranceZone) aZone = new StepDimTol_ToleranceZone();
3187 aZone->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(),
3188 theEntity->TolerancedShapeAspect().ShapeAspect()->OfShape(), StepData_LFalse,
3189 aZoneTargetArray, aForm);
3190 Model->AddWithRefs(aZone);
3192 // Runout_Tolerance_Zone
3193 Handle(StepBasic_PlaneAngleMeasureWithUnit) aPAMWU = new StepBasic_PlaneAngleMeasureWithUnit();
3194 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
3195 aValueMember->SetName("PLANE_ANGLE_MEASURE");
3196 aValueMember->SetReal(theObject->GetValueOfZoneModifier());
3197 aPAMWU->Init(aValueMember, GetUnit(theRC, Standard_True));
3198 Handle(StepDimTol_RunoutZoneOrientation) anOrientation = new StepDimTol_RunoutZoneOrientation();
3199 anOrientation->Init(aPAMWU);
3200 Handle(StepDimTol_RunoutZoneDefinition) aDefinition = new StepDimTol_RunoutZoneDefinition();
3201 aDefinition->Init(aZone, NULL, anOrientation);
3202 Model->AddWithRefs(aDefinition);
3203 Model->AddWithRefs(anOrientation);
3204 Model->AddWithRefs(aPAMWU);
3207 //=======================================================================
3208 //function : WriteGeomTolerance
3209 //purpose : auxiliary (write Geometric_Tolerance entity for given shapes,
3210 // label and datum system)
3211 //======================================================================
3212 void STEPCAFControl_Writer::WriteGeomTolerance (const Handle(XSControl_WorkSession) &WS,
3213 const TDF_LabelSequence theShapeSeqL,
3214 const TDF_Label theGeomTolL,
3215 const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem,
3216 const Handle(StepRepr_RepresentationContext)& theRC)
3219 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3220 Handle(XCAFDoc_GeomTolerance) aGTAttr;
3221 if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr))
3223 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
3224 if (anObject.IsNull())
3228 Handle(StepBasic_LengthMeasureWithUnit) aLMWU = new StepBasic_LengthMeasureWithUnit();
3229 StepBasic_Unit aUnit = GetUnit(theRC);
3230 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
3231 aValueMember->SetName("LENGTH_MEASURE");
3232 aValueMember->SetReal(anObject->GetValue());
3233 aLMWU->Init(aValueMember, aUnit);
3234 Model->AddWithRefs(aLMWU);
3236 // Geometric_Tolerance target
3237 Handle(StepRepr_ShapeAspect) aMainSA;
3238 Handle(StepRepr_RepresentationContext) dummyRC;
3239 Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
3240 if (theShapeSeqL.Length() == 1) {
3241 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(1));
3242 aMainSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU);
3243 Model->AddWithRefs(aMainSA);
3246 Handle(StepRepr_CompositeShapeAspect) aCSA;
3247 for (Standard_Integer i = 1; i <= theShapeSeqL.Length(); i++) {
3248 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(i));
3249 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU);
3252 if (aCSA.IsNull()) {
3253 aCSA = new StepRepr_CompositeShapeAspect();
3254 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3255 Model->AddWithRefs(aCSA);
3257 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3258 aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCSA, aSA);
3259 Model->AddWithRefs(aSAR);
3263 StepDimTol_GeometricToleranceTarget aGTTarget;
3264 aGTTarget.SetValue(aMainSA);
3266 Standard_Boolean isWithModif = Standard_False,
3267 isWithDatRef = Standard_False,
3268 isWithMaxTol = Standard_False;
3271 XCAFDimTolObjects_GeomToleranceModifiersSequence aModifiers = anObject->GetModifiers();
3272 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifArray;
3273 Handle(StepBasic_LengthMeasureWithUnit) aMaxLMWU;
3274 Standard_Integer aModifNb = aModifiers.Length();
3275 if (anObject->GetMaterialRequirementModifier() != XCAFDimTolObjects_GeomToleranceMatReqModif_None)
3277 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++)
3278 if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around ||
3279 aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over)
3282 isWithModif = Standard_True;
3283 aModifArray = new StepDimTol_HArray1OfGeometricToleranceModifier(1, aModifNb);
3284 Standard_Integer k = 1;
3285 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) {
3286 if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around ||
3287 aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over)
3289 StepDimTol_GeometricToleranceModifier aModif =
3290 STEPCAFControl_GDTProperty::GetGeomToleranceModifier(aModifiers.Value(i));
3291 aModifArray->SetValue(k, aModif);
3294 if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_L) {
3295 aModifArray->SetValue(aModifNb, StepDimTol_GTMLeastMaterialRequirement);
3297 else if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_M) {
3298 aModifArray->SetValue(aModifNb, StepDimTol_GTMMaximumMaterialRequirement);
3300 // Modifier with value
3301 if (anObject->GetMaxValueModifier() != 0) {
3302 isWithMaxTol = Standard_True;
3303 aMaxLMWU = new StepBasic_LengthMeasureWithUnit();
3304 Handle(StepBasic_MeasureValueMember) aModifierValueMember = new StepBasic_MeasureValueMember();
3305 aModifierValueMember->SetName("LENGTH_MEASURE");
3306 aModifierValueMember->SetReal(anObject->GetMaxValueModifier());
3307 aMaxLMWU->Init(aModifierValueMember, aUnit);
3308 Model->AddWithRefs(aMaxLMWU);
3313 isWithDatRef = !theDatumSystem.IsNull();
3315 // Collect all attributes
3316 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(),
3317 aDescription = new TCollection_HAsciiString();
3318 Handle(StepDimTol_GeometricToleranceWithDatumReference) aGTWDR =
3319 new StepDimTol_GeometricToleranceWithDatumReference();
3320 aGTWDR->SetDatumSystem(theDatumSystem);
3321 Handle(StepDimTol_GeometricToleranceWithModifiers) aGTWM =
3322 new StepDimTol_GeometricToleranceWithModifiers();
3323 aGTWM->SetModifiers(aModifArray);
3324 StepDimTol_GeometricToleranceType aType =
3325 STEPCAFControl_GDTProperty::GetGeomToleranceType(anObject->GetType());
3327 // Init and write necessary subtype of Geometric_Tolerance entity
3328 Handle(StepDimTol_GeometricTolerance) aGeomTol;
3332 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference &
3333 //Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers
3334 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aResult =
3335 new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol();
3336 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aMaxLMWU, aType);
3340 // Geometric_Tolerance & Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers
3341 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aResult =
3342 new StepDimTol_GeoTolAndGeoTolWthMaxTol();
3343 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWM, aMaxLMWU, aType);
3349 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference & Geometric_Tolerance_With_Modifiers
3350 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) aResult =
3351 new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod();
3352 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aType);
3356 // Geometric_Tolerance & Geometric_Tolerance_With_Modifiers
3357 Handle(StepDimTol_GeoTolAndGeoTolWthMod) aResult =
3358 new StepDimTol_GeoTolAndGeoTolWthMod();
3359 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWM, aType);
3366 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference
3367 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) aResult =
3368 new StepDimTol_GeoTolAndGeoTolWthDatRef();
3369 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aType);
3373 // Geometric_Tolerance
3374 Handle(StepDimTol_GeometricTolerance) aResult =
3375 STEPCAFControl_GDTProperty::GetGeomTolerance(anObject->GetType());
3376 if (!aResult.IsNull()) {
3377 aResult->Init(aName, aDescription, aLMWU, aGTTarget);
3382 Model->AddWithRefs(aGeomTol);
3383 WriteToleranceZone(WS, anObject, aGeomTol, theRC);
3384 //Annotation plane and Presentation
3385 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(),
3386 anObject->GetPlane(), anObject->GetPointTextAttach(), aGeomTol);
3389 //=======================================================================
3390 //function : WriteDGTs
3392 //=======================================================================
3393 Standard_Boolean STEPCAFControl_Writer::WriteDGTs (const Handle(XSControl_WorkSession) &WS,
3394 const TDF_LabelSequence &labels ) const
3397 if ( labels.Length() <=0 ) return Standard_False;
3400 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3401 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
3402 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
3404 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3405 if(aHGraph.IsNull())
3406 return Standard_False;
3408 Interface_Graph aGraph = aHGraph->Graph();
3409 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( labels(1) );
3410 if(DGTTool.IsNull() ) return Standard_False;
3412 TDF_LabelSequence DGTLabels;
3414 STEPConstruct_DataMapOfAsciiStringTransient DatumMap;
3418 DGTTool->GetDatumLabels(DGTLabels);
3419 if(DGTLabels.Length()<=0) return Standard_False;
3421 for(i=1; i<=DGTLabels.Length(); i++) {
3422 TDF_Label DatumL = DGTLabels.Value(i);
3423 TDF_LabelSequence ShapeL;
3424 TDF_LabelSequence aNullSeq;
3425 if(!DGTTool->GetRefShapeLabel(DatumL,ShapeL,aNullSeq)) continue;
3426 // find target shape
3427 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
3428 TopLoc_Location Loc;
3429 TColStd_SequenceOfTransient seqRI;
3430 FindEntities( FP, aShape, Loc, seqRI );
3431 if ( seqRI.Length() <= 0 ) {
3432 FP->Messenger()->SendInfo() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<std::endl;
3435 Handle(StepRepr_ProductDefinitionShape) PDS;
3436 Handle(StepRepr_RepresentationContext) RC;
3437 Handle(Standard_Transient) ent = seqRI.Value(1);
3438 Handle(StepShape_AdvancedFace) AF;
3439 Handle(StepShape_EdgeCurve) EC;
3440 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
3441 if(PDS.IsNull()) continue;
3442 //std::cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<std::endl;
3443 Handle(XCAFDoc_Datum) DatumAttr;
3444 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
3445 Handle(TCollection_HAsciiString) aName = DatumAttr->GetName();
3446 Handle(TCollection_HAsciiString) aDescription = DatumAttr->GetDescription();
3447 Handle(TCollection_HAsciiString) anIdentification = DatumAttr->GetIdentification();
3448 Handle(StepDimTol_DatumFeature) DF = new StepDimTol_DatumFeature;
3449 Handle(StepDimTol_Datum) aDatum = new StepDimTol_Datum;
3450 DF->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
3451 Model->AddWithRefs(DF);
3452 aDatum->Init(aName, new TCollection_HAsciiString, PDS, StepData_LFalse, anIdentification);
3453 Model->AddWithRefs(aDatum);
3454 Handle(StepRepr_ShapeAspectRelationship) SAR = new StepRepr_ShapeAspectRelationship;
3455 SAR->SetName(aName);
3456 SAR->SetRelatingShapeAspect(DF);
3457 SAR->SetRelatedShapeAspect(aDatum);
3458 Model->AddWithRefs(SAR);
3459 // write chain for DatumFeature
3460 StepRepr_CharacterizedDefinition CD;
3462 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
3463 PropD->Init(aName,Standard_True,aDescription,CD);
3464 Model->AddWithRefs(PropD);
3465 StepRepr_RepresentedDefinition RD;
3467 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
3468 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
3469 new StepRepr_HArray1OfRepresentationItem(1,1);
3470 HARI->SetValue(1,AF);
3471 SR->Init(aName,HARI,RC);
3472 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
3474 Model->AddWithRefs(SDR);
3475 // write chain for Datum
3476 StepRepr_CharacterizedDefinition CD1;
3477 CD1.SetValue(aDatum);
3478 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
3479 PropD1->Init(aName,Standard_True,aDescription,CD1);
3480 Model->AddWithRefs(PropD1);
3481 StepRepr_RepresentedDefinition RD1;
3482 RD1.SetValue(PropD1);
3483 Handle(StepShape_ShapeRepresentation) SR1 = new StepShape_ShapeRepresentation;
3484 Handle(StepRepr_HArray1OfRepresentationItem) HARI1 =
3485 new StepRepr_HArray1OfRepresentationItem(1,1);
3486 HARI1->SetValue(1,AF->FaceGeometry());
3487 SR1->Init(aName,HARI1,RC);
3488 Model->AddWithRefs(SR1);
3489 Handle(StepShape_ShapeDefinitionRepresentation) SDR1 = new StepShape_ShapeDefinitionRepresentation;
3490 SDR1->Init(RD1,SR1);
3491 Model->AddWithRefs(SDR1);
3492 // add created Datum into Map
3493 TCollection_AsciiString stmp(aName->ToCString());
3494 stmp.AssignCat(aDescription->ToCString());
3495 stmp.AssignCat(anIdentification->ToCString());
3496 DatumMap.Bind(stmp,aDatum);
3499 // write Tolerances and Dimensions
3501 DGTTool->GetDimTolLabels(DGTLabels);
3502 if(DGTLabels.Length()<=0) return Standard_False;
3503 for(i=1; i<=DGTLabels.Length(); i++) {
3504 TDF_Label DimTolL = DGTLabels.Value(i);
3505 TDF_LabelSequence ShapeL;
3506 TDF_LabelSequence aNullSeq;
3507 if(!DGTTool->GetRefShapeLabel(DimTolL,ShapeL,aNullSeq)) continue;
3508 // find target shape
3509 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
3510 TopLoc_Location Loc;
3511 TColStd_SequenceOfTransient seqRI;
3512 FindEntities( FP, aShape, Loc, seqRI );
3513 if ( seqRI.Length() <= 0 ) {
3514 FP->Messenger()->SendInfo() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<std::endl;
3517 Handle(StepRepr_ProductDefinitionShape) PDS;
3518 Handle(StepRepr_RepresentationContext) RC;
3519 Handle(Standard_Transient) ent = seqRI.Value(1);
3520 Handle(StepShape_AdvancedFace) AF;
3521 Handle(StepShape_EdgeCurve) EC;
3522 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
3523 if(PDS.IsNull()) continue;
3524 //std::cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<std::endl;
3526 Handle(XCAFDoc_DimTol) DimTolAttr;
3527 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) continue;
3528 Standard_Integer kind = DimTolAttr->GetKind();
3529 Handle(TColStd_HArray1OfReal) aVal = DimTolAttr->GetVal();
3530 Handle(TCollection_HAsciiString) aName = DimTolAttr->GetName();
3531 Handle(TCollection_HAsciiString) aDescription = DimTolAttr->GetDescription();
3533 // common part of writing D> entities
3534 StepRepr_CharacterizedDefinition CD;
3535 Handle(StepRepr_ShapeAspect) SA = new StepRepr_ShapeAspect;
3536 SA->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
3537 Model->AddWithRefs(SA);
3539 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
3540 PropD->Init(aName,Standard_True,aDescription,CD);
3541 Model->AddWithRefs(PropD);
3542 StepRepr_RepresentedDefinition RD;
3544 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
3545 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
3546 new StepRepr_HArray1OfRepresentationItem(1,1);
3548 HARI->SetValue(1,EC);
3550 HARI->SetValue(1,AF);
3551 SR->Init(aName,HARI,RC);
3552 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
3554 Model->AddWithRefs(SDR);
3555 // define aUnit for creation LengthMeasureWithUnit (common for all)
3556 StepBasic_Unit aUnit;
3557 aUnit = GetUnit(RC);
3559 // specific part of writing D> entities
3560 if(kind<20) { //dimension
3561 Handle(StepShape_DimensionalSize) DimSize = new StepShape_DimensionalSize;
3562 DimSize->Init(SA,aDescription);
3563 Model->AddWithRefs(DimSize);
3564 if(aVal->Length()>1) {
3565 // create MeasureWithUnits
3566 Handle(StepBasic_MeasureValueMember) MVM1 = new StepBasic_MeasureValueMember;
3567 MVM1->SetName("POSITIVE_LENGTH_MEASURE");
3568 MVM1->SetReal(aVal->Value(1));
3569 Handle(StepBasic_MeasureWithUnit) MWU1 = new StepBasic_MeasureWithUnit;
3570 MWU1->Init(MVM1,aUnit);
3571 Handle(StepBasic_MeasureValueMember) MVM2 = new StepBasic_MeasureValueMember;
3572 MVM2->SetName("POSITIVE_LENGTH_MEASURE");
3573 MVM2->SetReal(aVal->Value(2));
3574 Handle(StepBasic_MeasureWithUnit) MWU2 = new StepBasic_MeasureWithUnit;
3575 MWU2->Init(MVM2,aUnit);
3576 Handle(StepRepr_RepresentationItem) RI1 = new StepRepr_RepresentationItem;
3577 RI1->Init(new TCollection_HAsciiString("lower limit"));
3578 Handle(StepRepr_RepresentationItem) RI2 = new StepRepr_RepresentationItem;
3579 RI2->Init(new TCollection_HAsciiString("upper limit"));
3580 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU1 =
3581 new StepRepr_ReprItemAndLengthMeasureWithUnit;
3582 RILMU1->Init(MWU1,RI1);
3583 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU2 =
3584 new StepRepr_ReprItemAndLengthMeasureWithUnit;
3585 RILMU2->Init(MWU2,RI2);
3586 Model->AddWithRefs(RILMU1);
3587 Model->AddWithRefs(RILMU2);
3588 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
3589 // new StepRepr_CompoundItemDefinitionMember;
3590 //Handle(TColStd_HArray1OfTransient) ArrTr = new TColStd_HArray1OfTransient(1,2);
3591 //ArrTr->SetValue(1,RILMU1);
3592 //ArrTr->SetValue(2,RILMU2);
3593 //CIDM->SetArrTransient(ArrTr);
3594 //CIDM->SetName("SET_REPRESENTATION_ITEM");
3595 //StepRepr_CompoundItemDefinition CID;
3596 //CID.SetValue(CIDM);
3597 Handle(StepRepr_HArray1OfRepresentationItem) HARIVR =
3598 new StepRepr_HArray1OfRepresentationItem(1,2);
3599 HARIVR->SetValue(1,RILMU1);
3600 HARIVR->SetValue(2,RILMU2);
3601 Handle(StepRepr_ValueRange) VR = new StepRepr_ValueRange;
3602 //VR->Init(aName,CID);
3603 VR->Init(aName,HARIVR);
3604 Model->AddEntity(VR);
3605 Handle(StepShape_ShapeDimensionRepresentation) SDimR =
3606 new StepShape_ShapeDimensionRepresentation;
3607 Handle(StepRepr_HArray1OfRepresentationItem) aHARI =
3608 new StepRepr_HArray1OfRepresentationItem(1,1);
3609 aHARI->SetValue(1,VR);
3610 SDimR->Init(aName,aHARI,RC);
3611 Model->AddWithRefs(SDimR);
3612 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
3613 new StepShape_DimensionalCharacteristicRepresentation;
3614 StepShape_DimensionalCharacteristic DimChar;
3615 DimChar.SetValue(DimSize);
3616 DimCharR->Init(DimChar,SDimR);
3617 Model->AddEntity(DimCharR);
3620 else if(kind<50) { //tolerance
3621 if(kind<35) { // tolerance with datum system
3622 TDF_LabelSequence DatumLabels;
3623 DGTTool->GetDatumOfTolerLabels(DimTolL,DatumLabels);
3624 Standard_Integer NbDR = DatumLabels.Length();
3625 Handle(StepDimTol_HArray1OfDatumReference) HADR = new StepDimTol_HArray1OfDatumReference(1,NbDR);
3626 for(Standard_Integer j=1; j<=NbDR; j++) {
3627 Handle(XCAFDoc_Datum) DatumAttr;
3628 TDF_Label DatumL = DatumLabels.Value(j);
3629 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
3630 Handle(TCollection_HAsciiString) aNameD = DatumAttr->GetName();
3631 Handle(TCollection_HAsciiString) aDescriptionD = DatumAttr->GetDescription();
3632 Handle(TCollection_HAsciiString) anIdentificationD = DatumAttr->GetIdentification();
3633 TCollection_AsciiString stmp(aNameD->ToCString());
3634 stmp.AssignCat(aDescriptionD->ToCString());
3635 stmp.AssignCat(anIdentificationD->ToCString());
3636 if(DatumMap.IsBound(stmp)) {
3637 Handle(StepDimTol_Datum) aDatum =
3638 Handle(StepDimTol_Datum)::DownCast(DatumMap.Find(stmp));
3639 Handle(StepDimTol_DatumReference) DR = new StepDimTol_DatumReference;
3641 Model->AddWithRefs(DR);
3642 HADR->SetValue(j,DR);
3645 // create LengthMeasureWithUnit
3646 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
3647 MVM->SetName("LENGTH_MEASURE");
3648 MVM->SetReal(aVal->Value(1));
3649 Handle(StepBasic_LengthMeasureWithUnit) LMWU = new StepBasic_LengthMeasureWithUnit;
3650 LMWU->Init(MVM,aUnit);
3651 // create tolerance by it's type
3653 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
3654 new StepDimTol_GeometricToleranceWithDatumReference;
3655 GTWDR->SetDatumSystem(HADR);
3656 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
3657 new StepDimTol_ModifiedGeometricTolerance;
3658 if(kind==21) MGT->SetModifier(StepDimTol_MaximumMaterialCondition);
3659 else if(kind==22) MGT->SetModifier(StepDimTol_LeastMaterialCondition);
3660 else if(kind==23) MGT->SetModifier(StepDimTol_RegardlessOfFeatureSize);
3661 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
3662 new StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol;
3663 GTComplex->Init(aName,aDescription,LMWU,SA,GTWDR,MGT);
3664 Model->AddWithRefs(GTComplex);
3667 Handle(StepDimTol_AngularityTolerance) aToler =
3668 new StepDimTol_AngularityTolerance;
3669 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3670 Model->AddWithRefs(aToler);
3673 Handle(StepDimTol_CircularRunoutTolerance) aToler =
3674 new StepDimTol_CircularRunoutTolerance;
3675 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3676 Model->AddWithRefs(aToler);
3679 Handle(StepDimTol_CoaxialityTolerance) aToler =
3680 new StepDimTol_CoaxialityTolerance;
3681 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3682 Model->AddWithRefs(aToler);
3685 Handle(StepDimTol_ConcentricityTolerance) aToler =
3686 new StepDimTol_ConcentricityTolerance;
3687 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3688 Model->AddWithRefs(aToler);
3691 Handle(StepDimTol_ParallelismTolerance) aToler =
3692 new StepDimTol_ParallelismTolerance;
3693 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3694 Model->AddWithRefs(aToler);
3697 Handle(StepDimTol_PerpendicularityTolerance) aToler =
3698 new StepDimTol_PerpendicularityTolerance;
3699 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3700 Model->AddWithRefs(aToler);
3703 Handle(StepDimTol_SymmetryTolerance) aToler =
3704 new StepDimTol_SymmetryTolerance;
3705 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3706 Model->AddWithRefs(aToler);
3709 Handle(StepDimTol_TotalRunoutTolerance) aToler =
3710 new StepDimTol_TotalRunoutTolerance;
3711 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3712 Model->AddWithRefs(aToler);
3718 return Standard_True;
3721 //=======================================================================
3722 //function : WriteDGTsAP242
3724 //=======================================================================
3726 Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_WorkSession) &WS,
3727 const TDF_LabelSequence &labels )
3730 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
3732 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3733 if(aHGraph.IsNull())
3734 return Standard_False;
3736 Interface_Graph aGraph = aHGraph->Graph();
3737 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool(labels(1));
3738 if(DGTTool.IsNull())
3739 return Standard_False;
3741 // Common entities for presentation
3742 STEPConstruct_Styles aStyles (WS);
3743 Handle(StepVisual_Colour) aCurvColor = aStyles.EncodeColor(Quantity_NOC_WHITE);
3744 Handle(StepRepr_RepresentationItem) anItem = NULL;
3745 myGDTPrsCurveStyle->SetValue(1, aStyles.MakeColorPSA(anItem, aCurvColor, aCurvColor));
3746 Interface_EntityIterator aModelIter = aModel->Entities();
3747 for (; aModelIter.More() && myGDTCommonPDS.IsNull(); aModelIter.Next())
3748 myGDTCommonPDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aModelIter.Value());
3750 TDF_LabelSequence aDGTLabels;
3751 STEPConstruct_DataMapOfAsciiStringTransient aDatumMap;
3752 Handle(StepRepr_RepresentationContext) aRC;
3757 DGTTool->GetDatumLabels(aDGTLabels);
3758 // Find all shapes with datums
3759 TColStd_MapOfAsciiString aNameIdMap;
3760 for(Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3761 TDF_Label aDatumL = aDGTLabels.Value(i);
3762 TDF_LabelSequence aShapeL, aNullSeq;
3763 DGTTool->GetRefShapeLabel(aDatumL, aShapeL, aNullSeq);
3764 Handle(XCAFDoc_Datum) aDatumAttr;
3765 aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr);
3766 Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject();
3767 TCollection_AsciiString aDatumName = anObject->GetName()->String();
3768 TCollection_AsciiString aDatumTargetId = TCollection_AsciiString(anObject->GetDatumTargetNumber());
3769 if (!aNameIdMap.Add(aDatumName.Cat(aDatumTargetId)))
3771 Handle(Standard_Transient) aWrittenDatum;
3772 Standard_Boolean isFirstDT = !aDatumMap.Find(aDatumName, aWrittenDatum);
3773 Handle(StepDimTol_Datum) aDatum = WriteDatumAP242(WS, aShapeL, aDatumL, isFirstDT,
3774 Handle(StepDimTol_Datum)::DownCast (aWrittenDatum));
3775 // Add created Datum into Map
3776 aDatumMap.Bind(aDatumName, aDatum);
3779 //----------------- //
3780 // write Dimensions //
3781 //------------------//
3783 DGTTool->GetDimensionLabels(aDGTLabels);
3784 // Auxiliary entities for derived geometry
3785 Handle(StepRepr_ConstructiveGeometryRepresentation) aCGRepr =
3786 new StepRepr_ConstructiveGeometryRepresentation();
3787 Handle(StepRepr_ConstructiveGeometryRepresentationRelationship) aCGReprRel =
3788 new StepRepr_ConstructiveGeometryRepresentationRelationship();
3789 NCollection_Vector<Handle(StepGeom_CartesianPoint)> aConnectionPnts;
3790 Handle(StepRepr_RepresentationContext) dummyRC;
3791 Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
3792 for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3793 TDF_Label aDimensionL = aDGTLabels.Value(i);
3794 TDF_LabelSequence aFirstShapeL, aSecondShapeL;
3795 Handle(XCAFDoc_Dimension) aDimAttr;
3796 if (!aDimensionL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttr))
3798 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject();
3799 if (anObject.IsNull())
3801 if (anObject->GetType() == XCAFDimTolObjects_DimensionType_CommonLabel)
3803 Handle(StepRepr_ShapeAspect) aSA = new StepRepr_ShapeAspect();
3804 aSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), myGDTCommonPDS, StepData_LTrue);
3805 aModel->AddWithRefs(aSA);
3806 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->HasPlane(),
3807 Standard_False, anObject->GetPlane(), anObject->GetPointTextAttach(), aSA);
3810 if (!DGTTool->GetRefShapeLabel(aDimensionL, aFirstShapeL, aSecondShapeL))
3813 // Write links with shapes
3814 Handle(StepRepr_ShapeAspect) aFirstSA, aSecondSA;
3815 if (aFirstShapeL.Length() == 1) {
3816 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(1));
3817 aFirstSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3818 if (aRC.IsNull() && !dummyRC.IsNull())
3821 else if (aFirstShapeL.Length() > 1) {
3822 Handle(StepRepr_CompositeShapeAspect) aCSA;
3823 for (Standard_Integer shIt = 1; shIt <= aFirstShapeL.Length(); shIt++) {
3824 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(shIt));
3825 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3828 if (aCSA.IsNull()) {
3829 aCSA = new StepRepr_CompositeShapeAspect();
3830 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3831 aModel->AddWithRefs(aCSA);
3833 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3834 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA);
3835 aModel->AddWithRefs(aSAR);
3836 if (aRC.IsNull() && !dummyRC.IsNull())
3841 if (aSecondShapeL.Length() == 1) {
3842 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(1));
3843 aSecondSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3844 if (aRC.IsNull() && !dummyRC.IsNull())
3847 else if (aSecondShapeL.Length() > 1) {
3848 Handle(StepRepr_CompositeShapeAspect) aCSA;
3849 for (Standard_Integer shIt = 1; shIt <= aSecondShapeL.Length(); shIt++) {
3850 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(shIt));
3851 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3852 if (aCSA.IsNull() && !aSA.IsNull())
3854 aCSA = new StepRepr_CompositeShapeAspect();
3856 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3857 if (!aSA.IsNull()) {
3858 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3859 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA);
3860 aModel->AddWithRefs(aSAR);
3862 if (aRC.IsNull() && !dummyRC.IsNull())
3868 if (anObject->GetType() == XCAFDimTolObjects_DimensionType_DimensionPresentation)
3870 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->HasPlane(),
3871 Standard_False, anObject->GetPlane(), anObject->GetPointTextAttach(), aFirstSA);
3876 StepShape_DimensionalCharacteristic aDimension;
3877 if (anObject->HasPoint() || anObject->HasPoint2())
3878 WriteDerivedGeometry(WS, anObject, aCGRepr, aFirstSA, aSecondSA, aConnectionPnts);
3879 XCAFDimTolObjects_DimensionType aDimType = anObject->GetType();
3880 if (STEPCAFControl_GDTProperty::IsDimensionalLocation(aDimType)) {
3881 // Dimensional_Location
3882 Handle(StepShape_DimensionalLocation) aDim = new StepShape_DimensionalLocation();
3883 aDim->Init(STEPCAFControl_GDTProperty::GetDimTypeName(aDimType), Standard_False, NULL, aFirstSA, aSecondSA);
3884 aDimension.SetValue(aDim);
3886 else if (aDimType == XCAFDimTolObjects_DimensionType_Location_Angular) {
3888 Handle(StepShape_AngularLocation) aDim = new StepShape_AngularLocation();
3889 StepShape_AngleRelator aRelator = StepShape_Equal;
3890 if (anObject->HasQualifier()) {
3891 XCAFDimTolObjects_DimensionQualifier aQualifier = anObject->GetQualifier();
3892 switch (aQualifier) {
3893 case XCAFDimTolObjects_DimensionQualifier_Min: aRelator = StepShape_Small;
3895 case XCAFDimTolObjects_DimensionQualifier_Max: aRelator = StepShape_Large;
3897 default: aRelator = StepShape_Equal;
3900 aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aRelator);
3901 aDimension.SetValue(aDim);
3903 else if (aDimType == XCAFDimTolObjects_DimensionType_Location_WithPath) {
3904 // Dimensional_Location_With_Path
3905 Handle(StepShape_DimensionalLocationWithPath) aDim = new StepShape_DimensionalLocationWithPath();
3906 Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU);
3907 aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aPathSA);
3908 aDimension.SetValue(aDim);
3910 else if (STEPCAFControl_GDTProperty::IsDimensionalSize(aDimType)) {
3912 Handle(StepShape_DimensionalSize) aDim = new StepShape_DimensionalSize();
3913 aDim->Init(aFirstSA, STEPCAFControl_GDTProperty::GetDimTypeName(aDimType));
3914 aDimension.SetValue(aDim);
3916 else if (aDimType == XCAFDimTolObjects_DimensionType_Size_Angular) {
3918 Handle(StepShape_AngularSize) aDim = new StepShape_AngularSize();
3919 StepShape_AngleRelator aRelator = StepShape_Equal;
3920 if (anObject->HasQualifier()) {
3921 XCAFDimTolObjects_DimensionQualifier aQualifier = anObject->GetQualifier();
3922 switch (aQualifier) {
3923 case XCAFDimTolObjects_DimensionQualifier_Min: aRelator = StepShape_Small;
3925 case XCAFDimTolObjects_DimensionQualifier_Max: aRelator = StepShape_Large;
3927 default: aRelator = StepShape_Equal;
3930 aDim->Init(aFirstSA, new TCollection_HAsciiString(), aRelator);
3931 aDimension.SetValue(aDim);
3933 else if (aDimType == XCAFDimTolObjects_DimensionType_Size_WithPath) {
3934 // Dimensional_Size_With_Path
3935 Handle(StepShape_DimensionalSizeWithPath) aDim = new StepShape_DimensionalSizeWithPath();
3936 Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU);
3937 aDim->Init(aFirstSA, new TCollection_HAsciiString(), aPathSA);
3938 aDimension.SetValue(aDim);
3942 WriteDimValues(WS, anObject, aRC, aDimension);
3943 //Annotation plane and Presentation
3944 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(),
3945 anObject->GetPlane(), anObject->GetPointTextAttach(), aDimension.Value());
3947 // Write Derived geometry
3948 if (aConnectionPnts.Length() > 0) {
3949 Handle(StepRepr_HArray1OfRepresentationItem) anItems = new StepRepr_HArray1OfRepresentationItem(1, aConnectionPnts.Length());
3950 for (Standard_Integer i = 0; i < aConnectionPnts.Length(); i++)
3951 anItems->SetValue(i + 1, aConnectionPnts(i));
3952 aCGRepr->Init(new TCollection_HAsciiString(), anItems, dummyRC);
3953 aCGReprRel->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), dummyGISU->UsedRepresentation(), aCGRepr);
3954 aModel->AddWithRefs(aCGReprRel);
3957 //----------------------------//
3958 // write Geometric Tolerances //
3959 //----------------------------//
3961 DGTTool->GetGeomToleranceLabels(aDGTLabels);
3962 for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3963 TDF_Label aGeomTolL = aDGTLabels.Value(i);
3964 TDF_LabelSequence aFirstShapeL, aNullSeqL;
3965 if (!DGTTool->GetRefShapeLabel(aGeomTolL, aFirstShapeL, aNullSeqL))
3967 TDF_LabelSequence aDatumSeq;
3968 DGTTool->GetDatumWithObjectOfTolerLabels(aGeomTolL, aDatumSeq);
3969 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
3970 if (aDatumSeq.Length() > 0)
3971 aDatumSystem = WriteDatumSystem(WS, aGeomTolL, aDatumSeq, aDatumMap, aRC);
3972 WriteGeomTolerance(WS, aFirstShapeL, aGeomTolL, aDatumSystem, aRC);
3975 // Write Draughting model for Annotation Planes
3976 if (myGDTAnnotations.Length() == 0)
3977 return Standard_True;
3979 Handle(StepRepr_HArray1OfRepresentationItem) aItems =
3980 new StepRepr_HArray1OfRepresentationItem(1, myGDTAnnotations.Length());
3981 for (Standard_Integer i = 1; i <= aItems->Length(); i++) {
3982 aItems->SetValue(i, myGDTAnnotations.Value(i - 1));
3984 myGDTPresentationDM->Init(new TCollection_HAsciiString(), aItems, aRC);
3985 aModel->AddWithRefs(myGDTPresentationDM);
3987 return Standard_True;
3990 //=======================================================================
3991 //function : FindPDSforRI
3992 //purpose : auxilary:
3993 //=======================================================================
3994 static Standard_Boolean FindPDSforRI(const Interface_Graph &aGraph,
3995 const Handle(Standard_Transient) &ent,
3996 Handle(StepRepr_ProductDefinitionShape) &PDS,
3997 Handle(StepRepr_RepresentationContext) &RC)
3999 if(ent.IsNull() || !ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem)))
4000 return Standard_False;
4001 Interface_EntityIterator subs = aGraph.Sharings(ent);
4002 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
4003 Handle(StepShape_ShapeRepresentation) SR =
4004 Handle(StepShape_ShapeRepresentation)::DownCast(subs.Value());
4005 if(SR.IsNull()) continue;
4006 RC = SR->ContextOfItems();
4007 Interface_EntityIterator subs1 = aGraph.Sharings(SR);
4008 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
4009 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
4010 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs1.Value());
4011 if(SDR.IsNull()) continue;
4012 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
4013 if(PropD.IsNull()) continue;
4014 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
4017 return Standard_True;
4021 //=======================================================================
4022 //function : WriteMaterials
4024 //=======================================================================
4026 Standard_Boolean STEPCAFControl_Writer::WriteMaterials (const Handle(XSControl_WorkSession) &WS,
4027 const TDF_LabelSequence &labels ) const
4030 if ( labels.Length() <=0 ) return Standard_False;
4033 const Handle(Interface_InterfaceModel) &Model = WS->Model();
4034 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
4035 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
4037 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
4038 if(aHGraph.IsNull())
4039 return Standard_False;
4041 Interface_Graph aGraph = WS->HGraph()->Graph();
4042 Handle(XCAFDoc_ShapeTool) ShTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
4043 if(ShTool.IsNull() ) return Standard_False;
4044 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( labels(1) );
4045 if(MatTool.IsNull() ) return Standard_False;
4047 STEPConstruct_DataMapOfAsciiStringTransient MapDRI,MapMRI;
4048 TDF_LabelSequence TopLabels;
4049 ShTool->GetShapes(TopLabels);
4050 for(Standard_Integer i=1; i<=TopLabels.Length(); i++) {
4051 TDF_Label ShL = TopLabels.Value(i);
4052 Handle(TDataStd_TreeNode) Node;
4053 if( ShL.FindAttribute(XCAFDoc::MaterialRefGUID(),Node) && Node->HasFather() ) {
4054 // find PDS for current shape
4055 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShL);
4056 TopLoc_Location Loc;
4057 TColStd_SequenceOfTransient seqRI;
4058 FindEntities( FP, aShape, Loc, seqRI );
4059 if(seqRI.Length()<=0) continue;
4060 Handle(StepRepr_ProductDefinitionShape) PDS;
4061 Handle(StepRepr_RepresentationContext) RC;
4062 Handle(Standard_Transient) ent = seqRI.Value(1);
4063 FindPDSforRI(aGraph,ent,PDS,RC);
4064 if(PDS.IsNull()) continue;
4065 Handle(StepBasic_ProductDefinition) aProdDef =
4066 PDS->Definition().ProductDefinition();
4067 if(aProdDef.IsNull())
4069 // write material entities
4070 TDF_Label MatL = Node->Father()->Label();
4071 Handle(TCollection_HAsciiString) aName;
4072 Handle(TCollection_HAsciiString) aDescription;
4073 Standard_Real aDensity;
4074 Handle(TCollection_HAsciiString) aDensName;
4075 Handle(TCollection_HAsciiString) aDensValType;
4076 Handle(StepRepr_Representation) RepDRI;
4077 Handle(StepRepr_Representation) RepMRI;
4078 if(MatTool->GetMaterial(MatL,aName,aDescription,aDensity,aDensName,aDensValType)) {
4079 if(aName->Length()==0) continue;
4080 TCollection_AsciiString aKey(aName->ToCString());
4081 if(MapDRI.IsBound(aKey)) {
4082 RepDRI = Handle(StepRepr_Representation)::DownCast(MapDRI.Find(aKey));
4083 if(MapMRI.IsBound(aKey)) {
4084 RepMRI = Handle(StepRepr_Representation)::DownCast(MapMRI.Find(aKey));
4089 Handle(StepRepr_DescriptiveRepresentationItem) DRI = new StepRepr_DescriptiveRepresentationItem;
4090 DRI->Init(aName,aDescription);
4091 Handle(StepRepr_HArray1OfRepresentationItem) HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
4092 HARI->SetValue(1,DRI);
4093 RepDRI = new StepRepr_Representation();
4094 RepDRI->Init(new TCollection_HAsciiString("material name"),HARI,RC);
4095 Model->AddWithRefs(RepDRI);
4097 if( aDensity > 0 ) {
4099 Handle(StepBasic_SiUnitAndMassUnit) SMU = new StepBasic_SiUnitAndMassUnit;
4100 SMU->SetName(StepBasic_sunGram);
4101 Handle(StepBasic_DerivedUnitElement) DUE1 = new StepBasic_DerivedUnitElement;
4102 DUE1->Init(SMU,3.0);
4104 Handle(StepBasic_SiUnitAndLengthUnit) SLU = new StepBasic_SiUnitAndLengthUnit;
4105 SLU->Init(Standard_True,StepBasic_spCenti,StepBasic_sunMetre);
4106 Handle(StepBasic_DerivedUnitElement) DUE2 = new StepBasic_DerivedUnitElement;
4107 DUE2->Init(SLU,2.0);
4109 Handle(StepBasic_HArray1OfDerivedUnitElement) HADUE = new StepBasic_HArray1OfDerivedUnitElement(1,2);
4110 HADUE->SetValue(1,DUE1);
4111 HADUE->SetValue(2,DUE2);
4112 Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit;
4114 Model->AddWithRefs(DU);
4115 StepBasic_Unit aUnit;
4117 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
4118 MVM->SetName(aDensValType->ToCString());
4119 MVM->SetReal(aDensity);
4120 Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem;
4121 MRI->Init(aDensName,MVM,aUnit);
4122 HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
4123 HARI->SetValue(1,MRI);
4124 RepMRI = new StepRepr_Representation();
4125 RepMRI->Init(new TCollection_HAsciiString("density"),HARI,RC);
4126 Model->AddWithRefs(RepMRI);
4128 //WriteNewMaterial(Model,aName,aDescription,aDensity,aDensName,aDensValType,RC,RepDRI,RepMRI);
4129 MapDRI.Bind(aKey,RepDRI);
4130 if ( !RepMRI.IsNull() ) MapMRI.Bind (aKey, RepMRI);
4134 if( !RepDRI.IsNull() )
4136 StepRepr_CharacterizedDefinition CD1;
4137 CD1.SetValue(aProdDef);
4138 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
4139 PropD1->Init(new TCollection_HAsciiString("material property"),Standard_True,
4140 new TCollection_HAsciiString("material name"),CD1);
4141 Model->AddWithRefs(PropD1);
4142 StepRepr_RepresentedDefinition RD1;
4143 RD1.SetValue(PropD1);
4144 Handle(StepRepr_PropertyDefinitionRepresentation) PDR1 =
4145 new StepRepr_PropertyDefinitionRepresentation;
4146 PDR1->Init(RD1,RepDRI);
4147 Model->AddWithRefs(PDR1);
4149 if( !RepMRI.IsNull() )
4151 StepRepr_CharacterizedDefinition CD2;
4152 CD2.SetValue (aProdDef);
4153 Handle (StepRepr_PropertyDefinition) PropD2 = new StepRepr_PropertyDefinition;
4154 PropD2->Init (new TCollection_HAsciiString ("material property"), Standard_True,
4155 new TCollection_HAsciiString ("density"), CD2);
4156 Model->AddWithRefs (PropD2);
4157 StepRepr_RepresentedDefinition RD2;
4158 RD2.SetValue (PropD2);
4159 Handle (StepRepr_PropertyDefinitionRepresentation) PDR2 =
4160 new StepRepr_PropertyDefinitionRepresentation;
4161 PDR2->Init (RD2, RepMRI);
4162 Model->AddWithRefs (PDR2);
4168 return Standard_True;
4172 //=======================================================================
4173 //function : SetColorMode
4175 //=======================================================================
4177 void STEPCAFControl_Writer::SetColorMode (const Standard_Boolean colormode)
4179 myColorMode = colormode;
4183 //=======================================================================
4184 //function : GetColorMode
4186 //=======================================================================
4188 Standard_Boolean STEPCAFControl_Writer::GetColorMode () const
4194 //=======================================================================
4195 //function : SetNameMode
4197 //=======================================================================
4199 void STEPCAFControl_Writer::SetNameMode (const Standard_Boolean namemode)
4201 myNameMode = namemode;
4205 //=======================================================================
4206 //function : GetNameMode
4208 //=======================================================================
4210 Standard_Boolean STEPCAFControl_Writer::GetNameMode () const
4216 //=======================================================================
4217 //function : SetLayerMode
4219 //=======================================================================
4221 void STEPCAFControl_Writer::SetLayerMode (const Standard_Boolean layermode)
4223 myLayerMode = layermode;
4227 //=======================================================================
4228 //function : GetLayerMode
4230 //=======================================================================
4232 Standard_Boolean STEPCAFControl_Writer::GetLayerMode () const
4238 //=======================================================================
4239 //function : SetPropsMode
4241 //=======================================================================
4243 void STEPCAFControl_Writer::SetPropsMode (const Standard_Boolean propsmode)
4245 myPropsMode = propsmode;
4249 //=======================================================================
4250 //function : GetPropsMode
4252 //=======================================================================
4254 Standard_Boolean STEPCAFControl_Writer::GetPropsMode () const
4260 //=======================================================================
4261 //function : SetSHUOMode
4263 //=======================================================================
4265 void STEPCAFControl_Writer::SetSHUOMode (const Standard_Boolean mode)
4271 //=======================================================================
4272 //function : GetSHUOMode
4274 //=======================================================================
4276 Standard_Boolean STEPCAFControl_Writer::GetSHUOMode () const
4282 //=======================================================================
4283 //function : SetDimTolMode
4285 //=======================================================================
4287 void STEPCAFControl_Writer::SetDimTolMode(const Standard_Boolean dimtolmode)
4289 myGDTMode = dimtolmode;
4293 //=======================================================================
4294 //function : GetDimTolMode
4296 //=======================================================================
4298 Standard_Boolean STEPCAFControl_Writer::GetDimTolMode() const
4304 //=======================================================================
4305 //function : SetMaterialMode
4307 //=======================================================================
4309 void STEPCAFControl_Writer::SetMaterialMode(const Standard_Boolean matmode)
4311 myMatMode = matmode;
4315 //=======================================================================
4316 //function : GetMaterialMode
4318 //=======================================================================
4320 Standard_Boolean STEPCAFControl_Writer::GetMaterialMode() const