More functional fix for IPC API item modifications

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20206


(cherry picked from commit dc9fa2e2ac5af59a899b0b060fe8d75648cc6113)

Co-authored-by: Jon Evans <jon@craftyjon.com>
This commit is contained in:
Jon Evans 2025-03-30 19:01:16 -04:00
parent 4d6bb9317b
commit 73f77658bb
19 changed files with 101 additions and 1 deletions

View File

@ -86,6 +86,8 @@ public:
~BOARD_ITEM(); ~BOARD_ITEM();
virtual void CopyFrom( const BOARD_ITEM* aOther );
void SetParentGroup( PCB_GROUP* aGroup ) { m_group = aGroup; } void SetParentGroup( PCB_GROUP* aGroup ) { m_group = aGroup; }
PCB_GROUP* GetParentGroup() const { return m_group; } PCB_GROUP* GetParentGroup() const { return m_group; }

View File

@ -478,7 +478,7 @@ HANDLER_RESULT<ItemRequestStatus> API_HANDLER_PCB::handleCreateUpdateItemsIntern
{ {
BOARD_ITEM* boardItem = *optItem; BOARD_ITEM* boardItem = *optItem;
commit->Modify( boardItem ); commit->Modify( boardItem );
boardItem->SwapItemData( item.get() ); boardItem->CopyFrom( item.get() );
boardItem->Serialize( newItem ); boardItem->Serialize( newItem );
} }

View File

@ -44,6 +44,13 @@ BOARD_ITEM::~BOARD_ITEM()
} }
void BOARD_ITEM::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther, /* void */ );
*this = *aOther;
}
const BOARD* BOARD_ITEM::GetBoard() const const BOARD* BOARD_ITEM::GetBoard() const
{ {
if( Type() == PCB_T ) if( Type() == PCB_T )

View File

@ -1003,6 +1003,13 @@ FOOTPRINT& FOOTPRINT::operator=( const FOOTPRINT& aOther )
} }
void FOOTPRINT::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther && aOther->Type() == PCB_FOOTPRINT_T, /* void */ );
*this = *static_cast<const FOOTPRINT*>( aOther );
}
bool FOOTPRINT::IsConflicting() const bool FOOTPRINT::IsConflicting() const
{ {
return HasFlag( COURTYARD_CONFLICT ); return HasFlag( COURTYARD_CONFLICT );

View File

@ -134,6 +134,8 @@ public:
FOOTPRINT& operator=( const FOOTPRINT& aOther ); FOOTPRINT& operator=( const FOOTPRINT& aOther );
FOOTPRINT& operator=( FOOTPRINT&& aOther ); FOOTPRINT& operator=( FOOTPRINT&& aOther );
void CopyFrom( const BOARD_ITEM* aOther ) override;
void Serialize( google::protobuf::Any &aContainer ) const override; void Serialize( google::protobuf::Any &aContainer ) const override;
bool Deserialize( const google::protobuf::Any &aContainer ) override; bool Deserialize( const google::protobuf::Any &aContainer ) override;

View File

@ -141,6 +141,13 @@ PAD& PAD::operator=( const PAD &aOther )
} }
void PAD::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther && aOther->Type() == PCB_PAD_T, /* void */ );
*this = *static_cast<const PAD*>( aOther );
}
void PAD::Serialize( google::protobuf::Any &aContainer ) const void PAD::Serialize( google::protobuf::Any &aContainer ) const
{ {
using namespace kiapi::board::types; using namespace kiapi::board::types;

View File

@ -60,6 +60,8 @@ public:
PAD( const PAD& aPad ); PAD( const PAD& aPad );
PAD& operator=( const PAD &aOther ); PAD& operator=( const PAD &aOther );
void CopyFrom( const BOARD_ITEM* aOther ) override;
void Serialize( google::protobuf::Any &aContainer ) const override; void Serialize( google::protobuf::Any &aContainer ) const override;
bool Deserialize( const google::protobuf::Any &aContainer ) override; bool Deserialize( const google::protobuf::Any &aContainer ) override;

View File

@ -81,6 +81,13 @@ PCB_REFERENCE_IMAGE& PCB_REFERENCE_IMAGE::operator=( const BOARD_ITEM& aItem )
} }
void PCB_REFERENCE_IMAGE::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther && aOther->Type() == PCB_REFERENCE_IMAGE_T, /* void */ );
*this = *static_cast<const PCB_REFERENCE_IMAGE*>( aOther );
}
EDA_ITEM* PCB_REFERENCE_IMAGE::Clone() const EDA_ITEM* PCB_REFERENCE_IMAGE::Clone() const
{ {
return new PCB_REFERENCE_IMAGE( *this ); return new PCB_REFERENCE_IMAGE( *this );

View File

@ -43,6 +43,8 @@ public:
~PCB_REFERENCE_IMAGE(); ~PCB_REFERENCE_IMAGE();
void CopyFrom( const BOARD_ITEM* aOther ) override;
PCB_REFERENCE_IMAGE& operator=( const BOARD_ITEM& aItem ); PCB_REFERENCE_IMAGE& operator=( const BOARD_ITEM& aItem );
/** /**

View File

@ -69,6 +69,13 @@ PCB_SHAPE::~PCB_SHAPE()
} }
void PCB_SHAPE::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther && aOther->Type() == PCB_SHAPE_T, /* void */ );
*this = *static_cast<const PCB_SHAPE*>( aOther );
}
void PCB_SHAPE::Serialize( google::protobuf::Any &aContainer ) const void PCB_SHAPE::Serialize( google::protobuf::Any &aContainer ) const
{ {
using namespace kiapi::common; using namespace kiapi::common;

View File

@ -46,6 +46,8 @@ public:
~PCB_SHAPE() override; ~PCB_SHAPE() override;
void CopyFrom( const BOARD_ITEM* aOther ) override;
static bool ClassOf( const EDA_ITEM* aItem ) static bool ClassOf( const EDA_ITEM* aItem )
{ {
return aItem && PCB_SHAPE_T == aItem->Type(); return aItem && PCB_SHAPE_T == aItem->Type();

View File

@ -81,6 +81,13 @@ PCB_TEXT::~PCB_TEXT()
} }
void PCB_TEXT::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther && aOther->Type() == PCB_TEXT_T, /* void */ );
*this = *static_cast<const PCB_TEXT*>( aOther );
}
void PCB_TEXT::Serialize( google::protobuf::Any &aContainer ) const void PCB_TEXT::Serialize( google::protobuf::Any &aContainer ) const
{ {
using namespace kiapi::common; using namespace kiapi::common;

View File

@ -46,6 +46,8 @@ public:
~PCB_TEXT(); ~PCB_TEXT();
void CopyFrom( const BOARD_ITEM* aOther ) override;
static inline bool ClassOf( const EDA_ITEM* aItem ) static inline bool ClassOf( const EDA_ITEM* aItem )
{ {
return aItem && PCB_TEXT_T == aItem->Type(); return aItem && PCB_TEXT_T == aItem->Type();

View File

@ -61,6 +61,14 @@ PCB_TEXTBOX::~PCB_TEXTBOX()
{ {
} }
void PCB_TEXTBOX::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther && aOther->Type() == PCB_TEXTBOX_T, /* void */ );
*this = *static_cast<const PCB_TEXTBOX*>( aOther );
}
void PCB_TEXTBOX::Serialize( google::protobuf::Any &aContainer ) const void PCB_TEXTBOX::Serialize( google::protobuf::Any &aContainer ) const
{ {
using namespace kiapi::common::types; using namespace kiapi::common::types;

View File

@ -43,6 +43,8 @@ public:
~PCB_TEXTBOX(); ~PCB_TEXTBOX();
void CopyFrom( const BOARD_ITEM* aOther ) override;
static inline bool ClassOf( const EDA_ITEM* aItem ) static inline bool ClassOf( const EDA_ITEM* aItem )
{ {
return aItem && PCB_TEXTBOX_T == aItem->Type(); return aItem && PCB_TEXTBOX_T == aItem->Type();

View File

@ -71,6 +71,13 @@ EDA_ITEM* PCB_TRACK::Clone() const
} }
void PCB_TRACK::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther && aOther->Type() == PCB_TRACE_T, /* void */ );
*this = *static_cast<const PCB_TRACK*>( aOther );
}
PCB_ARC::PCB_ARC( BOARD_ITEM* aParent, const SHAPE_ARC* aArc ) : PCB_ARC::PCB_ARC( BOARD_ITEM* aParent, const SHAPE_ARC* aArc ) :
PCB_TRACK( aParent, PCB_ARC_T ) PCB_TRACK( aParent, PCB_ARC_T )
{ {
@ -86,6 +93,13 @@ EDA_ITEM* PCB_ARC::Clone() const
} }
void PCB_ARC::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther && aOther->Type() == PCB_ARC_T, /* void */ );
*this = *static_cast<const PCB_ARC*>( aOther );
}
PCB_VIA::PCB_VIA( BOARD_ITEM* aParent ) : PCB_VIA::PCB_VIA( BOARD_ITEM* aParent ) :
PCB_TRACK( aParent, PCB_VIA_T ), PCB_TRACK( aParent, PCB_VIA_T ),
m_padStack( this ) m_padStack( this )
@ -136,6 +150,13 @@ PCB_VIA& PCB_VIA::operator=( const PCB_VIA &aOther )
} }
void PCB_VIA::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther && aOther->Type() == PCB_VIA_T, /* void */ );
*this = *static_cast<const PCB_VIA*>( aOther );
}
EDA_ITEM* PCB_VIA::Clone() const EDA_ITEM* PCB_VIA::Clone() const
{ {
return new PCB_VIA( *this ); return new PCB_VIA( *this );

View File

@ -96,6 +96,8 @@ public:
// Do not create a copy constructor. The one generated by the compiler is adequate. // Do not create a copy constructor. The one generated by the compiler is adequate.
void CopyFrom( const BOARD_ITEM* aOther ) override;
void Move( const VECTOR2I& aMoveVector ) override void Move( const VECTOR2I& aMoveVector ) override
{ {
m_Start += aMoveVector; m_Start += aMoveVector;
@ -283,6 +285,8 @@ public:
PCB_ARC( BOARD_ITEM* aParent, const SHAPE_ARC* aArc ); PCB_ARC( BOARD_ITEM* aParent, const SHAPE_ARC* aArc );
void CopyFrom( const BOARD_ITEM* aOther ) override;
static inline bool ClassOf( const EDA_ITEM *aItem ) static inline bool ClassOf( const EDA_ITEM *aItem )
{ {
return aItem && PCB_ARC_T == aItem->Type(); return aItem && PCB_ARC_T == aItem->Type();
@ -383,6 +387,8 @@ public:
PCB_VIA( const PCB_VIA& aOther ); PCB_VIA( const PCB_VIA& aOther );
PCB_VIA& operator=( const PCB_VIA &aOther ); PCB_VIA& operator=( const PCB_VIA &aOther );
void CopyFrom( const BOARD_ITEM* aOther ) override;
bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
{ {
if( BOARD_CONNECTED_ITEM::IsType( aScanTypes ) ) if( BOARD_CONNECTED_ITEM::IsType( aScanTypes ) )

View File

@ -112,6 +112,13 @@ ZONE& ZONE::operator=( const ZONE& aOther )
} }
void ZONE::CopyFrom( const BOARD_ITEM* aOther )
{
wxCHECK( aOther && aOther->Type() == PCB_ZONE_T, /* void */ );
*this = *static_cast<const ZONE*>( aOther );
}
ZONE::~ZONE() ZONE::~ZONE()
{ {
delete m_Poly; delete m_Poly;

View File

@ -79,6 +79,8 @@ public:
~ZONE(); ~ZONE();
void CopyFrom( const BOARD_ITEM* aOther ) override;
static inline bool ClassOf( const EDA_ITEM* aItem ) static inline bool ClassOf( const EDA_ITEM* aItem )
{ {
return aItem && aItem->Type() == PCB_ZONE_T; return aItem && aItem->Type() == PCB_ZONE_T;