diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 6734765e32..79d2713579 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -73,7 +73,7 @@ private: // lines like this make me really think about a better name for SELECTION_CONDITIONS class bool mergeEnabled = ( SELECTION_CONDITIONS::MoreThan( 1 ) && /*SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) &&*/ - SELECTION_CONDITIONS::SameNet() && + SELECTION_CONDITIONS::SameNet( true ) && SELECTION_CONDITIONS::SameLayer() )( selTool->GetSelection() ); Enable( getMenuId( COMMON_ACTIONS::zoneMerge ), mergeEnabled ); diff --git a/pcbnew/tools/selection_conditions.cpp b/pcbnew/tools/selection_conditions.cpp index 31a8d1a544..7d860a41a6 100644 --- a/pcbnew/tools/selection_conditions.cpp +++ b/pcbnew/tools/selection_conditions.cpp @@ -52,9 +52,9 @@ bool SELECTION_CONDITIONS::OnlyConnectedItems( const SELECTION& aSelection ) } -SELECTION_CONDITION SELECTION_CONDITIONS::SameNet() +SELECTION_CONDITION SELECTION_CONDITIONS::SameNet( bool aAllowUnconnected ) { - return boost::bind( &SELECTION_CONDITIONS::sameNetFunc, _1 ); + return boost::bind( &SELECTION_CONDITIONS::sameNetFunc, _1, aAllowUnconnected ); } @@ -100,26 +100,40 @@ SELECTION_CONDITION SELECTION_CONDITIONS::LessThan( int aNumber ) } -bool SELECTION_CONDITIONS::sameNetFunc( const SELECTION& aSelection ) +bool SELECTION_CONDITIONS::sameNetFunc( const SELECTION& aSelection, bool aAllowUnconnected ) { if( aSelection.Empty() ) return false; - int netcode = -1; + int netcode = -1; // -1 stands for 'net code is not yet determined' for( int i = 0; i < aSelection.Size(); ++i ) { + int current_netcode = -1; + const BOARD_CONNECTED_ITEM* item = dynamic_cast( aSelection.Item( i ) ); - if( !item ) - return false; + 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 = item->GetNetCode(); + netcode = current_netcode; - if( netcode == NETINFO_LIST::UNCONNECTED ) + if( netcode == NETINFO_LIST::UNCONNECTED && !aAllowUnconnected ) return false; } else if( netcode != item->GetNetCode() ) diff --git a/pcbnew/tools/selection_conditions.h b/pcbnew/tools/selection_conditions.h index 715a4fab08..0c508a8971 100644 --- a/pcbnew/tools/selection_conditions.h +++ b/pcbnew/tools/selection_conditions.h @@ -76,14 +76,13 @@ public: /** * Function SameNet - * Creates a functor that tests if selection contains items belonging to the same net. If there - * are items which are not of BOARD_CONNECTED_ITEM type, the result is false. If all items do - * not have any net assigned, the result is negative (technically they have the same netcode, - * but in most cases they should not be connected together). - * @return Functor testing if selected items are exclusively connected items belonging to - * the same net (and netcode > 0). + * 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(); + static SELECTION_CONDITION SameNet( bool aAllowUnconnected = false ); /** * Function SameLayer @@ -146,7 +145,10 @@ public: static SELECTION_CONDITION LessThan( int aNumber ); private: - static bool sameNetFunc( const SELECTION& aSelection ); + ///> Helper function used by SameNet() + static bool sameNetFunc( const SELECTION& aSelection, bool aAllowUnconnected ); + + ///> Helper function used by SameLayer() static bool sameLayerFunc( const SELECTION& aSelection ); ///> Helper function used by HasType()