2008-03-06 10:46:43 -06:00
// x-----------------------------------------------------------------x
// | |
// | C O R I O L I S |
// | I s o b a r - Hurricane / Python Interface |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@asim.lip6.fr |
// | =============================================================== |
// | C++ Module : "./PyInstance.cpp" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
2008-05-21 17:46:29 -05:00
# include "hurricane/isobar/PyBox.h"
# include "hurricane/isobar/PyTransformation.h"
# include "hurricane/isobar/PyLibrary.h"
# include "hurricane/isobar/PyCell.h"
# include "hurricane/isobar/PyInstance.h"
# include "hurricane/isobar/PyNet.h"
# include "hurricane/isobar/PyPlug.h"
2008-10-17 12:27:20 -05:00
# include "hurricane/isobar/PyPlugCollection.h"
2008-03-06 10:46:43 -06:00
namespace Isobar {
2008-03-28 04:48:47 -05:00
using namespace Hurricane ;
2008-03-06 10:46:43 -06:00
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(Instance,instance,function)
# define LOAD_CONSTANT(CONSTANT_VALUE,CONSTANT_NAME) \
constant = PyInt_FromLong ( ( long ) CONSTANT_VALUE ) ; \
PyDict_SetItemString ( dictionnary , CONSTANT_NAME , constant ) ; \
Py_DECREF ( constant ) ;
// x=================================================================x
// | "PyInstance" Python Module Code Part |
// x=================================================================x
# if defined(__PYTHON_MODULE__)
// x-------------------------------------------------------------x
// | Global Constants Loading |
// x-------------------------------------------------------------x
extern void InstanceLoadConstants ( PyObject * dictionnary )
{
PyObject * constant ;
LOAD_CONSTANT ( Instance : : PlacementStatus : : UNPLACED , " PlacementStatusUNPLACED " )
LOAD_CONSTANT ( Instance : : PlacementStatus : : PLACED , " PlacementStatusPLACED " )
LOAD_CONSTANT ( Instance : : PlacementStatus : : FIXED , " PlacementStatusFIXED " )
}
// x-------------------------------------------------------------x
// | "PyInstance" Local Functions |
// x-------------------------------------------------------------x
// ---------------------------------------------------------------
// Local Function : "PyInt_AsType ()"
static Instance : : PlacementStatus PyInt_AsPlacementStatus ( PyObject * object )
{
switch ( PyInt_AsLong ( object ) ) {
case Instance : : PlacementStatus : : UNPLACED : return ( Instance : : PlacementStatus ( Instance : : PlacementStatus : : UNPLACED ) ) ;
case Instance : : PlacementStatus : : PLACED : return ( Instance : : PlacementStatus ( Instance : : PlacementStatus : : PLACED ) ) ;
case Instance : : PlacementStatus : : FIXED : return ( Instance : : PlacementStatus ( Instance : : PlacementStatus : : FIXED ) ) ;
}
return ( Instance : : PlacementStatus ( Instance : : PlacementStatus : : UNPLACED ) ) ;
}
// x-------------------------------------------------------------x
// | "PyInstance" Attribute Methods |
// x-------------------------------------------------------------x
// Standart Accessors (Attributes).
2008-03-17 08:54:33 -05:00
// Standart destroy (Attribute).
DBoDestroyAttribute ( PyInstance_destroy , PyInstance )
2008-03-06 10:46:43 -06:00
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyInstance_getName ()"
2008-03-06 10:46:43 -06:00
2008-12-11 06:25:02 -06:00
GetNameMethod ( Instance , instance )
2008-03-06 10:46:43 -06:00
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyInstance_getMasterCell ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject * PyInstance_getMasterCell ( PyInstance * self ) {
trace < < " PyInstance_getMasterCell () " < < endl ;
2008-03-06 10:46:43 -06:00
Cell * cell = NULL ;
HTRY
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( " Instance.getMasterCell() " )
cell = instance - > getMasterCell ( ) ;
2008-03-06 10:46:43 -06:00
HCATCH
return PyCell_Link ( cell ) ;
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyInstance_getPlacementStatus ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject * PyInstance_getPlacementStatus ( PyInstance * self ) {
trace < < " PyInstance_getPlacementStatus () " < < endl ;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( " Instance.getPlacementStatus() " ) ;
2008-03-06 10:46:43 -06:00
PyObject * pyObject = NULL ;
HTRY
2008-03-17 08:54:33 -05:00
pyObject = ( PyObject * ) Py_BuildValue ( " i " , ( long ) instance - > getPlacementStatus ( ) . getCode ( ) ) ;
2008-03-06 10:46:43 -06:00
HCATCH
return pyObject ;
}
// ---------------------------------------------------------------
// Attribute Method : "PyInstance_SetPlacementStatus ()"
2008-03-25 06:06:05 -05:00
static PyObject * PyInstance_setPlacementStatus ( PyInstance * self , PyObject * args ) {
trace < < " PyInstance_setPlacementStatus() " < < endl ;
METHOD_HEAD ( " Instance.setPlacementStatus() " )
2008-03-06 10:46:43 -06:00
HTRY
PyObject * arg0 ;
2008-03-25 06:06:05 -05:00
if ( ! ParseOneArg ( " Instance.setPlacementStatus() " , args , INT_ARG , ( PyObject * * ) & arg0 ) ) return ( NULL ) ;
2008-03-06 10:46:43 -06:00
2008-03-25 06:06:05 -05:00
instance - > setPlacementStatus ( PyInt_AsPlacementStatus ( arg0 ) ) ;
2008-03-06 10:46:43 -06:00
HCATCH
Py_RETURN_NONE ;
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyInstance_getTransformation ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject * PyInstance_getTransformation ( PyInstance * self ) {
trace < < " PyInstance_getTransformation () " < < endl ;
METHOD_HEAD ( " Instance.getTransformation() " ) ;
2008-03-06 10:46:43 -06:00
PyTransformation * resultPyTransf = PyObject_NEW ( PyTransformation , & PyTypeTransformation ) ;
if ( resultPyTransf = = NULL ) { return NULL ; }
HTRY
2008-03-17 08:54:33 -05:00
resultPyTransf - > _object = new Transformation ( instance - > getTransformation ( ) ) ;
2008-03-06 10:46:43 -06:00
HCATCH
return ( ( PyObject * ) resultPyTransf ) ;
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyInstance_getPlug ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject * PyInstance_getPlug ( PyInstance * self , PyObject * args ) {
trace < < " PyInstance_getPlug () " < < endl ;
2008-03-06 10:46:43 -06:00
Plug * plug = NULL ;
HTRY
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( " Instance.getPlug() " )
2008-03-06 10:46:43 -06:00
PyNet * masterNet ;
2008-03-17 08:54:33 -05:00
if ( ! ParseOneArg ( " Instance.getPlug " , args , NET_ARG , ( PyObject * * ) & masterNet ) ) return ( NULL ) ;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
plug = instance - > getPlug ( PYNET_O ( masterNet ) ) ;
2008-03-06 10:46:43 -06:00
HCATCH
return PyPlug_Link ( plug ) ;
}
// ---------------------------------------------------------------
2008-10-17 12:27:20 -05:00
// Attribute Method : "PyInstance_getPlugs()"
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
static PyObject * PyInstance_getPlugs ( PyInstance * self ) {
trace < < " PyInstance_getPlugs() " < < endl ;
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
METHOD_HEAD ( " Instance.getPlugs() " )
PyPlugCollection * pyPlugCollection = NULL ;
2008-03-06 10:46:43 -06:00
HTRY
2008-10-17 12:27:20 -05:00
Plugs * plugs = new Plugs ( instance - > getPlugs ( ) ) ;
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
pyPlugCollection = PyObject_NEW ( PyPlugCollection , & PyTypePlugCollection ) ;
if ( pyPlugCollection = = NULL ) {
return NULL ;
}
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
pyPlugCollection - > _object = plugs ;
HCATCH
return ( PyObject * ) pyPlugCollection ;
2008-03-06 10:46:43 -06:00
}
// ---------------------------------------------------------------
2008-10-17 12:27:20 -05:00
// Attribute Method : "PyInstance_getConnectedPlugs()"
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
static PyObject * PyInstance_getConnectedPlugs ( PyInstance * self ) {
trace < < " PyInstance_getConnectedPlugs () " < < endl ;
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
METHOD_HEAD ( " Instance.getConnectedPlugs() " )
PyPlugCollection * pyPlugCollection = NULL ;
2008-03-06 10:46:43 -06:00
HTRY
2008-10-17 12:27:20 -05:00
Plugs * plugs = new Plugs ( instance - > getConnectedPlugs ( ) ) ;
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
pyPlugCollection = PyObject_NEW ( PyPlugCollection , & PyTypePlugCollection ) ;
if ( pyPlugCollection = = NULL ) {
return NULL ;
}
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
pyPlugCollection - > _object = plugs ;
HCATCH
return ( PyObject * ) pyPlugCollection ;
2008-03-06 10:46:43 -06:00
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyInstance_getUnconnectedPlugsLocator ()"
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
static PyObject * PyInstance_getUnconnectedPlugs ( PyInstance * self ) {
trace < < " PyInstance_getUnconnectedPlugs () " < < endl ;
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
METHOD_HEAD ( " Instance.getUnconnectedPlugs() " )
PyPlugCollection * pyPlugCollection = NULL ;
2008-03-06 10:46:43 -06:00
HTRY
2008-10-17 12:27:20 -05:00
Plugs * plugs = new Plugs ( instance - > getUnconnectedPlugs ( ) ) ;
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
pyPlugCollection = PyObject_NEW ( PyPlugCollection , & PyTypePlugCollection ) ;
if ( pyPlugCollection = = NULL ) {
return NULL ;
}
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
pyPlugCollection - > _object = plugs ;
HCATCH
return ( PyObject * ) pyPlugCollection ;
2008-03-06 10:46:43 -06:00
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyInstance_getAbutmentBox ()"
2008-03-06 10:46:43 -06:00
2008-03-25 06:06:05 -05:00
static PyObject * PyInstance_getAbutmentBox ( PyInstance * self ) {
2008-03-17 08:54:33 -05:00
trace < < " PyInstance_getAbutmentBox () " < < endl ;
METHOD_HEAD ( " Instance.getAbutmentBox() " )
2008-03-06 10:46:43 -06:00
PyBox * pyBox = PyObject_NEW ( PyBox , & PyTypeBox ) ;
if ( pyBox = = NULL ) { return NULL ; }
HTRY
2008-03-17 08:54:33 -05:00
pyBox - > _object = new Box ( instance - > getAbutmentBox ( ) ) ;
2008-03-06 10:46:43 -06:00
HCATCH
return ( ( PyObject * ) pyBox ) ;
}
// ---------------------------------------------------------------
2008-03-25 06:06:05 -05:00
// Attribute Method : "PyInstance_setName ()"
2008-03-06 10:46:43 -06:00
2008-12-11 06:25:02 -06:00
SetNameMethod ( Instance , instance )
2008-03-06 10:46:43 -06:00
// ---------------------------------------------------------------
// Attribute Method : "PyInstance_SetTransformation ()"
2008-03-25 06:06:05 -05:00
static PyObject * PyInstance_setTransformation ( PyInstance * self , PyObject * args ) {
trace < < " PyInstance_setTransformation() " < < endl ;
METHOD_HEAD ( " Instance.setTransformation() " )
2008-03-06 10:46:43 -06:00
HTRY
PyTransformation * transformation ;
2008-03-25 06:06:05 -05:00
if ( ! ParseOneArg ( " Instance.setTransformation " , args , TRANS_ARG , ( PyObject * * ) & transformation ) ) return ( NULL ) ;
2008-03-06 10:46:43 -06:00
2008-03-25 06:06:05 -05:00
instance - > setTransformation ( * PYTRANSFORMATION_O ( transformation ) ) ;
2008-03-06 10:46:43 -06:00
HCATCH
Py_RETURN_NONE ;
}
// ---------------------------------------------------------------
// Attribute Method : "PyInstance_SetMasterCell ()"
2008-03-25 06:06:05 -05:00
static PyObject * PyInstance_setMasterCell ( PyInstance * self , PyObject * args ) {
trace < < " Instance.setMasterCell() " < < endl ;
METHOD_HEAD ( " Instance.setMasterCell() " )
2008-03-06 10:46:43 -06:00
HTRY
PyCell * masterCell ;
2008-03-25 06:06:05 -05:00
if ( ! ParseOneArg ( " Instance.setMasterCell " , args , CELL_ARG , ( PyObject * * ) & masterCell ) ) return ( NULL ) ;
2008-03-06 10:46:43 -06:00
2008-03-25 06:06:05 -05:00
instance - > setMasterCell ( PYCELL_O ( masterCell ) ) ;
2008-03-06 10:46:43 -06:00
HCATCH
Py_RETURN_NONE ;
}
// Standart Predicates (Attributes).
2008-03-25 06:06:05 -05:00
DirectGetBoolAttribute ( PyInstance_isTerminal , isTerminal , PyInstance , Instance )
DirectGetBoolAttribute ( PyInstance_isLeaf , isLeaf , PyInstance , Instance )
2008-03-06 10:46:43 -06:00
2008-03-25 06:06:05 -05:00
GetBoundStateAttribute ( PyInstance_isPyBound , PyInstance , Instance )
2008-03-06 10:46:43 -06:00
// ---------------------------------------------------------------
// PyInstance Attribute Method table.
PyMethodDef PyInstance_Methods [ ] =
2008-03-17 08:54:33 -05:00
{ { " getName " , ( PyCFunction ) PyInstance_getName , METH_NOARGS , " Returns the instance name. " }
, { " getMasterCell " , ( PyCFunction ) PyInstance_getMasterCell , METH_NOARGS , " Returns the cell model referenced by the instance. " }
, { " getTransformation " , ( PyCFunction ) PyInstance_getTransformation , METH_NOARGS , " Returns the transformation associated to the instance. " }
, { " getPlacementStatus " , ( PyCFunction ) PyInstance_getPlacementStatus , METH_NOARGS , " Returns the placement status of the instance. " }
, { " getPlug " , ( PyCFunction ) PyInstance_getPlug , METH_VARARGS , " Returns the plug associated to the <masterNet> if it exists or else NULL (if the net is not external). " }
2008-10-17 12:27:20 -05:00
, { " getPlugs " , ( PyCFunction ) PyInstance_getPlugs , METH_NOARGS , " Returns the collection of instance plugs. " }
, { " getConnectedPlugs " , ( PyCFunction ) PyInstance_getConnectedPlugs , METH_NOARGS , " Returns the collection of instance plugs which are effectively connected. " }
, { " getUnconnectedPlugs " , ( PyCFunction ) PyInstance_getUnconnectedPlugs , METH_NOARGS , " Returns the collection of instance plugs which are not connected. " }
2008-03-17 08:54:33 -05:00
, { " getAbutmentBox " , ( PyCFunction ) PyInstance_getAbutmentBox , METH_NOARGS , " Returns the abutment box of the instance, that is the abutment box of the master cell to which has been applied the instance transformation. " }
2008-03-25 06:06:05 -05:00
, { " isTerminal " , ( PyCFunction ) PyInstance_isTerminal , METH_NOARGS , " Returns true if the instance is a terminal instance. " }
, { " isLeaf " , ( PyCFunction ) PyInstance_isLeaf , METH_NOARGS , " Returns true if the instance is a leaf instance. " }
, { " isBound " , ( PyCFunction ) PyInstance_isPyBound , METH_NOARGS , " Returns true if the instance is bounded to the hurricane instance " }
, { " setName " , ( PyCFunction ) PyInstance_setName , METH_VARARGS , " Allows to change the instance name. " }
, { " setTransformation " , ( PyCFunction ) PyInstance_setTransformation , METH_VARARGS , " Allows to modify the instance transformation. " }
, { " setPlacementStatus " , ( PyCFunction ) PyInstance_setPlacementStatus , METH_VARARGS , " Allows to modify the instance placement status. " }
, { " setMasterCell " , ( PyCFunction ) PyInstance_setMasterCell , METH_VARARGS , " Allows to change the cell referenced by this instance. " }
2008-03-17 08:54:33 -05:00
, { " destroy " , ( PyCFunction ) PyInstance_destroy , METH_NOARGS
, " Destroy associated hurricane object The python object remains. " }
2008-03-06 10:46:43 -06:00
, { NULL , NULL , 0 , NULL } /* sentinel */
} ;
// x-------------------------------------------------------------x
// | "PyInstance" Object Methods |
// x-------------------------------------------------------------x
// ---------------------------------------------------------------
// Attribute Method : "PyInstance_new ()"
static PyObject * PyInstance_new ( PyTypeObject * type , PyObject * args , PyObject * kwds ) {
trace < < " PyInstance_new () " < < endl ;
Instance * instance = NULL ;
PyObject * arg0 ;
PyObject * arg1 ;
PyObject * arg2 ;
PyObject * arg3 ;
HTRY
2008-11-17 15:55:03 -06:00
__cs . init ( " Instance.new " ) ;
2008-03-06 10:46:43 -06:00
if ( ! PyArg_ParseTuple ( args , " O&O&O&|O&:Instance.new "
, Converter , & arg0
, Converter , & arg1
, Converter , & arg2
, Converter , & arg3
2008-10-14 13:44:20 -05:00
) ) {
PyErr_SetString ( ConstructorError , " invalid number of parameters for Instance constructor. " ) ;
return NULL ;
}
2008-03-06 10:46:43 -06:00
2008-12-12 12:49:17 -06:00
if ( __cs . getObjectIds ( ) = = " :ent:string:ent " ) {
instance = Instance : : create (
PYCELL_O ( arg0 ) ,
Name ( PyString_AsString ( arg1 ) ) ,
PYCELL_O ( arg2 ) ) ;
} else if ( __cs . getObjectIds ( ) = = " :ent:string:ent:transfo " ) {
instance = Instance : : create (
PYCELL_O ( arg0 ) ,
Name ( PyString_AsString ( arg1 ) ) ,
PYCELL_O ( arg2 ) ,
* PYTRANSFORMATION_O ( arg3 ) ,
Instance : : PlacementStatus : : PLACED ) ;
} else {
2008-03-06 10:46:43 -06:00
PyErr_SetString ( ConstructorError , " invalid number of parameters for Instance constructor. " ) ;
2008-12-12 12:49:17 -06:00
return NULL ;
2008-03-06 10:46:43 -06:00
}
HCATCH
2008-12-12 12:49:17 -06:00
return PyInstance_Link ( instance ) ;
2008-03-06 10:46:43 -06:00
}
DBoDeleteMethod ( Instance )
PyTypeObjectLinkPyType ( Instance )
PyTypeObjectConstructor ( Instance )
2008-10-19 17:07:32 -05:00
# else // End of Python Module Code Part.
2008-03-06 10:46:43 -06:00
// x=================================================================x
// | "PyInstance" Shared Library Code Part |
// x=================================================================x
// Link/Creation Method.
2008-10-12 08:37:33 -05:00
DBoLinkCreateMethod ( Instance )
2008-03-06 10:46:43 -06:00
// ---------------------------------------------------------------
// PyInstance Object Definitions.
2008-10-12 08:37:33 -05:00
PyTypeObjectDefinitions ( Instance )
2008-03-06 10:46:43 -06:00
2008-10-12 08:37:33 -05:00
# endif // End of Shared Library Code Part.
2008-03-06 10:46:43 -06:00
} // End of extern "C".
} // End of Isobar namespace.