Commit 235da608 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

SELECTION_TOOL emits event notifying about selecting/deselecting/clearing selection.

parent e6598e9d
Loading
Loading
Loading
Loading
+37 −4
Original line number Original line Diff line number Diff line
@@ -50,7 +50,11 @@
using boost::optional;
using boost::optional;


SELECTION_TOOL::SELECTION_TOOL() :
SELECTION_TOOL::SELECTION_TOOL() :
    TOOL_INTERACTIVE( "pcbnew.InteractiveSelection" ), m_additive( false ), m_multiple( false )
        TOOL_INTERACTIVE( "pcbnew.InteractiveSelection" ),
        SelectedEvent( TC_MESSAGE, TA_ACTION, "pcbnew.InteractiveSelection.selected" ),
        DeselectedEvent( TC_MESSAGE, TA_ACTION, "pcbnew.InteractiveSelection.deselected" ),
        ClearedEvent( TC_MESSAGE, TA_ACTION, "pcbnew.InteractiveSelection.cleared" ),
        m_additive( false ), m_multiple( false )
{
{
    m_selArea = new SELECTION_AREA;
    m_selArea = new SELECTION_AREA;
    m_selection.group = new KIGFX::VIEW_GROUP;
    m_selection.group = new KIGFX::VIEW_GROUP;
@@ -94,6 +98,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )


        if( evt->IsAction( &COMMON_ACTIONS::selectionSingle ) )
        if( evt->IsAction( &COMMON_ACTIONS::selectionSingle ) )
        {
        {
            // GetMousePosition() is used to be independent of snapping settings
            selectSingle( getView()->ToWorld( getViewControls()->GetMousePosition() ) );
            selectSingle( getView()->ToWorld( getViewControls()->GetMousePosition() ) );
        }
        }


@@ -167,6 +172,10 @@ void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem )
    if( aItem->IsSelected() )
    if( aItem->IsSelected() )
    {
    {
        deselect( aItem );
        deselect( aItem );

        // Inform other potentially interested tools
        TOOL_EVENT deselectEvent( DeselectedEvent );
        m_toolMgr->ProcessEvent( deselectEvent );
    }
    }
    else
    else
    {
    {
@@ -175,7 +184,13 @@ void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem )


        // Prevent selection of invisible or inactive items
        // Prevent selection of invisible or inactive items
        if( selectable( aItem ) )
        if( selectable( aItem ) )
        {
            select( aItem );
            select( aItem );

            // Inform other potentially interested tools
            TOOL_EVENT selectEvent( SelectedEvent );
            m_toolMgr->ProcessEvent( selectEvent );
        }
    }
    }
}
}


@@ -273,13 +288,21 @@ bool SELECTION_TOOL::selectMultiple()
                BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
                BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );


                // Add only those items that are visible and fully within the selection box
                // Add only those items that are visible and fully within the selection box
                if( !item->IsSelected() && selectable( item ) && selectionBox.Contains( item->ViewBBox() ) )
                if( !item->IsSelected() && selectable( item )
                        && selectionBox.Contains( item->ViewBBox() ) )
                    select( item );
                    select( item );
            }
            }


            // Do not display information about selected item,as there is more than one
            // Do not display information about selected item,as there is more than one
            getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( NULL );
            getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( NULL );


            if( !m_selection.Empty() )
            {
                // Inform other potentially interested tools
                TOOL_EVENT selectEvent( SelectedEvent );
                m_toolMgr->ProcessEvent( selectEvent );
            }

            break;  // Stop waiting for events
            break;  // Stop waiting for events
        }
        }
    }
    }
@@ -313,6 +336,10 @@ void SELECTION_TOOL::clearSelection()


    // Do not show the context menu when there is nothing selected
    // Do not show the context menu when there is nothing selected
    SetContextMenu( &m_menu, CMENU_OFF );
    SetContextMenu( &m_menu, CMENU_OFF );

    // Inform other potentially interested tools
    TOOL_EVENT clearEvent( ClearedEvent );
    m_toolMgr->ProcessEvent( clearEvent );
}
}




@@ -351,8 +378,10 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector )
                current->SetBrightened();
                current->SetBrightened();
            }
            }
            else
            else
            {
                current = NULL;
                current = NULL;
            }
            }
        }
        else if( evt->Action() == TA_CONTEXT_MENU_CHOICE )
        else if( evt->Action() == TA_CONTEXT_MENU_CHOICE )
        {
        {
            optional<int> id = evt->GetCommandId();
            optional<int> id = evt->GetCommandId();
@@ -543,6 +572,10 @@ void SELECTION_TOOL::deselect( BOARD_ITEM* aItem )
        SetContextMenu( &m_menu, CMENU_OFF );
        SetContextMenu( &m_menu, CMENU_OFF );
        getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( NULL );
        getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( NULL );
    }
    }

    // Inform other potentially interested tools
    TOOL_EVENT dupa( DeselectedEvent );
    m_toolMgr->ProcessEvent( dupa );
}
}




+5 −0
Original line number Original line Diff line number Diff line
@@ -114,6 +114,11 @@ public:
     */
     */
    void AddMenuItem( const TOOL_ACTION& aAction );
    void AddMenuItem( const TOOL_ACTION& aAction );


    // TODO comments
    const TOOL_EVENT SelectedEvent;
    const TOOL_EVENT DeselectedEvent;
    const TOOL_EVENT ClearedEvent;

private:
private:
    /**
    /**
     * Function selectSingle()
     * Function selectSingle()