OpenLexocad  27.1
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 <OpenLxApp/Building.h>
34 #include <OpenLxApp/Element.h>
35 #include <OpenLxApp/Site.h>
36 #include <OpenLxApp/Space.h>
38 
39 #include <memory>
40 #include <string>
41 #include <vector>
42 
43 
44 namespace App
45 {
46 class Document;
47 }
48 
49 namespace OpenLxApp
50 {
51 class Application;
52 class DocumentObserver;
53 
60 class LX_OPENLXAPP_EXPORT Document
61 {
62 public:
63  friend class Application;
64  friend class ApplicationP;
65 
68  Base::String getName() const;
69  void setCompany(const Base::String& company);
70  void setComment(const Base::String& comment);
71  void setCreatedBy(const Base::String& createdBy);
73 
74 
75 
78  void beginEditing();
79  void endEditing();
80  bool isEditing() const;
81  void addObject(std::shared_ptr<DocObject> aObject);
82  void removeObject(std::shared_ptr<DocObject> aObject);
83  void deleteObject(std::shared_ptr<DocObject> aObject);
84  void deleteObjects(const std::vector<std::shared_ptr<DocObject>>& aObjects);
85  void copyObjectsFrom(std::shared_ptr<Document> other);
86  void recompute();
88 
91  void attachDocumentObserver(std::shared_ptr<DocumentObserver> aObserver);
92  void detachDocumentObserver(std::shared_ptr<DocumentObserver> aObserver);
94 
95  bool saveAs(const Base::String& filename);
96  bool saveAs(const Base::String& format, const Base::String& filename);
97  bool saveAs2dl(const Base::String& filename,
98  const std::vector<std::shared_ptr<Element>>& elements,
99  const Geom::Ax2& axis,
100  bool exportFacesAsLines,
101  bool forLexo2d);
102  bool saveForWeb(const Base::String& fileOrDirName, bool aSingleHtmlFile = false);
103  bool createAutomaticWedgeMesh(const Base::String& xlsFileName = Base::String(), const Base::String& fileName2dl = Base::String());
104 
105 
108  Geom::XYZ getZeropointXYZ();
109  void setZeropointXYZ(const Geom::XYZ& xyz);
110  Geom::Pnt getZeropointLok();
111  void setZeropointLok(const Geom::Pnt& pnt);
112  double getZeropointAngle();
113  void setZeropointAngle(double value);
115 
117  std::shared_ptr<Element> addVariant(const Base::String& aFileValName, const Geom::Ax2& position);
118  std::shared_ptr<Element> import2dvFile(const Base::String& aFile2dvName, const Geom::Ax2& position);
119 
122  bool runCommand(const std::string& cmdName);
123  bool runCommand(Core::Command* cmd);
124  static std::vector<std::string> getCommandNames();
126 
129  std::vector<int> getLayerNumbers() const;
130  int addLayer(const Base::String& layerName, bool isVisible = true, bool isFrozen = false);
131  bool getLayerName(int layerNumber, Base::String& layerName) const;
132  bool setLayerName(int layerNumber, const Base::String& layerName);
133  bool setLayerVisible(int layerNumber, bool isVisible);
134  bool getLayerVisible(int layerNumber, bool& isVisible) const;
135  bool setLayerFrozen(int layerNumber, bool isFrozen);
136  bool getLayerFrozen(int layerNumber, bool& isFrozen) const;
138 
141  std::shared_ptr<Element> getElementByGlobalId(const Base::GlobalId& aGlobalId);
142  std::vector<std::shared_ptr<Element>> getElements();
143  std::vector<std::shared_ptr<Element>> getElements(std::function<bool(std::shared_ptr<Element> aElement)> aFilter);
144  std::shared_ptr<Root> getRootByGlobalId(const Base::GlobalId& aGlobalId);
145  std::vector<std::shared_ptr<Root>> getRoots();
146  std::vector<std::shared_ptr<Root>> getRoots(std::function<bool(std::shared_ptr<Root> aRoot)> aFilter);
147  std::vector<std::shared_ptr<DocObject>> getObjects();
148  std::vector<std::shared_ptr<DocObject>> getObjects(std::function<bool(std::shared_ptr<DocObject> aObject)> aFilter);
149 
150  std::vector<std::shared_ptr<Element>> getElementsByBimNumber(const Base::String& componentName, bool useRegularExpression = false);
151  std::vector<std::shared_ptr<Element>> getElementsByBimColor(const int& cadworkColor);
152 
153  std::vector<std::shared_ptr<SpatialElement>> getSpatialElements();
154  std::vector<std::shared_ptr<Site>> getSites();
155  std::vector<std::shared_ptr<Building>> getBuildings();
156  std::vector<std::shared_ptr<BuildingStorey>> getBuildingStoreys();
157  std::vector<std::shared_ptr<Space>> getSpaces();
158 
159  std::shared_ptr<Element> getActiveElement();
160  std::shared_ptr<Site> getActiveSite();
161  std::shared_ptr<Building> getActiveBuilding();
162  std::shared_ptr<BuildingStorey> getActiveBuildingStorey();
164 
167  Draw::PointStyle getActivePointStyle() const;
168  Draw::CurveStyle getActiveCurveStyle() const;
169  Draw::SurfaceStyle getActiveSurfaceStyle() const;
170  Draw::TextStyle getActiveTextStyle() const;
171  Draw::DimensionStyle getActiveDimensionStyle() const;
172  Draw::CurveStyle getActiveAuxiliaryCurveStyle() const;
173  Draw::SolidStyle getActiveSpineStyle() const;
174  Draw::ExtrusionStyle getActiveExtrusionStyle() const;
175 
176  void setActivePointStyle(const Draw::PointStyle& ps);
177  void setActiveCurveStyle(const Draw::CurveStyle& cs);
178  void setActiveSurfaceStyle(const Draw::SurfaceStyle& ss);
179  void setActiveTextStyle(const Draw::TextStyle& ts);
180  void setActiveDimensionStyle(const Draw::DimensionStyle& ds);
181  void setActiveAuxiliaryCurveStyle(const Draw::CurveStyle& cs);
182  void setActiveSpineStyle(const Draw::SolidStyle& ss);
183  void setActiveExtrusionStyle(const Draw::ExtrusionStyle& ss);
185 
188  void set_WCS(const Geom::Ax2& axis);
189  void reset_WCS();
190  double getRotationZ_WCS() const;
191  Geom::Pnt getLocation_WCS() const;
192  Geom::Dir getGlobalX_WCS() const;
193  Geom::Dir getGlobalY_WCS() const;
194  Geom::Dir getGlobalZ_WCS() const;
196 
199  bool registerPythonScript(const Base::GlobalId& aScriptId, const Base::String& aScriptFilePath = L"");
201 
202  Document(const Base::String& name, const Base::String& typeName = L"");
203  Document(App::Document* appDoc, const Base::String& name);
204 
205  // semi-regular
206  explicit Document(const Document& other) { _appDoc = other._appDoc; }
207 
208  Document& operator=(const Document& other)
209  {
210  _appDoc = other._appDoc;
211  return *this;
212  }
213 
214  bool isEqual(std::shared_ptr<Document> other) const { return (*this == *other); }
215 
216 
217  // regular
218  friend bool operator==(const Document& x, const Document& y) { return x._appDoc == y._appDoc; }
219  friend bool operator!=(const Document& x, const Document& y) { return !(x == y); }
220 
221  // totally ordered
222  friend bool operator<(const Document& x, const Document& y) { return x._appDoc < y._appDoc; }
223  friend bool operator>(const Document& x, const Document& y) { return y < x; }
224  friend bool operator<=(const Document& x, const Document& y) { return !(x > y); }
225  friend bool operator>=(const Document& x, const Document& y) { return !(x < y); }
226 
227  Document(App::Document* aDoc);
228  ~Document(void);
229 
230  std::shared_ptr<DocObjectFactory> create();
231 
232  // Internal
233  static std::set<std::string> commandSet;
234 
235  Document() {}
236 
238  // For internal use only
239  static void startTimer();
240  static int stopTimer();
241  static int elapsedTime();
242  static int elapsedTimeForTextures();
243  static int elapsedTimeForLocalAxes();
244  static int getRecomputeCount();
245 
246  Core::CoreDocument* __getInternalDoc__() const;
247  static void __addTextureTimeInMS__(int ms);
248  static void __addSetLocalAxesTimeInMS__(int ms);
249  static void __addRecomputeCount__();
250  static bool is_ok_for_sdk(Core::DocObject* aObj);
252 private:
253  App::Document* _appDoc = nullptr;
254  static int timeInMS;
255  static int textureTimeInMS;
256  static int setLocalAxesTimeInMS;
257  static int recomputeCnt;
258 };
259 
260 } // 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:43
static std::set< std::string > commandSet
Definition: Document.h:233
size_t getRecomputeCount() const
get count of recomputes()
Document(const Document &other)
Definition: Document.h:206
Core::PropertyText name
Definition: CoreDocument.h:167
Core::PropertyText company
Definition: CoreDocument.h:181
A Utf-16 (windows) or ucs4 (unix) encoded string class.
Definition: String.h:23
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:182
Definition: CoreDocument.h:210
friend bool operator!=(const Document &x, const Document &y)
Definition: Document.h:219
bool addObject(Core::DocObject *e)
Adds an existing object to the document.
friend bool operator>=(const Document &x, const Document &y)
Definition: Document.h:225
Document holding all persistent DocObjects.
Definition: Document.h:60
Definition: Ax2.h:67
Definition: XYZ.h:43
Definition: Dir.h:45
friend bool operator>(const Document &x, const Document &y)
Definition: Document.h:223
Definition: GlobalId.h:29
Definition: ActiveScript.h:7
Core::PropertyText filename
Definition: CoreDocument.h:176
bool isEqual(std::shared_ptr< Document > other) const
Definition: Document.h:214
friend bool operator<=(const Document &x, const Document &y)
Definition: Document.h:224
Core::PropertyText createdBy
Definition: CoreDocument.h:177
Base::String getTmpDirectory()
Returns the temporary directory.
friend bool operator<(const Document &x, const Document &y)
Definition: Document.h:222
The one and only Application.
Definition: Application.h:49
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:218
Document & operator=(const Document &other)
Definition: Document.h:208
Definition: Command.h:34
Document()
Definition: Document.h:235
Definition: DocObject.h:51