App/Application.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   (c) Jürgen Riegel (juergen.riegel@web.de) 2002                        *   
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU Library General Public License (LGPL)   *
00008  *   as published by the Free Software Foundation; either version 2 of     *
00009  *   the License, or (at your option) any later version.                   *
00010  *   for detail see the LICENCE text file.                                 *
00011  *                                                                         *
00012  *   FreeCAD is distributed in the hope that it will be useful,            *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * 
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU Library General Public License for more details.                  *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU Library General Public     *
00018  *   License along with FreeCAD; if not, write to the Free Software        *
00019  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00020  *   USA                                                                   *
00021  *                                                                         *
00022  *   Juergen Riegel 2002                                                   *
00023  ***************************************************************************/
00024 
00025 #ifndef APP_APPLICATION_H
00026 #define APP_APPLICATION_H
00027 
00028 #include <boost/signal.hpp>
00029 
00030 #include <vector>
00031 
00032 #include <Base/PyObjectBase.h>
00033 #include <Base/Parameter.h>
00034 #include <Base/Observer.h>
00035 
00036 
00037 namespace Base 
00038 {
00039     class ConsoleObserverStd; 
00040     class ConsoleObserverFile;
00041 }
00042 
00043 namespace App
00044 {
00045 
00046 class Document;
00047 class DocumentObject;
00048 class ApplicationObserver;
00049 class Property;
00050 
00051 
00052 
00057 class AppExport Application
00058 {
00059 
00060 public:
00061 
00062     //---------------------------------------------------------------------
00063     // exported functions goes here +++++++++++++++++++++++++++++++++++++++
00064     //---------------------------------------------------------------------
00065 
00077     App::Document* newDocument(const char * Name=0l, const char * UserName=0l);
00079     bool closeDocument(const char* name);
00081     std::string getUniqueDocumentName(const char *Name) const;
00083     App::Document* openDocument(const char * FileName=0l);
00085     App::Document* getActiveDocument(void) const;
00087     App::Document* getDocument(const char *Name) const;
00089     const char * getDocumentName(const App::Document* ) const;
00091     std::vector<App::Document*> getDocuments() const;
00093     void setActiveDocument(App::Document* pDoc);
00094     void setActiveDocument(const char *Name);
00096     void closeAllDocuments(void);
00098 
00101 
00102     boost::signal<void (const Document&)> signalNewDocument;
00104     boost::signal<void (const Document&)> signalDeleteDocument;
00106     boost::signal<void ()> signalDeletedDocument;
00108     boost::signal<void (const Document&)> signalRelabelDocument;
00110     boost::signal<void (const Document&)> signalRenameDocument;
00112     boost::signal<void (const Document&)> signalActiveDocument;
00114     boost::signal<void (const Document&)> signalSaveDocument;
00116     boost::signal<void (const Document&)> signalRestoreDocument;
00118 
00119 
00125 
00126     boost::signal<void (const App::DocumentObject&)> signalNewObject;
00127     //boost::signal<void (const App::DocumentObject&)>     m_sig;
00129     boost::signal<void (const App::DocumentObject&)> signalDeletedObject;
00131     boost::signal<void (const App::DocumentObject&, const App::Property&)> signalChangedObject;
00133     boost::signal<void (const App::DocumentObject&)> signalRenamedObject;
00135     boost::signal<void (const App::DocumentObject&)> signalActivatedObject;
00137 
00138 
00141 
00142     ParameterManager &                                GetSystemParameter(void) ;
00144     ParameterManager &                                GetUserParameter(void) ;
00154     Base::Reference<ParameterGrp>                     GetParameterGroupByPath(const char* sName);
00155 
00156     ParameterManager *                                GetParameterSet(const char* sName) const;
00157     const std::map<std::string,ParameterManager *> &  GetParameterSetList(void) const;
00158     void AddParameterSet(const char* sName);
00159     void RemoveParameterSet(const char* sName);
00161 
00174 
00175     void addImportType(const char* Type, const char* ModuleName);
00177     std::vector<std::string> getImportModules(const char* Type) const;
00179     std::vector<std::string> getImportModules() const;
00181     std::vector<std::string> getImportTypes(const char* Module) const;
00183     std::vector<std::string> getImportTypes(void) const;
00185     std::map<std::string, std::string> getImportFilters(const char* Type) const;
00187     std::map<std::string, std::string> getImportFilters(void) const;
00189 
00190 
00191     void addExportType(const char* Type, const char* ModuleName);
00193     std::vector<std::string> getExportModules(const char* Type) const;
00195     std::vector<std::string> getExportModules() const;
00197     std::vector<std::string> getExportTypes(const char* Module) const;
00199     std::vector<std::string> getExportTypes(void) const;
00201     std::map<std::string, std::string> getExportFilters(const char* Type) const;
00203     std::map<std::string, std::string> getExportFilters(void) const;
00205 
00208     static void init(int argc, char ** argv);
00209     static void initTypes(void);
00210     static void destruct(void);
00211     static void destructObserver(void);
00212     static void processCmdLineFiles(void);
00213     static void runApplication(void);
00214     friend Application &GetApplication(void);
00215     static std::map<std::string,std::string> &Config(void){return mConfig;}
00216     static int GetARGC(void){return _argc;}
00217     static char** GetARGV(void){return _argv;}
00219 
00220     const char* GetHomePath(void) const;
00221     const char* getExecutableName(void) const;
00222     static std::string getUserAppDataDir();
00223     static std::string getResourceDir();
00224     static std::string getHelpDir();
00225 
00226     friend class App::Document;
00227 
00228 protected:
00230     void renameDocument(const char *OldName, const char *NewName);
00231 
00236     void slotNewObject(const App::DocumentObject&);
00237     void slotDeletedObject(const App::DocumentObject&);
00238     void slotChangedObject(const App::DocumentObject&, const App::Property& Prop);
00239     void slotRenamedObject(const App::DocumentObject&);
00240     void slotActivatedObject(const App::DocumentObject&);
00242 
00243 private:
00245     Application(ParameterManager *pcSysParamMngr, ParameterManager *pcUserParamMngr,std::map<std::string,std::string> &mConfig);
00247     virtual ~Application();
00248 
00251     static ParameterManager *_pcSysParamMngr;
00252     static ParameterManager *_pcUserParamMngr;
00254 
00255 
00256     //---------------------------------------------------------------------
00257     // python exports goes here +++++++++++++++++++++++++++++++++++++++++++
00258     //---------------------------------------------------------------------
00259 
00260     // static python wrapper of the exported functions
00261     static PyObject* sGetParam          (PyObject *self,PyObject *args,PyObject *kwd);
00262     static PyObject* sGetVersion        (PyObject *self,PyObject *args,PyObject *kwd);
00263     static PyObject* sGetConfig         (PyObject *self,PyObject *args,PyObject *kwd);
00264     static PyObject* sSetConfig         (PyObject *self,PyObject *args,PyObject *kwd);
00265     static PyObject* sDumpConfig        (PyObject *self,PyObject *args,PyObject *kwd);
00266     static PyObject* sTemplateAdd       (PyObject *self,PyObject *args,PyObject *kwd);
00267     static PyObject* sTemplateDelete    (PyObject *self,PyObject *args,PyObject *kwd);
00268     static PyObject* sTemplateGet       (PyObject *self,PyObject *args,PyObject *kwd);
00269     static PyObject* sAddImportType     (PyObject *self,PyObject *args,PyObject *kwd);
00270     static PyObject* sGetImportType     (PyObject *self,PyObject *args,PyObject *kwd);
00271     static PyObject* sAddExportType     (PyObject *self,PyObject *args,PyObject *kwd);
00272     static PyObject* sGetExportType     (PyObject *self,PyObject *args,PyObject *kwd);
00273     static PyObject* sGetResourceDir    (PyObject *self,PyObject *args,PyObject *kwd);
00274     static PyObject* sGetHomePath       (PyObject *self,PyObject *args,PyObject *kwd);
00275 
00276     static PyObject* sLoadFile          (PyObject *self,PyObject *args,PyObject *kwd);
00277     static PyObject* sOpenDocument      (PyObject *self,PyObject *args,PyObject *kwd);
00278     static PyObject* sSaveDocument      (PyObject *self,PyObject *args,PyObject *kwd);
00279     static PyObject* sSaveDocumentAs    (PyObject *self,PyObject *args,PyObject *kwd);
00280     static PyObject* sNewDocument       (PyObject *self,PyObject *args,PyObject *kwd);
00281     static PyObject* sCloseDocument     (PyObject *self,PyObject *args,PyObject *kwd);
00282     static PyObject* sActiveDocument    (PyObject *self,PyObject *args,PyObject *kwd);
00283     static PyObject* sSetActiveDocument (PyObject *self,PyObject *args,PyObject *kwd);
00284     static PyObject* sGetDocument       (PyObject *self,PyObject *args,PyObject *kwd);
00285     static PyObject* sListDocuments     (PyObject *self,PyObject *args,PyObject *kwd);
00286     static PyObject* sAddDocObserver    (PyObject *self,PyObject *args,PyObject *kwd);
00287     static PyObject* sRemoveDocObserver (PyObject *self,PyObject *args,PyObject *kwd);
00288     static PyObject* sTranslateUnit     (PyObject *self,PyObject *args,PyObject *kwd);
00289 
00290     static PyMethodDef    Methods[]; 
00291 
00292     friend class ApplicationObserver;
00293 
00296     static void initConfig(int argc, char ** argv);
00297     static void initApplication(void);
00298     static void logStatus(void);
00299     // the one and only pointer to the application object
00300     static Application *_pcSingleton;
00302     static void ParseOptions(int argc, char ** argv);
00304     //static void CheckEnv(void);
00305     // search for the home path
00306     static std::string FindHomePath(const char* sCall);
00308     static void PrintInitHelp(void);
00310     static void ExtractUserPath();
00312     static void LoadParameters(void);
00314     static void SaveEnv(const char *);
00316     static std::map<std::string,std::string> mConfig;
00317     static int _argc;
00318     static char ** _argv;
00320 
00321     struct FileTypeItem {
00322         std::string filter;
00323         std::string module;
00324         std::vector<std::string> types;
00325     };
00326 
00328     std::vector<FileTypeItem> _mImportTypes;
00329     std::vector<FileTypeItem> _mExportTypes;
00330     std::map<std::string,Document*> DocMap;
00331     std::map<std::string,ParameterManager *> mpcPramManager;
00332     std::map<std::string,std::string> &_mConfig;
00333     App::Document* _pActiveDoc;
00334 
00335     static Base::ConsoleObserverStd  *_pConsoleObserverStd;
00336     static Base::ConsoleObserverFile *_pConsoleObserverFile;
00337 };
00338 
00340 inline App::Application &GetApplication(void){
00341     return *App::Application::_pcSingleton;
00342 }
00343 
00344 } // namespace App
00345 
00346 
00347 #endif // APP_APPLICATION_H
00348 

Generated on Wed Nov 23 18:59:55 2011 for FreeCAD by  doxygen 1.6.1