coriolis/hurricane/src/isobar/PyEntity.cpp

224 lines
7.5 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: PyEntity.cpp,v 1.8 2007/04/26 13:38:47 d2 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 : "./PyEntity.cpp" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
2008-11-30 14:33:42 -06:00
#include "hurricane/Cell.h"
#include "hurricane/isobar/PyNet.h"
#include "hurricane/isobar/PyLayer.h"
#include "hurricane/isobar/PyPoint.h"
#include "hurricane/isobar/PyBox.h"
#include "hurricane/isobar/PyCell.h"
#include "hurricane/isobar/PyInstance.h"
#include "hurricane/isobar/PyReference.h"
#include "hurricane/isobar/PyComponent.h"
#include "hurricane/isobar/PyPlug.h"
#include "hurricane/isobar/PyHorizontal.h"
#include "hurricane/isobar/PyVertical.h"
#include "hurricane/isobar/PyContact.h"
2008-11-20 04:56:11 -06:00
#include "hurricane/isobar/PyPad.h"
#include "hurricane/isobar/PyPin.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" {
// x=================================================================x
// | "PyEntity" Python Module Code Part |
// x=================================================================x
#if defined(__PYTHON_MODULE__)
#define METHOD_HEAD(function) GENERIC_METHOD_HEAD(Entity,entity,function)
// x-------------------------------------------------------------x
// | "PyEntity" Attribute Methods |
// x-------------------------------------------------------------x
2008-03-17 08:54:33 -05:00
// Standart destroy (Attribute).
DBoDestroyAttribute(PyEntity_destroy ,PyEntity)
2008-03-06 10:46:43 -06:00
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyEntity_getCell ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject* PyEntity_getCell ( PyEntity *self )
2008-03-06 10:46:43 -06:00
{
2008-03-17 08:54:33 -05:00
trace << "PyEntity_getCell ()" << endl;
2008-03-06 10:46:43 -06:00
Cell* cell = NULL;
HTRY
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( "Entity.getCell()" )
cell = entity->getCell ();
2008-03-06 10:46:43 -06:00
HCATCH
return PyCell_Link ( cell );
}
// ---------------------------------------------------------------
// PyEntity Attribute Method table.
PyMethodDef PyEntity_Methods[] =
2008-03-17 08:54:33 -05:00
{ { "getCell" , (PyCFunction)PyEntity_getCell , METH_NOARGS , "Returns the entity cell." }
, { "destroy" , (PyCFunction)PyEntity_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
// | "PyEntity" Object Methods |
// x-------------------------------------------------------------x
DBoDeleteMethod(Entity)
PyTypeObjectLinkPyType(Entity)
# else // End of Python Module Code Part.
// x=================================================================x
// | "PyEntity" Shared Library Code Part |
// x=================================================================x
// ---------------------------------------------------------------
// Allocator Method : "PyEntity_NEW ()"
//
// No PyEntity should ever be created, it's not a terminal object
// of the class hierarchy. Instead create the real underlying PyObject.
2008-11-20 04:56:11 -06:00
PyObject* PyEntity_NEW ( Entity* entity ) {
2008-03-06 10:46:43 -06:00
if ( !entity ) {
PyErr_SetString ( HurricaneError, "Invalid Entity (bad occurrence)" ); \
return NULL;
}
Cell* cell = dynamic_cast<Cell*>(entity);
if ( cell ) return PyCell_Link ( cell );
Instance* instance = dynamic_cast<Instance*>(entity);
if ( instance ) return PyInstance_Link ( instance );
Reference* reference = dynamic_cast<Reference*>(entity);
if ( reference ) return PyReference_Link ( reference );
Horizontal* horizontal = dynamic_cast<Horizontal*>(entity);
if ( horizontal ) return PyHorizontal_Link ( horizontal );
Vertical* vertical = dynamic_cast<Vertical*>(entity);
if ( vertical ) return PyVertical_Link ( vertical );
2008-11-20 04:56:11 -06:00
Pad* pad = dynamic_cast<Pad*>(entity);
if ( pad ) return PyPad_Link ( pad );
2008-03-06 10:46:43 -06:00
Contact* contact = dynamic_cast<Contact*>(entity);
if ( contact ) return PyContact_Link ( contact );
Plug* plug = dynamic_cast<Plug*>(entity);
if ( plug ) return PyPlug_Link ( plug );
Pin* pin = dynamic_cast<Pin*>(entity);
if ( pin ) return PyPin_Link ( pin );
Net* net = dynamic_cast<Net*>(entity);
if ( net ) return PyNet_Link ( net );
Py_RETURN_NONE;
}
PyTypeObjectDefinitions(Entity)
2008-03-06 10:46:43 -06:00
// ---------------------------------------------------------------
// PyEntity Object Definitions.
# endif // End of Shared Library Code Part.
} // End of extern "C".
# if !defined(__PYTHON_MODULE__)
Hurricane::Entity* EntityCast ( PyObject* derivedObject )
{
if ( IsPyCell (derivedObject) ) return PYCELL_O(derivedObject);
if ( IsPyInstance (derivedObject) ) return PYINSTANCE_O(derivedObject);
if ( IsPyReference (derivedObject) ) return PYREFERENCE_O(derivedObject);
if ( IsPyPlug (derivedObject) ) return PYPLUG_O(derivedObject);
if ( IsPyHorizontal(derivedObject) ) return PYHORIZONTAL_O(derivedObject);
if ( IsPyVertical (derivedObject) ) return PYVERTICAL_O(derivedObject);
if ( IsPyContact (derivedObject) ) return PYCONTACT_O(derivedObject);
if ( IsPyPin (derivedObject) ) return PYPIN_O(derivedObject);
if ( IsPyNet (derivedObject) ) return PYNET_O(derivedObject);
return NULL;
}
# endif
} // End of Isobar namespace.