OpenLexocad  27.0
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 #include <Core/core_defines2.h>
7 
8 #include <map>
9 #include <set>
10 #include <vector>
11 #include "CA_CommandObserver.h"
12 
13 class CA_CommandObserver;
15 
16 typedef std::vector<CA_CommandObserver*> ca_CommandObserver_Vector;
17 typedef std::vector<CA_TransactionObserver*> CA_TransactionObserver_Vector;
18 
19 namespace Base
20 {
21 class MessageBase;
22 class SequencerBase;
23 } // namespace Base
24 
25 namespace Core
26 {
27 class CoreApplicationP;
28 class CoreDocument;
29 class DocObject;
30 class Property;
31 class Pythonize;
32 class CommandFactory;
33 
34 
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 
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 
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 // CORE_EXPIMP_TEMPLATE template class CORE_EXPORT std::set<Base::Observer<const Core::AppChanges>*>;
86 CORE_EXPIMP_TEMPLATE template class CORE_EXPORT std::set<CA_TransactionObserver*>;
87 CORE_EXPIMP_TEMPLATE template class CORE_EXPORT std::set<CA_CommandObserver*>;
88 CORE_EXPIMP_TEMPLATE template class CORE_EXPORT std::set<CoreDocument*>;
89 CORE_EXPIMP_TEMPLATE template class CORE_EXPORT std::map<Base::String, Core::CoreDocument*>;
90 #endif
91 // CORE_EXPIMP_TEMPLATE template class CORE_EXPORT std::list<const Core::AppChanges>;
92 
93 
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  void closeApplication();
148  Base::String getApplicationPath() const;
151 
153  void setModulePreferenceValue(const std::string& moduleName, const std::string& key, const std::string& value);
155  std::string getModulePreferenceValue(const std::string& moduleName, const std::string& key);
156 
158  // //
159  // ---------------------- END API ---------------------- //
160  // //
162 
163 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
164 
166  bool registerCommandObserver(CA_CommandObserver* observer);
168  bool unregisterCommandObserver(CA_CommandObserver* observer);
170  ca_CommandObserver_Vector getCommandObserver();
171 
172  bool add_TransactionObserver(CA_TransactionObserver* observer);
173  bool remove_TransactionObserver(CA_TransactionObserver* observer);
174  CA_TransactionObserver_Vector getTransactionObservers();
175 
176  // Notifications
177  void notifyObject(Core::CoreDocument* doc, Core::DocObject* obj, Core::Property* pro, CA_Transaction::why transaction);
178  void notifyDocumentCreated(Core::CoreDocument* doc);
179  void notifyDocumentDeleted(Core::CoreDocument* doc);
180  void notifyDocumentRenamed(Core::CoreDocument* doc);
181  void notifyDocumentOpened(Core::CoreDocument* doc);
182  void notifyDocumentClosed(Core::CoreDocument* doc);
183  void notifyDocumentSaved(Core::CoreDocument* doc);
184  void notifyDocumentFinishedRead(Core::CoreDocument* doc);
185  void notifyDocumentChanged(Core::CoreDocument* doc, Core::Property* pro);
186  void notifyDocumentSetActive(Core::CoreDocument* doc);
187 
188  void notifyObjectCreated(Core::CoreDocument* doc, Core::DocObject* obj);
189  void notifyObjectDeleted(Core::CoreDocument* doc, Core::DocObject* obj);
190  void notifyObjectAdded(Core::CoreDocument* doc, Core::DocObject* obj);
191  void notifyObjectChanged(Core::CoreDocument* doc, Core::DocObject* obj, Core::Property* pro);
192  void notifyObjectHasError(Core::CoreDocument* doc, Core::DocObject* obj);
193 
194  void notifyPropertyCreate(Core::CoreDocument* doc, Core::DocObject* obj, Core::Property* pro);
195  void notifyPropertyChanged(Core::CoreDocument* doc, Core::DocObject* obj, Core::Property* pro);
196  void notifyPropertyDeleted(Core::CoreDocument* doc, Core::DocObject* obj, Core::Property* pro);
197 
198  void notifyRecomputeSuccess(Core::CoreDocument* doc);
199  void notifyRecomputeFailed(Core::CoreDocument* doc);
200 
201  void notifyApp(Core::CoreDocument* doc, AppChanges::why why, bool createGui, bool setAsActiveDocument = true);
202  void notifyCmdObservers(Core::CoreDocument* doc, bool createGui);
203 
205  bool closeDocument(Core::CoreDocument* doc, bool forceClose /*=false*/, bool dontNotify = false);
207  static std::string getVersion();
208  bool onClose(bool forceClose, bool dontNotify, bool& hardClose);
209  bool closeApplication(bool forceClose, bool dontNotify, bool& hardClose);
210  Base::String getUniqueDocumentName(const Base::String& s) const;
211  int getOpenDocuments(std::vector<Core::CoreDocument*>& vec);
212 
214  void initPython() const;
217  void finalizePython();
218 
219  bool runPythonString(const Base::String& str) const;
220  bool runPythonString(const Base::String& str, Base::String& err) const;
221  bool runPythonScript(const Base::String& scr, Base::String& err) const;
222  bool runPythonScript(const Base::String& scr) const;
223 
224  bool isClosing() const;
225  bool hasGui() const;
226  void sethasGui(bool on);
227 
228  static void getVersion(int& one, int& two, int& three, int& revision);
229  static unsigned int getVersionYear();
230  static std::string getVersionStr();
231  static std::string getBuildDateTime();
232  static std::string getDocumentVersion();
233  static int getDocumentVersionAsInteger();
235  static long getRefCount();
237  void ref(void);
239  void unref(void);
240 
241  LoadedDll* loadDllByName(Base::String n);
242  LoadedDll* getPartAcis();
243 
244 
245  void setCommandFactory(Core::CommandFactory* commandFactory) { _commandFactory = commandFactory; }
246  Core::CommandFactory* getCommandFactory() const { return _commandFactory; }
247 
248  virtual const char* subject_name(void) { return "CoreApplication"; };
249 #endif
250 
251 protected:
252  Core::CoreDocument* _newDocument(const std::string& typeName, const Base::String& name, bool createGui);
253 
255  void deleteDocument(Core::CoreDocument* doc);
256 
258  std::map<Base::String, Core::CoreDocument*> _documentMap;
259 
260 private:
261  //CoreApplication() {}
262  bool maybeSave(Core::CoreDocument* doc);
263  bool closeDocumentP(Core::CoreDocument* doc, bool forceClose, bool dontNotify);
264 
265  CoreApplicationP* _pimpl = nullptr;
266  static CoreApplication* _instance;
267  Base::String _applicationName;
268  std::set<CA_CommandObserver*> _commandObserverRegistry;
269  std::set<CA_TransactionObserver*> _transactionObserverRegistry;
270  static long _refcnt;
271  Core::PartAcis* _partTool = nullptr;
272  Core::CommandFactory* _commandFactory = nullptr;
273 
274 };
275 
276 } // namespace Core
Definition: CoreApplication.h:70
std::vector< CA_TransactionObserver * > CA_TransactionObserver_Vector
Definition: CA_CommandObserver.h:107
Definition: CoreApplication.h:94
#define CORE_EXPORT
Definition: core_defines2.h:10
virtual const char * subject_name(void)
Definition: CoreApplication.h:248
Definition: CA_CommandObserver.h:60
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:143
Definition: CA_CommandObserver.h:72
A Utf-16 (windows) or ucs4 (unix) encoded string class.
Definition: String.h:29
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:197
std::map< Base::String, Core::CoreDocument * > _documentMap
Map of all documents.
Definition: CoreApplication.h:258
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:460
Definition: Base.h:19
why
Definition: CoreApplication.h:41
Definition: Command.h:61
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:14
why
Definition: CA_CommandObserver.h:26
virtual ~PartAcis(void)
Definition: CoreApplication.h:74
SetActiveDocument
Definition: Globals.h:44
bool SetAsActiveDocument
Definition: CoreApplication.h:56
Definition: Property.h:81
Definition: AbstractXMLReader.h:8
std::vector< CA_CommandObserver * > ca_CommandObserver_Vector
Definition: CA_CommandObserver.h:106
void setCommandFactory(Core::CommandFactory *commandFactory)
Definition: CoreApplication.h:245
friend class CoreApplication
Definition: CoreDocument.h:129
Core::CommandFactory * getCommandFactory() const
Definition: CoreApplication.h:246
Definition: DocObject.h:28
std::vector< CA_TransactionObserver * > CA_TransactionObserver_Vector
Definition: CoreApplication.h:17
#define CORE_EXPIMP_TEMPLATE
Definition: core_defines2.h:11