FeaturePage.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 <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 // FeaturePage
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             // When loading a document the included file
00071             // doesn't need to exist at this point.
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         // if there is a old absolute template file set use a redirect
00088         fi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName());
00089         // try the redirect
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     // open Template file
00101     string line;
00102     ifstream file (fi.filePath().c_str());
00103 
00104     // make a temp file for FileIncluded Property
00105     string tempName = PageResult.getExchangeTempFile();
00106     ofstream ofile(tempName.c_str());
00107 
00108     while (!file.eof())
00109     {
00110         getline (file,line);
00111         // check if the marker in the template is found
00112         if(line.find("<!-- DrawingContent -->") == string::npos)
00113             // if not -  write through
00114             ofile << line << endl;
00115         else
00116         {
00117             // get through the children and collect all the views
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     //const char* text = "lskdfjlsd";
00135     //const char* regex = "lskdflds";
00136     //boost::regex e(regex);
00137     //boost::smatch what;
00138     //if(boost::regex_match(string(text), what, e))
00139     //{
00140     //}
00141     return App::DocumentObject::StdReturn;
00142 }

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