Migrate more 3d viewer actions to the tool framework

This commit is contained in:
Ian McInerney 2020-07-28 00:16:21 +01:00
parent 72a1c71e07
commit f34ffd3906
8 changed files with 75 additions and 59 deletions

View File

@ -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
{

View File

@ -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 );

View File

@ -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<EDA_3D_VIEWER_SETTINGS>();

View File

@ -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, "",

View File

@ -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;

View File

@ -150,14 +150,14 @@ int EDA_3D_CONTROLLER::RotateView( const TOOL_EVENT& aEvent )
{
double rotIncrement = glm::radians( m_rotationIncrement );
switch( aEvent.Parameter<intptr_t>() )
switch( aEvent.Parameter<ROTATION_DIR>() )
{
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<MATERIAL_MODE>();
m_boardAdapter->MaterialModeSet( mode );
if( EDA_3D_VIEWER* viewer = dynamic_cast<EDA_3D_VIEWER*>( 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() );

View File

@ -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 );

View File

@ -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,