RayProject.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2002     *
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 #ifndef _PreComp_
00027 # include <Standard.hxx>
00028 # include <string>
00029 #endif
00030 
00031 #include <Base/FileInfo.h>
00032 #include <Base/Console.h>
00033 #include "RayProject.h"
00034 #include "RaySegment.h"
00035 
00036 using namespace Raytracing;
00037 using namespace std;
00038 
00039 PROPERTY_SOURCE(Raytracing::RayProject, App::DocumentObjectGroup)
00040 
00041 //===========================================================================
00042 // Feature
00043 //===========================================================================
00044 
00045 RayProject::RayProject(void)
00046 {
00047     ADD_PROPERTY_TYPE(PageResult ,(0),0,App::Prop_Output,"Resulting povray Project file");
00048     ADD_PROPERTY_TYPE(Template   ,(""),0,App::Prop_None  ,"Template for the Povray project");
00049 }
00050 
00051 App::DocumentObjectExecReturn *RayProject::execute(void)
00052 {
00053     if (std::string(PageResult.getValue()) == "")
00054         PageResult.setValue(Template.getValue());
00055 
00056     Base::FileInfo fi(Template.getValue());
00057     if (!fi.isReadable()) {
00058         Base::Console().Log("RayProject::execute() not able to open %s!\n",Template.getValue());
00059         std::string error = std::string("Cannot open file ") + Template.getValue();
00060         return new App::DocumentObjectExecReturn(error);
00061     }
00062     // open Template file
00063     string line;
00064     ifstream file ( fi.filePath().c_str() );
00065 
00066     // make a temp file for FileIncluded Property
00067     string tempName = PageResult.getExchangeTempFile();
00068     ofstream ofile(tempName.c_str());
00069 
00070     while (!file.eof()) {
00071         getline (file,line);
00072         if (line != "<!- ProjectContent -->")
00073             ofile << line << endl;
00074         else {
00075             // get through the children and collect all the views
00076             const std::vector<App::DocumentObject*> &Grp = Group.getValues();
00077             for (std::vector<App::DocumentObject*>::const_iterator It= Grp.begin();It!=Grp.end();++It) {
00078                 if ((*It)->getTypeId().isDerivedFrom(Raytracing::RaySegment::getClassTypeId())) {
00079                     Raytracing::RaySegment *View = dynamic_cast<Raytracing::RaySegment *>(*It);
00080                     ofile << View->Result.getValue();
00081                     ofile << endl << endl << endl;
00082                 }
00083             }
00084         }
00085     }
00086 
00087     file.close();
00088     ofile.close();
00089 
00090     PageResult.setValue(tempName.c_str());
00091 
00092     return App::DocumentObject::StdReturn;
00093 }
00094 
00095 short RayProject::mustExecute() const
00096 {
00097     return 0;
00098 }

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