54 snapshot.
scale = view->GetScale();
55 snapshot.
center = view->GetCenter();
56 snapshot.
valid =
true;
65 if( !aSnapshot.
valid )
70 view->SetScale( aSnapshot.
scale );
71 view->SetCenter( aSnapshot.
center );
78 std::vector<KIID> kiids;
89 kiids.push_back( item->m_Uuid );
105 if( !selTool || !screen )
110 for(
const KIID& kiid : aKiids )
112 if( item->m_Uuid == kiid )
191 wxLogTrace( wxT(
"KICAD_TABS_DBG" ), wxT(
"activateSymbolTab SelectLibId '%s'" ),
192 m_symbol->GetLibId().Format().wx_str() );
237 const bool isTab = aEvent.GetKeyCode() == WXK_TAB;
238 const bool ctrlOnly = aEvent.ControlDown() && !aEvent.AltDown() && !aEvent.MetaDown();
242 const int keyCode = aEvent.GetKeyCode();
243 const bool isCtrlW = ctrlOnly && !aEvent.ShiftDown()
244 && ( keyCode ==
'W' || keyCode == (
'W' -
'@' ) );
272 for(
unsigned ii = 0; ii < cmd->
GetCount(); ++ii )
281 wxCHECK2_MSG( item != aLiveSymbol,
continue,
282 wxT(
"Live working symbol flagged UR_TRANSIENT in undo/redo list" ) );
308 screen->SetContentModified(
false );
316 for(
const std::unique_ptr<SYMBOL_EDITOR_TAB_CONTEXT>& ctx :
m_tabContexts )
318 if( ctx->GetLibrary() != aLibrary )
323 else if(
SCH_SCREEN* screen = ctx->GetScreen() )
324 screen->SetContentModified(
false );
336 for(
const std::unique_ptr<SYMBOL_EDITOR_TAB_CONTEXT>& ctx :
m_tabContexts )
338 if( ctx->GetTabKey() == aKey )
358 [ctx](
const std::unique_ptr<SYMBOL_EDITOR_TAB_CONTEXT>& aOwned )
360 return aOwned.get() == ctx;
370 const std::vector<EDITOR_TABS_MODEL::ENTRY>& entries =
m_tabsPanel->Model().Entries();
372 if( aIdx < 0 || aIdx >=
static_cast<int>( entries.size() ) )
380 int aUnit,
int aBodyStyle,
bool aAsPreview,
384 const int unit = aUnit > 0 ? aUnit : 1;
385 const int bodyStyle = aBodyStyle > 0 ? aBodyStyle : 1;
390 *aWasCreated =
false;
399 m_tabContexts.push_back( std::make_unique<SYMBOL_EDITOR_TAB_CONTEXT>( aLib, aName, buffer ) );
415 wxString replacedKey;
419 const std::vector<EDITOR_TABS_MODEL::ENTRY>& entries =
m_tabsPanel->Model().Entries();
420 const int previewIdx =
m_tabsPanel->Model().PreviewIndex();
422 if( previewIdx >= 0 && previewIdx <
static_cast<int>( entries.size() ) && entries[previewIdx].key != key )
423 replacedKey = entries[previewIdx].key;
428 if( !replacedKey.empty() )
442 const KIID& aSchematicSymbolUUID,
const wxString& aReference,
443 int aUnit,
int aBodyStyle )
446 const int unit = aUnit > 0 ? aUnit : 1;
447 const int bodyStyle = aBodyStyle > 0 ? aBodyStyle : 1;
455 existing->SetUnit( unit );
456 existing->SetBodyStyle( bodyStyle );
463 m_tabContexts.push_back( std::make_unique<SYMBOL_EDITOR_TAB_CONTEXT>( aSymbol, aScreen, aSchematicSymbolUUID,
481 auto ctx = std::make_unique<SYMBOL_EDITOR_TAB_CONTEXT>( aSymbol, aScreen );
504 wxString msg = wxString::Format(
_(
"Save changes to '%s' before closing?" ), ctx->
GetDisplayName(
true ) );
506 KIDIALOG dlg(
this, msg,
_(
"Confirmation" ), wxYES_NO | wxCANCEL | wxICON_WARNING );
507 dlg.SetYesNoCancelLabels(
_(
"Save" ),
_(
"Discard Changes" ),
_(
"Cancel" ) );
557 [ctx](
const std::unique_ptr<SYMBOL_EDITOR_TAB_CONTEXT>& aOwned )
559 return aOwned.get() == ctx;
568 for(
const std::unique_ptr<SYMBOL_EDITOR_TAB_CONTEXT>& ctx :
m_tabContexts )
570 if( ctx.get() !=
m_activeTab && ctx->IsTransient() && ctx->IsModified() )
581 std::vector<SYMBOL_EDITOR_TAB_CONTEXT*> dirty;
583 for(
const std::unique_ptr<SYMBOL_EDITOR_TAB_CONTEXT>& ctx :
m_tabContexts )
586 if( ctx.get() !=
m_activeTab && ctx->IsTransient() && ctx->IsModified() )
587 dirty.push_back( ctx.get() );
596 wxString msg = wxString::Format(
_(
"Save changes to '%s' before closing?" ), ctx->GetDisplayName() );
598 KIDIALOG dlg(
this, msg,
_(
"Confirmation" ), wxYES_NO | wxCANCEL | wxICON_WARNING );
599 dlg.SetYesNoCancelLabels(
_(
"Save" ),
_(
"Discard Changes" ),
_(
"Cancel" ) );
603 if( answer == wxID_YES )
615 else if( answer != wxID_NO )
652 for(
const std::unique_ptr<SYMBOL_EDITOR_TAB_CONTEXT>& ctx :
m_tabContexts )
691 const wxString unsavedKey =
m_activeTab->GetTabKey();
703 ctx->SetName( newName );
711 wxLogTrace( wxT(
"KICAD_TABS_DBG" ), wxT(
"restoreSymbolTabsFromSettings enter" ) );
718 wxString activeKey =
m_settings->m_ActiveTabKey;
725 wxLogTrace(
"KICAD_TABS",
"Dropping unresolved persisted symbol tab '%s:%s'.", tab.
lib, tab.
name );
734 wxLogTrace(
"KICAD_TABS",
"Dropping persisted symbol tab '%s:%s'; buffer unavailable.", tab.
lib, tab.
name );
749 wxLogTrace( wxT(
"KICAD_TABS_DBG" ), wxT(
"restoreSymbolTabsFromSettings exit (activeIdx=%d)" ), activeIdx );
761 for(
const std::unique_ptr<SYMBOL_EDITOR_TAB_CONTEXT>& ctx :
m_tabContexts )
764 if( ctx->IsTransient() )
768 tab.
lib = ctx->GetLibrary();
769 tab.
name = ctx->GetName();
770 tab.
unit = ctx->GetUnit();
775 const int idx =
m_tabsPanel->FindTab( ctx->GetTabKey() );
776 const std::vector<EDITOR_TABS_MODEL::ENTRY>& entries =
m_tabsPanel->Model().Entries();
778 if( idx >= 0 && idx <
static_cast<int>( entries.size() ) )
779 tab.
preview = entries[idx].preview;
static TOOL_ACTION zoomFitScreen
static TOOL_ACTION selectionClear
Clear the current selection.
UNDO_REDO_CONTAINER m_undoList
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
UNDO_REDO_CONTAINER m_redoList
PROPERTIES_PANEL * m_propertiesPanel
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A base class for most all the KiCad significant classes used in schematics and boards.
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
GUI-free preview/dirty/close state machine.
void MarkModified(const wxString &aKey, bool aModified)
Update the modified flag.
VIEW_SNAPSHOT & ViewSnapshot()
std::vector< KIID > & SavedSelection()
Selection saved as resolved KIIDs, restored after the view is rebuilt.
UNDO_REDO_CONTAINER & RedoList()
UNDO_REDO_CONTAINER & UndoList()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
A logical library item identifier and consists of various portions much like a URI.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Define a library symbol object.
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
A holder to handle information on schematic or board items.
unsigned GetCount() const
void ClearItemsList()
Delete only the list of pickers NOT the picked data itself.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Base class for any item which can be embedded within the SCHEMATIC container class,...
bool m_ShowGraphicsDisabled
EE_RTREE & Items()
Get the full RTree, usually for iterating.
One open symbol tab owning a working LIB_SYMBOL and screen lent to the frame while active.
void ReleaseToFrame()
Hand the working symbol/screen to the frame as the tab becomes active.
LIB_SYMBOL * GetSymbol() const
Observe the working symbol/screen.
const wxString & GetReference() const
static wxString MakeTabKey(const wxString &aLib, const wxString &aName)
De-duplication key for a library:symbol pair.
static wxString MakeInstanceTabKey(const KIID &aSchematicSymbolUUID)
De-duplication key for a placed schematic instance, in a namespace disjoint from library keys.
SCH_SCREEN * GetScreen() const
wxString GetTabKey() const override
Stable identity for persistence and de-duplication.
wxString GetDisplayName(bool aShortForm=false) const override
Short label shown on the tab.
const KIID & GetSchematicSymbolUUID() const
void SetBodyStyle(int aBodyStyle)
bool IsModified() const override
True when the working screen carries unsaved edits.
void AdoptWorkingObjects(LIB_SYMBOL *aSymbol, SCH_SCREEN *aScreen)
Take ownership back on detach, capturing whatever the frame's symbol now points at.
bool IsFromSchematic() const
std::vector< std::unique_ptr< SYMBOL_EDITOR_TAB_CONTEXT > > m_tabContexts
bool m_isSymbolFromSchematic
Flag if the symbol being edited was loaded directly from a schematic.
void restoreSymbolTabsFromSettings()
Recreate tabs from the persisted open-tab list once the libraries have loaded.
bool promptToSaveInactiveInstanceTabs()
Prompt to save each dirty instance (symbol from schematic) tab that is not the active one,...
bool hasDirtyInactiveInstanceTabs() const
True if any non-active instance (schematic) tab has unsaved edits.
bool IsLibraryTreeShown() const override
void RenameSymbolTab(const LIB_ID &aOldId, const LIB_ID &aNewId)
Update the open tab for aOldId, if any, to the renamed symbol aNewId so its label and key track the r...
static void freeTransientUndoCommands(UNDO_REDO_CONTAINER &aList, const LIB_SYMBOL *aLiveSymbol)
Free every command in the list and the UR_TRANSIENT-flagged copies it owns, which the shared deleters...
wxString m_reference
RefDes of the symbol (only valid if symbol was loaded from schematic)
EDITOR_TABS_PANEL * m_tabsPanel
SYMBOL_EDITOR_TAB_CONTEXT * findOrCreateSymbolInstanceTab(LIB_SYMBOL *aSymbol, SCH_SCREEN *aScreen, const KIID &aSchematicSymbolUUID, const wxString &aReference, int aUnit, int aBodyStyle)
Find or create the instance tab for a placed schematic symbol and make it active.
void restoreSymbolSelectionKiids(const std::vector< KIID > &aKiids)
Reselect the items named by aKiids after a reload rebuilt the view.
static void clearTabModifiedState(SYMBOL_EDITOR_TAB_CONTEXT &aContext, EDITOR_TABS_MODEL &aModel)
Clear a tab's dirty state on both the context (read on repaint) and the strip model (read on close),...
void RebuildSymbolUnitAndBodyStyleLists()
void OnTabCharHook(wxKeyEvent &aEvent)
Cycle symbol tabs from the char hook, since GTK cannot register WXK_TAB as an accelerator.
LIB_SYMBOL_LIBRARY_MANAGER * m_libMgr
bool IsSymbolAlias() const
SYMBOL_EDITOR_SETTINGS * m_settings
void dropSymbolTabContext(const wxString &aKey)
Drop the inactive context for aKey from m_tabContexts, freeing its undo/redo.
int m_unit
The unit number to edit and show.
bool IsSymbolFromLegacyLibrary() const
bool IsSymbolFromSchematic() const
void SetScreen(BASE_SCREEN *aScreen) override
SYMBOL_EDITOR_TAB_CONTEXT * m_activeTab
SYMBOL_EDITOR_SETTINGS * GetSettings() const
SCH_SCREEN * m_dummyScreen
Helper screen used when no symbol is loaded.
KIID m_schematicSymbolUUID
EDITOR_TAB_CONTEXT::VIEW_SNAPSHOT captureSymbolViewSnapshot() const
Capture the current view zoom/center for the active tab's snapshot.
void restoreSymbolViewSnapshot(const EDITOR_TAB_CONTEXT::VIEW_SNAPSHOT &aSnapshot)
Restore a previously captured view zoom/center.
bool m_silentSymbolTabClose
While true, promptAndCloseSymbolTab() skips the unsaved-changes dialog.
SYMBOL_EDITOR_TAB_CONTEXT * findOrCreateSymbolTab(const wxString &aLib, const wxString &aName, int aUnit, int aBodyStyle, bool aAsPreview, bool *aWasCreated=nullptr)
Open aName from aLib in a tab, creating it when absent, and return the activated context.
SYMBOL_EDITOR_TAB_CONTEXT * symbolTabContextForKey(const wxString &aKey) const
Resolve the tab context for a tab key, or nullptr.
void storeSymbolTabsToSettings()
Write the current tab set into the editor settings for the next session.
void UpdateSymbolMsgPanelInfo()
Display the documentation of the selected symbol.
int m_bodyStyle
Show the normal shape (m_bodyStyle <= 1) or the DeMorgan converted shape (m_bodyStyle > 1)
LIB_TREE * GetLibTree() const override
SYMBOL_EDITOR_TAB_CONTEXT * CreateUnsavedSymbolTab(LIB_SYMBOL *aSymbol, SCH_SCREEN *aScreen)
Open a new tab over a transient working symbol and screen and make it active.
bool promptAndCloseSymbolTab(int aIdx)
Prompt for unsaved changes on the tab and drop its context.
SYMBOL_TREE_PANE * m_treePane
std::vector< KIID > captureSymbolSelectionKiids() const
Capture the KIIDs of the current selection for the active tab's snapshot.
void closeSymbolTab(const LIB_ID &aLibId)
Close the open tab for aLibId, if any, without prompting and leaving the other tabs open.
bool saveCurrentSymbol()
Save the current symbol.
void clearSymbolTabsModifiedForLibrary(const wxString &aLibrary)
Clear the unsaved-edits flag on every tab in a saved library so its dirty indicator clears.
SYMBOL_EDITOR_TAB_CONTEXT * symbolTabContextForIndex(int aIdx) const
Resolve the tab context for a panel tab index, or nullptr.
static void clearSymbolTabUndoRedo(SYMBOL_EDITOR_TAB_CONTEXT &aContext)
Free a detached context's undo/redo, which the frame's own teardown path never reaches.
void detachActiveSymbolTab()
Snapshot the active tab's view and selection into its context without deleting the document.
void activateSymbolTab(SYMBOL_EDITOR_TAB_CONTEXT *aContext)
Make aContext the active tab, borrowing its working symbol, undo/redo, view and selection,...
void closeAllSymbolTabsSilently()
Close every tab without prompting and return the frame to the empty state.
A holder to handle a list of undo (or redo) commands.
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
#define UR_TRANSIENT
indicates the item is owned by the undo/redo stack
View snapshot captured on detach, restored on activate.
One persisted open editor tab, restored on the next session.