diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 5ff510421e..2d30d24dd0 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -400,6 +400,7 @@ set( PCB_COMMON_SRCS ../pcbnew/kicad_plugin.cpp ../pcbnew/gpcb_plugin.cpp ../pcbnew/pcb_netlist.cpp + widgets/widget_net_selector.cpp pcb_plot_params_keywords.cpp pcb_keywords.cpp ../pcbnew/pcb_parser.cpp diff --git a/common/widgets/widget_net_selector.cpp b/common/widgets/widget_net_selector.cpp new file mode 100644 index 0000000000..a9bea6dcfc --- /dev/null +++ b/common/widgets/widget_net_selector.cpp @@ -0,0 +1,107 @@ +/* + * 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 + +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 ) +{ + +} + +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& n : m_nets ) + { + if( n.code == aNetcode ) + { + SetSelection( n.pos ); + return; + } + } +} + +int WIDGET_NET_SELECTOR::GetSelectedNet() +{ + int pos = GetSelection(); + for( const auto& n : m_nets ) + { + if( n.pos == pos ) + return n.code; + } + + return 0; +} + +bool WIDGET_NET_SELECTOR::IsUniqueNetSelected() const +{ + if( m_multiple && ( GetSelection() == ( GetCount() - 1 ) ) ) + return false; + + return true; +} + +void WIDGET_NET_SELECTOR::SetBoard( BOARD* aBoard ) +{ + auto& netinfo = aBoard->GetNetInfo(); + + Append( wxT("" )); + + for(int i = 1; i < netinfo.GetNetCount(); i++) + { + NETINFO_ITEM *ni = netinfo.GetNetItem(i); + NET n; + n.name = ni->GetNetname(); + n.code = i; + m_nets.push_back( n ); + } + + std::sort( m_nets.begin(), m_nets.end() ); + + for ( auto& n : m_nets ) + { + n.pos = Append( n.name ); + } +} diff --git a/include/widgets/widget_net_selector.h b/include/widgets/widget_net_selector.h new file mode 100644 index 0000000000..939a6180da --- /dev/null +++ b/include/widgets/widget_net_selector.h @@ -0,0 +1,66 @@ +/* + * 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: + 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; + + void SetBoard( BOARD* m_board ); + +private: + struct NET { + int code; + int pos; + wxString name; + + bool operator <( const NET& aOther ) const + { + return name < aOther.name; + } + }; + + bool m_multiple; + std::vector m_nets; + +}; + +#endif diff --git a/pcbnew/dialogs/dialog_track_via_properties.cpp b/pcbnew/dialogs/dialog_track_via_properties.cpp index a55858e935..0658ffe90f 100644 --- a/pcbnew/dialogs/dialog_track_via_properties.cpp +++ b/pcbnew/dialogs/dialog_track_via_properties.cpp @@ -29,6 +29,7 @@ #include #include +#include #include DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParent, const SELECTION& aItems ) : @@ -55,9 +56,40 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen boost::optional viaX, viaY, viaDiameter; boost::optional viaDrill = boost::make_optional( false, 0 ); + m_haveUniqueNet = true; + int prevNet = -1; + + printf("Create!\n"); + + m_NetComboBox->SetBoard( aParent->GetBoard() ); + m_NetComboBox->Enable(1); + bool hasLocked = false; bool hasUnlocked = false; + for( auto& item : m_items ) + { + int net = static_cast(item)->GetNetCode(); + + if( prevNet >= 0 && net != prevNet ) + { + 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 ) { @@ -267,6 +299,13 @@ bool DIALOG_TRACK_VIA_PROPERTIES::Apply( COMMIT& aCommit ) if( changeLock ) t->SetLocked( setLock ); + if ( m_NetComboBox->IsUniqueNetSelected() ) + { + printf("snc %d\n", m_NetComboBox->GetSelectedNet()); + t->SetNetCode( m_NetComboBox->GetSelectedNet() ); + } + + break; } @@ -316,6 +355,13 @@ bool DIALOG_TRACK_VIA_PROPERTIES::Apply( COMMIT& aCommit ) if( m_viaDrill.Valid() ) v->SetDrill( m_viaDrill.GetValue() ); + + } + + if ( m_NetComboBox->IsUniqueNetSelected() ) + { + printf("snc %d\n", m_NetComboBox->GetSelectedNet()); + v->SetNetCode( m_NetComboBox->GetSelectedNet() ); } if( changeLock ) diff --git a/pcbnew/dialogs/dialog_track_via_properties.h b/pcbnew/dialogs/dialog_track_via_properties.h index 85f78308b4..3be7d4d77f 100644 --- a/pcbnew/dialogs/dialog_track_via_properties.h +++ b/pcbnew/dialogs/dialog_track_via_properties.h @@ -84,4 +84,7 @@ private: ///> Flag that determines if the dialog displays via properties. bool m_vias; + + ///> 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 96913c679e..7cc9c2e5c3 100644 --- a/pcbnew/dialogs/dialog_track_via_properties_base.cpp +++ b/pcbnew/dialogs/dialog_track_via_properties_base.cpp @@ -6,6 +6,7 @@ /////////////////////////////////////////////////////////////////////////// #include "class_pcb_layer_box_selector.h" +#include "widgets/widget_net_selector.h" #include "dialog_track_via_properties_base.h" @@ -29,9 +30,7 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa m_staticText24->Wrap( -1 ); fgSizer6->Add( m_staticText24, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - m_NetComboBox = new wxComboBox( m_sbCommonSizer->GetStaticBox(), wxID_ANY, _("Combo!"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); - m_NetComboBox->Enable( false ); - + m_NetComboBox = new WIDGET_NET_SELECTOR( m_sbCommonSizer->GetStaticBox(), wxID_ANY, _("Combo!"), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY ); fgSizer6->Add( m_NetComboBox, 1, wxALL|wxEXPAND, 5 ); @@ -46,10 +45,10 @@ DIALOG_TRACK_VIA_PROPERTIES_BASE::DIALOG_TRACK_VIA_PROPERTIES_BASE( wxWindow* pa fgSizer5->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); m_lockedCbox = new wxCheckBox( m_sbCommonSizer->GetStaticBox(), wxID_ANY, _("Locked"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE ); - fgSizer5->Add( m_lockedCbox, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); + fgSizer5->Add( m_lockedCbox, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - m_sbCommonSizer->Add( fgSizer5, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 ); + m_sbCommonSizer->Add( fgSizer5, 1, wxEXPAND|wxALIGN_BOTTOM, 5 ); m_MainSizer->Add( m_sbCommonSizer, 0, wxEXPAND|wxALL, 5 ); diff --git a/pcbnew/dialogs/dialog_track_via_properties_base.fbp b/pcbnew/dialogs/dialog_track_via_properties_base.fbp index 71d5f6b70a..a886bb710a 100644 --- a/pcbnew/dialogs/dialog_track_via_properties_base.fbp +++ b/pcbnew/dialogs/dialog_track_via_properties_base.fbp @@ -26,7 +26,7 @@ UI 0 0 - + 0 wxAUI_MGR_DEFAULT @@ -88,16 +88,16 @@ - + m_MainSizer wxVERTICAL protected - + 5 wxEXPAND|wxALL 0 - + wxID_ANY Common @@ -105,11 +105,11 @@ wxHORIZONTAL protected - + 5 wxEXPAND 1 - + 2 wxBOTH 1 @@ -121,11 +121,11 @@ none 0 0 - + 5 wxALIGN_CENTER_VERTICAL|wxALL 0 - + 1 1 1 @@ -204,11 +204,11 @@ - + 5 wxALL|wxEXPAND 1 - + 1 1 1 @@ -230,7 +230,7 @@ Dock 0 Left - 0 + 1 1 @@ -255,8 +255,8 @@ -1 1 - - + wxCB_DROPDOWN|wxCB_READONLY + WIDGET_NET_SELECTOR; widgets/widget_net_selector.h 0 @@ -297,11 +297,11 @@ - + 5 wxEXPAND | wxALL 0 - + 1 1 1 @@ -378,11 +378,11 @@ - + 5 - wxEXPAND|wxALIGN_CENTER_VERTICAL + wxEXPAND|wxALIGN_BOTTOM 1 - + 2 wxBOTH @@ -394,11 +394,11 @@ none 0 0 - + 5 - wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL 1 - + 1 1 1 @@ -486,11 +486,11 @@ - + 5 wxALL|wxEXPAND 0 - + wxID_ANY Tracks @@ -498,11 +498,11 @@ wxHORIZONTAL protected - + 5 wxEXPAND 1 - + 3 wxBOTH @@ -1625,11 +1625,11 @@ - + 5 wxEXPAND 1 - + 3 wxBOTH @@ -1898,21 +1898,21 @@ - + 5 wxEXPAND 1 - + 0 protected 0 - + 5 wxBOTTOM|wxTOP 0 - + 1 1 1 @@ -1996,11 +1996,11 @@ - + 5 wxEXPAND 1 - + 0 protected 0 @@ -2194,11 +2194,11 @@ - + 5 wxALL|wxEXPAND 0 - + wxID_ANY Vias @@ -2206,11 +2206,11 @@ wxHORIZONTAL protected - + 5 wxEXPAND|wxALL 1 - + 3 wxBOTH @@ -2819,11 +2819,11 @@ - + 5 wxEXPAND|wxALL 1 - + 3 wxBOTH @@ -3266,11 +3266,11 @@ - + 5 wxALIGN_CENTER_VERTICAL|wxALL 0 - + 1 1 1 @@ -3349,11 +3349,11 @@ - + 5 wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL 0 - + 1 1 1 @@ -3432,11 +3432,11 @@ - + 5 wxEXPAND 0 - + 1 1 1 @@ -3520,21 +3520,21 @@ - + 5 wxEXPAND 1 - + 0 protected 0 - + 5 wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL 0 - + 1 1 1 @@ -3613,11 +3613,11 @@ - + 5 wxEXPAND 0 - + 1 1 1 @@ -3704,21 +3704,21 @@ - + 5 wxEXPAND 1 - + 0 protected 0 - + 5 wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL 0 - + 1 1 1 @@ -3797,11 +3797,11 @@ - + 5 wxEXPAND 0 - + 1 1 1 @@ -3888,31 +3888,31 @@ - + 5 wxEXPAND 1 - + 0 protected 0 - + 5 wxEXPAND 1 - + 0 protected 0 - + 5 wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP 0 - + 1 1 1 @@ -3996,11 +3996,11 @@ - + 5 wxEXPAND 1 - + 0 protected 0 @@ -4010,11 +4010,11 @@ - + 5 wxALL|wxEXPAND 0 - + 0 1 0 diff --git a/pcbnew/dialogs/dialog_track_via_properties_base.h b/pcbnew/dialogs/dialog_track_via_properties_base.h index 789ada01d0..721d9144eb 100644 --- a/pcbnew/dialogs/dialog_track_via_properties_base.h +++ b/pcbnew/dialogs/dialog_track_via_properties_base.h @@ -13,6 +13,7 @@ #include class DIALOG_SHIM; class PCB_LAYER_BOX_SELECTOR; +class WIDGET_NET_SELECTOR; #include "dialog_shim.h" #include @@ -46,7 +47,7 @@ class DIALOG_TRACK_VIA_PROPERTIES_BASE : public DIALOG_SHIM wxBoxSizer* m_MainSizer; wxStaticBoxSizer* m_sbCommonSizer; wxStaticText* m_staticText24; - wxComboBox* m_NetComboBox; + WIDGET_NET_SELECTOR* m_NetComboBox; wxStaticLine* m_staticline3; wxCheckBox* m_lockedCbox; wxStaticBoxSizer* m_sbTrackSizer;