Browse Source
Refactor SELECTION, SELECTION_CONDITIONS, and context menus to common
Refactor SELECTION, SELECTION_CONDITIONS, and context menus to common
SELECTION now holds EDA_ITEMs not BOARD_ITEMs so various places had to change to casting the selected items to BOARD_ITEMs. Fixed compilation warnings on clang (Tom)pull/3/merge
committed by
Tomasz Włostowski
26 changed files with 434 additions and 306 deletions
-
5common/CMakeLists.txt
-
2common/tool/conditional_menu.cpp
-
4common/tool/grid_menu.cpp
-
101common/tool/selection_conditions.cpp
-
13common/tool/tool_menu.cpp
-
4common/tool/zoom_menu.cpp
-
0include/tool/conditional_menu.h
-
0include/tool/grid_menu.h
-
141include/tool/selection.h
-
35include/tool/selection_conditions.h
-
4include/tool/tool_menu.h
-
0include/tool/zoom_menu.h
-
6pcbnew/CMakeLists.txt
-
2pcbnew/dialogs/dialog_track_via_properties.h
-
5pcbnew/router/router_tool.cpp
-
10pcbnew/tools/drawing_tool.cpp
-
2pcbnew/tools/drawing_tool.h
-
29pcbnew/tools/edit_tool.cpp
-
2pcbnew/tools/pad_tool.cpp
-
9pcbnew/tools/pcb_editor_control.cpp
-
127pcbnew/tools/pcb_selection_conditions.cpp
-
72pcbnew/tools/pcb_selection_conditions.h
-
2pcbnew/tools/pcbnew_control.cpp
-
20pcbnew/tools/placement_tool.cpp
-
35pcbnew/tools/selection_tool.cpp
-
110pcbnew/tools/selection_tool.h
@ -0,0 +1,141 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2013-2017 CERN |
|||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> |
|||
* @author Maciej Suminski <maciej.suminski@cern.ch> |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef __SELECTION_H |
|||
#define __SELECTION_H |
|||
|
|||
#include <set> |
|||
|
|||
#include <base_struct.h> |
|||
#include <view/view_group.h> |
|||
|
|||
|
|||
class SELECTION : public KIGFX::VIEW_GROUP |
|||
{ |
|||
public: |
|||
using ITER = std::set<EDA_ITEM*>::iterator; |
|||
using CITER = std::set<EDA_ITEM*>::const_iterator; |
|||
|
|||
ITER begin() { return m_items.begin(); } |
|||
ITER end() { return m_items.end(); } |
|||
CITER begin() const { return m_items.cbegin(); } |
|||
CITER end() const { return m_items.cend(); } |
|||
|
|||
virtual void Add( EDA_ITEM* aItem ) |
|||
{ |
|||
m_items.insert( aItem ); |
|||
} |
|||
|
|||
virtual void Remove( EDA_ITEM *aItem ) |
|||
{ |
|||
m_items.erase( aItem ); |
|||
} |
|||
|
|||
virtual void Clear() override |
|||
{ |
|||
m_items.clear(); |
|||
} |
|||
|
|||
virtual unsigned int GetSize() const override |
|||
{ |
|||
return m_items.size(); |
|||
} |
|||
|
|||
virtual KIGFX::VIEW_ITEM* GetItem( unsigned int idx ) const override |
|||
{ |
|||
auto iter = m_items.begin(); |
|||
|
|||
std::advance( iter, idx ); |
|||
|
|||
return *iter; |
|||
} |
|||
|
|||
bool Contains( EDA_ITEM* aItem ) const |
|||
{ |
|||
return m_items.find( aItem ) != m_items.end(); |
|||
} |
|||
|
|||
/// Checks if there is anything selected |
|||
bool Empty() const |
|||
{ |
|||
return ( m_items.size() == 0 ); |
|||
} |
|||
|
|||
/// Returns the number of selected parts |
|||
int Size() const |
|||
{ |
|||
return m_items.size(); |
|||
} |
|||
|
|||
const std::set<EDA_ITEM*> GetItems() const |
|||
{ |
|||
return m_items; |
|||
} |
|||
|
|||
/// Returns the center point of the selection area bounding box. |
|||
VECTOR2I GetCenter() const; |
|||
|
|||
EDA_ITEM* operator[]( const int index ) const |
|||
{ |
|||
if( index < 0 || (unsigned int) index >= m_items.size() ) |
|||
return nullptr; |
|||
|
|||
auto iter = m_items.begin(); |
|||
std::advance( iter, index ); |
|||
return *iter; |
|||
} |
|||
|
|||
EDA_ITEM* Front() const |
|||
{ |
|||
if ( !m_items.size() ) |
|||
return nullptr; |
|||
|
|||
return *m_items.begin(); |
|||
} |
|||
|
|||
std::set<EDA_ITEM*>& Items() |
|||
{ |
|||
return m_items; |
|||
} |
|||
|
|||
virtual const VIEW_GROUP::ITEMS updateDrawList() const override; |
|||
|
|||
private: |
|||
/// Set of selected items |
|||
std::set<EDA_ITEM*> m_items; |
|||
|
|||
// mute hidden overloaded virtual function warnings |
|||
using VIEW_GROUP::Add; |
|||
using VIEW_GROUP::Remove; |
|||
}; |
|||
|
|||
enum SELECTION_LOCK_FLAGS |
|||
{ |
|||
SELECTION_UNLOCKED = 0, |
|||
SELECTION_LOCK_OVERRIDE = 1, |
|||
SELECTION_LOCKED = 2 |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,127 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2014 CERN |
|||
* @author Maciej Suminski <maciej.suminski@cern.ch> |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include "pcb_selection_conditions.h"
|
|||
#include "selection_tool.h"
|
|||
#include <class_board_connected_item.h>
|
|||
|
|||
#include <functional>
|
|||
using namespace std::placeholders; |
|||
|
|||
|
|||
bool PCB_SELECTION_CONDITIONS::OnlyConnectedItems( const SELECTION& aSelection ) |
|||
{ |
|||
if( aSelection.Empty() ) |
|||
return false; |
|||
|
|||
for( const auto &item : aSelection ) |
|||
{ |
|||
auto type = item->Type(); |
|||
|
|||
if( type != PCB_PAD_T && type != PCB_VIA_T && type != PCB_TRACE_T && type != PCB_ZONE_T ) |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
SELECTION_CONDITION PCB_SELECTION_CONDITIONS::SameNet( bool aAllowUnconnected ) |
|||
{ |
|||
return std::bind( &PCB_SELECTION_CONDITIONS::sameNetFunc, _1, aAllowUnconnected ); |
|||
} |
|||
|
|||
|
|||
SELECTION_CONDITION PCB_SELECTION_CONDITIONS::SameLayer() |
|||
{ |
|||
return std::bind( &PCB_SELECTION_CONDITIONS::sameLayerFunc, _1 ); |
|||
} |
|||
|
|||
|
|||
|
|||
bool PCB_SELECTION_CONDITIONS::sameNetFunc( const SELECTION& aSelection, bool aAllowUnconnected ) |
|||
{ |
|||
if( aSelection.Empty() ) |
|||
return false; |
|||
|
|||
int netcode = -1; // -1 stands for 'net code is not yet determined'
|
|||
|
|||
for( const auto& aitem : aSelection ) |
|||
{ |
|||
int current_netcode = -1; |
|||
|
|||
const BOARD_CONNECTED_ITEM* item = |
|||
dynamic_cast<const BOARD_CONNECTED_ITEM*>( aitem ); |
|||
|
|||
if( item ) |
|||
{ |
|||
current_netcode = item->GetNetCode(); |
|||
} |
|||
else |
|||
{ |
|||
if( !aAllowUnconnected ) |
|||
return false; |
|||
else |
|||
// if it is not a BOARD_CONNECTED_ITEM, treat it as if there was no net assigned
|
|||
current_netcode = 0; |
|||
} |
|||
|
|||
assert( current_netcode >= 0 ); |
|||
|
|||
if( netcode < 0 ) |
|||
{ |
|||
netcode = current_netcode; |
|||
|
|||
if( netcode == NETINFO_LIST::UNCONNECTED && !aAllowUnconnected ) |
|||
return false; |
|||
} |
|||
else if( netcode != current_netcode ) |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
bool PCB_SELECTION_CONDITIONS::sameLayerFunc( const SELECTION& aSelection ) |
|||
{ |
|||
if( aSelection.Empty() ) |
|||
return false; |
|||
|
|||
LSET layerSet; |
|||
layerSet.set(); |
|||
|
|||
for( const auto& i : aSelection ) |
|||
{ |
|||
auto item = static_cast<BOARD_ITEM*>( i ); |
|||
layerSet &= item->GetLayerSet(); |
|||
|
|||
if( !layerSet.any() ) // there are no common layers left
|
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2014 CERN |
|||
* @author Maciej Suminski <maciej.suminski@cern.ch> |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef PCB_SELECTION_CONDITIONS_H_ |
|||
#define PCB_SELECTION_CONDITIONS_H_ |
|||
|
|||
#include <tool/selection.h> |
|||
#include <tool/selection_conditions.h> |
|||
#include <class_board_item.h> |
|||
|
|||
|
|||
class PCB_SELECTION_CONDITIONS : public SELECTION_CONDITIONS |
|||
{ |
|||
public: |
|||
/** |
|||
* Function OnlyConnectedItems |
|||
* Tests if selection contains exclusively connected items (pads, tracks, vias, zones). |
|||
* @param aSelection is the selection to be tested. |
|||
* @return True if there are only connected items connected. |
|||
*/ |
|||
static bool OnlyConnectedItems( const SELECTION& aSelection ); |
|||
|
|||
/** |
|||
* Function SameNet |
|||
* Creates a functor that tests if selection contains items belonging to the same net or are |
|||
* unconnected if aAllowUnconnected == true. |
|||
* @param aAllowUnconnected determines if unconnected items (with no net code assigned) should |
|||
* be treated as connected to the same net. |
|||
* @return Functor testing if selected items are belonging to the same net. |
|||
*/ |
|||
static SELECTION_CONDITION SameNet( bool aAllowUnconnected = false ); |
|||
|
|||
/** |
|||
* Function SameLayer |
|||
* Creates a functor that tests if selection contains items that belong exclusively to the same |
|||
* layer. In case of items belonging to multiple layers, it is enough to have a single common |
|||
* layer with other items. |
|||
* @return Functor testing if selected items share at least one common layer. |
|||
*/ |
|||
static SELECTION_CONDITION SameLayer(); |
|||
|
|||
|
|||
private: |
|||
///> Helper function used by SameNet() |
|||
static bool sameNetFunc( const SELECTION& aSelection, bool aAllowUnconnected ); |
|||
|
|||
///> Helper function used by SameLayer() |
|||
static bool sameLayerFunc( const SELECTION& aSelection ); |
|||
}; |
|||
|
|||
#endif /* PCB_SELECTION_CONDITIONS_H_ */ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue