From 7dd247f1dcea6fa24e06caf251cd3ca7d919f890 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 17 Jun 2019 23:02:30 +0100 Subject: [PATCH] Make better use of TOOL_EVENT parameters. --- common/tool/action_menu.cpp | 9 +++-- common/tool/actions.cpp | 9 ++--- common/tool/common_control.cpp | 14 +------- eeschema/tools/ee_actions.cpp | 47 ++++++++++++++------------- eeschema/tools/lib_drawing_tools.cpp | 13 +------- eeschema/tools/sch_drawing_tools.cpp | 33 ++----------------- eeschema/tools/sch_edit_tool.cpp | 22 ++----------- include/frame_type.h | 2 +- include/tool/tool_action.h | 9 +++-- include/tool/tool_event.h | 12 +++++-- kicad/tools/kicad_manager_actions.cpp | 9 ++--- kicad/tools/kicad_manager_control.cpp | 14 +------- pcbnew/tools/edit_tool.cpp | 4 +-- pcbnew/tools/pcbnew_control.cpp | 2 +- 14 files changed, 63 insertions(+), 136 deletions(-) diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp index 981fd83e77..4f41495775 100644 --- a/common/tool/action_menu.cpp +++ b/common/tool/action_menu.cpp @@ -409,11 +409,10 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent ) // in fact 0 to n-1 for n items in clarification list) // id < 0 are automatically created for menuitems created with wxID_ANY #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST /* = 100 should be enough and better */ - if( !evt && ( ( m_selected >=0 && m_selected < ID_CONTEXT_MENU_ID_MAX ) || - ( m_selected >= ID_POPUP_MENU_START && - m_selected <= ID_POPUP_MENU_END ) - ) - ) + + if( !evt && + ( ( m_selected >= 0 && m_selected < ID_CONTEXT_MENU_ID_MAX ) || + ( m_selected >= ID_POPUP_MENU_START && m_selected <= ID_POPUP_MENU_END ) ) ) { menuText = GetLabelText( aEvent.GetId() ); evt = TOOL_EVENT( TC_COMMAND, TA_CHOICE_MENU_CHOICE, m_selected, AS_GLOBAL, diff --git a/common/tool/actions.cpp b/common/tool/actions.cpp index 6454560a7f..497db38770 100644 --- a/common/tool/actions.cpp +++ b/common/tool/actions.cpp @@ -24,6 +24,7 @@ #include #include #include +#include // Actions, being statically-defined, require specialized I18N handling. We continue to @@ -478,22 +479,22 @@ TOOL_ACTION ACTIONS::show3DViewer( "common.Control.show3DViewer", TOOL_ACTION ACTIONS::showSymbolBrowser( "common.Control.showSymbolBrowser", AS_GLOBAL, 0, "", _( "Symbol Library Browser" ), _( "Browse symbol libraries" ), - library_browse_xpm ); + library_browse_xpm, AF_NONE, (void*) FRAME_SCH_VIEWER ); TOOL_ACTION ACTIONS::showSymbolEditor( "common.Control.showSymbolEditor", AS_GLOBAL, 0, "", _( "Symbol Editor" ), _( "Create, delete and edit symbols" ), - libedit_xpm ); + libedit_xpm, AF_NONE, (void*) FRAME_SCH_LIB_EDITOR ); TOOL_ACTION ACTIONS::showFootprintBrowser( "common.Control.showFootprintBrowser", AS_GLOBAL, 0, "", _( "Footprint Library Browser" ), _( "Browse footprint libraries" ), - modview_icon_xpm ); + modview_icon_xpm, AF_NONE, (void*) FRAME_PCB_MODULE_VIEWER ); TOOL_ACTION ACTIONS::showFootprintEditor( "common.Control.showFootprintEditor", AS_GLOBAL, 0, "", _( "Footprint Editor" ), _( "Create, delete and edit footprints" ), - module_editor_xpm ); + module_editor_xpm, AF_NONE, (void*) FRAME_PCB_MODULE_EDITOR ); TOOL_ACTION ACTIONS::updatePcbFromSchematic( "common.Control.updatePcbFromSchematic", AS_GLOBAL, diff --git a/common/tool/common_control.cpp b/common/tool/common_control.cpp index c6438842ad..33acd71b7f 100644 --- a/common/tool/common_control.cpp +++ b/common/tool/common_control.cpp @@ -74,19 +74,7 @@ int COMMON_CONTROL::ShowLibraryTable( const TOOL_EVENT& aEvent ) int COMMON_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent ) { - FRAME_T playerType = FRAME_SCH_VIEWER; - - if( aEvent.IsAction( &ACTIONS::showSymbolBrowser ) ) - playerType = FRAME_SCH_VIEWER; - else if( aEvent.IsAction( &ACTIONS::showSymbolEditor ) ) - playerType = FRAME_SCH_LIB_EDITOR; - else if( aEvent.IsAction( &ACTIONS::showFootprintBrowser ) ) - playerType = FRAME_PCB_MODULE_VIEWER; - else if( aEvent.IsAction( &ACTIONS::showFootprintEditor ) ) - playerType = FRAME_PCB_MODULE_EDITOR; - else - wxFAIL_MSG( "ShowPlayer(): unexpected request" ); - + FRAME_T playerType = aEvent.Parameter(); KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true ); // Needed on Windows, other platforms do not use it, but it creates no issue diff --git a/eeschema/tools/ee_actions.cpp b/eeschema/tools/ee_actions.cpp index 6107cf2d92..ae9158c27c 100644 --- a/eeschema/tools/ee_actions.cpp +++ b/eeschema/tools/ee_actions.cpp @@ -24,6 +24,7 @@ #include #include #include +#include // Actions, being statically-defined, require specialized I18N handling. We continue to @@ -199,32 +200,32 @@ TOOL_ACTION EE_ACTIONS::placeSymbolPin( "eeschema.SymbolDrawing.placeSymbolPin", AS_GLOBAL, 'P', LEGACY_HK_NAME( "Create Pin" ), _( "Add Pin" ), _( "Add a pin" ), - pin_xpm, AF_ACTIVATE ); + pin_xpm, AF_ACTIVATE, (void*) LIB_PIN_T ); TOOL_ACTION EE_ACTIONS::placeSymbolText( "eeschema.SymbolDrawing.placeSymbolText", AS_GLOBAL, 0, "", _( "Add Text" ), _( "Add a text item" ), - text_xpm, AF_ACTIVATE ); + text_xpm, AF_ACTIVATE, (void*) LIB_TEXT_T ); TOOL_ACTION EE_ACTIONS::drawSymbolRectangle( "eeschema.SymbolDrawing.drawSymbolRectangle", AS_GLOBAL, 0, "", _( "Add Rectangle" ), _( "Add a rectangle" ), - add_rectangle_xpm, AF_ACTIVATE ); + add_rectangle_xpm, AF_ACTIVATE, (void*) LIB_RECTANGLE_T ); TOOL_ACTION EE_ACTIONS::drawSymbolCircle( "eeschema.SymbolDrawing.drawSymbolCircle", AS_GLOBAL, 0, "", _( "Add Circle" ), _( "Add a circle" ), - add_circle_xpm, AF_ACTIVATE ); + add_circle_xpm, AF_ACTIVATE, (void*) LIB_CIRCLE_T ); TOOL_ACTION EE_ACTIONS::drawSymbolArc( "eeschema.SymbolDrawing.drawSymbolArc", AS_GLOBAL, 0, "", _( "Add Arc" ), _( "Add an arc" ), - add_arc_xpm, AF_ACTIVATE ); + add_arc_xpm, AF_ACTIVATE, (void*) LIB_ARC_T ); TOOL_ACTION EE_ACTIONS::drawSymbolLines( "eeschema.SymbolDrawing.drawSymbolLines", AS_GLOBAL, 0, "", _( "Add Lines" ), _( "Add connected graphic lines" ), - add_graphical_segments_xpm, AF_ACTIVATE ); + add_graphical_segments_xpm, AF_ACTIVATE, (void*) LIB_POLYLINE_T ); TOOL_ACTION EE_ACTIONS::placeSymbolAnchor( "eeschema.SymbolDrawing.placeSymbolAnchor", AS_GLOBAL, 0, "", @@ -273,65 +274,65 @@ TOOL_ACTION EE_ACTIONS::placeNoConnect( "eeschema.InteractiveDrawing.placeNoConn AS_GLOBAL, 'Q', LEGACY_HK_NAME( "Add No Connect Flag" ), _( "Add No Connect Flag" ), _( "Add a no-connection flag" ), - noconn_xpm, AF_ACTIVATE ); + noconn_xpm, AF_ACTIVATE, (void*) SCH_NO_CONNECT_T ); TOOL_ACTION EE_ACTIONS::placeJunction( "eeschema.InteractiveDrawing.placeJunction", AS_GLOBAL, 'J', LEGACY_HK_NAME( "Add Junction" ), _( "Add Junction" ), _( "Add a junction" ), - add_junction_xpm, AF_ACTIVATE ); + add_junction_xpm, AF_ACTIVATE, (void*) SCH_JUNCTION_T ); TOOL_ACTION EE_ACTIONS::placeBusWireEntry( "eeschema.InteractiveDrawing.placeBusWireEntry", AS_GLOBAL, 'Z', LEGACY_HK_NAME( "Add Wire Entry" ), _( "Add Wire to Bus Entry" ), _( "Add a wire entry to a bus" ), - add_line2bus_xpm, AF_ACTIVATE ); + add_line2bus_xpm, AF_ACTIVATE, (void*) SCH_BUS_WIRE_ENTRY_T ); TOOL_ACTION EE_ACTIONS::placeBusBusEntry( "eeschema.InteractiveDrawing.placeBusBusEntry", AS_GLOBAL, '/', LEGACY_HK_NAME( "Add Bus Entry" ), _( "Add Bus to Bus Entry" ), _( "Add a bus entry to a bus" ), - add_bus2bus_xpm, AF_ACTIVATE ); + add_bus2bus_xpm, AF_ACTIVATE, (void*) SCH_BUS_BUS_ENTRY_T ); TOOL_ACTION EE_ACTIONS::placeLabel( "eeschema.InteractiveDrawing.placeLabel", AS_GLOBAL, 'L', LEGACY_HK_NAME( "Add Label" ), _( "Add Label" ), _( "Add a net label" ), - add_line_label_xpm, AF_ACTIVATE ); + add_line_label_xpm, AF_ACTIVATE, (void*) SCH_LABEL_T ); TOOL_ACTION EE_ACTIONS::placeHierLabel( "eeschema.InteractiveDrawing.placeHierarchicalLabel", AS_GLOBAL, 'H', LEGACY_HK_NAME( "Add Hierarchical Label" ), _( "Add Hierarchical Label" ), _( "Add a hierarchical sheet label" ), - add_hierarchical_label_xpm, AF_ACTIVATE ); + add_hierarchical_label_xpm, AF_ACTIVATE, (void*) SCH_HIER_LABEL_T ); TOOL_ACTION EE_ACTIONS::drawSheet( "eeschema.InteractiveDrawing.drawSheet", AS_GLOBAL, 'S', LEGACY_HK_NAME( "Add Sheet" ), _( "Add Sheet" ), _( "Add a hierarchical sheet" ), - add_hierarchical_subsheet_xpm, AF_ACTIVATE ); + add_hierarchical_subsheet_xpm, AF_ACTIVATE, (void*) SCH_SHEET_T ); TOOL_ACTION EE_ACTIONS::placeSheetPin( "eeschema.InteractiveDrawing.placeSheetPin", AS_GLOBAL, 0, "", _( "Add Sheet Pin" ), _( "Add a sheet pin" ), - add_hierar_pin_xpm, AF_ACTIVATE ); + add_hierar_pin_xpm, AF_ACTIVATE, (void*) SCH_SHEET_PIN_T ); TOOL_ACTION EE_ACTIONS::importSheetPin( "eeschema.InteractiveDrawing.importSheetPin", AS_GLOBAL, 0, "", _( "Import Sheet Pin" ), _( "Import a hierarchical sheet pin" ), - import_hierarchical_label_xpm, AF_ACTIVATE ); + import_hierarchical_label_xpm, AF_ACTIVATE, (void*) SCH_SHEET_PIN_T ); TOOL_ACTION EE_ACTIONS::placeGlobalLabel( "eeschema.InteractiveDrawing.placeGlobalLabel", AS_GLOBAL, MD_CTRL + 'H', LEGACY_HK_NAME( "Add Global Label" ), _( "Add Global Label" ), _( "Add a global label" ), - add_glabel_xpm, AF_ACTIVATE ); + add_glabel_xpm, AF_ACTIVATE, (void*) SCH_GLOBAL_LABEL_T ); TOOL_ACTION EE_ACTIONS::placeSchematicText( "eeschema.InteractiveDrawing.placeSchematicText", AS_GLOBAL, 'T', LEGACY_HK_NAME( "Add Graphic Text" ), _( "Add Text" ), _( "Add text" ), - text_xpm, AF_ACTIVATE ); + text_xpm, AF_ACTIVATE, (void*) SCH_TEXT_T ); TOOL_ACTION EE_ACTIONS::placeImage( "eeschema.InteractiveDrawing.placeImage", AS_GLOBAL, 0, "", @@ -428,32 +429,32 @@ TOOL_ACTION EE_ACTIONS::showDeMorganAlternate( "eeschema.InteractiveEdit.showDeM TOOL_ACTION EE_ACTIONS::toShapeSlash( "eeschema.InteractiveEdit.toShapeSlash", AS_GLOBAL, 0, "", _( "Set Bus Entry Shape /" ), _( "Change the bus entry shape to /" ), - change_entry_orient_xpm ); + change_entry_orient_xpm, AF_NONE, (void*) '/' ); TOOL_ACTION EE_ACTIONS::toShapeBackslash( "eeschema.InteractiveEdit.toShapeBackslash", AS_GLOBAL, 0, "", _( "Set Bus Entry Shape \\" ), _( "Change the bus entry shape to \\" ), - change_entry_orient_xpm ); + change_entry_orient_xpm, AF_NONE, (void*) '\\' ); TOOL_ACTION EE_ACTIONS::toLabel( "eeschema.InteractiveEdit.toLabel", AS_GLOBAL, 0, "", _( "Change to Label" ), _( "Change existing item to a label" ), - add_line_label_xpm ); + add_line_label_xpm, AF_NONE, (void*) SCH_LABEL_T ); TOOL_ACTION EE_ACTIONS::toHLabel( "eeschema.InteractiveEdit.toHLabel", AS_GLOBAL, 0, "", _( "Change to Hierarchical Label" ), _( "Change existing item to a hierarchical label" ), - add_hierarchical_label_xpm ); + add_hierarchical_label_xpm, AF_NONE, (void*) SCH_HIER_LABEL_T ); TOOL_ACTION EE_ACTIONS::toGLabel( "eeschema.InteractiveEdit.toGLabel", AS_GLOBAL, 0, "", _( "Change to Global Label" ), _( "Change existing item to a global label" ), - add_glabel_xpm ); + add_glabel_xpm, AF_NONE, (void*) SCH_GLOBAL_LABEL_T ); TOOL_ACTION EE_ACTIONS::toText( "eeschema.InteractiveEdit.toText", AS_GLOBAL, 0, "", _( "Change to Text" ), _( "Change existing item to a text comment" ), - text_xpm ); + text_xpm, AF_NONE, (void*) SCH_TEXT_T ); TOOL_ACTION EE_ACTIONS::cleanupSheetPins( "eeschema.InteractiveEdit.cleanupSheetPins", AS_GLOBAL, 0, "", diff --git a/eeschema/tools/lib_drawing_tools.cpp b/eeschema/tools/lib_drawing_tools.cpp index 12542e261a..489f620cec 100644 --- a/eeschema/tools/lib_drawing_tools.cpp +++ b/eeschema/tools/lib_drawing_tools.cpp @@ -250,23 +250,12 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode ) int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) { - KICAD_T type = TYPE_NOT_INIT; + KICAD_T type = aEvent.Parameter(); // We might be running as the same shape in another co-routine. Make sure that one // gets whacked. m_toolMgr->DeactivateTool(); - if( aEvent.IsAction( &EE_ACTIONS::drawSymbolArc ) ) - type = LIB_ARC_T; - else if( aEvent.IsAction( &EE_ACTIONS::drawSymbolCircle ) ) - type = LIB_CIRCLE_T; - else if( aEvent.IsAction( &EE_ACTIONS::drawSymbolLines ) ) - type = LIB_POLYLINE_T; - else if( aEvent.IsAction( &EE_ACTIONS::drawSymbolRectangle ) ) - type = LIB_RECTANGLE_T; - else - wxCHECK_MSG( false, 0, "Unknown action in LIB_DRAWING_TOOLS::DrawShape()" ); - m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); getViewControls()->ShowCursor( true ); diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 8bd55c435b..e0e37a71fe 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -359,11 +359,9 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) { bool immediateMode = aEvent.HasPosition(); wxPoint cursorPos; - KICAD_T type = TYPE_NOT_INIT; + KICAD_T type = aEvent.Parameter(); - if( aEvent.IsAction( &EE_ACTIONS::placeNoConnect ) ) - type = SCH_NO_CONNECT_T; - else if( aEvent.IsAction( &EE_ACTIONS::placeJunction ) ) + if( type == SCH_JUNCTION_T ) { if( immediateMode ) { @@ -378,19 +376,9 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true ); } } - - type = SCH_JUNCTION_T; } - else if( aEvent.IsAction( &EE_ACTIONS::placeHierLabel ) ) - type = SCH_HIER_LABEL_T; else if( aEvent.IsAction( &EE_ACTIONS::placeSheetPin ) ) type = SCH_SHEET_PIN_T; - else if( aEvent.IsAction( &EE_ACTIONS::placeBusWireEntry ) ) - type = SCH_BUS_WIRE_ENTRY_T; - else if( aEvent.IsAction( &EE_ACTIONS::placeBusBusEntry ) ) - type = SCH_BUS_BUS_ENTRY_T; - else - wxFAIL_MSG( "SingleClickPlace(): unexpected request" ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); getViewControls()->ShowCursor( true ); @@ -476,22 +464,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) { EDA_ITEM* item = nullptr; bool immediateMode = aEvent.HasPosition(); - KICAD_T type = TYPE_NOT_INIT; - - if( aEvent.IsAction( &EE_ACTIONS::placeLabel ) ) - type = SCH_LABEL_T; - else if( aEvent.IsAction( &EE_ACTIONS::placeGlobalLabel ) ) - type = SCH_GLOBAL_LABEL_T; - else if( aEvent.IsAction( &EE_ACTIONS::placeHierLabel ) ) - type = SCH_HIER_LABEL_T; - else if( aEvent.IsAction( &EE_ACTIONS::placeSheetPin ) ) - type = SCH_SHEET_PIN_T; - else if( aEvent.IsAction( &EE_ACTIONS::importSheetPin ) ) - type = SCH_SHEET_PIN_T; - else if( aEvent.IsAction( &EE_ACTIONS::placeSchematicText ) ) - type = SCH_TEXT_T; - else - wxFAIL_MSG( "TwoClickPlace(): unexpected request" ); + KICAD_T type = aEvent.Parameter(); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); getViewControls()->ShowCursor( true ); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 4c5f8f0701..5719041ceb 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1204,14 +1204,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::ChangeShape( const TOOL_EVENT& aEvent ) { EE_SELECTION& selection = m_selectionTool->GetSelection(); - char shape; - - if( aEvent.IsAction( &EE_ACTIONS::toShapeSlash ) ) - shape = '/'; - else if( aEvent.IsAction( &EE_ACTIONS::toShapeBackslash ) ) - shape = '\\'; - else - return 0; + char shape = aEvent.Parameter(); for( unsigned int i = 0; i < selection.GetSize(); ++i ) { @@ -1238,20 +1231,9 @@ int SCH_EDIT_TOOL::ChangeShape( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent ) { + KICAD_T convertTo = aEvent.Parameter(); KICAD_T allTextTypes[] = { SCH_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXT_T, EOT }; EE_SELECTION& selection = m_selectionTool->RequestSelection( allTextTypes ); - KICAD_T convertTo; - - if( aEvent.IsAction( &EE_ACTIONS::toLabel ) ) - convertTo = SCH_LABEL_T; - else if( aEvent.IsAction( &EE_ACTIONS::toHLabel ) ) - convertTo = SCH_HIER_LABEL_T; - else if( aEvent.IsAction( &EE_ACTIONS::toGLabel ) ) - convertTo = SCH_GLOBAL_LABEL_T; - else if( aEvent.IsAction( &EE_ACTIONS::toText ) ) - convertTo = SCH_TEXT_T; - else - return 0; for( unsigned int i = 0; i < selection.GetSize(); ++i ) { diff --git a/include/frame_type.h b/include/frame_type.h index c1db001811..9bddd4178d 100644 --- a/include/frame_type.h +++ b/include/frame_type.h @@ -33,7 +33,7 @@ */ enum FRAME_T { - FRAME_SCH, + FRAME_SCH = 0, FRAME_SCH_LIB_EDITOR, FRAME_SCH_VIEWER, FRAME_SCH_VIEWER_MODAL, diff --git a/include/tool/tool_action.h b/include/tool/tool_action.h index 9ec36d7da1..e7de543c2e 100644 --- a/include/tool/tool_action.h +++ b/include/tool/tool_action.h @@ -54,6 +54,10 @@ public: ~TOOL_ACTION(); + // TOOL_ACTIONS are singletons; don't be copying them around.... + TOOL_ACTION( const TOOL_ACTION& ) = delete; + TOOL_ACTION& operator= ( const TOOL_ACTION& ) = delete; + bool operator==( const TOOL_ACTION& aRhs ) const { return m_id == aRhs.m_id; @@ -168,11 +172,6 @@ protected: TOOL_ACTION_FLAGS m_flags; void* m_param; // Generic parameter - -private: - // TOOL_ACTIONS are singletons; don't be copying them around.... - TOOL_ACTION( const TOOL_ACTION& ) = delete; - TOOL_ACTION& operator= ( const TOOL_ACTION& ) = delete; }; #endif diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index 21a8de42e6..d886e0953c 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -176,7 +176,7 @@ public: const std::string Format() const; TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory = TC_NONE, TOOL_ACTIONS aAction = TA_NONE, - TOOL_ACTION_SCOPE aScope = AS_GLOBAL, void* aParameter = NULL ) : + TOOL_ACTION_SCOPE aScope = AS_GLOBAL, void* aParameter = nullptr ) : m_category( aCategory ), m_actions( aAction ), m_scope( aScope ), @@ -192,7 +192,7 @@ public: } TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction, int aExtraParam, - TOOL_ACTION_SCOPE aScope = AS_GLOBAL, void* aParameter = nullptr ) : + TOOL_ACTION_SCOPE aScope = AS_GLOBAL, void* aParameter = nullptr ) : m_category( aCategory ), m_actions( aAction ), m_scope( aScope ), @@ -392,7 +392,13 @@ public: template inline T Parameter() const { - return reinterpret_cast( m_param ); + // Exhibit #798 on why I love to hate C++ + // - reinterpret_cast needs to be used for pointers + // - static_cast must be used for enums + // - templates can't usefully distinguish between pointer and non-pointer types + // Fortunately good old C's cast can be a reinterpret_cast or a static_cast, and + // C99 gave us intptr_t which is guaranteed to be round-trippable with a pointer. + return (T) reinterpret_cast( m_param ); } /** diff --git a/kicad/tools/kicad_manager_actions.cpp b/kicad/tools/kicad_manager_actions.cpp index 8153067139..d2da9457fd 100644 --- a/kicad/tools/kicad_manager_actions.cpp +++ b/kicad/tools/kicad_manager_actions.cpp @@ -24,6 +24,7 @@ #include #include #include +#include // Actions, being statically-defined, require specialized I18N handling. We continue to @@ -55,25 +56,25 @@ TOOL_ACTION KICAD_MANAGER_ACTIONS::editSchematic( "kicad.Control.editSchematic", AS_GLOBAL, MD_CTRL + 'E', LEGACY_HK_NAME( "Run Eeschema" ), _( "Edit Schematic" ), "", - icon_eeschema_xpm ); + icon_eeschema_xpm, AF_NONE, (void*) FRAME_SCH ); TOOL_ACTION KICAD_MANAGER_ACTIONS::editSymbols( "kicad.Control.editSymbols", AS_GLOBAL, MD_CTRL + 'L', LEGACY_HK_NAME( "Run LibEdit" ), _( "Edit Schematic Symbols" ), "", - icon_libedit_xpm ); + icon_libedit_xpm, AF_NONE, (void*) FRAME_SCH_LIB_EDITOR ); TOOL_ACTION KICAD_MANAGER_ACTIONS::editPCB( "kicad.Control.editPCB", AS_GLOBAL, MD_CTRL + 'P', LEGACY_HK_NAME( "Run Pcbnew" ), _( "Edit PCB" ), "", - icon_pcbnew_xpm ); + icon_pcbnew_xpm, AF_NONE, (void*) FRAME_PCB ); TOOL_ACTION KICAD_MANAGER_ACTIONS::editFootprints( "kicad.Control.editFootprints", AS_GLOBAL, MD_CTRL + 'F', LEGACY_HK_NAME( "Run FpEditor" ), _( "Edit PCB Footprints" ), "", - icon_modedit_xpm ); + icon_modedit_xpm, AF_NONE, (void*) FRAME_PCB_MODULE_EDITOR ); TOOL_ACTION KICAD_MANAGER_ACTIONS::viewGerbers( "kicad.Control.viewGerbers", AS_GLOBAL, diff --git a/kicad/tools/kicad_manager_control.cpp b/kicad/tools/kicad_manager_control.cpp index afac80e37b..7a57a9e968 100644 --- a/kicad/tools/kicad_manager_control.cpp +++ b/kicad/tools/kicad_manager_control.cpp @@ -337,19 +337,7 @@ int KICAD_MANAGER_CONTROL::UpdateMenu( const TOOL_EVENT& aEvent ) int KICAD_MANAGER_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent ) { - FRAME_T playerType = FRAME_SCH_VIEWER; - - if( aEvent.IsAction( &KICAD_MANAGER_ACTIONS::editSchematic ) ) - playerType = FRAME_SCH; - else if( aEvent.IsAction( &KICAD_MANAGER_ACTIONS::editSymbols ) ) - playerType = FRAME_SCH_LIB_EDITOR; - else if( aEvent.IsAction( &KICAD_MANAGER_ACTIONS::editPCB ) ) - playerType = FRAME_PCB; - else if( aEvent.IsAction( &KICAD_MANAGER_ACTIONS::editFootprints ) ) - playerType = FRAME_PCB_MODULE_EDITOR; - else - wxFAIL_MSG( "ShowPlayer(): unexpected request" ); - + FRAME_T playerType = aEvent.Parameter(); KIWAY_PLAYER* player; try diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 0ab129d590..2698bcd04c 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -796,8 +796,8 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) // get a copy instead of reference (as we're going to clear the selection before removing items) PCBNEW_SELECTION selectionCopy; - bool isCut = aEvent.Parameter() == static_cast( PCB_ACTIONS::REMOVE_FLAGS::CUT ); - bool isAlt = aEvent.Parameter() == static_cast( PCB_ACTIONS::REMOVE_FLAGS::ALT ); + bool isCut = aEvent.Parameter() == PCB_ACTIONS::REMOVE_FLAGS::CUT; + bool isAlt = aEvent.Parameter() == PCB_ACTIONS::REMOVE_FLAGS::ALT; // If we are in a "Cut" operation, then the copied selection exists already if( isCut ) diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 479e2400de..a55df40c54 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -285,7 +285,7 @@ int PCBNEW_CONTROL::HighContrastMode( const TOOL_EVENT& aEvent ) // Layer control int PCBNEW_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent ) { - m_frame->SwitchLayer( NULL, (PCB_LAYER_ID) aEvent.Parameter() ); + m_frame->SwitchLayer( NULL, aEvent.Parameter() ); return 0; }