use of artisynth.core.gui.editorManager.AddComponentsCommand in project artisynth_core by artisynth.
the class InputNumericProbeEditor method setInputProbe.
// //
// // Called when a user adds an input property
// //
// public void addInputProbeProperty (int index, Property prop)
// {
// myProperties.set (index, prop);
//
// NumericConverter conv = new NumericConverter(prop.get());
// String varname = getUniqueVariableName(INPUT_PREFIX);
// NumericProbeVariable var = new NumericProbeVariable(conv.getDimension());
// myVariables.put (varname, var);
// NumericProbeDriver driver = new NumericProbeDriver();
// driver.setExpression (varname, myVariables);
// myDrivers.set (index, driver);
//
// AddVectorPane newVec = new AddVectorPane(this, varname);
// newVec.setDim(var.getDimension());
// addVectorGUI(newVec);
// super.updateGUI();
// }
private void setInputProbe() {
ArrayList<String> variableNames = new ArrayList<String>();
ArrayList<Integer> variableDims = new ArrayList<Integer>();
for (Map.Entry<String, NumericProbeVariable> entry : myVariables.entrySet()) {
variableNames.add(entry.getKey());
variableDims.add(entry.getValue().getDimension());
System.out.println(entry.getKey() + " -- " + entry.getValue());
}
int[] varDimsInt = new int[variableDims.size()];
for (int i = 0; i < variableDims.size(); i++) {
varDimsInt[i] = variableDims.get(i);
// System.out.println("size of V="+variableDims.get(i));
}
NumericInputProbe probeToSet;
if (oldProbe == null) {
ModelComponent refComp = ComponentUtils.getPropertyComponent(myProperties.get(0));
probeToSet = new NumericInputProbe(refComp);
} else {
probeToSet = oldProbe;
}
probeToSet.set(myProperties.toArray(new Property[0]), getDriverExpressions(), variableNames.toArray(new String[0]), varDimsInt);
probeToSet.setStartTime(startTimeField.getDoubleValue());
probeToSet.setStopTime(endTimeField.getDoubleValue());
probeToSet.setScale(scaleField.getDoubleValue());
probeToSet.setName(probeNameField.getStringValue());
String attachedFilePath = attachedFileField.getStringValue();
if (attachedFilePath != null) {
if (attachedFilePath.equals("") || !attachedInputFileValid(attachedFilePath, null)) {
attachedFilePath = null;
}
}
if (attachedFilePath != null) {
probeToSet.setAttachedFileName(attachedFilePath);
try {
probeToSet.load();
((Displayable) probeToSet).updateDisplays();
} catch (IOException e) {
System.err.println("Couldn't load probe ");
e.printStackTrace();
probeToSet.setAttachedFileName(null);
}
} else {
probeToSet.setAttachedFileName(null);
if (probeToSet.getNumericList().isEmpty()) {
// add knots at beginning and end
if (probeToSet.isSettable()) {
probeToSet.setData(probeToSet.getStartTime());
probeToSet.setData(probeToSet.getStopTime());
} else {
probeToSet.loadEmpty();
}
}
}
if (oldProbe == null) {
AddComponentsCommand cmd = new AddComponentsCommand("add input probe", probeToSet, myMain.getRootModel().getInputProbes());
myMain.getUndoManager().saveStateAndExecute(cmd);
}
}
use of artisynth.core.gui.editorManager.AddComponentsCommand in project artisynth_core by artisynth.
the class OutputNumericProbeEditor method setOutputProbe.
private void setOutputProbe() {
ArrayList<String> variableNames = new ArrayList<String>();
for (Map.Entry<String, NumericProbeVariable> entry : myVariables.entrySet()) {
variableNames.add(entry.getKey());
System.out.println("variable: " + entry.getKey() + " added to list");
}
for (Property prop : myProperties) {
System.out.println("property " + prop.getName() + " found");
}
// System.out.println("myProps size ="+myProperties.size());
// System.out.println("myVars size ="+variableNames.size());
NumericOutputProbe probeToSet;
if (oldProbe == null) {
probeToSet = new NumericOutputProbe();
} else {
probeToSet = oldProbe;
}
probeToSet.set(myProperties.toArray(new Property[0]), getDriverExpressions(), variableNames.toArray(new String[0]));
probeToSet.setStartTime(startTimeField.getDoubleValue());
probeToSet.setStopTime(endTimeField.getDoubleValue());
probeToSet.setName(probeNameField.getStringValue());
probeToSet.setUpdateInterval(intervalField.getDoubleValue());
if (!rangeField.valueIsVoid()) {
DoubleInterval range = rangeField.getRangeValue();
probeToSet.setDefaultDisplayRange(range.getLowerBound(), range.getUpperBound());
}
// probeToSet.setDefaultDisplayRange(
// dispLowerField.getDoubleValue(), dispUpperField.getDoubleValue());
probeToSet.setAttachedFileName(attachedFileField.getText());
if (oldProbe == null) {
AddComponentsCommand cmd = new AddComponentsCommand("add output probe", probeToSet, myMain.getRootModel().getOutputProbes());
myMain.getUndoManager().saveStateAndExecute(cmd);
// System.out.println("track index: "+probeToSet.getTrack());
// myMain.getRootModel().addOutputProbe(probeToSet);
// myMain.getTimeline().addProbe(probeToSet);
}
}
use of artisynth.core.gui.editorManager.AddComponentsCommand in project artisynth_core by artisynth.
the class ProbeInfo method duplicateProbe.
/**
* duplicate the probe
*/
private void duplicateProbe() {
// don't need to supply a copyMap to copy because it won't be used
Probe oldProbe = getProbe();
if (!(oldProbe.getParent() instanceof MutableCompositeComponent)) {
throw new InternalErrorException("Probe's parent is not editable");
}
Probe newProbe = null;
try {
newProbe = (Probe) getProbe().clone();
} catch (Exception e) {
e.printStackTrace();
throw new InternalErrorException("Cannot clone probe of type " + getProbe().getClass());
}
// set start time so that probe follows right after this one ...
double startTime = getProbe().getStartTime();
double stopTime = getProbe().getStopTime();
newProbe.setStartTime(stopTime);
newProbe.setStopTime(stopTime + (stopTime - startTime));
AddComponentsCommand cmd = new AddComponentsCommand("duplicate probe", newProbe, (MutableCompositeComponent) oldProbe.getParent());
getMain().getUndoManager().saveStateAndExecute(cmd);
SelectionManager selman = getMain().getSelectionManager();
selman.removeSelected(oldProbe);
selman.addSelected(newProbe);
// myController.deselectAllProbes(); XXX need to fix?
}
Aggregations