27 #include <wx/string.h> 29 #include <wx/tooltip.h> 44 bool* aClearAnnotationNewItems ) :
47 m_clearAnnotationNewItems( aClearAnnotationNewItems ),
48 m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits ),
49 m_dummySheet( *aSheet ),
50 m_dummySheetNameField( wxDefaultPosition,
SHEETNAME, &m_dummySheet )
59 m_grid->SetDefaultRowSize(
m_grid->GetDefaultRowSize() + 4 );
63 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
66 auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>(
Kiface().KifaceSettings() );
75 wxToolTip::Enable(
true );
88 m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
98 auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>(
Kiface().KifaceSettings() );
107 m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
112 m_grid->PopEventHandler(
true );
118 if( !wxDialog::TransferDataToWindow() )
130 wxString filename = field_copy.
GetText();
131 filename.Replace( wxT(
"/" ), wxT(
"\\" ) );
132 field_copy.
SetText( filename );
143 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->size() );
144 m_grid->ProcessTableMessage( msg );
191 wxString fieldName = field.
GetName(
false );
193 if( fieldName.IsEmpty() )
240 if( !wxDialog::TransferDataFromWindow() )
248 if( sheetFileName.IsEmpty() )
250 DisplayError(
this,
_(
"A sheet must have a valid file name." ) );
256 wxFileName fn( sheetFileName );
260 DisplayError(
this,
_(
"Sheet file must have a '.kicad_sch' extension." ) );
264 wxString newRelativeFilename = fn.GetFullPath();
267 newRelativeFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
270 oldFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
272 bool filename_changed = oldFilename != newRelativeFilename;
278 wxCHECK( currentScreen,
false );
280 bool clearFileName =
false;
285 clearFileName =
true;
289 wxFileName tmp( fn );
290 wxFileName screenFileName = currentScreen->
GetFileName();
292 if( fn.IsAbsolute() && fn.MakeRelativeTo( screenFileName.GetPath() ) )
294 wxMessageDialog makeRelDlg(
this,
_(
"Use relative path for sheet file?" ),
295 _(
"Sheet File Path" ),
296 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
298 makeRelDlg.SetExtendedMessage(
_(
"Using relative hierarchical sheet file name paths " 299 "improves schematic portability across systems and " 300 "platforms. Using absolute paths can result in " 301 "portability issues." ) );
302 makeRelDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Use Relative Path" ) ),
303 wxMessageDialog::ButtonLabel(
_(
"Use Absolute Path" ) ) );
305 if( makeRelDlg.ShowModal() == wxID_YES )
308 "\n to relative path: '%s'",
312 newRelativeFilename = fn.GetFullPath();
333 if( newSheetname.IsEmpty() )
334 newSheetname =
_(
"Untitled Sheet" );
339 for(
unsigned i = 0; i <
m_fields->size(); ++i )
355 wxPanel temp(
this );
360 KIDIALOG dlg(
this,
_(
"Note: item colors are overridden in the current color theme." ),
362 dlg.ShowDetailedText(
wxString::Format(
_(
"To see individual item colors uncheck '%s'\n" 363 "in Preferences > Eeschema > Colors." ),
400 wxFileName sheetFileName( aNewFilename );
402 if( sheetFileName.GetExt().IsEmpty() )
408 msg =
wxString::Format(
_(
"The file '%s' does not appear to be a valid schematic file." ),
409 sheetFileName.GetFullName() );
410 wxMessageDialog badSchFileDialog(
this, msg,
_(
"Invalid Schematic File" ),
411 wxOK | wxCENTRE | wxICON_EXCLAMATION );
412 badSchFileDialog.ShowModal();
417 std::vector<SCH_SHEET_INSTANCE> sheetInstances = fullHierarchy.
GetSheetInstances();
418 wxFileName screenFileName( sheetFileName );
419 wxFileName tmp( sheetFileName );
423 wxCHECK( currentScreen,
false );
426 wxFileName currentScreenFileName = currentScreen->
GetFileName();
428 if( !screenFileName.Normalize( wxPATH_NORM_ALL, currentScreenFileName.GetPath() ) )
432 "against parent sheet schematic file path:\n" 434 sheetFileName.GetPath(),
435 currentScreenFileName.GetPath() );
440 wxString newAbsoluteFilename = screenFileName.GetFullPath();
443 newAbsoluteFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
445 bool renameFile =
false;
446 bool loadFromFile =
false;
447 bool clearAnnotation =
false;
448 bool restoreSheet =
false;
449 bool isExistingSheet =
false;
457 loadFromFile = wxFileExists( newAbsoluteFilename );
461 loadFromFile ? wxT(
"found" ) : wxT(
"not found" ) );
469 if( useScreen || loadFromFile )
471 clearAnnotation =
true;
474 sheetFileName.GetFullName() )
477 newAbsoluteFilename ) ) )
489 bool isUndoable =
true;
490 isExistingSheet =
true;
505 oldAbsoluteFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
507 if( newAbsoluteFilename.Cmp( oldAbsoluteFilename ) != 0 )
512 if( useScreen || loadFromFile )
514 clearAnnotation =
true;
519 sheetFileName.GetFullName() )
521 +
_(
"This action cannot be undone." ) ) )
534 sheetFileName.GetFullName(),
537 +
_(
"This action cannot be undone." ) ) )
571 newAbsoluteFilename );
575 newAbsoluteFilename );
597 std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique<SCH_SHEET>();
599 tmpSheet->GetFields()[
SHEETFILENAME].SetText( sheetFileName.GetFullPath() );
600 tmpSheet->SetScreen( useScreen );
614 else if( loadFromFile )
616 if( isExistingSheet )
658 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(),
event.GetCol() );
659 wxControl* control =
editor->GetControl();
660 wxTextEntry* textControl = dynamic_cast<wxTextEntry*>( control );
666 if( textControl && textControl->IsEmpty() )
668 wxMessageBox(
_(
"A sheet must have a name." ) );
674 if( textControl->IsEmpty() )
676 wxMessageBox(
_(
"A sheet must have a file specified." ) );
681 if( success && control && control->GetValidator() )
682 success = control->GetValidator()->Validate( control );
709 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
710 m_grid->ProcessTableMessage( msg );
715 m_grid->EnableCellEditControl();
716 m_grid->ShowCellEditControl();
722 wxArrayInt selectedRows =
m_grid->GetSelectedRows();
724 if( selectedRows.empty() &&
m_grid->GetGridCursorRow() >= 0 )
725 selectedRows.push_back(
m_grid->GetGridCursorRow() );
727 if( selectedRows.empty() )
730 for(
int row : selectedRows )
743 selectedRows.Sort( [](
int* first,
int* second ) {
return *second - *first; } );
745 for(
int row : selectedRows )
750 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
751 m_grid->ProcessTableMessage( msg );
753 if(
m_grid->GetNumberRows() > 0 )
755 m_grid->MakeCellVisible( std::max( 0, row-1 ),
m_grid->GetGridCursorCol() );
756 m_grid->SetGridCursor( std::max( 0, row-1 ),
m_grid->GetGridCursorCol() );
767 int i =
m_grid->GetGridCursorRow();
776 m_grid->SetGridCursor( i - 1,
m_grid->GetGridCursorCol() );
789 int i =
m_grid->GetGridCursorRow();
798 m_grid->SetGridCursor( i + 1,
m_grid->GetGridCursorCol() );
810 aWidth -= (
m_grid->GetSize().x -
m_grid->GetClientSize().x );
812 m_grid->AutoSizeColumn( 0 );
814 int fixedColsWidth =
m_grid->GetColSize( 0 );
816 for(
int i = 2; i <
m_grid->GetNumberCols(); i++ )
817 fixedColsWidth +=
m_grid->GetColSize( i );
819 int colSize = std::max( aWidth - fixedColsWidth, -1 );
820 colSize = ( colSize == 0 ) ? -1 : colSize;
822 m_grid->SetColSize( 1, colSize );
834 if( !
m_grid->IsCellEditControlShown() )
839 wxString hierarchicalPath =
_(
"Hierarchical path: " );
843 if( hierarchicalPath.Last() !=
'/' )
844 hierarchicalPath.Append(
'/' );
847 wxControl* control =
editor->GetControl();
848 wxTextEntry* textControl = dynamic_cast<wxTextEntry*>( control );
852 sheetName = textControl->GetValue();
873 m_grid->EnableCellEditControl(
true );
874 m_grid->ShowCellEditControl();
884 auto new_size =
event.GetSize().GetX();
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
bool CheckSheetForRecursion(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy)
Verify that aSheet will not cause a recursion error in aHierarchy.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
wxBitmapButton * m_bpMoveUp
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
bool * m_clearAnnotationNewItems
EE_TYPE OfType(KICAD_T aType) const
void OnDeleteField(wxCommandEvent &event) override
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
void Offset(const wxPoint &aOffset)
Functions for manipulating tab traversal in forms and dialogs.
const wxString & GetFileName() const
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
bool Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
KIGFX::COLOR4D GetSwatchColor() const
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
wxCheckBox * m_optOverrideColors
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void SetFields(const std::vector< SCH_FIELD > &aFields)
Set multiple schematic fields.
void OnUpdateUI(wxUpdateUIEvent &event) override
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
This file is part of the common library.
void OnMoveDown(wxCommandEvent &event) override
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
wxString PathHumanReadable(bool aUseShortRootName=true) const
Return the sheet path in a human readable form made from the sheet names.
wxPoint GetPosition() const override
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
wxFont GetInfoFont(wxWindow *aWindow)
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
double GetTextAngle() const
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
void InitSheet(SCH_SHEET *aSheet, const wxString &aNewFilename)
KIGFX::COLOR4D GetBorderColor() const
Schematic editor (Eeschema) main window.
void AdjustGridColumns(int aWidth)
wxButton * m_stdDialogButtonSizerOK
wxBitmapButton * m_bpDelete
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...
A logical library item identifier and consists of various portions much like a URI.
SCH_SCREEN * GetScreen() const
void OnInitDlg(wxInitDialogEvent &event) override
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
void UpdateSheetInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
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.
KIGFX::COLOR4D GetBackgroundColor() const
void SetBorderWidth(int aWidth)
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
std::vector< SCH_FIELD > & GetFields()
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.
int GetBorderWidth() const
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, const wxString &aFileName)
Load a the KiCad schematic file aFileName into the sheet aSheet.
void SetBackgroundColor(KIGFX::COLOR4D aColor)
bool AllowCaseSensitiveFileNameClashes(const wxString &aSchematicFileName)
Check aSchematicFileName for a potential file name case sensitivity clashes.
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
virtual void SetText(const wxString &aText)
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
UNIT_BINDER m_borderWidth
virtual const wxString What() const
A composite of Problem() and Where()
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
bool TransferDataToWindow() override
SCHEMATIC & Schematic() const
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition of file extensions used in Kicad.
static bool positioningChanged(const SCH_FIELD &a, const SCH_FIELD &b)
wxStaticText * m_hierarchicalPathLabel
void ClearFieldsAutoplaced()
Class DIALOG_SHEET_PROPERTIES_BASE.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false)
Mark an item for refresh.
std::vector< SCH_SHEET_INSTANCE > GetSheetInstances() const
Fetch the instance information for all of the sheets in the hiearchy.
void SetDefaultColor(const KIGFX::COLOR4D &aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
wxLogTrace helper definitions.
wxTextCtrl * m_pageNumberTextCtrl
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
wxString GetFileName() const
Return the filename corresponding to this sheet.
wxPoint GetPosition() const override
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_SWATCH * m_backgroundSwatch
COLOR_SETTINGS * GetColorSettings() const override
Returns a pointer to the active color theme settings.
SCH_FIELD m_dummySheetNameField
void OnGridCellChanging(wxGridEvent &event)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
DIALOG_SHEET_PROPERTIES(SCH_EDIT_FRAME *aParent, SCH_SHEET *aSheet, bool *aClearAnnotationNewItems)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
COLOR_SWATCH * m_borderSwatch
wxString GetShownColumns()
Get a tokenized string containing the shown column indexes.
COLOR4D GetColor(int aLayer) const
bool TransferDataFromWindow() override
SCH_SCREEN * LastScreen()
void Append(SCH_ITEM *aItem)
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend)
Create a copy of the current schematic item, and put it in the undo list.
void OnMoveUp(wxCommandEvent &event) override
wxString GetName(bool aUseDefaultName=true) const
Return the field name.
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
const std::string KiCadSchematicFileExtension
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual long long int GetValue()
Return the current value in Internal Units.
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)
void OnSizeGrid(wxSizeEvent &event) override
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
bool onSheetFilenameChanged(const wxString &aNewFilename)
wxBitmapButton * m_bpMoveDown
FIELDS_GRID_TABLE< SCH_FIELD > * m_fields
~DIALOG_SHEET_PROPERTIES() override
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Base class for any item which can be embedded within the SCHEMATIC container class,...
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
virtual const wxString & GetText() const
Return the string associated with the text object.
Custom text control validator definitions.
SCH_SHEET_LIST & GetFullHierarchy() const
Return the full schematic flattened hierarchical sheet list.
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
void SetSwatchBackground(const KIGFX::COLOR4D &aBackground)
Set the swatch background color.
bool AddInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
A color representation with 4 components: red, green, blue, alpha.
void OnAddField(wxCommandEvent &event) override