From f34ffd390651bacf53fa0b412e86e30ed379d98e Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Tue, 28 Jul 2020 00:16:21 +0100 Subject: [PATCH] Migrate more 3d viewer actions to the tool framework --- 3d-viewer/3d_enums.h | 12 ++++++++ 3d-viewer/3d_viewer/3d_menubar.cpp | 20 ++---------- 3d-viewer/3d_viewer/eda_3d_viewer.cpp | 21 ++----------- 3d-viewer/3d_viewer/tools/3d_actions.cpp | 30 ++++++++++++++---- 3d-viewer/3d_viewer/tools/3d_actions.h | 4 +++ 3d-viewer/3d_viewer/tools/3d_controller.cpp | 34 ++++++++++++++++----- 3d-viewer/3d_viewer/tools/3d_controller.h | 2 ++ 3d-viewer/3d_viewer_id.h | 11 ------- 8 files changed, 75 insertions(+), 59 deletions(-) diff --git a/3d-viewer/3d_enums.h b/3d-viewer/3d_enums.h index e706022fe6..3ebae418b8 100644 --- a/3d-viewer/3d_enums.h +++ b/3d-viewer/3d_enums.h @@ -72,6 +72,18 @@ enum DISPLAY3D_FLG }; +/// Rotation direction for the 3d canvas +enum class ROTATION_DIR +{ + X_NEG, + X_POS, + Y_NEG, + Y_POS, + Z_NEG, + Z_POS +}; + + /// Camera types enum class CAMERA_TYPE { diff --git a/3d-viewer/3d_viewer/3d_menubar.cpp b/3d-viewer/3d_viewer/3d_menubar.cpp index 5a0e935085..7efcfa0886 100644 --- a/3d-viewer/3d_viewer/3d_menubar.cpp +++ b/3d-viewer/3d_viewer/3d_menubar.cpp @@ -123,23 +123,9 @@ void EDA_3D_VIEWER::CreateMenuBar() propsSubmenu->SetTitle( _( "Material Properties" ) ); propsSubmenu->SetIcon( color_materials_xpm ); - propsSubmenu->Add( _( "Use All Properties" ), - _( "Use all material properties from each 3D model file" ), - ID_MENU3D_FL_RENDER_MATERIAL_MODE_NORMAL, - nullptr, - ACTION_MENU::CHECK ); - - propsSubmenu->Add( _( "Use Diffuse Only" ), - _( "Use only the diffuse color property from model 3D model file" ), - ID_MENU3D_FL_RENDER_MATERIAL_MODE_DIFFUSE_ONLY, - nullptr, - ACTION_MENU::CHECK ); - - propsSubmenu->Add( _( "CAD Color Style" ), - _( "Use a CAD color style based on the diffuse color of the material" ), - ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE, - nullptr, - ACTION_MENU::CHECK ); + propsSubmenu->Add( EDA_3D_ACTIONS::materialNormal, ACTION_MENU::CHECK ); + propsSubmenu->Add( EDA_3D_ACTIONS::materialDiffuse, ACTION_MENU::CHECK ); + propsSubmenu->Add( EDA_3D_ACTIONS::materialCAD, ACTION_MENU::CHECK ); optsSubmenu->Add( propsSubmenu ); diff --git a/3d-viewer/3d_viewer/eda_3d_viewer.cpp b/3d-viewer/3d_viewer/eda_3d_viewer.cpp index 5a4b628d63..a3a0520eec 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer.cpp @@ -206,11 +206,11 @@ void EDA_3D_VIEWER::setupUIConditions() RegisterUIUpdateHandler( ID_RENDER_CURRENT_VIEW, ACTION_CONDITIONS().SetCheckCondition( raytracingCondition ) ); - mgr->SetConditions( ID_MENU3D_FL_RENDER_MATERIAL_MODE_NORMAL,, + mgr->SetConditions( EDA_3D_ACTIONS::materialNormal, MaterialCheck( MATERIAL_MODE::NORMAL ) ); - mgr->SetConditions( ID_MENU3D_FL_RENDER_MATERIAL_MODE_DIFFUSE_ONLY,, + mgr->SetConditions( EDA_3D_ACTIONS::materialDiffuse, MaterialCheck( MATERIAL_MODE::DIFFUSE_ONLY ) ); - mgr->SetConditions( ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE,, + mgr->SetConditions( EDA_3D_ACTIONS::materialCAD, MaterialCheck( MATERIAL_MODE::CAD_MODE ) ); mgr->SetConditions( EDA_3D_ACTIONS::renderShadows, @@ -369,21 +369,6 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event ) NewDisplay( true ); break; - case ID_MENU3D_FL_RENDER_MATERIAL_MODE_NORMAL: - m_boardAdapter.MaterialModeSet( MATERIAL_MODE::NORMAL ); - NewDisplay( true ); - return; - - case ID_MENU3D_FL_RENDER_MATERIAL_MODE_DIFFUSE_ONLY: - m_boardAdapter.MaterialModeSet( MATERIAL_MODE::DIFFUSE_ONLY ); - NewDisplay( true ); - return; - - case ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE: - m_boardAdapter.MaterialModeSet( MATERIAL_MODE::CAD_MODE ); - NewDisplay( true ); - return; - case ID_MENU3D_RESET_DEFAULTS: { auto cfg = Pgm().GetSettingsManager().GetAppSettings(); diff --git a/3d-viewer/3d_viewer/tools/3d_actions.cpp b/3d-viewer/3d_viewer/tools/3d_actions.cpp index a32661ece9..a63537ccb8 100644 --- a/3d-viewer/3d_viewer/tools/3d_actions.cpp +++ b/3d-viewer/3d_viewer/tools/3d_actions.cpp @@ -46,32 +46,32 @@ TOOL_ACTION EDA_3D_ACTIONS::pivotCenter( "3DViewer.Control.pivotCenter", TOOL_ACTION EDA_3D_ACTIONS::rotateXCW( "3DViewer.Control.rotateXclockwise", AS_GLOBAL, 0, "", _( "Rotate X Clockwise" ), _( "Rotate X Clockwise" ), - rotate_neg_x_xpm, AF_NONE, (void*) ID_ROTATE3D_X_NEG ); + rotate_neg_x_xpm, AF_NONE, (void*) ROTATION_DIR::X_NEG ); TOOL_ACTION EDA_3D_ACTIONS::rotateXCCW( "3DViewer.Control.rotateXcounterclockwise", AS_GLOBAL, 0, "", _( "Rotate X Counterclockwise" ), _( "Rotate X Counterclockwise" ), - rotate_pos_x_xpm, AF_NONE, (void*) ID_ROTATE3D_X_POS ); + rotate_pos_x_xpm, AF_NONE, (void*) ROTATION_DIR::X_POS ); TOOL_ACTION EDA_3D_ACTIONS::rotateYCW( "3DViewer.Control.rotateYclockwise", AS_GLOBAL, 0, "", _( "Rotate Y Clockwise" ), _( "Rotate Y Clockwise" ), - rotate_neg_y_xpm, AF_NONE, (void*) ID_ROTATE3D_Y_NEG ); + rotate_neg_y_xpm, AF_NONE, (void*) ROTATION_DIR::Y_NEG ); TOOL_ACTION EDA_3D_ACTIONS::rotateYCCW( "3DViewer.Control.rotateYcounterclockwise", AS_GLOBAL, 0, "", _( "Rotate Y Counterclockwise" ), _( "Rotate Y Counterclockwise" ), - rotate_pos_y_xpm, AF_NONE, (void*) ID_ROTATE3D_Y_POS ); + rotate_pos_y_xpm, AF_NONE, (void*) ROTATION_DIR::Y_POS ); TOOL_ACTION EDA_3D_ACTIONS::rotateZCW( "3DViewer.Control.rotateZclockwise", AS_GLOBAL, 0, "", _( "Rotate Z Clockwise" ), _( "Rotate Z Clockwise" ), - rotate_neg_z_xpm, AF_NONE, (void*) ID_ROTATE3D_Z_NEG ); + rotate_neg_z_xpm, AF_NONE, (void*) ROTATION_DIR::Z_NEG ); TOOL_ACTION EDA_3D_ACTIONS::rotateZCCW( "3DViewer.Control.rotateZcounterclockwise", AS_GLOBAL, 0, "", _( "Rotate Z Counterclockwise" ), _( "Rotate Z Counterclockwise" ), - rotate_pos_z_xpm, AF_NONE, (void*) ID_ROTATE3D_Z_POS ); + rotate_pos_z_xpm, AF_NONE, (void*) ROTATION_DIR::Z_POS ); TOOL_ACTION EDA_3D_ACTIONS::moveLeft( "3DViewer.Control.moveLeft", AS_ACTIVE, @@ -181,6 +181,24 @@ TOOL_ACTION EDA_3D_ACTIONS::show1mmGrid( "3DViewer.Control.show1mmGrid", _( "3D Grid 1mm" ), _( "3D Grid 1mm" ), nullptr, AF_NONE, (void*) GRID3D_TYPE::GRID_1MM ); +TOOL_ACTION EDA_3D_ACTIONS::materialNormal( "3DViewer.Control.materialNormal", + AS_ACTIVE, + 0, "", + _( "Use All Properties" ), _( "Use all material properties from each 3D model file" ), + nullptr, AF_NONE, (void*) MATERIAL_MODE::NORMAL ); + +TOOL_ACTION EDA_3D_ACTIONS::materialDiffuse( "3DViewer.Control.materialDiffuse", + AS_ACTIVE, + 0, "", + _( "Use Diffuse Only" ), _( "Use only the diffuse color property from model 3D model file" ), + nullptr, AF_NONE, (void*) MATERIAL_MODE::DIFFUSE_ONLY ); + +TOOL_ACTION EDA_3D_ACTIONS::materialCAD( "3DViewer.Control.materialCAD", + AS_ACTIVE, + 0, "", + _( "CAD Color Style" ),_( "Use a CAD color style based on the diffuse color of the material" ), + nullptr, AF_NONE, (void*) MATERIAL_MODE::CAD_MODE ); + TOOL_ACTION EDA_3D_ACTIONS::rotate45axisZ( "3DViewer.Control.rotate45axisZ", AS_ACTIVE, WXK_TAB, "", diff --git a/3d-viewer/3d_viewer/tools/3d_actions.h b/3d-viewer/3d_viewer/tools/3d_actions.h index 6b8d1504e5..a06351b6ef 100644 --- a/3d-viewer/3d_viewer/tools/3d_actions.h +++ b/3d-viewer/3d_viewer/tools/3d_actions.h @@ -72,6 +72,10 @@ public: static TOOL_ACTION show2_5mmGrid; static TOOL_ACTION show1mmGrid; + static TOOL_ACTION materialNormal; + static TOOL_ACTION materialDiffuse; + static TOOL_ACTION materialCAD; + static TOOL_ACTION rotate45axisZ; static TOOL_ACTION attributesTHT; static TOOL_ACTION attributesSMD; diff --git a/3d-viewer/3d_viewer/tools/3d_controller.cpp b/3d-viewer/3d_viewer/tools/3d_controller.cpp index f653bf8762..1f15269f3d 100644 --- a/3d-viewer/3d_viewer/tools/3d_controller.cpp +++ b/3d-viewer/3d_viewer/tools/3d_controller.cpp @@ -150,14 +150,14 @@ int EDA_3D_CONTROLLER::RotateView( const TOOL_EVENT& aEvent ) { double rotIncrement = glm::radians( m_rotationIncrement ); - switch( aEvent.Parameter() ) + switch( aEvent.Parameter() ) { - case ID_ROTATE3D_X_NEG: m_camera->RotateX( -rotIncrement ); break; - case ID_ROTATE3D_X_POS: m_camera->RotateX( rotIncrement ); break; - case ID_ROTATE3D_Y_NEG: m_camera->RotateY( -rotIncrement ); break; - case ID_ROTATE3D_Y_POS: m_camera->RotateY( rotIncrement ); break; - case ID_ROTATE3D_Z_NEG: m_camera->RotateZ( -rotIncrement ); break; - case ID_ROTATE3D_Z_POS: m_camera->RotateZ( rotIncrement ); break; + case ROTATION_DIR::X_NEG: m_camera->RotateX( -rotIncrement ); break; + case ROTATION_DIR::X_POS: m_camera->RotateX( rotIncrement ); break; + case ROTATION_DIR::Y_NEG: m_camera->RotateY( -rotIncrement ); break; + case ROTATION_DIR::Y_POS: m_camera->RotateY( rotIncrement ); break; + case ROTATION_DIR::Z_NEG: m_camera->RotateZ( -rotIncrement ); break; + case ROTATION_DIR::Z_POS: m_camera->RotateZ( rotIncrement ); break; default: wxFAIL; break; } @@ -170,6 +170,21 @@ int EDA_3D_CONTROLLER::RotateView( const TOOL_EVENT& aEvent ) } +int EDA_3D_CONTROLLER::SetMaterial( const TOOL_EVENT& aEvent ) +{ + MATERIAL_MODE mode = aEvent.Parameter(); + + m_boardAdapter->MaterialModeSet( mode ); + + if( EDA_3D_VIEWER* viewer = dynamic_cast( m_toolMgr->GetToolHolder() ) ) + viewer->NewDisplay( true ); + else + m_canvas->Request_refresh(); + + return 0; +} + + int EDA_3D_CONTROLLER::ToggleOrtho( const TOOL_EVENT& aEvent ) { m_camera->ToggleProjection(); @@ -321,6 +336,11 @@ void EDA_3D_CONTROLLER::setTransitions() Go( &EDA_3D_CONTROLLER::On3DGridSelection, EDA_3D_ACTIONS::show2_5mmGrid.MakeEvent() ); Go( &EDA_3D_CONTROLLER::On3DGridSelection, EDA_3D_ACTIONS::show1mmGrid.MakeEvent() ); + // Material + Go( &EDA_3D_CONTROLLER::SetMaterial, EDA_3D_ACTIONS::materialNormal.MakeEvent() ); + Go( &EDA_3D_CONTROLLER::SetMaterial, EDA_3D_ACTIONS::materialDiffuse.MakeEvent() ); + Go( &EDA_3D_CONTROLLER::SetMaterial, EDA_3D_ACTIONS::materialCAD.MakeEvent() ); + // Visibility Go( &EDA_3D_CONTROLLER::ToggleOrtho, EDA_3D_ACTIONS::toggleOrtho.MakeEvent() ); Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::attributesTHT.MakeEvent() ); diff --git a/3d-viewer/3d_viewer/tools/3d_controller.h b/3d-viewer/3d_viewer/tools/3d_controller.h index 5caaa71117..e75bc202f5 100644 --- a/3d-viewer/3d_viewer/tools/3d_controller.h +++ b/3d-viewer/3d_viewer/tools/3d_controller.h @@ -91,6 +91,8 @@ public: int On3DGridSelection( const TOOL_EVENT& aEvent ); + int SetMaterial( const TOOL_EVENT& aEvent ); + int ToggleOrtho( const TOOL_EVENT& aEvent ); int ToggleVisibility( const TOOL_EVENT& aEvent ); diff --git a/3d-viewer/3d_viewer_id.h b/3d-viewer/3d_viewer_id.h index 406f7b8e48..6f74cb24b5 100644 --- a/3d-viewer/3d_viewer_id.h +++ b/3d-viewer/3d_viewer_id.h @@ -17,12 +17,6 @@ enum id_3dview_frm { ID_START_COMMAND_3D = ID_KICAD_3D_VIEWER_START, - ID_ROTATE3D_X_NEG, - ID_ROTATE3D_X_POS, - ID_ROTATE3D_Y_NEG, - ID_ROTATE3D_Y_POS, - ID_ROTATE3D_Z_NEG, - ID_ROTATE3D_Z_POS, ID_RELOAD3D_BOARD, ID_VIEW3D_TOP, ID_VIEW3D_BOTTOM, @@ -44,11 +38,6 @@ enum id_3dview_frm ID_MENU3D_COPPER_COLOR, ID_MENU3D_STACKUP_COLORS, - ID_MENU3D_FL_RENDER_MATERIAL, - ID_MENU3D_FL_RENDER_MATERIAL_MODE_NORMAL, - ID_MENU3D_FL_RENDER_MATERIAL_MODE_DIFFUSE_ONLY, - ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE, - ID_MENU_SCREENCOPY_PNG, ID_MENU_SCREENCOPY_JPEG, ID_MENU_SCREENCOPY_TOCLIBBOARD,