KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_edit_symbols_libid.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright 2017 Jean-Pierre Charras, [email protected]
5 * Copyright 1992-2022, 2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
31#include <confirm.h>
32#include <sch_edit_frame.h>
33#include <sch_symbol.h>
34#include <sch_reference_list.h>
35#include <schematic.h>
36#include <symbol_lib_table.h>
37#include <trace_helpers.h>
38#include <widgets/wx_grid.h>
39
41#include <wx/tokenzr.h>
42#include <wx/choicdlg.h>
43#include <wx/dcclient.h>
44#include <wx/msgdlg.h>
45#include <grid_tricks.h>
47#include <kiplatform/ui.h>
48#include <string_utils.h>
49#include <project_sch.h>
50
51
52#define COL_REFS 0
53#define COL_CURR_LIBID 1
54#define COL_NEW_LIBID 2
55
56// a re-implementation of wxGridCellAutoWrapStringRenderer to allow workaround to autorowsize bug
57class GRIDCELL_AUTOWRAP_STRINGRENDERER : public wxGridCellAutoWrapStringRenderer
58{
59public:
60 int GetHeight( wxDC& aDC, wxGrid* aGrid, int aRow, int aCol );
61
62 wxGridCellRenderer *Clone() const override
64
65private:
66 // HELPER ROUTINES UNCHANGED FROM wxWidgets IMPLEMENTATION
67
68 wxArrayString GetTextLines( wxGrid& grid, wxDC& dc, const wxGridCellAttr& attr,
69 const wxRect& rect, int row, int col );
70
71 // Helper methods of GetTextLines()
72
73 // Break a single logical line of text into several physical lines, all of
74 // which are added to the lines array. The lines are broken at maxWidth and
75 // the dc is used for measuring text extent only.
76 void BreakLine( wxDC& dc, const wxString& logicalLine, wxCoord maxWidth, wxArrayString& lines );
77
78 // Break a word, which is supposed to be wider than maxWidth, into several
79 // lines, which are added to lines array and the last, incomplete, of which
80 // is returned in line output parameter.
81 //
82 // Returns the width of the last line.
83 wxCoord BreakWord( wxDC& dc, const wxString& word, wxCoord maxWidth, wxArrayString& lines,
84 wxString& line );
85};
86
87
88// PRIVATE METHOD UNCHANGED FROM wxWidgets IMPLEMENTATION
90 const wxGridCellAttr& attr,
91 const wxRect& rect, int row, int col )
92{
93 dc.SetFont( attr.GetFont() );
94 const wxCoord maxWidth = rect.GetWidth();
95
96 // Transform logical lines into physical ones, wrapping the longer ones.
97 const wxArrayString logicalLines = wxSplit( grid.GetCellValue( row, col ), '\n', '\0' );
98
99 // Trying to do anything if the column is hidden anyhow doesn't make sense
100 // and we run into problems in BreakLine() in this case.
101 if( maxWidth <= 0 )
102 return logicalLines;
103
104 wxArrayString physicalLines;
105
106 for( const wxString& line : logicalLines )
107 {
108 if( dc.GetTextExtent( line ).x > maxWidth )
109 {
110 // Line does not fit, break it up.
111 BreakLine( dc, line, maxWidth, physicalLines );
112 }
113 else // The entire line fits as is
114 {
115 physicalLines.push_back( line );
116 }
117 }
118
119 return physicalLines;
120}
121
122
123// PRIVATE METHOD UNCHANGED FROM wxWidgets IMPLEMENTATION
124void GRIDCELL_AUTOWRAP_STRINGRENDERER::BreakLine( wxDC& dc, const wxString& logicalLine,
125 wxCoord maxWidth, wxArrayString& lines )
126{
127 wxCoord lineWidth = 0;
128 wxString line;
129
130 // For each word
131 wxStringTokenizer wordTokenizer( logicalLine, wxS( " \t" ), wxTOKEN_RET_DELIMS );
132
133 while( wordTokenizer.HasMoreTokens() )
134 {
135 const wxString word = wordTokenizer.GetNextToken();
136 const wxCoord wordWidth = dc.GetTextExtent( word ).x;
137
138 if( lineWidth + wordWidth < maxWidth )
139 {
140 // Word fits, just add it to this line.
141 line += word;
142 lineWidth += wordWidth;
143 }
144 else
145 {
146 // Word does not fit, check whether the word is itself wider that
147 // available width
148 if( wordWidth < maxWidth )
149 {
150 // Word can fit in a new line, put it at the beginning
151 // of the new line.
152 lines.push_back( line );
153 line = word;
154 lineWidth = wordWidth;
155 }
156 else // Word cannot fit in available width at all.
157 {
158 if( !line.empty() )
159 {
160 lines.push_back( line );
161 line.clear();
162 lineWidth = 0;
163 }
164
165 // Break it up in several lines.
166 lineWidth = BreakWord( dc, word, maxWidth, lines, line );
167 }
168 }
169 }
170
171 if( !line.empty() )
172 lines.push_back( line );
173}
174
175
176// PRIVATE METHOD UNCHANGED FROM wxWidgets IMPLEMENTATION
177wxCoord GRIDCELL_AUTOWRAP_STRINGRENDERER::BreakWord( wxDC& dc, const wxString& word,
178 wxCoord maxWidth, wxArrayString& lines,
179 wxString& line )
180{
181 wxArrayInt widths;
182 dc.GetPartialTextExtents( word, widths );
183
184 // TODO: Use binary search to find the first element > maxWidth.
185 const unsigned count = widths.size();
186 unsigned n;
187
188 for( n = 0; n < count; n++ )
189 {
190 if( widths[n] > maxWidth )
191 break;
192 }
193
194 if( n == 0 )
195 {
196 // This is a degenerate case: the first character of the word is
197 // already wider than the available space, so we just can't show it
198 // completely and have to put the first character in this line.
199 n = 1;
200 }
201
202 lines.push_back( word.substr( 0, n ) );
203
204 // Check if the remainder of the string fits in one line.
205 //
206 // Unfortunately we can't use the existing partial text extents as the
207 // extent of the remainder may be different when it's rendered in a
208 // separate line instead of as part of the same one, so we have to
209 // recompute it.
210 const wxString rest = word.substr( n );
211 const wxCoord restWidth = dc.GetTextExtent( rest ).x;
212
213 if( restWidth <= maxWidth )
214 {
215 line = rest;
216 return restWidth;
217 }
218
219 // Break the rest of the word into lines.
220 //
221 // TODO: Perhaps avoid recursion? The code is simpler like this but using a
222 // loop in this function would probably be more efficient.
223 return BreakWord( dc, rest, maxWidth, lines, line );
224}
225
226
227#define GRID_CELL_MARGIN 4
228
229int GRIDCELL_AUTOWRAP_STRINGRENDERER::GetHeight( wxDC& aDC, wxGrid* aGrid, int aRow, int aCol )
230{
231 wxGridCellAttr* attr = aGrid->GetOrCreateCellAttr( aRow, aCol );
232 wxRect rect;
233
234 aDC.SetFont( attr->GetFont() );
235 rect.SetWidth( aGrid->GetColSize( aCol ) - ( 2 * GRID_CELL_MARGIN ) );
236
237 const size_t numLines = GetTextLines( *aGrid, aDC, *attr, rect, aRow, aCol ).size();
238 const int textHeight = numLines * aDC.GetCharHeight();
239
240 attr->DecRef();
241
242 return textHeight + ( 2 * GRID_CELL_MARGIN );
243}
244
245
250{
251public:
253 {
254 m_Symbol = aSymbol;
256 m_Row = -1;
257 m_IsOrphan = false;
258 m_Screen = nullptr;
259 }
260
261 // Return a string like mylib:symbol_name from the #LIB_ID of the symbol.
262 wxString GetStringLibId()
263 {
265 }
266
267 SCH_SYMBOL* m_Symbol; // the schematic symbol
268 int m_Row; // the row index in m_grid
269 SCH_SCREEN* m_Screen; // the screen where m_Symbol lives
270 wxString m_Reference; // the schematic reference, only to display it in list
271 wxString m_InitialLibId; // the Lib Id of the symbol before any change.
272 bool m_IsOrphan; // true if a symbol has no corresponding symbol found in libs.
273};
274
275
285{
286public:
289
291
293
294private:
295 void initDlg();
296
304 void AddRowToGrid( bool aMarkRow, const wxString& aReferences, const wxString& aStrLibId );
305
307 bool validateLibIds();
308
315 bool setLibIdByBrowser( int aRow );
316
317 // Event handlers
318
319 // called on a right click or a left double click:
320 void onCellBrowseLib( wxGridEvent& event ) override;
321
322 // Cancel all changes, and close the dialog
323 void onCancel( wxCommandEvent& event ) override
324 {
325 // Just skipping the event doesn't work after the library browser was run
326 if( IsQuasiModal() )
327 EndQuasiModal( wxID_CANCEL );
328 else
329 event.Skip();
330 }
331
332 // Try to find a candidate for non existing symbols
333 void onClickOrphansButton( wxCommandEvent& event ) override;
334
335 // Automatically called when click on OK button
336 bool TransferDataFromWindow() override;
337
338 void AdjustGridColumns();
339
340 void OnSizeGrid( wxSizeEvent& event ) override;
341
342 bool m_isModified; // set to true if the schematic is modified
343 std::vector<int> m_OrphansRowIndexes; // list of rows containing orphan lib_id
344
345 std::vector<SYMBOL_CANDIDATE> m_symbols;
346
348};
349
350
353{
355
356 m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
357
358 initDlg();
359
361}
362
363
365{
366 // Delete the GRID_TRICKS.
367 m_grid->PopEventHandler( true );
368
369 m_autoWrapRenderer->DecRef();
370}
371
372
373// A sort compare function to sort symbols list by LIB_ID and then reference.
374static bool sort_by_libid( const SYMBOL_CANDIDATE& candidate1, const SYMBOL_CANDIDATE& candidate2 )
375{
376 if( candidate1.m_Symbol->GetLibId() == candidate2.m_Symbol->GetLibId() )
377 return candidate1.m_Reference.Cmp( candidate2.m_Reference ) < 0;
378
379 return candidate1.m_Symbol->GetLibId() < candidate2.m_Symbol->GetLibId();
380}
381
382
384{
385 // Clear the FormBuilder rows
386 m_grid->ClearRows();
387
388 m_isModified = false;
389
390 // This option build the full symbol list.
391 // In complex hierarchies, the same symbol is in fact duplicated, but
392 // it is listed with different references (one by sheet instance)
393 // the list is larger and looks like it contains all symbols.
394 SCH_REFERENCE_LIST references;
395
396 // build the full list of symbols including symbol having no symbol in loaded libs
397 // (orphan symbols)
398 GetParent()->Schematic().Hierarchy().GetSymbols( references,
399 true /* include power symbols */,
400 true /* include orphan symbols */ );
401
402 for( unsigned ii = 0; ii < references.GetCount(); ii++ )
403 {
404 SCH_REFERENCE& item = references[ii];
405 SYMBOL_CANDIDATE candidate( item.GetSymbol() );
406 candidate.m_Screen = item.GetSheetPath().LastScreen();
407 SCH_SHEET_PATH sheetpath = item.GetSheetPath();
408 candidate.m_Reference = candidate.m_Symbol->GetRef( &sheetpath );
409 int unitcount = candidate.m_Symbol->GetUnitCount();
410 candidate.m_IsOrphan = ( unitcount == 0 );
411 m_symbols.push_back( candidate );
412 }
413
414 if( m_symbols.size() == 0 )
415 return;
416
417 // now sort by lib id to create groups of items having the same lib id
418 std::sort( m_symbols.begin(), m_symbols.end(), sort_by_libid );
419
420 // Now, fill m_grid
421 wxString last_str_libid = m_symbols.front().GetStringLibId();
422 int row = 0;
423 wxString refs;
424 wxString last_ref;
425 bool mark_cell = m_symbols.front().m_IsOrphan;
426
427 for( SYMBOL_CANDIDATE& symbol : m_symbols )
428 {
429 wxString str_libid = symbol.GetStringLibId();
430
431 if( last_str_libid != str_libid )
432 {
433 // Add last group to grid
434 AddRowToGrid( mark_cell, refs, last_str_libid );
435
436 // prepare next entry
437 mark_cell = symbol.m_IsOrphan;
438 last_str_libid = str_libid;
439 refs.Empty();
440 row++;
441 }
442 else if( symbol.m_Reference == last_ref )
443 {
444 symbol.m_Row = row;
445 continue;
446 }
447
448 last_ref = symbol.m_Reference;
449
450 if( !refs.IsEmpty() )
451 refs += wxT( ", " );
452
453 refs += symbol.m_Reference;
454 symbol.m_Row = row;
455 }
456
457 // Add last symbol group:
458 AddRowToGrid( mark_cell, refs, last_str_libid );
459
460 // Allows only the selection by row
461 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
462
463 m_buttonOrphanItems->Enable( m_OrphansRowIndexes.size() > 0 );
464 Layout();
465}
466
467
469{
470 return dynamic_cast<SCH_EDIT_FRAME*>( wxDialog::GetParent() );
471}
472
473
474void DIALOG_EDIT_SYMBOLS_LIBID::AddRowToGrid( bool aMarkRow, const wxString& aReferences,
475 const wxString& aStrLibId )
476{
477 int row = m_grid->GetNumberRows();
478
479 if( aMarkRow ) // An orphaned symbol exists, set m_AsOrphanCmp as true.
480 m_OrphansRowIndexes.push_back( row );
481
482 m_grid->AppendRows( 1 );
483
484 m_grid->SetCellValue( row, COL_REFS, UnescapeString( aReferences ) );
485 m_grid->SetReadOnly( row, COL_REFS );
486
487 m_grid->SetCellValue( row, COL_CURR_LIBID, UnescapeString( aStrLibId ) );
488 m_grid->SetReadOnly( row, COL_CURR_LIBID );
489
490 if( aMarkRow ) // A symbol is not existing in libraries: mark the cell
491 {
492 wxFont font = m_grid->GetDefaultCellFont();
493 font.MakeBold();
494 font.MakeItalic();
495 m_grid->SetCellFont( row, COL_CURR_LIBID, font );
496 }
497
498 m_grid->SetCellRenderer( row, COL_REFS, m_autoWrapRenderer->Clone() );
499
500 // wxWidgets' AutoRowHeight fails when used with wxGridCellAutoWrapStringRenderer
501 // (fixed in 2014, but didn't get in to wxWidgets 3.0.2)
502 wxClientDC dc( this );
503 m_grid->SetRowSize( row, m_autoWrapRenderer->GetHeight( dc, m_grid, row, COL_REFS ) );
504
505 // set new libid column browse button
506 wxGridCellAttr* attr = new wxGridCellAttr;
507 attr->SetEditor( new GRID_CELL_SYMBOL_ID_EDITOR( this, UnescapeString( aStrLibId ) ) );
508 m_grid->SetAttr( row, COL_NEW_LIBID, attr );
509}
510
511
512wxString getLibIdValue( const WX_GRID* aGrid, int aRow, int aCol )
513{
514 wxString rawValue = aGrid->GetCellValue( aRow, aCol );
515
516 if( rawValue.IsEmpty() )
517 return rawValue;
518
519 wxString itemName;
520 wxString libName = rawValue.BeforeFirst( ':', &itemName );
521
522 return EscapeString( libName, CTX_LIBID ) + ':' + EscapeString( itemName, CTX_LIBID );
523}
524
525
527{
529 return false;
530
531 int row_max = m_grid->GetNumberRows() - 1;
532
533 for( int row = 0; row <= row_max; row++ )
534 {
535 wxString new_libid = getLibIdValue( m_grid, row, COL_NEW_LIBID );
536
537 if( new_libid.IsEmpty() )
538 continue;
539
540 // a new lib id is found. validate this new value
541 LIB_ID id;
542 id.Parse( new_libid );
543
544 if( !id.IsValid() )
545 {
546 wxString msg;
547 msg.Printf( _( "Symbol library identifier %s is not valid." ), new_libid );
548 wxMessageBox( msg );
549
550 m_grid->SetFocus();
551 m_grid->MakeCellVisible( row, COL_NEW_LIBID );
552 m_grid->SetGridCursor( row, COL_NEW_LIBID );
553
554 m_grid->EnableCellEditControl( true );
555 m_grid->ShowCellEditControl();
556
557 return false;
558 }
559 }
560
561 return true;
562}
563
564
566{
567 int row = event.GetRow();
568 m_grid->SelectRow( row ); // only for user, to show the selected line
569
570 setLibIdByBrowser( row );
571
572}
573
574
576{
577 std::vector<wxString> libs = PROJECT_SCH::SchSymbolLibTable( &Prj() )->GetLogicalLibs();
578 wxArrayString aliasNames;
579 wxArrayString candidateSymbNames;
580
581 unsigned fixesCount = 0;
582
583 // Try to find a candidate for non existing symbols in any loaded library
584 for( int orphanRow : m_OrphansRowIndexes )
585 {
586 wxString orphanLibid = getLibIdValue( m_grid, orphanRow, COL_CURR_LIBID );
587 int grid_row_idx = orphanRow; //row index in m_grid for the current item
588
589 LIB_ID curr_libid;
590 curr_libid.Parse( orphanLibid, true );
591 wxString symbolName = curr_libid.GetLibItemName();
592
593 // number of full LIB_ID candidates (because we search for a symbol name
594 // inside all available libraries, perhaps the same symbol name can be found
595 // in more than one library, giving ambiguity
596 int libIdCandidateCount = 0;
597 candidateSymbNames.Clear();
598
599 // now try to find a candidate
600 for( const wxString &lib : libs )
601 {
602 aliasNames.Clear();
603
604 try
605 {
606 PROJECT_SCH::SchSymbolLibTable( &Prj() )->EnumerateSymbolLib( lib, aliasNames );
607 }
608 catch( const IO_ERROR& ) {} // ignore, it is handled below
609
610 if( aliasNames.IsEmpty() )
611 continue;
612
613 // Find a symbol name in symbols inside this library:
614 int index = aliasNames.Index( symbolName );
615
616 if( index != wxNOT_FOUND )
617 {
618 // a candidate is found!
619 libIdCandidateCount++;
620 wxString newLibid = lib + ':' + symbolName;
621
622 // Uses the first found. Most of time, it is alone.
623 // Others will be stored in a candidate list
624 if( libIdCandidateCount <= 1 )
625 {
626 m_grid->SetCellValue( grid_row_idx, COL_NEW_LIBID, UnescapeString( newLibid ) );
627 candidateSymbNames.Add( m_grid->GetCellValue( grid_row_idx, COL_NEW_LIBID ) );
628 fixesCount++;
629 }
630 else // Store other candidates for later selection
631 {
632 candidateSymbNames.Add( UnescapeString( newLibid ) );
633 }
634 }
635 }
636
637 // If more than one LIB_ID candidate, ask for selection between candidates:
638 if( libIdCandidateCount > 1 )
639 {
640 // Mainly for user: select the row being edited
641 m_grid->SelectRow( grid_row_idx );
642
643 wxString msg;
644 msg.Printf( _( "Available Candidates for %s " ),
645 m_grid->GetCellValue( grid_row_idx, COL_CURR_LIBID ) );
646
647 wxSingleChoiceDialog dlg ( this, msg,
648 wxString::Format( _( "Candidates count %d " ),
649 libIdCandidateCount ),
650 candidateSymbNames );
651
652 if( dlg.ShowModal() == wxID_OK )
653 m_grid->SetCellValue( grid_row_idx, COL_NEW_LIBID, dlg.GetStringSelection() );
654 }
655 }
656
657 if( fixesCount < m_OrphansRowIndexes.size() ) // Not all orphan symbols are fixed.
658 {
659 wxMessageBox( wxString::Format( _( "%u link(s) mapped, %u not found" ),
660 fixesCount,
661 (unsigned) m_OrphansRowIndexes.size() - fixesCount ) );
662 }
663 else
664 {
665 wxMessageBox( wxString::Format( _( "All %u link(s) resolved" ), fixesCount ) );
666 }
667}
668
669
671{
672 // Use library viewer to choose a symbol
673 std::vector<PICKED_SYMBOL> dummyHistory;
674 std::vector<PICKED_SYMBOL> dummyAlreadyPlaced;
675 LIB_ID preselected;
676 wxString current = getLibIdValue( m_grid, aRow, COL_NEW_LIBID );
677
678 if( current.IsEmpty() )
679 current = getLibIdValue( m_grid, aRow, COL_CURR_LIBID );
680
681 if( !current.IsEmpty() )
682 preselected.Parse( current, true );
683
685 nullptr, dummyHistory, dummyAlreadyPlaced, false, &preselected, false );
686
687 if( sel.LibId.empty() ) // command aborted
688 return false;
689
690 if( !sel.LibId.IsValid() ) // Should not occur
691 {
692 wxMessageBox( _( "Invalid symbol library identifier" ) );
693 return false;
694 }
695
696 wxString new_libid;
697 new_libid = sel.LibId.Format().wx_str();
698
699 m_grid->SetCellValue( aRow, COL_NEW_LIBID, UnescapeString( new_libid ) );
700
701 return true;
702}
703
704
706{
707 if( !validateLibIds() )
708 return false;
709
710 auto getName = []( const LIB_ID& aLibId )
711 {
712 return UnescapeString( aLibId.GetLibItemName().wx_str() );
713 };
714
715 int row_max = m_grid->GetNumberRows() - 1;
716
717 for( int row = 0; row <= row_max; row++ )
718 {
719 wxString new_libid = getLibIdValue( m_grid, row, COL_NEW_LIBID );
720
721 if( new_libid.IsEmpty() || new_libid == getLibIdValue( m_grid, row, COL_CURR_LIBID ) )
722 continue;
723
724 // A new lib id is found and was already validated.
725 LIB_ID id;
726 id.Parse( new_libid, true );
727
728 for( SYMBOL_CANDIDATE& candidate : m_symbols )
729 {
730 if( candidate.m_Row != row )
731 continue;
732
733 LIB_SYMBOL* symbol = nullptr;
734
735 try
736 {
737 symbol = PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbol( id );
738 }
739 catch( const IO_ERROR& ioe )
740 {
741 wxString msg;
742
743 msg.Printf( _( "Error loading symbol %s from library %s.\n\n%s" ),
744 id.GetLibItemName().wx_str(),
745 id.GetLibNickname().wx_str(),
746 ioe.What() );
747
748 DisplayError( this, msg );
749 }
750
751 if( symbol == nullptr )
752 continue;
753
754 GetParent()->SaveCopyInUndoList( candidate.m_Screen, candidate.m_Symbol,
755 UNDO_REDO::CHANGED, m_isModified );
756 m_isModified = true;
757
758 candidate.m_Screen->Remove( candidate.m_Symbol );
759 SCH_FIELD* value = candidate.m_Symbol->GetField( VALUE_FIELD );
760
761 // If value is a proxy for the itemName then make sure it gets updated
762 if( getName( candidate.m_Symbol->GetLibId() ) == value->GetText() )
763 candidate.m_Symbol->SetValueFieldText( getName( id ) );
764
765 candidate.m_Symbol->SetLibId( id );
766 candidate.m_Symbol->SetLibSymbol( symbol->Flatten().release() );
767 candidate.m_Screen->Append( candidate.m_Symbol );
768 candidate.m_Screen->SetContentModified();
769
770 if ( m_checkBoxUpdateFields->IsChecked() )
771 {
772 candidate.m_Symbol->UpdateFields( nullptr,
773 false, /* update style */
774 false, /* update ref */
775 false, /* update other fields */
776 false, /* reset ref */
777 true /* reset other fields */ );
778 }
779 }
780 }
781
782 return true;
783}
784
785
787{
788 // Account for scroll bars
790
791 int colWidth = width / 3;
792
793 m_grid->SetColSize( COL_REFS, colWidth );
794 width -= colWidth;
795
796 colWidth = 0;
797
798 for( int row = 0; row < m_grid->GetNumberRows(); ++row )
799 {
800 wxString cellValue = m_grid->GetCellValue( row, COL_CURR_LIBID );
801 colWidth = std::max( colWidth, KIUI::GetTextSize( cellValue, m_grid ).x );
802 }
803
804 colWidth += 20;
805 m_grid->SetColSize( COL_CURR_LIBID, colWidth );
806 width -= colWidth;
807
808 colWidth = 0;
809
810 for( int row = 0; row < m_grid->GetNumberRows(); ++row )
811 {
812 wxString cellValue = m_grid->GetCellValue( row, COL_NEW_LIBID );
813 colWidth = std::max( colWidth, KIUI::GetTextSize( cellValue, m_grid ).x );
814 }
815
816 colWidth += 20;
817 m_grid->SetColSize( COL_NEW_LIBID, std::max( colWidth, width ) );
818}
819
820
822{
824
825 wxClientDC dc( this );
826
827 // wxWidgets' AutoRowHeight fails when used with wxGridCellAutoWrapStringRenderer
828 for( int row = 0; row < m_grid->GetNumberRows(); ++row )
829 m_grid->SetRowSize( row, m_autoWrapRenderer->GetHeight( dc, m_grid, row, COL_REFS ) );
830
831 event.Skip();
832}
833
834
836{
837 // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
838 // frame. Therefore this dialog as a modal frame parent, MUST be run under
839 // quasimodal mode for the quasimodal frame support to work. So don't use
840 // the QUASIMODAL macros here.
841 DIALOG_EDIT_SYMBOLS_LIBID dlg( aCaller );
842
843 // DO NOT use ShowModal() here, otherwise the library browser will not work properly.
844 dlg.ShowQuasiModal();
845
846 return dlg.IsSchematicModified();
847}
Class DIALOG_EDIT_SYMBOLS_LIBID_BASE.
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.
void onCancel(wxCommandEvent &event) override
void onCellBrowseLib(wxGridEvent &event) override
bool validateLibIds()
returns true if all new lib id are valid
GRIDCELL_AUTOWRAP_STRINGRENDERER * m_autoWrapRenderer
void AddRowToGrid(bool aMarkRow, const wxString &aReferences, const wxString &aStrLibId)
Add a new row (new entry) in m_grid.
int ShowQuasiModal()
bool IsQuasiModal() const
Definition: dialog_shim.h:113
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.
Definition: eda_text.h:94
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.
Definition: grid_tricks.h:61
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
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.
Definition: lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:51
bool IsValid() const
Check if this LID_ID is valid.
Definition: lib_id.h:172
bool empty() const
Definition: lib_id.h:193
wxString GetUniStringLibId() const
Definition: lib_id.h:148
UTF8 Format() const
Definition: lib_id.cpp:118
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
Define a library symbol object.
Definition: lib_symbol.h:78
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:304
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.
Definition: schematic.cpp:214
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.
Definition: picksymbol.cpp:51
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,...
Definition: sch_field.h:51
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
size_t GetCount() const
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()
Schematic symbol object.
Definition: sch_symbol.h:104
const LIB_ID & GetLibId() const override
Definition: sch_symbol.h:193
int GetUnitCount() const override
Return the number of units per package of the symbol.
Definition: sch_symbol.cpp:468
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:737
A helper to handle symbols to edit.
SYMBOL_CANDIDATE(SCH_SYMBOL *aSymbol)
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.
wxString wx_str() const
Definition: utf8.cpp:45
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:184
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:637
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
This file is part of the common library.
static bool sort_by_libid(const SYMBOL_CANDIDATE &candidate1, const SYMBOL_CANDIDATE &candidate2)
#define COL_REFS
wxString getLibIdValue(const WX_GRID *aGrid, int aRow, int aCol)
#define COL_NEW_LIBID
#define GRID_CELL_MARGIN
#define COL_CURR_LIBID
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...
#define _(s)
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition: wxgtk/ui.cpp:195
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...
Definition: ui_common.cpp:77
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:...
@ CTX_LIBID
Definition: string_utils.h:54
LIB_ID LibId
Definition: sch_screen.h:79
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
wxLogTrace helper definitions.