|
1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013 - 2017 Teemu Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #pragma once |
|
20 #include <QObject> |
|
21 #include "main.h" |
|
22 #include "ldObject.h" |
|
23 #include "editHistory.h" |
|
24 #include "glShared.h" |
|
25 #include "model.h" |
|
26 |
|
27 struct LDGLData; |
|
28 class DocumentManager; |
|
29 |
|
30 // |
|
31 // This class stores a document either as a editable file for the user or for |
|
32 // subfile caching. |
|
33 // |
|
34 // A document is implicit when they are opened automatically for caching purposes |
|
35 // and are hidden from the user. User-opened files are explicit (not implicit). |
|
36 // |
|
37 // The default name is a placeholder, initially suggested name for a file. The |
|
38 // primitive generator uses this to give initial names to primitives. |
|
39 // |
|
40 class LDDocument : public Model, public HierarchyElement |
|
41 { |
|
42 Q_OBJECT |
|
43 |
|
44 public: |
|
45 LDDocument (DocumentManager* parent); |
|
46 ~LDDocument(); |
|
47 |
|
48 void addHistoryStep(); |
|
49 void addToHistory (AbstractHistoryEntry* entry); |
|
50 void addToSelection (LDObject* obj); |
|
51 void clearHistory(); |
|
52 void clearSelection(); |
|
53 void close(); |
|
54 QString defaultName() const; |
|
55 QString fullPath(); |
|
56 QString getDisplayName(); |
|
57 const QSet<LDObject*>& getSelection() const; |
|
58 bool hasUnsavedChanges() const; |
|
59 EditHistory* history() const; |
|
60 void initializeCachedData(); |
|
61 void inlineContents(Model& model, bool deep, bool renderinline); |
|
62 QList<LDPolygon> inlinePolygons(); |
|
63 const QSet<Vertex>& inlineVertices(); |
|
64 void insertObject (int pos, LDObject* obj); |
|
65 bool isFrozen() const; |
|
66 bool isSafeToClose(); |
|
67 QString name() const; |
|
68 void objectRemoved(LDObject* object, int index); |
|
69 const QList<LDPolygon>& polygonData() const; |
|
70 void recountTriangles(); |
|
71 void redo(); |
|
72 void redoVertices(); |
|
73 void reloadAllSubfiles(); |
|
74 void removeFromSelection (LDObject* obj); |
|
75 bool save (QString path = "", qint64* sizeptr = nullptr); |
|
76 long savePosition() const; |
|
77 void setDefaultName (QString value); |
|
78 void setFrozen(bool value); |
|
79 void setFullPath (QString value); |
|
80 void setName (QString value); |
|
81 void setSavePosition (long value); |
|
82 void setTabIndex (int value); |
|
83 bool swapObjects (LDObject* one, LDObject* other); |
|
84 int tabIndex() const; |
|
85 void undo(); |
|
86 void vertexChanged (const Vertex& a, const Vertex& b); |
|
87 |
|
88 static QString shortenName (QString a); // Turns a full path into a relative path |
|
89 |
|
90 public slots: |
|
91 void objectChanged(QString before, QString after); |
|
92 |
|
93 protected: |
|
94 LDObject* withdrawAt(int position); |
|
95 |
|
96 private: |
|
97 QString m_name; |
|
98 QString m_fullPath; |
|
99 QString m_defaultName; |
|
100 EditHistory* m_history; |
|
101 bool m_isFrozen = true; // Document may not be modified |
|
102 bool m_verticesOutdated = true; |
|
103 bool m_isBeingDestroyed = true; |
|
104 bool m_needsRecache = true; // The next polygon inline of this document rebuilds stored polygon data. |
|
105 long m_savePosition; |
|
106 int m_tabIndex; |
|
107 int m_triangleCount; |
|
108 QList<LDPolygon> m_polygonData; |
|
109 QMap<LDObject*, QSet<Vertex>> m_objectVertices; |
|
110 QSet<Vertex> m_vertices; |
|
111 QSet<LDObject*> m_selection; |
|
112 DocumentManager* m_manager; |
|
113 }; |
|
114 |
|
115 // Parses a string line containing an LDraw object and returns the object parsed. |
|
116 LDObject* ParseLine (QString line); |