35#include <wx/generic/textdlgg.h>
37#include <wx/wupdlock.h>
73 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
79 wxVector<wxBitmapBundle> images;
82 m_tree->SetImages( images );
87 wxImageList* imageList =
new wxImageList( tree_nosel_bm.GetWidth(), tree_nosel_bm.GetHeight(),
90 imageList->Add( tree_nosel_bm );
93 m_tree->AssignImageList( imageList );
96 sizer->Add(
m_tree, 1, wxEXPAND, wxBORDER_NONE );
131 std::vector<SCH_ITEM*> sheetChildren;
134 for(
SCH_ITEM* aItem : sheetChildren )
142 if( sheetNameBase.IsEmpty() )
145 sheetNameBase = fn.GetName();
149 wxTreeItemId child =
m_tree->AppendItem( aParent, sheetName, 0, 1 );
156 m_tree->SortChildren( aParent );
164 if( eventsWereBound )
176 [&](
const wxTreeItemId& id )
178 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
185 wxTreeItemIdValue cookie;
186 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
188 while( child.IsOk() )
191 child =
m_tree->GetNextChild(
id, cookie );
199 wxTreeItemId parent =
m_tree->GetItemParent(
id );
206 if(
m_tree->IsVisible( parent ) && !
m_tree->IsExpanded( parent ) )
210 if( !
m_tree->IsVisible(
id ) )
211 m_tree->EnsureVisible(
id );
213 m_tree->SetItemBold(
id,
true );
214 m_tree->SetFocusedItem(
id );
218 m_tree->SetItemBold(
id,
false );
221 wxTreeItemIdValue cookie;
222 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
224 while( child.IsOk() )
227 child =
m_tree->GetNextChild(
id, cookie );
233 if( eventsWereBound )
248 wxWindowUpdateLocker updateLock(
this );
252 if( eventsWereBound )
266 std::function<void(
const wxTreeItemId& )> getCollapsedNodes =
267 [&](
const wxTreeItemId& id )
269 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
274 if( itemData &&
m_tree->ItemHasChildren(
id ) && !
m_tree->IsExpanded(
id )
281 wxTreeItemIdValue cookie;
282 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
284 while( child.IsOk() )
286 getCollapsedNodes( child );
287 child =
m_tree->GetNextChild(
id, cookie );
293 if( !aClear && !
m_tree->IsEmpty() )
295 collapsedNodes.clear();
296 getCollapsedNodes(
m_tree->GetRootItem() );
306 std::vector<SCH_SHEET*> topLevelSheets =
m_frame->Schematic().GetTopLevelSheets();
314 m_list.push_back( sheet );
316 wxString sheetNameBase = sheet->GetShownName(
false );
319 if( sheetNameBase.IsEmpty() && sheet->GetScreen() )
321 wxFileName fn( sheet->GetScreen()->GetFileName() );
322 sheetNameBase = fn.GetName();
327 wxTreeItemId topLevelItem =
m_tree->AppendItem( projectRoot, sheetName, 0, 1 );
339 std::function<void(
const wxTreeItemId& )> collapseNodes =
340 [&](
const wxTreeItemId& id )
342 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
347 if(
id != projectRoot && itemData &&
354 wxTreeItemIdValue cookie;
355 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
357 while( child.IsOk() )
359 collapseNodes( child );
360 child =
m_tree->GetNextChild(
id, cookie );
364 collapseNodes( projectRoot );
367 if( eventsWereBound )
382 wxTreeItemId itemSel =
m_tree->GetSelection();
384 if( !itemSel.IsOk() )
392 SetCursor( wxCURSOR_ARROWWAIT );
394 SetCursor( wxCURSOR_ARROW );
404 std::function<void(
const wxTreeItemId& )> updateLabel =
405 [&](
const wxTreeItemId& id )
417 if(
m_tree->GetItemText(
id ) != sheetName )
418 m_tree->SetItemText(
id, sheetName );
421 wxTreeItemId rootId =
m_tree->GetRootItem();
422 updateLabel( rootId );
425 [&](
const wxTreeItemId& id )
427 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
428 wxTreeItemIdValue cookie;
429 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
431 while( child.IsOk() )
433 updateLabel( child );
435 child =
m_tree->GetNextChild(
id, cookie );
445 std::vector<wxString> collapsed;
450 std::function<void(
const wxTreeItemId& )> collect =
451 [&](
const wxTreeItemId& id )
453 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
457 if(
id !=
m_tree->GetRootItem() &&
m_tree->ItemHasChildren(
id )
458 && !
m_tree->IsExpanded(
id ) )
464 wxTreeItemIdValue cookie;
465 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
467 while( child.IsOk() )
470 child =
m_tree->GetNextChild(
id, cookie );
474 collect(
m_tree->GetRootItem() );
496 bool isProjectRoot =
false;
499 aItem =
m_tree->GetSelection();
504 isProjectRoot = (
m_tree->GetRootItem() == aItem.GetID() );
513 ctxMenu.Append(
RENAME,
_(
"Rename" ),
_(
"Change name of this sheet" ) );
519 _(
"Remove this top-level sheet from the project" ) );
523 ctxMenu.AppendSeparator();
527 ctxMenu.Append(
NEW_TOP_LEVEL_SHEET,
_(
"New Top-Level Sheet" ),
_(
"Create a new top-level sheet" ) );
528 ctxMenu.AppendSeparator();
534 int selected = GetPopupMenuSelectionFromUser( ctxMenu );
541 wxTextEntryDialog dlg(
m_frame,
_(
"Enter name for new top-level sheet:" ),
542 _(
"New Top-Level Sheet" ),
545 if( dlg.ShowModal() == wxID_OK )
547 wxString newName = dlg.GetValue();
549 if( !newName.IsEmpty() )
561 wxString filename = newName;
562 filename.Replace(
" ",
"_" );
563 filename = filename.Lower();
565 if( !filename.EndsWith(
".kicad_sch" ) )
566 filename +=
".kicad_sch";
571 int nextPage =
m_frame->Schematic().GetTopLevelSheets().size() + 1;
572 newScreen->
SetPageNumber( wxString::Format(
"%d", nextPage ) );
575 m_frame->Schematic().AddTopLevelSheet( newSheet );
577 commit.
Push(
_(
"Add new top-level sheet" ) );
593 wxString msg = wxString::Format(
_(
"Delete top-level sheet '%s'?\n\nThis cannot be undone." ),
596 if( wxMessageBox( msg,
_(
"Delete Top-Level Sheet" ), wxYES_NO | wxICON_QUESTION,
m_frame ) == wxYES )
599 if(
m_frame->Schematic().GetTopLevelSheets().size() <= 1 )
601 wxMessageBox(
_(
"Cannot delete the last top-level sheet." ),
_(
"Delete Top-Level Sheet" ),
602 wxOK | wxICON_ERROR,
m_frame );
609 if(
m_frame->Schematic().RemoveTopLevelSheet( sheet ) )
611 commit.
Push(
_(
"Delete top-level sheet" ) );
627 msg.Printf(
_(
"Enter page number for sheet path %s" ),
628 ( sheetPath.Length() > 20 ) ? wxS(
" \n" ) + sheetPath + wxT(
": " )
629 : sheetPath + wxT(
": " ) );
631 wxTextEntryDialog dlg(
m_frame, msg,
_(
"Edit Sheet Page Number" ), pageNumber );
633 dlg.SetTextValidator( wxFILTER_ALPHANUMERIC );
649 m_frame->GetScreen()->SetPageNumber( dlg.GetValue() );
650 m_frame->OnPageSettingsChange();
654 commit.
Push( wxS(
"Change sheet page number." ) );
669 m_tree->EditLabel( aItem );
679 wxString newName =
event.GetLabel();
683 if( !newName.IsEmpty() )
696 modifyScreen =
m_frame->Schematic().Root().GetScreen();
714 if( !commit.
Empty() )
715 commit.
Push(
_(
"Renaming sheet" ) );
719 m_frame->OnPageSettingsChange();
737 int hotkey = aKeyStroke.GetKeyCode();
739 int mods = aKeyStroke.GetModifiers();
744 if( wxmods & wxMOD_ALTGR )
749 if( mods & wxMOD_CONTROL )
752 if( mods & wxMOD_ALT )
756 if( mods & wxMOD_SHIFT )
760 if( mods & wxMOD_META )
765 if( mods & wxMOD_WIN )
791 if ( !
m_frame->Schematic().IsValid() )
792 return _(
"Schematic" );
795 wxString projectName =
m_frame->Schematic().Project().GetProjectName();
797 if( projectName.IsEmpty() )
798 projectName =
_(
"Schematic" );
806 return aName + wxT(
" " ) + wxString::Format(
_(
"(page %s)" ), aPage );
811 std::function<void(
const wxTreeItemId& )>
recursiveDescent = [&](
const wxTreeItemId& id )
813 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
820 wxFont font =
m_tree->GetItemFont(
id );
821 font.SetUnderlined( highLighted );
822 m_tree->SetItemFont(
id, font );
825 wxTreeItemIdValue cookie;
826 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
828 while( child.IsOk() )
831 child =
m_tree->GetNextChild(
id, cookie );
841 std::function<void(
const wxTreeItemId& )>
recursiveDescent = [&](
const wxTreeItemId& id )
843 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
850 wxTreeItemIdValue cookie;
851 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
853 while( child.IsOk() )
856 child =
m_tree->GetNextChild(
id, cookie );
872 modifyScreen =
m_frame->Schematic().Root().GetScreen();
890 m_frame->OnPageSettingsChange();
898 wxTreeItemIdValue cookie;
899 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
901 while( child.IsOk() )
904 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 onContextMenu(wxContextMenuEvent &aEvent)
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
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.
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.
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
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.
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.
wxString GetFileName() const
Return the filename corresponding to this sheet.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
void SetName(const wxString &aName)
SCH_SCREEN * GetScreen() const
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Store an SCH_SHEET_PATH of each sheet in hierarchy.
SCH_SHEET_PATH m_SheetPath
TREE_ITEM_DATA(SCH_SHEET_PATH &sheet)
WX_PANEL(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
static void recursiveDescent(wxSizer *aSizer, std::map< int, wxString > &aLabels)
wxIMPLEMENT_ABSTRACT_CLASS(HIERARCHY_TREE, wxTreeCtrl)