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