482 return prefix + frac + root + numstr + ".dat"; |
482 return prefix + frac + root + numstr + ".dat"; |
483 } |
483 } |
484 |
484 |
485 // ============================================================================= |
485 // ============================================================================= |
486 // ----------------------------------------------------------------------------- |
486 // ----------------------------------------------------------------------------- |
487 void generatePrimitive() |
487 LDFile* generatePrimitive (PrimitiveType type, int segs, int divs, int num) |
488 { PrimitivePrompt* dlg = new PrimitivePrompt (g_win); |
488 { // Make the description |
489 |
489 str frac = ftoa (((float) segs) / divs); |
490 if (!dlg->exec()) |
|
491 return; |
|
492 |
|
493 int segs = dlg->ui->sb_segs->value(); |
|
494 int divs = dlg->ui->cb_hires->isChecked() ? hires : lores; |
|
495 int num = dlg->ui->sb_ringnum->value(); |
|
496 PrimitiveType type = |
|
497 dlg->ui->rb_circle->isChecked() ? Circle : |
|
498 dlg->ui->rb_cylinder->isChecked() ? Cylinder : |
|
499 dlg->ui->rb_disc->isChecked() ? Disc : |
|
500 dlg->ui->rb_ndisc->isChecked() ? DiscNeg : |
|
501 dlg->ui->rb_ring->isChecked() ? Ring : Cone; |
|
502 |
|
503 // Make the description |
|
504 str frac = ftoa ( ( (float) segs) / divs); |
|
505 str name = radialFileName (type, segs, divs, num); |
490 str name = radialFileName (type, segs, divs, num); |
506 str descr; |
491 str descr; |
507 |
492 |
508 // Ensure that there's decimals, even if they're 0. |
493 // Ensure that there's decimals, even if they're 0. |
509 if (frac.indexOf (".") == -1) |
494 if (frac.indexOf (".") == -1) |
510 frac += ".0"; |
495 frac += ".0"; |
511 |
496 |
512 if (type == Ring || type == Cone) |
497 if (type == Ring || type == Cone) |
513 { str spacing = |
498 { str spacing = |
514 (num < 10) ? " " : |
499 (num < 10) ? " " : |
515 (num < 100) ? " " : ""; |
500 (num < 100) ? " " : ""; |
516 |
501 |
517 descr = fmt ("%1 %2%3 x %4", primitiveTypeName (type), spacing, num, frac); |
502 descr = fmt ("%1 %2%3 x %4", primitiveTypeName (type), spacing, num, frac); |
518 } |
503 } |
519 else |
504 else |
520 descr = fmt ("%1 %2", primitiveTypeName (type), frac); |
505 descr = fmt ("%1 %2", primitiveTypeName (type), frac); |
521 |
506 |
522 // Prepend "Hi-Res" if 48/ primitive. |
507 // Prepend "Hi-Res" if 48/ primitive. |
523 if (divs == hires) |
508 if (divs == hires) |
524 descr.insert (0, "Hi-Res "); |
509 descr.insert (0, "Hi-Res "); |
525 |
510 |
526 LDFile* f = new LDFile; |
511 LDFile* f = new LDFile; |
527 f->setName (QFileDialog::getSaveFileName (null, QObject::tr ("Save Primitive"), name)); |
512 f->setName (QFileDialog::getSaveFileName (null, QObject::tr ("Save Primitive"), name)); |
528 |
513 |
529 f->addObjects ( |
514 f->addObjects ( |
530 { new LDComment (descr), |
515 { new LDComment (descr), |
531 new LDComment (fmt ("Name: %1", name)), |
516 new LDComment (fmt ("Name: %1", name)), |
532 new LDComment (fmt ("Author: LDForge")), |
517 new LDComment (fmt ("Author: LDForge")), |
533 new LDComment (fmt ("!LDRAW_ORG Unofficial_%1Primitive", divs == hires ? "48_" : "")), |
518 new LDComment (fmt ("!LDRAW_ORG Unofficial_%1Primitive", divs == hires ? "48_" : "")), |
534 new LDComment (CALicense), |
519 new LDComment (CALicense), |
535 new LDEmpty, |
520 new LDEmpty, |
536 new LDBFC (LDBFC::CertifyCCW), |
521 new LDBFC (LDBFC::CertifyCCW), |
537 new LDEmpty, |
522 new LDEmpty, |
538 }); |
523 }); |
539 |
524 |
540 f->addObjects (makePrimitive (type, segs, divs, num)); |
525 f->addObjects (makePrimitive (type, segs, divs, num)); |
541 |
526 return f; |
542 g_win->save (f, false); |
527 } |
543 delete f; |
528 |
|
529 // ============================================================================= |
|
530 // ----------------------------------------------------------------------------- |
|
531 LDFile* getPrimitive (PrimitiveType type, int segs, int divs, int num) |
|
532 { str name = radialFileName (type, segs, divs, num); |
|
533 LDFile* f = getFile (name); |
|
534 if (f != null) |
|
535 return f; |
|
536 |
|
537 return generatePrimitive (type, segs, divs, num); |
544 } |
538 } |
545 |
539 |
546 // ============================================================================= |
540 // ============================================================================= |
547 // ----------------------------------------------------------------------------- |
541 // ----------------------------------------------------------------------------- |
548 PrimitivePrompt::PrimitivePrompt (QWidget* parent, Qt::WindowFlags f) : |
542 PrimitivePrompt::PrimitivePrompt (QWidget* parent, Qt::WindowFlags f) : |
549 QDialog (parent, f) |
543 QDialog (parent, f) |
550 { |
544 { |
551 |
545 |
552 ui = new Ui_MakePrimUI; |
546 ui = new Ui_MakePrimUI; |
553 ui->setupUi (this); |
547 ui->setupUi (this); |
554 connect (ui->cb_hires, SIGNAL (toggled (bool)), this, SLOT (hiResToggled (bool))); |
548 connect (ui->cb_hires, SIGNAL (toggled (bool)), this, SLOT (hiResToggled (bool))); |
555 } |
549 } |
556 |
550 |
562 |
556 |
563 // ============================================================================= |
557 // ============================================================================= |
564 // ----------------------------------------------------------------------------- |
558 // ----------------------------------------------------------------------------- |
565 void PrimitivePrompt::hiResToggled (bool on) |
559 void PrimitivePrompt::hiResToggled (bool on) |
566 { ui->sb_segs->setMaximum (on ? hires : lores); |
560 { ui->sb_segs->setMaximum (on ? hires : lores); |
567 |
561 |
568 // If the current value is 16 and we switch to hi-res, default the |
562 // If the current value is 16 and we switch to hi-res, default the |
569 // spinbox to 48. |
563 // spinbox to 48. |
570 if (on && ui->sb_segs->value() == lores) |
564 if (on && ui->sb_segs->value() == lores) |
571 ui->sb_segs->setValue (hires); |
565 ui->sb_segs->setValue (hires); |
572 } |
566 } |
|
567 |
|
568 // ============================================================================= |
|
569 // ----------------------------------------------------------------------------- |
|
570 DEFINE_ACTION (MakePrimitive, 0) |
|
571 { PrimitivePrompt* dlg = new PrimitivePrompt (g_win); |
|
572 |
|
573 if (!dlg->exec()) |
|
574 return; |
|
575 |
|
576 int segs = dlg->ui->sb_segs->value(); |
|
577 int divs = dlg->ui->cb_hires->isChecked() ? hires : lores; |
|
578 int num = dlg->ui->sb_ringnum->value(); |
|
579 PrimitiveType type = |
|
580 dlg->ui->rb_circle->isChecked() ? Circle : |
|
581 dlg->ui->rb_cylinder->isChecked() ? Cylinder : |
|
582 dlg->ui->rb_disc->isChecked() ? Disc : |
|
583 dlg->ui->rb_ndisc->isChecked() ? DiscNeg : |
|
584 dlg->ui->rb_ring->isChecked() ? Ring : Cone; |
|
585 |
|
586 LDFile* f = generatePrimitive (type, segs, divs, num); |
|
587 |
|
588 g_win->save (f, false); |
|
589 delete f; |
|
590 } |