440 QString root = roots[type]; |
440 QString root = roots[type]; |
441 QString numberString = (type == Ring or type == Cone) ? format ("%1", ringNumber) : ""; |
441 QString numberString = (type == Ring or type == Cone) ? format ("%1", ringNumber) : ""; |
442 |
442 |
443 // Truncate the root if necessary (7-16rin4.dat for instance). |
443 // Truncate the root if necessary (7-16rin4.dat for instance). |
444 // However, always keep the root at least 2 characters. |
444 // However, always keep the root at least 2 characters. |
445 int extra = (countof(frac) + countof(numberString) + countof(root)) - 8; |
445 if (style == LegacyStyleName) |
446 root.chop(qBound(0, extra, 2)); |
446 { |
|
447 int extra = (countof(frac) + countof(numberString) + countof(root)) - 8; |
|
448 root.chop(qBound(0, extra, 2)); |
|
449 } |
447 |
450 |
448 // Stick them all together and return the result. |
451 // Stick them all together and return the result. |
449 return prefix + frac + root + numberString + ".dat"; |
452 return prefix + frac + root + numberString + ".dat"; |
450 } |
453 } |
451 |
454 |
452 |
455 |
453 LDDocument* PrimitiveManager::generatePrimitive(const PrimitiveModel& spec) |
456 LDDocument* PrimitiveManager::generatePrimitive(const PrimitiveModel& spec) |
454 { |
457 { |
455 // Make the description |
458 // Make the description |
456 QString fraction = QString::number ((float) spec.segments / spec.divisions); |
459 QString fraction = QString::number ((float) spec.segments / spec.divisions); |
457 QString fileName = spec.makeFileName(); |
460 QString fileName = spec.makeFileName(PrimitiveModel::NewStyleName); |
458 QString description; |
461 QString description; |
459 |
462 |
460 // Ensure that there's decimals, even if they're 0. |
463 // Ensure that there's decimals, even if they're 0. |
461 if (fraction.indexOf(".") == -1) |
464 if (fraction.indexOf(".") == -1) |
462 fraction += ".0"; |
465 fraction += ".0"; |
517 * |
520 * |
518 * Gets a primitive by the given model. If the primitive cannot be found, it will be automatically generated. |
521 * Gets a primitive by the given model. If the primitive cannot be found, it will be automatically generated. |
519 */ |
522 */ |
520 LDDocument* PrimitiveManager::getPrimitive(const PrimitiveModel& model) |
523 LDDocument* PrimitiveManager::getPrimitive(const PrimitiveModel& model) |
521 { |
524 { |
522 QString name = model.makeFileName(); |
525 // Try find with the new style name. |
523 LDDocument* document = m_window->documents()->getDocumentByName (name); |
526 QString name = model.makeFileName(PrimitiveModel::NewStyleName); |
|
527 LDDocument* document = m_window->documents()->getDocumentByName(name); |
524 |
528 |
525 if (not document) |
529 if (not document) |
526 { |
530 { |
|
531 // Not found, try the legacy name |
|
532 QString name = model.makeFileName(PrimitiveModel::LegacyStyleName); |
|
533 document = m_window->documents()->getDocumentByName(name); |
|
534 } |
|
535 |
|
536 if (not document) |
|
537 { |
|
538 // Not found either, generate it. |
527 document = generatePrimitive(model); |
539 document = generatePrimitive(model); |
528 m_window->openDocumentForEditing(document); |
540 m_window->openDocumentForEditing(document); |
529 } |
541 } |
530 |
542 |
531 return document; |
543 return document; |