SELECTION has-a VIEW_GROUP instead of being-a VIEW_GROUP

Fixed numerous warnings caused by hidden overloaded methods
provided in both classes (Add(), Remove(), etc.)
This commit is contained in:
Maciej Suminski 2017-01-17 17:46:33 +01:00
parent 3c61b16e7b
commit 2eefa11732
4 changed files with 78 additions and 60 deletions

View File

@ -195,7 +195,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
// Add a VIEW_GROUP that serves as a preview for the new item
SELECTION preview;
m_view->Add( &preview );
m_view->Add( preview.ViewGroup() );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
@ -239,13 +239,13 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
{
text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() );
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
// TODO rotate CCW
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
{
text->Flip( text->GetPosition() );
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
}
@ -340,7 +340,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
text->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
// Show a preview of the item
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
}
@ -349,7 +349,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
m_controls->SetAutoPan( false );
m_controls->CaptureCursor( false );
m_view->Remove( &preview );
m_view->Remove( preview.ViewGroup() );
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -365,7 +365,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
// Add a VIEW_GROUP that serves as a preview for the new item
SELECTION preview;
m_view->Add( &preview );
m_view->Add( preview.ViewGroup() );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
@ -409,7 +409,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
else if( evt->IsAction( &COMMON_ACTIONS::incWidth ) && step != SET_ORIGIN )
{
dimension->SetWidth( dimension->GetWidth() + WIDTH_STEP );
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
else if( evt->IsAction( &COMMON_ACTIONS::decWidth ) && step != SET_ORIGIN )
@ -419,7 +419,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
if( width > WIDTH_STEP )
{
dimension->SetWidth( width - WIDTH_STEP );
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
}
@ -523,7 +523,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
}
// Show a preview of the item
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
}
@ -534,7 +534,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
m_controls->SetSnapping( false );
m_controls->SetAutoPan( false );
m_controls->CaptureCursor( false );
m_view->Remove( &preview );
m_view->Remove( preview.ViewGroup() );
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
@ -589,7 +589,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
}
BOARD_ITEM* firstItem = preview.Front();
m_view->Add( &preview );
m_view->Add( preview.ViewGroup() );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
@ -611,7 +611,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
for( auto item : preview )
item->Move( wxPoint( delta.x, delta.y ) );
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
else if( evt->Category() == TC_COMMAND )
@ -623,18 +623,18 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
item->Rotate( wxPoint( cursorPos.x, cursorPos.y ),
m_frame->GetRotationAngle() );
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
{
for( auto item : preview )
item->Flip( wxPoint( cursorPos.x, cursorPos.y ) );
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
else if( evt->IsCancel() || evt->IsActivate() )
{
preview.FreeItems();
preview.ViewGroup()->FreeItems();
break;
}
}
@ -731,7 +731,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
m_controls->SetSnapping( false );
m_controls->SetAutoPan( false );
m_controls->CaptureCursor( false );
m_view->Remove( &preview );
m_view->Remove( preview.ViewGroup() );
return 0;
}
@ -800,7 +800,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic,
// Add a VIEW_GROUP that serves as a preview for the new item
SELECTION preview;
m_view->Add( &preview );
m_view->Add( preview.ViewGroup() );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
@ -962,14 +962,14 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic,
}
if( updatePreview )
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
m_controls->ShowCursor( false );
m_controls->SetSnapping( false );
m_controls->SetAutoPan( false );
m_controls->CaptureCursor( false );
m_view->Remove( &preview );
m_view->Remove( preview.ViewGroup() );
return started;
}
@ -988,7 +988,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic )
// Add a VIEW_GROUP that serves as a preview for the new item
SELECTION preview;
m_view->Add( &preview );
m_view->Add( preview.ViewGroup() );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
@ -1116,13 +1116,13 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic )
}
// Show a preview of the item
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
else if( evt->IsAction( &COMMON_ACTIONS::incWidth ) )
{
aGraphic->SetWidth( aGraphic->GetWidth() + WIDTH_STEP );
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
else if( evt->IsAction( &COMMON_ACTIONS::decWidth ) )
@ -1132,7 +1132,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic )
if( width > WIDTH_STEP )
{
aGraphic->SetWidth( width - WIDTH_STEP );
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
}
@ -1144,7 +1144,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic )
aGraphic->SetAngle( aGraphic->GetAngle() + 3600.0 );
clockwise = !clockwise;
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
}
@ -1152,7 +1152,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic )
m_controls->SetSnapping( false );
m_controls->SetAutoPan( false );
m_controls->CaptureCursor( false );
m_view->Remove( &preview );
m_view->Remove( preview.ViewGroup() );
return ( step > SET_ORIGIN );
}
@ -1167,7 +1167,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
// Add a VIEW_GROUP that serves as a preview for the new item
SELECTION preview;
m_view->Add( &preview );
m_view->Add( preview.ViewGroup() );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true );
@ -1219,7 +1219,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
direction45 = false;
}
preview.FreeItems();
preview.ViewGroup()->FreeItems();
updatePreview = true;
numPoints = 0;
@ -1274,7 +1274,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
direction45 = false;
}
preview.FreeItems();
preview.ViewGroup()->FreeItems();
updatePreview = true;
}
else
@ -1357,14 +1357,14 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
}
if( updatePreview )
m_view->Update( &preview );
m_view->Update( preview.ViewGroup() );
}
m_controls->ShowCursor( false );
m_controls->SetSnapping( false );
m_controls->SetAutoPan( false );
m_controls->CaptureCursor( false );
m_view->Remove( &preview );
m_view->Remove( preview.ViewGroup() );
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013-2015 CERN
* Copyright (C) 2013-2017 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
@ -242,7 +242,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
}
}
getView()->Update( &selection );
getView()->Update( selection.ViewGroup() );
m_toolMgr->RunAction( COMMON_ACTIONS::editModifiedSelection, true );
}
@ -299,7 +299,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
{
// Update dragging offset (distance between cursor and the first dragged item)
m_offset = selection.Front()->GetPosition() - modPoint;
getView()->Update( &selection );
getView()->Update( selection.ViewGroup() );
updateRatsnest( true );
}
}

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013-2016 CERN
* Copyright (C) 2013-2017 CERN
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
@ -77,7 +77,7 @@ SELECTION_TOOL::SELECTION_TOOL() :
SELECTION_TOOL::~SELECTION_TOOL()
{
getView()->Remove( &m_selection );
getView()->Remove( m_selection.ViewGroup() );
}
@ -123,8 +123,8 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason )
clearSelection();
// Reinsert the VIEW_GROUP, in case it was removed from the VIEW
getView()->Remove( &m_selection );
getView()->Add( &m_selection );
getView()->Remove( m_selection.ViewGroup() );
getView()->Add( m_selection.ViewGroup() );
}
@ -1399,12 +1399,6 @@ bool SELECTION_TOOL::SanitizeSelection()
}
void SELECTION::clear()
{
m_items.clear();
}
VECTOR2I SELECTION::GetCenter() const
{
VECTOR2I centre;
@ -1431,9 +1425,9 @@ VECTOR2I SELECTION::GetCenter() const
}
const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList() const
const KIGFX::VIEW_GROUP::ITEMS SELECTION::SELECTION_VIEW_GROUP::updateDrawList() const
{
std::vector<VIEW_ITEM*> items;
std::vector<KIGFX::VIEW_ITEM*> items;
for( auto item : m_items )
{

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013-2016 CERN
* Copyright (C) 2013-2017 CERN
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
@ -45,12 +45,8 @@ namespace KIGFX
class GAL;
}
struct SELECTION : public KIGFX::VIEW_GROUP
struct SELECTION
{
private:
/// Set of selected items
std::set<BOARD_ITEM*> m_items;
public:
using ITER = std::set<BOARD_ITEM*>::iterator;
using CITER = std::set<BOARD_ITEM*>::const_iterator;
@ -60,27 +56,35 @@ public:
CITER begin() const { return m_items.cbegin(); }
CITER end() const { return m_items.cend(); }
virtual void Add( BOARD_ITEM* aItem )
SELECTION()
: m_viewGroup( m_items )
{
}
void Add( BOARD_ITEM* aItem )
{
m_items.insert( aItem );
m_viewGroup.Add( aItem );
}
virtual void Remove( BOARD_ITEM *aItem )
void Remove( BOARD_ITEM *aItem )
{
m_items.erase( aItem );
m_viewGroup.Remove( aItem );
}
virtual void Clear() override
void Clear()
{
m_items.clear();
m_viewGroup.Clear();
}
virtual unsigned int GetSize() const override
unsigned int GetSize() const
{
return m_items.size();
}
virtual KIGFX::VIEW_ITEM* GetItem( unsigned int idx ) const override
KIGFX::VIEW_ITEM* GetItem( unsigned int idx ) const
{
auto iter = m_items.begin();
@ -137,16 +141,35 @@ public:
return m_items;
}
virtual const VIEW_GROUP::ITEMS updateDrawList() const override;
KIGFX::VIEW_GROUP* ViewGroup()
{
return &m_viewGroup;
}
private:
class SELECTION_VIEW_GROUP : public KIGFX::VIEW_GROUP
{
public:
SELECTION_VIEW_GROUP( std::set<BOARD_ITEM*>& aItemSet )
: m_items( aItemSet )
{
}
protected:
virtual const VIEW_GROUP::ITEMS updateDrawList() const override;
/// Clears both the VIEW_GROUP and set of selected items. Please note that it does not
/// change properties of selected items (e.g. selection flag).
void clear();
private:
std::set<BOARD_ITEM*>& m_items;
};
/// VIEW_GROUP keeping the selected items
SELECTION_VIEW_GROUP m_viewGroup;
/// Set of selected items
std::set<BOARD_ITEM*> m_items;
};
enum SELECTION_LOCK_FLAGS
{
SELECTION_UNLOCKED = 0,
@ -154,6 +177,7 @@ enum SELECTION_LOCK_FLAGS
SELECTION_LOCKED = 2
};
/**
* Class SELECTION_TOOL
*