Skip to content

Commit

Permalink
Merge pull request #411 from CommonWealthRobotics/kh/auto-download-ed…
Browse files Browse the repository at this point in the history
…itors

Kh/auto download editors
  • Loading branch information
madhephaestus authored Jul 11, 2024
2 parents 01dbfa5 + 571af86 commit 1011012
Show file tree
Hide file tree
Showing 26 changed files with 1,184 additions and 604 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ dependencies {
// https://mvnrepository.com/artifact/com.github.kurbatov/firmata4j

// https://mvnrepository.com/artifact/com.fifesoft/rsyntaxtextarea
compile group: 'com.fifesoft', name: 'rsyntaxtextarea', version: '2.6.0'
compile group: 'com.fifesoft', name: 'rsyntaxtextarea', version: '3.4.1'

//compile 'org.bubblecloud.jbullet:jbullet:2.72.2.4'
// https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-svggen
compile group: 'org.apache.xmlgraphics', name: 'batik-svggen', version: '1.7'
implementation group: 'org.apache.xmlgraphics', name: 'batik-all', version: '1.17'
// https://mvnrepository.com/artifact/org.axsl.org.w3c.dom.svg/svg-dom-java
compile group: 'org.axsl.org.w3c.dom.svg', name: 'svg-dom-java', version: '1.1'

Expand All @@ -358,6 +358,8 @@ dependencies {
//MuJoCo
implementation group: 'org.bytedeco', name: 'javacpp', version: '1.5.7'
implementation group: 'com.neuronrobotics', name: 'mujoco-java', version:'3.1.3-pre.11'
// Zip and unzip, tar and untar
implementation 'org.apache.commons:commons-compress:1.26.2'


}
Expand Down
2 changes: 1 addition & 1 deletion libraries/bowler-script-kernel
Submodule bowler-script-kernel updated 24 files
+4 −0 .gitignore
+1 −1 JCSG
+46 −0 Test.SVG
+14 −1 build.gradle
+1 −1 java-bowler
+3 −3 src/main/java/com/neuronrobotics/bowlerstudio/assets/ConfigurationDatabase.java
+16 −2 src/main/java/com/neuronrobotics/bowlerstudio/creature/CadFileExporter.java
+14 −2 src/main/java/com/neuronrobotics/bowlerstudio/creature/MobileBaseCadManager.java
+20 −58 src/main/java/com/neuronrobotics/bowlerstudio/scripting/ArduinoLoader.java
+176 −0 src/main/java/com/neuronrobotics/bowlerstudio/scripting/BlenderLoader.java
+952 −0 src/main/java/com/neuronrobotics/bowlerstudio/scripting/DownloadManager.java
+351 −0 src/main/java/com/neuronrobotics/bowlerstudio/scripting/FreecadLoader.java
+5 −0 src/main/java/com/neuronrobotics/bowlerstudio/scripting/IApprovalForDownload.java
+48 −0 src/main/java/com/neuronrobotics/bowlerstudio/scripting/IExternalEditor.java
+116 −66 src/main/java/com/neuronrobotics/bowlerstudio/scripting/IScriptingLanguage.java
+5 −0 src/main/java/com/neuronrobotics/bowlerstudio/scripting/Listener.java
+77 −0 src/main/java/com/neuronrobotics/bowlerstudio/scripting/ProcessInputStream.java
+22 −3 src/main/java/com/neuronrobotics/bowlerstudio/scripting/RobotHelper.java
+38 −1 src/main/java/com/neuronrobotics/bowlerstudio/scripting/ScriptingEngine.java
+48 −0 src/main/java/com/neuronrobotics/bowlerstudio/scripting/StlLoader.java
+31 −11 src/main/java/com/neuronrobotics/bowlerstudio/vitamins/VitaminBomManager.java
+36 −1 src/main/java/com/neuronrobotics/bowlerstudio/vitamins/Vitamins.java
+23 −0 test/java/src/junit/bowler/BlenderLoadingTest.java
+51 −0 test/java/src/junit/bowler/SVGLoadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,18 @@ public void onAddFile(ActionEvent event) {
System.out.println("Adding new file" + filename + " to " + getGitRepo());
try {
ScriptingEngine.pull(getGitRepo());
String defaultContents = ScriptingEngine.getLangaugeByExtention(extentionStr).getDefaultContents(getGitRepo(), fileSlug );
//String defaultContents =
String fullBranch = ScriptingEngine.getFullBranch(getGitRepo());
if (fullBranch == null)
fullBranch = ScriptingEngine.newBranch(getGitRepo(), "main");

ScriptingEngine.pushCodeToGit(getGitRepo(), fullBranch, filename, defaultContents, message);
ScriptingEngine.getLangaugeByExtention(extentionStr).getDefaultContents(getGitRepo(), filename );
ScriptingEngine.pushCodeToGit(getGitRepo(), fullBranch, filename, null, message);
File nf = ScriptingEngine.fileFromGit(getGitRepo(), filename);

BowlerStudio.createFileTab(nf);

try {
BowlerStudio.createFileTab(nf);
}catch(Exception ex) {
ex.printStackTrace();
}
refreshevent.setToLoggedIn();
} catch (Exception e) {
new IssueReportingExceptionHandler().except(e);
Expand Down
128 changes: 91 additions & 37 deletions src/main/java/com/neuronrobotics/bowlerstudio/BowlerStudio.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.neuronrobotics.bowlerstudio;

import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;

//import com.neuronrobotics.kinematicschef.InverseKinematicsEngine;
import com.neuronrobotics.bowlerkernel.BowlerKernelBuildInfo;
Expand All @@ -13,16 +14,16 @@
import com.neuronrobotics.bowlerstudio.assets.StudioBuildInfo;
import com.neuronrobotics.bowlerstudio.creature.MobileBaseCadManager;
import com.neuronrobotics.bowlerstudio.creature.MobileBaseLoader;
import com.neuronrobotics.bowlerstudio.scripting.ArduinoLoader;
import com.neuronrobotics.bowlerstudio.scripting.DownloadManager;
import com.neuronrobotics.bowlerstudio.scripting.GitHubWebFlow;
import com.neuronrobotics.bowlerstudio.scripting.IApprovalForDownload;
import com.neuronrobotics.bowlerstudio.scripting.IURLOpen;
import com.neuronrobotics.bowlerstudio.scripting.PasswordManager;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingFileWidget;
import com.neuronrobotics.bowlerstudio.scripting.StlLoader;
import com.neuronrobotics.bowlerstudio.util.FileChangeWatcher;
import com.neuronrobotics.bowlerstudio.vitamins.Vitamins;
import com.neuronrobotics.imageprovider.NativeResource;
//import com.neuronrobotics.imageprovider.OpenCVJNILoader;
import com.neuronrobotics.javacad.JavaCadBuildInfo;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
Expand Down Expand Up @@ -59,23 +60,32 @@
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.TransportException;

import static com.neuronrobotics.bowlerstudio.scripting.DownloadManager.delim;

import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.SplashScreen;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;
Expand Down Expand Up @@ -123,7 +133,11 @@ public Console() {
}

@SuppressWarnings("restriction")
public void appendText(String valueOf) {
public void appendText(String v) {
if(v.length()>LengthOfOutputLog) {
v=v.substring(v.length()-LengthOfOutputLog, v.length());
}
String valueOf=v;
if (BowlerStudioModularFrame.getBowlerStudioModularFrame() == null) {
return;
}
Expand Down Expand Up @@ -301,7 +315,22 @@ public static void select(File script, int lineNumber) {
* @param args the command line arguments
* @throws Exception
*/

public static String getBowlerStudioBinaryVersion() throws FileNotFoundException {
String latestVersionString;
File currentVerFile = new File(System.getProperty("user.home") + delim() + "bin" + delim()
+ "BowlerStudioInstall" + delim() + "currentversion.txt");
String s = "";
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(currentVerFile)));
String line;
try {
while (null != (line = br.readLine())) {
s += line;
}
} catch (IOException e) {
}
latestVersionString = s.trim();
return latestVersionString;
}
@SuppressWarnings({ "unchecked", "restriction" })
public static void main(String[] args) throws Exception {
if (args.length != 0) {
Expand All @@ -310,6 +339,12 @@ public static void main(String[] args) throws Exception {
BowlerKernel.main(args);
return;
}
try {
makeSymLinkOfCurrentVersion();
}catch(Throwable t) {
//t.printStackTrace();
System.err.println("Symlink not creaded");
}
System.setOut(System.err);// send all prints to err until replaced with the terminal
net.java.games.input.ControllerEnvironment.getDefaultEnvironment();

Expand Down Expand Up @@ -479,37 +514,6 @@ public void open(URI toOpe) {

// System.err.println("Loading Main.fxml");
renderSplashFrame(81, "Find arduino");
String arduino = "arduino";
if (NativeResource.isLinux()) {

// Slic3r.setExecutableLocation("/usr/bin/slic3r");

} else if (NativeResource.isWindows()) {
arduino = "C:\\Program Files (x86)\\Arduino\\arduino.exe";
if (!new File(arduino).exists()) {
arduino = "C:\\Program Files\\Arduino\\arduino.exe";
}

} else if (NativeResource.isOSX()) {
arduino = "/Applications/Arduino.app/Contents/MacOS/Arduino";
}
try {
if (!new File(arduino).exists() && !NativeResource.isLinux()) {
boolean alreadyNotified = Boolean.getBoolean(
ConfigurationDatabase.getObject("BowlerStudioConfigs", "notifiedArduinoDep", false).toString());
if (!alreadyNotified) {
ConfigurationDatabase.setObject("BowlerStudioConfigs", "notifiedArduinoDep", true);
String adr = arduino;

}

}
System.err.println("Arduino exec found at: " + arduino);
ArduinoLoader.setARDUINOExec(arduino);
} catch (Exception e) {
reporter.uncaughtException(Thread.currentThread(), e);

}
renderSplashFrame(82, "Set up UI");
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
Expand All @@ -534,7 +538,10 @@ public void open(URI toOpe) {
ensureUpdated("https://github.com/CommonWealthRobotics/DHParametersCadDisplay.git",
"https://github.com/CommonWealthRobotics/HotfixBowlerStudio.git",
"https://github.com/CommonWealthRobotics/DeviceProviders.git",
"https://github.com/OperationSmallKat/Katapult.git");
"https://github.com/OperationSmallKat/Katapult.git",
"https://github.com/CommonWealthRobotics/ExternalEditorsBowlerStudio.git",
"https://github.com/CommonWealthRobotics/freecad-bowler-cli.git",
"https://github.com/CommonWealthRobotics/blender-bowler-cli.git");
ScriptingEngine.gitScriptRun("https://github.com/CommonWealthRobotics/HotfixBowlerStudio.git",
"hotfix.groovy", null);
ScriptingEngine.gitScriptRun("https://github.com/CommonWealthRobotics/DeviceProviders.git",
Expand All @@ -561,11 +568,58 @@ public void open(URI toOpe) {
reporter.uncaughtException(Thread.currentThread(), e);

}
DownloadManager.setApproval(new IApprovalForDownload() {
private ButtonType buttonType = null;

@Override
public boolean get(String name, String url) {
buttonType = null;

BowlerKernel.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Message");
alert.setHeaderText("Would you like to download: " + name + "\nfrom:\n" + url);
Optional<ButtonType> result = alert.showAndWait();
buttonType = result.get();
alert.close();
});

while (buttonType == null) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

return buttonType.equals(ButtonType.OK);
}
});
renderSplashFrame(92, "Launching UI");
launch();


}

private static void makeSymLinkOfCurrentVersion() throws Exception {
String version = getBowlerStudioBinaryVersion();
File installDir = new File(System.getProperty("user.home") + delim() + "bin" + delim()+ "BowlerStudioInstall" + delim());
File link = new File(installDir.getAbsolutePath()+delim()+"latest");
File latest = new File(installDir.getAbsolutePath()+delim()+version);
if(link.exists())
link.delete();
try {

Files.createSymbolicLink( link.toPath(),latest.toPath());
}catch(Throwable t) {
//t.printStackTrace();
//link = new File("\""+link.getAbsolutePath()+"\"");
Path ret = Files.createSymbolicLink( link.toPath(), Paths.get(".", version));
System.out.println("Path created "+ret);
}
}

private static void ensureUpdated(String ... urls) {
for(String s:urls) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static String createNewGist(String filename, String description, boolean
{
//TODO: Perhaps this method should throw GitAPIException and IOException
//Setup gist
String defaultContents = ScriptingEngine.getLangaugeByExtention(filename).getDefaultContents();
String defaultContents = "";//;
GitHub gitHub = PasswordManager.getGithub();
GHGistBuilder builder = gitHub.createGist();
builder.file(filename, defaultContents);
Expand Down Expand Up @@ -93,6 +93,7 @@ private static String createGistFromBuilder(GHGistBuilder builder, String filena
}

System.out.println("Creating gist at " + filename);
ScriptingEngine.getLangaugeByExtention(filename).getDefaultContents(gist.getGitPullUrl(), filename);
return gist.getGitPullUrl();
}
catch (IOException e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.neuronrobotics.bowlerstudio.creature;

import com.neuronrobotics.bowlerstudio.BowlerStudio;
import com.neuronrobotics.bowlerstudio.assets.FontSizeManager;

import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
Expand Down Expand Up @@ -127,12 +128,12 @@ public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldProperty
setpoint.valueProperty().addListener(this);

String unitsString = "(" + units + ")";

getColumnConstraints().add(new ColumnConstraints(30)); // column 2 is 100 wide
getColumnConstraints().add(new ColumnConstraints(40)); // column 2 is 100 wide
getColumnConstraints().add(new ColumnConstraints(30)); // column 2 is 100 wide
getColumnConstraints().add(new ColumnConstraints(100)); // column 2 is 100 wide
getColumnConstraints().add(new ColumnConstraints(unitsString.length() * 7)); // column 2 is 100 wide
double scale = (double)(FontSizeManager.getDefaultSize())/12.0;
getColumnConstraints().add(new ColumnConstraints(30*scale)); // column 2 is 100 wide
getColumnConstraints().add(new ColumnConstraints(40*scale)); // column 2 is 100 wide
getColumnConstraints().add(new ColumnConstraints(30*scale)); // column 2 is 100 wide
getColumnConstraints().add(new ColumnConstraints(100*scale)); // column 2 is 100 wide
getColumnConstraints().add(new ColumnConstraints(unitsString.length() * 7*scale)); // column 2 is 100 wide

add(setpoint, 3, 1);
add(jogplus, 2, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static String[] copyGitFile(String sourceGit, String targetGit, String fi

public static void addVitamins(IVitaminHolder vitamins, TreeItem<String> rootItem,
HashMap<TreeItem<String>, Runnable> callbackMapForTreeitems,
HashMap<TreeItem<String>, Parent> widgetMapForTreeitems,ITransformProvider tfp) {
HashMap<TreeItem<String>, Parent> widgetMapForTreeitems,ITransformProvider tfp,Affine manipulator, Affine lastLink, TransformNR offset) {
TreeItem<String> vitaminsMenu = new TreeItem<String>("Vitamins Add/Remove",
AssetFactory.loadIcon("Vitamins.png"));
HashMap<Parent,VitatminWidget> widget = new HashMap<>();
Expand All @@ -80,7 +80,9 @@ public static void addVitamins(IVitaminHolder vitamins, TreeItem<String> rootIt
Parent w = loader.load();
VitatminWidget tw = loader.getController();
tw.setVitaminProvider(vitamins,tfp);

tw.setManipulator(manipulator);
tw.setLastLinkAffine(lastLink);
tw.setOffset(offset);
//Group value = new Group(w);
widgetMapForTreeitems.put(vitaminsMenu, w);
widget.put(w, tw);
Expand Down Expand Up @@ -571,7 +573,7 @@ public void onTransformChaging(TransformNR newTrans) {
rootItem.getChildren().addAll(bodymass, imuCenter,PlaceLimb);
addVitamins( device, rootItem, callbackMapForTreeitems, widgetMapForTreeitems, selected->{
return device.forwardOffset(new TransformNR());
});
},(Affine)device.getRootListener(),(Affine)device.getRootListener(),new TransformNR());
if (root)
rootItem.getChildren().addAll( printable,arrangeBed, kinematics);
rootItem.getChildren().addAll(addArm, addleg, addFixed, addsteerable);
Expand Down Expand Up @@ -1104,6 +1106,10 @@ public void onSliderDoneMoving(EngineeringUnitsSliderWidget source, double newAn


link.getChildren().addAll(design);
Affine manipulator = (Affine) dh.getListener(linkIndex);
TransformNR offset = dh.getDHStep(linkIndex).inverse();
Affine lastLinkAffine = linkIndex==0? (Affine) dh.getRootListener() :(Affine) dh.getListener(linkIndex-1);

addVitamins( dh.getLinkConfiguration(linkIndex), link, callbackMapForTreeitems, widgetMapForTreeitems,selected->{
Affine linkObjectManipulator = (Affine) dh.getLinkObjectManipulator(linkIndex);
TransformNR pose = TransformFactory.affineToNr(linkObjectManipulator);
Expand All @@ -1120,7 +1126,7 @@ public void onSliderDoneMoving(EngineeringUnitsSliderWidget source, double newAn
pose = TransformFactory.affineToNr(ll);
}
return pose;
});
},manipulator,lastLinkAffine,offset);


link.getChildren().addAll(slaves, remove);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.neuronrobotics.bowlerstudio.assets.ConfigurationDatabase;
import com.neuronrobotics.bowlerstudio.physics.MuJoCoPhysicsManager;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.bowlerstudio.vitamins.Vitamins;
import com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration;
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.addons.kinematics.imu.IMUUpdate;
Expand Down Expand Up @@ -241,17 +242,8 @@ private void validateInput(TextField text,ComboBox<String> box,String key,String
BowlerStudio.runLater(()->box.setDisable(true));
String text2 = text.getText();
ConfigurationDatabase.setObject("PhysicsWidget",key ,text2);
if(!text2.endsWith(".git"))
if(!Vitamins.isGitURL(text2)) {
return;
if(text2.length()<=5)
return;
try {
new java.net.URL(text2);
}catch(Exception ex) {
if(!text2.startsWith("git@")) {
ex.printStackTrace();
return;
}
}
BowlerStudio.runLater(()->box.setDisable(false));

Expand Down
Loading

0 comments on commit 1011012

Please sign in to comment.