src/ldDocument.h

changeset 1073
a0a0d581309b
parent 1072
9ce9496427f2
child 1083
5903cfa6b4d9
equal deleted inserted replaced
1072:9ce9496427f2 1073:a0a0d581309b
20 #include <QObject> 20 #include <QObject>
21 #include "main.h" 21 #include "main.h"
22 #include "ldObject.h" 22 #include "ldObject.h"
23 #include "editHistory.h" 23 #include "editHistory.h"
24 #include "glShared.h" 24 #include "glShared.h"
25 #include "model.h"
25 26
26 class EditHistory; 27 class EditHistory;
27 class OpenProgressDialog; 28 class OpenProgressDialog;
28 struct LDGLData; 29 struct LDGLData;
29 class GLCompiler; 30 class GLCompiler;
37 // and are hidden from the user. User-opened files are explicit (not implicit). 38 // and are hidden from the user. User-opened files are explicit (not implicit).
38 // 39 //
39 // The default name is a placeholder, initially suggested name for a file. The 40 // The default name is a placeholder, initially suggested name for a file. The
40 // primitive generator uses this to give initial names to primitives. 41 // primitive generator uses this to give initial names to primitives.
41 // 42 //
42 class LDDocument : public QObject, public HierarchyElement 43 class LDDocument : public QObject, public Model, public HierarchyElement
43 { 44 {
44 Q_OBJECT 45 Q_OBJECT
45 46
46 public: 47 public:
47 enum Flag 48 enum Flag
49 IsCache = (1 << 0), 50 IsCache = (1 << 0),
50 VerticesOutdated = (1 << 1), 51 VerticesOutdated = (1 << 1),
51 NeedsVertexMerge = (1 << 2), 52 NeedsVertexMerge = (1 << 2),
52 IsBeingDestroyed = (1 << 3), 53 IsBeingDestroyed = (1 << 3),
53 NeedsRecache = (1 << 4), // The next polygon inline of this document rebuilds stored polygon data. 54 NeedsRecache = (1 << 4), // The next polygon inline of this document rebuilds stored polygon data.
54 NeedsTriangleRecount = (1 << 5),
55 }; 55 };
56 56
57 Q_DECLARE_FLAGS(Flags, Flag) 57 Q_DECLARE_FLAGS(Flags, Flag)
58 58
59 LDDocument (DocumentManager* parent); 59 LDDocument (DocumentManager* parent);
60 ~LDDocument(); 60 ~LDDocument();
61 61
62 void addHistoryStep(); 62 void addHistoryStep();
63 int addObject (LDObject* obj);
64 void addObjects (const LDObjectList& objs); 63 void addObjects (const LDObjectList& objs);
65 void addToHistory (AbstractHistoryEntry* entry); 64 void addToHistory (AbstractHistoryEntry* entry);
66 void addToSelection (LDObject* obj); 65 void addToSelection (LDObject* obj);
67 void clear();
68 void clearHistory(); 66 void clearHistory();
69 void clearSelection(); 67 void clearSelection();
70 void close(); 68 void close();
71 QString defaultName() const; 69 QString defaultName() const;
72 void forgetObject (LDObject* obj); 70 void forgetObject (LDObject* obj);
73 QString fullPath(); 71 QString fullPath();
74 QString getDisplayName(); 72 QString getDisplayName();
75 LDObject* getObject (int pos) const;
76 int getObjectCount() const; 73 int getObjectCount() const;
77 const LDObjectList& getSelection() const; 74 const QSet<LDObject*>& getSelection() const;
78 LDGLData* glData(); 75 LDGLData* glData();
79 bool hasUnsavedChanges() const; 76 bool hasUnsavedChanges() const;
80 EditHistory* history() const; 77 EditHistory* history() const;
81 void initializeCachedData(); 78 void initializeCachedData();
82 LDObjectList inlineContents (bool deep, bool renderinline); 79 void inlineContents(Model& model, bool deep, bool renderinline);
83 QList<LDPolygon> inlinePolygons(); 80 QList<LDPolygon> inlinePolygons();
84 const QSet<Vertex>& inlineVertices(); 81 const QSet<Vertex>& inlineVertices();
85 void insertObject (int pos, LDObject* obj); 82 void insertObject (int pos, LDObject* obj);
86 bool isCache() const; 83 bool isCache() const;
87 bool isSafeToClose(); 84 bool isSafeToClose();
88 QString name() const; 85 QString name() const;
89 void needVertexMerge(); 86 void needVertexMerge();
90 const LDObjectList& objects() const; 87 void objectRemoved(LDObject* object, int index);
91 void openForEditing(); 88 void openForEditing();
92 const QList<LDPolygon>& polygonData() const; 89 const QList<LDPolygon>& polygonData() const;
93 void recountTriangles(); 90 void recountTriangles();
94 void redo(); 91 void redo();
95 void redoVertices(); 92 void redoVertices();
98 bool save (QString path = "", int64* sizeptr = nullptr); 95 bool save (QString path = "", int64* sizeptr = nullptr);
99 long savePosition() const; 96 long savePosition() const;
100 void setDefaultName (QString value); 97 void setDefaultName (QString value);
101 void setFullPath (QString value); 98 void setFullPath (QString value);
102 void setName (QString value); 99 void setName (QString value);
103 void setObjectAt (int idx, LDObject* obj);
104 void setSavePosition (long value); 100 void setSavePosition (long value);
105 void setTabIndex (int value); 101 void setTabIndex (int value);
106 void swapObjects (LDObject* one, LDObject* other); 102 bool swapObjects (LDObject* one, LDObject* other);
107 int tabIndex() const; 103 int tabIndex() const;
108 int triangleCount();
109 void undo(); 104 void undo();
110 void vertexChanged (const Vertex& a, const Vertex& b); 105 void vertexChanged (const Vertex& a, const Vertex& b);
111 106
112 static QString shortenName (QString a); // Turns a full path into a relative path 107 static QString shortenName (QString a); // Turns a full path into a relative path
113 108
109 public slots:
110 void objectChanged(int position, QString before, QString after);
111
112 protected:
113 LDObject* withdrawAt(int position);
114
114 private: 115 private:
115 QString m_name; 116 QString m_name;
116 QString m_fullPath; 117 QString m_fullPath;
117 QString m_defaultName; 118 QString m_defaultName;
118 LDObjectList m_objects;
119 EditHistory* m_history; 119 EditHistory* m_history;
120 Flags m_flags; 120 Flags m_flags;
121 long m_savePosition; 121 long m_savePosition;
122 int m_tabIndex; 122 int m_tabIndex;
123 int m_triangleCount; 123 int m_triangleCount;
124 QList<LDPolygon> m_polygonData; 124 QList<LDPolygon> m_polygonData;
125 QMap<LDObject*, QSet<Vertex>> m_objectVertices; 125 QMap<LDObject*, QSet<Vertex>> m_objectVertices;
126 QSet<Vertex> m_vertices; 126 QSet<Vertex> m_vertices;
127 LDObjectList m_sel; 127 QSet<LDObject*> m_selection;
128 LDGLData* m_gldata; 128 LDGLData* m_gldata;
129 DocumentManager* m_manager; 129 DocumentManager* m_manager;
130 130
131 DEFINE_FLAG_ACCESS_METHODS(m_flags) 131 DEFINE_FLAG_ACCESS_METHODS(m_flags)
132 void addKnownVertices (LDObject* obj); 132 void addKnownVertices (LDObject* obj);

mercurial