Search in sources :

Example 41 with Property

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

the class ComponentPropertyField method valueToText.

protected String valueToText(Object value) {
    ModelComponent comp = getComponent(value);
    RootModel root = myMain.getRootModel();
    if (root == null || comp == null) {
        return "";
    }
    if (value instanceof ModelComponent) {
        return ComponentUtils.getPathName(root, comp);
    } else if (value instanceof Property) {
        Property prop = (Property) value;
        boolean excludeLeaf = (myPropertySelector != null && !(prop.get() instanceof CompositeProperty));
        String path = ComponentUtils.getPropertyPathName(prop, root, false);
        if (!path.contains(":")) {
            // root component + property
            path = "/:" + path;
        }
        return path;
    } else {
        throw new InternalErrorException("Unknown value type: " + value.getClass());
    }
// String text = ComponentUtils.getPathName(root, comp);
// if (value instanceof Property)
// { Property prop = (Property)value;
// String propPath = getPropertyPath (prop, myPropertySelector != null);
// if (propPath.length() > 0)
// { text += "/" + propPath;
// }
// }
// return text;
}
Also used : RootModel(artisynth.core.workspace.RootModel) ModelComponent(artisynth.core.modelbase.ModelComponent) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) CompositeProperty(maspack.properties.CompositeProperty)

Example 42 with Property

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

the class ComponentPropertyField method setValueFromPropertySelector.

private void setValueFromPropertySelector() {
    if (!myPropertyMask) {
        String propName = (String) myPropertySelector.getValue();
        HasProperties host = getHost();
        if (propName.equals(nullString)) {
            Object value = getValueForHost();
            System.out.println("new value");
            updateValueAndDisplay(value);
            return;
        }
        if (host == null) {
            throw new InternalErrorException("Current property host is null");
        }
        Property prop = host.getProperty(propName);
        if (prop == null) {
            throw new InternalErrorException("Current property host does not contain property " + propName);
        }
        updateValueAndDisplay(prop);
    }
}
Also used : HasProperties(maspack.properties.HasProperties) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property)

Example 43 with Property

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

the class PropertyField method setNumericOnly.

/**
 * Sets this field to accept only numeric properties (i.e., those whose
 * values can be mapped onto a vector).
 *
 * @param enable
 * if true, enables only numeric properties
 */
public void setNumericOnly(boolean enable) {
    if (myNumericOnly != enable) {
        myNumericOnly = enable;
        // clear to ensure property selection list will be rebuilt ...
        myLastSelectorHost = null;
        if (enable) {
            Property prop = getProperty();
            if (prop != null && !isNumeric(prop.getInfo())) {
                updateValueAndDisplay(getValueForHost());
                return;
            }
        }
        // will redo property selector entries
        updatePropertySelector();
    }
}
Also used : Property(maspack.properties.Property)

Example 44 with Property

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

the class ForceTargetDemo method addConForceProbe.

public void addConForceProbe(double duration, double interval) {
    ArrayList<Property> props = new ArrayList<Property>();
    for (BodyConnector rbc : mech.bodyConnectors()) {
        if (rbc.isEnabled() && rbc.getProperty("activation") != null) {
            props.add(rbc.getProperty("activation"));
        }
    }
    Property[] proparray = new Property[props.size()];
    for (int i = 0; i < props.size(); i++) {
        proparray[i] = props.get(i);
    }
    String name = "conforce";
    NumericOutputProbe p = new NumericOutputProbe(proparray, interval);
    p.setStartStopTimes(0, duration);
    p.setName(name);
    p.setAttachedFileName(name + "_output.txt");
    p.setDefaultDisplayRange(-0.1, 0.1);
    addOutputProbe(p);
}
Also used : ArrayList(java.util.ArrayList) NumericOutputProbe(artisynth.core.probes.NumericOutputProbe) Property(maspack.properties.Property) BodyConnector(artisynth.core.mechmodels.BodyConnector) TargetPoint(artisynth.core.inverse.TargetPoint)

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