35#include <wx/generic/textdlgg.h>
37#include <wx/wupdlock.h>
72 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
78 wxVector<wxBitmapBundle> images;
81 m_tree->SetImages( images );
85 wxBitmap tree_nosel_bm(
KiBitmap( BITMAPS::tree_nosel ) );
86 wxImageList* imageList =
new wxImageList( tree_nosel_bm.GetWidth(), tree_nosel_bm.GetHeight(),
89 imageList->Add( tree_nosel_bm );
90 imageList->Add(
KiBitmap( BITMAPS::tree_sel ) );
92 m_tree->AssignImageList( imageList );
95 sizer->Add(
m_tree, 1, wxEXPAND, wxBORDER_NONE );
128 std::vector<SCH_ITEM*> sheetChildren;
131 for(
SCH_ITEM* aItem : sheetChildren )
138 wxTreeItemId child =
m_tree->AppendItem( aParent, sheetName, 0, 1 );
145 m_tree->SortChildren( aParent );
153 if( eventsWereBound )
164 [&](
const wxTreeItemId& id )
166 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
172 wxTreeItemId parent =
m_tree->GetItemParent(
id );
174 if( parent.IsOk() && !
m_tree->IsExpanded( parent ) )
177 if( !
m_tree->IsVisible(
id ) )
178 m_tree->EnsureVisible(
id );
180 m_tree->SetItemBold(
id,
true );
181 m_tree->SetFocusedItem(
id );
185 m_tree->SetItemBold(
id,
false );
188 wxTreeItemIdValue cookie;
189 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
191 while( child.IsOk() )
194 child =
m_tree->GetNextChild(
id, cookie );
200 if( eventsWereBound )
214 wxWindowUpdateLocker updateLock(
this );
218 if( eventsWereBound )
231 std::function<void(
const wxTreeItemId& )> getCollapsedNodes =
232 [&](
const wxTreeItemId& id )
234 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
238 if(
m_tree->ItemHasChildren(
id ) && !
m_tree->IsExpanded(
id )
245 wxTreeItemIdValue cookie;
246 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
248 while( child.IsOk() )
250 getCollapsedNodes( child );
251 child =
m_tree->GetNextChild(
id, cookie );
257 if( !aClear && !
m_tree->IsEmpty() )
259 collapsedNodes.clear();
260 getCollapsedNodes(
m_tree->GetRootItem() );
276 std::function<void(
const wxTreeItemId& )> collapseNodes =
277 [&](
const wxTreeItemId& id )
279 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
291 wxTreeItemIdValue cookie;
292 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
294 while( child.IsOk() )
296 collapseNodes( child );
297 child =
m_tree->GetNextChild(
id, cookie );
301 collapseNodes( root );
304 if( eventsWereBound )
318 wxTreeItemId itemSel =
m_tree->GetSelection();
320 if( !itemSel.IsOk() )
328 SetCursor( wxCURSOR_ARROWWAIT );
330 SetCursor( wxCURSOR_ARROW );
340 std::function<void(
const wxTreeItemId& )> updateLabel =
341 [&](
const wxTreeItemId& id )
344 SCH_SHEET* sheet = itemData->m_SheetPath.Last();
347 itemData->m_SheetPath.GetPageNumber() );
349 if(
m_tree->GetItemText(
id ) != sheetName )
350 m_tree->SetItemText(
id, sheetName );
353 wxTreeItemId rootId =
m_tree->GetRootItem();
354 updateLabel( rootId );
357 [&](
const wxTreeItemId& id )
359 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
360 wxTreeItemIdValue cookie;
361 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
363 while( child.IsOk() )
365 updateLabel( child );
367 child =
m_tree->GetNextChild(
id, cookie );
377 std::vector<wxString> collapsed;
382 std::function<void(
const wxTreeItemId& )> collect =
383 [&](
const wxTreeItemId& id )
385 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
389 if(
id !=
m_tree->GetRootItem() &&
m_tree->ItemHasChildren(
id )
390 && !
m_tree->IsExpanded(
id ) )
396 wxTreeItemIdValue cookie;
397 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
399 while( child.IsOk() )
402 child =
m_tree->GetNextChild(
id, cookie );
406 collect(
m_tree->GetRootItem() );
423 aItem =
m_tree->GetSelection();
432 if(
m_tree->GetRootItem() != aItem.GetID() )
434 ctxMenu.Append(
RENAME,
_(
"Rename" ),
_(
"Change name of this sheet" ) );
437 ctxMenu.AppendSeparator();
443 int selected = GetPopupMenuSelectionFromUser( ctxMenu );
453 msg.Printf(
_(
"Enter page number for sheet path %s" ),
454 ( sheetPath.Length() > 20 ) ? wxS(
" \n" ) + sheetPath + wxT(
": " )
455 : sheetPath + wxT(
": " ) );
457 wxTextEntryDialog dlg(
m_frame, msg,
_(
"Edit Sheet Page Number" ), pageNumber );
459 dlg.SetTextValidator( wxFILTER_ALPHANUMERIC );
477 commit.
Push( wxS(
"Change sheet page number." ) );
492 m_tree->EditLabel( aItem );
502 wxString newName =
event.GetLabel();
506 if( !newName.IsEmpty() )
524 if( !commit.
Empty() )
525 commit.
Push(
_(
"Renaming sheet" ) );
547 int hotkey = aKeyStroke.GetKeyCode();
549 if( aKeyStroke.GetModifiers() & wxMOD_CONTROL )
552 if( aKeyStroke.GetModifiers() & wxMOD_ALT )
555 if( aKeyStroke.GetModifiers() & wxMOD_SHIFT )
589 return aName + wxT(
" " ) + wxString::Format(
_(
"(page %s)" ), aPage );
594 std::function<void(
const wxTreeItemId& )>
recursiveDescent = [&](
const wxTreeItemId& id )
596 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
602 wxFont font =
m_tree->GetItemFont(
id );
603 font.SetUnderlined( highLighted );
604 m_tree->SetItemFont(
id, font );
607 wxTreeItemIdValue cookie;
608 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
610 while( child.IsOk() )
613 child =
m_tree->GetNextChild(
id, cookie );
623 std::function<void(
const wxTreeItemId& )>
recursiveDescent = [&](
const wxTreeItemId& id )
625 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
648 wxTreeItemIdValue cookie;
649 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
651 while( child.IsOk() )
654 child =
m_tree->GetNextChild(
id, cookie );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
static TOOL_ACTION expandAll
static TOOL_ACTION collapseAll
void SetPageNumber(const wxString &aPageNumber)
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
void onRightClick(wxTreeItemId aItem)
void UpdateHierarchyTree(bool aClear=false)
Update the hierarchical tree of the schematic.
void onSelectSheetPath(wxTreeEvent &aEvent)
Open the selected sheet and display the corresponding screen when a tree item is selected.
void UpdateLabelsHierarchyTree()
Update the labels of the hierarchical tree of the schematic.
wxString formatPageString(const wxString &aName, const wxString &aPage)
void UpdateHierarchySelection()
Updates the tree's selection to match current page.
HIERARCHY_PANE(SCH_EDIT_FRAME *aParent)
std::set< wxString > m_collapsedPaths
void onCharHook(wxKeyEvent &aKeyStroke)
void renameIdenticalSheets(const SCH_SHEET_PATH &renamedSheet, const wxString newName, SCH_COMMIT *commit)
Rename all sheets in a hierarchial desing which has the same source renamed sheet.
void buildHierarchyTree(SCH_SHEET_PATH *aList, const wxTreeItemId &aParent)
Create the hierarchical tree of the schematic.
void onTreeItemRightClick(wxTreeEvent &aEvent)
std::vector< wxString > GetCollapsedPaths() const
Returns a list of sheet paths for nodes that are currently collapsed.
void onTreeEditFinished(wxTreeEvent &event)
void setIdenticalSheetsHighlighted(const SCH_SHEET_PATH &path, bool highLighted=true)
When renaming the sheets in tree it is helpful to highlight the identical sheets which got renamed by...
Navigation hierarchy tree control.
int OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2) override
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
The project local settings are things that are attached to a particular project, but also might be pa...
std::vector< wxString > m_SchHierarchyCollapsed
Collapsed nodes in the schematic hierarchy navigator.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
static TOOL_ACTION changeSheet
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void OnPageSettingsChange() override
Called when modifying the page settings.
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Base class for any item which can be embedded within the SCHEMATIC container class,...
void GetSheets(std::vector< SCH_ITEM * > *aItems) const
Similar to Items().OfType( SCH_SHEET_T ), but return the sheets in a deterministic order (L-R,...
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
bool HasPath(const KIID_PATH &aPath) const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
const SCH_SHEET * GetSheet(unsigned aIndex) const
int ComparePageNum(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare sheets by their page number.
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
Return the sheet path in a human readable form made from the sheet names.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare if this is the same sheet path as aSheetPathToTest.
wxString GetPageNumber() const
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void clear()
Forwarded method from std::vector.
size_t size() const
Forwarded method from std::vector.
void pop_back()
Forwarded method from std::vector.
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.
void SetName(const wxString &aName)
SCH_SCREEN * GetScreen() const
wxString GetShownName(bool aAllowExtraText) const
Store an SCH_SHEET_PATH of each sheet in hierarchy.
SCH_SHEET_PATH m_SheetPath
TREE_ITEM_DATA(SCH_SHEET_PATH &sheet)
static void recursiveDescent(wxSizer *aSizer, std::map< int, wxString > &aLabels)
wxIMPLEMENT_ABSTRACT_CLASS(HIERARCHY_TREE, wxTreeCtrl)