1 // Created on: 2000-08-15
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Builder.hxx>
18 #include <Geom_Axis2Placement.hxx>
19 #include <Geom_CartesianPoint.hxx>
20 #include <Geom_Plane.hxx>
21 #include <Interface_EntityIterator.hxx>
22 #include <Interface_InterfaceModel.hxx>
23 #include <StepData_StepModel.hxx>
24 #include <HeaderSection_FileSchema.hxx>
25 #include <Interface_Static.hxx>
26 #include <NCollection_DataMap.hxx>
27 #include <OSD_Path.hxx>
28 #include <Quantity_Color.hxx>
29 #include <StepAP214_AppliedExternalIdentificationAssignment.hxx>
30 #include <StepBasic_ConversionBasedUnitAndLengthUnit.hxx>
31 #include <StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx>
32 #include <StepBasic_ConversionBasedUnitAndMassUnit.hxx>
33 #include <StepBasic_DerivedUnit.hxx>
34 #include <StepBasic_DerivedUnitElement.hxx>
35 #include <StepBasic_MeasureValueMember.hxx>
36 #include <StepBasic_MeasureWithUnit.hxx>
37 #include <StepBasic_NamedUnit.hxx>
38 #include <StepBasic_Product.hxx>
39 #include <StepBasic_ProductDefinition.hxx>
40 #include <StepBasic_ProductDefinitionFormation.hxx>
41 #include <StepBasic_ProductDefinitionRelationship.hxx>
42 #include <StepBasic_SiUnit.hxx>
43 #include <StepBasic_SiUnitAndLengthUnit.hxx>
44 #include <StepBasic_Unit.hxx>
45 #include <STEPCAFControl_Controller.hxx>
46 #include <STEPCAFControl_DataMapIteratorOfDataMapOfShapePD.hxx>
47 #include <STEPCAFControl_DataMapOfPDExternFile.hxx>
48 #include <STEPCAFControl_DataMapOfSDRExternFile.hxx>
49 #include <STEPCAFControl_DataMapOfShapePD.hxx>
50 #include <STEPCAFControl_ExternFile.hxx>
51 #include <STEPCAFControl_Reader.hxx>
52 #include <STEPConstruct.hxx>
53 #include <STEPConstruct_Assembly.hxx>
54 #include <STEPConstruct_ExternRefs.hxx>
55 #include <STEPConstruct_Styles.hxx>
56 #include <STEPConstruct_Tool.hxx>
57 #include <STEPConstruct_UnitContext.hxx>
58 #include <STEPConstruct_ValidationProps.hxx>
59 #include <STEPControl_ActorRead.hxx>
60 #include <STEPControl_Reader.hxx>
61 #include <StepGeom_GeometricRepresentationItem.hxx>
62 #include <StepGeom_Axis2Placement3d.hxx>
63 #include <StepGeom_Direction.hxx>
64 #include <StepDimTol_AngularityTolerance.hxx>
65 #include <StepDimTol_CircularRunoutTolerance.hxx>
66 #include <StepDimTol_CoaxialityTolerance.hxx>
67 #include <StepDimTol_ConcentricityTolerance.hxx>
68 #include <StepDimTol_CylindricityTolerance.hxx>
69 #include <StepDimTol_Datum.hxx>
70 #include <StepDimTol_DatumFeature.hxx>
71 #include <StepDimTol_DatumReference.hxx>
72 #include <StepDimTol_DatumReferenceElement.hxx>
73 #include <StepDimTol_DatumReferenceCompartment.hxx>
74 #include <StepDimTol_DatumSystem.hxx>
75 #include <StepDimTol_FlatnessTolerance.hxx>
76 #include <StepDimTol_GeometricTolerance.hxx>
77 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
78 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
79 #include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx>
80 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
81 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol.hxx>
82 #include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx>
83 #include <StepDimTol_HArray1OfDatumReference.hxx>
84 #include <StepDimTol_LineProfileTolerance.hxx>
85 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
86 #include <StepDimTol_ParallelismTolerance.hxx>
87 #include <StepDimTol_PerpendicularityTolerance.hxx>
88 #include <StepDimTol_PositionTolerance.hxx>
89 #include <StepDimTol_ProjectedZoneDefinition.hxx>
90 #include <StepDimTol_RoundnessTolerance.hxx>
91 #include <StepDimTol_RunoutZoneDefinition.hxx>
92 #include <StepDimTol_StraightnessTolerance.hxx>
93 #include <StepDimTol_SurfaceProfileTolerance.hxx>
94 #include <StepDimTol_SymmetryTolerance.hxx>
95 #include <StepDimTol_ToleranceZone.hxx>
96 #include <StepDimTol_ToleranceZoneForm.hxx>
97 #include <StepDimTol_TotalRunoutTolerance.hxx>
98 #include <StepDimTol_GeometricToleranceWithModifiers.hxx>
99 #include <StepDimTol_HArray1OfGeometricToleranceModifier.hxx>
100 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
101 #include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
102 #include <StepDimTol_GeometricToleranceWithMaximumTolerance.hxx>
103 #include <StepGeom_Axis2Placement3d.hxx>
104 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
105 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
106 #include <StepGeom_Plane.hxx>
107 #include <StepGeom_Polyline.hxx>
108 #include <StepDimTol_PlacedDatumTargetFeature.hxx>
109 #include <StepRepr_AssemblyComponentUsage.hxx>
110 #include <StepRepr_CharacterizedDefinition.hxx>
111 #include <StepRepr_CompoundRepresentationItem.hxx>
112 #include <StepRepr_DerivedShapeAspect.hxx>
113 #include <StepRepr_DescriptiveRepresentationItem.hxx>
114 #include <StepRepr_HArray1OfRepresentationItem.hxx>
115 #include <StepRepr_MappedItem.hxx>
116 #include <StepRepr_MeasureRepresentationItem.hxx>
117 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
118 #include <StepRepr_ProductDefinitionShape.hxx>
119 #include <StepRepr_PropertyDefinition.hxx>
120 #include <StepRepr_PropertyDefinitionRepresentation.hxx>
121 #include <StepRepr_Representation.hxx>
122 #include <StepRepr_RepresentationItem.hxx>
123 #include <StepRepr_HArray1OfRepresentationItem.hxx>
124 #include <StepRepr_RepresentationMap.hxx>
125 #include <StepRepr_RepresentationRelationship.hxx>
126 #include <StepRepr_RepresentedDefinition.hxx>
127 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
128 #include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx>
129 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
130 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx>
131 #include <StepRepr_SequenceOfRepresentationItem.hxx>
132 #include <StepRepr_ShapeAspect.hxx>
133 #include <StepRepr_ShapeAspectDerivingRelationship.hxx>
134 #include <StepRepr_CompositeShapeAspect.hxx>
135 #include <StepRepr_AllAroundShapeAspect.hxx>
136 #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
137 #include <StepRepr_ShapeAspectRelationship.hxx>
138 #include <StepRepr_ShapeRepresentationRelationship.hxx>
139 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
140 #include <StepRepr_ValueRange.hxx>
141 #include <StepRepr_FeatureForDatumTargetRelationship.hxx>
142 #include <StepShape_AdvancedFace.hxx>
143 #include <StepShape_AdvancedBrepShapeRepresentation.hxx>
144 #include <StepShape_AngleRelator.hxx>
145 #include <StepShape_AngularSize.hxx>
146 #include <StepShape_AngularLocation.hxx>
147 #include <StepShape_ClosedShell.hxx>
148 #include <StepShape_ConnectedFaceSet.hxx>
149 #include <StepShape_ContextDependentShapeRepresentation.hxx>
150 #include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx>
151 #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
152 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
153 #include <StepShape_DimensionalSizeWithPath.hxx>
154 #include <StepShape_DimensionalLocationWithPath.hxx>
155 #include <StepShape_ShapeDimensionRepresentationItem.hxx>
156 #include <StepShape_ShapeRepresentationWithParameters.hxx>
157 #include <StepShape_HArray1OfShapeDimensionRepresentationItem.hxx>
158 #include <StepShape_DimensionalSize.hxx>
159 #include <StepShape_DimensionalLocation.hxx>
160 #include <StepShape_EdgeCurve.hxx>
161 #include <StepShape_EdgeLoop.hxx>
162 #include <StepShape_GeometricCurveSet.hxx>
163 #include <StepShape_GeometricSet.hxx>
164 #include <StepShape_HArray1OfFace.hxx>
165 #include <StepShape_HArray1OfFaceBound.hxx>
166 #include <StepShape_HArray1OfOrientedEdge.hxx>
167 #include <StepShape_HArray1OfShell.hxx>
168 #include <StepShape_LimitsAndFits.hxx>
169 #include <StepShape_Loop.hxx>
170 #include <StepShape_ManifoldSolidBrep.hxx>
171 #include <StepShape_PlusMinusTolerance.hxx>
172 #include <StepShape_QualifiedRepresentationItem.hxx>
173 #include <StepShape_OpenShell.hxx>
174 #include <StepShape_ShapeDefinitionRepresentation.hxx>
175 #include <StepShape_ShapeDimensionRepresentation.hxx>
176 #include <StepShape_ShapeRepresentation.hxx>
177 #include <StepShape_ShellBasedSurfaceModel.hxx>
178 #include <StepShape_SolidModel.hxx>
179 #include <StepShape_ToleranceMethodDefinition.hxx>
180 #include <StepShape_ToleranceValue.hxx>
181 #include <StepShape_ValueFormatTypeQualifier.hxx>
182 #include <StepShape_Vertex.hxx>
183 #include <StepToGeom.hxx>
184 #include <StepVisual_AnnotationCurveOccurrence.hxx>
185 #include <StepVisual_AnnotationFillArea.hxx>
186 #include <StepVisual_AnnotationPlane.hxx>
187 #include <StepVisual_CameraModelD3.hxx>
188 #include <StepVisual_CameraModelD3MultiClipping.hxx>
189 #include <StepVisual_CameraModelD3MultiClippingIntersection.hxx>
190 #include <StepVisual_CameraModelD3MultiClippingUnion.hxx>
191 #include <StepVisual_CoordinatesList.hxx>
192 #include <StepVisual_HArray1OfCameraModelD3MultiClippingInterectionSelect.hxx>
193 #include <StepVisual_HArray1OfCameraModelD3MultiClippingUnionSelect.hxx>
194 #include <StepVisual_DraughtingCallout.hxx>
195 #include <StepVisual_DraughtingCalloutElement.hxx>
196 #include <StepVisual_DraughtingModel.hxx>
197 #include <StepVisual_Invisibility.hxx>
198 #include <StepVisual_LayeredItem.hxx>
199 #include <StepVisual_PlanarBox.hxx>
200 #include <StepVisual_PresentationLayerAssignment.hxx>
201 #include <StepVisual_PresentationStyleByContext.hxx>
202 #include <StepVisual_StyleContextSelect.hxx>
203 #include <StepVisual_StyledItem.hxx>
204 #include <StepVisual_ViewVolume.hxx>
205 #include <StepShape_TypeQualifier.hxx>
206 #include <TCollection_AsciiString.hxx>
207 #include <TCollection_HAsciiString.hxx>
208 #include <TColStd_HArray1OfReal.hxx>
209 #include <TColStd_HArray1OfTransient.hxx>
210 #include <TColStd_HSequenceOfTransient.hxx>
211 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
212 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
213 #include <TColStd_MapOfTransient.hxx>
214 #include <TColStd_SequenceOfHAsciiString.hxx>
215 #include <TDataStd_Name.hxx>
216 #include <TDataStd_TreeNode.hxx>
217 #include <TDataStd_UAttribute.hxx>
218 #include <TDF_Label.hxx>
219 #include <TDF_Tool.hxx>
220 #include <TDocStd_Document.hxx>
221 #include <TNaming_NamedShape.hxx>
222 #include <TopExp_Explorer.hxx>
223 #include <TopoDS.hxx>
224 #include <TopoDS_Compound.hxx>
225 #include <TopoDS_Iterator.hxx>
226 #include <TopoDS_Shape.hxx>
227 #include <TopTools_ListIteratorOfListOfShape.hxx>
228 #include <TopTools_ListOfShape.hxx>
229 #include <TopTools_MapOfShape.hxx>
230 #include <Transfer_Binder.hxx>
231 #include <Transfer_TransientProcess.hxx>
232 #include <TransferBRep.hxx>
233 #include <UnitsMethods.hxx>
234 #include <XCAFDoc.hxx>
235 #include <XCAFDoc_Area.hxx>
236 #include <XCAFDoc_Centroid.hxx>
237 #include <XCAFDoc_ClippingPlaneTool.hxx>
238 #include <XCAFDoc_ColorTool.hxx>
239 #include <XCAFDoc_DataMapOfShapeLabel.hxx>
240 #include <XCAFDoc_DimTolTool.hxx>
241 #include <XCAFDoc_Dimension.hxx>
242 #include <XCAFDoc_Datum.hxx>
243 #include <XCAFDoc_GeomTolerance.hxx>
244 #include <XCAFDoc_DocumentTool.hxx>
245 #include <XCAFDoc_GraphNode.hxx>
246 #include <XCAFDoc_LayerTool.hxx>
247 #include <XCAFDoc_MaterialTool.hxx>
248 #include <XCAFDoc_ShapeTool.hxx>
249 #include <XCAFDoc_View.hxx>
250 #include <XCAFDoc_ViewTool.hxx>
251 #include <XCAFDoc_Volume.hxx>
252 #include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
253 #include <XCAFDimTolObjects_GeomToleranceType.hxx>
254 #include <XCAFDimTolObjects_DimensionObject.hxx>
255 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
256 #include <XCAFDimTolObjects_DatumObject.hxx>
257 #include <XCAFView_Object.hxx>
258 #include <XSAlgo.hxx>
259 #include <XSAlgo_AlgoContainer.hxx>
260 #include <XSControl_TransferReader.hxx>
261 #include <XSControl_WorkSession.hxx>
262 #include <StepAP242_DraughtingModelItemAssociation.hxx>
263 #include <StepAP242_GeometricItemSpecificUsage.hxx>
264 #include <StepGeom_CartesianPoint.hxx>
265 #include <STEPCAFControl_GDTProperty.hxx>
266 #include <StepVisual_TessellatedAnnotationOccurrence.hxx>
267 #include <StepVisual_TessellatedAnnotationOccurrence.hxx>
268 #include <StepVisual_TessellatedItem.hxx>
269 #include <StepVisual_TessellatedGeometricSet.hxx>
270 #include <StepVisual_TessellatedCurveSet.hxx>
271 #include <StepVisual_CoordinatesList.hxx>
272 #include <NCollection_Vector.hxx>
274 #include <TColgp_HArray1OfXYZ.hxx>
275 #include <BRepBuilderAPI_MakeEdge.hxx>
276 #include <BRepTools.hxx>
277 #include <Transfer_ActorOfTransientProcess.hxx>
278 #include <Bnd_Box.hxx>
279 #include <BRepBndLib.hxx>
281 // skl 21.08.2003 for reading G&DT
282 //#include <StepRepr_CompoundItemDefinition.hxx>
283 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
284 //#include <StepBasic_ConversionBasedUnit.hxx>
285 //#include <TDataStd_Real.hxx>
286 //#include <TDataStd_Constraint.hxx>
287 //#include <TDataStd_ConstraintEnum.hxx>
288 //#include <TNaming_Tool.hxx>
289 //#include <AIS_InteractiveObject.hxx>
290 //#include <TPrsStd_ConstraintTools.hxx>
291 //#include <AIS_DiameterDimension.hxx>
292 //#include <TPrsStd_Position.hxx>
293 //#include <TPrsStd_AISPresentation.hxx>
294 //#include <TNaming_Builder.hxx>
296 //! Converts address of the passed shape (TShape) to string.
297 //! \param theShape [in] Shape to dump.
298 //! \return corresponding string.
299 TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape)
301 std::string anAddrStr;
302 std::ostringstream ost;
303 ost << theShape.TShape().get();
304 anAddrStr = ost.str();
306 TCollection_AsciiString aStr =
307 TCollection_AsciiString("[").Cat( anAddrStr.c_str() ).Cat("]");
313 //=======================================================================
314 //function : STEPCAFControl_Reader
316 //=======================================================================
318 STEPCAFControl_Reader::STEPCAFControl_Reader ():
319 myColorMode( Standard_True ),
320 myNameMode ( Standard_True ),
321 myLayerMode( Standard_True ),
322 myPropsMode( Standard_True ),
323 mySHUOMode ( Standard_False ),
324 myGDTMode ( Standard_True ),
325 myMatMode(Standard_True),
326 myViewMode(Standard_True)
328 STEPCAFControl_Controller::Init();
332 //=======================================================================
333 //function : STEPCAFControl_Reader
335 //=======================================================================
337 STEPCAFControl_Reader::STEPCAFControl_Reader (const Handle(XSControl_WorkSession)& WS,
338 const Standard_Boolean scratch) :
339 myColorMode( Standard_True ),
340 myNameMode ( Standard_True ),
341 myLayerMode( Standard_True ),
342 myPropsMode( Standard_True ),
343 mySHUOMode ( Standard_False ),
344 myGDTMode ( Standard_True ),
345 myMatMode(Standard_True),
346 myViewMode(Standard_True)
348 STEPCAFControl_Controller::Init();
349 Init ( WS, scratch );
353 //=======================================================================
356 //=======================================================================
358 void STEPCAFControl_Reader::Init (const Handle(XSControl_WorkSession)& WS,
359 const Standard_Boolean scratch)
361 // necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
362 myReader.SetWS (WS,scratch);
367 //=======================================================================
368 //function : ReadFile
370 //=======================================================================
372 IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile (const Standard_CString filename)
374 return myReader.ReadFile ( filename );
378 //=======================================================================
379 //function : NbRootsForTransfer
381 //=======================================================================
383 Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer ()
385 return myReader.NbRootsForTransfer();
389 //=======================================================================
390 //function : TransferOneRoot
392 //=======================================================================
394 Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer num,
395 Handle(TDocStd_Document) &doc)
397 TDF_LabelSequence Lseq;
398 return Transfer ( myReader, num, doc, Lseq );
402 //=======================================================================
403 //function : Transfer
405 //=======================================================================
407 Standard_Boolean STEPCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc)
409 TDF_LabelSequence Lseq;
410 return Transfer ( myReader, 0, doc, Lseq );
414 //=======================================================================
417 //=======================================================================
419 Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename,
420 Handle(TDocStd_Document) &doc)
422 if ( ReadFile ( filename ) != IFSelect_RetDone ) return Standard_False;
423 return Transfer ( doc );
427 //=======================================================================
430 //=======================================================================
432 Standard_Boolean STEPCAFControl_Reader::Perform (const TCollection_AsciiString &filename,
433 Handle(TDocStd_Document) &doc)
435 if ( ReadFile ( filename.ToCString() ) != IFSelect_RetDone ) return Standard_False;
436 return Transfer ( doc );
440 //=======================================================================
441 //function : ExternFiles
443 //=======================================================================
445 const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& STEPCAFControl_Reader::ExternFiles () const
451 //=======================================================================
452 //function : ExternFile
454 //=======================================================================
456 Standard_Boolean STEPCAFControl_Reader::ExternFile (const Standard_CString name,
457 Handle(STEPCAFControl_ExternFile) &ef) const
460 if ( myFiles.IsEmpty() || !myFiles.IsBound ( name ) )
461 return Standard_False;
462 ef = myFiles.Find ( name );
463 return Standard_True;
467 //=======================================================================
470 //=======================================================================
472 STEPControl_Reader &STEPCAFControl_Reader::ChangeReader ()
478 //=======================================================================
481 //=======================================================================
483 const STEPControl_Reader &STEPCAFControl_Reader::Reader () const
489 //=======================================================================
490 //function : FillShapesMap
491 //purpose : auxiliary: fill a map by all compounds and their components
492 //=======================================================================
494 static void FillShapesMap (const TopoDS_Shape &S, TopTools_MapOfShape &map)
500 if ( S.ShapeType() != TopAbs_COMPOUND ) return;
501 for ( TopoDS_Iterator it(S); it.More(); it.Next() )
502 FillShapesMap ( it.Value(), map );
506 //=======================================================================
507 //function : Transfer
508 //purpose : basic working method
509 //=======================================================================
511 Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
512 const Standard_Integer nroot,
513 Handle(TDocStd_Document) &doc,
514 TDF_LabelSequence &Lseq,
515 const Standard_Boolean asOne)
517 reader.ClearShapes();
521 Standard_Integer num = reader.NbRootsForTransfer();
522 if ( num <=0 ) return Standard_False;
524 if ( nroot > num ) return Standard_False;
525 reader.TransferOneRoot ( nroot );
528 for ( i=1; i <= num; i++ ) reader.TransferOneRoot ( i );
530 num = reader.NbShapes();
531 if ( num <=0 ) return Standard_False;
533 // Fill a map of (top-level) shapes resulting from that transfer
534 // Only these shapes will be considered further
535 TopTools_MapOfShape ShapesMap, NewShapesMap;
536 for ( i=1; i <= num; i++ ) FillShapesMap ( reader.Shape(i), ShapesMap );
538 // Collect information on shapes originating from SDRs
539 // this will be used to distinguish compounds representing assemblies
540 // from the ones representing hybrid models and shape sets
541 STEPCAFControl_DataMapOfShapePD ShapePDMap;
542 STEPCAFControl_DataMapOfPDExternFile PDFileMap;
543 Handle(Interface_InterfaceModel) Model = reader.Model();
544 const Handle(Transfer_TransientProcess) &TP = reader.WS()->TransferReader()->TransientProcess();
545 Standard_Integer nb = Model->NbEntities();
547 Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
549 for (i = 1; i <= nb; i ++) {
550 Handle(Standard_Transient) enti = Model->Value(i);
551 if(enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
552 // sequence for acceleration ReadMaterials
553 SeqPDS->Append(enti);
555 if ( enti->IsKind ( STANDARD_TYPE(StepBasic_ProductDefinition ) ) ) {
556 Handle(StepBasic_ProductDefinition) PD =
557 Handle(StepBasic_ProductDefinition)::DownCast(enti);
558 Standard_Integer index = TP->MapIndex(PD);
560 Handle(Transfer_Binder) binder = TP->MapItem (index);
561 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
562 if ( ! S.IsNull() && ShapesMap.Contains(S) ) {
564 ShapePDMap.Bind ( S, PD );
565 Handle(STEPCAFControl_ExternFile) EF;
566 PDFileMap.Bind ( PD, EF );
570 if ( enti->IsKind ( STANDARD_TYPE(StepShape_ShapeRepresentation) ) ) {
571 Standard_Integer index = TP->MapIndex(enti);
573 Handle(Transfer_Binder) binder = TP->MapItem (index);
574 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
575 if ( ! S.IsNull() && ShapesMap.Contains(S) )
581 // get directory name of the main file
582 OSD_Path mainfile ( reader.WS()->LoadedFile() );
583 mainfile.SetName ( "" );
584 mainfile.SetExtension ( "" );
585 TCollection_AsciiString dpath;
586 mainfile.SystemName ( dpath );
588 // Load external references (only for relevant SDRs)
589 // and fill map SDR -> extern file
590 STEPConstruct_ExternRefs ExtRefs ( reader.WS() );
591 ExtRefs.LoadExternRefs();
592 for ( i=1; i <= ExtRefs.NbExternRefs(); i++ ) {
593 // check extern ref format
594 Handle(TCollection_HAsciiString) format = ExtRefs.Format(i);
595 if ( ! format.IsNull() ) {
596 static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString ( "STEP AP203" );
597 static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "STEP AP214" );
598 if ( ! format->IsSameString ( ap203, Standard_False ) &&
599 ! format->IsSameString ( ap214, Standard_False ) ) {
601 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << endl;
608 else cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << endl;
611 // get and check filename of the current extern ref
612 const Standard_CString filename = ExtRefs.FileName(i);
615 cout<<"filename="<<filename<<endl;
618 if ( ! filename || ! filename[0] ) {
620 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << endl;
622 continue; // not a valid extern ref
625 // compute true path to the extern file
626 TCollection_AsciiString fullname = OSD_Path::AbsolutePath ( dpath, filename );
627 if ( fullname.Length() <= 0 ) fullname = filename;
631 char *mainfile = reader.WS()->LoadedFile();
632 if ( ! mainfile ) mainfile = "";
633 Standard_Integer slash = 0;
634 for ( Standard_Integer k=0; mainfile[k]; k++ )
635 if ( mainfile[k] == '/' ) slash = k;
636 strncpy ( fullname, mainfile, slash );
637 sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename );
640 // get and check PD associated with the current extern ref
641 Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i);
642 if ( PD.IsNull() ) continue; // not a valid extern ref
643 if ( ! PDFileMap.IsBound ( PD ) ) continue; // this PD is not concerned by current transfer
645 // read extern file (or use existing data) and record its data
646 Handle(STEPCAFControl_ExternFile) EF =
647 ReadExternFile ( filename, fullname.ToCString(), doc );
648 PDFileMap.Bind ( PD, EF );
651 // and insert them to the document
652 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
653 if ( STool.IsNull() ) return Standard_False;
654 XCAFDoc_DataMapOfShapeLabel map;
656 Lseq.Append ( AddShape ( reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
658 for ( i=1; i <= num; i++ ) {
659 Lseq.Append ( AddShape ( reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
664 if ( GetColorMode() )
665 ReadColors ( reader.WS(), doc, map );
669 ReadNames ( reader.WS(), doc, PDFileMap, map );
671 // read validation props
672 if ( GetPropsMode() )
673 ReadValProps ( reader.WS(), doc, PDFileMap, map );
676 if ( GetLayerMode() )
677 ReadLayers ( reader.WS(), doc );
679 // read SHUO entities from STEP model
681 ReadSHUOs ( reader.WS(), doc, PDFileMap, map );
683 // read GDT entities from STEP model
685 ReadGDTs(reader.WS(),doc);
687 // read Material entities from STEP model
689 ReadMaterials(reader.WS(),doc,SeqPDS);
691 // read View entities from STEP model
693 ReadViews(reader.WS(), doc);
695 // Expand resulting CAF structure for sub-shapes (optionally with their
696 // names) if requested
697 ExpandSubShapes(STool, map, ShapePDMap);
699 // Update assembly compounds
700 STool->UpdateAssemblies();
702 return Standard_True;
705 //=======================================================================
706 //function : AddShape
708 //=======================================================================
710 TDF_Label STEPCAFControl_Reader::AddShape (const TopoDS_Shape &S,
711 const Handle(XCAFDoc_ShapeTool) &STool,
712 const TopTools_MapOfShape &NewShapesMap,
713 const STEPCAFControl_DataMapOfShapePD &ShapePDMap,
714 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
715 XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
717 // if shape has already been mapped, just return corresponding label
718 if ( ShapeLabelMap.IsBound ( S ) ) {
719 return ShapeLabelMap.Find ( S );
722 // if shape is located, create instance
723 if ( ! S.Location().IsIdentity() ) {
727 AddShape ( S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
728 TDF_Label L = STool->AddShape ( S, Standard_False ); // should create reference
729 ShapeLabelMap.Bind ( S, L );
733 // if shape is not compound, simple add it
734 if ( S.ShapeType() != TopAbs_COMPOUND ) {
735 TDF_Label L = STool->AddShape ( S, Standard_False );
736 ShapeLabelMap.Bind ( S, L );
740 // for compounds, compute number of subshapes and check whether this is assembly
741 Standard_Boolean isAssembly = Standard_False;
742 Standard_Integer nbComponents = 0;
744 for ( it.Initialize(S); it.More() && !isAssembly; it.Next(), nbComponents++ ) {
745 TopoDS_Shape Sub0 = it.Value();
747 Sub0.Location ( loc );
748 if ( NewShapesMap.Contains ( Sub0 ) ) isAssembly = Standard_True;
751 // if(nbComponents>0) isAssembly = Standard_True;
753 // check whether it has associated external ref
754 TColStd_SequenceOfHAsciiString SHAS;
755 if ( ShapePDMap.IsBound ( S ) && PDFileMap.IsBound ( ShapePDMap.Find(S) ) ) {
756 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( ShapePDMap.Find(S) );
757 if ( ! EF.IsNull() ) {
758 // (store information on extern refs in the document)
759 SHAS.Append(EF->GetName());
760 // if yes, just return corresponding label
761 if ( ! EF->GetLabel().IsNull() ) {
762 // but if components >0, ignore extern ref!
763 if ( nbComponents <=0 ) {
764 ShapeLabelMap.Bind ( S, EF->GetLabel() );
765 STool->SetExternRefs(EF->GetLabel(),SHAS);
766 return EF->GetLabel();
770 if ( ! EF->GetLabel().IsNull() )
771 cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << endl;
772 else if ( nbComponents <=0 )
773 cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << endl;
778 // add compound either as a whole,
779 if ( ! isAssembly ) {
780 TDF_Label L = STool->AddShape ( S, Standard_False );
781 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
782 ShapeLabelMap.Bind ( S, L );
786 // or as assembly, component-by-component
787 TDF_Label L = STool->NewShape();
789 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
790 TopoDS_Shape Sub0 = it.Value();
792 Sub0.Location ( loc );
793 TDF_Label subL = AddShape ( Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
794 if ( ! subL.IsNull() ) {
795 TDF_Label instL = STool->AddComponent ( L, subL, it.Value().Location() );
796 ShapeLabelMap.Bind(it.Value(), instL);
799 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
800 ShapeLabelMap.Bind ( S, L );
801 //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941
806 //=======================================================================
807 //function : ReadExternFile
809 //=======================================================================
811 Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const Standard_CString file,
812 const Standard_CString fullname,
813 Handle(TDocStd_Document)& doc)
815 // if the file is already read, associate it with SDR
816 if ( myFiles.IsBound ( file ) ) {
817 return myFiles.ChangeFind ( file );
821 cout << "Reading extern file: " << fullname << endl;
824 // create new WorkSession and Reader
825 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
826 newWS->SelectNorm ( "STEP" );
827 STEPControl_Reader sr ( newWS, Standard_False );
829 // start to fill the resulting ExternFile structure
830 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
832 EF->SetName ( new TCollection_HAsciiString ( file ) );
835 EF->SetLoadStatus ( sr.ReadFile ( fullname ) );
837 // transfer in single-result mode
838 if ( EF->GetLoadStatus() == IFSelect_RetDone ) {
839 TDF_LabelSequence labels;
840 EF->SetTransferStatus ( Transfer ( sr, 0, doc, labels, Standard_True ) );
841 if ( labels.Length() >0 ) EF->SetLabel ( labels.Value(1) );
844 // add read file to dictionary
845 myFiles.Bind( file, EF );
850 //=======================================================================
851 //function : findStyledSR
853 //=======================================================================
854 static void findStyledSR (const Handle(StepVisual_StyledItem) &style,
855 Handle(StepShape_ShapeRepresentation)& aSR)
857 // search Shape Represenatation for component styled item
858 for ( Standard_Integer j=1; j <= style->NbStyles(); j++ ) {
859 Handle(StepVisual_PresentationStyleByContext) PSA =
860 Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue ( j ));
863 StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext();
864 Handle(StepShape_ShapeRepresentation) aCurrentSR =
865 Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation());
866 if ( aCurrentSR.IsNull() )
874 //=======================================================================
875 //function : ReadColors
877 //=======================================================================
879 Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkSession) &WS,
880 Handle(TDocStd_Document)& Doc,
881 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
883 STEPConstruct_Styles Styles ( WS );
884 if ( ! Styles.LoadStyles() ) {
886 cout << "Warning: no styles are found in the model" << endl;
888 return Standard_False;
890 // searching for invisible items in the model
891 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
892 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
894 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
895 if ( CTool.IsNull() ) return Standard_False;
896 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
897 if (STool.IsNull()) return Standard_False;
899 // parse and search for color attributes
900 Standard_Integer nb = Styles.NbStyles();
901 for ( Standard_Integer i=1; i <= nb; i++ ) {
902 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
903 if ( style.IsNull() ) continue;
905 Standard_Boolean IsVisible = Standard_True;
906 // check the visibility of styled item.
907 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
908 if ( style != aHSeqOfInvisStyle->Value( si ) )
910 // found that current style is invisible.
911 IsVisible = Standard_False;
915 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
916 // check if it is component style
917 Standard_Boolean IsComponent = Standard_False;
918 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
922 NCollection_Vector<Handle(Standard_Transient)> anItems;
923 if (!style->Item().IsNull()) {
924 anItems.Append(style->Item());
926 else if (!style->ItemAP242().Representation().IsNull()){
927 //special case for AP242: item can be Reprsentation
928 Handle(StepRepr_Representation) aRepr = style->ItemAP242().Representation();
929 for (Standard_Integer j = 1; j <= aRepr->Items()->Length(); j++)
930 anItems.Append(aRepr->Items()->Value(j));
932 for (Standard_Integer itemIt = 0; itemIt < anItems.Length(); itemIt++) {
933 TopoDS_Shape S = STEPConstruct::FindShape ( Styles.TransientProcess(),
934 Handle(StepRepr_RepresentationItem)::DownCast(anItems.Value(itemIt)) );
935 Standard_Boolean isSkipSHUOstyle = Standard_False;
936 // take shape with real location.
937 while ( IsComponent ) {
939 Handle(StepShape_ShapeRepresentation) aSR;
940 findStyledSR( style, aSR );
941 // search for SR along model
944 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
945 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
946 for (subs.Start(); subs.More(); subs.Next()) {
947 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
950 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
951 Handle(StepRepr_ProductDefinitionShape) PDS =
952 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
955 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
957 Handle(StepRepr_AssemblyComponentUsage) ACU =
958 Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
961 // PTV 10.02.2003 skip styled item that refer to SHUO
962 if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
963 isSkipSHUOstyle = Standard_True;
966 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
967 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
972 // PTV 10.02.2003 to find component of assembly CORRECTLY
973 STEPConstruct_Tool Tool( WS );
974 TDF_Label aShLab = FindInstance ( NAUO, CTool->ShapeTool(), Tool, ShapeLabelMap );
975 aSh = CTool->ShapeTool()->GetShape(aShLab);
984 continue; // skip styled item which refer to SHUO
989 if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull() || !IsVisible)
992 Standard_Boolean isFound = STool->SearchUsingMap(S, aL, Standard_False, Standard_True);
993 if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull())
995 Quantity_Color aSCol, aBCol, aCCol;
996 if (!SurfCol.IsNull())
997 Styles.DecodeColor(SurfCol, aSCol);
998 if (!BoundCol.IsNull())
999 Styles.DecodeColor(BoundCol, aBCol);
1000 if (!CurveCol.IsNull())
1001 Styles.DecodeColor(CurveCol, aCCol);
1004 if (!SurfCol.IsNull())
1005 CTool->SetColor(aL, aSCol, XCAFDoc_ColorSurf);
1006 if (!BoundCol.IsNull())
1007 CTool->SetColor(aL, aBCol, XCAFDoc_ColorCurv);
1008 if (!CurveCol.IsNull())
1009 CTool->SetColor(aL, aCCol, XCAFDoc_ColorCurv);
1013 for (TopoDS_Iterator it(S); it.More(); it.Next())
1016 if (STool->SearchUsingMap(it.Value(), aL1, Standard_False, Standard_True))
1018 if (!SurfCol.IsNull())
1019 CTool->SetColor(aL1, aSCol, XCAFDoc_ColorSurf);
1020 if (!BoundCol.IsNull())
1021 CTool->SetColor(aL1, aBCol, XCAFDoc_ColorCurv);
1022 if (!CurveCol.IsNull())
1023 CTool->SetColor(aL1, aCCol, XCAFDoc_ColorCurv);
1030 // sets the invisibility for shape.
1032 CTool->SetVisibility(aL, Standard_False);
1037 CTool->ReverseChainsOfTreeNodes();
1038 return Standard_True;
1041 //=======================================================================
1042 //function : GetLabelFromPD
1044 //=======================================================================
1046 static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
1047 const Handle(XCAFDoc_ShapeTool) &STool,
1048 const Handle(Transfer_TransientProcess) &TP,
1049 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1050 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1053 if ( PDFileMap.IsBound ( PD ) ) {
1054 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
1055 if ( ! EF.IsNull() ) {
1057 if ( ! L.IsNull() ) return L;
1062 Handle(Transfer_Binder) binder = TP->Find(PD);
1063 if ( binder.IsNull() || ! binder->HasResult() ) return L;
1064 S = TransferBRep::ShapeResult ( TP, binder );
1065 if ( S.IsNull() ) return L;
1067 if ( ShapeLabelMap.IsBound ( S ) )
1068 L = ShapeLabelMap.Find ( S );
1070 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1074 //=======================================================================
1075 //function : FindInstance
1077 //=======================================================================
1079 TDF_Label STEPCAFControl_Reader::FindInstance (const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO,
1080 const Handle(XCAFDoc_ShapeTool) &STool,
1081 const STEPConstruct_Tool &Tool,
1082 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1086 // get shape resulting from CDSR (in fact, only location is interesting)
1087 Handle(Transfer_TransientProcess) TP = Tool.TransientProcess();
1088 Handle(Transfer_Binder) binder = TP->Find(NAUO);
1089 if ( binder.IsNull() || ! binder->HasResult() ) {
1091 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
1096 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1099 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
1104 if (ShapeLabelMap.IsBound(S))
1105 L = ShapeLabelMap(S);
1107 STool->Search(S, L, Standard_True, Standard_True, Standard_False);
1112 //=======================================================================
1113 //function : ReadNames
1115 //=======================================================================
1117 Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS,
1118 Handle(TDocStd_Document)& Doc,
1119 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1120 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1122 // get starting data
1123 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1124 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1125 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1126 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1127 if ( STool.IsNull() ) return Standard_False;
1128 STEPConstruct_Tool Tool ( WS );
1130 // iterate on model to find all SDRs and CDSRs
1131 Standard_Integer nb = Model->NbEntities();
1132 Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
1133 Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
1134 Handle(TCollection_HAsciiString) name;
1136 for (Standard_Integer i = 1; i <= nb; i++) {
1137 Handle(Standard_Transient) enti = Model->Value(i);
1139 // get description of NAUO
1140 if ( enti->DynamicType() == tNAUO ) {
1142 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1143 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
1144 if(NAUO.IsNull()) continue;
1145 Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
1146 for (subs.Start(); subs.More(); subs.Next()) {
1147 Handle(StepRepr_ProductDefinitionShape) PDS =
1148 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1149 if(PDS.IsNull()) continue;
1150 Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
1151 if ( PDR.IsNull() ) continue;
1152 if ( PDR->HasDescription() &&
1153 PDR->Description()->UsefullLength() >0 ) name = PDR->Description();
1154 else if ( !PDR->Name().IsNull() && PDR->Name()->UsefullLength() >0 ) name = PDR->Name();
1155 else if ( !PDR->Id().IsNull()) name = PDR->Id();
1156 else name = new TCollection_HAsciiString;
1158 // find proper label
1159 L = FindInstance ( NAUO, STool, Tool, ShapeLabelMap );
1160 if ( L.IsNull() ) continue;
1161 TCollection_ExtendedString str ( name->String() );
1162 TDataStd_Name::Set ( L, str );
1165 // for PD get name of associated product
1166 if ( enti->DynamicType() == tPD ) {
1168 Handle(StepBasic_ProductDefinition) PD =
1169 Handle(StepBasic_ProductDefinition)::DownCast(enti);
1170 if(PD.IsNull()) continue;
1171 Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL);
1173 name = new TCollection_HAsciiString;
1174 else if (!Prod->Name().IsNull() && Prod->Name()->UsefullLength() > 0)
1175 name = Prod->Name();
1176 else if (!Prod->Id().IsNull())
1179 name = new TCollection_HAsciiString;
1180 L = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1181 if ( L.IsNull() ) continue;
1182 TCollection_ExtendedString str ( name->String() );
1183 TDataStd_Name::Set ( L, str );
1185 // set a name to the document
1186 //TCollection_ExtendedString str ( name->String() );
1187 //TDataStd_Name::Set ( L, str );
1190 return Standard_True;
1193 //=======================================================================
1194 //function : GetLabelFromPD
1196 //=======================================================================
1198 static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
1199 const Handle(XCAFDoc_ShapeTool) &STool,
1200 const STEPConstruct_ValidationProps &Props,
1201 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1202 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1205 if ( PDFileMap.IsBound ( PD ) ) {
1206 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
1207 if ( ! EF.IsNull() ) {
1209 if ( ! L.IsNull() ) return L;
1212 TopoDS_Shape S = Props.GetPropShape ( PD );
1213 if ( S.IsNull() ) return L;
1214 if ( ShapeLabelMap.IsBound ( S ) )
1215 L = ShapeLabelMap.Find ( S );
1217 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1221 //=======================================================================
1222 //function : ReadValProps
1224 //=======================================================================
1226 Standard_Boolean STEPCAFControl_Reader::ReadValProps (const Handle(XSControl_WorkSession) &WS,
1227 Handle(TDocStd_Document)& Doc,
1228 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1229 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1231 // get starting data
1232 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1233 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1234 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1235 if ( STool.IsNull() ) return Standard_False;
1237 // load props from the STEP model
1238 TColStd_SequenceOfTransient props;
1239 STEPConstruct_ValidationProps Props ( WS );
1240 if ( ! Props.LoadProps ( props ) ) {
1242 cout << "Warning: no validation props found in the model" << endl;
1244 return Standard_False;
1247 // interpret props one by one
1248 for (Standard_Integer i = 1; i <= props.Length(); i ++) {
1249 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1250 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast ( props.Value(i) );
1251 if ( PDR.IsNull() ) continue;
1255 Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition();
1256 Interface_EntityIterator subs = Props.Graph().Shareds(PD);
1257 for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) {
1258 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)) ) {
1259 Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1260 if(PDS.IsNull()) continue;
1261 // find corresponding NAUO
1262 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO;
1263 Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS);
1264 for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) {
1265 if ( subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)) )
1266 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value());
1268 if ( !NAUO.IsNull() ) {
1269 L = FindInstance ( NAUO, STool, WS, ShapeLabelMap );
1270 if ( L.IsNull() ) continue;
1273 // find corresponding ProductDefinition:
1274 Handle(StepBasic_ProductDefinition) ProdDef;
1275 Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS);
1276 for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) {
1277 if ( subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)) )
1278 ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value());
1280 if ( ProdDef.IsNull() ) continue;
1281 L = GetLabelFromPD ( ProdDef, STool, Props, PDFileMap, ShapeLabelMap );
1285 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)) ) {
1286 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value());
1287 if(SA.IsNull()) continue;
1288 // find ShapeRepresentation
1289 Handle(StepShape_ShapeRepresentation) SR;
1290 Interface_EntityIterator subs1 = Props.Graph().Sharings(SA);
1291 for(subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) {
1292 Handle(StepRepr_PropertyDefinition) PropD1 =
1293 Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value());
1294 if(PropD1.IsNull()) continue;
1295 Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1);
1296 for(subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) {
1297 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1298 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
1299 if(SDR.IsNull()) continue;
1300 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1303 if(SR.IsNull()) continue;
1304 Handle(Transfer_Binder) binder;
1305 for(Standard_Integer ir=1; ir<=SR->NbItems() && binder.IsNull(); ir++) {
1306 if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) {
1307 Handle(StepShape_SolidModel) SM =
1308 Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir));
1309 binder = TP->Find(SM);
1311 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1312 Handle(StepShape_ShellBasedSurfaceModel) SBSM =
1313 Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir));
1314 binder = TP->Find(SBSM);
1316 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1317 Handle(StepShape_GeometricSet) GS =
1318 Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir));
1319 binder = TP->Find(GS);
1322 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1324 S = TransferBRep::ShapeResult ( TP, binder );
1325 if(S.IsNull()) continue;
1326 if ( ShapeLabelMap.IsBound ( S ) )
1327 L = ShapeLabelMap.Find ( S );
1329 STool->Search ( S, L, Standard_True, Standard_True, Standard_True );
1333 if(L.IsNull()) continue;
1335 // decode validation properties
1336 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
1337 for ( Standard_Integer j=1; j <= rep->NbItems(); j++ ) {
1338 Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j);
1339 Standard_Boolean isArea;
1342 if ( Props.GetPropReal ( ent, val, isArea ) ) {
1343 if ( isArea ) XCAFDoc_Area::Set ( L, val );
1344 else XCAFDoc_Volume::Set ( L, val );
1346 else if ( Props.GetPropPnt ( ent, rep->ContextOfItems(), pos ) ) {
1347 XCAFDoc_Centroid::Set ( L, pos );
1351 return Standard_True;
1354 //=======================================================================
1355 //function : ReadLayers
1357 //=======================================================================
1359 Standard_Boolean STEPCAFControl_Reader::ReadLayers (const Handle(XSControl_WorkSession) &WS,
1360 Handle(TDocStd_Document)& Doc) const
1362 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1363 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1364 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1365 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1366 if ( STool.IsNull() ) return Standard_False;
1367 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( Doc->Main() );
1368 if ( LTool.IsNull() ) return Standard_False;
1370 Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment);
1371 Standard_Integer nb = Model->NbEntities();
1372 Handle(TCollection_HAsciiString) name;
1374 for (Standard_Integer i = 1; i <= nb; i ++) {
1375 Handle(Standard_Transient) enti = Model->Value(i);
1376 if ( ! enti->IsKind ( tSVPLA ) ) continue;
1377 Handle(StepVisual_PresentationLayerAssignment) SVPLA =
1378 Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
1379 if (SVPLA->AssignedItems().IsNull())
1382 Handle(TCollection_HAsciiString) descr = SVPLA->Description();
1383 Handle(TCollection_HAsciiString) hName = SVPLA->Name();
1384 TCollection_ExtendedString aLayerName ( hName->String() );
1386 // find a target shape and its label in the document
1387 for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++ ) {
1388 StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j);
1389 Handle(Transfer_Binder) binder = TP->Find( LI.Value() );
1390 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1392 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1393 if ( S.IsNull() ) continue;
1396 if ( ! STool->Search ( S, shL, Standard_True, Standard_True, Standard_True ) ) continue;
1397 LTool->SetLayer ( shL, aLayerName );
1400 // check invisibility
1401 Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
1402 for (subs.Start(); subs.More(); subs.Next()) {
1403 if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility)) ) continue;
1405 cout<< "\tLayer \"" << aLayerName << "\" is invisible"<<endl;
1407 //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName);
1408 TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926
1409 Handle(TDataStd_UAttribute) aUAttr;
1410 aUAttr->Set( InvLayerLab, XCAFDoc::InvisibleGUID() );
1413 return Standard_True;
1416 //=======================================================================
1417 //function : ReadSHUOs
1419 //=======================================================================
1421 static Standard_Boolean findNextSHUOlevel (const Handle(XSControl_WorkSession) &WS,
1422 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1423 const Handle(XCAFDoc_ShapeTool)& STool,
1424 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1425 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap,
1426 TDF_LabelSequence& aLabels)
1428 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO);
1429 Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO;
1430 for (subs.Start(); subs.More(); subs.Next()) {
1431 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1432 subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value());
1436 if (subSHUO.IsNull())
1437 return Standard_False;
1439 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = subSHUO->NextUsage();
1440 if (NUNAUO.IsNull())
1441 return Standard_False;
1442 // Handle(Interface_InterfaceModel) Model = WS->Model();
1443 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1444 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1445 // Handle(Transfer_Binder) binder = TP->Find(NUNAUO);
1446 // if ( binder.IsNull() || ! binder->HasResult() )
1447 // return Standard_False;
1448 // TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder );
1449 // get label of NAUO next level
1451 STEPConstruct_Tool Tool( WS );
1452 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, ShapeLabelMap );
1453 // STool->Search(NUSh, NUlab);
1455 return Standard_False;
1456 aLabels.Append( NULab );
1457 // and check by recurse.
1458 findNextSHUOlevel( WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels );
1459 return Standard_True;
1463 //=======================================================================
1464 //function : setSHUOintoDoc
1465 //purpose : auxilary
1466 //=======================================================================
1467 static TDF_Label setSHUOintoDoc (const Handle(XSControl_WorkSession) &WS,
1468 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1469 const Handle(XCAFDoc_ShapeTool)& STool,
1470 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1471 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1473 TDF_Label aMainLabel;
1474 // get upper usage NAUO from SHUO.
1475 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
1476 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
1477 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = SHUO->NextUsage();
1478 if ( UUNAUO.IsNull() || NUNAUO.IsNull() ) {
1480 cout << "Warning: " << __FILE__ <<": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl;
1484 // Handle(Interface_InterfaceModel) Model = WS->Model();
1485 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1486 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1487 // TopoDS_Shape UUSh, NUSh;
1488 // Handle(Transfer_Binder) binder = TP->Find(UUNAUO);
1489 // if ( binder.IsNull() || ! binder->HasResult() )
1490 // return aMainLabel;
1491 // UUSh = TransferBRep::ShapeResult ( TP, binder );
1492 // binder = TP->Find(NUNAUO);
1493 // if ( binder.IsNull() || ! binder->HasResult() )
1494 // return aMainLabel;
1495 // NUSh = TransferBRep::ShapeResult ( TP, binder );
1497 // get first labels for first SHUO attribute
1498 TDF_Label UULab, NULab;
1499 STEPConstruct_Tool Tool( WS );
1500 UULab = STEPCAFControl_Reader::FindInstance ( UUNAUO, STool, Tool, ShapeLabelMap );
1501 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, ShapeLabelMap );
1503 // STool->Search(UUSh, UULab);
1504 // STool->Search(NUSh, NULab);
1505 if (UULab.IsNull() || NULab.IsNull()) return aMainLabel;
1506 //create sequence fo labels to set SHUO structure into the document
1507 TDF_LabelSequence ShuoLabels;
1508 ShuoLabels.Append( UULab );
1509 ShuoLabels.Append( NULab );
1510 // add all other labels of sub SHUO entities
1511 findNextSHUOlevel( WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels );
1512 // last accord for SHUO
1513 Handle(XCAFDoc_GraphNode) anSHUOAttr;
1514 if ( STool->SetSHUO( ShuoLabels, anSHUOAttr ) )
1515 aMainLabel = anSHUOAttr->Label();
1521 //=======================================================================
1522 //function : ReadSHUOs
1524 //=======================================================================
1526 Standard_Boolean STEPCAFControl_Reader::ReadSHUOs (const Handle(XSControl_WorkSession) &WS,
1527 Handle(TDocStd_Document)& Doc,
1528 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1529 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1531 // the big part code duplication from ReadColors.
1532 // It is possible to share this code functionality, just to decide how ???
1533 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
1534 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
1536 STEPConstruct_Styles Styles ( WS );
1537 if ( ! Styles.LoadStyles() ) {
1539 cout << "Warning: no styles are found in the model" << endl;
1541 return Standard_False;
1543 // searching for invisible items in the model
1544 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
1545 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
1546 // parse and search for color attributes
1547 Standard_Integer nb = Styles.NbStyles();
1548 for ( Standard_Integer i=1; i <= nb; i++ ) {
1549 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
1550 if ( style.IsNull() ) continue;
1552 Standard_Boolean IsVisible = Standard_True;
1553 // check the visibility of styled item.
1554 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
1555 if ( style != aHSeqOfInvisStyle->Value( si ) )
1557 // found that current style is invisible.
1559 cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << endl;
1561 IsVisible = Standard_False;
1565 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
1566 // check if it is component style
1567 Standard_Boolean IsComponent = Standard_False;
1568 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
1572 Handle(StepShape_ShapeRepresentation) aSR;
1573 findStyledSR( style, aSR );
1574 // search for SR along model
1577 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
1578 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1579 for (subs.Start(); subs.More(); subs.Next()) {
1580 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1581 if ( aSDR.IsNull() )
1583 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1584 Handle(StepRepr_ProductDefinitionShape) PDS =
1585 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1588 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1589 Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO =
1590 Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship());
1591 if ( SHUO.IsNull() )
1594 // set the SHUO structure to the document
1595 TDF_Label aLabelForStyle = setSHUOintoDoc( WS, SHUO, STool, PDFileMap, ShapeLabelMap );
1596 if ( aLabelForStyle.IsNull() ) {
1598 cout << "Warning: " << __FILE__ <<": coudnot create SHUO structure in the document" << endl;
1602 // now set the style to the SHUO main label.
1603 if ( ! SurfCol.IsNull() ) {
1605 Styles.DecodeColor ( SurfCol, col );
1606 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorSurf );
1608 if ( ! BoundCol.IsNull() ) {
1610 Styles.DecodeColor ( BoundCol, col );
1611 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1613 if ( ! CurveCol.IsNull() ) {
1615 Styles.DecodeColor ( CurveCol, col );
1616 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1619 // sets the invisibility for shape.
1620 CTool->SetVisibility( aLabelForStyle, Standard_False );
1622 } // end search SHUO by SDR
1623 } // end iterates on styles
1625 return Standard_True;
1628 //=======================================================================
1629 //function : GetMassConversionFactor
1631 //=======================================================================
1632 static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1633 Standard_Real& afact)
1636 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit)) ) return Standard_False;
1637 Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU =
1638 Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU);
1639 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor();
1640 afact = MWUCBU->ValueComponent();
1641 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1642 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1643 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1644 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1645 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1646 if(SU->Name()==StepBasic_sunGram) {
1648 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1652 return Standard_True;
1655 //=======================================================================
1656 //function : readPMIPresentation
1657 //purpose : read polyline or tessellated presentation for
1658 // (Annotation_Curve_Occurrence or Draughting_Callout)
1659 //=======================================================================
1660 Standard_Boolean readPMIPresentation(const Handle(Standard_Transient)& thePresentEntity,
1661 const Handle(XSControl_TransferReader)& theTR,
1662 const Standard_Real theFact,
1663 TopoDS_Shape& thePresentation,
1664 Handle(TCollection_HAsciiString)& thePresentName,
1667 if (thePresentEntity.IsNull())
1668 return Standard_False;
1669 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1670 Handle(StepVisual_AnnotationOccurrence) anAO;
1671 NCollection_Vector<Handle(StepVisual_StyledItem)> anAnnotations;
1672 if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
1674 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(thePresentEntity);
1675 if (!anAO.IsNull()) {
1676 thePresentName = anAO->Name();
1677 anAnnotations.Append(anAO);
1680 else if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)))
1682 Handle(StepVisual_DraughtingCallout) aDCallout =
1683 Handle(StepVisual_DraughtingCallout)::DownCast(thePresentEntity);
1684 thePresentName = aDCallout->Name();
1685 for (Standard_Integer i = 1; i <= aDCallout->NbContents() && anAO.IsNull(); i++) {
1686 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(aDCallout->ContentsValue(i).Value());
1689 anAnnotations.Append(anAO);
1692 Handle(StepVisual_TessellatedAnnotationOccurrence) aTesselation =
1693 aDCallout->ContentsValue(i).TessellatedAnnotationOccurrence();
1694 if (!aTesselation.IsNull())
1695 anAnnotations.Append(aTesselation);
1699 if (!anAnnotations.Length())
1700 return Standard_False;
1704 TopoDS_Compound aResAnnotation;
1705 aB.MakeCompound(aResAnnotation);
1707 Standard_Integer i = 0;
1709 Standard_Integer nbShapes = 0;
1710 for (; i < anAnnotations.Length(); i++)
1712 Handle(StepVisual_StyledItem) anItem = anAnnotations(i);
1713 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(anItem);
1714 TopoDS_Shape anAnnotationShape;
1717 Handle(StepRepr_RepresentationItem) aCurveItem = anAO->Item();
1718 anAnnotationShape = STEPConstruct::FindShape(aTP, aCurveItem);
1719 if (anAnnotationShape.IsNull())
1721 Handle(Transfer_Binder) binder = theTR->Actor()->Transfer(aCurveItem, aTP);
1722 if (!binder.IsNull() && binder->HasResult()) {
1723 anAnnotationShape = TransferBRep::ShapeResult(aTP, binder);
1727 //case of tessellated entities
1730 Handle(StepRepr_RepresentationItem) aTessItem = anItem->Item();
1731 if (aTessItem.IsNull())
1733 Handle(StepVisual_TessellatedGeometricSet) aTessSet = Handle(StepVisual_TessellatedGeometricSet)::DownCast(aTessItem);
1734 if (aTessSet.IsNull())
1736 NCollection_Handle<StepVisual_Array1OfTessellatedItem> aListItems = aTessSet->Items();
1737 Standard_Integer nb = aListItems.IsNull() ? 0 : aListItems->Length();
1738 Handle(StepVisual_TessellatedCurveSet) aTessCurve;
1739 for (Standard_Integer n = 1; n <= nb && aTessCurve.IsNull(); n++)
1741 aTessCurve = Handle(StepVisual_TessellatedCurveSet)::DownCast(aListItems->Value(n));
1743 if (aTessCurve.IsNull())
1745 Handle(StepVisual_CoordinatesList) aCoordList = aTessCurve->CoordList();
1746 if (aCoordList.IsNull())
1748 Handle(TColgp_HArray1OfXYZ) aPoints = aCoordList->Points();
1750 if (aPoints.IsNull() || aPoints->Length() == 0)
1752 NCollection_Handle<StepVisual_VectorOfHSequenceOfInteger> aCurves = aTessCurve->Curves();
1753 Standard_Integer aNbC = (aCurves.IsNull() ? 0 : aCurves->Length());
1754 TopoDS_Compound aComp;
1755 aB.MakeCompound(aComp);
1757 Standard_Integer k = 0;
1758 for (; k < aNbC; k++)
1760 Handle(TColStd_HSequenceOfInteger) anIndexes = aCurves->Value(k);
1764 for (Standard_Integer n = 1; n < anIndexes->Length(); n++)
1766 Standard_Integer ind = anIndexes->Value(n);
1767 Standard_Integer indnext = anIndexes->Value(n + 1);
1768 if (ind > aPoints->Length() || indnext > aPoints->Length())
1770 gp_Pnt aP1(aPoints->Value(ind) * theFact);
1771 gp_Pnt aP2(aPoints->Value(indnext) * theFact);
1772 BRepBuilderAPI_MakeEdge aMaker(aP1, aP2);
1773 if (aMaker.IsDone())
1775 TopoDS_Edge aCurE = aMaker.Edge();
1776 aB.Add(aCurW, aCurE);
1779 aB.Add(aComp, aCurW);
1781 anAnnotationShape = aComp;
1783 if (!anAnnotationShape.IsNull())
1786 aB.Add(aResAnnotation, anAnnotationShape);
1787 if (i == anAnnotations.Length() - 1)
1788 BRepBndLib::AddClose(anAnnotationShape, aBox);
1792 thePresentation = aResAnnotation;
1794 return (nbShapes > 0);
1797 //=======================================================================
1798 //function : readAnnotationPlane
1799 //purpose : read annotation plane
1800 //=======================================================================
1801 Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) theAnnotationPlane,
1804 if (theAnnotationPlane.IsNull())
1805 return Standard_False;
1806 Handle(StepRepr_RepresentationItem) aPlaneItem = theAnnotationPlane->Item();
1807 if (aPlaneItem.IsNull())
1808 return Standard_False;
1809 Handle(StepGeom_Axis2Placement3d) aA2P3D;
1810 //retrieve axes from AnnotationPlane
1811 if (aPlaneItem->IsKind(STANDARD_TYPE(StepGeom_Plane))) {
1812 Handle(StepGeom_Plane) aPlane = Handle(StepGeom_Plane)::DownCast(aPlaneItem);
1813 aA2P3D = aPlane->Position();
1815 else if (aPlaneItem->IsKind(STANDARD_TYPE(StepVisual_PlanarBox))) {
1816 Handle(StepVisual_PlanarBox) aBox = Handle(StepVisual_PlanarBox)::DownCast(aPlaneItem);
1817 aA2P3D = aBox->Placement().Axis2Placement3d();
1819 if (aA2P3D.IsNull())
1820 return Standard_False;
1822 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aA2P3D);
1823 thePlane = anAxis->Ax2();
1824 return Standard_True;
1827 //=======================================================================
1828 //function : readAnnotation
1829 //purpose : read annotation plane and position for given GDT
1830 // (Dimension, Geometric_Tolerance, Datum_Feature or Placed_Datum_Target_Feature)
1831 //=======================================================================
1832 void readAnnotation(const Handle(XSControl_TransferReader)& theTR,
1833 const Handle(Standard_Transient)& theGDT,
1834 const Handle(Standard_Transient)& theDimObject)
1836 if (theGDT.IsNull() || theDimObject.IsNull())
1838 Handle(TCollection_HAsciiString) aPresentName;
1839 TopoDS_Compound aResAnnotation;
1840 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1841 const Interface_Graph& aGraph = aTP->Graph();
1842 // find the proper DraughtingModelItemAssociation
1843 Interface_EntityIterator subs = aGraph.Sharings(theGDT);
1844 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
1845 for (subs.Start(); subs.More() && aDMIA.IsNull(); subs.Next()) {
1846 if (!subs.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
1848 aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(subs.Value());
1849 Handle(TCollection_HAsciiString) aName = aDMIA->Name();
1851 if (!aName->Search(new TCollection_HAsciiString("pmi representation to presentation link"))) {
1855 if (aDMIA.IsNull() || aDMIA->NbIdentifiedItem() == 0)
1859 Handle(StepVisual_DraughtingModel) aDModel =
1860 Handle(StepVisual_DraughtingModel)::DownCast(aDMIA->UsedRepresentation());
1861 XSAlgo::AlgoContainer()->PrepareForTransfer();
1862 STEPControl_ActorRead anActor;
1863 anActor.PrepareUnits(aDModel, aTP);
1864 Standard_Real aFact = UnitsMethods::LengthFactor();
1866 // retrieve AnnotationPlane
1867 Handle(StepRepr_RepresentationItem) aDMIAE = aDMIA->IdentifiedItemValue(1);
1868 if (aDMIAE.IsNull())
1871 subs = aGraph.Sharings(aDMIAE);
1872 Handle(StepVisual_AnnotationPlane) anAnPlane;
1873 for (subs.Start(); subs.More() && anAnPlane.IsNull(); subs.Next()) {
1874 anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(subs.Value());
1876 Standard_Boolean isHasPlane = readAnnotationPlane(anAnPlane, aPlaneAxes);
1878 // set plane axes to XCAF
1880 if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) {
1881 Handle(XCAFDimTolObjects_DimensionObject) anObj =
1882 Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject);
1883 Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt(1, 1);
1884 anObj->SetPlane(aPlaneAxes);
1886 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) {
1887 Handle(XCAFDimTolObjects_DatumObject) anObj =
1888 Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject);
1889 anObj->SetPlane(aPlaneAxes);
1891 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) {
1892 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj =
1893 Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject);
1894 anObj->SetPlane(aPlaneAxes);
1898 // Retrieve presentation
1900 if (!readPMIPresentation(aDMIAE, theTR, aFact, aResAnnotation, aPresentName, aBox))
1902 gp_Pnt aPtext(0., 0., 0.);
1903 // if Annotation plane location inside bounding box set it to text position
1904 // else set the center of bounding box to text position
1907 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
1908 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
1909 if (isHasPlane && !aBox.IsOut(aPlaneAxes.Location())) {
1910 aPtext = aPlaneAxes.Location();
1913 aPtext = gp_Pnt((aXmin + aXmax) * 0.5, (aYmin + aYmax) * 0.5, (aZmin + aZmax) * 0.5);
1917 aPtext = aPlaneAxes.Location();
1920 // set point to XCAF
1921 if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) {
1922 Handle(XCAFDimTolObjects_DimensionObject) anObj =
1923 Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject);
1924 anObj->SetPointTextAttach(aPtext);
1925 anObj->SetPresentation(aResAnnotation, aPresentName);
1927 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) {
1928 Handle(XCAFDimTolObjects_DatumObject) anObj =
1929 Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject);
1930 anObj->SetPointTextAttach(aPtext);
1931 anObj->SetPresentation(aResAnnotation, aPresentName);
1933 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) {
1934 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj =
1935 Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject);
1936 anObj->SetPointTextAttach(aPtext);
1937 anObj->SetPresentation(aResAnnotation, aPresentName);
1942 //=======================================================================
1943 //function : readConnectionPoints
1944 //purpose : read connection points for given dimension
1945 //=======================================================================
1946 void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR,
1947 const Handle(Standard_Transient) theGDT,
1948 const Handle(XCAFDimTolObjects_DimensionObject)& theDimObject)
1950 if (theGDT.IsNull() || theDimObject.IsNull())
1952 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1953 const Interface_Graph& aGraph = aTP->Graph();
1956 Handle(StepShape_ShapeDimensionRepresentation) aSDR = NULL;
1957 for (Interface_EntityIterator anIt = aGraph.Sharings(theGDT); aSDR.IsNull() && anIt.More(); anIt.Next()) {
1958 aSDR = Handle(StepShape_ShapeDimensionRepresentation)::DownCast(anIt.Value());
1960 XSAlgo::AlgoContainer()->PrepareForTransfer();
1961 STEPControl_ActorRead anActor;
1962 anActor.PrepareUnits(aSDR, aTP);
1963 Standard_Real aFact = UnitsMethods::LengthFactor();
1965 if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
1966 // retrieve derived geometry
1967 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theGDT);
1968 Handle(StepRepr_DerivedShapeAspect) aDSA = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->AppliesTo());
1971 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = NULL;
1972 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA); aGISU.IsNull() && anIt.More(); anIt.Next()) {
1973 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
1975 if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0)
1977 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU->IdentifiedItem()->Value(1));
1978 if (aPoint.IsNull()) {
1979 // try Axis2Placement3d.location instead of CartesianPoint
1980 Handle(StepGeom_Axis2Placement3d) anA2P3D =
1981 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU->IdentifiedItem()->Value(1));
1982 if (anA2P3D.IsNull())
1984 aPoint = anA2P3D->Location();
1987 // set connection point to object
1988 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
1989 theDimObject->SetPoint(aPnt);
1991 else if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
1992 // retrieve derived geometry
1993 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theGDT);
1994 Handle(StepRepr_DerivedShapeAspect) aDSA1 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatingShapeAspect());
1995 Handle(StepRepr_DerivedShapeAspect) aDSA2 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatedShapeAspect());
1996 if (aDSA1.IsNull() && aDSA2.IsNull())
1998 Handle(StepAP242_GeometricItemSpecificUsage) aGISU1 = NULL;
1999 Handle(StepAP242_GeometricItemSpecificUsage) aGISU2 = NULL;
2000 if (!aDSA1.IsNull()) {
2001 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA1); aGISU1.IsNull() && anIt.More(); anIt.Next()) {
2002 aGISU1 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2005 if (!aDSA2.IsNull()) {
2006 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA2); aGISU2.IsNull() && anIt.More(); anIt.Next()) {
2007 aGISU2 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2011 if (!aGISU1.IsNull() && aGISU1->NbIdentifiedItem() > 0) {
2012 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2013 if (aPoint.IsNull()) {
2014 // try Axis2Placement3d.location instead of CartesianPoint
2015 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2016 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2017 if (!anA2P3D.IsNull())
2018 aPoint = anA2P3D->Location();
2020 if (!aPoint.IsNull()) {
2021 // set connection point to object
2022 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2023 theDimObject->SetPoint(aPnt);
2027 if (!aGISU2.IsNull() && aGISU2->NbIdentifiedItem() > 0) {
2028 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2029 if (aPoint.IsNull()) {
2030 // try Axis2Placement3d.location instead of CartesianPoint
2031 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2032 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2033 if (!anA2P3D.IsNull())
2034 aPoint = anA2P3D->Location();
2036 if (!aPoint.IsNull()) {
2037 // set connection point to object
2038 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2039 theDimObject->SetPoint2(aPnt);
2045 //=======================================================================
2046 //function : ReadDatums
2047 //purpose : auxilary
2048 //=======================================================================
2049 static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
2050 const Handle(XCAFDoc_DimTolTool) &DGTTool,
2051 const Interface_Graph &graph,
2052 const Handle(Transfer_TransientProcess) &TP,
2053 const TDF_Label TolerL,
2054 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
2056 if(GTWDR.IsNull()) return Standard_False;
2057 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
2058 if(HADR.IsNull()) return Standard_False;
2059 for(Standard_Integer idr=1; idr<=HADR->Length(); idr++) {
2060 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
2061 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
2062 if(aDatum.IsNull()) continue;
2063 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
2064 for(subs4.Start(); subs4.More(); subs4.Next()) {
2065 Handle(StepRepr_ShapeAspectRelationship) SAR =
2066 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
2067 if(SAR.IsNull()) continue;
2068 Handle(StepDimTol_DatumFeature) DF =
2069 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
2070 if(DF.IsNull()) continue;
2071 Interface_EntityIterator subs5 = graph.Sharings(DF);
2072 Handle(StepRepr_PropertyDefinition) PropDef;
2073 for(subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
2074 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
2076 if(PropDef.IsNull()) continue;
2077 Handle(StepShape_AdvancedFace) AF;
2078 subs5 = graph.Sharings(PropDef);
2079 for(subs5.Start(); subs5.More(); subs5.Next()) {
2080 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2081 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
2083 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2084 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
2085 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
2086 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2090 if(AF.IsNull()) return Standard_False;
2091 Standard_Integer index = TP->MapIndex(AF);
2094 Handle(Transfer_Binder) binder = TP->MapItem(index);
2095 aSh = TransferBRep::ShapeResult(binder);
2097 if(aSh.IsNull()) continue;
2099 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2100 DGTTool->SetDatum(shL,TolerL,PropDef->Name(),PropDef->Description(),aDatum->Identification());
2103 return Standard_True;
2106 //=======================================================================
2107 //function : FindShapeIndexForDGT
2108 //purpose : auxiliary find shape index in map og imported shapes
2109 //=======================================================================
2110 static Standard_Integer FindShapeIndexForDGT(const Handle(Standard_Transient)& theEnt,
2111 const Handle(XSControl_WorkSession)& theWS)
2113 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2114 // try to find index of given entity
2115 Standard_Integer anIndex = aTP->MapIndex(theEnt);
2118 // if theEnt is a geometry item try to find its topological item
2119 const Interface_Graph& aGraph = aTP->Graph();
2120 Interface_EntityIterator anIter = aGraph.Sharings(theEnt);
2121 for (anIter.Start(); anIter.More(); anIter.Next()) {
2122 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)))
2124 anIndex = aTP->MapIndex(anIter.Value());
2132 //=======================================================================
2133 //function : collectShapeAspect
2135 //=======================================================================
2136 static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA,
2137 const Handle(XSControl_WorkSession)& theWS,
2138 NCollection_Sequence<Handle(StepRepr_ShapeAspect)>& theSAs)
2142 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2143 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2144 const Interface_Graph& aGraph = aTP->Graph();
2145 // Retrieve Shape_Aspect, connected to Representation_Item from Derived_Shape_Aspect
2146 if (theSA->IsKind(STANDARD_TYPE(StepRepr_DerivedShapeAspect))) {
2147 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2148 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = NULL;
2149 for (; aSADR.IsNull() && anIter.More(); anIter.Next()) {
2150 aSADR = Handle(StepRepr_ShapeAspectDerivingRelationship)::DownCast(anIter.Value());
2152 if (!aSADR.IsNull())
2153 collectShapeAspect(aSADR->RelatedShapeAspect(), theWS, theSAs);
2155 else if (theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
2156 theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) {
2157 theSAs.Append(theSA);
2161 // Find all children Shape_Aspect
2162 Standard_Boolean isSimple = Standard_True;
2163 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2164 for (; anIter.More(); anIter.Next()) {
2165 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship)) &&
2166 !anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2167 Handle(StepRepr_ShapeAspectRelationship) aSAR =
2168 Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
2169 if (aSAR->RelatingShapeAspect() == theSA && !aSAR->RelatedShapeAspect().IsNull()
2170 && !aSAR->RelatedShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_Datum))) {
2171 collectShapeAspect(aSAR->RelatedShapeAspect(), theWS, theSAs);
2172 isSimple = Standard_False;
2176 // If not Composite_Shape_Aspect (or subtype) append to sequence.
2178 theSAs.Append(theSA);
2182 //=======================================================================
2183 //function : getShapeLabel
2185 //=======================================================================
2187 static TDF_Label getShapeLabel(const Handle(StepRepr_RepresentationItem)& theItem,
2188 const Handle(XSControl_WorkSession)& theWS,
2189 const Handle(XCAFDoc_ShapeTool)& theShapeTool)
2192 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2193 Standard_Integer index = FindShapeIndexForDGT(theItem, theWS);
2194 TopoDS_Shape aShape;
2196 Handle(Transfer_Binder) aBinder = aTP->MapItem(index);
2197 aShape = TransferBRep::ShapeResult(aBinder);
2199 if (aShape.IsNull())
2201 theShapeTool->Search(aShape, aShapeL, Standard_True, Standard_True, Standard_True);
2205 //=======================================================================
2206 //function : setDatumToXCAF
2208 //=======================================================================
2210 Standard_Boolean STEPCAFControl_Reader::setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
2211 const TDF_Label theGDTL,
2212 const Standard_Integer thePositionCounter,
2213 const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
2214 const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
2215 const Standard_Real theModifValue,
2216 const Handle(TDocStd_Document)& theDoc,
2217 const Handle(XSControl_WorkSession)& theWS)
2219 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
2220 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
2221 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2222 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2223 const Interface_Graph& aGraph = aTP->Graph();
2224 Handle(XCAFDoc_Datum) aDat;
2225 TDF_LabelSequence aShapeLabels;
2226 Handle(XCAFDimTolObjects_DatumObject) aDatObj = new XCAFDimTolObjects_DatumObject();
2228 // Collect all links to shapes
2229 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2230 Interface_EntityIterator anIterD = aGraph.Sharings(theDat);
2231 for (anIterD.Start(); anIterD.More(); anIterD.Next()) {
2232 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value());
2233 if (aSAR.IsNull() || aSAR->RelatingShapeAspect().IsNull())
2235 collectShapeAspect(aSAR->RelatingShapeAspect(), theWS, aSAs);
2236 Handle(StepDimTol_DatumFeature) aDF = Handle(StepDimTol_DatumFeature)::DownCast(aSAR->RelatingShapeAspect());
2237 if (!aSAR->RelatingShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2238 readAnnotation(aTR, aSAR->RelatingShapeAspect(), aDatObj);
2241 // Collect shape labels
2242 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2243 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2246 // Skip datum targets
2247 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2250 // Process all connected GISU
2251 Interface_EntityIterator anIter = aGraph.Sharings(aSA);
2252 for (; anIter.More(); anIter.Next()) {
2253 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
2256 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2257 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2258 if (!aShapeL.IsNull())
2259 aShapeLabels.Append(aShapeL);
2264 // Process datum targets and create objects for them
2265 Standard_Boolean isExistDatumTarget = Standard_False;
2266 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2267 Handle(StepDimTol_PlacedDatumTargetFeature) aDT = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSAs.Value(i));
2270 Handle(XCAFDimTolObjects_DatumObject) aDatTargetObj = new XCAFDimTolObjects_DatumObject();
2271 XCAFDimTolObjects_DatumTargetType aType;
2272 if (!STEPCAFControl_GDTProperty::GetDatumTargetType(aDT->Description(), aType))
2274 aDatTargetObj->SetDatumTargetType(aType);
2275 Standard_Boolean isValidDT = Standard_False;
2277 // Feature for datum target
2278 TDF_LabelSequence aDTShapeLabels;
2279 Interface_EntityIterator aDTIter = aGraph.Sharings(aDT);
2280 Handle(StepRepr_FeatureForDatumTargetRelationship) aRelationship;
2281 for (; aDTIter.More() && aRelationship.IsNull(); aDTIter.Next()) {
2282 aRelationship = Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(aDTIter.Value());
2284 if (!aRelationship.IsNull()) {
2285 Handle(StepRepr_ShapeAspect) aSA = aRelationship->RelatingShapeAspect();
2286 Interface_EntityIterator aSAIter = aGraph.Sharings(aSA);
2287 for (; aSAIter.More(); aSAIter.Next()) {
2288 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aSAIter.Value());
2291 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2292 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2293 if (!aShapeL.IsNull()) {
2294 aDTShapeLabels.Append(aShapeL);
2295 isValidDT = Standard_True;
2301 if (aType != XCAFDimTolObjects_DatumTargetType_Area && !isValidDT) {
2302 // Try another way of feature connection
2303 for (aDTIter.Start(); aDTIter.More(); aDTIter.Next()) {
2304 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aDTIter.Value());
2307 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2308 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2309 if (!aShapeL.IsNull()) {
2310 aDTShapeLabels.Append(aShapeL);
2311 isValidDT = Standard_True;
2317 if (aType == XCAFDimTolObjects_DatumTargetType_Area) {
2318 // Area datum target
2319 Interface_EntityIterator anIterDTF = aGraph.Shareds(aDT);
2320 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2321 for (; anIterDTF.More() && aGISU.IsNull(); anIterDTF.Next()) {
2322 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDTF.Value());
2324 Handle(StepRepr_RepresentationItem) anItem;
2325 if (aGISU->NbIdentifiedItem() > 0)
2326 anItem = aGISU->IdentifiedItemValue(1);
2327 if (anItem.IsNull())
2329 Standard_Integer anItemIndex = FindShapeIndexForDGT(anItem, theWS);
2330 if (anItemIndex > 0) {
2331 Handle(Transfer_Binder) aBinder = aTP->MapItem(anItemIndex);
2332 TopoDS_Shape anItemShape = TransferBRep::ShapeResult(aBinder);
2333 aDatTargetObj->SetDatumTarget(anItemShape);
2334 isValidDT = Standard_True;
2338 // Point/line/rectangle/circle datum targets
2339 Interface_EntityIterator anIter = aGraph.Sharings(aDT);
2340 Handle(StepRepr_PropertyDefinition) aPD;
2341 for (; anIter.More() && aPD.IsNull(); anIter.Next()) {
2342 aPD = Handle(StepRepr_PropertyDefinition)::DownCast(anIter.Value());
2344 if (!aPD.IsNull()) {
2345 anIter = aGraph.Sharings(aPD);
2346 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2347 for (; anIter.More() && aSDR.IsNull(); anIter.Next()) {
2348 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anIter.Value());
2350 if (!aSDR.IsNull()) {
2351 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP
2352 = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(aSDR->UsedRepresentation());
2353 if (!aSRWP.IsNull()) {
2354 isValidDT = Standard_True;
2355 // Collect parameters of datum target
2356 for (Standard_Integer j = aSRWP->Items()->Lower(); j <= aSRWP->Items()->Upper(); j++)
2358 if (aSRWP->ItemsValue(j).IsNull())
2360 if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2362 Handle(StepGeom_Axis2Placement3d) anAx
2363 = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(j));
2364 XSAlgo::AlgoContainer()->PrepareForTransfer();
2365 STEPControl_ActorRead anActor;
2366 anActor.PrepareUnits(aSRWP, aTP);
2367 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(anAx);
2368 aDatTargetObj->SetDatumTargetAxis(anAxis->Ax2());
2370 else if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
2372 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
2373 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(j));
2374 Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
2375 StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
2376 if (anUnit.IsNull())
2378 Handle(StepBasic_NamedUnit) aNU = anUnit.NamedUnit();
2381 STEPConstruct_UnitContext anUnitCtx;
2382 anUnitCtx.ComputeFactors(aNU);
2383 aVal = aVal * anUnitCtx.LengthFactor();
2384 if (aM->Name()->String().IsEqual("target length") ||
2385 aM->Name()->String().IsEqual("target diameter"))
2386 aDatTargetObj->SetDatumTargetLength(aVal);
2388 aDatTargetObj->SetDatumTargetWidth(aVal);
2396 // Create datum target object
2398 TDF_Label aDatL = aDGTTool->AddDatum();
2399 myGDTMap.Bind(aDT, aDatL);
2400 aDGTTool->Lock(aDatL);
2401 aDat = XCAFDoc_Datum::Set(aDatL);
2402 aDGTTool->SetDatum(aDTShapeLabels, aDatL);
2403 aDatTargetObj->SetName(theDat->Identification());
2404 aDatTargetObj->SetPosition(thePositionCounter);
2405 if (!theXCAFModifiers.IsEmpty())
2406 aDatTargetObj->SetModifiers(theXCAFModifiers);
2407 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2408 aDatTargetObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2409 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2410 aDatTargetObj->IsDatumTarget(Standard_True);
2411 aDatTargetObj->SetDatumTargetNumber(aDT->TargetId()->IntegerValue());
2412 readAnnotation(aTR, aDT, aDatTargetObj);
2413 aDat->SetObject(aDatTargetObj);
2414 isExistDatumTarget = Standard_True;
2418 if (aShapeLabels.Length() > 0 || !isExistDatumTarget) {
2419 // Create object for datum
2420 TDF_Label aDatL = aDGTTool->AddDatum();
2421 myGDTMap.Bind(theDat, aDatL);
2422 // bind datum label with all reference datum_feature entities
2423 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2424 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2425 if (aSA.IsNull() || aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2427 myGDTMap.Bind(aSA, aDatL);
2429 aDGTTool->Lock(aDatL);
2430 aDat = XCAFDoc_Datum::Set(aDatL);
2431 aDGTTool->SetDatum(aShapeLabels, aDatL);
2432 aDatObj->SetName(theDat->Identification());
2433 aDatObj->SetPosition(thePositionCounter);
2434 if (!theXCAFModifiers.IsEmpty())
2435 aDatObj->SetModifiers(theXCAFModifiers);
2436 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2437 aDatObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2438 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2439 if (aDatObj->GetPresentation().IsNull()) {
2440 // Try find annotation connected to datum entity (not right case, according recommended practices)
2441 readAnnotation(aTR, theDat, aDatObj);
2443 aDat->SetObject(aDatObj);
2446 return Standard_True;
2450 //=======================================================================
2451 //function : ReadDatums
2452 //purpose : auxilary
2453 //=======================================================================
2454 Standard_Boolean STEPCAFControl_Reader::readDatumsAP242(const Handle(Standard_Transient)& theEnt,
2455 const TDF_Label theGDTL,
2456 const Handle(TDocStd_Document)& theDoc,
2457 const Handle(XSControl_WorkSession)& theWS)
2459 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2460 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2461 const Interface_Graph& aGraph = aTP->Graph();
2463 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2464 for(anIter.Start(); anIter.More(); anIter.Next()) {
2465 Handle(Standard_Transient) anAtr = anIter.Value();
2466 if(anAtr->IsKind(STANDARD_TYPE(StepDimTol_DatumSystem)))
2468 Standard_Integer aPositionCounter = 0;//position on frame
2469 Handle(StepDimTol_DatumSystem) aDS = Handle(StepDimTol_DatumSystem)::DownCast(anAtr);
2470 Interface_EntityIterator anIterDS = aGraph.Sharings(aDS);
2471 for(anIterDS.Start(); anIterDS.More(); anIterDS.Next()) {
2472 Handle(Standard_Transient) anAtrDS = anIterDS.Value();
2473 if(anAtrDS->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
2476 Handle(StepAP242_GeometricItemSpecificUsage)aAxGISUI
2477 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anAtrDS);
2478 if (aAxGISUI->IdentifiedItemValue(1)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2480 Handle(StepGeom_Axis2Placement3d) anAx
2481 = Handle(StepGeom_Axis2Placement3d)::DownCast(aAxGISUI->IdentifiedItemValue(1));
2482 Handle(XCAFDoc_GeomTolerance) aTol;
2483 if(theGDTL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aTol))
2485 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aTol->GetObject();
2486 Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
2487 Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
2488 Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
2492 if(!aDirArr.IsNull() && aDirArr->Length() > 2 &&
2493 !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
2494 !aLocArr.IsNull() && aLocArr->Length() > 2)
2496 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, aDirArr->Lower()+2);
2497 aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower()+1, aDirRArr->Lower()+2);
2498 aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower()+1, aLocArr->Lower()+2);
2499 gp_Ax2 anA(aPnt, aDir, aDirR);
2500 anObj->SetAxis(anA);
2501 aTol->SetObject(anObj);
2507 if (aDS->NbConstituents() > 0)
2509 //get datum feature and datum target from datum system
2510 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aDRCA = aDS->Constituents();
2513 for(Standard_Integer i = aDRCA->Lower(); i <= aDRCA->Upper(); i++)
2515 Handle(StepDimTol_DatumReferenceCompartment) aDRC = aDRCA->Value(i);
2517 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModif = aDRC->Modifiers();
2518 XCAFDimTolObjects_DatumModifiersSequence aXCAFModifiers;
2519 XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal = XCAFDimTolObjects_DatumModifWithValue_None;
2520 Standard_Real aModifValue = 0;
2521 if(!aModif.IsNull())
2523 for(Standard_Integer m = aModif->Lower(); m <= aModif->Upper(); m++)
2525 if(aModif->Value(m).CaseNumber() == 2)
2526 aXCAFModifiers.Append(
2527 (XCAFDimTolObjects_DatumSingleModif)aModif->Value(m).
2528 SimpleDatumReferenceModifierMember()->Value());
2529 else if (aModif->Value(m).CaseNumber() == 1)
2531 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModif->Value(m).DatumReferenceModifierWithValue()->ModifierType() + 1);
2532 Standard_Real aVal = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2533 StepBasic_Unit anUnit = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2534 if(anUnit.IsNull()) continue;
2535 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2536 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2537 STEPConstruct_UnitContext anUnitCtx;
2538 anUnitCtx.ComputeFactors(NU);
2539 aModifValue = aVal * anUnitCtx.LengthFactor();
2544 Interface_EntityIterator anIterDRC = aGraph.Shareds(aDRC);
2545 for(anIterDRC.Start(); anIterDRC.More(); anIterDRC.Next()) {
2547 if(anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2549 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRC.Value());
2550 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue,theDoc, theWS);
2552 else if(anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_DatumReferenceElement)))
2554 Handle(StepDimTol_DatumReferenceElement) aDRE
2555 = Handle(StepDimTol_DatumReferenceElement)::DownCast(anIterDRC.Value());
2556 //get modifiers from group of datums
2557 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifE = aDRE->Modifiers();
2558 if(!aModifE.IsNull())
2560 for(Standard_Integer k = aModifE->Lower(); k <= aModifE->Upper(); k++)
2562 if(aModifE->Value(k).CaseNumber() == 2)
2563 aXCAFModifiers.Append(
2564 (XCAFDimTolObjects_DatumSingleModif)aModifE->Value(k).
2565 SimpleDatumReferenceModifierMember()->Value());
2566 else if (aModifE->Value(k).CaseNumber() == 1)
2568 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierType() + 1);
2569 Standard_Real aVal = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2570 StepBasic_Unit anUnit = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2571 if(anUnit.IsNull()) continue;
2572 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2573 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2574 STEPConstruct_UnitContext anUnitCtx;
2575 anUnitCtx.ComputeFactors(NU);
2576 aModifValue = aVal * anUnitCtx.LengthFactor();
2580 Interface_EntityIterator anIterDRE = aGraph.Shareds(aDRE);
2581 for(anIterDRE.Start(); anIterDRE.More(); anIterDRE.Next()) {
2582 if(anIterDRE.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2584 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRE.Value());
2585 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue,theDoc, theWS);
2595 return Standard_True;
2598 //=======================================================================
2599 //function : createGeomTolObjectInXCAF
2601 //=======================================================================
2602 TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
2603 const Handle(TDocStd_Document)& theDoc,
2604 const Handle(XSControl_WorkSession)& theWS)
2607 if(!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
2608 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) &&
2609 !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
2614 Handle(TCollection_HAsciiString) aSemanticName;
2616 // protection against invalid input
2617 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2618 Handle(StepDimTol_GeometricTolerance) aGeomTol = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2619 if (aGeomTol->TolerancedShapeAspect().IsNull())
2621 aSemanticName = aGeomTol->Name();
2623 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2624 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2625 if (aDim->AppliesTo().IsNull())
2627 aSemanticName = aDim->Name();
2629 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2630 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
2631 if (aDim->RelatedShapeAspect().IsNull() || aDim->RelatingShapeAspect().IsNull())
2633 aSemanticName = aDim->Name();
2636 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
2637 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
2638 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2639 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2640 const Interface_Graph& aGraph = aTP->Graph();
2641 Standard_Boolean isAllAround = Standard_False;
2642 Standard_Boolean isAllOver = Standard_False;
2644 // find RepresentationItem for current Ent
2645 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI1, aSeqRI2;
2647 // Collect all Shape_Aspect entities
2648 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2649 for(anIter.Start(); anIter.More(); anIter.Next()) {
2650 Handle(Standard_Transient) anAtr = anIter.Value();
2651 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2652 if(anAtr->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)))
2654 //if associating tolerances with part (All-Over)
2655 Interface_EntityIterator anIterSDR = aGraph.Sharings(anAtr);
2656 for(anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next())
2658 Handle(Standard_Transient) anAtrSDR = anIterSDR.Value();
2659 if(anAtrSDR->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
2661 isAllOver = Standard_True;
2662 Interface_EntityIterator anIterABSR = aGraph.Shareds(anAtrSDR);
2663 for(anIterABSR.Start(); anIterABSR.More(); anIterABSR.Next())
2665 Handle(Standard_Transient) anAtrABSR = anIterABSR.Value();
2666 if(anAtrABSR->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
2668 aSeqRI1.Append(anAtrABSR);
2674 else if(anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
2675 anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
2677 //if tolerance attached to dimension
2678 Interface_EntityIterator anIterDim = aGraph.Shareds(anAtr);
2679 for(anIterDim.Start(); anIterDim.More(); anIterDim.Next())
2681 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anIterDim.Value());
2683 collectShapeAspect(aSA, theWS, aSAs);
2687 else if(anAtr->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
2689 if(anAtr->IsKind(STANDARD_TYPE(StepRepr_AllAroundShapeAspect)))
2691 // if applyed AllAround Modifier
2692 isAllAround = Standard_True;
2694 // dimensions and default tolerances
2695 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anAtr);
2697 collectShapeAspect(aSA, theWS, aSAs);
2701 // Collect all representation items
2704 //get representation items
2705 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI;
2706 for(Standard_Integer i = aSAs.Lower(); i <= aSAs.Upper(); i++)
2708 Interface_EntityIterator anIterSA = aGraph.Sharings(aSAs.Value(i));
2709 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2710 Handle(StepRepr_PropertyDefinition) PropD;
2711 for(anIterSA.Start(); anIterSA.More() && aGISU.IsNull() && PropD.IsNull(); anIterSA.Next()) {
2712 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
2713 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(anIterSA.Value());
2715 if(!PropD.IsNull())//for old version
2717 Handle(StepRepr_RepresentationItem) RI;
2718 Interface_EntityIterator subs4 = aGraph.Sharings(PropD);
2719 for(subs4.Start(); subs4.More(); subs4.Next()) {
2720 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2721 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
2723 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2724 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
2725 RI = Repr->ItemsValue(1);
2729 if(RI.IsNull()) continue;
2731 if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2733 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
2734 if(EC.IsNull()) continue;
2735 Handle(TCollection_HAsciiString) aName;
2736 Handle(StepShape_DimensionalSize) DimSize =
2737 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2738 Standard_Real dim1=-1.,dim2=-1.;
2739 subs4 = aGraph.Sharings(DimSize);
2740 for(subs4.Start(); subs4.More(); subs4.Next()) {
2741 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
2742 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
2743 if(!DimCharR.IsNull()) {
2744 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
2745 if(!SDimR.IsNull() && SDimR->NbItems()>0) {
2746 Handle(StepRepr_RepresentationItem) anItem = SDimR->ItemsValue(1);
2747 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(anItem);
2750 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
2751 //if(CID.IsNull()) continue;
2752 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
2753 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
2754 //if(CIDM.IsNull()) continue;
2755 //if(CIDM->ArrTransient().IsNull()) continue;
2756 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
2757 //if(CID.CaseMem(CIDM)==1)
2758 // HARI = CID.ListRepresentationItem();
2759 //if(CID.CaseMem(CIDM)==2)
2760 // HARI = CID.SetRepresentationItem();
2761 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
2762 if(HARI.IsNull()) continue;
2763 if(HARI->Length()>0) {
2764 Handle(StepRepr_RepresentationItem) RI1 = HARI->Value(1);
2765 if(RI1.IsNull()) continue;
2766 if(RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2767 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2768 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
2769 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2770 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2771 if(anUnit.IsNull()) continue;
2772 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2773 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2774 STEPConstruct_UnitContext anUnitCtx;
2775 anUnitCtx.ComputeFactors(NU);
2776 dim1 = dim1 * anUnitCtx.LengthFactor();
2779 if(HARI->Length()>1) {
2780 Handle(StepRepr_RepresentationItem) RI2 = HARI->Value(2);
2781 if(RI2.IsNull()) continue;
2782 if(RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2783 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2784 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
2785 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2786 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2787 if(anUnit.IsNull()) continue;
2788 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2789 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2790 STEPConstruct_UnitContext anUnitCtx;
2791 anUnitCtx.ComputeFactors(NU);
2792 dim2 = dim2 * anUnitCtx.LengthFactor();
2799 if(dim1<0) continue;
2800 if(dim2<0) dim2=dim1;
2801 //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl;
2802 // now we know edge_curve and value range therefore
2803 // we can create corresponding D> labels
2804 Standard_Integer index = aTP->MapIndex(EC);
2807 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2808 aSh = TransferBRep::ShapeResult(binder);
2810 if(aSh.IsNull()) continue;
2812 if( !aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2813 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,2);
2814 arr->SetValue(1,dim1);
2815 arr->SetValue(2,dim2);
2816 aDGTTool->SetDimTol(shL,1,arr,aName,DimSize->Name());
2818 // read tolerances and datums
2819 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2820 Handle(StepDimTol_GeometricTolerance) GT =
2821 Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2822 // read common data for tolerance
2823 //Standard_Real dim = GT->Magnitude()->ValueComponent();
2824 Handle (StepBasic_MeasureWithUnit) dim3 = GT->Magnitude();
2825 if(dim3.IsNull()) continue;
2826 Standard_Real dim = dim3->ValueComponent();
2827 StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent();
2828 if(anUnit.IsNull()) continue;
2829 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2830 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2831 STEPConstruct_UnitContext anUnitCtx;
2832 anUnitCtx.ComputeFactors(NU);
2833 dim = dim * anUnitCtx.LengthFactor();
2834 //cout<<"GeometricTolerance: Magnitude = "<<dim<<endl;
2835 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,1);
2836 arr->SetValue(1,dim);
2837 Handle(TCollection_HAsciiString) aName = GT->Name();
2838 Handle(TCollection_HAsciiString) aDescription = GT->Description();
2839 Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2840 if(AF.IsNull()) continue;
2841 Standard_Integer index = aTP->MapIndex(AF);
2844 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2845 aSh = TransferBRep::ShapeResult(binder);
2847 if(aSh.IsNull()) continue;
2849 if( !aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2850 // read specific data for tolerance
2851 if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) {
2852 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
2853 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(theEnt);
2854 Standard_Integer kind=20;
2855 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2856 GTComplex->GetModifiedGeometricTolerance();
2858 kind = kind + MGT->Modifier()+1;
2860 TDF_Label TolerL = aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
2861 // translate datums connected with this tolerance
2862 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2863 GTComplex->GetGeometricToleranceWithDatumReference();
2864 if(!GTWDR.IsNull()) {
2865 ReadDatums(aSTool,aDGTTool,aGraph,aTP,TolerL,GTWDR);
2868 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) {
2869 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2870 Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(theEnt);
2871 if(GTWDR.IsNull()) continue;
2872 Standard_Integer kind = 0;
2873 if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24;
2874 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25;
2875 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26;
2876 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27;
2877 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28;
2878 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29;
2879 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30;
2880 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31;
2881 //cout<<"GTWDR: kind="<<kind<<endl;
2882 TDF_Label TolerL = aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
2883 ReadDatums(aSTool,aDGTTool,aGraph,aTP,TolerL,GTWDR);
2885 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) {
2886 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2887 Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(theEnt);
2888 Standard_Integer kind = 35 + MGT->Modifier();
2889 aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
2891 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) {
2892 aDGTTool->SetDimTol(shL,38,arr,aName,aDescription);
2894 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) {
2895 aDGTTool->SetDimTol(shL,39,arr,aName,aDescription);
2897 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) {
2898 aDGTTool->SetDimTol(shL,40,arr,aName,aDescription);
2900 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) {
2901 aDGTTool->SetDimTol(shL,41,arr,aName,aDescription);
2903 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) {
2904 aDGTTool->SetDimTol(shL,42,arr,aName,aDescription);
2906 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) {
2907 aDGTTool->SetDimTol(shL,43,arr,aName,aDescription);
2909 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) {
2910 aDGTTool->SetDimTol(shL,44,arr,aName,aDescription);
2916 if(aGISU.IsNull()) continue;
2917 Standard_Integer j =1;
2918 for ( ; j <= aGISU->NbIdentifiedItem(); j++) {
2919 aSeqRI.Append(aGISU->IdentifiedItemValue(j));
2923 if(!aSeqRI.IsEmpty())
2925 if(aSeqRI1.IsEmpty())
2932 if(aSeqRI1.IsEmpty())
2935 TDF_LabelSequence aShLS1, aShLS2;
2938 for(Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper() ;i++)
2940 Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS);
2943 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
2944 aSh = TransferBRep::ShapeResult(aBinder);
2949 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
2950 if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
2952 TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
2956 aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
2957 if (!edgeL.IsNull())
2958 aShLS1.Append(edgeL);
2963 aShLS1.Append(aShL);
2966 if (!aSeqRI2.IsEmpty())
2968 //for dimensional location
2969 for(Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper() ;i++)
2971 Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI2.Value(i), theWS);
2974 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
2975 aSh = TransferBRep::ShapeResult(aBinder);
2980 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
2981 if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
2983 TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
2987 aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
2988 if (!edgeL.IsNull())
2989 aShLS2.Append(edgeL);
2994 aShLS2.Append(aShL);
2999 if(!aShLS1.IsEmpty())
3002 if(!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
3004 aGDTL = aDGTTool->AddDimension();
3005 myGDTMap.Bind(theEnt, aGDTL);
3006 aDGTTool->Lock(aGDTL);
3007 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
3008 TCollection_AsciiString aStr("DGT:Dimensional_");
3009 if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
3011 aStr.AssignCat("Size");
3013 else if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
3015 aStr.AssignCat("Location");
3017 TDataStd_Name::Set(aGDTL, aStr);
3019 if(!aShLS2.IsEmpty())
3021 aDGTTool->SetDimension(aShLS1, aShLS2, aGDTL);
3025 TDF_LabelSequence aEmptySeq;
3026 aDGTTool->SetDimension(aShLS1, aEmptySeq, aGDTL);
3031 aGDTL = aDGTTool->AddGeomTolerance();
3032 myGDTMap.Bind(theEnt, aGDTL);
3033 aDGTTool->Lock(aGDTL);
3034 Handle(XCAFDoc_GeomTolerance) aGTol = XCAFDoc_GeomTolerance::Set(aGDTL);
3035 TCollection_AsciiString aStr("DGT:GeomTolerance");
3036 TDataStd_Name::Set(aGDTL, aStr);
3037 aDGTTool->SetGeomTolerance(aShLS1, aGDTL);
3038 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGTol->GetObject();
3040 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Around);
3042 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Over);
3043 aGTol->SetObject(anObj);
3048 TCollection_ExtendedString str(aSemanticName->String());
3049 TDataStd_Name::Set(aGDTL, str);
3052 readDatumsAP242(theEnt, aGDTL, theDoc, theWS);
3057 //=======================================================================
3058 //function : convertAngleValue
3059 //purpose : auxilary
3060 //=======================================================================
3061 void convertAngleValue(
3062 const STEPConstruct_UnitContext& anUnitCtx,
3063 Standard_Real& aVal)
3065 // convert radian to deg
3066 Standard_Real aFact = anUnitCtx.PlaneAngleFactor() * 180 / M_PI;
3067 // in order to avoid inaccuracy of calculation perform conversion
3068 // only if aFact not eqaul 1 with some precision
3069 if (fabs(1. - aFact) > Precision::Confusion())
3071 aVal = aVal * aFact;
3076 //=======================================================================
3077 //function : setDimObjectToXCAF
3079 //=======================================================================
3080 static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3081 const TDF_Label& aDimL,
3082 const Handle(TDocStd_Document)& theDoc,
3083 const Handle(XSControl_WorkSession)& theWS)
3085 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
3086 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
3087 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3088 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
3089 const Interface_Graph& aGraph = aTP->Graph();
3090 Handle(XCAFDimTolObjects_DimensionObject) aDimObj;
3091 if(!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
3092 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
3095 Handle(StepShape_DimensionalSize) aDimSize =
3096 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
3097 Handle(StepShape_DimensionalLocation) aDimLocation =
3098 Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
3100 aDimObj = new XCAFDimTolObjects_DimensionObject();
3101 Standard_Real aDim1=-1.,aDim2=-1.,aDim3=-1.;
3102 Standard_Boolean isPlusMinusTolerance = Standard_False;
3103 Handle(StepShape_TypeQualifier) aTQ;
3104 Handle(StepShape_ValueFormatTypeQualifier) aVFTQ;
3105 Handle(StepShape_ToleranceValue) aTV;
3106 Handle(StepShape_LimitsAndFits) aLAF;
3107 Handle(StepRepr_CompoundRepresentationItem) aCRI;
3108 Handle(StepGeom_Axis2Placement3d) anAP;
3110 Interface_EntityIterator anIterDim;
3111 if(!aDimSize.IsNull())
3113 anIterDim = aGraph.Sharings(aDimSize);
3117 anIterDim = aGraph.Sharings(aDimLocation);
3119 for(anIterDim.Start(); anIterDim.More(); anIterDim.Next()) {
3120 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
3121 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anIterDim.Value());
3122 Handle(StepShape_PlusMinusTolerance) aPMT =
3123 Handle(StepShape_PlusMinusTolerance)::DownCast(anIterDim.Value());
3124 if(!aDCR.IsNull()) {
3125 Handle(StepShape_ShapeDimensionRepresentation) aSDR = aDCR->Representation();
3126 if(!aSDR.IsNull()) {
3127 Handle(StepRepr_HArray1OfRepresentationItem) aHARI = aSDR->Items();
3131 for(Standard_Integer nr = aHARI->Lower(); nr <= aHARI->Upper(); nr++)
3133 Handle(StepRepr_RepresentationItem) aDRI = aHARI->Value(nr);
3134 if(aDRI.IsNull()) continue;
3136 if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))) {
3137 // simple value / range
3138 Handle(StepRepr_ReprItemAndMeasureWithUnit) aMWU =
3139 Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aDRI);
3140 Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
3141 StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
3142 if (anUnit.IsNull())
3144 if (!(anUnit.CaseNum(anUnit.Value()) == 1))
3146 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3147 STEPConstruct_UnitContext anUnitCtx;
3148 anUnitCtx.ComputeFactors(NU);
3149 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
3150 aVal = aVal * anUnitCtx.LengthFactor();
3153 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit))) {
3154 convertAngleValue(anUnitCtx, aVal);
3156 Handle(TCollection_HAsciiString) aName = aMWU->Name();
3157 if (aName->Search("upper") > 0) // upper limit
3159 else // lower limit or simple nominal value
3162 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnitAndQRI))) {
3163 // value with qualifier (minimum/maximum/average)
3164 Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI) aMWU =
3165 Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI)::DownCast(aDRI);
3166 Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
3167 StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
3170 if( !(anUnit.CaseNum(anUnit.Value()) == 1) )
3172 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3173 STEPConstruct_UnitContext anUnitCtx;
3174 anUnitCtx.ComputeFactors(NU);
3175 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI))) {
3176 aVal = aVal * anUnitCtx.LengthFactor();
3179 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI))) {
3180 convertAngleValue(anUnitCtx, aVal);
3182 Handle(StepShape_QualifiedRepresentationItem) aQRI = aMWU->GetQualifiedRepresentationItem();
3183 if (aQRI->Qualifiers()->Length() == 0) {
3187 Handle(StepShape_TypeQualifier) aValueType = aQRI->Qualifiers()->Value(1).TypeQualifier();
3188 if (aValueType->Name()->String().IsEqual("minimum"))
3190 else if (aValueType->Name()->String().IsEqual("maximum"))
3194 else if(aDRI->IsKind(STANDARD_TYPE(StepShape_QualifiedRepresentationItem))) {
3196 Handle(StepShape_QualifiedRepresentationItem) aQRI =
3197 Handle(StepShape_QualifiedRepresentationItem)::DownCast(aDRI);
3198 for(Standard_Integer l = 1; l <= aQRI->NbQualifiers(); l++)
3200 aTQ = aQRI->Qualifiers()->Value(l).TypeQualifier();
3201 aVFTQ = aQRI->Qualifiers()->Value(l).ValueFormatTypeQualifier();
3204 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
3205 Handle(StepRepr_DescriptiveRepresentationItem) aDescription =
3206 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aDRI);
3207 aDimObj->AddDescription(aDescription->Description(), aDescription->Name());
3209 else if(aDRI->IsKind(STANDARD_TYPE(StepRepr_CompoundRepresentationItem))) {
3210 aCRI = Handle(StepRepr_CompoundRepresentationItem)::DownCast(aDRI);
3212 else if(aDRI->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
3214 anAP = Handle(StepGeom_Axis2Placement3d)::DownCast(aDRI);
3220 else if (!aPMT.IsNull())
3222 isPlusMinusTolerance = Standard_True;
3223 StepShape_ToleranceMethodDefinition aTMD = aPMT->Range();
3224 if(aPMT.IsNull()) continue;
3225 if(aTMD.CaseNumber() == 1)
3226 //! 1 -> ToleranceValue from StepShape
3227 //! 2 -> LimitsAndFits from StepShape
3229 //plus minus tolerance
3230 aTV = aTMD.ToleranceValue();
3231 if (aTV.IsNull()) continue;
3233 Handle(StepBasic_MeasureWithUnit) aMWU = aTV->UpperBound();
3234 Standard_Real aVal = aTV->UpperBound()->ValueComponent();
3235 StepBasic_Unit anUnit = aTV->UpperBound()->UnitComponent();
3236 if(anUnit.IsNull()) continue;
3237 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
3238 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3239 STEPConstruct_UnitContext anUnitCtx;
3240 anUnitCtx.ComputeFactors(NU);
3241 if (aMWU->IsKind(STANDARD_TYPE(StepBasic_LengthMeasureWithUnit)) ||
3242 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI)))
3244 aVal = aVal * anUnitCtx.LengthFactor();
3246 else if (aMWU->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) ||
3247 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI)))
3249 convertAngleValue(anUnitCtx, aVal);
3253 aMWU = aTV->LowerBound();
3254 aVal = aTV->LowerBound()->ValueComponent();
3255 anUnit = aTV->LowerBound()->UnitComponent();
3256 if(anUnit.IsNull()) continue;
3257 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
3258 NU = anUnit.NamedUnit();
3259 anUnitCtx.ComputeFactors(NU);
3260 if (aMWU->IsKind(STANDARD_TYPE(StepBasic_LengthMeasureWithUnit)) ||
3261 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI)))
3263 aVal = aVal * anUnitCtx.LengthFactor();
3265 else if (aMWU->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) ||
3266 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI)))
3268 convertAngleValue(anUnitCtx, aVal);
3274 // class of tolerance
3275 aLAF = aTMD.LimitsAndFits();
3283 aDimObj->SetValue(aDim1);
3286 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,2);
3287 anArr->SetValue(1,aDim1);
3288 anArr->SetValue(2,aDim2);
3289 aDimObj->SetValues(anArr);
3293 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,3);
3294 if (!isPlusMinusTolerance)
3296 aDim2 = aDim1 - aDim2;
3297 aDim3 = aDim3 - aDim1;
3299 anArr->SetValue(1,aDim1);
3300 anArr->SetValue(2,aDim2);
3301 anArr->SetValue(3,aDim3);
3302 aDimObj->SetValues(anArr);
3306 XCAFDimTolObjects_DimensionQualifier aQ;
3307 if (STEPCAFControl_GDTProperty::GetDimQualifierType(aTQ->Name(), aQ))
3309 aDimObj->SetQualifier(aQ);
3313 if (!aVFTQ.IsNull())
3315 //A typical value would be 'NR2 2.2'
3316 TCollection_HAsciiString aFormat = aVFTQ->FormatType();
3317 Standard_Integer i = aFormat.Location(1,' ',1,aFormat.Length());
3318 aFormat.SubString(i+1,i+1)->IntegerValue();
3319 aDimObj->SetNbOfDecimalPlaces(aFormat.SubString(i+1,i+1)->IntegerValue(),
3320 aFormat.SubString(i+3,i+3)->IntegerValue());
3325 //get class of tolerance
3326 Standard_Boolean aHolle = Standard_False;
3327 XCAFDimTolObjects_DimensionFormVariance aFV = XCAFDimTolObjects_DimensionFormVariance_None;
3328 XCAFDimTolObjects_DimensionGrade aG = XCAFDimTolObjects_DimensionGrade_IT01;
3329 STEPCAFControl_GDTProperty::GetDimClassOfTolerance(aLAF, aHolle, aFV, aG);
3330 aDimObj->SetClassOfTolerance(aHolle, aFV, aG);
3333 if (!aCRI.IsNull() && !aCRI->ItemElement().IsNull() && aCRI->ItemElement()->Length() > 0)
3336 XCAFDimTolObjects_DimensionModifiersSequence aModifiers;
3337 STEPCAFControl_GDTProperty::GetDimModifiers(aCRI, aModifiers);
3338 if(aModifiers.Length() > 0)
3339 aDimObj->SetModifiers(aModifiers);
3342 Handle(TCollection_HAsciiString) aName;
3343 if(!aDimSize.IsNull())
3345 aName = aDimSize->Name();
3349 aName = aDimLocation->Name();
3351 XCAFDimTolObjects_DimensionType aType = XCAFDimTolObjects_DimensionType_Location_None;
3352 if (!STEPCAFControl_GDTProperty::GetDimType(aName, aType))
3354 if(!aDimSize.IsNull())
3356 Handle(StepShape_AngularSize) anAngSize=
3357 Handle(StepShape_AngularSize)::DownCast(aDimSize);
3358 if(!anAngSize.IsNull())
3360 //get qualifier for angular value
3361 aType = XCAFDimTolObjects_DimensionType_Size_Angular;
3362 if(anAngSize->AngleSelection() == StepShape_Equal)
3363 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg);
3364 else if (anAngSize->AngleSelection() == StepShape_Large)
3365 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max);
3366 else if (anAngSize->AngleSelection() == StepShape_Small)
3367 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min);
3372 Handle(StepShape_AngularLocation) anAngLoc=
3373 Handle(StepShape_AngularLocation)::DownCast(aDimLocation);
3374 if(!anAngLoc.IsNull())
3376 //get qualifier for angular value
3377 aType = XCAFDimTolObjects_DimensionType_Location_Angular;
3378 if(anAngLoc->AngleSelection() == StepShape_Equal)
3379 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg);
3380 else if (anAngLoc->AngleSelection() == StepShape_Large)
3381 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max);
3382 else if (anAngLoc->AngleSelection() == StepShape_Small)
3383 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min);
3386 if(aType == XCAFDimTolObjects_DimensionType_Location_None)
3388 Handle(StepRepr_ShapeAspect) aPSA;
3389 if(!aDimSize.IsNull())
3391 Handle(StepShape_DimensionalSizeWithPath) aDimSizeWithPath=
3392 Handle(StepShape_DimensionalSizeWithPath)::DownCast(aDimSize);
3393 if (!aDimSizeWithPath.IsNull())
3395 aType = XCAFDimTolObjects_DimensionType_Size_WithPath;
3396 aPSA = aDimSizeWithPath->Path();
3401 Handle(StepShape_DimensionalLocationWithPath) aDimLocWithPath=
3402 Handle(StepShape_DimensionalLocationWithPath)::DownCast(aDimLocation);
3403 if (!aDimLocWithPath.IsNull())
3405 aType = XCAFDimTolObjects_DimensionType_Location_WithPath;
3406 aPSA = aDimLocWithPath->Path();
3412 //for DimensionalLocationWithPath
3413 Handle(StepGeom_GeometricRepresentationItem) aGRI;
3414 Handle(StepAP242_GeometricItemSpecificUsage) aPGISU;
3415 Interface_EntityIterator anIterDSWP = aGraph.Sharings(aPSA);
3416 for(anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
3417 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
3419 if(aPGISU.IsNull()) return;
3420 if(aPGISU->NbIdentifiedItem() > 0) {
3421 aGRI = Handle(StepGeom_GeometricRepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(1));
3423 if(aGRI.IsNull()) return;
3424 Handle(StepRepr_RepresentationItem) aPRI;
3425 Interface_EntityIterator anIterGRI = aGraph.Sharings(aGRI);
3426 for(anIterGRI.Start(); anIterGRI.More() && aPGISU.IsNull(); anIterGRI.Next()) {
3427 aPRI = Handle(StepRepr_RepresentationItem)::DownCast(anIterGRI.Value());
3429 Standard_Integer anIndex = FindShapeIndexForDGT(aPRI, theWS);
3432 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3433 aSh = TopoDS::Edge(TransferBRep::ShapeResult(aBinder));
3435 if(aSh.IsNull()) return;
3436 aDimObj->SetPath(aSh);
3438 else if(!anAP.IsNull())
3440 if(anAP->Name()->String().IsEqual("orientation") && !anAP->Axis().IsNull())
3442 //for Oriented Dimensional Location
3443 Handle(TColStd_HArray1OfReal) aDirArr = anAP->RefDirection()->DirectionRatios();
3445 if(!aDirArr.IsNull() && aDirArr->Length() > 2)
3447 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, aDirArr->Lower()+2);
3448 aDimObj->SetDirection(aDir);
3450 else if(aDirArr->Length() > 1)
3452 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, 0);
3453 aDimObj->SetDirection(aDir);
3459 aDimObj->SetType(aType);
3462 if(!aDimObj.IsNull())
3465 Handle(XCAFDoc_Dimension) aDim;
3467 if(aDimL.FindAttribute(XCAFDoc_Dimension::GetID(),aDim))
3469 readAnnotation(aTR, theEnt, aDimObj);
3470 readConnectionPoints(aTR, theEnt, aDimObj);
3471 aDim->SetObject(aDimObj);
3476 //=======================================================================
3477 //function : getTolType
3479 //=======================================================================
3480 static Standard_Boolean getTolType(const Handle(Standard_Transient)& theEnt,
3481 XCAFDimTolObjects_GeomToleranceType& theType)
3483 if(theEnt.IsNull() || !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
3484 return Standard_False;
3485 theType = XCAFDimTolObjects_GeomToleranceType_None;
3486 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRef)))
3488 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) anE = Handle(StepDimTol_GeoTolAndGeoTolWthDatRef)::DownCast(theEnt);
3489 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3491 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3493 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) anE =
3494 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(theEnt);
3495 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3497 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
3499 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) anE =
3500 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)::DownCast(theEnt);
3501 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3503 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3505 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) anE =
3506 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(theEnt);
3507 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3509 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
3511 Handle(StepDimTol_GeoTolAndGeoTolWthMod) anE =
3512 Handle(StepDimTol_GeoTolAndGeoTolWthMod)::DownCast(theEnt);
3513 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3515 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)))
3517 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol) anE =
3518 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)::DownCast(theEnt);
3519 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3521 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance)))
3523 theType = XCAFDimTolObjects_GeomToleranceType_Angularity;
3525 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance)))
3527 theType = XCAFDimTolObjects_GeomToleranceType_CircularRunout;
3529 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance)))
3531 theType = XCAFDimTolObjects_GeomToleranceType_CircularityOrRoundness;
3533 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance)))
3535 theType = XCAFDimTolObjects_GeomToleranceType_Coaxiality;
3537 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance)))
3539 theType = XCAFDimTolObjects_GeomToleranceType_Concentricity;
3541 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance)))
3543 theType = XCAFDimTolObjects_GeomToleranceType_Cylindricity;
3545 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance)))
3547 theType = XCAFDimTolObjects_GeomToleranceType_Flatness;
3549 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance)))
3551 theType = XCAFDimTolObjects_GeomToleranceType_Parallelism;
3553 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance)))
3555 theType = XCAFDimTolObjects_GeomToleranceType_Perpendicularity;
3557 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance)) ||
3558 theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)))
3560 theType = XCAFDimTolObjects_GeomToleranceType_Position;
3562 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance)))
3564 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfLine;
3566 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance)))
3568 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfSurface;
3570 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance)))
3572 theType = XCAFDimTolObjects_GeomToleranceType_Straightness;
3574 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance)))
3576 theType = XCAFDimTolObjects_GeomToleranceType_Symmetry;
3578 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance)))
3580 theType = XCAFDimTolObjects_GeomToleranceType_TotalRunout;
3582 return Standard_True;
3584 //=======================================================================
3585 //function : setGeomTolObjectToXCAF
3587 //=======================================================================
3588 static void setGeomTolObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3589 const TDF_Label& theTolL,
3590 const Handle(TDocStd_Document)& theDoc,
3591 const Handle(XSControl_WorkSession)& theWS)
3593 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
3594 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
3595 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3596 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
3597 const Interface_Graph& aGraph = aTP->Graph();
3598 Handle(XCAFDoc_GeomTolerance) aGTol;
3599 if(!theTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTol))
3603 Handle(XCAFDimTolObjects_GeomToleranceObject) aTolObj = aGTol->GetObject();
3604 Handle(StepDimTol_GeometricTolerance) aTolEnt = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
3606 XCAFDimTolObjects_GeomToleranceType aType = XCAFDimTolObjects_GeomToleranceType_None;
3607 getTolType(theEnt, aType);
3608 aTolObj->SetType(aType);
3609 if(!aTolEnt->Magnitude().IsNull()){
3611 Standard_Real aVal = aTolEnt->Magnitude()->ValueComponent();
3612 StepBasic_Unit anUnit = aTolEnt->Magnitude()->UnitComponent();
3613 if(anUnit.IsNull()) return;
3614 if( !(anUnit.CaseNum(anUnit.Value())==1) ) return;
3615 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3616 STEPConstruct_UnitContext anUnitCtx;
3617 anUnitCtx.ComputeFactors(NU);
3618 aVal = aVal * anUnitCtx.LengthFactor();
3619 aTolObj->SetValue(aVal);
3622 XCAFDimTolObjects_GeomToleranceTypeValue aTypeV = XCAFDimTolObjects_GeomToleranceTypeValue_None;
3623 Interface_EntityIterator anIter = aGraph.Sharings(aTolEnt);
3624 for(anIter.Start(); anIter.More(); anIter.Next()) {
3625 if(anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_ToleranceZone))){
3626 Handle(StepDimTol_ToleranceZoneForm) aForm
3627 = Handle(StepDimTol_ToleranceZone)::DownCast(anIter.Value())->Form();
3628 STEPCAFControl_GDTProperty::GetTolValueType(aForm->Name(), aTypeV);
3629 Interface_EntityIterator anIt = aGraph.Sharings(anIter.Value());
3630 for(anIt.Start(); anIt.More(); anIt.Next()) {
3631 if(anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_ProjectedZoneDefinition))){
3632 Handle(StepDimTol_ProjectedZoneDefinition) aPZone
3633 = Handle(StepDimTol_ProjectedZoneDefinition)::DownCast(anIt.Value());
3634 if(!aPZone->ProjectionLength().IsNull())
3636 Standard_Real aVal = aPZone->ProjectionLength()->ValueComponent();
3637 StepBasic_Unit anUnit = aPZone->ProjectionLength()->UnitComponent();
3638 if(anUnit.IsNull()) return;
3639 if( !(anUnit.CaseNum(anUnit.Value())==1) ) return;
3640 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3641 STEPConstruct_UnitContext anUnitCtx;
3642 anUnitCtx.ComputeFactors(NU);
3643 aVal = aVal * anUnitCtx.LengthFactor();
3644 aTolObj->SetValueOfZoneModifier(aVal);
3645 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Projected);
3648 else if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_RunoutZoneDefinition)))
3650 Handle(StepDimTol_RunoutZoneDefinition) aRZone
3651 = Handle(StepDimTol_RunoutZoneDefinition)::DownCast(anIt.Value());
3652 if(!aRZone->Orientation().IsNull())
3654 Standard_Real aVal = aRZone->Orientation()->Angle()->ValueComponent();
3655 StepBasic_Unit anUnit = aRZone->Orientation()->Angle()->UnitComponent();
3656 if(anUnit.IsNull()) continue;
3657 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
3658 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3659 STEPConstruct_UnitContext anUnitCtx;
3660 anUnitCtx.ComputeFactors(NU);
3661 convertAngleValue(anUnitCtx, aVal);
3662 aTolObj->SetValueOfZoneModifier(aVal);
3663 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Runout);
3667 aTolObj->SetTypeOfValue(aTypeV);
3670 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifiers;
3671 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithModifiers)))
3673 aModifiers = Handle(StepDimTol_GeometricToleranceWithModifiers)::DownCast(aTolEnt)->Modifiers();
3675 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
3677 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)
3678 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3680 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
3682 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMod)
3683 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3685 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3687 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)
3688 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3690 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3692 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)
3693 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3695 if(!aModifiers.IsNull())
3697 for(Standard_Integer i = aModifiers->Lower(); i <= aModifiers->Upper(); i++)
3699 if(aModifiers->Value(i) == StepDimTol_GTMLeastMaterialRequirement)
3700 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_L);
3701 else if (aModifiers->Value(i) == StepDimTol_GTMMaximumMaterialRequirement)
3702 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_M);
3704 aTolObj->AddModifier((XCAFDimTolObjects_GeomToleranceModif)aModifiers->Value(i));
3707 Standard_Real aVal = 0;
3708 StepBasic_Unit anUnit;
3709 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithMaximumTolerance)))
3711 Handle(StepDimTol_GeometricToleranceWithMaximumTolerance) aMax = Handle(StepDimTol_GeometricToleranceWithMaximumTolerance)::DownCast(aTolEnt);
3712 aVal = aMax->MaximumUpperTolerance()->ValueComponent();
3713 anUnit = aMax->MaximumUpperTolerance()->UnitComponent();
3715 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3717 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aMax =
3718 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(aTolEnt);
3719 aVal = aMax->GetMaxTolerance()->ValueComponent();
3720 anUnit = aMax->GetMaxTolerance()->UnitComponent();
3722 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3724 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aMax =
3725 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(aTolEnt);
3726 aVal = aMax->GetMaxTolerance()->ValueComponent();
3727 anUnit = aMax->GetMaxTolerance()->UnitComponent();
3729 if (!anUnit.IsNull() && (anUnit.CaseNum(anUnit.Value()) == 1))
3731 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3732 STEPConstruct_UnitContext anUnitCtx;
3733 anUnitCtx.ComputeFactors(NU);
3734 convertAngleValue(anUnitCtx, aVal);
3735 aTolObj->SetMaxValueModifier(aVal);
3738 readAnnotation(aTR, theEnt, aTolObj);
3739 aGTol->SetObject(aTolObj);
3742 //=======================================================================
3743 //function : ReadGDTs
3745 //=======================================================================
3747 Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession)& theWS,
3748 Handle(TDocStd_Document)& theDoc)
3750 const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
3751 const Interface_Graph& aGraph = theWS->Graph();
3752 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3753 Handle(StepData_StepModel) aSM = Handle(StepData_StepModel)::DownCast(aModel);
3754 Interface_EntityIterator anI = aSM->Header();
3755 Handle(HeaderSection_FileSchema) aH;
3756 for(anI.Start(); anI.More() && aH.IsNull();anI.Next())
3757 aH = Handle(HeaderSection_FileSchema)::DownCast(anI.Value());
3758 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
3759 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
3760 if ( aDGTTool.IsNull() ) return Standard_False;
3762 Standard_Integer nb = aModel->NbEntities();
3763 for(Standard_Integer i=1; i<=nb; i++) {
3764 Handle(Standard_Transient) anEnt = aModel->Value(i);
3765 if(anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3766 anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3767 anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3768 TDF_Label aGDTL = createGDTObjectInXCAF(anEnt,theDoc,theWS);
3769 if(!aGDTL.IsNull()){
3770 if(anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))){
3771 setGeomTolObjectToXCAF(anEnt, aGDTL,theDoc,theWS);
3774 setDimObjectToXCAF(anEnt, aGDTL,theDoc,theWS);
3778 else if (anEnt->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)) ||
3779 anEnt->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
3781 // Protection against import presentation twice
3782 Handle(StepVisual_DraughtingCallout) aDC;
3783 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDC.IsNull(); anIter.Next()) {
3784 aDC = Handle(StepVisual_DraughtingCallout)::DownCast(anIter.Value());
3788 // Read presentations for PMIs without semantic data.
3789 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
3790 TDF_LabelSequence aShapesL;
3791 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDMIA.IsNull(); anIter.Next()) {
3792 aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(anIter.Value());
3794 if (!aDMIA.IsNull()) {
3795 // Check entity, skip all, attached to GDTs
3796 Handle(StepRepr_ShapeAspect) aDefinition = aDMIA->Definition().ShapeAspect();
3797 if (!aDefinition.IsNull()) {
3798 Standard_Boolean isConnectedToGDT = Standard_False;
3799 // Skip if definition is a datum
3800 if (aDefinition->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
3801 aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
3802 aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
3803 aDefinition->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
3804 isConnectedToGDT = Standard_True;
3806 // Skip if any GDT is applied to definition
3807 for (Interface_EntityIterator anIter = aGraph.Sharings(aDefinition); anIter.More() && !isConnectedToGDT; anIter.Next()) {
3808 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3809 anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3810 anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3811 isConnectedToGDT = Standard_True;
3814 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
3815 if (!aSAR.IsNull()) {
3816 Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatedShapeAspect();
3817 if (!aSA.IsNull()) {
3818 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
3819 aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
3820 aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
3821 aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
3822 isConnectedToGDT = Standard_True;
3824 for (Interface_EntityIterator aDimIter = aGraph.Sharings(aSA); aDimIter.More() && !isConnectedToGDT; aDimIter.Next()) {
3825 if (aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3826 aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3827 aDimIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3828 isConnectedToGDT = Standard_True;
3835 if (isConnectedToGDT)
3838 else if (aDMIA->Definition().PropertyDefinition().IsNull())
3842 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
3843 collectShapeAspect(aDefinition, theWS, aSAs);
3844 for (Standard_Integer aSAIt = 1; aSAIt <= aSAs.Length(); aSAIt++) {
3845 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
3846 for (Interface_EntityIterator anIter = aGraph.Sharings(aSAs.Value(aSAIt)); anIter.More() && aGISU.IsNull(); anIter.Next())
3847 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
3850 for (Standard_Integer anItemIt = 1; anItemIt <= aGISU->NbIdentifiedItem(); anItemIt++) {
3851 TDF_Label aLabel = getShapeLabel(aGISU->IdentifiedItemValue(anItemIt), theWS, XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()));
3852 if (!aLabel.IsNull())
3853 aShapesL.Append(aLabel);
3857 Standard_Boolean isCommonLabel = (aShapesL.Length() == 0);
3860 Standard_Real aFact = 1.0;
3861 if (!aDMIA.IsNull())
3863 XSAlgo::AlgoContainer()->PrepareForTransfer();
3864 STEPControl_ActorRead anActor;
3865 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
3866 anActor.PrepareUnits(aDMIA->UsedRepresentation(), aTP);
3867 aFact = UnitsMethods::LengthFactor();
3871 TopoDS_Shape aPresentation;
3872 Handle(TCollection_HAsciiString) aPresentName;
3874 if (!readPMIPresentation(anEnt, aTR, aFact, aPresentation, aPresentName, aBox))
3877 Handle(StepVisual_AnnotationPlane) anAnPlane;
3878 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && anAnPlane.IsNull(); anIter.Next())
3879 anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
3881 // Set object to XCAF
3882 TDF_Label aGDTL = aDGTTool->AddDimension();
3883 myGDTMap.Bind(anEnt, aGDTL);
3884 aDGTTool->Lock(aGDTL);
3885 Handle(XCAFDimTolObjects_DimensionObject) aDimObj = new XCAFDimTolObjects_DimensionObject();
3886 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
3887 TCollection_AsciiString aStr("DGT:");
3888 if (isCommonLabel) {
3889 aStr.AssignCat("Common_label");
3890 aDimObj->SetType(XCAFDimTolObjects_DimensionType_CommonLabel);
3893 aStr.AssignCat("Dimension");
3894 aDimObj->SetType(XCAFDimTolObjects_DimensionType_DimensionPresentation);
3896 TDataStd_Name::Set(aGDTL, aStr);
3897 TDF_LabelSequence anEmptySeq2;
3898 aDGTTool->SetDimension(aShapesL, anEmptySeq2, aGDTL);
3900 if (!anAnPlane.IsNull()) {
3901 if (readAnnotationPlane(anAnPlane, aPlaneAxes))
3902 aDimObj->SetPlane(aPlaneAxes);
3904 aDimObj->SetPresentation(aPresentation, aPresentName);
3905 aDim->SetObject(aDimObj);
3908 return Standard_True;
3912 //=======================================================================
3913 //function : FindSolidForPDS
3914 //purpose : auxilary
3915 //=======================================================================
3917 static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS,
3918 const Interface_Graph &graph)
3920 Handle(StepShape_SolidModel) SM;
3921 Interface_EntityIterator subs = graph.Sharings(PDS);
3922 Handle(StepShape_ShapeRepresentation) SR;
3923 for(subs.Start(); subs.More() && SM.IsNull(); subs.Next()) {
3924 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
3925 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
3926 if(SDR.IsNull()) continue;
3927 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
3928 if(SR.IsNull()) continue;
3929 for(Standard_Integer i=1; i<=SR->NbItems() && SM.IsNull(); i++) {
3930 SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i));
3933 Interface_EntityIterator subs1 = graph.Sharings(SR);
3934 for(subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) {
3935 Handle(StepRepr_RepresentationRelationship) RR =
3936 Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value());
3937 if(RR.IsNull()) continue;
3938 Handle(StepShape_ShapeRepresentation) SR2;
3939 if(RR->Rep1()==SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2());
3940 else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1());
3941 if(SR2.IsNull()) continue;
3942 for(Standard_Integer i2=1; i2<=SR2->NbItems() && SM.IsNull(); i2++) {
3943 SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2));
3952 //=======================================================================
3953 //function : ReadMaterials
3955 //=======================================================================
3957 Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS,
3958 Handle(TDocStd_Document)& Doc,
3959 const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const
3961 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
3962 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
3963 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
3964 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( Doc->Main() );
3965 if(MatTool.IsNull()) return Standard_False;
3967 const Interface_Graph& graph = TP->Graph();
3968 for(Standard_Integer i=1; i<=SeqPDS->Length(); i++) {
3969 Handle(StepRepr_ProductDefinitionShape) PDS =
3970 Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i));
3973 Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition();
3974 if(aProdDef.IsNull())
3976 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
3977 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString("");
3978 Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString("");
3979 Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString("");
3980 Standard_Real aDensity=0;
3981 Interface_EntityIterator subs = graph.Sharings( aProdDef);
3982 for(subs.Start(); subs.More(); subs.Next()) {
3983 Handle(StepRepr_PropertyDefinition) PropD =
3984 Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value());
3985 if(PropD.IsNull()) continue;
3986 Interface_EntityIterator subs1 = graph.Sharings(PropD);
3987 for(subs1.Start(); subs1.More(); subs1.Next()) {
3988 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
3989 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value());
3990 if(PDR.IsNull()) continue;
3991 Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation();
3992 if(Repr.IsNull()) continue;
3993 Standard_Integer ir;
3994 for(ir=1; ir<=Repr->NbItems(); ir++) {
3995 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir);
3996 if(RI.IsNull()) continue;
3997 if(RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
3998 // find name and description for material
3999 Handle(StepRepr_DescriptiveRepresentationItem) DRI =
4000 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI);
4001 aName = DRI->Name();
4003 aDescription = DRI->Description();
4005 aName = aDescription;
4007 if(RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) {
4008 // try to find density for material
4009 Handle(StepRepr_MeasureRepresentationItem) MRI =
4010 Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI);
4011 aDensity = MRI->Measure()->ValueComponent();
4012 aDensName = MRI->Name();
4013 aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name());
4014 StepBasic_Unit aUnit = MRI->Measure()->UnitComponent();
4015 if(!aUnit.IsNull()) {
4016 Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit();
4017 if(DU.IsNull()) continue;
4018 for(Standard_Integer idu=1; idu<=DU->NbElements(); idu++) {
4019 Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu);
4020 Handle(StepBasic_NamedUnit) NU = DUE->Unit();
4021 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ||
4022 NU->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)))
4024 STEPConstruct_UnitContext anUnitCtx;
4025 anUnitCtx.ComputeFactors(NU);
4026 aDensity = aDensity / (anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor());
4027 // transfer length value for Density from millimeter to santimeter
4028 // in order to result density has dimension gram/(sm*sm*sm)
4029 aDensity = aDensity*1000. / (UnitsMethods::GetCasCadeLengthUnit()
4030 * UnitsMethods::GetCasCadeLengthUnit() * UnitsMethods::GetCasCadeLengthUnit());
4032 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) {
4033 Standard_Real afact = 1.;
4034 if (GetMassConversionFactor(NU, afact))
4036 aDensity = aDensity*afact;
4046 if( aName.IsNull() || aName->Length()==0 )
4048 // find shape label amd create Material link
4050 Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS,graph);
4052 Standard_Integer index = TP->MapIndex(SM);
4054 Handle(Transfer_Binder) binder = TP->MapItem(index);
4055 if(!binder.IsNull())
4056 aSh = TransferBRep::ShapeResult(binder);
4059 if(aSh.IsNull()) continue;
4061 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
4062 MatTool->SetMaterial(shL,aName,aDescription,aDensity,aDensName,aDensValType);
4065 return Standard_True;
4068 //=======================================================================
4069 //function : collectViewShapes
4070 //purpose : collect all labels of representations in given representation
4071 //=======================================================================
4073 void collectViewShapes(const Handle(XSControl_WorkSession)& theWS,
4074 const Handle(TDocStd_Document)& theDoc,
4075 const Handle(StepRepr_Representation) theRepr,
4076 TDF_LabelSequence& theShapes)
4078 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
4079 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4080 const Interface_Graph& aGraph = aTP->Graph();
4081 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4082 Standard_Integer anIndex = aTP->MapIndex(theRepr);
4085 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
4086 aSh = TransferBRep::ShapeResult(aBinder);
4088 if (!aSh.IsNull()) {
4090 aSTool->FindShape(aSh, aShL);
4092 theShapes.Append(aShL);
4094 Interface_EntityIterator anIter = aGraph.Sharings(theRepr);
4095 for (; anIter.More(); anIter.Next()) {
4096 if (!anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_RepresentationRelationship)))
4098 Handle(StepRepr_RepresentationRelationship) aReprRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(anIter.Value());
4099 if (aReprRelationship->Rep1() != theRepr)
4100 collectViewShapes(theWS, theDoc, aReprRelationship->Rep1(), theShapes);
4104 //=======================================================================
4105 //function : buildClippingPlanes
4107 //=======================================================================
4108 Handle(TCollection_HAsciiString) buildClippingPlanes(const Handle(StepGeom_GeometricRepresentationItem)& theClippingCameraModel,
4109 TDF_LabelSequence& theClippingPlanes,
4110 const Handle(XCAFDoc_ClippingPlaneTool) theTool)
4112 Handle(TCollection_HAsciiString) anExpression = new TCollection_HAsciiString();
4113 NCollection_Sequence<Handle(StepGeom_GeometricRepresentationItem)> aPlanes;
4114 Handle(TCollection_HAsciiString) anOperation = new TCollection_HAsciiString("*");
4117 if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClipping))) {
4118 Handle(StepVisual_CameraModelD3MultiClipping) aCameraModel =
4119 Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(theClippingCameraModel);
4120 // Root of clipping planes tree
4121 if (aCameraModel->ShapeClipping()->Length() == 1) {
4122 Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModelUnion =
4123 aCameraModel->ShapeClipping()->Value(1).CameraModelD3MultiClippingUnion();
4124 if (!aCameraModelUnion.IsNull())
4125 return buildClippingPlanes(aCameraModelUnion, theClippingPlanes, theTool);
4127 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4128 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4131 else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingUnion))) {
4132 Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModel =
4133 Handle(StepVisual_CameraModelD3MultiClippingUnion)::DownCast(theClippingCameraModel);
4134 anOperation = new TCollection_HAsciiString("+");
4135 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4136 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4139 else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingIntersection))) {
4140 Handle(StepVisual_CameraModelD3MultiClippingIntersection) aCameraModel =
4141 Handle(StepVisual_CameraModelD3MultiClippingIntersection)::DownCast(theClippingCameraModel);
4142 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4143 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4147 anExpression->AssignCat("(");
4148 for (Standard_Integer i = 1; i <= aPlanes.Length(); i++) {
4149 Handle(StepGeom_Plane) aPlaneEnt = Handle(StepGeom_Plane)::DownCast(aPlanes.Value(i));
4150 if (!aPlaneEnt.IsNull()) {
4151 Handle(Geom_Plane) aPlane = StepToGeom::MakePlane(aPlaneEnt);
4152 if (!aPlane.IsNull()) {
4153 TDF_Label aPlaneL = theTool->AddClippingPlane(aPlane->Pln(), aPlaneEnt->Name());
4154 theClippingPlanes.Append(aPlaneL);
4155 TCollection_AsciiString anEntry;
4156 TDF_Tool::Entry(aPlaneL, anEntry);
4157 anExpression->AssignCat(new TCollection_HAsciiString(anEntry));
4161 anExpression->AssignCat(buildClippingPlanes(aPlanes.Value(i), theClippingPlanes, theTool));
4163 anExpression->AssignCat(anOperation);
4165 // Insert brace instead of operation after last operand.
4166 anExpression->SetValue(anExpression->Length(), ')');
4167 return anExpression;
4171 //=======================================================================
4172 //function : ReadViews
4174 //=======================================================================
4175 Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const
4177 const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
4178 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4179 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
4180 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(theDoc->Main());
4181 if (aDGTTool.IsNull()) return Standard_False;
4183 Standard_Integer nb = aModel->NbEntities();
4184 for (Standard_Integer i = 1; i <= nb; i++) {
4185 Handle(Standard_Transient) anEnt = aModel->Value(i);
4186 if (!anEnt->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3)))
4188 Handle(XCAFView_Object) anObj = new XCAFView_Object();
4189 // Import attributes of view
4190 Handle(StepVisual_CameraModelD3) aCameraModel = Handle(StepVisual_CameraModelD3)::DownCast(anEnt);
4192 const Handle(XSControl_TransferReader)& aTR = theWS->TransferReader();
4193 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4194 const Interface_Graph& aGraph = aTP->Graph();
4195 // find the proper DraughtingModel
4196 Interface_EntityIterator subs = aGraph.Sharings(aCameraModel);
4197 Handle(StepVisual_DraughtingModel) aDModel;
4198 for (subs.Start(); subs.More() && aDModel.IsNull(); subs.Next())
4200 if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingModel)))
4204 aDModel = Handle(StepVisual_DraughtingModel)::DownCast(subs.Value());
4206 if (!aDModel.IsNull())
4208 XSAlgo::AlgoContainer()->PrepareForTransfer();
4209 STEPControl_ActorRead anActor;
4210 anActor.PrepareUnits(aDModel, aTP);
4213 anObj->SetName(aCameraModel->Name());
4214 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aCameraModel->ViewReferenceSystem());
4215 anObj->SetViewDirection(anAxis->Direction());
4216 anObj->SetUpDirection(anAxis->Direction() ^ anAxis->XDirection());
4217 Handle(StepVisual_ViewVolume) aViewVolume = aCameraModel->PerspectiveOfVolume();
4218 XCAFView_ProjectionType aType = XCAFView_ProjectionType_NoCamera;
4219 if (aViewVolume->ProjectionType() == StepVisual_copCentral)
4220 aType = XCAFView_ProjectionType_Central;
4221 else if (aViewVolume->ProjectionType() == StepVisual_copParallel)
4222 aType = XCAFView_ProjectionType_Parallel;
4223 anObj->SetType(aType);
4224 Handle(Geom_CartesianPoint) aPoint = StepToGeom::MakeCartesianPoint(aViewVolume->ProjectionPoint());
4225 anObj->SetProjectionPoint(aPoint->Pnt());
4226 anObj->SetZoomFactor(aViewVolume->ViewPlaneDistance());
4227 anObj->SetWindowHorizontalSize(aViewVolume->ViewWindow()->SizeInX());
4228 anObj->SetWindowVerticalSize(aViewVolume->ViewWindow()->SizeInY());
4229 if (aViewVolume->FrontPlaneClipping())
4230 anObj->SetFrontPlaneDistance(aViewVolume->FrontPlaneDistance());
4231 if (aViewVolume->BackPlaneClipping())
4232 anObj->SetBackPlaneDistance(aViewVolume->BackPlaneDistance());
4233 anObj->SetViewVolumeSidesClipping(aViewVolume->ViewVolumeSidesClipping());
4235 Handle(StepVisual_CameraModelD3MultiClipping) aClippingCameraModel =
4236 Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(aCameraModel);
4237 TDF_LabelSequence aClippingPlanes;
4238 if (!aClippingCameraModel.IsNull()) {
4239 Handle(TCollection_HAsciiString) aClippingExpression;
4240 Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(theDoc->Main());
4241 aClippingExpression = buildClippingPlanes(aClippingCameraModel, aClippingPlanes, aClippingPlaneTool);
4242 anObj->SetClippingExpression(aClippingExpression);
4245 // Collect shapes and GDTs
4246 if (aDModel.IsNull())
4247 return Standard_False;
4248 TDF_LabelSequence aShapes, aGDTs;
4249 Interface_EntityIterator anIter = aGraph.Shareds(aDModel);
4250 for (; anIter.More(); anIter.Next()) {
4251 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
4252 Handle(StepRepr_MappedItem) anItem = Handle(StepRepr_MappedItem)::DownCast(anIter.Value());
4253 Handle(StepRepr_Representation) aRepr = anItem->MappingSource()->MappedRepresentation();
4254 collectViewShapes(theWS, theDoc, aRepr, aShapes);
4256 else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)) ||
4257 anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout))) {
4258 Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
4259 for (; aDMIAIter.More(); aDMIAIter.Next()) {
4260 if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
4262 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
4263 Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
4265 Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
4267 isFind = myGDTMap.Find(anIter.Value(), aGDTL);
4270 aGDTs.Append(aGDTL);
4273 else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationPlane))) {
4274 Handle(StepVisual_AnnotationPlane) aPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
4275 for (Standard_Integer j = 1; j <= aPlane->NbElements(); j++) {
4276 Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
4277 for (; aDMIAIter.More(); aDMIAIter.Next()) {
4278 if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
4280 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
4281 Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
4283 Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
4285 aGDTs.Append(aGDTL);
4290 TDF_Label aViewL = aViewTool->AddView();
4291 Handle(XCAFDoc_View) aView = XCAFDoc_View::Set(aViewL);
4292 aView->SetObject(anObj);
4293 aViewTool->SetView(aShapes, aGDTs, aClippingPlanes, aViewL);
4294 aViewTool->Lock(aViewL);
4296 return Standard_True;
4299 //=======================================================================
4300 //function : SettleShapeData
4302 //=======================================================================
4304 TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_RepresentationItem)& theItem,
4305 const TDF_Label& theLab,
4306 const Handle(XCAFDoc_ShapeTool)& theShapeTool,
4307 const Handle(Transfer_TransientProcess)& TP) const
4309 TDF_Label aResult = theLab;
4311 Handle(TCollection_HAsciiString) hName = theItem->Name();
4312 if ( hName.IsNull() || hName->IsEmpty() )
4315 Handle(Transfer_Binder) aBinder = TP->Find(theItem);
4316 if ( aBinder.IsNull() )
4319 TopoDS_Shape aShape = TransferBRep::ShapeResult(aBinder);
4320 if ( aShape.IsNull() )
4323 // Allocate sub-Label
4324 aResult = theShapeTool->AddSubShape(theLab, aShape);
4325 if (aResult.IsNull())
4328 TCollection_AsciiString aName = hName->String();
4329 TDataStd_Name::Set(aResult, aName);
4330 theShapeTool->SetShape(aResult, aShape);
4335 //=======================================================================
4336 //function : collectRepresentationItems
4337 //purpose : recursive collection of representation items for given representation
4338 // with all representations, related to it.
4339 //=======================================================================
4341 void collectRepresentationItems(const Interface_Graph& theGraph,
4342 const Handle(StepShape_ShapeRepresentation)& theRepresentation,
4343 NCollection_Sequence<Handle(StepRepr_RepresentationItem)>& theItems)
4345 Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = theRepresentation->Items();
4346 for (Standard_Integer itemIt = aReprItems->Lower(); itemIt <= aReprItems->Upper(); itemIt++)
4347 theItems.Append(aReprItems->Value(itemIt));
4349 Interface_EntityIterator entIt = theGraph.TypedSharings(theRepresentation, STANDARD_TYPE(StepRepr_RepresentationRelationship));
4350 for (entIt.Start(); entIt.More(); entIt.Next())
4352 Handle(StepRepr_RepresentationRelationship) aRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(entIt.Value());
4353 if (aRelationship->Rep1() == theRepresentation)
4355 Handle(StepShape_ShapeRepresentation)
4356 aRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aRelationship->Rep2());
4357 if (!aRepr.IsNull())
4358 collectRepresentationItems(theGraph, aRepr, theItems);
4363 //=======================================================================
4364 //function : ExpandSubShapes
4366 //=======================================================================
4368 void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& ShapeTool,
4369 const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap,
4370 const STEPCAFControl_DataMapOfShapePD& ShapePDMap) const
4372 const Handle(Transfer_TransientProcess)& TP = Reader().WS()->TransferReader()->TransientProcess();
4373 NCollection_DataMap<TopoDS_Shape, Handle(TCollection_HAsciiString)> ShapeNameMap;
4374 TColStd_MapOfTransient aRepItems;
4376 // Read translation control variables
4377 Standard_Boolean doReadSNames = (Interface_Static::IVal("read.stepcaf.subshapes.name") > 0);
4379 if ( !doReadSNames )
4382 const Interface_Graph& Graph = Reader().WS()->Graph();
4384 for ( STEPCAFControl_DataMapIteratorOfDataMapOfShapePD it(ShapePDMap); it.More(); it.Next() )
4386 const TopoDS_Shape& aRootShape = it.Key();
4387 const Handle(StepBasic_ProductDefinition)& aPDef = it.Value();
4388 if ( aPDef.IsNull() )
4391 // Find SDR by Product
4392 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
4393 Interface_EntityIterator entIt = Graph.TypedSharings( aPDef, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation) );
4394 for ( entIt.Start(); entIt.More(); entIt.Next() )
4396 const Handle(Standard_Transient)& aReferer = entIt.Value();
4397 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aReferer);
4398 if ( !aSDR.IsNull() )
4402 if ( aSDR.IsNull() )
4405 // Access shape representation
4406 Handle(StepShape_ShapeRepresentation)
4407 aShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast( aSDR->UsedRepresentation() );
4409 if ( aShapeRepr.IsNull() )
4412 // Access representation items
4413 NCollection_Sequence<Handle(StepRepr_RepresentationItem)> aReprItems;
4414 collectRepresentationItems(Graph, aShapeRepr, aReprItems);
4416 if (aReprItems.Length() == 0)
4419 if ( !ShapeLabelMap.IsBound(aRootShape) )
4422 TDF_Label aRootLab = ShapeLabelMap.Find(aRootShape);
4423 // Do not add subshapes to assembly,
4424 // they will be processed with corresponding Shape_Product_Definition of necessary part.
4425 if (ShapeTool->IsAssembly(aRootLab))
4428 StepRepr_SequenceOfRepresentationItem aMSBSeq;
4429 StepRepr_SequenceOfRepresentationItem aSBSMSeq;
4431 // Iterate over the top level representation items collecting the
4432 // topological containers to expand
4433 for (Standard_Integer i = 1; i <= aReprItems.Length(); ++i)
4435 Handle(StepRepr_RepresentationItem) aTRepr = aReprItems.Value(i);
4436 if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ManifoldSolidBrep) ) )
4437 aMSBSeq.Append(aTRepr);
4438 else if ( aTRepr->IsKind( STANDARD_TYPE(StepShape_ShellBasedSurfaceModel) ) )
4439 aSBSMSeq.Append(aTRepr);
4442 // Insert intermediate OCAF Labels for SOLIDs in case there are more
4443 // than one Manifold Solid BRep in the Shape Representation
4444 Standard_Boolean doInsertSolidLab = (aMSBSeq.Length() > 1);
4446 // Expand Manifold Solid BReps
4447 for ( Standard_Integer i = 1; i <= aMSBSeq.Length(); ++i )
4449 // Put additional Label for SOLID
4450 if (doInsertSolidLab)
4451 SettleShapeData(aMSBSeq.Value(i), aRootLab, ShapeTool, TP);
4453 ExpandManifoldSolidBrep(aRootLab, aMSBSeq.Value(i), TP, ShapeTool);
4456 // Expand Shell-Based Surface Models
4457 for ( Standard_Integer i = 1; i <= aSBSMSeq.Length(); ++i )
4458 ExpandSBSM(aRootLab, aSBSMSeq.Value(i), TP, ShapeTool);
4462 //=======================================================================
4463 //function : ExpandManifoldSolidBrep
4465 //=======================================================================
4467 void STEPCAFControl_Reader::ExpandManifoldSolidBrep(TDF_Label& ShapeLab,
4468 const Handle(StepRepr_RepresentationItem)& Repr,
4469 const Handle(Transfer_TransientProcess)& TP,
4470 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4472 // Access outer shell
4473 Handle(StepShape_ManifoldSolidBrep) aMSB = Handle(StepShape_ManifoldSolidBrep)::DownCast(Repr);
4474 Handle(StepShape_ConnectedFaceSet) aShell = aMSB->Outer();
4476 // Expand shell contents to CAF tree
4477 ExpandShell(aShell, ShapeLab, TP, ShapeTool);
4480 //=======================================================================
4481 //function : ExpandSBSM
4483 //=======================================================================
4485 void STEPCAFControl_Reader::ExpandSBSM(TDF_Label& ShapeLab,
4486 const Handle(StepRepr_RepresentationItem)& Repr,
4487 const Handle(Transfer_TransientProcess)& TP,
4488 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4490 Handle(StepShape_ShellBasedSurfaceModel) aSBSM = Handle(StepShape_ShellBasedSurfaceModel)::DownCast(Repr);
4492 // Access boundary shells
4493 Handle(StepShape_HArray1OfShell) aShells = aSBSM->SbsmBoundary();
4494 for ( Standard_Integer s = aShells->Lower(); s <= aShells->Upper(); ++s )
4496 const StepShape_Shell& aShell = aShells->Value(s);
4497 Handle(StepShape_ConnectedFaceSet) aCFS;
4498 Handle(StepShape_OpenShell) anOpenShell = aShell.OpenShell();
4499 Handle(StepShape_ClosedShell) aClosedShell = aShell.ClosedShell();
4501 if ( !anOpenShell.IsNull() )
4504 aCFS = aClosedShell;
4506 ExpandShell(aCFS, ShapeLab, TP, ShapeTool);
4510 //=======================================================================
4511 //function : ExpandShell
4513 //=======================================================================
4515 void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)& Shell,
4517 const Handle(Transfer_TransientProcess)& TP,
4518 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4521 SettleShapeData(Shell, RootLab, ShapeTool, TP);
4524 Handle(StepShape_HArray1OfFace) aFaces = Shell->CfsFaces();
4525 for ( Standard_Integer f = aFaces->Lower(); f <= aFaces->Upper(); ++f )
4527 const Handle(StepShape_Face)& aFace = aFaces->Value(f);
4532 SettleShapeData(aFace, RootLab, ShapeTool, TP);
4534 // Access face bounds
4535 Handle(StepShape_HArray1OfFaceBound) aWires = aFace->Bounds();
4536 for ( Standard_Integer w = aWires->Lower(); w <= aWires->Upper(); ++w )
4538 const Handle(StepShape_Loop)& aWire = aWires->Value(w)->Bound();
4541 SettleShapeData(aWire, RootLab, ShapeTool, TP);
4543 // Access wire edges
4544 // Currently only EDGE LOOPs are considered (!)
4545 if ( !aWire->IsInstance( STANDARD_TYPE(StepShape_EdgeLoop) ) )
4549 Handle(StepShape_EdgeLoop) anEdgeLoop = Handle(StepShape_EdgeLoop)::DownCast(aWire);
4550 Handle(StepShape_HArray1OfOrientedEdge) anEdges = anEdgeLoop->EdgeList();
4551 for ( Standard_Integer e = anEdges->Lower(); e <= anEdges->Upper(); ++e )
4553 Handle(StepShape_Edge) anEdge = anEdges->Value(e)->EdgeElement();
4556 SettleShapeData(anEdge, RootLab, ShapeTool, TP);
4559 Handle(StepShape_Vertex) aV1 = anEdge->EdgeStart();
4560 Handle(StepShape_Vertex) aV2 = anEdge->EdgeEnd();
4563 SettleShapeData(aV1, RootLab, ShapeTool, TP);
4564 SettleShapeData(aV2, RootLab, ShapeTool, TP);
4570 //=======================================================================
4571 //function : SetColorMode
4573 //=======================================================================
4575 void STEPCAFControl_Reader::SetColorMode (const Standard_Boolean colormode)
4577 myColorMode = colormode;
4580 //=======================================================================
4581 //function : GetColorMode
4583 //=======================================================================
4585 Standard_Boolean STEPCAFControl_Reader::GetColorMode () const
4590 //=======================================================================
4591 //function : SetNameMode
4593 //=======================================================================
4595 void STEPCAFControl_Reader::SetNameMode (const Standard_Boolean namemode)
4597 myNameMode = namemode;
4600 //=======================================================================
4601 //function : GetNameMode
4603 //=======================================================================
4605 Standard_Boolean STEPCAFControl_Reader::GetNameMode () const
4610 //=======================================================================
4611 //function : SetLayerMode
4613 //=======================================================================
4615 void STEPCAFControl_Reader::SetLayerMode (const Standard_Boolean layermode)
4617 myLayerMode = layermode;
4620 //=======================================================================
4621 //function : GetLayerMode
4623 //=======================================================================
4625 Standard_Boolean STEPCAFControl_Reader::GetLayerMode () const
4630 //=======================================================================
4631 //function : SetPropsMode
4633 //=======================================================================
4635 void STEPCAFControl_Reader::SetPropsMode (const Standard_Boolean propsmode)
4637 myPropsMode = propsmode;
4640 //=======================================================================
4641 //function : GetPropsMode
4643 //=======================================================================
4645 Standard_Boolean STEPCAFControl_Reader::GetPropsMode () const
4650 //=======================================================================
4651 //function : SetSHUOMode
4653 //=======================================================================
4655 void STEPCAFControl_Reader::SetSHUOMode (const Standard_Boolean mode)
4660 //=======================================================================
4661 //function : GetSHUOMode
4663 //=======================================================================
4665 Standard_Boolean STEPCAFControl_Reader::GetSHUOMode () const
4670 //=======================================================================
4671 //function : SetGDTMode
4673 //=======================================================================
4675 void STEPCAFControl_Reader::SetGDTMode (const Standard_Boolean gdtmode)
4677 myGDTMode = gdtmode;
4680 //=======================================================================
4681 //function : GetGDTMode
4683 //=======================================================================
4685 Standard_Boolean STEPCAFControl_Reader::GetGDTMode () const
4691 //=======================================================================
4692 //function : SetMatMode
4694 //=======================================================================
4696 void STEPCAFControl_Reader::SetMatMode (const Standard_Boolean matmode)
4698 myMatMode = matmode;
4701 //=======================================================================
4702 //function : GetMatMode
4704 //=======================================================================
4706 Standard_Boolean STEPCAFControl_Reader::GetMatMode () const
4711 //=======================================================================
4712 //function : SetViewMode
4714 //=======================================================================
4716 void STEPCAFControl_Reader::SetViewMode(const Standard_Boolean viewmode)
4718 myViewMode = viewmode;
4721 //=======================================================================
4722 //function : GetViewMode
4724 //=======================================================================
4726 Standard_Boolean STEPCAFControl_Reader::GetViewMode() const