30#include <wx/tooltip.h>
49#include "wx/dcclient.h"
53 bool* aIsUndoable,
bool* aClearAnnotationNewItems,
54 bool* aUpdateHierarchyNavigator,
55 wxString* aSourceSheetFilename ) :
73 [&]( wxCommandEvent& aEvent )
77 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
78 m_grid->ShowHideColumns(
"0 1 2 3 4 5 6 7" );
81 if(
m_frame->GetColorSettings()->GetOverrideSchItemColors() )
82 m_infoBar->ShowMessage(
_(
"Note: individual item colors overridden in Preferences." ) );
89 wxToolTip::Enable(
true );
119 m_grid->PopEventHandler(
true );
125 if( !wxDialog::TransferDataToWindow() )
129 wxString variantName =
m_frame->Schematic().GetCurrentVariant();
140 wxString filename = field_copy.
GetText();
141 filename.Replace( wxT(
"/" ), wxT(
"\\" ) );
142 field_copy.
SetText( filename );
147 field_copy.
SetText(
m_sheet->GetFieldText( field.GetName(), &instance, variantName ) );
156 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->size() );
157 m_grid->ProcessTableMessage( msg );
190 if( !
m_grid->CommitPendingChanges() || !
m_grid->Validate() )
194 for(
size_t i = 0; i <
m_fields->size(); ++i )
250 if( !wxDialog::TransferDataFromWindow() )
261 if( sheetFileName.IsEmpty() )
263 DisplayError(
this,
_(
"A sheet must have a valid file name." ) );
274 DisplayError(
this,
_(
"A sheet must have a valid file name." ) );
278 wxFileName fn( sheetFileName );
280 wxString newRelativeFilename = fn.GetFullPath();
283 newRelativeFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
286 oldFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
288 bool filename_changed = oldFilename != newRelativeFilename;
290 if( filename_changed ||
m_sheet->IsNew() )
294 wxCHECK( currentScreen,
false );
296 bool clearFileName =
false;
301 clearFileName =
true;
302 currentScreen->
SetFileName(
m_frame->Prj().AbsolutePath( wxT(
"noname.kicad_sch" ) ) );
305 wxFileName tmp( fn );
306 wxFileName screenFileName = currentScreen->
GetFileName();
308 if( fn.IsAbsolute() && fn.MakeRelativeTo( screenFileName.GetPath() ) )
311 _(
"Sheet File Path" ),
312 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
314 makeRelDlg.SetExtendedMessage(
_(
"Using relative hierarchical sheet file name paths improves "
315 "schematic portability across systems and platforms. Using "
316 "absolute paths can result in portability issues." ) );
317 makeRelDlg.SetYesNoLabels( KICAD_MESSAGE_DIALOG::ButtonLabel(
_(
"Use Relative Path" ) ),
318 KICAD_MESSAGE_DIALOG::ButtonLabel(
_(
"Use Absolute Path" ) ) );
320 if( makeRelDlg.ShowModal() == wxID_YES )
323 "\n to relative path: '%s'",
327 newRelativeFilename = fn.GetFullPath();
358 if( newSheetname.IsEmpty() )
359 newSheetname =
_(
"Untitled Sheet" );
363 m_sheet->SetName( newSheetname );
364 m_sheet->SetFileName( newRelativeFilename );
368 m_field.Offset(
m_sheet->GetPosition() );
374 wxString variantName =
m_frame->Schematic().GetCurrentVariant();
376 for(
int ii =
m_fields->GetNumberRows() - 1; ii >= 0; ii-- )
387 else if( fieldName.IsEmpty() )
395 m_sheet->AddOptionalField( field );
399 wxString defaultText =
m_sheet->Schematic()->ConvertRefsToKIIDs( existingField->
GetText() );
400 tmp =
const_cast<SCH_FIELD*
>( existingField );
404 if( !variantName.IsEmpty() )
407 tmp->
SetText( defaultText, &instance );
410 &instance, variantName );
423 wxPanel temp(
this );
428 KIDIALOG dlg(
this,
_(
"Note: item colors are overridden in the current color theme." ),
430 dlg.ShowDetailedText( wxString::Format(
_(
"To see individual item colors uncheck '%s'\n"
431 "in Preferences > Schematic Editor > Colors." ),
468 wxFileName screenFileName( sheetFileName );
469 wxFileName tmp( sheetFileName );
472 wxCHECK( currentScreen,
false );
475 wxFileName currentScreenFileName = currentScreen->
GetFileName();
477 if( !screenFileName.Normalize(
FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS, currentScreenFileName.GetPath() ) )
479 msg = wxString::Format(
_(
"Cannot normalize new sheet schematic file path:\n"
481 "against parent sheet schematic file path:\n"
483 sheetFileName.GetPath(),
484 currentScreenFileName.GetPath() );
489 wxString newAbsoluteFilename = screenFileName.GetFullPath();
492 newAbsoluteFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
494 bool renameFile =
false;
495 bool loadFromFile =
false;
496 bool clearAnnotation =
false;
497 bool isExistingSheet =
false;
505 loadFromFile = wxFileExists( newAbsoluteFilename );
509 loadFromFile ?
"found" :
"not found" );
512 if(
m_sheet->GetScreen() ==
nullptr )
514 if( !
m_frame->AllowCaseSensitiveFileNameClashes(
m_sheet->GetFileName(), newAbsoluteFilename ) )
517 if( useScreen || loadFromFile )
519 clearAnnotation =
true;
521 if( !
IsOK(
this, wxString::Format(
_(
"'%s' already exists." ), sheetFileName.GetFullName() )
523 + wxString::Format(
_(
"Link '%s' to this file?" ), newAbsoluteFilename ) ) )
536 msg.Printf(
_(
"Failed to copy schematic file '%s' to destination '%s'." ),
537 currentScreenFileName.GetFullPath(),
538 newAbsoluteFilename );
552 isExistingSheet =
true;
554 if( !
m_frame->AllowCaseSensitiveFileNameClashes(
m_sheet->GetFileName(), newAbsoluteFilename ) )
566 wxString oldAbsoluteFilename =
m_sheet->GetScreen()->GetFileName();
567 oldAbsoluteFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
569 if( newAbsoluteFilename.Cmp( oldAbsoluteFilename ) != 0 )
575 if( useScreen || loadFromFile )
577 clearAnnotation =
true;
578 oldScreen =
m_sheet->GetScreen();
580 if( !
IsOK(
this, wxString::Format(
_(
"Change '%s' link from '%s' to '%s'?" ),
583 sheetFileName.GetFullName() )
585 +
_(
"This action cannot be undone." ) ) )
595 if(
m_sheet->GetScreenCount() > 1 )
597 if( !
IsOK(
this, wxString::Format(
_(
"Create new file '%s' with contents of '%s'?" ),
598 sheetFileName.GetFullName(),
601 +
_(
"This action cannot be undone." ) ) )
619 if(
m_sheet->GetScreenCount() <= 1 )
620 m_sheet->GetScreen()->SetFileName( newAbsoluteFilename );
624 pi->SaveSchematicFile( newAbsoluteFilename,
m_sheet, &schematic );
628 msg = wxString::Format(
_(
"Error occurred saving schematic file '%s'." ), newAbsoluteFilename );
631 msg = wxString::Format(
_(
"Failed to save schematic '%s'" ), newAbsoluteFilename );
632 m_frame->SetMsgPanel( wxEmptyString, msg );
639 if(
m_sheet->GetScreenCount() > 1 )
641 oldScreen =
m_sheet->GetScreen();
653 std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique<SCH_SHEET>( &schematic );
659 tmpSheet->SetScreen( useScreen );
662 if(
m_frame->CheckSheetForRecursion( tmpSheet.get(), ¤tSheet ) )
666 m_sheet->SetScreen( useScreen );
673 else if( loadFromFile )
675 bool restoreSheet =
false;
677 if( isExistingSheet )
685 if( !
m_frame->LoadSheetFromFile(
m_sheet, ¤tSheet, newAbsoluteFilename,
false,
true )
692 m_sheet->SetScreen( oldScreen );
717 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
718 wxControl* control =
editor->GetControl();
720 if( control && control->GetValidator() )
721 success = control->GetValidator()->Validate( control );
729 else if( event.GetCol() ==
FDC_NAME )
731 wxString newName =
event.GetString();
733 for(
int i = 0; i <
m_grid->GetNumberRows(); ++i )
735 if( i == event.GetRow() )
738 if( newName.CmpNoCase(
m_grid->GetCellValue( i,
FDC_NAME ) ) == 0 )
740 DisplayError(
this, wxString::Format(
_(
"Field name '%s' already in use." ),
757 [&]() -> std::pair<int, int>
766 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
767 m_grid->ProcessTableMessage( msg );
778 if( row < m_fields->GetMandatoryRowCount() )
780 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
781 m_fields->GetMandatoryRowCount() ) );
792 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
793 m_grid->ProcessTableMessage( msg );
803 return row >
m_fields->GetMandatoryRowCount();
807 std::swap( *(
m_fields->begin() + row ), *(
m_fields->begin() + row - 1 ) );
818 return row >=
m_fields->GetMandatoryRowCount();
822 std::swap( *(
m_fields->begin() + row ), *(
m_fields->begin() + row + 1 ) );
830 std::bitset<64> shownColumns =
m_grid->GetShownColumns();
836 if( !
m_grid->IsCellEditControlShown() )
837 m_grid->SetGridWidthsDirty();
842 wxString
path =
m_frame->GetCurrentSheet().PathHumanReadable(
false );
844 if(
path.Last() !=
'/' )
848 wxControl* control =
editor->GetControl();
849 wxTextEntry* textControl =
dynamic_cast<wxTextEntry*
>( control );
853 sheetName = textControl->GetValue();
868 path = wxControl::Ellipsize(
path, dc, wxELLIPSIZE_START, width, wxELLIPSIZE_FLAGS_NONE );
880 m_grid->EnableCellEditControl(
true );
881 m_grid->ShowCellEditControl();
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Color settings are a bit different than most of the settings objects in that there can be more than o...
bool GetOverrideSchItemColors() const
wxCheckBox * m_cbExcludeFromSim
wxStaticText * m_borderWidthLabel
STD_BITMAP_BUTTON * m_bpMoveUp
wxTextCtrl * m_pageNumberTextCtrl
wxTextCtrl * m_borderWidthCtrl
wxCheckBox * m_cbExcludeFromBom
wxStaticText * m_borderWidthUnits
COLOR_SWATCH * m_backgroundSwatch
wxStaticText * m_hierarchicalPath
wxCheckBox * m_cbExcludeFromBoard
STD_BITMAP_BUTTON * m_bpAdd
wxStdDialogButtonSizer * m_stdDialogButtonSizer
wxBoxSizer * m_sizerBottom
STD_BITMAP_BUTTON * m_bpDelete
COLOR_SWATCH * m_borderSwatch
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)
wxStaticText * m_hierarchicalPathLabel
STD_BITMAP_BUTTON * m_bpMoveDown
bool TransferDataToWindow() override
void OnAddField(wxCommandEvent &event) override
void OnMoveDown(wxCommandEvent &event) override
UNIT_BINDER m_borderWidth
std::bitset< 64 > m_shownColumns
SCH_FIELD m_dummySheetNameField
bool TransferDataFromWindow() override
void OnGridCellChanging(wxGridEvent &event)
void OnDeleteField(wxCommandEvent &event) override
bool onSheetFilenameChanged(const wxString &aNewFilename)
wxString * m_sourceSheetFilename
bool * m_updateHierarchyNavigator
void OnUpdateUI(wxUpdateUIEvent &event) override
bool * m_clearAnnotationNewItems
FIELDS_GRID_TABLE * m_fields
void OnMoveUp(wxCommandEvent &event) override
DIALOG_SHEET_PROPERTIES(SCH_EDIT_FRAME *aParent, SCH_SHEET *aSheet, bool *aIsUndoable, bool *aClearAnnotationNewItems, bool *aUpdateHierarchyNavigator, wxString *aSourceSheetFilename)
~DIALOG_SHEET_PROPERTIES() override
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
void Offset(const VECTOR2I &aOffset)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
virtual void SetVisible(bool aVisible)
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
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.
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
A color representation with 4 components: red, green, blue, alpha.
wxCheckBox * m_optOverrideColors
Holds all the data relating to one schematic.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
VECTOR2I GetPosition() const override
virtual const wxString & GetText() const override
Return the string associated with the text object.
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.
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,...
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
const wxString & GetFileName() const
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.
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.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
#define KICAD_MESSAGE_DIALOG
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.
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.
@ LAYER_SCHEMATIC_BACKGROUND
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
const SCH_FIELD * FindField(const std::vector< SCH_FIELD > &aFields, FIELD_T aFieldId)
bool IsFullFileNameValid(const wxString &aFullFilename)
Checks if a full filename is valid, i.e.
wxString GetUserFieldName(int aFieldNdx, bool aTranslateForHI)
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
wxLogTrace helper definitions.
Custom text control validator definitions.
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().