Search in sources :

Example 1 with AddComponentsCommand

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);
    }
}
Also used : Displayable(artisynth.core.gui.Displayable) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AddComponentsCommand(artisynth.core.gui.editorManager.AddComponentsCommand) ModelComponent(artisynth.core.modelbase.ModelComponent) NumericInputProbe(artisynth.core.probes.NumericInputProbe) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Property(maspack.properties.Property)

Example 2 with AddComponentsCommand

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);
    }
}
Also used : NumericProbeVariable(artisynth.core.probes.NumericProbeVariable) AddComponentsCommand(artisynth.core.gui.editorManager.AddComponentsCommand) ArrayList(java.util.ArrayList) NumericOutputProbe(artisynth.core.probes.NumericOutputProbe) DoubleInterval(maspack.util.DoubleInterval) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Property(maspack.properties.Property)

Example 3 with AddComponentsCommand

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?
}
Also used : SelectionManager(artisynth.core.gui.selectionManager.SelectionManager) MutableCompositeComponent(artisynth.core.modelbase.MutableCompositeComponent) AddComponentsCommand(artisynth.core.gui.editorManager.AddComponentsCommand) InternalErrorException(maspack.util.InternalErrorException) NumericOutputProbe(artisynth.core.probes.NumericOutputProbe) WayPointProbe(artisynth.core.probes.WayPointProbe) Probe(artisynth.core.probes.Probe) NumericInputProbe(artisynth.core.probes.NumericInputProbe) InternalErrorException(maspack.util.InternalErrorException) IOException(java.io.IOException)

Aggregations

AddComponentsCommand (artisynth.core.gui.editorManager.AddComponentsCommand)3 NumericInputProbe (artisynth.core.probes.NumericInputProbe)2 NumericOutputProbe (artisynth.core.probes.NumericOutputProbe)2 NumericProbeVariable (artisynth.core.probes.NumericProbeVariable)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Property (maspack.properties.Property)2 Displayable (artisynth.core.gui.Displayable)1 SelectionManager (artisynth.core.gui.selectionManager.SelectionManager)1 ModelComponent (artisynth.core.modelbase.ModelComponent)1 MutableCompositeComponent (artisynth.core.modelbase.MutableCompositeComponent)1 Probe (artisynth.core.probes.Probe)1 WayPointProbe (artisynth.core.probes.WayPointProbe)1 DoubleInterval (maspack.util.DoubleInterval)1 InternalErrorException (maspack.util.InternalErrorException)1