[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22153] branches/soc-2008-mxcurioni/source /blender/freestyle/intern/python/Interface0D/ViewVertex: SWIG/ directors dependency removal (cont'd)

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Sun Aug 2 21:36:18 CEST 2009


Revision: 22153
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22153
Author:   kjym3
Date:     2009-08-02 21:36:18 +0200 (Sun, 02 Aug 2009)

Log Message:
-----------
SWIG/directors dependency removal (cont'd)

Removed all castToSomething() methods from Interface0D's subclasses.
These methods are useless, because introspection-based automatic type
conversion takes place whenever it is applicable.

If you need to rewrite old style modules that rely on the cast methods,
apply the following rewriting rules:

- SVertex.castToSVertex()
- TVertex.castToViewVertex()
- TVertex.castToTVertex()
- NonTVertex.castToViewVertex()
- NonTVertex.castToNonTVertex()

  These 5 methods return an object itself, so just removing a method
  call will suffice.  If you need to handle objects in a different way
  depending on their types, then you can use Python's type checking
  idioms such as "type(obj) is T" and "isinstance(obj, T)".  Example:

    [Original]
    v = it.getObject()
    # try to convert v into a TVertex object
    vertex = v.castToTVertex()
    if vertex != None:
	... # do something on the TVertex object
    # try to convert v into a NonTVertex object
    vertex = v.castToNonTVertex()
    if vertex != None:
	... # do something on the NonTVertex object

    [Rewritten]
    vertex = it.getObject()
    if type(vertex) is TVertex:
	... # do something on the TVertex object
    elif type(vertex) is NonTVertex:
	... # do something on the NonTVertex object

- SVertex.castToViewVertex()
- SVertex.castToTVertex()
- SVertex.castToNonTVertex()

  Use SVertex.viewvertex() instead.  You don't need to care about
  which cast method is appropriate.  SVertex.viewvertex() does, if
  necessary, introspection-based automatic type conversion for you.

- NonTVertex.castToSVertex()

  Use NonTVertex.svertex() instead.

- CurvePoint.castToSVertex()

  Let cp be a CurvePoint object, then this method can be expressed as
  follows:

    if cp.t2d() == 0.0:
	return cp.A() # returns an SVertex
    elif cp.t2d() == 1.0:
	return cp.B() # returns an SVertex
    return None

- CurvePoint.castToViewVertex()
- CurvePoint.castToTVertex()
- CurvePoint.castToNonVertex()

  Similarly, these 3 methods can be expressed as follows:

    if cp.t2d() == 0.0:
	return cp.A().viewvertex()
    elif cp.t2d() == 1.0:
	return cp.B().viewvertex()
    return None

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp	2009-08-02 18:32:56 UTC (rev 22152)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp	2009-08-02 19:36:18 UTC (rev 22153)
@@ -12,18 +12,12 @@
 /*---------------  Python API function prototypes for NonTVertex___init__ instance  -----------*/
 static int NonTVertex___init__(BPy_NonTVertex *self, PyObject *args, PyObject *kwds);
 
-static PyObject * NonTVertex_castToSVertex( BPy_NonTVertex *self );
-static PyObject * NonTVertex_castToViewVertex( BPy_NonTVertex *self );
-static PyObject * NonTVertex_castToNonTVertex( BPy_NonTVertex *self );
 static PyObject * NonTVertex_svertex( BPy_NonTVertex *self );
 static PyObject * NonTVertex_setSVertex( BPy_NonTVertex *self, PyObject *args);
 
 /*----------------------NonTVertex instance definitions ----------------------------*/
 static PyMethodDef BPy_NonTVertex_methods[] = {	
 //	{"__copy__", ( PyCFunction ) NonTVertex___copy__, METH_NOARGS, "( )Cloning method."},
-	{"castToSVertex", ( PyCFunction ) NonTVertex_castToSVertex, METH_NOARGS, "( )Cast the Interface0D in SVertex if it can be. "},
-	{"castToViewVertex", ( PyCFunction ) NonTVertex_castToViewVertex, METH_NOARGS, "( )Cast the Interface0D in ViewVertex if it can be. "},
-	{"castToNonTVertex", ( PyCFunction ) NonTVertex_castToNonTVertex, METH_NOARGS, "( )Cast the Interface0D in NonTVertex if it can be. "},
 	{"svertex", ( PyCFunction ) NonTVertex_svertex, METH_NOARGS, "( )Returns the SVertex on top of which this NonTVertex is built. "},
 	{"setSVertex", ( PyCFunction ) NonTVertex_setSVertex, METH_VARARGS, "(SVertex sv )Sets the SVertex on top of which this NonTVertex is built. "},
 	{NULL, NULL, 0, NULL}
@@ -144,21 +138,6 @@
 	return 0;
 }
 
-PyObject * NonTVertex_castToSVertex( BPy_NonTVertex *self ) {
-	PyObject *py_sv =  SVertex_Type.tp_new( &SVertex_Type, 0, 0 );
-	((BPy_SVertex *) py_sv)->sv = self->ntv->castToSVertex();
-
-	return py_sv;
-}
-
-PyObject * NonTVertex_castToViewVertex( BPy_NonTVertex *self ) {
-	return BPy_ViewVertex_from_ViewVertex( *(self->ntv->castToViewVertex()) );
-}
-
-PyObject * NonTVertex_castToNonTVertex( BPy_NonTVertex *self ) {
-	return BPy_NonTVertex_from_NonTVertex( *(self->ntv->castToNonTVertex()) );
-}
-
 PyObject * NonTVertex_svertex( BPy_NonTVertex *self ) {
 	SVertex *v = self->ntv->svertex();
 	if( v ){

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp	2009-08-02 18:32:56 UTC (rev 22152)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp	2009-08-02 19:36:18 UTC (rev 22153)
@@ -15,8 +15,6 @@
 /*---------------  Python API function prototypes for TVertex___init__ instance  -----------*/
 static int TVertex___init__(BPy_TVertex *self, PyObject *args, PyObject *kwds);
 
-static PyObject * TVertex_castToViewVertex( BPy_TVertex *self );
-static PyObject * TVertex_castToTVertex( BPy_TVertex *self );
 static PyObject * TVertex_frontSVertex( BPy_TVertex *self );
 static PyObject * TVertex_backSVertex( BPy_TVertex *self );
 static PyObject * TVertex_setFrontSVertex( BPy_TVertex *self, PyObject *args); 
@@ -28,8 +26,6 @@
 /*----------------------TVertex instance definitions ----------------------------*/
 static PyMethodDef BPy_TVertex_methods[] = {	
 //	{"__copy__", ( PyCFunction ) TVertex___copy__, METH_NOARGS, "( )Cloning method."},
-	{"castToViewVertex", ( PyCFunction ) TVertex_castToViewVertex, METH_NOARGS, "( )Cast the Interface0D in ViewVertex if it can be. "},
-	{"castToTVertex", ( PyCFunction ) TVertex_castToTVertex, METH_NOARGS, "( )Cast the Interface0D in TVertex if it can be. "},
 	{"frontSVertex", ( PyCFunction ) TVertex_frontSVertex, METH_NOARGS, "( )Returns the SVertex that is closer to the viewpoint. "},
 	{"backSVertex", ( PyCFunction ) TVertex_backSVertex, METH_NOARGS, "( )Returns the SVertex that is further away from the viewpoint. "},
 	{"setFrontSVertex", ( PyCFunction ) TVertex_setFrontSVertex, METH_VARARGS, "(SVertex sv )Sets the SVertex that is closer to the viewpoint. "},
@@ -140,14 +136,6 @@
 }
 
 
-PyObject * TVertex_castToViewVertex( BPy_TVertex *self ) {
-	return BPy_ViewVertex_from_ViewVertex( *(self->tv->castToViewVertex()) );
-}
-
-PyObject * TVertex_castToTVertex( BPy_TVertex *self ) {
-	return BPy_TVertex_from_TVertex( *(self->tv->castToTVertex()) );
-}
-
 PyObject * TVertex_frontSVertex( BPy_TVertex *self ) {
 	SVertex *v = self->tv->frontSVertex();
 	if( v ){





More information about the Bf-blender-cvs mailing list