Search in sources :

Example 31 with InternalErrorException

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

the class GeometryInertiaPanel method resetMesh.

// XXX need to make sure myMeshFileTransform is not null, as it can
// be in rigid bodies
// Resets myMesh, myMeshFileName, and myMeshFileTransform based on the
// currently selected Geometry type. For all types, this will involve
// rebuilding the actual mesh (or for the Mesh type, copying/transforming it
// from myFileMesh).
// 
public void resetMesh() {
    GeometryType type = (GeometryType) myGeometrySelector.getValue();
    switch(type) {
        case Box:
            {
                Vector3d widths = (Vector3d) myBoxWidthsField.getValue();
                myMesh = MeshFactory.createBox(widths.get(0), widths.get(1), widths.get(2), 0, 0, 0);
                myMeshFileName = null;
                myMeshFileTransform = null;
                break;
            }
        case Sphere:
            {
                double radius = myPointRadiusField.getDoubleValue();
                int slices = myPointSlicesField.getIntValue();
                myMesh = MeshFactory.createSphere(radius, slices);
                myMeshFileName = null;
                myMeshFileTransform = null;
                break;
            }
        case Mesh:
            {
                String meshFileName = myMeshFileField.getStringValue();
                AffineTransform3dBase xform = myMeshXformWidget.getTransformValue();
                // if (xform instanceof RigidTransform3d) {
                // System.out.println ("xform.p=" + ((RigidTransform3d)xform).p);
                // }
                // set these to null, then override below as appropriate
                myMesh = null;
                myMeshFileName = null;
                myMeshFileTransform = null;
                if (myFileMesh != null) {
                    if (xform.isIdentity()) {
                        myMesh = myFileMesh;
                    } else {
                        myMesh = myFileMesh.copy();
                        myMesh.transform(xform);
                    }
                }
                if (meshFileName != null && meshFileName.length() > 0) {
                    myMeshFileName = meshFileName;
                    if (!xform.isIdentity()) {
                        myMeshFileTransform = xform;
                    }
                }
                break;
            }
        default:
            {
                throw new InternalErrorException("unimplemented geometry type: " + type);
            }
    }
    updateDensityAndInertia();
    if (myAttachedBody != null && myMesh != null) {
        // don't update the body unless we need to ...
        if (myMesh != myAttachedBody.getMesh() || !objectsEqual(myMeshFileName, myAttachedBody.getMeshFileName()) || !objectsEqual(myMeshFileTransform, myAttachedBody.getMeshFileTransform())) {
            myAttachedBody.setMesh(myMesh, myMeshFileName, myMeshFileTransform);
            Main.getMain().rerender();
        }
    }
}
Also used : InternalErrorException(maspack.util.InternalErrorException)

Example 32 with InternalErrorException

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

the class GeometryInertiaPanel method rebuildGeometryWidgets.

/**
 * Called once at panel creation, and then whenever the geometry type is
 * changed (via the GeometrySelection widget). It rebuilds the panel to
 * include the widgets appropriate to the geometry.
 */
private void rebuildGeometryWidgets(GeometryType type) {
    for (LabeledControl w : myGeometryWidgets) {
        removeWidget(w);
    }
    myGeometryWidgets.clear();
    switch(type) {
        case Box:
            {
                myGeometryWidgets.add(myBoxWidthsField);
                break;
            }
        case Sphere:
            {
                myGeometryWidgets.add(myPointRadiusField);
                myGeometryWidgets.add(myPointSlicesField);
                break;
            }
        case Mesh:
            {
                myGeometryWidgets.add(myMeshFileField);
                myGeometryWidgets.add(myMeshXformWidget.getScaleField());
                myGeometryWidgets.add(myMeshXformWidget.getTranslationField());
                myGeometryWidgets.add(myMeshXformWidget.getRotationField());
                break;
            }
        default:
            {
                throw new InternalErrorException("unimplemented geometry type: " + type);
            }
    }
    int idx = GuiUtils.indexOfComponent(this, myGeometrySelector) + 1;
    for (LabeledControl w : myGeometryWidgets) {
        addWidget(w, idx++);
    }
}
Also used : LabeledControl(maspack.widgets.LabeledControl) InternalErrorException(maspack.util.InternalErrorException)

Example 33 with InternalErrorException

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

the class ReadlinePanel method backwardKillLine.

protected void backwardKillLine() {
    int begOffs = getLineStart();
    int offs = getCaretPosition();
    if (begOffs < offs) {
        try {
            myKillBuffer = getText(begOffs, offs - begOffs);
            doDelete(begOffs, offs);
        } catch (BadLocationException ble) {
            throw new InternalErrorException("bad location");
        }
    }
}
Also used : InternalErrorException(maspack.util.InternalErrorException) BadLocationException(javax.swing.text.BadLocationException)

Example 34 with InternalErrorException

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

the class TimelineController method deleteTrack.

void deleteTrack(int trackType, int trackIndex, boolean requireConfirm) {
    if (!requireConfirm || confirmAction("Delete this track?")) {
        // delete everything associated with the track to be deleted,
        // also, remove it from this model's track list
        Track track = null;
        if (trackType == Track.TYPE_INPUT) {
            track = myInTracks.remove(trackIndex);
            updateTrackIndices(myInTracks);
        } else if (trackType == Track.TYPE_OUTPUT) {
            track = myOutTracks.remove(trackIndex);
            updateTrackIndices(myOutTracks);
        } else {
            throw new InternalErrorException("Unimplemented track type: " + trackType);
        }
        track.dispose();
        rebuildTimeline();
    }
}
Also used : InternalErrorException(maspack.util.InternalErrorException)

Example 35 with InternalErrorException

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

the class ComponentPropertyField method valueToTextArray.

protected String[] valueToTextArray(Object value) {
    ModelComponent comp = getComponent(value);
    RootModel root = myMain.getRootModel();
    String compStr = "/";
    String propStr = "";
    if (root == null || comp == null) {
        return new String[] { "", "" };
    }
    if (value instanceof ModelComponent) {
        compStr = ComponentUtils.getPathName(root, comp);
    } else if (value instanceof Property) {
        Property prop = (Property) value;
        boolean excludeLeaf = (myPropertySelector != null && !(prop.get() instanceof CompositeProperty));
        String path = ComponentUtils.getPropertyPathName(prop, root, false);
        int idx = path.indexOf(':');
        // default to root
        propStr = path;
        if (idx >= 0) {
            compStr = path.substring(0, idx);
            if (idx < path.length() - 1) {
                propStr = path.substring(idx + 1);
            }
        }
    } else {
        throw new InternalErrorException("Unknown value type: " + value.getClass());
    }
    return new String[] { compStr, propStr };
}
Also used : RootModel(artisynth.core.workspace.RootModel) ModelComponent(artisynth.core.modelbase.ModelComponent) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) CompositeProperty(maspack.properties.CompositeProperty)

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