30#include <wx/tooltip.h>
49#include "wx/dcclient.h"
53 bool* aIsUndoable,
bool* aClearAnnotationNewItems,
54 bool* aUpdateHierarchyNavigator,
55 wxString* aSourceSheetFilename ) :
58 m_isUndoable( aIsUndoable ),
59 m_clearAnnotationNewItems( aClearAnnotationNewItems ),
60 m_updateHierarchyNavigator( aUpdateHierarchyNavigator ),
61 m_sourceSheetFilename( aSourceSheetFilename ),
62 m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits ),
63 m_dummySheet( *aSheet ),
72 m_grid->SetDefaultRowSize(
m_grid->GetDefaultRowSize() + 4 );
76 [&]( wxCommandEvent& aEvent )
80 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
97 wxToolTip::Enable(
true );
111 m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
122 cfg->m_Appearance.edit_sheet_width = GetSize().x;
123 cfg->m_Appearance.edit_sheet_height = GetSize().y;
129 m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
134 m_grid->PopEventHandler(
true );
140 if( !wxDialog::TransferDataToWindow() )
150 if( field_copy.
GetId() == FIELD_T::SHEET_FILENAME )
152 wxString filename = field_copy.
GetText();
153 filename.Replace( wxT(
"/" ), wxT(
"\\" ) );
154 field_copy.
SetText( filename );
165 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->size() );
166 m_grid->ProcessTableMessage( msg );
208 for(
size_t i = 0; i <
m_fields->size(); ++i )
270 if( !wxDialog::TransferDataFromWindow() )
281 if( sheetFileName.IsEmpty() )
283 DisplayError(
this,
_(
"A sheet must have a valid file name." ) );
294 DisplayError(
this,
_(
"A sheet must have a valid file name." ) );
298 wxFileName fn( sheetFileName );
300 wxString newRelativeFilename = fn.GetFullPath();
303 newRelativeFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
306 oldFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
308 bool filename_changed = oldFilename != newRelativeFilename;
314 wxCHECK( currentScreen,
false );
316 bool clearFileName =
false;
321 clearFileName =
true;
325 wxFileName tmp( fn );
326 wxFileName screenFileName = currentScreen->
GetFileName();
328 if( fn.IsAbsolute() && fn.MakeRelativeTo( screenFileName.GetPath() ) )
330 wxMessageDialog makeRelDlg(
this,
_(
"Use relative path for sheet file?" ),
331 _(
"Sheet File Path" ),
332 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
334 makeRelDlg.SetExtendedMessage(
_(
"Using relative hierarchical sheet file name paths "
335 "improves schematic portability across systems and "
336 "platforms. Using absolute paths can result in "
337 "portability issues." ) );
338 makeRelDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Use Relative Path" ) ),
339 wxMessageDialog::ButtonLabel(
_(
"Use Absolute Path" ) ) );
341 if( makeRelDlg.ShowModal() == wxID_YES )
344 "\n to relative path: '%s'",
348 newRelativeFilename = fn.GetFullPath();
379 if( newSheetname.IsEmpty() )
380 newSheetname =
_(
"Untitled Sheet" );
402 else if( fieldName.IsEmpty() )
416 wxPanel temp(
this );
421 KIDIALOG dlg(
this,
_(
"Note: item colors are overridden in the current color theme." ),
423 dlg.ShowDetailedText( wxString::Format(
_(
"To see individual item colors uncheck '%s'\n"
424 "in Preferences > Schematic Editor > Colors." ),
464 wxFileName screenFileName( sheetFileName );
465 wxFileName tmp( sheetFileName );
468 wxCHECK( currentScreen,
false );
471 wxFileName currentScreenFileName = currentScreen->
GetFileName();
474 currentScreenFileName.GetPath() ) )
476 msg = wxString::Format(
_(
"Cannot normalize new sheet schematic file path:\n"
478 "against parent sheet schematic file path:\n"
480 sheetFileName.GetPath(),
481 currentScreenFileName.GetPath() );
486 wxString newAbsoluteFilename = screenFileName.GetFullPath();
489 newAbsoluteFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
491 bool renameFile =
false;
492 bool loadFromFile =
false;
493 bool clearAnnotation =
false;
494 bool isExistingSheet =
false;
502 loadFromFile = wxFileExists( newAbsoluteFilename );
506 loadFromFile ?
"found" :
"not found" );
512 newAbsoluteFilename ) )
515 if( useScreen || loadFromFile )
517 clearAnnotation =
true;
519 if( !
IsOK(
this, wxString::Format(
_(
"'%s' already exists." ),
520 sheetFileName.GetFullName() )
522 + wxString::Format(
_(
"Link '%s' to this file?" ),
523 newAbsoluteFilename ) ) )
536 msg.Printf(
_(
"Failed to copy schematic file '%s' to destination '%s'." ),
537 currentScreenFileName.GetFullPath(), newAbsoluteFilename );
551 isExistingSheet =
true;
554 newAbsoluteFilename ) )
567 oldAbsoluteFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
569 if( newAbsoluteFilename.Cmp( oldAbsoluteFilename ) != 0 )
575 if( useScreen || loadFromFile )
577 clearAnnotation =
true;
580 if( !
IsOK(
this, wxString::Format(
_(
"Change '%s' link from '%s' to '%s'?" ),
583 sheetFileName.GetFullName() )
585 +
_(
"This action cannot be undone." ) ) )
597 if( !
IsOK(
this, wxString::Format(
_(
"Create new file '%s' with contents "
599 sheetFileName.GetFullName(),
602 +
_(
"This action cannot be undone." ) ) )
625 pi->SaveSchematicFile( newAbsoluteFilename,
m_sheet, &schematic );
629 msg = wxString::Format(
_(
"Error occurred saving schematic file '%s'." ),
630 newAbsoluteFilename );
633 msg = wxString::Format(
_(
"Failed to save schematic '%s'" ),
634 newAbsoluteFilename );
656 std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique<SCH_SHEET>( &schematic );
657 *tmpSheet->GetField( FIELD_T::SHEET_NAME ) =
m_fields->
GetField( FIELD_T::SHEET_NAME );
658 tmpSheet->GetField( FIELD_T::SHEET_FILENAME )->
SetText( sheetFileName.GetFullPath() );
659 tmpSheet->SetScreen( useScreen );
674 else if( loadFromFile )
676 bool restoreSheet =
false;
678 if( isExistingSheet )
718 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
719 wxControl* control =
editor->GetControl();
721 if( control && control->GetValidator() )
722 success = control->GetValidator()->Validate( control );
748 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
749 m_grid->ProcessTableMessage( msg );
754 m_grid->EnableCellEditControl();
755 m_grid->ShowCellEditControl();
761 wxArrayInt selectedRows =
m_grid->GetSelectedRows();
763 if( selectedRows.empty() &&
m_grid->GetGridCursorRow() >= 0 )
764 selectedRows.push_back(
m_grid->GetGridCursorRow() );
766 if( selectedRows.empty() )
769 for(
int row : selectedRows )
771 if( row < m_fields->GetMandatoryRowCount() )
773 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
782 selectedRows.Sort( [](
int* first,
int* second ) {
return *second - *first; } );
784 for(
int row : selectedRows )
789 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
790 m_grid->ProcessTableMessage( msg );
792 if(
m_grid->GetNumberRows() > 0 )
794 m_grid->MakeCellVisible( std::max( 0, row-1 ),
m_grid->GetGridCursorCol() );
795 m_grid->SetGridCursor( std::max( 0, row-1 ),
m_grid->GetGridCursorCol() );
806 int i =
m_grid->GetGridCursorRow();
815 m_grid->SetGridCursor( i - 1,
m_grid->GetGridCursorCol() );
830 int i =
m_grid->GetGridCursorRow();
839 m_grid->SetGridCursor( i + 1,
m_grid->GetGridCursorCol() );
854 m_grid->AutoSizeColumn( 0 );
855 m_grid->SetColSize( 0, std::max( 72,
m_grid->GetColSize( 0 ) ) );
857 int fixedColsWidth =
m_grid->GetColSize( 0 );
859 for(
int i = 2; i <
m_grid->GetNumberCols(); i++ )
860 fixedColsWidth +=
m_grid->GetColSize( i );
862 m_grid->SetColSize( 1, std::max( 120, width - fixedColsWidth ) );
874 if( !
m_grid->IsCellEditControlShown() )
882 if(
path.Last() !=
'/' )
886 wxControl* control =
editor->GetControl();
887 wxTextEntry* textControl =
dynamic_cast<wxTextEntry*
>( control );
891 sheetName = textControl->GetValue();
906 path = wxControl::Ellipsize(
path, dc, wxELLIPSIZE_START, width, wxELLIPSIZE_FLAGS_NONE );
918 m_grid->EnableCellEditControl(
true );
919 m_grid->ShowCellEditControl();
929 auto new_size =
event.GetSize();
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
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.
wxCheckBox * m_cbExcludeFromSim
STD_BITMAP_BUTTON * m_bpMoveUp
wxTextCtrl * m_pageNumberTextCtrl
wxCheckBox * m_cbExcludeFromBom
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
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
void OnSizeGrid(wxSizeEvent &event) override
bool * m_updateHierarchyNavigator
void OnInitDlg(wxInitDialogEvent &event) override
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...
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 SetTextAngle(const EDA_ANGLE &aAngle)
EE_TYPE OfType(KICAD_T aType) const
SCH_FIELD * GetField(FIELD_T aFieldId)
int GetNumberRows() override
int GetMandatoryRowCount() const
int GetFieldRow(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.
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 GetProjectName() const
Return the short name of the project.
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 Hierarchy() 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 AllowCaseSensitiveFileNameClashes(const wxString &aOldName, 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 LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aCurrentSheet, const wxString &aFileName, bool aSkipRecursionCheck=false, bool aSkipLibCheck=false)
Load a the KiCad schematic file aFileName into the sheet aSheet.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
bool CheckSheetForRecursion(SCH_SHEET *aSheet, SCH_SHEET_PATH *aCurrentSheet)
Verify that aSheet will not cause a recursion error in aCurrentSheet.
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.
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,...
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)
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
void SetFieldsAutoplaced(AUTOPLACE_ALGO aAlgo)
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get 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.
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...
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.
bool GetExcludedFromBOM() const
void SetBorderColor(KIGFX::COLOR4D aColor)
wxString GetFileName() const
Return the filename corresponding to this sheet.
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
void SetExcludedFromBOM(bool aExcludeFromBOM)
Set or clear the exclude from schematic bill of materials flag.
bool GetExcludedFromBoard() const
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)
bool GetExcludedFromSim() const override
int GetBorderWidth() const
void SetExcludedFromBoard(bool aExcludeFromBoard)
Set or clear exclude from board netlist flag.
void SetExcludedFromSim(bool aExcludeFromSim) override
Set or clear the exclude from simulation flag.
bool GetDNP() const
Set or clear the 'Do Not Populate' flags.
KIGFX::COLOR4D GetBackgroundColor() const
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 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.
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.
This file is part of the common library.
@ LAYER_SCHEMATIC_BACKGROUND
KICOMMON_API wxFont GetInfoFont(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().