29#include <wx/tooltip.h>
45#include "wx/dcclient.h"
48 bool* aClearAnnotationNewItems ) :
51 m_clearAnnotationNewItems( aClearAnnotationNewItems ),
52 m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits ),
53 m_dummySheet( *aSheet ),
62 m_grid->SetDefaultRowSize(
m_grid->GetDefaultRowSize() + 4 );
66 [&]( wxCommandEvent& aEvent )
70 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
87 wxToolTip::Enable(
true );
101 m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
112 cfg->m_Appearance.edit_sheet_width = GetSize().x;
113 cfg->m_Appearance.edit_sheet_height = GetSize().y;
119 m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
124 m_grid->PopEventHandler(
true );
130 if( !wxDialog::TransferDataToWindow() )
142 wxString filename = field_copy.
GetText();
143 filename.Replace( wxT(
"/" ), wxT(
"\\" ) );
144 field_copy.
SetText( filename );
155 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->size() );
156 m_grid->ProcessTableMessage( msg );
187 pageNumber.Printf( wxT(
"%d" ),
static_cast<int>( hierarchy.size() ) + 1 );
212 wxString fieldName = field.
GetName(
false );
214 if( fieldName.IsEmpty() )
261 if( !wxDialog::TransferDataFromWindow() )
269 if( sheetFileName.IsEmpty() )
271 DisplayError(
this,
_(
"A sheet must have a valid file name." ) );
279 wxFileName fn( sheetFileName );
280 wxString newRelativeFilename = fn.GetFullPath();
283 newRelativeFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
286 oldFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
288 bool filename_changed = oldFilename != newRelativeFilename;
294 wxCHECK( currentScreen,
false );
296 bool clearFileName =
false;
301 clearFileName =
true;
305 wxFileName tmp( fn );
306 wxFileName screenFileName = currentScreen->
GetFileName();
308 if( fn.IsAbsolute() && fn.MakeRelativeTo( screenFileName.GetPath() ) )
310 wxMessageDialog makeRelDlg(
this,
_(
"Use relative path for sheet file?" ),
311 _(
"Sheet File Path" ),
312 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
314 makeRelDlg.SetExtendedMessage(
_(
"Using relative hierarchical sheet file name paths "
315 "improves schematic portability across systems and "
316 "platforms. Using absolute paths can result in "
317 "portability issues." ) );
318 makeRelDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Use Relative Path" ) ),
319 wxMessageDialog::ButtonLabel(
_(
"Use Absolute Path" ) ) );
321 if( makeRelDlg.ShowModal() == wxID_YES )
324 "\n to relative path: '%s'",
328 newRelativeFilename = fn.GetFullPath();
349 if( newSheetname.IsEmpty() )
350 newSheetname =
_(
"Untitled Sheet" );
355 for(
unsigned i = 0; i <
m_fields->size(); ++i )
366 if( fieldName.IsEmpty() && field.
GetText().IsEmpty() )
368 else if( fieldName.IsEmpty() )
382 wxPanel temp(
this );
387 KIDIALOG dlg(
this,
_(
"Note: item colors are overridden in the current color theme." ),
389 dlg.ShowDetailedText( wxString::Format(
_(
"To see individual item colors uncheck '%s'\n"
390 "in Preferences > Schematic Editor > Colors." ),
426 wxFileName screenFileName( sheetFileName );
427 wxFileName tmp( sheetFileName );
431 wxCHECK( currentScreen,
false );
434 wxFileName currentScreenFileName = currentScreen->
GetFileName();
437 currentScreenFileName.GetPath() ) )
439 msg = wxString::Format(
_(
"Cannot normalize new sheet schematic file path:\n"
441 "against parent sheet schematic file path:\n"
443 sheetFileName.GetPath(),
444 currentScreenFileName.GetPath() );
449 wxString newAbsoluteFilename = screenFileName.GetFullPath();
452 newAbsoluteFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
454 bool renameFile =
false;
455 bool loadFromFile =
false;
456 bool clearAnnotation =
false;
457 bool isExistingSheet =
false;
465 loadFromFile = wxFileExists( newAbsoluteFilename );
469 loadFromFile ?
"found" :
"not found" );
477 if( useScreen || loadFromFile )
479 clearAnnotation =
true;
481 if( !
IsOK(
this, wxString::Format(
_(
"'%s' already exists." ),
482 sheetFileName.GetFullName() )
484 + wxString::Format(
_(
"Link '%s' to this file?" ),
485 newAbsoluteFilename ) ) )
497 bool isUndoable =
true;
498 isExistingSheet =
true;
513 oldAbsoluteFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
515 if( newAbsoluteFilename.Cmp( oldAbsoluteFilename ) != 0 )
520 if( useScreen || loadFromFile )
522 clearAnnotation =
true;
524 if( !
IsOK(
this, wxString::Format(
_(
"Change '%s' link from '%s' to '%s'?" ),
527 sheetFileName.GetFullName() )
529 +
_(
"This action cannot be undone." ) ) )
541 if( !
IsOK(
this, wxString::Format(
_(
"Create new file '%s' with contents "
543 sheetFileName.GetFullName(),
546 +
_(
"This action cannot be undone." ) ) )
575 pi->
Save( newAbsoluteFilename,
m_sheet, &schematic );
579 msg = wxString::Format(
_(
"Error occurred saving schematic file '%s'." ),
580 newAbsoluteFilename );
583 msg = wxString::Format(
_(
"Failed to save schematic '%s'" ),
584 newAbsoluteFilename );
606 std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique<SCH_SHEET>( &schematic );
608 tmpSheet->GetFields()[
SHEETFILENAME].SetText( sheetFileName.GetFullPath() );
609 tmpSheet->SetScreen( useScreen );
618 else if( loadFromFile )
620 bool restoreSheet =
false;
622 if( isExistingSheet )
659 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
660 wxControl* control =
editor->GetControl();
661 wxTextEntry* textControl =
dynamic_cast<wxTextEntry*
>( control );
667 if( textControl && textControl->IsEmpty() )
669 wxMessageBox(
_(
"A sheet must have a name." ) );
675 if( textControl->IsEmpty() )
677 wxMessageBox(
_(
"A sheet must have a file specified." ) );
682 if( success && control && control->GetValidator() )
683 success = control->GetValidator()->Validate( control );
710 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
711 m_grid->ProcessTableMessage( msg );
716 m_grid->EnableCellEditControl();
717 m_grid->ShowCellEditControl();
723 wxArrayInt selectedRows =
m_grid->GetSelectedRows();
725 if( selectedRows.empty() &&
m_grid->GetGridCursorRow() >= 0 )
726 selectedRows.push_back(
m_grid->GetGridCursorRow() );
728 if( selectedRows.empty() )
731 for(
int row : selectedRows )
735 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
744 selectedRows.Sort( [](
int* first,
int* second ) {
return *second - *first; } );
746 for(
int row : selectedRows )
751 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
752 m_grid->ProcessTableMessage( msg );
754 if(
m_grid->GetNumberRows() > 0 )
756 m_grid->MakeCellVisible( std::max( 0, row-1 ),
m_grid->GetGridCursorCol() );
757 m_grid->SetGridCursor( std::max( 0, row-1 ),
m_grid->GetGridCursorCol() );
768 int i =
m_grid->GetGridCursorRow();
777 m_grid->SetGridCursor( i - 1,
m_grid->GetGridCursorCol() );
792 int i =
m_grid->GetGridCursorRow();
801 m_grid->SetGridCursor( i + 1,
m_grid->GetGridCursorCol() );
816 m_grid->AutoSizeColumn( 0 );
817 m_grid->SetColSize( 0, std::max( 72,
m_grid->GetColSize( 0 ) ) );
819 int fixedColsWidth =
m_grid->GetColSize( 0 );
821 for(
int i = 2; i <
m_grid->GetNumberCols(); i++ )
822 fixedColsWidth +=
m_grid->GetColSize( i );
824 m_grid->SetColSize( 1, std::max( 120, width - fixedColsWidth ) );
836 if( !
m_grid->IsCellEditControlShown() )
843 if(
path.Last() !=
'/' )
847 wxControl* control =
editor->GetControl();
848 wxTextEntry* textControl =
dynamic_cast<wxTextEntry*
>( control );
852 sheetName = textControl->GetValue();
867 path = wxControl::Ellipsize(
path, dc, wxELLIPSIZE_START, width, wxELLIPSIZE_FLAGS_NONE );
879 m_grid->EnableCellEditControl(
true );
880 m_grid->ShowCellEditControl();
890 auto new_size =
event.GetSize();
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Color settings are a bit different than most of the settings objects in that there can be more than o...
bool GetOverrideSchItemColors() const
COLOR4D GetColor(int aLayer) const
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
KIGFX::COLOR4D GetSwatchColor() const
void SetDefaultColor(const KIGFX::COLOR4D &aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
void SetSwatchBackground(const KIGFX::COLOR4D &aBackground)
Set the swatch background color.
Class DIALOG_SHEET_PROPERTIES_BASE.
STD_BITMAP_BUTTON * m_bpMoveUp
wxTextCtrl * m_pageNumberTextCtrl
COLOR_SWATCH * m_backgroundSwatch
wxStaticText * m_hierarchicalPath
STD_BITMAP_BUTTON * m_bpAdd
wxStdDialogButtonSizer * m_stdDialogButtonSizer
wxBoxSizer * m_sizerBottom
STD_BITMAP_BUTTON * m_bpDelete
COLOR_SWATCH * m_borderSwatch
wxStaticText * m_hierarchicalPathLabel
STD_BITMAP_BUTTON * m_bpMoveDown
bool TransferDataToWindow() override
DIALOG_SHEET_PROPERTIES(SCH_EDIT_FRAME *aParent, SCH_SHEET *aSheet, bool *aClearAnnotationNewItems)
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)
void OnSizeGrid(wxSizeEvent &event) override
FIELDS_GRID_TABLE< SCH_FIELD > * m_fields
void OnInitDlg(wxInitDialogEvent &event) override
void OnUpdateUI(wxUpdateUIEvent &event) override
bool * m_clearAnnotationNewItems
void OnMoveUp(wxCommandEvent &event) override
~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...
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
const EDA_ANGLE & GetTextAngle() const
virtual const wxString & GetText() const
Return the string associated with the text object.
void Offset(const VECTOR2I &aOffset)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual void SetText(const wxString &aText)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
EE_TYPE OfType(KICAD_T aType) const
int GetNumberRows() override
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)
Checks the 'do not show again' setting for the dialog.
APP_SETTINGS_BASE * KifaceSettings() const
A color representation with 4 components: red, green, blue, alpha.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A logical library item identifier and consists of various portions much like a URI.
wxCheckBox * m_optOverrideColors
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Holds all the data relating to one schematic.
SCH_SHEET_LIST & GetFullHierarchy() const
Return the full schematic flattened hierarchical sheet list.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
Schematic editor (Eeschema) main window.
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, const wxString &aFileName)
Load a the KiCad schematic file aFileName into the sheet aSheet.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
bool AllowCaseSensitiveFileNameClashes(const wxString &aSchematicFileName)
Check aSchematicFileName for a potential file name case sensitivity clashes.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void InitSheet(SCH_SHEET *aSheet, const wxString &aNewFilename)
bool CheckSheetForRecursion(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy)
Verify that aSheet will not cause a recursion error in aHierarchy.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
VECTOR2I GetPosition() const override
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetName(const wxString &aName)
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Base class for any item which can be embedded within the SCHEMATIC container class,...
void ClearFieldsAutoplaced()
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
virtual void Save(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
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.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
Return the sheet path in a human readable form made from the sheet names.
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.
void SetBorderColor(KIGFX::COLOR4D aColor)
wxString GetFileName() const
Return the filename corresponding to this sheet.
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
std::vector< SCH_FIELD > & GetFields()
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
void SetBackgroundColor(KIGFX::COLOR4D aColor)
SCH_SCREEN * GetScreen() const
VECTOR2I GetPosition() const override
void SetFields(const std::vector< SCH_FIELD > &aFields)
Set multiple schematic fields.
int GetScreenCount() const
Return the number of times the associated screen for the sheet is being used.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
KIGFX::COLOR4D GetBorderColor() const
void SetBorderWidth(int aWidth)
int GetBorderWidth() const
KIGFX::COLOR4D GetBackgroundColor() const
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
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...
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
std::bitset< 64 > GetShownColumns()
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
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 DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
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.
const std::string KiCadSchematicFileExtension
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
@ LAYER_SCHEMATIC_BACKGROUND
wxFont GetInfoFont(wxWindow *aWindow)
@ SHEET_MANDATORY_FIELDS
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
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().