From 6a2dcd19365173be86dd0c702adabd019c555aec Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Thu, 29 Sep 2022 00:18:50 +0100 Subject: [PATCH] Refactor 3D viewer view into enum class --- 3d-viewer/3d_canvas/eda_3d_canvas.cpp | 47 +++++++------------ 3d-viewer/3d_canvas/eda_3d_canvas.h | 8 ++-- 3d-viewer/3d_enums.h | 25 ++++++++++ .../3d_model_viewer/eda_3d_model_viewer.cpp | 8 ++-- 3d-viewer/3d_viewer/tools/eda_3d_actions.cpp | 20 ++++---- .../3d_viewer/tools/eda_3d_controller.cpp | 14 +++--- 3d-viewer/3d_viewer_id.h | 8 ---- 3d-viewer/dialogs/panel_preview_3d_model.h | 12 ++--- 8 files changed, 74 insertions(+), 68 deletions(-) diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.cpp b/3d-viewer/3d_canvas/eda_3d_canvas.cpp index 9abf179ac9..2e2f4e0006 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.cpp +++ b/3d-viewer/3d_canvas/eda_3d_canvas.cpp @@ -916,7 +916,7 @@ void EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position() } -bool EDA_3D_CANVAS::SetView3D( int aKeycode ) +bool EDA_3D_CANVAS::SetView3D( VIEW3D_TYPE aRequestedView ) { if( m_camera_is_moving ) return false; @@ -925,59 +925,48 @@ bool EDA_3D_CANVAS::SetView3D( int aKeycode ) const float arrow_moving_time_speed = 8.0f; bool handled = false; - switch( aKeycode ) + switch( aRequestedView ) { - case WXK_SPACE: + case VIEW3D_TYPE::VIEW3D_PIVOT_CENTER: move_pivot_based_on_cur_mouse_position(); return true; - case WXK_LEFT: + case VIEW3D_TYPE::VIEW3D_PAN_LEFT: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::LINEAR ); m_camera.SetT0_and_T1_current_T(); m_camera.Pan_T1( SFVEC3F( -delta_move, 0.0f, 0.0f ) ); request_start_moving_camera( arrow_moving_time_speed, false ); return true; - case WXK_RIGHT: + case VIEW3D_TYPE::VIEW3D_PAN_RIGHT: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::LINEAR ); m_camera.SetT0_and_T1_current_T(); m_camera.Pan_T1( SFVEC3F( +delta_move, 0.0f, 0.0f ) ); request_start_moving_camera( arrow_moving_time_speed, false ); return true; - case WXK_UP: + case VIEW3D_TYPE::VIEW3D_PAN_UP: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::LINEAR ); m_camera.SetT0_and_T1_current_T(); m_camera.Pan_T1( SFVEC3F( 0.0f, +delta_move, 0.0f ) ); request_start_moving_camera( arrow_moving_time_speed, false ); return true; - case WXK_DOWN: + case VIEW3D_TYPE::VIEW3D_PAN_DOWN: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::LINEAR ); m_camera.SetT0_and_T1_current_T(); m_camera.Pan_T1( SFVEC3F( 0.0f, -delta_move, 0.0f ) ); request_start_moving_camera( arrow_moving_time_speed, false ); return true; - case WXK_HOME: + case VIEW3D_TYPE::VIEW3D_FIT_SCREEN: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); m_camera.Reset_T1(); request_start_moving_camera( glm::min( glm::max( m_camera.GetZoom(), 1 / 1.26f ), 1.26f ) ); return true; - case WXK_END: - break; - - case WXK_TAB: - m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::EASING_IN_OUT ); - m_camera.SetT0_and_T1_current_T(); - m_camera.RotateZ_T1( glm::radians( 45.0f ) ); - request_start_moving_camera(); - handled = true; - break; - - case WXK_F1: + case VIEW3D_TYPE::VIEW3D_ZOOM_IN: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); @@ -986,7 +975,7 @@ bool EDA_3D_CANVAS::SetView3D( int aKeycode ) return true; - case WXK_F2: + case VIEW3D_TYPE::VIEW3D_ZOOM_OUT: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); @@ -995,14 +984,14 @@ bool EDA_3D_CANVAS::SetView3D( int aKeycode ) return true; - case ID_VIEW3D_RESET: + case VIEW3D_TYPE::VIEW3D_RESET: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); m_camera.Reset_T1(); request_start_moving_camera( glm::min( glm::max( m_camera.GetZoom(), 0.5f ), 1.125f ) ); return true; - case ID_VIEW3D_RIGHT: + case VIEW3D_TYPE::VIEW3D_RIGHT: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); m_camera.Reset_T1(); @@ -1011,7 +1000,7 @@ bool EDA_3D_CANVAS::SetView3D( int aKeycode ) request_start_moving_camera(); return true; - case ID_VIEW3D_LEFT: + case VIEW3D_TYPE::VIEW3D_LEFT: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); m_camera.Reset_T1(); @@ -1020,7 +1009,7 @@ bool EDA_3D_CANVAS::SetView3D( int aKeycode ) request_start_moving_camera(); return true; - case ID_VIEW3D_FRONT: + case VIEW3D_TYPE::VIEW3D_FRONT: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); m_camera.Reset_T1(); @@ -1028,7 +1017,7 @@ bool EDA_3D_CANVAS::SetView3D( int aKeycode ) request_start_moving_camera(); return true; - case ID_VIEW3D_BACK: + case VIEW3D_TYPE::VIEW3D_BACK: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); m_camera.Reset_T1(); @@ -1041,14 +1030,14 @@ bool EDA_3D_CANVAS::SetView3D( int aKeycode ) request_start_moving_camera(); return true; - case ID_VIEW3D_TOP: + case VIEW3D_TYPE::VIEW3D_TOP: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); m_camera.Reset_T1(); request_start_moving_camera( glm::min( glm::max( m_camera.GetZoom(), 0.5f ), 1.125f ) ); return true; - case ID_VIEW3D_BOTTOM: + case VIEW3D_TYPE::VIEW3D_BOTTOM: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); m_camera.Reset_T1(); @@ -1056,7 +1045,7 @@ bool EDA_3D_CANVAS::SetView3D( int aKeycode ) request_start_moving_camera( glm::min( glm::max( m_camera.GetZoom(), 0.5f ), 1.125f ) ); return true; - case ID_VIEW3D_FLIP: + case VIEW3D_TYPE::VIEW3D_FLIP: m_camera.SetInterpolateMode( CAMERA_INTERPOLATION::BEZIER ); m_camera.SetT0_and_T1_current_T(); m_camera.RotateY_T1( glm::radians( 179.999f ) ); diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.h b/3d-viewer/3d_canvas/eda_3d_canvas.h index 8ebdfb33f6..dc189f9796 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.h +++ b/3d-viewer/3d_canvas/eda_3d_canvas.h @@ -114,12 +114,12 @@ public: void GetScreenshot( wxImage& aDstImage ); /** - * Helper function to call view commands. + * Select a specific 3D view or operation * - * @param aKeycode ascii key commands. - * @return true if the key code was handled, false if no command found for this code. + * @param aRequestedView the view to move to + * @return true if the view request was handled, false if no command found for this view. */ - bool SetView3D( int aKeycode ); + bool SetView3D( VIEW3D_TYPE aRequestedView ); /** * Enable or disable camera animation when switching to a pre-defined view. diff --git a/3d-viewer/3d_enums.h b/3d-viewer/3d_enums.h index 3de6935e85..9dee2448fe 100644 --- a/3d-viewer/3d_enums.h +++ b/3d-viewer/3d_enums.h @@ -74,4 +74,29 @@ enum class MATERIAL_MODE CAD_MODE = 2 ///< Use a gray shading based on diffuse material }; +enum class VIEW3D_TYPE +{ + // Specific directions + VIEW3D_TOP, + VIEW3D_BOTTOM, + VIEW3D_LEFT, + VIEW3D_RIGHT, + VIEW3D_FRONT, + VIEW3D_BACK, + VIEW3D_RESET, + VIEW3D_FLIP, + + // Movement commands + VIEW3D_PAN_UP, + VIEW3D_PAN_DOWN, + VIEW3D_PAN_LEFT, + VIEW3D_PAN_RIGHT, + VIEW3D_ZOOM_IN, + VIEW3D_ZOOM_OUT, + VIEW3D_PIVOT_CENTER, + + // Specific levels + VIEW3D_FIT_SCREEN +}; + #endif // _3D_ENUMS_H_ diff --git a/3d-viewer/3d_model_viewer/eda_3d_model_viewer.cpp b/3d-viewer/3d_model_viewer/eda_3d_model_viewer.cpp index 4e3d375d52..c0b5b98a3a 100644 --- a/3d-viewer/3d_model_viewer/eda_3d_model_viewer.cpp +++ b/3d-viewer/3d_model_viewer/eda_3d_model_viewer.cpp @@ -400,16 +400,16 @@ void EDA_3D_MODEL_VIEWER::OnMouseWheel( wxMouseEvent& event ) if( event.ShiftDown() ) { //if( event.GetWheelRotation() < 0 ) - //SetView3D( WXK_UP ); // move up + //SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_UP ); // move up //else - //SetView3D( WXK_DOWN ); // move down + //SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_DOWN ); // move down } else if( event.ControlDown() ) { //if( event.GetWheelRotation() > 0 ) - //SetView3D( WXK_RIGHT ); // move right + //SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_RIGHT ); // move right //else - //SetView3D( WXK_LEFT ); // move left + //SetView3D( VIEW_3D_TYPE::VIEW3D_PAN_LEFT ); // move left } else { diff --git a/3d-viewer/3d_viewer/tools/eda_3d_actions.cpp b/3d-viewer/3d_viewer/tools/eda_3d_actions.cpp index 11f9940134..72527c5d77 100644 --- a/3d-viewer/3d_viewer/tools/eda_3d_actions.cpp +++ b/3d-viewer/3d_viewer/tools/eda_3d_actions.cpp @@ -46,7 +46,7 @@ TOOL_ACTION EDA_3D_ACTIONS::pivotCenter( TOOL_ACTION_ARGS() .MenuText( _( "Center pivot rotation" ) ) .Tooltip( _( "Center pivot rotation (middle mouse click)" ) ) .Flags( AF_NONE ) - .Parameter( WXK_SPACE ) ); + .Parameter( VIEW3D_TYPE::VIEW3D_PIVOT_CENTER ) ); TOOL_ACTION EDA_3D_ACTIONS::rotateXCW( TOOL_ACTION_ARGS() .Name( "3DViewer.Control.rotateXclockwise" ) @@ -149,7 +149,7 @@ TOOL_ACTION EDA_3D_ACTIONS::homeView( TOOL_ACTION_ARGS() .MenuText ( _( "Home view" ) ) .Tooltip( _( "Home view" ) ) .Flags( AF_NONE ) - .Parameter( WXK_HOME ) ); + .Parameter( VIEW3D_TYPE::VIEW3D_FIT_SCREEN ) ); TOOL_ACTION EDA_3D_ACTIONS::resetView( TOOL_ACTION_ARGS() .Name( "3DViewer.Control.resetView" ) @@ -158,7 +158,7 @@ TOOL_ACTION EDA_3D_ACTIONS::resetView( TOOL_ACTION_ARGS() .MenuText( _( "Reset view" ) ) .Tooltip( _( "Reset view" ) ) .Flags( AF_NONE ) - .Parameter( ID_VIEW3D_RESET ) ); + .Parameter( VIEW3D_TYPE::VIEW3D_RESET ) ); TOOL_ACTION EDA_3D_ACTIONS::flipView( TOOL_ACTION_ARGS() .Name( "3DViewer.Control.flipView" ) @@ -168,7 +168,7 @@ TOOL_ACTION EDA_3D_ACTIONS::flipView( TOOL_ACTION_ARGS() .Tooltip( _( "Flip the board view" ) ) .Icon( BITMAPS::flip_board ) .Flags( AF_NONE ) - .Parameter( ID_VIEW3D_FLIP ) ); + .Parameter( VIEW3D_TYPE::VIEW3D_FLIP ) ); TOOL_ACTION EDA_3D_ACTIONS::toggleOrtho( TOOL_ACTION_ARGS() .Name( "3DViewer.Control.toggleOrtho" ) @@ -185,7 +185,7 @@ TOOL_ACTION EDA_3D_ACTIONS::viewFront( TOOL_ACTION_ARGS() .Tooltip( _( "View Front" ) ) .Icon( BITMAPS::axis3d_front ) .Flags( AF_NONE ) - .Parameter( ID_VIEW3D_FRONT ) ); + .Parameter( VIEW3D_TYPE::VIEW3D_FRONT ) ); TOOL_ACTION EDA_3D_ACTIONS::viewBack( TOOL_ACTION_ARGS() .Name( "3DViewer.Control.viewBack" ) @@ -195,7 +195,7 @@ TOOL_ACTION EDA_3D_ACTIONS::viewBack( TOOL_ACTION_ARGS() .Tooltip( _( "View Back" ) ) .Icon( BITMAPS::axis3d_back ) .Flags( AF_NONE ) - .Parameter( ID_VIEW3D_BACK ) ); + .Parameter( VIEW3D_TYPE::VIEW3D_BACK ) ); TOOL_ACTION EDA_3D_ACTIONS::viewLeft( TOOL_ACTION_ARGS() .Name( "3DViewer.Control.viewLeft" ) @@ -205,7 +205,7 @@ TOOL_ACTION EDA_3D_ACTIONS::viewLeft( TOOL_ACTION_ARGS() .Tooltip( _( "View Left" ) ) .Icon( BITMAPS::axis3d_left ) .Flags( AF_NONE ) - .Parameter( ID_VIEW3D_LEFT ) ); + .Parameter( VIEW3D_TYPE::VIEW3D_LEFT ) ); TOOL_ACTION EDA_3D_ACTIONS::viewRight( TOOL_ACTION_ARGS() .Name( "3DViewer.Control.viewRight" ) @@ -215,7 +215,7 @@ TOOL_ACTION EDA_3D_ACTIONS::viewRight( TOOL_ACTION_ARGS() .Tooltip( _( "View Right" ) ) .Icon( BITMAPS::axis3d_right ) .Flags( AF_NONE ) - .Parameter( ID_VIEW3D_RIGHT ) ); + .Parameter( VIEW3D_TYPE::VIEW3D_RIGHT ) ); TOOL_ACTION EDA_3D_ACTIONS::viewTop( TOOL_ACTION_ARGS() .Name( "3DViewer.Control.viewTop" ) @@ -225,7 +225,7 @@ TOOL_ACTION EDA_3D_ACTIONS::viewTop( TOOL_ACTION_ARGS() .Tooltip( _( "View Top" ) ) .Icon( BITMAPS::axis3d_top ) .Flags( AF_NONE ) - .Parameter( ID_VIEW3D_TOP ) ); + .Parameter( VIEW3D_TYPE::VIEW3D_TOP ) ); TOOL_ACTION EDA_3D_ACTIONS::viewBottom( TOOL_ACTION_ARGS() .Name( "3DViewer.Control.viewBottom" ) @@ -235,7 +235,7 @@ TOOL_ACTION EDA_3D_ACTIONS::viewBottom( TOOL_ACTION_ARGS() .Tooltip( _( "View Bottom" ) ) .Icon( BITMAPS::axis3d_bottom ) .Flags( AF_NONE ) - .Parameter( ID_VIEW3D_BOTTOM ) ); + .Parameter( VIEW3D_TYPE::VIEW3D_BOTTOM ) ); TOOL_ACTION EDA_3D_ACTIONS::noGrid( TOOL_ACTION_ARGS() .Name( "3DViewer.Control.noGrid" ) diff --git a/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp b/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp index 65b7c6964e..98ac81bfa5 100644 --- a/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp +++ b/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp @@ -152,7 +152,7 @@ int EDA_3D_CONTROLLER::Main( const TOOL_EVENT& aEvent ) int EDA_3D_CONTROLLER::ViewControl( const TOOL_EVENT& aEvent ) { - m_canvas->SetView3D( aEvent.Parameter() ); + m_canvas->SetView3D( aEvent.Parameter() ); return 0; } @@ -162,10 +162,10 @@ int EDA_3D_CONTROLLER::PanControl( const TOOL_EVENT& aEvent ) { switch( aEvent.Parameter() ) { - case ACTIONS::CURSOR_UP: m_canvas->SetView3D( WXK_UP ); break; - case ACTIONS::CURSOR_DOWN: m_canvas->SetView3D( WXK_DOWN ); break; - case ACTIONS::CURSOR_LEFT: m_canvas->SetView3D( WXK_LEFT ); break; - case ACTIONS::CURSOR_RIGHT: m_canvas->SetView3D( WXK_RIGHT ); break; + case ACTIONS::CURSOR_UP: m_canvas->SetView3D( VIEW3D_TYPE::VIEW3D_PAN_UP ); break; + case ACTIONS::CURSOR_DOWN: m_canvas->SetView3D( VIEW3D_TYPE::VIEW3D_PAN_DOWN ); break; + case ACTIONS::CURSOR_LEFT: m_canvas->SetView3D( VIEW3D_TYPE::VIEW3D_PAN_LEFT ); break; + case ACTIONS::CURSOR_RIGHT: m_canvas->SetView3D( VIEW3D_TYPE::VIEW3D_PAN_RIGHT ); break; default: wxFAIL; break; } @@ -360,7 +360,7 @@ int EDA_3D_CONTROLLER::doZoomInOut( bool aDirection, bool aCenterOnCursor ) { if( m_canvas ) { - m_canvas->SetView3D( aDirection ? WXK_F1 : WXK_F2 ); + m_canvas->SetView3D( aDirection ? VIEW3D_TYPE::VIEW3D_ZOOM_IN : VIEW3D_TYPE::VIEW3D_ZOOM_OUT ); m_canvas->DisplayStatus(); } @@ -372,7 +372,7 @@ int EDA_3D_CONTROLLER::ZoomFitScreen( const TOOL_EVENT& aEvent ) { if( m_canvas ) { - m_canvas->SetView3D( WXK_HOME ); + m_canvas->SetView3D( VIEW3D_TYPE::VIEW3D_FIT_SCREEN ); m_canvas->DisplayStatus(); } diff --git a/3d-viewer/3d_viewer_id.h b/3d-viewer/3d_viewer_id.h index 1530c826d2..0374e1ae66 100644 --- a/3d-viewer/3d_viewer_id.h +++ b/3d-viewer/3d_viewer_id.h @@ -18,14 +18,6 @@ enum id_3dview_frm { ID_START_COMMAND_3D = ID_KICAD_3D_VIEWER_START, ID_RELOAD3D_BOARD, - ID_VIEW3D_TOP, - ID_VIEW3D_BOTTOM, - ID_VIEW3D_LEFT, - ID_VIEW3D_RIGHT, - ID_VIEW3D_FRONT, - ID_VIEW3D_BACK, - ID_VIEW3D_RESET, - ID_VIEW3D_FLIP, ID_TOOL_SCREENCOPY_TOCLIBBOARD, ID_MENU_SCREENCOPY_PNG, diff --git a/3d-viewer/dialogs/panel_preview_3d_model.h b/3d-viewer/dialogs/panel_preview_3d_model.h index c6400fddba..e589a0166c 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.h +++ b/3d-viewer/dialogs/panel_preview_3d_model.h @@ -155,17 +155,17 @@ private: void View3DLeft( wxCommandEvent& event ) override { - m_previewPane->SetView3D( ID_VIEW3D_LEFT ); + m_previewPane->SetView3D( VIEW3D_TYPE::VIEW3D_LEFT ); } void View3DFront( wxCommandEvent& event ) override { - m_previewPane->SetView3D( ID_VIEW3D_FRONT ); + m_previewPane->SetView3D( VIEW3D_TYPE::VIEW3D_FRONT ); } void View3DTop( wxCommandEvent& event ) override { - m_previewPane->SetView3D( ID_VIEW3D_TOP ); + m_previewPane->SetView3D( VIEW3D_TYPE::VIEW3D_TOP ); } void View3DUpdate( wxCommandEvent& event ) override @@ -176,17 +176,17 @@ private: void View3DRight( wxCommandEvent& event ) override { - m_previewPane->SetView3D( ID_VIEW3D_RIGHT ); + m_previewPane->SetView3D( VIEW3D_TYPE::VIEW3D_RIGHT ); } void View3DBack( wxCommandEvent& event ) override { - m_previewPane->SetView3D( ID_VIEW3D_BACK ); + m_previewPane->SetView3D( VIEW3D_TYPE::VIEW3D_BACK ); } void View3DBottom( wxCommandEvent& event ) override { - m_previewPane->SetView3D( ID_VIEW3D_BOTTOM ); + m_previewPane->SetView3D( VIEW3D_TYPE::VIEW3D_BOTTOM ); } private: