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.
16 #include <STEPCAFControl_Reader.hxx>
18 #include <BRep_Builder.hxx>
19 #include <Geom_Axis2Placement.hxx>
20 #include <Geom_CartesianPoint.hxx>
21 #include <Geom_Plane.hxx>
22 #include <Interface_EntityIterator.hxx>
23 #include <StepData_StepModel.hxx>
24 #include <HeaderSection_FileSchema.hxx>
25 #include <Interface_Static.hxx>
26 #include <Message_ProgressScope.hxx>
27 #include <NCollection_DataMap.hxx>
28 #include <OSD_Path.hxx>
29 #include <Quantity_ColorRGBA.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_DocumentFile.hxx>
36 #include <StepBasic_MeasureValueMember.hxx>
37 #include <StepBasic_NamedUnit.hxx>
38 #include <StepBasic_Product.hxx>
39 #include <StepBasic_ProductDefinition.hxx>
40 #include <StepBasic_ProductDefinitionFormation.hxx>
41 #include <StepBasic_ProductDefinitionWithAssociatedDocuments.hxx>
42 #include <StepBasic_SiUnitAndLengthUnit.hxx>
43 #include <StepData_GlobalFactors.hxx>
44 #include <STEPCAFControl_Controller.hxx>
45 #include <STEPCAFControl_DataMapOfPDExternFile.hxx>
46 #include <STEPCAFControl_DataMapOfShapePD.hxx>
47 #include <STEPCAFControl_ExternFile.hxx>
48 #include <STEPConstruct.hxx>
49 #include <STEPConstruct_ExternRefs.hxx>
50 #include <STEPConstruct_Styles.hxx>
51 #include <STEPConstruct_Tool.hxx>
52 #include <STEPConstruct_UnitContext.hxx>
53 #include <STEPConstruct_ValidationProps.hxx>
54 #include <STEPControl_ActorRead.hxx>
55 #include <STEPControl_Reader.hxx>
56 #include <StepGeom_Axis2Placement3d.hxx>
57 #include <StepGeom_Direction.hxx>
58 #include <StepDimTol_AngularityTolerance.hxx>
59 #include <StepDimTol_CircularRunoutTolerance.hxx>
60 #include <StepDimTol_CoaxialityTolerance.hxx>
61 #include <StepDimTol_ConcentricityTolerance.hxx>
62 #include <StepDimTol_CylindricityTolerance.hxx>
63 #include <StepDimTol_Datum.hxx>
64 #include <StepDimTol_DatumFeature.hxx>
65 #include <StepDimTol_DatumReference.hxx>
66 #include <StepDimTol_DatumReferenceElement.hxx>
67 #include <StepDimTol_DatumSystem.hxx>
68 #include <StepDimTol_FlatnessTolerance.hxx>
69 #include <StepDimTol_GeometricTolerance.hxx>
70 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
71 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
72 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
73 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol.hxx>
74 #include <StepDimTol_GeoTolAndGeoTolWthMaxTol.hxx>
75 #include <StepDimTol_HArray1OfDatumReference.hxx>
76 #include <StepDimTol_LineProfileTolerance.hxx>
77 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
78 #include <StepDimTol_ParallelismTolerance.hxx>
79 #include <StepDimTol_PerpendicularityTolerance.hxx>
80 #include <StepDimTol_PositionTolerance.hxx>
81 #include <StepDimTol_ProjectedZoneDefinition.hxx>
82 #include <StepDimTol_RoundnessTolerance.hxx>
83 #include <StepDimTol_RunoutZoneDefinition.hxx>
84 #include <StepDimTol_StraightnessTolerance.hxx>
85 #include <StepDimTol_SurfaceProfileTolerance.hxx>
86 #include <StepDimTol_SymmetryTolerance.hxx>
87 #include <StepDimTol_ToleranceZone.hxx>
88 #include <StepDimTol_ToleranceZoneForm.hxx>
89 #include <StepDimTol_TotalRunoutTolerance.hxx>
90 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
91 #include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
92 #include <StepDimTol_GeometricToleranceWithMaximumTolerance.hxx>
93 #include <StepGeom_Plane.hxx>
94 #include <StepDimTol_PlacedDatumTargetFeature.hxx>
95 #include <StepRepr_DerivedShapeAspect.hxx>
96 #include <StepRepr_DescriptiveRepresentationItem.hxx>
97 #include <StepRepr_MappedItem.hxx>
98 #include <StepRepr_MeasureRepresentationItem.hxx>
99 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
100 #include <StepRepr_ProductDefinitionShape.hxx>
101 #include <StepRepr_PropertyDefinition.hxx>
102 #include <StepRepr_RepresentationItem.hxx>
103 #include <StepRepr_RepresentationMap.hxx>
104 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
105 #include <StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI.hxx>
106 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
107 #include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI.hxx>
108 #include <StepRepr_SequenceOfRepresentationItem.hxx>
109 #include <StepRepr_ShapeAspect.hxx>
110 #include <StepRepr_ShapeAspectDerivingRelationship.hxx>
111 #include <StepRepr_AllAroundShapeAspect.hxx>
112 #include <StepRepr_ShapeAspectRelationship.hxx>
113 #include <StepRepr_ShapeRepresentationRelationship.hxx>
114 #include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
115 #include <StepRepr_ValueRange.hxx>
116 #include <StepRepr_FeatureForDatumTargetRelationship.hxx>
117 #include <StepShape_AdvancedFace.hxx>
118 #include <StepShape_AdvancedBrepShapeRepresentation.hxx>
119 #include <StepShape_AngularSize.hxx>
120 #include <StepShape_AngularLocation.hxx>
121 #include <StepShape_ClosedShell.hxx>
122 #include <StepShape_ConnectedFaceSet.hxx>
123 #include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
124 #include <StepShape_DimensionalCharacteristicRepresentation.hxx>
125 #include <StepShape_DimensionalSizeWithPath.hxx>
126 #include <StepShape_DimensionalLocationWithPath.hxx>
127 #include <StepShape_ShapeRepresentationWithParameters.hxx>
128 #include <StepShape_DimensionalSize.hxx>
129 #include <StepShape_DimensionalLocation.hxx>
130 #include <StepShape_EdgeCurve.hxx>
131 #include <StepShape_EdgeLoop.hxx>
132 #include <StepShape_GeometricSet.hxx>
133 #include <StepShape_HArray1OfFace.hxx>
134 #include <StepShape_HArray1OfFaceBound.hxx>
135 #include <StepShape_HArray1OfOrientedEdge.hxx>
136 #include <StepShape_Loop.hxx>
137 #include <StepShape_ManifoldSolidBrep.hxx>
138 #include <StepShape_PlusMinusTolerance.hxx>
139 #include <StepShape_QualifiedRepresentationItem.hxx>
140 #include <StepShape_OpenShell.hxx>
141 #include <StepShape_ShapeDefinitionRepresentation.hxx>
142 #include <StepShape_ShapeDimensionRepresentation.hxx>
143 #include <StepShape_ShapeRepresentation.hxx>
144 #include <StepShape_ShellBasedSurfaceModel.hxx>
145 #include <StepShape_SolidModel.hxx>
146 #include <StepShape_ToleranceMethodDefinition.hxx>
147 #include <StepShape_ToleranceValue.hxx>
148 #include <StepShape_ValueFormatTypeQualifier.hxx>
149 #include <StepShape_Vertex.hxx>
150 #include <StepToGeom.hxx>
151 #include <StepVisual_AnnotationPlane.hxx>
152 #include <StepVisual_CameraModelD3MultiClipping.hxx>
153 #include <StepVisual_CameraModelD3MultiClippingIntersection.hxx>
154 #include <StepVisual_CameraModelD3MultiClippingUnion.hxx>
155 #include <StepVisual_HArray1OfCameraModelD3MultiClippingInterectionSelect.hxx>
156 #include <StepVisual_HArray1OfCameraModelD3MultiClippingUnionSelect.hxx>
157 #include <StepVisual_DraughtingCallout.hxx>
158 #include <StepVisual_DraughtingCalloutElement.hxx>
159 #include <StepVisual_DraughtingModel.hxx>
160 #include <StepVisual_Invisibility.hxx>
161 #include <StepVisual_PlanarBox.hxx>
162 #include <StepVisual_PresentationLayerAssignment.hxx>
163 #include <StepVisual_PresentationStyleByContext.hxx>
164 #include <StepVisual_RepositionedTessellatedGeometricSet.hxx>
165 #include <StepVisual_StyleContextSelect.hxx>
166 #include <StepVisual_StyledItem.hxx>
167 #include <StepVisual_ViewVolume.hxx>
168 #include <StepShape_TypeQualifier.hxx>
169 #include <TCollection_AsciiString.hxx>
170 #include <TCollection_HAsciiString.hxx>
171 #include <TColStd_HArray1OfReal.hxx>
172 #include <TColStd_HSequenceOfTransient.hxx>
173 #include <TColStd_MapOfTransient.hxx>
174 #include <TColStd_SequenceOfHAsciiString.hxx>
175 #include <TDataStd_Name.hxx>
176 #include <TDataStd_TreeNode.hxx>
177 #include <TDF_Label.hxx>
178 #include <TDF_Tool.hxx>
179 #include <TDocStd_Document.hxx>
180 #include <TopExp_Explorer.hxx>
181 #include <TopoDS.hxx>
182 #include <TopoDS_Compound.hxx>
183 #include <TopoDS_Iterator.hxx>
184 #include <TopoDS_Shape.hxx>
185 #include <TopTools_MapOfShape.hxx>
186 #include <Transfer_Binder.hxx>
187 #include <Transfer_TransientProcess.hxx>
188 #include <TransferBRep.hxx>
189 #include <UnitsMethods.hxx>
190 #include <XCAFDoc_Area.hxx>
191 #include <XCAFDoc_Centroid.hxx>
192 #include <XCAFDoc_ClippingPlaneTool.hxx>
193 #include <XCAFDoc_ColorTool.hxx>
194 #include <XCAFDoc_DataMapOfShapeLabel.hxx>
195 #include <XCAFDoc_DimTolTool.hxx>
196 #include <XCAFDoc_Dimension.hxx>
197 #include <XCAFDoc_Datum.hxx>
198 #include <XCAFDoc_GeomTolerance.hxx>
199 #include <XCAFDoc_DocumentTool.hxx>
200 #include <XCAFDoc_GraphNode.hxx>
201 #include <XCAFDoc_LayerTool.hxx>
202 #include <XCAFDoc_MaterialTool.hxx>
203 #include <XCAFDoc_ShapeTool.hxx>
204 #include <XCAFDoc_View.hxx>
205 #include <XCAFDoc_ViewTool.hxx>
206 #include <XCAFDoc_Volume.hxx>
207 #include <XCAFDimTolObjects_DimensionObject.hxx>
208 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
209 #include <XCAFDimTolObjects_DatumObject.hxx>
210 #include <XCAFView_Object.hxx>
211 #include <XSAlgo.hxx>
212 #include <XSAlgo_AlgoContainer.hxx>
213 #include <XSControl_TransferReader.hxx>
214 #include <XSControl_WorkSession.hxx>
215 #include <StepAP242_DraughtingModelItemAssociation.hxx>
216 #include <StepAP242_GeometricItemSpecificUsage.hxx>
217 #include <StepGeom_CartesianPoint.hxx>
218 #include <STEPCAFControl_GDTProperty.hxx>
219 #include <StepVisual_TessellatedAnnotationOccurrence.hxx>
220 #include <StepVisual_TessellatedGeometricSet.hxx>
221 #include <StepVisual_TessellatedCurveSet.hxx>
222 #include <StepVisual_CoordinatesList.hxx>
223 #include <NCollection_Vector.hxx>
224 #include <StepVisual_OverRidingStyledItem.hxx>
225 #include <StepVisual_ContextDependentOverRidingStyledItem.hxx>
226 #include <StepRepr_ShapeRepresentationRelationshipWithTransformation.hxx>
227 #include <StepRepr_ItemDefinedTransformation.hxx>
229 #include <TColgp_HArray1OfXYZ.hxx>
230 #include <BRepBuilderAPI_MakeEdge.hxx>
231 #include <Transfer_ActorOfTransientProcess.hxx>
232 #include <Bnd_Box.hxx>
233 #include <BRepBndLib.hxx>
235 // skl 21.08.2003 for reading G&DT
236 //#include <StepRepr_CompoundItemDefinition.hxx>
237 //#include <StepRepr_CompoundItemDefinitionMember.hxx>
238 //#include <StepBasic_ConversionBasedUnit.hxx>
239 //#include <TDataStd_Real.hxx>
240 //#include <TDataStd_Constraint.hxx>
241 //#include <TDataStd_ConstraintEnum.hxx>
242 //#include <TNaming_Tool.hxx>
243 //#include <AIS_InteractiveObject.hxx>
244 //#include <TPrsStd_ConstraintTools.hxx>
245 //#include <AIS_DiameterDimension.hxx>
246 //#include <TPrsStd_Position.hxx>
247 //#include <TPrsStd_AISPresentation.hxx>
248 //#include <TNaming_Builder.hxx>
250 //! Converts address of the passed shape (TShape) to string.
251 //! \param theShape [in] Shape to dump.
252 //! \return corresponding string.
253 TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape)
255 std::string anAddrStr;
256 std::ostringstream ost;
257 ost << theShape.TShape().get();
258 anAddrStr = ost.str();
260 TCollection_AsciiString aStr =
261 TCollection_AsciiString("[").Cat(anAddrStr.c_str()).Cat("]");
267 //=======================================================================
268 //function : STEPCAFControl_Reader
270 //=======================================================================
272 STEPCAFControl_Reader::STEPCAFControl_Reader()
273 : myColorMode(Standard_True),
274 myNameMode(Standard_True),
275 myLayerMode(Standard_True),
276 myPropsMode(Standard_True),
277 mySHUOMode(Standard_False),
278 myGDTMode(Standard_True),
279 myMatMode(Standard_True),
280 myViewMode(Standard_True)
282 STEPCAFControl_Controller::Init();
286 //=======================================================================
287 //function : STEPCAFControl_Reader
289 //=======================================================================
291 STEPCAFControl_Reader::STEPCAFControl_Reader(const Handle(XSControl_WorkSession)& WS,
292 const Standard_Boolean scratch)
293 : myColorMode(Standard_True),
294 myNameMode(Standard_True),
295 myLayerMode(Standard_True),
296 myPropsMode(Standard_True),
297 mySHUOMode(Standard_False),
298 myGDTMode(Standard_True),
299 myMatMode(Standard_True),
300 myViewMode(Standard_True)
302 STEPCAFControl_Controller::Init();
306 //=======================================================================
307 //function : ~STEPCAFControl_Reader
309 //=======================================================================
310 STEPCAFControl_Reader::~STEPCAFControl_Reader()
315 //=======================================================================
318 //=======================================================================
320 void STEPCAFControl_Reader::Init(const Handle(XSControl_WorkSession)& WS,
321 const Standard_Boolean scratch)
323 // necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
324 myReader.SetWS(WS, scratch);
329 //=======================================================================
330 //function : convertName
332 //=======================================================================
333 TCollection_ExtendedString STEPCAFControl_Reader::convertName (const TCollection_AsciiString& theName) const
335 // If source code page is not a NoConversion
336 // the string is treated as having UTF-8 coding,
337 // else each character is copied to ExtCharacter.
338 return TCollection_ExtendedString (theName, myReader.StepModel()->SourceCodePage() != Resource_FormatType_NoConversion);
341 //=======================================================================
342 //function : ReadFile
344 //=======================================================================
345 IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile (const Standard_CString theFileName)
347 return myReader.ReadFile (theFileName);
350 //=======================================================================
351 //function : ReadStream
353 //=======================================================================
354 IFSelect_ReturnStatus STEPCAFControl_Reader::ReadStream (const Standard_CString theName,
355 std::istream& theIStream)
357 return myReader.ReadStream (theName, theIStream);
360 //=======================================================================
361 //function : NbRootsForTransfer
363 //=======================================================================
365 Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer()
367 return myReader.NbRootsForTransfer();
371 //=======================================================================
372 //function : TransferOneRoot
374 //=======================================================================
376 Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer num,
377 const Handle(TDocStd_Document) &doc,
378 const Message_ProgressRange& theProgress)
380 TDF_LabelSequence Lseq;
381 return Transfer (myReader, num, doc, Lseq, Standard_False, theProgress);
385 //=======================================================================
386 //function : Transfer
388 //=======================================================================
390 Standard_Boolean STEPCAFControl_Reader::Transfer (const Handle(TDocStd_Document) &doc,
391 const Message_ProgressRange& theProgress)
393 TDF_LabelSequence Lseq;
394 return Transfer (myReader, 0, doc, Lseq, Standard_False, theProgress);
398 //=======================================================================
401 //=======================================================================
403 Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename,
404 const Handle(TDocStd_Document) &doc,
405 const Message_ProgressRange& theProgress)
407 if (ReadFile (filename) != IFSelect_RetDone)
409 return Standard_False;
411 return Transfer (doc, theProgress);
415 //=======================================================================
418 //=======================================================================
420 Standard_Boolean STEPCAFControl_Reader::Perform (const TCollection_AsciiString &filename,
421 const Handle(TDocStd_Document) &doc,
422 const Message_ProgressRange& theProgress)
424 if ( ReadFile (filename.ToCString()) != IFSelect_RetDone)
426 return Standard_False;
428 return Transfer (doc, theProgress);
432 //=======================================================================
433 //function : ExternFiles
435 //=======================================================================
437 const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& STEPCAFControl_Reader::ExternFiles() const
443 //=======================================================================
444 //function : ExternFile
446 //=======================================================================
448 Standard_Boolean STEPCAFControl_Reader::ExternFile(const Standard_CString name,
449 Handle(STEPCAFControl_ExternFile) &ef) const
452 if (myFiles.IsEmpty() || !myFiles.IsBound(name))
453 return Standard_False;
454 ef = myFiles.Find(name);
455 return Standard_True;
459 //=======================================================================
462 //=======================================================================
464 STEPControl_Reader &STEPCAFControl_Reader::ChangeReader()
470 //=======================================================================
473 //=======================================================================
475 const STEPControl_Reader &STEPCAFControl_Reader::Reader() const
481 //=======================================================================
482 //function : FillShapesMap
483 //purpose : auxiliary: fill a map by all compounds and their components
484 //=======================================================================
486 static void FillShapesMap(const TopoDS_Shape &S, TopTools_MapOfShape &map)
492 if (S.ShapeType() != TopAbs_COMPOUND) return;
493 for (TopoDS_Iterator it(S); it.More(); it.Next())
494 FillShapesMap(it.Value(), map);
497 //=======================================================================
498 //function : prepareUnits
500 //=======================================================================
501 void STEPCAFControl_Reader::prepareUnits(const Handle(StepData_StepModel)& theModel,
502 const Handle(TDocStd_Document)& theDoc) const
504 Standard_Real aScaleFactorMM = 1.;
505 if (!XCAFDoc_DocumentTool::GetLengthUnit(theDoc, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter))
507 XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
508 aScaleFactorMM = UnitsMethods::GetCasCadeLengthUnit();
509 // Sets length unit to the document
510 XCAFDoc_DocumentTool::SetLengthUnit(theDoc, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter);
512 theModel->SetLocalLengthUnit(aScaleFactorMM);
515 //=======================================================================
516 //function : Transfer
517 //purpose : basic working method
518 //=======================================================================
520 Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
521 const Standard_Integer nroot,
522 const Handle(TDocStd_Document) &doc,
523 TDF_LabelSequence &Lseq,
524 const Standard_Boolean asOne,
525 const Message_ProgressRange& theProgress)
527 reader.ClearShapes();
528 Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(reader.Model());
529 prepareUnits(aModel, doc);
533 Standard_Integer num = reader.NbRootsForTransfer();
534 if (num <=0) return Standard_False;
536 Message_ProgressScope aPSRoot (theProgress, NULL, 2);
539 if (nroot > num) return Standard_False;
540 reader.TransferOneRoot (nroot, aPSRoot.Next());
543 Message_ProgressScope aPS (aPSRoot.Next(), NULL, num);
544 for (i = 1; i <= num && aPS.More(); i++)
545 reader.TransferOneRoot (i, aPS.Next());
547 if (aPSRoot.UserBreak())
548 return Standard_False;
550 num = reader.NbShapes();
551 if (num <= 0) return Standard_False;
553 // Fill a map of (top-level) shapes resulting from that transfer
554 // Only these shapes will be considered further
555 TopTools_MapOfShape ShapesMap, NewShapesMap;
556 for (i = 1; i <= num; i++) FillShapesMap(reader.Shape(i), ShapesMap);
558 // Collect information on shapes originating from SDRs
559 // this will be used to distinguish compounds representing assemblies
560 // from the ones representing hybrid models and shape sets
561 STEPCAFControl_DataMapOfShapePD ShapePDMap;
562 STEPCAFControl_DataMapOfPDExternFile PDFileMap;
563 const Handle(Transfer_TransientProcess) &TP = reader.WS()->TransferReader()->TransientProcess();
564 Standard_Integer nb = aModel->NbEntities();
566 Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
568 for (i = 1; i <= nb; i++) {
569 Handle(Standard_Transient) enti = aModel->Value(i);
570 if (enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
571 // sequence for acceleration ReadMaterials
572 SeqPDS->Append(enti);
574 if (enti->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) {
575 Handle(StepBasic_ProductDefinition) PD =
576 Handle(StepBasic_ProductDefinition)::DownCast(enti);
577 Standard_Integer index = TP->MapIndex(PD);
579 Handle(Transfer_Binder) binder = TP->MapItem(index);
580 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
581 if (!S.IsNull() && ShapesMap.Contains(S)) {
583 ShapePDMap.Bind(S, PD);
584 Handle(STEPCAFControl_ExternFile) EF;
585 PDFileMap.Bind(PD, EF);
589 if (enti->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) {
590 Standard_Integer index = TP->MapIndex(enti);
592 Handle(Transfer_Binder) binder = TP->MapItem(index);
593 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
594 if (!S.IsNull() && ShapesMap.Contains(S))
600 // get file name and directory name of the main file
601 OSD_Path mainfile(reader.WS()->LoadedFile());
602 TCollection_AsciiString aMainName;
603 aMainName = mainfile.Name() + mainfile.Extension();
604 mainfile.SetName("");
605 mainfile.SetExtension("");
606 TCollection_AsciiString dpath;
607 mainfile.SystemName(dpath);
609 // Load external references (only for relevant SDRs)
610 // and fill map SDR -> extern file
611 STEPConstruct_ExternRefs ExtRefs(reader.WS());
612 ExtRefs.LoadExternRefs();
613 Message_ProgressScope aPSE (aPSRoot.Next(), NULL, ExtRefs.NbExternRefs());
614 for (i = 1; i <= ExtRefs.NbExternRefs() && aPSE.More(); i++)
616 Message_ProgressRange aRange = aPSE.Next();
617 // check extern ref format
618 Handle(TCollection_HAsciiString) format = ExtRefs.Format(i);
619 if (!format.IsNull()) {
620 static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString("STEP AP203");
621 static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString("STEP AP214");
622 if (!format->IsSameString(ap203, Standard_False) &&
623 !format->IsSameString(ap214, Standard_False)) {
625 std::cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << std::endl;
632 else std::cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << std::endl;
635 // get and check filename of the current extern ref
636 const Standard_CString filename = ExtRefs.FileName(i);
639 std::cout << "filename=" << filename << std::endl;
642 if (!filename || !filename[0]) {
644 std::cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << std::endl;
646 continue; // not a valid extern ref
649 // compute true path to the extern file
650 TCollection_AsciiString fullname = OSD_Path::AbsolutePath(dpath, filename);
651 if (fullname.Length() <= 0) fullname = filename;
653 // check for not the same file
654 TCollection_AsciiString aMainFullName = OSD_Path::AbsolutePath(dpath, aMainName);
655 if (TCollection_AsciiString::IsSameString(aMainFullName,fullname,Standard_False)) {
656 TP->AddWarning(ExtRefs.DocFile(i), "External reference file is the same main file");
657 continue; // not a valid extern ref
662 char *mainfile = reader.WS()->LoadedFile();
663 if ( ! mainfile ) mainfile = "";
664 Standard_Integer slash = 0;
665 for ( Standard_Integer k=0; mainfile[k]; k++ )
666 if ( mainfile[k] == '/' ) slash = k;
667 strncpy ( fullname, mainfile, slash );
668 sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename );
671 // get and check PD associated with the current extern ref
672 Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i);
673 if (PD.IsNull()) continue; // not a valid extern ref
674 if (!PDFileMap.IsBound(PD)) continue; // this PD is not concerned by current transfer
676 // read extern file (or use existing data) and record its data
677 Handle(STEPCAFControl_ExternFile) EF =
678 ReadExternFile (filename, fullname.ToCString(), doc, aRange);
679 PDFileMap.Bind (PD, EF);
682 // and insert them to the document
683 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
684 if (STool.IsNull()) return Standard_False;
686 Lseq.Append(AddShape(reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap));
688 for (i = 1; i <= num; i++) {
689 Lseq.Append(AddShape(reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap));
695 ReadColors(reader.WS(), doc);
699 ReadNames(reader.WS(), doc, PDFileMap);
701 // read validation props
703 ReadValProps(reader.WS(), doc, PDFileMap);
707 ReadLayers(reader.WS(), doc);
709 // read SHUO entities from STEP model
711 ReadSHUOs(reader.WS(), doc, PDFileMap);
713 // read GDT entities from STEP model
715 ReadGDTs(reader.WS(), doc);
717 // read Material entities from STEP model
719 ReadMaterials(reader.WS(), doc, SeqPDS);
721 // read View entities from STEP model
723 ReadViews(reader.WS(), doc);
725 // Expand resulting CAF structure for sub-shapes (optionally with their
726 // names) if requested
727 ExpandSubShapes(STool, ShapePDMap);
729 // Update assembly compounds
730 STool->UpdateAssemblies();
731 return Standard_True;
734 //=======================================================================
735 //function : AddShape
737 //=======================================================================
739 TDF_Label STEPCAFControl_Reader::AddShape(const TopoDS_Shape &S,
740 const Handle(XCAFDoc_ShapeTool) &STool,
741 const TopTools_MapOfShape &NewShapesMap,
742 const STEPCAFControl_DataMapOfShapePD &ShapePDMap,
743 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap)
745 // if shape has already been mapped, just return corresponding label
746 if (myMap.IsBound(S)) {
747 return myMap.Find(S);
750 // if shape is located, create instance
751 if (!S.Location().IsIdentity()) {
755 AddShape(S0, STool, NewShapesMap, ShapePDMap, PDFileMap);
756 TDF_Label L = STool->AddShape(S, Standard_False); // should create reference
761 // if shape is not compound, simple add it
762 if (S.ShapeType() != TopAbs_COMPOUND) {
763 TDF_Label L = STool->AddShape(S, Standard_False);
768 // for compounds, compute number of subshapes and check whether this is assembly
769 Standard_Boolean isAssembly = Standard_False;
770 Standard_Integer nbComponents = 0;
772 for (it.Initialize(S); it.More() && !isAssembly; it.Next(), nbComponents++) {
773 TopoDS_Shape Sub0 = it.Value();
776 if (NewShapesMap.Contains(Sub0)) isAssembly = Standard_True;
779 // if(nbComponents>0) isAssembly = Standard_True;
781 // check whether it has associated external ref
782 TColStd_SequenceOfHAsciiString SHAS;
783 if (ShapePDMap.IsBound(S) && PDFileMap.IsBound(ShapePDMap.Find(S))) {
784 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(ShapePDMap.Find(S));
786 // (store information on extern refs in the document)
787 SHAS.Append(EF->GetName());
788 // if yes, just return corresponding label
789 if (!EF->GetLabel().IsNull()) {
790 // but if components >0, ignore extern ref!
791 if (nbComponents <= 0) {
792 myMap.Bind(S, EF->GetLabel());
793 STool->SetExternRefs(EF->GetLabel(), SHAS);
794 return EF->GetLabel();
798 if (!EF->GetLabel().IsNull())
799 std::cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << std::endl;
800 else if (nbComponents <= 0)
801 std::cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << std::endl;
806 // add compound either as a whole,
808 TDF_Label L = STool->AddShape(S, Standard_False);
809 if (SHAS.Length() > 0) STool->SetExternRefs(L, SHAS);
814 // or as assembly, component-by-component
815 TDF_Label L = STool->NewShape();
817 for (it.Initialize(S); it.More(); it.Next(), nbComponents++) {
818 TopoDS_Shape Sub0 = it.Value();
821 TDF_Label subL = AddShape(Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap);
822 if (!subL.IsNull()) {
823 TDF_Label instL = STool->AddComponent(L, subL, it.Value().Location());
824 if (!myMap.IsBound(it.Value())) {
825 myMap.Bind(it.Value(), instL);
829 if (SHAS.Length() > 0) STool->SetExternRefs(L, SHAS);
831 //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941
836 //=======================================================================
837 //function : ReadExternFile
839 //=======================================================================
841 Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const Standard_CString file,
842 const Standard_CString fullname,
843 const Handle(TDocStd_Document)& doc,
844 const Message_ProgressRange& theProgress)
846 // if the file is already read, associate it with SDR
847 if (myFiles.IsBound(file)) {
848 return myFiles.ChangeFind(file);
852 std::cout << "Reading extern file: " << fullname << std::endl;
855 // create new WorkSession and Reader
856 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
857 newWS->SelectNorm("STEP");
858 STEPControl_Reader sr(newWS, Standard_False);
860 // start to fill the resulting ExternFile structure
861 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
863 EF->SetName(new TCollection_HAsciiString(file));
866 EF->SetLoadStatus(sr.ReadFile(fullname));
868 // transfer in single-result mode
869 if (EF->GetLoadStatus() == IFSelect_RetDone) {
870 TDF_LabelSequence labels;
871 EF->SetTransferStatus (Transfer (sr, 0, doc, labels, Standard_False, theProgress));
872 if (labels.Length() > 0) EF->SetLabel (labels.Value(1));
875 // add read file to dictionary
876 myFiles.Bind(file, EF);
881 //=======================================================================
882 //function : findStyledSR
883 //purpose : auxiliary
884 //=======================================================================
885 static void findStyledSR(const Handle(StepVisual_StyledItem) &style,
886 Handle(StepShape_ShapeRepresentation)& aSR)
888 // search Shape Representation for component styled item
889 for (Standard_Integer j = 1; j <= style->NbStyles(); j++) {
890 Handle(StepVisual_PresentationStyleByContext) PSA =
891 Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue(j));
894 StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext();
895 Handle(StepShape_ShapeRepresentation) aCurrentSR =
896 Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation());
897 if (aCurrentSR.IsNull())
905 //=======================================================================
906 //function : propagateColorToParts
907 //purpose : auxiliary, propagate color styles from assemblies to parts
908 //=======================================================================
910 static void propagateColorToParts(const Handle(XCAFDoc_ShapeTool)& theSTool,
911 const Handle(XCAFDoc_ColorTool)& theCTool,
912 const TDF_Label& theRoot)
914 // collect components to propagate
915 TDF_LabelSequence aComponents;
916 if (theRoot.IsEqual(theSTool->Label()))
917 theSTool->GetFreeShapes(aComponents);
919 theSTool->GetComponents(theRoot, aComponents);
921 // iterate each component
922 for (TDF_LabelSequence::Iterator anIt(aComponents); anIt.More(); anIt.Next())
924 // get original label
925 TDF_Label anOriginalL = anIt.Value();
926 theSTool->GetReferredShape(anOriginalL, anOriginalL);
928 // propagate to components without own colors
929 TDF_Label aColorL, aDummyColorL;
930 for (Standard_Integer aType = 1; aType <= 3; aType++)
932 if (theCTool->GetColor(theRoot, (XCAFDoc_ColorType)aType, aColorL) &&
933 !theCTool->GetColor(anOriginalL, (XCAFDoc_ColorType)aType, aDummyColorL))
934 theCTool->SetColor(anOriginalL, aColorL, (XCAFDoc_ColorType)aType);
936 if (!theCTool->IsVisible(theRoot))
937 theCTool->SetVisibility(anOriginalL, Standard_False);
939 // propagate to next level children
940 if (theSTool->IsAssembly(anOriginalL))
941 propagateColorToParts(theSTool, theCTool, anOriginalL);
945 //=======================================================================
946 //function : SetAssemblyComponentStyle
947 //purpose : auxiliary: set override style for assembly components
948 //=======================================================================
950 static void SetAssemblyComponentStyle(const Handle(Transfer_TransientProcess) &theTP,
951 const Handle(XCAFDoc_ColorTool)& theCTool,
952 const STEPConstruct_Styles& theStyles,
953 const Handle(StepVisual_ContextDependentOverRidingStyledItem)& theStyle)
955 if (theStyle.IsNull()) return;
957 Handle(StepVisual_Colour) aSurfCol, aBoundCol, aCurveCol, aRenderCol;
958 Standard_Real aRenderTransp;
959 // check if it is component style
960 Standard_Boolean anIsComponent = Standard_False;
961 if (!theStyles.GetColors(theStyle, aSurfCol, aBoundCol, aCurveCol, aRenderCol, aRenderTransp, anIsComponent))
964 const Interface_Graph& aGraph = theTP->Graph();
965 TopLoc_Location aLoc; // init;
968 Handle(Transfer_Binder) aBinder;
969 Handle(StepShape_ShapeRepresentation) aRepr = Handle(StepShape_ShapeRepresentation)::DownCast(theStyle->ItemAP242 ().Value ());
972 Handle(StepRepr_ShapeRepresentationRelationship) aSRR;
973 Interface_EntityIterator aSubs = theTP->Graph().Sharings(aRepr);
974 for (aSubs.Start(); aSubs.More(); aSubs.Next()) {
975 const Handle(Standard_Transient)& aSubsVal = aSubs.Value();
976 if (aSubsVal->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship)))
978 // NB: C cast is used instead of DownCast() to improve performance on some cases.
979 // This saves ~10% of elapsed time on "testgrid perf de bug29* -parallel 0".
980 aSRR = (StepRepr_ShapeRepresentationRelationship*)(aSubsVal.get());
984 aBinder = theTP->Find(aSRR);
985 if (!aBinder.IsNull() ) {
986 aShape = TransferBRep::ShapeResult (aBinder);
992 aSubs = aGraph.Shareds (theStyle);
994 for(; aSubs.More(); aSubs.Next())
996 Handle(StepRepr_ShapeRepresentationRelationshipWithTransformation) aRelation = Handle(StepRepr_ShapeRepresentationRelationshipWithTransformation)::DownCast (aSubs.Value ());
997 if(aRelation.IsNull()) continue;
999 auto aTransf = aRelation->TransformationOperator ();
1000 if(auto anItemTransf = aTransf.ItemDefinedTransformation ())
1002 Handle(StepGeom_Axis2Placement3d) anAxp1 = Handle(StepGeom_Axis2Placement3d)::DownCast(anItemTransf->TransformItem1 ());
1003 Handle(StepGeom_Axis2Placement3d) anAxp2 = Handle(StepGeom_Axis2Placement3d)::DownCast(anItemTransf->TransformItem2 ());
1005 if(!anAxp1.IsNull() && !anAxp2.IsNull())
1007 Handle(Geom_Axis2Placement) anOrig = StepToGeom::MakeAxis2Placement (anAxp1);
1008 Handle(Geom_Axis2Placement) aTarg = StepToGeom::MakeAxis2Placement (anAxp2);
1009 gp_Ax3 anAx3Orig(anOrig->Ax2());
1010 gp_Ax3 anAx3Targ(aTarg->Ax2());
1013 aTr1.SetTransformation(anAx3Targ, anAx3Orig);
1014 TopLoc_Location aLoc1 (aTr1);
1015 aLoc = aLoc.Multiplied(aLoc1);
1020 aShape.Location( aLoc, Standard_False );
1022 if(!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || !aRenderCol.IsNull())
1024 Quantity_Color aSCol,aBCol,aCCol,aRCol;
1025 Quantity_ColorRGBA aFullSCol;
1026 if(!aSurfCol.IsNull()) {
1027 theStyles.DecodeColor(aSurfCol,aSCol);
1028 aFullSCol = Quantity_ColorRGBA(aSCol);
1030 if(!aBoundCol.IsNull())
1031 theStyles.DecodeColor(aBoundCol,aBCol);
1032 if(!aCurveCol.IsNull())
1033 theStyles.DecodeColor(aCurveCol,aCCol);
1034 if(!aRenderCol.IsNull()) {
1035 theStyles.DecodeColor(aRenderCol,aRCol);
1036 aFullSCol = Quantity_ColorRGBA(aRCol,static_cast<float>(1.0f - aRenderTransp));
1039 if(!aSurfCol.IsNull() || !aRenderCol.IsNull())
1040 theCTool->SetInstanceColor(aShape,XCAFDoc_ColorSurf,aFullSCol);
1041 if(!aBoundCol.IsNull())
1042 theCTool->SetInstanceColor(aShape,XCAFDoc_ColorCurv,aBCol);
1043 if(!aCurveCol.IsNull())
1044 theCTool->SetInstanceColor(aShape,XCAFDoc_ColorCurv,aCCol);
1048 //=======================================================================
1049 //function : SetStyle
1050 //purpose : auxiliary: set style for parts and instances
1051 //=======================================================================
1053 static void SetStyle(const Handle(XSControl_WorkSession) &theWS,
1054 const XCAFDoc_DataMapOfShapeLabel& theMap,
1055 const Handle(XCAFDoc_ColorTool)& theCTool,
1056 const Handle(XCAFDoc_ShapeTool)& theSTool,
1057 const STEPConstruct_Styles& theStyles,
1058 const Handle(TColStd_HSequenceOfTransient)& theHSeqOfInvisStyle,
1059 const Handle(StepVisual_StyledItem)& theStyle)
1061 if (theStyle.IsNull()) return;
1063 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
1064 if (Handle(StepVisual_OverRidingStyledItem) anOverridingStyle = Handle(StepVisual_OverRidingStyledItem)::DownCast (theStyle))
1066 SetStyle (theWS, theMap, theCTool, theSTool, theStyles, theHSeqOfInvisStyle, anOverridingStyle->OverRiddenStyle ());
1067 if (Handle(StepVisual_ContextDependentOverRidingStyledItem) anAssemblyComponentStyle = Handle(StepVisual_ContextDependentOverRidingStyledItem)::DownCast (theStyle))
1069 SetAssemblyComponentStyle (aTP, theCTool, theStyles,anAssemblyComponentStyle);
1074 Standard_Boolean anIsVisible = Standard_True;
1075 // check the visibility of styled item.
1076 for (Standard_Integer si = 1; si <= theHSeqOfInvisStyle->Length(); si++) {
1077 if (theStyle != theHSeqOfInvisStyle->Value(si))
1079 // found that current style is invisible.
1080 anIsVisible = Standard_False;
1083 Handle(StepVisual_Colour) aSurfCol, aBoundCol, aCurveCol, aRenderCol;
1084 Standard_Real aRenderTransp;
1085 // check if it is component style
1086 Standard_Boolean anIsComponent = Standard_False;
1087 if (!theStyles.GetColors(theStyle, aSurfCol, aBoundCol, aCurveCol, aRenderCol, aRenderTransp, anIsComponent) && anIsVisible)
1090 // collect styled items
1091 NCollection_Vector<StepVisual_StyledItemTarget> anItems;
1092 if (!theStyle->ItemAP242().IsNull()) {
1093 anItems.Append(theStyle->ItemAP242());
1096 for (Standard_Integer itemIt = 0; itemIt < anItems.Length(); itemIt++) {
1097 Standard_Integer anIndex = aTP->MapIndex(anItems.Value(itemIt).Value());
1100 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
1101 aS = TransferBRep::ShapeResult(aBinder);
1103 Standard_Boolean isSkipSHUOstyle = Standard_False;
1104 // take shape with real location.
1105 while (anIsComponent) {
1107 Handle(StepShape_ShapeRepresentation) aSR;
1108 findStyledSR(theStyle, aSR);
1109 // search for SR along model
1112 Interface_EntityIterator aSubs = theWS->HGraph()->Graph().Sharings(aSR);
1113 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1114 for (aSubs.Start(); aSubs.More(); aSubs.Next()) {
1115 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSubs.Value());
1118 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1119 Handle(StepRepr_ProductDefinitionShape) PDS =
1120 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1123 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1125 Handle(StepRepr_AssemblyComponentUsage) ACU =
1126 Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
1129 // PTV 10.02.2003 skip styled item that refer to SHUO
1130 if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1131 isSkipSHUOstyle = Standard_True;
1134 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1135 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
1140 // PTV 10.02.2003 to find component of assembly CORRECTLY
1141 STEPConstruct_Tool aTool(theWS);
1142 TDF_Label aShLab = STEPCAFControl_Reader::FindInstance(NAUO, theCTool->ShapeTool(), aTool, theMap);
1143 aSh = theCTool->ShapeTool()->GetShape(aShLab);
1144 if (!aSh.IsNull()) {
1151 if (isSkipSHUOstyle)
1152 continue; // skip styled item which refer to SHUO
1157 if (!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || !aRenderCol.IsNull() || !anIsVisible)
1160 Standard_Boolean isFound = theSTool->SearchUsingMap(aS, aL, Standard_False, Standard_True);
1161 if (!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || !aRenderCol.IsNull())
1163 Quantity_Color aSCol, aBCol, aCCol, aRCol;
1164 Quantity_ColorRGBA aFullSCol;
1165 if (!aSurfCol.IsNull()) {
1166 theStyles.DecodeColor(aSurfCol, aSCol);
1167 aFullSCol = Quantity_ColorRGBA(aSCol);
1169 if (!aBoundCol.IsNull())
1170 theStyles.DecodeColor(aBoundCol, aBCol);
1171 if (!aCurveCol.IsNull())
1172 theStyles.DecodeColor(aCurveCol, aCCol);
1173 if (!aRenderCol.IsNull()) {
1174 theStyles.DecodeColor(aRenderCol, aRCol);
1175 aFullSCol = Quantity_ColorRGBA(aRCol, static_cast<float>(1.0f - aRenderTransp));
1179 if (!aSurfCol.IsNull() || !aRenderCol.IsNull())
1180 theCTool->SetColor(aL, aFullSCol, XCAFDoc_ColorSurf);
1181 if (!aBoundCol.IsNull())
1182 theCTool->SetColor(aL, aBCol, XCAFDoc_ColorCurv);
1183 if (!aCurveCol.IsNull())
1184 theCTool->SetColor(aL, aCCol, XCAFDoc_ColorCurv);
1188 for (TopoDS_Iterator it(aS); it.More(); it.Next())
1191 if (theSTool->SearchUsingMap(it.Value(), aL1, Standard_False, Standard_True))
1193 if (!aSurfCol.IsNull() || !aRenderCol.IsNull())
1194 theCTool->SetColor(aL1, aFullSCol, XCAFDoc_ColorSurf);
1195 if (!aBoundCol.IsNull())
1196 theCTool->SetColor(aL1, aBCol, XCAFDoc_ColorCurv);
1197 if (!aCurveCol.IsNull())
1198 theCTool->SetColor(aL1, aCCol, XCAFDoc_ColorCurv);
1205 // sets the invisibility for shape.
1207 theCTool->SetVisibility(aL, Standard_False);
1213 //=======================================================================
1214 //function : IsOverriden
1215 //purpose : auxiliary: check that style is overridden
1216 //=======================================================================
1218 static Standard_Boolean IsOverriden(const Interface_Graph& theGraph,
1219 const Handle(StepVisual_StyledItem)& theStyle,
1220 Standard_Boolean theIsRoot)
1222 Interface_EntityIterator aSubs = theGraph.Sharings (theStyle);
1224 for(; aSubs.More(); aSubs.Next())
1226 Handle(StepVisual_OverRidingStyledItem) anOverRidingStyle = Handle(StepVisual_OverRidingStyledItem)::DownCast (aSubs.Value ());
1227 if(!anOverRidingStyle.IsNull())
1231 return Standard_True;
1233 // for root style returns true only if it is overridden by other root style
1234 auto anItem = anOverRidingStyle->ItemAP242 ().Value ();
1235 if(!anItem.IsNull() && anItem->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation)))
1237 return Standard_True;
1241 return Standard_False;
1244 //=======================================================================
1245 //function : ReadColors
1247 //=======================================================================
1249 Standard_Boolean STEPCAFControl_Reader::ReadColors(const Handle(XSControl_WorkSession) &WS,
1250 const Handle(TDocStd_Document)& Doc) const
1252 STEPConstruct_Styles Styles(WS);
1253 if (!Styles.LoadStyles()) {
1255 std::cout << "Warning: no styles are found in the model" << std::endl;
1257 return Standard_False;
1259 // searching for invisible items in the model
1260 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
1261 Styles.LoadInvisStyles(aHSeqOfInvisStyle);
1263 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
1264 if (CTool.IsNull()) return Standard_False;
1265 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1266 if (STool.IsNull()) return Standard_False;
1268 const Interface_Graph& aGraph = Styles.Graph ();
1270 // parse and search for color attributes
1271 Standard_Integer nb = Styles.NbRootStyles();
1272 // apply root styles earlier, as they can be overridden
1273 // function IsOverriden for root style returns true only if it is overridden by other root style
1274 Standard_Boolean anIsRootStyle = Standard_True;
1275 for(Standard_Integer i = 1; i <= nb; i++)
1277 Handle(StepVisual_StyledItem) Style = Styles.RootStyle(i);
1278 // check that style is overridden by other root style
1279 if (!IsOverriden (aGraph, Style, anIsRootStyle))
1281 SetStyle (WS, myMap, CTool, STool, Styles, aHSeqOfInvisStyle, Style);
1285 nb = Styles.NbStyles();
1286 // apply leaf styles, they can override root styles
1287 anIsRootStyle = Standard_False;
1288 for(Standard_Integer i = 1; i <= nb; i++)
1290 Handle(StepVisual_StyledItem) Style = Styles.Style(i);
1291 // check that style is overridden
1292 if (!IsOverriden (aGraph, Style, anIsRootStyle))
1294 SetStyle (WS, myMap, CTool, STool, Styles, aHSeqOfInvisStyle, Style);
1298 CTool->ReverseChainsOfTreeNodes();
1300 // some colors can be attached to assemblies, propagate them to components
1301 propagateColorToParts(STool, CTool, STool->Label());
1302 return Standard_True;
1305 //=======================================================================
1306 //function : GetLabelFromPD
1308 //=======================================================================
1310 static TDF_Label GetLabelFromPD(const Handle(StepBasic_ProductDefinition) &PD,
1311 const Handle(XCAFDoc_ShapeTool) &STool,
1312 const Handle(Transfer_TransientProcess) &TP,
1313 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1314 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1317 if (PDFileMap.IsBound(PD)) {
1318 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(PD);
1321 if (!L.IsNull()) return L;
1326 Handle(Transfer_Binder) binder = TP->Find(PD);
1327 if (binder.IsNull() || !binder->HasResult()) return L;
1328 S = TransferBRep::ShapeResult(TP, binder);
1329 if (S.IsNull()) return L;
1331 if (ShapeLabelMap.IsBound(S))
1332 L = ShapeLabelMap.Find(S);
1334 STool->Search(S, L, Standard_True, Standard_True, Standard_False);
1338 //=======================================================================
1339 //function : FindInstance
1341 //=======================================================================
1343 TDF_Label STEPCAFControl_Reader::FindInstance(const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO,
1344 const Handle(XCAFDoc_ShapeTool) &STool,
1345 const STEPConstruct_Tool &Tool,
1346 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1350 // get shape resulting from CDSR (in fact, only location is interesting)
1351 Handle(Transfer_TransientProcess) TP = Tool.TransientProcess();
1352 Handle(Transfer_Binder) binder = TP->Find(NAUO);
1353 if (binder.IsNull() || !binder->HasResult()) {
1355 std::cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << std::endl;
1360 TopoDS_Shape S = TransferBRep::ShapeResult(TP, binder);
1363 std::cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << std::endl;
1368 if (ShapeLabelMap.IsBound(S))
1369 L = ShapeLabelMap(S);
1371 STool->Search(S, L, Standard_True, Standard_True, Standard_False);
1376 //=======================================================================
1377 //function : ReadNames
1379 //=======================================================================
1381 Standard_Boolean STEPCAFControl_Reader::ReadNames(const Handle(XSControl_WorkSession) &WS,
1382 const Handle(TDocStd_Document)& Doc,
1383 const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const
1385 // get starting data
1386 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1387 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1388 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1389 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1390 if (STool.IsNull()) return Standard_False;
1391 STEPConstruct_Tool Tool(WS);
1393 // iterate on model to find all SDRs and CDSRs
1394 Standard_Integer nb = Model->NbEntities();
1395 Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
1396 Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
1397 Handle(Standard_Type) tPDWAD = STANDARD_TYPE(StepBasic_ProductDefinitionWithAssociatedDocuments);
1398 Handle(TCollection_HAsciiString) name;
1400 for (Standard_Integer i = 1; i <= nb; i++) {
1401 Handle(Standard_Transient) enti = Model->Value(i);
1403 // get description of NAUO
1404 if (enti->DynamicType() == tNAUO) {
1406 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1407 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
1408 if (NAUO.IsNull()) continue;
1409 Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
1410 for (subs.Start(); subs.More(); subs.Next()) {
1411 Handle(StepRepr_ProductDefinitionShape) PDS =
1412 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1413 if (PDS.IsNull()) continue;
1414 Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
1415 if (PDR.IsNull()) continue;
1416 if (PDR->HasDescription() &&
1417 PDR->Description()->UsefullLength() > 0) name = PDR->Description();
1418 else if (!PDR->Name().IsNull() && PDR->Name()->UsefullLength() > 0) name = PDR->Name();
1419 else if (!PDR->Id().IsNull()) name = PDR->Id();
1420 else name = new TCollection_HAsciiString;
1422 // find proper label
1423 L = FindInstance(NAUO, STool, Tool, myMap);
1424 if (L.IsNull()) continue;
1426 TCollection_ExtendedString str = convertName (name->String());
1427 TDataStd_Name::Set(L, str);
1430 // for PD get name of associated product
1431 if (enti->DynamicType() == tPD || enti->DynamicType() == tPDWAD) {
1433 Handle(StepBasic_ProductDefinition) PD =
1434 Handle(StepBasic_ProductDefinition)::DownCast(enti);
1435 if (PD.IsNull()) continue;
1436 Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL);
1438 name = new TCollection_HAsciiString;
1439 else if (!Prod->Name().IsNull() && Prod->Name()->UsefullLength() > 0)
1440 name = Prod->Name();
1441 else if (!Prod->Id().IsNull())
1444 name = new TCollection_HAsciiString;
1445 L = GetLabelFromPD(PD, STool, TP, PDFileMap, myMap);
1446 if (L.IsNull()) continue;
1447 TCollection_ExtendedString str = convertName (name->String());
1448 TDataStd_Name::Set(L, str);
1450 // set a name to the document
1451 //TCollection_ExtendedString str = convertName (name->String());
1452 //TDataStd_Name::Set ( L, str );
1455 return Standard_True;
1458 //=======================================================================
1459 //function : GetLabelFromPD
1461 //=======================================================================
1463 static TDF_Label GetLabelFromPD(const Handle(StepBasic_ProductDefinition) &PD,
1464 const Handle(XCAFDoc_ShapeTool) &STool,
1465 const STEPConstruct_ValidationProps &Props,
1466 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1467 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1470 if (PDFileMap.IsBound(PD)) {
1471 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find(PD);
1474 if (!L.IsNull()) return L;
1477 TopoDS_Shape S = Props.GetPropShape(PD);
1478 if (S.IsNull()) return L;
1479 if (ShapeLabelMap.IsBound(S))
1480 L = ShapeLabelMap.Find(S);
1482 STool->Search(S, L, Standard_True, Standard_True, Standard_False);
1486 //=======================================================================
1487 //function : ReadValProps
1489 //=======================================================================
1491 Standard_Boolean STEPCAFControl_Reader::ReadValProps(const Handle(XSControl_WorkSession) &WS,
1492 const Handle(TDocStd_Document)& Doc,
1493 const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const
1495 // get starting data
1496 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1497 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1498 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1499 if (STool.IsNull()) return Standard_False;
1501 // load props from the STEP model
1502 TColStd_SequenceOfTransient props;
1503 STEPConstruct_ValidationProps Props(WS);
1504 if (!Props.LoadProps(props)) {
1506 std::cout << "Warning: no validation props found in the model" << std::endl;
1508 return Standard_False;
1511 // interpret props one by one
1512 for (Standard_Integer i = 1; i <= props.Length(); i++) {
1513 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1514 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(props.Value(i));
1515 if (PDR.IsNull()) continue;
1519 Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition();
1520 Interface_EntityIterator subs = Props.Graph().Shareds(PD);
1521 for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) {
1522 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
1523 Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1524 if (PDS.IsNull()) continue;
1525 // find corresponding NAUO
1526 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO;
1527 Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS);
1528 for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) {
1529 if (subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)))
1530 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value());
1532 if (!NAUO.IsNull()) {
1533 L = FindInstance(NAUO, STool, WS, myMap);
1534 if (L.IsNull()) continue;
1537 // find corresponding ProductDefinition:
1538 Handle(StepBasic_ProductDefinition) ProdDef;
1539 Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS);
1540 for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) {
1541 if (subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)))
1542 ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value());
1544 if (ProdDef.IsNull()) continue;
1545 L = GetLabelFromPD(ProdDef, STool, Props, PDFileMap, myMap);
1549 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))) {
1550 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value());
1551 if (SA.IsNull()) continue;
1552 // find ShapeRepresentation
1553 Handle(StepShape_ShapeRepresentation) SR;
1554 Interface_EntityIterator subs1 = Props.Graph().Sharings(SA);
1555 for (subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) {
1556 Handle(StepRepr_PropertyDefinition) PropD1 =
1557 Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value());
1558 if (PropD1.IsNull()) continue;
1559 Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1);
1560 for (subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) {
1561 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1562 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
1563 if (SDR.IsNull()) continue;
1564 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1567 if (SR.IsNull()) continue;
1568 Handle(Transfer_Binder) binder;
1569 for (Standard_Integer ir = 1; ir <= SR->NbItems() && binder.IsNull(); ir++) {
1570 if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) {
1571 Handle(StepShape_SolidModel) SM =
1572 Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir));
1573 binder = TP->Find(SM);
1575 else if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1576 Handle(StepShape_ShellBasedSurfaceModel) SBSM =
1577 Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir));
1578 binder = TP->Find(SBSM);
1580 else if (SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1581 Handle(StepShape_GeometricSet) GS =
1582 Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir));
1583 binder = TP->Find(GS);
1586 if (binder.IsNull() || !binder->HasResult()) continue;
1588 S = TransferBRep::ShapeResult(TP, binder);
1589 if (S.IsNull()) continue;
1590 if (myMap.IsBound(S))
1593 STool->Search(S, L, Standard_True, Standard_True, Standard_True);
1597 if (L.IsNull()) continue;
1599 // decode validation properties
1600 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
1601 for (Standard_Integer j = 1; j <= rep->NbItems(); j++) {
1602 Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j);
1603 Standard_Boolean isArea;
1606 if (Props.GetPropReal(ent, val, isArea)) {
1607 if (isArea) XCAFDoc_Area::Set(L, val);
1608 else XCAFDoc_Volume::Set(L, val);
1610 else if (Props.GetPropPnt(ent, rep->ContextOfItems(), pos)) {
1611 XCAFDoc_Centroid::Set(L, pos);
1615 return Standard_True;
1618 //=======================================================================
1619 //function : ReadLayers
1621 //=======================================================================
1623 Standard_Boolean STEPCAFControl_Reader::ReadLayers(const Handle(XSControl_WorkSession) &WS,
1624 const Handle(TDocStd_Document)& Doc) const
1626 const Handle(Interface_InterfaceModel) &Model = WS->Model();
1627 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
1628 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
1629 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
1630 if (STool.IsNull()) return Standard_False;
1631 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
1632 if (LTool.IsNull()) return Standard_False;
1634 Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment);
1635 Standard_Integer nb = Model->NbEntities();
1636 Handle(TCollection_HAsciiString) name;
1638 for (Standard_Integer i = 1; i <= nb; i++) {
1639 Handle(Standard_Transient) enti = Model->Value(i);
1640 if (!enti->IsKind(tSVPLA)) continue;
1641 Handle(StepVisual_PresentationLayerAssignment) SVPLA =
1642 Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
1643 if (SVPLA->AssignedItems().IsNull())
1646 Handle(TCollection_HAsciiString) descr = SVPLA->Description();
1647 Handle(TCollection_HAsciiString) hName = SVPLA->Name();
1648 TCollection_ExtendedString aLayerName(hName->String());
1649 TDF_Label aLayerLabel;
1651 // check invisibility
1652 Standard_Boolean isVisible = Standard_True;;
1653 Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
1654 for (subs.Start(); subs.More() && isVisible; subs.Next()) {
1655 if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility))) continue;
1657 std::cout << "\tLayer \"" << aLayerName << "\" is invisible" << std::endl;
1659 isVisible = Standard_False;
1662 // find a target shape and its label in the document
1663 for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++) {
1664 StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j);
1665 Handle(Transfer_Binder) binder = TP->Find(LI.Value());
1666 if (binder.IsNull() || !binder->HasResult()) continue;
1668 TopoDS_Shape S = TransferBRep::ShapeResult(TP, binder);
1669 if (S.IsNull()) continue;
1672 if (!STool->Search(S, shL, Standard_True, Standard_True, Standard_True)) continue;
1673 if (aLayerLabel.IsNull())
1674 aLayerLabel = LTool->AddLayer(aLayerName, isVisible);
1675 LTool->SetLayer(shL, aLayerLabel);
1678 if (!aLayerLabel.IsNull())
1679 LTool->SetVisibility(aLayerLabel, isVisible);
1681 return Standard_True;
1684 //=======================================================================
1685 //function : ReadSHUOs
1687 //=======================================================================
1689 static Standard_Boolean findNextSHUOlevel(const Handle(XSControl_WorkSession) &WS,
1690 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1691 const Handle(XCAFDoc_ShapeTool)& STool,
1692 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1693 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap,
1694 TDF_LabelSequence& aLabels)
1696 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO);
1697 Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO;
1698 for (subs.Start(); subs.More(); subs.Next()) {
1699 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1700 subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value());
1704 if (subSHUO.IsNull())
1705 return Standard_False;
1707 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = subSHUO->NextUsage();
1708 if (NUNAUO.IsNull())
1709 return Standard_False;
1710 // Handle(Interface_InterfaceModel) Model = WS->Model();
1711 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1712 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1713 // Handle(Transfer_Binder) binder = TP->Find(NUNAUO);
1714 // if ( binder.IsNull() || ! binder->HasResult() )
1715 // return Standard_False;
1716 // TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder );
1717 // get label of NAUO next level
1719 STEPConstruct_Tool Tool(WS);
1720 NULab = STEPCAFControl_Reader::FindInstance(NUNAUO, STool, Tool, ShapeLabelMap);
1721 // STool->Search(NUSh, NUlab);
1723 return Standard_False;
1724 aLabels.Append(NULab);
1725 // and check by recurse.
1726 findNextSHUOlevel(WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels);
1727 return Standard_True;
1731 //=======================================================================
1732 //function : setSHUOintoDoc
1733 //purpose : auxiliary
1734 //=======================================================================
1735 static TDF_Label setSHUOintoDoc(const Handle(XSControl_WorkSession) &WS,
1736 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1737 const Handle(XCAFDoc_ShapeTool)& STool,
1738 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1739 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1741 TDF_Label aMainLabel;
1742 // get upper usage NAUO from SHUO.
1743 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
1744 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
1745 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO = SHUO->NextUsage();
1746 if (UUNAUO.IsNull() || NUNAUO.IsNull()) {
1748 std::cout << "Warning: " << __FILE__ << ": Upper_usage or Next_usage of styled SHUO is null. Skip it" << std::endl;
1752 // Handle(Interface_InterfaceModel) Model = WS->Model();
1753 // Handle(XSControl_TransferReader) TR = WS->TransferReader();
1754 // Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1755 // TopoDS_Shape UUSh, NUSh;
1756 // Handle(Transfer_Binder) binder = TP->Find(UUNAUO);
1757 // if ( binder.IsNull() || ! binder->HasResult() )
1758 // return aMainLabel;
1759 // UUSh = TransferBRep::ShapeResult ( TP, binder );
1760 // binder = TP->Find(NUNAUO);
1761 // if ( binder.IsNull() || ! binder->HasResult() )
1762 // return aMainLabel;
1763 // NUSh = TransferBRep::ShapeResult ( TP, binder );
1765 // get first labels for first SHUO attribute
1766 TDF_Label UULab, NULab;
1767 STEPConstruct_Tool Tool(WS);
1768 UULab = STEPCAFControl_Reader::FindInstance(UUNAUO, STool, Tool, ShapeLabelMap);
1769 NULab = STEPCAFControl_Reader::FindInstance(NUNAUO, STool, Tool, ShapeLabelMap);
1771 // STool->Search(UUSh, UULab);
1772 // STool->Search(NUSh, NULab);
1773 if (UULab.IsNull() || NULab.IsNull()) return aMainLabel;
1774 //create sequence fo labels to set SHUO structure into the document
1775 TDF_LabelSequence ShuoLabels;
1776 ShuoLabels.Append(UULab);
1777 ShuoLabels.Append(NULab);
1778 // add all other labels of sub SHUO entities
1779 findNextSHUOlevel(WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels);
1780 // last accord for SHUO
1781 Handle(XCAFDoc_GraphNode) anSHUOAttr;
1782 if (STool->SetSHUO(ShuoLabels, anSHUOAttr))
1783 aMainLabel = anSHUOAttr->Label();
1789 //=======================================================================
1790 //function : ReadSHUOs
1792 //=======================================================================
1794 Standard_Boolean STEPCAFControl_Reader::ReadSHUOs(const Handle(XSControl_WorkSession) &WS,
1795 const Handle(TDocStd_Document)& Doc,
1796 const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const
1798 // the big part code duplication from ReadColors.
1799 // It is possible to share this code functionality, just to decide how ???
1800 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
1801 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
1803 STEPConstruct_Styles Styles(WS);
1804 if (!Styles.LoadStyles()) {
1806 std::cout << "Warning: no styles are found in the model" << std::endl;
1808 return Standard_False;
1810 // searching for invisible items in the model
1811 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
1812 Styles.LoadInvisStyles(aHSeqOfInvisStyle);
1813 // parse and search for color attributes
1814 Standard_Integer nb = Styles.NbStyles();
1815 for (Standard_Integer i = 1; i <= nb; i++) {
1816 Handle(StepVisual_StyledItem) style = Styles.Style(i);
1817 if (style.IsNull()) continue;
1819 Standard_Boolean IsVisible = Standard_True;
1820 // check the visibility of styled item.
1821 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++) {
1822 if (style != aHSeqOfInvisStyle->Value(si))
1824 // found that current style is invisible.
1826 std::cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << std::endl;
1828 IsVisible = Standard_False;
1832 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol, RenderCol;
1833 Standard_Real RenderTransp;
1834 // check if it is component style
1835 Standard_Boolean IsComponent = Standard_False;
1836 if (!Styles.GetColors(style, SurfCol, BoundCol, CurveCol, RenderCol, RenderTransp, IsComponent) && IsVisible)
1840 Handle(StepShape_ShapeRepresentation) aSR;
1841 findStyledSR(style, aSR);
1842 // search for SR along model
1845 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(aSR);
1846 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1847 for (subs.Start(); subs.More(); subs.Next()) {
1848 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1851 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1852 Handle(StepRepr_ProductDefinitionShape) PDS =
1853 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1856 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1857 Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO =
1858 Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship());
1862 // set the SHUO structure to the document
1863 TDF_Label aLabelForStyle = setSHUOintoDoc(WS, SHUO, STool, PDFileMap, myMap);
1864 if (aLabelForStyle.IsNull()) {
1866 std::cout << "Warning: " << __FILE__ << ": coudnot create SHUO structure in the document" << std::endl;
1870 // now set the style to the SHUO main label.
1871 if (!SurfCol.IsNull() || !RenderCol.IsNull()) {
1873 Quantity_ColorRGBA colRGBA;
1874 if (!SurfCol.IsNull()) {
1875 Styles.DecodeColor(SurfCol, col);
1876 colRGBA = Quantity_ColorRGBA(col);
1878 if (!RenderCol.IsNull()) {
1879 Styles.DecodeColor(RenderCol, col);
1880 colRGBA = Quantity_ColorRGBA(col, static_cast<float>(1.0 - RenderTransp));
1882 CTool->SetColor(aLabelForStyle, colRGBA, XCAFDoc_ColorSurf);
1884 if (!BoundCol.IsNull()) {
1886 Styles.DecodeColor(BoundCol, col);
1887 CTool->SetColor(aLabelForStyle, col, XCAFDoc_ColorCurv);
1889 if (!CurveCol.IsNull()) {
1891 Styles.DecodeColor(CurveCol, col);
1892 CTool->SetColor(aLabelForStyle, col, XCAFDoc_ColorCurv);
1895 // sets the invisibility for shape.
1896 CTool->SetVisibility(aLabelForStyle, Standard_False);
1898 } // end search SHUO by SDR
1899 } // end iterates on styles
1901 return Standard_True;
1904 //=======================================================================
1905 //function : GetMassConversionFactor
1907 //=======================================================================
1908 static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1909 Standard_Real& afact)
1912 if (!NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) return Standard_False;
1913 Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU =
1914 Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU);
1915 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor();
1916 afact = MWUCBU->ValueComponent();
1917 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1918 if (anUnit2.CaseNum(anUnit2.Value()) == 1) {
1919 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1920 if (NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1921 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1922 if (SU->Name() == StepBasic_sunGram) {
1923 if (SU->HasPrefix())
1924 afact *= STEPConstruct_UnitContext::ConvertSiPrefix(SU->Prefix());
1928 return Standard_True;
1931 //=======================================================================
1932 //function : readPMIPresentation
1933 //purpose : read polyline or tessellated presentation for
1934 // (Annotation_Curve_Occurrence or Draughting_Callout)
1935 //=======================================================================
1936 Standard_Boolean readPMIPresentation(const Handle(Standard_Transient)& thePresentEntity,
1937 const Handle(XSControl_TransferReader)& theTR,
1938 const Standard_Real theFact,
1939 TopoDS_Shape& thePresentation,
1940 Handle(TCollection_HAsciiString)& thePresentName,
1943 if (thePresentEntity.IsNull())
1944 return Standard_False;
1945 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
1946 Handle(StepVisual_AnnotationOccurrence) anAO;
1947 NCollection_Vector<Handle(StepVisual_StyledItem)> anAnnotations;
1948 if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
1950 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(thePresentEntity);
1951 if (!anAO.IsNull()) {
1952 thePresentName = anAO->Name();
1953 anAnnotations.Append(anAO);
1956 else if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)))
1958 Handle(StepVisual_DraughtingCallout) aDCallout =
1959 Handle(StepVisual_DraughtingCallout)::DownCast(thePresentEntity);
1960 thePresentName = aDCallout->Name();
1961 for (Standard_Integer i = 1; i <= aDCallout->NbContents() && anAO.IsNull(); i++) {
1962 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(aDCallout->ContentsValue(i).Value());
1965 anAnnotations.Append(anAO);
1968 Handle(StepVisual_TessellatedAnnotationOccurrence) aTesselation =
1969 aDCallout->ContentsValue(i).TessellatedAnnotationOccurrence();
1970 if (!aTesselation.IsNull())
1971 anAnnotations.Append(aTesselation);
1975 if (!anAnnotations.Length())
1976 return Standard_False;
1980 TopoDS_Compound aResAnnotation;
1981 aB.MakeCompound(aResAnnotation);
1983 Standard_Integer i = 0;
1985 Standard_Integer nbShapes = 0;
1986 for (; i < anAnnotations.Length(); i++)
1988 Handle(StepVisual_StyledItem) anItem = anAnnotations(i);
1989 anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(anItem);
1990 TopoDS_Shape anAnnotationShape;
1993 Handle(StepRepr_RepresentationItem) aCurveItem = anAO->Item();
1994 anAnnotationShape = STEPConstruct::FindShape(aTP, aCurveItem);
1995 if (anAnnotationShape.IsNull())
1997 Handle(Transfer_Binder) binder = theTR->Actor()->Transfer(aCurveItem, aTP);
1998 if (!binder.IsNull() && binder->HasResult()) {
1999 anAnnotationShape = TransferBRep::ShapeResult(aTP, binder);
2003 //case of tessellated entities
2006 Handle(StepRepr_RepresentationItem) aTessItem = anItem->Item();
2007 if (aTessItem.IsNull())
2009 Handle(StepVisual_TessellatedGeometricSet) aTessSet = Handle(StepVisual_TessellatedGeometricSet)::DownCast(aTessItem);
2010 if (aTessSet.IsNull())
2013 if (aTessSet->IsKind(STANDARD_TYPE(StepVisual_RepositionedTessellatedGeometricSet)))
2015 Handle(StepVisual_RepositionedTessellatedGeometricSet) aRTGS =
2016 Handle(StepVisual_RepositionedTessellatedGeometricSet)::DownCast(aTessSet);
2017 Handle(Geom_Axis2Placement) aLocation = StepToGeom::MakeAxis2Placement(aRTGS->Location());
2018 if (!aLocation.IsNull())
2020 const gp_Ax3 anAx3Orig = gp::XOY();
2021 const gp_Ax3 anAx3Targ(aLocation->Ax2());
2022 if (anAx3Targ.Location().SquareDistance(anAx3Orig.Location()) >= Precision::SquareConfusion() ||
2023 !anAx3Targ.Direction().IsEqual(anAx3Orig.Direction(), Precision::Angular()) ||
2024 !anAx3Targ.XDirection().IsEqual(anAx3Orig.XDirection(), Precision::Angular()) ||
2025 !anAx3Targ.YDirection().IsEqual(anAx3Orig.YDirection(), Precision::Angular()))
2027 aTransf.SetTransformation(anAx3Targ, anAx3Orig);
2031 NCollection_Handle<StepVisual_Array1OfTessellatedItem> aListItems = aTessSet->Items();
2032 Standard_Integer nb = aListItems.IsNull() ? 0 : aListItems->Length();
2033 Handle(StepVisual_TessellatedCurveSet) aTessCurve;
2034 for (Standard_Integer n = 1; n <= nb && aTessCurve.IsNull(); n++)
2036 aTessCurve = Handle(StepVisual_TessellatedCurveSet)::DownCast(aListItems->Value(n));
2038 if (aTessCurve.IsNull())
2040 Handle(StepVisual_CoordinatesList) aCoordList = aTessCurve->CoordList();
2041 if (aCoordList.IsNull())
2043 Handle(TColgp_HArray1OfXYZ) aPoints = aCoordList->Points();
2045 if (aPoints.IsNull() || aPoints->Length() == 0)
2047 NCollection_Handle<StepVisual_VectorOfHSequenceOfInteger> aCurves = aTessCurve->Curves();
2048 Standard_Integer aNbC = (aCurves.IsNull() ? 0 : aCurves->Length());
2049 TopoDS_Compound aComp;
2050 aB.MakeCompound(aComp);
2052 Standard_Integer k = 0;
2053 for (; k < aNbC; k++)
2055 Handle(TColStd_HSequenceOfInteger) anIndexes = aCurves->Value(k);
2059 for (Standard_Integer n = 1; n < anIndexes->Length(); n++)
2061 Standard_Integer ind = anIndexes->Value(n);
2062 Standard_Integer indnext = anIndexes->Value(n + 1);
2063 if (ind > aPoints->Length() || indnext > aPoints->Length())
2065 gp_Pnt aP1(aPoints->Value(ind) * theFact);
2066 gp_Pnt aP2(aPoints->Value(indnext) * theFact);
2067 BRepBuilderAPI_MakeEdge aMaker(aP1, aP2);
2068 if (aMaker.IsDone())
2070 TopoDS_Edge aCurE = aMaker.Edge();
2071 aB.Add(aCurW, aCurE);
2074 aB.Add(aComp, aCurW);
2076 anAnnotationShape = aComp.Moved(aTransf);
2078 if (!anAnnotationShape.IsNull())
2081 aB.Add(aResAnnotation, anAnnotationShape);
2082 if (i == anAnnotations.Length() - 1)
2083 BRepBndLib::AddClose(anAnnotationShape, aBox);
2087 thePresentation = aResAnnotation;
2089 return (nbShapes > 0);
2092 //=======================================================================
2093 //function : readAnnotationPlane
2094 //purpose : read annotation plane
2095 //=======================================================================
2096 Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) theAnnotationPlane,
2099 if (theAnnotationPlane.IsNull())
2100 return Standard_False;
2101 Handle(StepRepr_RepresentationItem) aPlaneItem = theAnnotationPlane->Item();
2102 if (aPlaneItem.IsNull())
2103 return Standard_False;
2104 Handle(StepGeom_Axis2Placement3d) aA2P3D;
2105 //retrieve axes from AnnotationPlane
2106 if (aPlaneItem->IsKind(STANDARD_TYPE(StepGeom_Plane))) {
2107 Handle(StepGeom_Plane) aPlane = Handle(StepGeom_Plane)::DownCast(aPlaneItem);
2108 aA2P3D = aPlane->Position();
2110 else if (aPlaneItem->IsKind(STANDARD_TYPE(StepVisual_PlanarBox))) {
2111 Handle(StepVisual_PlanarBox) aBox = Handle(StepVisual_PlanarBox)::DownCast(aPlaneItem);
2112 aA2P3D = aBox->Placement().Axis2Placement3d();
2114 if (aA2P3D.IsNull())
2115 return Standard_False;
2117 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aA2P3D);
2118 thePlane = anAxis->Ax2();
2119 return Standard_True;
2122 //=======================================================================
2123 //function : readAnnotation
2124 //purpose : read annotation plane and position for given GDT
2125 // (Dimension, Geometric_Tolerance, Datum_Feature or Placed_Datum_Target_Feature)
2126 //=======================================================================
2127 void readAnnotation(const Handle(XSControl_TransferReader)& theTR,
2128 const Handle(Standard_Transient)& theGDT,
2129 const Handle(Standard_Transient)& theDimObject)
2131 if (theGDT.IsNull() || theDimObject.IsNull())
2133 Handle(TCollection_HAsciiString) aPresentName;
2134 TopoDS_Compound aResAnnotation;
2135 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
2136 const Interface_Graph& aGraph = aTP->Graph();
2137 // find the proper DraughtingModelItemAssociation
2138 Interface_EntityIterator subs = aGraph.Sharings(theGDT);
2139 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
2140 for (subs.Start(); subs.More() && aDMIA.IsNull(); subs.Next()) {
2141 if (!subs.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
2143 aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(subs.Value());
2144 Handle(TCollection_HAsciiString) aName = aDMIA->Name();
2146 if (!aName->Search(new TCollection_HAsciiString("pmi representation to presentation link"))) {
2150 if (aDMIA.IsNull() || aDMIA->NbIdentifiedItem() == 0)
2154 Handle(StepVisual_DraughtingModel) aDModel =
2155 Handle(StepVisual_DraughtingModel)::DownCast(aDMIA->UsedRepresentation());
2156 XSAlgo::AlgoContainer()->PrepareForTransfer();
2157 STEPControl_ActorRead anActor;
2158 anActor.PrepareUnits(aDModel, aTP);
2159 Standard_Real aFact = StepData_GlobalFactors::Intance().LengthFactor();
2161 // retrieve AnnotationPlane
2162 Handle(StepRepr_RepresentationItem) aDMIAE = aDMIA->IdentifiedItemValue(1);
2163 if (aDMIAE.IsNull())
2166 subs = aGraph.Sharings(aDMIAE);
2167 Handle(StepVisual_AnnotationPlane) anAnPlane;
2168 for (subs.Start(); subs.More() && anAnPlane.IsNull(); subs.Next()) {
2169 anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(subs.Value());
2171 Standard_Boolean isHasPlane = readAnnotationPlane(anAnPlane, aPlaneAxes);
2173 // set plane axes to XCAF
2175 if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) {
2176 Handle(XCAFDimTolObjects_DimensionObject) anObj =
2177 Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject);
2178 Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt(1, 1);
2179 anObj->SetPlane(aPlaneAxes);
2181 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) {
2182 Handle(XCAFDimTolObjects_DatumObject) anObj =
2183 Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject);
2184 anObj->SetPlane(aPlaneAxes);
2186 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) {
2187 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj =
2188 Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject);
2189 anObj->SetPlane(aPlaneAxes);
2193 // Retrieve presentation
2195 if (!readPMIPresentation(aDMIAE, theTR, aFact, aResAnnotation, aPresentName, aBox))
2197 gp_Pnt aPtext(0., 0., 0.);
2198 // if Annotation plane location inside bounding box set it to text position
2199 // else set the center of bounding box to text position 0027372
2202 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2203 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2204 if (isHasPlane && !aBox.IsOut(aPlaneAxes.Location())) {
2205 aPtext = aPlaneAxes.Location();
2208 aPtext = gp_Pnt((aXmin + aXmax) * 0.5, (aYmin + aYmax) * 0.5, (aZmin + aZmax) * 0.5);
2212 aPtext = aPlaneAxes.Location();
2215 // set point to XCAF
2216 if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) {
2217 Handle(XCAFDimTolObjects_DimensionObject) anObj =
2218 Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject);
2219 anObj->SetPointTextAttach(aPtext);
2220 anObj->SetPresentation(aResAnnotation, aPresentName);
2222 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) {
2223 Handle(XCAFDimTolObjects_DatumObject) anObj =
2224 Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject);
2225 anObj->SetPointTextAttach(aPtext);
2226 anObj->SetPresentation(aResAnnotation, aPresentName);
2228 else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) {
2229 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj =
2230 Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject);
2231 anObj->SetPointTextAttach(aPtext);
2232 anObj->SetPresentation(aResAnnotation, aPresentName);
2237 //=======================================================================
2238 //function : readConnectionPoints
2239 //purpose : read connection points for given dimension
2240 //=======================================================================
2241 void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR,
2242 const Handle(Standard_Transient) theGDT,
2243 const Handle(XCAFDimTolObjects_DimensionObject)& theDimObject)
2245 if (theGDT.IsNull() || theDimObject.IsNull())
2247 Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
2248 const Interface_Graph& aGraph = aTP->Graph();
2251 Standard_Real aFact = 1.;
2253 Handle(StepShape_ShapeDimensionRepresentation) aSDR = NULL;
2254 for (Interface_EntityIterator anIt = aGraph.Sharings(theGDT); aSDR.IsNull() && anIt.More(); anIt.Next()) {
2255 Handle(Standard_Transient) anEnt = anIt.Value();
2256 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
2257 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anEnt);
2259 aSDR = !aDCR.IsNull() ? aDCR->Representation() : Handle(StepShape_ShapeDimensionRepresentation)::DownCast(anEnt);
2263 XSAlgo::AlgoContainer()->PrepareForTransfer();
2264 STEPControl_ActorRead anActor;
2265 anActor.PrepareUnits(aSDR, aTP);
2266 aFact = StepData_GlobalFactors::Intance().LengthFactor();
2269 if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2270 // retrieve derived geometry
2271 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theGDT);
2272 Handle(StepRepr_DerivedShapeAspect) aDSA = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->AppliesTo());
2275 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = NULL;
2276 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA); aGISU.IsNull() && anIt.More(); anIt.Next()) {
2277 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2279 if (aGISU.IsNull() || aGISU->NbIdentifiedItem() == 0)
2281 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU->IdentifiedItem()->Value(1));
2282 if (aPoint.IsNull()) {
2283 // try Axis2Placement3d.location instead of CartesianPoint
2284 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2285 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU->IdentifiedItem()->Value(1));
2286 if (anA2P3D.IsNull())
2288 aPoint = anA2P3D->Location();
2291 // set connection point to object
2292 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2293 theDimObject->SetPoint(aPnt);
2295 else if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2296 // retrieve derived geometry
2297 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theGDT);
2298 Handle(StepRepr_DerivedShapeAspect) aDSA1 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatingShapeAspect());
2299 Handle(StepRepr_DerivedShapeAspect) aDSA2 = Handle(StepRepr_DerivedShapeAspect)::DownCast(aDim->RelatedShapeAspect());
2300 if (aDSA1.IsNull() && aDSA2.IsNull())
2302 Handle(StepAP242_GeometricItemSpecificUsage) aGISU1 = NULL;
2303 Handle(StepAP242_GeometricItemSpecificUsage) aGISU2 = NULL;
2304 if (!aDSA1.IsNull()) {
2305 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA1); aGISU1.IsNull() && anIt.More(); anIt.Next()) {
2306 aGISU1 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2309 if (!aDSA2.IsNull()) {
2310 for (Interface_EntityIterator anIt = aGraph.Sharings(aDSA2); aGISU2.IsNull() && anIt.More(); anIt.Next()) {
2311 aGISU2 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIt.Value());
2315 if (!aGISU1.IsNull() && aGISU1->NbIdentifiedItem() > 0) {
2316 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2317 if (aPoint.IsNull()) {
2318 // try Axis2Placement3d.location instead of CartesianPoint
2319 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2320 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU1->IdentifiedItem()->Value(1));
2321 if (!anA2P3D.IsNull())
2322 aPoint = anA2P3D->Location();
2324 if (!aPoint.IsNull()) {
2325 // set connection point to object
2326 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2327 theDimObject->SetPoint(aPnt);
2331 if (!aGISU2.IsNull() && aGISU2->NbIdentifiedItem() > 0) {
2332 Handle(StepGeom_CartesianPoint) aPoint = Handle(StepGeom_CartesianPoint)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2333 if (aPoint.IsNull()) {
2334 // try Axis2Placement3d.location instead of CartesianPoint
2335 Handle(StepGeom_Axis2Placement3d) anA2P3D =
2336 Handle(StepGeom_Axis2Placement3d)::DownCast(aGISU2->IdentifiedItem()->Value(1));
2337 if (!anA2P3D.IsNull())
2338 aPoint = anA2P3D->Location();
2340 if (!aPoint.IsNull()) {
2341 // set connection point to object
2342 gp_Pnt aPnt(aPoint->CoordinatesValue(1) * aFact, aPoint->CoordinatesValue(2) * aFact, aPoint->CoordinatesValue(3) * aFact);
2343 theDimObject->SetPoint2(aPnt);
2349 //=======================================================================
2350 //function : ReadDatums
2351 //purpose : auxiliary
2352 //=======================================================================
2353 static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
2354 const Handle(XCAFDoc_DimTolTool) &DGTTool,
2355 const Interface_Graph &graph,
2356 const Handle(Transfer_TransientProcess) &TP,
2357 const TDF_Label TolerL,
2358 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
2360 if (GTWDR.IsNull()) return Standard_False;
2361 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
2362 if (HADR.IsNull()) return Standard_False;
2363 for (Standard_Integer idr = 1; idr <= HADR->Length(); idr++) {
2364 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
2365 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
2366 if (aDatum.IsNull()) continue;
2367 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
2368 for (subs4.Start(); subs4.More(); subs4.Next()) {
2369 Handle(StepRepr_ShapeAspectRelationship) SAR =
2370 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
2371 if (SAR.IsNull()) continue;
2372 Handle(StepDimTol_DatumFeature) DF =
2373 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
2374 if (DF.IsNull()) continue;
2375 Interface_EntityIterator subs5 = graph.Sharings(DF);
2376 Handle(StepRepr_PropertyDefinition) PropDef;
2377 for (subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
2378 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
2380 if (PropDef.IsNull()) continue;
2381 Handle(StepShape_AdvancedFace) AF;
2382 subs5 = graph.Sharings(PropDef);
2383 for (subs5.Start(); subs5.More(); subs5.Next()) {
2384 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2385 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
2386 if (!SDR.IsNull()) {
2387 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2388 if (!Repr.IsNull() && Repr->NbItems() > 0) {
2389 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
2390 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2394 if (AF.IsNull()) return Standard_False;
2395 Standard_Integer index = TP->MapIndex(AF);
2398 Handle(Transfer_Binder) binder = TP->MapItem(index);
2399 aSh = TransferBRep::ShapeResult(binder);
2401 if (aSh.IsNull()) continue;
2403 if (!STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
2404 DGTTool->SetDatum(shL, TolerL, PropDef->Name(), PropDef->Description(), aDatum->Identification());
2407 return Standard_True;
2410 //=======================================================================
2411 //function : FindShapeIndexForDGT
2412 //purpose : auxiliary find shape index in map og imported shapes
2413 //=======================================================================
2414 static Standard_Integer FindShapeIndexForDGT(const Handle(Standard_Transient)& theEnt,
2415 const Handle(XSControl_WorkSession)& theWS)
2417 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2418 // try to find index of given entity
2419 Standard_Integer anIndex = aTP->MapIndex(theEnt);
2420 if (anIndex > 0 || theEnt.IsNull())
2422 // if theEnt is a geometry item try to find its topological item
2423 const Interface_Graph& aGraph = aTP->Graph();
2424 Interface_EntityIterator anIter = aGraph.Sharings(theEnt);
2425 for (anIter.Start(); anIter.More(); anIter.Next()) {
2426 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)))
2428 anIndex = aTP->MapIndex(anIter.Value());
2436 //=======================================================================
2437 //function : collectShapeAspect
2439 //=======================================================================
2440 static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA,
2441 const Handle(XSControl_WorkSession)& theWS,
2442 NCollection_Sequence<Handle(StepRepr_ShapeAspect)>& theSAs)
2446 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2447 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2448 const Interface_Graph& aGraph = aTP->Graph();
2449 // Retrieve Shape_Aspect, connected to Representation_Item from Derived_Shape_Aspect
2450 if (theSA->IsKind(STANDARD_TYPE(StepRepr_DerivedShapeAspect))) {
2451 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2452 Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = NULL;
2453 for (; aSADR.IsNull() && anIter.More(); anIter.Next()) {
2454 aSADR = Handle(StepRepr_ShapeAspectDerivingRelationship)::DownCast(anIter.Value());
2456 if (!aSADR.IsNull())
2457 collectShapeAspect(aSADR->RelatedShapeAspect(), theWS, theSAs);
2459 else if (theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
2460 theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) {
2461 theSAs.Append(theSA);
2465 // Find all children Shape_Aspect
2466 Standard_Boolean isSimple = Standard_True;
2467 Interface_EntityIterator anIter = aGraph.Sharings(theSA);
2468 for (; anIter.More(); anIter.Next()) {
2469 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship)) &&
2470 !anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2471 Handle(StepRepr_ShapeAspectRelationship) aSAR =
2472 Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
2473 if (aSAR->RelatingShapeAspect() == theSA && !aSAR->RelatedShapeAspect().IsNull()
2474 && !aSAR->RelatedShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_Datum))) {
2475 collectShapeAspect(aSAR->RelatedShapeAspect(), theWS, theSAs);
2476 isSimple = Standard_False;
2480 // If not Composite_Shape_Aspect (or subtype) append to sequence.
2482 theSAs.Append(theSA);
2486 //=======================================================================
2487 //function : getShapeLabel
2489 //=======================================================================
2491 static TDF_Label getShapeLabel(const Handle(StepRepr_RepresentationItem)& theItem,
2492 const Handle(XSControl_WorkSession)& theWS,
2493 const Handle(XCAFDoc_ShapeTool)& theShapeTool)
2496 const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
2497 Standard_Integer index = FindShapeIndexForDGT(theItem, theWS);
2498 TopoDS_Shape aShape;
2500 Handle(Transfer_Binder) aBinder = aTP->MapItem(index);
2501 aShape = TransferBRep::ShapeResult(aBinder);
2503 if (aShape.IsNull())
2505 theShapeTool->Search(aShape, aShapeL, Standard_True, Standard_True, Standard_True);
2509 //=======================================================================
2510 //function : setDatumToXCAF
2512 //=======================================================================
2514 Standard_Boolean STEPCAFControl_Reader::setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
2515 const TDF_Label theGDTL,
2516 const Standard_Integer thePositionCounter,
2517 const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
2518 const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
2519 const Standard_Real theModifValue,
2520 const Handle(TDocStd_Document)& theDoc,
2521 const Handle(XSControl_WorkSession)& theWS)
2523 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
2524 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
2525 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2526 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2527 const Interface_Graph& aGraph = aTP->Graph();
2528 Handle(XCAFDoc_Datum) aDat;
2529 TDF_LabelSequence aShapeLabels;
2530 Handle(XCAFDimTolObjects_DatumObject) aDatObj = new XCAFDimTolObjects_DatumObject();
2532 // Collect all links to shapes
2533 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2534 Interface_EntityIterator anIterD = aGraph.Sharings(theDat);
2535 for (anIterD.Start(); anIterD.More(); anIterD.Next()) {
2536 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value());
2537 if (aSAR.IsNull() || aSAR->RelatingShapeAspect().IsNull())
2539 collectShapeAspect(aSAR->RelatingShapeAspect(), theWS, aSAs);
2540 Handle(StepDimTol_DatumFeature) aDF = Handle(StepDimTol_DatumFeature)::DownCast(aSAR->RelatingShapeAspect());
2541 if (!aSAR->RelatingShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2542 readAnnotation(aTR, aSAR->RelatingShapeAspect(), aDatObj);
2545 // Collect shape labels
2546 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2547 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2550 // Skip datum targets
2551 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2554 // Process all connected GISU
2555 Interface_EntityIterator anIter = aGraph.Sharings(aSA);
2556 for (; anIter.More(); anIter.Next()) {
2557 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
2560 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2561 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2562 if (!aShapeL.IsNull())
2563 aShapeLabels.Append(aShapeL);
2568 // Process datum targets and create objects for them
2569 Standard_Boolean isExistDatumTarget = Standard_False;
2570 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2571 Handle(StepDimTol_PlacedDatumTargetFeature) aDT = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSAs.Value(i));
2574 Handle(XCAFDimTolObjects_DatumObject) aDatTargetObj = new XCAFDimTolObjects_DatumObject();
2575 XCAFDimTolObjects_DatumTargetType aType;
2576 if (!STEPCAFControl_GDTProperty::GetDatumTargetType(aDT->Description(), aType))
2578 aTP->AddWarning(aDT, "Unknown datum target type");
2581 aDatTargetObj->SetDatumTargetType(aType);
2582 Standard_Boolean isValidDT = Standard_False;
2584 // Feature for datum target
2585 TDF_LabelSequence aDTShapeLabels;
2586 Interface_EntityIterator aDTIter = aGraph.Sharings(aDT);
2587 Handle(StepRepr_FeatureForDatumTargetRelationship) aRelationship;
2588 for (; aDTIter.More() && aRelationship.IsNull(); aDTIter.Next()) {
2589 aRelationship = Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(aDTIter.Value());
2591 if (!aRelationship.IsNull()) {
2592 Handle(StepRepr_ShapeAspect) aSA = aRelationship->RelatingShapeAspect();
2593 Interface_EntityIterator aSAIter = aGraph.Sharings(aSA);
2594 for (; aSAIter.More(); aSAIter.Next()) {
2595 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aSAIter.Value());
2598 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2599 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2600 if (!aShapeL.IsNull()) {
2601 aDTShapeLabels.Append(aShapeL);
2602 isValidDT = Standard_True;
2608 if (aType != XCAFDimTolObjects_DatumTargetType_Area && !isValidDT) {
2609 // Try another way of feature connection
2610 for (aDTIter.Start(); aDTIter.More(); aDTIter.Next()) {
2611 Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aDTIter.Value());
2614 for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
2615 TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
2616 if (!aShapeL.IsNull()) {
2617 aDTShapeLabels.Append(aShapeL);
2618 isValidDT = Standard_True;
2624 if (aType == XCAFDimTolObjects_DatumTargetType_Area) {
2625 // Area datum target
2626 if (aRelationship.IsNull())
2628 Handle(StepRepr_ShapeAspect) aSA = aRelationship->RelatingShapeAspect();
2629 Interface_EntityIterator aSAIter = aGraph.Sharings(aSA);
2630 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2631 for (; aSAIter.More() && aGISU.IsNull(); aSAIter.Next()) {
2632 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aSAIter.Value());
2634 Handle(StepRepr_RepresentationItem) anItem;
2635 if (!aGISU.IsNull() && aGISU->NbIdentifiedItem() > 0)
2636 anItem = aGISU->IdentifiedItemValue(1);
2637 if (anItem.IsNull())
2639 Standard_Integer anItemIndex = FindShapeIndexForDGT(anItem, theWS);
2640 if (anItemIndex > 0) {
2641 Handle(Transfer_Binder) aBinder = aTP->MapItem(anItemIndex);
2642 TopoDS_Shape anItemShape = TransferBRep::ShapeResult(aBinder);
2643 aDatTargetObj->SetDatumTarget(anItemShape);
2644 isValidDT = Standard_True;
2648 // Point/line/rectangle/circle datum targets
2649 Interface_EntityIterator anIter = aGraph.Sharings(aDT);
2650 Handle(StepRepr_PropertyDefinition) aPD;
2651 for (; anIter.More() && aPD.IsNull(); anIter.Next()) {
2652 aPD = Handle(StepRepr_PropertyDefinition)::DownCast(anIter.Value());
2654 if (!aPD.IsNull()) {
2655 anIter = aGraph.Sharings(aPD);
2656 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
2657 for (; anIter.More() && aSDR.IsNull(); anIter.Next()) {
2658 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anIter.Value());
2660 if (!aSDR.IsNull()) {
2661 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP
2662 = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(aSDR->UsedRepresentation());
2663 if (!aSRWP.IsNull()) {
2664 isValidDT = Standard_True;
2665 // Collect parameters of datum target
2666 for (Standard_Integer j = aSRWP->Items()->Lower(); j <= aSRWP->Items()->Upper(); j++)
2668 if (aSRWP->ItemsValue(j).IsNull())
2670 if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2672 Handle(StepGeom_Axis2Placement3d) anAx
2673 = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(j));
2674 XSAlgo::AlgoContainer()->PrepareForTransfer();
2675 STEPControl_ActorRead anActor;
2676 anActor.PrepareUnits(aSRWP, aTP);
2677 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(anAx);
2678 aDatTargetObj->SetDatumTargetAxis(anAxis->Ax2());
2680 else if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
2682 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
2683 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(j));
2684 Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
2685 StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
2686 if (anUnit.IsNull())
2688 Handle(StepBasic_NamedUnit) aNU = anUnit.NamedUnit();
2691 STEPConstruct_UnitContext anUnitCtx;
2692 anUnitCtx.ComputeFactors(aNU);
2693 aVal = aVal * anUnitCtx.LengthFactor();
2694 if (aM->Name()->String().IsEqual("target length") ||
2695 aM->Name()->String().IsEqual("target diameter"))
2696 aDatTargetObj->SetDatumTargetLength(aVal);
2698 aDatTargetObj->SetDatumTargetWidth(aVal);
2706 // Create datum target object
2708 TDF_Label aDatL = aDGTTool->AddDatum(theDat->Name(), theDat->Description(), theDat->Identification());
2709 myGDTMap.Bind(aDT, aDatL);
2710 aDGTTool->Lock(aDatL);
2711 aDat = XCAFDoc_Datum::Set(aDatL);
2712 aDGTTool->SetDatum(aDTShapeLabels, aDatL);
2713 aDatTargetObj->SetName(theDat->Identification());
2714 aDatTargetObj->SetPosition(thePositionCounter);
2715 if (!theXCAFModifiers.IsEmpty())
2716 aDatTargetObj->SetModifiers(theXCAFModifiers);
2717 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2718 aDatTargetObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2719 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2720 aDatTargetObj->IsDatumTarget(Standard_True);
2721 aDatTargetObj->SetDatumTargetNumber(aDT->TargetId()->IntegerValue());
2722 readAnnotation(aTR, aDT, aDatTargetObj);
2723 aDat->SetObject(aDatTargetObj);
2724 isExistDatumTarget = Standard_True;
2728 if (aShapeLabels.Length() > 0 || !isExistDatumTarget) {
2729 // Create object for datum
2730 TDF_Label aDatL = aDGTTool->AddDatum(theDat->Name(), theDat->Description(), theDat->Identification());
2731 myGDTMap.Bind(theDat, aDatL);
2732 // bind datum label with all reference datum_feature entities
2733 for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
2734 Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
2735 if (aSA.IsNull() || aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
2737 myGDTMap.Bind(aSA, aDatL);
2739 aDGTTool->Lock(aDatL);
2740 aDat = XCAFDoc_Datum::Set(aDatL);
2741 aDGTTool->SetDatum(aShapeLabels, aDatL);
2742 aDatObj->SetName(theDat->Identification());
2743 aDatObj->SetPosition(thePositionCounter);
2744 if (!theXCAFModifiers.IsEmpty())
2745 aDatObj->SetModifiers(theXCAFModifiers);
2746 if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
2747 aDatObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
2748 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
2749 if (aDatObj->GetPresentation().IsNull()) {
2750 // Try find annotation connected to datum entity (not right case, according recommended practices)
2751 readAnnotation(aTR, theDat, aDatObj);
2753 aDat->SetObject(aDatObj);
2756 return Standard_True;
2760 //=======================================================================
2761 //function : ReadDatums
2762 //purpose : auxiliary
2763 //=======================================================================
2764 Standard_Boolean STEPCAFControl_Reader::readDatumsAP242(const Handle(Standard_Transient)& theEnt,
2765 const TDF_Label theGDTL,
2766 const Handle(TDocStd_Document)& theDoc,
2767 const Handle(XSControl_WorkSession)& theWS)
2769 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2770 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2771 const Interface_Graph& aGraph = aTP->Graph();
2773 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2774 for (anIter.Start(); anIter.More(); anIter.Next()) {
2775 Handle(Standard_Transient) anAtr = anIter.Value();
2776 if (anAtr->IsKind(STANDARD_TYPE(StepDimTol_DatumSystem)))
2778 Standard_Integer aPositionCounter = 0;//position on frame
2779 Handle(StepDimTol_DatumSystem) aDS = Handle(StepDimTol_DatumSystem)::DownCast(anAtr);
2780 Interface_EntityIterator anIterDS = aGraph.Sharings(aDS);
2781 for (anIterDS.Start(); anIterDS.More(); anIterDS.Next()) {
2782 Handle(Standard_Transient) anAtrDS = anIterDS.Value();
2783 if (anAtrDS->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
2786 Handle(StepAP242_GeometricItemSpecificUsage)aAxGISUI
2787 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anAtrDS);
2788 if (aAxGISUI->IdentifiedItemValue(1)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2790 Handle(StepGeom_Axis2Placement3d) anAx
2791 = Handle(StepGeom_Axis2Placement3d)::DownCast(aAxGISUI->IdentifiedItemValue(1));
2792 Handle(XCAFDoc_GeomTolerance) aTol;
2793 if (theGDTL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aTol))
2795 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aTol->GetObject();
2796 Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
2797 Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
2798 Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
2802 if (!aDirArr.IsNull() && aDirArr->Length() > 2 &&
2803 !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
2804 !aLocArr.IsNull() && aLocArr->Length() > 2)
2806 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, aDirArr->Lower() + 2);
2807 aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower() + 1, aDirRArr->Lower() + 2);
2808 aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower() + 1, aLocArr->Lower() + 2);
2809 gp_Ax2 anA(aPnt, aDir, aDirR);
2810 anObj->SetAxis(anA);
2811 aTol->SetObject(anObj);
2817 if (aDS->NbConstituents() > 0)
2819 //get datum feature and datum target from datum system
2820 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aDRCA = aDS->Constituents();
2821 if (!aDRCA.IsNull())
2823 for (Standard_Integer i = aDRCA->Lower(); i <= aDRCA->Upper(); i++)
2825 Handle(StepDimTol_DatumReferenceCompartment) aDRC = aDRCA->Value(i);
2827 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModif = aDRC->Modifiers();
2828 XCAFDimTolObjects_DatumModifiersSequence aXCAFModifiers;
2829 XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal = XCAFDimTolObjects_DatumModifWithValue_None;
2830 Standard_Real aModifValue = 0;
2831 if (!aModif.IsNull())
2833 for (Standard_Integer m = aModif->Lower(); m <= aModif->Upper(); m++)
2835 if (aModif->Value(m).CaseNumber() == 2)
2836 aXCAFModifiers.Append(
2837 (XCAFDimTolObjects_DatumSingleModif)aModif->Value(m).
2838 SimpleDatumReferenceModifierMember()->Value());
2839 else if (aModif->Value(m).CaseNumber() == 1)
2841 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModif->Value(m).DatumReferenceModifierWithValue()->ModifierType() + 1);
2842 Standard_Real aVal = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2843 StepBasic_Unit anUnit = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2844 if (anUnit.IsNull()) continue;
2845 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2846 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2847 STEPConstruct_UnitContext anUnitCtx;
2848 anUnitCtx.ComputeFactors(NU);
2849 aModifValue = aVal * anUnitCtx.LengthFactor();
2854 Interface_EntityIterator anIterDRC = aGraph.Shareds(aDRC);
2855 for (anIterDRC.Start(); anIterDRC.More(); anIterDRC.Next()) {
2857 if (anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2859 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRC.Value());
2860 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue, theDoc, theWS);
2862 else if (anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_DatumReferenceElement)))
2864 Handle(StepDimTol_DatumReferenceElement) aDRE
2865 = Handle(StepDimTol_DatumReferenceElement)::DownCast(anIterDRC.Value());
2866 //get modifiers from group of datums
2867 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifE = aDRE->Modifiers();
2868 if (!aModifE.IsNull())
2870 for (Standard_Integer k = aModifE->Lower(); k <= aModifE->Upper(); k++)
2872 if (aModifE->Value(k).CaseNumber() == 2)
2873 aXCAFModifiers.Append(
2874 (XCAFDimTolObjects_DatumSingleModif)aModifE->Value(k).
2875 SimpleDatumReferenceModifierMember()->Value());
2876 else if (aModifE->Value(k).CaseNumber() == 1)
2878 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierType() + 1);
2879 Standard_Real aVal = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2880 StepBasic_Unit anUnit = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2881 if (anUnit.IsNull()) continue;
2882 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
2883 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2884 STEPConstruct_UnitContext anUnitCtx;
2885 anUnitCtx.ComputeFactors(NU);
2886 aModifValue = aVal * anUnitCtx.LengthFactor();
2890 Interface_EntityIterator anIterDRE = aGraph.Shareds(aDRE);
2891 for (anIterDRE.Start(); anIterDRE.More(); anIterDRE.Next()) {
2892 if (anIterDRE.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2894 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRE.Value());
2895 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue, theDoc, theWS);
2905 return Standard_True;
2908 //=======================================================================
2909 //function : createGeomTolObjectInXCAF
2911 //=======================================================================
2912 TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
2913 const Handle(TDocStd_Document)& theDoc,
2914 const Handle(XSControl_WorkSession)& theWS)
2917 if (!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
2918 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) &&
2919 !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
2924 Handle(TCollection_HAsciiString) aSemanticName;
2926 // protection against invalid input
2927 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2928 Handle(StepDimTol_GeometricTolerance) aGeomTol = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2929 if (aGeomTol->TolerancedShapeAspect().IsNull())
2931 aSemanticName = aGeomTol->Name();
2933 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2934 Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2935 if (aDim->AppliesTo().IsNull())
2937 aSemanticName = aDim->Name();
2939 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
2940 Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
2941 if (aDim->RelatedShapeAspect().IsNull() || aDim->RelatingShapeAspect().IsNull())
2943 aSemanticName = aDim->Name();
2946 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
2947 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
2948 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
2949 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
2950 const Interface_Graph& aGraph = aTP->Graph();
2951 Standard_Boolean isAllAround = Standard_False;
2952 Standard_Boolean isAllOver = Standard_False;
2954 // find RepresentationItem for current Ent
2955 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI1, aSeqRI2;
2957 // Collect all Shape_Aspect entities
2958 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2959 for (anIter.Start(); anIter.More(); anIter.Next()) {
2960 Handle(Standard_Transient) anAtr = anIter.Value();
2961 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2962 if (anAtr->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)))
2964 //if associating tolerances with part (All-Over)
2965 Interface_EntityIterator anIterSDR = aGraph.Sharings(anAtr);
2966 for (anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next())
2968 Handle(Standard_Transient) anAtrSDR = anIterSDR.Value();
2969 if (anAtrSDR->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
2971 isAllOver = Standard_True;
2972 Interface_EntityIterator anIterABSR = aGraph.Shareds(anAtrSDR);
2973 for (anIterABSR.Start(); anIterABSR.More(); anIterABSR.Next())
2975 Handle(Standard_Transient) anAtrABSR = anIterABSR.Value();
2976 if (anAtrABSR->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
2978 aSeqRI1.Append(anAtrABSR);
2984 else if (anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
2985 anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
2987 //if tolerance attached to dimension
2988 Interface_EntityIterator anIterDim = aGraph.Shareds(anAtr);
2989 for (anIterDim.Start(); anIterDim.More(); anIterDim.Next())
2991 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anIterDim.Value());
2992 if (!aSA.IsNull()) {
2993 collectShapeAspect(aSA, theWS, aSAs);
2997 else if (anAtr->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
2999 if (anAtr->IsKind(STANDARD_TYPE(StepRepr_AllAroundShapeAspect)))
3001 // if applied AllAround Modifier
3002 isAllAround = Standard_True;
3004 // dimensions and default tolerances
3005 Handle(StepRepr_ShapeAspect) aSA = Handle(StepRepr_ShapeAspect)::DownCast(anAtr);
3006 if (!aSA.IsNull()) {
3007 collectShapeAspect(aSA, theWS, aSAs);
3011 // Collect all representation items
3012 if (!aSAs.IsEmpty())
3014 //get representation items
3015 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI;
3016 for (Standard_Integer i = aSAs.Lower(); i <= aSAs.Upper(); i++)
3018 Interface_EntityIterator anIterSA = aGraph.Sharings(aSAs.Value(i));
3019 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
3020 Handle(StepRepr_PropertyDefinition) PropD;
3021 for (anIterSA.Start(); anIterSA.More() && aGISU.IsNull() && PropD.IsNull(); anIterSA.Next()) {
3022 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
3023 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(anIterSA.Value());
3025 if (!PropD.IsNull())//for old version
3027 Handle(StepRepr_RepresentationItem) RI;
3028 Interface_EntityIterator subs4 = aGraph.Sharings(PropD);
3029 for (subs4.Start(); subs4.More(); subs4.Next()) {
3030 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
3031 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
3032 if (!SDR.IsNull()) {
3033 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
3034 if (!Repr.IsNull() && Repr->NbItems() > 0) {
3035 RI = Repr->ItemsValue(1);
3039 if (RI.IsNull()) continue;
3041 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
3043 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
3044 if (EC.IsNull()) continue;
3045 Handle(TCollection_HAsciiString) aName;
3046 Handle(StepShape_DimensionalSize) DimSize =
3047 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
3048 Standard_Real dim1 = -1., dim2 = -1.;
3049 subs4 = aGraph.Sharings(DimSize);
3050 for (subs4.Start(); subs4.More(); subs4.Next()) {
3051 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
3052 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
3053 if (!DimCharR.IsNull()) {
3054 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
3055 if (!SDimR.IsNull() && SDimR->NbItems() > 0) {
3056 Handle(StepRepr_RepresentationItem) anItem = SDimR->ItemsValue(1);
3057 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(anItem);
3060 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
3061 //if(CID.IsNull()) continue;
3062 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
3063 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
3064 //if(CIDM.IsNull()) continue;
3065 //if(CIDM->ArrTransient().IsNull()) continue;
3066 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
3067 //if(CID.CaseMem(CIDM)==1)
3068 // HARI = CID.ListRepresentationItem();
3069 //if(CID.CaseMem(CIDM)==2)
3070 // HARI = CID.SetRepresentationItem();
3071 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
3072 if (HARI.IsNull()) continue;
3073 if (HARI->Length() > 0) {
3074 Handle(StepRepr_RepresentationItem) RI1 = HARI->Value(1);
3075 if (RI1.IsNull()) continue;
3076 if (RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
3077 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
3078 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
3079 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
3080 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
3081 if (anUnit.IsNull()) continue;
3082 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3083 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3084 STEPConstruct_UnitContext anUnitCtx;
3085 anUnitCtx.ComputeFactors(NU);
3086 dim1 = dim1 * anUnitCtx.LengthFactor();
3089 if (HARI->Length() > 1) {
3090 Handle(StepRepr_RepresentationItem) RI2 = HARI->Value(2);
3091 if (RI2.IsNull()) continue;
3092 if (RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
3093 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
3094 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
3095 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
3096 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
3097 if (anUnit.IsNull()) continue;
3098 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3099 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3100 STEPConstruct_UnitContext anUnitCtx;
3101 anUnitCtx.ComputeFactors(NU);
3102 dim2 = dim2 * anUnitCtx.LengthFactor();
3109 if (dim1 < 0) continue;
3110 if (dim2 < 0) dim2 = dim1;
3111 //std::cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<std::endl;
3112 // now we know edge_curve and value range therefore
3113 // we can create corresponding D> labels
3114 Standard_Integer index = aTP->MapIndex(EC);
3117 Handle(Transfer_Binder) binder = aTP->MapItem(index);
3118 aSh = TransferBRep::ShapeResult(binder);
3120 if (aSh.IsNull()) continue;
3122 if (!aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
3123 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1, 2);
3124 arr->SetValue(1, dim1);
3125 arr->SetValue(2, dim2);
3126 aDGTTool->SetDimTol(shL, 1, arr, aName, DimSize->Name());
3128 // read tolerances and datums
3129 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
3130 Handle(StepDimTol_GeometricTolerance) GT =
3131 Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
3132 // read common data for tolerance
3133 //Standard_Real dim = GT->Magnitude()->ValueComponent();
3134 Handle(StepBasic_MeasureWithUnit) dim3 = GT->Magnitude();
3135 if (dim3.IsNull()) continue;
3136 Standard_Real dim = dim3->ValueComponent();
3137 StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent();
3138 if (anUnit.IsNull()) continue;
3139 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3140 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3141 STEPConstruct_UnitContext anUnitCtx;
3142 anUnitCtx.ComputeFactors(NU);
3143 dim = dim * anUnitCtx.LengthFactor();
3144 //std::cout<<"GeometricTolerance: Magnitude = "<<dim<<std::endl;
3145 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1, 1);
3146 arr->SetValue(1, dim);
3147 Handle(TCollection_HAsciiString) aName = GT->Name();
3148 Handle(TCollection_HAsciiString) aDescription = GT->Description();
3149 Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
3150 if (AF.IsNull()) continue;
3151 Standard_Integer index = aTP->MapIndex(AF);
3154 Handle(Transfer_Binder) binder = aTP->MapItem(index);
3155 aSh = TransferBRep::ShapeResult(binder);
3157 if (aSh.IsNull()) continue;
3159 if (!aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
3160 // read specific data for tolerance
3161 if (GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) {
3162 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
3163 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(theEnt);
3164 Standard_Integer kind = 20;
3165 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
3166 GTComplex->GetModifiedGeometricTolerance();
3167 if (!MGT.IsNull()) {
3168 kind = kind + MGT->Modifier() + 1;
3170 TDF_Label TolerL = aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription);
3171 // translate datums connected with this tolerance
3172 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
3173 GTComplex->GetGeometricToleranceWithDatumReference();
3174 if (!GTWDR.IsNull()) {
3175 ReadDatums(aSTool, aDGTTool, aGraph, aTP, TolerL, GTWDR);
3178 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) {
3179 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
3180 Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(theEnt);
3181 if (GTWDR.IsNull()) continue;
3182 Standard_Integer kind = 0;
3183 if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24;
3184 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25;
3185 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26;
3186 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27;
3187 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28;
3188 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29;
3189 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30;
3190 else if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31;
3191 //std::cout<<"GTWDR: kind="<<kind<<std::endl;
3192 TDF_Label TolerL = aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription);
3193 ReadDatums(aSTool, aDGTTool, aGraph, aTP, TolerL, GTWDR);
3195 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) {
3196 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
3197 Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(theEnt);
3198 Standard_Integer kind = 35 + MGT->Modifier();
3199 aDGTTool->SetDimTol(shL, kind, arr, aName, aDescription);
3201 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) {
3202 aDGTTool->SetDimTol(shL, 38, arr, aName, aDescription);
3204 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) {
3205 aDGTTool->SetDimTol(shL, 39, arr, aName, aDescription);
3207 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) {
3208 aDGTTool->SetDimTol(shL, 40, arr, aName, aDescription);
3210 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) {
3211 aDGTTool->SetDimTol(shL, 41, arr, aName, aDescription);
3213 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) {
3214 aDGTTool->SetDimTol(shL, 42, arr, aName, aDescription);
3216 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) {
3217 aDGTTool->SetDimTol(shL, 43, arr, aName, aDescription);
3219 else if (GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) {
3220 aDGTTool->SetDimTol(shL, 44, arr, aName, aDescription);
3226 if (aGISU.IsNull()) continue;
3227 Standard_Integer j = 1;
3228 for (; j <= aGISU->NbIdentifiedItem(); j++) {
3229 aSeqRI.Append(aGISU->IdentifiedItemValue(j));
3233 if (!aSeqRI.IsEmpty())
3235 if (aSeqRI1.IsEmpty())
3242 if (aSeqRI1.IsEmpty())
3245 TDF_LabelSequence aShLS1, aShLS2;
3248 for (Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper();i++)
3250 Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS);
3253 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3254 aSh = TransferBRep::ShapeResult(aBinder);
3259 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
3260 if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
3262 TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
3266 aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
3267 if (!edgeL.IsNull())
3268 aShLS1.Append(edgeL);
3273 aShLS1.Append(aShL);
3276 if (!aSeqRI2.IsEmpty())
3278 //for dimensional location
3279 for (Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper();i++)
3281 Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI2.Value(i), theWS);
3284 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3285 aSh = TransferBRep::ShapeResult(aBinder);
3290 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
3291 if (aShL.IsNull() && aSh.ShapeType() == TopAbs_WIRE)
3293 TopExp_Explorer ex(aSh, TopAbs_EDGE, TopAbs_SHAPE);
3297 aSTool->Search(ex.Current(), edgeL, Standard_True, Standard_True, Standard_True);
3298 if (!edgeL.IsNull())
3299 aShLS2.Append(edgeL);
3304 aShLS2.Append(aShL);
3309 if (!aShLS1.IsEmpty())
3312 if (!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
3314 aGDTL = aDGTTool->AddDimension();
3315 myGDTMap.Bind(theEnt, aGDTL);
3316 aDGTTool->Lock(aGDTL);
3317 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
3318 TCollection_AsciiString aStr("DGT:Dimensional_");
3319 if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
3321 aStr.AssignCat("Size");
3323 else if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
3325 aStr.AssignCat("Location");
3327 TDataStd_Name::Set(aGDTL, aStr);
3329 if (!aShLS2.IsEmpty())
3331 aDGTTool->SetDimension(aShLS1, aShLS2, aGDTL);
3335 TDF_LabelSequence aEmptySeq;
3336 aDGTTool->SetDimension(aShLS1, aEmptySeq, aGDTL);
3341 aGDTL = aDGTTool->AddGeomTolerance();
3342 myGDTMap.Bind(theEnt, aGDTL);
3343 aDGTTool->Lock(aGDTL);
3344 Handle(XCAFDoc_GeomTolerance) aGTol = XCAFDoc_GeomTolerance::Set(aGDTL);
3345 TCollection_AsciiString aStr("DGT:GeomTolerance");
3346 TDataStd_Name::Set(aGDTL, aStr);
3347 aDGTTool->SetGeomTolerance(aShLS1, aGDTL);
3348 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGTol->GetObject();
3350 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Around);
3352 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Over);
3353 aGTol->SetObject(anObj);
3358 TCollection_ExtendedString str(aSemanticName->String());
3359 TDataStd_Name::Set(aGDTL, str);
3362 readDatumsAP242(theEnt, aGDTL, theDoc, theWS);
3367 //=======================================================================
3368 //function : convertAngleValue
3369 //purpose : auxiliary
3370 //=======================================================================
3371 void convertAngleValue(
3372 const STEPConstruct_UnitContext& anUnitCtx,
3373 Standard_Real& aVal)
3375 // convert radian to deg
3376 Standard_Real aFact = anUnitCtx.PlaneAngleFactor() * 180 / M_PI;
3377 // in order to avoid inaccuracy of calculation perform conversion
3378 // only if aFact not equal 1 with some precision
3379 if (fabs(1. - aFact) > Precision::Confusion())
3381 aVal = aVal * aFact;
3386 //=======================================================================
3387 //function : setDimObjectToXCAF
3389 //=======================================================================
3390 static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3391 const TDF_Label& aDimL,
3392 const Handle(TDocStd_Document)& theDoc,
3393 const Handle(XSControl_WorkSession)& theWS)
3395 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
3396 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
3397 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3398 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
3399 const Interface_Graph& aGraph = aTP->Graph();
3400 Handle(XCAFDimTolObjects_DimensionObject) aDimObj;
3401 if (!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
3402 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
3405 Handle(StepShape_DimensionalSize) aDimSize =
3406 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
3407 Handle(StepShape_DimensionalLocation) aDimLocation =
3408 Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
3410 aDimObj = new XCAFDimTolObjects_DimensionObject();
3411 Standard_Real aDim1 = -1., aDim2 = -1., aDim3 = -1.;
3412 Standard_Boolean isPlusMinusTolerance = Standard_False;
3413 Handle(StepShape_TypeQualifier) aTQ;
3414 Handle(StepShape_ValueFormatTypeQualifier) aVFTQ;
3415 Handle(StepShape_ToleranceValue) aTV;
3416 Handle(StepShape_LimitsAndFits) aLAF;
3417 Handle(StepRepr_CompoundRepresentationItem) aCRI;
3418 Handle(StepGeom_Axis2Placement3d) anAP;
3420 Interface_EntityIterator anIterDim;
3421 if (!aDimSize.IsNull())
3423 anIterDim = aGraph.Sharings(aDimSize);
3427 anIterDim = aGraph.Sharings(aDimLocation);
3429 for (anIterDim.Start(); anIterDim.More(); anIterDim.Next()) {
3430 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
3431 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anIterDim.Value());
3432 Handle(StepShape_PlusMinusTolerance) aPMT =
3433 Handle(StepShape_PlusMinusTolerance)::DownCast(anIterDim.Value());
3434 if (!aDCR.IsNull()) {
3435 Handle(StepShape_ShapeDimensionRepresentation) aSDR = aDCR->Representation();
3436 if (!aSDR.IsNull()) {
3437 Handle(StepRepr_HArray1OfRepresentationItem) aHARI = aSDR->Items();
3439 if (!aHARI.IsNull())
3441 for (Standard_Integer nr = aHARI->Lower(); nr <= aHARI->Upper(); nr++)
3443 Handle(StepRepr_RepresentationItem) aDRI = aHARI->Value(nr);
3444 if (aDRI.IsNull()) continue;
3446 if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))) {
3447 // simple value / range
3448 Handle(StepRepr_ReprItemAndMeasureWithUnit) aMWU =
3449 Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aDRI);
3450 Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
3451 StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
3452 if (anUnit.IsNull())
3454 if (!(anUnit.CaseNum(anUnit.Value()) == 1))
3456 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3457 STEPConstruct_UnitContext anUnitCtx;
3458 anUnitCtx.ComputeFactors(NU);
3459 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
3460 aVal = aVal * anUnitCtx.LengthFactor();
3464 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit))) {
3465 convertAngleValue(anUnitCtx, aVal);
3467 Handle(TCollection_HAsciiString) aName = aMWU->Name();
3468 if (aName->Search("upper") > 0) // upper limit
3470 else // lower limit or simple nominal value
3473 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnitAndQRI))) {
3474 // value with qualifier (minimum/maximum/average)
3475 Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI) aMWU =
3476 Handle(StepRepr_ReprItemAndMeasureWithUnitAndQRI)::DownCast(aDRI);
3477 Standard_Real aVal = aMWU->GetMeasureWithUnit()->ValueComponent();
3478 StepBasic_Unit anUnit = aMWU->GetMeasureWithUnit()->UnitComponent();
3479 if (anUnit.IsNull())
3481 if (!(anUnit.CaseNum(anUnit.Value()) == 1))
3483 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3484 STEPConstruct_UnitContext anUnitCtx;
3485 anUnitCtx.ComputeFactors(NU);
3486 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI))) {
3487 aVal = aVal * anUnitCtx.LengthFactor();
3490 if (aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI))) {
3491 convertAngleValue(anUnitCtx, aVal);
3493 Handle(StepShape_QualifiedRepresentationItem) aQRI = aMWU->GetQualifiedRepresentationItem();
3494 if (aQRI->Qualifiers()->Length() == 0) {
3498 Handle(StepShape_TypeQualifier) aValueType = aQRI->Qualifiers()->Value(1).TypeQualifier();
3499 if (aValueType->Name()->String().IsEqual("minimum"))
3501 else if (aValueType->Name()->String().IsEqual("maximum"))
3505 else if (aDRI->IsKind(STANDARD_TYPE(StepShape_QualifiedRepresentationItem))) {
3507 Handle(StepShape_QualifiedRepresentationItem) aQRI =
3508 Handle(StepShape_QualifiedRepresentationItem)::DownCast(aDRI);
3509 for (Standard_Integer l = 1; l <= aQRI->NbQualifiers(); l++)
3511 aTQ = aQRI->Qualifiers()->Value(l).TypeQualifier();
3512 aVFTQ = aQRI->Qualifiers()->Value(l).ValueFormatTypeQualifier();
3515 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
3516 Handle(StepRepr_DescriptiveRepresentationItem) aDescription =
3517 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aDRI);
3518 aDimObj->AddDescription(aDescription->Description(), aDescription->Name());
3520 else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_CompoundRepresentationItem))) {
3521 aCRI = Handle(StepRepr_CompoundRepresentationItem)::DownCast(aDRI);
3523 else if (aDRI->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
3525 anAP = Handle(StepGeom_Axis2Placement3d)::DownCast(aDRI);
3531 else if (!aPMT.IsNull())
3533 isPlusMinusTolerance = Standard_True;
3534 StepShape_ToleranceMethodDefinition aTMD = aPMT->Range();
3535 if (aPMT.IsNull()) continue;
3536 if (aTMD.CaseNumber() == 1)
3537 //! 1 -> ToleranceValue from StepShape
3538 //! 2 -> LimitsAndFits from StepShape
3540 //plus minus tolerance
3541 aTV = aTMD.ToleranceValue();
3542 if (aTV.IsNull()) continue;
3544 Handle(Standard_Transient) aUpperBound = aTV->UpperBound();
3545 if(aUpperBound.IsNull())
3547 Handle(StepBasic_MeasureWithUnit) aMWU;
3548 if(aUpperBound->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit)) )
3549 aMWU = Handle(StepBasic_MeasureWithUnit)::DownCast(aUpperBound);
3550 else if(aUpperBound->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit)) )
3552 Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasureItem =
3553 Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aUpperBound);
3554 aMWU = aReprMeasureItem->GetMeasureWithUnit();
3559 Standard_Real aVal = aMWU->ValueComponent();
3560 StepBasic_Unit anUnit = aMWU->UnitComponent();
3561 if (anUnit.IsNull()) continue;
3562 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3563 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3564 STEPConstruct_UnitContext anUnitCtxUpperBound;
3565 anUnitCtxUpperBound.ComputeFactors(NU);
3566 if (aMWU->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) ||
3567 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI)))
3569 convertAngleValue(anUnitCtxUpperBound, aVal);
3571 else if ((aMWU->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit)) && anUnitCtxUpperBound.LengthFactor() > 0.) ||
3572 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI)))
3574 aVal = aVal * anUnitCtxUpperBound.LengthFactor();
3579 Handle(Standard_Transient) aLowerBound = aTV->LowerBound();
3580 if(aLowerBound.IsNull())
3583 if(aLowerBound->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit)) )
3584 aMWU = Handle(StepBasic_MeasureWithUnit)::DownCast(aLowerBound);
3585 else if(aLowerBound->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit)) )
3587 Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasureItem =
3588 Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aLowerBound);
3589 aMWU = aReprMeasureItem->GetMeasureWithUnit();
3595 aVal = aMWU->ValueComponent();
3596 anUnit = aMWU->UnitComponent();
3597 if (anUnit.IsNull()) continue;
3598 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
3599 NU = anUnit.NamedUnit();
3600 STEPConstruct_UnitContext anUnitCtxLowerBound;
3601 anUnitCtxLowerBound.ComputeFactors(NU);
3602 if (aMWU->IsKind(STANDARD_TYPE(StepBasic_PlaneAngleMeasureWithUnit)) ||
3603 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI)))
3605 convertAngleValue(anUnitCtxLowerBound, aVal);
3607 else if ((aMWU->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit)) && anUnitCtxLowerBound.LengthFactor() > 0.) ||
3608 aMWU->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI)))
3610 aVal = aVal * anUnitCtxLowerBound.LengthFactor();
3616 // class of tolerance
3617 aLAF = aTMD.LimitsAndFits();
3622 if (aDim1 < 0) return;
3625 aDimObj->SetValue(aDim1);
3628 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1, 2);
3629 anArr->SetValue(1, aDim1);
3630 anArr->SetValue(2, aDim2);
3631 aDimObj->SetValues(anArr);
3635 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1, 3);
3636 if (!isPlusMinusTolerance)
3638 aDim2 = aDim1 - aDim2;
3639 aDim3 = aDim3 - aDim1;
3641 anArr->SetValue(1, aDim1);
3642 anArr->SetValue(2, aDim2);
3643 anArr->SetValue(3, aDim3);
3644 aDimObj->SetValues(anArr);
3648 XCAFDimTolObjects_DimensionQualifier aQ;
3649 if (STEPCAFControl_GDTProperty::GetDimQualifierType(aTQ->Name(), aQ))
3651 aDimObj->SetQualifier(aQ);
3655 if (!aVFTQ.IsNull())
3657 //A typical value would be 'NR2 2.2'
3658 TCollection_HAsciiString aFormat = aVFTQ->FormatType();
3659 Standard_Integer i = aFormat.Location(1, ' ', 1, aFormat.Length());
3660 aFormat.SubString(i + 1, i + 1)->IntegerValue();
3661 aDimObj->SetNbOfDecimalPlaces(aFormat.SubString(i + 1, i + 1)->IntegerValue(),
3662 aFormat.SubString(i + 3, i + 3)->IntegerValue());
3667 //get class of tolerance
3668 Standard_Boolean aHolle = Standard_False;
3669 XCAFDimTolObjects_DimensionFormVariance aFV = XCAFDimTolObjects_DimensionFormVariance_None;
3670 XCAFDimTolObjects_DimensionGrade aG = XCAFDimTolObjects_DimensionGrade_IT01;
3671 STEPCAFControl_GDTProperty::GetDimClassOfTolerance(aLAF, aHolle, aFV, aG);
3672 aDimObj->SetClassOfTolerance(aHolle, aFV, aG);
3675 if (!aCRI.IsNull() && !aCRI->ItemElement().IsNull() && aCRI->ItemElement()->Length() > 0)
3678 XCAFDimTolObjects_DimensionModifiersSequence aModifiers;
3679 STEPCAFControl_GDTProperty::GetDimModifiers(aCRI, aModifiers);
3680 if (aModifiers.Length() > 0)
3681 aDimObj->SetModifiers(aModifiers);
3684 Handle(TCollection_HAsciiString) aName;
3685 if (!aDimSize.IsNull())
3687 aName = aDimSize->Name();
3691 aName = aDimLocation->Name();
3693 XCAFDimTolObjects_DimensionType aType = XCAFDimTolObjects_DimensionType_Location_None;
3694 if (!STEPCAFControl_GDTProperty::GetDimType(aName, aType))
3696 if (!aDimSize.IsNull())
3698 Handle(StepShape_AngularSize) anAngSize =
3699 Handle(StepShape_AngularSize)::DownCast(aDimSize);
3700 if (!anAngSize.IsNull())
3702 //get qualifier for angular value
3703 aType = XCAFDimTolObjects_DimensionType_Size_Angular;
3704 if (anAngSize->AngleSelection() == StepShape_Equal)
3705 aDimObj->SetAngularQualifier(XCAFDimTolObjects_AngularQualifier_Equal);
3706 else if (anAngSize->AngleSelection() == StepShape_Large)
3707 aDimObj->SetAngularQualifier(XCAFDimTolObjects_AngularQualifier_Large);
3708 else if (anAngSize->AngleSelection() == StepShape_Small)
3709 aDimObj->SetAngularQualifier(XCAFDimTolObjects_AngularQualifier_Small);
3714 Handle(StepShape_AngularLocation) anAngLoc =
3715 Handle(StepShape_AngularLocation)::DownCast(aDimLocation);
3716 if (!anAngLoc.IsNull())
3718 //get qualifier for angular value
3719 aType = XCAFDimTolObjects_DimensionType_Location_Angular;
3720 if (anAngLoc->AngleSelection() == StepShape_Equal)
3721 aDimObj->SetAngularQualifier(XCAFDimTolObjects_AngularQualifier_Equal);
3722 else if (anAngLoc->AngleSelection() == StepShape_Large)
3723 aDimObj->SetAngularQualifier(XCAFDimTolObjects_AngularQualifier_Large);
3724 else if (anAngLoc->AngleSelection() == StepShape_Small)
3725 aDimObj->SetAngularQualifier(XCAFDimTolObjects_AngularQualifier_Small);
3728 if (aType == XCAFDimTolObjects_DimensionType_Location_None)
3730 Handle(StepRepr_ShapeAspect) aPSA;
3731 if (!aDimSize.IsNull())
3733 Handle(StepShape_DimensionalSizeWithPath) aDimSizeWithPath =
3734 Handle(StepShape_DimensionalSizeWithPath)::DownCast(aDimSize);
3735 if (!aDimSizeWithPath.IsNull())
3737 aType = XCAFDimTolObjects_DimensionType_Size_WithPath;
3738 aPSA = aDimSizeWithPath->Path();
3743 Handle(StepShape_DimensionalLocationWithPath) aDimLocWithPath =
3744 Handle(StepShape_DimensionalLocationWithPath)::DownCast(aDimLocation);
3745 if (!aDimLocWithPath.IsNull())
3747 aType = XCAFDimTolObjects_DimensionType_Location_WithPath;
3748 aPSA = aDimLocWithPath->Path();
3754 //for DimensionalLocationWithPath
3755 Handle(StepGeom_GeometricRepresentationItem) aGRI;
3756 Handle(StepAP242_GeometricItemSpecificUsage) aPGISU;
3757 Interface_EntityIterator anIterDSWP = aGraph.Sharings(aPSA);
3758 for (anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
3759 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
3761 if (aPGISU.IsNull()) return;
3762 if (aPGISU->NbIdentifiedItem() > 0) {
3763 aGRI = Handle(StepGeom_GeometricRepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(1));
3765 if (aGRI.IsNull()) return;
3766 Handle(StepRepr_RepresentationItem) aPRI;
3767 Interface_EntityIterator anIterGRI = aGraph.Sharings(aGRI);
3768 for (anIterGRI.Start(); anIterGRI.More() && aPRI.IsNull(); anIterGRI.Next()) {
3769 aPRI = Handle(StepRepr_RepresentationItem)::DownCast(anIterGRI.Value());
3771 Standard_Integer anIndex = FindShapeIndexForDGT(aPRI, theWS);
3774 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
3775 aSh = TopoDS::Edge(TransferBRep::ShapeResult(aBinder));
3777 if (aSh.IsNull()) return;
3778 aDimObj->SetPath(aSh);
3780 else if (!anAP.IsNull())
3782 if (anAP->Name()->String().IsEqual("orientation") && !anAP->Axis().IsNull())
3784 //for Oriented Dimensional Location
3785 Handle(TColStd_HArray1OfReal) aDirArr = anAP->RefDirection()->DirectionRatios();
3787 if (!aDirArr.IsNull() && aDirArr->Length() > 2)
3789 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, aDirArr->Lower() + 2);
3790 aDimObj->SetDirection(aDir);
3792 else if (aDirArr->Length() > 1)
3794 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower() + 1, 0);
3795 aDimObj->SetDirection(aDir);
3801 aDimObj->SetType(aType);
3804 if (!aDimObj.IsNull())
3807 Handle(XCAFDoc_Dimension) aDim;
3809 if (aDimL.FindAttribute(XCAFDoc_Dimension::GetID(), aDim))
3811 readAnnotation(aTR, theEnt, aDimObj);
3812 readConnectionPoints(aTR, theEnt, aDimObj);
3813 aDim->SetObject(aDimObj);
3818 //=======================================================================
3819 //function : getTolType
3821 //=======================================================================
3822 static Standard_Boolean getTolType(const Handle(Standard_Transient)& theEnt,
3823 XCAFDimTolObjects_GeomToleranceType& theType)
3825 if (theEnt.IsNull() || !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
3826 return Standard_False;
3827 theType = XCAFDimTolObjects_GeomToleranceType_None;
3828 if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRef)))
3830 Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) anE = Handle(StepDimTol_GeoTolAndGeoTolWthDatRef)::DownCast(theEnt);
3831 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3833 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
3835 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) anE =
3836 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(theEnt);
3837 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3839 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
3841 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) anE =
3842 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)::DownCast(theEnt);
3843 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3845 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
3847 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) anE =
3848 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(theEnt);
3849 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3851 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
3853 Handle(StepDimTol_GeoTolAndGeoTolWthMod) anE =
3854 Handle(StepDimTol_GeoTolAndGeoTolWthMod)::DownCast(theEnt);
3855 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3857 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)))
3859 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol) anE =
3860 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndUneqDisGeoTol)::DownCast(theEnt);
3861 theType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anE->GetToleranceType());
3863 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance)))
3865 theType = XCAFDimTolObjects_GeomToleranceType_Angularity;
3867 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance)))
3869 theType = XCAFDimTolObjects_GeomToleranceType_CircularRunout;
3871 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance)))
3873 theType = XCAFDimTolObjects_GeomToleranceType_CircularityOrRoundness;
3875 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance)))
3877 theType = XCAFDimTolObjects_GeomToleranceType_Coaxiality;
3879 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance)))
3881 theType = XCAFDimTolObjects_GeomToleranceType_Concentricity;
3883 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance)))
3885 theType = XCAFDimTolObjects_GeomToleranceType_Cylindricity;
3887 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance)))
3889 theType = XCAFDimTolObjects_GeomToleranceType_Flatness;
3891 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance)))
3893 theType = XCAFDimTolObjects_GeomToleranceType_Parallelism;
3895 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance)))
3897 theType = XCAFDimTolObjects_GeomToleranceType_Perpendicularity;
3899 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance)) ||
3900 theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)))
3902 theType = XCAFDimTolObjects_GeomToleranceType_Position;
3904 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance)))
3906 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfLine;
3908 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance)))
3910 theType = XCAFDimTolObjects_GeomToleranceType_ProfileOfSurface;
3912 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance)))
3914 theType = XCAFDimTolObjects_GeomToleranceType_Straightness;
3916 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance)))
3918 theType = XCAFDimTolObjects_GeomToleranceType_Symmetry;
3920 else if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance)))
3922 theType = XCAFDimTolObjects_GeomToleranceType_TotalRunout;
3924 return Standard_True;
3926 //=======================================================================
3927 //function : setGeomTolObjectToXCAF
3929 //=======================================================================
3930 static void setGeomTolObjectToXCAF(const Handle(Standard_Transient)& theEnt,
3931 const TDF_Label& theTolL,
3932 const Handle(TDocStd_Document)& theDoc,
3933 const Handle(XSControl_WorkSession)& theWS)
3935 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
3936 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
3937 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
3938 const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
3939 const Interface_Graph& aGraph = aTP->Graph();
3940 Handle(XCAFDoc_GeomTolerance) aGTol;
3941 if (!theTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTol))
3945 Handle(XCAFDimTolObjects_GeomToleranceObject) aTolObj = aGTol->GetObject();
3946 Handle(StepDimTol_GeometricTolerance) aTolEnt = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
3948 XCAFDimTolObjects_GeomToleranceType aType = XCAFDimTolObjects_GeomToleranceType_None;
3949 getTolType(theEnt, aType);
3950 aTolObj->SetType(aType);
3951 if (!aTolEnt->Magnitude().IsNull()) {
3953 Standard_Real aVal = aTolEnt->Magnitude()->ValueComponent();
3954 StepBasic_Unit anUnit = aTolEnt->Magnitude()->UnitComponent();
3955 if (anUnit.IsNull()) return;
3956 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) return;
3957 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3958 STEPConstruct_UnitContext anUnitCtx;
3959 anUnitCtx.ComputeFactors(NU);
3960 aVal = aVal * anUnitCtx.LengthFactor();
3961 aTolObj->SetValue(aVal);
3964 XCAFDimTolObjects_GeomToleranceTypeValue aTypeV = XCAFDimTolObjects_GeomToleranceTypeValue_None;
3965 Interface_EntityIterator anIter = aGraph.Sharings(aTolEnt);
3966 for (anIter.Start(); anIter.More(); anIter.Next()) {
3967 if (anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_ToleranceZone))) {
3968 Handle(StepDimTol_ToleranceZoneForm) aForm
3969 = Handle(StepDimTol_ToleranceZone)::DownCast(anIter.Value())->Form();
3970 STEPCAFControl_GDTProperty::GetTolValueType(aForm->Name(), aTypeV);
3971 Interface_EntityIterator anIt = aGraph.Sharings(anIter.Value());
3972 for (anIt.Start(); anIt.More(); anIt.Next()) {
3973 if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_ProjectedZoneDefinition))) {
3974 Handle(StepDimTol_ProjectedZoneDefinition) aPZone
3975 = Handle(StepDimTol_ProjectedZoneDefinition)::DownCast(anIt.Value());
3976 if (!aPZone->ProjectionLength().IsNull())
3978 Standard_Real aVal = aPZone->ProjectionLength()->ValueComponent();
3979 StepBasic_Unit anUnit = aPZone->ProjectionLength()->UnitComponent();
3980 if (anUnit.IsNull()) return;
3981 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) return;
3982 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
3983 STEPConstruct_UnitContext anUnitCtx;
3984 anUnitCtx.ComputeFactors(NU);
3985 aVal = aVal * anUnitCtx.LengthFactor();
3986 aTolObj->SetValueOfZoneModifier(aVal);
3987 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Projected);
3990 else if (anIt.Value()->IsKind(STANDARD_TYPE(StepDimTol_RunoutZoneDefinition)))
3992 Handle(StepDimTol_RunoutZoneDefinition) aRZone
3993 = Handle(StepDimTol_RunoutZoneDefinition)::DownCast(anIt.Value());
3994 if (!aRZone->Orientation().IsNull())
3996 Standard_Real aVal = aRZone->Orientation()->Angle()->ValueComponent();
3997 StepBasic_Unit anUnit = aRZone->Orientation()->Angle()->UnitComponent();
3998 if (anUnit.IsNull()) continue;
3999 if (!(anUnit.CaseNum(anUnit.Value()) == 1)) continue;
4000 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
4001 STEPConstruct_UnitContext anUnitCtx;
4002 anUnitCtx.ComputeFactors(NU);
4003 convertAngleValue(anUnitCtx, aVal);
4004 aTolObj->SetValueOfZoneModifier(aVal);
4005 aTolObj->SetZoneModifier(XCAFDimTolObjects_GeomToleranceZoneModif_Runout);
4009 aTolObj->SetTypeOfValue(aTypeV);
4012 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifiers;
4013 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithModifiers)))
4015 aModifiers = Handle(StepDimTol_GeometricToleranceWithModifiers)::DownCast(aTolEnt)->Modifiers();
4017 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)))
4019 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)
4020 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
4022 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMod)))
4024 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMod)
4025 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
4027 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
4029 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)
4030 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
4032 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
4034 aModifiers = Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)
4035 ::DownCast(aTolEnt)->GetGeometricToleranceWithModifiers()->Modifiers();
4037 if (!aModifiers.IsNull())
4039 for (Standard_Integer i = aModifiers->Lower(); i <= aModifiers->Upper(); i++)
4041 if (aModifiers->Value(i) == StepDimTol_GTMLeastMaterialRequirement)
4042 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_L);
4043 else if (aModifiers->Value(i) == StepDimTol_GTMMaximumMaterialRequirement)
4044 aTolObj->SetMaterialRequirementModifier(XCAFDimTolObjects_GeomToleranceMatReqModif_M);
4046 aTolObj->AddModifier((XCAFDimTolObjects_GeomToleranceModif)aModifiers->Value(i));
4049 Standard_Real aVal = 0;
4050 StepBasic_Unit anUnit;
4051 if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithMaximumTolerance)))
4053 Handle(StepDimTol_GeometricToleranceWithMaximumTolerance) aMax = Handle(StepDimTol_GeometricToleranceWithMaximumTolerance)::DownCast(aTolEnt);
4054 aVal = aMax->MaximumUpperTolerance()->ValueComponent();
4055 anUnit = aMax->MaximumUpperTolerance()->UnitComponent();
4057 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthMaxTol)))
4059 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aMax =
4060 Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol)::DownCast(aTolEnt);
4061 aVal = aMax->GetMaxTolerance()->ValueComponent();
4062 anUnit = aMax->GetMaxTolerance()->UnitComponent();
4064 else if (aTolEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)))
4066 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aMax =
4067 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)::DownCast(aTolEnt);
4068 aVal = aMax->GetMaxTolerance()->ValueComponent();
4069 anUnit = aMax->GetMaxTolerance()->UnitComponent();
4071 if (!anUnit.IsNull() && (anUnit.CaseNum(anUnit.Value()) == 1))
4073 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
4074 STEPConstruct_UnitContext anUnitCtx;
4075 anUnitCtx.ComputeFactors(NU);
4076 convertAngleValue(anUnitCtx, aVal);
4077 aTolObj->SetMaxValueModifier(aVal);
4080 readAnnotation(aTR, theEnt, aTolObj);
4081 aGTol->SetObject(aTolObj);
4084 //=======================================================================
4085 //function : ReadGDTs
4087 //=======================================================================
4089 Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession)& theWS,
4090 const Handle(TDocStd_Document)& theDoc)
4092 const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
4093 const Interface_Graph& aGraph = theWS->Graph();
4094 const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
4095 Handle(StepData_StepModel) aSM = Handle(StepData_StepModel)::DownCast(aModel);
4096 Interface_EntityIterator anI = aSM->Header();
4097 Handle(HeaderSection_FileSchema) aH;
4098 for (anI.Start(); anI.More() && aH.IsNull();anI.Next())
4099 aH = Handle(HeaderSection_FileSchema)::DownCast(anI.Value());
4100 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4101 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
4102 if (aDGTTool.IsNull()) return Standard_False;
4104 Standard_Integer nb = aModel->NbEntities();
4105 for (Standard_Integer i = 1; i <= nb; i++) {
4106 Handle(Standard_Transient) anEnt = aModel->Value(i);
4107 if (anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
4108 anEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
4109 anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
4110 TDF_Label aGDTL = createGDTObjectInXCAF(anEnt, theDoc, theWS);
4111 if (!aGDTL.IsNull()) {
4112 if (anEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
4113 setGeomTolObjectToXCAF(anEnt, aGDTL, theDoc, theWS);
4116 setDimObjectToXCAF(anEnt, aGDTL, theDoc, theWS);
4120 else if (anEnt->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)) ||
4121 anEnt->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
4123 // Protection against import presentation twice
4124 Handle(StepVisual_DraughtingCallout) aDC;
4125 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDC.IsNull(); anIter.Next()) {
4126 aDC = Handle(StepVisual_DraughtingCallout)::DownCast(anIter.Value());
4130 // Read presentations for PMIs without semantic data.
4131 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
4132 TDF_LabelSequence aShapesL;
4133 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDMIA.IsNull(); anIter.Next()) {
4134 aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(anIter.Value());
4136 if (!aDMIA.IsNull()) {
4137 // Check entity, skip all, attached to GDTs
4138 Handle(StepRepr_ShapeAspect) aDefinition = aDMIA->Definition().ShapeAspect();
4139 if (!aDefinition.IsNull()) {
4140 Standard_Boolean isConnectedToGDT = Standard_False;
4141 // Skip if definition is a datum
4142 if (aDefinition->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
4143 aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
4144 aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
4145 aDefinition->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
4146 isConnectedToGDT = Standard_True;
4148 // Skip if any GDT is applied to definition
4149 for (Interface_EntityIterator anIter = aGraph.Sharings(aDefinition); anIter.More() && !isConnectedToGDT; anIter.Next()) {
4150 if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
4151 anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
4152 anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
4153 isConnectedToGDT = Standard_True;
4156 Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
4157 if (!aSAR.IsNull()) {
4158 Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatedShapeAspect();
4159 if (!aSA.IsNull()) {
4160 if (aSA->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
4161 aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
4162 aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
4163 aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
4164 isConnectedToGDT = Standard_True;
4166 for (Interface_EntityIterator aDimIter = aGraph.Sharings(aSA); aDimIter.More() && !isConnectedToGDT; aDimIter.Next()) {
4167 if (aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
4168 aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
4169 aDimIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
4170 isConnectedToGDT = Standard_True;
4177 if (isConnectedToGDT)
4180 else if (aDMIA->Definition().PropertyDefinition().IsNull())
4184 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
4185 collectShapeAspect(aDefinition, theWS, aSAs);
4186 for (Standard_Integer aSAIt = 1; aSAIt <= aSAs.Length(); aSAIt++) {
4187 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
4188 for (Interface_EntityIterator anIter = aGraph.Sharings(aSAs.Value(aSAIt)); anIter.More() && aGISU.IsNull(); anIter.Next())
4189 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
4192 for (Standard_Integer anItemIt = 1; anItemIt <= aGISU->NbIdentifiedItem(); anItemIt++) {
4193 TDF_Label aLabel = getShapeLabel(aGISU->IdentifiedItemValue(anItemIt), theWS, XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()));
4194 if (!aLabel.IsNull())
4195 aShapesL.Append(aLabel);
4199 Standard_Boolean isCommonLabel = (aShapesL.Length() == 0);
4202 Standard_Real aFact = 1.0;
4203 if (!aDMIA.IsNull())
4205 XSAlgo::AlgoContainer()->PrepareForTransfer();
4206 STEPControl_ActorRead anActor;
4207 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4208 anActor.PrepareUnits(aDMIA->UsedRepresentation(), aTP);
4209 aFact = StepData_GlobalFactors::Intance().LengthFactor();
4213 TopoDS_Shape aPresentation;
4214 Handle(TCollection_HAsciiString) aPresentName;
4216 if (!readPMIPresentation(anEnt, aTR, aFact, aPresentation, aPresentName, aBox))
4219 Handle(StepVisual_AnnotationPlane) anAnPlane;
4220 for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && anAnPlane.IsNull(); anIter.Next())
4221 anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
4223 // Set object to XCAF
4224 TDF_Label aGDTL = aDGTTool->AddDimension();
4225 myGDTMap.Bind(anEnt, aGDTL);
4226 aDGTTool->Lock(aGDTL);
4227 Handle(XCAFDimTolObjects_DimensionObject) aDimObj = new XCAFDimTolObjects_DimensionObject();
4228 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
4229 TCollection_AsciiString aStr("DGT:");
4230 if (isCommonLabel) {
4231 aStr.AssignCat("Common_label");
4232 aDimObj->SetType(XCAFDimTolObjects_DimensionType_CommonLabel);
4235 aStr.AssignCat("Dimension");
4236 aDimObj->SetType(XCAFDimTolObjects_DimensionType_DimensionPresentation);
4238 TDataStd_Name::Set(aGDTL, aStr);
4239 TDF_LabelSequence anEmptySeq2;
4240 aDGTTool->SetDimension(aShapesL, anEmptySeq2, aGDTL);
4242 if (!anAnPlane.IsNull()) {
4243 if (readAnnotationPlane(anAnPlane, aPlaneAxes))
4244 aDimObj->SetPlane(aPlaneAxes);
4246 aDimObj->SetPresentation(aPresentation, aPresentName);
4247 aDim->SetObject(aDimObj);
4250 return Standard_True;
4254 //=======================================================================
4255 //function : FindSolidForPDS
4256 //purpose : auxiliary
4257 //=======================================================================
4259 static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS,
4260 const Interface_Graph &graph)
4262 Handle(StepShape_SolidModel) SM;
4263 Interface_EntityIterator subs = graph.Sharings(PDS);
4264 Handle(StepShape_ShapeRepresentation) SR;
4265 for (subs.Start(); subs.More() && SM.IsNull(); subs.Next()) {
4266 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
4267 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
4268 if (SDR.IsNull()) continue;
4269 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
4270 if (SR.IsNull()) continue;
4271 for (Standard_Integer i = 1; i <= SR->NbItems() && SM.IsNull(); i++) {
4272 SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i));
4275 Interface_EntityIterator subs1 = graph.Sharings(SR);
4276 for (subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) {
4277 Handle(StepRepr_RepresentationRelationship) RR =
4278 Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value());
4279 if (RR.IsNull()) continue;
4280 Handle(StepShape_ShapeRepresentation) SR2;
4281 if (RR->Rep1() == SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2());
4282 else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1());
4283 if (SR2.IsNull()) continue;
4284 for (Standard_Integer i2 = 1; i2 <= SR2->NbItems() && SM.IsNull(); i2++) {
4285 SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2));
4294 //=======================================================================
4295 //function : ReadMaterials
4297 //=======================================================================
4299 Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS,
4300 const Handle(TDocStd_Document)& Doc,
4301 const Handle(TColStd_HSequenceOfTransient)& SeqPDS) const
4303 const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
4304 const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
4305 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
4306 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool(Doc->Main());
4307 if (MatTool.IsNull()) return Standard_False;
4309 const Interface_Graph& graph = TP->Graph();
4310 for (Standard_Integer i = 1; i <= SeqPDS->Length(); i++) {
4311 Handle(StepRepr_ProductDefinitionShape) PDS =
4312 Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i));
4315 Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition();
4316 if (aProdDef.IsNull())
4318 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
4319 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString("");
4320 Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString("");
4321 Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString("");
4322 Standard_Real aDensity = 0;
4323 Interface_EntityIterator subs = graph.Sharings(aProdDef);
4324 for (subs.Start(); subs.More(); subs.Next()) {
4325 Handle(StepRepr_PropertyDefinition) PropD =
4326 Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value());
4327 if (PropD.IsNull()) continue;
4328 Interface_EntityIterator subs1 = graph.Sharings(PropD);
4329 for (subs1.Start(); subs1.More(); subs1.Next()) {
4330 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
4331 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value());
4332 if (PDR.IsNull()) continue;
4333 Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation();
4334 if (Repr.IsNull()) continue;
4335 Standard_Integer ir;
4336 for (ir = 1; ir <= Repr->NbItems(); ir++) {
4337 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir);
4338 if (RI.IsNull()) continue;
4339 if (RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
4340 // find name and description for material
4341 Handle(StepRepr_DescriptiveRepresentationItem) DRI =
4342 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI);
4343 aName = DRI->Name();
4345 aDescription = DRI->Description();
4347 aName = aDescription;
4349 if (RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) {
4350 // try to find density for material
4351 Handle(StepRepr_MeasureRepresentationItem) MRI =
4352 Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI);
4353 aDensity = MRI->Measure()->ValueComponent();
4354 aDensName = MRI->Name();
4355 aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name());
4356 StepBasic_Unit aUnit = MRI->Measure()->UnitComponent();
4357 if (!aUnit.IsNull()) {
4358 Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit();
4359 if (DU.IsNull()) continue;
4360 for (Standard_Integer idu = 1; idu <= DU->NbElements(); idu++) {
4361 Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu);
4362 Handle(StepBasic_NamedUnit) NU = DUE->Unit();
4365 if (NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ||
4366 NU->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)))
4368 STEPConstruct_UnitContext anUnitCtx;
4369 anUnitCtx.ComputeFactors(NU);
4370 aDensity = aDensity / (anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor());
4371 // transfer length value for Density from millimeter to santimeter
4372 // in order to result density has dimension gram/(sm*sm*sm)
4373 const Standard_Real aCascadeUnit = StepData_GlobalFactors::Intance().CascadeUnit();
4374 aDensity = aDensity*1000. / (aCascadeUnit * aCascadeUnit * aCascadeUnit);
4376 if (NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) {
4377 Standard_Real afact = 1.;
4378 if (GetMassConversionFactor(NU, afact))
4380 aDensity = aDensity*afact;
4390 if (aName.IsNull() || aName->Length() == 0)
4392 // find shape label amd create Material link
4394 Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS, graph);
4396 Standard_Integer index = TP->MapIndex(SM);
4398 Handle(Transfer_Binder) binder = TP->MapItem(index);
4399 if (!binder.IsNull())
4400 aSh = TransferBRep::ShapeResult(binder);
4403 if (aSh.IsNull()) continue;
4405 if (!STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True)) continue;
4406 MatTool->SetMaterial(shL, aName, aDescription, aDensity, aDensName, aDensValType);
4409 return Standard_True;
4412 //=======================================================================
4413 //function : collectViewShapes
4414 //purpose : collect all labels of representations in given representation
4415 //=======================================================================
4417 void collectViewShapes(const Handle(XSControl_WorkSession)& theWS,
4418 const Handle(TDocStd_Document)& theDoc,
4419 const Handle(StepRepr_Representation) theRepr,
4420 TDF_LabelSequence& theShapes)
4422 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
4423 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4424 const Interface_Graph& aGraph = aTP->Graph();
4425 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4426 Standard_Integer anIndex = aTP->MapIndex(theRepr);
4429 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
4430 aSh = TransferBRep::ShapeResult(aBinder);
4432 if (!aSh.IsNull()) {
4434 aSTool->FindShape(aSh, aShL);
4436 theShapes.Append(aShL);
4438 Interface_EntityIterator anIter = aGraph.Sharings(theRepr);
4439 for (; anIter.More(); anIter.Next()) {
4440 if (!anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_RepresentationRelationship)))
4442 Handle(StepRepr_RepresentationRelationship) aReprRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(anIter.Value());
4443 if (!aReprRelationship->Rep1().IsNull() && aReprRelationship->Rep1() != theRepr)
4444 collectViewShapes(theWS, theDoc, aReprRelationship->Rep1(), theShapes);
4448 //=======================================================================
4449 //function : buildClippingPlanes
4451 //=======================================================================
4452 Handle(TCollection_HAsciiString) buildClippingPlanes(const Handle(StepGeom_GeometricRepresentationItem)& theClippingCameraModel,
4453 TDF_LabelSequence& theClippingPlanes,
4454 const Handle(XCAFDoc_ClippingPlaneTool) theTool)
4456 Handle(TCollection_HAsciiString) anExpression = new TCollection_HAsciiString();
4457 NCollection_Sequence<Handle(StepGeom_GeometricRepresentationItem)> aPlanes;
4458 Handle(TCollection_HAsciiString) anOperation = new TCollection_HAsciiString("*");
4461 if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClipping))) {
4462 Handle(StepVisual_CameraModelD3MultiClipping) aCameraModel =
4463 Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(theClippingCameraModel);
4465 if (aCameraModel->ShapeClipping().IsNull())
4466 return anExpression;
4468 // Root of clipping planes tree
4469 if (aCameraModel->ShapeClipping()->Length() == 1) {
4470 Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModelUnion =
4471 aCameraModel->ShapeClipping()->Value(1).CameraModelD3MultiClippingUnion();
4472 if (!aCameraModelUnion.IsNull())
4473 return buildClippingPlanes(aCameraModelUnion, theClippingPlanes, theTool);
4475 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4476 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4479 else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingUnion))) {
4480 Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModel =
4481 Handle(StepVisual_CameraModelD3MultiClippingUnion)::DownCast(theClippingCameraModel);
4482 anOperation = new TCollection_HAsciiString("+");
4483 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4484 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4487 else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingIntersection))) {
4488 Handle(StepVisual_CameraModelD3MultiClippingIntersection) aCameraModel =
4489 Handle(StepVisual_CameraModelD3MultiClippingIntersection)::DownCast(theClippingCameraModel);
4490 for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
4491 aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
4495 anExpression->AssignCat("(");
4496 for (Standard_Integer i = 1; i <= aPlanes.Length(); i++) {
4497 Handle(StepGeom_Plane) aPlaneEnt = Handle(StepGeom_Plane)::DownCast(aPlanes.Value(i));
4498 if (!aPlaneEnt.IsNull()) {
4499 Handle(Geom_Plane) aPlane = StepToGeom::MakePlane(aPlaneEnt);
4500 if (!aPlane.IsNull()) {
4501 TDF_Label aPlaneL = theTool->AddClippingPlane(aPlane->Pln(), aPlaneEnt->Name());
4502 theClippingPlanes.Append(aPlaneL);
4503 TCollection_AsciiString anEntry;
4504 TDF_Tool::Entry(aPlaneL, anEntry);
4505 anExpression->AssignCat(new TCollection_HAsciiString(anEntry));
4509 anExpression->AssignCat(buildClippingPlanes(aPlanes.Value(i), theClippingPlanes, theTool));
4511 anExpression->AssignCat(anOperation);
4513 // Insert brace instead of operation after last operand.
4514 anExpression->SetValue(anExpression->Length(), ')');
4515 return anExpression;
4519 //=======================================================================
4520 //function : ReadViews
4522 //=======================================================================
4523 Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSession)& theWS, const Handle(TDocStd_Document)& theDoc) const
4525 const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
4526 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
4527 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
4528 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(theDoc->Main());
4529 if (aDGTTool.IsNull()) return Standard_False;
4531 Standard_Integer nb = aModel->NbEntities();
4532 for (Standard_Integer i = 1; i <= nb; i++) {
4533 Handle(Standard_Transient) anEnt = aModel->Value(i);
4534 if (!anEnt->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3)))
4536 Handle(XCAFView_Object) anObj = new XCAFView_Object();
4537 // Import attributes of view
4538 Handle(StepVisual_CameraModelD3) aCameraModel = Handle(StepVisual_CameraModelD3)::DownCast(anEnt);
4540 const Handle(XSControl_TransferReader)& aTR = theWS->TransferReader();
4541 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
4542 const Interface_Graph& aGraph = aTP->Graph();
4543 // find the proper DraughtingModel
4544 Interface_EntityIterator subs = aGraph.Sharings(aCameraModel);
4545 Handle(StepVisual_DraughtingModel) aDModel;
4546 for (subs.Start(); subs.More() && aDModel.IsNull(); subs.Next())
4548 if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingModel)))
4552 aDModel = Handle(StepVisual_DraughtingModel)::DownCast(subs.Value());
4554 if (!aDModel.IsNull())
4556 XSAlgo::AlgoContainer()->PrepareForTransfer();
4557 STEPControl_ActorRead anActor;
4558 anActor.PrepareUnits(aDModel, aTP);
4561 anObj->SetName(aCameraModel->Name());
4562 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aCameraModel->ViewReferenceSystem());
4563 anObj->SetViewDirection(anAxis->Direction());
4564 anObj->SetUpDirection(anAxis->Direction() ^ anAxis->XDirection());
4565 Handle(StepVisual_ViewVolume) aViewVolume = aCameraModel->PerspectiveOfVolume();
4566 XCAFView_ProjectionType aType = XCAFView_ProjectionType_NoCamera;
4567 if (aViewVolume->ProjectionType() == StepVisual_copCentral)
4568 aType = XCAFView_ProjectionType_Central;
4569 else if (aViewVolume->ProjectionType() == StepVisual_copParallel)
4570 aType = XCAFView_ProjectionType_Parallel;
4571 anObj->SetType(aType);
4572 Handle(Geom_CartesianPoint) aPoint = StepToGeom::MakeCartesianPoint(aViewVolume->ProjectionPoint());
4573 anObj->SetProjectionPoint(aPoint->Pnt());
4574 anObj->SetZoomFactor(aViewVolume->ViewPlaneDistance());
4575 anObj->SetWindowHorizontalSize(aViewVolume->ViewWindow()->SizeInX());
4576 anObj->SetWindowVerticalSize(aViewVolume->ViewWindow()->SizeInY());
4577 if (aViewVolume->FrontPlaneClipping())
4578 anObj->SetFrontPlaneDistance(aViewVolume->FrontPlaneDistance());
4579 if (aViewVolume->BackPlaneClipping())
4580 anObj->SetBackPlaneDistance(aViewVolume->BackPlaneDistance());
4581 anObj->SetViewVolumeSidesClipping(aViewVolume->ViewVolumeSidesClipping());
4583 Handle(StepVisual_CameraModelD3MultiClipping) aClippingCameraModel =
4584 Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(aCameraModel);
4585 TDF_LabelSequence aClippingPlanes;
4586 if (!aClippingCameraModel.IsNull()) {
4587 Handle(TCollection_HAsciiString) aClippingExpression;
4588 Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(theDoc->Main());
4589 aClippingExpression = buildClippingPlanes(aClippingCameraModel, aClippingPlanes, aClippingPlaneTool);
4590 anObj->SetClippingExpression(aClippingExpression);
4593 // Collect shapes and GDTs
4594 if (aDModel.IsNull())
4595 return Standard_False;
4596 TDF_LabelSequence aShapes, aGDTs;
4597 Interface_EntityIterator anIter = aGraph.Shareds(aDModel);
4598 for (; anIter.More(); anIter.Next()) {
4599 if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
4600 Handle(StepRepr_MappedItem) anItem = Handle(StepRepr_MappedItem)::DownCast(anIter.Value());
4601 if (Handle(StepRepr_Representation) aRepr = anItem->MappingSource()->MappedRepresentation())
4603 collectViewShapes(theWS, theDoc, aRepr, aShapes);
4606 else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)) ||
4607 anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout))) {
4608 Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
4609 for (; aDMIAIter.More(); aDMIAIter.Next()) {
4610 if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
4612 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
4613 Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
4615 Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
4617 isFind = myGDTMap.Find(anIter.Value(), aGDTL);
4620 aGDTs.Append(aGDTL);
4623 else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationPlane))) {
4624 Handle(StepVisual_AnnotationPlane) aPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
4625 for (Standard_Integer j = 1; j <= aPlane->NbElements(); j++) {
4626 Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
4627 for (; aDMIAIter.More(); aDMIAIter.Next()) {
4628 if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
4630 Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
4631 Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
4633 Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
4635 aGDTs.Append(aGDTL);
4640 TDF_Label aViewL = aViewTool->AddView();
4641 Handle(XCAFDoc_View) aView = XCAFDoc_View::Set(aViewL);
4642 aView->SetObject(anObj);
4643 aViewTool->SetView(aShapes, aGDTs, aClippingPlanes, aViewL);
4644 aViewTool->Lock(aViewL);
4646 return Standard_True;
4649 //=======================================================================
4650 //function : SettleShapeData
4652 //=======================================================================
4654 TDF_Label STEPCAFControl_Reader::SettleShapeData(const Handle(StepRepr_RepresentationItem)& theItem,
4655 const TDF_Label& theLab,
4656 const Handle(XCAFDoc_ShapeTool)& theShapeTool,
4657 const Handle(Transfer_TransientProcess)& TP) const
4659 TDF_Label aResult = theLab;
4660 if (theItem.IsNull())
4663 Handle(TCollection_HAsciiString) hName = theItem->Name();
4664 if (hName.IsNull() || hName->IsEmpty())
4667 Handle(Transfer_Binder) aBinder = TP->Find(theItem);
4668 if (aBinder.IsNull())
4671 TopoDS_Shape aShape = TransferBRep::ShapeResult(aBinder);
4672 if (aShape.IsNull())
4675 // Allocate sub-Label
4676 aResult = theShapeTool->AddSubShape(theLab, aShape);
4677 if (aResult.IsNull())
4680 TCollection_AsciiString aName = hName->String();
4681 TDataStd_Name::Set(aResult, aName);
4682 theShapeTool->SetShape(aResult, aShape);
4687 //=======================================================================
4688 //function : collectRepresentationItems
4689 //purpose : recursive collection of representation items for given representation
4690 // with all representations, related to it.
4691 //=======================================================================
4693 void collectRepresentationItems(const Interface_Graph& theGraph,
4694 const Handle(StepShape_ShapeRepresentation)& theRepresentation,
4695 NCollection_Sequence<Handle(StepRepr_RepresentationItem)>& theItems)
4697 for (StepRepr_HArray1OfRepresentationItem::Iterator anIter(theRepresentation->Items()->Array1());
4698 anIter.More(); anIter.Next())
4700 const Handle(StepRepr_RepresentationItem)& anReprItem = anIter.Value();
4701 if (anReprItem.IsNull())
4705 theItems.Append(anReprItem);
4708 Interface_EntityIterator entIt = theGraph.TypedSharings(theRepresentation, STANDARD_TYPE(StepRepr_RepresentationRelationship));
4709 for (entIt.Start(); entIt.More(); entIt.Next())
4711 Handle(StepRepr_RepresentationRelationship) aRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(entIt.Value());
4712 if (aRelationship->Rep1() == theRepresentation)
4714 Handle(StepShape_ShapeRepresentation)
4715 aRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aRelationship->Rep2());
4716 if (!aRepr.IsNull())
4717 collectRepresentationItems(theGraph, aRepr, theItems);
4722 //=======================================================================
4723 //function : ExpandSubShapes
4725 //=======================================================================
4727 void STEPCAFControl_Reader::ExpandSubShapes(const Handle(XCAFDoc_ShapeTool)& ShapeTool,
4728 const STEPCAFControl_DataMapOfShapePD& ShapePDMap) const
4730 const Handle(Transfer_TransientProcess)& TP = Reader().WS()->TransferReader()->TransientProcess();
4731 NCollection_DataMap<TopoDS_Shape, Handle(TCollection_HAsciiString)> ShapeNameMap;
4732 TColStd_MapOfTransient aRepItems;
4734 // Read translation control variables
4735 Standard_Boolean doReadSNames = (Interface_Static::IVal("read.stepcaf.subshapes.name") > 0);
4740 const Interface_Graph& Graph = Reader().WS()->Graph();
4742 for (STEPCAFControl_DataMapIteratorOfDataMapOfShapePD it(ShapePDMap); it.More(); it.Next())
4744 const TopoDS_Shape& aRootShape = it.Key();
4745 const Handle(StepBasic_ProductDefinition)& aPDef = it.Value();
4749 // Find SDR by Product
4750 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
4751 Interface_EntityIterator entIt = Graph.TypedSharings(aPDef, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation));
4752 for (entIt.Start(); entIt.More(); entIt.Next())
4754 const Handle(Standard_Transient)& aReferer = entIt.Value();
4755 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aReferer);
4763 // Access shape representation
4764 Handle(StepShape_ShapeRepresentation)
4765 aShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast(aSDR->UsedRepresentation());
4767 if (aShapeRepr.IsNull())
4770 // Access representation items
4771 NCollection_Sequence<Handle(StepRepr_RepresentationItem)> aReprItems;
4772 collectRepresentationItems(Graph, aShapeRepr, aReprItems);
4774 if (aReprItems.Length() == 0)
4777 if (!myMap.IsBound(aRootShape))
4780 TDF_Label aRootLab = myMap.Find(aRootShape);
4781 // Do not add subshapes to assembly,
4782 // they will be processed with corresponding Shape_Product_Definition of necessary part.
4783 if (ShapeTool->IsAssembly(aRootLab))
4786 StepRepr_SequenceOfRepresentationItem aMSBSeq;
4787 StepRepr_SequenceOfRepresentationItem aSBSMSeq;
4789 // Iterate over the top level representation items collecting the
4790 // topological containers to expand
4791 for (Standard_Integer i = 1; i <= aReprItems.Length(); ++i)
4793 Handle(StepRepr_RepresentationItem) aTRepr = aReprItems.Value(i);
4794 if (aTRepr->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep)))
4795 aMSBSeq.Append(aTRepr);
4796 else if (aTRepr->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel)))
4797 aSBSMSeq.Append(aTRepr);
4800 // Insert intermediate OCAF Labels for SOLIDs in case there are more
4801 // than one Manifold Solid BRep in the Shape Representation
4802 Standard_Boolean doInsertSolidLab = (aMSBSeq.Length() > 1);
4804 // Expand Manifold Solid BReps
4805 for (Standard_Integer i = 1; i <= aMSBSeq.Length(); ++i)
4807 // Put additional Label for SOLID
4808 if (doInsertSolidLab)
4809 SettleShapeData(aMSBSeq.Value(i), aRootLab, ShapeTool, TP);
4811 ExpandManifoldSolidBrep(aRootLab, aMSBSeq.Value(i), TP, ShapeTool);
4814 // Expand Shell-Based Surface Models
4815 for (Standard_Integer i = 1; i <= aSBSMSeq.Length(); ++i)
4816 ExpandSBSM(aRootLab, aSBSMSeq.Value(i), TP, ShapeTool);
4820 //=======================================================================
4821 //function : ExpandManifoldSolidBrep
4823 //=======================================================================
4825 void STEPCAFControl_Reader::ExpandManifoldSolidBrep(TDF_Label& ShapeLab,
4826 const Handle(StepRepr_RepresentationItem)& Repr,
4827 const Handle(Transfer_TransientProcess)& TP,
4828 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4830 // Access outer shell
4831 Handle(StepShape_ManifoldSolidBrep) aMSB = Handle(StepShape_ManifoldSolidBrep)::DownCast(Repr);
4832 Handle(StepShape_ConnectedFaceSet) aShell = aMSB->Outer();
4834 // Expand shell contents to CAF tree
4835 ExpandShell(aShell, ShapeLab, TP, ShapeTool);
4838 //=======================================================================
4839 //function : ExpandSBSM
4841 //=======================================================================
4843 void STEPCAFControl_Reader::ExpandSBSM(TDF_Label& ShapeLab,
4844 const Handle(StepRepr_RepresentationItem)& Repr,
4845 const Handle(Transfer_TransientProcess)& TP,
4846 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4848 Handle(StepShape_ShellBasedSurfaceModel) aSBSM = Handle(StepShape_ShellBasedSurfaceModel)::DownCast(Repr);
4850 // Access boundary shells
4851 Handle(StepShape_HArray1OfShell) aShells = aSBSM->SbsmBoundary();
4852 for (Standard_Integer s = aShells->Lower(); s <= aShells->Upper(); ++s)
4854 const StepShape_Shell& aShell = aShells->Value(s);
4855 Handle(StepShape_ConnectedFaceSet) aCFS;
4856 Handle(StepShape_OpenShell) anOpenShell = aShell.OpenShell();
4857 Handle(StepShape_ClosedShell) aClosedShell = aShell.ClosedShell();
4859 if (!anOpenShell.IsNull())
4862 aCFS = aClosedShell;
4864 ExpandShell(aCFS, ShapeLab, TP, ShapeTool);
4868 //=======================================================================
4869 //function : ExpandShell
4871 //=======================================================================
4873 void STEPCAFControl_Reader::ExpandShell(const Handle(StepShape_ConnectedFaceSet)& Shell,
4875 const Handle(Transfer_TransientProcess)& TP,
4876 const Handle(XCAFDoc_ShapeTool)& ShapeTool) const
4879 SettleShapeData(Shell, RootLab, ShapeTool, TP);
4882 Handle(StepShape_HArray1OfFace) aFaces = Shell->CfsFaces();
4883 for (Standard_Integer f = aFaces->Lower(); f <= aFaces->Upper(); ++f)
4885 const Handle(StepShape_Face)& aFace = aFaces->Value(f);
4890 SettleShapeData(aFace, RootLab, ShapeTool, TP);
4892 // Access face bounds
4893 Handle(StepShape_HArray1OfFaceBound) aWires = aFace->Bounds();
4894 if (aWires.IsNull())
4896 for (Standard_Integer w = aWires->Lower(); w <= aWires->Upper(); ++w)
4898 const Handle(StepShape_Loop)& aWire = aWires->Value(w)->Bound();
4901 SettleShapeData(aWire, RootLab, ShapeTool, TP);
4903 // Access wire edges
4904 // Currently only EDGE LOOPs are considered (!)
4905 if (!aWire->IsInstance(STANDARD_TYPE(StepShape_EdgeLoop)))
4909 Handle(StepShape_EdgeLoop) anEdgeLoop = Handle(StepShape_EdgeLoop)::DownCast(aWire);
4910 Handle(StepShape_HArray1OfOrientedEdge) anEdges = anEdgeLoop->EdgeList();
4911 for (Standard_Integer e = anEdges->Lower(); e <= anEdges->Upper(); ++e)
4913 Handle(StepShape_OrientedEdge) anOrientedEdge = anEdges->Value(e);
4914 if (anOrientedEdge.IsNull())
4916 Handle(StepShape_Edge) anEdge = anOrientedEdge->EdgeElement();
4917 if (anEdge.IsNull())
4921 SettleShapeData(anEdge, RootLab, ShapeTool, TP);
4924 Handle(StepShape_Vertex) aV1 = anEdge->EdgeStart();
4925 Handle(StepShape_Vertex) aV2 = anEdge->EdgeEnd();
4928 SettleShapeData(aV1, RootLab, ShapeTool, TP);
4929 SettleShapeData(aV2, RootLab, ShapeTool, TP);
4935 //=======================================================================
4936 //function : SetColorMode
4938 //=======================================================================
4940 void STEPCAFControl_Reader::SetColorMode(const Standard_Boolean colormode)
4942 myColorMode = colormode;
4945 //=======================================================================
4946 //function : GetColorMode
4948 //=======================================================================
4950 Standard_Boolean STEPCAFControl_Reader::GetColorMode() const
4955 //=======================================================================
4956 //function : SetNameMode
4958 //=======================================================================
4960 void STEPCAFControl_Reader::SetNameMode(const Standard_Boolean namemode)
4962 myNameMode = namemode;
4965 //=======================================================================
4966 //function : GetNameMode
4968 //=======================================================================
4970 Standard_Boolean STEPCAFControl_Reader::GetNameMode() const
4975 //=======================================================================
4976 //function : SetLayerMode
4978 //=======================================================================
4980 void STEPCAFControl_Reader::SetLayerMode(const Standard_Boolean layermode)
4982 myLayerMode = layermode;
4985 //=======================================================================
4986 //function : GetLayerMode
4988 //=======================================================================
4990 Standard_Boolean STEPCAFControl_Reader::GetLayerMode() const
4995 //=======================================================================
4996 //function : SetPropsMode
4998 //=======================================================================
5000 void STEPCAFControl_Reader::SetPropsMode(const Standard_Boolean propsmode)
5002 myPropsMode = propsmode;
5005 //=======================================================================
5006 //function : GetPropsMode
5008 //=======================================================================
5010 Standard_Boolean STEPCAFControl_Reader::GetPropsMode() const
5015 //=======================================================================
5016 //function : SetSHUOMode
5018 //=======================================================================
5020 void STEPCAFControl_Reader::SetSHUOMode(const Standard_Boolean mode)
5025 //=======================================================================
5026 //function : GetSHUOMode
5028 //=======================================================================
5030 Standard_Boolean STEPCAFControl_Reader::GetSHUOMode() const
5035 //=======================================================================
5036 //function : SetGDTMode
5038 //=======================================================================
5040 void STEPCAFControl_Reader::SetGDTMode(const Standard_Boolean gdtmode)
5042 myGDTMode = gdtmode;
5045 //=======================================================================
5046 //function : GetGDTMode
5048 //=======================================================================
5050 Standard_Boolean STEPCAFControl_Reader::GetGDTMode() const
5056 //=======================================================================
5057 //function : SetMatMode
5059 //=======================================================================
5061 void STEPCAFControl_Reader::SetMatMode(const Standard_Boolean matmode)
5063 myMatMode = matmode;
5066 //=======================================================================
5067 //function : GetMatMode
5069 //=======================================================================
5071 Standard_Boolean STEPCAFControl_Reader::GetMatMode() const
5076 //=======================================================================
5077 //function : SetViewMode
5079 //=======================================================================
5081 void STEPCAFControl_Reader::SetViewMode(const Standard_Boolean viewmode)
5083 myViewMode = viewmode;
5086 //=======================================================================
5087 //function : GetViewMode
5089 //=======================================================================
5091 Standard_Boolean STEPCAFControl_Reader::GetViewMode() const