KiCad PCB EDA Suite
Loading...
Searching...
No Matches
hierarchy_pane.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2008 Wayne Stambaugh <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <bitmaps.h>
27#include <sch_edit_frame.h>
28#include <sch_commit.h>
29#include <tool/tool_manager.h>
30#include <tools/sch_actions.h>
31#include <hierarchy_pane.h>
33#include <kiface_base.h>
34#include <wx/object.h>
35#include <wx/generic/textdlgg.h>
36#include <wx/menu.h>
37#include <wx/wupdlock.h>
38
42class TREE_ITEM_DATA : public wxTreeItemData
43{
44public:
46
47 TREE_ITEM_DATA( SCH_SHEET_PATH& sheet ) : wxTreeItemData(), m_SheetPath( sheet ) {}
48};
49
50
51// Need to use wxRTTI macros in order for OnCompareItems to work properly
52// See: https://docs.wxwidgets.org/3.1/classwx_tree_ctrl.html#ab90a465793c291ca7aa827a576b7d146
54
55
56int HIERARCHY_TREE::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 )
57{
58 SCH_SHEET_PATH* item1Path = &static_cast<TREE_ITEM_DATA*>( GetItemData( item1 ) )->m_SheetPath;
59 SCH_SHEET_PATH* item2Path = &static_cast<TREE_ITEM_DATA*>( GetItemData( item2 ) )->m_SheetPath;
60
61 return item1Path->ComparePageNum( *item2Path );
62}
63
64
66 WX_PANEL( aParent )
67{
68 wxASSERT( dynamic_cast<SCH_EDIT_FRAME*>( aParent ) );
69
70 m_frame = aParent;
71
72 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
73 SetSizer( sizer );
74 m_tree = new HIERARCHY_TREE( this );
75
76#ifdef __WXMAC__
77 // HiDPI-aware API; will be generally available in wxWidgets 3.4
78 wxVector<wxBitmapBundle> images;
79 images.push_back( KiBitmapBundle( BITMAPS::tree_nosel ) );
80 images.push_back( KiBitmapBundle( BITMAPS::tree_sel ) );
81 m_tree->SetImages( images );
82#else
83 // Make an image list containing small icons
84 // All icons are expected having the same size.
85 wxBitmap tree_nosel_bm( KiBitmap( BITMAPS::tree_nosel ) );
86 wxImageList* imageList = new wxImageList( tree_nosel_bm.GetWidth(), tree_nosel_bm.GetHeight(),
87 true, 2 );
88
89 imageList->Add( tree_nosel_bm );
90 imageList->Add( KiBitmap( BITMAPS::tree_sel ) );
91
92 m_tree->AssignImageList( imageList );
93#endif
94
95 sizer->Add( m_tree, 1, wxEXPAND, wxBORDER_NONE );
96
97 m_events_bound = false;
98
99 PROJECT_LOCAL_SETTINGS& localSettings = m_frame->Prj().GetLocalSettings();
100
101 for( const wxString& path : localSettings.m_SchHierarchyCollapsed )
102 m_collapsedPaths.insert( path );
103
105
106 // Enable selection events
107 Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this );
108 Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this );
109 Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this );
110 Bind( wxEVT_CHAR_HOOK, &HIERARCHY_PANE::onCharHook, this );
111 m_tree->Bind( wxEVT_TREE_END_LABEL_EDIT, &HIERARCHY_PANE::onTreeEditFinished, this );
112 m_events_bound = true;
113}
114
115
117{
118 Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this );
119 Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this );
120 Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this );
121 Unbind( wxEVT_CHAR_HOOK, &HIERARCHY_PANE::onCharHook, this );
122 m_tree->Unbind( wxEVT_TREE_END_LABEL_EDIT, &HIERARCHY_PANE::onTreeEditFinished, this );
123}
124
125
126void HIERARCHY_PANE::buildHierarchyTree( SCH_SHEET_PATH* aList, const wxTreeItemId& aParent )
127{
128 std::vector<SCH_ITEM*> sheetChildren;
129 aList->LastScreen()->GetSheets( &sheetChildren );
130
131 for( SCH_ITEM* aItem : sheetChildren )
132 {
133 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
134 aList->push_back( sheet );
135
136 wxString sheetNameBase = sheet->GetField( FIELD_T::SHEET_NAME )->GetShownText( false );
137 wxString sheetName = formatPageString( sheetNameBase, aList->GetPageNumber() );
138 wxTreeItemId child = m_tree->AppendItem( aParent, sheetName, 0, 1 );
139 m_tree->SetItemData( child, new TREE_ITEM_DATA( *aList ) );
140
141 buildHierarchyTree( aList, child );
142 aList->pop_back();
143 }
144
145 m_tree->SortChildren( aParent );
146}
147
148
150{
151 bool eventsWereBound = m_events_bound;
152
153 if( eventsWereBound )
154 {
155 // Disable selection events
156 Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this );
157 Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this );
158 Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this );
159
160 m_events_bound = false;
161 }
162
163 std::function<void( const wxTreeItemId& )> recursiveDescent =
164 [&]( const wxTreeItemId& id )
165 {
166 wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) );
167
168 TREE_ITEM_DATA* itemData = static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( id ) );
169
170 if( itemData->m_SheetPath == m_frame->GetCurrentSheet() )
171 {
172 wxTreeItemId parent = m_tree->GetItemParent( id );
173
174 if( parent.IsOk() && !m_tree->IsExpanded( parent ) )
175 m_tree->Expand( parent );
176
177 if( !m_tree->IsVisible( id ) )
178 m_tree->EnsureVisible( id );
179
180 m_tree->SetItemBold( id, true );
181 m_tree->SetFocusedItem( id );
182 }
183 else
184 {
185 m_tree->SetItemBold( id, false );
186 }
187
188 wxTreeItemIdValue cookie;
189 wxTreeItemId child = m_tree->GetFirstChild( id, cookie );
190
191 while( child.IsOk() )
192 {
193 recursiveDescent( child );
194 child = m_tree->GetNextChild( id, cookie );
195 }
196 };
197
198 recursiveDescent( m_tree->GetRootItem() );
199
200 if( eventsWereBound )
201 {
202 // Enable selection events
203 Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this );
204 Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this );
205 Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this );
206
207 m_events_bound = true;
208 }
209}
210
211
213{
214 wxWindowUpdateLocker updateLock( this );
215
216 bool eventsWereBound = m_events_bound;
217
218 if( eventsWereBound )
219 {
220 // Disable selection events
221 Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this );
222 Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this );
223 Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this );
224
225 m_events_bound = false;
226 }
227
228 SCH_SHEET_LIST hierarchy = m_frame->Schematic().Hierarchy();
229 std::set<wxString> collapsedNodes = m_collapsedPaths;
230
231 std::function<void( const wxTreeItemId& )> getCollapsedNodes =
232 [&]( const wxTreeItemId& id )
233 {
234 wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) );
235
236 TREE_ITEM_DATA* itemData = static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( id ) );
237
238 if( m_tree->ItemHasChildren( id ) && !m_tree->IsExpanded( id )
239 && hierarchy.HasPath( itemData->m_SheetPath.Path() ) )
240 {
241 collapsedNodes.emplace( itemData->m_SheetPath.PathAsString() );
242 return;
243 }
244
245 wxTreeItemIdValue cookie;
246 wxTreeItemId child = m_tree->GetFirstChild( id, cookie );
247
248 while( child.IsOk() )
249 {
250 getCollapsedNodes( child );
251 child = m_tree->GetNextChild( id, cookie );
252 }
253 };
254
255 // If we are clearing the tree, don't try to get collapsed nodes as they
256 // might be deleted
257 if( !aClear && !m_tree->IsEmpty() )
258 {
259 collapsedNodes.clear();
260 getCollapsedNodes( m_tree->GetRootItem() );
261 }
262
263 m_list.clear();
264 m_list.push_back( &m_frame->Schematic().Root() );
265
266 m_tree->DeleteAllItems();
267
268 wxTreeItemId root = m_tree->AddRoot( getRootString(), 0, 1 );
269 m_tree->SetItemData( root, new TREE_ITEM_DATA( m_list ) );
270
271 buildHierarchyTree( &m_list, root );
273
274 m_tree->ExpandAll();
275
276 std::function<void( const wxTreeItemId& )> collapseNodes =
277 [&]( const wxTreeItemId& id )
278 {
279 wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) );
280
281 TREE_ITEM_DATA* itemData =
282 static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( id ) );
283
284 if( id != root &&
285 collapsedNodes.find( itemData->m_SheetPath.PathAsString() ) != collapsedNodes.end() )
286 {
287 m_tree->Collapse( id );
288 return;
289 }
290
291 wxTreeItemIdValue cookie;
292 wxTreeItemId child = m_tree->GetFirstChild( id, cookie );
293
294 while( child.IsOk() )
295 {
296 collapseNodes( child );
297 child = m_tree->GetNextChild( id, cookie );
298 }
299 };
300
301 collapseNodes( root );
302 m_collapsedPaths = std::move( collapsedNodes );
303
304 if( eventsWereBound )
305 {
306 // Enable selection events
307 Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this );
308 Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this );
309 Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this );
310
311 m_events_bound = true;
312 }
313}
314
315
316void HIERARCHY_PANE::onSelectSheetPath( wxTreeEvent& aEvent )
317{
318 wxTreeItemId itemSel = m_tree->GetSelection();
319
320 if( !itemSel.IsOk() )
321 return;
322
323 TREE_ITEM_DATA* itemData = static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( itemSel ) );
324
325 if( !itemData )
326 return;
327
328 SetCursor( wxCURSOR_ARROWWAIT );
329 m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &itemData->m_SheetPath );
330 SetCursor( wxCURSOR_ARROW );
331}
332
333
335{
336 // Update the labels of the hierarchical tree of the schematic.
337 // Must be called only for an up to date tree, to update displayed labels after
338 // a sheet name or a sheet number change.
339
340 std::function<void( const wxTreeItemId& )> updateLabel =
341 [&]( const wxTreeItemId& id )
342 {
343 auto* itemData = static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( id ) );
344 SCH_SHEET* sheet = itemData->m_SheetPath.Last();
345 wxString sheetNameBase = sheet->GetField( FIELD_T::SHEET_NAME )->GetShownText( false );
346 wxString sheetName = formatPageString( sheetNameBase,
347 itemData->m_SheetPath.GetPageNumber() );
348
349 if( m_tree->GetItemText( id ) != sheetName )
350 m_tree->SetItemText( id, sheetName );
351 };
352
353 wxTreeItemId rootId = m_tree->GetRootItem();
354 updateLabel( rootId );
355
356 std::function<void( const wxTreeItemId& )> recursiveDescent =
357 [&]( const wxTreeItemId& id )
358 {
359 wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) );
360 wxTreeItemIdValue cookie;
361 wxTreeItemId child = m_tree->GetFirstChild( id, cookie );
362
363 while( child.IsOk() )
364 {
365 updateLabel( child );
366 recursiveDescent( child );
367 child = m_tree->GetNextChild( id, cookie );
368 }
369 };
370
371 recursiveDescent( rootId );
372}
373
374
375std::vector<wxString> HIERARCHY_PANE::GetCollapsedPaths() const
376{
377 std::vector<wxString> collapsed;
378
379 if( m_tree->IsEmpty() )
380 return collapsed;
381
382 std::function<void( const wxTreeItemId& )> collect =
383 [&]( const wxTreeItemId& id )
384 {
385 wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) );
386
387 TREE_ITEM_DATA* itemData = static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( id ) );
388
389 if( id != m_tree->GetRootItem() && m_tree->ItemHasChildren( id )
390 && !m_tree->IsExpanded( id ) )
391 {
392 collapsed.push_back( itemData->m_SheetPath.PathAsString() );
393 return;
394 }
395
396 wxTreeItemIdValue cookie;
397 wxTreeItemId child = m_tree->GetFirstChild( id, cookie );
398
399 while( child.IsOk() )
400 {
401 collect( child );
402 child = m_tree->GetNextChild( id, cookie );
403 }
404 };
405
406 collect( m_tree->GetRootItem() );
407 return collapsed;
408}
409
410
411void HIERARCHY_PANE::onTreeItemRightClick( wxTreeEvent& aEvent )
412{
413 onRightClick( aEvent.GetItem() );
414}
415
416
417void HIERARCHY_PANE::onRightClick( wxTreeItemId aItem )
418{
419 wxMenu ctxMenu;
420 TREE_ITEM_DATA* itemData = nullptr;
421
422 if( !aItem.IsOk() )
423 aItem = m_tree->GetSelection();
424
425 if( aItem.IsOk() )
426 itemData = static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( aItem ) );
427
428 if( itemData )
429 {
430 ctxMenu.Append( EDIT_PAGE_NUMBER, _( "Edit Page Number" ) );
431 // The root item cannot be renamed
432 if( m_tree->GetRootItem() != aItem.GetID() )
433 {
434 ctxMenu.Append( RENAME, _( "Rename" ), _( "Change name of this sheet" ) );
435 }
436
437 ctxMenu.AppendSeparator();
438 }
439 ctxMenu.Append( EXPAND_ALL, ACTIONS::expandAll.GetMenuItem() );
440 ctxMenu.Append( COLLAPSE_ALL, ACTIONS::collapseAll.GetMenuItem() );
441
442
443 int selected = GetPopupMenuSelectionFromUser( ctxMenu );
444
445 switch( selected )
446 {
447 case EDIT_PAGE_NUMBER:
448 {
449 wxString msg;
450 wxString sheetPath = itemData->m_SheetPath.PathHumanReadable( false, true );
451 wxString pageNumber = itemData->m_SheetPath.GetPageNumber();
452
453 msg.Printf( _( "Enter page number for sheet path %s" ),
454 ( sheetPath.Length() > 20 ) ? wxS( " \n" ) + sheetPath + wxT( ": " )
455 : sheetPath + wxT( ": " ) );
456
457 wxTextEntryDialog dlg( m_frame, msg, _( "Edit Sheet Page Number" ), pageNumber );
458
459 dlg.SetTextValidator( wxFILTER_ALPHANUMERIC ); // No white space.
460
461 if( dlg.ShowModal() == wxID_OK && dlg.GetValue() != itemData->m_SheetPath.GetPageNumber() )
462 {
463 SCH_COMMIT commit( m_frame );
464 SCH_SHEET_PATH parentPath = itemData->m_SheetPath;
465 parentPath.pop_back();
466
467 commit.Modify( itemData->m_SheetPath.Last(), parentPath.LastScreen() );
468
469 itemData->m_SheetPath.SetPageNumber( dlg.GetValue() );
470
471 if( itemData->m_SheetPath == m_frame->GetCurrentSheet() )
472 {
473 m_frame->GetScreen()->SetPageNumber( dlg.GetValue() );
474 m_frame->OnPageSettingsChange();
475 }
476
477 commit.Push( wxS( "Change sheet page number." ) );
478
480 }
481
482 break;
483 }
484 case EXPAND_ALL:
485 m_tree->ExpandAll();
486 break;
487 case COLLAPSE_ALL:
488 m_tree->CollapseAll();
489 break;
490 case RENAME:
491 m_tree->SetItemText( aItem, itemData->m_SheetPath.Last()->GetName() );
492 m_tree->EditLabel( aItem );
494 break;
495 }
496}
497
498
499void HIERARCHY_PANE::onTreeEditFinished( wxTreeEvent& event )
500{
501 TREE_ITEM_DATA* data = static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( event.GetItem() ) );
502 wxString newName = event.GetLabel();
503
504 if( data && data->m_SheetPath.Last() )
505 {
506 if( !newName.IsEmpty() )
507 {
508 // The editor holds only the page name as a text, while normally
509 // the tree items displaying it suffixed with the page number
510 if( data->m_SheetPath.Last()->GetName() != newName )
511 {
512 const SCH_SHEET* parentSheet = data->m_SheetPath.GetSheet( data->m_SheetPath.size() - 2 );
513
514 if( parentSheet )
515 {
516 SCH_COMMIT commit( m_frame );
518 parentSheet->GetScreen() );
519
520 data->m_SheetPath.Last()->SetName( newName );
521
522 renameIdenticalSheets( data->m_SheetPath, newName, &commit );
523
524 if( !commit.Empty() )
525 commit.Push( _( "Renaming sheet" ) );
526
527 if( data->m_SheetPath == m_frame->GetCurrentSheet() )
528 {
529 m_frame->OnPageSettingsChange();
530 }
531 }
532 }
533 }
534
535 m_tree->SetItemText( event.GetItem(), formatPageString( data->m_SheetPath.Last()->GetName(),
536 data->m_SheetPath.GetPageNumber() ) );
538 // The event needs to be rejected otherwise the SetItemText call above
539 // will be ineffective (the treeview item will hold the editor's content)
540 event.Veto();
541 }
542}
543
544
545void HIERARCHY_PANE::onCharHook( wxKeyEvent& aKeyStroke )
546{
547 int hotkey = aKeyStroke.GetKeyCode();
548
549 int mods = aKeyStroke.GetModifiers();
550
551 // the flag wxMOD_ALTGR is defined in wxWidgets as wxMOD_CONTROL|wxMOD_ALT
552 // So AltGr key cannot used as modifier key because it is the same as Alt key + Ctrl key.
553#if CAN_USE_ALTGR_KEY
554 if( wxmods & wxMOD_ALTGR )
555 mods |= MD_ALTGR;
556 else
557#endif
558 {
559 if( mods & wxMOD_CONTROL )
560 hotkey += MD_CTRL;
561
562 if( mods & wxMOD_ALT )
563 hotkey += MD_ALT;
564 }
565
566 if( mods & wxMOD_SHIFT )
567 hotkey += MD_SHIFT;
568
569#ifdef wxMOD_META
570 if( mods & wxMOD_META )
571 hotkey += MD_META;
572#endif
573
574#ifdef wxMOD_WIN
575 if( mods & wxMOD_WIN )
576 hotkey += MD_SUPER;
577#endif
578
579 if( hotkey == ACTIONS::expandAll.GetHotKey()
580 || hotkey == ACTIONS::expandAll.GetHotKeyAlt() )
581 {
582 m_tree->ExpandAll();
583 return;
584 }
585 else if( hotkey == ACTIONS::collapseAll.GetHotKey()
586 || hotkey == ACTIONS::collapseAll.GetHotKeyAlt() )
587 {
588 m_tree->CollapseAll();
589 return;
590 }
591 else
592 {
593 aKeyStroke.Skip();
594 }
595}
596
597
599{
600 SCH_SHEET* rootSheet = &m_frame->Schematic().Root();
601 SCH_SHEET_PATH rootPath;
602 rootPath.push_back( rootSheet );
603
604 return formatPageString( rootSheet->GetShownName( false ), rootPath.GetPageNumber() );
605}
606
607
608wxString HIERARCHY_PANE::formatPageString( const wxString& aName, const wxString& aPage )
609{
610 return aName + wxT( " " ) + wxString::Format( _( "(page %s)" ), aPage );
611}
612
614{
615 std::function<void( const wxTreeItemId& )> recursiveDescent = [&]( const wxTreeItemId& id )
616 {
617 wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) );
618
619 TREE_ITEM_DATA* itemData = static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( id ) );
620
621 if( itemData->m_SheetPath.Cmp( path ) != 0 && itemData->m_SheetPath.Last() == path.Last() )
622 {
623 wxFont font = m_tree->GetItemFont( id );
624 font.SetUnderlined( highLighted );
625 m_tree->SetItemFont( id, font );
626 }
627
628 wxTreeItemIdValue cookie;
629 wxTreeItemId child = m_tree->GetFirstChild( id, cookie );
630
631 while( child.IsOk() )
632 {
633 recursiveDescent( child );
634 child = m_tree->GetNextChild( id, cookie );
635 }
636 };
637
638 recursiveDescent( m_tree->GetRootItem() );
639}
640
642 const wxString newName, SCH_COMMIT* commit )
643{
644 std::function<void( const wxTreeItemId& )> recursiveDescent = [&]( const wxTreeItemId& id )
645 {
646 wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) );
647
648 TREE_ITEM_DATA* data = static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( id ) );
649
650 const SCH_SHEET* parentSheet = data->m_SheetPath.GetSheet( data->m_SheetPath.size() - 2 );
651
652 if( parentSheet && data->m_SheetPath.Cmp( renamedSheet ) != 0
653 && data->m_SheetPath.Last() == renamedSheet.Last() )
654 {
656 parentSheet->GetScreen() );
657
658 data->m_SheetPath.Last()->SetName( newName );
659
660 if( data->m_SheetPath == m_frame->GetCurrentSheet() )
661 {
662 m_frame->OnPageSettingsChange();
663 }
664
665 m_tree->SetItemText( id, formatPageString( data->m_SheetPath.Last()->GetName(),
666 data->m_SheetPath.GetPageNumber() ) );
667 }
668
669 wxTreeItemIdValue cookie;
670 wxTreeItemId child = m_tree->GetFirstChild( id, cookie );
671
672 while( child.IsOk() )
673 {
674 recursiveDescent( child );
675 child = m_tree->GetNextChild( id, cookie );
676 }
677 };
678
679 recursiveDescent( m_tree->GetRootItem() );
680}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition bitmap.cpp:104
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
static TOOL_ACTION expandAll
Definition actions.h:90
static TOOL_ACTION collapseAll
Definition actions.h:91
bool Empty() const
Definition commit.h:137
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
SCH_EDIT_FRAME * m_frame
void onRightClick(wxTreeItemId aItem)
HIERARCHY_TREE * m_tree
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)
wxString getRootString()
SCH_SHEET_PATH m_list
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
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
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
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.
Definition sch_sheet.h:47
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
wxString GetName() const
Definition sch_sheet.h:113
void SetName(const wxString &aName)
Definition sch_sheet.h:114
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:116
wxString GetShownName(bool aAllowExtraText) const
Definition sch_sheet.h:109
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)
Definition wx_panel.cpp:28
static void recursiveDescent(wxSizer *aSizer, std::map< int, wxString > &aLabels)
#define _(s)
wxIMPLEMENT_ABSTRACT_CLASS(HIERARCHY_TREE, wxTreeCtrl)
@ MD_META
Definition tool_event.h:147
@ MD_ALT
Definition tool_event.h:145
@ MD_CTRL
Definition tool_event.h:144
@ MD_SUPER
Definition tool_event.h:146
@ MD_ALTGR
Definition tool_event.h:148
@ MD_SHIFT
Definition tool_event.h:143