From ec9d38e21fbffdc46cda9cbfa942619e8a40e6e1 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 19 Aug 2018 17:11:58 +0100 Subject: [PATCH] Add filter to net selector widget. Also fixes a bug where nets wouldn't get changed because the pads weren't changed and so the pad nets would propagate and wipe out the changed nets on the tracks. Also includes warning dialogs that pad nets will be changed if the track nets are. Fixes: lp:1779854 * https://bugs.launchpad.net/kicad/+bug/1779854 --- common/CMakeLists.txt | 2 +- common/widgets/net_selector.cpp | 290 ++++++++++++++++++ common/widgets/widget_net_selector.cpp | 124 -------- include/widgets/net_selector.h | 61 ++++ include/widgets/widget_net_selector.h | 73 ----- pcbnew/connectivity_data.cpp | 23 +- pcbnew/connectivity_data.h | 2 + .../dialog_global_edit_tracks_and_vias.cpp | 121 +++----- ...ialog_global_edit_tracks_and_vias_base.cpp | 16 +- ...ialog_global_edit_tracks_and_vias_base.fbp | 27 +- .../dialog_global_edit_tracks_and_vias_base.h | 4 +- pcbnew/dialogs/dialog_pad_properties.cpp | 54 ++-- pcbnew/dialogs/dialog_pad_properties.h | 7 +- pcbnew/dialogs/dialog_pad_properties_base.cpp | 24 +- pcbnew/dialogs/dialog_pad_properties_base.fbp | 135 +------- pcbnew/dialogs/dialog_pad_properties_base.h | 8 +- .../dialogs/dialog_track_via_properties.cpp | 177 +++++++---- pcbnew/dialogs/dialog_track_via_properties.h | 9 +- .../dialog_track_via_properties_base.cpp | 11 +- .../dialog_track_via_properties_base.fbp | 32 +- .../dialog_track_via_properties_base.h | 7 +- pcbnew/tools/edit_tool.cpp | 2 +- 22 files changed, 623 insertions(+), 586 deletions(-) create mode 100644 common/widgets/net_selector.cpp delete mode 100644 common/widgets/widget_net_selector.cpp create mode 100644 include/widgets/net_selector.h delete mode 100644 include/widgets/widget_net_selector.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 8755bc1a89..85dea19ef1 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -447,7 +447,7 @@ set( PCB_COMMON_SRCS ../pcbnew/ratsnest_viewitem.cpp ../pcbnew/sel_layer.cpp ../pcbnew/zone_settings.cpp - widgets/widget_net_selector.cpp + widgets/net_selector.cpp ) # add -DPCBNEW to compilation of these PCBNEW sources diff --git a/common/widgets/net_selector.cpp b/common/widgets/net_selector.cpp new file mode 100644 index 0000000000..6261578b29 --- /dev/null +++ b/common/widgets/net_selector.cpp @@ -0,0 +1,290 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + + +#include + +#include +#include +#include + + +wxDEFINE_EVENT( NET_SELECTED, wxCommandEvent ); + +#define LIST_ITEM_PADDING 5 // these are probably going to be platform-specific... +#define LIST_PADDING 5 + +#define NO_NET _( "" ) + + +class NET_SELECTOR_COMBOPOPUP : public wxPanel, public wxComboPopup +{ +public: + NET_SELECTOR_COMBOPOPUP() : + m_filterCtrl( nullptr ), + m_netListBox( nullptr ), + m_popupWidth( -1 ), + m_maxPopupHeight( 1000 ), + m_netinfoList( nullptr ), + m_selectedNet( 0 ) + { } + + bool Create(wxWindow* aParent) override + { + wxPanel::Create( aParent ); + + wxBoxSizer* mainSizer; + mainSizer = new wxBoxSizer( wxVERTICAL ); + + m_filterCtrl = new wxTextCtrl( this, wxID_ANY ); + m_filterCtrl->SetHint( _( "Filter" ) ); + mainSizer->Add( m_filterCtrl, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 0 ); + + m_netListBox = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, 0, + wxLB_SINGLE|wxLB_NEEDED_SB ); + mainSizer->Add( m_netListBox, 0, wxALL|wxEXPAND, 0 ); + + SetSizer( mainSizer ); + Layout(); + + // wxPopupTransientWindow's mouse capture strategy is an absolute nightmare. We can't + // tell where mouse-down events will come from, so we have to accept them from either + // ourselves (the popup) or our child (the net listbox). Mouse-move events are even + // worse as the above strategy doesn't even work -- so we process them on idle. + Connect( wxEVT_IDLE, wxIdleEventHandler( NET_SELECTOR_COMBOPOPUP::onIdle ), NULL, this ); + Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( NET_SELECTOR_COMBOPOPUP::onMouseClick ), NULL, this ); + m_netListBox->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( NET_SELECTOR_COMBOPOPUP::onMouseClick ), NULL, this ); + m_filterCtrl->Connect( wxEVT_TEXT, wxCommandEventHandler( NET_SELECTOR_COMBOPOPUP::onFilterEdit ), NULL, this ); + + return true; + } + + wxWindow *GetControl() override { return this; } + + void SetStringValue( const wxString& aNetName ) override + { + // shouldn't be here (combo is read-only) + } + + wxString GetStringValue() const override + { + NETINFO_ITEM* netInfo = m_netinfoList->GetNetItem( m_selectedNet ); + + if( netInfo && netInfo->GetNet() > 0 ) + return netInfo->GetNetname(); + + return NO_NET; + } + + void SetNetInfo( NETINFO_LIST* aNetInfoList ) + { + m_netinfoList = aNetInfoList; + rebuildList(); + } + + void SetIndeterminate() { m_selectedNet = -1; } + bool IsIndeterminate() { return m_selectedNet == -1; } + + void SetSelectedNetcode( int aNetcode ) { m_selectedNet = aNetcode; } + int GetSelectedNetcode() { return m_selectedNet; } + + wxSize GetAdjustedSize( int aMinWidth, int aPrefHeight, int aMaxHeight ) override + { + // Called when the popup is first shown. Stash the width and maxHeight so we + // can use them later when refreshing the sizes after filter changes. + m_popupWidth = aMinWidth; + m_maxPopupHeight = aMaxHeight; + + return updateSize(); + } + + void OnPopup() override + { + // The updateSize() call in GetAdjustedSize() leaves the height off-by-one for + // some reason, so do it again. + updateSize(); + } + +protected: + wxSize updateSize() + { + wxSize popupSize( m_popupWidth, m_maxPopupHeight ); + int listTop = m_netListBox->GetRect().y; + int itemHeight = GetTextSize( wxT( "Xy" ), this ).y + LIST_ITEM_PADDING; + int listHeight = m_netListBox->GetCount() * itemHeight + LIST_PADDING; + + if( listTop + listHeight >= m_maxPopupHeight ) + listHeight = m_maxPopupHeight - listTop - 1; + + popupSize.y = listTop + listHeight; + SetSize( popupSize ); // us + GetParent()->SetSize( popupSize ); // the window that wxComboCtrl put us in + + m_netListBox->SetSize( wxSize( m_popupWidth, listHeight ) ); + m_netListBox->Refresh(); + + return popupSize; + } + + void rebuildList() + { + wxArrayString netNames; + wxString filter = m_filterCtrl->GetValue().MakeLower(); + + if( !filter.IsEmpty() ) + filter = wxT( "*" ) + filter + wxT( "*" ); + + for( NETINFO_ITEM* netinfo : *m_netinfoList ) + { + if( netinfo->GetNet() == 0 ) + continue; // we'll insert NO_NET after sorting + + if( filter.IsEmpty() || wxString( netinfo->GetNetname() ).MakeLower().Matches( filter ) ) + netNames.push_back( netinfo->GetNetname() ); + } + std::sort( netNames.begin(), netNames.end() ); + + if( filter.IsEmpty() || wxString( NO_NET ).MakeLower().Matches( filter ) ) + netNames.insert( netNames.begin(), NO_NET ); + + m_netListBox->Set( netNames ); + } + + // Hot-track mouse. + void onIdle( wxIdleEvent& aEvent ) + { + wxPoint screenPos = wxGetMousePosition(); + + if( m_netListBox->GetScreenRect().Contains( screenPos ) ) + { + if( HasCapture() ) + ReleaseMouse(); + +#ifdef __WXOSX_MAC__ + m_netListBox->OSXForceFocus(); +#else + m_netListBox->SetFocus(); +#endif + + wxPoint relativePos = m_netListBox->ScreenToClient( screenPos ); + int item = m_netListBox->HitTest( relativePos ); + + if( item >= 0 ) + m_netListBox->SetSelection( item ); + } + else if( m_filterCtrl->GetScreenRect().Contains( screenPos ) ) + { + if( HasCapture() ) + ReleaseMouse(); + + m_filterCtrl->SetFocus(); + } + } + + // Accecpt single-click closure from m_netListBox + void onMouseClick( wxMouseEvent& aEvent ) + { + wxPoint relativePos = m_netListBox->ScreenToClient( wxGetMousePosition() ); + int item = m_netListBox->HitTest( relativePos ); + + if( item >= 0 ) + { + wxString selectedNetName = m_netListBox->GetString( (unsigned) item ); + + if( selectedNetName.IsEmpty() ) + { + m_selectedNet = -1; + GetComboCtrl()->SetValue( INDETERMINATE ); + } + else if( selectedNetName == NO_NET ) + { + m_selectedNet = 0; + GetComboCtrl()->SetValue( NO_NET ); + } + else + { + m_selectedNet = m_netinfoList->GetNetItem( selectedNetName )->GetNet(); + GetComboCtrl()->SetValue( selectedNetName ); + } + + wxCommandEvent changeEvent( NET_SELECTED ); + wxPostEvent( GetComboCtrl(), changeEvent ); + + Dismiss(); + } + aEvent.Skip(); + } + + void onFilterEdit( wxCommandEvent& aEvent ) + { + rebuildList(); + updateSize(); + } + +protected: + wxTextCtrl* m_filterCtrl; + wxListBox* m_netListBox; + int m_popupWidth; + int m_maxPopupHeight; + + NETINFO_LIST* m_netinfoList; + + int m_selectedNet; +}; + + +NET_SELECTOR::NET_SELECTOR( wxWindow *parent, wxWindowID id, + const wxPoint &pos, const wxSize &size, long style ) : + wxComboCtrl( parent, id, wxEmptyString, pos, size, style|wxCB_READONLY ) +{ + m_netSelectorPopup = new NET_SELECTOR_COMBOPOPUP(); + SetPopupControl( m_netSelectorPopup ); +} + +void NET_SELECTOR::SetNetInfo( NETINFO_LIST* aNetInfoList ) +{ + m_netSelectorPopup->SetNetInfo( aNetInfoList ); +} + +void NET_SELECTOR::SetSelectedNetcode( int aNetcode ) +{ + m_netSelectorPopup->SetSelectedNetcode( aNetcode ); + SetValue( m_netSelectorPopup->GetStringValue() ); +} + +void NET_SELECTOR::SetIndeterminate() +{ + m_netSelectorPopup->SetIndeterminate(); + SetValue( INDETERMINATE ); +} + +bool NET_SELECTOR::IsIndeterminate() +{ + return m_netSelectorPopup->IsIndeterminate(); +} + +int NET_SELECTOR::GetSelectedNetcode() +{ + return m_netSelectorPopup->GetSelectedNetcode(); +} + diff --git a/common/widgets/widget_net_selector.cpp b/common/widgets/widget_net_selector.cpp deleted file mode 100644 index a84c0318ad..0000000000 --- a/common/widgets/widget_net_selector.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2017 CERN - * @author Tomasz Wlostowski - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - - -#include - -#include -#include -#include - -WIDGET_NET_SELECTOR::WIDGET_NET_SELECTOR( wxWindow *parent, wxWindowID id, - const wxString &value, const wxPoint &pos, const wxSize &size, - int n, const wxString choices[], long style, - const wxValidator &validator, const wxString &name ) : - wxComboBox( parent, id, value, pos, size, n, choices, style, validator, name ), - m_multiple( false ) -{ -} - - -WIDGET_NET_SELECTOR::~WIDGET_NET_SELECTOR() -{ -} - - -void WIDGET_NET_SELECTOR::SetMultiple( bool aMultiple ) -{ - if ( aMultiple ) - { - m_multiple = true; - - int k = Append( wxT("") ); - SetSelection( k ); - } -} - - -void WIDGET_NET_SELECTOR::SetSelectedNet ( int aNetcode ) -{ - for( const auto& net : m_nets ) - { - if( net.m_Code == aNetcode ) - { - SetSelection( net.m_Pos ); - return; - } - } - - SetSelection( 0 ); -} - - -int WIDGET_NET_SELECTOR::GetSelectedNet() -{ - int pos = GetSelection(); - - for( const auto& net : m_nets ) - { - if( net.m_Pos == pos ) - return net.m_Code; - } - - return 0; -} - - -bool WIDGET_NET_SELECTOR::IsUniqueNetSelected() const -{ - if( m_multiple && ( GetSelection() == ( (int)GetCount() - 1 ) ) ) - return false; - - return true; -} - - -void WIDGET_NET_SELECTOR::SetBoard( BOARD* aBoard ) -{ - auto& netinfo = aBoard->GetNetInfo(); - - for( unsigned i = 1; i < netinfo.GetNetCount(); i++ ) - { - NETINFO_ITEM* ni = netinfo.GetNetItem( i ); - NET net; - net.m_Name = ni->GetNetname(); - net.m_Code = i; - m_nets.push_back( net ); - } - - std::sort( m_nets.begin(), m_nets.end() ); - - // Add the list of selectable nets to the wxComboBox. - // Using a wxArrayString is much faster than adding each name separately - wxArrayString netnames; - - netnames.Add( wxT( "" ) ); // Always on top of the list - - for( auto& net : m_nets ) - { - net.m_Pos = netnames.Add( net.m_Name ); - } - - Append( netnames ); -} diff --git a/include/widgets/net_selector.h b/include/widgets/net_selector.h new file mode 100644 index 0000000000..74f9ed64f4 --- /dev/null +++ b/include/widgets/net_selector.h @@ -0,0 +1,61 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WIDGET_NET_SELECTOR_H +#define __WIDGET_NET_SELECTOR_H + +#include +#include + + +class BOARD; +class NETINFO_LIST; +class NET_SELECTOR_COMBOPOPUP; + + +wxDECLARE_EVENT( NET_SELECTED, wxCommandEvent ); + + +class NET_SELECTOR : public wxComboCtrl +{ +public: + // Note: this list of arguments is here because it keeps us from having to customize + // the constructor calls in wxFormBuilder. + NET_SELECTOR( wxWindow *parent, wxWindowID id, + const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, + long style = 0 ); + + void SetNetInfo( NETINFO_LIST* aNetInfoList ); + + void SetSelectedNetcode( int aNetcode ); + void SetIndeterminate(); + + bool IsIndeterminate(); + int GetSelectedNetcode(); + +protected: + NET_SELECTOR_COMBOPOPUP* m_netSelectorPopup; +}; + + +#endif diff --git a/include/widgets/widget_net_selector.h b/include/widgets/widget_net_selector.h deleted file mode 100644 index d914649ea3..0000000000 --- a/include/widgets/widget_net_selector.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2017 CERN - * @author Tomasz Wlostowski - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#ifndef __WIDGET_NET_SELECTOR_H -#define __WIDGET_NET_SELECTOR_H - -#include -#include - -class BOARD; - -class WIDGET_NET_SELECTOR : public wxComboBox -{ -public: - // Note: this list of arguments is here because WIDGET_NET_SELECTOR must - // have the same arguments as wxComboBox to be used inside wxFormaBuilder - WIDGET_NET_SELECTOR( wxWindow *parent, wxWindowID id, - const wxString &value=wxEmptyString, - const wxPoint &pos=wxDefaultPosition, - const wxSize &size=wxDefaultSize, - int n=0, const wxString choices[]=NULL, - long style=0, const wxValidator &validator=wxDefaultValidator, - const wxString &name=wxComboBoxNameStr); - - ~WIDGET_NET_SELECTOR(); - - void SetMultiple( bool aMultiple = true ); - void SetSelectedNet ( int aNetcode ); - int GetSelectedNet(); - - bool IsUniqueNetSelected() const; - - // Build the list of netnames and populate the wxComboBox - void SetBoard( BOARD* aBoard ); - -private: - struct NET { - int m_Code; - int m_Pos; - wxString m_Name; - - bool operator <( const NET& aOther ) const - { - return m_Name < aOther.m_Name; - } - }; - - bool m_multiple; - std::vector m_nets; -}; - -#endif diff --git a/pcbnew/connectivity_data.cpp b/pcbnew/connectivity_data.cpp index 6498ae7496..8d0a13dbf8 100644 --- a/pcbnew/connectivity_data.cpp +++ b/pcbnew/connectivity_data.cpp @@ -462,22 +462,27 @@ const } -const std::vector CONNECTIVITY_DATA::GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) -const +const void CONNECTIVITY_DATA::GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem, + std::set* pads ) const { - auto& entry = m_connAlgo->ItemEntry( aItem ); - - std::set pads; - std::vector rv; - - for( auto citem : entry.GetItems() ) + for( auto citem : m_connAlgo->ItemEntry( aItem ).GetItems() ) { for( auto connected : citem->ConnectedItems() ) { if( connected->Valid() && connected->Parent()->Type() == PCB_PAD_T ) - pads.insert( static_cast ( connected->Parent() ) ); + pads->insert( static_cast ( connected->Parent() ) ); } } +} + + +const std::vector CONNECTIVITY_DATA::GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) +const +{ + std::set pads; + std::vector rv; + + GetConnectedPads( aItem, &pads ); std::copy( pads.begin(), pads.end(), std::back_inserter( rv ) ); return rv; diff --git a/pcbnew/connectivity_data.h b/pcbnew/connectivity_data.h index bf9c57e694..004b096eaf 100644 --- a/pcbnew/connectivity_data.h +++ b/pcbnew/connectivity_data.h @@ -174,6 +174,8 @@ public: const std::vector GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) const; + const void GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem, std::set* pads ) const; + const std::vector GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor, KICAD_T aTypes[] ); void GetUnconnectedEdges( std::vector& aEdges ) const; diff --git a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp index 2cf500ce02..7dc838b57c 100644 --- a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp +++ b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp @@ -68,7 +68,7 @@ private: void OnSizeNetclassGrid( wxSizeEvent& event ) override; void AdjustNetclassGridColumns( int aWidth ); - void OnNetFilterSelect( wxCommandEvent& event ) override + void OnNetFilterSelect( wxCommandEvent& event ) { m_netFilterOpt->SetValue( true ); } @@ -115,98 +115,79 @@ DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS( PCB_EDIT m_netclassGrid->SetCellHighlightPenWidth( 0 ); m_sdbSizerOK->SetDefault(); + m_netFilter->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this ); + FinishDialogSettings(); } DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::~DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS() { + m_netFilter->Disconnect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this ); + delete[] m_originalColWidths; } void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildFilterLists() { - int currentNet = m_brd->GetHighLightNetCode(); - - if( currentNet < 0 && m_parent->GetCurItem() && m_parent->GetCurItem()->IsConnected() ) - currentNet = static_cast( m_parent->GetCurItem() )->GetNetCode(); - - wxString currentNetClass = m_brd->GetDesignSettings().GetCurrentNetClassName(); - LAYER_NUM currentLayer = m_parent->GetActiveLayer(); - // Populate the net filter list with net names - for( unsigned netcode = 0; netcode < m_brd->GetNetCount(); netcode++ ) - { - wxString netname; - - if( netcode == 0 ) // netcode 0 is the netcode of not connected items - netname = ""; - else - netname = m_brd->GetNetInfo().GetNetItem( netcode )->GetNetname(); - - m_netFilter->Append( netname ); - - if( (int) netcode == currentNet ) - m_netFilter->SetSelection( m_netFilter->GetCount() - 1 ); - } + m_netFilter->SetNetInfo( &m_brd->GetNetInfo() ); + m_netFilter->SetSelectedNetcode( m_brd->GetHighLightNetCode() ); // Populate the netclass filter list with netclass names - NETCLASSES& netclasses = m_brd->GetDesignSettings().m_NetClasses; + wxArrayString netclassNames; + NETCLASSES& netclasses = m_brd->GetDesignSettings().m_NetClasses; - m_netclassFilter->Append( netclasses.GetDefault()->GetName() ); + netclassNames.push_back(netclasses.GetDefault()->GetName() ); for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc ) - m_netclassFilter->Append( nc->second->GetName() ); + netclassNames.push_back( nc->second->GetName() ); - m_netclassFilter->SetSelection( m_netclassFilter->FindString( currentNetClass ) ); + m_netclassFilter->Set( netclassNames ); + m_netclassFilter->SetStringSelection( m_brd->GetDesignSettings().GetCurrentNetClassName() ); // Populate the layer filter list m_layerFilter->SetBoardFrame( m_parent ); m_layerFilter->SetLayersHotkeys( false ); m_layerFilter->SetNotAllowedLayerSet( LSET::AllNonCuMask() ); m_layerFilter->Resync(); - - m_layerFilter->SetLayerSelection( currentLayer ); + m_layerFilter->SetLayerSelection( m_parent->GetActiveLayer() ); } void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildNetclassesGrid() { -#define SET_NETCLASS_VALUE( aRow, aGrid, aCol, aValue ) \ - aGrid->SetCellValue( aRow, aCol, StringFromValue( GetUserUnits(), aValue, true, true ) ) +#define SET_NETCLASS_VALUE( row, col, val ) \ + m_netclassGrid->SetCellValue( row, col, StringFromValue( GetUserUnits(), val, true, true ) ) - m_netclassGrid->SetCellValue( 0, GRID_NAME, wxEmptyString ); - m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track width" ) ); - m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via size" ) ); - m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via drill" ) ); - m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia size" ) ); - m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia drill" ) ); + m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track Width" ) ); + m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via Size" ) ); + m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via Drill" ) ); + m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia Size" ) ); + m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia Drill" ) ); NETCLASSES& netclasses = m_brd->GetDesignSettings().m_NetClasses; + NETCLASSPTR defaultNetclass = m_brd->GetDesignSettings().GetDefault(); m_netclassGrid->AppendRows( netclasses.GetCount() + 1 ); - NETCLASSPTR netclass = m_brd->GetDesignSettings().GetDefault(); - int row = 1; + m_netclassGrid->SetCellValue( 1, GRID_NAME, defaultNetclass->GetName() ); + SET_NETCLASS_VALUE( 1, GRID_TRACKSIZE, defaultNetclass->GetTrackWidth() ); + SET_NETCLASS_VALUE( 1, GRID_VIASIZE, defaultNetclass->GetViaDiameter() ); + SET_NETCLASS_VALUE( 1, GRID_VIADRILL, defaultNetclass->GetViaDrill() ); + SET_NETCLASS_VALUE( 1, GRID_uVIASIZE, defaultNetclass->GetuViaDiameter() ); + SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() ); - m_netclassGrid->SetCellValue( row, GRID_NAME, netclass->GetName() ); - SET_NETCLASS_VALUE( row, m_netclassGrid, GRID_TRACKSIZE, netclass->GetTrackWidth() ); - SET_NETCLASS_VALUE( row, m_netclassGrid, GRID_VIASIZE, netclass->GetViaDiameter() ); - SET_NETCLASS_VALUE( row, m_netclassGrid, GRID_VIADRILL, netclass->GetViaDrill() ); - SET_NETCLASS_VALUE( row, m_netclassGrid, GRID_uVIASIZE, netclass->GetuViaDiameter() ); - SET_NETCLASS_VALUE( row, m_netclassGrid, GRID_uVIADRILL, netclass->GetuViaDrill() ); - - row++; - - for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc, ++row ) + int row = 2; + for( const auto& netclass : netclasses ) { - netclass = nc->second; - m_netclassGrid->SetCellValue( row, GRID_NAME, netclass->GetName() ); - SET_NETCLASS_VALUE( row, m_netclassGrid, GRID_TRACKSIZE, netclass->GetTrackWidth() ); - SET_NETCLASS_VALUE( row, m_netclassGrid, GRID_VIASIZE, netclass->GetViaDiameter() ); - SET_NETCLASS_VALUE( row, m_netclassGrid, GRID_VIADRILL, netclass->GetViaDrill() ); - SET_NETCLASS_VALUE( row, m_netclassGrid, GRID_uVIASIZE, netclass->GetuViaDiameter() ); - SET_NETCLASS_VALUE( row, m_netclassGrid, GRID_uVIADRILL, netclass->GetuViaDrill() ); + m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first ); + SET_NETCLASS_VALUE( row, GRID_TRACKSIZE, netclass.second->GetTrackWidth() ); + SET_NETCLASS_VALUE( row, GRID_VIASIZE, netclass.second->GetViaDiameter() ); + SET_NETCLASS_VALUE( row, GRID_VIADRILL, netclass.second->GetViaDrill() ); + SET_NETCLASS_VALUE( row, GRID_uVIASIZE, netclass.second->GetuViaDiameter() ); + SET_NETCLASS_VALUE( row, GRID_uVIADRILL, netclass.second->GetuViaDrill() ); + row++; } } @@ -217,7 +198,7 @@ bool DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::TransferDataToWindow() if( item ) { - m_netFilter->SetStringSelection( item->GetNetname() ); + m_netFilter->SetSelectedNetcode( item->GetNetCode() ); m_netclassFilter->SetStringSelection( item->GetNet()->GetClassName() ); m_layerFilter->SetLayerSelection( item->GetLayer() ); } @@ -241,11 +222,13 @@ void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::processItem( PICKED_ITEMS_LIST* aUndoLi { unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex(); unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex(); - - brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() ); - brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() ); - - m_parent->SetTrackSegmentWidth( aItem, aUndoList, false ); + { + brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() ); + brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() ); + m_parent->SetTrackSegmentWidth( aItem, aUndoList, false ); + } + brdSettings.SetTrackWidthIndex( prevTrackWidthIndex ); + brdSettings.SetViaSizeIndex( prevViaSizeIndex ); if( m_layerBox->GetLayerSelection() != UNDEFINED_LAYER && aItem->Type() == PCB_TRACE_T ) { @@ -259,9 +242,6 @@ void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::processItem( PICKED_ITEMS_LIST* aUndoLi aItem->SetLayer( ToLAYER_ID( m_layerBox->GetLayerSelection() ) ); m_parent->GetBoard()->GetConnectivity()->Update( aItem ); } - - brdSettings.SetTrackWidthIndex( prevTrackWidthIndex ); - brdSettings.SetViaSizeIndex( prevViaSizeIndex ); } else { @@ -272,13 +252,13 @@ void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::processItem( PICKED_ITEMS_LIST* aUndoLi void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::visitItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem ) { - if( m_netFilterOpt->GetValue() ) + if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 ) { - if( aItem->GetNetCode() != m_netFilter->GetSelection() ) + if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() ) return; } - if( m_netclassFilterOpt->GetValue() ) + if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() ) { if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() ) return; @@ -318,9 +298,7 @@ bool DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::TransferDataFromWindow() m_parent->GetGalCanvas()->GetView()->Update( segment ); } else - { m_parent->GetCanvas()->Refresh(); - } } return true; @@ -342,7 +320,6 @@ void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::AdjustNetclassGridColumns( int aWidth ) void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnSizeNetclassGrid( wxSizeEvent& event ) { AdjustNetclassGridColumns( event.GetSize().GetX() ); - event.Skip(); } @@ -350,6 +327,6 @@ void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnSizeNetclassGrid( wxSizeEvent& event void PCB_EDIT_FRAME::OnEditTracksAndVias( wxCommandEvent& event ) { DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( this ); - dlg.ShowModal(); + dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR } diff --git a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.cpp b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.cpp index ef5e43b5cb..34e1b6f5fa 100644 --- a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.cpp +++ b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.cpp @@ -49,16 +49,14 @@ DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE fgSizer3 = new wxFlexGridSizer( 0, 3, 0, 0 ); fgSizer3->AddGrowableCol( 1 ); fgSizer3->AddGrowableCol( 2 ); - fgSizer3->SetFlexibleDirection( wxBOTH ); + fgSizer3->SetFlexibleDirection( wxHORIZONTAL ); fgSizer3->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); m_netFilterOpt = new wxCheckBox( sbFilters->GetStaticBox(), wxID_ANY, _("Filter items by net:"), wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer3->Add( m_netFilterOpt, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + fgSizer3->Add( m_netFilterOpt, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); - wxArrayString m_netFilterChoices; - m_netFilter = new wxChoice( sbFilters->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_netFilterChoices, 0 ); - m_netFilter->SetSelection( 0 ); - fgSizer3->Add( m_netFilter, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + m_netFilter = new NET_SELECTOR( sbFilters->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer3->Add( m_netFilter, 1, wxEXPAND|wxRIGHT, 5 ); fgSizer3->Add( 0, 0, 1, wxEXPAND|wxRIGHT|wxLEFT, 100 ); @@ -75,10 +73,10 @@ DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE fgSizer3->Add( 0, 0, 1, wxEXPAND, 5 ); m_layerFilterOpt = new wxCheckBox( sbFilters->GetStaticBox(), wxID_ANY, _("Filter items by layer:"), wxDefaultPosition, wxDefaultSize, 0 ); - fgSizer3->Add( m_layerFilterOpt, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + fgSizer3->Add( m_layerFilterOpt, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); m_layerFilter = new PCB_LAYER_BOX_SELECTOR( sbFilters->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); - fgSizer3->Add( m_layerFilter, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + fgSizer3->Add( m_layerFilter, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); fgSizer3->Add( 0, 0, 1, wxEXPAND, 5 ); @@ -174,7 +172,6 @@ DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE // Connect Events this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::OnUpdateUI ) ); - m_netFilter->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::OnNetFilterSelect ), NULL, this ); m_netclassFilter->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::OnNetclassFilterSelect ), NULL, this ); m_layerFilter->Connect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::OnLayerFilterSelect ), NULL, this ); m_netclassGrid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::OnSizeNetclassGrid ), NULL, this ); @@ -184,7 +181,6 @@ DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::~DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BAS { // Disconnect Events this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::OnUpdateUI ) ); - m_netFilter->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::OnNetFilterSelect ), NULL, this ); m_netclassFilter->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::OnNetclassFilterSelect ), NULL, this ); m_layerFilter->Disconnect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::OnLayerFilterSelect ), NULL, this ); m_netclassGrid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE::OnSizeNetclassGrid ), NULL, this ); diff --git a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.fbp b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.fbp index bf3be74e47..15013e557b 100644 --- a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.fbp +++ b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.fbp @@ -321,7 +321,7 @@ 1 3 - wxBOTH + wxHORIZONTAL 1,2 0 @@ -333,7 +333,7 @@ 0 5 - wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT + wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT 0 1 @@ -421,9 +421,9 @@ 5 - wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT + wxEXPAND|wxRIGHT 1 - + 1 1 1 @@ -437,10 +437,12 @@ 1 0 - + NET_SELECTOR 1 + 1 + 0 Dock 0 @@ -452,6 +454,7 @@ 0 0 wxID_ANY + #include <widgets/net_selector.h> 0 @@ -467,22 +470,16 @@ 1 Resizable - 0 + 1 - - + ; forward_declare 0 - - wxFILTER_NONE - wxDefaultValidator - - OnNetFilterSelect @@ -705,7 +702,7 @@ 5 - wxALIGN_CENTER_VERTICAL|wxALL + wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT 0 1 @@ -793,7 +790,7 @@ 5 - wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxRIGHT 0 1 diff --git a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.h b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.h index a0b13f9cef..cb09a09a59 100644 --- a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.h +++ b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias_base.h @@ -22,6 +22,7 @@ class PCB_LAYER_BOX_SELECTOR; #include #include #include +#include #include #include #include @@ -45,7 +46,7 @@ class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE : public DIALOG_SHIM wxCheckBox* m_tracks; wxCheckBox* m_vias; wxCheckBox* m_netFilterOpt; - wxChoice* m_netFilter; + NET_SELECTOR* m_netFilter; wxCheckBox* m_netclassFilterOpt; wxChoice* m_netclassFilter; wxCheckBox* m_layerFilterOpt; @@ -62,7 +63,6 @@ class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE : public DIALOG_SHIM // Virtual event handlers, overide them in your derived class virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); } - virtual void OnNetFilterSelect( wxCommandEvent& event ) { event.Skip(); } virtual void OnNetclassFilterSelect( wxCommandEvent& event ) { event.Skip(); } virtual void OnLayerFilterSelect( wxCommandEvent& event ) { event.Skip(); } virtual void OnSizeNetclassGrid( wxSizeEvent& event ) { event.Skip(); } diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index 18306943c6..f9ddb56bc6 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -1,8 +1,3 @@ -/** - * @file dialog_pad_properties.cpp - * @brief dialog pad properties editor. - */ - /* * This program source code file is part of KiCad, a free EDA CAD application. * @@ -47,7 +42,7 @@ #include #include #include -#include +#include #include #include @@ -101,7 +96,7 @@ static const LSET std_pad_layers[] = void PCB_BASE_FRAME::InstallPadOptionsFrame( D_PAD* aPad ) { DIALOG_PAD_PROPERTIES dlg( this, aPad ); - dlg.ShowModal(); + dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR } @@ -132,7 +127,7 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aP m_board = m_parent->GetBoard(); - m_PadNetNameCombo->SetBoard( m_board ); + m_PadNetSelector->SetNetInfo( &m_board->GetNetInfo() ); m_OrientValidator.SetRange( -360.0, 360.0 ); m_orientation->SetValidator( m_OrientValidator ); @@ -163,8 +158,7 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aP m_nonCopperNote->SetFont( infoFont ); // Usually, TransferDataToWindow is called by OnInitDialog - // calling it here fixes all widgets sizes, and FinishDialogSettings can - // safely fix minsizes + // calling it here fixes all widget sizes so FinishDialogSettings can safely fix minsizes TransferDataToWindow(); // Initialize canvas to be able to display the dummy pad: @@ -174,10 +168,22 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aP m_sdbSizerOK->SetDefault(); m_canUpdate = true; + m_PadNetSelector->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES::OnValuesChanged ), NULL, this ); + // Now all widgets have the size fixed, call FinishDialogSettings FinishDialogSettings(); } + +DIALOG_PAD_PROPERTIES::~DIALOG_PAD_PROPERTIES() +{ + m_PadNetSelector->Disconnect( NET_SELECTED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES::OnValuesChanged ), NULL, this ); + + delete m_dummyPad; + delete m_axisOrigin; +} + + bool DIALOG_PAD_PROPERTIES::m_sketchPreview = false; // Stores the pad draw option during a session @@ -212,14 +218,12 @@ void DIALOG_PAD_PROPERTIES::enablePrimitivePage( bool aEnable ) m_buttonAddShape->Enable( aEnable ); m_buttonDup->Enable( aEnable ); m_buttonGeometry->Enable( aEnable ); - m_buttonImport->Enable( aEnable ); } void DIALOG_PAD_PROPERTIES::prepareCanvas() { // Initialize the canvases (legacy or gal) to display the pad - // Enable the suitable canvas and make some inits // Show the X and Y axis. It is usefull because pad shape can have an offset // or be a complex shape. @@ -282,8 +286,7 @@ void DIALOG_PAD_PROPERTIES::OnPaintShowPanel( wxPaintEvent& event ) if( m_dummyPad->GetLayerSet()[B_Cu] ) color = color.LegacyMix( m_parent->Settings().Colors().GetItemColor( LAYER_PAD_BK ) ); - // What could happen: the pad color is *actually* black, or no - // copper was selected + // What could happen: the pad color is *actually* black, or no copper was selected if( color == BLACK ) color = LIGHTGRAY; @@ -355,7 +358,6 @@ void DIALOG_PAD_PROPERTIES::OnPaintShowPanel( wxPaintEvent& event ) // draw selected primitives: long select = m_listCtrlPrimitives->GetFirstSelected(); - wxPoint start, end, center; while( select >= 0 ) { @@ -565,7 +567,7 @@ void DIALOG_PAD_PROPERTIES::initValues() m_FlippedWarningSizer->Show( m_isFlipped ); m_PadNumCtrl->SetValue( m_dummyPad->GetName() ); - m_PadNetNameCombo->SetSelectedNet( m_dummyPad->GetNetCode() ); + m_PadNetSelector->SetSelectedNetcode( m_dummyPad->GetNetCode() ); // Display current pad parameters units: m_posX.SetValue( m_dummyPad->GetPosition().x ); @@ -706,7 +708,7 @@ void DIALOG_PAD_PROPERTIES::initValues() m_PadNumText->Enable( enable ); m_PadNumCtrl->Enable( enable ); m_PadNameText->Enable( enable && m_canEditNetName && m_currentPad ); - m_PadNetNameCombo->Enable( enable && m_canEditNetName && m_currentPad ); + m_PadNetSelector->Enable( enable && m_canEditNetName && m_currentPad ); m_padToDie.Enable( enable ); if( m_dummyPad->GetDrillShape() != PAD_DRILL_SHAPE_OBLONG ) @@ -976,13 +978,13 @@ void DIALOG_PAD_PROPERTIES::PadTypeSelected( wxCommandEvent& event ) if( !hasConnection ) { m_PadNumCtrl->SetValue( wxEmptyString ); - m_PadNetNameCombo->SetSelectedNet( 0 ); + m_PadNetSelector->SetSelectedNetcode( 0 ); m_padToDie.SetValue( 0 ); } else if( m_PadNumCtrl->GetValue().IsEmpty() && m_currentPad ) { m_PadNumCtrl->SetValue( m_currentPad->GetName() ); - m_PadNetNameCombo->SetSelectedNet( m_currentPad->GetNetCode() ); + m_PadNetSelector->SetSelectedNetcode( m_currentPad->GetNetCode() ); } transferDataToPad( m_dummyPad ); @@ -1019,7 +1021,7 @@ void DIALOG_PAD_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event ) m_PadNumText->Enable( hasConnection ); m_PadNumCtrl->Enable( hasConnection ); m_PadNameText->Enable( hasConnection ); - m_PadNetNameCombo->Enable( hasConnection && m_canEditNetName && m_currentPad ); + m_PadNetSelector->Enable( hasConnection && m_canEditNetName && m_currentPad ); m_padToDie.Enable( hasConnection ); // Enable/disable Copper Layers control @@ -1163,9 +1165,7 @@ bool DIALOG_PAD_PROPERTIES::padValuesOK() } if( error ) - { error_msgs.Add( _( "Too large value for pad delta size" ) ); - } switch( m_dummyPad->GetAttribute() ) { @@ -1448,7 +1448,7 @@ bool DIALOG_PAD_PROPERTIES::TransferDataFromWindow() // For PAD_ATTRIB_HOLE_NOT_PLATED, ensure there is no net name selected if( m_padMaster->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED ) - padNetcode = m_PadNetNameCombo->GetSelectedNet(); + padNetcode = m_PadNetSelector->GetSelectedNetcode(); if( m_currentPad->GetNetCode() != padNetcode ) { @@ -1629,7 +1629,7 @@ bool DIALOG_PAD_PROPERTIES::transferDataToPad( D_PAD* aPad ) aPad->SetOffset( wxPoint( m_offsetX.GetValue(), m_offsetY.GetValue() ) ); aPad->SetOrientation( m_OrientValue * 10.0 ); aPad->SetName( m_PadNumCtrl->GetValue() ); - aPad->SetNetCode( m_PadNetNameCombo->GetSelectedNet() ); + aPad->SetNetCode( m_PadNetSelector->GetSelectedNetcode() ); // Clear some values, according to the pad type and shape switch( aPad->GetShape() ) @@ -1906,12 +1906,6 @@ void DIALOG_PAD_PROPERTIES::onAddPrimitive( wxCommandEvent& event ) } -void DIALOG_PAD_PROPERTIES::onImportPrimitives( wxCommandEvent& event ) -{ - wxMessageBox( "Not yet available" ); -} - - void DIALOG_PAD_PROPERTIES::onGeometryTransform( wxCommandEvent& event ) { long select = m_listCtrlPrimitives->GetFirstSelected(); diff --git a/pcbnew/dialogs/dialog_pad_properties.h b/pcbnew/dialogs/dialog_pad_properties.h index 9ee7f5f264..2ba5a81d28 100644 --- a/pcbnew/dialogs/dialog_pad_properties.h +++ b/pcbnew/dialogs/dialog_pad_properties.h @@ -57,11 +57,7 @@ class DIALOG_PAD_PROPERTIES : public DIALOG_PAD_PROPERTIES_BASE { public: DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aPad ); - ~DIALOG_PAD_PROPERTIES() - { - delete m_dummyPad; - delete m_axisOrigin; - } + ~DIALOG_PAD_PROPERTIES(); private: PCB_BASE_FRAME* m_parent; @@ -157,7 +153,6 @@ private: void onDeletePrimitive( wxCommandEvent& event ) override; void onEditPrimitive( wxCommandEvent& event ) override; void onAddPrimitive( wxCommandEvent& event ) override; - void onImportPrimitives( wxCommandEvent& event ) override; void onGeometryTransform( wxCommandEvent& event ) override; void onDuplicatePrimitive( wxCommandEvent& event ) override; diff --git a/pcbnew/dialogs/dialog_pad_properties_base.cpp b/pcbnew/dialogs/dialog_pad_properties_base.cpp index f95e662a85..e984b0dd5f 100644 --- a/pcbnew/dialogs/dialog_pad_properties_base.cpp +++ b/pcbnew/dialogs/dialog_pad_properties_base.cpp @@ -6,7 +6,6 @@ /////////////////////////////////////////////////////////////////////////// #include "widgets/text_ctrl_eval.h" -#include "widgets/widget_net_selector.h" #include "dialog_pad_properties_base.h" @@ -52,8 +51,8 @@ DIALOG_PAD_PROPERTIES_BASE::DIALOG_PAD_PROPERTIES_BASE( wxWindow* parent, wxWind m_PadNameText->Wrap( -1 ); fgSizerShapeType->Add( m_PadNameText, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxTOP, 3 ); - m_PadNetNameCombo = new WIDGET_NET_SELECTOR( m_panelGeneral, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); - fgSizerShapeType->Add( m_PadNetNameCombo, 0, wxEXPAND|wxLEFT|wxTOP, 3 ); + m_PadNetSelector = new NET_SELECTOR( m_panelGeneral, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizerShapeType->Add( m_PadNetSelector, 0, wxTOP|wxLEFT|wxEXPAND, 3 ); fgSizerShapeType->Add( 0, 0, 1, wxEXPAND, 5 ); @@ -630,21 +629,12 @@ DIALOG_PAD_PROPERTIES_BASE::DIALOG_PAD_PROPERTIES_BASE( wxWindow* parent, wxWind m_buttonDup = new wxButton( m_panelCustomShapePrimitives, wxID_ANY, _("Duplicate Primitive"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerButtonsUpper->Add( m_buttonDup, 0, wxALL, 5 ); + m_buttonGeometry = new wxButton( m_panelCustomShapePrimitives, wxID_ANY, _("Transform Primitive"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButtonsUpper->Add( m_buttonGeometry, 0, wxALL, 5 ); + bSizerButtons->Add( bSizerButtonsUpper, 0, wxALIGN_CENTER_HORIZONTAL, 5 ); - wxBoxSizer* bSizerButtonsLower; - bSizerButtonsLower = new wxBoxSizer( wxHORIZONTAL ); - - m_buttonGeometry = new wxButton( m_panelCustomShapePrimitives, wxID_ANY, _("Geometry Transform"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizerButtonsLower->Add( m_buttonGeometry, 0, wxALL, 5 ); - - m_buttonImport = new wxButton( m_panelCustomShapePrimitives, wxID_ANY, _("Import Primitives"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizerButtonsLower->Add( m_buttonImport, 0, wxALL, 5 ); - - - bSizerButtons->Add( bSizerButtonsLower, 0, wxALIGN_CENTER_HORIZONTAL, 5 ); - m_bSizerPanelPrimitives->Add( bSizerButtons, 0, wxALIGN_CENTER_HORIZONTAL, 5 ); @@ -723,7 +713,6 @@ DIALOG_PAD_PROPERTIES_BASE::DIALOG_PAD_PROPERTIES_BASE( wxWindow* parent, wxWind this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnInitDialog ) ); m_panelGeneral->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnUpdateUI ), NULL, this ); m_PadNumCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnValuesChanged ), NULL, this ); - m_PadNetNameCombo->Connect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnValuesChanged ), NULL, this ); m_PadType->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::PadTypeSelected ), NULL, this ); m_PadShape->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnPadShapeSelection ), NULL, this ); m_sizeXCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnValuesChanged ), NULL, this ); @@ -760,7 +749,6 @@ DIALOG_PAD_PROPERTIES_BASE::DIALOG_PAD_PROPERTIES_BASE( wxWindow* parent, wxWind m_buttonAddShape->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::onAddPrimitive ), NULL, this ); m_buttonDup->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::onDuplicatePrimitive ), NULL, this ); m_buttonGeometry->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::onGeometryTransform ), NULL, this ); - m_buttonImport->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::onImportPrimitives ), NULL, this ); m_panelShowPad->Connect( wxEVT_PAINT, wxPaintEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnPaintShowPanel ), NULL, this ); m_cbShowPadOutline->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::onChangePadMode ), NULL, this ); m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnCancel ), NULL, this ); @@ -772,7 +760,6 @@ DIALOG_PAD_PROPERTIES_BASE::~DIALOG_PAD_PROPERTIES_BASE() this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnInitDialog ) ); m_panelGeneral->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnUpdateUI ), NULL, this ); m_PadNumCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnValuesChanged ), NULL, this ); - m_PadNetNameCombo->Disconnect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnValuesChanged ), NULL, this ); m_PadType->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::PadTypeSelected ), NULL, this ); m_PadShape->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnPadShapeSelection ), NULL, this ); m_sizeXCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnValuesChanged ), NULL, this ); @@ -809,7 +796,6 @@ DIALOG_PAD_PROPERTIES_BASE::~DIALOG_PAD_PROPERTIES_BASE() m_buttonAddShape->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::onAddPrimitive ), NULL, this ); m_buttonDup->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::onDuplicatePrimitive ), NULL, this ); m_buttonGeometry->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::onGeometryTransform ), NULL, this ); - m_buttonImport->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::onImportPrimitives ), NULL, this ); m_panelShowPad->Disconnect( wxEVT_PAINT, wxPaintEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnPaintShowPanel ), NULL, this ); m_cbShowPadOutline->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::onChangePadMode ), NULL, this ); m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_PAD_PROPERTIES_BASE::OnCancel ), NULL, this ); diff --git a/pcbnew/dialogs/dialog_pad_properties_base.fbp b/pcbnew/dialogs/dialog_pad_properties_base.fbp index 673b3209f9..692fd4fd80 100644 --- a/pcbnew/dialogs/dialog_pad_properties_base.fbp +++ b/pcbnew/dialogs/dialog_pad_properties_base.fbp @@ -561,9 +561,9 @@ 3 - wxEXPAND|wxLEFT|wxTOP + wxTOP|wxLEFT|wxEXPAND 0 - + 1 1 1 @@ -577,10 +577,12 @@ 1 0 - + NET_SELECTOR 1 + 1 + 0 Dock 0 @@ -592,6 +594,7 @@ 0 0 wxID_ANY + #include <widgets/net_selector.h> 0 @@ -599,7 +602,7 @@ 0 1 - m_PadNetNameCombo + m_PadNetSelector 1 @@ -607,25 +610,16 @@ 1 Resizable - -1 + 1 - wxCB_READONLY - WIDGET_NET_SELECTOR; widgets/widget_net_selector.h; forward_declare + ; forward_declare 0 - - wxFILTER_NONE - wxDefaultValidator - - - OnValuesChanged - - @@ -647,8 +641,6 @@ - - @@ -9616,20 +9608,20 @@ - + 5 wxALIGN_CENTER_HORIZONTAL 0 - + bSizerButtons wxVERTICAL none - + 5 wxALIGN_CENTER_HORIZONTAL 0 - + bSizerButtonsUpper wxHORIZONTAL @@ -9986,17 +9978,6 @@ - - - - 5 - wxALIGN_CENTER_HORIZONTAL - 0 - - - bSizerButtonsLower - wxHORIZONTAL - none 5 wxALL @@ -10030,7 +10011,7 @@ 0 0 wxID_ANY - Geometry Transform + Transform Primitive 0 @@ -10085,94 +10066,6 @@ - - 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Import Primitives - - 0 - - - 0 - - 1 - m_buttonImport - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - onImportPrimitives - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pcbnew/dialogs/dialog_pad_properties_base.h b/pcbnew/dialogs/dialog_pad_properties_base.h index 5aee5fde12..60f2d46618 100644 --- a/pcbnew/dialogs/dialog_pad_properties_base.h +++ b/pcbnew/dialogs/dialog_pad_properties_base.h @@ -12,7 +12,6 @@ #include #include class TEXT_CTRL_EVAL; -class WIDGET_NET_SELECTOR; #include "dialog_shim.h" #include @@ -22,8 +21,9 @@ class WIDGET_NET_SELECTOR; #include #include #include -#include +#include #include +#include #include #include #include @@ -65,7 +65,7 @@ class DIALOG_PAD_PROPERTIES_BASE : public DIALOG_SHIM wxStaticText* m_PadNumText; wxTextCtrl* m_PadNumCtrl; wxStaticText* m_PadNameText; - WIDGET_NET_SELECTOR* m_PadNetNameCombo; + NET_SELECTOR* m_PadNetSelector; wxStaticText* m_staticText44; wxChoice* m_PadType; wxStaticText* m_staticText45; @@ -174,7 +174,6 @@ class DIALOG_PAD_PROPERTIES_BASE : public DIALOG_SHIM wxButton* m_buttonAddShape; wxButton* m_buttonDup; wxButton* m_buttonGeometry; - wxButton* m_buttonImport; wxStaticText* m_parentInfoLine1; wxStaticText* m_parentInfoLine2; wxPanel* m_panelShowPad; @@ -204,7 +203,6 @@ class DIALOG_PAD_PROPERTIES_BASE : public DIALOG_SHIM virtual void onAddPrimitive( wxCommandEvent& event ) { event.Skip(); } virtual void onDuplicatePrimitive( wxCommandEvent& event ) { event.Skip(); } virtual void onGeometryTransform( wxCommandEvent& event ) { event.Skip(); } - virtual void onImportPrimitives( wxCommandEvent& event ) { event.Skip(); } virtual void OnPaintShowPanel( wxPaintEvent& event ) { event.Skip(); } virtual void onChangePadMode( wxCommandEvent& event ) { event.Skip(); } virtual void OnCancel( wxCommandEvent& event ) { event.Skip(); } diff --git a/pcbnew/dialogs/dialog_track_via_properties.cpp b/pcbnew/dialogs/dialog_track_via_properties.cpp index c93f2982ee..55c566f961 100644 --- a/pcbnew/dialogs/dialog_track_via_properties.cpp +++ b/pcbnew/dialogs/dialog_track_via_properties.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 CERN + * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -28,8 +29,9 @@ #include #include #include - -#include +#include +#include +#include #include #define MIN_SIZE ( int )( 0.001 * IU_PER_MM ) @@ -38,7 +40,9 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen const SELECTION& aItems, COMMIT& aCommit ) : DIALOG_TRACK_VIA_PROPERTIES_BASE( aParent ), - m_items( aItems ), m_commit( aCommit ), + m_frame( aParent ), + m_items( aItems ), + m_commit( aCommit ), m_trackStartX( aParent, m_TrackStartXLabel, m_TrackStartXCtrl, m_TrackStartXUnit ), m_trackStartY( aParent, m_TrackStartYLabel, m_TrackStartYCtrl, m_TrackStartYUnit ), m_trackEndX( aParent, m_TrackEndXLabel, m_TrackEndXCtrl, m_TrackEndXUnit ), @@ -55,11 +59,7 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen VIATYPE_T viaType = VIA_NOT_DEFINED; - m_haveUniqueNet = true; - int prevNet = -1; - - m_NetComboBox->SetBoard( aParent->GetBoard() ); - m_NetComboBox->Enable( true ); + m_netSelector->SetNetInfo( &aParent->GetBoard()->GetNetInfo() ); m_TrackLayerCtrl->SetLayersHotkeys( false ); m_TrackLayerCtrl->SetNotAllowedLayerSet( LSET::AllNonCuMask() ); @@ -76,32 +76,24 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen m_ViaEndLayer->SetBoardFrame( aParent ); m_ViaEndLayer->Resync(); + bool nets = false; + int net = 0; bool hasLocked = false; bool hasUnlocked = false; - for( auto& item : m_items ) - { - int net = static_cast(item)->GetNetCode(); - - if( prevNet >= 0 && net != prevNet ) - { - DBG( printf("prev %d net %d\n", net, prevNet ) ); - m_haveUniqueNet = false; - break; - } - - prevNet = net; - } - - if ( m_haveUniqueNet ) - m_NetComboBox->SetSelectedNet( prevNet ); - else - m_NetComboBox->SetMultiple( true ); - - // Look for values that are common for every item that is selected for( auto& item : m_items ) { + if( !nets ) + { + net = static_cast( item )->GetNetCode(); + nets = true; + } + else if( net != static_cast( item )->GetNetCode() ) + { + net = -1; + } + switch( item->Type() ) { case PCB_TRACE_T: @@ -116,7 +108,7 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen m_trackEndY.SetValue( t->GetEnd().y ); m_trackWidth.SetValue( t->GetWidth() ); m_TrackLayerCtrl->SetLayerSelection( t->GetLayer() ); - m_tracks = true; + m_tracks = true; } else // check if values are the same for every selected track { @@ -202,6 +194,11 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen } } + if ( net >= 0 ) + m_netSelector->SetSelectedNetcode( net ); + else + m_netSelector->SetIndeterminate(); + wxASSERT( m_tracks || m_vias ); if( m_vias ) @@ -236,14 +233,13 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen m_ViaTypeChoice->Enable(); - if( viaType == VIA_THROUGH ) - m_ViaTypeChoice->SetSelection( 0 ); - else if( viaType == VIA_MICROVIA ) - m_ViaTypeChoice->SetSelection( 1 ); - else if ( viaType == VIA_BLIND_BURIED ) - m_ViaTypeChoice->SetSelection( 2 ); - else if( viaType == VIA_NOT_DEFINED ) - m_ViaTypeChoice->SetSelection( 3 ); + switch( viaType ) + { + case VIA_THROUGH: m_ViaTypeChoice->SetSelection( 0 ); break; + case VIA_MICROVIA: m_ViaTypeChoice->SetSelection( 1 ); break; + case VIA_BLIND_BURIED: m_ViaTypeChoice->SetSelection( 2 ); break; + case VIA_NOT_DEFINED: m_ViaTypeChoice->SetSelection( 3 ); break; + } m_ViaStartLayer->Enable( viaType != VIA_THROUGH ); m_ViaEndLayer->Enable( viaType != VIA_THROUGH ); @@ -297,16 +293,72 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen } +bool DIALOG_TRACK_VIA_PROPERTIES::confirmPadChange( const std::set& connectedPads ) +{ + wxString msg; + + if( connectedPads.size() == 1 ) + { + D_PAD* pad = *connectedPads.begin(); + msg.Printf( _( "This will change the net assigned to %s pad %s to %s.\n" + "Do you wish to continue?" ), + pad->GetParent()->GetReference(), + pad->GetName(), + m_netSelector->GetValue() ); + } + else if( connectedPads.size() == 2 ) + { + D_PAD* pad1 = *connectedPads.begin(); + D_PAD* pad2 = *( ++connectedPads.begin() ); + msg.Printf( _( "This will change the net assigned to %s pad %s and %s pad %s to %s.\n" + "Do you wish to continue?" ), + pad1->GetParent()->GetReference(), + pad1->GetName(), + pad2->GetParent()->GetReference(), + pad2->GetName(), + m_netSelector->GetValue() ); + } + else + { + msg.Printf( _( "This will change the net assigned to %d connected pads to %s.\n" + "Do you wish to continue?" ), + connectedPads.size(), + m_netSelector->GetValue() ); + } + + KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING ); + dlg.SetOKLabel( _( "Continue" ) ); + dlg.DoNotShowCheckbox(); + + return dlg.ShowModal() == wxID_OK; +} + + bool DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow() { + std::set connectedPads; + auto connectivity = m_frame->GetBoard()->GetConnectivity(); + + if ( !m_netSelector->IsIndeterminate() ) + { + for( auto& item : m_items ) + { + auto boardItem = static_cast( item ); + connectivity->GetConnectedPads( boardItem, &connectedPads ); + } + } + // Run validations: + if( connectedPads.size() ) + { + if( !confirmPadChange( connectedPads ) ) + return false; + } + if( m_vias ) { - if( !m_viaDiameter.Validate( true ) ) - return false; - - if( !m_viaDrill.Validate( true ) ) + if( !m_viaDiameter.Validate( true ) || !m_viaDrill.Validate( true ) ) return false; if( !m_trackNetclass->IsChecked() && m_viaDiameter.GetValue() <= m_viaDrill.GetValue() ) @@ -372,11 +424,8 @@ bool DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow() if( changeLock ) t->SetLocked( setLock ); - if ( m_NetComboBox->IsUniqueNetSelected() ) - { - DBG( printf( "snc %d\n", m_NetComboBox->GetSelectedNet() ) ); - t->SetNetCode( m_NetComboBox->GetSelectedNet() ); - } + if ( !m_netSelector->IsIndeterminate() ) + t->SetNetCode( m_netSelector->GetSelectedNetcode() ); break; } @@ -396,18 +445,10 @@ bool DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow() { switch( m_ViaTypeChoice->GetSelection() ) { - case 0: - v->SetViaType( VIA_THROUGH ); - v->SanitizeLayers(); - break; - case 1: - v->SetViaType( VIA_MICROVIA ); - break; - case 2: - v->SetViaType( VIA_BLIND_BURIED ); - break; - default: - break; + default: + case 0: v->SetViaType( VIA_THROUGH ); v->SanitizeLayers(); break; + case 1: v->SetViaType( VIA_MICROVIA ); break; + case 2: v->SetViaType( VIA_BLIND_BURIED ); break; } } @@ -439,7 +480,6 @@ bool DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow() case VIA_MICROVIA: v->SetWidth( v->GetNetClass()->GetuViaDiameter() ); v->SetDrill( v->GetNetClass()->GetuViaDrill() ); - break; } } @@ -452,11 +492,8 @@ bool DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow() v->SetDrill( m_viaDrill.GetValue() ); } - if ( m_NetComboBox->IsUniqueNetSelected() ) - { - DBG( printf( "snc %d\n", m_NetComboBox->GetSelectedNet() ) ); - v->SetNetCode( m_NetComboBox->GetSelectedNet() ); - } + if ( !m_netSelector->IsIndeterminate() ) + v->SetNetCode( m_netSelector->GetSelectedNetcode() ); if( changeLock ) v->SetLocked( setLock ); @@ -470,6 +507,18 @@ bool DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow() } } + if ( !m_netSelector->IsIndeterminate() ) + { + // Commit::Push() will rebuild connectivitiy propagating nets from connected pads + // outwards. We therefore have to update the connected pads in order for the net + // change to "stick". + for( D_PAD* pad : connectedPads ) + { + m_commit.Modify( pad ); + pad->SetNetCode( m_netSelector->GetSelectedNetcode() ); + } + } + m_commit.Push( _( "Edit track/via properties" ) ); return true; diff --git a/pcbnew/dialogs/dialog_track_via_properties.h b/pcbnew/dialogs/dialog_track_via_properties.h index 3b417c5f05..884b23d48a 100644 --- a/pcbnew/dialogs/dialog_track_via_properties.h +++ b/pcbnew/dialogs/dialog_track_via_properties.h @@ -29,8 +29,9 @@ class SELECTION; class COMMIT; - +class NET_SELECTOR_COMBO_POPUP; class PCB_BASE_FRAME; +class D_PAD; class DIALOG_TRACK_VIA_PROPERTIES : public DIALOG_TRACK_VIA_PROPERTIES_BASE { @@ -48,6 +49,9 @@ private: void onViaSelect( wxCommandEvent& aEvent ); void onViaEdit( wxCommandEvent& aEvent ); + bool confirmPadChange( const std::set& connectedPads ); + + PCB_BASE_FRAME* m_frame; const SELECTION& m_items; // List of items to be modified. COMMIT& m_commit; // An undo record to add any changes to. @@ -60,7 +64,4 @@ private: bool m_tracks; // True if dialog displays any track properties. bool m_vias; // True if dialog displays any via properties. - - ///> Fixme - bool m_haveUniqueNet; }; diff --git a/pcbnew/dialogs/dialog_track_via_properties_base.cpp b/pcbnew/dialogs/dialog_track_via_properties_base.cpp index b56fd2a625..47a1734efd 100644 --- a/pcbnew/dialogs/dialog_track_via_properties_base.cpp +++ b/pcbnew/dialogs/dialog_track_via_properties_base.cpp @@ -6,7 +6,6 @@ /////////////////////////////////////////////////////////////////////////// #include "pcb_layer_box_selector.h" -#include "widgets/widget_net_selector.h" #include "dialog_track_via_properties_base.h" @@ -20,12 +19,12 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa m_sbCommonSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Common") ), wxHORIZONTAL ); - m_staticText24 = new wxStaticText( m_sbCommonSizer->GetStaticBox(), wxID_ANY, _("Net:"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticText24->Wrap( -1 ); - m_sbCommonSizer->Add( m_staticText24, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + m_netSelectorLabel = new wxStaticText( m_sbCommonSizer->GetStaticBox(), wxID_ANY, _("Net:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_netSelectorLabel->Wrap( -1 ); + m_sbCommonSizer->Add( m_netSelectorLabel, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - m_NetComboBox = new WIDGET_NET_SELECTOR( m_sbCommonSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY ); - m_sbCommonSizer->Add( m_NetComboBox, 6, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + m_netSelector = new NET_SELECTOR( m_sbCommonSizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + m_sbCommonSizer->Add( m_netSelector, 5, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_sbCommonSizer->Add( 0, 0, 1, wxEXPAND, 5 ); diff --git a/pcbnew/dialogs/dialog_track_via_properties_base.fbp b/pcbnew/dialogs/dialog_track_via_properties_base.fbp index 27833b71f0..3f0b5bce9b 100644 --- a/pcbnew/dialogs/dialog_track_via_properties_base.fbp +++ b/pcbnew/dialogs/dialog_track_via_properties_base.fbp @@ -146,7 +146,7 @@ 0 1 - m_staticText24 + m_netSelectorLabel 1 @@ -189,11 +189,11 @@ - + 5 - wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT - 6 - + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT + 5 + 1 1 1 @@ -207,10 +207,12 @@ 1 0 - + NET_SELECTOR 1 + 1 + 0 Dock 0 @@ -222,6 +224,7 @@ 0 0 wxID_ANY + #include <widgets/net_selector.h> 0 @@ -229,7 +232,7 @@ 0 1 - m_NetComboBox + m_netSelector 1 @@ -237,25 +240,16 @@ 1 Resizable - -1 + 1 - wxCB_DROPDOWN|wxCB_READONLY - WIDGET_NET_SELECTOR; widgets/widget_net_selector.h + ; ; forward_declare 0 - - wxFILTER_NONE - wxDefaultValidator - - - - - @@ -277,8 +271,6 @@ - - diff --git a/pcbnew/dialogs/dialog_track_via_properties_base.h b/pcbnew/dialogs/dialog_track_via_properties_base.h index 30200a5065..19f4a5732b 100644 --- a/pcbnew/dialogs/dialog_track_via_properties_base.h +++ b/pcbnew/dialogs/dialog_track_via_properties_base.h @@ -12,7 +12,6 @@ #include #include class PCB_LAYER_BOX_SELECTOR; -class WIDGET_NET_SELECTOR; #include "dialog_shim.h" #include @@ -21,7 +20,7 @@ class WIDGET_NET_SELECTOR; #include #include #include -#include +#include #include #include #include @@ -44,8 +43,8 @@ class DIALOG_TRACK_VIA_PROPERTIES_BASE : public DIALOG_SHIM protected: wxBoxSizer* m_MainSizer; wxStaticBoxSizer* m_sbCommonSizer; - wxStaticText* m_staticText24; - WIDGET_NET_SELECTOR* m_NetComboBox; + wxStaticText* m_netSelectorLabel; + NET_SELECTOR* m_netSelector; wxCheckBox* m_lockedCbox; wxStaticBoxSizer* m_sbTrackSizer; wxStaticText* m_TrackStartXLabel; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 5f93f3afcd..f00f841d50 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -630,7 +630,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) if ( !changeTrackWidthOnClick( selection ) ) { DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit ); - dlg.ShowModal(); + dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR } } else if( selection.Size() == 1 ) // Properties are displayed when there is only one item selected