Skip to content

Commit

Permalink
Fixing the regeneration problem with pasted items
Browse files Browse the repository at this point in the history
Boils down to making sure that all added objects are added to the
creaated names, but then are filtered out in the recoursive apply just
like the locked items. THis allows the parameterics to be added to the
new items, but also prevents then additional items from being selected
in the selection box.
  • Loading branch information
madhephaestus committed Dec 24, 2024
1 parent f9a7073 commit e148652
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -62,12 +74,18 @@ public List<CSG> process(List<CSG> 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<CSG> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ public static CSG get(String typencoming,String defaultValue, ArrayList<Object>
}
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<String> params = part.getParameters();

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) {
Expand All @@ -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<Object> ar = new ArrayList<>();
ar.addAll(args);
ar.set(0, previous.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -87,25 +90,27 @@ private ArrayList<String> constituants(ArrayList<CSG> b, String name) {

private ArrayList<CSG> copyPasteMoved(ArrayList<CSG> 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<CSG> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public List<CSG> process(List<CSG> 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);
Expand Down

0 comments on commit e148652

Please sign in to comment.