Search in sources :

Example 1 with CompositeProperty

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

the class CompositePropertyPanel method setCpropValueFromWidget.

// /**
// * Gets all the property widgets used by this widget.
// */
// private LabeledComponentBase[] collectWidgets() {
// LabeledComponentBase[] widgets;
// Component[] allWidgets = myPanel.getWidgets();
// if (allWidgets.length > 1) {
// // return all widgets except for the first, which is
// // the composite property type selector
// widgets = new LabeledComponentBase[allWidgets.length-1];
// for (int i=0; i<widgets.length; i++) {
// widgets[i] = (LabeledComponentBase)allWidgets[i+1];
// }
// }
// else {
// widgets = new LabeledComponentBase[0];
// }
// return widgets;
// }
/**
 * Sets the current composite property for a CompositePropertyPanel to the
 * type currently stored by that panel.
 */
private void setCpropValueFromWidget(Property cprop, CompositePropertyPanel cpanel) {
    cpanel.myCpropProperty = cprop;
    if (getCpropTypeFromProperty(cprop) != cpanel.myCpropType) {
        if (cpanel.myCpropType == Property.VoidValue) {
            System.out.println("Warning: void widget value for " + cprop.getName() + ", ignoring");
        } else {
            CompositeProperty protoCprop = createCprop(cpanel.myCpropType);
            // PropertyInfo info = cpanel.myCpropProperty.getInfo();
            cpanel.myCpropProperty.set(protoCprop);
        }
    }
    cpanel.rebuildPanel(/*setValuesFromWidgets=*/
    true);
}
Also used : CompositeProperty(maspack.properties.CompositeProperty)

Example 2 with CompositeProperty

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

the class CompositePropertyPanel method tryCreatingCpropFromPrototype.

/**
 * Try to create a prototype for a particular type of composite property by
 * cloning an instance (if there is one) in a host list.
 */
private CompositeProperty tryCreatingCpropFromPrototype(Class<?> type) {
    CompositeProperty protoCprop = null;
    EditingProperty eprop = (EditingProperty) myCpropProperty;
    HostList hostList = eprop.getHostList();
    Object[] values = hostList.getAllValues(eprop.getCell());
    for (int i = 0; i < values.length; i++) {
        if (type.isInstance(values[i]) && values[i] instanceof Clonable) {
            try {
                protoCprop = (CompositeProperty) ((Clonable) values[i]).clone();
            } catch (Exception e) {
                System.out.println("Warning: clone failed for " + values[i].getClass());
            }
            if (protoCprop != null) {
                break;
            }
        }
    }
    return protoCprop;
}
Also used : EditingProperty(maspack.properties.EditingProperty) Clonable(maspack.util.Clonable) HostList(maspack.properties.HostList) CompositeProperty(maspack.properties.CompositeProperty) InternalErrorException(maspack.util.InternalErrorException)

Example 3 with CompositeProperty

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

the class ComponentPropertyField method valueToTextArray.

protected String[] valueToTextArray(Object value) {
    ModelComponent comp = getComponent(value);
    RootModel root = myMain.getRootModel();
    String compStr = "/";
    String propStr = "";
    if (root == null || comp == null) {
        return new String[] { "", "" };
    }
    if (value instanceof ModelComponent) {
        compStr = 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);
        int idx = path.indexOf(':');
        // default to root
        propStr = path;
        if (idx >= 0) {
            compStr = path.substring(0, idx);
            if (idx < path.length() - 1) {
                propStr = path.substring(idx + 1);
            }
        }
    } else {
        throw new InternalErrorException("Unknown value type: " + value.getClass());
    }
    return new String[] { compStr, propStr };
}
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 4 with CompositeProperty

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

the class ComponentPropertyField method getPropertyForComposite.

private Property getPropertyForComposite(CompositeProperty cprop) {
    PropertyInfo info = cprop.getPropertyInfo();
    HasProperties host = cprop.getPropertyHost();
    Property prop = host.getProperty(info.getName());
    if (prop == null) {
        throw new InternalErrorException("Property not found in composite property host");
    }
    return prop;
}
Also used : HasProperties(maspack.properties.HasProperties) InternalErrorException(maspack.util.InternalErrorException) PropertyInfo(maspack.properties.PropertyInfo) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property)

Example 5 with CompositeProperty

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

the class CompositePropertyPanel method createWidgetProps.

/**
 * Create properties for the widgets controlling the property values of the
 * current composite property.
 */
private LinkedList<Property> createWidgetProps() {
    if (myCpropProperty instanceof EditingProperty) {
        EditingProperty eprop = (EditingProperty) myCpropProperty;
        HostList hostList = eprop.getHostList();
        PropTreeCell cell = eprop.getCell();
        cell.removeAllChildren();
        CompositeProperty cprop = createCprop(myCpropType);
        LinkedList<Property> props = PropertyUtils.createProperties(cprop);
        for (Property prop : props) {
            cell.addChild(new PropTreeCell(prop.getInfo(), prop.get()));
        }
        hostList.setSubHostsFromValue(cell);
        hostList.saveBackupValues(cell);
        hostList.getCommonValues(cell, /*live=*/
        true);
        cell.setValue(CompositeProperty.class);
        return EditingProperty.createProperties(cell, hostList, /*live=*/
        true);
    } else {
        myCprop = (CompositeProperty) myCpropProperty.get();
        return PropertyUtils.createProperties(myCprop);
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) PropTreeCell(maspack.properties.PropTreeCell) HostList(maspack.properties.HostList) InheritableProperty(maspack.properties.InheritableProperty) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty) CompositeProperty(maspack.properties.CompositeProperty)

Aggregations

CompositeProperty (maspack.properties.CompositeProperty)8 InternalErrorException (maspack.util.InternalErrorException)5 Property (maspack.properties.Property)4 ModelComponent (artisynth.core.modelbase.ModelComponent)3 EditingProperty (maspack.properties.EditingProperty)3 RootModel (artisynth.core.workspace.RootModel)2 HostList (maspack.properties.HostList)2 CompositeComponent (artisynth.core.modelbase.CompositeComponent)1 HasProperties (maspack.properties.HasProperties)1 InheritableProperty (maspack.properties.InheritableProperty)1 PropTreeCell (maspack.properties.PropTreeCell)1 PropertyInfo (maspack.properties.PropertyInfo)1 Clonable (maspack.util.Clonable)1