From da9fc844217547e0054d527b3b08fbed1dc26d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= Date: Wed, 18 Feb 2015 00:58:14 +0100 Subject: [PATCH] improved module locking: lock pads only/lock whole module mode added --- pcbnew/class_module.cpp | 28 ++++++++++++++----- pcbnew/class_module.h | 18 ++++++++++++ pcbnew/class_pad.cpp | 1 - .../dialog_edit_module_for_BoardEditor.cpp | 16 ++++++++--- ...ialog_edit_module_for_BoardEditor_base.cpp | 4 +-- ...ialog_edit_module_for_BoardEditor_base.fbp | 4 +-- 6 files changed, 55 insertions(+), 16 deletions(-) diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index c6e0b5d5e5..1f9462da5c 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -57,7 +57,7 @@ MODULE::MODULE( BOARD* parent ) : m_Attributs = MOD_DEFAULT; m_Layer = F_Cu; m_Orient = 0; - m_ModuleStatus = 0; + m_ModuleStatus = MODULE_PADS_LOCKED; flag = 0; m_CntRot90 = m_CntRot180 = 0; m_Surface = 0.0; @@ -815,6 +815,11 @@ void MODULE::RunOnChildren( boost::function aFunction ) } } +const BOX2I MODULE::ViewBBox() const +{ + return BOX2I( VECTOR2I( GetFootprintRect().GetOrigin() ), + VECTOR2I( GetFootprintRect().GetSize() ) ); +} void MODULE::ViewUpdate( int aUpdateFlags ) { @@ -867,12 +872,6 @@ unsigned int MODULE::ViewGetLOD( int aLayer ) const return 30; } -const BOX2I MODULE::ViewBBox() const -{ - EDA_RECT fpRect = GetFootprintRect(); - - return BOX2I( VECTOR2I( fpRect.GetOrigin() ), VECTOR2I( fpRect.GetSize() ) ); -} /* Test for validity of the name in a library of the footprint * ( no spaces, dir separators ... ) @@ -1116,3 +1115,18 @@ void MODULE::SetOrientation( double newangle ) CalculateBoundingBox(); } +double MODULE::PadCoverageRatio() const +{ + double padArea = 0.0; + double moduleArea = GetFootprintRect().GetArea(); + + for( D_PAD* pad = m_Pads; pad; pad = pad->Next() ) + padArea += pad->GetBoundingBox().GetArea(); + + if(moduleArea == 0.0) + return 1.0; + + double ratio = padArea / moduleArea; + + return std::min(ratio, 1.0); +} diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 266b033e3f..e8ae7e6946 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -223,6 +223,7 @@ public: #define MODULE_is_LOCKED 0x01 ///< module LOCKED: no autoplace allowed #define MODULE_is_PLACED 0x02 ///< In autoplace: module automatically placed #define MODULE_to_PLACE 0x04 ///< In autoplace: module waiting for autoplace +#define MODULE_PADS_LOCKED 0x08 ///< In autoplace: module waiting for autoplace bool IsLocked() const @@ -261,6 +262,15 @@ public: m_ModuleStatus &= ~MODULE_to_PLACE; } + bool PadsLocked() const { return (m_ModuleStatus & MODULE_PADS_LOCKED ); } + void SetPadsLocked( bool aPadsLocked ) + { + if( aPadsLocked ) + m_ModuleStatus |= MODULE_PADS_LOCKED; + else + m_ModuleStatus &= ~MODULE_PADS_LOCKED; + } + void SetLastEditTime( time_t aTime ) { m_LastEditTime = aTime; } void SetLastEditTime( ) { m_LastEditTime = time( NULL ); } time_t GetLastEditTime() const { return m_LastEditTime; } @@ -559,6 +569,14 @@ public: m_initial_comments = aInitialComments; } + /** + * Function PadCoverageRatio + * Calculates the ratio of total area of the footprint pads to the area of the + * footprint. Used by selection tool heuristics. + * @return the ratio + */ + double PadCoverageRatio() const; + /// Return the initial comments block or NULL if none, without transfer of ownership. const wxArrayString* GetInitialComments() const { return m_initial_comments; } diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index 4abd48edcf..7ec4f88fbc 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -177,7 +177,6 @@ const EDA_RECT D_PAD::GetBoundingBox() const area.SetOrigin( m_Pos.x-dx, m_Pos.y-dy ); area.SetSize( 2*dx, 2*dy ); break; - break; case PAD_RECT: //Use two corners and track their rotation diff --git a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp index f7430f96fb..7c7d9ba7ea 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp @@ -313,12 +313,19 @@ void DIALOG_MODULE_BOARD_EDITOR::InitModeditProperties() break; } - m_AutoPlaceCtrl->SetSelection( (m_CurrentModule->IsLocked()) ? 1 : 0 ); + if (m_CurrentModule->IsLocked() ) + m_AutoPlaceCtrl->SetSelection( 2 ); + else if (m_CurrentModule->PadsLocked() ) + m_AutoPlaceCtrl->SetSelection( 1 ); + else + m_AutoPlaceCtrl->SetSelection( 0 ); m_AutoPlaceCtrl->SetItemToolTip( 0, - _( "Enable hotkey move commands and Auto Placement" ) ); + _( "Component can be freely moved and auto placed. User can arbitrarily select and edit component's pads." ) ); m_AutoPlaceCtrl->SetItemToolTip( 1, - _( "Disable hotkey move commands and Auto Placement" ) ); + _( "Component can be freely moved and auto placed, but its pads cannot be selected or edited." ) ); + m_AutoPlaceCtrl->SetItemToolTip( 2, + _( "Component is locked: it cannot be freely moved or auto placed." ) ); m_CostRot90Ctrl->SetValue( m_CurrentModule->GetPlacementCost90() ); @@ -583,7 +590,8 @@ void DIALOG_MODULE_BOARD_EDITOR::OnOkClick( wxCommandEvent& event ) modpos.x = ValueFromTextCtrl( *m_ModPositionX ); modpos.y = ValueFromTextCtrl( *m_ModPositionY ); m_CurrentModule->SetPosition( modpos ); - m_CurrentModule->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 ); + m_CurrentModule->SetLocked( m_AutoPlaceCtrl->GetSelection() == 2 ); + m_CurrentModule->SetPadsLocked( m_AutoPlaceCtrl->GetSelection() == 1 ); switch( m_AttributsCtrl->GetSelection() ) { diff --git a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor_base.cpp b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor_base.cpp index d47946603b..f47642935a 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor_base.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor_base.cpp @@ -143,10 +143,10 @@ DIALOG_MODULE_BOARD_EDITOR_BASE::DIALOG_MODULE_BOARD_EDITOR_BASE( wxWindow* pare m_AttributsCtrl->SetSelection( 0 ); bSizerAttrib->Add( m_AttributsCtrl, 1, wxALL|wxEXPAND, 5 ); - wxString m_AutoPlaceCtrlChoices[] = { _("Free"), _("Locked") }; + wxString m_AutoPlaceCtrlChoices[] = { _("Free"), _("Lock pads"), _("Lock module") }; int m_AutoPlaceCtrlNChoices = sizeof( m_AutoPlaceCtrlChoices ) / sizeof( wxString ); m_AutoPlaceCtrl = new wxRadioBox( m_PanelProperties, wxID_ANY, _("Move and Place"), wxDefaultPosition, wxDefaultSize, m_AutoPlaceCtrlNChoices, m_AutoPlaceCtrlChoices, 1, wxRA_SPECIFY_COLS ); - m_AutoPlaceCtrl->SetSelection( 0 ); + m_AutoPlaceCtrl->SetSelection( 1 ); bSizerAttrib->Add( m_AutoPlaceCtrl, 1, wxALL|wxEXPAND, 5 ); diff --git a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor_base.fbp b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor_base.fbp index 80a6083222..86a87cfef9 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor_base.fbp +++ b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor_base.fbp @@ -2260,7 +2260,7 @@ 1 0 - "Free" "Locked" + "Free" "Lock pads" "Lock module" 1 1 @@ -2292,7 +2292,7 @@ 1 Resizable - 0 + 1 1 wxRA_SPECIFY_COLS