Search in sources :

Example 46 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class PropertyDialog method actionPerformed.

// public void setParentFrame (PropertyWindowBase parent)
// {
// myParent = parent;
// }
// public void addChildWindow (PropertyWindowBase child)
// {
// myChildren.add (child);
// Collection<ValueChangeListener> listeners =
// myPanel.getGlobalValueChangeListeners();
// if (listeners.size() > 0)
// { for (ValueChangeListener l : listeners)
// { child.addGlobalValueChangeListener (l);
// }
// }
// child.setParentFrame (this);
// }
// public void removeChildWindow (PropertyWindowBase child)
// {
// child.setParentFrame (null);
// myChildren.remove (child);
// }
// public boolean hasChildWindows()
// {
// return !myChildren.isEmpty();
// }
public void actionPerformed(ActionEvent e) {
    String actionCmd = e.getActionCommand();
    if (actionCmd.equals("OK") || actionCmd.equals("Done")) {
        myReturnValue = OptionPanel.OK_OPTION;
        setVisible(false);
        dispose();
    } else if (actionCmd.equals("Reset")) {
        System.out.println("reset");
        if (myHostList != null) {
            myHostList.restoreBackupValues();
            myHostList.getCommonValues(myTree, /* live= */
            true);
            fireGlobalValueChangeListeners();
        }
    } else if (actionCmd.equals("Cancel")) {
        myReturnValue = OptionPanel.CANCEL_OPTION;
        // System.out.println ("host list=" + myHostList);
        if (myHostList != null) {
            myHostList.restoreBackupValues();
            fireGlobalValueChangeListeners();
        }
        setVisible(false);
        dispose();
    } else if (actionCmd.equals("LiveUpdate")) {
        boolean enabled = !isLiveUpdatingEnabled();
        enableLiveUpdating(enabled);
        myOptionPanel.setLiveUpdateEnabled(enabled);
    } else {
        throw new InternalErrorException("Unknown action: " + actionCmd);
    }
}
Also used : InternalErrorException(maspack.util.InternalErrorException)

Example 47 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class CompositePropertyPanel method valueChange.

/**
 * Called when the composite property type is changed via the composite
 * property type selector.
 */
public void valueChange(ValueChangeEvent e) {
    if (e.getSource() == myCpropSelector) {
        String newCpropName = (String) myCpropSelector.getValue();
        Class<?> newCpropType = myCpropTypes.get(newCpropName);
        CompositeProperty protoCprop = null;
        if (myCpropType == Property.VoidValue && newCpropType != null && myCpropProperty instanceof EditingProperty) {
            // if there is an existing composite property of this type among the
            // hosts, try to create the prototype by cloning it so
            // that we start with it's properties
            protoCprop = tryCreatingCpropFromPrototype(newCpropType);
        }
        if (protoCprop == null) {
            protoCprop = createCprop(newCpropType);
        }
        myCpropProperty.set(protoCprop);
        myCpropType = newCpropType;
        rebuildPanel(/*setValuesFromWidgets=*/
        true);
        GuiUtils.repackComponentWindow(this);
        fireGlobalValueChangeListeners(new ValueChangeEvent(this, e));
    } else if (e.getSource() == myExpandButton) {
        if (myExpandButton.getBooleanValue()) {
            setExpandState(ExpandState.Expanded);
        } else {
            setExpandState(ExpandState.Contracted);
        }
    } else {
        throw new InternalErrorException("Unexpected valueChange event: " + e);
    // fireGlobalValueChangeListeners(new ValueChangeEvent(this, e));
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty)

Example 48 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class CompositePropertyPanel method attachPropsToWidgets.

/**
 * Attaches a newly created set of properties to their associated
 * widgets.
 *
 * @param widgets list of widgets
 * @param props newly created properties
 * @param setValuesFromWidgets if <code>true</code>, then the properties
 * should be set to assume the values currently stored in the widgets.
 */
private void attachPropsToWidgets(LabeledComponentBase[] widgets, LinkedList<Property> props, boolean setValuesFromWidgets) {
    if (widgets.length != props.size()) {
        throw new InternalErrorException("Number of widgets (" + widgets.length + ") != number of properties (" + props.size() + ")");
    }
    int i = 0;
    for (Property prop : props) {
        LabeledComponentBase widget = widgets[i++];
        if (!setValuesFromWidgets || !(widget instanceof CompositePropertyPanel)) {
            PropertyWidget.initializeWidget(widget, prop);
        }
        if (setValuesFromWidgets) {
            if (widget instanceof CompositePropertyPanel) {
                CompositePropertyPanel cpanel = (CompositePropertyPanel) widget;
                if (cpanel.myCpropType != Property.VoidValue) {
                    setCpropValueFromWidget(prop, (CompositePropertyPanel) widget);
                } else {
                    cpanel.myCpropProperty = prop;
                    cpanel.updateWidgetValues(/*updateFromSource=*/
                    true);
                }
            } else if (widget instanceof LabeledControl) {
                LabeledControl ctrl = (LabeledControl) widget;
                if (ctrl.getValue() != Property.VoidValue) {
                    setValueFromWidget(prop, ctrl);
                } else {
                    if (prop instanceof EditingProperty) {
                        EditingProperty eprop = (EditingProperty) prop;
                        eprop.updateValue();
                    }
                    PropertyWidget.updateValue(ctrl, prop);
                }
            }
        }
        // will set value
        PropertyWidget.finishWidget(widget, prop);
        if (prop instanceof InheritableProperty) {
            PropertyModeButton button = PropertyWidget.getModeButton((LabeledComponentBase) widget);
            if (button != null) {
                button.setProperty((InheritableProperty) prop);
            }
        }
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) InheritableProperty(maspack.properties.InheritableProperty) InternalErrorException(maspack.util.InternalErrorException) InheritableProperty(maspack.properties.InheritableProperty) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty)

Example 49 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class GL3Viewer method drawLine.

@Override
public void drawLine(RenderProps props, float[] pnt0, float[] pnt1, float[] color, boolean capped, boolean highlight) {
    boolean savedHighlighting = getHighlighting();
    Shading savedShading = setLineShading(props);
    if (color == null) {
        color = props.getLineColorF();
    }
    setPropsColoring(props, color, highlight);
    switch(props.getLineStyle()) {
        case LINE:
            {
                // boolean savedLighting = isLightingEnabled();
                // setLightingEnabled (false);
                setLineWidth(gl, props.getLineWidth());
                // if (color.length == 3 && props.getAlpha () < 1) {
                // color = new float[]{color[0], color[1], color[2], (float)props.getAlpha ()};
                // }
                // setColor (color, selected);
                drawGLLine(gl, pnt0, pnt1);
                // setLightingEnabled (savedLighting);
                break;
            }
        case CYLINDER:
            {
                // Shading savedShading = getShadeModel();
                // setShadeModel (props.getShading());
                // setPropsMaterial (props, color, selected);
                drawCylinder(pnt0, pnt1, props.getLineRadius(), capped);
                // setShadeModel(savedShading);
                break;
            }
        case SOLID_ARROW:
            {
                // Shading savedShading = getShadeModel();
                // setShadeModel (props.getShading());
                // setPropsMaterial (props, color, selected);
                drawArrow(pnt0, pnt1, props.getLineRadius(), capped);
                // setShadeModel(savedShading);
                break;
            }
        case SPINDLE:
            {
                // Shading savedShading = getShadeModel();
                // setShadeModel (props.getShading());
                // setPropsMaterial (props, color, selected);
                drawSpindle(pnt0, pnt1, props.getLineRadius());
                // setShadeModel(savedShading);
                break;
            }
        default:
            {
                throw new InternalErrorException("Unimplemented line style " + props.getLineStyle());
            }
    }
    setShading(savedShading);
    setHighlighting(savedHighlighting);
}
Also used : InternalErrorException(maspack.util.InternalErrorException)

Example 50 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class GL3Viewer method drawArrow.

@Override
public void drawArrow(RenderProps props, float[] pnt0, float[] pnt1, boolean capped, boolean highlight) {
    boolean savedHighlighting = getHighlighting();
    Shading savedShading = setLineShading(props);
    setLineColoring(props, highlight);
    Vector3d utmp = new Vector3d(pnt1[0] - pnt0[0], pnt1[1] - pnt0[1], pnt1[2] - pnt0[2]);
    double len = utmp.norm();
    utmp.scale(1.0 / len);
    Vector3d vtmp = new Vector3d(pnt0[0], pnt0[1], pnt0[2]);
    double arrowRad = 3 * props.getLineRadius();
    double arrowLen = 2 * arrowRad;
    vtmp.scaledAdd(len - arrowLen, utmp);
    float[] ctmp = new float[3];
    ctmp[0] = (float) vtmp.x;
    ctmp[1] = (float) vtmp.y;
    ctmp[2] = (float) vtmp.z;
    if (len > arrowLen) {
        switch(props.getLineStyle()) {
            case LINE:
                {
                    setLineWidth(gl, props.getLineWidth());
                    drawGLLine(gl, pnt0, ctmp);
                    break;
                }
            case CYLINDER:
            case SOLID_ARROW:
                {
                    drawCylinder(pnt0, ctmp, props.getLineRadius(), capped);
                    break;
                }
            case SPINDLE:
                {
                    drawSpindle(pnt0, pnt1, props.getLineRadius());
                    break;
                }
            default:
                {
                    throw new InternalErrorException("Unimplemented line style " + props.getLineStyle());
                }
        }
    }
    if (props.getLineStyle() == LineStyle.LINE) {
        // reset shading from NONE to props value
        setShading(props.getShading());
    }
    if (len <= arrowLen) {
        drawCone(pnt0, pnt1, len / 2, 0, capped);
    } else {
        drawCone(ctmp, pnt1, arrowRad, 0, capped);
    }
    setShading(savedShading);
    setHighlighting(savedHighlighting);
}
Also used : Vector3d(maspack.matrix.Vector3d) InternalErrorException(maspack.util.InternalErrorException)

Aggregations

InternalErrorException (maspack.util.InternalErrorException)92 Vector3d (maspack.matrix.Vector3d)9 CompositeProperty (maspack.properties.CompositeProperty)8 Point3d (maspack.matrix.Point3d)7 Property (maspack.properties.Property)7 FemModel3d (artisynth.core.femmodels.FemModel3d)6 Point (artisynth.core.mechmodels.Point)6 ModelComponent (artisynth.core.modelbase.ModelComponent)5 PolygonalMesh (maspack.geometry.PolygonalMesh)5 Line (maspack.matrix.Line)5 RigidTransform3d (maspack.matrix.RigidTransform3d)5 EditingProperty (maspack.properties.EditingProperty)5 BadLocationException (javax.swing.text.BadLocationException)4 RotationMatrix3d (maspack.matrix.RotationMatrix3d)4 RigidBody (artisynth.core.mechmodels.RigidBody)3 RootModel (artisynth.core.workspace.RootModel)3 File (java.io.File)3 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 SelectionManager (artisynth.core.gui.selectionManager.SelectionManager)2