From ce8f4006452d020d6513dfd9032bac648dc45262 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 9 May 2016 10:29:06 +0200 Subject: [PATCH] Added menu for locking tracks & vias (GAL). --- include/class_board_item.h | 12 ++++- pcbnew/class_module.h | 6 +-- pcbnew/class_track.h | 3 ++ pcbnew/tools/common_actions.cpp | 12 ++++- pcbnew/tools/common_actions.h | 6 ++- pcbnew/tools/pcb_editor_control.cpp | 74 +++++++++++++++++++++++++---- pcbnew/tools/pcb_editor_control.h | 17 ++++++- 7 files changed, 112 insertions(+), 18 deletions(-) diff --git a/include/class_board_item.h b/include/class_board_item.h index 7b202ffadd..e532b5d112 100644 --- a/include/class_board_item.h +++ b/include/class_board_item.h @@ -199,7 +199,17 @@ public: */ virtual bool IsLocked() const { - return false; // only MODULEs can be locked at this time. + // only MODULEs & TRACKs can be locked at this time. + return false; + } + + /** + * Function SetLocked + * modifies 'lock' status for of the item. + */ + virtual void SetLocked( bool aLocked ) + { + // only MODULEs & TRACKs can be locked at this time. } /** diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index e0b269bbf5..8d5c59b463 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -238,9 +238,9 @@ public: #define MODULE_PADS_LOCKED 0x08 ///< In autoplace: module waiting for autoplace - bool IsLocked() const + bool IsLocked() const override { - return (m_ModuleStatus & MODULE_is_LOCKED) != 0; + return ( m_ModuleStatus & MODULE_is_LOCKED ) != 0; } /** @@ -248,7 +248,7 @@ public: * sets the MODULE_is_LOCKED bit in the m_ModuleStatus * @param isLocked When true means turn on locked status, else unlock */ - void SetLocked( bool isLocked ) + void SetLocked( bool isLocked ) override { if( isLocked ) m_ModuleStatus |= MODULE_is_LOCKED; diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index fd37d95675..ad171c356f 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -132,6 +132,9 @@ public: // Virtual function const EDA_RECT GetBoundingBox() const; + bool IsLocked() const override { return GetState( TRACK_LOCKED ); } + void SetLocked( bool aLocked ) override { return SetState( TRACK_LOCKED, aLocked ); } + /** * Function GetBestInsertPoint * searches the "best" insertion point within the track linked list. diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index f452719f66..ca057b3a51 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -399,9 +399,17 @@ TOOL_ACTION COMMON_ACTIONS::crossProbeSchToPcb( "pcbnew.EditorControl.crossProbS AS_GLOBAL, 0, "", "" ); -TOOL_ACTION COMMON_ACTIONS::toggleLockModule( "pcbnew.EditorControl.toggleLockModule", +TOOL_ACTION COMMON_ACTIONS::toggleLock( "pcbnew.EditorControl.toggleLock", AS_GLOBAL, 'L', - "", "" ); + "Toggle lock", "" ); + +TOOL_ACTION COMMON_ACTIONS::lock( "pcbnew.EditorControl.lock", + AS_GLOBAL, 0, + _( "Lock" ), "" ); + +TOOL_ACTION COMMON_ACTIONS::unlock( "pcbnew.EditorControl.unlock", + AS_GLOBAL, 0, + _( "Unlock" ), "" ); TOOL_ACTION COMMON_ACTIONS::appendBoard( "pcbnew.EditorControl.appendBoard", AS_GLOBAL, 0, diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index fbedcdc2e7..dfc88a19c6 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -290,6 +290,11 @@ public: static TOOL_ACTION panLeft; static TOOL_ACTION panRight; + // Locking + static TOOL_ACTION toggleLock; + static TOOL_ACTION lock; + static TOOL_ACTION unlock; + // Miscellaneous static TOOL_ACTION selectionTool; static TOOL_ACTION pickerTool; @@ -301,7 +306,6 @@ public: static TOOL_ACTION highlightNetCursor; static TOOL_ACTION drillOrigin; static TOOL_ACTION crossProbeSchToPcb; - static TOOL_ACTION toggleLockModule; static TOOL_ACTION appendBoard; static TOOL_ACTION showHelp; static TOOL_ACTION toBeDone; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 15a0fc67b6..90699b1a99 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -81,6 +81,19 @@ private: }; +class LOCK_CONTEXT_MENU : public CONTEXT_MENU +{ +public: + LOCK_CONTEXT_MENU() + { + SetIcon( locked_xpm ); + Add( COMMON_ACTIONS::lock ); + Add( COMMON_ACTIONS::unlock ); + Add( COMMON_ACTIONS::toggleLock ); + } +}; + + PCB_EDITOR_CONTROL::PCB_EDITOR_CONTROL() : TOOL_INTERACTIVE( "pcbnew.EditorControl" ), m_frame( NULL ), m_zoneMenu( NULL ) { @@ -94,6 +107,7 @@ PCB_EDITOR_CONTROL::~PCB_EDITOR_CONTROL() { delete m_placeOrigin; delete m_zoneMenu; + delete m_lockMenu; } @@ -120,6 +134,11 @@ bool PCB_EDITOR_CONTROL::Init() m_zoneMenu->SetTool( this ); selTool->GetMenu().AddMenu( m_zoneMenu, _( "Zones" ), false, SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) ); + + m_lockMenu = new LOCK_CONTEXT_MENU; + m_lockMenu->SetTool( this ); + selTool->GetMenu().AddMenu( m_lockMenu, _( "Locking" ), false, + SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); } return true; @@ -319,26 +338,61 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) } -int PCB_EDITOR_CONTROL::ToggleLockModule( const TOOL_EVENT& aEvent ) +int PCB_EDITOR_CONTROL::ToggleLockSelected( const TOOL_EVENT& aEvent ) +{ + return modifyLockSelected( TOGGLE ); +} + + +int PCB_EDITOR_CONTROL::LockSelected( const TOOL_EVENT& aEvent ) +{ + return modifyLockSelected( ON ); +} + + +int PCB_EDITOR_CONTROL::UnlockSelected( const TOOL_EVENT& aEvent ) +{ + return modifyLockSelected( OFF ); +} + + +int PCB_EDITOR_CONTROL::modifyLockSelected( MODIFY_MODE aMode ) { SELECTION_TOOL* selTool = m_toolMgr->GetTool(); const SELECTION& selection = selTool->GetSelection(); - bool clearSelection = selection.Empty(); - if( clearSelection ) + if( selection.Empty() ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionCursor, true ); + bool modified = false; + for( int i = 0; i < selection.Size(); ++i ) { - if( selection.Item( i )->Type() == PCB_MODULE_T ) + BOARD_ITEM* item = selection.Item( i ); + bool prevState = item->IsLocked(); + + switch( aMode ) { - MODULE* module = selection.Item( i ); - module->SetLocked( !module->IsLocked() ); + case ON: + item->SetLocked( true ); + break; + + case OFF: + item->SetLocked( false ); + break; + + case TOGGLE: + item->SetLocked( !prevState ); + break; } + + // Check if we really modified an item + if( !modified && prevState != item->IsLocked() ) + modified = true; } - if( clearSelection ) - m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); + if( modified ) + m_frame->OnModify(); return 0; } @@ -780,7 +834,9 @@ void PCB_EDITOR_CONTROL::SetTransitions() Go( &PCB_EDITOR_CONTROL::PlaceModule, COMMON_ACTIONS::placeModule.MakeEvent() ); // Other - Go( &PCB_EDITOR_CONTROL::ToggleLockModule, COMMON_ACTIONS::toggleLockModule.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::ToggleLockSelected, COMMON_ACTIONS::toggleLock.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::LockSelected, COMMON_ACTIONS::lock.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::UnlockSelected, COMMON_ACTIONS::unlock.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::CrossProbePcbToSch, SELECTION_TOOL::SelectedEvent ); Go( &PCB_EDITOR_CONTROL::CrossProbeSchToPcb, COMMON_ACTIONS::crossProbeSchToPcb.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::DrillOrigin, COMMON_ACTIONS::drillOrigin.MakeEvent() ); diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index 51de40272a..c7119d826a 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -33,6 +33,7 @@ namespace KIGFX { class PCB_EDIT_FRAME; class ZONE_CONTEXT_MENU; +class LOCK_CONTEXT_MENU; /** * Class PCB_EDITOR_CONTROL @@ -76,8 +77,14 @@ public: */ int PlaceModule( const TOOL_EVENT& aEvent ); - ///> (Un)locks module. - int ToggleLockModule( const TOOL_EVENT& aEvent ); + ///> Toggles 'lock' property for selected items. + int ToggleLockSelected( const TOOL_EVENT& aEvent ); + + ///> Locks selected items. + int LockSelected( const TOOL_EVENT& aEvent ); + + ///> Unlocks selected items. + int UnlockSelected( const TOOL_EVENT& aEvent ); ///> Notifies eeschema about the selected item. int CrossProbePcbToSch( const TOOL_EVENT& aEvent ); @@ -107,10 +114,16 @@ private: ///> Flag to ignore a single crossprobe message from eeschema. bool m_probingSchToPcb; + ///> How to modify a property for selected items. + enum MODIFY_MODE { ON, OFF, TOGGLE }; + + int modifyLockSelected( MODIFY_MODE aMode ); + // How does line width change after one -/+ key press. static const int WIDTH_STEP; ZONE_CONTEXT_MENU* m_zoneMenu; + LOCK_CONTEXT_MENU* m_lockMenu; }; #endif