Get back the selection

Hello, I managed to decompose my solid (cube with a hole), on the other hand I wanted to know how I could get back the selection made with the mouse? For make out a will if the selection is a circle for example.
Thank you for your help

Paul Jimenez's picture

AIS_InteractiveContext: Check for methods that deal with LocalContext, Select and Current. It is up to you to decide what is useful for your specific case.

duduch24's picture

The purpose would have been to be able to click the circle and what it shows a pop up to modify the diameter.

Paul Jimenez's picture

Is the circle stored as a Wire or Face? Are you using AIS_Shape to display it? The more information you can give, the easier it is to help you.

duduch24's picture

Here is the function that I used to create my piece :

TopoDS_Shape
MakeBouchon()
{
//The cylinder
gp_Pnt neckLocation(gp_Pnt(30,30,30));
gp_Dir neckNormal = gp::DZ();
gp_Ax2 neckAx2(neckLocation , neckNormal);
TopoDS_Shape aHole = BRepPrimAPI_MakeCylinder(neckAx2,5,40);
//The cube
TopoDS_Shape box = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 60,60 , 60);
//Cube - Cylinder
TopoDS_Shape result = BRepAlgoAPI_Cut(box,aHole);
//Building the resulting compound
TopoDS_Compound aRes;
BRep_Builder aBuilder;
aBuilder.MakeCompound (aRes);

aBuilder.Add (aRes, result);
return aRes;
}

Then the display :
TopoDS_Shape aTest=MakeBouchon();
Handle(AIS_Shape) AISBottle=new AIS_Shape(aTest);
getContext()->SetMaterial(AISBottle,Graphic3d_NOM_GOLD);

getContext()->Display(AISBottle, Standard_False);

getContext()->SetCurrentObject(AISBottle,Standard_False);
getContext()->SetDisplayMode(AISBottle,1,Standard_False);
getContext()->CloseAllContexts();
getContext()->OpenLocalContext();

emit selectionChanged();
fitAll();
QApplication::restoreOverrideCursor();

Paul Jimenez's picture

The idea is to use AIS_InteractiveContext::MoveTo when the mouse moves, AIS_InteractiveContext::Select when the user clicks, query for selection of a shape with AIS_InteractiveContext::HasSelectedShape, query the shape with AIS_InteractiveContext::SelectedShape, query the AIS_InteractiveObject with AIS_InteractiveContext::SelectedInteractive, ...

That is enough to get the selection.

Have you checked the samples provided with OpenCASCADE? All the basic stuff is covered there.

duduch24's picture

Thank you, I have to decompose my solid in this way:
getContext()->CloseAllContexts();
getContext()->OpenLocalContext();
getContext()->ActivateStandardMode(TopAbs_WIRE);
But when I click my circle it selects me all the same all my solid.

zhangzhigang824's picture

Hello,
Add the follow code, have a try, good luck!

Handle(AIS_TypeFilter) filter= new AIS_TypeFilter(AIS_KOI_Object );
Handle(AIS_TypeFilter) filter1= new AIS_TypeFilter(AIS_KOI_Datum );
Handle(AIS_TypeFilter) filter2= new AIS_TypeFilter(AIS_KOI_Shape );
Handle(AIS_TypeFilter) filter3= new AIS_TypeFilter(AIS_KOI_Relation);
Handle(AIS_TypeFilter) filter4= new AIS_TypeFilter(AIS_KOI_None );

m_hContext->AddFilter(filter);
m_hContext->AddFilter(filter1);
m_hContext->AddFilter(filter2);
m_hContext->AddFilter(filter3);
m_hContext->AddFilter(filter4);

Thanks!

duduch24's picture

I shall have wanted to know how to make out a will if the selection is a circle and if yes to show a popup

Thanks

zhangzhigang824's picture

Hi,

Firstly, you need add selection filter for the AIS_InteractiveContext, and then you can select an Edge of a Solid.
When you get the Edge Shape, the follow step is:

//m_selectShape is the Edge you select
if (m_selectShape.ShapeType() == TopAbs_Edge)
{
TopoDS_Edge edgeShape = TopoDS::Edge(m_selectShape);
Standard_Real first = 0, last = 0;
Handle_Geom_Curve curve = BRep_Tool::Curve(edgeShape,first,last);
if (curve->IsKind("Geom_Circle"))
{
MessageBox("You have selected a circle");
}
}

duduch24's picture

Thanks but how i convert context->Current() in shape ?

Paul Jimenez's picture

AIS_InteractiveContext::SelectedShape should give you what you want.

duduch24's picture

I've tried this code but I have many errors when i compile. Have you tried this code ?