Debian Codegraph @

src/App/DocumentObserverPython.h

raw
1 /***************************************************************************
2 * Copyright (c) 2009 Werner Mayer <wmayer[at]users.sourceforge.net> *
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 #ifndef APP_DOCUMENTOBSERVERPYTHON_H
25 #define APP_DOCUMENTOBSERVERPYTHON_H
26
27 #include <FCGlobal.h>
28 #include <boost/signals2.hpp>
29 #include <CXX/Objects.hxx>
30 #include <string>
31 #include <vector>
32
33 namespace App
34 {
35
36 class Document;
37 class DocumentObject;
38 class ExtensionContainer;
39 class Property;
40
41 /**
42 * The DocumentObserverPython class is used to notify registered Python instances
43 * whenever something happens to a document, like creation, destruction, adding or
44 * removing objects or when property changes.
45 *
46 * @author Werner Mayer
47 */
48 class AppExport DocumentObserverPython
49 {
50
51 public:
52 /// Constructor
53 DocumentObserverPython(const Py::Object& obj);
54 virtual ~DocumentObserverPython();
55
56 static void addObserver(const Py::Object& obj);
57 static void removeObserver(const Py::Object& obj);
58
59 private:
60 /** Checks if a new document was created */
61 void slotCreatedDocument(const App::Document& Doc);
62 /** Checks if the given document is about to be closed */
63 void slotDeletedDocument(const App::Document& Doc);
64 /** Checks if the given document is relabeled */
65 void slotRelabelDocument(const App::Document& Doc);
66 /** Checks if the given document is activated */
67 void slotActivateDocument(const App::Document& Doc);
68 /** The property of an observed document has changed */
69 void slotBeforeChangeDocument(const App::Document& Obj, const App::Property& Prop);
70 /** The property of an observed document has changed */
71 void slotChangedDocument(const App::Document& Obj, const App::Property& Prop);
72 /** Checks if a new object was added. */
73 void slotCreatedObject(const App::DocumentObject& Obj);
74 /** Checks if the given object is about to be removed. */
75 void slotDeletedObject(const App::DocumentObject& Obj);
76 /** The property of an observed object has changed */
77 void slotBeforeChangeObject(const App::DocumentObject& Obj, const App::Property& Prop);
78 /** The property of an observed object has changed */
79 void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop);
80 /** Undoes the last transaction of the document */
81 void slotUndoDocument(const App::Document& Doc);
82 /** Redoes the last undone transaction of the document */
83 void slotRedoDocument(const App::Document& Doc);
84 /** Called when a given object is recomputed */
85 void slotRecomputedObject(const App::DocumentObject& Obj);
86 /** Called before an observed document is recomputed */
87 void slotBeforeRecomputeDocument(const App::Document& Doc);
88 /** Called when an observed document is recomputed */
89 void slotRecomputedDocument(const App::Document& Doc);
90 /** Called when an observed document opens a transaction */
91 void slotOpenTransaction(const App::Document& Doc, std::string str);
92 /** Called when an observed document commits a transaction */
93 void slotCommitTransaction(const App::Document& Doc);
94 /** Called when an observed document aborts a transaction */
95 void slotAbortTransaction(const App::Document& Doc);
96 /** Called after application wide undo */
97 void slotUndo();
98 /** Called after application wide redo */
99 void slotRedo();
100 /** Called before closing/aborting application active transaction */
101 void slotBeforeCloseTransaction(bool abort);
102 /** Called after closing/aborting application active transaction */
103 void slotCloseTransaction(bool abort);
104 /** Called when an object gets a new dynamic property added*/
105 void slotAppendDynamicProperty(const App::Property& Prop);
106 /** Called when an object gets a dynamic property removed*/
107 void slotRemoveDynamicProperty(const App::Property& Prop);
108 /** Called when an object property gets a new editor relevant status like hidden or read only*/
109 void slotChangePropertyEditor(const App::Document& Doc, const App::Property& Prop);
110 /** Called when a document is about to be saved*/
111 void slotStartSaveDocument(const App::Document&, const std::string&);
112 /** Called when an document has been saved*/
113 void slotFinishSaveDocument(const App::Document&, const std::string&);
114 /** Called before an object gets a new extension added*/
115 void slotBeforeAddingDynamicExtension(const App::ExtensionContainer&, std::string extension);
116 /** Called when an object gets a dynamic extension added*/
117 void slotAddedDynamicExtension(const App::ExtensionContainer&, std::string extension);
118
119
120 private:
121 Py::Object inst;
122 static std::vector<DocumentObserverPython*> _instances;
123
124 using Connection = struct PythonObject
125 {
126 boost::signals2::scoped_connection slot;
127 Py::Object py;
128 PyObject* ptr()
129 {
130 return py.ptr();
131 }
132 };
133
134 Connection pyCreatedDocument;
135 Connection pyDeletedDocument;
136 Connection pyRelabelDocument;
137 Connection pyActivateDocument;
138 Connection pyUndoDocument;
139 Connection pyRedoDocument;
140 Connection pyBeforeChangeDocument;
141 Connection pyChangedDocument;
142 Connection pyCreatedObject;
143 Connection pyDeletedObject;
144 Connection pyBeforeChangeObject;
145 Connection pyChangedObject;
146 Connection pyRecomputedObject;
147 Connection pyBeforeRecomputeDocument;
148 Connection pyRecomputedDocument;
149 Connection pyOpenTransaction;
150 Connection pyCommitTransaction;
151 Connection pyAbortTransaction;
152 Connection pyUndo;
153 Connection pyRedo;
154 Connection pyBeforeCloseTransaction;
155 Connection pyCloseTransaction;
156 Connection pyStartSaveDocument;
157 Connection pyFinishSaveDocument;
158 Connection pyAppendDynamicProperty;
159 Connection pyRemoveDynamicProperty;
160 Connection pyChangePropertyEditor;
161 Connection pyBeforeAddingDynamicExtension;
162 Connection pyAddedDynamicExtension;
163 };
164
165 } // namespace App
166
167 #endif // APP_DOCUMENTOBSERVERPYTHON_H