src/primitives.cpp

changeset 421
7d26db0be944
parent 410
a5aebcf4a1c8
child 436
4268a5507725
equal deleted inserted replaced
420:8d6af951b611 421:7d26db0be944
284 284
285 // ============================================================================= 285 // =============================================================================
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
287 // ============================================================================= 287 // =============================================================================
288 static double radialPoint (int i, int divs, double (*func) (double)) { 288 static double radialPoint (int i, int divs, double (*func) (double)) {
289 return (*func) ( (i * 2 * pi) / divs); 289 return (*func) ((i * 2 * pi) / divs);
290 } 290 }
291 291
292 // ============================================================================= 292 // =============================================================================
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
294 // ============================================================================= 294 // =============================================================================
490 490
491 // ============================================================================= 491 // =============================================================================
492 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 492 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
493 // ============================================================================= 493 // =============================================================================
494 void generatePrimitive() { 494 void generatePrimitive() {
495 PrimitivePrompt* dlg = new PrimitivePrompt( g_win ); 495 PrimitivePrompt* dlg = new PrimitivePrompt (g_win);
496 496
497 if (!dlg->exec()) 497 if (!dlg->exec())
498 return; 498 return;
499 499
500 int segs = dlg->ui->sb_segs->value(); 500 int segs = dlg->ui->sb_segs->value();
506 dlg->ui->rb_disc->isChecked() ? Disc : 506 dlg->ui->rb_disc->isChecked() ? Disc :
507 dlg->ui->rb_ndisc->isChecked() ? DiscNeg : 507 dlg->ui->rb_ndisc->isChecked() ? DiscNeg :
508 dlg->ui->rb_ring->isChecked() ? Ring : Cone; 508 dlg->ui->rb_ring->isChecked() ? Ring : Cone;
509 509
510 // Make the description 510 // Make the description
511 str frac = ftoa ( ( (float) segs) / divs); 511 str frac = ftoa (((float) segs) / divs);
512 str name = radialFileName (type, segs, divs, num); 512 str name = radialFileName (type, segs, divs, num);
513 str descr; 513 str descr;
514 514
515 // Ensure that there's decimals, even if they're 0. 515 // Ensure that there's decimals, even if they're 0.
516 if (frac.indexOf (".") == -1) 516 if (frac.indexOf (".") == -1)
517 frac += ".0"; 517 frac += ".0";
518 518
519 if (type == Ring || type == Cone) { 519 if (type == Ring || type == Cone) {
520 str spacing = 520 str spacing =
521 ( num < 10 ) ? " " : 521 (num < 10 ) ? " " :
522 ( num < 100 ) ? " " : ""; 522 (num < 100) ? " " : "";
523 523
524 descr = fmt ("%1 %2%3 x %4", primitiveTypeName (type), spacing, num, frac); 524 descr = fmt ("%1 %2%3 x %4", primitiveTypeName (type), spacing, num, frac);
525 } else 525 } else
526 descr = fmt ("%1 %2", primitiveTypeName (type), frac); 526 descr = fmt ("%1 %2", primitiveTypeName (type), frac);
527 527
528 // Prepend "Hi-Res" if 48/ primitive. 528 // Prepend "Hi-Res" if 48/ primitive.
529 if( divs == hires ) 529 if (divs == hires)
530 descr.insert( 0, "Hi-Res " ); 530 descr.insert (0, "Hi-Res ");
531 531
532 LDFile* f = new LDFile; 532 LDFile* f = new LDFile;
533 f->setName (QFileDialog::getSaveFileName (null, QObject::tr ("Save Primitive"), name)); 533 f->setName (QFileDialog::getSaveFileName (null, QObject::tr ("Save Primitive"), name));
534 534
535 *f << new LDCommentObject (descr); 535 *f << new LDCommentObject (descr);
545 g_win->save (f, false); 545 g_win->save (f, false);
546 delete f; 546 delete f;
547 } 547 }
548 548
549 PrimitivePrompt::PrimitivePrompt (QWidget* parent, Qt::WindowFlags f) : 549 PrimitivePrompt::PrimitivePrompt (QWidget* parent, Qt::WindowFlags f) :
550 QDialog (parent, f) 550 QDialog (parent, f) {
551 { 551
552 ui = new Ui_MakePrimUI; 552 ui = new Ui_MakePrimUI;
553 ui->setupUi( this ); 553 ui->setupUi (this);
554 connect( ui->cb_hires, SIGNAL( toggled(bool) ), this, SLOT( hiResToggled( bool ))); 554 connect (ui->cb_hires, SIGNAL (toggled(bool)), this, SLOT (hiResToggled (bool)));
555 } 555 }
556 556
557 PrimitivePrompt::~PrimitivePrompt() { 557 PrimitivePrompt::~PrimitivePrompt() {
558 delete ui; 558 delete ui;
559 } 559 }
560 560
561 void PrimitivePrompt::hiResToggled( bool on ) { 561 void PrimitivePrompt::hiResToggled (bool on) {
562 ui->sb_segs->setMaximum( on ? hires : lores ); 562 ui->sb_segs->setMaximum (on ? hires : lores);
563 563
564 // If the current value is 16 and we switch to hi-res, default the 564 // If the current value is 16 and we switch to hi-res, default the
565 // spinbox to 48. 565 // spinbox to 48.
566 if( on && ui->sb_segs->value() == lores ) 566 if (on && ui->sb_segs->value() == lores)
567 ui->sb_segs->setValue( hires ); 567 ui->sb_segs->setValue (hires);
568 } 568 }
569 569
570 #include "build/moc_primitives.cpp" 570 #include "build/moc_primitives.cpp"

mercurial