KiCad PCB EDA Suite
dialog_sch_sheet_props.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 <stambaughw@gmail.com>
5  * Copyright (C) 2014-2020 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 
25 #include <dialog_sch_sheet_props.h>
26 #include <kiface_i.h>
27 #include <wx/string.h>
28 #include <wx/tooltip.h>
29 #include <confirm.h>
30 #include <validators.h>
32 #include <widgets/tab_traversal.h>
33 #include <sch_edit_frame.h>
34 #include <sch_sheet.h>
35 #include <schematic.h>
36 #include <bitmaps.h>
37 #include <eeschema_settings.h>
39 #include <trace_helpers.h>
41 
43  bool* aClearAnnotationNewItems ) :
44  DIALOG_SCH_SHEET_PROPS_BASE( aParent ),
45  m_frame( aParent ),
46  m_clearAnnotationNewItems( aClearAnnotationNewItems ),
47  m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits, true )
48 {
49  m_sheet = aSheet;
50  m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_sheet );
51  m_width = 100; // Will be later set to a better value
54 
55  // Give a bit more room for combobox editors
56  m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
57 
59  m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this ) );
60 
61  // Show/hide columns according to user's preference
62  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
63  wxASSERT( cfg );
64 
65  if( cfg )
66  {
67  m_shownColumns = cfg->m_Appearance.edit_sheet_visible_columns;
69  }
70 
71  wxToolTip::Enable( true );
72  m_stdDialogButtonSizerOK->SetDefault();
73 
74  // Configure button logos
75  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
76  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
77  m_bpMoveUp->SetBitmap( KiBitmap( small_up_xpm ) );
78  m_bpMoveDown->SetBitmap( KiBitmap( small_down_xpm ) );
79 
80  // Set font sizes
81  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
82  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
83  m_hiearchicalPathLabel->SetFont( infoFont );
84  m_heirarchyPath->SetFont( infoFont );
85  m_heirarchyPath->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_MENU ) );
86 
87  // wxFormBuilder doesn't include this event...
88  m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
89  wxGridEventHandler( DIALOG_SCH_SHEET_PROPS::OnGridCellChanging ),
90  NULL, this );
91 
93 }
94 
95 
97 {
98  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
99  wxASSERT( cfg );
100 
101  if( cfg )
102  cfg->m_Appearance.edit_sheet_visible_columns = m_grid->GetShownColumns();
103 
104  // Prevents crash bug in wxGrid's d'tor
106 
107  m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
108  wxGridEventHandler( DIALOG_SCH_SHEET_PROPS::OnGridCellChanging ),
109  NULL, this );
110 
111  // Delete the GRID_TRICKS.
112  m_grid->PopEventHandler( true );
113 }
114 
115 
117 {
118  if( !wxDialog::TransferDataToWindow() )
119  return false;
120 
121  // Push a copy of each field into m_updateFields
122  for( SCH_FIELD& field : m_sheet->GetFields() )
123  {
124  SCH_FIELD field_copy( field );
125 
126 #ifdef __WINDOWS__
127  // Filenames are stored using unix notation
128  if( field_copy.GetId() == SHEETFILENAME )
129  {
130  wxString filename = field_copy.GetText();
131  filename.Replace( wxT("/"), wxT("\\") );
132  field_copy.SetText( filename );
133  }
134 #endif
135 
136  // change offset to be symbol-relative
137  field_copy.Offset( -m_sheet->GetPosition() );
138 
139  m_fields->push_back( field_copy );
140  }
141 
142  // notify the grid
143  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->size() );
144  m_grid->ProcessTableMessage( msg );
145  AdjustGridColumns( m_grid->GetRect().GetWidth() );
146 
147  // border width
149 
150  // set up color swatches
151  KIGFX::COLOR4D borderColor = m_sheet->GetBorderColor();
152  KIGFX::COLOR4D backgroundColor = m_sheet->GetBackgroundColor();
153 
154  m_borderSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
155  m_backgroundSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
156 
157  m_borderSwatch->SetSwatchColor( borderColor, false );
158  m_backgroundSwatch->SetSwatchColor( backgroundColor, false );
159 
163 
164  // set up the read-only fields
166 
167  Layout();
168 
169  return true;
170 }
171 
172 
174 {
175  wxString msg;
176  LIB_ID id;
177 
178  if( !m_grid->CommitPendingChanges() || !m_grid->Validate() )
179  return false;
180 
181  // Check for missing field names.
182  for( size_t i = SHEET_MANDATORY_FIELDS; i < m_fields->size(); ++i )
183  {
184  SCH_FIELD& field = m_fields->at( i );
185  wxString fieldName = field.GetName( false );
186 
187  if( fieldName.IsEmpty() )
188  {
189  DisplayErrorMessage( this, _( "Fields must have a name." ) );
190 
192  m_delayedFocusRow = i;
193 
194  return false;
195  }
196  }
197 
198  return true;
199 }
200 
201 
202 static bool positioningChanged( const SCH_FIELD& a, const SCH_FIELD& b )
203 {
204  if( a.GetPosition() != b.GetPosition() )
205  return true;
206 
207  if( a.GetHorizJustify() != b.GetHorizJustify() )
208  return true;
209 
210  if( a.GetVertJustify() != b.GetVertJustify() )
211  return true;
212 
213  if( a.GetTextAngle() != b.GetTextAngle() )
214  return true;
215 
216  return false;
217 }
218 
219 
220 static bool positioningChanged( FIELDS_GRID_TABLE<SCH_FIELD>* a, std::vector<SCH_FIELD>& b )
221 {
222  for( size_t i = 0; i < SHEET_MANDATORY_FIELDS; ++i )
223  {
224  if( positioningChanged( a->at( i ), b.at( i ) ) )
225  return true;
226  }
227 
228  return false;
229 }
230 
231 
233 {
234  if( !wxDialog::TransferDataFromWindow() ) // Calls our Validate() method.
235  return false;
236 
237  wxString newRelativeNativeFilename = m_fields->at( SHEETFILENAME ).GetText();
238 
239  // Ensure filepath is not empty. (In normal use will be caught by grid validators,
240  // but unedited data from existing files can be bad.)
241 
242  // @todo What happens when there are invalid file name characters?
243  if( newRelativeNativeFilename.IsEmpty() )
244  {
245  wxMessageBox( _( "A sheet must have a valid file name." ) );
246  return false;
247  }
248 
249  // Ensure the filename extension is OK. (In normaly use will be caught by grid
250  // validators, but unedited data from existing files can be bad.)
251  wxFileName fn( newRelativeNativeFilename );
252 
253  if( fn.GetExt().CmpNoCase( KiCadSchematicFileExtension ) != 0 )
254  {
255  wxMessageBox( _( "Sheet file must have a '.kicad_sch' extension." ) );
256  return false;
257  }
258 
259  wxString newRelativeFilename = fn.GetFullPath();
260 
261  // Inside Eeschema, filenames are stored using unix notation
262  newRelativeFilename.Replace( wxT( "\\" ), wxT( "/" ) );
263 
264  wxString oldFilename = m_sheet->GetFields()[ SHEETFILENAME ].GetText();
265  oldFilename.Replace( wxT( "\\" ), wxT( "/" ) );
266 
267  bool filename_changed = oldFilename != newRelativeFilename;
268 
269  if( filename_changed || m_sheet->IsNew() )
270  {
271  if( !onSheetFilenameChanged( newRelativeFilename ) )
272  return false;
273  }
274 
275  wxString newSheetname = m_fields->at( SHEETNAME ).GetText();
276 
277  if( newSheetname.IsEmpty() )
278  newSheetname = _( "Untitled Sheet" );
279 
280  m_fields->at( SHEETNAME ).SetText( newSheetname );
281 
282  // change all field positions from relative to absolute
283  for( unsigned i = 0; i < m_fields->size(); ++i )
284  m_fields->at( i ).Offset( m_sheet->GetPosition() );
285 
288 
290 
292 
293  COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
294 
295  if( colorSettings->GetOverrideSchItemColors()
298  {
299  wxPanel temp( this );
300  temp.Hide();
301  PANEL_EESCHEMA_COLOR_SETTINGS prefs( m_frame, &temp );
302  wxString checkboxLabel = prefs.m_optOverrideColors->GetLabel();
303 
304  KIDIALOG dlg( this, _( "Note: item colors are overridden in the current color theme." ),
306  dlg.ShowDetailedText( wxString::Format( _( "To see individual item colors uncheck '%s'\n"
307  "in Preferences > Eeschema > Colors." ),
308  checkboxLabel ) );
309  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
310  dlg.ShowModal();
311  }
312 
315 
317 
318  // Refresh all sheets in case ordering changed.
319  for( SCH_ITEM* item : m_frame->GetScreen()->Items().OfType( SCH_SHEET_T ) )
320  m_frame->UpdateItem( item );
321 
322  m_frame->OnModify();
323 
324  return true;
325 }
326 
327 
328 bool DIALOG_SCH_SHEET_PROPS::onSheetFilenameChanged( const wxString& aNewFilename )
329 {
330  wxString msg;
331 
332  // Relative file names are relative to the path of the current sheet. This allows for
333  // nesting of schematic files in subfolders.
334  wxFileName fileName( aNewFilename );
335 
336  if( fileName.GetExt().IsEmpty() )
337  {
338  fileName.SetExt( KiCadSchematicFileExtension );
339  }
340  else if( fileName.GetExt().CmpNoCase( KiCadSchematicFileExtension ) != 0 )
341  {
342  msg.Printf( _( "The file \"%s\" does not appear to be a valid schematic file." ),
343  fileName.GetFullName() );
344  wxMessageDialog badSchFileDialog( this, msg, _( "Invalid Schematic File" ),
345  wxOK | wxCENTRE | wxICON_EXCLAMATION );
346  badSchFileDialog.ShowModal();
347  return false;
348  }
349 
350  if( !fileName.IsAbsolute() )
351  {
352  const SCH_SCREEN* currentScreen = m_frame->GetCurrentSheet().LastScreen();
353  wxCHECK_MSG( currentScreen, false, "Invalid sheet path object." );
354 
355  wxFileName currentSheetFileName = currentScreen->GetFileName();
356 
357  if( !fileName.Normalize( wxPATH_NORM_ALL, currentSheetFileName.GetPath() ) )
358  {
359  wxFAIL_MSG( "Cannot normalize new sheet schematic file path." );
360  return false;
361  }
362  }
363 
364  wxString newAbsoluteFilename = fileName.GetFullPath();
365 
366  // Inside Eeschema, filenames are stored using unix notation
367  newAbsoluteFilename.Replace( wxT( "\\" ), wxT( "/" ) );
368 
369  bool renameFile = false;
370  bool loadFromFile = false;
371  bool clearAnnotation = false;
372  bool restoreSheet = false;
373  bool isExistingSheet = false;
374  SCH_SCREEN* useScreen = NULL;
375 
376  // Search for a schematic file having the same filename already in use in the hierarchy
377  // or on disk, in order to reuse it.
378  if( !m_frame->Schematic().Root().SearchHierarchy( newAbsoluteFilename, &useScreen ) )
379  {
380  loadFromFile = wxFileExists( newAbsoluteFilename );
381 
382  wxLogTrace( tracePathsAndFiles, "Sheet requested file \"%s\", %s",
383  newAbsoluteFilename,
384  ( loadFromFile ) ? "found" : "not found" );
385  }
386 
387  if( m_sheet->GetScreen() == NULL ) // New just created sheet.
388  {
389  if( !m_frame->AllowCaseSensitiveFileNameClashes( newAbsoluteFilename ) )
390  return false;
391 
392  if( useScreen || loadFromFile ) // Load from existing file.
393  {
394  clearAnnotation = true;
395  wxString existsMsg;
396  wxString linkMsg;
397  existsMsg.Printf( _( "\"%s\" already exists." ), fileName.GetFullName() );
398  linkMsg.Printf( _( "Link \"%s\" to this file?" ), newAbsoluteFilename );
399  msg.Printf( wxT( "%s\n\n%s" ), existsMsg, linkMsg );
400 
401  if( !IsOK( this, msg ) )
402  return false;
403  }
404  else // New file.
405  {
406  m_frame->InitSheet( m_sheet, newAbsoluteFilename );
407  }
408  }
409  else // Existing sheet.
410  {
411  bool isUndoable = true;
412  wxString replaceMsg;
413  wxString newMsg;
414  wxString noUndoMsg;
415  isExistingSheet = true;
416 
417  if( !m_frame->AllowCaseSensitiveFileNameClashes( newAbsoluteFilename ) )
418  return false;
419 
420  // Changing the filename of a sheet can modify the full hierarchy structure
421  // and can be not always undoable.
422  // So prepare messages for user notifications:
423  replaceMsg.Printf( _( "Change \"%s\" link from \"%s\" to \"%s\"?" ),
424  newAbsoluteFilename,
425  m_sheet->GetFileName(),
426  fileName.GetFullName() );
427  newMsg.Printf( _( "Create new file \"%s\" with contents of \"%s\"?" ),
428  fileName.GetFullName(),
429  m_sheet->GetFileName() );
430  noUndoMsg = _( "This action cannot be undone." );
431 
432  // We are always using here a case insensitive comparison to avoid issues
433  // under Windows, although under Unix filenames are case sensitive.
434  // But many users create schematic under both Unix and Windows
435  // **
436  // N.B. 1: aSheet->GetFileName() will return a relative path
437  // aSheet->GetScreen()->GetFileName() returns a full path
438  //
439  // N.B. 2: newFilename uses the unix notation for separator.
440  // so we must use it also to compare the old and new filenames
441  wxString oldAbsoluteFilename = m_sheet->GetScreen()->GetFileName();
442  oldAbsoluteFilename.Replace( wxT( "\\" ), wxT( "/" ) );
443 
444  if( newAbsoluteFilename.Cmp( oldAbsoluteFilename ) != 0 )
445  {
446  // Sheet file name changes cannot be undone.
447  isUndoable = false;
448 
449  if( useScreen || loadFromFile ) // Load from existing file.
450  {
451  clearAnnotation = true;
452 
453  msg.Printf( wxT( "%s\n\n%s" ), replaceMsg, noUndoMsg );
454 
455  if( !IsOK( this, msg ) )
456  return false;
457 
458  if( loadFromFile )
459  m_sheet->SetScreen( NULL );
460  }
461  else // Save to new file name.
462  {
463  if( m_sheet->GetScreenCount() > 1 )
464  {
465  msg.Printf( wxT( "%s\n\n%s" ), newMsg, noUndoMsg );
466 
467  if( !IsOK( this, msg ) )
468  return false;
469  }
470 
471  renameFile = true;
472  }
473  }
474 
475  if( isUndoable )
477 
478  if( renameFile )
479  {
480  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
481 
482  // If the the associated screen is shared by more than one sheet, do not
483  // change the filename of the corresponding screen here.
484  // (a new screen will be created later)
485  // if it is not shared, update the filename
486  if( m_sheet->GetScreenCount() <= 1 )
487  m_sheet->GetScreen()->SetFileName( newAbsoluteFilename );
488 
489  try
490  {
491  pi->Save( newAbsoluteFilename, m_sheet, &m_frame->Schematic() );
492  }
493  catch( const IO_ERROR& ioe )
494  {
495  msg.Printf( _( "Error occurred saving schematic file \"%s\"." ),
496  newAbsoluteFilename );
497  DisplayErrorMessage( this, msg, ioe.What() );
498 
499  msg.Printf( _( "Failed to save schematic \"%s\"" ), newAbsoluteFilename );
500  m_frame->AppendMsgPanel( wxEmptyString, msg, CYAN );
501 
502  return false;
503  }
504 
505  // If the the associated screen is shared by more than one sheet, remove the
506  // screen and reload the file to a new screen. Failure to do this will trash
507  // the screen reference counting in complex hierarchies.
508  if( m_sheet->GetScreenCount() > 1 )
509  {
510  m_sheet->SetScreen( NULL );
511  loadFromFile = true;
512  }
513  }
514  }
515 
516  wxFileName nativeFileName( aNewFilename );
517  SCH_SHEET_PATH& currentSheet = m_frame->GetCurrentSheet();
518 
519  if( useScreen )
520  {
521  // Create a temporary sheet for recursion testing to prevent a possible recursion error.
522  std::unique_ptr< SCH_SHEET> tmpSheet( new SCH_SHEET );
523  tmpSheet->GetFields()[SHEETNAME] = m_fields->at( SHEETNAME );
524  tmpSheet->GetFields()[SHEETFILENAME].SetText( nativeFileName.GetFullPath() );
525  tmpSheet->SetScreen( useScreen );
526 
527  // No need to check for valid library IDs if we are using an existing screen.
528  if( m_frame->CheckSheetForRecursion( tmpSheet.get(), &currentSheet ) )
529  {
530  if( restoreSheet )
531  currentSheet.LastScreen()->Append( m_sheet );
532 
533  return false;
534  }
535 
536  // It's safe to set the sheet screen now.
537  m_sheet->SetScreen( useScreen );
538  }
539  else if( loadFromFile )
540  {
541  if( isExistingSheet )
542  {
543  // Temporarily remove the sheet from the current schematic page so that recursion
544  // and symbol library link tests can be performed with the modified sheet settings.
545  restoreSheet = true;
546  currentSheet.LastScreen()->Remove( m_sheet );
547  }
548 
549  if( !m_frame->LoadSheetFromFile( m_sheet, &currentSheet, newAbsoluteFilename )
550  || m_frame->CheckSheetForRecursion( m_sheet, &currentSheet ) )
551  {
552  if( restoreSheet )
553  currentSheet.LastScreen()->Append( m_sheet );
554 
555  return false;
556  }
557 
558  if( restoreSheet )
559  currentSheet.LastScreen()->Append( m_sheet );
560  }
561 
563  *m_clearAnnotationNewItems = clearAnnotation;
564 
565  return true;
566 }
567 
568 
570 {
571  bool success = true;
572  wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
573  wxControl* control = editor->GetControl();
574  wxTextEntry* textControl = dynamic_cast<wxTextEntry*>( control );
575 
576  // Short-circuit the validator's more generic "can't be empty" message for the
577  // two mandatory fields:
578  if( event.GetRow() == SHEETNAME && event.GetCol() == FDC_VALUE )
579  {
580  if( textControl && textControl->IsEmpty() )
581  {
582  wxMessageBox( _( "A sheet must have a name." ) );
583  success = false;
584  }
585  }
586  else if( event.GetRow() == SHEETFILENAME && event.GetCol() == FDC_VALUE && textControl )
587  {
588  if( textControl->IsEmpty() )
589  {
590  wxMessageBox( _( "A sheet must have a file specified." ) );
591  success = false;
592  }
593  else
594  {
595  wxFileName fn = textControl->GetValue();
596 
597  if( fn.GetExt().CmpNoCase( KiCadSchematicFileExtension ) != 0 )
598  {
599  wxMessageBox( _( "Sheet filename must have a '.kicad_sch' extension." ) );
600  success = false;
601  }
602  }
603  }
604 
605  if( success && control && control->GetValidator() )
606  success = control->GetValidator()->Validate( control );
607 
608  if( !success )
609  {
610  event.Veto();
611  m_delayedFocusRow = event.GetRow();
612  m_delayedFocusColumn = event.GetCol();
613  }
614 
615  editor->DecRef();
616 }
617 
618 
619 void DIALOG_SCH_SHEET_PROPS::OnAddField( wxCommandEvent& event )
620 {
621  if( !m_grid->CommitPendingChanges() )
622  return;
623 
624  int fieldID = m_fields->size();
625  SCH_FIELD newField( wxPoint( 0, 0 ), fieldID, m_sheet,
626  SCH_SHEET::GetDefaultFieldName( fieldID ) );
627 
628  newField.SetTextAngle( m_fields->at( SHEETNAME ).GetTextAngle() );
629 
630  m_fields->push_back( newField );
631 
632  // notify the grid
633  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
634  m_grid->ProcessTableMessage( msg );
635 
636  m_grid->MakeCellVisible( m_fields->size() - 1, 0 );
637  m_grid->SetGridCursor( m_fields->size() - 1, 0 );
638 
639  m_grid->EnableCellEditControl();
640  m_grid->ShowCellEditControl();
641 }
642 
643 
644 void DIALOG_SCH_SHEET_PROPS::OnDeleteField( wxCommandEvent& event )
645 {
646  int curRow = m_grid->GetGridCursorRow();
647 
648  if( curRow < 0 )
649  return;
650  else if( curRow < SHEET_MANDATORY_FIELDS )
651  {
652  DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
654  return;
655  }
656 
657  m_grid->CommitPendingChanges( true /* quiet mode */ );
658 
659  m_fields->erase( m_fields->begin() + curRow );
660 
661  // notify the grid
662  wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
663  m_grid->ProcessTableMessage( msg );
664 
665  if( m_grid->GetNumberRows() > 0 )
666  {
667  m_grid->MakeCellVisible( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
668  m_grid->SetGridCursor( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
669  }
670 }
671 
672 
673 void DIALOG_SCH_SHEET_PROPS::OnMoveUp( wxCommandEvent& event )
674 {
675  if( !m_grid->CommitPendingChanges() )
676  return;
677 
678  int i = m_grid->GetGridCursorRow();
679 
680  if( i > SHEET_MANDATORY_FIELDS )
681  {
682  SCH_FIELD tmp = m_fields->at( (unsigned) i );
683  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
684  m_fields->insert( m_fields->begin() + i - 1, tmp );
685  m_grid->ForceRefresh();
686 
687  m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
688  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
689  }
690  else
691  wxBell();
692 }
693 
694 
695 void DIALOG_SCH_SHEET_PROPS::OnMoveDown( wxCommandEvent& event )
696 {
697  if( !m_grid->CommitPendingChanges() )
698  return;
699 
700  int i = m_grid->GetGridCursorRow();
701 
702  if( i >= SHEET_MANDATORY_FIELDS && i < m_grid->GetNumberRows() - 1 )
703  {
704  SCH_FIELD tmp = m_fields->at( (unsigned) i );
705  m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
706  m_fields->insert( m_fields->begin() + i + 1, tmp );
707  m_grid->ForceRefresh();
708 
709  m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
710  m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
711  }
712  else
713  wxBell();
714 }
715 
716 
718 {
719  m_width = aWidth;
720  // Account for scroll bars
721  aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
722 
723  m_grid->AutoSizeColumn( 0 );
724 
725  int fixedColsWidth = m_grid->GetColSize( 0 );
726 
727  for( int i = 2; i < m_grid->GetNumberCols(); i++ )
728  fixedColsWidth += m_grid->GetColSize( i );
729 
730  m_grid->SetColSize( 1, aWidth - fixedColsWidth );
731 }
732 
733 
734 void DIALOG_SCH_SHEET_PROPS::OnUpdateUI( wxUpdateUIEvent& event )
735 {
736  wxString shownColumns = m_grid->GetShownColumns();
737 
738  if( shownColumns != m_shownColumns )
739  {
740  m_shownColumns = shownColumns;
741 
742  if( !m_grid->IsCellEditControlShown() )
743  AdjustGridColumns( m_grid->GetRect().GetWidth() );
744  }
745 
746  // Handle a delayed focus
747  if( m_delayedFocusRow >= 0 )
748  {
749  m_grid->SetFocus();
750  m_grid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
751  m_grid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
752 
753 
754  m_grid->EnableCellEditControl( true );
755  m_grid->ShowCellEditControl();
756 
757  m_delayedFocusRow = -1;
759  }
760 }
761 
762 
763 void DIALOG_SCH_SHEET_PROPS::OnSizeGrid( wxSizeEvent& event )
764 {
765  auto new_size = event.GetSize().GetX();
766 
767  if( m_width != new_size )
768  {
769  AdjustGridColumns( new_size );
770  }
771 
772  // Always propagate for a grid repaint (needed if the height changes, as well as width)
773  event.Skip();
774 }
775 
776 
777 void DIALOG_SCH_SHEET_PROPS::OnInitDlg( wxInitDialogEvent& event )
778 {
780 
781  // Now all widgets have the size fixed, call FinishDialogSettings
783 }
bool CheckSheetForRecursion(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy)
Verify that aSheet will not cause a recursion error in aHierarchy.
Definition: sheet.cpp:46
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:46
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:253
Functions for manipulating tab traversal in forms and dialogs.
const wxString & GetFileName() const
Definition: sch_screen.h:185
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox
Definition: confirm.cpp:53
bool Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:243
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:631
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
KIGFX::COLOR4D GetSwatchColor() const
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:200
void SetSwatchColor(KIGFX::COLOR4D aColor, bool sendEvent)
Set the current swatch color directly.
void OnMoveUp(wxCommandEvent &event) override
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:44
void SetFields(const std::vector< SCH_FIELD > &aFields)
Set multiple schematic fields.
Definition: sch_sheet.h:275
void OnDeleteField(wxCommandEvent &event) override
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:70
This file is part of the common library.
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:127
void SetDefaultColor(KIGFX::COLOR4D aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
wxPoint GetPosition() const override
Definition: sch_field.cpp:603
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:150
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
double GetTextAngle() const
Definition: eda_text.h:174
int GetId() const
Definition: sch_field.h:114
void InitSheet(SCH_SHEET *aSheet, const wxString &aNewFilename)
Definition: sheet.cpp:95
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:290
Schematic editor (Eeschema) main window.
void SetSwatchBackground(KIGFX::COLOR4D aBackground)
Set the swatch background color.
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
COLOR_SETTINGS * GetColorSettings() override
Returns a pointer to the active color theme settings.
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:65
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
void OnAddField(wxCommandEvent &event) override
bool IsNew() const
Definition: base_struct.h:199
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:293
void SetBorderWidth(int aWidth)
Definition: sch_sheet.h:288
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition: wx_grid.cpp:96
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:268
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
int GetScreenCount() const
Return the number of times the associated screen for the sheet is being used.
Definition: sch_sheet.cpp:173
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
int GetBorderWidth() const
Definition: sch_sheet.h:287
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, const wxString &aFileName)
Load a the KiCad schematic file aFileName into the sheet aSheet.
Definition: sheet.cpp:103
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:294
bool AllowCaseSensitiveFileNameClashes(const wxString &aSchematicFileName)
Check aSchematicFileName for a potential file name case sensitivity clashes.
Definition: sheet.cpp:605
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:199
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
#define NULL
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
void OnGridCellChanging(wxGridEvent &event)
const BITMAP_OPAQUE small_down_xpm[1]
Definition: small_down.cpp:25
SCHEMATIC & Schematic() const
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:291
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
Definition of file extensions used in Kicad.
void ClearFieldsAutoplaced()
Set fields automatically placed flag false.
Definition: sch_item.h:447
Definition: color4d.h:58
wxLogTrace helper definitions.
void OnInitDlg(wxInitDialogEvent &event) override
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:44
SCH_SHEET_PATH.
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:180
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:496
static bool positioningChanged(const SCH_FIELD &a, const SCH_FIELD &b)
wxPoint GetPosition() const override
Definition: sch_sheet.h:567
const BITMAP_OPAQUE small_up_xpm[1]
Definition: small_up.cpp:26
void OnUpdateUI(wxUpdateUIEvent &event) override
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:469
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:109
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
Class DIALOG_SCH_SHEET_PROPS_BASE.
COLOR4D GetColor(int aLayer) const
SCH_SHEET & Root() const
Definition: schematic.h:94
SCH_SCREEN * LastScreen()
Function LastScreen.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:131
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:442
EE_RTREE & Items()
Definition: sch_screen.h:158
const std::string KiCadSchematicFileExtension
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
void OnSizeGrid(wxSizeEvent &event) override
int ShowModal() override
Definition: confirm.cpp:95
Color settings are a bit different than most of the settings objects in that there can be more than o...
SCH_SHEET_PATH & GetCurrentSheet() const
bool GetOverrideSchItemColors() const
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:167
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:183
wxString PathHumanReadable() const
Function PathHumanReadable returns the sheet path in a human readable form, i.e.
bool onSheetFilenameChanged(const wxString &aNewFilename)
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:283
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:20
Custom text control validator definitions.
FIELDS_GRID_TABLE< SCH_FIELD > * m_fields
DIALOG_SCH_SHEET_PROPS(SCH_EDIT_FRAME *aParent, SCH_SHEET *aSheet, bool *aClearAnnotationNewItems)
void OnMoveDown(wxCommandEvent &event) override
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99