From f3bdc29e8eb68e311e12d483ad59acd6cdc4aae9 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 16:50:31 +0200 Subject: [PATCH] Support for "locked" property for modules (GAL). --- pcbnew/tools/edit_tool.cpp | 9 +++-- pcbnew/tools/selection_tool.cpp | 59 ++++++++++++++++++++++++++++++--- pcbnew/tools/selection_tool.h | 18 ++++++---- 3 files changed, 72 insertions(+), 14 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index da350c4aa8..9b5924327e 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -158,6 +158,9 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) } else // Prepare to start dragging { + if( m_selectionTool->CheckLock() ) + break; + // Save items, so changes can be undone editFrame->OnModify(); 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? bool unselect = selection.Empty(); - if( !makeSelection( selection ) ) + if( !makeSelection( selection ) || m_selectionTool->CheckLock() ) { setTransitions(); @@ -352,7 +355,7 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) // Shall the selection be cleared at the end? bool unselect = selection.Empty(); - if( !makeSelection( selection ) ) + if( !makeSelection( selection ) || m_selectionTool->CheckLock() ) { setTransitions(); @@ -402,7 +405,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); - if( !makeSelection( selection ) ) + if( !makeSelection( selection ) || m_selectionTool->CheckLock() ) { setTransitions(); diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index b281091923..303dd30987 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -25,9 +25,7 @@ #include #include -#include -#include #include #include #include @@ -35,6 +33,9 @@ #include #include +#include + +#include #include #include #include @@ -52,7 +53,8 @@ SELECTION_TOOL::SELECTION_TOOL() : 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_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_selection.group = new KIGFX::VIEW_GROUP; @@ -77,6 +79,7 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason ) clearSelection(); m_frame = getEditFrame(); + m_locked = true; // Reinsert the VIEW_GROUP, in case it was removed from the VIEW 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( i ); + + switch( item->Type() ) + { + case PCB_MODULE_T: + if( static_cast( item )->IsLocked() ) + containsLocked = true; + break; + + case PCB_MODULE_EDGE_T: + case PCB_MODULE_TEXT_T: + if( static_cast( 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 ) { selectSingle( getView()->ToWorld( getViewControls()->GetMousePosition() ) ); @@ -419,7 +464,8 @@ void SELECTION_TOOL::clearSelection() } m_selection.clear(); - getEditFrame()->SetCurItem( NULL ); + m_frame->SetCurItem( NULL ); + m_locked = true; // Inform other potentially interested tools TOOL_EVENT clearEvent( ClearedEvent ); @@ -650,7 +696,10 @@ void SELECTION_TOOL::deselect( BOARD_ITEM* aItem ) m_selection.items.RemovePicker( itemIdx ); if( m_selection.Empty() ) + { m_frame->SetCurItem( NULL ); + m_locked = true; + } // Inform other potentially interested tools TOOL_EVENT deselected( DeselectedEvent ); @@ -772,7 +821,7 @@ void SELECTION_TOOL::generateMenu() } if( m_menuCopy.GetMenuItemCount() > 0 ) - SetContextMenu( &m_menuCopy, CMENU_NOW ); + SetContextMenu( &m_menuCopy, CMENU_NOW ); } diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 06a0af35e6..beceefee5d 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -148,6 +148,15 @@ public: 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. const TOOL_EVENT SelectedEvent; @@ -157,12 +166,6 @@ public: ///> Event sent after selection is cleared. 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: /** * Function selectSingle() @@ -313,6 +316,9 @@ private: /// Edit module mode flag. bool m_editModules; + /// Can other tools modify locked items. + bool m_locked; + /// Conditions for specific context menu entries. std::deque m_menuConditions; };