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.
This commit is contained in:
parent
5e84e953f3
commit
9c08873210
|
@ -185,6 +185,7 @@ set( COMMON_PAGE_LAYOUT_SRCS
|
||||||
|
|
||||||
set( COMMON_PREVIEW_ITEMS_SRCS
|
set( COMMON_PREVIEW_ITEMS_SRCS
|
||||||
preview_items/simple_overlay_item.cpp
|
preview_items/simple_overlay_item.cpp
|
||||||
|
preview_items/selection_area.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set( COMMON_SRCS
|
set( COMMON_SRCS
|
||||||
|
|
|
@ -22,13 +22,20 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "selection_area.h"
|
#include <preview_items/selection_area.h>
|
||||||
#include <gal/graphics_abstraction_layer.h>
|
|
||||||
#include <gal/color4d.h>
|
|
||||||
|
|
||||||
|
#include <gal/graphics_abstraction_layer.h>
|
||||||
#include <view/view.h>
|
#include <view/view.h>
|
||||||
|
|
||||||
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
|
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;
|
aGal.DrawRectangle( m_origin, m_end );
|
||||||
aCount = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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.
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -22,63 +22,70 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __SELECTION_AREA_H
|
#ifndef PREVIEW_ITEMS_SELECTION_AREA_H
|
||||||
#define __SELECTION_AREA_H
|
#define PREVIEW_ITEMS_SELECTION_AREA_H
|
||||||
|
|
||||||
|
#include <preview_items/simple_overlay_item.h>
|
||||||
|
|
||||||
#include <base_struct.h>
|
|
||||||
#include <layers_id_colors_and_visibility.h>
|
|
||||||
#include <math/box2.h>
|
|
||||||
|
|
||||||
namespace KIGFX
|
namespace KIGFX
|
||||||
{
|
{
|
||||||
class GAL;
|
class GAL;
|
||||||
}
|
|
||||||
|
namespace PREVIEW
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SELECTION_AREA
|
* 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:
|
public:
|
||||||
static const int SelectionLayer = ITEM_GAL_LAYER( GP_OVERLAY );
|
|
||||||
|
|
||||||
SELECTION_AREA();
|
SELECTION_AREA();
|
||||||
~SELECTION_AREA() {};
|
|
||||||
|
|
||||||
virtual const BOX2I ViewBBox() const override;
|
const BOX2I ViewBBox() const override;
|
||||||
|
|
||||||
void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override;
|
|
||||||
|
|
||||||
void ViewGetLayers( int aLayers[], int& aCount ) const override;
|
|
||||||
|
|
||||||
|
///> Set the origin of the rectange (the fixed corner)
|
||||||
void SetOrigin( VECTOR2I aOrigin )
|
void SetOrigin( VECTOR2I aOrigin )
|
||||||
{
|
{
|
||||||
m_origin = aOrigin;
|
m_origin = aOrigin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current end of the rectangle (the corner that moves
|
||||||
|
* with the cursor.
|
||||||
|
*/
|
||||||
void SetEnd( VECTOR2I aEnd )
|
void SetEnd( VECTOR2I aEnd )
|
||||||
{
|
{
|
||||||
m_end = aEnd;
|
m_end = aEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG)
|
/**
|
||||||
void Show( int x, std::ostream& st ) const override
|
* Get class name
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Get class name
|
|
||||||
* @return string "SELECTION_AREA"
|
* @return string "SELECTION_AREA"
|
||||||
*/
|
*/
|
||||||
virtual wxString GetClass() const override
|
wxString GetClass() const override
|
||||||
{
|
{
|
||||||
return wxT( "SELECTION_AREA" );
|
return wxT( "SELECTION_AREA" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw the selection rectangle onto the GAL
|
||||||
|
*/
|
||||||
|
void drawPreviewShape( KIGFX::GAL& aGal ) const override;
|
||||||
|
|
||||||
VECTOR2I m_origin, m_end;
|
VECTOR2I m_origin, m_end;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
} // PREVIEW
|
||||||
|
} // KIGFX
|
||||||
|
|
||||||
|
#endif // PREVIEW_ITEMS_SELECTION_AREA_H
|
|
@ -290,7 +290,6 @@ set( PCBNEW_CLASS_SRCS
|
||||||
class_action_plugin.cpp
|
class_action_plugin.cpp
|
||||||
|
|
||||||
tools/selection_tool.cpp
|
tools/selection_tool.cpp
|
||||||
tools/selection_area.cpp
|
|
||||||
tools/pcb_selection_conditions.cpp
|
tools/pcb_selection_conditions.cpp
|
||||||
tools/bright_box.cpp
|
tools/bright_box.cpp
|
||||||
tools/edit_points.cpp
|
tools/edit_points.cpp
|
||||||
|
|
|
@ -43,6 +43,7 @@ using namespace std::placeholders;
|
||||||
#include <class_draw_panel_gal.h>
|
#include <class_draw_panel_gal.h>
|
||||||
#include <view/view_controls.h>
|
#include <view/view_controls.h>
|
||||||
#include <view/view_group.h>
|
#include <view/view_group.h>
|
||||||
|
#include <preview_items/selection_area.h>
|
||||||
#include <painter.h>
|
#include <painter.h>
|
||||||
#include <bitmaps.h>
|
#include <bitmaps.h>
|
||||||
#include <hotkeys.h>
|
#include <hotkeys.h>
|
||||||
|
@ -52,7 +53,6 @@ using namespace std::placeholders;
|
||||||
#include <ratsnest_data.h>
|
#include <ratsnest_data.h>
|
||||||
|
|
||||||
#include "selection_tool.h"
|
#include "selection_tool.h"
|
||||||
#include "selection_area.h"
|
|
||||||
#include "bright_box.h"
|
#include "bright_box.h"
|
||||||
#include "pcb_actions.h"
|
#include "pcb_actions.h"
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ bool SELECTION_TOOL::selectMultiple()
|
||||||
KIGFX::VIEW* view = getView();
|
KIGFX::VIEW* view = getView();
|
||||||
getViewControls()->SetAutoPan( true );
|
getViewControls()->SetAutoPan( true );
|
||||||
|
|
||||||
SELECTION_AREA area;
|
KIGFX::PREVIEW::SELECTION_AREA area;
|
||||||
view->Add( &area );
|
view->Add( &area );
|
||||||
|
|
||||||
while( OPT_TOOL_EVENT evt = Wait() )
|
while( OPT_TOOL_EVENT evt = Wait() )
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
#include <tool/tool_menu.h>
|
#include <tool/tool_menu.h>
|
||||||
|
|
||||||
class PCB_BASE_FRAME;
|
class PCB_BASE_FRAME;
|
||||||
class SELECTION_AREA;
|
|
||||||
class BOARD_ITEM;
|
class BOARD_ITEM;
|
||||||
class GENERAL_COLLECTOR;
|
class GENERAL_COLLECTOR;
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,9 @@
|
||||||
#include <view/view_controls.h>
|
#include <view/view_controls.h>
|
||||||
#include <view/view.h>
|
#include <view/view.h>
|
||||||
#include <tool/tool_manager.h>
|
#include <tool/tool_manager.h>
|
||||||
|
#include <preview_items/selection_area.h>
|
||||||
|
|
||||||
#include "zoom_tool.h"
|
#include "zoom_tool.h"
|
||||||
#include "selection_area.h"
|
|
||||||
#include "pcb_actions.h"
|
#include "pcb_actions.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ bool ZOOM_TOOL::selectRegion()
|
||||||
auto canvas = m_frame->GetGalCanvas();
|
auto canvas = m_frame->GetGalCanvas();
|
||||||
getViewControls()->SetAutoPan( true );
|
getViewControls()->SetAutoPan( true );
|
||||||
|
|
||||||
SELECTION_AREA area;
|
KIGFX::PREVIEW::SELECTION_AREA area;
|
||||||
view->Add( &area );
|
view->Add( &area );
|
||||||
|
|
||||||
while( auto evt = Wait() )
|
while( auto evt = Wait() )
|
||||||
|
|
Loading…
Reference in New Issue