Selection of face's edges

hi,

i'd like to select some of face's edges in the local context. i prepared the next function, but it doesn't work well. edges are hilighted but when i try to remove some of them by means of the SHIFT mouse selection, they stay selected. is there something wrong in my code?

best regards,
adrian

bool Select_Edge (Handle(AIS_InteractiveContext) &po_AIS_Context, AIS_ListOfInteractive &o_AIS_Objects, TopoDS_Edge &o_Edge, bool b_Update_Display)
{
AIS_ListIteratorOfListOfInteractive o_iterator;

for (o_iterator.Initialize (o_AIS_Objects); o_iterator.More(); o_iterator.Next())
{
if (o_iterator.Value()->IsKind(STANDARD_TYPE(AIS_Shape)))
{
Handle(AIS_Shape) po_shape = Handle(AIS_Shape)::DownCast (o_iterator.Value()); //->Shape();

if (po_shape->HasSelection (2))//TopAbs_EDGE))
{
const Handle(SelectMgr_Selection) &po_selection = po_shape->Selection (2);//TopAbs_EDGE);
for (po_selection->Init (); po_selection->More(); po_selection->Next())
{
const Handle(SelectBasics_SensitiveEntity) &po_sel_entity = po_selection->Sensitive ();

const Handle(SelectBasics_EntityOwner) &po_basic_owner = po_sel_entity->OwnerId();

DeclareAndCast (SelectMgr_EntityOwner, po_mgr_owner, po_basic_owner);

const TopoDS_Shape &o_owner_shape = ((Handle(StdSelect_BRepOwner)&)po_mgr_owner)->Shape();

if (o_owner_shape.ShapeType()== TopAbs_EDGE)
{
const TopoDS_Edge &o_edge = TopoDS::Edge(o_owner_shape);

if (o_edge.IsSame (o_Edge))
{

const Handle(AIS_Selection) &po_cur_ais_selection = AIS_Selection::CurrentSelection();

po_cur_ais_selection->Select (po_mgr_owner);

if (po_AIS_Context->HasOpenedContext())
po_AIS_Context->HilightSelected (b_Update_Display);
else
po_AIS_Context->HilightCurrents (b_Update_Display);

return true;
}
}
}
}
}
}

return false;
}

a-helcman's picture

IS IT A KIND OF PSYCHO DISEASE TO REPLY TO MYSELF?
HERE IS THE SOLUTION:
const Handle(AIS_Selection) &po_cur_ais_selection = AIS_Selection::CurrentSelection();
po_mgr_owner->State (-1); //<=========== NEW LINE
po_cur_ais_selection->Select (po_mgr_owner);

Hugues's picture

Hi Adrian,

I'm really interested by your function 'Select_Edge'. What I would like to achieve is to select programmatically topological edges and faces of a loaded CAD model.
I think if you can select edges, faces is pretty the same.
Can you explain how your function works? At least the arguments of the function. What is the 2nd argument (o_AIS_Objects) for?

Have you already tried to use AIS_InteractiveContext::AddOrRemoveSelected (const TopoDS_Shape& aShape)? I can't get it to work, however I set up correctly a local context to burst the CAD model into edges, so that they are selectable by the user.

Thanks for your explanations.

a-helcman's picture

hi hugues,

first, i have to say that the function doesn't work 100% (...improvement is on the way...). i have problem to unselect neighbour edges under some conditions. but perhaps this will not disturb you.
yes, i have tried to use also addorremoveselected function. result was not better than with the current solution. it's possible that i did not use it in a correct way (??).
o_AIS_Objects - list of ais objects to be scanned for an edge containment. for obtaining the list of all interactive objects, use the next lines:
AIS_ListOfInteractive o_list_of_io;
po_AIS_Context->DisplayedObjects (o_list_of_io);
algo:
- for each interactive object scan all selectable edges. if the selectable edge points to o_Edge, the edge is selected and hilighted.

best regards,
adrian

Hugues's picture

Adrian, thanks for your enlightenments.
I will try your "Select_Edge" function in the next couple of days, as this AddOrRemoveSelected function does not work. I've already asked about the way to use this function in the OCC forum, but nobody seems to know how to.

At first glance, I am a bit afraid by your function, it has to scan the whole model to select one of the edge, it may become slow rapidely.
Please do not hesitate to post here improvements made on your "Select_Edge" function. It will give help to anybody who wants to achieve the same thing (especially me).

Hugues's picture

Hi Adrian,
I have tested your function, it works fine(i.e. edges are selected) but there are some edges that can't be unselected in shift select mode(even with your patch ...->State(-1)). Did you improve your function? Do you have news about it?

Best regards.

Svetlozar Kostadinov's picture

I've tried a solution very close to given above and I can confirm that the selected edges cannot be unselected. Does somebody know a solution or workarround for this issue?

Greetings