~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/App/DocumentObject.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
Import upstream version 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) J�rgen Riegel          (juergen.riegel@web.de)          *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  is distributed in the hope that it will be useful,      *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
 
 
25
 
 
26
#ifndef APP_DOCUMENTOBJECT_H
 
27
#define APP_DOCUMENTOBJECT_H
 
28
 
 
29
#include <App/PropertyContainer.h>
 
30
#include <App/PropertyStandard.h>
 
31
 
 
32
#include <Base/TimeInfo.h>
 
33
#include <CXX/Objects.hxx>
 
34
 
 
35
#include <bitset>
 
36
 
 
37
 
 
38
namespace App
 
39
{
 
40
class Document;
 
41
class DocumentObjectPy;
 
42
 
 
43
/** Return object for feature execution
 
44
*/
 
45
class AppExport DocumentObjectExecReturn
 
46
{
 
47
public:
 
48
    DocumentObjectExecReturn(const std::string& sWhy, DocumentObject* WhichObject=0)
 
49
        : Why(sWhy), Which(WhichObject)
 
50
    {
 
51
    }
 
52
    DocumentObjectExecReturn(const char* sWhy, DocumentObject* WhichObject=0)
 
53
        : Which(WhichObject)
 
54
    {
 
55
        if(sWhy)
 
56
            Why = sWhy;
 
57
    }
 
58
 
 
59
    std::string Why;
 
60
    DocumentObject* Which;
 
61
};
 
62
 
 
63
 
 
64
 
 
65
/** Base class of all Classes handled in the Document
 
66
 */
 
67
class AppExport DocumentObject: public App::PropertyContainer
 
68
{
 
69
    PROPERTY_HEADER(App::DocumentObject);
 
70
 
 
71
public:
 
72
 
 
73
    PropertyString Label;
 
74
 
 
75
    /// returns the type name of the ViewProvider
 
76
    virtual const char* getViewProviderName(void) const {
 
77
        return "";
 
78
    }
 
79
    /// Constructor
 
80
    DocumentObject(void);
 
81
    virtual ~DocumentObject();
 
82
 
 
83
 
 
84
    /// returns the name which is set in the document for this object (not the Name propertie!)
 
85
    const char *getNameInDocument(void) const;
 
86
    /// gets the document in which this Object is handled
 
87
    App::Document *getDocument(void) const;
 
88
 
 
89
    /** Set the property touched -> changed, cause recomputation in Update()
 
90
     */
 
91
    //@{
 
92
    /// set this feature touched (cause recomputation on depndend features)
 
93
    void touch(void);
 
94
    /// test if this feature is touched 
 
95
    bool isTouched(void) const {return StatusBits.test(0);}
 
96
    /// reset this feature touched 
 
97
    void purgeTouched(void){StatusBits.reset(0);setPropertyStatus(0,false);}
 
98
    /// set this feature to error 
 
99
    bool isError(void) const {return  StatusBits.test(1);}
 
100
    bool isValid(void) const {return !StatusBits.test(1);}
 
101
    /// remove the error from the object
 
102
    void purgeError(void){StatusBits.reset(1);}
 
103
    //@}
 
104
 
 
105
    /** get called by the document to recompute this feature
 
106
      * Normaly this methode get called in the processing of 
 
107
      * Document::recompute(). 
 
108
      * In execute() the outpupt properties get recomputed
 
109
      * with the data from linked objects and objects own 
 
110
      * properties.
 
111
      */
 
112
    virtual App::DocumentObjectExecReturn *execute(void);
 
113
 
 
114
    /** mustExecute
 
115
     *  We call this method to check if the object was modified to
 
116
     *  be invoked. If the object label or an argument is modified.
 
117
     *  If we must recompute the object - to call the method execute().
 
118
     *  0: no recompution is needed
 
119
     *  1: recompution needed
 
120
     * -1: the document examine all links of this object and if one is touched -> recompute
 
121
     */ 
 
122
    virtual short mustExecute(void) const;
 
123
 
 
124
 
 
125
    /// get the status Message
 
126
    const char *getStatusString(void) const;//{return _cStatusMessage.c_str();}
 
127
 
 
128
 
 
129
 
 
130
    /** Called in case of losing a link
 
131
     * Get called by the document when a object got deleted a link property of this 
 
132
     * object ist pointing to. The standard behaivour of the DocumentObject implementation 
 
133
     * is to reset the links to nothing. You may overide this methode to implement 
 
134
     *additional or different behavior.
 
135
     */
 
136
    virtual void onLoseLinkToObject(DocumentObject*);
 
137
    virtual PyObject *getPyObject(void);
 
138
 
 
139
    friend class Document;
 
140
    friend class Transaction;
 
141
 
 
142
    static DocumentObjectExecReturn *StdReturn;
 
143
 
 
144
    virtual void Save (Base::Writer &writer) const;
 
145
 
 
146
 
 
147
protected:
 
148
 
 
149
    /** status bits of the document object
 
150
     * the first 8 bits are used for the base system
 
151
     * the rest can be used in descendend classes to 
 
152
     * to mark special stati on the objects
 
153
     */
 
154
    std::bitset<32> StatusBits;
 
155
 
 
156
    void setError(void){StatusBits.set(1);}
 
157
    void resetError(void){StatusBits.reset(1);}
 
158
    void setDocument(App::Document* doc);
 
159
    
 
160
    /// get called befor the value is changed
 
161
    virtual void onBeforeChange(const Property* prop);
 
162
    /// get called by the container when a property was changed
 
163
    virtual void onChanged(const Property* prop);
 
164
 
 
165
     /// python object of this class and all descendend
 
166
protected: // attributes
 
167
    Py::Object PythonObject;
 
168
    /// pointer to the document this object belongs to
 
169
    App::Document* _pDoc;
 
170
 
 
171
    // pointer to the document name string (for performance)
 
172
    const std::string *pcNameInDocument;
 
173
};
 
174
 
 
175
} //namespace App
 
176
 
 
177
 
 
178
#endif // APP_DOCUMENTOBJECT_H