From 9c08873210e805bca539af6b73f213d9eb467484 Mon Sep 17 00:00:00 2001 From: John Beard Date: Fri, 10 Mar 2017 14:34:06 +0100 Subject: [PATCH] Make SELECTION_AREA a generic overlay item This simplifies the (already simple) SELECTION_AREA class. It is also moved into KIGFX::PREVIEW and put in the common library, where it can be reused by other GAL-aware tools (not just in Pcbnew) in future. --- common/CMakeLists.txt | 1 + .../preview_items}/selection_area.cpp | 37 +++++-------- .../preview_items}/selection_area.h | 55 +++++++++++-------- pcbnew/CMakeLists.txt | 1 - pcbnew/tools/selection_tool.cpp | 4 +- pcbnew/tools/selection_tool.h | 1 - pcbnew/tools/zoom_tool.cpp | 4 +- 7 files changed, 49 insertions(+), 54 deletions(-) rename {pcbnew/tools => common/preview_items}/selection_area.cpp (66%) rename {pcbnew/tools => include/preview_items}/selection_area.h (65%) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index c191f69977..4520919b10 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -185,6 +185,7 @@ set( COMMON_PAGE_LAYOUT_SRCS set( COMMON_PREVIEW_ITEMS_SRCS preview_items/simple_overlay_item.cpp + preview_items/selection_area.cpp ) set( COMMON_SRCS diff --git a/pcbnew/tools/selection_area.cpp b/common/preview_items/selection_area.cpp similarity index 66% rename from pcbnew/tools/selection_area.cpp rename to common/preview_items/selection_area.cpp index 7e4e900a8a..f66cb1deed 100644 --- a/pcbnew/tools/selection_area.cpp +++ b/common/preview_items/selection_area.cpp @@ -22,13 +22,20 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "selection_area.h" -#include -#include +#include +#include #include -using namespace KIGFX; +using namespace KIGFX::PREVIEW; + + +SELECTION_AREA::SELECTION_AREA() +{ + SetStrokeColor( COLOR4D( 1.0, 1.0, 0.4, 1.0 ) ); + SetFillColor( COLOR4D( 0.3, 0.3, 0.5, 0.3 ) ); +} + const BOX2I SELECTION_AREA::ViewBBox() const { @@ -41,26 +48,8 @@ const BOX2I SELECTION_AREA::ViewBBox() const } -void SELECTION_AREA::ViewGetLayers( int aLayers[], int& aCount ) const +void SELECTION_AREA::drawPreviewShape( KIGFX::GAL& aGal ) const { - aLayers[0] = SelectionLayer; - aCount = 1; + aGal.DrawRectangle( m_origin, m_end ); } - -void SELECTION_AREA::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const -{ - auto gal = aView->GetGAL(); - gal->SetLineWidth( 1.0 ); - gal->SetStrokeColor( COLOR4D( 1.0, 1.0, 0.4, 1.0 ) ); - gal->SetFillColor( COLOR4D( 0.3, 0.3, 0.5, 0.3 ) ); - gal->SetIsStroke( true ); - gal->SetIsFill( true ); - gal->DrawRectangle( m_origin, m_end ); -} - - -SELECTION_AREA::SELECTION_AREA() : - EDA_ITEM( NOT_USED ) // this item is never added to a BOARD so it needs no type. -{ -} diff --git a/pcbnew/tools/selection_area.h b/include/preview_items/selection_area.h similarity index 65% rename from pcbnew/tools/selection_area.h rename to include/preview_items/selection_area.h index 97fb0ab021..9c274c86fa 100644 --- a/pcbnew/tools/selection_area.h +++ b/include/preview_items/selection_area.h @@ -22,63 +22,70 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef __SELECTION_AREA_H -#define __SELECTION_AREA_H +#ifndef PREVIEW_ITEMS_SELECTION_AREA_H +#define PREVIEW_ITEMS_SELECTION_AREA_H + +#include -#include -#include -#include namespace KIGFX { class GAL; -} + +namespace PREVIEW +{ /** * Class SELECTION_AREA * - * Represents a selection area (currently a rectangle) in a VIEW. + * Represents a selection area (currently a rectangle) in a VIEW, + * drawn corner-to-corner between two points. This is useful when + * selecting a rectangular area, for lasso-select or zooming, for + * example. */ -class SELECTION_AREA : public EDA_ITEM +class SELECTION_AREA : public SIMPLE_OVERLAY_ITEM { public: - static const int SelectionLayer = ITEM_GAL_LAYER( GP_OVERLAY ); SELECTION_AREA(); - ~SELECTION_AREA() {}; - virtual const BOX2I ViewBBox() const override; - - void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override; - - void ViewGetLayers( int aLayers[], int& aCount ) const override; + const BOX2I ViewBBox() const override; + ///> Set the origin of the rectange (the fixed corner) void SetOrigin( VECTOR2I aOrigin ) { m_origin = aOrigin; } + /** + * Set the current end of the rectangle (the corner that moves + * with the cursor. + */ void SetEnd( VECTOR2I aEnd ) { m_end = aEnd; } -#if defined(DEBUG) - void Show( int x, std::ostream& st ) const override - { - } -#endif - - /** Get class name + /** + * Get class name * @return string "SELECTION_AREA" */ - virtual wxString GetClass() const override + wxString GetClass() const override { return wxT( "SELECTION_AREA" ); } private: + + /** + * Draw the selection rectangle onto the GAL + */ + void drawPreviewShape( KIGFX::GAL& aGal ) const override; + VECTOR2I m_origin, m_end; }; -#endif +} // PREVIEW +} // KIGFX + +#endif // PREVIEW_ITEMS_SELECTION_AREA_H diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 47a70f5cec..53b8bcd7f5 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -290,7 +290,6 @@ set( PCBNEW_CLASS_SRCS class_action_plugin.cpp tools/selection_tool.cpp - tools/selection_area.cpp tools/pcb_selection_conditions.cpp tools/bright_box.cpp tools/edit_points.cpp diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index f25f8310ff..a3e1e41d43 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -43,6 +43,7 @@ using namespace std::placeholders; #include #include #include +#include #include #include #include @@ -52,7 +53,6 @@ using namespace std::placeholders; #include #include "selection_tool.h" -#include "selection_area.h" #include "bright_box.h" #include "pcb_actions.h" @@ -464,7 +464,7 @@ bool SELECTION_TOOL::selectMultiple() KIGFX::VIEW* view = getView(); getViewControls()->SetAutoPan( true ); - SELECTION_AREA area; + KIGFX::PREVIEW::SELECTION_AREA area; view->Add( &area ); while( OPT_TOOL_EVENT evt = Wait() ) diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 28c2fc2020..aff8e499bc 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -37,7 +37,6 @@ #include class PCB_BASE_FRAME; -class SELECTION_AREA; class BOARD_ITEM; class GENERAL_COLLECTOR; diff --git a/pcbnew/tools/zoom_tool.cpp b/pcbnew/tools/zoom_tool.cpp index 5ced5a3356..0278e3402a 100644 --- a/pcbnew/tools/zoom_tool.cpp +++ b/pcbnew/tools/zoom_tool.cpp @@ -23,9 +23,9 @@ #include #include #include +#include #include "zoom_tool.h" -#include "selection_area.h" #include "pcb_actions.h" @@ -76,7 +76,7 @@ bool ZOOM_TOOL::selectRegion() auto canvas = m_frame->GetGalCanvas(); getViewControls()->SetAutoPan( true ); - SELECTION_AREA area; + KIGFX::PREVIEW::SELECTION_AREA area; view->Add( &area ); while( auto evt = Wait() )