use of maspack.properties.Property in project artisynth_core by artisynth.
the class InputNumericProbeEditor method changeProperty.
/**
* this occurs when a current property in the list is valid, but a new one is
* selected to take its place. first we check if the same property has been
* selected. if this is the case, don't need to do anything. otherwise, if a
* new one is selected, we replace the old one, and invalidate the driver if
* and ONLY if the size has changed. (otherwise old driver will still be
* valid).
*/
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 {
System.out.println(myDrivers.get(idx).getExpression() + " invalidated");
myDrivers.get(idx).setInvalid();
getEqPane(idx).setEqText("");
}
updateGUI();
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class NumericProbeEditor method actionPerformed.
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
System.out.println("Numeric Probe Editor received event: " + cmd);
if (cmd.equals("Cancel")) {
dispose();
} else if (cmd.equals("Browse")) {
JFileChooser fileDialog = new JFileChooser();
if (attachedFile != null) {
fileDialog.setSelectedFile(attachedFile);
} else {
System.out.println(ArtisynthPath.getWorkingDir().getPath());
fileDialog.setCurrentDirectory(ArtisynthPath.getWorkingDir());
}
int retVal = fileDialog.showOpenDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
attachedFile = fileDialog.getSelectedFile();
attachedFileField.setValue(getAttachedFilePath(attachedFile));
}
} else if (cmd.equals("Invalidate")) {
AddPropertyPane pane = (AddPropertyPane) e.getSource();
pane.updateAppearance();
propPane.repaint();
refreshAddBtn();
} else if (cmd.equals("Done")) {
Property[] properties = new Property[propList.size()];
for (int i = 0; i < propList.size(); i++) {
String fullPropPath = propList.get(i).getPropPath();
// String compPath = splitPath(fullPropPath, true);
// String propPath = splitPath(fullPropPath, false);
// System.out.println(compPath);
// System.out.println(propPath);
Property prop = ComponentUtils.findProperty(myMain.getRootModel(), fullPropPath);
if (prop != null) {
properties[i] = prop;
}
}
} else if (cmd.equals("Change Focus")) {
AddPropertyPane focusedPane = (AddPropertyPane) e.getSource();
for (// disable edit for all other
AddPropertyPane pane : // disable edit for all other
propList) // properties
{
if (pane != focusedPane) {
pane.setEditable(false);
pane.updateAppearance();
}
}
// AddPropertyPane focusedPane = (AddPropertyPane)e.getSource();
// focusedPane.setEditable(true);
// focusedPane.refreshColor();
propPane.repaint();
}
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class ControlPanel method updateReferences.
@Override
public void updateReferences(boolean undo, Deque<Object> undoInfo) {
super.updateReferences(undo, undoInfo);
boolean changed = false;
if (undo) {
Object obj;
while ((obj = undoInfo.removeFirst()) != NULL_OBJ) {
WidgetRemoveInfo info = (WidgetRemoveInfo) obj;
myPanel.addPropertyWidget(info.myProp, info.myComp, info.myIdx);
changed = true;
}
} else {
// remove soft references which aren't in the hierarchy any more:
ArrayList<WidgetRemoveInfo> removeList = new ArrayList<WidgetRemoveInfo>();
for (int i = 0; i < myPanel.numWidgets(); i++) {
if (myPanel.getWidget(i) instanceof LabeledComponentBase) {
LabeledComponentBase widget = (LabeledComponentBase) myPanel.getWidget(i);
Property prop = myPanel.getWidgetProperty(widget);
if (prop instanceof GenericPropertyHandle) {
ModelComponent comp = ComponentUtils.getPropertyComponent(prop);
if (comp != null && !ComponentUtils.isConnected(this, comp)) {
removeList.add(new WidgetRemoveInfo(prop, widget, i));
changed = true;
}
} else {
// TODO - handle other cases
}
}
}
for (WidgetRemoveInfo info : removeList) {
myPanel.removeWidget(info.myComp);
}
undoInfo.addAll(removeList);
undoInfo.addLast(NULL_OBJ);
}
if (changed && myFrame != null) {
myFrame.pack();
}
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class InverseManager method configureExcitationProbe.
private void configureExcitationProbe(TrackingController myController) {
Property[] props = new Property[myController.getExciters().size()];
for (int i = 0; i < myController.getExciters().size(); i++) {
// XXX how to handle nested excitations?
props[i] = myController.getExciters().get(i).getProperty("excitation");
}
excitationOutProbe.setModel(myController.getMech());
excitationOutProbe.setOutputProperties(props);
excitationOutProbe.setAttachedFileName("excitations.txt");
if (excitationInput != null) {
excitationInput.setModel(myController.getMech());
excitationInput.setInputProperties(props);
excitationInput.setAttachedFileName("excitations_input.txt");
excitationInput.setActive(false);
}
}
use of maspack.properties.Property in project artisynth_core by artisynth.
the class InverseManager method configureTargetForceProbe.
private void configureTargetForceProbe(NumericProbeBase probe, ArrayList<ForceTarget> targets, String filename) {
// System.out.println ("configuring force probe");
ArrayList<Property> props = new ArrayList<Property>();
for (ForceTarget target : targets) {
props.add(target.getProperty("targetLambda"));
}
// probe.setModel(myController.getMech());
probe.setAttachedFileName(filename);
if (probe instanceof NumericInputProbe) {
((NumericInputProbe) probe).setInputProperties(props.toArray(new Property[props.size()]));
} else if (probe instanceof NumericOutputProbe) {
((NumericOutputProbe) probe).setOutputProperties(props.toArray(new Property[props.size()]));
}
if (probe instanceof NumericInputProbe) {
File file = probe.getAttachedFile();
if (file == null || !file.exists()) {
((NumericInputProbe) probe).loadEmpty();
probe.setActive(false);
} else {
try {
probe.load();
probe.setActive(true);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Aggregations