324 |
324 |
325 // ============================================================================= |
325 // ============================================================================= |
326 // |
326 // |
327 static void CheckTokenCount (const QStringList& tokens, int num) |
327 static void CheckTokenCount (const QStringList& tokens, int num) |
328 { |
328 { |
329 if (length(tokens) != num) |
329 if (countof(tokens) != num) |
330 throw QString (format ("Bad amount of tokens, expected %1, got %2", num, length(tokens))); |
330 throw QString (format ("Bad amount of tokens, expected %1, got %2", num, countof(tokens))); |
331 } |
331 } |
332 |
332 |
333 // ============================================================================= |
333 // ============================================================================= |
334 // |
334 // |
335 static void CheckTokenNumbers (const QStringList& tokens, int min, int max) |
335 static void CheckTokenNumbers (const QStringList& tokens, int min, int max) |
393 { |
393 { |
394 try |
394 try |
395 { |
395 { |
396 QStringList tokens = line.split (" ", QString::SkipEmptyParts); |
396 QStringList tokens = line.split (" ", QString::SkipEmptyParts); |
397 |
397 |
398 if (length(tokens) <= 0) |
398 if (countof(tokens) <= 0) |
399 { |
399 { |
400 // Line was empty, or only consisted of whitespace |
400 // Line was empty, or only consisted of whitespace |
401 return LDSpawn<LDEmpty>(); |
401 return LDSpawn<LDEmpty>(); |
402 } |
402 } |
403 |
403 |
404 if (length(tokens[0]) != 1 or not tokens[0][0].isDigit()) |
404 if (countof(tokens[0]) != 1 or not tokens[0][0].isDigit()) |
405 throw QString ("Illogical line code"); |
405 throw QString ("Illogical line code"); |
406 |
406 |
407 int num = tokens[0][0].digitValue(); |
407 int num = tokens[0][0].digitValue(); |
408 |
408 |
409 switch (num) |
409 switch (num) |
413 // Comment |
413 // Comment |
414 QString commentText (line.mid (line.indexOf ("0") + 2)); |
414 QString commentText (line.mid (line.indexOf ("0") + 2)); |
415 QString commentTextSimplified (commentText.simplified()); |
415 QString commentTextSimplified (commentText.simplified()); |
416 |
416 |
417 // Handle BFC statements |
417 // Handle BFC statements |
418 if (length(tokens) > 2 and tokens[1] == "BFC") |
418 if (countof(tokens) > 2 and tokens[1] == "BFC") |
419 { |
419 { |
420 for (BfcStatement statement : iterateEnum<BfcStatement>()) |
420 for (BfcStatement statement : iterateEnum<BfcStatement>()) |
421 { |
421 { |
422 if (commentTextSimplified == format("BFC %1", LDBfc::statementToString (statement))) |
422 if (commentTextSimplified == format("BFC %1", LDBfc::statementToString (statement))) |
423 return LDSpawn<LDBfc>(statement); |
423 return LDSpawn<LDBfc>(statement); |
432 return LDSpawn<LDBfc> (BfcStatement::Clip); |
432 return LDSpawn<LDBfc> (BfcStatement::Clip); |
433 else if (commentTextSimplified == "BFC CERTIFY NOCLIP") |
433 else if (commentTextSimplified == "BFC CERTIFY NOCLIP") |
434 return LDSpawn<LDBfc> (BfcStatement::NoClip); |
434 return LDSpawn<LDBfc> (BfcStatement::NoClip); |
435 } |
435 } |
436 |
436 |
437 if (length(tokens) > 2 and tokens[1] == "!LDFORGE") |
437 if (countof(tokens) > 2 and tokens[1] == "!LDFORGE") |
438 { |
438 { |
439 // Handle LDForge-specific types, they're embedded into comments too |
439 // Handle LDForge-specific types, they're embedded into comments too |
440 if (tokens[2] == "OVERLAY") |
440 if (tokens[2] == "OVERLAY") |
441 { |
441 { |
442 CheckTokenCount (tokens, 9); |
442 CheckTokenCount (tokens, 9); |
603 |
603 |
604 // ============================================================================= |
604 // ============================================================================= |
605 // |
605 // |
606 int LDDocument::addObject (LDObject* obj) |
606 int LDDocument::addObject (LDObject* obj) |
607 { |
607 { |
608 history()->add (new AddHistoryEntry (length(objects()), obj)); |
608 history()->add (new AddHistoryEntry (countof(objects()), obj)); |
609 m_objects << obj; |
609 m_objects << obj; |
610 addKnownVertices (obj); |
610 addKnownVertices (obj); |
611 obj->setDocument (this); |
611 obj->setDocument (this); |
612 setFlag(NeedsTriangleRecount); |
612 setFlag(NeedsTriangleRecount); |
613 m_window->renderer()->compileObject (obj); |
613 m_window->renderer()->compileObject (obj); |
681 |
681 |
682 // ============================================================================= |
682 // ============================================================================= |
683 // |
683 // |
684 void LDDocument::setObjectAt (int idx, LDObject* obj) |
684 void LDDocument::setObjectAt (int idx, LDObject* obj) |
685 { |
685 { |
686 if (idx < 0 or idx >= length(m_objects)) |
686 if (idx < 0 or idx >= countof(m_objects)) |
687 return; |
687 return; |
688 |
688 |
689 // Mark this change to history |
689 // Mark this change to history |
690 if (not m_history->isIgnoring()) |
690 if (not m_history->isIgnoring()) |
691 { |
691 { |
706 |
706 |
707 // ============================================================================= |
707 // ============================================================================= |
708 // |
708 // |
709 LDObject* LDDocument::getObject (int pos) const |
709 LDObject* LDDocument::getObject (int pos) const |
710 { |
710 { |
711 if (pos < length(m_objects)) |
711 if (pos < countof(m_objects)) |
712 return m_objects[pos]; |
712 return m_objects[pos]; |
713 else |
713 else |
714 return nullptr; |
714 return nullptr; |
715 } |
715 } |
716 |
716 |
717 // ============================================================================= |
717 // ============================================================================= |
718 // |
718 // |
719 int LDDocument::getObjectCount() const |
719 int LDDocument::getObjectCount() const |
720 { |
720 { |
721 return length(objects()); |
721 return countof(objects()); |
722 } |
722 } |
723 |
723 |
724 // ============================================================================= |
724 // ============================================================================= |
725 // |
725 // |
726 bool LDDocument::hasUnsavedChanges() const |
726 bool LDDocument::hasUnsavedChanges() const |