From db0d7083007106ac2693268862096e3b3bc7c978 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 16:25:50 +0200 Subject: [PATCH] Simplified code for switching layers in GAL view. Tools are notified of layer change event. --- pcbnew/pcbframe.cpp | 3 + pcbnew/tools/common_actions.cpp | 4 + pcbnew/tools/common_actions.h | 2 + pcbnew/tools/drawing_tool.cpp | 2 +- pcbnew/tools/module_tools.cpp | 11 +- pcbnew/tools/pcbnew_control.cpp | 120 +++++------------- pcbnew/tools/pcbnew_control.h | 9 +- ...nvert_brd_items_to_polygons_with_Boost.cpp | 2 +- 8 files changed, 50 insertions(+), 103 deletions(-) diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index e9c082533b..eb72a49fd6 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -828,7 +828,10 @@ void PCB_EDIT_FRAME::SetActiveLayer( LAYER_ID aLayer ) syncLayerWidgetLayer(); if( IsGalCanvasActive() ) + { + m_toolManager->RunAction( COMMON_ACTIONS::layerChanged ); // notify other tools GetGalCanvas()->Refresh(); + } } diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 0ef2778256..cf2879e725 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -222,6 +222,10 @@ TOOL_ACTION COMMON_ACTIONS::layerAlphaDec( "pcbnew.Control.layerAlphaDec", AS_GLOBAL, '{', "", "" ); +TOOL_ACTION COMMON_ACTIONS::layerChanged( "pcbnew.Control.layerChanged", + AS_GLOBAL, 0, + "", "", AF_NOTIFY ); + // Grid control TOOL_ACTION COMMON_ACTIONS::gridFast1( "pcbnew.Control.gridFast1", diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index fb53fed993..6df00fae9b 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -157,6 +157,8 @@ public: static TOOL_ACTION layerAlphaInc; static TOOL_ACTION layerAlphaDec; + static TOOL_ACTION layerChanged; // notification + // Grid control static TOOL_ACTION gridFast1; static TOOL_ACTION gridFast2; diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 170f723e09..83ae2129b8 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -889,7 +889,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, if( aStartingPoint ) { - LAYER_NUM layer = m_frame->GetScreen()->m_Active_Layer; + LAYER_ID layer = m_frame->GetScreen()->m_Active_Layer; // Init the new item attributes aGraphic->SetShape( (STROKE_T) aShape ); diff --git a/pcbnew/tools/module_tools.cpp b/pcbnew/tools/module_tools.cpp index cf9a142448..3a6827a9d9 100644 --- a/pcbnew/tools/module_tools.cpp +++ b/pcbnew/tools/module_tools.cpp @@ -576,14 +576,9 @@ int MODULE_TOOLS::ModuleEdgeOutlines( TOOL_EVENT& aEvent ) KIGFX::PCB_RENDER_SETTINGS* settings = static_cast( painter->GetSettings() ); - const LAYER_NUM layers[] = { ADHESIVE_N_FRONT, ADHESIVE_N_BACK,\ - SOLDERPASTE_N_FRONT, SOLDERPASTE_N_BACK,\ - SILKSCREEN_N_FRONT, SILKSCREEN_N_BACK,\ - SOLDERMASK_N_FRONT, SOLDERMASK_N_BACK,\ - DRAW_N,\ - COMMENT_N,\ - ECO1_N, ECO2_N,\ - EDGE_N }; + const LAYER_ID layers[] = { F_Adhes, B_Adhes, F_Paste, B_Paste, + F_SilkS, B_SilkS, F_Mask, B_Mask, + Dwgs_User, Cmts_User, Eco1_User, Eco2_User, Edge_Cuts }; bool enable = !settings->GetSketchMode( layers[0] ); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 2d92566530..537b051bed 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -279,79 +279,25 @@ int PCBNEW_CONTROL::HighContrastDec( TOOL_EVENT& aEvent ) // Layer control -int PCBNEW_CONTROL::LayerTop( TOOL_EVENT& aEvent ) +int PCBNEW_CONTROL::LayerSwitch( TOOL_EVENT& aEvent ) { - m_frame->SwitchLayer( NULL, F_Cu ); - m_frame->GetGalCanvas()->SetFocus(); - setTransitions(); + 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 ); - return 0; -} - - -int PCBNEW_CONTROL::LayerInner1( TOOL_EVENT& aEvent ) -{ - m_frame->SwitchLayer( NULL, In1_Cu ); - m_frame->GetGalCanvas()->SetFocus(); - setTransitions(); - - return 0; -} - - -int PCBNEW_CONTROL::LayerInner2( TOOL_EVENT& aEvent ) -{ - m_frame->SwitchLayer( NULL, In2_Cu ); - m_frame->GetGalCanvas()->SetFocus(); - setTransitions(); - - return 0; -} - - -int PCBNEW_CONTROL::LayerInner3( TOOL_EVENT& aEvent ) -{ - m_frame->SwitchLayer( NULL, In3_Cu ); - m_frame->GetGalCanvas()->SetFocus(); - setTransitions(); - - return 0; -} - - -int PCBNEW_CONTROL::LayerInner4( TOOL_EVENT& aEvent ) -{ - m_frame->SwitchLayer( NULL, In4_Cu ); - m_frame->GetGalCanvas()->SetFocus(); - setTransitions(); - - return 0; -} - - -int PCBNEW_CONTROL::LayerInner5( TOOL_EVENT& aEvent ) -{ - m_frame->SwitchLayer( NULL, In5_Cu ); - m_frame->GetGalCanvas()->SetFocus(); - setTransitions(); - - return 0; -} - - -int PCBNEW_CONTROL::LayerInner6( TOOL_EVENT& aEvent ) -{ - m_frame->SwitchLayer( NULL, In6_Cu ); - m_frame->GetGalCanvas()->SetFocus(); - setTransitions(); - - return 0; -} - - -int PCBNEW_CONTROL::LayerBottom( TOOL_EVENT& aEvent ) -{ - m_frame->SetActiveLayer( B_Cu ); m_frame->GetGalCanvas()->SetFocus(); setTransitions(); @@ -364,15 +310,17 @@ int PCBNEW_CONTROL::LayerNext( TOOL_EVENT& aEvent ) PCB_BASE_FRAME* editFrame = m_frame; LAYER_NUM layer = editFrame->GetActiveLayer(); - if( layer < F_Cu || layer >= B_Cu ) + if( layer < F_Cu || layer > B_Cu ) { setTransitions(); return 0; } - if( getModel()->GetCopperLayerCount() < 2 ) // Single layer + int layerCount = getModel()->GetCopperLayerCount(); + + if( layer == layerCount - 2 || layerCount < 2 ) layer = B_Cu; - else if( layer >= getModel()->GetCopperLayerCount() - 2 ) + else if( layer == B_Cu ) layer = F_Cu; else ++layer; @@ -390,16 +338,18 @@ int PCBNEW_CONTROL::LayerPrev( TOOL_EVENT& aEvent ) PCB_BASE_FRAME* editFrame = m_frame; LAYER_NUM layer = editFrame->GetActiveLayer(); - if( layer <= F_Cu || layer > B_Cu ) + if( layer < F_Cu || layer > B_Cu ) { setTransitions(); return 0; } - if( getModel()->GetCopperLayerCount() < 2 ) // Single layer + int layerCount = getModel()->GetCopperLayerCount(); + + if( layer == F_Cu || layerCount < 2 ) layer = B_Cu; else if( layer == B_Cu ) - layer = std::max( int( F_Cu ), getModel()->GetCopperLayerCount() - 2 ); + layer = layerCount - 2; else --layer; @@ -617,14 +567,14 @@ void PCBNEW_CONTROL::setTransitions() Go( &PCBNEW_CONTROL::HighContrastDec, COMMON_ACTIONS::highContrastDec.MakeEvent() ); // Layer control - Go( &PCBNEW_CONTROL::LayerTop, COMMON_ACTIONS::layerTop.MakeEvent() ); - Go( &PCBNEW_CONTROL::LayerInner1, COMMON_ACTIONS::layerInner1.MakeEvent() ); - Go( &PCBNEW_CONTROL::LayerInner2, COMMON_ACTIONS::layerInner2.MakeEvent() ); - Go( &PCBNEW_CONTROL::LayerInner3, COMMON_ACTIONS::layerInner3.MakeEvent() ); - Go( &PCBNEW_CONTROL::LayerInner4, COMMON_ACTIONS::layerInner4.MakeEvent() ); - Go( &PCBNEW_CONTROL::LayerInner5, COMMON_ACTIONS::layerInner5.MakeEvent() ); - Go( &PCBNEW_CONTROL::LayerInner6, COMMON_ACTIONS::layerInner6.MakeEvent() ); - Go( &PCBNEW_CONTROL::LayerBottom, COMMON_ACTIONS::layerBottom.MakeEvent() ); + Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerTop.MakeEvent() ); + Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner1.MakeEvent() ); + Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner2.MakeEvent() ); + Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner3.MakeEvent() ); + Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner4.MakeEvent() ); + Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner5.MakeEvent() ); + Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner6.MakeEvent() ); + Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerBottom.MakeEvent() ); Go( &PCBNEW_CONTROL::LayerNext, COMMON_ACTIONS::layerNext.MakeEvent() ); Go( &PCBNEW_CONTROL::LayerPrev, COMMON_ACTIONS::layerPrev.MakeEvent() ); Go( &PCBNEW_CONTROL::LayerAlphaInc, COMMON_ACTIONS::layerAlphaInc.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 4c11b9777b..7fc9978b60 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -62,14 +62,7 @@ public: int HighContrastDec( TOOL_EVENT& aEvent ); // Layer control - int LayerTop( TOOL_EVENT& aEvent ); - int LayerInner1( TOOL_EVENT& aEvent ); - int LayerInner2( TOOL_EVENT& aEvent ); - int LayerInner3( TOOL_EVENT& aEvent ); - int LayerInner4( TOOL_EVENT& aEvent ); - int LayerInner5( TOOL_EVENT& aEvent ); - int LayerInner6( TOOL_EVENT& aEvent ); - int LayerBottom( TOOL_EVENT& aEvent ); + int LayerSwitch( TOOL_EVENT& aEvent ); int LayerNext( TOOL_EVENT& aEvent ); int LayerPrev( TOOL_EVENT& aEvent ); int LayerAlphaInc( TOOL_EVENT& aEvent ); diff --git a/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp b/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp index 5144e4c88e..4d2117592e 100644 --- a/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp +++ b/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp @@ -303,7 +303,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) { for( BOARD_ITEM* item = module->GraphicalItems(); item; item = item->Next() ) { - if( !item->IsOnLayer( GetLayer() ) && !item->IsOnLayer( EDGE_N ) ) + if( !item->IsOnLayer( GetLayer() ) && !item->IsOnLayer( Edge_Cuts ) ) continue; if( item->Type() != PCB_MODULE_EDGE_T )