Debian Codegraph @

src/App/Application.h

raw
1 /***************************************************************************
2 * Copyright (c) 2002 Jürgen Riegel <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU Library General Public License (LGPL) *
8 * as published by the Free Software Foundation; either version 2 of *
9 * the License, or (at your option) any later version. *
10 * for detail see the LICENCE text file. *
11 * *
12 * FreeCAD is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Library General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Library General Public *
18 * License along with FreeCAD; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
20 * USA *
21 * *
22 ***************************************************************************/
23
24 #ifndef SRC_APP_APPLICATION_H_
25 #define SRC_APP_APPLICATION_H_
26
27 #include <boost/signals2.hpp>
28 #include <QtCore/qtextstream.h>
29
30 #include <deque>
31 #include <vector>
32 #include <list>
33 #include <set>
34 #include <map>
35 #include <string>
36
37 #include <Base/Observer.h>
38 #include <Base/Parameter.h>
39 #include <Base/ProgressIndicator.h>
40
41 // forward declarations
42 using PyObject = struct _object;
43 using PyMethodDef = struct PyMethodDef;
44
45 namespace Base
46 {
47 class ConsoleObserverStd;
48 class ConsoleObserverFile;
49 }
50
51 namespace App
52 {
53
54 class Document;
55 class DocumentObject;
56 class ApplicationDirectories;
57 class ApplicationObserver;
58 class Property;
59 class AutoTransaction;
60 class ExtensionContainer;
61
62 enum GetLinkOption {
63 /// Get all links (both directly and in directly) linked to the given object
64 GetLinkRecursive = 1,
65 /// Get link array element instead of the array
66 GetLinkArrayElement = 2,
67 /// Get linked object instead of the link, no effect if GetLinkRecursive
68 GetLinkedObject = 4,
69 /// Get only external links, no effect if GetLinkRecursive
70 GetLinkExternal = 8,
71 };
72
73 enum class MessageOption {
74 Quiet, /**< Suppress error. */
75 Error, /**< Print an error message. */
76 Throw, /**< Throw an exception. */
77 };
78
79 struct DocumentInitFlags {
80 bool createView {true};
81 bool temporary {false};
82 };
83
84 /** The Application
85 * The root of the whole application
86 * @see App::Document
87 */
88 class AppExport Application
89 {
90
91 public:
92 //---------------------------------------------------------------------
93 // exported functions go here +++++++++++++++++++++++++++++++++++++++++
94 //---------------------------------------------------------------------
95
96 /** @name methods for document handling */
97 //@{
98 /** Creates a new document
99 * @param proposedName: a prototype name used to create the permanent Name for the document.
100 * It is converted to be like an identifier in a programming language,
101 * with no spaces and not starting with a number. This name gets also forced to be unique
102 * in this Application. You can obtain the unique name using doc.getDocumentName
103 * on the returned document.
104 * @param proposedLabel: a UTF8 name of any kind. It's that name normally shown to
105 * the user and stored in the App::Document::Label property.
106 */
107 App::Document* newDocument(const char * proposedName=nullptr, const char * proposedLabel=nullptr,
108 DocumentInitFlags CreateFlags=DocumentInitFlags());
109 /// Closes the document \a name and removes it from the application.
110 bool closeDocument(const char* name);
111 /// find a unique document name
112 std::string getUniqueDocumentName(const char *Name, bool tempDoc=false) const;
113 /// Open an existing document from a file
114 App::Document* openDocument(const char * FileName=nullptr, DocumentInitFlags initFlags = DocumentInitFlags{});
115 /** Open multiple documents
116 *
117 * @param filenames: input file names
118 * @param paths: optional input file path in case it is different from
119 * filenames (mainly used during recovery).
120 * @param labels: optional label assign to document (mainly used during recovery).
121 * @param errs: optional output error message corresponding to each input
122 * file name. If errs is given, this function will catch all
123 * Base::Exception and save the error message inside. Otherwise, it will
124 * throw on exception when opening the input files.
125 * @param createView: whether to signal Gui module to create view on restore.
126 *
127 * @return Return opened document object corresponding to each input file
128 * name, which maybe NULL if failed.
129 *
130 * This function will also open any external referenced files.
131 */
132 std::vector<Document*> openDocuments(const std::vector<std::string> &filenames,
133 const std::vector<std::string> *paths=nullptr,
134 const std::vector<std::string> *labels=nullptr,
135 std::vector<std::string> *errs=nullptr,
136 DocumentInitFlags initFlags = DocumentInitFlags{});
137 /// Retrieve the active document
138 App::Document* getActiveDocument() const;
139 /// Retrieve a named document
140 App::Document* getDocument(const char *Name) const;
141
142 /// Path matching mode for getDocumentByPath()
143 enum class PathMatchMode {
144 /// Match by resolving to absolute file path
145 MatchAbsolute = 0,
146 /** Match by absolute path first. If not found then match by resolving
147 * to canonical file path where any intermediate '.' '..' and symlinks
148 * are resolved.
149 */
150 MatchCanonical = 1,
151 /** Same as MatchCanonical, but if a document is found by canonical
152 * path match, which means the document can be resolved using two
153 * different absolute path, a warning is printed and the found document
154 * is not returned. This is to allow the caller to intentionally load
155 * the same physical file as separate documents.
156 */
157 MatchCanonicalWarning = 2,
158 };
159 /** Retrieve a document based on file path
160 *
161 * @param path: file path
162 * @param checkCanonical: file path matching mode, @sa PathMatchMode.
163 * @return Return the document found by matching with the given path
164 */
165 App::Document* getDocumentByPath(const char *path,
166 PathMatchMode checkCanonical = PathMatchMode::MatchAbsolute) const;
167
168 /// gets the (internal) name of the document
169 const char * getDocumentName(const App::Document* ) const;
170 /// get a list of all documents in the application
171 std::vector<App::Document*> getDocuments() const;
172 /// Set the active document
173 void setActiveDocument(App::Document* pDoc);
174 void setActiveDocument(const char* Name);
175 /// close all documents (without saving)
176 void closeAllDocuments();
177 /// Add pending document to open together with the current opening document
178 int addPendingDocument(const char *FileName, const char *objName, bool allowPartial);
179 /// Indicate whether the application is opening (restoring) some document
180 bool isRestoring() const;
181 /// Indicate the application is closing all document
182 bool isClosingAll() const;
183 //@}
184
185 /** @name Application-wide trandaction setting */
186 //@{
187 /** Setup a pending application-wide active transaction
188 *
189 * @param name: new transaction name
190 * @param persist: by default, if the calling code is inside any invocation
191 * of a command, it will be auto closed once all command within the current
192 * stack exists. To disable auto closing, set persist=true
193 *
194 * @return The new transaction ID.
195 *
196 * Call this function to setup an application-wide transaction. All current
197 * pending transactions of opening documents will be committed first.
198 * However, no new transaction is created by this call. Any subsequent
199 * changes in any current opening document will auto create a transaction
200 * with the given name and ID. If more than one document is changed, the
201 * transactions will share the same ID, and will be undo/redo together.
202 */
203 int setActiveTransaction(const char *name, bool persist=false);
204 /// Return the current active transaction name and ID
205 const char *getActiveTransaction(int *tid=nullptr) const;
206 /** Commit/abort current active transactions
207 *
208 * @param abort: whether to abort or commit the transactions
209 *
210 * Bsides calling this function directly, it will be called by automatically
211 * if 1) any new transaction is created with a different ID, or 2) any
212 * transaction with the current active transaction ID is either committed or
213 * aborted
214 */
215 void closeActiveTransaction(bool abort=false, int id=0);
216 //@}
217
218 // NOLINTBEGIN
219 // clang-format off
220 /** @name Signals of the Application */
221 //@{
222 /// signal on new Document
223 boost::signals2::signal<void (const Document&, bool)> signalNewDocument;
224 /// signal on document getting deleted
225 boost::signals2::signal<void (const Document&)> signalDeleteDocument;
226 /// signal on already deleted Document
227 boost::signals2::signal<void ()> signalDeletedDocument;
228 /// signal on relabeling Document (user name)
229 boost::signals2::signal<void (const Document&)> signalRelabelDocument;
230 /// signal on renaming Document (internal name)
231 boost::signals2::signal<void (const Document&)> signalRenameDocument;
232 /// signal on activating Document
233 boost::signals2::signal<void (const Document&)> signalActiveDocument;
234 /// signal on saving Document
235 boost::signals2::signal<void (const Document&)> signalSaveDocument;
236 /// signal on starting to restore Document
237 boost::signals2::signal<void (const Document&)> signalStartRestoreDocument;
238 /// signal on restoring Document
239 boost::signals2::signal<void (const Document&)> signalFinishRestoreDocument;
240 /// signal on pending reloading of a partial Document
241 boost::signals2::signal<void (const Document&)> signalPendingReloadDocument;
242 /// signal on starting to save Document
243 boost::signals2::signal<void (const Document&, const std::string&)> signalStartSaveDocument;
244 /// signal on saved Document
245 boost::signals2::signal<void (const Document&, const std::string&)> signalFinishSaveDocument;
246 /// signal on undo in document
247 boost::signals2::signal<void (const Document&)> signalUndoDocument;
248 /// signal on application wide undo
249 boost::signals2::signal<void ()> signalUndo;
250 /// signal on redo in document
251 boost::signals2::signal<void (const Document&)> signalRedoDocument;
252 /// signal on application wide redo
253 boost::signals2::signal<void ()> signalRedo;
254 /// signal before open active transaction
255 boost::signals2::signal<void (const std::string&)> signalBeforeOpenTransaction;
256 /// signal before close/abort active transaction
257 boost::signals2::signal<void (bool)> signalBeforeCloseTransaction;
258 /// signal after close/abort active transaction
259 boost::signals2::signal<void (bool)> signalCloseTransaction;
260 /// signal on show hidden items
261 boost::signals2::signal<void (const Document&)> signalShowHidden;
262 /// signal on start opening document(s)
263 boost::signals2::signal<void ()> signalStartOpenDocument;
264 /// signal on finished opening document(s)
265 boost::signals2::signal<void ()> signalFinishOpenDocument;
266 //@}
267
268
269 /** @name Signals of the document
270 * This signals are an aggregation of all document. If you only
271 * the signal of a special document connect to the document itself
272 */
273 //@{
274 /// signal before change of doc property
275 boost::signals2::signal<void (const App::Document&, const App::Property&)> signalBeforeChangeDocument;
276 /// signal on changed doc property
277 boost::signals2::signal<void (const App::Document&, const App::Property&)> signalChangedDocument;
278 /// signal on new Object
279 boost::signals2::signal<void (const App::DocumentObject&)> signalNewObject;
280 //boost::signals2::signal<void (const App::DocumentObject&)> m_sig;
281 /// signal on deleted Object
282 boost::signals2::signal<void (const App::DocumentObject&)> signalDeletedObject;
283 /// signal on changed Object
284 boost::signals2::signal<void (const App::DocumentObject&, const App::Property&)> signalBeforeChangeObject;
285 /// signal on changed Object
286 boost::signals2::signal<void (const App::DocumentObject&, const App::Property&)> signalChangedObject;
287 /// signal on relabeled Object
288 boost::signals2::signal<void (const App::DocumentObject&)> signalRelabelObject;
289 /// signal on activated Object
290 boost::signals2::signal<void (const App::DocumentObject&)> signalActivatedObject;
291 /// signal before recomputed document
292 boost::signals2::signal<void (const App::Document&)> signalBeforeRecomputeDocument;
293 /// signal on recomputed document
294 boost::signals2::signal<void (const App::Document&)> signalRecomputed;
295 /// signal on recomputed document object
296 boost::signals2::signal<void (const App::DocumentObject&)> signalObjectRecomputed;
297 // signal on opened transaction
298 boost::signals2::signal<void (const App::Document&, std::string)> signalOpenTransaction;
299 // signal a committed transaction
300 boost::signals2::signal<void (const App::Document&)> signalCommitTransaction;
301 // signal an aborted transaction
302 boost::signals2::signal<void (const App::Document&)> signalAbortTransaction;
303 //@}
304
305 /** @name Signals of property changes
306 * These signals are emitted on property additions or removal.
307 * The changed object can be any sub-class of PropertyContainer.
308 */
309 //@{
310 /// signal on adding a dynamic property
311 boost::signals2::signal<void (const App::Property&)> signalAppendDynamicProperty;
312 /// signal on renaming a dynamic property
313 boost::signals2::signal<void (const App::Property&, const char*)> signalRenameDynamicProperty;
314 /// signal on about removing a dynamic property
315 boost::signals2::signal<void (const App::Property&)> signalRemoveDynamicProperty;
316 /// signal on about changing the editor mode of a property
317 boost::signals2::signal<void (const App::Document&, const App::Property&)> signalChangePropertyEditor;
318 //@}
319
320 /** @name Signals of extension changes
321 * These signals are emitted on dynamic extension addition. Dynamic extensions are the ones added by python (c++ ones are part
322 * of the class definition, hence not dynamic)
323 * The extension in question is provided as parameter.
324 */
325 //@{
326 /// signal before adding the extension
327 boost::signals2::signal<void (const App::ExtensionContainer&, std::string extension)> signalBeforeAddingDynamicExtension;
328 /// signal after the extension was added
329 boost::signals2::signal<void (const App::ExtensionContainer&, std::string extension)> signalAddedDynamicExtension;
330 //@}
331 // clang-format off
332 // NOLINTEND
333
334
335 /** @name methods for parameter handling */
336 //@{
337 /// returns the system parameter
338 ParameterManager & GetSystemParameter();
339 /// returns the user parameter
340 ParameterManager & GetUserParameter();
341 /** Gets a parameter group by a full qualified path
342 * It's an easy method to get a group:
343 * \code
344 * // getting standard parameter
345 * ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Raytracing");
346 * std::string cDir = hGrp->GetASCII("ProjectPath", "");
347 * std::string cCameraName = hGrp->GetASCII("CameraName", "TempCamera.inc");
348 * \endcode
349 */
350 Base::Reference<ParameterGrp> GetParameterGroupByPath(const char* sName);
351
352 ParameterManager * GetParameterSet(const char* sName) const;
353 const std::map<std::string,Base::Reference<ParameterManager>> & GetParameterSetList() const;
354 void AddParameterSet(const char* sName);
355 void RemoveParameterSet(const char* sName);
356 //@}
357
358 /** @name methods for the open handler
359 * With this facility an Application module can register
360 * an ending (filetype) which it can handle to open.
361 * The ending and the module name are stored and if the file
362 * type is opened the module gets loaded and needs to register an
363 * OpenHandler class in the OpenHandlerFactorySingleton.
364 * After the module is loaded, an OpenHandler of this type is created
365 * and the file gets loaded.
366 * @see OpenHandler
367 * @see OpenHandlerFactorySingleton
368 */
369 //@{
370 /// Register an import filetype and a module name
371 void addImportType(const char* Type, const char* ModuleName);
372 /// Change the module name of a registered filetype
373 void changeImportModule(const char* Type, const char* OldModuleName, const char* NewModuleName);
374 /// Return a list of modules that support the given filetype.
375 std::vector<std::string> getImportModules(const std::string& Type) const;
376 /// Return a list of all modules.
377 std::vector<std::string> getImportModules() const;
378 /// Return a list of filetypes that are supported by a module.
379 std::vector<std::string> getImportTypes(const std::string& Module) const;
380 /// Return a list of all filetypes.
381 std::vector<std::string> getImportTypes() const;
382 /// Return the import filters with modules of a given filetype.
383 std::map<std::string, std::string> getImportFilters(const std::string& Type) const;
384 /// Return a list of all import filters.
385 std::map<std::string, std::string> getImportFilters() const;
386 //@}
387 //@{
388 /// Register an export filetype and a module name
389 void addExportType(const char* Type, const char* ModuleName);
390 /// Change the module name of a registered filetype
391 void changeExportModule(const char* Type, const char* OldModuleName, const char* NewModuleName);
392 /// Return a list of modules that support the given filetype.
393 std::vector<std::string> getExportModules(const std::string& Type) const;
394 /// Return a list of all modules.
395 std::vector<std::string> getExportModules() const;
396 /// Return a list of filetypes that are supported by a module.
397 std::vector<std::string> getExportTypes(const std::string& Module) const;
398 /// Return a list of all filetypes.
399 std::vector<std::string> getExportTypes() const;
400 /// Return the export filters with modules of a given filetype.
401 std::map<std::string, std::string> getExportFilters(const std::string& Type) const;
402 /// Return a list of all export filters.
403 std::map<std::string, std::string> getExportFilters() const;
404 //@}
405
406 /** @name Init, Destruct an Access methods */
407 //@{
408 static void init(int argc, char ** argv);
409 static void initTypes();
410 static void destruct();
411 static void destructObserver();
412 static void processCmdLineFiles();
413 static std::list<std::string> getCmdLineFiles();
414 static std::list<std::string> processFiles(const std::list<std::string>&);
415 static void runApplication();
416 friend Application &GetApplication();
417 static std::map<std::string, std::string> &Config(){return mConfig;}
418 static int GetARGC(){return _argc;}
419 static char** GetARGV(){return _argv;}
420 static int64_t applicationPid();
421 //@}
422
423 /** @name Application directories */
424 //@{
425 static std::string getHomePath();
426 static std::string getExecutableName();
427 static std::string getNameWithVersion();
428 static bool isDevelopmentVersion();
429
430 /// Access to the various directories for the program a replacement for the get*Path methods below
431 static const std::unique_ptr<ApplicationDirectories>& directories();
432
433 /*!
434 Returns the temporary directory. By default, this is set to the
435 system's temporary directory but can be customized by the user.
436 */
437 static std::string getTempPath();
438 static std::string getTempFileName(const char* FileName=nullptr);
439 static std::string getUserCachePath();
440 static std::string getUserConfigPath();
441 static std::string getUserAppDataDir();
442 static std::string getUserMacroDir();
443 static std::string getResourceDir();
444 static std::string getLibraryDir();
445 static std::string getHelpDir();
446 //@}
447
448 /** @name Verbose Information */
449 //@{
450 static void getVerboseCommonInfo(QTextStream& str, const std::map<std::string,std::string>& mConfig);
451 static void getVerboseAddOnsInfo(QTextStream& str, const std::map<std::string,std::string>& mConfig);
452 static void addModuleInfo(QTextStream& str, const QString& modPath, bool& firstMod);
453 static QString prettyProductInfoWrapper();
454 static QString getValueOrEmpty(const std::map<std::string, std::string>& map, const std::string& key);
455 static constexpr const char* verboseVersionEmitMessage{"verbose_version"};
456 //@}
457
458 /** @name Link handling */
459 //@{
460
461 /** Check for link recursion depth
462 *
463 * @param depth: current depth
464 * @param option: whether to throw exception, print an error message or quieten any output.
465 * In the latter case the caller must check the returned value.
466 *
467 * @return Return the maximum remaining depth.
468 *
469 * The function uses an internal count of all objects in all documents as
470 * the limit of recursion depth.
471 */
472 int checkLinkDepth(int depth, MessageOption option = MessageOption::Error);
473
474 /** Return the links to a given object
475 *
476 * @param obj: the linked object. If NULL, then all links are returned.
477 * @param option: @sa App::GetLinkOption
478 * @param maxCount: limit the number of links returned, 0 means no limit
479 */
480 std::set<DocumentObject*> getLinksTo(
481 const DocumentObject *, int options, int maxCount=0) const;
482
483 /// Check if there is any link to the given object
484 bool hasLinksTo(const DocumentObject *obj) const;
485 //@}
486
487 /// Gets the base progress indicator instance.
488 Base::ProgressIndicator& getProgressIndicator() { return _progressIndicator; }
489
490 friend class App::Document;
491
492 protected:
493 /// get called by the document when the name is changing
494 void renameDocument(const char *OldName, const char *NewName);
495
496 /** @name I/O of the document
497 * This slot gets connected to all App::Documents created
498 */
499 //@{
500 void slotBeforeChangeDocument(const App::Document& doc, const App::Property& prop);
501 void slotChangedDocument(const App::Document& doc, const App::Property& prop);
502 void slotNewObject(const App::DocumentObject& obj);
503 void slotDeletedObject(const App::DocumentObject& obj);
504 void slotBeforeChangeObject(const App::DocumentObject& obj, const App::Property& prop);
505 void slotChangedObject(const App::DocumentObject& obj, const App::Property& prop);
506 void slotRelabelObject(const App::DocumentObject& obj);
507 void slotActivatedObject(const App::DocumentObject& obj);
508 void slotUndoDocument(const App::Document& doc);
509 void slotRedoDocument(const App::Document& doc);
510 void slotRecomputedObject(const App::DocumentObject& obj);
511 void slotRecomputed(const App::Document& doc);
512 void slotBeforeRecompute(const App::Document& doc);
513 void slotOpenTransaction(const App::Document& doc, std::string name);
514 void slotCommitTransaction(const App::Document& doc);
515 void slotAbortTransaction(const App::Document& doc);
516 void slotStartSaveDocument(const App::Document& doc, const std::string& filename);
517 void slotFinishSaveDocument(const App::Document& doc, const std::string& filename);
518 void slotChangePropertyEditor(const App::Document& doc, const App::Property& prop);
519 //@}
520
521 /// open single document only
522 App::Document* openDocumentPrivate(const char * FileName, const char *propFileName,
523 const char *label, bool isMainDoc, DocumentInitFlags initFlags, std::vector<std::string> &&objNames);
524
525 /// Helper class for App::Document to signal on close/abort transaction
526 class AppExport TransactionSignaller {
527 public:
528 TransactionSignaller(bool abort, bool signal);
529 ~TransactionSignaller();
530 private:
531 bool abort;
532 };
533
534 private:
535 /// Constructor. The passed configuration must last for the lifetime of the constructed Application
536 // NOLINTNEXTLINE(runtime/references)
537 explicit Application(std::map<std::string, std::string> &mConfig);
538 /// Destructor
539 virtual ~Application();
540
541 static void cleanupUnits();
542
543 void setActiveDocumentNoSignal(App::Document* pDoc);
544
545 /** @name member for parameter */
546 //@{
547 static Base::Reference<ParameterManager> _pcSysParamMngr;
548 static Base::Reference<ParameterManager> _pcUserParamMngr;
549 //@}
550
551 //---------------------------------------------------------------------
552 // python exports goes here +++++++++++++++++++++++++++++++++++++++++++
553 //---------------------------------------------------------------------
554 static void setupPythonTypes();
555 static void setupPythonException(PyObject*);
556
557 // clang-format off
558 // static python wrapper of the exported functions
559 static PyObject* sGetParam (PyObject *self, PyObject *args);
560 static PyObject* sSaveParameter (PyObject *self, PyObject *args);
561 static PyObject* sGetVersion (PyObject *self, PyObject *args);
562 static PyObject* sGetConfig (PyObject *self, PyObject *args);
563 static PyObject* sSetConfig (PyObject *self, PyObject *args);
564 static PyObject* sDumpConfig (PyObject *self, PyObject *args);
565 static PyObject* sAddImportType (PyObject *self, PyObject *args);
566 static PyObject* sChangeImportModule(PyObject *self, PyObject *args);
567 static PyObject* sGetImportType (PyObject *self, PyObject *args);
568 static PyObject* sAddExportType (PyObject *self, PyObject *args);
569 static PyObject* sChangeExportModule(PyObject *self, PyObject *args);
570 static PyObject* sGetExportType (PyObject *self, PyObject *args);
571 static PyObject* sGetResourcePath (PyObject *self, PyObject *args);
572 static PyObject* sGetLibraryPath (PyObject *self, PyObject *args);
573 static PyObject* sGetTempPath (PyObject *self, PyObject *args);
574 static PyObject* sGetUserCachePath (PyObject *self, PyObject *args);
575 static PyObject* sGetUserConfigPath (PyObject *self, PyObject *args);
576 static PyObject* sGetUserAppDataPath(PyObject *self, PyObject *args);
577 static PyObject* sGetUserMacroPath (PyObject *self, PyObject *args);
578 static PyObject* sGetHelpPath (PyObject *self, PyObject *args);
579 static PyObject* sGetHomePath (PyObject *self, PyObject *args);
580
581 static PyObject* sLoadFile (PyObject *self,PyObject *args);
582 static PyObject* sOpenDocument (PyObject *self,PyObject *args, PyObject *kwd);
583 static PyObject* sSaveDocument (PyObject *self,PyObject *args);
584 static PyObject* sSaveDocumentAs (PyObject *self,PyObject *args);
585 static PyObject* sNewDocument (PyObject *self,PyObject *args, PyObject *kwd);
586 static PyObject* sCloseDocument (PyObject *self,PyObject *args);
587 static PyObject* sActiveDocument (PyObject *self,PyObject *args);
588 static PyObject* sSetActiveDocument (PyObject *self,PyObject *args);
589 static PyObject* sGetDocument (PyObject *self,PyObject *args);
590 static PyObject* sListDocuments (PyObject *self,PyObject *args);
591 static PyObject* sAddDocObserver (PyObject *self,PyObject *args);
592 static PyObject* sRemoveDocObserver (PyObject *self,PyObject *args);
593 static PyObject *sIsRestoring (PyObject *self,PyObject *args);
594
595 static PyObject *sSetLogLevel (PyObject *self,PyObject *args);
596 static PyObject *sGetLogLevel (PyObject *self,PyObject *args);
597
598 static PyObject *sCheckLinkDepth (PyObject *self,PyObject *args);
599 static PyObject *sGetLinksTo (PyObject *self,PyObject *args);
600
601 static PyObject *sGetDependentObjects(PyObject *self,PyObject *args);
602
603 static PyObject *sSetActiveTransaction (PyObject *self,PyObject *args);
604 static PyObject *sGetActiveTransaction (PyObject *self,PyObject *args);
605 static PyObject *sCloseActiveTransaction(PyObject *self,PyObject *args);
606 static PyObject *sCheckAbort(PyObject *self,PyObject *args);
607 static PyMethodDef Methods[];
608 // clang-format on
609
610 friend class ApplicationObserver;
611
612 /** @name Private Init, Destruct an Access methods */
613 //@{
614 static void initConfig(int argc, char ** argv);
615 static void initApplication();
616 static void logStatus();
617 // the one and only pointer to the application object
618 static Application *_pcSingleton;
619 /// checks if the environment is alright
620 //static void CheckEnv(void);
621 /// Search for the FreeCAD home path based on argv[0]
622 /*!
623 * There are multiple implementations of this method per-OS
624 */
625 static std::string FindHomePath(const char* sCall);
626 /// Print the help message
627 static void PrintInitHelp();
628 /// figure out some things
629 static void ExtractUserPath();
630 /// load the user and system parameter set
631 static void LoadParameters();
632 /// puts the given env variable in the config
633 static void SaveEnv(const char *);
634 /// startup configuration container
635 static std::map<std::string,std::string> mConfig;
636 /// Management of and access to applications directories
637 static std::unique_ptr<ApplicationDirectories> _appDirs;
638 static int _argc;
639 static char ** _argv;
640 //@}
641
642 struct FileTypeItem {
643 std::string filter;
644 std::string module;
645 std::vector<std::string> types;
646 };
647
648 /// open ending information
649 std::vector<FileTypeItem> _mImportTypes;
650 std::vector<FileTypeItem> _mExportTypes;
651 std::map<std::string,Document*> DocMap;
652 mutable std::map<std::string,Document*> DocFileMap;
653 std::map<std::string,Base::Reference<ParameterManager>> mpcPramManager;
654 std::map<std::string,std::string> &_mConfig;
655 App::Document* _pActiveDoc{nullptr};
656
657 std::deque<std::string> _pendingDocs;
658 std::deque<std::string> _pendingDocsReopen;
659 std::map<std::string,std::vector<std::string> > _pendingDocMap;
660
661 // To prevent infinite recursion of reloading a partial document due a truly
662 // missing object
663 std::map<std::string,std::set<std::string> > _docReloadAttempts;
664
665 bool _isRestoring{false};
666 bool _allowPartial{false};
667 bool _isClosingAll{false};
668
669 // for estimate max link depth
670 int _objCount{-1};
671
672 friend class AutoTransaction;
673
674 std::string _activeTransactionName;
675 int _activeTransactionID{0};
676 int _activeTransactionGuard{0};
677 bool _activeTransactionTmpName{false};
678
679 Base::ProgressIndicator _progressIndicator;
680
681 static Base::ConsoleObserverStd *_pConsoleObserverStd;
682 static Base::ConsoleObserverFile *_pConsoleObserverFile;
683 };
684
685 /// Singleton getter of the Application
686 inline App::Application &GetApplication(){
687 return *App::Application::_pcSingleton;
688 }
689
690 } // namespace App
691
692
693 #endif // SRC_APP_APPLICATION_H_