Debian Codegraph @

src/Gui/ViewProviderDocumentObject.h

raw
1 /***************************************************************************
2 * Copyright (c) 2004 Jürgen Riegel <[email protected]> *
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 GUI_VIEWPROVIDER_DOCUMENTOBJECT_H
25 #define GUI_VIEWPROVIDER_DOCUMENTOBJECT_H
26
27 #include <Inventor/SoType.h>
28
29 #include "ViewProvider.h"
30 #include <App/DocumentObject.h>
31
32 class SoMaterial;
33 class SoDrawStyle;
34 class SoNode;
35 class SoType;
36
37 namespace App
38 {
39 class DocumentObject;
40 class Material;
41 } // namespace App
42
43
44 namespace Gui
45 {
46
47 class MDIView;
48 class Document;
49
50 class GuiExport ViewProviderDocumentObject: public ViewProvider
51 {
52 PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderDocumentObject);
53
54 public:
55 /// constructor.
56 ViewProviderDocumentObject();
57
58 /// destructor.
59 ~ViewProviderDocumentObject() override;
60
61 // Display properties
62 App::PropertyEnumeration DisplayMode;
63 App::PropertyBool Visibility;
64 App::PropertyBool ShowInTree;
65 App::PropertyEnumeration OnTopWhenSelected;
66 App::PropertyEnumeration SelectionStyle;
67
68 virtual void attach(App::DocumentObject* pcObject);
69 virtual void reattach(App::DocumentObject*);
70 void update(const App::Property*) override;
71 /// Set the active mode, i.e. the first item of the 'Display' property.
72 void setActiveMode();
73 /// Hide the object in the view
74 void hide() override;
75 /// Show the object in the view
76 void show() override;
77 /// Is called by the tree if the user double clicks on the object. It returns the string
78 /// for the transaction that will be shown in the undo/redo dialog.
79 /// If null is returned then no transaction will be opened.
80 const char* getTransactionText() const override;
81
82 bool canDropObjectEx(
83 App::DocumentObject*,
84 App::DocumentObject*,
85 const char*,
86 const std::vector<std::string>&
87 ) const override;
88
89 int replaceObject(App::DocumentObject*, App::DocumentObject*) override;
90
91 bool showInTree() const override;
92
93 /// Get a list of TaskBoxes associated with this object
94 void getTaskViewContent(std::vector<Gui::TaskView::TaskContent*>&) const override;
95
96 /// Run a redraw
97 void updateView();
98 /// Get the object of this ViewProvider object
99 App::DocumentObject* getObject() const
100 {
101 return pcObject;
102 }
103 /// Get the object of this ViewProvider object as specified type
104 template<class T>
105 T* getObject() const
106 {
107 return freecad_cast<T*>(pcObject);
108 }
109 /// Asks the view provider if the given object can be deleted.
110 bool canDelete(App::DocumentObject* obj) const override;
111 /// Ask the view provider if it accepts object deletions while in edit
112 virtual bool acceptDeletionsInEdit()
113 {
114 return false;
115 }
116 /// Get the GUI document to this ViewProvider object
117 Gui::Document* getDocument() const;
118 /// Get the python wrapper for that ViewProvider
119 PyObject* getPyObject() override;
120
121 /// return a hit element given the picked point which contains the full node path
122 bool getElementPicked(const SoPickedPoint*, std::string& subname) const override;
123 /// return the coin node detail and path to the node of the subname
124 bool getDetailPath(const char* subname, SoFullPath* pPath, bool append, SoDetail*& det) const override;
125
126 /* Force update visual
127 *
128 * These method exists because some view provider skips visual update when
129 * hidden (e.g. PartGui::ViewProviderPartExt). Call this function to force
130 * visual update.
131 */
132 //@{
133 virtual void forceUpdate(bool enable = true)
134 {
135 (void)enable;
136 }
137 virtual bool isUpdateForced() const
138 {
139 return false;
140 }
141 //@}
142
143 /** @name Restoring view provider from document load */
144 //@{
145 virtual void startRestoring();
146 virtual void finishRestoring();
147 //@}
148
149 /** @name Tree rank */
150 //@{
151 int getTreeRank() const
152 {
153 return treeRank;
154 }
155 void setTreeRank(int value)
156 {
157 treeRank = value;
158 }
159 //@}
160
161 bool removeDynamicProperty(const char* prop) override;
162
163 App::Property* addDynamicProperty(
164 const char* type,
165 const char* name = nullptr,
166 const char* group = nullptr,
167 const char* doc = nullptr,
168 short attr = 0,
169 bool ro = false,
170 bool hidden = false
171 ) override;
172
173 /** Return the linked view object
174 *
175 * This function is mainly used for GUI navigation (e.g.
176 * StdCmdLinkSelectLinked).
177 *
178 * @param subname: output as the subname referencing the linked object
179 * @param recursive: whether to follow the link recursively
180 *
181 * @return Returns the linked view provider. If none, it shall return
182 * itself.
183 */
184 virtual ViewProviderDocumentObject* getLinkedViewProvider(
185 std::string* subname = nullptr,
186 bool recursive = false
187 ) const;
188
189 std::string getFullName() const override;
190
191 /** Allow this class to be used as an override for the original view provider of the given object
192 *
193 * @sa App::DocumentObject::getViewProviderNameOverride()
194 */
195 virtual bool allowOverride(const App::DocumentObject&) const
196 {
197 return false;
198 }
199
200 void setShowable(bool enable);
201 bool isShowable() const;
202
203 /** Start the edit mode with ViewProvider::Default */
204 void startDefaultEditMode();
205
206 protected:
207 /*! Get the active mdi view of the document this view provider is part of.
208 @note The returned mdi view doesn't need to be a 3d view but can be e.g.
209 an image view, an SVG view or something else.
210 */
211 Gui::MDIView* getActiveView() const;
212 /*! Get the mdi view of the document this view provider is part of and
213 that is in editing mode.
214 @note In case there is no mdi view in editing mode 0 is returned.
215 If a value different to 0 is returned it is guaranteed to be a 3d view.
216 */
217 Gui::MDIView* getEditingView() const;
218 /*! Get any mdi view of the document this view provider is part of.
219 In case there is an mdi view in editing mode that contains this
220 view provider that mdi view is returned. Otherwise any other
221 3d view that contains this view provider is returned.
222 If a value different to 0 is returned it is guaranteed to be a 3d view.
223 */
224 Gui::MDIView* getInventorView() const;
225 /*! Get the mdi view of the document that contains the given \a node.
226 */
227 Gui::MDIView* getViewOfNode(SoNode* node) const;
228 /// get called before the value is changed
229 void onBeforeChange(const App::Property* prop) override;
230 /// Gets called by the container whenever a property has been changed
231 void onChanged(const App::Property* prop) override;
232 /** Searches in all view providers that are attached to an object that
233 * is part of the same document as the object this view provider is
234 * attached to for an front root of \a type.
235 * Before calling this function this view provider has to be attached
236 * to an object. The method returns after the first front root node
237 * matches. If no front root node matches, 0 is returned.
238 */
239 SoNode* findFrontRootOfType(const SoType& type) const;
240
241 /** @name Transaction handling
242 */
243 //@{
244 bool isAttachedToDocument() const override;
245 const char* detachFromDocument() override;
246
247 /// get called when a property status has changed
248 void onPropertyStatusChanged(const App::Property& prop, unsigned long oldStatus) override;
249
250 //@}
251
252 void setModeSwitch() override;
253
254 /** Adds a menu item and bind it with \ref startDefaultEditMode(). */
255 void addDefaultAction(QMenu*, const QString&);
256
257 protected:
258 App::DocumentObject* pcObject {nullptr};
259 Gui::Document* pcDocument {nullptr};
260
261 private:
262 bool _Showable = true;
263 int treeRank = -1;
264
265 std::vector<const char*> aDisplayEnumsArray;
266 std::vector<std::string> aDisplayModesArray;
267
268 friend class Document;
269 };
270
271
272 } // namespace Gui
273
274 #endif // GUI_VIEWPROVIDER_DOCUMENTOBJECT_H