42#include <wx/tokenzr.h>
43#include <wx/choicdlg.h>
44#include <wx/dcclient.h>
54#define COL_CURR_LIBID 1
55#define COL_NEW_LIBID 2
61 int GetHeight( wxDC& aDC, wxGrid* aGrid,
int aRow,
int aCol );
63 wxGridCellRenderer *
Clone()
const override
69 wxArrayString
GetTextLines( wxGrid&
grid, wxDC& dc,
const wxGridCellAttr& attr,
70 const wxRect& rect,
int row,
int col );
77 void BreakLine( wxDC& dc,
const wxString& logicalLine, wxCoord maxWidth, wxArrayString& lines );
84 wxCoord
BreakWord( wxDC& dc,
const wxString& word, wxCoord maxWidth, wxArrayString& lines,
91 const wxGridCellAttr& attr,
92 const wxRect& rect,
int row,
int col )
94 dc.SetFont( attr.GetFont() );
95 const wxCoord maxWidth = rect.GetWidth();
98 const wxArrayString logicalLines = wxSplit(
grid.GetCellValue( row, col ),
'\n',
'\0' );
105 wxArrayString physicalLines;
107 for(
const wxString& line : logicalLines )
109 if( dc.GetTextExtent( line ).x > maxWidth )
112 BreakLine( dc, line, maxWidth, physicalLines );
116 physicalLines.push_back( line );
120 return physicalLines;
126 wxCoord maxWidth, wxArrayString& lines )
128 wxCoord lineWidth = 0;
132 wxStringTokenizer wordTokenizer( logicalLine, wxS(
" \t" ), wxTOKEN_RET_DELIMS );
134 while( wordTokenizer.HasMoreTokens() )
136 const wxString word = wordTokenizer.GetNextToken();
137 const wxCoord wordWidth = dc.GetTextExtent( word ).x;
139 if( lineWidth + wordWidth < maxWidth )
143 lineWidth += wordWidth;
149 if( wordWidth < maxWidth )
153 lines.push_back( line );
155 lineWidth = wordWidth;
161 lines.push_back( line );
167 lineWidth =
BreakWord( dc, word, maxWidth, lines, line );
173 lines.push_back( line );
179 wxCoord maxWidth, wxArrayString& lines,
183 dc.GetPartialTextExtents( word, widths );
186 const unsigned count = widths.size();
189 for( n = 0; n < count; n++ )
191 if( widths[n] > maxWidth )
203 lines.push_back( word.substr( 0, n ) );
211 const wxString rest = word.substr( n );
212 const wxCoord restWidth = dc.GetTextExtent( rest ).x;
214 if( restWidth <= maxWidth )
224 return BreakWord( dc, rest, maxWidth, lines, line );
228#define GRID_CELL_MARGIN 4
232 wxGridCellAttr* attr = aGrid->GetOrCreateCellAttr( aRow, aCol );
235 aDC.SetFont( attr->GetFont() );
238 const size_t numLines =
GetTextLines( *aGrid, aDC, *attr, rect, aRow, aCol ).size();
239 const int textHeight = numLines * aDC.GetCharHeight();
305 void AddRowToGrid(
bool aMarkRow,
const wxString& aReferences,
const wxString& aStrLibId );
341 void OnSizeGrid( wxSizeEvent& event )
override;
368 m_grid->PopEventHandler(
true );
403 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
422 wxString last_str_libid =
m_symbols.front().GetStringLibId();
426 bool mark_cell =
m_symbols.front().m_IsOrphan;
430 wxString str_libid = symbol.GetStringLibId();
432 if( last_str_libid != str_libid )
438 mark_cell = symbol.m_IsOrphan;
439 last_str_libid = str_libid;
443 else if( symbol.m_Reference == last_ref )
449 last_ref = symbol.m_Reference;
451 if( !refs.IsEmpty() )
454 refs += symbol.m_Reference;
462 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
476 const wxString& aStrLibId )
478 int row =
m_grid->GetNumberRows();
493 wxFont font =
m_grid->GetDefaultCellFont();
503 wxClientDC dc(
this );
507 wxGridCellAttr* attr =
new wxGridCellAttr;
515 wxString rawValue = aGrid->GetCellValue( aRow, aCol );
517 if( rawValue.IsEmpty() )
521 wxString libName = rawValue.BeforeFirst(
':', &itemName );
532 int row_max =
m_grid->GetNumberRows() - 1;
534 for(
int row = 0; row <= row_max; row++ )
538 if( new_libid.IsEmpty() )
543 id.
Parse( new_libid );
548 msg.Printf(
_(
"Symbol library identifier %s is not valid." ), new_libid );
555 m_grid->EnableCellEditControl(
true );
556 m_grid->ShowCellEditControl();
568 int row =
event.GetRow();
579 wxArrayString aliasNames;
580 wxArrayString candidateSymbNames;
582 unsigned fixesCount = 0;
588 int grid_row_idx = orphanRow;
591 curr_libid.
Parse( orphanLibid,
true );
597 int libIdCandidateCount = 0;
598 candidateSymbNames.Clear();
601 for(
const wxString &lib : libs )
611 if( aliasNames.IsEmpty() )
615 int index = aliasNames.Index( symbolName );
617 if( index != wxNOT_FOUND )
620 libIdCandidateCount++;
621 wxString newLibid = lib +
':' + symbolName;
625 if( libIdCandidateCount <= 1 )
639 if( libIdCandidateCount > 1 )
642 m_grid->SelectRow( grid_row_idx );
645 msg.Printf(
_(
"Available Candidates for %s " ),
648 wxSingleChoiceDialog dlg (
this, msg,
649 wxString::Format(
_(
"Candidates count %d " ),
650 libIdCandidateCount ),
651 candidateSymbNames );
653 if( dlg.ShowModal() == wxID_OK )
660 wxMessageBox( wxString::Format(
_(
"%u link(s) mapped, %u not found" ),
666 wxMessageBox( wxString::Format(
_(
"All %u link(s) resolved" ), fixesCount ) );
674 std::vector<PICKED_SYMBOL> dummyHistory;
675 std::vector<PICKED_SYMBOL> dummyAlreadyPlaced;
679 if( current.IsEmpty() )
682 if( !current.IsEmpty() )
683 preselected.
Parse( current,
true );
686 nullptr, dummyHistory, dummyAlreadyPlaced,
false, &preselected,
false );
693 wxMessageBox(
_(
"Invalid symbol library identifier" ) );
713 auto getName = [](
const LIB_ID& aLibId )
718 int row_max =
m_grid->GetNumberRows() - 1;
720 for(
int row = 0; row <= row_max; row++ )
729 id.
Parse( new_libid,
true );
733 if( candidate.m_Row != row )
746 msg.Printf(
_(
"Error loading symbol %s from library %s.\n\n%s" ),
747 id.GetLibItemName().wx_str(),
748 id.GetLibNickname().wx_str(),
754 if( symbol ==
nullptr )
757 commit.
Modify( candidate.m_Symbol, candidate.m_Screen );
760 candidate.m_Screen->Remove( candidate.m_Symbol );
764 if( getName( candidate.m_Symbol->GetLibId() ) == value->
GetText() )
765 candidate.m_Symbol->SetValueFieldText( getName(
id ) );
767 candidate.m_Symbol->SetLibId(
id );
768 candidate.m_Symbol->SetLibSymbol( symbol->
Flatten().release() );
769 candidate.m_Screen->Append( candidate.m_Symbol );
770 candidate.m_Screen->SetContentModified();
774 candidate.m_Symbol->UpdateFields(
nullptr,
785 commit.
Push( wxS(
"Change Symbol Library Indentifier" ) );
796 int colWidth = width / 3;
803 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
815 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
830 wxClientDC dc(
this );
833 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Class DIALOG_EDIT_SYMBOLS_LIBID_BASE.
wxCheckBox * m_checkBoxUpdateFields
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...
virtual const wxString & GetText() const
Return the string associated with the text object.
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.
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.
wxString GetUniStringLibId() const
const UTF8 & GetLibItemName() const
Define a library symbol object.
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
SCH_SHEET_LIST Hierarchy() const override
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
Revert the commit by restoring the modified items state.
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
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, bool aIncludePowerSymbols=true, 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()
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
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
Field Value of part, i.e. "3.3K".
wxLogTrace helper definitions.