28#include <wx/tooltip.h>
51#include "wx/dcclient.h"
55 bool* aIsUndoable,
bool* aClearAnnotationNewItems,
56 bool* aUpdateHierarchyNavigator,
57 wxString* aSourceSheetFilename ) :
70 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
71 embeddedFilesStack.push_back(
m_sheet->Schematic() );
80 [&]( wxCommandEvent& aEvent )
84 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
85 m_grid->ShowHideColumns(
"0 1 2 3 4 5 6 7" );
88 if(
m_frame->GetColorSettings()->GetOverrideSchItemColors() )
89 m_infoBar->ShowMessage(
_(
"Note: individual item colors overridden in Preferences." ) );
96 int suffixWidth =
m_fullSuffixCtrl->GetTextExtent( wxS(
"XXXX_XXXX" ) ).GetWidth() + FromDIP( 20 );
99 wxToolTip::Enable(
true );
133 m_grid->PopEventHandler(
true );
139 if( !wxDialog::TransferDataToWindow() )
144 wxString variantName =
m_frame->Schematic().GetCurrentVariant();
152 wxString filename = field_copy.GetText();
153 filename.Replace( wxT(
"/" ), wxT(
"\\" ) );
154 field_copy.SetText( filename );
158 if( !field_copy.IsMandatory() &&
m_sheet->GetField( field_copy.GetName() ) )
160 wxString
text =
m_sheet->GetFieldText( field_copy.GetName(), &instance, variantName );
165 field_copy.Offset( -
m_sheet->GetPosition() );
167 field_copy.SetParent(
m_sheet );
172 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->size() );
173 m_grid->ProcessTableMessage( msg );
205 GetSizer()->SetSizeHints(
this );
208 wxSize curSize = GetSize();
211 SetSize( wxSize( std::max( curSize.x,
minSize.x ), std::max( curSize.y,
minSize.y ) ) );
219 if( !
m_grid->CommitPendingChanges() || !
m_grid->Validate() )
223 for(
size_t i = 0; i <
m_fields->size(); ++i )
279 if( !wxDialog::TransferDataFromWindow() )
290 if( sheetFileName.IsEmpty() )
292 DisplayError(
this,
_(
"A sheet must have a valid file name." ) );
314 DisplayError(
this,
_(
"A sheet must have a valid file name." ) );
318 wxFileName fn( sheetFileName );
320 wxString newRelativeFilename = fn.GetFullPath();
323 newRelativeFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
326 oldFilename.Replace( wxT(
"\\" ), wxT(
"/" ) );
328 bool filename_changed = oldFilename != newRelativeFilename;
330 if( filename_changed ||
m_sheet->IsNew() )
334 wxCHECK( currentScreen,
false );
336 bool clearFileName =
false;
341 clearFileName =
true;
342 currentScreen->
SetFileName(
m_frame->Prj().AbsolutePath( wxT(
"noname.kicad_sch" ) ) );
345 wxFileName tmp( fn );
346 wxFileName screenFileName = currentScreen->
GetFileName();
348 if( fn.IsAbsolute() && fn.MakeRelativeTo( screenFileName.GetPath() ) )
351 _(
"Sheet File Path" ),
352 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
354 makeRelDlg.SetExtendedMessage(
_(
"Using relative hierarchical sheet file name paths improves "
355 "schematic portability across systems and platforms. Using "
356 "absolute paths can result in portability issues." ) );
357 makeRelDlg.SetYesNoLabels( KICAD_MESSAGE_DIALOG::ButtonLabel(
_(
"Use Relative Path" ) ),
358 KICAD_MESSAGE_DIALOG::ButtonLabel(
_(
"Use Absolute Path" ) ) );
360 if( makeRelDlg.ShowModal() == wxID_YES )
363 "\n to relative path: '%s'",
367 newRelativeFilename = fn.GetFullPath();
398 if( newSheetname.IsEmpty() )
399 newSheetname =
_(
"Untitled Sheet" );
408 m_sheet->SetName( newSheetname );
409 m_sheet->SetFileName( newRelativeFilename );
413 if( oldNetPrefix != newNetPrefix )
414 m_frame->Prj().GetProjectFile().NetSettings()->RenameNetPathPrefix( oldNetPrefix, newNetPrefix );
418 m_field.Offset(
m_sheet->GetPosition() );
424 wxString variantName =
m_frame->Schematic().GetCurrentVariant();
430 const wxString& fieldName = field.GetUntranslatedName();
432 if( field.IsEmpty() )
434 else if( fieldName.IsEmpty() )
435 field.SetName(
_(
"untitled" ) );
437 if( !field.IsMandatory() )
448 tmp =
m_sheet->AddField( field );
453 wxString defaultText =
m_sheet->Schematic()->ConvertRefsToKIIDs( existingField->
GetText() );
454 tmp =
const_cast<SCH_FIELD*
>( existingField );
458 if( !variantName.IsEmpty() )
461 tmp->
SetText( defaultText, &instance );
463 wxString variantText =
m_sheet->Schematic()->ConvertRefsToKIIDs( field.GetText() );
464 tmp->
SetText( variantText, &instance, variantName );
469 for(
int ii = (
int)
m_sheet->GetFields().size() - 1; ii >= 0; ii-- )
480 if( editedField.GetName() == sheetField.
GetName() )
491 std::stable_sort(
m_sheet->GetFields().begin(),
m_sheet->GetFields().end(),
494 return lhs.GetOrdinal() < rhs.GetOrdinal();
505 wxPanel temp(
this );
510 KIDIALOG dlg(
this,
_(
"Note: item colors are overridden in the current color theme." ),
512 dlg.ShowDetailedText( wxString::Format(
_(
"To see individual item colors uncheck '%s'\n"
513 "in Preferences > Schematic Editor > Colors." ),
552 wxPoint pos =
m_grid->CalcUnscrolledPosition( aEvent.GetPosition() );
553 int row =
m_grid->YToRow( pos.y );
558 tooltip =
_(
"Appended to component references in this sheet. Example: _M1 produces R1_M1." );
561 if(
m_grid->GetGridWindow()->GetToolTipText() != tooltip )
562 m_grid->GetGridWindow()->SetToolTip( tooltip );
569 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
570 wxControl* control =
editor->GetControl();
572 if( control && control->GetValidator() )
573 success = control->GetValidator()->Validate( control );
581 else if( event.GetCol() ==
FDC_NAME )
583 wxString newName =
event.GetString();
585 for(
int i = 0; i <
m_grid->GetNumberRows(); ++i )
587 if( i == event.GetRow() )
591 || newName ==
m_fields->at( i ).GetUntranslatedName() )
593 DisplayError(
this, wxString::Format(
_(
"Field name '%s' already in use." ), newName ) );
609 [&]() -> std::pair<int, int>
618 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
619 m_grid->ProcessTableMessage( msg );
630 if( row < m_fields->GetMandatoryRowCount() )
632 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
633 m_fields->GetMandatoryRowCount() ) );
639 DisplayError(
this,
_(
"The reference suffix field cannot be deleted. Clear its value instead." ) );
651 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
652 m_grid->ProcessTableMessage( msg );
662 return row >
m_fields->GetMandatoryRowCount() + 1;
677 return row >=
m_fields->GetMandatoryRowCount() + 1;
689 std::bitset<64> shownColumns =
m_grid->GetShownColumns();
695 if( !
m_grid->IsCellEditControlShown() )
696 m_grid->SetGridWidthsDirty();
701 wxString
path =
m_frame->GetCurrentSheet().PathHumanReadable(
false );
703 if(
path.Last() !=
'/' )
707 wxControl* control =
editor->GetControl();
708 wxTextEntry* textControl =
dynamic_cast<wxTextEntry*
>( control );
712 sheetName = textControl->GetValue();
727 path = wxControl::Ellipsize(
path,
dc, wxELLIPSIZE_START, width, wxELLIPSIZE_FLAGS_NONE );
736 if( !
m_frame->Schematic().GetCurrentVariant().IsEmpty() )
740 const SCH_FIELD* baseField = std::as_const( *m_sheet ).GetField( field.GetName() );
749 wxString preview = fullSuffix.IsEmpty() ?
_(
"None" ) : fullSuffix;
761 m_grid->EnableCellEditControl(
true );
762 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
wxTextCtrl * m_fullSuffixCtrl
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 OnGridMotion(wxMouseEvent &aEvent)
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 SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
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 SetParent(EDA_ITEM *aParent)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
virtual void SetVisible(bool aVisible)
virtual EDA_ANGLE GetTextAngle() const
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
SCH_FIELD * GetField(FIELD_T aFieldId)
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.
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Schematic editor (Eeschema) main window.
VECTOR2I GetPosition() const override
virtual const wxString & GetText() const override
Return the string associated with the text object.
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
const wxString & GetFileName() const
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
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 GetPageNumber() const
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false, bool aEscapeSheetNames=false) const
Return the sheet path in a human readable form made from the sheet names.
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
wxString ComposeRefSuffix() const
Compose the reference suffixes of every sheet in this path, from the root down.
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.
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
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.
std::vector< SCH_FIELD > GetSheetFieldsForEditing(const SCH_SHEET &aSheet)
static const std::string KiCadSchematicFileExtension
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
@ 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.
bool FieldNamesAreDuplicates(const wxString &aLhs, const wxString &aRhs, std::initializer_list< FIELD_T > aMandatoryFields)
Test whether two field names should be treated as duplicates for the purposes of field name uniquenes...
wxString GetUserFieldName(int aFieldNdx, TRANSLATION aTranslation)
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ SHEET_REF_SUFFIX
Optional sheet field appended to the references of the sheet's symbols.
#define SHEET_MANDATORY_FIELDS
DATABASE_CONNECTION dc(odbcBackend(cs))
wxLogTrace helper definitions.
wxString GetFieldValidationErrorMessage(FIELD_T aFieldId, const wxString &aValue)
Return the error message if aValue is invalid for aFieldId.
Custom text control validator definitions.
Definition of file extensions used in Kicad.