Search in sources :

Example 76 with InternalErrorException

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

the class PropertyWidgetDialog method createWidget.

public LabeledComponentBase createWidget() {
    if (getModelComponent() == null || getPropertyInfo() == null) {
        throw new IllegalStateException("component and/or property not set");
    }
    LabeledComponentBase widget;
    ModelComponent comp = getModelComponent();
    String propPath = getPropertyPath();
    Property prop = comp.getProperty(propPath);
    if (prop == null) {
        throw new InternalErrorException("property '" + propPath + "' not found for component " + comp.getClass());
    }
    if (CompositeProperty.class.isAssignableFrom(prop.getInfo().getValueClass())) {
        // replace prop with an EditingProperty, since
        // CompositePropertyWidgets only work properly with those
        prop = createEditingProperty(prop);
    }
    if (isSliderSelected()) {
        widget = PropertyWidget.create(prop, getSliderMinimum(), getSliderMaximum());
    } else {
        widget = PropertyWidget.create(prop);
    }
    String labelText = myLabelTextField.getStringValue();
    widget.setLabelText(labelText);
    if (!myLabelFontColorSelector.valueIsNull()) {
        widget.setLabelFontColor(myLabelFontColorSelector.getColor());
    }
    if (!myBackgroundColorSelector.valueIsNull()) {
        widget.setBackgroundColor(myBackgroundColorSelector.getColor());
    }
    return widget;
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) LabeledComponentBase(maspack.widgets.LabeledComponentBase) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) EditingProperty(maspack.properties.EditingProperty) Property(maspack.properties.Property)

Example 77 with InternalErrorException

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

the class Merge method doMerge.

private void doMerge() {
    int i = 0;
    processors = new Processor[sourcesURLs.size()];
    dataOutputs = new DataSource[sourcesURLs.size()];
    for (i = 0; i < sourcesURLs.size(); i++) {
        String source = (String) sourcesURLs.elementAt(i);
        MediaLocator ml = new MediaLocator(source);
        ProcessorModel pm = new MyPM(ml);
        try {
            processors[i] = Manager.createRealizedProcessor(pm);
            dataOutputs[i] = processors[i].getDataOutput();
            processors[i].start();
        } catch (Exception e) {
            throw new InternalErrorException("Failed to create a processor: " + e);
        }
    }
    // Merge the data sources from the individual processors
    try {
        merger = Manager.createMergingDataSource(dataOutputs);
        merger.connect();
        merger.start();
    } catch (Exception e) {
        throw new InternalErrorException("Failed to merge data sources: " + e);
    }
    if (merger == null) {
        throw new InternalErrorException("Failed to merge data sources");
    }
    /*
        try {
        Player p = Manager.createPlayer(merger);
        new com.sun.media.ui.PlayerWindow(p);
        } catch (Exception e) {
        System.err.println("Failed to create player " + e);
        }
      */
    // Create the output processor
    ProcessorModel outputPM = new MyPMOut(merger);
    try {
        outputProcessor = Manager.createRealizedProcessor(outputPM);
        outputDataSource = outputProcessor.getDataOutput();
    } catch (Exception e) {
        throw new InternalErrorException("Failed to create output processor: " + e);
    }
    try {
        outputLocator = new MediaLocator(outputFile);
        outputDataSink = Manager.createDataSink(outputDataSource, outputLocator);
        outputDataSink.open();
    } catch (Exception e) {
        throw new InternalErrorException("Failed to create output DataSink: " + e);
    }
    outputProcessor.addControllerListener(this);
    outputDataSink.addDataSinkListener(this);
    // System.err.println("Merging...");
    try {
        outputDataSink.start();
        outputProcessor.start();
    } catch (Exception e) {
        throw new InternalErrorException("Failed to start file writing: " + e);
    }
    int count = 0;
    while (!done) {
        try {
            Thread.currentThread().sleep(100);
        } catch (InterruptedException ie) {
        }
        if (outputProcessor != null && (int) (outputProcessor.getMediaTime().getSeconds()) > count) {
            System.err.print(".");
            count = (int) (outputProcessor.getMediaTime().getSeconds());
        }
    }
    if (outputDataSink != null) {
        outputDataSink.close();
    }
    synchronized (this) {
        if (outputProcessor != null) {
            outputProcessor.close();
        }
    }
// System.err.println("Done!");
}
Also used : InternalErrorException(maspack.util.InternalErrorException) InternalErrorException(maspack.util.InternalErrorException)

Example 78 with InternalErrorException

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

the class MovieMakerDialog method actionPerformed.

public void actionPerformed(ActionEvent event) {
    String cmd = event.getActionCommand();
    Object source = event.getSource();
    if (cmd.equals(FULL_WINDOW_CMD)) {
        viewerCapture = false;
        customCapture = false;
        showCaptureFrame.setEnabled(false);
        setAreaSelectionFrame(null);
        setCaptureArea(myFrame);
        viewWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        fullWindowButton.setBorder(new BevelBorder(BevelBorder.LOWERED));
        customWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        originalSize.setEnabled(false);
        constrainSize.setEnabled(false);
        resizeWidth.getTextField().setEnabled(false);
        resizeHeight.getTextField().setEnabled(false);
        resizeSamples.getTextField().setEnabled(false);
        windowWidth.getTextField().setEnabled(false);
        windowHeight.getTextField().setEnabled(false);
        windowXPosition.getTextField().setEnabled(false);
        windowYPosition.getTextField().setEnabled(false);
    } else if (cmd.equals(VIEW_WINDOW_CMD)) {
        viewerCapture = true;
        customCapture = false;
        showCaptureFrame.setEnabled(false);
        setAreaSelectionFrame(null);
        setCaptureArea(myFrame.getViewer().getCanvas().getComponent());
        viewWindowButton.setBorder(new BevelBorder(BevelBorder.LOWERED));
        fullWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        customWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        originalSize.setEnabled(true);
        if (!originalSize.isSelected()) {
            originalSize.doClick();
        }
        constrainSize.setEnabled(false);
        resizeWidth.getTextField().setEnabled(false);
        resizeHeight.getTextField().setEnabled(false);
        resizeSamples.getTextField().setEnabled(false);
        windowWidth.getTextField().setEnabled(false);
        windowHeight.getTextField().setEnabled(false);
        windowXPosition.getTextField().setEnabled(false);
        windowYPosition.getTextField().setEnabled(false);
    } else if (cmd.equals(CUSTOM_WINDOW_CMD)) {
        viewerCapture = false;
        customCapture = true;
        if (!showCaptureFrame.isSelected() || !showCaptureFrame.isEnabled()) {
            showCaptureFrame.setEnabled(true);
            showCaptureFrame.setSelected(true);
            createSelectionFrame();
            showCaptureFrame.setSelected(true);
        }
        viewWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        fullWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        customWindowButton.setBorder(new BevelBorder(BevelBorder.LOWERED));
        originalSize.setEnabled(false);
        constrainSize.setEnabled(false);
        resizeWidth.getTextField().setEnabled(false);
        resizeHeight.getTextField().setEnabled(false);
        resizeSamples.getTextField().setEnabled(false);
        windowWidth.getTextField().setEnabled(true);
        windowHeight.getTextField().setEnabled(true);
        windowXPosition.getTextField().setEnabled(true);
        windowYPosition.getTextField().setEnabled(true);
    } else if (cmd.equals(REC_AUDIO_CMD)) {
        if (recordAudio.isSelected()) {
            System.out.println("rec. audio selected");
            recordAudioTxt.setSelected(false);
        }
        normalizeAudio.setEnabled(recordAudio.isSelected() || recordAudioTxt.isSelected());
    } else if (cmd.equals(REC_AUDIO_TO_TXT_CMD)) {
        if (recordAudioTxt.isSelected()) {
            System.out.println("rec. audio txt selected");
            recordAudio.setSelected(false);
        }
        normalizeAudio.setEnabled(recordAudio.isSelected() || recordAudioTxt.isSelected());
    } else if (cmd.equals(START_CMD)) {
        startMovie();
    } else if (cmd.equals(STOP_CMD)) {
        stopMovie();
    } else if (cmd.equals(CLOSE_CMD)) {
        setVisible(false);
    } else if (cmd.equals(WAYPOINT_CMD)) {
        waypointCapture();
    } else if (cmd.equals(FRAME_CMD)) {
        try {
            myMovieMaker.forceGrab();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (cmd.equals(CUSTOMIZE_CMD)) {
        String methodName = (String) methodSelector.getValue();
        MovieMaker.Method method = myMovieMaker.getMethodMap().get(methodName);
        if (method == null) {
            throw new InternalErrorException("MovieMaker does not know about method " + methodName);
        }
        MethodDialog dialog = new MethodDialog(this, method);
        dialog.setLocationRelativeTo(this);
        dialog.setVisible(true);
    } else if (source == showCaptureFrame) {
        if (showCaptureFrame.isSelected()) {
            createSelectionFrame();
        } else {
            setAreaSelectionFrame(null);
        }
    } else if (source == originalSize) {
        if (originalSize.isSelected()) {
            constrainSize.setEnabled(false);
            resizeWidth.setValue(windowWidth.getIntValue());
            resizeHeight.setValue(windowHeight.getIntValue());
            resizeWidth.getTextField().setEnabled(false);
            resizeHeight.getTextField().setEnabled(false);
            resizeSamples.getTextField().setEnabled(false);
        } else {
            constrainSize.setEnabled(true);
            resizeWidth.getTextField().setEnabled(true);
            resizeHeight.getTextField().setEnabled(true);
            resizeSamples.getTextField().setEnabled(true);
        }
    } else if (cmd.equals("Screenshot")) {
        takeScreenshot();
    } else if (source == constrainSize && constrainSize.isSelected()) {
        double scale = resizeWidth.getDoubleValue() / windowWidth.getDoubleValue();
        resizeHeight.setValue(scale * windowHeight.getIntValue());
        myMovieMaker.setCaptureArea(myMovieMaker.getCaptureArea(), new Dimension((Integer) resizeWidth.getIntValue(), (Integer) resizeHeight.getIntValue()), viewerCapture);
    } else if (source == alwaysOnTop) {
        boolean onTop = alwaysOnTop.isSelected();
        myMovieMaker.setAlwaysOnTop(onTop);
        if (isRecordingStarted) {
            myFrame.setAlwaysOnTop(onTop);
        }
    }
}
Also used : Method(artisynth.core.moviemaker.MovieMaker.Method) BevelBorder(javax.swing.border.BevelBorder) FrameBufferObject(maspack.render.GL.FrameBufferObject) InternalErrorException(maspack.util.InternalErrorException) Dimension(java.awt.Dimension) InternalErrorException(maspack.util.InternalErrorException)

Example 79 with InternalErrorException

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

the class RigidBody method writeItems.

protected void writeItems(PrintWriter pw, NumberFormat fmt, CompositeComponent ancestor) throws IOException {
    getAllPropertyInfo().writeNonDefaultProps(this, pw, fmt);
    pw.println("position=[ " + myState.getPosition().toString(fmt) + "]");
    pw.println("rotation=[ " + myState.getRotation().toString(fmt) + "]");
    // fmt, RigidTransform3d.AXIS_ANGLE_STRING));
    if (!myState.vel.v.equals(zeroVect) || !myState.vel.w.equals(zeroVect)) {
        pw.print("vel=[ ");
        pw.print(myState.vel.toString(fmt));
        pw.println(" ]");
    }
    switch(myInertiaMethod) {
        case Explicit:
            {
                pw.println("inertia=" + mySpatialInertia.toString(fmt, SpatialInertia.MASS_INERTIA_STRING));
                break;
            }
        case Mass:
            {
                pw.println("mass=" + fmt.format(getMass()));
                break;
            }
        case Density:
            {
                pw.println("density=" + fmt.format(getDensity()));
                break;
            }
        default:
            {
                throw new InternalErrorException("Unimplemented inertia method " + myInertiaMethod);
            }
    }
    myMeshInfo.write(pw, fmt);
}
Also used : InternalErrorException(maspack.util.InternalErrorException)

Example 80 with InternalErrorException

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

the class RigidBody method prerender.

public void prerender(RenderList list) {
    myRenderFrame.set(myState.XFrameToWorld);
    // list.addIfVisible (myMarkers);
    PolygonalMesh surf = null;
    if (myRenderDistanceSurface != DistanceSurfaceRendering.NONE && (surf = getDistanceSurface()) != null) {
        surf.prerender(myRenderProps);
    } else {
        if (myRenderProps == null) {
            throw new InternalErrorException("RigidBody has null RenderProps");
        }
        myMeshInfo.prerender(myRenderProps);
    }
    mySDRenderSurface = surf;
    DistanceGrid grid = null;
    if (myRenderDistanceGrid && (grid = getDistanceGrid()) != null) {
        grid.prerender(myRenderProps);
    }
    mySDRenderGrid = grid;
}
Also used : DistanceGrid(maspack.geometry.DistanceGrid) InternalErrorException(maspack.util.InternalErrorException) PolygonalMesh(maspack.geometry.PolygonalMesh)

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