131 // Clear the cache as well |
131 // Clear the cache as well |
132 for (LDObject* obj : cache()) |
132 for (LDObject* obj : cache()) |
133 delete obj; |
133 delete obj; |
134 |
134 |
135 // Remove this file from the list of files |
135 // Remove this file from the list of files |
136 for (ulong i = 0; i < g_loadedFiles.size(); ++i) |
136 for (int i = 0; i < g_loadedFiles.size(); ++i) |
137 { if (g_loadedFiles[i] == this) |
137 { if (g_loadedFiles[i] == this) |
138 { g_loadedFiles.erase (i); |
138 { g_loadedFiles.erase (i); |
139 break; |
139 break; |
140 } |
140 } |
141 } |
141 } |
359 g_aborted = true; |
359 g_aborted = true; |
360 } |
360 } |
361 |
361 |
362 // ============================================================================= |
362 // ============================================================================= |
363 // ----------------------------------------------------------------------------- |
363 // ----------------------------------------------------------------------------- |
364 List<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* ok) |
364 List<LDObject*> loadFileContents (File* f, int* numWarnings, bool* ok) |
365 { List<str> lines; |
365 { List<str> lines; |
366 List<LDObject*> objs; |
366 List<LDObject*> objs; |
367 |
367 |
368 if (numWarnings) |
368 if (numWarnings) |
369 *numWarnings = 0; |
369 *numWarnings = 0; |
418 return null; |
418 return null; |
419 |
419 |
420 LDFile* load = new LDFile; |
420 LDFile* load = new LDFile; |
421 load->setName (path); |
421 load->setName (path); |
422 |
422 |
423 ulong numWarnings; |
423 int numWarnings; |
424 bool ok; |
424 bool ok; |
425 List<LDObject*> objs = loadFileContents (f, &numWarnings, &ok); |
425 List<LDObject*> objs = loadFileContents (f, &numWarnings, &ok); |
426 |
426 |
427 if (!ok) |
427 if (!ok) |
428 return null; |
428 return null; |
429 |
429 |
430 for (LDObject * obj : objs) |
430 for (LDObject* obj : objs) |
431 load->addObject (obj); |
431 load->addObject (obj); |
432 |
432 |
433 delete f; |
433 delete f; |
434 g_loadedFiles << load; |
434 g_loadedFiles << load; |
435 |
435 |
639 #define CHECK_TOKEN_COUNT(N) \ |
639 #define CHECK_TOKEN_COUNT(N) \ |
640 if (tokens.size() != N) \ |
640 if (tokens.size() != N) \ |
641 return new LDError (line, "Bad amount of tokens"); |
641 return new LDError (line, "Bad amount of tokens"); |
642 |
642 |
643 #define CHECK_TOKEN_NUMBERS(MIN, MAX) \ |
643 #define CHECK_TOKEN_NUMBERS(MIN, MAX) \ |
644 for (ushort i = MIN; i <= MAX; ++i) \ |
644 for (int i = MIN; i <= MAX; ++i) \ |
645 if (!isNumber (tokens[i])) \ |
645 if (!isNumber (tokens[i])) \ |
646 return new LDError (line, fmt ("Token #%1 was `%2`, expected a number", (i + 1), tokens[i])); |
646 return new LDError (line, fmt ("Token #%1 was `%2`, expected a number", (i + 1), tokens[i])); |
647 |
647 |
648 // ============================================================================= |
648 // ============================================================================= |
649 // ----------------------------------------------------------------------------- |
649 // ----------------------------------------------------------------------------- |
650 static vertex parseVertex (QStringList& s, const ushort n) |
650 static vertex parseVertex (QStringList& s, const int n) |
651 { vertex v; |
651 { vertex v; |
652 |
652 |
653 for (const Axis ax : g_Axes) |
653 for (const Axis ax : g_Axes) |
654 v[ax] = atof (s[n + ax]); |
654 v[ax] = atof (s[n + ax]); |
655 |
655 |
873 LDFile::closeUnused(); |
873 LDFile::closeUnused(); |
874 } |
874 } |
875 |
875 |
876 // ============================================================================= |
876 // ============================================================================= |
877 // ----------------------------------------------------------------------------- |
877 // ----------------------------------------------------------------------------- |
878 ulong LDFile::addObject (LDObject* obj) |
878 int LDFile::addObject (LDObject* obj) |
879 { m_history.add (new AddHistory (objects().size(), obj)); |
879 { m_history.add (new AddHistory (objects().size(), obj)); |
880 m_objects << obj; |
880 m_objects << obj; |
881 |
881 |
882 if (obj->getType() == LDObject::Vertex) |
882 if (obj->getType() == LDObject::Vertex) |
883 m_vertices << obj; |
883 m_vertices << obj; |
894 addObject (obj); |
894 addObject (obj); |
895 } |
895 } |
896 |
896 |
897 // ============================================================================= |
897 // ============================================================================= |
898 // ----------------------------------------------------------------------------- |
898 // ----------------------------------------------------------------------------- |
899 void LDFile::insertObj (const ulong pos, LDObject* obj) |
899 void LDFile::insertObj (int pos, LDObject* obj) |
900 { m_history.add (new AddHistory (pos, obj)); |
900 { m_history.add (new AddHistory (pos, obj)); |
901 m_objects.insert (pos, obj); |
901 m_objects.insert (pos, obj); |
902 obj->setFile (this); |
902 obj->setFile (this); |
903 } |
903 } |
904 |
904 |
905 // ============================================================================= |
905 // ============================================================================= |
906 // ----------------------------------------------------------------------------- |
906 // ----------------------------------------------------------------------------- |
907 void LDFile::forgetObject (LDObject* obj) |
907 void LDFile::forgetObject (LDObject* obj) |
908 { ulong idx = obj->getIndex(); |
908 { int idx = obj->getIndex(); |
909 m_history.add (new DelHistory (idx, obj)); |
909 m_history.add (new DelHistory (idx, obj)); |
910 m_objects.erase (idx); |
910 m_objects.erase (idx); |
911 obj->setFile (null); |
911 obj->setFile (null); |
912 } |
912 } |
913 |
913 |
921 return true; |
921 return true; |
922 } |
922 } |
923 |
923 |
924 // ============================================================================= |
924 // ============================================================================= |
925 // ----------------------------------------------------------------------------- |
925 // ----------------------------------------------------------------------------- |
926 void LDFile::setObject (ulong idx, LDObject* obj) |
926 void LDFile::setObject (int idx, LDObject* obj) |
927 { assert (idx < numObjs()); |
927 { assert (idx < numObjs()); |
928 |
928 |
929 // Mark this change to history |
929 // Mark this change to history |
930 str oldcode = object (idx)->raw(); |
930 str oldcode = object (idx)->raw(); |
931 str newcode = obj->raw(); |
931 str newcode = obj->raw(); |
985 g_loadedFiles << filesUsed; |
985 g_loadedFiles << filesUsed; |
986 } |
986 } |
987 |
987 |
988 // ============================================================================= |
988 // ============================================================================= |
989 // ----------------------------------------------------------------------------- |
989 // ----------------------------------------------------------------------------- |
990 LDObject* LDFile::object (ulong pos) const |
990 LDObject* LDFile::object (int pos) const |
991 { if (m_objects.size() <= pos) |
991 { if (m_objects.size() <= pos) |
992 return null; |
992 return null; |
993 |
993 |
994 return m_objects[pos]; |
994 return m_objects[pos]; |
995 } |
995 } |
996 |
996 |
997 // ============================================================================= |
997 // ============================================================================= |
998 // ----------------------------------------------------------------------------- |
998 // ----------------------------------------------------------------------------- |
999 LDObject* LDFile::obj (ulong pos) const |
999 LDObject* LDFile::obj (int pos) const |
1000 { return object (pos); |
1000 { return object (pos); |
1001 } |
1001 } |
1002 |
1002 |
1003 // ============================================================================= |
1003 // ============================================================================= |
1004 // ----------------------------------------------------------------------------- |
1004 // ----------------------------------------------------------------------------- |
1005 ulong LDFile::numObjs() const |
1005 int LDFile::numObjs() const |
1006 { return objects().size(); |
1006 { return objects().size(); |
1007 } |
1007 } |
1008 |
1008 |
1009 // ============================================================================= |
1009 // ============================================================================= |
1010 // ----------------------------------------------------------------------------- |
1010 // ----------------------------------------------------------------------------- |