Front-end of parameterization
This commit is contained in:
parent
4ab1b95954
commit
dc95d6d20b
25 changed files with 1393 additions and 13 deletions
28
openscad.pro
28
openscad.pro
|
|
@ -224,7 +224,9 @@ FORMS += src/MainWindow.ui \
|
|||
src/FontListDialog.ui \
|
||||
src/ProgressWidget.ui \
|
||||
src/launchingscreen.ui \
|
||||
src/LibraryInfoDialog.ui
|
||||
src/LibraryInfoDialog.ui \
|
||||
src/parameter/ParameterWidget.ui \
|
||||
src/parameter/ParameterEntryWidget.ui
|
||||
|
||||
# AST nodes
|
||||
win* {
|
||||
|
|
@ -385,6 +387,17 @@ HEADERS += src/version_check.h \
|
|||
src/LibraryInfoDialog.h \
|
||||
\
|
||||
src/comment.h\
|
||||
\
|
||||
src/parameter/ParameterWidget.h \
|
||||
src/parameter/parameterobject.h \
|
||||
src/parameter/parameterextractor.h \
|
||||
src/parameter/parametervirtualwidget.h \
|
||||
src/parameter/parameterspinbox.h \
|
||||
src/parameter/parametercombobox.h \
|
||||
src/parameter/parameterslider.h \
|
||||
src/parameter/parametercheckbox.h \
|
||||
src/parameter/parametertext.h \
|
||||
src/parameter/parametervector.h
|
||||
|
||||
SOURCES += \
|
||||
src/libsvg/libsvg.cc \
|
||||
|
|
@ -509,7 +522,18 @@ SOURCES += \
|
|||
src/legacyeditor.cc \
|
||||
src/LibraryInfoDialog.cc\
|
||||
\
|
||||
src/comment.cpp
|
||||
src/comment.cpp \
|
||||
\
|
||||
src/parameter/ParameterWidget.cc\
|
||||
src/parameter/parameterobject.cpp \
|
||||
src/parameter/parameterextractor.cpp \
|
||||
src/parameter/parameterspinbox.cpp \
|
||||
src/parameter/parametercombobox.cpp \
|
||||
src/parameter/parameterslider.cpp \
|
||||
src/parameter/parametercheckbox.cpp \
|
||||
src/parameter/parametertext.cpp \
|
||||
src/parameter/parametervector.cpp
|
||||
|
||||
|
||||
# ClipperLib
|
||||
SOURCES += src/polyclipping/clipper.cpp
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ public:
|
|||
QLabel *versionLabel;
|
||||
QWidget *editorDockTitleWidget;
|
||||
QWidget *consoleDockTitleWidget;
|
||||
|
||||
QWidget *parameterDockTitleWidget;
|
||||
|
||||
QString editortype;
|
||||
bool useScintilla;
|
||||
|
||||
|
|
@ -150,6 +151,7 @@ private slots:
|
|||
void hideEditor();
|
||||
void hideConsole();
|
||||
void showConsole();
|
||||
void hideParameters();
|
||||
|
||||
private slots:
|
||||
void selectFindType(int);
|
||||
|
|
@ -204,8 +206,11 @@ public slots:
|
|||
void on_editorDock_visibilityChanged(bool);
|
||||
void on_consoleDock_visibilityChanged(bool);
|
||||
void on_toolButtonCompileResultClose_clicked();
|
||||
void on_parameterDock_visibilityChanged(bool);
|
||||
void editorTopLevelChanged(bool);
|
||||
void consoleTopLevelChanged(bool);
|
||||
void parameterTopLevelChanged(bool);
|
||||
|
||||
#ifdef ENABLE_OPENCSG
|
||||
void viewModePreview();
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -15,7 +15,16 @@
|
|||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
|
|
@ -30,7 +39,16 @@
|
|||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
|
|
@ -162,7 +180,16 @@
|
|||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayoutAnimate">
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
|
|
@ -374,6 +401,7 @@
|
|||
<addaction name="viewActionHideToolBars"/>
|
||||
<addaction name="viewActionHideEditor"/>
|
||||
<addaction name="viewActionHideConsole"/>
|
||||
<addaction name="viewActionHideParameters"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuHelp">
|
||||
<property name="title">
|
||||
|
|
@ -402,7 +430,16 @@
|
|||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
|
|
@ -528,7 +565,16 @@
|
|||
</attribute>
|
||||
<widget class="QWidget" name="consoleDockContents">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
|
|
@ -550,6 +596,36 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="Dock" name="parameterDock">
|
||||
<property name="windowTitle">
|
||||
<string>Parameter Widget</string>
|
||||
</property>
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>2</number>
|
||||
</attribute>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="ParameterWidget" name="parameterWidget" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<action name="fileActionNew">
|
||||
<property name="icon">
|
||||
<iconset resource="../openscad.qrc">
|
||||
|
|
@ -1283,6 +1359,17 @@
|
|||
<string>Ctrl+Shift+C</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="viewActionHideParameters">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Hide parameters</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
@ -1297,6 +1384,12 @@
|
|||
<header>Dock.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ParameterWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>parameter/ParameterWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../openscad.qrc"/>
|
||||
|
|
|
|||
|
|
@ -176,11 +176,14 @@ MainWindow::MainWindow(const QString &filename)
|
|||
|
||||
editorDockTitleWidget = new QWidget();
|
||||
consoleDockTitleWidget = new QWidget();
|
||||
parameterDockTitleWidget = new QWidget();
|
||||
|
||||
this->editorDock->setConfigKey("view/hideEditor");
|
||||
this->editorDock->setAction(this->viewActionHideEditor);
|
||||
this->consoleDock->setConfigKey("view/hideConsole");
|
||||
this->consoleDock->setAction(this->viewActionHideConsole);
|
||||
this->parameterDock->setConfigKey("view/hideParameters");
|
||||
this->parameterDock->setAction(this->viewActionHideParameters);
|
||||
|
||||
this->versionLabel = NULL; // must be initialized before calling updateStatusBar()
|
||||
updateStatusBar(NULL);
|
||||
|
|
@ -276,7 +279,7 @@ MainWindow::MainWindow(const QString &filename)
|
|||
waitAfterReloadTimer->setSingleShot(true);
|
||||
waitAfterReloadTimer->setInterval(200);
|
||||
connect(waitAfterReloadTimer, SIGNAL(timeout()), this, SLOT(waitAfterReload()));
|
||||
|
||||
connect(this->parameterWidget, SIGNAL(previewRequested()), this, SLOT(actionRenderPreview()));
|
||||
connect(this->e_tval, SIGNAL(textChanged(QString)), this, SLOT(updatedAnimTval()));
|
||||
connect(this->e_fps, SIGNAL(textChanged(QString)), this, SLOT(updatedAnimFps()));
|
||||
connect(this->e_fsteps, SIGNAL(textChanged(QString)), this, SLOT(updatedAnimSteps()));
|
||||
|
|
@ -409,7 +412,7 @@ MainWindow::MainWindow(const QString &filename)
|
|||
connect(this->viewActionHideToolBars, SIGNAL(triggered()), this, SLOT(hideToolbars()));
|
||||
connect(this->viewActionHideEditor, SIGNAL(triggered()), this, SLOT(hideEditor()));
|
||||
connect(this->viewActionHideConsole, SIGNAL(triggered()), this, SLOT(hideConsole()));
|
||||
|
||||
connect(this->viewActionHideParameters, SIGNAL(triggered()), this, SLOT(hideParameters()));
|
||||
// Help menu
|
||||
connect(this->helpActionAbout, SIGNAL(triggered()), this, SLOT(helpAbout()));
|
||||
connect(this->helpActionHomepage, SIGNAL(triggered()), this, SLOT(helpHomepage()));
|
||||
|
|
@ -561,7 +564,7 @@ MainWindow::MainWindow(const QString &filename)
|
|||
|
||||
connect(this->editorDock, SIGNAL(topLevelChanged(bool)), this, SLOT(editorTopLevelChanged(bool)));
|
||||
connect(this->consoleDock, SIGNAL(topLevelChanged(bool)), this, SLOT(consoleTopLevelChanged(bool)));
|
||||
|
||||
connect(this->parameterDock, SIGNAL(topLevelChanged(bool)), this, SLOT(parameterTopLevelChanged(bool)));
|
||||
// display this window and check for OpenGL 2.0 (OpenCSG) support
|
||||
viewModeThrownTogether();
|
||||
show();
|
||||
|
|
@ -632,6 +635,8 @@ void MainWindow::loadViewSettings(){
|
|||
hideEditor();
|
||||
viewActionHideToolBars->setChecked(settings.value("view/hideToolbar").toBool());
|
||||
hideToolbars();
|
||||
viewActionHideParameters->setChecked(settings.value("view/hideParameters").toBool());
|
||||
hideParameters();
|
||||
updateMdiMode(settings.value("advanced/mdi").toBool());
|
||||
updateUndockMode(settings.value("advanced/undockableWindows").toBool());
|
||||
updateReorderMode(settings.value("advanced/reorderWindows").toBool());
|
||||
|
|
@ -662,6 +667,7 @@ void MainWindow::updateUndockMode(bool undockMode)
|
|||
if (undockMode) {
|
||||
editorDock->setFeatures(editorDock->features() | QDockWidget::DockWidgetFloatable);
|
||||
consoleDock->setFeatures(consoleDock->features() | QDockWidget::DockWidgetFloatable);
|
||||
parameterDock->setFeatures(parameterDock->features() | QDockWidget::DockWidgetFloatable);
|
||||
} else {
|
||||
if (editorDock->isFloating()) {
|
||||
editorDock->setFloating(false);
|
||||
|
|
@ -671,6 +677,10 @@ void MainWindow::updateUndockMode(bool undockMode)
|
|||
consoleDock->setFloating(false);
|
||||
}
|
||||
consoleDock->setFeatures(consoleDock->features() & ~QDockWidget::DockWidgetFloatable);
|
||||
if (parameterDock->isFloating()) {
|
||||
parameterDock->setFloating(false);
|
||||
}
|
||||
parameterDock->setFeatures(parameterDock->features() & ~QDockWidget::DockWidgetFloatable);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -679,6 +689,7 @@ void MainWindow::updateReorderMode(bool reorderMode)
|
|||
MainWindow::reorderMode = reorderMode;
|
||||
editorDock->setTitleBarWidget(reorderMode ? 0 : editorDockTitleWidget);
|
||||
consoleDock->setTitleBarWidget(reorderMode ? 0 : consoleDockTitleWidget);
|
||||
parameterDock->setTitleBarWidget(reorderMode ? 0 : parameterDockTitleWidget);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
|
@ -774,6 +785,7 @@ void MainWindow::setFileName(const QString &filename)
|
|||
}
|
||||
editorTopLevelChanged(editorDock->isFloating());
|
||||
consoleTopLevelChanged(consoleDock->isFloating());
|
||||
parameterTopLevelChanged(parameterDock->isFloating() );
|
||||
}
|
||||
|
||||
void MainWindow::updateRecentFiles()
|
||||
|
|
@ -1411,7 +1423,7 @@ void MainWindow::actionSaveAs()
|
|||
// defaultSuffix property
|
||||
QFileInfo info(new_filename);
|
||||
if (info.exists()) {
|
||||
if (QMessageBox::warning(this, windowTitle(),
|
||||
if (QMessageBox::warning(this, windowTitle(),
|
||||
QString(_("%1 already exists.\nDo you want to replace it?")).arg(info.fileName()),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) {
|
||||
return;
|
||||
|
|
@ -1704,8 +1716,11 @@ void MainWindow::compileTopLevelDocument()
|
|||
if(this->root_module!=NULL){
|
||||
//add parameters as annotation in AST
|
||||
addParameter(fulltext.c_str(),this->root_module);
|
||||
|
||||
}
|
||||
|
||||
this->parameterWidget->setParameters(this->root_module);
|
||||
this->parameterWidget->applyParameters(this->root_module);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::checkAutoReload()
|
||||
|
|
@ -2439,6 +2454,11 @@ void MainWindow::on_consoleDock_visibilityChanged(bool)
|
|||
consoleTopLevelChanged(consoleDock->isFloating());
|
||||
}
|
||||
|
||||
void MainWindow::on_parameterDock_visibilityChanged(bool)
|
||||
{
|
||||
consoleTopLevelChanged(consoleDock->isFloating());
|
||||
}
|
||||
|
||||
void MainWindow::editorTopLevelChanged(bool topLevel)
|
||||
{
|
||||
setDockWidgetTitle(editorDock, QString(_("Editor")), topLevel);
|
||||
|
|
@ -2449,6 +2469,11 @@ void MainWindow::consoleTopLevelChanged(bool topLevel)
|
|||
setDockWidgetTitle(consoleDock, QString(_("Console")), topLevel);
|
||||
}
|
||||
|
||||
void MainWindow::parameterTopLevelChanged(bool topLevel)
|
||||
{
|
||||
setDockWidgetTitle(parameterDock, QString(_("ParameterWidget")), topLevel);
|
||||
}
|
||||
|
||||
void MainWindow::setDockWidgetTitle(QDockWidget *dockWidget, QString prefix, bool topLevel)
|
||||
{
|
||||
QString title(prefix);
|
||||
|
|
@ -2499,6 +2524,15 @@ void MainWindow::hideConsole()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::hideParameters()
|
||||
{
|
||||
if (viewActionHideParameters->isChecked()) {
|
||||
parameterDock->hide();
|
||||
} else {
|
||||
parameterDock->show();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls())
|
||||
|
|
|
|||
287
src/parameter/ParameterEntryWidget.ui
Normal file
287
src/parameter/ParameterEntryWidget.ui
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ParameterEntryWidget</class>
|
||||
<widget class="QWidget" name="ParameterEntryWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>562</width>
|
||||
<height>144</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="midLineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<property name="leftMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<item row="2" column="0">
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<widget class="QWidget" name="pageCheckBox">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="pageSlider">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QSlider" name="slider">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="labelSliderValue">
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="pageComboBox">
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="pageText">
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="frame">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="pageVector">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox2">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox1">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox3">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox4">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelDescription">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>11</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelParameter">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Parameter</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
156
src/parameter/ParameterWidget.cc
Normal file
156
src/parameter/ParameterWidget.cc
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* OpenSCAD (www.openscad.org)
|
||||
* Copyright (C) 2009-2014 Clifford Wolf <clifford@clifford.at> and
|
||||
* Marius Kintel <marius@kintel.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* As a special exception, you have permission to link this program
|
||||
* with the CGAL library and distribute executables, as long as you
|
||||
* follow the requirements of the GNU GPL in regard to all of the
|
||||
* software in the executable aside from CGAL.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include <QWidget>
|
||||
|
||||
#include "ParameterWidget.h"
|
||||
|
||||
#include "parameterspinbox.h"
|
||||
#include "parametercombobox.h"
|
||||
#include "parameterslider.h"
|
||||
#include "parametercheckbox.h"
|
||||
#include "parametertext.h"
|
||||
#include "parametervector.h"
|
||||
|
||||
|
||||
ParameterWidget::ParameterWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
descriptionShow=true;
|
||||
autoPreviewTimer.setInterval(500);
|
||||
autoPreviewTimer.setSingleShot(true);
|
||||
connect(&autoPreviewTimer, SIGNAL(timeout()), this, SLOT(onPreviewTimerElapsed()));
|
||||
connect(checkBoxAutoPreview, SIGNAL(toggled(bool)), this, SLOT(onValueChanged()));
|
||||
connect(checkBoxDetailedDescription,SIGNAL(toggled(bool)),this,SLOT(onDescriptionShow()));
|
||||
}
|
||||
|
||||
ParameterWidget::~ParameterWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void ParameterWidget::onDescriptionShow()
|
||||
{
|
||||
if(checkBoxDetailedDescription->isChecked()){
|
||||
descriptionShow=true;
|
||||
}else{
|
||||
descriptionShow=false;
|
||||
}
|
||||
emit previewRequested();
|
||||
}
|
||||
|
||||
void ParameterWidget::onValueChanged()
|
||||
{
|
||||
autoPreviewTimer.stop();
|
||||
if (checkBoxAutoPreview->isChecked()) {
|
||||
autoPreviewTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterWidget::onPreviewTimerElapsed()
|
||||
{
|
||||
emit previewRequested();
|
||||
}
|
||||
|
||||
void ParameterWidget::begin()
|
||||
{
|
||||
QLayoutItem *child;
|
||||
while ((child = this->scrollAreaWidgetContents->layout()->takeAt(0)) != 0) {
|
||||
QWidget *w = child->widget();
|
||||
this->scrollAreaWidgetContents->layout()->removeWidget(w);
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterWidget::addEntry(ParameterVirtualWidget *entry)
|
||||
{
|
||||
QSizePolicy policy;
|
||||
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
||||
policy.setVerticalPolicy(QSizePolicy::Preferred);
|
||||
policy.setHorizontalStretch(0);
|
||||
policy.setVerticalStretch(0);
|
||||
entry->setSizePolicy(policy);
|
||||
this->scrollAreaWidgetContents->layout()->addWidget(entry);
|
||||
}
|
||||
|
||||
void ParameterWidget::end()
|
||||
{
|
||||
QSizePolicy policy;
|
||||
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
||||
policy.setVerticalPolicy(QSizePolicy::Preferred);
|
||||
policy.setHorizontalStretch(0);
|
||||
policy.setVerticalStretch(1);
|
||||
QLabel *label = new QLabel("");
|
||||
label->setSizePolicy(policy);
|
||||
this->scrollAreaWidgetContents->layout()->addWidget(label);
|
||||
}
|
||||
|
||||
void ParameterWidget::connectWidget()
|
||||
{
|
||||
for(entry_map_t::iterator it = entries.begin(); it != entries.end();) {
|
||||
if(!(*it).second->set){
|
||||
it=entries.erase(it);
|
||||
}else{
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
begin();
|
||||
for(entry_map_t::iterator it = entries.begin(); it != entries.end(); it++) {
|
||||
|
||||
ParameterVirtualWidget *entry ;
|
||||
switch (it->second->target) {
|
||||
case COMBOBOX:{
|
||||
entry = new ParameterComboBox(it->second,descriptionShow);
|
||||
break;
|
||||
}
|
||||
case SLIDER:{
|
||||
entry = new ParameterSlider(it->second,descriptionShow);
|
||||
break;
|
||||
}
|
||||
case CHECKBOX:{
|
||||
entry = new ParameterCheckBox(it->second,descriptionShow);
|
||||
break;
|
||||
}
|
||||
case TEXT:{
|
||||
entry = new ParameterText(it->second,descriptionShow);
|
||||
break;
|
||||
}
|
||||
case NUMBER:{
|
||||
entry = new ParameterSpinBox(it->second,descriptionShow);
|
||||
break;
|
||||
}
|
||||
case VECTOR:{
|
||||
entry = new ParameterVector(it->second,descriptionShow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(it->second->target!=UNDEFINED){
|
||||
connect(entry, SIGNAL(changed()), this, SLOT(onValueChanged()));
|
||||
addEntry(entry);
|
||||
}
|
||||
}
|
||||
end();
|
||||
}
|
||||
60
src/parameter/ParameterWidget.h
Normal file
60
src/parameter/ParameterWidget.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* OpenSCAD (www.openscad.org)
|
||||
* Copyright (C) 2009-2014 Clifford Wolf <clifford@clifford.at> and
|
||||
* Marius Kintel <marius@kintel.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* As a special exception, you have permission to link this program
|
||||
* with the CGAL library and distribute executables, as long as you
|
||||
* follow the requirements of the GNU GPL in regard to all of the
|
||||
* software in the executable aside from CGAL.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
#include "parameterextractor.h"
|
||||
#include "ui_ParameterWidget.h"
|
||||
|
||||
|
||||
class ParameterWidget : public QWidget, public Ui::ParameterWidget, public ParameterExtractor
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
typedef enum { UNDEFINED, COMBOBOX, SLIDER, CHECKBOX, TEXT, NUMBER, VECTOR } parameter_type_t;
|
||||
QTimer autoPreviewTimer;
|
||||
bool descriptionShow;
|
||||
|
||||
public:
|
||||
ParameterWidget(QWidget *parent = 0);
|
||||
virtual ~ParameterWidget();
|
||||
|
||||
protected slots:
|
||||
void onValueChanged();
|
||||
void onPreviewTimerElapsed();
|
||||
void onDescriptionShow();
|
||||
|
||||
signals:
|
||||
void previewRequested();
|
||||
|
||||
protected:
|
||||
void connectWidget();
|
||||
void begin();
|
||||
void addEntry(class ParameterVirtualWidget *entry);
|
||||
void end();
|
||||
};
|
||||
106
src/parameter/ParameterWidget.ui
Normal file
106
src/parameter/ParameterWidget.ui
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ParameterWidget</class>
|
||||
<widget class="QWidget" name="ParameterWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>486</width>
|
||||
<height>590</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Parameter Widget</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="6" column="0">
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>+</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0" colspan="4">
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>472</width>
|
||||
<height>502</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Preset:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="checkBoxAutoPreview">
|
||||
<property name="text">
|
||||
<string>Automatic Preview</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>-</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QCheckBox" name="checkBoxDetailedDescription">
|
||||
<property name="text">
|
||||
<string>Detailed descritpion</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
26
src/parameter/parametercheckbox.cpp
Normal file
26
src/parameter/parametercheckbox.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include "parametercheckbox.h"
|
||||
|
||||
ParameterCheckBox::ParameterCheckBox(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(checkBox,SIGNAL(clicked()),this,SLOT(on_Changed()));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
checkBox->setToolTip(object->description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ParameterCheckBox::on_Changed(){
|
||||
object->value = ValuePtr(checkBox->isChecked());
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterCheckBox::setValue(){
|
||||
this->stackedWidget->setCurrentWidget(this->pageCheckBox);
|
||||
this->checkBox->setChecked(object->value->toBool());
|
||||
}
|
||||
18
src/parameter/parametercheckbox.h
Normal file
18
src/parameter/parametercheckbox.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef PARAMETERCHECKBOX_H
|
||||
#define PARAMETERCHECKBOX_H
|
||||
|
||||
#include"parametervirtualwidget.h"
|
||||
|
||||
|
||||
class ParameterCheckBox : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterCheckBox(ParameterObject *parameterobject,bool);
|
||||
void setValue();
|
||||
|
||||
protected slots:
|
||||
void on_Changed();
|
||||
};
|
||||
|
||||
#endif // PARAMETERCHECKBOX_H
|
||||
54
src/parameter/parametercombobox.cpp
Normal file
54
src/parameter/parametercombobox.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include "parametercombobox.h"
|
||||
|
||||
ParameterComboBox::ParameterComboBox(ParameterObject *parameterobject, bool showDescription){
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(comboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(on_Changed(int)));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
comboBox->setToolTip(object->description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ParameterComboBox::on_Changed(int idx){
|
||||
|
||||
if(object->dvt == Value::STRING){
|
||||
const string v = comboBox->itemData(idx).toString().toStdString();
|
||||
object->value = ValuePtr(v);
|
||||
}else{
|
||||
const double v = comboBox->itemData(idx).toDouble();
|
||||
object->value = ValuePtr(v);
|
||||
}
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterComboBox::setValue(){
|
||||
|
||||
this->stackedWidget->setCurrentWidget(this->pageComboBox);
|
||||
comboBox->clear();
|
||||
const Value::VectorType& vec = object->values->toVector();
|
||||
for (Value::VectorType::const_iterator it = vec.begin(); it != vec.end(); it++) {
|
||||
|
||||
if((*it)->toVector().size()>1){
|
||||
comboBox->addItem(QString::fromStdString((*it)->toVector()[1]->toString()),
|
||||
QVariant(QString::fromStdString((*it)->toVector()[0]->toString())));
|
||||
}
|
||||
else
|
||||
{
|
||||
comboBox->addItem(QString::fromStdString((*it)->toString()),
|
||||
QVariant(QString::fromStdString((*it)->toString())));
|
||||
|
||||
}
|
||||
}
|
||||
QString defaultText = QString::fromStdString(object->value->toString());
|
||||
int idx = comboBox->findData(QVariant(defaultText));
|
||||
if (idx >= 0) {
|
||||
comboBox->setCurrentIndex(idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
19
src/parameter/parametercombobox.h
Normal file
19
src/parameter/parametercombobox.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef PARAMETERCOMBOBOX_H
|
||||
#define PARAMETERCOMBOBOX_H
|
||||
|
||||
#include"parametervirtualwidget.h"
|
||||
|
||||
class ParameterComboBox : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ParameterComboBox(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
|
||||
public slots:
|
||||
void on_Changed(int idx);
|
||||
};
|
||||
|
||||
|
||||
#endif // PARAMETERCOMBOBOX_H
|
||||
67
src/parameter/parameterextractor.cpp
Normal file
67
src/parameter/parameterextractor.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include "parameterextractor.h"
|
||||
|
||||
#include "modcontext.h"
|
||||
|
||||
ParameterExtractor::ParameterExtractor()
|
||||
{
|
||||
}
|
||||
|
||||
ParameterExtractor::~ParameterExtractor()
|
||||
{
|
||||
}
|
||||
|
||||
void ParameterExtractor::applyParameters(FileModule *fileModule)
|
||||
{
|
||||
if (fileModule == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (AssignmentList::iterator it = fileModule->scope.assignments.begin();it != fileModule->scope.assignments.end();it++) {
|
||||
entry_map_t::iterator entry = entries.find((*it).name);
|
||||
if (entry == entries.end()) {
|
||||
continue;
|
||||
}
|
||||
(*entry).second->applyParameter(&(*it));
|
||||
(*entry).second->set=false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterExtractor::setParameters(const FileModule* module)
|
||||
{
|
||||
if (module == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ModuleContext ctx;
|
||||
|
||||
foreach(Assignment assignment, module->scope.assignments)
|
||||
{
|
||||
const Annotation *param = assignment.annotation("Parameter");
|
||||
if (!param) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const ValuePtr defaultValue = assignment.expr.get()->evaluate(&ctx);
|
||||
if (defaultValue->type() == Value::UNDEFINED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ParameterObject *entryObject = new ParameterObject();
|
||||
entryObject->setAssignment(&ctx, &assignment, defaultValue);
|
||||
|
||||
//need to improve structure
|
||||
if(entries.find(assignment.name) == entries.end()){
|
||||
entries[assignment.name] = entryObject;
|
||||
}else{
|
||||
if(*entryObject==*entries[assignment.name]){
|
||||
entryObject=entries[assignment.name];
|
||||
}else{
|
||||
entries[assignment.name] = entryObject;
|
||||
}
|
||||
}
|
||||
|
||||
entryObject->set=true;
|
||||
}
|
||||
connectWidget();
|
||||
}
|
||||
29
src/parameter/parameterextractor.h
Normal file
29
src/parameter/parameterextractor.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef PARAMETEREXTRACTOR_H
|
||||
#define PARAMETEREXTRACTOR_H
|
||||
|
||||
#include "FileModule.h"
|
||||
#include "parametervirtualwidget.h"
|
||||
|
||||
class ParameterExtractor
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
typedef std::map<std::string, class ParameterObject *> entry_map_t;
|
||||
entry_map_t entries;
|
||||
|
||||
public:
|
||||
ParameterExtractor();
|
||||
virtual ~ParameterExtractor();
|
||||
void setParameters(const FileModule* module);
|
||||
void applyParameters(FileModule *fileModule);
|
||||
|
||||
|
||||
protected:
|
||||
virtual void begin()=0;
|
||||
virtual void addEntry(ParameterVirtualWidget *entry)=0;
|
||||
virtual void end()=0;
|
||||
virtual void connectWidget()=0;
|
||||
};
|
||||
|
||||
#endif // PARAMETEREXTRACTOR_H
|
||||
64
src/parameter/parameterobject.cpp
Normal file
64
src/parameter/parameterobject.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include "parameterobject.h"
|
||||
|
||||
#include "module.h"
|
||||
#include "modcontext.h"
|
||||
|
||||
ParameterObject::ParameterObject()
|
||||
{
|
||||
}
|
||||
|
||||
void ParameterObject::applyParameter(class Assignment *assignment){
|
||||
|
||||
ModuleContext ctx;
|
||||
const ValuePtr defaultValue =assignment->expr.get()->evaluate(&ctx);
|
||||
|
||||
if( defaultValue->type() == dvt ){
|
||||
assignment->expr = shared_ptr<Expression>(new Literal(value));
|
||||
}
|
||||
}
|
||||
|
||||
int ParameterObject::setValue(const class ValuePtr defaultValue, const class ValuePtr values){
|
||||
|
||||
this->values = values;
|
||||
this->value = defaultValue;
|
||||
this->defaultValue = defaultValue;
|
||||
this->vt = values->type();
|
||||
this->dvt = defaultValue->type();
|
||||
|
||||
if (dvt == Value::BOOL) {
|
||||
target = CHECKBOX;
|
||||
} else if ((dvt == Value::VECTOR) && (defaultValue->toVector().size() <= 4)) {
|
||||
target = VECTOR;
|
||||
} else if ((vt == Value::VECTOR) && ((dvt == Value::NUMBER) || (dvt == Value::STRING))) {
|
||||
target = COMBOBOX;
|
||||
} else if ((vt == Value::RANGE) && (dvt == Value::NUMBER)) {
|
||||
target = SLIDER;
|
||||
} else if (dvt == Value::NUMBER) {
|
||||
target = NUMBER;
|
||||
} else {
|
||||
target = TEXT;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
void ParameterObject::setAssignment(Context *ctx, const Assignment *assignment, const ValuePtr defaultValue){
|
||||
name = assignment->name;
|
||||
const Annotation *param = assignment->annotation("Parameter");
|
||||
const ValuePtr values = param->evaluate(ctx, "values");
|
||||
setValue(defaultValue, values);
|
||||
const Annotation *desc = assignment->annotation("Description");
|
||||
|
||||
if (desc) {
|
||||
const ValuePtr v = desc->evaluate(ctx, "text");
|
||||
if (v->type() == Value::STRING) {
|
||||
description=QString::fromStdString(v->toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ParameterObject::operator == (const ParameterObject &second)
|
||||
{
|
||||
return (this->defaultValue == second.defaultValue && this->values==second.values &&
|
||||
this->description == second.description);
|
||||
}
|
||||
40
src/parameter/parameterobject.h
Normal file
40
src/parameter/parameterobject.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef PARAMETEROBJECT_H
|
||||
#define PARAMETEROBJECT_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "value.h"
|
||||
#include "qtgettext.h"
|
||||
#include "Assignment.h"
|
||||
#include "expression.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class ParameterObject
|
||||
{
|
||||
typedef enum { UNDEFINED, COMBOBOX, SLIDER, CHECKBOX, TEXT, NUMBER, VECTOR } parameter_type_t;
|
||||
|
||||
public:
|
||||
ValuePtr value;
|
||||
ValuePtr values;
|
||||
ValuePtr defaultValue;
|
||||
Value::ValueType dvt;
|
||||
parameter_type_t target;
|
||||
QString description;
|
||||
string name;
|
||||
bool set;
|
||||
|
||||
private:
|
||||
Value::ValueType vt;
|
||||
|
||||
public:
|
||||
ParameterObject();
|
||||
void setAssignment(Context *context, const Assignment *assignment, const ValuePtr defaultValue);
|
||||
void applyParameter( Assignment *assignment);
|
||||
bool operator == (const ParameterObject &second);
|
||||
|
||||
protected:
|
||||
int setValue(const ValuePtr defaultValue, const ValuePtr values);
|
||||
};
|
||||
|
||||
#endif // PARAMETEROBJECT_H
|
||||
33
src/parameter/parameterslider.cpp
Normal file
33
src/parameter/parameterslider.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include "parameterslider.h"
|
||||
|
||||
ParameterSlider::ParameterSlider(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(on_Changed(int)));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
slider->setToolTip(object->description);
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterSlider::on_Changed(int)
|
||||
{
|
||||
double v = slider->value();
|
||||
object->value = ValuePtr(v);
|
||||
//to be corrected
|
||||
this->labelSliderValue->setText(QString::number(v, 'f', 0));
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterSlider::setValue()
|
||||
{
|
||||
this->stackedWidget->setCurrentWidget(this->pageSlider);
|
||||
this->slider->setRange(object->values->toRange().begin_value(),object->values->toRange().end_value());
|
||||
this->slider->setValue(object->value->toDouble());
|
||||
this->slider->setSingleStep(object->values->toRange().step_value());
|
||||
this->labelSliderValue->setText(QString::number(object->value->toDouble(), 'f', 0));
|
||||
}
|
||||
17
src/parameter/parameterslider.h
Normal file
17
src/parameter/parameterslider.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef PARAMETERSLIDER_H
|
||||
#define PARAMETERSLIDER_H
|
||||
|
||||
#include"parametervirtualwidget.h"
|
||||
|
||||
class ParameterSlider : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterSlider(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
|
||||
protected slots:
|
||||
void on_Changed(int);
|
||||
};
|
||||
|
||||
#endif // PARAMETERSLIDER_H
|
||||
34
src/parameter/parameterspinbox.cpp
Normal file
34
src/parameter/parameterspinbox.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "parameterspinbox.h"
|
||||
|
||||
ParameterSpinBox::ParameterSpinBox(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(doubleSpinBox1,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
doubleSpinBox1->setToolTip(object->description);
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterSpinBox::on_Changed(double){
|
||||
|
||||
object->value = ValuePtr(doubleSpinBox1->value());
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterSpinBox::setValue(){
|
||||
|
||||
this->stackedWidget->setCurrentWidget(this->pageVector);
|
||||
this->doubleSpinBox1->setValue(object->value->toDouble());
|
||||
if(object->values->toDouble()>0){
|
||||
this->doubleSpinBox1->setSingleStep(object->values->toDouble());
|
||||
}
|
||||
|
||||
this->doubleSpinBox2->hide();
|
||||
this->doubleSpinBox3->hide();
|
||||
this->doubleSpinBox4->hide();
|
||||
}
|
||||
17
src/parameter/parameterspinbox.h
Normal file
17
src/parameter/parameterspinbox.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef PARAMETERSPINBOX_H
|
||||
#define PARAMETERSPINBOX_H
|
||||
|
||||
#include"parametervirtualwidget.h"
|
||||
|
||||
class ParameterSpinBox :public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterSpinBox(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
|
||||
protected slots:
|
||||
void on_Changed(double);
|
||||
};
|
||||
|
||||
#endif // PARAMETERSPINBOX_H
|
||||
49
src/parameter/parametertext.cpp
Normal file
49
src/parameter/parametertext.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#include "parametertext.h"
|
||||
|
||||
#include "modcontext.h"
|
||||
extern AssignmentList * parser(const char *text);
|
||||
|
||||
ParameterText::ParameterText(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(lineEdit,SIGNAL(editingFinished()),this,SLOT(on_Changed()));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
lineEdit->setToolTip(object->description);
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterText::on_Changed()
|
||||
{
|
||||
if(object->dvt == Value::STRING){
|
||||
object->value = ValuePtr(lineEdit->text().toStdString());
|
||||
}
|
||||
else{
|
||||
ModuleContext ctx;
|
||||
AssignmentList *assignmentList;
|
||||
assignmentList=parser(lineEdit->text().toStdString().c_str());
|
||||
if(assignmentList==NULL){
|
||||
return ;
|
||||
}
|
||||
for(unsigned int i=0; i<assignmentList->size(); i++) {
|
||||
ValuePtr newValue=assignmentList[i].data()->expr.get()->evaluate(&ctx);
|
||||
if(object->dvt==newValue->type()){
|
||||
object->value=newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterText::setValue()
|
||||
{
|
||||
this->stackedWidget->setCurrentWidget(this->pageText);
|
||||
this->lineEdit->setText(QString::fromStdString(object->value->toString()));
|
||||
if(object->values->toDouble()>0){
|
||||
this->lineEdit->setMaxLength(object->values->toDouble());
|
||||
}
|
||||
}
|
||||
17
src/parameter/parametertext.h
Normal file
17
src/parameter/parametertext.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef PARAMETERTEXT_H
|
||||
#define PARAMETERTEXT_H
|
||||
|
||||
#include"parametervirtualwidget.h"
|
||||
|
||||
class ParameterText : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterText(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
|
||||
protected slots:
|
||||
void on_Changed();
|
||||
};
|
||||
|
||||
#endif // PARAMETERTEXT_H
|
||||
70
src/parameter/parametervector.cpp
Normal file
70
src/parameter/parametervector.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#include "parametervector.h"
|
||||
|
||||
ParameterVector::ParameterVector(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(doubleSpinBox1,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
connect(doubleSpinBox2,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
connect(doubleSpinBox3,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
connect(doubleSpinBox4,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
frame->setToolTip(object->description);
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterVector::on_Changed(double)
|
||||
{
|
||||
if (object->target == 5) {
|
||||
object->value = ValuePtr(doubleSpinBox1->value());
|
||||
} else {
|
||||
Value::VectorType vt;
|
||||
vt.push_back(this->doubleSpinBox1->value());
|
||||
if (!this->doubleSpinBox2->isReadOnly()) {
|
||||
vt.push_back(this->doubleSpinBox2->value());
|
||||
}
|
||||
if (!this->doubleSpinBox3->isReadOnly()) {
|
||||
vt.push_back(this->doubleSpinBox3->value());
|
||||
}
|
||||
if (!this->doubleSpinBox4->isReadOnly()) {
|
||||
vt.push_back(this->doubleSpinBox4->value());
|
||||
}
|
||||
object->value = ValuePtr(vt);
|
||||
}
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterVector::setValue()
|
||||
{
|
||||
this->stackedWidget->setCurrentWidget(this->pageVector);
|
||||
Value::VectorType vec = object->value->toVector();
|
||||
if (vec.size() < 4) {
|
||||
this->doubleSpinBox4->hide();
|
||||
this->doubleSpinBox4->setReadOnly(true);
|
||||
}
|
||||
if (vec.size() < 3) {
|
||||
this->doubleSpinBox3->hide();
|
||||
this->doubleSpinBox3->setReadOnly(true);
|
||||
}
|
||||
if (vec.size() < 2) {
|
||||
this->doubleSpinBox2->hide();
|
||||
this->doubleSpinBox2->setReadOnly(true);
|
||||
}
|
||||
this->doubleSpinBox1->setValue(vec.at(0)->toDouble());
|
||||
if (vec.size() > 1) {
|
||||
this->doubleSpinBox2->setValue(vec.at(1)->toDouble());
|
||||
this->doubleSpinBox2->setReadOnly(false);
|
||||
}
|
||||
if (vec.size() > 2) {
|
||||
this->doubleSpinBox3->setValue(vec.at(2)->toDouble());
|
||||
this->doubleSpinBox3->setReadOnly(false);
|
||||
}
|
||||
if (vec.size() > 3) {
|
||||
this->doubleSpinBox4->setValue(vec.at(3)->toDouble());
|
||||
this->doubleSpinBox4->setReadOnly(false);
|
||||
}
|
||||
}
|
||||
17
src/parameter/parametervector.h
Normal file
17
src/parameter/parametervector.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef PARAMETERVECTOR_H
|
||||
#define PARAMETERVECTOR_H
|
||||
|
||||
#include"parametervirtualwidget.h"
|
||||
|
||||
class ParameterVector : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterVector(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
|
||||
protected slots:
|
||||
void on_Changed(double);
|
||||
};
|
||||
|
||||
#endif // PARAMETERVECTOR_H
|
||||
44
src/parameter/parametervirtualwidget.h
Normal file
44
src/parameter/parametervirtualwidget.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef PARAMETERVIRTUALWIDGET_H
|
||||
#define PARAMETERVIRTUALWIDGET_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "value.h"
|
||||
#include "qtgettext.h"
|
||||
#include "ui_ParameterEntryWidget.h"
|
||||
#include "parameterobject.h"
|
||||
|
||||
class ParameterVirtualWidget : public QWidget, public Ui::ParameterEntryWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
ParameterObject *object;
|
||||
|
||||
public:
|
||||
ParameterVirtualWidget(QWidget *parent=0) : QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
virtual ~ParameterVirtualWidget(){}
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
protected:
|
||||
virtual void setValue()=0;
|
||||
void setName(const QString& name)
|
||||
{
|
||||
this->labelDescription->hide();
|
||||
this->labelParameter->setText(name);
|
||||
}
|
||||
|
||||
void setDescription(const QString& description)
|
||||
{
|
||||
this->labelDescription->show();
|
||||
this->labelDescription->setText(description);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PARAMETERVIRTUALWIDGET_H
|
||||
Loading…
Reference in a new issue