Simple object transformations

I need to perform very simple task: to transform selected objects.
Transformations include:
1. move
2. rotate around location
3. uniform scale

In my code i've used following commands:
For translation and scale:
AISContext->Current()->SetLocation(TopLoc_Location(t) * AISContext->Current()->Location());
and a bit more involved for rotation to make it rotate around shape location and not around coordinate center.

The problem is that after setting location, object's selection boundary stays the same as before transformation... that is if i move object to some point, to select/deselect/highlight it again i need to move mouse cursor to the position where it was before moving...

As far as i understand if i want to just transform original shape location and not make a copy of it i need use Location routine and not BRepBuilderAPI_Transform. I also tried to use SetTransform of interactive object but it gives me the same results as SetLocation.

Spent 2 days already on this and still no luck...

Stephane Routelous's picture

did you try the AIS_InteractiveContext::SetLocation instead of the AIS_InteractiveObject one ?
AISContext->SetLocation(AISContext->Current(),TopLoc_Location(t) * AISContext->Current()->Location());

Stephane

devast's picture

tried both:

1. AISContext->Current()->SetLocation(TopLoc_Location(t) * AISContext->Current()->Location());
2. AISContext->SetLocation(AISContext->Current(), TopLoc_Location(t) * AISContext->Current()->Location());

same results

devast's picture

so no any assumptions?
i don't see any apllication of Location stuff if it is working this way, 'cos these simple transforms are very common to any editor.

Pawel's picture

Hi devast,

I'm not sure why it setting location doesn't work in your case. What I do is modifying the underlying TopoDS_Shape and the reassigning/recomputing the presentation. Something like this:

Handle_AIS_Shape anIS = Handle_AIS_Shape::DownCast(aisShape);
anIS->Set(topoShape);
anIS->Redisplay();

Maybe it works for you...

Pawel

devast's picture

Location call is not really dont work at all. It works but with a strange behavior. As i described in the first post after i apply Location change, shape itself moves, but to SELECT it again i must move mouse cursor to PREVIOUS position, that is rendering representation updates while selection representation not!

I've tried your suggestion about changing shape itself

Handle_AIS_Shape aAS = Handle(AIS_Shape)::DownCast(AISContext->Current());
TopoDS_Shape shape = aAS->Shape();
shape.Move(TopLoc_Location(t));
aAS->Set(shape);
aAS->Redisplay();

but got the same results.... BUT!

After few minutes i discovered very interesting thing. If i use this approach AND do any change to the view (pan/rotate/zoom) everything works ok! I.e. to select the transformed shape i click on the TRANSFORMED shape not on the place where it WAS!

"HA!" i thought.. now i can just apply any view transformation in the code and it'll work! I made
Pan(1,1);Pan(-1,-1);
transformation and to my surprise... it DIDNT worked... it only works if i call transformation that is not identity in the sum, i.e. just Pan(1,1) for example... i dont have any reasonable explanation of what is going on...

Again i stopped on a dirty hack solution:
static bool flag = false;
if (flag = !flag) Pan(1, 0);
else Pan(-1, 0);
I call this routine after transformation and *seems* it works (at least i haven't found a bug _yet_).

To summarize im getting very frustrated with OCC... if such a very simple task is solved in this way what awaits me ahead....

Pawel's picture

have you tried updating the view after applying the new location?

devast's picture

tried:
view->Redraw();
and/or
view->Update();

also:
AISContext->UpdateCurrentViewer();

as you may guess no results... (usually i dont post on the forum if there is something i can try myself, this time i tried everything i know and even more...)

Stephane Routelous's picture

maybe using
ais_interactiveobject::SetTransformation, UpdateLocation, UpdateSelection (from SelectMgr_SelectableObject)

Stephane

devast's picture

tried:
AISContext->Current()->SetTransformation(new Geom_Transformation(t), true, false);
AISContext->Current()->UpdateSelection();

and as you may guess.. same results! doesnt work properly without above posted hack.

also strange thing about SetTransformation:
AISContext->Current()->SetTransformation(new Geom_Transformation(t), true, true);
(notice last parameter is true) should update selection, but in this form it throws an exception..

UpdateLocation is a private function.

p.s. i found same topic on this forum w/o any solution... seems we are missing something simple or... it's just a plain bug!

devast's picture

is there any occ sample about setting location? i found TopologyTransformations sample, but they use BRepBuilderAPI_Transform there...

Paul Jimenez's picture

Have you tried calling AIS_InteractiveContext::RecomputeSelectionOnly and then AIS_InteractiveContext::Redisplay?

devast's picture

RecomputeSelectionOnly gives me a more weird results, after inserting this call, im not able to select object at all!

after struggling with all the stuff, i've stopped on the following non hack way:

Handle_AIS_Shape aAS = Handle(AIS_Shape)::DownCast(AISContext->Current());
TopoDS_Shape shape = aAS->Shape();

BRepBuilderAPI_Transform aTransform(t);
aTransform.Perform(shape, false); // notice false as second parameter

Handle_AIS_Shape sh = new AIS_Shape(aTransform.Shape());
AISContext->Display(sh, false);

AISContext->Erase(AISContext->Current(), false, false);
AISContext->ClearCurrents();
AISContext->SetSelected(sh, false);

as the doxygen says if i specify false to Perform, no copying will occur and operation will set Location of the shape. And to overcome selection bug, im just creating a new interactive object passing transformed shape to the constructor, and erasing the old one.

Dmitry Khabi's picture

You are not the first, who has this problem:
http://www.opencascade.org/org/forum/thread_16478/
but there is no answer.......

devast's picture

yeah i had found your topic, made this one only 'cos there were no answers.

Marco Balen's picture

Hello Devast,

I have the same problem.
I have tried to change the position of an AIS_InteractiveObject using the function :

MyContext->SetLocation(pObject,TopLoc_Location(GeometryTransformation));

and I get the object correctly positioned but hte selection stay on the old position.

I tried to "Erase", "chacjìge location" and than "Display" the object but the behaviour is always the same.

have you found a solution to this problem ?

Marco Balen's picture

I have done more test and the way proposed by Pavel seems works ok.

I have replaced my code with the new code :

->old
MyContext->SetLocation(pObject,TopLoc_Location(GeometryTransformation));

->new
Handle_AIS_Shape anIS = Handle_AIS_Shape::DownCast(pObject);
TopoDS_Shape shape = anIS->Shape();
shape.Location(TopLoc_Location(TheTrsf));
anIS->Set(shape);
pObject->Redisplay(true);

I hope this solution help someone.

Mathieu's picture

That's good working for me !

Thank you

plbarrio's picture

This works for mi.
1. Unselect
2. Move
2. Select.

I had problems only when LocalContext are opened, and TopoDs_SOLID, with TOPO_DS_Compound i had no problems.

gp_Trsf traslation;
traslation.SetTranslation ( gp_Vec ( gp_Pnt ( x1, y1, z1) , pfin ) );

Handle_AIS_InteractiveObject aisshape = m_Context -> SelectedInteractive();

m_Context->SetSelected ( aisshape, false);
m_Context -> SetLocation ( aisshape , traslation * m_Context -> Location ( anaisshape) ) ;
m_Context -> SetSelected ( aisshape, true);

Christian Haag's picture

Possibly a simpler solution... I tried a lot of things and found that this works the best for me:
AISContext()->Activate(Object);

Younghyo Kim's picture

good. it works for me. thank you.

Handle_AIS_Shape anIS = Handle_AIS_Shape::DownCast(curAISObject);
TopoDS_Shape shape = anIS->Shape();
shape.Location(TopLoc_Location(trsf));
anIS->Set(shape);
curAISObject->Redisplay(true);
myAISContext->Activate(curAISObject);