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