Search in sources :

Example 1 with NumericConverter

use of maspack.properties.NumericConverter in project artisynth_core by artisynth.

the class InputNumericProbeEditor method addProperty.

/**
 * Called when a valid property has been selected for the first time. A
 * property is null before this point. so we set the property at the
 * corresponding index in the ArrayList. Then we automatically create an
 * input variable to go along with this property. The GUI elements are added
 * accordingly for the new input vector. The driver at the current index is
 * also created with the input variable name as its expression.
 *
 * @param index
 * index of property (also of driver, since they should be in sync)
 * @param prop
 * the selected property.
 */
public void addProperty(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);
    AddVectorPane newVec = new AddVectorPane(this, varname);
    newVec.setDim(var.getDimension());
    addVectorGUI(newVec);
    NumericProbeDriver driver = new NumericProbeDriver();
    driver.setExpression(varname, myVariables);
    myDrivers.set(index, driver);
    updateGUI();
}
Also used : NumericConverter(maspack.properties.NumericConverter) NumericProbeDriver(artisynth.core.probes.NumericProbeDriver) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable)

Example 2 with NumericConverter

use of maspack.properties.NumericConverter in project artisynth_core by artisynth.

the class OutputNumericProbeEditor method addProperty.

public boolean addProperty(int index, Property prop) {
    myProperties.set(index, prop);
    AddPropertyPane propPane = propList.get(index);
    String varname = propPane.getPropNameFieldText();
    NumericConverter conv = new NumericConverter(prop.get());
    NumericProbeVariable var = new NumericProbeVariable(conv.getDimension());
    myVariables.put(varname, var);
    // list. If so, use that:
    if (myDrivers.size() > 0 && !myDrivers.get(myDrivers.size() - 1).isValid()) {
        int id = myDrivers.size() - 1;
        AddEquationPane eqn = eqList.get(id);
        eqn.setEqText(varname);
        changeExpression(id, varname);
        updateGUI();
        return false;
    } else {
        // otherwise, add a new driver
        NumericProbeDriver driver = new NumericProbeDriver();
        // System.out.println("addProperty; var name= "+varname);
        driver.setExpression(varname, myVariables);
        // add it at the end of list
        myDrivers.add(myDrivers.size(), driver);
        // add an equation pane for it
        AddEquationPane newEq = createEquationPane(driver.getExpression());
        newEq.setDimensionLabel(driver.getOutputSize());
        newEq.updateAppearance();
        addEquationGUI(newEq);
        updateGUI();
        return true;
    }
}
Also used : NumericConverter(maspack.properties.NumericConverter) NumericProbeDriver(artisynth.core.probes.NumericProbeDriver) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable)

Example 3 with NumericConverter

use of maspack.properties.NumericConverter in project artisynth_core by artisynth.

the class NumericInputProbe method setInputProperties.

// public NumericInputProbe (
// Property[] props, ModelComponent e, double ymin, double ymax) {
// this();
// setModelFromComponent (e);
// setInputProperties (props);
// setDefaultDisplayRange (ymin, ymax);
// }
public void setInputProperties(Property[] props) {
    // set up default variable and driver list and pass this to
    // the regular set routine
    String[] driverExpressions = new String[props.length];
    String[] variableNames = new String[props.length];
    int[] variableDimensions = new int[props.length];
    for (int i = 0; i < props.length; i++) {
        NumericConverter numInfo = null;
        try {
            numInfo = new NumericConverter(props[i].get());
        } catch (Exception e) {
            throw new IllegalArgumentException("property '" + props[i].getInfo().getName() + "' is not numeric");
        }
        driverExpressions[i] = "V" + i;
        variableNames[i] = "V" + i;
        variableDimensions[i] = numInfo.getDimension();
    }
    set(props, driverExpressions, variableNames, variableDimensions);
}
Also used : NumericConverter(maspack.properties.NumericConverter)

Example 4 with NumericConverter

use of maspack.properties.NumericConverter in project artisynth_core by artisynth.

the class NumericInputProbe method set.

public void set(Property[] props, String[] driverExpressions, String[] variableNames, int[] variableDimensions, PlotTraceInfo[] traceInfos) {
    if (props.length != driverExpressions.length) {
        throw new IllegalArgumentException("number of drivers must equal number of properties");
    }
    if (variableNames.length != variableDimensions.length) {
        throw new IllegalArgumentException("number of channels must equal number of variable names");
    }
    NumericConverter[] newConverters = createConverters(props);
    LinkedHashMap<String, NumericProbeVariable> newVariables = new LinkedHashMap<String, NumericProbeVariable>();
    int newVsize = 0;
    for (int i = 0; i < variableNames.length; i++) {
        String name = variableNames[i];
        if (name == null || newVariables.get(name) != null) {
            throw new IllegalArgumentException("null or repeated variable name '" + name + "'");
        }
        if (!isValidVariableName(name)) {
            throw new IllegalArgumentException("variable name '" + name + "' is not a valid variable name");
        }
        if (variableDimensions[i] <= 0) {
            throw new IllegalArgumentException("channel sizes must be greater than 0");
        }
        newVariables.put(name, new NumericProbeVariable(variableDimensions[i]));
        newVsize += variableDimensions[i];
    }
    ArrayList<NumericProbeDriver> newDrivers = createDrivers(driverExpressions, newVariables);
    myPropList = createPropertyList(props);
    myConverters = newConverters;
    // myPropValues = new double[props.length][];
    myVariables = newVariables;
    myDrivers = newDrivers;
    if (myNumericList == null || myVsize != newVsize) {
        myVsize = newVsize;
        myNumericList = new NumericList(myVsize);
        myNumericList.setInterpolation(myInterpolation);
        myTmpVec = new VectorNd(myVsize);
    }
    if (traceInfos != null) {
        myPlotTraceManager.rebuild(getPropsOrDimens(), traceInfos);
    } else {
        myPlotTraceManager.rebuild(getPropsOrDimens());
    }
    if (myLegend != null) {
        myLegend.rebuild();
    }
}
Also used : NumericConverter(maspack.properties.NumericConverter) NumericList(maspack.interpolation.NumericList) VectorNd(maspack.matrix.VectorNd)

Example 5 with NumericConverter

use of maspack.properties.NumericConverter in project artisynth_core by artisynth.

the class NumericOutputProbe method set.

public void set(Property[] props, String[] driverExpressions, String[] variableNames, PlotTraceInfo[] traceInfos) {
    if (variableNames.length != props.length) {
        throw new IllegalArgumentException("Number of variable names does not equal the number of properties");
    }
    NumericConverter[] newConverters = createConverters(props);
    LinkedHashMap<String, NumericProbeVariable> newVariables = new LinkedHashMap<String, NumericProbeVariable>();
    for (int i = 0; i < props.length; i++) {
        String name = variableNames[i];
        if (name == null || newVariables.get(name) != null) {
            throw new IllegalArgumentException("null or repeated variable name '" + name + "'");
        }
        if (!isValidVariableName(name)) {
            throw new IllegalArgumentException("variable name '" + name + "' is not a valid variable name");
        }
        newVariables.put(name, new NumericProbeVariable(newConverters[i].getDimension()));
    }
    ArrayList<NumericProbeDriver> newDrivers = createDrivers(driverExpressions, newVariables);
    myVsize = 0;
    for (int i = 0; i < newDrivers.size(); i++) {
        myVsize += newDrivers.get(i).getOutputSize();
    }
    myDrivers = newDrivers;
    myPropList = createPropertyList(props);
    myVariables = newVariables;
    myConverters = newConverters;
    myNumericList = new NumericList(myVsize);
    if (traceInfos != null) {
        myPlotTraceManager.rebuild(getPropsOrDimens(), traceInfos);
    } else {
        myPlotTraceManager.rebuild(getPropsOrDimens());
    }
    if (myLegend != null) {
        myLegend.rebuild();
    }
}
Also used : NumericConverter(maspack.properties.NumericConverter) NumericList(maspack.interpolation.NumericList)

Aggregations

NumericConverter (maspack.properties.NumericConverter)6 NumericProbeDriver (artisynth.core.probes.NumericProbeDriver)2 NumericProbeVariable (artisynth.core.probes.NumericProbeVariable)2 NumericList (maspack.interpolation.NumericList)2 NumericProbePanel (artisynth.core.gui.NumericProbePanel)1 IOException (java.io.IOException)1 Interpolation (maspack.interpolation.Interpolation)1 VectorNd (maspack.matrix.VectorNd)1 Property (maspack.properties.Property)1 PyString (org.python.core.PyString)1 PyStringMap (org.python.core.PyStringMap)1