Can't change location of shape correctly

TopoDS_Shape shape = myAisShape->Shape();
myContext()->Remove(myAisShape, true);

gp_Trsf trsf = myAisShape->Transformation();

Standard_Real x = ui->xSpinBox->value();
Standard_Real y = ui->ySpinBox->value();
Standard_Real z = ui->zSpinBox->value();

trsf.SetTranslationPart(gp_Vec(x,y,z));

BRepBuilderAPI_Transform transform(shape, trsf, false);
transform.Build();
shape = transform.Shape();

AIS_Shape *aisShape = new AIS_Shape(shape);
aisShape->SetLocalTransformation(shape.Location().Transformation());

myContext()->Display(aisShape, true);

I really cannot understand why this isn't work as excepted modified shapes relocated somewhere other than given coordinates and also losses rotation sometimes need help.

Kirill Gavrilov's picture
AIS_Shape *aisShape = new AIS_Shape(shape);
aisShape->SetLocalTransformation(shape.Location().Transformation());

here you are applying transformation twice - as assigned to TopoDS_Shape and as additional local transformation of AIS_Shape. It makes sense applying transformation either to TopoDS_Shape (in this case AIS_Shape could have identity transformation) or to AIS_Shape (in this case TopoDS_Shape should have identity location).

AIS_Shape *aisShape = new AIS_Shape(shape);

This code is dangerous and might lead to memory leaks. It is better always using Handles (e.g. Handle(AIS_Shape)) instead of raw pointers for any objects inheriting Standard_Transient (which is majority of classes in OCCT).

Semih Ufuk Güler's picture

Thank you for your fast reply,

Unfortunately result is still incorrect.