Visualization about Filter(Help)

Hi all:
When the mouse cursor moves over objects. I only hope to pick up(highlight)object(like compound). I have used
Handle(StdSelect_ShapeTypeFilter) Filter = new StdSelect_ShapeTypeFilter(TopAbs_COMPOUND);
Handle(SelectMgr_Filter) aFilter = Filter;
GetDocument()->GetAISContext()-AddFilter(aFilter);
GetDocument()->GetAISContext()-MoveTo(x,y,myView);

It doesn't work. It still highlights all objects. Does anyone know about this? I am very appreciated your help.

Sincerely shawn

Sergey RUIN's picture

Hi Shawn,

Try this way:

GetDocument()->GetAISContext()->OpenLocalContext(); GetDocument()->GetAISContext()->ActivateStandardMode(TopAbs_COMPOUND);

GetDocument()->GetAISContext()->MoveTo(x,y,myView);

Best Regards

Sergey

Shawn Yang's picture

Dear Sergey : Thanks a lot. I just wonder how about Filter. Do you know when I can use them? It seems there is no difference between in neutral point and in local context. What is the definition of neutral point? Becasue I saw your answer and it works I get confused.

sincerely shawn

Sergey RUIN's picture

Dear Shawn,

The neutral point may be defined as a state of Interactive context when there is no opened Local contexts, in the neutral point you can select only InteractiveObject itself.

Concerning filters, they mostly used in Local contexts. (There are some that can be used in neutral point, like AIS_TypeFilter). When you open Local Context nothing can be selected, you need to activate some or all InteractiveObjects in defined mode of selection (look AIS_Shape for diffirent modes of shape selection). Activation means that sensitive entities are calculated and loaded in ViewerSelector. Now you have to add filters. Every filter has method IsOk(SensitiveEntity). On command MoveTo(X,Y) ViewerSelector searches for all sensitive entities that can be picked for point (X,Y). Every found sensitive entity is given to a filter using method IsOk() and if the filter returns True that entity is considered selected and shape associated with it is hilighted.

I hope my explanation was clear enough...

Best Regards

Sergey

Shawn Yang's picture

Dear Sergey :
I spent more time to test what you said. If I insist on only selecting COMPOUND in neutral point. Is there any way I can do
Because :
If I want to make a new compound that is combined with one compound(basis) and plus other objects. The basis compound is composed by several objects(including FACE or COMPOUND). If I use in local context. It will cause highlight object(COMPOUND) in basis compound. Thank you.

sincerely shawn

Sergey RUIN's picture

Dear Shawn,

You can look in a source code of AIS_TypeFilter, this filter can be used in neutral point. You just need implement your own filter class in fashion of AIS_TypeFilter. As you can see there is downcasting to AIS_InteractiveObject, you may try to downcast to AIS_Shape and if handle is not null get from it TopoDS_Shape (method Shape of AIS_Shape) and check a type of that shape to find out whether that shape is COMPOUND. By default when you use method Display in AIS_InteractiveContext the context activates InteractiveObject in the default selection mode, for AIS_Shape it equals 0, that is the shape itself without decomposition.

Best Regards

Sergey RUIN

Shawn Yang's picture

Dear Sergey: Thank you very much. Actually, I don't have any idea to implement my own filter class in fashion of AIS_TypeFilter. I have saw source code. But, I don't know how to apply it. Would you mind giving me hint to deal with it? Thanks, again.

sincerely shawn

Sergey RUIN's picture

The method IsOk of your filter could be like this:

Standard_Boolean AIS_TypeFilter::IsOk(const Handle(SelectMgr_EntityOwner)& anObj) const {

Handle(AIS_Shape) anIO = Handle(AIS_Shape)::DownCast(anObj->Selectable());

if(!anIO.IsNull() && anIO->Shape().ShapeType() == TopAbs_COMPOUND) return Standard_True;

return Standard_False; }

Shawn Yang's picture

Dear Sergey:
I have tried it. But, I couldn't go through. This is I done as following:
In AIS_TypeFilter.cxx(All code)
#include AIS_TypeFilter.ixx
#include AIS_InteractiveObject.hxx

AIS_TypeFilter::AIS_TypeFilter(const AIS_KindOfInteractive TheKind): myKind(TheKind){}

Standard_Boolean AIS_TypeFilter::IsOk(const Handle(SelectMgr_EntityOwner)& anObj) const {

Handle(AIS_Shape) anIO = Handle(AIS_Shape)::DownCast(anObj->Selectable());
if (!anIO.IsNull() && anIO->Shape().ShapeType() == TopoAbs_COMPOUND)
return Standard_True;
return Standard_False }

In my program:
Handle (AIS_TypeFilter) ComFilter = new AIS_TypeFilter(TopAbs_COMPOUND);
GetDocument()->GetAISContext()->AddFilter(ComFilter);
GetDocument()->GetAISContext()->MoveTo(x,y,myView);

Build the program:
Error C2664: '__thiscall AIS_TypeFilter::AIS_TypeFilter(const enum AIS_KindOfInteractive)' : cannot convert parameter 1 from 'enum TopAbs_ShapeEnum' to 'const enum AIS_KindOfInteractive'

Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)

I know what wrong with it. But, I don't have any ideal to deal with it. I have tried read about AIS_KindOfInteractive. Is it relative to AIS_KOI_Object? I don't know how to use AIS_KOI_Object passing parameter to AIS_TypeFilter. Thank you very much for your help.

sincerely shawn

Sergey RUIN's picture

Hi Shawn,

If you are going on the way of changing of existent AIS_TypeFilter instead of creation of new class you will loose the functionality of TypeFilter. Nevertheless, to make it work you need pass in constructor AIS_KOI_Shape. Don't forget add #include AIS_KindOfInteractive.hxx

Best Regards

Sergey

Shawn Yang's picture

Dear Sergey:
I am a little bit of confused. Where I can put new clss(IsOk) for myown. Is it in AIS_TypeFilter. The AIS_TypeFilter already have had IsOk function.
I have another question. When I use the codes as following :
GetDocument()->GetAISContext()->OpenLocalContext();
GetDocument()->GetAISContext()->ActivateStandardMode(TopAbs_COMPOUND);
GetDocument()->GetAISContext()->MoveTo(x,y,myView);

Then,
GetDocument()->GetAISContext()->Select();
BRep_Builder builder; //create empty compound
TopoDS_Compound Comp;
builder.MakeCompound(Comp);
builder.Add(Comp,GetDocument()->GetAISContext()->SelectedShape());
I always failed at builder.Add.....
At another place I get errors, as well. I think it is same as the above error.
Handle(AIS_InteractiveObject) picked;
picked = GetDocument()->GetAISContext()->Current();
TopoDS_Shape aShape = Handle(AIS_Shape)::DownCast(picked)->Shape();
I failed at TopoDS_Shape.....
If I didn't downcast to TopoDS_Shape(just ignore). The program is fine. How can get TopoDS_Shape when I selected based on OCAF? I don't use Label, Name..... so far. Thank you very much.

Sergey RUIN's picture

Hi Shawn,

>I am a little bit of confused. Where I can put new clss(IsOk) for myown. Is it in

>AIS_TypeFilter. The AIS_TypeFilter already have had IsOk function.

You need to create new class that inherits class Filter from SelectMgr and redefine its method IsOk

>I have another question. When I use the codes as following :

>GetDocument()->GetAISContext()->OpenLocalContext();

>GetDocument()->GetAISContext()->ActivateStandardMode(TopAbs_COMPOUND);

>GetDocument()->GetAISContext()->MoveTo(x,y,myView);

>Then,

>GetDocument()->GetAISContext()->Select();

>BRep_Builder builder; //create empty compound

>TopoDS_Compound Comp;

>builder.MakeCompound(Comp);

>builder.Add(Comp,GetDocument()->GetAISContext()->SelectedShape());
>I always failed at builder.Add.....

there should be something like this:

for(myCtx->InitSelected(); myCtx->MoreSelected();

myCtx->NextSelected()) {

if(myCtx.HasSelectedShape())

builder.Add(myCtx->SelectedShape()); } where myCtx is a pointer to AIS_InteractiveContext That is only when Local Context is open.

>At another place I get errors, as well. I think it is same as the above error.

>Handle(AIS_InteractiveObject) picked;

>picked = GetDocument()->GetAISContext()->Current();

>TopoDS_Shape aShape = Handle(AIS_Shape)::DownCast(picked)->Shape();
>I failed at TopoDS_Shape.....

>If I didn't downcast to TopoDS_Shape(just ignore). The program is fine. How can get

TopoDS_Shape when I selected based on OCAF? I don't use Label, Name..... so far. Thank

you very much.

The same way as above

for(myCtx->InitCurrent(); myCtx->MoreCurrent(); myCtx->NextCurrent()) { Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(myCtx->Current()); }

That is only for neutral point.

Best Regards

Sergey

Shawn Yang's picture

Dear Sergey:
I have done according your answer except for new class. I am still working on it. Thank you very much.

sincerely shawn