Debian Codegraph @

src/Gui/Application.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 APPLICATION_H
25 #define APPLICATION_H
26
27 #include <QPixmap>
28 #include <map>
29 #include <string>
30
31 #include <App/Application.h>
32
33 #include "StyleParameters/ParameterManager.h"
34
35 class QCloseEvent;
36 class SoNode;
37 class NavlibInterface;
38
39 namespace Gui
40 {
41 class ApplicationPy;
42 class BaseView;
43 class CommandManager;
44 class Document;
45 class MacroManager;
46 class MDIView;
47 class MainWindow;
48 class MenuItem;
49 class PreferencePackManager;
50 class ViewProvider;
51 class ViewProviderDocumentObject;
52
53 /** The Application main class
54 * This is the central class of the GUI
55 * @author Jürgen Riegel, Werner Mayer
56 */
57 class GuiExport Application
58 {
59 public:
60 enum Status
61 {
62 UserInitiatedOpenDocument = 0
63 };
64
65 /// construction
66 explicit Application(bool GUIenabled);
67 /// destruction
68 ~Application();
69
70 /// Initializes default configuration for Style Parameter Manager
71 void initStyleParameterManager();
72
73 /** @name methods for support of files */
74 //@{
75 /// open a file
76 void open(const char* FileName, const char* Module);
77 /// import a file into the document DocName
78 void importFrom(const char* FileName, const char* DocName, const char* Module);
79 /// Export objects from the document DocName to a single file
80 void exportTo(const char* FileName, const char* DocName, const char* Module);
81 /// Reload a partial opened document
82 App::Document* reopen(App::Document* doc);
83 /// Prompt about recomputing if needed
84 static void checkForRecomputes();
85 /// Prompt about PartialRestore
86 void checkPartialRestore(App::Document* doc);
87 /// Prompt for Errors on open
88 void checkRestoreError(App::Document* doc);
89 //@}
90
91
92 /** @name methods for View handling */
93 //@{
94 /// send Messages to the active view
95 bool sendMsgToActiveView(const char* pMsg, const char** ppReturn = nullptr);
96 /// send Messages test to the active view
97 bool sendHasMsgToActiveView(const char* pMsg);
98 /// send Messages to the focused view
99 bool sendMsgToFocusView(const char* pMsg, const char** ppReturn = nullptr);
100 /// send Messages test to the focused view
101 bool sendHasMsgToFocusView(const char* pMsg);
102 /// Attach a view (get called by the FCView constructor)
103 void attachView(Gui::BaseView* pcView);
104 /// Detach a view (get called by the FCView destructor)
105 void detachView(Gui::BaseView* pcView);
106 /// get called if a view gets activated, this manage the whole activation scheme
107 void viewActivated(Gui::MDIView* pcView);
108 /// get called if a view gets closed
109 void viewClosed(Gui::MDIView* pcView);
110 /// call update to all documents and all views (costly!)
111 void onUpdate();
112 /// call update to all views of the active document
113 void updateActive();
114 /// call update to all command actions
115 void updateActions(bool delay = false);
116 //@}
117
118 /** @name Signals of the Application */
119 //@{
120 /// signal on new Document
121 boost::signals2::signal<void(const Gui::Document&, bool)> signalNewDocument;
122 /// signal on deleted Document
123 boost::signals2::signal<void(const Gui::Document&)> signalDeleteDocument;
124 /// signal on relabeling Document
125 boost::signals2::signal<void(const Gui::Document&)> signalRelabelDocument;
126 /// signal on renaming Document
127 boost::signals2::signal<void(const Gui::Document&)> signalRenameDocument;
128 /// signal on activating Document
129 boost::signals2::signal<void(const Gui::Document&)> signalActiveDocument;
130 /// signal on new Object
131 boost::signals2::signal<void(const Gui::ViewProvider&)> signalNewObject;
132 /// signal on deleted Object
133 boost::signals2::signal<void(const Gui::ViewProvider&)> signalDeletedObject;
134 /// signal on changed Object
135 boost::signals2::signal<void(const Gui::ViewProvider&, const App::Property&)> signalBeforeChangeObject;
136 /// signal on changed object property
137 boost::signals2::signal<void(const Gui::ViewProvider&, const App::Property&)> signalChangedObject;
138 /// signal on renamed Object
139 boost::signals2::signal<void(const Gui::ViewProvider&)> signalRelabelObject;
140 /// signal on activated Object
141 boost::signals2::signal<void(const Gui::ViewProvider&)> signalActivatedObject;
142 /// signal on activated workbench
143 boost::signals2::signal<void(const char*)> signalActivateWorkbench;
144 /// signal on added/removed workbench
145 boost::signals2::signal<void()> signalRefreshWorkbenches;
146 /// signal on show hidden items
147 boost::signals2::signal<void(const Gui::Document&)> signalShowHidden;
148 /// signal on activating view
149 boost::signals2::signal<void(const Gui::MDIView*)> signalActivateView;
150 /// signal on closing view
151 boost::signals2::signal<void(const Gui::MDIView*)> signalCloseView;
152 /// signal on entering in edit mode
153 boost::signals2::signal<void(const Gui::ViewProviderDocumentObject&)> signalInEdit;
154 /// signal on leaving edit mode
155 boost::signals2::signal<void(const Gui::ViewProviderDocumentObject&)> signalResetEdit;
156 /// signal on changing user edit mode
157 boost::signals2::signal<void(int)> signalUserEditModeChanged;
158 //@}
159
160 /** @name methods for Document handling */
161 //@{
162 protected:
163 /// Observer message from the Application
164 void slotNewDocument(const App::Document&, bool);
165 void slotDeleteDocument(const App::Document&);
166 void slotRelabelDocument(const App::Document&);
167 void slotRenameDocument(const App::Document&);
168 void slotActiveDocument(const App::Document&);
169 void slotShowHidden(const App::Document&);
170 void slotNewObject(const ViewProvider&);
171 void slotDeletedObject(const ViewProvider&);
172 void slotChangedObject(const ViewProvider&, const App::Property& Prop);
173 void slotRelabelObject(const ViewProvider&);
174 void slotActivatedObject(const ViewProvider&);
175 void slotInEdit(const Gui::ViewProviderDocumentObject&);
176 void slotResetEdit(const Gui::ViewProviderDocumentObject&);
177
178 public:
179 /// message when a GuiDocument is about to vanish
180 void onLastWindowClosed(Gui::Document* pcDoc);
181 /// Getter for the active document
182 Gui::Document* activeDocument() const;
183 /// Set the active document
184 void setActiveDocument(Gui::Document* pcDocument);
185 /// Getter for the editing document
186 Gui::Document* editDocument() const;
187 Gui::MDIView* editViewOfNode(SoNode* node) const;
188 /// Set editing document, which will reset editing of all other document
189 void setEditDocument(Gui::Document* pcDocument);
190 /** Retrieves a pointer to the Gui::Document whose App::Document has the name \a name.
191 * If no such document exists 0 is returned.
192 */
193 Gui::Document* getDocument(const char* name) const;
194 /** Retrieves a pointer to the Gui::Document whose App::Document matches to \a pDoc.
195 * If no such document exists 0 is returned.
196 */
197 Gui::Document* getDocument(const App::Document* pDoc) const;
198 /// Getter for the active view of the active document or null
199 Gui::MDIView* activeView() const;
200 /// Activate a view of the given type of the active document
201 void activateView(const Base::Type&, bool create = false);
202 /// Shows the associated view provider of the given object
203 void showViewProvider(const App::DocumentObject*);
204 /// Hides the associated view provider of the given object
205 void hideViewProvider(const App::DocumentObject*);
206 /// Get the view provider of the given object
207 Gui::ViewProvider* getViewProvider(const App::DocumentObject*) const;
208 /// Get the type safe view provider of the given object
209 template<typename T>
210 T* getViewProvider(const App::DocumentObject* obj) const
211 {
212 return freecad_cast<T*>(getViewProvider(obj));
213 }
214 //@}
215
216 /// true when the application shutting down
217 bool isClosing();
218
219 void checkForDeprecatedSettings();
220 void checkForPreviousCrashes();
221
222 /** @name workbench handling */
223 //@{
224 /// Activate a named workbench
225 bool activateWorkbench(const char* name);
226 QPixmap workbenchIcon(const QString&) const;
227 QString workbenchToolTip(const QString&) const;
228 QString workbenchMenuText(const QString&) const;
229 QStringList workbenches() const;
230 void setupContextMenu(const char* recipient, MenuItem*) const;
231 //@}
232
233 /** @name Appearance */
234 //@{
235 /// Activate a stylesheet
236 void setStyleSheet(const QString& qssFile, bool tiledBackground);
237 void reloadStyleSheet();
238 QString replaceVariablesInQss(const QString& qssText);
239
240 /// Set QStyle by name
241 void setStyle(const QString& name);
242 //@}
243
244 /** @name User Commands */
245 //@{
246 /// Get macro manager
247 Gui::MacroManager* macroManager();
248 /// Reference to the command manager
249 Gui::CommandManager& commandManager();
250 /// helper which create the commands
251 void createStandardOperations();
252 //@}
253
254 Gui::PreferencePackManager* prefPackManager();
255 Gui::StyleParameters::ParameterManager* styleParameterManager();
256
257 /** @name Init, Destruct an Access methods */
258 //@{
259 /// some kind of singleton
260 static Application* Instance;
261 static void initApplication();
262 static void initTypes();
263 static void initOpenInventor();
264 static void runInitGuiScript();
265 static void runApplication();
266 void tryClose(QCloseEvent* e);
267 //@}
268
269 /// get verbose DPI and style info
270 static void getVerboseDPIStyleInfo(QTextStream& str);
271
272 /// whenever GUI is about to start with the main window hidden
273 static bool hiddenMainWindow();
274 /// return the status bits
275 bool testStatus(Status pos) const;
276 /// set the status bits
277 void setStatus(Status pos, bool on);
278
279 /** @name User edit mode */
280 //@{
281 protected:
282 // the below std::map is a translation of 'EditMode' enum in ViewProvider.h
283 // to add a new edit mode, it should first be added there
284 // this is only used for GUI user interaction (menu, toolbar, Python API)
285 const std::map<int, std::pair<std::string, std::string>> userEditModes {
286 {0,
287 std::make_pair(
288 QT_TRANSLATE_NOOP("EditMode", "&Default"),
289 QT_TRANSLATE_NOOP(
290 "EditMode",
291 "The object will be edited using the mode defined internally to be "
292 "the most appropriate for the object type"
293 )
294 )},
295 {1,
296 std::make_pair(
297 QT_TRANSLATE_NOOP("EditMode", "Trans&form"),
298 QT_TRANSLATE_NOOP(
299 "EditMode",
300 "The object will have its placement editable with the "
301 "Std TransformManip command"
302 )
303 )},
304 {2,
305 std::make_pair(
306 QT_TRANSLATE_NOOP("EditMode", "Cu&tting"),
307 QT_TRANSLATE_NOOP(
308 "EditMode",
309 "This edit mode is implemented as available but "
310 "currently does not seem to be used by any object"
311 )
312 )},
313 {3,
314 std::make_pair(
315 QT_TRANSLATE_NOOP("EditMode", "&Color"),
316 QT_TRANSLATE_NOOP(
317 "EditMode",
318 "The object will have the color of its individual faces "
319 "editable with the Appearance per Face command"
320 )
321 )},
322 };
323 int userEditMode = userEditModes.begin()->first;
324
325 public:
326 std::map<int, std::pair<std::string, std::string>> listUserEditModes() const
327 {
328 return userEditModes;
329 }
330 int getUserEditMode(const std::string& mode = "") const;
331 std::pair<std::string, std::string> getUserEditModeUIStrings(int mode = -1) const;
332 bool setUserEditMode(int mode);
333 bool setUserEditMode(const std::string& mode);
334 //@}
335
336 private:
337 struct ApplicationP* d;
338 /// workbench python dictionary
339 PyObject* _pcWorkbenchDictionary;
340 NavlibInterface* pNavlibInterface;
341
342 friend class ApplicationPy;
343 };
344
345 } // namespace Gui
346
347 #endif