27 #include <wx/string.h> 28 #include <wx/tooltip.h> 43 bool* aClearAnnotationNewItems ) :
46 m_clearAnnotationNewItems( aClearAnnotationNewItems ),
47 m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits, true ),
48 m_dummySheet( *aSheet ),
49 m_dummySheetNameField( wxDefaultPosition,
SHEETNAME, &m_dummySheet )
58 m_grid->SetDefaultRowSize(
m_grid->GetDefaultRowSize() + 4 );
64 auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>(
Kiface().KifaceSettings() );
73 wxToolTip::Enable(
true );
83 wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
84 infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
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 );
169 wxString nextPageNumber;
172 nextPageNumber.Printf(
"%d", static_cast<int>( hierarchy.size() ) + 1 );
196 wxString fieldName = field.
GetName(
false );
198 if( fieldName.IsEmpty() )
245 if( !wxDialog::TransferDataFromWindow() )
254 if( newRelativeNativeFilename.IsEmpty() )
256 wxMessageBox(
_(
"A sheet must have a valid file name." ) );
262 wxFileName fn( newRelativeNativeFilename );
266 wxMessageBox(
_(
"Sheet file must have a '.kicad_sch' extension." ) );
270 wxString newRelativeFilename = fn.GetFullPath();
273 newRelativeFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
276 oldFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
278 bool filename_changed = oldFilename != newRelativeFilename;
291 if( newSheetname.IsEmpty() )
292 newSheetname =
_(
"Untitled Sheet" );
297 for(
unsigned i = 0; i <
m_fields->size(); ++i )
313 wxPanel temp(
this );
318 KIDIALOG dlg(
this,
_(
"Note: item colors are overridden in the current color theme." ),
320 dlg.ShowDetailedText(
wxString::Format(
_(
"To see individual item colors uncheck '%s'\n" 321 "in Preferences > Eeschema > Colors." ),
358 wxFileName fileName( aNewFilename );
360 if( fileName.GetExt().IsEmpty() )
366 msg.Printf(
_(
"The file \"%s\" does not appear to be a valid schematic file." ),
367 fileName.GetFullName() );
368 wxMessageDialog badSchFileDialog(
this, msg,
_(
"Invalid Schematic File" ),
369 wxOK | wxCENTRE | wxICON_EXCLAMATION );
370 badSchFileDialog.ShowModal();
374 if( !fileName.IsAbsolute() )
377 wxCHECK_MSG( currentScreen,
false,
"Invalid sheet path object." );
379 wxFileName currentSheetFileName = currentScreen->
GetFileName();
381 if( !fileName.Normalize( wxPATH_NORM_ALL, currentSheetFileName.GetPath() ) )
383 wxFAIL_MSG(
"Cannot normalize new sheet schematic file path." );
388 wxString newAbsoluteFilename = fileName.GetFullPath();
391 newAbsoluteFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
393 bool renameFile =
false;
394 bool loadFromFile =
false;
395 bool clearAnnotation =
false;
396 bool restoreSheet =
false;
397 bool isExistingSheet =
false;
404 loadFromFile = wxFileExists( newAbsoluteFilename );
408 ( loadFromFile ) ?
"found" :
"not found" );
416 if( useScreen || loadFromFile )
418 clearAnnotation =
true;
421 existsMsg.Printf(
_(
"\"%s\" already exists." ), fileName.GetFullName() );
422 linkMsg.Printf(
_(
"Link \"%s\" to this file?" ), newAbsoluteFilename );
423 msg.Printf( wxT(
"%s\n\n%s" ), existsMsg, linkMsg );
425 if( !
IsOK(
this, msg ) )
435 bool isUndoable =
true;
439 isExistingSheet =
true;
447 replaceMsg.Printf(
_(
"Change \"%s\" link from \"%s\" to \"%s\"?" ),
450 fileName.GetFullName() );
451 newMsg.Printf(
_(
"Create new file \"%s\" with contents of \"%s\"?" ),
452 fileName.GetFullName(),
454 noUndoMsg =
_(
"This action cannot be undone." );
466 oldAbsoluteFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
468 if( newAbsoluteFilename.Cmp( oldAbsoluteFilename ) != 0 )
473 if( useScreen || loadFromFile )
475 clearAnnotation =
true;
477 msg.Printf( wxT(
"%s\n\n%s" ), replaceMsg, noUndoMsg );
479 if( !
IsOK(
this, msg ) )
489 msg.Printf( wxT(
"%s\n\n%s" ), newMsg, noUndoMsg );
491 if( !
IsOK(
this, msg ) )
519 msg.Printf(
_(
"Error occurred saving schematic file \"%s\"." ),
520 newAbsoluteFilename );
523 msg.Printf(
_(
"Failed to save schematic \"%s\"" ), newAbsoluteFilename );
540 wxFileName nativeFileName( aNewFilename );
546 std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique<SCH_SHEET>();
548 tmpSheet->GetFields()[
SHEETFILENAME].SetText( nativeFileName.GetFullPath() );
549 tmpSheet->SetScreen( useScreen );
563 else if( loadFromFile )
565 if( isExistingSheet )
596 wxGridCellEditor* editor =
m_grid->GetCellEditor( event.GetRow(),
event.GetCol() );
597 wxControl* control = editor->GetControl();
598 wxTextEntry* textControl = dynamic_cast<wxTextEntry*>( control );
604 if( textControl && textControl->IsEmpty() )
606 wxMessageBox(
_(
"A sheet must have a name." ) );
612 if( textControl->IsEmpty() )
614 wxMessageBox(
_(
"A sheet must have a file specified." ) );
619 wxFileName fn = textControl->GetValue();
623 wxMessageBox(
_(
"Sheet filename must have a '.kicad_sch' extension." ) );
629 if( success && control && control->GetValidator() )
630 success = control->GetValidator()->Validate( control );
657 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
658 m_grid->ProcessTableMessage( msg );
663 m_grid->EnableCellEditControl();
664 m_grid->ShowCellEditControl();
670 int curRow =
m_grid->GetGridCursorRow();
686 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
687 m_grid->ProcessTableMessage( msg );
689 if(
m_grid->GetNumberRows() > 0 )
691 m_grid->MakeCellVisible( std::max( 0, curRow-1 ),
m_grid->GetGridCursorCol() );
692 m_grid->SetGridCursor( std::max( 0, curRow-1 ),
m_grid->GetGridCursorCol() );
702 int i =
m_grid->GetGridCursorRow();
711 m_grid->SetGridCursor( i - 1,
m_grid->GetGridCursorCol() );
724 int i =
m_grid->GetGridCursorRow();
733 m_grid->SetGridCursor( i + 1,
m_grid->GetGridCursorCol() );
745 aWidth -= (
m_grid->GetSize().x -
m_grid->GetClientSize().x );
747 m_grid->AutoSizeColumn( 0 );
749 int fixedColsWidth =
m_grid->GetColSize( 0 );
751 for(
int i = 2; i <
m_grid->GetNumberCols(); i++ )
752 fixedColsWidth +=
m_grid->GetColSize( i );
754 m_grid->SetColSize( 1, aWidth - fixedColsWidth );
766 if( !
m_grid->IsCellEditControlShown() )
771 wxString hierarchicalPath =
_(
"Hierarchical path: " );
775 if( hierarchicalPath.Last() !=
'/' )
776 hierarchicalPath.Append(
'/' );
779 wxControl* control = editor->GetControl();
780 wxTextEntry* textControl = dynamic_cast<wxTextEntry*>( control );
784 sheetName = textControl->GetValue();
805 m_grid->EnableCellEditControl(
true );
806 m_grid->ShowCellEditControl();
816 auto new_size =
event.GetSize().GetX();
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
SCH_FIELD instances are attached to a component and provide a place for the component'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.
void SetSwatchColor(KIGFX::COLOR4D aColor, bool aSendEvent)
Set the current swatch color directly.
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.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
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
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
void SetDefaultColor(KIGFX::COLOR4D aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
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
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
double GetTextAngle() const
void InitSheet(SCH_SHEET *aSheet, const wxString &aNewFilename)
KIGFX::COLOR4D GetBorderColor() const
Schematic editor (Eeschema) main window.
void SetSwatchBackground(KIGFX::COLOR4D aBackground)
Set the swatch background color.
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.
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.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
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.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
const BITMAP_OPAQUE small_down_xpm[1]
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()
Set fields automatically placed flag false.
Class DIALOG_SHEET_PROPERTIES_BASE.
wxLogTrace helper definitions.
static const wxString GetDefaultFieldName(int aFieldNdx)
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
const BITMAP_OPAQUE small_up_xpm[1]
COLOR_SWATCH * m_backgroundSwatch
COLOR_SETTINGS * GetColorSettings() const override
Returns a pointer to the active color theme settings.
const BITMAP_OPAQUE small_trash_xpm[1]
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
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
const std::string KiCadSchematicFileExtension
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)
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 const wxString & GetText() const
Return the string associated with the text object.
const BITMAP_OPAQUE small_plus_xpm[1]
Custom text control validator definitions.
SCH_SHEET_LIST & GetFullHierarchy() const
Return the full schematic flattened hiearchical sheet list.
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
bool AddInstance(const KIID_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