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 (C) 2023-2024 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/ee_tool_base.h>
27
28#include <lib_item.h>
29#include <lib_symbol.h>
30
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
40
42 m_toolMgr( aToolMgr ),
43 m_isLibEditor( false )
44{
45 SCH_BASE_FRAME* frame = static_cast<SCH_BASE_FRAME*>( m_toolMgr->GetToolHolder() );
46 m_isLibEditor = frame && frame->IsType( FRAME_SCH_SYMBOL_EDITOR );
47}
48
49
51{
52 m_toolMgr = aTool->GetManager();
54}
55
56
58{
59 m_toolMgr = aFrame->GetToolManager();
61}
62
63
65{
66}
67
68
69COMMIT& SCH_COMMIT::Stage( EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen )
70{
71 wxCHECK( aItem, *this );
72
73 // If aItem belongs a symbol, sheet or label, the full parent will be saved because undo/redo
74 // does not handle "sub items" modifications.
75 if( aItem->Type() != SCH_SHEET_T
76 && aItem->GetParent() && aItem->GetParent()->IsType( { SCH_SYMBOL_T, LIB_SYMBOL_T,
77 SCH_SHEET_T,
78 SCH_LABEL_LOCATE_ANY_T } ) )
79 {
80 aItem = aItem->GetParent();
81 aChangeType = CHT_MODIFY;
82 }
83
84 // IS_SELECTED flag should not be set on undo items which were added for
85 // a drag operation.
86 if( aItem->IsSelected() && aItem->HasFlag( SELECTED_BY_DRAG ) )
87 {
88 aItem->ClearSelected();
89 COMMIT::Stage( aItem, aChangeType, aScreen );
90 aItem->SetSelected();
91 }
92 else
93 {
94 COMMIT::Stage( aItem, aChangeType, aScreen );
95 }
96
97 return *this;
98}
99
100
101COMMIT& SCH_COMMIT::Stage( std::vector<EDA_ITEM*> &container, CHANGE_TYPE aChangeType,
102 BASE_SCREEN *aScreen )
103{
104 for( EDA_ITEM* item : container )
105 Stage( item, aChangeType, aScreen );
106
107 return *this;
108}
109
110
112 BASE_SCREEN *aScreen )
113{
114 return COMMIT::Stage( aItems, aModFlag, aScreen );
115}
116
117
118void SCH_COMMIT::pushLibEdit( const wxString& aMessage, int aCommitFlags )
119{
120 KIGFX::VIEW* view = m_toolMgr->GetView();
121 SYMBOL_EDIT_FRAME* frame = static_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
122
123 if( Empty() )
124 return;
125
126 // Symbol editor just saves copies of the whole symbol, so grab the first and discard the rest
127 LIB_SYMBOL* symbol = dynamic_cast<LIB_SYMBOL*>( m_changes.front().m_item );
128 LIB_SYMBOL* copy = dynamic_cast<LIB_SYMBOL*>( m_changes.front().m_copy );
129
130 if( symbol )
131 {
132 if( view )
133 {
134 view->Update( symbol );
135
136 symbol->RunOnChildren(
137 [&]( LIB_ITEM* aChild )
138 {
139 view->Update( aChild );
140 });
141 }
142
143 if( !( aCommitFlags & SKIP_UNDO ) )
144 {
145 if( frame && copy )
146 {
147 frame->PushSymbolToUndoList( aMessage, copy );
148 copy = nullptr; // we've transferred ownership to the undo stack
149 }
150 }
151
152 if( copy )
153 {
154 // if no undo entry was needed, the copy would create a memory leak
155 delete copy;
156 copy = nullptr;
157 }
158 }
159
162
163 if( !( aCommitFlags & SKIP_SET_DIRTY ) )
164 {
165 if( frame )
166 frame->OnModify();
167 }
168
169 for( size_t ii = 1; ii < m_changes.size(); ++ii )
170 delete m_changes[ii].m_copy;
171
172 clear();
173}
174
175
176void SCH_COMMIT::pushSchEdit( const wxString& aMessage, int aCommitFlags )
177{
178 // Objects potentially interested in changes:
179 PICKED_ITEMS_LIST undoList;
180 KIGFX::VIEW* view = m_toolMgr->GetView();
181
182 SCH_EDIT_FRAME* frame = static_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
184 bool itemsDeselected = false;
185 bool selectedModified = false;
186 bool dirtyConnectivity = false;
187 SCH_CLEANUP_FLAGS connectivityCleanUp = NO_CLEANUP;
188
189 if( Empty() )
190 return;
191
192 undoList.SetDescription( aMessage );
193
194 SCHEMATIC* schematic = nullptr;
195 std::vector<SCH_ITEM*> bulkAddedItems;
196 std::vector<SCH_ITEM*> bulkRemovedItems;
197 std::vector<SCH_ITEM*> itemsChanged;
198
199 for( COMMIT_LINE& ent : m_changes )
200 {
201 int changeType = ent.m_type & CHT_TYPE;
202 int changeFlags = ent.m_type & CHT_FLAGS;
203 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( ent.m_item );
204 SCH_SCREEN* screen = dynamic_cast<SCH_SCREEN*>( ent.m_screen );
205
206 wxCHECK2( schItem && screen, continue );
207
208 if( !schematic )
209 schematic = schItem->Schematic();
210
211 if( schItem->IsSelected() )
212 selectedModified = true;
213
214 auto updateConnectivityFlag =
215 [&]()
216 {
217 if( schItem->IsConnectable() )
218 {
219 dirtyConnectivity = true;
220
221 // Do a local clean up if there are any connectable objects in the commit.
222 if( connectivityCleanUp == NO_CLEANUP )
223 connectivityCleanUp = LOCAL_CLEANUP;
224
225 // Do a full rebauild of the connectivity if there is a sheet in the commit.
226 if( schItem->Type() == SCH_SHEET_T )
227 connectivityCleanUp = GLOBAL_CLEANUP;
228 }
229 };
230
231 switch( changeType )
232 {
233 case CHT_ADD:
234 {
235 updateConnectivityFlag();
236
237 if( !( aCommitFlags & SKIP_UNDO ) )
238 undoList.PushItem( ITEM_PICKER( screen, schItem, UNDO_REDO::NEWITEM ) );
239
240 if( !( changeFlags & CHT_DONE ) )
241 {
242 if( !screen->CheckIfOnDrawList( schItem ) ) // don't want a loop!
243 screen->Append( schItem );
244
245 if( view )
246 view->Add( schItem );
247 }
248
249 if( frame )
250 frame->UpdateItem( schItem, true, true );
251
252 bulkAddedItems.push_back( schItem );
253
254 break;
255 }
256
257 case CHT_REMOVE:
258 {
259 updateConnectivityFlag();
260
261 if( !( aCommitFlags & SKIP_UNDO ) )
262 undoList.PushItem( ITEM_PICKER( screen, schItem, UNDO_REDO::DELETED ) );
263
264 if( schItem->IsSelected() )
265 {
266 if( selTool )
267 selTool->RemoveItemFromSel( schItem, true /* quiet mode */ );
268
269 itemsDeselected = true;
270 }
271
272 if( schItem->Type() == SCH_FIELD_T )
273 {
274 static_cast<SCH_FIELD*>( schItem )->SetVisible( false );
275 break;
276 }
277
278 if( !( changeFlags & CHT_DONE ) )
279 {
280 screen->Remove( schItem );
281
282 if( view )
283 view->Remove( schItem );
284 }
285
286 if( frame )
287 frame->UpdateItem( schItem, true, true );
288
289 bulkRemovedItems.push_back( schItem );
290
291 break;
292 }
293
294 case CHT_MODIFY:
295 {
296 if( !( aCommitFlags & SKIP_UNDO ) )
297 {
298 ITEM_PICKER itemWrapper( screen, schItem, UNDO_REDO::CHANGED );
299 wxASSERT( ent.m_copy );
300 itemWrapper.SetLink( ent.m_copy );
301
302 const SCH_ITEM* itemCopy = static_cast<const SCH_ITEM*>( ent.m_copy );
303
304 wxCHECK2( itemCopy, continue );
305
306 SCH_SHEET_PATH currentSheet;
307
308 if( frame )
309 currentSheet = frame->GetCurrentSheet();
310
311 if( itemCopy->HasConnectivityChanges( schItem, &currentSheet ) )
312 updateConnectivityFlag();
313
314 undoList.PushItem( itemWrapper );
315 ent.m_copy = nullptr; // We've transferred ownership to the undo list
316 }
317
318 if( frame )
319 frame->UpdateItem( schItem, false, true );
320
321 itemsChanged.push_back( schItem );
322
323 if( ent.m_copy )
324 {
325 // if no undo entry is needed, the copy would create a memory leak
326 delete ent.m_copy;
327 ent.m_copy = nullptr;
328 }
329
330 break;
331 }
332
333 default:
334 wxASSERT( false );
335 break;
336 }
337
338 // Clear all flags but SELECTED and others used to move and rotate commands,
339 // after edition (selected items must keep their selection flag).
340 const int selected_mask = ( SELECTED | STARTPOINT | ENDPOINT );
341 schItem->ClearFlags( EDA_ITEM_ALL_FLAGS - selected_mask );
342 }
343
344 if( schematic )
345 {
346 if( bulkAddedItems.size() > 0 )
347 schematic->OnItemsAdded( bulkAddedItems );
348
349 if( bulkRemovedItems.size() > 0 )
350 schematic->OnItemsRemoved( bulkRemovedItems );
351
352 if( itemsChanged.size() > 0 )
353 schematic->OnItemsChanged( itemsChanged );
354 }
355
356 if( !( aCommitFlags & SKIP_UNDO ) )
357 {
358 if( frame )
359 {
360 frame->SaveCopyInUndoList( undoList, UNDO_REDO::UNSPECIFIED, false, dirtyConnectivity );
361
362 if( dirtyConnectivity )
363 {
364 wxLogTrace( wxS( "CONN_PROFILE" ),
365 wxS( "SCH_COMMIT::pushSchEdit() %s clean up connectivity rebuild." ),
366 ( connectivityCleanUp == LOCAL_CLEANUP ) ? wxS( "local" ) : wxS( "global" ) );
367 frame->RecalculateConnections( this, connectivityCleanUp );
368 }
369 }
370 }
371
373
374 if( itemsDeselected )
376
377 if( selectedModified )
379
380 if( frame && frame->GetCanvas() )
381 frame->GetCanvas()->Refresh();
382
383 if( !( aCommitFlags & SKIP_SET_DIRTY ) )
384 {
385 if( frame )
386 frame->OnModify();
387 }
388
389 clear();
390}
391
392
393void SCH_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
394{
395 if( m_isLibEditor )
396 pushLibEdit( aMessage, aCommitFlags );
397 else
398 pushSchEdit( aMessage, aCommitFlags );
399}
400
401
403{
404 EDA_ITEM* parent = aItem->GetParent();
405
406 if( parent && parent->Type() == SCH_SYMBOL_T )
407 return parent;
408
409 if( parent && parent->Type() == LIB_SYMBOL_T )
410 return parent;
411
412 if( m_isLibEditor )
413 return static_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() )->GetCurSymbol();
414
415 return aItem;
416}
417
418
420{
421 if( m_isLibEditor )
422 {
423 SYMBOL_EDIT_FRAME* frame = static_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
424 LIB_SYMBOL* symbol = frame->GetCurSymbol();
425 std::vector<KIID> selected;
426
427 for( const LIB_ITEM& item : symbol->GetDrawItems() )
428 {
429 if( item.IsSelected() )
430 selected.push_back( item.m_Uuid );
431 }
432
433 symbol = new LIB_SYMBOL( *symbol );
434
435 for( LIB_ITEM& item : symbol->GetDrawItems() )
436 {
437 if( alg::contains( selected, item.m_Uuid ) )
438 item.SetSelected();
439 }
440
441 return symbol;
442 }
443
444 return aItem->Clone();
445}
446
447
449{
450 if( Empty() )
451 return;
452
453 // Symbol editor just saves copies of the whole symbol, so grab the first and discard the rest
454 SYMBOL_EDIT_FRAME* frame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
455 LIB_SYMBOL* copy = dynamic_cast<LIB_SYMBOL*>( m_changes.front().m_copy );
457
458 if( frame && copy )
459 {
460 frame->SetCurSymbol( copy, false );
462 }
463
464 for( size_t ii = 1; ii < m_changes.size(); ++ii )
465 delete m_changes[ii].m_copy;
466
467 if( selTool )
468 selTool->RebuildSelection();
469
470 clear();
471}
472
473
475{
476 KIGFX::VIEW* view = m_toolMgr->GetView();
477 SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
479
480 if( m_changes.empty() )
481 return;
482
483 if( m_isLibEditor )
484 {
486 return;
487 }
488
489 SCHEMATIC* schematic = nullptr;
490 std::vector<SCH_ITEM*> bulkAddedItems;
491 std::vector<SCH_ITEM*> bulkRemovedItems;
492 std::vector<SCH_ITEM*> itemsChanged;
493
494 for( COMMIT_LINE& ent : m_changes )
495 {
496 int changeType = ent.m_type & CHT_TYPE;
497 int changeFlags = ent.m_type & CHT_FLAGS;
498 SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( ent.m_item );
499 SCH_ITEM* copy = dynamic_cast<SCH_ITEM*>( ent.m_copy );
500 SCH_SCREEN* screen = dynamic_cast<SCH_SCREEN*>( ent.m_screen );
501
502 wxCHECK2( item && screen, continue );
503
504 if( !schematic )
505 schematic = item->Schematic();
506
507 switch( changeType )
508 {
509 case CHT_ADD:
510 if( !( changeFlags & CHT_DONE ) )
511 break;
512
513 if( view )
514 view->Remove( item );
515
516 screen->Remove( item );
517 bulkRemovedItems.push_back( item );
518 break;
519
520 case CHT_REMOVE:
521 item->SetConnectivityDirty();
522
523 if( !( changeFlags & CHT_DONE ) )
524 break;
525
526 if( view )
527 view->Add( item );
528
529 screen->Append( item );
530 bulkAddedItems.push_back( item );
531 break;
532
533 case CHT_MODIFY:
534 {
535 if( view )
536 view->Remove( item );
537
538 bool unselect = !item->IsSelected();
539
540 item->SwapData( copy );
541
542 if( unselect )
543 {
544 item->ClearSelected();
545 item->RunOnChildren( []( SCH_ITEM* aChild ) { aChild->ClearSelected(); } );
546 }
547
548 // Special cases for items which have instance data
549 if( item->GetParent() && item->GetParent()->Type() == SCH_SYMBOL_T
550 && item->Type() == SCH_FIELD_T )
551 {
552 SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
553 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item->GetParent() );
554
555 if( field->GetId() == REFERENCE_FIELD )
556 {
557 SCH_SHEET_PATH sheet = schematic->GetSheets().FindSheetForScreen( screen );
558 symbol->SetRef( &sheet, field->GetText() );
559 }
560 }
561
562 // This must be called before any calls that require stable object pointers.
563 screen->Update( item );
564
565 // This hack is to prevent incorrectly parented symbol pins from breaking the
566 // connectivity algorithm.
567 if( item->Type() == SCH_SYMBOL_T )
568 {
569 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
570 symbol->UpdatePins();
571
572 CONNECTION_GRAPH* graph = schematic->ConnectionGraph();
573
574 SCH_SYMBOL* symbolCopy = static_cast<SCH_SYMBOL*>( copy );
575 graph->RemoveItem( symbolCopy );
576
577 for( SCH_PIN* pin : symbolCopy->GetPins() )
578 graph->RemoveItem( pin );
579 }
580
581 item->SetConnectivityDirty();
582
583 if( view )
584 view->Add( item );
585
586 delete copy;
587 break;
588 }
589
590 default:
591 wxASSERT( false );
592 break;
593 }
594 }
595
596 if( schematic )
597 {
598 if( bulkAddedItems.size() > 0 )
599 schematic->OnItemsAdded( bulkAddedItems );
600
601 if( bulkRemovedItems.size() > 0 )
602 schematic->OnItemsRemoved( bulkRemovedItems );
603
604 if( itemsChanged.size() > 0 )
605 schematic->OnItemsChanged( itemsChanged );
606 }
607
608 if( selTool )
609 selTool->RebuildSelection();
610
611 if( frame )
612 {
613 frame->RecalculateConnections( nullptr, NO_CLEANUP );
614 }
615
616 clear();
617}
618
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:74
virtual COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr)
Definition: commit.cpp:48
bool Empty() const
Returns status of an item.
Definition: commit.h:144
void clear()
Definition: commit.h:165
std::vector< COMMIT_LINE > m_changes
Definition: commit.h:195
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 base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
void ClearSelected()
Definition: eda_item.h:118
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:125
bool IsSelected() const
Definition: eda_item.h:106
void SetSelected()
Definition: eda_item.h:115
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:172
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:82
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:127
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
A foundation class for a tool operating on a schematic or symbol.
Definition: ee_tool_base.h:48
bool IsSymbolEditor() const
Returns true if the tool is running in the symbol editor.
Definition: ee_tool_base.h:99
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:264
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:258
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:68
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:315
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:354
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:1639
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
Define a library symbol object.
Definition: lib_symbol.h:99
void RunOnChildren(const std::function< void(LIB_ITEM *)> &aFunction)
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:545
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:75
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:749
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:755
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:146
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:100
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:761
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.
bool m_isLibEditor
Definition: sch_commit.h:76
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:393
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr) override
Definition: sch_commit.cpp:69
virtual void Revert() override
Definition: sch_commit.cpp:474
TOOL_MANAGER * m_toolMgr
Definition: sch_commit.h:75
SCH_COMMIT(TOOL_MANAGER *aToolMgr)
Definition: sch_commit.cpp:41
virtual ~SCH_COMMIT()
Definition: sch_commit.cpp:64
void pushLibEdit(const wxString &aMessage, int aCommitFlags)
Definition: sch_commit.cpp:118
void revertLibEdit()
Definition: sch_commit.cpp:448
EDA_ITEM * makeImage(EDA_ITEM *aItem) const override
Definition: sch_commit.cpp:419
EDA_ITEM * parentObject(EDA_ITEM *aItem) const override
Definition: sch_commit.cpp:402
void pushSchEdit(const wxString &aMessage, int aCommitFlags)
Definition: sch_commit.cpp:176
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)
Generate the connection data for the entire schematic hierarchy.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:52
int GetId() const
Definition: sch_field.h:128
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:165
virtual bool IsConnectable() const
Definition: sch_item.h:389
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:511
virtual void SwapData(SCH_ITEM *aItem)
Swap the internal data structures aItem with the schematic item.
Definition: sch_item.cpp:261
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:455
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:472
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:150
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:320
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:313
bool CheckIfOnDrawList(const SCH_ITEM *aItem) const
Definition: sch_screen.cpp:383
SCH_SHEET_PATH FindSheetForScreen(const SCH_SCREEN *aScreen)
Return the first SCH_SHEET_PATH object (not necessarily the only one) using a particular screen.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition: sch_symbol.h:109
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
Definition: sch_symbol.cpp:341
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:793
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
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:145
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
Master controller class:
Definition: tool_manager.h:57
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:389
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:378
CHANGE_TYPE
Types of changes.
Definition: commit.h:41
@ CHT_MODIFY
Definition: commit.h:44
@ CHT_REMOVE
Definition: commit.h:43
@ CHT_DONE
Flag to indicate the change is already applied.
Definition: commit.h:49
@ CHT_TYPE
Definition: commit.h:47
@ CHT_ADD
Definition: commit.h:42
@ CHT_FLAGS
Definition: commit.h:50
#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:42
#define SKIP_UNDO
Definition: sch_commit.h:40
SCH_CLEANUP_FLAGS
@ LOCAL_CLEANUP
@ NO_CLEANUP
@ GLOBAL_CLEANUP
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition: tool_action.h:48
@ TA_MODEL_CHANGE
Definition: tool_event.h:120
@ TC_MESSAGE
Definition: tool_event.h:57
@ LIB_SYMBOL_T
Definition: typeinfo.h:202
@ SCH_SYMBOL_T
Definition: typeinfo.h:160
@ SCH_FIELD_T
Definition: typeinfo.h:159
@ SCH_SHEET_T
Definition: typeinfo.h:162
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...