28#include <wx/textdlg.h>
56 wxGridCellAttr* attr =
new wxGridCellAttr;
62 wxGridCellAttr* roAttr =
new wxGridCellAttr;
63 roAttr->SetReadOnly(
true );
66 wxGridCellAttr* roAttr2 =
new wxGridCellAttr;
67 roAttr2->SetReadOnly(
true );
76 [
this]( wxGridEvent& evt )
84 wxMessageBox( wxString::Format(
85 _(
"Name '%s' contains invalid characters." ), val ),
86 _(
"Net Chains" ), wxOK | wxICON_ERROR,
this );
91 int gridRow = evt.GetRow();
97 if( dataIdx >= 0 && dataIdx <
static_cast<int>(
m_chainRows.size() ) )
123 std::shared_ptr<NET_SETTINGS> ns =
m_frame->Prj().GetProjectFile().NetSettings();
124 std::map<wxString, wxString> chainToClass;
127 chainToClass = ns->GetNetChainClasses();
142 auto it = chainToClass.find( row.
origName );
144 if( it != chainToClass.end() )
151 std::set<wxString> distinctClasses;
153 for(
const auto& [chainName, className] : chainToClass )
155 if( !className.IsEmpty() )
156 distinctClasses.insert( className );
159 for(
const wxString& cn : distinctClasses )
171 wxArrayString choices;
172 choices.Add( wxEmptyString );
176 if( !cr.deletePending && !cr.newName.IsEmpty() )
177 choices.Add( cr.newName );
180 wxGridCellAttr* attr =
new wxGridCellAttr;
181 attr->SetEditor(
new wxGridCellChoiceEditor( choices,
true ) );
188 wxArrayString choices;
189 choices.Add( wxEmptyString );
193 std::shared_ptr<NET_SETTINGS> ns =
m_frame->Prj().GetProjectFile().NetSettings();
197 for(
const auto& [
name, nc] : ns->GetNetclasses() )
202 wxGridCellAttr* attr =
new wxGridCellAttr;
203 attr->SetEditor(
new wxGridCellChoiceEditor( choices,
true ) );
220 if( !row.deletePending )
224 m_chainsHeader->SetLabel( wxString::Format(
_(
"%d net chain(s)" ), activeCount ) );
242 wxString::Format(
_(
"%zu nets" ), row.
memberNets.size() ) );
251 int dataIdx = ( sel >= 0 && sel < static_cast<int>(
m_gridToChainIdx.size() ) )
266 std::map<wxString, int> memberCount;
270 if( row.deletePending || row.newChainClass.IsEmpty() )
273 ++memberCount[row.newChainClass];
279 int r =
static_cast<int>( i );
283 wxString::Format( wxT(
"%d" ),
324 if( colorStr.IsEmpty() )
349 wxMessageBox( wxString::Format(
_(
"Net chain on row %zu cannot have an empty name." ),
351 _(
"Net Chains" ), wxOK | wxICON_ERROR,
this );
357 wxMessageBox( wxString::Format(
_(
"Net chain name '%s' contains invalid characters." ),
359 _(
"Net Chains" ), wxOK | wxICON_ERROR,
this );
365 wxMessageBox( wxString::Format(
_(
"Duplicate net chain name '%s' on row %zu." ),
367 _(
"Net Chains" ), wxOK | wxICON_ERROR,
this );
382 wxMessageBox( wxString::Format(
_(
"Class on row %zu cannot have an empty name." ),
384 _(
"Net Chain Classes" ), wxOK | wxICON_ERROR,
this );
390 wxMessageBox( wxString::Format(
_(
"Duplicate class name '%s' on row %zu." ),
392 _(
"Net Chain Classes" ), wxOK | wxICON_ERROR,
this );
420 std::shared_ptr<NET_SETTINGS> ns =
m_frame->Prj().GetProjectFile().NetSettings();
425 if( row.deletePending )
428 if( !row.origName.IsEmpty() && row.origName != row.newName )
432 if( ns && !row.origName.IsEmpty() )
434 wxString oldClass = ns->GetNetChainClass( row.origName );
436 if( !oldClass.IsEmpty() )
438 ns->SetNetChainClass( row.origName, wxEmptyString );
439 ns->SetNetChainClass( row.newName, oldClass );
443 row.origName = row.newName;
451 if( row.deletePending || !row.livePtr )
454 row.livePtr->SetColor( row.newColor );
455 row.livePtr->SetNetClass( row.newNetClass );
463 if( row.deletePending )
466 ns->SetNetChainClass( row.newName, row.newChainClass );
473 if( !row.deletePending )
479 ns->SetNetChainClass( row.origName, wxEmptyString );
490 if( !cls.deletePending )
495 std::vector<wxString> toClear;
497 for(
const auto& [chainName, className] : ns->GetNetChainClasses() )
499 if( className == cls.origName )
500 toClear.push_back( chainName );
503 for(
const wxString& chainName : toClear )
504 ns->SetNetChainClass( chainName, wxEmptyString );
509 if( cls.deletePending )
512 if( !cls.origName.IsEmpty() && cls.origName != cls.newName )
516 std::vector<wxString> toRename;
518 for(
const auto& [chainName, className] : ns->GetNetChainClasses() )
520 if( className == cls.origName )
521 toRename.push_back( chainName );
524 for(
const wxString& chainName : toRename )
525 ns->SetNetChainClass( chainName, cls.newName );
575 for(
int i = 0; i < static_cast<int>(
m_chainRows.size() ); ++i )
577 if( i == aExceptRow )
583 if(
m_chainRows[i].newName == aName && !aName.IsEmpty() )
593 for(
int i = 0; i < static_cast<int>(
m_classRows.size() ); ++i )
595 if( i == aExceptRow )
601 if(
m_classRows[i].newName == aName && !aName.IsEmpty() )
618 if( wxMessageBox( wxString::Format(
_(
"Delete net chain '%s'?" ), row.
newName ),
619 _(
"Delete Net Chain" ), wxYES_NO | wxICON_QUESTION,
this ) != wxYES )
632 int gridRow = aEvent.GetRow();
633 int dataIdx = ( gridRow >= 0 && gridRow < static_cast<int>(
m_gridToChainIdx.size() ) )
644 if( aRow < 0 || aRow >=
static_cast<int>(
m_chainRows.size() ) )
652 wxString label = row.
newName.IsEmpty()
653 ? wxString::Format(
_(
"Member Nets (%zu)" ), row.
memberNets.size() )
654 : wxString::Format(
_(
"Member Nets \u2014 %s (%zu)" ), row.
newName,
659 wxArrayString sorted;
672 wxTextEntryDialog dlg(
this,
_(
"New net chain class name:" ),
_(
"Add Class" ) );
674 if( dlg.ShowModal() != wxID_OK )
677 wxString
name = dlg.GetValue();
681 wxMessageBox(
_(
"That class name is empty or already in use." ),
682 _(
"Add Class" ), wxOK | wxICON_ERROR,
this );
700 if( r < 0 || r >=
static_cast<int>(
m_classRows.size() ) )
705 wxTextEntryDialog dlg(
this,
_(
"Rename net chain class:" ),
_(
"Rename Class" ),
708 if( dlg.ShowModal() != wxID_OK )
711 wxString
name = dlg.GetValue();
715 wxMessageBox(
_(
"That class name is empty or already in use." ),
716 _(
"Rename Class" ), wxOK | wxICON_ERROR,
this );
720 wxString oldName = row.
newName;
725 if( chainRow.newChainClass == oldName )
726 chainRow.newChainClass =
name;
739 if( r < 0 || r >=
static_cast<int>(
m_classRows.size() ) )
744 if( wxMessageBox( wxString::Format(
_(
"Delete net chain class '%s'? Chains assigned to it "
745 "will become unclassified." ),
747 _(
"Delete Class" ), wxYES_NO | wxICON_QUESTION,
this ) != wxYES )
757 if( chainRow.newChainClass == row.
newName )
758 chainRow.newChainClass = wxEmptyString;
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Calculate the connectivity of a schematic and generates netlists.
bool RenameCommittedNetChain(const wxString &aOld, const wxString &aNew)
Rename a committed net chain.
const std::vector< std::unique_ptr< SCH_NETCHAIN > > & GetCommittedNetChains() const
Return user-created (committed) net chains (legacy accessor retained under net-chain API).
bool DeleteCommittedNetChain(const wxString &aName)
Delete a committed net chain by name.
A color representation with 4 components: red, green, blue, alpha.
wxString ToCSSString() const
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
wxStaticText * m_chainsHeader
wxStaticText * m_membersLabel
STD_BITMAP_BUTTON * m_addClassButton
PANEL_SETUP_NET_CHAINS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxListBox * m_membersListBox
STD_BITMAP_BUTTON * m_renameClassButton
STD_BITMAP_BUTTON * m_deleteClassButton
STD_BITMAP_BUTTON * m_deleteChainButton
void updateMembersDetail(int aRow)
void rebuildClassesGrid()
PANEL_SETUP_NET_CHAINS(wxWindow *aParent, SCH_EDIT_FRAME *aFrame)
int selectedClassRow() const
int selectedChainRow() const
void refreshChainClassDropdownChoices()
void OnClassDeleteClicked(wxCommandEvent &aEvent) override
void refreshNetClassDropdownChoices()
std::vector< CHAIN_ROW > m_chainRows
void OnClassAddClicked(wxCommandEvent &aEvent) override
~PANEL_SETUP_NET_CHAINS() override
bool nameInChainGridAlready(const wxString &aName, int aExceptRow) const
void OnChainGridSelectionChanged(wxGridEvent &aEvent) override
bool TransferDataFromWindow() override
std::vector< CLASS_ROW > m_classRows
void OnClassRenameClicked(wxCommandEvent &aEvent) override
bool TransferDataToWindow() override
void OnDeleteChainClicked(wxCommandEvent &aEvent) override
bool nameInClassGridAlready(const wxString &aName, int aExceptRow) const
std::vector< int > m_gridToChainIdx
Schematic editor (Eeschema) main window.
static bool IsValidName(const wxString &aName)
static const wxString c_statusPotential
static const wxString c_statusCommitted
std::set< wxString > memberNets
const SHAPE_LINE_CHAIN chain