App/Document.h

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 #ifndef APP_DOCUMENT_H
00024 #define APP_DOCUMENT_H
00025 
00026 #include <CXX/Objects.hxx>
00027 #include <Base/Observer.h>
00028 #include <Base/Persistence.h>
00029 #include <Base/Type.h>
00030 
00031 #include "PropertyContainer.h"
00032 #include "PropertyStandard.h"
00033 
00034 #include <map>
00035 #include <vector>
00036 #include <stack>
00037 
00038 #include <boost/signals.hpp>
00039 #include <boost/graph/adjacency_list.hpp>
00040 
00041 
00042 namespace Base {
00043     class Writer;
00044 }
00045 
00046 namespace App
00047 {
00048     class DocumentObject;
00049     class DocumentObjectExecReturn;
00050     class Document;
00051     class DocumentPy; // the python document class
00052     class Application;
00053     class Transaction;
00054 }
00055 
00056 namespace App
00057 {
00058 
00060 class AppExport Document : public App::PropertyContainer
00061 {
00062     PROPERTY_HEADER(App::Document);
00063 
00064 public:
00067 
00068     PropertyString Label;
00070     PropertyString FileName;
00072     PropertyString CreatedBy;
00073     PropertyString CreationDate;
00074     PropertyString LastModifiedBy;
00075     PropertyString LastModifiedDate;
00076     PropertyString Company;
00077     PropertyString Comment;
00078     PropertyString Id;
00079     PropertyString TransientDir;
00081 
00084 
00085     boost::signal<void (const App::DocumentObject&)> signalNewObject;
00086     //boost::signal<void (const App::DocumentObject&)>     m_sig;
00088     boost::signal<void (const App::DocumentObject&)> signalDeletedObject;
00090     boost::signal<void (const App::DocumentObject&, const App::Property&)> signalChangedObject;
00092     boost::signal<void (const App::DocumentObject&)> signalRenamedObject;
00094     boost::signal<void (const App::DocumentObject&)> signalActivatedObject;
00100     boost::signal<void (Base::Writer   &)> signalSaveDocument;
00101     boost::signal<void (Base::XMLReader&)> signalRestoreDocument;
00102     boost::signal<void (const std::vector<App::DocumentObject*>&,
00103                         Base::Writer   &)> signalExportObjects;
00104     boost::signal<void (const std::vector<App::DocumentObject*>&,
00105                         Base::XMLReader&)> signalImportObjects;
00107 
00110 
00111     //void saveAs (const char* Name);
00113     bool save (void);
00115     void restore (void);
00116     void exportObjects(const std::vector<App::DocumentObject*>&, std::ostream&);
00117     std::vector<App::DocumentObject*> importObjects(std::istream&);
00119     //void open (void);
00121     bool isSaved() const;
00123     const char* getName() const;
00125 
00126     virtual void Save (Base::Writer &writer) const;
00127     virtual void Restore(Base::XMLReader &reader);
00128 
00130     unsigned int getMemSize (void) const;
00131 
00134 
00135     DocumentObject *addObject(const char* sType, const char* pObjectName=0);
00137     void remObject(const char* sName);
00143     DocumentObject* copyObject(DocumentObject* obj, bool recursive=false);
00150     DocumentObject* moveObject(DocumentObject* obj, bool recursive=false);
00152     DocumentObject *getActiveObject(void) const;
00154     DocumentObject *getObject(const char *Name) const;
00156     const char *getObjectName(DocumentObject *pFeat) const;
00158     std::string getUniqueObjectName(const char *Name) const;
00160     std::string getStandardObjectName(const char *Name, int d) const;
00162     std::vector<DocumentObject*> getObjects() const;
00163     std::vector<DocumentObject*> getObjectsOfType(const Base::Type& typeId) const;
00165     template<typename T> inline std::vector<T*> getObjectsOfType() const;
00166     int countObjectsOfType(const Base::Type& typeId) const;
00168     int countObjects(void) const;
00170 
00174 
00175     void purgeTouched();
00177     bool isTouched(void) const;
00179     std::vector<App::DocumentObject *> getTouched(void) const;
00181     void setClosable(bool);
00183     bool isClosable() const;
00185     void recompute();
00187     void recomputeFeature(DocumentObject* Feat);
00189     const std::vector<App::DocumentObjectExecReturn*> &getRecomputeLog(void)const{return _RecomputeLog;}
00191     const char* getErrorDescription(const App::DocumentObject*) const;
00193 
00194 
00197 
00198     void setUndoMode(int iMode);  
00200     int getUndoMode(void) const;  
00202     void setTransactionMode(int iMode);
00204     void openTransaction(const char* name=0);
00205     // Commit the Command transaction. Do nothing If there is no Command transaction open.
00206     void commitTransaction();
00208     void abortTransaction();
00210     void setUndoLimit(unsigned int UndoMemSize=0);
00212     unsigned int getUndoMemSize (void) const;
00214     void setMaxUndoStackSize(unsigned int UndoMaxStackSize=20);
00216     unsigned int getMaxUndoStackSize(void)const;
00218     void clearUndos();
00220     int getAvailableUndos() const;
00222     std::vector<std::string> getAvailableUndoNames() const;
00224     bool undo();
00226     int getAvailableRedos() const;
00228     std::vector<std::string> getAvailableRedoNames() const;
00230     bool redo() ;
00232 
00235 
00236     void writeDependencyGraphViz(std::ostream &out);
00238     bool checkOnCycle(void);
00240     std::vector<App::DocumentObject*> getInList(const DocumentObject* me) const;
00241     // set Changed
00242     //void setChanged(DocumentObject* change);
00244 
00245     virtual PyObject *getPyObject(void);
00246 
00247     friend class Application;
00249     friend class DocumentObject;
00250     friend class Transaction;
00251     friend class TransactionObject;
00252 
00254     virtual ~Document();
00255 
00256 protected:
00258     Document(void);
00259 
00260     void _remObject(DocumentObject* pcObject);
00261     void _addObject(DocumentObject* pcObject, const char* pObjectName);
00262     DocumentObject* _copyObject(DocumentObject* obj, std::map<DocumentObject*, 
00263         DocumentObject*>&, bool recursive=false);
00264     void breakDependency(DocumentObject* pcObject, bool clear);
00265 
00266     void onChanged(const Property* prop);
00268     void onBeforeChangeProperty(const DocumentObject *Who, const Property *What);
00270     void onChangedProperty(const DocumentObject *Who, const Property *What);
00272     bool _recomputeFeature(DocumentObject* Feat);
00273     void _clearRedos();
00274 
00275 
00276 private:
00277     // # Data Member of the document +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00278     std::list<Transaction*> mUndoTransactions;
00279     std::list<Transaction*> mRedoTransactions;
00280     // recompute log
00281     std::vector<App::DocumentObjectExecReturn*> _RecomputeLog;
00282 
00283     // pointer to the python class
00284     Py::Object DocumentPythonObject;
00285     struct DocumentP* d;
00286 };
00287 
00288 template<typename T>
00289 inline std::vector<T*> Document::getObjectsOfType() const
00290 {
00291     std::vector<T*> type;
00292     std::vector<App::DocumentObject*> obj = this->getObjectsOfType(T::getClassTypeId());
00293     type.reserve(obj.size());
00294     for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it)
00295         type.push_back(static_cast<T*>(*it));
00296     return type;
00297 }
00298 
00299 
00300 } //namespace App
00301 
00302 #endif // APP_DOCUMENT_H

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