43 #include <wx/tokenzr.h> 44 #include <wx/choicdlg.h> 45 #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 const wxGridCellAttr& attr,
77 const wxString& logicalLine,
79 wxArrayString& lines);
98 const wxGridCellAttr& attr,
102 dc.SetFont( attr.GetFont() );
103 const wxCoord maxWidth = rect.GetWidth();
107 logicalLines = wxSplit(grid.GetCellValue(row, col),
'\n',
'\0');
114 wxArrayString physicalLines;
115 for ( wxArrayString::const_iterator it = logicalLines.begin();
116 it != logicalLines.end();
119 const wxString& line = *it;
121 if ( dc.GetTextExtent(line).x > maxWidth )
124 BreakLine(dc, line, maxWidth, physicalLines);
128 physicalLines.push_back(line);
132 return physicalLines;
139 const wxString& logicalLine,
141 wxArrayString& lines)
143 wxCoord lineWidth = 0;
147 wxStringTokenizer wordTokenizer(logicalLine, wxS(
" \t"), wxTOKEN_RET_DELIMS);
148 while ( wordTokenizer.HasMoreTokens() )
150 const wxString word = wordTokenizer.GetNextToken();
151 const wxCoord wordWidth = dc.GetTextExtent(word).x;
152 if ( lineWidth + wordWidth < maxWidth )
156 lineWidth += wordWidth;
162 if ( wordWidth < maxWidth )
166 lines.push_back(line);
168 lineWidth = wordWidth;
174 lines.push_back(line);
180 lineWidth =
BreakWord(dc, word, maxWidth, lines, line);
186 lines.push_back(line);
193 const wxString& word,
195 wxArrayString& lines,
199 dc.GetPartialTextExtents(word, widths);
202 const unsigned count = widths.size();
204 for ( n = 0; n < count; n++ )
206 if ( widths[n] > maxWidth )
218 lines.push_back( word.substr(0, n) );
226 const wxString rest = word.substr(n);
227 const wxCoord restWidth = dc.GetTextExtent(rest).x;
229 if ( restWidth <= maxWidth )
239 return BreakWord(dc, rest, maxWidth, lines, line);
243 #define GRID_CELL_MARGIN 4 247 wxGridCellAttr* attr = aGrid->GetOrCreateCellAttr( aRow, aCol );
250 aDC.SetFont( attr->GetFont() );
253 const size_t numLines =
GetTextLines( *aGrid, aDC, *attr, rect, aRow, aCol ).size();
254 const int textHeight = numLines * aDC.GetCharHeight();
330 void AddRowToGrid(
bool aMarkRow,
const wxString& aReferences,
const wxString& aStrLibId );
364 void OnSizeGrid( wxSizeEvent& event )
override;
384 m_grid->PopEventHandler(
true );
418 for(
unsigned ii = 0; ii < references.
GetCount(); ii++ )
424 candidate.m_Reference = candidate.m_Component->GetRef( &sheetpath );
425 int unitcount = candidate.m_Component->GetUnitCount();
426 candidate.m_IsOrphan = ( unitcount == 0 );
437 wxString last_str_libid =
m_components.front().GetStringLibId();
445 wxString str_libid = cmp.GetStringLibId();
447 if( last_str_libid != str_libid )
453 mark_cell = cmp.m_IsOrphan;
454 last_str_libid = str_libid;
458 else if( cmp.GetSchematicReference() == last_ref )
464 last_ref = cmp.GetSchematicReference();
466 if( !refs.IsEmpty() )
469 refs += cmp.GetSchematicReference();
477 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
486 return dynamic_cast<SCH_EDIT_FRAME*>( wxDialog::GetParent() );
491 const wxString& aStrLibId )
493 int row =
m_grid->GetNumberRows();
508 wxFont font =
m_grid->GetDefaultCellFont();
518 wxClientDC dc(
this );
522 wxGridCellAttr* attr =
new wxGridCellAttr;
533 int row_max =
m_grid->GetNumberRows() - 1;
535 for(
int row = 0; row <= row_max; row++ )
539 if( new_libid.IsEmpty() )
544 id.
Parse( new_libid );
549 msg.Printf(
_(
"Symbol library identifier \"%s\" is not valid." ), new_libid );
556 m_grid->EnableCellEditControl(
true );
557 m_grid->ShowCellEditControl();
569 int row =
event.GetRow();
579 std::vector< wxString > libs =
Prj().SchSymbolLibTable()->GetLogicalLibs();
580 wxArrayString aliasNames;
581 wxArrayString candidateSymbNames;
583 unsigned fixesCount = 0;
589 int grid_row_idx = orphanRow;
592 curr_libid.
Parse( orphanLibid,
true );
597 int libIdCandidateCount = 0;
598 candidateSymbNames.Clear();
601 for(
auto &lib : libs )
607 Prj().SchSymbolLibTable()->EnumerateSymbolLib( lib, aliasNames );
611 if( aliasNames.IsEmpty() )
615 int index = aliasNames.Index( symbName );
617 if( index != wxNOT_FOUND )
620 libIdCandidateCount++;
621 wxString newLibid = lib +
':' + symbName;
625 if( libIdCandidateCount <= 1 )
633 candidateSymbNames.Add( newLibid );
639 if( libIdCandidateCount > 1 )
642 m_grid->SelectRow( grid_row_idx );
645 msg.Printf(
_(
"Available Candidates for %s " ),
648 wxSingleChoiceDialog dlg (
this, msg,
650 candidateSymbNames );
652 if( dlg.ShowModal() == wxID_OK )
672 SCH_BASE_FRAME::HISTORY_LIST
dummy;
673 SCH_BASE_FRAME::PICKED_SYMBOL sel = m_frame->SelectComponentFromLibrary(
NULL,
dummy,
true,
680 if( current.IsEmpty() )
683 if( !current.IsEmpty() )
684 preselected.
Parse( current,
true );
694 wxMessageBox(
_(
"Invalid symbol library identifier" ) );
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( cmp.m_Row != row )
734 symbol =
Prj().SchSymbolLibTable()->LoadSymbol(
id );
740 msg.Printf(
_(
"Error occurred loading symbol %s from library %s.\n\n%s" ),
741 id.GetLibItemName().wx_str(),
742 id.GetLibNickname().wx_str(),
748 if( symbol ==
nullptr )
755 cmp.m_Screen->Remove( cmp.m_Component );
759 if( cmp.m_Component->GetLibId().GetLibItemName().wx_str() == value->
GetText() )
760 cmp.m_Component->SetValue(
id.GetLibItemName().wx_str() );
762 cmp.m_Component->SetLibId(
id );
763 cmp.m_Component->SetLibSymbol( symbol->
Flatten().release() );
764 cmp.m_Screen->Append( cmp.m_Component );
765 cmp.m_Screen->SetModify();
768 cmp.m_Component->UpdateFields(
false,
false );
780 aWidth -= (
m_grid->GetSize().x -
m_grid->GetClientSize().x );
782 int colWidth = aWidth / 3;
788 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
799 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
814 wxClientDC dc(
this );
817 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
DIALOG_EDIT_COMPONENTS_LIBID(SCH_EDIT_FRAME *aParent)
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
const UTF8 & GetLibItemName() const
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false) const
Add a SCH_REFERENCE object to aReferences for each component in the list of sheets.
std::vector< CMP_CANDIDATE > m_components
This file is part of the common library.
const SCH_SHEET_PATH & GetSheetPath() const
wxCoord BreakWord(wxDC &dc, const wxString &word, wxCoord maxWidth, wxArrayString &lines, wxString &line)
bool setLibIdByBrowser(int aRow)
run the lib browser and set the selected LIB_ID for row aRow
void OnSizeGrid(wxSizeEvent &event) override
GRIDCELL_AUTOWRAP_STRINGRENDERER * m_autoWrapRenderer
void BreakLine(wxDC &dc, const wxString &logicalLine, wxCoord maxWidth, wxArrayString &lines)
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
bool IsQuasiModal() const
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Schematic editor (Eeschema) main window.
wxArrayString GetTextLines(wxGrid &grid, wxDC &dc, const wxGridCellAttr &attr, const wxRect &rect, int row, int col)
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
wxString GetStringLibId()
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
Field Value of part, i.e. "3.3K".
CMP_CANDIDATE(SCH_COMPONENT *aComponent)
void AdjustGridColumns(int aWidth)
Dialog to globally edit the LIB_ID of groups if components having the same initial LIB_ID.
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...
virtual const wxString What() const
A composite of Problem() and Where()
~DIALOG_EDIT_COMPONENTS_LIBID() override
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
int GetHeight(wxDC &aDC, wxGrid *aGrid, int aRow, int aCol)
static bool sort_by_libid(const CMP_CANDIDATE &cmp1, const CMP_CANDIDATE &cmp2)
void onCancel(wxCommandEvent &event) override
SCHEMATIC & Schematic() const
Define a library symbol object.
bool TransferDataFromWindow() override
bool InvokeDialogEditComponentsLibId(SCH_EDIT_FRAME *aCaller)
Run a dialog to modify the LIB_ID of components for instance when a symbol has moved from a symbol li...
wxLogTrace helper definitions.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString GetSchematicReference()
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
std::unique_ptr< LIB_PART > Flatten() const
Return a flattened symbol inheritance to the caller.
SCH_EDIT_FRAME * GetParent()
PICKED_SYMBOL PickSymbolFromLibBrowser(wxTopLevelWindow *aParent, const SCHLIB_FILTER *aFilter, const LIB_ID &aPreselectedLibId, int aUnit, int aConvert)
Function PickSymbolFromLibBrowser Calls the library viewer to select component to import into schemat...
SCH_COMPONENT * GetSymbol() const
wxCheckBox * m_checkBoxUpdateFields
std::vector< int > m_OrphansRowIndexes
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
unsigned GetCount() const
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
wxGridCellRenderer * Clone() const override
void EndQuasiModal(int retCode)
void onCellBrowseLib(wxGridEvent &event) override
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
SCH_SCREEN * LastScreen()
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend)
Create a copy of the current schematic item, and put it in the undo list.
SCH_COMPONENT * m_Component
void AddRowToGrid(bool aMarkRow, const wxString &aReferences, const wxString &aStrLibId)
Add a new row (new entry) in m_grid.
Class DIALOG_EDIT_COMPONENTS_LIBID_BASE.
wxButton * m_buttonOrphanItems
wxString GetUniStringLibId() const
const LIB_ID & GetLibId() const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
bool IsSchematicModified()
void onClickOrphansButton(wxCommandEvent &event) override
virtual const wxString & GetText() const
Return the string associated with the text object.
A helper to define a symbol's reference designator in a schematic.
bool validateLibIds()
returns true if all new lib id are valid