0027934: Data Exchange - implement STEP common labels
[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
dde68833 670 if (Interface_Static::IVal("write.stepcaf.subshapes.name") != 0)
02a0b964 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,
0b622d67 2319 const Handle(TCollection_HAsciiString)& thePrsName,
b0cef606 2320 const gp_Ax2 theAnnotationPlane,
f0bf70e8 2321 const gp_Pnt theTextPosition,
b0cef606 2322 const Handle(Standard_Transient) theDimension)
2323{
2324 if (thePresentation.IsNull())
2325 return;
2326 // Get working data
7f56eba8 2327 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
b0cef606 2328
2329 // Presentation
2330 Handle(StepVisual_TessellatedGeometricSet) aGeomSet = STEPCAFControl_GDTProperty::GetTessellation(thePresentation);
2331 Handle(StepVisual_TessellatedAnnotationOccurrence) aTAO = new StepVisual_TessellatedAnnotationOccurrence();
2332 aTAO->Init(new TCollection_HAsciiString(), gdtPrsCurveStyle, aGeomSet);
2333 StepVisual_DraughtingCalloutElement aDCElement;
2334 aDCElement.SetValue(aTAO);
2335 Handle(StepVisual_HArray1OfDraughtingCalloutElement) aTAOs = new StepVisual_HArray1OfDraughtingCalloutElement(1, 1);
2336 aTAOs->SetValue(1, aDCElement);
2337 Handle(StepVisual_DraughtingCallout) aDCallout = new StepVisual_DraughtingCallout();
0b622d67 2338 aDCallout->Init(thePrsName, aTAOs);
b0cef606 2339 Handle(StepRepr_HArray1OfRepresentationItem) aDCsForDMIA = new StepRepr_HArray1OfRepresentationItem(1, 1);
2340 aDCsForDMIA->SetValue(1, aDCallout);
2341 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDimension;
2342 aDimension.SetValue(theDimension);
2343 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
2344 new StepAP242_DraughtingModelItemAssociation();
2345 aDMIA->Init(new TCollection_HAsciiString("PMI representation to presentation link"),
2346 new TCollection_HAsciiString(), aDimension, gdtPresentationDM, aDCsForDMIA);
2347 aModel->AddWithRefs(aDMIA);
2348
2349 // Annotation plane
2350 // Presentation Style
2351 Handle(StepVisual_NullStyleMember) aNullStyle = new StepVisual_NullStyleMember();
2352 aNullStyle->SetEnumText(0, ".NULL.");
2353 StepVisual_PresentationStyleSelect aStyleItem;
2354 aStyleItem.SetValue(aNullStyle);
2355 Handle(StepVisual_HArray1OfPresentationStyleSelect) aStyles = new StepVisual_HArray1OfPresentationStyleSelect(1, 1);
2356 aStyles->SetValue(1, aStyleItem);
2357 Handle(StepVisual_PresentationStyleAssignment) aPrsStyle = new StepVisual_PresentationStyleAssignment();
2358 aPrsStyle->Init(aStyles);
2359 Handle(StepVisual_HArray1OfPresentationStyleAssignment) aPrsStyles =
2360 new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
2361 aPrsStyles->SetValue(1, aPrsStyle);
2362 // Plane
2363 Handle(StepGeom_Plane) aPlane = new StepGeom_Plane();
2364 Handle(StepGeom_Axis2Placement3d) anAxis = STEPCAFControl_GDTProperty::GetAxis2Placement3D(theAnnotationPlane);
f0bf70e8 2365 // Set text position to plane origin
2366 Handle(StepGeom_CartesianPoint) aTextPos = new StepGeom_CartesianPoint();
2367 Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
2368 for (Standard_Integer i = 1; i <= 3; i++)
2369 aCoords->SetValue(i, theTextPosition.Coord(i));
2370 aTextPos->Init(new TCollection_HAsciiString(), aCoords);
2371 anAxis->SetLocation(aTextPos);
b0cef606 2372 aPlane->Init(new TCollection_HAsciiString(), anAxis);
2373 // Annotation plane element
2374 StepVisual_AnnotationPlaneElement aPlaneElement;
2375 aPlaneElement.SetValue(aDCallout);
2376 Handle(StepVisual_HArray1OfAnnotationPlaneElement) aDCsForAnnPln = new StepVisual_HArray1OfAnnotationPlaneElement(1, 1);
2377 aDCsForAnnPln->SetValue(1, aPlaneElement);
2378 // Init AnnotationPlane entity
2379 Handle(StepVisual_AnnotationPlane) anAnnPlane = new StepVisual_AnnotationPlane();
2380 anAnnPlane->Init(new TCollection_HAsciiString(), aPrsStyles, aPlane, aDCsForAnnPln);
2381 gdtAnnotationPlanes.Append(anAnnPlane);
2382 aModel->AddWithRefs(anAnnPlane);
2383}
2384
0b622d67 2385//======================================================================
2386//function : WritePresentation
2387//purpose : auxiliary (write annotation plane and presentation for common labels)
2388//======================================================================
2389static void WritePresentation(const Handle(XSControl_WorkSession) &WS,
2390 const TopoDS_Shape thePresentation,
2391 const Handle(TCollection_HAsciiString)& thePrsName,
2392 const gp_Ax2 theAnnotationPlane)
2393{
2394 if (thePresentation.IsNull())
2395 return;
2396 // Get working data
2397 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2398
2399 // Presentation
2400 Handle(StepVisual_TessellatedGeometricSet) aGeomSet = STEPCAFControl_GDTProperty::GetTessellation(thePresentation);
2401 Handle(StepVisual_TessellatedAnnotationOccurrence) aTAO = new StepVisual_TessellatedAnnotationOccurrence();
2402 aTAO->Init(new TCollection_HAsciiString(), gdtPrsCurveStyle, aGeomSet);
2403 StepVisual_DraughtingCalloutElement aDCElement;
2404 aDCElement.SetValue(aTAO);
2405 Handle(StepVisual_HArray1OfDraughtingCalloutElement) aTAOs = new StepVisual_HArray1OfDraughtingCalloutElement(1, 1);
2406 aTAOs->SetValue(1, aDCElement);
2407 Handle(StepVisual_DraughtingCallout) aDCallout = new StepVisual_DraughtingCallout();
2408 aDCallout->Init(thePrsName, aTAOs);
2409 aModel->AddWithRefs(aDCallout);
2410
2411 // Annotation plane
2412 // Presentation Style
2413 Handle(StepVisual_NullStyleMember) aNullStyle = new StepVisual_NullStyleMember();
2414 aNullStyle->SetEnumText(0, ".NULL.");
2415 StepVisual_PresentationStyleSelect aStyleItem;
2416 aStyleItem.SetValue(aNullStyle);
2417 Handle(StepVisual_HArray1OfPresentationStyleSelect) aStyles = new StepVisual_HArray1OfPresentationStyleSelect(1, 1);
2418 aStyles->SetValue(1, aStyleItem);
2419 Handle(StepVisual_PresentationStyleAssignment) aPrsStyle = new StepVisual_PresentationStyleAssignment();
2420 aPrsStyle->Init(aStyles);
2421 Handle(StepVisual_HArray1OfPresentationStyleAssignment) aPrsStyles =
2422 new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
2423 aPrsStyles->SetValue(1, aPrsStyle);
2424 // Plane
2425 Handle(StepGeom_Plane) aPlane = new StepGeom_Plane();
2426 Handle(StepGeom_Axis2Placement3d) anAxis = STEPCAFControl_GDTProperty::GetAxis2Placement3D(theAnnotationPlane);
2427 aPlane->Init(new TCollection_HAsciiString(), anAxis);
2428 // Annotation plane element
2429 StepVisual_AnnotationPlaneElement aPlaneElement;
2430 aPlaneElement.SetValue(aDCallout);
2431 Handle(StepVisual_HArray1OfAnnotationPlaneElement) aDCsForAnnPln = new StepVisual_HArray1OfAnnotationPlaneElement(1, 1);
2432 aDCsForAnnPln->SetValue(1, aPlaneElement);
2433 // Init AnnotationPlane entity
2434 Handle(StepVisual_AnnotationPlane) anAnnPlane = new StepVisual_AnnotationPlane();
2435 anAnnPlane->Init(new TCollection_HAsciiString(), aPrsStyles, aPlane, aDCsForAnnPln);
2436 gdtAnnotationPlanes.Append(anAnnPlane);
2437 aModel->AddWithRefs(anAnnPlane);
2438}
2439
6595eee7 2440//=======================================================================
2441//function : WriteDatumAP242
2442//purpose : auxiliary (write Datum entity for given shape or write all
2443// necessary entities and link them to already written datum
2444// in case of multiple features association)
2445//=======================================================================
2446static Handle(StepDimTol_Datum) WriteDatumAP242(const Handle(XSControl_WorkSession) &WS,
2447 const TDF_Label theShapeL,
2448 const TDF_Label theDatumL,
2449 const Standard_Boolean isFirstDTarget,
2450 const Handle(StepDimTol_Datum) theWrittenDatum)
2451{
2452 // Get working data
7f56eba8 2453 const Handle(Interface_InterfaceModel) &Model = WS->Model();
2454 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
2455 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
6595eee7 2456 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2457 if (aHGraph.IsNull())
2458 return NULL;
2459 Interface_Graph aGraph = aHGraph->Graph();
2460
2461 Handle(StepRepr_ShapeAspect) aSA;
2462 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2463 // Link with datum feature
2464 Handle(StepRepr_ProductDefinitionShape) aPDS;
2465 Handle(StepRepr_RepresentationContext) aRC;
2466 Handle(Standard_Transient) anEnt;
2467 Handle(StepShape_AdvancedFace) anAF;
2468 Handle(StepShape_EdgeCurve) anEC;
2469 TopoDS_Shape aShape;
2470 TopLoc_Location aLoc;
2471 TColStd_SequenceOfTransient aSeqRI;
2472
2473 aShape = XCAFDoc_ShapeTool::GetShape(theShapeL);
2474 FindEntities( FP, aShape, aLoc, aSeqRI );
2475 if ( aSeqRI.Length() <= 0 ) {
2476 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
2477 return NULL;
2478 }
2479 anEnt = aSeqRI.Value(1);
2480 FindPDSforDGT(aGraph, anEnt, aPDS, aRC, anAF, anEC);
2481 if (aPDS.IsNull())
2482 return NULL;
2483
2484 aSA = WriteShapeAspect(WS, theDatumL, aShape, aRC, aGISU);
2485 if (aSA.IsNull())
2486 return NULL;
2487 Standard_Integer aSANum = Model->Number(aSA);
2488 Standard_Integer aGISUNum = Model->Number(aGISU);
2489 // Find if datum has datum targets and get common datum attributes
2490 Handle(XCAFDoc_Datum) aDatumAttr;
2491 if (!theDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
2492 return NULL;
2493 Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject();
2494 if (anObject.IsNull())
2495 return NULL;
2496 Standard_Boolean isSimpleDatum = !anObject->IsDatumTarget();
2497 Handle(TCollection_HAsciiString) anIdentifier = anObject->GetName();
2498 Handle(TCollection_HAsciiString) aTargetId = (anObject->GetDatumTargetNumber() == 0 ?
2499 new TCollection_HAsciiString() : new TCollection_HAsciiString(anObject->GetDatumTargetNumber()));
2500
2501 // If datum type is area, but there is no area in object, write as simple datum
2502 if (anObject->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Area &&
2503 anObject->GetDatumTarget().IsNull())
2504 isSimpleDatum = Standard_True;
2505
2506 // Simple datum
2507 if (isSimpleDatum) {
2508 Handle(StepDimTol_DatumFeature) aDF = new StepDimTol_DatumFeature();
2509 aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aSA->OfShape(), aSA->ProductDefinitional());
2510 Model->ReplaceEntity(aSANum, aDF);
2511 aSA = aDF;
2512 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2513 aDefinition.SetValue(aDF);
2514 aGISU->SetDefinition(aDefinition);
2515 Model->ReplaceEntity(aGISUNum, aGISU);
2516 }
2517 // Datum with datum targets
2518 else {
2519 XCAFDimTolObjects_DatumTargetType aDatumType = anObject->GetDatumTargetType();
2520 Handle(StepDimTol_DatumTarget) aDatumTarget;
2521 // Note: the given way to write such datum type may be incorrect (too little information)
2522 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Area) {
2523 TopoDS_Shape aDTShape = anObject->GetDatumTarget();
2524 Handle(StepAP242_GeometricItemSpecificUsage) anAreaGISU;
2525 Handle(StepRepr_ShapeAspect) anAreaSA = WriteShapeAspect(WS, theDatumL, aDTShape, aRC, anAreaGISU);
2526 aSANum = Model->Number(anAreaSA);
2527 aGISUNum = Model->Number(anAreaGISU);
2528 Handle(StepDimTol_DatumTarget) aDT = new StepDimTol_DatumTarget();
2529 aDT->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString("area"), anAreaSA->OfShape(),
2530 anAreaSA->ProductDefinitional(), aTargetId);
2531 Model->ReplaceEntity(aSANum, aDT);
2532 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2533 aDefinition.SetValue(aDT);
2534 anAreaGISU->SetDefinition(aDefinition);
2535 Model->ReplaceEntity(aGISUNum, anAreaGISU);
2536 }
2537 else {
2538 Handle(StepDimTol_PlacedDatumTargetFeature) aPDTF = new StepDimTol_PlacedDatumTargetFeature();
727b5ad9 2539 aPDTF->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDatumTargetName(aDatumType),
6595eee7 2540 aPDS, StepData_LTrue, aTargetId);
2541 Model->AddWithRefs(aPDTF);
2542 aDatumTarget = aPDTF;
2543 // Datum targets
2544 Handle(StepRepr_PropertyDefinition) aPD = new StepRepr_PropertyDefinition();
2545 StepRepr_CharacterizedDefinition aCDefinition;
2546 aCDefinition.SetValue(aPDTF);
2547 aPD->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCDefinition);
2548 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP = new StepShape_ShapeRepresentationWithParameters();
2549 // Common for all datum targets
2550 StepBasic_Unit aUnit = GetUnit(aRC);
2551 gp_Ax2 aDTAxis = anObject->GetDatumTargetAxis();
2552 Handle(StepGeom_Axis2Placement3d) anA2P3D =
727b5ad9 2553 STEPCAFControl_GDTProperty::GetAxis2Placement3D(aDTAxis);
b0cef606 2554 anA2P3D->SetName(new TCollection_HAsciiString("orientation"));
6595eee7 2555 Handle(StepRepr_HArray1OfRepresentationItem) anItems;
2556 // Process each datum target type
2557 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Point) {
2558 anItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
2559 }
2560 else {
2561 Handle(TCollection_HAsciiString) aTargetValueName;
2562 if (aDatumType == XCAFDimTolObjects_DatumTargetType_Line) {
2563 anItems = new StepRepr_HArray1OfRepresentationItem(1, 2);
2564 aTargetValueName = new TCollection_HAsciiString("target length");
2565 }
2566 else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Rectangle) {
2567 anItems = new StepRepr_HArray1OfRepresentationItem(1, 3);
2568 aTargetValueName = new TCollection_HAsciiString("target length");
2569 // Additional value
2570 Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue = CreateDimValue(anObject->GetDatumTargetWidth(),
2571 aUnit, new TCollection_HAsciiString("target width"), "POSITIVE_LENGTH_MEASURE", Standard_False);
2572 anItems->SetValue(2, aTargetValue);
2573 Model->AddWithRefs(aTargetValue);
2574 }
2575 else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Circle) {
2576 anItems = new StepRepr_HArray1OfRepresentationItem(1, 2);
2577 aTargetValueName = new TCollection_HAsciiString("target diameter");
2578 }
2579 // Value
2580 Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue= CreateDimValue(anObject->GetDatumTargetLength(),
2581 aUnit, aTargetValueName, "POSITIVE_LENGTH_MEASURE", Standard_False);
2582 anItems->SetValue(1, aTargetValue);
2583 Model->AddWithRefs(aTargetValue);
2584 }
2585 anItems->SetValue(anItems->Length(), anA2P3D);
2586 aSRWP->Init(new TCollection_HAsciiString(), anItems, aRC);
2587
2588 // Create and write auxiliary entities
2589 Handle (StepShape_ShapeDefinitionRepresentation) aSDR = new StepShape_ShapeDefinitionRepresentation();
2590 StepRepr_RepresentedDefinition aRDefinition;
2591 aRDefinition.SetValue(aPD);
2592 aSDR->Init(aRDefinition, aSRWP);
2593 Model->AddWithRefs(aPD);
2594 Model->AddWithRefs(aSRWP);
2595 Model->AddWithRefs(aSDR);
2596 }
2597 // Link datum target to datum feature
2598 Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR = new StepRepr_FeatureForDatumTargetRelationship();
2599 aFFDTR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aDatumTarget, aSA);
2600 Model->AddWithRefs(aFFDTR);
2601 aSA = aDatumTarget;
2602 }
2603
2604 // Datum
2605 Handle(StepDimTol_Datum) aDatum = theWrittenDatum;
2606 if (isFirstDTarget) {
2607 aDatum = new StepDimTol_Datum();
2608 aDatum->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue, anIdentifier);
2609 Model->AddWithRefs(aDatum);
2610 }
2611
2612 // Shape_Aspect_Relationship
2613 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
2614 aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aSA, aDatum);
2615 Model->AddWithRefs(aSAR);
2616
2617 // Auxiliary entities
2618 // Property_Definition
2619 Handle(StepRepr_PropertyDefinition) aPD = new StepRepr_PropertyDefinition();
2620 Handle(TCollection_HAsciiString) aPDName = new TCollection_HAsciiString("Datum Feature Symbol ");
2621 aPDName = aPDName->Cat(anIdentifier)->Cat(aTargetId);
2622 StepRepr_CharacterizedDefinition aCD;
2623 aCD.SetValue(aSA);
2624 aPD->Init(aPDName, Standard_False, NULL, aCD);
2625 Model->AddWithRefs(aPD);
2626 // Shape_Representation
2627 Handle(StepShape_ShapeRepresentation) aShapeRepr = new StepShape_ShapeRepresentation();
2628 aShapeRepr->Init(aPDName, aGISU->IdentifiedItem(), aRC);
2629 Model->AddWithRefs(aShapeRepr);
2630 // Shape_Definition_Representation
2631 Handle (StepShape_ShapeDefinitionRepresentation) aSDR = new StepShape_ShapeDefinitionRepresentation();
2632 StepRepr_RepresentedDefinition aRDefinition;
2633 aRDefinition.SetValue(aPD);
2634 aSDR->Init(aRDefinition, aShapeRepr);
2635 Model->AddWithRefs(aSDR);
2636
b0cef606 2637 //Annotation plane and Presentation
0b622d67 2638 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->GetPlane(), anObject->GetPointTextAttach(), aSA);
b0cef606 2639
6595eee7 2640 return aDatum;
2641}
2642
2643//=======================================================================
2644//function : WriteDimValues
2645//purpose : auxiliary (write all data for given dimension: values,
2646// qualifiers, modifiers, orientation and tolerance class)
2647//======================================================================
2648static void WriteDimValues(const Handle(XSControl_WorkSession) &WS,
2649 const Handle(XCAFDimTolObjects_DimensionObject) theObject,
2650 const Handle(StepRepr_RepresentationContext) theRC,
2651 const StepShape_DimensionalCharacteristic theDimension)
2652{
2653 // Get working data
7f56eba8 2654 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
6595eee7 2655 XCAFDimTolObjects_DimensionModifiersSequence aModifiers = theObject->GetModifiers();
2656 Handle(Standard_Transient) aDim = theDimension.Value();
2657 Standard_Boolean isAngle = aDim->IsKind(STANDARD_TYPE(StepShape_AngularLocation)) ||
2658 aDim->IsKind(STANDARD_TYPE(StepShape_AngularSize));
2659
2660 // Unit
2661 StepBasic_Unit aUnit = GetUnit(theRC, isAngle);
2662 Standard_CString aMeasureName;
2663 if (isAngle)
2664 aMeasureName = "POSITIVE_PLANE_ANGLE_MEASURE";
2665 else
2666 aMeasureName = "POSITIVE_LENGTH_MEASURE";
2667
2668 // Values
2669 Handle(StepRepr_HArray1OfRepresentationItem) aValues;
7644c7f4 2670 Standard_Integer aNbItems = 1, aValIt = 1;
6595eee7 2671 if (theObject->IsDimWithRange())
7644c7f4 2672 aNbItems += 2;
6595eee7 2673 if (aModifiers.Length() > 0)
7644c7f4 2674 aNbItems++;
6595eee7 2675 if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented)
7644c7f4 2676 aNbItems++;
2677 aNbItems += theObject->NbDescriptions();
2678 aValues = new StepRepr_HArray1OfRepresentationItem(1, aNbItems);
6595eee7 2679
2680 // Nominal value
2681 Standard_Real aNominal = theObject->GetValue();
2682 Standard_Integer aLeftNbDigits, aRightNbDigits;
2683 theObject->GetNbOfDecimalPlaces(aLeftNbDigits, aRightNbDigits);
2684 Standard_Integer aNbQualifiers = 0;
2685 if (theObject->HasQualifier() && !isAngle)
2686 aNbQualifiers++;
2687 if (aLeftNbDigits > 0 || aRightNbDigits > 0)
2688 aNbQualifiers++;
2689 // With qualifiers
2690 if (aNbQualifiers > 0) {
2691 Handle(StepShape_QualifiedRepresentationItem) aQRI = new StepShape_QualifiedRepresentationItem();
2692 Handle(StepShape_HArray1OfValueQualifier) aQualifiers = new StepShape_HArray1OfValueQualifier(1, aNbQualifiers);
2693 // Type qualifier
2694 if (theObject->HasQualifier() && !isAngle) {
2695 StepShape_ValueQualifier anItem;
2696 Handle(StepShape_TypeQualifier) aType = new StepShape_TypeQualifier();
2697 XCAFDimTolObjects_DimensionQualifier aQualifier = theObject->GetQualifier();
727b5ad9 2698 aType->Init(STEPCAFControl_GDTProperty::GetDimQualifierName(aQualifier));
6595eee7 2699 aModel->AddWithRefs(aType);
2700 anItem.SetValue(aType);
2701 aQualifiers->SetValue(1, anItem);
2702 }
2703 // Number of decimal places
2704 if (aLeftNbDigits > 0 || aRightNbDigits > 0) {
2705 StepShape_ValueQualifier anItem;
2706 Handle(StepShape_ValueFormatTypeQualifier) aType = new StepShape_ValueFormatTypeQualifier();
2707 Handle(TCollection_HAsciiString) aFormatType = new TCollection_HAsciiString("NR2 ");
2708 aFormatType->AssignCat(new TCollection_HAsciiString(aLeftNbDigits));
2709 aFormatType->AssignCat(new TCollection_HAsciiString("."));
2710 aFormatType->AssignCat(new TCollection_HAsciiString(aRightNbDigits));
2711 aType->Init(aFormatType);
2712 aModel->AddWithRefs(aType);
2713 anItem.SetValue(aType);
2714 aQualifiers->SetValue(aNbQualifiers, anItem);
2715 }
2716 // Set qualifiers
2717 aQRI->SetQualifiers(aQualifiers);
2718 Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
2719 new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle, Standard_True, aQRI);
7644c7f4 2720 aValues->SetValue(aValIt, anItem);
2721 aValIt++;
6595eee7 2722 }
2723 // Without qualifiers
2724 else {
2725 Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
2726 new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle);
7644c7f4 2727 aValues->SetValue(aValIt, anItem);
2728 aValIt++;
6595eee7 2729 }
7644c7f4 2730
6595eee7 2731 // Ranges
2732 if (theObject->IsDimWithRange()) {
2733 Handle(StepRepr_ReprItemAndMeasureWithUnit) aLowerItem = CreateDimValue(theObject->GetLowerBound(), aUnit,
2734 new TCollection_HAsciiString("lower limit"), aMeasureName, isAngle);
2735 Handle(StepRepr_ReprItemAndMeasureWithUnit) anUpperItem = CreateDimValue(theObject->GetUpperBound(), aUnit,
2736 new TCollection_HAsciiString("upper limit"), aMeasureName, isAngle);
7644c7f4 2737 aValues->SetValue(aValIt, aLowerItem);
2738 aValIt++;
2739 aValues->SetValue(aValIt, anUpperItem);
2740 aValIt++;
6595eee7 2741 }
2742
2743 // Modifiers
2744 if (aModifiers.Length() > 0) {
2745 Handle(StepRepr_CompoundRepresentationItem) aCompoundRI = new StepRepr_CompoundRepresentationItem();
2746 Handle (StepRepr_HArray1OfRepresentationItem) aModifItems =
2747 new StepRepr_HArray1OfRepresentationItem(1, aModifiers.Length());
2748 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) {
2749 XCAFDimTolObjects_DimensionModif aModif = aModifiers.Value(i);
2750 Handle(StepRepr_DescriptiveRepresentationItem) aModifItem =
2751 new StepRepr_DescriptiveRepresentationItem();
727b5ad9 2752 aModifItem->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDimModifierName(aModif));
6595eee7 2753 aModel->AddWithRefs(aModifItem);
2754 aModifItems->SetValue(i, aModifItem);
2755 }
2756 aCompoundRI->Init(new TCollection_HAsciiString(), aModifItems);
7644c7f4 2757 aValues->SetValue(aValIt, aCompoundRI);
2758 aValIt++;
6595eee7 2759 }
2760
2761 // Orientation
2762 if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented) {
2763 Handle(StepGeom_Axis2Placement3d) anOrientation = new StepGeom_Axis2Placement3d();
2764 gp_Dir aDir;
2765 theObject->GetDirection(aDir);
b7b2f85a 2766 GeomToStep_MakeCartesianPoint MkPoint(gp_Pnt(0, 0, 0));
18f7c9a5 2767 Handle(StepGeom_CartesianPoint) aLoc = MkPoint.Value();
6595eee7 2768 Handle(StepGeom_Direction) anAxis = new StepGeom_Direction();
2769 Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
2770 aCoords->SetValue(1, aDir.X());
2771 aCoords->SetValue(2, aDir.Y());
2772 aCoords->SetValue(3, aDir.Z());
2773 anAxis->Init(new TCollection_HAsciiString(), aCoords);
2774 anOrientation->Init(new TCollection_HAsciiString("orientation"), aLoc, Standard_True, anAxis, Standard_False, NULL);
7644c7f4 2775 aValues->SetValue(aValIt, anOrientation);
2776 aValIt++;
2777 }
2778
2779 // Descriptions
2780 if (theObject->HasDescriptions()) {
2781 for (Standard_Integer i = 0; i < theObject->NbDescriptions(); i++) {
2782 Handle(StepRepr_DescriptiveRepresentationItem) aDRI = new StepRepr_DescriptiveRepresentationItem();
2783 aDRI->Init(theObject->GetDescriptionName(i), theObject->GetDescription(i));
2784 aValues->SetValue(aValIt, aDRI);
2785 aValIt++;
2786 }
6595eee7 2787 }
2788
2789 for (Standard_Integer i = 1; i <= aValues->Length(); i++)
2790 aModel->AddWithRefs(aValues->Value(i));
2791
2792 // Create resulting Shape_Dimension_Representation
2793 Handle(StepShape_ShapeDimensionRepresentation) aSDR = new StepShape_ShapeDimensionRepresentation();
2794 aSDR->Init(new TCollection_HAsciiString(), aValues, theRC);
2795 aModel->AddWithRefs(aSDR);
2796 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR = new StepShape_DimensionalCharacteristicRepresentation();
2797 aDCR->Init(theDimension, aSDR);
2798 aModel->AddWithRefs(aDCR);
2799
2800 // Plus_Minus_Tolerance
2801 if (theObject->IsDimWithPlusMinusTolerance()) {
2802 Handle(TCollection_HAsciiString) aDummyName = new TCollection_HAsciiString(aMeasureName);
2803 aDummyName = aDummyName->SubString(9, aDummyName->Length()); //delete "POSITIVE_"
2804 aMeasureName = aDummyName->ToCString();
2805 Standard_Real aLowerTolValue = -theObject->GetLowerTolValue(),
2806 anUpperTolValue = theObject->GetUpperTolValue();
2807 // Upper
2808 Handle(StepBasic_MeasureWithUnit) anUpperMWU = new StepBasic_MeasureWithUnit();
2809 Handle(StepBasic_MeasureValueMember) anUpperValue = new StepBasic_MeasureValueMember();
2810 anUpperValue->SetName(aMeasureName);
2811 anUpperValue->SetReal(anUpperTolValue);
2812 anUpperMWU->Init(anUpperValue, aUnit);
2813 aModel->AddWithRefs(anUpperMWU);
2814 // Lower
2815 Handle(StepBasic_MeasureWithUnit) aLowerMWU = new StepBasic_MeasureWithUnit();
2816 Handle(StepBasic_MeasureValueMember) aLowerValue = new StepBasic_MeasureValueMember();
2817 aLowerValue->SetName(aMeasureName);
2818 aLowerValue->SetReal(aLowerTolValue);
2819 aLowerMWU->Init(aLowerValue, aUnit);
2820 aModel->AddWithRefs(aLowerMWU);
2821 // Tolerance
2822 Handle(StepShape_ToleranceValue) aTolValue = new StepShape_ToleranceValue();
2823 aTolValue->Init(aLowerMWU, anUpperMWU);
2824 aModel->AddWithRefs(aTolValue);
2825 StepShape_ToleranceMethodDefinition aMethod;
2826 aMethod.SetValue(aTolValue);
2827 Handle(StepShape_PlusMinusTolerance) aPlusMinusTol = new StepShape_PlusMinusTolerance();
2828 aPlusMinusTol->Init(aMethod, theDimension);
2829 aModel->AddWithRefs(aPlusMinusTol);
2830 }
2831 // Tolerance class
2832 if (theObject->IsDimWithClassOfTolerance()) {
2833 Standard_Boolean isHole;
2834 XCAFDimTolObjects_DimensionFormVariance aFormVariance;
2835 XCAFDimTolObjects_DimensionGrade aGrade;
2836 if (!theObject->GetClassOfTolerance(isHole, aFormVariance, aGrade))
2837 return;
727b5ad9 2838 Handle(StepShape_LimitsAndFits) aLAF = STEPCAFControl_GDTProperty::GetLimitsAndFits(isHole, aFormVariance, aGrade);
6595eee7 2839 aModel->AddWithRefs(aLAF);
2840 StepShape_ToleranceMethodDefinition aMethod;
2841 aMethod.SetValue(aLAF);
2842 Handle(StepShape_PlusMinusTolerance) aPlusMinusTol = new StepShape_PlusMinusTolerance();
2843 aPlusMinusTol->Init(aMethod, theDimension);
2844 aModel->AddWithRefs(aPlusMinusTol);
2845 }
2846}
2847
b7b2f85a 2848//=======================================================================
2849//function : WriteDerivedGeometry
2850//purpose : auxiliary (write connection point for dimensions)
2851//======================================================================
2852static void WriteDerivedGeometry (const Handle(XSControl_WorkSession) &WS,
2853 const Handle(XCAFDimTolObjects_DimensionObject)& theObject,
2854 const Handle(StepRepr_ConstructiveGeometryRepresentation) theRepr,
2855 Handle(StepRepr_ShapeAspect)& theFirstSA,
2856 Handle(StepRepr_ShapeAspect)& theSecondSA,
2857 NCollection_Vector<Handle(StepGeom_CartesianPoint)>& thePnts)
2858{
2859 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
2860 // First point
2861 if (theObject->HasPoint()) {
2862 GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint());
2863 Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
2864 thePnts.Append(aPoint);
2865 Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
2866 aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse);
2867 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2868 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2869 aDefinition.SetValue(aDSA);
2870 Handle(StepRepr_HArray1OfRepresentationItem) anItem = new StepRepr_HArray1OfRepresentationItem(1, 1);
2871 anItem->SetValue(1, aPoint);
2872 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDefinition, theRepr, anItem);
2873 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = new StepRepr_ShapeAspectDerivingRelationship();
2874 aSADR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDSA, theFirstSA);
2875 theFirstSA = aDSA;
2876 aModel->AddWithRefs(aGISU);
2877 aModel->AddWithRefs(aSADR);
2878 }
2879
2880 // Second point (for locations)
2881 if (theObject->HasPoint2()) {
2882 GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint2());
2883 Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value();
2884 thePnts.Append(aPoint);
2885 Handle(StepRepr_DerivedShapeAspect) aDSA = new StepRepr_DerivedShapeAspect();
2886 aDSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), theFirstSA->OfShape(), StepData_LFalse);
2887 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
2888 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
2889 aDefinition.SetValue(aDSA);
2890 Handle(StepRepr_HArray1OfRepresentationItem) anItem = new StepRepr_HArray1OfRepresentationItem(1, 1);
2891 anItem->SetValue(1, aPoint);
2892 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDefinition, theRepr, anItem);
2893 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = new StepRepr_ShapeAspectDerivingRelationship();
2894 aSADR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDSA, theSecondSA);
2895 theSecondSA = aDSA;
2896 aModel->AddWithRefs(aGISU);
2897 aModel->AddWithRefs(aSADR);
2898 }
2899}
2900
6595eee7 2901//=======================================================================
2902//function : WriteDatumSystem
2903//purpose : auxiliary (write Write datum system for given
2904// geometric_tolerance)
2905//======================================================================
2906static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const Handle(XSControl_WorkSession) &WS,
2907 const TDF_Label theGeomTolL,
2908 const TDF_LabelSequence theDatumSeq,
2909 const STEPConstruct_DataMapOfAsciiStringTransient theDatumMap,
2910 const Handle(StepRepr_RepresentationContext)& theRC)
2911{
2912 // Get working data
7f56eba8 2913 const Handle(Interface_InterfaceModel) &Model = WS->Model();
6595eee7 2914 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
2915 if (aHGraph.IsNull())
2916 return NULL;
2917 Interface_Graph aGraph = aHGraph->Graph();
2918 Handle(XCAFDoc_GeomTolerance) aGTAttr;
2919 if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr))
2920 return NULL;
2921 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
2922 if (anObject.IsNull())
2923 return NULL;
2924
2925 // Unit
2926 StepBasic_Unit aUnit = GetUnit(theRC);
2927
2928 XCAFDimTolObjects_DatumObjectSequence aDatums;
2929 Standard_Integer aMaxDatumNum = 0;
2930 for (Standard_Integer i = 1; i <= theDatumSeq.Length(); i++) {
2931 Handle(XCAFDoc_Datum) aDatumAttr;
2932 if (!theDatumSeq.Value(i).FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
2933 continue;
2934 Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject();
2935 if (aDatumObj.IsNull())
2936 continue;
2937 aDatums.Append(aDatumObj);
2938 aMaxDatumNum = Max(aMaxDatumNum, aDatumObj->GetPosition());
2939 }
c1070321 2940 if (aMaxDatumNum == 0)
2941 return NULL;
6595eee7 2942
2943 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aConstituents =
2944 new StepDimTol_HArray1OfDatumReferenceCompartment(1, aMaxDatumNum);
2945 // Auxiliary datum to initialize attributes in Datum_System
2946 Handle(StepDimTol_Datum) aFirstDatum;
2947 Standard_Integer aConstituentsNum = 0;
2948 for (Standard_Integer i = 1; i <= aMaxDatumNum; i++) {
2949 // Collect datums with i-th position
2950 XCAFDimTolObjects_DatumObjectSequence aDatumSeqPos;
2951 for (Standard_Integer j = 1; j <= aDatums.Length(); j++)
2952 if (aDatums.Value(j)->GetPosition() == i)
2953 aDatumSeqPos.Append(aDatums.Value(j));
2954 if (aDatumSeqPos.Length() < 1)
2955 continue;
2956
2957 aConstituentsNum++;
2958 // Initialize Datum_Reference_Compartment
2959 StepDimTol_DatumOrCommonDatum aDatumRef;
2960 Handle(StepDimTol_DatumReferenceCompartment) aCompartment =
2961 new StepDimTol_DatumReferenceCompartment();
2962 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifiers;
2963 if (aDatumSeqPos.Length() == 1) {
2964 // Datum entity
aa00364d 2965 Handle(Standard_Transient) aFDValue;
f3ec3b37 2966 if (theDatumMap.Find(aDatumSeqPos.Value(1)->GetName()->String(), aFDValue) && !aFDValue.IsNull())
aa00364d 2967 aFirstDatum = Handle(StepDimTol_Datum)::DownCast (aFDValue);
6595eee7 2968 aDatumRef.SetValue(aFirstDatum);
2969 // Modifiers
2970 XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(1)->GetModifiers();
2971 XCAFDimTolObjects_DatumModifWithValue aModifWithVal;
2972 Standard_Real aValue = 0;
2973 aDatumSeqPos.Value(1)->GetModifierWithValue(aModifWithVal, aValue);
727b5ad9 2974 aModifiers = STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit);
6595eee7 2975 // Add Datum_Reference_Modifier_With_Value
2976 if (!aModifiers.IsNull()) {
2977 Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV =
2978 aModifiers->Value(aModifiers->Length()).DatumReferenceModifierWithValue();
2979 if (!aDRMWV.IsNull()) {
2980 Model->AddWithRefs(aDRMWV);
2981 }
2982 }
2983 }
2984 else {
2985 Handle(StepDimTol_HArray1OfDatumReferenceElement) aCommonDatumList = new StepDimTol_HArray1OfDatumReferenceElement(1, aDatumSeqPos.Length());
2986 for (Standard_Integer j = 1; j <= aDatumSeqPos.Length(); j++) {
2987 // Datum entity
2988 Handle(StepDimTol_Datum) aDatum;
aa00364d 2989 Handle(Standard_Transient) aDValue;
2990 if (theDatumMap.Find(aDatumSeqPos.Value(j)->GetName()->String(), aDValue))
2991 aDatum = Handle(StepDimTol_Datum)::DownCast (aDValue);
6595eee7 2992 StepDimTol_DatumOrCommonDatum anElemDatumRef;
2993 anElemDatumRef.SetValue(aDatum);
2994 if (aFirstDatum.IsNull())
2995 aFirstDatum = aDatum;
2996 // Modifiers
2997 XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(j)->GetModifiers();
2998 XCAFDimTolObjects_DatumModifWithValue aModifWithVal;
2999 Standard_Real aValue = 0;
3000 aDatumSeqPos.Value(j)->GetModifierWithValue(aModifWithVal, aValue);
3001 Handle(StepDimTol_HArray1OfDatumReferenceModifier) anElemModifiers =
727b5ad9 3002 STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit);
6595eee7 3003 // Add Datum_Reference_Modifier_With_Value
3004 if (!anElemModifiers.IsNull()) {
3005 Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV =
f3ec3b37 3006 anElemModifiers->Value(anElemModifiers->Length()).DatumReferenceModifierWithValue();
6595eee7 3007 if (!aDRMWV.IsNull()) {
3008 Model->AddWithRefs(aDRMWV);
3009 }
3010 }
3011 // Datum_Reference_Element
3012 Handle(StepDimTol_DatumReferenceElement) anElement = new StepDimTol_DatumReferenceElement();
3013 anElement->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDatum->OfShape(),
3014 aDatum->ProductDefinitional(), anElemDatumRef, !anElemModifiers.IsNull(), anElemModifiers);
3015 Model->AddWithRefs(anElement);
3016 aCommonDatumList->SetValue(j, anElement);
3017 }
3018 aDatumRef.SetValue(aCommonDatumList);
3019 }
3020 aCompartment->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(),
3021 aFirstDatum->ProductDefinitional(), aDatumRef, !aModifiers.IsNull(), aModifiers);
3022 Model->AddWithRefs(aCompartment);
3023 aConstituents->SetValue(aConstituentsNum, aCompartment);
3024 }
3025 // Remove null elements from aConstituents
3026 Standard_Integer aNbConstituents = 0;
3027 for (Standard_Integer i = 1; i <= aConstituents->Length(); i++)
3028 if (!aConstituents->Value(i).IsNull())
3029 aNbConstituents++;
3030 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aResConstituents =
3031 new StepDimTol_HArray1OfDatumReferenceCompartment(1, aNbConstituents);
3032 Standard_Integer aConstituentsIt = 0;
3033 for (Standard_Integer i = 1; i <= aConstituents->Length(); i++)
3034 if (!aConstituents->Value(i).IsNull()) {
3035 aConstituentsIt++;
3036 aResConstituents->SetValue(aConstituentsIt, aConstituents->Value(i));
3037 }
3038
3039 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
3040 Handle(StepDimTol_DatumSystem) aDS = new StepDimTol_DatumSystem();
3041 aDS->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(),
3042 aFirstDatum->ProductDefinitional(), aResConstituents);
3043 Model->AddWithRefs(aDS);
3044 StepDimTol_DatumSystemOrReference anArrayValue;
3045 anArrayValue.SetValue(aDS);
3046 aDatumSystem = new StepDimTol_HArray1OfDatumSystemOrReference(1, 1);
3047 aDatumSystem->SetValue(1, anArrayValue);
3048
3049 // Axis
3050 if (anObject->HasAxis()) {
3051 Handle(StepGeom_Axis2Placement3d) anAxis =
727b5ad9 3052 STEPCAFControl_GDTProperty::GetAxis2Placement3D(anObject->GetAxis());
b0cef606 3053 anAxis->SetName(new TCollection_HAsciiString("orientation"));
6595eee7 3054 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = new StepAP242_GeometricItemSpecificUsage();
3055 StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition;
3056 aDefinition.SetValue(aDS);
3057 Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1);
a9dde4a3 3058 Handle(StepRepr_RepresentationItem) anIdentifiedItem = anAxis;
6595eee7 3059 anReprItems->SetValue(1, anIdentifiedItem);
3060 Interface_EntityIterator subs = aGraph.Sharings(aFirstDatum->OfShape());
3061 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
3062 for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) {
3063 Handle(Standard_Transient) anEntity = subs.Value();
3064 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity);
3065 }
3066 if (aSDR.IsNull())
3067 return aDatumSystem;
3068
3069 aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(),
3070 aDefinition, aSDR->UsedRepresentation(), anReprItems);
3071 Model->AddWithRefs(anAxis);
3072 Model->AddWithRefs(aGISU);
3073 }
3074
3075 return aDatumSystem;
3076}
3077
3078//=======================================================================
3079//function : WriteToleranceZone
3080//purpose : auxiliary (write tolerace zones)
3081//=======================================================================
3082static void WriteToleranceZone (const Handle(XSControl_WorkSession) &WS,
3083 const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject,
3084 const Handle(StepDimTol_GeometricTolerance)& theEntity,
3085 const Handle(StepRepr_RepresentationContext)& theRC)
3086{
3087 // Get working data
7f56eba8 3088 const Handle(Interface_InterfaceModel) &Model = WS->Model();
6595eee7 3089 if (theEntity.IsNull() || theObject.IsNull())
3090 return;
3091
3092 // Return if there is no tolerance zones
3093 if (theObject->GetTypeOfValue() == XCAFDimTolObjects_GeomToleranceTypeValue_None &&
3094 theObject->GetZoneModifier() != XCAFDimTolObjects_GeomToleranceZoneModif_Runout)
3095 return;
3096
3097 // Create Tolerance_Zone
3098 Handle(StepDimTol_ToleranceZoneForm) aForm = new StepDimTol_ToleranceZoneForm();
3099 Model->AddWithRefs(aForm);
727b5ad9 3100 aForm->Init(STEPCAFControl_GDTProperty::GetTolValueType(theObject->GetTypeOfValue()));
6595eee7 3101 Handle(StepDimTol_HArray1OfToleranceZoneTarget) aZoneTargetArray = new StepDimTol_HArray1OfToleranceZoneTarget(1, 1);
3102 StepDimTol_ToleranceZoneTarget aTarget;
3103 aTarget.SetValue(theEntity);
3104 aZoneTargetArray->SetValue(1, aTarget);
3105 Handle(StepDimTol_ToleranceZone) aZone = new StepDimTol_ToleranceZone();
3106 aZone->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(),
3107 theEntity->TolerancedShapeAspect().ShapeAspect()->OfShape(), StepData_LFalse,
3108 aZoneTargetArray, aForm);
3109 Model->AddWithRefs(aZone);
3110
3111 // Runout_Tolerance_Zone
3112 Handle(StepBasic_PlaneAngleMeasureWithUnit) aPAMWU = new StepBasic_PlaneAngleMeasureWithUnit();
3113 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
3114 aValueMember->SetName("PLANE_ANGLE_MEASURE");
3115 aValueMember->SetReal(theObject->GetValueOfZoneModifier());
3116 aPAMWU->Init(aValueMember, GetUnit(theRC, Standard_True));
3117 Handle(StepDimTol_RunoutZoneOrientation) anOrientation = new StepDimTol_RunoutZoneOrientation();
3118 anOrientation->Init(aPAMWU);
3119 Handle(StepDimTol_RunoutZoneDefinition) aDefinition = new StepDimTol_RunoutZoneDefinition();
3120 aDefinition->Init(aZone, NULL, anOrientation);
3121 Model->AddWithRefs(aDefinition);
3122 Model->AddWithRefs(anOrientation);
3123 Model->AddWithRefs(aPAMWU);
3124}
3125
3126//=======================================================================
3127//function : WriteGeomTolerance
3128//purpose : auxiliary (write Geometric_Tolerance entity for given shapes,
3129// label and datum system)
3130//======================================================================
3131static void WriteGeomTolerance (const Handle(XSControl_WorkSession) &WS,
3132 const TDF_LabelSequence theShapeSeqL,
3133 const TDF_Label theGeomTolL,
3134 const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem,
3135 const Handle(StepRepr_RepresentationContext)& theRC)
3136{
3137 // Get working data
7f56eba8 3138 const Handle(Interface_InterfaceModel) &Model = WS->Model();
6595eee7 3139 Handle(XCAFDoc_GeomTolerance) aGTAttr;
3140 if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr))
3141 return;
3142 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
3143 if (anObject.IsNull())
3144 return;
3145
3146 // Value
3147 Handle(StepBasic_LengthMeasureWithUnit) aLMWU = new StepBasic_LengthMeasureWithUnit();
3148 StepBasic_Unit aUnit = GetUnit(theRC);
3149 Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember();
3150 aValueMember->SetName("LENGTH_MEASURE");
3151 aValueMember->SetReal(anObject->GetValue());
3152 aLMWU->Init(aValueMember, aUnit);
3153 Model->AddWithRefs(aLMWU);
3154
3155 // Geometric_Tolerance target
3156 Handle(StepRepr_ShapeAspect) aMainSA;
3157 Handle(StepRepr_RepresentationContext) dummyRC;
3158 Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
3159 if (theShapeSeqL.Length() == 1) {
3160 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(1));
3161 aMainSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU);
3162 Model->AddWithRefs(aMainSA);
3163 }
3164 else {
3165 Handle(StepRepr_CompositeShapeAspect) aCSA;
3166 for (Standard_Integer i = 1; i <= theShapeSeqL.Length(); i++) {
3167 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(i));
3168 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU);
3169 if (aSA.IsNull())
3170 continue;
3171 if (aCSA.IsNull()) {
3172 aCSA = new StepRepr_CompositeShapeAspect();
3173 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3174 Model->AddWithRefs(aCSA);
3175 }
3176 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3177 aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCSA, aSA);
3178 Model->AddWithRefs(aSAR);
3179 }
3180 aMainSA = aCSA;
3181 }
3182 StepDimTol_GeometricToleranceTarget aGTTarget;
3183 aGTTarget.SetValue(aMainSA);
3184
3185 Standard_Boolean isWithModif = Standard_False,
3186 isWithDatRef = Standard_False,
3187 isWithMaxTol = Standard_False;
3188 // Modifiers
3189 // Simple modifiers
3190 XCAFDimTolObjects_GeomToleranceModifiersSequence aModifiers = anObject->GetModifiers();
3191 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifArray;
3192 Handle(StepBasic_LengthMeasureWithUnit) aMaxLMWU;
3193 Standard_Integer aModifNb = aModifiers.Length();
3194 if (anObject->GetMaterialRequirementModifier() != XCAFDimTolObjects_GeomToleranceMatReqModif_None)
3195 aModifNb++;
3196 for (Standard_Integer i = 1; i < aModifiers.Length(); i++)
3197 if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around ||
3198 aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over)
3199 aModifNb--;
3200 if (aModifNb > 0) {
3201 isWithModif = Standard_True;
3202 aModifArray = new StepDimTol_HArray1OfGeometricToleranceModifier(1, aModifNb);
3203 Standard_Integer k = 1;
3204 for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) {
3205 if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around ||
3206 aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over)
3207 continue;
3208 StepDimTol_GeometricToleranceModifier aModif =
727b5ad9 3209 STEPCAFControl_GDTProperty::GetGeomToleranceModifier(aModifiers.Value(i));
6595eee7 3210 aModifArray->SetValue(k, aModif);
3211 k++;
3212 }
3213 if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_L) {
3214 aModifArray->SetValue(aModifNb, StepDimTol_GTMLeastMaterialRequirement);
3215 }
3216 else if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_M) {
3217 aModifArray->SetValue(aModifNb, StepDimTol_GTMMaximumMaterialRequirement);
3218 }
3219 // Modifier with value
3220 if (anObject->GetMaxValueModifier() != 0) {
3221 isWithMaxTol = Standard_True;
3222 aMaxLMWU = new StepBasic_LengthMeasureWithUnit();
c7854818 3223 Handle(StepBasic_MeasureValueMember) aModifierValueMember = new StepBasic_MeasureValueMember();
3224 aModifierValueMember->SetName("LENGTH_MEASURE");
3225 aModifierValueMember->SetReal(anObject->GetMaxValueModifier());
3226 aMaxLMWU->Init(aModifierValueMember, aUnit);
6595eee7 3227 Model->AddWithRefs(aMaxLMWU);
3228 }
3229 }
3230
3231 // Datum Reference
3232 isWithDatRef = !theDatumSystem.IsNull();
3233
3234 // Collect all attributes
3235 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(),
3236 aDescription = new TCollection_HAsciiString();
3237 Handle(StepDimTol_GeometricToleranceWithDatumReference) aGTWDR =
3238 new StepDimTol_GeometricToleranceWithDatumReference();
3239 aGTWDR->SetDatumSystem(theDatumSystem);
3240 Handle(StepDimTol_GeometricToleranceWithModifiers) aGTWM =
3241 new StepDimTol_GeometricToleranceWithModifiers();
3242 aGTWM->SetModifiers(aModifArray);
3243 StepDimTol_GeometricToleranceType aType =
727b5ad9 3244 STEPCAFControl_GDTProperty::GetGeomToleranceType(anObject->GetType());
6595eee7 3245
3246 // Init and write necessary subtype of Geometric_Tolerance entity
3247 Handle(StepDimTol_GeometricTolerance) aGeomTol;
3248 if (isWithModif) {
3249 if (isWithMaxTol) {
3250 if (isWithDatRef) {
3251 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference &
3252 //Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers
3253 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aResult =
3254 new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol();
3255 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aMaxLMWU, aType);
3256 aGeomTol = aResult;
3257 }
3258 else {
3259 // Geometric_Tolerance & Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers
3260 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aResult =
3261 new StepDimTol_GeoTolAndGeoTolWthMaxTol();
3262 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWM, aMaxLMWU, aType);
3263 aGeomTol = aResult;
3264 }
3265 }
3266 else {
3267 if (isWithDatRef) {
3268 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference & Geometric_Tolerance_With_Modifiers
3269 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) aResult =
3270 new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod();
3271 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aType);
3272 aGeomTol = aResult;
3273 }
3274 else {
3275 // Geometric_Tolerance & Geometric_Tolerance_With_Modifiers
3276 Handle(StepDimTol_GeoTolAndGeoTolWthMod) aResult =
3277 new StepDimTol_GeoTolAndGeoTolWthMod();
3278 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWM, aType);
3279 aGeomTol = aResult;
3280 }
3281 }
3282 }
3283 else {
3284 if (isWithDatRef) {
3285 // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference
3286 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) aResult =
3287 new StepDimTol_GeoTolAndGeoTolWthDatRef();
3288 aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aType);
3289 aGeomTol = aResult;
3290 }
3291 else {
3292 // Geometric_Tolerance
3293 Handle(StepDimTol_GeometricTolerance) aResult =
727b5ad9 3294 STEPCAFControl_GDTProperty::GetGeomTolerance(anObject->GetType());
6595eee7 3295 if (!aResult.IsNull()) {
3296 aResult->Init(aName, aDescription, aLMWU, aGTTarget);
3297 aGeomTol = aResult;
3298 }
3299 }
3300 }
3301 Model->AddWithRefs(aGeomTol);
3302 WriteToleranceZone(WS, anObject, aGeomTol, theRC);
b0cef606 3303 //Annotation plane and Presentation
0b622d67 3304 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->GetPlane(), anObject->GetPointTextAttach(), aGeomTol);
6595eee7 3305}
7fd59977 3306
3307//=======================================================================
3308//function : WriteDGTs
3309//purpose :
3310//=======================================================================
7fd59977 3311Standard_Boolean STEPCAFControl_Writer::WriteDGTs (const Handle(XSControl_WorkSession) &WS,
3312 const TDF_LabelSequence &labels ) const
3313{
3314
3315 if ( labels.Length() <=0 ) return Standard_False;
6595eee7 3316
7fd59977 3317 // get working data
7f56eba8 3318 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3319 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
3320 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
9e20ed57 3321
3322 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3323 if(aHGraph.IsNull())
3324 return Standard_False;
3325
3326 Interface_Graph aGraph = aHGraph->Graph();
7fd59977 3327 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( labels(1) );
3328 if(DGTTool.IsNull() ) return Standard_False;
3329
3330 TDF_LabelSequence DGTLabels;
6595eee7 3331
7fd59977 3332 STEPConstruct_DataMapOfAsciiStringTransient DatumMap;
3333
3334 // write Datums
6595eee7 3335 DGTLabels.Clear();
7fd59977 3336 DGTTool->GetDatumLabels(DGTLabels);
3337 if(DGTLabels.Length()<=0) return Standard_False;
3338 Standard_Integer i;
3339 for(i=1; i<=DGTLabels.Length(); i++) {
3340 TDF_Label DatumL = DGTLabels.Value(i);
9ebaae37 3341 TDF_LabelSequence ShapeL;
1c9d3225 3342 TDF_LabelSequence aNullSeq;
3343 if(!DGTTool->GetRefShapeLabel(DatumL,ShapeL,aNullSeq)) continue;
7fd59977 3344 // find target shape
9ebaae37 3345 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
7fd59977 3346 TopLoc_Location Loc;
3347 TColStd_SequenceOfTransient seqRI;
3348 FindEntities( FP, aShape, Loc, seqRI );
3349 if ( seqRI.Length() <= 0 ) {
3350 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
3351 continue;
3352 }
3353 Handle(StepRepr_ProductDefinitionShape) PDS;
3354 Handle(StepRepr_RepresentationContext) RC;
3355 Handle(Standard_Transient) ent = seqRI.Value(1);
3356 Handle(StepShape_AdvancedFace) AF;
3357 Handle(StepShape_EdgeCurve) EC;
3358 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
3359 if(PDS.IsNull()) continue;
3360 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
3361 Handle(XCAFDoc_Datum) DatumAttr;
3362 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
3363 Handle(TCollection_HAsciiString) aName = DatumAttr->GetName();
3364 Handle(TCollection_HAsciiString) aDescription = DatumAttr->GetDescription();
3365 Handle(TCollection_HAsciiString) anIdentification = DatumAttr->GetIdentification();
3366 Handle(StepDimTol_DatumFeature) DF = new StepDimTol_DatumFeature;
3367 Handle(StepDimTol_Datum) aDatum = new StepDimTol_Datum;
3368 DF->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
3369 Model->AddWithRefs(DF);
3370 aDatum->Init(aName, new TCollection_HAsciiString, PDS, StepData_LFalse, anIdentification);
3371 Model->AddWithRefs(aDatum);
3372 Handle(StepRepr_ShapeAspectRelationship) SAR = new StepRepr_ShapeAspectRelationship;
3373 SAR->SetName(aName);
3374 SAR->SetRelatingShapeAspect(DF);
3375 SAR->SetRelatedShapeAspect(aDatum);
3376 Model->AddWithRefs(SAR);
3377 // write chain for DatumFeature
3378 StepRepr_CharacterizedDefinition CD;
3379 CD.SetValue(DF);
3380 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
3381 PropD->Init(aName,Standard_True,aDescription,CD);
3382 Model->AddWithRefs(PropD);
3383 StepRepr_RepresentedDefinition RD;
3384 RD.SetValue(PropD);
3385 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
3386 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
3387 new StepRepr_HArray1OfRepresentationItem(1,1);
3388 HARI->SetValue(1,AF);
3389 SR->Init(aName,HARI,RC);
3390 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
3391 SDR->Init(RD,SR);
3392 Model->AddWithRefs(SDR);
3393 // write chain for Datum
3394 StepRepr_CharacterizedDefinition CD1;
3395 CD1.SetValue(aDatum);
3396 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
3397 PropD1->Init(aName,Standard_True,aDescription,CD1);
3398 Model->AddWithRefs(PropD1);
3399 StepRepr_RepresentedDefinition RD1;
3400 RD1.SetValue(PropD1);
3401 Handle(StepShape_ShapeRepresentation) SR1 = new StepShape_ShapeRepresentation;
3402 Handle(StepRepr_HArray1OfRepresentationItem) HARI1 =
3403 new StepRepr_HArray1OfRepresentationItem(1,1);
3404 HARI1->SetValue(1,AF->FaceGeometry());
3405 SR1->Init(aName,HARI1,RC);
3406 Model->AddWithRefs(SR1);
3407 Handle(StepShape_ShapeDefinitionRepresentation) SDR1 = new StepShape_ShapeDefinitionRepresentation;
3408 SDR1->Init(RD1,SR1);
3409 Model->AddWithRefs(SDR1);
3410 // add created Datum into Map
3411 TCollection_AsciiString stmp(aName->ToCString());
3412 stmp.AssignCat(aDescription->ToCString());
3413 stmp.AssignCat(anIdentification->ToCString());
3414 DatumMap.Bind(stmp,aDatum);
3415 }
3416
3417 // write Tolerances and Dimensions
3418 DGTLabels.Clear();
3419 DGTTool->GetDimTolLabels(DGTLabels);
3420 if(DGTLabels.Length()<=0) return Standard_False;
3421 for(i=1; i<=DGTLabels.Length(); i++) {
3422 TDF_Label DimTolL = DGTLabels.Value(i);
9ebaae37 3423 TDF_LabelSequence ShapeL;
1c9d3225 3424 TDF_LabelSequence aNullSeq;
3425 if(!DGTTool->GetRefShapeLabel(DimTolL,ShapeL,aNullSeq)) continue;
7fd59977 3426 // find target shape
9ebaae37 3427 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1));
7fd59977 3428 TopLoc_Location Loc;
3429 TColStd_SequenceOfTransient seqRI;
3430 FindEntities( FP, aShape, Loc, seqRI );
3431 if ( seqRI.Length() <= 0 ) {
3432 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
3433 continue;
3434 }
3435 Handle(StepRepr_ProductDefinitionShape) PDS;
3436 Handle(StepRepr_RepresentationContext) RC;
3437 Handle(Standard_Transient) ent = seqRI.Value(1);
3438 Handle(StepShape_AdvancedFace) AF;
3439 Handle(StepShape_EdgeCurve) EC;
3440 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
3441 if(PDS.IsNull()) continue;
3442 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
3443
3444 Handle(XCAFDoc_DimTol) DimTolAttr;
3445 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) continue;
3446 Standard_Integer kind = DimTolAttr->GetKind();
3447 Handle(TColStd_HArray1OfReal) aVal = DimTolAttr->GetVal();
3448 Handle(TCollection_HAsciiString) aName = DimTolAttr->GetName();
3449 Handle(TCollection_HAsciiString) aDescription = DimTolAttr->GetDescription();
3450
3451 // common part of writing D&GT entities
3452 StepRepr_CharacterizedDefinition CD;
3453 Handle(StepRepr_ShapeAspect) SA = new StepRepr_ShapeAspect;
3454 SA->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
3455 Model->AddWithRefs(SA);
3456 CD.SetValue(SA);
3457 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
3458 PropD->Init(aName,Standard_True,aDescription,CD);
3459 Model->AddWithRefs(PropD);
3460 StepRepr_RepresentedDefinition RD;
3461 RD.SetValue(PropD);
3462 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
3463 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
3464 new StepRepr_HArray1OfRepresentationItem(1,1);
3465 if(kind<20)
3466 HARI->SetValue(1,EC);
3467 else
3468 HARI->SetValue(1,AF);
3469 SR->Init(aName,HARI,RC);
3470 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
3471 SDR->Init(RD,SR);
3472 Model->AddWithRefs(SDR);
3473 // define aUnit for creation LengthMeasureWithUnit (common for all)
3474 StepBasic_Unit aUnit;
3475 Handle(StepBasic_SiUnitAndLengthUnit) SLU;
3476 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) Ctx =
3477 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(RC);
3478 if(!Ctx.IsNull()) {
3479 for(Standard_Integer j=1; j<=Ctx->NbUnits(); j++) {
3480 if(Ctx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
3481 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx->UnitsValue(j));
3482 break;
3483 }
3484 }
3485 }
3486 if(SLU.IsNull()) {
3487 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) Ctx1 =
3488 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(RC);
3489 if(!Ctx1.IsNull()) {
3490 for(Standard_Integer j=1; j<=Ctx1->NbUnits(); j++) {
3491 if(Ctx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
3492 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx1->UnitsValue(j));
3493 break;
3494 }
3495 }
3496 }
3497 }
3498 if(SLU.IsNull()) {
3499 SLU = new StepBasic_SiUnitAndLengthUnit;
3500 }
3501 aUnit.SetValue(SLU);
3502
3503 // specific part of writing D&GT entities
3504 if(kind<20) { //dimension
3505 Handle(StepShape_DimensionalSize) DimSize = new StepShape_DimensionalSize;
3506 DimSize->Init(SA,aDescription);
3507 Model->AddWithRefs(DimSize);
3508 if(aVal->Length()>1) {
3509 // create MeasureWithUnits
3510 Handle(StepBasic_MeasureValueMember) MVM1 = new StepBasic_MeasureValueMember;
3511 MVM1->SetName("POSITIVE_LENGTH_MEASURE");
3512 MVM1->SetReal(aVal->Value(1));
3513 Handle(StepBasic_MeasureWithUnit) MWU1 = new StepBasic_MeasureWithUnit;
3514 MWU1->Init(MVM1,aUnit);
3515 Handle(StepBasic_MeasureValueMember) MVM2 = new StepBasic_MeasureValueMember;
3516 MVM2->SetName("POSITIVE_LENGTH_MEASURE");
3517 MVM2->SetReal(aVal->Value(2));
3518 Handle(StepBasic_MeasureWithUnit) MWU2 = new StepBasic_MeasureWithUnit;
3519 MWU2->Init(MVM2,aUnit);
3520 Handle(StepRepr_RepresentationItem) RI1 = new StepRepr_RepresentationItem;
3521 RI1->Init(new TCollection_HAsciiString("lower limit"));
3522 Handle(StepRepr_RepresentationItem) RI2 = new StepRepr_RepresentationItem;
3523 RI2->Init(new TCollection_HAsciiString("upper limit"));
3524 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU1 =
3525 new StepRepr_ReprItemAndLengthMeasureWithUnit;
3526 RILMU1->Init(MWU1,RI1);
3527 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU2 =
3528 new StepRepr_ReprItemAndLengthMeasureWithUnit;
3529 RILMU2->Init(MWU2,RI2);
3530 Model->AddWithRefs(RILMU1);
3531 Model->AddWithRefs(RILMU2);
3532 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
3533 // new StepRepr_CompoundItemDefinitionMember;
3534 //Handle(TColStd_HArray1OfTransient) ArrTr = new TColStd_HArray1OfTransient(1,2);
3535 //ArrTr->SetValue(1,RILMU1);
3536 //ArrTr->SetValue(2,RILMU2);
3537 //CIDM->SetArrTransient(ArrTr);
3538 //CIDM->SetName("SET_REPRESENTATION_ITEM");
3539 //StepRepr_CompoundItemDefinition CID;
3540 //CID.SetValue(CIDM);
3541 Handle(StepRepr_HArray1OfRepresentationItem) HARIVR =
3542 new StepRepr_HArray1OfRepresentationItem(1,2);
3543 HARIVR->SetValue(1,RILMU1);
3544 HARIVR->SetValue(2,RILMU2);
3545 Handle(StepRepr_ValueRange) VR = new StepRepr_ValueRange;
3546 //VR->Init(aName,CID);
3547 VR->Init(aName,HARIVR);
3548 Model->AddEntity(VR);
3549 Handle(StepShape_ShapeDimensionRepresentation) SDimR =
3550 new StepShape_ShapeDimensionRepresentation;
51740958 3551 Handle(StepRepr_HArray1OfRepresentationItem) aHARI =
7fd59977 3552 new StepRepr_HArray1OfRepresentationItem(1,1);
51740958 3553 aHARI->SetValue(1,VR);
3554 SDimR->Init(aName,aHARI,RC);
7fd59977 3555 Model->AddWithRefs(SDimR);
3556 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
3557 new StepShape_DimensionalCharacteristicRepresentation;
3558 StepShape_DimensionalCharacteristic DimChar;
3559 DimChar.SetValue(DimSize);
3560 DimCharR->Init(DimChar,SDimR);
3561 Model->AddEntity(DimCharR);
3562 }
3563 }
3564 else if(kind<50) { //tolerance
3565 if(kind<35) { // tolerance with datum system
3566 TDF_LabelSequence DatumLabels;
9ebaae37 3567 DGTTool->GetDatumOfTolerLabels(DimTolL,DatumLabels);
7fd59977 3568 Standard_Integer NbDR = DatumLabels.Length();
3569 Handle(StepDimTol_HArray1OfDatumReference) HADR = new StepDimTol_HArray1OfDatumReference(1,NbDR);
3570 for(Standard_Integer j=1; j<=NbDR; j++) {
3571 Handle(XCAFDoc_Datum) DatumAttr;
3572 TDF_Label DatumL = DatumLabels.Value(j);
3573 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
3574 Handle(TCollection_HAsciiString) aNameD = DatumAttr->GetName();
3575 Handle(TCollection_HAsciiString) aDescriptionD = DatumAttr->GetDescription();
3576 Handle(TCollection_HAsciiString) anIdentificationD = DatumAttr->GetIdentification();
3577 TCollection_AsciiString stmp(aNameD->ToCString());
3578 stmp.AssignCat(aDescriptionD->ToCString());
3579 stmp.AssignCat(anIdentificationD->ToCString());
3580 if(DatumMap.IsBound(stmp)) {
3581 Handle(StepDimTol_Datum) aDatum =
3582 Handle(StepDimTol_Datum)::DownCast(DatumMap.Find(stmp));
3583 Handle(StepDimTol_DatumReference) DR = new StepDimTol_DatumReference;
3584 DR->Init(j,aDatum);
3585 Model->AddWithRefs(DR);
3586 HADR->SetValue(j,DR);
3587 }
3588 }
3589 // create LengthMeasureWithUnit
3590 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
3591 MVM->SetName("LENGTH_MEASURE");
3592 MVM->SetReal(aVal->Value(1));
3593 Handle(StepBasic_LengthMeasureWithUnit) LMWU = new StepBasic_LengthMeasureWithUnit;
3594 LMWU->Init(MVM,aUnit);
3595 // create tolerance by it's type
3596 if(kind<24) {
3597 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
3598 new StepDimTol_GeometricToleranceWithDatumReference;
3599 GTWDR->SetDatumSystem(HADR);
3600 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
3601 new StepDimTol_ModifiedGeometricTolerance;
3602 if(kind==21) MGT->SetModifier(StepDimTol_MaximumMaterialCondition);
3603 else if(kind==22) MGT->SetModifier(StepDimTol_LeastMaterialCondition);
3604 else if(kind==23) MGT->SetModifier(StepDimTol_RegardlessOfFeatureSize);
3605 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
3606 new StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol;
3607 GTComplex->Init(aName,aDescription,LMWU,SA,GTWDR,MGT);
3608 Model->AddWithRefs(GTComplex);
3609 }
3610 else if(kind==24) {
3611 Handle(StepDimTol_AngularityTolerance) aToler =
3612 new StepDimTol_AngularityTolerance;
3613 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3614 Model->AddWithRefs(aToler);
3615 }
3616 else if(kind==25) {
3617 Handle(StepDimTol_CircularRunoutTolerance) aToler =
3618 new StepDimTol_CircularRunoutTolerance;
3619 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3620 Model->AddWithRefs(aToler);
3621 }
3622 else if(kind==26) {
3623 Handle(StepDimTol_CoaxialityTolerance) aToler =
3624 new StepDimTol_CoaxialityTolerance;
3625 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3626 Model->AddWithRefs(aToler);
3627 }
3628 else if(kind==27) {
3629 Handle(StepDimTol_ConcentricityTolerance) aToler =
3630 new StepDimTol_ConcentricityTolerance;
3631 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3632 Model->AddWithRefs(aToler);
3633 }
3634 else if(kind==28) {
3635 Handle(StepDimTol_ParallelismTolerance) aToler =
3636 new StepDimTol_ParallelismTolerance;
3637 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3638 Model->AddWithRefs(aToler);
3639 }
3640 else if(kind==29) {
3641 Handle(StepDimTol_PerpendicularityTolerance) aToler =
3642 new StepDimTol_PerpendicularityTolerance;
3643 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3644 Model->AddWithRefs(aToler);
3645 }
3646 else if(kind==30) {
3647 Handle(StepDimTol_SymmetryTolerance) aToler =
3648 new StepDimTol_SymmetryTolerance;
3649 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3650 Model->AddWithRefs(aToler);
3651 }
3652 else if(kind==31) {
3653 Handle(StepDimTol_TotalRunoutTolerance) aToler =
3654 new StepDimTol_TotalRunoutTolerance;
3655 aToler->Init(aName,aDescription,LMWU,SA,HADR);
3656 Model->AddWithRefs(aToler);
3657 }
3658 }
3659 }
3660 }
3661
3662 return Standard_True;
3663}
3664
6595eee7 3665//=======================================================================
3666//function : WriteDGTsAP242
3667//purpose :
3668//=======================================================================
3669
3670Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_WorkSession) &WS,
3671 const TDF_LabelSequence &labels ) const
3672{
3673 // Get working data
7f56eba8 3674 const Handle(Interface_InterfaceModel) &aModel = WS->Model();
6595eee7 3675
3676 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3677 if(aHGraph.IsNull())
3678 return Standard_False;
3679
3680 Interface_Graph aGraph = aHGraph->Graph();
3681 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool(labels(1));
3682 if(DGTTool.IsNull())
3683 return Standard_False;
3684
b0cef606 3685 // Common entities for presentation
3686 gdtPresentationDM = new StepVisual_DraughtingModel();
3687 STEPConstruct_Styles aStyles (WS);
3688 Handle(StepVisual_Colour) aCurvColor = aStyles.EncodeColor(Quantity_NOC_WHITE);
3689 Handle(StepRepr_RepresentationItem) anItem = NULL;
3690 gdtPrsCurveStyle = new StepVisual_HArray1OfPresentationStyleAssignment(1, 1);
3691 gdtPrsCurveStyle->SetValue(1, aStyles.MakeColorPSA(anItem, aCurvColor, aCurvColor));
3692
6595eee7 3693 TDF_LabelSequence aDGTLabels;
3694 STEPConstruct_DataMapOfAsciiStringTransient aDatumMap;
3695 Handle(StepRepr_RepresentationContext) aRC;
3696
3697 //------------- //
3698 // write Datums //
3699 //--------------//
3700 DGTTool->GetDatumLabels(aDGTLabels);
3701 // Find all shapes with datums
3702 TColStd_MapOfAsciiString aNameIdMap;
3703 for(Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3704 TDF_Label aDatumL = aDGTLabels.Value(i);
3705 TDF_LabelSequence aShapeL;
3706 TDF_LabelSequence aNullSeq;
3707 if(!DGTTool->GetRefShapeLabel(aDatumL, aShapeL, aNullSeq))
3708 continue;
3709 Handle(XCAFDoc_Datum) aDatumAttr;
3710 aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr);
3711 Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject();
3712 TCollection_AsciiString aDatumName = anObject->GetName()->String();
3713 TCollection_AsciiString aDatumTargetId = TCollection_AsciiString(anObject->GetDatumTargetNumber());
3714 if (!aNameIdMap.Add(aDatumName.Cat(aDatumTargetId)))
3715 continue;
aa00364d 3716 Handle(Standard_Transient) aWrittenDatum;
6595eee7 3717 Standard_Boolean isFirstDT = !aDatumMap.Find(aDatumName, aWrittenDatum);
aa00364d 3718 Handle(StepDimTol_Datum) aDatum = WriteDatumAP242(WS, aShapeL.First(), aDatumL, isFirstDT,
3719 Handle(StepDimTol_Datum)::DownCast (aWrittenDatum));
6595eee7 3720 // Add created Datum into Map
3721 aDatumMap.Bind(aDatumName, aDatum);
3722 }
3723
3724 //----------------- //
3725 // write Dimensions //
3726 //------------------//
3727 aDGTLabels.Clear();
3728 DGTTool->GetDimensionLabels(aDGTLabels);
b7b2f85a 3729 // Auxiliary entities for derived geometry
3730 Handle(StepRepr_ConstructiveGeometryRepresentation) aCGRepr =
3731 new StepRepr_ConstructiveGeometryRepresentation();
3732 Handle(StepRepr_ConstructiveGeometryRepresentationRelationship) aCGReprRel =
3733 new StepRepr_ConstructiveGeometryRepresentationRelationship();
3734 NCollection_Vector<Handle(StepGeom_CartesianPoint)> aConnectionPnts;
3735 Handle(StepRepr_RepresentationContext) dummyRC;
3736 Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU;
6595eee7 3737 for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3738 TDF_Label aDimensionL = aDGTLabels.Value(i);
3739 TDF_LabelSequence aFirstShapeL, aSecondShapeL;
6595eee7 3740 Handle(XCAFDoc_Dimension) aDimAttr;
3741 if (!aDimensionL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttr))
3742 continue;
3743 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject();
3744 if (anObject.IsNull())
3745 continue;
0b622d67 3746 if (anObject->GetType() == XCAFDimTolObjects_DimensionType_CommonLabel)
3747 {
3748 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->GetPlane());
3749 }
3750
3751 if (!DGTTool->GetRefShapeLabel(aDimensionL, aFirstShapeL, aSecondShapeL))
3752 continue;
6595eee7 3753
3754 // Write links with shapes
6595eee7 3755 Handle(StepRepr_ShapeAspect) aFirstSA, aSecondSA;
3756 if (aFirstShapeL.Length() == 1) {
3757 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(1));
3758 aFirstSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3759 if (aRC.IsNull() && !dummyRC.IsNull())
3760 aRC = dummyRC;
3761 }
3762 else if (aFirstShapeL.Length() > 1) {
3763 Handle(StepRepr_CompositeShapeAspect) aCSA;
3764 for (Standard_Integer shIt = 1; shIt <= aFirstShapeL.Length(); shIt++) {
3765 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(shIt));
3766 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
f3ec3b37 3767 if (aSA.IsNull())
3768 continue;
3769 if (aCSA.IsNull()) {
6595eee7 3770 aCSA = new StepRepr_CompositeShapeAspect();
3771 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3772 aModel->AddWithRefs(aCSA);
6595eee7 3773 }
f3ec3b37 3774 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3775 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA);
3776 aModel->AddWithRefs(aSAR);
6595eee7 3777 if (aRC.IsNull() && !dummyRC.IsNull())
3778 aRC = dummyRC;
3779 }
3780 aFirstSA = aCSA;
3781 }
3782 if (aSecondShapeL.Length() == 1) {
3783 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(1));
3784 aSecondSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3785 if (aRC.IsNull() && !dummyRC.IsNull())
3786 aRC = dummyRC;
3787 }
3788 else if (aSecondShapeL.Length() > 1) {
3789 Handle(StepRepr_CompositeShapeAspect) aCSA;
3790 for (Standard_Integer shIt = 1; shIt <= aSecondShapeL.Length(); shIt++) {
3791 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(shIt));
3792 Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU);
3793 if (aCSA.IsNull() && !aSA.IsNull())
3794 aCSA = new StepRepr_CompositeShapeAspect();
3795 aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional());
3796 if (!aSA.IsNull()) {
3797 Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship();
3798 aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA);
3799 aModel->AddWithRefs(aSAR);
3800 }
3801 if (aRC.IsNull() && !dummyRC.IsNull())
3802 aRC = dummyRC;
3803 }
3804 aSecondSA = aCSA;
3805 }
3806
3807 // Write dimensions
3808 StepShape_DimensionalCharacteristic aDimension;
b7b2f85a 3809 if (anObject->HasPoint() || anObject->HasPoint2())
3810 WriteDerivedGeometry(WS, anObject, aCGRepr, aFirstSA, aSecondSA, aConnectionPnts);
6595eee7 3811 XCAFDimTolObjects_DimensionType aDimType = anObject->GetType();
727b5ad9 3812 if (STEPCAFControl_GDTProperty::IsDimensionalLocation(aDimType)) {
6595eee7 3813 // Dimensional_Location
3814 Handle(StepShape_DimensionalLocation) aDim = new StepShape_DimensionalLocation();
727b5ad9 3815 aDim->Init(STEPCAFControl_GDTProperty::GetDimTypeName(aDimType), Standard_False, NULL, aFirstSA, aSecondSA);
6595eee7 3816 aDimension.SetValue(aDim);
3817 }
3818 else if (aDimType == XCAFDimTolObjects_DimensionType_Location_Angular) {
3819 // Angular_Location
3820 Handle(StepShape_AngularLocation) aDim = new StepShape_AngularLocation();
3821 StepShape_AngleRelator aRelator = StepShape_Equal;
3822 if (anObject->HasQualifier()) {
3823 XCAFDimTolObjects_DimensionQualifier aQualifier = anObject->GetQualifier();
3824 switch (aQualifier) {
3825 case XCAFDimTolObjects_DimensionQualifier_Min: aRelator = StepShape_Small;
3826 break;
3827 case XCAFDimTolObjects_DimensionQualifier_Max: aRelator = StepShape_Large;
3828 break;
3829 default: aRelator = StepShape_Equal;
3830 }
3831 }
3832 aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aRelator);
3833 aDimension.SetValue(aDim);
3834 }
3835 else if (aDimType == XCAFDimTolObjects_DimensionType_Location_WithPath) {
3836 // Dimensional_Location_With_Path
3837 Handle(StepShape_DimensionalLocationWithPath) aDim = new StepShape_DimensionalLocationWithPath();
3838 Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU);
3839 aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aPathSA);
3840 aDimension.SetValue(aDim);
3841 }
727b5ad9 3842 else if (STEPCAFControl_GDTProperty::IsDimensionalSize(aDimType)) {
6595eee7 3843 // Dimensional_Size
3844 Handle(StepShape_DimensionalSize) aDim = new StepShape_DimensionalSize();
727b5ad9 3845 aDim->Init(aFirstSA, STEPCAFControl_GDTProperty::GetDimTypeName(aDimType));
6595eee7 3846 aDimension.SetValue(aDim);
3847 }
3848 else if (aDimType == XCAFDimTolObjects_DimensionType_Size_Angular) {
3849 // Angular_Size
3850 Handle(StepShape_AngularSize) aDim = new StepShape_AngularSize();
3851 StepShape_AngleRelator aRelator = StepShape_Equal;
3852 if (anObject->HasQualifier()) {
3853 XCAFDimTolObjects_DimensionQualifier aQualifier = anObject->GetQualifier();
3854 switch (aQualifier) {
3855 case XCAFDimTolObjects_DimensionQualifier_Min: aRelator = StepShape_Small;
3856 break;
3857 case XCAFDimTolObjects_DimensionQualifier_Max: aRelator = StepShape_Large;
3858 break;
3859 default: aRelator = StepShape_Equal;
3860 }
3861 }
3862 aDim->Init(aFirstSA, new TCollection_HAsciiString(), aRelator);
3863 aDimension.SetValue(aDim);
3864 }
3865 else if (aDimType == XCAFDimTolObjects_DimensionType_Size_WithPath) {
3866 // Dimensional_Size_With_Path
3867 Handle(StepShape_DimensionalSizeWithPath) aDim = new StepShape_DimensionalSizeWithPath();
3868 Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU);
3869 aDim->Init(aFirstSA, new TCollection_HAsciiString(), aPathSA);
3870 aDimension.SetValue(aDim);
3871 }
3872
3873 // Write values
3874 WriteDimValues(WS, anObject, aRC, aDimension);
b0cef606 3875 //Annotation plane and Presentation
0b622d67 3876 WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->GetPlane(), anObject->GetPointTextAttach(), aDimension.Value());
6595eee7 3877 }
b7b2f85a 3878 // Write Derived geometry
3879 if (aConnectionPnts.Length() > 0) {
3880 Handle(StepRepr_HArray1OfRepresentationItem) anItems = new StepRepr_HArray1OfRepresentationItem(1, aConnectionPnts.Length());
3881 for (Standard_Integer i = 0; i < aConnectionPnts.Length(); i++)
3882 anItems->SetValue(i + 1, aConnectionPnts(i));
3883 aCGRepr->Init(new TCollection_HAsciiString(), anItems, dummyRC);
3884 aCGReprRel->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), dummyGISU->UsedRepresentation(), aCGRepr);
3885 aModel->AddWithRefs(aCGReprRel);
3886 }
6595eee7 3887
3888 //----------------------------//
3889 // write Geometric Tolerances //
3890 //----------------------------//
3891 aDGTLabels.Clear();
3892 DGTTool->GetGeomToleranceLabels(aDGTLabels);
3893 for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) {
3894 TDF_Label aGeomTolL = aDGTLabels.Value(i);
3895 TDF_LabelSequence aFirstShapeL, aNullSeqL;
3896 if (!DGTTool->GetRefShapeLabel(aGeomTolL, aFirstShapeL, aNullSeqL))
3897 continue;
3898 TDF_LabelSequence aDatumSeq;
3899 DGTTool->GetDatumWithObjectOfTolerLabels(aGeomTolL, aDatumSeq);
3900 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
3901 if (aDatumSeq.Length() > 0)
3902 aDatumSystem = WriteDatumSystem(WS, aGeomTolL, aDatumSeq, aDatumMap, aRC);
3903 WriteGeomTolerance(WS, aFirstShapeL, aGeomTolL, aDatumSystem, aRC);
3904 }
3905
b0cef606 3906 // Write Draughting model for Annotation Planes
3907 if (gdtAnnotationPlanes.Length() == 0)
3908 return Standard_True;
3909
3910 Handle(StepRepr_HArray1OfRepresentationItem) aItems =
3911 new StepRepr_HArray1OfRepresentationItem(1, gdtAnnotationPlanes.Length());
3912 for (Standard_Integer i = 1; i <= aItems->Length(); i++) {
3913 aItems->SetValue(i, gdtAnnotationPlanes.Value(i - 1));
3914 }
3915 gdtPresentationDM->Init(new TCollection_HAsciiString(), aItems, aRC);
3916 aModel->AddWithRefs(gdtPresentationDM);
3917
6595eee7 3918 return Standard_True;
3919}
7fd59977 3920
3921//=======================================================================
3922//function : FindPDSforRI
3923//purpose : auxilary:
3924//=======================================================================
3925static Standard_Boolean FindPDSforRI(const Interface_Graph &aGraph,
3926 const Handle(Standard_Transient) &ent,
3927 Handle(StepRepr_ProductDefinitionShape) &PDS,
3928 Handle(StepRepr_RepresentationContext) &RC)
3929{
3930 if(!ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem))) return Standard_False;
3931 Interface_EntityIterator subs = aGraph.Sharings(ent);
3932 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
3933 Handle(StepShape_ShapeRepresentation) SR =
3934 Handle(StepShape_ShapeRepresentation)::DownCast(subs.Value());
3935 if(SR.IsNull()) continue;
3936 RC = SR->ContextOfItems();
3937 Interface_EntityIterator subs1 = aGraph.Sharings(SR);
3938 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
3939 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
3940 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs1.Value());
3941 if(SDR.IsNull()) continue;
3942 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
3943 if(PropD.IsNull()) continue;
3944 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
3945 }
3946 }
3947 return Standard_True;
3948}
3949
3950
3951//=======================================================================
3952//function : WriteMaterials
3953//purpose :
3954//=======================================================================
3955
3956Standard_Boolean STEPCAFControl_Writer::WriteMaterials (const Handle(XSControl_WorkSession) &WS,
3957 const TDF_LabelSequence &labels ) const
3958{
3959
3960 if ( labels.Length() <=0 ) return Standard_False;
3961
3962 // get working data
7f56eba8 3963 const Handle(Interface_InterfaceModel) &Model = WS->Model();
3964 const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter();
3965 const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess();
9e20ed57 3966
3967 const Handle(Interface_HGraph) aHGraph = WS->HGraph();
3968 if(aHGraph.IsNull())
3969 return Standard_False;
3970
7fd59977 3971 Interface_Graph aGraph = WS->HGraph()->Graph();
3972 Handle(XCAFDoc_ShapeTool) ShTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
3973 if(ShTool.IsNull() ) return Standard_False;
3974 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( labels(1) );
3975 if(MatTool.IsNull() ) return Standard_False;
3976
3977 STEPConstruct_DataMapOfAsciiStringTransient MapDRI,MapMRI;
3978 TDF_LabelSequence TopLabels;
3979 ShTool->GetShapes(TopLabels);
3980 for(Standard_Integer i=1; i<=TopLabels.Length(); i++) {
3981 TDF_Label ShL = TopLabels.Value(i);
3982 Handle(TDataStd_TreeNode) Node;
3983 if( ShL.FindAttribute(XCAFDoc::MaterialRefGUID(),Node) && Node->HasFather() ) {
3984 // find PDS for current shape
3985 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShL);
3986 TopLoc_Location Loc;
3987 TColStd_SequenceOfTransient seqRI;
3988 FindEntities( FP, aShape, Loc, seqRI );
3989 if(seqRI.Length()<=0) continue;
3990 Handle(StepRepr_ProductDefinitionShape) PDS;
3991 Handle(StepRepr_RepresentationContext) RC;
3992 Handle(Standard_Transient) ent = seqRI.Value(1);
3993 FindPDSforRI(aGraph,ent,PDS,RC);
3994 if(PDS.IsNull()) continue;
1d2b1ccb
G
3995 Handle(StepBasic_ProductDefinition) aProdDef =
3996 PDS->Definition().ProductDefinition();
3997 if(aProdDef.IsNull())
3998 continue;
7fd59977 3999 // write material entities
4000 TDF_Label MatL = Node->Father()->Label();
4001 Handle(TCollection_HAsciiString) aName;
4002 Handle(TCollection_HAsciiString) aDescription;
4003 Standard_Real aDensity;
4004 Handle(TCollection_HAsciiString) aDensName;
4005 Handle(TCollection_HAsciiString) aDensValType;
41e259eb 4006 Handle(StepRepr_Representation) RepDRI;
4007 Handle(StepRepr_Representation) RepMRI;
7fd59977 4008 if(MatTool->GetMaterial(MatL,aName,aDescription,aDensity,aDensName,aDensValType)) {
4009 if(aName->Length()==0) continue;
4010 TCollection_AsciiString aKey(aName->ToCString());
4011 if(MapDRI.IsBound(aKey)) {
4012 RepDRI = Handle(StepRepr_Representation)::DownCast(MapDRI.Find(aKey));
4013 if(MapMRI.IsBound(aKey)) {
4014 RepMRI = Handle(StepRepr_Representation)::DownCast(MapMRI.Find(aKey));
4015 }
4016 }
4017 else {
4018 // write DRI
4019 Handle(StepRepr_DescriptiveRepresentationItem) DRI = new StepRepr_DescriptiveRepresentationItem;
4020 DRI->Init(aName,aDescription);
4021 Handle(StepRepr_HArray1OfRepresentationItem) HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
4022 HARI->SetValue(1,DRI);
41e259eb 4023 RepDRI = new StepRepr_Representation();
7fd59977 4024 RepDRI->Init(new TCollection_HAsciiString("material name"),HARI,RC);
4025 Model->AddWithRefs(RepDRI);
4026 // write MRI
41e259eb 4027 if( aDensity > 0 ) {
7fd59977 4028 // mass
4029 Handle(StepBasic_SiUnitAndMassUnit) SMU = new StepBasic_SiUnitAndMassUnit;
4030 SMU->SetName(StepBasic_sunGram);
4031 Handle(StepBasic_DerivedUnitElement) DUE1 = new StepBasic_DerivedUnitElement;
4032 DUE1->Init(SMU,3.0);
4033 // length
4034 Handle(StepBasic_SiUnitAndLengthUnit) SLU = new StepBasic_SiUnitAndLengthUnit;
4035 SLU->Init(Standard_True,StepBasic_spCenti,StepBasic_sunMetre);
4036 Handle(StepBasic_DerivedUnitElement) DUE2 = new StepBasic_DerivedUnitElement;
4037 DUE2->Init(SLU,2.0);
4038 // other
4039 Handle(StepBasic_HArray1OfDerivedUnitElement) HADUE = new StepBasic_HArray1OfDerivedUnitElement(1,2);
4040 HADUE->SetValue(1,DUE1);
4041 HADUE->SetValue(2,DUE2);
4042 Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit;
4043 DU->Init(HADUE);
4044 Model->AddWithRefs(DU);
4045 StepBasic_Unit aUnit;
4046 aUnit.SetValue(DU);
4047 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
4048 MVM->SetName(aDensValType->ToCString());
4049 MVM->SetReal(aDensity);
4050 Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem;
4051 MRI->Init(aDensName,MVM,aUnit);
4052 HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
4053 HARI->SetValue(1,MRI);
41e259eb 4054 RepMRI = new StepRepr_Representation();
7fd59977 4055 RepMRI->Init(new TCollection_HAsciiString("density"),HARI,RC);
4056 Model->AddWithRefs(RepMRI);
4057 }
4058 //WriteNewMaterial(Model,aName,aDescription,aDensity,aDensName,aDensValType,RC,RepDRI,RepMRI);
4059 MapDRI.Bind(aKey,RepDRI);
41e259eb 4060 if ( !RepMRI.IsNull() ) MapMRI.Bind (aKey, RepMRI);
4061 }
4062 }
4063
4064 if( !RepDRI.IsNull() )
4065 {
4066 StepRepr_CharacterizedDefinition CD1;
4067 CD1.SetValue(aProdDef);
4068 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
4069 PropD1->Init(new TCollection_HAsciiString("material property"),Standard_True,
4070 new TCollection_HAsciiString("material name"),CD1);
4071 Model->AddWithRefs(PropD1);
4072 StepRepr_RepresentedDefinition RD1;
4073 RD1.SetValue(PropD1);
4074 Handle(StepRepr_PropertyDefinitionRepresentation) PDR1 =
4075 new StepRepr_PropertyDefinitionRepresentation;
4076 PDR1->Init(RD1,RepDRI);
4077 Model->AddWithRefs(PDR1);
4078
4079 if( !RepMRI.IsNull() )
4080 {
4081 StepRepr_CharacterizedDefinition CD2;
4082 CD2.SetValue (aProdDef);
4083 Handle (StepRepr_PropertyDefinition) PropD2 = new StepRepr_PropertyDefinition;
4084 PropD2->Init (new TCollection_HAsciiString ("material property"), Standard_True,
4085 new TCollection_HAsciiString ("density"), CD2);
4086 Model->AddWithRefs (PropD2);
4087 StepRepr_RepresentedDefinition RD2;
4088 RD2.SetValue (PropD2);
4089 Handle (StepRepr_PropertyDefinitionRepresentation) PDR2 =
4090 new StepRepr_PropertyDefinitionRepresentation;
4091 PDR2->Init (RD2, RepMRI);
4092 Model->AddWithRefs (PDR2);
7fd59977 4093 }
4094 }
7fd59977 4095 }
4096 }
4097
4098 return Standard_True;
4099}
4100
4101
4102//=======================================================================
4103//function : SetColorMode
4104//purpose :
4105//=======================================================================
4106
4107void STEPCAFControl_Writer::SetColorMode (const Standard_Boolean colormode)
4108{
4109 myColorMode = colormode;
4110}
4111
4112
4113//=======================================================================
4114//function : GetColorMode
4115//purpose :
4116//=======================================================================
4117
4118Standard_Boolean STEPCAFControl_Writer::GetColorMode () const
4119{
4120 return myColorMode;
4121}
4122
4123
4124//=======================================================================
4125//function : SetNameMode
4126//purpose :
4127//=======================================================================
4128
4129void STEPCAFControl_Writer::SetNameMode (const Standard_Boolean namemode)
4130{
4131 myNameMode = namemode;
4132}
4133
4134
4135//=======================================================================
4136//function : GetNameMode
4137//purpose :
4138//=======================================================================
4139
4140Standard_Boolean STEPCAFControl_Writer::GetNameMode () const
4141{
4142 return myNameMode;
4143}
4144
4145
4146//=======================================================================
4147//function : SetLayerMode
4148//purpose :
4149//=======================================================================
4150
4151void STEPCAFControl_Writer::SetLayerMode (const Standard_Boolean layermode)
4152{
4153 myLayerMode = layermode;
4154}
4155
4156
4157//=======================================================================
4158//function : GetLayerMode
4159//purpose :
4160//=======================================================================
4161
4162Standard_Boolean STEPCAFControl_Writer::GetLayerMode () const
4163{
4164 return myLayerMode;
4165}
4166
4167
4168//=======================================================================
4169//function : SetPropsMode
4170//purpose :
4171//=======================================================================
4172
4173void STEPCAFControl_Writer::SetPropsMode (const Standard_Boolean propsmode)
4174{
4175 myPropsMode = propsmode;
4176}
4177
4178
4179//=======================================================================
4180//function : GetPropsMode
4181//purpose :
4182//=======================================================================
4183
4184Standard_Boolean STEPCAFControl_Writer::GetPropsMode () const
4185{
4186 return myPropsMode;
4187}
4188
4189
4190//=======================================================================
4191//function : SetSHUOMode
4192//purpose :
4193//=======================================================================
4194
4195void STEPCAFControl_Writer::SetSHUOMode (const Standard_Boolean mode)
4196{
4197 mySHUOMode = mode;
4198}
4199
4200
4201//=======================================================================
4202//function : GetSHUOMode
4203//purpose :
4204//=======================================================================
4205
4206Standard_Boolean STEPCAFControl_Writer::GetSHUOMode () const
4207{
4208 return mySHUOMode;
4209}
4210
4211
4212//=======================================================================
4213//function : SetDimTolMode
4214//purpose :
4215//=======================================================================
4216
4217void STEPCAFControl_Writer::SetDimTolMode(const Standard_Boolean dimtolmode)
4218{
4219 myDGTMode = dimtolmode;
4220}
4221
4222
4223//=======================================================================
4224//function : GetDimTolMode
4225//purpose :
4226//=======================================================================
4227
4228Standard_Boolean STEPCAFControl_Writer::GetDimTolMode() const
4229{
4230 return myDGTMode;
4231}
4232
4233
4234//=======================================================================
4235//function : SetMaterialMode
4236//purpose :
4237//=======================================================================
4238
4239void STEPCAFControl_Writer::SetMaterialMode(const Standard_Boolean matmode)
4240{
4241 myMatMode = matmode;
4242}
4243
4244
4245//=======================================================================
4246//function : GetMaterialMode
4247//purpose :
4248//=======================================================================
4249
4250Standard_Boolean STEPCAFControl_Writer::GetMaterialMode() const
4251{
4252 return myMatMode;
4253}