How to select an edge or a face of a solid

Hello everyone,

I want to select an edge or a face of a solid.

My code is below:

void setFilter()
{
    Handle(StdSelect_ShapeTypeFilter) solidFilter = new StdSelect_ShapeTypeFilter(TopAbs_SOLID);
	Handle(StdSelect_FaceFilter) faceFilter = new StdSelect_FaceFilter(StdSelect_AnyFace);
	Handle(StdSelect_EdgeFilter) edgeFilter = new StdSelect_EdgeFilter(StdSelect_AnyEdge);
	m_context->AddFilter(solidFilter);
	m_context->AddFilter(faceFilter);
	m_context->AddFilter(edgeFilter);
}

void DrawWidget::createCylinder()
{
	gp_Ax2 axes(gp_Pnt(0,0,0),gp_Dir(0,1,0));
	double r = 50;
	double h = 60;
	double angle = M_PI*1.5;
	TopoDS_Shape topo_cylinder = BRepPrimAPI_MakeCylinder(axes, r, h, angle);
	Handle(AIS_Shape) ais_cylinder = new AIS_Shape(topo_cylinder);
	m_context->Display(ais_cylinder, Standard_True);
	const int aFaceMode = AIS_Shape::SelectionMode(TopAbs_FACE);
	const int aEdgeMode = AIS_Shape::SelectionMode(TopAbs_EDGE);
	m_context->Activate(ais_cylinder, aFaceMode);
	m_context->Activate(ais_cylinder, aEdgeMode);
}

I select edges or faces by upper code, when I move the mouse to the edge or face which will highlight,but the selected result is the whole cylider shape. 

How can I do?Anyone can help me?

Kirill Gavrilov's picture

I select edges or faces by upper code, when I move the mouse to the edge or face which will highlight,but the selected result is the whole cylider shape. 

What do you mean by "selected result is the whole cylinder shape"?
How do you check result?

Note that activating selection of both SOLID and FACE doesn't make sense, as FACE will be always preferred over SOLID
(although you can iterate over picking results <> which will include SOLID).
Draw Harness script doing the similar thing that your C++ code works as expected:

pload MODELING VISUALIZATION
box b 1 2 3
vclear
vinit View1
vdisplay -dispMode 1 b
vfit
vselmode b 2 1
vselmode b 4 1
vselmode b 6 1
vselfilter -clear
vselfilter -type EDGE
vselfilter -type FACE
vselfilter -type SOLID
chao ren's picture

Glad to see your reply.

I've tested your code. It works very well. 

Thank you.I made it.

949657811_149740's picture

can you share your code?