Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ public class CaDoodleFile {
@Expose(serialize = true, deserialize = true)
private TransformNR rulerLocation = new TransformNR();
@Expose(serialize = true, deserialize = true)

// Non Serialised private variables
private TransformNR workplane = new TransformNR();
@Expose(serialize = true, deserialize = true)
private CaDoodleParameters parameters;


private File self;
// @Expose (serialize = false, deserialize = false)
// private List<CSG> currentState = new ArrayList<CSG>();
Expand Down Expand Up @@ -1516,4 +1518,11 @@ public ThumbnailImage getImageEngine() {
private void setImageEngine(ThumbnailImage imageEngine) {
this.imageEngine = imageEngine;
}

public CaDoodleParameters getParameters() {
if(parameters==null)
parameters=new CaDoodleParameters();
parameters.setDb(csgDBinstance);
return parameters;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.neuronrobotics.bowlerstudio.scripting.cadoodle;

import com.google.gson.annotations.Expose;

public class CaDoodleParameter {
@Expose(serialize = true, deserialize = true)
private String key;
@Expose(serialize = true, deserialize = true)
private String value;

public CaDoodleParameter(String key, String string) {
this.key = key;
// TODO Auto-generated constructor stub
this.setValue(string);
}

public String getKey() {
return key;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.neuronrobotics.bowlerstudio.scripting.cadoodle;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;

import com.google.gson.annotations.Expose;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;

import eu.mihosoft.vrl.v3d.parametrics.CSGDatabaseInstance;

public class CaDoodleParameters {
@Expose(serialize = true, deserialize = true)
private ArrayList<CaDoodleParameter> params;

private HashMap<String, Double> values = null;

private CSGDatabaseInstance db;

public String getString(String key) {
for (CaDoodleParameter m : getParams()) {
if (m.getKey().contentEquals(key))
return m.getValue();
}
throw new NumberFormatException();
}
public void delete(String key) {
CaDoodleParameter set = null;
for (CaDoodleParameter m : getParams()) {
if (m.getKey().contentEquals(key)) {
set = m;
break;
}
}
if(set!=null)
params.remove(set);
}
public void set(String key, Object value) {
CaDoodleParameter set = null;
for (CaDoodleParameter m : getParams()) {
if (m.getKey().contentEquals(key)) {
set = m;
break;
}
}
if (set == null) {
set =new CaDoodleParameter(key,value.toString());
getParams().add(set);
}
set.setValue(value.toString());
values=null;
}
public ArrayList<String> keys(){
ArrayList<String> keys=new ArrayList<String>();
for(CaDoodleParameter e:getParams()) {
keys.add(e.getKey());
}
return keys;
}
private ArrayList<CaDoodleParameter> getParams() {
if (params == null) {
params = new ArrayList<CaDoodleParameter>();
}
return params;
}

public double getValue(String key) throws Exception {
Number double1 = getValues().get(key);
return double1.doubleValue();
}

private HashMap<String, Double> getValues() throws Exception {
if (values == null) {
String code = "HashMap<String,Double> numbers = new HashMap<String,Double>()\n";
String vars = "";
String equs = "";

for (CaDoodleParameter m : getParams()) {
// System.out.println(line);
String value = m.getValue();
String variableName =m.getKey();
String reconstructed = variableName + "=" + value;
try {
Double.parseDouble(value);
vars += reconstructed + "\n";
vars += "numbers.put(\"" + variableName + "\"," + variableName + ");\n";
} catch (NumberFormatException ex) {
equs += reconstructed + "\n";
equs += "numbers.put(\"" + variableName + "\"," + variableName + ");\n";
}
}
code += vars;
code += equs;
code += "return numbers";
// println code
values = (HashMap<String, Double>) ScriptingEngine.inlineScriptStringRun(getDb(), code, null, "Groovy");
}
return values;
}

public CSGDatabaseInstance getDb() {
return db;
}

public void setDb(CSGDatabaseInstance db) {
this.db = db;
}

}
20 changes: 20 additions & 0 deletions test/java/src/junit/bowler/CaDoodleWorkflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.neuronrobotics.bowlerstudio.scripting.cadoodle.AddFromScript;
import com.neuronrobotics.bowlerstudio.scripting.cadoodle.CaDoodleFile;
import com.neuronrobotics.bowlerstudio.scripting.cadoodle.CaDoodleOperation;
import com.neuronrobotics.bowlerstudio.scripting.cadoodle.CaDoodleParameters;
import com.neuronrobotics.bowlerstudio.scripting.cadoodle.Group;
import com.neuronrobotics.bowlerstudio.scripting.cadoodle.ModelNotes;
import com.neuronrobotics.bowlerstudio.scripting.cadoodle.MoveCenter;
Expand Down Expand Up @@ -84,6 +85,14 @@ public void test() throws Exception {
fail("Names must be unique!");
com.neuronrobotics.sdk.common.Log.error("Name one : "+nameOne );
com.neuronrobotics.sdk.common.Log.error("Name two : "+nameTwo );
CaDoodleParameters params = cf.getParameters();
params.set("var1", 10.0);
params.set("var2", 1.5);
params.set("var3", "var1 + var2 + 0.25");
params.set("var4", "(var3 / var2) + 0.25");
for(String k:cf.getParameters().keys()){
com.neuronrobotics.sdk.common.Log.debug("Key "+k+" value = "+cf.getParameters().getValue(k));
}
double distaance =10;
MoveCenter move = new MoveCenter()
.setLocation(new TransformNR(distaance,0,0))
Expand Down Expand Up @@ -302,8 +311,19 @@ public void test() throws Exception {
}
System.out.println("Saving");
loaded.save();
CaDoodleParameters parameters = loaded.getParameters();
for(String k:parameters.keys()){
com.neuronrobotics.sdk.common.Log.debug("Key "+k+" value = "+parameters.getValue(k)+" "+parameters.getString(k));
}
parameters.set("var2", 0.85);
for(String k:parameters.keys()){
com.neuronrobotics.sdk.common.Log.debug("Key "+k+" value = "+parameters.getValue(k)+" "+parameters.getString(k));
}
assertEquals(parameters.getValue("var4"), 13.3088235294, 0.0001);
loaded.close();
System.out.println("Save finished");
Thread.sleep(200);

}

}