28 // IO_OpenLDrawFile (str) |
28 // IO_OpenLDrawFile (str) |
29 // |
29 // |
30 // Opens the given file and parses the LDraw code within. |
30 // Opens the given file and parses the LDraw code within. |
31 // ============================================================================= |
31 // ============================================================================= |
32 OpenFile* IO_OpenLDrawFile (str path) { |
32 OpenFile* IO_OpenLDrawFile (str path) { |
|
33 logf ("Opening %s...\n", path.chars()); |
|
34 |
33 FILE* fp = fopen (path.chars (), "r"); |
35 FILE* fp = fopen (path.chars (), "r"); |
34 |
36 |
35 if (!fp) { |
37 if (!fp) { |
36 printf ("Couldn't open %s!\n", path.chars ()); |
38 logf (LOG_Error, "Couldn't open %s: %s\n", path.chars (), strerror (errno)); |
37 return NULL; |
39 return NULL; |
38 } |
40 } |
39 |
41 |
40 OpenFile* load = new OpenFile; |
42 OpenFile* load = new OpenFile; |
|
43 ulong numWarnings = 0; |
|
44 |
41 load->zFileName = path; |
45 load->zFileName = path; |
42 |
46 |
43 vector<str> lines; |
47 vector<str> lines; |
44 |
48 |
45 { |
49 { |
54 } |
58 } |
55 } |
59 } |
56 |
60 |
57 fclose (fp); |
61 fclose (fp); |
58 |
62 |
59 for (ulong i = 0; i < lines.size(); ++i) |
63 for (ulong i = 0; i < lines.size(); ++i) { |
60 load->objects.push_back (ParseLine (lines[i])); |
64 LDObject* obj = ParseLine (lines[i]); |
|
65 load->objects.push_back (obj); |
|
66 |
|
67 // Check for warnings |
|
68 if (obj->getType() == OBJ_Gibberish) { |
|
69 logf (LOG_Warning, "Couldn't parse line #%lu: %s\n", |
|
70 i, static_cast<LDGibberish*> (obj)->zReason.chars()); |
|
71 logf (LOG_Warning, "- Line was: %s\n", lines[i].chars()); |
|
72 numWarnings++; |
|
73 } |
|
74 } |
61 |
75 |
62 g_LoadedFiles.push_back (load); |
76 g_LoadedFiles.push_back (load); |
63 g_CurrentFile = g_LoadedFiles[g_LoadedFiles.size() - 1]; |
77 g_CurrentFile = g_LoadedFiles[g_LoadedFiles.size() - 1]; |
64 |
78 |
65 // Recalculate the bounding box |
79 // Recalculate the bounding box |
66 g_BBox.calculate(); |
80 g_BBox.calculate(); |
67 |
81 |
68 // Rebuild the object tree view now. |
82 // Rebuild the object tree view now. |
69 g_qWindow->buildObjList (); |
83 g_qWindow->buildObjList (); |
70 g_qWindow->setTitle (); |
84 g_qWindow->setTitle (); |
|
85 |
|
86 logf (LOG_Success, "File %s parsed successfully (%lu warnings).\n", |
|
87 path.chars(), numWarnings); |
71 |
88 |
72 return g_CurrentFile; |
89 return g_CurrentFile; |
73 } |
90 } |
74 |
91 |
75 // ============================================================================= |
92 // ============================================================================= |