FeaturePage.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 <sstream>
00028 #endif
00029
00030
00031 #include <Base/Exception.h>
00032 #include <Base/Console.h>
00033 #include <Base/FileInfo.h>
00034 #include <App/Application.h>
00035 #include <boost/regex.hpp>
00036 #include <iostream>
00037
00038 #include "FeaturePage.h"
00039 #include "FeatureView.h"
00040
00041 using namespace Drawing;
00042 using namespace std;
00043
00044
00045
00046
00047
00048
00049 PROPERTY_SOURCE(Drawing::FeaturePage, App::DocumentObjectGroup)
00050
00051 const char *group = "Drawing view";
00052
00053 FeaturePage::FeaturePage(void)
00054 {
00055 static const char *group = "Drawing view";
00056
00057 ADD_PROPERTY_TYPE(PageResult ,(0),group,App::Prop_Output,"Resulting SVG document of that page");
00058 ADD_PROPERTY_TYPE(Template ,(""),group,App::Prop_None ,"Template for the page");
00059 }
00060
00061 FeaturePage::~FeaturePage()
00062 {
00063 }
00064
00066 void FeaturePage::onChanged(const App::Property* prop)
00067 {
00068 if (prop == &PageResult) {
00069 if (this->isRestoring()) {
00070
00071
00072 Base::FileInfo fi(PageResult.getValue());
00073 if (!fi.exists())
00074 return;
00075 }
00076 }
00077 App::DocumentObjectGroup::onChanged(prop);
00078 }
00079
00080 App::DocumentObjectExecReturn *FeaturePage::execute(void)
00081 {
00082 if(Template.getValue() == "")
00083 return App::DocumentObject::StdReturn;
00084
00085 Base::FileInfo fi(Template.getValue());
00086 if (!fi.isReadable()) {
00087
00088 fi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName());
00089
00090 if (!fi.isReadable()) {
00091 Base::Console().Log("FeaturePage::execute() not able to open %s!\n",Template.getValue());
00092 std::string error = std::string("Cannot open file ") + Template.getValue();
00093 return new App::DocumentObjectExecReturn(error);
00094 }
00095 }
00096
00097 if (std::string(PageResult.getValue()).empty())
00098 PageResult.setValue(fi.filePath().c_str());
00099
00100
00101 string line;
00102 ifstream file (fi.filePath().c_str());
00103
00104
00105 string tempName = PageResult.getExchangeTempFile();
00106 ofstream ofile(tempName.c_str());
00107
00108 while (!file.eof())
00109 {
00110 getline (file,line);
00111
00112 if(line.find("<!-- DrawingContent -->") == string::npos)
00113
00114 ofile << line << endl;
00115 else
00116 {
00117
00118 const std::vector<App::DocumentObject*> &Grp = Group.getValues();
00119 for (std::vector<App::DocumentObject*>::const_iterator It= Grp.begin();It!=Grp.end();++It) {
00120 if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) {
00121 Drawing::FeatureView *View = dynamic_cast<Drawing::FeatureView *>(*It);
00122 ofile << View->ViewResult.getValue();
00123 ofile << endl << endl << endl;
00124 }
00125 }
00126 }
00127 }
00128
00129 file.close();
00130 ofile.close();
00131
00132 PageResult.setValue(tempName.c_str());
00133
00134
00135
00136
00137
00138
00139
00140
00141 return App::DocumentObject::StdReturn;
00142 }