Sat, 11/23/2024 - 21:05
Forums:
I am trying to implement the translation of a box using an AIS_Manipulator in my Qt application and I am encountering several issues.
The first one: after I click on the box to select it, I am assigning the manipulator, but myManipulator->HasActiveMode() is always returning false for some reason.
Here is my code:
void ViewerWidget::init()
{
gp_Ax2 anAxisManipulator;
myManipulator = new AIS_Manipulator(anAxisManipulator);
// No rotation and no scaling
myManipulator->SetPart(0, AIS_ManipulatorMode::AIS_MM_Rotation, Standard_False);
myManipulator->SetPart(1, AIS_ManipulatorMode::AIS_MM_Rotation, Standard_False);
myManipulator->SetPart(2, AIS_ManipulatorMode::AIS_MM_Rotation, Standard_False);
myManipulator->SetPart(0, AIS_ManipulatorMode::AIS_MM_Scaling, Standard_False);
myManipulator->SetPart(1, AIS_ManipulatorMode::AIS_MM_Scaling, Standard_False);
myManipulator->SetPart(2, AIS_ManipulatorMode::AIS_MM_Scaling, Standard_False);
}
// Create the box
void ViewerWidget::makeBox()
{
TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(50.0, 50.0, 50.0).Shape();
Handle(AIS_Shape) anAisBox = new AIS_Shape(aTopoBox);
anAisBox->SetColor(Quantity_NOC_AZURE);
myContext->SetMaterial(anAisBox, Graphic3d_NOM_STONE, Standard_True);
myContext->Display(anAisBox, Standard_True);
}
void ViewerWidget::mousePressEvent(QMouseEvent* event)
{
myContext->MoveTo(event->pos().x(), event->pos().y(), myView, Standard_True);
myContext->SelectDetected();
Handle(AIS_InteractiveObject) selected = myContext->FirstSelectedObject();
if (selected) {
// Detach the manipulator if it was already attached
if (myManipulator->IsAttached())
myManipulator->Detach();
// Attach the manipulator to the selected object
myManipulator->Attach(selected /*, anOptions*/);
// Show the manipulator
myContext->Display(myManipulator, Standard_True);
// We want only translation
myManipulator->SetPart(0, AIS_ManipulatorMode::AIS_MM_Translation, Standard_True);
myManipulator->SetPart(1, AIS_ManipulatorMode::AIS_MM_Translation, Standard_True);
myManipulator->SetPart(2, AIS_ManipulatorMode::AIS_MM_Translation, Standard_True);
// Enable the translation
myManipulator->EnableMode(AIS_ManipulatorMode::AIS_MM_Translation);
qDebug() << "myManipulator->HasActiveMode(): " << myManipulator->HasActiveMode(); // <--- HasActiveMode() is always returning false
qDebug() << "myManipulator->IsAttached(): " << myManipulator->IsAttached(); // <--- returns true
qDebug() << "myManipulator->ActiveMode(): " << myManipulator->ActiveMode(); // <--- always returns zero
}
}
Tue, 12/31/2024 - 02:29
Any update on this?
I am wondering why is myManipulator->ActiveMode() always returning zero, even after calling myManipulator->EnableMode(AIS_ManipulatorMode::AIS_MM_Translation);
Is that a bug?
Maybe someone can share a code sample that uses a gizmo to move around a cube? That would help.
Fri, 01/24/2025 - 11:03
Lol, my friend, maybe you need add this code:
AIS_Manipulator::SetModeActivationOnDetection(Standard_True);
If you haven't add this code, ActiveMode() will not catch any operations. (This trap stuck me a few days)