1 package com.neuronrobotics.bowlerstudio.creature;
4 import java.io.IOException;
5 import java.nio.file.Paths;
6 import java.util.ArrayList;
7 import java.util.Collection;
10 import org.apache.commons.io.FilenameUtils;
12 import eu.mihosoft.vrl.v3d.CSG;
13 import eu.mihosoft.vrl.v3d.FileUtil;
14 import eu.mihosoft.vrl.v3d.JavaFXInitializer;
15 import eu.mihosoft.vrl.v3d.Transform;
16 import eu.mihosoft.vrl.v3d.svg.SVGExporter;
17 import javafx.scene.transform.Affine;
29 public void setSelectedCsg(Collection<CSG> selectedCsg) {
35 public void setAllCSG(Collection<CSG> toAdd, File source) {
41 public void highlightException(File fileEngineRunByName, Throwable ex) {
47 public Set<CSG> getVisibleCSGs() {
53 public void addCSG(Collection<CSG> toAdd, File source) {
59 public void setSelected(Affine rootListener) {
66 ArrayList<File> allCadStl =
new ArrayList<>();
67 if(!baseDirForFiles.isDirectory()){
68 String fileNameWithOutExt = FilenameUtils.removeExtension(baseDirForFiles.getAbsolutePath());
69 baseDirForFiles =
new File(fileNameWithOutExt);
70 if (!baseDirForFiles.exists())
71 baseDirForFiles.mkdirs();
74 if(!baseDirForFiles.getName().contentEquals(
"manufacturing")){
75 dir =
new File(baseDirForFiles.getAbsolutePath() +
"/manufacturing/");
82 ArrayList<CSG> svgParts =
new ArrayList<>();
85 for(
CSG part: totalAssembly){
86 String name = part.getName();
88 if( manufactured==
null){
91 manufactured.
setName(part.getName());
93 name=
"Part-Num-"+index;
94 nameBase = dir.getAbsolutePath()+
"/"+name;
96 if(part.getExportFormats()==
null){
98 allCadStl.add(
makeStl(nameBase,manufactured));
100 System.err.println(
"Failed to generate "+part.getName());
105 for(String format:part.getExportFormats()){
106 if(format.toLowerCase().contains(
"obj")){
107 allCadStl.add(
makeObj(nameBase,manufactured));
108 ui.
setCsg(manufactured ,
null);
110 if(format.toLowerCase().contains(
"stl")){
111 allCadStl.add(
makeStl(nameBase,manufactured));
112 ui.
setCsg(manufactured ,
null);
114 if(format.toLowerCase().contains(
"svg")){
116 svgName =part.toString();
118 svgParts.add(manufactured);
125 if(svgParts.size()>0){
126 allCadStl.add(
makeSvg(nameBase,svgParts));
131 private File
makeStl(String nameBase,
CSG tmp )
throws IOException{
132 File stl =
new File(nameBase +
".stl");
134 FileUtil.
write(Paths.get(stl.getAbsolutePath()), tmp.toStlString());
135 System.out.println(
"Writing "+stl.getAbsolutePath());
138 private File
makeObj(String nameBase,
CSG tmp )
throws IOException{
139 File stl =
new File(nameBase +
".obj");
141 FileUtil.
write(Paths.get(stl.getAbsolutePath()), tmp.toObjString());
142 System.out.println(
"Writing "+stl.getAbsolutePath());
146 private File
makeSvg(String nameBase, List<CSG> currentCsg)
throws IOException {
147 File stl =
new File(nameBase +
".svg");
150 for (
CSG csg : currentCsg) {
151 if (csg.getSlicePlanes() ==
null) {
158 }
catch (Exception e) {
159 ArrayList<CSG> movedDown =
new ArrayList<>();
160 for (
CSG csg : currentCsg) {
165 movedDown.add(movez);
171 System.out.println(
"Writing " + stl.getAbsolutePath());
172 }
catch (Throwable t) {
173 System.err.println(
"ERROR, NO pixelization engine availible for slicing");
File makeStl(String nameBase, CSG tmp)
File makeObj(String nameBase, CSG tmp)
CadFileExporter(IMobileBaseUI myUI)
File makeSvg(String nameBase, List< CSG > currentCsg)
ArrayList< File > generateManufacturingParts(List< CSG > totalAssembly, File baseDirForFiles)
CSG movez(Number howFarToMove)
void addSlicePlane(Transform slicePlane)
CSG prepForManufacturing()
ArrayList< Transform > getSlicePlanes()
static void write(Path p, String s)
static void export(List< Polygon > polygons, File defaultDir, boolean groupAll)
default void setCsg(CSG toAdd, File source)
void setAllCSG(Collection< CSG > toAdd, File source)