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