Move AIS_Shape with Mouse

Hi, everybody:

Now my code can move AIS_Shape with Mouse, but one important deficiency is the `move' is not persisted. I use the following code:

//handler for WM_MOUSEMOVE:
gp_Trsf trsf;
trsf.SetTranslation(oldPnt, newPnt);

// m_hSelected is a Handle_AIS_Shape
hAISContext->SetLocation(m_hSelected, trsf);
hAISContext->Redisplay(m_hSelected);

this code can move AIS_Shape with mouse correctly, but next I try to move the same AIS_Shape, it will return to original location and then move starting from there!

So I add code to change the underlying TopoDS_Shape and reset this shape to AIS_Shape.
But I didn't know how can I synchronize two TopLoc_Location for both AIS_Shape & TopoDS_Shape, i.e. if I use m_hSelected->Location() as Location of associated TopoDS_Shape, it will be placed on a strange position. Could someone help me?

angel's picture

Hi,
Maybe you can use the code like as following:
//handler for WM_MOUSEMOVE:
gp_Trsf trsf;
trsf.SetTranslation(oldPnt, newPnt);
// m_hSelected is a Handle_AIS_Shape
aShape=m_hSelected ->Shape();
BRepBuilderAPI_Transform myTrsf(aShape,trsf,Standard_False);
aShape= myTrsf.Shape();
m_hSelected->Set(aShape);
hAISContext->Redisplay(m_hSelected);

Good luck,
Angel.

fhchina's picture

Thank you Angel. Now my code can run.

But I want to know more. My first code uses TopoDS_Shape::SetLocation(), it gaves incorrect result. And If I change BRepBuilderAPI_Transform to SetLocation, it is also wrong.

But OCC Sample often use SetLocation, I want to know when to use BRepBuilderAPI_Transform and when to use SetLocation?

angel's picture

Hi,
There is no TopoDS_Shape::SetLocation()and only has AIS_InteractiveContext::SetLocation. It mean you just only modify graphic representation but TopoDS is still in the original position.

Sincerely,
Angel

fhchina's picture

Sorry, I mean TopoDS_Shape.Location(). It exits and I use it a lot. MFC sample also use this function.

angel's picture

Hi,
You can see BRepBuilderAPI_Transform.cxx,and you'll find it use TopoDS_Shape.Moved().

DU's picture

Hi, Angel,

I think your code could be changed for the better if using the followed method.

gp_Trsf trsf;
trsf.SetTranslation(oldPnt, newPnt);
// m_hSelected is a Handle_AIS_Shape
aShape=m_hSelected ->Shape();
//BRepBuilderAPI_Transform myTrsf(aShape,trsf,Standard_False);

// aShape= myTrsf.Shape();
aShape.Location(trsf); m_hSelected->Set(aShape);
hAISContext->Redisplay(m_hSelected);

fhchina's picture

Hi, Du,

Sorry, I am afraid this code will not work as imagine.

In fact, after reading Angle's post, I first change my code just like yours, but there will be more modification for oldPnt & newPnt, one must commit this change in WM_LBUTTONUP handler, etc. Much more consideration.

I think Angel's method is the easiest way, at least in my code.

But I still a question, i.e. the difference between TopoDS_Shape.Location & BRepBuilderAPI_Transform.

a's picture

Hi,
Can Anybody help me in erasing background object when I move object on mouse move event

ekiroglu's picture

In your CView class, add to the method OnDraw the following code :
myView->Redraw();