DocumentObject.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de)          *
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 #ifndef APP_DOCUMENTOBJECT_H
00025 #define APP_DOCUMENTOBJECT_H
00026 
00027 #include <App/PropertyContainer.h>
00028 #include <App/PropertyStandard.h>
00029 
00030 #include <Base/TimeInfo.h>
00031 #include <CXX/Objects.hxx>
00032 
00033 #include <bitset>
00034 
00035 
00036 namespace App
00037 {
00038 class Document;
00039 class DocumentObjectPy;
00040 
00043 class AppExport DocumentObjectExecReturn
00044 {
00045 public:
00046     DocumentObjectExecReturn(const std::string& sWhy, DocumentObject* WhichObject=0)
00047         : Why(sWhy), Which(WhichObject)
00048     {
00049     }
00050     DocumentObjectExecReturn(const char* sWhy, DocumentObject* WhichObject=0)
00051         : Which(WhichObject)
00052     {
00053         if(sWhy)
00054             Why = sWhy;
00055     }
00056 
00057     std::string Why;
00058     DocumentObject* Which;
00059 };
00060 
00061 
00062 
00065 class AppExport DocumentObject: public App::PropertyContainer
00066 {
00067     PROPERTY_HEADER(App::DocumentObject);
00068 
00069 public:
00070 
00071     PropertyString Label;
00072 
00074     virtual const char* getViewProviderName(void) const {
00075         return "";
00076     }
00078     DocumentObject(void);
00079     virtual ~DocumentObject();
00080 
00082     const char *getNameInDocument(void) const;
00084     App::Document *getDocument(void) const;
00085 
00089 
00090     void touch(void);
00092     bool isTouched(void) const {return StatusBits.test(0);}
00094     void purgeTouched(void){StatusBits.reset(0);setPropertyStatus(0,false);}
00096     bool isError(void) const {return  StatusBits.test(1);}
00097     bool isValid(void) const {return !StatusBits.test(1);}
00099     void purgeError(void){StatusBits.reset(1);}
00101     bool isRecomputing() const {return StatusBits.test(3);}
00103     bool isRestoring() const {return StatusBits.test(4);}
00105     App::DocumentObjectExecReturn *recompute(void);
00107     unsigned long getStatus() const {return StatusBits.to_ulong();}
00109 
00111     std::vector<App::DocumentObject*> getOutList(void) const;
00113     std::vector<App::DocumentObject*> getInList(void) const;
00114 
00115 
00116 public:
00125     virtual short mustExecute(void) const;
00126 
00128     const char *getStatusString(void) const;
00129 
00136     virtual void onLostLinkToObject(DocumentObject*);
00137     virtual PyObject *getPyObject(void);
00139     virtual std::vector<PyObject *> getPySubObjects(const std::vector<std::string>&) const;
00140 
00141     friend class Document;
00142     friend class Transaction;
00143     friend class ObjectExecution;
00144 
00145     static DocumentObjectExecReturn *StdReturn;
00146 
00147     virtual void Save (Base::Writer &writer) const;
00148 
00149 protected:
00157     virtual App::DocumentObjectExecReturn *execute(void);
00158 
00172     std::bitset<32> StatusBits;
00173 
00174     void setError(void){StatusBits.set(1);}
00175     void resetError(void){StatusBits.reset(1);}
00176     void setDocument(App::Document* doc);
00177 
00179     virtual void onBeforeChange(const Property* prop);
00181     virtual void onChanged(const Property* prop);
00182 
00184 protected: // attributes
00185     Py::Object PythonObject;
00187     App::Document* _pDoc;
00188 
00189     // pointer to the document name string (for performance)
00190     const std::string *pcNameInDocument;
00191 };
00192 
00193 } //namespace App
00194 
00195 
00196 #endif // APP_DOCUMENTOBJECT_H

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