Search in sources :

Example 1 with NumericProbeVariable

use of artisynth.core.probes.NumericProbeVariable in project artisynth_core by artisynth.

the class InputNumericProbeEditor method actionPerformed.

/**
 * Event handler. Goes through the input probe specific commands first, and
 * if its not specifically for an input probe, send it up to the parent class
 */
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand() == "Add") {
        String name = getUniqueVariableName(INPUT_PREFIX);
        AddVectorPane newVec = new AddVectorPane(this, name);
        addVectorGUI(newVec);
        addInputVariable(name, 1);
        increaseFrameSize();
    } else if (e.getActionCommand() == "Delete Channel") {
        AddVectorPane vecPane = (AddVectorPane) e.getSource();
        System.out.println("Deleting Channel GUI ID" + e.getID());
        String name = vecPane.getChannelName();
        revalidateDrivers(name);
        deleteInputVariable(name);
        removeChannelGUI(vecPane);
    } else if (e.getActionCommand() == "Add Property") {
        addBlankInputProbeProperty();
        increaseFrameSize();
    } else if (e.getActionCommand() == "Delete Property") {
        AddPropertyPane pane = (AddPropertyPane) e.getSource();
        int index = propList.indexOf(pane);
        System.out.println("Deleting Property ID" + index);
        removePropertyGUI(index);
        removeEquationGUI(index);
        deleteProperty(index);
    } else if (e.getActionCommand() == "PropSelected") {
        AddPropertyPane propPane = (AddPropertyPane) e.getSource();
        int index = propList.indexOf(propPane);
        System.out.println("prop selected from prop pane #: " + index);
        String propPath = propPane.getPropPath();
        Property prop = getProp(propPath);
        updateProperty(index, prop);
        increaseFrameSize();
    } else if (e.getActionCommand() == "blank") {
        // happens when we make a non-selection
        AddPropertyPane propPane = (AddPropertyPane) e.getSource();
        int index = propList.indexOf(propPane);
        if (index < 0)
            return;
        System.out.println("trying to get eq at index " + index);
        AddEquationPane eqPane = getEqPane(index);
        if (eqPane != null) {
            try {
                // myProperties.set(index, null);
                myDrivers.get(index).setInvalid();
            } catch (Exception exp) {
                System.out.println(exp.getMessage());
            }
            eqPane.setEnabled(false);
            eqPane.setEqText("");
        }
    } else if (e.getActionCommand() == "Resized") {
        AddVectorPane vecPane = (AddVectorPane) e.getSource();
        NumericProbeVariable var = myVariables.get(vecPane.getChannelName());
        if (var != null) {
            changeVariableDimension(vecPane.getChannelName(), vecPane.getDim());
            // myVariables.get(vecPane.getChannelName()).getDimension());
            System.out.println("new dim: " + vecPane.getDim());
        }
    } else if (e.getActionCommand() == "Renamed") {
        AddVectorPane vecPane = (AddVectorPane) e.getSource();
        String newName = vecPane.getChannelName();
        String oldName = vecPane.getOldName();
        for (AddVectorPane pane : probeChannels) {
            if (!pane.equals(vecPane)) {
                if (newName.compareTo(pane.getChannelName()) == 0) {
                    // check to make sure there are no duplicates
                    JOptionPane.showMessageDialog(this, "Name already exists!", "Error!", JOptionPane.ERROR_MESSAGE);
                    newName = vecPane.getOldName();
                // so in this case, the 'new' name is the same as old, so
                // effectively we don't make any changes
                // and when calling setChannelName a few lines later we
                // restore the old name into the GUI
                }
            }
        }
        vecPane.setOldName(newName);
        vecPane.setChannelName(newName);
        renameInputVariable(oldName, newName);
        System.out.println(oldName + " changed to " + newName);
    // if (newName.compareTo(oldName) != 0 )
    // {
    // revalidateDrivers(oldName); //any driver that uses this name should
    // be invalidated
    // }
    } else if (e.getActionCommand() == "Expression Changed") {
        AddEquationPane eqPane = (AddEquationPane) e.getSource();
        System.out.println("new expression entered :" + eqPane.getEqText());
        String newExpr = eqPane.getEqText();
        if (// otherwise, do nothing and driver will
        !newExpr.equals("")) // remain invalid
        {
            changeExpression(eqList.indexOf(eqPane), newExpr);
        } else {
            invalidateDriverAndGUI(eqList.indexOf(eqPane));
        }
    // check consistency of size:
    } else // }
    if (e.getActionCommand() == "MouseEnteredProp") {
        int index = propList.indexOf(e.getSource());
        AddEquationPane eqPane = eqList.get(index);
        if (eqPane != null) {
            eqPane.setHighlight(true);
        }
    } else if (e.getActionCommand() == "MouseExitedProp") {
        int index = propList.indexOf(e.getSource());
        AddEquationPane eqPane = eqList.get(index);
        if (eqPane != null) {
            eqPane.setHighlight(false);
        }
    } else if (e.getActionCommand() == "MouseEnteredEq") {
        int index = eqList.indexOf(e.getSource());
        AddPropertyPane propPane = propList.get(index);
        if (propPane != null) {
            propPane.setHighlight(true);
        }
    } else if (e.getActionCommand() == "MouseExitedEq") {
        int index = eqList.indexOf(e.getSource());
        AddPropertyPane propPane = propList.get(index);
        if (propPane != null) {
            propPane.setHighlight(false);
        }
    } else if (e.getActionCommand() == "Done") {
        setInputProbe();
        // if (myParent != null) {
        // myParent.actionPerformed (new ActionEvent (this, 0, "ProbeEdited"));
        // }
        Timeline timeline = myMain.getTimeline();
        if (timeline != null) {
            timeline.updateProbes(myMain.getRootModel());
        }
        dispose();
    } else {
        // send it to the superclass
        super.actionPerformed(e);
    }
    refreshAddBtn();
}
Also used : Timeline(artisynth.core.gui.Timeline) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable) Property(maspack.properties.Property) IOException(java.io.IOException)

Example 2 with NumericProbeVariable

use of artisynth.core.probes.NumericProbeVariable in project artisynth_core by artisynth.

the class InputNumericProbeEditor method addProperty.

/**
 * Called when a valid property has been selected for the first time. A
 * property is null before this point. so we set the property at the
 * corresponding index in the ArrayList. Then we automatically create an
 * input variable to go along with this property. The GUI elements are added
 * accordingly for the new input vector. The driver at the current index is
 * also created with the input variable name as its expression.
 *
 * @param index
 * index of property (also of driver, since they should be in sync)
 * @param prop
 * the selected property.
 */
public void addProperty(int index, Property prop) {
    myProperties.set(index, prop);
    NumericConverter conv = new NumericConverter(prop.get());
    String varname = getUniqueVariableName(INPUT_PREFIX);
    NumericProbeVariable var = new NumericProbeVariable(conv.getDimension());
    myVariables.put(varname, var);
    AddVectorPane newVec = new AddVectorPane(this, varname);
    newVec.setDim(var.getDimension());
    addVectorGUI(newVec);
    NumericProbeDriver driver = new NumericProbeDriver();
    driver.setExpression(varname, myVariables);
    myDrivers.set(index, driver);
    updateGUI();
}
Also used : NumericConverter(maspack.properties.NumericConverter) NumericProbeDriver(artisynth.core.probes.NumericProbeDriver) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable)

Example 3 with NumericProbeVariable

use of artisynth.core.probes.NumericProbeVariable in project artisynth_core by artisynth.

the class InputNumericProbeEditor method setInputProbe.

// //
// // Called when a user adds an input property
// //
// public void addInputProbeProperty (int index, Property prop)
// {
// myProperties.set (index, prop);
// 
// NumericConverter conv = new NumericConverter(prop.get());
// String varname = getUniqueVariableName(INPUT_PREFIX);
// NumericProbeVariable var = new NumericProbeVariable(conv.getDimension());
// myVariables.put (varname, var);
// NumericProbeDriver driver = new NumericProbeDriver();
// driver.setExpression (varname, myVariables);
// myDrivers.set (index, driver);
// 
// AddVectorPane newVec = new AddVectorPane(this, varname);
// newVec.setDim(var.getDimension());
// addVectorGUI(newVec);
// super.updateGUI();
// }
private void setInputProbe() {
    ArrayList<String> variableNames = new ArrayList<String>();
    ArrayList<Integer> variableDims = new ArrayList<Integer>();
    for (Map.Entry<String, NumericProbeVariable> entry : myVariables.entrySet()) {
        variableNames.add(entry.getKey());
        variableDims.add(entry.getValue().getDimension());
        System.out.println(entry.getKey() + " -- " + entry.getValue());
    }
    int[] varDimsInt = new int[variableDims.size()];
    for (int i = 0; i < variableDims.size(); i++) {
        varDimsInt[i] = variableDims.get(i);
    // System.out.println("size of V="+variableDims.get(i));
    }
    NumericInputProbe probeToSet;
    if (oldProbe == null) {
        ModelComponent refComp = ComponentUtils.getPropertyComponent(myProperties.get(0));
        probeToSet = new NumericInputProbe(refComp);
    } else {
        probeToSet = oldProbe;
    }
    probeToSet.set(myProperties.toArray(new Property[0]), getDriverExpressions(), variableNames.toArray(new String[0]), varDimsInt);
    probeToSet.setStartTime(startTimeField.getDoubleValue());
    probeToSet.setStopTime(endTimeField.getDoubleValue());
    probeToSet.setScale(scaleField.getDoubleValue());
    probeToSet.setName(probeNameField.getStringValue());
    String attachedFilePath = attachedFileField.getStringValue();
    if (attachedFilePath != null) {
        if (attachedFilePath.equals("") || !attachedInputFileValid(attachedFilePath, null)) {
            attachedFilePath = null;
        }
    }
    if (attachedFilePath != null) {
        probeToSet.setAttachedFileName(attachedFilePath);
        try {
            probeToSet.load();
            ((Displayable) probeToSet).updateDisplays();
        } catch (IOException e) {
            System.err.println("Couldn't load probe ");
            e.printStackTrace();
            probeToSet.setAttachedFileName(null);
        }
    } else {
        probeToSet.setAttachedFileName(null);
        if (probeToSet.getNumericList().isEmpty()) {
            // add knots at beginning and end
            if (probeToSet.isSettable()) {
                probeToSet.setData(probeToSet.getStartTime());
                probeToSet.setData(probeToSet.getStopTime());
            } else {
                probeToSet.loadEmpty();
            }
        }
    }
    if (oldProbe == null) {
        AddComponentsCommand cmd = new AddComponentsCommand("add input probe", probeToSet, myMain.getRootModel().getInputProbes());
        myMain.getUndoManager().saveStateAndExecute(cmd);
    }
}
Also used : Displayable(artisynth.core.gui.Displayable) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AddComponentsCommand(artisynth.core.gui.editorManager.AddComponentsCommand) ModelComponent(artisynth.core.modelbase.ModelComponent) NumericInputProbe(artisynth.core.probes.NumericInputProbe) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Property(maspack.properties.Property)

Example 4 with NumericProbeVariable

use of artisynth.core.probes.NumericProbeVariable in project artisynth_core by artisynth.

the class InputNumericProbeEditor method addInputVariable.

/**
 * called when the user adds a new input variable. simple create a new
 * variable and place it into the hash table.
 *
 * @param name
 * name of variable
 * @param dimen
 * dimension of variable
 */
public void addInputVariable(String name, int dimen) {
    NumericProbeVariable var = new NumericProbeVariable(dimen);
    myVariables.put(name, var);
    super.updateGUI();
}
Also used : NumericProbeVariable(artisynth.core.probes.NumericProbeVariable)

Example 5 with NumericProbeVariable

use of artisynth.core.probes.NumericProbeVariable in project artisynth_core by artisynth.

the class OutputNumericProbeEditor method addProperty.

public boolean addProperty(int index, Property prop) {
    myProperties.set(index, prop);
    AddPropertyPane propPane = propList.get(index);
    String varname = propPane.getPropNameFieldText();
    NumericConverter conv = new NumericConverter(prop.get());
    NumericProbeVariable var = new NumericProbeVariable(conv.getDimension());
    myVariables.put(varname, var);
    // list. If so, use that:
    if (myDrivers.size() > 0 && !myDrivers.get(myDrivers.size() - 1).isValid()) {
        int id = myDrivers.size() - 1;
        AddEquationPane eqn = eqList.get(id);
        eqn.setEqText(varname);
        changeExpression(id, varname);
        updateGUI();
        return false;
    } else {
        // otherwise, add a new driver
        NumericProbeDriver driver = new NumericProbeDriver();
        // System.out.println("addProperty; var name= "+varname);
        driver.setExpression(varname, myVariables);
        // add it at the end of list
        myDrivers.add(myDrivers.size(), driver);
        // add an equation pane for it
        AddEquationPane newEq = createEquationPane(driver.getExpression());
        newEq.setDimensionLabel(driver.getOutputSize());
        newEq.updateAppearance();
        addEquationGUI(newEq);
        updateGUI();
        return true;
    }
}
Also used : NumericConverter(maspack.properties.NumericConverter) NumericProbeDriver(artisynth.core.probes.NumericProbeDriver) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable)

Aggregations

NumericProbeVariable (artisynth.core.probes.NumericProbeVariable)12 NumericProbeDriver (artisynth.core.probes.NumericProbeDriver)7 Property (maspack.properties.Property)4 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 AddComponentsCommand (artisynth.core.gui.editorManager.AddComponentsCommand)2 ArrayList (java.util.ArrayList)2 NumericConverter (maspack.properties.NumericConverter)2 Displayable (artisynth.core.gui.Displayable)1 Timeline (artisynth.core.gui.Timeline)1 ModelComponent (artisynth.core.modelbase.ModelComponent)1 NumericInputProbe (artisynth.core.probes.NumericInputProbe)1 NumericOutputProbe (artisynth.core.probes.NumericOutputProbe)1 CompositeProperty (maspack.properties.CompositeProperty)1 DoubleInterval (maspack.util.DoubleInterval)1