src/file.h

changeset 183
f1b8cb53d2a2
child 189
ac2d3e8dd110
equal deleted inserted replaced
182:9374fea8f77f 183:f1b8cb53d2a2
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 Santeri 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 #ifndef FILE_H
20 #define FILE_H
21
22 #include "common.h"
23 #include "ldtypes.h"
24 #include "str.h"
25
26 namespace LDPaths {
27 void initPaths ();
28 bool tryConfigure (str path);
29
30 str ldconfig ();
31 str prims ();
32 str parts ();
33 str getError ();
34 }
35
36 // =============================================================================
37 // OpenFile
38 //
39 // The OpenFile class stores a file opened in LDForge either as a editable file
40 // for the user or for subfile caching. Its methods handle file input and output.
41 // =============================================================================
42 class OpenFile {
43 public:
44 str m_filename, m_title;
45 vector<LDObject*> m_objs;
46 vector<LDObject*> m_objCache; // Cache of this file's contents, if desired
47
48 int lastError;
49
50 // Is this file implicit? Implicit files are opened automatically for
51 // caching purposes and are hidden from the user.
52 bool m_implicit;
53
54 OpenFile ();
55 ~OpenFile ();
56
57 // Saves this file to disk.
58 bool save (str zPath = "");
59
60 // Perform safety checks. Do this before closing any files!
61 bool safeToClose ();
62
63 // Adds an object to this file at the end of the file.
64 ulong addObject (LDObject* obj);
65
66 // Deletes the given object from the object chain.
67 void forgetObject (LDObject* obj);
68
69 // At what point was this file last saved?
70 long savePos;
71
72 LDObject* object (ulong pos) const {
73 return m_objs[pos];
74 }
75
76 void insertObj (const ulong pos, LDObject* obj);
77 };
78
79 // Close all current loaded files and start off blank.
80 void newFile ();
81
82 // Opens the given file as the main file. Everything is closed first.
83 void openMainFile (str zPath);
84
85 // Finds an OpenFile by name or null if not open
86 OpenFile* findLoadedFile (str name);
87
88 // Opens the given file and parses the LDraw code within. Returns a pointer
89 // to the opened file or null on error.
90 OpenFile* openDATFile (str path, bool search);
91
92 // Opens the given file and returns a pointer to it, potentially looking in /parts and /p
93 FILE* openLDrawFile (str path, bool bSubDirectories);
94
95 // Close all open files, whether user-opened or subfile caches.
96 void closeAll ();
97
98 // Parses a string line containing an LDraw object and returns the object parsed.
99 LDObject* parseLine (str zLine);
100
101 // Retrieves the pointer to - or loads - the given subfile.
102 OpenFile* loadSubfile (str zFile);
103
104 // Re-caches all subfiles.
105 void reloadAllSubfiles ();
106
107 typedef struct {
108 char sName[65], sTitle[81];
109 } partListEntry;
110
111 // Init and parse parts.lst
112 void initPartList ();
113
114 std::vector< LDObject* > loadFileContents (FILE* fp, ulong* numWarnings);
115
116 extern vector<OpenFile*> g_loadedFiles;
117 extern vector<partListEntry> g_PartList;
118
119 #endif // FILE_H

mercurial