Introducing Pad as Python object

This commit is contained in:
Christophe Alexandre 2008-11-20 10:56:11 +00:00
parent e35c5ef8e5
commit 77e0872072
8 changed files with 220 additions and 16 deletions

View File

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

View File

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

View File

@ -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<Vertical*>(entity);
if ( vertical ) return PyVertical_Link ( vertical );
Pad* pad = dynamic_cast<Pad*>(entity);
if ( pad ) return PyPad_Link ( pad );
Contact* contact = dynamic_cast<Contact*>(entity);
if ( contact ) return PyContact_Link ( contact );

View File

@ -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 , "<PlugCollection>" , false );
__cs.addType ( "point" , &PyTypePoint , "<Point>" , false );
__cs.addType ( "segment" , &PyTypeSegment , "<Segment>" , false, "comp" );
__cs.addType ( "pad " , &PyTypePad , "<Pad>" , false, "comp" );
__cs.addType ( "segmentCol" , &PyTypeSegmentCollection, "<SegmentCollection>", false );
__cs.addType ( "db" , &PyTypeDataBase , "<DataBase>" , false );
__cs.addType ( "techno" , &PyTypeTechnology , "<Technology>" , 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);

View File

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

View File

@ -101,6 +101,7 @@ extern "C" {
// x-------------------------------------------------------------x
// | "PyVertical" Object Methods |
// x-------------------------------------------------------------x
// ---------------------------------------------------------------
// Attribute Method : "PyVertical_new ()"

View File

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

View File

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