OpenLexocad  27.0
Document.h
Go to the documentation of this file.
1 // //
3 // LEXOCAD API //
4 // //
5 // ©2005-2016 Cadwork Informatik. All rights reserved. //
6 // //
7 // ONLY INCLUDE OTHER INTERFACES! //
8 // Lexocad provides API Classes for public use and //
9 // Implementation Classes for private use. //
10 // //
11 // - Do ONLY include and use the LEXOCAD API in this header. //
12 // - Do not change existing interfaces. //
13 // - Document your code! //
14 // //
15 // - All types from Base, Core, Geom, Topo are allowed here. //
16 // - In the Gui modules the use of Qt types is allowed. //
17 // //
19 
20 #pragma once
21 
22 #include <Base/String.h>
23 #include <Core/Command.h>
24 #include <Draw/CurveStyle.h>
25 #include <Draw/DimensionStyle.h>
26 #include <Draw/ExtrusionStyle.h>
27 #include <Draw/PointStyle.h>
28 #include <Draw/SolidStyle.h>
29 #include <Draw/SurfaceStyle.h>
30 #include <Draw/TextStyle.h>
31 #include <LxIfc4/IFC4_impl/LxIfc4EntityEnums.h>
32 #include <OpenLxApp/Building.h>
35 #include <OpenLxApp/Element.h>
37 #include <OpenLxApp/Site.h>
38 #include <OpenLxApp/Space.h>
40 
41 #include <memory>
42 #include <string>
43 #include <vector>
44 
45 
46 namespace App
47 {
48 class Document;
49 }
50 
51 namespace OpenLxApp
52 {
53 class Application;
54 class DocumentObserver;
55 
63 {
64 public:
65  friend class Application;
66  friend class ApplicationP;
67 
70  Base::String getName() const;
71  void setCompany(const Base::String& company);
72  void setComment(const Base::String& comment);
73  void setCreatedBy(const Base::String& createdBy);
75 
76 
77 
80  void beginEditing();
81  void endEditing();
82  bool isEditing() const;
83  void addObject(std::shared_ptr<DocObject> aObject);
84  void removeObject(std::shared_ptr<DocObject> aObject);
85  void deleteObject(std::shared_ptr<DocObject> aObject);
86  void deleteObjects(const std::vector<std::shared_ptr<DocObject>>& aObjects);
87  void copyObjectsFrom(std::shared_ptr<Document> other);
88  void recompute();
90 
93  void attachDocumentObserver(std::shared_ptr<DocumentObserver> aObserver);
94  void detachDocumentObserver(std::shared_ptr<DocumentObserver> aObserver);
96 
97  bool saveAs(const Base::String& filename);
98  bool saveAs(const Base::String& format, const Base::String& filename);
99  bool saveAs2dl(const Base::String& filename,
100  const std::vector<std::shared_ptr<Element>>& elements,
101  const Geom::Ax2& axis,
102  bool exportFacesAsLines,
103  bool forLexo2d);
104  bool saveForWeb(const Base::String& fileOrDirName, bool aSingleHtmlFile = false);
105  bool createAutomaticWedgeMesh(const Base::String& xlsFileName = Base::String(), const Base::String& fileName2dl = Base::String());
106 
107 
110  Geom::XYZ getZeropointXYZ();
111  void setZeropointXYZ(const Geom::XYZ& xyz);
112  Geom::Pnt getZeropointLok();
113  void setZeropointLok(const Geom::Pnt& pnt);
114  double getZeropointAngle();
115  void setZeropointAngle(double value);
117 
119  std::shared_ptr<Element> addVariant(const Base::String& aFileValName, const Geom::Ax2& position);
120  std::shared_ptr<Element> import2dvFile(const Base::String& aFile2dvName, const Geom::Ax2& position);
121 
124  bool runCommand(const std::string& cmdName);
125  bool runCommand(Core::Command* cmd);
126  static std::vector<std::string> getCommandNames();
128 
131  std::vector<int> getLayerNumbers() const;
132  int addLayer(const Base::String& layerName, bool isVisible = true, bool isFrozen = false);
133  bool getLayerName(int layerNumber, Base::String& layerName) const;
134  bool setLayerName(int layerNumber, const Base::String& layerName);
135  bool setLayerVisible(int layerNumber, bool isVisible);
136  bool getLayerVisible(int layerNumber, bool& isVisible) const;
137  bool setLayerFrozen(int layerNumber, bool isFrozen);
138  bool getLayerFrozen(int layerNumber, bool& isFrozen) const;
140 
143  std::shared_ptr<Element> getElementByGlobalId(const Base::GlobalId& aGlobalId);
144  std::vector<std::shared_ptr<Element>> getElements();
145  std::vector<std::shared_ptr<Element>> getElements(std::function<bool(std::shared_ptr<Element> aElement)> aFilter);
146  std::shared_ptr<Root> getRootByGlobalId(const Base::GlobalId& aGlobalId);
147  std::vector<std::shared_ptr<Root>> getRoots();
148  std::vector<std::shared_ptr<Root>> getRoots(std::function<bool(std::shared_ptr<Root> aRoot)> aFilter);
149  std::vector<std::shared_ptr<DocObject>> getObjects();
150  std::vector<std::shared_ptr<DocObject>> getObjects(std::function<bool(std::shared_ptr<DocObject> aObject)> aFilter);
151 
152  std::vector<std::shared_ptr<Element>> getElementsByBimNumber(const Base::String& componentName, bool useRegularExpression = false);
153  std::vector<std::shared_ptr<Element>> getElementsByBimColor(const int& cadworkColor);
154 
155  std::vector<std::shared_ptr<SpatialElement>> getSpatialElements();
156  std::vector<std::shared_ptr<Site>> getSites();
157  std::vector<std::shared_ptr<Building>> getBuildings();
158  std::vector<std::shared_ptr<BuildingStorey>> getBuildingStoreys();
159  std::vector<std::shared_ptr<Space>> getSpaces();
160 
161  std::shared_ptr<Element> getActiveElement();
162  std::shared_ptr<Site> getActiveSite();
163  std::shared_ptr<Building> getActiveBuilding();
164  std::shared_ptr<BuildingStorey> getActiveBuildingStorey();
166 
169  Draw::PointStyle getActivePointStyle() const;
170  Draw::CurveStyle getActiveCurveStyle() const;
171  Draw::SurfaceStyle getActiveSurfaceStyle() const;
172  Draw::TextStyle getActiveTextStyle() const;
173  Draw::DimensionStyle getActiveDimensionStyle() const;
174  Draw::CurveStyle getActiveAuxiliaryCurveStyle() const;
175  Draw::SolidStyle getActiveSpineStyle() const;
176  Draw::ExtrusionStyle getActiveExtrusionStyle() const;
177 
178  void setActivePointStyle(const Draw::PointStyle& ps);
179  void setActiveCurveStyle(const Draw::CurveStyle& cs);
180  void setActiveSurfaceStyle(const Draw::SurfaceStyle& ss);
181  void setActiveTextStyle(const Draw::TextStyle& ts);
182  void setActiveDimensionStyle(const Draw::DimensionStyle& ds);
183  void setActiveAuxiliaryCurveStyle(const Draw::CurveStyle& cs);
184  void setActiveSpineStyle(const Draw::SolidStyle& ss);
185  void setActiveExtrusionStyle(const Draw::ExtrusionStyle& ss);
187 
190  void set_WCS(const Geom::Ax2& axis);
191  void reset_WCS();
192  double getRotationZ_WCS() const;
193  Geom::Pnt getLocation_WCS() const;
194  Geom::Dir getGlobalX_WCS() const;
195  Geom::Dir getGlobalY_WCS() const;
196  Geom::Dir getGlobalZ_WCS() const;
198 
201  bool registerPythonScript(const Base::GlobalId& aScriptId, const Base::String& aScriptFilePath = L"");
203 
204  Document(const Base::String& name, const Base::String& typeName = L"");
205  Document(App::Document* appDoc, const Base::String& name);
206 
207  // semi-regular
208  explicit Document(const Document& other) { _appDoc = other._appDoc; }
209 
210  Document& operator=(const Document& other)
211  {
212  _appDoc = other._appDoc;
213  return *this;
214  }
215 
216  bool isEqual(std::shared_ptr<Document> other) const { return (*this == *other); }
217 
218 
219  // regular
220  friend bool operator==(const Document& x, const Document& y) { return x._appDoc == y._appDoc; }
221  friend bool operator!=(const Document& x, const Document& y) { return !(x == y); }
222 
223  // totally ordered
224  friend bool operator<(const Document& x, const Document& y) { return x._appDoc < y._appDoc; }
225  friend bool operator>(const Document& x, const Document& y) { return y < x; }
226  friend bool operator<=(const Document& x, const Document& y) { return !(x > y); }
227  friend bool operator>=(const Document& x, const Document& y) { return !(x < y); }
228 
229  Document(App::Document* aDoc);
230  ~Document(void);
231 
232  std::shared_ptr<DocObjectFactory> create();
233 
234  // Internal
235  static std::set<std::string> commandSet;
236 
237  Document() {}
238 
240  // For internal use only
241  static void startTimer();
242  static int stopTimer();
243  static int elapsedTime();
244  static int elapsedTimeForTextures();
245  static int elapsedTimeForLocalAxes();
246  static int getRecomputeCount();
247 
248  Core::CoreDocument* __getInternalDoc__() const;
249  static void __addTextureTimeInMS__(int ms);
250  static void __addSetLocalAxesTimeInMS__(int ms);
251  static void __addRecomputeCount__();
252  static bool is_ok_for_sdk(Core::DocObject* aObj);
254 private:
255  App::Document* _appDoc = nullptr;
256  static int timeInMS;
257  static int textureTimeInMS;
258  static int setLocalAxesTimeInMS;
259  static int recomputeCnt;
260 };
261 
262 } // namespace OpenLxApp
virtual void recompute()
Recomputes the document.
void removeObject(Core::DocObject *e)
Removes an object from the document.
Defines a non-persistent 3D Cartesian point.
Definition: Pnt.h:42
static std::set< std::string > commandSet
Definition: Document.h:235
size_t getRecomputeCount() const
get count of recomputes()
Document(const Document &other)
Definition: Document.h:208
Core::PropertyText name
Definition: CoreDocument.h:143
Core::PropertyText company
Definition: CoreDocument.h:156
A Utf-16 (windows) or ucs4 (unix) encoded string class.
Definition: String.h:29
virtual void deleteObject(Core::DocObject *o)
Physically deletes an object without informing the object maps.
virtual bool saveAs(const Base::String &filename)
Saves the document under this name.
Core::PropertyText comment
Definition: CoreDocument.h:157
Definition: CoreDocument.h:197
friend bool operator!=(const Document &x, const Document &y)
Definition: Document.h:221
bool addObject(Core::DocObject *e)
Adds an existing object to the document.
friend bool operator>=(const Document &x, const Document &y)
Definition: Document.h:227
Document holding all persistent DocObjects.
Definition: Document.h:62
Definition: Ax2.h:69
Definition: XYZ.h:46
#define OPENLXAPP_EXPORT
Definition: OpenLxApp_defines.h:12
Definition: Dir.h:46
friend bool operator>(const Document &x, const Document &y)
Definition: Document.h:225
Definition: GlobalId.h:32
Definition: ActiveScript.h:9
Core::PropertyText filename
Definition: CoreDocument.h:151
bool isEqual(std::shared_ptr< Document > other) const
Definition: Document.h:216
friend bool operator<=(const Document &x, const Document &y)
Definition: Document.h:226
Core::PropertyText createdBy
Definition: CoreDocument.h:152
Base::String getTmpDirectory()
Returns the temporary directory.
friend bool operator<(const Document &x, const Document &y)
Definition: Document.h:224
The one and only Application.
Definition: Application.h:50
std::vector< Core::DocObject * > getObjects(bool includeDeletedObjects=false) const
Returns all objects in the document.
friend bool operator==(const Document &x, const Document &y)
Definition: Document.h:220
Document & operator=(const Document &other)
Definition: Document.h:210
Definition: Command.h:35
Document()
Definition: Document.h:237
Definition: DocObject.h:28