|
| 1 | +package com.neuronrobotics.bowlerstudio.scripting.cadoodle; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.HashMap; |
| 5 | + |
| 6 | +import com.neuronrobotics.bowlerstudio.vitamins.Vitamins; |
| 7 | +import com.neuronrobotics.sdk.addons.kinematics.VitaminLocation; |
| 8 | +import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR; |
| 9 | + |
| 10 | +import eu.mihosoft.vrl.v3d.CSG; |
| 11 | +import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; |
| 12 | +import eu.mihosoft.vrl.v3d.parametrics.IRegenerate; |
| 13 | +import eu.mihosoft.vrl.v3d.parametrics.StringParameter; |
| 14 | + |
| 15 | +public class CaDoodleVitamin { |
| 16 | + public static CSG get(String type, ArrayList<Object> args) { |
| 17 | + ArrayList<String> listVitaminSizes = Vitamins.listVitaminSizes(type); |
| 18 | + String name = args.get(0).toString(); |
| 19 | + StringParameter size = new StringParameter(type + " Default", listVitaminSizes.get(0), listVitaminSizes); |
| 20 | + if (size.getStrValue().length() == 0) |
| 21 | + size.setStrValue(listVitaminSizes.get(0)); |
| 22 | + StringParameter word = new StringParameter(name + "_CaDoodle_Vitamin_Size", size.getStrValue(), |
| 23 | + listVitaminSizes); |
| 24 | + size.setStrValue(word.getStrValue()); |
| 25 | + if (args.size() > 1) { |
| 26 | + HashMap<String, Object> object = (HashMap<String, Object>) args.get(1); |
| 27 | + if (!(Boolean) object.get("PreventBomAdd")) { |
| 28 | + VitaminLocation vl = new VitaminLocation(false, name, type, word.getStrValue(), new TransformNR()); |
| 29 | + CaDoodleFile.getBoM().addVitamin(vl, true); |
| 30 | + } |
| 31 | + } |
| 32 | + CSG part; |
| 33 | + try { |
| 34 | + part = Vitamins.get(type, word.getStrValue()).setIsHole(true); |
| 35 | + CSGDatabase.saveDatabase(); |
| 36 | + return part.setParameter(word).setRegenerate(new IRegenerate() { |
| 37 | + @Override |
| 38 | + public CSG regenerate(CSG previous) { |
| 39 | + ArrayList<Object> ar = new ArrayList<>(); |
| 40 | + ar.addAll(args); |
| 41 | + ar.set(0, previous.getName()); |
| 42 | + return CaDoodleVitamin.get(type, ar); |
| 43 | + } |
| 44 | + }); |
| 45 | + } catch (Exception e) { |
| 46 | + // TODO Auto-generated catch block |
| 47 | + e.printStackTrace(); |
| 48 | + } |
| 49 | + throw new RuntimeException("Failed to load vitamin of type " + type); |
| 50 | + } |
| 51 | +} |
0 commit comments