1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-21 10:13:43 +03:00

0033664: Visualization - Selection does not work for simple shape

Fixed direction calculation for Select3D_SensitiveCylinder created from Geom_CylindricalSurface
This commit is contained in:
mzernova 2024-07-19 00:16:11 +01:00
parent 2fa9309186
commit 75a1e08b63
2 changed files with 49 additions and 16 deletions

View File

@ -579,11 +579,11 @@ static Standard_Real getCylinderHeight (const Handle(Poly_Triangulation)& theTri
//function : isCylinderOrCone //function : isCylinderOrCone
//purpose : //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; Standard_Boolean isCylinder = Standard_False;
gp_Pnt aPos; gp_Pnt aPos[2];
TopExp_Explorer anEdgeExp; TopExp_Explorer anEdgeExp;
for (anEdgeExp.Init (theHollowCylinder, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next()) for (anEdgeExp.Init (theHollowCylinder, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next())
@ -596,16 +596,28 @@ static Standard_Boolean isCylinderOrCone (const TopoDS_Face& theHollowCylinder,
{ {
aCirclesNb++; aCirclesNb++;
isCylinder = Standard_True; isCylinder = Standard_True;
aPos[aCirclesNb - 1] = anAdaptor.Circle().Location();
if (aCirclesNb == 2) if (aCirclesNb == 2)
{ {
// Reverse the direction of the cylinder, relevant if the cylinder was created as a prism break;
if (aPos.IsEqual (theLocation, Precision::Confusion())) }
}
}
switch (aCirclesNb)
{ {
theDirection.Reverse(); case 2:
{
if (!aPos[0].IsEqual (aPos[1], Precision::Confusion()))
{
theDirection = gp_Dir(aPos[1].XYZ() - aPos[0].XYZ());
} }
return Standard_True; Standard_FALLTHROUGH;
} }
aPos = anAdaptor.Circle().Location().XYZ(); 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)) else if (Handle(Geom_ConicalSurface) aGeomCone = Handle(Geom_ConicalSurface)::DownCast (aSurf))
{ {
gp_Dir aDummyDir; 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 gp_Cone aCone = BRepAdaptor_Surface (theFace).Cone();
const Standard_Real aRad1 = aCone.RefRadius(); 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)) else if (Handle(Geom_CylindricalSurface) aGeomCyl = Handle(Geom_CylindricalSurface)::DownCast (aSurf))
{ {
const gp_Cylinder aCyl = BRepAdaptor_Surface (theFace).Cylinder(); const gp_Cylinder aCyl = BRepAdaptor_Surface (theFace).Cylinder();
gp_Ax3 aPos = aCyl.Position(); gp_Pnt aPos = aCyl.Position().Location();
gp_Dir aDirection = aPos.Direction(); 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 aRad = aCyl.Radius();
const Standard_Real aHeight = getCylinderHeight (aTriangulation, aLoc); const Standard_Real aHeight = getCylinderHeight (aTriangulation, aLoc);
gp_Trsf aTrsf; gp_Trsf aTrsf;
aPos.SetDirection (aDirection); aTrsf.SetTransformation (gp_Ax3 (aPos, aDirection), gp::XOY());
aTrsf.SetTransformation (aPos, gp::XOY());
Handle(Select3D_SensitiveCylinder) aSensSCyl = new Select3D_SensitiveCylinder (theOwner, aRad, aRad, aHeight, aTrsf, true); Handle(Select3D_SensitiveCylinder) aSensSCyl = new Select3D_SensitiveCylinder (theOwner, aRad, aRad, aHeight, aTrsf, true);
theSensitiveList.Append (aSensSCyl); theSensitiveList.Append (aSensSCyl);

21
tests/v3d/bugs/bug33664 Normal file
View File

@ -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