41#include <wx/tokenzr.h>
42#include <wx/choicdlg.h>
43#include <wx/dcclient.h>
51#define COL_CURR_LIBID 1
52#define COL_NEW_LIBID 2
58 int GetHeight( wxDC& aDC, wxGrid* aGrid,
int aRow,
int aCol );
60 wxGridCellRenderer *
Clone()
const override
66 wxArrayString
GetTextLines( wxGrid&
grid, wxDC& dc,
const wxGridCellAttr& attr,
67 const wxRect& rect,
int row,
int col );
74 void BreakLine( wxDC& dc,
const wxString& logicalLine, wxCoord maxWidth, wxArrayString& lines );
81 wxCoord
BreakWord( wxDC& dc,
const wxString& word, wxCoord maxWidth, wxArrayString& lines,
88 const wxGridCellAttr& attr,
89 const wxRect& rect,
int row,
int col )
91 dc.SetFont( attr.GetFont() );
92 const wxCoord maxWidth = rect.GetWidth();
95 const wxArrayString logicalLines = wxSplit(
grid.GetCellValue( row, col ),
'\n',
'\0' );
102 wxArrayString physicalLines;
104 for(
const wxString& line : logicalLines )
106 if( dc.GetTextExtent( line ).x > maxWidth )
109 BreakLine( dc, line, maxWidth, physicalLines );
113 physicalLines.push_back( line );
117 return physicalLines;
123 wxCoord maxWidth, wxArrayString& lines )
125 wxCoord lineWidth = 0;
129 wxStringTokenizer wordTokenizer( logicalLine, wxS(
" \t" ), wxTOKEN_RET_DELIMS );
131 while( wordTokenizer.HasMoreTokens() )
133 const wxString word = wordTokenizer.GetNextToken();
134 const wxCoord wordWidth = dc.GetTextExtent( word ).x;
136 if( lineWidth + wordWidth < maxWidth )
140 lineWidth += wordWidth;
146 if( wordWidth < maxWidth )
150 lines.push_back( line );
152 lineWidth = wordWidth;
158 lines.push_back( line );
164 lineWidth =
BreakWord( dc, word, maxWidth, lines, line );
170 lines.push_back( line );
176 wxCoord maxWidth, wxArrayString& lines,
180 dc.GetPartialTextExtents( word, widths );
183 const unsigned count = widths.size();
186 for( n = 0; n < count; n++ )
188 if( widths[n] > maxWidth )
200 lines.push_back( word.substr( 0, n ) );
208 const wxString rest = word.substr( n );
209 const wxCoord restWidth = dc.GetTextExtent( rest ).x;
211 if( restWidth <= maxWidth )
221 return BreakWord( dc, rest, maxWidth, lines, line );
225#define GRID_CELL_MARGIN 4
229 wxGridCellAttr* attr = aGrid->GetOrCreateCellAttr( aRow, aCol );
232 aDC.SetFont( attr->GetFont() );
235 const size_t numLines =
GetTextLines( *aGrid, aDC, *attr, rect, aRow, aCol ).size();
236 const int textHeight = numLines * aDC.GetCharHeight();
302 void AddRowToGrid(
bool aMarkRow,
const wxString& aReferences,
const wxString& aStrLibId );
338 void OnSizeGrid( wxSizeEvent& event )
override;
365 m_grid->PopEventHandler(
true );
400 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
419 wxString last_str_libid =
m_symbols.front().GetStringLibId();
423 bool mark_cell =
m_symbols.front().m_IsOrphan;
427 wxString str_libid = symbol.GetStringLibId();
429 if( last_str_libid != str_libid )
435 mark_cell = symbol.m_IsOrphan;
436 last_str_libid = str_libid;
440 else if( symbol.m_Reference == last_ref )
446 last_ref = symbol.m_Reference;
448 if( !refs.IsEmpty() )
451 refs += symbol.m_Reference;
459 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
473 const wxString& aStrLibId )
475 int row =
m_grid->GetNumberRows();
490 wxFont font =
m_grid->GetDefaultCellFont();
500 wxClientDC dc(
this );
504 wxGridCellAttr* attr =
new wxGridCellAttr;
512 wxString rawValue = aGrid->GetCellValue( aRow, aCol );
514 if( rawValue.IsEmpty() )
518 wxString libName = rawValue.BeforeFirst(
':', &itemName );
529 int row_max =
m_grid->GetNumberRows() - 1;
531 for(
int row = 0; row <= row_max; row++ )
535 if( new_libid.IsEmpty() )
540 id.
Parse( new_libid );
545 msg.Printf(
_(
"Symbol library identifier %s is not valid." ), new_libid );
552 m_grid->EnableCellEditControl(
true );
553 m_grid->ShowCellEditControl();
565 int row =
event.GetRow();
575 std::vector<wxString> libs =
Prj().SchSymbolLibTable()->GetLogicalLibs();
576 wxArrayString aliasNames;
577 wxArrayString candidateSymbNames;
579 unsigned fixesCount = 0;
585 int grid_row_idx = orphanRow;
588 curr_libid.
Parse( orphanLibid,
true );
594 int libIdCandidateCount = 0;
595 candidateSymbNames.Clear();
598 for(
const wxString &lib : libs )
604 Prj().SchSymbolLibTable()->EnumerateSymbolLib( lib, aliasNames );
608 if( aliasNames.IsEmpty() )
612 int index = aliasNames.Index( symbolName );
614 if( index != wxNOT_FOUND )
617 libIdCandidateCount++;
618 wxString newLibid = lib +
':' + symbolName;
622 if( libIdCandidateCount <= 1 )
636 if( libIdCandidateCount > 1 )
639 m_grid->SelectRow( grid_row_idx );
642 msg.Printf(
_(
"Available Candidates for %s " ),
645 wxSingleChoiceDialog dlg (
this, msg,
646 wxString::Format(
_(
"Candidates count %d " ),
647 libIdCandidateCount ),
648 candidateSymbNames );
650 if( dlg.ShowModal() == wxID_OK )
657 wxMessageBox( wxString::Format(
_(
"%u link(s) mapped, %u not found" ),
663 wxMessageBox( wxString::Format(
_(
"All %u link(s) resolved" ), fixesCount ) );
672 SCH_BASE_FRAME::HISTORY_LIST
dummy;
673 SCH_BASE_FRAME::PICKED_SYMBOL sel = m_frame->SelectComponentFromLibrary(
nullptr,
dummy,
true,
680 if( current.IsEmpty() )
683 if( !current.IsEmpty() )
684 preselected.
Parse( current,
true );
689 if( sel.LibId.empty() )
692 if( !sel.LibId.IsValid() )
694 wxMessageBox(
_(
"Invalid symbol library identifier" ) );
699 new_libid = sel.LibId.Format();
712 auto getName = [](
const LIB_ID& aLibId )
717 int row_max =
m_grid->GetNumberRows() - 1;
719 for(
int row = 0; row <= row_max; row++ )
728 id.
Parse( new_libid,
true );
732 if( candidate.m_Row != row )
739 symbol =
Prj().SchSymbolLibTable()->LoadSymbol(
id );
745 msg.Printf(
_(
"Error loading symbol %s from library %s.\n\n%s" ),
746 id.GetLibItemName().wx_str(),
747 id.GetLibNickname().wx_str(),
753 if( symbol ==
nullptr )
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,
793 int colWidth = width / 3;
800 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
812 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
827 wxClientDC dc(
this );
830 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
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.
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.
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
PICKED_SYMBOL PickSymbolFromLibBrowser(wxTopLevelWindow *aParent, const SYMBOL_LIBRARY_FILTER *aFilter, const LIB_ID &aPreselectedLibId, int aUnit, int aConvert)
Call the library viewer to select symbol to import into schematic.
Schematic editor (Eeschema) main window.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
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
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
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()
int GetUnitCount() const
Return the number of units per package of the symbol.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
const LIB_ID & GetLibId() const
A helper to handle symbols to edit.
SYMBOL_CANDIDATE(SCH_SYMBOL *aSymbol)
wxString GetStringLibId()
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 DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box 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...
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...
std::vector< FAB_LAYER_COLOR > dummy
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.