Selection lost when SetTransformation called

Hi there!

I am trying to move an AIS_Shape when selected with some keys. The problem is that when SetTransformation is called with the new transformation matrix, the selection is lost and I have to select the object again to be able to move it again.

Is there any flag I should activate, any selection mode?

I am using OCC 6.5.1.

Thank you very much!

m.costa's picture

I am working with an old, fragile code base and I don't know OpenCASCADE very well.
Is this the default behaviour? Or may I look for a change on the default behaviour?

Can anyone help me, please?

planetdhxy's picture

these codes worked .

gp_Pnt CtestsdiView::to3DPoint(const CPoint & point)
{
V3d_Coordinate XEye,YEye,ZEye,XAt,YAt,ZAt;
m_3dView->Eye(XEye,YEye,ZEye);
m_3dView->At(XAt,YAt,ZAt);
gp_Pnt EyePoint(XEye,YEye,ZEye);
gp_Pnt AtPoint(XAt,YAt,ZAt);
gp_Vec EyeVector(EyePoint,AtPoint);
gp_Dir EyeDir(EyeVector);

gp_Pln PlaneOfTheView=gp_Pln(AtPoint,EyeDir);
Standard_Real X,Y,Z;
m_3dView->Convert(point.x,point.y,X,Y,Z);
gp_Pnt ConvertedPoint(X,Y,Z);
gp_Pnt2d ConvertedPointOnPlane=ProjLib::Project(PlaneOfTheView,ConvertedPoint);
gp_Pnt ResultPoint=ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
return ResultPoint;
}

m_AISInteractiveContext3D->InitSelected();

while (m_AISInteractiveContext3D->MoreSelected())
{Standard_Boolean b=m_AISInteractiveContext3D->HasSelectedShape();
if (1)
{

Handle_AIS_InteractiveObject picked;
picked= m_AISInteractiveContext3D->SelectedInteractive();
Handle(AIS_Shape) aisShape=Handle(AIS_Shape)::DownCast(picked);
TopoDS_Shape ashape= aisShape->Shape();

gp_Pnt gp3d=to3DPoint(point);
CPoint prepoint;
prepoint.x=myXmax;
prepoint.y=myYmax;
gp_Pnt pre_gp3d=to3DPoint(prepoint);

gp_Trsf theTransformation;
gp_Vec theVectorOfTranslation(0,gp3d.Y()-pre_gp3d.Y(),0);
theTransformation.SetTranslation(theVectorOfTranslation);

BRepBuilderAPI_Transform aTransform(theTransformation);

aTransform.Perform(aisShape->Shape());

ashape=aTransform;

aisShape->Set(ashape);
m_AISInteractiveContext3D->Redisplay(aisShape);

}
else
{
Handle_AIS_InteractiveObject aniobj = m_AISInteractiveContext3D->Interactive();
}

m_AISInteractiveContext3D->NextSelected();
}
myXmax=point.x; myYmax=point.y;
}

JuryS's picture

Hi, Marc.
I make the move function of objects for six month and It's working for me, but I really don't understand how you move selected object. With pressed mouse button? Maybe you need another way, before select object and then move mouse and see how this object transformed on the scene?

See samples or type here part of your code.

m.costa's picture

Hi Yuriy,

My test is really simple:

I select the object with the mouse, then I press the keyboard key "A" and I call SetTransformation with the new matrix (with each press I translate the object -5 units on the X axis).

And after the transformation is applied, the object is automatically deselected.

I guess I need to tell OCC to deselect the object, so which function do I need to look for? Is there any parameter to a function (maybe display related) that deselects all the objects?

Thanks.

m.costa's picture

Hi there,

The codebase is too big to post here, and I have no time to create a simple test case, but for the sake of understanding, this is what I am doing:

// Get all the selected entities
AIS_Context->InitSelected ();
while (AIS_Context->MoreSelected ())
{
entity = AIS_Context->SelectedInteractive ();
list_entities.add (entity);
}

for each entity in list_entities
{
// NO OpenCASCADE functions
position = entity->get_position ();
position += Position (-5.f, 0.f, 0.f);

// OpenCASCADE function again
entity->SeTransformation (GetGeomTransformation (posision));
}

AIS_Context->Redraw ();
// Here all the selection is lost, to make more transformations I need to select the entities again...

These are the OpenCASCADE functions I call during the transformation. Is there anything wrong? Do I have to look for a viewer state? Do I do anything wrong (maybe with contexts, setting the transformation, redrawing the entities, not redrawing the selection..)?

Since I am new to OpenCASCADE and the codebase is not documented at all, I have no clues.

Thank you for the help!

m.costa's picture

This post: http://www.opencascade.org/org/forum/thread_16772/ leads to a solution:

AIS_Context->SetSelected (entity, Standard_False);
entity->SetTransformation (...);
AIS_Context->SetSelected (entity, Standard_True);

I don't know if this IS the way to go or only a HACK due to a bug on OpenCASCADE. Anyway, I leave it here for anyone who might need it.

m.costa's picture

This only works for single selected objects, though. If you ShiftSelect different objects, only the last one will remain selected.

It seems that SetTransformation resets the "selection status" of the AIS_InteractiveContext. So what should I do? Keep a list of selected objects and select them after each SetTransformation call? Isn't it an OpenCASCADE job to keep the selection updated? Keeping a selected objects list make me replicate the OpenCASCADE selection information only not to lose it when calling SetTransformation.

And if not called, the extra work is totally useless.

m.costa's picture

I have found this thread: http://www.opencascade.org/org/forum/thread_17759/ and with it a solution:

AIS_InteractiveContext->OpenLocalContext ();
entity->SetTransformation (...);
AIS_InteractiveContext->CloseLocalContext ();

Opening a local context prevents the default one reset the selection status/information.