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?
Discussion
9 archived replies
Posts are displayed in their archived order.
01Commenter-1
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,
Commenter-1.
02Author
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?
03Commenter-1
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,
Commenter-1
04Author
Sorry, I mean TopoDS_Shape.Location(). It exits and I use it a lot. MFC sample also use this function.
05Commenter-1
Hi,
You can see BRepBuilderAPI_Transform.cxx,and you'll find it use TopoDS_Shape.Moved().
06Commenter-2
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);
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.
08Commenter-3
Hi,
Can Anybody help me in erasing background object when I move object on mouse move event
09Commenter-4
In your CView class, add to the method OnDraw the following code :
myView->Redraw();