Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics
 

Simple object transformations

Simple object transformations
devast 2009/06/25 15:48
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 2009/06/25 16:03
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 2009/06/25 16:21
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 2009/06/27 14:38
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 2009/06/27 15:01
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 2009/06/27 19:09
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 2009/06/27 20:03
have you tried updating the view after applying the new location?
devast 2009/06/27 21:26
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 2009/06/27 22:17
maybe using
ais_interactiveobject::SetTransformation, UpdateLocation, UpdateSelection (from SelectMgr_SelectableObject)

Stephane
devast 2009/06/27 22:55
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 2009/06/27 21:29
is there any occ sample about setting location? i found TopologyTransformations sample, but they use BRepBuilderAPI_Transform there...
Paul Jimenez 2009/06/29 07:49
Have you tried calling AIS_InteractiveContext::RecomputeSelectionOnly and then AIS_InteractiveContext::Redisplay?
devast 2009/06/29 08:23
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 2009/06/29 08:38
You are not the first, who has this problem:
http://www.opencascade.org/org/forum/thread_16478/
but there is no answer.......
devast 2009/06/29 08:46
yeah i had found your topic, made this one only 'cos there were no answers.
Giglietti Antonio 2010/01/07 18:23
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 ?

Giglietti Antonio 2010/01/08 16:29
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 2010/03/17 16:27
That's good working for me !

Thank you
plbarrio 2010/05/27 16:56
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 2013/05/13 18:19
Possibly a simpler solution... I tried a lot of things and found that this works the best for me:
AISContext()->Activate(Object);
Younghyo Kim 2014/08/01 06:40
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);

 
 
Latest news
  • OCCT Applications
  • Open CASCADE Technology 6.8.0 is available for download!
  • New features to enhance the development process

  • © OPEN CASCADE 2000 - 2014  |  Search  |  Contacts   |  Site map