Search in sources :

Example 1 with Displayable

use of artisynth.core.gui.Displayable 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 2 with Displayable

use of artisynth.core.gui.Displayable in project artisynth_core by artisynth.

the class ProbeInfo method expandProbe.

public void expandProbe() {
    int width = myDisplayArea.getWidth();
    int height = GuiStorage.PROBE_DETAIL_HEIGHT;
    if (getProbe() instanceof Displayable) {
        Displayable dispProbe = (Displayable) getProbe();
        JPanel display = dispProbe.getDisplay(width, height, false);
        if (display instanceof NumericProbePanel && getProbe() instanceof NumericProbeBase) {
            smallDisplay = (NumericProbePanel) display;
        }
        myDisplayArea.add(display);
    }
    myLabel.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
    myController.updateComponentSizes();
    updateProbeDisplays();
}
Also used : NumericProbePanel(artisynth.core.gui.NumericProbePanel) Displayable(artisynth.core.gui.Displayable) NumericProbeBase(artisynth.core.probes.NumericProbeBase) Point(java.awt.Point) WayPoint(artisynth.core.probes.WayPoint)

Aggregations

Displayable (artisynth.core.gui.Displayable)2 NumericProbePanel (artisynth.core.gui.NumericProbePanel)1 AddComponentsCommand (artisynth.core.gui.editorManager.AddComponentsCommand)1 ModelComponent (artisynth.core.modelbase.ModelComponent)1 NumericInputProbe (artisynth.core.probes.NumericInputProbe)1 NumericProbeBase (artisynth.core.probes.NumericProbeBase)1 NumericProbeVariable (artisynth.core.probes.NumericProbeVariable)1 WayPoint (artisynth.core.probes.WayPoint)1 Point (java.awt.Point)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Property (maspack.properties.Property)1