28#include <wx/textdlg.h>
56 wxGridCellAttr* attr =
new wxGridCellAttr;
65 wxGridCellAttr* roAttr =
new wxGridCellAttr;
66 roAttr->SetReadOnly(
true );
69 wxGridCellAttr* roAttr2 =
new wxGridCellAttr;
70 roAttr2->SetReadOnly(
true );
79 [
this]( wxGridEvent& evt )
87 wxMessageBox( wxString::Format(
_(
"Name '%s' contains invalid characters." ), val ),
88 _(
"Net Chains" ), wxOK | wxICON_ERROR,
this );
93 int gridRow = evt.GetRow();
99 if( dataIdx >= 0 && dataIdx <
static_cast<int>(
m_chainRows.size() ) )
120 auto& manager =
m_frame->Schematic().NetChains();
122 std::shared_ptr<NET_SETTINGS> ns =
m_frame->Prj().GetProjectFile().NetSettings();
123 std::map<wxString, wxString> chainToClass;
126 chainToClass = ns->GetNetChainClasses();
128 for(
const std::unique_ptr<SCH_NETCHAIN>&
chain : manager.GetCommittedNetChains() )
141 auto it = chainToClass.find( row.
origName );
143 if( it != chainToClass.end() )
150 std::set<wxString> distinctClasses;
152 for(
const auto& [chainName, className] : chainToClass )
154 if( !className.IsEmpty() )
155 distinctClasses.insert( className );
158 for(
const wxString& cn : distinctClasses )
170 wxArrayString choices;
171 choices.Add( wxEmptyString );
175 if( !cr.deletePending && !cr.newName.IsEmpty() )
176 choices.Add( cr.newName );
179 wxGridCellAttr* attr =
new wxGridCellAttr;
180 attr->SetEditor(
new wxGridCellChoiceEditor( choices,
true ) );
187 wxArrayString choices;
188 choices.Add( wxEmptyString );
192 std::shared_ptr<NET_SETTINGS> ns =
m_frame->Prj().GetProjectFile().NetSettings();
196 for(
const auto& [
name, nc] : ns->GetNetclasses() )
201 wxGridCellAttr* attr =
new wxGridCellAttr;
202 attr->SetEditor(
new wxGridCellChoiceEditor( choices,
true ) );
219 if( !row.deletePending )
223 m_chainsHeader->SetLabel( wxString::Format(
_(
"%d net chain(s)" ), activeCount ) );
265 std::map<wxString, int> memberCount;
269 if( row.deletePending || row.newChainClass.IsEmpty() )
272 ++memberCount[row.newChainClass];
278 int r =
static_cast<int>( i );
321 if( colorStr.IsEmpty() )
345 wxMessageBox( wxString::Format(
_(
"Net chain on row %zu cannot have an empty name." ), i + 1 ),
346 _(
"Net Chains" ), wxOK | wxICON_ERROR,
this );
352 wxMessageBox( wxString::Format(
_(
"Net chain name '%s' contains invalid characters." ), row.
newName ),
353 _(
"Net Chains" ), wxOK | wxICON_ERROR,
this );
359 wxMessageBox( wxString::Format(
_(
"Duplicate net chain name '%s' on row %zu." ), row.
newName, i + 1 ),
360 _(
"Net Chains" ), wxOK | wxICON_ERROR,
this );
375 wxMessageBox( wxString::Format(
_(
"Class on row %zu cannot have an empty name." ), i + 1 ),
376 _(
"Net Chain Classes" ), wxOK | wxICON_ERROR,
this );
382 wxMessageBox( wxString::Format(
_(
"Duplicate class name '%s' on row %zu." ), row.
newName, i + 1 ),
383 _(
"Net Chain Classes" ), wxOK | wxICON_ERROR,
this );
406 auto& manager =
m_frame->Schematic().NetChains();
408 std::shared_ptr<NET_SETTINGS> ns =
m_frame->Prj().GetProjectFile().NetSettings();
413 if( row.deletePending )
416 if( !row.origName.IsEmpty() && row.origName != row.newName )
418 if( manager.RenameCommittedNetChain( row.origName, row.newName ) )
419 row.origName = row.newName;
426 if( row.deletePending || !row.livePtr )
429 row.livePtr->SetColor( row.newColor );
430 row.livePtr->SetNetClass( row.newNetClass );
438 if( row.deletePending )
441 ns->SetNetChainClass( row.newName, row.newChainClass );
448 if( !row.deletePending )
451 if( !row.origName.IsEmpty() )
452 manager.DeleteCommittedNetChain( row.origName );
462 if( !cls.deletePending )
467 std::vector<wxString> toClear;
469 for(
const auto& [chainName, className] : ns->GetNetChainClasses() )
471 if( className == cls.origName )
472 toClear.push_back( chainName );
475 for(
const wxString& chainName : toClear )
476 ns->SetNetChainClass( chainName, wxEmptyString );
481 if( cls.deletePending )
484 if( !cls.origName.IsEmpty() && cls.origName != cls.newName )
488 std::vector<wxString> toRename;
490 for(
const auto& [chainName, className] : ns->GetNetChainClasses() )
492 if( className == cls.origName )
493 toRename.push_back( chainName );
496 for(
const wxString& chainName : toRename )
497 ns->SetNetChainClass( chainName, cls.newName );
547 for(
int i = 0; i < (int)
m_chainRows.size(); ++i )
549 if( i == aExceptRow )
555 if(
m_chainRows[i].newName == aName && !aName.IsEmpty() )
565 for(
int i = 0; i < static_cast<int>(
m_classRows.size() ); ++i )
567 if( i == aExceptRow )
573 if(
m_classRows[i].newName == aName && !aName.IsEmpty() )
590 if( wxMessageBox( wxString::Format(
_(
"Delete net chain '%s'?" ), row.
newName ),
591 _(
"Delete Net Chain" ), wxYES_NO | wxICON_QUESTION,
this ) != wxYES )
604 int gridRow = aEvent.GetRow();
617 if( aRow < 0 || aRow >=
static_cast<int>(
m_chainRows.size() ) )
625 wxString label = row.
newName.IsEmpty() ? wxString::Format(
_(
"Member Nets (%zu)" ),
627 : wxString::Format(
_(
"Member Nets \u2014 %s (%zu)" ),
633 wxArrayString sorted;
646 wxTextEntryDialog dlg(
this,
_(
"New net chain class name:" ),
_(
"Add Class" ) );
648 if( dlg.ShowModal() != wxID_OK )
651 wxString
name = dlg.GetValue();
655 wxMessageBox(
_(
"That class name is empty or already in use." ),
_(
"Add Class" ), wxOK | wxICON_ERROR,
674 if( r < 0 || r >=
static_cast<int>(
m_classRows.size() ) )
679 wxTextEntryDialog dlg(
this,
_(
"Rename net chain class:" ),
_(
"Rename Class" ), row.
newName );
681 if( dlg.ShowModal() != wxID_OK )
684 wxString
name = dlg.GetValue();
688 wxMessageBox(
_(
"That class name is empty or already in use." ),
_(
"Rename Class" ), wxOK | wxICON_ERROR,
693 wxString oldName = row.
newName;
698 if( chainRow.newChainClass == oldName )
699 chainRow.newChainClass =
name;
712 if( r < 0 || r >=
static_cast<int>(
m_classRows.size() ) )
717 if( wxMessageBox( wxString::Format(
_(
"Delete net chain class '%s'? Chains assigned to it "
718 "will become unclassified." ),
720 _(
"Delete Class" ), wxYES_NO | wxICON_QUESTION,
this ) != wxYES )
730 if( chainRow.newChainClass == row.
newName )
731 chainRow.newChainClass = wxEmptyString;
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
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_functionCall
wxStaticText * m_chainsHeader
wxStaticText * m_hintBeforeFunctionCall
wxStaticText * m_membersLabel
wxStaticText * m_hintAfterFunctionCall
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)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
KICOMMON_API wxFont GetMonospacedUIFont(int aRelativeSize=0)
static const wxString c_statusPotential
static const wxString c_statusCommitted
std::set< wxString > memberNets
const SHAPE_LINE_CHAIN chain