Move more frames to the new UI condition framework

* Frames moved: cvpcb, cvpcb footprints frame, gerbview, pagelayout editor

This also introduces new EDITOR_CONDITIONS that are used to set the
conditions of very common editor settings.

Also, some IDs were converted to tools in the pagelayout editor.
This commit is contained in:
Ian McInerney 2020-07-30 00:50:25 +01:00
parent f34ffd3906
commit 3b05d7cddd
28 changed files with 962 additions and 421 deletions

View File

@ -395,6 +395,7 @@ set( COMMON_SRCS
tool/conditional_menu.cpp
tool/edit_constraints.cpp
tool/edit_points.cpp
tool/editor_conditions.cpp
tool/grid_menu.cpp
tool/picker_tool.cpp
tool/selection_conditions.cpp

View File

@ -0,0 +1,166 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Ian McInerney <ian.s.mcinerney at ieee.org>
* 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 <class_draw_panel_gal.h>
#include <eda_base_frame.h>
#include <eda_draw_frame.h>
#include <tool/editor_conditions.h>
#include <tool/selection.h>
#include <functional>
#include <wx/debug.h>
using namespace std::placeholders;
SELECTION_CONDITION EDITOR_CONDITIONS::ContentModified()
{
return std::bind( &EDITOR_CONDITIONS::contentModifiedFunc, _1, m_frame );
}
SELECTION_CONDITION EDITOR_CONDITIONS::UndoAvailable()
{
return std::bind( &EDITOR_CONDITIONS::undoFunc, _1, m_frame );
}
SELECTION_CONDITION EDITOR_CONDITIONS::RedoAvailable()
{
return std::bind( &EDITOR_CONDITIONS::redoFunc, _1, m_frame );
}
SELECTION_CONDITION EDITOR_CONDITIONS::Units( EDA_UNITS aUnit )
{
return std::bind( &EDITOR_CONDITIONS::unitsFunc, _1, m_frame, aUnit );
}
SELECTION_CONDITION EDITOR_CONDITIONS::CurrentTool( const TOOL_ACTION& aTool )
{
return std::bind( &EDITOR_CONDITIONS::toolFunc, _1, m_frame, std::cref( aTool ) );
}
SELECTION_CONDITION EDITOR_CONDITIONS::GridVisible()
{
// The grid visibility check requires a draw frame
EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
wxASSERT( drwFrame );
return std::bind( &EDITOR_CONDITIONS::gridFunc, _1, drwFrame );
}
SELECTION_CONDITION EDITOR_CONDITIONS::PolarCoordinates()
{
// The polar coordinates require a draw frame
EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
wxASSERT( drwFrame );
return std::bind( &EDITOR_CONDITIONS::polarCoordFunc, _1, drwFrame );
}
SELECTION_CONDITION EDITOR_CONDITIONS::FullscreenCursor()
{
// The fullscreen cursor requires a draw frame
EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
wxASSERT( drwFrame );
return std::bind( &EDITOR_CONDITIONS::gridFunc, _1, drwFrame );
}
SELECTION_CONDITION EDITOR_CONDITIONS::CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE aType )
{
// The canvas type requires a draw frame
EDA_DRAW_FRAME* drwFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_frame );
wxASSERT( drwFrame );
return std::bind( &EDITOR_CONDITIONS::canvasTypeFunc, _1, drwFrame, aType );
}
bool EDITOR_CONDITIONS::contentModifiedFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
{
return aFrame->IsContentModified();
}
bool EDITOR_CONDITIONS::undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
{
return aFrame->GetUndoCommandCount() > 0;
}
bool EDITOR_CONDITIONS::redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame )
{
return aFrame->GetRedoCommandCount() > 0;
}
bool EDITOR_CONDITIONS::unitsFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
EDA_UNITS aUnits )
{
return aFrame->GetUserUnits() == aUnits;
}
bool EDITOR_CONDITIONS::toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
const TOOL_ACTION& aTool )
{
return aFrame->IsCurrentTool( aTool );
}
bool EDITOR_CONDITIONS::gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
{
return aFrame->IsGridVisible();
}
bool EDITOR_CONDITIONS::polarCoordFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
{
return aFrame->GetShowPolarCoords();
}
bool EDITOR_CONDITIONS::cursorFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame )
{
return aFrame->GetGalDisplayOptions().m_fullscreenCursor;
}
bool EDITOR_CONDITIONS::canvasTypeFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame,
EDA_DRAW_PANEL_GAL::GAL_TYPE aType )
{
return aFrame->GetCanvas()->GetBackend() == aType;
}

View File

@ -37,6 +37,24 @@ bool SELECTION_CONDITIONS::NotEmpty( const SELECTION& aSelection )
}
bool SELECTION_CONDITIONS::Empty( const SELECTION& aSelection )
{
return aSelection.Empty();
}
bool SELECTION_CONDITIONS::Idle( const SELECTION& aSelection )
{
return ( !aSelection.Front() || aSelection.Front()->GetEditFlags() == 0 );
}
bool SELECTION_CONDITIONS::IdleSelection( const SELECTION& aSelection )
{
return ( aSelection.Front() && aSelection.Front()->GetEditFlags() == 0 );
}
SELECTION_CONDITION SELECTION_CONDITIONS::HasType( KICAD_T aType )
{
return std::bind( &SELECTION_CONDITIONS::hasTypeFunc, _1, aType );
@ -153,3 +171,17 @@ SELECTION_CONDITION operator!( const SELECTION_CONDITION& aCondition )
{
return std::bind( &SELECTION_CONDITIONS::notFunc, aCondition, _1 );
}
SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
SELECTION_BOOL aConditionB )
{
return std::bind( &SELECTION_CONDITIONS::orBoolFunc, aConditionA, std::ref( aConditionB ), _1 );
}
SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
SELECTION_BOOL aConditionB )
{
return std::bind( &SELECTION_CONDITIONS::andBoolFunc, aConditionA, std::ref( aConditionB ), _1 );
}

View File

@ -32,8 +32,10 @@
#include <macros.h>
#include <netlist_reader/netlist_reader.h>
#include <numeric>
#include <tool/action_manager.h>
#include <tool/action_toolbar.h>
#include <tool/common_control.h>
#include <tool/editor_conditions.h>
#include <tool/tool_dispatcher.h>
#include <tool/tool_manager.h>
#include <widgets/progress_reporter.h>
@ -79,6 +81,7 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
LoadSettings( config() );
setupTools();
setupUIConditions();
ReCreateMenuBar();
ReCreateHToolbar();
@ -223,6 +226,52 @@ void CVPCB_MAINFRAME::setupTools()
m_footprintContextMenu->Add( CVPCB_ACTIONS::showFootprintViewer );
}
void CVPCB_MAINFRAME::setupUIConditions()
{
EDA_BASE_FRAME::setupUIConditions();
ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
EDITOR_CONDITIONS cond( this );
wxASSERT( mgr );
#define Enable( x ) ACTION_CONDITIONS().SetEnableCondition( x )
#define Check( x ) ACTION_CONDITIONS().SetCheckCondition( x )
mgr->SetConditions( CVPCB_ACTIONS::saveAssociations, Enable( cond.ContentModified() ) );
mgr->SetConditions( ACTIONS::undo, Enable( cond.UndoAvailable() ) );
mgr->SetConditions( ACTIONS::redo, Enable( cond.RedoAvailable() ) );
#define filterActive( filter ) ( m_filteringOptions & filter )
auto compFilter =
[this] ( const SELECTION& )
{
return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_FP_FILTERS;
};
auto libFilter =
[this] ( const SELECTION& )
{
return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY;
};
auto pinFilter =
[this] ( const SELECTION& )
{
return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT;
};
mgr->SetConditions( CVPCB_ACTIONS::FilterFPbyFPFilters, Check( compFilter ) );
mgr->SetConditions( CVPCB_ACTIONS::FilterFPbyLibrary, Check( libFilter ) );
mgr->SetConditions( CVPCB_ACTIONS::filterFPbyPin, Check( pinFilter ) );
#undef Check
#undef Enable
}
void CVPCB_MAINFRAME::setupEventHandlers()
{
// Connect the handlers to launch the context menus in the listboxes

View File

@ -86,6 +86,8 @@ protected:
CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent );
void setupUIConditions() override;
public:
~CVPCB_MAINFRAME();
@ -231,6 +233,16 @@ public:
*/
void RedoAssociation();
int GetUndoCommandCount() const override
{
return m_undoList.size();
}
int GetRedoCommandCount() const override
{
return m_redoList.size();
}
/**
* Associate a footprint with a specific component in the list.
*
@ -363,11 +375,6 @@ public:
void SetStatusText( const wxString& aText, int aNumber = 0 ) override;
/**
* Syncronize the toolbar state with the current tool state.
*/
void SyncToolbars() override;
private:
/**
* Setup the tool system for the CVPCB main frame.

View File

@ -43,6 +43,7 @@
#include <settings/settings_manager.h>
#include <tool/action_toolbar.h>
#include <tool/common_tools.h>
#include <tool/editor_conditions.h>
#include <tool/tool_dispatcher.h>
#include <tool/tool_manager.h>
#include <tool/zoom_tool.h>
@ -53,6 +54,7 @@
#include <tools/pcb_viewer_tools.h> // shared tools with other pcbnew frames
#include <tools/cvpcb_fpviewer_selection_tool.h>
#include <widgets/infobar.h>
#include <wx/debug.h>
BEGIN_EVENT_TABLE( DISPLAY_FOOTPRINTS_FRAME, PCB_BASE_FRAME )
@ -117,6 +119,8 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa
m_toolManager->InitTools();
setupUIConditions();
// Run the control tool, it is supposed to be always active
m_toolManager->InvokeTool( "cvpcb.FootprintViewerInteractiveSelection" );
@ -177,6 +181,68 @@ DISPLAY_FOOTPRINTS_FRAME::~DISPLAY_FOOTPRINTS_FRAME()
}
void DISPLAY_FOOTPRINTS_FRAME::setupUIConditions()
{
EDA_BASE_FRAME::setupUIConditions();
ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
EDITOR_CONDITIONS cond( this );
wxASSERT( mgr );
#define Check( x ) ACTION_CONDITIONS().SetCheckCondition( x )
mgr->SetConditions( ACTIONS::zoomTool, Check( cond.CurrentTool( ACTIONS::zoomTool ) ) );
mgr->SetConditions( ACTIONS::selectionTool, Check( cond.CurrentTool( ACTIONS::selectionTool ) ) );
mgr->SetConditions( ACTIONS::measureTool, Check( cond.CurrentTool( ACTIONS::measureTool ) ) );
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 ) ) );
auto autoZoomCond =
[this] ( const SELECTION& aSel )
{
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 ) );
#undef Check
}
void DISPLAY_FOOTPRINTS_FRAME::OnCloseWindow( wxCloseEvent& event )
{
Destroy();
@ -456,29 +522,6 @@ void DISPLAY_FOOTPRINTS_FRAME::UpdateMsgPanel()
}
void DISPLAY_FOOTPRINTS_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();
}
COLOR_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetColorSettings()
{
auto* settings = Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
@ -510,3 +553,9 @@ bool DISPLAY_FOOTPRINTS_FRAME::GetAutoZoom()
wxCHECK( cfg, false );
return cfg->m_FootprintViewerAutoZoom;
}
SELECTION& DISPLAY_FOOTPRINTS_FRAME::GetCurrentSelection()
{
return m_toolManager->GetTool<CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL>()->GetSelection();
}

View File

@ -114,8 +114,6 @@ public:
// currently: do nothing in CvPcb.
}
void SyncToolbars() override;
/**
* Set if the canvas should automatically zoom to the footprint on load.
*
@ -130,7 +128,12 @@ public:
*/
bool GetAutoZoom() override;
SELECTION& GetCurrentSelection() override;
DECLARE_EVENT_TABLE()
protected:
void setupUIConditions() override;
};
#endif // DISPLAY_FOOTPRINTS_FRAME_H

View File

@ -44,59 +44,41 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
//-- File menu -----------------------------------------------------------
//
CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, tool );
ACTION_MENU* fileMenu = new ACTION_MENU( false, tool );
auto enableSaveCondition = [ this ] ( const SELECTION& sel )
{
return IsContentModified();
};
fileMenu->AddItem( CVPCB_ACTIONS::saveAssociations, enableSaveCondition );
fileMenu->AddSeparator();
fileMenu->Add( CVPCB_ACTIONS::saveAssociations );
fileMenu->AppendSeparator();
fileMenu->AddClose( _( "Assign Footprints" ) );
fileMenu->Resolve();
//-- Preferences menu -----------------------------------------------
//
ACTION_MENU* editMenu = new ACTION_MENU( false, tool );
editMenu->Add( ACTIONS::undo );
editMenu->Add( ACTIONS::redo );
editMenu->AppendSeparator();
editMenu->Add( ACTIONS::cut );
editMenu->Add( ACTIONS::copy );
editMenu->Add( ACTIONS::paste );
//-- Preferences menu -----------------------------------------------
//
CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, tool );
ACTION_MENU* prefsMenu = new ACTION_MENU( false, tool );
auto enableUndoCondition = [ this ] ( const SELECTION& sel )
{
return m_undoList.size() > 0;
};
auto enableRedoCondition = [ this ] ( const SELECTION& sel )
{
return m_redoList.size() > 0;
};
prefsMenu->Add( ACTIONS::configurePaths );
prefsMenu->Add( ACTIONS::showFootprintLibTable );
prefsMenu->Add( _( "Preferences...\tCTRL+," ),
_( "Show preferences for all open tools" ),
wxID_PREFERENCES,
preference_xpm );
editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
editMenu->AddSeparator();
editMenu->AddItem( ACTIONS::cut, SELECTION_CONDITIONS::ShowAlways );
editMenu->AddItem( ACTIONS::copy, SELECTION_CONDITIONS::ShowAlways );
editMenu->AddItem( ACTIONS::paste, SELECTION_CONDITIONS::ShowAlways );
prefsMenu->AppendSeparator();
prefsMenu->Add( CVPCB_ACTIONS::showEquFileTable);
editMenu->Resolve();
//-- Preferences menu -----------------------------------------------
//
CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, tool );
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->AddItem( CVPCB_ACTIONS::showEquFileTable, SELECTION_CONDITIONS::ShowAlways );
prefsMenu->AddSeparator();
prefsMenu->AppendSeparator();
AddMenuLanguageList( prefsMenu, tool );
prefsMenu->Resolve();
//-- Menubar -------------------------------------------------------------
//
menuBar->Append( fileMenu, _( "&File" ) );

View File

@ -74,9 +74,9 @@ void CVPCB_MAINFRAME::ReCreateHToolbar()
#endif
m_mainToolBar->AddControl( text );
m_mainToolBar->Add( CVPCB_ACTIONS::FilterFPbyFPFilters, true );
m_mainToolBar->Add( CVPCB_ACTIONS::filterFPbyPin, true );
m_mainToolBar->Add( CVPCB_ACTIONS::FilterFPbyLibrary, true );
m_mainToolBar->Add( CVPCB_ACTIONS::FilterFPbyFPFilters, ACTION_TOOLBAR::TOGGLE );
m_mainToolBar->Add( CVPCB_ACTIONS::filterFPbyPin, ACTION_TOOLBAR::TOGGLE );
m_mainToolBar->Add( CVPCB_ACTIONS::FilterFPbyLibrary, ACTION_TOOLBAR::TOGGLE );
m_mainToolBar->AddScaledSeparator( this );
@ -90,21 +90,3 @@ void CVPCB_MAINFRAME::ReCreateHToolbar()
// after adding the buttons to the toolbar, must call Realize() to reflect the changes
m_mainToolBar->Realize();
}
void CVPCB_MAINFRAME::SyncToolbars()
{
#define filterActive( filter ) ( m_filteringOptions & filter )
m_mainToolBar->Toggle( CVPCB_ACTIONS::saveAssociations, IsContentModified() );
m_mainToolBar->Toggle( ACTIONS::undo, m_undoList.size() > 0 );
m_mainToolBar->Toggle( ACTIONS::redo, m_redoList.size() > 0 );
m_mainToolBar->Toggle( CVPCB_ACTIONS::FilterFPbyFPFilters,
filterActive( FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_FP_FILTERS ) );
m_mainToolBar->Toggle( CVPCB_ACTIONS::FilterFPbyLibrary,
filterActive( FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY ) );
m_mainToolBar->Toggle( CVPCB_ACTIONS::filterFPbyPin,
filterActive( FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT ) );
m_mainToolBar->Refresh();
}

View File

@ -128,7 +128,7 @@ void SCH_EDIT_FRAME::ReCreateVToolbar()
m_drawToolBar->Add( EE_ACTIONS::placeJunction, ACTION_TOOLBAR::TOGGLE );
m_drawToolBar->Add( EE_ACTIONS::placeLabel, ACTION_TOOLBAR::TOGGLE );
m_drawToolBar->Add( EE_ACTIONS::placeGlobalLabel, ACTION_TOOLBAR::TOGGLE );
m_drawToolBar->Add( EE_ACTIONS::placeHierLabel, ACTION_TOOLBAR::TOGGLE );
m_drawToolBar->Add( EE_ACTIONS::placeHierLabel, ACTION_TOOLBAR::TOGGLE );
m_drawToolBar->Add( EE_ACTIONS::drawSheet, ACTION_TOOLBAR::TOGGLE );
m_drawToolBar->Add( EE_ACTIONS::importSheetPin, ACTION_TOOLBAR::TOGGLE );

View File

@ -52,24 +52,6 @@
#include <view/view_group.h>
SELECTION_CONDITION EE_CONDITIONS::Empty = [] (const SELECTION& aSelection )
{
return aSelection.Empty();
};
SELECTION_CONDITION EE_CONDITIONS::Idle = [] (const SELECTION& aSelection )
{
return ( !aSelection.Front() || aSelection.Front()->GetEditFlags() == 0 );
};
SELECTION_CONDITION EE_CONDITIONS::IdleSelection = [] (const SELECTION& aSelection )
{
return ( aSelection.Front() && aSelection.Front()->GetEditFlags() == 0 );
};
SELECTION_CONDITION EE_CONDITIONS::SingleSymbol = [] (const SELECTION& aSel )
{
if( aSel.GetSize() == 1 )

View File

@ -44,10 +44,6 @@ namespace KIGFX
class EE_CONDITIONS : public SELECTION_CONDITIONS
{
public:
static SELECTION_CONDITION Empty;
static SELECTION_CONDITION Idle;
static SELECTION_CONDITION IdleSelection;
static SELECTION_CONDITION SingleSymbol;
static SELECTION_CONDITION SingleDeMorganSymbol;
static SELECTION_CONDITION SingleMultiUnitSymbol;

View File

@ -45,8 +45,10 @@
#include <tool/tool_dispatcher.h>
#include <tool/common_control.h>
#include <tool/common_tools.h>
#include <tool/editor_conditions.h>
#include <tool/zoom_tool.h>
#include <tools/gerbview_actions.h>
#include <tools/gerbview_selection.h>
#include <tools/gerbview_selection_tool.h>
#include <tools/gerbview_control.h>
#include <view/view.h>
@ -124,6 +126,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent )
LoadSettings( config() );
setupTools();
setupUIConditions();
ReCreateMenuBar();
ReCreateHToolbar();
ReCreateOptToolbar();
@ -1170,6 +1173,106 @@ void GERBVIEW_FRAME::setupTools()
}
void GERBVIEW_FRAME::setupUIConditions()
{
EDA_BASE_FRAME::setupUIConditions();
ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
EDITOR_CONDITIONS cond( this );
wxASSERT( mgr );
#define Enable( x ) ACTION_CONDITIONS().SetEnableCondition( x )
#define Check( x ) ACTION_CONDITIONS().SetCheckCondition( x )
mgr->SetConditions( ACTIONS::zoomTool, Check( cond.CurrentTool( ACTIONS::zoomTool ) ) );
mgr->SetConditions( ACTIONS::selectionTool, Check( cond.CurrentTool( ACTIONS::selectionTool ) ) );
mgr->SetConditions( ACTIONS::measureTool, Check( cond.CurrentTool( ACTIONS::measureTool ) ) );
mgr->SetConditions( ACTIONS::toggleGrid, Check( cond.GridVisible() ) );
mgr->SetConditions( ACTIONS::togglePolarCoords, Check( cond.PolarCoordinates() ) );
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 ) ) );
auto flashedDisplayOutlinesCond =
[this] ( const SELECTION& )
{
return !m_DisplayOptions.m_DisplayFlashedItemsFill;
};
auto linesFillCond =
[this] ( const SELECTION& )
{
return !m_DisplayOptions.m_DisplayLinesFill;
};
auto polygonsFilledCond =
[this] ( const SELECTION& )
{
return !m_DisplayOptions.m_DisplayPolygonsFill;
};
auto negativeObjectsCond =
[this] ( const SELECTION& )
{
return IsElementVisible( LAYER_NEGATIVE_OBJECTS );
};
auto dcodeCond =
[this] ( const SELECTION& )
{
return IsElementVisible( LAYER_DCODES );
};
auto diffModeCond =
[this] ( const SELECTION& )
{
return m_DisplayOptions.m_DiffMode;
};
auto highContrastModeCond =
[this] ( const SELECTION& )
{
return m_DisplayOptions.m_HighContrastMode;
};
auto flipGerberCond =
[this] ( const SELECTION& )
{
return m_DisplayOptions.m_FlipGerberView;
};
mgr->SetConditions( GERBVIEW_ACTIONS::flashedDisplayOutlines, Check( flashedDisplayOutlinesCond ) );
mgr->SetConditions( GERBVIEW_ACTIONS::linesDisplayOutlines, Check( linesFillCond ) );
mgr->SetConditions( GERBVIEW_ACTIONS::polygonsDisplayOutlines, Check( polygonsFilledCond ) );
mgr->SetConditions( GERBVIEW_ACTIONS::negativeObjectDisplay, Check( negativeObjectsCond ) );
mgr->SetConditions( GERBVIEW_ACTIONS::dcodeDisplay, Check( dcodeCond ) );
mgr->SetConditions( GERBVIEW_ACTIONS::toggleDiffMode, Check( diffModeCond ) );
mgr->SetConditions( GERBVIEW_ACTIONS::flipGerberView, Check( flipGerberCond ) );
mgr->SetConditions( ACTIONS::highContrastMode, Check( highContrastModeCond ) );
auto layersManagerShownCondition =
[this] ( const SELECTION& aSel )
{
return m_show_layer_manager_tools;
};
RegisterUIUpdateHandler( ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
Check( layersManagerShownCondition ) );
#undef Check
#undef Enable
}
void GERBVIEW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
{
EDA_DRAW_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
@ -1179,3 +1282,8 @@ void GERBVIEW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
SendSizeEvent();
}
SELECTION& GERBVIEW_FRAME::GetCurrentSelection()
{
return m_toolManager->GetTool<GERBVIEW_SELECTION_TOOL>()->GetSelection();
}

View File

@ -43,6 +43,7 @@ class GERBER_DRAW_ITEM;
class GERBER_FILE_IMAGE;
class GERBER_FILE_IMAGE_LIST;
class REPORTER;
class SELECTION;
/**
@ -153,6 +154,8 @@ protected:
wxString m_lastFileName; // The last filename chosen to be proposed to the user
void setupUIConditions() override;
public:
wxChoice* m_SelComponentBox; // a choice box to display and highlight component graphic items
wxChoice* m_SelNetnameBox; // a choice box to display and highlight netlist graphic items
@ -565,7 +568,7 @@ public:
*/
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
void SyncToolbars() override;
SELECTION& GetCurrentSelection() override;
DECLARE_EVENT_TABLE()
};

View File

@ -28,8 +28,8 @@
#include <kiface_i.h>
#include <menus_helpers.h>
#include <pgm_base.h>
#include <tool/action_menu.h>
#include <tool/actions.h>
#include <tool/conditional_menu.h>
#include <tool/tool_manager.h>
#include <tools/gerbview_actions.h>
#include <tools/gerbview_selection_tool.h>
@ -46,14 +46,15 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
//-- File menu -------------------------------------------------------
//
CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
static ACTION_MENU* openRecentGbrMenu;
static ACTION_MENU* openRecentDrlMenu;
static ACTION_MENU* openRecentJobMenu;
static ACTION_MENU* openRecentZipMenu;
FILE_HISTORY& recentGbrFiles = GetFileHistory();
recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) );
#define FileHistoryCond( x ) ACTION_CONDITIONS().SetEnableCondition( FILE_HISTORY::FileHistoryNotEmpty( x ) )
// Create the gerber file menu if it does not exist. Adding a file to/from the history
@ -66,9 +67,15 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
openRecentGbrMenu->SetIcon( recent_xpm );
recentGbrFiles.UseMenu( openRecentGbrMenu );
recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) );
recentGbrFiles.AddFilesToMenu();
}
fileMenu->Add( GERBVIEW_ACTIONS::openGerber );
wxMenuItem* gbrItem = fileMenu->Add( openRecentGbrMenu );
RegisterUIUpdateHandler( gbrItem->GetId(), FileHistoryCond( recentGbrFiles) );
// Create the drill file menu if it does not exist. Adding a file to/from the history
// will automatically refresh the menu.
if( !openRecentDrlMenu )
@ -79,9 +86,15 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
openRecentDrlMenu->SetIcon( recent_xpm );
m_drillFileHistory.UseMenu( openRecentDrlMenu );
m_drillFileHistory.SetClearText( _( "Clear Recent Drill Files" ) );
m_drillFileHistory.AddFilesToMenu();
}
fileMenu->Add( GERBVIEW_ACTIONS::openGerber );
wxMenuItem* drillItem = fileMenu->Add( openRecentDrlMenu );
RegisterUIUpdateHandler( drillItem->GetId(), FileHistoryCond( m_drillFileHistory ) );
// Create the job file menu if it does not exist. Adding a file to/from the history
// will automatically refresh the menu.
if( !openRecentJobMenu )
@ -92,9 +105,15 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
openRecentJobMenu->SetIcon( recent_xpm );
m_jobFileHistory.UseMenu( openRecentJobMenu );
m_jobFileHistory.SetClearText( _( "Clear Recent Job Files" ) );
m_jobFileHistory.AddFilesToMenu();
}
fileMenu->Add( GERBVIEW_ACTIONS::openGerber );
wxMenuItem* jobItem = fileMenu->Add( openRecentJobMenu );
RegisterUIUpdateHandler( jobItem->GetId(), FileHistoryCond( m_jobFileHistory ) );
// Create the zip file menu if it does not exist. Adding a file to/from the history
// will automatically refresh the menu.
if( !openRecentZipMenu )
@ -105,169 +124,131 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
openRecentZipMenu->SetIcon( recent_xpm );
m_zipFileHistory.UseMenu( openRecentZipMenu );
m_zipFileHistory.SetClearText( _( "Clear Recent Zip Files" ) );
m_zipFileHistory.AddFilesToMenu();
}
fileMenu->AddItem( GERBVIEW_ACTIONS::openGerber, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentGbrMenu, FILE_HISTORY::FileHistoryNotEmpty( recentGbrFiles ) );
fileMenu->Add( GERBVIEW_ACTIONS::openGerber );
wxMenuItem* zipItem = fileMenu->Add( openRecentZipMenu );
RegisterUIUpdateHandler( zipItem->GetId(), FileHistoryCond( m_zipFileHistory ) );
fileMenu->AddItem( GERBVIEW_ACTIONS::openDrillFile, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentDrlMenu, FILE_HISTORY::FileHistoryNotEmpty( m_drillFileHistory ) );
#undef FileHistoryCond
fileMenu->AddItem( GERBVIEW_ACTIONS::openJobFile, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentJobMenu, FILE_HISTORY::FileHistoryNotEmpty( m_jobFileHistory ) );
fileMenu->AppendSeparator();
fileMenu->Add( _( "Clear &All Layers" ),
_( "Clear all layers. All data will be deleted" ),
ID_GERBVIEW_ERASE_ALL,
delete_gerber_xpm );
fileMenu->AddItem( GERBVIEW_ACTIONS::openZipFile, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentZipMenu, FILE_HISTORY::FileHistoryNotEmpty( m_zipFileHistory ) );
fileMenu->Add( _( "Reload All Layers" ),
_( "Reload all layers. All data will be reloaded" ),
ID_GERBVIEW_RELOAD_ALL,
reload2_xpm );
fileMenu->AddSeparator();
fileMenu->AddItem( ID_GERBVIEW_ERASE_ALL, _( "Clear &All Layers" ),
_( "Clear all layers. All data will be deleted" ),
delete_gerber_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AppendSeparator();
fileMenu->Add( _( "Export to Pcbnew..." ),
_( "Export data in Pcbnew format" ),
ID_GERBVIEW_EXPORT_TO_PCBNEW,
export_xpm );
fileMenu->AddItem( ID_GERBVIEW_RELOAD_ALL, _( "Reload All Layers" ),
_( "Reload all layers. All data will be reloaded" ),
reload2_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AppendSeparator();
fileMenu->Add( ACTIONS::print );
fileMenu->AddSeparator();
fileMenu->AddItem( ID_GERBVIEW_EXPORT_TO_PCBNEW, _( "Export to Pcbnew..." ),
_( "Export data in Pcbnew format" ),
export_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddSeparator();
fileMenu->AddItem( ACTIONS::print, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddSeparator();
fileMenu->AppendSeparator();
fileMenu->AddQuitOrClose( &Kiface(), _( "GerbView" ) );
fileMenu->Resolve();
//-- View menu -------------------------------------------------------
//
CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
return IsGridVisible();
};
auto polarCoordsCondition = [ this ] ( const SELECTION& aSel ) {
return GetShowPolarCoords();
};
auto layersManagerShownCondition = [ this ] ( const SELECTION& aSel ) {
return m_show_layer_manager_tools;
};
auto imperialUnitsCondition = [this]( const SELECTION& aSel ) {
return GetUserUnits() == EDA_UNITS::INCHES;
};
auto metricUnitsCondition = [this]( const SELECTION& aSel ) {
return GetUserUnits() == EDA_UNITS::MILLIMETRES;
};
auto sketchFlashedCondition = [ this ] ( const SELECTION& aSel ) {
return !m_DisplayOptions.m_DisplayFlashedItemsFill;
};
auto sketchLinesCondition = [ this ] ( const SELECTION& aSel ) {
return !m_DisplayOptions.m_DisplayLinesFill;
};
auto sketchPolygonsCondition = [ this ] ( const SELECTION& aSel ) {
return !m_DisplayOptions.m_DisplayPolygonsFill;
};
auto showDcodes = [ this ] ( const SELECTION& aSel ) {
return IsElementVisible( LAYER_DCODES );
};
auto showNegativeObjects = [ this ] ( const SELECTION& aSel ) {
return IsElementVisible( LAYER_NEGATIVE_OBJECTS );
};
auto diffModeCondition = [ this ] ( const SELECTION& aSel ) {
return m_DisplayOptions.m_DiffMode;
};
auto contrastModeCondition = [ this ] ( const SELECTION& aSel ) {
return m_DisplayOptions.m_HighContrastMode;
};
auto flipViewCondition = [this]( const SELECTION& aSel ) {
return m_DisplayOptions.m_FlipGerberView;
};
ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
// Hide layer manager
viewMenu->AddCheckItem( ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
_( "Show &Layers Manager" ), _( "Show or hide the layer manager" ),
layers_manager_xpm, layersManagerShownCondition );
viewMenu->Add( _( "Show &Layers Manager" ),
_( "Show or hide the layer manager" ),
ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
layers_manager_xpm );
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->AppendSeparator();
viewMenu->Add( ACTIONS::zoomInCenter );
viewMenu->Add( ACTIONS::zoomOutCenter );
viewMenu->Add( ACTIONS::zoomFitScreen );
viewMenu->Add( ACTIONS::zoomTool );
viewMenu->Add( ACTIONS::zoomRedraw );
viewMenu->AddSeparator();
viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
viewMenu->AddCheckItem( ACTIONS::togglePolarCoords, polarCoordsCondition );
viewMenu->AppendSeparator();
viewMenu->Add( ACTIONS::toggleGrid, ACTION_MENU::CHECK );
viewMenu->Add( ACTIONS::togglePolarCoords, ACTION_MENU::CHECK );
#ifdef __APPLE__
// Add a separator only on macOS because the OS adds menu items to the view menu after ours
viewMenu->AppendSeparator();
#endif
// 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->AddSeparator();
viewMenu->AddCheckItem( GERBVIEW_ACTIONS::flashedDisplayOutlines, sketchFlashedCondition );
viewMenu->AddCheckItem( GERBVIEW_ACTIONS::linesDisplayOutlines, sketchLinesCondition );
viewMenu->AddCheckItem( GERBVIEW_ACTIONS::polygonsDisplayOutlines, sketchPolygonsCondition );
viewMenu->AddCheckItem( GERBVIEW_ACTIONS::dcodeDisplay, showDcodes );
viewMenu->AddCheckItem( GERBVIEW_ACTIONS::negativeObjectDisplay, showNegativeObjects );
viewMenu->AddCheckItem( GERBVIEW_ACTIONS::toggleDiffMode, diffModeCondition );
viewMenu->AddCheckItem( ACTIONS::highContrastMode, contrastModeCondition );
viewMenu->AddCheckItem( GERBVIEW_ACTIONS::flipGerberView, flipViewCondition );
viewMenu->Add( unitsSubMenu );
viewMenu->AppendSeparator();
viewMenu->Add( GERBVIEW_ACTIONS::flashedDisplayOutlines, ACTION_MENU::CHECK );
viewMenu->Add( GERBVIEW_ACTIONS::linesDisplayOutlines, ACTION_MENU::CHECK );
viewMenu->Add( GERBVIEW_ACTIONS::polygonsDisplayOutlines, ACTION_MENU::CHECK );
viewMenu->Add( GERBVIEW_ACTIONS::dcodeDisplay, ACTION_MENU::CHECK );
viewMenu->Add( GERBVIEW_ACTIONS::negativeObjectDisplay, ACTION_MENU::CHECK );
viewMenu->Add( GERBVIEW_ACTIONS::toggleDiffMode, ACTION_MENU::CHECK );
viewMenu->Add( ACTIONS::highContrastMode, ACTION_MENU::CHECK );
viewMenu->Add( GERBVIEW_ACTIONS::flipGerberView, ACTION_MENU::CHECK );
viewMenu->Resolve();
//-- Tools menu -------------------------------------------------------
//
ACTION_MENU* toolsMenu = new ACTION_MENU( false );
toolsMenu->Add( _( "&List DCodes..." ), _( "List D-codes defined in Gerber files" ),
ID_GERBVIEW_SHOW_LIST_DCODES, show_dcodenumber_xpm );
toolsMenu->Add( _( "&List DCodes..." ),
_( "List D-codes defined in Gerber files" ),
ID_GERBVIEW_SHOW_LIST_DCODES,
show_dcodenumber_xpm );
toolsMenu->Add( _( "&Show Source..." ), _( "Show source file for the current layer" ),
ID_GERBVIEW_SHOW_SOURCE, tools_xpm );
toolsMenu->Add( _( "&Show Source..." ),
_( "Show source file for the current layer" ),
ID_GERBVIEW_SHOW_SOURCE,
tools_xpm );
toolsMenu->Add( ACTIONS::measureTool );
toolsMenu->AppendSeparator();
toolsMenu->Add( _( "Clear Current Layer..." ), _( "Clear the selected graphic layer" ),
ID_GERBVIEW_ERASE_CURR_LAYER, delete_sheet_xpm );
toolsMenu->Add( _( "Clear Current Layer..." ),
_( "Clear the selected graphic layer" ),
ID_GERBVIEW_ERASE_CURR_LAYER,
delete_sheet_xpm );
//-- Preferences menu -----------------------------------------------
//
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;
};
ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
CONDITIONAL_MENU* preferencesMenu = new CONDITIONAL_MENU( false, selTool );
preferencesMenu->Add( _( "Preferences...\tCTRL+," ),
_( "Show preferences for all open tools" ),
wxID_PREFERENCES,
preference_xpm );
preferencesMenu->AddItem( wxID_PREFERENCES,
_( "Preferences...\tCTRL+," ),
_( "Show preferences for all open tools" ),
preference_xpm, SELECTION_CONDITIONS::ShowAlways );
preferencesMenu->AddSeparator();
preferencesMenu->AppendSeparator();
AddMenuLanguageList( preferencesMenu, selTool );
preferencesMenu->AddSeparator();
preferencesMenu->AddCheckItem( ACTIONS::acceleratedGraphics, acceleratedGraphicsCondition );
preferencesMenu->AddCheckItem( ACTIONS::standardGraphics, standardGraphicsCondition );
preferencesMenu->AppendSeparator();
preferencesMenu->Add( ACTIONS::acceleratedGraphics, ACTION_MENU::CHECK );
preferencesMenu->Add( ACTIONS::standardGraphics, ACTION_MENU::CHECK );
preferencesMenu->Resolve();
//-- Menubar -------------------------------------------------------------
//
menuBar->Append( fileMenu, _( "&File" ) );
menuBar->Append( viewMenu, _( "&View" ) );
menuBar->Append( toolsMenu, _( "&Tools" ) );
menuBar->Append( fileMenu, _( "&File" ) );
menuBar->Append( viewMenu, _( "&View" ) );
menuBar->Append( toolsMenu, _( "&Tools" ) );
menuBar->Append( preferencesMenu, _( "&Preferences" ) );
AddStandardHelpMenu( menuBar );

View File

@ -474,33 +474,3 @@ void GERBVIEW_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
m_SelLayerBox->SetSelection( GetActiveLayer() );
}
void GERBVIEW_FRAME::SyncToolbars()
{
KIGFX::GAL_DISPLAY_OPTIONS& galOpts = GetGalDisplayOptions();
#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) )
TOGGLE_TOOL( m_mainToolBar, ACTIONS::zoomTool );
m_mainToolBar->Refresh();
TOGGLE_TOOL( m_optionsToolBar, ACTIONS::selectionTool );
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::toggleCursorStyle, !galOpts.m_fullscreenCursor );
m_optionsToolBar->Toggle( GERBVIEW_ACTIONS::flashedDisplayOutlines,
!m_DisplayOptions.m_DisplayFlashedItemsFill );
m_optionsToolBar->Toggle( GERBVIEW_ACTIONS::linesDisplayOutlines,
!m_DisplayOptions.m_DisplayLinesFill );
m_optionsToolBar->Toggle( GERBVIEW_ACTIONS::polygonsDisplayOutlines,
!m_DisplayOptions.m_DisplayPolygonsFill );
m_optionsToolBar->Toggle( GERBVIEW_ACTIONS::negativeObjectDisplay,
IsElementVisible( LAYER_NEGATIVE_OBJECTS ) );
m_optionsToolBar->Toggle( GERBVIEW_ACTIONS::dcodeDisplay,
IsElementVisible( LAYER_DCODES ) );
m_optionsToolBar->Toggle( GERBVIEW_ACTIONS::toggleDiffMode,m_DisplayOptions.m_DiffMode );
m_optionsToolBar->Toggle( ACTIONS::highContrastMode, m_DisplayOptions.m_HighContrastMode );
m_optionsToolBar->Toggle( GERBVIEW_ACTIONS::flipGerberView, m_DisplayOptions.m_FlipGerberView );
m_optionsToolBar->Refresh();
}

View File

@ -644,8 +644,8 @@ public:
*/
virtual PICKED_ITEMS_LIST* PopCommandFromRedoList();
int GetUndoCommandCount() const { return m_undoList.m_CommandsList.size(); }
int GetRedoCommandCount() const { return m_redoList.m_CommandsList.size(); }
virtual int GetUndoCommandCount() const { return m_undoList.m_CommandsList.size(); }
virtual int GetRedoCommandCount() const { return m_redoList.m_CommandsList.size(); }
int GetMaxUndoItems() const { return m_UndoRedoCountMax; }
};

View File

@ -0,0 +1,156 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Ian McInerney <ian.s.mcinerney at ieee.org>
* 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 EDITOR_CONDITIONS_H_
#define EDITOR_CONDITIONS_H_
#include <class_draw_panel_gal.h>
#include <common.h>
#include <functional>
#include <tool/selection.h>
#include <tool/selection_conditions.h>
#include <tool/tool_action.h>
class EDA_BASE_FRAME;
class EDA_DRAW_FRAME;
/**
* Class that groups generic conditions for editor states.
*/
class EDITOR_CONDITIONS : public SELECTION_CONDITIONS
{
public:
/**
* Create an object to define conditions dependent upon a specific frame.
*
* @param aFrame is the frame to query for the conditions
*/
EDITOR_CONDITIONS( EDA_BASE_FRAME* aFrame ) :
m_frame( aFrame )
{}
/**
* Creates a functor that tests if the content of the frame is modified.
*
* @return Functor testing for modified content
*/
SELECTION_CONDITION ContentModified();
/**
* Creates a functor that tests if there are any items in the undo queue
*
* @return Functor testing if the undo queue has items.
*/
SELECTION_CONDITION UndoAvailable();
/**
* Creates a functor that tests if there are any items in the redo queue
*
* @return Functor testing if the redo queue has items.
*/
SELECTION_CONDITION RedoAvailable();
/**
* Creates a functor that tests if the frame has the specified units
*
* @return Functor testing the units of a frame.
*/
SELECTION_CONDITION Units( EDA_UNITS aUnit );
/**
* Creates a functor testing if the specified tool is the current active tool in the frame.
*
* @return Functor testing the current tool of a frame
*/
SELECTION_CONDITION CurrentTool( const TOOL_ACTION& aTool );
/**
* Creates a functor testing if the grid is visible in a frame.
*
* @note this requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
*
* @return Functor testing if the grid is visible
*/
SELECTION_CONDITION GridVisible();
/**
* Creates a functor testing if polar coordinates are current being used.
*
* @note this requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
*
* @return Functor testing if the grid is visible
*/
SELECTION_CONDITION PolarCoordinates();
/**
* Creates a functor testing if the cursor is full screen in a frame.
*
* @note this requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
*
* @return Functor testing if the cursor is full screen
*/
SELECTION_CONDITION FullscreenCursor();
/**
* Creates a functor testing if the specified canvas is active in the frame.
*
* @note this requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
*
* @return Functor testing the canvas type of the frame
*/
SELECTION_CONDITION CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE aType );
private:
///> Helper function used by ContentModified()
static bool contentModifiedFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
///> Helper function used by UndoAvailable()
static bool undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
///> Helper function used by RedoAvailable()
static bool redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
///> Helper function used by Units()
static bool unitsFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame, EDA_UNITS aUnits );
///> Helper function used by CurrentTool()
static bool toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame, const TOOL_ACTION& aTool );
///> Helper function used by GridVisible()
static bool gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
///> Helper function used by PolarCoordinates()
static bool polarCoordFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
///> Helper function used by FullscreenCursor()
static bool cursorFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
///> Helper function used by CanvasType()
static bool canvasTypeFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame,
EDA_DRAW_PANEL_GAL::GAL_TYPE aType );
///> The frame to apply the conditions to
EDA_BASE_FRAME* m_frame;
};
#endif /* EDITOR_CONDITIONS_H_ */

View File

@ -42,6 +42,19 @@ SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
SELECTION_CONDITION operator!( const SELECTION_CONDITION& aCondition );
/// Signature for a reference to a function that takes a SELECTION and returns
/// a boolean. This type is meant to be used to define logical operations between
/// SELECTION_CONDITION functors and non-functor SELECTION_CONDITION-like functions.
/// It should not be used in user code.
typedef bool ( &SELECTION_BOOL )( const SELECTION& );
SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
SELECTION_BOOL aConditionB );
SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
SELECTION_BOOL aConditionB );
/**
* Class that groups generic conditions for selected items.
*/
@ -78,6 +91,30 @@ public:
*/
static bool NotEmpty( const SELECTION& aSelection );
/**
* Tests if there are no items selected.
*
* @param aSelection is the selection to be tested.
* @return True if there are no items selected.
*/
static bool Empty( const SELECTION& aSelection );
/**
* Tests if there no items selected or being edited.
*
* @param aSelection is the selection to be tested.
* @return True if there are no items being edited or no items selected.
*/
static bool Idle( const SELECTION& aSelection );
/**
* Tests if all selected items are not being edited.
*
* @param aSelection is the selection to be tested.
* @return True if no selected items are being edited.
*/
static bool IdleSelection( const SELECTION& aSelection );
/**
* Creates a functor that tests if among the selected items there is at least one of a given type.
*
@ -169,6 +206,20 @@ private:
return !aCondition( aSelection );
}
///> Helper function used by operator||
static bool orBoolFunc( const SELECTION_CONDITION& aConditionA,
SELECTION_BOOL& aConditionB, const SELECTION& aSelection )
{
return aConditionA( aSelection ) || aConditionB( aSelection );
}
///> Helper function used by operator&&
static bool andBoolFunc( const SELECTION_CONDITION& aConditionA,
SELECTION_BOOL& aConditionB, const SELECTION& aSelection )
{
return aConditionA( aSelection ) && aConditionB( aSelection );
}
friend SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
const SELECTION_CONDITION& aConditionB );
@ -176,6 +227,12 @@ private:
const SELECTION_CONDITION& aConditionB );
friend SELECTION_CONDITION operator!( const SELECTION_CONDITION& aCondition );
friend SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
SELECTION_BOOL aConditionB );
friend SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
SELECTION_BOOL aConditionB );
};
#endif /* SELECTION_CONDITIONS_H_ */

View File

@ -27,7 +27,7 @@
#include <kiface_i.h>
#include <menus_helpers.h>
#include <pgm_base.h>
#include <tool/conditional_menu.h>
#include <tool/action_menu.h>
#include <tool/tool_manager.h>
#include <tool/selection.h>
#include <tools/pl_actions.h>
@ -45,10 +45,6 @@ void PL_EDITOR_FRAME::ReCreateMenuBar()
wxMenuBar* oldMenuBar = GetMenuBar();
WX_MENUBAR* menuBar = new WX_MENUBAR();
auto modifiedDocumentCondition = [ this ] ( const SELECTION& sel ) {
return IsContentModified();
};
static ACTION_MENU* openRecentMenu; // Open Recent submenu, static to remember this menu
FILE_HISTORY& recentFiles = GetFileHistory();
@ -67,126 +63,101 @@ void PL_EDITOR_FRAME::ReCreateMenuBar()
//-- File menu -------------------------------------------------------
//
CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
fileMenu->AddItem( ACTIONS::doNew, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddItem( ACTIONS::open, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentMenu, FILE_HISTORY::FileHistoryNotEmpty( recentFiles ) );
fileMenu->Add( ACTIONS::doNew );
fileMenu->Add( ACTIONS::open );
fileMenu->AddSeparator();
fileMenu->AddItem( ACTIONS::save, modifiedDocumentCondition );
fileMenu->AddItem( ACTIONS::saveAs, SELECTION_CONDITIONS::ShowAlways );
wxMenuItem* item = fileMenu->Add( openRecentMenu );
fileMenu->AddSeparator();
fileMenu->AddItem( ACTIONS::print, SELECTION_CONDITIONS::ShowAlways );
// Add the file menu condition here since it needs the item ID for the submenu
ACTION_CONDITIONS cond;
cond.SetEnableCondition( FILE_HISTORY::FileHistoryNotEmpty( recentFiles ) );
RegisterUIUpdateHandler( item->GetId(), cond );
fileMenu->AddSeparator();
fileMenu->AppendSeparator();
fileMenu->Add( ACTIONS::save );
fileMenu->Add( ACTIONS::saveAs );
fileMenu->AppendSeparator();
fileMenu->Add( ACTIONS::print );
fileMenu->AppendSeparator();
fileMenu->AddQuitOrClose( &Kiface(), _( "Page Layout 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 idleCondition = [] ( const SELECTION& sel ) {
return !sel.Front() || sel.Front()->GetEditFlags() == 0;
};
editMenu->Add( ACTIONS::undo );
editMenu->Add( ACTIONS::redo );
editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
editMenu->AddSeparator();
editMenu->AddItem( ACTIONS::cut, SELECTION_CONDITIONS::MoreThan( 0 ) );
editMenu->AddItem( ACTIONS::copy, SELECTION_CONDITIONS::MoreThan( 0 ) );
editMenu->AddItem( ACTIONS::paste, idleCondition );
editMenu->AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::MoreThan( 0 ) );
editMenu->Resolve();
editMenu->AppendSeparator();
editMenu->Add( ACTIONS::cut );
editMenu->Add( ACTIONS::copy );
editMenu->Add( ACTIONS::paste );
editMenu->Add( ACTIONS::doDelete );
//-- View menu -------------------------------------------------------
//
CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
auto whiteBackgroundCondition = [ this ] ( const SELECTION& aSel ) {
return GetDrawBgColor() == WHITE;
};
auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
return IsGridVisible();
};
auto fullCrosshairCondition = [ this ] ( const SELECTION& aSel ) {
return GetGalDisplayOptions().m_fullscreenCursor;
};
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->AppendSeparator();
viewMenu->Add( PL_ACTIONS::toggleBackground, ACTION_MENU::CHECK );
viewMenu->Add( ACTIONS::toggleGrid, ACTION_MENU::CHECK );
viewMenu->Add( ACTIONS::toggleCursorStyle, ACTION_MENU::CHECK );
viewMenu->AddSeparator();
viewMenu->AddCheckItem( PL_ACTIONS::toggleBackground, whiteBackgroundCondition );
viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition );
viewMenu->AddSeparator();
viewMenu->AddItem( PL_ACTIONS::previewSettings, SELECTION_CONDITIONS::ShowAlways );
viewMenu->AppendSeparator();
viewMenu->Add( PL_ACTIONS::previewSettings );
#ifdef __APPLE__
viewMenu->AddSeparator();
// Add a separator only on macOS because the OS adds menu items to the view menu after ours
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( PL_ACTIONS::drawLine, SELECTION_CONDITIONS::ShowAlways );
placeMenu->AddItem( PL_ACTIONS::drawRectangle, SELECTION_CONDITIONS::ShowAlways );
placeMenu->AddItem( PL_ACTIONS::placeText, SELECTION_CONDITIONS::ShowAlways );
placeMenu->AddItem( PL_ACTIONS::placeImage, SELECTION_CONDITIONS::ShowAlways );
placeMenu->Add( PL_ACTIONS::drawLine );
placeMenu->Add( PL_ACTIONS::drawRectangle );
placeMenu->Add( PL_ACTIONS::placeText );
placeMenu->Add( PL_ACTIONS::placeImage );
placeMenu->AddSeparator();
placeMenu->AddItem( PL_ACTIONS::appendImportedWorksheet, SELECTION_CONDITIONS::ShowAlways );
placeMenu->Resolve();
placeMenu->AppendSeparator();
placeMenu->Add( PL_ACTIONS::appendImportedWorksheet );
//-- Inspector menu -------------------------------------------------------
//
CONDITIONAL_MENU* inspectorMenu = new CONDITIONAL_MENU( false, selTool );
inspectorMenu->AddItem( PL_ACTIONS::showInspector, SELECTION_CONDITIONS::ShowAlways );
ACTION_MENU* inspectorMenu = new ACTION_MENU( false, selTool );
inspectorMenu->Add( PL_ACTIONS::showInspector );
inspectorMenu->Resolve();
//-- Preferences menu --------------------------------------------------
//
CONDITIONAL_MENU* preferencesMenu = new CONDITIONAL_MENU( false, selTool );
ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
preferencesMenu->AddItem( wxID_PREFERENCES,
_( "Preferences...\tCTRL+," ),
_( "Show preferences for all open tools" ),
preference_xpm, SELECTION_CONDITIONS::ShowAlways );
preferencesMenu->Add( _( "Preferences...\tCTRL+," ),
_( "Show preferences for all open tools" ),
wxID_PREFERENCES,
preference_xpm );
// Language submenu
AddMenuLanguageList( preferencesMenu, selTool );
preferencesMenu->Resolve();
//-- Menubar -----------------------------------------------------------
//
menuBar->Append( fileMenu, _( "&File" ) );
menuBar->Append( editMenu, _( "&Edit" ) );
menuBar->Append( viewMenu, _( "&View" ) );
menuBar->Append( placeMenu, _( "&Place" ) );
menuBar->Append( inspectorMenu, _( "&Inspect" ) );
menuBar->Append( fileMenu, _( "&File" ) );
menuBar->Append( editMenu, _( "&Edit" ) );
menuBar->Append( viewMenu, _( "&View" ) );
menuBar->Append( placeMenu, _( "&Place" ) );
menuBar->Append( inspectorMenu, _( "&Inspect" ) );
menuBar->Append( preferencesMenu, _( "P&references" ) );
AddStandardHelpMenu( menuBar );

View File

@ -43,6 +43,8 @@
#include <confirm.h>
#include <tool/selection.h>
#include <tool/action_toolbar.h>
#include <tool/editor_conditions.h>
#include <tool/selection_conditions.h>
#include <tool/tool_dispatcher.h>
#include <tool/tool_manager.h>
#include <tool/common_control.h>
@ -69,13 +71,8 @@ BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME )
EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, PL_EDITOR_FRAME::OnFileHistory )
EVT_MENU( ID_FILE_LIST_CLEAR, PL_EDITOR_FRAME::OnClearFileHistory )
EVT_TOOL( ID_SHOW_REAL_MODE, PL_EDITOR_FRAME::OnSelectTitleBlockDisplayMode )
EVT_TOOL( ID_SHOW_PL_EDITOR_MODE, PL_EDITOR_FRAME::OnSelectTitleBlockDisplayMode )
EVT_CHOICE( ID_SELECT_COORDINATE_ORIGIN, PL_EDITOR_FRAME::OnSelectCoordOriginCorner )
EVT_CHOICE( ID_SELECT_PAGE_NUMBER, PL_EDITOR_FRAME::OnSelectPage )
EVT_UPDATE_UI( ID_SHOW_REAL_MODE, PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayNormalMode )
EVT_UPDATE_UI( ID_SHOW_PL_EDITOR_MODE, PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayEditMode )
END_EVENT_TABLE()
@ -117,6 +114,7 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
SetScreen( new BASE_SCREEN( pageSizeIU ) );
setupTools();
setupUIConditions();
ReCreateMenuBar();
ReCreateHToolbar();
ReCreateVToolbar();
@ -242,6 +240,69 @@ void PL_EDITOR_FRAME::setupTools()
}
void PL_EDITOR_FRAME::setupUIConditions()
{
EDA_BASE_FRAME::setupUIConditions();
ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
EDITOR_CONDITIONS cond( this );
wxASSERT( mgr );
#define Enable( x ) ACTION_CONDITIONS().SetEnableCondition( x )
#define Check( x ) ACTION_CONDITIONS().SetCheckCondition( 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::cut, Enable( SELECTION_CONDITIONS::MoreThan( 0 ) ) );
mgr->SetConditions( ACTIONS::copy, Enable( SELECTION_CONDITIONS::MoreThan( 0 ) ) );
mgr->SetConditions( ACTIONS::paste, Enable( SELECTION_CONDITIONS::Idle ) );
mgr->SetConditions( ACTIONS::doDelete, Enable( SELECTION_CONDITIONS::MoreThan( 0 ) ) );
mgr->SetConditions( ACTIONS::zoomTool, Check( cond.CurrentTool( ACTIONS::zoomTool ) ) );
mgr->SetConditions( ACTIONS::selectionTool, Check( cond.CurrentTool( ACTIONS::selectionTool ) ) );
mgr->SetConditions( ACTIONS::deleteTool, Check( cond.CurrentTool( ACTIONS::deleteTool ) ) );
mgr->SetConditions( PL_ACTIONS::drawLine, Check( cond.CurrentTool( PL_ACTIONS::drawLine ) ) );
mgr->SetConditions( PL_ACTIONS::drawRectangle, Check( cond.CurrentTool( PL_ACTIONS::drawRectangle ) ) );
mgr->SetConditions( PL_ACTIONS::placeText, Check( cond.CurrentTool( PL_ACTIONS::placeText ) ) );
mgr->SetConditions( PL_ACTIONS::placeImage, Check( cond.CurrentTool( PL_ACTIONS::placeImage ) ) );
// Not a tool, just a way to activate the action
mgr->SetConditions( PL_ACTIONS::appendImportedWorksheet, Check( SELECTION_CONDITIONS::ShowNever ) );
auto whiteBackgroundCondition = [ this ] ( const SELECTION& aSel ) {
return GetDrawBgColor() == WHITE;
};
mgr->SetConditions( PL_ACTIONS::toggleBackground, Check( whiteBackgroundCondition ) );
auto titleBlockNormalMode =
[] ( const SELECTION& )
{
return WS_DATA_MODEL::GetTheInstance().m_EditMode == false;
};
auto titleBlockEditMode =
[] ( const SELECTION& )
{
return WS_DATA_MODEL::GetTheInstance().m_EditMode == true;
};
mgr->SetConditions( PL_ACTIONS::layoutNormalMode, Check( titleBlockNormalMode ) );
mgr->SetConditions( PL_ACTIONS::layoutEditMode, Check( titleBlockEditMode ) );
#undef Check
#undef Enable
}
bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
{
wxString fn = aFileSet[0];
@ -334,13 +395,6 @@ void PL_EDITOR_FRAME::OnSelectCoordOriginCorner( wxCommandEvent& event )
}
void PL_EDITOR_FRAME::OnSelectTitleBlockDisplayMode( wxCommandEvent& event )
{
WS_DATA_MODEL::GetTheInstance().m_EditMode = (event.GetId() == ID_SHOW_PL_EDITOR_MODE);
HardRedraw();
}
void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
{
// static print data and page setup data, to remember settings during the session
@ -386,18 +440,6 @@ void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
}
void PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayNormalMode( wxUpdateUIEvent& event )
{
event.Check( WS_DATA_MODEL::GetTheInstance().m_EditMode == false );
}
void PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayEditMode( wxUpdateUIEvent& event )
{
event.Check( WS_DATA_MODEL::GetTheInstance().m_EditMode == true );
}
const BOX2I PL_EDITOR_FRAME::GetDocumentExtents() const
{
BOX2I rv( VECTOR2I( 0, 0 ), GetPageLayout().GetPageSettings().GetSizeIU() );
@ -746,6 +788,12 @@ PL_DRAW_PANEL_GAL* PL_EDITOR_FRAME::GetCanvas() const
}
SELECTION& PL_EDITOR_FRAME::GetCurrentSelection()
{
return m_toolManager->GetTool<PL_SELECTION_TOOL>()->GetSelection();
}
void PL_EDITOR_FRAME::HardRedraw()
{
GetCanvas()->DisplayWorksheet();

View File

@ -59,6 +59,8 @@ protected:
/// The last filename chosen to be proposed to the user
PROPERTIES_FRAME* m_propertiesPagelayout;
void setupUIConditions() override;
public:
PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent );
~PL_EDITOR_FRAME();
@ -123,6 +125,7 @@ public:
const wxSize GetPageSizeIU() const override;
PL_DRAW_PANEL_GAL* GetCanvas() const override;
SELECTION& GetCurrentSelection() override;
const wxPoint& GetGridOrigin() const override { return m_grid_origin; }
void SetGridOrigin( const wxPoint& aPoint ) override { m_grid_origin = aPoint; }
@ -160,8 +163,6 @@ public:
void ReCreateMenuBar() override;
void SyncToolbars() override;
const PL_EDITOR_LAYOUT& GetPageLayout() const { return m_pageLayout; }
PL_EDITOR_LAYOUT& GetPageLayout() { return m_pageLayout; }
@ -206,9 +207,6 @@ public:
*/
void OnSelectTitleBlockDisplayMode( wxCommandEvent& event );
void OnUpdateTitleBlockDisplayNormalMode( wxUpdateUIEvent& event );
void OnUpdateTitleBlockDisplayEditMode( wxUpdateUIEvent& event );
/**
* Function ToPrinter
* Open a dialog frame to print layers

View File

@ -35,8 +35,6 @@ enum pl_editor_ids
{
ID_MAIN_MENUBAR = ID_END_LIST,
ID_SHOW_REAL_MODE,
ID_SHOW_PL_EDITOR_MODE,
ID_SELECT_COORDINATE_ORIGIN,
ID_SELECT_PAGE_NUMBER,

View File

@ -62,17 +62,8 @@ void PL_EDITOR_FRAME::ReCreateHToolbar()
// Display mode switch
m_mainToolBar->AddScaledSeparator( this );
m_mainToolBar->AddTool( ID_SHOW_REAL_MODE, wxEmptyString,
KiScaledBitmap( pagelayout_normal_view_mode_xpm, this ),
_( "Show title block in preview mode:\n"
"text placeholders will be replaced with preview data."),
wxITEM_CHECK );
m_mainToolBar->AddTool( ID_SHOW_PL_EDITOR_MODE, wxEmptyString,
KiScaledBitmap( pagelayout_special_view_mode_xpm, this ),
_( "Show title block in edit mode:\n"
"text placeholders are shown as ${keyword} tokens."),
wxITEM_CHECK );
m_mainToolBar->Add( PL_ACTIONS::layoutNormalMode, ACTION_TOOLBAR::TOGGLE );
m_mainToolBar->Add( PL_ACTIONS::layoutEditMode, ACTION_TOOLBAR::TOGGLE );
m_mainToolBar->AddScaledSeparator( this );
wxString choiceList[5] =
@ -144,25 +135,3 @@ void PL_EDITOR_FRAME::ReCreateVToolbar()
void PL_EDITOR_FRAME::ReCreateOptToolbar()
{
}
void PL_EDITOR_FRAME::SyncToolbars()
{
#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) )
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 );
m_mainToolBar->Refresh();
TOGGLE_TOOL( m_drawToolBar, ACTIONS::selectionTool );
TOGGLE_TOOL( m_drawToolBar, PL_ACTIONS::drawLine );
TOGGLE_TOOL( m_drawToolBar, PL_ACTIONS::drawRectangle );
TOGGLE_TOOL( m_drawToolBar, PL_ACTIONS::placeText );
TOGGLE_TOOL( m_drawToolBar, PL_ACTIONS::placeImage );
TOGGLE_TOOL( m_drawToolBar, ACTIONS::deleteTool );
m_drawToolBar->Toggle( PL_ACTIONS::appendImportedWorksheet, false ); // Not really a tool
m_drawToolBar->Refresh();
}

View File

@ -91,6 +91,20 @@ TOOL_ACTION PL_ACTIONS::previewSettings( "plEditor.EditorControl.PreviewSettings
_( "Page Preview Settings..." ), _( "Edit preview data for page size and title block" ),
sheetset_xpm );
TOOL_ACTION PL_ACTIONS::layoutNormalMode( "plEditor.EditorControl.LayoutNormalMode",
AS_GLOBAL, 0, "",
_( "Show title block in preview mode" ),
_( "Show title block in preview mode:\n"
"text placeholders will be replaced with preview data." ),
pagelayout_normal_view_mode_xpm );
TOOL_ACTION PL_ACTIONS::layoutEditMode( "plEditor.EditorControl.LayoutEditMode",
AS_GLOBAL, 0, "",
_( "Show title block in edit mode" ),
_( "Show title block in edit mode:\n"
"text placeholders are shown as ${keyword} tokens." ),
pagelayout_special_view_mode_xpm );
// PL_SELECTION_TOOL
//

View File

@ -70,6 +70,9 @@ public:
// Editing
static TOOL_ACTION move;
static TOOL_ACTION layoutNormalMode;
static TOOL_ACTION layoutEditMode;
// Miscellaneous
static TOOL_ACTION refreshPreview;
static TOOL_ACTION toggleBackground;

View File

@ -36,6 +36,7 @@
#include <properties_frame.h>
#include <pl_editor_id.h>
#include <dialog_page_settings.h>
#include <ws_data_model.h>
bool PL_EDITOR_CONTROL::Init()
{
@ -137,6 +138,18 @@ int PL_EDITOR_CONTROL::ShowInspector( const TOOL_EVENT& aEvent )
}
int PL_EDITOR_CONTROL::TitleBlockDisplayMode( const TOOL_EVENT& aEvent )
{
if( aEvent.IsAction( &PL_ACTIONS::layoutEditMode ) )
WS_DATA_MODEL::GetTheInstance().m_EditMode = true;
else
WS_DATA_MODEL::GetTheInstance().m_EditMode = false;
m_frame->HardRedraw();
return 0;
}
int PL_EDITOR_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
{
PL_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PL_SELECTION_TOOL>();
@ -183,6 +196,8 @@ void PL_EDITOR_CONTROL::setTransitions()
Go( &PL_EDITOR_CONTROL::PageSetup, PL_ACTIONS::previewSettings.MakeEvent() );
Go( &PL_EDITOR_CONTROL::ToggleBackgroundColor, PL_ACTIONS::toggleBackground.MakeEvent() );
Go( &PL_EDITOR_CONTROL::ShowInspector, PL_ACTIONS::showInspector.MakeEvent() );
Go( &PL_EDITOR_CONTROL::TitleBlockDisplayMode, PL_ACTIONS::layoutEditMode.MakeEvent() );
Go( &PL_EDITOR_CONTROL::TitleBlockDisplayMode, PL_ACTIONS::layoutNormalMode.MakeEvent() );
Go( &PL_EDITOR_CONTROL::UpdateMessagePanel, EVENTS::SelectedEvent );
Go( &PL_EDITOR_CONTROL::UpdateMessagePanel, EVENTS::UnselectedEvent );

View File

@ -62,6 +62,7 @@ public:
int ToggleBackgroundColor( const TOOL_EVENT& aEvent );
int ShowInspector( const TOOL_EVENT& aEvent );
int TitleBlockDisplayMode( const TOOL_EVENT& aEvent );
/**
* Update the message panel *and* the Properties frame, after change