From 77e08720729e2624e89a3e308c801b2c975e442f Mon Sep 17 00:00:00 2001 From: Christophe Alexandre Date: Thu, 20 Nov 2008 10:56:11 +0000 Subject: [PATCH] Introducing Pad as Python object --- hurricane/src/isobar/CMakeLists.txt | 2 + hurricane/src/isobar/PyComponent.cpp | 15 +- hurricane/src/isobar/PyEntity.cpp | 7 +- hurricane/src/isobar/PyHurricane.cpp | 6 + hurricane/src/isobar/PyPad.cpp | 141 ++++++++++++++++++ hurricane/src/isobar/PyVertical.cpp | 1 + hurricane/src/isobar/hurricane/isobar/PyPad.h | 52 +++++++ .../src/isobar/hurricane/isobar/PySegment.h | 12 +- 8 files changed, 220 insertions(+), 16 deletions(-) create mode 100644 hurricane/src/isobar/PyPad.cpp create mode 100644 hurricane/src/isobar/hurricane/isobar/PyPad.h diff --git a/hurricane/src/isobar/CMakeLists.txt b/hurricane/src/isobar/CMakeLists.txt index 6bf10cee..92c4886b 100644 --- a/hurricane/src/isobar/CMakeLists.txt +++ b/hurricane/src/isobar/CMakeLists.txt @@ -24,6 +24,7 @@ PyNetCollection.cpp PyOccurrence.cpp PyOccurrenceCollection.cpp + PyPad.cpp PyPath.cpp PyPin.cpp PyPinCollection.cpp @@ -62,6 +63,7 @@ hurricane/isobar/PyNetCollection.h hurricane/isobar/PyOccurrence.h hurricane/isobar/PyOccurrenceCollection.h + hurricane/isobar/PyPad.h hurricane/isobar/PyPath.h hurricane/isobar/PyPin.h hurricane/isobar/PyPinCollection.h diff --git a/hurricane/src/isobar/PyComponent.cpp b/hurricane/src/isobar/PyComponent.cpp index a6f76c68..bdc5fde6 100644 --- a/hurricane/src/isobar/PyComponent.cpp +++ b/hurricane/src/isobar/PyComponent.cpp @@ -69,18 +69,18 @@ using namespace Hurricane; extern "C" { -# undef ACCESS_OBJECT -# undef ACCESS_CLASS -# define ACCESS_OBJECT _baseObject._object -# define ACCESS_CLASS(_pyObject) &(_pyObject->_baseObject) -# define METHOD_HEAD(function) GENERIC_METHOD_HEAD(Component,component,function) +#undef ACCESS_OBJECT +#undef ACCESS_CLASS +#define ACCESS_OBJECT _baseObject._object +#define ACCESS_CLASS(_pyObject) &(_pyObject->_baseObject) +#define METHOD_HEAD(function) GENERIC_METHOD_HEAD(Component,component,function) // x=================================================================x // | "PyComponent" Python Module Code Part | // x=================================================================x -# if defined(__PYTHON_MODULE__) +#if defined(__PYTHON_MODULE__) // x-------------------------------------------------------------x @@ -209,7 +209,7 @@ extern "C" { PyTypeObjectDefinitions(Component) -# endif // End of Shared Library Code Part. +#endif // End of Shared Library Code Part. } // End of extern "C". @@ -218,4 +218,3 @@ extern "C" { } // End of Isobar namespace. - diff --git a/hurricane/src/isobar/PyEntity.cpp b/hurricane/src/isobar/PyEntity.cpp index 5a607b35..47dfd03b 100644 --- a/hurricane/src/isobar/PyEntity.cpp +++ b/hurricane/src/isobar/PyEntity.cpp @@ -61,6 +61,7 @@ #include "hurricane/isobar/PyHorizontal.h" #include "hurricane/isobar/PyVertical.h" #include "hurricane/isobar/PyContact.h" +#include "hurricane/isobar/PyPad.h" #include "hurricane/isobar/PyPin.h" namespace Isobar { @@ -143,8 +144,7 @@ extern "C" { // No PyEntity should ever be created, it's not a terminal object // of the class hierarchy. Instead create the real underlying PyObject. - PyObject* PyEntity_NEW ( Entity* entity ) - { + PyObject* PyEntity_NEW ( Entity* entity ) { if ( !entity ) { PyErr_SetString ( HurricaneError, "Invalid Entity (bad occurrence)" ); \ return NULL; @@ -164,6 +164,9 @@ extern "C" { Vertical* vertical = dynamic_cast(entity); if ( vertical ) return PyVertical_Link ( vertical ); + + Pad* pad = dynamic_cast(entity); + if ( pad ) return PyPad_Link ( pad ); Contact* contact = dynamic_cast(entity); if ( contact ) return PyContact_Link ( contact ); diff --git a/hurricane/src/isobar/PyHurricane.cpp b/hurricane/src/isobar/PyHurricane.cpp index 6ba2c2c0..6e1a946b 100644 --- a/hurricane/src/isobar/PyHurricane.cpp +++ b/hurricane/src/isobar/PyHurricane.cpp @@ -83,6 +83,7 @@ #include "hurricane/isobar/PyContact.h" #include "hurricane/isobar/PyHorizontal.h" #include "hurricane/isobar/PyVertical.h" +#include "hurricane/isobar/PyPad.h" #include "hurricane/isobar/PyPath.h" #include "hurricane/isobar/PyOccurrence.h" #include "hurricane/isobar/PyOccurrenceCollection.h" @@ -547,6 +548,7 @@ extern "C" { PyHyperNet_LinkPyType (); PyComponent_LinkPyType (); PySegment_LinkPyType (); + PyPad_LinkPyType (); PyVertical_LinkPyType (); PyHorizontal_LinkPyType (); PyContact_LinkPyType (); @@ -569,6 +571,7 @@ extern "C" { PyVertical_Constructor(); PyContact_Constructor(); PyPin_Constructor(); + PyPad_Constructor(); PyPath_Constructor(); PyOccurrence_Constructor(); @@ -615,6 +618,7 @@ extern "C" { PYTYPE_READY_SUB ( Contact , Component) PYTYPE_READY_SUB ( Pin , Contact ) PYTYPE_READY_SUB ( Plug , Component) + PYTYPE_READY_SUB ( Pad , Component) // Identifier string can take up to 10 characters ! @@ -651,6 +655,7 @@ extern "C" { __cs.addType ( "plugCol" , &PyTypePlugCollection , "" , false ); __cs.addType ( "point" , &PyTypePoint , "" , false ); __cs.addType ( "segment" , &PyTypeSegment , "" , false, "comp" ); + __cs.addType ( "pad " , &PyTypePad , "" , false, "comp" ); __cs.addType ( "segmentCol" , &PyTypeSegmentCollection, "", false ); __cs.addType ( "db" , &PyTypeDataBase , "" , false ); __cs.addType ( "techno" , &PyTypeTechnology , "" , false ); @@ -680,6 +685,7 @@ extern "C" { PyModule_AddObject(module, "HyperNet" , (PyObject*)&PyTypeHyperNet); PyModule_AddObject(module, "Horizontal" , (PyObject*)&PyTypeHorizontal); PyModule_AddObject(module, "Vertical" , (PyObject*)&PyTypeVertical); + PyModule_AddObject(module, "Pad" , (PyObject*)&PyTypePad); PyModule_AddObject(module, "Contact" , (PyObject*)&PyTypeContact); PyModule_AddObject(module, "Pin" , (PyObject*)&PyTypePin); PyModule_AddObject(module, "Path" , (PyObject*)&PyTypePath); diff --git a/hurricane/src/isobar/PyPad.cpp b/hurricane/src/isobar/PyPad.cpp new file mode 100644 index 00000000..fff8aa1e --- /dev/null +++ b/hurricane/src/isobar/PyPad.cpp @@ -0,0 +1,141 @@ +#include "hurricane/isobar/PyNet.h" +#include "hurricane/isobar/PyLayer.h" +#include "hurricane/isobar/PyBox.h" +#include "hurricane/isobar/PyPad.h" + + +namespace Isobar { + +using namespace Hurricane; + +extern "C" { + + +#undef ACCESS_OBJECT +#undef ACCESS_CLASS +#define ACCESS_OBJECT _baseObject._baseObject._object +#define ACCESS_CLASS(_pyObject) &(_pyObject->_baseObject._baseObject) +#define METHOD_HEAD(function) GENERIC_METHOD_HEAD(Pad,pad,function) + + +// x=================================================================x +// | "PyPad" Python Module Code Part | +// x=================================================================x + +#if defined(__PYTHON_MODULE__) + + + // x-------------------------------------------------------------x + // | "PyPad" Attribute Methods | + // x-------------------------------------------------------------x + + + // Standard Accessors (Attributes). + DirectGetLongAttribute(PyPad_getX, getX, PyPad, Pad) + DirectGetLongAttribute(PyPad_getY, getY, PyPad, Pad) + + // Standard Destroy (Attribute). + DBoDestroyAttribute(PyPad_destroy, PyPad) + + // --------------------------------------------------------------- + // Attribute Method : "PyPad_getSourcePosition ()" + + static PyObject* PyPad_getBoundingBox( PyPad *self ) { + trace << "PyPad_getBoundingBox()" << endl; + + METHOD_HEAD ( "Pad.BoundingBox()" ) + + PyBox* pyBox = PyObject_NEW ( PyBox, &PyTypeBox ); + if (pyBox == NULL) { return NULL; } + + HTRY + pyBox->_object = new Box ( pad->getBoundingBox() ); + HCATCH + + return ( (PyObject*)pyBox ); + } + + // --------------------------------------------------------------- + // PyPad Attribute Method table. + + PyMethodDef PyPad_Methods[] = + { { "getX" , (PyCFunction)PyPad_getX , METH_NOARGS, "Return the Pad X value." } + , { "getY" , (PyCFunction)PyPad_getY , METH_NOARGS, "Return the Pad Y value." } + , { "getBoundingBox " , (PyCFunction)PyPad_getBoundingBox, METH_NOARGS, "Return the Pad Bounding Box." } + , { "destroy" , (PyCFunction)PyPad_destroy , METH_NOARGS + , "Destroy associated hurricane object, the python object remains." } + , {NULL, NULL, 0, NULL} /* sentinel */ + }; + + + // x-------------------------------------------------------------x + // | "PyPad" Object Methods | + // x-------------------------------------------------------------x + + // --------------------------------------------------------------- + // Attribute Method : "PyPad_new ()" + + static PyObject* PyPad_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { + trace << "PyPad_new()" << endl; + + PyObject* arg0; + PyObject* arg1; + PyObject* arg2; + Pad* pad = NULL; + + HTRY + __cs.init ("Pad.new"); + if (!PyArg_ParseTuple(args,"O&O&O&:Pad.new" + ,Converter,&arg0 + ,Converter,&arg1 + ,Converter,&arg2 + )) { + PyErr_SetString ( ConstructorError, "invalid number of parameters for Pad constructor." ); + return NULL; + } + + if ( __cs.getObjectIds() == ":ent:layer:box") { + pad = Pad::create(PYNET_O(arg0), PYLAYER_O(arg1), *PYBOX_O(arg2)); + } else { + PyErr_SetString ( ConstructorError, "invalid number of parameters for Pad constructor." ); + return NULL; + } + + HCATCH + + return PyPad_Link(pad); + } + + + DBoDeleteMethod(Pad) + PyTypeObjectLinkPyType(Pad) + PyTypeObjectConstructor(Pad) + + +#else // End of Python Module Code Part. + + +// x=================================================================x +// | "PyPad" Shared Library Code Part | +// x=================================================================x + + + // Link/Creation Method. + DBoLinkCreateMethod(Pad) + + + // --------------------------------------------------------------- + // PyPad Object Definitions. + + + PyTypeObjectDefinitions(Pad) + +#endif // End of Shared Library Code Part. + + +} // End of extern "C". + + + + +} // End of Isobar namespace. diff --git a/hurricane/src/isobar/PyVertical.cpp b/hurricane/src/isobar/PyVertical.cpp index b608eacc..d80c4424 100644 --- a/hurricane/src/isobar/PyVertical.cpp +++ b/hurricane/src/isobar/PyVertical.cpp @@ -101,6 +101,7 @@ extern "C" { // x-------------------------------------------------------------x // | "PyVertical" Object Methods | // x-------------------------------------------------------------x + // --------------------------------------------------------------- // Attribute Method : "PyVertical_new ()" diff --git a/hurricane/src/isobar/hurricane/isobar/PyPad.h b/hurricane/src/isobar/hurricane/isobar/PyPad.h new file mode 100644 index 00000000..1d2d9db9 --- /dev/null +++ b/hurricane/src/isobar/hurricane/isobar/PyPad.h @@ -0,0 +1,52 @@ +#ifndef __PYPAD_H +#define __PYPAD_H + + +#include "hurricane/isobar/PyComponent.h" + +#include "hurricane/Pad.h" + + +namespace Isobar { + + +extern "C" { + + +// ------------------------------------------------------------------- +// Python Object : "PyPad". + + typedef struct { + PyComponent _baseObject; + } PyPad; + + + + +// ------------------------------------------------------------------- +// Functions & Types exported to "PyHurricane.ccp". + + extern PyTypeObject PyTypePad; + extern PyMethodDef PyPad_Methods[]; + + extern PyObject* PyPad_Link ( Hurricane::Pad* object ); + extern void PyPad_LinkPyType (); + extern void PyPad_Constructor(); + + +#define IsPyPad(v) ( (v)->ob_type == &PyTypePad ) +#define PYPAD(v) ( (PyPad*)(v) ) +#define PYPAD_O(v) ( PYPAD(v)->_baseObject._baseObject._object ) + + +} // End of extern "C". + + + + +} // End of Isobar namespace. + + + + +#endif /* __PYPAD_H */ diff --git a/hurricane/src/isobar/hurricane/isobar/PySegment.h b/hurricane/src/isobar/hurricane/isobar/PySegment.h index b6dac5d0..8b4b191c 100644 --- a/hurricane/src/isobar/hurricane/isobar/PySegment.h +++ b/hurricane/src/isobar/hurricane/isobar/PySegment.h @@ -53,8 +53,8 @@ -# ifndef __PYSEGMENT__ -# define __PYSEGMENT__ +#ifndef __PYSEGMENT_H +#define __PYSEGMENT_H #include "hurricane/isobar/PyComponent.h" @@ -87,9 +87,9 @@ extern "C" { extern void PySegment_LinkPyType (); -# define IsPySegment(v) ( (v)->ob_type == &PyTypeSegment ) -# define PYSEGMENT(v) ( (PySegment*)(v) ) -# define PYSEGMENT_O(v) ( PYSEGMENT(v)->_baseObject._baseObject._object ) +#define IsPySegment(v) ( (v)->ob_type == &PyTypeSegment ) +#define PYSEGMENT(v) ( (PySegment*)(v) ) +#define PYSEGMENT_O(v) ( PYSEGMENT(v)->_baseObject._baseObject._object ) } // End of extern "C". @@ -102,4 +102,4 @@ extern "C" { -# endif +#endif /* __PYSEGMENT_H */