1 package com.neuronrobotics.bowlerstudio.vitamins;
3 import java.io.BufferedWriter;
5 import java.io.FileWriter;
6 import java.io.IOException;
7 import java.lang.reflect.Type;
8 import java.nio.file.Files;
9 import java.util.ArrayList;
10 import java.util.HashMap;
13 import org.apache.commons.io.FileUtils;
14 import org.eclipse.jgit.api.errors.GitAPIException;
15 import org.eclipse.jgit.api.errors.InvalidRemoteException;
16 import org.eclipse.jgit.api.errors.TransportException;
18 import com.google.gson.Gson;
19 import com.google.gson.GsonBuilder;
20 import com.google.gson.reflect.TypeToken;
21 import com.neuronrobotics.bowlerstudio.physics.TransformFactory;
22 import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
23 import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
24 import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR;
26 import eu.mihosoft.vrl.v3d.CSG;
27 import javafx.scene.paint.Color;
33 private static boolean saving =
false;
42 Type type =
new TypeToken<HashMap<String, ArrayList<VitaminElement>>>() {
44 Gson gson =
new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
45 private HashMap<String, ArrayList<VitaminElement>>
database =
null;
53 if (!bom.getParentFile().exists()) {
54 bom.getParentFile().mkdir();
58 }
catch (IOException e) {
67 bytes = Files.readAllBytes(bom.toPath());
68 source =
new String(bytes,
"UTF-8");
69 database = gson.fromJson(source, type);
70 }
catch (Exception ex) {
75 database=
new HashMap<String, ArrayList<VitaminElement>>();
79 public void set(String name, String type, String size,
TransformNR location) {
81 boolean toAdd =
false;
82 if (newElement ==
null) {
84 newElement.name = name;
87 newElement.pose = location;
88 newElement.size = size;
89 newElement.type = type;
90 String key = type +
":" + size;
93 database.put(key,
new ArrayList<VitaminBomManager.VitaminElement>());
102 public CSG get(String name) {
105 throw new RuntimeException(
"Vitamin must be defined before it is used: " + name);
115 }
catch (Exception e1) {
117 e1.printStackTrace();
139 throw new RuntimeException(
"Vitamin must be defined before it is used: " + name);
146 for (String testName :
database.keySet()) {
147 ArrayList<VitaminElement> list =
database.get(testName);
149 if (el.name.contentEquals(name))
165 String csv =
"name,qty,source\n";
166 String content =
null;
171 for (String key :
database.keySet()) {
172 ArrayList<VitaminElement> list =
database.get(key);
173 if (list.size() > 0) {
175 String size =
database.get(key).size() +
"";
177 csv += key +
"," + size +
"," + URL +
"\n";
179 System.out.println(
"Failure on " + key);
186 if (current.contentEquals(csv) && currentJ.contentEquals(content)) {
191 }
catch (Exception e1) {
193 e1.printStackTrace();
202 }
catch (Exception e) {
210 private void write(String file, String content)
211 throws InvalidRemoteException, TransportException, GitAPIException, IOException {
213 if (!f.getParentFile().exists())
214 f.getParentFile().mkdir();
218 BufferedWriter writer =
new BufferedWriter(
new FileWriter(f.getAbsolutePath()));
219 writer.write(content);
static String[] codeFromGit(String id, String FileName)
static File fileFromGit(String remoteURI, String fileInRepo)
static File getRepositoryCloneDirectory(String remoteURI)
static final String MANUFACTURING_BOM_JSON
Map< String, Object > getConfiguration(String name)
TransformNR getCoMLocation(String name)
double getMassKg(String name)
static final String MANUFACTURING_BOM_BASE
void write(String file, String content)
HashMap< String, ArrayList< VitaminElement > > database
VitaminElement getElement(String name)
static final String MANUFACTURING_BOM_CSV
VitaminBomManager(String url)
static Map< String, Object > getConfiguration(String type, String id)
static CSG get(File resource)
CSG transformed(Transform transform)
CSG setManufacturing(PrepForManufacturing manufactuing)
CSG setColor(Color color)