Skip to content

Commit

Permalink
Merge pull request #365 from CommonWealthRobotics/kh/kernelMobileBase…
Browse files Browse the repository at this point in the history
…LoaderErrorFix

Kh/kernel mobile base loader error fix
  • Loading branch information
madhephaestus committed Jun 20, 2023
2 parents 09d645e + 4774fa3 commit c6fcce8
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.neuronrobotics.sdk.util.ThreadUtil;

import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader;
Expand Down Expand Up @@ -46,10 +48,15 @@ public class CreatureLab extends AbstractBowlerStudioTab implements IOnEngineeri
private ProgressIndicator pi;

private MobileBaseCadManager baseManager;
private CheckBox autoRegen = new CheckBox("Auto-Regen CAD");
private CheckBox autoRegen = new CheckBox("Auto-Generate CAD");
private Button regen=new Button("Generate Cad Now");
Parent root;
private BowlerJInputDevice gameController = null;
CreatureLabControlsTab tab = new CreatureLabControlsTab();;
CreatureLabControlsTab tab = new CreatureLabControlsTab();

private long timeSinceLastUpdate = 0;

private HBox radioOptions;;

@Override
public void onTabClosing() {
Expand All @@ -68,11 +75,14 @@ public void initializeUI(BowlerAbstractDevice pm) {
setGraphic(AssetFactory.loadIcon("CreatureLab-Tab.png"));
this.pm = pm;
autoRegen.setSelected(true);

disable();
autoRegen.setOnAction(event -> {
baseManager.setAutoRegen(autoRegen.isSelected());
if (autoRegen.isSelected()) {
generateCad();
}
regenFromUiEvent();
});
regen.setOnAction(event -> {
autoRegen.setSelected(true);
regenFromUiEvent();
});
// TODO Auto-generated method stub
setText(pm.getScriptingName());
Expand Down Expand Up @@ -110,7 +120,7 @@ public void initializeUI(BowlerAbstractDevice pm) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
while(getContent()==null)
while (getContent() == null)
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Expand All @@ -119,6 +129,30 @@ public void initializeUI(BowlerAbstractDevice pm) {
}
}

private void regenFromUiEvent() {
BowlerStudio.runLater(() -> {

if (System.currentTimeMillis() - timeSinceLastUpdate < 500) {
return;
}
timeSinceLastUpdate = System.currentTimeMillis();
if (autoRegen.isSelected()) {
disable();
}
baseManager.setAutoRegen(autoRegen.isSelected());
if (autoRegen.isSelected()) {
generateCad();
}
});
}

private void disable() {
autoRegen.setDisable(true);
if (radioOptions != null)
radioOptions.setDisable(true);
regen.setDisable(true);
}

private void finishLoading(MobileBase device) {

TreeItem<String> rootItem = null;
Expand Down Expand Up @@ -170,8 +204,8 @@ private void finishLoading(MobileBase device) {

rootItemFinal.setExpanded(true);
MobileBaseCadManager.get(device, BowlerStudioController.getMobileBaseUI());
MobleBaseMenueFactory.load(device, tree, mainBaseFinal, callbackMapForTreeitems, widgetMapForTreeitems, this,
true, creatureIsOwnedByUser);
MobleBaseMenueFactory.load(device, tree, mainBaseFinal, callbackMapForTreeitems, widgetMapForTreeitems,
this, true, creatureIsOwnedByUser);
tree.setPrefWidth(325);
tree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
JogMobileBase walkWidget = new JogMobileBase(device);
Expand Down Expand Up @@ -232,39 +266,60 @@ public void run() {
setCadMode(true);
});

HBox radioOptions = new HBox(10);
radioOptions = new HBox(10);
radioOptions.getChildren().addAll(new Label("Cad"), rb1, rb2, new Label("Config"));

pi = new ProgressIndicator(0);
baseManager = MobileBaseCadManager.get(device, BowlerStudioController.getMobileBaseUI());
pi.progressProperty().bindBidirectional(baseManager.getProcesIndictor());
HBox progressIndicatorPanel = new HBox(10);
progressIndicatorPanel.getChildren().addAll(new Label("Cad Progress:"), pi);
progress.getChildren().addAll(progressIndicatorPanel, autoRegen, radioOptions);

progress.setStyle("-fx-background-color: #FFFFFF;");
progress.setOpacity(.7);
progress.setMinHeight(100);
progress.setPrefSize(325, 150);
tab.setOverlayTop(progress);
progress.getChildren().addAll( regen,autoRegen, radioOptions);
progressIndicatorPanel.getChildren().addAll( progress,pi);

progressIndicatorPanel.setStyle("-fx-background-color: #FFFFFF;");
progressIndicatorPanel.setOpacity(.7);
progressIndicatorPanel.setMinHeight(100);
progressIndicatorPanel.setPrefSize(325, 150);
tab.setOverlayTop(progressIndicatorPanel);

BowlerStudioModularFrame.getBowlerStudioModularFrame().showCreatureLab();
setCadMode(true);// start the UI in config mode
generateCad();

}
pi.progressProperty().addListener(new ChangeListener<Number>() {

@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
System.out.println("Progress listener " + newValue);
if (newValue.doubleValue() > 0.99) {
BowlerStudio.runLater(() -> {
enable();
});
}else {
BowlerStudio.runLater(() -> {
disable();
});
}
}


});
}
private void enable() {
autoRegen.setDisable(false);
if (radioOptions != null)
radioOptions.setDisable(false);
regen.setDisable(false);
}
private boolean hasWalking(MobileBase device) {
return device.getLegs().size() > 0 || device.getSteerable().size() > 0 || device.getDrivable().size() > 0;
}

private void setCadMode(boolean mode) {
new Thread(() -> {
baseManager.setConfigurationViewerMode(mode);
baseManager.setAutoRegen(autoRegen.isSelected());
if (autoRegen.isSelected()) {
generateCad();
}
regenFromUiEvent();
}).start();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javafx.fxml.FXML;
import javafx.scene.control.TreeView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

public class CreatureLabControlsTab {
Expand Down Expand Up @@ -53,7 +54,7 @@ public void setTreeBox(AnchorPane treeBox) {
}


public void setOverlayTop(VBox progress) {
public void setOverlayTop(HBox progress) {
// TODO Auto-generated method stub
BowlerStudio.runLater(()->{
progressBar.getChildren().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Axis(int i) {

Affine yp = new Affine();
yp.setTy(i / 2);
yText = CSG.unionAll(TextExtrude.text((double)strokWidth,"Y",font)).toYMin().rotz(90).movey(i).moveToCenterX();
yText = CSG.unionAll(TextExtrude.text((double)strokWidth,"Y",font)).rotz(90).toYMin().movey(i).moveToCenterX();
//yText.getTransforms().add(yp);

// zp.setTz(i/2);
Expand Down

0 comments on commit c6fcce8

Please sign in to comment.