57 |
57 |
58 public: |
58 public: |
59 typedef vector<LDObject*>::it it; |
59 typedef vector<LDObject*>::it it; |
60 typedef vector<LDObject*>::c_it c_it; |
60 typedef vector<LDObject*>::c_it c_it; |
61 |
61 |
62 LDOpenFile (); |
62 LDOpenFile(); |
63 ~LDOpenFile (); |
63 ~LDOpenFile(); |
64 |
64 |
65 // Saves this file to disk. |
65 // Saves this file to disk. |
66 bool save (str zPath = ""); |
66 bool save (str zPath = ""); |
67 |
67 |
68 // Perform safety checks. Do this before closing any files! |
68 // Perform safety checks. Do this before closing any files! |
69 bool safeToClose (); |
69 bool safeToClose(); |
70 |
70 |
71 // Adds an object to this file at the end of the file. |
71 // Adds an object to this file at the end of the file. |
72 ulong addObject (LDObject* obj); |
72 ulong addObject (LDObject* obj); |
73 |
73 |
74 // Deletes the given object from the object chain. |
74 // Deletes the given object from the object chain. |
75 void forgetObject (LDObject* obj); |
75 void forgetObject (LDObject* obj); |
76 |
76 |
77 LDObject* object (ulong pos) const; |
77 LDObject* object (ulong pos) const; |
78 LDObject* obj (ulong pos) const { return object (pos); } |
78 LDObject* obj (ulong pos) const { |
|
79 return object (pos); |
|
80 } |
79 |
81 |
80 void insertObj (const ulong pos, LDObject* obj); |
82 void insertObj (const ulong pos, LDObject* obj); |
81 ulong numObjs () const { return m_objs.size (); } |
83 ulong numObjs() const { |
|
84 return m_objs.size(); |
|
85 } |
82 void setObject (ulong idx, LDObject* obj); |
86 void setObject (ulong idx, LDObject* obj); |
83 |
87 |
84 LDOpenFile& operator<< (LDObject* obj) { |
88 LDOpenFile& operator<< (LDObject* obj) { |
85 addObject (obj); |
89 addObject (obj); |
86 return *this; |
90 return *this; |
87 } |
91 } |
88 |
92 |
89 LDOpenFile& operator<<( vector<LDObject*> objs ); |
93 LDOpenFile& operator<< (vector<LDObject*> objs); |
90 |
94 |
91 it begin () { return PROP_NAME( objs ).begin(); } |
95 it begin() { |
92 c_it begin () const { return PROP_NAME( objs ).begin(); } |
96 return PROP_NAME (objs).begin(); |
93 it end () { return PROP_NAME( objs ).end(); } |
97 } |
94 c_it end () const { return PROP_NAME( objs ).end(); } |
98 |
95 |
99 c_it begin() const { |
96 static void closeUnused (); |
100 return PROP_NAME (objs).begin(); |
97 |
101 } |
98 void openHistory() { m_history.open (); } |
102 |
99 void closeHistory() { m_history.close (); } |
103 it end() { |
100 void undo() { m_history.undo (); } |
104 return PROP_NAME (objs).end(); |
101 void redo() { m_history.redo (); } |
105 } |
102 void clearHistory() { m_history.clear (); } |
106 |
103 void addToHistory( AbstractHistoryEntry* entry ) { m_history << entry; } |
107 c_it end() const { |
|
108 return PROP_NAME (objs).end(); |
|
109 } |
|
110 |
|
111 static void closeUnused(); |
|
112 |
|
113 void openHistory() { |
|
114 m_history.open(); |
|
115 } |
|
116 |
|
117 void closeHistory() { |
|
118 m_history.close(); |
|
119 } |
|
120 |
|
121 void undo() { |
|
122 m_history.undo(); |
|
123 } |
|
124 |
|
125 void redo() { |
|
126 m_history.redo(); |
|
127 } |
|
128 |
|
129 void clearHistory() { |
|
130 m_history.clear(); |
|
131 } |
|
132 |
|
133 void addToHistory (AbstractHistoryEntry* entry) { |
|
134 m_history << entry; |
|
135 } |
104 }; |
136 }; |
105 |
137 |
106 // Close all current loaded files and start off blank. |
138 // Close all current loaded files and start off blank. |
107 void newFile(); |
139 void newFile(); |
108 |
140 |
109 // Opens the given file as the main file. Everything is closed first. |
141 // Opens the given file as the main file. Everything is closed first. |
110 void openMainFile( str path ); |
142 void openMainFile (str path); |
111 |
143 |
112 // Finds an OpenFile by name or null if not open |
144 // Finds an OpenFile by name or null if not open |
113 LDOpenFile* findLoadedFile( str name ); |
145 LDOpenFile* findLoadedFile (str name); |
114 |
146 |
115 // Opens the given file and parses the LDraw code within. Returns a pointer |
147 // Opens the given file and parses the LDraw code within. Returns a pointer |
116 // to the opened file or null on error. |
148 // to the opened file or null on error. |
117 LDOpenFile* openDATFile( str path, bool search ); |
149 LDOpenFile* openDATFile (str path, bool search); |
118 |
150 |
119 // Opens the given file and returns a pointer to it, potentially looking in /parts and /p |
151 // Opens the given file and returns a pointer to it, potentially looking in /parts and /p |
120 File* openLDrawFile( str relpath, bool subdirs ); |
152 File* openLDrawFile (str relpath, bool subdirs); |
121 |
153 |
122 // Close all open files, whether user-opened or subfile caches. |
154 // Close all open files, whether user-opened or subfile caches. |
123 void closeAll(); |
155 void closeAll(); |
124 |
156 |
125 // Parses a string line containing an LDraw object and returns the object parsed. |
157 // Parses a string line containing an LDraw object and returns the object parsed. |
126 LDObject* parseLine( str line ); |
158 LDObject* parseLine (str line); |
127 |
159 |
128 // Retrieves the pointer to - or loads - the given subfile. |
160 // Retrieves the pointer to - or loads - the given subfile. |
129 LDOpenFile* getFile( str filename ); |
161 LDOpenFile* getFile (str filename); |
130 |
162 |
131 // Re-caches all subfiles. |
163 // Re-caches all subfiles. |
132 void reloadAllSubfiles(); |
164 void reloadAllSubfiles(); |
133 |
165 |
134 // Is it safe to close all files? |
166 // Is it safe to close all files? |
135 bool safeToCloseAll(); |
167 bool safeToCloseAll(); |
136 |
168 |
137 vector<LDObject*> loadFileContents( File* f, ulong* numWarnings, bool* ok = null ); |
169 vector<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* ok = null); |
138 |
170 |
139 extern vector<LDOpenFile*> g_loadedFiles; |
171 extern vector<LDOpenFile*> g_loadedFiles; |
140 |
172 |
141 str basename( str path ); |
173 void addRecentFile (str path); |
142 str dirname( str path ); |
174 str basename (str path); |
|
175 str dirname (str path); |
143 |
176 |
144 // ============================================================================= |
177 // ============================================================================= |
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
146 // ============================================================================= |
179 // ============================================================================= |
147 // FileLoader |
180 // FileLoader |
148 // |
181 // |
149 // Loads the given file and parses it to LDObjects using parseLine. It's a |
182 // Loads the given file and parses it to LDObjects using parseLine. It's a |
150 // separate class so as to be able to do the work in a separate thread. |
183 // separate class so as to be able to do the work in a separate thread. |
151 // ============================================================================= |
184 // ============================================================================= |
152 class FileLoader : public QObject { |
185 class FileLoader : public QObject { |
153 Q_OBJECT |
186 Q_OBJECT |
154 READ_PROPERTY( vector<LDObject*>, objs, setObjects ) |
187 READ_PROPERTY (vector<LDObject*>, objs, setObjects) |
155 READ_PROPERTY( bool, done, setDone ) |
188 READ_PROPERTY (bool, done, setDone) |
156 READ_PROPERTY( ulong, progress, setProgress ) |
189 READ_PROPERTY (ulong, progress, setProgress) |
157 READ_PROPERTY( bool, aborted, setAborted ) |
190 READ_PROPERTY (bool, aborted, setAborted) |
158 PROPERTY( vector<str>, lines, setLines ) |
191 PROPERTY (vector<str>, lines, setLines) |
159 PROPERTY( ulong*, warningsPointer, setWarningsPointer ) |
192 PROPERTY (ulong*, warningsPointer, setWarningsPointer) |
160 PROPERTY( bool, concurrent, setConcurrent ) |
193 PROPERTY (bool, concurrent, setConcurrent) |
161 |
194 |
162 public slots: |
195 public slots: |
163 void start(); |
196 void start(); |
164 void abort(); |
197 void abort(); |
165 |
198 |
166 private: |
199 private: |
167 OpenProgressDialog* dlg; |
200 OpenProgressDialog* dlg; |
168 |
201 |
169 private slots: |
202 private slots: |
170 void work( ulong i ); |
203 void work (ulong i); |
171 |
204 |
172 signals: |
205 signals: |
173 void progressUpdate( int progress ); |
206 void progressUpdate (int progress); |
174 void workDone(); |
207 void workDone(); |
175 }; |
208 }; |
176 |
209 |
177 #endif // FILE_H |
210 #endif // FILE_H |
|
211 // kate: indent-mode cstyle; indent-width 4; replace-tabs off; tab-width 4; |