]> OCCT Git - occt.git/commitdiff
0033664: Visualization - Selection does not work for simple shape
authormzernova <mzernova@opencascade.com>
Thu, 18 Jul 2024 23:16:11 +0000 (00:16 +0100)
committermzernova <mzernova@opencascade.com>
Fri, 6 Sep 2024 10:50:33 +0000 (11:50 +0100)
Fixed direction calculation for Select3D_SensitiveCylinder created from Geom_CylindricalSurface

src/StdSelect/StdSelect_BRepSelectionTool.cxx
tests/v3d/bugs/bug33664 [new file with mode: 0644]

index 07b5a96543ffe528a78104206805823dd05f2094..4fd6b2fe8d86fcf448d4b12ffc9cd69ffe424de4 100644 (file)
@@ -579,11 +579,11 @@ static Standard_Real getCylinderHeight (const Handle(Poly_Triangulation)& theTri
 //function : isCylinderOrCone
 //purpose  :
 //=======================================================================
-static Standard_Boolean isCylinderOrCone (const TopoDS_Face& theHollowCylinder, const gp_Pnt& theLocation, gp_Dir& theDirection)
+static Standard_Boolean isCylinderOrCone (const TopoDS_Face& theHollowCylinder, gp_Pnt& theLocation, gp_Dir& theDirection)
 {
-  Standard_Integer aCirclesNb = 0;
+  Standard_Size aCirclesNb = 0;
   Standard_Boolean isCylinder = Standard_False;
-  gp_Pnt aPos;
+  gp_Pnt aPos[2];
 
   TopExp_Explorer anEdgeExp;
   for (anEdgeExp.Init (theHollowCylinder, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next())
@@ -596,16 +596,28 @@ static Standard_Boolean isCylinderOrCone (const TopoDS_Face& theHollowCylinder,
     {
       aCirclesNb++;
       isCylinder = Standard_True;
+      aPos[aCirclesNb - 1] = anAdaptor.Circle().Location();
       if (aCirclesNb == 2)
       {
-        // Reverse the direction of the cylinder, relevant if the cylinder was created as a prism
-        if (aPos.IsEqual (theLocation, Precision::Confusion()))
-        {
-          theDirection.Reverse();
-        }
-        return Standard_True;
+        break;
       }
-      aPos = anAdaptor.Circle().Location().XYZ();
+    }
+  }
+
+  switch (aCirclesNb)
+  {
+    case 2:
+    {
+      if (!aPos[0].IsEqual (aPos[1], Precision::Confusion()))
+      {
+        theDirection = gp_Dir(aPos[1].XYZ() - aPos[0].XYZ());
+      }
+      Standard_FALLTHROUGH;
+    }
+    case 1:
+    {
+      theLocation = aPos[0];
+      break;
     }
   }
 
@@ -659,7 +671,8 @@ Standard_Boolean StdSelect_BRepSelectionTool::GetSensitiveForFace (const TopoDS_
     else if (Handle(Geom_ConicalSurface) aGeomCone = Handle(Geom_ConicalSurface)::DownCast (aSurf))
     {
       gp_Dir aDummyDir;
-      if (isCylinderOrCone (theFace, gp_Pnt(), aDummyDir))
+      gp_Pnt aDummyLoc;
+      if (isCylinderOrCone (theFace, aDummyLoc, aDummyDir))
       {
         const gp_Cone aCone = BRepAdaptor_Surface (theFace).Cone();
         const Standard_Real aRad1 = aCone.RefRadius();
@@ -691,17 +704,16 @@ Standard_Boolean StdSelect_BRepSelectionTool::GetSensitiveForFace (const TopoDS_
     else if (Handle(Geom_CylindricalSurface) aGeomCyl = Handle(Geom_CylindricalSurface)::DownCast (aSurf))
     {
       const gp_Cylinder aCyl = BRepAdaptor_Surface (theFace).Cylinder();
-      gp_Ax3 aPos = aCyl.Position();
-      gp_Dir aDirection = aPos.Direction();
+      gp_Pnt aPos = aCyl.Position().Location();
+      gp_Dir aDirection = aCyl.Position().Direction();
 
-      if (isCylinderOrCone (theFace, aPos.Location(), aDirection))
+      if (isCylinderOrCone (theFace, aPos, aDirection))
       {
         const Standard_Real aRad = aCyl.Radius();
         const Standard_Real aHeight = getCylinderHeight (aTriangulation, aLoc);
 
         gp_Trsf aTrsf;
-        aPos.SetDirection (aDirection);
-        aTrsf.SetTransformation (aPos, gp::XOY());
+        aTrsf.SetTransformation (gp_Ax3 (aPos, aDirection), gp::XOY());
 
         Handle(Select3D_SensitiveCylinder) aSensSCyl = new Select3D_SensitiveCylinder (theOwner, aRad, aRad, aHeight, aTrsf, true);
         theSensitiveList.Append (aSensSCyl);
diff --git a/tests/v3d/bugs/bug33664 b/tests/v3d/bugs/bug33664
new file mode 100644 (file)
index 0000000..969ff42
--- /dev/null
@@ -0,0 +1,21 @@
+puts "============"
+puts "0033664: Visualization - Selection does not work for simple shape"
+puts "============"
+puts ""
+
+pload MODELING VISUALIZATION
+vclear
+vinit View1
+
+restore [locate_data_file cylinder_surface.brep] b
+vdisplay -dispMode 1 b
+vfit
+vsensdis
+
+vselect 200 200
+if {[vnbselected] != "1"} {
+  puts "ERROR: wrong sensitive area"
+}
+
+vselect 0 0
+vdump $::imagedir/${::casename}.png