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