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