src/extPrograms.cc

changeset 714
b4a990f59a5e
parent 706
d79083b9f74d
parent 662
2f1bd9112408
child 739
152b33a6d51b
equal deleted inserted replaced
713:46377d340c23 714:b4a990f59a5e
99 99
100 // ============================================================================= 100 // =============================================================================
101 // 101 //
102 static bool mkTempFile (QTemporaryFile& tmp, QString& fname) 102 static bool mkTempFile (QTemporaryFile& tmp, QString& fname)
103 { 103 {
104 if (!tmp.open()) 104 if (not tmp.open())
105 return false; 105 return false;
106 106
107 fname = tmp.fileName(); 107 fname = tmp.fileName();
108 tmp.close(); 108 tmp.close();
109 return true; 109 return true;
118 if (path.length() > 0) 118 if (path.length() > 0)
119 return true; 119 return true;
120 120
121 ExtProgPathPrompt* dlg = new ExtProgPathPrompt (g_extProgNames[prog]); 121 ExtProgPathPrompt* dlg = new ExtProgPathPrompt (g_extProgNames[prog]);
122 122
123 if (dlg->exec() && !dlg->getPath().isEmpty()) 123 if (dlg->exec() && not dlg->getPath().isEmpty())
124 { 124 {
125 path = dlg->getPath(); 125 path = dlg->getPath();
126 return true; 126 return true;
127 } 127 }
128 128
190 static void writeObjects (const LDObjectList& objects, QString fname) 190 static void writeObjects (const LDObjectList& objects, QString fname)
191 { 191 {
192 // Write the input file 192 // Write the input file
193 QFile f (fname); 193 QFile f (fname);
194 194
195 if (!f.open (QIODevice::WriteOnly | QIODevice::Text)) 195 if (not f.open (QIODevice::WriteOnly | QIODevice::Text))
196 { 196 {
197 critical (format ("Couldn't open temporary file %1 for writing: %2\n", fname, f.errorString())); 197 critical (format ("Couldn't open temporary file %1 for writing: %2\n", fname, f.errorString()));
198 return; 198 return;
199 } 199 }
200 200
219 { 219 {
220 LDObjectList objects; 220 LDObjectList objects;
221 221
222 for (LDObject* obj : getCurrentDocument()->objects()) 222 for (LDObject* obj : getCurrentDocument()->objects())
223 { 223 {
224 if (obj->isColored() == false || obj->color() != colnum) 224 if (not obj->isColored() || obj->color() != colnum)
225 continue; 225 continue;
226 226
227 objects << obj; 227 objects << obj;
228 } 228 }
229 229
245 } 245 }
246 #endif // _WIN32 246 #endif // _WIN32
247 247
248 print ("Running command: %1 %2\n", path, argv.join (" ")); 248 print ("Running command: %1 %2\n", path, argv.join (" "));
249 249
250 if (!input.open()) 250 if (not input.open())
251 return false; 251 return false;
252 252
253 QProcess proc; 253 QProcess proc;
254 254
255 // Begin! 255 // Begin!
256 proc.setStandardInputFile (input.fileName()); 256 proc.setStandardInputFile (input.fileName());
257 proc.start (path, argv); 257 proc.start (path, argv);
258 258
259 if (!proc.waitForStarted()) 259 if (not proc.waitForStarted())
260 { 260 {
261 critical (format ("Couldn't start %1: %2\n", g_extProgNames[prog], processErrorString (prog, proc))); 261 critical (format ("Couldn't start %1: %2\n", g_extProgNames[prog], processErrorString (prog, proc)));
262 return false; 262 return false;
263 } 263 }
264 264
275 275
276 // Check the return code 276 // Check the return code
277 if (proc.exitCode() != 0) 277 if (proc.exitCode() != 0)
278 err = format ("Program exited abnormally (return code %1).", proc.exitCode()); 278 err = format ("Program exited abnormally (return code %1).", proc.exitCode());
279 279
280 if (!err.isEmpty()) 280 if (not err.isEmpty())
281 { 281 {
282 critical (format ("%1 failed: %2\n", g_extProgNames[prog], err)); 282 critical (format ("%1 failed: %2\n", g_extProgNames[prog], err));
283 return false; 283 return false;
284 } 284 }
285 285
295 #endif // RELEASE 295 #endif // RELEASE
296 296
297 // Read the output file 297 // Read the output file
298 QFile f (fname); 298 QFile f (fname);
299 299
300 if (!f.open (QIODevice::ReadOnly)) 300 if (not f.open (QIODevice::ReadOnly))
301 { 301 {
302 critical (format ("Couldn't open temporary file %1 for reading.\n", fname)); 302 critical (format ("Couldn't open temporary file %1 for reading.\n", fname));
303 return; 303 return;
304 } 304 }
305 305
315 // Insert the new objects 315 // Insert the new objects
316 getCurrentDocument()->clearSelection(); 316 getCurrentDocument()->clearSelection();
317 317
318 for (LDObject* obj : objs) 318 for (LDObject* obj : objs)
319 { 319 {
320 if (!obj->isScemantic()) 320 if (not obj->isScemantic())
321 { 321 {
322 obj->destroy(); 322 obj->destroy();
323 continue; 323 continue;
324 } 324 }
325 325
335 // ============================================================================= 335 // =============================================================================
336 DEFINE_ACTION (Ytruder, 0) 336 DEFINE_ACTION (Ytruder, 0)
337 { 337 {
338 setlocale (LC_ALL, "C"); 338 setlocale (LC_ALL, "C");
339 339
340 if (!checkProgPath (Ytruder)) 340 if (not checkProgPath (Ytruder))
341 return; 341 return;
342 342
343 QDialog* dlg = new QDialog; 343 QDialog* dlg = new QDialog;
344 Ui::YtruderUI ui; 344 Ui::YtruderUI ui;
345 ui.setupUi (dlg); 345 ui.setupUi (dlg);
346 346
347 if (!dlg->exec()) 347 if (not dlg->exec())
348 return; 348 return;
349 349
350 // Read the user's choices 350 // Read the user's choices
351 const enum { Distance, Symmetry, Projection, Radial } mode = 351 const enum { Distance, Symmetry, Projection, Radial } mode =
352 ui.mode_distance->isChecked() ? Distance : 352 ui.mode_distance->isChecked() ? Distance :
362 362
363 QTemporaryFile indat, outdat; 363 QTemporaryFile indat, outdat;
364 QString inDATName, outDATName; 364 QString inDATName, outDATName;
365 365
366 // Make temp files for the input and output files 366 // Make temp files for the input and output files
367 if (!mkTempFile (indat, inDATName) || !mkTempFile (outdat, outDATName)) 367 if (not mkTempFile (indat, inDATName) || not mkTempFile (outdat, outDATName))
368 return; 368 return;
369 369
370 // Compose the command-line arguments 370 // Compose the command-line arguments
371 QString argv = join ( 371 QString argv = join (
372 { 372 {
379 outDATName 379 outDATName
380 }); 380 });
381 381
382 writeSelection (inDATName); 382 writeSelection (inDATName);
383 383
384 if (!runUtilityProcess (Ytruder, prog_ytruder, argv)) 384 if (not runUtilityProcess (Ytruder, prog_ytruder, argv))
385 return; 385 return;
386 386
387 insertOutput (outDATName, false, {}); 387 insertOutput (outDATName, false, {});
388 } 388 }
389 389
392 // ============================================================================= 392 // =============================================================================
393 DEFINE_ACTION (Rectifier, 0) 393 DEFINE_ACTION (Rectifier, 0)
394 { 394 {
395 setlocale (LC_ALL, "C"); 395 setlocale (LC_ALL, "C");
396 396
397 if (!checkProgPath (Rectifier)) 397 if (not checkProgPath (Rectifier))
398 return; 398 return;
399 399
400 QDialog* dlg = new QDialog; 400 QDialog* dlg = new QDialog;
401 Ui::RectifierUI ui; 401 Ui::RectifierUI ui;
402 ui.setupUi (dlg); 402 ui.setupUi (dlg);
403 403
404 if (!dlg->exec()) 404 if (not dlg->exec())
405 return; 405 return;
406 406
407 QTemporaryFile indat, outdat; 407 QTemporaryFile indat, outdat;
408 QString inDATName, outDATName; 408 QString inDATName, outDATName;
409 409
410 // Make temp files for the input and output files 410 // Make temp files for the input and output files
411 if (!mkTempFile (indat, inDATName) || !mkTempFile (outdat, outDATName)) 411 if (not mkTempFile (indat, inDATName) || not mkTempFile (outdat, outDATName))
412 return; 412 return;
413 413
414 // Compose arguments 414 // Compose arguments
415 QString argv = join ( 415 QString argv = join (
416 { 416 {
417 (!ui.cb_condense->isChecked()) ? "-q" : "", 417 (not ui.cb_condense->isChecked()) ? "-q" : "",
418 (!ui.cb_subst->isChecked()) ? "-r" : "", 418 (not ui.cb_subst->isChecked()) ? "-r" : "",
419 (ui.cb_condlineCheck->isChecked()) ? "-a" : "", 419 (ui.cb_condlineCheck->isChecked()) ? "-a" : "",
420 (ui.cb_colorize->isChecked()) ? "-c" : "", 420 (ui.cb_colorize->isChecked()) ? "-c" : "",
421 "-t", 421 "-t",
422 ui.dsb_coplthres->value(), 422 ui.dsb_coplthres->value(),
423 inDATName, 423 inDATName,
424 outDATName 424 outDATName
425 }); 425 });
426 426
427 writeSelection (inDATName); 427 writeSelection (inDATName);
428 428
429 if (!runUtilityProcess (Rectifier, prog_rectifier, argv)) 429 if (not runUtilityProcess (Rectifier, prog_rectifier, argv))
430 return; 430 return;
431 431
432 insertOutput (outDATName, true, {}); 432 insertOutput (outDATName, true, {});
433 } 433 }
434 434
437 // ============================================================================= 437 // =============================================================================
438 DEFINE_ACTION (Intersector, 0) 438 DEFINE_ACTION (Intersector, 0)
439 { 439 {
440 setlocale (LC_ALL, "C"); 440 setlocale (LC_ALL, "C");
441 441
442 if (!checkProgPath (Intersector)) 442 if (not checkProgPath (Intersector))
443 return; 443 return;
444 444
445 QDialog* dlg = new QDialog; 445 QDialog* dlg = new QDialog;
446 Ui::IntersectorUI ui; 446 Ui::IntersectorUI ui;
447 ui.setupUi (dlg); 447 ui.setupUi (dlg);
455 int inCol, cutCol; 455 int inCol, cutCol;
456 const bool repeatInverse = ui.cb_repeat->isChecked(); 456 const bool repeatInverse = ui.cb_repeat->isChecked();
457 457
458 forever 458 forever
459 { 459 {
460 if (!dlg->exec()) 460 if (not dlg->exec())
461 return; 461 return;
462 462
463 inCol = ui.cmb_incol->itemData (ui.cmb_incol->currentIndex()).toInt(); 463 inCol = ui.cmb_incol->itemData (ui.cmb_incol->currentIndex()).toInt();
464 cutCol = ui.cmb_cutcol->itemData (ui.cmb_cutcol->currentIndex()).toInt(); 464 cutCol = ui.cmb_cutcol->itemData (ui.cmb_cutcol->currentIndex()).toInt();
465 465
479 // outdat2 = inverse output 479 // outdat2 = inverse output
480 // edgesdat = edges output (isecalc) 480 // edgesdat = edges output (isecalc)
481 QTemporaryFile indat, cutdat, outdat, outdat2, edgesdat; 481 QTemporaryFile indat, cutdat, outdat, outdat2, edgesdat;
482 QString inDATName, cutDATName, outDATName, outDAT2Name, edgesDATName; 482 QString inDATName, cutDATName, outDATName, outDAT2Name, edgesDATName;
483 483
484 if (!mkTempFile (indat, inDATName) || !mkTempFile (cutdat, cutDATName) || 484 if (not mkTempFile (indat, inDATName) ||
485 !mkTempFile (outdat, outDATName) || !mkTempFile (outdat2, outDAT2Name) || 485 not mkTempFile (cutdat, cutDATName) ||
486 !mkTempFile (edgesdat, edgesDATName)) 486 not mkTempFile (outdat, outDATName) ||
487 not mkTempFile (outdat2, outDAT2Name) ||
488 not mkTempFile (edgesdat, edgesDATName))
487 { 489 {
488 return; 490 return;
489 } 491 }
490 492
491 QString parms = join ( 493 QString parms = join (
513 }); 515 });
514 516
515 writeColorGroup (inCol, inDATName); 517 writeColorGroup (inCol, inDATName);
516 writeColorGroup (cutCol, cutDATName); 518 writeColorGroup (cutCol, cutDATName);
517 519
518 if (!runUtilityProcess (Intersector, prog_intersector, argv_normal)) 520 if (not runUtilityProcess (Intersector, prog_intersector, argv_normal))
519 return; 521 return;
520 522
521 insertOutput (outDATName, false, {inCol}); 523 insertOutput (outDATName, false, {inCol});
522 524
523 if (repeatInverse && runUtilityProcess (Intersector, prog_intersector, argv_inverse)) 525 if (repeatInverse && runUtilityProcess (Intersector, prog_intersector, argv_inverse))
535 // 537 //
536 DEFINE_ACTION (Coverer, 0) 538 DEFINE_ACTION (Coverer, 0)
537 { 539 {
538 setlocale (LC_ALL, "C"); 540 setlocale (LC_ALL, "C");
539 541
540 if (!checkProgPath (Coverer)) 542 if (not checkProgPath (Coverer))
541 return; 543 return;
542 544
543 QDialog* dlg = new QDialog; 545 QDialog* dlg = new QDialog;
544 Ui::CovererUI ui; 546 Ui::CovererUI ui;
545 ui.setupUi (dlg); 547 ui.setupUi (dlg);
548 550
549 int in1Col, in2Col; 551 int in1Col, in2Col;
550 552
551 forever 553 forever
552 { 554 {
553 if (!dlg->exec()) 555 if (not dlg->exec())
554 return; 556 return;
555 557
556 in1Col = ui.cmb_col1->itemData (ui.cmb_col1->currentIndex()).toInt(); 558 in1Col = ui.cmb_col1->itemData (ui.cmb_col1->currentIndex()).toInt();
557 in2Col = ui.cmb_col2->itemData (ui.cmb_col2->currentIndex()).toInt(); 559 in2Col = ui.cmb_col2->itemData (ui.cmb_col2->currentIndex()).toInt();
558 560
566 } 568 }
567 569
568 QTemporaryFile in1dat, in2dat, outdat; 570 QTemporaryFile in1dat, in2dat, outdat;
569 QString in1DATName, in2DATName, outDATName; 571 QString in1DATName, in2DATName, outDATName;
570 572
571 if (!mkTempFile (in1dat, in1DATName) || !mkTempFile (in2dat, in2DATName) || !mkTempFile (outdat, outDATName)) 573 if (not mkTempFile (in1dat, in1DATName) ||
572 return; 574 not mkTempFile (in2dat, in2DATName) ||
575 not mkTempFile (outdat, outDATName))
576 {
577 return;
578 }
573 579
574 QString argv = join ( 580 QString argv = join (
575 { 581 {
576 (ui.cb_oldsweep->isChecked() ? "-s" : ""), 582 (ui.cb_oldsweep->isChecked() ? "-s" : ""),
577 (ui.cb_reverse->isChecked() ? "-r" : ""), 583 (ui.cb_reverse->isChecked() ? "-r" : ""),
583 }); 589 });
584 590
585 writeColorGroup (in1Col, in1DATName); 591 writeColorGroup (in1Col, in1DATName);
586 writeColorGroup (in2Col, in2DATName); 592 writeColorGroup (in2Col, in2DATName);
587 593
588 if (!runUtilityProcess (Coverer, prog_coverer, argv)) 594 if (not runUtilityProcess (Coverer, prog_coverer, argv))
589 return; 595 return;
590 596
591 insertOutput (outDATName, false, {}); 597 insertOutput (outDATName, false, {});
592 } 598 }
593 599
595 // 601 //
596 DEFINE_ACTION (Isecalc, 0) 602 DEFINE_ACTION (Isecalc, 0)
597 { 603 {
598 setlocale (LC_ALL, "C"); 604 setlocale (LC_ALL, "C");
599 605
600 if (!checkProgPath (Isecalc)) 606 if (not checkProgPath (Isecalc))
601 return; 607 return;
602 608
603 Ui::IsecalcUI ui; 609 Ui::IsecalcUI ui;
604 QDialog* dlg = new QDialog; 610 QDialog* dlg = new QDialog;
605 ui.setupUi (dlg); 611 ui.setupUi (dlg);
610 int in1Col, in2Col; 616 int in1Col, in2Col;
611 617
612 // Run the dialog and validate input 618 // Run the dialog and validate input
613 forever 619 forever
614 { 620 {
615 if (!dlg->exec()) 621 if (not dlg->exec())
616 return; 622 return;
617 623
618 in1Col = ui.cmb_col1->itemData (ui.cmb_col1->currentIndex()).toInt(), 624 in1Col = ui.cmb_col1->itemData (ui.cmb_col1->currentIndex()).toInt(),
619 in2Col = ui.cmb_col1->itemData (ui.cmb_col2->currentIndex()).toInt(); 625 in2Col = ui.cmb_col1->itemData (ui.cmb_col2->currentIndex()).toInt();
620 626
628 } 634 }
629 635
630 QTemporaryFile in1dat, in2dat, outdat; 636 QTemporaryFile in1dat, in2dat, outdat;
631 QString in1DATName, in2DATName, outDATName; 637 QString in1DATName, in2DATName, outDATName;
632 638
633 if (!mkTempFile (in1dat, in1DATName) || !mkTempFile (in2dat, in2DATName) || !mkTempFile (outdat, outDATName)) 639 if (not mkTempFile (in1dat, in1DATName) ||
634 return; 640 not mkTempFile (in2dat, in2DATName) ||
641 not mkTempFile (outdat, outDATName))
642 {
643 return;
644 }
635 645
636 QString argv = join ( 646 QString argv = join (
637 { 647 {
638 in1DATName, 648 in1DATName,
639 in2DATName, 649 in2DATName,
650 // 660 //
651 DEFINE_ACTION (Edger2, 0) 661 DEFINE_ACTION (Edger2, 0)
652 { 662 {
653 setlocale (LC_ALL, "C"); 663 setlocale (LC_ALL, "C");
654 664
655 if (!checkProgPath (Edger2)) 665 if (not checkProgPath (Edger2))
656 return; 666 return;
657 667
658 QDialog* dlg = new QDialog; 668 QDialog* dlg = new QDialog;
659 Ui::Edger2Dialog ui; 669 Ui::Edger2Dialog ui;
660 ui.setupUi (dlg); 670 ui.setupUi (dlg);
661 671
662 if (!dlg->exec()) 672 if (not dlg->exec())
663 return; 673 return;
664 674
665 QTemporaryFile in, out; 675 QTemporaryFile in, out;
666 QString inName, outName; 676 QString inName, outName;
667 677
668 if (!mkTempFile (in, inName) || !mkTempFile (out, outName)) 678 if (not mkTempFile (in, inName) || not mkTempFile (out, outName))
669 return; 679 return;
670 680
671 int unmatched = ui.unmatched->currentIndex(); 681 int unmatched = ui.unmatched->currentIndex();
672 682
673 QString argv = join ( 683 QString argv = join (
687 outName, 697 outName,
688 }); 698 });
689 699
690 writeSelection (inName); 700 writeSelection (inName);
691 701
692 if (!runUtilityProcess (Edger2, prog_edger2, argv)) 702 if (not runUtilityProcess (Edger2, prog_edger2, argv))
693 return; 703 return;
694 704
695 insertOutput (outName, true, {}); 705 insertOutput (outName, true, {});
696 } 706 }

mercurial