KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_commit.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <macros.h>
25#include <tool/tool_manager.h>
26#include <tools/sch_tool_base.h>
27
28#include <lib_symbol.h>
29
30#include <sch_group.h>
31#include <sch_screen.h>
32#include <schematic.h>
33
34#include <view/view.h>
35#include <sch_commit.h>
36#include <connection_graph.h>
37
38#include <functional>
39#include <wx/log.h>
40
41
43 m_toolMgr( aToolMgr ),
44 m_isLibEditor( false )
45{
46 SCH_BASE_FRAME* frame = static_cast<SCH_BASE_FRAME*>( m_toolMgr->GetToolHolder() );
47 m_isLibEditor = frame && frame->IsType( FRAME_SCH_SYMBOL_EDITOR );
48}
49
50
52{
53 m_toolMgr = aTool->GetManager();
55}
56
57
59{
60 m_toolMgr = aFrame->GetToolManager();
62}
63
64
66{
67}
68
69
71 RECURSE_MODE aRecurse )
72{
73 wxCHECK( aItem, *this );
74
75 // If aItem belongs a symbol, sheet or label, the full parent will be saved because undo/redo
76 // does not handle "sub items" modifications.
77 if( aItem->Type() != SCH_SHEET_T
78 && aItem->GetParent() && aItem->GetParent()->IsType( { SCH_SYMBOL_T, LIB_SYMBOL_T,
79 SCH_SHEET_T,
80 SCH_LABEL_LOCATE_ANY_T } ) )
81 {
82 aItem = aItem->GetParent();
83 aChangeType = CHT_MODIFY;
84 }
85
86 if( aRecurse == RECURSE_MODE::RECURSE )
87 {
88 if( SCH_GROUP* group = dynamic_cast<SCH_GROUP*>( aItem ) )
89 {
90 for( EDA_ITEM* member : group->GetItems() )
91 Stage( member, aChangeType, aScreen, aRecurse );
92 }
93 }
94
95 // IS_SELECTED flag should not be set on undo items which were added for
96 // a drag operation.
97 if( aItem->IsSelected() && aItem->HasFlag( SELECTED_BY_DRAG ) )
98 {
99 aItem->ClearSelected();
100 COMMIT::Stage( aItem, aChangeType, aScreen );
101 aItem->SetSelected();
102 }
103 else
104 {
105 COMMIT::Stage( aItem, aChangeType, aScreen );
106 }
107
108 return *this;
109}
110
111
112COMMIT& SCH_COMMIT::Stage( std::vector<EDA_ITEM*> &container, CHANGE_TYPE aChangeType,
113 BASE_SCREEN *aScreen )
114{
115 for( EDA_ITEM* item : container )
116 Stage( item, aChangeType, aScreen );
117
118 return *this;
119}
120
121
123 BASE_SCREEN *aScreen )
124{
125 return COMMIT::Stage( aItems, aModFlag, aScreen );
126}
127
128
129void SCH_COMMIT::pushLibEdit( const wxString& aMessage, int aCommitFlags )
130{
131 KIGFX::VIEW* view = m_toolMgr->GetView();
132 SYMBOL_EDIT_FRAME* frame = static_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
133
134 if( Empty() )
135 return;
136
137 // Symbol editor just saves copies of the whole symbol, so grab the first and discard the rest
138 LIB_SYMBOL* symbol = dynamic_cast<LIB_SYMBOL*>( m_changes.front().m_item );
139 LIB_SYMBOL* copy = dynamic_cast<LIB_SYMBOL*>( m_changes.front().m_copy );
140
141 if( symbol )
142 {
143 if( view )
144 {
145 view->Update( symbol );
146
147 symbol->RunOnChildren(
148 [&]( SCH_ITEM* aChild )
149 {
150 view->Update( aChild );
151 },
152 RECURSE_MODE::NO_RECURSE );
153 }
154
155 if( !( aCommitFlags & SKIP_UNDO ) )
156 {
157 if( frame && copy )
158 {
159 frame->PushSymbolToUndoList( aMessage, copy );
160 copy = nullptr; // we've transferred ownership to the undo stack
161 }
162 }
163
164 if( copy )
165 {
166 // if no undo entry was needed, the copy would create a memory leak
167 delete copy;
168 copy = nullptr;
169 }
170 }
171
174
175 if( !( aCommitFlags & SKIP_SET_DIRTY ) )
176 {
177 if( frame )
178 frame->OnModify();
179 }
180
181 for( size_t ii = 1; ii < m_changes.size(); ++ii )
182 delete m_changes[ii].m_copy;
183
184 clear();
185}
186
187
188void SCH_COMMIT::pushSchEdit( const wxString& aMessage, int aCommitFlags )
189{
190 // Objects potentially interested in changes:
191 PICKED_ITEMS_LIST undoList;
192 KIGFX::VIEW* view = m_toolMgr->GetView();
193
194 SCH_EDIT_FRAME* frame = static_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
196 SCH_GROUP* enteredGroup = selTool ? selTool->GetEnteredGroup() : nullptr;
197 bool itemsDeselected = false;
198 bool selectedModified = false;
199 bool dirtyConnectivity = false;
200 bool refreshHierarchy = false;
201 SCH_CLEANUP_FLAGS connectivityCleanUp = NO_CLEANUP;
202
203 if( Empty() )
204 return;
205
206 undoList.SetDescription( aMessage );
207
208 SCHEMATIC* schematic = nullptr;
209 std::vector<SCH_ITEM*> bulkAddedItems;
210 std::vector<SCH_ITEM*> bulkRemovedItems;
211 std::vector<SCH_ITEM*> itemsChanged;
212
213 auto updateConnectivityFlag =
214 [&]( SCH_ITEM* schItem )
215 {
216 if( schItem->IsConnectable() || ( schItem->Type() == SCH_RULE_AREA_T ) )
217 {
218 dirtyConnectivity = true;
219
220 // Do a local clean up if there are any connectable objects in the commit.
221 if( connectivityCleanUp == NO_CLEANUP )
222 connectivityCleanUp = LOCAL_CLEANUP;
223
224 // Do a full rebuild of the connectivity if there is a sheet in the commit.
225 if( schItem->Type() == SCH_SHEET_T )
226 connectivityCleanUp = GLOBAL_CLEANUP;
227 }
228 };
229
230 // We don't know that anything will be added to the entered group, but it does no harm to
231 // add it to the commit anyway.
232 if( enteredGroup )
233 Modify( enteredGroup );
234
235 // Handle wires with Hop Over shapes:
236 for( COMMIT_LINE& ent : m_changes )
237 {
238 SCH_ITEM* schCopyItem = dynamic_cast<SCH_ITEM*>( ent.m_copy );
239 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( ent.m_item );
240
241 if( schCopyItem && schCopyItem->Type() == SCH_LINE_T )
242 frame->UpdateHopOveredWires( schCopyItem );
243
244 if( schItem && schItem->Type() == SCH_LINE_T )
245 frame->UpdateHopOveredWires( schItem );
246 }
247
248
249 for( COMMIT_LINE& ent : m_changes )
250 {
251 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( ent.m_item );
252 int changeType = ent.m_type & CHT_TYPE;
253
254 wxCHECK2( schItem, continue );
255
256 if( changeType == CHT_REMOVE && schItem->GetParentGroup() )
257 Modify( schItem->GetParentGroup()->AsEdaItem() );
258 }
259
260 for( COMMIT_LINE& ent : m_changes )
261 {
262 int changeType = ent.m_type & CHT_TYPE;
263 int changeFlags = ent.m_type & CHT_FLAGS;
264 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( ent.m_item );
265 SCH_SCREEN* screen = dynamic_cast<SCH_SCREEN*>( ent.m_screen );
266
267 wxCHECK2( schItem, continue );
268 wxCHECK2( screen, continue );
269
270 if( !schematic )
271 schematic = schItem->Schematic();
272
273 if( schItem->IsSelected() )
274 {
275 selectedModified = true;
276 }
277 else
278 {
279 schItem->RunOnChildren(
280 [&selectedModified]( SCH_ITEM* aChild )
281 {
282 if( aChild->IsSelected() )
283 selectedModified = true;
284 },
285 RECURSE_MODE::NO_RECURSE );
286 }
287
288 switch( changeType )
289 {
290 case CHT_ADD:
291 {
292 if( enteredGroup && schItem->IsGroupableType() && !schItem->GetParentGroup() )
293 selTool->GetEnteredGroup()->AddItem( schItem );
294
295 updateConnectivityFlag( schItem );
296
297 if( !( aCommitFlags & SKIP_UNDO ) )
298 undoList.PushItem( ITEM_PICKER( screen, schItem, UNDO_REDO::NEWITEM ) );
299
300 if( !( changeFlags & CHT_DONE ) )
301 {
302 if( !screen->CheckIfOnDrawList( schItem ) ) // don't want a loop!
303 screen->Append( schItem );
304
305 if( view )
306 view->Add( schItem );
307 }
308
309 if( frame )
310 frame->UpdateItem( schItem, true, true );
311
312 bulkAddedItems.push_back( schItem );
313
314 if( schItem->Type() == SCH_SHEET_T )
315 refreshHierarchy = true;
316
317 break;
318 }
319
320 case CHT_REMOVE:
321 {
322 updateConnectivityFlag( schItem );
323
324 if( !( aCommitFlags & SKIP_UNDO ) )
325 {
326 ITEM_PICKER itemWrapper( screen, schItem, UNDO_REDO::DELETED );
327 itemWrapper.SetLink( ent.m_copy );
328 ent.m_copy = nullptr; // We've transferred ownership to the undo list
329 undoList.PushItem( itemWrapper );
330 }
331
332 if( schItem->IsSelected() )
333 {
334 if( selTool )
335 selTool->RemoveItemFromSel( schItem, true /* quiet mode */ );
336
337 itemsDeselected = true;
338 }
339
340 if( schItem->Type() == SCH_FIELD_T )
341 {
342 static_cast<SCH_FIELD*>( schItem )->SetVisible( false );
343 break;
344 }
345
346 if( EDA_GROUP* group = schItem->GetParentGroup() )
347 group->RemoveItem( schItem );
348
349 if( !( changeFlags & CHT_DONE ) )
350 {
351 screen->Remove( schItem );
352
353 if( view )
354 view->Remove( schItem );
355 }
356
357 if( frame )
358 frame->UpdateItem( schItem, true, true );
359
360 if( schItem->Type() == SCH_SHEET_T )
361 refreshHierarchy = true;
362
363 bulkRemovedItems.push_back( schItem );
364 break;
365 }
366
367 case CHT_MODIFY:
368 {
369 const SCH_ITEM* itemCopy = static_cast<const SCH_ITEM*>( ent.m_copy );
370 SCH_SHEET_PATH currentSheet;
371
372 if( frame )
373 currentSheet = frame->GetCurrentSheet();
374
375 if( itemCopy->HasConnectivityChanges( schItem, &currentSheet )
376 || ( itemCopy->Type() == SCH_RULE_AREA_T ) )
377 {
378 updateConnectivityFlag( schItem );
379 }
380
381 if( !( aCommitFlags & SKIP_UNDO ) )
382 {
383 ITEM_PICKER itemWrapper( screen, schItem, UNDO_REDO::CHANGED );
384 itemWrapper.SetLink( ent.m_copy );
385 ent.m_copy = nullptr; // We've transferred ownership to the undo list
386 undoList.PushItem( itemWrapper );
387 }
388
389 if( schItem->Type() == SCH_SHEET_T )
390 {
391 const SCH_SHEET* modifiedSheet = static_cast<const SCH_SHEET*>( schItem );
392 const SCH_SHEET* originalSheet = static_cast<const SCH_SHEET*>( itemCopy );
393 wxCHECK2( modifiedSheet && originalSheet, continue );
394
395 if( originalSheet->HasPageNumberChanges( *modifiedSheet ) )
396 refreshHierarchy = true;
397 }
398
399 if( frame )
400 frame->UpdateItem( schItem, false, true );
401
402 itemsChanged.push_back( schItem );
403 break;
404 }
405
406 default:
407 wxASSERT( false );
408 break;
409 }
410
411 // Delete any copies we still have ownership of
412 delete ent.m_copy;
413 ent.m_copy = nullptr;
414
415 // Clear all flags but SELECTED and others used to move and rotate commands,
416 // after edition (selected items must keep their selection flag).
417 const int selected_mask = ( SELECTED | STARTPOINT | ENDPOINT );
418 schItem->ClearFlags( EDA_ITEM_ALL_FLAGS - selected_mask );
419
420 if( schItem->Type() == SCH_SHEET_T || schItem->Type() == SCH_SYMBOL_T )
421 {
422 schItem->RunOnChildren(
423 [&]( SCH_ITEM* child )
424 {
425 child->ClearFlags( EDA_ITEM_ALL_FLAGS - selected_mask );
426 },
427 RECURSE_MODE::NO_RECURSE );
428 }
429 }
430
431 if( schematic )
432 {
433 if( bulkAddedItems.size() > 0 )
434 schematic->OnItemsAdded( bulkAddedItems );
435
436 if( bulkRemovedItems.size() > 0 )
437 schematic->OnItemsRemoved( bulkRemovedItems );
438
439 if( itemsChanged.size() > 0 )
440 schematic->OnItemsChanged( itemsChanged );
441
442 if( refreshHierarchy )
443 {
444 schematic->RefreshHierarchy();
445
446 if( frame )
448 }
449 }
450
451 if( !( aCommitFlags & SKIP_UNDO ) )
452 {
453 if( frame )
454 {
455 frame->SaveCopyInUndoList( undoList, UNDO_REDO::UNSPECIFIED, false, dirtyConnectivity );
456
457 if( dirtyConnectivity )
458 {
459 wxLogTrace( wxS( "CONN_PROFILE" ),
460 wxS( "SCH_COMMIT::pushSchEdit() %s clean up connectivity rebuild." ),
461 ( connectivityCleanUp == LOCAL_CLEANUP ) ? wxS( "local" )
462 : wxS( "global" ) );
463 frame->RecalculateConnections( this, connectivityCleanUp );
464 }
465 }
466 }
467
469
470 if( itemsDeselected )
472
473 if( selectedModified )
475
476 if( frame && frame->GetCanvas() )
477 frame->GetCanvas()->Refresh();
478
479 if( !( aCommitFlags & SKIP_SET_DIRTY ) )
480 {
481 if( frame )
482 frame->OnModify();
483 }
484
485 clear();
486}
487
488
489void SCH_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
490{
491 if( m_isLibEditor )
492 pushLibEdit( aMessage, aCommitFlags );
493 else
494 pushSchEdit( aMessage, aCommitFlags );
495}
496
497
499{
500 EDA_ITEM* parent = aItem->GetParent();
501
502 if( parent && ( parent->Type() == SCH_SYMBOL_T || parent->Type() == LIB_SYMBOL_T ) )
503 return parent;
504
505 if( m_isLibEditor )
506 return static_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() )->GetCurSymbol();
507
508 return aItem;
509}
510
511
513{
514 if( m_isLibEditor )
515 {
516 SYMBOL_EDIT_FRAME* frame = static_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
517 LIB_SYMBOL* symbol = frame->GetCurSymbol();
518 std::vector<KIID> selected;
519
520 for( const SCH_ITEM& item : symbol->GetDrawItems() )
521 {
522 if( item.IsSelected() )
523 selected.push_back( item.m_Uuid );
524 }
525
526 symbol = new LIB_SYMBOL( *symbol );
527
528 for( SCH_ITEM& item : symbol->GetDrawItems() )
529 {
530 if( alg::contains( selected, item.m_Uuid ) )
531 item.SetSelected();
532 }
533
534 return symbol;
535 }
536
537 return aItem->Clone();
538}
539
540
542{
543 if( Empty() )
544 return;
545
546 // Symbol editor just saves copies of the whole symbol, so grab the first and discard the rest
547 SYMBOL_EDIT_FRAME* frame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
548 LIB_SYMBOL* copy = dynamic_cast<LIB_SYMBOL*>( m_changes.front().m_copy );
550
551 if( frame && copy )
552 {
553 frame->SetCurSymbol( copy, false );
555 }
556
557 for( size_t ii = 1; ii < m_changes.size(); ++ii )
558 delete m_changes[ii].m_copy;
559
560 if( selTool )
561 selTool->RebuildSelection();
562
563 clear();
564}
565
566
568{
569 KIGFX::VIEW* view = m_toolMgr->GetView();
570 SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
572 SCH_SHEET_LIST sheets;
573
574 if( m_changes.empty() )
575 return;
576
577 if( m_isLibEditor )
578 {
580 return;
581 }
582
583 SCHEMATIC* schematic = nullptr;
584 std::vector<SCH_ITEM*> bulkAddedItems;
585 std::vector<SCH_ITEM*> bulkRemovedItems;
586 std::vector<SCH_ITEM*> itemsChanged;
587
588 for( COMMIT_LINE& ent : m_changes )
589 {
590 int changeType = ent.m_type & CHT_TYPE;
591 int changeFlags = ent.m_type & CHT_FLAGS;
592 SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( ent.m_item );
593 SCH_ITEM* copy = dynamic_cast<SCH_ITEM*>( ent.m_copy );
594 SCH_SCREEN* screen = dynamic_cast<SCH_SCREEN*>( ent.m_screen );
595
596 wxCHECK2( item && screen, continue );
597
598 if( !schematic )
599 schematic = item->Schematic();
600
601 switch( changeType )
602 {
603 case CHT_ADD:
604 if( !( changeFlags & CHT_DONE ) )
605 break;
606
607 if( view )
608 view->Remove( item );
609
610 screen->Remove( item );
611 bulkRemovedItems.push_back( item );
612 break;
613
614 case CHT_REMOVE:
615 item->SetConnectivityDirty();
616
617 if( !( changeFlags & CHT_DONE ) )
618 break;
619
620 if( view )
621 view->Add( item );
622
623 screen->Append( item );
624 bulkAddedItems.push_back( item );
625 break;
626
627 case CHT_MODIFY:
628 {
629 wxCHECK2( copy, break );
630
631 if( view )
632 view->Remove( item );
633
634 bool unselect = !item->IsSelected();
635
636 item->SwapItemData( copy );
637
638 if( unselect )
639 {
640 item->ClearSelected();
641 item->RunOnChildren( []( SCH_ITEM* aChild ) { aChild->ClearSelected(); }, RECURSE_MODE::NO_RECURSE );
642 }
643
644 // Special cases for items which have instance data
645 if( item->GetParent() && item->GetParent()->Type() == SCH_SYMBOL_T
646 && item->Type() == SCH_FIELD_T )
647 {
648 SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
649 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item->GetParent() );
650
651 if( field->GetId() == FIELD_T::REFERENCE )
652 {
653 // Lazy eval of sheet list; this is expensive even when unsorted
654 if( sheets.empty() )
655 sheets = schematic->Hierarchy();
656
657 SCH_SHEET_PATH sheet = sheets.FindSheetForScreen( screen );
658 symbol->SetRef( &sheet, field->GetText() );
659 }
660 }
661
662 // This must be called before any calls that require stable object pointers.
663 screen->Update( item );
664
665 // This hack is to prevent incorrectly parented symbol pins from breaking the
666 // connectivity algorithm.
667 if( item->Type() == SCH_SYMBOL_T )
668 {
669 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
670 symbol->UpdatePins();
671
672 CONNECTION_GRAPH* graph = schematic->ConnectionGraph();
673
674 SCH_SYMBOL* symbolCopy = static_cast<SCH_SYMBOL*>( copy );
675 graph->RemoveItem( symbolCopy );
676
677 for( SCH_PIN* pin : symbolCopy->GetPins() )
678 graph->RemoveItem( pin );
679 }
680
681 item->SetConnectivityDirty();
682
683 if( view )
684 view->Add( item );
685
686 delete copy;
687 break;
688 }
689
690 default:
691 wxASSERT( false );
692 break;
693 }
694 }
695
696 if( schematic )
697 {
698 if( bulkAddedItems.size() > 0 )
699 schematic->OnItemsAdded( bulkAddedItems );
700
701 if( bulkRemovedItems.size() > 0 )
702 schematic->OnItemsRemoved( bulkRemovedItems );
703
704 if( itemsChanged.size() > 0 )
705 schematic->OnItemsChanged( itemsChanged );
706 }
707
708 if( selTool )
709 selTool->RebuildSelection();
710
711 if( frame )
712 {
713 frame->RecalculateConnections( nullptr, NO_CLEANUP );
714 }
715
716 clear();
717}
718
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:41
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition: commit.h:73
bool Empty() const
Definition: commit.h:150
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:107
void clear()
Should be called in Push() & Revert() methods.
Definition: commit.h:171
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:201
virtual COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Add a change of the item aItem of type aChangeType to the change list.
Definition: commit.cpp:46
Calculate the connectivity of a schematic and generates netlists.
void RemoveItem(SCH_ITEM *aItem)
bool IsType(FRAME_T aType) const
The base class for create windows for drawing purpose.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A set of EDA_ITEMs (i.e., without duplicates).
Definition: eda_group.h:46
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition: eda_group.cpp:27
virtual EDA_ITEM * AsEdaItem()=0
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:97
virtual EDA_GROUP * GetParentGroup() const
Definition: eda_item.h:115
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:109
void ClearSelected()
Definition: eda_item.h:136
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:143
bool IsSelected() const
Definition: eda_item.h:126
void SetSelected()
Definition: eda_item.h:133
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:191
EDA_ITEM * GetParent() const
Definition: eda_item.h:111
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:118
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:145
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:97
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:345
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:339
void SetLink(EDA_ITEM *aItem)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:297
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:331
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1675
Define a library symbol object.
Definition: lib_symbol.h:85
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:519
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode) override
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
void SetDescription(const wxString &aDescription)
Holds all the data relating to one schematic.
Definition: schematic.h:87
void OnItemsAdded(std::vector< SCH_ITEM * > &aNewItems)
Must be used if Add() is used using a BULK_x ADD_MODE to generate a change event for listeners.
Definition: schematic.cpp:796
void OnItemsRemoved(std::vector< SCH_ITEM * > &aRemovedItems)
Must be used if Remove() is used using a BULK_x REMOVE_MODE to generate a change event for listeners.
Definition: schematic.cpp:802
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:219
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:182
void RefreshHierarchy()
Definition: schematic.cpp:227
void OnItemsChanged(std::vector< SCH_ITEM * > &aItems)
Notify the schematic and its listeners that an item on the schematic has been modified in some way.
Definition: schematic.cpp:808
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE) override
Add a change of the item aItem of type aChangeType to the change list.
Definition: sch_commit.cpp:70
bool m_isLibEditor
Definition: sch_commit.h:77
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Definition: sch_commit.cpp:489
virtual void Revert() override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:567
TOOL_MANAGER * m_toolMgr
Definition: sch_commit.h:76
SCH_COMMIT(TOOL_MANAGER *aToolMgr)
Definition: sch_commit.cpp:42
virtual ~SCH_COMMIT()
Definition: sch_commit.cpp:65
void pushLibEdit(const wxString &aMessage, int aCommitFlags)
Definition: sch_commit.cpp:129
void revertLibEdit()
Definition: sch_commit.cpp:541
EDA_ITEM * makeImage(EDA_ITEM *aItem) const override
Definition: sch_commit.cpp:512
EDA_ITEM * parentObject(EDA_ITEM *aItem) const override
Definition: sch_commit.cpp:498
void pushSchEdit(const wxString &aMessage, int aCommitFlags)
Definition: sch_commit.cpp:188
Schematic editor (Eeschema) main window.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
SCH_SHEET_PATH & GetCurrentSheet() const
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr)
Generate the connection data for the entire schematic hierarchy.
void UpdateHierarchyNavigator(bool aRefreshNetNavigator=true, bool aClear=false)
Update the hierarchy navigation tree and history.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
void UpdateHopOveredWires(SCH_ITEM *aItem)
FIELD_T GetId() const
Definition: sch_field.h:115
A set of SCH_ITEMs (i.e., without duplicates).
Definition: sch_group.h:52
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode)
Definition: sch_item.h:598
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:212
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:557
virtual bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const
Check if aItem has connectivity changes against this object.
Definition: sch_item.h:574
bool IsGroupableType() const
Definition: sch_item.cpp:127
void SwapItemData(SCH_ITEM *aImage)
Swap data between aItem and aImage.
Definition: sch_item.cpp:452
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:160
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:330
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:323
bool CheckIfOnDrawList(const SCH_ITEM *aItem) const
Definition: sch_screen.cpp:393
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
SCH_GROUP * GetEnteredGroup()
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:47
bool HasPageNumberChanges(const SCH_SHEET &aOther) const
Check if the instance data of this sheet has any changes compared to aOther.
Definition: sch_sheet.cpp:1475
Schematic symbol object.
Definition: sch_symbol.h:75
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
Definition: sch_symbol.cpp:288
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:592
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
A foundation class for a tool operating on a schematic or symbol.
Definition: sch_tool_base.h:49
bool IsSymbolEditor() const
Returns true if the tool is running in the symbol editor.
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
The symbol library editor main window.
void PushSymbolToUndoList(const wxString &aDescription, LIB_SYMBOL *aSymbolCopy, UNDO_REDO aUndoType=UNDO_REDO::LIBEDIT)
void SetCurSymbol(LIB_SYMBOL *aSymbol, bool aUpdateZoom)
Take ownership of aSymbol and notes that it is the one currently being edited.
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current symbol.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:146
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
Master controller class:
Definition: tool_manager.h:62
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:406
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:395
CHANGE_TYPE
Types of changes.
Definition: commit.h:42
@ CHT_MODIFY
Definition: commit.h:45
@ CHT_REMOVE
Definition: commit.h:44
@ CHT_DONE
Flag to indicate the change is already applied.
Definition: commit.h:48
@ CHT_TYPE
Definition: commit.h:46
@ CHT_ADD
Definition: commit.h:43
@ CHT_FLAGS
Definition: commit.h:49
RECURSE_MODE
Definition: eda_item.h:49
#define SELECTED
Item was manually selected by the user.
#define SELECTED_BY_DRAG
Item was algorithmically selected as a dragged item.
#define EDA_ITEM_ALL_FLAGS
#define ENDPOINT
ends. (Used to support dragging.)
#define STARTPOINT
When a line is selected, these flags indicate which.
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
This file contains miscellaneous commonly used macros and functions.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:100
#define SKIP_SET_DIRTY
Definition: sch_commit.h:43
#define SKIP_UNDO
Definition: sch_commit.h:41
Class to handle a set of SCH_ITEMs.
SCH_CLEANUP_FLAGS
Definition: schematic.h:73
@ LOCAL_CLEANUP
Definition: schematic.h:75
@ NO_CLEANUP
Definition: schematic.h:74
@ GLOBAL_CLEANUP
Definition: schematic.h:76
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition: tool_action.h:49
@ TA_MODEL_CHANGE
Model has changed (partial update).
Definition: tool_event.h:121
@ TC_MESSAGE
Definition: tool_event.h:58
@ SCH_LINE_T
Definition: typeinfo.h:164
@ LIB_SYMBOL_T
Definition: typeinfo.h:149
@ SCH_SYMBOL_T
Definition: typeinfo.h:173
@ SCH_FIELD_T
Definition: typeinfo.h:151
@ SCH_SHEET_T
Definition: typeinfo.h:176
@ SCH_RULE_AREA_T
Definition: typeinfo.h:171
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...