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();
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));
665 ReadColors(reader.WS(), doc, map);
669 ReadNames(reader.WS(), doc, PDFileMap, map);
671 // read validation props
673 ReadValProps(reader.WS(), doc, PDFileMap, map);
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();
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));
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,
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();
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);
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);
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());
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());
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) {
1647 if (SU->HasPrefix())
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 0027372
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 Standard_Real aFact = 1.;
1958 Handle(StepShape_ShapeDimensionRepresentation) aSDR = NULL;
1959 for (Interface_EntityIterator anIt = aGraph.Sharings(theGDT); aSDR.IsNull() && anIt.More(); anIt.Next()) {
1960 Handle(Standard_Transient) anEnt = anIt.Value();
1961 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
1962 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anEnt);
1964 aSDR = !aDCR.IsNull() ? aDCR->Representation() : Handle(StepShape_ShapeDimensionRepresentation)::DownCast(anEnt);
1968 XSAlgo::AlgoContainer()->PrepareForTransfer();
1969 STEPControl_ActorRead anActor;
1970 anActor.PrepareUnits(aSDR, aTP);
1971 aFact = UnitsMethods::LengthFactor();
1974 if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
1975 // retrieve derived geometry
1976 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theGDT);
1977 Handle(StepRepr_DerivedShapeAspect) aDSA = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->AppliesTo());
1980 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = NULL;
1981 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA); aGISU.IsNull() && anIt.More(); anIt.Next()) {
1982 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
1984 if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0)
1986 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU->IdentifiedItem()->Value(1));
1987 if (aPoint.IsNull()) {
1988 // try Axis2Placement3d.location instead of CartesianPoint
1989 Handle(StepGeom_Axis2Placement3d) anA2P3D =
1990 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU->IdentifiedItem()->Value(1));
1991 if (anA2P3D.IsNull())
1993 aPoint = anA2P3D->Location();
1996 // set connection point to object
1997 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
1998 theDimObject->SetPoint(aPnt);
2000 else if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2001 // retrieve derived geometry
2002 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theGDT);
2003 Handle(StepRepr_DerivedShapeAspect) aDSA1 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatingShapeAspect());
2004 Handle(StepRepr_DerivedShapeAspect) aDSA2 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatedShapeAspect());
2005 if (aDSA1.IsNull() && aDSA2.IsNull())
2007 Handle(StepAP242_GeometricItemSpecificUsage) aGISU1 = NULL;
2008 Handle(StepAP242_GeometricItemSpecificUsage) aGISU2 = NULL;
2009 if (!aDSA1.IsNull()) {
2010 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA1); aGISU1.IsNull() && anIt.More(); anIt.Next()) {
2011 aGISU1 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2014 if (!aDSA2.IsNull()) {
2015 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA2); aGISU2.IsNull() && anIt.More(); anIt.Next()) {
2016 aGISU2 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2020 if (!aGISU1.IsNull() && aGISU1->NbIdentifiedItem() > 0) {
2021 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2022 if (aPoint.IsNull()) {
2023 // try Axis2Placement3d.location instead of CartesianPoint
2024 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2025 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2026 if (!anA2P3D.IsNull())
2027 aPoint = anA2P3D->Location();
2029 if (!aPoint.IsNull()) {
2030 // set connection point to object
2031 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2032 theDimObject->SetPoint(aPnt);
2036 if (!aGISU2.IsNull() && aGISU2->NbIdentifiedItem() > 0) {
2037 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2038 if (aPoint.IsNull()) {
2039 // try Axis2Placement3d.location instead of CartesianPoint
2040 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2041 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2042 if (!anA2P3D.IsNull())
2043 aPoint = anA2P3D->Location();
2045 if (!aPoint.IsNull()) {
2046 // set connection point to object
2047 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2048 theDimObject->SetPoint2(aPnt);
2054 //=======================================================================
2055 //function : ReadDatums
2056 //purpose : auxilary
2057 //=======================================================================
2058 static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
2059 const Handle(XCAFDoc_DimTolTool) &DGTTool,
2060 const Interface_Graph &graph,
2061 const Handle(Transfer_TransientProcess) &TP,
2062 const TDF_Label TolerL,
2063 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
2065 if (GTWDR.IsNull()) return Standard_False;
2066 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
2067 if (HADR.IsNull()) return Standard_False;
2068 for (Standard_Integer idr = 1; idr <= HADR->Length(); idr++) {
2069 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
2070 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
2071 if (aDatum.IsNull()) continue;
2072 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
2073 for (subs4.Start(); subs4.More(); subs4.Next()) {
2074 Handle(StepRepr_ShapeAspectRelationship) SAR =
2075 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
2076 if (SAR.IsNull()) continue;
2077 Handle(StepDimTol_DatumFeature) DF =
2078 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
2079 if (DF.IsNull()) continue;
2080 Interface_EntityIterator subs5 = graph.Sharings(DF);
2081 Handle(StepRepr_PropertyDefinition) PropDef;
2082 for (subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
2083 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
2085 if (PropDef.IsNull()) continue;
2086 Handle(StepShape_AdvancedFace) AF;
2087 subs5 = graph.Sharings(PropDef);
2088 for (subs5.Start(); subs5.More(); subs5.Next()) {
2089 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2090 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
2091 if (!SDR.IsNull()) {
2092 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2093 if (!Repr.IsNull() && Repr->NbItems() > 0) {
2094 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
2095 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2099 if (AF.IsNull()) return Standard_False;
2100 Standard_Integer index = TP->MapIndex(AF);
2103 Handle(Transfer_Binder) binder = TP->MapItem(index);
2104 aSh = TransferBRep::ShapeResult(binder);
2106 if (aSh.IsNull()) continue;
2108 if (!STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
2109 DGTTool->SetDatum(shL, TolerL, PropDef->Name(), PropDef->Description(), aDatum->Identification());
2112 return Standard_True;
2115 //=======================================================================
2116 //function : FindShapeIndexForDGT
2117 //purpose : auxiliary find shape index in map og imported shapes
2118 //=======================================================================
2119 static Standard_Integer FindShapeIndexForDGT(const Handle(Standard_Transient)& theEnt,
2120 const Handle(XSControl_WorkSession)& theWS)
2122 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2123 // try to find index of given entity
2124 Standard_Integer anIndex = aTP->MapIndex(theEnt);
2127 // if theEnt is a geometry item try to find its topological item
2128 const Interface_Graph& aGraph = aTP->Graph();
2129 Interface_EntityIterator anIter = aGraph.Sharings(theEnt);
2130 for (anIter.Start(); anIter.More(); anIter.Next()) {
2131 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)))
2133 anIndex = aTP->MapIndex(anIter.Value());
2141 //=======================================================================
2142 //function : collectShapeAspect
2144 //=======================================================================
2145 static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA,
2146 const Handle(XSControl_WorkSession)& theWS,
2147 NCollection_Sequence<Handle(StepRepr_ShapeAspect)>& theSAs)
2151 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2152 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2153 const Interface_Graph& aGraph = aTP->Graph();
2154 // Retrieve Shape_Aspect, connected to Representation_Item from Derived_Shape_Aspect
2155 if (theSA->IsKind(STANDARD_TYPE(StepRepr_DerivedShapeAspect))) {
2156 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2157 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = NULL;
2158 for (; aSADR.IsNull() && anIter.More(); anIter.Next()) {
2159 aSADR = Handle(StepRepr_ShapeAspectDerivingRelationship)::DownCast(anIter.Value());
2161 if (!aSADR.IsNull())
2162 collectShapeAspect(aSADR->RelatedShapeAspect(), theWS, theSAs);
2164 else if (theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
2165 theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) {
2166 theSAs.Append(theSA);
2170 // Find all children Shape_Aspect
2171 Standard_Boolean isSimple = Standard_True;
2172 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2173 for (; anIter.More(); anIter.Next()) {
2174 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship)) &&
2175 !anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2176 Handle(StepRepr_ShapeAspectRelationship) aSAR =
2177 Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
2178 if (aSAR->RelatingShapeAspect() == theSA && !aSAR->RelatedShapeAspect().IsNull()
2179 && !aSAR->RelatedShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_Datum))) {
2180 collectShapeAspect(aSAR->RelatedShapeAspect(), theWS, theSAs);
2181 isSimple = Standard_False;
2185 // If not Composite_Shape_Aspect (or subtype) append to sequence.
2187 theSAs.Append(theSA);
2191 //=======================================================================
2192 //function : getShapeLabel
2194 //=======================================================================
2196 static TDF_Label getShapeLabel(const Handle(StepRepr_RepresentationItem)& theItem,
2197 const Handle(XSControl_WorkSession)& theWS,
2198 const Handle(XCAFDoc_ShapeTool)& theShapeTool)
2201 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2202 Standard_Integer index = FindShapeIndexForDGT(theItem, theWS);
2203 TopoDS_Shape aShape;
2205 Handle(Transfer_Binder) aBinder = aTP->MapItem(index);
2206 aShape = TransferBRep::ShapeResult(aBinder);
2208 if (aShape.IsNull())
2210 theShapeTool->Search(aShape, aShapeL, Standard_True, Standard_True, Standard_True);
2214 //=======================================================================
2215 //function : setDatumToXCAF
2217 //=======================================================================
2219 Standard_Boolean STEPCAFControl_Reader::setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
2220 const TDF_Label theGDTL,
2221 const Standard_Integer thePositionCounter,
2222 const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
2223 const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
2224 const Standard_Real theModifValue,
2225 const Handle(TDocStd_Document)& theDoc,
2226 const Handle(XSControl_WorkSession)& theWS)
2228 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
2229 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
2230 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2231 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2232 const Interface_Graph& aGraph = aTP->Graph();
2233 Handle(XCAFDoc_Datum) aDat;
2234 TDF_LabelSequence aShapeLabels;
2235 Handle(XCAFDimTolObjects_DatumObject) aDatObj = new XCAFDimTolObjects_DatumObject();
2237 // Collect all links to shapes
2238 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2239 Interface_EntityIterator anIterD = aGraph.Sharings(theDat);
2240 for (anIterD.Start(); anIterD.More(); anIterD.Next()) {
2241 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value());
2242 if (aSAR.IsNull() || aSAR->RelatingShapeAspect().IsNull())
2244 collectShapeAspect(aSAR->RelatingShapeAspect(), theWS, aSAs);
2245 Handle(StepDimTol_DatumFeature) aDF = Handle(StepDimTol_DatumFeature)::DownCast(aSAR->RelatingShapeAspect());
2246 if (!aSAR->RelatingShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2247 readAnnotation(aTR, aSAR->RelatingShapeAspect(), aDatObj);
2250 // Collect shape labels
2251 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2252 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2255 // Skip datum targets
2256 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2259 // Process all connected GISU
2260 Interface_EntityIterator anIter = aGraph.Sharings(aSA);
2261 for (; anIter.More(); anIter.Next()) {
2262 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
2265 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2266 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2267 if (!aShapeL.IsNull())
2268 aShapeLabels.Append(aShapeL);
2273 // Process datum targets and create objects for them
2274 Standard_Boolean isExistDatumTarget = Standard_False;
2275 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2276 Handle(StepDimTol_PlacedDatumTargetFeature) aDT = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSAs.Value(i));
2279 Handle(XCAFDimTolObjects_DatumObject) aDatTargetObj = new XCAFDimTolObjects_DatumObject();
2280 XCAFDimTolObjects_DatumTargetType aType;
2281 if (!STEPCAFControl_GDTProperty::GetDatumTargetType(aDT->Description(), aType))
2283 aDatTargetObj->SetDatumTargetType(aType);
2284 Standard_Boolean isValidDT = Standard_False;
2286 // Feature for datum target
2287 TDF_LabelSequence aDTShapeLabels;
2288 Interface_EntityIterator aDTIter = aGraph.Sharings(aDT);
2289 Handle(StepRepr_FeatureForDatumTargetRelationship) aRelationship;
2290 for (; aDTIter.More() && aRelationship.IsNull(); aDTIter.Next()) {
2291 aRelationship = Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(aDTIter.Value());
2293 if (!aRelationship.IsNull()) {
2294 Handle(StepRepr_ShapeAspect) aSA = aRelationship->RelatingShapeAspect();
2295 Interface_EntityIterator aSAIter = aGraph.Sharings(aSA);
2296 for (; aSAIter.More(); aSAIter.Next()) {
2297 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aSAIter.Value());
2300 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2301 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2302 if (!aShapeL.IsNull()) {
2303 aDTShapeLabels.Append(aShapeL);
2304 isValidDT = Standard_True;
2310 if (aType != XCAFDimTolObjects_DatumTargetType_Area && !isValidDT) {
2311 // Try another way of feature connection
2312 for (aDTIter.Start(); aDTIter.More(); aDTIter.Next()) {
2313 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aDTIter.Value());
2316 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2317 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2318 if (!aShapeL.IsNull()) {
2319 aDTShapeLabels.Append(aShapeL);
2320 isValidDT = Standard_True;
2326 if (aType == XCAFDimTolObjects_DatumTargetType_Area) {
2327 // Area datum target
2328 Interface_EntityIterator anIterDTF = aGraph.Shareds(aDT);
2329 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2330 for (; anIterDTF.More() && aGISU.IsNull(); anIterDTF.Next()) {
2331 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDTF.Value());
2333 Handle(StepRepr_RepresentationItem) anItem;
2334 if (aGISU->NbIdentifiedItem() > 0)
2335 anItem = aGISU->IdentifiedItemValue(1);
2336 if (anItem.IsNull())
2338 Standard_Integer anItemIndex = FindShapeIndexForDGT(anItem, theWS);
2339 if (anItemIndex > 0) {
2340 Handle(Transfer_Binder) aBinder = aTP->MapItem(anItemIndex);
2341 TopoDS_Shape anItemShape = TransferBRep::ShapeResult(aBinder);
2342 aDatTargetObj->SetDatumTarget(anItemShape);
2343 isValidDT = Standard_True;
2347 // Point/line/rectangle/circle datum targets
2348 Interface_EntityIterator anIter = aGraph.Sharings(aDT);
2349 Handle(StepRepr_PropertyDefinition) aPD;
2350 for (; anIter.More() && aPD.IsNull(); anIter.Next()) {
2351 aPD = Handle(StepRepr_PropertyDefinition)::DownCast(anIter.Value());
2353 if (!aPD.IsNull()) {
2354 anIter = aGraph.Sharings(aPD);
2355 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2356 for (; anIter.More() && aSDR.IsNull(); anIter.Next()) {
2357 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anIter.Value());
2359 if (!aSDR.IsNull()) {
2360 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP
2361 = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(aSDR->UsedRepresentation());
2362 if (!aSRWP.IsNull()) {
2363 isValidDT = Standard_True;
2364 // Collect parameters of datum target
2365 for (Standard_Integer j = aSRWP->Items()->Lower(); j <= aSRWP->Items()->Upper(); j++)
2367 if (aSRWP->ItemsValue(j).IsNull())
2369 if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2371 Handle(StepGeom_Axis2Placement3d) anAx
2372 = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(j));
2373 XSAlgo::AlgoContainer()->PrepareForTransfer();
2374 STEPControl_ActorRead anActor;
2375 anActor.PrepareUnits(aSRWP, aTP);
2376 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(anAx);
2377 aDatTargetObj->SetDatumTargetAxis(anAxis->Ax2());
2379 else if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
2381 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
2382 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(j));
2383 Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
2384 StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
2385 if (anUnit.IsNull())
2387 Handle(StepBasic_NamedUnit) aNU = anUnit.NamedUnit();
2390 STEPConstruct_UnitContext anUnitCtx;
2391 anUnitCtx.ComputeFactors(aNU);
2392 aVal = aVal * anUnitCtx.LengthFactor();
2393 if (aM->Name()->String().IsEqual("target length") ||
2394 aM->Name()->String().IsEqual("target diameter"))
2395 aDatTargetObj->SetDatumTargetLength(aVal);
2397 aDatTargetObj->SetDatumTargetWidth(aVal);
2405 // Create datum target object
2407 TDF_Label aDatL = aDGTTool->AddDatum();
2408 myGDTMap.Bind(aDT, aDatL);
2409 aDGTTool->Lock(aDatL);
2410 aDat = XCAFDoc_Datum::Set(aDatL);
2411 aDGTTool->SetDatum(aDTShapeLabels, aDatL);
2412 aDatTargetObj->SetName(theDat->Identification());
2413 aDatTargetObj->SetPosition(thePositionCounter);
2414 if (!theXCAFModifiers.IsEmpty())
2415 aDatTargetObj->SetModifiers(theXCAFModifiers);
2416 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2417 aDatTargetObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2418 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2419 aDatTargetObj->IsDatumTarget(Standard_True);
2420 aDatTargetObj->SetDatumTargetNumber(aDT->TargetId()->IntegerValue());
2421 readAnnotation(aTR, aDT, aDatTargetObj);
2422 aDat->SetObject(aDatTargetObj);
2423 isExistDatumTarget = Standard_True;
2427 if (aShapeLabels.Length() > 0 || !isExistDatumTarget) {
2428 // Create object for datum
2429 TDF_Label aDatL = aDGTTool->AddDatum();
2430 myGDTMap.Bind(theDat, aDatL);
2431 // bind datum label with all reference datum_feature entities
2432 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2433 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2434 if (aSA.IsNull() || aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2436 myGDTMap.Bind(aSA, aDatL);
2438 aDGTTool->Lock(aDatL);
2439 aDat = XCAFDoc_Datum::Set(aDatL);
2440 aDGTTool->SetDatum(aShapeLabels, aDatL);
2441 aDatObj->SetName(theDat->Identification());
2442 aDatObj->SetPosition(thePositionCounter);
2443 if (!theXCAFModifiers.IsEmpty())
2444 aDatObj->SetModifiers(theXCAFModifiers);
2445 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2446 aDatObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2447 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2448 if (aDatObj->GetPresentation().IsNull()) {
2449 // Try find annotation connected to datum entity (not right case, according recommended practices)
2450 readAnnotation(aTR, theDat, aDatObj);
2452 aDat->SetObject(aDatObj);
2455 return Standard_True;
2459 //=======================================================================
2460 //function : ReadDatums
2461 //purpose : auxilary
2462 //=======================================================================
2463 Standard_Boolean STEPCAFControl_Reader::readDatumsAP242(const Handle(Standard_Transient)& theEnt,
2464 const TDF_Label theGDTL,
2465 const Handle(TDocStd_Document)& theDoc,
2466 const Handle(XSControl_WorkSession)& theWS)
2468 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2469 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2470 const Interface_Graph& aGraph = aTP->Graph();
2472 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2473 for (anIter.Start(); anIter.More(); anIter.Next()) {
2474 Handle(Standard_Transient) anAtr = anIter.Value();
2475 if (anAtr->IsKind(STANDARD_TYPE(StepDimTol_DatumSystem)))
2477 Standard_Integer aPositionCounter = 0;//position on frame
2478 Handle(StepDimTol_DatumSystem) aDS = Handle(StepDimTol_DatumSystem)::DownCast(anAtr);
2479 Interface_EntityIterator anIterDS = aGraph.Sharings(aDS);
2480 for (anIterDS.Start(); anIterDS.More(); anIterDS.Next()) {
2481 Handle(Standard_Transient) anAtrDS = anIterDS.Value();
2482 if (anAtrDS->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
2485 Handle(StepAP242_GeometricItemSpecificUsage)aAxGISUI
2486 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anAtrDS);
2487 if (aAxGISUI->IdentifiedItemValue(1)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2489 Handle(StepGeom_Axis2Placement3d) anAx
2490 = Handle(StepGeom_Axis2Placement3d)::DownCast(aAxGISUI->IdentifiedItemValue(1));
2491 Handle(XCAFDoc_GeomTolerance) aTol;
2492 if (theGDTL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aTol))
2494 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aTol->GetObject();
2495 Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
2496 Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
2497 Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
2501 if (!aDirArr.IsNull() && aDirArr->Length() > 2 &&
2502 !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
2503 !aLocArr.IsNull() && aLocArr->Length() > 2)
2505 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, aDirArr->Lower() + 2);
2506 aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower() + 1, aDirRArr->Lower() + 2);
2507 aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower() + 1, aLocArr->Lower() + 2);
2508 gp_Ax2 anA(aPnt, aDir, aDirR);
2509 anObj->SetAxis(anA);
2510 aTol->SetObject(anObj);
2516 if (aDS->NbConstituents() > 0)
2518 //get datum feature and datum target from datum system
2519 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aDRCA = aDS->Constituents();
2520 if (!aDRCA.IsNull())
2522 for (Standard_Integer i = aDRCA->Lower(); i <= aDRCA->Upper(); i++)
2524 Handle(StepDimTol_DatumReferenceCompartment) aDRC = aDRCA->Value(i);
2526 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModif = aDRC->Modifiers();
2527 XCAFDimTolObjects_DatumModifiersSequence aXCAFModifiers;
2528 XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal = XCAFDimTolObjects_DatumModifWithValue_None;
2529 Standard_Real aModifValue = 0;
2530 if (!aModif.IsNull())
2532 for (Standard_Integer m = aModif->Lower(); m <= aModif->Upper(); m++)
2534 if (aModif->Value(m).CaseNumber() == 2)
2535 aXCAFModifiers.Append(
2536 (XCAFDimTolObjects_DatumSingleModif)aModif->Value(m).
2537 SimpleDatumReferenceModifierMember()->Value());
2538 else if (aModif->Value(m).CaseNumber() == 1)
2540 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModif->Value(m).DatumReferenceModifierWithValue()->ModifierType() + 1);
2541 Standard_Real aVal = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2542 StepBasic_Unit anUnit = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2543 if (anUnit.IsNull()) continue;
2544 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2545 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2546 STEPConstruct_UnitContext anUnitCtx;
2547 anUnitCtx.ComputeFactors(NU);
2548 aModifValue = aVal * anUnitCtx.LengthFactor();
2553 Interface_EntityIterator anIterDRC = aGraph.Shareds(aDRC);
2554 for (anIterDRC.Start(); anIterDRC.More(); anIterDRC.Next()) {
2556 if (anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2558 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRC.Value());
2559 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue, theDoc, theWS);
2561 else if (anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_DatumReferenceElement)))
2563 Handle(StepDimTol_DatumReferenceElement) aDRE
2564 = Handle(StepDimTol_DatumReferenceElement)::DownCast(anIterDRC.Value());
2565 //get modifiers from group of datums
2566 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifE = aDRE->Modifiers();
2567 if (!aModifE.IsNull())
2569 for (Standard_Integer k = aModifE->Lower(); k <= aModifE->Upper(); k++)
2571 if (aModifE->Value(k).CaseNumber() == 2)
2572 aXCAFModifiers.Append(
2573 (XCAFDimTolObjects_DatumSingleModif)aModifE->Value(k).
2574 SimpleDatumReferenceModifierMember()->Value());
2575 else if (aModifE->Value(k).CaseNumber() == 1)
2577 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierType() + 1);
2578 Standard_Real aVal = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2579 StepBasic_Unit anUnit = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2580 if (anUnit.IsNull()) continue;
2581 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2582 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2583 STEPConstruct_UnitContext anUnitCtx;
2584 anUnitCtx.ComputeFactors(NU);
2585 aModifValue = aVal * anUnitCtx.LengthFactor();
2589 Interface_EntityIterator anIterDRE = aGraph.Shareds(aDRE);
2590 for (anIterDRE.Start(); anIterDRE.More(); anIterDRE.Next()) {
2591 if (anIterDRE.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2593 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRE.Value());
2594 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue, theDoc, theWS);
2604 return Standard_True;
2607 //=======================================================================
2608 //function : createGeomTolObjectInXCAF
2610 //=======================================================================
2611 TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
2612 const Handle(TDocStd_Document)& theDoc,
2613 const Handle(XSControl_WorkSession)& theWS)
2616 if (!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
2617 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) &&
2618 !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
2623 Handle(TCollection_HAsciiString) aSemanticName;
2625 // protection against invalid input
2626 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2627 Handle(StepDimTol_GeometricTolerance) aGeomTol = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2628 if (aGeomTol->TolerancedShapeAspect().IsNull())
2630 aSemanticName = aGeomTol->Name();
2632 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2633 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2634 if (aDim->AppliesTo().IsNull())
2636 aSemanticName = aDim->Name();
2638 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2639 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
2640 if (aDim->RelatedShapeAspect().IsNull() || aDim->RelatingShapeAspect().IsNull())
2642 aSemanticName = aDim->Name();
2645 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
2646 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
2647 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2648 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2649 const Interface_Graph& aGraph = aTP->Graph();
2650 Standard_Boolean isAllAround = Standard_False;
2651 Standard_Boolean isAllOver = Standard_False;
2653 // find RepresentationItem for current Ent
2654 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI1, aSeqRI2;
2656 // Collect all Shape_Aspect entities
2657 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2658 for (anIter.Start(); anIter.More(); anIter.Next()) {
2659 Handle(Standard_Transient) anAtr = anIter.Value();
2660 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2661 if (anAtr->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)))
2663 //if associating tolerances with part (All-Over)
2664 Interface_EntityIterator anIterSDR = aGraph.Sharings(anAtr);
2665 for (anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next())
2667 Handle(Standard_Transient) anAtrSDR = anIterSDR.Value();
2668 if (anAtrSDR->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
2670 isAllOver = Standard_True;
2671 Interface_EntityIterator anIterABSR = aGraph.Shareds(anAtrSDR);
2672 for (anIterABSR.Start(); anIterABSR.More(); anIterABSR.Next())
2674 Handle(Standard_Transient) anAtrABSR = anIterABSR.Value();
2675 if (anAtrABSR->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
2677 aSeqRI1.Append(anAtrABSR);
2683 else if (anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
2684 anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
2686 //if tolerance attached to dimension
2687 Interface_EntityIterator anIterDim = aGraph.Shareds(anAtr);
2688 for (anIterDim.Start(); anIterDim.More(); anIterDim.Next())
2690 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anIterDim.Value());
2691 if (!aSA.IsNull()) {
2692 collectShapeAspect(aSA, theWS, aSAs);
2696 else if (anAtr->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
2698 if (anAtr->IsKind(STANDARD_TYPE(StepRepr_AllAroundShapeAspect)))
2700 // if applyed AllAround Modifier
2701 isAllAround = Standard_True;
2703 // dimensions and default tolerances
2704 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anAtr);
2705 if (!aSA.IsNull()) {
2706 collectShapeAspect(aSA, theWS, aSAs);
2710 // Collect all representation items
2711 if (!aSAs.IsEmpty())
2713 //get representation items
2714 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI;
2715 for (Standard_Integer i = aSAs.Lower(); i <= aSAs.Upper(); i++)
2717 Interface_EntityIterator anIterSA = aGraph.Sharings(aSAs.Value(i));
2718 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2719 Handle(StepRepr_PropertyDefinition) PropD;
2720 for (anIterSA.Start(); anIterSA.More() && aGISU.IsNull() && PropD.IsNull(); anIterSA.Next()) {
2721 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
2722 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(anIterSA.Value());
2724 if (!PropD.IsNull())//for old version
2726 Handle(StepRepr_RepresentationItem) RI;
2727 Interface_EntityIterator subs4 = aGraph.Sharings(PropD);
2728 for (subs4.Start(); subs4.More(); subs4.Next()) {
2729 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2730 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
2731 if (!SDR.IsNull()) {
2732 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2733 if (!Repr.IsNull() && Repr->NbItems() > 0) {
2734 RI = Repr->ItemsValue(1);
2738 if (RI.IsNull()) continue;
2740 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2742 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
2743 if (EC.IsNull()) continue;
2744 Handle(TCollection_HAsciiString) aName;
2745 Handle(StepShape_DimensionalSize) DimSize =
2746 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2747 Standard_Real dim1 = -1., dim2 = -1.;
2748 subs4 = aGraph.Sharings(DimSize);
2749 for (subs4.Start(); subs4.More(); subs4.Next()) {
2750 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
2751 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
2752 if (!DimCharR.IsNull()) {
2753 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
2754 if (!SDimR.IsNull() && SDimR->NbItems() > 0) {
2755 Handle(StepRepr_RepresentationItem) anItem = SDimR->ItemsValue(1);
2756 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(anItem);
2759 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
2760 //if(CID.IsNull()) continue;
2761 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
2762 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
2763 //if(CIDM.IsNull()) continue;
2764 //if(CIDM->ArrTransient().IsNull()) continue;
2765 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
2766 //if(CID.CaseMem(CIDM)==1)
2767 // HARI = CID.ListRepresentationItem();
2768 //if(CID.CaseMem(CIDM)==2)
2769 // HARI = CID.SetRepresentationItem();
2770 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
2771 if (HARI.IsNull()) continue;
2772 if (HARI->Length() > 0) {
2773 Handle(StepRepr_RepresentationItem) RI1 = HARI->Value(1);
2774 if (RI1.IsNull()) continue;
2775 if (RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2776 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2777 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
2778 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2779 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2780 if (anUnit.IsNull()) continue;
2781 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2782 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2783 STEPConstruct_UnitContext anUnitCtx;
2784 anUnitCtx.ComputeFactors(NU);
2785 dim1 = dim1 * anUnitCtx.LengthFactor();
2788 if (HARI->Length() > 1) {
2789 Handle(StepRepr_RepresentationItem) RI2 = HARI->Value(2);
2790 if (RI2.IsNull()) continue;
2791 if (RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2792 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2793 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
2794 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2795 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2796 if (anUnit.IsNull()) continue;
2797 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2798 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2799 STEPConstruct_UnitContext anUnitCtx;
2800 anUnitCtx.ComputeFactors(NU);
2801 dim2 = dim2 * anUnitCtx.LengthFactor();
2808 if (dim1 < 0) continue;
2809 if (dim2 < 0) dim2 = dim1;
2810 //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl;
2811 // now we know edge_curve and value range therefore
2812 // we can create corresponding D> labels
2813 Standard_Integer index = aTP->MapIndex(EC);
2816 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2817 aSh = TransferBRep::ShapeResult(binder);
2819 if (aSh.IsNull()) continue;
2821 if (!aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
2822 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1, 2);
2823 arr->SetValue(1, dim1);
2824 arr->SetValue(2, dim2);
2825 aDGTTool->SetDimTol(shL, 1, arr, aName, DimSize->Name());
2827 // read tolerances and datums
2828 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2829 Handle(StepDimTol_GeometricTolerance) GT =
2830 Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2831 // read common data for tolerance
2832 //Standard_Real dim = GT->Magnitude()->ValueComponent();
2833 Handle(StepBasic_MeasureWithUnit) dim3 = GT->Magnitude();
2834 if (dim3.IsNull()) continue;
2835 Standard_Real dim = dim3->ValueComponent();
2836 StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent();
2837 if (anUnit.IsNull()) continue;
2838 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2839 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2840 STEPConstruct_UnitContext anUnitCtx;
2841 anUnitCtx.ComputeFactors(NU);
2842 dim = dim * anUnitCtx.LengthFactor();
2843 //cout<<"GeometricTolerance: Magnitude = "<<dim<<endl;
2844 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1, 1);
2845 arr->SetValue(1, dim);
2846 Handle(TCollection_HAsciiString) aName = GT->Name();
2847 Handle(TCollection_HAsciiString) aDescription = GT->Description();
2848 Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2849 if (AF.IsNull()) continue;
2850 Standard_Integer index = aTP->MapIndex(AF);
2853 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2854 aSh = TransferBRep::ShapeResult(binder);
2856 if (aSh.IsNull()) continue;
2858 if (!aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
2859 // read specific data for tolerance
2860 if (GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) {
2861 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
2862 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(theEnt);
2863 Standard_Integer kind = 20;
2864 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2865 GTComplex->GetModifiedGeometricTolerance();
2866 if (!MGT.IsNull()) {
2867 kind = kind + MGT->Modifier() + 1;
2869 TDF_Label TolerL = aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription);
2870 // translate datums connected with this tolerance
2871 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2872 GTComplex->GetGeometricToleranceWithDatumReference();
2873 if (!GTWDR.IsNull()) {
2874 ReadDatums(aSTool, aDGTTool, aGraph, aTP, TolerL, GTWDR);
2877 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) {
2878 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2879 Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(theEnt);
2880 if (GTWDR.IsNull()) continue;
2881 Standard_Integer kind = 0;
2882 if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24;
2883 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25;
2884 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26;
2885 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27;
2886 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28;
2887 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29;
2888 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30;
2889 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31;
2890 //cout<<"GTWDR: kind="<<kind<<endl;
2891 TDF_Label TolerL = aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription);
2892 ReadDatums(aSTool, aDGTTool, aGraph, aTP, TolerL, GTWDR);
2894 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) {
2895 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2896 Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(theEnt);
2897 Standard_Integer kind = 35 + MGT->Modifier();
2898 aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription);
2900 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) {
2901 aDGTTool->SetDimTol(shL, 38, arr, aName, aDescription);
2903 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) {
2904 aDGTTool->SetDimTol(shL, 39, arr, aName, aDescription);
2906 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) {
2907 aDGTTool->SetDimTol(shL, 40, arr, aName, aDescription);
2909 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) {
2910 aDGTTool->SetDimTol(shL, 41, arr, aName, aDescription);
2912 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) {
2913 aDGTTool->SetDimTol(shL, 42, arr, aName, aDescription);
2915 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) {
2916 aDGTTool->SetDimTol(shL, 43, arr, aName, aDescription);
2918 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) {
2919 aDGTTool->SetDimTol(shL, 44, arr, aName, aDescription);
2925 if (aGISU.IsNull()) continue;
2926 Standard_Integer j = 1;
2927 for (; j <= aGISU->NbIdentifiedItem(); j++) {
2928 aSeqRI.Append(aGISU->IdentifiedItemValue(j));
2932 if (!aSeqRI.IsEmpty())
2934 if (aSeqRI1.IsEmpty())
2941 if (aSeqRI1.IsEmpty())
2944 TDF_LabelSequence aShLS1, aShLS2;
2947 for (Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper();i++)
2949 Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS);
2952 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
2953 aSh = TransferBRep::ShapeResult(aBinder);
2958 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
2959 if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
2961 TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
2965 aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
2966 if (!edgeL.IsNull())
2967 aShLS1.Append(edgeL);
2972 aShLS1.Append(aShL);
2975 if (!aSeqRI2.IsEmpty())
2977 //for dimensional location
2978 for (Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper();i++)
2980 Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI2.Value(i), theWS);
2983 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
2984 aSh = TransferBRep::ShapeResult(aBinder);
2989 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
2990 if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
2992 TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
2996 aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
2997 if (!edgeL.IsNull())
2998 aShLS2.Append(edgeL);
3003 aShLS2.Append(aShL);
3008 if (!aShLS1.IsEmpty())
3011 if (!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
3013 aGDTL = aDGTTool->AddDimension();
3014 myGDTMap.Bind(theEnt, aGDTL);
3015 aDGTTool->Lock(aGDTL);
3016 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
3017 TCollection_AsciiString aStr("DGT:Dimensional_");
3018 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
3020 aStr.AssignCat("Size");
3022 else if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
3024 aStr.AssignCat("Location");
3026 TDataStd_Name::Set(aGDTL, aStr);
3028 if (!aShLS2.IsEmpty())
3030 aDGTTool->SetDimension(aShLS1, aShLS2, aGDTL);
3034 TDF_LabelSequence aEmptySeq;
3035 aDGTTool->SetDimension(aShLS1, aEmptySeq, aGDTL);
3040 aGDTL = aDGTTool->AddGeomTolerance();
3041 myGDTMap.Bind(theEnt, aGDTL);
3042 aDGTTool->Lock(aGDTL);
3043 Handle(XCAFDoc_GeomTolerance) aGTol = XCAFDoc_GeomTolerance::Set(aGDTL);
3044 TCollection_AsciiString aStr("DGT:GeomTolerance");
3045 TDataStd_Name::Set(aGDTL, aStr);
3046 aDGTTool->SetGeomTolerance(aShLS1, aGDTL);
3047 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGTol->GetObject();
3049 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Around);
3051 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Over);
3052 aGTol->SetObject(anObj);
3057 TCollection_ExtendedString str(aSemanticName->String());
3058 TDataStd_Name::Set(aGDTL, str);
3061 readDatumsAP242(theEnt, aGDTL, theDoc, theWS);
3066 //=======================================================================
3067 //function : convertAngleValue
3068 //purpose : auxilary
3069 //=======================================================================
3070 void convertAngleValue(
3071 const STEPConstruct_UnitContext& anUnitCtx,
3072 Standard_Real& aVal)
3074 // convert radian to deg
3075 Standard_Real aFact = anUnitCtx.PlaneAngleFactor() * 180 / M_PI;
3076 // in order to avoid inaccuracy of calculation perform conversion
3077 // only if aFact not eqaul 1 with some precision
3078 if (fabs(1. - aFact) > Precision::Confusion())
3080 aVal = aVal * aFact;
3085 //=======================================================================
3086 //function : setDimObjectToXCAF
3088 //=======================================================================
3089 static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3090 const TDF_Label& aDimL,
3091 const Handle(TDocStd_Document)& theDoc,
3092 const Handle(XSControl_WorkSession)& theWS)
3094 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
3095 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
3096 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3097 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
3098 const Interface_Graph& aGraph = aTP->Graph();
3099 Handle(XCAFDimTolObjects_DimensionObject) aDimObj;
3100 if (!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
3101 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
3104 Handle(StepShape_DimensionalSize) aDimSize =
3105 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
3106 Handle(StepShape_DimensionalLocation) aDimLocation =
3107 Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
3109 aDimObj = new XCAFDimTolObjects_DimensionObject();
3110 Standard_Real aDim1 = -1., aDim2 = -1., aDim3 = -1.;
3111 Standard_Boolean isPlusMinusTolerance = Standard_False;
3112 Handle(StepShape_TypeQualifier) aTQ;
3113 Handle(StepShape_ValueFormatTypeQualifier) aVFTQ;
3114 Handle(StepShape_ToleranceValue) aTV;
3115 Handle(StepShape_LimitsAndFits) aLAF;
3116 Handle(StepRepr_CompoundRepresentationItem) aCRI;
3117 Handle(StepGeom_Axis2Placement3d) anAP;
3119 Interface_EntityIterator anIterDim;
3120 if (!aDimSize.IsNull())
3122 anIterDim = aGraph.Sharings(aDimSize);
3126 anIterDim = aGraph.Sharings(aDimLocation);
3128 for (anIterDim.Start(); anIterDim.More(); anIterDim.Next()) {
3129 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
3130 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anIterDim.Value());
3131 Handle(StepShape_PlusMinusTolerance) aPMT =
3132 Handle(StepShape_PlusMinusTolerance)::DownCast(anIterDim.Value());
3133 if (!aDCR.IsNull()) {
3134 Handle(StepShape_ShapeDimensionRepresentation) aSDR = aDCR->Representation();
3135 if (!aSDR.IsNull()) {
3136 Handle(StepRepr_HArray1OfRepresentationItem) aHARI = aSDR->Items();
3138 if (!aHARI.IsNull())
3140 for (Standard_Integer nr = aHARI->Lower(); nr <= aHARI->Upper(); nr++)
3142 Handle(StepRepr_RepresentationItem) aDRI = aHARI->Value(nr);
3143 if (aDRI.IsNull()) continue;
3145 if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))) {
3146 // simple value / range
3147 Handle(StepRepr_ReprItemAndMeasureWithUnit) aMWU =
3148 Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aDRI);
3149 Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
3150 StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
3151 if (anUnit.IsNull())
3153 if (!(anUnit.CaseNum(anUnit.Value()) == 1))
3155 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3156 STEPConstruct_UnitContext anUnitCtx;
3157 anUnitCtx.ComputeFactors(NU);
3158 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
3159 aVal = aVal * anUnitCtx.LengthFactor();
3163 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit))) {
3164 convertAngleValue(anUnitCtx, aVal);
3166 Handle(TCollection_HAsciiString) aName = aMWU->Name();
3167 if (aName->Search("upper") > 0) // upper limit
3169 else // lower limit or simple nominal value
3172 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnitAndQRI))) {
3173 // value with qualifier (minimum/maximum/average)
3174 Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI) aMWU =
3175 Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI)::DownCast(aDRI);
3176 Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
3177 StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
3178 if (anUnit.IsNull())
3180 if (!(anUnit.CaseNum(anUnit.Value()) == 1))
3182 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3183 STEPConstruct_UnitContext anUnitCtx;
3184 anUnitCtx.ComputeFactors(NU);
3185 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI))) {
3186 aVal = aVal * anUnitCtx.LengthFactor();
3189 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI))) {
3190 convertAngleValue(anUnitCtx, aVal);
3192 Handle(StepShape_QualifiedRepresentationItem) aQRI = aMWU->GetQualifiedRepresentationItem();
3193 if (aQRI->Qualifiers()->Length() == 0) {
3197 Handle(StepShape_TypeQualifier) aValueType = aQRI->Qualifiers()->Value(1).TypeQualifier();
3198 if (aValueType->Name()->String().IsEqual("minimum"))
3200 else if (aValueType->Name()->String().IsEqual("maximum"))
3204 else if (aDRI->IsKind(STANDARD_TYPE(StepShape_QualifiedRepresentationItem))) {
3206 Handle(StepShape_QualifiedRepresentationItem) aQRI =
3207 Handle(StepShape_QualifiedRepresentationItem)::DownCast(aDRI);
3208 for (Standard_Integer l = 1; l <= aQRI->NbQualifiers(); l++)
3210 aTQ = aQRI->Qualifiers()->Value(l).TypeQualifier();
3211 aVFTQ = aQRI->Qualifiers()->Value(l).ValueFormatTypeQualifier();
3214 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
3215 Handle(StepRepr_DescriptiveRepresentationItem) aDescription =
3216 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aDRI);
3217 aDimObj->AddDescription(aDescription->Description(), aDescription->Name());
3219 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_CompoundRepresentationItem))) {
3220 aCRI = Handle(StepRepr_CompoundRepresentationItem)::DownCast(aDRI);
3222 else if (aDRI->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
3224 anAP = Handle(StepGeom_Axis2Placement3d)::DownCast(aDRI);
3230 else if (!aPMT.IsNull())
3232 isPlusMinusTolerance = Standard_True;
3233 StepShape_ToleranceMethodDefinition aTMD = aPMT->Range();
3234 if (aPMT.IsNull()) continue;
3235 if (aTMD.CaseNumber() == 1)
3236 //! 1 -> ToleranceValue from StepShape
3237 //! 2 -> LimitsAndFits from StepShape
3239 //plus minus tolerance
3240 aTV = aTMD.ToleranceValue();
3241 if (aTV.IsNull()) continue;
3243 Handle(StepBasic_MeasureWithUnit) aMWU = aTV->UpperBound();
3244 Standard_Real aVal = aTV->UpperBound()->ValueComponent();
3245 StepBasic_Unit anUnit = aTV->UpperBound()->UnitComponent();
3246 if (anUnit.IsNull()) continue;
3247 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3248 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3249 STEPConstruct_UnitContext anUnitCtx;
3250 anUnitCtx.ComputeFactors(NU);
3251 if (aMWU->IsKind(STANDARD_TYPE(StepBasic_LengthMeasureWithUnit)) ||
3252 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI)))
3254 aVal = aVal * anUnitCtx.LengthFactor();
3256 else if (aMWU->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) ||
3257 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI)))
3259 convertAngleValue(anUnitCtx, aVal);
3263 aMWU = aTV->LowerBound();
3264 aVal = aTV->LowerBound()->ValueComponent();
3265 anUnit = aTV->LowerBound()->UnitComponent();
3266 if (anUnit.IsNull()) continue;
3267 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3268 NU = anUnit.NamedUnit();
3269 anUnitCtx.ComputeFactors(NU);
3270 if (aMWU->IsKind(STANDARD_TYPE(StepBasic_LengthMeasureWithUnit)) ||
3271 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI)))
3273 aVal = aVal * anUnitCtx.LengthFactor();
3275 else if (aMWU->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) ||
3276 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI)))
3278 convertAngleValue(anUnitCtx, aVal);
3284 // class of tolerance
3285 aLAF = aTMD.LimitsAndFits();
3290 if (aDim1 < 0) return;
3293 aDimObj->SetValue(aDim1);
3296 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1, 2);
3297 anArr->SetValue(1, aDim1);
3298 anArr->SetValue(2, aDim2);
3299 aDimObj->SetValues(anArr);
3303 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1, 3);
3304 if (!isPlusMinusTolerance)
3306 aDim2 = aDim1 - aDim2;
3307 aDim3 = aDim3 - aDim1;
3309 anArr->SetValue(1, aDim1);
3310 anArr->SetValue(2, aDim2);
3311 anArr->SetValue(3, aDim3);
3312 aDimObj->SetValues(anArr);
3316 XCAFDimTolObjects_DimensionQualifier aQ;
3317 if (STEPCAFControl_GDTProperty::GetDimQualifierType(aTQ->Name(), aQ))
3319 aDimObj->SetQualifier(aQ);
3323 if (!aVFTQ.IsNull())
3325 //A typical value would be 'NR2 2.2'
3326 TCollection_HAsciiString aFormat = aVFTQ->FormatType();
3327 Standard_Integer i = aFormat.Location(1, ' ', 1, aFormat.Length());
3328 aFormat.SubString(i + 1, i + 1)->IntegerValue();
3329 aDimObj->SetNbOfDecimalPlaces(aFormat.SubString(i + 1, i + 1)->IntegerValue(),
3330 aFormat.SubString(i + 3, i + 3)->IntegerValue());
3335 //get class of tolerance
3336 Standard_Boolean aHolle = Standard_False;
3337 XCAFDimTolObjects_DimensionFormVariance aFV = XCAFDimTolObjects_DimensionFormVariance_None;
3338 XCAFDimTolObjects_DimensionGrade aG = XCAFDimTolObjects_DimensionGrade_IT01;
3339 STEPCAFControl_GDTProperty::GetDimClassOfTolerance(aLAF, aHolle, aFV, aG);
3340 aDimObj->SetClassOfTolerance(aHolle, aFV, aG);
3343 if (!aCRI.IsNull() && !aCRI->ItemElement().IsNull() && aCRI->ItemElement()->Length() > 0)
3346 XCAFDimTolObjects_DimensionModifiersSequence aModifiers;
3347 STEPCAFControl_GDTProperty::GetDimModifiers(aCRI, aModifiers);
3348 if (aModifiers.Length() > 0)
3349 aDimObj->SetModifiers(aModifiers);
3352 Handle(TCollection_HAsciiString) aName;
3353 if (!aDimSize.IsNull())
3355 aName = aDimSize->Name();
3359 aName = aDimLocation->Name();
3361 XCAFDimTolObjects_DimensionType aType = XCAFDimTolObjects_DimensionType_Location_None;
3362 if (!STEPCAFControl_GDTProperty::GetDimType(aName, aType))
3364 if (!aDimSize.IsNull())
3366 Handle(StepShape_AngularSize) anAngSize =
3367 Handle(StepShape_AngularSize)::DownCast(aDimSize);
3368 if (!anAngSize.IsNull())
3370 //get qualifier for angular value
3371 aType = XCAFDimTolObjects_DimensionType_Size_Angular;
3372 if (anAngSize->AngleSelection() == StepShape_Equal)
3373 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg);
3374 else if (anAngSize->AngleSelection() == StepShape_Large)
3375 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max);
3376 else if (anAngSize->AngleSelection() == StepShape_Small)
3377 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min);
3382 Handle(StepShape_AngularLocation) anAngLoc =
3383 Handle(StepShape_AngularLocation)::DownCast(aDimLocation);
3384 if (!anAngLoc.IsNull())
3386 //get qualifier for angular value
3387 aType = XCAFDimTolObjects_DimensionType_Location_Angular;
3388 if (anAngLoc->AngleSelection() == StepShape_Equal)
3389 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Avg);
3390 else if (anAngLoc->AngleSelection() == StepShape_Large)
3391 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Max);
3392 else if (anAngLoc->AngleSelection() == StepShape_Small)
3393 aDimObj->SetQualifier(XCAFDimTolObjects_DimensionQualifier_Min);
3396 if (aType == XCAFDimTolObjects_DimensionType_Location_None)
3398 Handle(StepRepr_ShapeAspect) aPSA;
3399 if (!aDimSize.IsNull())
3401 Handle(StepShape_DimensionalSizeWithPath) aDimSizeWithPath =
3402 Handle(StepShape_DimensionalSizeWithPath)::DownCast(aDimSize);
3403 if (!aDimSizeWithPath.IsNull())
3405 aType = XCAFDimTolObjects_DimensionType_Size_WithPath;
3406 aPSA = aDimSizeWithPath->Path();
3411 Handle(StepShape_DimensionalLocationWithPath) aDimLocWithPath =
3412 Handle(StepShape_DimensionalLocationWithPath)::DownCast(aDimLocation);
3413 if (!aDimLocWithPath.IsNull())
3415 aType = XCAFDimTolObjects_DimensionType_Location_WithPath;
3416 aPSA = aDimLocWithPath->Path();
3422 //for DimensionalLocationWithPath
3423 Handle(StepGeom_GeometricRepresentationItem) aGRI;
3424 Handle(StepAP242_GeometricItemSpecificUsage) aPGISU;
3425 Interface_EntityIterator anIterDSWP = aGraph.Sharings(aPSA);
3426 for (anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
3427 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
3429 if (aPGISU.IsNull()) return;
3430 if (aPGISU->NbIdentifiedItem() > 0) {
3431 aGRI = Handle(StepGeom_GeometricRepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(1));
3433 if (aGRI.IsNull()) return;
3434 Handle(StepRepr_RepresentationItem) aPRI;
3435 Interface_EntityIterator anIterGRI = aGraph.Sharings(aGRI);
3436 for (anIterGRI.Start(); anIterGRI.More() && aPGISU.IsNull(); anIterGRI.Next()) {
3437 aPRI = Handle(StepRepr_RepresentationItem)::DownCast(anIterGRI.Value());
3439 Standard_Integer anIndex = FindShapeIndexForDGT(aPRI, theWS);
3442 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3443 aSh = TopoDS::Edge(TransferBRep::ShapeResult(aBinder));
3445 if (aSh.IsNull()) return;
3446 aDimObj->SetPath(aSh);
3448 else if (!anAP.IsNull())
3450 if (anAP->Name()->String().IsEqual("orientation") && !anAP->Axis().IsNull())
3452 //for Oriented Dimensional Location
3453 Handle(TColStd_HArray1OfReal) aDirArr = anAP->RefDirection()->DirectionRatios();
3455 if (!aDirArr.IsNull() && aDirArr->Length() > 2)
3457 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, aDirArr->Lower() + 2);
3458 aDimObj->SetDirection(aDir);
3460 else if (aDirArr->Length() > 1)
3462 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, 0);
3463 aDimObj->SetDirection(aDir);
3469 aDimObj->SetType(aType);
3472 if (!aDimObj.IsNull())
3475 Handle(XCAFDoc_Dimension) aDim;
3477 if (aDimL.FindAttribute(XCAFDoc_Dimension::GetID(), aDim))
3479 readAnnotation(aTR, theEnt, aDimObj);
3480 readConnectionPoints(aTR, theEnt, aDimObj);
3481 aDim->SetObject(aDimObj);
3486 //=======================================================================
3487 //function : getTolType
3489 //=======================================================================
3490 static Standard_Boolean getTolType(const Handle(Standard_Transient)& theEnt,
3491 XCAFDimTolObjects_GeomToleranceType& theType)
3493 if (theEnt.IsNull() || !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
3494 return Standard_False;
3495 theType = XCAFDimTolObjects_GeomToleranceType_None;
3496 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRef)))
3498 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) anE = Handle(StepDimTol_GeoTolAndGeoTolWthDatRef)::DownCast(theEnt);
3499 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3501 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3503 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) anE =
3504 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(theEnt);
3505 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3507 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
3509 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) anE =
3510 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)::DownCast(theEnt);
3511 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3513 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3515 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) anE =
3516 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(theEnt);
3517 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3519 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
3521 Handle(StepDimTol_GeoTolAndGeoTolWthMod) anE =
3522 Handle(StepDimTol_GeoTolAndGeoTolWthMod)::DownCast(theEnt);
3523 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3525 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)))
3527 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol) anE =
3528 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)::DownCast(theEnt);
3529 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3531 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance)))
3533 theType = XCAFDimTolObjects_GeomToleranceType_Angularity;
3535 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance)))
3537 theType = XCAFDimTolObjects_GeomToleranceType_CircularRunout;
3539 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance)))
3541 theType = XCAFDimTolObjects_GeomToleranceType_CircularityOrRoundness;
3543 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance)))
3545 theType = XCAFDimTolObjects_GeomToleranceType_Coaxiality;
3547 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance)))
3549 theType = XCAFDimTolObjects_GeomToleranceType_Concentricity;
3551 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance)))
3553 theType = XCAFDimTolObjects_GeomToleranceType_Cylindricity;
3555 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance)))
3557 theType = XCAFDimTolObjects_GeomToleranceType_Flatness;
3559 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance)))
3561 theType = XCAFDimTolObjects_GeomToleranceType_Parallelism;
3563 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance)))
3565 theType = XCAFDimTolObjects_GeomToleranceType_Perpendicularity;
3567 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance)) ||
3568 theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)))
3570 theType = XCAFDimTolObjects_GeomToleranceType_Position;
3572 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance)))
3574 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfLine;
3576 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance)))
3578 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfSurface;
3580 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance)))
3582 theType = XCAFDimTolObjects_GeomToleranceType_Straightness;
3584 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance)))
3586 theType = XCAFDimTolObjects_GeomToleranceType_Symmetry;
3588 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance)))
3590 theType = XCAFDimTolObjects_GeomToleranceType_TotalRunout;
3592 return Standard_True;
3594 //=======================================================================
3595 //function : setGeomTolObjectToXCAF
3597 //=======================================================================
3598 static void setGeomTolObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3599 const TDF_Label& theTolL,
3600 const Handle(TDocStd_Document)& theDoc,
3601 const Handle(XSControl_WorkSession)& theWS)
3603 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
3604 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
3605 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3606 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
3607 const Interface_Graph& aGraph = aTP->Graph();
3608 Handle(XCAFDoc_GeomTolerance) aGTol;
3609 if (!theTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTol))
3613 Handle(XCAFDimTolObjects_GeomToleranceObject) aTolObj = aGTol->GetObject();
3614 Handle(StepDimTol_GeometricTolerance) aTolEnt = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
3616 XCAFDimTolObjects_GeomToleranceType aType = XCAFDimTolObjects_GeomToleranceType_None;
3617 getTolType(theEnt, aType);
3618 aTolObj->SetType(aType);
3619 if (!aTolEnt->Magnitude().IsNull()) {
3621 Standard_Real aVal = aTolEnt->Magnitude()->ValueComponent();
3622 StepBasic_Unit anUnit = aTolEnt->Magnitude()->UnitComponent();
3623 if (anUnit.IsNull()) return;
3624 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) return;
3625 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3626 STEPConstruct_UnitContext anUnitCtx;
3627 anUnitCtx.ComputeFactors(NU);
3628 aVal = aVal * anUnitCtx.LengthFactor();
3629 aTolObj->SetValue(aVal);
3632 XCAFDimTolObjects_GeomToleranceTypeValue aTypeV = XCAFDimTolObjects_GeomToleranceTypeValue_None;
3633 Interface_EntityIterator anIter = aGraph.Sharings(aTolEnt);
3634 for (anIter.Start(); anIter.More(); anIter.Next()) {
3635 if (anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_ToleranceZone))) {
3636 Handle(StepDimTol_ToleranceZoneForm) aForm
3637 = Handle(StepDimTol_ToleranceZone)::DownCast(anIter.Value())->Form();
3638 STEPCAFControl_GDTProperty::GetTolValueType(aForm->Name(), aTypeV);
3639 Interface_EntityIterator anIt = aGraph.Sharings(anIter.Value());
3640 for (anIt.Start(); anIt.More(); anIt.Next()) {
3641 if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_ProjectedZoneDefinition))) {
3642 Handle(StepDimTol_ProjectedZoneDefinition) aPZone
3643 = Handle(StepDimTol_ProjectedZoneDefinition)::DownCast(anIt.Value());
3644 if (!aPZone->ProjectionLength().IsNull())
3646 Standard_Real aVal = aPZone->ProjectionLength()->ValueComponent();
3647 StepBasic_Unit anUnit = aPZone->ProjectionLength()->UnitComponent();
3648 if (anUnit.IsNull()) return;
3649 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) return;
3650 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3651 STEPConstruct_UnitContext anUnitCtx;
3652 anUnitCtx.ComputeFactors(NU);
3653 aVal = aVal * anUnitCtx.LengthFactor();
3654 aTolObj->SetValueOfZoneModifier(aVal);
3655 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Projected);
3658 else if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_RunoutZoneDefinition)))
3660 Handle(StepDimTol_RunoutZoneDefinition) aRZone
3661 = Handle(StepDimTol_RunoutZoneDefinition)::DownCast(anIt.Value());
3662 if (!aRZone->Orientation().IsNull())
3664 Standard_Real aVal = aRZone->Orientation()->Angle()->ValueComponent();
3665 StepBasic_Unit anUnit = aRZone->Orientation()->Angle()->UnitComponent();
3666 if (anUnit.IsNull()) continue;
3667 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3668 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3669 STEPConstruct_UnitContext anUnitCtx;
3670 anUnitCtx.ComputeFactors(NU);
3671 convertAngleValue(anUnitCtx, aVal);
3672 aTolObj->SetValueOfZoneModifier(aVal);
3673 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Runout);
3677 aTolObj->SetTypeOfValue(aTypeV);
3680 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifiers;
3681 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithModifiers)))
3683 aModifiers = Handle(StepDimTol_GeometricToleranceWithModifiers)::DownCast(aTolEnt)->Modifiers();
3685 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
3687 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)
3688 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3690 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
3692 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMod)
3693 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3695 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3697 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)
3698 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3700 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3702 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)
3703 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
3705 if (!aModifiers.IsNull())
3707 for (Standard_Integer i = aModifiers->Lower(); i <= aModifiers->Upper(); i++)
3709 if (aModifiers->Value(i) == StepDimTol_GTMLeastMaterialRequirement)
3710 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_L);
3711 else if (aModifiers->Value(i) == StepDimTol_GTMMaximumMaterialRequirement)
3712 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_M);
3714 aTolObj->AddModifier((XCAFDimTolObjects_GeomToleranceModif)aModifiers->Value(i));
3717 Standard_Real aVal = 0;
3718 StepBasic_Unit anUnit;
3719 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithMaximumTolerance)))
3721 Handle(StepDimTol_GeometricToleranceWithMaximumTolerance) aMax = Handle(StepDimTol_GeometricToleranceWithMaximumTolerance)::DownCast(aTolEnt);
3722 aVal = aMax->MaximumUpperTolerance()->ValueComponent();
3723 anUnit = aMax->MaximumUpperTolerance()->UnitComponent();
3725 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3727 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aMax =
3728 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(aTolEnt);
3729 aVal = aMax->GetMaxTolerance()->ValueComponent();
3730 anUnit = aMax->GetMaxTolerance()->UnitComponent();
3732 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3734 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aMax =
3735 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(aTolEnt);
3736 aVal = aMax->GetMaxTolerance()->ValueComponent();
3737 anUnit = aMax->GetMaxTolerance()->UnitComponent();
3739 if (!anUnit.IsNull() && (anUnit.CaseNum(anUnit.Value()) == 1))
3741 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3742 STEPConstruct_UnitContext anUnitCtx;
3743 anUnitCtx.ComputeFactors(NU);
3744 convertAngleValue(anUnitCtx, aVal);
3745 aTolObj->SetMaxValueModifier(aVal);
3748 readAnnotation(aTR, theEnt, aTolObj);
3749 aGTol->SetObject(aTolObj);
3752 //=======================================================================
3753 //function : ReadGDTs
3755 //=======================================================================
3757 Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession)& theWS,
3758 Handle(TDocStd_Document)& theDoc)
3760 const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
3761 const Interface_Graph& aGraph = theWS->Graph();
3762 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3763 Handle(StepData_StepModel) aSM = Handle(StepData_StepModel)::DownCast(aModel);
3764 Interface_EntityIterator anI = aSM->Header();
3765 Handle(HeaderSection_FileSchema) aH;
3766 for (anI.Start(); anI.More() && aH.IsNull();anI.Next())
3767 aH = Handle(HeaderSection_FileSchema)::DownCast(anI.Value());
3768 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
3769 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
3770 if (aDGTTool.IsNull()) return Standard_False;
3772 Standard_Integer nb = aModel->NbEntities();
3773 for (Standard_Integer i = 1; i <= nb; i++) {
3774 Handle(Standard_Transient) anEnt = aModel->Value(i);
3775 if (anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3776 anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3777 anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3778 TDF_Label aGDTL = createGDTObjectInXCAF(anEnt, theDoc, theWS);
3779 if (!aGDTL.IsNull()) {
3780 if (anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3781 setGeomTolObjectToXCAF(anEnt, aGDTL, theDoc, theWS);
3784 setDimObjectToXCAF(anEnt, aGDTL, theDoc, theWS);
3788 else if (anEnt->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)) ||
3789 anEnt->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
3791 // Protection against import presentation twice
3792 Handle(StepVisual_DraughtingCallout) aDC;
3793 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDC.IsNull(); anIter.Next()) {
3794 aDC = Handle(StepVisual_DraughtingCallout)::DownCast(anIter.Value());
3798 // Read presentations for PMIs without semantic data.
3799 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
3800 TDF_LabelSequence aShapesL;
3801 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDMIA.IsNull(); anIter.Next()) {
3802 aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(anIter.Value());
3804 if (!aDMIA.IsNull()) {
3805 // Check entity, skip all, attached to GDTs
3806 Handle(StepRepr_ShapeAspect) aDefinition = aDMIA->Definition().ShapeAspect();
3807 if (!aDefinition.IsNull()) {
3808 Standard_Boolean isConnectedToGDT = Standard_False;
3809 // Skip if definition is a datum
3810 if (aDefinition->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
3811 aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
3812 aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
3813 aDefinition->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
3814 isConnectedToGDT = Standard_True;
3816 // Skip if any GDT is applied to definition
3817 for (Interface_EntityIterator anIter = aGraph.Sharings(aDefinition); anIter.More() && !isConnectedToGDT; anIter.Next()) {
3818 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3819 anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3820 anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3821 isConnectedToGDT = Standard_True;
3824 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
3825 if (!aSAR.IsNull()) {
3826 Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatedShapeAspect();
3827 if (!aSA.IsNull()) {
3828 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
3829 aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
3830 aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
3831 aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
3832 isConnectedToGDT = Standard_True;
3834 for (Interface_EntityIterator aDimIter = aGraph.Sharings(aSA); aDimIter.More() && !isConnectedToGDT; aDimIter.Next()) {
3835 if (aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
3836 aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
3837 aDimIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3838 isConnectedToGDT = Standard_True;
3845 if (isConnectedToGDT)
3848 else if (aDMIA->Definition().PropertyDefinition().IsNull())
3852 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
3853 collectShapeAspect(aDefinition, theWS, aSAs);
3854 for (Standard_Integer aSAIt = 1; aSAIt <= aSAs.Length(); aSAIt++) {
3855 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
3856 for (Interface_EntityIterator anIter = aGraph.Sharings(aSAs.Value(aSAIt)); anIter.More() && aGISU.IsNull(); anIter.Next())
3857 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
3860 for (Standard_Integer anItemIt = 1; anItemIt <= aGISU->NbIdentifiedItem(); anItemIt++) {
3861 TDF_Label aLabel = getShapeLabel(aGISU->IdentifiedItemValue(anItemIt), theWS, XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()));
3862 if (!aLabel.IsNull())
3863 aShapesL.Append(aLabel);
3867 Standard_Boolean isCommonLabel = (aShapesL.Length() == 0);
3870 Standard_Real aFact = 1.0;
3871 if (!aDMIA.IsNull())
3873 XSAlgo::AlgoContainer()->PrepareForTransfer();
3874 STEPControl_ActorRead anActor;
3875 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
3876 anActor.PrepareUnits(aDMIA->UsedRepresentation(), aTP);
3877 aFact = UnitsMethods::LengthFactor();
3881 TopoDS_Shape aPresentation;
3882 Handle(TCollection_HAsciiString) aPresentName;
3884 if (!readPMIPresentation(anEnt, aTR, aFact, aPresentation, aPresentName, aBox))
3887 Handle(StepVisual_AnnotationPlane) anAnPlane;
3888 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && anAnPlane.IsNull(); anIter.Next())
3889 anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
3891 // Set object to XCAF
3892 TDF_Label aGDTL = aDGTTool->AddDimension();
3893 myGDTMap.Bind(anEnt, aGDTL);
3894 aDGTTool->Lock(aGDTL);
3895 Handle(XCAFDimTolObjects_DimensionObject) aDimObj = new XCAFDimTolObjects_DimensionObject();
3896 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
3897 TCollection_AsciiString aStr("DGT:");
3898 if (isCommonLabel) {
3899 aStr.AssignCat("Common_label");
3900 aDimObj->SetType(XCAFDimTolObjects_DimensionType_CommonLabel);
3903 aStr.AssignCat("Dimension");
3904 aDimObj->SetType(XCAFDimTolObjects_DimensionType_DimensionPresentation);
3906 TDataStd_Name::Set(aGDTL, aStr);
3907 TDF_LabelSequence anEmptySeq2;
3908 aDGTTool->SetDimension(aShapesL, anEmptySeq2, aGDTL);
3910 if (!anAnPlane.IsNull()) {
3911 if (readAnnotationPlane(anAnPlane, aPlaneAxes))
3912 aDimObj->SetPlane(aPlaneAxes);
3914 aDimObj->SetPresentation(aPresentation, aPresentName);
3915 aDim->SetObject(aDimObj);
3918 return Standard_True;
3922 //=======================================================================
3923 //function : FindSolidForPDS
3924 //purpose : auxilary
3925 //=======================================================================
3927 static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS,
3928 const Interface_Graph &graph)
3930 Handle(StepShape_SolidModel) SM;
3931 Interface_EntityIterator subs = graph.Sharings(PDS);
3932 Handle(StepShape_ShapeRepresentation) SR;
3933 for (subs.Start(); subs.More() && SM.IsNull(); subs.Next()) {
3934 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
3935 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
3936 if (SDR.IsNull()) continue;
3937 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
3938 if (SR.IsNull()) continue;
3939 for (Standard_Integer i = 1; i <= SR->NbItems() && SM.IsNull(); i++) {
3940 SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i));
3943 Interface_EntityIterator subs1 = graph.Sharings(SR);
3944 for (subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) {
3945 Handle(StepRepr_RepresentationRelationship) RR =
3946 Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value());
3947 if (RR.IsNull()) continue;
3948 Handle(StepShape_ShapeRepresentation) SR2;
3949 if (RR->Rep1() == SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2());
3950 else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1());
3951 if (SR2.IsNull()) continue;
3952 for (Standard_Integer i2 = 1; i2 <= SR2->NbItems() && SM.IsNull(); i2++) {
3953 SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2));
3962 //=======================================================================
3963 //function : ReadMaterials
3965 //=======================================================================
3967 Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS,
3968 Handle(TDocStd_Document)& Doc,
3969 const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const
3971 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
3972 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
3973 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
3974 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool(Doc->Main());
3975 if (MatTool.IsNull()) return Standard_False;
3977 const Interface_Graph& graph = TP->Graph();
3978 for (Standard_Integer i = 1; i <= SeqPDS->Length(); i++) {
3979 Handle(StepRepr_ProductDefinitionShape) PDS =
3980 Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i));
3983 Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition();
3984 if (aProdDef.IsNull())
3986 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
3987 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString("");
3988 Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString("");
3989 Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString("");
3990 Standard_Real aDensity = 0;
3991 Interface_EntityIterator subs = graph.Sharings(aProdDef);
3992 for (subs.Start(); subs.More(); subs.Next()) {
3993 Handle(StepRepr_PropertyDefinition) PropD =
3994 Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value());
3995 if (PropD.IsNull()) continue;
3996 Interface_EntityIterator subs1 = graph.Sharings(PropD);
3997 for (subs1.Start(); subs1.More(); subs1.Next()) {
3998 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
3999 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value());
4000 if (PDR.IsNull()) continue;
4001 Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation();
4002 if (Repr.IsNull()) continue;
4003 Standard_Integer ir;
4004 for (ir = 1; ir <= Repr->NbItems(); ir++) {
4005 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir);
4006 if (RI.IsNull()) continue;
4007 if (RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
4008 // find name and description for material
4009 Handle(StepRepr_DescriptiveRepresentationItem) DRI =
4010 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI);
4011 aName = DRI->Name();
4013 aDescription = DRI->Description();
4015 aName = aDescription;
4017 if (RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) {
4018 // try to find density for material
4019 Handle(StepRepr_MeasureRepresentationItem) MRI =
4020 Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI);
4021 aDensity = MRI->Measure()->ValueComponent();
4022 aDensName = MRI->Name();
4023 aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name());
4024 StepBasic_Unit aUnit = MRI->Measure()->UnitComponent();
4025 if (!aUnit.IsNull()) {
4026 Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit();
4027 if (DU.IsNull()) continue;
4028 for (Standard_Integer idu = 1; idu <= DU->NbElements(); idu++) {
4029 Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu);
4030 Handle(StepBasic_NamedUnit) NU = DUE->Unit();
4031 if (NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ||
4032 NU->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)))
4034 STEPConstruct_UnitContext anUnitCtx;
4035 anUnitCtx.ComputeFactors(NU);
4036 aDensity = aDensity / (anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor());
4037 // transfer length value for Density from millimeter to santimeter
4038 // in order to result density has dimension gram/(sm*sm*sm)
4039 aDensity = aDensity*1000. / (UnitsMethods::GetCasCadeLengthUnit()
4040 * UnitsMethods::GetCasCadeLengthUnit() * UnitsMethods::GetCasCadeLengthUnit());
4042 if (NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) {
4043 Standard_Real afact = 1.;
4044 if (GetMassConversionFactor(NU, afact))
4046 aDensity = aDensity*afact;
4056 if (aName.IsNull() || aName->Length() == 0)
4058 // find shape label amd create Material link
4060 Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS, graph);
4062 Standard_Integer index = TP->MapIndex(SM);
4064 Handle(Transfer_Binder) binder = TP->MapItem(index);
4065 if (!binder.IsNull())
4066 aSh = TransferBRep::ShapeResult(binder);
4069 if (aSh.IsNull()) continue;
4071 if (!STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
4072 MatTool->SetMaterial(shL, aName, aDescription, aDensity, aDensName, aDensValType);
4075 return Standard_True;
4078 //=======================================================================
4079 //function : collectViewShapes
4080 //purpose : collect all labels of representations in given representation
4081 //=======================================================================
4083 void collectViewShapes(const Handle(XSControl_WorkSession)& theWS,
4084 const Handle(TDocStd_Document)& theDoc,
4085 const Handle(StepRepr_Representation) theRepr,
4086 TDF_LabelSequence& theShapes)
4088 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
4089 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4090 const Interface_Graph& aGraph = aTP->Graph();
4091 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4092 Standard_Integer anIndex = aTP->MapIndex(theRepr);
4095 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
4096 aSh = TransferBRep::ShapeResult(aBinder);
4098 if (!aSh.IsNull()) {
4100 aSTool->FindShape(aSh, aShL);
4102 theShapes.Append(aShL);
4104 Interface_EntityIterator anIter = aGraph.Sharings(theRepr);
4105 for (; anIter.More(); anIter.Next()) {
4106 if (!anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_RepresentationRelationship)))
4108 Handle(StepRepr_RepresentationRelationship) aReprRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(anIter.Value());
4109 if (aReprRelationship->Rep1() != theRepr)
4110 collectViewShapes(theWS, theDoc, aReprRelationship->Rep1(), theShapes);
4114 //=======================================================================
4115 //function : buildClippingPlanes
4117 //=======================================================================
4118 Handle(TCollection_HAsciiString) buildClippingPlanes(const Handle(StepGeom_GeometricRepresentationItem)& theClippingCameraModel,
4119 TDF_LabelSequence& theClippingPlanes,
4120 const Handle(XCAFDoc_ClippingPlaneTool) theTool)
4122 Handle(TCollection_HAsciiString) anExpression = new TCollection_HAsciiString();
4123 NCollection_Sequence<Handle(StepGeom_GeometricRepresentationItem)> aPlanes;
4124 Handle(TCollection_HAsciiString) anOperation = new TCollection_HAsciiString("*");
4127 if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClipping))) {
4128 Handle(StepVisual_CameraModelD3MultiClipping) aCameraModel =
4129 Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(theClippingCameraModel);
4131 if (aCameraModel->ShapeClipping().IsNull())
4132 return anExpression;
4134 // Root of clipping planes tree
4135 if (aCameraModel->ShapeClipping()->Length() == 1) {
4136 Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModelUnion =
4137 aCameraModel->ShapeClipping()->Value(1).CameraModelD3MultiClippingUnion();
4138 if (!aCameraModelUnion.IsNull())
4139 return buildClippingPlanes(aCameraModelUnion, theClippingPlanes, theTool);
4141 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4142 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4145 else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingUnion))) {
4146 Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModel =
4147 Handle(StepVisual_CameraModelD3MultiClippingUnion)::DownCast(theClippingCameraModel);
4148 anOperation = new TCollection_HAsciiString("+");
4149 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4150 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4153 else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingIntersection))) {
4154 Handle(StepVisual_CameraModelD3MultiClippingIntersection) aCameraModel =
4155 Handle(StepVisual_CameraModelD3MultiClippingIntersection)::DownCast(theClippingCameraModel);
4156 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4157 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4161 anExpression->AssignCat("(");
4162 for (Standard_Integer i = 1; i <= aPlanes.Length(); i++) {
4163 Handle(StepGeom_Plane) aPlaneEnt = Handle(StepGeom_Plane)::DownCast(aPlanes.Value(i));
4164 if (!aPlaneEnt.IsNull()) {
4165 Handle(Geom_Plane) aPlane = StepToGeom::MakePlane(aPlaneEnt);
4166 if (!aPlane.IsNull()) {
4167 TDF_Label aPlaneL = theTool->AddClippingPlane(aPlane->Pln(), aPlaneEnt->Name());
4168 theClippingPlanes.Append(aPlaneL);
4169 TCollection_AsciiString anEntry;
4170 TDF_Tool::Entry(aPlaneL, anEntry);
4171 anExpression->AssignCat(new TCollection_HAsciiString(anEntry));
4175 anExpression->AssignCat(buildClippingPlanes(aPlanes.Value(i), theClippingPlanes, theTool));
4177 anExpression->AssignCat(anOperation);
4179 // Insert brace instead of operation after last operand.
4180 anExpression->SetValue(anExpression->Length(), ')');
4181 return anExpression;
4185 //=======================================================================
4186 //function : ReadViews
4188 //=======================================================================
4189 Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const
4191 const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
4192 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4193 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
4194 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(theDoc->Main());
4195 if (aDGTTool.IsNull()) return Standard_False;
4197 Standard_Integer nb = aModel->NbEntities();
4198 for (Standard_Integer i = 1; i <= nb; i++) {
4199 Handle(Standard_Transient) anEnt = aModel->Value(i);
4200 if (!anEnt->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3)))
4202 Handle(XCAFView_Object) anObj = new XCAFView_Object();
4203 // Import attributes of view
4204 Handle(StepVisual_CameraModelD3) aCameraModel = Handle(StepVisual_CameraModelD3)::DownCast(anEnt);
4206 const Handle(XSControl_TransferReader)& aTR = theWS->TransferReader();
4207 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4208 const Interface_Graph& aGraph = aTP->Graph();
4209 // find the proper DraughtingModel
4210 Interface_EntityIterator subs = aGraph.Sharings(aCameraModel);
4211 Handle(StepVisual_DraughtingModel) aDModel;
4212 for (subs.Start(); subs.More() && aDModel.IsNull(); subs.Next())
4214 if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingModel)))
4218 aDModel = Handle(StepVisual_DraughtingModel)::DownCast(subs.Value());
4220 if (!aDModel.IsNull())
4222 XSAlgo::AlgoContainer()->PrepareForTransfer();
4223 STEPControl_ActorRead anActor;
4224 anActor.PrepareUnits(aDModel, aTP);
4227 anObj->SetName(aCameraModel->Name());
4228 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aCameraModel->ViewReferenceSystem());
4229 anObj->SetViewDirection(anAxis->Direction());
4230 anObj->SetUpDirection(anAxis->Direction() ^ anAxis->XDirection());
4231 Handle(StepVisual_ViewVolume) aViewVolume = aCameraModel->PerspectiveOfVolume();
4232 XCAFView_ProjectionType aType = XCAFView_ProjectionType_NoCamera;
4233 if (aViewVolume->ProjectionType() == StepVisual_copCentral)
4234 aType = XCAFView_ProjectionType_Central;
4235 else if (aViewVolume->ProjectionType() == StepVisual_copParallel)
4236 aType = XCAFView_ProjectionType_Parallel;
4237 anObj->SetType(aType);
4238 Handle(Geom_CartesianPoint) aPoint = StepToGeom::MakeCartesianPoint(aViewVolume->ProjectionPoint());
4239 anObj->SetProjectionPoint(aPoint->Pnt());
4240 anObj->SetZoomFactor(aViewVolume->ViewPlaneDistance());
4241 anObj->SetWindowHorizontalSize(aViewVolume->ViewWindow()->SizeInX());
4242 anObj->SetWindowVerticalSize(aViewVolume->ViewWindow()->SizeInY());
4243 if (aViewVolume->FrontPlaneClipping())
4244 anObj->SetFrontPlaneDistance(aViewVolume->FrontPlaneDistance());
4245 if (aViewVolume->BackPlaneClipping())
4246 anObj->SetBackPlaneDistance(aViewVolume->BackPlaneDistance());
4247 anObj->SetViewVolumeSidesClipping(aViewVolume->ViewVolumeSidesClipping());
4249 Handle(StepVisual_CameraModelD3MultiClipping) aClippingCameraModel =
4250 Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(aCameraModel);
4251 TDF_LabelSequence aClippingPlanes;
4252 if (!aClippingCameraModel.IsNull()) {
4253 Handle(TCollection_HAsciiString) aClippingExpression;
4254 Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(theDoc->Main());
4255 aClippingExpression = buildClippingPlanes(aClippingCameraModel, aClippingPlanes, aClippingPlaneTool);
4256 anObj->SetClippingExpression(aClippingExpression);
4259 // Collect shapes and GDTs
4260 if (aDModel.IsNull())
4261 return Standard_False;
4262 TDF_LabelSequence aShapes, aGDTs;
4263 Interface_EntityIterator anIter = aGraph.Shareds(aDModel);
4264 for (; anIter.More(); anIter.Next()) {
4265 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
4266 Handle(StepRepr_MappedItem) anItem = Handle(StepRepr_MappedItem)::DownCast(anIter.Value());
4267 Handle(StepRepr_Representation) aRepr = anItem->MappingSource()->MappedRepresentation();
4268 collectViewShapes(theWS, theDoc, aRepr, aShapes);
4270 else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)) ||
4271 anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout))) {
4272 Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
4273 for (; aDMIAIter.More(); aDMIAIter.Next()) {
4274 if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
4276 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
4277 Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
4279 Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
4281 isFind = myGDTMap.Find(anIter.Value(), aGDTL);
4284 aGDTs.Append(aGDTL);
4287 else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationPlane))) {
4288 Handle(StepVisual_AnnotationPlane) aPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
4289 for (Standard_Integer j = 1; j <= aPlane->NbElements(); j++) {
4290 Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
4291 for (; aDMIAIter.More(); aDMIAIter.Next()) {
4292 if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
4294 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
4295 Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
4297 Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
4299 aGDTs.Append(aGDTL);
4304 TDF_Label aViewL = aViewTool->AddView();
4305 Handle(XCAFDoc_View) aView = XCAFDoc_View::Set(aViewL);
4306 aView->SetObject(anObj);
4307 aViewTool->SetView(aShapes, aGDTs, aClippingPlanes, aViewL);
4308 aViewTool->Lock(aViewL);
4310 return Standard_True;
4313 //=======================================================================
4314 //function : SettleShapeData
4316 //=======================================================================
4318 TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_RepresentationItem)& theItem,
4319 const TDF_Label& theLab,
4320 const Handle(XCAFDoc_ShapeTool)& theShapeTool,
4321 const Handle(Transfer_TransientProcess)& TP) const
4323 TDF_Label aResult = theLab;
4325 Handle(TCollection_HAsciiString) hName = theItem->Name();
4326 if (hName.IsNull() || hName->IsEmpty())
4329 Handle(Transfer_Binder) aBinder = TP->Find(theItem);
4330 if (aBinder.IsNull())
4333 TopoDS_Shape aShape = TransferBRep::ShapeResult(aBinder);
4334 if (aShape.IsNull())
4337 // Allocate sub-Label
4338 aResult = theShapeTool->AddSubShape(theLab, aShape);
4339 if (aResult.IsNull())
4342 TCollection_AsciiString aName = hName->String();
4343 TDataStd_Name::Set(aResult, aName);
4344 theShapeTool->SetShape(aResult, aShape);
4349 //=======================================================================
4350 //function : collectRepresentationItems
4351 //purpose : recursive collection of representation items for given representation
4352 // with all representations, related to it.
4353 //=======================================================================
4355 void collectRepresentationItems(const Interface_Graph& theGraph,
4356 const Handle(StepShape_ShapeRepresentation)& theRepresentation,
4357 NCollection_Sequence<Handle(StepRepr_RepresentationItem)>& theItems)
4359 Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = theRepresentation->Items();
4360 for (Standard_Integer itemIt = aReprItems->Lower(); itemIt <= aReprItems->Upper(); itemIt++)
4361 theItems.Append(aReprItems->Value(itemIt));
4363 Interface_EntityIterator entIt = theGraph.TypedSharings(theRepresentation, STANDARD_TYPE(StepRepr_RepresentationRelationship));
4364 for (entIt.Start(); entIt.More(); entIt.Next())
4366 Handle(StepRepr_RepresentationRelationship) aRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(entIt.Value());
4367 if (aRelationship->Rep1() == theRepresentation)
4369 Handle(StepShape_ShapeRepresentation)
4370 aRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aRelationship->Rep2());
4371 if (!aRepr.IsNull())
4372 collectRepresentationItems(theGraph, aRepr, theItems);
4377 //=======================================================================
4378 //function : ExpandSubShapes
4380 //=======================================================================
4382 void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& ShapeTool,
4383 const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap,
4384 const STEPCAFControl_DataMapOfShapePD& ShapePDMap) const
4386 const Handle(Transfer_TransientProcess)& TP = Reader().WS()->TransferReader()->TransientProcess();
4387 NCollection_DataMap<TopoDS_Shape, Handle(TCollection_HAsciiString)> ShapeNameMap;
4388 TColStd_MapOfTransient aRepItems;
4390 // Read translation control variables
4391 Standard_Boolean doReadSNames = (Interface_Static::IVal("read.stepcaf.subshapes.name") > 0);
4396 const Interface_Graph& Graph = Reader().WS()->Graph();
4398 for (STEPCAFControl_DataMapIteratorOfDataMapOfShapePD it(ShapePDMap); it.More(); it.Next())
4400 const TopoDS_Shape& aRootShape = it.Key();
4401 const Handle(StepBasic_ProductDefinition)& aPDef = it.Value();
4405 // Find SDR by Product
4406 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
4407 Interface_EntityIterator entIt = Graph.TypedSharings(aPDef, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation));
4408 for (entIt.Start(); entIt.More(); entIt.Next())
4410 const Handle(Standard_Transient)& aReferer = entIt.Value();
4411 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aReferer);
4419 // Access shape representation
4420 Handle(StepShape_ShapeRepresentation)
4421 aShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aSDR->UsedRepresentation());
4423 if (aShapeRepr.IsNull())
4426 // Access representation items
4427 NCollection_Sequence<Handle(StepRepr_RepresentationItem)> aReprItems;
4428 collectRepresentationItems(Graph, aShapeRepr, aReprItems);
4430 if (aReprItems.Length() == 0)
4433 if (!ShapeLabelMap.IsBound(aRootShape))
4436 TDF_Label aRootLab = ShapeLabelMap.Find(aRootShape);
4437 // Do not add subshapes to assembly,
4438 // they will be processed with corresponding Shape_Product_Definition of necessary part.
4439 if (ShapeTool->IsAssembly(aRootLab))
4442 StepRepr_SequenceOfRepresentationItem aMSBSeq;
4443 StepRepr_SequenceOfRepresentationItem aSBSMSeq;
4445 // Iterate over the top level representation items collecting the
4446 // topological containers to expand
4447 for (Standard_Integer i = 1; i <= aReprItems.Length(); ++i)
4449 Handle(StepRepr_RepresentationItem) aTRepr = aReprItems.Value(i);
4450 if (aTRepr->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep)))
4451 aMSBSeq.Append(aTRepr);
4452 else if (aTRepr->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel)))
4453 aSBSMSeq.Append(aTRepr);
4456 // Insert intermediate OCAF Labels for SOLIDs in case there are more
4457 // than one Manifold Solid BRep in the Shape Representation
4458 Standard_Boolean doInsertSolidLab = (aMSBSeq.Length() > 1);
4460 // Expand Manifold Solid BReps
4461 for (Standard_Integer i = 1; i <= aMSBSeq.Length(); ++i)
4463 // Put additional Label for SOLID
4464 if (doInsertSolidLab)
4465 SettleShapeData(aMSBSeq.Value(i), aRootLab, ShapeTool, TP);
4467 ExpandManifoldSolidBrep(aRootLab, aMSBSeq.Value(i), TP, ShapeTool);
4470 // Expand Shell-Based Surface Models
4471 for (Standard_Integer i = 1; i <= aSBSMSeq.Length(); ++i)
4472 ExpandSBSM(aRootLab, aSBSMSeq.Value(i), TP, ShapeTool);
4476 //=======================================================================
4477 //function : ExpandManifoldSolidBrep
4479 //=======================================================================
4481 void STEPCAFControl_Reader::ExpandManifoldSolidBrep(TDF_Label& ShapeLab,
4482 const Handle(StepRepr_RepresentationItem)& Repr,
4483 const Handle(Transfer_TransientProcess)& TP,
4484 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4486 // Access outer shell
4487 Handle(StepShape_ManifoldSolidBrep) aMSB = Handle(StepShape_ManifoldSolidBrep)::DownCast(Repr);
4488 Handle(StepShape_ConnectedFaceSet) aShell = aMSB->Outer();
4490 // Expand shell contents to CAF tree
4491 ExpandShell(aShell, ShapeLab, TP, ShapeTool);
4494 //=======================================================================
4495 //function : ExpandSBSM
4497 //=======================================================================
4499 void STEPCAFControl_Reader::ExpandSBSM(TDF_Label& ShapeLab,
4500 const Handle(StepRepr_RepresentationItem)& Repr,
4501 const Handle(Transfer_TransientProcess)& TP,
4502 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4504 Handle(StepShape_ShellBasedSurfaceModel) aSBSM = Handle(StepShape_ShellBasedSurfaceModel)::DownCast(Repr);
4506 // Access boundary shells
4507 Handle(StepShape_HArray1OfShell) aShells = aSBSM->SbsmBoundary();
4508 for (Standard_Integer s = aShells->Lower(); s <= aShells->Upper(); ++s)
4510 const StepShape_Shell& aShell = aShells->Value(s);
4511 Handle(StepShape_ConnectedFaceSet) aCFS;
4512 Handle(StepShape_OpenShell) anOpenShell = aShell.OpenShell();
4513 Handle(StepShape_ClosedShell) aClosedShell = aShell.ClosedShell();
4515 if (!anOpenShell.IsNull())
4518 aCFS = aClosedShell;
4520 ExpandShell(aCFS, ShapeLab, TP, ShapeTool);
4524 //=======================================================================
4525 //function : ExpandShell
4527 //=======================================================================
4529 void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)& Shell,
4531 const Handle(Transfer_TransientProcess)& TP,
4532 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4535 SettleShapeData(Shell, RootLab, ShapeTool, TP);
4538 Handle(StepShape_HArray1OfFace) aFaces = Shell->CfsFaces();
4539 for (Standard_Integer f = aFaces->Lower(); f <= aFaces->Upper(); ++f)
4541 const Handle(StepShape_Face)& aFace = aFaces->Value(f);
4546 SettleShapeData(aFace, RootLab, ShapeTool, TP);
4548 // Access face bounds
4549 Handle(StepShape_HArray1OfFaceBound) aWires = aFace->Bounds();
4550 if (aWires.IsNull())
4552 for (Standard_Integer w = aWires->Lower(); w <= aWires->Upper(); ++w)
4554 const Handle(StepShape_Loop)& aWire = aWires->Value(w)->Bound();
4557 SettleShapeData(aWire, RootLab, ShapeTool, TP);
4559 // Access wire edges
4560 // Currently only EDGE LOOPs are considered (!)
4561 if (!aWire->IsInstance(STANDARD_TYPE(StepShape_EdgeLoop)))
4565 Handle(StepShape_EdgeLoop) anEdgeLoop = Handle(StepShape_EdgeLoop)::DownCast(aWire);
4566 Handle(StepShape_HArray1OfOrientedEdge) anEdges = anEdgeLoop->EdgeList();
4567 for (Standard_Integer e = anEdges->Lower(); e <= anEdges->Upper(); ++e)
4569 Handle(StepShape_OrientedEdge) anOrientedEdge = anEdges->Value(e);
4570 if (anOrientedEdge.IsNull())
4572 Handle(StepShape_Edge) anEdge = anOrientedEdge->EdgeElement();
4573 if (anEdge.IsNull())
4577 SettleShapeData(anEdge, RootLab, ShapeTool, TP);
4580 Handle(StepShape_Vertex) aV1 = anEdge->EdgeStart();
4581 Handle(StepShape_Vertex) aV2 = anEdge->EdgeEnd();
4584 SettleShapeData(aV1, RootLab, ShapeTool, TP);
4585 SettleShapeData(aV2, RootLab, ShapeTool, TP);
4591 //=======================================================================
4592 //function : SetColorMode
4594 //=======================================================================
4596 void STEPCAFControl_Reader::SetColorMode(const Standard_Boolean colormode)
4598 myColorMode = colormode;
4601 //=======================================================================
4602 //function : GetColorMode
4604 //=======================================================================
4606 Standard_Boolean STEPCAFControl_Reader::GetColorMode() const
4611 //=======================================================================
4612 //function : SetNameMode
4614 //=======================================================================
4616 void STEPCAFControl_Reader::SetNameMode(const Standard_Boolean namemode)
4618 myNameMode = namemode;
4621 //=======================================================================
4622 //function : GetNameMode
4624 //=======================================================================
4626 Standard_Boolean STEPCAFControl_Reader::GetNameMode() const
4631 //=======================================================================
4632 //function : SetLayerMode
4634 //=======================================================================
4636 void STEPCAFControl_Reader::SetLayerMode(const Standard_Boolean layermode)
4638 myLayerMode = layermode;
4641 //=======================================================================
4642 //function : GetLayerMode
4644 //=======================================================================
4646 Standard_Boolean STEPCAFControl_Reader::GetLayerMode() const
4651 //=======================================================================
4652 //function : SetPropsMode
4654 //=======================================================================
4656 void STEPCAFControl_Reader::SetPropsMode(const Standard_Boolean propsmode)
4658 myPropsMode = propsmode;
4661 //=======================================================================
4662 //function : GetPropsMode
4664 //=======================================================================
4666 Standard_Boolean STEPCAFControl_Reader::GetPropsMode() const
4671 //=======================================================================
4672 //function : SetSHUOMode
4674 //=======================================================================
4676 void STEPCAFControl_Reader::SetSHUOMode(const Standard_Boolean mode)
4681 //=======================================================================
4682 //function : GetSHUOMode
4684 //=======================================================================
4686 Standard_Boolean STEPCAFControl_Reader::GetSHUOMode() const
4691 //=======================================================================
4692 //function : SetGDTMode
4694 //=======================================================================
4696 void STEPCAFControl_Reader::SetGDTMode(const Standard_Boolean gdtmode)
4698 myGDTMode = gdtmode;
4701 //=======================================================================
4702 //function : GetGDTMode
4704 //=======================================================================
4706 Standard_Boolean STEPCAFControl_Reader::GetGDTMode() const
4712 //=======================================================================
4713 //function : SetMatMode
4715 //=======================================================================
4717 void STEPCAFControl_Reader::SetMatMode(const Standard_Boolean matmode)
4719 myMatMode = matmode;
4722 //=======================================================================
4723 //function : GetMatMode
4725 //=======================================================================
4727 Standard_Boolean STEPCAFControl_Reader::GetMatMode() const
4732 //=======================================================================
4733 //function : SetViewMode
4735 //=======================================================================
4737 void STEPCAFControl_Reader::SetViewMode(const Standard_Boolean viewmode)
4739 myViewMode = viewmode;
4742 //=======================================================================
4743 //function : GetViewMode
4745 //=======================================================================
4747 Standard_Boolean STEPCAFControl_Reader::GetViewMode() const