Mon, 06 May 2013 12:50:20 +0300
Further ytruder support
extprogs.cpp | file | annotate | diff | comparison | revisions | |
extprogs.h | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
icons/ytruder.png | file | annotate | diff | comparison | revisions | |
ldforge.qrc | file | annotate | diff | comparison | revisions |
--- a/extprogs.cpp Mon May 06 03:32:00 2013 +0300 +++ b/extprogs.cpp Mon May 06 12:50:20 2013 +0300 @@ -16,15 +16,20 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <qprocess.h> +#include <qtemporaryfile.h> +#include <qeventloop.h> +#include <qdialog.h> +#include <qdialogbuttonbox.h> +#include <qspinbox.h> #include "common.h" #include "config.h" #include "misc.h" #include "extprogs.h" #include "gui.h" #include "file.h" -#include <qprocess.h> -#include <qtemporaryfile.h> -#include <qeventloop.h> +#include "radiobox.h" +#include "history.h" // ============================================================================= cfg (str, prog_isecalc, ""); @@ -109,6 +114,40 @@ return; } + QDialog* dlg = new QDialog (g_win); + + RadioBox* rb_mode = new RadioBox ("Extrusion mode", {"Distance", "Symmetry", "Projection", "Radial"}, 0, Qt::Horizontal, dlg); + RadioBox* rb_axis = new RadioBox ("Axis", {"X", "Y", "Z"}, 0, Qt::Horizontal, dlg); + LabeledWidget<QDoubleSpinBox>* dsb_depth = new LabeledWidget<QDoubleSpinBox> ("Plane depth", dlg), + *dsb_condAngle = new LabeledWidget<QDoubleSpinBox> ("Conditional line threshold", dlg); + QDialogButtonBox* bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + QWidget::connect (bbx_buttons, SIGNAL (accepted ()), dlg, SLOT (accept ())); + QWidget::connect (bbx_buttons, SIGNAL (rejected ()), dlg, SLOT (reject ())); + + rb_axis->setValue (Y); + dsb_depth->w ()->setMinimum (-10000.0); + dsb_depth->w ()->setMaximum (10000.0); + dsb_depth->w ()->setDecimals (3); + dsb_condAngle->w ()->setValue (30.0f); + + QVBoxLayout* layout = new QVBoxLayout (dlg); + layout->addWidget (rb_mode); + layout->addWidget (rb_axis); + layout->addWidget (dsb_depth); + layout->addWidget (dsb_condAngle); + layout->addWidget (bbx_buttons); + + dlg->setWindowIcon (getIcon ("extrude")); + + if (!dlg->exec ()) + return; + + const enum modetype { Distance, Symmetry, Projection, Radial } mode = (modetype) rb_mode->value (); + const Axis axis = (Axis) rb_axis->value (); + const double depth = dsb_depth->w ()->value (), + condAngle = dsb_condAngle->w ()->value (); + QTemporaryFile in, out, input; str inname, outname, inputname; FILE* fp; @@ -117,7 +156,14 @@ return; QProcess proc; - QStringList argv ({"-p", "0", "-y", inname, outname}); + QStringList argv ({(axis == X) ? "-x" : (axis == Y) ? "-y" : "-z", + (mode == Distance) ? "-d" : (mode == Symmetry) ? "-s" : (mode == Projection) ? "-p" : "-r", + fmt ("%f", depth), "-a", fmt ("%f", condAngle), inname, outname}); + + printf ("cmdline: %s ", prog_ytruder.value.chars ()); + for (QString& arg : argv) + printf ("%s ", qchars (arg)); + printf ("\n"); // Write the input file fp = fopen (inname, "w"); @@ -157,13 +203,20 @@ if (!fp) fprintf (stderr, "couldn't read %s\n", outname.chars ()); - char line[1024]; - while (fgets (line, sizeof line, fp)) { - printf ("%s", line); - LDObject* obj = parseLine (str (line).strip ({'\n', '\r'})); - g_curfile->addObject (obj); + std::vector<LDObject*> objs = loadFileContents (fp, null), + copies; + std::vector<ulong> indices; + + g_win->sel ().clear (); + for (LDObject* obj : objs) { + ulong idx = g_curfile->addObject (obj); + indices.push_back (idx); + copies.push_back (obj->clone ()); } + + History::addEntry (new AddHistory ({indices, copies})); + fclose (fp); - + g_win->sel () = objs; g_win->refresh (); } \ No newline at end of file
--- a/extprogs.h Mon May 06 03:32:00 2013 +0300 +++ b/extprogs.h Mon May 06 12:50:20 2013 +0300 @@ -21,29 +21,6 @@ #include <qobject.h> -class QProcess; -class ProcessWaiter : public QObject { - Q_OBJECT - -public: - ProcessWaiter (QProcess* proc, bool& readyvar) : m_proc (proc), m_readyvar (readyvar) { - m_readyvar = false; - } - - int exitFlag () { return m_exitflag; } - -public slots: - void slot_procDone (int exitflag) { - m_readyvar = true; - m_exitflag = exitflag; - } - -private: - QProcess* m_proc; - bool& m_readyvar; - int m_exitflag; -}; - enum extprog { IseCalc, Intersector,
--- a/gui.cpp Mon May 06 03:32:00 2013 +0300 +++ b/gui.cpp Mon May 06 12:50:20 2013 +0300 @@ -231,6 +231,9 @@ addMenuAction ("rotateZPos"); // Rotate +Z addMenuAction ("rotateZNeg"); // Rotate -Z + initMenu ("E&xternal Programs"); + addMenuAction ("ytruder"); + #ifndef RELEASE // Debug menu initMenu ("&Debug"); @@ -375,7 +378,9 @@ addToolBarAction ("roundCoords"); addToolBarAction ("screencap"); addToolBarAction ("uncolorize"); - addToolBarAction ("extrude"); + + initSingleToolBar ("External Programs"); + addToolBarAction ("ytruder"); updateToolBars (); }
--- a/gui_editactions.cpp Mon May 06 03:32:00 2013 +0300 +++ b/gui_editactions.cpp Mon May 06 12:50:20 2013 +0300 @@ -689,38 +689,6 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -MAKE_ACTION (extrude, "Extrude", "extrude", "Extrude selected lines to a given plane", KEY (F8)) { - QDialog* dlg = new QDialog (g_win); - - RadioBox* rb_mode = new RadioBox ("Extrusion mode", {"Project", "Mirror"}, 0, Qt::Horizontal, dlg); - RadioBox* rb_axis = new RadioBox ("Axis", {"X", "Y", "Z"}, 0, Qt::Horizontal, dlg); - LabeledWidget<QDoubleSpinBox>* dsb_depth = new LabeledWidget<QDoubleSpinBox> ("Plane depth", dlg); - QDialogButtonBox* bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - QCheckBox* cb_edges = new QCheckBox ("Add edgelines to extrusion point"); - - QWidget::connect (bbx_buttons, SIGNAL (accepted ()), dlg, SLOT (accept ())); - QWidget::connect (bbx_buttons, SIGNAL (rejected ()), dlg, SLOT (reject ())); - - dsb_depth->w ()->setMinimum (-10000.0); - dsb_depth->w ()->setMaximum (10000.0); - dsb_depth->w ()->setDecimals (3); - - QVBoxLayout* layout = new QVBoxLayout (dlg); - layout->addWidget (rb_mode); - layout->addWidget (rb_axis); - layout->addWidget (dsb_depth); - layout->addWidget (cb_edges); - layout->addWidget (bbx_buttons); - - dlg->setWindowIcon (getIcon ("extrude")); - - if (!dlg->exec ()) - return; - - const double depth = dsb_depth->w ()->value (); - const Axis axis = (Axis) rb_axis->value (); - const enum modetype { Projection, Mirror } mode = (modetype) rb_mode->value (); - const bool addEdges = cb_edges->isChecked (); - +MAKE_ACTION (ytruder, "Ytruder", "ytruder", "Extrude selected lines to a given plane", KEY (F8)) { runYtruder (); } \ No newline at end of file
--- a/ldforge.qrc Mon May 06 03:32:00 2013 +0300 +++ b/ldforge.qrc Mon May 06 12:50:20 2013 +0300 @@ -82,6 +82,7 @@ <file>./icons/uncolorize.png</file> <file>./icons/undo.png</file> <file>./icons/vertex.png</file> + <file>./icons/ytruder.png</file> <file>./docs/test2.html</file> <file>./docs/test.html</file> <file>LICENSE</file>