API: Add symbol path for footprint instances

See https://gitlab.com/kicad/code/kicad-python/-/issues/37


(cherry picked from commit 4dd39976a345df7f77213c7f48b80d5923c5d8ed)

Co-authored-by: Jon Evans <jon@craftyjon.com>
This commit is contained in:
Jon Evans 2025-05-26 18:29:35 -04:00
parent faf6db6972
commit a63758e1e6
4 changed files with 20 additions and 0 deletions

View File

@ -896,4 +896,7 @@ message FootprintInstance
FootprintAttributes attributes = 11;
FootprintDesignRuleOverrides overrides = 12;
// The sheet path to the associated symbol for this footprint instance, if one exists
kiapi.common.types.SheetPath symbol_path = 13;
}

View File

@ -21,6 +21,7 @@
#include <magic_enum.hpp>
#include <api/api_utils.h>
#include <geometry/shape_poly_set.h>
#include <kiid.h>
#include <wx/log.h>
const wxChar* const traceApi = wxT( "KICAD_API" );
@ -232,4 +233,14 @@ KICOMMON_API KIGFX::COLOR4D UnpackColor( const types::Color& aInput )
return KIGFX::COLOR4D( r, g, b, a );
}
KICOMMON_API void PackSheetPath( types::SheetPath& aOutput, const KIID_PATH& aInput )
{
aOutput.clear_path();
for( const KIID& entry : aInput )
aOutput.add_path()->set_value( entry.AsStdString() );
aOutput.set_path_human_readable( aInput.AsString().ToStdString() );
}
} // namespace kiapi::common

View File

@ -34,6 +34,7 @@
#include <gal/color4d.h>
class SHAPE_LINE_CHAIN;
class KIID_PATH;
/**
* Flag to enable debug output related to the IPC API and its plugin system
@ -77,6 +78,8 @@ KICOMMON_API void PackColor( types::Color& aOutput, const KIGFX::COLOR4D& aInput
KICOMMON_API KIGFX::COLOR4D UnpackColor( const types::Color& aInput );
KICOMMON_API void PackSheetPath( types::SheetPath& aOutput, const KIID_PATH& aInput );
} // namespace kiapi::common
#endif //KICAD_API_UTILS_H

View File

@ -395,6 +395,9 @@ void FOOTPRINT::Serialize( google::protobuf::Any &aContainer ) const
itemMsg->PackFrom( modelMsg );
}
// Serialized only (can't modify this from the API to change the symbol mapping)
kiapi::common::PackSheetPath( *footprint.mutable_symbol_path(), m_path );
aContainer.PackFrom( footprint );
}