0029803: STEP Import: Units (inch) not applied to entity possessing GEOMETRIC_REPRESE...
authorgka <gka@opencascade.com>
Mon, 17 Feb 2020 17:24:59 +0000 (20:24 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 25 Mar 2020 16:52:12 +0000 (19:52 +0300)
Translation of the entities AXIS2_PLACEMENT_3D including in the entity CONSTRUCTIVE_GEOMETRY_REPRESENTATION_RELATIONSHIP was added.
Entity  AXIS2_PLACEMENT_3D is translated to the planar face with axis equal to AXIS2_PLACEMENT_3D.
New parameter "read.step.constructivegeom.relationship" is added to enable this translation (by default it is OFF).

Added test bugs step bug29803

dox/user_guides/step/step.md
src/STEPControl/STEPControl_ActorRead.cxx
src/STEPControl/STEPControl_ActorRead.hxx
src/STEPControl/STEPControl_Controller.cxx
tests/bugs/step/bug29803 [new file with mode: 0644]

index c22f2a5..e65953f 100644 (file)
@@ -406,6 +406,47 @@ if(!Interface_Static::SetIVal(;read.step.shape.aspect;,1))
 ~~~~~
 Default value is 1 (ON). 
 
+<h4>read.step.constructivegeom.relationship:</h4>
+
+Boolean flag regulating translation of "CONSTRUCTIVE_GEOMETRY_REPRESENTATION_RELATIONSHIP" entities that define
+position of constructive geometry entities contained in "CONSTRUCTIVE_GEOMETRY_REPRESENTATION" with respect to the
+main representation of the shape (product).
+
+By default, the flag is set to 0 (OFF) so these entities are not translated. 
+Set this flag to 1 (ON) if you need to translate constructive geometry entities associated with the parts:
+
+~~~~~
+if (!Interface_Static::SetIVal("read.step.constructivegeom.relationship", 1)) { .. error .. }
+~~~~~
+
+The "CONSTRUCTIVE_GEOMETRY_REPRESENTATION" entity is translated into compound of two unlimited planar faces, 
+whose location is result of translation of corresponding "AXIS_PLACEMENT" entity.
+Note that appropriate interpretation of the translated data should be done after translation.
+
+The result of translation can be obtained either for the "CONSTRUCTIVE_GEOMETRY_REPRESENTATION_RELATIONSHIP" entity,
+of for each of the two "AXIS2_PLACEMENT_3D" entities referenced by it. as follows:
+
+~~~~~
+  STEPControl_Reader aReader;
+  ... // translate file and parse STEP model to find relevant axis entity
+  Handle(StepGeom_Axis2Placement3d) aSTEPAxis = ...;
+  Handle(Transfer_Binder) aBinder = aReader->WS()->TransferReader()->TransientProcess()->Find(aSTEPAxis);
+  Handle(TransferBRep_ShapeBinder) aShBinder = Handle(TransferBRep_ShapeBinder)::DownCast(aBinder);
+  if (! aShBinder.IsNull())
+  {
+    TopoDS_Face aFace = TopoDS::Face (aShBinder->Result());
+    if (! aFace.IsNull())
+    {
+      Handle(Geom_Plane) aSurf = Handle(Geom_Plane)::DownCast (BRep_Tool::Surface (aFace));
+      if (! aSurf.IsNull())
+      {
+        gp_Ax3 anAxis = aSurf->Placement();
+        ... // use the axis placement data
+      }
+    }
+  }
+~~~~~
+
 @subsubsection occt_step_2_3_4 Performing the STEP file translation
 
 Perform the translation according to what you want to translate. You can choose either root entities (all or selected by the number of root), or select any entity by its number in the STEP file. There is a limited set of types of entities that can be used as starting entities for translation. Only the following entities are recognized as transferable: 
index f009517..ebebfd2 100644 (file)
 #include <UnitsMethods.hxx>
 #include <XSAlgo.hxx>
 #include <XSAlgo_AlgoContainer.hxx>
+#include <StepRepr_ConstructiveGeometryRepresentationRelationship.hxx>
+#include <StepRepr_ConstructiveGeometryRepresentation.hxx>
+#include <Geom_Plane.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(STEPControl_ActorRead,Transfer_ActorOfTransientProcess)
 
@@ -505,6 +508,7 @@ static void getSDR(const Handle(StepRepr_ProductDefinitionShape)& PDS,
   // should be taken into account 
   Standard_Integer readSRR = Interface_Static::IVal("read.step.shape.relationship");
   
+  Standard_Integer readConstructiveGeomRR = Interface_Static::IVal("read.step.constructivegeom.relationship");
   // Flag indicating whether SDRs associated with the product`s main SDR
   // by SAs (which correspond to hybrid model representation in AP203 before 1998) 
   // should be taken into account 
@@ -625,19 +629,35 @@ static void getSDR(const Handle(StepRepr_ProductDefinitionShape)& PDS,
       Handle(Standard_Type) tSRR = STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship);
       for (subs1.Start(); subs1.More(); subs1.Next()) {
         Handle(Standard_Transient) anitem = subs1.Value();
-        if ( anitem->DynamicType() != tSRR ) continue;
-        Handle(StepRepr_ShapeRepresentationRelationship) SRR =
-          Handle(StepRepr_ShapeRepresentationRelationship)::DownCast(anitem);
-        Standard_Integer nbrep = ( rep == SRR->Rep1() ? 2 : 1 );
-        // SKL for bug 29068: parameter useTrsf is used because if root entity has connection with other
-        // by ShapeRepresentationRelationship then result after such transferring need to transform also.
-        // This case is from test "bugs modalg_7 bug30196"
-        binder = TransferEntity(SRR, TP, nbrep, useTrsf);
-        if ( ! binder.IsNull() ) {
-          theResult = TransferBRep::ShapeResult (binder);
-          Result1 = theResult;
-          B.Add(Cund, theResult);
-          nbShapes++;
+        if( !anitem->IsKind(STANDARD_TYPE(StepRepr_RepresentationRelationship)))
+          continue;
+        if (anitem->DynamicType() == tSRR)
+        {
+          Handle(StepRepr_ShapeRepresentationRelationship) SRR =
+            Handle(StepRepr_ShapeRepresentationRelationship)::DownCast(anitem);
+          Standard_Integer nbrep = (rep == SRR->Rep1() ? 2 : 1);
+          // SKL for bug 29068: parameter useTrsf is used because if root entity has connection with other
+          // by ShapeRepresentationRelationship then result after such transferring need to transform also.
+          // This case is from test "bugs modalg_7 bug30196"
+          binder = TransferEntity(SRR, TP, nbrep, useTrsf);
+          if (! binder.IsNull()) {
+            theResult = TransferBRep::ShapeResult (binder);
+            Result1 = theResult;
+            B.Add(Cund, theResult);
+            nbShapes++;
+          }
+        }
+        else if(readConstructiveGeomRR && anitem->IsKind(STANDARD_TYPE(StepRepr_ConstructiveGeometryRepresentationRelationship)))
+        {
+          Handle(StepRepr_ConstructiveGeometryRepresentationRelationship) aCSRR =
+            Handle(StepRepr_ConstructiveGeometryRepresentationRelationship)::DownCast(anitem);
+           binder = TransferEntity(aCSRR, TP);
+           if (! binder.IsNull())
+           {
+             Result1 = TransferBRep::ShapeResult (binder);
+             B.Add(Cund, Result1);
+             nbShapes++;
+           }
         }
       }
     }
@@ -1101,6 +1121,70 @@ Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(
 }
 
 //=======================================================================
+//function : TransferEntity
+//purpose  : 
+//=======================================================================
+
+
+Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(
+    const Handle(StepRepr_ConstructiveGeometryRepresentationRelationship)& theCGRR,
+    const Handle(Transfer_TransientProcess)& theTP)
+{
+  Handle(TransferBRep_ShapeBinder) shbinder;
+  if (theCGRR.IsNull()) 
+    return shbinder;
+  Standard_Boolean resetUnits = Standard_False;
+  Handle(StepRepr_Representation) oldSRContext = mySRContext;
+  TopoDS_Compound aComp;
+  BRep_Builder aB;
+  aB.MakeCompound(aComp);
+  for (Standard_Integer i = 1; i <= 2; i ++) 
+  {
+    Handle(StepRepr_ConstructiveGeometryRepresentation) aCRepr = 
+      Handle(StepRepr_ConstructiveGeometryRepresentation)::DownCast(i == 1 ? theCGRR->Rep1() : theCGRR->Rep2() );
+    if(aCRepr.IsNull())
+      continue;
+    if(mySRContext.IsNull() || aCRepr->ContextOfItems() != mySRContext->ContextOfItems())
+    {
+      PrepareUnits(aCRepr,theTP);
+      resetUnits = Standard_True;
+    }
+    Standard_Integer j =1;
+    Handle(StepGeom_Axis2Placement3d) anAxis1;
+    Handle(StepGeom_Axis2Placement3d) anAxis2;
+    for( ; j <= 2; j++ )
+    {
+      Handle(StepRepr_RepresentationItem) anItem = aCRepr->ItemsValue(j);
+      Handle(StepGeom_Axis2Placement3d) aStepAxis =
+        Handle(StepGeom_Axis2Placement3d)::DownCast(anItem);
+      if( !aStepAxis.IsNull())
+      {
+        Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement (aStepAxis);
+        if(anAxis.IsNull())
+          continue;
+        Handle(Geom_Plane) aPlane = new Geom_Plane(gp_Ax3(anAxis->Ax2()));
+        TopoDS_Face aPlaneFace;
+        aB.MakeFace(aPlaneFace, aPlane, Precision::Confusion());
+        Handle(TransferBRep_ShapeBinder) axisbinder = new TransferBRep_ShapeBinder (aPlaneFace);
+        theTP->Bind(aStepAxis, axisbinder);
+        aB.Add(aComp, aPlaneFace);
+      }
+    }
+
+  }
+  shbinder = new TransferBRep_ShapeBinder (aComp);
+  mySRContext = oldSRContext;
+  if(oldSRContext.IsNull() || resetUnits)
+    PrepareUnits(oldSRContext,theTP);
+
+  theTP->Bind(theCGRR, shbinder);
+  
+  return shbinder;
+  
+}
+
+//=======================================================================
 //function : IsNeedRepresentation
 //purpose  : 
 //=======================================================================
index e235410..eb0f8e2 100644 (file)
@@ -45,6 +45,7 @@ class StepRepr_MappedItem;
 class StepShape_FaceSurface;
 class TopoDS_Shell;
 class TopoDS_Compound;
+class StepRepr_ConstructiveGeometryRepresentationRelationship;
 
 
 class STEPControl_ActorRead;
@@ -136,6 +137,9 @@ protected:
   
   //! Transfers  FaceSurface entity
   Standard_EXPORT Handle(TransferBRep_ShapeBinder) TransferEntity (const Handle(StepShape_FaceSurface)& fs, const Handle(Transfer_TransientProcess)& TP);
+
+  Handle(TransferBRep_ShapeBinder) TransferEntity( const Handle(StepRepr_ConstructiveGeometryRepresentationRelationship)& theCGRR,
+    const Handle(Transfer_TransientProcess)& theTP);
   
   //! Tranlates file by old way when CDSR are roots . Acts only if "read.step.product_mode" is equal Off.
   Standard_EXPORT Handle(TransferBRep_ShapeBinder) OldWay (const Handle(Standard_Transient)& start, const Handle(Transfer_TransientProcess)& TP);
index dc3ec17..1499322 100644 (file)
@@ -199,6 +199,16 @@ STEPControl_Controller::STEPControl_Controller ()
     Interface_Static::Init("step", "read.step.all.shapes", '&', "eval On");
     Interface_Static::SetIVal("read.step.all.shapes", 0);
 
+     // Mode for reading constructive geometry representation relationship to read
+    //StepRepr_ConstructiveGeometryRepresentation method implemented only for StepGeom_MakeAxis2Placement3d
+    //for axis placements representing axis for suplemented geometry. Axis placements are translated to planar faces with CS 
+    //equal to translated axis placements
+    Interface_Static::Init("step","read.step.constructivegeom.relationship",'e',"");
+    Interface_Static::Init("step","read.step.constructivegeom.relationship",'&',"enum 0");
+    Interface_Static::Init("step","read.step.constructivegeom.relationship",'&',"eval OFF");
+    Interface_Static::Init("step","read.step.constructivegeom.relationship",'&',"eval ON");
+    Interface_Static::SetCVal("read.step.constructivegeom.relationship","OFF");
+
     init = Standard_True;
   }
 
diff --git a/tests/bugs/step/bug29803 b/tests/bugs/step/bug29803
new file mode 100644 (file)
index 0000000..2eeed5b
--- /dev/null
@@ -0,0 +1,12 @@
+puts "===================================="
+puts "0029803: STEP Import: Units (inch) not applied to entity possessing GEOMETRIC_REPRESENTATION_CONTEXT"
+puts "===================================="
+
+puts "Read STEP file containing GEOMETRIC_REPRESENTATION_CONTEXT and check"
+puts "that it has been translated into two empty faces"
+
+dall
+param read.step.constructivegeom.relationship 1
+stepread [locate_data_file bug29803.stp] a *
+tpdraw #1759
+checknbshapes tp_1577 -face 2 -wire 0 -compound 1