For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

programmatically set selection of multiple shapes

Peter Zbinden's picture
Forums: 

Hello,
I'm an OCC Newbie and try to select programmatically an AIS_Shape. If I only select one shape, it works. If I try to select more than one shape, only the last selected is marked as selected in the viewer. (multiple selection with the mouse works)

loop over a list of shapes
{
AisContext->SetSelected(aAisShape);
}
How can I select multiple shapes?
Can anyone help me? Thanks in advance.
Peter

int's picture

Hello. I have the same problem. I also would like to know the solution.

Yuriy Sinithin's picture

Hi! It's work for me when I select group.
Try next code:

void objectView::tryToSelectGroup()
{
Handle_TPrsStd_AISPresentation CurrentPrs;

if ((!CurrentHighLightedLabels.IsEmpty())&&(!nowSelectedLabels.IsEmpty())) //Ïîïûòàþñü îáëåã÷èòü âûäåëåíèå.
{
for (TDF_ListIteratorOfLabelList itneed(CurrentHighLightedLabels); itneed.More(); itneed.Next())
{
for (TDF_ListIteratorOfLabelList itnow(nowSelectedLabels); itnow.More(); itnow.Next())
{
if (itnow.Value()==itneed.Value())
{
nowSelectedLabels.Remove(itnow);
break;
}
}
}
}

if (!nowSelectedLabels.IsEmpty()) //Óæå âûäåëåííûå ìåòêè
{
for (TDF_ListIteratorOfLabelList it(nowSelectedLabels); it.More(); it.Next())
{
if (!it.Value().FindAttribute(TPrsStd_AISPresentation::GetID(),CurrentPrs)) continue;
if (myContext->IsSelected(CurrentPrs->GetAIS()))
myContext->AddOrRemoveSelected(CurrentPrs->GetAIS());
}
nowSelectedLabels.Clear();
}

if (!CurrentHighLightedLabels.IsEmpty()) //Ìåòêè, êîòîðûå íóæíî âûäåëèòü
{
for (TDF_ListIteratorOfLabelList it(CurrentHighLightedLabels); it.More(); it.Next())
{
if (!it.Value().FindAttribute(TPrsStd_AISPresentation::GetID(),CurrentPrs)) continue;
if (!myContext->IsSelected(CurrentPrs->GetAIS()))
myContext->AddOrRemoveSelected(CurrentPrs->GetAIS());

nowSelectedLabels.Append(it.Value());
}
}
else
myContext->Select(); //Åñëè íè÷åãî íåò âûäåëåííîãî, òîãäà ïðîñòî ñíèìàþ âûäåëåíèÿ
}

int's picture

Thank you! I understand.

int's picture

Although no. That is my problem:

//----------
cAISContext->OpenLocalContext();
cAISContext->OpenLocalContext();
cAISContext->CloseLocalContext();

Handle_AIS_Shape S1 = new AIS_Shape(BRepPrimAPI_MakeBox(gp_Pnt(0,0,0), 1,1,1));
cAISContext->Display(S1, 1);

cAISContext->AddOrRemoveSelected(S1, 1);

Standard_Boolean b = cAISContext->IsSelected(S1);
// b == 0 // cAISContext->SetSelected(S1) works correctly in this case
//----------

 îáùåì â ëîêàëüíîì êîíòåêñòå ïîñëå îòêðûòèÿ è çàêðûòèÿ äðóãîãî êîíòåêñòà SetSelected() ðàáîòàåò ïðàâèëüíî, à ïîñëå AddOrRemoveSelected() îáúåêò âûäåëÿåòñÿ òîëüêî ïîñëå ïîäâåäåíèÿ ìûøêè ê íåìó. Íå ïîéìó ïî÷åìó òàê.

Yuriy Sinithin's picture

Âîò è îòëè÷íî. ß â OCAF ñäåëàë ìåòêó ñ äðàéâåðîì Group. íà âòîðîé óðîâåíü çàøèâàþ èìåíà âñåõ îáúåêòîâ, êîòîðûå âõîäÿò â ãðóïïó. À äëÿ îáúåêòîâ, âõîäÿùèõ â ãðóïïó íà òðåòüåì óðîâíå çàøèâàþ èìÿ ãðóïïû. Ïîëó÷èëîñü íå ïëîõî. Ó ìåíÿ íåò ïðîáëåì ñ âûäåëåíèÿìè.

P.S. Ðàä âñòðå÷å ñ ðóññêîÿçû÷íûì ïîëüçîâàòåëåì ! Óäà÷è â ðàçðàáîòêàõ.

Yuriy Sinithin's picture

int. à êàê ïðîèñõîäèò âûäåëåíèå, èç êàêîãî-òî äèàëîãîâîãî îêíà ??? ìîæåò áûòü ýòî âèäæåòû ïàðÿò. Ïîñëå âûäåëåíèÿ íóæíî îáÿçàòåëüíî îáíîâèòü âüþâåð â ýòîì ñëó÷àå.

Åñëè äîáàâèòü îáúåêòû â TDF_LabelList òî ïîòîì ìîæíî èõ âñåõ îòðàáîòàòü, âûäåëèòü èëè ñíÿòü âûäåëåíèå... íî îïÿòü æå ïîñëå ýòîãî íóæíî îáíîâèòü âüþâåð. â ìîåì ïðèìåðå âñå ýòî íàãëÿäíî ïîêàçàíî

P Dolbey's picture

Please refer to lanuage policy on the very first post on this forum

http://www.opencascade.org/org/forum/thread_1

pete

Yuriy Sinithin's picture

ok!

int's picture

No, the problem is in the code that I showed above.
I found that if after CloseLocalContext () to add cAISContext->ClearSelected (), then AddOrRemoveSelected () will work correctly. Maybe it's a bug, but maybe my misunderstanding.
------
I never worked with OCAF.
-----
Thank you, I am glad to meet you too!