From 22bde480888378b2bc6a0c20643153587556aa0b Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sat, 4 Oct 2025 17:13:21 -0400 Subject: [PATCH 01/24] Move map of parametrics into the CSGDatabase instance --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 86 +++++++++---------- src/main/java/eu/mihosoft/vrl/v3d/Cube.java | 18 ++-- .../java/eu/mihosoft/vrl/v3d/Cylinder.java | 36 ++++---- .../java/eu/mihosoft/vrl/v3d/Primitive.java | 8 +- .../java/eu/mihosoft/vrl/v3d/RoundedCube.java | 18 ++-- src/main/java/eu/mihosoft/vrl/v3d/Sphere.java | 16 ++-- .../vrl/v3d/parametrics/CSGDatabase.java | 5 +- .../v3d/parametrics/CSGDatabaseInstance.java | 22 ++++- 8 files changed, 114 insertions(+), 95 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index a442f3a6..a001d2d7 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -36,6 +36,7 @@ import eu.mihosoft.vrl.v3d.ext.org.poly2tri.PolygonUtil; import eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil; import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; +import eu.mihosoft.vrl.v3d.parametrics.CSGDatabaseInstance; import eu.mihosoft.vrl.v3d.parametrics.IParametric; import eu.mihosoft.vrl.v3d.parametrics.IRegenerate; import eu.mihosoft.vrl.v3d.parametrics.LengthParameter; @@ -172,7 +173,6 @@ public class CSG implements IuserAPI, Serializable { public static final int INDEX_OF_PARAMETRIC_UPPER = 2; private ArrayList groovyFileLines = new ArrayList<>(); private PrepForManufacturing manufactuing = null; - private HashMap mapOfparametrics = null; private IRegenerate regenerate = null; private boolean markForRegeneration = false; private String name = ""; @@ -224,7 +224,6 @@ public CSG prepForManufacturing() { ret.setName(getName()); ret.setColor(getColor()); ret.slicePlanes = slicePlanes; - ret.mapOfparametrics = mapOfparametrics; ret.exportFormats = exportFormats; return ret; } @@ -2937,19 +2936,19 @@ public CSG historySync(CSG dyingCSG) { if (useStackTraces) { this.addCreationEventStringList(dyingCSG.getCreationEventStackTraceList()); } - Set params = dyingCSG.getParameters(); - for (String param : params) { - boolean existing = false; - for (String s : this.getParameters()) { - if (s.contentEquals(param)) - existing = true; - } - if (!existing) { - Parameter vals = CSGDatabase.get(param); - if (vals != null) - this.setParameter(vals, dyingCSG.getMapOfparametrics().get(param)); - } - } +// Set params = dyingCSG.getParameters(); +// for (String param : params) { +// boolean existing = false; +// for (String s : this.getParameters()) { +// if (s.contentEquals(param)) +// existing = true; +// } +// if (!existing) { +// Parameter vals = CSGDatabase.get(param); +// if (vals != null) +// this.setParameter(vals, dyingCSG.getMapOfparametrics().get(param)); +// } +// } if (getName().length() == 0) setName(dyingCSG.getName()); setColor(dyingCSG.getColor()); @@ -3017,18 +3016,10 @@ public CSG setManufacturing(PrepForManufacturing manufactuing) { // return setManufacturing(manufactuing); // } - public CSG setParameter(Parameter w, IParametric function) { - if (w == null) - return this; - if (CSGDatabase.get(w.getName()) == null) - CSGDatabase.set(w.getName(), w); - if (getMapOfparametrics().get(w.getName()) == null) - getMapOfparametrics().put(w.getName(), function); - return this; - } - public CSG setParameter(Parameter w) { - setParameter(w, new IParametric() { + @Deprecated + public CSG setParameter(CSGDatabaseInstance instance,Parameter w) { + setParameter(instance,w, new IParametric() { @Override public CSG change(CSG oldCSG, String parameterKey, Long newValue) { if (parameterKey.contentEquals(w.getName())) @@ -3038,19 +3029,29 @@ public CSG change(CSG oldCSG, String parameterKey, Long newValue) { }); return this; } - - public CSG setParameter(String key, double defaultValue, double upperBound, double lowerBound, + @Deprecated + public CSG setParameter(CSGDatabaseInstance instance,String key, double defaultValue, double upperBound, double lowerBound, IParametric function) { ArrayList vals = new ArrayList(); vals.add(upperBound); vals.add(lowerBound); - setParameter(new LengthParameter(key, defaultValue, vals), function); + setParameter(instance,new LengthParameter(key, defaultValue, vals), function); return this; } - - public CSG setParameterIfNull(String key) { - if (getMapOfparametrics().get(key) == null) - getMapOfparametrics().put(key, new IParametric() { + @Deprecated + public CSG setParameter(CSGDatabaseInstance instance,Parameter w, IParametric function) { + if (w == null) + return this; + if (CSGDatabase.get(w.getName()) == null) + CSGDatabase.set(w.getName(), w); + if (instance.getMapOfparametrics(this).get(w.getName()) == null) + instance.getMapOfparametrics(this).put(w.getName(), function); + return this; + } + @Deprecated + public CSG setParameterIfNull(CSGDatabaseInstance instance,String key) { + if (instance.getMapOfparametrics(this).get(key) == null) + instance.getMapOfparametrics(this).put(key, new IParametric() { @Override public CSG change(CSG oldCSG, String parameterKey, Long newValue) { @@ -3060,14 +3061,14 @@ public CSG change(CSG oldCSG, String parameterKey, Long newValue) { }); return this; } + @Deprecated + public Set getParameters(CSGDatabaseInstance instance) { - public Set getParameters() { - - return getMapOfparametrics().keySet(); + return instance.getMapOfparametrics(this).keySet(); } - - public CSG setParameterNewValue(String key, double newValue) { - IParametric function = getMapOfparametrics().get(key); + @Deprecated + public CSG setParameterNewValue(CSGDatabaseInstance instance, String key, double newValue) { + IParametric function = instance.getMapOfparametrics(this).get(key); if (function != null) { CSG setManipulator = function.change(this, key, new Long((long) (newValue * 1000))) .setManipulator(this.getManipulator()); @@ -3097,12 +3098,7 @@ public CSG regenerate() { return this; } - public HashMap getMapOfparametrics() { - if (mapOfparametrics == null) { - mapOfparametrics = new HashMap<>(); - } - return mapOfparametrics; - } + public boolean isMarkedForRegeneration() { return markForRegeneration; diff --git a/src/main/java/eu/mihosoft/vrl/v3d/Cube.java b/src/main/java/eu/mihosoft/vrl/v3d/Cube.java index 96d1c52f..96786dc5 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/Cube.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/Cube.java @@ -105,15 +105,15 @@ public Cube(Vector3d center, Vector3d dimensions) { public Cube(double w, double h, double d) { this(Vector3d.ZERO, new Vector3d(w, h, d)); } - public Cube(LengthParameter w, LengthParameter h, LengthParameter d) { - this(Vector3d.ZERO, new Vector3d(w.getMM(), h.getMM(), d.getMM())); - parametrics.add(w); - parametrics.add(h); - parametrics.add(d); - } - public Cube(LengthParameter size) { - this(size,size,size); - } +// public Cube(LengthParameter w, LengthParameter h, LengthParameter d) { +// this(Vector3d.ZERO, new Vector3d(w.getMM(), h.getMM(), d.getMM())); +//// parametrics.add(w); +//// parametrics.add(h); +//// parametrics.add(d); +// } +// public Cube(LengthParameter size) { +// this(size,size,size); +// } /* (non-Javadoc) * @see eu.mihosoft.vrl.v3d.Primitive#toPolygons() */ diff --git a/src/main/java/eu/mihosoft/vrl/v3d/Cylinder.java b/src/main/java/eu/mihosoft/vrl/v3d/Cylinder.java index 77a9ed47..93abd128 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/Cylinder.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/Cylinder.java @@ -186,24 +186,24 @@ public Cylinder(double startRadius, double endRadius, double height) { this.startRadius = startRadius parametrics=new ArrayList<>(); +// ArrayList parametrics=new ArrayList<>(); /** @@ -62,9 +62,9 @@ public abstract class Primitive implements ItoCSG{ */ public CSG toCSG() { CSG tmp = CSG.fromPolygons(getProperties(),new ArrayList<>(toPolygons())); - if(parametrics!=null) - for(Parameter p:parametrics) - tmp.setParameter(p); +// if(parametrics!=null) +// for(Parameter p:parametrics) +// tmp.setParameter(p); //tmp.triangulate(); return tmp; } diff --git a/src/main/java/eu/mihosoft/vrl/v3d/RoundedCube.java b/src/main/java/eu/mihosoft/vrl/v3d/RoundedCube.java index f9c311f3..88781df0 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/RoundedCube.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/RoundedCube.java @@ -59,15 +59,15 @@ public RoundedCube(double size) { } - public RoundedCube(LengthParameter w, LengthParameter h, LengthParameter d) { - this(Vector3d.ZERO, new Vector3d(w.getMM(), h.getMM(), d.getMM())); - parametrics.add(w); - parametrics.add(h); - parametrics.add(d); - } - public RoundedCube(LengthParameter size) { - this(size,size,size); - } +// public RoundedCube(LengthParameter w, LengthParameter h, LengthParameter d) { +// this(Vector3d.ZERO, new Vector3d(w.getMM(), h.getMM(), d.getMM())); +// parametrics.add(w); +// parametrics.add(h); +// parametrics.add(d); +// } +// public RoundedCube(LengthParameter size) { +// this(size,size,size); +// } /** * Constructor. Creates a new rounded cuboid with the specified center and diff --git a/src/main/java/eu/mihosoft/vrl/v3d/Sphere.java b/src/main/java/eu/mihosoft/vrl/v3d/Sphere.java index 44556e20..5d87646c 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/Sphere.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/Sphere.java @@ -91,14 +91,14 @@ public Sphere(double radius) { // this(Vector3d.ZERO, new Vector3d(w.getMM(), h.getMM(), d.getMM())); // // } - public Sphere(LengthParameter size) { - this(size.getMM()); - parametrics.add(size); - } - public Sphere(LengthParameter size, int numSlices, int numStacks) { - this(size.getMM(), numSlices, numStacks); - parametrics.add(size); - } +// public Sphere(LengthParameter size) { +// this(size.getMM()); +// parametrics.add(size); +// } +// public Sphere(LengthParameter size, int numSlices, int numStacks) { +// this(size.getMM(), numSlices, numStacks); +// parametrics.add(size); +// } /** * Constructor. Creates a sphere with the specified radius, number of slices * and stacks. diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java index f04ed30f..157a8375 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java @@ -1,11 +1,14 @@ package eu.mihosoft.vrl.v3d.parametrics; import java.io.File; +import java.util.HashMap; import java.util.concurrent.CopyOnWriteArrayList; +import eu.mihosoft.vrl.v3d.CSG; + public class CSGDatabase { private static CSGDatabaseInstance instance = new CSGDatabaseInstance(new File("CSGdatabase.json")); - + public static void set(String key, Parameter value) { getInstance().set(key, value); } diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java index 9cc011c0..6f25b722 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java @@ -5,6 +5,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Type; +import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -14,6 +15,8 @@ import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; +import eu.mihosoft.vrl.v3d.CSG; + public class CSGDatabaseInstance { ConcurrentHashMap database = null; @@ -22,7 +25,24 @@ public class CSGDatabaseInstance { }.getType(); final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); final ConcurrentHashMap> parameterListeners = new ConcurrentHashMap<>(); - + + private HashMap> mapOfAllparametrics = null; + + private HashMap> getMap(){ + if(mapOfAllparametrics==null) { + mapOfAllparametrics=new HashMap>(); + } + return mapOfAllparametrics; + } + + public HashMap getMapOfparametrics(CSG source) { + if (getMap().get(source) == null) { + getMap().put(source,new HashMap<>()); + } + return getMap().get(source); + } + + public CSGDatabaseInstance(File db) { dbFile = db; if(!dbFile.exists()) From e1e05440372990f946a782ae379b5bda560b8e1f Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sat, 4 Oct 2025 17:15:01 -0400 Subject: [PATCH 02/24] fix the unit test --- src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java b/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java index de479394..3040744d 100644 --- a/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java +++ b/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java @@ -8,6 +8,7 @@ import org.junit.Test; +import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; import eu.mihosoft.vrl.v3d.parametrics.LengthParameter; public class ServerClientTest { @@ -48,7 +49,8 @@ public CSG prep(CSG incoming) { } }); LengthParameter param = new LengthParameter("parameter", (double) 35, new ArrayList()); - a.setParameter(param); + + a.setParameter(CSGDatabase.getInstance(),param ); CSG b = new Cube(20, 30, 5).toCSG(); b.getBounds(); CSG c = new Cube(10, 10, 10).toCSG(); From 74bbf5835c6e6ff1621c4421aade678209a0dee8 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sat, 4 Oct 2025 18:26:01 -0400 Subject: [PATCH 03/24] move operation code into the dataabase --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 128 ++++++++++-------- .../v3d/parametrics/CSGDatabaseInstance.java | 71 +++++++++- 2 files changed, 138 insertions(+), 61 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index a001d2d7..aaabe44b 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -140,12 +140,31 @@ public class CSG implements IuserAPI, Serializable { private static final long serialVersionUID = 4071874097772427063L; private static IDebug3dProvider providerOf3d = null; private static int numFacesInOffset = 15; + public static final int INDEX_OF_PARAMETRIC_DEFAULT = 0; + public static final int INDEX_OF_PARAMETRIC_LOWER = 1; + public static final int INDEX_OF_PARAMETRIC_UPPER = 2; + private static HashMap manufactuingMap = new HashMap(); + private static OptType defaultOptType = OptType.CSG_BOUND; + private static String defaultcolor = "#007956"; + // private boolean triangulated; + private static boolean useStackTraces = true; + private static boolean preventNonManifoldTriangles = false; + private static boolean warned = false; + // GPU processing + private static boolean useGPU = true; + private static int ExtraSpace = 100; + private static ICSGProgress progressMoniter = new ICSGProgress() { + @Override + public void progressUpdate(int currentIndex, int finalIndex, String type, CSG intermediateShape) { + System.err.println(type + " cur:" + currentIndex + " of " + finalIndex); + } + }; + private static ForkJoinPool poolGlobal=null; /** The polygons. */ private ArrayList polygons; /** The default opt type. */ - private static OptType defaultOptType = OptType.CSG_BOUND; /** The opt type. */ private OptType optType = null; @@ -157,7 +176,6 @@ public class CSG implements IuserAPI, Serializable { /** The current. */ private MeshView current; - private static String defaultcolor = "#007956"; /** The color. */ // private Color color = getDefaultColor(); @@ -168,33 +186,17 @@ public class CSG implements IuserAPI, Serializable { /** The manipulator. */ private Affine manipulator; private Bounds bounds; - public static final int INDEX_OF_PARAMETRIC_DEFAULT = 0; - public static final int INDEX_OF_PARAMETRIC_LOWER = 1; - public static final int INDEX_OF_PARAMETRIC_UPPER = 2; + private ArrayList groovyFileLines = new ArrayList<>(); - private PrepForManufacturing manufactuing = null; private IRegenerate regenerate = null; private boolean markForRegeneration = false; private String name = ""; private ArrayList slicePlanes = null; private ArrayList exportFormats = null; private ArrayList datumReferences = null; - // private boolean triangulated; - private static boolean useStackTraces = true; - private static boolean preventNonManifoldTriangles = false; - private static boolean warned = false; - // GPU processing - private static boolean useGPU = true; + private int pointsAdded; - private static int ExtraSpace = 100; - private static ICSGProgress progressMoniter = new ICSGProgress() { - @Override - public void progressUpdate(int currentIndex, int finalIndex, String type, CSG intermediateShape) { - System.err.println(type + " cur:" + currentIndex + " of " + finalIndex); - } - }; - private static ForkJoinPool poolGlobal=null; /** * Instantiates a new csg. @@ -2990,7 +2992,7 @@ public CSG prepMfg() { } public PrepForManufacturing getManufacturing() { - return manufactuing; + return manufactuingMap.get(this.hashCode()); } public PrepForManufacturing getMfg() { @@ -3002,7 +3004,7 @@ public CSG setMfg(PrepForManufacturing manufactuing) { } public CSG setManufacturing(PrepForManufacturing manufactuing) { - this.manufactuing = manufactuing; + manufactuingMap.put(this.hashCode(), manufactuing); return this; } @@ -3019,64 +3021,80 @@ public CSG setManufacturing(PrepForManufacturing manufactuing) { @Deprecated public CSG setParameter(CSGDatabaseInstance instance,Parameter w) { - setParameter(instance,w, new IParametric() { - @Override - public CSG change(CSG oldCSG, String parameterKey, Long newValue) { - if (parameterKey.contentEquals(w.getName())) - CSGDatabase.get(w.getName()).setValue(newValue); - return oldCSG; - } - }); + instance.setParameter(this, w); return this; } @Deprecated public CSG setParameter(CSGDatabaseInstance instance,String key, double defaultValue, double upperBound, double lowerBound, IParametric function) { - ArrayList vals = new ArrayList(); - vals.add(upperBound); - vals.add(lowerBound); - setParameter(instance,new LengthParameter(key, defaultValue, vals), function); + instance.setParameter(this, key, defaultValue, upperBound, lowerBound, function); return this; } @Deprecated public CSG setParameter(CSGDatabaseInstance instance,Parameter w, IParametric function) { if (w == null) return this; - if (CSGDatabase.get(w.getName()) == null) - CSGDatabase.set(w.getName(), w); - if (instance.getMapOfparametrics(this).get(w.getName()) == null) - instance.getMapOfparametrics(this).put(w.getName(), function); + instance.setParameter(this, w, function); return this; } @Deprecated public CSG setParameterIfNull(CSGDatabaseInstance instance,String key) { - if (instance.getMapOfparametrics(this).get(key) == null) - instance.getMapOfparametrics(this).put(key, new IParametric() { - - @Override - public CSG change(CSG oldCSG, String parameterKey, Long newValue) { - CSGDatabase.get(key).setValue(newValue); - return oldCSG; - } - }); + instance.setParameterIfNull(this, key); return this; } + @Deprecated public Set getParameters(CSGDatabaseInstance instance) { - return instance.getMapOfparametrics(this).keySet(); } @Deprecated public CSG setParameterNewValue(CSGDatabaseInstance instance, String key, double newValue) { - IParametric function = instance.getMapOfparametrics(this).get(key); - if (function != null) { - CSG setManipulator = function.change(this, key, new Long((long) (newValue * 1000))) - .setManipulator(this.getManipulator()); - setManipulator.setColor(getColor()); - return setManipulator; - } + instance.setParameterNewValue(this, key, newValue); return this; } + @Deprecated + public HashMap getMapOfparametrics(CSGDatabaseInstance instance){ + return instance.getMapOfparametrics(this); + } + + @Deprecated + public HashMap getMapOfparametrics(){ + new RuntimeException("This is using LEGACY database!").printStackTrace(); + return CSGDatabase.getInstance().getMapOfparametrics(this); + } + @Deprecated + public CSG setParameter(Parameter w) { + new RuntimeException("This is using LEGACY database!").printStackTrace(); + return setParameter(CSGDatabase.getInstance(),w); + } + @Deprecated + public CSG setParameter(String key, double defaultValue, double upperBound, double lowerBound, + IParametric function) { + new RuntimeException("This is using LEGACY database!").printStackTrace(); + setParameter(CSGDatabase.getInstance(), key, defaultValue, upperBound, lowerBound, function); + return this; + } + @Deprecated + public CSG setParameter(Parameter w, IParametric function) { + new RuntimeException("This is using LEGACY database!").printStackTrace(); + return setParameter(CSGDatabase.getInstance(), w, function); + } + @Deprecated + public CSG setParameterIfNull(String key) { + new RuntimeException("This is using LEGACY database!").printStackTrace(); + setParameterIfNull(CSGDatabase.getInstance(), key); + return this; + } + @Deprecated + public Set getParameters() { + new RuntimeException("This is using LEGACY database!").printStackTrace(); + return getParameters(CSGDatabase.getInstance()); + } + @Deprecated + public CSG setParameterNewValue( String key, double newValue) { + new RuntimeException("This is using LEGACY database!").printStackTrace(); + return setParameterNewValue(CSGDatabase.getInstance(),key,newValue); + } public CSG setRegenerate(IRegenerate function) { regenerate = function; diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java index 6f25b722..720a7d64 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java @@ -5,7 +5,9 @@ import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -26,22 +28,79 @@ public class CSGDatabaseInstance { final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); final ConcurrentHashMap> parameterListeners = new ConcurrentHashMap<>(); - private HashMap> mapOfAllparametrics = null; + private HashMap> mapOfAllparametrics = null; - private HashMap> getMap(){ + private HashMap> getMap(){ if(mapOfAllparametrics==null) { - mapOfAllparametrics=new HashMap>(); + mapOfAllparametrics=new HashMap>(); } return mapOfAllparametrics; } public HashMap getMapOfparametrics(CSG source) { - if (getMap().get(source) == null) { - getMap().put(source,new HashMap<>()); + if (getMap().get(source.hashCode()) == null) { + getMap().put(source.hashCode(),new HashMap<>()); } - return getMap().get(source); + return getMap().get(source.hashCode()); } + public CSGDatabaseInstance setParameter(CSG instance,Parameter w) { + setParameter(instance,w, new IParametric() { + @Override + public CSG change(CSG oldCSG, String parameterKey, Long newValue) { + if (parameterKey.contentEquals(w.getName())) + CSGDatabase.get(w.getName()).setValue(newValue); + return oldCSG; + } + }); + return this; + } + public CSGDatabaseInstance setParameter(CSG instance,String key, double defaultValue, double upperBound, double lowerBound, + IParametric function) { + ArrayList vals = new ArrayList(); + vals.add(upperBound); + vals.add(lowerBound); + setParameter(instance,new LengthParameter(key, defaultValue, vals), function); + return this; + } + public CSGDatabaseInstance setParameter(CSG obj,Parameter w, IParametric function) { + if (w == null) + return this; + if (CSGDatabase.get(w.getName()) == null) + CSGDatabase.set(w.getName(), w); + if (getMapOfparametrics(obj).get(w.getName()) == null) + getMapOfparametrics(obj).put(w.getName(), function); + return this; + } + + public CSGDatabaseInstance setParameterIfNull(CSG instance,String key) { + if (getMapOfparametrics(instance).get(key) == null) + getMapOfparametrics(instance).put(key, new IParametric() { + + @Override + public CSG change(CSG oldCSG, String parameterKey, Long newValue) { + CSGDatabase.get(key).setValue(newValue); + return oldCSG; + } + }); + return this; + } + + public Set getParameters(CSG instance) { + + return getMapOfparametrics(instance).keySet(); + } + + public CSGDatabaseInstance setParameterNewValue(CSG instance, String key, double newValue) { + IParametric function = getMapOfparametrics(instance).get(key); + if (function != null) { + CSG setManipulator = function.change(instance, key, new Long((long) (newValue * 1000))) + .setManipulator(instance.getManipulator()); + setManipulator.setColor(instance.getColor()); + return this; + } + return this; + } public CSGDatabaseInstance(File db) { dbFile = db; From 3491011aa24363ce952db27f47ad8463b2a71d99 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sat, 4 Oct 2025 18:44:08 -0400 Subject: [PATCH 04/24] remove the static API for cleaning --- .../vrl/v3d/parametrics/CSGDatabase.java | 104 +++++++++--------- .../v3d/parametrics/CSGDatabaseInstance.java | 10 +- .../vrl/v3d/parametrics/LengthParameter.java | 9 +- .../vrl/v3d/parametrics/Parameter.java | 31 ++++-- .../vrl/v3d/parametrics/StringParameter.java | 6 +- .../eu/mihosoft/vrl/v3d/ServerClientTest.java | 2 +- 6 files changed, 89 insertions(+), 73 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java index 157a8375..bfdba221 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java @@ -9,58 +9,58 @@ public class CSGDatabase { private static CSGDatabaseInstance instance = new CSGDatabaseInstance(new File("CSGdatabase.json")); - public static void set(String key, Parameter value) { - getInstance().set(key, value); - } - - public static Parameter get(String key) { - return getInstance().get(key); - } - - public static void clear() { - getInstance().clear(); - } - - public static void addParameterListener(String key, IParameterChanged l) { - getInstance().addParameterListener(key, l); - } - - public static void clearParameterListeners(String key) { - getInstance().clearParameterListeners(key); - } - - public static void removeParameterListener(String key, IParameterChanged l) { - getInstance().removeParameterListener(key, l); - } - - public static CopyOnWriteArrayList getParamListeners(String key) { - return getInstance().getParamListeners(key); - } - - public static void delete(String key) { - getInstance().delete(key); - } - - public static void loadDatabaseFromFile(File f) { - getInstance().loadDatabaseFromFile(f); - } - - public static String getDataBaseString() { - return getInstance().getDataBaseString(); - } - - public static void saveDatabase() { - getInstance().saveDatabase(); - } - - - public static File getDbFile() { - return getInstance().getDbFile(); - } - - public static void reLoadDbFile() { - getInstance().reLoadDbFile(); - } +// public static void set(String key, Parameter value) { +// getInstance().set(key, value); +// } +// +// public static Parameter get(String key) { +// return getInstance().get(key); +// } +// +// public static void clear() { +// getInstance().clear(); +// } +// +// public static void addParameterListener(String key, IParameterChanged l) { +// getInstance().addParameterListener(key, l); +// } +// +// public static void clearParameterListeners(String key) { +// getInstance().clearParameterListeners(key); +// } +// +// public static void removeParameterListener(String key, IParameterChanged l) { +// getInstance().removeParameterListener(key, l); +// } +// +// public static CopyOnWriteArrayList getParamListeners(String key) { +// return getInstance().getParamListeners(key); +// } +// +// public static void delete(String key) { +// getInstance().delete(key); +// } +// +// public static void loadDatabaseFromFile(File f) { +// getInstance().loadDatabaseFromFile(f); +// } +// +// public static String getDataBaseString() { +// return getInstance().getDataBaseString(); +// } +// +// public static void saveDatabase() { +// getInstance().saveDatabase(); +// } +// +// +// public static File getDbFile() { +// return getInstance().getDbFile(); +// } +// +// public static void reLoadDbFile() { +// getInstance().reLoadDbFile(); +// } public static CSGDatabaseInstance getInstance() { return instance; diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java index 720a7d64..0f24c816 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java @@ -49,7 +49,7 @@ public CSGDatabaseInstance setParameter(CSG instance,Parameter w) { @Override public CSG change(CSG oldCSG, String parameterKey, Long newValue) { if (parameterKey.contentEquals(w.getName())) - CSGDatabase.get(w.getName()).setValue(newValue); + get(w.getName()).setValue(newValue); return oldCSG; } }); @@ -60,14 +60,14 @@ public CSGDatabaseInstance setParameter(CSG instance,String key, double defaultV ArrayList vals = new ArrayList(); vals.add(upperBound); vals.add(lowerBound); - setParameter(instance,new LengthParameter(key, defaultValue, vals), function); + setParameter(instance,new LengthParameter(this,key, defaultValue, vals), function); return this; } public CSGDatabaseInstance setParameter(CSG obj,Parameter w, IParametric function) { if (w == null) return this; - if (CSGDatabase.get(w.getName()) == null) - CSGDatabase.set(w.getName(), w); + if (get(w.getName()) == null) + set(w.getName(), w); if (getMapOfparametrics(obj).get(w.getName()) == null) getMapOfparametrics(obj).put(w.getName(), function); return this; @@ -79,7 +79,7 @@ public CSGDatabaseInstance setParameterIfNull(CSG instance,String key) { @Override public CSG change(CSG oldCSG, String parameterKey, Long newValue) { - CSGDatabase.get(key).setValue(newValue); + get(key).setValue(newValue); return oldCSG; } }); diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/LengthParameter.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/LengthParameter.java index 2b03acda..051c71ad 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/LengthParameter.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/LengthParameter.java @@ -3,9 +3,12 @@ import java.util.ArrayList; public class LengthParameter extends Parameter { - - public LengthParameter(String key, Double defaultValue, ArrayList options) { - ArrayList opts=new ArrayList(); +// public LengthParameter(String key, Double defaultValue, ArrayList options) { +// this(CSGDatabase.getInstance(),key,defaultValue,options); +// } + public LengthParameter(CSGDatabaseInstance instance,String key, Double defaultValue, ArrayList options) { + super(instance); + ArrayList opts=new ArrayList(); for(Object d:options) opts.add(d.toString()); setup(key, new Long((long) (defaultValue*1000.0)), opts); diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/Parameter.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/Parameter.java index 15832ca8..d4db281e 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/Parameter.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/Parameter.java @@ -9,17 +9,20 @@ public class Parameter { private final ArrayList options=new ArrayList(); private Long value=null; private String strValue=null; + private CSGDatabaseInstance instance; - public Parameter(){} + //public Parameter(){} + public Parameter(CSGDatabaseInstance instance){ + this.setInstance(instance);} protected void setup(String key,Long defaultValue,ArrayList options){ this.name = key; - if(CSGDatabase.get(name)==null) + if(getInstance().get(name)==null) setValue(defaultValue); else{ - setValue(CSGDatabase.get(name).getValue()); + setValue(getInstance().get(name).getValue()); } - CSGDatabase.addParameterListener(name, new IParameterChanged() { + getInstance().addParameterListener(name, new IParameterChanged() { @Override public void parameterChanged(String name, Parameter p) { value = p.getValue();// if another instance of parameter with this key changes value @@ -28,16 +31,16 @@ public void parameterChanged(String name, Parameter p) { for(String o:options){ this.options.add(o); } - CSGDatabase.set(key, this); + getInstance().set(key, this); } protected void setup(String key,String defaultValue,ArrayList options){ this.name = key; - if(CSGDatabase.get(name)==null) + if(getInstance().get(name)==null) this.strValue = defaultValue; else{ - this.strValue = CSGDatabase.get(name).getStrValue(); + this.strValue = getInstance().get(name).getStrValue(); } - CSGDatabase.addParameterListener(name, new IParameterChanged() { + getInstance().addParameterListener(name, new IParameterChanged() { @Override public void parameterChanged(String name, Parameter p) { strValue = p.getStrValue();// if another instance of parameter with this key changes value @@ -46,7 +49,7 @@ public void parameterChanged(String name, Parameter p) { for(String o:options){ this.options.add(o); } - CSGDatabase.set(key, this); + getInstance().set(key, this); } public String getName() { return name; @@ -55,7 +58,7 @@ public String getName() { public void setValue(Long newVal){ if(value!=newVal){ value=newVal; - CopyOnWriteArrayList listeners = CSGDatabase.getParamListeners(name); + CopyOnWriteArrayList listeners = getInstance().getParamListeners(name); for(int i=0;i listeners = CSGDatabase.getParamListeners(name); + CopyOnWriteArrayList listeners = getInstance().getParamListeners(name); for(IParameterChanged l:listeners){ l.parameterChanged(name, this); } @@ -99,6 +102,12 @@ public double getMM(){ public double getMicrons(){ return (Long)getValue(); } + public CSGDatabaseInstance getInstance() { + return instance; + } + public void setInstance(CSGDatabaseInstance instance) { + this.instance = instance; + } } diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/StringParameter.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/StringParameter.java index 104ec4c0..9f67be8a 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/StringParameter.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/StringParameter.java @@ -6,7 +6,11 @@ public class StringParameter extends Parameter { private List options2; - public StringParameter(String key, String defaultValue, ArrayList options) { +// public StringParameter(String key, String defaultValue, ArrayList options) { +// this(CSGDatabase.getInstance(),key, defaultValue, options); +// } + public StringParameter(CSGDatabaseInstance instance,String key, String defaultValue, ArrayList options) { + super(instance); setup(key, defaultValue, options); options2 = options; } diff --git a/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java b/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java index 3040744d..69df4dfe 100644 --- a/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java +++ b/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java @@ -48,7 +48,7 @@ public CSG prep(CSG incoming) { return incoming; } }); - LengthParameter param = new LengthParameter("parameter", (double) 35, new ArrayList()); + LengthParameter param = new LengthParameter(CSGDatabase.getInstance(),"parameter", (double) 35, new ArrayList()); a.setParameter(CSGDatabase.getInstance(),param ); CSG b = new Cube(20, 30, 5).toCSG(); From 8259e60e6d64b66b398e6ec66d77f4b438b89578 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sat, 4 Oct 2025 21:09:13 -0400 Subject: [PATCH 05/24] exclude fields not explicatly serializable --- .../java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java | 1 - .../eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java index bfdba221..9103766f 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java @@ -65,7 +65,6 @@ public class CSGDatabase { public static CSGDatabaseInstance getInstance() { return instance; } - public static void setInstance(CSGDatabaseInstance instance) { System.out.println("\n\nCSG Instance Set here to "+instance.getDbFile().getAbsolutePath()+"\n\n"); CSGDatabase.instance = instance; diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java index 0f24c816..97bad497 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java @@ -25,7 +25,10 @@ public class CSGDatabaseInstance { File dbFile = null; final Type TT_mapStringString = new TypeToken>() { }.getType(); - final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); + //final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); + private static Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .excludeFieldsWithoutExposeAnnotation() + .create(); final ConcurrentHashMap> parameterListeners = new ConcurrentHashMap<>(); private HashMap> mapOfAllparametrics = null; From c5e0b67c9ecaf66b462298053a2019f216e57b2d Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sat, 4 Oct 2025 21:09:41 -0400 Subject: [PATCH 06/24] set which fields to expose, no recoursive inclusing with the instance --- .../java/eu/mihosoft/vrl/v3d/parametrics/Parameter.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/Parameter.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/Parameter.java index d4db281e..34007226 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/Parameter.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/Parameter.java @@ -3,12 +3,18 @@ import java.util.ArrayList; import java.util.concurrent.CopyOnWriteArrayList; +import com.google.gson.annotations.Expose; + public class Parameter { - + @Expose(serialize = true, deserialize = true) private String name=null; + @Expose(serialize = true, deserialize = true) private final ArrayList options=new ArrayList(); + @Expose(serialize = true, deserialize = true) private Long value=null; + @Expose(serialize = true, deserialize = true) private String strValue=null; + @Expose(serialize = false, deserialize = false) private CSGDatabaseInstance instance; //public Parameter(){} From b8741d6de585de1a016fc4775fab1beb9e920359 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sat, 4 Oct 2025 21:09:57 -0400 Subject: [PATCH 07/24] add save tothe test --- src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java b/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java index 69df4dfe..11b05d8c 100644 --- a/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java +++ b/src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java @@ -9,6 +9,7 @@ import org.junit.Test; import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; +import eu.mihosoft.vrl.v3d.parametrics.CSGDatabaseInstance; import eu.mihosoft.vrl.v3d.parametrics.LengthParameter; public class ServerClientTest { @@ -48,9 +49,12 @@ public CSG prep(CSG incoming) { return incoming; } }); - LengthParameter param = new LengthParameter(CSGDatabase.getInstance(),"parameter", (double) 35, new ArrayList()); + CSGDatabaseInstance instance = CSGDatabase.getInstance(); + + LengthParameter param = new LengthParameter(instance,"parameter", (double) 35, new ArrayList()); a.setParameter(CSGDatabase.getInstance(),param ); + instance.saveDatabase(); CSG b = new Cube(20, 30, 5).toCSG(); b.getBounds(); CSG c = new Cube(10, 10, 10).toCSG(); From c17329ba5aceec001dd370c9e661a62197b34db5 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sat, 4 Oct 2025 21:52:29 -0400 Subject: [PATCH 08/24] sync properties needs the dataabase to work --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 109 +++++++++--------- .../v3d/parametrics/CSGDatabaseInstance.java | 73 ++++++------ .../vrl/v3d/thumbnail/ThumbnailImage.java | 13 ++- .../eu/mihosoft/vrl/v3d/GroupingTest.java | 4 +- .../java/eu/mihosoft/vrl/v3d/SVGLoadTest.java | 9 +- .../java/eu/mihosoft/vrl/v3d/StlLoadTest.java | 3 +- 6 files changed, 114 insertions(+), 97 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index aaabe44b..c2732f47 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -2938,25 +2938,29 @@ public CSG historySync(CSG dyingCSG) { if (useStackTraces) { this.addCreationEventStringList(dyingCSG.getCreationEventStackTraceList()); } -// Set params = dyingCSG.getParameters(); -// for (String param : params) { -// boolean existing = false; -// for (String s : this.getParameters()) { -// if (s.contentEquals(param)) -// existing = true; -// } -// if (!existing) { -// Parameter vals = CSGDatabase.get(param); -// if (vals != null) -// this.setParameter(vals, dyingCSG.getMapOfparametrics().get(param)); -// } -// } if (getName().length() == 0) setName(dyingCSG.getName()); setColor(dyingCSG.getColor()); return this; } + public CSG syncParameter(CSGDatabaseInstance instance,CSG dyingCSG) { + Set params = dyingCSG.getParameters(instance); + for (String param : params) { + boolean existing = false; + for (String s : this.getParameters(instance)) { + if (s.contentEquals(param)) + existing = true; + } + if (!existing) { + Parameter vals = instance.get(param); + if (vals != null) + this.setParameter(instance,vals, dyingCSG.getMapOfparametrics(instance).get(param)); + } + } + return this; + } + public CSG addCreationEventStringList(ArrayList incoming) { if (useStackTraces) for (String s : incoming) { @@ -3057,44 +3061,44 @@ public HashMap getMapOfparametrics(CSGDatabaseInstance inst return instance.getMapOfparametrics(this); } - @Deprecated - public HashMap getMapOfparametrics(){ - new RuntimeException("This is using LEGACY database!").printStackTrace(); - return CSGDatabase.getInstance().getMapOfparametrics(this); - } - @Deprecated - public CSG setParameter(Parameter w) { - new RuntimeException("This is using LEGACY database!").printStackTrace(); - return setParameter(CSGDatabase.getInstance(),w); - } - @Deprecated - public CSG setParameter(String key, double defaultValue, double upperBound, double lowerBound, - IParametric function) { - new RuntimeException("This is using LEGACY database!").printStackTrace(); - setParameter(CSGDatabase.getInstance(), key, defaultValue, upperBound, lowerBound, function); - return this; - } - @Deprecated - public CSG setParameter(Parameter w, IParametric function) { - new RuntimeException("This is using LEGACY database!").printStackTrace(); - return setParameter(CSGDatabase.getInstance(), w, function); - } - @Deprecated - public CSG setParameterIfNull(String key) { - new RuntimeException("This is using LEGACY database!").printStackTrace(); - setParameterIfNull(CSGDatabase.getInstance(), key); - return this; - } - @Deprecated - public Set getParameters() { - new RuntimeException("This is using LEGACY database!").printStackTrace(); - return getParameters(CSGDatabase.getInstance()); - } - @Deprecated - public CSG setParameterNewValue( String key, double newValue) { - new RuntimeException("This is using LEGACY database!").printStackTrace(); - return setParameterNewValue(CSGDatabase.getInstance(),key,newValue); - } +// @Deprecated +// public HashMap getMapOfparametrics(){ +// new RuntimeException("This is using LEGACY database!").printStackTrace(); +// return CSGDatabase.getInstance().getMapOfparametrics(this); +// } +// @Deprecated +// public CSG setParameter(Parameter w) { +// new RuntimeException("This is using LEGACY database!").printStackTrace(); +// return setParameter(CSGDatabase.getInstance(),w); +// } +// @Deprecated +// public CSG setParameter(String key, double defaultValue, double upperBound, double lowerBound, +// IParametric function) { +// new RuntimeException("This is using LEGACY database!").printStackTrace(); +// setParameter(CSGDatabase.getInstance(), key, defaultValue, upperBound, lowerBound, function); +// return this; +// } +// @Deprecated +// public CSG setParameter(Parameter w, IParametric function) { +// new RuntimeException("This is using LEGACY database!").printStackTrace(); +// return setParameter(CSGDatabase.getInstance(), w, function); +// } +// @Deprecated +// public CSG setParameterIfNull(String key) { +// new RuntimeException("This is using LEGACY database!").printStackTrace(); +// setParameterIfNull(CSGDatabase.getInstance(), key); +// return this; +// } +// @Deprecated +// public Set getParameters() { +// new RuntimeException("This is using LEGACY database!").printStackTrace(); +// return getParameters(CSGDatabase.getInstance()); +// } +// @Deprecated +// public CSG setParameterNewValue( String key, double newValue) { +// new RuntimeException("This is using LEGACY database!").printStackTrace(); +// return setParameterNewValue(CSGDatabase.getInstance(),key,newValue); +// } public CSG setRegenerate(IRegenerate function) { regenerate = function; @@ -3726,10 +3730,11 @@ public CSG setMobileBaseName(String name) { public Optional getMobileBaseName() { return getStorage().getValue("MobileBaseName"); } - public CSG syncProperties(CSG dying) { + public CSG syncProperties(CSGDatabaseInstance instance,CSG dying) { getStorage().syncProperties(dying.getStorage()); regenerate = dying.regenerate; setManipulator(dying.manipulator); + syncParameter(instance,dying); return this; } diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java index 97bad497..d7d6c93b 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java @@ -25,30 +25,30 @@ public class CSGDatabaseInstance { File dbFile = null; final Type TT_mapStringString = new TypeToken>() { }.getType(); - //final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); + // final Gson gson = new + // GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); private static Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() - .excludeFieldsWithoutExposeAnnotation() - .create(); + .excludeFieldsWithoutExposeAnnotation().create(); final ConcurrentHashMap> parameterListeners = new ConcurrentHashMap<>(); - - private HashMap> mapOfAllparametrics = null; - - private HashMap> getMap(){ - if(mapOfAllparametrics==null) { - mapOfAllparametrics=new HashMap>(); + + private HashMap> mapOfAllparametrics = null; + + private HashMap> getMap() { + if (mapOfAllparametrics == null) { + mapOfAllparametrics = new HashMap>(); } return mapOfAllparametrics; } - + public HashMap getMapOfparametrics(CSG source) { if (getMap().get(source.hashCode()) == null) { - getMap().put(source.hashCode(),new HashMap<>()); + getMap().put(source.hashCode(), new HashMap<>()); } return getMap().get(source.hashCode()); } - - public CSGDatabaseInstance setParameter(CSG instance,Parameter w) { - setParameter(instance,w, new IParametric() { + + public CSGDatabaseInstance setParameter(CSG instance, Parameter w) { + setParameter(instance, w, new IParametric() { @Override public CSG change(CSG oldCSG, String parameterKey, Long newValue) { if (parameterKey.contentEquals(w.getName())) @@ -58,15 +58,17 @@ public CSG change(CSG oldCSG, String parameterKey, Long newValue) { }); return this; } - public CSGDatabaseInstance setParameter(CSG instance,String key, double defaultValue, double upperBound, double lowerBound, - IParametric function) { + + public CSGDatabaseInstance setParameter(CSG instance, String key, double defaultValue, double upperBound, + double lowerBound, IParametric function) { ArrayList vals = new ArrayList(); vals.add(upperBound); vals.add(lowerBound); - setParameter(instance,new LengthParameter(this,key, defaultValue, vals), function); + setParameter(instance, new LengthParameter(this, key, defaultValue, vals), function); return this; } - public CSGDatabaseInstance setParameter(CSG obj,Parameter w, IParametric function) { + + public CSGDatabaseInstance setParameter(CSG obj, Parameter w, IParametric function) { if (w == null) return this; if (get(w.getName()) == null) @@ -75,8 +77,8 @@ public CSGDatabaseInstance setParameter(CSG obj,Parameter w, IParametric functio getMapOfparametrics(obj).put(w.getName(), function); return this; } - - public CSGDatabaseInstance setParameterIfNull(CSG instance,String key) { + + public CSGDatabaseInstance setParameterIfNull(CSG instance, String key) { if (getMapOfparametrics(instance).get(key) == null) getMapOfparametrics(instance).put(key, new IParametric() { @@ -93,7 +95,7 @@ public Set getParameters(CSG instance) { return getMapOfparametrics(instance).keySet(); } - + public CSGDatabaseInstance setParameterNewValue(CSG instance, String key, double newValue) { IParametric function = getMapOfparametrics(instance).get(key); if (function != null) { @@ -104,22 +106,26 @@ public CSGDatabaseInstance setParameterNewValue(CSG instance, String key, double } return this; } - + public CSGDatabaseInstance(File db) { dbFile = db; - if(!dbFile.exists()) + if (!dbFile.exists()) { try { dbFile.createNewFile(); + saveDatabase(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } + }else { + getDatabase(); + } } public void set(String key, Parameter value) { getDatabase(); // synchronized(database){ - if(value==null) + if (value == null) throw new RuntimeException(); getDatabase().put(key, value); // } @@ -209,19 +215,18 @@ private ConcurrentHashMap getDatabase() { ConcurrentHashMap tm = gson.fromJson(jsonString, TT_mapStringString); if (tm != null) { -// ////System.out.println("Hash Map loaded from "+jsonString); -// for(String k:tm.keySet()){ -// ////System.out.println("Key: "+k+" vlaue= "+tm.get(k)); -// } + for (String k : tm.keySet()) { + tm.get(k).setInstance(this); + } setDatabase(tm); - }else { + } else { setDatabase(new ConcurrentHashMap()); saveDatabase(); } } } catch (Exception e) { - //e.printStackTrace(); - //System.err.println("Failed to load " + dbFile.getAbsolutePath()); + // e.printStackTrace(); + // System.err.println("Failed to load " + dbFile.getAbsolutePath()); setDatabase(new ConcurrentHashMap()); saveDatabase(); } @@ -233,7 +238,7 @@ public void run() { }); } - if(database==null) + if (database == null) throw new RuntimeException(); return database; } @@ -249,7 +254,9 @@ public void loadDatabaseFromFile(File f) { ConcurrentHashMap tm = gson.fromJson(jsonString, TT_mapStringString); if (tm != null) for (String k : tm.keySet()) { - set(k, tm.get(k)); + Parameter value = tm.get(k); + value.setInstance(this); + set(k, value); } saveDatabase(); } catch (Exception e) { diff --git a/src/main/java/eu/mihosoft/vrl/v3d/thumbnail/ThumbnailImage.java b/src/main/java/eu/mihosoft/vrl/v3d/thumbnail/ThumbnailImage.java index 08f133dd..bb04046a 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/thumbnail/ThumbnailImage.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/thumbnail/ThumbnailImage.java @@ -11,6 +11,7 @@ import eu.mihosoft.vrl.v3d.Bounds; import eu.mihosoft.vrl.v3d.CSG; import eu.mihosoft.vrl.v3d.Vector3d; +import eu.mihosoft.vrl.v3d.parametrics.CSGDatabaseInstance; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.SceneAntialiasing; @@ -66,11 +67,11 @@ public static Bounds getSellectedBounds(List incoming) { return new Bounds(min, max); } - public static WritableImage get(List c) { + public static WritableImage get(List c,CSGDatabaseInstance instance) { ArrayList csgList = new ArrayList(); for (CSG cs : c) { if (cs.getManipulator() != null) { - csgList.add(cs.transformed(TransformConverter.fromAffine(cs.getManipulator())).syncProperties(cs)); + csgList.add(cs.transformed(TransformConverter.fromAffine(cs.getManipulator())).syncProperties(instance,cs)); } else csgList.add(cs); } @@ -153,20 +154,20 @@ public static WritableImage get(List c) { return snapshot; } - public static Thread writeImage(CSG incoming, File toPNG) { + public static Thread writeImage(CSGDatabaseInstance instance,CSG incoming, File toPNG) { ArrayList bits = new ArrayList(); bits.add(incoming); - return writeImage(bits, toPNG); + return writeImage(instance,bits, toPNG); } - public static Thread writeImage(List incoming, File toPNG) { + public static Thread writeImage(CSGDatabaseInstance instance,List incoming, File toPNG) { Thread t = new Thread(new Runnable() { WritableImage img = null; @Override public void run() { File image = toPNG; - javafx.application.Platform.runLater(() -> img = ThumbnailImage.get(incoming)); + javafx.application.Platform.runLater(() -> img = ThumbnailImage.get(incoming,instance)); while (img == null) try { Thread.sleep(16); diff --git a/src/test/java/eu/mihosoft/vrl/v3d/GroupingTest.java b/src/test/java/eu/mihosoft/vrl/v3d/GroupingTest.java index 2760642b..153859c4 100644 --- a/src/test/java/eu/mihosoft/vrl/v3d/GroupingTest.java +++ b/src/test/java/eu/mihosoft/vrl/v3d/GroupingTest.java @@ -4,6 +4,8 @@ import org.junit.Test; +import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; + public class GroupingTest { @Test @@ -13,7 +15,7 @@ public void test() { c.addGroupMembership(groupID); c.setName("MyName"); c.addIsGroupResult(groupID); - CSG copy = c.clone().syncProperties(c).setName(c.getName()); + CSG copy = c.clone().syncProperties(CSGDatabase.getInstance(),c).setName(c.getName()); copy.removeGroupMembership(groupID); copy.removeIsGroupResult(groupID); diff --git a/src/test/java/eu/mihosoft/vrl/v3d/SVGLoadTest.java b/src/test/java/eu/mihosoft/vrl/v3d/SVGLoadTest.java index d9ea4d37..d966cc33 100644 --- a/src/test/java/eu/mihosoft/vrl/v3d/SVGLoadTest.java +++ b/src/test/java/eu/mihosoft/vrl/v3d/SVGLoadTest.java @@ -13,6 +13,7 @@ import org.junit.Before; import org.junit.Test; +import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; import eu.mihosoft.vrl.v3d.svg.SVGLoad; import eu.mihosoft.vrl.v3d.thumbnail.ThumbnailImage; import javafx.scene.paint.Color; @@ -76,7 +77,7 @@ public void flame() throws IOException { throw new RuntimeException("Failed to load"); try { ThumbnailImage.setCullFaceValue(CullFace.NONE); - ThumbnailImage.writeImage(parts,new File(svg.getAbsolutePath()+".png")).join(); + ThumbnailImage.writeImage(CSGDatabase.getInstance(),parts,new File(svg.getAbsolutePath()+".png")).join(); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); @@ -127,7 +128,7 @@ public void box() throws IOException { ArrayListparts =run(s); try { ThumbnailImage.setCullFaceValue(CullFace.NONE); - ThumbnailImage.writeImage(parts,new File(svg.getAbsolutePath()+".png")).join(); + ThumbnailImage.writeImage(CSGDatabase.getInstance(),parts,new File(svg.getAbsolutePath()+".png")).join(); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); @@ -146,7 +147,7 @@ public void inside() throws IOException { ArrayListparts =new ArrayList<>(Arrays.asList(CSG.unionAll(run(s)))); try { ThumbnailImage.setCullFaceValue(CullFace.NONE); - ThumbnailImage.writeImage(parts,new File(svg.getAbsolutePath()+".png")).join(); + ThumbnailImage.writeImage(CSGDatabase.getInstance(),parts,new File(svg.getAbsolutePath()+".png")).join(); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); @@ -165,7 +166,7 @@ public void adversarial() throws IOException { ArrayListparts =run(s); try { ThumbnailImage.setCullFaceValue(CullFace.NONE); - ThumbnailImage.writeImage(parts,new File(svg.getAbsolutePath()+".png")).join(); + ThumbnailImage.writeImage(CSGDatabase.getInstance(),parts,new File(svg.getAbsolutePath()+".png")).join(); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); diff --git a/src/test/java/eu/mihosoft/vrl/v3d/StlLoadTest.java b/src/test/java/eu/mihosoft/vrl/v3d/StlLoadTest.java index 84eae98d..7c089c42 100644 --- a/src/test/java/eu/mihosoft/vrl/v3d/StlLoadTest.java +++ b/src/test/java/eu/mihosoft/vrl/v3d/StlLoadTest.java @@ -7,6 +7,7 @@ import org.junit.Test; +import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; import eu.mihosoft.vrl.v3d.thumbnail.ThumbnailImage; import javafx.scene.shape.CullFace; @@ -19,7 +20,7 @@ public void test() throws IOException { CSG loaded = STL.file(file.toPath()); try { ThumbnailImage.setCullFaceValue(CullFace.NONE); - ThumbnailImage.writeImage(loaded,new File(file.getAbsolutePath()+".png")).join(); + ThumbnailImage.writeImage(CSGDatabase.getInstance(),loaded,new File(file.getAbsolutePath()+".png")).join(); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); From 7bd4d7c762de92990fe196162f006521250a888e Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sun, 5 Oct 2025 10:29:58 -0400 Subject: [PATCH 09/24] make the static and objects transparent foe serialization --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 41 +++++++++++----------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index c2732f47..5ea4b34d 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -135,31 +135,31 @@ @SuppressWarnings("restriction") public class CSG implements IuserAPI, Serializable { - private static final double POINTS_CONTACT_DISTANCE = 0.00001; - private static int MinPolygonsForOffloading = 200; - private static final long serialVersionUID = 4071874097772427063L; - private static IDebug3dProvider providerOf3d = null; - private static int numFacesInOffset = 15; - public static final int INDEX_OF_PARAMETRIC_DEFAULT = 0; - public static final int INDEX_OF_PARAMETRIC_LOWER = 1; - public static final int INDEX_OF_PARAMETRIC_UPPER = 2; - private static HashMap manufactuingMap = new HashMap(); - private static OptType defaultOptType = OptType.CSG_BOUND; - private static String defaultcolor = "#007956"; + transient private static final double POINTS_CONTACT_DISTANCE = 0.00001; + transient private static int MinPolygonsForOffloading = 200; + transient private static final long serialVersionUID = 4071874097772427063L; + transient private static IDebug3dProvider providerOf3d = null; + transient private static int numFacesInOffset = 15; + transient public static final int INDEX_OF_PARAMETRIC_DEFAULT = 0; + transient public static final int INDEX_OF_PARAMETRIC_LOWER = 1; + transient public static final int INDEX_OF_PARAMETRIC_UPPER = 2; + transient private static HashMap manufactuingMap = new HashMap(); + transient private static OptType defaultOptType = OptType.CSG_BOUND; + transient private static String defaultcolor = "#007956"; // private boolean triangulated; - private static boolean useStackTraces = true; - private static boolean preventNonManifoldTriangles = false; - private static boolean warned = false; + transient private static boolean useStackTraces = true; + transient private static boolean preventNonManifoldTriangles = false; + transient private static boolean warned = false; // GPU processing - private static boolean useGPU = true; - private static int ExtraSpace = 100; - private static ICSGProgress progressMoniter = new ICSGProgress() { + transient private static boolean useGPU = true; + transient private static int ExtraSpace = 100; + transient private static ICSGProgress progressMoniter = new ICSGProgress() { @Override public void progressUpdate(int currentIndex, int finalIndex, String type, CSG intermediateShape) { System.err.println(type + " cur:" + currentIndex + " of " + finalIndex); } }; - private static ForkJoinPool poolGlobal=null; + transient private static ForkJoinPool poolGlobal = null; /** The polygons. */ private ArrayList polygons; @@ -174,8 +174,7 @@ public void progressUpdate(int currentIndex, int finalIndex, String type, CSG in private PropertyStorage assembly; /** The current. */ - private MeshView current; - + transient private MeshView current; /** The color. */ // private Color color = getDefaultColor(); @@ -188,7 +187,7 @@ public void progressUpdate(int currentIndex, int finalIndex, String type, CSG in private Bounds bounds; private ArrayList groovyFileLines = new ArrayList<>(); - private IRegenerate regenerate = null; + transient private IRegenerate regenerate = null; private boolean markForRegeneration = false; private String name = ""; private ArrayList slicePlanes = null; From a5e12b5d820852473b02ba24388f4c685a655313 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sun, 5 Oct 2025 10:30:10 -0400 Subject: [PATCH 10/24] add prints --- src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java index 9103766f..b720e3d8 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.concurrent.CopyOnWriteArrayList; + import eu.mihosoft.vrl.v3d.CSG; public class CSGDatabase { @@ -63,6 +64,7 @@ public class CSGDatabase { // } public static CSGDatabaseInstance getInstance() { + new Exception("Depricated database access!").printStackTrace(); return instance; } public static void setInstance(CSGDatabaseInstance instance) { From e454dcfff849a32472fbda759626762ae92b49f5 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sun, 5 Oct 2025 15:23:49 -0400 Subject: [PATCH 11/24] Use a unique ID as the comparitor for identity --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 76 ++++++++++++------- .../v3d/parametrics/CSGDatabaseInstance.java | 13 ++-- 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index 5ea4b34d..65be540f 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -55,6 +55,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.UUID; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinWorkerThread; import java.util.concurrent.TimeUnit; @@ -143,7 +144,8 @@ public class CSG implements IuserAPI, Serializable { transient public static final int INDEX_OF_PARAMETRIC_DEFAULT = 0; transient public static final int INDEX_OF_PARAMETRIC_LOWER = 1; transient public static final int INDEX_OF_PARAMETRIC_UPPER = 2; - transient private static HashMap manufactuingMap = new HashMap(); + transient private static HashMap manufactuingMap = new HashMap(); + transient private static HashMap regenerate = new HashMap(); transient private static OptType defaultOptType = OptType.CSG_BOUND; transient private static String defaultcolor = "#007956"; // private boolean triangulated; @@ -187,7 +189,7 @@ public void progressUpdate(int currentIndex, int finalIndex, String type, CSG in private Bounds bounds; private ArrayList groovyFileLines = new ArrayList<>(); - transient private IRegenerate regenerate = null; + private boolean markForRegeneration = false; private String name = ""; private ArrayList slicePlanes = null; @@ -195,7 +197,7 @@ public void progressUpdate(int currentIndex, int finalIndex, String type, CSG in private ArrayList datumReferences = null; private int pointsAdded; - + private final String uniqueId = UUID.randomUUID().toString(); /** * Instantiates a new csg. @@ -208,7 +210,23 @@ public CSG() { addStackTrace(new Exception()); } } - + @Override + public boolean equals(Object obj) { + // Check if same reference + if (this == obj) return true; + + // Check if null or different class + if (obj == null || getClass() != obj.getClass()) return false; + + // Cast and compare fields + CSG test = (CSG) obj; + return this.getUniqueId().contentEquals(test.getUniqueId()); + } + @Override + public int hashCode() { + return getUniqueId().hashCode(); + } + public CSG addDatumReference(Transform t) { if (getDatumReferences() == null) setDatumReferences(new ArrayList()); @@ -2995,7 +3013,15 @@ public CSG prepMfg() { } public PrepForManufacturing getManufacturing() { - return manufactuingMap.get(this.hashCode()); + if(manufactuingMap.get(this.getUniqueId())==null) { + manufactuingMap.put(this.getUniqueId(), new PrepForManufacturing() { + @Override + public CSG prep(CSG incoming) { + return incoming; + } + }); + } + return manufactuingMap.get(this.getUniqueId()); } public PrepForManufacturing getMfg() { @@ -3007,55 +3033,36 @@ public CSG setMfg(PrepForManufacturing manufactuing) { } public CSG setManufacturing(PrepForManufacturing manufactuing) { - manufactuingMap.put(this.hashCode(), manufactuing); + manufactuingMap.put(this.getUniqueId(), manufactuing); return this; } -// @Deprecated -// public PrepForManufacturing getManufactuing() { -// return getManufacturing(); -// } - -// @Deprecated -// public CSG setManufactuing(PrepForManufacturing manufactuing) { -// return setManufacturing(manufactuing); -// } - - - @Deprecated public CSG setParameter(CSGDatabaseInstance instance,Parameter w) { instance.setParameter(this, w); return this; } - @Deprecated public CSG setParameter(CSGDatabaseInstance instance,String key, double defaultValue, double upperBound, double lowerBound, IParametric function) { instance.setParameter(this, key, defaultValue, upperBound, lowerBound, function); return this; } - @Deprecated public CSG setParameter(CSGDatabaseInstance instance,Parameter w, IParametric function) { if (w == null) return this; instance.setParameter(this, w, function); return this; } - @Deprecated public CSG setParameterIfNull(CSGDatabaseInstance instance,String key) { instance.setParameterIfNull(this, key); return this; } - - @Deprecated public Set getParameters(CSGDatabaseInstance instance) { return instance.getMapOfparametrics(this).keySet(); } - @Deprecated public CSG setParameterNewValue(CSGDatabaseInstance instance, String key, double newValue) { instance.setParameterNewValue(this, key, newValue); return this; } - @Deprecated public HashMap getMapOfparametrics(CSGDatabaseInstance instance){ return instance.getMapOfparametrics(this); } @@ -3100,19 +3107,28 @@ public HashMap getMapOfparametrics(CSGDatabaseInstance inst // } public CSG setRegenerate(IRegenerate function) { - regenerate = function; + regenerate.put(getUniqueId(), function); return this; } public IRegenerate getRegenerate() { - return regenerate; + if(regenerate.get(getUniqueId())==null) { + regenerate.put(getUniqueId(), new IRegenerate() { + @Override + public CSG regenerate(CSG previous) { + return previous; + } + }); + + } + return regenerate.get(getUniqueId()); } public CSG regenerate() { this.markForRegeneration = false; if (regenerate == null) return this; - CSG regenerate2 = regenerate.regenerate(this); + CSG regenerate2 = regenerate.get(getUniqueId()).regenerate(this); if (regenerate2 != null) return regenerate2.setManipulator(this.getManipulator()).historySync(this); ; @@ -4043,5 +4059,9 @@ public MeshView getCurrentMeshView() { public void setCurrentMeshView(MeshView current) { this.current = current; } + + public String getUniqueId() { + return uniqueId; + } } diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java index d7d6c93b..35d23636 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java @@ -31,20 +31,20 @@ public class CSGDatabaseInstance { .excludeFieldsWithoutExposeAnnotation().create(); final ConcurrentHashMap> parameterListeners = new ConcurrentHashMap<>(); - private HashMap> mapOfAllparametrics = null; + private HashMap> mapOfAllparametrics = null; - private HashMap> getMap() { + private HashMap> getMap() { if (mapOfAllparametrics == null) { - mapOfAllparametrics = new HashMap>(); + mapOfAllparametrics = new HashMap>(); } return mapOfAllparametrics; } public HashMap getMapOfparametrics(CSG source) { - if (getMap().get(source.hashCode()) == null) { - getMap().put(source.hashCode(), new HashMap<>()); + if (getMap().get(source.getUniqueId()) == null) { + getMap().put(source.getUniqueId(), new HashMap<>()); } - return getMap().get(source.hashCode()); + return getMap().get(source.getUniqueId()); } public CSGDatabaseInstance setParameter(CSG instance, Parameter w) { @@ -133,7 +133,6 @@ public void set(String key, Parameter value) { public Parameter get(String key) { Parameter ret = null; - getDatabase();// load database before synchronization // synchronized(database){ ret = getDatabase().get(key); // } From 0efc55124ce09176cff4a7dfd2e2bd92edd89b73 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sun, 5 Oct 2025 16:38:24 -0400 Subject: [PATCH 12/24] store the affine in a static structure as well as the rest of the interconnect code --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index 65be540f..e6783977 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -146,6 +146,8 @@ public class CSG implements IuserAPI, Serializable { transient public static final int INDEX_OF_PARAMETRIC_UPPER = 2; transient private static HashMap manufactuingMap = new HashMap(); transient private static HashMap regenerate = new HashMap(); + transient private static HashMap manipulator = new HashMap(); + transient private static OptType defaultOptType = OptType.CSG_BOUND; transient private static String defaultcolor = "#007956"; // private boolean triangulated; @@ -185,7 +187,6 @@ public void progressUpdate(int currentIndex, int finalIndex, String type, CSG in private double b = getDefaultColor().getBlue(); private double o = getDefaultColor().getOpacity(); /** The manipulator. */ - private Affine manipulator; private Bounds bounds; private ArrayList groovyFileLines = new ArrayList<>(); @@ -297,14 +298,13 @@ public CSG setTemporaryColor(Color color) { * @param manipulator the manipulator * @return the affine */ - public CSG setManipulator(javafx.scene.transform.Affine manipulator) { + public CSG setManipulator(javafx.scene.transform.Affine m) { if (manipulator == null) return this; - Affine old = manipulator; - this.manipulator = manipulator; + manipulator.put(getUniqueId(), m); if (getCurrentMeshView() != null) { getCurrentMeshView().getTransforms().clear(); - getCurrentMeshView().getTransforms().add(manipulator); + getCurrentMeshView().getTransforms().add(m); } return this; } @@ -553,7 +553,7 @@ public CSG moveToCenter() { public ArrayList move(ArrayList p) { ArrayList bits = new ArrayList(); - for (Transform t : p) { + for (int i = 0; i < p.size(); i++) { bits.add(this.clone()); } return move(bits, p); @@ -931,13 +931,13 @@ public CSG union(List incoming) { if(test==null) continue; boolean touching =false; - int t=-1; + //int t=-1; for(int j=0;j unique = new HashSet(); - int running = 0; + //int running = 0; for (int i = 0; i < numberOfPolygons; i++) { int ps = polyStartIndex[i]; int size = polySizes[i]; @@ -2878,9 +2878,9 @@ public CSG toolOffset(Number sn) { return union(minkowskiHullShape(printNozzel)); } - private int getNumFacesForOffsets() { - return getNumfacesinoffset(); - } +// private int getNumFacesForOffsets() { +// return getNumfacesinoffset(); +// } public CSG makeKeepaway(Number sn) { double shellThickness = sn.doubleValue(); @@ -2909,9 +2909,9 @@ public boolean hasManipulator() { return manipulator!=null; } public Affine getManipulator() { - if (manipulator == null) - return new Affine(); - return manipulator; + if (manipulator.get(uniqueId) == null) + manipulator.put(uniqueId, new Affine()); + return manipulator.get(uniqueId); } public CSG addCreationEventStackTraceList(ArrayList incoming) { @@ -3747,8 +3747,8 @@ public Optional getMobileBaseName() { } public CSG syncProperties(CSGDatabaseInstance instance,CSG dying) { getStorage().syncProperties(dying.getStorage()); - regenerate = dying.regenerate; - setManipulator(dying.manipulator); + regenerate.put(uniqueId,regenerate.get(dying.uniqueId)) ; + setManipulator(manipulator.get(dying.uniqueId)); syncParameter(instance,dying); return this; } From be36eba1b4e6dae5472ae7c2c809c98008e73c92 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sun, 5 Oct 2025 16:38:24 -0400 Subject: [PATCH 13/24] store the affine in a static structure as well as the rest of the interconnect code From 2aaf159cbd0f1fa41786c46f72680a52b6086db8 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sun, 5 Oct 2025 21:40:09 -0400 Subject: [PATCH 14/24] syncing the parameters for cadoodle state --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index e6783977..7628ff9b 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -2957,11 +2957,21 @@ public CSG historySync(CSG dyingCSG) { } if (getName().length() == 0) setName(dyingCSG.getName()); - setColor(dyingCSG.getColor()); + syncCadoodleCatagories(dyingCSG); return this; } + private void syncCadoodleCatagories(CSG dyingCSG) { + setIsHole(dyingCSG.isHole()); + setIsHide(dyingCSG.isHide()); + setIsAlwaysShow(dyingCSG.isAlwaysShow()); + setIsLock(dyingCSG.isLock()); + setIsMotionLock(dyingCSG.isMotionLock()); + setIsWireFrame(dyingCSG.isWireFrame()); + setColor(dyingCSG.getColor()); + } public CSG syncParameter(CSGDatabaseInstance instance,CSG dyingCSG) { + syncCadoodleCatagories(dyingCSG); Set params = dyingCSG.getParameters(instance); for (String param : params) { boolean existing = false; From 67f0b86615da299adb65f72b8fe374996a098cc0 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Mon, 6 Oct 2025 08:54:51 -0400 Subject: [PATCH 15/24] udate the cadoodle fetures --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index 7628ff9b..3b475845 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -2960,15 +2960,7 @@ public CSG historySync(CSG dyingCSG) { syncCadoodleCatagories(dyingCSG); return this; } - private void syncCadoodleCatagories(CSG dyingCSG) { - setIsHole(dyingCSG.isHole()); - setIsHide(dyingCSG.isHide()); - setIsAlwaysShow(dyingCSG.isAlwaysShow()); - setIsLock(dyingCSG.isLock()); - setIsMotionLock(dyingCSG.isMotionLock()); - setIsWireFrame(dyingCSG.isWireFrame()); - setColor(dyingCSG.getColor()); - } + public CSG syncParameter(CSGDatabaseInstance instance,CSG dyingCSG) { syncCadoodleCatagories(dyingCSG); @@ -3717,6 +3709,7 @@ public CSG setIsAlwaysShow(boolean Hide) { getStorage().set("isAlwaysShow", Hide); return this; } + public boolean isAlwaysShow() { Optional o = getStorage().getValue("isAlwaysShow"); @@ -3737,6 +3730,17 @@ public boolean isHole() { return o.get(); return false; } + + private void syncCadoodleCatagories(CSG dyingCSG) { + setIsHole(dyingCSG.isHole()); + setIsHide(dyingCSG.isHide()); + setIsAlwaysShow(dyingCSG.isAlwaysShow()); + setIsLock(dyingCSG.isLock()); + setIsMotionLock(dyingCSG.isMotionLock()); + setIsWireFrame(dyingCSG.isWireFrame()); + setColor(dyingCSG.getColor()); + setNoScale(dyingCSG.isNoScale()); + } // Hole public CSG setLimbName(String name) { getStorage().set("LimbName", name); From 4a7e829063f51707ede86b9042e41e59ac7a5413 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Mon, 6 Oct 2025 20:03:07 -0400 Subject: [PATCH 16/24] ensure all of the text extrude is set to not be a hole --- src/main/java/eu/mihosoft/vrl/v3d/TextExtrude.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/TextExtrude.java b/src/main/java/eu/mihosoft/vrl/v3d/TextExtrude.java index 311abf44..bbddc45e 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/TextExtrude.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/TextExtrude.java @@ -168,12 +168,12 @@ private TextExtrude(String text, Font font, double dir) { // subtract.getElements().forEach(this::getPoints); for (int i = 0; i < sections.size(); i++) { + sections.get(i).setIsHole(false); for (CSG h : holes) { try { if (sections.get(i).isBoundsTouching(h)) { // println "Hole found " - CSG nl = sections.get(i).difference(h); - + CSG nl = sections.get(i).difference(h).setIsHole(false); sections.set(i, nl); } } catch (Exception e) { From 4d94fcf4c6504bfe9610eeb3949b18ca3b3ea78a Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Mon, 6 Oct 2025 21:32:10 -0400 Subject: [PATCH 17/24] be careful how and when to save --- .../v3d/parametrics/CSGDatabaseInstance.java | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java index 35d23636..d497b78f 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java @@ -113,13 +113,13 @@ public CSGDatabaseInstance(File db) { try { dbFile.createNewFile(); saveDatabase(); - } catch (IOException e) { + } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } - }else { - getDatabase(); } + getDatabase(); + } public void set(String key, Parameter value) { @@ -139,15 +139,15 @@ public Parameter get(String key) { return ret; } - public void clear() { - - getDatabase(); - // synchronized(database){ - database.clear(); - // } - parameterListeners.clear(); - saveDatabase(); - } +// public void clear() { +// +// getDatabase(); +// // synchronized(database){ +// database.clear(); +// // } +// parameterListeners.clear(); +// saveDatabase(); +// } public void addParameterListener(String key, IParameterChanged l) { CopyOnWriteArrayList list = getParamListeners(key); @@ -224,15 +224,19 @@ private ConcurrentHashMap getDatabase() { } } } catch (Exception e) { - // e.printStackTrace(); - // System.err.println("Failed to load " + dbFile.getAbsolutePath()); + e.printStackTrace(); + System.err.println("Failed to load " + dbFile.getAbsolutePath()); setDatabase(new ConcurrentHashMap()); - saveDatabase(); } Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { - saveDatabase(); + try { + saveDatabase(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } }); @@ -276,7 +280,10 @@ public String getDataBaseString() { return writeOut; } - public void saveDatabase() { + public void saveDatabase() throws Exception { + if(database.size()==0) { + throw new Exception("Can not save an empty database! to "+getDbFile().getAbsolutePath()); + } String writeOut = getDataBaseString(); try { if (!getDbFile().exists()) { From bf5d7c5ecab6a4c1fbfa119e2d9c5c055b460936 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Wed, 8 Oct 2025 17:50:53 -0400 Subject: [PATCH 18/24] make properties concurency safe --- src/main/java/eu/mihosoft/vrl/v3d/PropertyStorage.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/PropertyStorage.java b/src/main/java/eu/mihosoft/vrl/v3d/PropertyStorage.java index e7e1801b..0467316e 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/PropertyStorage.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/PropertyStorage.java @@ -40,6 +40,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import javafx.scene.paint.Color; @@ -50,8 +51,10 @@ */ public class PropertyStorage implements Serializable{ - /** The map. */ - private final Map map = new HashMap<>(); + private static final long serialVersionUID = 1460815261025940141L; + + /** The map. */ + private final ConcurrentHashMap map = new ConcurrentHashMap<>(); /** The Constant colors. */ private static final Color[] colors = { From e79d98b26fb26e2de7a6f92d50d615e65889064e Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Wed, 8 Oct 2025 17:51:40 -0400 Subject: [PATCH 19/24] move the color set and add a print to motion lock set --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index 3b475845..4dac83f3 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -2957,6 +2957,8 @@ public CSG historySync(CSG dyingCSG) { } if (getName().length() == 0) setName(dyingCSG.getName()); + setColor(dyingCSG.getColor()); + //str.syncProperties(dyingCSG.str); syncCadoodleCatagories(dyingCSG); return this; } @@ -3658,6 +3660,9 @@ public boolean isGroupResult() { // Hole public CSG setIsMotionLock(boolean Lock) { + if(Lock) { + new RuntimeException("Motion Lock Enabled here").printStackTrace(); + } getStorage().set("isMotionLock", Lock); return this; } @@ -3741,6 +3746,15 @@ private void syncCadoodleCatagories(CSG dyingCSG) { setColor(dyingCSG.getColor()); setNoScale(dyingCSG.isNoScale()); } + public void setDefaultCadoodleCatagories() { + setIsHole(false); + setIsHide(false); + setIsAlwaysShow(false); + setIsLock(false); + setIsMotionLock(false); + setIsWireFrame(false); + setNoScale(false); + } // Hole public CSG setLimbName(String name) { getStorage().set("LimbName", name); From 50d87c14e9b9cd2201c37b10bf85964365adc2e2 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Wed, 8 Oct 2025 19:19:19 -0400 Subject: [PATCH 20/24] Use a temp file for the CSGDatabase when in default mode --- .../mihosoft/vrl/v3d/parametrics/CSGDatabase.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java index b720e3d8..aed4971f 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabase.java @@ -1,6 +1,8 @@ package eu.mihosoft.vrl.v3d.parametrics; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.util.HashMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -8,8 +10,7 @@ import eu.mihosoft.vrl.v3d.CSG; public class CSGDatabase { - private static CSGDatabaseInstance instance = new CSGDatabaseInstance(new File("CSGdatabase.json")); - + private static CSGDatabaseInstance instance ; // public static void set(String key, Parameter value) { // getInstance().set(key, value); // } @@ -65,6 +66,14 @@ public class CSGDatabase { public static CSGDatabaseInstance getInstance() { new Exception("Depricated database access!").printStackTrace(); + if(instance==null) { + try { + instance = new CSGDatabaseInstance( Files.createTempFile("CSGDatabase", ".json").toFile()); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } return instance; } public static void setInstance(CSGDatabaseInstance instance) { From b491054c75f341fadceaf0d59f3bdb276341c5de Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Wed, 8 Oct 2025 19:19:47 -0400 Subject: [PATCH 21/24] remove save database when it it empty --- .../eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java index d497b78f..17be35fb 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java @@ -220,7 +220,6 @@ private ConcurrentHashMap getDatabase() { setDatabase(tm); } else { setDatabase(new ConcurrentHashMap()); - saveDatabase(); } } } catch (Exception e) { From c49e17847c87b596d6c3aa838925ba590ebe6ef9 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Wed, 8 Oct 2025 19:37:08 -0400 Subject: [PATCH 22/24] just print exception and return early --- .../eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java index 17be35fb..526da27d 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/parametrics/CSGDatabaseInstance.java @@ -281,7 +281,8 @@ public String getDataBaseString() { public void saveDatabase() throws Exception { if(database.size()==0) { - throw new Exception("Can not save an empty database! to "+getDbFile().getAbsolutePath()); + new Exception("Can not save an empty database! to "+getDbFile().getAbsolutePath()).printStackTrace();; + return; } String writeOut = getDataBaseString(); try { From da55c5d63e7663e8104ff061b1cf97d25e388429 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Wed, 8 Oct 2025 20:51:03 -0400 Subject: [PATCH 23/24] refactor touching to use bounds, faster --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index 4dac83f3..3a78fd4a 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -3161,9 +3161,7 @@ public CSG markForRegeneration() { public boolean touching(CSG incoming) { // Fast bounding box overlap check, quick fail if not intersecting // bounding boxes - if (this.getMaxX() > incoming.getMinX() && this.getMinX() < incoming.getMaxX() - && this.getMaxY() > incoming.getMinY() && this.getMinY() < incoming.getMaxY() - && this.getMaxZ() > incoming.getMinZ() && this.getMinZ() < incoming.getMaxZ()) { + if (isBoundsTouching(incoming)) { // Run a full intersection CSG inter = this.intersect(incoming); if (inter.getPolygons().size() > 0) { From 7d28ab20c12b936b32e527d32017b22bdd955c87 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Sat, 11 Oct 2025 07:15:45 -0400 Subject: [PATCH 24/24] remove the exception from lock --- src/main/java/eu/mihosoft/vrl/v3d/CSG.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java index 3a78fd4a..a539e709 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/CSG.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/CSG.java @@ -3658,9 +3658,9 @@ public boolean isGroupResult() { // Hole public CSG setIsMotionLock(boolean Lock) { - if(Lock) { - new RuntimeException("Motion Lock Enabled here").printStackTrace(); - } +// if(Lock) { +// new RuntimeException("Motion Lock Enabled here").printStackTrace(); +// } getStorage().set("isMotionLock", Lock); return this; }