From 256f52f27ed241fe52deb3675e899c14b3c668bf Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 20 Sep 2017 15:56:22 -0400 Subject: [PATCH] Use VIEW_GROUP for candidate highlighting; enable in PcbNew also --- gerbview/class_gerber_draw_item.cpp | 13 +++--------- gerbview/tools/selection_tool.cpp | 16 +++++++++++---- pcbnew/pcb_painter.cpp | 7 +++++++ pcbnew/pcb_painter.h | 3 +++ pcbnew/tools/selection_tool.cpp | 32 +++++++++++++++++------------ 5 files changed, 44 insertions(+), 27 deletions(-) diff --git a/gerbview/class_gerber_draw_item.cpp b/gerbview/class_gerber_draw_item.cpp index 4412fa34f2..356ff1736b 100644 --- a/gerbview/class_gerber_draw_item.cpp +++ b/gerbview/class_gerber_draw_item.cpp @@ -765,17 +765,10 @@ void GERBER_DRAW_ITEM::Show( int nestLevel, std::ostream& os ) const void GERBER_DRAW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const { - aCount = IsBrightened() ? 1 : 2; + aCount = 2; - if( IsBrightened() ) - { - aLayers[0] = LAYER_GP_OVERLAY; - } - else - { - aLayers[0] = GERBER_DRAW_LAYER( GetLayer() ); - aLayers[1] = GERBER_DCODE_LAYER( aLayers[0] ); - } + aLayers[0] = GERBER_DRAW_LAYER( GetLayer() ); + aLayers[1] = GERBER_DCODE_LAYER( aLayers[0] ); } diff --git a/gerbview/tools/selection_tool.cpp b/gerbview/tools/selection_tool.cpp index efd48a2b82..d12fd893cc 100644 --- a/gerbview/tools/selection_tool.cpp +++ b/gerbview/tools/selection_tool.cpp @@ -633,9 +633,12 @@ void GERBVIEW_SELECTION_TOOL::zoomFitSelection( void ) EDA_ITEM* GERBVIEW_SELECTION_TOOL::disambiguationMenu( GERBER_COLLECTOR* aCollector ) { EDA_ITEM* current = NULL; - BRIGHT_BOX brightBox; + KIGFX::VIEW_GROUP highlightGroup; CONTEXT_MENU menu; + highlightGroup.SetLayer( LAYER_GP_OVERLAY ); + getView()->Add( &highlightGroup ); + int limit = std::min( 10, aCollector->GetCount() ); for( int i = 0; i < limit; ++i ) @@ -657,7 +660,8 @@ EDA_ITEM* GERBVIEW_SELECTION_TOOL::disambiguationMenu( GERBER_COLLECTOR* aCollec if( current ) { current->ClearBrightened(); - getView()->Update( current, KIGFX::LAYERS ); + getView()->Hide( current, false ); + highlightGroup.Remove( current ); getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); } @@ -668,7 +672,8 @@ EDA_ITEM* GERBVIEW_SELECTION_TOOL::disambiguationMenu( GERBER_COLLECTOR* aCollec { current = ( *aCollector )[id - 1]; current->SetBrightened(); - getView()->Update( current, KIGFX::LAYERS ); + getView()->Hide( current, true ); + highlightGroup.Add( current ); getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); } else @@ -693,10 +698,13 @@ EDA_ITEM* GERBVIEW_SELECTION_TOOL::disambiguationMenu( GERBER_COLLECTOR* aCollec if( current && current->IsBrightened() ) { current->ClearBrightened(); - getView()->Update( current, KIGFX::LAYERS ); + getView()->Hide( current, false ); getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); } + getView()->Remove( &highlightGroup ); + + return current; } diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 3a0e82d222..fa20016d94 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -53,6 +53,7 @@ PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS() m_clearance = CL_NONE; m_sketchBoardGfx = false; m_sketchFpGfx = false; + m_selectionCandidateColor = COLOR4D( 0.0, 1.0, 0.0, 0.75 ); // By default everything should be displayed as filled for( unsigned int i = 0; i < PCB_LAYER_ID_COUNT; ++i ) @@ -210,6 +211,12 @@ const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer if( item ) { + // Selection disambiguation + if( item->IsBrightened() ) + { + return m_selectionCandidateColor; + } + if( item->IsSelected() ) { return m_layerColorsSel[aLayer]; diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index 895e57e452..e1cef7bbfa 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -163,6 +163,9 @@ protected: ///> Clearance visibility settings int m_clearance; + + ///> Color used for highlighting selection candidates + COLOR4D m_selectionCandidateColor; }; diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 210dbb13a2..117831c185 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -1268,10 +1268,11 @@ void SELECTION_TOOL::clearSelection() BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) { BOARD_ITEM* current = NULL; - PCB_BRIGHT_BOX brightBox; + KIGFX::VIEW_GROUP highlightGroup; CONTEXT_MENU menu; - getView()->Add( &brightBox ); + highlightGroup.SetLayer( LAYER_GP_OVERLAY ); + getView()->Add( &highlightGroup ); int limit = std::min( 9, aCollector->GetCount() ); @@ -1294,7 +1295,12 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) if( evt->Action() == TA_CONTEXT_MENU_UPDATE ) { if( current ) + { current->ClearBrightened(); + getView()->Hide( current, false ); + highlightGroup.Remove( current ); + getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); + } int id = *evt->GetCommandId(); @@ -1303,6 +1309,9 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) { current = ( *aCollector )[id - 1]; current->SetBrightened(); + getView()->Hide( current, true ); + highlightGroup.Add( current ); + getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); } else { @@ -1321,19 +1330,16 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) break; } - - // Draw a mark to show which item is available to be selected - if( current && current->IsBrightened() ) - { - brightBox.SetItem( current ); - getView()->SetVisible( &brightBox, true ); -// getView()->Hide( &brightBox, false ); - getView()->Update( &brightBox, KIGFX::GEOMETRY ); - getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); - } } - getView()->Remove( &brightBox ); + if( current && current->IsBrightened() ) + { + current->ClearBrightened(); + getView()->Hide( current, false ); + getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); + } + + getView()->Remove( &highlightGroup ); return current;