Search in sources :

Example 1 with Dragger3d

use of maspack.render.Dragger3d in project artisynth_core by artisynth.

the class MeshThicken method drawToolAdded.

public void drawToolAdded(DrawToolEvent e) {
    Dragger3d tool = e.getSource();
    System.out.println("Added " + tool);
    myEditingRegion = null;
    if (tool instanceof SplineTool) {
        SplineTool splineTool = (SplineTool) tool;
        Region selectedRegion = null;
        for (Region region : myRegions) {
            if (region.isSelected()) {
                selectedRegion = region;
            }
        }
        if (selectedRegion != null) {
            splineTool.setFrame(selectedRegion.myFrame);
            splineTool.setFrameOffset(selectedRegion.myHeight);
            splineTool.setCurve(selectedRegion.myCurve);
            splineTool.setFrameBinding(FrameBinding.INTERNAL_FRAME);
            myEditingRegion = selectedRegion;
        }
    }
}
Also used : SplineTool(maspack.widgets.SplineTool) Dragger3d(maspack.render.Dragger3d)

Example 2 with Dragger3d

use of maspack.render.Dragger3d in project artisynth_core by artisynth.

the class MeshThicken method drawToolEnd.

public void drawToolEnd(DrawToolEvent e) {
    System.out.println("Entered");
    Dragger3d tool = e.getSource();
    if (tool instanceof SplineTool) {
        SplineTool splineTool = (SplineTool) tool;
        NURBSCurve2d curve = splineTool.getCurve();
        if (curve != null) {
            if (myEditingRegion != null) {
                myEditingRegion.setCurve(new NURBSCurve2d(curve));
                myEditingRegion = null;
            } else {
                RigidTransform3d X = new RigidTransform3d();
                splineTool.getToolToWorld(X);
                X.mulXyz(0, 0, -myDefaultRegionHeight);
                Region region = new Region(curve, X, myDefaultRegionHeight);
                region.myMargin = myDefaultRegionMargin;
                region.myThickening = myDefaultRegionThickening;
                region.myUnthickening = myDefaultRegionUnthickening;
                addRegion(region);
            }
        }
        splineTool.clear();
        viewer.rerender();
    }
}
Also used : SplineTool(maspack.widgets.SplineTool) RigidTransform3d(maspack.matrix.RigidTransform3d) NURBSCurve2d(maspack.geometry.NURBSCurve2d) Dragger3d(maspack.render.Dragger3d)

Example 3 with Dragger3d

use of maspack.render.Dragger3d in project artisynth_core by artisynth.

the class GLMouseAdapter method mousePressed.

public void mousePressed(MouseEvent e) {
    int mask = (e.getModifiersEx() & ALL_MODIFIERS);
    int selectionMask = getSelectionButtonMask();
    // Start checking draggers
    Dragger3d drawTool = viewer.myDrawTool;
    boolean grabbed = false;
    if (viewer.myDraggers.size() > 0 || drawTool != null) {
        MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
        for (Dragger3d d : viewer.myDraggers) {
            // pass event to any visible Dragger3dBase, or any other Dragger3d
            if (d.isVisible()) {
                updateDraggerModeAndFlags(mask, d);
                if (d.mousePressed(rayEvt)) {
                    grabbed = true;
                    dragAction = DRAGGER_ACTION;
                    break;
                }
            }
        }
        if (drawTool != null && drawTool.isVisible()) {
            updateDraggerModeAndFlags(mask, drawTool);
            if (drawTool.mousePressed(rayEvt)) {
                grabbed = true;
                dragAction = DRAGGER_ACTION;
            }
        }
    }
    if (grabbed) {
        viewer.repaint();
    } else {
        if (viewer.getEllipticCursorActive() && (mask & ellipticCursorResizeMask) == ellipticCursorResizeMask) {
            dragAction = ELLIPTIC_CURSOR_RESIZE;
            ellipticCursorStartSize = new Vector2d(viewer.getEllipticCursorSize());
        } else if (mask == getTranslateButtonMask()) {
            dragAction = TRANSLATE;
        } else if (mask == getRotateButtonMask()) {
            dragAction = ROTATE;
        } else if (mask == getZoomButtonMask()) {
            dragAction = ZOOM;
        } else if (viewer.isSelectionEnabled() && (mask & selectionMask) == selectionMask) {
            if (viewer.getSelectOnPress()) {
                checkForSelection(e);
                dragAction = NO_ACTION;
                viewer.setDragBox(null);
            } else {
                if (viewer.getEllipticSelection()) {
                    checkForSelection(e);
                }
                dragAction = DRAG_SELECT;
            }
        } else {
            dragAction = NO_ACTION;
        }
    }
    dragStartX = lastX = e.getX();
    dragStartY = lastY = e.getY();
}
Also used : Vector2d(maspack.matrix.Vector2d) MouseRayEvent(maspack.render.MouseRayEvent) Point(java.awt.Point) Dragger3d(maspack.render.Dragger3d)

Example 4 with Dragger3d

use of maspack.render.Dragger3d in project artisynth_core by artisynth.

the class GLMouseAdapter method mouseReleased.

public void mouseReleased(MouseEvent e) {
    // End any dragger modes
    Dragger3d drawTool = viewer.myDrawTool;
    boolean grabbed = false;
    if (dragAction == DRAG_SELECT) {
        checkForSelection(e);
        viewer.setDragBox(null);
    } else if (dragAction == DRAGGER_ACTION) {
        if (viewer.myDraggers.size() > 0 || drawTool != null) {
            MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
            for (Dragger3d d : viewer.myDraggers) {
                // pass event to any visible Dragger3dBase, or any other Dragger3d
                if (d.isVisible()) {
                    if (d.mouseReleased(rayEvt)) {
                        grabbed = true;
                        d.clearFlags();
                        d.setDragMode(DragMode.OFF);
                        break;
                    }
                }
            }
            if (drawTool != null && drawTool.isVisible()) {
                if (drawTool.mouseReleased(rayEvt)) {
                    grabbed = true;
                    drawTool.clearFlags();
                    drawTool.setDragMode(DragMode.OFF);
                }
            }
        }
        if (grabbed) {
            viewer.repaint();
        }
    }
    dragAction = NO_ACTION;
// if (dragAction == NO_ACTION) {
// Dragger3d drawTool = viewer.myDrawTool;
// boolean grabbed = false;
// 
// if (viewer.myDraggers.size() > 0 || drawTool != null) {
// MouseRayEvent rayEvt = MouseRayEvent.create (e, viewer);
// for (Dragger3d d : viewer.myDraggers) {
// // pass event to any visible Dragger3dBase, or any other Dragger3d
// if (d.isVisible()) {
// if (d.mouseReleased (rayEvt)) {
// grabbed = true;
// break;
// }
// }
// }
// if (drawTool != null && drawTool.isVisible()) {
// if (drawTool.mouseReleased (rayEvt)) {
// grabbed = true;
// }
// }
// }
// if (grabbed) {
// viewer.repaint();
// }
// }
// else if (dragAction == DRAG_SELECT) {
// checkForSelection (e);
// viewer.setDragBox (null);
// }
}
Also used : MouseRayEvent(maspack.render.MouseRayEvent) Dragger3d(maspack.render.Dragger3d)

Example 5 with Dragger3d

use of maspack.render.Dragger3d in project artisynth_core by artisynth.

the class GLMouseAdapter method mouseDragged.

public void mouseDragged(MouseEvent e) {
    currentCursor = new Point(e.getX(), e.getY());
    int xOff = e.getX() - lastX, yOff = e.getY() - lastY;
    switch(dragAction) {
        case ROTATE:
            {
                viewer.rotate(-xOff / 200.0, -yOff / 200.0);
                break;
            }
        case ZOOM:
            {
                double r = yOff < 0 ? 0.99 : 1.01;
                double s = Math.pow(r, Math.abs(yOff));
                viewer.zoom(s);
                // viewer.repaint();
                break;
            }
        case TRANSLATE:
            {
                double dpp = viewer.centerDistancePerPixel();
                viewer.translate(dpp * xOff, -dpp * yOff);
                break;
            }
        case DRAGGER_ACTION:
            {
                Dragger3d drawTool = viewer.myDrawTool;
                boolean grabbed = false;
                int mods = e.getModifiersEx() & ALL_MODIFIERS;
                if (viewer.myDraggers.size() > 0 || drawTool != null) {
                    MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
                    for (Dragger3d d : viewer.myDraggers) {
                        // pass to any visible Dragger3dBase, or any other Dragger3d
                        if (d.isVisible()) {
                            updateDraggerFlags(mods, d);
                            if (d.mouseDragged(rayEvt)) {
                                grabbed = true;
                                break;
                            }
                        }
                    }
                    if (drawTool != null && drawTool.isVisible()) {
                        updateDraggerFlags(mods, drawTool);
                        if (drawTool.mouseDragged(rayEvt)) {
                            grabbed = true;
                        }
                    }
                }
                if (grabbed) {
                    viewer.repaint();
                }
                break;
            }
        case DRAG_SELECT:
            {
                if (viewer.getEllipticSelection()) {
                    Vector2d csize = viewer.getEllipticCursorSize();
                    float x = e.getX();
                    float y = e.getY();
                    // Increase to make the program check for selection more often when dragging a circle.
                    int sensitivity = 4;
                    if (Math.abs(x - dragStartX) > csize.x / sensitivity || Math.abs(y - dragStartY) > csize.y / sensitivity) {
                        checkForSelection(e);
                        // viewer.setSelectionCircle(null);
                        dragStartX = (int) x;
                        dragStartY = (int) y;
                    }
                } else {
                    int x = dragStartX;
                    int y = dragStartY;
                    int w = e.getX() - x;
                    int h = e.getY() - y;
                    if (w == 0) {
                        w = 1;
                    } else if (w < 0) {
                        x = e.getX();
                        w = -w;
                    }
                    if (h == 0) {
                        h = 1;
                    } else if (h < 0) {
                        y = e.getY();
                        h = -h;
                    }
                    viewer.setDragBox(new Rectangle(x, y, w, h));
                    viewer.repaint();
                }
                break;
            }
        case ELLIPTIC_CURSOR_RESIZE:
            {
                Vector2d csize = new Vector2d(ellipticCursorStartSize);
                csize.x = Math.max(1, csize.x + e.getX() - dragStartX);
                csize.y = Math.max(1, csize.y + e.getY() - dragStartY);
                viewer.setEllipticCursorSize(csize);
                break;
            }
    }
    if (viewer.getEllipticCursorActive()) {
        viewer.repaint();
    }
    lastX = e.getX();
    lastY = e.getY();
}
Also used : Vector2d(maspack.matrix.Vector2d) MouseRayEvent(maspack.render.MouseRayEvent) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point) Dragger3d(maspack.render.Dragger3d)

Aggregations

Dragger3d (maspack.render.Dragger3d)11 Point (java.awt.Point)7 MouseRayEvent (maspack.render.MouseRayEvent)5 Vector2d (maspack.matrix.Vector2d)2 GLClipPlane (maspack.render.GL.GLClipPlane)2 RenderList (maspack.render.RenderList)2 SplineTool (maspack.widgets.SplineTool)2 GL2 (com.jogamp.opengl.GL2)1 Rectangle (java.awt.Rectangle)1 NURBSCurve2d (maspack.geometry.NURBSCurve2d)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 DragMode (maspack.render.Dragger3d.DragMode)1