Search in sources :

Example 21 with InternalErrorException

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

the class LabeledComponentPanel method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command.equals("delete")) {
        LinkedList<JComponent> list = new LinkedList<JComponent>();
        list.addAll(mySelectedWidgets);
        for (JComponent comp : list) {
            removeWidget(comp);
        }
        repackContainingWindow();
    } else if (command.equals("add separator")) {
        JComponent comp = mySelectedWidgets.iterator().next();
        addWidget(new JSeparator(), getComponentIndex(comp) + 1);
        repackContainingWindow();
    } else if (command.equals("set properties")) {
        Window win = SwingUtilities.getWindowAncestor(this);
        if (win != null) {
            LinkedList<HasProperties> hosts = new LinkedList<HasProperties>();
            JComponent lastComp = null;
            for (JComponent comp : mySelectedWidgets) {
                if (comp instanceof HasProperties) {
                    hosts.add((HasProperties) comp);
                }
                lastComp = comp;
            }
            HostList hostList = new HostList(hosts);
            PropertyDialog dialog = PropertyDialog.createDialog(win, "Edit properties", hostList, "OK Cancel");
            // PropertyDialog dialog = PropertyDialog.createDialog (
            // win, "Edit properties", new PropertyPanel (comp), "OK Cancel");
            GuiUtils.locateVertically(dialog, lastComp, GuiUtils.BELOW);
            GuiUtils.locateHorizontally(dialog, this, GuiUtils.CENTER);
            dialog.setModal(true);
            dialog.setVisible(true);
        }
    } else if (command.equals("reset sliderRange")) {
        for (JComponent comp : mySelectedWidgets) {
            if (comp instanceof NumericFieldSlider) {
                // fix this for regular sliders too?
                NumericFieldSlider nslider = (NumericFieldSlider) comp;
                nslider.setSliderRange(SliderRange.estimateBoundsIfNecessary(nslider.getRange(), nslider.getDoubleValue()));
            }
        }
    } else if (mySelectedWidgets.size() == 1) {
        JComponent comp = mySelectedWidgets.iterator().next();
        if (comp instanceof LabeledComponentBase) {
            ((LabeledComponentBase) comp).actionPerformed(e);
        }
    } else {
        throw new InternalErrorException("Unexpected action: " + e);
    }
}
Also used : Window(java.awt.Window) JComponent(javax.swing.JComponent) HasProperties(maspack.properties.HasProperties) HostList(maspack.properties.HostList) InternalErrorException(maspack.util.InternalErrorException) LinkedList(java.util.LinkedList) JSeparator(javax.swing.JSeparator)

Example 22 with InternalErrorException

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

the class MouseBindings method clone.

public MouseBindings clone() {
    MouseBindings bindings;
    try {
        bindings = (MouseBindings) super.clone();
    } catch (Exception e) {
        throw new InternalErrorException("MouseBindings cannot be cloned");
    }
    bindings.myActionMasks = Arrays.copyOf(myActionMasks, myActionMasks.length);
    return bindings;
}
Also used : InternalErrorException(maspack.util.InternalErrorException) InternalErrorException(maspack.util.InternalErrorException)

Example 23 with InternalErrorException

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

the class SelectionToolbar method setSelectionButtons.

public void setSelectionButtons() {
    // create an array of all the selection buttons
    ArrayList<JButton> selectionButtons = new ArrayList<JButton>();
    selectionButtons.add(selectButton);
    selectionButtons.add(ellipticSelectButton);
    selectionButtons.add(scaleButton);
    selectionButtons.add(transrotateButton);
    selectionButtons.add(translateButton);
    selectionButtons.add(rotateButton);
    selectionButtons.add(constrainedTranslateButton);
    selectionButtons.add(pullButton);
    // selectionButtons.add (articulatedTransformButton);
    // selectionButtons.add(addMarkerButton);
    // get the button that is currently selected
    SelectionMode mode = main.getSelectionMode();
    JButton selectedButton = null;
    switch(mode) {
        case Select:
            {
                selectedButton = selectButton;
                break;
            }
        case EllipticSelect:
            {
                selectedButton = ellipticSelectButton;
                break;
            }
        case Scale:
            {
                selectedButton = scaleButton;
                break;
            }
        case Translate:
            {
                selectedButton = translateButton;
                break;
            }
        case Transrotate:
            {
                selectedButton = transrotateButton;
                break;
            }
        case Rotate:
            {
                selectedButton = rotateButton;
                break;
            }
        case ConstrainedTranslate:
            {
                selectedButton = constrainedTranslateButton;
                break;
            }
        case Pull:
            {
                selectedButton = pullButton;
                break;
            }
        default:
            {
                throw new InternalErrorException("unimplemented mode " + mode);
            }
    }
    // remove the button that is currently selected from the array list
    selectionButtons.remove(selectedButton);
    // set the decoration on the selected button
    selectedButton.setBorder(bevelBorder);
    selectedButton.setBackground(Color.LIGHT_GRAY);
    // set the decoration on the unselected buttons
    for (JButton b : selectionButtons) {
        b.setBorder(border);
        b.setBackground(background);
    }
}
Also used : JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) InternalErrorException(maspack.util.InternalErrorException) SelectionMode(artisynth.core.driver.Main.SelectionMode)

Example 24 with InternalErrorException

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

the class FemModel3d method findNearestSurfaceElement.

/**
 * Returns the nearest surface element to a specified point,
 * which is found by projecting the point onto the FEM surface.
 * The location of the projection is returned in <code>loc</code>.
 *
 * @param loc Projected location of the point onto the surface.
 * @param pnt Point for which nearest surface element is desired.
 * @return Nearest surface element.
 */
public FemElement3d findNearestSurfaceElement(Point3d loc, Point3d pnt) {
    Vector2d coords = new Vector2d();
    PolygonalMesh surf = getSurfaceMesh();
    if (surf == null || surf.numFaces() == 0) {
        surf = getInternalSurfaceMesh();
    }
    if (surf != null) {
        Face face = BVFeatureQuery.getNearestFaceToPoint(loc, coords, surf, pnt);
        FemElement3d elem = getSurfaceElement(face);
        if (elem == null) {
            throw new InternalErrorException("surface element not found for face");
        }
        return elem;
    } else {
        return null;
    }
}
Also used : Vector2d(maspack.matrix.Vector2d) InternalErrorException(maspack.util.InternalErrorException) Face(maspack.geometry.Face) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 25 with InternalErrorException

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

the class FemElement3d method createIntegrationPoints.

public static IntegrationPoint3d[] createIntegrationPoints(FemElement3d exampleElem, double[] cdata) {
    int numi = cdata.length / 4;
    IntegrationPoint3d[] pnts = new IntegrationPoint3d[numi];
    if (cdata.length != 4 * numi) {
        throw new InternalErrorException("Coordinate data length is " + cdata.length + ", expecting " + 4 * numi);
    }
    for (int k = 0; k < numi; k++) {
        pnts[k] = IntegrationPoint3d.create(exampleElem, cdata[k * 4], cdata[k * 4 + 1], cdata[k * 4 + 2], cdata[k * 4 + 3]);
        pnts[k].setNumber(k);
    }
    return pnts;
}
Also used : InternalErrorException(maspack.util.InternalErrorException) Point(artisynth.core.mechmodels.Point)

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