Search in sources :

Example 26 with ModelComponent

use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.

the class HydrostatModel method createTargetList.

public ArrayList<ModelComponent> createTargetList() {
    double l = getXdirLength();
    ArrayList<ModelComponent> targetNodes = new ArrayList<ModelComponent>();
    for (FemNode n : myNodes) {
        if (n.getPosition().x < -l / 2 + eps) {
            if (myShape == Shape.Tube) {
                double r2 = n.getPosition().y * n.getPosition().y + n.getPosition().z * n.getPosition().z;
                if (Math.sqrt(r2) <= 2 * rin)
                    continue;
            }
            targetNodes.add(n);
            if (simpleMuscleGroupingsP)
                break;
        }
    }
    return targetNodes;
}
Also used : FemNode(artisynth.core.femmodels.FemNode) ModelComponent(artisynth.core.modelbase.ModelComponent) ArrayList(java.util.ArrayList)

Example 27 with ModelComponent

use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.

the class Main method setDragger.

private void setDragger() {
    translator3d.setVisible(false);
    transrotator3d.setVisible(false);
    scalar3d.setVisible(false);
    rotator3d.setVisible(false);
    constrainedTranslator3d.setVisible(false);
    constrainedTranslator3d.setMesh(null);
    currentDragger = null;
    myDraggableComponents.clear();
    if (mySelectionMode != SelectionMode.Select && mySelectionMode != SelectionMode.EllipticSelect && mySelectionMode != SelectionMode.Pull) {
        Point3d pmin = new Point3d(inf, inf, inf);
        Point3d pmax = new Point3d(-inf, -inf, -inf);
        int n = 0;
        for (ModelComponent sel : mySelectionManager.getCurrentSelection()) {
            if (sel instanceof Renderable && sel instanceof TransformableGeometry && !ComponentUtils.isAncestorSelected(sel)) {
                myDraggableComponents.add(sel);
                ((Renderable) sel).updateBounds(pmin, pmax);
                n++;
            }
        }
        if (n > 0) {
            RigidTransform3d TDW = new RigidTransform3d();
            double radius = computeDraggerToWorld(TDW, myDraggableComponents, null);
            // set a minimum radius to about 1/6 of the viewer window width
            radius = Math.max(radius, myViewer.distancePerPixel(myViewer.getCenter()) * myViewer.getScreenWidth() / 6);
            if (mySelectionMode == SelectionMode.Translate) {
                translator3d.setVisible(true);
                translator3d.setDraggerToWorld(TDW);
                translator3d.setSize(radius);
                currentDragger = translator3d;
            } else if (mySelectionMode == SelectionMode.Transrotate) {
                transrotator3d.setVisible(true);
                transrotator3d.setDraggerToWorld(TDW);
                transrotator3d.setSize(radius);
                currentDragger = transrotator3d;
            } else if (mySelectionMode == SelectionMode.Scale) {
                scalar3d.setVisible(true);
                scalar3d.setDraggerToWorld(TDW);
                scalar3d.setSize(radius);
                currentDragger = scalar3d;
            } else if (mySelectionMode == SelectionMode.Rotate) {
                rotator3d.setVisible(true);
                rotator3d.setDraggerToWorld(TDW);
                rotator3d.setSize(radius);
                currentDragger = rotator3d;
            } else if (mySelectionMode == SelectionMode.ConstrainedTranslate) {
                PolygonalMesh mesh = null;
                for (Object sel : mySelectionManager.getCurrentSelection()) {
                    if (sel instanceof FrameMarker) {
                        FrameMarker frameMarker = (FrameMarker) sel;
                        Point3d p = new Point3d(frameMarker.getPosition());
                        constrainedTranslator3d.setLocation(p);
                        Frame frame = frameMarker.getFrame();
                        if (frame instanceof RigidBody) {
                            mesh = ((RigidBody) frame).getMesh();
                        }
                        break;
                    }
                }
                if (mesh != null) {
                    constrainedTranslator3d.setSize(radius);
                    constrainedTranslator3d.setMesh(mesh);
                    constrainedTranslator3d.setVisible(true);
                    currentDragger = constrainedTranslator3d;
                }
            }
        }
    }
}
Also used : TransformableGeometry(artisynth.core.modelbase.TransformableGeometry) OrientedTransformableGeometry(artisynth.core.modelbase.OrientedTransformableGeometry) RigidTransform3d(maspack.matrix.RigidTransform3d) JFrame(javax.swing.JFrame) GLViewerFrame(maspack.render.GL.GLViewerFrame) Frame(artisynth.core.mechmodels.Frame) HasCoordinateFrame(artisynth.core.modelbase.HasCoordinateFrame) Renderable(maspack.render.Renderable) ModelComponent(artisynth.core.modelbase.ModelComponent) FrameMarker(artisynth.core.mechmodels.FrameMarker) Point3d(maspack.matrix.Point3d) RigidBody(artisynth.core.mechmodels.RigidBody) PolygonalMesh(maspack.geometry.PolygonalMesh) WayPoint(artisynth.core.probes.WayPoint)

Example 28 with ModelComponent

use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.

the class Main method centerViewOnSelection.

void centerViewOnSelection() {
    Point3d center = new Point3d();
    Point3d pmin = new Point3d(inf, inf, inf);
    Point3d pmax = new Point3d(-inf, -inf, -inf);
    int n = 0;
    ModelComponent firstComp = null;
    for (ModelComponent sel : mySelectionManager.getCurrentSelection()) {
        if (sel instanceof Renderable && !ComponentUtils.isAncestorSelected(sel)) {
            if (firstComp == null) {
                firstComp = sel;
            }
            ((Renderable) sel).updateBounds(pmin, pmax);
            n++;
        }
    }
    if (n > 0) {
        if (n == 1 && firstComp instanceof HasCoordinateFrame) {
            RigidTransform3d X = new RigidTransform3d();
            ((HasCoordinateFrame) firstComp).getPose(X);
            center.set(X.p);
        } else {
            center.add(pmin, pmax);
            center.scale(0.5);
        }
        myViewer.setCenter(center);
        rerender();
    }
}
Also used : HasCoordinateFrame(artisynth.core.modelbase.HasCoordinateFrame) RigidTransform3d(maspack.matrix.RigidTransform3d) Renderable(maspack.render.Renderable) ModelComponent(artisynth.core.modelbase.ModelComponent) Point3d(maspack.matrix.Point3d) WayPoint(artisynth.core.probes.WayPoint)

Example 29 with ModelComponent

use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.

the class MenuBarHandler method actionPerformed.

/**
 * action performed to process all the menu and button actions in this class
 */
public void actionPerformed(ActionEvent event) {
    String cmd = event.getActionCommand();
    // Scripts menu
    if (isScriptMenuItem(event.getSource())) {
        String scriptName = myMain.getScriptName(cmd);
        runScript(scriptName);
    } else if (cmd.equals("load script from file")) {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setCurrentDirectory(ArtisynthPath.getWorkingDir());
        FileFilter jythonFilter = new GenericFileFilter(new String[] { "py", "jy" }, "Jython files");
        fileChooser.addChoosableFileFilter(jythonFilter);
        fileChooser.setFileFilter(jythonFilter);
        int result = fileChooser.showOpenDialog(myFrame);
        if (result == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();
            runScript(selectedFile.getAbsolutePath());
        }
    } else // 
    if (myMain.isDemoClassName(cmd)) {
        ModelInfo mi = new ModelInfo(myMain.getDemoClassName(cmd), cmd, null);
        doLoadModelSafely(mi);
    } else // 
    if (cmd.equals("Clear model")) {
        doClearModel();
    } else if (cmd.equals("New blank MechModel")) {
        doBlankMechmodel();
    } else if (cmd.equals("Save model")) {
        doSaveModel();
    } else if (cmd.equals("Save model as ...")) {
        doSaveModelAs();
    } else if (cmd.equals("Reload model")) {
        doReloadModel();
    } else if (cmd.equals("Load model ...")) {
        doLoadModel();
    } else if (cmd.equals("Load from class ...")) {
        doLoadFromClass();
    } else if (cmd.equals("Switch workspace ...")) {
        doSwitchWorkspace();
    } else if (cmd.equals("Open MATLAB connection")) {
        doOpenMatlab();
    } else if (cmd.equals("Close MATLAB connection")) {
        doCloseMatlab();
    } else if (cmd.equals("Load probes ...")) {
        doLoadProbes();
    } else if (cmd.equals("Save probes")) {
        doSaveProbes();
    } else if (cmd.equals("Save probes as ...")) {
        doSaveProbesAs();
    } else if (cmd.equals("Load probes from ...")) {
        newLoadProbesFrom();
    } else if (cmd.equals("Save probes new")) {
        newSaveProbes();
    } else if (cmd.equals("Save probes in ...")) {
        newSaveProbesIn();
    } else if (cmd.equals("Save viewer image ...")) {
        saveViewerImage();
    } else if (cmd.equals("Quit")) {
        myMain.quit();
    } else // 
    if (cmd.equals("Add input probe")) {
        doAddInputProbe();
    } else if (cmd.equals("Add output probe")) {
        doAddOutputProbe();
    } else if (cmd.equals("Add control panel")) {
        doAddControlPanel();
    } else if (cmd.equals("Load control panel")) {
        doLoadControlPanel();
    } else if (cmd.equals("Print selection")) {
        SelectionManager sm = myMain.getSelectionManager();
        for (ModelComponent c : sm.getCurrentSelection()) {
            System.out.println(ComponentUtils.getPathName(c));
        }
    } else if (cmd.equals("Undo")) {
        doUndoCommand();
    } else // 
    if (cmd.equals("Background color")) {
        setBackgroundColor();
    } else if (cmd.equals("Selection color")) {
        setSelectionColor();
    } else if (cmd.equals("Enable selection highlighting")) {
        setSelectionColorEnabled(true);
    } else if (cmd.equals("Disable selection highlighting")) {
        setSelectionColorEnabled(false);
    } else if (cmd.equals("Visual display rate")) {
        setVisualDisplayRate();
    } else if (cmd.equals("Real-time scaling")) {
        setRealTimeScaling();
    } else if (cmd.equals("Mouse Preferences ...")) {
        openMouseSettingsDialog();
    } else if (cmd.equals("Init draggers in world coords")) {
        myMain.setInitDraggersInWorldCoords(true);
    } else if (cmd.equals("Init draggers in local coords")) {
        myMain.setInitDraggersInWorldCoords(false);
    } else if (cmd.equals("Enable articulated transforms")) {
        myMain.setArticulatedTransformsEnabled(true);
    } else if (cmd.equals("Disable articulated transforms")) {
        myMain.setArticulatedTransformsEnabled(false);
    } else // }
    if (cmd.equals("PullController properties ...")) {
        showPullControllerPropertyDialog();
    } else if (cmd.equals("PullController render props ...")) {
        showPullControllerRenderPropsDialog();
    } else // 
    if (cmd.equals("Center view on selection")) {
        myMain.centerViewOnSelection();
    } else if (cmd.equals("Hide timeline")) {
        myMain.setTimelineVisible(false);
        isTimelineVisible = false;
    } else if (cmd.equals("Show timeline")) {
        myMain.setTimelineVisible(true);
        isTimelineVisible = true;
    } else if (cmd.equals("Reset view")) {
        GLViewer v = myMain.getViewer();
        v.setAxialView(v.getAxialView());
        v.autoFit();
    } else if (cmd.equals("Perspective view")) {
        myMain.getViewer().setOrthographicView(false);
    } else if (cmd.equals("Orthographic view")) {
        myMain.getViewer().setOrthographicView(true);
    } else if (cmd.equals("Hide Jython console")) {
        setJythonConsoleVisible(false);
    } else if (cmd.equals("Show Jython console")) {
        setJythonConsoleVisible(true);
    } else if (cmd.equals("Show Inverse panel")) {
        myMain.getInverseManager().showInversePanel(myMain.getRootModel(), InverseManager.findInverseController());
    } else if (cmd.equals("Hide Inverse panel")) {
        myMain.getInverseManager().hideInversePanel();
    } else if (cmd.equals("Show movie panel")) {
        myFrame.getMain().getViewer().getCanvas().display();
        myMain.getMovieMaker().showDialog(myFrame);
    } else if (cmd.equals("Hide movie panel")) {
        // TODO: this isn't implemented yet because we need to set
        // this up as an action
        myMain.getMovieMaker().closeDialog();
    } else if (cmd.equals("Show empty components in navpanel")) {
        myFrame.getNavPanel().setHideEmptyComponents(false);
    } else if (cmd.equals("Hide empty components in navpanel")) {
        myFrame.getNavPanel().setHideEmptyComponents(true);
    } else if (cmd.equals("New viewer")) {
        myMain.createViewerFrame();
    } else if (cmd.equals("Clear traces")) {
        myMain.getRootModel().clearTraces();
    } else if (cmd.equals("Disable all tracing")) {
        myMain.getRootModel().disableAllTracing();
    } else if (cmd.equals("Remove traces")) {
        RemoveComponentsCommand rmCmd = new RemoveComponentsCommand("remove traces", myMain.getRootModel().getTracingProbes());
        myMain.getUndoManager().saveStateAndExecute(rmCmd);
        myMain.rerender();
    } else if (cmd.equals("Set traces visible")) {
        myMain.getRootModel().setTracingProbesVisible(true);
        myMain.rerender();
    } else if (cmd.equals("Set traces invisible")) {
        myMain.getRootModel().setTracingProbesVisible(false);
        myMain.rerender();
    } else if (cmd.equals("Hide viewer toolbar")) {
        isToolbarVisible = false;
        detachViewerToolbar(toolbarPanel);
    } else if (cmd.equals("Show viewer toolbar")) {
        isToolbarVisible = true;
        attachViewerToolbar(toolbarPanel);
    } else if (cmd.equals("Merge control panels")) {
        myMain.getRootModel().mergeAllControlPanels(true);
    } else if (cmd.equals("Separate control panels")) {
        myMain.getRootModel().mergeAllControlPanels(false);
    } else if (cmd.equals("Show progress")) {
        spawnProgressBar();
    } else // 
    if (cmd.equals("About ArtiSynth")) {
        myFrame.displayAboutArtisynth();
    } else if (cmd.equals("About the current model")) {
        myFrame.displayAboutModel(myMain.getRootModel());
    } else if (cmd.equals("Keybindings")) {
        myFrame.displayKeybindings();
    } else // 
    if (cmd.equals("Hide NavBar")) {
        myFrame.getNavPanel().setStatus(!myFrame.getNavPanel().getStatus());
        myFrame.refreshSplitPane();
        navBarButton.setToolTipText("Show Navbar");
        navBarButton.setActionCommand("Show Navbar");
    } else if (cmd.equals("Show Navbar")) {
        myFrame.getNavPanel().setStatus(!myFrame.getNavPanel().getStatus());
        myFrame.refreshSplitPane();
        navBarButton.setToolTipText("Hide NavBar");
        navBarButton.setActionCommand("Hide NavBar");
    } else if (cmd.equals("Re-render")) {
        myMain.rerender();
    } else if (cmd.equals("Reset")) {
        myMain.getScheduler().reset();
    } else if (cmd.equals("Rewind")) {
        myMain.getScheduler().rewind();
    } else if (cmd.equals("Play")) {
        myMain.getScheduler().play();
    } else if (cmd.equals("Pause")) {
        myMain.getScheduler().pause();
    } else if (cmd.equals("Single step")) {
        myMain.getScheduler().step();
    } else if (cmd.equals("Fast forward")) {
        myMain.getScheduler().fastForward();
    } else if (cmd.equals("cancel")) {
        return;
    } else {
        throw new InternalErrorException("Unimplemented command: " + cmd);
    }
}
Also used : SelectionManager(artisynth.core.gui.selectionManager.SelectionManager) GLViewer(maspack.render.GL.GLViewer) JFileChooser(javax.swing.JFileChooser) ModelComponent(artisynth.core.modelbase.ModelComponent) RemoveComponentsCommand(artisynth.core.gui.editorManager.RemoveComponentsCommand) GenericFileFilter(maspack.util.GenericFileFilter) InternalErrorException(maspack.util.InternalErrorException) ExtensionFileFilter(artisynth.core.util.ExtensionFileFilter) GenericFileFilter(maspack.util.GenericFileFilter) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 30 with ModelComponent

use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.

the class AuxMaterialElementDescList method dorender.

private void dorender(Renderer renderer, int flags, boolean selected) {
    // This code is taken mostly verbatim from FemElement3dList.
    // Should find a way to avoid duplicate code ...
    double fractionRenderRadius = 0;
    FractionRenderType fractionRenderType = AuxMaterialBundle.DEFAULT_FRACTION_RENDER_TYPE;
    ModelComponent parent = getParent();
    if (parent instanceof AuxMaterialBundle) {
        fractionRenderRadius = ((AuxMaterialBundle) parent).getFractionRenderRadius();
        fractionRenderType = ((AuxMaterialBundle) parent).getFractionRenderType();
    }
    if (fractionRenderRadius > 0) {
        Shading savedShading = renderer.getShading();
        renderer.setShading(myRenderProps.getShading());
        renderer.setPointColoring(myRenderProps, /*highlight=*/
        false);
        renderFractions(renderer, fractionRenderRadius, fractionRenderType, false);
        renderer.setShading(savedShading);
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) Shading(maspack.render.Renderer.Shading) FractionRenderType(artisynth.core.femmodels.AuxMaterialBundle.FractionRenderType)

Aggregations

ModelComponent (artisynth.core.modelbase.ModelComponent)53 RootModel (artisynth.core.workspace.RootModel)9 Property (maspack.properties.Property)8 CompositeComponent (artisynth.core.modelbase.CompositeComponent)5 ArrayList (java.util.ArrayList)5 Point (artisynth.core.mechmodels.Point)4 Renderable (maspack.render.Renderable)4 InternalErrorException (maspack.util.InternalErrorException)4 HasCoordinateFrame (artisynth.core.modelbase.HasCoordinateFrame)3 Traceable (artisynth.core.modelbase.Traceable)3 WayPoint (artisynth.core.probes.WayPoint)3 Point (java.awt.Point)3 LinkedList (java.util.LinkedList)3 CompositeProperty (maspack.properties.CompositeProperty)3 FractionRenderType (artisynth.core.femmodels.AuxMaterialBundle.FractionRenderType)2 FemModel3d (artisynth.core.femmodels.FemModel3d)2 HexElement (artisynth.core.femmodels.HexElement)2 DirectionRenderType (artisynth.core.femmodels.MuscleBundle.DirectionRenderType)2 RemoveComponentsCommand (artisynth.core.gui.editorManager.RemoveComponentsCommand)2 ExcitationComponent (artisynth.core.mechmodels.ExcitationComponent)2