[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54129] branches/soc-2008-mxcurioni: Freestyle Python API improvements.

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Sun Jan 27 22:51:28 CET 2013


Revision: 54129
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54129
Author:   kjym3
Date:     2013-01-27 21:51:25 +0000 (Sun, 27 Jan 2013)
Log Message:
-----------
Freestyle Python API improvements.

StrokeAttribute class methods were renamed from camel case to lower case plus underscore.
Also made changes to shaders.pyTVertexOrientationShader that uses the affected methods.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/shaders.py
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp

Modified: branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/shaders.py
===================================================================
--- branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/shaders.py	2013-01-27 20:26:18 UTC (rev 54128)
+++ branches/soc-2008-mxcurioni/release/scripts/freestyle/style_modules/shaders.py	2013-01-27 21:51:25 UTC (rev 54129)
@@ -821,47 +821,56 @@
 	## the previous or next edge
 	def findOrientation(self, tv, ve):
 		mateVE = tv.mate(ve)
-		if((ve.qi() != 0) or (mateVE.qi() != 0)):
+		if ve.qi() != 0 or mateVE.qi() != 0:
 			ait = AdjacencyIterator(tv,1,0)
 			winner = None
-			incoming = 1
-			while(ait.isEnd() == 0):
+			incoming = True
+			while not ait.isEnd():
 				ave = ait.getObject()
-				if((ave.getId() != ve.getId()) and (ave.getId() != mateVE.getId())):
+				if  ave.getId() != ve.getId() and ave.getId() != mateVE.getId():
 					winner = ait.getObject()
-					if(ait.isIncoming() == 0):
-						incoming = 0
+					if not ait.isIncoming():
+						incoming = False
 						break
 				ait.increment()
-			if(winner != None):
-				if(incoming != 0):
+			if winner is not None:
+				if not incoming:
 					direction = self._Get2dDirection(winner.fedgeB())
 				else:
 					direction = self._Get2dDirection(winner.fedgeA())
 				return direction
+		return None
+	def castToTVertex(self, cp):
+		if cp.t2d() == 0.0:
+			return cp.A().viewvertex()
+		elif cp.t2d() == 1.0:
+			return cp.B().viewvertex()
+		return None
 	def shade(self, stroke):
 		it = stroke.strokeVerticesBegin()
 		it2 = StrokeVertexIterator(it)
 		it2.increment()
 		## case where the first vertex is a TVertex
-		v = it.getObject() 
+		v = it.getObject()
 		if(v.getNature() & Nature.T_VERTEX):
-			tv = v.castToTVertex()
-			ve = getFEdge(v, it2.getObject()).viewedge()
-			if(tv != None):			
+			tv = self.castToTVertex(v)
+			if tv is not None:
+				ve = getFEdge(v, it2.getObject()).viewedge()
 				dir = self.findOrientation(tv, ve)
-				#print(dir.x, dir.y)
-				v.attribute.setAttributeVec2f("orientation", dir)
+				if dir is not None:
+					#print(dir.x, dir.y)
+					v.attribute.set_attribute_vec2("orientation", dir)
 		while(it2.isEnd() == 0):
 			vprevious = it.getObject()
 			v = it2.getObject()
 			if(v.getNature() & Nature.T_VERTEX):
-				tv = v.castToTVertex()
-				ve = getFEdge(vprevious, v).viewedge()
-				if(tv != None):	
+				tv = self.castToTVertex(v)
+				if tv is not None:
+					ve = getFEdge(vprevious, v).viewedge()
 					dir = self.findOrientation(tv, ve)
-					#print(dir.x, dir.y)
-					v.attribute.setAttributeVec2f("orientation", dir)			
+					if dir is not None:
+						#print(dir.x, dir.y)
+						v.attribute.set_attribute_vec2("orientation", dir)
 			it.increment()
 			it2.increment()
 		## case where the last vertex is a TVertex
@@ -869,12 +878,13 @@
 		if(v.getNature() & Nature.T_VERTEX):
 			itPrevious = StrokeVertexIterator(it)
 			itPrevious.decrement()
-			tv = v.castToTVertex()
-			ve = getFEdge(itPrevious.getObject(), v).viewedge()
-			if(tv != None):			
+			tv = self.castToTVertex(v)
+			if tv is not None:
+				ve = getFEdge(itPrevious.getObject(), v).viewedge()
 				dir = self.findOrientation(tv, ve)
-				#print(dir.x, dir.y)
-				v.attribute.setAttributeVec2f("orientation", dir)
+				if dir is not None:
+					#print(dir.x, dir.y)
+					v.attribute.set_attribute_vec2("orientation", dir)
 
 class pySinusDisplacementShader(StrokeShader):
 	def __init__(self, f, a):

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp	2013-01-27 20:26:18 UTC (rev 54128)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp	2013-01-27 21:51:25 UTC (rev 54129)
@@ -25,7 +25,7 @@
 
 //------------------------INSTANCE METHODS ----------------------------------
 
-static char StrokeAttribute___doc__[] =
+PyDoc_STRVAR(StrokeAttribute_doc,
 "Class to define a set of attributes associated with a :class:`StrokeVertex`.\n"
 "The attribute set stores the color, alpha and thickness values for a Stroke\n"
 "Vertex.\n"
@@ -68,7 +68,7 @@
 "   :arg a2: The second StrokeAttribute object.\n"
 "   :type a2: :class:`StrokeAttribute`\n"
 "   :arg t: The interpolation parameter.\n"
-"   :type t: float\n";
+"   :type t: float\n");
 
 static int StrokeAttribute___init__(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds)
 {
@@ -134,17 +134,17 @@
 	return PyUnicode_FromString( repr.str().c_str() );
 }
 
-static char StrokeAttribute_getAttributeReal___doc__[] =
-".. method:: getAttributeReal(iName)\n"
+PyDoc_STRVAR(StrokeAttribute_get_attribute_real_doc,
+".. method:: get_attribute_real(iName)\n"
 "\n"
 "   Returns an attribute of float type.\n"
 "\n"
 "   :arg iName: The name of the attribute.\n"
 "   :type iName: str\n"
 "   :return: The attribute value.\n"
-"   :rtype: float\n";
+"   :rtype: float\n");
 
-static PyObject *StrokeAttribute_getAttributeReal( BPy_StrokeAttribute *self, PyObject *args ) {
+static PyObject *StrokeAttribute_get_attribute_real( BPy_StrokeAttribute *self, PyObject *args ) {
 	char *attr;
 
 	if(!( PyArg_ParseTuple(args, "s", &attr) ))
@@ -154,17 +154,17 @@
 	return PyFloat_FromDouble( a );
 }
 
-static char StrokeAttribute_getAttributeVec2f___doc__[] =
-".. method:: getAttributeVec2f(iName)\n"
+PyDoc_STRVAR(StrokeAttribute_get_attribute_vec2_doc,
+".. method:: get_attribute_vec2(iName)\n"
 "\n"
 "   Returns an attribute of two-dimensional vector type.\n"
 "\n"
 "   :arg iName: The name of the attribute.\n"
 "   :type iName: str\n"
 "   :return: The attribute value.\n"
-"   :rtype: :class:`mathutils.Vector`\n";
+"   :rtype: :class:`mathutils.Vector`\n");
 
-static PyObject *StrokeAttribute_getAttributeVec2f( BPy_StrokeAttribute *self, PyObject *args ) {
+static PyObject *StrokeAttribute_get_attribute_vec2( BPy_StrokeAttribute *self, PyObject *args ) {
 	char *attr;
 
 	if(!( PyArg_ParseTuple(args, "s", &attr) ))
@@ -174,17 +174,17 @@
 	return Vector_from_Vec2f( a );
 }
 
-static char StrokeAttribute_getAttributeVec3f___doc__[] =
-".. method:: getAttributeVec3f(iName)\n"
+PyDoc_STRVAR(StrokeAttribute_get_attribute_vec3_doc,
+".. method:: get_attribute_vec3(iName)\n"
 "\n"
 "   Returns an attribute of three-dimensional vector type.\n"
 "\n"
 "   :arg iName: The name of the attribute.\n"
 "   :type iName: str\n"
 "   :return: The attribute value.\n"
-"   :rtype: :class:`mathutils.Vector`\n";
+"   :rtype: :class:`mathutils.Vector`\n");
 
-static PyObject *StrokeAttribute_getAttributeVec3f( BPy_StrokeAttribute *self, PyObject *args ) {
+static PyObject *StrokeAttribute_get_attribute_vec3( BPy_StrokeAttribute *self, PyObject *args ) {
 	char *attr;
 
 	if(!( PyArg_ParseTuple(args, "s", &attr) ))
@@ -194,17 +194,17 @@
 	return Vector_from_Vec3f( a );
 }
 
-static char StrokeAttribute_isAttributeAvailableReal___doc__[] =
-".. method:: isAttributeAvailableReal(iName)\n"
+PyDoc_STRVAR(StrokeAttribute_has_attribute_real_doc,
+".. method:: has_attribute_real(iName)\n"
 "\n"
 "   Checks whether the attribute iName of float type is available.\n"
 "\n"
 "   :arg iName: The name of the attribute.\n"
 "   :type iName: str\n"
 "   :return: True if the attribute is availbale.\n"
-"   :rtype: bool\n";
+"   :rtype: bool\n");
 
-static PyObject *StrokeAttribute_isAttributeAvailableReal( BPy_StrokeAttribute *self, PyObject *args ) {
+static PyObject *StrokeAttribute_has_attribute_real( BPy_StrokeAttribute *self, PyObject *args ) {
 	char *attr;
 
 	if(!( PyArg_ParseTuple(args, "s", &attr) ))
@@ -213,8 +213,8 @@
 	return PyBool_from_bool( self->sa->isAttributeAvailableReal( attr ) );
 }
 
-static char StrokeAttribute_isAttributeAvailableVec2f___doc__[] =
-".. method:: isAttributeAvailableVec2f(iName)\n"
+PyDoc_STRVAR(StrokeAttribute_has_attribute_vec2_doc,
+".. method:: has_attribute_vec2(iName)\n"
 "\n"
 "   Checks whether the attribute iName of two-dimensional vector type\n"
 "   is available.\n"
@@ -222,9 +222,9 @@
 "   :arg iName: The name of the attribute.\n"
 "   :type iName: str\n"
 "   :return: True if the attribute is availbale.\n"
-"   :rtype: bool\n";
+"   :rtype: bool\n");
 
-static PyObject *StrokeAttribute_isAttributeAvailableVec2f( BPy_StrokeAttribute *self, PyObject *args ) {
+static PyObject *StrokeAttribute_has_attribute_vec2( BPy_StrokeAttribute *self, PyObject *args ) {
 	char *attr;
 
 	if(!( PyArg_ParseTuple(args, "s", &attr) ))
@@ -233,8 +233,8 @@
 	return PyBool_from_bool( self->sa->isAttributeAvailableVec2f( attr ) );
 }
 
-static char StrokeAttribute_isAttributeAvailableVec3f___doc__[] =
-".. method:: isAttributeAvailableVec3f(iName)\n"
+PyDoc_STRVAR(StrokeAttribute_has_attribute_vec3_doc,
+".. method:: has_attribute_vec3(iName)\n"
 "\n"
 "   Checks whether the attribute iName of three-dimensional vector\n"
 "   type is available.\n"
@@ -242,9 +242,9 @@
 "   :arg iName: The name of the attribute.\n"
 "   :type iName: str\n"
 "   :return: True if the attribute is availbale.\n"
-"   :rtype: bool\n";
+"   :rtype: bool\n");
 
-static PyObject *StrokeAttribute_isAttributeAvailableVec3f( BPy_StrokeAttribute *self, PyObject *args ) {
+static PyObject *StrokeAttribute_has_attribute_vec3( BPy_StrokeAttribute *self, PyObject *args ) {
 	char *attr;
 
 	if(!( PyArg_ParseTuple(args, "s", &attr) ))
@@ -253,8 +253,8 @@
 	return PyBool_from_bool( self->sa->isAttributeAvailableVec3f( attr ) );
 }
 
-static char StrokeAttribute_setAttributeReal___doc__[] =
-".. method:: setAttributeReal(iName, att)\n"
+PyDoc_STRVAR(StrokeAttribute_set_attribute_real_doc,
+".. method:: set_attribute_real(iName, att)\n"
 "\n"
 "   Adds a user-defined attribute of float type.  If there is no\n"
 "   attribute of the given name, it is added.  Otherwise, the new value\n"
@@ -263,9 +263,9 @@
 "   :arg iName: The name of the attribute.\n"
 "   :type iName: str\n"
 "   :arg att: The attribute value.\n"
-"   :type att: float\n";
+"   :type att: float\n");
 
-static PyObject * StrokeAttribute_setAttributeReal( BPy_StrokeAttribute *self, PyObject *args ) {
+static PyObject * StrokeAttribute_set_attribute_real( BPy_StrokeAttribute *self, PyObject *args ) {
 	char *s = 0;
 	double d = 0;
 
@@ -276,8 +276,8 @@
 	Py_RETURN_NONE;
 }
 
-static char StrokeAttribute_setAttributeVec2f___doc__[] =
-".. method:: setAttributeVec2f(iName, att)\n"

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list