diff --git a/src/Mod/Raytracing/App/AppRaytracing.cpp b/src/Mod/Raytracing/App/AppRaytracing.cpp index 48a48f942..a4570e0aa 100644 --- a/src/Mod/Raytracing/App/AppRaytracing.cpp +++ b/src/Mod/Raytracing/App/AppRaytracing.cpp @@ -32,6 +32,7 @@ #include "RayFeature.h" #include "RayProject.h" #include "RaySegment.h" +#include "LuxFeature.h" extern struct PyMethodDef Raytracing_methods[]; @@ -51,6 +52,7 @@ void AppRaytracingExport initRaytracing() Raytracing::RaySegment ::init(); Raytracing::RayFeature ::init(); Raytracing::RayProject ::init(); + Raytracing::LuxFeature ::init(); (void) Py_InitModule("Raytracing", Raytracing_methods); /* mod name, table ptr */ diff --git a/src/Mod/Raytracing/App/CMakeLists.txt b/src/Mod/Raytracing/App/CMakeLists.txt index de458a9b2..94499db7f 100644 --- a/src/Mod/Raytracing/App/CMakeLists.txt +++ b/src/Mod/Raytracing/App/CMakeLists.txt @@ -52,6 +52,8 @@ SET(Raytracing_SRCS RayProject.h RaySegment.cpp RaySegment.h + LuxFeature.h + LuxFeature.cpp ) SET(Raytracing_Scripts diff --git a/src/Mod/Raytracing/App/LuxFeature.cpp b/src/Mod/Raytracing/App/LuxFeature.cpp new file mode 100644 index 000000000..3a6d64bff --- /dev/null +++ b/src/Mod/Raytracing/App/LuxFeature.cpp @@ -0,0 +1,82 @@ +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2013 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +#endif + +#include +#include +#include + +#include "PovTools.h" +#include "LuxFeature.h" +#include "LuxTools.h" + + +using namespace Raytracing; + +PROPERTY_SOURCE(Raytracing::LuxFeature, Raytracing::RaySegment) + +//=========================================================================== +// Feature +//=========================================================================== + +LuxFeature::LuxFeature(void) +{ + ADD_PROPERTY(Source,(0)); + ADD_PROPERTY(Color,(App::Color(0.5f,0.5f,0.5f))); +} + +App::DocumentObjectExecReturn *LuxFeature::execute(void) +{ + std::stringstream result; + std::string ViewName = Label.getValue(); + + App::DocumentObject* link = Source.getValue(); + if (!link) + return new App::DocumentObjectExecReturn("No object linked"); + if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) + return new App::DocumentObjectExecReturn("Linked object is not a Part object"); + TopoDS_Shape shape = static_cast(link)->Shape.getShape()._Shape; + std::string Name(std::string("Lux_")+static_cast(link)->Label.getValue()); + if (shape.IsNull()) + return new App::DocumentObjectExecReturn("Linked shape object is empty"); + + // write a material entry + // This must not be done in LuxTools::writeShape! + const App::Color& c = Color.getValue(); + result << "MakeNamedMaterial \"FreeCADMaterial_" << Name << "\"" << endl + << " \"color Kd\" [" << c.r << " " << c.g << " " << c.b << "]" << endl + << " \"float sigma\" [0.000000000000000]" << endl + << " \"string type\" [\"matte\"]" << endl << endl; + + LuxTools::writeShape(result,Name.c_str(),shape); + + // Apply the resulting fragment + Result.setValue(result.str().c_str()); + + return App::DocumentObject::StdReturn; +} diff --git a/src/Mod/Raytracing/App/LuxFeature.h b/src/Mod/Raytracing/App/LuxFeature.h new file mode 100644 index 000000000..a0966617e --- /dev/null +++ b/src/Mod/Raytracing/App/LuxFeature.h @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2013 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef _LuxFeature_h_ +#define _LuxFeature_h_ + +#include +#include +#include +#include + +#include "RaySegment.h" + + +namespace Raytracing +{ + +class Property; + +/** Base class of all Feature classes in FreeCAD + */ +//class LuxFeature: public Part::PartFeature +class AppRaytracingExport LuxFeature: public Raytracing::RaySegment +{ + PROPERTY_HEADER(Raytracing::LuxFeature); +public: + /// Constructor + LuxFeature(void); + + App::PropertyLink Source; + App::PropertyColor Color; + + /** @name methods overide Feature */ + //@{ + /// recalculate the Feature + App::DocumentObjectExecReturn *execute(void); + + /// returns the type name of the ViewProvider + const char* getViewProviderName(void) const { + return "Gui::ViewProviderDocumentObject"; + } + //@} +}; + +} //namespace Raytracing + +#endif //_LuxFeature_h_ diff --git a/src/Mod/Raytracing/App/LuxTools.h b/src/Mod/Raytracing/App/LuxTools.h index c02e2de0f..bde71398c 100644 --- a/src/Mod/Raytracing/App/LuxTools.h +++ b/src/Mod/Raytracing/App/LuxTools.h @@ -34,6 +34,7 @@ namespace Data { class ComplexGeoData; } namespace Raytracing { + class AppRaytracingExport LuxTools { public: