0027455: Implementation of connection points
[occt.git] / src / STEPCAFControl / STEPCAFControl_Writer.cxx
CommitLineData
b311480e 1// Created on: 2000-08-15
2// Created by: Andrey BETENEV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
7fd59977 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
7fd59977 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
16// CURRENT LIMITATIONS:
7fd59977 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)
7fd59977 21// Names and validation props are supported for top-level shapes only
22
7fd59977 23#include <BRep_Builder.hxx>
18f7c9a5 24#include <GeomToStep_MakeCartesianPoint.hxx>
7fd59977 25#include <HeaderSection_FileSchema.hxx>
42cf5bc1 26#include <Interface_EntityIterator.hxx>
27#include <Interface_Static.hxx>
28#include <Message_Messenger.hxx>
7fd59977 29#include <MoniTool_DataMapIteratorOfDataMapOfShapeTransient.hxx>
b0cef606 30#include <NCollection_Vector.hxx>
42cf5bc1 31#include <OSD_Path.hxx>
7fd59977 32#include <Quantity_TypeOfColor.hxx>
42cf5bc1 33#include <StepAP214_Protocol.hxx>
b0cef606 34#include <StepAP242_DraughtingModelItemAssociation.hxx>
6595eee7 35#include <StepAP242_GeometricItemSpecificUsage.hxx>
42cf5bc1 36#include <StepBasic_DerivedUnit.hxx>
37#include <StepBasic_DerivedUnitElement.hxx>
38#include <StepBasic_HArray1OfDerivedUnitElement.hxx>
39#include <StepBasic_LengthMeasureWithUnit.hxx>
7fd59977 40#include <StepBasic_MeasureValueMember.hxx>
42cf5bc1 41#include <StepBasic_Product.hxx>
42#include <StepBasic_ProductDefinition.hxx>
43#include <StepBasic_ProductDefinitionFormation.hxx>
44#include <StepBasic_ProductDefinitionRelationship.hxx>
7fd59977 45#include <StepBasic_SiUnitAndLengthUnit.hxx>
42cf5bc1 46#include <StepBasic_SiUnitAndMassUnit.hxx>
6595eee7 47#include <StepBasic_SiUnitAndPlaneAngleUnit.hxx>
42cf5bc1 48#include <STEPCAFControl_ActorWrite.hxx>
49#include <STEPCAFControl_Controller.hxx>
50#include <STEPCAFControl_DictionaryOfExternFile.hxx>
51#include <STEPCAFControl_ExternFile.hxx>
52#include <STEPCAFControl_IteratorOfDictionaryOfExternFile.hxx>
53#include <STEPCAFControl_Writer.hxx>
54#include <STEPConstruct.hxx>
55#include <STEPConstruct_DataMapOfAsciiStringTransient.hxx>
56#include <STEPConstruct_DataMapOfPointTransient.hxx>
57#include <STEPConstruct_ExternRefs.hxx>
727b5ad9 58#include <STEPCAFControl_GDTProperty.hxx>
42cf5bc1 59#include <STEPConstruct_Styles.hxx>
60#include <STEPConstruct_ValidationProps.hxx>
61#include <STEPControl_StepModelType.hxx>
62#include <STEPControl_Writer.hxx>
7fd59977 63#include <StepData_Logical.hxx>
42cf5bc1 64#include <StepData_StepModel.hxx>
7fd59977 65#include <StepDimTol_AngularityTolerance.hxx>
66#include <StepDimTol_CircularRunoutTolerance.hxx>
67#include <StepDimTol_CoaxialityTolerance.hxx>
68#include <StepDimTol_ConcentricityTolerance.hxx>
7fd59977 69#include <StepDimTol_CylindricityTolerance.hxx>
42cf5bc1 70#include <StepDimTol_Datum.hxx>
71#include <StepDimTol_DatumFeature.hxx>
72#include <StepDimTol_DatumReference.hxx>
6595eee7 73#include <StepDimTol_DatumReferenceElement.hxx>
74#include <StepDimTol_DatumSystem.hxx>
75#include <StepDimTol_DatumSystemOrReference.hxx>
76#include <StepDimTol_DatumTarget.hxx>
7fd59977 77#include <StepDimTol_FlatnessTolerance.hxx>
6595eee7 78#include <StepDimTol_GeometricToleranceType.hxx>
42cf5bc1 79#include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
6595eee7 80#include <StepDimTol_GeometricToleranceWithModifiers.hxx>
81#include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx>
82#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
83#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
42cf5bc1 84#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
6595eee7 85#include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx>
86#include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
42cf5bc1 87#include <StepDimTol_HArray1OfDatumReference.hxx>
6595eee7 88#include <StepDimTol_HArray1OfDatumReferenceElement.hxx>
89#include <StepDimTol_HArray1OfDatumReferenceModifier.hxx>
90#include <StepDimTol_HArray1OfDatumSystemOrReference.hxx>
7fd59977 91#include <StepDimTol_LineProfileTolerance.hxx>
42cf5bc1 92#include <StepDimTol_ModifiedGeometricTolerance.hxx>
93#include <StepDimTol_ParallelismTolerance.hxx>
94#include <StepDimTol_PerpendicularityTolerance.hxx>
6595eee7 95#include <StepDimTol_PlacedDatumTargetFeature.hxx>
7fd59977 96#include <StepDimTol_PositionTolerance.hxx>
97#include <StepDimTol_RoundnessTolerance.hxx>
6595eee7 98#include <StepDimTol_RunoutZoneDefinition.hxx>
99#include <StepDimTol_RunoutZoneOrientation.hxx>
7fd59977 100#include <StepDimTol_StraightnessTolerance.hxx>
101#include <StepDimTol_SurfaceProfileTolerance.hxx>
42cf5bc1 102#include <StepDimTol_SymmetryTolerance.hxx>
6595eee7 103#include <StepDimTol_ToleranceZone.hxx>
104#include <StepDimTol_ToleranceZoneForm.hxx>
42cf5bc1 105#include <StepDimTol_TotalRunoutTolerance.hxx>
6595eee7 106#include <StepGeom_Axis2Placement3d.hxx>
107#include <StepGeom_CartesianPoint.hxx>
108#include <StepGeom_Direction.hxx>
42cf5bc1 109#include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
110#include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
b0cef606 111#include <StepGeom_Plane.hxx>
42cf5bc1 112#include <StepGeom_Surface.hxx>
6595eee7 113#include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx>
114#include <StepRepr_CompositeShapeAspect.hxx>
b7b2f85a 115#include <StepRepr_ConstructiveGeometryRepresentation.hxx>
116#include <StepRepr_ConstructiveGeometryRepresentationRelationship.hxx>
117#include <StepRepr_DerivedShapeAspect.hxx>
7fd59977 118#include <StepRepr_DescriptiveRepresentationItem.hxx>
6595eee7 119#include <StepRepr_FeatureForDatumTargetRelationship.hxx>
42cf5bc1 120#include <StepRepr_HArray1OfRepresentationItem.hxx>
7fd59977 121#include <StepRepr_MeasureRepresentationItem.hxx>
42cf5bc1 122#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
123#include <StepRepr_ProductDefinitionShape.hxx>
124#include <StepRepr_PropertyDefinition.hxx>
6595eee7 125#include <StepRepr_RepresentedDefinition.hxx>
42cf5bc1 126#include <StepRepr_Representation.hxx>
ec357c5c 127#include <StepRepr_RepresentationItem.hxx>
42cf5bc1 128#include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
6595eee7 129#include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx>
130#include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
131#include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx>
42cf5bc1 132#include <StepRepr_ShapeAspect.hxx>
b7b2f85a 133#include <StepRepr_ShapeAspectDerivingRelationship.hxx>
42cf5bc1 134#include <StepRepr_ShapeAspectRelationship.hxx>
135#include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
136#include <StepRepr_ValueRange.hxx>
137#include <StepShape_AdvancedFace.hxx>
6595eee7 138#include <StepShape_AngleRelator.hxx>
139#include <StepShape_AngularLocation.hxx>
140#include <StepShape_AngularSize.hxx>
42cf5bc1 141#include <StepShape_ConnectedFaceSet.hxx>
142#include <StepShape_ContextDependentShapeRepresentation.hxx>
6595eee7 143#include <StepShape_DimensionalCharacteristic.hxx>
42cf5bc1 144#include <StepShape_DimensionalCharacteristicRepresentation.hxx>
6595eee7 145#include <StepShape_DimensionalLocation.hxx>
146#include <StepShape_DimensionalLocationWithPath.hxx>
42cf5bc1 147#include <StepShape_DimensionalSize.hxx>
6595eee7 148#include <StepShape_DimensionalSizeWithPath.hxx>
42cf5bc1 149#include <StepShape_EdgeCurve.hxx>
150#include <StepShape_EdgeLoop.hxx>
151#include <StepShape_FaceBound.hxx>
6595eee7 152#include <StepShape_LimitsAndFits.hxx>
42cf5bc1 153#include <StepShape_OrientedEdge.hxx>
6595eee7 154#include <StepShape_PlusMinusTolerance.hxx>
155#include <StepShape_QualifiedRepresentationItem.hxx>
42cf5bc1 156#include <StepShape_ShapeDefinitionRepresentation.hxx>
157#include <StepShape_ShapeDimensionRepresentation.hxx>
158#include <StepShape_ShapeRepresentation.hxx>
6595eee7 159#include <StepShape_ShapeRepresentationWithParameters.hxx>
160#include <StepShape_ToleranceValue.hxx>
161#include <StepShape_TypeQualifier.hxx>
162#include <StepShape_ValueFormatTypeQualifier.hxx>
b0cef606 163#include <StepVisual_AnnotationPlane.hxx>
42cf5bc1 164#include <StepVisual_CurveStyle.hxx>
b0cef606 165#include <StepVisual_DraughtingCallout.hxx>
166#include <StepVisual_DraughtingModel.hxx>
42cf5bc1 167#include <StepVisual_HArray1OfInvisibleItem.hxx>
168#include <StepVisual_HArray1OfLayeredItem.hxx>
169#include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
170#include <StepVisual_HArray1OfPresentationStyleSelect.hxx>
171#include <StepVisual_Invisibility.hxx>
172#include <StepVisual_InvisibleItem.hxx>
173#include <StepVisual_MechanicalDesignGeometricPresentationRepresentation.hxx>
b0cef606 174#include <StepVisual_NullStyleMember.hxx>
42cf5bc1 175#include <StepVisual_PointStyle.hxx>
176#include <StepVisual_PresentationLayerAssignment.hxx>
ec357c5c 177#include <StepVisual_PresentationRepresentation.hxx>
42cf5bc1 178#include <StepVisual_PresentationStyleAssignment.hxx>
179#include <StepVisual_PresentationStyleByContext.hxx>
180#include <StepVisual_StyledItem.hxx>
181#include <StepVisual_SurfaceStyleUsage.hxx>
b0cef606 182#include <StepVisual_TessellatedAnnotationOccurrence.hxx>
183#include <StepVisual_TessellatedGeometricSet.hxx>
42cf5bc1 184#include <TCollection_AsciiString.hxx>
185#include <TCollection_HAsciiString.hxx>
186#include <TColStd_HArray1OfReal.hxx>
187#include <TColStd_HArray1OfTransient.hxx>
188#include <TColStd_HSequenceOfTransient.hxx>
6595eee7 189#include <TColStd_MapOfAsciiString.hxx>
42cf5bc1 190#include <TColStd_MapOfTransient.hxx>
191#include <TDataStd_Name.hxx>
192#include <TDataStd_TreeNode.hxx>
193#include <TDataStd_UAttribute.hxx>
194#include <TDF_AttributeSequence.hxx>
195#include <TDF_ChildIterator.hxx>
196#include <TDF_Label.hxx>
197#include <TDF_LabelSequence.hxx>
198#include <TDF_Tool.hxx>
199#include <TDocStd_Document.hxx>
200#include <TopoDS_Compound.hxx>
201#include <TopoDS_Iterator.hxx>
202#include <TopoDS_Shape.hxx>
203#include <TopTools_MapOfShape.hxx>
204#include <TopTools_SequenceOfShape.hxx>
205#include <Transfer_ActorOfFinderProcess.hxx>
206#include <Transfer_Binder.hxx>
207#include <Transfer_FinderProcess.hxx>
208#include <Transfer_TransientListBinder.hxx>
209#include <TransferBRep.hxx>
210#include <TransferBRep_ShapeMapper.hxx>
6595eee7 211#include <XCAFDimTolObjects_DatumObject.hxx>
212#include <XCAFDimTolObjects_DimensionFormVariance.hxx>
213#include <XCAFDimTolObjects_DimensionGrade.hxx>
214#include <XCAFDimTolObjects_DimensionObject.hxx>
215#include <XCAFDimTolObjects_DimensionModif.hxx>
216#include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
217#include <XCAFDimTolObjects_DimensionQualifier.hxx>
218#include <XCAFDimTolObjects_GeomToleranceObject.hxx>
42cf5bc1 219#include <XCAFDoc.hxx>
220#include <XCAFDoc_Area.hxx>
221#include <XCAFDoc_Centroid.hxx>
222#include <XCAFDoc_ColorTool.hxx>
223#include <XCAFDoc_Datum.hxx>
6595eee7 224#include <XCAFDoc_Dimension.hxx>
42cf5bc1 225#include <XCAFDoc_DimTol.hxx>
226#include <XCAFDoc_DimTolTool.hxx>
227#include <XCAFDoc_DocumentTool.hxx>
6595eee7 228#include <XCAFDoc_GeomTolerance.hxx>
42cf5bc1 229#include <XCAFDoc_GraphNode.hxx>
230#include <XCAFDoc_LayerTool.hxx>
231#include <XCAFDoc_Material.hxx>
232#include <XCAFDoc_MaterialTool.hxx>
233#include <XCAFDoc_ShapeTool.hxx>
234#include <XCAFDoc_Volume.hxx>
235#include <XCAFPrs.hxx>
236#include <XCAFPrs_DataMapIteratorOfDataMapOfStyleShape.hxx>
237#include <XCAFPrs_DataMapOfShapeStyle.hxx>
238#include <XCAFPrs_DataMapOfStyleShape.hxx>
239#include <XCAFPrs_Style.hxx>
240#include <XSControl_TransferWriter.hxx>
241#include <XSControl_WorkSession.hxx>
7fd59977 242
b0cef606 243static NCollection_Vector<Handle(StepVisual_AnnotationPlane)> gdtAnnotationPlanes;
244static Handle(StepVisual_DraughtingModel) gdtPresentationDM;
245static Handle(StepVisual_HArray1OfPresentationStyleAssignment) gdtPrsCurveStyle;
6595eee7 246
42cf5bc1 247// added by skl 15.01.2004 for D&GT writing
248//#include <StepRepr_CompoundItemDefinition.hxx>
249//#include <StepRepr_CompoundItemDefinitionMember.hxx>
250// added by skl 12.02.2004 for writing materials
7fd59977 251//=======================================================================
252//function : GetLabelName
253//purpose : auxilary function: take name of label and append it to str
254//=======================================================================
255static Standard_Boolean GetLabelName (const TDF_Label &L, Handle(TCollection_HAsciiString) &str)
256{
257 Handle(TDataStd_Name) N;
258 if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) return Standard_False;
259 TCollection_ExtendedString name = N->Get();
260 if ( name.Length() <=0 ) return Standard_False;
261
262 // set name, converting it to Ascii and removing spaces
263 TCollection_AsciiString buf ( name, '?' );
264 buf.LeftAdjust();
265 buf.RightAdjust();
266 buf.ChangeAll(' ','_');
267 str->AssignCat ( buf.ToCString() );
268 return Standard_True;
269}
270
271
272//=======================================================================
273//function : STEPCAFControl_Writer
274//purpose :
275//=======================================================================
276
277STEPCAFControl_Writer::STEPCAFControl_Writer () :
278 myColorMode( Standard_True ),
279 myNameMode ( Standard_True ),
280 myLayerMode( Standard_True ),
281 myPropsMode( Standard_True ),
282 mySHUOMode ( Standard_True ),
283 myDGTMode ( Standard_True ),
284 myMatMode ( Standard_True )
285{
286 STEPCAFControl_Controller::Init();
287 Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
288 Init ( WS );
289}
290
291
292//=======================================================================
293//function : STEPCAFControl_Writer
294//purpose :
295//=======================================================================
296
297STEPCAFControl_Writer::STEPCAFControl_Writer (const Handle(XSControl_WorkSession)& WS,
298 const Standard_Boolean scratch)
299{
300 STEPCAFControl_Controller::Init();
301 Init ( WS, scratch );
302 myColorMode = Standard_True;
303 myNameMode = Standard_True;
304 myLayerMode = Standard_True;
305 myPropsMode = Standard_True;
306 mySHUOMode = Standard_True;
307}
308
309
310//=======================================================================
311//function : Init
312//purpose :
313//=======================================================================
314
315void STEPCAFControl_Writer::Init (const Handle(XSControl_WorkSession)& WS,
316 const Standard_Boolean scratch)
317{
318 WS->SelectNorm ( "STEP" );
319 myWriter.SetWS (WS,scratch);
320 myFiles = new STEPCAFControl_DictionaryOfExternFile;
321 myLabEF.Clear();
322 myLabels.Clear();
323}
324
325
326//=======================================================================
327//function : Write
328//purpose :
329//=======================================================================
330
331IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filename)
332{
333 IFSelect_ReturnStatus status = myWriter.Write ( filename );
334
335 // get directory name of the main file
336 OSD_Path mainfile ( filename );
337 mainfile.SetName ( "" );
338 mainfile.SetExtension ( "" );
339 TCollection_AsciiString dpath;
340 mainfile.SystemName ( dpath );
341
342 STEPCAFControl_IteratorOfDictionaryOfExternFile it ( myFiles );
343 for ( ; it.More(); it.Next() ) {
344 Handle(STEPCAFControl_ExternFile) EF = it.Value();
345 if ( EF->GetWriteStatus() != IFSelect_RetVoid ) continue;
346
347 // construct extern file name
348 TCollection_AsciiString fname = OSD_Path::AbsolutePath ( dpath, EF->GetName()->String() );
349 if ( fname.Length() <= 0 ) fname = EF->GetName()->String();
0797d9d3 350#ifdef OCCT_DEBUG
7fd59977 351 cout << "Writing external file: " << fname.ToCString() << endl;
352#endif
353
354 EF->SetWriteStatus ( EF->GetWS()->SendAll ( fname.ToCString() ) );
355 }
356
357 return status;
358}
359
360
361//=======================================================================
362//function : Transfer
363//purpose :
364//=======================================================================
365
1b44ab4b 366Standard_Boolean STEPCAFControl_Writer::Transfer( const Handle(TDocStd_Document) &doc,
7fd59977 367 const STEPControl_StepModelType mode,
1b44ab4b 368 const Standard_CString multi )
7fd59977 369{
370 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
371 if ( STool.IsNull() ) return Standard_False;
372
373 TDF_LabelSequence labels;
374 STool->GetFreeShapes ( labels );
375 return Transfer ( myWriter, labels, mode, multi );
376}
377
378
379//=======================================================================
380//function : Transfer
381//purpose :
382//=======================================================================
383
1b44ab4b 384Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_Label& L,
7fd59977 385 const STEPControl_StepModelType mode,
1b44ab4b 386 const Standard_CString multi )
7fd59977 387{
388 TDF_LabelSequence labels;
389 labels.Append ( L );
390 return Transfer ( myWriter, labels, mode, multi );
391}
392
1b44ab4b 393//=======================================================================
394//function : Transfer
395//purpose :
396//=======================================================================
397
398Standard_Boolean STEPCAFControl_Writer::Transfer( const TDF_LabelSequence& labels,
399 const STEPControl_StepModelType mode,
400 const Standard_CString multi )
401{
402 return Transfer( myWriter, labels, mode, multi );
403}
7fd59977 404
405//=======================================================================
406//function : Perform
407//purpose :
408//=======================================================================
409
410Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
411 const Standard_CString filename)
412{
413 if ( ! Transfer ( doc ) ) return Standard_False;
414 return Write ( filename ) == IFSelect_RetDone;
415}
416
417
418//=======================================================================
419//function : Perform
420//purpose :
421//=======================================================================
422
423Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
424 const TCollection_AsciiString &filename)
425{
426 if ( ! Transfer ( doc ) ) return Standard_False;
427 return Write ( filename.ToCString() ) == IFSelect_RetDone;
428}
429
430
431//=======================================================================
432//function : ExternFiles
433//purpose :
434//=======================================================================
435
436const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Writer::ExternFiles () const
437{
438 return myFiles;
439}
440
441
442//=======================================================================
443//function : ExternFile
444//purpose :
445//=======================================================================
446
447Standard_Boolean STEPCAFControl_Writer::ExternFile (const TDF_Label &L,
448 Handle(STEPCAFControl_ExternFile) &ef) const
449{
450 ef.Nullify();
451 if ( ! myLabEF.IsBound ( L ) ) return Standard_False;
452 ef = myLabEF.Find ( L );
453 return Standard_True;
454}
455
456
457//=======================================================================
458//function : ExternFile
459//purpose :
460//=======================================================================
461
462Standard_Boolean STEPCAFControl_Writer::ExternFile (const Standard_CString name,
463 Handle(STEPCAFControl_ExternFile) &ef) const
464{
465 ef.Nullify();
466 if ( ! myFiles.IsNull() || ! myFiles->HasItem ( name ) )
467 return Standard_False;
468 ef = myFiles->Item ( name );
469 return Standard_True;
470}
471
472
473//=======================================================================
474//function : Writer
475//purpose :
476//=======================================================================
477
478STEPControl_Writer &STEPCAFControl_Writer::ChangeWriter ()
479{
480 return myWriter;
481}
482
483
484//=======================================================================
485//function : Writer
486//purpose :
487//=======================================================================
488
489const STEPControl_Writer &STEPCAFControl_Writer::Writer () const
490{
491 return myWriter;
492}
493
494
495//=======================================================================
496//function : Transfer
497//purpose :
498//=======================================================================
499
500Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
501 const TDF_LabelSequence &labels,
502 const STEPControl_StepModelType mode,
503 const Standard_CString multi,
504 const Standard_Boolean isExternFile)
505{
506 if ( labels.Length() <=0 ) return Standard_False;
507
508 Handle(STEPCAFControl_ActorWrite) Actor =
509 Handle(STEPCAFControl_ActorWrite)::DownCast ( writer.WS()->NormAdaptor()->ActorWrite() );
510
511 // translate free top-level shapes of the DECAF document
7fd59977 512 Standard_Integer ap = Interface_Static::IVal ("write.step.schema");
513 TDF_LabelSequence sublabels;
514 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
515 TDF_Label L = labels.Value(i);
516 TopoDS_Shape dummy;
517 if ( myLabels.IsBound ( L ) ) continue; // already processed
518
519 TopoDS_Shape shape = XCAFDoc_ShapeTool::GetShape ( L );
520 if ( shape.IsNull() ) continue;
521
522 // write shape either as a whole, or as multifile (with extern refs)
f5e92b04 523 if ( ! multi ) {
7fd59977 524 Actor->SetStdMode ( Standard_False );
525
7fd59977 526 TDF_LabelSequence comp;
f5e92b04 527
528 //for case when only part of assemby structure should be written in the document
529 //if specified label is component of the assembly then
530 //in order to save location of this component in the high-level assembly
531 //and save name of high-level assembly it is necessary to represent structure of high-level assembly
532 //as assembly with one component specified by current label.
533 //For that compound containing only specified component is binded to the label of the high-level assembly.
534 //The such way full structure of high-level assembly was replaced on the assembly contaning one component.
535 if ( XCAFDoc_ShapeTool::IsComponent ( L ) )
536 {
537 TopoDS_Compound aComp;
538 BRep_Builder aB;
539 aB.MakeCompound(aComp);
540 aB.Add(aComp, shape);
541 shape = aComp;
542 comp.Append(L);
543 TDF_Label ref;
544 if ( XCAFDoc_ShapeTool::GetReferredShape ( L, ref ) )
545 {
546 if(XCAFDoc_ShapeTool::IsAssembly ( ref))
547 XCAFDoc_ShapeTool::GetComponents ( ref, comp, Standard_True );
548 }
549 L = L.Father();
550 }
551 else
552 {
553 // fill sequence of (sub) shapes for which attributes should be written
554 // and set actor to handle assemblies in a proper way
555 if(XCAFDoc_ShapeTool::IsAssembly ( L ))
556 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_True );
557 }
558
7fd59977 559 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
f5e92b04 560 TDF_Label ref;
561 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( comp(k), ref ) ) continue;
562 if ( ! myLabels.IsBound ( ref ) ) {
563 TopoDS_Shape refS = XCAFDoc_ShapeTool::GetShape ( ref );
564 myLabels.Bind ( ref, refS );
565 sublabels.Append ( ref );
566 if ( XCAFDoc_ShapeTool::IsAssembly ( ref ) )
567 Actor->RegisterAssembly ( refS );
568 }
7fd59977 569 }
570 myLabels.Bind ( L, shape );
571 sublabels.Append ( L );
572 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) )
f5e92b04 573 Actor->RegisterAssembly ( shape );
7fd59977 574
575 writer.Transfer(shape,mode,Standard_False);
576 Actor->SetStdMode ( Standard_True ); // restore default behaviour
577 }
578 else {
579 // translate final solids
580 TopoDS_Shape Sass = TransferExternFiles ( L, mode, sublabels, multi );
581
582 // translate main assembly structure
583/*
584 if ( ap == 3 ) { // if AP203, switch to AP214
585 Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
586 Handle(StepData_StepModel) model =
587 Handle(StepData_StepModel)::DownCast ( writer.WS()->Model() );
588 if ( model->HasHeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) ) {
589 Handle(HeaderSection_FileSchema) fs =
590 Handle(HeaderSection_FileSchema)::DownCast ( model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) );
591 Handle(TCollection_HAsciiString) str = fs->SchemaIdentifiersValue ( 1 );
592 Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "AUTOMOTIVE_DESIGN" );
593 if ( str->Search ( ap214 ) <0 ) {
594 str->Clear();
595 str->AssignCat ( ap214 );
596 }
597 }
598 }
599*/
600 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
601 Interface_Static::SetCVal ("write.step.assembly", "On");
602 writer.Transfer ( Sass, STEPControl_AsIs );
603 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
604 Interface_Static::SetIVal ("write.step.schema", ap);
605 }
606 }
607
608 writer.WS()->ComputeGraph(Standard_True );// added by skl 03.11.2003 since we use
609 // writer.Transfer() wihtout compute graph
610
611 // write names
612 if ( GetNameMode() )
613 WriteNames ( writer.WS(), sublabels );
614
615 if ( !multi ) {
616 // write colors
617 if ( GetColorMode() )
618 WriteColors ( writer.WS(), sublabels );
619
620 // write layers
621 if ( GetLayerMode() )
622 WriteLayers ( writer.WS(), sublabels );
623
624 // write SHUO entities
625 if ( GetSHUOMode() && !isExternFile )
626 // do not store SHUO for extern reference for the moment
627 WriteSHUOs ( writer.WS(), sublabels );
628
629 // write G&DTs
d658f275 630 if(GetDimTolMode()) {
631 if (ap == 5) {
632 WriteDGTsAP242(writer.WS(), sublabels);
633 }
634 else {
635 WriteDGTs(writer.WS(), sublabels);
636 }
637 }
7fd59977 638
639 // write Materials
640 if(GetMaterialMode())
641 WriteMaterials(writer.WS(),sublabels);
642
643 // register all MDGPRs in model
7f56eba8 644 const Handle(Interface_InterfaceModel) &Model = writer.WS()->Model();
7fd59977 645 MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR);
7f56eba8 646 for (; anItr.More(); anItr.Next())
7fd59977 647 Model->AddWithRefs( anItr.Value() );
7fd59977 648 }
649
650 if ( multi ) { // external refs
651 WriteExternRefs ( writer.WS(), sublabels );
652 }
653
654 // write validation props
655// if ( multi && ap ==3 ) {
656// Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
657// }
658 if ( GetPropsMode() )
659 WriteValProps ( writer.WS(), sublabels, multi );
660
661 Interface_Static::SetIVal ("write.step.schema", ap);
662
663 // refresh graph
664 writer.WS()->ComputeGraph ( Standard_True );
665
02a0b964 666 /* ================================
667 * Write names for the sub-shapes
668 * ================================ */
669
670 if ( Interface_Static::IVal("write.stepcaf.subshapes.name") )
671 {
7f56eba8 672 const Handle(XSControl_TransferWriter) &TW = this->ChangeWriter().WS()->TransferWriter();
673 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
02a0b964 674
675 for ( int i = 1; i <= labels.Length(); i++ )
676 {
677 TDF_Label L = labels.Value(i);
678
679 for ( TDF_ChildIterator it(L, Standard_True); it.More(); it.Next() )
680 {
681 TDF_Label SubL = it.Value();
682
683 // Access name recorded in OCAF TDataStd_Name attribute
684 Handle(TCollection_HAsciiString) hSubName = new TCollection_HAsciiString;
685 if ( !GetLabelName(SubL, hSubName) )
686 continue;
687
688 // Access topological data
689 TopoDS_Shape SubS = XCAFDoc_ShapeTool::GetShape(SubL);
690 if ( SubS.IsNull() )
691 continue;
692
693 // Access the correspondent STEP Representation Item
694 Handle(StepRepr_RepresentationItem) RI;
695 Handle(TransferBRep_ShapeMapper) aShMapper = TransferBRep::ShapeMapper(FP, SubS);
696 if ( !FP->FindTypedTransient(aShMapper, STANDARD_TYPE(StepRepr_RepresentationItem), RI) )
697 continue;
698
699 // Record the name
700 RI->SetName(hSubName);
701 }
702 }
703 }
704
7fd59977 705 return Standard_True;
706}
707
708
709//=======================================================================
710//function : TransferExternFiles
711//purpose :
712//=======================================================================
713
714TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L,
715 const STEPControl_StepModelType mode,
716 TDF_LabelSequence &labels,
717 const Standard_CString prefix)
718{
719 // if label already translated, just return the shape
720 if ( myLabels.IsBound ( L ) ) {
721 return myLabels.Find ( L );
722 }
723
724 TopoDS_Compound C;
725 BRep_Builder B;
726 B.MakeCompound ( C );
f5e92b04 727 //labels.Append ( L );
7fd59977 728 // if not assembly, write to separate file
f5e92b04 729 if ( ! XCAFDoc_ShapeTool::IsAssembly ( L ) && !XCAFDoc_ShapeTool::IsComponent ( L )) {
730 labels.Append ( L );
7fd59977 731 // prepare for transfer
732 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
733 newWS->SelectNorm ( "STEP" );
734 STEPControl_Writer sw ( newWS, Standard_True );
735 TDF_LabelSequence Lseq;
736 Lseq.Append ( L );
737
738 // construct the name for extern file
739 Handle(TCollection_HAsciiString) basename = new TCollection_HAsciiString;
740 if ( prefix && prefix[0] ) basename->AssignCat ( prefix );
741 GetLabelName ( L, basename );
742 Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString ( basename );
743 name->AssignCat ( ".stp" );
744 if ( myFiles->HasItem ( name->ToCString() ) ) { // avoid confusions
745 for ( Standard_Integer k=1; k < 32000; k++ ) {
746 name = new TCollection_HAsciiString ( basename );
747 name->AssignCat ( "_" );
748 name->AssignCat ( TCollection_AsciiString ( k ).ToCString() );
749 name->AssignCat ( ".stp" );
750 if ( ! myFiles->HasItem ( name->ToCString() ) ) break;
751 }
752 }
753
754 // translate and record extern file
755 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
756 EF->SetWS ( newWS );
757 EF->SetName ( name );
758 EF->SetLabel ( L );
759 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
760 Interface_Static::SetCVal ("write.step.assembly", "Off");
761 const Standard_CString multi = 0;
762 EF->SetTransferStatus ( Transfer ( sw, Lseq, mode, multi, Standard_True ) );
763 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
764 myLabEF.Bind ( L, EF );
765 myFiles->SetItem ( name->ToCString(), EF );
766
767 // return empty compound as replacement for the shape
768 myLabels.Bind ( L, C );
769 return C;
770 }
f5e92b04 771 TDF_LabelSequence comp;
772 TDF_Label aCurL = L;
773 //if specified shape is component then high-level assembly is considered
774 //to get valid structure with location
775 if ( XCAFDoc_ShapeTool::IsComponent ( L ) )
776 {
777 comp.Append(L);
778 aCurL = L.Father();
779 }
7fd59977 780 // else iterate on components add create structure of empty compounds
781 // representing the assembly
f5e92b04 782 else if (XCAFDoc_ShapeTool::IsAssembly ( L ))
783 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_False );
784
785 labels.Append ( aCurL );
7fd59977 786 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
787 TDF_Label lab = comp(k);
788 TDF_Label ref;
789 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, ref ) ) continue;
790 TopoDS_Shape Scomp = TransferExternFiles ( ref, mode, labels, prefix );
791 Scomp.Location ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
792 B.Add ( C, Scomp );
793 }
f5e92b04 794 myLabels.Bind ( aCurL, C );
7fd59977 795 return C;
796}
797
798
799//=======================================================================
800//function : WriteExternRefs
801//purpose :
802//=======================================================================
803
804Standard_Boolean STEPCAFControl_Writer::WriteExternRefs (const Handle(XSControl_WorkSession) &WS,
805 const TDF_LabelSequence &labels) const
806{
807 if ( labels.Length() <=0 ) return Standard_False;
808
7f56eba8 809 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
810 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
7fd59977 811 STEPConstruct_ExternRefs EFTool ( WS );
812 Standard_Integer schema = Interface_Static::IVal("write.step.schema");
813 for ( Standard_Integer k=1; k <= labels.Length(); k++ ) {
814 TDF_Label lab = labels(k);
815 if ( XCAFDoc_ShapeTool::IsAssembly ( lab ) ) continue; // skip assemblies
816
817 // get extern file
818 Handle(STEPCAFControl_ExternFile) EF;
819 if ( ! ExternFile ( lab, EF ) ) continue; // should never be
820
821 // find SDR
822 if ( ! myLabels.IsBound ( lab ) ) continue; // not recorded as translated, skip
823 TopoDS_Shape S = myLabels.Find ( lab );
824
825 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
826 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
827 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
0797d9d3 828#ifdef OCCT_DEBUG
7fd59977 829 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
830#endif
831 continue;
832 }
833
834 // add extern ref
835 const Standard_CString format = (const Standard_CString) ( schema == 3 ? "STEP AP203" : "STEP AP214" );
836 // try to get PD from SDR
837 StepRepr_RepresentedDefinition RD = SDR->Definition();
838 Handle(StepRepr_PropertyDefinition) aPropDef = RD.PropertyDefinition();
839 if (aPropDef.IsNull()) {
0797d9d3 840#ifdef OCCT_DEBUG
7fd59977 841 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepRepr_PropertyDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
842#endif
843 continue;
844 }
845 StepRepr_CharacterizedDefinition CharDef = aPropDef->Definition();
846 Handle(StepBasic_ProductDefinition) PD = CharDef.ProductDefinition();
847 if (PD.IsNull()) {
0797d9d3 848#ifdef OCCT_DEBUG
7fd59977 849 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepBasic_ProductDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
850#endif
851 continue;
852 }
853 EFTool.AddExternRef ( EF->GetName()->ToCString(), PD, format );
854 }
855 EFTool.WriteExternRefs(schema);
856 return Standard_True;
857}
858
859
860//=======================================================================
861//function : FindEntities
862//purpose : auxilary
863//=======================================================================
864static Standard_Integer FindEntities (const Handle(Transfer_FinderProcess) &FP,
865 const TopoDS_Shape &S,
866 TopLoc_Location &L,
867 TColStd_SequenceOfTransient &seqRI)
868{
869 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, S, L );
870
871 if ( ! item.IsNull() ) {
872 seqRI.Append ( item );
873 return 1;
874 }
875
876 // may be S was splited during shape processing
877 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
878 Handle(Transfer_Binder) bnd = FP->Find ( mapper );
879 if ( bnd.IsNull() ) return 0;
880
881 Handle(Transfer_TransientListBinder) TransientListBinder =
882 //Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) );
883 Handle(Transfer_TransientListBinder)::DownCast( bnd );
884 Standard_Integer nres=0;
885 if ( TransientListBinder.IsNull() && S.ShapeType() == TopAbs_COMPOUND)
886 {
887 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
51740958 888 Handle(StepRepr_RepresentationItem) aLocalItem = STEPConstruct::FindEntity ( FP, it.Value(), L );
889 if (aLocalItem.IsNull() ) continue;
7fd59977 890 nres++;
51740958 891 seqRI.Append (aLocalItem);
7fd59977 892 }
893 }
894 else
895 {
896 const Standard_Integer nb = TransientListBinder->NbTransients();
897 for (Standard_Integer i=1; i<=nb; i++) {
898 Handle(Standard_Transient) t = TransientListBinder->Transient(i);
899 item = Handle(StepRepr_RepresentationItem)::DownCast(t);
900 if ( item.IsNull() ) continue;
901 nres++;
902 seqRI.Append ( item );
903 }
904 }
905/* works but is obsolete: another approach
906 if (i<=nb) {
907 TopoDS_Shape comp = TransferBRep::ShapeResult(bnd);
908 if ( ! comp.IsNull() && comp.ShapeType() < S.ShapeType() ) {
909 for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) {
910 MakeSTEPStyles(Styles, it.Value(), settings, STEPstyle,
911 Map, ( hasOwn ? &style : 0 ) );
912 }
913 }
914 }
915*/
916 return nres;
917}
918
919
920//=======================================================================
921//function : getStyledItem
922//purpose : auxilary
923//=======================================================================
924static Standard_Boolean getStyledItem(const TopoDS_Shape& S,
925 const Handle(XCAFDoc_ShapeTool)& STool,
926 const STEPConstruct_Styles &Styles,
927 Handle(StepVisual_StyledItem) &resSelItem,
928 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
929{
930 TDF_Label aTopShL = STool->FindShape(S, Standard_False);
931 TopoDS_Shape aTopLevSh = STool->GetShape( aTopShL );
932 Standard_Boolean found = Standard_False;
933 if ( !aTopLevSh.IsNull() && myMapCompMDGPR.IsBound( aTopLevSh ) ) {
934 Handle(StepVisual_PresentationRepresentation) aMDGPR =
935 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopLevSh ) );
936 Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items();
937 // search for PSA of Monifold solid
938 if ( !anSelItmHArr.IsNull() )
939 {
940 for (Standard_Integer si = 1; si <= anSelItmHArr->Length(); si++) {
941 Handle(StepVisual_StyledItem) aSelItm =
942 Handle(StepVisual_StyledItem)::DownCast(anSelItmHArr->Value(si));
943
944 if ( aSelItm.IsNull() )
945 continue;
946
947 // check that it is a stiled item for monifold solid brep
948 TopLoc_Location Loc;
949 TColStd_SequenceOfTransient aNewseqRI;
950 FindEntities ( Styles.FinderProcess(), aTopLevSh, Loc, aNewseqRI );
951 if ( aNewseqRI.Length() > 0 )
952 {
953
954 Handle(StepRepr_RepresentationItem) anItem = aSelItm->Item();
955 Standard_Boolean isSameMonSolBR = Standard_False;
956 for (Standard_Integer mi = 1; mi <= aNewseqRI.Length(); mi++) {
957 if ( !anItem.IsNull() && anItem == aNewseqRI.Value( mi ) ) {
958 isSameMonSolBR = Standard_True;
959 break;
960 }
961 }
962 if (!isSameMonSolBR)
963 continue;
964 }
965
966
967 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
a9dde4a3 968 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA = aSelItm->StylesValue(jsi);
7fd59977 969 // check for PSA for top-level (not Presentation style by contex for NAUO)
970 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
971 continue;
972 resSelItem = aSelItm;
973 found = Standard_True;
974 }
975 }
976 }
977 }
978 return found;
979}
980
981
982//=======================================================================
983//function : setDefaultInstanceColor
984//purpose : auxilary
985//=======================================================================
986static Standard_Boolean setDefaultInstanceColor (const Handle(StepVisual_StyledItem) &aSelItm,
987 Handle(StepVisual_PresentationStyleAssignment)& PSA)
988{
989 Standard_Boolean found = Standard_False;
990 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
a9dde4a3 991 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA = aSelItm->StylesValue(jsi);
7fd59977 992 // check for PSA for top-level (not Presentation style by contex for NAUO)
993 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
994 return Standard_False;
995
996 // get style select from father PSA
997 if (aFatherPSA->NbStyles() > 0) {
998 Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles =
999 new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles());
1000 for (Standard_Integer k = 1; k <= aFatherPSA->NbStyles(); k++) {
1001 StepVisual_PresentationStyleSelect PSS;
1002 StepVisual_PresentationStyleSelect olDPSS = aFatherPSA->StylesValue(k);
1003 if (!olDPSS.PointStyle().IsNull())
1004 PSS.SetValue (olDPSS.PointStyle());
1005 else if (!olDPSS.CurveStyle().IsNull())
1006 PSS.SetValue (olDPSS.CurveStyle());
1007 else if (!olDPSS.SurfaceStyleUsage().IsNull())
1008 PSS.SetValue (olDPSS.SurfaceStyleUsage());
1009 else {
1010 found = Standard_False;
1011 break;
1012 }
1013 //aFatherStyles->SetValue( k, PSS );
1014 aFatherStyles->SetValue( k, olDPSS );
1015 found = Standard_True;
1016 }
1017 // init PSA of NAUO
1018 if (found) {
1019 PSA->Init( aFatherStyles );
1020 }
1021 }
1022
1023 }
1024 return found;
1025}
1026
1027
1028//=======================================================================
1029//function : MakeSTEPStyles
1030//purpose : auxilary
1031//=======================================================================
1032static void MakeSTEPStyles (STEPConstruct_Styles &Styles,
1033 const TopoDS_Shape &S,
1034 const XCAFPrs_DataMapOfShapeStyle &settings,
1035 Handle(StepVisual_StyledItem) &override,
1036 TopTools_MapOfShape &Map,
1037 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR,
1038 STEPConstruct_DataMapOfAsciiStringTransient &DPDCs,
1039 STEPConstruct_DataMapOfPointTransient &ColRGBs,
1040 const Handle(XCAFDoc_ColorTool)& CTool,
1041 const XCAFPrs_Style *inherit = 0,
1042 const Standard_Boolean isComponent = Standard_False)
1043{
1044 // skip already processed shapes
1045 if ( ! Map.Add ( S ) ) return;
1046
1047 // check if shape has its own style (r inherits from ancestor)
1048 XCAFPrs_Style style;
1049 if ( inherit ) style = *inherit;
1050 if ( settings.IsBound(S) ) {
1051 XCAFPrs_Style own = settings.Find(S);
1052 if ( !own.IsVisible() ) style.SetVisibility ( Standard_False );
1053 if ( own.IsSetColorCurv() ) style.SetColorCurv ( own.GetColorCurv() );
1054 if ( own.IsSetColorSurf() ) style.SetColorSurf ( own.GetColorSurf() );
1055 }
1056
1057 // translate colors to STEP
1058 Handle(StepVisual_Colour) surfColor, curvColor;
1059 if ( style.IsSetColorSurf() )
1060 surfColor = Styles.EncodeColor(style.GetColorSurf(),DPDCs,ColRGBs);
1061 if ( style.IsSetColorCurv() )
1062 curvColor = Styles.EncodeColor(style.GetColorCurv(),DPDCs,ColRGBs);
1063
1064 Standard_Boolean hasOwn = ( ! surfColor.IsNull() ||
1065 ! curvColor.IsNull() ||
1066 ! style.IsVisible() );
1067
1068 // find target item and assign style to it
1069 Handle(StepVisual_StyledItem) STEPstyle = override;
1070 if ( hasOwn ) {
1071 if ( S.ShapeType() != TopAbs_COMPOUND || isComponent ) { // skip compounds, let subshapes inherit its colors
1072 TopLoc_Location L;
1073 TColStd_SequenceOfTransient seqRI;
1074 Standard_Integer nb = FindEntities ( Styles.FinderProcess(), S, L, seqRI );
0797d9d3 1075#ifdef OCCT_DEBUG
7fd59977 1076 if ( nb <=0 ) cout << "Warning: Cannot find RI for " << S.TShape()->DynamicType()->Name() << endl;
1077#endif
1078 //Get overridden style gka 10.06.03
1079 if ( isComponent && nb)
1080 getStyledItem(S, CTool->ShapeTool(), Styles, override,myMapCompMDGPR);
1081
1082
1083 for ( Standard_Integer i=1; i <= nb; i++ ) {
1084 Handle(StepRepr_RepresentationItem) item =
1085 Handle(StepRepr_RepresentationItem)::DownCast(seqRI(i));
1086 Handle(StepVisual_PresentationStyleAssignment) PSA;
1087 if ( style.IsVisible() || !surfColor.IsNull() || !curvColor.IsNull() ) {
1088 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1089 }
1090 else {
1091 // default white color
1092 surfColor = Styles.EncodeColor(Quantity_Color(1,1,1,Quantity_TOC_RGB),DPDCs,ColRGBs);
1093 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1094 if ( isComponent )
1095 setDefaultInstanceColor( override, PSA);
1096
1097 } // end of component case
1098
1099 STEPstyle = Styles.AddStyle ( item, PSA, override );
1100 hasOwn = Standard_False;
1101 }
1102 }
1103 }
1104
1105 // iterate on subshapes (except vertices :)
1106 if ( S.ShapeType() == TopAbs_EDGE ) return;
1107 if ( !isComponent ) // PTV 10.02.2003
1108 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
1109 MakeSTEPStyles ( Styles, it.Value(), settings, STEPstyle,
1110 Map, myMapCompMDGPR, DPDCs, ColRGBs, CTool,
1111 ( hasOwn ? &style : 0 ) );
1112 }
1113}
1114
1115/*
1116static Standard_Boolean getFatherColor (const TDF_Label& L,
1117 const Handle(XCAFDoc_ColorTool)& CTool,
1118 XCAFPrs_Style& style)
1119{
1120 Standard_Boolean done = Standard_False;
1121 TopoDS_Shape aSh = CTool->ShapeTool()->GetShape( L );
1122 TDF_Label aFL = CTool->ShapeTool()->FindShape( aSh );
1123 if (aFL.IsNull() || aFL == L)
1124 return done;
1125 Quantity_Color C;
1126 if ( CTool->GetColor ( aFL, XCAFDoc_ColorGen, C ) ) {
1127 style.SetColorCurv ( C );
1128 style.SetColorSurf ( C );
1129 done = Standard_True;
1130 }
1131 if ( CTool->GetColor ( aFL, XCAFDoc_ColorSurf, C ) ) {
1132 style.SetColorSurf ( C );
1133 done = Standard_True;
1134 }
1135 if ( CTool->GetColor ( aFL, XCAFDoc_ColorCurv, C ) ) {
1136 style.SetColorCurv ( C );
1137 done = Standard_True;
1138 }
1139
1140 return done;
1141}
1142*/
1143
1144
1145//=======================================================================
1146//function : WriteColors
1147//purpose :
1148//=======================================================================
1149
1150Standard_Boolean STEPCAFControl_Writer::WriteColors (const Handle(XSControl_WorkSession) &WS,
1151 const TDF_LabelSequence &labels)
1152{
1153 if ( labels.Length() <=0 ) return Standard_False;
1154
1155 // Iterate on shapes in the document
1156 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1157 if ( CTool.IsNull() ) return Standard_False;
1158
1159 STEPConstruct_Styles Styles ( WS );
1160 STEPConstruct_DataMapOfAsciiStringTransient DPDCs;
1161 STEPConstruct_DataMapOfPointTransient ColRGBs;
1162 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1163 TDF_Label L = labels.Value(i);
1164
1165 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1166 // Skip assemblies: colors assigned to assemblies and their instances
1167 // are not supported (it is not clear how to encode that in STEP)
1168 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
0797d9d3 1169#ifdef OCCT_DEBUG
7fd59977 1170 cout << "Warning: Cannot write color for Assembly" << endl;
1171 cout << "Info: Check for colors assigned to components in assembly" << endl;
1172#endif
1173 // PTV 22.01.2003 Write color for instances.
1174 TDF_LabelSequence compLabels;
1175 if ( aSTool.IsNull() )
1176 continue;
1177 if (!aSTool->GetComponents(L, compLabels))
1178 continue;
1179 WriteColors(WS, compLabels);
1180 continue;
1181 }
1182 Styles.ClearStyles();
1183
1184 // get a target shape and try to find corresponding context
1185 // (all the colors set under that label will be put into that context)
1186 TopoDS_Shape S;
1187 if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1188 Standard_Boolean isComponent = aSTool->IsComponent( L );
1189 TopoDS_Shape aTopSh = S;
1190 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext ( S );
1191 if ( isComponent ) {
1192 TDF_Label aTopShL = aSTool->FindShape(S, Standard_False);
1193 if (aTopShL.IsNull())
1194 continue;
1195 aTopSh = aSTool->GetShape( aTopShL );
1196 Context = Styles.FindContext ( aTopSh );
1197 }
1198 if ( Context.IsNull() )
1199 continue;
1200
1201 // collect settings set on that label
1202 XCAFPrs_DataMapOfShapeStyle settings;
1203 TDF_LabelSequence seq;
1204 seq.Append ( L );
1205 XCAFDoc_ShapeTool::GetSubShapes ( L, seq );
1206 Standard_Boolean isVisible = Standard_True;
1207 for ( Standard_Integer j = 1; j <= seq.Length(); j++ ) {
1208 TDF_Label lab = seq.Value(j);
1209 XCAFPrs_Style style;
1210 Quantity_Color C;
574d7236 1211 if ( lab == L ) {
7fd59977 1212 // check for invisible status of object on label
1213 if ( !CTool->IsVisible( lab ) ) {
1214 isVisible = Standard_False;
1215 style.SetVisibility( Standard_False );
1216 }
1217 }
1218 if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) {
ec99ba32
G
1219 style.SetColorCurv ( C );
1220 style.SetColorSurf ( C );
7fd59977 1221 }
1222 if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) )
ec99ba32 1223 style.SetColorSurf ( C );
7fd59977 1224 if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) )
ec99ba32
G
1225 style.SetColorCurv ( C );
1226
7fd59977 1227 // commented, cause we are need to take reference from
1228// if ( isComponent && lab == L && !isVisible)
1229// if ( !style.IsSetColorSurf() && !style.IsSetColorCurv() ) {
1230// getFatherColor ( L, CTool, style);
1231// }
1232 if ( ! style.IsSetColorCurv() && ! style.IsSetColorSurf() && isVisible ) continue;
1233
1234 TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab );
1235 settings.Bind ( sub, style );
1236 }
1237
1238 if ( settings.Extent() <=0 ) continue;
1239
1240 // iterate on subshapes and create STEP styles
1241 Handle(StepVisual_StyledItem) override;
1242 TopTools_MapOfShape Map;
1243
1244 MakeSTEPStyles(Styles,S,settings,override,Map,myMapCompMDGPR,DPDCs,ColRGBs,CTool,0,isComponent);
1245
1246 // create MDGPR and record it in model
1247 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1248
1249 if (!isComponent) {
1250 if ( myMapCompMDGPR.IsBound( aTopSh )) {
0797d9d3 1251#ifdef OCCT_DEBUG
7fd59977 1252 cerr << "Error: Current Top-Level shape have MDGPR already " << endl;
1253#endif
1254 }
1255 Styles.CreateMDGPR ( Context, aMDGPR );
1256 if (!aMDGPR.IsNull())
1257 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1258 }
1259 else {
1260 // create SDR and add to model.
7f56eba8 1261 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1262 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
7fd59977 1263 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1264 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1265 if ( FP->FindTypedTransient(mapper,
1266 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1267 CDSR) ) {
1268 // create SDR for NAUO
1269 Handle(StepRepr_ProductDefinitionShape) nullPDS; // important to be NULL
1270 Styles.CreateNAUOSRD( Context, CDSR, nullPDS );
1271
1272 // search for MDGPR of the component top-level shape
1273 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1274 aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1275 } else {
1276 aMDGPR = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
1277 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
1278 aMDGPR->SetName( ReprName );
1279 aMDGPR->SetContextOfItems( Context );
1280 myMapCompMDGPR.Bind ( aTopSh, aMDGPR );
1281 }
1282 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1283 Standard_Integer oldLengthlen = 0;
1284 if (!oldItems.IsNull())
1285 oldLengthlen = oldItems->Length();
1286 const Standard_Integer nbIt = oldLengthlen + Styles.NbStyles();
1287 if(!nbIt)
1288 continue;
1289 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1290 new StepRepr_HArray1OfRepresentationItem(1, nbIt);
1291 Standard_Integer si;
1292 Standard_Integer el = 1;
1293 for ( si=1; si <= oldLengthlen; si++ )
1294 newItems->SetValue( el++, oldItems->Value( si ) );
1295 for ( si=1; si <= Styles.NbStyles(); si++ ) {
a9dde4a3 1296 newItems->SetValue( el++, Styles.Style(si));
7fd59977 1297 }
574d7236 1298
7fd59977 1299 if (newItems->Length() > 0)
1300 aMDGPR->SetItems( newItems );
1301 } //end of work with CDSR
1302 }
574d7236 1303 if ( !isVisible ) {
1304 // create invisibility item and refer for stiledItem
1305 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1306 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1307 new StepVisual_HArray1OfInvisibleItem (1,Styles.NbStyles());
1308 // put all style item into the harray
1309 for ( Standard_Integer si=1; si <= Styles.NbStyles(); si++ ) {
a9dde4a3 1310 Handle(StepRepr_RepresentationItem) styledItm = Styles.Style(si);
574d7236 1311 StepVisual_InvisibleItem anInvItem;
1312 anInvItem.SetValue( styledItm );
1313 HInvsblItm->SetValue( si, anInvItem );
1314 }
1315 // set the invisibility of items
1316 Invsblt->Init( HInvsblItm );
1317 WS->Model()->AddWithRefs( Invsblt );
1318 }
7fd59977 1319 }
1320
1321 return Standard_True;
1322}
1323
1324
1325//=======================================================================
1326//function : WriteNames
1327//purpose :
1328//=======================================================================
1329
1330Standard_Boolean STEPCAFControl_Writer::WriteNames (const Handle(XSControl_WorkSession) &WS,
1331 const TDF_LabelSequence &labels) const
1332{
1333 if ( labels.Length() <=0 ) return Standard_False;
1334
1335 // get working data
7f56eba8 1336 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1337 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
7fd59977 1338
1339 // Iterate on requested shapes
1340 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1341 TDF_Label L = labels.Value(i);
1342
1343 // get name
1344 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1345 if ( ! GetLabelName (L, hName) ) continue;
1346// Handle(TDataStd_Name) N;
1347// if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) continue;
1348// TCollection_ExtendedString name = N->Get();
1349// if ( name.Length() <=0 ) continue;
1350
1351 // find target STEP entity for the current shape
1352// TopoDS_Shape S;
1353// if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1354 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1355 TopoDS_Shape S = myLabels.Find ( L );
1356
1357 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
1358 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1359 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
0797d9d3 1360#ifdef OCCT_DEBUG
7fd59977 1361 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
1362#endif
1363 continue;
1364 }
1365
1366 // set the name to the PRODUCT
1367 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
1368 if ( PropD.IsNull() ) continue;
1369 Handle(StepBasic_ProductDefinition) PD = PropD->Definition().ProductDefinition();
1370 if ( PD.IsNull() ) continue;
1371 Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
1372
1373 Prod->SetId ( hName );
1374 Prod->SetName ( hName );
1375
1376 // write names for components of assemblies
1377 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1378 TDF_LabelSequence seq;
1379 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1380 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1381 TDF_Label lab = seq(k);
1382
1383 // get shape with correct location
1384 TDF_Label Lref;
1385 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1386 ! myLabels.IsBound ( Lref ) ) continue;
1387 S = myLabels.Find ( Lref );
1388 S.Move ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
1389
1390 hName = new TCollection_HAsciiString;
1391 if ( ! GetLabelName (lab, hName) ) continue;
1392
1393 // find the target CDSR corresponding to a shape
1394 mapper = TransferBRep::ShapeMapper ( FP, S );
1395 Handle(Transfer_Binder) binder = FP->Find ( mapper );
1396 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1397 if ( ! FP->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), CDSR) )
1398 continue;
1399 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1400 Handle(StepBasic_ProductDefinitionRelationship) NAUO = PDS->Definition().ProductDefinitionRelationship();
1401 if ( ! NAUO.IsNull() ) NAUO->SetName ( hName );
1402 }
1403 }
1404 }
1405
1406 return Standard_True;
1407}
1408
1409
1410//=======================================================================
1411//function : WritePropsForLabel
1412//purpose :
1413//=======================================================================
1414static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession) &WS,
1415 const Handle(XCAFDoc_ShapeTool) &aSTool,
1416 const STEPCAFControl_DataMapOfLabelShape &myLabels,
1417 const TDF_Label &L,
1418 const Standard_CString multi)
1419{
1420 if(L.IsNull()) return Standard_False;
1421
1422 STEPConstruct_ValidationProps Props ( WS );
1423
1424 TopoDS_Shape S = aSTool->GetShape(L);
1425 if(S.IsNull()) return Standard_False;
1426
1427 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1428 // write area
1429 Handle(XCAFDoc_Area) A;
1430 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1431 if ( ! A.IsNull() ) {
1432 Props.AddArea ( S, A->Get() );
1433 }
1434 // write volume
1435 Handle(XCAFDoc_Volume) V;
1436 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1437 if ( ! V.IsNull() ) {
1438 Props.AddVolume ( S, V->Get() );
1439 }
1440 }
1441 // write centroid
1442 Handle(XCAFDoc_Centroid) C;
1443 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1444 if ( ! C.IsNull() ) {
1445 Props.AddCentroid ( S, C->Get() );
1446 }
1447
1448 if( XCAFDoc_ShapeTool::IsCompound(L) || XCAFDoc_ShapeTool::IsAssembly(L) ) {
1449 if(L.HasChild()) {
1450 for(Standard_Integer ich=1; ich<=L.NbChildren(); ich++) {
1451 WritePropsForLabel(WS,aSTool,myLabels,L.FindChild(ich),multi);
1452 }
1453 }
1454 }
1455
1456 return Standard_True;
1457}
1458
1459
1460//=======================================================================
1461//function : WriteValProps
1462//purpose :
1463//=======================================================================
1464
1465Standard_Boolean STEPCAFControl_Writer::WriteValProps (const Handle(XSControl_WorkSession) &WS,
1466 const TDF_LabelSequence &labels,
1467 const Standard_CString multi) const
1468{
1469 if ( labels.Length() <=0 ) return Standard_False;
1470
1471 // get working data
1472// STEPConstruct_ValidationProps Props ( WS );
1473 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1474
1475 // Iterate on requested shapes
1476 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1477 TDF_Label L = labels.Value(i);
1478
1479 WritePropsForLabel(WS,aSTool,myLabels,L,multi);
1480/*
1481 // find target STEP entity for the current shape
1482 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1483 TopoDS_Shape S = myLabels.Find ( L );
1484
1485 // write area and volume (except for components in multifile mode)
1486 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1487 Handle(XCAFDoc_Area) A;
1488 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1489 if ( ! A.IsNull() ) Props.AddArea ( S, A->Get() );
1490
1491 Handle(XCAFDoc_Volume) V;
1492 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1493 if ( ! V.IsNull() ) Props.AddVolume ( S, V->Get() );
1494 }
1495
1496 // write centroid
1497 Handle(XCAFDoc_Centroid) C;
1498 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1499 if ( ! C.IsNull() ) Props.AddCentroid ( S, C->Get() );
1500
1501 // write centroid for components of assemblies
1502 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1503 TDF_LabelSequence seq;
1504 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1505 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1506 TDF_Label lab = seq(k);
1507
1508 // get shape with correct location
1509 TDF_Label Lref;
1510 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1511 ! myLabels.IsBound ( Lref ) ) continue;
1512 TopLoc_Location Loc = XCAFDoc_ShapeTool::GetLocation ( lab );
1513 S = myLabels.Find ( Lref );
1514 S.Move ( Loc );
1515
1516 C.Nullify();
1517 lab.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1518 // if centroid is not assigned to an instance,
1519 // use (shifted) centroid of original shape
1520 gp_Pnt center;
1521 if ( C.IsNull() ) {
1522 Lref.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1523 if ( C.IsNull() ) continue;
1524 center = C->Get().Transformed ( Loc.Transformation() );
1525 }
1526 else center = C->Get();
1527
1528 Props.AddCentroid ( S, center, Standard_True );
1529 }
1530 }
1531*/
1532 }
1533
1534 return Standard_True;
1535}
1536
1537
1538//=======================================================================
1539//function : WriteLayers
1540//purpose :
1541//=======================================================================
1542
1543Standard_Boolean STEPCAFControl_Writer::WriteLayers (const Handle(XSControl_WorkSession) &WS,
1544 const TDF_LabelSequence &labels ) const
1545{
1546
1547 if ( labels.Length() <=0 ) return Standard_False;
1548
1549 // get working data
7f56eba8 1550 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1551 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1552 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
7fd59977 1553 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( labels(1) );
1554 if (LTool.IsNull() ) return Standard_False;
1555
1556 TDF_LabelSequence LayerLS;
1557 LTool->GetLayerLabels(LayerLS);
1558 if ( LayerLS.Length() <=0 ) return Standard_False;
1559
1560 // Iterate on requested layers and for each layer take set of shapes.
1561 for ( Standard_Integer i=1; i <= LayerLS.Length(); i++ ) {
1562 TDF_Label L = LayerLS.Value(i);
1563
1564 // get labels of shapes in that layer
1565 TDF_LabelSequence ShapeLs;
1566 LTool->GetShapesOfLayer(L, ShapeLs);
1567 if ( ShapeLs.Length() <=0 ) continue;
1568
1569 // name of layer: if not set, is considered as being empty
1570 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1571 GetLabelName ( L, hName );
1572
1573 // Find target STEP entity for each shape and add to StepVisual_PresentationLayerAssignment items.
1574 TColStd_SequenceOfTransient seqRI;
1575 for ( Standard_Integer j=1; j <= ShapeLs.Length(); j++) {
1576 TDF_Label shLabel = ShapeLs.Value(j);
1577 if ( shLabel.IsNull() ) continue;
1578
1579 // there is no way to assign layer to instance in STEP
1580 if ( XCAFDoc_ShapeTool::IsAssembly ( shLabel ) ||
1581 XCAFDoc_ShapeTool::IsReference ( shLabel ) )
1582 continue;
1583
1584 // check that the shape is one of (uub)labels written during current transfer
1585 Standard_Integer k = 1;
1586 for ( ; k <= labels.Length(); k++ )
1587 if ( shLabel.IsDescendant ( labels(k) ) ) break;
1588 if ( k > labels.Length() ) continue;
1589
1590 // get target STEP entity
1591 TopoDS_Shape oneShape = XCAFDoc_ShapeTool::GetShape(shLabel);
1592
1593 TopLoc_Location Loc;
1594 Standard_Integer nb =
1595 FindEntities ( FP, oneShape, Loc, seqRI );
1596 if ( nb <=0 )
1597 FP->Messenger() << "Warning: Cannot find RI for " << oneShape.TShape()->DynamicType()->Name() << endl;
1598 }
1599 if ( seqRI.Length() <= 0 ) continue;
1600
1601 // analyze visibility
1602 Handle(StepVisual_PresentationLayerAssignment) StepLayerAs = new StepVisual_PresentationLayerAssignment;
1603 Handle(TCollection_HAsciiString) descr;
1604 Handle(TDataStd_UAttribute) aUAttr;
1605 Standard_Boolean isLinv = Standard_False;
1606 if (L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr)) {
1607 descr = new TCollection_HAsciiString ("invisible");
0797d9d3 1608#ifdef OCCT_DEBUG
7fd59977 1609 FP->Messenger() << "\tLayer \"" << hName->String().ToCString() << "\" is invisible"<<endl;
1610#endif
1611 isLinv = Standard_True;
1612 }
1613 else descr = new TCollection_HAsciiString ("visible");
1614
1615 // create layer entity
1616 Handle(StepVisual_HArray1OfLayeredItem) HArrayOfLItem =
1617 new StepVisual_HArray1OfLayeredItem ( 1, seqRI.Length() );
1618 for (Standard_Integer i1 = 1; i1<=seqRI.Length(); i1++) {
1619 StepVisual_LayeredItem LI;
1620 LI.SetValue ( seqRI.Value(i1) );
1621 HArrayOfLItem->SetValue( i1, LI );
1622 }
1623 StepLayerAs->Init(hName, descr, HArrayOfLItem);
1624 Model->AddWithRefs( StepLayerAs );
1625 // PTV 23.01.2003 add the invisibility AFTER adding layer into the model.
1626 // add the invisibility for the layer
1627 if (isLinv) {
1628 // Invisibility Item for containig invisible layers.
1629 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm = new StepVisual_HArray1OfInvisibleItem (1,1);
1630 StepVisual_InvisibleItem InvIt;
1631 InvIt.SetValue( StepLayerAs );
1632 HInvsblItm->SetValue( 1, InvIt);
1633
1634 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1635 Invsblt->Init( HInvsblItm );
1636 Model->AddWithRefs( Invsblt );
1637 }
1638 }
1639 return Standard_True;
1640}
1641
1642
1643//=======================================================================
1644//function : getSHUOstyle
1645//purpose : auxilary
1646//=======================================================================
1647static Standard_Boolean getSHUOstyle(const TDF_Label& aSHUOlab,
1648 const Handle(XCAFDoc_ColorTool)& CTool,
1649 XCAFPrs_Style& SHUOstyle)
1650{
1651 Quantity_Color C;
1652 if (!CTool->IsVisible( aSHUOlab ) )
1653 SHUOstyle.SetVisibility(Standard_False);
1654 else {
1655 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) {
1656 SHUOstyle.SetColorCurv ( C );
1657 SHUOstyle.SetColorSurf ( C );
1658 }
1659 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) )
1660 SHUOstyle.SetColorSurf ( C );
1661 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) )
1662 SHUOstyle.SetColorCurv ( C );
1663 }
1664 if ( !SHUOstyle.IsSetColorCurv() &&
1665 !SHUOstyle.IsSetColorSurf() &&
1666 SHUOstyle.IsVisible() )
1667 return Standard_False;
1668 return Standard_True;
1669}
1670
1671
1672//=======================================================================
1673//function : getProDefinitionOfNAUO
1674//purpose : auxilary
1675//=======================================================================
1676static Standard_Boolean getProDefinitionOfNAUO(const Handle(XSControl_WorkSession)& WS,
1677 const TopoDS_Shape& theShape,
1678 Handle(StepBasic_ProductDefinition)& PD,
1679 Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO,
1680 Standard_Boolean IsRelating)
1681{
1682 if ( theShape.IsNull() )
1683 return Standard_False;
1684 // get CDSR
7f56eba8 1685 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1686 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
7fd59977 1687 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1688 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, theShape );
1689 if (!FP->FindTypedTransient(mapper,
1690 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1691 CDSR))
1692 return Standard_False;
1693 // get PDS of NAUO
1694 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1695 if (PDS.IsNull())
1696 return Standard_False;
1697 // get the NAUO entity
1698 Interface_Graph aGraph = WS->HGraph()->Graph();
1699 Interface_EntityIterator subs = aGraph.Shareds(PDS);
1700 for ( subs.Start(); subs.More(); subs.Next() ) {
1701 if (!subs.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)))
1702 continue;
1703 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value());
1704 break;
1705 }
1706 if ( NAUO.IsNull() )
1707 return Standard_False;
1708 // get Relatinf or Related product definition
1709 if ( !IsRelating )
1710 PD = NAUO->RelatedProductDefinition();
1711 else
1712 PD = NAUO->RelatingProductDefinition();
1713 if ( PD.IsNull() )
1714 return Standard_False;
1715 return Standard_True;
1716}
1717
1718
1719//=======================================================================
1720//function : writeSHUO
1721//purpose : auxilary
1722//=======================================================================
1723static Standard_Boolean writeSHUO (const Handle(XCAFDoc_GraphNode)& theSHUO,
1724 const Handle(XCAFDoc_ShapeTool)& theSTool,
1725 const Handle(XSControl_WorkSession)& WS,
1726 Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO,
1727 TopoDS_Shape& NAUOShape,
1728 Handle(StepBasic_ProductDefinition)& theRelatingPD,
1729 Standard_Boolean& isDeepest)
1730{
1731 // set the ProductDefinitionRelationship descriptin information as empty strings.
1732 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
1733
1734 TDF_LabelSequence aNextUsageLabs;
1735 theSTool->GetSHUONextUsage( theSHUO->Label(), aNextUsageLabs );
1736 Handle(XCAFDoc_GraphNode) NuSHUO;
1737 if ( theTopSHUO.IsNull() ) {
1738 // the top SHUO
1739 if (aNextUsageLabs.Length() < 1)
1740 return Standard_False;
1741 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1742 if (NuSHUO.IsNull())
1743 return Standard_False;
1744 // get relating product definition
1745 TopoDS_Shape aTopCompShape = theSTool->GetShape( theSHUO->Label().Father() );
1746 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO;
1747 if (!getProDefinitionOfNAUO( WS, aTopCompShape,
1748 theRelatingPD, UUNAUO, Standard_True ))
1749 return Standard_False;
1750 // get related product definition
1751 TopoDS_Shape aNUShape = theSTool->GetShape( NuSHUO->Label().Father() );
1752 Handle(StepBasic_ProductDefinition) aRelatedPD;
1753 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO;
1754 if (!getProDefinitionOfNAUO( WS, aNUShape,
1755 aRelatedPD, NUNAUO, Standard_False ))
1756 return Standard_False;
1757
1758 theTopSHUO = new StepRepr_SpecifiedHigherUsageOccurrence;
1759 // create deepest shuo EmptyString
1760 theTopSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1761 /*no description*/Standard_False,/*description*/EmptyString,
1762 theRelatingPD, aRelatedPD,
1763 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1764 /*upper_usage*/UUNAUO, /*next_usage*/NUNAUO);
1765 // write the other SHUO.
1766 if(!writeSHUO( NuSHUO, theSTool, WS, theTopSHUO, NAUOShape, theRelatingPD, isDeepest )) {
1767 theTopSHUO.Nullify();
1768 return Standard_False;
1769 }
1770
1771 return Standard_True;
1772 }
1773// Handle(XCAFDoc_GraphNode) NuSHUO;
1774 if ( aNextUsageLabs.Length() > 0) {
1775 // store SHUO recursive
0797d9d3 1776#ifdef OCCT_DEBUG
7fd59977 1777 if ( aNextUsageLabs.Length() > 1 )
1778 cout << "Warning: store only one next_usage of current SHUO" << endl;
1779#endif
1780 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1781 Handle(StepRepr_SpecifiedHigherUsageOccurrence) aNUEntSHUO =
1782 new StepRepr_SpecifiedHigherUsageOccurrence;
1783 if (!writeSHUO( NuSHUO, theSTool, WS, aNUEntSHUO, NAUOShape, theRelatingPD, isDeepest ))
1784 return Standard_False;
1785
1786 // store the deepest SHUO to the dociment
1787 TopoDS_Shape aNUSh, aUUSh;
1788 aNUSh = theSTool->GetShape( NuSHUO->Label().Father() );
1789 aUUSh = theSTool->GetShape( theSHUO->Label().Father() );
1790 // get relating PD with upper_usage and related PD with next_usage
1791 Handle(StepBasic_ProductDefinition) nullPD;// no need to use,case have shared <theRelatingPD>
1792 Handle(StepBasic_ProductDefinition) aRelatedPD;
1793 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO, NUNAUO;
1794 if (!getProDefinitionOfNAUO( WS, aUUSh, nullPD, UUNAUO, Standard_True ) ||
1795 !getProDefinitionOfNAUO( WS, aNUSh, aRelatedPD, NUNAUO, Standard_False )) {
0797d9d3 1796#ifdef OCCT_DEBUG
7fd59977 1797 cout << "Warning: cannot get related or relating PD" << endl;
1798#endif
1799 return Standard_False;
1800 }
1801 aNUEntSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1802 /*no description*/Standard_False,/*description*/EmptyString,
1803 theRelatingPD, aRelatedPD,
1804 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1805 /*upper_usage*/theTopSHUO, /*next_usage*/NUNAUO);
1806 if ( isDeepest ) {
1807 isDeepest = Standard_False;
1808 }
1809 WS->Model()->AddWithRefs ( aNUEntSHUO );
1810 return Standard_True;
1811 } // end of recurse storing
1812
1813 // get shape
1814 TDF_Label aShapeL = theSHUO->Label().Father();
1815 NAUOShape = theSTool->GetShape( aShapeL );
1816 // return to the deepest level from SHUO shape level
1817 // it is because SHUO is attribute on deep level and shape level.
1818 isDeepest = Standard_True;
1819 return Standard_True;
1820}
1821
1822
1823//=======================================================================
1824//function : createSHUOStyledItem
1825//purpose : auxilary
1826//=======================================================================
1827static Standard_Boolean createSHUOStyledItem (const XCAFPrs_Style& style,
1828 const Handle(StepRepr_ProductDefinitionShape)& PDS,
1829 const Handle(XSControl_WorkSession) &WS,
1830 const TopoDS_Shape& Sh,
1831 const Handle(XCAFDoc_ShapeTool)& STool,
1832 MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
1833{
1834 // create styled item for the indicated SHUO and store to the model
1835 STEPConstruct_Styles Styles( WS );
1836 // translate colors to STEP
1837 Handle(StepVisual_Colour) surfColor, curvColor;
1838 if ( style.IsSetColorSurf() )
1839 surfColor = Styles.EncodeColor ( style.GetColorSurf() );
1840 if ( style.IsSetColorCurv() )
1841 curvColor = Styles.EncodeColor ( style.GetColorCurv() );
1842 Standard_Boolean isComponent = Standard_True;// cause need to get PSBC
1843 Handle(StepRepr_RepresentationItem) item;
1844 // set default color for invisible SHUO.
1845 Standard_Boolean isSetDefaultColor = Standard_False;
1846 if (surfColor.IsNull() && curvColor.IsNull() && !style.IsVisible() ) {
1847 surfColor = Styles.EncodeColor ( Quantity_Color( 1, 1, 1, Quantity_TOC_RGB ) );
1848 isSetDefaultColor = Standard_True;
1849 }
1850 Handle(StepVisual_PresentationStyleAssignment) PSA =
1851 Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1852 Handle(StepVisual_StyledItem) override; //null styled item
1853
1854 // find the repr item of the shape
7f56eba8 1855 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
1856 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
7fd59977 1857 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, Sh );
1858 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1859 FP->FindTypedTransient(mapper,
1860 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1861 CDSR);
1862 if ( CDSR.IsNull() )
1863 return Standard_False;
1864 // find context
1865 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext( Sh );
1866 TopoDS_Shape aTopSh = Sh;
1867 if (Context.IsNull()) {
1868 TDF_Label aTopShL = STool->FindShape(Sh, Standard_False);
1869 if (aTopShL.IsNull())
1870 return Standard_False;
1871 aTopSh = STool->GetShape( aTopShL );
1872 Context = Styles.FindContext ( aTopSh );
1873 }
1874 if (Context.IsNull())
1875 return Standard_False;
1876 // get representation item of the shape
1877 TopLoc_Location L;
1878 TColStd_SequenceOfTransient seqRI;
1879 FindEntities ( FP, Sh, L, seqRI );
0797d9d3 1880#ifdef OCCT_DEBUG
7fd59977 1881 if ( seqRI.Length() <=0 )
1882 FP->Messenger() << "Warning: Cannot find RI for " << Sh.TShape()->DynamicType()->Name() << endl;
1883#endif
1884 item = Handle(StepRepr_RepresentationItem)::DownCast(seqRI(1));
1885 //get overridden styled item
1886 getStyledItem(Sh,STool, Styles, override,myMapCompMDGPR);
1887
1888 // get STEP STYLED ITEM
1889 Handle(StepVisual_StyledItem) STEPstyle = Styles.AddStyle ( item, PSA, override );
1890 // create SR, SDR and all necessary references between them and ST, PDS, PSBC, GRC
1891 Styles.CreateNAUOSRD( Context, CDSR, PDS );
1892
1893 // add step styled item of SHUO to the model
1894 // do it by additing styled item to the MDGPR
1895 if ( !aTopSh.IsNull() && !myMapCompMDGPR.IsBound( aTopSh ) ) {
1896 // create MDGPR and record it in model
0797d9d3 1897#ifdef OCCT_DEBUG
7fd59977 1898 cout << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance" << endl;
1899#endif
1900 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1901 Styles.CreateMDGPR ( Context, aMDGPR );
1902 if (!aMDGPR.IsNull())
1903 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1904 }
1905 else if ( !aTopSh.IsNull() && myMapCompMDGPR.IsBound( aTopSh ) ) {
1906 // get MDGPR of the top-level shape
1907 Handle(StepVisual_PresentationRepresentation) aMDGPR =
1908 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1909 // get old styled items to not lose it
1910 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1911 Standard_Integer oldLengthlen = 0;
1912 if (!oldItems.IsNull())
1913 oldLengthlen = oldItems->Length();
1914 // create new array of styled items by an olds and new one
1915 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1916 new StepRepr_HArray1OfRepresentationItem(1, oldLengthlen + 1);
1917 Standard_Integer si;
1918 Standard_Integer el = 1;
1919 for ( si=1; si <= oldLengthlen; si++ )
1920 newItems->SetValue( el++, oldItems->Value( si ) );
a9dde4a3 1921 newItems->SetValue (el++, STEPstyle);
7fd59977 1922 // init MDGPR be new array of styled items
1923 if (newItems->Length() > 0)
1924 aMDGPR->SetItems( newItems );
1925 }
1926 else {
1927 WS->Model()->AddWithRefs ( STEPstyle ); // add as root to the model, but it is not good
0797d9d3 1928#ifdef OCCT_DEBUG
7fd59977 1929 cout << "Warning: " << __FILE__ << ": adds styled item of SHUO as root, casue cannot find MDGPR" << endl;
1930#endif
1931 }
1932 // create invisibility item for the styled item
1933 if ( !style.IsVisible() ) {
1934 if (isSetDefaultColor) {
1935 // try to set default color from top-level shape
1936
1937 setDefaultInstanceColor(override, PSA);
1938 }
1939 // create invisibility item and refer for stiledItem
1940 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1941 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1942 new StepVisual_HArray1OfInvisibleItem (1,1);
1943 // put all style item into the harray
1944 StepVisual_InvisibleItem anInvItem;
1945 anInvItem.SetValue( STEPstyle );
1946 HInvsblItm->SetValue( 1, anInvItem );
1947 Invsblt->Init( HInvsblItm );
1948 WS->Model()->AddWithRefs( Invsblt );
1949 }
1950
1951 return Standard_True;
1952}
1953
1954
1955//=======================================================================
1956//function : WriteSHUOs
1957//purpose :
1958//=======================================================================
1959
1960Standard_Boolean STEPCAFControl_Writer::WriteSHUOs (const Handle(XSControl_WorkSession) &WS,
1961 const TDF_LabelSequence &labels )
1962{
1963 if ( labels.Length() <=0 ) return Standard_False;
1964
1965 // get working data
7fd59977 1966 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1967 if (CTool.IsNull() )
1968 return Standard_False;
1969 // map of transfered SHUO
1970 TColStd_MapOfTransient aMapOfMainSHUO;
7fd59977 1971 // Iterate on requested shapes
1972 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1973 TDF_Label L = labels.Value(i);
1974 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
7fd59977 1975 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1976 TDF_LabelSequence seq;
1977 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1978 // iterates on components of assembly
1979 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1980 TDF_Label lab = seq(k);
1981 TDF_AttributeSequence anAttrSeq;
1982 CTool->ShapeTool()->GetAllComponentSHUO( lab, anAttrSeq );
1983 // work with SHUO
1984 for (Standard_Integer j = 1; j <= anAttrSeq.Length(); j++) {
1985 Handle(XCAFDoc_GraphNode) aSHUO =
1986 Handle(XCAFDoc_GraphNode)::DownCast(anAttrSeq.Value( j ));
1987 // take label of SHUO
1988 TDF_Label aSHUOlab = aSHUO->Label();
1989 TDF_LabelSequence aUpLabels;
1990 // check is it SHUO of upper_usage
1991 CTool->ShapeTool()->GetSHUOUpperUsage( aSHUOlab, aUpLabels );
1992 if ( aUpLabels.Length() > 0 )
1993 continue; // transfer only main SHUO
1994 if ( aMapOfMainSHUO.Contains( aSHUO ) )
1995 continue; // do not try to transfer SHUO twice
1996 aMapOfMainSHUO.Add( aSHUO );
1997 // check if it is styled SHUO
1998 XCAFPrs_Style SHUOstyle;
1999 if ( !getSHUOstyle ( aSHUOlab, CTool, SHUOstyle ) ) {
0797d9d3 2000#ifdef OCCT_DEBUG
7fd59977 2001 cout << "Warning: " << __FILE__ << ": do not store SHUO without any style to the STEP model" << endl;
2002#endif
2003 continue;
2004 }
2005 // write SHUO to the model amd then add structure type.
2006 TopoDS_Shape NAUOShape; // shape of the deepest NAUO in the SHUO structure
2007 Standard_Boolean isDeepest = Standard_False;
2008 Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO;
2009 Handle(StepBasic_ProductDefinition) aRelatingPD;
2010 // create the top SHUO and all other.
2011 writeSHUO( aSHUO, CTool->ShapeTool(), WS, anEntOfSHUO, NAUOShape, aRelatingPD, isDeepest );
2012 if ( anEntOfSHUO.IsNull() || NAUOShape.IsNull() ) {
0797d9d3 2013#ifdef OCCT_DEBUG
7fd59977 2014 cout << "Warning: " << __FILE__ << ": Cannot store SHUO" << endl;
2015#endif
2016 continue;
2017 }
2018 // create new Product Definition Shape for TOP SHUO
0797d9d3 2019#ifdef OCCT_DEBUG
7fd59977 2020 cout << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO " << endl;
2021#endif
2022 Handle(StepRepr_ProductDefinitionShape) PDS = new StepRepr_ProductDefinitionShape;
2023 Handle(TCollection_HAsciiString) aPDSname = new TCollection_HAsciiString("SHUO");
2024 Handle(TCollection_HAsciiString) descrStr = new TCollection_HAsciiString("");
2025 StepRepr_CharacterizedDefinition aCharDef;
2026 aCharDef.SetValue( anEntOfSHUO );
2027 PDS->Init( aPDSname, Standard_False, descrStr, aCharDef );
2028
2029 // create styled item for SHUO and add to the model
2030 createSHUOStyledItem ( SHUOstyle, PDS, WS, NAUOShape, CTool->ShapeTool(), myMapCompMDGPR );
2031
2032 } // end work with SHUO
2033 } // end of an assembly components
2034 } // end of IsAssembly case
2035 // nothing to do if it is not assembly
2036 continue;
2037 } // end of iterates on indicated labels
2038 return Standard_True;
2039}
2040
2041
2042//=======================================================================
2043//function : FindPDSforDGT
2044//purpose : auxilary: find PDS for AdvancedFace or EdgeCurve for creation
2045// needed ShapeAspect in D&GT structure
2046//=======================================================================
2047static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph,
2048 const Handle(Standard_Transient) &ent,
2049 Handle(StepRepr_ProductDefinitionShape) &PDS,
2050 Handle(StepRepr_RepresentationContext) &RC,
2051 Handle(StepShape_AdvancedFace) &AF,
2052 Handle(StepShape_EdgeCurve) &EC)
2053{
2054 if( !ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) &&
2055 !ent->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)) )
2056 return Standard_False;
2057
2058 AF = Handle(StepShape_AdvancedFace)::DownCast(ent);
2059 if( ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) ) {
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());
2076 }
2077 }
2078 }
2079 }
2080 }
2081 if(AF.IsNull()) return Standard_False;
2082
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);
2107 }
2108 }
2109 }
2110 }
2111
2112 return Standard_True;
2113}
2114
6595eee7 2115//=======================================================================
2116//function : GetUnit
2117//purpose : auxiliary
2118//=======================================================================
2119
2120static StepBasic_Unit GetUnit(const Handle(StepRepr_RepresentationContext)& theRC,
2121 const Standard_Boolean isAngle = Standard_False)
2122{
2123 StepBasic_Unit aUnit;
2124 if (isAngle) {
2125 Handle(StepBasic_SiUnitAndPlaneAngleUnit) aSiPAU;
2126 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
2127 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
2128 if(!aCtx.IsNull()) {
2129 for(Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) {
2130 if(aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))) {
2131 aSiPAU = Handle(StepBasic_SiUnitAndPlaneAngleUnit)::DownCast(aCtx->UnitsValue(j));
2132 break;
2133 }
2134 }
2135 }
2136 if(aSiPAU.IsNull()) {
2137 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
2138 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
2139 if(!aCtx1.IsNull()) {
2140 for(Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) {
2141 if(aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit))) {
2142 aSiPAU = Handle(StepBasic_SiUnitAndPlaneAngleUnit)::DownCast(aCtx1->UnitsValue(j));
2143 break;
2144 }
2145 }
2146 }
2147 }
2148 if(aSiPAU.IsNull())
2149 aSiPAU = new StepBasic_SiUnitAndPlaneAngleUnit;
2150 aUnit.SetValue(aSiPAU);
2151 }
2152 else {
2153 Handle(StepBasic_SiUnitAndLengthUnit) aSiLU;
2154 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx =
2155 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC);
2156 if(!aCtx.IsNull()) {
2157 for(Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) {
2158 if(aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2159 aSiLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(aCtx->UnitsValue(j));
2160 break;
2161 }
2162 }
2163 }
2164 if(aSiLU.IsNull()) {
2165 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 =
2166 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC);
2167 if(!aCtx1.IsNull()) {
2168 for(Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) {
2169 if(aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2170 aSiLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(aCtx1->UnitsValue(j));
2171 break;
2172 }
2173 }
2174 }
2175 }
2176 if(aSiLU.IsNull())
2177 aSiLU = new StepBasic_SiUnitAndLengthUnit;
2178 aUnit.SetValue(aSiLU);
2179 }
2180 return aUnit;
2181}
2182
2183//=======================================================================
2184//function : CreateDimValue
2185//purpose : auxiliary
2186//======================================================================
2187static Handle(StepRepr_ReprItemAndMeasureWithUnit) CreateDimValue(const Standard_Real theValue,
2188 const StepBasic_Unit theUnit,
2189 const Handle(TCollection_HAsciiString)& theName,
2190 const Standard_CString theMeasureName,
2191 const Standard_Boolean isAngle,
2192 const Standard_Boolean isQualified = Standard_False,
2193 const Handle(StepShape_QualifiedRepresentationItem)& theQRI = NULL)
2194{
2195 Handle(StepRepr_RepresentationItem) aReprItem = new StepRepr_RepresentationItem();
2196 aReprItem->Init(new TCollection_HAsciiString(theName));
2197 Handle(StepBasic_MeasureWithUnit) aMWU = new StepBasic_MeasureWithUnit();
2198 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
2199 aValueMember->SetName(theMeasureName);
2200 aValueMember->SetReal(theValue);
2201 aMWU->Init(aValueMember, theUnit);
2202 if (isQualified) {
2203 if (isAngle) {
2204 // Angle & with qualifiers
2205 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI) anItem =
2206 new StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI();
2207 anItem->Init(aMWU, aReprItem, theQRI);
2208 return anItem;
2209 }
2210 else {
2211 // Length & with qualifiers
2212 Handle(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI) anItem =
2213 new StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI();
2214 anItem->Init(aMWU, aReprItem, theQRI);
2215 return anItem;
2216 }
2217 }
2218 else {
2219 if (isAngle) {
2220 // Angle & without qualifiers
2221 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) anItem =
2222 new StepRepr_ReprItemAndPlaneAngleMeasureWithUnit();
2223 anItem->Init(aMWU, aReprItem);
2224 return anItem;
2225 }
2226 else {
2227 // Length & without qualifiers
2228 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) anItem =
2229 new StepRepr_ReprItemAndLengthMeasureWithUnit();
2230 anItem->Init(aMWU, aReprItem);
2231 return anItem;
2232 }
2233 }
2234}
2235
2236//=======================================================================
2237//function : WriteShapeAspect
2238//purpose : auxiliary (write Shape_Aspect entity for given shape)
2239//=======================================================================
2240
2241static Handle(StepRepr_ShapeAspect) WriteShapeAspect (const Handle(XSControl_WorkSession) &WS,
2242 const TDF_Label theLabel,
2243 const TopoDS_Shape theShape,
2244 Handle(StepRepr_RepresentationContext)& theRC,
2245 Handle(StepAP242_GeometricItemSpecificUsage)& theGISU)
2246{
2247 // Get working data
7f56eba8 2248 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2249 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
2250 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
6595eee7 2251 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2252 if (aHGraph.IsNull())
2253 return NULL;
2254 Interface_Graph aGraph = aHGraph->Graph();
2255
2256 TopLoc_Location aLoc;
2257 TColStd_SequenceOfTransient aSeqRI;
2258 FindEntities( FP, theShape, aLoc, aSeqRI );
2259 if ( aSeqRI.Length() <= 0 ) {
2260 FP->Messenger() << "Warning: Cannot find RI for "<<theShape.TShape()->DynamicType()->Name()<<endl;
2261 return NULL;
2262 }
2263
2264 Handle(StepRepr_ProductDefinitionShape) aPDS;
2265 Handle(StepRepr_RepresentationContext) aRC;
2266 Handle(Standard_Transient) anEnt = aSeqRI.Value(1);
2267 Handle(StepShape_AdvancedFace) anAF;
2268 Handle(StepShape_EdgeCurve) anEC;
2269 FindPDSforDGT(aGraph, anEnt, aPDS, aRC, anAF, anEC);
2270 if(aPDS.IsNull())
2271 return NULL;
2272
2273 theRC = aRC;
2274 // Shape_Aspect
2275 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString();
2276 Handle(TDataStd_Name) aNameAttr;
2277 if (theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) {
2278 aName = new TCollection_HAsciiString(TCollection_AsciiString(aNameAttr->Get(), '?'));
2279 Standard_Integer aFirstSpace = aName->Search(" ");
2280 if (aFirstSpace != -1)
2281 aName = aName->SubString(aFirstSpace + 1, aName->Length());
2282 else
2283 aName = new TCollection_HAsciiString();
2284 }
2285 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString();
2286 Handle(StepRepr_ShapeAspect) aSA = new StepRepr_ShapeAspect;
2287 aSA->Init(aName, aDescription, aPDS, StepData_LTrue);
2288
2289 // Geometric_Item_Specific_Usage
2290 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2291 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2292 aDefinition.SetValue(aSA);
2293 Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
2294 Handle(StepRepr_RepresentationItem) anIdentifiedItem = Handle(StepRepr_RepresentationItem)::DownCast(anEnt);
2295 anReprItems->SetValue(1, anIdentifiedItem);
2296 Interface_EntityIterator subs = aGraph.Sharings(aPDS);
2297 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2298 for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) {
2299 Handle(Standard_Transient) anEntity = subs.Value();
2300 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity);
2301 }
2302 if (aSDR.IsNull())
2303 return NULL;
2304
2305 // Set entities to model
2306 aGISU->Init(aName, aDescription, aDefinition, aSDR->UsedRepresentation(), anReprItems);
2307 Model->AddWithRefs(aSA);
2308 Model->AddWithRefs(aGISU);
2309 theGISU = aGISU;
2310 return aSA;
2311}
2312
b0cef606 2313//=======================================================================
2314//function : WritePresentation
2315//purpose : auxiliary (write annotation plane and presentation)
2316//======================================================================
2317static void WritePresentation(const Handle(XSControl_WorkSession) &WS,
2318 const TopoDS_Shape thePresentation,
2319 const gp_Ax2 theAnnotationPlane,
f0bf70e8 2320 const gp_Pnt theTextPosition,
b0cef606 2321 const Handle(Standard_Transient) theDimension)
2322{
2323 if (thePresentation.IsNull())
2324 return;
2325 // Get working data
7f56eba8 2326 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
b0cef606 2327
2328 // Presentation
2329 Handle(StepVisual_TessellatedGeometricSet) aGeomSet = STEPCAFControl_GDTProperty::GetTessellation(thePresentation);
2330 Handle(StepVisual_TessellatedAnnotationOccurrence) aTAO = new StepVisual_TessellatedAnnotationOccurrence();
2331 aTAO->Init(new TCollection_HAsciiString(), gdtPrsCurveStyle, aGeomSet);
2332 StepVisual_DraughtingCalloutElement aDCElement;
2333 aDCElement.SetValue(aTAO);
2334 Handle(StepVisual_HArray1OfDraughtingCalloutElement) aTAOs = new StepVisual_HArray1OfDraughtingCalloutElement(1, 1);
2335 aTAOs->SetValue(1, aDCElement);
2336 Handle(StepVisual_DraughtingCallout) aDCallout = new StepVisual_DraughtingCallout();
2337 aDCallout->Init(new TCollection_HAsciiString(), aTAOs);
2338 Handle(StepRepr_HArray1OfRepresentationItem) aDCsForDMIA = new StepRepr_HArray1OfRepresentationItem(1, 1);
2339 aDCsForDMIA->SetValue(1, aDCallout);
2340 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDimension;
2341 aDimension.SetValue(theDimension);
2342 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
2343 new StepAP242_DraughtingModelItemAssociation();
2344 aDMIA->Init(new TCollection_HAsciiString("PMI representation to presentation link"),
2345 new TCollection_HAsciiString(), aDimension, gdtPresentationDM, aDCsForDMIA);
2346 aModel->AddWithRefs(aDMIA);
2347
2348 // Annotation plane
2349 // Presentation Style
2350 Handle(StepVisual_NullStyleMember) aNullStyle = new StepVisual_NullStyleMember();
2351 aNullStyle->SetEnumText(0, ".NULL.");
2352 StepVisual_PresentationStyleSelect aStyleItem;
2353 aStyleItem.SetValue(aNullStyle);
2354 Handle(StepVisual_HArray1OfPresentationStyleSelect) aStyles = new StepVisual_HArray1OfPresentationStyleSelect(1, 1);
2355 aStyles->SetValue(1, aStyleItem);
2356 Handle(StepVisual_PresentationStyleAssignment) aPrsStyle = new StepVisual_PresentationStyleAssignment();
2357 aPrsStyle->Init(aStyles);
2358 Handle(StepVisual_HArray1OfPresentationStyleAssignment) aPrsStyles =
2359 new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
2360 aPrsStyles->SetValue(1, aPrsStyle);
2361 // Plane
2362 Handle(StepGeom_Plane) aPlane = new StepGeom_Plane();
2363 Handle(StepGeom_Axis2Placement3d) anAxis = STEPCAFControl_GDTProperty::GetAxis2Placement3D(theAnnotationPlane);
f0bf70e8 2364 // Set text position to plane origin
2365 Handle(StepGeom_CartesianPoint) aTextPos = new StepGeom_CartesianPoint();
2366 Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
2367 for (Standard_Integer i = 1; i <= 3; i++)
2368 aCoords->SetValue(i, theTextPosition.Coord(i));
2369 aTextPos->Init(new TCollection_HAsciiString(), aCoords);
2370 anAxis->SetLocation(aTextPos);
b0cef606 2371 aPlane->Init(new TCollection_HAsciiString(), anAxis);
2372 // Annotation plane element
2373 StepVisual_AnnotationPlaneElement aPlaneElement;
2374 aPlaneElement.SetValue(aDCallout);
2375 Handle(StepVisual_HArray1OfAnnotationPlaneElement) aDCsForAnnPln = new StepVisual_HArray1OfAnnotationPlaneElement(1, 1);
2376 aDCsForAnnPln->SetValue(1, aPlaneElement);
2377 // Init AnnotationPlane entity
2378 Handle(StepVisual_AnnotationPlane) anAnnPlane = new StepVisual_AnnotationPlane();
2379 anAnnPlane->Init(new TCollection_HAsciiString(), aPrsStyles, aPlane, aDCsForAnnPln);
2380 gdtAnnotationPlanes.Append(anAnnPlane);
2381 aModel->AddWithRefs(anAnnPlane);
2382}
2383
6595eee7 2384//=======================================================================
2385//function : WriteDatumAP242
2386//purpose : auxiliary (write Datum entity for given shape or write all
2387// necessary entities and link them to already written datum
2388// in case of multiple features association)
2389//=======================================================================
2390static Handle(StepDimTol_Datum) WriteDatumAP242(const Handle(XSControl_WorkSession) &WS,
2391 const TDF_Label theShapeL,
2392 const TDF_Label theDatumL,
2393 const Standard_Boolean isFirstDTarget,
2394 const Handle(StepDimTol_Datum) theWrittenDatum)
2395{
2396 // Get working data
7f56eba8 2397 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2398 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
2399 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
6595eee7 2400 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2401 if (aHGraph.IsNull())
2402 return NULL;
2403 Interface_Graph aGraph = aHGraph->Graph();
2404
2405 Handle(StepRepr_ShapeAspect) aSA;
2406 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2407 // Link with datum feature
2408 Handle(StepRepr_ProductDefinitionShape) aPDS;
2409 Handle(StepRepr_RepresentationContext) aRC;
2410 Handle(Standard_Transient) anEnt;
2411 Handle(StepShape_AdvancedFace) anAF;
2412 Handle(StepShape_EdgeCurve) anEC;
2413 TopoDS_Shape aShape;
2414 TopLoc_Location aLoc;
2415 TColStd_SequenceOfTransient aSeqRI;
2416
2417 aShape = XCAFDoc_ShapeTool::GetShape(theShapeL);
2418 FindEntities( FP, aShape, aLoc, aSeqRI );
2419 if ( aSeqRI.Length() <= 0 ) {
2420 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
2421 return NULL;
2422 }
2423 anEnt = aSeqRI.Value(1);
2424 FindPDSforDGT(aGraph, anEnt, aPDS, aRC, anAF, anEC);
2425 if (aPDS.IsNull())
2426 return NULL;
2427
2428 aSA = WriteShapeAspect(WS, theDatumL, aShape, aRC, aGISU);
2429 if (aSA.IsNull())
2430 return NULL;
2431 Standard_Integer aSANum = Model->Number(aSA);
2432 Standard_Integer aGISUNum = Model->Number(aGISU);
2433 // Find if datum has datum targets and get common datum attributes
2434 Handle(XCAFDoc_Datum) aDatumAttr;
2435 if (!theDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
2436 return NULL;
2437 Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject();
2438 if (anObject.IsNull())
2439 return NULL;
2440 Standard_Boolean isSimpleDatum = !anObject->IsDatumTarget();
2441 Handle(TCollection_HAsciiString) anIdentifier = anObject->GetName();
2442 Handle(TCollection_HAsciiString) aTargetId = (anObject->GetDatumTargetNumber() == 0 ?
2443 new TCollection_HAsciiString() : new TCollection_HAsciiString(anObject->GetDatumTargetNumber()));
2444
2445 // If datum type is area, but there is no area in object, write as simple datum
2446 if (anObject->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Area &&
2447 anObject->GetDatumTarget().IsNull())
2448 isSimpleDatum = Standard_True;
2449
2450 // Simple datum
2451 if (isSimpleDatum) {
2452 Handle(StepDimTol_DatumFeature) aDF = new StepDimTol_DatumFeature();
2453 aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aSA->OfShape(), aSA->ProductDefinitional());
2454 Model->ReplaceEntity(aSANum, aDF);
2455 aSA = aDF;
2456 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2457 aDefinition.SetValue(aDF);
2458 aGISU->SetDefinition(aDefinition);
2459 Model->ReplaceEntity(aGISUNum, aGISU);
2460 }
2461 // Datum with datum targets
2462 else {
2463 XCAFDimTolObjects_DatumTargetType aDatumType = anObject->GetDatumTargetType();
2464 Handle(StepDimTol_DatumTarget) aDatumTarget;
2465 // Note: the given way to write such datum type may be incorrect (too little information)
2466 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Area) {
2467 TopoDS_Shape aDTShape = anObject->GetDatumTarget();
2468 Handle(StepAP242_GeometricItemSpecificUsage) anAreaGISU;
2469 Handle(StepRepr_ShapeAspect) anAreaSA = WriteShapeAspect(WS, theDatumL, aDTShape, aRC, anAreaGISU);
2470 aSANum = Model->Number(anAreaSA);
2471 aGISUNum = Model->Number(anAreaGISU);
2472 Handle(StepDimTol_DatumTarget) aDT = new StepDimTol_DatumTarget();
2473 aDT->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString("area"), anAreaSA->OfShape(),
2474 anAreaSA->ProductDefinitional(), aTargetId);
2475 Model->ReplaceEntity(aSANum, aDT);
2476 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2477 aDefinition.SetValue(aDT);
2478 anAreaGISU->SetDefinition(aDefinition);
2479 Model->ReplaceEntity(aGISUNum, anAreaGISU);
2480 }
2481 else {
2482 Handle(StepDimTol_PlacedDatumTargetFeature) aPDTF = new StepDimTol_PlacedDatumTargetFeature();
727b5ad9 2483 aPDTF->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDatumTargetName(aDatumType),
6595eee7 2484 aPDS, StepData_LTrue, aTargetId);
2485 Model->AddWithRefs(aPDTF);
2486 aDatumTarget = aPDTF;
2487 // Datum targets
2488 Handle(StepRepr_PropertyDefinition) aPD = new StepRepr_PropertyDefinition();
2489 StepRepr_CharacterizedDefinition aCDefinition;
2490 aCDefinition.SetValue(aPDTF);
2491 aPD->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCDefinition);
2492 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP = new StepShape_ShapeRepresentationWithParameters();
2493 // Common for all datum targets
2494 StepBasic_Unit aUnit = GetUnit(aRC);
2495 gp_Ax2 aDTAxis = anObject->GetDatumTargetAxis();
2496 Handle(StepGeom_Axis2Placement3d) anA2P3D =
727b5ad9 2497 STEPCAFControl_GDTProperty::GetAxis2Placement3D(aDTAxis);
b0cef606 2498 anA2P3D->SetName(new TCollection_HAsciiString("orientation"));
6595eee7 2499 Handle(StepRepr_HArray1OfRepresentationItem) anItems;
2500 // Process each datum target type
2501 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Point) {
2502 anItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
2503 }
2504 else {
2505 Handle(TCollection_HAsciiString) aTargetValueName;
2506 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Line) {
2507 anItems = new StepRepr_HArray1OfRepresentationItem(1, 2);
2508 aTargetValueName = new TCollection_HAsciiString("target length");
2509 }
2510 else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Rectangle) {
2511 anItems = new StepRepr_HArray1OfRepresentationItem(1, 3);
2512 aTargetValueName = new TCollection_HAsciiString("target length");
2513 // Additional value
2514 Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue = CreateDimValue(anObject->GetDatumTargetWidth(),
2515 aUnit, new TCollection_HAsciiString("target width"), "POSITIVE_LENGTH_MEASURE", Standard_False);
2516 anItems->SetValue(2, aTargetValue);
2517 Model->AddWithRefs(aTargetValue);
2518 }
2519 else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Circle) {
2520 anItems = new StepRepr_HArray1OfRepresentationItem(1, 2);
2521 aTargetValueName = new TCollection_HAsciiString("target diameter");
2522 }
2523 // Value
2524 Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue= CreateDimValue(anObject->GetDatumTargetLength(),
2525 aUnit, aTargetValueName, "POSITIVE_LENGTH_MEASURE", Standard_False);
2526 anItems->SetValue(1, aTargetValue);
2527 Model->AddWithRefs(aTargetValue);
2528 }
2529 anItems->SetValue(anItems->Length(), anA2P3D);
2530 aSRWP->Init(new TCollection_HAsciiString(), anItems, aRC);
2531
2532 // Create and write auxiliary entities
2533 Handle (StepShape_ShapeDefinitionRepresentation) aSDR = new StepShape_ShapeDefinitionRepresentation();
2534 StepRepr_RepresentedDefinition aRDefinition;
2535 aRDefinition.SetValue(aPD);
2536 aSDR->Init(aRDefinition, aSRWP);
2537 Model->AddWithRefs(aPD);
2538 Model->AddWithRefs(aSRWP);
2539 Model->AddWithRefs(aSDR);
2540 }
2541 // Link datum target to datum feature
2542 Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR = new StepRepr_FeatureForDatumTargetRelationship();
2543 aFFDTR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aDatumTarget, aSA);
2544 Model->AddWithRefs(aFFDTR);
2545 aSA = aDatumTarget;
2546 }
2547
2548 // Datum
2549 Handle(StepDimTol_Datum) aDatum = theWrittenDatum;
2550 if (isFirstDTarget) {
2551 aDatum = new StepDimTol_Datum();
2552 aDatum->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue, anIdentifier);
2553 Model->AddWithRefs(aDatum);
2554 }
2555
2556 // Shape_Aspect_Relationship
2557 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
2558 aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aSA, aDatum);
2559 Model->AddWithRefs(aSAR);
2560
2561 // Auxiliary entities
2562 // Property_Definition
2563 Handle(StepRepr_PropertyDefinition) aPD = new StepRepr_PropertyDefinition();
2564 Handle(TCollection_HAsciiString) aPDName = new TCollection_HAsciiString("Datum Feature Symbol ");
2565 aPDName = aPDName->Cat(anIdentifier)->Cat(aTargetId);
2566 StepRepr_CharacterizedDefinition aCD;
2567 aCD.SetValue(aSA);
2568 aPD->Init(aPDName, Standard_False, NULL, aCD);
2569 Model->AddWithRefs(aPD);
2570 // Shape_Representation
2571 Handle(StepShape_ShapeRepresentation) aShapeRepr = new StepShape_ShapeRepresentation();
2572 aShapeRepr->Init(aPDName, aGISU->IdentifiedItem(), aRC);
2573 Model->AddWithRefs(aShapeRepr);
2574 // Shape_Definition_Representation
2575 Handle (StepShape_ShapeDefinitionRepresentation) aSDR = new StepShape_ShapeDefinitionRepresentation();
2576 StepRepr_RepresentedDefinition aRDefinition;
2577 aRDefinition.SetValue(aPD);
2578 aSDR->Init(aRDefinition, aShapeRepr);
2579 Model->AddWithRefs(aSDR);
2580
b0cef606 2581 //Annotation plane and Presentation
f0bf70e8 2582 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPlane(), anObject->GetPointTextAttach(), aSA);
b0cef606 2583
6595eee7 2584 return aDatum;
2585}
2586
2587//=======================================================================
2588//function : WriteDimValues
2589//purpose : auxiliary (write all data for given dimension: values,
2590// qualifiers, modifiers, orientation and tolerance class)
2591//======================================================================
2592static void WriteDimValues(const Handle(XSControl_WorkSession) &WS,
2593 const Handle(XCAFDimTolObjects_DimensionObject) theObject,
2594 const Handle(StepRepr_RepresentationContext) theRC,
2595 const StepShape_DimensionalCharacteristic theDimension)
2596{
2597 // Get working data
7f56eba8 2598 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
6595eee7 2599 XCAFDimTolObjects_DimensionModifiersSequence aModifiers = theObject->GetModifiers();
2600 Handle(Standard_Transient) aDim = theDimension.Value();
2601 Standard_Boolean isAngle = aDim->IsKind(STANDARD_TYPE(StepShape_AngularLocation)) ||
2602 aDim->IsKind(STANDARD_TYPE(StepShape_AngularSize));
2603
2604 // Unit
2605 StepBasic_Unit aUnit = GetUnit(theRC, isAngle);
2606 Standard_CString aMeasureName;
2607 if (isAngle)
2608 aMeasureName = "POSITIVE_PLANE_ANGLE_MEASURE";
2609 else
2610 aMeasureName = "POSITIVE_LENGTH_MEASURE";
2611
2612 // Values
2613 Handle(StepRepr_HArray1OfRepresentationItem) aValues;
7644c7f4 2614 Standard_Integer aNbItems = 1, aValIt = 1;
6595eee7 2615 if (theObject->IsDimWithRange())
7644c7f4 2616 aNbItems += 2;
6595eee7 2617 if (aModifiers.Length() > 0)
7644c7f4 2618 aNbItems++;
6595eee7 2619 if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented)
7644c7f4 2620 aNbItems++;
2621 aNbItems += theObject->NbDescriptions();
2622 aValues = new StepRepr_HArray1OfRepresentationItem(1, aNbItems);
6595eee7 2623
2624 // Nominal value
2625 Standard_Real aNominal = theObject->GetValue();
2626 Standard_Integer aLeftNbDigits, aRightNbDigits;
2627 theObject->GetNbOfDecimalPlaces(aLeftNbDigits, aRightNbDigits);
2628 Standard_Integer aNbQualifiers = 0;
2629 if (theObject->HasQualifier() && !isAngle)
2630 aNbQualifiers++;
2631 if (aLeftNbDigits > 0 || aRightNbDigits > 0)
2632 aNbQualifiers++;
2633 // With qualifiers
2634 if (aNbQualifiers > 0) {
2635 Handle(StepShape_QualifiedRepresentationItem) aQRI = new StepShape_QualifiedRepresentationItem();
2636 Handle(StepShape_HArray1OfValueQualifier) aQualifiers = new StepShape_HArray1OfValueQualifier(1, aNbQualifiers);
2637 // Type qualifier
2638 if (theObject->HasQualifier() && !isAngle) {
2639 StepShape_ValueQualifier anItem;
2640 Handle(StepShape_TypeQualifier) aType = new StepShape_TypeQualifier();
2641 XCAFDimTolObjects_DimensionQualifier aQualifier = theObject->GetQualifier();
727b5ad9 2642 aType->Init(STEPCAFControl_GDTProperty::GetDimQualifierName(aQualifier));
6595eee7 2643 aModel->AddWithRefs(aType);
2644 anItem.SetValue(aType);
2645 aQualifiers->SetValue(1, anItem);
2646 }
2647 // Number of decimal places
2648 if (aLeftNbDigits > 0 || aRightNbDigits > 0) {
2649 StepShape_ValueQualifier anItem;
2650 Handle(StepShape_ValueFormatTypeQualifier) aType = new StepShape_ValueFormatTypeQualifier();
2651 Handle(TCollection_HAsciiString) aFormatType = new TCollection_HAsciiString("NR2 ");
2652 aFormatType->AssignCat(new TCollection_HAsciiString(aLeftNbDigits));
2653 aFormatType->AssignCat(new TCollection_HAsciiString("."));
2654 aFormatType->AssignCat(new TCollection_HAsciiString(aRightNbDigits));
2655 aType->Init(aFormatType);
2656 aModel->AddWithRefs(aType);
2657 anItem.SetValue(aType);
2658 aQualifiers->SetValue(aNbQualifiers, anItem);
2659 }
2660 // Set qualifiers
2661 aQRI->SetQualifiers(aQualifiers);
2662 Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
2663 new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle, Standard_True, aQRI);
7644c7f4 2664 aValues->SetValue(aValIt, anItem);
2665 aValIt++;
6595eee7 2666 }
2667 // Without qualifiers
2668 else {
2669 Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
2670 new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle);
7644c7f4 2671 aValues->SetValue(aValIt, anItem);
2672 aValIt++;
6595eee7 2673 }
7644c7f4 2674
6595eee7 2675 // Ranges
2676 if (theObject->IsDimWithRange()) {
2677 Handle(StepRepr_ReprItemAndMeasureWithUnit) aLowerItem = CreateDimValue(theObject->GetLowerBound(), aUnit,
2678 new TCollection_HAsciiString("lower limit"), aMeasureName, isAngle);
2679 Handle(StepRepr_ReprItemAndMeasureWithUnit) anUpperItem = CreateDimValue(theObject->GetUpperBound(), aUnit,
2680 new TCollection_HAsciiString("upper limit"), aMeasureName, isAngle);
7644c7f4 2681 aValues->SetValue(aValIt, aLowerItem);
2682 aValIt++;
2683 aValues->SetValue(aValIt, anUpperItem);
2684 aValIt++;
6595eee7 2685 }
2686
2687 // Modifiers
2688 if (aModifiers.Length() > 0) {
2689 Handle(StepRepr_CompoundRepresentationItem) aCompoundRI = new StepRepr_CompoundRepresentationItem();
2690 Handle (StepRepr_HArray1OfRepresentationItem) aModifItems =
2691 new StepRepr_HArray1OfRepresentationItem(1, aModifiers.Length());
2692 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) {
2693 XCAFDimTolObjects_DimensionModif aModif = aModifiers.Value(i);
2694 Handle(StepRepr_DescriptiveRepresentationItem) aModifItem =
2695 new StepRepr_DescriptiveRepresentationItem();
727b5ad9 2696 aModifItem->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDimModifierName(aModif));
6595eee7 2697 aModel->AddWithRefs(aModifItem);
2698 aModifItems->SetValue(i, aModifItem);
2699 }
2700 aCompoundRI->Init(new TCollection_HAsciiString(), aModifItems);
7644c7f4 2701 aValues->SetValue(aValIt, aCompoundRI);
2702 aValIt++;
6595eee7 2703 }
2704
2705 // Orientation
2706 if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented) {
2707 Handle(StepGeom_Axis2Placement3d) anOrientation = new StepGeom_Axis2Placement3d();
2708 gp_Dir aDir;
2709 theObject->GetDirection(aDir);
b7b2f85a 2710 GeomToStep_MakeCartesianPoint MkPoint(gp_Pnt(0, 0, 0));
18f7c9a5 2711 Handle(StepGeom_CartesianPoint) aLoc = MkPoint.Value();
6595eee7 2712 Handle(StepGeom_Direction) anAxis = new StepGeom_Direction();
2713 Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
2714 aCoords->SetValue(1, aDir.X());
2715 aCoords->SetValue(2, aDir.Y());
2716 aCoords->SetValue(3, aDir.Z());
2717 anAxis->Init(new TCollection_HAsciiString(), aCoords);
2718 anOrientation->Init(new TCollection_HAsciiString("orientation"), aLoc, Standard_True, anAxis, Standard_False, NULL);
7644c7f4 2719 aValues->SetValue(aValIt, anOrientation);
2720 aValIt++;
2721 }
2722
2723 // Descriptions
2724 if (theObject->HasDescriptions()) {
2725 for (Standard_Integer i = 0; i < theObject->NbDescriptions(); i++) {
2726 Handle(StepRepr_DescriptiveRepresentationItem) aDRI = new StepRepr_DescriptiveRepresentationItem();
2727 aDRI->Init(theObject->GetDescriptionName(i), theObject->GetDescription(i));
2728 aValues->SetValue(aValIt, aDRI);
2729 aValIt++;
2730 }
6595eee7 2731 }
2732
2733 for (Standard_Integer i = 1; i <= aValues->Length(); i++)
2734 aModel->AddWithRefs(aValues->Value(i));
2735
2736 // Create resulting Shape_Dimension_Representation
2737 Handle(StepShape_ShapeDimensionRepresentation) aSDR = new StepShape_ShapeDimensionRepresentation();
2738 aSDR->Init(new TCollection_HAsciiString(), aValues, theRC);
2739 aModel->AddWithRefs(aSDR);
2740 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR = new StepShape_DimensionalCharacteristicRepresentation();
2741 aDCR->Init(theDimension, aSDR);
2742 aModel->AddWithRefs(aDCR);
2743
2744 // Plus_Minus_Tolerance
2745 if (theObject->IsDimWithPlusMinusTolerance()) {
2746 Handle(TCollection_HAsciiString) aDummyName = new TCollection_HAsciiString(aMeasureName);
2747 aDummyName = aDummyName->SubString(9, aDummyName->Length()); //delete "POSITIVE_"
2748 aMeasureName = aDummyName->ToCString();
2749 Standard_Real aLowerTolValue = -theObject->GetLowerTolValue(),
2750 anUpperTolValue = theObject->GetUpperTolValue();
2751 // Upper
2752 Handle(StepBasic_MeasureWithUnit) anUpperMWU = new StepBasic_MeasureWithUnit();
2753 Handle(StepBasic_MeasureValueMember) anUpperValue = new StepBasic_MeasureValueMember();
2754 anUpperValue->SetName(aMeasureName);
2755 anUpperValue->SetReal(anUpperTolValue);
2756 anUpperMWU->Init(anUpperValue, aUnit);
2757 aModel->AddWithRefs(anUpperMWU);
2758 // Lower
2759 Handle(StepBasic_MeasureWithUnit) aLowerMWU = new StepBasic_MeasureWithUnit();
2760 Handle(StepBasic_MeasureValueMember) aLowerValue = new StepBasic_MeasureValueMember();
2761 aLowerValue->SetName(aMeasureName);
2762 aLowerValue->SetReal(aLowerTolValue);
2763 aLowerMWU->Init(aLowerValue, aUnit);
2764 aModel->AddWithRefs(aLowerMWU);
2765 // Tolerance
2766 Handle(StepShape_ToleranceValue) aTolValue = new StepShape_ToleranceValue();
2767 aTolValue->Init(aLowerMWU, anUpperMWU);
2768 aModel->AddWithRefs(aTolValue);
2769 StepShape_ToleranceMethodDefinition aMethod;
2770 aMethod.SetValue(aTolValue);
2771 Handle(StepShape_PlusMinusTolerance) aPlusMinusTol = new StepShape_PlusMinusTolerance();
2772 aPlusMinusTol->Init(aMethod, theDimension);
2773 aModel->AddWithRefs(aPlusMinusTol);
2774 }
2775 // Tolerance class
2776 if (theObject->IsDimWithClassOfTolerance()) {
2777 Standard_Boolean isHole;
2778 XCAFDimTolObjects_DimensionFormVariance aFormVariance;
2779 XCAFDimTolObjects_DimensionGrade aGrade;
2780 if (!theObject->GetClassOfTolerance(isHole, aFormVariance, aGrade))
2781 return;
727b5ad9 2782 Handle(StepShape_LimitsAndFits) aLAF = STEPCAFControl_GDTProperty::GetLimitsAndFits(isHole, aFormVariance, aGrade);
6595eee7 2783 aModel->AddWithRefs(aLAF);
2784 StepShape_ToleranceMethodDefinition aMethod;
2785 aMethod.SetValue(aLAF);
2786 Handle(StepShape_PlusMinusTolerance) aPlusMinusTol = new StepShape_PlusMinusTolerance();
2787 aPlusMinusTol->Init(aMethod, theDimension);
2788 aModel->AddWithRefs(aPlusMinusTol);
2789 }
2790}
2791
b7b2f85a 2792//=======================================================================
2793//function : WriteDerivedGeometry
2794//purpose : auxiliary (write connection point for dimensions)
2795//======================================================================
2796static void WriteDerivedGeometry (const Handle(XSControl_WorkSession) &WS,
2797 const Handle(XCAFDimTolObjects_DimensionObject)& theObject,
2798 const Handle(StepRepr_ConstructiveGeometryRepresentation) theRepr,
2799 Handle(StepRepr_ShapeAspect)& theFirstSA,
2800 Handle(StepRepr_ShapeAspect)& theSecondSA,
2801 NCollection_Vector<Handle(StepGeom_CartesianPoint)>& thePnts)
2802{
2803 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2804 // First point
2805 if (theObject->HasPoint()) {
2806 GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint());
2807 Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
2808 thePnts.Append(aPoint);
2809 Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
2810 aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse);
2811 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2812 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2813 aDefinition.SetValue(aDSA);
2814 Handle(StepRepr_HArray1OfRepresentationItem) anItem = new StepRepr_HArray1OfRepresentationItem(1, 1);
2815 anItem->SetValue(1, aPoint);
2816 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDefinition, theRepr, anItem);
2817 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = new StepRepr_ShapeAspectDerivingRelationship();
2818 aSADR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDSA, theFirstSA);
2819 theFirstSA = aDSA;
2820 aModel->AddWithRefs(aGISU);
2821 aModel->AddWithRefs(aSADR);
2822 }
2823
2824 // Second point (for locations)
2825 if (theObject->HasPoint2()) {
2826 GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint2());
2827 Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
2828 thePnts.Append(aPoint);
2829 Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
2830 aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse);
2831 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2832 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2833 aDefinition.SetValue(aDSA);
2834 Handle(StepRepr_HArray1OfRepresentationItem) anItem = new StepRepr_HArray1OfRepresentationItem(1, 1);
2835 anItem->SetValue(1, aPoint);
2836 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDefinition, theRepr, anItem);
2837 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = new StepRepr_ShapeAspectDerivingRelationship();
2838 aSADR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDSA, theSecondSA);
2839 theSecondSA = aDSA;
2840 aModel->AddWithRefs(aGISU);
2841 aModel->AddWithRefs(aSADR);
2842 }
2843}
2844
6595eee7 2845//=======================================================================
2846//function : WriteDatumSystem
2847//purpose : auxiliary (write Write datum system for given
2848// geometric_tolerance)
2849//======================================================================
2850static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const Handle(XSControl_WorkSession) &WS,
2851 const TDF_Label theGeomTolL,
2852 const TDF_LabelSequence theDatumSeq,
2853 const STEPConstruct_DataMapOfAsciiStringTransient theDatumMap,
2854 const Handle(StepRepr_RepresentationContext)& theRC)
2855{
2856 // Get working data
7f56eba8 2857 const Handle(Interface_InterfaceModel) &Model = WS->Model();
6595eee7 2858 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2859 if (aHGraph.IsNull())
2860 return NULL;
2861 Interface_Graph aGraph = aHGraph->Graph();
2862 Handle(XCAFDoc_GeomTolerance) aGTAttr;
2863 if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr))
2864 return NULL;
2865 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
2866 if (anObject.IsNull())
2867 return NULL;
2868
2869 // Unit
2870 StepBasic_Unit aUnit = GetUnit(theRC);
2871
2872 XCAFDimTolObjects_DatumObjectSequence aDatums;
2873 Standard_Integer aMaxDatumNum = 0;
2874 for (Standard_Integer i = 1; i <= theDatumSeq.Length(); i++) {
2875 Handle(XCAFDoc_Datum) aDatumAttr;
2876 if (!theDatumSeq.Value(i).FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
2877 continue;
2878 Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject();
2879 if (aDatumObj.IsNull())
2880 continue;
2881 aDatums.Append(aDatumObj);
2882 aMaxDatumNum = Max(aMaxDatumNum, aDatumObj->GetPosition());
2883 }
2884
2885 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aConstituents =
2886 new StepDimTol_HArray1OfDatumReferenceCompartment(1, aMaxDatumNum);
2887 // Auxiliary datum to initialize attributes in Datum_System
2888 Handle(StepDimTol_Datum) aFirstDatum;
2889 Standard_Integer aConstituentsNum = 0;
2890 for (Standard_Integer i = 1; i <= aMaxDatumNum; i++) {
2891 // Collect datums with i-th position
2892 XCAFDimTolObjects_DatumObjectSequence aDatumSeqPos;
2893 for (Standard_Integer j = 1; j <= aDatums.Length(); j++)
2894 if (aDatums.Value(j)->GetPosition() == i)
2895 aDatumSeqPos.Append(aDatums.Value(j));
2896 if (aDatumSeqPos.Length() < 1)
2897 continue;
2898
2899 aConstituentsNum++;
2900 // Initialize Datum_Reference_Compartment
2901 StepDimTol_DatumOrCommonDatum aDatumRef;
2902 Handle(StepDimTol_DatumReferenceCompartment) aCompartment =
2903 new StepDimTol_DatumReferenceCompartment();
2904 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifiers;
2905 if (aDatumSeqPos.Length() == 1) {
2906 // Datum entity
aa00364d 2907 Handle(Standard_Transient) aFDValue;
2908 if (theDatumMap.Find(aDatumSeqPos.Value(1)->GetName()->String(), aFDValue))
2909 aFirstDatum = Handle(StepDimTol_Datum)::DownCast (aFDValue);
6595eee7 2910 aDatumRef.SetValue(aFirstDatum);
2911 // Modifiers
2912 XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(1)->GetModifiers();
2913 XCAFDimTolObjects_DatumModifWithValue aModifWithVal;
2914 Standard_Real aValue = 0;
2915 aDatumSeqPos.Value(1)->GetModifierWithValue(aModifWithVal, aValue);
727b5ad9 2916 aModifiers = STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit);
6595eee7 2917 // Add Datum_Reference_Modifier_With_Value
2918 if (!aModifiers.IsNull()) {
2919 Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV =
2920 aModifiers->Value(aModifiers->Length()).DatumReferenceModifierWithValue();
2921 if (!aDRMWV.IsNull()) {
2922 Model->AddWithRefs(aDRMWV);
2923 }
2924 }
2925 }
2926 else {
2927 Handle(StepDimTol_HArray1OfDatumReferenceElement) aCommonDatumList = new StepDimTol_HArray1OfDatumReferenceElement(1, aDatumSeqPos.Length());
2928 for (Standard_Integer j = 1; j <= aDatumSeqPos.Length(); j++) {
2929 // Datum entity
2930 Handle(StepDimTol_Datum) aDatum;
aa00364d 2931 Handle(Standard_Transient) aDValue;
2932 if (theDatumMap.Find(aDatumSeqPos.Value(j)->GetName()->String(), aDValue))
2933 aDatum = Handle(StepDimTol_Datum)::DownCast (aDValue);
6595eee7 2934 StepDimTol_DatumOrCommonDatum anElemDatumRef;
2935 anElemDatumRef.SetValue(aDatum);
2936 if (aFirstDatum.IsNull())
2937 aFirstDatum = aDatum;
2938 // Modifiers
2939 XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(j)->GetModifiers();
2940 XCAFDimTolObjects_DatumModifWithValue aModifWithVal;
2941 Standard_Real aValue = 0;
2942 aDatumSeqPos.Value(j)->GetModifierWithValue(aModifWithVal, aValue);
2943 Handle(StepDimTol_HArray1OfDatumReferenceModifier) anElemModifiers =
727b5ad9 2944 STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit);
6595eee7 2945 // Add Datum_Reference_Modifier_With_Value
2946 if (!anElemModifiers.IsNull()) {
2947 Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV =
2948 anElemModifiers->Value(aModifiers->Length()).DatumReferenceModifierWithValue();
2949 if (!aDRMWV.IsNull()) {
2950 Model->AddWithRefs(aDRMWV);
2951 }
2952 }
2953 // Datum_Reference_Element
2954 Handle(StepDimTol_DatumReferenceElement) anElement = new StepDimTol_DatumReferenceElement();
2955 anElement->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDatum->OfShape(),
2956 aDatum->ProductDefinitional(), anElemDatumRef, !anElemModifiers.IsNull(), anElemModifiers);
2957 Model->AddWithRefs(anElement);
2958 aCommonDatumList->SetValue(j, anElement);
2959 }
2960 aDatumRef.SetValue(aCommonDatumList);
2961 }
2962 aCompartment->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(),
2963 aFirstDatum->ProductDefinitional(), aDatumRef, !aModifiers.IsNull(), aModifiers);
2964 Model->AddWithRefs(aCompartment);
2965 aConstituents->SetValue(aConstituentsNum, aCompartment);
2966 }
2967 // Remove null elements from aConstituents
2968 Standard_Integer aNbConstituents = 0;
2969 for (Standard_Integer i = 1; i <= aConstituents->Length(); i++)
2970 if (!aConstituents->Value(i).IsNull())
2971 aNbConstituents++;
2972 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aResConstituents =
2973 new StepDimTol_HArray1OfDatumReferenceCompartment(1, aNbConstituents);
2974 Standard_Integer aConstituentsIt = 0;
2975 for (Standard_Integer i = 1; i <= aConstituents->Length(); i++)
2976 if (!aConstituents->Value(i).IsNull()) {
2977 aConstituentsIt++;
2978 aResConstituents->SetValue(aConstituentsIt, aConstituents->Value(i));
2979 }
2980
2981 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
2982 Handle(StepDimTol_DatumSystem) aDS = new StepDimTol_DatumSystem();
2983 aDS->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(),
2984 aFirstDatum->ProductDefinitional(), aResConstituents);
2985 Model->AddWithRefs(aDS);
2986 StepDimTol_DatumSystemOrReference anArrayValue;
2987 anArrayValue.SetValue(aDS);
2988 aDatumSystem = new StepDimTol_HArray1OfDatumSystemOrReference(1, 1);
2989 aDatumSystem->SetValue(1, anArrayValue);
2990
2991 // Axis
2992 if (anObject->HasAxis()) {
2993 Handle(StepGeom_Axis2Placement3d) anAxis =
727b5ad9 2994 STEPCAFControl_GDTProperty::GetAxis2Placement3D(anObject->GetAxis());
b0cef606 2995 anAxis->SetName(new TCollection_HAsciiString("orientation"));
6595eee7 2996 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2997 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2998 aDefinition.SetValue(aDS);
2999 Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
a9dde4a3 3000 Handle(StepRepr_RepresentationItem) anIdentifiedItem = anAxis;
6595eee7 3001 anReprItems->SetValue(1, anIdentifiedItem);
3002 Interface_EntityIterator subs = aGraph.Sharings(aFirstDatum->OfShape());
3003 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
3004 for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) {
3005 Handle(Standard_Transient) anEntity = subs.Value();
3006 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity);
3007 }
3008 if (aSDR.IsNull())
3009 return aDatumSystem;
3010
3011 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(),
3012 aDefinition, aSDR->UsedRepresentation(), anReprItems);
3013 Model->AddWithRefs(anAxis);
3014 Model->AddWithRefs(aGISU);
3015 }
3016
3017 return aDatumSystem;
3018}
3019
3020//=======================================================================
3021//function : WriteToleranceZone
3022//purpose : auxiliary (write tolerace zones)
3023//=======================================================================
3024static void WriteToleranceZone (const Handle(XSControl_WorkSession) &WS,
3025 const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject,
3026 const Handle(StepDimTol_GeometricTolerance)& theEntity,
3027 const Handle(StepRepr_RepresentationContext)& theRC)
3028{
3029 // Get working data
7f56eba8 3030 const Handle(Interface_InterfaceModel) &Model = WS->Model();
6595eee7 3031 if (theEntity.IsNull() || theObject.IsNull())
3032 return;
3033
3034 // Return if there is no tolerance zones
3035 if (theObject->GetTypeOfValue() == XCAFDimTolObjects_GeomToleranceTypeValue_None &&
3036 theObject->GetZoneModifier() != XCAFDimTolObjects_GeomToleranceZoneModif_Runout)
3037 return;
3038
3039 // Create Tolerance_Zone
3040 Handle(StepDimTol_ToleranceZoneForm) aForm = new StepDimTol_ToleranceZoneForm();
3041 Model->AddWithRefs(aForm);
727b5ad9 3042 aForm->Init(STEPCAFControl_GDTProperty::GetTolValueType(theObject->GetTypeOfValue()));
6595eee7 3043 Handle(StepDimTol_HArray1OfToleranceZoneTarget) aZoneTargetArray = new StepDimTol_HArray1OfToleranceZoneTarget(1, 1);
3044 StepDimTol_ToleranceZoneTarget aTarget;
3045 aTarget.SetValue(theEntity);
3046 aZoneTargetArray->SetValue(1, aTarget);
3047 Handle(StepDimTol_ToleranceZone) aZone = new StepDimTol_ToleranceZone();
3048 aZone->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(),
3049 theEntity->TolerancedShapeAspect().ShapeAspect()->OfShape(), StepData_LFalse,
3050 aZoneTargetArray, aForm);
3051 Model->AddWithRefs(aZone);
3052
3053 // Runout_Tolerance_Zone
3054 Handle(StepBasic_PlaneAngleMeasureWithUnit) aPAMWU = new StepBasic_PlaneAngleMeasureWithUnit();
3055 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
3056 aValueMember->SetName("PLANE_ANGLE_MEASURE");
3057 aValueMember->SetReal(theObject->GetValueOfZoneModifier());
3058 aPAMWU->Init(aValueMember, GetUnit(theRC, Standard_True));
3059 Handle(StepDimTol_RunoutZoneOrientation) anOrientation = new StepDimTol_RunoutZoneOrientation();
3060 anOrientation->Init(aPAMWU);
3061 Handle(StepDimTol_RunoutZoneDefinition) aDefinition = new StepDimTol_RunoutZoneDefinition();
3062 aDefinition->Init(aZone, NULL, anOrientation);
3063 Model->AddWithRefs(aDefinition);
3064 Model->AddWithRefs(anOrientation);
3065 Model->AddWithRefs(aPAMWU);
3066}
3067
3068//=======================================================================
3069//function : WriteGeomTolerance
3070//purpose : auxiliary (write Geometric_Tolerance entity for given shapes,
3071// label and datum system)
3072//======================================================================
3073static void WriteGeomTolerance (const Handle(XSControl_WorkSession) &WS,
3074 const TDF_LabelSequence theShapeSeqL,
3075 const TDF_Label theGeomTolL,
3076 const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem,
3077 const Handle(StepRepr_RepresentationContext)& theRC)
3078{
3079 // Get working data
7f56eba8 3080 const Handle(Interface_InterfaceModel) &Model = WS->Model();
6595eee7 3081 Handle(XCAFDoc_GeomTolerance) aGTAttr;
3082 if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr))
3083 return;
3084 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
3085 if (anObject.IsNull())
3086 return;
3087
3088 // Value
3089 Handle(StepBasic_LengthMeasureWithUnit) aLMWU = new StepBasic_LengthMeasureWithUnit();
3090 StepBasic_Unit aUnit = GetUnit(theRC);
3091 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
3092 aValueMember->SetName("LENGTH_MEASURE");
3093 aValueMember->SetReal(anObject->GetValue());
3094 aLMWU->Init(aValueMember, aUnit);
3095 Model->AddWithRefs(aLMWU);
3096
3097 // Geometric_Tolerance target
3098 Handle(StepRepr_ShapeAspect) aMainSA;
3099 Handle(StepRepr_RepresentationContext) dummyRC;
3100 Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
3101 if (theShapeSeqL.Length() == 1) {
3102 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(1));
3103 aMainSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU);
3104 Model->AddWithRefs(aMainSA);
3105 }
3106 else {
3107 Handle(StepRepr_CompositeShapeAspect) aCSA;
3108 for (Standard_Integer i = 1; i <= theShapeSeqL.Length(); i++) {
3109 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(i));
3110 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU);
3111 if (aSA.IsNull())
3112 continue;
3113 if (aCSA.IsNull()) {
3114 aCSA = new StepRepr_CompositeShapeAspect();
3115 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3116 Model->AddWithRefs(aCSA);
3117 }
3118 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3119 aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCSA, aSA);
3120 Model->AddWithRefs(aSAR);
3121 }
3122 aMainSA = aCSA;
3123 }
3124 StepDimTol_GeometricToleranceTarget aGTTarget;
3125 aGTTarget.SetValue(aMainSA);
3126
3127 Standard_Boolean isWithModif = Standard_False,
3128 isWithDatRef = Standard_False,
3129 isWithMaxTol = Standard_False;
3130 // Modifiers
3131 // Simple modifiers
3132 XCAFDimTolObjects_GeomToleranceModifiersSequence aModifiers = anObject->GetModifiers();
3133 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifArray;
3134 Handle(StepBasic_LengthMeasureWithUnit) aMaxLMWU;
3135 Standard_Integer aModifNb = aModifiers.Length();
3136 if (anObject->GetMaterialRequirementModifier() != XCAFDimTolObjects_GeomToleranceMatReqModif_None)
3137 aModifNb++;
3138 for (Standard_Integer i = 1; i < aModifiers.Length(); i++)
3139 if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around ||
3140 aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over)
3141 aModifNb--;
3142 if (aModifNb > 0) {
3143 isWithModif = Standard_True;
3144 aModifArray = new StepDimTol_HArray1OfGeometricToleranceModifier(1, aModifNb);
3145 Standard_Integer k = 1;
3146 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) {
3147 if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around ||
3148 aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over)
3149 continue;
3150 StepDimTol_GeometricToleranceModifier aModif =
727b5ad9 3151 STEPCAFControl_GDTProperty::GetGeomToleranceModifier(aModifiers.Value(i));
6595eee7 3152 aModifArray->SetValue(k, aModif);
3153 k++;
3154 }
3155 if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_L) {
3156 aModifArray->SetValue(aModifNb, StepDimTol_GTMLeastMaterialRequirement);
3157 }
3158 else if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_M) {
3159 aModifArray->SetValue(aModifNb, StepDimTol_GTMMaximumMaterialRequirement);
3160 }
3161 // Modifier with value
3162 if (anObject->GetMaxValueModifier() != 0) {
3163 isWithMaxTol = Standard_True;
3164 aMaxLMWU = new StepBasic_LengthMeasureWithUnit();
c7854818 3165 Handle(StepBasic_MeasureValueMember) aModifierValueMember = new StepBasic_MeasureValueMember();
3166 aModifierValueMember->SetName("LENGTH_MEASURE");
3167 aModifierValueMember->SetReal(anObject->GetMaxValueModifier());
3168 aMaxLMWU->Init(aModifierValueMember, aUnit);
6595eee7 3169 Model->AddWithRefs(aMaxLMWU);
3170 }
3171 }
3172
3173 // Datum Reference
3174 isWithDatRef = !theDatumSystem.IsNull();
3175
3176 // Collect all attributes
3177 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(),
3178 aDescription = new TCollection_HAsciiString();
3179 Handle(StepDimTol_GeometricToleranceWithDatumReference) aGTWDR =
3180 new StepDimTol_GeometricToleranceWithDatumReference();
3181 aGTWDR->SetDatumSystem(theDatumSystem);
3182 Handle(StepDimTol_GeometricToleranceWithModifiers) aGTWM =
3183 new StepDimTol_GeometricToleranceWithModifiers();
3184 aGTWM->SetModifiers(aModifArray);
3185 StepDimTol_GeometricToleranceType aType =
727b5ad9 3186 STEPCAFControl_GDTProperty::GetGeomToleranceType(anObject->GetType());
6595eee7 3187
3188 // Init and write necessary subtype of Geometric_Tolerance entity
3189 Handle(StepDimTol_GeometricTolerance) aGeomTol;
3190 if (isWithModif) {
3191 if (isWithMaxTol) {
3192 if (isWithDatRef) {
3193 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference &
3194 //Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers
3195 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aResult =
3196 new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol();
3197 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aMaxLMWU, aType);
3198 aGeomTol = aResult;
3199 }
3200 else {
3201 // Geometric_Tolerance & Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers
3202 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aResult =
3203 new StepDimTol_GeoTolAndGeoTolWthMaxTol();
3204 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWM, aMaxLMWU, aType);
3205 aGeomTol = aResult;
3206 }
3207 }
3208 else {
3209 if (isWithDatRef) {
3210 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference & Geometric_Tolerance_With_Modifiers
3211 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) aResult =
3212 new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod();
3213 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aType);
3214 aGeomTol = aResult;
3215 }
3216 else {
3217 // Geometric_Tolerance & Geometric_Tolerance_With_Modifiers
3218 Handle(StepDimTol_GeoTolAndGeoTolWthMod) aResult =
3219 new StepDimTol_GeoTolAndGeoTolWthMod();
3220 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWM, aType);
3221 aGeomTol = aResult;
3222 }
3223 }
3224 }
3225 else {
3226 if (isWithDatRef) {
3227 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference
3228 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) aResult =
3229 new StepDimTol_GeoTolAndGeoTolWthDatRef();
3230 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aType);
3231 aGeomTol = aResult;
3232 }
3233 else {
3234 // Geometric_Tolerance
3235 Handle(StepDimTol_GeometricTolerance) aResult =
727b5ad9 3236 STEPCAFControl_GDTProperty::GetGeomTolerance(anObject->GetType());
6595eee7 3237 if (!aResult.IsNull()) {
3238 aResult->Init(aName, aDescription, aLMWU, aGTTarget);
3239 aGeomTol = aResult;
3240 }
3241 }
3242 }
3243 Model->AddWithRefs(aGeomTol);
3244 WriteToleranceZone(WS, anObject, aGeomTol, theRC);
b0cef606 3245 //Annotation plane and Presentation
f0bf70e8 3246 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPlane(), anObject->GetPointTextAttach(), aGeomTol);
6595eee7 3247}
7fd59977 3248
3249//=======================================================================
3250//function : WriteDGTs
3251//purpose :
3252//=======================================================================
7fd59977 3253Standard_Boolean STEPCAFControl_Writer::WriteDGTs (const Handle(XSControl_WorkSession) &WS,
3254 const TDF_LabelSequence &labels ) const
3255{
3256
3257 if ( labels.Length() <=0 ) return Standard_False;
6595eee7 3258
7fd59977 3259 // get working data
7f56eba8 3260 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3261 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
3262 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
9e20ed57 3263
3264 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3265 if(aHGraph.IsNull())
3266 return Standard_False;
3267
3268 Interface_Graph aGraph = aHGraph->Graph();
7fd59977 3269 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( labels(1) );
3270 if(DGTTool.IsNull() ) return Standard_False;
3271
3272 TDF_LabelSequence DGTLabels;
6595eee7 3273
7fd59977 3274 STEPConstruct_DataMapOfAsciiStringTransient DatumMap;
3275
3276 // write Datums
6595eee7 3277 DGTLabels.Clear();
7fd59977 3278 DGTTool->GetDatumLabels(DGTLabels);
3279 if(DGTLabels.Length()<=0) return Standard_False;
3280 Standard_Integer i;
3281 for(i=1; i<=DGTLabels.Length(); i++) {
3282 TDF_Label DatumL = DGTLabels.Value(i);
9ebaae37 3283 TDF_LabelSequence ShapeL;
1c9d3225 3284 TDF_LabelSequence aNullSeq;
3285 if(!DGTTool->GetRefShapeLabel(DatumL,ShapeL,aNullSeq)) continue;
7fd59977 3286 // find target shape
9ebaae37 3287 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
7fd59977 3288 TopLoc_Location Loc;
3289 TColStd_SequenceOfTransient seqRI;
3290 FindEntities( FP, aShape, Loc, seqRI );
3291 if ( seqRI.Length() <= 0 ) {
3292 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
3293 continue;
3294 }
3295 Handle(StepRepr_ProductDefinitionShape) PDS;
3296 Handle(StepRepr_RepresentationContext) RC;
3297 Handle(Standard_Transient) ent = seqRI.Value(1);
3298 Handle(StepShape_AdvancedFace) AF;
3299 Handle(StepShape_EdgeCurve) EC;
3300 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
3301 if(PDS.IsNull()) continue;
3302 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
3303 Handle(XCAFDoc_Datum) DatumAttr;
3304 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
3305 Handle(TCollection_HAsciiString) aName = DatumAttr->GetName();
3306 Handle(TCollection_HAsciiString) aDescription = DatumAttr->GetDescription();
3307 Handle(TCollection_HAsciiString) anIdentification = DatumAttr->GetIdentification();
3308 Handle(StepDimTol_DatumFeature) DF = new StepDimTol_DatumFeature;
3309 Handle(StepDimTol_Datum) aDatum = new StepDimTol_Datum;
3310 DF->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
3311 Model->AddWithRefs(DF);
3312 aDatum->Init(aName, new TCollection_HAsciiString, PDS, StepData_LFalse, anIdentification);
3313 Model->AddWithRefs(aDatum);
3314 Handle(StepRepr_ShapeAspectRelationship) SAR = new StepRepr_ShapeAspectRelationship;
3315 SAR->SetName(aName);
3316 SAR->SetRelatingShapeAspect(DF);
3317 SAR->SetRelatedShapeAspect(aDatum);
3318 Model->AddWithRefs(SAR);
3319 // write chain for DatumFeature
3320 StepRepr_CharacterizedDefinition CD;
3321 CD.SetValue(DF);
3322 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
3323 PropD->Init(aName,Standard_True,aDescription,CD);
3324 Model->AddWithRefs(PropD);
3325 StepRepr_RepresentedDefinition RD;
3326 RD.SetValue(PropD);
3327 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
3328 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
3329 new StepRepr_HArray1OfRepresentationItem(1,1);
3330 HARI->SetValue(1,AF);
3331 SR->Init(aName,HARI,RC);
3332 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
3333 SDR->Init(RD,SR);
3334 Model->AddWithRefs(SDR);
3335 // write chain for Datum
3336 StepRepr_CharacterizedDefinition CD1;
3337 CD1.SetValue(aDatum);
3338 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
3339 PropD1->Init(aName,Standard_True,aDescription,CD1);
3340 Model->AddWithRefs(PropD1);
3341 StepRepr_RepresentedDefinition RD1;
3342 RD1.SetValue(PropD1);
3343 Handle(StepShape_ShapeRepresentation) SR1 = new StepShape_ShapeRepresentation;
3344 Handle(StepRepr_HArray1OfRepresentationItem) HARI1 =
3345 new StepRepr_HArray1OfRepresentationItem(1,1);
3346 HARI1->SetValue(1,AF->FaceGeometry());
3347 SR1->Init(aName,HARI1,RC);
3348 Model->AddWithRefs(SR1);
3349 Handle(StepShape_ShapeDefinitionRepresentation) SDR1 = new StepShape_ShapeDefinitionRepresentation;
3350 SDR1->Init(RD1,SR1);
3351 Model->AddWithRefs(SDR1);
3352 // add created Datum into Map
3353 TCollection_AsciiString stmp(aName->ToCString());
3354 stmp.AssignCat(aDescription->ToCString());
3355 stmp.AssignCat(anIdentification->ToCString());
3356 DatumMap.Bind(stmp,aDatum);
3357 }
3358
3359 // write Tolerances and Dimensions
3360 DGTLabels.Clear();
3361 DGTTool->GetDimTolLabels(DGTLabels);
3362 if(DGTLabels.Length()<=0) return Standard_False;
3363 for(i=1; i<=DGTLabels.Length(); i++) {
3364 TDF_Label DimTolL = DGTLabels.Value(i);
9ebaae37 3365 TDF_LabelSequence ShapeL;
1c9d3225 3366 TDF_LabelSequence aNullSeq;
3367 if(!DGTTool->GetRefShapeLabel(DimTolL,ShapeL,aNullSeq)) continue;
7fd59977 3368 // find target shape
9ebaae37 3369 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
7fd59977 3370 TopLoc_Location Loc;
3371 TColStd_SequenceOfTransient seqRI;
3372 FindEntities( FP, aShape, Loc, seqRI );
3373 if ( seqRI.Length() <= 0 ) {
3374 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
3375 continue;
3376 }
3377 Handle(StepRepr_ProductDefinitionShape) PDS;
3378 Handle(StepRepr_RepresentationContext) RC;
3379 Handle(Standard_Transient) ent = seqRI.Value(1);
3380 Handle(StepShape_AdvancedFace) AF;
3381 Handle(StepShape_EdgeCurve) EC;
3382 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
3383 if(PDS.IsNull()) continue;
3384 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
3385
3386 Handle(XCAFDoc_DimTol) DimTolAttr;
3387 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) continue;
3388 Standard_Integer kind = DimTolAttr->GetKind();
3389 Handle(TColStd_HArray1OfReal) aVal = DimTolAttr->GetVal();
3390 Handle(TCollection_HAsciiString) aName = DimTolAttr->GetName();
3391 Handle(TCollection_HAsciiString) aDescription = DimTolAttr->GetDescription();
3392
3393 // common part of writing D&GT entities
3394 StepRepr_CharacterizedDefinition CD;
3395 Handle(StepRepr_ShapeAspect) SA = new StepRepr_ShapeAspect;
3396 SA->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
3397 Model->AddWithRefs(SA);
3398 CD.SetValue(SA);
3399 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
3400 PropD->Init(aName,Standard_True,aDescription,CD);
3401 Model->AddWithRefs(PropD);
3402 StepRepr_RepresentedDefinition RD;
3403 RD.SetValue(PropD);
3404 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
3405 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
3406 new StepRepr_HArray1OfRepresentationItem(1,1);
3407 if(kind<20)
3408 HARI->SetValue(1,EC);
3409 else
3410 HARI->SetValue(1,AF);
3411 SR->Init(aName,HARI,RC);
3412 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
3413 SDR->Init(RD,SR);
3414 Model->AddWithRefs(SDR);
3415 // define aUnit for creation LengthMeasureWithUnit (common for all)
3416 StepBasic_Unit aUnit;
3417 Handle(StepBasic_SiUnitAndLengthUnit) SLU;
3418 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) Ctx =
3419 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(RC);
3420 if(!Ctx.IsNull()) {
3421 for(Standard_Integer j=1; j<=Ctx->NbUnits(); j++) {
3422 if(Ctx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
3423 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx->UnitsValue(j));
3424 break;
3425 }
3426 }
3427 }
3428 if(SLU.IsNull()) {
3429 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) Ctx1 =
3430 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(RC);
3431 if(!Ctx1.IsNull()) {
3432 for(Standard_Integer j=1; j<=Ctx1->NbUnits(); j++) {
3433 if(Ctx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
3434 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx1->UnitsValue(j));
3435 break;
3436 }
3437 }
3438 }
3439 }
3440 if(SLU.IsNull()) {
3441 SLU = new StepBasic_SiUnitAndLengthUnit;
3442 }
3443 aUnit.SetValue(SLU);
3444
3445 // specific part of writing D&GT entities
3446 if(kind<20) { //dimension
3447 Handle(StepShape_DimensionalSize) DimSize = new StepShape_DimensionalSize;
3448 DimSize->Init(SA,aDescription);
3449 Model->AddWithRefs(DimSize);
3450 if(aVal->Length()>1) {
3451 // create MeasureWithUnits
3452 Handle(StepBasic_MeasureValueMember) MVM1 = new StepBasic_MeasureValueMember;
3453 MVM1->SetName("POSITIVE_LENGTH_MEASURE");
3454 MVM1->SetReal(aVal->Value(1));
3455 Handle(StepBasic_MeasureWithUnit) MWU1 = new StepBasic_MeasureWithUnit;
3456 MWU1->Init(MVM1,aUnit);
3457 Handle(StepBasic_MeasureValueMember) MVM2 = new StepBasic_MeasureValueMember;
3458 MVM2->SetName("POSITIVE_LENGTH_MEASURE");
3459 MVM2->SetReal(aVal->Value(2));
3460 Handle(StepBasic_MeasureWithUnit) MWU2 = new StepBasic_MeasureWithUnit;
3461 MWU2->Init(MVM2,aUnit);
3462 Handle(StepRepr_RepresentationItem) RI1 = new StepRepr_RepresentationItem;
3463 RI1->Init(new TCollection_HAsciiString("lower limit"));
3464 Handle(StepRepr_RepresentationItem) RI2 = new StepRepr_RepresentationItem;
3465 RI2->Init(new TCollection_HAsciiString("upper limit"));
3466 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU1 =
3467 new StepRepr_ReprItemAndLengthMeasureWithUnit;
3468 RILMU1->Init(MWU1,RI1);
3469 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU2 =
3470 new StepRepr_ReprItemAndLengthMeasureWithUnit;
3471 RILMU2->Init(MWU2,RI2);
3472 Model->AddWithRefs(RILMU1);
3473 Model->AddWithRefs(RILMU2);
3474 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
3475 // new StepRepr_CompoundItemDefinitionMember;
3476 //Handle(TColStd_HArray1OfTransient) ArrTr = new TColStd_HArray1OfTransient(1,2);
3477 //ArrTr->SetValue(1,RILMU1);
3478 //ArrTr->SetValue(2,RILMU2);
3479 //CIDM->SetArrTransient(ArrTr);
3480 //CIDM->SetName("SET_REPRESENTATION_ITEM");
3481 //StepRepr_CompoundItemDefinition CID;
3482 //CID.SetValue(CIDM);
3483 Handle(StepRepr_HArray1OfRepresentationItem) HARIVR =
3484 new StepRepr_HArray1OfRepresentationItem(1,2);
3485 HARIVR->SetValue(1,RILMU1);
3486 HARIVR->SetValue(2,RILMU2);
3487 Handle(StepRepr_ValueRange) VR = new StepRepr_ValueRange;
3488 //VR->Init(aName,CID);
3489 VR->Init(aName,HARIVR);
3490 Model->AddEntity(VR);
3491 Handle(StepShape_ShapeDimensionRepresentation) SDimR =
3492 new StepShape_ShapeDimensionRepresentation;
51740958 3493 Handle(StepRepr_HArray1OfRepresentationItem) aHARI =
7fd59977 3494 new StepRepr_HArray1OfRepresentationItem(1,1);
51740958 3495 aHARI->SetValue(1,VR);
3496 SDimR->Init(aName,aHARI,RC);
7fd59977 3497 Model->AddWithRefs(SDimR);
3498 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
3499 new StepShape_DimensionalCharacteristicRepresentation;
3500 StepShape_DimensionalCharacteristic DimChar;
3501 DimChar.SetValue(DimSize);
3502 DimCharR->Init(DimChar,SDimR);
3503 Model->AddEntity(DimCharR);
3504 }
3505 }
3506 else if(kind<50) { //tolerance
3507 if(kind<35) { // tolerance with datum system
3508 TDF_LabelSequence DatumLabels;
9ebaae37 3509 DGTTool->GetDatumOfTolerLabels(DimTolL,DatumLabels);
7fd59977 3510 Standard_Integer NbDR = DatumLabels.Length();
3511 Handle(StepDimTol_HArray1OfDatumReference) HADR = new StepDimTol_HArray1OfDatumReference(1,NbDR);
3512 for(Standard_Integer j=1; j<=NbDR; j++) {
3513 Handle(XCAFDoc_Datum) DatumAttr;
3514 TDF_Label DatumL = DatumLabels.Value(j);
3515 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
3516 Handle(TCollection_HAsciiString) aNameD = DatumAttr->GetName();
3517 Handle(TCollection_HAsciiString) aDescriptionD = DatumAttr->GetDescription();
3518 Handle(TCollection_HAsciiString) anIdentificationD = DatumAttr->GetIdentification();
3519 TCollection_AsciiString stmp(aNameD->ToCString());
3520 stmp.AssignCat(aDescriptionD->ToCString());
3521 stmp.AssignCat(anIdentificationD->ToCString());
3522 if(DatumMap.IsBound(stmp)) {
3523 Handle(StepDimTol_Datum) aDatum =
3524 Handle(StepDimTol_Datum)::DownCast(DatumMap.Find(stmp));
3525 Handle(StepDimTol_DatumReference) DR = new StepDimTol_DatumReference;
3526 DR->Init(j,aDatum);
3527 Model->AddWithRefs(DR);
3528 HADR->SetValue(j,DR);
3529 }
3530 }
3531 // create LengthMeasureWithUnit
3532 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
3533 MVM->SetName("LENGTH_MEASURE");
3534 MVM->SetReal(aVal->Value(1));
3535 Handle(StepBasic_LengthMeasureWithUnit) LMWU = new StepBasic_LengthMeasureWithUnit;
3536 LMWU->Init(MVM,aUnit);
3537 // create tolerance by it's type
3538 if(kind<24) {
3539 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
3540 new StepDimTol_GeometricToleranceWithDatumReference;
3541 GTWDR->SetDatumSystem(HADR);
3542 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
3543 new StepDimTol_ModifiedGeometricTolerance;
3544 if(kind==21) MGT->SetModifier(StepDimTol_MaximumMaterialCondition);
3545 else if(kind==22) MGT->SetModifier(StepDimTol_LeastMaterialCondition);
3546 else if(kind==23) MGT->SetModifier(StepDimTol_RegardlessOfFeatureSize);
3547 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
3548 new StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol;
3549 GTComplex->Init(aName,aDescription,LMWU,SA,GTWDR,MGT);
3550 Model->AddWithRefs(GTComplex);
3551 }
3552 else if(kind==24) {
3553 Handle(StepDimTol_AngularityTolerance) aToler =
3554 new StepDimTol_AngularityTolerance;
3555 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3556 Model->AddWithRefs(aToler);
3557 }
3558 else if(kind==25) {
3559 Handle(StepDimTol_CircularRunoutTolerance) aToler =
3560 new StepDimTol_CircularRunoutTolerance;
3561 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3562 Model->AddWithRefs(aToler);
3563 }
3564 else if(kind==26) {
3565 Handle(StepDimTol_CoaxialityTolerance) aToler =
3566 new StepDimTol_CoaxialityTolerance;
3567 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3568 Model->AddWithRefs(aToler);
3569 }
3570 else if(kind==27) {
3571 Handle(StepDimTol_ConcentricityTolerance) aToler =
3572 new StepDimTol_ConcentricityTolerance;
3573 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3574 Model->AddWithRefs(aToler);
3575 }
3576 else if(kind==28) {
3577 Handle(StepDimTol_ParallelismTolerance) aToler =
3578 new StepDimTol_ParallelismTolerance;
3579 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3580 Model->AddWithRefs(aToler);
3581 }
3582 else if(kind==29) {
3583 Handle(StepDimTol_PerpendicularityTolerance) aToler =
3584 new StepDimTol_PerpendicularityTolerance;
3585 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3586 Model->AddWithRefs(aToler);
3587 }
3588 else if(kind==30) {
3589 Handle(StepDimTol_SymmetryTolerance) aToler =
3590 new StepDimTol_SymmetryTolerance;
3591 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3592 Model->AddWithRefs(aToler);
3593 }
3594 else if(kind==31) {
3595 Handle(StepDimTol_TotalRunoutTolerance) aToler =
3596 new StepDimTol_TotalRunoutTolerance;
3597 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3598 Model->AddWithRefs(aToler);
3599 }
3600 }
3601 }
3602 }
3603
3604 return Standard_True;
3605}
3606
6595eee7 3607//=======================================================================
3608//function : WriteDGTsAP242
3609//purpose :
3610//=======================================================================
3611
3612Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_WorkSession) &WS,
3613 const TDF_LabelSequence &labels ) const
3614{
3615 // Get working data
7f56eba8 3616 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
6595eee7 3617
3618 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3619 if(aHGraph.IsNull())
3620 return Standard_False;
3621
3622 Interface_Graph aGraph = aHGraph->Graph();
3623 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool(labels(1));
3624 if(DGTTool.IsNull())
3625 return Standard_False;
3626
b0cef606 3627 // Common entities for presentation
3628 gdtPresentationDM = new StepVisual_DraughtingModel();
3629 STEPConstruct_Styles aStyles (WS);
3630 Handle(StepVisual_Colour) aCurvColor = aStyles.EncodeColor(Quantity_NOC_WHITE);
3631 Handle(StepRepr_RepresentationItem) anItem = NULL;
3632 gdtPrsCurveStyle = new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
3633 gdtPrsCurveStyle->SetValue(1, aStyles.MakeColorPSA(anItem, aCurvColor, aCurvColor));
3634
6595eee7 3635 TDF_LabelSequence aDGTLabels;
3636 STEPConstruct_DataMapOfAsciiStringTransient aDatumMap;
3637 Handle(StepRepr_RepresentationContext) aRC;
3638
3639 //------------- //
3640 // write Datums //
3641 //--------------//
3642 DGTTool->GetDatumLabels(aDGTLabels);
3643 // Find all shapes with datums
3644 TColStd_MapOfAsciiString aNameIdMap;
3645 for(Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3646 TDF_Label aDatumL = aDGTLabels.Value(i);
3647 TDF_LabelSequence aShapeL;
3648 TDF_LabelSequence aNullSeq;
3649 if(!DGTTool->GetRefShapeLabel(aDatumL, aShapeL, aNullSeq))
3650 continue;
3651 Handle(XCAFDoc_Datum) aDatumAttr;
3652 aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr);
3653 Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject();
3654 TCollection_AsciiString aDatumName = anObject->GetName()->String();
3655 TCollection_AsciiString aDatumTargetId = TCollection_AsciiString(anObject->GetDatumTargetNumber());
3656 if (!aNameIdMap.Add(aDatumName.Cat(aDatumTargetId)))
3657 continue;
aa00364d 3658 Handle(Standard_Transient) aWrittenDatum;
6595eee7 3659 Standard_Boolean isFirstDT = !aDatumMap.Find(aDatumName, aWrittenDatum);
aa00364d 3660 Handle(StepDimTol_Datum) aDatum = WriteDatumAP242(WS, aShapeL.First(), aDatumL, isFirstDT,
3661 Handle(StepDimTol_Datum)::DownCast (aWrittenDatum));
6595eee7 3662 // Add created Datum into Map
3663 aDatumMap.Bind(aDatumName, aDatum);
3664 }
3665
3666 //----------------- //
3667 // write Dimensions //
3668 //------------------//
3669 aDGTLabels.Clear();
3670 DGTTool->GetDimensionLabels(aDGTLabels);
b7b2f85a 3671 // Auxiliary entities for derived geometry
3672 Handle(StepRepr_ConstructiveGeometryRepresentation) aCGRepr =
3673 new StepRepr_ConstructiveGeometryRepresentation();
3674 Handle(StepRepr_ConstructiveGeometryRepresentationRelationship) aCGReprRel =
3675 new StepRepr_ConstructiveGeometryRepresentationRelationship();
3676 NCollection_Vector<Handle(StepGeom_CartesianPoint)> aConnectionPnts;
3677 Handle(StepRepr_RepresentationContext) dummyRC;
3678 Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
6595eee7 3679 for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3680 TDF_Label aDimensionL = aDGTLabels.Value(i);
3681 TDF_LabelSequence aFirstShapeL, aSecondShapeL;
3682 if (!DGTTool->GetRefShapeLabel(aDimensionL, aFirstShapeL, aSecondShapeL))
3683 continue;
3684 Handle(XCAFDoc_Dimension) aDimAttr;
3685 if (!aDimensionL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttr))
3686 continue;
3687 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject();
3688 if (anObject.IsNull())
3689 continue;
3690
3691 // Write links with shapes
6595eee7 3692 Handle(StepRepr_ShapeAspect) aFirstSA, aSecondSA;
3693 if (aFirstShapeL.Length() == 1) {
3694 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(1));
3695 aFirstSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3696 if (aRC.IsNull() && !dummyRC.IsNull())
3697 aRC = dummyRC;
3698 }
3699 else if (aFirstShapeL.Length() > 1) {
3700 Handle(StepRepr_CompositeShapeAspect) aCSA;
3701 for (Standard_Integer shIt = 1; shIt <= aFirstShapeL.Length(); shIt++) {
3702 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(shIt));
3703 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3704 if (aCSA.IsNull() && !aSA.IsNull())
3705 aCSA = new StepRepr_CompositeShapeAspect();
3706 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3707 aModel->AddWithRefs(aCSA);
3708 if (!aSA.IsNull()) {
3709 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3710 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA);
3711 aModel->AddWithRefs(aSAR);
3712 }
3713 if (aRC.IsNull() && !dummyRC.IsNull())
3714 aRC = dummyRC;
3715 }
3716 aFirstSA = aCSA;
3717 }
3718 if (aSecondShapeL.Length() == 1) {
3719 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(1));
3720 aSecondSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3721 if (aRC.IsNull() && !dummyRC.IsNull())
3722 aRC = dummyRC;
3723 }
3724 else if (aSecondShapeL.Length() > 1) {
3725 Handle(StepRepr_CompositeShapeAspect) aCSA;
3726 for (Standard_Integer shIt = 1; shIt <= aSecondShapeL.Length(); shIt++) {
3727 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(shIt));
3728 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3729 if (aCSA.IsNull() && !aSA.IsNull())
3730 aCSA = new StepRepr_CompositeShapeAspect();
3731 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3732 if (!aSA.IsNull()) {
3733 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3734 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA);
3735 aModel->AddWithRefs(aSAR);
3736 }
3737 if (aRC.IsNull() && !dummyRC.IsNull())
3738 aRC = dummyRC;
3739 }
3740 aSecondSA = aCSA;
3741 }
3742
3743 // Write dimensions
3744 StepShape_DimensionalCharacteristic aDimension;
b7b2f85a 3745 if (anObject->HasPoint() || anObject->HasPoint2())
3746 WriteDerivedGeometry(WS, anObject, aCGRepr, aFirstSA, aSecondSA, aConnectionPnts);
6595eee7 3747 XCAFDimTolObjects_DimensionType aDimType = anObject->GetType();
727b5ad9 3748 if (STEPCAFControl_GDTProperty::IsDimensionalLocation(aDimType)) {
6595eee7 3749 // Dimensional_Location
3750 Handle(StepShape_DimensionalLocation) aDim = new StepShape_DimensionalLocation();
727b5ad9 3751 aDim->Init(STEPCAFControl_GDTProperty::GetDimTypeName(aDimType), Standard_False, NULL, aFirstSA, aSecondSA);
6595eee7 3752 aDimension.SetValue(aDim);
3753 }
3754 else if (aDimType == XCAFDimTolObjects_DimensionType_Location_Angular) {
3755 // Angular_Location
3756 Handle(StepShape_AngularLocation) aDim = new StepShape_AngularLocation();
3757 StepShape_AngleRelator aRelator = StepShape_Equal;
3758 if (anObject->HasQualifier()) {
3759 XCAFDimTolObjects_DimensionQualifier aQualifier = anObject->GetQualifier();
3760 switch (aQualifier) {
3761 case XCAFDimTolObjects_DimensionQualifier_Min: aRelator = StepShape_Small;
3762 break;
3763 case XCAFDimTolObjects_DimensionQualifier_Max: aRelator = StepShape_Large;
3764 break;
3765 default: aRelator = StepShape_Equal;
3766 }
3767 }
3768 aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aRelator);
3769 aDimension.SetValue(aDim);
3770 }
3771 else if (aDimType == XCAFDimTolObjects_DimensionType_Location_WithPath) {
3772 // Dimensional_Location_With_Path
3773 Handle(StepShape_DimensionalLocationWithPath) aDim = new StepShape_DimensionalLocationWithPath();
3774 Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU);
3775 aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aPathSA);
3776 aDimension.SetValue(aDim);
3777 }
727b5ad9 3778 else if (STEPCAFControl_GDTProperty::IsDimensionalSize(aDimType)) {
6595eee7 3779 // Dimensional_Size
3780 Handle(StepShape_DimensionalSize) aDim = new StepShape_DimensionalSize();
727b5ad9 3781 aDim->Init(aFirstSA, STEPCAFControl_GDTProperty::GetDimTypeName(aDimType));
6595eee7 3782 aDimension.SetValue(aDim);
3783 }
3784 else if (aDimType == XCAFDimTolObjects_DimensionType_Size_Angular) {
3785 // Angular_Size
3786 Handle(StepShape_AngularSize) aDim = new StepShape_AngularSize();
3787 StepShape_AngleRelator aRelator = StepShape_Equal;
3788 if (anObject->HasQualifier()) {
3789 XCAFDimTolObjects_DimensionQualifier aQualifier = anObject->GetQualifier();
3790 switch (aQualifier) {
3791 case XCAFDimTolObjects_DimensionQualifier_Min: aRelator = StepShape_Small;
3792 break;
3793 case XCAFDimTolObjects_DimensionQualifier_Max: aRelator = StepShape_Large;
3794 break;
3795 default: aRelator = StepShape_Equal;
3796 }
3797 }
3798 aDim->Init(aFirstSA, new TCollection_HAsciiString(), aRelator);
3799 aDimension.SetValue(aDim);
3800 }
3801 else if (aDimType == XCAFDimTolObjects_DimensionType_Size_WithPath) {
3802 // Dimensional_Size_With_Path
3803 Handle(StepShape_DimensionalSizeWithPath) aDim = new StepShape_DimensionalSizeWithPath();
3804 Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU);
3805 aDim->Init(aFirstSA, new TCollection_HAsciiString(), aPathSA);
3806 aDimension.SetValue(aDim);
3807 }
3808
3809 // Write values
3810 WriteDimValues(WS, anObject, aRC, aDimension);
b0cef606 3811 //Annotation plane and Presentation
f0bf70e8 3812 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPlane(), anObject->GetPointTextAttach(), aDimension.Value());
6595eee7 3813 }
b7b2f85a 3814 // Write Derived geometry
3815 if (aConnectionPnts.Length() > 0) {
3816 Handle(StepRepr_HArray1OfRepresentationItem) anItems = new StepRepr_HArray1OfRepresentationItem(1, aConnectionPnts.Length());
3817 for (Standard_Integer i = 0; i < aConnectionPnts.Length(); i++)
3818 anItems->SetValue(i + 1, aConnectionPnts(i));
3819 aCGRepr->Init(new TCollection_HAsciiString(), anItems, dummyRC);
3820 aCGReprRel->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), dummyGISU->UsedRepresentation(), aCGRepr);
3821 aModel->AddWithRefs(aCGReprRel);
3822 }
6595eee7 3823
3824 //----------------------------//
3825 // write Geometric Tolerances //
3826 //----------------------------//
3827 aDGTLabels.Clear();
3828 DGTTool->GetGeomToleranceLabels(aDGTLabels);
3829 for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3830 TDF_Label aGeomTolL = aDGTLabels.Value(i);
3831 TDF_LabelSequence aFirstShapeL, aNullSeqL;
3832 if (!DGTTool->GetRefShapeLabel(aGeomTolL, aFirstShapeL, aNullSeqL))
3833 continue;
3834 TDF_LabelSequence aDatumSeq;
3835 DGTTool->GetDatumWithObjectOfTolerLabels(aGeomTolL, aDatumSeq);
3836 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
3837 if (aDatumSeq.Length() > 0)
3838 aDatumSystem = WriteDatumSystem(WS, aGeomTolL, aDatumSeq, aDatumMap, aRC);
3839 WriteGeomTolerance(WS, aFirstShapeL, aGeomTolL, aDatumSystem, aRC);
3840 }
3841
b0cef606 3842 // Write Draughting model for Annotation Planes
3843 if (gdtAnnotationPlanes.Length() == 0)
3844 return Standard_True;
3845
3846 Handle(StepRepr_HArray1OfRepresentationItem) aItems =
3847 new StepRepr_HArray1OfRepresentationItem(1, gdtAnnotationPlanes.Length());
3848 for (Standard_Integer i = 1; i <= aItems->Length(); i++) {
3849 aItems->SetValue(i, gdtAnnotationPlanes.Value(i - 1));
3850 }
3851 gdtPresentationDM->Init(new TCollection_HAsciiString(), aItems, aRC);
3852 aModel->AddWithRefs(gdtPresentationDM);
3853
6595eee7 3854 return Standard_True;
3855}
7fd59977 3856
3857//=======================================================================
3858//function : FindPDSforRI
3859//purpose : auxilary:
3860//=======================================================================
3861static Standard_Boolean FindPDSforRI(const Interface_Graph &aGraph,
3862 const Handle(Standard_Transient) &ent,
3863 Handle(StepRepr_ProductDefinitionShape) &PDS,
3864 Handle(StepRepr_RepresentationContext) &RC)
3865{
3866 if(!ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem))) return Standard_False;
3867 Interface_EntityIterator subs = aGraph.Sharings(ent);
3868 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
3869 Handle(StepShape_ShapeRepresentation) SR =
3870 Handle(StepShape_ShapeRepresentation)::DownCast(subs.Value());
3871 if(SR.IsNull()) continue;
3872 RC = SR->ContextOfItems();
3873 Interface_EntityIterator subs1 = aGraph.Sharings(SR);
3874 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
3875 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
3876 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs1.Value());
3877 if(SDR.IsNull()) continue;
3878 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
3879 if(PropD.IsNull()) continue;
3880 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
3881 }
3882 }
3883 return Standard_True;
3884}
3885
3886
3887//=======================================================================
3888//function : WriteMaterials
3889//purpose :
3890//=======================================================================
3891
3892Standard_Boolean STEPCAFControl_Writer::WriteMaterials (const Handle(XSControl_WorkSession) &WS,
3893 const TDF_LabelSequence &labels ) const
3894{
3895
3896 if ( labels.Length() <=0 ) return Standard_False;
3897
3898 // get working data
7f56eba8 3899 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3900 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
3901 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
9e20ed57 3902
3903 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3904 if(aHGraph.IsNull())
3905 return Standard_False;
3906
7fd59977 3907 Interface_Graph aGraph = WS->HGraph()->Graph();
3908 Handle(XCAFDoc_ShapeTool) ShTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
3909 if(ShTool.IsNull() ) return Standard_False;
3910 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( labels(1) );
3911 if(MatTool.IsNull() ) return Standard_False;
3912
3913 STEPConstruct_DataMapOfAsciiStringTransient MapDRI,MapMRI;
3914 TDF_LabelSequence TopLabels;
3915 ShTool->GetShapes(TopLabels);
3916 for(Standard_Integer i=1; i<=TopLabels.Length(); i++) {
3917 TDF_Label ShL = TopLabels.Value(i);
3918 Handle(TDataStd_TreeNode) Node;
3919 if( ShL.FindAttribute(XCAFDoc::MaterialRefGUID(),Node) && Node->HasFather() ) {
3920 // find PDS for current shape
3921 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShL);
3922 TopLoc_Location Loc;
3923 TColStd_SequenceOfTransient seqRI;
3924 FindEntities( FP, aShape, Loc, seqRI );
3925 if(seqRI.Length()<=0) continue;
3926 Handle(StepRepr_ProductDefinitionShape) PDS;
3927 Handle(StepRepr_RepresentationContext) RC;
3928 Handle(Standard_Transient) ent = seqRI.Value(1);
3929 FindPDSforRI(aGraph,ent,PDS,RC);
3930 if(PDS.IsNull()) continue;
1d2b1ccb
G
3931 Handle(StepBasic_ProductDefinition) aProdDef =
3932 PDS->Definition().ProductDefinition();
3933 if(aProdDef.IsNull())
3934 continue;
7fd59977 3935 // write material entities
3936 TDF_Label MatL = Node->Father()->Label();
3937 Handle(TCollection_HAsciiString) aName;
3938 Handle(TCollection_HAsciiString) aDescription;
3939 Standard_Real aDensity;
3940 Handle(TCollection_HAsciiString) aDensName;
3941 Handle(TCollection_HAsciiString) aDensValType;
41e259eb 3942 Handle(StepRepr_Representation) RepDRI;
3943 Handle(StepRepr_Representation) RepMRI;
7fd59977 3944 if(MatTool->GetMaterial(MatL,aName,aDescription,aDensity,aDensName,aDensValType)) {
3945 if(aName->Length()==0) continue;
3946 TCollection_AsciiString aKey(aName->ToCString());
3947 if(MapDRI.IsBound(aKey)) {
3948 RepDRI = Handle(StepRepr_Representation)::DownCast(MapDRI.Find(aKey));
3949 if(MapMRI.IsBound(aKey)) {
3950 RepMRI = Handle(StepRepr_Representation)::DownCast(MapMRI.Find(aKey));
3951 }
3952 }
3953 else {
3954 // write DRI
3955 Handle(StepRepr_DescriptiveRepresentationItem) DRI = new StepRepr_DescriptiveRepresentationItem;
3956 DRI->Init(aName,aDescription);
3957 Handle(StepRepr_HArray1OfRepresentationItem) HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
3958 HARI->SetValue(1,DRI);
41e259eb 3959 RepDRI = new StepRepr_Representation();
7fd59977 3960 RepDRI->Init(new TCollection_HAsciiString("material name"),HARI,RC);
3961 Model->AddWithRefs(RepDRI);
3962 // write MRI
41e259eb 3963 if( aDensity > 0 ) {
7fd59977 3964 // mass
3965 Handle(StepBasic_SiUnitAndMassUnit) SMU = new StepBasic_SiUnitAndMassUnit;
3966 SMU->SetName(StepBasic_sunGram);
3967 Handle(StepBasic_DerivedUnitElement) DUE1 = new StepBasic_DerivedUnitElement;
3968 DUE1->Init(SMU,3.0);
3969 // length
3970 Handle(StepBasic_SiUnitAndLengthUnit) SLU = new StepBasic_SiUnitAndLengthUnit;
3971 SLU->Init(Standard_True,StepBasic_spCenti,StepBasic_sunMetre);
3972 Handle(StepBasic_DerivedUnitElement) DUE2 = new StepBasic_DerivedUnitElement;
3973 DUE2->Init(SLU,2.0);
3974 // other
3975 Handle(StepBasic_HArray1OfDerivedUnitElement) HADUE = new StepBasic_HArray1OfDerivedUnitElement(1,2);
3976 HADUE->SetValue(1,DUE1);
3977 HADUE->SetValue(2,DUE2);
3978 Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit;
3979 DU->Init(HADUE);
3980 Model->AddWithRefs(DU);
3981 StepBasic_Unit aUnit;
3982 aUnit.SetValue(DU);
3983 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
3984 MVM->SetName(aDensValType->ToCString());
3985 MVM->SetReal(aDensity);
3986 Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem;
3987 MRI->Init(aDensName,MVM,aUnit);
3988 HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
3989 HARI->SetValue(1,MRI);
41e259eb 3990 RepMRI = new StepRepr_Representation();
7fd59977 3991 RepMRI->Init(new TCollection_HAsciiString("density"),HARI,RC);
3992 Model->AddWithRefs(RepMRI);
3993 }
3994 //WriteNewMaterial(Model,aName,aDescription,aDensity,aDensName,aDensValType,RC,RepDRI,RepMRI);
3995 MapDRI.Bind(aKey,RepDRI);
41e259eb 3996 if ( !RepMRI.IsNull() ) MapMRI.Bind (aKey, RepMRI);
3997 }
3998 }
3999
4000 if( !RepDRI.IsNull() )
4001 {
4002 StepRepr_CharacterizedDefinition CD1;
4003 CD1.SetValue(aProdDef);
4004 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
4005 PropD1->Init(new TCollection_HAsciiString("material property"),Standard_True,
4006 new TCollection_HAsciiString("material name"),CD1);
4007 Model->AddWithRefs(PropD1);
4008 StepRepr_RepresentedDefinition RD1;
4009 RD1.SetValue(PropD1);
4010 Handle(StepRepr_PropertyDefinitionRepresentation) PDR1 =
4011 new StepRepr_PropertyDefinitionRepresentation;
4012 PDR1->Init(RD1,RepDRI);
4013 Model->AddWithRefs(PDR1);
4014
4015 if( !RepMRI.IsNull() )
4016 {
4017 StepRepr_CharacterizedDefinition CD2;
4018 CD2.SetValue (aProdDef);
4019 Handle (StepRepr_PropertyDefinition) PropD2 = new StepRepr_PropertyDefinition;
4020 PropD2->Init (new TCollection_HAsciiString ("material property"), Standard_True,
4021 new TCollection_HAsciiString ("density"), CD2);
4022 Model->AddWithRefs (PropD2);
4023 StepRepr_RepresentedDefinition RD2;
4024 RD2.SetValue (PropD2);
4025 Handle (StepRepr_PropertyDefinitionRepresentation) PDR2 =
4026 new StepRepr_PropertyDefinitionRepresentation;
4027 PDR2->Init (RD2, RepMRI);
4028 Model->AddWithRefs (PDR2);
7fd59977 4029 }
4030 }
7fd59977 4031 }
4032 }
4033
4034 return Standard_True;
4035}
4036
4037
4038//=======================================================================
4039//function : SetColorMode
4040//purpose :
4041//=======================================================================
4042
4043void STEPCAFControl_Writer::SetColorMode (const Standard_Boolean colormode)
4044{
4045 myColorMode = colormode;
4046}
4047
4048
4049//=======================================================================
4050//function : GetColorMode
4051//purpose :
4052//=======================================================================
4053
4054Standard_Boolean STEPCAFControl_Writer::GetColorMode () const
4055{
4056 return myColorMode;
4057}
4058
4059
4060//=======================================================================
4061//function : SetNameMode
4062//purpose :
4063//=======================================================================
4064
4065void STEPCAFControl_Writer::SetNameMode (const Standard_Boolean namemode)
4066{
4067 myNameMode = namemode;
4068}
4069
4070
4071//=======================================================================
4072//function : GetNameMode
4073//purpose :
4074//=======================================================================
4075
4076Standard_Boolean STEPCAFControl_Writer::GetNameMode () const
4077{
4078 return myNameMode;
4079}
4080
4081
4082//=======================================================================
4083//function : SetLayerMode
4084//purpose :
4085//=======================================================================
4086
4087void STEPCAFControl_Writer::SetLayerMode (const Standard_Boolean layermode)
4088{
4089 myLayerMode = layermode;
4090}
4091
4092
4093//=======================================================================
4094//function : GetLayerMode
4095//purpose :
4096//=======================================================================
4097
4098Standard_Boolean STEPCAFControl_Writer::GetLayerMode () const
4099{
4100 return myLayerMode;
4101}
4102
4103
4104//=======================================================================
4105//function : SetPropsMode
4106//purpose :
4107//=======================================================================
4108
4109void STEPCAFControl_Writer::SetPropsMode (const Standard_Boolean propsmode)
4110{
4111 myPropsMode = propsmode;
4112}
4113
4114
4115//=======================================================================
4116//function : GetPropsMode
4117//purpose :
4118//=======================================================================
4119
4120Standard_Boolean STEPCAFControl_Writer::GetPropsMode () const
4121{
4122 return myPropsMode;
4123}
4124
4125
4126//=======================================================================
4127//function : SetSHUOMode
4128//purpose :
4129//=======================================================================
4130
4131void STEPCAFControl_Writer::SetSHUOMode (const Standard_Boolean mode)
4132{
4133 mySHUOMode = mode;
4134}
4135
4136
4137//=======================================================================
4138//function : GetSHUOMode
4139//purpose :
4140//=======================================================================
4141
4142Standard_Boolean STEPCAFControl_Writer::GetSHUOMode () const
4143{
4144 return mySHUOMode;
4145}
4146
4147
4148//=======================================================================
4149//function : SetDimTolMode
4150//purpose :
4151//=======================================================================
4152
4153void STEPCAFControl_Writer::SetDimTolMode(const Standard_Boolean dimtolmode)
4154{
4155 myDGTMode = dimtolmode;
4156}
4157
4158
4159//=======================================================================
4160//function : GetDimTolMode
4161//purpose :
4162//=======================================================================
4163
4164Standard_Boolean STEPCAFControl_Writer::GetDimTolMode() const
4165{
4166 return myDGTMode;
4167}
4168
4169
4170//=======================================================================
4171//function : SetMaterialMode
4172//purpose :
4173//=======================================================================
4174
4175void STEPCAFControl_Writer::SetMaterialMode(const Standard_Boolean matmode)
4176{
4177 myMatMode = matmode;
4178}
4179
4180
4181//=======================================================================
4182//function : GetMaterialMode
4183//purpose :
4184//=======================================================================
4185
4186Standard_Boolean STEPCAFControl_Writer::GetMaterialMode() const
4187{
4188 return myMatMode;
4189}