Cosmetics, coding style
This commit is contained in:
parent
fa5b58dfe5
commit
3b36f44977
7 changed files with 85 additions and 116 deletions
|
|
@ -176,7 +176,7 @@ static GroupList collectGroups(const std::string &fulltext)
|
|||
Insert Parameters in AST of given scad file
|
||||
form of annotations
|
||||
*/
|
||||
void CommentParser::addParameter(const char *fulltext, FileModule *root_module)
|
||||
void CommentParser::collectParameters(const char *fulltext, FileModule *root_module)
|
||||
{
|
||||
// Get all groups of parameters
|
||||
GroupList groupList = collectGroups(std::string(fulltext));
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
namespace CommentParser {
|
||||
|
||||
shared_ptr<Expression> parser(const char *text);
|
||||
void addParameter(const char *fulltext, FileModule *root_module);
|
||||
void collectParameters(const char *fulltext, FileModule *root_module);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ MainWindow::MainWindow(const QString &filename)
|
|||
|
||||
editorDockTitleWidget = new QWidget();
|
||||
consoleDockTitleWidget = new QWidget();
|
||||
parameterDockTitleWidget = new QWidget();
|
||||
parameterDockTitleWidget = new QWidget();
|
||||
|
||||
this->versionLabel = NULL; // must be initialized before calling updateStatusBar()
|
||||
updateStatusBar(NULL);
|
||||
|
|
@ -559,7 +559,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)));
|
||||
connect(this->parameterDock, SIGNAL(topLevelChanged(bool)), this, SLOT(parameterTopLevelChanged(bool)));
|
||||
// display this window and check for OpenGL 2.0 (OpenCSG) support
|
||||
viewModeThrownTogether();
|
||||
show();
|
||||
|
|
@ -636,14 +636,14 @@ void MainWindow::loadViewSettings(){
|
|||
viewActionHideToolBars->setChecked(settings.value("view/hideToolbar").toBool());
|
||||
hideToolbars();
|
||||
|
||||
if(Feature::ExperimentalCustomizer.is_enabled()){
|
||||
viewActionHideParameters->setChecked(settings.value("view/hideCustomizer").toBool());
|
||||
hideParameters();
|
||||
}else{
|
||||
viewActionHideParameters->setChecked(true);
|
||||
hideParameters();
|
||||
viewActionHideParameters->setVisible(false);
|
||||
}
|
||||
if (Feature::ExperimentalCustomizer.is_enabled()) {
|
||||
viewActionHideParameters->setChecked(settings.value("view/hideCustomizer").toBool());
|
||||
hideParameters();
|
||||
} else {
|
||||
viewActionHideParameters->setChecked(true);
|
||||
hideParameters();
|
||||
viewActionHideParameters->setVisible(false);
|
||||
}
|
||||
|
||||
updateMdiMode(settings.value("advanced/mdi").toBool());
|
||||
updateUndockMode(settings.value("advanced/undockableWindows").toBool());
|
||||
|
|
@ -675,7 +675,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);
|
||||
parameterDock->setFeatures(parameterDock->features() | QDockWidget::DockWidgetFloatable);
|
||||
} else {
|
||||
if (editorDock->isFloating()) {
|
||||
editorDock->setFloating(false);
|
||||
|
|
@ -685,10 +685,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);
|
||||
if (parameterDock->isFloating()) {
|
||||
parameterDock->setFloating(false);
|
||||
}
|
||||
parameterDock->setFeatures(parameterDock->features() & ~QDockWidget::DockWidgetFloatable);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -697,7 +697,7 @@ void MainWindow::updateReorderMode(bool reorderMode)
|
|||
MainWindow::reorderMode = reorderMode;
|
||||
editorDock->setTitleBarWidget(reorderMode ? 0 : editorDockTitleWidget);
|
||||
consoleDock->setTitleBarWidget(reorderMode ? 0 : consoleDockTitleWidget);
|
||||
parameterDock->setTitleBarWidget(reorderMode ? 0 : parameterDockTitleWidget);
|
||||
parameterDock->setTitleBarWidget(reorderMode ? 0 : parameterDockTitleWidget);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
|
@ -788,7 +788,7 @@ void MainWindow::setFileName(const QString &filename)
|
|||
this->fileName = fileinfo.absoluteFilePath();
|
||||
setWindowFilePath(this->fileName);
|
||||
|
||||
this->parameterWidget->setFile(this->fileName);
|
||||
this->parameterWidget->setFile(this->fileName);
|
||||
|
||||
QDir::setCurrent(fileinfo.dir().absolutePath());
|
||||
this->top_ctx.setDocumentPath(fileinfo.dir().absolutePath().toLocal8Bit().constData());
|
||||
|
|
@ -1728,7 +1728,7 @@ void MainWindow::compileTopLevelDocument()
|
|||
if (Feature::ExperimentalCustomizer.is_enabled()) {
|
||||
if (this->root_module!=NULL) {
|
||||
//add parameters as annotation in AST
|
||||
CommentParser::addParameter(fulltext.c_str(),this->root_module);
|
||||
CommentParser::collectParameters(fulltext.c_str(),this->root_module);
|
||||
}
|
||||
this->parameterWidget->setParameters(this->root_module);
|
||||
this->parameterWidget->applyParameters(this->root_module);
|
||||
|
|
|
|||
|
|
@ -404,10 +404,10 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c
|
|||
|
||||
if (Feature::ExperimentalCustomizer.is_enabled()) {
|
||||
// add parameter to AST
|
||||
CommentParser::addParameter(text.c_str(), root_module);
|
||||
CommentParser::collectParameters(text.c_str(), root_module);
|
||||
if (!parameterFile.empty() && !setName.empty()) {
|
||||
ParameterSet param;
|
||||
param.getParameterSet(parameterFile);
|
||||
param.readParameterSet(parameterFile);
|
||||
param.applyParameterSet(root_module, setName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,17 @@
|
|||
#include "parametercheckbox.h"
|
||||
#include "parametertext.h"
|
||||
#include "parametervector.h"
|
||||
#include <QInputDialog>
|
||||
|
||||
#include "modcontext.h"
|
||||
#include "comment.h"
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
namespace pt = boost::property_tree;
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <fstream>
|
||||
|
||||
ParameterWidget::ParameterWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
|
@ -89,7 +95,7 @@ void ParameterWidget::onSetAdd(){
|
|||
void ParameterWidget::setFile(QString jsonFile){
|
||||
|
||||
this->jsonFile=jsonFile.replace(".scad",".json").toStdString();
|
||||
getParameterSet(this->jsonFile);
|
||||
readParameterSet(this->jsonFile);
|
||||
connect(addButton,SIGNAL(clicked()),this,SLOT(onSetAdd()));
|
||||
connect(deleteButton,SIGNAL(clicked()),this,SLOT(onSetDelete()));
|
||||
this->comboBox->clear();
|
||||
|
|
@ -291,7 +297,6 @@ void ParameterWidget::applyParameterSet(string setName){
|
|||
return;
|
||||
}
|
||||
string path="SET."+setName;
|
||||
Parameterset::iterator set=parameterSet.find(setName);
|
||||
for(pt::ptree::value_type &v : root.get_child(path)){
|
||||
entry_map_t::iterator entry =entries.find(v.first);
|
||||
if(entry!=entries.end()){
|
||||
|
|
|
|||
|
|
@ -1,89 +1,65 @@
|
|||
#include "parameterset.h"
|
||||
#include "modcontext.h"
|
||||
#include "comment.h"
|
||||
#include "modcontext.h"
|
||||
#include "filemodule.h"
|
||||
#include "expression.h"
|
||||
|
||||
ParameterSet::ParameterSet()
|
||||
{
|
||||
}
|
||||
ParameterSet::~ParameterSet()
|
||||
{
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
void ParameterSet::readParameterSet(const std::string &filename)
|
||||
{
|
||||
try {
|
||||
pt::read_json(filename, this->root);
|
||||
}
|
||||
catch (const pt::json_parser_error &e) {
|
||||
// FIXME: Better error handling
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterSet::getParameterSet(const std::string &filename)
|
||||
void ParameterSet::writeParameterSet(const std::string &filename) const
|
||||
{
|
||||
std::fstream myfile;
|
||||
myfile.open (filename);
|
||||
// send your JSON above to the parser below, but populate ss first
|
||||
if(myfile.is_open()){
|
||||
try{
|
||||
pt::read_json(myfile, this->root);
|
||||
}
|
||||
catch (std::exception const& e){
|
||||
if (this->root.empty()) return;
|
||||
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
myfile.close();
|
||||
}
|
||||
|
||||
void ParameterSet::writeParameterSet(const std::string &filename){
|
||||
if(root.empty()){
|
||||
return;
|
||||
}
|
||||
|
||||
std::fstream myfile;
|
||||
myfile.open(filename, std::ios::out);
|
||||
// send your JSON above to the parser below, but populate ss first
|
||||
if(myfile.is_open()){
|
||||
try{
|
||||
pt::write_json(myfile, this->root);
|
||||
}
|
||||
catch (std::exception const& e){
|
||||
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
myfile.close();
|
||||
try {
|
||||
pt::write_json(filename, this->root);
|
||||
}
|
||||
catch (const pt::json_parser_error &e) {
|
||||
// FIXME: Better error handling
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterSet::applyParameterSet(FileModule *fileModule, const std::string &setName)
|
||||
{
|
||||
try{
|
||||
if (fileModule == NULL ||root.empty()) {
|
||||
return;
|
||||
}
|
||||
ModuleContext ctx;
|
||||
std::string path="SET."+setName;
|
||||
for (AssignmentList::iterator it = fileModule->scope.assignments.begin();it != fileModule->scope.assignments.end();it++) {
|
||||
|
||||
for(pt::ptree::value_type &v : root.get_child(path)){
|
||||
if(v.first== (*it).name){
|
||||
Assignment *assignment;
|
||||
assignment=&(*it);
|
||||
const ValuePtr defaultValue = assignment->expr.get()->evaluate(&ctx);
|
||||
if(defaultValue->type()== Value::STRING){
|
||||
|
||||
assignment->expr = shared_ptr<Expression>(new Literal(ValuePtr(v.second.data())));
|
||||
}else if(defaultValue->type()== Value::BOOL){
|
||||
|
||||
assignment->expr = shared_ptr<Expression>(new Literal(ValuePtr(v.second.get_value<bool>())));
|
||||
}else{
|
||||
|
||||
shared_ptr<Expression> params = CommentParser::parser(v.second.data().c_str());
|
||||
if (!params) continue;
|
||||
ModuleContext ctx;
|
||||
if (defaultValue->type() == params->evaluate(&ctx)->type()) {
|
||||
assignment->expr = params;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fileModule == NULL || this->root.empty()) return;
|
||||
try {
|
||||
ModuleContext ctx;
|
||||
std::string path = "SET." + setName;
|
||||
for (auto &assignment : fileModule->scope.assignments) {
|
||||
for (auto &v : root.get_child(path)) {
|
||||
if (v.first == assignment.name) {
|
||||
const ValuePtr defaultValue = assignment.expr->evaluate(&ctx);
|
||||
if (defaultValue->type() == Value::STRING) {
|
||||
assignment.expr = shared_ptr<Expression>(new Literal(ValuePtr(v.second.data())));
|
||||
}
|
||||
else if (defaultValue->type() == Value::BOOL) {
|
||||
assignment.expr = shared_ptr<Expression>(new Literal(ValuePtr(v.second.get_value<bool>())));
|
||||
} else {
|
||||
shared_ptr<Expression> params = CommentParser::parser(v.second.data().c_str());
|
||||
if (!params) continue;
|
||||
ModuleContext ctx;
|
||||
if (defaultValue->type() == params->evaluate(&ctx)->type()) {
|
||||
assignment.expr = params;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
catch (std::exception const& e) {
|
||||
// FIXME: Better error handling
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,6 @@
|
|||
#ifndef PARAMETERSET_H
|
||||
#define PARAMETERSET_H
|
||||
#pragma once
|
||||
|
||||
#include "expression.h"
|
||||
#include "FileModule.h"
|
||||
#include "modcontext.h"
|
||||
|
||||
#include <map>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
namespace pt = boost::property_tree;
|
||||
|
||||
|
|
@ -15,16 +8,11 @@ class ParameterSet
|
|||
{
|
||||
protected:
|
||||
pt::ptree root;
|
||||
typedef std::map<std::string, pt::ptree::value_type> Parameterset;
|
||||
Parameterset parameterSet;
|
||||
|
||||
public:
|
||||
ParameterSet();
|
||||
~ParameterSet();
|
||||
void getParameterSet(const std::string &filename);
|
||||
void writeParameterSet(const std::string &filename);
|
||||
void applyParameterSet(FileModule *fileModule, const std::string &setName);
|
||||
|
||||
ParameterSet() {}
|
||||
~ParameterSet() {}
|
||||
void readParameterSet(const std::string &filename);
|
||||
void writeParameterSet(const std::string &filename) const;
|
||||
void applyParameterSet(class FileModule *fileModule, const std::string &setName);
|
||||
};
|
||||
|
||||
#endif // PARAMETERSET_H
|
||||
|
|
|
|||
Loading…
Reference in a new issue