diff --git a/openscad.pro b/openscad.pro index 9a0f71fd..b237e70f 100644 --- a/openscad.pro +++ b/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 diff --git a/src/MainWindow.h b/src/MainWindow.h index 68d81788..e8b438f6 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -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 diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 0ed75748..e37a41e0 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -15,7 +15,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -30,7 +39,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -162,7 +180,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -374,6 +401,7 @@ + @@ -402,7 +430,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -528,7 +565,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -550,6 +596,36 @@ + + + Parameter Widget + + + 2 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + @@ -1283,6 +1359,17 @@ Ctrl+Shift+C + + + true + + + true + + + Hide parameters + + @@ -1297,6 +1384,12 @@
Dock.h
1
+ + ParameterWidget + QWidget +
parameter/ParameterWidget.h
+ 1 +
diff --git a/src/mainwin.cc b/src/mainwin.cc index 74e64731..f388668e 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -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()) diff --git a/src/parameter/ParameterEntryWidget.ui b/src/parameter/ParameterEntryWidget.ui new file mode 100644 index 00000000..5e8d944f --- /dev/null +++ b/src/parameter/ParameterEntryWidget.ui @@ -0,0 +1,287 @@ + + + ParameterEntryWidget + + + + 0 + 0 + 562 + 144 + + + + Form + + + + 4 + + + 4 + + + 4 + + + 9 + + + 0 + + + + + QFrame::Box + + + QFrame::Raised + + + 1 + + + 0 + + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + + + + Value + + + 4 + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + true + + + + + + true + + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 0 + + + 1000.000000000000000 + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 0 + + + 1000.000000000000000 + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 0 + + + 1000.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 0 + + + 1000.000000000000000 + + + + + + + + + + + + 11 + + + + Description + + + true + + + + + + + + 12 + 75 + true + + + + Parameter + + + + + + + + + + + diff --git a/src/parameter/ParameterWidget.cc b/src/parameter/ParameterWidget.cc new file mode 100644 index 00000000..522fb9f9 --- /dev/null +++ b/src/parameter/ParameterWidget.cc @@ -0,0 +1,156 @@ +/* + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2014 Clifford Wolf and + * Marius Kintel + * + * 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 + +#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(); +} diff --git a/src/parameter/ParameterWidget.h b/src/parameter/ParameterWidget.h new file mode 100644 index 00000000..80b91780 --- /dev/null +++ b/src/parameter/ParameterWidget.h @@ -0,0 +1,60 @@ +/* + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2014 Clifford Wolf and + * Marius Kintel + * + * 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 + + +#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(); +}; diff --git a/src/parameter/ParameterWidget.ui b/src/parameter/ParameterWidget.ui new file mode 100644 index 00000000..906f58f5 --- /dev/null +++ b/src/parameter/ParameterWidget.ui @@ -0,0 +1,106 @@ + + + ParameterWidget + + + + 0 + 0 + 486 + 590 + + + + Parameter Widget + + + + + + + 1 + 0 + + + + + + + + + + + + + + + + true + + + + + 0 + 0 + 472 + 502 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + Preset: + + + + + + + Automatic Preview + + + true + + + + + + + - + + + + + + + Detailed descritpion + + + true + + + + + + + + diff --git a/src/parameter/parametercheckbox.cpp b/src/parameter/parametercheckbox.cpp new file mode 100644 index 00000000..8fc55d31 --- /dev/null +++ b/src/parameter/parametercheckbox.cpp @@ -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()); +} diff --git a/src/parameter/parametercheckbox.h b/src/parameter/parametercheckbox.h new file mode 100644 index 00000000..5cbadd6f --- /dev/null +++ b/src/parameter/parametercheckbox.h @@ -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 diff --git a/src/parameter/parametercombobox.cpp b/src/parameter/parametercombobox.cpp new file mode 100644 index 00000000..d50f0239 --- /dev/null +++ b/src/parameter/parametercombobox.cpp @@ -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); + } +} + + diff --git a/src/parameter/parametercombobox.h b/src/parameter/parametercombobox.h new file mode 100644 index 00000000..9e541b24 --- /dev/null +++ b/src/parameter/parametercombobox.h @@ -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 diff --git a/src/parameter/parameterextractor.cpp b/src/parameter/parameterextractor.cpp new file mode 100644 index 00000000..ffa39398 --- /dev/null +++ b/src/parameter/parameterextractor.cpp @@ -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(); +} diff --git a/src/parameter/parameterextractor.h b/src/parameter/parameterextractor.h new file mode 100644 index 00000000..98478007 --- /dev/null +++ b/src/parameter/parameterextractor.h @@ -0,0 +1,29 @@ +#ifndef PARAMETEREXTRACTOR_H +#define PARAMETEREXTRACTOR_H + +#include "FileModule.h" +#include "parametervirtualwidget.h" + +class ParameterExtractor +{ + +protected: + + typedef std::map 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 diff --git a/src/parameter/parameterobject.cpp b/src/parameter/parameterobject.cpp new file mode 100644 index 00000000..09e26dad --- /dev/null +++ b/src/parameter/parameterobject.cpp @@ -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(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); +} diff --git a/src/parameter/parameterobject.h b/src/parameter/parameterobject.h new file mode 100644 index 00000000..cd25c632 --- /dev/null +++ b/src/parameter/parameterobject.h @@ -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 diff --git a/src/parameter/parameterslider.cpp b/src/parameter/parameterslider.cpp new file mode 100644 index 00000000..eda8d0c7 --- /dev/null +++ b/src/parameter/parameterslider.cpp @@ -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)); +} diff --git a/src/parameter/parameterslider.h b/src/parameter/parameterslider.h new file mode 100644 index 00000000..50d7446f --- /dev/null +++ b/src/parameter/parameterslider.h @@ -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 diff --git a/src/parameter/parameterspinbox.cpp b/src/parameter/parameterspinbox.cpp new file mode 100644 index 00000000..9b8905a9 --- /dev/null +++ b/src/parameter/parameterspinbox.cpp @@ -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(); +} diff --git a/src/parameter/parameterspinbox.h b/src/parameter/parameterspinbox.h new file mode 100644 index 00000000..3659e7ac --- /dev/null +++ b/src/parameter/parameterspinbox.h @@ -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 diff --git a/src/parameter/parametertext.cpp b/src/parameter/parametertext.cpp new file mode 100644 index 00000000..a92fa55b --- /dev/null +++ b/src/parameter/parametertext.cpp @@ -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; isize(); 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()); + } +} diff --git a/src/parameter/parametertext.h b/src/parameter/parametertext.h new file mode 100644 index 00000000..48660a98 --- /dev/null +++ b/src/parameter/parametertext.h @@ -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 diff --git a/src/parameter/parametervector.cpp b/src/parameter/parametervector.cpp new file mode 100644 index 00000000..62d28340 --- /dev/null +++ b/src/parameter/parametervector.cpp @@ -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); + } +} diff --git a/src/parameter/parametervector.h b/src/parameter/parametervector.h new file mode 100644 index 00000000..ea6c9810 --- /dev/null +++ b/src/parameter/parametervector.h @@ -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 diff --git a/src/parameter/parametervirtualwidget.h b/src/parameter/parametervirtualwidget.h new file mode 100644 index 00000000..ce8bb297 --- /dev/null +++ b/src/parameter/parametervirtualwidget.h @@ -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