Skip to content

Commit d5f7b95

Browse files
committed
Add a filter on the move operation that rejects origin transforms
1 parent ad7353c commit d5f7b95

2 files changed

Lines changed: 48 additions & 20 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.neuronrobotics.bowlerstudio.scripting.cadoodle;
2+
3+
public class InvalidLocationMove extends Exception {
4+
5+
}

src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/MoveCenter.java

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
import com.neuronrobotics.bowlerstudio.physics.TransformFactory;
1111
import com.neuronrobotics.bowlerstudio.vitamins.VitaminBomManager;
1212
import com.neuronrobotics.sdk.addons.kinematics.VitaminLocation;
13+
import com.neuronrobotics.sdk.addons.kinematics.math.RotationNR;
1314
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
1415

1516
import eu.mihosoft.vrl.v3d.CSG;
1617
import eu.mihosoft.vrl.v3d.PropertyStorage;
1718
import eu.mihosoft.vrl.v3d.Transform;
1819

19-
public class MoveCenter extends CaDoodleOperation{
20+
public class MoveCenter extends CaDoodleOperation {
2021
@Expose(serialize = true, deserialize = true)
2122
private TransformNR location = new TransformNR();
2223
@Expose(serialize = true, deserialize = true)
@@ -26,7 +27,7 @@ public class MoveCenter extends CaDoodleOperation{
2627

2728
public String getName() {
2829
if (name == null) {
29-
name=(RandomStringFactory.generateRandomString());
30+
name = (RandomStringFactory.generateRandomString());
3031
}
3132
return name;
3233
}
@@ -35,9 +36,11 @@ public String getName() {
3536
public String getType() {
3637
return "Move Center";
3738
}
39+
3840
public static void set(String name, CSG c, TransformNR tf) {
39-
set(name,c,TransformFactory.nrToCSG(tf));
41+
set(name, c, TransformFactory.nrToCSG(tf));
4042
}
43+
4144
public static void set(String name, CSG c, Transform tf) {
4245
if (tf == null)
4346
throw new NullPointerException();
@@ -78,7 +81,8 @@ public static Transform getTotalOffset(CSG c) {
7881
Transform transTmp = new Transform().apply((Transform) storage.getValue(s).get());
7982
start = transTmp.apply(start);
8083
} catch (Exception ex) {
81-
com.neuronrobotics.sdk.common.Log.error(ex);;
84+
com.neuronrobotics.sdk.common.Log.error(ex);
85+
;
8286
}
8387
}
8488
nrToCSG = start;
@@ -94,47 +98,66 @@ public List<CSG> process(List<CSG> incoming) {
9498
CaDoodleFile.applyToAllConstituantElements(false, names, back, new ICadoodleRecursiveEvent() {
9599
@Override
96100
public ArrayList<CSG> process(CSG incoming, int depth) {
97-
101+
98102
Transform nrToCSG2 = TransformFactory.nrToCSG(location);
99-
if(incoming.isMotionLock()) {
100-
nrToCSG2=new Transform();
103+
if (incoming.isMotionLock()) {
104+
nrToCSG2 = new Transform();
101105
}
102106
CSG tmpToAdd = incoming.transformed(nrToCSG2)
103-
.syncProperties(getCaDoodleFile().getCsgDBinstance(),incoming)
104-
.setName(incoming.getName())
107+
.syncProperties(getCaDoodleFile().getCsgDBinstance(), incoming).setName(incoming.getName())
105108
.setID(incoming);
106109
ArrayList<CSG> b = new ArrayList<>();
107110
b.add(tmpToAdd);
108111
set(getName(), tmpToAdd, location);
109112
return b;
110113
}
111-
},1);
114+
}, 1);
112115

113116
return back;
114117
}
115118

119+
public boolean isWorkplaneNotOrigin(TransformNR w) {
120+
double epsilon = 0.00001;
121+
RotationNR r = w.getRotation();
122+
double abst = Math.abs(w.getX());
123+
double abs2t = Math.abs(w.getY());
124+
double abs3t = Math.abs(w.getZ());
125+
126+
if ((abst > epsilon) || (abs2t > epsilon) || (abs3t > epsilon))
127+
return true;
128+
129+
double abs = Math.abs(r.getRotationAzimuthDegrees());
130+
double abs2 = Math.abs(r.getRotationElevationDegrees());
131+
double abs3 = Math.abs(r.getRotationTiltDegrees());
132+
133+
return ((abs > epsilon) || (abs2 > epsilon) || (abs3 > epsilon));
134+
}
135+
116136
public TransformNR getLocation() {
117137
return location;
118138
}
119139

120-
public MoveCenter setLocation(TransformNR location) {
121-
this.location = location;
140+
public MoveCenter setLocation(TransformNR location) throws InvalidLocationMove {
141+
if (isWorkplaneNotOrigin(location))
142+
this.location = location;
143+
else
144+
throw new InvalidLocationMove();
122145
return this;
123146
}
124147

125148
public List<String> getNamesAddedInThisOperation() {
126149
return names;
127150
}
128151

129-
public MoveCenter setNames(List<String> names,CaDoodleFile f) {
130-
131-
for(String s:names) {
132-
boolean found=false;
133-
for(CSG c:f.getCurrentState()) {
134-
if(c.getName().contentEquals(s))
135-
found=true;
152+
public MoveCenter setNames(List<String> names, CaDoodleFile f) {
153+
154+
for (String s : names) {
155+
boolean found = false;
156+
for (CSG c : f.getCurrentState()) {
157+
if (c.getName().contentEquals(s))
158+
found = true;
136159
}
137-
if(!found)
160+
if (!found)
138161
throw new RuntimeException("Set a name that does not exist!!");
139162
}
140163
this.names = names;

0 commit comments

Comments
 (0)