-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCaDoodleParameters.java
More file actions
109 lines (96 loc) · 2.75 KB
/
CaDoodleParameters.java
File metadata and controls
109 lines (96 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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;
}
}