KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_sheet_properties.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 (C) 2009 Wayne Stambaugh <[email protected]>
5 * Copyright The KiCad Developers, see CHANGELOG.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, see <https://www.gnu.org/licenses/>.
19 */
20
22
23#include <algorithm>
24
25#include <kiface_base.h>
26#include <wx/string.h>
27#include <wx/log.h>
28#include <wx/tooltip.h>
29#include <common.h>
30#include <confirm.h>
31#include <kidialog.h>
32#include <validators.h>
33#include <wx_filename.h>
36#include <kiplatform/ui.h>
37#include <sch_commit.h>
38#include <sch_edit_frame.h>
39#include <sch_io/sch_io.h>
40#include <sch_sheet.h>
41#include <schematic.h>
44#include <template_fieldnames.h>
45#include <bitmaps.h>
46#include <eeschema_settings.h>
48#include <widgets/wx_infobar.h>
49#include <trace_helpers.h>
51#include "wx/dcclient.h"
52#include "string_utils.h"
53
55 bool* aIsUndoable, bool* aClearAnnotationNewItems,
56 bool* aUpdateHierarchyNavigator,
57 wxString* aSourceSheetFilename ) :
59 m_frame( aParent ),
60 m_isUndoable( aIsUndoable ),
61 m_clearAnnotationNewItems( aClearAnnotationNewItems ),
62 m_updateHierarchyNavigator( aUpdateHierarchyNavigator ),
63 m_sourceSheetFilename( aSourceSheetFilename ),
65 m_dummySheet( *aSheet ),
67{
68 m_sheet = aSheet;
69
70 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
71 embeddedFilesStack.push_back( m_sheet->Schematic() );
72
73 m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_sheet, embeddedFilesStack );
76
77 m_grid->SetTable( m_fields );
79 m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this, embeddedFilesStack,
80 [&]( wxCommandEvent& aEvent )
81 {
82 OnAddField( aEvent );
83 } ) );
84 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
85 m_grid->ShowHideColumns( "0 1 2 3 4 5 6 7" );
86 m_shownColumns = m_grid->GetShownColumns();
87
88 if( m_frame->GetColorSettings()->GetOverrideSchItemColors() )
89 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
90
91 wxSize minSize = m_pageNumberTextCtrl->GetMinSize();
92 int minWidth = m_pageNumberTextCtrl->GetTextExtent( wxT( "XXX.XXX" ) ).GetWidth();
93
94 m_pageNumberTextCtrl->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
95
96 int suffixWidth = m_fullSuffixCtrl->GetTextExtent( wxS( "XXXX_XXXX" ) ).GetWidth() + FromDIP( 20 );
97 m_fullSuffixCtrl->SetMinSize( wxSize( suffixWidth, -1 ) );
98
99 wxToolTip::Enable( true );
101
102 // Configure button logos
107
108 // Set font sizes
110 m_hierarchicalPath->SetFont( KIUI::GetSmallInfoFont( this ) );
111
112 m_grid->GetGridWindow()->Bind( wxEVT_MOTION, &DIALOG_SHEET_PROPERTIES::OnGridMotion, this );
113
114 // wxFormBuilder doesn't include this event...
115 m_grid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_SHEET_PROPERTIES::OnGridCellChanging ),
116 nullptr, this );
117
119}
120
121
123{
124 m_grid->GetGridWindow()->Unbind( wxEVT_MOTION, &DIALOG_SHEET_PROPERTIES::OnGridMotion, this );
125
126 // Prevents crash bug in wxGrid's d'tor
127 m_grid->DestroyTable( m_fields );
128
129 m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_SHEET_PROPERTIES::OnGridCellChanging ),
130 nullptr, this );
131
132 // Delete the GRID_TRICKS.
133 m_grid->PopEventHandler( true );
134}
135
136
138{
139 if( !wxDialog::TransferDataToWindow() )
140 return false;
141
142 SCHEMATIC& schematic = m_frame->Schematic();
143 SCH_SHEET_PATH instance = m_frame->GetCurrentSheet();
144 wxString variantName = m_frame->Schematic().GetCurrentVariant();
145
146 for( SCH_FIELD field_copy : GetSheetFieldsForEditing( *m_sheet ) )
147 {
148#ifdef __WINDOWS__
149 // Filenames are stored using unix notation, so convert to Windows notation
150 if( field_copy.GetId() == FIELD_T::SHEET_FILENAME )
151 {
152 wxString filename = field_copy.GetText();
153 filename.Replace( wxT( "/" ), wxT( "\\" ) );
154 field_copy.SetText( filename );
155 }
156#endif
157
158 if( !field_copy.IsMandatory() && m_sheet->GetField( field_copy.GetName() ) )
159 {
160 wxString text = m_sheet->GetFieldText( field_copy.GetName(), &instance, variantName );
161 field_copy.SetText( schematic.ConvertKIIDsToRefs( text ) );
162 }
163
164 // change offset to be symbol-relative
165 field_copy.Offset( -m_sheet->GetPosition() );
166
167 field_copy.SetParent( m_sheet );
168 m_fields->push_back( field_copy );
169 }
170
171 // notify the grid
172 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->size() );
173 m_grid->ProcessTableMessage( msg );
174
175 // border width
176 m_borderWidth.SetValue( m_sheet->GetBorderWidth() );
177
178 // set up color swatches
179 KIGFX::COLOR4D borderColor = m_sheet->GetBorderColor();
180 KIGFX::COLOR4D backgroundColor = m_sheet->GetBackgroundColor();
181
182 m_borderSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
183 m_backgroundSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
184
185 m_borderSwatch->SetSwatchColor( borderColor, false );
186 m_backgroundSwatch->SetSwatchColor( backgroundColor, false );
187
188 KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
189 m_borderSwatch->SetSwatchBackground( canvas );
190 m_backgroundSwatch->SetSwatchBackground( canvas );
191
192 m_cbExcludeFromSim->SetValue( m_sheet->GetExcludedFromSim( &instance, variantName ) );
193 m_cbExcludeFromBom->SetValue( m_sheet->GetExcludedFromBOM( &instance, variantName ) );
194 m_cbExcludeFromBoard->SetValue( m_sheet->GetExcludedFromBoard( &instance, variantName ) );
195 m_cbDNP->SetValue( m_sheet->GetDNP( &instance, variantName ) );
196
197 instance.push_back( m_sheet );
198 m_pageNumberTextCtrl->ChangeValue( instance.GetPageNumber() );
199
200 // Recalculate the dialog size now that the grid is populated and controls
201 // have their real values. On first run, the dialog was sized before data
202 // was available, so the minimum size may not account for the actual content.
203 m_grid->Layout();
204 Layout();
205 GetSizer()->SetSizeHints( this );
206
207 wxSize minSize = GetMinSize();
208 wxSize curSize = GetSize();
209
210 if( curSize.x < minSize.x || curSize.y < minSize.y )
211 SetSize( wxSize( std::max( curSize.x, minSize.x ), std::max( curSize.y, minSize.y ) ) );
212
213 return true;
214}
215
216
218{
219 if( !m_grid->CommitPendingChanges() || !m_grid->Validate() )
220 return false;
221
222 // Check for missing field names.
223 for( size_t i = 0; i < m_fields->size(); ++i )
224 {
225 SCH_FIELD& field = m_fields->at( i );
226
227 if( field.IsMandatory() )
228 continue;
229
230 if( field.GetName( false ).empty() && !field.GetText().empty() )
231 {
232 DisplayErrorMessage( this, _( "Fields must have a name." ) );
233
235 m_delayedFocusRow = (int) i;
236
237 return false;
238 }
239 }
240
241 return true;
242}
243
244
245static bool positioningChanged( const SCH_FIELD& a, const SCH_FIELD& b )
246{
247 if( a.GetPosition() != b.GetPosition() )
248 return true;
249
250 if( a.GetHorizJustify() != b.GetHorizJustify() )
251 return true;
252
253 if( a.GetVertJustify() != b.GetVertJustify() )
254 return true;
255
256 if( a.GetTextAngle() != b.GetTextAngle() )
257 return true;
258
259 return false;
260}
261
262
264{
266 return true;
267
269 return true;
270
271 return false;
272}
273
274
276{
277 wxCHECK( m_sheet && m_frame, false );
278
279 if( !wxDialog::TransferDataFromWindow() ) // Calls our Validate() method.
280 return false;
281
282 if( m_isUndoable )
283 *m_isUndoable = true;
284
285 // Sheet file names can be relative or absolute.
286 wxString sheetFileName = m_fields->GetField( FIELD_T::SHEET_FILENAME )->GetText();
287
288 // Ensure filepath is not empty. (In normal use will be caught by grid validators,
289 // but unedited data from existing files can be bad.)
290 if( sheetFileName.IsEmpty() )
291 {
292 DisplayError( this, _( "A sheet must have a valid file name." ) );
293 return false;
294 }
295
296 if( const SCH_FIELD* suffix = FindField( *m_fields, FIELD_T::SHEET_REF_SUFFIX ) )
297 {
298 wxString msg = GetFieldValidationErrorMessage( FIELD_T::SHEET_REF_SUFFIX, suffix->GetText() );
299
300 if( !msg.IsEmpty() )
301 {
302 DisplayError( this, msg );
303 return false;
304 }
305 }
306
307 // Ensure the filename extension is OK. (In normal use will be caught by grid validators,
308 // but unedited data from existing files can be bad.)
309 sheetFileName = EnsureFileExtension( sheetFileName, FILEEXT::KiCadSchematicFileExtension );
310
311 // Ensure sheetFileName is legal
312 if( !IsFullFileNameValid( sheetFileName ) )
313 {
314 DisplayError( this, _( "A sheet must have a valid file name." ) );
315 return false;
316 }
317
318 wxFileName fn( sheetFileName );
319
320 wxString newRelativeFilename = fn.GetFullPath();
321
322 // Inside Eeschema, filenames are stored using unix notation
323 newRelativeFilename.Replace( wxT( "\\" ), wxT( "/" ) );
324
325 wxString oldFilename = m_sheet->GetField( FIELD_T::SHEET_FILENAME )->GetText();
326 oldFilename.Replace( wxT( "\\" ), wxT( "/" ) );
327
328 bool filename_changed = oldFilename != newRelativeFilename;
329
330 if( filename_changed || m_sheet->IsNew() )
331 {
332 SCH_SCREEN* currentScreen = m_frame->GetCurrentSheet().LastScreen();
333
334 wxCHECK( currentScreen, false );
335
336 bool clearFileName = false;
337
338 // This can happen for the root sheet when opening Eeschema in the stand alone mode.
339 if( currentScreen->GetFileName().IsEmpty() )
340 {
341 clearFileName = true;
342 currentScreen->SetFileName( m_frame->Prj().AbsolutePath( wxT( "noname.kicad_sch" ) ) );
343 }
344
345 wxFileName tmp( fn );
346 wxFileName screenFileName = currentScreen->GetFileName();
347
348 if( fn.IsAbsolute() && fn.MakeRelativeTo( screenFileName.GetPath() ) )
349 {
350 KICAD_MESSAGE_DIALOG makeRelDlg( this, _( "Use relative path for sheet file?" ),
351 _( "Sheet File Path" ),
352 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
353
354 makeRelDlg.SetExtendedMessage( _( "Using relative hierarchical sheet file name paths improves "
355 "schematic portability across systems and platforms. Using "
356 "absolute paths can result in portability issues." ) );
357 makeRelDlg.SetYesNoLabels( KICAD_MESSAGE_DIALOG::ButtonLabel( _( "Use Relative Path" ) ),
358 KICAD_MESSAGE_DIALOG::ButtonLabel( _( "Use Absolute Path" ) ) );
359
360 if( makeRelDlg.ShowModal() == wxID_YES )
361 {
362 wxLogTrace( tracePathsAndFiles, "\n Converted absolute path: '%s'"
363 "\n to relative path: '%s'",
364 tmp.GetPath(),
365 fn.GetPath() );
366 m_fields->GetField( FIELD_T::SHEET_FILENAME )->SetText( fn.GetFullPath() );
367 newRelativeFilename = fn.GetFullPath();
368 }
369 }
370
371 if( !onSheetFilenameChanged( newRelativeFilename ) )
372 {
373 if( clearFileName )
374 currentScreen->SetFileName( wxEmptyString );
375 else
377
378 return false;
379 }
381 {
383 }
384
385 if( clearFileName )
386 currentScreen->SetFileName( wxEmptyString );
387
388 // One last validity check (and potential repair) just to be sure to be sure
389 SCH_SHEET_LIST repairedList;
390 repairedList.BuildSheetList( &m_frame->Schematic().Root(), true );
391 }
392
393 wxString newSheetname = m_fields->GetField( FIELD_T::SHEET_NAME )->GetText();
394
395 if( ( newSheetname != m_sheet->GetName() ) && m_updateHierarchyNavigator )
397
398 if( newSheetname.IsEmpty() )
399 newSheetname = _( "Untitled Sheet" );
400
401 m_fields->GetField( FIELD_T::SHEET_NAME )->SetText( newSheetname );
402
403 // Net names embed the sheet path, so retarget netclass/color assignments on a rename.
404 SCH_SHEET_PATH renamedPath = m_frame->GetCurrentSheet();
405 renamedPath.push_back( m_sheet );
406 wxString oldNetPrefix = renamedPath.PathHumanReadable( true, false, true );
407
408 m_sheet->SetName( newSheetname );
409 m_sheet->SetFileName( newRelativeFilename );
410
411 wxString newNetPrefix = renamedPath.PathHumanReadable( true, false, true );
412
413 if( oldNetPrefix != newNetPrefix )
414 m_frame->Prj().GetProjectFile().NetSettings()->RenameNetPathPrefix( oldNetPrefix, newNetPrefix );
415
416 // change all field positions from relative to absolute
417 for( SCH_FIELD& m_field : *m_fields)
418 m_field.Offset( m_sheet->GetPosition() );
419
421 m_sheet->SetFieldsAutoplaced( AUTOPLACE_NONE );
422
423 SCH_SHEET_PATH instance = m_frame->GetCurrentSheet();
424 wxString variantName = m_frame->Schematic().GetCurrentVariant();
425
426 int ordinal = 42; // Arbitrarily larger than any mandatory FIELD_T ids.
427
428 for( SCH_FIELD& field : *m_fields )
429 {
430 const wxString& fieldName = field.GetUntranslatedName();
431
432 if( field.IsEmpty() )
433 continue;
434 else if( fieldName.IsEmpty() )
435 field.SetName( _( "untitled" ) );
436
437 if( !field.IsMandatory() )
438 field.SetOrdinal( ordinal++, FIELD_T::SHEET_USER );
439
440 SCH_FIELD* existingField = m_sheet->GetField( fieldName );
441 SCH_FIELD* tmp;
442
443 if( !existingField && field.GetId() == FIELD_T::SHEET_REF_SUFFIX && field.GetText().IsEmpty() )
444 continue;
445
446 if( !existingField )
447 {
448 tmp = m_sheet->AddField( field );
449 tmp->SetParent( m_sheet );
450 }
451 else
452 {
453 wxString defaultText = m_sheet->Schematic()->ConvertRefsToKIIDs( existingField->GetText() );
454 tmp = const_cast<SCH_FIELD*>( existingField );
455
456 *tmp = field;
457
458 if( !variantName.IsEmpty() )
459 {
460 // Restore the default field text for existing fields.
461 tmp->SetText( defaultText, &instance );
462
463 wxString variantText = m_sheet->Schematic()->ConvertRefsToKIIDs( field.GetText() );
464 tmp->SetText( variantText, &instance, variantName );
465 }
466 }
467 }
468
469 for( int ii = (int) m_sheet->GetFields().size() - 1; ii >= 0; ii-- )
470 {
471 SCH_FIELD& sheetField = m_sheet->GetFields()[ii];
472
473 if( sheetField.IsMandatory() )
474 continue;
475
476 bool found = false;
477
478 for( const SCH_FIELD& editedField : *m_fields )
479 {
480 if( editedField.GetName() == sheetField.GetName() )
481 {
482 found = true;
483 break;
484 }
485 }
486
487 if( !found )
488 m_sheet->GetFields().erase( m_sheet->GetFields().begin() + ii );
489 }
490
491 std::stable_sort( m_sheet->GetFields().begin(), m_sheet->GetFields().end(),
492 []( const SCH_FIELD& lhs, const SCH_FIELD& rhs )
493 {
494 return lhs.GetOrdinal() < rhs.GetOrdinal();
495 } );
496
497 m_sheet->SetBorderWidth( m_borderWidth.GetIntValue() );
498
499 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
500
501 if( colorSettings->GetOverrideSchItemColors()
502 && ( m_sheet->GetBorderColor() != m_borderSwatch->GetSwatchColor() ||
503 m_sheet->GetBackgroundColor() != m_backgroundSwatch->GetSwatchColor() ) )
504 {
505 wxPanel temp( this );
506 temp.Hide();
507 PANEL_EESCHEMA_COLOR_SETTINGS prefs( &temp );
508 wxString checkboxLabel = prefs.m_optOverrideColors->GetLabel();
509
510 KIDIALOG dlg( this, _( "Note: item colors are overridden in the current color theme." ),
512 dlg.ShowDetailedText( wxString::Format( _( "To see individual item colors uncheck '%s'\n"
513 "in Preferences > Schematic Editor > Colors." ),
514 checkboxLabel ) );
515 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
516 dlg.ShowModal();
517 }
518
519 m_sheet->SetBorderColor( m_borderSwatch->GetSwatchColor() );
520 m_sheet->SetBackgroundColor( m_backgroundSwatch->GetSwatchColor() );
521
522 m_sheet->SetExcludedFromSim( m_cbExcludeFromSim->GetValue(), &instance, variantName );
523 m_sheet->SetExcludedFromBOM( m_cbExcludeFromBom->GetValue(), &instance, variantName );
524 m_sheet->SetExcludedFromBoard( m_cbExcludeFromBoard->GetValue() );
525 m_sheet->SetDNP( m_cbDNP->GetValue(), &instance, variantName );
526
527 instance.push_back( m_sheet );
528
529 instance.SetPageNumber( m_pageNumberTextCtrl->GetValue() );
530
531 m_frame->TestDanglingEnds();
532
533 // Refresh all sheets in case ordering changed.
534 for( SCH_ITEM* item : m_frame->GetScreen()->Items().OfType( SCH_SHEET_T ) )
535 m_frame->UpdateItem( item );
536
537 return true;
538}
539
540
541bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilename )
542{
543 return m_frame->ChangeSheetFile( m_sheet, aNewFilename, m_clearAnnotationNewItems, m_isUndoable,
545}
546
547
548void DIALOG_SHEET_PROPERTIES::OnGridMotion( wxMouseEvent& aEvent )
549{
550 aEvent.Skip();
551
552 wxPoint pos = m_grid->CalcUnscrolledPosition( aEvent.GetPosition() );
553 int row = m_grid->YToRow( pos.y );
554 wxString tooltip;
555
556 if( row >= 0 && row < m_fields->GetNumberRows() && m_fields->at( row ).GetId() == FIELD_T::SHEET_REF_SUFFIX )
557 {
558 tooltip = _( "Appended to component references in this sheet. Example: _M1 produces R1_M1." );
559 }
560
561 if( m_grid->GetGridWindow()->GetToolTipText() != tooltip )
562 m_grid->GetGridWindow()->SetToolTip( tooltip );
563}
564
565
567{
568 bool success = true;
569 wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
570 wxControl* control = editor->GetControl();
571
572 if( control && control->GetValidator() )
573 success = control->GetValidator()->Validate( control );
574
575 if( !success )
576 {
577 event.Veto();
578 m_delayedFocusRow = event.GetRow();
579 m_delayedFocusColumn = event.GetCol();
580 }
581 else if( event.GetCol() == FDC_NAME )
582 {
583 wxString newName = event.GetString();
584
585 for( int i = 0; i < m_grid->GetNumberRows(); ++i )
586 {
587 if( i == event.GetRow() )
588 continue;
589
590 if( FieldNamesAreDuplicates( newName, m_grid->GetCellValue( i, FDC_NAME ), SHEET_MANDATORY_FIELDS )
591 || newName == m_fields->at( i ).GetUntranslatedName() )
592 {
593 DisplayError( this, wxString::Format( _( "Field name '%s' already in use." ), newName ) );
594 event.Veto();
595 m_delayedFocusRow = event.GetRow();
596 m_delayedFocusColumn = event.GetCol();
597 break;
598 }
599 }
600 }
601
602 editor->DecRef();
603}
604
605
606void DIALOG_SHEET_PROPERTIES::OnAddField( wxCommandEvent& event )
607{
608 m_grid->OnAddRow(
609 [&]() -> std::pair<int, int>
610 {
612
613 newField.SetTextAngle( m_fields->GetField( FIELD_T::SHEET_NAME )->GetTextAngle() );
614 newField.SetVisible( false );
615 m_fields->push_back( newField );
616
617 // notify the grid
618 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
619 m_grid->ProcessTableMessage( msg );
620 return { m_fields->GetNumberRows() - 1, FDC_NAME };
621 } );
622}
623
624
625void DIALOG_SHEET_PROPERTIES::OnDeleteField( wxCommandEvent& event )
626{
627 m_grid->OnDeleteRows(
628 [&]( int row )
629 {
630 if( row < m_fields->GetMandatoryRowCount() )
631 {
632 DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
633 m_fields->GetMandatoryRowCount() ) );
634 return false;
635 }
636
637 if( m_fields->at( row ).GetId() == FIELD_T::SHEET_REF_SUFFIX )
638 {
639 DisplayError( this, _( "The reference suffix field cannot be deleted. Clear its value instead." ) );
640 return false;
641 }
642
643 return true;
644 },
645 [&]( int row )
646 {
647 if( !m_fields->EraseRow( row ) )
648 return;
649
650 // notify the grid
651 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
652 m_grid->ProcessTableMessage( msg );
653 } );
654}
655
656
657void DIALOG_SHEET_PROPERTIES::OnMoveUp( wxCommandEvent& event )
658{
659 m_grid->OnMoveRowUp(
660 [&]( int row )
661 {
662 return row > m_fields->GetMandatoryRowCount() + 1;
663 },
664 [&]( int row )
665 {
666 m_fields->SwapRows( row, row - 1 );
667 m_grid->ForceRefresh();
668 } );
669}
670
671
672void DIALOG_SHEET_PROPERTIES::OnMoveDown( wxCommandEvent& event )
673{
674 m_grid->OnMoveRowDown(
675 [&]( int row )
676 {
677 return row >= m_fields->GetMandatoryRowCount() + 1;
678 },
679 [&]( int row )
680 {
681 m_fields->SwapRows( row, row + 1 );
682 m_grid->ForceRefresh();
683 } );
684}
685
686
687void DIALOG_SHEET_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
688{
689 std::bitset<64> shownColumns = m_grid->GetShownColumns();
690
691 if( shownColumns != m_shownColumns )
692 {
693 m_shownColumns = shownColumns;
694
695 if( !m_grid->IsCellEditControlShown() )
696 m_grid->SetGridWidthsDirty();
697 }
698
699 // Propagate changes in sheetname to displayed hierarchical path
700 int sheetnameRow = m_fields->GetFieldRow( FIELD_T::SHEET_NAME );
701 wxString path = m_frame->GetCurrentSheet().PathHumanReadable( false );
702
703 if( path.Last() != '/' )
704 path.Append( '/' );
705
706 wxGridCellEditor* editor = m_grid->GetCellEditor( sheetnameRow, FDC_VALUE );
707 wxControl* control = editor->GetControl();
708 wxTextEntry* textControl = dynamic_cast<wxTextEntry*>( control );
709 wxString sheetName;
710
711 if( textControl )
712 sheetName = textControl->GetValue();
713 else
714 sheetName = m_grid->GetCellValue( sheetnameRow, FDC_VALUE );
715
716 m_dummySheet.SetFields( *m_fields );
717 m_dummySheetNameField.SetText( sheetName );
718 path += m_dummySheetNameField.GetShownText( FOR_GUI );
719
720 editor->DecRef();
721
722 wxClientDC dc( m_hierarchicalPathLabel );
723 int width = m_sizerBottom->GetSize().x - m_stdDialogButtonSizer->GetSize().x
724 - m_hierarchicalPathLabel->GetSize().x
725 - 30;
726
727 path = wxControl::Ellipsize( path, dc, wxELLIPSIZE_START, width, wxELLIPSIZE_FLAGS_NONE );
728
729 if( m_hierarchicalPath->GetLabel() != path )
730 m_hierarchicalPath->SetLabel( path );
731
732 // Preview the configured suffix even when separate numbering leaves it inactive
733 const SCH_SHEET_PATH& parentPath = m_frame->GetCurrentSheet();
734
735 // Edits under a variant become overrides, and suffixes only read base text
736 if( !m_frame->Schematic().GetCurrentVariant().IsEmpty() )
737 {
738 for( SCH_FIELD& field : m_dummySheet.GetFields() )
739 {
740 const SCH_FIELD* baseField = std::as_const( *m_sheet ).GetField( field.GetName() );
741
742 if( baseField && field.GetId() != FIELD_T::SHEET_REF_SUFFIX )
743 field.SetText( baseField->GetText() );
744 }
745 }
746
747 wxString fullSuffix = parentPath.ComposeRefSuffix() + m_dummySheet.GetRefSuffix( parentPath );
748
749 wxString preview = fullSuffix.IsEmpty() ? _( "None" ) : fullSuffix;
750
751 if( m_fullSuffixCtrl->GetValue() != preview )
752 m_fullSuffixCtrl->ChangeValue( preview );
753
754 // Handle a delayed focus
755 if( m_delayedFocusRow >= 0 && IsShownOnScreen() )
756 {
757 m_grid->SetFocus();
758 m_grid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
760
761 m_grid->EnableCellEditControl( true );
762 m_grid->ShowCellEditControl();
763
766 }
767}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
Color settings are a bit different than most of the settings objects in that there can be more than o...
bool GetOverrideSchItemColors() const
wxStdDialogButtonSizer * m_stdDialogButtonSizer
DIALOG_SHEET_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Sheet Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU)
void OnAddField(wxCommandEvent &event) override
void OnGridMotion(wxMouseEvent &aEvent)
void OnMoveDown(wxCommandEvent &event) override
void OnGridCellChanging(wxGridEvent &event)
void OnDeleteField(wxCommandEvent &event) override
bool onSheetFilenameChanged(const wxString &aNewFilename)
void OnUpdateUI(wxUpdateUIEvent &event) override
void OnMoveUp(wxCommandEvent &event) override
DIALOG_SHEET_PROPERTIES(SCH_EDIT_FRAME *aParent, SCH_SHEET *aSheet, bool *aIsUndoable, bool *aClearAnnotationNewItems, bool *aUpdateHierarchyNavigator, wxString *aSourceSheetFilename)
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:95
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:239
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
virtual EDA_ANGLE GetTextAngle() const
Definition eda_text.h:178
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:242
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:269
SCH_FIELD * GetField(FIELD_T aFieldId)
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:38
@ KD_WARNING
Definition kidialog.h:43
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition kidialog.cpp:51
int ShowModal() override
Definition kidialog.cpp:89
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Holds all the data relating to one schematic.
Definition schematic.h:155
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Schematic editor (Eeschema) main window.
bool IsMandatory() const
VECTOR2I GetPosition() const override
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
FIELD_T GetId() const
Definition sch_field.h:143
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
const wxString & GetFileName() const
Definition sch_screen.h:157
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString GetPageNumber() const
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false, bool aEscapeSheetNames=false) const
Return the sheet path in a human readable form made from the sheet names.
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
wxString ComposeRefSuffix() const
Compose the reference suffixes of every sheet in this path, from the root down.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:50
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
Definition common.cpp:880
@ FOR_GUI
Definition common.h:93
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
#define KICAD_MESSAGE_DIALOG
Definition confirm.h:48
static bool positioningChanged(const SCH_FIELD &a, const SCH_FIELD &b)
static bool positioningChanged(const SCH_FIELD &a, const SCH_FIELD &b)
const int minSize
Push and Shove router track width and via size dialog.
#define _(s)
std::vector< SCH_FIELD > GetSheetFieldsForEditing(const SCH_SHEET &aSheet)
@ FDC_NAME
@ FDC_VALUE
static const std::string KiCadSchematicFileExtension
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:519
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
const SCH_FIELD * FindField(const std::vector< SCH_FIELD > &aFields, FIELD_T aFieldId)
Definition sch_field.h:390
@ AUTOPLACE_NONE
Definition sch_item.h:74
bool IsFullFileNameValid(const wxString &aFullFilename)
Checks if a full filename is valid, i.e.
bool FieldNamesAreDuplicates(const wxString &aLhs, const wxString &aRhs, std::initializer_list< FIELD_T > aMandatoryFields)
Test whether two field names should be treated as duplicates for the purposes of field name uniquenes...
wxString GetUserFieldName(int aFieldNdx, TRANSLATION aTranslation)
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ SHEET_REF_SUFFIX
Optional sheet field appended to the references of the sheet's symbols.
@ TRANSLATED
#define SHEET_MANDATORY_FIELDS
DATABASE_CONNECTION dc(odbcBackend(cs))
std::string path
wxLogTrace helper definitions.
@ SCH_SHEET_T
Definition typeinfo.h:171
wxString GetFieldValidationErrorMessage(FIELD_T aFieldId, const wxString &aValue)
Return the error message if aValue is invalid for aFieldId.
Custom text control validator definitions.
Definition of file extensions used in Kicad.