Skip to content

Commit

Permalink
Adding a cadoodle vitamins manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Harrington committed Dec 7, 2024
1 parent dcdb98c commit e153304
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.neuronrobotics.bowlerstudio.scripting.cadoodle;

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

import com.neuronrobotics.bowlerstudio.vitamins.Vitamins;
import com.neuronrobotics.sdk.addons.kinematics.VitaminLocation;
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;

import eu.mihosoft.vrl.v3d.CSG;
import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase;
import eu.mihosoft.vrl.v3d.parametrics.IRegenerate;
import eu.mihosoft.vrl.v3d.parametrics.StringParameter;

public class CaDoodleVitamin {
public static CSG get(String type, ArrayList<Object> args) {
ArrayList<String> listVitaminSizes = Vitamins.listVitaminSizes(type);
String name = args.get(0).toString();
StringParameter size = new StringParameter(type + " Default", listVitaminSizes.get(0), listVitaminSizes);
if (size.getStrValue().length() == 0)
size.setStrValue(listVitaminSizes.get(0));
StringParameter word = new StringParameter(name + "_CaDoodle_Vitamin_Size", size.getStrValue(),
listVitaminSizes);
size.setStrValue(word.getStrValue());
if (args.size() > 1) {
HashMap<String, Object> object = (HashMap<String, Object>) args.get(1);
if (!(Boolean) object.get("PreventBomAdd")) {
VitaminLocation vl = new VitaminLocation(false, name, type, word.getStrValue(), new TransformNR());
CaDoodleFile.getBoM().addVitamin(vl, true);
}
}
CSG part;
try {
part = Vitamins.get(type, word.getStrValue()).setIsHole(true);
CSGDatabase.saveDatabase();
return part.setParameter(word).setRegenerate(new IRegenerate() {
@Override
public CSG regenerate(CSG previous) {
ArrayList<Object> ar = new ArrayList<>();
ar.addAll(args);
ar.set(0, previous.getName());
return CaDoodleVitamin.get(type, ar);
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
throw new RuntimeException("Failed to load vitamin of type " + type);
}
}

0 comments on commit e153304

Please sign in to comment.