summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ProgressWidget.cc29
-rw-r--r--src/ProgressWidget.h25
-rw-r--r--src/ProgressWidget.ui74
-rw-r--r--src/mainwin.cc65
4 files changed, 173 insertions, 20 deletions
diff --git a/src/ProgressWidget.cc b/src/ProgressWidget.cc
new file mode 100644
index 0000000..0e98286
--- /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 0000000..a609dbd
--- /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 0000000..895586c
--- /dev/null
+++ b/src/ProgressWidget.ui
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ProgressWidget</class>
+ <widget class="QWidget" name="ProgressWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>121</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="spacing">
+ <number>5</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="value">
+ <number>24</number>
+ </property>
+ <property name="format">
+ <string>%v / %m</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="stopButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>12</width>
+ <height>12</height>
+ </size>
+ </property>
+ <property name="baseSize">
+ <size>
+ <width>12</width>
+ <height>12</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset resource="../openscad.qrc">
+ <normaloff>:/icons/stopbutton.png</normaloff>:/icons/stopbutton.png</iconset>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>12</width>
+ <height>12</height>
+ </size>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources>
+ <include location="../openscad.qrc"/>
+ </resources>
+ <connections/>
+</ui>
diff --git a/src/mainwin.cc b/src/mainwin.cc
index 02ea445..6b8fe13 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 <QMenu>
#include <QTime>
@@ -338,18 +341,24 @@ MainWindow::~MainWindow()
#endif
}
-typedef QPair<QProgressBar*, QProgressDialog*> ProgressData;
-
static void report_func(const class AbstractNode*, void *vp, int mark)
{
- ProgressData *progpair = static_cast<ProgressData*>(vp);
+#ifdef USE_PROGRESSWIDGET
+ ProgressWidget *pw = static_cast<ProgressWidget*>(vp);
+ int v = (int)((mark*100.0) / progress_report_count);
+ pw->setValue(v < 100 ? v : 99);
+ QApplication::processEvents();
+ if (pw->wasCanceled()) throw ProgressCancelException();
+#else
+ QProgressDialog *pd = static_cast<QProgressDialog*>(vp);
int v = (int)((mark*100.0) / progress_report_count);
- progpair->first->setValue(v < 100 ? v : 99);
+ 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;
}
contact: Jan Huwald // Impressum