For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Could any one tell me how to use AIS_Manipulator ?

Kate Ken's picture
Forums: 

i downloaded the latest 7.1.0 beta version source ocde , and i found this version repaired a lot of problems,dan boolean operation in release mode is very fast, and i found new fecture like AIS_Manipulator, and i have displayed it. it looks like gizmo in other software eg blend,solidworks.but how i can use it tu change another ais_shape object's position,rotation?

Vincent Zhang's picture

Hi!

After attaching the manipulator to an object, u should:

1. add the below codes in your mouse leftbotton down event

if (aManipulator->HasActiveMode())

{

aManipulator->StartTransform (myXmax, myYmax, myView​);

}

2.add the below codes in your mouse move event

if (aManipulator->HasActiveMode())

{

aManipulator->Transform (myXmax, myYmax, myView​);

myView->Redraw();

}

Thus u can change the object's position, size and rotation through operating the manipulator by mouse!

Kate Ken's picture

Dear Vincent Zhang

Thanks for your reply, i will try .

another question, are u a Chinese guy?

Vincent Zhang's picture

Yes! HaHa!

I'm so happy that I can help!

Kate Ken's picture

me 2,haha,

 

Vincent Zhang's picture

Dear Forum supervisor

Sorry about that!

Kate Ken's picture

okay, what is your q ,we can exchange informations 

Vincent Zhang's picture

my Q:1458495650

Forum supervisor's picture

Dear All,

Please, use English only on these Forums - see the Forum Rules at https://www.opencascade.com/content/forums-rules.

Thank you.

Forum supervisor

Kate Ken's picture

ok~ my bad~ 

Max Chen's picture

Is there sample code to use the AIS_Manipulator ?

I try the following code, and AIS_Manipulator can attach to the object and display in the view, but it did not interactive with the mouse.

bool EventManager::UpdateMouseButtons(const Graphic3d_Vec2i& thePoint,
	Aspect_VKeyMouse theButtons,
	Aspect_VKeyFlags theModifiers,
	bool theIsEmulated)
{
	if (theButtons == Aspect_VKeyMouse_LeftButton) {
		Handle(AIS_InteractiveObject) selected = m_Context->FirstSelectedObject();
		if (!selected.IsNull() && selected != m_Selected && selected != m_Manipulator) {
			m_Selected = selected;
			AIS_Manipulator::OptionsForAttach anOptions;
			anOptions.SetAdjustPosition(true);
			anOptions.SetAdjustSize(true);
			anOptions.SetEnableModes(true);
			//m_Manipulator->SetPart (0, AIS_MM_Rotation, true);
			//m_Manipulator->SetPart (1, AIS_Manipulator::Rotation, Standard_False);
			if (m_Manipulator->IsAttached())
				m_Manipulator->Detach();
			m_Manipulator->Attach(selected, anOptions);
			m_Manipulator->EnableMode(AIS_MM_Translation);
			m_Manipulator->EnableMode(AIS_MM_Rotation);
			m_Manipulator->EnableMode(AIS_MM_Scaling);
			m_Manipulator->EnableMode(AIS_MM_TranslationPlane);
			m_Manipulator->SetModeActivationOnDetection(true);
			if (m_Context->IsDisplayed(m_Manipulator))
				m_Context->Remove(m_Manipulator, false);
			m_Context->Display(m_Manipulator, true);
			m_View->Redraw();
		}
		else if (selected.IsNull()) {
			if (m_Context->IsDisplayed(m_Manipulator)) {
				m_Manipulator->Detach();
				m_Context->Remove(m_Manipulator, false);
			}
		}
	}
	return AIS_ViewController::UpdateMouseButtons(thePoint, theButtons, theModifiers, theIsEmulated);
}

bool EventManager::UpdateMousePosition(const Graphic3d_Vec2i& thePoint,
	Aspect_VKeyMouse theButtons,
	Aspect_VKeyFlags theModifiers,
	bool theIsEmulated)
{
	if (m_Manipulator->HasActiveMode())
	{
		m_Manipulator->Transform(thePoint.x(), thePoint.y(), m_View);
		m_View->Redraw();
	}

	return AIS_ViewController::UpdateMousePosition(thePoint, theButtons, theModifiers, theIsEmulated);
}
jordi's picture

Hi Max

I think you must call AIS_Manipulator::StartTransform on mouse click.

regards

Jordi

Max Chen's picture

Hi Jordi

I use AIS_ViewController with AIS_Manipulator, so no need to call AIS_Manipulator::StartTransform.

In my code, EventManger is derived from AIS_ViewController.

Here is the partly working code :

void EventManager::PressMouseButton(const Graphic3d_Vec2i& thePoint,
	Aspect_VKeyMouse theButton,
	Aspect_VKeyFlags theModifiers)
{
	if (AIS_ViewController::PressMouseButton(thePoint, theButton, theModifiers, false))
		AIS_ViewController::FlushViewEvents(m_Context, m_View, true);

	if (theButton == Aspect_VKeyMouse_LeftButton) {
		if (m_Manipulator->IsAttached() && m_Manipulator->HasActiveMode()) {
			m_Manipulator->SetModeActivationOnDetection(false);
			m_Context->SetAutomaticHilight(false);
		}
	}
}

void EventManager::ReleaseMouseButton(const Graphic3d_Vec2i& thePoint,
	Aspect_VKeyMouse theButton,
	Aspect_VKeyFlags theModifiers)
{
	if (AIS_ViewController::ReleaseMouseButton(thePoint, theButton, theModifiers, false))
		AIS_ViewController::FlushViewEvents(m_Context, m_View, true);

	if (theButton == Aspect_VKeyMouse_LeftButton) {
		m_Manipulator->SetModeActivationOnDetection(true);
		m_Context->SetAutomaticHilight(true);
		Handle(AIS_InteractiveObject) selected = m_Context->FirstSelectedObject();
		if (!selected.IsNull() && selected != m_Selected) {
			m_Selected = selected;
			if (m_Manipulator->IsAttached())
				m_Manipulator->Detach();
			m_Manipulator->Attach(selected);
			m_Context->Redisplay(m_Manipulator, true);
			m_View->Redraw();
		}
		else if (selected.IsNull()) {
			if (m_Context->IsDisplayed(m_Manipulator)) {
				m_Manipulator->Detach();
				m_Context->Remove(m_Manipulator, Standard_True);
				m_Selected = Handle(AIS_InteractiveObject)();
			}
		}
	}
}

But in the source code of DRAW, no need for all these stuff, I can't figure it out how.