added test cases, json file save when saveas, type of variable doesn't changes dues to json
This commit is contained in:
parent
99813eaceb
commit
34d9e9bb53
10 changed files with 262 additions and 29 deletions
|
|
@ -81,6 +81,7 @@ void ParameterWidget::setFile(QString jsonFile){
|
|||
getParameterSet(this->jsonFile);
|
||||
connect(addButton,SIGNAL(clicked()),this,SLOT(onSetAdd()));
|
||||
connect(deleteButton,SIGNAL(clicked()),this,SLOT(onSetDelete()));
|
||||
this->comboBox->clear();
|
||||
setComboBoxForSet();
|
||||
}
|
||||
|
||||
|
|
@ -271,23 +272,26 @@ void ParameterWidget::applyParameterSet(string setName){
|
|||
for(pt::ptree::value_type &v : root.get_child(path)){
|
||||
entry_map_t::iterator entry =entries.find(v.first);
|
||||
if(entry!=entries.end()){
|
||||
if(entry->second->dvt == Value::NUMBER){
|
||||
entry->second->value=ValuePtr(v.second.get_value<double>());
|
||||
}else if(entry->second->dvt== Value::BOOL){
|
||||
entry->second->value=ValuePtr(v.second.get_value<bool>());
|
||||
}else if(entry->second->dvt== Value::VECTOR){
|
||||
ModuleContext ctx;
|
||||
if(entry->second->dvt== Value::STRING){
|
||||
entry->second->value=ValuePtr(v.second.data());
|
||||
}else{
|
||||
|
||||
AssignmentList *assignmentList;
|
||||
assignmentList=parser(v.second.data().c_str());
|
||||
if(assignmentList==NULL){
|
||||
return ;
|
||||
}
|
||||
|
||||
ModuleContext ctx;
|
||||
Assignment *assignment;
|
||||
for(int i=0; i<assignmentList->size(); i++) {
|
||||
assignment=assignmentList[i].data();
|
||||
ValuePtr newValue=assignmentList[i].data()->expr.get()->evaluate(&ctx);
|
||||
if(entry->second->dvt==newValue->type()){
|
||||
entry->second->value=newValue;
|
||||
}
|
||||
}
|
||||
entry->second->value=assignment->expr.get()->evaluate(&ctx);
|
||||
}else if(entry->second->dvt== Value::STRING){
|
||||
entry->second->value=ValuePtr(v.second.data());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ ParameterSet::ParameterSet()
|
|||
}
|
||||
ParameterSet::~ParameterSet()
|
||||
{
|
||||
myfile.close();
|
||||
|
||||
}
|
||||
|
||||
void ParameterSet::getParameterSet(string filename){
|
||||
|
||||
fstream myfile;
|
||||
myfile.open (filename);
|
||||
// send your JSON above to the parser below, but populate ss first
|
||||
if(myfile.is_open()){
|
||||
|
|
@ -22,6 +23,27 @@ void ParameterSet::getParameterSet(string filename){
|
|||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
myfile.close();
|
||||
}
|
||||
|
||||
void ParameterSet::writeParameterSet(string filename){
|
||||
if(root.empty()){
|
||||
return;
|
||||
}
|
||||
|
||||
fstream myfile;
|
||||
myfile.open(filename,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();
|
||||
}
|
||||
|
||||
void ParameterSet::applyParameterSet(FileModule *fileModule,string setName)
|
||||
|
|
@ -39,21 +61,23 @@ void ParameterSet::applyParameterSet(FileModule *fileModule,string setName)
|
|||
Assignment *assignment;
|
||||
assignment=&(*it);
|
||||
const ValuePtr defaultValue = assignment->expr.get()->evaluate(&ctx);
|
||||
if(defaultValue->type()== Value::NUMBER){
|
||||
assignment->expr = shared_ptr<Expression>(new Literal(ValuePtr(v.second.get_value<double>()))) ;
|
||||
}else if(defaultValue->type()== Value::BOOL){
|
||||
assignment->expr = shared_ptr<Expression>(new Literal(ValuePtr(v.second.get_value<bool>())));
|
||||
}else if(defaultValue->type()== Value::VECTOR){
|
||||
if(defaultValue->type()== Value::STRING){
|
||||
assignment->expr = shared_ptr<Expression>(new Literal(ValuePtr(v.second.data())));
|
||||
}else{
|
||||
|
||||
AssignmentList *assignmentList;
|
||||
assignmentList=parser(v.second.data().c_str());
|
||||
for(int i=0; i<assignmentList->size(); i++) {
|
||||
assignment=assignmentList[i].data();
|
||||
if(assignmentList==NULL){
|
||||
return ;
|
||||
}
|
||||
ModuleContext ctx;
|
||||
for(int i=0; i<assignmentList->size(); i++) {
|
||||
if(defaultValue->type()== assignmentList[i].data()->expr.get()->evaluate(&ctx)->type()){
|
||||
assignment=assignmentList[i].data();
|
||||
}
|
||||
}
|
||||
}else if(defaultValue->type()== Value::STRING){
|
||||
assignment->expr = shared_ptr<Expression>(new Literal(ValuePtr(v.second.data())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ class ParameterSet
|
|||
|
||||
protected:
|
||||
pt::ptree root;
|
||||
fstream myfile;
|
||||
typedef map<string,pt::ptree::value_type> Parameterset;
|
||||
Parameterset parameterSet;
|
||||
|
||||
|
|
@ -28,6 +27,7 @@ public:
|
|||
ParameterSet();
|
||||
~ParameterSet();
|
||||
void getParameterSet(string filename);
|
||||
void writeParameterSet(string filename);
|
||||
void applyParameterSet(FileModule *fileModule,string setName);
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -26,10 +26,15 @@ void ParameterText::on_Changed()
|
|||
AssignmentList *assignmentList;
|
||||
assignmentList=parser(lineEdit->text().toStdString().c_str());
|
||||
Assignment *assignment;
|
||||
for(int i=0; i<assignmentList->size(); i++) {
|
||||
assignment=assignmentList[i].data();
|
||||
if(assignmentList==NULL){
|
||||
return ;
|
||||
}
|
||||
for(int i=0; i<assignmentList->size(); i++) {
|
||||
ValuePtr newValue=assignmentList[i].data()->expr.get()->evaluate(&ctx);
|
||||
if(object->dvt==newValue->type()){
|
||||
object->value=newValue;
|
||||
}
|
||||
}
|
||||
object->value=assignment->expr.get()->evaluate(&ctx);
|
||||
}
|
||||
emit changed();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ MainWindow::MainWindow(const QString &filename)
|
|||
{
|
||||
setupUi(this);
|
||||
|
||||
this->parameterWidget->setFile(filename);
|
||||
|
||||
editorDockTitleWidget = new QWidget();
|
||||
consoleDockTitleWidget = new QWidget();
|
||||
parameterDockTitleWidget = new QWidget();
|
||||
|
|
@ -783,7 +783,7 @@ void MainWindow::setFileName(const QString &filename)
|
|||
QFileInfo fileinfo(filename);
|
||||
this->fileName = fileinfo.absoluteFilePath();
|
||||
setWindowFilePath(this->fileName);
|
||||
|
||||
this->parameterWidget->setFile(this->fileName);
|
||||
QDir::setCurrent(fileinfo.dir().absolutePath());
|
||||
this->top_ctx.setDocumentPath(fileinfo.dir().absolutePath().toLocal8Bit().constData());
|
||||
}
|
||||
|
|
@ -1433,6 +1433,8 @@ void MainWindow::actionSaveAs()
|
|||
}
|
||||
}
|
||||
}
|
||||
QString jsonfile=new_filename;
|
||||
this->parameterWidget->writeParameterSet(jsonfile.replace(".scad",".json").toStdString());
|
||||
setFileName(new_filename);
|
||||
actionSave();
|
||||
}
|
||||
|
|
|
|||
42
testdata/scad/customizer/group.scad
vendored
Normal file
42
testdata/scad/customizer/group.scad
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// combo box for nunber
|
||||
Numbers=2; // [0, 1, 2, 3]
|
||||
|
||||
// combo box for string
|
||||
Strings="foo"; // [foo, bar, baz]
|
||||
|
||||
//labeled combo box for numbers
|
||||
Labeled_values=10; // [10:L, 20:M, 30:L]
|
||||
|
||||
//labeled combo box for string
|
||||
Labeled_value="S"; // [S:Small, M:Medium, L:Large]
|
||||
|
||||
/*[ Global ]*/
|
||||
// slider widget for number
|
||||
slider =34; // [10:100]
|
||||
|
||||
//step slider for number
|
||||
stepSlider=2; //[0:5:100]
|
||||
|
||||
/* [Hidden] */
|
||||
|
||||
//description
|
||||
Variable = true; //comment
|
||||
|
||||
/*[Global] */
|
||||
|
||||
// spinbox with step size 23
|
||||
Spinbox = 5; //23
|
||||
|
||||
/* [Textbox] */
|
||||
|
||||
//Text box for vector with more than 4 elements
|
||||
Vector=[12,34,44,43,23,23];//comment
|
||||
|
||||
// Text box for string
|
||||
String="hello"; //comment
|
||||
|
||||
/* [Special vector] */
|
||||
//Text box for vector with less than or equal to 4 elements
|
||||
Vector2=[12,34,45,23]; //any thing
|
||||
|
||||
echo(String);
|
||||
58
testdata/scad/customizer/nativeParameter.scad
vendored
Normal file
58
testdata/scad/customizer/nativeParameter.scad
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
@Parameter(12)
|
||||
x1 = 1;
|
||||
@Description("normal description")
|
||||
@Parameter(12)
|
||||
x2 = 1;
|
||||
@Description("normal1 description")
|
||||
@Description("normal2 description")
|
||||
@Parameter(12)
|
||||
x3 = 1;
|
||||
@Parameter("ADAD")
|
||||
@Parameter([1 : 12])
|
||||
@Parameter(12)
|
||||
x4 = 1;
|
||||
@Group("Global")
|
||||
@Description("normal description")
|
||||
@Parameter([1 : 12])
|
||||
x5 = 1;
|
||||
@Description("normal description")
|
||||
@Group("Global")
|
||||
@Parameter([1 : 2 : 12])
|
||||
x6 = 1;
|
||||
@Description("normal description")
|
||||
x7 = 1;
|
||||
@Group("Global")
|
||||
x8 = 1;
|
||||
x9 = 1;
|
||||
x10 = 1;
|
||||
x11 = 1;
|
||||
@Group("Global")
|
||||
@Parameter([12])
|
||||
x12 = 1;
|
||||
@Parameter([[10, "Small"], [20, "Medium"], [30, "Large"]])
|
||||
x13 = 10;
|
||||
@Parameter([[10, 100], [20, 101], [30, 102]])
|
||||
x14 = 10;
|
||||
@Parameter("parameter")
|
||||
x15 = 10;
|
||||
@Parameter([0, 1, 2, 3])
|
||||
x16 = 10;
|
||||
@Parameter("parameter")
|
||||
x17 = "text";
|
||||
@Parameter(["foo", "bar", "baz"])
|
||||
x18 = "text";
|
||||
@Parameter([[0, "text"], [1, "foo"], [2, "bar"], [3, "hello"]])
|
||||
x19 = "text";
|
||||
@Parameter([["foo", 10], ["bar", 10], ["baz", 30]])
|
||||
x20 = "text";
|
||||
@Parameter([["foo", "yes"], ["bar", "no"], ["baz", "mgiht"]])
|
||||
x21 = "text";
|
||||
@Parameter([23, 4])
|
||||
x22 = [12, 34];
|
||||
@Parameter([23, 4, 23, 4, 45])
|
||||
x23 = [12, 34];
|
||||
@Parameter([23, 4, 2, 3, 4, 6])
|
||||
x24 = [12, 34, 2, 3, 41, 23];
|
||||
@Parameter("end parameter")
|
||||
x27 = 12;
|
||||
|
||||
|
|
@ -1531,7 +1531,8 @@ add_cmdline_test(moduledumptest EXE ${OPENSCAD_BINPATH} ARGS -o SUFFIX ast FILES
|
|||
${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/allmodulescomment.scad
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/allfunctionscomment.scad
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/allexpressionscomment.scad
|
||||
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/nativeParameter.scad
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/group.scad
|
||||
)
|
||||
add_cmdline_test(csgtexttest SUFFIX txt FILES
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/allexpressions.scad
|
||||
|
|
|
|||
42
tests/regression/moduledumptest/group-expected.ast
Normal file
42
tests/regression/moduledumptest/group-expected.ast
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
@Description("combo box for nunber")
|
||||
@Parameter([0, 1, 2, 3])
|
||||
Numbers = 2;
|
||||
@Description("combo box for string")
|
||||
@Parameter(["foo", "bar", "baz"])
|
||||
Strings = "foo";
|
||||
@Description("labeled combo box for numbers")
|
||||
@Parameter([[10, "L"], [20, "M"], [30, "L"]])
|
||||
Labeled_values = 10;
|
||||
@Description("labeled combo box for string")
|
||||
@Parameter([["S", "Small"], ["M", "Medium"], ["L", "Large"]])
|
||||
Labeled_value = "S";
|
||||
@Group(" Global ")
|
||||
@Description("slider widget for number")
|
||||
@Parameter([10 : 100])
|
||||
slider = 34;
|
||||
@Group(" Global ")
|
||||
@Description("step slider for number")
|
||||
@Parameter([0 : 5 : 100])
|
||||
stepSlider = 2;
|
||||
@Group("Hidden")
|
||||
@Description("description")
|
||||
@Parameter("comment")
|
||||
Variable = true;
|
||||
@Group("Global")
|
||||
@Description("spinbox with step size 23")
|
||||
@Parameter(23)
|
||||
Spinbox = 5;
|
||||
@Group("Textbox")
|
||||
@Description("Text box for vector with more than 4 elements")
|
||||
@Parameter("comment")
|
||||
Vector = [12, 34, 44, 43, 23, 23];
|
||||
@Group("Textbox")
|
||||
@Description("Text box for string")
|
||||
@Parameter("comment")
|
||||
String = "hello";
|
||||
@Group("Special vector")
|
||||
@Description("Text box for vector with less than or equal to 4 elements")
|
||||
@Parameter("any thing")
|
||||
Vector2 = [12, 34, 45, 23];
|
||||
echo(String);
|
||||
|
||||
55
tests/regression/moduledumptest/nativeParameter-expected.ast
Normal file
55
tests/regression/moduledumptest/nativeParameter-expected.ast
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
@Parameter(12)
|
||||
x1 = 1;
|
||||
@Description("normal description")
|
||||
@Parameter(12)
|
||||
x2 = 1;
|
||||
@Description("normal1 description")
|
||||
@Parameter(12)
|
||||
x3 = 1;
|
||||
@Parameter("ADAD")
|
||||
x4 = 1;
|
||||
@Group("Global")
|
||||
@Description("normal description")
|
||||
@Parameter([1 : 12])
|
||||
x5 = 1;
|
||||
@Group("Global")
|
||||
@Description("normal description")
|
||||
@Parameter([1 : 2 : 12])
|
||||
x6 = 1;
|
||||
@Description("normal description")
|
||||
x7 = 1;
|
||||
@Group("Global")
|
||||
x8 = 1;
|
||||
x9 = 1;
|
||||
x10 = 1;
|
||||
x11 = 1;
|
||||
@Group("Global")
|
||||
@Parameter([12])
|
||||
x12 = 1;
|
||||
@Parameter([[10, "Small"], [20, "Medium"], [30, "Large"]])
|
||||
x13 = 10;
|
||||
@Parameter([[10, 100], [20, 101], [30, 102]])
|
||||
x14 = 10;
|
||||
@Parameter("parameter")
|
||||
x15 = 10;
|
||||
@Parameter([0, 1, 2, 3])
|
||||
x16 = 10;
|
||||
@Parameter("parameter")
|
||||
x17 = "text";
|
||||
@Parameter(["foo", "bar", "baz"])
|
||||
x18 = "text";
|
||||
@Parameter([[0, "text"], [1, "foo"], [2, "bar"], [3, "hello"]])
|
||||
x19 = "text";
|
||||
@Parameter([["foo", 10], ["bar", 10], ["baz", 30]])
|
||||
x20 = "text";
|
||||
@Parameter([["foo", "yes"], ["bar", "no"], ["baz", "mgiht"]])
|
||||
x21 = "text";
|
||||
@Parameter([23, 4])
|
||||
x22 = [12, 34];
|
||||
@Parameter([23, 4, 23, 4, 45])
|
||||
x23 = [12, 34];
|
||||
@Parameter([23, 4, 2, 3, 4, 6])
|
||||
x24 = [12, 34, 2, 3, 41, 23];
|
||||
@Parameter("end parameter")
|
||||
x27 = 12;
|
||||
|
||||
Loading…
Reference in a new issue