Hi Stephane!
No right to Add a selected shape means that you can't add a previously selected shape, but if it hasn't yet been selected you can add that shape to the selection list.
Best regards
Commenter-1
Archived discussion
Hello,
I have an AIS_InteractiveContext. In this context , I have an AIS_Shape.
I open a local context in face selection mode.
I want in c++ add a face from my object to the current selected list.
How to do that ? I have seen the function :
AIS_InteractiveContext::AddOrRemoveSelected ( me:mutable ; aShape:Shape from TopoDS ; updateviewer : Boolean from Standard=Standard_True);
---Purpose: No right to Add a selected Shape (Internal Management of shape Selection).
-- A Previous selected shape may only be removed.
This function seems to be what I need , but we have no right to use it for Add , just for remove ( but why the name AddOrRemove if we cannot use add `? :-) ).
As somebody an idea ?
Thanks,
Stephane
Discussion
Posts are displayed in their archived order.
Hi Stephane!
No right to Add a selected shape means that you can't add a previously selected shape, but if it hasn't yet been selected you can add that shape to the selection list.
Best regards
Commenter-1
Hello Stephane and Sergey, I just want to provide an example of how to use it. The following code will toggle all displayed objects in the AISContext:
void GUIF_CCVDocument::SelectToggle()
{
AIS_ListOfInteractive Obj_List;
myAISContext->DisplayedObjects(Obj_List);
// create listiterator
AIS_ListIteratorOfListOfInteractive it;
// iterate through all objects
for (it.Initialize(Obj_List); it.More(); it.Next())
{
if (!myAISContext->IsInCollector(it.Value()))
{
if (it.Value()->Type() != AIS_KOI_Datum)
{
if (!myAISContext->HasOpenedContext())
// AISContext is at neutral point
myAISContext->AddOrRemoveCurrentObject(it.Value(),Standard _False);
else
// AISContext has an opened Local Context
myAISContext->AddOrRemoveSelected(it.Value(),Standard_Fals e);
}
}
}
myAISContext->UpdateCurrentViewer();
}
with regards Commenter-2
Hello Michael ,
Thanks, but it is not exactly whant I want. I don't want to work with the AIS_InteractiveObjects from the neutral plane ( without local context ) , but with the sub-shapes of an AIS_Shape ( see my other mail for an example ).
Commenter-3
It is exactly the same except that you use AddOrRemoveCurrentObject in neutral point and AddOrRemoveSelected for local context. It is divided through if ... then in my last example.
best regards Commenter-2
PS: In your code sample: do you see selection of face1 and face2 on the screen ?
No , I don't see anything selected... That is where is my problem ..
Commenter-3
Hi Sergey,
Thanks for the response. I've tried the function in a test programm ( I'm using NT ( visualC++ ) with Cascade 2.1 )
It seems not to work. If you can see what's wrong with my code...
Thanks,
Commenter-3
TopoDS_Shape aBox = BRepAPI_MakeBox(1,1,1);
Handle_AIS_Shape anAISBox = new AIS_Shape(aBox);
anAISBox->SetDisplayMode(AIS_WireFrame);
myAISContext->Display(anAISBox);
myAISContext->OpenLocalContext();
myAISContext->ActivateStandardMode(TopAbs_FACE);
TopExp_Explorer Exp;
Exp.Init(aBox,TopAbs_FACE);
TopoDS_Face theFace1;
TopoDS_Face theFace2;
if ( Exp.More() )
{
theFace1 = TopoDS::Face(Exp.Current());
Exp.Next();
if ( Exp.More() )
{
theFace2 = TopoDS::Face(Exp.Current());
}
}
if ( !theFace1.IsNull() )
{
myAISContext->AddOrRemoveSelected(theFace1);
}
if ( !theFace2.IsNull() )
{
myAISContext->AddOrRemoveSelected(theFace2);
}
myAISContext->InitSelected();
int nb_selected = myAISContext->NbSelected();
cout << "NbSelected = " << nb_selected << endl;
// the output is 0
Hi Stephane!
I'm afraid that I was wrong with AddOrRemoveSelected method, nevertheless I can propose two ways to add a shape to the list of selected shapes.
1. Handle(StdSelect_BRepOwner) BO = new StdSelect_BRepOwner(shape,aisIO, 0, true);
// Where "shape" is shape to be selected, "aisIO" is AIS_InteractiveObject from
// which "shape" was decomposed.
Handle(AIS_Selection) sel = AIS_Selection::CurrentSelection();
sel->Select(BO); // Puts "shape" to the list of selected shapes
myAISContext->HilightSelected(Standard_True);
// Hilighting selected shapes
2. As there is LocalContext open you can create
a temporary AIS_Shape object from TopoDS_Shape
Handle(AIS_Shape) aisShape=new AIS_Shape(shape);
Handle(AIS_TypeFilter) TF=new AIS_TypeFilter(
AIS_KOI_Shape);
if( !ctx->IsSelected(TF) ) {
ctx->AddFilter(TF); // To allow aisShape be selected
ctx->SetSelected(aisShape);
ctx->RemoveFilter(TF);
}
ctx->Hilight(aisShape);
Best regards
Commenter-1
Hi Sergey,
Thanks for your help.
I used the first solution , and it's working fine. BTW, I thought about the second solution ( it is more or less what I'm using in neutral point ), but I thought it's a pity to create a new AIS_Shape for that, because the information is already somewhere.
Commenter-3
Hi Stephane!
If you want you can trade space for speed while making selected TopoDS_Shape.
You can retrieve CurrentSelection from AIS_InteractiveObject (IO), that IO has to be activated in the desired standard selection mode, to have SelectMgr_Selection (S) available. Then, iterating that S you can get SelectBasics_SensitiveEntity from them with method Owner() it's possible to retrieve StdSelect_BRepOwner's (BO) and find, using method Shape of BO, which one contains TopoDS_Shape you want to select.
As use BO to get the TopoDS_Shape selected I wrote in the previous letter. That's all.
Best regards
Commenter-1
hI,
As Hightlight the object,my question is ,if I import a step file and parse the Face,Wire,Edge,Vertext and put them into a TreeCtrl,while I click the Item of TreeCtrl,the chosed object hightlight show by different color.
Do you have any suggestion?could you give me the C++ code to do it?
thanks
Commenter-4.Jiang