KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_design_block_utils.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 <pgm_base.h>
25#include <kiway.h>
26#include <design_block.h>
29#include <sch_edit_frame.h>
30#include <sch_group.h>
31#include <wx/choicdlg.h>
32#include <wx/msgdlg.h>
33#include <wx/textdlg.h>
35#include <paths.h>
36#include <env_paths.h>
37#include <common.h>
38#include <kidialog.h>
39#include <confirm.h>
40#include <tool/actions.h>
41#include <tool/tool_manager.h>
42#include <sch_selection_tool.h>
44#include <json_common.h>
45
46bool checkOverwriteDb( wxWindow* aFrame, wxString& libname, wxString& newName )
47{
48 wxString msg = wxString::Format( _( "Design block '%s' already exists in library '%s'." ),
49 newName.GetData(),
50 libname.GetData() );
51
52 if( OKOrCancelDialog( aFrame, _( "Confirmation" ), msg, _( "Overwrite existing design block?" ), _( "Overwrite" ) )
53 != wxID_OK )
54 {
55 return false;
56 }
57
58 return true;
59}
60
61
62bool checkOverwriteDbSchematic( wxWindow* aFrame, const LIB_ID& aLibId )
63{
64 wxString msg = wxString::Format( _( "Design block '%s' already has a schematic." ),
65 aLibId.GetUniStringLibItemName() );
66
67 if( OKOrCancelDialog( aFrame, _( "Confirmation" ), msg, _( "Overwrite existing schematic?" ), _( "Overwrite" ) )
68 != wxID_OK )
69 {
70 return false;
71 }
72
73 return true;
74}
75
76
77bool SCH_EDIT_FRAME::SaveSheetAsDesignBlock( const wxString& aLibraryName, SCH_SHEET_PATH& aSheetPath )
78{
79 // Make sure the user has selected a library to save into
80 if( m_designBlocksPane->GetSelectedLibId().GetLibNickname().empty() )
81 {
82 DisplayErrorMessage( this, _( "Please select a library to save the design block to." ) );
83 return false;
84 }
85
86 // Just block all attempts to create design blocks with nested sheets at this point
87 std::vector<SCH_ITEM*> sheets;
88 aSheetPath.LastScreen()->GetSheets( &sheets );
89
90 if( !sheets.empty() )
91 {
92 DisplayErrorMessage( this, _( "Design blocks with nested sheets are not supported." ) );
93 return false;
94 }
95
96 DESIGN_BLOCK blk;
97 wxFileName fn = wxFileNameFromPath( aSheetPath.Last()->GetName() );
98
99 blk.SetLibId( LIB_ID( aLibraryName, fn.GetName() ) );
100
101 // Copy all fields from the sheet to the design block
102 for( SCH_FIELD& field : aSheetPath.Last()->GetFields() )
103 {
104 if( field.GetId() == FIELD_T::SHEET_NAME || field.GetId() == FIELD_T::SHEET_FILENAME )
105 continue;
106
107 blk.GetFields()[field.GetCanonicalName()] = field.GetText();
108 }
109
110 DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, &blk );
111
112 if( dlg.ShowModal() != wxID_OK )
113 return false;
114
115 wxString libName = blk.GetLibId().GetLibNickname();
116 wxString newName = blk.GetLibId().GetLibItemName();
117
118 if( Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !checkOverwriteDb( this, libName, newName ) )
119 return false;
120
121 // Save a temporary copy of the schematic file, as the plugin is just going to move it
122 wxString tempFile = wxFileName::CreateTempFileName( "design_block" );
123
124 if( !saveSchematicFile( aSheetPath.Last(), tempFile ) )
125 {
126 DisplayErrorMessage( this, _( "Error saving temporary schematic file to create design block." ) );
127 wxRemoveFile( tempFile );
128 return false;
129 }
130
131 blk.SetSchematicFile( tempFile );
132
133 bool success = false;
134
135 try
136 {
137 success = Prj().DesignBlockLibs()->SaveDesignBlock( aLibraryName, &blk )
139 }
140 catch( const IO_ERROR& ioe )
141 {
142 DisplayError( this, ioe.What() );
143 }
144
145 // Clean up the temporary file
146 wxRemoveFile( tempFile );
147
148 m_designBlocksPane->RefreshLibs();
149 m_designBlocksPane->SelectLibId( blk.GetLibId() );
150
151 return success;
152}
153
154
156{
157 // Make sure the user has selected a library to save into
158 if( !Prj().DesignBlockLibs()->DesignBlockExists( aLibId.GetLibNickname(), aLibId.GetLibItemName() ) )
159 {
160 DisplayErrorMessage( this, _( "Please select a design block to save the schematic to." ) );
161 return false;
162 }
163
164 // Just block all attempts to create design blocks with nested sheets at this point
165 std::vector<SCH_ITEM*> sheets;
166 aSheetPath.LastScreen()->GetSheets( &sheets );
167
168 if( !sheets.empty() )
169 {
170 DisplayErrorMessage( this, _( "Design blocks with nested sheets are not supported." ) );
171 return false;
172 }
173
174 std::unique_ptr<DESIGN_BLOCK> blk;
175
176 try
177 {
178 blk.reset( Prj().DesignBlockLibs()->LoadDesignBlock( aLibId.GetLibNickname(), aLibId.GetLibItemName() ) );
179 }
180 catch( const IO_ERROR& ioe )
181 {
182 DisplayError( this, ioe.What() );
183 return false;
184 }
185
186 if( !blk->GetSchematicFile().IsEmpty() && !checkOverwriteDbSchematic( this, aLibId ) )
187 return false;
188
189 // Copy all fields from the sheet to the design block.
190 // Note: this will overwrite any existing fields in the design block, but
191 // will leave extra fields not in this source sheet alone.
192 for( SCH_FIELD& field : aSheetPath.Last()->GetFields() )
193 {
194 if( field.GetId() == FIELD_T::SHEET_NAME || field.GetId() == FIELD_T::SHEET_FILENAME )
195 continue;
196
197 blk->GetFields()[field.GetCanonicalName()] = field.GetText();
198 }
199
200 DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, blk.get(), true );
201
202 if( dlg.ShowModal() != wxID_OK )
203 return false;
204
205 // Save a temporary copy of the schematic file, as the plugin is just going to move it
206 wxString tempFile = wxFileName::CreateTempFileName( "design_block" );
207 if( !saveSchematicFile( aSheetPath.Last(), tempFile ) )
208 {
209 DisplayErrorMessage( this, _( "Error saving temporary schematic file to create design block." ) );
210 wxRemoveFile( tempFile );
211 return false;
212 }
213
214 blk->SetSchematicFile( tempFile );
215
216 bool success = false;
217
218 try
219 {
220 success = Prj().DesignBlockLibs()->SaveDesignBlock( aLibId.GetLibNickname(), blk.get() )
222 }
223 catch( const IO_ERROR& ioe )
224 {
225 DisplayError( this, ioe.What() );
226 }
227
228 // Clean up the temporary file
229 wxRemoveFile( tempFile );
230
231 m_designBlocksPane->RefreshLibs();
232 m_designBlocksPane->SelectLibId( blk->GetLibId() );
233
234 return success;
235}
236
237
238bool SCH_EDIT_FRAME::SaveSelectionAsDesignBlock( const wxString& aLibraryName )
239{
240 // Get all selected items
241 SCH_SELECTION selection = m_toolManager->GetTool<SCH_SELECTION_TOOL>()->GetSelection();
242
243 if( selection.Empty() )
244 {
245 DisplayErrorMessage( this, _( "Please select some items to save as a design block." ) );
246 return false;
247 }
248
249 // Make sure the user has selected a library to save into
250 if( m_designBlocksPane->GetSelectedLibId().GetLibNickname().empty() )
251 {
252 DisplayErrorMessage( this, _( "Please select a library to save the design block to." ) );
253 return false;
254 }
255
256 // Just block all attempts to create design blocks with nested sheets at this point
257 if( selection.HasType( SCH_SHEET_T ) )
258 {
259 if( selection.Size() == 1 )
260 {
261 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( selection.Front() );
263
264 curPath.push_back( sheet );
265 SaveSheetAsDesignBlock( aLibraryName, curPath );
266 }
267 else
268 {
269 DisplayErrorMessage( this, _( "Design blocks with nested sheets are not supported." ) );
270 }
271
272 return false;
273 }
274
275 DESIGN_BLOCK blk;
276 SCH_GROUP* group = nullptr;
277
278 if( selection.Size() == 1 && selection.HasType( SCH_GROUP_T ) )
279 group = static_cast<SCH_GROUP*>( selection.Front() );
280
281 if( group && !group->GetName().IsEmpty() )
282 // If the user has selected a single group, they probably want the design block named after the group
283 blk.SetLibId( LIB_ID( aLibraryName, group->GetName() ) );
284 else
285 {
286 // Otherwise, use the current screen name
287 wxFileName fn = wxFileNameFromPath( GetScreen()->GetFileName() );
288 blk.SetLibId( LIB_ID( aLibraryName, fn.GetName() ) );
289 }
290
291 DIALOG_DESIGN_BLOCK_PROPERTIES dlg( this, &blk );
292
293 if( dlg.ShowModal() != wxID_OK )
294 return false;
295
296 wxString libName = blk.GetLibId().GetLibNickname();
297 wxString newName = blk.GetLibId().GetLibItemName();
298
299 if( Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !checkOverwriteDb( this, libName, newName ) )
300 return false;
301
302 // Create a temporary screen
303 SCH_SCREEN* tempScreen = new SCH_SCREEN( m_schematic );
304
305 // If we have a single group, we want to strip the group and select the children
306 if( group )
307 {
308 selection.Remove( group );
309
310 // Don't recurse; if we have a group of groups the user probably intends the inner groups to be saved
311 group->RunOnChildren(
312 [&]( EDA_ITEM* aItem )
313 {
314 selection.Add( aItem );
315 },
317 }
318
319 // Copy the selected items to the temporary screen
320 for( EDA_ITEM* item : selection )
321 {
322 // We need to deep copy since selections of groups will not have the children
323 if( item->Type() == SCH_GROUP_T )
324 {
325 SCH_GROUP* clonedGroup = static_cast<SCH_GROUP*>( item )->DeepClone();
326
327 tempScreen->Append( clonedGroup );
328
329 clonedGroup->RunOnChildren(
330 [&]( EDA_ITEM* aItem )
331 {
332 tempScreen->Append( static_cast<SCH_ITEM*>( aItem ) );
333 },
335 }
336 else if( item->Type() == SCH_SYMBOL_T )
337 {
338 SCH_SYMBOL* clonedSymbol = static_cast<SCH_SYMBOL*>( item->Clone() );
339 tempScreen->Append( clonedSymbol );
340 }
341 else if( item->Type() == SCH_PIN_T || item->Type() == SCH_FIELD_T )
342 {
343 // Handled as symbol children
344 continue;
345 }
346 else
347 {
348 EDA_ITEM* copy = item->Clone();
349 tempScreen->Append( static_cast<SCH_ITEM*>( copy ) );
350 }
351 }
352
353 // Create a sheet for the temporary screen
354 SCH_SHEET* tempSheet = new SCH_SHEET( m_schematic );
355 tempSheet->SetScreen( tempScreen );
356
357 // Save a temporary copy of the schematic file, as the plugin is just going to move it
358 wxString tempFile = wxFileName::CreateTempFileName( "design_block" );
359 if( !saveSchematicFile( tempSheet, tempFile ) )
360 {
361 DisplayErrorMessage( this, _( "Error saving temporary schematic file to create design block." ) );
362 wxRemoveFile( tempFile );
363 return false;
364 }
365
366 blk.SetSchematicFile( tempFile );
367
368 bool success = false;
369
370 try
371 {
372 success = Prj().DesignBlockLibs()->SaveDesignBlock( aLibraryName, &blk )
374 }
375 catch( const IO_ERROR& ioe )
376 {
377 DisplayError( this, ioe.What() );
378 }
379
380 if( success && !group )
381 {
382 SCH_COMMIT commit( m_toolManager );
383 SCH_SCREEN* screen = GetScreen();
384
385 SCH_GROUP* newGroup = new SCH_GROUP;
386 newGroup->SetParent( screen );
387 newGroup->SetName( blk.GetLibId().GetUniStringLibItemName() );
388 newGroup->SetDesignBlockLibId( blk.GetLibId() );
389
390 bool added = false;
391
392 for( EDA_ITEM* edaItem : selection )
393 {
394 if( !edaItem->IsSCH_ITEM() )
395 continue;
396
397 SCH_ITEM* item = static_cast<SCH_ITEM*>( edaItem );
398
399 if( item->GetParentSymbol() )
400 continue;
401
402 if( !item->IsGroupableType() )
403 continue;
404
405 if( EDA_GROUP* existingGroup = item->GetParentGroup() )
406 commit.Modify( existingGroup->AsEdaItem(), screen, RECURSE_MODE::NO_RECURSE );
407
408 commit.Modify( item, screen, RECURSE_MODE::NO_RECURSE );
409 newGroup->AddItem( item );
410 added = true;
411 }
412
413 if( added )
414 {
415 commit.Add( newGroup, screen );
416 commit.Push( _( "Group Items" ) );
417
419 m_toolManager->RunAction( ACTIONS::selectItem, newGroup->AsEdaItem() );
420 }
421 else
422 {
423 delete newGroup;
424 }
425 }
426 else if( success && group && !group->HasDesignBlockLink() )
427 {
428 SCH_COMMIT commit( m_toolManager );
429
430 commit.Modify( group, GetScreen() );
431 group->SetDesignBlockLibId( blk.GetLibId() );
432
433 commit.Push( _( "Set Group Design Block Link" ) );
434 }
435
436 // Clean up the temporaries
437 wxRemoveFile( tempFile );
438 // This will also delete the screen
439 delete tempSheet;
440
441 m_designBlocksPane->RefreshLibs();
442 m_designBlocksPane->SelectLibId( blk.GetLibId() );
443
444 return success;
445}
446
447
449{
450 // Get all selected items
451 SCH_SELECTION selection = m_toolManager->GetTool<SCH_SELECTION_TOOL>()->GetSelection();
452
453 if( selection.Empty() )
454 {
455 DisplayErrorMessage( this, _( "Please select some items to save as a design block." ) );
456 return false;
457 }
458
459 // Make sure the user has selected a library to save into
460 if( !Prj().DesignBlockLibs()->DesignBlockExists( aLibId.GetLibNickname(), aLibId.GetLibItemName() ) )
461 {
462 DisplayErrorMessage( this, _( "Please select a design block to save the schematic to." ) );
463 return false;
464 }
465
466 // Just block all attempts to create design blocks with nested sheets at this point
467 if( selection.HasType( SCH_SHEET_T ) )
468 {
469 if( selection.Size() == 1 )
470 {
471 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( selection.Front() );
473
474 curPath.push_back( sheet );
475 UpdateDesignBlockFromSheet( aLibId, curPath );
476 }
477 else
478 {
479 DisplayErrorMessage( this, _( "Design blocks with nested sheets are not supported." ) );
480 }
481
482 return false;
483 }
484
485 // If we have a single group, we want to strip the group and select the children
486 SCH_GROUP* group = nullptr;
487
488 if( selection.Size() == 1 )
489 {
490 EDA_ITEM* item = selection.Front();
491
492 if( item->Type() == SCH_GROUP_T )
493 {
494 group = static_cast<SCH_GROUP*>( item );
495
496 selection.Remove( group );
497
498 // Don't recurse; if we have a group of groups the user probably intends the inner groups to be saved
499 group->RunOnChildren( [&]( EDA_ITEM* aItem )
500 {
501 selection.Add( aItem );
502 },
504 }
505 }
506
507 std::unique_ptr<DESIGN_BLOCK> blk;
508
509 try
510 {
511 blk.reset( Prj().DesignBlockLibs()->LoadDesignBlock( aLibId.GetLibNickname(), aLibId.GetLibItemName() ) );
512 }
513 catch( const IO_ERROR& ioe )
514 {
515 DisplayError( this, ioe.What() );
516 return false;
517 }
518
519 if( !blk->GetSchematicFile().IsEmpty() && !checkOverwriteDbSchematic( this, aLibId ) )
520 return false;
521
522 // Create a temporary screen
523 SCH_SCREEN* tempScreen = new SCH_SCREEN( m_schematic );
524
525 auto cloneAndAdd =
526 [&] ( EDA_ITEM* aItem ) -> SCH_ITEM*
527 {
528 if( !aItem->IsSCH_ITEM() )
529 return nullptr;
530
531 SCH_ITEM* copy = static_cast<SCH_ITEM*>( aItem->Clone() );
532 tempScreen->Append( static_cast<SCH_ITEM*>( copy ) );
533 return copy;
534 };
535
536 // Copy the selected items to the temporary board
537 for( EDA_ITEM* item : selection )
538 {
539 // Remove parent group membership since we strip the first group layer
540 if( SCH_ITEM* copy = cloneAndAdd( item ) )
541 copy->SetParentGroup( nullptr );
542
543 if( item->Type() == SCH_GROUP_T )
544 {
545 SCH_GROUP* innerGroup = static_cast<SCH_GROUP*>( item );
546
547 // Groups also need their children copied
548 innerGroup->RunOnChildren( cloneAndAdd, RECURSE_MODE::RECURSE );
549 }
550 }
551
552 // Create a sheet for the temporary screen
553 SCH_SHEET* tempSheet = new SCH_SHEET( m_schematic );
554 tempSheet->SetScreen( tempScreen );
555
556 // Save a temporary copy of the schematic file, as the plugin is just going to move it
557 wxString tempFile = wxFileName::CreateTempFileName( "design_block" );
558
559 if( !saveSchematicFile( tempSheet, tempFile ) )
560 {
561 DisplayErrorMessage( this, _( "Error saving temporary schematic file to create design block." ) );
562 wxRemoveFile( tempFile );
563 return false;
564 }
565
566 blk->SetSchematicFile( tempFile );
567
568 bool success = false;
569
570 try
571 {
572 success = Prj().DesignBlockLibs()->SaveDesignBlock( aLibId.GetLibNickname(), blk.get() )
574
575 // If we had a group, we need to reselect it
576 if( group )
577 {
578 selection.Clear();
579 selection.Add( group );
580
581 // If we didn't have a design block link before, add one for convenience
582 if( !group->HasDesignBlockLink() )
583 {
584 SCH_COMMIT commit( m_toolManager );
585
586 commit.Modify( group, GetScreen() );
587 group->SetDesignBlockLibId( aLibId );
588
589 commit.Push( _( "Set Group Design Block Link" ) );
590 }
591 }
592 }
593 catch( const IO_ERROR& ioe )
594 {
595 DisplayError( this, ioe.What() );
596 }
597
598 if( success && !group )
599 {
600 SCH_COMMIT commit( m_toolManager );
601 SCH_SCREEN* screen = GetScreen();
602
603 SCH_GROUP* newGroup = new SCH_GROUP;
604 newGroup->SetParent( screen );
605 newGroup->SetName( aLibId.GetUniStringLibItemName() );
606 newGroup->SetDesignBlockLibId( aLibId );
607
608 bool added = false;
609
610 for( EDA_ITEM* edaItem : selection )
611 {
612 if( !edaItem->IsSCH_ITEM() )
613 continue;
614
615 SCH_ITEM* item = static_cast<SCH_ITEM*>( edaItem );
616
617 if( item->GetParentSymbol() )
618 continue;
619
620 if( !item->IsGroupableType() )
621 continue;
622
623 if( EDA_GROUP* existingGroup = item->GetParentGroup() )
624 commit.Modify( existingGroup->AsEdaItem(), screen, RECURSE_MODE::NO_RECURSE );
625
626 commit.Modify( item, screen, RECURSE_MODE::NO_RECURSE );
627 newGroup->AddItem( item );
628 added = true;
629 }
630
631 if( added )
632 {
633 commit.Add( newGroup, screen );
634 commit.Push( _( "Group Items" ) );
635
637 m_toolManager->RunAction( ACTIONS::selectItem, newGroup->AsEdaItem() );
638 }
639 else
640 {
641 delete newGroup;
642 }
643 }
644
645 // Clean up the temporaries
646 wxRemoveFile( tempFile );
647 // This will also delete the screen
648 delete tempSheet;
649
650 m_designBlocksPane->RefreshLibs();
651 m_designBlocksPane->SelectLibId( blk->GetLibId() );
652
653 return success;
654}
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition actions.h:227
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:224
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
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition commit.h:78
SAVE_T SaveDesignBlock(const wxString &aNickname, const DESIGN_BLOCK *aDesignBlock, bool aOverwrite=true)
Write aDesignBlock to an existing library given by aNickname.
void SetSchematicFile(const wxString &aFile)
void SetLibId(const LIB_ID &aName)
const LIB_ID & GetLibId() const
const nlohmann::ordered_map< wxString, wxString > & GetFields() const
int ShowModal() override
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:46
void SetDesignBlockLibId(const LIB_ID &aLibId)
Definition eda_group.h:72
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:27
void SetName(const wxString &aName)
Definition eda_group.h:52
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.h:113
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
Definition lib_id.h:112
const UTF8 & GetLibItemName() const
Definition lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:87
virtual DESIGN_BLOCK_LIBRARY_ADAPTER * DesignBlockLibs()
Return the table of design block libraries.
Definition project.cpp:417
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
bool UpdateDesignBlockFromSelection(const LIB_ID &aLibId)
SCHEMATIC * m_schematic
The currently loaded schematic.
SCH_SHEET_PATH & GetCurrentSheet() const
bool saveSchematicFile(SCH_SHEET *aSheet, const wxString &aSavePath)
Save aSheet to a schematic file.
SCH_DESIGN_BLOCK_PANE * m_designBlocksPane
bool SaveSheetAsDesignBlock(const wxString &aLibraryName, SCH_SHEET_PATH &aSheetPath)
bool UpdateDesignBlockFromSheet(const LIB_ID &aLibId, SCH_SHEET_PATH &aSheetPath)
bool SaveSelectionAsDesignBlock(const wxString &aLibraryName)
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:52
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode) override
EDA_ITEM * AsEdaItem() override
Definition sch_group.h:60
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:253
bool IsGroupableType() const
Definition sch_item.cpp:108
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
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,...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
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.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
Definition sch_sheet.h:88
wxString GetName() const
Definition sch_sheet.h:142
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Schematic symbol object.
Definition sch_symbol.h:76
virtual void Add(EDA_ITEM *aItem)
Definition selection.cpp:42
virtual void Remove(EDA_ITEM *aItem)
Definition selection.cpp:60
EDA_ITEM * Front() const
Definition selection.h:177
virtual void Clear() override
Remove all the stored items from the group.
Definition selection.h:98
bool HasType(KICAD_T aType) const
Checks if there is at least one item of requested kind.
int Size() const
Returns the number of selected parts.
Definition selection.h:121
bool Empty() const
Checks if there is anything selected.
Definition selection.h:115
TOOL_MANAGER * m_toolManager
The common library.
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
Definition confirm.cpp:150
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:202
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:177
This file is part of the common library.
#define _(s)
@ RECURSE
Definition eda_item.h:51
@ NO_RECURSE
Definition eda_item.h:52
Helper functions to substitute paths with environmental variables.
PROJECT & Prj()
Definition kicad.cpp:637
see class PGM_BASE
bool checkOverwriteDb(wxWindow *aFrame, wxString &libname, wxString &newName)
bool checkOverwriteDbSchematic(wxWindow *aFrame, const LIB_ID &aLibId)
Class to handle a set of SCH_ITEMs.
@ SCH_GROUP_T
Definition typeinfo.h:177
@ SCH_SYMBOL_T
Definition typeinfo.h:176
@ SCH_FIELD_T
Definition typeinfo.h:154
@ SCH_SHEET_T
Definition typeinfo.h:179
@ SCH_PIN_T
Definition typeinfo.h:157
Definition of file extensions used in Kicad.