0028449: Data Exchange - Wrong orientation of Annotation Plane in GD&T
[occt.git] / src / STEPCAFControl / STEPCAFControl_Reader.cxx
index 5bbf3de..70d3988 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <BRep_Builder.hxx>
 #include <Geom_Axis2Placement.hxx>
+#include <Geom_CartesianPoint.hxx>
+#include <Geom_Plane.hxx>
 #include <Interface_EntityIterator.hxx>
 #include <Interface_InterfaceModel.hxx>
 #include <StepData_StepModel.hxx>
 #include <StepRepr_DerivedShapeAspect.hxx>
 #include <StepRepr_DescriptiveRepresentationItem.hxx>
 #include <StepRepr_HArray1OfRepresentationItem.hxx>
+#include <StepRepr_MappedItem.hxx>
 #include <StepRepr_MeasureRepresentationItem.hxx>
 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
 #include <StepRepr_ProductDefinitionShape.hxx>
 #include <StepRepr_Representation.hxx>
 #include <StepRepr_RepresentationItem.hxx>
 #include <StepRepr_HArray1OfRepresentationItem.hxx>
+#include <StepRepr_RepresentationMap.hxx>
 #include <StepRepr_RepresentationRelationship.hxx>
 #include <StepRepr_RepresentedDefinition.hxx>
 #include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
 #include <StepShape_Vertex.hxx>
 #include <StepToGeom.hxx>
 #include <StepVisual_AnnotationCurveOccurrence.hxx>
+#include <StepVisual_AnnotationFillArea.hxx>
 #include <StepVisual_AnnotationPlane.hxx>
+#include <StepVisual_CameraModelD3.hxx>
+#include <StepVisual_CameraModelD3MultiClipping.hxx>
+#include <StepVisual_CameraModelD3MultiClippingIntersection.hxx>
+#include <StepVisual_CameraModelD3MultiClippingUnion.hxx>
+#include <StepVisual_CoordinatesList.hxx>
+#include <StepVisual_HArray1OfCameraModelD3MultiClippingInterectionSelect.hxx>
+#include <StepVisual_HArray1OfCameraModelD3MultiClippingUnionSelect.hxx>
 #include <StepVisual_DraughtingCallout.hxx>
 #include <StepVisual_DraughtingCalloutElement.hxx>
 #include <StepVisual_DraughtingModel.hxx>
 #include <StepVisual_PresentationStyleByContext.hxx>
 #include <StepVisual_StyleContextSelect.hxx>
 #include <StepVisual_StyledItem.hxx>
+#include <StepVisual_ViewVolume.hxx>
 #include <StepShape_TypeQualifier.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_HAsciiString.hxx>
 #include <XCAFDoc.hxx>
 #include <XCAFDoc_Area.hxx>
 #include <XCAFDoc_Centroid.hxx>
+#include <XCAFDoc_ClippingPlaneTool.hxx>
 #include <XCAFDoc_ColorTool.hxx>
 #include <XCAFDoc_DataMapOfShapeLabel.hxx>
 #include <XCAFDoc_DimTolTool.hxx>
 #include <XCAFDoc_LayerTool.hxx>
 #include <XCAFDoc_MaterialTool.hxx>
 #include <XCAFDoc_ShapeTool.hxx>
+#include <XCAFDoc_View.hxx>
+#include <XCAFDoc_ViewTool.hxx>
 #include <XCAFDoc_Volume.hxx>
 #include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
 #include <XCAFDimTolObjects_GeomToleranceType.hxx>
 #include <XCAFDimTolObjects_DimensionObject.hxx>
 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
 #include <XCAFDimTolObjects_DatumObject.hxx>
+#include <XCAFView_Object.hxx>
 #include <XSControl_TransferReader.hxx>
 #include <XSControl_WorkSession.hxx>
 #include <StepAP242_DraughtingModelItemAssociation.hxx>
@@ -320,7 +337,8 @@ STEPCAFControl_Reader::STEPCAFControl_Reader ():
        myPropsMode( Standard_True ),
           mySHUOMode ( Standard_False ),
        myGDTMode  ( Standard_True ),
-       myMatMode  ( Standard_True )
+       myMatMode(Standard_True),
+       myViewMode(Standard_True)
 {
   STEPCAFControl_Controller::Init();
 }
@@ -339,7 +357,8 @@ STEPCAFControl_Reader::STEPCAFControl_Reader (const Handle(XSControl_WorkSession
        myPropsMode( Standard_True ),
           mySHUOMode ( Standard_False ),
        myGDTMode  ( Standard_True ),
-       myMatMode  ( Standard_True )
+       myMatMode(Standard_True),
+       myViewMode(Standard_True)
 {
   STEPCAFControl_Controller::Init();
   Init ( WS, scratch );
@@ -684,10 +703,17 @@ Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
   if(GetMatMode())
     ReadMaterials(reader.WS(),doc,SeqPDS);
 
+  // read View entities from STEP model
+  if (GetViewMode())
+    ReadViews(reader.WS(), doc);
+
   // Expand resulting CAF structure for sub-shapes (optionally with their
   // names) if requested
   ExpandSubShapes(STool, map, ShapePDMap);
 
+  // Update assembly compounds
+  STool->UpdateAssemblies();
+
   return Standard_True;
 }
 
@@ -1396,6 +1422,8 @@ Standard_Boolean STEPCAFControl_Reader::ReadLayers (const Handle(XSControl_WorkS
     if ( ! enti->IsKind ( tSVPLA ) ) continue;
     Handle(StepVisual_PresentationLayerAssignment) SVPLA = 
       Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
+    if (SVPLA->AssignedItems().IsNull())
+      continue;
     
     Handle(TCollection_HAsciiString) descr = SVPLA->Description();
     Handle(TCollection_HAsciiString) hName = SVPLA->Name();
@@ -1767,6 +1795,7 @@ static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
   }
   return Standard_True;
 }
+
 //=======================================================================
 //function : readPMIPresentation
 //purpose  : read polyline or tessellated presentation for 
@@ -1782,25 +1811,26 @@ Standard_Boolean readPMIPresentation(const Handle(Standard_Transient)& thePresen
   if (thePresentEntity.IsNull())
     return Standard_False;
   Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
-  Handle(StepVisual_AnnotationCurveOccurrence) anACO;
+  Handle(StepVisual_AnnotationOccurrence) anAO;
   NCollection_Vector<Handle(StepVisual_StyledItem)> anAnnotations;
-  if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_AnnotationCurveOccurrence)))
+  if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
   {
-    anACO = Handle(StepVisual_AnnotationCurveOccurrence)::DownCast(thePresentEntity);
-    thePresentName = anACO->Name();
-    if (!anACO.IsNull())
-      anAnnotations.Append(anACO);
+    anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(thePresentEntity);
+    if (!anAO.IsNull()) {
+      thePresentName = anAO->Name();
+      anAnnotations.Append(anAO);
+    }
   }
   else if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)))
   {
     Handle(StepVisual_DraughtingCallout) aDCallout =
       Handle(StepVisual_DraughtingCallout)::DownCast(thePresentEntity);
     thePresentName = aDCallout->Name();
-    for (Standard_Integer i = 1; i <= aDCallout->NbContents() && anACO.IsNull(); i++) {
-      anACO = aDCallout->ContentsValue(i).AnnotationCurveOccurrence();
-      if (!anACO.IsNull())
+    for (Standard_Integer i = 1; i <= aDCallout->NbContents() && anAO.IsNull(); i++) {
+      anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(aDCallout->ContentsValue(i).Value());
+      if (!anAO.IsNull())
       {
-        anAnnotations.Append(anACO);
+        anAnnotations.Append(anAO);
         continue;
       }
       Handle(StepVisual_TessellatedAnnotationOccurrence) aTesselation =
@@ -1824,11 +1854,11 @@ Standard_Boolean readPMIPresentation(const Handle(Standard_Transient)& thePresen
   for (; i < anAnnotations.Length(); i++)
   {
     Handle(StepVisual_StyledItem) anItem = anAnnotations(i);
-    anACO = Handle(StepVisual_AnnotationCurveOccurrence)::DownCast(anItem);
+    anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(anItem);
     TopoDS_Shape anAnnotationShape;
-    if (!anACO.IsNull())
+    if (!anAO.IsNull())
     {
-      Handle(StepRepr_RepresentationItem) aCurveItem = anACO->Item();
+      Handle(StepRepr_RepresentationItem) aCurveItem = anAO->Item();
       anAnnotationShape = STEPConstruct::FindShape(aTP, aCurveItem);
       if (anAnnotationShape.IsNull())
       {
@@ -1918,7 +1948,6 @@ Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) th
 {
   if (theAnnotationPlane.IsNull())
     return Standard_False;
-  gp_Ax2 aPlaneAxes;
   Handle(StepRepr_RepresentationItem) aPlaneItem = theAnnotationPlane->Item();
   if (aPlaneItem.IsNull())
     return Standard_False;
@@ -1935,23 +1964,11 @@ Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) th
   if (aA2P3D.IsNull())
     return Standard_False;
 
-  // build gp_Ax2 from axes
-  Handle(StepGeom_Direction) anAxis = aA2P3D->Axis(),
-    aRefDir = aA2P3D->RefDirection();
-  if (anAxis.IsNull() || aRefDir.IsNull())
-    return Standard_False;
-
-  Handle(TColStd_HArray1OfReal) aCoords;
-  aCoords = anAxis->DirectionRatios();
-  gp_Dir aXDir(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3));
-  aCoords = aRefDir->DirectionRatios();
-  gp_Dir aYDir(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3));
-  aPlaneAxes.SetDirection(aXDir.Crossed(aYDir));
-  aPlaneAxes.SetYDirection(aYDir);
-  //set location of the annotation plane
-  Handle(TColStd_HArray1OfReal) aLocCoords;
-  Handle(StepGeom_CartesianPoint) aLoc = aA2P3D->Location();
-  gp_Pnt aLocPos(aLoc->CoordinatesValue(1) * theFact, aLoc->CoordinatesValue(2) * theFact, aLoc->CoordinatesValue(3) * theFact);
+  gp_Ax2 aPlaneAxes;
+  Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aA2P3D);
+  aPlaneAxes = anAxis->Ax2();
+  gp_XYZ aLocPos = aPlaneAxes.Location().XYZ();
+  aLocPos *= theFact;
   aPlaneAxes.SetLocation(aLocPos);
   thePlane = aPlaneAxes;
   return Standard_True;
@@ -2338,14 +2355,14 @@ static TDF_Label getShapeLabel(const Handle(StepRepr_RepresentationItem)& theIte
 //purpose  : 
 //=======================================================================
 
-static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
-                                       const TDF_Label theGDTL,
-                                       const Standard_Integer thePositionCounter,
-                                       const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
-                                       const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
-                                       const Standard_Real theModifValue,
-                                       const Handle(TDocStd_Document)& theDoc,
-                                       const Handle(XSControl_WorkSession)& theWS)
+Standard_Boolean STEPCAFControl_Reader::setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
+                                                       const TDF_Label theGDTL,
+                                                       const Standard_Integer thePositionCounter,
+                                                       const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
+                                                       const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
+                                                       const Standard_Real theModifValue,
+                                                       const Handle(TDocStd_Document)& theDoc,
+                                                       const Handle(XSControl_WorkSession)& theWS)
 {
   Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
   Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
@@ -2384,8 +2401,8 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
       Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
       if (aGISU.IsNull())
         continue;
-      for (Standard_Integer i = 1; i <= aGISU->NbIdentifiedItem(); i++) {
-        TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(i), theWS, aSTool);
+      for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
+        TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
         if (!aShapeL.IsNull())
           aShapeLabels.Append(aShapeL);
       }
@@ -2398,19 +2415,19 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
     Handle(StepDimTol_PlacedDatumTargetFeature) aDT = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSAs.Value(i));
     if (aDT.IsNull())
       continue;
-    Handle(XCAFDimTolObjects_DatumObject) aDatObj = new XCAFDimTolObjects_DatumObject();
+    Handle(XCAFDimTolObjects_DatumObject) aDatTargetObj = new XCAFDimTolObjects_DatumObject();
     XCAFDimTolObjects_DatumTargetType aType;
     if (!STEPCAFControl_GDTProperty::GetDatumTargetType(aDT->Description(), aType))
       continue;
-    aDatObj->SetDatumTargetType(aType);
+    aDatTargetObj->SetDatumTargetType(aType);
     Standard_Boolean isValidDT = Standard_False;
 
     // Feature for datum target
     TDF_LabelSequence aDTShapeLabels;
-    Interface_EntityIterator anIter = aGraph.Sharings(aDT);
+    Interface_EntityIterator aDTIter = aGraph.Sharings(aDT);
     Handle(StepRepr_FeatureForDatumTargetRelationship) aRelationship;
-    for (; anIter.More() && aRelationship.IsNull(); anIter.Next()) {
-      aRelationship = Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(anIter.Value());
+    for (; aDTIter.More() && aRelationship.IsNull(); aDTIter.Next()) {
+      aRelationship = Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(aDTIter.Value());
     }
     if (!aRelationship.IsNull()) {
       Handle(StepRepr_ShapeAspect) aSA = aRelationship->RelatingShapeAspect();
@@ -2419,8 +2436,8 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
         Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aSAIter.Value());
         if (aGISU.IsNull())
           continue;
-        for (Standard_Integer i = 1; i <= aGISU->NbIdentifiedItem(); i++) {
-          TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(i), theWS, aSTool);
+        for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
+          TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
           if (!aShapeL.IsNull()) {
             aDTShapeLabels.Append(aShapeL);
             isValidDT = Standard_True;
@@ -2431,12 +2448,12 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
 
     if (aType != XCAFDimTolObjects_DatumTargetType_Area && !isValidDT) {
       // Try another way of feature connection
-      for (anIter.Start(); anIter.More(); anIter.Next()) {
-        Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
+      for (aDTIter.Start(); aDTIter.More(); aDTIter.Next()) {
+        Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aDTIter.Value());
         if (aGISU.IsNull())
           continue;
-        for (Standard_Integer i = 1; i <= aGISU->NbIdentifiedItem(); i++) {
-          TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(i), theWS, aSTool);
+        for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
+          TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
           if (!aShapeL.IsNull()) {
             aDTShapeLabels.Append(aShapeL);
             isValidDT = Standard_True;
@@ -2461,7 +2478,7 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
       if (anItemIndex > 0) {
         Handle(Transfer_Binder) aBinder = aTP->MapItem(anItemIndex);
         TopoDS_Shape anItemShape = TransferBRep::ShapeResult(aBinder);
-        aDatObj->SetDatumTarget(anItemShape);
+        aDatTargetObj->SetDatumTarget(anItemShape);
         isValidDT = Standard_True;
       }
     }
@@ -2484,21 +2501,21 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
           if (!aSRWP.IsNull()) {
             isValidDT = Standard_True;
             // Collect parameters of datum target
-            for (Standard_Integer i = aSRWP->Items()->Lower(); i <= aSRWP->Items()->Upper(); i++)
+            for (Standard_Integer j = aSRWP->Items()->Lower(); j <= aSRWP->Items()->Upper(); j++)
             {
-              if (aSRWP->ItemsValue(i).IsNull())
+              if (aSRWP->ItemsValue(j).IsNull())
                 continue;
-              if (aSRWP->ItemsValue(i)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
+              if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
               {
                 Handle(StepGeom_Axis2Placement3d) anAx
-                  = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(i));
+                  = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(j));
                 Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(anAx);
-                aDatObj->SetDatumTargetAxis(anAxis->Ax2());
+                aDatTargetObj->SetDatumTargetAxis(anAxis->Ax2());
               }
-              else if (aSRWP->ItemsValue(i)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
+              else if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
               {
                 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
-                  Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(i));
+                  Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(j));
                 Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
                 StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
                 Standard_Real aFact = 1.;
@@ -2511,9 +2528,9 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
                   aVal = aVal * aFact;
                 if (aM->Name()->String().IsEqual("target length") ||
                   aM->Name()->String().IsEqual("target diameter"))
-                  aDatObj->SetDatumTargetLength(aVal);
+                  aDatTargetObj->SetDatumTargetLength(aVal);
                 else
-                  aDatObj->SetDatumTargetWidth(aVal);
+                  aDatTargetObj->SetDatumTargetWidth(aVal);
               }
             }
           }
@@ -2524,19 +2541,21 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
     // Create datum target object
     if (isValidDT) {
       TDF_Label aDatL = aDGTTool->AddDatum();
+      myGDTMap.Bind(aDT, aDatL);
+      aDGTTool->Lock(aDatL);
       aDat = XCAFDoc_Datum::Set(aDatL);
       aDGTTool->SetDatum(aDTShapeLabels, aDatL);
-      aDatObj->SetName(theDat->Identification());
-      aDatObj->SetPosition(thePositionCounter);
+      aDatTargetObj->SetName(theDat->Identification());
+      aDatTargetObj->SetPosition(thePositionCounter);
       if (!theXCAFModifiers.IsEmpty())
-        aDatObj->SetModifiers(theXCAFModifiers);
+        aDatTargetObj->SetModifiers(theXCAFModifiers);
       if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
-        aDatObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
+        aDatTargetObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
       aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
-      aDatObj->IsDatumTarget(Standard_True);
-      aDatObj->SetDatumTargetNumber(aDT->TargetId()->IntegerValue());
-      readAnnotation(aTR, aDT, aDatObj);
-      aDat->SetObject(aDatObj);
+      aDatTargetObj->IsDatumTarget(Standard_True);
+      aDatTargetObj->SetDatumTargetNumber(aDT->TargetId()->IntegerValue());
+      readAnnotation(aTR, aDT, aDatTargetObj);
+      aDat->SetObject(aDatTargetObj);
       isExistDatumTarget = Standard_True;
     }
   }
@@ -2544,6 +2563,15 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
   if (aShapeLabels.Length() > 0 || !isExistDatumTarget) {
     // Create object for datum
     TDF_Label aDatL = aDGTTool->AddDatum();
+    myGDTMap.Bind(theDat, aDatL);
+    // bind datum label with all reference datum_feature entities
+    for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
+      Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
+      if (aSA.IsNull() || aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
+        continue;
+      myGDTMap.Bind(aSA, aDatL);
+    }
+    aDGTTool->Lock(aDatL);
     aDat = XCAFDoc_Datum::Set(aDatL);
     aDGTTool->SetDatum(aShapeLabels, aDatL);
     aDatObj->SetName(theDat->Identification());
@@ -2568,10 +2596,10 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
 //function : ReadDatums
 //purpose  : auxilary
 //=======================================================================
-static Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt,
-                                        const TDF_Label theGDTL,
-                                        const Handle(TDocStd_Document)& theDoc,
-                                        const Handle(XSControl_WorkSession)& theWS)
+Standard_Boolean STEPCAFControl_Reader::readDatumsAP242(const Handle(Standard_Transient)& theEnt,
+                                                        const TDF_Label theGDTL,
+                                                        const Handle(TDocStd_Document)& theDoc,
+                                                        const Handle(XSControl_WorkSession)& theWS)
 {
   const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
   const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
@@ -2716,9 +2744,9 @@ static Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt
 //function : createGeomTolObjectInXCAF
 //purpose  : 
 //=======================================================================
-static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
-                                               const Handle(TDocStd_Document)& theDoc,
-                                               const Handle(XSControl_WorkSession)& theWS)
+TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
+                                                       const Handle(TDocStd_Document)& theDoc,
+                                                       const Handle(XSControl_WorkSession)& theWS)
 {
   TDF_Label aGDTL;
   if(!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
@@ -3084,6 +3112,8 @@ static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
     if(!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
     {
       aGDTL = aDGTTool->AddDimension();
+      myGDTMap.Bind(theEnt, aGDTL);
+      aDGTTool->Lock(aGDTL);
       Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
       TCollection_AsciiString aStr("DGT:Dimensional_");
       if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
@@ -3109,6 +3139,8 @@ static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
     else
     {
       aGDTL = aDGTTool->AddGeomTolerance();
+      myGDTMap.Bind(theEnt, aGDTL);
+      aDGTTool->Lock(aGDTL);
       Handle(XCAFDoc_GeomTolerance) aGTol = XCAFDoc_GeomTolerance::Set(aGDTL);
       TCollection_AsciiString aStr("DGT:GeomTolerance");
       TDataStd_Name::Set(aGDTL, aStr);
@@ -3783,7 +3815,7 @@ static void setGeomTolObjectToXCAF(const Handle(Standard_Transient)& theEnt,
 //=======================================================================
 
 Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession)& theWS,
-                                                 Handle(TDocStd_Document)& theDoc) const
+                                                 Handle(TDocStd_Document)& theDoc)
 {
   const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
   const Interface_Graph& aGraph = theWS->Graph();
@@ -3814,51 +3846,125 @@ Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSess
       }
     }
     else if (anEnt->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)) ||
-      anEnt->IsKind(STANDARD_TYPE(StepVisual_AnnotationCurveOccurrence)))
+      anEnt->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
     {
-      // read common PMIs: presentation, which is not connected to any PMI.
-      Handle(StepVisual_AnnotationPlane) anAnPlane;
-      Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
-      Standard_Boolean isCommonLabel = Standard_True;
-      for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More(); anIter.Next())
-      {
-        if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationPlane)))
-          anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
-        else
-          isCommonLabel = Standard_False;
+      // Protection against import presentation twice
+      Handle(StepVisual_DraughtingCallout) aDC;
+      for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDC.IsNull(); anIter.Next()) {
+        aDC = Handle(StepVisual_DraughtingCallout)::DownCast(anIter.Value());
       }
-      if (!isCommonLabel)
+      if (!aDC.IsNull())
         continue;
-      // create empty Dimension
-      TDF_Label aGDTL = aDGTTool->AddDimension();
-      Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
-      TCollection_AsciiString aStr("DGT:Common_label");
-      TDataStd_Name::Set(aGDTL, aStr);
-      TDF_LabelSequence anEmptySeq1, anEmptySeq2;
-      aDGTTool->SetDimension(anEmptySeq1, anEmptySeq2, aGDTL);
-      Handle(XCAFDimTolObjects_DimensionObject) aDimObj = new XCAFDimTolObjects_DimensionObject();
-      // read annotations
-      Standard_Real aFact = 1.0;
-      if (!anAnPlane.IsNull())
-      {
-        Handle(StepVisual_DraughtingModel) aDModel;
-        for (Interface_EntityIterator anIter = aGraph.Sharings(anAnPlane); anIter.More() && aDModel.IsNull(); anIter.Next())
-        {
-          if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingModel)))
-            aDModel = Handle(StepVisual_DraughtingModel)::DownCast(anIter.Value());
+      // Read presentations for PMIs without semantic data.
+      Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
+      TDF_LabelSequence aShapesL;
+      for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDMIA.IsNull(); anIter.Next()) {
+        aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(anIter.Value());
+      }
+      if (!aDMIA.IsNull()) {
+        // Check entity, skip all, attached to GDTs
+        Handle(StepRepr_ShapeAspect) aDefinition = aDMIA->Definition().ShapeAspect();
+        if (!aDefinition.IsNull()) {
+          Standard_Boolean isConnectedToGDT = Standard_False;
+          // Skip if definition is a datum
+          if (aDefinition->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
+            aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
+            aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
+            aDefinition->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
+            isConnectedToGDT = Standard_True;
+          }
+          // Skip if any GDT is applied to definition
+          for (Interface_EntityIterator anIter = aGraph.Sharings(aDefinition); anIter.More() && !isConnectedToGDT; anIter.Next()) {
+            if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
+              anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
+              anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
+              isConnectedToGDT = Standard_True;
+              continue;
+            }
+            Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
+            if (!aSAR.IsNull()) {
+              Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatedShapeAspect();
+              if (!aSA.IsNull()) {
+                if (aSA->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
+                  aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
+                  aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
+                  aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
+                  isConnectedToGDT = Standard_True;
+                }
+                for (Interface_EntityIterator aDimIter = aGraph.Sharings(aSA); aDimIter.More() && !isConnectedToGDT; aDimIter.Next()) {
+                  if (aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
+                    aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
+                    aDimIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
+                    isConnectedToGDT = Standard_True;
+                    continue;
+                  }
+                }
+              }
+            }
+          }
+          if (isConnectedToGDT)
+            continue;
+        }
+        else if (aDMIA->Definition().PropertyDefinition().IsNull())
+          continue;
+
+        // Get shapes
+        NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
+        collectShapeAspect(aDefinition, theWS, aSAs);
+        for (Standard_Integer aSAIt = 1; aSAIt <= aSAs.Length(); aSAIt++) {
+          Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
+          for (Interface_EntityIterator anIter = aGraph.Sharings(aSAs.Value(aSAIt)); anIter.More() && aGISU.IsNull(); anIter.Next())
+            aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
+          if (aGISU.IsNull())
+            continue;
+          for (Standard_Integer anItemIt = 1; anItemIt <= aGISU->NbIdentifiedItem(); anItemIt++) {
+            TDF_Label aLabel = getShapeLabel(aGISU->IdentifiedItemValue(anItemIt), theWS, XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()));
+            if (!aLabel.IsNull())
+              aShapesL.Append(aLabel);
+          }
         }
-        if (!aDModel.IsNull())
-          GetLengthConversionFactorFromContext(aDModel->ContextOfItems(), aFact);
       }
-      gp_Ax2 aPlaneAxes;
-      readAnnotationPlane(anAnPlane, aFact, aPlaneAxes);
+      Standard_Boolean isCommonLabel = (aShapesL.Length() == 0);
+
+      // Calculate unit
+      Standard_Real aFact = 1.0;
+      if (!aDMIA.IsNull() && !aDMIA->UsedRepresentation().IsNull())
+        GetLengthConversionFactorFromContext(aDMIA->UsedRepresentation()->ContextOfItems(), aFact);
+
+      // Presentation
       TopoDS_Shape aPresentation;
       Handle(TCollection_HAsciiString) aPresentName;
       Bnd_Box aBox;
-      readPMIPresentation(anEnt, aTR, aFact, aPresentation, aPresentName, aBox);
-      // populate Dimension
-      aDimObj->SetType(XCAFDimTolObjects_DimensionType_CommonLabel);
-      aDimObj->SetPlane(aPlaneAxes);
+      if (!readPMIPresentation(anEnt, aTR, aFact, aPresentation, aPresentName, aBox))
+        continue;
+      // Annotation plane
+      Handle(StepVisual_AnnotationPlane) anAnPlane;
+      for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && anAnPlane.IsNull(); anIter.Next())
+        anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
+      
+      // Set object to XCAF
+      TDF_Label aGDTL = aDGTTool->AddDimension();
+      myGDTMap.Bind(anEnt, aGDTL);
+      aDGTTool->Lock(aGDTL);
+      Handle(XCAFDimTolObjects_DimensionObject) aDimObj = new XCAFDimTolObjects_DimensionObject();
+      Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
+      TCollection_AsciiString aStr("DGT:");
+      if (isCommonLabel) {
+        aStr.AssignCat("Common_label");
+        aDimObj->SetType(XCAFDimTolObjects_DimensionType_CommonLabel);
+      }
+      else {
+        aStr.AssignCat("Dimension");
+        aDimObj->SetType(XCAFDimTolObjects_DimensionType_DimensionPresentation);
+      }
+      TDataStd_Name::Set(aGDTL, aStr);
+      TDF_LabelSequence anEmptySeq2;
+      aDGTTool->SetDimension(aShapesL, anEmptySeq2, aGDTL);
+      gp_Ax2 aPlaneAxes;
+      if (!anAnPlane.IsNull()) {
+        if (readAnnotationPlane(anAnPlane, aFact, aPlaneAxes))
+          aDimObj->SetPlane(aPlaneAxes);
+      }
       aDimObj->SetPresentation(aPresentation, aPresentName);
       aDim->SetObject(aDimObj);
     }
@@ -4015,6 +4121,223 @@ Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_Wor
   return Standard_True;
 }
 
+//=======================================================================
+//function : collectViewShapes
+//purpose  : collect all labels of representations in given representation
+//=======================================================================
+
+void collectViewShapes(const Handle(XSControl_WorkSession)& theWS,
+  const Handle(TDocStd_Document)& theDoc,
+  const Handle(StepRepr_Representation) theRepr,
+  TDF_LabelSequence& theShapes)
+{
+  Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
+  Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
+  const Interface_Graph& aGraph = aTP->Graph();
+  Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
+  Standard_Integer anIndex = aTP->MapIndex(theRepr);
+  TopoDS_Shape aSh;
+  if (anIndex > 0) {
+    Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
+    aSh = TransferBRep::ShapeResult(aBinder);
+  }
+  if (!aSh.IsNull()) {
+    TDF_Label aShL;
+    aSTool->FindShape(aSh, aShL);
+    if (!aShL.IsNull())
+      theShapes.Append(aShL);
+  }
+  Interface_EntityIterator anIter = aGraph.Sharings(theRepr);
+  for (; anIter.More(); anIter.Next()) {
+    if (!anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_RepresentationRelationship)))
+      continue;
+    Handle(StepRepr_RepresentationRelationship) aReprRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(anIter.Value());
+    if (aReprRelationship->Rep1() != theRepr)
+      collectViewShapes(theWS, theDoc, aReprRelationship->Rep1(), theShapes);
+  }
+}
+
+//=======================================================================
+//function : buildClippingPlanes
+//purpose  :
+//=======================================================================
+Handle(TCollection_HAsciiString) buildClippingPlanes(const Handle(StepGeom_GeometricRepresentationItem)& theClippingCameraModel,
+  TDF_LabelSequence& theClippingPlanes,
+  const Handle(XCAFDoc_ClippingPlaneTool) theTool)
+{
+  Handle(TCollection_HAsciiString) anExpression = new TCollection_HAsciiString();
+  NCollection_Sequence<Handle(StepGeom_GeometricRepresentationItem)> aPlanes;
+  Handle(TCollection_HAsciiString) anOperation = new TCollection_HAsciiString("*");
+
+  // Store operands
+  if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClipping))) {
+    Handle(StepVisual_CameraModelD3MultiClipping) aCameraModel =
+      Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(theClippingCameraModel);
+    // Root of clipping planes tree
+    if (aCameraModel->ShapeClipping()->Length() == 1) {
+      Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModelUnion =
+        aCameraModel->ShapeClipping()->Value(1).CameraModelD3MultiClippingUnion();
+      if (!aCameraModelUnion.IsNull())
+        return buildClippingPlanes(aCameraModelUnion, theClippingPlanes, theTool);
+    }
+    for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
+      aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
+    }
+  }
+  else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingUnion))) {
+    Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModel =
+      Handle(StepVisual_CameraModelD3MultiClippingUnion)::DownCast(theClippingCameraModel);
+    anOperation = new TCollection_HAsciiString("+");
+    for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
+      aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
+    }
+  }
+  else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingIntersection))) {
+    Handle(StepVisual_CameraModelD3MultiClippingIntersection) aCameraModel =
+      Handle(StepVisual_CameraModelD3MultiClippingIntersection)::DownCast(theClippingCameraModel);
+    for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
+      aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
+    }
+  }
+  // Build expression
+  anExpression->AssignCat("(");
+  for (Standard_Integer i = 1; i <= aPlanes.Length(); i++) {
+    Handle(StepGeom_Plane) aPlaneEnt = Handle(StepGeom_Plane)::DownCast(aPlanes.Value(i));
+    if (!aPlaneEnt.IsNull()) {
+      Handle(Geom_Plane) aPlane = StepToGeom::MakePlane(aPlaneEnt);
+      if (!aPlane.IsNull()) {
+        TDF_Label aPlaneL = theTool->AddClippingPlane(aPlane->Pln(), aPlaneEnt->Name());
+        theClippingPlanes.Append(aPlaneL);
+        TCollection_AsciiString anEntry;
+        TDF_Tool::Entry(aPlaneL, anEntry);
+        anExpression->AssignCat(new TCollection_HAsciiString(anEntry));
+      }
+    }
+    else {
+      anExpression->AssignCat(buildClippingPlanes(aPlanes.Value(i), theClippingPlanes, theTool));
+    }
+    anExpression->AssignCat(anOperation);
+  }
+  // Insert brace instead of operation after last operand.
+  anExpression->SetValue(anExpression->Length(), ')');
+  return anExpression;
+}
+
+
+//=======================================================================
+//function : ReadViews
+//purpose  :
+//=======================================================================
+Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const
+{
+  const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
+  Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
+  Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
+  Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(theDoc->Main());
+  if (aDGTTool.IsNull()) return Standard_False;
+
+  Standard_Integer nb = aModel->NbEntities();
+  for (Standard_Integer i = 1; i <= nb; i++) {
+    Handle(Standard_Transient) anEnt = aModel->Value(i);
+    if (!anEnt->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3)))
+      continue;
+    Handle(XCAFView_Object) anObj = new XCAFView_Object();
+    // Import attributes of view
+    Handle(StepVisual_CameraModelD3) aCameraModel = Handle(StepVisual_CameraModelD3)::DownCast(anEnt);
+    anObj->SetName(aCameraModel->Name());
+    Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aCameraModel->ViewReferenceSystem());
+    anObj->SetViewDirection(anAxis->Direction());
+    anObj->SetUpDirection(anAxis->Direction() ^ anAxis->XDirection());
+    Handle(StepVisual_ViewVolume) aViewVolume = aCameraModel->PerspectiveOfVolume();
+    XCAFView_ProjectionType aType = XCAFView_ProjectionType_NoCamera;
+    if (aViewVolume->ProjectionType() == StepVisual_copCentral)
+      aType = XCAFView_ProjectionType_Central;
+    else if (aViewVolume->ProjectionType() == StepVisual_copParallel)
+      aType = XCAFView_ProjectionType_Parallel;
+    anObj->SetType(aType);
+    Handle(Geom_CartesianPoint) aPoint = StepToGeom::MakeCartesianPoint(aViewVolume->ProjectionPoint());
+    anObj->SetProjectionPoint(aPoint->Pnt());
+    anObj->SetZoomFactor(aViewVolume->ViewPlaneDistance());
+    anObj->SetWindowHorizontalSize(aViewVolume->ViewWindow()->SizeInX());
+    anObj->SetWindowVerticalSize(aViewVolume->ViewWindow()->SizeInY());
+    if (aViewVolume->FrontPlaneClipping())
+      anObj->SetFrontPlaneDistance(aViewVolume->FrontPlaneDistance());
+    if (aViewVolume->BackPlaneClipping())
+      anObj->SetBackPlaneDistance(aViewVolume->BackPlaneDistance());
+    anObj->SetViewVolumeSidesClipping(aViewVolume->ViewVolumeSidesClipping());
+    // Clipping plane
+    Handle(StepVisual_CameraModelD3MultiClipping) aClippingCameraModel =
+      Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(aCameraModel);
+    TDF_LabelSequence aClippingPlanes;
+    if (!aClippingCameraModel.IsNull()) {
+      Handle(TCollection_HAsciiString) aClippingExpression;
+      Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(theDoc->Main());
+      aClippingExpression = buildClippingPlanes(aClippingCameraModel, aClippingPlanes, aClippingPlaneTool);
+      anObj->SetClippingExpression(aClippingExpression);
+    }
+    // Collect shapes and GDTs
+    TDF_LabelSequence aShapes, aGDTs;
+    Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
+    Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
+    const Interface_Graph& aGraph = aTP->Graph();
+    Handle(StepVisual_DraughtingModel) aDModel;
+    Interface_EntityIterator anIter = aGraph.Sharings(aCameraModel);
+    for (; anIter.More() && aDModel.IsNull(); anIter.Next()) {
+      aDModel = Handle(StepVisual_DraughtingModel)::DownCast(anIter.Value());
+    }
+    if (aDModel.IsNull())
+      return Standard_False;
+
+    anIter = aGraph.Shareds(aDModel);
+    for (; anIter.More(); anIter.Next()) {
+      if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
+        Handle(StepRepr_MappedItem) anItem = Handle(StepRepr_MappedItem)::DownCast(anIter.Value());
+        Handle(StepRepr_Representation) aRepr = anItem->MappingSource()->MappedRepresentation();
+        collectViewShapes(theWS, theDoc, aRepr, aShapes);
+      }
+      else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)) ||
+        anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout))) {
+        Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
+        for (; aDMIAIter.More(); aDMIAIter.Next()) {
+          if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
+            continue;
+          Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
+            Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
+          TDF_Label aGDTL;
+          Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
+          if (!isFind) {
+            isFind = myGDTMap.Find(anIter.Value(), aGDTL);
+          }
+          if (isFind)
+            aGDTs.Append(aGDTL);
+        }
+      }
+      else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationPlane))) {
+        Handle(StepVisual_AnnotationPlane) aPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
+        for (Standard_Integer j = 1; j <= aPlane->NbElements(); j++) {
+          Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
+          for (; aDMIAIter.More(); aDMIAIter.Next()) {
+            if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
+              continue;
+            Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
+              Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
+            TDF_Label aGDTL;
+            Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
+            if (isFind)
+              aGDTs.Append(aGDTL);
+          }
+        }
+      }
+    }
+    TDF_Label aViewL = aViewTool->AddView();
+    Handle(XCAFDoc_View) aView = XCAFDoc_View::Set(aViewL);
+    aView->SetObject(anObj);
+    aViewTool->SetView(aShapes, aGDTs, aClippingPlanes, aViewL);
+    aViewTool->Lock(aViewL);
+  }
+  return Standard_True;
+}
+
 //=======================================================================
 //function : SettleShapeData
 //purpose  :
@@ -4394,3 +4717,23 @@ Standard_Boolean STEPCAFControl_Reader::GetMatMode () const
 {
   return myMatMode;
 }
+
+//=======================================================================
+//function : SetViewMode
+//purpose  : 
+//=======================================================================
+
+void STEPCAFControl_Reader::SetViewMode(const Standard_Boolean viewmode)
+{
+  myViewMode = viewmode;
+}
+
+//=======================================================================
+//function : GetViewMode
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean STEPCAFControl_Reader::GetViewMode() const
+{
+  return myViewMode;
+}