Browse Source

API: Add symbol path for footprint instances

See https://gitlab.com/kicad/code/kicad-python/-/issues/37
pull/18/head
Jon Evans 6 months ago
parent
commit
4dd39976a3
  1. 3
      api/proto/board/board_types.proto
  2. 11
      common/api/api_utils.cpp
  3. 3
      include/api/api_utils.h
  4. 3
      pcbnew/footprint.cpp

3
api/proto/board/board_types.proto

@ -960,4 +960,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;
}

11
common/api/api_utils.cpp

@ -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

3
include/api/api_utils.h

@ -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

3
pcbnew/footprint.cpp

@ -389,6 +389,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 );
}

Loading…
Cancel
Save