38#include <wx/tokenzr.h>
39#include <wx/choicdlg.h>
40#include <wx/dcclient.h>
50#define COL_CURR_LIBID 1
51#define COL_NEW_LIBID 2
57 int GetHeight( wxDC& aDC, wxGrid* aGrid,
int aRow,
int aCol );
59 wxGridCellRenderer *
Clone()
const override
67 wxArrayString
GetTextLines( wxGrid&
grid, wxDC& dc,
const wxGridCellAttr& attr,
68 const wxRect& rect,
int row,
int col );
75 void BreakLine( wxDC& dc,
const wxString& logicalLine, wxCoord maxWidth, wxArrayString& lines );
82 wxCoord
BreakWord( wxDC& dc,
const wxString& word, wxCoord maxWidth, wxArrayString& lines,
89 const wxGridCellAttr& attr,
90 const wxRect& rect,
int row,
int col )
92 dc.SetFont( attr.GetFont() );
93 const wxCoord maxWidth = rect.GetWidth();
96 const wxArrayString logicalLines = wxSplit(
grid.GetCellValue( row, col ),
'\n',
'\0' );
103 wxArrayString physicalLines;
105 for(
const wxString& line : logicalLines )
107 if( dc.GetTextExtent( line ).x > maxWidth )
110 BreakLine( dc, line, maxWidth, physicalLines );
114 physicalLines.push_back( line );
118 return physicalLines;
124 wxCoord maxWidth, wxArrayString& lines )
126 wxCoord lineWidth = 0;
130 wxStringTokenizer wordTokenizer( logicalLine,
" \t", wxTOKEN_RET_DELIMS );
132 while( wordTokenizer.HasMoreTokens() )
134 const wxString word = wordTokenizer.GetNextToken();
135 const wxCoord wordWidth = dc.GetTextExtent( word ).x;
137 if( lineWidth + wordWidth < maxWidth )
141 lineWidth += wordWidth;
147 if( wordWidth < maxWidth )
151 lines.push_back( line );
153 lineWidth = wordWidth;
159 lines.push_back( line );
165 lineWidth =
BreakWord( dc, word, maxWidth, lines, line );
171 lines.push_back( line );
177 wxCoord maxWidth, wxArrayString& lines,
181 dc.GetPartialTextExtents( word, widths );
184 const unsigned count = widths.size();
187 for( n = 0; n < count; n++ )
189 if( widths[n] > maxWidth )
201 lines.push_back( word.substr( 0, n ) );
209 const wxString rest = word.substr( n );
210 const wxCoord restWidth = dc.GetTextExtent( rest ).x;
212 if( restWidth <= maxWidth )
222 return BreakWord( dc, rest, maxWidth, lines, line );
226#define GRID_CELL_MARGIN 4
230 wxGridCellAttr* attr = aGrid->GetOrCreateCellAttr( aRow, aCol );
233 aDC.SetFont( attr->GetFont() );
236 const size_t numLines =
GetTextLines( *aGrid, aDC, *attr, rect, aRow, aCol ).size();
237 const int textHeight = numLines * aDC.GetCharHeight();
263 return m_Symbol->GetLibId().GetUniStringLibId();
303 void AddRowToGrid(
bool aMarkRow,
const wxString& aReferences,
const wxString& aStrLibId );
339 void OnSizeGrid( wxSizeEvent& event )
override;
366 m_grid->PopEventHandler(
true );
399 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
418 wxString last_str_libid =
m_symbols.front().GetStringLibId();
422 bool mark_cell =
m_symbols.front().m_IsOrphan;
426 wxString str_libid = symbol.GetStringLibId();
428 if( last_str_libid != str_libid )
434 mark_cell = symbol.m_IsOrphan;
435 last_str_libid = str_libid;
439 else if( symbol.m_Reference == last_ref )
445 last_ref = symbol.m_Reference;
447 if( !refs.IsEmpty() )
450 refs += symbol.m_Reference;
458 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
472 const wxString& aStrLibId )
474 int row =
m_grid->GetNumberRows();
489 wxFont font =
m_grid->GetDefaultCellFont();
499 wxClientDC dc(
this );
503 wxGridCellAttr* attr =
new wxGridCellAttr;
511 wxString rawValue = aGrid->GetCellValue( aRow, aCol );
513 if( rawValue.IsEmpty() )
517 wxString libName = rawValue.BeforeFirst(
':', &itemName );
525 if( !
m_grid->CommitPendingChanges() )
528 int row_max =
m_grid->GetNumberRows() - 1;
530 for(
int row = 0; row <= row_max; row++ )
534 if( new_libid.IsEmpty() )
539 id.
Parse( new_libid );
544 msg.Printf(
_(
"Symbol library identifier %s is not valid." ), new_libid );
551 m_grid->EnableCellEditControl(
true );
552 m_grid->ShowCellEditControl();
564 int row =
event.GetRow();
575 std::vector<wxString> aliasNames;
576 wxArrayString candidateSymbNames;
578 unsigned fixesCount = 0;
584 int grid_row_idx = orphanRow;
587 curr_libid.
Parse( orphanLibid,
true );
593 int libIdCandidateCount = 0;
594 candidateSymbNames.Clear();
597 for(
const wxString &lib : libs )
607 if( aliasNames.empty() )
611 if(
auto it = std::ranges::find( aliasNames, symbolName ); it != aliasNames.end() )
614 libIdCandidateCount++;
615 wxString newLibid = lib +
':' + symbolName;
619 if( libIdCandidateCount <= 1 )
633 if( libIdCandidateCount > 1 )
636 m_grid->SelectRow( grid_row_idx );
639 msg.Printf(
_(
"Available Candidates for %s " ),
642 wxSingleChoiceDialog dlg (
this, msg,
643 wxString::Format(
_(
"Candidates count %d " ),
644 libIdCandidateCount ),
645 candidateSymbNames );
647 if( dlg.ShowModal() == wxID_OK )
654 wxMessageBox( wxString::Format(
_(
"%u link(s) mapped, %u not found" ),
660 wxMessageBox( wxString::Format(
_(
"All %u link(s) resolved" ), fixesCount ) );
668 std::vector<PICKED_SYMBOL> dummyHistory;
669 std::vector<PICKED_SYMBOL> dummyAlreadyPlaced;
673 if( current.IsEmpty() )
676 if( !current.IsEmpty() )
677 preselected.
Parse( current,
true );
680 nullptr, dummyHistory, dummyAlreadyPlaced,
false, &preselected,
false );
687 wxMessageBox(
_(
"Invalid symbol library identifier" ) );
707 auto getName = [](
const LIB_ID& aLibId )
712 int row_max =
m_grid->GetNumberRows() - 1;
714 for(
int row = 0; row <= row_max; row++ )
723 id.
Parse( new_libid,
true );
727 if( candidate.m_Row != row )
740 msg.Printf(
_(
"Error loading symbol %s from library %s.\n\n%s" ),
741 id.GetLibItemName().wx_str(),
742 id.GetLibNickname().wx_str(),
748 if( symbol ==
nullptr )
751 commit.
Modify( candidate.m_Symbol, candidate.m_Screen );
754 candidate.m_Screen->Remove( candidate.m_Symbol );
758 if( getName( candidate.m_Symbol->GetLibId() ) == value->
GetText() )
759 candidate.m_Symbol->SetValueFieldText( getName(
id ) );
761 candidate.m_Symbol->SetLibId(
id );
762 candidate.m_Symbol->SetLibSymbol( symbol->
Flatten().release() );
763 candidate.m_Screen->Append( candidate.m_Symbol );
764 candidate.m_Screen->SetContentModified();
768 candidate.m_Symbol->UpdateFields(
nullptr,
779 commit.
Push( wxS(
"Change Symbol Library Indentifier" ) );
790 int colWidth = width / 3;
797 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
809 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
824 wxClientDC dc(
this );
827 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
wxCheckBox * m_checkBoxUpdateFields
DIALOG_EDIT_SYMBOLS_LIBID_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Symbol Library References"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxButton * m_buttonOrphanItems
Dialog to globally edit the LIB_ID of groups if symbols having the same initial LIB_ID.
void OnSizeGrid(wxSizeEvent &event) override
std::vector< SYMBOL_CANDIDATE > m_symbols
void onClickOrphansButton(wxCommandEvent &event) override
DIALOG_EDIT_SYMBOLS_LIBID(SCH_EDIT_FRAME *aParent)
bool setLibIdByBrowser(int aRow)
Run the lib browser and set the selected LIB_ID for aRow.
~DIALOG_EDIT_SYMBOLS_LIBID() override
void onCancel(wxCommandEvent &event) override
void onCellBrowseLib(wxGridEvent &event) override
bool validateLibIds()
returns true if all new lib id are valid
SCH_EDIT_FRAME * GetParent()
GRIDCELL_AUTOWRAP_STRINGRENDERER * m_autoWrapRenderer
bool TransferDataFromWindow() override
bool IsSchematicModified()
void AddRowToGrid(bool aMarkRow, const wxString &aReferences, const wxString &aStrLibId)
Add a new row (new entry) in m_grid.
std::vector< int > m_OrphansRowIndexes
bool IsQuasiModal() const
void EndQuasiModal(int retCode)
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
wxArrayString GetTextLines(wxGrid &grid, wxDC &dc, const wxGridCellAttr &attr, const wxRect &rect, int row, int col)
int GetHeight(wxDC &aDC, wxGrid *aGrid, int aRow, int aCol)
wxCoord BreakWord(wxDC &dc, const wxString &word, wxCoord maxWidth, wxArrayString &lines, wxString &line)
void BreakLine(wxDC &dc, const wxString &logicalLine, wxCoord maxWidth, wxArrayString &lines)
wxGridCellRenderer * Clone() const override
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
std::vector< wxString > GetLibraryNames() const
Returns a list of library nicknames that are available (skips any that failed to load)
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
bool IsValid() const
Check if this LID_ID is valid.
const UTF8 & GetLibItemName() const
Define a library symbol object.
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
PICKED_SYMBOL PickSymbolFromLibrary(const SYMBOL_LIBRARY_FILTER *aFilter, std::vector< PICKED_SYMBOL > &aHistoryList, std::vector< PICKED_SYMBOL > &aAlreadyPlaced, bool aShowFootprints, const LIB_ID *aHighlight=nullptr, bool aAllowFields=true)
Call the library viewer to select symbol to import into schematic.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
virtual const wxString & GetText() const override
Return the string associated with the text object.
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
A helper to define a symbol's reference designator in a schematic.
const SCH_SHEET_PATH & GetSheetPath() const
SCH_SYMBOL * GetSymbol() const
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
const LIB_ID & GetLibId() const override
int GetUnitCount() const override
Return the number of units per package of the symbol.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
A helper to handle symbols to edit.
SYMBOL_CANDIDATE(SCH_SYMBOL *aSymbol)
wxString GetStringLibId()
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
std::vector< wxString > GetSymbolNames(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static bool sort_by_libid(const SYMBOL_CANDIDATE &candidate1, const SYMBOL_CANDIDATE &candidate2)
wxString getLibIdValue(const WX_GRID *aGrid, int aRow, int aCol)
bool InvokeDialogEditSymbolsLibId(SCH_EDIT_FRAME *aCaller)
Run a dialog to modify the LIB_ID of symbols for instance when a symbol has moved from a symbol libra...
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ VALUE
Field Value of part, i.e. "3.3K".
wxLogTrace helper definitions.