src/extPrograms.cc

changeset 739
152b33a6d51b
parent 714
b4a990f59a5e
child 757
8ab9fa53142b
equal deleted inserted replaced
738:16b63398aa1f 739:152b33a6d51b
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 QString* const g_extProgPaths[] = 61 String* 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,
97 "Edger2" 97 "Edger2"
98 }; 98 };
99 99
100 // ============================================================================= 100 // =============================================================================
101 // 101 //
102 static bool mkTempFile (QTemporaryFile& tmp, QString& fname) 102 static bool mkTempFile (QTemporaryFile& tmp, String& fname)
103 { 103 {
104 if (not tmp.open()) 104 if (not tmp.open())
105 return false; 105 return false;
106 106
107 fname = tmp.fileName(); 107 fname = tmp.fileName();
111 111
112 // ============================================================================= 112 // =============================================================================
113 // 113 //
114 static bool checkProgPath (const extprog prog) 114 static bool checkProgPath (const extprog prog)
115 { 115 {
116 QString& path = *g_extProgPaths[prog]; 116 String& path = *g_extProgPaths[prog];
117 117
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]);
129 return false; 129 return false;
130 } 130 }
131 131
132 // ============================================================================= 132 // =============================================================================
133 // 133 //
134 static QString processErrorString (extprog prog, QProcess& proc) 134 static String processErrorString (extprog prog, QProcess& proc)
135 { 135 {
136 switch (proc.error()) 136 switch (proc.error())
137 { 137 {
138 case QProcess::FailedToStart: 138 case QProcess::FailedToStart:
139 { 139 {
140 QString wineblurb; 140 String wineblurb;
141 141
142 #ifndef _WIN32 142 #ifndef _WIN32
143 if (*g_extProgWine[prog]) 143 if (*g_extProgWine[prog])
144 wineblurb = "make sure Wine is installed and "; 144 wineblurb = "make sure Wine is installed and ";
145 #endif 145 #endif
185 } 185 }
186 } 186 }
187 187
188 // ============================================================================= 188 // =============================================================================
189 // 189 //
190 static void writeObjects (const LDObjectList& objects, QString fname) 190 static void writeObjects (const LDObjectList& objects, String 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 (not f.open (QIODevice::WriteOnly | QIODevice::Text)) 195 if (not f.open (QIODevice::WriteOnly | QIODevice::Text))
206 #endif 206 #endif
207 } 207 }
208 208
209 // ============================================================================= 209 // =============================================================================
210 // 210 //
211 void writeSelection (QString fname) 211 void writeSelection (String 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, QString fname) 218 void writeColorGroup (const int colnum, String fname)
219 { 219 {
220 LDObjectList objects; 220 LDObjectList objects;
221 221
222 for (LDObject* obj : getCurrentDocument()->objects()) 222 for (LDObject* obj : getCurrentDocument()->objects())
223 { 223 {
230 writeObjects (objects, fname); 230 writeObjects (objects, fname);
231 } 231 }
232 232
233 // ============================================================================= 233 // =============================================================================
234 // 234 //
235 bool runUtilityProcess (extprog prog, QString path, QString argvstr) 235 bool runUtilityProcess (extprog prog, String path, String argvstr)
236 { 236 {
237 QTemporaryFile input; 237 QTemporaryFile input;
238 QStringList argv = argvstr.split (" ", QString::SkipEmptyParts); 238 QStringList argv = argvstr.split (" ", String::SkipEmptyParts);
239 239
240 #ifndef _WIN32 240 #ifndef _WIN32
241 if (*g_extProgWine[prog]) 241 if (*g_extProgWine[prog])
242 { 242 {
243 argv.insert (0, path); 243 argv.insert (0, path);
266 input.write ("\n"); 266 input.write ("\n");
267 267
268 // Wait while it runs 268 // Wait while it runs
269 proc.waitForFinished(); 269 proc.waitForFinished();
270 270
271 QString err = ""; 271 String err = "";
272 272
273 if (proc.exitStatus() != QProcess::NormalExit) 273 if (proc.exitStatus() != QProcess::NormalExit)
274 err = processErrorString (prog, proc); 274 err = processErrorString (prog, proc);
275 275
276 // Check the return code 276 // Check the return code
286 return true; 286 return true;
287 } 287 }
288 288
289 // ============================================================================= 289 // =============================================================================
290 // 290 //
291 static void insertOutput (QString fname, bool replace, QList<int> colorsToReplace) 291 static void insertOutput (String fname, bool replace, QList<int> colorsToReplace)
292 { 292 {
293 #ifdef DEBUG 293 #ifdef DEBUG
294 QFile::copy (fname, "./debug_lastOutput"); 294 QFile::copy (fname, "./debug_lastOutput");
295 #endif // RELEASE 295 #endif // RELEASE
296 296
359 359
360 const double depth = ui.planeDepth->value(), 360 const double depth = ui.planeDepth->value(),
361 condAngle = ui.condAngle->value(); 361 condAngle = ui.condAngle->value();
362 362
363 QTemporaryFile indat, outdat; 363 QTemporaryFile indat, outdat;
364 QString inDATName, outDATName; 364 String 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 (not mkTempFile (indat, inDATName) || not 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 String argv = join (
372 { 372 {
373 (axis == X) ? "-x" : (axis == Y) ? "-y" : "-z", 373 (axis == X) ? "-x" : (axis == Y) ? "-y" : "-z",
374 (mode == Distance) ? "-d" : (mode == Symmetry) ? "-s" : (mode == Projection) ? "-p" : "-r", 374 (mode == Distance) ? "-d" : (mode == Symmetry) ? "-s" : (mode == Projection) ? "-p" : "-r",
375 depth, 375 depth,
376 "-a", 376 "-a",
403 403
404 if (not 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 String 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 (not mkTempFile (indat, inDATName) || not 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 String argv = join (
416 { 416 {
417 (not ui.cb_condense->isChecked()) ? "-q" : "", 417 (not ui.cb_condense->isChecked()) ? "-q" : "",
418 (not 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" : "",
477 // cutdat = cutter group file 477 // cutdat = cutter group file
478 // outdat = primary output 478 // outdat = primary output
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 String inDATName, cutDATName, outDATName, outDAT2Name, edgesDATName;
483 483
484 if (not mkTempFile (indat, inDATName) || 484 if (not mkTempFile (indat, inDATName) ||
485 not mkTempFile (cutdat, cutDATName) || 485 not mkTempFile (cutdat, cutDATName) ||
486 not mkTempFile (outdat, outDATName) || 486 not mkTempFile (outdat, outDATName) ||
487 not mkTempFile (outdat2, outDAT2Name) || 487 not mkTempFile (outdat2, outDAT2Name) ||
488 not mkTempFile (edgesdat, edgesDATName)) 488 not mkTempFile (edgesdat, edgesDATName))
489 { 489 {
490 return; 490 return;
491 } 491 }
492 492
493 QString parms = join ( 493 String parms = join (
494 { 494 {
495 (ui.cb_colorize->isChecked()) ? "-c" : "", 495 (ui.cb_colorize->isChecked()) ? "-c" : "",
496 (ui.cb_nocondense->isChecked()) ? "-t" : "", 496 (ui.cb_nocondense->isChecked()) ? "-t" : "",
497 "-s", 497 "-s",
498 ui.dsb_prescale->value() 498 ui.dsb_prescale->value()
499 }); 499 });
500 500
501 QString argv_normal = join ( 501 String argv_normal = join (
502 { 502 {
503 parms, 503 parms,
504 inDATName, 504 inDATName,
505 cutDATName, 505 cutDATName,
506 outDATName 506 outDATName
507 }); 507 });
508 508
509 QString argv_inverse = join ( 509 String argv_inverse = join (
510 { 510 {
511 parms, 511 parms,
512 cutDATName, 512 cutDATName,
513 inDATName, 513 inDATName,
514 outDAT2Name 514 outDAT2Name
566 566
567 break; 567 break;
568 } 568 }
569 569
570 QTemporaryFile in1dat, in2dat, outdat; 570 QTemporaryFile in1dat, in2dat, outdat;
571 QString in1DATName, in2DATName, outDATName; 571 String in1DATName, in2DATName, outDATName;
572 572
573 if (not mkTempFile (in1dat, in1DATName) || 573 if (not mkTempFile (in1dat, in1DATName) ||
574 not mkTempFile (in2dat, in2DATName) || 574 not mkTempFile (in2dat, in2DATName) ||
575 not mkTempFile (outdat, outDATName)) 575 not mkTempFile (outdat, outDATName))
576 { 576 {
577 return; 577 return;
578 } 578 }
579 579
580 QString argv = join ( 580 String argv = join (
581 { 581 {
582 (ui.cb_oldsweep->isChecked() ? "-s" : ""), 582 (ui.cb_oldsweep->isChecked() ? "-s" : ""),
583 (ui.cb_reverse->isChecked() ? "-r" : ""), 583 (ui.cb_reverse->isChecked() ? "-r" : ""),
584 (ui.dsb_segsplit->value() != 0 ? format ("-l %1", ui.dsb_segsplit->value()) : ""), 584 (ui.dsb_segsplit->value() != 0 ? format ("-l %1", ui.dsb_segsplit->value()) : ""),
585 (ui.sb_bias->value() != 0 ? format ("-s %1", ui.sb_bias->value()) : ""), 585 (ui.sb_bias->value() != 0 ? format ("-s %1", ui.sb_bias->value()) : ""),
632 632
633 break; 633 break;
634 } 634 }
635 635
636 QTemporaryFile in1dat, in2dat, outdat; 636 QTemporaryFile in1dat, in2dat, outdat;
637 QString in1DATName, in2DATName, outDATName; 637 String in1DATName, in2DATName, outDATName;
638 638
639 if (not mkTempFile (in1dat, in1DATName) || 639 if (not mkTempFile (in1dat, in1DATName) ||
640 not mkTempFile (in2dat, in2DATName) || 640 not mkTempFile (in2dat, in2DATName) ||
641 not mkTempFile (outdat, outDATName)) 641 not mkTempFile (outdat, outDATName))
642 { 642 {
643 return; 643 return;
644 } 644 }
645 645
646 QString argv = join ( 646 String argv = join (
647 { 647 {
648 in1DATName, 648 in1DATName,
649 in2DATName, 649 in2DATName,
650 outDATName 650 outDATName
651 }); 651 });
671 671
672 if (not dlg->exec()) 672 if (not dlg->exec())
673 return; 673 return;
674 674
675 QTemporaryFile in, out; 675 QTemporaryFile in, out;
676 QString inName, outName; 676 String inName, outName;
677 677
678 if (not mkTempFile (in, inName) || not mkTempFile (out, outName)) 678 if (not mkTempFile (in, inName) || not mkTempFile (out, outName))
679 return; 679 return;
680 680
681 int unmatched = ui.unmatched->currentIndex(); 681 int unmatched = ui.unmatched->currentIndex();
682 682
683 QString argv = join ( 683 String argv = join (
684 { 684 {
685 format ("-p %1", ui.precision->value()), 685 format ("-p %1", ui.precision->value()),
686 format ("-af %1", ui.flatAngle->value()), 686 format ("-af %1", ui.flatAngle->value()),
687 format ("-ac %1", ui.condAngle->value()), 687 format ("-ac %1", ui.condAngle->value()),
688 format ("-ae %1", ui.edgeAngle->value()), 688 format ("-ae %1", ui.edgeAngle->value()),

mercurial