|
| 1 | +package com.neuronrobotics.bowlerstudio.scripting.external; |
| 2 | + |
| 3 | +import static com.neuronrobotics.bowlerstudio.scripting.DownloadManager.*; |
| 4 | + |
| 5 | +import java.io.File; |
| 6 | +import java.io.IOException; |
| 7 | +import java.net.MalformedURLException; |
| 8 | +import java.net.URL; |
| 9 | +import java.util.Arrays; |
| 10 | +import java.util.List; |
| 11 | + |
| 12 | +import org.eclipse.jgit.api.Git; |
| 13 | +import org.eclipse.jgit.api.errors.GitAPIException; |
| 14 | +import org.eclipse.jgit.api.errors.InvalidRemoteException; |
| 15 | +import org.eclipse.jgit.api.errors.TransportException; |
| 16 | +import org.eclipse.jgit.errors.NoWorkTreeException; |
| 17 | + |
| 18 | +import com.neuronrobotics.bowlerstudio.assets.AssetFactory; |
| 19 | +import com.neuronrobotics.bowlerstudio.scripting.BashLoader; |
| 20 | +import com.neuronrobotics.bowlerstudio.scripting.CaDoodleLoader; |
| 21 | +import com.neuronrobotics.bowlerstudio.scripting.DownloadManager; |
| 22 | +import com.neuronrobotics.bowlerstudio.scripting.FXMLBowlerLoader; |
| 23 | +import com.neuronrobotics.bowlerstudio.scripting.GroovyHelper; |
| 24 | +import com.neuronrobotics.bowlerstudio.scripting.IExternalEditor; |
| 25 | +import com.neuronrobotics.bowlerstudio.scripting.JsonRunner; |
| 26 | +import com.neuronrobotics.bowlerstudio.scripting.OpenSCADLoader; |
| 27 | +import com.neuronrobotics.bowlerstudio.scripting.RobotHelper; |
| 28 | +import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine; |
| 29 | +import com.neuronrobotics.bowlerstudio.scripting.SvgLoader; |
| 30 | +import com.neuronrobotics.video.OSUtil; |
| 31 | + |
| 32 | +import eu.mihosoft.vrl.v3d.JavaFXInitializer; |
| 33 | +import javafx.scene.control.Button; |
| 34 | +import javafx.scene.image.Image; |
| 35 | + |
| 36 | +public class CaDoodleExternalEditor implements IExternalEditor { |
| 37 | + |
| 38 | + private Button advanced; |
| 39 | + |
| 40 | + @Override |
| 41 | + public void launch(File file, Button advanced) { |
| 42 | + new Thread(() -> { |
| 43 | + this.advanced = advanced; |
| 44 | + String filename = file.getAbsolutePath(); |
| 45 | + |
| 46 | + try { |
| 47 | + File dir = file.getAbsoluteFile().getParentFile(); |
| 48 | + File openscad = DownloadManager.getRunExecutable("cadoodle", null); |
| 49 | + |
| 50 | + List<String> asList = Arrays.asList( |
| 51 | + openscad.getAbsolutePath(), |
| 52 | + filename); |
| 53 | + |
| 54 | + Thread t=run(this, dir, System.err, asList); |
| 55 | + t.join(); |
| 56 | + } catch (NoWorkTreeException e) { |
| 57 | + // Auto-generated catch block |
| 58 | + e.printStackTrace(); |
| 59 | + } catch (Exception e) { |
| 60 | + // Auto-generated catch block |
| 61 | + e.printStackTrace(); |
| 62 | + } |
| 63 | + onProcessExit(0) ; |
| 64 | + |
| 65 | + }).start(); |
| 66 | + } |
| 67 | + |
| 68 | + public void onProcessExit(int ev) { |
| 69 | + advanced.setDisable(false); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public URL getInstallURL() throws MalformedURLException { |
| 74 | + return new URL("https://github.com/CommonWealthRobotics/CaDoodle/blob/main/README.md"); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public String nameOfEditor() { |
| 79 | + return "CaDoodle"; |
| 80 | + } |
| 81 | + |
| 82 | + public Image getImage() { |
| 83 | + try { |
| 84 | + Image asset = AssetFactory.loadAsset("Script-Tab-CaDoodle.png"); |
| 85 | + return asset; |
| 86 | + } catch (Exception e) { |
| 87 | + // Auto-generated catch block |
| 88 | + e.printStackTrace(); |
| 89 | + } |
| 90 | + return null; |
| 91 | + } |
| 92 | + |
| 93 | + public static void main(String[] args) |
| 94 | + throws InvalidRemoteException, TransportException, GitAPIException, IOException { |
| 95 | + JavaFXInitializer.go(); |
| 96 | + String url="https://github.com/madhephaestus/TestRepo.git"; |
| 97 | + ScriptingEngine.pull("https://github.com/CommonWealthRobotics/ExternalEditorsBowlerStudio.git"); |
| 98 | + ScriptingEngine.pull(url); |
| 99 | + File f = ScriptingEngine.fileFromGit(url, |
| 100 | + "Doodle1/TestRepo.doodle"); |
| 101 | + |
| 102 | + new CaDoodleExternalEditor().launch(f, new Button()); |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + public List<Class> getSupportedLangauge() { |
| 107 | + return Arrays.asList( CaDoodleLoader.class); |
| 108 | + } |
| 109 | +} |
0 commit comments