From c09dc5abdda3d7bb6e21b1574c1695828bf35884 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 11 Jan 2021 11:23:26 -0800 Subject: [PATCH] Prevent locking items in footprint editor Adding footprints to the board now has a preference for whether we want pads locked or unlocked by default --- .../dialog_graphic_item_properties.cpp | 4 + pcbnew/dialogs/dialog_pad_properties.cpp | 3 + pcbnew/dialogs/panel_edit_options.cpp | 3 + pcbnew/dialogs/panel_edit_options_base.cpp | 7 +- pcbnew/dialogs/panel_edit_options_base.fbp | 120 ++++++++++++++---- pcbnew/dialogs/panel_edit_options_base.h | 3 +- pcbnew/footprint_viewer_frame.cpp | 17 ++- pcbnew/pcbnew_settings.cpp | 4 + pcbnew/pcbnew_settings.h | 3 + pcbnew/tools/board_editor_control.cpp | 3 + pcbnew/tools/edit_tool.cpp | 18 +-- pcbnew/tools/placement_tool.cpp | 4 +- pcbnew/tools/position_relative_tool.cpp | 2 +- 13 files changed, 149 insertions(+), 42 deletions(-) diff --git a/pcbnew/dialogs/dialog_graphic_item_properties.cpp b/pcbnew/dialogs/dialog_graphic_item_properties.cpp index ace0ee540b..3b7db19055 100644 --- a/pcbnew/dialogs/dialog_graphic_item_properties.cpp +++ b/pcbnew/dialogs/dialog_graphic_item_properties.cpp @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -115,6 +116,9 @@ DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FR m_angleCtrl->SetValidator( m_AngleValidator ); m_AngleValidator.SetWindow( m_angleCtrl ); + // Do not allow locking items in the footprint editor + m_locked->Show( dynamic_cast( aParent ) != nullptr ); + // Configure the layers list selector if( m_fp_item ) { diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index 9ff944d2d0..47eb0f0086 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -188,6 +188,9 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, PAD* aPad m_staticTextInfoPosValue->SetFont( infoFont ); m_staticTextPrimitiveListWarning->SetFont( infoFont ); + // Do not allow locking items in the footprint editor + m_locked->Show( dynamic_cast( aParent ) != nullptr ); + // Usually, TransferDataToWindow is called by OnInitDialog // calling it here fixes all widget sizes so FinishDialogSettings can safely fix minsizes TransferDataToWindow(); diff --git a/pcbnew/dialogs/panel_edit_options.cpp b/pcbnew/dialogs/panel_edit_options.cpp index a4f32eca7b..536b194252 100644 --- a/pcbnew/dialogs/panel_edit_options.cpp +++ b/pcbnew/dialogs/panel_edit_options.cpp @@ -37,6 +37,7 @@ PANEL_EDIT_OPTIONS::PANEL_EDIT_OPTIONS( PCB_BASE_EDIT_FRAME* aFrame, PAGED_DIALO m_magneticPads->Show( dynamic_cast( m_frame ) != nullptr ); m_magneticGraphics->Show( dynamic_cast( m_frame ) != nullptr ); m_flipLeftRight->Show( dynamic_cast( m_frame ) != nullptr ); + m_addUnlockedPads->Show( dynamic_cast( m_frame ) != nullptr ); #ifdef __WXOSX_MAC__ m_mouseCmdsOSX->Show( true ); @@ -71,6 +72,7 @@ bool PANEL_EDIT_OPTIONS::TransferDataToWindow() m_magneticTrackChoice->SetSelection( static_cast( general_opts.m_MagneticItems.tracks ) ); m_magneticGraphicsChoice->SetSelection( !general_opts.m_MagneticItems.graphics ); m_flipLeftRight->SetValue( general_opts.m_FlipLeftRight ); + m_addUnlockedPads->SetValue( general_opts.m_AddUnlockedPads ); m_Show_Page_Limits->SetValue( m_frame->ShowPageLimits() ); @@ -115,6 +117,7 @@ bool PANEL_EDIT_OPTIONS::TransferDataFromWindow() m_frame->Settings().m_FlipLeftRight = m_flipLeftRight->GetValue(); m_frame->SetShowPageLimits( m_Show_Page_Limits->GetValue() ); + m_frame->Settings().m_AddUnlockedPads = m_addUnlockedPads->GetValue(); if( m_rbTrackDragMove->GetValue() ) pcbnewSettings.m_TrackDragAction = TRACK_DRAG_ACTION::MOVE; diff --git a/pcbnew/dialogs/panel_edit_options_base.cpp b/pcbnew/dialogs/panel_edit_options_base.cpp index 22dd886c69..20e17e780f 100644 --- a/pcbnew/dialogs/panel_edit_options_base.cpp +++ b/pcbnew/dialogs/panel_edit_options_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.9.0 Dec 30 2020) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -46,6 +46,11 @@ PANEL_EDIT_OPTIONS_BASE::PANEL_EDIT_OPTIONS_BASE( wxWindow* parent, wxWindowID i m_flipLeftRight = new wxCheckBox( bOptionsSizer->GetStaticBox(), wxID_ANY, _("Flip board items L/R (default is T/B)"), wxDefaultPosition, wxDefaultSize, 0 ); bOptionsSizer->Add( m_flipLeftRight, 0, wxALL, 5 ); + m_addUnlockedPads = new wxCheckBox( bOptionsSizer->GetStaticBox(), wxID_ANY, _("Add footprints with pads unlocked"), wxDefaultPosition, wxDefaultSize, 0 ); + m_addUnlockedPads->SetToolTip( _("If checked, when a footprint is added to the board, the pads will be freely moveable.") ); + + bOptionsSizer->Add( m_addUnlockedPads, 0, wxALL, 5 ); + wxFlexGridSizer* fgSizer12; fgSizer12 = new wxFlexGridSizer( 0, 2, 0, 0 ); fgSizer12->AddGrowableCol( 1 ); diff --git a/pcbnew/dialogs/panel_edit_options_base.fbp b/pcbnew/dialogs/panel_edit_options_base.fbp index 2f2bc429f0..347b8af60f 100644 --- a/pcbnew/dialogs/panel_edit_options_base.fbp +++ b/pcbnew/dialogs/panel_edit_options_base.fbp @@ -14,6 +14,7 @@ panel_edit_options_base 1000 none + 1 PanelEditOptions @@ -25,6 +26,7 @@ 1 1 UI + 0 1 0 @@ -370,6 +372,70 @@ + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Add footprints with pads unlocked + + 0 + + + 0 + + 1 + m_addLockedPads + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + If checked, when a footprint is added to the board, the pads will be freely moveable. + + wxFILTER_NONE + wxDefaultValidator + + + + + + 5 wxEXPAND|wxTOP @@ -2448,16 +2514,16 @@ wxTAB_TRAVERSAL - + pcbOptionsSizer wxVERTICAL none - + 5 wxEXPAND 1 - + wxID_ANY Magnetic Points @@ -2465,11 +2531,11 @@ wxVERTICAL 1 none - + 5 wxEXPAND|wxBOTTOM 1 - + 2 wxBOTH @@ -2860,11 +2926,11 @@ - + 5 wxEXPAND|wxTOP 1 - + wxID_ANY Ratsnest @@ -2872,11 +2938,11 @@ wxVERTICAL 1 none - + 5 wxBOTTOM|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -2936,11 +3002,11 @@ - + 5 wxBOTTOM|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -3002,11 +3068,11 @@ - + 5 wxEXPAND|wxTOP 0 - + wxID_ANY Annotations @@ -3080,11 +3146,11 @@ - + 5 wxEXPAND|wxTOP 1 - + wxID_ANY Track Editing @@ -3092,11 +3158,11 @@ wxVERTICAL 1 none - + 3 wxBOTTOM|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -3153,11 +3219,11 @@ -1 - + 5 wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -3217,21 +3283,21 @@ - + 5 wxEXPAND 0 - + 5 protected 0 - + 5 wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -3291,21 +3357,21 @@ - + 5 wxEXPAND 0 - + 5 protected 0 - + 5 wxBOTTOM|wxRIGHT|wxLEFT 0 - + 1 1 1 diff --git a/pcbnew/dialogs/panel_edit_options_base.h b/pcbnew/dialogs/panel_edit_options_base.h index 63d994416f..4e3189f020 100644 --- a/pcbnew/dialogs/panel_edit_options_base.h +++ b/pcbnew/dialogs/panel_edit_options_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.9.0 Dec 30 2020) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -45,6 +45,7 @@ class PANEL_EDIT_OPTIONS_BASE : public wxPanel wxCheckBox* m_magneticGraphics; wxCheckBox* m_segments45OnlyCtrl; wxCheckBox* m_flipLeftRight; + wxCheckBox* m_addUnlockedPads; wxStaticText* m_staticTextRotationAngle; wxTextCtrl* m_rotationAngle; wxStaticBoxSizer* m_mouseCmdsWinLin; diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 13b0b7a471..a348eb71f6 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -735,7 +735,21 @@ void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& aEvent ) // Create the "new" footprint FOOTPRINT* newFootprint = (FOOTPRINT*) GetBoard()->GetFirstFootprint()->Duplicate(); newFootprint->SetParent( pcbframe->GetBoard() ); - newFootprint->SetLink( 0 ); + newFootprint->SetLink( niluuid ); + newFootprint->SetFlags(IS_NEW ); // whatever + + // Pads in the library all have orphaned nets. Replace with Default. + for( PAD* pad : newFootprint->Pads() ) + { + pad->SetLocked( !pcbframe->Settings().m_AddUnlockedPads ); + pad->SetNetCode( 0 ); + } + + // Put it on FRONT layer, + // (Can be stored flipped if the lib is an archive built from a board) + if( newFootprint->IsFlipped() ) + newFootprint->Flip( newFootprint->GetPosition(), + pcbframe->Settings().m_FlipLeftRight ); KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls(); VECTOR2D cursorPos = viewControls->GetCursorPosition(); @@ -743,6 +757,7 @@ void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& aEvent ) commit.Add( newFootprint ); viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false ); pcbframe->PlaceFootprint( newFootprint ); + newFootprint->SetPosition( wxPoint( 0, 0 ) ); viewControls->SetCrossHairCursorPosition( cursorPos, false ); commit.Push( wxT( "Insert footprint" ) ); diff --git a/pcbnew/pcbnew_settings.cpp b/pcbnew/pcbnew_settings.cpp index b9ecbce5c6..bd2747704f 100644 --- a/pcbnew/pcbnew_settings.cpp +++ b/pcbnew/pcbnew_settings.cpp @@ -67,6 +67,7 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() m_TrackDragAction( TRACK_DRAG_ACTION::DRAG ), m_Use45DegreeGraphicSegments( false ), m_FlipLeftRight( false ), + m_AddUnlockedPads( false ), m_PolarCoords( false ), m_RotationAngle( 900 ), m_PlotLineWidth( 0.1 ), @@ -103,6 +104,9 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() m_params.emplace_back( new PARAM( "editing.flip_left_right", &m_FlipLeftRight, true ) ); + m_params.emplace_back( new PARAM( "editing.add_unlocked_pads", + &m_AddUnlockedPads, false ) ); + m_params.emplace_back( new PARAM( "editing.magnetic_graphics", &m_MagneticItems.graphics, true ) ); diff --git a/pcbnew/pcbnew_settings.h b/pcbnew/pcbnew_settings.h index 4ee4271144..6cfdc0ed97 100644 --- a/pcbnew/pcbnew_settings.h +++ b/pcbnew/pcbnew_settings.h @@ -281,6 +281,9 @@ public: bool m_FlipLeftRight; // True: Flip footprints across Y axis // False: Flip footprints across X axis + bool m_AddUnlockedPads; // True: Pads are unlocked when new footprints are added to the board + // False: Pads are locked in new footprints + bool m_PolarCoords; int m_RotationAngle; diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index 236efe22b8..cd1876b4af 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -904,7 +904,10 @@ int BOARD_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) // Pads in the library all have orphaned nets. Replace with Default. for( PAD* pad : fp->Pads() ) + { + pad->SetLocked( !m_frame->Settings().m_AddUnlockedPads ); pad->SetNetCode( 0 ); + } // Put it on FRONT layer, // (Can be stored flipped if the lib is an archive built from a board) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index dbae8296fd..315be8f34d 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -251,7 +251,7 @@ int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent ) BOARD_ITEM* item = aCollector[ i ]; // We don't operate on pads; convert them to footprint selections - if( !sTool->IsFootprintEditor() && item->Type() == PCB_PAD_T + if( !sTool->IsFootprintEditor() && item->IsLocked() && item->Type() == PCB_PAD_T && !item->GetParent()->IsLocked() ) { aCollector.Remove( item ); @@ -263,7 +263,7 @@ int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent ) sTool->FilterCollectorForGroups( aCollector ); }, - true /* prompt user regarding locked items */ ); + !m_isFootprintEditor /* prompt user regarding locked items */ ); if( selection.Empty() ) return 0; @@ -358,7 +358,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) for( BOARD_ITEM* item : to_add ) aCollector.Append( item ); }, - true /* prompt user regarding locked items */ ); + !m_isFootprintEditor /* prompt user regarding locked items only in pcb editor*/ ); if( selection.Empty() ) return 0; @@ -988,7 +988,7 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) sTool->FilterCollectorForGroups( aCollector ); }, - !m_dragging /* prompt user regarding locked items */ ); + !m_dragging && !m_isFootprintEditor /* prompt user regarding locked items */ ); if( selection.Empty() ) return 0; @@ -1114,7 +1114,7 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) sTool->FilterCollectorForGroups( aCollector ); }, - !m_dragging /* prompt user regarding locked items */ ); + !m_dragging && !m_isFootprintEditor /* prompt user regarding locked items */ ); if( selection.Empty() ) return 0; @@ -1233,7 +1233,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) sTool->FilterCollectorForGroups( aCollector ); }, - !m_dragging /* prompt user regarding locked items */ ); + !m_dragging && !m_isFootprintEditor/* prompt user regarding locked items */ ); if( selection.Empty() ) return 0; @@ -1323,7 +1323,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool ) { }, - true /* prompt user regarding locked items */ ); + !m_isFootprintEditor /* prompt user regarding locked items */ ); } bool isHover = selectionCopy.IsHover(); @@ -1530,7 +1530,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) sTool->FilterCollectorForGroups( aCollector ); }, - true /* prompt user regarding locked items */ ); + !m_isFootprintEditor /* prompt user regarding locked items */ ); if( selection.Empty() ) return 0; @@ -1958,7 +1958,7 @@ int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool ) { }, - aEvent.IsAction( &ACTIONS::cut ) /* prompt user regarding locked items */ ); + aEvent.IsAction( &ACTIONS::cut ) && !m_isFootprintEditor /* prompt user regarding locked items */ ); if( !selection.Empty() ) { diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index e6b5b5b522..2147e0189c 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -484,7 +484,7 @@ int ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally( const TOOL_EVENT& aEvent ) aCollector.Remove( item ); } }, - true /* prompt user regarding locked items */ ); + m_frame->IsType( FRAME_PCB_EDITOR ) /* prompt user regarding locked items */ ); if( selection.Size() <= 1 ) return 0; @@ -605,7 +605,7 @@ int ALIGN_DISTRIBUTE_TOOL::DistributeVertically( const TOOL_EVENT& aEvent ) aCollector.Remove( item ); } }, - true /* prompt user regarding locked items */ ); + m_frame->IsType( FRAME_PCB_EDITOR ) /* prompt user regarding locked items */ ); if( selection.Size() <= 1 ) return 0; diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index e4c07b6775..715f22b6c3 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -78,7 +78,7 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent ) aCollector.Remove( item ); } }, - true /* prompt user regarding locked items */ ); + !m_isFootprintEditor /* prompt user regarding locked items */ ); if( selection.Empty() ) return 0;