OpenLexocad  27.1
CoreApplication.h
Go to the documentation of this file.
1 #pragma once
2 #pragma warning(disable : 4251)
3 
4 #include <Base/Observer.h>
5 #include <Base/String.h>
6 
7 #include <map>
8 #include <set>
9 #include <vector>
10 #include "CA_CommandObserver.h"
11 
12 class CA_CommandObserver;
14 
15 typedef std::vector<CA_CommandObserver*> ca_CommandObserver_Vector;
16 typedef std::vector<CA_TransactionObserver*> CA_TransactionObserver_Vector;
17 
18 namespace Base
19 {
20 class MessageBase;
21 class SequencerBase;
22 } // namespace Base
23 
24 namespace Core
25 {
26 class CoreApplicationP;
27 class CoreDocument;
28 class DocObject;
29 class Property;
30 class Pythonize;
31 class CommandFactory;
32 class AutoTransaction;
33 
34 
38 class LX_CORE_EXPORT AppChanges
39 {
40 public:
41  enum why
42  {
46  } Why;
47 
48  bool operator==(const AppChanges& m) const
49  {
50  return ((this->Why == m.Why) && (this->Doc == m.Doc) && (this->CreateGui == m.CreateGui) &&
51  (this->SetAsActiveDocument == m.SetAsActiveDocument));
52  }
53 
54  Core::CoreDocument* Doc = nullptr;
55  bool CreateGui; // If true a corresponding GuiDocument gets created
56  bool SetAsActiveDocument = true; // If true when NewDocument is notified, the document will become active
57 };
58 
59 
60 class LX_CORE_EXPORT LoadedDll
61 {
62 public:
63  LoadedDll(void){};
64  virtual ~LoadedDll(void){};
65  virtual Base::String getInfo() = 0;
66  virtual void init() = 0;
67  virtual void release() = 0;
68 };
69 
70 class LX_CORE_EXPORT PartAcis : public Core::LoadedDll
71 {
72 public:
73  PartAcis(void){};
74  virtual ~PartAcis(void){};
75  virtual Base::String getInfo() = 0;
76  virtual void init() = 0;
77  virtual void release() = 0;
78  virtual Core::DocObject* create_PartGeometry(Core::CoreDocument* doc, const std::string& type) = 0;
79 };
80 
81 
82 
83 
84 #ifndef SWIG
85 // LX_CORE_EXTERN template class LX_CORE_EXPORT std::set<Base::Observer<const Core::AppChanges>*>;
86 LX_CORE_EXTERN template class LX_CORE_EXPORT std::set<CA_TransactionObserver*>;
87 LX_CORE_EXTERN template class LX_CORE_EXPORT std::set<CA_CommandObserver*>;
88 LX_CORE_EXTERN template class LX_CORE_EXPORT std::set<CoreDocument*>;
89 LX_CORE_EXTERN template class LX_CORE_EXPORT std::map<Base::String, Core::CoreDocument*>;
90 #endif
91 // LX_CORE_EXTERN template class LX_CORE_EXPORT std::list<const Core::AppChanges>;
92 
93 
94 class LX_CORE_EXPORT CoreApplication : public Base::Subject<Core::AppChanges>
95 {
96 public:
98  // //
99  // --------------------- BEGIN API --------------------- //
100  // //
101  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
102  // //
104 
105  CoreApplication(int argc, char** argv);
106  ~CoreApplication();
107 
109  static CoreApplication* instance(void);
111  static void destroy();
113  static void reset();
114 
116  Base::String getApplicationName() const;
118  void setApplicationName(const Base::String& name);
119 
121  Core::CoreDocument* newCoreDocument(const std::string& typeName, const Base::String& name = Base::String());
124  Core::CoreDocument* newDocument(const std::string& typeName,
125  const Base::String& name = Base::String(),
126  bool createGui = true,
127  bool setAsActiveDocument = true,
128  bool createDefaultObjects = true);
130  Core::CoreDocument* openCoreDocument(const std::string& typeName, const Base::String& path);
132  Core::CoreDocument* openDocument(const std::string& typeName,
133  const Base::String& path = Base::String(),
134  bool createGui = true,
135  bool savepath = true,
136  bool setAsActiveDocument = true);
138  bool closeDocument(Core::CoreDocument* doc);
140  Core::CoreDocument* getActiveDocument() const;
142  bool setActiveDocument(Core::CoreDocument* doc);
144  Core::CoreDocument* getDocumentByName(const Base::String& name);
146  std::vector<Core::CoreDocument*> getDocuments() const;
148  void closeApplication();
150  Base::String getApplicationPath() const;
153 
155  void setModulePreferenceValue(const std::string& moduleName, const std::string& key, const std::string& value);
157  std::string getModulePreferenceValue(const std::string& moduleName, const std::string& key);
158 
160  // //
161  // ---------------------- END API ---------------------- //
162  // //
164 
165 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
166 
168  bool registerCommandObserver(CA_CommandObserver* observer);
170  bool unregisterCommandObserver(CA_CommandObserver* observer);
172  ca_CommandObserver_Vector getCommandObserver();
173 
174  bool add_TransactionObserver(CA_TransactionObserver* observer);
175  bool remove_TransactionObserver(CA_TransactionObserver* observer);
176  CA_TransactionObserver_Vector getTransactionObservers();
177 
178  // Notifications
179  void notifyObject(Core::CoreDocument* doc, Core::DocObject* obj, Core::Property* pro, CA_Transaction::why transaction);
180  void notifyDocumentCreated(Core::CoreDocument* doc);
181  void notifyDocumentDeleted(Core::CoreDocument* doc);
182  void notifyDocumentRenamed(Core::CoreDocument* doc);
183  void notifyDocumentOpened(Core::CoreDocument* doc);
184  void notifyDocumentClosed(Core::CoreDocument* doc);
185  void notifyDocumentSaved(Core::CoreDocument* doc);
186  void notifyDocumentFinishedRead(Core::CoreDocument* doc);
187  void notifyDocumentChanged(Core::CoreDocument* doc, Core::Property* pro);
188  void notifyDocumentSetActive(Core::CoreDocument* doc);
189 
190  void notifyObjectCreated(Core::CoreDocument* doc, Core::DocObject* obj);
191  void notifyObjectDeleted(Core::CoreDocument* doc, Core::DocObject* obj);
192  void notifyObjectAdded(Core::CoreDocument* doc, Core::DocObject* obj);
193  void notifyObjectChanged(Core::CoreDocument* doc, Core::DocObject* obj, Core::Property* pro);
194  void notifyObjectHasError(Core::CoreDocument* doc, Core::DocObject* obj);
195 
196  void notifyPropertyCreate(Core::CoreDocument* doc, Core::DocObject* obj, Core::Property* pro);
197  void notifyPropertyChanged(Core::CoreDocument* doc, Core::DocObject* obj, Core::Property* pro);
198  void notifyPropertyDeleted(Core::CoreDocument* doc, Core::DocObject* obj, Core::Property* pro);
199 
200  void notifyRecomputeSuccess(Core::CoreDocument* doc);
201  void notifyRecomputeFailed(Core::CoreDocument* doc);
202 
203  void notifyApp(Core::CoreDocument* doc, AppChanges::why why, bool createGui, bool setAsActiveDocument = true);
204  void notifyCmdObservers(Core::CoreDocument* doc, bool createGui);
205 
207  bool closeDocument(Core::CoreDocument* doc, bool forceClose /*=false*/, bool dontNotify = false);
208 
209  // Look through the opened documents map for the tested document;
210  // this could happen when the document was closed and we just have still the pointer to removed document
211  // which is invalid
212  bool isDocumentValid(Core::CoreDocument* testedDocument) const;
213 
215  bool onClose(bool forceClose, bool dontNotify, bool& hardClose);
216  bool closeApplication(bool forceClose, bool dontNotify, bool& hardClose);
217  Base::String getUniqueDocumentName(const Base::String& s) const;
218  int getOpenDocuments(std::vector<Core::CoreDocument*>& vec);
219 
221  void initPython() const;
224  void finalizePython() const;
225 
226  bool runPythonString(const Base::String& str) const;
227  bool runPythonString(const Base::String& str, Base::String& err) const;
228  bool runPythonScript(const Base::String& scr, Base::String& err) const;
229  bool runPythonScript(const Base::String& scr) const;
230 
231  bool isClosing() const;
232  bool hasGui() const;
233  void sethasGui(bool on);
234 
235  static unsigned int getVersionYear();
236  static std::string getBuildDateTime();
237  static std::string getDocumentVersion();
238  static int getDocumentVersionAsInteger();
240  static long getRefCount();
242  void ref(void);
244  void unref(void);
245 
246  LoadedDll* loadDllByName(const Base::String& name);
247 
248  void setCommandFactory(Core::CommandFactory* commandFactory) { _commandFactory = commandFactory; }
249  Core::CommandFactory* getCommandFactory() const { return _commandFactory; }
250 
251  virtual const char* subject_name(void) { return "CoreApplication"; };
252 
253 
272  int setActiveTransaction(const char* name, bool persist = false);
274  const char* getActiveTransaction(int* tid = nullptr) const;
284  void closeActiveTransaction(bool abort = false, int id = 0);
286 
287 #endif
288 
289 protected:
290  Core::CoreDocument* _newDocument(const std::string& typeName, const Base::String& name, bool createGui);
291 
293  void deleteDocument(Core::CoreDocument* doc);
294 
296  std::map<Base::String, Core::CoreDocument*> _documentMap;
297 
298 private:
299  static void cleanOldTempDirectories();
300  //CoreApplication() {}
301  bool maybeSave(Core::CoreDocument* doc);
302  bool closeDocumentP(Core::CoreDocument* doc, bool forceClose, bool dontNotify);
303 
304  std::unique_ptr<CoreApplicationP> _pimpl = nullptr;
305  static CoreApplication* _instance;
306  Base::String _applicationName;
307  std::set<CA_CommandObserver*> _commandObserverRegistry;
308  std::set<CA_TransactionObserver*> _transactionObserverRegistry;
309  static long _refcnt;
310  Core::PartAcis* _partTool = nullptr;
311  Core::CommandFactory* _commandFactory = nullptr;
312 
313  friend class AutoTransaction;
314 
315  std::string _activeTransactionName = "";
316  int _activeTransactionID = 0;
317  int _activeTransactionGuard = 0;
318  bool _activeTransactionTmpName = false;
319 
320 };
321 
322 } // namespace Core
Definition: CoreApplication.h:70
std::vector< CA_TransactionObserver * > CA_TransactionObserver_Vector
Definition: CA_CommandObserver.h:105
Definition: CoreApplication.h:94
virtual const char * subject_name(void)
Definition: CoreApplication.h:251
Definition: CA_CommandObserver.h:58
CoreDocument()
virtual ~LoadedDll(void)
Definition: CoreApplication.h:64
Definition: CoreApplication.h:44
Definition: CoreApplication.h:60
bool operator==(const AppChanges &m) const
Definition: CoreApplication.h:48
Core::PropertyText name
Definition: CoreDocument.h:167
Definition: CA_CommandObserver.h:70
A Utf-16 (windows) or ucs4 (unix) encoded string class.
Definition: String.h:23
LoadedDll(void)
Definition: CoreApplication.h:63
Definition: CoreApplication.h:38
bool CreateGui
Definition: CoreApplication.h:55
PartAcis(void)
Definition: CoreApplication.h:73
Definition: CoreDocument.h:210
std::map< Base::String, Core::CoreDocument * > _documentMap
Map of all documents.
Definition: CoreApplication.h:296
Definition: CoreApplication.h:43
enum Core::AppChanges::why Why
virtual bool maybeSave()
Can be overwritten to check if the undo stack is clean etc.
Definition: CoreDocument.h:612
Definition: Base.h:12
why
Definition: CoreApplication.h:41
Definition: Command.h:71
Base::String getTmpDirectory()
Returns the temporary directory.
Core::CoreDocument * Doc
Definition: CoreApplication.h:54
int getDocumentVersion() const
Returns the version of the document.
basic_observer< entity > observer
Alias declaration for the most common use case.
Definition: entt.hpp:3793
std::vector< CA_CommandObserver * > ca_CommandObserver_Vector
Definition: CoreApplication.h:13
why
Definition: CA_CommandObserver.h:24
virtual ~PartAcis(void)
Definition: CoreApplication.h:74
SetActiveDocument
Definition: Globals.h:41
bool SetAsActiveDocument
Definition: CoreApplication.h:56
Definition: Property.h:77
Definition: AbstractXMLReader.h:5
std::vector< CA_CommandObserver * > ca_CommandObserver_Vector
Definition: CA_CommandObserver.h:104
friend class AutoTransaction
Definition: CoreApplication.h:313
void setCommandFactory(Core::CommandFactory *commandFactory)
Definition: CoreApplication.h:248
friend class CoreApplication
Definition: CoreDocument.h:138
Core::CommandFactory * getCommandFactory() const
Definition: CoreApplication.h:249
Definition: DocObject.h:51
std::vector< CA_TransactionObserver * > CA_TransactionObserver_Vector
Definition: CoreApplication.h:16