62 case SCH_LINE_T:
return std::make_unique<SCH_LINE>();
63 case SCH_SHAPE_T:
return std::make_unique<SCH_SHAPE>();
64 case SCH_BITMAP_T:
return std::make_unique<SCH_BITMAP>();
66 case SCH_TEXT_T:
return std::make_unique<SCH_TEXT>();
67 case SCH_TABLE_T:
return std::make_unique<SCH_TABLE>();
69 case SCH_LABEL_T:
return std::make_unique<SCH_LABEL>();
73 case SCH_FIELD_T:
return std::make_unique<SCH_FIELD>( parentSchItem );
74 case SCH_GROUP_T:
return std::make_unique<SCH_GROUP>();
75 case SCH_SYMBOL_T:
return std::make_unique<SCH_SYMBOL>();
76 case LIB_SYMBOL_T:
return std::make_unique<LIB_SYMBOL>( wxEmptyString );
80 return std::make_unique<SCH_SHEET>(
static_cast<SCH_SCREEN*
>( aContainer ) );
88 return std::make_unique<SCH_SHEET_PIN>(
static_cast<SCH_SHEET*
>( aContainer ) );
94 return std::make_unique<SCH_PIN>(
static_cast<LIB_SYMBOL*
>( aContainer ) );
112 wxLogTrace(
traceApi,
"error: instance data for symbol %s on %s is missing",
117 google::protobuf::Any
any;
120 if( !
any.UnpackTo( aOutput ) )
124 aOutput->mutable_reference_field()->mutable_text()->set_text( instance.
m_Reference.ToUTF8() );
125 aOutput->mutable_unit()->set_unit( instance.
m_Unit );
127 kiapi::schematic::types::SchematicSymbol* def = aOutput->mutable_definition();
129 std::vector<const SCH_PIN*> pins = aInput->
GetPins( &aPath );
131 std::ranges::sort( pins,
139 kiapi::schematic::types::SchematicSymbolChild* item = def->add_items();
140 item->mutable_unit()->set_unit(
pin->GetUnit() );
141 item->mutable_body_style()->set_style(
pin->GetBodyStyle() );
142 item->set_is_private(
pin->IsPrivate() );
143 pin->Serialize( *item->mutable_item() );
146 kiapi::schematic::types::SchematicSymbolAttributes* attributes = aOutput->mutable_attributes();
152 attributes->set_do_not_populate( instance.
m_DNP );
156 kiapi::schematic::types::SchematicSymbolVariant* variant = aOutput->add_variants();
157 variant->set_name(
name.ToUTF8() );
158 variant->set_description( variantInfo.m_Description.ToUTF8() );
160 attributes = variant->mutable_attributes();
161 attributes->set_exclude_from_simulation( variantInfo.m_ExcludedFromSim );
162 attributes->set_exclude_from_bill_of_materials( variantInfo.m_ExcludedFromBOM );
163 attributes->set_exclude_from_board( variantInfo.m_ExcludedFromBoard );
164 attributes->set_exclude_from_position_files( variantInfo.m_ExcludedFromPosFiles );
165 attributes->set_do_not_populate( variantInfo.m_DNP );
167 for(
const auto& [key, value] : variantInfo.m_Fields )
168 ( *variant->mutable_fields() )[std::string( key.ToUTF8() )] = value.ToUTF8();
177 using namespace kiapi::common::types;
178 using namespace kiapi::schematic::types;
180 google::protobuf::Any
any;
181 any.PackFrom( aInput );
188 instance.
m_Reference = wxString::FromUTF8( aInput.reference_field().text().text() );
189 instance.
m_Unit = aInput.has_unit() ? aInput.unit().unit() : 1;
191 if( aInput.has_attributes() )
193 const SchematicSymbolAttributes& attrs = aInput.attributes();
198 instance.
m_DNP = attrs.do_not_populate();
204 aOutput->
SetDNP( attrs.do_not_populate() );
207 for(
const SchematicSymbolVariant& variantProto : aInput.variants() )
210 variant.
m_Description = wxString::FromUTF8( variantProto.description() );
212 if( variantProto.has_attributes() )
214 const SchematicSymbolAttributes& vAttrs = variantProto.attributes();
219 variant.
m_DNP = vAttrs.do_not_populate();
222 for(
const auto& [key, value] : variantProto.fields() )
223 variant.
m_Fields[ wxString::FromUTF8( key ) ] = wxString::FromUTF8( value );
236 google::protobuf::Any
any;
239 if( !
any.UnpackTo( aOutput ) )
249tl::expected<bool, ApiResponseStatus>
UnpackSheet(
SCH_SHEET* aOutput,
const kiapi::schematic::types::SheetSymbol& aInput )
251 google::protobuf::Any
any;
252 any.PackFrom( aInput );
257 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
258 e.set_error_message(
"could not unpack SCH_SHEET from SheetSymbol in request" );
259 return tl::unexpected( e );
264 if( !instancePath.empty() )
267 instance.
m_Path = instancePath;
268 instance.
m_PageNumber = wxString::FromUTF8( aInput.page_number() );
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)
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.
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 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.
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)
Class to handle a set of SCH_ITEMs.
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.