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();
}
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;
}
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;
}
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);
}
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;
}
Aggregations