From 529b92cbfe8e188c7e8170bf80c5eec3ab4a95f3 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 29 Dec 2011 23:23:37 -0200 Subject: [PATCH] + small fixes to the Drawing Page --- src/Mod/Drawing/App/FeaturePage.cpp | 66 +++++++++++++++++------------ src/Mod/Drawing/App/FeaturePage.h | 1 + 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/Mod/Drawing/App/FeaturePage.cpp b/src/Mod/Drawing/App/FeaturePage.cpp index 2779105e9..bf1af14af 100644 --- a/src/Mod/Drawing/App/FeaturePage.cpp +++ b/src/Mod/Drawing/App/FeaturePage.cpp @@ -76,34 +76,11 @@ void FeaturePage::onChanged(const App::Property* prop) } } if (prop == &Template) { - // getting editable texts from "freecad:editable" tags in SVG template if (!this->isRestoring()) { - if (Template.getValue() != "") { - Base::FileInfo tfi(Template.getValue()); - if (tfi.isReadable()) { - string tline, tfrag; - ifstream tfile (tfi.filePath().c_str()); - while (!tfile.eof()) { - getline (tfile,tline); - tfrag += tline; - tfrag += "--endOfLine--"; - } - tfile.close(); - boost::regex e ("(.*?)"); - string::const_iterator tbegin, tend; - tbegin = tfrag.begin(); - tend = tfrag.end(); - boost::match_results twhat; - std::vector eds; - while (boost::regex_search(tbegin, tend, twhat, e)) { - printf(twhat[1].str().c_str()); - eds.push_back(twhat[2]); - tbegin = twhat[0].second; - } - EditableTexts.setValues(eds); - } - } + cout << "setting template " << Template.getValue() << endl; + EditableTexts.setValues(getEditableTexts()); } + else cout << "restoring" << endl; } App::DocumentObjectGroup::onChanged(prop); } @@ -199,3 +176,40 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void) //} return App::DocumentObject::StdReturn; } + +std::vector FeaturePage::getEditableTexts(void) const { + //getting editable texts from "freecad:editable" tags in SVG template + + std::vector eds; + + if (Template.getValue() != "") { + Base::FileInfo tfi(Template.getValue()); + if (!tfi.isReadable()) { + // if there is a old absolute template file set use a redirect + tfi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + tfi.fileName()); + // try the redirect + if (!tfi.isReadable()) { + return eds; + } + } + string tline, tfrag; + ifstream tfile (tfi.filePath().c_str()); + while (!tfile.eof()) { + getline (tfile,tline); + tfrag += tline; + tfrag += "--endOfLine--"; + } + tfile.close(); + boost::regex e ("(.*?)"); + string::const_iterator tbegin, tend; + tbegin = tfrag.begin(); + tend = tfrag.end(); + boost::match_results twhat; + while (boost::regex_search(tbegin, tend, twhat, e)) { + printf(twhat[1].str().c_str()); + eds.push_back(twhat[2]); + tbegin = twhat[0].second; + } + } + return eds; +} diff --git a/src/Mod/Drawing/App/FeaturePage.h b/src/Mod/Drawing/App/FeaturePage.h index ed64c1b3b..3f74065b7 100644 --- a/src/Mod/Drawing/App/FeaturePage.h +++ b/src/Mod/Drawing/App/FeaturePage.h @@ -59,6 +59,7 @@ public: virtual const char* getViewProviderName(void) const { return "DrawingGui::ViewProviderDrawingPage"; } + virtual std::vector getEditableTexts(void) const; protected: void onChanged(const App::Property* prop);