Skip to content

Commit 3606705

Browse files
committed
Adding a server launch to the kernel
1 parent 4985731 commit 3606705

File tree

1 file changed

+71
-40
lines changed

1 file changed

+71
-40
lines changed

src/main/java/com/neuronrobotics/bowlerstudio/BowlerKernel.java

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
5858

5959
import eu.mihosoft.vrl.v3d.CSG;
60+
import eu.mihosoft.vrl.v3d.CSGServer;
6061
import eu.mihosoft.vrl.v3d.ICSGProgress;
6162
import eu.mihosoft.vrl.v3d.JavaFXInitializer;
6263
import javafx.application.Platform;
@@ -72,7 +73,7 @@ public class BowlerKernel {
7273

7374
// private static final String CSG = null;
7475
private static File historyFile = new File(ScriptingEngine.getWorkspace().getAbsolutePath() + "/bowler.history");
75-
private static boolean kernelMode=true;
76+
private static boolean kernelMode = true;
7677

7778
private static void loadHistoryLocal() {
7879
historyFile = new File(ScriptingEngine.getWorkspace().getAbsolutePath() + "/bowler.history");
@@ -108,8 +109,9 @@ private static void fail() {
108109
"java -jar BowlerScriptKernel.jar -p <file 1> .. <file n> # This will load one script then take the list of objects returned and pss them to the next script as its 'args' variable ");
109110
com.neuronrobotics.sdk.common.Log.error(
110111
"java -jar BowlerScriptKernel.jar -r <Groovy Jython or Clojure> (Optional)(-s or -p)<file 1> .. <file n> # This will start a shell in the requested langauge and run the files provided. ");
111-
com.neuronrobotics.sdk.common.Log.error("java -jar BowlerScriptKernel.jar -g <Git repo> <Git file> # this will run a file from git");
112-
if(isKernelMode())
112+
com.neuronrobotics.sdk.common.Log
113+
.error("java -jar BowlerScriptKernel.jar -g <Git repo> <Git file> # this will run a file from git");
114+
if (isKernelMode())
113115
System.exit(1);
114116
}
115117

@@ -130,8 +132,10 @@ public static void runArgumentsAfterStartup(String[] args, long startTime)
130132
boolean gitRun = false;
131133
String gitRepo = null;
132134
String gitFile = null;
135+
boolean runCSGServer = false;
136+
File keys = null;
137+
int port = 3742;
133138
for (String s : args) {
134-
135139
if (gitRun) {
136140
if (gitRepo == null) {
137141
gitRepo = s;
@@ -142,7 +146,34 @@ public static void runArgumentsAfterStartup(String[] args, long startTime)
142146
if (s.startsWith("-g")) {
143147
gitRun = true;
144148
}
149+
if (s.toLowerCase().contains("-csgserver")) {
150+
runCSGServer = true;
151+
continue;
152+
}
153+
if (runCSGServer) {
154+
if (keys == null) {
155+
keys = new File(s);
156+
continue;
157+
} else {
158+
try {
159+
port = Integer.parseInt(s);
160+
}catch(NumberFormatException ex) {
161+
ex.printStackTrace();
162+
}
163+
}
164+
}
165+
}
166+
if (runCSGServer) {
167+
CSGServer.setDirectory(ScriptingEngine.getWorkspace());
168+
CSGServer server = new CSGServer(port, keys);
169+
try {
170+
server.start();
171+
} catch (Exception e) {
172+
e.printStackTrace();
173+
}
174+
return;
145175
}
176+
146177
Object ret = null;
147178
File baseWorkspaceFile = null;
148179
if (gitRun && gitRepo != null) {
@@ -198,21 +229,21 @@ public static void runArgumentsAfterStartup(String[] args, long startTime)
198229
File f = new File(s);
199230
String location;
200231
try {
201-
location =ScriptingEngine.locateGitTopLevelDirectory(f).getAbsolutePath();
202-
}catch(Exception ex) {
203-
location= new File(".").getAbsolutePath();
232+
location = ScriptingEngine.locateGitTopLevelDirectory(f).getAbsolutePath();
233+
} catch (Exception ex) {
234+
location = new File(".").getAbsolutePath();
235+
}
236+
if (location.endsWith(".")) {
237+
location = location.substring(0, location.length() - 1);
204238
}
205-
if(location.endsWith(".")) {
206-
location=location.substring(0,location.length()-1);
207-
}
208-
if(!location.endsWith("/")) {
209-
location+="/";
239+
if (!location.endsWith("/")) {
240+
location += "/";
210241
}
211242
baseWorkspaceFile = new File(location);
212-
213-
System.out.println("Using working directory "+baseWorkspaceFile.getAbsolutePath());
214-
f=new File(baseWorkspaceFile.getAbsolutePath()+"/"+s);
215-
com.neuronrobotics.sdk.common.Log.error("File "+f.getName());
243+
244+
System.out.println("Using working directory " + baseWorkspaceFile.getAbsolutePath());
245+
f = new File(baseWorkspaceFile.getAbsolutePath() + "/" + s);
246+
com.neuronrobotics.sdk.common.Log.error("File " + f.getName());
216247
ret = ScriptingEngine.inlineFileScriptRun(f, null);
217248
} catch (Throwable e) {
218249
e.printStackTrace();
@@ -385,27 +416,27 @@ public void progressUpdate(int currentIndex, int finalIndex, String type,
385416
}
386417

387418
private static void finish(long startTime) {
388-
com.neuronrobotics.sdk.common.Log.error(
389-
"Process took " + (((double) (System.currentTimeMillis() - startTime))) / 60000.0 + " minutes");
419+
com.neuronrobotics.sdk.common.Log
420+
.error("Process took " + (((double) (System.currentTimeMillis() - startTime))) / 60000.0 + " minutes");
390421
System.exit(0);
391422
}
392423

393424
public static void processReturnedObjectsStart(Object ret, File baseWorkspaceFile) {
394425
processUIOpening(ret);
395-
if(baseWorkspaceFile!=null)
396-
System.out.println("Processing file in directory "+baseWorkspaceFile.getAbsolutePath());
426+
if (baseWorkspaceFile != null)
427+
System.out.println("Processing file in directory " + baseWorkspaceFile.getAbsolutePath());
397428

398-
399429
if (baseWorkspaceFile != null) {
400-
401-
File baseDirForFiles = new File(baseWorkspaceFile.getAbsolutePath()+"/manufacturing/");
430+
431+
File baseDirForFiles = new File(baseWorkspaceFile.getAbsolutePath() + "/manufacturing/");
402432
if (baseDirForFiles.exists()) {
403433
// baseDirForFiles.mkdir();
404434
File bomCSV = new File(
405435
baseWorkspaceFile.getAbsolutePath() + "/" + VitaminBomManager.getManufacturingBomCsv());
406436
if (bomCSV.exists()) {
407437

408-
File file = new File(baseWorkspaceFile.getAbsolutePath() + "/"+ VitaminBomManager.getManufacturingBomCsv());
438+
File file = new File(
439+
baseWorkspaceFile.getAbsolutePath() + "/" + VitaminBomManager.getManufacturingBomCsv());
409440
// if (file.exists())
410441
// file.delete();
411442
try {
@@ -418,7 +449,8 @@ public static void processReturnedObjectsStart(Object ret, File baseWorkspaceFil
418449
File bom = new File(
419450
baseWorkspaceFile.getAbsolutePath() + "/" + VitaminBomManager.getManufacturingBomJson());
420451
if (bom.exists()) {
421-
File file = new File(baseWorkspaceFile.getAbsolutePath() + "/"+ VitaminBomManager.getManufacturingBomJson());
452+
File file = new File(
453+
baseWorkspaceFile.getAbsolutePath() + "/" + VitaminBomManager.getManufacturingBomJson());
422454
// if (file.exists())
423455
// file.delete();
424456
try {
@@ -428,17 +460,17 @@ public static void processReturnedObjectsStart(Object ret, File baseWorkspaceFil
428460
e.printStackTrace();
429461
}
430462
}
431-
}else {
463+
} else {
432464
baseDirForFiles.mkdirs();
433465
}
434466
}
435467
ArrayList<CSG> csgBits = new ArrayList<>();
436468
try {
437469
processReturnedObjects(ret, csgBits);
438470
String url = ScriptingEngine.locateGitUrl(baseWorkspaceFile);
439-
com.neuronrobotics.sdk.common.Log.error("Loading printbed URL "+url);
471+
com.neuronrobotics.sdk.common.Log.error("Loading printbed URL " + url);
440472
PrintBedManager printBedManager = new PrintBedManager(baseWorkspaceFile, csgBits);
441-
if(printBedManager.hasPrintBed())
473+
if (printBedManager.hasPrintBed())
442474
csgBits = printBedManager.makePrintBeds();
443475
else {
444476
com.neuronrobotics.sdk.common.Log.error("Exporting files without print bed");
@@ -451,12 +483,12 @@ public static void processReturnedObjectsStart(Object ret, File baseWorkspaceFil
451483
}
452484

453485
private static void processUIOpening(Object ret) {
454-
if(Tab.class.isInstance(ret)) {
486+
if (Tab.class.isInstance(ret)) {
455487
com.neuronrobotics.sdk.common.Log.error("Launching User Defined UI");
456-
Tab t=(Tab)ret;
488+
Tab t = (Tab) ret;
457489
CompletableFuture<Boolean> future = new CompletableFuture<>();
458490

459-
BowlerKernel.runLater(()->{
491+
BowlerKernel.runLater(() -> {
460492
// Get the content from the tab
461493
javafx.scene.Node content = t.getContent();
462494
// Create a new stage
@@ -482,7 +514,7 @@ private static void processUIOpening(Object ret) {
482514
newStage.setOnCloseRequest(event -> {
483515
// Exit the JVM when the window is closed
484516
future.complete(true);
485-
BowlerKernel.runLater(()->Platform.exit());
517+
BowlerKernel.runLater(() -> Platform.exit());
486518
});
487519
FontSizeManager.addListener(fontNum -> {
488520
int tmp = fontNum - 10;
@@ -491,10 +523,10 @@ private static void processUIOpening(Object ret) {
491523
root.setStyle("-fx-font-size: " + tmp + "pt");
492524
newStage.sizeToScene();
493525
});
494-
if(IStageReceiver.class.isInstance(ret)) {
526+
if (IStageReceiver.class.isInstance(ret)) {
495527
com.neuronrobotics.sdk.common.Log.error("UI is a IStageReceiver");
496-
IStageReceiver r=(IStageReceiver)ret;
497-
BowlerKernel.runLater(()->{
528+
IStageReceiver r = (IStageReceiver) ret;
529+
BowlerKernel.runLater(() -> {
498530
r.receiveStage(newStage, scene);
499531
});
500532
}
@@ -505,13 +537,13 @@ private static void processUIOpening(Object ret) {
505537
scene.getRoot().layout();
506538
});
507539
try {
508-
future.get();
540+
future.get();
509541
System.exit(0);
510542
} catch (Exception e) {
511543
e.printStackTrace();
512544
}
513545
}
514-
546+
515547
}
516548

517549
private static void processReturnedObjects(Object ret, ArrayList<CSG> csgBits) {
@@ -524,8 +556,8 @@ private static void processReturnedObjects(Object ret, ArrayList<CSG> csgBits) {
524556
if (CSG.class.isInstance(ret)) {
525557
csgBits.add((CSG) ret);
526558
}
527-
if(CaDoodleFile.class.isInstance(ret)) {
528-
processReturnedObjects(CaDoodleLoader.process((CaDoodleFile)ret), csgBits);
559+
if (CaDoodleFile.class.isInstance(ret)) {
560+
processReturnedObjects(CaDoodleLoader.process((CaDoodleFile) ret), csgBits);
529561
return;
530562
}
531563
if (MobileBase.class.isInstance(ret)) {
@@ -831,5 +863,4 @@ public static void setKernelMode(boolean kernelMode) {
831863
BowlerKernel.kernelMode = kernelMode;
832864
}
833865

834-
835866
}

0 commit comments

Comments
 (0)