[MOAB-dev] r2923 - in MOAB/trunk/tools/iMesh/python: . doc test
jvporter at wisc.edu
jvporter at wisc.edu
Mon Jun 1 16:21:49 CDT 2009
Author: jvporter
Date: 2009-06-01 16:21:49 -0500 (Mon, 01 Jun 2009)
New Revision: 2923
Modified:
MOAB/trunk/tools/iMesh/python/common.h
MOAB/trunk/tools/iMesh/python/doc/imesh.rst
MOAB/trunk/tools/iMesh/python/iBase.c
MOAB/trunk/tools/iMesh/python/iMesh.c
MOAB/trunk/tools/iMesh/python/iMesh_Python.h
MOAB/trunk/tools/iMesh/python/iMesh_entSet.c
MOAB/trunk/tools/iMesh/python/iMesh_iter.c
MOAB/trunk/tools/iMesh/python/iMesh_tag.c
MOAB/trunk/tools/iMesh/python/test/entset.py
MOAB/trunk/tools/iMesh/python/test/iter.py
MOAB/trunk/tools/iMesh/python/test/tags.py
Log:
* Cleanup code
* Resolve potential crash
* Add "instance" member to iMesh handles
Modified: MOAB/trunk/tools/iMesh/python/common.h
===================================================================
--- MOAB/trunk/tools/iMesh/python/common.h 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/common.h 2009-06-01 21:21:49 UTC (rev 2923)
@@ -2,64 +2,53 @@
#include <Python.h>
-#define SIMPLE_TYPE(name,type,name_str,doc) \
- static PyTypeObject type = { \
- PyObject_HEAD_INIT(NULL) \
- 0, /*ob_size*/ \
- (name_str), /*tp_name*/ \
- sizeof(name), /*tp_basicsize*/ \
- 0, /*tp_itemsize*/ \
- 0, /*tp_dealloc*/ \
- 0, /*tp_print*/ \
- 0, /*tp_getattr*/ \
- 0, /*tp_setattr*/ \
- 0, /*tp_compare*/ \
- 0, /*tp_repr*/ \
- 0, /*tp_as_number*/ \
- 0, /*tp_as_sequence*/ \
- 0, /*tp_as_mapping*/ \
- 0, /*tp_hash */ \
- 0, /*tp_call*/ \
- 0, /*tp_str*/ \
- 0, /*tp_getattro*/ \
- 0, /*tp_setattro*/ \
- 0, /*tp_as_buffer*/ \
- Py_TPFLAGS_DEFAULT, /*tp_flags*/ \
- (doc), /* tp_doc */ \
-}
+#define SIMPLE_TYPE(name,name_str,doc) \
+ static PyTypeObject name ## _Type = { \
+ PyObject_HEAD_INIT(NULL) \
+ 0, /* ob_size*/ \
+ (name_str), /* tp_name*/ \
+ sizeof(name ## _Object), /* tp_basicsize */ \
+ 0, /* tp_itemsize */ \
+ 0, /* tp_dealloc */ \
+ 0, /* tp_print */ \
+ 0, /* tp_getattr */ \
+ 0, /* tp_setattr */ \
+ 0, /* tp_compare */ \
+ 0, /* tp_repr */ \
+ 0, /* tp_as_number */ \
+ 0, /* tp_as_sequence */ \
+ 0, /* tp_as_mapping */ \
+ 0, /* tp_hash */ \
+ 0, /* tp_call */ \
+ 0, /* tp_str */ \
+ 0, /* tp_getattro */ \
+ 0, /* tp_setattro */ \
+ 0, /* tp_as_buffer */ \
+ Py_TPFLAGS_DEFAULT, /* tp_flags */ \
+ (doc), /* tp_doc */ \
+ }
-#define ENUM_TYPE(name,namestr,docstr) \
- typedef struct \
- { \
- PyObject_HEAD \
- } name ## _Object; \
- SIMPLE_TYPE(name ## _Object,name ## _Type, \
- namestr,docstr)
+#define ENUM_TYPE(name,namestr,docstr) \
+ typedef struct \
+ { \
+ PyObject_HEAD \
+ } name ## _Object; \
+ SIMPLE_TYPE(name,namestr,docstr)
-#define ADD_ENUM(typename,name,value) \
- do { \
- PyObject *o = Py_BuildValue("i",(value)); \
- PyDict_SetItemString((&typename ## _Type)-> \
- tp_dict,(name),o); \
- Py_DECREF(o); \
- } while(0)
+#define ADD_ENUM(typename,name,value) \
+ do { \
+ PyObject *o = Py_BuildValue("i",(value)); \
+ PyDict_SetItemString((&typename ## _Type)-> \
+ tp_dict,(name),o); \
+ Py_DECREF(o); \
+ } while(0)
-#define REGISTER_SIMPLE(m,name) \
- do { \
- name ## _Type.tp_new = PyType_GenericNew; \
- if(PyType_Ready(&name ## _Type) < 0) \
- return; \
- Py_INCREF(&name ## _Type); \
- PyModule_AddObject(m,#name, \
- (PyObject *)&name ## _Type); \
- } while(0)
-
-#define REGISTER_SIMPLE_SUB(base,name) \
- do { \
- name ## _Type.tp_new = PyType_GenericNew; \
- if(PyType_Ready(&name ## _Type) < 0) \
- return; \
- Py_INCREF(&name ## _Type); \
- PyDict_SetItemString(base.tp_dict,#name, \
- (PyObject *)&name ## _Type); \
- } while(0)
+#define REGISTER_SIMPLE(m,py_name,name) \
+ do { \
+ name ## _Type.tp_new = PyType_GenericNew; \
+ if(PyType_Ready(&name ## _Type) < 0) \
+ return; \
+ Py_INCREF(&name ## _Type); \
+ PyModule_AddObject(m,py_name, \
+ (PyObject *)&name ## _Type); \
+ } while(0)
Modified: MOAB/trunk/tools/iMesh/python/doc/imesh.rst
===================================================================
--- MOAB/trunk/tools/iMesh/python/doc/imesh.rst 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/doc/imesh.rst 2009-06-01 21:21:49 UTC (rev 2923)
@@ -223,7 +223,7 @@
Get all the tags associated with a specified entity or entity set.
:param entities: Entity or entity set being queried
- :return: Array of :class:`Tag` s associated with ``entities``
+ :return: Array of :class:`Tag`\ s associated with ``entities``
EntitySet
@@ -231,6 +231,10 @@
.. class:: EntitySet
+ .. attribute:: instance
+
+ Return the :class:`Mesh` instance from which this entity set was created.
+
.. attribute:: isList
Return whether this entity set is ordered.
@@ -451,6 +455,10 @@
:param topo: Topology of entities being requested
:param count: Number of entities to return on each step of iteration
+ .. attribute:: instance
+
+ Return the :class:`Mesh` instance from which this iterator was created.
+
.. method:: reset()
Resets the iterator to the beginning.
@@ -461,6 +469,10 @@
.. class:: Tag
+ .. attribute:: instance
+
+ Return the :class:`Mesh` instance from which this tag was created.
+
.. attribute:: name
Get the name for this tag.
Modified: MOAB/trunk/tools/iMesh/python/iBase.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/iBase.c 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/iBase.c 2009-06-01 21:21:49 UTC (rev 2923)
@@ -3,10 +3,9 @@
#include <numpy/arrayobject.h>
-SIMPLE_TYPE(iBaseEntity_Object,iBaseEntity_Type,"itaps.iBase.iBaseEntity","");
-SIMPLE_TYPE(iBaseEntitySet_Object,iBaseEntitySet_Type,
- "itaps.iBase.iBaseEntitySet","");
-SIMPLE_TYPE(iBaseTag_Object,iBaseTag_Type,"itaps.iBase.iBaseTag","");
+SIMPLE_TYPE(iBaseEntity,"itaps.iBase.Entity","");
+SIMPLE_TYPE(iBaseEntitySet,"itaps.iBase.EntitySet","");
+SIMPLE_TYPE(iBaseTag,"itaps.iBase.Tag","");
static PyObject *
iBaseEntity_FromHandle(iBase_EntityHandle h)
@@ -35,10 +34,10 @@
}
static int NPY_IBASETAG;
-ENUM_TYPE(Type, "iBase.Type", "");
-ENUM_TYPE(AdjCost, "iBase.AdjCost", "");
-ENUM_TYPE(StorageOrder, "iBase.StorageOrder", "");
-ENUM_TYPE(CreationStatus, "iBase.CreationStatus", "");
+ENUM_TYPE(iBaseType, "iBase.Type", "");
+ENUM_TYPE(iBaseAdjCost, "iBase.AdjCost", "");
+ENUM_TYPE(iBaseStorageOrder, "iBase.StorageOrder", "");
+ENUM_TYPE(iBaseCreationStatus, "iBase.CreationStatus", "");
static PyMethodDef module_methods[] = {
{0}
@@ -79,7 +78,7 @@
iBaseEntObj_repr(iBaseEntity_Object *self)
{
char out[64];
- snprintf(out,64,"<iBase_EntityHandle %p>",self->handle);
+ snprintf(out,64,"<itaps.iBase.Entity %p>",self->handle);
return Py_BuildValue("s",out);
}
@@ -146,7 +145,7 @@
iBaseEntSetObj_repr(iBaseEntitySet_Object *self)
{
char out[64];
- snprintf(out,64,"<iBase_EntitySetHandle %p>",self->handle);
+ snprintf(out,64,"<itaps.iBase.EntitySet %p>",self->handle);
return Py_BuildValue("s",out);
}
@@ -252,66 +251,55 @@
PyModule_AddObject(m, "_C_API", api_obj);
/***** initialize type enum *****/
- REGISTER_SIMPLE(m,Type);
+ REGISTER_SIMPLE(m,"Type",iBaseType);
- ADD_ENUM(Type,"vertex", iBase_VERTEX);
- ADD_ENUM(Type,"edge", iBase_EDGE);
- ADD_ENUM(Type,"face", iBase_FACE);
- ADD_ENUM(Type,"region", iBase_REGION);
- ADD_ENUM(Type,"all", iBase_ALL_TYPES);
+ ADD_ENUM(iBaseType,"vertex", iBase_VERTEX);
+ ADD_ENUM(iBaseType,"edge", iBase_EDGE);
+ ADD_ENUM(iBaseType,"face", iBase_FACE);
+ ADD_ENUM(iBaseType,"region", iBase_REGION);
+ ADD_ENUM(iBaseType,"all", iBase_ALL_TYPES);
/***** initialize adjacency cost enum *****/
- REGISTER_SIMPLE(m,AdjCost);
+ REGISTER_SIMPLE(m,"AdjCost",iBaseAdjCost);
- ADD_ENUM(AdjCost,"unavailable", iBase_UNAVAILABLE);
- ADD_ENUM(AdjCost,"all_order_1", iBase_ALL_ORDER_1);
- ADD_ENUM(AdjCost,"all_order_logn", iBase_ALL_ORDER_LOGN);
- ADD_ENUM(AdjCost,"all_order_n", iBase_ALL_ORDER_N);
- ADD_ENUM(AdjCost,"some_order_1", iBase_SOME_ORDER_1);
- ADD_ENUM(AdjCost,"some_order_logn", iBase_SOME_ORDER_LOGN);
- ADD_ENUM(AdjCost,"some_order_n", iBase_SOME_ORDER_N);
+ ADD_ENUM(iBaseAdjCost,"unavailable", iBase_UNAVAILABLE);
+ ADD_ENUM(iBaseAdjCost,"all_order_1", iBase_ALL_ORDER_1);
+ ADD_ENUM(iBaseAdjCost,"all_order_logn", iBase_ALL_ORDER_LOGN);
+ ADD_ENUM(iBaseAdjCost,"all_order_n", iBase_ALL_ORDER_N);
+ ADD_ENUM(iBaseAdjCost,"some_order_1", iBase_SOME_ORDER_1);
+ ADD_ENUM(iBaseAdjCost,"some_order_logn", iBase_SOME_ORDER_LOGN);
+ ADD_ENUM(iBaseAdjCost,"some_order_n", iBase_SOME_ORDER_N);
/***** initialize storage order enum *****/
- REGISTER_SIMPLE(m,StorageOrder);
+ REGISTER_SIMPLE(m,"StorageOrder",iBaseStorageOrder);
- ADD_ENUM(StorageOrder,"blocked", iBase_BLOCKED);
- ADD_ENUM(StorageOrder,"interleaved", iBase_INTERLEAVED);
+ ADD_ENUM(iBaseStorageOrder,"blocked", iBase_BLOCKED);
+ ADD_ENUM(iBaseStorageOrder,"interleaved", iBase_INTERLEAVED);
/***** initialize creation status enum *****/
- REGISTER_SIMPLE(m,CreationStatus);
+ REGISTER_SIMPLE(m,"CreationStatus",iBaseCreationStatus);
- ADD_ENUM(CreationStatus,"new", iBase_NEW);
- ADD_ENUM(CreationStatus,"exists", iBase_ALREADY_EXISTED);
- ADD_ENUM(CreationStatus,"duplicated", iBase_CREATED_DUPLICATE);
- ADD_ENUM(CreationStatus,"failed", iBase_CREATION_FAILED);
+ ADD_ENUM(iBaseCreationStatus,"new", iBase_NEW);
+ ADD_ENUM(iBaseCreationStatus,"exists", iBase_ALREADY_EXISTED);
+ ADD_ENUM(iBaseCreationStatus,"duplicated", iBase_CREATED_DUPLICATE);
+ ADD_ENUM(iBaseCreationStatus,"failed", iBase_CREATION_FAILED);
/***** initialize iBaseEntity handle *****/
iBaseEntity_Type.tp_repr = (reprfunc)iBaseEntObj_repr;
iBaseEntity_Type.tp_richcompare = (richcmpfunc)iBaseEntObj_richcompare;
- iBaseEntity_Type.tp_new = PyType_GenericNew;
- if(PyType_Ready(&iBaseEntity_Type) < 0)
- return;
- Py_INCREF(&iBaseEntity_Type);
- PyModule_AddObject(m,"iBaseEntity",(PyObject *)&iBaseEntity_Type);
+ REGISTER_SIMPLE(m,"Entity",iBaseEntity);
+
/***** initialize iBaseEntitySet handle *****/
iBaseEntitySet_Type.tp_repr = (reprfunc)iBaseEntSetObj_repr;
iBaseEntitySet_Type.tp_richcompare =
(richcmpfunc)iBaseEntSetObj_richcompare;
- iBaseEntitySet_Type.tp_new = PyType_GenericNew;
- if(PyType_Ready(&iBaseEntitySet_Type) < 0)
- return;
- Py_INCREF(&iBaseEntitySet_Type);
- PyModule_AddObject(m,"iBaseEntitySet",(PyObject *)&iBaseEntitySet_Type);
+ REGISTER_SIMPLE(m,"EntitySet",iBaseEntitySet);
+
/***** initialize iBaseTag handle *****/
- iBaseTag_Type.tp_new = PyType_GenericNew;
- if(PyType_Ready(&iBaseTag_Type) < 0)
- return;
- Py_INCREF(&iBaseTag_Type);
- PyModule_AddObject(m,"iBaseTag",(PyObject *)&iBaseTag_Type);
+ REGISTER_SIMPLE(m,"Tag",iBaseTag);
-
/***** initialize iBaseEntity array type *****/
descr = PyArray_DescrNewFromType(NPY_INTP);
descr->f = &iBaseEntArr_funcs;
Modified: MOAB/trunk/tools/iMesh/python/iMesh.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh.c 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/iMesh.c 2009-06-01 21:21:49 UTC (rev 2923)
@@ -45,7 +45,7 @@
return res;
}
-/* NOTE: steals references to adj and offsets */
+/* NOTE: steals references to ents, adj, indices, and offsets */
PyObject *
IndexedAdjacencyList_New(PyObject *ents, PyObject *adj,PyObject *indices,
PyObject *offsets)
@@ -64,8 +64,26 @@
return res;
}
+iMeshEntitySet_Object *
+iMeshEntitySet_New(iMesh_Object *mesh)
+{
+ iMeshEntitySet_Object *o = iMeshEntitySet_NewRaw();
+ o->mesh = mesh;
+ Py_INCREF(o->mesh);
+ return o;
+}
+
+iMeshTag_Object *
+iMeshTag_New(iMesh_Object *mesh)
+{
+ iMeshTag_Object *o = iMeshTag_NewRaw();
+ o->mesh = mesh;
+ Py_INCREF(o->mesh);
+ return o;
+}
+
static int
-iMeshObj_init(iMeshObject *self,PyObject *args,PyObject *kwds)
+iMeshObj_init(iMesh_Object *self,PyObject *args,PyObject *kwds)
{
static char *kwlist[] = {"options",0};
const char *options = "";
@@ -77,24 +95,22 @@
iMesh_newMesh(options,&self->mesh,&err,strlen(options));
if(checkError(self->mesh,err))
return -1;
-
return 0;
}
static void
-iMeshObj_dealloc(iMeshObject *self)
+iMeshObj_dealloc(iMesh_Object *self)
{
if(self->mesh)
{
int err;
iMesh_dtor(self->mesh,&err);
}
-
self->ob_type->tp_free((PyObject*)self);
}
static PyObject *
-iMeshObj_load(iMeshObject *self,PyObject *args)
+iMeshObj_load(iMesh_Object *self,PyObject *args)
{
const char *name = 0;
const char *options = "";
@@ -116,7 +132,7 @@
}
static PyObject *
-iMeshObj_save(iMeshObject *self,PyObject *args)
+iMeshObj_save(iMesh_Object *self,PyObject *args)
{
const char *name = 0;
const char *options = "";
@@ -138,10 +154,9 @@
}
static PyObject *
-iMeshObj_getRootSet(iMeshObject *self,void *closure)
+iMeshObj_getRootSet(iMesh_Object *self,void *closure)
{
- iMeshEntitySet_Object *rootset = iMeshEntitySet_New();
- rootset->mesh = self; /* TODO: incref? */
+ iMeshEntitySet_Object *rootset = iMeshEntitySet_New(self);
int err;
iMesh_getRootSet(self->mesh,&rootset->set.handle,&err);
@@ -156,7 +171,7 @@
static PyObject *
-iMeshObj_getGeometricDimension(iMeshObject *self,void *closure)
+iMeshObj_getGeometricDimension(iMesh_Object *self,void *closure)
{
int dim,err;
iMesh_getGeometricDimension(self->mesh,&dim,&err);
@@ -167,7 +182,7 @@
}
static int
-iMeshObj_setGeometricDimension(iMeshObject *self,PyObject *value,void *closure)
+iMeshObj_setGeometricDimension(iMesh_Object *self,PyObject *value,void *closure)
{
if(value == NULL)
{
@@ -187,7 +202,7 @@
}
static PyObject *
-iMeshObj_getDfltStorage(iMeshObject *self,void *closure)
+iMeshObj_getDfltStorage(iMesh_Object *self,void *closure)
{
int order,err;
iMesh_getDfltStorage(self->mesh,&order,&err);
@@ -198,7 +213,7 @@
}
static PyObject *
-iMeshObj_getAdjTable(iMeshObject *self,void *closure)
+iMeshObj_getAdjTable(iMesh_Object *self,void *closure)
{
int *adjtable=0;
int alloc=0,size,err;
@@ -212,7 +227,7 @@
}
static PyObject *
-iMeshObj_areEHValid(iMeshObject *self,PyObject *args)
+iMeshObj_areEHValid(iMesh_Object *self,PyObject *args)
{
int doReset,areInv,err;
if(!PyArg_ParseTuple(args,"i",&doReset))
@@ -226,7 +241,7 @@
}
static PyObject *
-iMeshObj_getVtxCoords(iMeshObject *self,PyObject *args)
+iMeshObj_getVtxCoords(iMesh_Object *self,PyObject *args)
{
PyObject *obj;
int storage_order=-1;
@@ -286,7 +301,7 @@
}
static PyObject *
-iMeshObj_getEntTopo(iMeshObject *self,PyObject *args)
+iMeshObj_getEntTopo(iMesh_Object *self,PyObject *args)
{
PyObject *obj;
int err;
@@ -333,7 +348,7 @@
}
static PyObject *
-iMeshObj_getEntType(iMeshObject *self,PyObject *args)
+iMeshObj_getEntType(iMesh_Object *self,PyObject *args)
{
PyObject *obj;
int err;
@@ -379,7 +394,7 @@
}
static PyObject *
-iMeshObj_getEntAdj(iMeshObject *self,PyObject *args)
+iMeshObj_getEntAdj(iMesh_Object *self,PyObject *args)
{
PyObject *obj;
int type_req;
@@ -450,7 +465,7 @@
}
static PyObject *
-iMeshObj_getEnt2ndAdj(iMeshObject *self,PyObject *args)
+iMeshObj_getEnt2ndAdj(iMesh_Object *self,PyObject *args)
{
PyObject *obj;
int bridge_type,type_req;
@@ -521,7 +536,7 @@
}
static PyObject *
-iMeshObj_createEntSet(iMeshObject *self,PyObject *args)
+iMeshObj_createEntSet(iMesh_Object *self,PyObject *args)
{
int isList,err;
PyObject *obj;
@@ -530,9 +545,7 @@
if(!PyArg_ParseTuple(args,"O!",&PyBool_Type,&obj))
return NULL;
- set = iMeshEntitySet_New();
- set->mesh = self;
- /*Py_INCREF(self); TODO?? */
+ set = iMeshEntitySet_New(self);
isList = (obj == Py_True);
@@ -547,7 +560,7 @@
}
static PyObject *
-iMeshObj_destroyEntSet(iMeshObject *self,PyObject *args)
+iMeshObj_destroyEntSet(iMesh_Object *self,PyObject *args)
{
int err;
iBaseEntitySet_Object *set;
@@ -563,7 +576,7 @@
}
static PyObject *
-iMeshObj_setVtxCoords(iMeshObject *self,PyObject *args)
+iMeshObj_setVtxCoords(iMesh_Object *self,PyObject *args)
{
PyObject *obj;
int storage_order = -1;
@@ -633,7 +646,7 @@
}
static PyObject *
-iMeshObj_createVtx(iMeshObject *self,PyObject *args)
+iMeshObj_createVtx(iMesh_Object *self,PyObject *args)
{
int storage_order=-1;
PyObject *data;
@@ -698,7 +711,7 @@
}
static PyObject *
-iMeshObj_createEnt(iMeshObject *self,PyObject *args)
+iMeshObj_createEnt(iMesh_Object *self,PyObject *args)
{
int topo,status,err;
PyObject *obj;
@@ -731,7 +744,7 @@
}
static PyObject *
-iMeshObj_createEntArr(iMeshObject *self,PyObject *args)
+iMeshObj_createEntArr(iMesh_Object *self,PyObject *args)
{
int topo,err;
PyObject *obj;
@@ -773,7 +786,7 @@
static PyObject *
-iMeshObj_deleteEnt(iMeshObject *self,PyObject *args)
+iMeshObj_deleteEnt(iMesh_Object *self,PyObject *args)
{
PyObject *obj;
int err;
@@ -807,7 +820,7 @@
static PyObject *
-iMeshObj_createTag(iMeshObject *self,PyObject *args)
+iMeshObj_createTag(iMesh_Object *self,PyObject *args)
{
char *name;
char typechar;
@@ -824,9 +837,7 @@
return NULL;
}
- tag = iMeshTag_New();
- tag->mesh = self;
- /*Py_INCREF(self); TODO?? */
+ tag = iMeshTag_New(self);
iMesh_createTag(self->mesh,name,size,type,&tag->tag.handle,&err,
strlen(name));
@@ -840,7 +851,7 @@
}
static PyObject *
-iMeshObj_destroyTag(iMeshObject *self,PyObject *args)
+iMeshObj_destroyTag(iMesh_Object *self,PyObject *args)
{
int forced,err;
iBaseTag_Object *tag;
@@ -859,7 +870,7 @@
}
static PyObject *
-iMeshObj_getTagHandle(iMeshObject *self,PyObject *args)
+iMeshObj_getTagHandle(iMesh_Object *self,PyObject *args)
{
char *name;
iMeshTag_Object *tag;
@@ -868,9 +879,7 @@
if(!PyArg_ParseTuple(args,"s",&name))
return NULL;
- tag = iMeshTag_New();
- tag->mesh = self;
- /*Py_INCREF(self); TODO?? */
+ tag = iMeshTag_New(self);
iMesh_getTagHandle(self->mesh,name,&tag->tag.handle,&err,strlen(name));
if(checkError(self->mesh,err))
@@ -883,7 +892,7 @@
}
static PyObject *
-iMeshObj_getAllTags(iMeshObject *self,PyObject *args)
+iMeshObj_getAllTags(iMesh_Object *self,PyObject *args)
{
PyObject *ents;
iBase_TagHandle *tags=0;
@@ -1001,11 +1010,11 @@
{0}
};
-static PyTypeObject iMeshType = {
+static PyTypeObject iMesh_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"itaps.iMesh.Mesh", /* tp_name */
- sizeof(iMeshObject), /* tp_basicsize */
+ sizeof(iMesh_Object), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)iMeshObj_dealloc, /* tp_dealloc */
0, /* tp_print */
@@ -1053,11 +1062,10 @@
iMeshEntSetArr_getitem(void *data,void *arr)
{
ArrDealloc_Object *b = (ArrDealloc_Object*)PyArray_BASE(arr);
- iMeshObject *mesh = (iMeshObject*)b->base;
- iMeshEntitySet_Object *o = iMeshEntitySet_New();
+ iMesh_Object *mesh = (iMesh_Object*)b->base;
+ iMeshEntitySet_Object *o = iMeshEntitySet_New(mesh);
o->set.handle = *(iBase_EntitySetHandle*)data;
- o->mesh = mesh; /* TODO: incref? */
return (PyObject*)o;
}
@@ -1066,11 +1074,10 @@
iMeshTagArr_getitem(void *data,void *arr)
{
ArrDealloc_Object *b = (ArrDealloc_Object*)PyArray_BASE(arr);
- iMeshObject *mesh = (iMeshObject*)b->base;
- iMeshTag_Object *o = iMeshTag_New();
+ iMesh_Object *mesh = (iMesh_Object*)b->base;
+ iMeshTag_Object *o = iMeshTag_New(mesh);
o->tag.handle = *(iBase_TagHandle*)data;
- o->mesh = mesh; /* TODO: incref? */
return (PyObject*)o;
}
@@ -1081,7 +1088,7 @@
static PyArray_ArrFuncs iMeshTagArr_Funcs;
int NPY_IMESHTAG;
-ENUM_TYPE(Topology,"iMesh.Topology","");
+ENUM_TYPE(iMeshTopology,"iMesh.Topology","");
static void
@@ -1158,27 +1165,23 @@
"IndexedAdjacencyList")) == NULL)
return;
- iMeshType.tp_new = PyType_GenericNew;
- if(PyType_Ready(&iMeshType) < 0)
- return;
- Py_INCREF(&iMeshType);
- PyModule_AddObject(m,"Mesh",(PyObject *)&iMeshType);
+ REGISTER_SIMPLE(m,"Mesh",iMesh);
/***** initialize topology enum *****/
- REGISTER_SIMPLE(m,Topology);
+ REGISTER_SIMPLE(m,"Topology",iMeshTopology);
- ADD_ENUM(Topology,"point", iMesh_POINT);
- ADD_ENUM(Topology,"line_segment", iMesh_LINE_SEGMENT);
- ADD_ENUM(Topology,"polygon", iMesh_POLYGON);
- ADD_ENUM(Topology,"triangle", iMesh_TRIANGLE);
- ADD_ENUM(Topology,"quadrilateral", iMesh_QUADRILATERAL);
- ADD_ENUM(Topology,"polyhedron", iMesh_POLYHEDRON);
- ADD_ENUM(Topology,"tetrahedron", iMesh_TETRAHEDRON);
- ADD_ENUM(Topology,"hexahedron", iMesh_HEXAHEDRON);
- ADD_ENUM(Topology,"prism", iMesh_PRISM);
- ADD_ENUM(Topology,"pyramid", iMesh_PYRAMID);
- ADD_ENUM(Topology,"septahedron", iMesh_SEPTAHEDRON);
- ADD_ENUM(Topology,"all", iMesh_ALL_TOPOLOGIES);
+ ADD_ENUM(iMeshTopology,"point", iMesh_POINT);
+ ADD_ENUM(iMeshTopology,"line_segment", iMesh_LINE_SEGMENT);
+ ADD_ENUM(iMeshTopology,"polygon", iMesh_POLYGON);
+ ADD_ENUM(iMeshTopology,"triangle", iMesh_TRIANGLE);
+ ADD_ENUM(iMeshTopology,"quadrilateral", iMesh_QUADRILATERAL);
+ ADD_ENUM(iMeshTopology,"polyhedron", iMesh_POLYHEDRON);
+ ADD_ENUM(iMeshTopology,"tetrahedron", iMesh_TETRAHEDRON);
+ ADD_ENUM(iMeshTopology,"hexahedron", iMesh_HEXAHEDRON);
+ ADD_ENUM(iMeshTopology,"prism", iMesh_PRISM);
+ ADD_ENUM(iMeshTopology,"pyramid", iMesh_PYRAMID);
+ ADD_ENUM(iMeshTopology,"septahedron", iMesh_SEPTAHEDRON);
+ ADD_ENUM(iMeshTopology,"all", iMesh_ALL_TOPOLOGIES);
/***** initialize iterator type *****/
iMeshIter_Type.tp_new = PyType_GenericNew;
Modified: MOAB/trunk/tools/iMesh/python/iMesh_Python.h
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh_Python.h 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/iMesh_Python.h 2009-06-01 21:21:49 UTC (rev 2923)
@@ -50,13 +50,13 @@
{
PyObject_HEAD
iMesh_Instance mesh;
-} iMeshObject;
+} iMesh_Object;
typedef struct
{
PyObject_HEAD
- iMesh_Instance mesh;
+ iMesh_Object *mesh;
int is_arr;
union
{
@@ -70,13 +70,15 @@
typedef struct
{
iBaseEntitySet_Object set;
- iMeshObject *mesh;
+ iMesh_Object *mesh;
} iMeshEntitySet_Object;
extern PyTypeObject iMeshEntitySet_Type;
extern int NPY_IMESHENTSET;
-#define iMeshEntitySet_New() \
+iMeshEntitySet_Object * iMeshEntitySet_New(iMesh_Object *mesh);
+
+#define iMeshEntitySet_NewRaw() \
(iMeshEntitySet_Object*)PyObject_CallObject( \
(PyObject*)&iMeshEntitySet_Type,NULL)
@@ -89,13 +91,15 @@
typedef struct
{
iBaseTag_Object tag;
- iMeshObject *mesh;
+ iMesh_Object *mesh;
} iMeshTag_Object;
extern PyTypeObject iMeshTag_Type;
extern int NPY_IMESHTAG;
-#define iMeshTag_New() \
+iMeshTag_Object * iMeshTag_New(iMesh_Object *mesh);
+
+#define iMeshTag_NewRaw() \
(iMeshTag_Object*)PyObject_CallObject( \
(PyObject*)&iMeshTag_Type,NULL)
Modified: MOAB/trunk/tools/iMesh/python/iMesh_entSet.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh_entSet.c 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/iMesh_entSet.c 2009-06-01 21:21:49 UTC (rev 2923)
@@ -4,7 +4,15 @@
#include "errors.h"
#include "iMesh_Python.h"
#include "iBase_Python.h"
+#include "structmember.h"
+static void
+iMeshEntSetObj_dealloc(iMeshEntitySet_Object *self)
+{
+ Py_XDECREF(self->mesh);
+ ((PyObject*)self)->ob_type->tp_free((PyObject*)self);
+}
+
static PyObject *
iMeshEntSetObj_load(iMeshEntitySet_Object *self,PyObject *args)
{
@@ -456,8 +464,8 @@
if(lhs->mesh->mesh != rhs->mesh->mesh)
return NULL;
- result = iMeshEntitySet_New();
- result->mesh = lhs->mesh; /* TODO: incref? */
+ result = iMeshEntitySet_New(lhs->mesh);
+
iMesh_subtract(lhs->mesh->mesh,lhs->set.handle,rhs->set.handle,
&result->set.handle,&err);
if(checkError(lhs->mesh->mesh,err))
@@ -478,8 +486,8 @@
if(lhs->mesh->mesh != rhs->mesh->mesh)
return NULL;
- result = iMeshEntitySet_New();
- result->mesh = lhs->mesh; /* TODO: incref? */
+ result = iMeshEntitySet_New(lhs->mesh);
+
iMesh_intersect(lhs->mesh->mesh,lhs->set.handle,rhs->set.handle,
&result->set.handle,&err);
if(checkError(lhs->mesh->mesh,err))
@@ -500,8 +508,8 @@
if(lhs->mesh->mesh != rhs->mesh->mesh)
return NULL;
- result = iMeshEntitySet_New();
- result->mesh = lhs->mesh; /* TODO: incref? */
+ result = iMeshEntitySet_New(lhs->mesh);
+
iMesh_unite(lhs->mesh->mesh,lhs->set.handle,rhs->set.handle,
&result->set.handle,&err);
if(checkError(lhs->mesh->mesh,err))
@@ -618,6 +626,12 @@
{0}
};
+static PyMemberDef iMeshEntSetObj_members[] = {
+ {"instance", T_OBJECT_EX, offsetof(iMeshEntitySet_Object, mesh), READONLY,
+ "base iMesh instance"},
+ {0}
+};
+
static PyGetSetDef iMeshEntSetObj_getset[] = {
{ "isList", (getter)iMeshEntSetObj_isList, 0,
"Return whether a specified set is ordered or unordered", 0 },
@@ -653,10 +667,10 @@
PyTypeObject iMeshEntitySet_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
- "itaps.iMesh.entitySet", /* tp_name */
+ "itaps.iMesh.EntitySet", /* tp_name */
sizeof(iMeshEntitySet_Object), /* tp_basicsize */
0, /* tp_itemsize */
- 0, /* tp_dealloc */
+ (destructor)iMeshEntSetObj_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
@@ -681,7 +695,7 @@
0, /* tp_iter */
0, /* tp_iternext */
iMeshEntSetObj_methods, /* tp_methods */
- 0, /* tp_members */
+ iMeshEntSetObj_members, /* tp_members */
iMeshEntSetObj_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
Modified: MOAB/trunk/tools/iMesh/python/iMesh_iter.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh_iter.c 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/iMesh_iter.c 2009-06-01 21:21:49 UTC (rev 2923)
@@ -3,6 +3,7 @@
#include "iMesh_Python.h"
#include "iBase_Python.h"
+#include "structmember.h"
static int
iMeshIterObj_init(iMeshIter_Object *self,PyObject *args,PyObject *kwds)
@@ -16,20 +17,22 @@
&array_size) )
return -1;
- self->mesh = set->mesh->mesh;
+ self->mesh = set->mesh;
+ Py_INCREF(self->mesh);
+
if(array_size == 1)
{
self->is_arr = 0;
- iMesh_initEntIter(self->mesh,set->set.handle,type,topo,&self->iter,
- &err);
+ iMesh_initEntIter(self->mesh->mesh,set->set.handle,type,topo,
+ &self->iter,&err);
}
else
{
self->is_arr = 1;
- iMesh_initEntArrIter(self->mesh,set->set.handle,type,topo,array_size,
- &self->arr_iter,&err);
+ iMesh_initEntArrIter(self->mesh->mesh,set->set.handle,type,topo,
+ array_size,&self->arr_iter,&err);
}
- if(checkError(self->mesh,err))
+ if(checkError(self->mesh->mesh,err))
return -1;
return 0;
@@ -42,11 +45,12 @@
{
int err;
if(self->is_arr)
- iMesh_endEntArrIter(self->mesh,self->arr_iter,&err);
+ iMesh_endEntArrIter(self->mesh->mesh,self->arr_iter,&err);
else
- iMesh_endEntIter(self->mesh,self->iter,&err);
+ iMesh_endEntIter(self->mesh->mesh,self->iter,&err);
}
+ Py_XDECREF(self->mesh);
self->ob_type->tp_free((PyObject*)self);
}
@@ -55,22 +59,15 @@
{
int err;
if(self->is_arr)
- iMesh_resetEntArrIter(self->mesh,self->arr_iter,&err);
+ iMesh_resetEntArrIter(self->mesh->mesh,self->arr_iter,&err);
else
- iMesh_resetEntIter(self->mesh,self->iter,&err);
+ iMesh_resetEntIter(self->mesh->mesh,self->iter,&err);
- if(checkError(self->mesh,err))
+ if(checkError(self->mesh->mesh,err))
return NULL;
Py_RETURN_NONE;
}
-static PyMethodDef iMeshIter_methods[] = {
- { "reset", (PyCFunction)iMeshIterObj_reset, METH_NOARGS,
- "Reset the iterator"
- },
- {0}
-};
-
static PyObject *
iMeshIterObj_iternext(iMeshIter_Object *self)
{
@@ -81,9 +78,9 @@
iBase_EntityHandle *entities=0;
int alloc=0,size;
- iMesh_getNextEntArrIter(self->mesh,self->arr_iter,&entities,&alloc,
- &size,&has_data,&err);
- if(checkError(self->mesh,err))
+ iMesh_getNextEntArrIter(self->mesh->mesh,self->arr_iter,&entities,
+ &alloc,&size,&has_data,&err);
+ if(checkError(self->mesh->mesh,err))
return NULL;
if(!has_data)
return NULL;
@@ -94,8 +91,9 @@
else
{
iBase_EntityHandle entity;
- iMesh_getNextEntIter(self->mesh,self->iter,&entity,&has_data,&err);
- if(checkError(self->mesh,err))
+ iMesh_getNextEntIter(self->mesh->mesh,self->iter,&entity,&has_data,
+ &err);
+ if(checkError(self->mesh->mesh,err))
return NULL;
if(!has_data)
return NULL;
@@ -106,10 +104,23 @@
}
}
+static PyMethodDef iMeshIterObj_methods[] = {
+ { "reset", (PyCFunction)iMeshIterObj_reset, METH_NOARGS,
+ "Reset the iterator"
+ },
+ {0}
+};
+
+static PyMemberDef iMeshIterObj_members[] = {
+ {"instance", T_OBJECT_EX, offsetof(iMeshIter_Object, mesh), READONLY,
+ "base iMesh instance"},
+ {0}
+};
+
PyTypeObject iMeshIter_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
- "itaps.iMesh.iterator", /* tp_name */
+ "itaps.iMesh.Iterator", /* tp_name */
sizeof(iMeshIter_Object), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)iMeshIterObj_dealloc, /* tp_dealloc */
@@ -137,8 +148,8 @@
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)iMeshIterObj_iternext, /* tp_iternext */
- iMeshIter_methods, /* tp_methods */
- 0, /* tp_members */
+ iMeshIterObj_methods, /* tp_methods */
+ iMeshIterObj_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
Modified: MOAB/trunk/tools/iMesh/python/iMesh_tag.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh_tag.c 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/iMesh_tag.c 2009-06-01 21:21:49 UTC (rev 2923)
@@ -4,6 +4,7 @@
#include "iMesh_Python.h"
#include "iBase_Python.h"
#include "errors.h"
+#include "structmember.h"
static char typechars[] = {'i','d','E','b'};
@@ -26,6 +27,13 @@
}
+static void
+iMeshTagObj_dealloc(iMeshTag_Object *self)
+{
+ Py_XDECREF(self->mesh);
+ ((PyObject*)self)->ob_type->tp_free((PyObject*)self);
+}
+
static PyObject *
iMeshTagObj_getName(iMeshTag_Object *self,void *closure)
{
@@ -501,6 +509,12 @@
{0}
};
+static PyMemberDef iMeshTagObj_members[] = {
+ {"instance", T_OBJECT_EX, offsetof(iMeshTag_Object, mesh), READONLY,
+ "base iMesh instance"},
+ {0}
+};
+
static PyGetSetDef iMeshTagObj_getset[] = {
{ "name", (getter)iMeshTagObj_getName, 0,
"Get the name for a given tag handle", 0
@@ -521,10 +535,10 @@
PyTypeObject iMeshTag_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
- "itaps.iMesh.tag", /* tp_name */
+ "itaps.iMesh.Tag", /* tp_name */
sizeof(iMeshTag_Object), /* tp_basicsize */
0, /* tp_itemsize */
- 0, /* tp_dealloc */
+ (destructor)iMeshTagObj_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
@@ -549,7 +563,7 @@
0, /* tp_iter */
0, /* tp_iternext */
iMeshTagObj_methods, /* tp_methods */
- 0, /* tp_members */
+ iMeshTagObj_members, /* tp_members */
iMeshTagObj_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
Modified: MOAB/trunk/tools/iMesh/python/test/entset.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/entset.py 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/test/entset.py 2009-06-01 21:21:49 UTC (rev 2923)
@@ -10,6 +10,7 @@
self.mesh = None
def testCreation(self):
+ self.assertEqual(self.set.instance, self.mesh)
self.assertEqual(self.set.isList, True)
self.assertEqual(self.set.getNumEntSets(1), 0)
self.assertEqual(self.mesh.rootSet.getNumEntSets(0), 1)
Modified: MOAB/trunk/tools/iMesh/python/test/iter.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/iter.py 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/test/iter.py 2009-06-01 21:21:49 UTC (rev 2923)
@@ -35,6 +35,9 @@
def testAlternate(self):
count = 0
iter = iMesh.Iterator(self.set, iBase.Type.all, iMesh.Topology.all)
+
+ self.assertEqual(iter.instance, self.mesh)
+
for i in iter:
count += 1
self.assertEqual(i, self.ent)
Modified: MOAB/trunk/tools/iMesh/python/test/tags.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/tags.py 2009-06-01 19:31:52 UTC (rev 2922)
+++ MOAB/trunk/tools/iMesh/python/test/tags.py 2009-06-01 21:21:49 UTC (rev 2923)
@@ -17,11 +17,28 @@
self.set = self.mesh.createEntSet(True)
def testCreation(self):
+ self.assertEqual(self.itag.instance, self.mesh)
self.assertEqual(self.itag.name, 'int')
self.assertEqual(self.itag.type, 'i')
self.assertEqual(self.itag.sizeValues, 1)
- self.assertEqual(self.itag.sizeBytes, 4)
+ self.assertEqual(self.dtag.instance, self.mesh)
+ self.assertEqual(self.dtag.name, 'double')
+ self.assertEqual(self.dtag.type, 'd')
+ self.assertEqual(self.dtag.sizeValues, 1)
+ self.assertEqual(self.dtag.sizeBytes, 8)
+
+ self.assertEqual(self.etag.instance, self.mesh)
+ self.assertEqual(self.etag.name, 'handle')
+ self.assertEqual(self.etag.type, 'E')
+ self.assertEqual(self.etag.sizeValues, 1)
+
+ self.assertEqual(self.btag.instance, self.mesh)
+ self.assertEqual(self.btag.name, 'bytes')
+ self.assertEqual(self.btag.type, 'b')
+ self.assertEqual(self.btag.sizeValues, 3)
+ self.assertEqual(self.btag.sizeBytes, 3)
+
def testFind(self):
t = self.mesh.getTagHandle('int')
self.assertEqual(t.name, self.itag.name)
More information about the moab-dev
mailing list