use of artisynth.core.probes.NumericProbeDriver in project artisynth_core by artisynth.
the class NumericProbeEditor method revalidateDrivers.
//
// goes through all drivers and see if the current string
//
protected void revalidateDrivers(String currentExpr) {
// this variable
for (NumericProbeDriver driver : myDrivers) {
if (driver.usesVariable(currentExpr)) {
driver.setInvalid();
System.out.println("invalidated driver with expr [" + driver.getExpression() + "]");
int index = myDrivers.indexOf(driver);
eqList.get(index).setEqText("");
System.out.println("cleared equation box #" + index);
}
}
}
use of artisynth.core.probes.NumericProbeDriver in project artisynth_core by artisynth.
the class OutputNumericProbeEditor method updateVariable.
private void updateVariable(String name, Property prop) {
// the way we have to check to see the drivers work here is similar to
// updateProperty in the input probe editor.
NumericProbeVariable var = myVariables.get(name);
if (var.getDimension() != getPropDim(prop)) {
System.out.println(name + " variable changed to size " + getPropDim(prop));
var.setDimension(getPropDim(prop));
for (NumericProbeDriver driver : myDrivers) {
System.out.println("driver expression is : " + driver.getExpression());
if (driver.usesVariable(name)) {
int index = myDrivers.indexOf(driver);
System.out.println("Driver #" + index + "uses this variable");
AddEquationPane eqPane = eqList.get(index);
// AddVectorPane vecPane = probeChannels.get(index);
try {
System.out.println("size used to be: " + driver.getOutputSize());
driver.setExpression(driver.getExpression(), myVariables);
// vecPane = probeChannels.get(index);
System.out.println("size is now: " + driver.getOutputSize());
eqPane.setDimensionLabel(driver.getOutputSize());
} catch (Exception exception) {
System.out.println(exception.getMessage());
showErrorWindow(exception.getMessage());
invalidateDriverAndGUI(index);
// invalidate current driver.
eqPane.setEqText("");
eqPane.clearDimensionLabel();
System.out.println("invalidating driver @ index " + index);
}
}
}
}
}
use of artisynth.core.probes.NumericProbeDriver in project artisynth_core by artisynth.
the class OutputNumericProbeEditor method actionPerformed.
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "Add") {
addBlankOutputProbeVector();
increaseFrameSize();
} else if (e.getActionCommand() == "Add Property") {
addBlankOutputProperty();
increaseFrameSize();
} else // }
if (e.getActionCommand() == "PropSelected") {
// same as input?
AddPropertyPane propPane = (AddPropertyPane) e.getSource();
propPane.setPropNameEnabled(true);
int index = propList.indexOf(propPane);
System.out.println("prop selected from prop pane #: " + index);
String propPath = propPane.getPropPath();
Property prop = getProp(propPath);
if (updateProperty(index, prop)) {
increaseFrameSize();
}
updateVariable(propPane.getPropNameFieldText(), prop);
} else if (e.getActionCommand() == "blank") {
// happens when we receive a non-selection from the prop select box
// todo: decide if this method is better (leave prop in list as is)
// or the one in input editor (where we null the property).
AddPropertyPane propPane = (AddPropertyPane) e.getSource();
int index = propList.indexOf(propPane);
if (index < 0)
return;
for (NumericProbeDriver driver : myDrivers) {
if (driver.usesVariable(propPane.getPropNameFieldText())) {
int driverIndex = myDrivers.indexOf(driver);
driver.setInvalid();
AddEquationPane eqPane = eqList.get(driverIndex);
eqPane.setEqText("");
eqPane.clearDimensionLabel();
// AddVectorPane vecPane = probeChannels.get(driverIndex);
// vecPane.clearDimBox();
System.out.println("invalidated driver with expr [" + driver.getExpression() + "]");
}
}
myVariables.remove(propPane.getPropNameFieldText());
myProperties.set(index, null);
propPane.setPropNameEnabled(false);
// AddEquationPane eqPane = getEqPane(index);
// if (eqPane != null)
// {
// try
// {
// myProperties.set(index, null);
// myDrivers.get(index).setInvalid();
// }
// catch (Exception exp)
// {
// System.out.println(exp.getMessage());
// }
// eqPane.setEnabled(false);
// eqPane.setEqText("");
// }
} else if (// delete output
e.getActionCommand() == "Expression Changed") {
AddEquationPane eqPane = (AddEquationPane) e.getSource();
System.out.println("new expression entered :" + eqPane.getEqText());
String newExpr = eqPane.getEqText();
if (// otherwise, do nothing and driver will
!newExpr.equals("")) // remain invalid
{
changeExpression(eqList.indexOf(eqPane), newExpr);
} else {
invalidateDriverAndGUI(eqList.indexOf(eqPane));
eqPane.clearDimensionLabel();
}
} else if (// delete output
e.getActionCommand() == "Delete Channel") {
System.out.println("Deleting channel and equation GUI...");
AddEquationPane pane = (AddEquationPane) e.getSource();
int index = eqList.indexOf(pane);
removeEquationGUI(index);
deleteOutput(index);
} else if (// delete a property
e.getActionCommand() == "Delete Property") {
AddPropertyPane pane = (AddPropertyPane) e.getSource();
int index = propList.indexOf(pane);
String propname = pane.getPropNameFieldText();
System.out.println("Deleting Property ID" + index);
removePropertyGUI(index);
deleteProperty(index);
myVariables.remove(propname);
revalidateDrivers(propname);
} else if (// rename property
e.getActionCommand() == "Property Renamed") {
AddPropertyPane propPane = (AddPropertyPane) e.getSource();
String newName = propPane.getPropNameFieldText();
String oldName = propPane.getOldPropName();
for (AddPropertyPane pane : propList) {
if (!propPane.equals(pane)) {
if (newName.compareTo(pane.getPropNameFieldText()) == 0) {
// check to make sure there are no duplicates
showErrorWindow("Name already exists!");
newName = oldName;
// so in this case, the 'new' name is the same as old, so
// effectively we don't make any changes
// and when calling setChannelName a few lines later we
// restore the old name into the GUI
}
}
}
// System.out.println("trying to set name");
propPane.setPropNameField(newName);
renameProperty(oldName, newName);
} else if (e.getActionCommand() == "MouseEnteredEq") {
// int index = eqList.indexOf(e.getSource());
// AddVectorPane vec = probeChannels.get(index);
// vec.setHighlight(true);
} else if (e.getActionCommand() == "MouseExitedEq") {
// int index = eqList.indexOf(e.getSource());
// AddVectorPane vec = probeChannels.get(index);
// vec.setHighlight(false);
} else if (e.getActionCommand() == "MouseEnteredVec") {
// int index = probeChannels.indexOf(e.getSource());
// AddEquationPane eq = eqList.get(index);
// eq.setHighlight(true);
} else if (e.getActionCommand() == "MouseExitedVec") {
// int index = probeChannels.indexOf(e.getSource());
// AddEquationPane eq = eqList.get(index);
// eq.setHighlight(false);
} else if (// done. add the probe!
e.getActionCommand() == "Done") {
setOutputProbe();
// if (myParent != null) {
// myParent.actionPerformed (new ActionEvent (this, 0, "ProbeEdited"));
// }
Timeline timeline = myMain.getTimeline();
if (timeline != null) {
timeline.updateProbes(myMain.getRootModel());
}
dispose();
} else {
super.actionPerformed(e);
}
refreshAddBtn();
}
use of artisynth.core.probes.NumericProbeDriver in project artisynth_core by artisynth.
the class OutputNumericProbeEditor method changeExpression.
public void changeExpression(int id, String expr) {
NumericProbeDriver driver = myDrivers.get(id);
// AddVectorPane vecPane = probeChannels.get(id);
String oldExpr = driver.getExpression();
System.out.println("old driver expr is [" + oldExpr + "]");
if (expr == driver.getExpression()) {
System.out.println("same as old expression. do nothing.");
return;
}
if (// todo: either remove this bit, or remove it in the
expr == "") // function that calls it
{
driver.setInvalid();
System.out.println("invalidating driver");
return;
}
AddEquationPane eqPane = eqList.get(id);
try {
driver.setExpression(expr, myVariables);
// vecPane = probeChannels.get(id);
System.out.println("setting size display to: " + driver.getOutputSize());
eqPane.setDimensionLabel(driver.getOutputSize());
eqPane.updateAppearance();
} catch (Exception exception) {
System.out.println(exception.getMessage());
showErrorWindow(exception.getMessage());
eqPane.clearDimensionLabel();
invalidateDriverAndGUI(id);
return;
}
}
use of artisynth.core.probes.NumericProbeDriver in project artisynth_core by artisynth.
the class OutputNumericProbeEditor method renameProperty.
/**
* renames the current property by: a.) changing the name in myVariables b.)
* updating this change in all drivers
*/
public void renameProperty(String oldname, String newname) {
// first, rename the property in the variables list.
try {
NumericProbeVariable var = myVariables.get(oldname);
// System.out.println(var.getDimension());
myVariables.remove(oldname);
myVariables.put(newname, var);
} catch (Exception e) {
System.out.println(e.getMessage());
}
// then, rename it for each driver.
for (NumericProbeDriver driver : myDrivers) {
if (driver.isValid()) {
driver.renameVariable(oldname, newname);
System.out.println(oldname + " changed to " + newname);
int id = myDrivers.indexOf(driver);
getEqPane(id).setEqText(driver.getExpression());
getEqPane(id).updateAppearance();
System.out.println("setting driver " + id + " expression to " + driver.getExpression());
}
}
// System.out.println("Done renaming of Property");
}
Aggregations