Exemplo n.º 1
0
bool EDIT_TOOL::makeSelection( const SELECTION& aSelection )
{
    if( aSelection.Empty() )                        // Try to find an item that could be modified
        m_toolMgr->RunAction( COMMON_ACTIONS::selectionSingle, true );

    return !aSelection.Empty();
}
bool SELECTION_CONDITIONS::sameNetFunc( const SELECTION& aSelection )
{
    if( aSelection.Empty() )
        return false;

    int netcode = -1;

    for( int i = 0; i < aSelection.Size(); ++i )
    {
        const BOARD_CONNECTED_ITEM* item =
            dynamic_cast<const BOARD_CONNECTED_ITEM*>( aSelection.Item<EDA_ITEM>( i ) );

        if( !item )
            return false;

        if( netcode < 0 )
        {
            netcode = item->GetNetCode();

            if( netcode == NETINFO_LIST::UNCONNECTED )
                return false;
        }
        else if( netcode != item->GetNetCode() )
        {
            return false;
        }
    }

    return true;
}
Exemplo n.º 3
0
bool EDIT_TOOL::hoverSelection( const SELECTION& aSelection, bool aSanitize )
{
    if( aSelection.Empty() )                        // Try to find an item that could be modified
    {
        m_toolMgr->RunAction( COMMON_ACTIONS::selectionCursor, true );

        if( m_selectionTool->CheckLock() == SELECTION_LOCKED )
        {
            m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
            return false;
        }
    }

    if( aSanitize )
        m_selectionTool->SanitizeSelection();

    if( aSelection.Empty() )        // TODO is it necessary?
        m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );

    return !aSelection.Empty();
}
bool SELECTION_CONDITIONS::onlyTypeFunc( const SELECTION& aSelection, KICAD_T aType )
{
    if( aSelection.Empty() )
        return false;

    for( int i = 0; i < aSelection.Size(); ++i )
    {
        if( aSelection.Item<EDA_ITEM>( i )->Type() != aType )
            return false;
    }

    return true;
}
bool SELECTION_CONDITIONS::OnlyConnectedItems( const SELECTION& aSelection )
{
    if( aSelection.Empty() )
        return false;

    for( int i = 0; i < aSelection.Size(); ++i )
    {
        KICAD_T type = aSelection.Item<EDA_ITEM>( i )->Type();

        if( type != PCB_PAD_T && type != PCB_VIA_T && type != PCB_TRACE_T && type != PCB_ZONE_T )
            return false;
    }

    return true;
}
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_AREA_T )
            return false;
    }

    return true;
}
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;
}
bool SELECTION_CONDITIONS::sameLayerFunc( const SELECTION& aSelection )
{
    if( aSelection.Empty() )
        return false;

    LSET layerSet;
    layerSet.set();

    for( int i = 0; i < aSelection.Size(); ++i )
    {
        const BOARD_ITEM* item = dynamic_cast<const BOARD_ITEM*>( aSelection.Item<EDA_ITEM>( i ) );

        if( !item )
            return false;

        layerSet &= item->GetLayerSet();

        if( !layerSet.any() )       // there are no common layers left
            return false;
    }

    return true;
}
bool SELECTION_CONDITIONS::onlyTypesFunc( const SELECTION& aSelection, const std::vector<KICAD_T>& aTypes )
{
    if( aSelection.Empty() )
        return false;

    for( int i = 0; i < aSelection.Size(); ++i )
    {
        bool valid = false;

        for( std::vector<KICAD_T>::const_iterator it = aTypes.begin(); it != aTypes.end(); ++it )
        {
            if( aSelection.Item<EDA_ITEM>( i )->Type() == *it )
            {
                valid = true;
                break;
            }
        }

        if( !valid )
            return false;
    }

    return true;
}
bool SELECTION_CONDITIONS::NotEmpty( const SELECTION& aSelection )
{
    return !aSelection.Empty();
}