Search in sources :

Example 31 with Property

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

the class OutputNumericProbeEditor method changeProperty.

public void changeProperty(Property newprop, int idx) {
    if (newprop.equals(myProperties.get(idx))) {
        // System.out.println("new and old the same. don't need to replace");
        return;
    }
    System.out.println("replacing property @ index " + idx);
    Property oldprop = myProperties.remove(idx);
    myProperties.add(idx, newprop);
    if (getPropDim(newprop) == getPropDim(oldprop)) {
        System.out.println("new prop has same dim as old. keep driver");
    } else {
    // the size is different, but there is a chance that it could work as
    // long as
    // the equation is valid- requirement is less stringent than
    // input probe since the size only matters during the operation, and
    // not the output
    }
    updateGUI();
}
Also used : Property(maspack.properties.Property)

Example 32 with Property

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

the class NumericInputProbe method getPropsOrDimens.

/**
 * Returns an array of Objects that represents, for each input variable,
 * either the property that variable maps to (if any), or the dimension
 * of that variable. This information is used by the plotTraceManager.
 *
 * @return property or dimension information for input variables
 */
protected Object[] getPropsOrDimens() {
    Object[] propsOrDimens = new Object[myVariables.size()];
    int idx = 0;
    for (String varname : myVariables.keySet()) {
        Property prop = null;
        for (int k = 0; k < myDrivers.size(); k++) {
            String singleVariable = myDrivers.get(k).getSingleVariable();
            if (singleVariable != null && singleVariable.equals(varname)) {
                prop = myPropList.get(k);
                break;
            }
        }
        if (prop != null) {
            propsOrDimens[idx++] = prop;
        } else {
            propsOrDimens[idx++] = myVariables.get(varname).getDimension();
        }
    }
    return propsOrDimens;
}
Also used : Property(maspack.properties.Property)

Example 33 with Property

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

the class NumericProbeBase method clone.

public Object clone() throws CloneNotSupportedException {
    NumericProbeBase probe = (NumericProbeBase) super.clone();
    probe.myNumericList = (NumericList) myNumericList.clone();
    probe.myInterpolation = new Interpolation(myInterpolation);
    if (myVariables != null) {
        // make a deep copy of the variable list
        probe.myVariables = new LinkedHashMap<String, NumericProbeVariable>();
        for (Map.Entry<String, NumericProbeVariable> entry : myVariables.entrySet()) {
            probe.myVariables.put(entry.getKey(), new NumericProbeVariable(entry.getValue()));
        }
    }
    if (myDrivers != null) {
        probe.myDrivers = new ArrayList<NumericProbeDriver>();
        for (NumericProbeDriver oldDriver : myDrivers) {
            NumericProbeDriver driver = new NumericProbeDriver();
            try {
                driver.setExpression(oldDriver.getExpression(), probe.myVariables);
            } catch (Exception e) {
                throw new InternalErrorException("Illegal driver expression '" + oldDriver.getExpression() + "': " + e.getMessage());
            }
            probe.myDrivers.add(driver);
        }
    }
    if (myPropList != null) {
        probe.myPropList = (ArrayList<Property>) myPropList.clone();
    }
    if (myConverters != null) {
        probe.myConverters = new NumericConverter[myConverters.length];
        for (int i = 0; i < myConverters.length; i++) {
            probe.myConverters[i] = new NumericConverter(myConverters[i]);
        }
    }
    // clear the displays because these are lazily allocated and
    // we don't want them reused
    probe.mySmallDisplay = null;
    probe.myDisplays = new ArrayList<NumericProbePanel>();
    // attached file should also not be brought into clone
    probe.myAttachedFileName = null;
    return probe;
}
Also used : NumericProbePanel(artisynth.core.gui.NumericProbePanel) PyString(org.python.core.PyString) IOException(java.io.IOException) Interpolation(maspack.interpolation.Interpolation) NumericConverter(maspack.properties.NumericConverter) PyStringMap(org.python.core.PyStringMap) Property(maspack.properties.Property)

Example 34 with Property

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

the class PropertyWidgetDialog method updateRange.

private void updateRange(ModelComponent comp, PropertyInfo info) {
    Property prop = comp.getProperty(info.getName());
    if (prop == null) {
        throw new InternalErrorException("Cannot create property '" + info.getName() + " for component type " + comp.getClass());
    }
    DoubleInterval newRange = getDefaultRange(prop);
    double currentValue = ((Number) prop.get()).doubleValue();
    if (currentValue < newRange.getLowerBound()) {
        newRange.setLowerBound(currentValue);
    } else if (currentValue > newRange.getUpperBound()) {
        newRange.setUpperBound(currentValue);
    }
    myRangeField.setValue(newRange);
}
Also used : DoubleInterval(maspack.util.DoubleInterval) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) EditingProperty(maspack.properties.EditingProperty) Property(maspack.properties.Property)

Example 35 with Property

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

the class PropertyWidgetDialog method createWidget.

public LabeledComponentBase createWidget() {
    if (getModelComponent() == null || getPropertyInfo() == null) {
        throw new IllegalStateException("component and/or property not set");
    }
    LabeledComponentBase widget;
    ModelComponent comp = getModelComponent();
    String propPath = getPropertyPath();
    Property prop = comp.getProperty(propPath);
    if (prop == null) {
        throw new InternalErrorException("property '" + propPath + "' not found for component " + comp.getClass());
    }
    if (CompositeProperty.class.isAssignableFrom(prop.getInfo().getValueClass())) {
        // replace prop with an EditingProperty, since
        // CompositePropertyWidgets only work properly with those
        prop = createEditingProperty(prop);
    }
    if (isSliderSelected()) {
        widget = PropertyWidget.create(prop, getSliderMinimum(), getSliderMaximum());
    } else {
        widget = PropertyWidget.create(prop);
    }
    String labelText = myLabelTextField.getStringValue();
    widget.setLabelText(labelText);
    if (!myLabelFontColorSelector.valueIsNull()) {
        widget.setLabelFontColor(myLabelFontColorSelector.getColor());
    }
    if (!myBackgroundColorSelector.valueIsNull()) {
        widget.setBackgroundColor(myBackgroundColorSelector.getColor());
    }
    return widget;
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) LabeledComponentBase(maspack.widgets.LabeledComponentBase) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) EditingProperty(maspack.properties.EditingProperty) Property(maspack.properties.Property)

Aggregations

Property (maspack.properties.Property)44 CompositeProperty (maspack.properties.CompositeProperty)15 EditingProperty (maspack.properties.EditingProperty)15 InheritableProperty (maspack.properties.InheritableProperty)10 ModelComponent (artisynth.core.modelbase.ModelComponent)9 IOException (java.io.IOException)7 InternalErrorException (maspack.util.InternalErrorException)7 ArrayList (java.util.ArrayList)6 LabeledComponentBase (maspack.widgets.LabeledComponentBase)6 NumericInputProbe (artisynth.core.probes.NumericInputProbe)5 HasProperties (maspack.properties.HasProperties)5 NumericOutputProbe (artisynth.core.probes.NumericOutputProbe)4 NumericProbeVariable (artisynth.core.probes.NumericProbeVariable)4 RootModel (artisynth.core.workspace.RootModel)3 Component (java.awt.Component)3 Point (java.awt.Point)3 File (java.io.File)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Timeline (artisynth.core.gui.Timeline)2