Skip to content

Commit

Permalink
recoursivly apply the allign move but only calculate the move by the
Browse files Browse the repository at this point in the history
visable objectes
  • Loading branch information
madhephaestus committed Dec 23, 2024
1 parent 817c286 commit f9a7073
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public static Object process(CaDoodleFile loaded) {
ArrayList<CSG> back = new ArrayList<CSG>();
back.addAll(incoming);
for(CSG c: incoming) {
if(c.isInGroup()) {
back.remove(c);
}
if(c.isHide()) {
if(c.isInGroup() || c.isHide()) {
back.remove(c);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.neuronrobotics.bowlerstudio.scripting.cadoodle;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.google.gson.annotations.Expose;
Expand All @@ -9,6 +10,7 @@

import eu.mihosoft.vrl.v3d.Bounds;
import eu.mihosoft.vrl.v3d.CSG;
import eu.mihosoft.vrl.v3d.Transform;

public class Allign implements ICaDoodleOpperation {
@Expose (serialize = true, deserialize = true)
Expand Down Expand Up @@ -40,77 +42,62 @@ public String toString(){

@Override
public List<CSG> process(List<CSG> incoming) {
ArrayList<CSG> toMove = new ArrayList<CSG>();
ArrayList<CSG> back = new ArrayList<CSG>();
back.addAll(incoming);
CSG reference=null;
CSG refProps =null;
for(CSG c: incoming) {
if(c.isLock())
continue;
String name = names.get(0);
if(name.contentEquals(c.getName())) {
back.remove(c);
refProps=c;
reference=c.transformed(TransformFactory.nrToCSG(getWorkplane()).inverse());
}
}
for(String name:names)
collectToMove(toMove, back, name);

Bounds bounds2 ;//
if(bounds!=null) {
bounds2=bounds.getBounds();
toMove.add(refProps);
}else {
CSG transformed = reference.transformed(TransformFactory.nrToCSG(getWorkplane()));
back.add(sync(refProps,transformed));
bounds2 = reference.getBounds();
throw new RuntimeException("Allign can not be initialized without bounds!");
}
for(CSG tmp:toMove) {
CSG c = tmp.transformed(TransformFactory.nrToCSG(getWorkplane()).inverse());
c = performTransform(bounds2, c);
back.add(sync(tmp,c.transformed(TransformFactory.nrToCSG(getWorkplane()))));
HashMap<String,TransformNR> moves= new HashMap<>();
for(String name :names) {
for(CSG tmp:back) {
if(!tmp.getName().contentEquals(name))
continue;
CSG c = tmp.transformed(TransformFactory.nrToCSG(getWorkplane()).inverse());
TransformNR tf = performTransform(bounds2, c);
moves.put(c.getName(),tf);
}
}
for(String name:moves.keySet()) {
Transform tf = TransformFactory.nrToCSG(moves.get(name));
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()))));
return b;
}, 1);
}
return back;
}

private void collectToMove(ArrayList<CSG> toMove, ArrayList<CSG> back, String name) {
ArrayList<CSG> toSearch = new ArrayList<CSG>();
toSearch.addAll(back);
for (int i = 0; i < toSearch.size(); i++) {
CSG c = toSearch.get(i);
if(name.contentEquals(c.getName())) {
back.remove(c);
toMove.add(c);
if(c.isGroupResult()) {
for(int j=0;j<back.size();j++) {
CSG mem = back.get(j);
if(mem.isInGroup() && mem.checkGroupMembership(name)) {
String newObjName = mem.getName();
collectToMove(toMove, back, newObjName);
}
}
}
}
}
}
// private void collectToMove(ArrayList<CSG> toMove, ArrayList<CSG> back, String name) {
// ArrayList<CSG> toSearch = new ArrayList<CSG>();
// toSearch.addAll(back);
// for (int i = 0; i < toSearch.size(); i++) {
// CSG c = toSearch.get(i);
// if(name.contentEquals(c.getName())) {
// toMove.add(c);
// }
// }
// }

private CSG performTransform(Bounds reference, CSG incoming) {
CSG c = incoming;
private TransformNR performTransform(Bounds reference, CSG incoming) {
//CSG c = incoming;
double tx=0,ty=0,tz=0;
if(z!=null) {
switch(z) {
case negative:
c=( c.toZMin()
.movez(reference.getMinZ())
);
tz=-incoming.getMinZ()+reference.getMinZ();
break;
case middle:
c=( c.moveToCenterZ()
.movez(reference.getCenterZ()));
tz=-incoming.getCenterZ()+reference.getCenterZ();
break;
case positive:
c=( c.toZMax()
.movez(reference.getMaxZ()));
tz=-incoming.getMaxZ()+reference.getMaxZ();
break;
default:
break;
Expand All @@ -119,16 +106,13 @@ private CSG performTransform(Bounds reference, CSG incoming) {
if(x!=null) {
switch(x) {
case negative:
c=( c.toXMin()
.movex(reference.getMinX()));
tx=-incoming.getMinX()+reference.getMinX();
break;
case middle:
c=( c.moveToCenterX()
.movex(reference.getCenterX()));
tx=-incoming.getCenterX()+reference.getCenterX();
break;
case positive:
c=( c.toXMax()
.movex(reference.getMaxX()));
tx=-incoming.getMaxX()+reference.getMaxX();
break;
default:
break;
Expand All @@ -137,24 +121,21 @@ private CSG performTransform(Bounds reference, CSG incoming) {
}
if(y!=null) {
switch(y) {
case negative:
ty=-incoming.getMinY()+reference.getMinY();
break;
case middle:
c=( c.moveToCenterY()
.movey(reference.getCenterY()));
ty=-incoming.getCenterY()+reference.getCenterY();
break;
case positive:
c=( c.toYMax()
.movey(reference.getMaxY()));
break;
case negative:
c= c.toYMin()
.movey(reference.getMinY());
ty=-incoming.getMaxY()+reference.getMaxY();
break;
default:
break;

}
}
return sync(incoming, c);
return new TransformNR(tx,ty,tz);
}

private CSG sync(CSG incoming, CSG c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,21 @@ public Thread addOpperation(ICaDoodleOpperation o) throws CadoodleConcurrencyExc
opperationRunner.start();
return opperationRunner;
}
public static CSG getByName(ArrayList<CSG> back, String name) {
for (CSG c : back) {
if (c.getName().contentEquals(name))
return c;
}
throw new RuntimeException("Fail! there was no object named " + name);
}

public static int applyToAllConstituantElements(boolean addRet, List<String> targetNames, ArrayList<CSG> back,
ICadoodleRecursiveEvent p, int depth) {
for (int i = 0; i < targetNames.size(); i++) {
String s = targetNames.get(i);
CSG c=getByName(back, s);
if(c.isInGroup())
continue;
applyToAllConstituantElements(addRet, s, back, p,depth);
}
return back.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public ArrayList<CSG> process(CSG ic, int depth) {
},1);

for (String from : cpMap.keySet()) {
CSG source = getByName(back, from);
CSG source = CaDoodleFile.getByName(back, from);
if (source.isGroupResult()) {
ArrayList<String> c = constituants(back, from);
if(c.size()<2)
throw new RuntimeException("A group result must have at least 2 constituants!");
String newGroupName = getByName(back, cpMap.get(from)).getName();
String newGroupName = CaDoodleFile.getByName(back, cpMap.get(from)).getName();
for (String s : c) {
CSG dest = getByName(back, s);
CSG dest = CaDoodleFile.getByName(back, s);
dest.removeGroupMembership(from);
dest.addGroupMembership(newGroupName);
}
Expand All @@ -69,9 +69,9 @@ public ArrayList<CSG> process(CSG ic, int depth) {
private ArrayList<String> constituants(ArrayList<CSG> b, String name) {
ArrayList<String> c = new ArrayList<String>();
for (String ky:cpMap.keySet()) {
CSG byName = getByName(b,ky);
CSG byName = CaDoodleFile.getByName(b,ky);
String name2 = cpMap.get(ky);
CSG byName2 = getByName(b,name2);
CSG byName2 = CaDoodleFile.getByName(b,name2);
for(CSG csg:Arrays.asList(byName,byName2)){
if (csg.checkGroupMembership(name)) {
// only add objects that were created by this operation
Expand All @@ -83,13 +83,7 @@ private ArrayList<String> constituants(ArrayList<CSG> b, String name) {
return c;
}

private CSG getByName(ArrayList<CSG> back, String name) {
for (CSG c : back) {
if (c.getName().contentEquals(name))
return c;
}
throw new RuntimeException("Fail! there was no object named " + name);
}


private ArrayList<CSG> copyPasteMoved(ArrayList<CSG> back, CSG c, int depth) {
String prevName = c.getName();
Expand All @@ -106,7 +100,8 @@ private ArrayList<CSG> copyPasteMoved(ArrayList<CSG> back, CSG c, int depth) {
newOne.setRegenerate(c.getRegenerate()).setName(name);
index++;
newOne.syncProperties(c).setName(name);
getNamesAdded().add(name);
if(!c.isInGroup())
getNamesAdded().add(name);
ArrayList<CSG> b = new ArrayList<>();
b.add(c);
b.add(newOne);
Expand Down

0 comments on commit f9a7073

Please sign in to comment.