00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "PreCompiled.h"
00024 #ifndef _PreComp_
00025 #endif
00026
00027
00028 #include <Python.h>
00029
00030 #include <Base/Console.h>
00031 #include "PovTools.h"
00032
00033 #include "FreeCADpov.h"
00034
00035 #include <Mod/Part/App/TopoShape.h>
00036 #include <Mod/Part/App/TopoShapePy.h>
00037 #include <App/Application.h>
00038
00039 using namespace Raytracing;
00040
00041
00043 static PyObject *
00044 writeProjectFile(PyObject *self, PyObject *args)
00045 {
00046 char *fromPython;
00047 if (! PyArg_ParseTuple(args, "(s)", &fromPython))
00048 return NULL;
00049
00050 std::ofstream fout;
00051 if(fromPython)
00052 fout.open(fromPython);
00053 else
00054 fout.open("FreeCAD.pov");
00055
00056 fout << FreeCAD ;
00057 fout.close();
00058
00059 Py_Return;
00060 }
00061
00063 static PyObject *
00064 getProjectFile(PyObject *self, PyObject *args)
00065 {
00066 return Py_BuildValue("s", FreeCAD);
00067 }
00068
00070 static PyObject *
00071 getPartAsPovray(PyObject *self, PyObject *args)
00072 {
00073 float r=0.5,g=0.5,b=0.5;
00074 PyObject *ShapeObject;
00075 const char *PartName;
00076 if (! PyArg_ParseTuple(args, "sO!|fff",&PartName,
00077 &(Part::TopoShapePy::Type), &ShapeObject,&r,&g,&b))
00078 return NULL;
00079
00080 std::stringstream out;
00081 TopoDS_Shape &aShape = static_cast<Part::TopoShapePy *>(ShapeObject)->getTopoShapePtr()->_Shape;
00082
00083 PovTools::writeShape(out,PartName,aShape,(float)0.1);
00084
00085 out << "// instance to render" << endl
00086 << "object {" << PartName << endl
00087 << " texture {" << endl
00088 << " pigment {color rgb <"<<r<<","<<g<<","<<b<<">}" << endl
00089 << " finish {StdFinish } //definition on top of the project" << endl
00090 << " }" << endl
00091 << "}" << endl ;
00092 return Py::new_reference_to(Py::String(out.str()));
00093 }
00094
00096 static PyObject *
00097 writePartFile(PyObject *self, PyObject *args)
00098 {
00099 PyObject *ShapeObject;
00100 const char *FileName,*PartName;
00101 if (! PyArg_ParseTuple(args, "ssO!",&FileName,&PartName,
00102 &(Part::TopoShapePy::Type), &ShapeObject))
00103 return NULL;
00104
00105 TopoDS_Shape &aShape = static_cast<Part::TopoShapePy *>(ShapeObject)->getTopoShapePtr()->_Shape;
00106
00107 PovTools::writeShape(FileName,PartName,aShape,(float)0.1);
00108
00109 Py_Return;
00110 }
00111
00113 static PyObject *
00114 writeDataFile(PyObject *self, PyObject *args)
00115 {
00116 PyObject *dataObject;
00117 const char *FileName,*PartName;
00118 if (! PyArg_ParseTuple(args, "ssO!",&FileName,&PartName,
00119 &(Data::ComplexGeoDataPy::Type), &dataObject))
00120 return 0;
00121
00122 const Data::ComplexGeoData* aData = static_cast<Data::ComplexGeoDataPy *>
00123 (dataObject)->getComplexGeoDataPtr();
00124
00125 PovTools::writeData(FileName,PartName,aData,0.1f);
00126
00127 Py_Return;
00128 }
00129
00131 static PyObject *
00132 writePartFileCSV(PyObject *self, PyObject *args)
00133 {
00134 PyObject *ShapeObject;
00135 const char *FileName;
00136 float Acur,Length;
00137 if (! PyArg_ParseTuple(args, "O!sff",&(Part::TopoShapePy::Type),
00138 &ShapeObject,&FileName,&Acur,&Length))
00139 return NULL;
00140
00141 TopoDS_Shape aShape = static_cast<Part::TopoShapePy *>(ShapeObject)->getTopoShapePtr()->_Shape;
00142 PovTools::writeShapeCSV(FileName,aShape,Acur,Length);
00143 Py_Return;
00144 }
00145
00147 static PyObject *
00148 writeCameraFile(PyObject *self, PyObject *args)
00149 {
00150 PyObject *Arg[4];
00151 const char *FileName;
00152 double vecs[4][3];
00153 if (! PyArg_ParseTuple(args, "sO!O!O!O!",&FileName,&PyTuple_Type,
00154 &Arg[0],&PyTuple_Type, &Arg[1],&PyTuple_Type, &Arg[2],&PyTuple_Type, &Arg[3]))
00155 return NULL;
00156
00157
00158 for(int i=0;i<4;i++) {
00159
00160 if(PyTuple_GET_SIZE(Arg[i]) != 3)
00161 Py_Error(PyExc_Exception,"Wrong parameter format, four Tuple of three floats needed!");
00162
00163
00164 for(int l=0;l<3;l++) {
00165 PyObject* temp = PyTuple_GetItem(Arg[i],l);
00166
00167 if (PyFloat_Check(temp))
00168 vecs[i][l] = PyFloat_AsDouble(temp);
00169 else if (PyLong_Check(temp))
00170 vecs[i][l] = (double) PyLong_AsLong(temp);
00171 else if (PyInt_Check(temp))
00172 vecs[i][l] = (double) PyInt_AsLong(temp);
00173 else
00174 Py_Error(PyExc_Exception,"Wrong parameter format, four Tuple of three floats needed!");
00175 }
00176 }
00177
00178
00179 PovTools::writeCamera(FileName,CamDef(gp_Vec(vecs[0][0],vecs[0][1],vecs[0][2]),
00180 gp_Vec(vecs[1][0],vecs[1][1],vecs[1][2]),
00181 gp_Vec(vecs[2][0],vecs[2][1],vecs[2][2]),
00182 gp_Vec(vecs[3][0],vecs[3][1],vecs[3][2])));
00183
00184 Py_Return;
00185 }
00186
00188 static PyObject *
00189 copyResource(PyObject *self, PyObject *args)
00190 {
00191 const char *FileName,*DestDir;
00192 if (! PyArg_ParseTuple(args, "ss",&FileName,&DestDir))
00193 return NULL;
00194
00195 std::string resName = App::GetApplication().GetHomePath();
00196 resName += "Mod";
00197 resName += PATHSEP ;
00198 resName += "Raytracing";
00199 resName += PATHSEP ;
00200 resName += "resources";
00201 resName += PATHSEP;
00202 resName += FileName;
00203
00204 Base::Console().Warning("Using fileName = %s\nRaytracer scene file not generated "
00205 "because function is not implemented yet.\nYou can copy "
00206 "the standard scene file FreeCAD.pov to your raytracing "
00207 "directory to render the scene.\n",resName.c_str());
00208
00209
00210
00211 Py_Return;
00212 }
00213
00214
00215 struct PyMethodDef Raytracing_methods[] = {
00216 {"writeProjectFile", writeProjectFile, 1},
00217 {"getProjectFile", getProjectFile , 1},
00218 {"writePartFile", writePartFile , 1},
00219 {"writePartFileCSV", writePartFileCSV, 1},
00220 {"getPartAsPovray", getPartAsPovray , 1},
00221 {"writeDataFile", writeDataFile , 1},
00222 {"writeCameraFile", writeCameraFile , 1},
00223 {"copyResource", copyResource , 1},
00224 {NULL, NULL}
00225 };