coriolis/hurricane/src/isobar/PyHurricane.cpp

704 lines
28 KiB
C++
Raw Normal View History

2008-03-06 10:46:43 -06:00
// -*- C++ -*-
//
// This file is part of the Coriolis Project.
// Copyright (C) Laboratoire LIP6 - Departement ASIM
// Universite Pierre et Marie Curie
//
// Main contributors :
// Christophe Alexandre <Christophe.Alexandre@lip6.fr>
// Sophie Belloeil <Sophie.Belloeil@lip6.fr>
// Hugo Cl<43>ment <Hugo.Clement@lip6.fr>
// Jean-Paul Chaput <Jean-Paul.Chaput@lip6.fr>
// Damien Dupuis <Damien.Dupuis@lip6.fr>
// Christian Masson <Christian.Masson@lip6.fr>
// Marek Sroka <Marek.Sroka@lip6.fr>
//
// The Coriolis Project is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// The Coriolis Project is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with the Coriolis Project; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
// License-Tag
// Authors-Tag
// ===================================================================
//
// $Id: PyHurricane.cpp,v 1.58 2008/02/07 19:09:58 xtof Exp $
//
// 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 : "./PyHurricane.cpp" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
#include "hurricane/isobar/PyHurricane.h"
#include "hurricane/isobar/PyUpdateSession.h"
#include "hurricane/isobar/PyDbU.h"
#include "hurricane/isobar/PyPoint.h"
#include "hurricane/isobar/PyBox.h"
#include "hurricane/isobar/PyTransformation.h"
#include "hurricane/isobar/PyDataBase.h"
#include "hurricane/isobar/PyLibrary.h"
#include "hurricane/isobar/PyEntity.h"
#include "hurricane/isobar/PyCell.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyCellCollection.h"
#include "hurricane/isobar/PyLayer.h"
#include "hurricane/isobar/PyPin.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyPinCollection.h"
#include "hurricane/isobar/PyInstance.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyInstanceCollection.h"
#include "hurricane/isobar/PyReference.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyReferenceCollection.h"
#include "hurricane/isobar/PyNet.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyNetCollection.h"
#include "hurricane/isobar/PyHyperNet.h"
#include "hurricane/isobar/PyComponent.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyComponentCollection.h"
#include "hurricane/isobar/PyPlug.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyPlugCollection.h"
#include "hurricane/isobar/PySegment.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PySegmentCollection.h"
#include "hurricane/isobar/PyContact.h"
#include "hurricane/isobar/PyHorizontal.h"
#include "hurricane/isobar/PyVertical.h"
2008-11-20 04:56:11 -06:00
#include "hurricane/isobar/PyPad.h"
#include "hurricane/isobar/PyPath.h"
#include "hurricane/isobar/PyOccurrence.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyOccurrenceCollection.h"
#include "hurricane/isobar/PyTechnology.h"
#include "hurricane/NetExternalComponents.h"
2008-03-06 10:46:43 -06:00
namespace Isobar {
2008-03-17 08:54:33 -05:00
#if !defined(__PYTHON_MODULE__)
2008-03-06 10:46:43 -06:00
// x=================================================================x
// | "PyHurricane" Shared Library Code Part |
// x=================================================================x
// x-----------------------------------------------------------------x
// | "PyHurricane" C++ Local Variables |
// x-----------------------------------------------------------------x
namespace {
using namespace std;
// ---------------------------------------------------------------
// Local Variables.
const char* objectTypeRedefinition =
"ConverterState::AddType () :\n\n"
" Attempt to add twice a type with identifier \n";
} // End of local namespace.
2008-03-28 04:48:47 -05:00
using namespace Hurricane;
2008-03-06 10:46:43 -06:00
// x-----------------------------------------------------------------x
// | "PyHurricane" C++ Global Variables |
// x-----------------------------------------------------------------x
const char* ConverterState::ObjectType::_inheritStop
2008-03-06 10:46:43 -06:00
= "comp";
ConverterState __cs = ConverterState ();
int __objectOffset = offsetof ( PyPoint, _object );
// x-----------------------------------------------------------------x
// | "PyHurricane" C++ Functions |
// x-----------------------------------------------------------------x
// -------------------------------------------------------------------
// Method : "::ConverterState::ObjectType::PyEqual ()"
bool ConverterState::ObjectType::PyEqual ( PyTypeObject* pyType ) {
if ( _pyType == pyType ) return true;
if ( _idBase[0] == '\0' ) return false;
2008-03-17 08:54:33 -05:00
return ( __cs.getObject(_idBase)->PyEqual(pyType) );
2008-03-06 10:46:43 -06:00
}
// -------------------------------------------------------------------
// Method : "::ConverterState::ObjectType::PyBase ()"
ConverterState::ObjectType* ConverterState::ObjectType::PyBase ( PyTypeObject* pyType )
{
if ( _pyType != pyType ) return NULL;
return ( PyBase() );
}
ConverterState::ObjectType* ConverterState::ObjectType::PyBase ()
{
if ( _idBase[0] == '\0' ) return this;
if ( ! strcmp(_id,_inheritStop) ) return this;
2008-03-17 08:54:33 -05:00
return ( __cs.getObject(_idBase)->PyBase() );
2008-03-06 10:46:43 -06:00
}
// -------------------------------------------------------------------
// Method : "::ConverterState::ObjectType::PyBaseId ()"
char* ConverterState::ObjectType::PyBaseId ( PyTypeObject* pyType )
{
if ( _idBase[0] == '\0' ) return _id;
if ( ! strcmp(_id,_inheritStop) ) return _id;
2008-03-17 08:54:33 -05:00
return ( __cs.getObject(_idBase)->PyBase(pyType)->_id );
2008-03-06 10:46:43 -06:00
}
// -------------------------------------------------------------------
// Destructor : "::ConverterState::~ConverterState ()"
ConverterState::~ConverterState () {
for ( unsigned i=0 ; i < _types.size() ; i++ )
delete _types [ i ];
}
// -------------------------------------------------------------------
2008-11-17 15:55:03 -06:00
// Method : "::ConverterState::addType ()"
2008-03-06 10:46:43 -06:00
void ConverterState::addType ( const char* id
2008-03-06 10:46:43 -06:00
, PyTypeObject* pyType
, const char* name
2008-03-06 10:46:43 -06:00
, bool isPythonType
, const char* idBase ) {
2008-03-06 10:46:43 -06:00
for ( unsigned i=0 ; i < _types.size() ; i++ ) {
if ( ! strcmp ( _types[i]->_id, id ) ) {
//throw Error ( objectTypeRedefinition ); // 04.09.2009 d2 modification so Pharos can run several scripts during one execution
trace << objectTypeRedefinition << endl;
return;
}
2008-03-06 10:46:43 -06:00
}
assert ( strlen ( id ) < 11 );
ObjectType* otype = new ObjectType;
strcpy ( otype->_id, id );
otype->_pyType = pyType;
otype->_name = name;
otype->_isPythonType = isPythonType;
strcpy ( otype->_idBase, idBase );
otype->_index = _types.size();
_types.push_back ( otype );
}
// -------------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Method : "::ConverterState::getObjectType ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
string ConverterState::getObjectType ( string objectsTypes, unsigned n ) {
2008-03-06 10:46:43 -06:00
string temp;
size_t end, head, tail, start;
unsigned element = 0;
end = objectsTypes.size();
if ( end > 0 ) {
for ( head=0 ; head <= end ; head=tail ) {
tail = objectsTypes.find ( ':' , head+1 );
start = head+1;
temp = objectsTypes.substr ( start, tail-start );
if ( n == element )
return temp;
element++;
}
}
return "";
}
// -------------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Method : "::ConverterState::getObjectId ()"
2008-03-06 10:46:43 -06:00
const char* ConverterState::getObjectId ( PyObject* object ) const {
2008-03-06 10:46:43 -06:00
for ( unsigned i=0 ; i < _types.size() ; i++ ) {
if ( ( ! strcmp ( _types[i]->_id, "function" ) ) && ( PyCallable_Check(object) ) )
return ( _types[i]->_id );
if ( ( ! strcmp ( _types[i]->_id, "none" ) ) && ( object == Py_None ) )
return ( _types[i]->_id );
if ( object->ob_type == _types[i]->_pyType ) return ( _types[i]->_id );
}
return ( "unknown" ); // return 'X'
}
// -------------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Method : "::ConverterState::getObject ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
ConverterState::ObjectType* ConverterState::getObject ( char* id ) {
2008-03-06 10:46:43 -06:00
for ( unsigned i=0 ; i < _types.size() ; i++ ) {
if ( ! strcmp ( id, _types[i]->_id ) ) return ( _types[i] );
}
return ( NULL );
}
// -------------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Method : "::ConverterState::getObjectName ()"
2008-03-06 10:46:43 -06:00
const char *ConverterState::getObjectName ( string id ) const {
2008-03-06 10:46:43 -06:00
for ( unsigned i=0 ; i < _types.size() ; i++ ) {
if ( ! strcmp ( id.c_str(), _types[i]->_id ) ) return ( _types[i]->_name );
}
return ( "<Unknown>" );
}
// -------------------------------------------------------------------
2008-11-17 15:55:03 -06:00
// Method : "::ConverterState::init ()"
2008-03-06 10:46:43 -06:00
void ConverterState::init ( const char* function, const char* inheritStop ) {
2008-03-06 10:46:43 -06:00
_objectIds = "";
2008-11-17 15:55:03 -06:00
setFunction ( function );
2008-03-06 10:46:43 -06:00
ObjectType::_inheritStop = inheritStop;
};
// -------------------------------------------------------------------
// Function : "Converter ()"
int Converter ( PyObject* object, void** pArg ) {
ostringstream message;
string unboundObject = "";
ConverterState::ObjectType* baseType;
2008-03-17 08:54:33 -05:00
for ( unsigned i=0 ; i < __cs.getTypes().size() ; i++ ) {
baseType = __cs.getTypes()[i]->PyBase ( object->ob_type );
2008-03-06 10:46:43 -06:00
if ( PyCallable_Check(object) || baseType ) {
*pArg = object;
i = baseType->_index;
2008-11-17 15:55:03 -06:00
__cs.addId ( baseType->_id );
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
if ( ! __cs.getTypes()[i]->_isPythonType ) {
2008-03-06 10:46:43 -06:00
void** member = ( (void**)( (unsigned long)object + __objectOffset ) );
if ( *member == NULL ) {
2008-03-17 08:54:33 -05:00
unboundObject = __cs.getTypes()[i]->_name;
2008-03-06 10:46:43 -06:00
break;
}
}
return ( 1 );
}
}
if ( unboundObject.size() ) {
2008-03-17 08:54:33 -05:00
message << "Attempt to call " << __cs.getFunction()
2008-03-06 10:46:43 -06:00
<< "() with an unbound " << unboundObject << " argument";
PyErr_SetString ( ProxyError, message.str().c_str() );
return ( 0 );
}
2008-03-17 08:54:33 -05:00
message << "Argument " << __cs.getSize() + 1
<< " of call to " << __cs.getFunction()
2008-03-06 10:46:43 -06:00
<< "() is of unmanaged type " << object->ob_type->tp_name;
PyErr_SetString ( ProxyError, message.str().c_str() );
return ( 0 );
}
// -------------------------------------------------------------------
// Function : "ParseOneArg ()"
2008-11-19 11:36:30 -06:00
bool ParseOneArg ( const char* function, PyObject* args, string format, PyObject** arg ) {
2008-03-06 10:46:43 -06:00
ostringstream message;
2008-11-17 15:55:03 -06:00
__cs.init ( function );
2008-03-06 10:46:43 -06:00
if ( ! PyArg_ParseTuple(args,"O&",Converter,arg) ) return ( false );
2008-03-17 08:54:33 -05:00
string firstArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 0 );
string firstArgTypeExp = ConverterState::getObjectType ( format , 0 );
2008-03-06 10:46:43 -06:00
if ( firstArgType != firstArgTypeExp ) {
return ( false );
}
return ( true );
}
// -------------------------------------------------------------------
// Function : "ParseTwoArg ()"
2008-11-19 11:36:30 -06:00
bool ParseTwoArg ( const char* function, PyObject* args, string format, PyObject** arg0, PyObject** arg1 ) {
2008-03-06 10:46:43 -06:00
ostringstream message;
2008-11-17 15:55:03 -06:00
__cs.init ( function );
2008-03-06 10:46:43 -06:00
if ( ! PyArg_ParseTuple(args,"O&O&",Converter,arg0,Converter,arg1) ) return ( false );
2008-03-17 08:54:33 -05:00
string firstArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 0 );
string firstArgTypeExp = ConverterState::getObjectType ( format , 0 );
2008-03-06 10:46:43 -06:00
if ( firstArgType != firstArgTypeExp ) {
return ( false );
}
2008-03-17 08:54:33 -05:00
string secondArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 1 );
string secondArgTypeExp = ConverterState::getObjectType ( format , 1 );
2008-03-06 10:46:43 -06:00
if ( secondArgType != secondArgTypeExp ) {
return ( false );
}
return ( true );
}
// -------------------------------------------------------------------
// Function : "ParseThreeArg ()"
2008-11-19 11:36:30 -06:00
bool ParseThreeArg ( const char* function, PyObject* args, string format, PyObject** arg0, PyObject** arg1, PyObject** arg2 ) {
2008-03-06 10:46:43 -06:00
ostringstream message;
2008-11-17 15:55:03 -06:00
__cs.init ( function );
2008-03-06 10:46:43 -06:00
if ( ! PyArg_ParseTuple(args,"O&O&O&",Converter,arg0,Converter,arg1,Converter,arg2) ) return ( false );
2008-03-17 08:54:33 -05:00
string firstArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 0 );
string firstArgTypeExp = ConverterState::getObjectType ( format , 0 );
2008-03-06 10:46:43 -06:00
if ( firstArgType != firstArgTypeExp ) {
return ( false );
}
2008-03-17 08:54:33 -05:00
string secondArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 1 );
string secondArgTypeExp = ConverterState::getObjectType ( format , 1 );
2008-03-06 10:46:43 -06:00
if ( secondArgType != secondArgTypeExp ) {
PyErr_SetString ( ProxyError, message.str().c_str() );
return ( false );
}
2008-03-17 08:54:33 -05:00
string thirdArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 2 );
string thirdArgTypeExp = ConverterState::getObjectType ( format , 2 );
2008-03-06 10:46:43 -06:00
if ( thirdArgType != thirdArgTypeExp ) {
2008-03-17 08:54:33 -05:00
message << "Third argument of call to " << __cs.getFunction()
2008-03-06 10:46:43 -06:00
<< "() is of unexpected type " << (*arg2)->ob_type->tp_name
2008-03-17 08:54:33 -05:00
<< ", must be of type " << __cs.getObjectName( thirdArgTypeExp );
2008-03-06 10:46:43 -06:00
PyErr_SetString ( ProxyError, message.str().c_str() );
return ( false );
}
return ( true );
}
// x-----------------------------------------------------------------x
// | "PyHurricane" C Global Variables |
// x-----------------------------------------------------------------x
extern "C" {
PyObject* ConstructorError = NULL;
PyObject* ProxyError = NULL;
PyObject* HurricaneError = NULL;
PyObject* CoriolisError = NULL;
PyObject* HurricaneWarning = NULL;
}
# else // End of PyHurricane Shared Library Code Part.
// x=================================================================x
// | "PyHurricane" Python Module Code Part |
// x=================================================================x
extern "C" {
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyNetExternalComponents_getNetExternalComponents ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
PyObject* PyNetExternalComponents_getExternalComponents ( PyObject* module, PyObject* args )
2008-03-06 10:46:43 -06:00
{
2008-03-17 08:54:33 -05:00
trace << "PyNetExternalComponents_getExternalComponents()" << endl;
2008-03-06 10:46:43 -06:00
PyObject* arg0;
2008-03-17 08:54:33 -05:00
if ( ! ParseOneArg ( "getExternalComponents", args, ":ent", &arg0) ) return ( NULL );
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
PyComponentCollection* pyComponentCollection = NULL;
2008-03-06 10:46:43 -06:00
HTRY
2008-10-17 12:27:20 -05:00
Components* components = new Components(NetExternalComponents::get(PYNET_O(arg0)));
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
pyComponentCollection = PyObject_NEW(PyComponentCollection, &PyTypeComponentCollection);
if (pyComponentCollection == NULL) { return NULL; }
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
pyComponentCollection->_object = components;
2008-03-06 10:46:43 -06:00
HCATCH
2008-10-17 12:27:20 -05:00
return ((PyObject*)pyComponentCollection);
2008-03-06 10:46:43 -06:00
}
// x-------------------------------------------------------------x
// | "PyHurricane" Module Methods |
// x-------------------------------------------------------------x
static PyMethodDef PyHurricane_Methods[] =
{ { "DbU_db" , PyDbU_db , METH_VARARGS, "Converts an integer to DbU::Unit (no scale factor)." }
, { "DbU_grid" , PyDbU_grid , METH_VARARGS, "Converts a founder grid to DbU::Unit." }
, { "DbU_lambda" , PyDbU_lambda , METH_VARARGS, "Converts a symbolic (lambda) to DbU::Unit." }
, { "DbU_getDb" , PyDbU_getDb , METH_VARARGS, "Converts a DbU::Unit to an integer value (no scale factor)." }
, { "DbU_getGrid" , PyDbU_getGrid , METH_VARARGS, "Converts a DbU::Unit to a to grid founder." }
, { "DbU_getLambda" , PyDbU_getLambda , METH_VARARGS, "Converts a DbU::Unit to a symbolic value (to lambda)." }
, { "DbU_getPhysical" , PyDbU_getPhysical , METH_VARARGS, "Converts a DbU::Unit to a physical value." }
, { "DbU_getOnPhysicalGrid" , PyDbU_getOnPhysicalGrid , METH_VARARGS, "Adjusts a DbU::Unit to physical grid." }
, { "Point" , PyPoint_create , METH_VARARGS, "Creates a new Point." }
, { "Box" , PyBox_create , METH_VARARGS, "Creates a new Box." }
, { "Transformation" , PyTransformation_create , METH_VARARGS, "Creates a new Transformation." }
, { "UpdateSession_open" , (PyCFunction)PyUpdateSession_open , METH_NOARGS , "Opens an update session." }
, { "UpdateSession_close" , (PyCFunction)PyUpdateSession_close , METH_NOARGS , "Closes an update session." }
, { "DataBase" , (PyCFunction)PyDataBase_create , METH_NOARGS , "Creates the DataBase." }
, { "getDataBase" , (PyCFunction)PyDataBase_getDataBase , METH_NOARGS , "Gets the current DataBase." }
, { "Library" , (PyCFunction)PyLibrary_create , METH_VARARGS, "Creates a new Library." }
// , { "getLibrary" , (PyCFunction)PyLibrary_getLibrary , METH_NOARGS , "Gets the current Library." }
, { "Reference" , (PyCFunction)PyReference_create , METH_VARARGS, "Creates a new Reference." }
, { "Cell" , (PyCFunction)PyCell_create , METH_VARARGS, "Creates a new Cell." }
, { "Instance" , (PyCFunction)PyInstance_create , METH_VARARGS, "Creates a new Instance." }
, { "Net" , (PyCFunction)PyNet_create , METH_VARARGS, "Creates a new Net." }
, { "HyperNet" , (PyCFunction)PyHyperNet_create , METH_VARARGS, "Creates a new HyperNet." }
, { "Horizontal" , (PyCFunction)PyHorizontal_create , METH_VARARGS, "Creates a new Horizontal." }
, { "Vertical" , (PyCFunction)PyVertical_create , METH_VARARGS, "Creates a new Vertical." }
, { "Contact" , (PyCFunction)PyContact_create , METH_VARARGS, "Creates a new Contact." }
, { "Pin" , (PyCFunction)PyPin_create , METH_VARARGS, "Creates a new Pin." }
, { "Pad" , (PyCFunction)PyPad_create , METH_VARARGS, "Creates a new Pad." }
, { "Path" , (PyCFunction)PyPath_create , METH_VARARGS, "Creates a new Path." }
, { "Occurrence" , (PyCFunction)PyOccurrence_create , METH_VARARGS, "Creates a new Occurrence." }
2008-03-17 08:54:33 -05:00
, { "getExternalComponents" , (PyCFunction)PyNetExternalComponents_getExternalComponents, METH_VARARGS, "Returns the components collection of an external net" }
2008-03-06 10:46:43 -06:00
, {NULL, NULL, 0, NULL} /* sentinel */
};
// ---------------------------------------------------------------
// Module Initialization : "initHurricane ()"
DL_EXPORT(void) initHurricane () {
trace << "initHurricane()" << endl;
PyPoint_LinkPyType ();
PyBox_LinkPyType ();
PyTransformation_LinkPyType ();
PyDataBase_LinkPyType ();
PyTechnology_LinkPyType ();
PyLibrary_LinkPyType ();
PyEntity_LinkPyType ();
PyLayer_LinkPyType ();
PyPath_LinkPyType ();
PyOccurrence_LinkPyType ();
2008-10-17 12:27:20 -05:00
PyInstanceCollection_LinkPyType ();
PyPlugCollection_LinkPyType ();
PyNetCollection_LinkPyType ();
2008-10-14 05:48:53 -05:00
PyNetCollection_LinkPyType ();
2008-10-17 12:27:20 -05:00
PyCellCollection_LinkPyType ();
PyPinCollection_LinkPyType ();
PySegmentCollection_LinkPyType ();
PyOccurrenceCollection_LinkPyType ();
PyComponentCollection_LinkPyType ();
PyReferenceCollection_LinkPyType ();
2008-03-06 10:46:43 -06:00
PyCell_LinkPyType ();
PyInstance_LinkPyType ();
PyReference_LinkPyType ();
PyNet_LinkPyType ();
PyHyperNet_LinkPyType ();
PyComponent_LinkPyType ();
PySegment_LinkPyType ();
2008-11-20 04:56:11 -06:00
PyPad_LinkPyType ();
2008-03-06 10:46:43 -06:00
PyVertical_LinkPyType ();
PyHorizontal_LinkPyType ();
PyContact_LinkPyType ();
PyPin_LinkPyType ();
PyPlug_LinkPyType ();
2008-10-17 12:27:20 -05:00
PYTYPE_READY ( Point )
PYTYPE_READY ( Box )
PYTYPE_READY ( Transformation )
PYTYPE_READY ( DataBase )
PYTYPE_READY ( Technology )
PYTYPE_READY ( Library )
PYTYPE_READY ( Entity )
PYTYPE_READY ( Layer )
PYTYPE_READY ( Path )
PYTYPE_READY ( Occurrence )
PYTYPE_READY ( InstanceCollection )
PYTYPE_READY ( InstanceCollectionLocator )
PYTYPE_READY ( PlugCollection )
PYTYPE_READY ( PlugCollectionLocator )
PYTYPE_READY ( NetCollection )
PYTYPE_READY ( NetCollectionLocator )
PYTYPE_READY ( CellCollection )
PYTYPE_READY ( CellCollectionLocator )
PYTYPE_READY ( PinCollection )
PYTYPE_READY ( PinCollectionLocator )
PYTYPE_READY ( SegmentCollection )
PYTYPE_READY ( SegmentCollectionLocator )
PYTYPE_READY ( ComponentCollection )
PYTYPE_READY ( ComponentCollectionLocator )
PYTYPE_READY ( OccurrenceCollection )
PYTYPE_READY ( OccurrenceCollectionLocator )
PYTYPE_READY ( ReferenceCollection )
PYTYPE_READY ( ReferenceCollectionLocator )
PYTYPE_READY ( HyperNet )
2008-03-06 10:46:43 -06:00
PYTYPE_READY_SUB ( Cell , Entity )
PYTYPE_READY_SUB ( Instance , Entity )
PYTYPE_READY_SUB ( Reference , Entity )
PYTYPE_READY_SUB ( Net , Entity )
PYTYPE_READY_SUB ( Component , Entity )
PYTYPE_READY_SUB ( Segment , Component)
PYTYPE_READY_SUB ( Horizontal, Segment )
PYTYPE_READY_SUB ( Vertical , Segment )
PYTYPE_READY_SUB ( Contact , Component)
PYTYPE_READY_SUB ( Pin , Contact )
PYTYPE_READY_SUB ( Plug , Component)
2008-11-20 04:56:11 -06:00
PYTYPE_READY_SUB ( Pad , Component)
2008-03-06 10:46:43 -06:00
// Identifier string can take up to 10 characters !
2008-11-17 15:55:03 -06:00
__cs.addType ( "box" , &PyTypeBox , "<Box>" , false );
__cs.addType ( "ent" , &PyTypeEntity , "<Entity>" , false );
__cs.addType ( "cell" , &PyTypeCell , "<Cell>" , false, "ent" );
__cs.addType ( "cellCol" , &PyTypeCellCollection , "<CellCollection>" , false );
__cs.addType ( "comp" , &PyTypeComponent , "<Component>" , false, "ent" );
__cs.addType ( "compCol" , &PyTypeComponentCollection, "<ComponentCollection>" , false );
__cs.addType ( "contact" , &PyTypeContact , "<Contact>" , false, "comp" );
2008-03-06 10:46:43 -06:00
// Do not change the "none" string. It's hardwired to the None object.
2008-11-17 15:55:03 -06:00
__cs.addType ( "none" , Py_None->ob_type , "<None>" , true );
__cs.addType ( "float" , &PyFloat_Type , "<Float>" , true );
__cs.addType ( "int" , &PyInt_Type , "<Int>" , true );
__cs.addType ( "bool" , &PyBool_Type , "<Bool>" , true );
__cs.addType ( "string" , &PyString_Type , "<String>" , true );
__cs.addType ( "list" , &PyList_Type , "<List>" , true );
2008-03-06 10:46:43 -06:00
// Do not change the "function" string. It's hardwired to callable (function) objects.
2008-11-17 15:55:03 -06:00
__cs.addType ( "function" , NULL , "<Function>" , true );
__cs.addType ( "horiz" , &PyTypeHorizontal , "<Horizontal>" , false, "segment" );
__cs.addType ( "inst" , &PyTypeInstance , "<Instance>" , false, "ent" );
__cs.addType ( "instCol" , &PyTypeInstanceCollection, "<InstanceCollection>" , false );
__cs.addType ( "layer" , &PyTypeLayer , "<Layer>" , false );
__cs.addType ( "library" , &PyTypeLibrary , "<Library>" , false );
__cs.addType ( "ref" , &PyTypeReference , "<Reference>" , false, "ent" );
__cs.addType ( "refCol" , &PyTypeReferenceCollection, "<ReferenceCollection>" , false );
__cs.addType ( "net" , &PyTypeNet , "<Net>" , false, "ent" );
__cs.addType ( "netCol" , &PyTypeNetCollection , "<NetCollection>" , false );
__cs.addType ( "hyperNet" , &PyTypeHyperNet , "<HyperNet>" , false );
__cs.addType ( "pin" , &PyTypePin , "<Pin>" , false, "contact" );
__cs.addType ( "pinCol" , &PyTypePinCollection , "<PinCollection>" , false );
__cs.addType ( "plug" , &PyTypePlug , "<Plug>" , false, "comp" );
__cs.addType ( "plugCol" , &PyTypePlugCollection , "<PlugCollection>" , false );
__cs.addType ( "point" , &PyTypePoint , "<Point>" , false );
__cs.addType ( "segment" , &PyTypeSegment , "<Segment>" , false, "comp" );
2008-11-20 04:56:11 -06:00
__cs.addType ( "pad " , &PyTypePad , "<Pad>" , false, "comp" );
2008-11-17 15:55:03 -06:00
__cs.addType ( "segmentCol" , &PyTypeSegmentCollection, "<SegmentCollection>", false );
__cs.addType ( "db" , &PyTypeDataBase , "<DataBase>" , false );
__cs.addType ( "techno" , &PyTypeTechnology , "<Technology>" , false );
__cs.addType ( "transfo" , &PyTypeTransformation , "<Transformation>" , false );
__cs.addType ( "vert" , &PyTypeVertical , "<Vertical>" , false, "segment" );
__cs.addType ( "path" , &PyTypePath , "<Path>" , false );
__cs.addType ( "occur" , &PyTypeOccurrence , "<Occurrence>" , false );
__cs.addType ( "occurCol" , &PyTypeOccurrenceCollection, "<OccurrenceCollection>", false );
2008-03-06 10:46:43 -06:00
PyObject* module = Py_InitModule ( "Hurricane", PyHurricane_Methods );
if ( module == NULL ) {
cerr << "[ERROR]\n"
<< " Failed to initialize Hurricane module." << endl;
return;
}
//PyModule_AddObject(module, "Box", (PyObject*)&PyTypeBox); // To add Hurricane.Box type in module -> the Hurricane.Box() method must be renamed
2008-03-06 10:46:43 -06:00
PyObject* dictionnary = PyModule_GetDict ( module );
ConstructorError = PyErr_NewException ( "hurricane.ConstructorError", NULL, NULL );
ProxyError = PyErr_NewException ( "hurricane.ProxyError" , NULL, NULL );
HurricaneError = PyErr_NewException ( "hurricane.HurricaneError" , NULL, NULL );
HurricaneWarning = PyErr_NewException ( "hurricane.HurricaneWarning", PyExc_Warning, NULL );
PyDict_SetItemString ( dictionnary, "ConstructorError", ConstructorError );
PyDict_SetItemString ( dictionnary, "ProxyError" , ProxyError );
PyDict_SetItemString ( dictionnary, "HurricaneError" , HurricaneError );
DbULoadConstants ( dictionnary );
2008-03-06 10:46:43 -06:00
TransformationLoadConstants ( dictionnary );
NetLoadConstants ( dictionnary );
InstanceLoadConstants ( dictionnary );
PinLoadConstants ( dictionnary );
}
} // End of extern "C".
2008-03-17 08:54:33 -05:00
#endif // End of Python Module Code Part.
2008-03-06 10:46:43 -06:00
} // End of Isobar namespace.