KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_sch_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 (C) 2024 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <algorithm>
22#include <set>
23#include <trace_helpers.h>
24
25#include <sch_pin.h>
26#include <lib_symbol.h>
27#include <schematic.h>
28#include <sch_symbol.h>
29#include <sch_bitmap.h>
30#include <sch_bus_entry.h>
31#include <sch_field.h>
32#include <sch_group.h>
33#include <sch_junction.h>
34#include <sch_label.h>
35#include <sch_line.h>
36#include <sch_no_connect.h>
37#include <sch_rule_area.h>
38#include <sch_shape.h>
39#include <sch_sheet.h>
40#include <sch_sheet_path.h>
41#include <sch_screen.h>
42#include <sch_sheet_pin.h>
43#include <sch_table.h>
44#include <sch_tablecell.h>
45#include <sch_text.h>
46#include <sch_textbox.h>
47
48#include "api_sch_utils.h"
49
50#include <api/api_utils.h>
51#include <api/api_enums.h>
52
53
54using namespace kiapi::common;
55
56
57std::unique_ptr<EDA_ITEM> CreateItemForType( KICAD_T aType, EDA_ITEM* aContainer )
58{
59 SCH_ITEM* parentSchItem = dynamic_cast<SCH_ITEM*>( aContainer );
60
61 switch( aType )
62 {
63 case SCH_JUNCTION_T: return std::make_unique<SCH_JUNCTION>();
64 case SCH_NO_CONNECT_T: return std::make_unique<SCH_NO_CONNECT>();
65 case SCH_BUS_WIRE_ENTRY_T: return std::make_unique<SCH_BUS_WIRE_ENTRY>();
66 case SCH_BUS_BUS_ENTRY_T: return std::make_unique<SCH_BUS_BUS_ENTRY>();
67 case SCH_LINE_T: return std::make_unique<SCH_LINE>();
68 case SCH_SHAPE_T: return std::make_unique<SCH_SHAPE>();
69 case SCH_BITMAP_T: return std::make_unique<SCH_BITMAP>();
70 case SCH_TEXTBOX_T: return std::make_unique<SCH_TEXTBOX>();
71 case SCH_TEXT_T: return std::make_unique<SCH_TEXT>();
72 case SCH_TABLE_T: return std::make_unique<SCH_TABLE>();
73 case SCH_TABLECELL_T: return std::make_unique<SCH_TABLECELL>();
74 case SCH_LABEL_T: return std::make_unique<SCH_LABEL>();
75 case SCH_GLOBAL_LABEL_T: return std::make_unique<SCH_GLOBALLABEL>();
76 case SCH_HIER_LABEL_T: return std::make_unique<SCH_HIERLABEL>();
77 case SCH_DIRECTIVE_LABEL_T: return std::make_unique<SCH_DIRECTIVE_LABEL>();
78 case SCH_RULE_AREA_T: return std::make_unique<SCH_RULE_AREA>();
79 case SCH_FIELD_T: return std::make_unique<SCH_FIELD>( parentSchItem );
80 case SCH_GROUP_T: return std::make_unique<SCH_GROUP>();
81 case SCH_SYMBOL_T: return std::make_unique<SCH_SYMBOL>();
82 case LIB_SYMBOL_T: return std::make_unique<LIB_SYMBOL>( wxEmptyString );
83 case SCH_SHEET_T:
84 {
85 if( aContainer && aContainer->Type() == SCH_SCREEN_T )
86 return std::make_unique<SCH_SHEET>( static_cast<SCH_SCREEN*>( aContainer ) );
87
88 return nullptr;
89 }
90
91
92 case SCH_SHEET_PIN_T:
93 if( aContainer && aContainer->Type() == SCH_SHEET_T )
94 return std::make_unique<SCH_SHEET_PIN>( static_cast<SCH_SHEET*>( aContainer ) );
95
96 return nullptr;
97
98 case SCH_PIN_T:
99 if( aContainer && aContainer->Type() == LIB_SYMBOL_T )
100 return std::make_unique<SCH_PIN>( static_cast<LIB_SYMBOL*>( aContainer ) );
101
102 return nullptr;
103
104 default:
105 return nullptr;
106 }
107}
108
109
110void PackPinMapOverride( kiapi::schematic::types::PinMapInstanceOverride* aOutput,
111 const PIN_MAP_INSTANCE_OVERRIDE& aOverride )
112{
113 aOutput->Clear();
114 aOutput->set_mode(
116 aOutput->set_active_map_name( aOverride.m_ActiveMapName.ToUTF8() );
117
118 for( const PIN_MAP_ENTRY& edit : aOverride.m_Edits )
119 {
120 kiapi::schematic::types::PinMapEntry* e = aOutput->add_edits();
121 e->set_pin_number( edit.m_PinNumber.ToUTF8() );
122 e->set_pad_number( edit.m_PadNumber.ToUTF8() );
123 }
124}
125
126
127PIN_MAP_INSTANCE_OVERRIDE UnpackPinMapOverride( const kiapi::schematic::types::PinMapInstanceOverride& aInput )
128{
130 override.m_Mode = FromProtoEnum<PIN_MAP_OVERRIDE_MODE>( aInput.mode() );
131 override.m_ActiveMapName = wxString::FromUTF8( aInput.active_map_name() );
132
133 for( const kiapi::schematic::types::PinMapEntry& e : aInput.edits() )
134 {
135 override.m_Edits.push_back( { wxString::FromUTF8( e.pin_number() ), wxString::FromUTF8( e.pad_number() ) } );
136 }
137
138 return override;
139}
140
141
142bool PackSymbol( kiapi::schematic::types::SchematicSymbolInstance* aOutput, const SCH_SYMBOL* aInput,
143 const SCH_SHEET_PATH& aPath )
144{
145 KIID_PATH path = aPath.Path();
146 SCH_SYMBOL_INSTANCE instance;
147
148 if( !aInput->GetInstance( instance, path ) )
149 {
150 wxLogTrace( traceApi, "error: instance data for symbol %s on %s is missing",
151 aInput->m_Uuid.AsString(), aPath.PathHumanReadable() );
152 return false;
153 }
154
155 google::protobuf::Any any;
156 aInput->Serialize( any );
157
158 if( !any.UnpackTo( aOutput ) )
159 return false;
160
161 PackSheetPath( *aOutput->mutable_path(), aPath );
162 aOutput->mutable_reference_field()->mutable_text()->set_text( instance.m_Reference.ToUTF8() );
163 aOutput->mutable_unit()->set_unit( instance.m_Unit );
164
165 kiapi::schematic::types::SchematicSymbol* def = aOutput->mutable_definition();
166
167 std::vector<const SCH_PIN*> pins = aInput->GetPins( &aPath );
168
169 std::ranges::sort( pins,
170 []( const SCH_PIN* a, const SCH_PIN* b )
171 {
172 return a->m_Uuid < b->m_Uuid;
173 } );
174
175 for( const SCH_PIN* pin : pins )
176 {
177 kiapi::schematic::types::SchematicSymbolChild* item = def->add_items();
178 item->mutable_unit()->set_unit( pin->GetUnit() );
179 item->mutable_body_style()->set_style( pin->GetBodyStyle() );
180 item->set_is_private( pin->IsPrivate() );
181 pin->Serialize( *item->mutable_item() );
182 }
183
184 // Also include the pins from non-placed units
185 if( const LIB_SYMBOL* lib = aInput->GetLibSymbolRef().get() )
186 {
187 std::set<wxString> placedNumbers;
188
189 for( const SCH_PIN* pin : pins )
190 placedNumbers.insert( pin->GetNumber() );
191
192 for( const SCH_PIN* libPin : lib->GetPins() )
193 {
194 if( libPin->GetBodyStyle() && aInput->GetBodyStyle()
195 && aInput->GetBodyStyle() != libPin->GetBodyStyle() )
196 {
197 continue;
198 }
199
200 if( placedNumbers.count( libPin->GetNumber() ) )
201 continue;
202
203 kiapi::schematic::types::SchematicSymbolChild* item = def->add_items();
204 item->mutable_unit()->set_unit( libPin->GetUnit() );
205 item->mutable_body_style()->set_style( libPin->GetBodyStyle() );
206 item->set_is_private( libPin->IsPrivate() );
207 libPin->Serialize( *item->mutable_item() );
208 }
209 }
210
211 PIN_MAP_INSTANCE_OVERRIDE override = aInput->GetPinMapOverride( &aPath );
212
213 if( !override.IsDefault() )
214 PackPinMapOverride( aOutput->mutable_pin_map_override(), override );
215
216 kiapi::schematic::types::SchematicSymbolAttributes* attributes = aOutput->mutable_attributes();
217
218 attributes->set_exclude_from_simulation( aInput->GetExcludedFromSim() );
219 attributes->set_exclude_from_bill_of_materials( aInput->GetExcludedFromBOM() );
220 attributes->set_exclude_from_board( aInput->GetExcludedFromBoard() );
221 attributes->set_exclude_from_position_files( aInput->GetExcludedFromPosFiles() );
222 attributes->set_do_not_populate( aInput->GetDNP() );
223
224 // Descriptions belong to the schematic's variant registry rather than to each record.
225 SCHEMATIC* schematic = aInput->Schematic();
226
227 // Always set, so that sending the response back describes the placement's variants in full.
228 kiapi::schematic::types::SchematicSymbolVariants* variants = aOutput->mutable_variants();
229
230 for( const auto& [name, variantInfo] : instance.m_Variants )
231 {
232 kiapi::schematic::types::SchematicSymbolVariant* variant = variants->add_variants();
233 variant->set_name( name.ToUTF8() );
234
235 if( schematic )
236 variant->set_description( schematic->GetVariantDescription( name ).ToUTF8() );
237
238 attributes = variant->mutable_attributes();
239 attributes->set_exclude_from_simulation( variantInfo.m_ExcludedFromSim );
240 attributes->set_exclude_from_bill_of_materials( variantInfo.m_ExcludedFromBOM );
241 attributes->set_exclude_from_board( variantInfo.m_ExcludedFromBoard );
242 attributes->set_exclude_from_position_files( variantInfo.m_ExcludedFromPosFiles );
243 attributes->set_do_not_populate( variantInfo.m_DNP );
244
245 for( const auto& [key, value] : variantInfo.m_Fields )
246 ( *variant->mutable_fields() )[std::string( key.ToUTF8() )] = value.ToUTF8();
247
248 if( variantInfo.m_SymbolOverride )
249 PackLibId( variant->mutable_symbol_override(), *variantInfo.m_SymbolOverride );
250
251 if( !variantInfo.m_PinMapOverride.IsDefault() )
252 PackPinMapOverride( variant->mutable_pin_map_override(), variantInfo.m_PinMapOverride );
253 }
254
255 return true;
256}
257
258
259bool UnpackSymbol( SCH_SYMBOL* aOutput, const kiapi::schematic::types::SchematicSymbolInstance& aInput )
260{
261 using namespace kiapi::common::types;
262 using namespace kiapi::schematic::types;
263
264 if( !aOutput->Deserialize( aInput ) )
265 return false;
266
267 if( aInput.has_attributes() )
268 {
269 const SchematicSymbolAttributes& attrs = aInput.attributes();
270
271 aOutput->SetExcludedFromSim( attrs.exclude_from_simulation() );
272 aOutput->SetExcludedFromBOM( attrs.exclude_from_bill_of_materials() );
273 aOutput->SetExcludedFromBoard( attrs.exclude_from_board() );
274 aOutput->SetExcludedFromPosFiles( attrs.exclude_from_position_files() );
275 aOutput->SetDNP( attrs.do_not_populate() );
276 }
277
278 aOutput->SetPinMapOverride( aInput.has_pin_map_override() ? UnpackPinMapOverride( aInput.pin_map_override() )
280
281 return true;
282}
283
284
286template <typename VariantProto>
287static void registerVariant( SCHEMATIC* aSchematic, const wxString& aName,
288 const VariantProto& aInput )
289{
290 if( !aSchematic )
291 return;
292
293 aSchematic->AddVariant( aName );
294
295 // An empty description clears the one the variant has, so honour presence rather than text.
296 if( aInput.has_description() )
297 aSchematic->SetVariantDescription( aName, wxString::FromUTF8( aInput.description() ) );
298}
299
300
302static void applySymbolVariants( SCH_SYMBOL* aSymbol,
303 const kiapi::schematic::types::SchematicSymbolVariants& aInput,
304 const SCH_SHEET_PATH& aPath, SCHEMATIC* aSchematic )
305{
306 using namespace kiapi::schematic::types;
307
308 std::set<wxString> requested;
309
310 for( const SchematicSymbolVariant& variantProto : aInput.variants() )
311 {
312 wxString name = wxString::FromUTF8( variantProto.name() );
313
314 // The empty name selects the default variant, whose values are the symbol's own.
315 if( name.IsEmpty() )
316 continue;
317
318 requested.insert( name );
319 registerVariant( aSchematic, name, variantProto );
320
321 if( variantProto.has_attributes() )
322 {
323 const SchematicSymbolAttributes& attrs = variantProto.attributes();
324
325 aSymbol->SetExcludedFromSim( attrs.exclude_from_simulation(), &aPath, name );
326 aSymbol->SetExcludedFromBOM( attrs.exclude_from_bill_of_materials(), &aPath, name );
327 aSymbol->SetExcludedFromBoard( attrs.exclude_from_board(), &aPath, name );
328 aSymbol->SetExcludedFromPosFiles( attrs.exclude_from_position_files(), &aPath, name );
329 aSymbol->SetDNP( attrs.do_not_populate(), &aPath, name );
330 }
331
332 // Overrides the request dropped go back to resolving as the symbol's own value.
333 SCH_SYMBOL_INSTANCE stored;
334
335 if( aSymbol->GetInstance( stored, aPath.Path() ) && stored.m_Variants.contains( name ) )
336 {
337 for( const auto& [fieldName, unused] : stored.m_Variants[name].m_Fields )
338 {
339 if( variantProto.fields().find( std::string( fieldName.ToUTF8() ) )
340 == variantProto.fields().end() )
341 {
342 aSymbol->ClearVariantField( aPath.Path(), name, fieldName );
343 }
344 }
345 }
346
347 if( variantProto.has_symbol_override() )
348 aSymbol->SetVariantSymbolOverride( aPath, name, UnpackLibId( variantProto.symbol_override() ) );
349 else
350 aSymbol->ClearVariantSymbolOverride( aPath, name );
351
352 if( variantProto.has_pin_map_override() )
353 aSymbol->SetPinMapOverride( UnpackPinMapOverride( variantProto.pin_map_override() ), &aPath, name );
354 else
355 aSymbol->SetPinMapOverride( PIN_MAP_INSTANCE_OVERRIDE(), &aPath, name );
356
357 for( const auto& [key, value] : variantProto.fields() )
358 {
359 aSymbol->SetFieldText( wxString::FromUTF8( key ), wxString::FromUTF8( value ), &aPath,
360 name );
361 }
362 }
363
364 // Variants the request left out are removed from this placement only; the variant itself
365 // stays registered with the schematic and other placements keep theirs.
366 SCH_SYMBOL_INSTANCE stored;
367
368 if( aSymbol->GetInstance( stored, aPath.Path() ) )
369 {
370 for( const auto& [name, unused] : stored.m_Variants )
371 {
372 if( !requested.contains( name ) )
373 aSymbol->DeleteVariant( aPath.Path(), name );
374 }
375 }
376}
377
378
380 const kiapi::schematic::types::SchematicSymbolInstance& aInput,
381 const SCH_SHEET_PATH& aPath, SCHEMATIC* aSchematic )
382{
383 wxString reference = wxString::FromUTF8( aInput.reference_field().text().text() );
384 int unit = aInput.has_unit() ? aInput.unit().unit() : 1;
385 SCH_SYMBOL_INSTANCE existing;
386
387 if( aSymbol->GetInstance( existing, aPath.Path() ) )
388 {
389 if( !reference.IsEmpty() )
390 aSymbol->SetRef( &aPath, reference );
391
392 aSymbol->SetUnitSelection( &aPath, unit );
393 }
394 else
395 {
396 SCH_SYMBOL_INSTANCE instance;
397 instance.m_Path = aPath.Path();
398 instance.m_Reference = reference;
399 instance.m_Unit = unit;
400
401 aSymbol->AddHierarchicalReference( instance );
402 }
403
404 // The displayed unit follows the placement the request targeted, as it does in the editor.
405 aSymbol->SetUnit( unit );
406
407 // A request that carries no variant set leaves the placement's variants as they are.
408 if( aInput.has_variants() )
409 applySymbolVariants( aSymbol, aInput.variants(), aPath, aSchematic );
410}
411
412
413bool PackSheet( kiapi::schematic::types::SheetSymbol* aOutput, const SCH_SHEET* aInput,
414 const SCH_SHEET_PATH& aPath )
415{
416 google::protobuf::Any any;
417 aInput->Serialize( any );
418
419 if( !any.UnpackTo( aOutput ) )
420 return false;
421
422 PackSheetPath( *aOutput->mutable_path(), aPath );
423
424 SCHEMATIC* schematic = aInput->Schematic();
425
426 kiapi::schematic::types::SheetVariants* variants = aOutput->mutable_variants();
427
428 if( const SCH_SHEET_INSTANCE* instance = aInput->GetInstance( aPath.Path() ) )
429 {
430 aOutput->set_page_number( instance->m_PageNumber.ToUTF8() );
431
432 for( const auto& [name, variantInfo] : instance->m_Variants )
433 {
434 kiapi::schematic::types::SheetVariant* variant = variants->add_variants();
435 variant->set_name( name.ToUTF8() );
436
437 if( schematic )
438 variant->set_description( schematic->GetVariantDescription( name ).ToUTF8() );
439
440 variant->set_exclude_from_sim( variantInfo.m_ExcludedFromSim );
441 variant->set_exclude_from_bom( variantInfo.m_ExcludedFromBOM );
442 variant->set_dnp( variantInfo.m_DNP );
443
444 for( const auto& [key, value] : variantInfo.m_Fields )
445 ( *variant->mutable_fields() )[std::string( key.ToUTF8() )] = value.ToUTF8();
446 }
447 }
448
449 return true;
450}
451
452
456static void applySheetVariants( SCH_SHEET* aSheet,
457 const kiapi::schematic::types::SheetVariants& aInput,
458 const SCH_SHEET_PATH& aParentPath, SCHEMATIC* aSchematic )
459{
460 using namespace kiapi::schematic::types;
461
462 std::set<wxString> requested;
463
464 for( const SheetVariant& variantProto : aInput.variants() )
465 {
466 wxString name = wxString::FromUTF8( variantProto.name() );
467
468 // The empty name selects the default variant, whose values are the sheet's own.
469 if( name.IsEmpty() )
470 continue;
471
472 requested.insert( name );
473 registerVariant( aSchematic, name, variantProto );
474
475 // Each attribute the request leaves out keeps the value this variant already has.
476 if( variantProto.has_exclude_from_sim() )
477 aSheet->SetExcludedFromSim( variantProto.exclude_from_sim(), &aParentPath, name );
478
479 if( variantProto.has_exclude_from_bom() )
480 aSheet->SetExcludedFromBOM( variantProto.exclude_from_bom(), &aParentPath, name );
481
482 if( variantProto.has_dnp() )
483 aSheet->SetDNP( variantProto.dnp(), &aParentPath, name );
484
485 // Overrides the request dropped go back to resolving as the sheet's own value.
486 if( const SCH_SHEET_INSTANCE* stored = aSheet->GetInstance( aParentPath.Path() );
487 stored && stored->m_Variants.contains( name ) )
488 {
489 std::map<wxString, wxString> storedFields = stored->m_Variants.at( name ).m_Fields;
490
491 for( const auto& [fieldName, unused] : storedFields )
492 {
493 if( variantProto.fields().find( std::string( fieldName.ToUTF8() ) )
494 == variantProto.fields().end() )
495 {
496 aSheet->ClearVariantField( aParentPath.Path(), name, fieldName );
497 }
498 }
499 }
500
501 for( const auto& [key, value] : variantProto.fields() )
502 {
503 aSheet->SetFieldText( wxString::FromUTF8( key ), wxString::FromUTF8( value ),
504 &aParentPath, name );
505 }
506 }
507
508 // Remove variants from the sheet (not the schematic) that the client didn't send.
509 if( const SCH_SHEET_INSTANCE* stored = aSheet->GetInstance( aParentPath.Path() ) )
510 {
511 std::vector<wxString> obsolete;
512
513 for( const auto& [name, unused] : stored->m_Variants )
514 {
515 if( !requested.contains( name ) )
516 obsolete.push_back( name );
517 }
518
519 for( const wxString& name : obsolete )
520 aSheet->DeleteVariant( aParentPath.Path(), name );
521 }
522}
523
524
525void ApplySheetInstance( SCH_SHEET* aSheet, const kiapi::schematic::types::SheetSymbol& aInput,
526 const SCH_SHEET_PATH& aParentPath, SCHEMATIC* aSchematic )
527{
528 wxString pageNumber = wxString::FromUTF8( aInput.page_number() );
529 SCH_SHEET_PATH path( aParentPath );
530
531 path.push_back( aSheet );
532
533 // Creates the placement record when it is missing and keeps an existing one's variants; an
534 // empty page number in the request leaves the placement on the page it already has.
535 path.SetPageNumber( pageNumber.IsEmpty() ? path.GetPageNumber() : pageNumber );
536
537 // A request that carries no variant set leaves the placement's variants as they are.
538 if( aInput.has_variants() )
539 applySheetVariants( aSheet, aInput.variants(), aParentPath, aSchematic );
540}
541
542
543tl::expected<bool, ApiResponseStatus> UnpackSheet( SCH_SHEET* aOutput, const kiapi::schematic::types::SheetSymbol& aInput )
544{
545 google::protobuf::Any any;
546 any.PackFrom( aInput );
547
548 if( !aOutput->Deserialize( any ) )
549 {
550 ApiResponseStatus e;
551 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
552 e.set_error_message( "could not unpack SCH_SHEET from SheetSymbol in request" );
553 return tl::unexpected( e );
554 }
555
556 return true;
557}
558
559
560void PackSheetPath( types::SheetPath& aOutput, const SCH_SHEET_PATH& aInput )
561{
562 PackSheetPath( aOutput, aInput.Path() );
563 aOutput.set_path_human_readable( aInput.PathHumanReadable().ToUTF8() );
564}
const char * name
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:55
static void registerVariant(SCHEMATIC *aSchematic, const wxString &aName, const VariantProto &aInput)
Make the schematic aware of a variant a request named. Accepts either variant message.
static void applySheetVariants(SCH_SHEET *aSheet, const kiapi::schematic::types::SheetVariants &aInput, const SCH_SHEET_PATH &aParentPath, SCHEMATIC *aSchematic)
Make the set of variant records on one placement of a sheet match aInput, by name.
std::unique_ptr< EDA_ITEM > CreateItemForType(KICAD_T aType, EDA_ITEM *aContainer)
void ApplySymbolInstance(SCH_SYMBOL *aSymbol, const kiapi::schematic::types::SchematicSymbolInstance &aInput, const SCH_SHEET_PATH &aPath, SCHEMATIC *aSchematic)
Apply placement-specific data to an aSymbol at aPath: reference, unit, and the per-placement attribut...
tl::expected< bool, ApiResponseStatus > UnpackSheet(SCH_SHEET *aOutput, const kiapi::schematic::types::SheetSymbol &aInput)
Unpack the every placement data from the input.
bool PackSheet(kiapi::schematic::types::SheetSymbol *aOutput, const SCH_SHEET *aInput, const SCH_SHEET_PATH &aPath)
bool PackSymbol(kiapi::schematic::types::SchematicSymbolInstance *aOutput, const SCH_SYMBOL *aInput, const SCH_SHEET_PATH &aPath)
void ApplySheetInstance(SCH_SHEET *aSheet, const kiapi::schematic::types::SheetSymbol &aInput, const SCH_SHEET_PATH &aParentPath, SCHEMATIC *aSchematic)
Apply the placement data in a sheet message to aSheet: page number and the variants the message carri...
PIN_MAP_INSTANCE_OVERRIDE UnpackPinMapOverride(const kiapi::schematic::types::PinMapInstanceOverride &aInput)
void PackPinMapOverride(kiapi::schematic::types::PinMapInstanceOverride *aOutput, const PIN_MAP_INSTANCE_OVERRIDE &aOverride)
Pack/unpack a pin-to-pad map instance override to/from its protobuf form (issue #2282).
static void applySymbolVariants(SCH_SYMBOL *aSymbol, const kiapi::schematic::types::SchematicSymbolVariants &aInput, const SCH_SHEET_PATH &aPath, SCHEMATIC *aSchematic)
Make the set of variant records on one placement of a symbol match aInput, by name.
bool UnpackSymbol(SCH_SYMBOL *aOutput, const kiapi::schematic::types::SchematicSymbolInstance &aInput)
Unpack the geometry, the library definition, fields, and the default-variant attributes that are shar...
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:597
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
wxString AsString() const
Definition kiid.cpp:264
Define a library symbol object.
Definition lib_symbol.h:119
Holds all the data relating to one schematic.
Definition schematic.h:148
void AddVariant(const wxString &aVariantName)
void SetVariantDescription(const wxString &aVariantName, const wxString &aDescription)
Set the description for a variant.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:165
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:281
int GetBodyStyle() const
Definition sch_item.h:247
virtual void SetUnit(int aUnit)
Definition sch_item.h:236
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false, bool aEscapeSheetNames=false) const
Return the sheet path in a human readable form made from the sheet names.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
void ClearVariantField(const KIID_PATH &aPath, const wxString &aVariantName, const wxString &aFieldName)
void SetExcludedFromSim(bool aExcludeFromSim, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from simulation flag.
const SCH_SHEET_INSTANCE * GetInstance(const KIID_PATH &aParentPath) const
Return this sheet's placement record under aParentPath, or nullptr if it has none.
Definition sch_sheet.h:522
void SetDNP(bool aDNP, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void SetExcludedFromBOM(bool aExcludeFromBOM, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from schematic bill of materials flag.
void DeleteVariant(const KIID_PATH &aPath, const wxString &aVariantName)
void SetFieldText(const wxString &aFieldName, const wxString &aFieldText, const SCH_SHEET_PATH *aPath=nullptr, const wxString &aVariantName=wxEmptyString)
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Schematic symbol object.
Definition sch_symbol.h:75
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
virtual void SetDNP(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
bool ClearVariantSymbolOverride(const SCH_SHEET_PATH &aPath, const wxString &aVariantName)
Remove the alternate-symbol override for a given variant and sheet instance.
void SetFieldText(const wxString &aFieldName, const wxString &aFieldText, const SCH_SHEET_PATH *aPath=nullptr, const wxString &aVariantName=wxEmptyString)
void SetVariantSymbolOverride(const SCH_SHEET_PATH &aPath, const wxString &aVariantName, const LIB_ID &aLibId)
Set the alternate-symbol override for a given variant and sheet instance.
void SetExcludedFromSim(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from simulation flag.
PIN_MAP_INSTANCE_OVERRIDE GetPinMapOverride(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
void SetPinMapOverride(const PIN_MAP_INSTANCE_OVERRIDE &aOverride, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString)
Set the per-instance pin-to-pad map override (issue #2282).
void ClearVariantField(const KIID_PATH &aPath, const wxString &aVariantName, const wxString &aFieldName)
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
void SetExcludedFromPosFiles(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
bool GetExcludedFromPosFiles(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
void SetExcludedFromBOM(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from schematic bill of materials flag.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:183
void DeleteVariant(const KIID_PATH &aPath, const wxString &aVariantName)
virtual bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flag.
void SetExcludedFromBoard(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
A type-safe container of any type.
Definition ki_any.h:92
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
Definition api_utils.cpp:33
KICOMMON_API void PackSheetPath(types::SheetPath &aOutput, const KIID_PATH &aInput)
KICOMMON_API void PackLibId(types::LibraryIdentifier *aOutput, const LIB_ID &aId)
KICOMMON_API LIB_ID UnpackLibId(const types::LibraryIdentifier &aId)
Class to handle a set of SCH_ITEMs.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
One symbol-pin to footprint-pad mapping inside a PIN_MAP.
Definition pin_map.h:42
Per-instance override of the active pin map and a sparse delta on top.
Definition pin_map.h:200
std::vector< PIN_MAP_ENTRY > m_Edits
Definition pin_map.h:203
PIN_MAP_OVERRIDE_MODE m_Mode
Definition pin_map.h:201
A simple container for sheet instance information.
std::map< wxString, SCH_SHEET_VARIANT > m_Variants
A list of sheet variants.
A simple container for schematic symbol instance information.
std::map< wxString, SCH_SYMBOL_VARIANT > m_Variants
A list of symbol variants.
std::string path
KIBIS_PIN * pin
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ SCH_GROUP_T
Definition typeinfo.h:169
@ SCH_TABLE_T
Definition typeinfo.h:161
@ SCH_LINE_T
Definition typeinfo.h:159
@ LIB_SYMBOL_T
Definition typeinfo.h:144
@ SCH_NO_CONNECT_T
Definition typeinfo.h:156
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_TABLECELL_T
Definition typeinfo.h:162
@ SCH_FIELD_T
Definition typeinfo.h:146
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:167
@ SCH_LABEL_T
Definition typeinfo.h:163
@ SCH_SHEET_T
Definition typeinfo.h:171
@ SCH_SHAPE_T
Definition typeinfo.h:145
@ SCH_RULE_AREA_T
Definition typeinfo.h:166
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
@ SCH_BUS_BUS_ENTRY_T
Definition typeinfo.h:158
@ SCH_SCREEN_T
Definition typeinfo.h:198
@ SCH_SHEET_PIN_T
Definition typeinfo.h:170
@ SCH_TEXT_T
Definition typeinfo.h:147
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:157
@ SCH_BITMAP_T
Definition typeinfo.h:160
@ SCH_TEXTBOX_T
Definition typeinfo.h:148
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:164
@ SCH_JUNCTION_T
Definition typeinfo.h:155
@ SCH_PIN_T
Definition typeinfo.h:149