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