From d610486c1eb1f41bc28405d115a6caa7c10ff029 Mon Sep 17 00:00:00 2001 From: qu1ck Date: Sun, 5 Mar 2023 15:37:34 -0800 Subject: [PATCH] Add vector3 to swig Fixes regression in 7.0 making fp 3d model offsets not accessible in python Fixes https://gitlab.com/kicad/code/kicad/-/issues/14179 (cherry picked from commit 88062c5fc3ca7446b3a16a69a731583d9b19b984) --- common/swig/math.i | 42 +++++++++++++++++++++++++++++++++- pcbnew/python/swig/footprint.i | 1 - 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/common/swig/math.i b/common/swig/math.i index cafbebfb83..bc532b2d8e 100644 --- a/common/swig/math.i +++ b/common/swig/math.i @@ -34,13 +34,18 @@ %rename(getWxPoint) operator wxPoint; %rename(getWxSize) operator wxSize; +%{ #include -%include +#include #include +%} +%include +%include %include %template(VECTOR2I) VECTOR2; %template(VECTOR2I_EXTENDED_TYPE) VECTOR2_TRAITS; +%template(VECTOR3D) VECTOR3; %template(BOX2I) BOX2; %extend VECTOR2 @@ -74,3 +79,38 @@ %} } + +%extend VECTOR3 +{ + void Set(double x, double y, double z) { self->x = x; self->y = y; self->z = z; } + + PyObject* Get() + { + PyObject* tup = PyTuple_New(3); + PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x)); + PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y)); + PyTuple_SET_ITEM(tup, 2, PyFloat_FromDouble(self->z)); + return tup; + } + + %pythoncode + %{ + def __eq__(self,other): return (self.x==other.x and self.y==other.y and self.z==other.z) + def __ne__(self,other): return not (self==other) + def __str__(self): return str(self.Get()) + def __repr__(self): return 'VECTOR3D'+str(self.Get()) + def __len__(self): return len(self.Get()) + def __getitem__(self, index): return self.Get()[index] + def __setitem__(self, index, val): + if index == 0: + self.x = val + elif index == 1: + self.y = val + elif index == 2: + self.z = val + else: + raise IndexError + def __nonzero__(self): return self.Get() != (0, 0, 0) + + %} +} diff --git a/pcbnew/python/swig/footprint.i b/pcbnew/python/swig/footprint.i index 1b64158d2a..5b32afc52e 100644 --- a/pcbnew/python/swig/footprint.i +++ b/pcbnew/python/swig/footprint.i @@ -33,7 +33,6 @@ %rename(GetPropertiesNative) FOOTPRINT::GetProperties; %rename(GetPropertyNative) FOOTPRINT::GetProperty; %rename(SetPropertiesNative) FOOTPRINT::SetProperties; -%rename(MODULE_3D_SETTINGS_VECTOR3D) MODULE_3D_SETTINGS::VECTOR3D; %feature("flatnested"); %include footprint.h %feature("flatnested", "");