1#include <Core/Asset/Camera.hpp>
2#include <Engine/OpenGL.hpp>
3#include <Engine/Scene/CameraComponent.hpp>
5#include <Gui/Utils/Keyboard.hpp>
6#include <Gui/Viewer/CameraManipulator.hpp>
7#include <Gui/Viewer/Gizmo/GizmoManager.hpp>
8#include <Gui/Viewer/Gizmo/RotateGizmo.hpp>
9#include <Gui/Viewer/Gizmo/ScaleGizmo.hpp>
10#include <Gui/Viewer/Gizmo/TranslateGizmo.hpp>
15using GizmoMapping = KeyMappingManageable<GizmoManager>;
19#define KMA_VALUE( XX ) Gui::KeyMappingManager::KeyMappingAction GizmoManager::XX;
23void GizmoManager::configureKeyMapping_impl() {
24 GizmoMapping::setContext( Gui::KeyMappingManager::getInstance()->getContext(
"GizmoContext" ) );
25 if ( GizmoMapping::getContext().isInvalid() ) {
26 LOG( Ra::Core::Utils::logINFO )
27 <<
"GizmoContext not defined (maybe the configuration file do not contains it)";
28 LOG( Ra::Core::Utils::logERROR ) <<
"GizmoContext all keymapping invalide !";
31#define KMA_VALUE( XX ) \
32 XX = Gui::KeyMappingManager::getInstance()->getAction( GizmoMapping::getContext(), #XX );
39 if ( action.isInvalid() )
return false;
42#define KMA_VALUE( XX ) res = ( XX == action ) || res;
56GizmoManager::GizmoManager( QObject* parent ) :
57 QObject( parent ), m_currentGizmoType( NONE ), m_mode( Gizmo::GLOBAL ) {
58 m_gizmos[0].reset(
new TranslateGizmo( Engine::Scene::SystemEntity::uiCmp(),
59 Ra::Core::Transform::Identity(),
62 m_gizmos[1].reset(
new RotateGizmo( Engine::Scene::SystemEntity::uiCmp(),
63 Ra::Core::Transform::Identity(),
66 m_gizmos[2].reset(
new ScaleGizmo( Engine::Scene::SystemEntity::uiCmp(),
67 Ra::Core::Transform::Identity(),
70 for (
auto& g : m_gizmos ) {
71 if ( g ) { g->show(
false ); }
76 TransformEditor::setEditable( ent );
80void GizmoManager::updateGizmo() {
81 for (
auto& g : m_gizmos ) {
82 if ( g ) { g->show(
false ); }
86 Core::Transform worldTransform = getWorldTransform();
87 auto g = currentGizmo();
89 g->updateTransform( m_mode, worldTransform, m_transform );
95void GizmoManager::setLocal(
bool useLocal ) {
96 m_mode = useLocal ? Gizmo::LOCAL : Gizmo::GLOBAL;
100void GizmoManager::changeGizmoType( GizmoManager::GizmoType type ) {
101 m_currentGizmoType = type;
105void GizmoManager::updateValues() {
108 if ( currentGizmo() ) {
109 currentGizmo()->updateTransform( m_mode, getWorldTransform(), m_transform );
114bool GizmoManager::handleMousePressEvent( QMouseEvent* event,
115 const Qt::MouseButtons& buttons,
116 const Qt::KeyboardModifiers& modifiers,
120 if ( !canEdit() || m_currentGizmoType == NONE || !currentGizmo()->isSelected() ) {
123 auto action = KeyMappingManager::getInstance()->getAction(
124 GizmoMapping::getContext(), buttons, modifiers, key,
false );
126 if ( !( isValidAction( action ) ) ) {
return false; }
128 currentGizmo()->setInitialState( cam,
129 Core::Vector2( Scalar( event->x() ), Scalar( event->y() ) ) );
133bool GizmoManager::handleMouseReleaseEvent( QMouseEvent* ) {
134 if ( currentGizmo() ) { currentGizmo()->selectConstraint( -1 ); }
135 return ( currentGizmo() !=
nullptr );
138bool GizmoManager::handleMouseMoveEvent( QMouseEvent* event,
139 const Qt::MouseButtons& buttons,
140 const Qt::KeyboardModifiers& modifiers,
145 auto action = KeyMappingManager::getInstance()->getAction(
146 GizmoMapping::getContext(), buttons, modifiers, key,
false );
148 if ( m_currentGizmoType != NONE && canEdit() && isValidAction( action ) && currentGizmo() &&
149 currentGizmo()->isSelected() ) {
150 Core::Vector2 currentXY( event->x(), event->y() );
151 bool step = action == GIZMOMANAGER_STEP || action == GIZMOMANAGER_STEP_WHOLE;
152 bool whole = action == GIZMOMANAGER_WHOLE || action == GIZMOMANAGER_STEP_WHOLE;
154 Core::Transform newTransform = currentGizmo()->mouseMove( cam, currentXY, step, whole );
155 setTransform( newTransform );
162void GizmoManager::handlePickingResult(
int drawableId ) {
163 if ( currentGizmo() ) { currentGizmo()->selectConstraint( drawableId ); }
166Gizmo* GizmoManager::currentGizmo() {
167 return ( m_currentGizmoType == NONE ) ? nullptr : m_gizmos[m_currentGizmoType - 1].get();
170void GizmoManager::cleanup() {
171 for (
auto& g : m_gizmos ) {
Camera class storing the Camera frame and the projection properties The view direction is -z in camer...
Ra::Core::Utils::Index KeyMappingAction
handle to an action
hepler function to manage enum as underlying types in VariableSet