50 // primitive generator uses this to give initial names to primitives. |
39 // primitive generator uses this to give initial names to primitives. |
51 // |
40 // |
52 class LDDocument : public QObject, public HierarchyElement |
41 class LDDocument : public QObject, public HierarchyElement |
53 { |
42 { |
54 Q_OBJECT |
43 Q_OBJECT |
55 PROPERTY (public, QString, name, setName, STOCK_WRITE) |
|
56 PROPERTY (private, LDObjectList, objects, setObjects, STOCK_WRITE) |
|
57 PROPERTY (private, LDObjectList, cache, setCache, STOCK_WRITE) |
|
58 PROPERTY (private, History*, history, setHistory, STOCK_WRITE) |
|
59 PROPERTY (public, QString, fullPath, setFullPath, STOCK_WRITE) |
|
60 PROPERTY (public, QString, defaultName, setDefaultName, STOCK_WRITE) |
|
61 PROPERTY (public, bool, isImplicit, setImplicit, CUSTOM_WRITE) |
|
62 PROPERTY (public, long, savePosition, setSavePosition, STOCK_WRITE) |
|
63 PROPERTY (public, int, tabIndex, setTabIndex, STOCK_WRITE) |
|
64 PROPERTY (public, QList<LDPolygon>, polygonData, setPolygonData, STOCK_WRITE) |
|
65 PROPERTY (private, LDDocumentFlags, flags, setFlags, STOCK_WRITE) |
|
66 |
44 |
67 public: |
45 public: |
68 LDDocument (QObject* parent); |
46 LDDocument (QObject* parent); |
69 ~LDDocument(); |
47 ~LDDocument(); |
70 |
48 |
71 int addObject (LDObject* obj); // Adds an object to this file at the end of the file. |
49 void addHistoryStep(); |
|
50 void addKnownVertices (LDObject* obj); |
|
51 int addObject (LDObject* obj); |
72 void addObjects (const LDObjectList& objs); |
52 void addObjects (const LDObjectList& objs); |
|
53 void addToHistory (AbstractHistoryEntry* entry); |
|
54 void addToSelection (LDObject* obj); |
|
55 void clear(); |
|
56 void clearHistory(); |
73 void clearSelection(); |
57 void clearSelection(); |
74 void forgetObject (LDObject* obj); // Deletes the given object from the object chain. |
58 void close(); |
|
59 QString defaultName() const; |
|
60 void forgetObject (LDObject* obj); |
|
61 QString fullPath(); |
75 QString getDisplayName(); |
62 QString getDisplayName(); |
|
63 LDObject* getObject (int pos) const; |
|
64 int getObjectCount() const; |
76 const LDObjectList& getSelection() const; |
65 const LDObjectList& getSelection() const; |
77 bool hasUnsavedChanges() const; // Does this document have unsaved changes? |
66 LDGLData* glData(); |
|
67 bool hasUnsavedChanges() const; |
|
68 History* history() const; |
78 void initializeCachedData(); |
69 void initializeCachedData(); |
79 LDObjectList inlineContents (bool deep, bool renderinline); |
70 LDObjectList inlineContents (bool deep, bool renderinline); |
|
71 QList<LDPolygon> inlinePolygons(); |
|
72 const QVector<Vertex>& inlineVertices(); |
80 void insertObj (int pos, LDObject* obj); |
73 void insertObj (int pos, LDObject* obj); |
81 int getObjectCount() const; |
74 bool isCache() const; |
82 LDObject* getObject (int pos) const; |
75 bool isSafeToClose(); |
83 bool save (QString path = "", int64* sizeptr = null); // Saves this file to disk. |
76 void mergeVertices(); |
|
77 QString name() const; |
|
78 void needVertexMerge(); |
|
79 const LDObjectList& objects() const; |
|
80 void openForEditing(); |
|
81 const QList<LDPolygon>& polygonData() const; |
|
82 void redo(); |
|
83 void redoVertices(); |
|
84 void reloadAllSubfiles(); |
|
85 void removeFromSelection (LDObject* obj); |
|
86 bool save (QString path = "", int64* sizeptr = null); |
|
87 long savePosition() const; |
|
88 void setDefaultName (QString value); |
|
89 void setFullPath (QString value); |
|
90 void setImplicit (bool value); |
|
91 void setName (QString value); |
|
92 void setObject (int idx, LDObject* obj); |
|
93 void setSavePosition (long value); |
|
94 void setTabIndex (int value); |
84 void swapObjects (LDObject* one, LDObject* other); |
95 void swapObjects (LDObject* one, LDObject* other); |
85 bool isSafeToClose(); // Perform safety checks. Do this before closing any files! |
96 int tabIndex() const; |
86 void setObject (int idx, LDObject* obj); |
97 void undo(); |
87 QList<LDPolygon> inlinePolygons(); |
|
88 void vertexChanged (const Vertex& a, const Vertex& b); |
98 void vertexChanged (const Vertex& a, const Vertex& b); |
89 const QVector<Vertex>& inlineVertices(); |
|
90 void clear(); |
|
91 void addKnownVertices (LDObject* obj); |
|
92 void redoVertices(); |
|
93 void needVertexMerge(); |
|
94 void reloadAllSubfiles(); |
|
95 |
99 |
96 inline LDDocument& operator<< (LDObject* obj) |
100 static QString shortenName (QString a); // Turns a full path into a relative path |
97 { |
|
98 addObject (obj); |
|
99 return *this; |
|
100 } |
|
101 |
|
102 inline void addHistoryStep() |
|
103 { |
|
104 history()->addStep(); |
|
105 } |
|
106 |
|
107 inline void undo() |
|
108 { |
|
109 history()->undo(); |
|
110 } |
|
111 |
|
112 inline void redo() |
|
113 { |
|
114 history()->redo(); |
|
115 } |
|
116 |
|
117 inline void clearHistory() |
|
118 { |
|
119 history()->clear(); |
|
120 } |
|
121 |
|
122 inline void addToHistory (AbstractHistoryEntry* entry) |
|
123 { |
|
124 *history() << entry; |
|
125 } |
|
126 |
|
127 inline void dismiss() |
|
128 { |
|
129 setImplicit (true); |
|
130 } |
|
131 |
|
132 // Turns a full path into a relative path |
|
133 static QString shortenName (QString a); |
|
134 void mergeVertices(); |
|
135 |
|
136 protected: |
|
137 void addToSelection (LDObject* obj); |
|
138 void removeFromSelection (LDObject* obj); |
|
139 |
|
140 LDGLData* getGLData() |
|
141 { |
|
142 return m_gldata; |
|
143 } |
|
144 |
|
145 friend class LDObject; |
|
146 friend class GLRenderer; |
|
147 |
101 |
148 private: |
102 private: |
149 |
103 QString m_name; |
|
104 QString m_fullPath; |
|
105 QString m_defaultName; |
|
106 LDObjectList m_objects; |
|
107 History* m_history; |
|
108 bool m_isCache; |
|
109 bool m_verticesOutdated; |
|
110 bool m_needVertexMerge; |
|
111 bool m_needsReCache; // If true, next polygon inline of this document rebuilds stored polygon data. |
|
112 bool m_beingDestroyed; |
|
113 long m_savePosition; |
|
114 int m_tabIndex; |
|
115 QList<LDPolygon> m_polygonData; |
150 QMap<LDObject*, QVector<Vertex>> m_objectVertices; |
116 QMap<LDObject*, QVector<Vertex>> m_objectVertices; |
151 QVector<Vertex> m_vertices; |
117 QVector<Vertex> m_vertices; |
152 bool m_verticesOutdated; |
118 LDObjectList m_sel; |
153 bool m_needVertexMerge; |
119 LDGLData* m_gldata; |
154 LDObjectList m_sel; |
|
155 LDGLData* m_gldata; |
|
156 |
|
157 // If set to true, next polygon inline of this document discards the |
|
158 // stored polygon data and re-builds it. |
|
159 bool m_needsReCache; |
|
160 }; |
120 }; |
161 |
121 |
162 // Opens the given file as the main file. Everything is closed first. |
122 // Opens the given file as the main file. Everything is closed first. |
163 void OpenMainModel (QString path); |
123 void OpenMainModel (QString path); |
164 |
124 |