diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Allign.java b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Allign.java index 947a228f..dc54b32d 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Allign.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Allign.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import com.google.gson.annotations.Expose; @@ -25,7 +26,18 @@ public class Allign implements ICaDoodleOpperation { private TransformNR workplane=null; @Expose (serialize = true, deserialize = true) public StoragbeBounds bounds=null; - + @Expose(serialize = true, deserialize = true) + protected String name = null; + public String getName() { + if (name == null) { + setName(RandomStringFactory.generateRandomString()); + } + return name; + } + + public void setName(String name) { + this.name = name; + } @Override public String getType() { return "Allign"; @@ -62,12 +74,18 @@ public List process(List incoming) { } } for(String name:moves.keySet()) { - Transform tf = TransformFactory.nrToCSG(moves.get(name)); + TransformNR wpinv = getWorkplane().inverse(); + TransformNR nr = moves.get(name); + TransformNR wp = getWorkplane(); + + TransformNR times = wp.times(nr.times(wpinv)); + Transform tf = TransformFactory.nrToCSG(times); CaDoodleFile.applyToAllConstituantElements(false, name, back, (incoming1, depth) ->{ ArrayList b = new ArrayList<>(); - CSG c = incoming1.transformed(TransformFactory.nrToCSG(getWorkplane()).inverse()); - c=c.transformed(tf); - b.add(sync(incoming1,c.transformed(TransformFactory.nrToCSG(getWorkplane())))); + CSG c=incoming1.transformed(tf); + sync(incoming1,c); + MoveCenter.set(getName() , c, times); + b.add(c); return b; }, 1); } diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/CaDoodleVitamin.java b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/CaDoodleVitamin.java index fa278f5f..ddaaf33d 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/CaDoodleVitamin.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/CaDoodleVitamin.java @@ -76,7 +76,7 @@ public static CSG get(String typencoming,String defaultValue, ArrayList } CSG part; try { - System.out.println("Generating Vitamin "+type+" "+word.getStrValue()+" for vitamin named "+name); +// System.out.println("Generating Vitamin "+type+" "+word.getStrValue()+" for vitamin named "+name); part = Vitamins.get(type, word.getStrValue()).setIsHole(true); CSGDatabase.saveDatabase(); Set params = part.getParameters(); @@ -84,11 +84,11 @@ public static CSG get(String typencoming,String defaultValue, ArrayList part.setParameter(word); part.setParameter(typeParam); params = part.getParameters(); - - System.out.println("Parameters on Vitamin: "+name); - for(String s:params) { - System.out.println("\t"+s); - } + part.setName(name); +// System.out.println("Parameters on Vitamin: "+name); +// for(String s:params) { +// System.out.println("\t"+s); +// } CSG back = part.setRegenerate(new IRegenerate() { @Override public CSG regenerate(CSG previous) { @@ -98,7 +98,7 @@ public CSG regenerate(CSG previous) { name2=pv.get().toString(); else name2=name; - System.out.println("Regenerating source \n\t"+name+" on part \n\t"+name2); + //System.out.println("Regenerating source \n\t"+name+" on part \n\t"+name2); ArrayList ar = new ArrayList<>(); ar.addAll(args); ar.set(0, previous.getName()); diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Paste.java b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Paste.java index 3a2e58ec..6e9cdf35 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Paste.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Paste.java @@ -8,6 +8,7 @@ import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import com.google.gson.annotations.Expose; @@ -18,6 +19,8 @@ import eu.mihosoft.vrl.v3d.CSG; import eu.mihosoft.vrl.v3d.Transform; +import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; +import eu.mihosoft.vrl.v3d.parametrics.Parameter; public class Paste extends AbstractAddFrom implements ICaDoodleOpperation { @Expose(serialize = true, deserialize = true) @@ -87,25 +90,27 @@ private ArrayList constituants(ArrayList b, String name) { private ArrayList copyPasteMoved(ArrayList back, CSG c, int depth) { String prevName = c.getName(); - String name = getName() +(index == 0 ? "" : "_" + index); + String name = getName() +( index == 0 ? "" : "_" + index); CSG clone = c.clone(); clone.setRegenerate(c.getRegenerate()).setName(name); clone.getStorage().set("PreviousName", prevName); Transform nrToCSG = MoveCenter.getTotalOffset(c); CSG newOne = null; - if (CaDoodleVitamin.isVitamin(c)) - newOne = clone.regenerate().transformed(nrToCSG); - else + if (CaDoodleVitamin.isVitamin(c)) { + CSG regenerate = clone.getRegenerate().regenerate(clone); + newOne = regenerate.transformed(nrToCSG); + newOne.setRegenerate(regenerate.getRegenerate()); + }else { newOne = clone; - newOne.setRegenerate(c.getRegenerate()).setName(name); - index++; + newOne.setRegenerate(c.getRegenerate()); + } newOne.syncProperties(c).setName(name); - if(!c.isInGroup()) - getNamesAdded().add(name); + index++; + getNamesAdded().add(name); ArrayList b = new ArrayList<>(); b.add(c); b.add(newOne); - System.out.println("Copy "+c.getName()+" to "+newOne.getName()); + //System.out.println("Copy "+c.getName()+" to "+newOne.getName()); cpMap.put(c.getName(), newOne.getName()); return b; } diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/UnGroup.java b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/UnGroup.java index d208940e..92774521 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/UnGroup.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/UnGroup.java @@ -34,11 +34,11 @@ public List process(List incoming) { if (csg.checkGroupMembership(name)) { // release this object from the group Transform nrToCSG = MoveCenter.getTotalOffset(csg); - CSG transformed=null; - if(CaDoodleVitamin.isVitamin(csg)) - transformed= csg.regenerate().transformed(nrToCSG); - else - transformed=csg; + CSG transformed=csg; + if(CaDoodleVitamin.isVitamin(csg)) { + CSG regenerate = csg.getRegenerate().regenerate(csg); + transformed = regenerate.transformed(nrToCSG); + } CSG readd= transformed.setRegenerate(csg.getRegenerate()).syncProperties(csg).setName(csg.getName()); readd.removeGroupMembership(name);