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_DerivedUnit.hxx>
38 #include <StepBasic_DerivedUnitElement.hxx>
39 #include <StepBasic_HArray1OfDerivedUnitElement.hxx>
40 #include <StepBasic_LengthMeasureWithUnit.hxx>
41 #include <StepBasic_MeasureValueMember.hxx>
42 #include <StepBasic_Product.hxx>
43 #include <StepBasic_ProductDefinition.hxx>
44 #include <StepBasic_ProductDefinitionFormation.hxx>
45 #include <StepBasic_ProductDefinitionRelationship.hxx>
46 #include <StepBasic_SiUnitAndLengthUnit.hxx>
47 #include <StepBasic_SiUnitAndMassUnit.hxx>
48 #include <StepBasic_SiUnitAndPlaneAngleUnit.hxx>
49 #include <STEPCAFControl_ActorWrite.hxx>
50 #include <STEPCAFControl_Controller.hxx>
51 #include <STEPCAFControl_ExternFile.hxx>
52 #include <STEPCAFControl_Writer.hxx>
53 #include <STEPConstruct.hxx>
54 #include <STEPConstruct_DataMapOfAsciiStringTransient.hxx>
55 #include <STEPConstruct_DataMapOfPointTransient.hxx>
56 #include <STEPConstruct_ExternRefs.hxx>
57 #include <STEPCAFControl_GDTProperty.hxx>
58 #include <STEPConstruct_Styles.hxx>
59 #include <STEPConstruct_ValidationProps.hxx>
60 #include <STEPControl_StepModelType.hxx>
61 #include <STEPControl_Writer.hxx>
62 #include <StepData_Logical.hxx>
63 #include <StepData_StepModel.hxx>
64 #include <StepDimTol_AngularityTolerance.hxx>
65 #include <StepDimTol_CircularRunoutTolerance.hxx>
66 #include <StepDimTol_CoaxialityTolerance.hxx>
67 #include <StepDimTol_ConcentricityTolerance.hxx>
68 #include <StepDimTol_CylindricityTolerance.hxx>
69 #include <StepDimTol_Datum.hxx>
70 #include <StepDimTol_DatumFeature.hxx>
71 #include <StepDimTol_DatumReference.hxx>
72 #include <StepDimTol_DatumReferenceElement.hxx>
73 #include <StepDimTol_DatumSystem.hxx>
74 #include <StepDimTol_DatumSystemOrReference.hxx>
75 #include <StepDimTol_DatumTarget.hxx>
76 #include <StepDimTol_FlatnessTolerance.hxx>
77 #include <StepDimTol_GeometricToleranceType.hxx>
78 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
79 #include <StepDimTol_GeometricToleranceWithModifiers.hxx>
80 #include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx>
81 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
82 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
83 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
84 #include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx>
85 #include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
86 #include <StepDimTol_HArray1OfDatumReference.hxx>
87 #include <StepDimTol_HArray1OfDatumReferenceElement.hxx>
88 #include <StepDimTol_HArray1OfDatumReferenceModifier.hxx>
89 #include <StepDimTol_HArray1OfDatumSystemOrReference.hxx>
90 #include <StepDimTol_LineProfileTolerance.hxx>
91 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
92 #include <StepDimTol_ParallelismTolerance.hxx>
93 #include <StepDimTol_PerpendicularityTolerance.hxx>
94 #include <StepDimTol_PlacedDatumTargetFeature.hxx>
95 #include <StepDimTol_PositionTolerance.hxx>
96 #include <StepDimTol_RoundnessTolerance.hxx>
97 #include <StepDimTol_RunoutZoneDefinition.hxx>
98 #include <StepDimTol_RunoutZoneOrientation.hxx>
99 #include <StepDimTol_StraightnessTolerance.hxx>
100 #include <StepDimTol_SurfaceProfileTolerance.hxx>
101 #include <StepDimTol_SymmetryTolerance.hxx>
102 #include <StepDimTol_ToleranceZone.hxx>
103 #include <StepDimTol_ToleranceZoneForm.hxx>
104 #include <StepDimTol_TotalRunoutTolerance.hxx>
105 #include <StepGeom_Axis2Placement3d.hxx>
106 #include <StepGeom_CartesianPoint.hxx>
107 #include <StepGeom_Direction.hxx>
108 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
109 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
110 #include <StepGeom_Plane.hxx>
111 #include <StepGeom_Surface.hxx>
112 #include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx>
113 #include <StepRepr_CompositeShapeAspect.hxx>
114 #include <StepRepr_ConstructiveGeometryRepresentation.hxx>
115 #include <StepRepr_ConstructiveGeometryRepresentationRelationship.hxx>
116 #include <StepRepr_DerivedShapeAspect.hxx>
117 #include <StepRepr_DescriptiveRepresentationItem.hxx>
118 #include <StepRepr_FeatureForDatumTargetRelationship.hxx>
119 #include <StepRepr_HArray1OfRepresentationItem.hxx>
120 #include <StepRepr_MeasureRepresentationItem.hxx>
121 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
122 #include <StepRepr_ProductDefinitionShape.hxx>
123 #include <StepRepr_PropertyDefinition.hxx>
124 #include <StepRepr_RepresentedDefinition.hxx>
125 #include <StepRepr_Representation.hxx>
126 #include <StepRepr_RepresentationItem.hxx>
127 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
128 #include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx>
129 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
130 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx>
131 #include <StepRepr_ShapeAspect.hxx>
132 #include <StepRepr_ShapeAspectDerivingRelationship.hxx>
133 #include <StepRepr_ShapeAspectRelationship.hxx>
134 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
135 #include <StepRepr_ValueRange.hxx>
136 #include <StepShape_AdvancedFace.hxx>
137 #include <StepShape_AngleRelator.hxx>
138 #include <StepShape_AngularLocation.hxx>
139 #include <StepShape_AngularSize.hxx>
140 #include <StepShape_ConnectedFaceSet.hxx>
141 #include <StepShape_ContextDependentShapeRepresentation.hxx>
142 #include <StepShape_DimensionalCharacteristic.hxx>
143 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
144 #include <StepShape_DimensionalLocation.hxx>
145 #include <StepShape_DimensionalLocationWithPath.hxx>
146 #include <StepShape_DimensionalSize.hxx>
147 #include <StepShape_DimensionalSizeWithPath.hxx>
148 #include <StepShape_EdgeCurve.hxx>
149 #include <StepShape_EdgeLoop.hxx>
150 #include <StepShape_FaceBound.hxx>
151 #include <StepShape_LimitsAndFits.hxx>
152 #include <StepShape_OrientedEdge.hxx>
153 #include <StepShape_PlusMinusTolerance.hxx>
154 #include <StepShape_QualifiedRepresentationItem.hxx>
155 #include <StepShape_ShapeDefinitionRepresentation.hxx>
156 #include <StepShape_ShapeDimensionRepresentation.hxx>
157 #include <StepShape_ShapeRepresentation.hxx>
158 #include <StepShape_ShapeRepresentationWithParameters.hxx>
159 #include <StepShape_ToleranceValue.hxx>
160 #include <StepShape_TypeQualifier.hxx>
161 #include <StepShape_ValueFormatTypeQualifier.hxx>
162 #include <StepVisual_AnnotationPlane.hxx>
163 #include <StepVisual_CurveStyle.hxx>
164 #include <StepVisual_DraughtingCallout.hxx>
165 #include <StepVisual_DraughtingModel.hxx>
166 #include <StepVisual_HArray1OfInvisibleItem.hxx>
167 #include <StepVisual_HArray1OfLayeredItem.hxx>
168 #include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
169 #include <StepVisual_HArray1OfPresentationStyleSelect.hxx>
170 #include <StepVisual_Invisibility.hxx>
171 #include <StepVisual_InvisibleItem.hxx>
172 #include <StepVisual_MechanicalDesignGeometricPresentationRepresentation.hxx>
173 #include <StepVisual_NullStyleMember.hxx>
174 #include <StepVisual_PointStyle.hxx>
175 #include <StepVisual_PresentationLayerAssignment.hxx>
176 #include <StepVisual_PresentationRepresentation.hxx>
177 #include <StepVisual_PresentationStyleAssignment.hxx>
178 #include <StepVisual_PresentationStyleByContext.hxx>
179 #include <StepVisual_StyledItem.hxx>
180 #include <StepVisual_SurfaceStyleUsage.hxx>
181 #include <StepVisual_TessellatedAnnotationOccurrence.hxx>
182 #include <StepVisual_TessellatedGeometricSet.hxx>
183 #include <TCollection_AsciiString.hxx>
184 #include <TCollection_HAsciiString.hxx>
185 #include <TColStd_HArray1OfReal.hxx>
186 #include <TColStd_HArray1OfTransient.hxx>
187 #include <TColStd_HSequenceOfTransient.hxx>
188 #include <TColStd_MapOfAsciiString.hxx>
189 #include <TColStd_MapOfTransient.hxx>
190 #include <TDataStd_Name.hxx>
191 #include <TDataStd_TreeNode.hxx>
192 #include <TDataStd_UAttribute.hxx>
193 #include <TDF_AttributeSequence.hxx>
194 #include <TDF_ChildIterator.hxx>
195 #include <TDF_Label.hxx>
196 #include <TDF_LabelSequence.hxx>
197 #include <TDF_Tool.hxx>
198 #include <TDocStd_Document.hxx>
199 #include <TopoDS_Compound.hxx>
200 #include <TopoDS_Iterator.hxx>
201 #include <TopoDS_Shape.hxx>
202 #include <TopTools_MapOfShape.hxx>
203 #include <TopTools_SequenceOfShape.hxx>
204 #include <Transfer_ActorOfFinderProcess.hxx>
205 #include <Transfer_Binder.hxx>
206 #include <Transfer_FinderProcess.hxx>
207 #include <Transfer_TransientListBinder.hxx>
208 #include <TransferBRep.hxx>
209 #include <TransferBRep_ShapeMapper.hxx>
210 #include <XCAFDimTolObjects_DatumObject.hxx>
211 #include <XCAFDimTolObjects_DimensionFormVariance.hxx>
212 #include <XCAFDimTolObjects_DimensionGrade.hxx>
213 #include <XCAFDimTolObjects_DimensionObject.hxx>
214 #include <XCAFDimTolObjects_DimensionModif.hxx>
215 #include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
216 #include <XCAFDimTolObjects_DimensionQualifier.hxx>
217 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
218 #include <XCAFDoc.hxx>
219 #include <XCAFDoc_Area.hxx>
220 #include <XCAFDoc_Centroid.hxx>
221 #include <XCAFDoc_ColorTool.hxx>
222 #include <XCAFDoc_Datum.hxx>
223 #include <XCAFDoc_Dimension.hxx>
224 #include <XCAFDoc_DimTol.hxx>
225 #include <XCAFDoc_DimTolTool.hxx>
226 #include <XCAFDoc_DocumentTool.hxx>
227 #include <XCAFDoc_GeomTolerance.hxx>
228 #include <XCAFDoc_GraphNode.hxx>
229 #include <XCAFDoc_LayerTool.hxx>
230 #include <XCAFDoc_Material.hxx>
231 #include <XCAFDoc_MaterialTool.hxx>
232 #include <XCAFDoc_ShapeTool.hxx>
233 #include <XCAFDoc_Volume.hxx>
234 #include <XCAFPrs.hxx>
235 #include <XCAFPrs_DataMapIteratorOfDataMapOfStyleShape.hxx>
236 #include <XCAFPrs_DataMapOfShapeStyle.hxx>
237 #include <XCAFPrs_DataMapOfStyleShape.hxx>
238 #include <XCAFPrs_Style.hxx>
239 #include <XSControl_TransferWriter.hxx>
240 #include <XSControl_WorkSession.hxx>
242 // added by skl 15.01.2004 for D> writing
243 //#include <StepRepr_CompoundItemDefinition.hxx>
244 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
245 // added by skl 12.02.2004 for writing materials
246 //=======================================================================
247 //function : GetLabelName
248 //purpose : auxilary function: take name of label and append it to str
249 //=======================================================================
250 static Standard_Boolean GetLabelName (const TDF_Label &L, Handle(TCollection_HAsciiString) &str)
252 Handle(TDataStd_Name) N;
253 if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) return Standard_False;
254 TCollection_ExtendedString name = N->Get();
255 if ( name.Length() <=0 ) return Standard_False;
257 // set name, converting it to Ascii and removing spaces
258 TCollection_AsciiString buf ( name, '?' );
261 buf.ChangeAll(' ','_');
262 str->AssignCat ( buf.ToCString() );
263 return Standard_True;
267 //=======================================================================
268 //function : STEPCAFControl_Writer
270 //=======================================================================
272 STEPCAFControl_Writer::STEPCAFControl_Writer () :
273 myColorMode( Standard_True ),
274 myNameMode ( Standard_True ),
275 myLayerMode( Standard_True ),
276 myPropsMode( Standard_True ),
277 mySHUOMode ( Standard_True ),
278 myDGTMode ( Standard_True ),
279 myMatMode ( Standard_True )
281 STEPCAFControl_Controller::Init();
282 Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
287 //=======================================================================
288 //function : STEPCAFControl_Writer
290 //=======================================================================
292 STEPCAFControl_Writer::STEPCAFControl_Writer (const Handle(XSControl_WorkSession)& WS,
293 const Standard_Boolean scratch)
295 STEPCAFControl_Controller::Init();
296 Init ( WS, scratch );
297 myColorMode = Standard_True;
298 myNameMode = Standard_True;
299 myLayerMode = Standard_True;
300 myPropsMode = Standard_True;
301 mySHUOMode = Standard_True;
305 //=======================================================================
308 //=======================================================================
310 void STEPCAFControl_Writer::Init (const Handle(XSControl_WorkSession)& WS,
311 const Standard_Boolean scratch)
313 WS->SelectNorm ( "STEP" );
314 myWriter.SetWS (WS,scratch);
318 myGDTPresentationDM = new StepVisual_DraughtingModel();
319 myGDTPrsCurveStyle = new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
323 //=======================================================================
326 //=======================================================================
328 IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filename)
330 IFSelect_ReturnStatus status = myWriter.Write ( filename );
332 // get directory name of the main file
333 OSD_Path mainfile ( filename );
334 mainfile.SetName ( "" );
335 mainfile.SetExtension ( "" );
336 TCollection_AsciiString dpath;
337 mainfile.SystemName ( dpath );
339 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>::Iterator it(myFiles);
340 for ( ; it.More(); it.Next() ) {
341 Handle(STEPCAFControl_ExternFile) EF = it.Value();
342 if ( EF->GetWriteStatus() != IFSelect_RetVoid ) continue;
344 // construct extern file name
345 TCollection_AsciiString fname = OSD_Path::AbsolutePath ( dpath, EF->GetName()->String() );
346 if ( fname.Length() <= 0 ) fname = EF->GetName()->String();
348 cout << "Writing external file: " << fname.ToCString() << endl;
351 EF->SetWriteStatus ( EF->GetWS()->SendAll ( fname.ToCString() ) );
358 //=======================================================================
359 //function : Transfer
361 //=======================================================================
363 Standard_Boolean STEPCAFControl_Writer::Transfer( const Handle(TDocStd_Document) &doc,
364 const STEPControl_StepModelType mode,
365 const Standard_CString multi )
367 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
368 if ( STool.IsNull() ) return Standard_False;
370 TDF_LabelSequence labels;
371 STool->GetFreeShapes ( labels );
372 return Transfer ( myWriter, labels, mode, multi );
376 //=======================================================================
377 //function : Transfer
379 //=======================================================================
381 Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_Label& L,
382 const STEPControl_StepModelType mode,
383 const Standard_CString multi )
385 TDF_LabelSequence labels;
387 return Transfer ( myWriter, labels, mode, multi );
390 //=======================================================================
391 //function : Transfer
393 //=======================================================================
395 Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_LabelSequence& labels,
396 const STEPControl_StepModelType mode,
397 const Standard_CString multi )
399 return Transfer( myWriter, labels, mode, multi );
402 //=======================================================================
405 //=======================================================================
407 Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
408 const Standard_CString filename)
410 if ( ! Transfer ( doc ) ) return Standard_False;
411 return Write ( filename ) == IFSelect_RetDone;
415 //=======================================================================
418 //=======================================================================
420 Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
421 const TCollection_AsciiString &filename)
423 if ( ! Transfer ( doc ) ) return Standard_False;
424 return Write ( filename.ToCString() ) == IFSelect_RetDone;
428 //=======================================================================
429 //function : ExternFiles
431 //=======================================================================
433 const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& STEPCAFControl_Writer::ExternFiles () const
439 //=======================================================================
440 //function : ExternFile
442 //=======================================================================
444 Standard_Boolean STEPCAFControl_Writer::ExternFile (const TDF_Label &L,
445 Handle(STEPCAFControl_ExternFile) &ef) const
448 if ( ! myLabEF.IsBound ( L ) ) return Standard_False;
449 ef = myLabEF.Find ( L );
450 return Standard_True;
454 //=======================================================================
455 //function : ExternFile
457 //=======================================================================
459 Standard_Boolean STEPCAFControl_Writer::ExternFile (const Standard_CString name,
460 Handle(STEPCAFControl_ExternFile) &ef) const
463 if ( ! myFiles.IsEmpty() || ! myFiles.IsBound ( name ) )
464 return Standard_False;
465 ef = myFiles.Find( name );
466 return Standard_True;
470 //=======================================================================
473 //=======================================================================
475 STEPControl_Writer &STEPCAFControl_Writer::ChangeWriter ()
481 //=======================================================================
484 //=======================================================================
486 const STEPControl_Writer &STEPCAFControl_Writer::Writer () const
492 //=======================================================================
493 //function : Transfer
495 //=======================================================================
497 Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
498 const TDF_LabelSequence &labels,
499 const STEPControl_StepModelType mode,
500 const Standard_CString multi,
501 const Standard_Boolean isExternFile)
503 if ( labels.Length() <=0 ) return Standard_False;
505 Handle(STEPCAFControl_ActorWrite) Actor =
506 Handle(STEPCAFControl_ActorWrite)::DownCast ( writer.WS()->NormAdaptor()->ActorWrite() );
508 // translate free top-level shapes of the DECAF document
509 Standard_Integer ap = Interface_Static::IVal ("write.step.schema");
510 TDF_LabelSequence sublabels;
511 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
512 TDF_Label L = labels.Value(i);
514 if ( myLabels.IsBound ( L ) ) continue; // already processed
516 TopoDS_Shape shape = XCAFDoc_ShapeTool::GetShape ( L );
517 if ( shape.IsNull() ) continue;
519 // write shape either as a whole, or as multifile (with extern refs)
521 Actor->SetStdMode ( Standard_False );
523 TDF_LabelSequence comp;
525 //for case when only part of assemby structure should be written in the document
526 //if specified label is component of the assembly then
527 //in order to save location of this component in the high-level assembly
528 //and save name of high-level assembly it is necessary to represent structure of high-level assembly
529 //as assembly with one component specified by current label.
530 //For that compound containing only specified component is binded to the label of the high-level assembly.
531 //The such way full structure of high-level assembly was replaced on the assembly contaning one component.
532 if ( XCAFDoc_ShapeTool::IsComponent ( L ) )
534 TopoDS_Compound aComp;
536 aB.MakeCompound(aComp);
537 aB.Add(aComp, shape);
541 if ( XCAFDoc_ShapeTool::GetReferredShape ( L, ref ) )
543 if(XCAFDoc_ShapeTool::IsAssembly ( ref))
544 XCAFDoc_ShapeTool::GetComponents ( ref, comp, Standard_True );
550 // fill sequence of (sub) shapes for which attributes should be written
551 // and set actor to handle assemblies in a proper way
552 if(XCAFDoc_ShapeTool::IsAssembly ( L ))
553 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_True );
556 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
558 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( comp(k), ref ) ) continue;
559 if ( ! myLabels.IsBound ( ref ) ) {
560 TopoDS_Shape refS = XCAFDoc_ShapeTool::GetShape ( ref );
561 myLabels.Bind ( ref, refS );
562 sublabels.Append ( ref );
563 if ( XCAFDoc_ShapeTool::IsAssembly ( ref ) )
564 Actor->RegisterAssembly ( refS );
567 myLabels.Bind ( L, shape );
568 sublabels.Append ( L );
569 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) )
570 Actor->RegisterAssembly ( shape );
572 writer.Transfer(shape,mode,Standard_False);
573 Actor->SetStdMode ( Standard_True ); // restore default behaviour
576 // translate final solids
577 TopoDS_Shape Sass = TransferExternFiles ( L, mode, sublabels, multi );
579 // translate main assembly structure
581 if ( ap == 3 ) { // if AP203, switch to AP214
582 Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
583 Handle(StepData_StepModel) model =
584 Handle(StepData_StepModel)::DownCast ( writer.WS()->Model() );
585 if ( model->HasHeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) ) {
586 Handle(HeaderSection_FileSchema) fs =
587 Handle(HeaderSection_FileSchema)::DownCast ( model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) );
588 Handle(TCollection_HAsciiString) str = fs->SchemaIdentifiersValue ( 1 );
589 Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "AUTOMOTIVE_DESIGN" );
590 if ( str->Search ( ap214 ) <0 ) {
592 str->AssignCat ( ap214 );
597 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
598 Interface_Static::SetCVal ("write.step.assembly", "On");
599 writer.Transfer ( Sass, STEPControl_AsIs );
600 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
601 Interface_Static::SetIVal ("write.step.schema", ap);
605 writer.WS()->ComputeGraph(Standard_True );// added by skl 03.11.2003 since we use
606 // writer.Transfer() wihtout compute graph
610 WriteNames ( writer.WS(), sublabels );
614 if ( GetColorMode() )
615 WriteColors ( writer.WS(), sublabels );
618 if ( GetLayerMode() )
619 WriteLayers ( writer.WS(), sublabels );
621 // write SHUO entities
622 if ( GetSHUOMode() && !isExternFile )
623 // do not store SHUO for extern reference for the moment
624 WriteSHUOs ( writer.WS(), sublabels );
627 if(GetDimTolMode()) {
629 WriteDGTsAP242(writer.WS(), sublabels);
632 WriteDGTs(writer.WS(), sublabels);
637 if(GetMaterialMode())
638 WriteMaterials(writer.WS(),sublabels);
640 // register all MDGPRs in model
641 const Handle(Interface_InterfaceModel) &Model = writer.WS()->Model();
642 MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR);
643 for (; anItr.More(); anItr.Next())
644 Model->AddWithRefs( anItr.Value() );
647 if ( multi ) { // external refs
648 WriteExternRefs ( writer.WS(), sublabels );
651 // write validation props
652 // if ( multi && ap ==3 ) {
653 // Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
655 if ( GetPropsMode() )
656 WriteValProps ( writer.WS(), sublabels, multi );
658 Interface_Static::SetIVal ("write.step.schema", ap);
661 writer.WS()->ComputeGraph ( Standard_True );
663 /* ================================
664 * Write names for the sub-shapes
665 * ================================ */
667 if (Interface_Static::IVal("write.stepcaf.subshapes.name") != 0)
669 const Handle(XSControl_TransferWriter) &TW = this->ChangeWriter().WS()->TransferWriter();
670 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
672 for ( int i = 1; i <= labels.Length(); i++ )
674 TDF_Label L = labels.Value(i);
676 for ( TDF_ChildIterator it(L, Standard_True); it.More(); it.Next() )
678 TDF_Label SubL = it.Value();
680 // Access name recorded in OCAF TDataStd_Name attribute
681 Handle(TCollection_HAsciiString) hSubName = new TCollection_HAsciiString;
682 if ( !GetLabelName(SubL, hSubName) )
685 // Access topological data
686 TopoDS_Shape SubS = XCAFDoc_ShapeTool::GetShape(SubL);
690 // Access the correspondent STEP Representation Item
691 Handle(StepRepr_RepresentationItem) RI;
692 Handle(TransferBRep_ShapeMapper) aShMapper = TransferBRep::ShapeMapper(FP, SubS);
693 if ( !FP->FindTypedTransient(aShMapper, STANDARD_TYPE(StepRepr_RepresentationItem), RI) )
697 RI->SetName(hSubName);
702 return Standard_True;
706 //=======================================================================
707 //function : TransferExternFiles
709 //=======================================================================
711 TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L,
712 const STEPControl_StepModelType mode,
713 TDF_LabelSequence &labels,
714 const Standard_CString prefix)
716 // if label already translated, just return the shape
717 if ( myLabels.IsBound ( L ) ) {
718 return myLabels.Find ( L );
723 B.MakeCompound ( C );
724 //labels.Append ( L );
725 // if not assembly, write to separate file
726 if ( ! XCAFDoc_ShapeTool::IsAssembly ( L ) && !XCAFDoc_ShapeTool::IsComponent ( L )) {
728 // prepare for transfer
729 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
730 newWS->SelectNorm ( "STEP" );
731 STEPControl_Writer sw ( newWS, Standard_True );
732 TDF_LabelSequence Lseq;
735 // construct the name for extern file
736 Handle(TCollection_HAsciiString) basename = new TCollection_HAsciiString;
737 if ( prefix && prefix[0] ) basename->AssignCat ( prefix );
738 GetLabelName ( L, basename );
739 Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString ( basename );
740 name->AssignCat ( ".stp" );
741 if ( myFiles.IsBound( name->ToCString() ) ) { // avoid confusions
742 for ( Standard_Integer k=1; k < 32000; k++ ) {
743 name = new TCollection_HAsciiString ( basename );
744 name->AssignCat ( "_" );
745 name->AssignCat ( TCollection_AsciiString ( k ).ToCString() );
746 name->AssignCat ( ".stp" );
747 if ( ! myFiles.IsBound ( name->ToCString() ) ) break;
751 // translate and record extern file
752 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
754 EF->SetName ( name );
756 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
757 Interface_Static::SetCVal ("write.step.assembly", "Off");
758 const Standard_CString multi = 0;
759 EF->SetTransferStatus ( Transfer ( sw, Lseq, mode, multi, Standard_True ) );
760 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
761 myLabEF.Bind ( L, EF );
762 myFiles.Bind ( name->ToCString(), EF );
764 // return empty compound as replacement for the shape
765 myLabels.Bind ( L, C );
768 TDF_LabelSequence comp;
770 //if specified shape is component then high-level assembly is considered
771 //to get valid structure with location
772 if ( XCAFDoc_ShapeTool::IsComponent ( L ) )
777 // else iterate on components add create structure of empty compounds
778 // representing the assembly
779 else if (XCAFDoc_ShapeTool::IsAssembly ( L ))
780 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_False );
782 labels.Append ( aCurL );
783 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
784 TDF_Label lab = comp(k);
786 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, ref ) ) continue;
787 TopoDS_Shape Scomp = TransferExternFiles ( ref, mode, labels, prefix );
788 Scomp.Location ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
791 myLabels.Bind ( aCurL, C );
796 //=======================================================================
797 //function : WriteExternRefs
799 //=======================================================================
801 Standard_Boolean STEPCAFControl_Writer::WriteExternRefs (const Handle(XSControl_WorkSession) &WS,
802 const TDF_LabelSequence &labels) const
804 if ( labels.Length() <=0 ) return Standard_False;
806 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
807 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
808 STEPConstruct_ExternRefs EFTool ( WS );
809 Standard_Integer schema = Interface_Static::IVal("write.step.schema");
810 for ( Standard_Integer k=1; k <= labels.Length(); k++ ) {
811 TDF_Label lab = labels(k);
812 if ( XCAFDoc_ShapeTool::IsAssembly ( lab ) ) continue; // skip assemblies
815 Handle(STEPCAFControl_ExternFile) EF;
816 if ( ! ExternFile ( lab, EF ) ) continue; // should never be
819 if ( ! myLabels.IsBound ( lab ) ) continue; // not recorded as translated, skip
820 TopoDS_Shape S = myLabels.Find ( lab );
822 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
823 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
824 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
826 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
832 const Standard_CString format = (const Standard_CString) ( schema == 3 ? "STEP AP203" : "STEP AP214" );
833 // try to get PD from SDR
834 StepRepr_RepresentedDefinition RD = SDR->Definition();
835 Handle(StepRepr_PropertyDefinition) aPropDef = RD.PropertyDefinition();
836 if (aPropDef.IsNull()) {
838 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepRepr_PropertyDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
842 StepRepr_CharacterizedDefinition CharDef = aPropDef->Definition();
843 Handle(StepBasic_ProductDefinition) PD = CharDef.ProductDefinition();
846 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepBasic_ProductDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
850 EFTool.AddExternRef ( EF->GetName()->ToCString(), PD, format );
852 EFTool.WriteExternRefs(schema);
853 return Standard_True;
857 //=======================================================================
858 //function : FindEntities
860 //=======================================================================
861 static Standard_Integer FindEntities (const Handle(Transfer_FinderProcess) &FP,
862 const TopoDS_Shape &S,
864 TColStd_SequenceOfTransient &seqRI)
866 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, S, L );
868 if ( ! item.IsNull() ) {
869 seqRI.Append ( item );
873 // may be S was splited during shape processing
874 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
875 Handle(Transfer_Binder) bnd = FP->Find ( mapper );
876 if ( bnd.IsNull() ) return 0;
878 Handle(Transfer_TransientListBinder) TransientListBinder =
879 //Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) );
880 Handle(Transfer_TransientListBinder)::DownCast( bnd );
881 Standard_Integer nres=0;
882 if ( TransientListBinder.IsNull() && S.ShapeType() == TopAbs_COMPOUND)
884 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
885 Handle(StepRepr_RepresentationItem) aLocalItem = STEPConstruct::FindEntity ( FP, it.Value(), L );
886 if (aLocalItem.IsNull() ) continue;
888 seqRI.Append (aLocalItem);
891 else if(!TransientListBinder.IsNull())
894 const Standard_Integer nb = TransientListBinder->NbTransients();
895 for (Standard_Integer i=1; i<=nb; i++) {
896 Handle(Standard_Transient) t = TransientListBinder->Transient(i);
897 item = Handle(StepRepr_RepresentationItem)::DownCast(t);
898 if ( item.IsNull() ) continue;
900 seqRI.Append ( item );
903 /* works but is obsolete: another approach
905 TopoDS_Shape comp = TransferBRep::ShapeResult(bnd);
906 if ( ! comp.IsNull() && comp.ShapeType() < S.ShapeType() ) {
907 for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) {
908 MakeSTEPStyles(Styles, it.Value(), settings, STEPstyle,
909 Map, ( hasOwn ? &style : 0 ) );
918 //=======================================================================
919 //function : getStyledItem
921 //=======================================================================
922 static Standard_Boolean getStyledItem(const TopoDS_Shape& S,
923 const Handle(XCAFDoc_ShapeTool)& STool,
924 const STEPConstruct_Styles &Styles,
925 Handle(StepVisual_StyledItem) &resSelItem,
926 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
928 TDF_Label aTopShL = STool->FindShape(S, Standard_False);
929 TopoDS_Shape aTopLevSh = STool->GetShape( aTopShL );
930 Standard_Boolean found = Standard_False;
931 if ( !aTopLevSh.IsNull() && myMapCompMDGPR.IsBound( aTopLevSh ) ) {
932 Handle(StepVisual_PresentationRepresentation) aMDGPR =
933 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopLevSh ) );
934 Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items();
935 // search for PSA of Monifold solid
936 if ( !anSelItmHArr.IsNull() )
938 for (Standard_Integer si = 1; si <= anSelItmHArr->Length(); si++) {
939 Handle(StepVisual_StyledItem) aSelItm =
940 Handle(StepVisual_StyledItem)::DownCast(anSelItmHArr->Value(si));
942 if ( aSelItm.IsNull() )
945 // check that it is a stiled item for monifold solid brep
947 TColStd_SequenceOfTransient aNewseqRI;
948 FindEntities ( Styles.FinderProcess(), aTopLevSh, Loc, aNewseqRI );
949 if ( aNewseqRI.Length() > 0 )
952 Handle(StepRepr_RepresentationItem) anItem = aSelItm->Item();
953 Standard_Boolean isSameMonSolBR = Standard_False;
954 for (Standard_Integer mi = 1; mi <= aNewseqRI.Length(); mi++) {
955 if ( !anItem.IsNull() && anItem == aNewseqRI.Value( mi ) ) {
956 isSameMonSolBR = Standard_True;
965 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
966 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA = aSelItm->StylesValue(jsi);
967 // check for PSA for top-level (not Presentation style by contex for NAUO)
968 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
970 resSelItem = aSelItm;
971 found = Standard_True;
980 //=======================================================================
981 //function : setDefaultInstanceColor
983 //=======================================================================
984 static Standard_Boolean setDefaultInstanceColor (const Handle(StepVisual_StyledItem) &aSelItm,
985 Handle(StepVisual_PresentationStyleAssignment)& PSA)
987 Standard_Boolean found = Standard_False;
988 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
989 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA = aSelItm->StylesValue(jsi);
990 // check for PSA for top-level (not Presentation style by contex for NAUO)
991 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
992 return Standard_False;
994 // get style select from father PSA
995 if (aFatherPSA->NbStyles() > 0) {
996 Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles =
997 new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles());
998 for (Standard_Integer k = 1; k <= aFatherPSA->NbStyles(); k++) {
999 StepVisual_PresentationStyleSelect PSS;
1000 StepVisual_PresentationStyleSelect olDPSS = aFatherPSA->StylesValue(k);
1001 if (!olDPSS.PointStyle().IsNull())
1002 PSS.SetValue (olDPSS.PointStyle());
1003 else if (!olDPSS.CurveStyle().IsNull())
1004 PSS.SetValue (olDPSS.CurveStyle());
1005 else if (!olDPSS.SurfaceStyleUsage().IsNull())
1006 PSS.SetValue (olDPSS.SurfaceStyleUsage());
1008 found = Standard_False;
1011 //aFatherStyles->SetValue( k, PSS );
1012 aFatherStyles->SetValue( k, olDPSS );
1013 found = Standard_True;
1017 PSA->Init( aFatherStyles );
1026 //=======================================================================
1027 //function : MakeSTEPStyles
1028 //purpose : auxilary
1029 //=======================================================================
1030 static void MakeSTEPStyles (STEPConstruct_Styles &Styles,
1031 const TopoDS_Shape &S,
1032 const XCAFPrs_DataMapOfShapeStyle &settings,
1033 Handle(StepVisual_StyledItem) &override,
1034 TopTools_MapOfShape &Map,
1035 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR,
1036 STEPConstruct_DataMapOfAsciiStringTransient &DPDCs,
1037 STEPConstruct_DataMapOfPointTransient &ColRGBs,
1038 const Handle(XCAFDoc_ColorTool)& CTool,
1039 const XCAFPrs_Style *inherit = 0,
1040 const Standard_Boolean isComponent = Standard_False)
1042 // skip already processed shapes
1043 if ( ! Map.Add ( S ) ) return;
1045 // check if shape has its own style (r inherits from ancestor)
1046 XCAFPrs_Style style;
1047 if ( inherit ) style = *inherit;
1048 if ( settings.IsBound(S) ) {
1049 XCAFPrs_Style own = settings.Find(S);
1050 if ( !own.IsVisible() ) style.SetVisibility ( Standard_False );
1051 if ( own.IsSetColorCurv() ) style.SetColorCurv ( own.GetColorCurv() );
1052 if ( own.IsSetColorSurf() ) style.SetColorSurf ( own.GetColorSurf() );
1055 // translate colors to STEP
1056 Handle(StepVisual_Colour) surfColor, curvColor;
1057 if ( style.IsSetColorSurf() )
1058 surfColor = Styles.EncodeColor(style.GetColorSurf(),DPDCs,ColRGBs);
1059 if ( style.IsSetColorCurv() )
1060 curvColor = Styles.EncodeColor(style.GetColorCurv(),DPDCs,ColRGBs);
1062 Standard_Boolean hasOwn = ( ! surfColor.IsNull() ||
1063 ! curvColor.IsNull() ||
1064 ! style.IsVisible() );
1066 // find target item and assign style to it
1067 Handle(StepVisual_StyledItem) STEPstyle = override;
1069 if ( S.ShapeType() != TopAbs_COMPOUND || isComponent ) { // skip compounds, let subshapes inherit its colors
1071 TColStd_SequenceOfTransient seqRI;
1072 Standard_Integer nb = FindEntities ( Styles.FinderProcess(), S, L, seqRI );
1074 if ( nb <=0 ) cout << "Warning: Cannot find RI for " << S.TShape()->DynamicType()->Name() << endl;
1076 //Get overridden style gka 10.06.03
1077 if ( isComponent && nb)
1078 getStyledItem(S, CTool->ShapeTool(), Styles, override,myMapCompMDGPR);
1081 for ( Standard_Integer i=1; i <= nb; i++ ) {
1082 Handle(StepRepr_RepresentationItem) item =
1083 Handle(StepRepr_RepresentationItem)::DownCast(seqRI(i));
1084 Handle(StepVisual_PresentationStyleAssignment) PSA;
1085 if ( style.IsVisible() || !surfColor.IsNull() || !curvColor.IsNull() ) {
1086 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1089 // default white color
1090 surfColor = Styles.EncodeColor(Quantity_Color(1,1,1,Quantity_TOC_RGB),DPDCs,ColRGBs);
1091 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1093 setDefaultInstanceColor( override, PSA);
1095 } // end of component case
1097 STEPstyle = Styles.AddStyle ( item, PSA, override );
1098 hasOwn = Standard_False;
1103 // iterate on subshapes (except vertices :)
1104 if ( S.ShapeType() == TopAbs_EDGE ) return;
1105 if ( !isComponent ) // PTV 10.02.2003
1106 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
1107 MakeSTEPStyles ( Styles, it.Value(), settings, STEPstyle,
1108 Map, myMapCompMDGPR, DPDCs, ColRGBs, CTool,
1109 ( hasOwn ? &style : 0 ) );
1114 static Standard_Boolean getFatherColor (const TDF_Label& L,
1115 const Handle(XCAFDoc_ColorTool)& CTool,
1116 XCAFPrs_Style& style)
1118 Standard_Boolean done = Standard_False;
1119 TopoDS_Shape aSh = CTool->ShapeTool()->GetShape( L );
1120 TDF_Label aFL = CTool->ShapeTool()->FindShape( aSh );
1121 if (aFL.IsNull() || aFL == L)
1124 if ( CTool->GetColor ( aFL, XCAFDoc_ColorGen, C ) ) {
1125 style.SetColorCurv ( C );
1126 style.SetColorSurf ( C );
1127 done = Standard_True;
1129 if ( CTool->GetColor ( aFL, XCAFDoc_ColorSurf, C ) ) {
1130 style.SetColorSurf ( C );
1131 done = Standard_True;
1133 if ( CTool->GetColor ( aFL, XCAFDoc_ColorCurv, C ) ) {
1134 style.SetColorCurv ( C );
1135 done = Standard_True;
1143 //=======================================================================
1144 //function : WriteColors
1146 //=======================================================================
1148 Standard_Boolean STEPCAFControl_Writer::WriteColors (const Handle(XSControl_WorkSession) &WS,
1149 const TDF_LabelSequence &labels)
1151 if ( labels.Length() <=0 ) return Standard_False;
1153 // Iterate on shapes in the document
1154 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1155 if ( CTool.IsNull() ) return Standard_False;
1157 STEPConstruct_Styles Styles ( WS );
1158 STEPConstruct_DataMapOfAsciiStringTransient DPDCs;
1159 STEPConstruct_DataMapOfPointTransient ColRGBs;
1160 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1161 TDF_Label L = labels.Value(i);
1163 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1164 // Skip assemblies: colors assigned to assemblies and their instances
1165 // are not supported (it is not clear how to encode that in STEP)
1166 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1168 cout << "Warning: Cannot write color for Assembly" << endl;
1169 cout << "Info: Check for colors assigned to components in assembly" << endl;
1171 // PTV 22.01.2003 Write color for instances.
1172 TDF_LabelSequence compLabels;
1173 if ( aSTool.IsNull() )
1175 if (!aSTool->GetComponents(L, compLabels))
1177 WriteColors(WS, compLabels);
1180 Styles.ClearStyles();
1182 // get a target shape and try to find corresponding context
1183 // (all the colors set under that label will be put into that context)
1185 if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1186 Standard_Boolean isComponent = aSTool->IsComponent( L );
1187 TopoDS_Shape aTopSh = S;
1188 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext ( S );
1189 if ( isComponent ) {
1190 TDF_Label aTopShL = aSTool->FindShape(S, Standard_False);
1191 if (aTopShL.IsNull())
1193 aTopSh = aSTool->GetShape( aTopShL );
1194 Context = Styles.FindContext ( aTopSh );
1196 if ( Context.IsNull() )
1199 // collect settings set on that label
1200 XCAFPrs_DataMapOfShapeStyle settings;
1201 TDF_LabelSequence seq;
1203 XCAFDoc_ShapeTool::GetSubShapes ( L, seq );
1204 Standard_Boolean isVisible = Standard_True;
1205 for ( Standard_Integer j = 1; j <= seq.Length(); j++ ) {
1206 TDF_Label lab = seq.Value(j);
1207 XCAFPrs_Style style;
1210 // check for invisible status of object on label
1211 if ( !CTool->IsVisible( lab ) ) {
1212 isVisible = Standard_False;
1213 style.SetVisibility( Standard_False );
1216 if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) {
1217 style.SetColorCurv ( C );
1218 style.SetColorSurf ( C );
1220 if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) )
1221 style.SetColorSurf ( C );
1222 if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) )
1223 style.SetColorCurv ( C );
1225 // commented, cause we are need to take reference from
1226 // if ( isComponent && lab == L && !isVisible)
1227 // if ( !style.IsSetColorSurf() && !style.IsSetColorCurv() ) {
1228 // getFatherColor ( L, CTool, style);
1230 if ( ! style.IsSetColorCurv() && ! style.IsSetColorSurf() && isVisible ) continue;
1232 TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab );
1233 settings.Bind ( sub, style );
1236 if ( settings.Extent() <=0 ) continue;
1238 // iterate on subshapes and create STEP styles
1239 Handle(StepVisual_StyledItem) override;
1240 TopTools_MapOfShape Map;
1242 MakeSTEPStyles(Styles,S,settings,override,Map,myMapCompMDGPR,DPDCs,ColRGBs,CTool,0,isComponent);
1244 // create MDGPR and record it in model
1245 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1248 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1250 cerr << "Error: Current Top-Level shape have MDGPR already " << endl;
1253 Styles.CreateMDGPR ( Context, aMDGPR );
1254 if (!aMDGPR.IsNull())
1255 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1258 // create SDR and add to model.
1259 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1260 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1261 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1262 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1263 if ( FP->FindTypedTransient(mapper,
1264 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1266 // create SDR for NAUO
1267 Handle(StepRepr_ProductDefinitionShape) nullPDS; // important to be NULL
1268 Styles.CreateNAUOSRD( Context, CDSR, nullPDS );
1270 // search for MDGPR of the component top-level shape
1271 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1272 aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1274 aMDGPR = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
1275 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
1276 aMDGPR->SetName( ReprName );
1277 aMDGPR->SetContextOfItems( Context );
1278 myMapCompMDGPR.Bind ( aTopSh, aMDGPR );
1280 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1281 Standard_Integer oldLengthlen = 0;
1282 if (!oldItems.IsNull())
1283 oldLengthlen = oldItems->Length();
1284 const Standard_Integer nbIt = oldLengthlen + Styles.NbStyles();
1287 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1288 new StepRepr_HArray1OfRepresentationItem(1, nbIt);
1289 Standard_Integer si;
1290 Standard_Integer el = 1;
1291 for ( si=1; si <= oldLengthlen; si++ )
1292 newItems->SetValue( el++, oldItems->Value( si ) );
1293 for ( si=1; si <= Styles.NbStyles(); si++ ) {
1294 newItems->SetValue( el++, Styles.Style(si));
1297 if (newItems->Length() > 0)
1298 aMDGPR->SetItems( newItems );
1299 } //end of work with CDSR
1302 // create invisibility item and refer for stiledItem
1303 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1304 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1305 new StepVisual_HArray1OfInvisibleItem (1,Styles.NbStyles());
1306 // put all style item into the harray
1307 for ( Standard_Integer si=1; si <= Styles.NbStyles(); si++ ) {
1308 Handle(StepRepr_RepresentationItem) styledItm = Styles.Style(si);
1309 StepVisual_InvisibleItem anInvItem;
1310 anInvItem.SetValue( styledItm );
1311 HInvsblItm->SetValue( si, anInvItem );
1313 // set the invisibility of items
1314 Invsblt->Init( HInvsblItm );
1315 WS->Model()->AddWithRefs( Invsblt );
1319 return Standard_True;
1323 //=======================================================================
1324 //function : WriteNames
1326 //=======================================================================
1328 Standard_Boolean STEPCAFControl_Writer::WriteNames (const Handle(XSControl_WorkSession) &WS,
1329 const TDF_LabelSequence &labels) const
1331 if ( labels.Length() <=0 ) return Standard_False;
1334 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1335 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1337 // Iterate on requested shapes
1338 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1339 TDF_Label L = labels.Value(i);
1342 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1343 if ( ! GetLabelName (L, hName) ) continue;
1344 // Handle(TDataStd_Name) N;
1345 // if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) continue;
1346 // TCollection_ExtendedString name = N->Get();
1347 // if ( name.Length() <=0 ) continue;
1349 // find target STEP entity for the current shape
1351 // if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1352 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1353 TopoDS_Shape S = myLabels.Find ( L );
1355 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
1356 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1357 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
1359 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
1364 // set the name to the PRODUCT
1365 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
1366 if ( PropD.IsNull() ) continue;
1367 Handle(StepBasic_ProductDefinition) PD = PropD->Definition().ProductDefinition();
1368 if ( PD.IsNull() ) continue;
1369 Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
1371 Prod->SetId ( hName );
1372 Prod->SetName ( hName );
1374 // write names for components of assemblies
1375 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1376 TDF_LabelSequence seq;
1377 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1378 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1379 TDF_Label lab = seq(k);
1381 // get shape with correct location
1383 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1384 ! myLabels.IsBound ( Lref ) ) continue;
1385 S = myLabels.Find ( Lref );
1386 S.Move ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
1388 hName = new TCollection_HAsciiString;
1389 if ( ! GetLabelName (lab, hName) ) continue;
1391 // find the target CDSR corresponding to a shape
1392 mapper = TransferBRep::ShapeMapper ( FP, S );
1393 Handle(Transfer_Binder) binder = FP->Find ( mapper );
1394 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1395 if ( ! FP->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), CDSR) )
1397 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1398 Handle(StepBasic_ProductDefinitionRelationship) NAUO = PDS->Definition().ProductDefinitionRelationship();
1399 if ( ! NAUO.IsNull() ) NAUO->SetName ( hName );
1404 return Standard_True;
1408 //=======================================================================
1409 //function : WritePropsForLabel
1411 //=======================================================================
1412 static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession) &WS,
1413 const Handle(XCAFDoc_ShapeTool) &aSTool,
1414 const STEPCAFControl_DataMapOfLabelShape &myLabels,
1416 const Standard_CString multi)
1418 if(L.IsNull()) return Standard_False;
1420 STEPConstruct_ValidationProps Props ( WS );
1422 TopoDS_Shape S = aSTool->GetShape(L);
1423 if(S.IsNull()) return Standard_False;
1425 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1427 Handle(XCAFDoc_Area) A;
1428 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1429 if ( ! A.IsNull() ) {
1430 Props.AddArea ( S, A->Get() );
1433 Handle(XCAFDoc_Volume) V;
1434 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1435 if ( ! V.IsNull() ) {
1436 Props.AddVolume ( S, V->Get() );
1440 Handle(XCAFDoc_Centroid) C;
1441 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1442 if ( ! C.IsNull() ) {
1443 Props.AddCentroid ( S, C->Get() );
1446 if( XCAFDoc_ShapeTool::IsCompound(L) || XCAFDoc_ShapeTool::IsAssembly(L) ) {
1448 for(Standard_Integer ich=1; ich<=L.NbChildren(); ich++) {
1449 WritePropsForLabel(WS,aSTool,myLabels,L.FindChild(ich),multi);
1454 return Standard_True;
1458 //=======================================================================
1459 //function : WriteValProps
1461 //=======================================================================
1463 Standard_Boolean STEPCAFControl_Writer::WriteValProps (const Handle(XSControl_WorkSession) &WS,
1464 const TDF_LabelSequence &labels,
1465 const Standard_CString multi) const
1467 if ( labels.Length() <=0 ) return Standard_False;
1470 // STEPConstruct_ValidationProps Props ( WS );
1471 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1473 // Iterate on requested shapes
1474 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1475 TDF_Label L = labels.Value(i);
1477 WritePropsForLabel(WS,aSTool,myLabels,L,multi);
1479 // find target STEP entity for the current shape
1480 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1481 TopoDS_Shape S = myLabels.Find ( L );
1483 // write area and volume (except for components in multifile mode)
1484 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1485 Handle(XCAFDoc_Area) A;
1486 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1487 if ( ! A.IsNull() ) Props.AddArea ( S, A->Get() );
1489 Handle(XCAFDoc_Volume) V;
1490 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1491 if ( ! V.IsNull() ) Props.AddVolume ( S, V->Get() );
1495 Handle(XCAFDoc_Centroid) C;
1496 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1497 if ( ! C.IsNull() ) Props.AddCentroid ( S, C->Get() );
1499 // write centroid for components of assemblies
1500 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1501 TDF_LabelSequence seq;
1502 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1503 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1504 TDF_Label lab = seq(k);
1506 // get shape with correct location
1508 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1509 ! myLabels.IsBound ( Lref ) ) continue;
1510 TopLoc_Location Loc = XCAFDoc_ShapeTool::GetLocation ( lab );
1511 S = myLabels.Find ( Lref );
1515 lab.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1516 // if centroid is not assigned to an instance,
1517 // use (shifted) centroid of original shape
1520 Lref.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1521 if ( C.IsNull() ) continue;
1522 center = C->Get().Transformed ( Loc.Transformation() );
1524 else center = C->Get();
1526 Props.AddCentroid ( S, center, Standard_True );
1532 return Standard_True;
1536 //=======================================================================
1537 //function : WriteLayers
1539 //=======================================================================
1541 Standard_Boolean STEPCAFControl_Writer::WriteLayers (const Handle(XSControl_WorkSession) &WS,
1542 const TDF_LabelSequence &labels ) const
1545 if ( labels.Length() <=0 ) return Standard_False;
1548 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1549 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1550 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1551 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( labels(1) );
1552 if (LTool.IsNull() ) return Standard_False;
1554 TDF_LabelSequence LayerLS;
1555 LTool->GetLayerLabels(LayerLS);
1556 if ( LayerLS.Length() <=0 ) return Standard_False;
1558 // Iterate on requested layers and for each layer take set of shapes.
1559 for ( Standard_Integer i=1; i <= LayerLS.Length(); i++ ) {
1560 TDF_Label L = LayerLS.Value(i);
1562 // get labels of shapes in that layer
1563 TDF_LabelSequence ShapeLs;
1564 LTool->GetShapesOfLayer(L, ShapeLs);
1565 if ( ShapeLs.Length() <=0 ) continue;
1567 // name of layer: if not set, is considered as being empty
1568 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1569 GetLabelName ( L, hName );
1571 // Find target STEP entity for each shape and add to StepVisual_PresentationLayerAssignment items.
1572 TColStd_SequenceOfTransient seqRI;
1573 for ( Standard_Integer j=1; j <= ShapeLs.Length(); j++) {
1574 TDF_Label shLabel = ShapeLs.Value(j);
1575 if ( shLabel.IsNull() ) continue;
1577 // there is no way to assign layer to instance in STEP
1578 if ( XCAFDoc_ShapeTool::IsAssembly ( shLabel ) ||
1579 XCAFDoc_ShapeTool::IsReference ( shLabel ) )
1582 // check that the shape is one of (uub)labels written during current transfer
1583 Standard_Integer k = 1;
1584 for ( ; k <= labels.Length(); k++ )
1585 if ( shLabel.IsDescendant ( labels(k) ) ) break;
1586 if ( k > labels.Length() ) continue;
1588 // get target STEP entity
1589 TopoDS_Shape oneShape = XCAFDoc_ShapeTool::GetShape(shLabel);
1591 TopLoc_Location Loc;
1592 Standard_Integer nb =
1593 FindEntities ( FP, oneShape, Loc, seqRI );
1595 FP->Messenger() << "Warning: Cannot find RI for " << oneShape.TShape()->DynamicType()->Name() << endl;
1597 if ( seqRI.Length() <= 0 ) continue;
1599 // analyze visibility
1600 Handle(StepVisual_PresentationLayerAssignment) StepLayerAs = new StepVisual_PresentationLayerAssignment;
1601 Handle(TCollection_HAsciiString) descr;
1602 Handle(TDataStd_UAttribute) aUAttr;
1603 Standard_Boolean isLinv = Standard_False;
1604 if (L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr)) {
1605 descr = new TCollection_HAsciiString ("invisible");
1607 FP->Messenger() << "\tLayer \"" << hName->String().ToCString() << "\" is invisible"<<endl;
1609 isLinv = Standard_True;
1611 else descr = new TCollection_HAsciiString ("visible");
1613 // create layer entity
1614 Handle(StepVisual_HArray1OfLayeredItem) HArrayOfLItem =
1615 new StepVisual_HArray1OfLayeredItem ( 1, seqRI.Length() );
1616 for (Standard_Integer i1 = 1; i1<=seqRI.Length(); i1++) {
1617 StepVisual_LayeredItem LI;
1618 LI.SetValue ( seqRI.Value(i1) );
1619 HArrayOfLItem->SetValue( i1, LI );
1621 StepLayerAs->Init(hName, descr, HArrayOfLItem);
1622 Model->AddWithRefs( StepLayerAs );
1623 // PTV 23.01.2003 add the invisibility AFTER adding layer into the model.
1624 // add the invisibility for the layer
1626 // Invisibility Item for containig invisible layers.
1627 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm = new StepVisual_HArray1OfInvisibleItem (1,1);
1628 StepVisual_InvisibleItem InvIt;
1629 InvIt.SetValue( StepLayerAs );
1630 HInvsblItm->SetValue( 1, InvIt);
1632 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1633 Invsblt->Init( HInvsblItm );
1634 Model->AddWithRefs( Invsblt );
1637 return Standard_True;
1641 //=======================================================================
1642 //function : getSHUOstyle
1643 //purpose : auxilary
1644 //=======================================================================
1645 static Standard_Boolean getSHUOstyle(const TDF_Label& aSHUOlab,
1646 const Handle(XCAFDoc_ColorTool)& CTool,
1647 XCAFPrs_Style& SHUOstyle)
1650 if (!CTool->IsVisible( aSHUOlab ) )
1651 SHUOstyle.SetVisibility(Standard_False);
1653 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) {
1654 SHUOstyle.SetColorCurv ( C );
1655 SHUOstyle.SetColorSurf ( C );
1657 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) )
1658 SHUOstyle.SetColorSurf ( C );
1659 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) )
1660 SHUOstyle.SetColorCurv ( C );
1662 if ( !SHUOstyle.IsSetColorCurv() &&
1663 !SHUOstyle.IsSetColorSurf() &&
1664 SHUOstyle.IsVisible() )
1665 return Standard_False;
1666 return Standard_True;
1670 //=======================================================================
1671 //function : getProDefinitionOfNAUO
1672 //purpose : auxilary
1673 //=======================================================================
1674 static Standard_Boolean getProDefinitionOfNAUO(const Handle(XSControl_WorkSession)& WS,
1675 const TopoDS_Shape& theShape,
1676 Handle(StepBasic_ProductDefinition)& PD,
1677 Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO,
1678 Standard_Boolean IsRelating)
1680 if ( theShape.IsNull() )
1681 return Standard_False;
1683 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1684 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1685 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1686 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, theShape );
1687 if (!FP->FindTypedTransient(mapper,
1688 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1690 return Standard_False;
1692 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1694 return Standard_False;
1695 // get the NAUO entity
1696 Interface_Graph aGraph = WS->HGraph()->Graph();
1697 Interface_EntityIterator subs = aGraph.Shareds(PDS);
1698 for ( subs.Start(); subs.More(); subs.Next() ) {
1699 if (!subs.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)))
1701 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value());
1704 if ( NAUO.IsNull() )
1705 return Standard_False;
1706 // get Relatinf or Related product definition
1708 PD = NAUO->RelatedProductDefinition();
1710 PD = NAUO->RelatingProductDefinition();
1712 return Standard_False;
1713 return Standard_True;
1717 //=======================================================================
1718 //function : writeSHUO
1719 //purpose : auxilary
1720 //=======================================================================
1721 static Standard_Boolean writeSHUO (const Handle(XCAFDoc_GraphNode)& theSHUO,
1722 const Handle(XCAFDoc_ShapeTool)& theSTool,
1723 const Handle(XSControl_WorkSession)& WS,
1724 Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO,
1725 TopoDS_Shape& NAUOShape,
1726 Handle(StepBasic_ProductDefinition)& theRelatingPD,
1727 Standard_Boolean& isDeepest)
1729 // set the ProductDefinitionRelationship descriptin information as empty strings.
1730 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
1732 TDF_LabelSequence aNextUsageLabs;
1733 theSTool->GetSHUONextUsage( theSHUO->Label(), aNextUsageLabs );
1734 Handle(XCAFDoc_GraphNode) NuSHUO;
1735 if ( theTopSHUO.IsNull() ) {
1737 if (aNextUsageLabs.Length() < 1)
1738 return Standard_False;
1739 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1740 if (NuSHUO.IsNull())
1741 return Standard_False;
1742 // get relating product definition
1743 TopoDS_Shape aTopCompShape = theSTool->GetShape( theSHUO->Label().Father() );
1744 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO;
1745 if (!getProDefinitionOfNAUO( WS, aTopCompShape,
1746 theRelatingPD, UUNAUO, Standard_True ))
1747 return Standard_False;
1748 // get related product definition
1749 TopoDS_Shape aNUShape = theSTool->GetShape( NuSHUO->Label().Father() );
1750 Handle(StepBasic_ProductDefinition) aRelatedPD;
1751 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO;
1752 if (!getProDefinitionOfNAUO( WS, aNUShape,
1753 aRelatedPD, NUNAUO, Standard_False ))
1754 return Standard_False;
1756 theTopSHUO = new StepRepr_SpecifiedHigherUsageOccurrence;
1757 // create deepest shuo EmptyString
1758 theTopSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1759 /*no description*/Standard_False,/*description*/EmptyString,
1760 theRelatingPD, aRelatedPD,
1761 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1762 /*upper_usage*/UUNAUO, /*next_usage*/NUNAUO);
1763 // write the other SHUO.
1764 if(!writeSHUO( NuSHUO, theSTool, WS, theTopSHUO, NAUOShape, theRelatingPD, isDeepest )) {
1765 theTopSHUO.Nullify();
1766 return Standard_False;
1769 return Standard_True;
1771 // Handle(XCAFDoc_GraphNode) NuSHUO;
1772 if ( aNextUsageLabs.Length() > 0) {
1773 // store SHUO recursive
1775 if ( aNextUsageLabs.Length() > 1 )
1776 cout << "Warning: store only one next_usage of current SHUO" << endl;
1778 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1779 Handle(StepRepr_SpecifiedHigherUsageOccurrence) aNUEntSHUO =
1780 new StepRepr_SpecifiedHigherUsageOccurrence;
1781 if (!writeSHUO( NuSHUO, theSTool, WS, aNUEntSHUO, NAUOShape, theRelatingPD, isDeepest ))
1782 return Standard_False;
1784 // store the deepest SHUO to the dociment
1785 TopoDS_Shape aNUSh, aUUSh;
1786 aNUSh = theSTool->GetShape( NuSHUO->Label().Father() );
1787 aUUSh = theSTool->GetShape( theSHUO->Label().Father() );
1788 // get relating PD with upper_usage and related PD with next_usage
1789 Handle(StepBasic_ProductDefinition) nullPD;// no need to use,case have shared <theRelatingPD>
1790 Handle(StepBasic_ProductDefinition) aRelatedPD;
1791 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO, NUNAUO;
1792 if (!getProDefinitionOfNAUO( WS, aUUSh, nullPD, UUNAUO, Standard_True ) ||
1793 !getProDefinitionOfNAUO( WS, aNUSh, aRelatedPD, NUNAUO, Standard_False )) {
1795 cout << "Warning: cannot get related or relating PD" << endl;
1797 return Standard_False;
1799 aNUEntSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1800 /*no description*/Standard_False,/*description*/EmptyString,
1801 theRelatingPD, aRelatedPD,
1802 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1803 /*upper_usage*/theTopSHUO, /*next_usage*/NUNAUO);
1805 isDeepest = Standard_False;
1807 WS->Model()->AddWithRefs ( aNUEntSHUO );
1808 return Standard_True;
1809 } // end of recurse storing
1812 TDF_Label aShapeL = theSHUO->Label().Father();
1813 NAUOShape = theSTool->GetShape( aShapeL );
1814 // return to the deepest level from SHUO shape level
1815 // it is because SHUO is attribute on deep level and shape level.
1816 isDeepest = Standard_True;
1817 return Standard_True;
1821 //=======================================================================
1822 //function : createSHUOStyledItem
1823 //purpose : auxilary
1824 //=======================================================================
1825 static Standard_Boolean createSHUOStyledItem (const XCAFPrs_Style& style,
1826 const Handle(StepRepr_ProductDefinitionShape)& PDS,
1827 const Handle(XSControl_WorkSession) &WS,
1828 const TopoDS_Shape& Sh,
1829 const Handle(XCAFDoc_ShapeTool)& STool,
1830 MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
1832 // create styled item for the indicated SHUO and store to the model
1833 STEPConstruct_Styles Styles( WS );
1834 // translate colors to STEP
1835 Handle(StepVisual_Colour) surfColor, curvColor;
1836 if ( style.IsSetColorSurf() )
1837 surfColor = Styles.EncodeColor ( style.GetColorSurf() );
1838 if ( style.IsSetColorCurv() )
1839 curvColor = Styles.EncodeColor ( style.GetColorCurv() );
1840 Standard_Boolean isComponent = Standard_True;// cause need to get PSBC
1841 Handle(StepRepr_RepresentationItem) item;
1842 // set default color for invisible SHUO.
1843 Standard_Boolean isSetDefaultColor = Standard_False;
1844 if (surfColor.IsNull() && curvColor.IsNull() && !style.IsVisible() ) {
1845 surfColor = Styles.EncodeColor ( Quantity_Color( 1, 1, 1, Quantity_TOC_RGB ) );
1846 isSetDefaultColor = Standard_True;
1848 Handle(StepVisual_PresentationStyleAssignment) PSA =
1849 Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1850 Handle(StepVisual_StyledItem) override; //null styled item
1852 // find the repr item of the shape
1853 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1854 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
1855 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, Sh );
1856 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1857 FP->FindTypedTransient(mapper,
1858 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1860 if ( CDSR.IsNull() )
1861 return Standard_False;
1863 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext( Sh );
1864 TopoDS_Shape aTopSh = Sh;
1865 if (Context.IsNull()) {
1866 TDF_Label aTopShL = STool->FindShape(Sh, Standard_False);
1867 if (aTopShL.IsNull())
1868 return Standard_False;
1869 aTopSh = STool->GetShape( aTopShL );
1870 Context = Styles.FindContext ( aTopSh );
1872 if (Context.IsNull())
1873 return Standard_False;
1874 // get representation item of the shape
1876 TColStd_SequenceOfTransient seqRI;
1877 FindEntities ( FP, Sh, L, seqRI );
1879 if ( seqRI.Length() <=0 )
1880 FP->Messenger() << "Warning: Cannot find RI for " << Sh.TShape()->DynamicType()->Name() << endl;
1882 item = Handle(StepRepr_RepresentationItem)::DownCast(seqRI(1));
1883 //get overridden styled item
1884 getStyledItem(Sh,STool, Styles, override,myMapCompMDGPR);
1886 // get STEP STYLED ITEM
1887 Handle(StepVisual_StyledItem) STEPstyle = Styles.AddStyle ( item, PSA, override );
1888 // create SR, SDR and all necessary references between them and ST, PDS, PSBC, GRC
1889 Styles.CreateNAUOSRD( Context, CDSR, PDS );
1891 // add step styled item of SHUO to the model
1892 // do it by additing styled item to the MDGPR
1893 if ( !aTopSh.IsNull() && !myMapCompMDGPR.IsBound( aTopSh ) ) {
1894 // create MDGPR and record it in model
1896 cout << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance" << endl;
1898 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1899 Styles.CreateMDGPR ( Context, aMDGPR );
1900 if (!aMDGPR.IsNull())
1901 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1903 else if ( !aTopSh.IsNull() && myMapCompMDGPR.IsBound( aTopSh ) ) {
1904 // get MDGPR of the top-level shape
1905 Handle(StepVisual_PresentationRepresentation) aMDGPR =
1906 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1907 // get old styled items to not lose it
1908 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1909 Standard_Integer oldLengthlen = 0;
1910 if (!oldItems.IsNull())
1911 oldLengthlen = oldItems->Length();
1912 // create new array of styled items by an olds and new one
1913 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1914 new StepRepr_HArray1OfRepresentationItem(1, oldLengthlen + 1);
1915 Standard_Integer si;
1916 Standard_Integer el = 1;
1917 for ( si=1; si <= oldLengthlen; si++ )
1918 newItems->SetValue( el++, oldItems->Value( si ) );
1919 newItems->SetValue (el++, STEPstyle);
1920 // init MDGPR be new array of styled items
1921 if (newItems->Length() > 0)
1922 aMDGPR->SetItems( newItems );
1925 WS->Model()->AddWithRefs ( STEPstyle ); // add as root to the model, but it is not good
1927 cout << "Warning: " << __FILE__ << ": adds styled item of SHUO as root, casue cannot find MDGPR" << endl;
1930 // create invisibility item for the styled item
1931 if ( !style.IsVisible() ) {
1932 if (isSetDefaultColor) {
1933 // try to set default color from top-level shape
1935 setDefaultInstanceColor(override, PSA);
1937 // create invisibility item and refer for stiledItem
1938 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1939 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1940 new StepVisual_HArray1OfInvisibleItem (1,1);
1941 // put all style item into the harray
1942 StepVisual_InvisibleItem anInvItem;
1943 anInvItem.SetValue( STEPstyle );
1944 HInvsblItm->SetValue( 1, anInvItem );
1945 Invsblt->Init( HInvsblItm );
1946 WS->Model()->AddWithRefs( Invsblt );
1949 return Standard_True;
1953 //=======================================================================
1954 //function : WriteSHUOs
1956 //=======================================================================
1958 Standard_Boolean STEPCAFControl_Writer::WriteSHUOs (const Handle(XSControl_WorkSession) &WS,
1959 const TDF_LabelSequence &labels )
1961 if ( labels.Length() <=0 ) return Standard_False;
1964 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1965 if (CTool.IsNull() )
1966 return Standard_False;
1967 // map of transfered SHUO
1968 TColStd_MapOfTransient aMapOfMainSHUO;
1969 // Iterate on requested shapes
1970 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1971 TDF_Label L = labels.Value(i);
1972 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1973 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1974 TDF_LabelSequence seq;
1975 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1976 // iterates on components of assembly
1977 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1978 TDF_Label lab = seq(k);
1979 TDF_AttributeSequence anAttrSeq;
1980 CTool->ShapeTool()->GetAllComponentSHUO( lab, anAttrSeq );
1982 for (Standard_Integer j = 1; j <= anAttrSeq.Length(); j++) {
1983 Handle(XCAFDoc_GraphNode) aSHUO =
1984 Handle(XCAFDoc_GraphNode)::DownCast(anAttrSeq.Value( j ));
1985 // take label of SHUO
1986 TDF_Label aSHUOlab = aSHUO->Label();
1987 TDF_LabelSequence aUpLabels;
1988 // check is it SHUO of upper_usage
1989 CTool->ShapeTool()->GetSHUOUpperUsage( aSHUOlab, aUpLabels );
1990 if ( aUpLabels.Length() > 0 )
1991 continue; // transfer only main SHUO
1992 if ( aMapOfMainSHUO.Contains( aSHUO ) )
1993 continue; // do not try to transfer SHUO twice
1994 aMapOfMainSHUO.Add( aSHUO );
1995 // check if it is styled SHUO
1996 XCAFPrs_Style SHUOstyle;
1997 if ( !getSHUOstyle ( aSHUOlab, CTool, SHUOstyle ) ) {
1999 cout << "Warning: " << __FILE__ << ": do not store SHUO without any style to the STEP model" << endl;
2003 // write SHUO to the model amd then add structure type.
2004 TopoDS_Shape NAUOShape; // shape of the deepest NAUO in the SHUO structure
2005 Standard_Boolean isDeepest = Standard_False;
2006 Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO;
2007 Handle(StepBasic_ProductDefinition) aRelatingPD;
2008 // create the top SHUO and all other.
2009 writeSHUO( aSHUO, CTool->ShapeTool(), WS, anEntOfSHUO, NAUOShape, aRelatingPD, isDeepest );
2010 if ( anEntOfSHUO.IsNull() || NAUOShape.IsNull() ) {
2012 cout << "Warning: " << __FILE__ << ": Cannot store SHUO" << endl;
2016 // create new Product Definition Shape for TOP SHUO
2018 cout << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO " << endl;
2020 Handle(StepRepr_ProductDefinitionShape) PDS = new StepRepr_ProductDefinitionShape;
2021 Handle(TCollection_HAsciiString) aPDSname = new TCollection_HAsciiString("SHUO");
2022 Handle(TCollection_HAsciiString) descrStr = new TCollection_HAsciiString("");
2023 StepRepr_CharacterizedDefinition aCharDef;
2024 aCharDef.SetValue( anEntOfSHUO );
2025 PDS->Init( aPDSname, Standard_False, descrStr, aCharDef );
2027 // create styled item for SHUO and add to the model
2028 createSHUOStyledItem ( SHUOstyle, PDS, WS, NAUOShape, CTool->ShapeTool(), myMapCompMDGPR );
2030 } // end work with SHUO
2031 } // end of an assembly components
2032 } // end of IsAssembly case
2033 // nothing to do if it is not assembly
2035 } // end of iterates on indicated labels
2036 return Standard_True;
2040 //=======================================================================
2041 //function : FindPDSforDGT
2042 //purpose : auxilary: find PDS for AdvancedFace or EdgeCurve for creation
2043 // needed ShapeAspect in D> structure
2044 //=======================================================================
2045 static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph,
2046 const Handle(Standard_Transient) &ent,
2047 Handle(StepRepr_ProductDefinitionShape) &PDS,
2048 Handle(StepRepr_RepresentationContext) &RC,
2049 Handle(StepShape_AdvancedFace) &AF,
2050 Handle(StepShape_EdgeCurve) &EC)
2053 return Standard_False;
2054 if( !ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) &&
2055 !ent->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)) )
2056 return Standard_False;
2058 AF = Handle(StepShape_AdvancedFace)::DownCast(ent);
2060 EC = Handle(StepShape_EdgeCurve)::DownCast(ent);
2061 Interface_EntityIterator subs = aGraph.Sharings(EC);
2062 for(subs.Start(); subs.More() && AF.IsNull(); subs.Next()) {
2063 Handle(StepShape_OrientedEdge) OE = Handle(StepShape_OrientedEdge)::DownCast(subs.Value());
2064 if(OE.IsNull()) continue;
2065 Interface_EntityIterator subs1 = aGraph.Sharings(OE);
2066 for(subs1.Start(); subs1.More() && AF.IsNull(); subs1.Next()) {
2067 Handle(StepShape_EdgeLoop) EL = Handle(StepShape_EdgeLoop)::DownCast(subs1.Value());
2068 if(EL.IsNull()) continue;
2069 Interface_EntityIterator subs2 = aGraph.Sharings(EL);
2070 for(subs2.Start(); subs2.More() && AF.IsNull(); subs2.Next()) {
2071 Handle(StepShape_FaceBound) FB = Handle(StepShape_FaceBound)::DownCast(subs2.Value());
2072 if(FB.IsNull()) continue;
2073 Interface_EntityIterator subs3 = aGraph.Sharings(FB);
2074 for(subs3.Start(); subs3.More() && AF.IsNull(); subs3.Next()) {
2075 AF = Handle(StepShape_AdvancedFace)::DownCast(subs3.Value());
2081 if(AF.IsNull()) return Standard_False;
2083 Interface_EntityIterator subs = aGraph.Sharings(AF);
2084 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
2085 Handle(StepShape_ConnectedFaceSet) CFS =
2086 Handle(StepShape_ConnectedFaceSet)::DownCast(subs.Value());
2087 if(CFS.IsNull()) continue;
2088 Interface_EntityIterator subs1 = aGraph.Sharings(CFS);
2089 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
2090 Handle(StepRepr_RepresentationItem) RI =
2091 Handle(StepRepr_RepresentationItem)::DownCast(subs1.Value());
2092 if(RI.IsNull()) continue;
2093 Interface_EntityIterator subs2 = aGraph.Sharings(RI);
2094 for(subs2.Start(); subs2.More() && PDS.IsNull(); subs2.Next()) {
2095 Handle(StepShape_ShapeRepresentation) SR =
2096 Handle(StepShape_ShapeRepresentation)::DownCast(subs2.Value());
2097 if(SR.IsNull()) continue;
2098 RC = SR->ContextOfItems();
2099 Interface_EntityIterator subs3 = aGraph.Sharings(SR);
2100 for(subs3.Start(); subs3.More() && PDS.IsNull(); subs3.Next()) {
2101 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2102 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs3.Value());
2103 if(SDR.IsNull()) continue;
2104 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
2105 if(PropD.IsNull()) continue;
2106 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
2112 return Standard_True;
2115 //=======================================================================
2116 //function : FindPDS
2117 //purpose : auxilary: find Product_definition_shape entity for given entity
2118 //=======================================================================
2119 static Handle(StepRepr_ProductDefinitionShape) FindPDS(const Interface_Graph &theGraph,
2120 const Handle(Standard_Transient) &theEnt,
2121 Handle(StepRepr_RepresentationContext) &theRC)
2123 if (theEnt.IsNull())
2125 Handle(StepRepr_ProductDefinitionShape) aPDS;
2127 // try to find shape_representation in sharings
2128 Interface_EntityIterator anIter = theGraph.Sharings(theEnt);
2129 for (anIter.Start(); anIter.More() && aPDS.IsNull(); anIter.Next()) {
2130 Handle(StepShape_ShapeRepresentation) aSR = Handle(StepShape_ShapeRepresentation)::DownCast(anIter.Value());
2133 theRC = aSR->ContextOfItems();
2134 Interface_EntityIterator aSDRIt = theGraph.Sharings(aSR);
2135 for (aSDRIt.Start(); aSDRIt.More() && aPDS.IsNull(); aSDRIt.Next()) {
2136 Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
2137 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value());
2138 if (aSDR.IsNull()) continue;
2139 Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition();
2140 if (aPropD.IsNull()) continue;
2141 aPDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aPropD);
2147 anIter = theGraph.Sharings(theEnt);
2148 for (anIter.Start(); anIter.More(); anIter.Next()) {
2149 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)) ||
2150 anIter.Value()->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem)))
2152 aPDS = FindPDS(theGraph, anIter.Value(), theRC);
2161 //=======================================================================
2162 //function : GetUnit
2163 //purpose : auxiliary
2164 //=======================================================================
2165 static StepBasic_Unit GetUnit(const Handle(StepRepr_RepresentationContext)& theRC,
2166 const Standard_Boolean isAngle = Standard_False)
2168 StepBasic_Unit aUnit;
2170 Handle(StepBasic_SiUnitAndPlaneAngleUnit) aSiPAU;
2171 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
2172 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
2173 if(!aCtx.IsNull()) {
2174 for(Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) {
2175 if(aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))) {
2176 aSiPAU = Handle(StepBasic_SiUnitAndPlaneAngleUnit)::DownCast(aCtx->UnitsValue(j));
2181 if(aSiPAU.IsNull()) {
2182 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
2183 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
2184 if(!aCtx1.IsNull()) {
2185 for(Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) {
2186 if(aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))) {
2187 aSiPAU = Handle(StepBasic_SiUnitAndPlaneAngleUnit)::DownCast(aCtx1->UnitsValue(j));
2194 aSiPAU = new StepBasic_SiUnitAndPlaneAngleUnit;
2195 aUnit.SetValue(aSiPAU);
2198 Handle(StepBasic_SiUnitAndLengthUnit) aSiLU;
2199 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
2200 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
2201 if(!aCtx.IsNull()) {
2202 for(Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) {
2203 if(aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2204 aSiLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(aCtx->UnitsValue(j));
2209 if(aSiLU.IsNull()) {
2210 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
2211 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
2212 if(!aCtx1.IsNull()) {
2213 for(Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) {
2214 if(aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2215 aSiLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(aCtx1->UnitsValue(j));
2222 aSiLU = new StepBasic_SiUnitAndLengthUnit;
2223 aUnit.SetValue(aSiLU);
2228 //=======================================================================
2229 //function : CreateDimValue
2230 //purpose : auxiliary
2231 //======================================================================
2232 static Handle(StepRepr_ReprItemAndMeasureWithUnit) CreateDimValue(const Standard_Real theValue,
2233 const StepBasic_Unit theUnit,
2234 const Handle(TCollection_HAsciiString)& theName,
2235 const Standard_CString theMeasureName,
2236 const Standard_Boolean isAngle,
2237 const Standard_Boolean isQualified = Standard_False,
2238 const Handle(StepShape_QualifiedRepresentationItem)& theQRI = NULL)
2240 Handle(StepRepr_RepresentationItem) aReprItem = new StepRepr_RepresentationItem();
2241 aReprItem->Init(new TCollection_HAsciiString(theName));
2242 Handle(StepBasic_MeasureWithUnit) aMWU = new StepBasic_MeasureWithUnit();
2243 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
2244 aValueMember->SetName(theMeasureName);
2245 aValueMember->SetReal(theValue);
2246 aMWU->Init(aValueMember, theUnit);
2249 // Angle & with qualifiers
2250 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI) anItem =
2251 new StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI();
2252 anItem->Init(aMWU, aReprItem, theQRI);
2256 // Length & with qualifiers
2257 Handle(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI) anItem =
2258 new StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI();
2259 anItem->Init(aMWU, aReprItem, theQRI);
2265 // Angle & without qualifiers
2266 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) anItem =
2267 new StepRepr_ReprItemAndPlaneAngleMeasureWithUnit();
2268 anItem->Init(aMWU, aReprItem);
2272 // Length & without qualifiers
2273 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) anItem =
2274 new StepRepr_ReprItemAndLengthMeasureWithUnit();
2275 anItem->Init(aMWU, aReprItem);
2281 //=======================================================================
2282 //function : WriteShapeAspect
2283 //purpose : auxiliary (write Shape_Aspect entity for given shape)
2284 //=======================================================================
2286 Handle(StepRepr_ShapeAspect) STEPCAFControl_Writer::WriteShapeAspect (const Handle(XSControl_WorkSession) &WS,
2287 const TDF_Label theLabel,
2288 const TopoDS_Shape theShape,
2289 Handle(StepRepr_RepresentationContext)& theRC,
2290 Handle(StepAP242_GeometricItemSpecificUsage)& theGISU)
2293 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2294 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
2295 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
2296 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2297 if (aHGraph.IsNull())
2299 Interface_Graph aGraph = aHGraph->Graph();
2301 TopLoc_Location aLoc;
2302 TColStd_SequenceOfTransient aSeqRI;
2303 FindEntities( FP, theShape, aLoc, aSeqRI );
2304 if ( aSeqRI.Length() <= 0 ) {
2305 FP->Messenger() << "Warning: Cannot find RI for "<<theShape.TShape()->DynamicType()->Name()<<endl;
2309 Handle(StepRepr_ProductDefinitionShape) aPDS;
2310 Handle(StepRepr_RepresentationContext) aRC;
2311 Handle(Standard_Transient) anEnt = aSeqRI.Value(1);
2312 aPDS = FindPDS(aGraph, anEnt, aRC);
2318 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString();
2319 Handle(TDataStd_Name) aNameAttr;
2320 if (theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) {
2321 aName = new TCollection_HAsciiString(TCollection_AsciiString(aNameAttr->Get(), '?'));
2322 Standard_Integer aFirstSpace = aName->Search(" ");
2323 if (aFirstSpace != -1)
2324 aName = aName->SubString(aFirstSpace + 1, aName->Length());
2326 aName = new TCollection_HAsciiString();
2328 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString();
2329 Handle(StepRepr_ShapeAspect) aSA = new StepRepr_ShapeAspect;
2330 aSA->Init(aName, aDescription, aPDS, StepData_LTrue);
2332 // Geometric_Item_Specific_Usage
2333 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2334 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2335 aDefinition.SetValue(aSA);
2336 Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
2337 Handle(StepRepr_RepresentationItem) anIdentifiedItem = Handle(StepRepr_RepresentationItem)::DownCast(anEnt);
2338 anReprItems->SetValue(1, anIdentifiedItem);
2339 Interface_EntityIterator subs = aGraph.Sharings(aPDS);
2340 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2341 for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) {
2342 Handle(Standard_Transient) anEntity = subs.Value();
2343 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity);
2348 // Set entities to model
2349 aGISU->Init(aName, aDescription, aDefinition, aSDR->UsedRepresentation(), anReprItems);
2350 Model->AddWithRefs(aSA);
2351 Model->AddWithRefs(aGISU);
2356 //=======================================================================
2357 //function : WritePresentation
2358 //purpose : auxiliary (write annotation plane and presentation)
2359 //======================================================================
2360 void STEPCAFControl_Writer::WritePresentation(const Handle(XSControl_WorkSession) &WS,
2361 const TopoDS_Shape thePresentation,
2362 const Handle(TCollection_HAsciiString)& thePrsName,
2363 const Standard_Boolean hasSemantic,
2364 const Standard_Boolean hasPlane,
2365 const gp_Ax2 theAnnotationPlane,
2366 const gp_Pnt theTextPosition,
2367 const Handle(Standard_Transient) theDimension)
2369 if (thePresentation.IsNull())
2372 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2375 Handle(StepVisual_TessellatedGeometricSet) aGeomSet = STEPCAFControl_GDTProperty::GetTessellation(thePresentation);
2376 Handle(StepVisual_TessellatedAnnotationOccurrence) aTAO = new StepVisual_TessellatedAnnotationOccurrence();
2377 aTAO->Init(new TCollection_HAsciiString(), myGDTPrsCurveStyle, aGeomSet);
2378 StepVisual_DraughtingCalloutElement aDCElement;
2379 aDCElement.SetValue(aTAO);
2380 Handle(StepVisual_HArray1OfDraughtingCalloutElement) aTAOs = new StepVisual_HArray1OfDraughtingCalloutElement(1, 1);
2381 aTAOs->SetValue(1, aDCElement);
2382 Handle(StepVisual_DraughtingCallout) aDCallout = new StepVisual_DraughtingCallout();
2383 Handle(TCollection_HAsciiString) aPrsName = thePrsName.IsNull() ? new TCollection_HAsciiString() : thePrsName;
2384 aDCallout->Init(aPrsName, aTAOs);
2385 Handle(StepRepr_HArray1OfRepresentationItem) aDCsForDMIA = new StepRepr_HArray1OfRepresentationItem(1, 1);
2386 aDCsForDMIA->SetValue(1, aDCallout);
2387 myGDTAnnotations.Append(aDCallout);
2388 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDimension;
2389 aDimension.SetValue(theDimension);
2390 Handle(TCollection_HAsciiString) aDMIAName;
2392 aDMIAName = new TCollection_HAsciiString("PMI representation to presentation link");
2394 aDMIAName = new TCollection_HAsciiString();
2395 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
2396 new StepAP242_DraughtingModelItemAssociation();
2397 aDMIA->Init(aDMIAName, new TCollection_HAsciiString(), aDimension, myGDTPresentationDM, aDCsForDMIA);
2398 aModel->AddWithRefs(aDMIA);
2404 // Presentation Style
2405 Handle(StepVisual_NullStyleMember) aNullStyle = new StepVisual_NullStyleMember();
2406 aNullStyle->SetEnumText(0, ".NULL.");
2407 StepVisual_PresentationStyleSelect aStyleItem;
2408 aStyleItem.SetValue(aNullStyle);
2409 Handle(StepVisual_HArray1OfPresentationStyleSelect) aStyles = new StepVisual_HArray1OfPresentationStyleSelect(1, 1);
2410 aStyles->SetValue(1, aStyleItem);
2411 Handle(StepVisual_PresentationStyleAssignment) aPrsStyle = new StepVisual_PresentationStyleAssignment();
2412 aPrsStyle->Init(aStyles);
2413 Handle(StepVisual_HArray1OfPresentationStyleAssignment) aPrsStyles =
2414 new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
2415 aPrsStyles->SetValue(1, aPrsStyle);
2417 Handle(StepGeom_Plane) aPlane = new StepGeom_Plane();
2418 GeomToStep_MakeAxis2Placement3d anAxisMaker(theAnnotationPlane);
2419 Handle(StepGeom_Axis2Placement3d) anAxis = anAxisMaker.Value();
2420 // Set text position to plane origin
2421 Handle(StepGeom_CartesianPoint) aTextPos = new StepGeom_CartesianPoint();
2422 Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
2423 for (Standard_Integer i = 1; i <= 3; i++)
2424 aCoords->SetValue(i, theTextPosition.Coord(i));
2425 aTextPos->Init(new TCollection_HAsciiString(), aCoords);
2426 anAxis->SetLocation(aTextPos);
2427 aPlane->Init(new TCollection_HAsciiString(), anAxis);
2428 // Annotation plane element
2429 StepVisual_AnnotationPlaneElement aPlaneElement;
2430 aPlaneElement.SetValue(aDCallout);
2431 Handle(StepVisual_HArray1OfAnnotationPlaneElement) aDCsForAnnPln = new StepVisual_HArray1OfAnnotationPlaneElement(1, 1);
2432 aDCsForAnnPln->SetValue(1, aPlaneElement);
2433 // Init AnnotationPlane entity
2434 Handle(StepVisual_AnnotationPlane) anAnnPlane = new StepVisual_AnnotationPlane();
2435 anAnnPlane->Init(new TCollection_HAsciiString(), aPrsStyles, aPlane, aDCsForAnnPln);
2436 myGDTAnnotations.Append(anAnnPlane);
2437 aModel->AddWithRefs(anAnnPlane);
2440 //=======================================================================
2441 //function : WriteDatumAP242
2442 //purpose : auxiliary (write Datum entity for given shape or write all
2443 // necessary entities and link them to already written datum
2444 // in case of multiple features association)
2445 //=======================================================================
2446 Handle(StepDimTol_Datum) STEPCAFControl_Writer::WriteDatumAP242(const Handle(XSControl_WorkSession) &WS,
2447 const TDF_LabelSequence theShapeL,
2448 const TDF_Label theDatumL,
2449 const Standard_Boolean isFirstDTarget,
2450 const Handle(StepDimTol_Datum) theWrittenDatum)
2453 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2454 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
2455 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
2456 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2457 if (aHGraph.IsNull())
2459 Interface_Graph aGraph = aHGraph->Graph();
2461 Handle(StepRepr_ShapeAspect) aSA;
2462 Handle(StepRepr_RepresentationContext) aRC;
2463 Handle(StepRepr_ProductDefinitionShape) aPDS;
2464 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSASeq;
2465 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2466 Standard_Integer aSANum = 0, aGISUNum = 0;
2467 // Link with datum feature
2468 for (Standard_Integer i = 1; i <= theShapeL.Length(); i++) {
2469 Handle(Standard_Transient) anEnt;
2470 TopoDS_Shape aShape;
2471 TopLoc_Location aLoc;
2472 TColStd_SequenceOfTransient aSeqRI;
2474 aShape = XCAFDoc_ShapeTool::GetShape(theShapeL.Value(i));
2475 FindEntities(FP, aShape, aLoc, aSeqRI);
2476 if (aSeqRI.Length() <= 0) {
2477 FP->Messenger() << "Warning: Cannot find RI for " << aShape.TShape()->DynamicType()->Name() << endl;
2480 anEnt = aSeqRI.Value(1);
2481 aPDS = FindPDS(aGraph, anEnt, aRC);
2485 Handle(StepRepr_ShapeAspect) aCurrentSA = WriteShapeAspect(WS, theDatumL, aShape, aRC, aGISU);
2486 if (aCurrentSA.IsNull())
2488 aSASeq.Append(aCurrentSA);
2489 aSANum = Model->Number(aCurrentSA);
2490 aGISUNum = Model->Number(aGISU);
2492 if (aPDS.IsNull()) {
2493 // Workaround for datums without shape
2494 aPDS = myGDTCommonPDS;
2495 Interface_EntityIterator aSDRIt = aGraph.Sharings(aPDS);
2496 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2497 for (aSDRIt.Start(); aSDRIt.More() && aSDR.IsNull(); aSDRIt.Next())
2498 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value());
2499 if (!aSDR.IsNull()) {
2500 Handle(StepRepr_Representation) aRepr = aSDR->UsedRepresentation();
2501 if (!aRepr.IsNull())
2502 aRC = aRepr->ContextOfItems();
2507 // Find if datum has datum targets and get common datum attributes
2508 Handle(XCAFDoc_Datum) aDatumAttr;
2509 if (!theDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
2511 Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject();
2512 if (anObject.IsNull())
2514 Standard_Boolean isSimpleDatum = !anObject->IsDatumTarget();
2515 Handle(TCollection_HAsciiString) anIdentifier = anObject->GetName();
2516 Handle(TCollection_HAsciiString) aTargetId = (anObject->GetDatumTargetNumber() == 0 ?
2517 new TCollection_HAsciiString() : new TCollection_HAsciiString(anObject->GetDatumTargetNumber()));
2519 // If datum type is area, but there is no area in object, write as simple datum
2520 if (anObject->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Area &&
2521 anObject->GetDatumTarget().IsNull())
2522 isSimpleDatum = Standard_True;
2525 if (isSimpleDatum) {
2526 if (aSASeq.Length() == 0) {
2527 // Create empty datum with name and presentation only
2528 Handle(StepDimTol_DatumFeature) aDF = new StepDimTol_DatumFeature();
2529 aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue);
2531 Model->AddWithRefs(aDF);
2533 else if (aSASeq.Length() == 1) {
2534 Handle(StepDimTol_DatumFeature) aDF = new StepDimTol_DatumFeature();
2535 aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue);
2536 Model->ReplaceEntity(aSANum, aDF);
2538 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2539 aDefinition.SetValue(aDF);
2540 aGISU->SetDefinition(aDefinition);
2541 Model->ReplaceEntity(aGISUNum, aGISU);
2543 else if (aSASeq.Length() > 1) {
2544 Handle(StepRepr_CompShAspAndDatumFeatAndShAsp) aDF = new StepRepr_CompShAspAndDatumFeatAndShAsp();
2545 aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue);
2546 for (Standard_Integer i = 1; i <= aSASeq.Length(); i++) {
2547 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
2548 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDF, aSASeq.Value(i));
2549 Model->AddWithRefs(aSAR);
2552 Model->AddWithRefs(aDF);
2555 // Datum with datum targets
2557 XCAFDimTolObjects_DatumTargetType aDatumType = anObject->GetDatumTargetType();
2558 Handle(StepDimTol_DatumTarget) aDatumTarget;
2559 // Note: the given way to write such datum type may be incorrect (too little information)
2560 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Area) {
2561 TopoDS_Shape aDTShape = anObject->GetDatumTarget();
2562 Handle(StepAP242_GeometricItemSpecificUsage) anAreaGISU;
2563 Handle(StepRepr_ShapeAspect) anAreaSA = WriteShapeAspect(WS, theDatumL, aDTShape, aRC, anAreaGISU);
2564 aSANum = Model->Number(anAreaSA);
2565 aGISUNum = Model->Number(anAreaGISU);
2566 Handle(StepDimTol_DatumTarget) aDT = new StepDimTol_DatumTarget();
2567 aDT->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString("area"), anAreaSA->OfShape(),
2568 StepData_LTrue, aTargetId);
2569 Model->ReplaceEntity(aSANum, aDT);
2570 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2571 aDefinition.SetValue(aDT);
2572 anAreaGISU->SetDefinition(aDefinition);
2573 Model->ReplaceEntity(aGISUNum, anAreaGISU);
2576 Handle(StepDimTol_PlacedDatumTargetFeature) aPDTF = new StepDimTol_PlacedDatumTargetFeature();
2577 aPDTF->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDatumTargetName(aDatumType),
2578 aPDS, StepData_LTrue, aTargetId);
2579 Model->AddWithRefs(aPDTF);
2580 aDatumTarget = aPDTF;
2582 Handle(StepRepr_PropertyDefinition) aPD = new StepRepr_PropertyDefinition();
2583 StepRepr_CharacterizedDefinition aCDefinition;
2584 aCDefinition.SetValue(aPDTF);
2585 aPD->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCDefinition);
2586 if (anObject->HasDatumTargetParams()) {
2587 // write all parameters of datum target
2588 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP = new StepShape_ShapeRepresentationWithParameters();
2589 // Common for all datum targets
2590 StepBasic_Unit aUnit = GetUnit(aRC);
2591 gp_Ax2 aDTAxis = anObject->GetDatumTargetAxis();
2592 GeomToStep_MakeAxis2Placement3d anAxisMaker(aDTAxis);
2593 Handle(StepGeom_Axis2Placement3d) anA2P3D = anAxisMaker.Value();
2594 anA2P3D->SetName(new TCollection_HAsciiString("orientation"));
2595 Handle(StepRepr_HArray1OfRepresentationItem) anItems;
2596 // Process each datum target type
2597 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Point) {
2598 anItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
2601 Handle(TCollection_HAsciiString) aTargetValueName;
2602 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Line) {
2603 anItems = new StepRepr_HArray1OfRepresentationItem(1, 2);
2604 aTargetValueName = new TCollection_HAsciiString("target length");
2606 else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Rectangle) {
2607 anItems = new StepRepr_HArray1OfRepresentationItem(1, 3);
2608 aTargetValueName = new TCollection_HAsciiString("target length");
2610 Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue = CreateDimValue(anObject->GetDatumTargetWidth(),
2611 aUnit, new TCollection_HAsciiString("target width"), "POSITIVE_LENGTH_MEASURE", Standard_False);
2612 anItems->SetValue(2, aTargetValue);
2613 Model->AddWithRefs(aTargetValue);
2615 else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Circle) {
2616 anItems = new StepRepr_HArray1OfRepresentationItem(1, 2);
2617 aTargetValueName = new TCollection_HAsciiString("target diameter");
2620 Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue = CreateDimValue(anObject->GetDatumTargetLength(),
2621 aUnit, aTargetValueName, "POSITIVE_LENGTH_MEASURE", Standard_False);
2622 anItems->SetValue(1, aTargetValue);
2623 Model->AddWithRefs(aTargetValue);
2625 anItems->SetValue(anItems->Length(), anA2P3D);
2626 aSRWP->Init(new TCollection_HAsciiString(), anItems, aRC);
2627 // Create and write auxiliary entities
2628 Handle(StepShape_ShapeDefinitionRepresentation) aSDR = new StepShape_ShapeDefinitionRepresentation();
2629 StepRepr_RepresentedDefinition aRDefinition;
2630 aRDefinition.SetValue(aPD);
2631 aSDR->Init(aRDefinition, aSRWP);
2632 Model->AddWithRefs(aPD);
2633 Model->AddWithRefs(aSRWP);
2634 Model->AddWithRefs(aSDR);
2637 // Link datum target to datum feature
2638 // if aSASeq.Length() == 0 nothing to do
2639 if (aSASeq.Length() == 1) {
2640 Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR = new StepRepr_FeatureForDatumTargetRelationship();
2641 aFFDTR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aSASeq.Value(1), aDatumTarget);
2642 Model->AddWithRefs(aFFDTR);
2644 else if (aSASeq.Length() > 1) {
2645 Handle(StepRepr_CompositeShapeAspect) aCompSA = new StepRepr_CompositeShapeAspect();
2646 aCompSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, aSASeq.Value(1)->ProductDefinitional());
2647 for (Standard_Integer i = 1; i <= aSASeq.Length(); i++) {
2648 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
2649 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCompSA, aSASeq.Value(i));
2650 Model->AddWithRefs(aSAR);
2652 Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR = new StepRepr_FeatureForDatumTargetRelationship();
2653 aFFDTR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCompSA, aDatumTarget);
2654 Model->AddWithRefs(aFFDTR);
2660 Handle(StepDimTol_Datum) aDatum = theWrittenDatum;
2661 if (isFirstDTarget) {
2662 aDatum = new StepDimTol_Datum();
2663 aDatum->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LFalse, anIdentifier);
2664 Model->AddWithRefs(aDatum);
2667 // Shape_Aspect_Relationship
2668 if (!aSA.IsNull()) {
2669 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
2670 aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aSA, aDatum);
2671 Model->AddWithRefs(aSAR);
2674 //Annotation plane and Presentation
2675 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(),
2676 anObject->GetPlane(), anObject->GetPointTextAttach(), aSA);
2681 //=======================================================================
2682 //function : WriteDimValues
2683 //purpose : auxiliary (write all data for given dimension: values,
2684 // qualifiers, modifiers, orientation and tolerance class)
2685 //======================================================================
2686 static void WriteDimValues(const Handle(XSControl_WorkSession) &WS,
2687 const Handle(XCAFDimTolObjects_DimensionObject) theObject,
2688 const Handle(StepRepr_RepresentationContext) theRC,
2689 const StepShape_DimensionalCharacteristic theDimension)
2692 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2693 XCAFDimTolObjects_DimensionModifiersSequence aModifiers = theObject->GetModifiers();
2694 Handle(Standard_Transient) aDim = theDimension.Value();
2695 Standard_Boolean isAngle = aDim->IsKind(STANDARD_TYPE(StepShape_AngularLocation)) ||
2696 aDim->IsKind(STANDARD_TYPE(StepShape_AngularSize));
2699 StepBasic_Unit aUnit = GetUnit(theRC, isAngle);
2700 Standard_CString aMeasureName;
2702 aMeasureName = "POSITIVE_PLANE_ANGLE_MEASURE";
2704 aMeasureName = "POSITIVE_LENGTH_MEASURE";
2707 Handle(StepRepr_HArray1OfRepresentationItem) aValues;
2708 Standard_Integer aNbItems = 1, aValIt = 1;
2709 if (theObject->IsDimWithRange())
2711 if (aModifiers.Length() > 0)
2713 if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented)
2715 aNbItems += theObject->NbDescriptions();
2716 aValues = new StepRepr_HArray1OfRepresentationItem(1, aNbItems);
2719 Standard_Real aNominal = theObject->GetValue();
2720 Standard_Integer aLeftNbDigits, aRightNbDigits;
2721 theObject->GetNbOfDecimalPlaces(aLeftNbDigits, aRightNbDigits);
2722 Standard_Integer aNbQualifiers = 0;
2723 if (theObject->HasQualifier() && !isAngle)
2725 if (aLeftNbDigits > 0 || aRightNbDigits > 0)
2728 if (aNbQualifiers > 0) {
2729 Handle(StepShape_QualifiedRepresentationItem) aQRI = new StepShape_QualifiedRepresentationItem();
2730 Handle(StepShape_HArray1OfValueQualifier) aQualifiers = new StepShape_HArray1OfValueQualifier(1, aNbQualifiers);
2732 if (theObject->HasQualifier() && !isAngle) {
2733 StepShape_ValueQualifier anItem;
2734 Handle(StepShape_TypeQualifier) aType = new StepShape_TypeQualifier();
2735 XCAFDimTolObjects_DimensionQualifier aQualifier = theObject->GetQualifier();
2736 aType->Init(STEPCAFControl_GDTProperty::GetDimQualifierName(aQualifier));
2737 aModel->AddWithRefs(aType);
2738 anItem.SetValue(aType);
2739 aQualifiers->SetValue(1, anItem);
2741 // Number of decimal places
2742 if (aLeftNbDigits > 0 || aRightNbDigits > 0) {
2743 StepShape_ValueQualifier anItem;
2744 Handle(StepShape_ValueFormatTypeQualifier) aType = new StepShape_ValueFormatTypeQualifier();
2745 Handle(TCollection_HAsciiString) aFormatType = new TCollection_HAsciiString("NR2 ");
2746 aFormatType->AssignCat(new TCollection_HAsciiString(aLeftNbDigits));
2747 aFormatType->AssignCat(new TCollection_HAsciiString("."));
2748 aFormatType->AssignCat(new TCollection_HAsciiString(aRightNbDigits));
2749 aType->Init(aFormatType);
2750 aModel->AddWithRefs(aType);
2751 anItem.SetValue(aType);
2752 aQualifiers->SetValue(aNbQualifiers, anItem);
2755 aQRI->SetQualifiers(aQualifiers);
2756 Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
2757 new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle, Standard_True, aQRI);
2758 aValues->SetValue(aValIt, anItem);
2761 // Without qualifiers
2763 Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
2764 new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle);
2765 aValues->SetValue(aValIt, anItem);
2770 if (theObject->IsDimWithRange()) {
2771 Handle(StepRepr_ReprItemAndMeasureWithUnit) aLowerItem = CreateDimValue(theObject->GetLowerBound(), aUnit,
2772 new TCollection_HAsciiString("lower limit"), aMeasureName, isAngle);
2773 Handle(StepRepr_ReprItemAndMeasureWithUnit) anUpperItem = CreateDimValue(theObject->GetUpperBound(), aUnit,
2774 new TCollection_HAsciiString("upper limit"), aMeasureName, isAngle);
2775 aValues->SetValue(aValIt, aLowerItem);
2777 aValues->SetValue(aValIt, anUpperItem);
2782 if (aModifiers.Length() > 0) {
2783 Handle(StepRepr_CompoundRepresentationItem) aCompoundRI = new StepRepr_CompoundRepresentationItem();
2784 Handle (StepRepr_HArray1OfRepresentationItem) aModifItems =
2785 new StepRepr_HArray1OfRepresentationItem(1, aModifiers.Length());
2786 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) {
2787 XCAFDimTolObjects_DimensionModif aModif = aModifiers.Value(i);
2788 Handle(StepRepr_DescriptiveRepresentationItem) aModifItem =
2789 new StepRepr_DescriptiveRepresentationItem();
2790 aModifItem->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDimModifierName(aModif));
2791 aModel->AddWithRefs(aModifItem);
2792 aModifItems->SetValue(i, aModifItem);
2794 aCompoundRI->Init(new TCollection_HAsciiString(), aModifItems);
2795 aValues->SetValue(aValIt, aCompoundRI);
2800 if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented) {
2801 Handle(StepGeom_Axis2Placement3d) anOrientation = new StepGeom_Axis2Placement3d();
2803 theObject->GetDirection(aDir);
2804 GeomToStep_MakeCartesianPoint MkPoint(gp_Pnt(0, 0, 0));
2805 Handle(StepGeom_CartesianPoint) aLoc = MkPoint.Value();
2806 Handle(StepGeom_Direction) anAxis = new StepGeom_Direction();
2807 Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
2808 aCoords->SetValue(1, aDir.X());
2809 aCoords->SetValue(2, aDir.Y());
2810 aCoords->SetValue(3, aDir.Z());
2811 anAxis->Init(new TCollection_HAsciiString(), aCoords);
2812 anOrientation->Init(new TCollection_HAsciiString("orientation"), aLoc, Standard_True, anAxis, Standard_False, NULL);
2813 aValues->SetValue(aValIt, anOrientation);
2818 if (theObject->HasDescriptions()) {
2819 for (Standard_Integer i = 0; i < theObject->NbDescriptions(); i++) {
2820 Handle(StepRepr_DescriptiveRepresentationItem) aDRI = new StepRepr_DescriptiveRepresentationItem();
2821 aDRI->Init(theObject->GetDescriptionName(i), theObject->GetDescription(i));
2822 aValues->SetValue(aValIt, aDRI);
2827 for (Standard_Integer i = 1; i <= aValues->Length(); i++)
2828 aModel->AddWithRefs(aValues->Value(i));
2830 // Create resulting Shape_Dimension_Representation
2831 Handle(StepShape_ShapeDimensionRepresentation) aSDR = new StepShape_ShapeDimensionRepresentation();
2832 aSDR->Init(new TCollection_HAsciiString(), aValues, theRC);
2833 aModel->AddWithRefs(aSDR);
2834 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR = new StepShape_DimensionalCharacteristicRepresentation();
2835 aDCR->Init(theDimension, aSDR);
2836 aModel->AddWithRefs(aDCR);
2838 // Plus_Minus_Tolerance
2839 if (theObject->IsDimWithPlusMinusTolerance()) {
2840 Handle(TCollection_HAsciiString) aDummyName = new TCollection_HAsciiString(aMeasureName);
2841 aDummyName = aDummyName->SubString(9, aDummyName->Length()); //delete "POSITIVE_"
2842 aMeasureName = aDummyName->ToCString();
2843 Standard_Real aLowerTolValue = -theObject->GetLowerTolValue(),
2844 anUpperTolValue = theObject->GetUpperTolValue();
2846 Handle(StepBasic_MeasureWithUnit) anUpperMWU = new StepBasic_MeasureWithUnit();
2847 Handle(StepBasic_MeasureValueMember) anUpperValue = new StepBasic_MeasureValueMember();
2848 anUpperValue->SetName(aMeasureName);
2849 anUpperValue->SetReal(anUpperTolValue);
2850 anUpperMWU->Init(anUpperValue, aUnit);
2851 aModel->AddWithRefs(anUpperMWU);
2853 Handle(StepBasic_MeasureWithUnit) aLowerMWU = new StepBasic_MeasureWithUnit();
2854 Handle(StepBasic_MeasureValueMember) aLowerValue = new StepBasic_MeasureValueMember();
2855 aLowerValue->SetName(aMeasureName);
2856 aLowerValue->SetReal(aLowerTolValue);
2857 aLowerMWU->Init(aLowerValue, aUnit);
2858 aModel->AddWithRefs(aLowerMWU);
2860 Handle(StepShape_ToleranceValue) aTolValue = new StepShape_ToleranceValue();
2861 aTolValue->Init(aLowerMWU, anUpperMWU);
2862 aModel->AddWithRefs(aTolValue);
2863 StepShape_ToleranceMethodDefinition aMethod;
2864 aMethod.SetValue(aTolValue);
2865 Handle(StepShape_PlusMinusTolerance) aPlusMinusTol = new StepShape_PlusMinusTolerance();
2866 aPlusMinusTol->Init(aMethod, theDimension);
2867 aModel->AddWithRefs(aPlusMinusTol);
2870 if (theObject->IsDimWithClassOfTolerance()) {
2871 Standard_Boolean isHole;
2872 XCAFDimTolObjects_DimensionFormVariance aFormVariance;
2873 XCAFDimTolObjects_DimensionGrade aGrade;
2874 if (!theObject->GetClassOfTolerance(isHole, aFormVariance, aGrade))
2876 Handle(StepShape_LimitsAndFits) aLAF = STEPCAFControl_GDTProperty::GetLimitsAndFits(isHole, aFormVariance, aGrade);
2877 aModel->AddWithRefs(aLAF);
2878 StepShape_ToleranceMethodDefinition aMethod;
2879 aMethod.SetValue(aLAF);
2880 Handle(StepShape_PlusMinusTolerance) aPlusMinusTol = new StepShape_PlusMinusTolerance();
2881 aPlusMinusTol->Init(aMethod, theDimension);
2882 aModel->AddWithRefs(aPlusMinusTol);
2886 //=======================================================================
2887 //function : WriteDerivedGeometry
2888 //purpose : auxiliary (write connection point for dimensions)
2889 //======================================================================
2890 static void WriteDerivedGeometry (const Handle(XSControl_WorkSession) &WS,
2891 const Handle(XCAFDimTolObjects_DimensionObject)& theObject,
2892 const Handle(StepRepr_ConstructiveGeometryRepresentation) theRepr,
2893 Handle(StepRepr_ShapeAspect)& theFirstSA,
2894 Handle(StepRepr_ShapeAspect)& theSecondSA,
2895 NCollection_Vector<Handle(StepGeom_CartesianPoint)>& thePnts)
2897 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2899 if (theObject->HasPoint()) {
2900 GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint());
2901 Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
2902 thePnts.Append(aPoint);
2903 Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
2904 aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse);
2905 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2906 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2907 aDefinition.SetValue(aDSA);
2908 Handle(StepRepr_HArray1OfRepresentationItem) anItem = new StepRepr_HArray1OfRepresentationItem(1, 1);
2909 anItem->SetValue(1, aPoint);
2910 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDefinition, theRepr, anItem);
2911 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = new StepRepr_ShapeAspectDerivingRelationship();
2912 aSADR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDSA, theFirstSA);
2914 aModel->AddWithRefs(aGISU);
2915 aModel->AddWithRefs(aSADR);
2918 // Second point (for locations)
2919 if (theObject->HasPoint2()) {
2920 GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint2());
2921 Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
2922 thePnts.Append(aPoint);
2923 Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
2924 aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse);
2925 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2926 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2927 aDefinition.SetValue(aDSA);
2928 Handle(StepRepr_HArray1OfRepresentationItem) anItem = new StepRepr_HArray1OfRepresentationItem(1, 1);
2929 anItem->SetValue(1, aPoint);
2930 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDefinition, theRepr, anItem);
2931 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = new StepRepr_ShapeAspectDerivingRelationship();
2932 aSADR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDSA, theSecondSA);
2934 aModel->AddWithRefs(aGISU);
2935 aModel->AddWithRefs(aSADR);
2939 //=======================================================================
2940 //function : WriteDatumSystem
2941 //purpose : auxiliary (write Write datum system for given
2942 // geometric_tolerance)
2943 //======================================================================
2944 static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const Handle(XSControl_WorkSession) &WS,
2945 const TDF_Label theGeomTolL,
2946 const TDF_LabelSequence theDatumSeq,
2947 const STEPConstruct_DataMapOfAsciiStringTransient theDatumMap,
2948 const Handle(StepRepr_RepresentationContext)& theRC)
2951 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2952 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2953 if (aHGraph.IsNull())
2955 Interface_Graph aGraph = aHGraph->Graph();
2956 Handle(XCAFDoc_GeomTolerance) aGTAttr;
2957 if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr))
2959 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
2960 if (anObject.IsNull())
2964 StepBasic_Unit aUnit = GetUnit(theRC);
2966 XCAFDimTolObjects_DatumObjectSequence aDatums;
2967 Standard_Integer aMaxDatumNum = 0;
2968 for (Standard_Integer i = 1; i <= theDatumSeq.Length(); i++) {
2969 Handle(XCAFDoc_Datum) aDatumAttr;
2970 if (!theDatumSeq.Value(i).FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
2972 Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject();
2973 if (aDatumObj.IsNull())
2975 aDatums.Append(aDatumObj);
2976 aMaxDatumNum = Max(aMaxDatumNum, aDatumObj->GetPosition());
2978 if (aMaxDatumNum == 0)
2981 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aConstituents =
2982 new StepDimTol_HArray1OfDatumReferenceCompartment(1, aMaxDatumNum);
2983 // Auxiliary datum to initialize attributes in Datum_System
2984 Handle(StepDimTol_Datum) aFirstDatum;
2985 Standard_Integer aConstituentsNum = 0;
2986 for (Standard_Integer i = 1; i <= aMaxDatumNum; i++) {
2987 // Collect datums with i-th position
2988 XCAFDimTolObjects_DatumObjectSequence aDatumSeqPos;
2989 for (Standard_Integer j = 1; j <= aDatums.Length(); j++)
2990 if (aDatums.Value(j)->GetPosition() == i)
2991 aDatumSeqPos.Append(aDatums.Value(j));
2992 if (aDatumSeqPos.Length() < 1)
2996 // Initialize Datum_Reference_Compartment
2997 StepDimTol_DatumOrCommonDatum aDatumRef;
2998 Handle(StepDimTol_DatumReferenceCompartment) aCompartment =
2999 new StepDimTol_DatumReferenceCompartment();
3000 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifiers;
3001 if (aDatumSeqPos.Length() == 1) {
3003 Handle(Standard_Transient) aFDValue;
3004 if (theDatumMap.Find(aDatumSeqPos.Value(1)->GetName()->String(), aFDValue) && !aFDValue.IsNull())
3005 aFirstDatum = Handle(StepDimTol_Datum)::DownCast (aFDValue);
3006 aDatumRef.SetValue(aFirstDatum);
3008 XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(1)->GetModifiers();
3009 XCAFDimTolObjects_DatumModifWithValue aModifWithVal;
3010 Standard_Real aValue = 0;
3011 aDatumSeqPos.Value(1)->GetModifierWithValue(aModifWithVal, aValue);
3012 aModifiers = STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit);
3013 // Add Datum_Reference_Modifier_With_Value
3014 if (!aModifiers.IsNull()) {
3015 Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV =
3016 aModifiers->Value(aModifiers->Length()).DatumReferenceModifierWithValue();
3017 if (!aDRMWV.IsNull()) {
3018 Model->AddWithRefs(aDRMWV);
3023 Handle(StepDimTol_HArray1OfDatumReferenceElement) aCommonDatumList = new StepDimTol_HArray1OfDatumReferenceElement(1, aDatumSeqPos.Length());
3024 for (Standard_Integer j = 1; j <= aDatumSeqPos.Length(); j++) {
3026 Handle(StepDimTol_Datum) aDatum;
3027 Handle(Standard_Transient) aDValue;
3028 if (theDatumMap.Find(aDatumSeqPos.Value(j)->GetName()->String(), aDValue))
3029 aDatum = Handle(StepDimTol_Datum)::DownCast (aDValue);
3030 StepDimTol_DatumOrCommonDatum anElemDatumRef;
3031 anElemDatumRef.SetValue(aDatum);
3032 if (aFirstDatum.IsNull())
3033 aFirstDatum = aDatum;
3035 XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(j)->GetModifiers();
3036 XCAFDimTolObjects_DatumModifWithValue aModifWithVal;
3037 Standard_Real aValue = 0;
3038 aDatumSeqPos.Value(j)->GetModifierWithValue(aModifWithVal, aValue);
3039 Handle(StepDimTol_HArray1OfDatumReferenceModifier) anElemModifiers =
3040 STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit);
3041 // Add Datum_Reference_Modifier_With_Value
3042 if (!anElemModifiers.IsNull()) {
3043 Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV =
3044 anElemModifiers->Value(anElemModifiers->Length()).DatumReferenceModifierWithValue();
3045 if (!aDRMWV.IsNull()) {
3046 Model->AddWithRefs(aDRMWV);
3049 // Datum_Reference_Element
3050 Handle(StepDimTol_DatumReferenceElement) anElement = new StepDimTol_DatumReferenceElement();
3051 anElement->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDatum->OfShape(),
3052 aDatum->ProductDefinitional(), anElemDatumRef, !anElemModifiers.IsNull(), anElemModifiers);
3053 Model->AddWithRefs(anElement);
3054 aCommonDatumList->SetValue(j, anElement);
3056 aDatumRef.SetValue(aCommonDatumList);
3058 aCompartment->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(),
3059 aFirstDatum->ProductDefinitional(), aDatumRef, !aModifiers.IsNull(), aModifiers);
3060 Model->AddWithRefs(aCompartment);
3061 aConstituents->SetValue(aConstituentsNum, aCompartment);
3063 // Remove null elements from aConstituents
3064 Standard_Integer aNbConstituents = 0;
3065 for (Standard_Integer i = 1; i <= aConstituents->Length(); i++)
3066 if (!aConstituents->Value(i).IsNull())
3068 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aResConstituents =
3069 new StepDimTol_HArray1OfDatumReferenceCompartment(1, aNbConstituents);
3070 Standard_Integer aConstituentsIt = 0;
3071 for (Standard_Integer i = 1; i <= aConstituents->Length(); i++)
3072 if (!aConstituents->Value(i).IsNull()) {
3074 aResConstituents->SetValue(aConstituentsIt, aConstituents->Value(i));
3077 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
3078 Handle(StepDimTol_DatumSystem) aDS = new StepDimTol_DatumSystem();
3079 aDS->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(),
3080 aFirstDatum->ProductDefinitional(), aResConstituents);
3081 Model->AddWithRefs(aDS);
3082 StepDimTol_DatumSystemOrReference anArrayValue;
3083 anArrayValue.SetValue(aDS);
3084 aDatumSystem = new StepDimTol_HArray1OfDatumSystemOrReference(1, 1);
3085 aDatumSystem->SetValue(1, anArrayValue);
3088 if (anObject->HasAxis()) {
3089 GeomToStep_MakeAxis2Placement3d anAxisMaker(anObject->GetAxis());
3090 Handle(StepGeom_Axis2Placement3d) anAxis = anAxisMaker.Value();
3091 anAxis->SetName(new TCollection_HAsciiString("orientation"));
3092 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
3093 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
3094 aDefinition.SetValue(aDS);
3095 Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
3096 Handle(StepRepr_RepresentationItem) anIdentifiedItem = anAxis;
3097 anReprItems->SetValue(1, anIdentifiedItem);
3098 Interface_EntityIterator subs = aGraph.Sharings(aFirstDatum->OfShape());
3099 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
3100 for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) {
3101 Handle(Standard_Transient) anEntity = subs.Value();
3102 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity);
3105 return aDatumSystem;
3107 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(),
3108 aDefinition, aSDR->UsedRepresentation(), anReprItems);
3109 Model->AddWithRefs(anAxis);
3110 Model->AddWithRefs(aGISU);
3113 return aDatumSystem;
3116 //=======================================================================
3117 //function : WriteToleranceZone
3118 //purpose : auxiliary (write tolerace zones)
3119 //=======================================================================
3120 void STEPCAFControl_Writer::WriteToleranceZone (const Handle(XSControl_WorkSession) &WS,
3121 const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject,
3122 const Handle(StepDimTol_GeometricTolerance)& theEntity,
3123 const Handle(StepRepr_RepresentationContext)& theRC)
3126 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3127 if (theEntity.IsNull() || theObject.IsNull())
3130 // Return if there is no tolerance zones
3131 if (theObject->GetTypeOfValue() == XCAFDimTolObjects_GeomToleranceTypeValue_None &&
3132 theObject->GetZoneModifier() != XCAFDimTolObjects_GeomToleranceZoneModif_Runout)
3135 // Create Tolerance_Zone
3136 Handle(StepDimTol_ToleranceZoneForm) aForm = new StepDimTol_ToleranceZoneForm();
3137 Model->AddWithRefs(aForm);
3138 aForm->Init(STEPCAFControl_GDTProperty::GetTolValueType(theObject->GetTypeOfValue()));
3139 Handle(StepDimTol_HArray1OfToleranceZoneTarget) aZoneTargetArray = new StepDimTol_HArray1OfToleranceZoneTarget(1, 1);
3140 StepDimTol_ToleranceZoneTarget aTarget;
3141 aTarget.SetValue(theEntity);
3142 aZoneTargetArray->SetValue(1, aTarget);
3143 Handle(StepDimTol_ToleranceZone) aZone = new StepDimTol_ToleranceZone();
3144 aZone->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(),
3145 theEntity->TolerancedShapeAspect().ShapeAspect()->OfShape(), StepData_LFalse,
3146 aZoneTargetArray, aForm);
3147 Model->AddWithRefs(aZone);
3149 // Runout_Tolerance_Zone
3150 Handle(StepBasic_PlaneAngleMeasureWithUnit) aPAMWU = new StepBasic_PlaneAngleMeasureWithUnit();
3151 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
3152 aValueMember->SetName("PLANE_ANGLE_MEASURE");
3153 aValueMember->SetReal(theObject->GetValueOfZoneModifier());
3154 aPAMWU->Init(aValueMember, GetUnit(theRC, Standard_True));
3155 Handle(StepDimTol_RunoutZoneOrientation) anOrientation = new StepDimTol_RunoutZoneOrientation();
3156 anOrientation->Init(aPAMWU);
3157 Handle(StepDimTol_RunoutZoneDefinition) aDefinition = new StepDimTol_RunoutZoneDefinition();
3158 aDefinition->Init(aZone, NULL, anOrientation);
3159 Model->AddWithRefs(aDefinition);
3160 Model->AddWithRefs(anOrientation);
3161 Model->AddWithRefs(aPAMWU);
3164 //=======================================================================
3165 //function : WriteGeomTolerance
3166 //purpose : auxiliary (write Geometric_Tolerance entity for given shapes,
3167 // label and datum system)
3168 //======================================================================
3169 void STEPCAFControl_Writer::WriteGeomTolerance (const Handle(XSControl_WorkSession) &WS,
3170 const TDF_LabelSequence theShapeSeqL,
3171 const TDF_Label theGeomTolL,
3172 const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem,
3173 const Handle(StepRepr_RepresentationContext)& theRC)
3176 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3177 Handle(XCAFDoc_GeomTolerance) aGTAttr;
3178 if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr))
3180 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
3181 if (anObject.IsNull())
3185 Handle(StepBasic_LengthMeasureWithUnit) aLMWU = new StepBasic_LengthMeasureWithUnit();
3186 StepBasic_Unit aUnit = GetUnit(theRC);
3187 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
3188 aValueMember->SetName("LENGTH_MEASURE");
3189 aValueMember->SetReal(anObject->GetValue());
3190 aLMWU->Init(aValueMember, aUnit);
3191 Model->AddWithRefs(aLMWU);
3193 // Geometric_Tolerance target
3194 Handle(StepRepr_ShapeAspect) aMainSA;
3195 Handle(StepRepr_RepresentationContext) dummyRC;
3196 Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
3197 if (theShapeSeqL.Length() == 1) {
3198 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(1));
3199 aMainSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU);
3200 Model->AddWithRefs(aMainSA);
3203 Handle(StepRepr_CompositeShapeAspect) aCSA;
3204 for (Standard_Integer i = 1; i <= theShapeSeqL.Length(); i++) {
3205 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(i));
3206 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU);
3209 if (aCSA.IsNull()) {
3210 aCSA = new StepRepr_CompositeShapeAspect();
3211 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3212 Model->AddWithRefs(aCSA);
3214 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3215 aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCSA, aSA);
3216 Model->AddWithRefs(aSAR);
3220 StepDimTol_GeometricToleranceTarget aGTTarget;
3221 aGTTarget.SetValue(aMainSA);
3223 Standard_Boolean isWithModif = Standard_False,
3224 isWithDatRef = Standard_False,
3225 isWithMaxTol = Standard_False;
3228 XCAFDimTolObjects_GeomToleranceModifiersSequence aModifiers = anObject->GetModifiers();
3229 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifArray;
3230 Handle(StepBasic_LengthMeasureWithUnit) aMaxLMWU;
3231 Standard_Integer aModifNb = aModifiers.Length();
3232 if (anObject->GetMaterialRequirementModifier() != XCAFDimTolObjects_GeomToleranceMatReqModif_None)
3234 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++)
3235 if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around ||
3236 aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over)
3239 isWithModif = Standard_True;
3240 aModifArray = new StepDimTol_HArray1OfGeometricToleranceModifier(1, aModifNb);
3241 Standard_Integer k = 1;
3242 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) {
3243 if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around ||
3244 aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over)
3246 StepDimTol_GeometricToleranceModifier aModif =
3247 STEPCAFControl_GDTProperty::GetGeomToleranceModifier(aModifiers.Value(i));
3248 aModifArray->SetValue(k, aModif);
3251 if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_L) {
3252 aModifArray->SetValue(aModifNb, StepDimTol_GTMLeastMaterialRequirement);
3254 else if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_M) {
3255 aModifArray->SetValue(aModifNb, StepDimTol_GTMMaximumMaterialRequirement);
3257 // Modifier with value
3258 if (anObject->GetMaxValueModifier() != 0) {
3259 isWithMaxTol = Standard_True;
3260 aMaxLMWU = new StepBasic_LengthMeasureWithUnit();
3261 Handle(StepBasic_MeasureValueMember) aModifierValueMember = new StepBasic_MeasureValueMember();
3262 aModifierValueMember->SetName("LENGTH_MEASURE");
3263 aModifierValueMember->SetReal(anObject->GetMaxValueModifier());
3264 aMaxLMWU->Init(aModifierValueMember, aUnit);
3265 Model->AddWithRefs(aMaxLMWU);
3270 isWithDatRef = !theDatumSystem.IsNull();
3272 // Collect all attributes
3273 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(),
3274 aDescription = new TCollection_HAsciiString();
3275 Handle(StepDimTol_GeometricToleranceWithDatumReference) aGTWDR =
3276 new StepDimTol_GeometricToleranceWithDatumReference();
3277 aGTWDR->SetDatumSystem(theDatumSystem);
3278 Handle(StepDimTol_GeometricToleranceWithModifiers) aGTWM =
3279 new StepDimTol_GeometricToleranceWithModifiers();
3280 aGTWM->SetModifiers(aModifArray);
3281 StepDimTol_GeometricToleranceType aType =
3282 STEPCAFControl_GDTProperty::GetGeomToleranceType(anObject->GetType());
3284 // Init and write necessary subtype of Geometric_Tolerance entity
3285 Handle(StepDimTol_GeometricTolerance) aGeomTol;
3289 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference &
3290 //Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers
3291 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aResult =
3292 new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol();
3293 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aMaxLMWU, aType);
3297 // Geometric_Tolerance & Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers
3298 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aResult =
3299 new StepDimTol_GeoTolAndGeoTolWthMaxTol();
3300 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWM, aMaxLMWU, aType);
3306 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference & Geometric_Tolerance_With_Modifiers
3307 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) aResult =
3308 new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod();
3309 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aType);
3313 // Geometric_Tolerance & Geometric_Tolerance_With_Modifiers
3314 Handle(StepDimTol_GeoTolAndGeoTolWthMod) aResult =
3315 new StepDimTol_GeoTolAndGeoTolWthMod();
3316 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWM, aType);
3323 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference
3324 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) aResult =
3325 new StepDimTol_GeoTolAndGeoTolWthDatRef();
3326 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aType);
3330 // Geometric_Tolerance
3331 Handle(StepDimTol_GeometricTolerance) aResult =
3332 STEPCAFControl_GDTProperty::GetGeomTolerance(anObject->GetType());
3333 if (!aResult.IsNull()) {
3334 aResult->Init(aName, aDescription, aLMWU, aGTTarget);
3339 Model->AddWithRefs(aGeomTol);
3340 WriteToleranceZone(WS, anObject, aGeomTol, theRC);
3341 //Annotation plane and Presentation
3342 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(),
3343 anObject->GetPlane(), anObject->GetPointTextAttach(), aGeomTol);
3346 //=======================================================================
3347 //function : WriteDGTs
3349 //=======================================================================
3350 Standard_Boolean STEPCAFControl_Writer::WriteDGTs (const Handle(XSControl_WorkSession) &WS,
3351 const TDF_LabelSequence &labels ) const
3354 if ( labels.Length() <=0 ) return Standard_False;
3357 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3358 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
3359 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
3361 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3362 if(aHGraph.IsNull())
3363 return Standard_False;
3365 Interface_Graph aGraph = aHGraph->Graph();
3366 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( labels(1) );
3367 if(DGTTool.IsNull() ) return Standard_False;
3369 TDF_LabelSequence DGTLabels;
3371 STEPConstruct_DataMapOfAsciiStringTransient DatumMap;
3375 DGTTool->GetDatumLabels(DGTLabels);
3376 if(DGTLabels.Length()<=0) return Standard_False;
3378 for(i=1; i<=DGTLabels.Length(); i++) {
3379 TDF_Label DatumL = DGTLabels.Value(i);
3380 TDF_LabelSequence ShapeL;
3381 TDF_LabelSequence aNullSeq;
3382 if(!DGTTool->GetRefShapeLabel(DatumL,ShapeL,aNullSeq)) continue;
3383 // find target shape
3384 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
3385 TopLoc_Location Loc;
3386 TColStd_SequenceOfTransient seqRI;
3387 FindEntities( FP, aShape, Loc, seqRI );
3388 if ( seqRI.Length() <= 0 ) {
3389 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
3392 Handle(StepRepr_ProductDefinitionShape) PDS;
3393 Handle(StepRepr_RepresentationContext) RC;
3394 Handle(Standard_Transient) ent = seqRI.Value(1);
3395 Handle(StepShape_AdvancedFace) AF;
3396 Handle(StepShape_EdgeCurve) EC;
3397 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
3398 if(PDS.IsNull()) continue;
3399 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
3400 Handle(XCAFDoc_Datum) DatumAttr;
3401 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
3402 Handle(TCollection_HAsciiString) aName = DatumAttr->GetName();
3403 Handle(TCollection_HAsciiString) aDescription = DatumAttr->GetDescription();
3404 Handle(TCollection_HAsciiString) anIdentification = DatumAttr->GetIdentification();
3405 Handle(StepDimTol_DatumFeature) DF = new StepDimTol_DatumFeature;
3406 Handle(StepDimTol_Datum) aDatum = new StepDimTol_Datum;
3407 DF->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
3408 Model->AddWithRefs(DF);
3409 aDatum->Init(aName, new TCollection_HAsciiString, PDS, StepData_LFalse, anIdentification);
3410 Model->AddWithRefs(aDatum);
3411 Handle(StepRepr_ShapeAspectRelationship) SAR = new StepRepr_ShapeAspectRelationship;
3412 SAR->SetName(aName);
3413 SAR->SetRelatingShapeAspect(DF);
3414 SAR->SetRelatedShapeAspect(aDatum);
3415 Model->AddWithRefs(SAR);
3416 // write chain for DatumFeature
3417 StepRepr_CharacterizedDefinition CD;
3419 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
3420 PropD->Init(aName,Standard_True,aDescription,CD);
3421 Model->AddWithRefs(PropD);
3422 StepRepr_RepresentedDefinition RD;
3424 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
3425 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
3426 new StepRepr_HArray1OfRepresentationItem(1,1);
3427 HARI->SetValue(1,AF);
3428 SR->Init(aName,HARI,RC);
3429 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
3431 Model->AddWithRefs(SDR);
3432 // write chain for Datum
3433 StepRepr_CharacterizedDefinition CD1;
3434 CD1.SetValue(aDatum);
3435 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
3436 PropD1->Init(aName,Standard_True,aDescription,CD1);
3437 Model->AddWithRefs(PropD1);
3438 StepRepr_RepresentedDefinition RD1;
3439 RD1.SetValue(PropD1);
3440 Handle(StepShape_ShapeRepresentation) SR1 = new StepShape_ShapeRepresentation;
3441 Handle(StepRepr_HArray1OfRepresentationItem) HARI1 =
3442 new StepRepr_HArray1OfRepresentationItem(1,1);
3443 HARI1->SetValue(1,AF->FaceGeometry());
3444 SR1->Init(aName,HARI1,RC);
3445 Model->AddWithRefs(SR1);
3446 Handle(StepShape_ShapeDefinitionRepresentation) SDR1 = new StepShape_ShapeDefinitionRepresentation;
3447 SDR1->Init(RD1,SR1);
3448 Model->AddWithRefs(SDR1);
3449 // add created Datum into Map
3450 TCollection_AsciiString stmp(aName->ToCString());
3451 stmp.AssignCat(aDescription->ToCString());
3452 stmp.AssignCat(anIdentification->ToCString());
3453 DatumMap.Bind(stmp,aDatum);
3456 // write Tolerances and Dimensions
3458 DGTTool->GetDimTolLabels(DGTLabels);
3459 if(DGTLabels.Length()<=0) return Standard_False;
3460 for(i=1; i<=DGTLabels.Length(); i++) {
3461 TDF_Label DimTolL = DGTLabels.Value(i);
3462 TDF_LabelSequence ShapeL;
3463 TDF_LabelSequence aNullSeq;
3464 if(!DGTTool->GetRefShapeLabel(DimTolL,ShapeL,aNullSeq)) continue;
3465 // find target shape
3466 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
3467 TopLoc_Location Loc;
3468 TColStd_SequenceOfTransient seqRI;
3469 FindEntities( FP, aShape, Loc, seqRI );
3470 if ( seqRI.Length() <= 0 ) {
3471 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
3474 Handle(StepRepr_ProductDefinitionShape) PDS;
3475 Handle(StepRepr_RepresentationContext) RC;
3476 Handle(Standard_Transient) ent = seqRI.Value(1);
3477 Handle(StepShape_AdvancedFace) AF;
3478 Handle(StepShape_EdgeCurve) EC;
3479 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
3480 if(PDS.IsNull()) continue;
3481 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
3483 Handle(XCAFDoc_DimTol) DimTolAttr;
3484 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) continue;
3485 Standard_Integer kind = DimTolAttr->GetKind();
3486 Handle(TColStd_HArray1OfReal) aVal = DimTolAttr->GetVal();
3487 Handle(TCollection_HAsciiString) aName = DimTolAttr->GetName();
3488 Handle(TCollection_HAsciiString) aDescription = DimTolAttr->GetDescription();
3490 // common part of writing D> entities
3491 StepRepr_CharacterizedDefinition CD;
3492 Handle(StepRepr_ShapeAspect) SA = new StepRepr_ShapeAspect;
3493 SA->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
3494 Model->AddWithRefs(SA);
3496 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
3497 PropD->Init(aName,Standard_True,aDescription,CD);
3498 Model->AddWithRefs(PropD);
3499 StepRepr_RepresentedDefinition RD;
3501 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
3502 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
3503 new StepRepr_HArray1OfRepresentationItem(1,1);
3505 HARI->SetValue(1,EC);
3507 HARI->SetValue(1,AF);
3508 SR->Init(aName,HARI,RC);
3509 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
3511 Model->AddWithRefs(SDR);
3512 // define aUnit for creation LengthMeasureWithUnit (common for all)
3513 StepBasic_Unit aUnit;
3514 Handle(StepBasic_SiUnitAndLengthUnit) SLU;
3515 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) Ctx =
3516 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(RC);
3518 for(Standard_Integer j=1; j<=Ctx->NbUnits(); j++) {
3519 if(Ctx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
3520 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx->UnitsValue(j));
3526 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) Ctx1 =
3527 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(RC);
3528 if(!Ctx1.IsNull()) {
3529 for(Standard_Integer j=1; j<=Ctx1->NbUnits(); j++) {
3530 if(Ctx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
3531 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx1->UnitsValue(j));
3538 SLU = new StepBasic_SiUnitAndLengthUnit;
3540 aUnit.SetValue(SLU);
3542 // specific part of writing D> entities
3543 if(kind<20) { //dimension
3544 Handle(StepShape_DimensionalSize) DimSize = new StepShape_DimensionalSize;
3545 DimSize->Init(SA,aDescription);
3546 Model->AddWithRefs(DimSize);
3547 if(aVal->Length()>1) {
3548 // create MeasureWithUnits
3549 Handle(StepBasic_MeasureValueMember) MVM1 = new StepBasic_MeasureValueMember;
3550 MVM1->SetName("POSITIVE_LENGTH_MEASURE");
3551 MVM1->SetReal(aVal->Value(1));
3552 Handle(StepBasic_MeasureWithUnit) MWU1 = new StepBasic_MeasureWithUnit;
3553 MWU1->Init(MVM1,aUnit);
3554 Handle(StepBasic_MeasureValueMember) MVM2 = new StepBasic_MeasureValueMember;
3555 MVM2->SetName("POSITIVE_LENGTH_MEASURE");
3556 MVM2->SetReal(aVal->Value(2));
3557 Handle(StepBasic_MeasureWithUnit) MWU2 = new StepBasic_MeasureWithUnit;
3558 MWU2->Init(MVM2,aUnit);
3559 Handle(StepRepr_RepresentationItem) RI1 = new StepRepr_RepresentationItem;
3560 RI1->Init(new TCollection_HAsciiString("lower limit"));
3561 Handle(StepRepr_RepresentationItem) RI2 = new StepRepr_RepresentationItem;
3562 RI2->Init(new TCollection_HAsciiString("upper limit"));
3563 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU1 =
3564 new StepRepr_ReprItemAndLengthMeasureWithUnit;
3565 RILMU1->Init(MWU1,RI1);
3566 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU2 =
3567 new StepRepr_ReprItemAndLengthMeasureWithUnit;
3568 RILMU2->Init(MWU2,RI2);
3569 Model->AddWithRefs(RILMU1);
3570 Model->AddWithRefs(RILMU2);
3571 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
3572 // new StepRepr_CompoundItemDefinitionMember;
3573 //Handle(TColStd_HArray1OfTransient) ArrTr = new TColStd_HArray1OfTransient(1,2);
3574 //ArrTr->SetValue(1,RILMU1);
3575 //ArrTr->SetValue(2,RILMU2);
3576 //CIDM->SetArrTransient(ArrTr);
3577 //CIDM->SetName("SET_REPRESENTATION_ITEM");
3578 //StepRepr_CompoundItemDefinition CID;
3579 //CID.SetValue(CIDM);
3580 Handle(StepRepr_HArray1OfRepresentationItem) HARIVR =
3581 new StepRepr_HArray1OfRepresentationItem(1,2);
3582 HARIVR->SetValue(1,RILMU1);
3583 HARIVR->SetValue(2,RILMU2);
3584 Handle(StepRepr_ValueRange) VR = new StepRepr_ValueRange;
3585 //VR->Init(aName,CID);
3586 VR->Init(aName,HARIVR);
3587 Model->AddEntity(VR);
3588 Handle(StepShape_ShapeDimensionRepresentation) SDimR =
3589 new StepShape_ShapeDimensionRepresentation;
3590 Handle(StepRepr_HArray1OfRepresentationItem) aHARI =
3591 new StepRepr_HArray1OfRepresentationItem(1,1);
3592 aHARI->SetValue(1,VR);
3593 SDimR->Init(aName,aHARI,RC);
3594 Model->AddWithRefs(SDimR);
3595 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
3596 new StepShape_DimensionalCharacteristicRepresentation;
3597 StepShape_DimensionalCharacteristic DimChar;
3598 DimChar.SetValue(DimSize);
3599 DimCharR->Init(DimChar,SDimR);
3600 Model->AddEntity(DimCharR);
3603 else if(kind<50) { //tolerance
3604 if(kind<35) { // tolerance with datum system
3605 TDF_LabelSequence DatumLabels;
3606 DGTTool->GetDatumOfTolerLabels(DimTolL,DatumLabels);
3607 Standard_Integer NbDR = DatumLabels.Length();
3608 Handle(StepDimTol_HArray1OfDatumReference) HADR = new StepDimTol_HArray1OfDatumReference(1,NbDR);
3609 for(Standard_Integer j=1; j<=NbDR; j++) {
3610 Handle(XCAFDoc_Datum) DatumAttr;
3611 TDF_Label DatumL = DatumLabels.Value(j);
3612 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
3613 Handle(TCollection_HAsciiString) aNameD = DatumAttr->GetName();
3614 Handle(TCollection_HAsciiString) aDescriptionD = DatumAttr->GetDescription();
3615 Handle(TCollection_HAsciiString) anIdentificationD = DatumAttr->GetIdentification();
3616 TCollection_AsciiString stmp(aNameD->ToCString());
3617 stmp.AssignCat(aDescriptionD->ToCString());
3618 stmp.AssignCat(anIdentificationD->ToCString());
3619 if(DatumMap.IsBound(stmp)) {
3620 Handle(StepDimTol_Datum) aDatum =
3621 Handle(StepDimTol_Datum)::DownCast(DatumMap.Find(stmp));
3622 Handle(StepDimTol_DatumReference) DR = new StepDimTol_DatumReference;
3624 Model->AddWithRefs(DR);
3625 HADR->SetValue(j,DR);
3628 // create LengthMeasureWithUnit
3629 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
3630 MVM->SetName("LENGTH_MEASURE");
3631 MVM->SetReal(aVal->Value(1));
3632 Handle(StepBasic_LengthMeasureWithUnit) LMWU = new StepBasic_LengthMeasureWithUnit;
3633 LMWU->Init(MVM,aUnit);
3634 // create tolerance by it's type
3636 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
3637 new StepDimTol_GeometricToleranceWithDatumReference;
3638 GTWDR->SetDatumSystem(HADR);
3639 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
3640 new StepDimTol_ModifiedGeometricTolerance;
3641 if(kind==21) MGT->SetModifier(StepDimTol_MaximumMaterialCondition);
3642 else if(kind==22) MGT->SetModifier(StepDimTol_LeastMaterialCondition);
3643 else if(kind==23) MGT->SetModifier(StepDimTol_RegardlessOfFeatureSize);
3644 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
3645 new StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol;
3646 GTComplex->Init(aName,aDescription,LMWU,SA,GTWDR,MGT);
3647 Model->AddWithRefs(GTComplex);
3650 Handle(StepDimTol_AngularityTolerance) aToler =
3651 new StepDimTol_AngularityTolerance;
3652 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3653 Model->AddWithRefs(aToler);
3656 Handle(StepDimTol_CircularRunoutTolerance) aToler =
3657 new StepDimTol_CircularRunoutTolerance;
3658 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3659 Model->AddWithRefs(aToler);
3662 Handle(StepDimTol_CoaxialityTolerance) aToler =
3663 new StepDimTol_CoaxialityTolerance;
3664 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3665 Model->AddWithRefs(aToler);
3668 Handle(StepDimTol_ConcentricityTolerance) aToler =
3669 new StepDimTol_ConcentricityTolerance;
3670 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3671 Model->AddWithRefs(aToler);
3674 Handle(StepDimTol_ParallelismTolerance) aToler =
3675 new StepDimTol_ParallelismTolerance;
3676 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3677 Model->AddWithRefs(aToler);
3680 Handle(StepDimTol_PerpendicularityTolerance) aToler =
3681 new StepDimTol_PerpendicularityTolerance;
3682 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3683 Model->AddWithRefs(aToler);
3686 Handle(StepDimTol_SymmetryTolerance) aToler =
3687 new StepDimTol_SymmetryTolerance;
3688 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3689 Model->AddWithRefs(aToler);
3692 Handle(StepDimTol_TotalRunoutTolerance) aToler =
3693 new StepDimTol_TotalRunoutTolerance;
3694 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3695 Model->AddWithRefs(aToler);
3701 return Standard_True;
3704 //=======================================================================
3705 //function : WriteDGTsAP242
3707 //=======================================================================
3709 Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_WorkSession) &WS,
3710 const TDF_LabelSequence &labels )
3713 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
3715 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3716 if(aHGraph.IsNull())
3717 return Standard_False;
3719 Interface_Graph aGraph = aHGraph->Graph();
3720 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool(labels(1));
3721 if(DGTTool.IsNull())
3722 return Standard_False;
3724 // Common entities for presentation
3725 STEPConstruct_Styles aStyles (WS);
3726 Handle(StepVisual_Colour) aCurvColor = aStyles.EncodeColor(Quantity_NOC_WHITE);
3727 Handle(StepRepr_RepresentationItem) anItem = NULL;
3728 myGDTPrsCurveStyle->SetValue(1, aStyles.MakeColorPSA(anItem, aCurvColor, aCurvColor));
3729 Interface_EntityIterator aModelIter = aModel->Entities();
3730 for (; aModelIter.More() && myGDTCommonPDS.IsNull(); aModelIter.Next())
3731 myGDTCommonPDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aModelIter.Value());
3733 TDF_LabelSequence aDGTLabels;
3734 STEPConstruct_DataMapOfAsciiStringTransient aDatumMap;
3735 Handle(StepRepr_RepresentationContext) aRC;
3740 DGTTool->GetDatumLabels(aDGTLabels);
3741 // Find all shapes with datums
3742 TColStd_MapOfAsciiString aNameIdMap;
3743 for(Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3744 TDF_Label aDatumL = aDGTLabels.Value(i);
3745 TDF_LabelSequence aShapeL, aNullSeq;
3746 DGTTool->GetRefShapeLabel(aDatumL, aShapeL, aNullSeq);
3747 Handle(XCAFDoc_Datum) aDatumAttr;
3748 aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr);
3749 Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject();
3750 TCollection_AsciiString aDatumName = anObject->GetName()->String();
3751 TCollection_AsciiString aDatumTargetId = TCollection_AsciiString(anObject->GetDatumTargetNumber());
3752 if (!aNameIdMap.Add(aDatumName.Cat(aDatumTargetId)))
3754 Handle(Standard_Transient) aWrittenDatum;
3755 Standard_Boolean isFirstDT = !aDatumMap.Find(aDatumName, aWrittenDatum);
3756 Handle(StepDimTol_Datum) aDatum = WriteDatumAP242(WS, aShapeL, aDatumL, isFirstDT,
3757 Handle(StepDimTol_Datum)::DownCast (aWrittenDatum));
3758 // Add created Datum into Map
3759 aDatumMap.Bind(aDatumName, aDatum);
3762 //----------------- //
3763 // write Dimensions //
3764 //------------------//
3766 DGTTool->GetDimensionLabels(aDGTLabels);
3767 // Auxiliary entities for derived geometry
3768 Handle(StepRepr_ConstructiveGeometryRepresentation) aCGRepr =
3769 new StepRepr_ConstructiveGeometryRepresentation();
3770 Handle(StepRepr_ConstructiveGeometryRepresentationRelationship) aCGReprRel =
3771 new StepRepr_ConstructiveGeometryRepresentationRelationship();
3772 NCollection_Vector<Handle(StepGeom_CartesianPoint)> aConnectionPnts;
3773 Handle(StepRepr_RepresentationContext) dummyRC;
3774 Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
3775 for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3776 TDF_Label aDimensionL = aDGTLabels.Value(i);
3777 TDF_LabelSequence aFirstShapeL, aSecondShapeL;
3778 Handle(XCAFDoc_Dimension) aDimAttr;
3779 if (!aDimensionL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttr))
3781 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject();
3782 if (anObject.IsNull())
3784 if (anObject->GetType() == XCAFDimTolObjects_DimensionType_CommonLabel)
3786 Handle(StepRepr_ShapeAspect) aSA = new StepRepr_ShapeAspect();
3787 aSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), myGDTCommonPDS, StepData_LTrue);
3788 aModel->AddWithRefs(aSA);
3789 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->HasPlane(),
3790 Standard_False, anObject->GetPlane(), anObject->GetPointTextAttach(), aSA);
3793 if (!DGTTool->GetRefShapeLabel(aDimensionL, aFirstShapeL, aSecondShapeL))
3796 // Write links with shapes
3797 Handle(StepRepr_ShapeAspect) aFirstSA, aSecondSA;
3798 if (aFirstShapeL.Length() == 1) {
3799 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(1));
3800 aFirstSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3801 if (aRC.IsNull() && !dummyRC.IsNull())
3804 else if (aFirstShapeL.Length() > 1) {
3805 Handle(StepRepr_CompositeShapeAspect) aCSA;
3806 for (Standard_Integer shIt = 1; shIt <= aFirstShapeL.Length(); shIt++) {
3807 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(shIt));
3808 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3811 if (aCSA.IsNull()) {
3812 aCSA = new StepRepr_CompositeShapeAspect();
3813 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3814 aModel->AddWithRefs(aCSA);
3816 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3817 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA);
3818 aModel->AddWithRefs(aSAR);
3819 if (aRC.IsNull() && !dummyRC.IsNull())
3824 if (aSecondShapeL.Length() == 1) {
3825 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(1));
3826 aSecondSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3827 if (aRC.IsNull() && !dummyRC.IsNull())
3830 else if (aSecondShapeL.Length() > 1) {
3831 Handle(StepRepr_CompositeShapeAspect) aCSA;
3832 for (Standard_Integer shIt = 1; shIt <= aSecondShapeL.Length(); shIt++) {
3833 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(shIt));
3834 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3835 if (aCSA.IsNull() && !aSA.IsNull())
3837 aCSA = new StepRepr_CompositeShapeAspect();
3839 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3840 if (!aSA.IsNull()) {
3841 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3842 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA);
3843 aModel->AddWithRefs(aSAR);
3845 if (aRC.IsNull() && !dummyRC.IsNull())
3851 if (anObject->GetType() == XCAFDimTolObjects_DimensionType_DimensionPresentation)
3853 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->HasPlane(),
3854 Standard_False, anObject->GetPlane(), anObject->GetPointTextAttach(), aFirstSA);
3859 StepShape_DimensionalCharacteristic aDimension;
3860 if (anObject->HasPoint() || anObject->HasPoint2())
3861 WriteDerivedGeometry(WS, anObject, aCGRepr, aFirstSA, aSecondSA, aConnectionPnts);
3862 XCAFDimTolObjects_DimensionType aDimType = anObject->GetType();
3863 if (STEPCAFControl_GDTProperty::IsDimensionalLocation(aDimType)) {
3864 // Dimensional_Location
3865 Handle(StepShape_DimensionalLocation) aDim = new StepShape_DimensionalLocation();
3866 aDim->Init(STEPCAFControl_GDTProperty::GetDimTypeName(aDimType), Standard_False, NULL, aFirstSA, aSecondSA);
3867 aDimension.SetValue(aDim);
3869 else if (aDimType == XCAFDimTolObjects_DimensionType_Location_Angular) {
3871 Handle(StepShape_AngularLocation) aDim = new StepShape_AngularLocation();
3872 StepShape_AngleRelator aRelator = StepShape_Equal;
3873 if (anObject->HasQualifier()) {
3874 XCAFDimTolObjects_DimensionQualifier aQualifier = anObject->GetQualifier();
3875 switch (aQualifier) {
3876 case XCAFDimTolObjects_DimensionQualifier_Min: aRelator = StepShape_Small;
3878 case XCAFDimTolObjects_DimensionQualifier_Max: aRelator = StepShape_Large;
3880 default: aRelator = StepShape_Equal;
3883 aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aRelator);
3884 aDimension.SetValue(aDim);
3886 else if (aDimType == XCAFDimTolObjects_DimensionType_Location_WithPath) {
3887 // Dimensional_Location_With_Path
3888 Handle(StepShape_DimensionalLocationWithPath) aDim = new StepShape_DimensionalLocationWithPath();
3889 Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU);
3890 aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aPathSA);
3891 aDimension.SetValue(aDim);
3893 else if (STEPCAFControl_GDTProperty::IsDimensionalSize(aDimType)) {
3895 Handle(StepShape_DimensionalSize) aDim = new StepShape_DimensionalSize();
3896 aDim->Init(aFirstSA, STEPCAFControl_GDTProperty::GetDimTypeName(aDimType));
3897 aDimension.SetValue(aDim);
3899 else if (aDimType == XCAFDimTolObjects_DimensionType_Size_Angular) {
3901 Handle(StepShape_AngularSize) aDim = new StepShape_AngularSize();
3902 StepShape_AngleRelator aRelator = StepShape_Equal;
3903 if (anObject->HasQualifier()) {
3904 XCAFDimTolObjects_DimensionQualifier aQualifier = anObject->GetQualifier();
3905 switch (aQualifier) {
3906 case XCAFDimTolObjects_DimensionQualifier_Min: aRelator = StepShape_Small;
3908 case XCAFDimTolObjects_DimensionQualifier_Max: aRelator = StepShape_Large;
3910 default: aRelator = StepShape_Equal;
3913 aDim->Init(aFirstSA, new TCollection_HAsciiString(), aRelator);
3914 aDimension.SetValue(aDim);
3916 else if (aDimType == XCAFDimTolObjects_DimensionType_Size_WithPath) {
3917 // Dimensional_Size_With_Path
3918 Handle(StepShape_DimensionalSizeWithPath) aDim = new StepShape_DimensionalSizeWithPath();
3919 Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU);
3920 aDim->Init(aFirstSA, new TCollection_HAsciiString(), aPathSA);
3921 aDimension.SetValue(aDim);
3925 WriteDimValues(WS, anObject, aRC, aDimension);
3926 //Annotation plane and Presentation
3927 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(),
3928 anObject->GetPlane(), anObject->GetPointTextAttach(), aDimension.Value());
3930 // Write Derived geometry
3931 if (aConnectionPnts.Length() > 0) {
3932 Handle(StepRepr_HArray1OfRepresentationItem) anItems = new StepRepr_HArray1OfRepresentationItem(1, aConnectionPnts.Length());
3933 for (Standard_Integer i = 0; i < aConnectionPnts.Length(); i++)
3934 anItems->SetValue(i + 1, aConnectionPnts(i));
3935 aCGRepr->Init(new TCollection_HAsciiString(), anItems, dummyRC);
3936 aCGReprRel->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), dummyGISU->UsedRepresentation(), aCGRepr);
3937 aModel->AddWithRefs(aCGReprRel);
3940 //----------------------------//
3941 // write Geometric Tolerances //
3942 //----------------------------//
3944 DGTTool->GetGeomToleranceLabels(aDGTLabels);
3945 for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3946 TDF_Label aGeomTolL = aDGTLabels.Value(i);
3947 TDF_LabelSequence aFirstShapeL, aNullSeqL;
3948 if (!DGTTool->GetRefShapeLabel(aGeomTolL, aFirstShapeL, aNullSeqL))
3950 TDF_LabelSequence aDatumSeq;
3951 DGTTool->GetDatumWithObjectOfTolerLabels(aGeomTolL, aDatumSeq);
3952 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
3953 if (aDatumSeq.Length() > 0)
3954 aDatumSystem = WriteDatumSystem(WS, aGeomTolL, aDatumSeq, aDatumMap, aRC);
3955 WriteGeomTolerance(WS, aFirstShapeL, aGeomTolL, aDatumSystem, aRC);
3958 // Write Draughting model for Annotation Planes
3959 if (myGDTAnnotations.Length() == 0)
3960 return Standard_True;
3962 Handle(StepRepr_HArray1OfRepresentationItem) aItems =
3963 new StepRepr_HArray1OfRepresentationItem(1, myGDTAnnotations.Length());
3964 for (Standard_Integer i = 1; i <= aItems->Length(); i++) {
3965 aItems->SetValue(i, myGDTAnnotations.Value(i - 1));
3967 myGDTPresentationDM->Init(new TCollection_HAsciiString(), aItems, aRC);
3968 aModel->AddWithRefs(myGDTPresentationDM);
3970 return Standard_True;
3973 //=======================================================================
3974 //function : FindPDSforRI
3975 //purpose : auxilary:
3976 //=======================================================================
3977 static Standard_Boolean FindPDSforRI(const Interface_Graph &aGraph,
3978 const Handle(Standard_Transient) &ent,
3979 Handle(StepRepr_ProductDefinitionShape) &PDS,
3980 Handle(StepRepr_RepresentationContext) &RC)
3982 if(ent.IsNull() || !ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem)))
3983 return Standard_False;
3984 Interface_EntityIterator subs = aGraph.Sharings(ent);
3985 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
3986 Handle(StepShape_ShapeRepresentation) SR =
3987 Handle(StepShape_ShapeRepresentation)::DownCast(subs.Value());
3988 if(SR.IsNull()) continue;
3989 RC = SR->ContextOfItems();
3990 Interface_EntityIterator subs1 = aGraph.Sharings(SR);
3991 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
3992 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
3993 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs1.Value());
3994 if(SDR.IsNull()) continue;
3995 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
3996 if(PropD.IsNull()) continue;
3997 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
4000 return Standard_True;
4004 //=======================================================================
4005 //function : WriteMaterials
4007 //=======================================================================
4009 Standard_Boolean STEPCAFControl_Writer::WriteMaterials (const Handle(XSControl_WorkSession) &WS,
4010 const TDF_LabelSequence &labels ) const
4013 if ( labels.Length() <=0 ) return Standard_False;
4016 const Handle(Interface_InterfaceModel) &Model = WS->Model();
4017 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
4018 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
4020 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
4021 if(aHGraph.IsNull())
4022 return Standard_False;
4024 Interface_Graph aGraph = WS->HGraph()->Graph();
4025 Handle(XCAFDoc_ShapeTool) ShTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
4026 if(ShTool.IsNull() ) return Standard_False;
4027 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( labels(1) );
4028 if(MatTool.IsNull() ) return Standard_False;
4030 STEPConstruct_DataMapOfAsciiStringTransient MapDRI,MapMRI;
4031 TDF_LabelSequence TopLabels;
4032 ShTool->GetShapes(TopLabels);
4033 for(Standard_Integer i=1; i<=TopLabels.Length(); i++) {
4034 TDF_Label ShL = TopLabels.Value(i);
4035 Handle(TDataStd_TreeNode) Node;
4036 if( ShL.FindAttribute(XCAFDoc::MaterialRefGUID(),Node) && Node->HasFather() ) {
4037 // find PDS for current shape
4038 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShL);
4039 TopLoc_Location Loc;
4040 TColStd_SequenceOfTransient seqRI;
4041 FindEntities( FP, aShape, Loc, seqRI );
4042 if(seqRI.Length()<=0) continue;
4043 Handle(StepRepr_ProductDefinitionShape) PDS;
4044 Handle(StepRepr_RepresentationContext) RC;
4045 Handle(Standard_Transient) ent = seqRI.Value(1);
4046 FindPDSforRI(aGraph,ent,PDS,RC);
4047 if(PDS.IsNull()) continue;
4048 Handle(StepBasic_ProductDefinition) aProdDef =
4049 PDS->Definition().ProductDefinition();
4050 if(aProdDef.IsNull())
4052 // write material entities
4053 TDF_Label MatL = Node->Father()->Label();
4054 Handle(TCollection_HAsciiString) aName;
4055 Handle(TCollection_HAsciiString) aDescription;
4056 Standard_Real aDensity;
4057 Handle(TCollection_HAsciiString) aDensName;
4058 Handle(TCollection_HAsciiString) aDensValType;
4059 Handle(StepRepr_Representation) RepDRI;
4060 Handle(StepRepr_Representation) RepMRI;
4061 if(MatTool->GetMaterial(MatL,aName,aDescription,aDensity,aDensName,aDensValType)) {
4062 if(aName->Length()==0) continue;
4063 TCollection_AsciiString aKey(aName->ToCString());
4064 if(MapDRI.IsBound(aKey)) {
4065 RepDRI = Handle(StepRepr_Representation)::DownCast(MapDRI.Find(aKey));
4066 if(MapMRI.IsBound(aKey)) {
4067 RepMRI = Handle(StepRepr_Representation)::DownCast(MapMRI.Find(aKey));
4072 Handle(StepRepr_DescriptiveRepresentationItem) DRI = new StepRepr_DescriptiveRepresentationItem;
4073 DRI->Init(aName,aDescription);
4074 Handle(StepRepr_HArray1OfRepresentationItem) HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
4075 HARI->SetValue(1,DRI);
4076 RepDRI = new StepRepr_Representation();
4077 RepDRI->Init(new TCollection_HAsciiString("material name"),HARI,RC);
4078 Model->AddWithRefs(RepDRI);
4080 if( aDensity > 0 ) {
4082 Handle(StepBasic_SiUnitAndMassUnit) SMU = new StepBasic_SiUnitAndMassUnit;
4083 SMU->SetName(StepBasic_sunGram);
4084 Handle(StepBasic_DerivedUnitElement) DUE1 = new StepBasic_DerivedUnitElement;
4085 DUE1->Init(SMU,3.0);
4087 Handle(StepBasic_SiUnitAndLengthUnit) SLU = new StepBasic_SiUnitAndLengthUnit;
4088 SLU->Init(Standard_True,StepBasic_spCenti,StepBasic_sunMetre);
4089 Handle(StepBasic_DerivedUnitElement) DUE2 = new StepBasic_DerivedUnitElement;
4090 DUE2->Init(SLU,2.0);
4092 Handle(StepBasic_HArray1OfDerivedUnitElement) HADUE = new StepBasic_HArray1OfDerivedUnitElement(1,2);
4093 HADUE->SetValue(1,DUE1);
4094 HADUE->SetValue(2,DUE2);
4095 Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit;
4097 Model->AddWithRefs(DU);
4098 StepBasic_Unit aUnit;
4100 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
4101 MVM->SetName(aDensValType->ToCString());
4102 MVM->SetReal(aDensity);
4103 Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem;
4104 MRI->Init(aDensName,MVM,aUnit);
4105 HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
4106 HARI->SetValue(1,MRI);
4107 RepMRI = new StepRepr_Representation();
4108 RepMRI->Init(new TCollection_HAsciiString("density"),HARI,RC);
4109 Model->AddWithRefs(RepMRI);
4111 //WriteNewMaterial(Model,aName,aDescription,aDensity,aDensName,aDensValType,RC,RepDRI,RepMRI);
4112 MapDRI.Bind(aKey,RepDRI);
4113 if ( !RepMRI.IsNull() ) MapMRI.Bind (aKey, RepMRI);
4117 if( !RepDRI.IsNull() )
4119 StepRepr_CharacterizedDefinition CD1;
4120 CD1.SetValue(aProdDef);
4121 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
4122 PropD1->Init(new TCollection_HAsciiString("material property"),Standard_True,
4123 new TCollection_HAsciiString("material name"),CD1);
4124 Model->AddWithRefs(PropD1);
4125 StepRepr_RepresentedDefinition RD1;
4126 RD1.SetValue(PropD1);
4127 Handle(StepRepr_PropertyDefinitionRepresentation) PDR1 =
4128 new StepRepr_PropertyDefinitionRepresentation;
4129 PDR1->Init(RD1,RepDRI);
4130 Model->AddWithRefs(PDR1);
4132 if( !RepMRI.IsNull() )
4134 StepRepr_CharacterizedDefinition CD2;
4135 CD2.SetValue (aProdDef);
4136 Handle (StepRepr_PropertyDefinition) PropD2 = new StepRepr_PropertyDefinition;
4137 PropD2->Init (new TCollection_HAsciiString ("material property"), Standard_True,
4138 new TCollection_HAsciiString ("density"), CD2);
4139 Model->AddWithRefs (PropD2);
4140 StepRepr_RepresentedDefinition RD2;
4141 RD2.SetValue (PropD2);
4142 Handle (StepRepr_PropertyDefinitionRepresentation) PDR2 =
4143 new StepRepr_PropertyDefinitionRepresentation;
4144 PDR2->Init (RD2, RepMRI);
4145 Model->AddWithRefs (PDR2);
4151 return Standard_True;
4155 //=======================================================================
4156 //function : SetColorMode
4158 //=======================================================================
4160 void STEPCAFControl_Writer::SetColorMode (const Standard_Boolean colormode)
4162 myColorMode = colormode;
4166 //=======================================================================
4167 //function : GetColorMode
4169 //=======================================================================
4171 Standard_Boolean STEPCAFControl_Writer::GetColorMode () const
4177 //=======================================================================
4178 //function : SetNameMode
4180 //=======================================================================
4182 void STEPCAFControl_Writer::SetNameMode (const Standard_Boolean namemode)
4184 myNameMode = namemode;
4188 //=======================================================================
4189 //function : GetNameMode
4191 //=======================================================================
4193 Standard_Boolean STEPCAFControl_Writer::GetNameMode () const
4199 //=======================================================================
4200 //function : SetLayerMode
4202 //=======================================================================
4204 void STEPCAFControl_Writer::SetLayerMode (const Standard_Boolean layermode)
4206 myLayerMode = layermode;
4210 //=======================================================================
4211 //function : GetLayerMode
4213 //=======================================================================
4215 Standard_Boolean STEPCAFControl_Writer::GetLayerMode () const
4221 //=======================================================================
4222 //function : SetPropsMode
4224 //=======================================================================
4226 void STEPCAFControl_Writer::SetPropsMode (const Standard_Boolean propsmode)
4228 myPropsMode = propsmode;
4232 //=======================================================================
4233 //function : GetPropsMode
4235 //=======================================================================
4237 Standard_Boolean STEPCAFControl_Writer::GetPropsMode () const
4243 //=======================================================================
4244 //function : SetSHUOMode
4246 //=======================================================================
4248 void STEPCAFControl_Writer::SetSHUOMode (const Standard_Boolean mode)
4254 //=======================================================================
4255 //function : GetSHUOMode
4257 //=======================================================================
4259 Standard_Boolean STEPCAFControl_Writer::GetSHUOMode () const
4265 //=======================================================================
4266 //function : SetDimTolMode
4268 //=======================================================================
4270 void STEPCAFControl_Writer::SetDimTolMode(const Standard_Boolean dimtolmode)
4272 myDGTMode = dimtolmode;
4276 //=======================================================================
4277 //function : GetDimTolMode
4279 //=======================================================================
4281 Standard_Boolean STEPCAFControl_Writer::GetDimTolMode() const
4287 //=======================================================================
4288 //function : SetMaterialMode
4290 //=======================================================================
4292 void STEPCAFControl_Writer::SetMaterialMode(const Standard_Boolean matmode)
4294 myMatMode = matmode;
4298 //=======================================================================
4299 //function : GetMaterialMode
4301 //=======================================================================
4303 Standard_Boolean STEPCAFControl_Writer::GetMaterialMode() const