[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11097] branches/pyapi_devel/source/ blender/python/api2_2x: added face edge and mesh flags back as indervidual bool attributes.

Campbell Barton cbarton at metavr.com
Thu Jun 28 12:49:17 CEST 2007


Revision: 11097
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11097
Author:   campbellbarton
Date:     2007-06-28 12:49:17 +0200 (Thu, 28 Jun 2007)

Log Message:
-----------
added face edge and mesh flags back as indervidual bool attributes. (still need to agree on naming convention)
Made it so vertex colors cant reference invalid memory locations. (if you get the face color then remove the VCol data, the Python color reports that its been removed)

Modified Paths:
--------------
    branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
    branches/pyapi_devel/source/blender/python/api2_2x/Mesh.h

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c	2007-06-28 09:10:36 UTC (rev 11096)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c	2007-06-28 10:49:17 UTC (rev 11097)
@@ -126,6 +126,8 @@
 static PyObject *MFace_CreatePyObject( BPy_Mesh * bpymesh, int i );
 static PyObject *MEdge_CreatePyObject( BPy_Mesh * bpymesh, int i );
 
+static MFace * MFace_get_pointer( BPy_MFace * self );
+
 /* These checks are only needed if we allow users to remove meshes */
 // #define MESH_DEL_CHECK_PY(_mesh) if (!(_mesh)) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "This mesh has been removed" ) )
 // #define MESH_DEL_CHECK_INT(_mesh) if (!(_mesh)) return ( EXPP_ReturnIntError( PyExc_RuntimeError, "This mesh has been removed" ) )
@@ -587,6 +589,25 @@
  *
  ************************************************************************/
 
+static MCol *MCol_get_pointer(BPy_MCol * self)
+{
+	MFace *face = MFace_get_pointer(self->bpyface);
+	
+	if (!face)
+		return NULL; /* error set */
+	
+	if (!self->bpyface->bpymesh->mesh->mcol)
+		return (MCol *)EXPP_ReturnPyObjError(
+				PyExc_RuntimeError, "the face this MCol used has been removed." );
+	
+	if (self->face_index==4 && face->v4==0)
+		return (MCol *)EXPP_ReturnPyObjError(
+				PyExc_RuntimeError, "the face this MCol used has been replaced with a triangle." );
+	
+	return &self->bpyface->bpymesh->mesh->mcol[(self->bpyface->index*4) + self->face_index];
+}
+
+
 /*
  * get a color attribute
  */
@@ -594,23 +615,25 @@
 static PyObject *MCol_getAttr( BPy_MCol * self, void *type )
 {
 	unsigned char param;
+	MCol * color = MCol_get_pointer(self);
 	
+	if (!color)
+		return NULL; /* error set */
+	
 	// MESH_DEL_CHECK_PY(self->bpymesh->mesh);
 	
-	/* TODO - Check the face was still there */
-	
 	switch( (long)type ) {
     case 'R':	/* these are backwards, but that how it works */
-		param = self->color->b;
+		param = color->b;
 		break;
     case 'G':
-		param = self->color->g;
+		param = color->g;
 		break;
     case 'B':	/* these are backwards, but that how it works */
-		param = self->color->r;
+		param = color->r;
 		break;
     case 'A':
-		param = self->color->a;
+		param = color->a;
 		break;
 	default:
 		{
@@ -631,21 +654,25 @@
 static int MCol_setAttr( BPy_MCol * self, PyObject * value, void * type )
 {
 	unsigned char *param;
+	MCol * color = MCol_get_pointer(self);
 	
+	if (!color)
+		return -1; /* error set */
+	
 	// MESH_DEL_CHECK_INT(self->bpymesh->mesh);
 	
 	switch( (long)type ) {
     case 'R':	/* these are backwards, but that how it works */
-		param = (unsigned char *)&self->color->b;
+		param = (unsigned char *)&color->b;
 		break;
     case 'G':
-		param = (unsigned char *)&self->color->g;
+		param = (unsigned char *)&color->g;
 		break;
     case 'B':	/* these are backwards, but that how it works */
-		param = (unsigned char *)&self->color->r;
+		param = (unsigned char *)&color->r;
 		break;
     case 'A':
-		param = (unsigned char *)&self->color->a;
+		param = (unsigned char *)&color->a;
 		break;
 	default:
 		{
@@ -685,9 +712,9 @@
 	{NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 };
 
-static void MCol_dealloc( BPy_MVertSeq * self )
+static void MCol_dealloc( BPy_MCol * self )
 {
-	Py_DECREF(self->bpymesh);
+	Py_DECREF( (PyObject *)self->bpyface );
 	PyObject_DEL( self );
 }
 
@@ -696,21 +723,24 @@
 static PyObject *MCol_item(BPy_MCol * self, int i)
 {
 	unsigned char param;
+	MCol * color = MCol_get_pointer(self);
 	
+	if (!color)
+		return NULL; /* error set */
 	// MESH_DEL_CHECK_PY(self->bpymesh->mesh);
 	
 	switch (i) {
 	case 0:
-		param = self->color->b;
+		param = color->b;
 		break;
 	case 1:
-		param = self->color->g;
+		param = color->g;
 		break;
 	case 2:
-		param = self->color->r;
+		param = color->r;
 		break;
 	case 3:
-		param = self->color->a;
+		param = color->a;
 		break;	
 	default:
 		return EXPP_ReturnPyObjError(PyExc_IndexError,
@@ -725,21 +755,25 @@
 static int MCol_ass_item(BPy_MCol * self, int i, PyObject * value)
 {
 	unsigned char *param;
+	MCol * color = MCol_get_pointer(self);
 	
+	if (!color)
+		return -1; /* error set */
+	
 	// MESH_DEL_CHECK_INT(self->bpymesh->mesh);
 	
 	switch (i) {
 	case 0:
-		param = (unsigned char *)&self->color->b; /* reversed? why */
+		param = (unsigned char *)&color->b; /* reversed? why */
 		break;
 	case 1:
-		param = (unsigned char *)&self->color->g;
+		param = (unsigned char *)&color->g;
 		break;
 	case 2:
-		param = (unsigned char *)&self->color->r; /* reversed? why */
+		param = (unsigned char *)&color->r; /* reversed? why */
 		break;
 	case 3:
-		param = (unsigned char *)&self->color->a;
+		param = (unsigned char *)&color->a;
 		break;	
 	default:
 		{
@@ -757,13 +791,15 @@
 
 static PyObject *MCol_repr( BPy_MCol * self )
 {
-	if (self->bpymesh->mesh) {
+	MCol * color = MCol_get_pointer(self);
+	
+	if (!color) {
+		PyErr_Clear();
+		return PyString_FromString("[MCol <deleted>]"); 
+	}
 	return PyString_FromFormat( "[MCol %d %d %d %d]",
-			(int)self->color->b, (int)self->color->g, 
-			(int)self->color->r, (int)self->color->a );
-	} else {
-		return PyString_FromString( "[MCol <deleted>]" );
-	}
+			(int)color->b, (int)color->g, 
+			(int)color->r, (int)color->a );
 }
 
 /*-----------------PROTCOL DECLARATIONS--------------------------*/
@@ -865,7 +901,7 @@
 	NULL
 };
 
-static PyObject *MCol_CreatePyObject( BPy_Mesh * bpymesh, MCol * color )
+static PyObject *MCol_CreatePyObject( BPy_MFace * bpyface, char face_index )
 {
 	BPy_MCol *obj = PyObject_NEW( BPy_MCol, &MCol_Type );
 
@@ -873,9 +909,9 @@
 		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 				"PyObject_New() failed" );
 
-	obj->color = color;
-	obj->bpymesh = bpymesh;
-	Py_INCREF(bpymesh);
+	obj->face_index = face_index;
+	obj->bpyface = bpyface;
+	Py_INCREF(bpyface);
 	return (PyObject *)obj;
 }
 
@@ -1593,7 +1629,7 @@
 
 static int PVert_compare( BPy_MVert * a, BPy_MVert * b )
 {
-	return( a->bpymesh == b->bpymesh ) ? 0 : -1; /* TODO - add PVert support back */
+	return( a->bpymesh == b->bpymesh ) ? 0 : -1;
 }
 
 /************************************************************************
@@ -2069,8 +2105,6 @@
 		memcpy( tmpvert->co, co, sizeof(co) );
 		
 		tmpvert->flag |= SELECT;
-	/* TODO: anything else which needs to be done when we add a vert? */
-	/* probably not: NMesh's newvert() doesn't */
 		++tmpvert;
 	}
 
@@ -2420,6 +2454,26 @@
 	return &self->bpymesh->mesh->medge[self->index]; 
 }
 
+static PyObject *MEdge_getFlag(BPy_MEdge *self, void *flag)
+{
+	MEdge *edge = MEdge_get_pointer( self );
+	if (edge->flag & (int)flag)
+		Py_RETURN_TRUE;
+	else
+		Py_RETURN_FALSE;
+		
+}
+
+static int MEdge_setFlag(BPy_MEdge *self, PyObject *value, void *flag)
+{
+	MEdge *edge = MEdge_get_pointer( self );
+	if ( PyObject_IsTrue(value) )
+		edge->flag |= (long)flag;
+	else
+		edge->flag &= ~(long)flag;
+	return 0;
+}
+
 /*
  * get an edge's crease value
  */
@@ -2670,6 +2724,32 @@
 	 (getter)MEdge_getKey, (setter)NULL,
      "edge's key for using with sets or dictionaries, read only",
      NULL},
+     
+     /* flags */
+	{"enableDraw",
+	 (getter)MEdge_getFlag, (setter)MEdge_setFlag,
+     "draw the edge in wireframe display",
+     (void *)ME_EDGEDRAW},
+	{"enableRender",
+	 (getter)MEdge_getFlag, (setter)MEdge_setFlag,
+     "render the edge",
+     (void *)ME_EDGERENDER},
+	{"enableSeam",
+	 (getter)MEdge_getFlag, (setter)MEdge_setFlag,
+     "make this edge a UV seam",
+     (void *)ME_SEAM},
+	{"enableFgon",
+	 (getter)MEdge_getFlag, (setter)MEdge_setFlag,
+     "this edge is apart of an fgon",
+     (void *)ME_FGON},
+	{"enableLoose",
+	 (getter)MEdge_getFlag, (setter)NULL,
+     "this edge has no faces using it (set when existing edit mode)",
+     (void *)ME_LOOSEEDGE},
+	{"enableSharp",
+	 (getter)MEdge_getFlag, (setter)MEdge_setFlag,
+     "this edge is sharp when using the edge split modifier",
+     (void *)ME_SHARP},
 	{NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 };
 
@@ -3799,6 +3879,39 @@
 }
 
 /*
+ * get a face's flags
+ */
+
+static PyObject *MFace_getMode(BPy_MFace *self, void *mode)
+{
+	if( !self->bpymesh->mesh->mtface )
+		return EXPP_ReturnPyObjError( PyExc_ValueError,
+				"face has no texture values" );
+	
+	if( !MFace_get_pointer( self ) )
+		return NULL; /* error set */
+	
+	if (self->bpymesh->mesh->mtface[self->index].mode & (long)mode)
+		Py_RETURN_TRUE;
+	else
+		Py_RETURN_FALSE;
+		
+}
+
+static int MFace_setMode(BPy_MFace *self, PyObject *value, void *mode)
+{	
+	if( !self->bpymesh->mesh->mtface )
+		return EXPP_ReturnIntError( PyExc_ValueError,
+				"face has no texture values" );
+	
+	if ( PyObject_IsTrue(value) )
+		self->bpymesh->mesh->mtface[self->index].mode |= (long)mode;
+	else
+		self->bpymesh->mesh->mtface[self->index].mode &= ~(long)mode;
+	return 0;
+}
+
+/*
  * get a face's vertices
  */
 
@@ -3843,8 +3956,25 @@
 		return EXPP_ReturnIntError( PyExc_TypeError,
 			"expected tuple of 3 or 4 MVerts" );
 	
-	/* TODO - check the vert range and that they are from this mesh? */
+	if(	v1->index == v2->index || 
+		v1->index == v3->index || 
+		v2->index == v3->index  ) 
+		return EXPP_ReturnIntError( PyExc_ValueError,
+			"cannot assign 2 or move verts that are the same" );
 	
+	if(v4 && (	v1->index == v4->index ||
+				v2->index == v4->index ||
+				v3->index == v4->index ))
+		return EXPP_ReturnIntError( PyExc_ValueError,
+			"cannot assign 2 or move verts that are the same" );
+	
+	if(		v1->index >= self->bpymesh->mesh->totvert || 
+			v2->index >= self->bpymesh->mesh->totvert || 
+			v3->index >= self->bpymesh->mesh->totvert ||
+	(v4 &&(	v4->index >= self->bpymesh->mesh->totvert)))
+		return EXPP_ReturnIntError( PyExc_ValueError,
+			"cannot assign verts that have been removed" );
+	
 	face->v1 = v1->index;
 	face->v2 = v2->index;
 	face->v3 = v3->index;
@@ -4305,7 +4435,7 @@
 static PyObject *MFace_getCol( BPy_MFace * self )
 {
 	PyObject *attr;
-	int length, i;
+	char length, i;
 	MCol * mcol;
 
 	if( self->index >= self->bpymesh->mesh->totface )
@@ -4328,10 +4458,12 @@
 				"PyTuple_New() failed" );
 
 	for( i=0; i<length; ++i ) {
-		PyObject *color = MCol_CreatePyObject( self->bpymesh, &mcol[i] );
-		if( !color )
+		PyObject *color = MCol_CreatePyObject( self, i );
+		if( !color ) {
+			Py_DECREF(attr);
 			return NULL;
-		PyTuple_SetItem( attr, i, color );
+		}
+		PyTuple_SET_ITEM( attr, i, color );
 	}
 
 	return attr;
@@ -4374,11 +4506,19 @@
 
 	for( i=0; i<length; ++i ) {
 		BPy_MCol *obj = (BPy_MCol *)PySequence_ITEM( value, i );

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list