RayProject.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00063 string line;
00064 ifstream file ( fi.filePath().c_str() );
00065
00066
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
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 }