MaterialPyImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #include "App/Material.h"
00027 
00028 // inclusion of the generated files (generated out of MaterialPy.xml)
00029 #include "MaterialPy.h"
00030 #include "MaterialPy.cpp"
00031 
00032 using namespace App;
00033 
00034 // returns a string which represents the object e.g. when printed in python
00035 std::string MaterialPy::representation(void) const
00036 {
00037     return std::string("<Material object>");
00038 }
00039 
00040 PyObject* MaterialPy::set(PyObject * args)
00041 {
00042     char *pstr;
00043     if (!PyArg_ParseTuple(args, "s", &pstr))     // convert args: Python->C 
00044         return NULL;                             // NULL triggers exception 
00045 
00046     getMaterialPtr()->set(pstr);
00047 
00048     Py_Return;
00049 }
00050 
00051 Py::Tuple MaterialPy::getAmbientColor(void) const
00052 {
00053     Py::Tuple tuple(4);
00054     tuple.setItem(0, Py::Float(getMaterialPtr()->ambientColor.r));
00055     tuple.setItem(1, Py::Float(getMaterialPtr()->ambientColor.g));
00056     tuple.setItem(2, Py::Float(getMaterialPtr()->ambientColor.b));
00057     tuple.setItem(3, Py::Float(getMaterialPtr()->ambientColor.a));
00058     return tuple;
00059 }
00060 
00061 void MaterialPy::setAmbientColor(Py::Tuple arg)
00062 {
00063     Color c;
00064     c.r = (float)Py::Float(arg.getItem(0));
00065     c.g = (float)Py::Float(arg.getItem(1));
00066     c.b = (float)Py::Float(arg.getItem(2));
00067     if (arg.size() == 4)
00068     c.a = (float)Py::Float(arg.getItem(3));
00069     getMaterialPtr()->ambientColor = c;
00070 }
00071 
00072 Py::Tuple MaterialPy::getDiffuseColor(void) const
00073 {
00074     Py::Tuple tuple(4);
00075     tuple.setItem(0, Py::Float(getMaterialPtr()->diffuseColor.r));
00076     tuple.setItem(1, Py::Float(getMaterialPtr()->diffuseColor.g));
00077     tuple.setItem(2, Py::Float(getMaterialPtr()->diffuseColor.b));
00078     tuple.setItem(3, Py::Float(getMaterialPtr()->diffuseColor.a));
00079     return tuple;
00080 }
00081 
00082 void MaterialPy::setDiffuseColor(Py::Tuple arg)
00083 {
00084     Color c;
00085     c.r = (float)Py::Float(arg.getItem(0));
00086     c.g = (float)Py::Float(arg.getItem(1));
00087     c.b = (float)Py::Float(arg.getItem(2));
00088     if (arg.size() == 4)
00089     c.a = (float)Py::Float(arg.getItem(3));
00090     getMaterialPtr()->diffuseColor = c;
00091 }
00092 
00093 Py::Tuple MaterialPy::getEmissiveColor(void) const
00094 {
00095     Py::Tuple tuple(4);
00096     tuple.setItem(0, Py::Float(getMaterialPtr()->emissiveColor.r));
00097     tuple.setItem(1, Py::Float(getMaterialPtr()->emissiveColor.g));
00098     tuple.setItem(2, Py::Float(getMaterialPtr()->emissiveColor.b));
00099     tuple.setItem(3, Py::Float(getMaterialPtr()->emissiveColor.a));
00100     return tuple;
00101 }
00102 
00103 void MaterialPy::setEmissiveColor(Py::Tuple arg)
00104 {
00105     Color c;
00106     c.r = (float)Py::Float(arg.getItem(0));
00107     c.g = (float)Py::Float(arg.getItem(1));
00108     c.b = (float)Py::Float(arg.getItem(2));
00109     if (arg.size() == 4)
00110     c.a = (float)Py::Float(arg.getItem(3));
00111     getMaterialPtr()->emissiveColor = c;
00112 }
00113 
00114 Py::Tuple MaterialPy::getSpecularColor(void) const
00115 {
00116     Py::Tuple tuple(4);
00117     tuple.setItem(0, Py::Float(getMaterialPtr()->specularColor.r));
00118     tuple.setItem(1, Py::Float(getMaterialPtr()->specularColor.g));
00119     tuple.setItem(2, Py::Float(getMaterialPtr()->specularColor.b));
00120     tuple.setItem(3, Py::Float(getMaterialPtr()->specularColor.a));
00121     return tuple;
00122 }
00123 
00124 void MaterialPy::setSpecularColor(Py::Tuple arg)
00125 {
00126     Color c;
00127     c.r = (float)Py::Float(arg.getItem(0));
00128     c.g = (float)Py::Float(arg.getItem(1));
00129     c.b = (float)Py::Float(arg.getItem(2));
00130     if (arg.size() == 4)
00131     c.a = (float)Py::Float(arg.getItem(3));
00132     getMaterialPtr()->specularColor = c;
00133 }
00134 
00135 Py::Float MaterialPy::getShininess(void) const
00136 {
00137     return Py::Float(getMaterialPtr()->shininess);
00138 }
00139 
00140 void MaterialPy::setShininess(Py::Float arg)
00141 {
00142     getMaterialPtr()->shininess = (float)arg;
00143 }
00144 
00145 Py::Float MaterialPy::getTransparency(void) const
00146 {
00147     return Py::Float(getMaterialPtr()->transparency);
00148 }
00149 
00150 void MaterialPy::setTransparency(Py::Float arg)
00151 {
00152     getMaterialPtr()->transparency = (float)arg;
00153 }
00154 
00155 PyObject *MaterialPy::getCustomAttributes(const char* /*attr*/) const
00156 {
00157     return 0;
00158 }
00159 
00160 int MaterialPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00161 {
00162     return 0; 
00163 }

Generated on Wed Nov 23 19:00:21 2011 for FreeCAD by  doxygen 1.6.1