Search in sources :

Example 16 with InternalErrorException

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

the class SphericalCoupling method getConstraintInfo.

@Override
public void getConstraintInfo(ConstraintInfo[] info, RigidTransform3d TGD, RigidTransform3d TCD, RigidTransform3d XERR, boolean setEngaged) {
    // projectToConstraint(TGD, TCD);
    // info[0].bilateral = true;
    // info[1].bilateral = true;
    // info[2].bilateral = true;
    // info[3].bilateral = false;
    // info[4].bilateral = false;
    // info[5].bilateral = false;
    // myXFC.mulInverseLeft(TGD, TCD);
    myErr.set(XERR);
    setDistancesAndZeroDerivatives(info, 3, myErr);
    if (myRangeType == TILT_LIMIT) {
        Vector3d utilt = new Vector3d();
        // Tilt axis is is z(C) x z(D).
        // In C coordinates, z(C) = (0,0,1) and z(D) = last row of TGD.R.
        // In D coordinates, z(D) = (0,0,1) and z(C) = last col of TGD.R.
        // D coordinates
        utilt.set(TGD.R.m12, -TGD.R.m02, 0);
        // utilt.set (-TGD.R.m21, TGD.R.m20, 0); // in C coordinates
        double ulen = utilt.norm();
        double theta = 0;
        if (ulen > 1e-8) {
            theta = Math.atan2(ulen, TGD.R.m22);
            utilt.scale(1 / ulen);
        }
        if (setEngaged) {
            if (theta > myMaxTilt) {
                info[3].engaged = 1;
            }
        }
        if (info[3].engaged != 0) {
            info[3].distance = myMaxTilt - theta;
            utilt.inverseTransform(TGD.R);
            info[3].wrenchC.set(0, 0, 0, utilt.x, utilt.y, utilt.z);
            info[3].dotWrenchC.setZero();
        }
    } else if (myRangeType == ROTATION_LIMIT) {
        Vector3d u = new Vector3d();
        double ang = TGD.R.getAxisAngle(u);
        // paranoid
        u.normalize();
        Vector3d a = new Vector3d(u.x * myMaxRotX, u.y * myMaxRotY, u.z * myMaxRotZ);
        double maxAng = a.norm();
        if (setEngaged) {
            if (ang > 0 && ang > maxAng) {
                info[3].engaged = 1;
            }
        }
        if (info[3].engaged != 0) {
            info[3].distance = maxAng - ang;
            u.x /= myMaxRotX;
            u.y /= myMaxRotY;
            u.z /= myMaxRotZ;
            u.normalize();
            info[3].wrenchC.set(0, 0, 0, -u.x, -u.y, -u.z);
            // TODO set this
            info[3].dotWrenchC.setZero();
        }
    } else if (myRangeType == RPY_LIMIT) {
        double roll, pitch, yaw;
        double[] rpy = new double[3];
        RotationMatrix3d RDC = new RotationMatrix3d();
        Vector3d wBA = new Vector3d();
        RDC.transpose(TGD.R);
        doGetRpy(rpy, RDC);
        roll = rpy[0];
        pitch = rpy[1];
        yaw = rpy[2];
        double cr = Math.cos(roll);
        double sr = Math.sin(roll);
        double cp = Math.cos(pitch);
        double sp = Math.sin(pitch);
        double denom = cp;
        // the singularity at cp = 0
        if (Math.abs(denom) < 0.0001) {
            denom = (denom >= 0 ? 0.0001 : -0.0001);
        }
        double tp = sp / denom;
        // Don't need to transform because vel is now in Frame C
        // get angular velocity of B with respect to A in frame C
        // if (!myComputeVelInFrameC) {
        // wBA.transform(RDC, myVelBA.w);
        // }
        info[3].distance = 0;
        info[4].distance = 0;
        info[5].distance = 0;
        double dotp = -sr * wBA.x + cr * wBA.y;
        double doty = (cr * wBA.x + sr * wBA.y) / denom;
        double dotr = wBA.z + sp * doty;
        if (setEngaged) {
            maybeSetEngaged(info[3], roll, myMinRoll, myMaxRoll);
            maybeSetEngaged(info[4], pitch, myMinPitch, myMaxPitch);
            maybeSetEngaged(info[5], yaw, myMinYaw, myMaxYaw);
        }
        if (info[3].engaged != 0) {
            info[3].distance = getDistance(roll, myMinRoll, myMaxRoll);
            info[3].wrenchC.set(0, 0, 0, sp * cr / denom, sp * sr / denom, 1);
            info[3].dotWrenchC.f.setZero();
            double tt = (1 + tp * tp);
            info[3].dotWrenchC.m.set(-sr * tp * dotr + tt * cr * dotp, cr * tp * dotr + tt * sr * dotp, 0);
            // checkDeriv ("roll", info[3], conR);
            if (info[3].engaged == -1) {
                info[3].wrenchC.negate();
                info[3].dotWrenchC.negate();
            }
        }
        if (info[4].engaged != 0) {
            info[4].distance = getDistance(pitch, myMinPitch, myMaxPitch);
            info[4].wrenchC.set(0, 0, 0, -sr, cr, 0);
            info[4].dotWrenchC.f.setZero();
            info[4].dotWrenchC.m.set(-cr * dotr, -sr * dotr, 0);
            // checkDeriv ("pitch", info[4], conP);
            if (info[4].engaged == -1) {
                info[4].wrenchC.negate();
                info[4].dotWrenchC.negate();
            }
        }
        if (info[5].engaged != 0) {
            info[5].distance = getDistance(yaw, myMinYaw, myMaxYaw);
            info[5].wrenchC.set(0, 0, 0, cr / denom, sr / denom, 0);
            info[5].dotWrenchC.f.setZero();
            info[5].dotWrenchC.m.set((-sr * dotr + cr * tp * dotp) / denom, (cr * dotr + sr * tp * dotp) / denom, 0);
            // checkDeriv ("yaw", info[5], conY);
            if (info[5].engaged == -1) {
                info[5].wrenchC.negate();
                info[5].dotWrenchC.negate();
            }
        }
    // System.out.println ("xxx:");
    // for (int i=3; i<6; i++) {
    // System.out.println (
    // info[i].engaged+" "+Math.toDegrees(info[i].distance));
    // }
    } else if (myRangeType != 0) {
        throw new InternalErrorException("Unimplemented range limits " + NumberFormat.formatHex(myRangeType));
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) InternalErrorException(maspack.util.InternalErrorException) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 17 with InternalErrorException

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

the class PropertyFrame method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String actionCmd = e.getActionCommand();
    if (actionCmd.equals("OK") || actionCmd.equals("Done") || actionCmd.equals("Close")) {
        myReturnValue = OptionPanel.OK_OPTION;
        setVisible(false);
        dispose();
    } else if (actionCmd.equals("Reset")) {
        if (myHostList != null) {
            myHostList.restoreBackupValues();
            myHostList.getCommonValues(myTree, /* live= */
            true);
            // updateWidgetValues();
            fireGlobalValueChangeListeners();
        }
    } else if (actionCmd.equals("Cancel")) {
        myReturnValue = OptionPanel.CANCEL_OPTION;
        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 18 with InternalErrorException

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

the class SetHandler method initializeWidget.

public static boolean initializeWidget(LabeledComponentBase widget, Property prop) {
    String name = prop.getName();
    PropertyInfo info = prop.getInfo();
    Class<?> type = info.getValueClass();
    if (widget instanceof LabeledWidget) {
        LabeledWidget lwidget = (LabeledWidget) widget;
        if (textIsEmpty(lwidget.getLabelText())) {
            lwidget.setLabelText(name);
        }
        if (textIsEmpty(lwidget.getToolTipText())) {
            lwidget.setToolTipText(info.getDescription());
        }
    }
    if (widget instanceof LabeledControl) {
        removeOldListeners((LabeledControl) widget);
    }
    try {
        if (String.class.isAssignableFrom(type)) {
            // if String has a range, then use StringSelector
            // otherwise, use a simple StringField
            Range stringRange = prop.getRange();
            if (info.isInheritable() || stringRange == null || !(stringRange instanceof StringRange) || ((StringRange) stringRange).isWildcard()) {
                StringField stringField = (StringField) widget;
                stringField.setColumns(20);
                stringField.addValueChangeListener(new PropChangeListener(prop) {

                    public void valueChange(ValueChangeEvent e) {
                        if (e.getValue() == null || e.getValue().equals("")) {
                            super.valueChange(new ValueChangeEvent(e.getSource(), ""));
                        } else {
                            super.valueChange(e);
                        }
                    }
                });
                stringField.setStretchable(true);
            } else {
                String[] constants = ((StringRange) stringRange).getValidStrings();
                StringSelector selector = (StringSelector) widget;
                selector.setSelections(constants, null);
                selector.addValueChangeListener(new PropChangeListener(prop));
            }
        } else if (type == double.class || type == float.class || type == Double.class || type == Float.class) {
            DoubleField doubleField = (DoubleField) widget;
            Range range = prop.getRange();
            if (range instanceof NumericInterval) {
                doubleField.setRange((NumericInterval) range);
            }
            // }
            if (info.getPrintFormat() != null && formatIsDefault(doubleField)) {
                doubleField.setFormat(info.getPrintFormat());
            }
            GuiUtils.setFixedWidth(doubleField.getTextField(), 100);
            doubleField.addValueChangeListener(new PropChangeListener(prop));
        } else if (type == int.class || type == Integer.class) {
            IntegerField intField = (IntegerField) widget;
            GuiUtils.setFixedWidth(intField.getTextField(), 100);
            intField.addValueChangeListener(new PropChangeListener(prop));
        } else if (type == boolean.class || type == Boolean.class) {
            if (info.isReadOnly()) {
                StringField stringField = (StringField) widget;
                stringField.setColumns(5);
            } else {
                BooleanSelector selector = (BooleanSelector) widget;
                selector.addValueChangeListener(new PropChangeListener(prop));
            }
        } else if (VectorBase.class.isAssignableFrom(type) && info.getDimension() != -1) {
            VectorBase resultVec;
            try {
                resultVec = (VectorBase) type.newInstance();
            } catch (Exception e) {
                throw new InternalErrorException("Error creating no-args instance of " + type);
            }
            if (resultVec instanceof VectorNd) {
                ((VectorNd) resultVec).setSize(info.getDimension());
            }
            VectorField vectorField = (VectorField) widget;
            // from scratch)
            if (vectorField.getVectorSize() != info.getDimension()) {
                vectorField.setVectorSize(info.getDimension());
            } else {
                VectorNd existingValue = vectorField.getVectorValue();
                if (existingValue != null) {
                    resultVec.set(existingValue);
                }
            }
            vectorField.setResultHolder(resultVec);
            vectorField.addValueChangeListener(new PropChangeListener(prop));
            if (info.getPrintFormat() != null && formatIsDefault(vectorField)) {
                vectorField.setFormat(info.getPrintFormat());
            }
            vectorField.setStretchable(true);
        } else if (VectoriBase.class.isAssignableFrom(type) && info.getDimension() != -1) {
            VectoriBase resultVec;
            try {
                resultVec = (VectoriBase) type.newInstance();
            } catch (Exception e) {
                throw new InternalErrorException("Error creating no-args instance of " + type);
            }
            if (resultVec instanceof VectorNi) {
                ((VectorNi) resultVec).setSize(info.getDimension());
            }
            VectoriField vectorField = (VectoriField) widget;
            // from scratch)
            if (vectorField.getVectorSize() != info.getDimension()) {
                vectorField.setVectorSize(info.getDimension());
            } else {
                VectorNi existingValue = vectorField.getVectorValue();
                if (existingValue != null) {
                    resultVec.set(existingValue);
                }
            }
            vectorField.setResultHolder(resultVec);
            vectorField.addValueChangeListener(new PropChangeListener(prop));
            if (info.getPrintFormat() != null && formatIsDefault(vectorField)) {
                vectorField.setFormat(info.getPrintFormat());
            }
            vectorField.setStretchable(true);
        } else if (VectorBase.class.isAssignableFrom(type) && info.getDimension() == -1) {
            VectorBase resultVec;
            try {
                resultVec = (VectorBase) type.newInstance();
            } catch (Exception e) {
                throw new InternalErrorException("Error creating no-args instance of " + type);
            }
            VariableVectorField vectorField = (VariableVectorField) widget;
            VectorNd existingValue = vectorField.getVectorValue();
            if (vectorField.getVectorSize() != resultVec.size()) {
                resultVec.setSize(vectorField.getVectorSize());
            }
            if (existingValue != null) {
                resultVec.set(existingValue);
            }
            vectorField.setResultHolder(resultVec);
            vectorField.addValueChangeListener(new PropChangeListener(prop));
            if (info.getPrintFormat() != null && formatIsDefault(vectorField)) {
                vectorField.setFormat(info.getPrintFormat());
            }
            vectorField.setStretchable(true);
        } else if (SymmetricMatrix3d.class.isAssignableFrom(type)) {
            SymmetricMatrix3dField matrixField = (SymmetricMatrix3dField) widget;
            matrixField.addValueChangeListener(new PropChangeListener(prop));
            if (info.getPrintFormat() != null && formatIsDefault(matrixField)) {
                matrixField.setFormat(info.getPrintFormat());
            }
            matrixField.setStretchable(true);
        } else if (RigidTransform3d.class.isAssignableFrom(type)) {
            RigidTransformWidget transformField = (RigidTransformWidget) widget;
            transformField.addValueChangeListener(new PropChangeListener(prop));
            transformField.setStretchable(true);
        } else if (AffineTransform3d.class.isAssignableFrom(type)) {
            AffineTransformWidget transformField = (AffineTransformWidget) widget;
            transformField.addValueChangeListener(new PropChangeListener(prop));
            transformField.setStretchable(true);
        } else if (Rectangle2d.class.isAssignableFrom(type)) {
            RectangleField rectField = (RectangleField) widget;
            rectField.addValueChangeListener(new PropChangeListener(prop));
            if (info.getPrintFormat() != null && formatIsDefault(rectField)) {
                rectField.setFormat(info.getPrintFormat());
            }
            rectField.setStretchable(true);
        } else // }
        if (AxisAngle.class.isAssignableFrom(type)) {
            AxisAngleField orientationField = (AxisAngleField) widget;
            orientationField.addValueChangeListener(new PropChangeListener(prop));
            orientationField.setStretchable(true);
        } else if (Enum.class.isAssignableFrom(type)) {
            Enum<?>[] constants = null;
            Range range = prop.getRange();
            if (range != null && range instanceof EnumRange) {
                constants = ((EnumRange<?>) range).getValidEnums();
            } else {
                constants = (Enum[]) type.getEnumConstants();
            }
            if (info.isReadOnly()) {
                StringField stringField = (StringField) widget;
                int ncols = 0;
                for (int i = 0; i < constants.length; i++) {
                    int len = constants[i].toString().length();
                    if (len > ncols) {
                        ncols = len;
                    }
                }
                stringField.setColumns(ncols);
            } else {
                EnumSelector selector = (EnumSelector) widget;
                selector.setSelections(constants, null);
                selector.addValueChangeListener(new PropChangeListener(prop));
            }
        } else if (Color.class.isAssignableFrom(type)) {
            ColorSelector selector = (ColorSelector) widget;
            if (info.getNullValueOK()) {
                selector.enableNullColors();
            }
            selector.addValueChangeListener(new PropChangeListener(prop));
        } else if (IntegerInterval.class.isAssignableFrom(type)) {
            IntegerIntervalField rangeField = (IntegerIntervalField) widget;
            rangeField.addValueChangeListener(new PropChangeListener(prop));
            rangeField.setStretchable(true);
        } else if (NumericInterval.class.isAssignableFrom(type)) {
            DoubleIntervalField rangeField = (DoubleIntervalField) widget;
            rangeField.addValueChangeListener(new PropChangeListener(prop));
            rangeField.setStretchable(true);
        } else if (GLGridResolution.class.isAssignableFrom(type)) {
            GridResolutionField resField = (GridResolutionField) widget;
            resField.addValueChangeListener(new PropChangeListener(prop));
        } else if (Font.class.isAssignableFrom(type)) {
            FontField fontField = (FontField) widget;
            fontField.addValueChangeListener(new PropChangeListener(prop));
        } else if (CompositeProperty.class.isAssignableFrom(type)) {
            if (widget instanceof CompositePropertyWidget) {
                CompositePropertyWidget compProp = (CompositePropertyWidget) widget;
                compProp.setProperty(prop);
            } else {
                CompositePropertyPanel compProp = (CompositePropertyPanel) widget;
                compProp.setExpandState(info.getWidgetExpandState());
                compProp.initializeSelection(prop);
            }
        } else {
            return false;
        }
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("widget type " + widget.getClass() + " inappropriate for property type " + type);
    }
    // finishWidget (widget, prop);
    return true;
}
Also used : EnumRange(maspack.util.EnumRange) NumericInterval(maspack.util.NumericInterval) SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) Color(java.awt.Color) EnumRange(maspack.util.EnumRange) StringRange(maspack.util.StringRange) Range(maspack.util.Range) StringRange(maspack.util.StringRange) VectorBase(maspack.matrix.VectorBase) AffineTransform3d(maspack.matrix.AffineTransform3d) VectoriBase(maspack.matrix.VectoriBase) Font(java.awt.Font) InternalErrorException(maspack.util.InternalErrorException) InternalErrorException(maspack.util.InternalErrorException) AxisAngle(maspack.matrix.AxisAngle) VectorNd(maspack.matrix.VectorNd) PropertyInfo(maspack.properties.PropertyInfo) VectorNi(maspack.matrix.VectorNi)

Example 19 with InternalErrorException

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

the class RenderPropsDialog method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String actionCmd = e.getActionCommand();
    if (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.replaceSubHostsIfNecessary(myTree);
            myHostList.getCommonValues(myTree, /* live= */
            true);
            updateWidgetValues();
        }
        fireGlobalValueChangeListeners();
    } else {
        throw new InternalErrorException("Unimplemented action command " + actionCmd);
    }
}
Also used : InternalErrorException(maspack.util.InternalErrorException)

Example 20 with InternalErrorException

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

the class CompositePropertyWidget method setClearButtonFace.

protected void setClearButtonFace(int face) {
    if (myClearButtonInstalled) {
        if (myClearButtonFace != face) {
            if (face == CLEAR) {
                int idx = removeMajorComponent(myNullLabel);
                addMajorComponent(myClearButton, idx);
            } else if (face == NULL) {
                int idx = removeMajorComponent(myClearButton);
                addMajorComponent(myNullLabel, idx);
            } else {
                throw new InternalErrorException("Unknown face spec: " + face);
            }
            revalidate();
            repaint();
            myClearButtonFace = face;
        }
    }
}
Also used : 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