Commit 433e17a5 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Support for "locked" property for modules (GAL).

parent c1eda6b8
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -158,6 +158,9 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
            }
            }
            else    // Prepare to start dragging
            else    // Prepare to start dragging
            {
            {
                if( m_selectionTool->CheckLock() )
                    break;

                // Save items, so changes can be undone
                // Save items, so changes can be undone
                editFrame->OnModify();
                editFrame->OnModify();
                editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
                editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
@@ -298,7 +301,7 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
    // Shall the selection be cleared at the end?
    // Shall the selection be cleared at the end?
    bool unselect = selection.Empty();
    bool unselect = selection.Empty();


    if( !makeSelection( selection ) )
    if( !makeSelection( selection ) || m_selectionTool->CheckLock() )
    {
    {
        setTransitions();
        setTransitions();


@@ -352,7 +355,7 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent )
    // Shall the selection be cleared at the end?
    // Shall the selection be cleared at the end?
    bool unselect = selection.Empty();
    bool unselect = selection.Empty();


    if( !makeSelection( selection ) )
    if( !makeSelection( selection ) || m_selectionTool->CheckLock() )
    {
    {
        setTransitions();
        setTransitions();


@@ -402,7 +405,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent )
{
{
    const SELECTION& selection = m_selectionTool->GetSelection();
    const SELECTION& selection = m_selectionTool->GetSelection();


    if( !makeSelection( selection ) )
    if( !makeSelection( selection ) || m_selectionTool->CheckLock() )
    {
    {
        setTransitions();
        setTransitions();


+54 −5
Original line number Original line Diff line number Diff line
@@ -25,9 +25,7 @@


#include <boost/foreach.hpp>
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
#include <boost/bind.hpp>
#include <cassert>


#include <class_draw_panel_gal.h>
#include <class_board.h>
#include <class_board.h>
#include <class_board_item.h>
#include <class_board_item.h>
#include <class_track.h>
#include <class_track.h>
@@ -35,6 +33,9 @@


#include <wxPcbStruct.h>
#include <wxPcbStruct.h>
#include <collectors.h>
#include <collectors.h>
#include <confirm.h>

#include <class_draw_panel_gal.h>
#include <view/view_controls.h>
#include <view/view_controls.h>
#include <view/view_group.h>
#include <view/view_group.h>
#include <painter.h>
#include <painter.h>
@@ -52,7 +53,8 @@ SELECTION_TOOL::SELECTION_TOOL() :
        SelectedEvent( TC_MESSAGE, TA_ACTION, "pcbnew.InteractiveSelection.selected" ),
        SelectedEvent( TC_MESSAGE, TA_ACTION, "pcbnew.InteractiveSelection.selected" ),
        DeselectedEvent( TC_MESSAGE, TA_ACTION, "pcbnew.InteractiveSelection.deselected" ),
        DeselectedEvent( TC_MESSAGE, TA_ACTION, "pcbnew.InteractiveSelection.deselected" ),
        ClearedEvent( TC_MESSAGE, TA_ACTION, "pcbnew.InteractiveSelection.cleared" ),
        ClearedEvent( TC_MESSAGE, TA_ACTION, "pcbnew.InteractiveSelection.cleared" ),
        m_frame( NULL ), m_additive( false ), m_multiple( false ), m_editModules( false )
        m_frame( NULL ), m_additive( false ), m_multiple( false ),
        m_editModules( false ), m_locked( true )
{
{
    m_selArea = new SELECTION_AREA;
    m_selArea = new SELECTION_AREA;
    m_selection.group = new KIGFX::VIEW_GROUP;
    m_selection.group = new KIGFX::VIEW_GROUP;
@@ -77,6 +79,7 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason )
        clearSelection();
        clearSelection();


    m_frame = getEditFrame<PCB_BASE_FRAME>();
    m_frame = getEditFrame<PCB_BASE_FRAME>();
    m_locked = true;


    // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
    // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
    getView()->Remove( m_selection.group );
    getView()->Remove( m_selection.group );
@@ -384,6 +387,48 @@ void SELECTION_TOOL::setTransitions()
}
}




bool SELECTION_TOOL::CheckLock()
{
    if( !m_locked )
        return false;

    bool containsLocked = false;

    // Check if the selection contains locked items
    for( int i = 0; i < m_selection.Size(); ++i )
    {
        BOARD_ITEM* item = m_selection.Item<BOARD_ITEM>( i );

        switch( item->Type() )
        {
        case PCB_MODULE_T:
            if( static_cast<MODULE*>( item )->IsLocked() )
                containsLocked = true;
            break;

        case PCB_MODULE_EDGE_T:
        case PCB_MODULE_TEXT_T:
            if( static_cast<MODULE*>( item->GetParent() )->IsLocked() )
                containsLocked = true;
            break;

        default:    // suppress warnings
            break;
        }
    }

    if( containsLocked &&
        !IsOK( m_frame, _( "Selection contains locked items. Do you want to continue?" ) ) )
    {
        return true;
    }

    m_locked = false;

    return false;
}


int SELECTION_TOOL::SingleSelection( TOOL_EVENT& aEvent )
int SELECTION_TOOL::SingleSelection( TOOL_EVENT& aEvent )
{
{
    selectSingle( getView()->ToWorld( getViewControls()->GetMousePosition() ) );
    selectSingle( getView()->ToWorld( getViewControls()->GetMousePosition() ) );
@@ -419,7 +464,8 @@ void SELECTION_TOOL::clearSelection()
    }
    }
    m_selection.clear();
    m_selection.clear();


    getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( NULL );
    m_frame->SetCurItem( NULL );
    m_locked = true;


    // Inform other potentially interested tools
    // Inform other potentially interested tools
    TOOL_EVENT clearEvent( ClearedEvent );
    TOOL_EVENT clearEvent( ClearedEvent );
@@ -650,7 +696,10 @@ void SELECTION_TOOL::deselect( BOARD_ITEM* aItem )
        m_selection.items.RemovePicker( itemIdx );
        m_selection.items.RemovePicker( itemIdx );


    if( m_selection.Empty() )
    if( m_selection.Empty() )
    {
        m_frame->SetCurItem( NULL );
        m_frame->SetCurItem( NULL );
        m_locked = true;
    }


    // Inform other potentially interested tools
    // Inform other potentially interested tools
    TOOL_EVENT deselected( DeselectedEvent );
    TOOL_EVENT deselected( DeselectedEvent );
+12 −6
Original line number Original line Diff line number Diff line
@@ -148,6 +148,15 @@ public:
        m_editModules = aEnabled;
        m_editModules = aEnabled;
    }
    }


    ///> Checks if the user has agreed to modify locked items for the given selection.
    bool CheckLock();

    ///> Select single item event handler.
    int SingleSelection( TOOL_EVENT& aEvent );

    ///> Clear current selection event handler.
    int ClearSelection( TOOL_EVENT& aEvent );

    ///> Event sent after an item is selected.
    ///> Event sent after an item is selected.
    const TOOL_EVENT SelectedEvent;
    const TOOL_EVENT SelectedEvent;


@@ -157,12 +166,6 @@ public:
    ///> Event sent after selection is cleared.
    ///> Event sent after selection is cleared.
    const TOOL_EVENT ClearedEvent;
    const TOOL_EVENT ClearedEvent;


    ///> Select single item event handler.
    int SingleSelection( TOOL_EVENT& aEvent );

    ///> Clear current selection event handler.
    int ClearSelection( TOOL_EVENT& aEvent );

private:
private:
    /**
    /**
     * Function selectSingle()
     * Function selectSingle()
@@ -313,6 +316,9 @@ private:
    /// Edit module mode flag.
    /// Edit module mode flag.
    bool m_editModules;
    bool m_editModules;


    /// Can other tools modify locked items.
    bool m_locked;

    /// Conditions for specific context menu entries.
    /// Conditions for specific context menu entries.
    std::deque<SELECTION_CONDITION> m_menuConditions;
    std::deque<SELECTION_CONDITION> m_menuConditions;
};
};