From ecf22a10c13689775c4d0985ea6dd8ff9a264efa Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sat, 27 Apr 2013 17:51:33 +0000 Subject: [PATCH] * ./hurricane/sr/isobar: - New: Added support for Hook Collections, PyHookCollection. --- hurricane/src/isobar/CMakeLists.txt | 3 + hurricane/src/isobar/PyHook.cpp | 47 +++++++++++++++ hurricane/src/isobar/PyHookCollection.cpp | 58 +++++++++++++++++++ hurricane/src/isobar/PyHurricane.cpp | 6 ++ .../hurricane/isobar/PyHookCollection.h | 58 +++++++++++++++++++ .../src/isobar/hurricane/isobar/PyHurricane.h | 18 +++++- 6 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 hurricane/src/isobar/PyHookCollection.cpp create mode 100644 hurricane/src/isobar/hurricane/isobar/PyHookCollection.h diff --git a/hurricane/src/isobar/CMakeLists.txt b/hurricane/src/isobar/CMakeLists.txt index 457d6fcb..8e47821f 100644 --- a/hurricane/src/isobar/CMakeLists.txt +++ b/hurricane/src/isobar/CMakeLists.txt @@ -41,6 +41,7 @@ PyOccurrence.cpp PyOccurrenceCollection.cpp PyHook.cpp + PyHookCollection.cpp PyPad.cpp PyPath.cpp PyPin.cpp @@ -95,6 +96,8 @@ hurricane/isobar/PyNetExternalComponents.h hurricane/isobar/PyOccurrence.h hurricane/isobar/PyOccurrenceCollection.h + hurricane/isobar/PyHook.h + hurricane/isobar/PyHookCollection.h hurricane/isobar/PyPad.h hurricane/isobar/PyPath.h hurricane/isobar/PyPin.h diff --git a/hurricane/src/isobar/PyHook.cpp b/hurricane/src/isobar/PyHook.cpp index 23b1a3f8..f172bac2 100644 --- a/hurricane/src/isobar/PyHook.cpp +++ b/hurricane/src/isobar/PyHook.cpp @@ -18,6 +18,7 @@ #include "hurricane/isobar/PyEntity.h" #include "hurricane/isobar/PyComponent.h" #include "hurricane/isobar/PyHook.h" +#include "hurricane/isobar/PyHookCollection.h" namespace Isobar { @@ -57,6 +58,48 @@ extern "C" { return (PyObject*)PyEntity_NEW(component); } + + + static PyObject* PyHook_getHooks ( PyHook *self ) + { + trace << "PyHook_getHooks()" << endl; + + METHOD_HEAD( "Hook.getHooks()" ) + + PyHookCollection* pyHookCollection = NULL; + + HTRY + Hooks* hooks = new Hooks( hook->getHooks() ); + + pyHookCollection = PyObject_NEW( PyHookCollection, &PyTypeHookCollection ); + if (pyHookCollection == NULL) return NULL; + + pyHookCollection->_object = hooks; + HCATCH + + return (PyObject*)pyHookCollection; + } + + + static PyObject* PyHook_getSlaveHooks ( PyHook *self ) + { + trace << "PyHook_getSlaveHooks()" << endl; + + METHOD_HEAD( "Hook.getSlaveHooks()" ) + + PyHookCollection* pyHookCollection = NULL; + + HTRY + Hooks* hooks = new Hooks( hook->getSlaveHooks() ); + + pyHookCollection = PyObject_NEW( PyHookCollection, &PyTypeHookCollection ); + if (pyHookCollection == NULL) return NULL; + + pyHookCollection->_object = hooks; + HCATCH + + return (PyObject*)pyHookCollection; + } static PyObject* PyHook_detach ( PyHook *self ) @@ -145,6 +188,10 @@ extern "C" { , "Return the master hook next to the master of this Hook." } , { "getPreviousMasterHook", (PyCFunction)PyHook_getPreviousMasterHook, METH_NOARGS , "Return the master hook previous to the master of this Hook (walk trough the whole ring)." } + , { "getHooks" , (PyCFunction)PyHook_getHooks , METH_NOARGS + , "Return the Collection of all hooks part of that ring." } + , { "getSlaveHooks" , (PyCFunction)PyHook_getSlaveHooks , METH_NOARGS + , "Return the Collection of all hooks slave to this one." } , { "isMaster" , (PyCFunction)PyHook_isMaster , METH_NOARGS , "Tells if this Hook is of master kind" } , { "isAttached" , (PyCFunction)PyHook_isAttached , METH_NOARGS diff --git a/hurricane/src/isobar/PyHookCollection.cpp b/hurricane/src/isobar/PyHookCollection.cpp new file mode 100644 index 00000000..ee476710 --- /dev/null +++ b/hurricane/src/isobar/PyHookCollection.cpp @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC 2013-2013, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | 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@lip6.fr | +// | =============================================================== | +// | C++ Module : "./PyHookCollection.cpp" | +// +-----------------------------------------------------------------+ + + +#include "hurricane/isobar/PyHookCollection.h" +#include "hurricane/isobar/PyHook.h" + + +namespace Isobar { + +using namespace Hurricane; + + +extern "C" { + + +#if defined(__PYTHON_MODULE__) + +// +=================================================================+ +// | "PyHookCollection" Python Module Code Part | +// +=================================================================+ + + + DirectDeleteMethod(PyHookCollection_DeAlloc, PyHookCollection) + + NolinkLocatorNextMethod(Hook) + CollectionMethods(Hook) + + +#else // End of Python Module Code Part. + +// +=================================================================+ +// | "PyHookCollection" Shared Library Code Part | +// +=================================================================+ + + + PyTypeCollectionObjectDefinitions(HookCollection) + PyTypeCollectionObjectDefinitions(HookCollectionLocator) + +#endif // End of Shared Library Code Part. + + +} // End of extern "C". + +} // End of Isobar namespace. diff --git a/hurricane/src/isobar/PyHurricane.cpp b/hurricane/src/isobar/PyHurricane.cpp index 509b2a8e..b9b65c62 100644 --- a/hurricane/src/isobar/PyHurricane.cpp +++ b/hurricane/src/isobar/PyHurricane.cpp @@ -51,6 +51,7 @@ #include "hurricane/isobar/PyNetExternalComponents.h" #include "hurricane/isobar/PyHyperNet.h" #include "hurricane/isobar/PyHook.h" +#include "hurricane/isobar/PyHookCollection.h" #include "hurricane/isobar/PyComponent.h" #include "hurricane/isobar/PyComponentCollection.h" #include "hurricane/isobar/PyPlug.h" @@ -550,6 +551,7 @@ extern "C" { PyNet_LinkPyType (); PyHyperNet_LinkPyType (); PyHook_LinkPyType (); + PyHookCollection_LinkPyType (); PyComponent_LinkPyType (); PySegment_LinkPyType (); PyPad_LinkPyType (); @@ -573,6 +575,7 @@ extern "C" { PYTYPE_READY ( Library ) PYTYPE_READY ( Entity ) PYTYPE_READY ( Hook ) + PYTYPE_READY ( HookCollection ) PYTYPE_READY ( Material ) PYTYPE_READY ( Layer ) PYTYPE_READY ( LayerMask ) @@ -637,6 +640,7 @@ extern "C" { __cs.addType ( "cell" , &PyTypeCell , "" , false, "ent" ); __cs.addType ( "cellCol" , &PyTypeCellCollection , "" , false ); __cs.addType ( "hook" , &PyTypeHook , "" , false ); + __cs.addType ( "hookColl" , &PyTypeHookCollection , "" , false ); __cs.addType ( "comp" , &PyTypeComponent , "" , false, "ent" ); __cs.addType ( "compCol" , &PyTypeComponentCollection , "" , false ); __cs.addType ( "contact" , &PyTypeContact , "" , false, "comp" ); @@ -729,6 +733,8 @@ extern "C" { Py_INCREF ( &PyTypeHook ); PyModule_AddObject ( module, "Hook" , (PyObject*)&PyTypeHook ); + Py_INCREF ( &PyTypeHookCollection ); + PyModule_AddObject ( module, "HookCollection" , (PyObject*)&PyTypeHookCollection ); Py_INCREF ( &PyTypeRoutingPad ); PyModule_AddObject ( module, "RoutingPad" , (PyObject*)&PyTypeRoutingPad ); Py_INCREF ( &PyTypeVertical ); diff --git a/hurricane/src/isobar/hurricane/isobar/PyHookCollection.h b/hurricane/src/isobar/hurricane/isobar/PyHookCollection.h new file mode 100644 index 00000000..a8c58a6f --- /dev/null +++ b/hurricane/src/isobar/hurricane/isobar/PyHookCollection.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC 2013-2013, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | 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@lip6.fr | +// | =============================================================== | +// | C++ Header : "./hurricane/isobar/PyHookCollection.h" | +// +-----------------------------------------------------------------+ + + +#ifndef ISOBAR_PYSEGMENT_COLLECTION_H +#define ISOBAR_PYSEGMENT_COLLECTION_H + +#include "hurricane/isobar/PyHurricane.h" +#include "hurricane/Hook.h" +#include "hurricane/Hooks.h" + + +namespace Isobar { + +extern "C" { + +// ------------------------------------------------------------------- +// Python Object : "PyHookCollection". + + typedef struct { + PyObject_HEAD + Hurricane::Hooks* _object; + } PyHookCollection; + + typedef struct { + PyObject_HEAD + Hurricane::Locator* _object; + PyHookCollection* _collection; + } PyHookCollectionLocator; + + +// ------------------------------------------------------------------- +// Functions & Types exported to "PyHurricane.ccp". + + extern PyTypeObject PyTypeHookCollection; + extern PyTypeObject PyTypeHookCollectionLocator; + + extern void PyHookCollection_LinkPyType(); + extern void PyHookCollectionLocator_LinkPyType(); + +} // extern "C". + +} // Isobar namespace. + +#endif diff --git a/hurricane/src/isobar/hurricane/isobar/PyHurricane.h b/hurricane/src/isobar/hurricane/isobar/PyHurricane.h index 8d6a7b97..0b062d1b 100644 --- a/hurricane/src/isobar/hurricane/isobar/PyHurricane.h +++ b/hurricane/src/isobar/hurricane/isobar/PyHurricane.h @@ -719,8 +719,24 @@ extern "C" { return NULL; \ } +#define NolinkLocatorNextMethod(TYPE) \ + static PyObject* Py##TYPE##LocatorNext(Py##TYPE##CollectionLocator* pyLocator) \ + { \ + Locator* locator = pyLocator->_object; \ + HTRY \ + if (locator->isValid()) { \ + Py##TYPE* pyObject = PyObject_NEW( Py##TYPE, &PyType##TYPE ); \ + if (pyObject == NULL) return NULL; \ + pyObject->_object = locator->getElement(); \ + locator->progress(); \ + return (PyObject*)pyObject; \ + } \ + HCATCH \ + return NULL; \ + } -#define EntityLocatorNextMethod(TYPE) \ + +#define EntityLocatorNextMethod(TYPE) \ static PyObject* Py##TYPE##LocatorNext(Py##TYPE##CollectionLocator* pyLocator) { \ Locator* locator = pyLocator->_object; \ HTRY \