src/extprogs.cc

changeset 606
3dd6f343ec06
parent 604
01bdac75994a
child 609
a8dc74a809c6
equal deleted inserted replaced
605:2983f7c7e7c9 606:3dd6f343ec06
56 cfg (String, prog_coverer, ""); 56 cfg (String, prog_coverer, "");
57 cfg (String, prog_ytruder, ""); 57 cfg (String, prog_ytruder, "");
58 cfg (String, prog_rectifier, ""); 58 cfg (String, prog_rectifier, "");
59 cfg (String, prog_edger2, ""); 59 cfg (String, prog_edger2, "");
60 60
61 str* const g_extProgPaths[] = 61 QString* const g_extProgPaths[] =
62 { 62 {
63 &prog_isecalc, 63 &prog_isecalc,
64 &prog_intersector, 64 &prog_intersector,
65 &prog_coverer, 65 &prog_coverer,
66 &prog_ytruder, 66 &prog_ytruder,
99 99
100 // ============================================================================= 100 // =============================================================================
101 // ----------------------------------------------------------------------------- 101 // -----------------------------------------------------------------------------
102 static bool checkProgPath (const extprog prog) 102 static bool checkProgPath (const extprog prog)
103 { 103 {
104 str& path = *g_extProgPaths[prog]; 104 QString& path = *g_extProgPaths[prog];
105 105
106 if (path.length() > 0) 106 if (path.length() > 0)
107 return true; 107 return true;
108 108
109 ExtProgPathPrompt* dlg = new ExtProgPathPrompt (g_extProgNames[prog]); 109 ExtProgPathPrompt* dlg = new ExtProgPathPrompt (g_extProgNames[prog]);
117 return false; 117 return false;
118 } 118 }
119 119
120 // ============================================================================= 120 // =============================================================================
121 // ----------------------------------------------------------------------------- 121 // -----------------------------------------------------------------------------
122 static str processErrorString (extprog prog, QProcess& proc) 122 static QString processErrorString (extprog prog, QProcess& proc)
123 { 123 {
124 switch (proc.error()) 124 switch (proc.error())
125 { 125 {
126 case QProcess::FailedToStart: 126 case QProcess::FailedToStart:
127 { 127 {
128 str wineblurb; 128 QString wineblurb;
129 129
130 #ifndef _WIN32 130 #ifndef _WIN32
131 if (*g_extProgWine[prog]) 131 if (*g_extProgWine[prog])
132 wineblurb = "make sure Wine is installed and "; 132 wineblurb = "make sure Wine is installed and ";
133 #endif 133 #endif
152 return ""; 152 return "";
153 } 153 }
154 154
155 // ============================================================================= 155 // =============================================================================
156 // ----------------------------------------------------------------------------- 156 // -----------------------------------------------------------------------------
157 static bool mkTempFile (QTemporaryFile& tmp, str& fname) 157 static bool mkTempFile (QTemporaryFile& tmp, QString& fname)
158 { 158 {
159 if (!tmp.open()) 159 if (!tmp.open())
160 return false; 160 return false;
161 161
162 fname = tmp.fileName(); 162 fname = tmp.fileName();
185 } 185 }
186 } 186 }
187 187
188 // ============================================================================= 188 // =============================================================================
189 // ----------------------------------------------------------------------------- 189 // -----------------------------------------------------------------------------
190 static void writeObjects (const QList<LDObject*>& objects, str fname) 190 static void writeObjects (const QList<LDObject*>& objects, QString fname)
191 { 191 {
192 // Write the input file 192 // Write the input file
193 File f (fname, File::Write); 193 File f (fname, File::Write);
194 194
195 if (!f) 195 if (!f)
206 #endif 206 #endif
207 } 207 }
208 208
209 // ============================================================================= 209 // =============================================================================
210 // ----------------------------------------------------------------------------- 210 // -----------------------------------------------------------------------------
211 void writeSelection (str fname) 211 void writeSelection (QString fname)
212 { 212 {
213 writeObjects (selection(), fname); 213 writeObjects (selection(), fname);
214 } 214 }
215 215
216 // ============================================================================= 216 // =============================================================================
217 // ----------------------------------------------------------------------------- 217 // -----------------------------------------------------------------------------
218 void writeColorGroup (const int colnum, str fname) 218 void writeColorGroup (const int colnum, QString fname)
219 { 219 {
220 QList<LDObject*> objects; 220 QList<LDObject*> objects;
221 221
222 for (LDObject* obj : getCurrentDocument()->getObjects()) 222 for (LDObject* obj : getCurrentDocument()->getObjects())
223 { 223 {
230 writeObjects (objects, fname); 230 writeObjects (objects, fname);
231 } 231 }
232 232
233 // ============================================================================= 233 // =============================================================================
234 // ----------------------------------------------------------------------------- 234 // -----------------------------------------------------------------------------
235 bool runUtilityProcess (extprog prog, str path, str argvstr) 235 bool runUtilityProcess (extprog prog, QString path, QString argvstr)
236 { 236 {
237 QTemporaryFile input, output; 237 QTemporaryFile input, output;
238 str inputname, outputname; 238 QString inputname, outputname;
239 QStringList argv = argvstr.split (" ", QString::SkipEmptyParts); 239 QStringList argv = argvstr.split (" ", QString::SkipEmptyParts);
240 240
241 #ifndef _WIN32 241 #ifndef _WIN32
242 if (*g_extProgWine[prog]) 242 if (*g_extProgWine[prog])
243 { 243 {
271 stdinfp.write ("\n"); 271 stdinfp.write ("\n");
272 272
273 // Wait while it runs 273 // Wait while it runs
274 proc.waitForFinished(); 274 proc.waitForFinished();
275 275
276 str err = ""; 276 QString err = "";
277 277
278 if (proc.exitStatus() != QProcess::NormalExit) 278 if (proc.exitStatus() != QProcess::NormalExit)
279 err = processErrorString (prog, proc); 279 err = processErrorString (prog, proc);
280 280
281 // Check the return code 281 // Check the return code
291 return true; 291 return true;
292 } 292 }
293 293
294 // ============================================================================= 294 // =============================================================================
295 // ----------------------------------------------------------------------------- 295 // -----------------------------------------------------------------------------
296 static void insertOutput (str fname, bool replace, QList<int> colorsToReplace) 296 static void insertOutput (QString fname, bool replace, QList<int> colorsToReplace)
297 { 297 {
298 #ifdef DEBUG 298 #ifdef DEBUG
299 QFile::copy (fname, "./debug_lastOutput"); 299 QFile::copy (fname, "./debug_lastOutput");
300 #endif // RELEASE 300 #endif // RELEASE
301 301
364 364
365 const double depth = ui.planeDepth->value(), 365 const double depth = ui.planeDepth->value(),
366 condAngle = ui.condAngle->value(); 366 condAngle = ui.condAngle->value();
367 367
368 QTemporaryFile indat, outdat; 368 QTemporaryFile indat, outdat;
369 str inDATName, outDATName; 369 QString inDATName, outDATName;
370 370
371 // Make temp files for the input and output files 371 // Make temp files for the input and output files
372 if (!mkTempFile (indat, inDATName) || !mkTempFile (outdat, outDATName)) 372 if (!mkTempFile (indat, inDATName) || !mkTempFile (outdat, outDATName))
373 return; 373 return;
374 374
375 // Compose the command-line arguments 375 // Compose the command-line arguments
376 str argv = join ( 376 QString argv = join (
377 { 377 {
378 (axis == X) ? "-x" : (axis == Y) ? "-y" : "-z", 378 (axis == X) ? "-x" : (axis == Y) ? "-y" : "-z",
379 (mode == Distance) ? "-d" : (mode == Symmetry) ? "-s" : (mode == Projection) ? "-p" : "-r", 379 (mode == Distance) ? "-d" : (mode == Symmetry) ? "-s" : (mode == Projection) ? "-p" : "-r",
380 depth, 380 depth,
381 "-a", 381 "-a",
408 408
409 if (!dlg->exec()) 409 if (!dlg->exec())
410 return; 410 return;
411 411
412 QTemporaryFile indat, outdat; 412 QTemporaryFile indat, outdat;
413 str inDATName, outDATName; 413 QString inDATName, outDATName;
414 414
415 // Make temp files for the input and output files 415 // Make temp files for the input and output files
416 if (!mkTempFile (indat, inDATName) || !mkTempFile (outdat, outDATName)) 416 if (!mkTempFile (indat, inDATName) || !mkTempFile (outdat, outDATName))
417 return; 417 return;
418 418
419 // Compose arguments 419 // Compose arguments
420 str argv = join ( 420 QString argv = join (
421 { 421 {
422 (!ui.cb_condense->isChecked()) ? "-q" : "", 422 (!ui.cb_condense->isChecked()) ? "-q" : "",
423 (!ui.cb_subst->isChecked()) ? "-r" : "", 423 (!ui.cb_subst->isChecked()) ? "-r" : "",
424 (ui.cb_condlineCheck->isChecked()) ? "-a" : "", 424 (ui.cb_condlineCheck->isChecked()) ? "-a" : "",
425 (ui.cb_colorize->isChecked()) ? "-c" : "", 425 (ui.cb_colorize->isChecked()) ? "-c" : "",
482 // cutdat = cutter group file 482 // cutdat = cutter group file
483 // outdat = primary output 483 // outdat = primary output
484 // outdat2 = inverse output 484 // outdat2 = inverse output
485 // edgesdat = edges output (isecalc) 485 // edgesdat = edges output (isecalc)
486 QTemporaryFile indat, cutdat, outdat, outdat2, edgesdat; 486 QTemporaryFile indat, cutdat, outdat, outdat2, edgesdat;
487 str inDATName, cutDATName, outDATName, outDAT2Name, edgesDATName; 487 QString inDATName, cutDATName, outDATName, outDAT2Name, edgesDATName;
488 488
489 if (!mkTempFile (indat, inDATName) || !mkTempFile (cutdat, cutDATName) || 489 if (!mkTempFile (indat, inDATName) || !mkTempFile (cutdat, cutDATName) ||
490 !mkTempFile (outdat, outDATName) || !mkTempFile (outdat2, outDAT2Name) || 490 !mkTempFile (outdat, outDATName) || !mkTempFile (outdat2, outDAT2Name) ||
491 !mkTempFile (edgesdat, edgesDATName)) 491 !mkTempFile (edgesdat, edgesDATName))
492 { 492 {
493 return; 493 return;
494 } 494 }
495 495
496 str parms = join ( 496 QString parms = join (
497 { 497 {
498 (ui.cb_colorize->isChecked()) ? "-c" : "", 498 (ui.cb_colorize->isChecked()) ? "-c" : "",
499 (ui.cb_nocondense->isChecked()) ? "-t" : "", 499 (ui.cb_nocondense->isChecked()) ? "-t" : "",
500 "-s", 500 "-s",
501 ui.dsb_prescale->value() 501 ui.dsb_prescale->value()
502 }); 502 });
503 503
504 str argv_normal = join ( 504 QString argv_normal = join (
505 { 505 {
506 parms, 506 parms,
507 inDATName, 507 inDATName,
508 cutDATName, 508 cutDATName,
509 outDATName 509 outDATName
510 }); 510 });
511 511
512 str argv_inverse = join ( 512 QString argv_inverse = join (
513 { 513 {
514 parms, 514 parms,
515 cutDATName, 515 cutDATName,
516 inDATName, 516 inDATName,
517 outDAT2Name 517 outDAT2Name
569 569
570 break; 570 break;
571 } 571 }
572 572
573 QTemporaryFile in1dat, in2dat, outdat; 573 QTemporaryFile in1dat, in2dat, outdat;
574 str in1DATName, in2DATName, outDATName; 574 QString in1DATName, in2DATName, outDATName;
575 575
576 if (!mkTempFile (in1dat, in1DATName) || !mkTempFile (in2dat, in2DATName) || !mkTempFile (outdat, outDATName)) 576 if (!mkTempFile (in1dat, in1DATName) || !mkTempFile (in2dat, in2DATName) || !mkTempFile (outdat, outDATName))
577 return; 577 return;
578 578
579 str argv = join ( 579 QString argv = join (
580 { 580 {
581 (ui.cb_oldsweep->isChecked() ? "-s" : ""), 581 (ui.cb_oldsweep->isChecked() ? "-s" : ""),
582 (ui.cb_reverse->isChecked() ? "-r" : ""), 582 (ui.cb_reverse->isChecked() ? "-r" : ""),
583 (ui.dsb_segsplit->value() != 0 ? fmt ("-l %1", ui.dsb_segsplit->value()) : ""), 583 (ui.dsb_segsplit->value() != 0 ? fmt ("-l %1", ui.dsb_segsplit->value()) : ""),
584 (ui.sb_bias->value() != 0 ? fmt ("-s %1", ui.sb_bias->value()) : ""), 584 (ui.sb_bias->value() != 0 ? fmt ("-s %1", ui.sb_bias->value()) : ""),
631 631
632 break; 632 break;
633 } 633 }
634 634
635 QTemporaryFile in1dat, in2dat, outdat; 635 QTemporaryFile in1dat, in2dat, outdat;
636 str in1DATName, in2DATName, outDATName; 636 QString in1DATName, in2DATName, outDATName;
637 637
638 if (!mkTempFile (in1dat, in1DATName) || !mkTempFile (in2dat, in2DATName) || !mkTempFile (outdat, outDATName)) 638 if (!mkTempFile (in1dat, in1DATName) || !mkTempFile (in2dat, in2DATName) || !mkTempFile (outdat, outDATName))
639 return; 639 return;
640 640
641 str argv = join ( 641 QString argv = join (
642 { 642 {
643 in1DATName, 643 in1DATName,
644 in2DATName, 644 in2DATName,
645 outDATName 645 outDATName
646 }); 646 });
666 666
667 if (!dlg->exec()) 667 if (!dlg->exec())
668 return; 668 return;
669 669
670 QTemporaryFile in, out; 670 QTemporaryFile in, out;
671 str inName, outName; 671 QString inName, outName;
672 672
673 if (!mkTempFile (in, inName) || !mkTempFile (out, outName)) 673 if (!mkTempFile (in, inName) || !mkTempFile (out, outName))
674 return; 674 return;
675 675
676 int unmatched = ui.unmatched->currentIndex(); 676 int unmatched = ui.unmatched->currentIndex();
677 677
678 str argv = join ( 678 QString argv = join (
679 { 679 {
680 fmt ("-p %1", ui.precision->value()), 680 fmt ("-p %1", ui.precision->value()),
681 fmt ("-af %1", ui.flatAngle->value()), 681 fmt ("-af %1", ui.flatAngle->value()),
682 fmt ("-ac %1", ui.condAngle->value()), 682 fmt ("-ac %1", ui.condAngle->value()),
683 fmt ("-ae %1", ui.edgeAngle->value()), 683 fmt ("-ae %1", ui.edgeAngle->value()),

mercurial