how to get global position of AIS_Shape?

TopLoc_Location originalLocation = myAIS_TopoDSshape.Location() just returns null TopLoc_Location.

Is there a reason or another way to get global position?

Sathiya nathan's picture

You can try to get location from the Context.

john wick's picture

don't know why this is happening, there is no selected shape from context manager and the location of the AIS_Shape I imputed return NULL from the context manager as well.


but my mouse clicking the AIS highlights it just fine.

Kirill Gavrilov's picture

Why you expect location to be non-identity? Have you set it to the object? Share your code then.

john wick's picture

I think I found the problem for identity location. It is because BRepBuilderAPI_Transform does not "move" the object by calling “Move()”, instead it calls “Moved()”. That is the reason why object's location is just identity .

However, the AIS_Shape's location gotten from “InteractiveContext()->Location(this)” is still identity, I have to call
“myShape->Location()” to get the actual global location.

After some testing, like moving the object, that I concluded that class object myTransformation just records the local tranformation from which the shape
originates (from its parent). If you don't move the shape you get 0,0,0 in position, if you moved the shape then you get a non-zero position.

Just like in the image (which I cannot place right here) of a object placed initially at non-origin position. zero value position returns no matter, and none zero value appear only after I have moved the object in User Interface with my mouse.

TopoDS_Compound m_walls1;
BRep_Builder().Add(m_walls1, m_walls); // m_walls1 is a compound that has its own location initialized to zero, so we need to set the coordinate
(some reason I cannot insert image right here on forum)
// transform the object
gp_Trsf M;
M.SetTranslation(gp_Pnt(), gp_Pnt(position_in_view.x(), position_in_view.y(), position_in_view.z()));

// problem lies below
BRepBuilderAPI_Transform BRepTrsf5(M);

Kirill Gavrilov's picture

It is because BRepBuilderAPI_Transform does not "move" the object

BRepBuilderAPI_Transform / BRepBuilderAPI_GTransform are designed to handle complex transformations that should be propagated to geometry. If you would like to assign location without modifying geometry - just use related methods of TopoDS_Shape itself.

Sathiya nathan's picture

I would suggest instead of translating the whole compound TopDs_Shape to certain location. You can set location on AIS_Shape. It would work much faster and you can get location using Context as you expect.