63 case SCH_LINE_T:
return std::make_unique<SCH_LINE>();
64 case SCH_SHAPE_T:
return std::make_unique<SCH_SHAPE>();
65 case SCH_BITMAP_T:
return std::make_unique<SCH_BITMAP>();
67 case SCH_TEXT_T:
return std::make_unique<SCH_TEXT>();
68 case SCH_TABLE_T:
return std::make_unique<SCH_TABLE>();
70 case SCH_LABEL_T:
return std::make_unique<SCH_LABEL>();
74 case SCH_FIELD_T:
return std::make_unique<SCH_FIELD>( parentSchItem );
75 case SCH_GROUP_T:
return std::make_unique<SCH_GROUP>();
76 case SCH_SYMBOL_T:
return std::make_unique<SCH_SYMBOL>();
77 case LIB_SYMBOL_T:
return std::make_unique<LIB_SYMBOL>( wxEmptyString );
81 return std::make_unique<SCH_SHEET>(
static_cast<SCH_SCREEN*
>( aContainer ) );
89 return std::make_unique<SCH_SHEET_PIN>(
static_cast<SCH_SHEET*
>( aContainer ) );
95 return std::make_unique<SCH_PIN>(
static_cast<LIB_SYMBOL*
>( aContainer ) );
115 kiapi::schematic::types::PinMapEntry* e = aOutput->add_edits();
116 e->set_pin_number(
edit.m_PinNumber.ToUTF8() );
117 e->set_pad_number(
edit.m_PadNumber.ToUTF8() );
126 override.m_ActiveMapName = wxString::FromUTF8( aInput.active_map_name() );
128 for(
const kiapi::schematic::types::PinMapEntry& e : aInput.edits() )
130 override.m_Edits.push_back( { wxString::FromUTF8( e.pin_number() ), wxString::FromUTF8( e.pad_number() ) } );
145 wxLogTrace(
traceApi,
"error: instance data for symbol %s on %s is missing",
150 google::protobuf::Any
any;
153 if( !
any.UnpackTo( aOutput ) )
157 aOutput->mutable_reference_field()->mutable_text()->set_text( instance.
m_Reference.ToUTF8() );
158 aOutput->mutable_unit()->set_unit( instance.
m_Unit );
160 kiapi::schematic::types::SchematicSymbol* def = aOutput->mutable_definition();
162 std::vector<const SCH_PIN*> pins = aInput->
GetPins( &aPath );
164 std::ranges::sort( pins,
172 kiapi::schematic::types::SchematicSymbolChild* item = def->add_items();
173 item->mutable_unit()->set_unit(
pin->GetUnit() );
174 item->mutable_body_style()->set_style(
pin->GetBodyStyle() );
175 item->set_is_private(
pin->IsPrivate() );
176 pin->Serialize( *item->mutable_item() );
183 kiapi::schematic::types::LibSymbolPinMaps* pinMaps = def->mutable_pin_maps();
187 kiapi::schematic::types::AssociatedFootprint* a = pinMaps->add_associated_footprints();
188 PackLibId( a->mutable_footprint(), assoc.m_FootprintLibId );
189 a->set_map_name( assoc.m_MapName.ToUTF8() );
192 for(
const PIN_MAP& map : lib->GetEffectivePinMaps().GetAll() )
194 kiapi::schematic::types::PinMap* m = pinMaps->add_pin_maps();
195 m->set_name( map.GetName().ToUTF8() );
199 kiapi::schematic::types::PinMapEntry* e = m->add_entries();
200 e->set_pin_number( entry.m_PinNumber.ToUTF8() );
201 e->set_pad_number( entry.m_PadNumber.ToUTF8() );
208 if( !
override.IsDefault() )
211 kiapi::schematic::types::SchematicSymbolAttributes* attributes = aOutput->mutable_attributes();
217 attributes->set_do_not_populate( instance.
m_DNP );
221 kiapi::schematic::types::SchematicSymbolVariant* variant = aOutput->add_variants();
222 variant->set_name(
name.ToUTF8() );
223 variant->set_description( variantInfo.m_Description.ToUTF8() );
225 attributes = variant->mutable_attributes();
226 attributes->set_exclude_from_simulation( variantInfo.m_ExcludedFromSim );
227 attributes->set_exclude_from_bill_of_materials( variantInfo.m_ExcludedFromBOM );
228 attributes->set_exclude_from_board( variantInfo.m_ExcludedFromBoard );
229 attributes->set_exclude_from_position_files( variantInfo.m_ExcludedFromPosFiles );
230 attributes->set_do_not_populate( variantInfo.m_DNP );
232 for(
const auto& [key, value] : variantInfo.m_Fields )
233 ( *variant->mutable_fields() )[std::string( key.ToUTF8() )] = value.ToUTF8();
242 using namespace kiapi::common::types;
243 using namespace kiapi::schematic::types;
245 google::protobuf::Any
any;
246 any.PackFrom( aInput );
253 instance.
m_Reference = wxString::FromUTF8( aInput.reference_field().text().text() );
254 instance.
m_Unit = aInput.has_unit() ? aInput.unit().unit() : 1;
256 if( aInput.has_attributes() )
258 const SchematicSymbolAttributes& attrs = aInput.attributes();
263 instance.
m_DNP = attrs.do_not_populate();
269 aOutput->
SetDNP( attrs.do_not_populate() );
272 for(
const SchematicSymbolVariant& variantProto : aInput.variants() )
275 variant.
m_Description = wxString::FromUTF8( variantProto.description() );
277 if( variantProto.has_attributes() )
279 const SchematicSymbolAttributes& vAttrs = variantProto.attributes();
284 variant.
m_DNP = vAttrs.do_not_populate();
287 for(
const auto& [key, value] : variantProto.fields() )
288 variant.
m_Fields[ wxString::FromUTF8( key ) ] = wxString::FromUTF8( value );
293 if( aInput.has_pin_map_override() )
304 google::protobuf::Any
any;
307 if( !
any.UnpackTo( aOutput ) )
317tl::expected<bool, ApiResponseStatus>
UnpackSheet(
SCH_SHEET* aOutput,
const kiapi::schematic::types::SheetSymbol& aInput )
319 google::protobuf::Any
any;
320 any.PackFrom( aInput );
325 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
326 e.set_error_message(
"could not unpack SCH_SHEET from SheetSymbol in request" );
327 return tl::unexpected( e );
332 if( !instancePath.empty() )
335 instance.
m_Path = instancePath;
336 instance.
m_PageNumber = wxString::FromUTF8( aInput.page_number() );
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
std::unique_ptr< EDA_ITEM > CreateItemForType(KICAD_T aType, EDA_ITEM *aContainer)
tl::expected< bool, ApiResponseStatus > UnpackSheet(SCH_SHEET *aOutput, const kiapi::schematic::types::SheetSymbol &aInput)
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)
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).
bool UnpackSymbol(SCH_SYMBOL *aOutput, const kiapi::schematic::types::SchematicSymbolInstance &aInput)
A base class for most all the KiCad significant classes used in schematics and boards.
KICAD_T Type() const
Returns the type of object.
wxString AsString() const
Define a library symbol object.
Base class for any item which can be embedded within the SCHEMATIC container class,...
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 GetPageNumber() const
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.
void AddInstance(const SCH_SHEET_INSTANCE &aInstance)
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.
Variant information for a schematic symbol.
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.
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.
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 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 GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
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()
void SetExcludedFromBoard(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
std::map< wxString, wxString > m_Fields
bool m_ExcludedFromPosFiles
A type-safe container of any type.
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
KICOMMON_API KIID_PATH UnpackSheetPath(const types::SheetPath &aInput)
KICOMMON_API void PackSheetPath(types::SheetPath &aOutput, const KIID_PATH &aInput)
KICOMMON_API void PackLibId(types::LibraryIdentifier *aOutput, const LIB_ID &aId)
Class to handle a set of SCH_ITEMs.
One symbol-pin to footprint-pad mapping inside a PIN_MAP.
Per-instance override of the active pin map and a sparse delta on top.
std::vector< PIN_MAP_ENTRY > m_Edits
PIN_MAP_OVERRIDE_MODE m_Mode
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
std::map< wxString, SCH_SYMBOL_VARIANT > m_Variants
A list of symbol variants.
bool m_ExcludedFromPosFiles
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.