Added Coverer interface

Tue, 14 May 2013 18:32:34 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 14 May 2013 18:32:34 +0300
changeset 203
ccde5e88f0b6
parent 202
a027f6fc6141
child 204
7476044c6c29

Added Coverer interface

src/configDialog.cpp file | annotate | diff | comparison | revisions
src/extprogs.cpp file | annotate | diff | comparison | revisions
src/extprogs.h file | annotate | diff | comparison | revisions
src/gui.cpp file | annotate | diff | comparison | revisions
src/gui_editactions.cpp file | annotate | diff | comparison | revisions
--- a/src/configDialog.cpp	Tue May 14 18:00:50 2013 +0300
+++ b/src/configDialog.cpp	Tue May 14 18:32:34 2013 +0300
@@ -315,6 +315,7 @@
 extern_cfg (str, prog_ytruder);
 extern_cfg (str, prog_rectifier);
 extern_cfg (str, prog_intersector);
+extern_cfg (str, prog_coverer);
 extern_cfg (str, prog_isecalc);
 static const struct extProgInfo {
 	const char* const name, *iconname;
@@ -326,6 +327,7 @@
 	{ "Rectifier", "rectifier", &prog_rectifier, null, null },
 	{ "Intersector", "intersector", &prog_intersector, null, null },
 	{ "Isecalc", "isecalc", &prog_isecalc, null, null },
+	{ "Coverer", "coverer", &prog_coverer, null, null },
 };
 
 void ConfigDialog::initExtProgTab () {
--- a/src/extprogs.cpp	Tue May 14 18:00:50 2013 +0300
+++ b/src/extprogs.cpp	Tue May 14 18:32:34 2013 +0300
@@ -23,6 +23,7 @@
 #include <QSpinBox>
 #include <QCheckBox>
 #include <QComboBox>
+#include <QGridLayout>
 
 #include "common.h"
 #include "config.h"
@@ -353,6 +354,12 @@
 	insertOutput (outDATName, true, {});
 }
 
+LabeledWidget<QComboBox>* buildColorSelector (const char* label) {
+	LabeledWidget<QComboBox>* widget = new LabeledWidget<QComboBox> (label, new QComboBox);
+	makeColorSelector (widget->w ());
+	return widget;
+}
+
 // =======================================================================================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =======================================================================================================================================
@@ -365,8 +372,8 @@
 	
 	QDialog dlg;
 	
-	LabeledWidget<QComboBox>* cmb_incol = new LabeledWidget<QComboBox> ("Input", new QComboBox),
-		*cmb_cutcol = new LabeledWidget<QComboBox> ("Cutter", new QComboBox);
+	LabeledWidget<QComboBox>* cmb_incol = buildColorSelector ("Input"),
+		*cmb_cutcol = buildColorSelector ("Cutter");
 	QCheckBox* cb_colorize = new QCheckBox ("Colorize output"),
 		*cb_nocondense = new QCheckBox ("No condensing"),
 		*cb_repeatInverse = new QCheckBox ("Repeat inverse"),
@@ -377,8 +384,6 @@
 		" cutter group with the input group. Both groups are cut by the intersection.");
 	cb_edges->setWhatsThis ("Makes " APPNAME " try run Isecalc to create edgelines for the intersection.");
 	
-	makeColorSelector (cmb_incol->w ());
-	makeColorSelector (cmb_cutcol->w ());
 	dsb_prescale->w ()->setMinimum (0.0f);
 	dsb_prescale->w ()->setMaximum (10000.0f);
 	dsb_prescale->w ()->setSingleStep (0.01f);
@@ -452,4 +457,75 @@
 		runUtilityProcess (Isecalc, prog_isecalc, fmt ("%s %s %s", inDATName.chars (), cutDATName.chars (), edgesDATName.chars ()));
 		insertOutput (edgesDATName, false, {});
 	}
+}
+
+// =======================================================================================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =======================================================================================================================================
+void runCoverer () {
+	setlocale (LC_ALL, "C");
+	
+	if (!checkProgPath (prog_coverer, Coverer))
+		return;
+	
+	QDialog dlg;
+	
+	LabeledWidget<QComboBox>* cmb_col1 = buildColorSelector ("Shape 1"),
+		*cmb_col2 = buildColorSelector ("Shape 2");
+	
+	QDoubleSpinBox* dsb_segsplit = new QDoubleSpinBox;
+	QLabel* lb_segsplit = new QLabel ("Segment split length:");
+	QSpinBox* sb_bias = new QSpinBox;
+	QLabel* lb_bias = new QLabel ("Bias:");
+	QCheckBox* cb_reverse = new QCheckBox ("Reverse shape 2"),
+		*cb_oldsweep = new QCheckBox ("Old sweep method");
+	
+	dsb_segsplit->setSpecialValueText ("No splitting");
+	dsb_segsplit->setRange (0.0f, 10000.0f);
+	sb_bias->setSpecialValueText ("No bias");
+	sb_bias->setRange (-100, 100);
+	
+	QGridLayout* spinboxlayout = new QGridLayout;
+	spinboxlayout->addWidget (lb_segsplit, 0, 0);
+	spinboxlayout->addWidget (dsb_segsplit, 0, 1);
+	spinboxlayout->addWidget (lb_bias, 1, 0);
+	spinboxlayout->addWidget (sb_bias, 1, 1);
+	
+	QVBoxLayout* layout = new QVBoxLayout (&dlg);
+	layout->addWidget (cmb_col1);
+	layout->addWidget (cmb_col2);
+	layout->addLayout (spinboxlayout);
+	layout->addWidget (cb_reverse);
+	layout->addWidget (cb_oldsweep);
+	layout->addWidget (makeButtonBox (dlg));
+	
+exec:
+	if (!dlg.exec ())
+		return;
+	
+	const short in1Col = cmb_col1->w ()->itemData (cmb_col1->w ()->currentIndex ()).toInt (),
+		in2Col = cmb_col1->w ()->itemData (cmb_col2->w ()->currentIndex ()).toInt ();
+	
+	if (in1Col == in2Col) {
+		critical ("Cannot use the same color group for both input and cutter!");
+		goto exec;
+	}
+	
+	QTemporaryFile in1dat, in2dat, outdat;
+	str in1DATName, in2DATName, outDATName;
+	
+	if (!mkTempFile (in1dat, in1DATName) || !mkTempFile (in2dat, in2DATName) || !mkTempFile (outdat, outDATName))
+		return;
+	
+	str argv = fmt ("%s %s %s %s %s %s %s",
+		(cb_oldsweep->isChecked () ? "-s" : ""),
+		(cb_reverse->isChecked () ? "-r" : ""),
+		(dsb_segsplit->value () != 0 ? fmt ("-l %f", dsb_segsplit->value ()).c () : ""),
+		(sb_bias->value () != 0 ? fmt ("-s %d", sb_bias->value ()).c () : ""),
+		in1DATName.c (), in2DATName.c (), outDATName.c ());
+	
+	writeColorGroup (in1Col, in1DATName);
+	writeColorGroup (in2Col, in2DATName);
+	runUtilityProcess (Coverer, prog_coverer, argv);
+	insertOutput (outDATName, false, {});
 }
\ No newline at end of file
--- a/src/extprogs.h	Tue May 14 18:00:50 2013 +0300
+++ b/src/extprogs.h	Tue May 14 18:32:34 2013 +0300
@@ -33,5 +33,6 @@
 void runYtruder ();
 void runRectifier ();
 void runIntersector ();
+void runCoverer ();
 
 #endif // EXTPROGS_H
\ No newline at end of file
--- a/src/gui.cpp	Tue May 14 18:00:50 2013 +0300
+++ b/src/gui.cpp	Tue May 14 18:32:34 2013 +0300
@@ -246,6 +246,7 @@
 	addMenuAction ("ytruder");
 	addMenuAction ("rectifier");
 	addMenuAction ("intersector");
+	addMenuAction ("coverer");
 	
 	// Help menu
 	initMenu ("&Help");
@@ -394,6 +395,7 @@
 	addToolBarAction ("ytruder");
 	addToolBarAction ("rectifier");
 	addToolBarAction ("intersector");
+	addToolBarAction ("coverer");
 	updateToolBars ();
 }
 
--- a/src/gui_editactions.cpp	Tue May 14 18:00:50 2013 +0300
+++ b/src/gui_editactions.cpp	Tue May 14 18:32:34 2013 +0300
@@ -668,18 +668,22 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-MAKE_ACTION (ytruder, "Ytruder", "ytruder", "Extrude selected lines to a given plane", KEY (F4)) {
+MAKE_ACTION (ytruder, "Ytruder", "ytruder", "Extrude selected lines to a given plane", (0)) {
 	runYtruder ();
 }
 
-MAKE_ACTION (rectifier, "Rectifier", "rectifier", "Optimizes quads into rect primitives.", KEY (F8)) {
+MAKE_ACTION (rectifier, "Rectifier", "rectifier", "Optimizes quads into rect primitives.", (0)) {
 	runRectifier ();
 }
 
-MAKE_ACTION (intersector, "Intersector", "intersector", "Perform clipping between two input groups.", KEY (F5)) {
+MAKE_ACTION (intersector, "Intersector", "intersector", "Perform clipping between two input groups.", (0)) {
 	runIntersector ();
 }
 
+MAKE_ACTION (coverer, "Coverer", "coverer", "Fill the space between two line shapes", (0)) {
+	runCoverer ();
+}
+
 // =========================================================================================================================================
 MAKE_ACTION (replaceCoords, "Replace Coordinates", "replace-coords", "Find and replace coordinate values", CTRL (R)) {
 	ReplaceCoordsDialog dlg;

mercurial