From 78853febbe50ad7bbccd4328cf77a62d23a1a79e Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 16:57:01 +0200 Subject: [PATCH] Zone fill/unfill actions in context menu (GAL). --- pcbnew/router/pns_router.cpp | 3 +- pcbnew/router/router_tool.cpp | 6 +- pcbnew/tools/common_actions.cpp | 15 +++++ pcbnew/tools/common_actions.h | 6 +- pcbnew/tools/pcb_editor_control.cpp | 90 +++++++++++++++++++++++++++++ pcbnew/tools/pcb_editor_control.h | 9 ++- pcbnew/tools/pcbnew_control.cpp | 1 + pcbnew/tools/pcbnew_control.h | 8 +-- 8 files changed, 123 insertions(+), 15 deletions(-) diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 67d54ceda5..d9db594a0f 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -759,7 +759,8 @@ void PNS_ROUTER::CommitRouting( PNS_NODE* aNode ) via_board->SetWidth( via->Diameter() ); via_board->SetDrill( via->Drill() ); via_board->SetNetCode( via->Net() ); - via_board->SetLayerPair( m_settings.GetLayerTop(), m_settings.GetLayerBottom() ); + via_board->SetLayerPair( ToLAYER_ID( m_settings.GetLayerTop() ), + ToLAYER_ID( m_settings.GetLayerBottom() ) ); newBI = via_board; break; } diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 03298fd9a1..29de1909db 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -212,8 +212,8 @@ public: Add( ACT_PlaceThroughVia ); Add( ACT_SwitchPosture ); - AppendSeparator ( ); - + AppendSeparator(); + CONTEXT_TRACK_WIDTH_MENU* trackMenu = new CONTEXT_TRACK_WIDTH_MENU; trackMenu->SetBoard( aBoard ); AppendSubMenu( trackMenu, wxT( "Select Track Width" ) ); @@ -567,7 +567,7 @@ void ROUTER_TOOL::performRouting() break; // Synchronize the indicated layer - frame->SetActiveLayer( m_router->GetCurrentLayer() ); + frame->SetActiveLayer( ToLAYER_ID( m_router->GetCurrentLayer() ) ); m_router->Move( m_endSnapPoint, m_endItem ); } diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 47321a67c5..0ce1c0f806 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -109,6 +109,7 @@ TOOL_ACTION COMMON_ACTIONS::setAnchor( "pcbnew.InteractiveDrawing.setAnchor", "Place the footprint anchor", "Place the footprint anchor", AF_ACTIVATE ); + // View Controls TOOL_ACTION COMMON_ACTIONS::zoomIn( "pcbnew.Control.zoomIn", AS_GLOBAL, WXK_F1, @@ -271,6 +272,20 @@ TOOL_ACTION COMMON_ACTIONS::trackViaSizeChanged( "pcbnew.EditorControl.trackViaS "", "", AF_NOTIFY ); +// Zone actions +TOOL_ACTION COMMON_ACTIONS::zoneFill( "pcbnew.EditorControl.zoneFill", + AS_GLOBAL, 0, + "Fill", "Fill zone(s)" ); + +TOOL_ACTION COMMON_ACTIONS::zoneFillAll( "pcbnew.EditorControl.zoneFillAll", + AS_GLOBAL, 0, + "Fill all", "Fill all zones" ); + +TOOL_ACTION COMMON_ACTIONS::zoneUnfill( "pcbnew.EditorControl.zoneUnfill", + AS_GLOBAL, 0, + "Unfill", "Unfill zone(s)" ); + + // Module editor tools TOOL_ACTION COMMON_ACTIONS::placePad( "pcbnew.ModuleEditor.placePad", AS_GLOBAL, 0, diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 79af0ee129..4712b42525 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -62,7 +62,6 @@ public: /// Deleting a BOARD_ITEM static TOOL_ACTION remove; - // Drawing Tool /// Activation of the drawing tool (line) static TOOL_ACTION drawLine; @@ -177,6 +176,10 @@ public: static TOOL_ACTION trackViaSizeChanged; // notification + // Zone actions + static TOOL_ACTION zoneFill; + static TOOL_ACTION zoneFillAll; + static TOOL_ACTION zoneUnfill; // Module editor tools /// Activation of the drawing tool (placing a PAD) @@ -197,7 +200,6 @@ public: /// Display module texts as outlines static TOOL_ACTION moduleTextOutlines; - // Miscellaneous static TOOL_ACTION resetCoords; static TOOL_ACTION switchCursor; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index a1b46c8a46..f1c8fe3833 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -25,10 +25,26 @@ #include "pcb_editor_control.h" #include "common_actions.h" +#include "selection_tool.h" + #include #include +#include #include + +class ZONE_CONTEXT_MENU : public CONTEXT_MENU +{ +public: + ZONE_CONTEXT_MENU() + { + Add( COMMON_ACTIONS::zoneFill ); + Add( COMMON_ACTIONS::zoneFillAll ); + Add( COMMON_ACTIONS::zoneUnfill ); + } +}; + + PCB_EDITOR_CONTROL::PCB_EDITOR_CONTROL() : TOOL_INTERACTIVE( "pcbnew.EditorControl" ) { @@ -43,6 +59,14 @@ void PCB_EDITOR_CONTROL::Reset( RESET_REASON aReason ) bool PCB_EDITOR_CONTROL::Init() { + SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + + if( selTool ) + { + selTool->AddSubMenu( new ZONE_CONTEXT_MENU, wxT( "Zones" ), + SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) ); + } + setTransitions(); return true; @@ -134,6 +158,67 @@ int PCB_EDITOR_CONTROL::ViaSizeDec( TOOL_EVENT& aEvent ) } +// Zone actions +int PCB_EDITOR_CONTROL::ZoneFill( TOOL_EVENT& aEvent ) +{ + SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + const SELECTION& selection = selTool->GetSelection(); + + for( int i = 0; i < selection.Size(); ++i ) + { + assert( selection.Item( i )->Type() == PCB_ZONE_AREA_T ); + + ZONE_CONTAINER* zone = selection.Item( i ); + m_frame->Fill_Zone( zone ); + zone->SetIsFilled( true ); + zone->ViewUpdate(); + } + + setTransitions(); + + return 0; +} + + +int PCB_EDITOR_CONTROL::ZoneFillAll( TOOL_EVENT& aEvent ) +{ + BOARD* board = getModel(); + + for( int i = 0; i < board->GetAreaCount(); ++i ) + { + ZONE_CONTAINER* zone = board->GetArea( i ); + m_frame->Fill_Zone( zone ); + zone->SetIsFilled( true ); + zone->ViewUpdate(); + } + + setTransitions(); + + return 0; +} + + +int PCB_EDITOR_CONTROL::ZoneUnfill( TOOL_EVENT& aEvent ) +{ + SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + const SELECTION& selection = selTool->GetSelection(); + + for( int i = 0; i < selection.Size(); ++i ) + { + assert( selection.Item( i )->Type() == PCB_ZONE_AREA_T ); + + ZONE_CONTAINER* zone = selection.Item( i ); + zone->SetIsFilled( false ); + zone->ClearFilledPolysList(); + zone->ViewUpdate(); + } + + setTransitions(); + + return 0; +} + + void PCB_EDITOR_CONTROL::setTransitions() { // Track & via size control @@ -141,4 +226,9 @@ void PCB_EDITOR_CONTROL::setTransitions() 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() ); + + // Zone actions + Go( &PCB_EDITOR_CONTROL::ZoneFill, COMMON_ACTIONS::zoneFill.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::ZoneFillAll, COMMON_ACTIONS::zoneFillAll.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::ZoneUnfill, COMMON_ACTIONS::zoneUnfill.MakeEvent() ); } diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index 8d879907fa..6d272884c9 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -30,9 +30,9 @@ class PCB_EDIT_FRAME; /** - * Class PCBNEW_CONTROL + * Class PCB_EDITOR_CONTROL * - * Handles hot keys that are not accepted by any other tool. + * Handles actions specific to the board editor in pcbnew. */ class PCB_EDITOR_CONTROL : public TOOL_INTERACTIVE { @@ -51,6 +51,11 @@ public: int ViaSizeInc( TOOL_EVENT& aEvent ); int ViaSizeDec( TOOL_EVENT& aEvent ); + // Zone actions + int ZoneFill( TOOL_EVENT& aEvent ); + int ZoneFillAll( TOOL_EVENT& aEvent ); + int ZoneUnfill( TOOL_EVENT& aEvent ); + private: ///> Sets up handlers for various events. void setTransitions(); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 1bbddbc432..a0573b3118 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -40,6 +40,7 @@ #include #include + PCBNEW_CONTROL::PCBNEW_CONTROL() : TOOL_INTERACTIVE( "pcbnew.Control" ) { diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 7fc9978b60..e9e87cb1e4 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -32,7 +32,7 @@ class PCB_BASE_FRAME; /** * Class PCBNEW_CONTROL * - * Handles hot keys that are not accepted by any other tool. + * Handles actions that are shared between different frames in pcbnew. */ class PCBNEW_CONTROL : public TOOL_INTERACTIVE @@ -75,12 +75,6 @@ public: int GridPrev( TOOL_EVENT& aEvent ); int GridSetOrigin( TOOL_EVENT& aEvent ); - // Track & via size control - int TrackWidthInc( TOOL_EVENT& aEvent ); - int TrackWidthDec( TOOL_EVENT& aEvent ); - int ViaSizeInc( TOOL_EVENT& aEvent ); - int ViaSizeDec( TOOL_EVENT& aEvent ); - // Miscellaneous int ResetCoords( TOOL_EVENT& aEvent ); int SwitchCursor( TOOL_EVENT& aEvent );