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, 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
26
27#include <kiface_base.h>
28#include <wx/string.h>
29#include <wx/log.h>
30#include <wx/tooltip.h>
31#include <common.h>
32#include <confirm.h>
33#include <kidialog.h>
34#include <validators.h>
35#include <wx_filename.h>
38#include <kiplatform/ui.h>
39#include <sch_commit.h>
40#include <sch_edit_frame.h>
41#include <sch_io/sch_io.h>
42#include <sch_sheet.h>
43#include <schematic.h>
44#include <bitmaps.h>
45#include <eeschema_settings.h>
47#include <trace_helpers.h>
49#include "wx/dcclient.h"
50#include "string_utils.h"
51
53 bool* aIsUndoable, bool* aClearAnnotationNewItems,
54 bool* aUpdateHierarchyNavigator,
55 wxString* aSourceSheetFilename ) :
57 m_frame( aParent ),
58 m_isUndoable( aIsUndoable ),
59 m_clearAnnotationNewItems( aClearAnnotationNewItems ),
60 m_updateHierarchyNavigator( aUpdateHierarchyNavigator ),
61 m_sourceSheetFilename( aSourceSheetFilename ),
63 m_dummySheet( *aSheet ),
65{
66 m_sheet = aSheet;
67 m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_sheet );
70
71 m_grid->SetTable( m_fields );
72 m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this, { &aParent->Schematic() },
73 [&]( wxCommandEvent& aEvent )
74 {
75 OnAddField( aEvent );
76 } ) );
77 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
78 m_grid->ShowHideColumns( "0 1 2 3 4 5 6 7" );
79 m_shownColumns = m_grid->GetShownColumns();
80
81 if( m_frame->GetColorSettings()->GetOverrideSchItemColors() )
82 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
83
84 wxSize minSize = m_pageNumberTextCtrl->GetMinSize();
85 int minWidth = m_pageNumberTextCtrl->GetTextExtent( wxT( "XXX.XXX" ) ).GetWidth();
86
87 m_pageNumberTextCtrl->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
88
89 wxToolTip::Enable( true );
91
92 // Configure button logos
97
98 // Set font sizes
100 m_hierarchicalPath->SetFont( KIUI::GetSmallInfoFont( this ) );
101
102 // wxFormBuilder doesn't include this event...
103 m_grid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_SHEET_PROPERTIES::OnGridCellChanging ),
104 nullptr, this );
105
107}
108
109
111{
112 // Prevents crash bug in wxGrid's d'tor
113 m_grid->DestroyTable( m_fields );
114
115 m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_SHEET_PROPERTIES::OnGridCellChanging ),
116 nullptr, this );
117
118 // Delete the GRID_TRICKS.
119 m_grid->PopEventHandler( true );
120}
121
122
124{
125 if( !wxDialog::TransferDataToWindow() )
126 return false;
127
128 // Push a copy of each field into m_updateFields
129 for( SCH_FIELD& field : m_sheet->GetFields() )
130 {
131 SCH_FIELD field_copy( field );
132
133#ifdef __WINDOWS__
134 // Filenames are stored using unix notation, so convert to Windows notation
135 if( field_copy.GetId() == FIELD_T::SHEET_FILENAME )
136 {
137 wxString filename = field_copy.GetText();
138 filename.Replace( wxT( "/" ), wxT( "\\" ) );
139 field_copy.SetText( filename );
140 }
141#endif
142
143 // change offset to be symbol-relative
144 field_copy.Offset( -m_sheet->GetPosition() );
145
146 m_fields->push_back( field_copy );
147 }
148
149 // notify the grid
150 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->size() );
151 m_grid->ProcessTableMessage( msg );
152
153 // border width
154 m_borderWidth.SetValue( m_sheet->GetBorderWidth() );
155
156 // set up color swatches
157 KIGFX::COLOR4D borderColor = m_sheet->GetBorderColor();
158 KIGFX::COLOR4D backgroundColor = m_sheet->GetBackgroundColor();
159
160 m_borderSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
161 m_backgroundSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
162
163 m_borderSwatch->SetSwatchColor( borderColor, false );
164 m_backgroundSwatch->SetSwatchColor( backgroundColor, false );
165
166 KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
167 m_borderSwatch->SetSwatchBackground( canvas );
168 m_backgroundSwatch->SetSwatchBackground( canvas );
169
170 SCH_SHEET_PATH instance = m_frame->GetCurrentSheet();
171 instance.push_back( m_sheet );
172
173 m_pageNumberTextCtrl->ChangeValue( instance.GetPageNumber() );
174
175 m_cbExcludeFromSim->SetValue( m_sheet->GetExcludedFromSim() );
176 m_cbExcludeFromBom->SetValue( m_sheet->GetExcludedFromBOM() );
177 m_cbExcludeFromBoard->SetValue( m_sheet->GetExcludedFromBoard() );
178 m_cbDNP->SetValue( m_sheet->GetDNP() );
179
180 return true;
181}
182
183
185{
186 if( !m_grid->CommitPendingChanges() || !m_grid->Validate() )
187 return false;
188
189 // Check for missing field names.
190 for( size_t i = 0; i < m_fields->size(); ++i )
191 {
192 SCH_FIELD& field = m_fields->at( i );
193
194 if( field.IsMandatory() )
195 continue;
196
197 if( field.GetName( false ).empty() && !field.GetText().empty() )
198 {
199 DisplayErrorMessage( this, _( "Fields must have a name." ) );
200
202 m_delayedFocusRow = (int) i;
203
204 return false;
205 }
206 }
207
208 return true;
209}
210
211
212static bool positioningChanged( const SCH_FIELD& a, const SCH_FIELD& b )
213{
214 if( a.GetPosition() != b.GetPosition() )
215 return true;
216
217 if( a.GetHorizJustify() != b.GetHorizJustify() )
218 return true;
219
220 if( a.GetVertJustify() != b.GetVertJustify() )
221 return true;
222
223 if( a.GetTextAngle() != b.GetTextAngle() )
224 return true;
225
226 return false;
227}
228
229
231{
233 return true;
234
236 return true;
237
238 return false;
239}
240
241
243{
244 wxCHECK( m_sheet && m_frame, false );
245
246 if( !wxDialog::TransferDataFromWindow() ) // Calls our Validate() method.
247 return false;
248
249 if( m_isUndoable )
250 *m_isUndoable = true;
251
252 // Sheet file names can be relative or absolute.
253 wxString sheetFileName = m_fields->GetField( FIELD_T::SHEET_FILENAME )->GetText();
254
255 // Ensure filepath is not empty. (In normal use will be caught by grid validators,
256 // but unedited data from existing files can be bad.)
257 if( sheetFileName.IsEmpty() )
258 {
259 DisplayError( this, _( "A sheet must have a valid file name." ) );
260 return false;
261 }
262
263 // Ensure the filename extension is OK. (In normal use will be caught by grid validators,
264 // but unedited data from existing files can be bad.)
265 sheetFileName = EnsureFileExtension( sheetFileName, FILEEXT::KiCadSchematicFileExtension );
266
267 // Ensure sheetFileName is legal
268 if( !IsFullFileNameValid( sheetFileName ) )
269 {
270 DisplayError( this, _( "A sheet must have a valid file name." ) );
271 return false;
272 }
273
274 wxFileName fn( sheetFileName );
275
276 wxString newRelativeFilename = fn.GetFullPath();
277
278 // Inside Eeschema, filenames are stored using unix notation
279 newRelativeFilename.Replace( wxT( "\\" ), wxT( "/" ) );
280
281 wxString oldFilename = m_sheet->GetField( FIELD_T::SHEET_FILENAME )->GetText();
282 oldFilename.Replace( wxT( "\\" ), wxT( "/" ) );
283
284 bool filename_changed = oldFilename != newRelativeFilename;
285
286 if( filename_changed || m_sheet->IsNew() )
287 {
288 SCH_SCREEN* currentScreen = m_frame->GetCurrentSheet().LastScreen();
289
290 wxCHECK( currentScreen, false );
291
292 bool clearFileName = false;
293
294 // This can happen for the root sheet when opening Eeschema in the stand alone mode.
295 if( currentScreen->GetFileName().IsEmpty() )
296 {
297 clearFileName = true;
298 currentScreen->SetFileName( m_frame->Prj().AbsolutePath( wxT( "noname.kicad_sch" ) ) );
299 }
300
301 wxFileName tmp( fn );
302 wxFileName screenFileName = currentScreen->GetFileName();
303
304 if( fn.IsAbsolute() && fn.MakeRelativeTo( screenFileName.GetPath() ) )
305 {
306 wxMessageDialog makeRelDlg( this, _( "Use relative path for sheet file?" ), _( "Sheet File Path" ),
307 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
308
309 makeRelDlg.SetExtendedMessage( _( "Using relative hierarchical sheet file name paths improves "
310 "schematic portability across systems and platforms. Using "
311 "absolute paths can result in portability issues." ) );
312 makeRelDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Use Relative Path" ) ),
313 wxMessageDialog::ButtonLabel( _( "Use Absolute Path" ) ) );
314
315 if( makeRelDlg.ShowModal() == wxID_YES )
316 {
317 wxLogTrace( tracePathsAndFiles, "\n Converted absolute path: '%s'"
318 "\n to relative path: '%s'",
319 tmp.GetPath(),
320 fn.GetPath() );
321 m_fields->GetField( FIELD_T::SHEET_FILENAME )->SetText( fn.GetFullPath() );
322 newRelativeFilename = fn.GetFullPath();
323 }
324 }
325
326 if( !onSheetFilenameChanged( newRelativeFilename ) )
327 {
328 if( clearFileName )
329 currentScreen->SetFileName( wxEmptyString );
330 else
332
333 return false;
334 }
336 {
338 }
339
340 if( clearFileName )
341 currentScreen->SetFileName( wxEmptyString );
342
343 // One last validity check (and potential repair) just to be sure to be sure
344 SCH_SHEET_LIST repairedList;
345 repairedList.BuildSheetList( &m_frame->Schematic().Root(), true );
346 }
347
348 wxString newSheetname = m_fields->GetField( FIELD_T::SHEET_NAME )->GetText();
349
350 if( ( newSheetname != m_sheet->GetName() ) && m_updateHierarchyNavigator )
352
353 if( newSheetname.IsEmpty() )
354 newSheetname = _( "Untitled Sheet" );
355
356 m_fields->GetField( FIELD_T::SHEET_NAME )->SetText( newSheetname );
357
358 // change all field positions from relative to absolute
359 for( SCH_FIELD& m_field : *m_fields)
360 m_field.Offset( m_sheet->GetPosition() );
361
363 m_sheet->SetFieldsAutoplaced( AUTOPLACE_NONE );
364
365 for( int ii = m_fields->GetNumberRows() - 1; ii >= 0; ii-- )
366 {
367 SCH_FIELD& field = m_fields->at( ii );
368
369 if( field.IsMandatory() )
370 continue;
371
372 const wxString& fieldName = field.GetCanonicalName();
373
374 if( field.IsEmpty() )
375 m_fields->erase( m_fields->begin() + ii );
376 else if( fieldName.IsEmpty() )
377 field.SetName( _( "untitled" ) );
378 }
379
380 m_sheet->SetFields( *m_fields );
381
382 m_sheet->SetBorderWidth( m_borderWidth.GetIntValue() );
383
384 COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
385
386 if( colorSettings->GetOverrideSchItemColors()
387 && ( m_sheet->GetBorderColor() != m_borderSwatch->GetSwatchColor() ||
388 m_sheet->GetBackgroundColor() != m_backgroundSwatch->GetSwatchColor() ) )
389 {
390 wxPanel temp( this );
391 temp.Hide();
392 PANEL_EESCHEMA_COLOR_SETTINGS prefs( &temp );
393 wxString checkboxLabel = prefs.m_optOverrideColors->GetLabel();
394
395 KIDIALOG dlg( this, _( "Note: item colors are overridden in the current color theme." ),
397 dlg.ShowDetailedText( wxString::Format( _( "To see individual item colors uncheck '%s'\n"
398 "in Preferences > Schematic Editor > Colors." ),
399 checkboxLabel ) );
400 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
401 dlg.ShowModal();
402 }
403
404 m_sheet->SetBorderColor( m_borderSwatch->GetSwatchColor() );
405 m_sheet->SetBackgroundColor( m_backgroundSwatch->GetSwatchColor() );
406
407 m_sheet->SetExcludedFromSim( m_cbExcludeFromSim->GetValue() );
408 m_sheet->SetExcludedFromBOM( m_cbExcludeFromBom->GetValue() );
409 m_sheet->SetExcludedFromBoard( m_cbExcludeFromBoard->GetValue() );
410 m_sheet->SetDNP( m_cbDNP->GetValue() );
411
412 SCH_SHEET_PATH instance = m_frame->GetCurrentSheet();
413
414 instance.push_back( m_sheet );
415
416 instance.SetPageNumber( m_pageNumberTextCtrl->GetValue() );
417
418 m_frame->TestDanglingEnds();
419
420 // Refresh all sheets in case ordering changed.
421 for( SCH_ITEM* item : m_frame->GetScreen()->Items().OfType( SCH_SHEET_T ) )
422 m_frame->UpdateItem( item );
423
424 return true;
425}
426
427
428bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilename )
429{
430 wxString msg;
431 wxFileName sheetFileName( EnsureFileExtension( aNewFilename, FILEEXT::KiCadSchematicFileExtension ) );
432
433 // Sheet file names are relative to the path of the current sheet. This allows for
434 // nesting of schematic files in subfolders. Screen file names are always absolute.
435 SCHEMATIC& schematic = m_frame->Schematic();
436 SCH_SHEET_LIST fullHierarchy = schematic.Hierarchy();
437 wxFileName screenFileName( sheetFileName );
438 wxFileName tmp( sheetFileName );
439 SCH_SCREEN* currentScreen = m_frame->GetCurrentSheet().LastScreen();
440
441 wxCHECK( currentScreen, false );
442
443 // SCH_SCREEN file names are always absolute.
444 wxFileName currentScreenFileName = currentScreen->GetFileName();
445
446 if( !screenFileName.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS, currentScreenFileName.GetPath() ) )
447 {
448 msg = wxString::Format( _( "Cannot normalize new sheet schematic file path:\n"
449 "'%s'\n"
450 "against parent sheet schematic file path:\n"
451 "'%s'." ),
452 sheetFileName.GetPath(),
453 currentScreenFileName.GetPath() );
454 DisplayError( this, msg );
455 return false;
456 }
457
458 wxString newAbsoluteFilename = screenFileName.GetFullPath();
459
460 // Inside Eeschema, filenames are stored using unix notation
461 newAbsoluteFilename.Replace( wxT( "\\" ), wxT( "/" ) );
462
463 bool renameFile = false;
464 bool loadFromFile = false;
465 bool clearAnnotation = false;
466 bool isExistingSheet = false;
467 SCH_SCREEN* useScreen = nullptr;
468 SCH_SCREEN* oldScreen = nullptr;
469
470 // Search for a schematic file having the same filename already in use in the hierarchy
471 // or on disk, in order to reuse it.
472 if( !schematic.Root().SearchHierarchy( newAbsoluteFilename, &useScreen ) )
473 {
474 loadFromFile = wxFileExists( newAbsoluteFilename );
475
476 wxLogTrace( tracePathsAndFiles, "\n Sheet requested file '%s', %s",
477 newAbsoluteFilename,
478 loadFromFile ? "found" : "not found" );
479 }
480
481 if( m_sheet->GetScreen() == nullptr ) // New just created sheet.
482 {
483 if( !m_frame->AllowCaseSensitiveFileNameClashes( m_sheet->GetFileName(), newAbsoluteFilename ) )
484 return false;
485
486 if( useScreen || loadFromFile ) // Load from existing file.
487 {
488 clearAnnotation = true;
489
490 if( !IsOK( this, wxString::Format( _( "'%s' already exists." ), sheetFileName.GetFullName() )
491 + wxT( "\n\n" )
492 + wxString::Format( _( "Link '%s' to this file?" ), newAbsoluteFilename ) ) )
493 {
494 return false;
495 }
496 }
497 // If we are drawing a sheet from a design block/sheet import, we need to copy the
498 // sheet to the current directory.
499 else if( m_sourceSheetFilename && !m_sourceSheetFilename->IsEmpty() )
500 {
501 loadFromFile = true;
502
503 if( !wxCopyFile( *m_sourceSheetFilename, newAbsoluteFilename, false ) )
504 {
505 msg.Printf( _( "Failed to copy schematic file '%s' to destination '%s'." ),
506 currentScreenFileName.GetFullPath(),
507 newAbsoluteFilename );
508
509 DisplayError( m_frame, msg );
510
511 return false;
512 }
513 }
514 else // New file.
515 {
516 m_frame->InitSheet( m_sheet, newAbsoluteFilename );
517 }
518 }
519 else // Existing sheet.
520 {
521 isExistingSheet = true;
522
523 if( !m_frame->AllowCaseSensitiveFileNameClashes( m_sheet->GetFileName(), newAbsoluteFilename ) )
524 return false;
525
526 // We are always using here a case insensitive comparison to avoid issues
527 // under Windows, although under Unix filenames are case sensitive.
528 // But many users create schematic under both Unix and Windows
529 // **
530 // N.B. 1: aSheet->GetFileName() will return a relative path
531 // aSheet->GetScreen()->GetFileName() returns a full path
532 //
533 // N.B. 2: newFilename uses the unix notation for separator.
534 // so we must use it also to compare the old and new filenames
535 wxString oldAbsoluteFilename = m_sheet->GetScreen()->GetFileName();
536 oldAbsoluteFilename.Replace( wxT( "\\" ), wxT( "/" ) );
537
538 if( newAbsoluteFilename.Cmp( oldAbsoluteFilename ) != 0 )
539 {
540 // Sheet file name changes cannot be undone.
541 if( m_isUndoable )
542 *m_isUndoable = false;
543
544 if( useScreen || loadFromFile ) // Load from existing file.
545 {
546 clearAnnotation = true;
547 oldScreen = m_sheet->GetScreen();
548
549 if( !IsOK( this, wxString::Format( _( "Change '%s' link from '%s' to '%s'?" ),
550 newAbsoluteFilename,
551 m_sheet->GetFileName(),
552 sheetFileName.GetFullName() )
553 + wxT( "\n\n" )
554 + _( "This action cannot be undone." ) ) )
555 {
556 return false;
557 }
558
559 if( loadFromFile )
560 m_sheet->SetScreen( nullptr );
561 }
562 else // Save to new file name.
563 {
564 if( m_sheet->GetScreenCount() > 1 )
565 {
566 if( !IsOK( this, wxString::Format( _( "Create new file '%s' with contents of '%s'?" ),
567 sheetFileName.GetFullName(),
568 m_sheet->GetFileName() )
569 + wxT( "\n\n" )
570 + _( "This action cannot be undone." ) ) )
571 {
572 return false;
573 }
574 }
575
576 renameFile = true;
577 }
578 }
579
580 if( renameFile )
581 {
582 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
583
584 // If the associated screen is shared by more than one sheet, do not
585 // change the filename of the corresponding screen here.
586 // (a new screen will be created later)
587 // if it is not shared, update the filename
588 if( m_sheet->GetScreenCount() <= 1 )
589 m_sheet->GetScreen()->SetFileName( newAbsoluteFilename );
590
591 try
592 {
593 pi->SaveSchematicFile( newAbsoluteFilename, m_sheet, &schematic );
594 }
595 catch( const IO_ERROR& ioe )
596 {
597 msg = wxString::Format( _( "Error occurred saving schematic file '%s'." ), newAbsoluteFilename );
598 DisplayErrorMessage( this, msg, ioe.What() );
599
600 msg = wxString::Format( _( "Failed to save schematic '%s'" ), newAbsoluteFilename );
601 m_frame->SetMsgPanel( wxEmptyString, msg );
602 return false;
603 }
604
605 // If the associated screen is shared by more than one sheet, remove the
606 // screen and reload the file to a new screen. Failure to do this will trash
607 // the screen reference counting in complex hierarchies.
608 if( m_sheet->GetScreenCount() > 1 )
609 {
610 oldScreen = m_sheet->GetScreen();
611 m_sheet->SetScreen( nullptr );
612 loadFromFile = true;
613 }
614 }
615 }
616
617 SCH_SHEET_PATH& currentSheet = m_frame->GetCurrentSheet();
618
619 if( useScreen )
620 {
621 // Create a temporary sheet for recursion testing to prevent a possible recursion error.
622 std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique<SCH_SHEET>( &schematic );
623 *tmpSheet->GetField( FIELD_T::SHEET_NAME ) = m_fields->GetField( FIELD_T::SHEET_NAME );
624 tmpSheet->GetField( FIELD_T::SHEET_FILENAME )->SetText( sheetFileName.GetFullPath() );
625 tmpSheet->SetScreen( useScreen );
626
627 // No need to check for valid library IDs if we are using an existing screen.
628 if( m_frame->CheckSheetForRecursion( tmpSheet.get(), &currentSheet ) )
629 return false;
630
631 // It's safe to set the sheet screen now.
632 m_sheet->SetScreen( useScreen );
633
634 SCH_SHEET_LIST sheetHierarchy( m_sheet ); // The hierarchy of the loaded file.
635
636 sheetHierarchy.AddNewSymbolInstances( currentSheet, m_frame->Prj().GetProjectName() );
637 sheetHierarchy.AddNewSheetInstances( currentSheet, fullHierarchy.GetLastVirtualPageNumber() );
638 }
639 else if( loadFromFile )
640 {
641 bool restoreSheet = false;
642
643 if( isExistingSheet )
644 {
645 // Temporarily remove the sheet from the current schematic page so that recursion
646 // and symbol library link tests can be performed with the modified sheet settings.
647 restoreSheet = true;
648 currentSheet.LastScreen()->Remove( m_sheet );
649 }
650
651 if( !m_frame->LoadSheetFromFile( m_sheet, &currentSheet, newAbsoluteFilename, false, true )
652 || m_frame->CheckSheetForRecursion( m_sheet, &currentSheet ) )
653 {
654 if( restoreSheet )
655 {
656 // If we cleared the previous screen, restore it before returning to the user
657 if( oldScreen )
658 m_sheet->SetScreen( oldScreen );
659
660 currentSheet.LastScreen()->Append( m_sheet );
661 }
662
663 return false;
664 }
665
666 if( restoreSheet )
667 currentSheet.LastScreen()->Append( m_sheet );
668 }
669
671 *m_clearAnnotationNewItems = clearAnnotation;
672
673 // Rebuild the entire connection graph.
674 m_frame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
675
676 return true;
677}
678
679
681{
682 bool success = true;
683 wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
684 wxControl* control = editor->GetControl();
685
686 if( control && control->GetValidator() )
687 success = control->GetValidator()->Validate( control );
688
689 if( !success )
690 {
691 event.Veto();
692 m_delayedFocusRow = event.GetRow();
693 m_delayedFocusColumn = event.GetCol();
694 }
695
696 editor->DecRef();
697}
698
699
700void DIALOG_SHEET_PROPERTIES::OnAddField( wxCommandEvent& event )
701{
702 m_grid->OnAddRow(
703 [&]() -> std::pair<int, int>
704 {
706
707 newField.SetTextAngle( m_fields->GetField( FIELD_T::SHEET_NAME )->GetTextAngle() );
708 newField.SetVisible( false );
709 m_fields->push_back( newField );
710
711 // notify the grid
712 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
713 m_grid->ProcessTableMessage( msg );
714 return { m_fields->size() - 1, FDC_NAME };
715 } );
716}
717
718
719void DIALOG_SHEET_PROPERTIES::OnDeleteField( wxCommandEvent& event )
720{
721 m_grid->OnDeleteRows(
722 [&]( int row )
723 {
724 if( row < m_fields->GetMandatoryRowCount() )
725 {
726 DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
727 m_fields->GetMandatoryRowCount() ) );
728 return false;
729 }
730
731 return true;
732 },
733 [&]( int row )
734 {
735 m_fields->erase( m_fields->begin() + row );
736
737 // notify the grid
738 wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
739 m_grid->ProcessTableMessage( msg );
740 } );
741}
742
743
744void DIALOG_SHEET_PROPERTIES::OnMoveUp( wxCommandEvent& event )
745{
746 m_grid->OnMoveRowUp(
747 [&]( int row )
748 {
749 return row > m_fields->GetMandatoryRowCount();
750 },
751 [&]( int row )
752 {
753 std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) );
754 m_grid->ForceRefresh();
755 } );
756}
757
758
759void DIALOG_SHEET_PROPERTIES::OnMoveDown( wxCommandEvent& event )
760{
761 m_grid->OnMoveRowUp(
762 [&]( int row )
763 {
764 return row >= m_fields->GetMandatoryRowCount();
765 },
766 [&]( int row )
767 {
768 std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) );
769 m_grid->ForceRefresh();
770 } );
771}
772
773
774void DIALOG_SHEET_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
775{
776 std::bitset<64> shownColumns = m_grid->GetShownColumns();
777
778 if( shownColumns != m_shownColumns )
779 {
780 m_shownColumns = shownColumns;
781
782 if( !m_grid->IsCellEditControlShown() )
783 m_grid->SetGridWidthsDirty();
784 }
785
786 // Propagate changes in sheetname to displayed hierarchical path
787 int sheetnameRow = m_fields->GetFieldRow( FIELD_T::SHEET_NAME );
788 wxString path = m_frame->GetCurrentSheet().PathHumanReadable( false );
789
790 if( path.Last() != '/' )
791 path.Append( '/' );
792
793 wxGridCellEditor* editor = m_grid->GetCellEditor( sheetnameRow, FDC_VALUE );
794 wxControl* control = editor->GetControl();
795 wxTextEntry* textControl = dynamic_cast<wxTextEntry*>( control );
796 wxString sheetName;
797
798 if( textControl )
799 sheetName = textControl->GetValue();
800 else
801 sheetName = m_grid->GetCellValue( sheetnameRow, FDC_VALUE );
802
803 m_dummySheet.SetFields( *m_fields );
804 m_dummySheetNameField.SetText( sheetName );
805 path += m_dummySheetNameField.GetShownText( false );
806
807 editor->DecRef();
808
809 wxClientDC dc( m_hierarchicalPathLabel );
810 int width = m_sizerBottom->GetSize().x - m_stdDialogButtonSizer->GetSize().x
811 - m_hierarchicalPathLabel->GetSize().x
812 - 30;
813
814 path = wxControl::Ellipsize( path, dc, wxELLIPSIZE_START, width, wxELLIPSIZE_FLAGS_NONE );
815
816 if( m_hierarchicalPath->GetLabel() != path )
817 m_hierarchicalPath->SetLabel( path );
818
819 // Handle a delayed focus
820 if( m_delayedFocusRow >= 0 )
821 {
822 m_grid->SetFocus();
823 m_grid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
825
826 m_grid->EnableCellEditControl( true );
827 m_grid->ShowCellEditControl();
828
831 }
832}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:399
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 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 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...
const EDA_ANGLE & GetTextAngle() const
Definition eda_text.h:147
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:98
void Offset(const VECTOR2I &aOffset)
Definition eda_text.cpp:602
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:200
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:394
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:203
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:307
SCH_FIELD * GetField(FIELD_T aFieldId)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:42
@ KD_WARNING
Definition kidialog.h:47
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition kidialog.cpp:55
int ShowModal() override
Definition kidialog.cpp:93
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
Holds all the data relating to one schematic.
Definition schematic.h:88
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
SCH_SHEET & Root() const
Definition schematic.h:125
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
bool IsMandatory() const
VECTOR2I GetPosition() const override
FIELD_T GetId() const
Definition sch_field.h:116
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
bool IsEmpty()
Return true if both the name and value of the field are empty.
Definition sch_field.h:154
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
const wxString & GetFileName() const
Definition sch_screen.h:152
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void AddNewSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath, const wxString &aProjectName)
Attempt to add new symbol instances for all symbols in this list of sheet paths prefixed with aPrefix...
int GetLastVirtualPageNumber() const
void AddNewSheetInstances(const SCH_SHEET_PATH &aPrefixSheetPath, int aLastVirtualPageNumber)
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...
SCH_SCREEN * LastScreen()
wxString GetPageNumber() const
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:47
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
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:580
The common library.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:259
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:202
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:177
This file is part of the common library.
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)
@ FDC_NAME
@ FDC_VALUE
static const std::string KiCadSchematicFileExtension
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:488
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
const SCH_FIELD * FindField(const std::vector< SCH_FIELD > &aFields, FIELD_T aFieldId)
Definition sch_field.h:362
@ AUTOPLACE_NONE
Definition sch_item.h:69
@ GLOBAL_CLEANUP
Definition schematic.h:77
bool IsFullFileNameValid(const wxString &aFullFilename)
Checks if a full filename is valid, i.e.
wxString GetUserFieldName(int aFieldNdx, bool aTranslateForHI)
#define DO_TRANSLATE
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
std::string path
wxLogTrace helper definitions.
@ SCH_SHEET_T
Definition typeinfo.h:179
Custom text control validator definitions.
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition wx_filename.h:39