diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index f8253fb31f..3bb9580e90 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -262,6 +262,7 @@ set( PCBNEW_CLASS_SRCS tools/drawing_tool.cpp tools/edit_tool.cpp tools/pcbnew_control.cpp + tools/pcb_editor_control.cpp tools/pcb_tools.cpp tools/common_actions.cpp ) diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp new file mode 100644 index 0000000000..a1b46c8a46 --- /dev/null +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -0,0 +1,144 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2014 CERN + * @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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "pcb_editor_control.h" +#include "common_actions.h" + +#include +#include +#include + +PCB_EDITOR_CONTROL::PCB_EDITOR_CONTROL() : + TOOL_INTERACTIVE( "pcbnew.EditorControl" ) +{ +} + + +void PCB_EDITOR_CONTROL::Reset( RESET_REASON aReason ) +{ + m_frame = getEditFrame(); +} + + +bool PCB_EDITOR_CONTROL::Init() +{ + setTransitions(); + + return true; +} + + +// Track & via size control +int PCB_EDITOR_CONTROL::TrackWidthInc( TOOL_EVENT& aEvent ) +{ + BOARD* board = getModel(); + int widthIndex = board->GetDesignSettings().GetTrackWidthIndex() + 1; + + if( widthIndex >= (int) board->GetDesignSettings().m_TrackWidthList.size() ) + widthIndex = board->GetDesignSettings().m_TrackWidthList.size() - 1; + + board->GetDesignSettings().SetTrackWidthIndex( widthIndex ); + board->GetDesignSettings().UseCustomTrackViaSize( false ); + + wxUpdateUIEvent dummy; + m_frame->OnUpdateSelectTrackWidth( dummy ); + setTransitions(); + + m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); + + return 0; +} + + +int PCB_EDITOR_CONTROL::TrackWidthDec( TOOL_EVENT& aEvent ) +{ + BOARD* board = getModel(); + int widthIndex = board->GetDesignSettings().GetTrackWidthIndex() - 1; + + if( widthIndex < 0 ) + widthIndex = 0; + + board->GetDesignSettings().SetTrackWidthIndex( widthIndex ); + board->GetDesignSettings().UseCustomTrackViaSize( false ); + + wxUpdateUIEvent dummy; + m_frame->OnUpdateSelectTrackWidth( dummy ); + setTransitions(); + + m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); + + return 0; +} + + +int PCB_EDITOR_CONTROL::ViaSizeInc( TOOL_EVENT& aEvent ) +{ + BOARD* board = getModel(); + int sizeIndex = board->GetDesignSettings().GetViaSizeIndex() + 1; + + if( sizeIndex >= (int) board->GetDesignSettings().m_ViasDimensionsList.size() ) + sizeIndex = board->GetDesignSettings().m_ViasDimensionsList.size() - 1; + + board->GetDesignSettings().SetViaSizeIndex( sizeIndex ); + board->GetDesignSettings().UseCustomTrackViaSize( false ); + + wxUpdateUIEvent dummy; + m_frame->OnUpdateSelectViaSize( dummy ); + setTransitions(); + + m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); + + return 0; +} + + +int PCB_EDITOR_CONTROL::ViaSizeDec( TOOL_EVENT& aEvent ) +{ + BOARD* board = getModel(); + int sizeIndex = board->GetDesignSettings().GetViaSizeIndex() - 1; + + if( sizeIndex < 0 ) + sizeIndex = 0; + + board->GetDesignSettings().SetViaSizeIndex( sizeIndex ); + board->GetDesignSettings().UseCustomTrackViaSize( false ); + + wxUpdateUIEvent dummy; + m_frame->OnUpdateSelectViaSize( dummy ); + setTransitions(); + + m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); + + return 0; +} + + +void PCB_EDITOR_CONTROL::setTransitions() +{ + // Track & via size control + Go( &PCB_EDITOR_CONTROL::TrackWidthInc, COMMON_ACTIONS::trackWidthInc.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::TrackWidthDec, COMMON_ACTIONS::trackWidthDec.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::ViaSizeInc, COMMON_ACTIONS::viaSizeInc.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::ViaSizeDec, COMMON_ACTIONS::viaSizeDec.MakeEvent() ); +} diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h new file mode 100644 index 0000000000..50b9a6c691 --- /dev/null +++ b/pcbnew/tools/pcb_editor_control.h @@ -0,0 +1,62 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2014 CERN + * @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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef PCB_EDITOR_CONTROL_H +#define PCB_EDITOR_CONTROL_H + +#include + +class PCB_EDIT_FRAME; + +/** + * Class PCBNEW_CONTROL + * + * Handles hot keys that are not accepted by any other tool. + */ +class PCB_EDITOR_CONTROL : public TOOL_INTERACTIVE +{ +public: + PCB_EDITOR_CONTROL(); + + /// @copydoc TOOL_INTERACTIVE::Reset() + void Reset( RESET_REASON aReason ); + + /// @copydoc TOOL_INTERACTIVE::Init() + bool Init(); + + // Track & via size control + int TrackWidthInc( TOOL_EVENT& aEvent ); + int TrackWidthDec( TOOL_EVENT& aEvent ); + int ViaSizeInc( TOOL_EVENT& aEvent ); + int ViaSizeDec( TOOL_EVENT& aEvent ); + +private: + ///> Sets up handlers for various events. + void setTransitions(); + + ///> Pointerto the currently used edit frame. + PCB_EDIT_FRAME* m_frame; +}; + +#endif diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index ee8af05595..6ba1a787e8 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -35,6 +35,7 @@ #include "drawing_tool.h" #include "point_editor.h" #include "pcbnew_control.h" +#include "pcb_editor_control.h" #include "common_actions.h" #include @@ -53,6 +54,7 @@ void PCB_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new DRAWING_TOOL ); m_toolManager->RegisterTool( new POINT_EDITOR ); m_toolManager->RegisterTool( new PCBNEW_CONTROL ); + m_toolManager->RegisterTool( new PCB_EDITOR_CONTROL ); m_toolManager->ResetTools( TOOL_BASE::RUN ); // Run the selection tool, it is supposed to be always active diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 17b5b021aa..1702cfe64b 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -46,7 +46,7 @@ PCBNEW_CONTROL::PCBNEW_CONTROL() : void PCBNEW_CONTROL::Reset( RESET_REASON aReason ) { - m_frame = getEditFrame(); + m_frame = getEditFrame(); } @@ -149,7 +149,7 @@ int PCBNEW_CONTROL::TrackDisplayMode( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::PadDisplayMode( TOOL_EVENT& aEvent ) { wxCommandEvent dummy; - getEditFrame()->OnTogglePadDrawMode( dummy ); + m_frame->OnTogglePadDrawMode( dummy ); setTransitions(); return 0; @@ -219,8 +219,8 @@ int PCBNEW_CONTROL::HighContrastDec( TOOL_EVENT& aEvent ) // Layer control int PCBNEW_CONTROL::LayerTop( TOOL_EVENT& aEvent ) { - getEditFrame()->SwitchLayer( NULL, F_Cu ); - getEditFrame()->GetGalCanvas()->SetFocus(); + m_frame->SwitchLayer( NULL, F_Cu ); + m_frame->GetGalCanvas()->SetFocus(); setTransitions(); return 0; @@ -229,8 +229,8 @@ int PCBNEW_CONTROL::LayerTop( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerInner1( TOOL_EVENT& aEvent ) { - getEditFrame()->SwitchLayer( NULL, In1_Cu ); - getEditFrame()->GetGalCanvas()->SetFocus(); + m_frame->SwitchLayer( NULL, In1_Cu ); + m_frame->GetGalCanvas()->SetFocus(); setTransitions(); return 0; @@ -239,8 +239,8 @@ int PCBNEW_CONTROL::LayerInner1( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerInner2( TOOL_EVENT& aEvent ) { - getEditFrame()->SwitchLayer( NULL, In2_Cu ); - getEditFrame()->GetGalCanvas()->SetFocus(); + m_frame->SwitchLayer( NULL, In2_Cu ); + m_frame->GetGalCanvas()->SetFocus(); setTransitions(); return 0; @@ -249,8 +249,8 @@ int PCBNEW_CONTROL::LayerInner2( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerInner3( TOOL_EVENT& aEvent ) { - getEditFrame()->SwitchLayer( NULL, In3_Cu ); - getEditFrame()->GetGalCanvas()->SetFocus(); + m_frame->SwitchLayer( NULL, In3_Cu ); + m_frame->GetGalCanvas()->SetFocus(); setTransitions(); return 0; @@ -259,8 +259,8 @@ int PCBNEW_CONTROL::LayerInner3( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerInner4( TOOL_EVENT& aEvent ) { - getEditFrame()->SwitchLayer( NULL, In4_Cu ); - getEditFrame()->GetGalCanvas()->SetFocus(); + m_frame->SwitchLayer( NULL, In4_Cu ); + m_frame->GetGalCanvas()->SetFocus(); setTransitions(); return 0; @@ -269,8 +269,8 @@ int PCBNEW_CONTROL::LayerInner4( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerInner5( TOOL_EVENT& aEvent ) { - getEditFrame()->SwitchLayer( NULL, In5_Cu ); - getEditFrame()->GetGalCanvas()->SetFocus(); + m_frame->SwitchLayer( NULL, In5_Cu ); + m_frame->GetGalCanvas()->SetFocus(); setTransitions(); return 0; @@ -279,8 +279,8 @@ int PCBNEW_CONTROL::LayerInner5( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerInner6( TOOL_EVENT& aEvent ) { - getEditFrame()->SwitchLayer( NULL, In6_Cu ); - getEditFrame()->GetGalCanvas()->SetFocus(); + m_frame->SwitchLayer( NULL, In6_Cu ); + m_frame->GetGalCanvas()->SetFocus(); setTransitions(); return 0; @@ -289,8 +289,8 @@ int PCBNEW_CONTROL::LayerInner6( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerBottom( TOOL_EVENT& aEvent ) { - getEditFrame()->SwitchLayer( NULL, B_Cu ); - getEditFrame()->GetGalCanvas()->SetFocus(); + m_frame->SetActiveLayer( B_Cu ); + m_frame->GetGalCanvas()->SetFocus(); setTransitions(); return 0; @@ -299,8 +299,8 @@ int PCBNEW_CONTROL::LayerBottom( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerNext( TOOL_EVENT& aEvent ) { - PCB_EDIT_FRAME* editFrame = getEditFrame(); - LAYER_NUM layer = editFrame->GetActiveLayer(); + PCB_BASE_FRAME* editFrame = m_frame; + LAYER_NUM layer = editFrame->GetActiveLayer(); if( layer < F_Cu || layer >= B_Cu ) { @@ -325,8 +325,8 @@ int PCBNEW_CONTROL::LayerNext( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerPrev( TOOL_EVENT& aEvent ) { - PCB_EDIT_FRAME* editFrame = getEditFrame(); - LAYER_NUM layer = editFrame->GetActiveLayer(); + PCB_BASE_FRAME* editFrame = m_frame; + LAYER_NUM layer = editFrame->GetActiveLayer(); if( layer <= F_Cu || layer > B_Cu ) { @@ -399,7 +399,7 @@ int PCBNEW_CONTROL::LayerAlphaDec( TOOL_EVENT& aEvent ) // Grid control int PCBNEW_CONTROL::GridFast1( TOOL_EVENT& aEvent ) { - getEditFrame()->SetFastGrid1(); + m_frame->SetFastGrid1(); setTransitions(); return 0; @@ -408,7 +408,7 @@ int PCBNEW_CONTROL::GridFast1( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridFast2( TOOL_EVENT& aEvent ) { - getEditFrame()->SetFastGrid2(); + m_frame->SetFastGrid2(); setTransitions(); return 0; @@ -417,7 +417,7 @@ int PCBNEW_CONTROL::GridFast2( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridNext( TOOL_EVENT& aEvent ) { - getEditFrame()->SetNextGrid(); + m_frame->SetNextGrid(); setTransitions(); return 0; @@ -426,7 +426,7 @@ int PCBNEW_CONTROL::GridNext( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridPrev( TOOL_EVENT& aEvent ) { - getEditFrame()->SetPrevGrid(); + m_frame->SetPrevGrid(); setTransitions(); return 0; @@ -436,7 +436,7 @@ int PCBNEW_CONTROL::GridPrev( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridSetOrigin( TOOL_EVENT& aEvent ) { Activate(); - getEditFrame()->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, + m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) ); KIGFX::VIEW_CONTROLS* controls = getViewControls(); @@ -466,91 +466,6 @@ int PCBNEW_CONTROL::GridSetOrigin( TOOL_EVENT& aEvent ) } -// Track & via size control -int PCBNEW_CONTROL::TrackWidthInc( TOOL_EVENT& aEvent ) -{ - BOARD* board = getModel(); - int widthIndex = board->GetDesignSettings().GetTrackWidthIndex() + 1; - - if( widthIndex >= (int) board->GetDesignSettings().m_TrackWidthList.size() ) - widthIndex = board->GetDesignSettings().m_TrackWidthList.size() - 1; - - board->GetDesignSettings().SetTrackWidthIndex( widthIndex ); - board->GetDesignSettings().UseCustomTrackViaSize( false ); - - wxUpdateUIEvent dummy; - getEditFrame()->OnUpdateSelectTrackWidth( dummy ); - setTransitions(); - - m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); - - return 0; -} - - -int PCBNEW_CONTROL::TrackWidthDec( TOOL_EVENT& aEvent ) -{ - BOARD* board = getModel(); - int widthIndex = board->GetDesignSettings().GetTrackWidthIndex() - 1; - - if( widthIndex < 0 ) - widthIndex = 0; - - board->GetDesignSettings().SetTrackWidthIndex( widthIndex ); - board->GetDesignSettings().UseCustomTrackViaSize( false ); - - wxUpdateUIEvent dummy; - getEditFrame()->OnUpdateSelectTrackWidth( dummy ); - setTransitions(); - - m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); - - return 0; -} - - -int PCBNEW_CONTROL::ViaSizeInc( TOOL_EVENT& aEvent ) -{ - BOARD* board = getModel(); - int sizeIndex = board->GetDesignSettings().GetViaSizeIndex() + 1; - - if( sizeIndex >= (int) board->GetDesignSettings().m_ViasDimensionsList.size() ) - sizeIndex = board->GetDesignSettings().m_ViasDimensionsList.size() - 1; - - board->GetDesignSettings().SetViaSizeIndex( sizeIndex ); - board->GetDesignSettings().UseCustomTrackViaSize( false ); - - wxUpdateUIEvent dummy; - getEditFrame()->OnUpdateSelectViaSize( dummy ); - setTransitions(); - - m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); - - return 0; -} - - -int PCBNEW_CONTROL::ViaSizeDec( TOOL_EVENT& aEvent ) -{ - BOARD* board = getModel(); - int sizeIndex = board->GetDesignSettings().GetViaSizeIndex() - 1; - - if( sizeIndex < 0 ) - sizeIndex = 0; - - board->GetDesignSettings().SetViaSizeIndex( sizeIndex ); - board->GetDesignSettings().UseCustomTrackViaSize( false ); - - wxUpdateUIEvent dummy; - getEditFrame()->OnUpdateSelectViaSize( dummy ); - setTransitions(); - - m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); - - return 0; -} - - // Miscellaneous int PCBNEW_CONTROL::ResetCoords( TOOL_EVENT& aEvent ) { @@ -630,12 +545,6 @@ void PCBNEW_CONTROL::setTransitions() Go( &PCBNEW_CONTROL::GridPrev, COMMON_ACTIONS::gridPrev.MakeEvent() ); Go( &PCBNEW_CONTROL::GridSetOrigin, COMMON_ACTIONS::gridSetOrigin.MakeEvent() ); - // Track & via size control - Go( &PCBNEW_CONTROL::TrackWidthInc, COMMON_ACTIONS::trackWidthInc.MakeEvent() ); - Go( &PCBNEW_CONTROL::TrackWidthDec, COMMON_ACTIONS::trackWidthDec.MakeEvent() ); - Go( &PCBNEW_CONTROL::ViaSizeInc, COMMON_ACTIONS::viaSizeInc.MakeEvent() ); - Go( &PCBNEW_CONTROL::ViaSizeDec, COMMON_ACTIONS::viaSizeDec.MakeEvent() ); - // Miscellaneous Go( &PCBNEW_CONTROL::ResetCoords, COMMON_ACTIONS::resetCoords.MakeEvent() ); Go( &PCBNEW_CONTROL::SwitchUnits, COMMON_ACTIONS::switchUnits.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index e4920484db..c5bd7e8841 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -27,7 +27,7 @@ #include -class PCB_EDIT_FRAME; +class PCB_BASE_FRAME; /** * Class PCBNEW_CONTROL @@ -97,7 +97,7 @@ private: void setTransitions(); ///> Pointerto the currently used edit frame. - PCB_EDIT_FRAME* m_frame; + PCB_BASE_FRAME* m_frame; }; #endif