Search in sources :

Example 6 with NumericProbeVariable

use of artisynth.core.probes.NumericProbeVariable 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 7 with NumericProbeVariable

use of artisynth.core.probes.NumericProbeVariable in project artisynth_core by artisynth.

the class InputNumericProbeEditor method renameInputVariable.

// 
// Called when a user renames a variable.
// first rename the variable in myVariables, and then
// go through all the drivers and rename
// 
public void renameInputVariable(String oldname, String newname) {
    try {
        NumericProbeVariable var = myVariables.get(oldname);
        myVariables.remove(oldname);
        myVariables.put(newname, var);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    for (NumericProbeDriver driver : myDrivers) {
        if (driver.renameVariable(oldname, newname)) {
            System.out.println("new name different... renaming");
        }
        int id = myDrivers.indexOf(driver);
        getEqPane(id).setEqText(driver.getExpression());
        System.out.println("setting driver expression to " + driver.getExpression());
    }
    super.updateGUI();
}
Also used : NumericProbeDriver(artisynth.core.probes.NumericProbeDriver) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable) IOException(java.io.IOException)

Example 8 with NumericProbeVariable

use of artisynth.core.probes.NumericProbeVariable in project artisynth_core by artisynth.

the class InputNumericProbeEditor method changeVariableDimension.

// 
// Called when a user changes the variable's dimension
// 
public void changeVariableDimension(String varname, int dimen) {
    NumericProbeVariable var = myVariables.get(varname);
    myVariables.remove(var);
    myVariables.put(varname, new NumericProbeVariable(dimen));
    for (NumericProbeDriver driver : myDrivers) {
        if (driver.usesVariable(varname)) {
            driver.setInvalid();
            AddEquationPane eqPane = eqList.get(myDrivers.indexOf(driver));
            eqPane.setEqText("");
            System.out.println("invalidated driver with expr [" + driver.getExpression() + "]");
        }
    }
// super.updateGUI();
}
Also used : NumericProbeDriver(artisynth.core.probes.NumericProbeDriver) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable)

Example 9 with NumericProbeVariable

use of artisynth.core.probes.NumericProbeVariable in project artisynth_core by artisynth.

the class NumericProbeEditor method load.

public void load(NumericProbeBase probe) {
    // when opening a probe we create local copies of:
    // 
    // 1) the properties
    // 2) the drivers
    // 3) the variables
    // 4) the variable dimensions (for input probes)
    NumericProbeDriver[] drivers = probe.getDrivers();
    myDrivers = new ArrayList<NumericProbeDriver>();
    for (int i = 0; i < drivers.length; i++) {
        myDrivers.add(new NumericProbeDriver(drivers[i]));
    }
    myProperties = new ArrayList<Property>();
    Property[] props = probe.getAttachedProperties();
    for (int i = 0; i < props.length; i++) {
        myProperties.add(props[i]);
    }
    myVariables = new LinkedHashMap<String, NumericProbeVariable>();
    for (Map.Entry<String, NumericProbeVariable> entry : probe.getVariables().entrySet()) {
        myVariables.put(entry.getKey(), new NumericProbeVariable(entry.getValue()));
    }
}
Also used : NumericProbeDriver(artisynth.core.probes.NumericProbeDriver) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 10 with NumericProbeVariable

use of artisynth.core.probes.NumericProbeVariable 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);
                }
            }
        }
    }
}
Also used : NumericProbeDriver(artisynth.core.probes.NumericProbeDriver) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable)

Aggregations

NumericProbeVariable (artisynth.core.probes.NumericProbeVariable)12 NumericProbeDriver (artisynth.core.probes.NumericProbeDriver)7 Property (maspack.properties.Property)4 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 AddComponentsCommand (artisynth.core.gui.editorManager.AddComponentsCommand)2 ArrayList (java.util.ArrayList)2 NumericConverter (maspack.properties.NumericConverter)2 Displayable (artisynth.core.gui.Displayable)1 Timeline (artisynth.core.gui.Timeline)1 ModelComponent (artisynth.core.modelbase.ModelComponent)1 NumericInputProbe (artisynth.core.probes.NumericInputProbe)1 NumericOutputProbe (artisynth.core.probes.NumericOutputProbe)1 CompositeProperty (maspack.properties.CompositeProperty)1 DoubleInterval (maspack.util.DoubleInterval)1