Search in sources :

Example 11 with Property

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();
}
Also used : Property(maspack.properties.Property)

Example 12 with Property

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();
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property)

Example 13 with Property

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();
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) LabeledComponentBase(maspack.widgets.LabeledComponentBase) GenericPropertyHandle(maspack.properties.GenericPropertyHandle) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty) Point(java.awt.Point)

Example 14 with Property

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);
    }
}
Also used : Property(maspack.properties.Property) Point(artisynth.core.mechmodels.Point) WayPoint(artisynth.core.probes.WayPoint)

Example 15 with Property

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();
            }
        }
    }
}
Also used : NumericInputProbe(artisynth.core.probes.NumericInputProbe) ArrayList(java.util.ArrayList) NumericOutputProbe(artisynth.core.probes.NumericOutputProbe) IOException(java.io.IOException) Property(maspack.properties.Property) File(java.io.File)

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