From e8b11c911e7f8777a3f8891545b6ca827c785300 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Fri, 14 Aug 2020 00:09:17 +0100 Subject: [PATCH] Migrate Pcbnew/footprint viewer/footprint editor to the new UI update system --- common/CMakeLists.txt | 1 + common/tool/action_toolbar.cpp | 10 +- common/tool/editor_conditions.cpp | 12 + common/tool/selection_conditions.cpp | 12 + cvpcb/display_footprints_frame.cpp | 38 +- include/tool/action_toolbar.h | 6 +- include/tool/editor_conditions.h | 12 +- include/tool/selection_conditions.h | 5 + pcbnew/footprint_edit_frame.cpp | 107 ++++++ pcbnew/footprint_edit_frame.h | 6 +- pcbnew/footprint_viewer_frame.cpp | 49 +++ pcbnew/footprint_viewer_frame.h | 6 +- pcbnew/menubar_footprint_editor.cpp | 294 ++++++---------- pcbnew/menubar_pcb_editor.cpp | 469 ++++++++++--------------- pcbnew/pcb_edit_frame.cpp | 206 +++++++++++ pcbnew/pcb_edit_frame.h | 6 +- pcbnew/pcbnew.cpp | 1 - pcbnew/swig/python_scripting.h | 2 + pcbnew/toolbars_footprint_editor.cpp | 70 ---- pcbnew/toolbars_footprint_viewer.cpp | 44 +-- pcbnew/toolbars_pcb_editor.cpp | 136 +------ pcbnew/tools/pcb_editor_conditions.cpp | 153 ++++++++ pcbnew/tools/pcb_editor_conditions.h | 122 +++++++ 23 files changed, 1028 insertions(+), 739 deletions(-) create mode 100644 pcbnew/tools/pcb_editor_conditions.cpp create mode 100644 pcbnew/tools/pcb_editor_conditions.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index c6bb159ee8..84d52b7c49 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -517,6 +517,7 @@ set( PCB_COMMON_SRCS ${CMAKE_SOURCE_DIR}/pcbnew/tools/grid_helper.cpp ${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_actions.cpp + ${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_editor_conditions.cpp ${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_viewer_tools.cpp widgets/net_selector.cpp diff --git a/common/tool/action_toolbar.cpp b/common/tool/action_toolbar.cpp index 515ad47680..0719f95e2a 100644 --- a/common/tool/action_toolbar.cpp +++ b/common/tool/action_toolbar.cpp @@ -100,7 +100,7 @@ void ACTION_TOOLBAR::AddScaledSeparator( wxWindow* aWindow ) } -void ACTION_TOOLBAR::AddToolContextMenu( const TOOL_ACTION& aAction, CONDITIONAL_MENU* aMenu ) +void ACTION_TOOLBAR::AddToolContextMenu( const TOOL_ACTION& aAction, ACTION_MENU* aMenu ) { int toolId = aAction.GetUIId(); @@ -208,10 +208,12 @@ void ACTION_TOOLBAR::onToolRightClick( wxAuiToolBarEvent& aEvent ) return; // Update and show the menu - CONDITIONAL_MENU* menu = it->second; - SELECTION dummySel; + ACTION_MENU* menu = it->second; + SELECTION dummySel; + + if( CONDITIONAL_MENU* condMenu = dynamic_cast( menu ) ) + condMenu->Evaluate( dummySel ); - menu->Evaluate( dummySel ); menu->UpdateAll(); PopupMenu( menu ); diff --git a/common/tool/editor_conditions.cpp b/common/tool/editor_conditions.cpp index 5ed02ea379..6d2a6ef286 100644 --- a/common/tool/editor_conditions.cpp +++ b/common/tool/editor_conditions.cpp @@ -65,6 +65,12 @@ SELECTION_CONDITION EDITOR_CONDITIONS::CurrentTool( const TOOL_ACTION& aTool ) } +SELECTION_CONDITION EDITOR_CONDITIONS::NoActiveTool() +{ + return std::bind( &EDITOR_CONDITIONS::noToolFunc, _1, m_frame ); +} + + SELECTION_CONDITION EDITOR_CONDITIONS::GridVisible() { // The grid visibility check requires a draw frame @@ -141,6 +147,12 @@ bool EDITOR_CONDITIONS::toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* a } +bool EDITOR_CONDITIONS::noToolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame ) +{ + return aFrame->ToolStackIsEmpty(); +} + + bool EDITOR_CONDITIONS::gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame ) { return aFrame->IsGridVisible(); diff --git a/common/tool/selection_conditions.cpp b/common/tool/selection_conditions.cpp index d78cd93e04..71a5406747 100644 --- a/common/tool/selection_conditions.cpp +++ b/common/tool/selection_conditions.cpp @@ -179,9 +179,21 @@ SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA, return std::bind( &SELECTION_CONDITIONS::orBoolFunc, aConditionA, std::ref( aConditionB ), _1 ); } +SELECTION_CONDITION operator||( SELECTION_BOOL aConditionA, + const SELECTION_CONDITION& aConditionB ) +{ + return aConditionB || aConditionA; +} + SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA, SELECTION_BOOL aConditionB ) { return std::bind( &SELECTION_CONDITIONS::andBoolFunc, aConditionA, std::ref( aConditionB ), _1 ); } + +SELECTION_CONDITION operator&&( SELECTION_BOOL aConditionA, + const SELECTION_CONDITION& aConditionB ) +{ + return aConditionB && aConditionA; +} diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 00e0255c24..74480d4421 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -51,6 +50,7 @@ #include #include #include +#include // Shared conditions with other pcbnew frames #include // shared tools with other pcbnew frames #include #include @@ -185,8 +185,8 @@ void DISPLAY_FOOTPRINTS_FRAME::setupUIConditions() { PCB_BASE_FRAME::setupUIConditions(); - ACTION_MANAGER* mgr = m_toolManager->GetActionManager(); - EDITOR_CONDITIONS cond( this ); + ACTION_MANAGER* mgr = m_toolManager->GetActionManager(); + PCB_EDITOR_CONDITIONS cond( this ); wxASSERT( mgr ); @@ -209,35 +209,11 @@ void DISPLAY_FOOTPRINTS_FRAME::setupUIConditions() return GetAutoZoom(); }; - auto padNumCond = - [this] ( const SELECTION& aSel ) - { - return GetDisplayOptions().m_DisplayPadNum; - }; - - auto padFillCond = - [this] ( const SELECTION& aSel ) - { - return !GetDisplayOptions().m_DisplayPadFill; - }; - - auto textFillCond = - [this] ( const SELECTION& aSel ) - { - return !GetDisplayOptions().m_DisplayTextFill; - }; - - auto graphicsFillCond = - [this] ( const SELECTION& aSel ) - { - return !GetDisplayOptions().m_DisplayGraphicsFill; - }; - mgr->SetConditions( PCB_ACTIONS::zoomFootprintAutomatically, CHECK( autoZoomCond ) ); - mgr->SetConditions( PCB_ACTIONS::showPadNumbers, CHECK( padNumCond ) ); - mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( padFillCond ) ); - mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( textFillCond ) ); - mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( graphicsFillCond ) ); + mgr->SetConditions( PCB_ACTIONS::showPadNumbers, CHECK( cond.PadNumbersDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) ); #undef CHECK } diff --git a/include/tool/action_toolbar.h b/include/tool/action_toolbar.h index e8612814ad..e178c1ca67 100644 --- a/include/tool/action_toolbar.h +++ b/include/tool/action_toolbar.h @@ -29,7 +29,7 @@ #include #include -class CONDITIONAL_MENU; +class ACTION_MENU; class EDA_BASE_FRAME; class TOOL_MANAGER; class TOOL_ACTION; @@ -77,7 +77,7 @@ public: * @param aAction is the action to get the menu * @param aMenu is the context menu */ - void AddToolContextMenu( const TOOL_ACTION& aAction, CONDITIONAL_MENU* aMenu ); + void AddToolContextMenu( const TOOL_ACTION& aAction, ACTION_MENU* aMenu ); /** * Clear the toolbar and remove all associated menus. @@ -111,7 +111,7 @@ protected: TOOL_MANAGER* m_toolManager; std::map m_toolKinds; std::map m_toolActions; - std::map m_toolMenus; + std::map m_toolMenus; }; #endif diff --git a/include/tool/editor_conditions.h b/include/tool/editor_conditions.h index 30b621e0a0..c7ef080251 100644 --- a/include/tool/editor_conditions.h +++ b/include/tool/editor_conditions.h @@ -84,6 +84,13 @@ public: */ SELECTION_CONDITION CurrentTool( const TOOL_ACTION& aTool ); + /** + * Creates a functor testing if there are no tools active in the frame. + * + * @return Functor testing the frame has no tools running + */ + SELECTION_CONDITION NoActiveTool(); + /** * Creates a functor testing if the grid is visible in a frame. * @@ -120,7 +127,7 @@ public: */ SELECTION_CONDITION CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE aType ); -private: +protected: ///> Helper function used by ContentModified() static bool contentModifiedFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame ); @@ -136,6 +143,9 @@ private: ///> Helper function used by CurrentTool() static bool toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame, const TOOL_ACTION& aTool ); + ///> Helper function used by NoActiveTool() + static bool noToolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame ); + ///> Helper function used by GridVisible() static bool gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame ); diff --git a/include/tool/selection_conditions.h b/include/tool/selection_conditions.h index 19281bbfac..4493bf77f1 100644 --- a/include/tool/selection_conditions.h +++ b/include/tool/selection_conditions.h @@ -51,9 +51,14 @@ typedef bool ( &SELECTION_BOOL )( const SELECTION& ); SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA, SELECTION_BOOL aConditionB ); +SELECTION_CONDITION operator||( SELECTION_BOOL aConditionA, + const SELECTION_CONDITION& aConditionB ); + SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA, SELECTION_BOOL aConditionB ); +SELECTION_CONDITION operator&&( SELECTION_BOOL aConditionA, + const SELECTION_CONDITION& aConditionB ); /** * Class that groups generic conditions for selected items. diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index d787d9d90d..889432e082 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -61,9 +61,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -173,6 +175,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, // Create the manager and dispatcher & route draw panel events to the dispatcher setupTools(); + setupUIConditions(); initLibraryTree(); m_treePane = new FOOTPRINT_TREE_PANE( this ); @@ -272,6 +275,12 @@ bool FOOTPRINT_EDIT_FRAME::IsContentModified() } +SELECTION& FOOTPRINT_EDIT_FRAME::GetCurrentSelection() +{ + return m_toolManager->GetTool()->GetSelection(); +} + + void FOOTPRINT_EDIT_FRAME::SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) { // switches currently used canvas (Cairo / OpenGL). @@ -897,6 +906,104 @@ void FOOTPRINT_EDIT_FRAME::setupTools() } +void FOOTPRINT_EDIT_FRAME::setupUIConditions() +{ + PCB_BASE_EDIT_FRAME::setupUIConditions(); + + ACTION_MANAGER* mgr = m_toolManager->GetActionManager(); + PCB_EDITOR_CONDITIONS cond( this ); + + wxASSERT( mgr ); + +#define ENABLE( x ) ACTION_CONDITIONS().Enable( x ) +#define CHECK( x ) ACTION_CONDITIONS().Check( x ) + + auto haveFootprintCond = + [this]( const SELECTION& ) + { + return GetBoard()->GetFirstModule() != nullptr; + }; + + auto footprintTargettedCond = + [this] ( const SELECTION& ) + { + return !GetTargetFPID().GetLibItemName().empty(); + }; + + mgr->SetConditions( ACTIONS::saveAs, ENABLE( footprintTargettedCond ) ); + mgr->SetConditions( ACTIONS::revert, ENABLE( cond.ContentModified() ) ); + mgr->SetConditions( PCB_ACTIONS::saveToBoard, ENABLE( cond.ContentModified() ) ); + mgr->SetConditions( PCB_ACTIONS::saveToLibrary, ENABLE( cond.ContentModified() ) ); + + mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) ); + mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) ); + + mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) ); + mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) ); + mgr->SetConditions( ACTIONS::metricUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) ); + mgr->SetConditions( ACTIONS::imperialUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) ); + mgr->SetConditions( ACTIONS::acceleratedGraphics, CHECK( cond.CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL ) ) ); + mgr->SetConditions( ACTIONS::standardGraphics, CHECK( cond.CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ) ) ); + + mgr->SetConditions( ACTIONS::cut, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); + mgr->SetConditions( ACTIONS::copy, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); + mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) ); + mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) ); + mgr->SetConditions( ACTIONS::doDelete, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); + mgr->SetConditions( ACTIONS::duplicate, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); + + mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) ); + + mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); + mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) ); + + + auto highContrastCond = + [this] ( const SELECTION& ) + { + return GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL; + }; + + auto footprintTreeCond = + [this] (const SELECTION& ) + { + return IsSearchTreeShown(); + }; + + mgr->SetConditions( ACTIONS::highContrastMode, CHECK( highContrastCond ) ); + mgr->SetConditions( PCB_ACTIONS::toggleFootprintTree, CHECK( footprintTreeCond ) ); + + mgr->SetConditions( ACTIONS::print, ENABLE( haveFootprintCond ) ); + mgr->SetConditions( PCB_ACTIONS::exportFootprint, ENABLE( haveFootprintCond ) ); + mgr->SetConditions( PCB_ACTIONS::footprintProperties, ENABLE( haveFootprintCond ) ); + mgr->SetConditions( PCB_ACTIONS::cleanupGraphics, ENABLE( haveFootprintCond ) ); + + +// Only enable a tool if the part is edtable +#define CURRENT_EDIT_TOOL( action ) mgr->SetConditions( action, \ + ACTION_CONDITIONS().Enable( haveFootprintCond ).Check( cond.CurrentTool( action ) ) ) + + CURRENT_EDIT_TOOL( ACTIONS::deleteTool ); + CURRENT_EDIT_TOOL( ACTIONS::measureTool ); + CURRENT_EDIT_TOOL( PCB_ACTIONS::placePad ); + CURRENT_EDIT_TOOL( PCB_ACTIONS::drawLine ); + CURRENT_EDIT_TOOL( PCB_ACTIONS::drawRectangle ); + CURRENT_EDIT_TOOL( PCB_ACTIONS::drawCircle ); + CURRENT_EDIT_TOOL( PCB_ACTIONS::drawArc ); + CURRENT_EDIT_TOOL( PCB_ACTIONS::drawPolygon ); + CURRENT_EDIT_TOOL( PCB_ACTIONS::drawZoneKeepout ); + CURRENT_EDIT_TOOL( PCB_ACTIONS::placeText ); + CURRENT_EDIT_TOOL( PCB_ACTIONS::setAnchor ); + CURRENT_EDIT_TOOL( PCB_ACTIONS::gridSetOrigin ); + +#undef CURRENT_EDIT_TOOL +#undef ENABLE +#undef CHECK +} + + void FOOTPRINT_EDIT_FRAME::ActivateGalCanvas() { PCB_BASE_EDIT_FRAME::ActivateGalCanvas(); diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index 58fb310450..489cbb07f7 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -32,6 +32,7 @@ class EDGE_MODULE; class FOOTPRINT_TREE_PANE; class LIB_MANAGER; class FOOTPRINT_EDITOR_SETTINGS; +class PCBNEW_SELECTION; namespace PCB { struct IFACE; } // A KIFACE_I coded in pcbnew.c @@ -61,6 +62,7 @@ public: ///> @copydoc PCB_BASE_FRAME::GetModel() BOARD_ITEM_CONTAINER* GetModel() const override; + SELECTION& GetCurrentSelection() override; /** * Get if any footprints or libraries have been modified but not saved. @@ -340,8 +342,6 @@ public: void KiwayMailIn( KIWAY_EXPRESS& mail ) override; - void SyncToolbars() override; - DECLARE_EVENT_TABLE() protected: @@ -373,6 +373,8 @@ protected: * Run the Footprint Properties dialog and handle changes made in it. */ void editFootprintProperties( MODULE* aFootprint ); + + void setupUIConditions() override; }; #endif // FOOTPRINT_EDIT_FRAME_H diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 1c273305f6..409a97d65d 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -46,11 +46,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -212,6 +214,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent m_toolManager->InitTools(); m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" ); + setupUIConditions(); ReCreateMenuBar(); ReCreateHToolbar(); ReCreateVToolbar(); @@ -285,6 +288,52 @@ FOOTPRINT_VIEWER_FRAME::~FOOTPRINT_VIEWER_FRAME() } +SELECTION& FOOTPRINT_VIEWER_FRAME::GetCurrentSelection() +{ + return m_toolManager->GetTool()->GetSelection(); +} + + +void FOOTPRINT_VIEWER_FRAME::setupUIConditions() +{ + PCB_BASE_FRAME::setupUIConditions(); + + ACTION_MANAGER* mgr = m_toolManager->GetActionManager(); + PCB_EDITOR_CONDITIONS cond( this ); + + wxASSERT( mgr ); + +#define ENABLE( x ) ACTION_CONDITIONS().Enable( x ) +#define CHECK( x ) ACTION_CONDITIONS().Check( x ) + + mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) ); + mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) ); + mgr->SetConditions( ACTIONS::metricUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) ); + mgr->SetConditions( ACTIONS::imperialUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) ); + + + mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); + mgr->SetConditions( ACTIONS::measureTool, CHECK( cond.CurrentTool( ACTIONS::measureTool ) ) ); + mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) ); + + mgr->SetConditions( PCB_ACTIONS::showPadNumbers, CHECK( cond.PadNumbersDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) ); + + auto autoZoomCond = + [this] ( const SELECTION& ) + { + return GetAutoZoom(); + }; + + mgr->SetConditions( PCB_ACTIONS::zoomFootprintAutomatically, CHECK( autoZoomCond ) ); + +#undef ENABLE +#undef CHECK +} + + void FOOTPRINT_VIEWER_FRAME::OnCloseWindow( wxCloseEvent& Event ) { // A workaround to avoid flicker, in modal mode when modview frame is destroyed, diff --git a/pcbnew/footprint_viewer_frame.h b/pcbnew/footprint_viewer_frame.h index d120cda61b..ce68a5abf6 100644 --- a/pcbnew/footprint_viewer_frame.h +++ b/pcbnew/footprint_viewer_frame.h @@ -34,6 +34,7 @@ class wxSashLayoutWindow; class wxListBox; class FP_LIB_TABLE; class BOARD_ITEM; +class SELECTION; namespace PCB { struct IFACE; } @@ -49,6 +50,8 @@ protected: MAGNETIC_SETTINGS m_magneticItems; + void setupUIConditions() override; + public: ~FOOTPRINT_VIEWER_FRAME(); @@ -56,6 +59,8 @@ public: ///> @copydoc PCB_BASE_FRAME::GetModel() BOARD_ITEM_CONTAINER* GetModel() const override; + SELECTION& GetCurrentSelection() override; + virtual COLOR4D GetGridColor() override; bool GetAutoZoom() override; @@ -124,7 +129,6 @@ private: void ReCreateVToolbar() override; void ReCreateOptToolbar() override; void ReCreateMenuBar() override; - void SyncToolbars() override; void OnLibFilter( wxCommandEvent& aEvent ); void OnFPFilter( wxCommandEvent& aEvent ); diff --git a/pcbnew/menubar_footprint_editor.cpp b/pcbnew/menubar_footprint_editor.cpp index 1a172628c6..85484b5759 100644 --- a/pcbnew/menubar_footprint_editor.cpp +++ b/pcbnew/menubar_footprint_editor.cpp @@ -28,7 +28,7 @@ #include "pcbnew_id.h" #include #include -#include +#include #include #include #include @@ -44,36 +44,29 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() wxMenuBar* oldMenuBar = GetMenuBar(); WX_MENUBAR* menuBar = new WX_MENUBAR(); - auto modifiedDocumentCondition = [this]( const SELECTION& sel ) { - return IsContentModified(); - }; - auto haveFootprintCondition = [this]( const SELECTION& aSelection ) { - return GetBoard()->GetFirstModule() != nullptr; - }; - auto footprintTargettedCondition = [this]( const SELECTION& aSelection ) { - return !GetTargetFPID().GetLibItemName().empty(); - }; - //-- File menu ---------------------------------------------------------- // - CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool ); + + fileMenu->Add( ACTIONS::newLibrary ); + fileMenu->Add( ACTIONS::addLibrary ); + fileMenu->Add( PCB_ACTIONS::newFootprint ); - fileMenu->AddItem( ACTIONS::newLibrary, SELECTION_CONDITIONS::ShowAlways ); - fileMenu->AddItem( ACTIONS::addLibrary, SELECTION_CONDITIONS::ShowAlways ); - fileMenu->AddItem( PCB_ACTIONS::newFootprint, SELECTION_CONDITIONS::ShowAlways ); #ifdef KICAD_SCRIPTING - fileMenu->AddItem( PCB_ACTIONS::createFootprint, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->Add( PCB_ACTIONS::createFootprint ); #endif - fileMenu->AddSeparator(); - if( IsCurrentFPFromBoard() ) - fileMenu->AddItem( PCB_ACTIONS::saveToBoard, modifiedDocumentCondition ); - else - fileMenu->AddItem( PCB_ACTIONS::saveToLibrary, modifiedDocumentCondition ); - fileMenu->AddItem( ACTIONS::saveAs, footprintTargettedCondition ); - fileMenu->AddItem( ACTIONS::revert, modifiedDocumentCondition ); + fileMenu->AppendSeparator(); - fileMenu->AddSeparator(); + if( IsCurrentFPFromBoard() ) + fileMenu->Add( PCB_ACTIONS::saveToBoard ); + else + fileMenu->Add( PCB_ACTIONS::saveToLibrary ); + + fileMenu->Add( ACTIONS::saveAs ); + fileMenu->Add( ACTIONS::revert ); + + fileMenu->AppendSeparator(); ACTION_MENU* submenuImport = new ACTION_MENU( false ); submenuImport->SetTool( selTool ); @@ -83,228 +76,175 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() submenuImport->Add( PCB_ACTIONS::importFootprint ); submenuImport->Add( _( "&Import Graphics..." ), _( "Import 2D Drawing file to Footprint Editor on Drawings layer" ), - ID_GEN_IMPORT_GRAPHICS_FILE, import_vector_xpm ); + ID_GEN_IMPORT_GRAPHICS_FILE, + import_vector_xpm ); - fileMenu->AddMenu( submenuImport, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->Add( submenuImport ); - CONDITIONAL_MENU* submenuExport = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* submenuExport = new ACTION_MENU( false, selTool ); submenuExport->SetTitle( _( "Export" ) ); submenuExport->SetIcon( export_xpm ); - submenuExport->AddItem( PCB_ACTIONS::exportFootprint, haveFootprintCondition ); - submenuExport->AddItem( ID_MODEDIT_SAVE_PNG, _( "Export View as &PNG..." ), - _( "Create a PNG file from the current view" ), - plot_xpm, SELECTION_CONDITIONS::ShowAlways ); + submenuExport->Add( PCB_ACTIONS::exportFootprint ); + submenuExport->Add( _( "Export View as &PNG..." ), + _( "Create a PNG file from the current view" ), + ID_MODEDIT_SAVE_PNG, + plot_xpm ); - fileMenu->AddMenu( submenuExport, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->Add( submenuExport ); - fileMenu->AddSeparator(); - fileMenu->AddItem( ACTIONS::print, haveFootprintCondition ); + fileMenu->AppendSeparator(); + fileMenu->Add( ACTIONS::print ); - fileMenu->AddSeparator(); + fileMenu->AppendSeparator(); fileMenu->AddClose( _( "Footprint Editor" ) ); - fileMenu->Resolve(); //-- Edit menu ------------------------------------------------------- // - CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* editMenu = new ACTION_MENU( false, selTool ); - auto enableUndoCondition = [ this ] ( const SELECTION& sel ) { - return GetUndoCommandCount() > 0; - }; - auto enableRedoCondition = [ this ] ( const SELECTION& sel ) { - return GetRedoCommandCount() > 0; - }; - auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) { - return ToolStackIsEmpty(); - }; + editMenu->Add( ACTIONS::undo ); + editMenu->Add( ACTIONS::redo ); - editMenu->AddItem( ACTIONS::undo, enableUndoCondition ); - editMenu->AddItem( ACTIONS::redo, enableRedoCondition ); + editMenu->AppendSeparator(); + editMenu->Add( ACTIONS::cut ); + editMenu->Add( ACTIONS::copy ); + editMenu->Add( ACTIONS::paste ); + editMenu->Add( ACTIONS::doDelete ); + editMenu->Add( ACTIONS::duplicate ); - editMenu->AddSeparator(); - editMenu->AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty ); - editMenu->AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty ); - editMenu->AddItem( ACTIONS::paste, noActiveToolCondition ); - editMenu->AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty ); - editMenu->AddItem( ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty ); + editMenu->AppendSeparator(); + editMenu->Add( PCB_ACTIONS::footprintProperties ); + editMenu->Add( PCB_ACTIONS::defaultPadProperties ); - editMenu->AddSeparator(); - editMenu->AddItem( PCB_ACTIONS::footprintProperties, haveFootprintCondition ); - editMenu->AddItem( PCB_ACTIONS::defaultPadProperties, SELECTION_CONDITIONS::ShowAlways ); + editMenu->AppendSeparator(); + editMenu->Add( PCB_ACTIONS::cleanupGraphics ); - editMenu->AddSeparator(); - editMenu->AddItem( PCB_ACTIONS::cleanupGraphics, haveFootprintCondition ); - - editMenu->Resolve(); //-- View menu ------------------------------------------------------- // - CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool ); - auto gridShownCondition = [ this ] ( const SELECTION& aSel ) { - return IsGridVisible(); - }; - auto polarCoordsCondition = [ this ] ( const SELECTION& aSel ) { - return GetShowPolarCoords(); - }; - auto imperialUnitsCondition = [this]( const SELECTION& aSel ) { - return GetUserUnits() == EDA_UNITS::INCHES; - }; - auto metricUnitsCondition = [this]( const SELECTION& aSel ) { - return GetUserUnits() == EDA_UNITS::MILLIMETRES; - }; - auto fullCrosshairCondition = [ this ] ( const SELECTION& aSel ) { - return GetGalDisplayOptions().m_fullscreenCursor; - }; - auto sketchPadsCondition = [ this ] ( const SELECTION& aSel ) { - return !GetDisplayOptions().m_DisplayPadFill; - }; - auto sketchGraphicsCondition = [ this ] ( const SELECTION& aSel ) { - return !GetDisplayOptions().m_DisplayGraphicsFill; - }; - auto sketchTextCondition = [ this ] ( const SELECTION& aSel ) { - return !GetDisplayOptions().m_DisplayTextFill; - }; - auto contrastModeCondition = [ this ] ( const SELECTION& aSel ) { - return ( GetDisplayOptions().m_ContrastModeDisplay != - HIGH_CONTRAST_MODE::NORMAL ); - }; - auto searchTreeShownCondition = [ this ] ( const SELECTION& aSel ) { - return IsSearchTreeShown(); - }; + viewMenu->Add( ACTIONS::showFootprintBrowser ); + viewMenu->Add( ACTIONS::show3DViewer ); - viewMenu->AddItem( ACTIONS::showFootprintBrowser, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::show3DViewer, SELECTION_CONDITIONS::ShowAlways ); + viewMenu->AppendSeparator(); + viewMenu->Add( ACTIONS::zoomInCenter ); + viewMenu->Add( ACTIONS::zoomOutCenter ); + viewMenu->Add( ACTIONS::zoomFitScreen ); + viewMenu->Add( ACTIONS::zoomTool ); + viewMenu->Add( ACTIONS::zoomRedraw ); - viewMenu->AddSeparator(); - viewMenu->AddItem( ACTIONS::zoomInCenter, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomOutCenter, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomFitScreen, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomTool, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomRedraw, SELECTION_CONDITIONS::ShowAlways ); - - viewMenu->AddSeparator(); - viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition ); - viewMenu->AddItem( ACTIONS::gridProperties, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddCheckItem( PCB_ACTIONS::togglePolarCoords, polarCoordsCondition ); + viewMenu->AppendSeparator(); + viewMenu->Add( ACTIONS::toggleGrid, ACTION_MENU::CHECK ); + viewMenu->Add( ACTIONS::gridProperties ); + viewMenu->Add( PCB_ACTIONS::togglePolarCoords, ACTION_MENU::CHECK ); // Units submenu - CONDITIONAL_MENU* unitsSubMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool ); unitsSubMenu->SetTitle( _( "&Units" ) ); unitsSubMenu->SetIcon( unit_mm_xpm ); - unitsSubMenu->AddCheckItem( ACTIONS::imperialUnits, imperialUnitsCondition ); - unitsSubMenu->AddCheckItem( ACTIONS::metricUnits, metricUnitsCondition ); - viewMenu->AddMenu( unitsSubMenu ); + unitsSubMenu->Add( ACTIONS::imperialUnits, ACTION_MENU::CHECK ); + unitsSubMenu->Add( ACTIONS::metricUnits, ACTION_MENU::CHECK ); + viewMenu->Add( unitsSubMenu ); - viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition ); + viewMenu->Add( ACTIONS::toggleCursorStyle, ACTION_MENU::CHECK ); - viewMenu->AddSeparator(); + viewMenu->AppendSeparator(); // Drawing Mode Submenu - CONDITIONAL_MENU* drawingModeSubMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* drawingModeSubMenu = new ACTION_MENU( false, selTool ); drawingModeSubMenu->SetTitle( _( "&Drawing Mode" ) ); drawingModeSubMenu->SetIcon( add_zone_xpm ); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::padDisplayMode, sketchPadsCondition ); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::graphicsOutlines, sketchGraphicsCondition ); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::textOutlines, sketchTextCondition ); - viewMenu->AddMenu( drawingModeSubMenu ); + drawingModeSubMenu->Add( PCB_ACTIONS::padDisplayMode, ACTION_MENU::CHECK ); + drawingModeSubMenu->Add( PCB_ACTIONS::graphicsOutlines, ACTION_MENU::CHECK ); + drawingModeSubMenu->Add( PCB_ACTIONS::textOutlines, ACTION_MENU::CHECK ); + viewMenu->Add( drawingModeSubMenu ); // Contrast Mode Submenu - CONDITIONAL_MENU* contrastModeSubMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* contrastModeSubMenu = new ACTION_MENU( false, selTool ); contrastModeSubMenu->SetTitle( _( "&Contrast Mode" ) ); contrastModeSubMenu->SetIcon( contrast_mode_xpm ); - contrastModeSubMenu->AddCheckItem( ACTIONS::highContrastMode, contrastModeCondition ); - contrastModeSubMenu->AddItem( PCB_ACTIONS::layerAlphaDec, SELECTION_CONDITIONS::ShowAlways ); - contrastModeSubMenu->AddItem( PCB_ACTIONS::layerAlphaInc, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddMenu( contrastModeSubMenu ); + contrastModeSubMenu->Add( ACTIONS::highContrastMode, ACTION_MENU::CHECK ); + contrastModeSubMenu->Add( PCB_ACTIONS::layerAlphaDec ); + contrastModeSubMenu->Add( PCB_ACTIONS::layerAlphaInc ); + viewMenu->Add( contrastModeSubMenu ); - viewMenu->AddSeparator(); - viewMenu->AddCheckItem( PCB_ACTIONS::toggleFootprintTree, searchTreeShownCondition ); + viewMenu->AppendSeparator(); + viewMenu->Add( PCB_ACTIONS::toggleFootprintTree, ACTION_MENU::CHECK ); - viewMenu->Resolve(); //-- Place menu ------------------------------------------------------- // - CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool ); - placeMenu->AddItem( PCB_ACTIONS::placePad, haveFootprintCondition ); + placeMenu->Add( PCB_ACTIONS::placePad ); - placeMenu->AddSeparator(); - placeMenu->AddItem( PCB_ACTIONS::placeText, haveFootprintCondition ); - placeMenu->AddItem( PCB_ACTIONS::drawArc, haveFootprintCondition ); - placeMenu->AddItem( PCB_ACTIONS::drawRectangle, haveFootprintCondition ); - placeMenu->AddItem( PCB_ACTIONS::drawCircle, haveFootprintCondition ); - placeMenu->AddItem( PCB_ACTIONS::drawLine, haveFootprintCondition ); - placeMenu->AddItem( PCB_ACTIONS::drawPolygon, haveFootprintCondition ); - placeMenu->AddItem( PCB_ACTIONS::drawZoneKeepout, haveFootprintCondition ); + placeMenu->AppendSeparator(); + placeMenu->Add( PCB_ACTIONS::placeText ); + placeMenu->Add( PCB_ACTIONS::drawArc ); + placeMenu->Add( PCB_ACTIONS::drawRectangle ); + placeMenu->Add( PCB_ACTIONS::drawCircle ); + placeMenu->Add( PCB_ACTIONS::drawLine ); + placeMenu->Add( PCB_ACTIONS::drawPolygon ); + placeMenu->Add( PCB_ACTIONS::drawZoneKeepout ); - placeMenu->AddSeparator(); - placeMenu->AddItem( PCB_ACTIONS::setAnchor, haveFootprintCondition ); - placeMenu->AddItem( ACTIONS::gridSetOrigin, haveFootprintCondition ); + placeMenu->AppendSeparator(); + placeMenu->Add( PCB_ACTIONS::setAnchor ); + placeMenu->Add( ACTIONS::gridSetOrigin ); - placeMenu->Resolve(); //-- Inspect menu ------------------------------------------------------ // - CONDITIONAL_MENU* inspectMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* inspectMenu = new ACTION_MENU( false, selTool ); + + inspectMenu->Add( ACTIONS::measureTool ); - inspectMenu->AddItem( ACTIONS::measureTool, haveFootprintCondition ); - inspectMenu->Resolve(); //-- Tools menu -------------------------------------------------------- // - wxMenu* toolsMenu = new wxMenu; + ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool ); - AddMenuItem( toolsMenu, ID_MODEDIT_LOAD_MODULE_FROM_BOARD, - _( "&Load Footprint from PCB..." ), - _( "Load a footprint from the current board into the editor" ), - KiBitmap( load_module_board_xpm ) ); + toolsMenu->Add( _( "&Load Footprint from PCB..." ), + _( "Load a footprint from the current board into the editor" ), + ID_MODEDIT_LOAD_MODULE_FROM_BOARD, + load_module_board_xpm ); - AddMenuItem( toolsMenu, ID_ADD_FOOTPRINT_TO_BOARD, - _( "&Insert Footprint on PCB" ), - _( "Insert footprint onto current board" ), - KiBitmap( insert_module_board_xpm ) ); + toolsMenu->Add( _( "&Insert Footprint on PCB" ), + _( "Insert footprint onto current board" ), + ID_ADD_FOOTPRINT_TO_BOARD, + insert_module_board_xpm ); //-- Preferences menu ------------------------------------------------- // - CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* prefsMenu = new ACTION_MENU( false, selTool ); - auto acceleratedGraphicsCondition = [ this ] ( const SELECTION& aSel ) { - return GetCanvas()->GetBackend() == EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL; - }; - auto standardGraphicsCondition = [ this ] ( const SELECTION& aSel ) { - return GetCanvas()->GetBackend() == EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO; - }; + prefsMenu->Add( ACTIONS::configurePaths ); + prefsMenu->Add( ACTIONS::showFootprintLibTable ); + prefsMenu->Add( _( "Preferences...\tCTRL+," ), + _( "Show preferences for all open tools" ), + wxID_PREFERENCES, + preference_xpm ); - prefsMenu->AddItem( ACTIONS::configurePaths, SELECTION_CONDITIONS::ShowAlways ); - prefsMenu->AddItem( ACTIONS::showFootprintLibTable, SELECTION_CONDITIONS::ShowAlways ); - prefsMenu->AddItem( wxID_PREFERENCES, - _( "Preferences...\tCTRL+," ), - _( "Show preferences for all open tools" ), - preference_xpm, SELECTION_CONDITIONS::ShowAlways ); - - prefsMenu->AddSeparator(); + prefsMenu->AppendSeparator(); AddMenuLanguageList( prefsMenu, selTool ); - prefsMenu->AddSeparator(); - prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition ); - prefsMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition ); - - prefsMenu->Resolve(); + prefsMenu->AppendSeparator(); + prefsMenu->Add( ACTIONS::acceleratedGraphics, ACTION_MENU::CHECK ); + prefsMenu->Add( ACTIONS::standardGraphics, ACTION_MENU::CHECK ); //--MenuBar ----------------------------------------------------------- // - menuBar->Append( fileMenu, _( "&File" ) ); - menuBar->Append( editMenu, _( "&Edit" ) ); - menuBar->Append( viewMenu, _( "&View" ) ); - menuBar->Append( placeMenu, _( "&Place" ) ); + menuBar->Append( fileMenu, _( "&File" ) ); + menuBar->Append( editMenu, _( "&Edit" ) ); + menuBar->Append( viewMenu, _( "&View" ) ); + menuBar->Append( placeMenu, _( "&Place" ) ); menuBar->Append( inspectMenu, _( "&Inspect" ) ); - menuBar->Append( toolsMenu, _( "&Tools" ) ); - menuBar->Append( prefsMenu, _( "P&references" ) ); + menuBar->Append( toolsMenu, _( "&Tools" ) ); + menuBar->Append( prefsMenu, _( "P&references" ) ); AddStandardHelpMenu( menuBar ); SetMenuBar( menuBar ); diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index a5ddde87a0..663eb6ae26 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -51,17 +51,12 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() wxMenuBar* oldMenuBar = GetMenuBar(); WX_MENUBAR* menuBar = new WX_MENUBAR(); - auto modifiedDocumentCondition = [ this ] ( const SELECTION& sel ) { - return IsContentModified(); - }; - // Recreate all menus: //-- File menu ----------------------------------------------------------- // - CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool ); static ACTION_MENU* openRecentMenu; - auto& disp_opt = GetDisplayOptions(); if( Kiface().IsSingle() ) // not when under a project mgr { @@ -80,31 +75,36 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() fileHistory.AddFilesToMenu(); } - fileMenu->AddItem( ACTIONS::doNew, SELECTION_CONDITIONS::ShowAlways ); - fileMenu->AddItem( ACTIONS::open, SELECTION_CONDITIONS::ShowAlways ); - fileMenu->AddMenu( openRecentMenu, FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) ); + fileMenu->Add( ACTIONS::doNew ); + fileMenu->Add( ACTIONS::open ); - fileMenu->AddItem( PCB_ACTIONS::appendBoard, SELECTION_CONDITIONS::ShowAlways ); + wxMenuItem* item = fileMenu->Add( openRecentMenu ); - fileMenu->AddSeparator(); + // Add the file menu condition here since it needs the item ID for the submenu + ACTION_CONDITIONS cond; + cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) ); + RegisterUIUpdateHandler( item->GetId(), cond ); + + fileMenu->Add( PCB_ACTIONS::appendBoard ); + fileMenu->AppendSeparator(); } - fileMenu->AddItem( ACTIONS::save, modifiedDocumentCondition ); + fileMenu->Add( ACTIONS::save ); // Save as menu: // under a project mgr we do not want to modify the board filename // to keep consistency with the project mgr which expects files names same as prj name // for main files if( Kiface().IsSingle() ) - fileMenu->AddItem( ACTIONS::saveAs, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->Add( ACTIONS::saveAs ); else - fileMenu->AddItem( ACTIONS::saveCopyAs, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->Add( ACTIONS::saveCopyAs ); - fileMenu->AddSeparator(); - fileMenu->AddItem( ID_MENU_RECOVER_BOARD_AUTOSAVE, - _( "Resc&ue" ), - _( "Clear board and get last rescue file automatically saved by Pcbnew" ), - rescue_xpm, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AppendSeparator(); + fileMenu->Add( _( "Resc&ue" ), + _( "Clear board and get last rescue file automatically saved by Pcbnew" ), + ID_MENU_RECOVER_BOARD_AUTOSAVE, + rescue_xpm ); // Import submenu ACTION_MENU* submenuImport = new ACTION_MENU( false ); @@ -124,8 +124,8 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() ID_IMPORT_NON_KICAD_BOARD, import_brd_file_xpm ); } - fileMenu->AddSeparator(); - fileMenu->AddMenu( submenuImport, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AppendSeparator(); + fileMenu->Add( submenuImport ); // Export submenu ACTION_MENU* submenuExport = new ACTION_MENU( false ); @@ -150,7 +150,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() submenuExport->Add( _( "Hyperlynx..." ), "", ID_GEN_EXPORT_FILE_HYPERLYNX, export_step_xpm ); - fileMenu->AddMenu( submenuExport, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->Add( submenuExport ); // Fabrication Outputs submenu ACTION_MENU* submenuFabOutputs = new ACTION_MENU( false ); @@ -164,22 +164,15 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() submenuFabOutputs->Add( PCB_ACTIONS::generateReportFile ); submenuFabOutputs->Add( PCB_ACTIONS::generateD356File ); submenuFabOutputs->Add( PCB_ACTIONS::generateBOM ); + fileMenu->Add( submenuFabOutputs ); - fileMenu->AddMenu( submenuFabOutputs, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AppendSeparator(); + fileMenu->Add( PCB_ACTIONS::boardSetup ); - auto enableBoardSetupCondition = [ this ] ( const SELECTION& sel ) { - if( DRC* tool = m_toolManager->GetTool() ) - return !tool->IsDRCDialogShown(); - - return true; - }; - fileMenu->AddSeparator(); - fileMenu->AddItem( PCB_ACTIONS::boardSetup, enableBoardSetupCondition ); - - fileMenu->AddSeparator(); - fileMenu->AddItem( ACTIONS::pageSettings, SELECTION_CONDITIONS::ShowAlways ); - fileMenu->AddItem( ACTIONS::print, SELECTION_CONDITIONS::ShowAlways ); - fileMenu->AddItem( ACTIONS::plot, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AppendSeparator(); + fileMenu->Add( ACTIONS::pageSettings ); + fileMenu->Add( ACTIONS::print ); + fileMenu->Add( ACTIONS::plot ); // Archive submenu ACTION_MENU* submenuArchive = new ACTION_MENU( false ); @@ -197,234 +190,144 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() "(if the library already exists it will be replaced)" ), ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES, library_archive_as_xpm ); - fileMenu->AddSeparator(); - fileMenu->AddMenu( submenuArchive, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AppendSeparator(); + fileMenu->Add( submenuArchive ); - fileMenu->AddSeparator(); + fileMenu->AppendSeparator(); fileMenu->AddQuitOrClose( &Kiface(), _( "Pcbnew" ) ); - fileMenu->Resolve(); - //-- Edit menu ----------------------------------------------------------- // - CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* editMenu = new ACTION_MENU( false, selTool ); - auto enableUndoCondition = [ this ] ( const SELECTION& sel ) { - return GetUndoCommandCount() > 0; - }; - auto enableRedoCondition = [ this ] ( const SELECTION& sel ) { - return GetRedoCommandCount() > 0; - }; - auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) { - return ToolStackIsEmpty(); - }; + editMenu->Add( ACTIONS::undo ); + editMenu->Add( ACTIONS::redo ); - editMenu->AddItem( ACTIONS::undo, enableUndoCondition ); - editMenu->AddItem( ACTIONS::redo, enableRedoCondition ); + editMenu->AppendSeparator(); + editMenu->Add( ACTIONS::cut ); + editMenu->Add( ACTIONS::copy ); + editMenu->Add( ACTIONS::paste ); + editMenu->Add( ACTIONS::doDelete ); + editMenu->Add( ACTIONS::duplicate ); - editMenu->AddSeparator(); - editMenu->AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty ); - editMenu->AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty ); - editMenu->AddItem( ACTIONS::paste, noActiveToolCondition ); - editMenu->AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty ); - editMenu->AddItem( ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty ); + editMenu->AppendSeparator(); + editMenu->Add( ACTIONS::find ); - editMenu->AddSeparator(); - editMenu->AddItem( ACTIONS::find, SELECTION_CONDITIONS::ShowAlways ); + editMenu->AppendSeparator(); + editMenu->Add( PCB_ACTIONS::editTracksAndVias ); + editMenu->Add( PCB_ACTIONS::editTextAndGraphics ); + editMenu->Add( PCB_ACTIONS::changeFootprints ); + editMenu->Add( PCB_ACTIONS::swapLayers ); - editMenu->AddSeparator(); - editMenu->AddItem( PCB_ACTIONS::editTracksAndVias, SELECTION_CONDITIONS::ShowAlways ); - editMenu->AddItem( PCB_ACTIONS::editTextAndGraphics, SELECTION_CONDITIONS::ShowAlways ); - editMenu->AddItem( PCB_ACTIONS::changeFootprints, SELECTION_CONDITIONS::ShowAlways ); - editMenu->AddItem( PCB_ACTIONS::swapLayers, SELECTION_CONDITIONS::ShowAlways ); + editMenu->AppendSeparator(); + editMenu->Add( PCB_ACTIONS::zoneFillAll ); + editMenu->Add( PCB_ACTIONS::zoneUnfillAll ); - editMenu->AddSeparator(); - editMenu->AddItem( PCB_ACTIONS::zoneFillAll, SELECTION_CONDITIONS::ShowAlways ); - editMenu->AddItem( PCB_ACTIONS::zoneUnfillAll, SELECTION_CONDITIONS::ShowAlways ); + editMenu->AppendSeparator(); + editMenu->Add( ACTIONS::deleteTool ); + editMenu->Add( PCB_ACTIONS::globalDeletions ); + editMenu->Add( PCB_ACTIONS::cleanupTracksAndVias ); + editMenu->Add( PCB_ACTIONS::cleanupGraphics ); - editMenu->AddSeparator(); - editMenu->AddItem( ACTIONS::deleteTool, SELECTION_CONDITIONS::ShowAlways ); - editMenu->AddItem( PCB_ACTIONS::globalDeletions, SELECTION_CONDITIONS::ShowAlways ); - editMenu->AddItem( PCB_ACTIONS::cleanupTracksAndVias, SELECTION_CONDITIONS::ShowAlways ); - editMenu->AddItem( PCB_ACTIONS::cleanupGraphics, SELECTION_CONDITIONS::ShowAlways ); - - editMenu->Resolve(); //----- View menu ----------------------------------------------------------- // - CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool ); - auto layersPaletteShownCondition = [ this ]( const SELECTION &aSel ) - { - return LayerManagerShown(); - }; - auto microwaveToolbarShownCondition = [ this ]( const SELECTION &aSel ) - { - return MicrowaveToolbarShown(); - }; - auto gridShownCondition = [ this ]( const SELECTION &aSel ) - { - return IsGridVisible(); - }; - auto polarCoordsCondition = [ this ]( const SELECTION &aSel ) - { - return GetShowPolarCoords(); - }; - auto imperialUnitsCondition = [this]( const SELECTION& aSel ) { - return GetUserUnits() == EDA_UNITS::INCHES; - }; - auto metricUnitsCondition = [this]( const SELECTION& aSel ) { - return GetUserUnits() == EDA_UNITS::MILLIMETRES; - }; - auto fullCrosshairCondition = [ this ]( const SELECTION &aSel ) - { - return GetGalDisplayOptions().m_fullscreenCursor; - }; - auto ratsnestShownCondition = [ &disp_opt ]( const SELECTION &aSel ) - { - return disp_opt.m_ShowGlobalRatsnest; - }; - auto curvedRatsnestCondition = [ &disp_opt ]( const SELECTION &aSel ) - { - return disp_opt.m_DisplayRatsnestLinesCurved; - }; - auto boardFlippedCondition = [ this ]( const SELECTION &aSel ) - { - return GetCanvas()->GetView()->IsMirroredX(); - }; - auto zonesFilledCondition = [ &disp_opt ]( const SELECTION &aSel ) - { - return disp_opt.m_ZoneDisplayMode == ZONE_DISPLAY_MODE::SHOW_FILLED; - }; - auto zonesWireframedCondition = [ &disp_opt ]( const SELECTION &aSel ) - { - return disp_opt.m_ZoneDisplayMode == ZONE_DISPLAY_MODE::HIDE_FILLED; - }; - auto zonesOutlinedCondition = [ &disp_opt ]( const SELECTION &aSel ) - { - return disp_opt.m_ZoneDisplayMode == ZONE_DISPLAY_MODE::SHOW_OUTLINED; - }; - auto sketchTracksCondition = [ &disp_opt ]( const SELECTION &aSel ) - { - return !disp_opt.m_DisplayPcbTrackFill; - }; - auto sketchViasCondition = [ &disp_opt ]( const SELECTION &aSel ) - { - return !disp_opt.m_DisplayViaFill; - }; - auto sketchPadsCondition = [ disp_opt ]( const SELECTION &aSel ) - { - return !disp_opt.m_DisplayPadFill; - }; - auto contrastModeCondition = [ &disp_opt ]( const SELECTION &aSel ) - { - return disp_opt.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL; - }; - auto sketchGraphicsCondition = [ &disp_opt ]( const SELECTION &aSel ) - { - return !disp_opt.m_DisplayGraphicsFill; - }; - auto sketchTextOutlinesCondition = [ &disp_opt ]( const SELECTION &aSel ) - { - return !disp_opt.m_DisplayTextFill; - }; + viewMenu->Add( PCB_ACTIONS::showLayersManager, ACTION_MENU::CHECK ); + viewMenu->Add( PCB_ACTIONS::showMicrowaveToolbar, ACTION_MENU::CHECK ); + viewMenu->Add( ACTIONS::showFootprintBrowser ); + viewMenu->Add( ACTIONS::show3DViewer ); - viewMenu->AddCheckItem( PCB_ACTIONS::showLayersManager, layersPaletteShownCondition ); - viewMenu->AddCheckItem( PCB_ACTIONS::showMicrowaveToolbar, microwaveToolbarShownCondition ); - viewMenu->AddItem( ACTIONS::showFootprintBrowser, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::show3DViewer, SELECTION_CONDITIONS::ShowAlways ); + viewMenu->AppendSeparator(); + viewMenu->Add( ACTIONS::zoomInCenter ); + viewMenu->Add( ACTIONS::zoomOutCenter ); + viewMenu->Add( ACTIONS::zoomFitScreen ); + viewMenu->Add( ACTIONS::zoomTool ); + viewMenu->Add( ACTIONS::zoomRedraw ); - viewMenu->AddSeparator(); - viewMenu->AddItem( ACTIONS::zoomInCenter, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomOutCenter, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomFitScreen, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomTool, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomRedraw, SELECTION_CONDITIONS::ShowAlways ); - - viewMenu->AddSeparator(); - viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition ); - viewMenu->AddItem( ACTIONS::gridProperties, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddCheckItem( PCB_ACTIONS::togglePolarCoords, polarCoordsCondition ); + viewMenu->AppendSeparator(); + viewMenu->Add( ACTIONS::toggleGrid, ACTION_MENU::CHECK ); + viewMenu->Add( ACTIONS::gridProperties ); + viewMenu->Add( PCB_ACTIONS::togglePolarCoords, ACTION_MENU::CHECK ); // Units submenu - CONDITIONAL_MENU* unitsSubMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool ); unitsSubMenu->SetTitle( _( "&Units" ) ); unitsSubMenu->SetIcon( unit_mm_xpm ); - unitsSubMenu->AddCheckItem( ACTIONS::imperialUnits, imperialUnitsCondition ); - unitsSubMenu->AddCheckItem( ACTIONS::metricUnits, metricUnitsCondition ); - viewMenu->AddMenu( unitsSubMenu ); + unitsSubMenu->Add( ACTIONS::imperialUnits, ACTION_MENU::CHECK ); + unitsSubMenu->Add( ACTIONS::metricUnits, ACTION_MENU::CHECK ); + viewMenu->Add( unitsSubMenu ); - viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition ); + viewMenu->Add( ACTIONS::toggleCursorStyle, ACTION_MENU::CHECK ); - viewMenu->AddSeparator(); - viewMenu->AddCheckItem( PCB_ACTIONS::showRatsnest, ratsnestShownCondition ); - viewMenu->AddCheckItem( PCB_ACTIONS::ratsnestLineMode, curvedRatsnestCondition ); + viewMenu->AppendSeparator(); + viewMenu->Add( PCB_ACTIONS::showRatsnest, ACTION_MENU::CHECK ); + viewMenu->Add( PCB_ACTIONS::ratsnestLineMode, ACTION_MENU::CHECK ); - viewMenu->AddSeparator(); + viewMenu->AppendSeparator(); // Drawing Mode Submenu - CONDITIONAL_MENU* drawingModeSubMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* drawingModeSubMenu = new ACTION_MENU( false, selTool ); drawingModeSubMenu->SetTitle( _( "&Drawing Mode" ) ); drawingModeSubMenu->SetIcon( add_zone_xpm ); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::zoneDisplayEnable, zonesFilledCondition ); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::zoneDisplayDisable, zonesWireframedCondition ); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::zoneDisplayOutlines, zonesOutlinedCondition ); + drawingModeSubMenu->Add( PCB_ACTIONS::zoneDisplayEnable, ACTION_MENU::CHECK ); + drawingModeSubMenu->Add( PCB_ACTIONS::zoneDisplayDisable, ACTION_MENU::CHECK ); + drawingModeSubMenu->Add( PCB_ACTIONS::zoneDisplayOutlines, ACTION_MENU::CHECK ); - drawingModeSubMenu->AddSeparator(); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::padDisplayMode, sketchPadsCondition ); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::viaDisplayMode, sketchViasCondition ); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::trackDisplayMode, sketchTracksCondition ); + drawingModeSubMenu->AppendSeparator(); + drawingModeSubMenu->Add( PCB_ACTIONS::padDisplayMode, ACTION_MENU::CHECK ); + drawingModeSubMenu->Add( PCB_ACTIONS::viaDisplayMode, ACTION_MENU::CHECK ); + drawingModeSubMenu->Add( PCB_ACTIONS::trackDisplayMode, ACTION_MENU::CHECK ); - drawingModeSubMenu->AddSeparator(); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::graphicsOutlines, sketchGraphicsCondition ); - drawingModeSubMenu->AddCheckItem( PCB_ACTIONS::textOutlines, sketchTextOutlinesCondition ); + drawingModeSubMenu->AppendSeparator(); + drawingModeSubMenu->Add( PCB_ACTIONS::graphicsOutlines, ACTION_MENU::CHECK ); + drawingModeSubMenu->Add( PCB_ACTIONS::textOutlines, ACTION_MENU::CHECK ); - viewMenu->AddMenu( drawingModeSubMenu ); + viewMenu->Add( drawingModeSubMenu ); // Contrast Mode Submenu - CONDITIONAL_MENU* contrastModeSubMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* contrastModeSubMenu = new ACTION_MENU( false, selTool ); contrastModeSubMenu->SetTitle( _( "&Contrast Mode" ) ); contrastModeSubMenu->SetIcon( contrast_mode_xpm ); - contrastModeSubMenu->AddCheckItem( ACTIONS::highContrastMode, contrastModeCondition ); - contrastModeSubMenu->AddItem( PCB_ACTIONS::layerAlphaDec, SELECTION_CONDITIONS::ShowAlways ); - contrastModeSubMenu->AddItem( PCB_ACTIONS::layerAlphaInc, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddMenu( contrastModeSubMenu ); + contrastModeSubMenu->Add( ACTIONS::highContrastMode, ACTION_MENU::CHECK ); + contrastModeSubMenu->Add( PCB_ACTIONS::layerAlphaDec ); + contrastModeSubMenu->Add( PCB_ACTIONS::layerAlphaInc ); + viewMenu->Add( contrastModeSubMenu ); - viewMenu->AddCheckItem( PCB_ACTIONS::flipBoard, boardFlippedCondition ); + viewMenu->Add( PCB_ACTIONS::flipBoard, ACTION_MENU::CHECK ); #ifdef __APPLE__ - viewMenu->AddSeparator(); + viewMenu->AppendSeparator(); #endif - viewMenu->Resolve(); - //-- Place Menu ---------------------------------------------------------- // - CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool ); - placeMenu->AddItem( PCB_ACTIONS::placeModule, SELECTION_CONDITIONS::ShowAlways ); - placeMenu->AddItem( PCB_ACTIONS::drawVia, SELECTION_CONDITIONS::ShowAlways ); - placeMenu->AddItem( PCB_ACTIONS::drawZone, SELECTION_CONDITIONS::ShowAlways ); - placeMenu->AddItem( PCB_ACTIONS::drawZoneKeepout, SELECTION_CONDITIONS::ShowAlways ); - placeMenu->AddItem( PCB_ACTIONS::placeText, SELECTION_CONDITIONS::ShowAlways ); - placeMenu->AddItem( PCB_ACTIONS::drawArc, SELECTION_CONDITIONS::ShowAlways ); - placeMenu->AddItem( PCB_ACTIONS::drawRectangle, SELECTION_CONDITIONS::ShowAlways ); - placeMenu->AddItem( PCB_ACTIONS::drawCircle, SELECTION_CONDITIONS::ShowAlways ); - placeMenu->AddItem( PCB_ACTIONS::drawLine, SELECTION_CONDITIONS::ShowAlways ); - placeMenu->AddItem( PCB_ACTIONS::drawPolygon, SELECTION_CONDITIONS::ShowAlways ); + placeMenu->Add( PCB_ACTIONS::placeModule ); + placeMenu->Add( PCB_ACTIONS::drawVia ); + placeMenu->Add( PCB_ACTIONS::drawZone ); + placeMenu->Add( PCB_ACTIONS::drawZoneKeepout ); + placeMenu->Add( PCB_ACTIONS::placeText ); + placeMenu->Add( PCB_ACTIONS::drawArc ); + placeMenu->Add( PCB_ACTIONS::drawRectangle ); + placeMenu->Add( PCB_ACTIONS::drawCircle ); + placeMenu->Add( PCB_ACTIONS::drawLine ); + placeMenu->Add( PCB_ACTIONS::drawPolygon ); - placeMenu->AddSeparator(); - placeMenu->AddItem( PCB_ACTIONS::drawDimension, SELECTION_CONDITIONS::ShowAlways ); + placeMenu->AppendSeparator(); + placeMenu->Add( PCB_ACTIONS::drawDimension ); - placeMenu->AddSeparator(); - placeMenu->AddItem( PCB_ACTIONS::placeTarget, SELECTION_CONDITIONS::ShowAlways ); + placeMenu->AppendSeparator(); + placeMenu->Add( PCB_ACTIONS::placeTarget ); - placeMenu->AddSeparator(); - placeMenu->AddItem( PCB_ACTIONS::drillOrigin, SELECTION_CONDITIONS::ShowAlways ); - placeMenu->AddItem( ACTIONS::gridSetOrigin, SELECTION_CONDITIONS::ShowAlways ); + placeMenu->AppendSeparator(); + placeMenu->Add( PCB_ACTIONS::drillOrigin ); + placeMenu->Add( ACTIONS::gridSetOrigin ); - placeMenu->AddSeparator(); + placeMenu->AppendSeparator(); ACTION_MENU* autoplaceSubmenu = new ACTION_MENU( false ); autoplaceSubmenu->SetTitle( _( "Auto-Place Footprints" ) ); @@ -434,68 +337,60 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() autoplaceSubmenu->Add( PCB_ACTIONS::autoplaceOffboardComponents ); autoplaceSubmenu->Add( PCB_ACTIONS::autoplaceSelectedComponents ); - placeMenu->AddMenu( autoplaceSubmenu ); + placeMenu->Add( autoplaceSubmenu ); - placeMenu->Resolve(); //-- Route Menu ---------------------------------------------------------- // - CONDITIONAL_MENU* routeMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* routeMenu = new ACTION_MENU( false, selTool ); - routeMenu->AddItem( PCB_ACTIONS::selectLayerPair, SELECTION_CONDITIONS::ShowAlways ); + routeMenu->Add( PCB_ACTIONS::selectLayerPair ); - routeMenu->AddSeparator(); - routeMenu->AddItem( PCB_ACTIONS::routeSingleTrack, SELECTION_CONDITIONS::ShowAlways ); - routeMenu->AddItem( PCB_ACTIONS::routeDiffPair, SELECTION_CONDITIONS::ShowAlways ); + routeMenu->AppendSeparator(); + routeMenu->Add( PCB_ACTIONS::routeSingleTrack ); + routeMenu->Add( PCB_ACTIONS::routeDiffPair ); - routeMenu->AddSeparator(); - routeMenu->AddItem( PCB_ACTIONS::routerTuneSingleTrace, SELECTION_CONDITIONS::ShowAlways ); - routeMenu->AddItem( PCB_ACTIONS::routerTuneDiffPair, SELECTION_CONDITIONS::ShowAlways ); - routeMenu->AddItem( PCB_ACTIONS::routerTuneDiffPairSkew, SELECTION_CONDITIONS::ShowAlways ); + routeMenu->AppendSeparator(); + routeMenu->Add( PCB_ACTIONS::routerTuneSingleTrace ); + routeMenu->Add( PCB_ACTIONS::routerTuneDiffPair ); + routeMenu->Add( PCB_ACTIONS::routerTuneDiffPairSkew ); - routeMenu->AddSeparator(); - routeMenu->AddItem( PCB_ACTIONS::routerSettingsDialog, SELECTION_CONDITIONS::ShowAlways ); + routeMenu->AppendSeparator(); + routeMenu->Add( PCB_ACTIONS::routerSettingsDialog ); - routeMenu->Resolve(); //-- Inspect Menu -------------------------------------------------------- // - CONDITIONAL_MENU* inspectMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* inspectMenu = new ACTION_MENU( false, selTool ); - inspectMenu->AddItem( PCB_ACTIONS::listNets, SELECTION_CONDITIONS::ShowAlways ); - inspectMenu->AddItem( ACTIONS::measureTool, SELECTION_CONDITIONS::ShowAlways ); - inspectMenu->AddItem( PCB_ACTIONS::boardStatistics, SELECTION_CONDITIONS::ShowAlways ); + inspectMenu->Add( PCB_ACTIONS::listNets ); + inspectMenu->Add( ACTIONS::measureTool ); + inspectMenu->Add( PCB_ACTIONS::boardStatistics ); - inspectMenu->AddSeparator(); - inspectMenu->AddItem( PCB_ACTIONS::runDRC, SELECTION_CONDITIONS::ShowAlways ); + inspectMenu->AppendSeparator(); + inspectMenu->Add( PCB_ACTIONS::runDRC ); - inspectMenu->Resolve(); //-- Tools menu ---------------------------------------------------------- // - CONDITIONAL_MENU* toolsMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool ); - toolsMenu->AddItem( ACTIONS::updatePcbFromSchematic, SELECTION_CONDITIONS::ShowAlways ); - toolsMenu->AddItem( ACTIONS::updateSchematicFromPcb, SELECTION_CONDITIONS::ShowAlways ); - toolsMenu->AddItem( PCB_ACTIONS::showEeschema, SELECTION_CONDITIONS::ShowAlways ); + toolsMenu->Add( ACTIONS::updatePcbFromSchematic ); + toolsMenu->Add( ACTIONS::updateSchematicFromPcb ); + toolsMenu->Add( PCB_ACTIONS::showEeschema ); - toolsMenu->AddSeparator(); - toolsMenu->AddItem( ACTIONS::showFootprintEditor, SELECTION_CONDITIONS::ShowAlways ); - toolsMenu->AddItem( PCB_ACTIONS::updateFootprints, SELECTION_CONDITIONS::ShowAlways ); - toolsMenu->AddItem( PCB_ACTIONS::boardReannotate, SELECTION_CONDITIONS::ShowAlways ); + toolsMenu->AppendSeparator(); + toolsMenu->Add( ACTIONS::showFootprintEditor ); + toolsMenu->Add( PCB_ACTIONS::updateFootprints ); + toolsMenu->Add( PCB_ACTIONS::boardReannotate ); - toolsMenu->AddSeparator(); - toolsMenu->AddItem( PCB_ACTIONS::removeUnusedPads, SELECTION_CONDITIONS::ShowAlways ); - toolsMenu->AddItem( PCB_ACTIONS::repairBoard, SELECTION_CONDITIONS::ShowAlways ); + toolsMenu->AppendSeparator(); + toolsMenu->Add( PCB_ACTIONS::removeUnusedPads ); + toolsMenu->Add( PCB_ACTIONS::repairBoard ); #if defined(KICAD_SCRIPTING_WXPYTHON) - auto pythonConsoleShownCondition = [] ( const SELECTION& aSel ) { - wxMiniFrame* pythonConsole = (wxMiniFrame *) PCB_EDIT_FRAME::findPythonConsole(); - return pythonConsole && pythonConsole->IsShown(); - }; - - toolsMenu->AddSeparator(); - toolsMenu->AddCheckItem( PCB_ACTIONS::showPythonConsole, pythonConsoleShownCondition ); + toolsMenu->AppendSeparator(); + toolsMenu->Add( PCB_ACTIONS::showPythonConsole ); #endif #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU) @@ -506,68 +401,62 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() submenuActionPlugins->Add( _( "Refresh Plugins" ), _( "Reload all python plugins and refresh plugin menus" ), - ID_TOOLBARH_PCB_ACTION_PLUGIN_REFRESH, reload_xpm ); + ID_TOOLBARH_PCB_ACTION_PLUGIN_REFRESH, + reload_xpm ); #ifdef __APPLE__ submenuActionPlugins->Add( _( "Reveal Plugin Folder in Finder" ), _( "Reveals the plugins folder in a Finder window" ), - ID_TOOLBARH_PCB_ACTION_PLUGIN_SHOW_FOLDER, folder_xpm ); + ID_TOOLBARH_PCB_ACTION_PLUGIN_SHOW_FOLDER, + folder_xpm ); #else submenuActionPlugins->Add( _( "Open Plugin Directory" ), _( "Opens the directory in the default system file manager" ), - ID_TOOLBARH_PCB_ACTION_PLUGIN_SHOW_FOLDER, folder_xpm ); + ID_TOOLBARH_PCB_ACTION_PLUGIN_SHOW_FOLDER, + folder_xpm ); #endif submenuActionPlugins->AppendSeparator(); - toolsMenu->AddSeparator(); - toolsMenu->AddMenu( submenuActionPlugins, SELECTION_CONDITIONS::ShowAlways ); + toolsMenu->AppendSeparator(); + toolsMenu->Add( submenuActionPlugins ); #endif - toolsMenu->Resolve(); //-- Preferences menu ---------------------------------------------------- // - CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* prefsMenu = new ACTION_MENU( false, selTool ); - auto acceleratedGraphicsCondition = [ this ] ( const SELECTION& aSel ) { - return GetCanvas()->GetBackend() == EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL; - }; - auto standardGraphicsCondition = [ this ] ( const SELECTION& aSel ) { - return GetCanvas()->GetBackend() == EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO; - }; - - prefsMenu->AddItem( ACTIONS::configurePaths, SELECTION_CONDITIONS::ShowAlways ); - prefsMenu->AddItem( ACTIONS::showFootprintLibTable, SELECTION_CONDITIONS::ShowAlways ); + prefsMenu->Add( ACTIONS::configurePaths ); + prefsMenu->Add( ACTIONS::showFootprintLibTable ); #ifdef BUILD_GITHUB_PLUGIN - prefsMenu->AddItem( ID_PCB_3DSHAPELIB_WIZARD, - _( "Add &3D Shapes Libraries Wizard..." ), - _( "Download 3D shape libraries from GitHub" ), - import3d_xpm, SELECTION_CONDITIONS::ShowAlways ); + prefsMenu->Add( _( "Add &3D Shapes Libraries Wizard..." ), + _( "Download 3D shape libraries from GitHub" ), + ID_PCB_3DSHAPELIB_WIZARD, + import3d_xpm ); #endif - prefsMenu->AddItem( wxID_PREFERENCES, - _( "Preferences...\tCTRL+," ), - _( "Show preferences for all open tools" ), - preference_xpm, SELECTION_CONDITIONS::ShowAlways ); + prefsMenu->Add( _( "Preferences...\tCTRL+," ), + _( "Show preferences for all open tools" ), + wxID_PREFERENCES, + preference_xpm ); - prefsMenu->AddSeparator(); + prefsMenu->AppendSeparator(); AddMenuLanguageList( prefsMenu, selTool ); - prefsMenu->AddSeparator(); - prefsMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition ); - prefsMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition ); + prefsMenu->AppendSeparator(); + prefsMenu->Add( ACTIONS::acceleratedGraphics, ACTION_MENU::CHECK ); + prefsMenu->Add( ACTIONS::standardGraphics, ACTION_MENU::CHECK ); - prefsMenu->Resolve(); //--MenuBar ----------------------------------------------------------- // - menuBar->Append( fileMenu, _( "&File" ) ); - menuBar->Append( editMenu, _( "&Edit" ) ); - menuBar->Append( viewMenu, _( "&View" ) ); - menuBar->Append( placeMenu, _( "&Place" ) ); - menuBar->Append( routeMenu, _( "Ro&ute" ) ); + menuBar->Append( fileMenu, _( "&File" ) ); + menuBar->Append( editMenu, _( "&Edit" ) ); + menuBar->Append( viewMenu, _( "&View" ) ); + menuBar->Append( placeMenu, _( "&Place" ) ); + menuBar->Append( routeMenu, _( "Ro&ute" ) ); menuBar->Append( inspectMenu, _( "&Inspect" ) ); - menuBar->Append( toolsMenu, _( "&Tools" ) ); - menuBar->Append( prefsMenu, _( "P&references" ) ); + menuBar->Append( toolsMenu, _( "&Tools" ) ); + menuBar->Append( prefsMenu, _( "P&references" ) ); AddStandardHelpMenu( menuBar ); SetMenuBar( menuBar ); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 1e58cc0530..c71fd0fb00 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,7 @@ #include #include #include +#include #include #include #include @@ -219,6 +221,10 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : ReCreateOptToolbar(); ReCreateMicrowaveVToolbar(); + // We call this after the toolbars have been created to ensure the layer widget button handler + // doesn't cause problems + setupUIConditions(); + m_selectionFilterPanel = new PANEL_SELECTION_FILTER( this ); // Create the infobar @@ -443,6 +449,12 @@ bool PCB_EDIT_FRAME::isAutoSaveRequired() const } +SELECTION& PCB_EDIT_FRAME::GetCurrentSelection() +{ + return m_toolManager->GetTool()->GetSelection(); +} + + void PCB_EDIT_FRAME::setupTools() { // Create the manager and dispatcher & route draw panel events to the dispatcher @@ -483,6 +495,188 @@ void PCB_EDIT_FRAME::setupTools() } +void PCB_EDIT_FRAME::setupUIConditions() +{ + PCB_BASE_EDIT_FRAME::setupUIConditions(); + + ACTION_MANAGER* mgr = m_toolManager->GetActionManager(); + PCB_EDITOR_CONDITIONS cond( this ); + + wxASSERT( mgr ); + +#define ENABLE( x ) ACTION_CONDITIONS().Enable( x ) +#define CHECK( x ) ACTION_CONDITIONS().Check( x ) + + mgr->SetConditions( ACTIONS::save, ENABLE( cond.ContentModified() ) ); + mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) ); + mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) ); + + mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) ); + mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) ); + mgr->SetConditions( ACTIONS::togglePolarCoords, CHECK( cond.PolarCoordinates() ) ); + mgr->SetConditions( ACTIONS::metricUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) ); + mgr->SetConditions( ACTIONS::imperialUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) ); + mgr->SetConditions( ACTIONS::acceleratedGraphics, CHECK( cond.CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL ) ) ); + mgr->SetConditions( ACTIONS::standardGraphics, CHECK( cond.CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ) ) ); + + mgr->SetConditions( ACTIONS::cut, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); + mgr->SetConditions( ACTIONS::copy, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); + mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) ); + mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) ); + mgr->SetConditions( ACTIONS::doDelete, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); + mgr->SetConditions( ACTIONS::duplicate, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); + + mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::viaDisplayMode, CHECK( !cond.ViaFillDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::trackDisplayMode, CHECK( !cond.TrackFillDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::zoneDisplayEnable, CHECK( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FILLED ) ) ); + mgr->SetConditions( PCB_ACTIONS::zoneDisplayDisable, CHECK( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::HIDE_FILLED ) ) ); + mgr->SetConditions( PCB_ACTIONS::zoneDisplayOutlines, CHECK( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_OUTLINED ) ) ); + + +#if defined( KICAD_SCRIPTING_WXPYTHON ) + auto pythonConsoleCond = + [] ( const SELECTION& ) + { + if( IsWxPythonLoaded() ) + { + wxWindow* console = PCB_EDIT_FRAME::findPythonConsole(); + return console && console->IsShown(); + } + + return false; + }; + + mgr->SetConditions( PCB_ACTIONS::showPythonConsole, CHECK( pythonConsoleCond ) ); +#endif + + + auto enableBoardSetupCondition = + [this] ( const SELECTION& ) + { + if( DRC* tool = m_toolManager->GetTool() ) + return !tool->IsDRCDialogShown(); + + return true; + }; + + auto boardFlippedCond = + [this]( const SELECTION& ) + { + return GetCanvas()->GetView()->IsMirroredX(); + }; + + auto layerManagerCond = + [this] ( const SELECTION& ) + { + return LayerManagerShown(); + }; + + auto microwaveToolbarCond = + [this] ( const SELECTION& ) + { + return MicrowaveToolbarShown(); + }; + + auto highContrastCond = + [this] ( const SELECTION& ) + { + return GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL; + }; + + auto globalRatsnestCond = + [this] (const SELECTION& ) + { + return GetDisplayOptions().m_ShowGlobalRatsnest; + }; + + auto curvedRatsnestCond = + [this] (const SELECTION& ) + { + return GetDisplayOptions().m_DisplayRatsnestLinesCurved; + }; + + mgr->SetConditions( ACTIONS::highContrastMode, CHECK( highContrastCond ) ); + mgr->SetConditions( PCB_ACTIONS::flipBoard, CHECK( boardFlippedCond ) ); + mgr->SetConditions( PCB_ACTIONS::showLayersManager, CHECK( layerManagerCond ) ); + mgr->SetConditions( PCB_ACTIONS::showMicrowaveToolbar, CHECK( microwaveToolbarCond ) ); + mgr->SetConditions( PCB_ACTIONS::showRatsnest, CHECK( globalRatsnestCond ) ); + mgr->SetConditions( PCB_ACTIONS::ratsnestLineMode, CHECK( curvedRatsnestCond ) ); + mgr->SetConditions( PCB_ACTIONS::boardSetup , ENABLE( enableBoardSetupCondition ) ); + + + auto isHighlightMode = + [this]( const SELECTION& ) + { + ROUTER_TOOL* tool = m_toolManager->GetTool(); + return tool->GetRouterMode() == PNS::RM_MarkObstacles; + }; + + auto isShoveMode = + [this]( const SELECTION& ) + { + ROUTER_TOOL* tool = m_toolManager->GetTool(); + return tool->GetRouterMode() == PNS::RM_Shove; + }; + + auto isWalkaroundMode = + [this]( const SELECTION& ) + { + ROUTER_TOOL* tool = m_toolManager->GetTool(); + return tool->GetRouterMode() == PNS::RM_Walkaround; + }; + + mgr->SetConditions( PCB_ACTIONS::routerHighlightMode, CHECK( isHighlightMode ) ); + mgr->SetConditions( PCB_ACTIONS::routerShoveMode, CHECK( isShoveMode ) ); + mgr->SetConditions( PCB_ACTIONS::routerWalkaroundMode, CHECK( isWalkaroundMode ) ); + + // The layer indicator is special, so we register a callback directly that will regenerate the + // bitmap instead of using the conditions system + auto layerIndicatorUpdate = + [this] ( wxUpdateUIEvent& ) + { + PrepareLayerIndicator(); + }; + + Bind( wxEVT_UPDATE_UI, layerIndicatorUpdate, PCB_ACTIONS::selectLayerPair.GetUIId() ); + + +#define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) ) + + CURRENT_TOOL( ACTIONS::zoomTool ); + CURRENT_TOOL( ACTIONS::deleteTool ); + CURRENT_TOOL( ACTIONS::measureTool ); + CURRENT_TOOL( ACTIONS::selectionTool ); + CURRENT_TOOL( PCB_ACTIONS::highlightNetTool ); + CURRENT_TOOL( PCB_ACTIONS::localRatsnestTool ); + CURRENT_TOOL( PCB_ACTIONS::placeModule ); + CURRENT_TOOL( PCB_ACTIONS::routeSingleTrack); + CURRENT_TOOL( PCB_ACTIONS::drawVia ); + CURRENT_TOOL( PCB_ACTIONS::drawZone ); + CURRENT_TOOL( PCB_ACTIONS::drawZoneKeepout ); + CURRENT_TOOL( PCB_ACTIONS::drawLine ); + CURRENT_TOOL( PCB_ACTIONS::drawRectangle ); + CURRENT_TOOL( PCB_ACTIONS::drawCircle ); + CURRENT_TOOL( PCB_ACTIONS::drawArc ); + CURRENT_TOOL( PCB_ACTIONS::drawPolygon ); + CURRENT_TOOL( PCB_ACTIONS::placeText ); + CURRENT_TOOL( PCB_ACTIONS::drawDimension ); + CURRENT_TOOL( PCB_ACTIONS::placeTarget ); + CURRENT_TOOL( PCB_ACTIONS::drillOrigin ); + CURRENT_TOOL( PCB_ACTIONS::gridSetOrigin ); + + CURRENT_TOOL( PCB_ACTIONS::microwaveCreateLine ); + CURRENT_TOOL( PCB_ACTIONS::microwaveCreateGap ); + CURRENT_TOOL( PCB_ACTIONS::microwaveCreateStub ); + CURRENT_TOOL( PCB_ACTIONS::microwaveCreateStubArc ); + CURRENT_TOOL( PCB_ACTIONS::microwaveCreateFunctionShape ); + +#undef CURRENT_TOOL +#undef ENABLE +#undef CHECK +} + + void PCB_EDIT_FRAME::OnQuit( wxCommandEvent& event ) { if( event.GetId() == wxID_EXIT ) @@ -1374,3 +1568,15 @@ wxString PCB_EDIT_FRAME::GetCurrentFileName() const { return GetBoard()->GetFileName(); } + + +bool PCB_EDIT_FRAME::LayerManagerShown() +{ + return m_auimgr.GetPane( "LayersManager" ).IsShown(); +} + + +bool PCB_EDIT_FRAME::MicrowaveToolbarShown() +{ + return m_auimgr.GetPane( "MicrowaveToolbar" ).IsShown(); +} diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 12d30e4054..80b1c71812 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -52,6 +52,7 @@ class DRAWSEGMENT; class GENERAL_COLLECTOR; class GENERAL_COLLECTORS_GUIDE; class PCB_LAYER_WIDGET; +class SELECTION; class MARKER_PCB; class BOARD_ITEM; class PCB_LAYER_BOX_SELECTOR; @@ -122,6 +123,7 @@ protected: // The Tool Framework initalization void setupTools(); + void setupUIConditions() override; /** * switches currently used canvas (Cairo / OpenGL). @@ -926,10 +928,10 @@ public: void ProjectChanged() override; - void SyncToolbars() override; - wxString GetCurrentFileName() const override; + SELECTION& GetCurrentSelection() override; + DECLARE_EVENT_TABLE() }; diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 16ae782cc8..3671f971d0 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -58,7 +58,6 @@ #include "invoke_pcb_dialog.h" #include "dialog_global_fp_lib_table_config.h" -extern bool IsWxPythonLoaded(); namespace PCB { diff --git a/pcbnew/swig/python_scripting.h b/pcbnew/swig/python_scripting.h index c67abe3804..1428562c41 100644 --- a/pcbnew/swig/python_scripting.h +++ b/pcbnew/swig/python_scripting.h @@ -92,6 +92,8 @@ void RedirectStdio(); wxWindow* CreatePythonShellWindow( wxWindow* parent, const wxString& aFramenameId ); #endif +bool IsWxPythonLoaded(); + #if 0 && defined (KICAD_SCRIPTING_WXPYTHON) // This definition of PyLOCK crashed Pcbnew under some conditions (JPC), // especially reloading plugins diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp index ead227f1cd..c10594a0ed 100644 --- a/pcbnew/toolbars_footprint_editor.cpp +++ b/pcbnew/toolbars_footprint_editor.cpp @@ -215,73 +215,3 @@ void FOOTPRINT_EDIT_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent ) { m_selLayerBox->SetLayerSelection( GetActiveLayer() ); } - - -void FOOTPRINT_EDIT_FRAME::SyncToolbars() -{ -#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, true, IsCurrentTool( tool ) ) - - if( !m_mainToolBar || !m_optionsToolBar || !m_drawToolBar ) - return; - - auto& opts = GetDisplayOptions(); - - if( IsCurrentFPFromBoard() ) - m_mainToolBar->Toggle( PCB_ACTIONS::saveToBoard, IsContentModified() ); - else - m_mainToolBar->Toggle( PCB_ACTIONS::saveToLibrary, IsContentModified() ); - - m_mainToolBar->Toggle( ACTIONS::undo, GetUndoCommandCount() > 0 ); - m_mainToolBar->Toggle( ACTIONS::redo, GetRedoCommandCount() > 0 ); - TOGGLE_TOOL( m_mainToolBar, ACTIONS::zoomTool ); - m_mainToolBar->Toggle( PCB_ACTIONS::footprintProperties, GetBoard()->GetFirstModule() ); - m_mainToolBar->Refresh(); - - bool hcm = opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL; - - m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() ); - m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != EDA_UNITS::INCHES ); - m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == EDA_UNITS::INCHES ); - m_optionsToolBar->Toggle( ACTIONS::togglePolarCoords, GetShowPolarCoords() ); - m_optionsToolBar->Toggle( PCB_ACTIONS::padDisplayMode, !opts.m_DisplayPadFill ); - m_optionsToolBar->Toggle( PCB_ACTIONS::textOutlines, !opts.m_DisplayTextFill ); - m_optionsToolBar->Toggle( PCB_ACTIONS::graphicsOutlines, !opts.m_DisplayGraphicsFill ); - m_optionsToolBar->Toggle( ACTIONS::highContrastMode, hcm ); - m_optionsToolBar->Toggle( PCB_ACTIONS::toggleFootprintTree, IsSearchTreeShown() ); - m_optionsToolBar->Refresh(); - - if( GetLoadedFPID().empty() ) - { - // If there is no footprint loaded, disable the editing tools - m_drawToolBar->Toggle( PCB_ACTIONS::placePad, false, false ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawLine, false, false ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawRectangle, false, false ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawCircle, false, false ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawArc, false, false ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawPolygon, false, false ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawZoneKeepout, false, false ); - m_drawToolBar->Toggle( PCB_ACTIONS::placeText, false, false ); - m_drawToolBar->Toggle( ACTIONS::deleteTool, false, false ); - m_drawToolBar->Toggle( PCB_ACTIONS::setAnchor, false, false ); - m_drawToolBar->Toggle( PCB_ACTIONS::gridSetOrigin, false, false ); - m_drawToolBar->Toggle( ACTIONS::measureTool, false, false ); - } - else - { - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placePad ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawLine ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawRectangle ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawCircle ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawArc ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawPolygon ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawZoneKeepout ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeText ); - TOGGLE_TOOL( m_drawToolBar, ACTIONS::deleteTool ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::setAnchor ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::gridSetOrigin ); - TOGGLE_TOOL( m_drawToolBar, ACTIONS::measureTool ); - } - - TOGGLE_TOOL( m_drawToolBar, ACTIONS::selectionTool ); - m_drawToolBar->Refresh(); -} diff --git a/pcbnew/toolbars_footprint_viewer.cpp b/pcbnew/toolbars_footprint_viewer.cpp index b5206caae6..8702f55ccf 100644 --- a/pcbnew/toolbars_footprint_viewer.cpp +++ b/pcbnew/toolbars_footprint_viewer.cpp @@ -130,29 +130,6 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateVToolbar() } -void FOOTPRINT_VIEWER_FRAME::SyncToolbars() -{ - m_mainToolBar->Toggle( ACTIONS::zoomTool, IsCurrentTool( ACTIONS::zoomTool ) ); - m_mainToolBar->Toggle( PCB_ACTIONS::zoomFootprintAutomatically, GetAutoZoom() ); - m_mainToolBar->Refresh(); - - m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() ); - m_optionsToolBar->Toggle( ACTIONS::selectionTool, IsCurrentTool( ACTIONS::selectionTool ) ); - m_optionsToolBar->Toggle( ACTIONS::measureTool, IsCurrentTool( ACTIONS::measureTool ) ); - m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != EDA_UNITS::INCHES ); - m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == EDA_UNITS::INCHES ); - - const PCB_DISPLAY_OPTIONS& opts = GetDisplayOptions(); - - m_optionsToolBar->Toggle( PCB_ACTIONS::showPadNumbers, opts.m_DisplayPadNum ); - m_optionsToolBar->Toggle( PCB_ACTIONS::padDisplayMode, !opts.m_DisplayPadFill ); - m_optionsToolBar->Toggle( PCB_ACTIONS::textOutlines, !opts.m_DisplayTextFill ); - m_optionsToolBar->Toggle( PCB_ACTIONS::graphicsOutlines, !opts.m_DisplayGraphicsFill ); - - m_optionsToolBar->Refresh(); -} - - void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar() { SELECTION_TOOL* selTool = m_toolManager->GetTool(); @@ -161,28 +138,27 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar() wxMenuBar* oldMenuBar = GetMenuBar(); WX_MENUBAR* menuBar = new WX_MENUBAR(); + //----- File menu ----------------------------------------------------------- // - CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool ); fileMenu->AddClose( _( "Footprint Viewer" ) ); - fileMenu->Resolve(); //----- View menu ----------------------------------------------------------- // - CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool ); + ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool ); - viewMenu->AddSeparator(); - viewMenu->AddItem( ACTIONS::zoomInCenter, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomOutCenter, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomFitScreen, SELECTION_CONDITIONS::ShowAlways ); - viewMenu->AddItem( ACTIONS::zoomRedraw, SELECTION_CONDITIONS::ShowAlways ); + viewMenu->AppendSeparator(); + viewMenu->Add( ACTIONS::zoomInCenter ); + viewMenu->Add( ACTIONS::zoomOutCenter ); + viewMenu->Add( ACTIONS::zoomFitScreen ); + viewMenu->Add( ACTIONS::zoomRedraw ); - viewMenu->AddSeparator(); - viewMenu->AddItem( ACTIONS::show3DViewer, SELECTION_CONDITIONS::ShowAlways ); + viewMenu->AppendSeparator(); + viewMenu->Add( ACTIONS::show3DViewer ); - viewMenu->Resolve(); //----- Menubar ------------------------------------------------------------- // diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index c9f68df610..27396c49f2 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -49,7 +49,9 @@ #include #include -extern bool IsWxPythonLoaded(); +#if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON) +#include +#endif #define SEL_LAYER_HELP _( \ "Show active layer selections\nand select layer pair for route and place via" ) @@ -386,39 +388,19 @@ void PCB_EDIT_FRAME::ReCreateVToolbar() m_drawToolBar->Add( PCB_ACTIONS::gridSetOrigin, ACTION_TOOLBAR::TOGGLE ); m_drawToolBar->Add( ACTIONS::measureTool, ACTION_TOOLBAR::TOGGLE ); - auto isHighlightMode = - [this]( const SELECTION& aSel ) - { - ROUTER_TOOL* tool = m_toolManager->GetTool(); - return tool->GetRouterMode() == PNS::RM_MarkObstacles; - }; + SELECTION_TOOL* selTool = m_toolManager->GetTool(); + ACTION_MENU* routeMenu = new ACTION_MENU( false, selTool ); + routeMenu->Add( PCB_ACTIONS::routerHighlightMode, ACTION_MENU::CHECK ); + routeMenu->Add( PCB_ACTIONS::routerShoveMode, ACTION_MENU::CHECK ); + routeMenu->Add( PCB_ACTIONS::routerWalkaroundMode, ACTION_MENU::CHECK ); - auto isShoveMode = - [this]( const SELECTION& aSel ) - { - ROUTER_TOOL* tool = m_toolManager->GetTool(); - return tool->GetRouterMode() == PNS::RM_Shove; - }; - - auto isWalkaroundMode = - [this]( const SELECTION& aSel ) - { - ROUTER_TOOL* tool = m_toolManager->GetTool(); - return tool->GetRouterMode() == PNS::RM_Walkaround; - }; - - SELECTION_TOOL* selTool = m_toolManager->GetTool(); - CONDITIONAL_MENU* routeMenu = new CONDITIONAL_MENU( false, selTool ); - routeMenu->AddCheckItem( PCB_ACTIONS::routerHighlightMode, isHighlightMode ); - routeMenu->AddCheckItem( PCB_ACTIONS::routerShoveMode, isShoveMode ); - routeMenu->AddCheckItem( PCB_ACTIONS::routerWalkaroundMode, isWalkaroundMode ); - routeMenu->AddSeparator(); - routeMenu->AddItem( PCB_ACTIONS::routerSettingsDialog, SELECTION_CONDITIONS::ShowAlways ); + routeMenu->AppendSeparator(); + routeMenu->Add( PCB_ACTIONS::routerSettingsDialog ); m_drawToolBar->AddToolContextMenu( PCB_ACTIONS::routeSingleTrack, routeMenu ); - CONDITIONAL_MENU* zoneMenu = new CONDITIONAL_MENU( false, selTool ); - zoneMenu->AddItem( PCB_ACTIONS::zoneFillAll, SELECTION_CONDITIONS::ShowAlways ); - zoneMenu->AddItem( PCB_ACTIONS::zoneUnfillAll, SELECTION_CONDITIONS::ShowAlways ); + ACTION_MENU* zoneMenu = new ACTION_MENU( false, selTool ); + zoneMenu->Add( PCB_ACTIONS::zoneFillAll ); + zoneMenu->Add( PCB_ACTIONS::zoneUnfillAll ); m_drawToolBar->AddToolContextMenu( PCB_ACTIONS::drawZone, zoneMenu ); m_drawToolBar->Realize(); @@ -682,95 +664,3 @@ void PCB_EDIT_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent ) { m_SelLayerBox->SetLayerSelection( GetActiveLayer() ); } - - -bool PCB_EDIT_FRAME::LayerManagerShown() -{ - return m_auimgr.GetPane( "LayersManager" ).IsShown(); -} - -bool PCB_EDIT_FRAME::MicrowaveToolbarShown() -{ - return m_auimgr.GetPane( "MicrowaveToolbar" ).IsShown(); -} - - -void PCB_EDIT_FRAME::SyncToolbars() -{ -#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) ) - - if( !m_mainToolBar || !m_optionsToolBar || !m_drawToolBar || !m_microWaveToolBar ) - return; - - auto& opts = GetDisplayOptions(); - KIGFX::GAL_DISPLAY_OPTIONS& galOpts = GetGalDisplayOptions(); - ZONE_DISPLAY_MODE zoneMode = opts.m_ZoneDisplayMode; - - m_mainToolBar->Toggle( ACTIONS::save, IsContentModified() ); - m_mainToolBar->Toggle( ACTIONS::undo, GetUndoCommandCount() > 0 ); - m_mainToolBar->Toggle( ACTIONS::redo, GetRedoCommandCount() > 0 ); - TOGGLE_TOOL( m_mainToolBar, ACTIONS::zoomTool ); -#if defined(KICAD_SCRIPTING_WXPYTHON) - if( IsWxPythonLoaded() ) - { - wxMiniFrame* console = (wxMiniFrame *) PCB_EDIT_FRAME::findPythonConsole(); - m_mainToolBar->Toggle( PCB_ACTIONS::showPythonConsole, console && console->IsShown() ); - } -#endif - m_mainToolBar->Refresh(); - - PrepareLayerIndicator(); - - m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() ); - m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != EDA_UNITS::INCHES ); - m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == EDA_UNITS::INCHES ); - m_optionsToolBar->Toggle( ACTIONS::togglePolarCoords, GetShowPolarCoords() ); - m_optionsToolBar->Toggle( ACTIONS::toggleCursorStyle, galOpts.m_fullscreenCursor ); - m_optionsToolBar->Toggle( PCB_ACTIONS::showRatsnest, opts.m_ShowGlobalRatsnest ); - m_optionsToolBar->Toggle( PCB_ACTIONS::ratsnestLineMode, opts.m_DisplayRatsnestLinesCurved ); - m_optionsToolBar->Toggle( PCB_ACTIONS::showLayersManager, LayerManagerShown() ); - m_optionsToolBar->Toggle( PCB_ACTIONS::showMicrowaveToolbar, MicrowaveToolbarShown() ); - - m_optionsToolBar->Toggle( PCB_ACTIONS::zoneDisplayEnable, - zoneMode == ZONE_DISPLAY_MODE::SHOW_FILLED ); - m_optionsToolBar->Toggle( PCB_ACTIONS::zoneDisplayDisable, - zoneMode == ZONE_DISPLAY_MODE::HIDE_FILLED ); - m_optionsToolBar->Toggle( PCB_ACTIONS::zoneDisplayOutlines, - zoneMode == ZONE_DISPLAY_MODE::SHOW_OUTLINED ); - - m_optionsToolBar->Toggle( PCB_ACTIONS::trackDisplayMode, !opts.m_DisplayPcbTrackFill ); - m_optionsToolBar->Toggle( PCB_ACTIONS::viaDisplayMode, !opts.m_DisplayViaFill ); - m_optionsToolBar->Toggle( PCB_ACTIONS::padDisplayMode, !opts.m_DisplayPadFill ); - m_optionsToolBar->Toggle( ACTIONS::highContrastMode, - opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL ); - m_optionsToolBar->Refresh(); - - TOGGLE_TOOL( m_drawToolBar, ACTIONS::selectionTool ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::highlightNetTool ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::localRatsnestTool ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeModule ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::routeSingleTrack ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawVia ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawZone ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawZoneKeepout ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawLine ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawRectangle ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawCircle ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawArc ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawPolygon ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeText ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawDimension ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeTarget ); - TOGGLE_TOOL( m_drawToolBar, ACTIONS::deleteTool ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drillOrigin ); - TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::gridSetOrigin ); - TOGGLE_TOOL( m_drawToolBar, ACTIONS::measureTool ); - m_drawToolBar->Refresh(); - - TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateLine ); - TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateGap ); - TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateStub ); - TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateStubArc ); - TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateFunctionShape ); - m_microWaveToolBar->Refresh(); -} diff --git a/pcbnew/tools/pcb_editor_conditions.cpp b/pcbnew/tools/pcb_editor_conditions.cpp new file mode 100644 index 0000000000..db4ccfe28d --- /dev/null +++ b/pcbnew/tools/pcb_editor_conditions.cpp @@ -0,0 +1,153 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Ian McInerney + * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + + +#include +#include +#include + +#include +#include + +using namespace std::placeholders; + + +SELECTION_CONDITION PCB_EDITOR_CONDITIONS::PadNumbersDisplay() +{ + // Requires a PCB_BASE_FRAME + PCB_BASE_FRAME* drwFrame = dynamic_cast( m_frame ); + + wxASSERT( drwFrame ); + + return std::bind( &PCB_EDITOR_CONDITIONS::padNumberDisplayFunc, _1, drwFrame ); +} + + +SELECTION_CONDITION PCB_EDITOR_CONDITIONS::PadFillDisplay() +{ + // Requires a PCB_BASE_FRAME + PCB_BASE_FRAME* drwFrame = dynamic_cast( m_frame ); + + wxASSERT( drwFrame ); + + return std::bind( &PCB_EDITOR_CONDITIONS::padFillDisplayFunc, _1, drwFrame ); +} + + +SELECTION_CONDITION PCB_EDITOR_CONDITIONS::TextFillDisplay() +{ + // Requires a PCB_BASE_FRAME + PCB_BASE_FRAME* drwFrame = dynamic_cast( m_frame ); + + wxASSERT( drwFrame ); + + return std::bind( &PCB_EDITOR_CONDITIONS::textFillDisplayFunc, _1, drwFrame ); +} + + +SELECTION_CONDITION PCB_EDITOR_CONDITIONS::GraphicsFillDisplay() +{ + // Requires a PCB_BASE_FRAME + PCB_BASE_FRAME* drwFrame = dynamic_cast( m_frame ); + + wxASSERT( drwFrame ); + + return std::bind( &PCB_EDITOR_CONDITIONS::graphicsFillDisplayFunc, _1, drwFrame ); +} + + +SELECTION_CONDITION PCB_EDITOR_CONDITIONS::ViaFillDisplay() +{ + // Requires a PCB_BASE_FRAME + PCB_BASE_FRAME* drwFrame = dynamic_cast( m_frame ); + + wxASSERT( drwFrame ); + + return std::bind( &PCB_EDITOR_CONDITIONS::viaFillDisplayFunc, _1, drwFrame ); +} + + +SELECTION_CONDITION PCB_EDITOR_CONDITIONS::TrackFillDisplay() +{ + // Requires a PCB_BASE_FRAME + PCB_BASE_FRAME* drwFrame = dynamic_cast( m_frame ); + + wxASSERT( drwFrame ); + + return std::bind( &PCB_EDITOR_CONDITIONS::trackFillDisplayFunc, _1, drwFrame ); +} + + +SELECTION_CONDITION PCB_EDITOR_CONDITIONS::ZoneDisplayMode( ZONE_DISPLAY_MODE aMode ) +{ + // Requires a PCB_BASE_FRAME + PCB_BASE_FRAME* drwFrame = dynamic_cast( m_frame ); + + wxASSERT( drwFrame ); + + return std::bind( &PCB_EDITOR_CONDITIONS::zoneDisplayModeFunc, _1, drwFrame, aMode ); +} + + +bool PCB_EDITOR_CONDITIONS::padNumberDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) +{ + return aFrame->GetDisplayOptions().m_DisplayPadNum; +} + + +bool PCB_EDITOR_CONDITIONS::padFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) +{ + return aFrame->GetDisplayOptions().m_DisplayPadFill; +} + + +bool PCB_EDITOR_CONDITIONS::textFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) +{ + return aFrame->GetDisplayOptions().m_DisplayTextFill; +} + + +bool PCB_EDITOR_CONDITIONS::graphicsFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) +{ + return aFrame->GetDisplayOptions().m_DisplayGraphicsFill; +} + + +bool PCB_EDITOR_CONDITIONS::viaFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) +{ + return aFrame->GetDisplayOptions().m_DisplayViaFill; +} + + +bool PCB_EDITOR_CONDITIONS::trackFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) +{ + return aFrame->GetDisplayOptions().m_DisplayPcbTrackFill; +} + + +bool PCB_EDITOR_CONDITIONS::zoneDisplayModeFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame, + ZONE_DISPLAY_MODE aMode ) +{ + return aFrame->GetDisplayOptions().m_ZoneDisplayMode == aMode; +} diff --git a/pcbnew/tools/pcb_editor_conditions.h b/pcbnew/tools/pcb_editor_conditions.h new file mode 100644 index 0000000000..3e38352e4e --- /dev/null +++ b/pcbnew/tools/pcb_editor_conditions.h @@ -0,0 +1,122 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Ian McInerney + * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef PCB_EDITOR_CONDITIONS_H_ +#define PCB_EDITOR_CONDITIONS_H_ + +#include +#include +#include +#include +#include + +class EDA_BASE_FRAME; +class EDA_DRAW_FRAME; +class PCB_BASE_FRAME; + +/** + * Class that groups generic conditions for PCB editor states. + */ +class PCB_EDITOR_CONDITIONS : public EDITOR_CONDITIONS +{ +public: + PCB_EDITOR_CONDITIONS( PCB_BASE_FRAME* aFrame ) : + EDITOR_CONDITIONS( aFrame ) + {} + + /** + * Creates a functor that tests if the pad numbers are displayed + * + * @return Functor returning true if the pad numbers are displayed + */ + SELECTION_CONDITION PadNumbersDisplay(); + + /** + * Creates a functor that tests if the frame fills the pads + * + * @return Functor returning true if the pads are filled + */ + SELECTION_CONDITION PadFillDisplay(); + + /** + * Creates a functor that tests if the frame fills text items + * + * @return Functor returning true if the text items are filled + */ + SELECTION_CONDITION TextFillDisplay(); + + /** + * Creates a functor that tests if the frame fills graphics items + * + * @return Functor returning true if graphics items are filled + */ + SELECTION_CONDITION GraphicsFillDisplay(); + + /** + * Creates a functor that tests if the frame fills vias + * + * @return Functor returning true if vias are filled + */ + SELECTION_CONDITION ViaFillDisplay(); + + /** + * Creates a functor that tests if the frame fills vias + * + * @return Functor returning true if tracks are filled + */ + SELECTION_CONDITION TrackFillDisplay(); + + /** + * Creates a functor that tests the current zone display mode in the frame + * + * @param aMode is the mode to test for + * @return Functor returning true if the frame is using the specified mode + */ + SELECTION_CONDITION ZoneDisplayMode( ZONE_DISPLAY_MODE aMode ); + +protected: + ///> Helper function used by PadNumbersDisplay() + static bool padNumberDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); + + ///> Helper function used by PadFillDisplay() + static bool padFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); + + ///> Helper function used by TextFillDisplay() + static bool textFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); + + ///> Helper function used by GraphicsFillDisplay() + static bool graphicsFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); + + ///> Helper function used by ViaFillDisplay() + static bool viaFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); + + ///> Helper function used by TrackFillDisplay() + static bool trackFillDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); + + ///> Helper function used by ZoneDisplayMode() + static bool zoneDisplayModeFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame, + ZONE_DISPLAY_MODE aMode ); +}; + +#endif /* PCB_EDITOR_CONDITIONS_H_ */