From 5c984aa0690be40363ac1995d715834eb313b694 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:01 +0200 Subject: [PATCH 01/25] Parametrized TOOL_ACTIONs. --- common/tool/tool_manager.cpp | 10 ++++++++-- include/tool/tool_action.h | 25 +++++++++++-------------- include/tool/tool_event.h | 23 +++++++++++++---------- pcbnew/tools/common_actions.cpp | 19 ++++++++++--------- pcbnew/tools/pcbnew_control.cpp | 21 ++------------------- pcbnew/tools/selection_tool.cpp | 4 ++-- 6 files changed, 46 insertions(+), 56 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index ff6ada4725..db7a6013e8 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -303,7 +303,10 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a if( action ) { TOOL_EVENT event = action->MakeEvent(); - event.SetParameter( aParam ); + + // Allow to override the action parameter + if( aParam ) + event.SetParameter( aParam ); if( aNow ) ProcessEvent( event ); @@ -320,7 +323,10 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam ) { TOOL_EVENT event = aAction.MakeEvent(); - event.SetParameter( aParam ); + + // Allow to override the action parameter + if( aParam ) + event.SetParameter( aParam ); if( aNow ) ProcessEvent( event ); diff --git a/include/tool/tool_action.h b/include/tool/tool_action.h index 032a4aefc7..ff9de67d5a 100644 --- a/include/tool/tool_action.h +++ b/include/tool/tool_action.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 CERN + * Copyright (C) 2013-2015 CERN * @author Tomasz Wlostowski * @author Maciej Suminski * @@ -41,7 +41,7 @@ struct BITMAP_OPAQUE; * - running the DRC from the menu * and so on, and so forth.... * Action class groups all necessary properties of an action, including explanation, - * icons, hotkeys,.menu items, etc. + * icons, hotkeys, menu items, etc. */ class TOOL_ACTION { @@ -49,10 +49,10 @@ public: TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT, int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString, const wxString& aMenuDesc = wxEmptyString, const BITMAP_OPAQUE* aIcon = NULL, - TOOL_ACTION_FLAGS aFlags = AF_NONE ) : + TOOL_ACTION_FLAGS aFlags = AF_NONE, void* aParam = NULL ) : m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ), - m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), - m_menuDescription( aMenuDesc ), m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ) + m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ), + m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam ) { TOOL_MANAGER::GetActionList().push_back( this ); } @@ -150,11 +150,11 @@ public: TOOL_EVENT MakeEvent() const { if( IsActivation() ) - return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope ); + return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope, m_param ); else if( IsNotification() ) - return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope ); + return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope, m_param ); else - return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope ); + return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope, m_param ); } const wxString& GetMenuItem() const @@ -219,7 +219,7 @@ private: /// Name of the action (convention is: app.[tool.]action.name) std::string m_name; - /// Scope of the action (i.e. the event that is issued after activation). + /// Scope of the action TOOL_ACTION_SCOPE m_scope; /// Default hot key that activates the action. @@ -243,11 +243,8 @@ private: /// Action flags TOOL_ACTION_FLAGS m_flags; - /// Origin of the action - // const TOOL_BASE* m_origin; - - /// Originating UI object - // wxWindow* m_uiOrigin; + /// Generic parameter + void* m_param; }; #endif diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index 435451b676..d7ead512ba 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -159,24 +159,24 @@ public: const std::string Format() const; TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory = TC_NONE, TOOL_ACTIONS aAction = TA_NONE, - TOOL_ACTION_SCOPE aScope = AS_GLOBAL ) : + TOOL_ACTION_SCOPE aScope = AS_GLOBAL, void* aParameter = NULL ) : m_category( aCategory ), m_actions( aAction ), m_scope( aScope ), m_mouseButtons( 0 ), m_keyCode( 0 ), m_modifiers( 0 ), - m_param( NULL ) {} + m_param( aParameter ) {} TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction, int aExtraParam, - TOOL_ACTION_SCOPE aScope = AS_GLOBAL ) : + TOOL_ACTION_SCOPE aScope = AS_GLOBAL, void* aParameter = NULL ) : m_category( aCategory ), m_actions( aAction ), m_scope( aScope ), m_mouseButtons( 0 ), m_keyCode( 0 ), m_modifiers( 0 ), - m_param( NULL ) + m_param( aParameter ) { if( aCategory == TC_MOUSE ) { @@ -198,14 +198,15 @@ public: } TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction, - const std::string& aExtraParam, TOOL_ACTION_SCOPE aScope = AS_GLOBAL ) : + const std::string& aExtraParam, TOOL_ACTION_SCOPE aScope = AS_GLOBAL, + void* aParameter = NULL ) : m_category( aCategory ), m_actions( aAction ), m_scope( aScope ), m_mouseButtons( 0 ), m_keyCode( 0 ), m_modifiers( 0 ), - m_param( NULL ) + m_param( aParameter ) { if( aCategory == TC_COMMAND || aCategory == TC_MESSAGE ) m_commandStr = aExtraParam; @@ -360,9 +361,10 @@ public: * Returns a non-standard parameter assigned to the event. Its meaning depends on the * target tool. */ - void* Parameter() const + template + inline T Parameter() const { - return m_param; + return reinterpret_cast( m_param ); } /** @@ -371,9 +373,10 @@ public: * target tool. * @param aParam is the new parameter. */ - void SetParameter(void* aParam) + template + void SetParameter(T aParam) { - m_param = aParam; + m_param = (void*) aParam; } boost::optional GetCommandId() const diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 599111c0e2..b6d2af06d1 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 CERN + * Copyright (C) 2013-2015 CERN * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -25,6 +25,7 @@ #include "common_actions.h" #include #include +#include #include // These members are static in class COMMON_ACTIONS: Build them here: @@ -246,35 +247,35 @@ TOOL_ACTION COMMON_ACTIONS::highContrastDec( "pcbnew.Control.highContrastDec", // Layer control TOOL_ACTION COMMON_ACTIONS::layerTop( "pcbnew.Control.layerTop", AS_GLOBAL, WXK_PAGEUP, - "", "" ); + "", "", NULL, AF_NONE, (void*) F_Cu ); TOOL_ACTION COMMON_ACTIONS::layerInner1( "pcbnew.Control.layerInner1", AS_GLOBAL, WXK_F5, - "", "" ); + "", "", NULL, AF_NONE, (void*) In1_Cu ); TOOL_ACTION COMMON_ACTIONS::layerInner2( "pcbnew.Control.layerInner2", AS_GLOBAL, WXK_F6, - "", "" ); + "", "", NULL, AF_NONE, (void*) In2_Cu ); TOOL_ACTION COMMON_ACTIONS::layerInner3( "pcbnew.Control.layerInner3", AS_GLOBAL, WXK_F7, - "", "" ); + "", "", NULL, AF_NONE, (void*) In3_Cu ); TOOL_ACTION COMMON_ACTIONS::layerInner4( "pcbnew.Control.layerInner4", AS_GLOBAL, WXK_F8, - "", "" ); + "", "", NULL, AF_NONE, (void*) In4_Cu ); TOOL_ACTION COMMON_ACTIONS::layerInner5( "pcbnew.Control.layerInner5", AS_GLOBAL, WXK_F9, - "", "" ); + "", "", NULL, AF_NONE, (void*) In5_Cu ); TOOL_ACTION COMMON_ACTIONS::layerInner6( "pcbnew.Control.layerInner6", AS_GLOBAL, WXK_F10, - "", "" ); + "", "", NULL, AF_NONE, (void*) In6_Cu ); TOOL_ACTION COMMON_ACTIONS::layerBottom( "pcbnew.Control.layerBottom", AS_GLOBAL, WXK_PAGEDOWN, - "", "" ); + "", "", NULL, AF_NONE, (void*) B_Cu ); TOOL_ACTION COMMON_ACTIONS::layerNext( "pcbnew.Control.layerNext", AS_GLOBAL, '+', diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index c32c728f7f..bc4b469ef3 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -285,23 +285,7 @@ int PCBNEW_CONTROL::HighContrastDec( const TOOL_EVENT& aEvent ) // Layer control int PCBNEW_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent ) { - if( aEvent.IsAction( &COMMON_ACTIONS::layerTop ) ) - m_frame->SwitchLayer( NULL, F_Cu ); - else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner1 ) ) - m_frame->SwitchLayer( NULL, In1_Cu ); - else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner2 ) ) - m_frame->SwitchLayer( NULL, In2_Cu ); - else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner3 ) ) - m_frame->SwitchLayer( NULL, In3_Cu ); - else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner4 ) ) - m_frame->SwitchLayer( NULL, In4_Cu ); - else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner5 ) ) - m_frame->SwitchLayer( NULL, In5_Cu ); - else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner6 ) ) - m_frame->SwitchLayer( NULL, In6_Cu ); - else if( aEvent.IsAction( &COMMON_ACTIONS::layerBottom ) ) - m_frame->SwitchLayer( NULL, B_Cu ); - + m_frame->SwitchLayer( NULL, (LAYER_ID) aEvent.Parameter() ); setTransitions(); return 0; @@ -450,8 +434,7 @@ int PCBNEW_CONTROL::GridPrev( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) { Activate(); - m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, - _( "Adjust grid origin" ) ); + m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) ); KIGFX::VIEW_CONTROLS* controls = getViewControls(); controls->ShowCursor( true ); diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 6ea637506e..b6fc1ac055 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -509,7 +509,7 @@ int SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent ) int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent ) { // Check if there is an item to be selected - BOARD_ITEM* item = static_cast( aEvent.Parameter() ); + BOARD_ITEM* item = aEvent.Parameter(); if( item ) { @@ -527,7 +527,7 @@ int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent ) int SELECTION_TOOL::UnselectItem( const TOOL_EVENT& aEvent ) { // Check if there is an item to be selected - BOARD_ITEM* item = static_cast( aEvent.Parameter() ); + BOARD_ITEM* item = aEvent.Parameter(); if( item ) { From 557bb43dd2e7ee1c08d99a2f06bd0a094d4a61ea Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:02 +0200 Subject: [PATCH 02/25] Moved TOOL_MANAGER & TOOL_DISPATCHER to EDA_DRAW_FRAME. --- common/draw_frame.cpp | 8 ++++++++ include/draw_frame.h | 9 +++++++++ include/wxBasePcbFrame.h | 3 --- include/wxstruct.h | 2 ++ pcbnew/basepcbframe.cpp | 7 ------- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 0bdd8ff0b6..a190f57ec6 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -51,6 +51,8 @@ #include #include #include +#include +#include /** * Definition for enabling and disabling scroll bar setting trace output. See the @@ -110,6 +112,8 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, m_canvas = NULL; m_galCanvas = NULL; m_galCanvasActive = false; + m_toolManager = NULL; + m_toolDispatcher = NULL; m_messagePanel = NULL; m_currentScreen = NULL; m_toolId = ID_NO_TOOL_SELECTED; @@ -180,6 +184,10 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, EDA_DRAW_FRAME::~EDA_DRAW_FRAME() { + delete m_toolManager; + delete m_toolDispatcher; + delete m_galCanvas; + delete m_currentScreen; m_currentScreen = NULL; diff --git a/include/draw_frame.h b/include/draw_frame.h index a8ea81e3a9..38613bb0ad 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -72,6 +72,9 @@ protected: /// The area to draw on. EDA_DRAW_PANEL* m_canvas; + TOOL_MANAGER* m_toolManager; + TOOL_DISPATCHER* m_toolDispatcher; + /// Tool ID of previously active draw tool bar button. int m_lastDrawToolId; @@ -730,6 +733,12 @@ public: EDA_DRAW_PANEL_GAL* GetGalCanvas() const { return m_galCanvas; } void SetGalCanvas( EDA_DRAW_PANEL_GAL* aPanel ) { m_galCanvas = aPanel; } + /** + * Function GetToolManager + * returns the tool manager instance, if any. + */ + TOOL_MANAGER* GetToolManager() const { return m_toolManager; } + /** * Function GetDisplayOptions * A way to pass info to draw functions. the base class has no knowledge about diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index 793496888a..cd87d1bb21 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -86,9 +86,6 @@ protected: /// main window. wxAuiToolBar* m_auxiliaryToolBar; - TOOL_MANAGER* m_toolManager; - TOOL_DISPATCHER* m_toolDispatcher; - void updateGridSelectBox(); void updateZoomSelectBox(); virtual void unitsChangeRefresh(); diff --git a/include/wxstruct.h b/include/wxstruct.h index 6ce0a79265..19a9fb6cd4 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -72,6 +72,8 @@ class PAGE_INFO; class PLOTTER; class TITLE_BLOCK; class MSG_PANEL_ITEM; +class TOOL_MANAGER; +class TOOL_DISPATCHER; enum id_librarytype { diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 2721c78285..864a5545b9 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -96,8 +96,6 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame EDA_DRAW_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ) { m_Pcb = NULL; - m_toolManager = NULL; - m_toolDispatcher = NULL; m_Draw3DFrame = NULL; // Display Window in 3D mode (OpenGL) m_UserGridSize = wxRealPoint( 100.0, 100.0 ); @@ -119,12 +117,7 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame PCB_BASE_FRAME::~PCB_BASE_FRAME() { delete m_Collector; - - delete m_toolManager; - delete m_toolDispatcher; - delete m_Pcb; - delete GetGalCanvas(); } From 74a902da2020980aaa51217432eaa6940a3deae5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:02 +0200 Subject: [PATCH 03/25] Syntactic sugar for TOOL_MANAGER::RunAction(). --- include/tool/tool_manager.h | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 23b992cf38..4c60bfa9d6 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -110,7 +110,18 @@ public: * depends on the action. * @return False if the action was not found. */ - bool RunAction( const std::string& aActionName, bool aNow = false, void* aParam = NULL ); + template + bool RunAction( const std::string& aActionName, bool aNow = false, T aParam = NULL ) + { + return RunAction( aActionName, aNow, reinterpret_cast( aParam ) ); + } + + bool RunAction( const std::string& aActionName, bool aNow, void* aParam = NULL ); + + bool RunAction( const std::string& aActionName, bool aNow = false ) + { + return RunAction( aActionName, aNow, (void*) NULL ); + } /** * Function RunAction() @@ -122,7 +133,18 @@ public: * @param aParam is an optional parameter that might be used by the invoked action. Its meaning * depends on the action. */ - void RunAction( const TOOL_ACTION& aAction, bool aNow = false, void* aParam = NULL ); + template + void RunAction( const TOOL_ACTION& aAction, bool aNow = false, T aParam = NULL ) + { + RunAction( aAction, aNow, reinterpret_cast( aParam ) ); + } + + void RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam ); + + void RunAction( const TOOL_ACTION& aAction, bool aNow = false ) + { + RunAction( aAction, aNow, (void*) NULL ); + } /** * Function FindTool() From c4888afbccc55482290bdd5881da9a91137682de Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:02 +0200 Subject: [PATCH 04/25] Refactored the way GAL handles zoom settings. --- common/draw_frame.cpp | 60 ++++++++++++--------------------- common/zoom.cpp | 41 ++++++++++++++-------- include/class_base_screen.h | 2 +- include/draw_frame.h | 13 +++++++ pcbnew/tools/common_actions.cpp | 16 +++++---- pcbnew/tools/common_actions.h | 1 + pcbnew/tools/pcbnew_control.cpp | 30 +++++++++++++++++ pcbnew/tools/pcbnew_control.h | 1 + 8 files changed, 104 insertions(+), 60 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index a190f57ec6..0047ebd653 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -424,8 +424,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) if( IsGalCanvasActive() ) { - GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size.x, - screen->GetGrid().m_Size.y ) ); + GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size ) ); GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); } @@ -456,22 +455,14 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event ) return; GetScreen()->SetZoom( selectedZoom ); - - if( IsGalCanvasActive() ) - { - // Apply computed view settings to GAL - KIGFX::VIEW* view = GetGalCanvas()->GetView(); - KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); - - double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); - double zoom = 1.0 / ( zoomFactor * GetZoom() ); - - view->SetScale( zoom ); - GetGalCanvas()->Refresh(); - } - else - RedrawScreen( GetScrollCenterPosition(), false ); + RedrawScreen( GetScrollCenterPosition(), false ); } + + // Notify GAL + TOOL_MANAGER* mgr = GetToolManager(); + + if( mgr && IsGalCanvasActive() ) + mgr->RunAction( "common.Control.zoomPreset", true, id ); } @@ -1026,38 +1017,29 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + BASE_SCREEN* screen = GetScreen(); // Display the same view after canvas switching - if( aEnable ) + if( aEnable ) // Switch to GAL rendering { - BASE_SCREEN* screen = GetScreen(); - - // Switch to GAL rendering - if( !IsGalCanvasActive() ) - { - // Set up viewport - double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() ); - view->SetScale( zoom ); - view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); - } + // Set up viewport + double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() ); + view->SetScale( zoom ); + view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); // Set up grid settings gal->SetGridVisibility( IsGridVisible() ); - gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) ); + gal->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) ); } - else + else // Switch to standard rendering { - // Switch to standard rendering - if( IsGalCanvasActive() ) - { - // Change view settings only if GAL was active previously - double zoom = 1.0 / ( zoomFactor * view->GetScale() ); - m_canvas->SetZoom( zoom ); + // Change view settings only if GAL was active previously + double zoom = 1.0 / ( zoomFactor * view->GetScale() ); + m_canvas->SetZoom( zoom ); - VECTOR2D center = view->GetCenter(); - RedrawScreen( wxPoint( center.x, center.y ), false ); - } + VECTOR2D center = view->GetCenter(); + AdjustScrollBars( wxPoint( center.x, center.y ) ); } m_canvas->SetEvtHandlerEnabled( !aEnable ); diff --git a/common/zoom.cpp b/common/zoom.cpp index 8f8d34d1b9..ef04c78dfc 100644 --- a/common/zoom.cpp +++ b/common/zoom.cpp @@ -33,8 +33,6 @@ #include #include #include -#include -#include #include #include #include @@ -46,6 +44,9 @@ void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer ) { + if( IsGalCanvasActive() ) + return; + AdjustScrollBars( aCenterPoint ); // Move the mouse cursor to the on grid graphic cursor position @@ -58,6 +59,9 @@ void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointe void EDA_DRAW_FRAME::RedrawScreen2( const wxPoint& posBefore ) { + if( IsGalCanvasActive() ) + return; + wxPoint dPos = posBefore - m_canvas->GetClientSize() / 2; // relative screen position to center before zoom wxPoint newScreenPos = m_canvas->ToDeviceXY( GetCrossHairPosition() ); // screen position of crosshair after zoom wxPoint newCenter = m_canvas->ToLogicalXY( newScreenPos - dPos ); @@ -186,18 +190,7 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event ) break; default: - unsigned i; - - i = id - ID_POPUP_ZOOM_LEVEL_START; - - if( i >= screen->m_ZoomList.size() ) - { - wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ), - __TFILE__, __LINE__, i ); - return; - } - if( screen->SetZoom( screen->m_ZoomList[i] ) ) - RedrawScreen( center, true ); + SetPresetZoom( id - ID_POPUP_ZOOM_LEVEL_START ); } UpdateStatusBar(); @@ -216,6 +209,26 @@ void EDA_DRAW_FRAME::SetPrevZoom() } +void EDA_DRAW_FRAME::SetPresetZoom( int aIndex ) +{ + BASE_SCREEN* screen = GetScreen(); + + if( aIndex >= (int) screen->m_ZoomList.size() ) + { + wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ), + __TFILE__, __LINE__, aIndex ); + return; + } + + m_zoomSelectBox->SetSelection( aIndex ); + + if( screen->SetZoom( screen->m_ZoomList[aIndex] ) ) + RedrawScreen( GetScrollCenterPosition(), true ); + + UpdateStatusBar(); +} + + /* add the zoom list menu the the MasterMenu. * used in OnRightClick(wxMouseEvent& event) */ diff --git a/include/class_base_screen.h b/include/class_base_screen.h index 0ea8fa9e7b..64aba0e999 100644 --- a/include/class_base_screen.h +++ b/include/class_base_screen.h @@ -215,7 +215,7 @@ public: int m_ScreenNumber; int m_NumberOfScreens; - std::vector m_ZoomList; ///< standard zoom (i.e. scale) coefficients. + std::vector m_ZoomList; ///< standard zoom (i.e. scale) coefficients. bool m_IsPrinting; public: diff --git a/include/draw_frame.h b/include/draw_frame.h index 38613bb0ad..d37f03106c 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -346,6 +346,12 @@ public: */ virtual const wxString GetZoomLevelIndicator() const; + /** + * Function GetZoomLevelCoeff + * returns the coefficient to convert internal display scale factor to zoom level. + */ + inline double GetZoomLevelCoeff() const { return m_zoomLevelCoeff; } + void EraseMsgBox(); void Process_PageSettings( wxCommandEvent& event ); @@ -505,6 +511,13 @@ public: */ void SetPrevZoom(); + /** + * Function SetPresetZoom() + * changes zoom to one of the preset values. + * @param aIndex is the zoom index from the list. + */ + void SetPresetZoom( int aIndex ); + /** * Function RedrawScreen * redraws the entire screen area by updating the scroll bars and mouse pointer in diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index b6d2af06d1..9921844e22 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -181,30 +181,34 @@ TOOL_ACTION COMMON_ACTIONS::arcPosture( "pcbnew.InteractiveDrawing.arcPosture", // View Controls -TOOL_ACTION COMMON_ACTIONS::zoomIn( "pcbnew.Control.zoomIn", +TOOL_ACTION COMMON_ACTIONS::zoomIn( "common.Control.zoomIn", AS_GLOBAL, WXK_F1, "", "" ); -TOOL_ACTION COMMON_ACTIONS::zoomOut( "pcbnew.Control.zoomOut", +TOOL_ACTION COMMON_ACTIONS::zoomOut( "common.Control.zoomOut", AS_GLOBAL, WXK_F2, "", "" ); -TOOL_ACTION COMMON_ACTIONS::zoomInCenter( "pcbnew.Control.zoomInCenter", +TOOL_ACTION COMMON_ACTIONS::zoomInCenter( "common.Control.zoomInCenter", AS_GLOBAL, 0, "", "" ); -TOOL_ACTION COMMON_ACTIONS::zoomOutCenter( "pcbnew.Control.zoomOutCenter", +TOOL_ACTION COMMON_ACTIONS::zoomOutCenter( "common.Control.zoomOutCenter", AS_GLOBAL, 0, "", "" ); -TOOL_ACTION COMMON_ACTIONS::zoomCenter( "pcbnew.Control.zoomCenter", +TOOL_ACTION COMMON_ACTIONS::zoomCenter( "common.Control.zoomCenter", AS_GLOBAL, WXK_F4, "", "" ); -TOOL_ACTION COMMON_ACTIONS::zoomFitScreen( "pcbnew.Control.zoomFitScreen", +TOOL_ACTION COMMON_ACTIONS::zoomFitScreen( "common.Control.zoomFitScreen", AS_GLOBAL, WXK_HOME, "", "" ); +TOOL_ACTION COMMON_ACTIONS::zoomPreset( "common.Control.zoomPreset", + AS_GLOBAL, 0, + "", "" ); + // Display modes TOOL_ACTION COMMON_ACTIONS::trackDisplayMode( "pcbnew.Control.trackDisplayMode", diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 2e51f81d30..65eedc7a68 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -188,6 +188,7 @@ public: static TOOL_ACTION zoomOutCenter; static TOOL_ACTION zoomCenter; static TOOL_ACTION zoomFitScreen; + static TOOL_ACTION zoomPreset; // Display modes static TOOL_ACTION trackDisplayMode; diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index bc4b469ef3..ed58de2cac 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -140,6 +140,35 @@ int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent ) } +int PCBNEW_CONTROL::ZoomPreset( const TOOL_EVENT& aEvent ) +{ + unsigned int idx = aEvent.Parameter(); + std::vector& zoomList = m_frame->GetScreen()->m_ZoomList; + KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); + KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); + + m_frame->SetPresetZoom( idx ); + + if( idx == 0 ) + { + return ZoomFitScreen( aEvent ); + } + else if( idx < 0 || idx >= zoomList.size() ) + { + setTransitions(); + return 0; + } + + double selectedZoom = zoomList[idx]; + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + view->SetScale( 1.0 / ( zoomFactor * selectedZoom ) ); + + setTransitions(); + + return 0; +} + + int PCBNEW_CONTROL::TrackDisplayMode( const TOOL_EVENT& aEvent ) { KIGFX::PCB_PAINTER* painter = @@ -539,6 +568,7 @@ void PCBNEW_CONTROL::setTransitions() Go( &PCBNEW_CONTROL::ZoomInOutCenter, COMMON_ACTIONS::zoomOutCenter.MakeEvent() ); Go( &PCBNEW_CONTROL::ZoomCenter, COMMON_ACTIONS::zoomCenter.MakeEvent() ); Go( &PCBNEW_CONTROL::ZoomFitScreen, COMMON_ACTIONS::zoomFitScreen.MakeEvent() ); + Go( &PCBNEW_CONTROL::ZoomPreset, COMMON_ACTIONS::zoomPreset.MakeEvent() ); // Display modes Go( &PCBNEW_CONTROL::TrackDisplayMode, COMMON_ACTIONS::trackDisplayMode.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 7bfec224a2..bbdddbb136 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -51,6 +51,7 @@ public: int ZoomInOutCenter( const TOOL_EVENT& aEvent ); int ZoomCenter( const TOOL_EVENT& aEvent ); int ZoomFitScreen( const TOOL_EVENT& aEvent ); + int ZoomPreset( const TOOL_EVENT& aEvent ); // Display modes int TrackDisplayMode( const TOOL_EVENT& aEvent ); From 50afd515c25ea058e3138a1b639d3807a915b22c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:03 +0200 Subject: [PATCH 05/25] Minor code cleaning. --- common/draw_panel_gal.cpp | 62 +++++++++++++-------------------------- 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index 1458fdfe43..5f6aa6c0ac 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -99,17 +99,10 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL() { - if( m_painter ) - delete m_painter; - - if( m_viewControls ) - delete m_viewControls; - - if( m_view ) - delete m_view; - - if( m_gal ) - delete m_gal; + delete m_painter; + delete m_viewControls; + delete m_view; + delete m_gal; } @@ -194,42 +187,29 @@ void EDA_DRAW_PANEL_GAL::SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher ) m_eventDispatcher = aEventDispatcher; #if wxCHECK_VERSION( 3, 0, 0 ) - if( m_eventDispatcher ) - { - m_parent->Connect( wxEVT_TOOL, - wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), - NULL, m_eventDispatcher ); - } - else - { - // While loops are used to be sure, that we are removing all event handlers - while( m_parent->Disconnect( wxEVT_TOOL, - wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), - NULL, m_eventDispatcher ) ); - } + const wxEventType eventTypes[] = { wxEVT_TOOL }; #else + const wxEventType eventTypes[] = { wxEVT_COMMAND_MENU_SELECTED, wxEVT_COMMAND_TOOL_CLICKED }; +#endif + if( m_eventDispatcher ) { - m_parent->Connect( wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), - NULL, m_eventDispatcher ); - - m_parent->Connect( wxEVT_COMMAND_TOOL_CLICKED, - wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), - NULL, m_eventDispatcher ); + BOOST_FOREACH( wxEventType type, eventTypes ) + { + m_parent->Connect( type, wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), + NULL, m_eventDispatcher ); + } } else { - // While loops are used to be sure, that we are removing all event handlers - while( m_parent->Disconnect( wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), - NULL, m_eventDispatcher ) ); - - while( m_parent->Disconnect( wxEVT_COMMAND_TOOL_CLICKED, - wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), - NULL, m_eventDispatcher ) ); + BOOST_FOREACH( wxEventType type, eventTypes ) + { + // While loop is used to be sure that all event handlers are removed. + while( m_parent->Disconnect( type, + wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), + NULL, m_eventDispatcher ) ); + } } -#endif } @@ -316,7 +296,7 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) m_backend = aGalType; } - catch (std::runtime_error& err) + catch( std::runtime_error& err ) { DisplayError( m_parent, wxString( err.what() ) ); return false; From 6e45180b5ac8425325fef8f7d2203e9b99845030 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:03 +0200 Subject: [PATCH 06/25] Two extra filters for .bzrignore. --- .bzrignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bzrignore b/.bzrignore index e91f863965..00136e4f70 100644 --- a/.bzrignore +++ b/.bzrignore @@ -31,6 +31,8 @@ install_manifest.txt Documentation/doxygen Documentation/development/doxygen *.bak +.*.swp +*.~* common/pcb_plot_params_keywords.cpp include/pcb_plot_params_lexer.h pcbnew/specctra_keywords.cpp From 946b9d193322a70f1b71914e584f4f507651e0a4 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:03 +0200 Subject: [PATCH 07/25] setTransitions() are called automatically for tools. --- common/tool/tool_manager.cpp | 6 ++++ include/tool/tool_base.h | 7 ++++ pcbnew/tools/drawing_tool.cpp | 18 +--------- pcbnew/tools/drawing_tool.h | 6 ++-- pcbnew/tools/edit_tool.cpp | 47 +----------------------- pcbnew/tools/edit_tool.h | 6 ++-- pcbnew/tools/module_tools.cpp | 19 +--------- pcbnew/tools/module_tools.h | 4 +-- pcbnew/tools/pcb_editor_control.cpp | 24 +------------ pcbnew/tools/pcb_editor_control.h | 4 +-- pcbnew/tools/pcbnew_control.cpp | 55 ++--------------------------- pcbnew/tools/pcbnew_control.h | 7 ++-- pcbnew/tools/placement_tool.cpp | 16 +-------- pcbnew/tools/placement_tool.h | 4 +-- pcbnew/tools/point_editor.cpp | 10 ++---- pcbnew/tools/point_editor.h | 6 ++-- pcbnew/tools/selection_tool.cpp | 17 +-------- pcbnew/tools/selection_tool.h | 6 ++-- 18 files changed, 43 insertions(+), 219 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index db7a6013e8..cabf2d5302 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -389,6 +389,7 @@ bool TOOL_MANAGER::runTool( TOOL_BASE* aTool ) } aTool->Reset( TOOL_INTERACTIVE::RUN ); + aTool->SetTransitions(); // Add the tool on the front of the processing queue (it gets events first) m_activeTools.push_front( aTool->GetId() ); @@ -425,7 +426,10 @@ void TOOL_MANAGER::ResetTools( TOOL_BASE::RESET_REASON aReason ) ProcessEvent( evt ); BOOST_FOREACH( TOOL_BASE* tool, m_toolState | boost::adaptors::map_keys ) + { tool->Reset( aReason ); + tool->SetTransitions(); + } } @@ -621,6 +625,8 @@ void TOOL_MANAGER::finishTool( TOOL_STATE* aState ) if( tool != m_activeTools.end() ) m_activeTools.erase( tool ); } + + aState->theTool->SetTransitions(); } diff --git a/include/tool/tool_base.h b/include/tool/tool_base.h index 5ebeacffb6..77a5d5badc 100644 --- a/include/tool/tool_base.h +++ b/include/tool/tool_base.h @@ -140,6 +140,13 @@ public: return m_toolMgr; } + /** + * Function SetTransitions() + * This method is meant to be overridden in order to specify handlers for events. It is called + * every time tool is reset or finished. + */ + virtual void SetTransitions() {}; + protected: friend class TOOL_MANAGER; diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 1eca131b39..adb005e00f 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -66,8 +66,6 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason ) m_controls = getViewControls(); m_board = getModel(); m_frame = getEditFrame(); - - setTransitions(); } @@ -124,7 +122,6 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) } } - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -172,7 +169,6 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) } } - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -220,7 +216,6 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) } } - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -411,7 +406,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) m_controls->CaptureCursor( false ); m_view->Remove( &preview ); - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -442,11 +436,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) const std::list& list = dlg.GetImportedItems(); if( dlgResult != wxID_OK || m_board->m_Modules == NULL || list.empty() ) - { - setTransitions(); - return 0; - } VECTOR2I cursorPos = m_controls->GetCursorPosition(); VECTOR2I delta = cursorPos - (*list.begin())->GetPosition(); @@ -617,8 +607,6 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) m_controls->CaptureCursor( false ); m_view->Remove( &preview ); - setTransitions(); - return 0; } @@ -663,7 +651,6 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) m_controls->SetSnapping( false ); m_controls->ShowCursor( false ); - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -1230,7 +1217,6 @@ int DRAWING_TOOL::drawZone( bool aKeepout ) m_controls->CaptureCursor( false ); m_view->Remove( &preview ); - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -1351,7 +1337,6 @@ int DRAWING_TOOL::placeTextModule() m_controls->CaptureCursor( true ); m_view->Remove( &preview ); - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -1461,7 +1446,6 @@ int DRAWING_TOOL::placeTextPcb() m_controls->CaptureCursor( false ); m_view->Remove( &preview ); - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -1490,7 +1474,7 @@ void DRAWING_TOOL::make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) } -void DRAWING_TOOL::setTransitions() +void DRAWING_TOOL::SetTransitions() { Go( &DRAWING_TOOL::DrawLine, COMMON_ACTIONS::drawLine.MakeEvent() ); Go( &DRAWING_TOOL::DrawCircle, COMMON_ACTIONS::drawCircle.MakeEvent() ); diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index fbea3a564d..432da1e64b 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -132,6 +132,9 @@ public: m_editModules = aEnabled; } + ///> Sets up handlers for various events. + void SetTransitions(); + private: ///> Starts drawing a selected shape (i.e. DRAWSEGMENT). ///> @param aShape is the type of created shape (@see STROKE_T). @@ -176,9 +179,6 @@ private: */ void make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const; - ///> Sets up handlers for various events. - void setTransitions(); - ///> Returns the appropriate width for a segment depending on the settings. int getSegmentWidth( unsigned int aLayer ) const; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 18af0eea8f..6a4326f473 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -96,8 +96,6 @@ bool EDIT_TOOL::Init() m_offset.x = 0; m_offset.y = 0; - setTransitions(); - return true; } @@ -128,10 +126,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) // Be sure that there is at least one item that we can modify. If nothing was selected before, // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection) if( !hoverSelection( selection ) ) - { - setTransitions(); return 0; - } Activate(); @@ -345,8 +340,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) controls->SetAutoPan( false ); controls->ForceCursorPosition( false ); - setTransitions(); - return 0; } @@ -357,11 +350,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); if( !hoverSelection( selection, false ) ) - { - setTransitions(); - return 0; - } // Properties are displayed when there is only one item selected if( selection.Size() == 1 ) @@ -398,8 +387,6 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) item->SetFlags( flags ); } - setTransitions(); - return 0; } @@ -413,11 +400,7 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) bool unselect = selection.Empty(); if( !hoverSelection( selection ) ) - { - setTransitions(); - return 0; - } wxPoint rotatePoint = getModificationPoint( selection ); @@ -453,7 +436,6 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); - setTransitions(); return 0; } @@ -468,11 +450,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) bool unselect = selection.Empty(); if( !hoverSelection( selection ) ) - { - setTransitions(); - return 0; - } wxPoint flipPoint = getModificationPoint( selection ); @@ -507,7 +485,6 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); - setTransitions(); return 0; } @@ -518,11 +495,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) const SELECTION& selection = m_selectionTool->GetSelection(); if( !hoverSelection( selection ) ) - { - setTransitions(); - return 0; - } // Get a copy of the selected items set PICKED_ITEMS_LIST selectedItems = selection.items; @@ -544,8 +517,6 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) getModel()->GetRatsnest()->Recalculate(); - setTransitions(); - return 0; } @@ -655,11 +626,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) bool unselect = selection.Empty(); if( !hoverSelection( selection ) ) - { - setTransitions(); - return 0; - } wxPoint translation; double rotation = 0; @@ -705,8 +672,6 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); } - setTransitions(); - return 0; } @@ -721,10 +686,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // Be sure that there is at least one item that we can modify if( !hoverSelection( selection ) ) - { - setTransitions(); return 0; - } // we have a selection to work on now, so start the tool process @@ -803,8 +765,6 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // and re-enable undos decUndoInhibit(); - setTransitions(); - return 0; } @@ -817,10 +777,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) // Be sure that there is at least one item that we can modify if( !hoverSelection( selection ) ) - { - setTransitions(); return 0; - } bool originalItemsModified = false; @@ -980,13 +937,12 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) } getModel()->GetRatsnest()->Recalculate(); - setTransitions(); return 0; } -void EDIT_TOOL::setTransitions() +void EDIT_TOOL::SetTransitions() { Go( &EDIT_TOOL::Main, COMMON_ACTIONS::editActivate.MakeEvent() ); Go( &EDIT_TOOL::Rotate, COMMON_ACTIONS::rotate.MakeEvent() ); @@ -1125,6 +1081,5 @@ int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent ) editor->Show( true ); editor->Raise(); // Iconize( false ); - setTransitions(); return 0; } diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 009d53c6d5..6bf9a283b1 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -126,6 +126,9 @@ public: m_editModules = aEnabled; } + ///> Sets up handlers for various events. + void SetTransitions(); + private: ///> Selection tool used for obtaining selected items SELECTION_TOOL* m_selectionTool; @@ -149,9 +152,6 @@ private: ///> Removes and frees a single BOARD_ITEM. void remove( BOARD_ITEM* aItem ); - ///> Sets up handlers for various events. - void setTransitions(); - ///> The required update flag for modified items KIGFX::VIEW_ITEM::VIEW_UPDATE_FLAGS m_updateFlag; diff --git a/pcbnew/tools/module_tools.cpp b/pcbnew/tools/module_tools.cpp index 0d602c455c..658e5d1ad0 100644 --- a/pcbnew/tools/module_tools.cpp +++ b/pcbnew/tools/module_tools.cpp @@ -76,8 +76,6 @@ bool MODULE_TOOLS::Init() selectionTool->AddMenuItem( COMMON_ACTIONS::enumeratePads ); - setTransitions(); - return true; } @@ -170,7 +168,6 @@ int MODULE_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) m_controls->SetAutoPan( false ); m_view->Remove( &preview ); - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -200,11 +197,7 @@ int MODULE_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) DIALOG_ENUM_PADS settingsDlg( m_frame ); if( settingsDlg.ShowModal() == wxID_CANCEL ) - { - setTransitions(); - return 0; - } int padNumber = settingsDlg.GetStartNumber(); wxString padPrefix = settingsDlg.GetPrefix(); @@ -312,8 +305,6 @@ int MODULE_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) m_frame->DisplayToolMsg( wxEmptyString ); m_controls->ShowCursor( false ); - setTransitions(); - return 0; } @@ -384,8 +375,6 @@ int MODULE_TOOLS::CopyItems( const TOOL_EVENT& aEvent ) m_controls->ShowCursor( false ); m_controls->SetAutoPan( false ); - setTransitions(); - return 0; } @@ -406,8 +395,6 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) catch( ... ) { m_frame->DisplayToolMsg( _( "Invalid clipboard contents" ) ); - setTransitions(); - return 0; } @@ -516,8 +503,6 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) m_controls->SetAutoPan( false ); m_view->Remove( &preview ); - setTransitions(); - return 0; } @@ -553,7 +538,6 @@ int MODULE_TOOLS::ModuleTextOutlines( const TOOL_EVENT& aEvent ) } m_frame->GetGalCanvas()->Refresh(); - setTransitions(); return 0; } @@ -585,13 +569,12 @@ int MODULE_TOOLS::ModuleEdgeOutlines( const TOOL_EVENT& aEvent ) } m_frame->GetGalCanvas()->Refresh(); - setTransitions(); return 0; } -void MODULE_TOOLS::setTransitions() +void MODULE_TOOLS::SetTransitions() { Go( &MODULE_TOOLS::PlacePad, COMMON_ACTIONS::placePad.MakeEvent() ); Go( &MODULE_TOOLS::EnumeratePads, COMMON_ACTIONS::enumeratePads.MakeEvent() ); diff --git a/pcbnew/tools/module_tools.h b/pcbnew/tools/module_tools.h index 8b001d7518..a2c4891268 100644 --- a/pcbnew/tools/module_tools.h +++ b/pcbnew/tools/module_tools.h @@ -98,10 +98,10 @@ public: */ int ModuleEdgeOutlines( const TOOL_EVENT& aEvent ); -private: ///> Sets up handlers for various events. - void setTransitions(); + void SetTransitions(); +private: KIGFX::VIEW* m_view; KIGFX::VIEW_CONTROLS* m_controls; BOARD* m_board; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index e382367bb2..8577f1a8ea 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -78,8 +78,6 @@ bool PCB_EDITOR_CONTROL::Init() SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) ); } - setTransitions(); - return true; } @@ -98,8 +96,6 @@ int PCB_EDITOR_CONTROL::TrackWidthInc( const TOOL_EVENT& aEvent ) wxUpdateUIEvent dummy; m_frame->OnUpdateSelectTrackWidth( dummy ); - setTransitions(); - m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); return 0; @@ -119,8 +115,6 @@ int PCB_EDITOR_CONTROL::TrackWidthDec( const TOOL_EVENT& aEvent ) wxUpdateUIEvent dummy; m_frame->OnUpdateSelectTrackWidth( dummy ); - setTransitions(); - m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); return 0; @@ -140,8 +134,6 @@ int PCB_EDITOR_CONTROL::ViaSizeInc( const TOOL_EVENT& aEvent ) wxUpdateUIEvent dummy; m_frame->OnUpdateSelectViaSize( dummy ); - setTransitions(); - m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); return 0; @@ -161,8 +153,6 @@ int PCB_EDITOR_CONTROL::ViaSizeDec( const TOOL_EVENT& aEvent ) wxUpdateUIEvent dummy; m_frame->OnUpdateSelectViaSize( dummy ); - setTransitions(); - m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); return 0; @@ -277,7 +267,6 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) controls->CaptureCursor( false ); view->Remove( &preview ); - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -370,7 +359,6 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) controls->CaptureCursor( false ); view->Remove( &preview ); - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -393,8 +381,6 @@ int PCB_EDITOR_CONTROL::ZoneFill( const TOOL_EVENT& aEvent ) zone->ViewUpdate(); } - setTransitions(); - return 0; } @@ -411,8 +397,6 @@ int PCB_EDITOR_CONTROL::ZoneFillAll( const TOOL_EVENT& aEvent ) zone->ViewUpdate(); } - setTransitions(); - return 0; } @@ -432,8 +416,6 @@ int PCB_EDITOR_CONTROL::ZoneUnfill( const TOOL_EVENT& aEvent ) zone->ViewUpdate(); } - setTransitions(); - return 0; } @@ -450,8 +432,6 @@ int PCB_EDITOR_CONTROL::ZoneUnfillAll( const TOOL_EVENT& aEvent ) zone->ViewUpdate(); } - setTransitions(); - return 0; } @@ -464,13 +444,11 @@ int PCB_EDITOR_CONTROL::SelectionCrossProbe( const TOOL_EVENT& aEvent ) if( selection.Size() == 1 ) m_frame->SendMessageToEESCHEMA( selection.Item( 0 ) ); - setTransitions(); - return 0; } -void PCB_EDITOR_CONTROL::setTransitions() +void PCB_EDITOR_CONTROL::SetTransitions() { // Track & via size control Go( &PCB_EDITOR_CONTROL::TrackWidthInc, COMMON_ACTIONS::trackWidthInc.MakeEvent() ); diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index d9f40dc174..31ba8ebddb 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -72,10 +72,10 @@ public: ///> Notifies eeschema about the selected item. int SelectionCrossProbe( const TOOL_EVENT& aEvent ); -private: ///> Sets up handlers for various events. - void setTransitions(); + void SetTransitions(); +private: ///> Pointer to the currently used edit frame. PCB_EDIT_FRAME* m_frame; diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index ed58de2cac..40974aba8e 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -52,14 +52,6 @@ void PCBNEW_CONTROL::Reset( RESET_REASON aReason ) } -bool PCBNEW_CONTROL::Init() -{ - setTransitions(); - - return true; -} - - int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); @@ -71,7 +63,6 @@ int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent ) zoomScale = 0.7; view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() ); - setTransitions(); return 0; } @@ -88,7 +79,6 @@ int PCBNEW_CONTROL::ZoomInOutCenter( const TOOL_EVENT& aEvent ) zoomScale = 0.7; view->SetScale( view->GetScale() * zoomScale ); - setTransitions(); return 0; } @@ -98,7 +88,6 @@ int PCBNEW_CONTROL::ZoomCenter( const TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); view->SetCenter( getViewControls()->GetCursorPosition() ); - setTransitions(); return 0; } @@ -134,8 +123,6 @@ int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent ) view->SetCenter( boardBBox.Centre() ); } - setTransitions(); - return 0; } @@ -150,21 +137,14 @@ int PCBNEW_CONTROL::ZoomPreset( const TOOL_EVENT& aEvent ) m_frame->SetPresetZoom( idx ); if( idx == 0 ) - { return ZoomFitScreen( aEvent ); - } else if( idx < 0 || idx >= zoomList.size() ) - { - setTransitions(); return 0; - } double selectedZoom = zoomList[idx]; double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); view->SetScale( 1.0 / ( zoomFactor * selectedZoom ) ); - setTransitions(); - return 0; } @@ -188,7 +168,6 @@ int PCBNEW_CONTROL::TrackDisplayMode( const TOOL_EVENT& aEvent ) } m_frame->GetGalCanvas()->Refresh(); - setTransitions(); return 0; } @@ -213,7 +192,6 @@ int PCBNEW_CONTROL::PadDisplayMode( const TOOL_EVENT& aEvent ) } m_frame->GetGalCanvas()->Refresh(); - setTransitions(); return 0; } @@ -238,7 +216,6 @@ int PCBNEW_CONTROL::ViaDisplayMode( const TOOL_EVENT& aEvent ) } m_frame->GetGalCanvas()->Refresh(); - setTransitions(); return 0; } @@ -269,7 +246,6 @@ int PCBNEW_CONTROL::ZoneDisplayMode( const TOOL_EVENT& aEvent ) board->GetArea( i )->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->GetGalCanvas()->Refresh(); - setTransitions(); return 0; } @@ -287,8 +263,6 @@ int PCBNEW_CONTROL::HighContrastMode( const TOOL_EVENT& aEvent ) settings->LoadDisplayOptions( displ_opts ); m_frame->GetGalCanvas()->SetHighContrastLayer( m_frame->GetActiveLayer() ); - setTransitions(); - return 0; } @@ -296,7 +270,6 @@ int PCBNEW_CONTROL::HighContrastMode( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::HighContrastInc( const TOOL_EVENT& aEvent ) { std::cout << __PRETTY_FUNCTION__ << std::endl; - setTransitions(); return 0; } @@ -305,7 +278,6 @@ int PCBNEW_CONTROL::HighContrastInc( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::HighContrastDec( const TOOL_EVENT& aEvent ) { std::cout << __PRETTY_FUNCTION__ << std::endl; - setTransitions(); return 0; } @@ -315,7 +287,6 @@ int PCBNEW_CONTROL::HighContrastDec( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent ) { m_frame->SwitchLayer( NULL, (LAYER_ID) aEvent.Parameter() ); - setTransitions(); return 0; } @@ -327,10 +298,7 @@ int PCBNEW_CONTROL::LayerNext( const TOOL_EVENT& aEvent ) LAYER_NUM layer = editFrame->GetActiveLayer(); if( layer < F_Cu || layer > B_Cu ) - { - setTransitions(); return 0; - } int layerCount = getModel()->GetCopperLayerCount(); @@ -343,7 +311,6 @@ int PCBNEW_CONTROL::LayerNext( const TOOL_EVENT& aEvent ) assert( IsCopperLayer( layer ) ); editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) ); - setTransitions(); return 0; } @@ -355,10 +322,7 @@ int PCBNEW_CONTROL::LayerPrev( const TOOL_EVENT& aEvent ) LAYER_NUM layer = editFrame->GetActiveLayer(); if( layer < F_Cu || layer > B_Cu ) - { - setTransitions(); return 0; - } int layerCount = getModel()->GetCopperLayerCount(); @@ -371,7 +335,6 @@ int PCBNEW_CONTROL::LayerPrev( const TOOL_EVENT& aEvent ) assert( IsCopperLayer( layer ) ); editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) ); - setTransitions(); return 0; } @@ -394,8 +357,6 @@ int PCBNEW_CONTROL::LayerAlphaInc( const TOOL_EVENT& aEvent ) m_frame->GetGalCanvas()->GetView()->UpdateLayerColor( currentLayer ); } - setTransitions(); - return 0; } @@ -417,8 +378,6 @@ int PCBNEW_CONTROL::LayerAlphaDec( const TOOL_EVENT& aEvent ) m_frame->GetGalCanvas()->GetView()->UpdateLayerColor( currentLayer ); } - setTransitions(); - return 0; } @@ -427,7 +386,6 @@ int PCBNEW_CONTROL::LayerAlphaDec( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridFast1( const TOOL_EVENT& aEvent ) { m_frame->SetFastGrid1(); - setTransitions(); return 0; } @@ -436,7 +394,6 @@ int PCBNEW_CONTROL::GridFast1( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridFast2( const TOOL_EVENT& aEvent ) { m_frame->SetFastGrid2(); - setTransitions(); return 0; } @@ -445,7 +402,6 @@ int PCBNEW_CONTROL::GridFast2( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridNext( const TOOL_EVENT& aEvent ) { m_frame->SetNextGrid(); - setTransitions(); return 0; } @@ -454,7 +410,6 @@ int PCBNEW_CONTROL::GridNext( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridPrev( const TOOL_EVENT& aEvent ) { m_frame->SetPrevGrid(); - setTransitions(); return 0; } @@ -485,7 +440,6 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) controls->SetAutoPan( false ); controls->SetSnapping( false ); controls->ShowCursor( false ); - setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -499,7 +453,6 @@ int PCBNEW_CONTROL::ResetCoords( const TOOL_EVENT& aEvent ) m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y ); m_frame->UpdateStatusBar(); - setTransitions(); return 0; } @@ -517,8 +470,6 @@ int PCBNEW_CONTROL::SwitchCursor( const TOOL_EVENT& aEvent ) else gal->SetCursorSize( BIG_CURSOR ); - setTransitions(); - return 0; } @@ -534,7 +485,6 @@ int PCBNEW_CONTROL::SwitchUnits( const TOOL_EVENT& aEvent ) evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_INCH ); m_frame->ProcessEvent( evt ); - setTransitions(); return 0; } @@ -544,7 +494,6 @@ int PCBNEW_CONTROL::ShowHelp( const TOOL_EVENT& aEvent ) { // TODO DisplayInfoMessage( m_frame, _( "Not implemented yet." ) ); - setTransitions(); return 0; } @@ -553,13 +502,12 @@ int PCBNEW_CONTROL::ShowHelp( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::ToBeDone( const TOOL_EVENT& aEvent ) { DisplayInfoMessage( m_frame, _( "Not implemented yet." ) ); - setTransitions(); return 0; } -void PCBNEW_CONTROL::setTransitions() +void PCBNEW_CONTROL::SetTransitions() { // View controls Go( &PCBNEW_CONTROL::ZoomInOut, COMMON_ACTIONS::zoomIn.MakeEvent() ); @@ -601,6 +549,7 @@ void PCBNEW_CONTROL::setTransitions() Go( &PCBNEW_CONTROL::GridNext, COMMON_ACTIONS::gridNext.MakeEvent() ); Go( &PCBNEW_CONTROL::GridPrev, COMMON_ACTIONS::gridPrev.MakeEvent() ); Go( &PCBNEW_CONTROL::GridSetOrigin, COMMON_ACTIONS::gridSetOrigin.MakeEvent() ); + //Go( &PCBNEW_CONTROL::GridSetPreset, COMMON_ACTIONS::gridSetPreset.MakeEvent() ); // Miscellaneous Go( &PCBNEW_CONTROL::ResetCoords, COMMON_ACTIONS::resetCoords.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index bbdddbb136..7c6d904691 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -43,9 +43,6 @@ public: /// @copydoc TOOL_INTERACTIVE::Reset() void Reset( RESET_REASON aReason ); - /// @copydoc TOOL_INTERACTIVE::Init() - bool Init(); - // View controls int ZoomInOut( const TOOL_EVENT& aEvent ); int ZoomInOutCenter( const TOOL_EVENT& aEvent ); @@ -83,10 +80,10 @@ public: int ShowHelp( const TOOL_EVENT& aEvent ); int ToBeDone( const TOOL_EVENT& aEvent ); -private: ///> Sets up handlers for various events. - void setTransitions(); + void SetTransitions(); +private: ///> Pointer to the currently used edit frame. PCB_BASE_FRAME* m_frame; }; diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index 6e647a193c..555f37611f 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -66,8 +66,6 @@ bool PLACEMENT_TOOL::Init() m_selectionTool->AddSubMenu( menu, _( "Align/distribute" ), SELECTION_CONDITIONS::MoreThan( 1 ) ); - setTransitions(); - return true; } @@ -109,8 +107,6 @@ int PLACEMENT_TOOL::AlignTop( const TOOL_EVENT& aEvent ) getModel()->GetRatsnest()->Recalculate(); } - setTransitions(); - return 0; } @@ -152,8 +148,6 @@ int PLACEMENT_TOOL::AlignBottom( const TOOL_EVENT& aEvent ) getModel()->GetRatsnest()->Recalculate(); } - setTransitions(); - return 0; } @@ -195,8 +189,6 @@ int PLACEMENT_TOOL::AlignLeft( const TOOL_EVENT& aEvent ) getModel()->GetRatsnest()->Recalculate(); } - setTransitions(); - return 0; } @@ -238,8 +230,6 @@ int PLACEMENT_TOOL::AlignRight( const TOOL_EVENT& aEvent ) getModel()->GetRatsnest()->Recalculate(); } - setTransitions(); - return 0; } @@ -299,8 +289,6 @@ int PLACEMENT_TOOL::DistributeHorizontally( const TOOL_EVENT& aEvent ) getModel()->GetRatsnest()->Recalculate(); } - setTransitions(); - return 0; } @@ -348,13 +336,11 @@ int PLACEMENT_TOOL::DistributeVertically( const TOOL_EVENT& aEvent ) getModel()->GetRatsnest()->Recalculate(); } - setTransitions(); - return 0; } -void PLACEMENT_TOOL::setTransitions() +void PLACEMENT_TOOL::SetTransitions() { Go( &PLACEMENT_TOOL::AlignTop, COMMON_ACTIONS::alignTop.MakeEvent() ); Go( &PLACEMENT_TOOL::AlignBottom, COMMON_ACTIONS::alignBottom.MakeEvent() ); diff --git a/pcbnew/tools/placement_tool.h b/pcbnew/tools/placement_tool.h index 75e52fb07c..e7beb75de4 100644 --- a/pcbnew/tools/placement_tool.h +++ b/pcbnew/tools/placement_tool.h @@ -77,10 +77,10 @@ public: */ int DistributeVertically( const TOOL_EVENT& aEvent ); -private: ///> Sets up handlers for various events. - void setTransitions(); + void SetTransitions(); +private: SELECTION_TOOL* m_selectionTool; }; diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 2897eca830..ebe888e794 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -213,8 +213,6 @@ bool POINT_EDITOR::Init() m_selectionTool->AddMenuItem( COMMON_ACTIONS::pointEditorBreakOutline, POINT_EDITOR::breakOutlineCondition ); - setTransitions(); - return true; } @@ -233,11 +231,9 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) EDA_ITEM* item = selection.items.GetPickedItem( 0 ); m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() ); + if( !m_editPoints ) - { - setTransitions(); return 0; - } view->Add( m_editPoints.get() ); m_dragPoint = NULL; @@ -363,8 +359,6 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) controls->ForceCursorPosition( false ); } - setTransitions(); - return 0; } @@ -795,7 +789,7 @@ void POINT_EDITOR::breakOutline( const VECTOR2I& aBreakPoint ) } -void POINT_EDITOR::setTransitions() +void POINT_EDITOR::SetTransitions() { Go( &POINT_EDITOR::OnSelectionChange, SELECTION_TOOL::SelectedEvent ); Go( &POINT_EDITOR::OnSelectionChange, SELECTION_TOOL::UnselectedEvent ); diff --git a/pcbnew/tools/point_editor.h b/pcbnew/tools/point_editor.h index fa3b1360fa..c9a039f35a 100644 --- a/pcbnew/tools/point_editor.h +++ b/pcbnew/tools/point_editor.h @@ -55,6 +55,9 @@ public: */ int OnSelectionChange( const TOOL_EVENT& aEvent ); + ///> Sets up handlers for various events. + void SetTransitions(); + private: ///> Selection tool used for obtaining selected items SELECTION_TOOL* m_selectionTool; @@ -98,9 +101,6 @@ private: ///> Adds a new edit point on a zone outline/line. void breakOutline( const VECTOR2I& aBreakPoint ); - ///> Sets up handlers for various events. - void setTransitions(); - ///> Condition to display "Create corner" context menu entry. static bool breakOutlineCondition( const SELECTION& aSelection ); }; diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index b6fc1ac055..04c3ef0a97 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -106,8 +106,6 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason ) // Reinsert the VIEW_GROUP, in case it was removed from the VIEW getView()->Remove( m_selection.group ); getView()->Add( m_selection.group ); - - setTransitions(); } @@ -428,7 +426,7 @@ bool SELECTION_TOOL::selectMultiple() } -void SELECTION_TOOL::setTransitions() +void SELECTION_TOOL::SetTransitions() { Go( &SELECTION_TOOL::Main, COMMON_ACTIONS::selectionActivate.MakeEvent() ); Go( &SELECTION_TOOL::CursorSelection, COMMON_ACTIONS::selectionCursor.MakeEvent() ); @@ -492,7 +490,6 @@ SELECTION_LOCK_FLAGS SELECTION_TOOL::CheckLock() int SELECTION_TOOL::CursorSelection( const TOOL_EVENT& aEvent ) { selectCursor( getView()->ToWorld( getViewControls()->GetMousePosition() ) ); - setTransitions(); return 0; } @@ -501,7 +498,6 @@ int SELECTION_TOOL::CursorSelection( const TOOL_EVENT& aEvent ) int SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent ) { clearSelection(); - setTransitions(); return 0; } @@ -519,8 +515,6 @@ int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent ) m_toolMgr->ProcessEvent( SelectedEvent ); } - setTransitions(); - return 0; } @@ -537,8 +531,6 @@ int SELECTION_TOOL::UnselectItem( const TOOL_EVENT& aEvent ) m_toolMgr->ProcessEvent( UnselectedEvent ); } - setTransitions(); - return 0; } @@ -562,8 +554,6 @@ int SELECTION_TOOL::selectConnection( const TOOL_EVENT& aEvent ) m_toolMgr->ProcessEvent( selectEvent ); } - setTransitions(); - return 0; } @@ -588,8 +578,6 @@ int SELECTION_TOOL::selectNet( const TOOL_EVENT& aEvent ) m_toolMgr->ProcessEvent( selectEvent ); } - setTransitions(); - return 0; } @@ -618,7 +606,6 @@ int SELECTION_TOOL::find( const TOOL_EVENT& aEvent ) dlg.EnableWarp( false ); dlg.SetCallback( boost::bind( &SELECTION_TOOL::findCallback, this, _1 ) ); dlg.ShowModal(); - setTransitions(); return 0; } @@ -635,8 +622,6 @@ int SELECTION_TOOL::findMove( const TOOL_EVENT& aEvent ) m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" ); } - setTransitions(); - return 0; } diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index e986199751..0c5b701d24 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -185,6 +185,9 @@ public: ///> Event sent after selection is cleared. static const TOOL_EVENT ClearedEvent; + ///> Sets up handlers for various events. + void SetTransitions(); + private: /** * Function selectCursor() @@ -221,9 +224,6 @@ private: ///> Find an item and start moving. int findMove( const TOOL_EVENT& aEvent ); - ///> Sets up handlers for various events. - void setTransitions(); - /** * Function clearSelection() * Clears the current selection. From 4be876a13afc6431dc9fc319aa81d17579806221 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:04 +0200 Subject: [PATCH 08/25] Expandable CONTEXT_MENUs (GAL). Minor CONTEXT_MENU --- common/tool/context_menu.cpp | 139 +++++++++++++++++++------------- include/tool/context_menu.h | 41 +++++----- pcbnew/router/router_tool.cpp | 4 +- pcbnew/tools/selection_tool.cpp | 12 +-- pcbnew/tools/selection_tool.h | 4 +- 5 files changed, 114 insertions(+), 86 deletions(-) diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index 016911647f..08bada78e7 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -33,14 +33,11 @@ CONTEXT_MENU::CONTEXT_MENU() : m_titleSet( false ), m_selected( -1 ), m_tool( NULL ), m_icon( NULL ) { - setCustomEventHandler( boost::bind( &CONTEXT_MENU::handleCustomEvent, this, _1 ) ); setupEvents(); } -CONTEXT_MENU::CONTEXT_MENU( const CONTEXT_MENU& aMenu ) : - m_titleSet( aMenu.m_titleSet ), m_selected( -1 ), m_tool( aMenu.m_tool ), - m_toolActions( aMenu.m_toolActions ), m_customHandler( aMenu.m_customHandler ) +CONTEXT_MENU::CONTEXT_MENU( const CONTEXT_MENU& aMenu ) { copyFrom( aMenu ); setupEvents(); @@ -51,12 +48,6 @@ CONTEXT_MENU& CONTEXT_MENU::operator=( const CONTEXT_MENU& aMenu ) { Clear(); - m_titleSet = aMenu.m_titleSet; - m_selected = aMenu.m_selected; - m_tool = aMenu.m_tool; - m_toolActions = aMenu.m_toolActions; - m_customHandler = aMenu.m_customHandler; - copyFrom( aMenu ); setupEvents(); @@ -90,7 +81,7 @@ void CONTEXT_MENU::SetTitle( const wxString& aTitle ) } -void CONTEXT_MENU::Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon ) +wxMenuItem* CONTEXT_MENU::Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon ) { #ifdef DEBUG @@ -103,18 +94,18 @@ void CONTEXT_MENU::Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aI if( aIcon ) item->SetBitmap( KiBitmap( aIcon ) ); - Append( item ); + return Append( item ); } -void CONTEXT_MENU::Add( const TOOL_ACTION& aAction ) +wxMenuItem* CONTEXT_MENU::Add( const TOOL_ACTION& aAction ) { - /// ID numbers for tool actions need to have a value higher than m_actionId - int id = m_actionId + aAction.GetId(); + /// ID numbers for tool actions need to have a value higher than ACTION_ID + int id = ACTION_ID + aAction.GetId(); const BITMAP_OPAQUE* icon = aAction.GetIcon(); - wxMenuItem* item = new wxMenuItem( this, id, - aAction.GetMenuItem(), aAction.GetDescription(), wxITEM_NORMAL ); + wxMenuItem* item = new wxMenuItem( this, id, aAction.GetMenuItem(), + aAction.GetDescription(), wxITEM_NORMAL ); if( icon ) item->SetBitmap( KiBitmap( icon ) ); @@ -136,24 +127,45 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction ) item->SetAccel( &accel ); } - Append( item ); m_toolActions[id] = &aAction; + + return Append( item ); } -void CONTEXT_MENU::Add( CONTEXT_MENU* aMenu, const wxString& aLabel ) +std::list CONTEXT_MENU::Add( CONTEXT_MENU* aMenu, const wxString& aLabel, bool aExpand ) { - if( aMenu->m_icon ) + std::list items; + + if( aExpand ) { - wxMenuItem* newItem = new wxMenuItem( this, -1, aLabel, wxEmptyString, wxITEM_NORMAL ); - newItem->SetBitmap( KiBitmap( aMenu->m_icon ) ); - newItem->SetSubMenu( aMenu ); - Append( newItem ); + unsigned int i = 0; + + for( i = 0; i < aMenu->GetMenuItemCount(); ++i ) + { + wxMenuItem* item = aMenu->FindItemByPosition( i ); + items.push_back( appendCopy( item ) ); + } } else { - AppendSubMenu( aMenu, aLabel ); + if( aMenu->m_icon ) + { + wxMenuItem* newItem = new wxMenuItem( this, -1, aLabel, wxEmptyString, wxITEM_NORMAL ); + newItem->SetBitmap( KiBitmap( aMenu->m_icon ) ); + newItem->SetSubMenu( aMenu ); + items.push_back( Append( newItem ) ); + } + else + { + items.push_back( AppendSubMenu( aMenu, aLabel ) ); + } } + + m_toolActions.insert( aMenu->m_toolActions.begin(), aMenu->m_toolActions.end() ); + m_handlers.insert( m_handlers.end(), aMenu->m_handlers.begin(), aMenu->m_handlers.end() ); + + return items; } @@ -164,6 +176,7 @@ void CONTEXT_MENU::Clear() GetMenuItems().DeleteContents( true ); GetMenuItems().Clear(); m_toolActions.clear(); + m_handlers.clear(); GetMenuItems().DeleteContents( false ); // restore the default so destructor does not go wild assert( GetMenuItemCount() == 0 ); @@ -211,7 +224,14 @@ void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent ) } } #endif - evt = m_customHandler( aEvent ); + for( std::list::iterator it = m_handlers.begin(); + it != m_handlers.end(); ++it ) + { + evt = (*it)( aEvent ); + + if( evt ) + break; + } // Handling non-action menu entries (e.g. items in clarification list) if( !evt ) @@ -244,49 +264,56 @@ void CONTEXT_MENU::setTool( TOOL_INTERACTIVE* aTool ) } -void CONTEXT_MENU::copyItem( const wxMenuItem* aSource, wxMenuItem* aDest ) const +wxMenuItem* CONTEXT_MENU::appendCopy( const wxMenuItem* aSource ) { - assert( !aSource->IsSubMenu() ); // it does not transfer submenus + wxMenuItem* newItem = new wxMenuItem( this, aSource->GetId(), aSource->GetItemLabel(), + aSource->GetHelp(), aSource->GetKind() ); - aDest->SetKind( aSource->GetKind() ); - aDest->SetHelp( aSource->GetHelp() ); - aDest->Enable( aSource->IsEnabled() ); + if( aSource->GetKind() == wxITEM_NORMAL ) + newItem->SetBitmap( aSource->GetBitmap() ); - if( aSource->IsCheckable() ) - aDest->Check( aSource->IsChecked() ); + if( aSource->IsSubMenu() ) + { +#ifdef DEBUG + // Submenus of a CONTEXT_MENU are supposed to be CONTEXT_MENUs as well + assert( dynamic_cast( aSource->GetSubMenu() ) ); +#endif + + CONTEXT_MENU* menu = new CONTEXT_MENU( static_cast( *aSource->GetSubMenu() ) ); + newItem->SetSubMenu( menu ); + Append( newItem ); + + m_toolActions.insert( menu->m_toolActions.begin(), menu->m_toolActions.end() ); + m_handlers.insert( m_handlers.end(), menu->m_handlers.begin(), menu->m_handlers.end() ); + } + else + { + Append( newItem ); + newItem->SetKind( aSource->GetKind() ); + newItem->SetHelp( aSource->GetHelp() ); + newItem->Enable( aSource->IsEnabled() ); + + if( aSource->IsCheckable() ) + newItem->Check( aSource->IsChecked() ); + } + + return newItem; } void CONTEXT_MENU::copyFrom( const CONTEXT_MENU& aMenu ) { m_icon = aMenu.m_icon; + m_titleSet = aMenu.m_titleSet; + m_selected = -1; // aMenu.m_selected; + m_tool = aMenu.m_tool; + m_toolActions = aMenu.m_toolActions; + m_handlers = aMenu.m_handlers; // Copy all the menu entries for( unsigned i = 0; i < aMenu.GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu.FindItemByPosition( i ); - - wxMenuItem* newItem = new wxMenuItem( this, item->GetId(), item->GetItemLabel(), - item->GetHelp(), item->GetKind() ); - - if( item->GetKind() == wxITEM_NORMAL ) - newItem->SetBitmap( item->GetBitmap() ); - - if( item->IsSubMenu() ) - { -#ifdef DEBUG - // Submenus of a CONTEXT_MENU are supposed to be CONTEXT_MENUs as well - assert( dynamic_cast( item->GetSubMenu() ) ); -#endif - - CONTEXT_MENU* menu = new CONTEXT_MENU( static_cast( *item->GetSubMenu() ) ); - newItem->SetSubMenu( menu ); - Append( newItem ); - } - else - { - Append( newItem ); - copyItem( item, newItem ); - } + appendCopy( item ); } } diff --git a/include/tool/context_menu.h b/include/tool/context_menu.h index 7d629d14eb..5acf177cb0 100644 --- a/include/tool/context_menu.h +++ b/include/tool/context_menu.h @@ -77,7 +77,7 @@ public: * @param aId is the ID that is sent in the TOOL_EVENT. It should be unique for every entry. * @param aIcon is an optional icon. */ - void Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon = NULL ); + wxMenuItem* Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon = NULL ); /** * Function Add() @@ -85,7 +85,7 @@ public: * a TOOL_EVENT command containing name of the action is sent. * @param aAction is the action to be added to menu entry. */ - void Add( const TOOL_ACTION& aAction ); + wxMenuItem* Add( const TOOL_ACTION& aAction ); /** * Function Add() @@ -93,8 +93,10 @@ public: * is the capability to handle icons. * @param aMenu is the submenu to be added. * @param aLabel is the caption displayed for the menu entry. + * @param aExpand allows to add all entries from the menu as individual entries rather than + * add everything as a submenu. */ - void Add( CONTEXT_MENU* aMenu, const wxString& aLabel ); + std::list Add( CONTEXT_MENU* aMenu, const wxString& aLabel, bool aExpand = false ); /** * Function Clear() @@ -114,23 +116,21 @@ public: return m_selected; } -protected: - void setCustomEventHandler( boost::function aHandler ) - { - m_customHandler = aHandler; - } + ///> Function type to handle menu events in a custom way. + typedef boost::function CUSTOM_MENU_HANDLER; - virtual OPT_TOOL_EVENT handleCustomEvent( const wxMenuEvent& aEvent ) + ///> Adds an event handler to the custom menu event handlers chain. + void AppendCustomEventHandler( CUSTOM_MENU_HANDLER aHandler ) { - return OPT_TOOL_EVENT(); + m_handlers.push_back( aHandler ); } private: /** - * Function copyItem - * Copies all properties of a menu entry to another. + * Function appendCopy + * Appends a copy of wxMenuItem. */ - void copyItem( const wxMenuItem* aSource, wxMenuItem* aDest ) const; + wxMenuItem* appendCopy( const wxMenuItem* aSource ); ///> Common part of copy constructor and assignment operator. void copyFrom( const CONTEXT_MENU& aMenu ); @@ -154,22 +154,19 @@ private: ///> Stores the id number of selected item. int m_selected; - ///> Instance of menu event handler. - //CMEventHandler m_handler; - ///> Creator of the menu TOOL_INTERACTIVE* m_tool; - /// Menu items with ID higher than that are considered TOOL_ACTIONs - static const int m_actionId = 10000; + ///> Menu items with ID higher than that are considered TOOL_ACTIONs + static const int ACTION_ID = 30000; - /// Associates tool actions with menu item IDs. Non-owning. + ///> Associates tool actions with menu item IDs. Non-owning. std::map m_toolActions; - /// Custom events handler, allows to translate wxEvents to TOOL_EVENTs. - boost::function m_customHandler; + ///> Chain of custom menu event handlers. + std::list m_handlers; - /// Optional icon + ///> Optional icon const BITMAP_OPAQUE* m_icon; friend class TOOL_INTERACTIVE; diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 1710df9eac..644e6efe5a 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -96,8 +96,8 @@ public: { m_board = NULL; SetIcon( width_track_via_xpm ); - setCustomEventHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::handleCustomEvent, - this, _1 ) ); + AppendCustomEventHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::handleCustomEvent, + this, _1 ) ); } void SetBoard( BOARD* aBoard ) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 04c3ef0a97..f60bd845fa 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -242,7 +242,7 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) void SELECTION_TOOL::AddMenuItem( const TOOL_ACTION& aAction, const SELECTION_CONDITION& aCondition ) { - assert( aAction.GetId() > 0 ); // Check if the action was registered before in ACTION_MANAGER + assert( aAction.GetId() > 0 ); // Check if action was previously registered in ACTION_MANAGER m_menu.Add( aAction ); m_menuConditions.push_back( aCondition ); @@ -250,10 +250,12 @@ void SELECTION_TOOL::AddMenuItem( const TOOL_ACTION& aAction, const SELECTION_CO void SELECTION_TOOL::AddSubMenu( CONTEXT_MENU* aMenu, const wxString& aLabel, - const SELECTION_CONDITION& aCondition ) + const SELECTION_CONDITION& aCondition, bool aExpand ) { - m_menu.Add( aMenu, aLabel ); - m_menuConditions.push_back( aCondition ); + std::list items = m_menu.Add( aMenu, aLabel, aExpand ); + + for( unsigned int i = 0; i < items.size(); ++i ) + m_menuConditions.push_back( aCondition ); } @@ -1285,7 +1287,7 @@ void SELECTION_TOOL::generateMenu() assert( m_menuCopy.GetMenuItemCount() == m_menuConditions.size() ); - // Filter out entries that does not apply to the current selection + // Filter out entries that do not comply with the current selection for( int i = m_menuCopy.GetMenuItemCount() - 1; i >= 0; --i ) { try diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 0c5b701d24..bc726ed8b1 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -141,9 +141,11 @@ public: * @param aMenu is the submenu to be added. * @param aLabel is the label of added submenu. * @param aCondition is a condition that has to be fulfilled to enable the submenu entry. + * @param aExpand determines if the added submenu items should be added as individual items. */ void AddSubMenu( CONTEXT_MENU* aMenu, const wxString& aLabel, - const SELECTION_CONDITION& aCondition = SELECTION_CONDITIONS::ShowAlways ); + const SELECTION_CONDITION& aCondition = SELECTION_CONDITIONS::ShowAlways, + bool aExpand = false ); /** * Function EditModules() From 025d4cf23a6fa9568bd31f05638374dd8eb9089a Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:04 +0200 Subject: [PATCH 09/25] Alternative way of handling grid settings in GAL. --- common/draw_frame.cpp | 82 ++++++++++++--------------------- include/draw_frame.h | 7 +++ pcbnew/tools/common_actions.cpp | 13 ++++-- pcbnew/tools/common_actions.h | 1 + pcbnew/tools/pcbnew_control.cpp | 17 ++++++- pcbnew/tools/pcbnew_control.h | 1 + 6 files changed, 63 insertions(+), 58 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 0047ebd653..59ebf87e5a 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -387,46 +387,17 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) else { eventId = event.GetId(); - - /* Update the grid select combobox if the grid size was changed - * by menu event. - */ - if( m_gridSelectBox != NULL ) - { - for( size_t i = 0; i < m_gridSelectBox->GetCount(); i++ ) - { - clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( i ); - - if( clientData && eventId == *clientData ) - { - m_gridSelectBox->SetSelection( i ); - break; - } - } - } } - // Be sure m_LastGridSizeId is up to date. - m_LastGridSizeId = eventId - ID_POPUP_GRID_LEVEL_1000; + int idx = eventId - ID_POPUP_GRID_LEVEL_1000; - BASE_SCREEN* screen = GetScreen(); + // Notify GAL + TOOL_MANAGER* mgr = GetToolManager(); - if( screen->GetGridId() == eventId ) - return; - - /* - * This allows for saving non-sequential command ID offsets used that - * may be used in the grid size combobox. Do not use the selection - * index returned by GetSelection(). - */ - screen->SetGrid( eventId ); - SetCrossHairPosition( RefPos( true ) ); - - if( IsGalCanvasActive() ) - { - GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size ) ); - GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); - } + if( mgr && IsGalCanvasActive() ) + mgr->RunAction( "common.Control.gridPreset", true, idx ); + else + SetPresetGrid( idx ); m_canvas->Refresh(); } @@ -556,14 +527,7 @@ wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const void EDA_DRAW_FRAME::SetNextGrid() { if( m_gridSelectBox ) - { - m_gridSelectBox->SetSelection( ( m_gridSelectBox->GetSelection() + 1 ) % - m_gridSelectBox->GetCount() ); - - wxCommandEvent cmd( wxEVT_COMMAND_COMBOBOX_SELECTED ); - // cmd.SetEventObject( this ); - OnSelectGrid( cmd ); - } + SetPresetGrid( ( m_gridSelectBox->GetSelection() + 1 ) % m_gridSelectBox->GetCount() ); } @@ -571,20 +535,34 @@ void EDA_DRAW_FRAME::SetPrevGrid() { if( m_gridSelectBox ) { - int cnt = m_gridSelectBox->GetSelection(); + int idx = m_gridSelectBox->GetSelection(); - if( --cnt < 0 ) - cnt = m_gridSelectBox->GetCount() - 1; + if( --idx < 0 ) + idx = m_gridSelectBox->GetCount() - 1; - m_gridSelectBox->SetSelection( cnt ); - - wxCommandEvent cmd( wxEVT_COMMAND_COMBOBOX_SELECTED ); - // cmd.SetEventObject( this ); - OnSelectGrid( cmd ); + SetPresetGrid( idx ); } } +void EDA_DRAW_FRAME::SetPresetGrid( int aIndex ) +{ + if( aIndex < 0 || aIndex >= (int) m_gridSelectBox->GetCount() ) + { + wxASSERT_MSG( false, "Invalid grid index" ); + return; + } + + if( m_gridSelectBox ) + m_gridSelectBox->SetSelection( aIndex ); + + // Be sure m_LastGridSizeId is up to date. + m_LastGridSizeId = aIndex; + GetScreen()->SetGrid( aIndex + ID_POPUP_GRID_LEVEL_1000 ); + SetCrossHairPosition( RefPos( true ) ); +} + + int EDA_DRAW_FRAME::BlockCommand( int key ) { return 0; diff --git a/include/draw_frame.h b/include/draw_frame.h index d37f03106c..098a78f9fd 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -439,6 +439,13 @@ public: */ virtual void SetPrevGrid(); + /** + * Function SetPresetGrid() + * changes the grid size to one of the preset values. + * @param aIndex is the index from the list. + */ + void SetPresetGrid( int aIndex ); + /** * Command event handler for selecting grid sizes. * diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 9921844e22..17ac5046cc 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -303,26 +303,29 @@ TOOL_ACTION COMMON_ACTIONS::layerChanged( "pcbnew.Control.layerChanged", // Grid control -TOOL_ACTION COMMON_ACTIONS::gridFast1( "pcbnew.Control.gridFast1", +TOOL_ACTION COMMON_ACTIONS::gridFast1( "common.Control.gridFast1", AS_GLOBAL, MD_ALT + int( '1' ), "", "" ); -TOOL_ACTION COMMON_ACTIONS::gridFast2( "pcbnew.Control.gridFast2", +TOOL_ACTION COMMON_ACTIONS::gridFast2( "common.Control.gridFast2", AS_GLOBAL, MD_ALT + int( '2' ), "", "" ); -TOOL_ACTION COMMON_ACTIONS::gridNext( "pcbnew.Control.gridNext", +TOOL_ACTION COMMON_ACTIONS::gridNext( "common.Control.gridNext", AS_GLOBAL, '`', "", "" ); -TOOL_ACTION COMMON_ACTIONS::gridPrev( "pcbnew.Control.gridPrev", +TOOL_ACTION COMMON_ACTIONS::gridPrev( "common.Control.gridPrev", AS_GLOBAL, MD_CTRL + int( '`' ), "", "" ); -TOOL_ACTION COMMON_ACTIONS::gridSetOrigin( "pcbnew.Control.gridSetOrigin", +TOOL_ACTION COMMON_ACTIONS::gridSetOrigin( "common.Control.gridSetOrigin", AS_GLOBAL, 0, "", "" ); +TOOL_ACTION COMMON_ACTIONS::gridPreset( "common.Control.gridPreset", + AS_GLOBAL, 0, + "", "" ); // Track & via size control TOOL_ACTION COMMON_ACTIONS::trackWidthInc( "pcbnew.EditorControl.trackWidthInc", diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 65eedc7a68..106221b0a1 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -223,6 +223,7 @@ public: static TOOL_ACTION gridNext; static TOOL_ACTION gridPrev; static TOOL_ACTION gridSetOrigin; + static TOOL_ACTION gridPreset; // Track & via size control static TOOL_ACTION trackWidthInc; diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 40974aba8e..90be91582a 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -446,6 +446,21 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) } +int PCBNEW_CONTROL::GridPreset( const TOOL_EVENT& aEvent ) +{ + long idx = aEvent.Parameter(); + + m_frame->SetPresetGrid( idx ); + BASE_SCREEN* screen = m_frame->GetScreen(); + GRID_TYPE grid = screen->GetGrid( idx ); + + getView()->GetGAL()->SetGridSize( VECTOR2D( grid.m_Size ) ); + getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); + + return 0; +} + + // Miscellaneous int PCBNEW_CONTROL::ResetCoords( const TOOL_EVENT& aEvent ) { @@ -549,7 +564,7 @@ void PCBNEW_CONTROL::SetTransitions() Go( &PCBNEW_CONTROL::GridNext, COMMON_ACTIONS::gridNext.MakeEvent() ); Go( &PCBNEW_CONTROL::GridPrev, COMMON_ACTIONS::gridPrev.MakeEvent() ); Go( &PCBNEW_CONTROL::GridSetOrigin, COMMON_ACTIONS::gridSetOrigin.MakeEvent() ); - //Go( &PCBNEW_CONTROL::GridSetPreset, COMMON_ACTIONS::gridSetPreset.MakeEvent() ); + Go( &PCBNEW_CONTROL::GridPreset, COMMON_ACTIONS::gridPreset.MakeEvent() ); // Miscellaneous Go( &PCBNEW_CONTROL::ResetCoords, COMMON_ACTIONS::resetCoords.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 7c6d904691..c0f41fa3a0 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -72,6 +72,7 @@ public: int GridNext( const TOOL_EVENT& aEvent ); int GridPrev( const TOOL_EVENT& aEvent ); int GridSetOrigin( const TOOL_EVENT& aEvent ); + int GridPreset( const TOOL_EVENT& aEvent ); // Miscellaneous int ResetCoords( const TOOL_EVENT& aEvent ); From 10a4b640054e1ec8285d29eef3f479b35db8f89e Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:04 +0200 Subject: [PATCH 10/25] More icons for context menus. --- pcbnew/tools/common_actions.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 17ac5046cc..8eac887772 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -122,7 +122,7 @@ TOOL_ACTION COMMON_ACTIONS::flip( "pcbnew.InteractiveEdit.flip", TOOL_ACTION COMMON_ACTIONS::remove( "pcbnew.InteractiveEdit.remove", AS_GLOBAL, WXK_DELETE, - _( "Remove" ), _( "Deletes selected item(s)" ), delete_track_xpm ); + _( "Remove" ), _( "Deletes selected item(s)" ), delete_xpm ); TOOL_ACTION COMMON_ACTIONS::properties( "pcbnew.InteractiveEdit.properties", AS_GLOBAL, 'E', @@ -183,11 +183,11 @@ TOOL_ACTION COMMON_ACTIONS::arcPosture( "pcbnew.InteractiveDrawing.arcPosture", // View Controls TOOL_ACTION COMMON_ACTIONS::zoomIn( "common.Control.zoomIn", AS_GLOBAL, WXK_F1, - "", "" ); + "Zoom In", "", zoom_in_xpm ); TOOL_ACTION COMMON_ACTIONS::zoomOut( "common.Control.zoomOut", AS_GLOBAL, WXK_F2, - "", "" ); + "Zoom Out", "", zoom_out_xpm ); TOOL_ACTION COMMON_ACTIONS::zoomInCenter( "common.Control.zoomInCenter", AS_GLOBAL, 0, @@ -199,11 +199,11 @@ TOOL_ACTION COMMON_ACTIONS::zoomOutCenter( "common.Control.zoomOutCenter", TOOL_ACTION COMMON_ACTIONS::zoomCenter( "common.Control.zoomCenter", AS_GLOBAL, WXK_F4, - "", "" ); + "Center", "", zoom_center_on_screen_xpm ); TOOL_ACTION COMMON_ACTIONS::zoomFitScreen( "common.Control.zoomFitScreen", AS_GLOBAL, WXK_HOME, - "", "" ); + "Zoom Auto", "", zoom_fit_in_page_xpm ); TOOL_ACTION COMMON_ACTIONS::zoomPreset( "common.Control.zoomPreset", AS_GLOBAL, 0, From dfb0443b670e746245cbdb6544fc24165e5cf9b2 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:05 +0200 Subject: [PATCH 11/25] Refactoring library dependencies. --- common/CMakeLists.txt | 11 ++++++++--- cvpcb/CMakeLists.txt | 17 ----------------- gerbview/CMakeLists.txt | 1 - pagelayout_editor/CMakeLists.txt | 1 - pcbnew/CMakeLists.txt | 8 -------- 5 files changed, 8 insertions(+), 30 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 1e7a3971f2..a182fdd362 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -56,9 +56,14 @@ set( GAL_SRCS add_library( gal STATIC ${GAL_SRCS} ) add_dependencies( gal shader_headers ) - add_dependencies( gal lib-dependencies ) -add_dependencies( shader_headers lib-dependencies ) + +target_link_libraries( gal + ${GLEW_LIBRARIES} + ${CAIRO_LIBRARIES} + ${PIXMAN_LIBRARY} + ${OPENGL_LIBRARIES} +) # Only for win32 cross compilation using MXE @@ -247,7 +252,7 @@ set( COMMON_SRCS ) add_library( common STATIC ${COMMON_SRCS} ) add_dependencies( common lib-dependencies ) - +target_link_libraries( common ${Boost_LIBRARIES} ) set( PCB_COMMON_SRCS base_screen.cpp diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index 052f009bc2..fba2d99e61 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -117,26 +117,9 @@ target_link_libraries( cvpcb_kiface polygon gal ${wxWidgets_LIBRARIES} - ${OPENGL_LIBRARIES} ${GDI_PLUS_LIBRARIES} - ${GLEW_LIBRARIES} - ${CAIRO_LIBRARIES} - ${PIXMAN_LIBRARY} - ${OPENMP_LIBRARIES} ) -# Only for win32 cross compilation using MXE -if( WIN32 AND MSYS AND CMAKE_CROSSCOMPILING ) - target_link_libraries( cvpcb_kiface - opengl32 - glu32 - pixman-1 - fontconfig - freetype - bz2 - ) -endif() - if( BUILD_GITHUB_PLUGIN ) target_link_libraries( cvpcb_kiface github_plugin ) endif() diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt index 5f737f85c3..d9f99ab09f 100644 --- a/gerbview/CMakeLists.txt +++ b/gerbview/CMakeLists.txt @@ -131,7 +131,6 @@ target_link_libraries( gerbview_kiface common polygon bitmaps - ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} ${GDI_PLUS_LIBRARIES} ) diff --git a/pagelayout_editor/CMakeLists.txt b/pagelayout_editor/CMakeLists.txt index b38936a9e5..f28999ed77 100644 --- a/pagelayout_editor/CMakeLists.txt +++ b/pagelayout_editor/CMakeLists.txt @@ -100,7 +100,6 @@ target_link_libraries( pl_editor_kiface common polygon bitmaps - ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} ${GDI_PLUS_LIBRARIES} ) diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 77ce1a2b94..5dc358f3a3 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -413,11 +413,7 @@ if( KICAD_SCRIPTING_MODULES ) polygon bitmaps gal - ${GLEW_LIBRARIES} - ${CAIRO_LIBRARIES} - ${PIXMAN_LIBRARY} ${wxWidgets_LIBRARIES} - ${OPENGL_LIBRARIES} ${GDI_PLUS_LIBRARIES} ${PYTHON_LIBRARIES} ${PCBNEW_EXTRA_LIBS} @@ -583,12 +579,8 @@ target_link_libraries( pcbnew_kiface idf3 ${GITHUB_PLUGIN_LIBRARIES} ${wxWidgets_LIBRARIES} - ${OPENGL_LIBRARIES} ${GDI_PLUS_LIBRARIES} ${PYTHON_LIBRARIES} - ${GLEW_LIBRARIES} - ${CAIRO_LIBRARIES} - ${PIXMAN_LIBRARY} ${Boost_LIBRARIES} # must follow GITHUB ${PCBNEW_EXTRA_LIBS} # -lrt must follow Boost ${OPENMP_LIBRARIES} From 06b978b82951c6d52b4e05d2d429ffc400bec3c5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:05 +0200 Subject: [PATCH 12/25] Refactored CONTEXT_MENU, added handler for updating. --- common/tool/context_menu.cpp | 97 ++++++++++++++++++++++----------- common/tool/tool_manager.cpp | 3 + include/tool/context_menu.h | 65 +++++++++++++++++----- pcbnew/router/router_tool.cpp | 6 +- pcbnew/tools/selection_tool.cpp | 4 ++ 5 files changed, 126 insertions(+), 49 deletions(-) diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index 08bada78e7..105450e8a2 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -1,8 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 CERN + * Copyright (C) 2013-2015 CERN * @author Tomasz Wlostowski + * @author Maciej Suminski * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,7 +32,9 @@ #include CONTEXT_MENU::CONTEXT_MENU() : - m_titleSet( false ), m_selected( -1 ), m_tool( NULL ), m_icon( NULL ) + m_titleSet( false ), m_selected( -1 ), m_tool( NULL ), m_parent( NULL ), m_icon( NULL ), + m_menu_handler( CONTEXT_MENU::menuHandlerStub ), + m_update_handler( CONTEXT_MENU::updateHandlerStub ) { setupEvents(); } @@ -44,12 +47,22 @@ CONTEXT_MENU::CONTEXT_MENU( const CONTEXT_MENU& aMenu ) } +CONTEXT_MENU::~CONTEXT_MENU() +{ + // Set parent to NULL to prevent submenus from unregistering from a notexisting object + for( std::list::iterator it = m_submenus.begin(); it != m_submenus.end(); ++it ) + (*it)->m_parent = NULL; + + if( m_parent ) + m_parent->m_submenus.remove( this ); +} + + CONTEXT_MENU& CONTEXT_MENU::operator=( const CONTEXT_MENU& aMenu ) { Clear(); copyFrom( aMenu ); - setupEvents(); return *this; } @@ -84,11 +97,11 @@ void CONTEXT_MENU::SetTitle( const wxString& aTitle ) wxMenuItem* CONTEXT_MENU::Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon ) { #ifdef DEBUG - if( FindItem( aId ) != NULL ) wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in" "undefined behaviour" ) ); #endif + wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL ); if( aIcon ) @@ -139,9 +152,7 @@ std::list CONTEXT_MENU::Add( CONTEXT_MENU* aMenu, const wxString& a if( aExpand ) { - unsigned int i = 0; - - for( i = 0; i < aMenu->GetMenuItemCount(); ++i ) + for( unsigned int i = 0; i < aMenu->GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu->FindItemByPosition( i ); items.push_back( appendCopy( item ) ); @@ -162,8 +173,8 @@ std::list CONTEXT_MENU::Add( CONTEXT_MENU* aMenu, const wxString& a } } - m_toolActions.insert( aMenu->m_toolActions.begin(), aMenu->m_toolActions.end() ); - m_handlers.insert( m_handlers.end(), aMenu->m_handlers.begin(), aMenu->m_handlers.end() ); + m_submenus.push_back( aMenu ); + aMenu->m_parent = this; return items; } @@ -176,13 +187,22 @@ void CONTEXT_MENU::Clear() GetMenuItems().DeleteContents( true ); GetMenuItems().Clear(); m_toolActions.clear(); - m_handlers.clear(); GetMenuItems().DeleteContents( false ); // restore the default so destructor does not go wild + m_submenus.clear(); + m_parent = NULL; assert( GetMenuItemCount() == 0 ); } +void CONTEXT_MENU::UpdateAll() +{ + m_update_handler(); + + runOnSubmenus( boost::bind( &CONTEXT_MENU::UpdateAll, _1 ) ); +} + + void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent ) { OPT_TOOL_EVENT evt; @@ -208,8 +228,10 @@ void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent ) } else { - // Under Linux, every submenu can have a separate event handler, under - // Windows all submenus are handled by the main menu. + runEventHandlers( aEvent, evt ); + + // Under Linux, every submenu can have a separate event handler, under + // Windows all submenus are handled by the main menu. #ifdef __WINDOWS__ if( !evt ) { @@ -224,14 +246,6 @@ void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent ) } } #endif - for( std::list::iterator it = m_handlers.begin(); - it != m_handlers.end(); ++it ) - { - evt = (*it)( aEvent ); - - if( evt ) - break; - } // Handling non-action menu entries (e.g. items in clarification list) if( !evt ) @@ -251,16 +265,22 @@ void CONTEXT_MENU::setTool( TOOL_INTERACTIVE* aTool ) { m_tool = aTool; - for( unsigned i = 0; i < GetMenuItemCount(); ++i ) - { - wxMenuItem* item = FindItemByPosition( i ); + runOnSubmenus( boost::bind( &CONTEXT_MENU::setTool, _1, aTool ) ); +} - if( item->IsSubMenu() ) - { - CONTEXT_MENU* menu = static_cast( item->GetSubMenu() ); - menu->setTool( aTool ); - } - } + +void CONTEXT_MENU::runEventHandlers( const wxMenuEvent& aMenuEvent, OPT_TOOL_EVENT& aToolEvent ) +{ + aToolEvent = m_menu_handler( aMenuEvent ); + + if( !aToolEvent ) + runOnSubmenus( boost::bind( &CONTEXT_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) ); +} + + +void CONTEXT_MENU::runOnSubmenus( boost::function aFunction ) +{ + std::for_each( m_submenus.begin(), m_submenus.end(), aFunction ); } @@ -283,8 +303,8 @@ wxMenuItem* CONTEXT_MENU::appendCopy( const wxMenuItem* aSource ) newItem->SetSubMenu( menu ); Append( newItem ); - m_toolActions.insert( menu->m_toolActions.begin(), menu->m_toolActions.end() ); - m_handlers.insert( m_handlers.end(), menu->m_handlers.begin(), menu->m_handlers.end() ); + m_submenus.push_back( menu ); + menu->m_parent = this; } else { @@ -308,7 +328,9 @@ void CONTEXT_MENU::copyFrom( const CONTEXT_MENU& aMenu ) m_selected = -1; // aMenu.m_selected; m_tool = aMenu.m_tool; m_toolActions = aMenu.m_toolActions; - m_handlers = aMenu.m_handlers; + m_parent = NULL; // aMenu.m_parent; + m_menu_handler = aMenu.m_menu_handler; + m_update_handler = aMenu.m_update_handler; // Copy all the menu entries for( unsigned i = 0; i < aMenu.GetMenuItemCount(); ++i ) @@ -317,3 +339,14 @@ void CONTEXT_MENU::copyFrom( const CONTEXT_MENU& aMenu ) appendCopy( item ); } } + + +OPT_TOOL_EVENT CONTEXT_MENU::menuHandlerStub( const wxMenuEvent& ) +{ + return OPT_TOOL_EVENT(); +} + + +void CONTEXT_MENU::updateHandlerStub() +{ +} diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index cabf2d5302..68b2ad8070 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -596,6 +596,9 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent ) // using the point where the user has invoked a context menu m_viewControls->ForceCursorPosition( true, m_viewControls->GetCursorPosition() ); + // Run update handlers + st->contextMenu->UpdateAll(); + boost::scoped_ptr menu( new CONTEXT_MENU( *st->contextMenu ) ); GetEditFrame()->PopupMenu( menu.get() ); diff --git a/include/tool/context_menu.h b/include/tool/context_menu.h index 5acf177cb0..23a643004d 100644 --- a/include/tool/context_menu.h +++ b/include/tool/context_menu.h @@ -1,8 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 CERN + * Copyright (C) 2013-2015 CERN * @author Tomasz Wlostowski + * @author Maciej Suminski * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -47,9 +48,9 @@ public: ///> Copy constructor CONTEXT_MENU( const CONTEXT_MENU& aMenu ); - CONTEXT_MENU& operator=( const CONTEXT_MENU& aMenu ); + virtual ~CONTEXT_MENU(); - virtual ~CONTEXT_MENU() {} + CONTEXT_MENU& operator=( const CONTEXT_MENU& aMenu ); /** * Function SetTitle() @@ -64,7 +65,7 @@ public: * Assigns an icon for the entry. * @param aIcon is the icon to be assigned. NULL is used to remove icon. */ - void SetIcon( const BITMAP_OPAQUE* aIcon ) + inline void SetIcon( const BITMAP_OPAQUE* aIcon ) { m_icon = aIcon; } @@ -111,21 +112,43 @@ public: * menu was dismissed. * @return The position of selected item in the context menu. */ - int GetSelected() const + inline int GetSelected() const { return m_selected; } - ///> Function type to handle menu events in a custom way. - typedef boost::function CUSTOM_MENU_HANDLER; + /** + * Function UpdateAll() + * Runs update handlers for the menu and its submenus. + */ + void UpdateAll(); - ///> Adds an event handler to the custom menu event handlers chain. - void AppendCustomEventHandler( CUSTOM_MENU_HANDLER aHandler ) + typedef boost::function MENU_HANDLER; + typedef boost::function UPDATE_HANDLER; + + /** + * Function SetMenuHandler() + * Sets the menu event handler to another function. + */ + inline void SetMenuHandler( MENU_HANDLER aMenuHandler ) { - m_handlers.push_back( aHandler ); + m_menu_handler = aMenuHandler; + } + + /** + * Function SetUpdateHandler() + * Sets the update handler to a different function. + */ + inline void SetUpdateHandler( UPDATE_HANDLER aUpdateHandler ) + { + m_update_handler = aUpdateHandler; } private: + // Empty stubs used by the default constructor + static OPT_TOOL_EVENT menuHandlerStub(const wxMenuEvent& ); + static void updateHandlerStub(); + /** * Function appendCopy * Appends a copy of wxMenuItem. @@ -138,7 +161,7 @@ private: ///> Initializes handlers for events. void setupEvents(); - ///> Event handler. + ///> The default menu event handler. void onMenuEvent( wxMenuEvent& aEvent ); /** @@ -148,6 +171,13 @@ private: */ void setTool( TOOL_INTERACTIVE* aTool ); + ///> Traverses the submenus tree looking for a submenu capable of handling a particular menu + ///> event. In case it is handled, it is returned the aToolEvent parameter. + void runEventHandlers( const wxMenuEvent& aMenuEvent, OPT_TOOL_EVENT& aToolEvent ); + + ///> Runs a function on the menu and all its submenus. + void runOnSubmenus( boost::function aFunction ); + ///> Flag indicating that the menu title was set up. bool m_titleSet; @@ -163,12 +193,21 @@ private: ///> Associates tool actions with menu item IDs. Non-owning. std::map m_toolActions; - ///> Chain of custom menu event handlers. - std::list m_handlers; + ///> List of submenus. + std::list m_submenus; + + ///> Parent CONTEXT_MENU. + CONTEXT_MENU* m_parent; ///> Optional icon const BITMAP_OPAQUE* m_icon; + ///> Optional callback to translate wxMenuEvents to TOOL_EVENTs. + MENU_HANDLER m_menu_handler; + + ///> Optional callback to update the menu state before it is displayed. + UPDATE_HANDLER m_update_handler; + friend class TOOL_INTERACTIVE; }; diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 644e6efe5a..f6e1708037 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -96,8 +96,7 @@ public: { m_board = NULL; SetIcon( width_track_via_xpm ); - AppendCustomEventHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::handleCustomEvent, - this, _1 ) ); + SetMenuHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::EventHandler, this, _1 ) ); } void SetBoard( BOARD* aBoard ) @@ -153,8 +152,7 @@ public: } } -protected: - OPT_TOOL_EVENT handleCustomEvent( const wxMenuEvent& aEvent ) + OPT_TOOL_EVENT EventHandler( const wxMenuEvent& aEvent ) { #if ID_POPUP_PCB_SELECT_VIASIZE1 < ID_POPUP_PCB_SELECT_WIDTH1 #error You have changed event ids order, it breaks code. Check the source code for more details. diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index f60bd845fa..2030407283 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -1282,6 +1282,10 @@ bool SELECTION_TOOL::SanitizeSelection() void SELECTION_TOOL::generateMenu() { + // Menu has to be updated before its copy is created. Copying does not preserve subtypes of the + // stored menus, so updating may not work correctly. + m_menu.UpdateAll(); + // Create a copy of the master context menu m_menuCopy = m_menu; From 6379d80636e705b59e1081d97e41f302510ceff7 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:05 +0200 Subject: [PATCH 13/25] Zoom & grid menus for GAL canvases. --- pcbnew/CMakeLists.txt | 3 +++ pcbnew/tools/selection_tool.cpp | 30 ++++++++++++++++++++++++------ pcbnew/tools/selection_tool.h | 5 ++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 5dc358f3a3..0725c08ebc 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -284,6 +284,9 @@ set( PCBNEW_CLASS_SRCS tools/common_actions.cpp tools/grid_helper.cpp tools/tools_common.cpp + + tools/grid_menu.cpp + tools/zoom_menu.cpp ) set( PCBNEW_SRCS ${PCBNEW_AUTOROUTER_SRCS} ${PCBNEW_CLASS_SRCS} ${PCBNEW_DIALOGS} ) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 2030407283..2c0873745b 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -51,6 +51,8 @@ #include "selection_tool.h" #include "selection_area.h" +#include "zoom_menu.h" +#include "grid_menu.h" #include "bright_box.h" #include "common_actions.h" @@ -70,12 +72,6 @@ SELECTION_TOOL::SELECTION_TOOL() : m_frame( NULL ), m_additive( false ), m_multiple( false ), m_editModules( false ), m_locked( true ) { - m_selArea = new SELECTION_AREA; - m_selection.group = new KIGFX::VIEW_GROUP; - - AddSubMenu( new SELECT_MENU, _( "Select..." ), - (SELECTION_CONDITION) SELECTION_CONDITIONS::OnlyConnectedItems && - SELECTION_CONDITIONS::Count( 1 ) ); } @@ -86,6 +82,28 @@ SELECTION_TOOL::~SELECTION_TOOL() } +bool SELECTION_TOOL::Init() +{ + m_selArea = new SELECTION_AREA; + m_selection.group = new KIGFX::VIEW_GROUP; + + AddSubMenu( new SELECT_MENU, _( "Select..." ), + (SELECTION_CONDITION) SELECTION_CONDITIONS::OnlyConnectedItems && + SELECTION_CONDITIONS::Count( 1 ) ); + + AddMenuItem( COMMON_ACTIONS::zoomCenter ); + AddMenuItem( COMMON_ACTIONS::zoomIn ); + AddMenuItem( COMMON_ACTIONS::zoomOut ); + AddMenuItem( COMMON_ACTIONS::zoomFitScreen ); + + AddSubMenu( new ZOOM_MENU( getEditFrame() ), "Zoom" ); + + AddSubMenu( new GRID_MENU( getEditFrame() ), "Grid" ); + + return true; +} + + void SELECTION_TOOL::Reset( RESET_REASON aReason ) { if( aReason == TOOL_BASE::MODEL_RELOAD ) diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index bc726ed8b1..b74d6220f7 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -104,7 +104,10 @@ public: SELECTION_TOOL(); ~SELECTION_TOOL(); - /// @copydoc TOOL_INTERACTIVE::Reset() + /// @copydoc TOOL_BASE::Init() + bool Init(); + + /// @copydoc TOOL_BASE::Reset() void Reset( RESET_REASON aReason ); /** From 3e46f2233a65ae48501e2b21838bd61006adf436 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:06 +0200 Subject: [PATCH 14/25] Corrected "Zoom Auto" in GAL with empty board. --- pcbnew/tools/pcbnew_control.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 90be91582a..c34d834780 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -100,18 +100,17 @@ int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent ) BOARD* board = getModel(); board->ComputeBoundingBox(); BOX2I boardBBox = board->ViewBBox(); + VECTOR2I screenSize = gal->GetScreenPixelSize(); if( boardBBox.GetSize().x == 0 || boardBBox.GetSize().y == 0 ) { // Empty view - view->SetScale( 100000.0 ); - view->SetCenter( VECTOR2D( 0, 0 ) ); + view->SetCenter( view->ToWorld( VECTOR2D( screenSize.x / 2, screenSize.y / 2 ) ) ); + view->SetScale( 17.0 ); } else { // Autozoom to board - VECTOR2I screenSize = gal->GetScreenPixelSize(); - double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0; double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0; @@ -119,8 +118,8 @@ int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent ) double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoom = 1.0 / ( zoomFactor * bestZoom ); - view->SetScale( zoom ); view->SetCenter( boardBBox.Centre() ); + view->SetScale( zoom ); } return 0; From 787415c2aa9c8fd9b9416d1bc10703f9ca79477f Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:06 +0200 Subject: [PATCH 15/25] Updating the user grid size on change in GAL. --- pcbnew/dialogs/dialog_set_grid.cpp | 14 ++++++++------ pcbnew/tools/pcbnew_control.cpp | 7 ++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pcbnew/dialogs/dialog_set_grid.cpp b/pcbnew/dialogs/dialog_set_grid.cpp index ad0323476a..a4e575e921 100644 --- a/pcbnew/dialogs/dialog_set_grid.cpp +++ b/pcbnew/dialogs/dialog_set_grid.cpp @@ -34,8 +34,10 @@ #include #include #include + #include #include +#include class DIALOG_SET_GRID : public DIALOG_SET_GRID_BASE @@ -227,12 +229,12 @@ bool PCB_BASE_FRAME::InvokeDialogGrid() if( screen->GetGridId() == ID_POPUP_GRID_USER ) screen->SetGrid( ID_POPUP_GRID_USER ); - if( IsGalCanvasActive() ) - { - GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size.x, - screen->GetGrid().m_Size.y ) ); - GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); - } + // Notify GAL + TOOL_MANAGER* mgr = GetToolManager(); + + if( mgr && IsGalCanvasActive() ) + mgr->RunAction( "common.Control.gridPreset", true, + ID_POPUP_GRID_USER - ID_POPUP_GRID_LEVEL_1000 ); m_canvas->Refresh(); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index c34d834780..99da5fa518 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -135,10 +135,15 @@ int PCBNEW_CONTROL::ZoomPreset( const TOOL_EVENT& aEvent ) m_frame->SetPresetZoom( idx ); - if( idx == 0 ) + if( idx == 0 ) // Zoom Auto + { return ZoomFitScreen( aEvent ); + } else if( idx < 0 || idx >= zoomList.size() ) + { + assert( false ); return 0; + } double selectedZoom = zoomList[idx]; double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); From f2788a3086b5c1a514f364a01047418486ca4d7b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:06 +0200 Subject: [PATCH 16/25] Corrected way of storing cursor coordinates for context --- common/tool/tool_manager.cpp | 4 +++- include/view/view_controls.h | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 68b2ad8070..6314e8eac0 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -594,6 +594,8 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent ) // Temporarily store the cursor position, so the tools could execute actions // using the point where the user has invoked a context menu + bool forcedCursor = m_viewControls->IsCursorPositionForced(); + VECTOR2D cursorPos = m_viewControls->GetCursorPosition(); m_viewControls->ForceCursorPosition( true, m_viewControls->GetCursorPosition() ); // Run update handlers @@ -609,7 +611,7 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent ) dispatchInternal( evt ); } - m_viewControls->ForceCursorPosition( false ); + m_viewControls->ForceCursorPosition( forcedCursor, cursorPos ); break; } diff --git a/include/view/view_controls.h b/include/view/view_controls.h index fddf6ad68f..7f8aef9cb2 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -152,7 +152,6 @@ public: */ virtual VECTOR2D GetCursorPosition() const = 0; - /** * Function ForceCursorPosition() * Places the cursor immediately at a given point. Mouse movement is ignored. @@ -182,6 +181,11 @@ public: m_cursorCaptured = aEnabled; } + inline bool IsCursorPositionForced() const + { + return m_forceCursorPosition; + } + protected: /// Sets center for VIEW, takes into account panning boundaries. void setCenter( const VECTOR2D& aCenter ); From d18ed945c9456ed7ee006d035515548327c55260 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:06 +0200 Subject: [PATCH 17/25] Do not run OpenMP loops when there is no data to --- pcbnew/ratsnest_data.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index 7349e6264f..3086feb12d 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -1182,9 +1182,10 @@ void RN_DATA::Recalculate( int aNet ) if( netCount > m_nets.size() ) m_nets.resize( netCount ); - if( aNet < 0 ) // Recompute everything + if( aNet < 0 && netCount > 1 ) // Recompute everything { unsigned int i; + #ifdef USE_OPENMP #pragma omp parallel shared(netCount) private(i) { From b218c1099f90325d9f8de93e25ac9840efe4edb6 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:07 +0200 Subject: [PATCH 18/25] Added TA_CONTEXT_MENU_CLOSED tool event. --- common/tool/tool_manager.cpp | 3 +++ include/tool/tool_event.h | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 6314e8eac0..e828259877 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -611,6 +611,9 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent ) dispatchInternal( evt ); } + TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CLOSED ); + dispatchInternal( evt ); + m_viewControls->ForceCursorPosition( forcedCursor, cursorPos ); break; diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index d7ead512ba..61015a69a5 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -88,14 +88,19 @@ enum TOOL_ACTIONS // closed it without selecting anything. TA_CONTEXT_MENU_CHOICE = 0x8000, + // Context menu is closed, no matter whether anything has been chosen or not. + TA_CONTEXT_MENU_CLOSED = 0x10000, + + TA_CONTEXT_MENU = TA_CONTEXT_MENU_UPDATE | TA_CONTEXT_MENU_CHOICE | TA_CONTEXT_MENU_CLOSED, + // This event is sent *before* undo/redo command is performed. - TA_UNDO_REDO = 0x10000, + TA_UNDO_REDO = 0x20000, // Tool action (allows to control tools). - TA_ACTION = 0x20000, + TA_ACTION = 0x40000, // Tool activation event. - TA_ACTIVATE = 0x40000, + TA_ACTIVATE = 0x80000, TA_ANY = 0xffffffff }; From e37b07a6fc5336bed42faf96de66c60221d4f0ef Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:07 +0200 Subject: [PATCH 19/25] Explicit destruction of menu entries in CONTEXT_MENU. --- common/tool/context_menu.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index 105450e8a2..9658f7dd5b 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -152,7 +152,7 @@ std::list CONTEXT_MENU::Add( CONTEXT_MENU* aMenu, const wxString& a if( aExpand ) { - for( unsigned int i = 0; i < aMenu->GetMenuItemCount(); ++i ) + for( int i = 0; i < (int) aMenu->GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu->FindItemByPosition( i ); items.push_back( appendCopy( item ) ); @@ -184,10 +184,10 @@ void CONTEXT_MENU::Clear() { m_titleSet = false; - GetMenuItems().DeleteContents( true ); - GetMenuItems().Clear(); + for( int i = GetMenuItemCount() - 1; i >= 0; --i ) + Destroy( FindItemByPosition( i ) ); + m_toolActions.clear(); - GetMenuItems().DeleteContents( false ); // restore the default so destructor does not go wild m_submenus.clear(); m_parent = NULL; @@ -333,7 +333,7 @@ void CONTEXT_MENU::copyFrom( const CONTEXT_MENU& aMenu ) m_update_handler = aMenu.m_update_handler; // Copy all the menu entries - for( unsigned i = 0; i < aMenu.GetMenuItemCount(); ++i ) + for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i ) { wxMenuItem* item = aMenu.FindItemByPosition( i ); appendCopy( item ); From b8295b6af843983a3f6ad3b3e2afb0e16ccdd4d9 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:07 +0200 Subject: [PATCH 20/25] Code formatting. --- pcbnew/tools/edit_tool.cpp | 4 ++-- pcbnew/tools/selection_tool.cpp | 5 ++++- pcbnew/tools/selection_tool.h | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 6a4326f473..8057920fc6 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -90,8 +90,8 @@ bool EDIT_TOOL::Init() // Footprint actions m_selectionTool->AddMenuItem( COMMON_ACTIONS::editFootprintInFpEditor, - SELECTION_CONDITIONS::OnlyType ( PCB_MODULE_T ) && - SELECTION_CONDITIONS::Count ( 1 ) ); + SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) && + SELECTION_CONDITIONS::Count( 1 ) ); m_offset.x = 0; m_offset.y = 0; diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 2c0873745b..3f3039cba4 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -352,7 +352,7 @@ bool SELECTION_TOOL::selectCursor( const VECTOR2I& aWhere, bool aOnDrag ) else if( collector.GetCount() > 1 ) { if( aOnDrag ) - Wait ( TOOL_EVENT( TC_ANY, TA_MOUSE_UP, BUT_LEFT ) ); + Wait( TOOL_EVENT( TC_ANY, TA_MOUSE_UP, BUT_LEFT ) ); item = disambiguationMenu( &collector ); @@ -507,6 +507,7 @@ SELECTION_LOCK_FLAGS SELECTION_TOOL::CheckLock() return SELECTION_UNLOCKED; } + int SELECTION_TOOL::CursorSelection( const TOOL_EVENT& aEvent ) { selectCursor( getView()->ToWorld( getViewControls()->GetMousePosition() ) ); @@ -522,6 +523,7 @@ int SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent ) return 0; } + int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent ) { // Check if there is an item to be selected @@ -538,6 +540,7 @@ int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent ) return 0; } + int SELECTION_TOOL::UnselectItem( const TOOL_EVENT& aEvent ) { // Check if there is an item to be selected diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index b74d6220f7..fffa8790ac 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -171,8 +171,8 @@ public: ///> Clear current selection event handler. int ClearSelection( const TOOL_EVENT& aEvent ); - ///> Makes sure a group selection does not contain items that would cause - ///> conflicts when moving/rotating together (e.g. a footprint and one of the same footprint's pads) + ///> Makes sure a group selection does not contain items that would cause + ///> conflicts when moving/rotating together (e.g. a footprint and one of the same footprint's pads) bool SanitizeSelection(); ///> Item selection event handler. From 9ef9b7b8e1a5bddd50f0a21b765d32075874548d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:07 +0200 Subject: [PATCH 21/25] Preliminary selection mode for SELECTION_TOOL. --- pcbnew/tools/selection_tool.cpp | 17 +++++++++++++++-- pcbnew/tools/selection_tool.h | 7 ++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 3f3039cba4..e3e9d10758 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -111,7 +111,6 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason ) // Remove pointers to the selected items from containers // without changing their properties (as they are already deleted // while a new board is loaded) - m_selection.group->Clear(); m_selection.clear(); } else @@ -120,6 +119,7 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason ) m_frame = getEditFrame(); m_locked = true; + m_preliminary = true; // Reinsert the VIEW_GROUP, in case it was removed from the VIEW getView()->Remove( m_selection.group ); @@ -155,10 +155,13 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) // right click? if there is any object - show the context menu else if( evt->IsClick( BUT_RIGHT ) ) { - if( m_selection.Empty() ) + bool emptySelection = m_selection.Empty(); + + if( emptySelection ) selectCursor( evt->Position() ); generateMenu(); + m_preliminary = emptySelection; } // double click? Display the properties window @@ -175,10 +178,14 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { if( m_additive ) { + m_preliminary = false; + selectMultiple(); } else if( m_selection.Empty() ) { + m_preliminary = false; + // There is nothing selected, so try to select something if( !selectCursor( getView()->ToWorld( getViewControls()->GetMousePosition() ), false ) ) { @@ -249,6 +256,12 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { selectNet( *evt ); } + + else if( evt->Action() == TA_CONTEXT_MENU_CLOSED ) + { + if( m_preliminary ) + clearSelection(); + } } // This tool is supposed to be active forever diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index fffa8790ac..fce960470d 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -122,8 +122,10 @@ public: * * Returns the set of currently selected items. */ - const SELECTION& GetSelection() const + const SELECTION& GetSelection() { + // The selected items list has been requested, so it is no longer preliminary + m_preliminary = false; return m_selection; } @@ -356,6 +358,9 @@ private: /// Can other tools modify locked items. bool m_locked; + /// Determines if the selection is preliminary or final. + bool m_preliminary; + /// Conditions for specific context menu entries. std::deque m_menuConditions; }; From 958046ddb283967be336f1478b9fde011252fc4c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:08 +0200 Subject: [PATCH 22/25] Moved SELECTION_TOOL context menu to a separate class. --- pcbnew/CMakeLists.txt | 1 + pcbnew/tools/edit_tool.cpp | 22 +++---- pcbnew/tools/module_tools.cpp | 2 +- pcbnew/tools/pcb_editor_control.cpp | 4 +- pcbnew/tools/placement_tool.cpp | 3 +- pcbnew/tools/point_editor.cpp | 4 +- pcbnew/tools/selection_tool.cpp | 97 +++++++---------------------- pcbnew/tools/selection_tool.h | 53 +++------------- 8 files changed, 51 insertions(+), 135 deletions(-) diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 0725c08ebc..968038649c 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -271,6 +271,7 @@ set( PCBNEW_CLASS_SRCS tools/selection_tool.cpp tools/selection_area.cpp tools/selection_conditions.cpp + tools/conditional_menu.cpp tools/bright_box.cpp tools/edit_points.cpp tools/edit_constraints.cpp diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 8057920fc6..bbce5510ad 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -79,19 +79,19 @@ bool EDIT_TOOL::Init() } // Add context menu entries that are displayed when selection tool is active - m_selectionTool->AddMenuItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty ); - m_selectionTool->AddMenuItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty ); - m_selectionTool->AddMenuItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty ); - m_selectionTool->AddMenuItem( COMMON_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty ); - m_selectionTool->AddMenuItem( COMMON_ACTIONS::properties, SELECTION_CONDITIONS::NotEmpty ); - m_selectionTool->AddMenuItem( COMMON_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty ); - m_selectionTool->AddMenuItem( COMMON_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty ); - m_selectionTool->AddMenuItem( COMMON_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty ); + m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty ); + m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty ); + m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty ); + m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty ); + m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::properties, SELECTION_CONDITIONS::NotEmpty ); + m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty ); + m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty ); + m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty ); // Footprint actions - m_selectionTool->AddMenuItem( COMMON_ACTIONS::editFootprintInFpEditor, - SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) && - SELECTION_CONDITIONS::Count( 1 ) ); + m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::editFootprintInFpEditor, + SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) && + SELECTION_CONDITIONS::Count( 1 ) ); m_offset.x = 0; m_offset.y = 0; diff --git a/pcbnew/tools/module_tools.cpp b/pcbnew/tools/module_tools.cpp index 658e5d1ad0..ece3429d8b 100644 --- a/pcbnew/tools/module_tools.cpp +++ b/pcbnew/tools/module_tools.cpp @@ -74,7 +74,7 @@ bool MODULE_TOOLS::Init() return false; } - selectionTool->AddMenuItem( COMMON_ACTIONS::enumeratePads ); + selectionTool->GetMenu().AddItem( COMMON_ACTIONS::enumeratePads ); return true; } diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 8577f1a8ea..cdf4042f3f 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -74,8 +74,8 @@ bool PCB_EDITOR_CONTROL::Init() if( selTool ) { - selTool->AddSubMenu( new ZONE_CONTEXT_MENU, _( "Zones" ), - SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) ); + selTool->GetMenu().AddMenu( new ZONE_CONTEXT_MENU, _( "Zones" ), + SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) ); } return true; diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index 555f37611f..79a42d78ef 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -63,8 +63,7 @@ bool PLACEMENT_TOOL::Init() menu->AppendSeparator(); menu->Add( COMMON_ACTIONS::distributeHorizontally ); menu->Add( COMMON_ACTIONS::distributeVertically ); - m_selectionTool->AddSubMenu( menu, _( "Align/distribute" ), - SELECTION_CONDITIONS::MoreThan( 1 ) ); + m_selectionTool->GetMenu().AddMenu( menu, _( "Align/distribute" ), SELECTION_CONDITIONS::MoreThan( 1 ) ); return true; } diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index ebe888e794..35bea0fdcc 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -210,8 +210,8 @@ bool POINT_EDITOR::Init() return false; } - m_selectionTool->AddMenuItem( COMMON_ACTIONS::pointEditorBreakOutline, - POINT_EDITOR::breakOutlineCondition ); + m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::pointEditorBreakOutline, + POINT_EDITOR::breakOutlineCondition ); return true; } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index e3e9d10758..15ff1e7299 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -77,28 +77,27 @@ SELECTION_TOOL::SELECTION_TOOL() : SELECTION_TOOL::~SELECTION_TOOL() { - delete m_selArea; delete m_selection.group; } bool SELECTION_TOOL::Init() { - m_selArea = new SELECTION_AREA; m_selection.group = new KIGFX::VIEW_GROUP; - AddSubMenu( new SELECT_MENU, _( "Select..." ), + m_menu.AddMenu( new SELECT_MENU, _( "Select..." ), (SELECTION_CONDITION) SELECTION_CONDITIONS::OnlyConnectedItems && SELECTION_CONDITIONS::Count( 1 ) ); - AddMenuItem( COMMON_ACTIONS::zoomCenter ); - AddMenuItem( COMMON_ACTIONS::zoomIn ); - AddMenuItem( COMMON_ACTIONS::zoomOut ); - AddMenuItem( COMMON_ACTIONS::zoomFitScreen ); + m_menu.AddItem( COMMON_ACTIONS::zoomCenter ); + m_menu.AddItem( COMMON_ACTIONS::zoomIn ); + m_menu.AddItem( COMMON_ACTIONS::zoomOut ); + m_menu.AddItem( COMMON_ACTIONS::zoomFitScreen ); - AddSubMenu( new ZOOM_MENU( getEditFrame() ), "Zoom" ); + m_menu.AddMenu( new ZOOM_MENU( getEditFrame() ), "Zoom" ); + m_menu.AddMenu( new GRID_MENU( getEditFrame() ), "Grid" ); - AddSubMenu( new GRID_MENU( getEditFrame() ), "Grid" ); + //m_menu.AddSeparator(); return true; } @@ -160,7 +159,11 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) if( emptySelection ) selectCursor( evt->Position() ); - generateMenu(); + CONTEXT_MENU& contextMenu = m_menu.Generate( m_selection ); + + if( contextMenu.GetMenuItemCount() > 0 ) + SetContextMenu( &contextMenu, CMENU_NOW ); + m_preliminary = emptySelection; } @@ -271,25 +274,6 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) } -void SELECTION_TOOL::AddMenuItem( const TOOL_ACTION& aAction, const SELECTION_CONDITION& aCondition ) -{ - assert( aAction.GetId() > 0 ); // Check if action was previously registered in ACTION_MANAGER - - m_menu.Add( aAction ); - m_menuConditions.push_back( aCondition ); -} - - -void SELECTION_TOOL::AddSubMenu( CONTEXT_MENU* aMenu, const wxString& aLabel, - const SELECTION_CONDITION& aCondition, bool aExpand ) -{ - std::list items = m_menu.Add( aMenu, aLabel, aExpand ); - - for( unsigned int i = 0; i < items.size(); ++i ) - m_menuConditions.push_back( aCondition ); -} - - void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem ) { if( aItem->IsSelected() ) @@ -390,7 +374,8 @@ bool SELECTION_TOOL::selectMultiple() KIGFX::VIEW* view = getView(); getViewControls()->SetAutoPan( true ); - view->Add( m_selArea ); + SELECTION_AREA area; + view->Add( &area ); while( OPT_TOOL_EVENT evt = Wait() ) { @@ -406,20 +391,20 @@ bool SELECTION_TOOL::selectMultiple() clearSelection(); // Start drawing a selection box - m_selArea->SetOrigin( evt->DragOrigin() ); - m_selArea->SetEnd( evt->Position() ); - m_selArea->ViewSetVisible( true ); - m_selArea->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + area.SetOrigin( evt->DragOrigin() ); + area.SetEnd( evt->Position() ); + area.ViewSetVisible( true ); + area.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } if( evt->IsMouseUp( BUT_LEFT ) ) { // End drawing the selection box - m_selArea->ViewSetVisible( false ); + area.ViewSetVisible( false ); // Mark items within the selection box as selected std::vector selectedItems; - BOX2I selectionBox = m_selArea->ViewBBox(); + BOX2I selectionBox = area.ViewBBox(); view->Query( selectionBox, selectedItems ); // Get the list of selected items std::vector::iterator it, it_end; @@ -450,8 +435,8 @@ bool SELECTION_TOOL::selectMultiple() } // Stop drawing the selection box - m_selArea->ViewSetVisible( false ); - view->Remove( m_selArea ); + area.ViewSetVisible( false ); + view->Remove( &area ); m_multiple = false; // Multiple selection mode is inactive getViewControls()->SetAutoPan( false ); @@ -1314,42 +1299,6 @@ bool SELECTION_TOOL::SanitizeSelection() } -void SELECTION_TOOL::generateMenu() -{ - // Menu has to be updated before its copy is created. Copying does not preserve subtypes of the - // stored menus, so updating may not work correctly. - m_menu.UpdateAll(); - - // Create a copy of the master context menu - m_menuCopy = m_menu; - - assert( m_menuCopy.GetMenuItemCount() == m_menuConditions.size() ); - - // Filter out entries that do not comply with the current selection - for( int i = m_menuCopy.GetMenuItemCount() - 1; i >= 0; --i ) - { - try - { - if( !m_menuConditions[i]( m_selection ) ) - { - wxMenuItem* item = m_menuCopy.FindItemByPosition( i ); - m_menuCopy.Destroy( item ); - } - } - catch( boost::bad_function_call ) - { - // If it is not possible to determine if a menu entry should be - // shown or not - do not let users pick non-existing options - wxMenuItem* item = m_menuCopy.FindItemByPosition( i ); - m_menuCopy.Destroy( item ); - } - } - - if( m_menuCopy.GetMenuItemCount() > 0 ) - SetContextMenu( &m_menuCopy, CMENU_NOW ); -} - - void SELECTION::clear() { items.ClearItemsList(); diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index fce960470d..57cf0100af 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -32,6 +32,7 @@ #include #include "selection_conditions.h" +#include "conditional_menu.h" class PCB_BASE_FRAME; class SELECTION_AREA; @@ -122,36 +123,13 @@ public: * * Returns the set of currently selected items. */ - const SELECTION& GetSelection() + inline const SELECTION& GetSelection() { // The selected items list has been requested, so it is no longer preliminary m_preliminary = false; return m_selection; } - /** - * Function AddMenuItem() - * - * Adds a menu entry to run a TOOL_ACTION on selected items. - * @param aAction is a menu entry to be added. - * @param aCondition is a condition that has to be fulfilled to enable the menu entry. - */ - void AddMenuItem( const TOOL_ACTION& aAction, - const SELECTION_CONDITION& aCondition = SELECTION_CONDITIONS::ShowAlways ); - - /** - * Function AddSubMenu() - * - * Adds a submenu to the selection tool right-click context menu. - * @param aMenu is the submenu to be added. - * @param aLabel is the label of added submenu. - * @param aCondition is a condition that has to be fulfilled to enable the submenu entry. - * @param aExpand determines if the added submenu items should be added as individual items. - */ - void AddSubMenu( CONTEXT_MENU* aMenu, const wxString& aLabel, - const SELECTION_CONDITION& aCondition = SELECTION_CONDITIONS::ShowAlways, - bool aExpand = false ); - /** * Function EditModules() * @@ -159,11 +137,16 @@ public: * (graphics, pads, etc.), so they can be modified. * @param aEnabled decides if the mode should be enabled. */ - void EditModules( bool aEnabled ) + inline void EditModules( bool aEnabled ) { m_editModules = aEnabled; } + inline CONDITIONAL_MENU& GetMenu() + { + return m_menu; + } + ///> Checks if the user has agreed to modify locked items for the given selection. SELECTION_LOCK_FLAGS CheckLock(); @@ -324,19 +307,9 @@ private: */ void guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) const; - /** - * Function generateMenu() - * Creates a copy of context menu that is filtered by menu conditions and displayed to - * the user. - */ - void generateMenu(); - /// Pointer to the parent frame. PCB_BASE_FRAME* m_frame; - /// Visual representation of selection box. - SELECTION_AREA* m_selArea; - /// Current state of selection. SELECTION m_selection; @@ -346,12 +319,6 @@ private: /// Flag saying if multiple selection mode is active. bool m_multiple; - /// Right click popup menu (master instance). - CONTEXT_MENU m_menu; - - /// Copy of the context menu that is filtered by menu conditions and displayed to the user. - CONTEXT_MENU m_menuCopy; - /// Edit module mode flag. bool m_editModules; @@ -361,8 +328,8 @@ private: /// Determines if the selection is preliminary or final. bool m_preliminary; - /// Conditions for specific context menu entries. - std::deque m_menuConditions; + /// Menu displayed by the tool. + CONDITIONAL_MENU m_menu; }; #endif From 872259981a299700a82ef7936082039f2d736247 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:08 +0200 Subject: [PATCH 23/25] CONDITIONAL_MENU supports separators and ordering. --- pcbnew/tools/pcb_editor_control.cpp | 2 +- pcbnew/tools/placement_tool.cpp | 3 ++- pcbnew/tools/selection_tool.cpp | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index cdf4042f3f..84b0833b58 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -74,7 +74,7 @@ bool PCB_EDITOR_CONTROL::Init() if( selTool ) { - selTool->GetMenu().AddMenu( new ZONE_CONTEXT_MENU, _( "Zones" ), + selTool->GetMenu().AddMenu( new ZONE_CONTEXT_MENU, _( "Zones" ), false, SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) ); } diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index 79a42d78ef..435e4d352e 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -63,7 +63,8 @@ bool PLACEMENT_TOOL::Init() menu->AppendSeparator(); menu->Add( COMMON_ACTIONS::distributeHorizontally ); menu->Add( COMMON_ACTIONS::distributeVertically ); - m_selectionTool->GetMenu().AddMenu( menu, _( "Align/distribute" ), SELECTION_CONDITIONS::MoreThan( 1 ) ); + m_selectionTool->GetMenu().AddMenu( menu, _( "Align/distribute" ), false, + SELECTION_CONDITIONS::MoreThan( 1 ) ); return true; } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 15ff1e7299..51c3c43df6 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -85,19 +85,21 @@ bool SELECTION_TOOL::Init() { m_selection.group = new KIGFX::VIEW_GROUP; - m_menu.AddMenu( new SELECT_MENU, _( "Select..." ), + m_menu.AddMenu( new SELECT_MENU, _( "Select..." ), false, (SELECTION_CONDITION) SELECTION_CONDITIONS::OnlyConnectedItems && SELECTION_CONDITIONS::Count( 1 ) ); - m_menu.AddItem( COMMON_ACTIONS::zoomCenter ); - m_menu.AddItem( COMMON_ACTIONS::zoomIn ); - m_menu.AddItem( COMMON_ACTIONS::zoomOut ); - m_menu.AddItem( COMMON_ACTIONS::zoomFitScreen ); + m_menu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 ); - m_menu.AddMenu( new ZOOM_MENU( getEditFrame() ), "Zoom" ); - m_menu.AddMenu( new GRID_MENU( getEditFrame() ), "Grid" ); + m_menu.AddItem( COMMON_ACTIONS::zoomCenter, SELECTION_CONDITIONS::ShowAlways, 1000 ); + m_menu.AddItem( COMMON_ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways, 1000 ); + m_menu.AddItem( COMMON_ACTIONS::zoomOut , SELECTION_CONDITIONS::ShowAlways, 1000 ); + m_menu.AddItem( COMMON_ACTIONS::zoomFitScreen , SELECTION_CONDITIONS::ShowAlways, 1000 ); - //m_menu.AddSeparator(); + m_menu.AddMenu( new ZOOM_MENU( getEditFrame() ), "Zoom", + false, SELECTION_CONDITIONS::ShowAlways, 1000 ); + m_menu.AddMenu( new GRID_MENU( getEditFrame() ), "Grid", + false, SELECTION_CONDITIONS::ShowAlways, 1000 ); return true; } From 47582e274122c7890721873bfe70dca3a5604764 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:08 +0200 Subject: [PATCH 24/25] GAL autozooms on every EDA_DRAW_FRAME::Zoom_Automatique --- common/zoom.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/zoom.cpp b/common/zoom.cpp index ef04c78dfc..8d4ae6740f 100644 --- a/common/zoom.cpp +++ b/common/zoom.cpp @@ -40,6 +40,7 @@ #include #include #include +#include void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer ) @@ -90,6 +91,8 @@ void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer ) if( !IsGalCanvasActive() ) RedrawScreen( GetScrollCenterPosition(), aWarpPointer ); + else + m_toolManager->RunAction( "common.Control.zoomFitScreen", true ); } From 8390fec69d67be6efd51a533a547a899a318e288 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 30 Apr 2015 10:46:08 +0200 Subject: [PATCH 25/25] Minor fixes. --- common/tool/tool_manager.cpp | 2 ++ include/tool/tool_manager.h | 2 +- include/view/view_item.h | 11 ++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index e828259877..f12ceb8ff6 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -316,6 +316,8 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a return true; } + wxASSERT_MSG( action != NULL, wxString::Format( _( "Could not find action %s." ), aActionName ) ); + return false; } diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 4c60bfa9d6..aeb19823d0 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -116,7 +116,7 @@ public: return RunAction( aActionName, aNow, reinterpret_cast( aParam ) ); } - bool RunAction( const std::string& aActionName, bool aNow, void* aParam = NULL ); + bool RunAction( const std::string& aActionName, bool aNow, void* aParam ); bool RunAction( const std::string& aActionName, bool aNow = false ) { diff --git a/include/view/view_item.h b/include/view/view_item.h index 86c8473cc4..5846d199b5 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -203,10 +203,15 @@ public: */ virtual void ViewUpdate( int aUpdateFlags = ALL ) { - if( m_view && m_requiredUpdate == NONE ) - m_view->MarkForUpdate( this ); + if( m_view ) + { + assert( aUpdateFlags != NONE ); - m_requiredUpdate |= aUpdateFlags; + if( m_requiredUpdate == NONE ) + m_view->MarkForUpdate( this ); + + m_requiredUpdate |= aUpdateFlags; + } } /**