src/ldDocument.h

changeset 978
4603d8fd063e
parent 968
4b93b7963456
child 979
880d3fe9ac7c
equal deleted inserted replaced
977:dc3ceb65cda7 978:4603d8fd063e
47 // and are hidden from the user. User-opened files are explicit (not implicit). 47 // and are hidden from the user. User-opened files are explicit (not implicit).
48 // 48 //
49 // The default name is a placeholder, initially suggested name for a file. The 49 // The default name is a placeholder, initially suggested name for a file. The
50 // primitive generator uses this to give initial names to primitives. 50 // primitive generator uses this to give initial names to primitives.
51 // 51 //
52 class LDDocument 52 class LDDocument : public QObject, public HierarchyElement
53 { 53 {
54 public: 54 Q_OBJECT
55 PROPERTY (public, QString, name, setName, STOCK_WRITE) 55 PROPERTY (public, QString, name, setName, STOCK_WRITE)
56 PROPERTY (private, LDObjectList, objects, setObjects, STOCK_WRITE) 56 PROPERTY (private, LDObjectList, objects, setObjects, STOCK_WRITE)
57 PROPERTY (private, LDObjectList, cache, setCache, STOCK_WRITE) 57 PROPERTY (private, LDObjectList, cache, setCache, STOCK_WRITE)
58 PROPERTY (private, History*, history, setHistory, STOCK_WRITE) 58 PROPERTY (private, History*, history, setHistory, STOCK_WRITE)
59 PROPERTY (public, QString, fullPath, setFullPath, STOCK_WRITE) 59 PROPERTY (public, QString, fullPath, setFullPath, STOCK_WRITE)
62 PROPERTY (public, long, savePosition, setSavePosition, STOCK_WRITE) 62 PROPERTY (public, long, savePosition, setSavePosition, STOCK_WRITE)
63 PROPERTY (public, int, tabIndex, setTabIndex, STOCK_WRITE) 63 PROPERTY (public, int, tabIndex, setTabIndex, STOCK_WRITE)
64 PROPERTY (public, QList<LDPolygon>, polygonData, setPolygonData, STOCK_WRITE) 64 PROPERTY (public, QList<LDPolygon>, polygonData, setPolygonData, STOCK_WRITE)
65 PROPERTY (private, LDDocumentFlags, flags, setFlags, STOCK_WRITE) 65 PROPERTY (private, LDDocumentFlags, flags, setFlags, STOCK_WRITE)
66 66
67 QMap<LDObject*, QVector<Vertex>> m_objectVertices;
68 QVector<Vertex> m_vertices;
69 bool m_verticesOutdated;
70 bool m_needVertexMerge;
71
72 public: 67 public:
73 LDDocument(); 68 LDDocument (QObject* parent);
74 ~LDDocument(); 69 ~LDDocument();
75 70
76 int addObject (LDObject* obj); // Adds an object to this file at the end of the file. 71 int addObject (LDObject* obj); // Adds an object to this file at the end of the file.
77 void addObjects (const LDObjectList& objs); 72 void addObjects (const LDObjectList& objs);
78 void clearSelection(); 73 void clearSelection();
132 inline void dismiss() 127 inline void dismiss()
133 { 128 {
134 setImplicit (true); 129 setImplicit (true);
135 } 130 }
136 131
137 static LDDocument* current();
138 static void setCurrent (LDDocument* f);
139 static void closeInitialFile();
140 static int countExplicitFiles();
141 static LDDocument* createNew();
142
143 // Turns a full path into a relative path 132 // Turns a full path into a relative path
144 static QString shortenName (QString a); 133 static QString shortenName (QString a);
145 static QList<LDDocument*> const& explicitDocuments();
146 void mergeVertices(); 134 void mergeVertices();
147 135
148 protected: 136 protected:
149 void addToSelection (LDObject* obj); 137 void addToSelection (LDObject* obj);
150 void removeFromSelection (LDObject* obj); 138 void removeFromSelection (LDObject* obj);
156 144
157 friend class LDObject; 145 friend class LDObject;
158 friend class GLRenderer; 146 friend class GLRenderer;
159 147
160 private: 148 private:
149
150 QMap<LDObject*, QVector<Vertex>> m_objectVertices;
151 QVector<Vertex> m_vertices;
152 bool m_verticesOutdated;
153 bool m_needVertexMerge;
161 LDObjectList m_sel; 154 LDObjectList m_sel;
162 LDGLData* m_gldata; 155 LDGLData* m_gldata;
163 156
164 // If set to true, next polygon inline of this document discards the 157 // If set to true, next polygon inline of this document discards the
165 // stored polygon data and re-builds it. 158 // stored polygon data and re-builds it.
166 bool m_needsReCache; 159 bool m_needsReCache;
167 }; 160 };
168 161
169 inline LDDocument* CurrentDocument()
170 {
171 return LDDocument::current();
172 }
173
174 // Close all current loaded files and start off blank.
175 void newFile();
176
177 // Opens the given file as the main file. Everything is closed first. 162 // Opens the given file as the main file. Everything is closed first.
178 void OpenMainModel (QString path); 163 void OpenMainModel (QString path);
179 164
180 // Finds an OpenFile by name or null if not open 165 // Finds an OpenFile by name or null if not open
181 LDDocument* FindDocument (QString name); 166 LDDocument* FindDocument (QString name);
200 // Is it safe to close all files? 185 // Is it safe to close all files?
201 bool IsSafeToCloseAll(); 186 bool IsSafeToCloseAll();
202 187
203 LDObjectList LoadFileContents (QFile* f, int* numWarnings, bool* ok = null); 188 LDObjectList LoadFileContents (QFile* f, int* numWarnings, bool* ok = null);
204 189
205 inline const LDObjectList& Selection() 190 const LDObjectList& selectedObjects();
206 {
207 return CurrentDocument()->getSelection();
208 }
209
210 void AddRecentFile (QString path); 191 void AddRecentFile (QString path);
211 void LoadLogoStuds(); 192 void LoadLogoStuds();
212 QString Basename (QString path); 193 QString Basename (QString path);
213 QString Dirname (QString path); 194 QString Dirname (QString path);
214 195

mercurial