diff --git a/doc/TODO.txt b/doc/TODO.txt index 0bbd24b6..c0a25d47 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -22,6 +22,7 @@ o Preferences - OpenGL params - Default language feature settings - Auto-view CSG/thrown together on load + - Make the library search path configurable? o Export etc.: automatically add missing extension as in SaveAs o MDI - Think about how to do MDI the right way @@ -61,8 +62,6 @@ o Editor o Computation - Run CGAL rendering in a backgroud thread - - Progress - - Move progress bar to status bar (as in Eclipse) - Enable viewing/editing while rendering o Misc - Reload and compile: Ask for confirmation if file is locally edited @@ -94,7 +93,6 @@ o Language Frontend - Add "use" statement to load modules. Like include but read a module only once, ignore all top level objects (they are used as module testcase) and search in a module search path. - - Add a default search path for included files to allow bundling libs - allow 0/1 f/t FALSE/TRUE as boolean values o DXF Import - Support for POLYLINE entity @@ -137,7 +135,6 @@ o Make the interfaces from OpenSCAD and OpenCSG and CGAL cleaner to facilitate INFRASTRUCTURE -------------- -o Think about making external libraries easier available. Probably mostly convenience. o Use a logging framework to get debugging/info output more under control? (check log4j, google project) diff --git a/icons/stopbutton.png b/icons/stopbutton.png new file mode 100644 index 00000000..bb20225d Binary files /dev/null and b/icons/stopbutton.png differ diff --git a/openscad.pro b/openscad.pro index 8ab9b31e..8e2ac2ce 100644 --- a/openscad.pro +++ b/openscad.pro @@ -34,12 +34,20 @@ QT += opengl macx:CONFIG += mdi CONFIG += cgal CONFIG += opencsg +#CONFIG += progresswidget mdi { # MDI needs an OpenCSG library that is compiled with OpenCSG-Reset-Hack.patch applied DEFINES += ENABLE_MDI } +progresswidget { + DEFINES += USE_PROGRESSWIDGET + FORMS += src/ProgressWidget.ui + HEADERS += src/ProgressWidget.h + SOURCES += src/ProgressWidget.cc +} + include(cgal.pri) include(opencsg.pri) diff --git a/openscad.qrc b/openscad.qrc index 80b59341..73639ce5 100644 --- a/openscad.qrc +++ b/openscad.qrc @@ -1,7 +1,8 @@ - - - icons/prefsAdvanced.png - icons/prefs3DView.png - icons/prefsEditor.png - - + + + icons/stopbutton.png + icons/prefsAdvanced.png + icons/prefs3DView.png + icons/prefsEditor.png + + diff --git a/src/ProgressWidget.cc b/src/ProgressWidget.cc new file mode 100644 index 00000000..0e98286d --- /dev/null +++ b/src/ProgressWidget.cc @@ -0,0 +1,29 @@ +#include "ProgressWidget.h" + +ProgressWidget::ProgressWidget(QWidget *parent) + :QWidget(parent) +{ + setupUi(this); + this->wascanceled = false; + connect(this->stopButton, SIGNAL(clicked()), this, SLOT(cancel())); +} + +bool ProgressWidget::wasCanceled() const +{ + return this->wascanceled; +} + +void ProgressWidget::cancel() +{ + this->wascanceled = true; +} + +void ProgressWidget::setRange(int minimum, int maximum) +{ + this->progressBar->setRange(minimum, maximum); +} + +void ProgressWidget::setValue(int progress) +{ + this->progressBar->setValue(progress); +} diff --git a/src/ProgressWidget.h b/src/ProgressWidget.h new file mode 100644 index 00000000..a609dbd6 --- /dev/null +++ b/src/ProgressWidget.h @@ -0,0 +1,25 @@ +#ifndef PROGRESSWIDGET_H_ +#define PROGRESSWIDGET_H_ + +#include "ui_ProgressWidget.h" + +class ProgressWidget : public QWidget, public Ui::ProgressWidget +{ + Q_OBJECT; + Q_PROPERTY(bool wasCanceled READ wasCanceled); + +public: + ProgressWidget(QWidget *parent = NULL); + bool wasCanceled() const; + +public slots: + void setRange(int minimum, int maximum); + void setValue(int progress); + void cancel(); + +private: + bool wascanceled; + +}; + +#endif diff --git a/src/ProgressWidget.ui b/src/ProgressWidget.ui new file mode 100644 index 00000000..895586cb --- /dev/null +++ b/src/ProgressWidget.ui @@ -0,0 +1,74 @@ + + + ProgressWidget + + + + 0 + 0 + 121 + 20 + + + + Form + + + + 5 + + + 0 + + + + + 24 + + + %v / %m + + + + + + + + 0 + 0 + + + + + 12 + 12 + + + + + 12 + 12 + + + + + :/icons/stopbutton.png:/icons/stopbutton.png + + + + 12 + 12 + + + + true + + + + + + + + + + diff --git a/src/mainwin.cc b/src/mainwin.cc index 02ea4454..6b8fe137 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -38,6 +38,9 @@ #include "builtin.h" #include "dxftess.h" #include "progress.h" +#ifdef USE_PROGRESSWIDGET +#include "ProgressWidget.h" +#endif #include #include @@ -338,18 +341,24 @@ MainWindow::~MainWindow() #endif } -typedef QPair ProgressData; - static void report_func(const class AbstractNode*, void *vp, int mark) { - ProgressData *progpair = static_cast(vp); +#ifdef USE_PROGRESSWIDGET + ProgressWidget *pw = static_cast(vp); int v = (int)((mark*100.0) / progress_report_count); - progpair->first->setValue(v < 100 ? v : 99); + pw->setValue(v < 100 ? v : 99); + QApplication::processEvents(); + if (pw->wasCanceled()) throw ProgressCancelException(); +#else + QProgressDialog *pd = static_cast(vp); + int v = (int)((mark*100.0) / progress_report_count); + pd->setValue(v < 100 ? v : 99); QString label; label.sprintf("Rendering Polygon Mesh (%d/%d)", mark, progress_report_count); - progpair->second->setLabelText(label); + pd->setLabelText(label); QApplication::processEvents(); - if (progpair->second->wasCanceled()) throw ProgressCancelException(); + if (pd->wasCanceled()) throw ProgressCancelException(); +#endif } /*! @@ -635,17 +644,21 @@ void MainWindow::compileCSG(bool procevents) QTime t; t.start(); +#ifdef USE_PROGRESSWIDGET + ProgressWidget *pd = new ProgressWidget(this); + pd->setRange(0, 100); + pd->setValue(0); + this->statusBar()->addPermanentWidget(pd); +#else QProgressDialog *pd = new QProgressDialog("Rendering CSG products...", "Cancel", 0, 100); - QProgressBar *bar = new QProgressBar(pd); - bar->setRange(0, 100); - bar->setValue(0); - pd->setBar(bar); + pd->setRange(0, 100); + pd->setValue(0); pd->setAutoClose(false); pd->show(); - ProgressData progpair(bar, pd); +#endif QApplication::processEvents(); - progress_report_prep(root_node, report_func, &progpair); + progress_report_prep(root_node, report_func, pd); try { root_raw_term = root_node->render_csg_term(m, &highlight_terms, &background_terms); if (!root_raw_term) { @@ -655,8 +668,12 @@ void MainWindow::compileCSG(bool procevents) } } catch (ProgressCancelException e) { + PRINT("CSG generation cancelled."); } progress_report_fin(); +#ifdef USE_PROGRESSWIDGET + this->statusBar()->removeWidget(pd); +#endif delete pd; if (root_raw_term) { @@ -1032,25 +1049,30 @@ void MainWindow::actionRenderCGAL() QTime t; t.start(); + +#ifdef USE_PROGRESSWIDGET + ProgressWidget *pd = new ProgressWidget(this); + pd->setRange(0, 100); + pd->setValue(0); + this->statusBar()->addPermanentWidget(pd); +#else QProgressDialog *pd = new QProgressDialog("Rendering Polygon Mesh using CGAL...", "Cancel", 0, 100); - QProgressBar *bar = new QProgressBar(pd); - bar->setRange(0, 100); - bar->setValue(0); - pd->setBar(bar); + pd->setRange(0, 100); + pd->setValue(0); pd->setAutoClose(false); pd->show(); -// this->statusBar()->addPermanentWidget(bar); - ProgressData progpair(bar, pd); +#endif + QApplication::processEvents(); - progress_report_prep(root_node, report_func, &progpair); + progress_report_prep(root_node, report_func, pd); try { this->root_N = new CGAL_Nef_polyhedron(root_node->render_cgal_nef_polyhedron()); } catch (ProgressCancelException e) { + PRINT("Rendering cancelled."); } progress_report_fin(); -// this->statusBar()->removeWidget(bar); if (this->root_N) { @@ -1111,6 +1133,9 @@ void MainWindow::actionRenderCGAL() PRINT("Rendering finished."); } +#ifdef USE_PROGRESSWIDGET + this->statusBar()->removeWidget(pd); +#endif delete pd; current_win = NULL; }