35#include <wx/generic/textdlgg.h>
37#include <wx/wupdlock.h>
73 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
77 wxVector<wxBitmapBundle> images;
80 m_tree->SetImages( images );
82 sizer->Add(
m_tree, 1, wxEXPAND, wxBORDER_NONE );
117 std::vector<SCH_ITEM*> sheetChildren;
120 for(
SCH_ITEM* aItem : sheetChildren )
128 if( sheetNameBase.IsEmpty() )
131 sheetNameBase = fn.GetName();
135 wxTreeItemId child =
m_tree->AppendItem( aParent, sheetName, 0, 1 );
142 m_tree->SortChildren( aParent );
150 if( eventsWereBound )
162 [&](
const wxTreeItemId& id )
164 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
171 wxTreeItemIdValue cookie;
172 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
174 while( child.IsOk() )
177 child =
m_tree->GetNextChild(
id, cookie );
185 wxTreeItemId parent =
m_tree->GetItemParent(
id );
192 if(
m_tree->IsVisible( parent ) && !
m_tree->IsExpanded( parent ) )
196 if( !
m_tree->IsVisible(
id ) )
197 m_tree->EnsureVisible(
id );
199 m_tree->SetItemBold(
id,
true );
200 m_tree->SetFocusedItem(
id );
204 m_tree->SetItemBold(
id,
false );
207 wxTreeItemIdValue cookie;
208 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
210 while( child.IsOk() )
213 child =
m_tree->GetNextChild(
id, cookie );
219 if( eventsWereBound )
234 wxWindowUpdateLocker updateLock(
this );
238 if( !
m_frame->Schematic().HasHierarchy() )
243 if( eventsWereBound )
257 std::function<void(
const wxTreeItemId& )> getCollapsedNodes =
258 [&](
const wxTreeItemId& id )
260 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
265 if( itemData &&
m_tree->ItemHasChildren(
id ) && !
m_tree->IsExpanded(
id )
272 wxTreeItemIdValue cookie;
273 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
275 while( child.IsOk() )
277 getCollapsedNodes( child );
278 child =
m_tree->GetNextChild(
id, cookie );
284 if( !aClear && !
m_tree->IsEmpty() )
286 collapsedNodes.clear();
287 getCollapsedNodes(
m_tree->GetRootItem() );
297 std::vector<SCH_SHEET*> topLevelSheets =
m_frame->Schematic().GetTopLevelSheets();
305 m_list.push_back( sheet );
307 wxString sheetNameBase = sheet->GetShownName(
false );
310 if( sheetNameBase.IsEmpty() && sheet->GetScreen() )
312 wxFileName fn( sheet->GetScreen()->GetFileName() );
313 sheetNameBase = fn.GetName();
318 wxTreeItemId topLevelItem =
m_tree->AppendItem( projectRoot, sheetName, 0, 1 );
330 std::function<void(
const wxTreeItemId& )> collapseNodes =
331 [&](
const wxTreeItemId& id )
333 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
338 if(
id != projectRoot && itemData &&
345 wxTreeItemIdValue cookie;
346 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
348 while( child.IsOk() )
350 collapseNodes( child );
351 child =
m_tree->GetNextChild(
id, cookie );
355 collapseNodes( projectRoot );
358 if( eventsWereBound )
373 wxTreeItemId itemSel =
m_tree->GetSelection();
375 if( !itemSel.IsOk() )
383 SetCursor( wxCURSOR_ARROWWAIT );
385 SetCursor( wxCURSOR_ARROW );
395 std::function<void(
const wxTreeItemId& )> updateLabel =
396 [&](
const wxTreeItemId& id )
408 if(
m_tree->GetItemText(
id ) != sheetName )
409 m_tree->SetItemText(
id, sheetName );
412 wxTreeItemId rootId =
m_tree->GetRootItem();
413 updateLabel( rootId );
416 [&](
const wxTreeItemId& id )
418 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
419 wxTreeItemIdValue cookie;
420 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
422 while( child.IsOk() )
424 updateLabel( child );
426 child =
m_tree->GetNextChild(
id, cookie );
436 std::vector<wxString> collapsed;
441 std::function<void(
const wxTreeItemId& )> collect =
442 [&](
const wxTreeItemId& id )
444 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
448 if(
id !=
m_tree->GetRootItem() &&
m_tree->ItemHasChildren(
id )
449 && !
m_tree->IsExpanded(
id ) )
455 wxTreeItemIdValue cookie;
456 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
458 while( child.IsOk() )
461 child =
m_tree->GetNextChild(
id, cookie );
465 collect(
m_tree->GetRootItem() );
487 bool isProjectRoot =
false;
490 aItem =
m_tree->GetSelection();
495 isProjectRoot = (
m_tree->GetRootItem() == aItem.GetID() );
504 ctxMenu.Append(
RENAME,
_(
"Rename" ),
_(
"Change name of this sheet" ) );
510 _(
"Remove this top-level sheet from the project" ) );
514 ctxMenu.AppendSeparator();
518 ctxMenu.Append(
NEW_TOP_LEVEL_SHEET,
_(
"New Top-Level Sheet" ),
_(
"Create a new top-level sheet" ) );
519 ctxMenu.AppendSeparator();
525 int selected = GetPopupMenuSelectionFromUser( ctxMenu );
532 wxTextEntryDialog dlg(
m_frame,
_(
"Enter name for new top-level sheet:" ),
533 _(
"New Top-Level Sheet" ),
536 if( dlg.ShowModal() == wxID_OK )
538 wxString newName = dlg.GetValue();
540 if( !newName.IsEmpty() )
552 wxString filename = newName;
553 filename.Replace(
" ",
"_" );
554 filename = filename.Lower();
556 if( !filename.EndsWith(
".kicad_sch" ) )
557 filename +=
".kicad_sch";
562 int nextPage =
m_frame->Schematic().GetTopLevelSheets().size() + 1;
563 newScreen->
SetPageNumber( wxString::Format(
"%d", nextPage ) );
566 m_frame->Schematic().AddTopLevelSheet( newSheet );
568 commit.
Push(
_(
"Add new top-level sheet" ) );
584 wxString msg = wxString::Format(
_(
"Delete top-level sheet '%s'?\n\nThis cannot be undone." ),
587 if( wxMessageBox( msg,
_(
"Delete Top-Level Sheet" ), wxYES_NO | wxICON_QUESTION,
m_frame ) == wxYES )
590 if(
m_frame->Schematic().GetTopLevelSheets().size() <= 1 )
592 wxMessageBox(
_(
"Cannot delete the last top-level sheet." ),
_(
"Delete Top-Level Sheet" ),
593 wxOK | wxICON_ERROR,
m_frame );
600 if(
m_frame->Schematic().RemoveTopLevelSheet( sheet ) )
602 commit.
Push(
_(
"Delete top-level sheet" ) );
618 msg.Printf(
_(
"Enter page number for sheet path %s" ),
619 ( sheetPath.Length() > 20 ) ? wxS(
" \n" ) + sheetPath + wxT(
": " )
620 : sheetPath + wxT(
": " ) );
622 wxTextEntryDialog dlg(
m_frame, msg,
_(
"Edit Sheet Page Number" ), pageNumber );
624 dlg.SetTextValidator( wxFILTER_ALPHANUMERIC );
640 m_frame->GetScreen()->SetPageNumber( dlg.GetValue() );
641 m_frame->OnPageSettingsChange();
645 commit.
Push( wxS(
"Change sheet page number." ) );
660 m_tree->EditLabel( aItem );
670 wxString newName =
event.GetLabel();
674 if( !newName.IsEmpty() )
687 modifyScreen =
m_frame->Schematic().Root().GetScreen();
705 if( !commit.
Empty() )
706 commit.
Push(
_(
"Renaming sheet" ) );
710 m_frame->OnPageSettingsChange();
728 int hotkey = aKeyStroke.GetKeyCode();
730 int mods = aKeyStroke.GetModifiers();
735 if( wxmods & wxMOD_ALTGR )
740 if( mods & wxMOD_CONTROL )
743 if( mods & wxMOD_ALT )
747 if( mods & wxMOD_SHIFT )
751 if( mods & wxMOD_META )
756 if( mods & wxMOD_WIN )
782 if ( !
m_frame->Schematic().IsValid() )
783 return _(
"Schematic" );
786 wxString projectName =
m_frame->Schematic().Project().GetProjectName();
788 if( projectName.IsEmpty() )
789 projectName =
_(
"Schematic" );
797 return aName + wxT(
" " ) + wxString::Format(
_(
"(page %s)" ), aPage );
802 std::function<void(
const wxTreeItemId& )>
recursiveDescent = [&](
const wxTreeItemId& id )
804 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
811 wxFont font =
m_tree->GetItemFont(
id );
812 font.SetUnderlined( highLighted );
813 m_tree->SetItemFont(
id, font );
816 wxTreeItemIdValue cookie;
817 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
819 while( child.IsOk() )
822 child =
m_tree->GetNextChild(
id, cookie );
832 std::function<void(
const wxTreeItemId& )>
recursiveDescent = [&](
const wxTreeItemId& id )
834 wxCHECK_RET(
id.IsOk(), wxT(
"Invalid tree item" ) );
841 wxTreeItemIdValue cookie;
842 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
844 while( child.IsOk() )
847 child =
m_tree->GetNextChild(
id, cookie );
863 modifyScreen =
m_frame->Schematic().Root().GetScreen();
881 m_frame->OnPageSettingsChange();
889 wxTreeItemIdValue cookie;
890 wxTreeItemId child =
m_tree->GetFirstChild(
id, cookie );
892 while( child.IsOk() )
895 child =
m_tree->GetNextChild(
id, cookie );
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 wxString &aVariantName=wxEmptyString) 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.
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 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.
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)