Search in sources :

Example 1 with Command

use of facetmodeller.commands.Command in project facetmodeller by pglelievre.

the class DefineRegionClickTask method mouseClick.

@Override
public void mouseClick(MyPoint2D p) {
    // Check for the required information:
    if (!check()) {
        return;
    }
    if (p == null) {
        return;
    }
    // Get the current group:
    Group group = controller.getSelectedCurrentGroup();
    // Check if regions already exist in the current group and ask user what to do:
    boolean deleteRegions = false;
    if (group.numberOfRegions() != 0) {
        String message = "Do you want to delete the current region(s) in the group?";
        int response = Dialogs.question(controller, message, title());
        if (response == Dialogs.CANCEL_OPTION) {
            return;
        }
        if (response == Dialogs.YES_OPTION) {
            deleteRegions = true;
        }
    }
    // Ask if this is a regular region point or a control point:
    int response = Dialogs.question(controller, "What type of point is this?", title(), "Region", "Control", "Cancel");
    boolean isCon;
    switch(response) {
        case Dialogs.YES_OPTION:
            // region point
            isCon = false;
            break;
        case Dialogs.NO_OPTION:
            // control point
            isCon = true;
            break;
        default:
            // user cancelled
            return;
    }
    // Create a new region object linked to the current section and current group:
    Region newRegion = new Region(isCon, p, controller.getSelectedCurrentSection(), group);
    // Add the region, deleting the current regions if requested:
    Command com;
    if (deleteRegions) {
        RegionVector regions = group.getRegions();
        com = new ReplaceRegionCommand(controller.getModelManager(), regions, newRegion);
    } else {
        com = new AddRegionCommand(controller.getModelManager(), newRegion);
    }
    com.execute();
    controller.undoVectorAdd(com);
    // Enable or disable menu items:
    controller.checkItemsEnabled();
    // Repaint:
    controller.redraw();
}
Also used : Group(facetmodeller.groups.Group) Command(facetmodeller.commands.Command) ReplaceRegionCommand(facetmodeller.commands.ReplaceRegionCommand) AddRegionCommand(facetmodeller.commands.AddRegionCommand) Region(facetmodeller.plc.Region) RegionVector(facetmodeller.plc.RegionVector) AddRegionCommand(facetmodeller.commands.AddRegionCommand) ReplaceRegionCommand(facetmodeller.commands.ReplaceRegionCommand)

Example 2 with Command

use of facetmodeller.commands.Command in project facetmodeller by pglelievre.

the class UndoPreviousCommandMenuTask method execute.

@Override
public void execute() {
    // Check for the required information:
    if (!check()) {
        return;
    }
    // Get the previous command:
    Command command = controller.undoVectorGet();
    // Check we can undo:
    if (command == null) {
        Dialogs.inform(controller, "There is nothing to undo.", title());
        return;
    }
    // Ask for confirmation:
    String prompt = "This will undo the most recent \"" + command.getName() + "\" command.";
    int response = Dialogs.continueCancel(controller, prompt, title());
    if (response != Dialogs.OK_OPTION) {
        return;
    }
    // Remove the previous command from the undo information vector:
    controller.undoVectorRemove();
    // Undo the command:
    command.undo();
    // Enable or disable menu items:
    controller.checkItemsEnabled();
    // Repaint:
    controller.redraw();
}
Also used : Command(facetmodeller.commands.Command)

Example 3 with Command

use of facetmodeller.commands.Command in project facetmodeller by pglelievre.

the class MarkNodeClickTask method mouseClick.

@Override
public void mouseClick(MyPoint2D p) {
    // Check for the required information:
    if (!check()) {
        return;
    }
    if (p == null) {
        return;
    }
    // Calculate the closest node to the clicked point:
    if (!controller.calculateClosestNode(p)) {
        return;
    }
    // just in case the closestNode object gets nullified by a mouse move (not sure if that is possible but better safe than sorry)
    Node node = controller.getClosestNode();
    if (node == null) {
        return;
    }
    // Perform the change:
    Command com;
    if (opt > 0) {
        com = new SetNodeBoundaryMarkerCommand(node, true);
    } else if (opt < 0) {
        com = new SetNodeBoundaryMarkerCommand(node, false);
    } else {
        // opt==0
        com = new ToggleNodeBoundaryMarkerCommand(node);
    }
    com.execute();
    controller.undoVectorAdd(com);
    // Enable or disable menu items:
    controller.checkItemsEnabled();
    // Repaint:
    // (or else the old closest node point will be painted)
    controller.clearClosestNode();
    controller.redraw();
}
Also used : ToggleNodeBoundaryMarkerCommand(facetmodeller.commands.ToggleNodeBoundaryMarkerCommand) Command(facetmodeller.commands.Command) SetNodeBoundaryMarkerCommand(facetmodeller.commands.SetNodeBoundaryMarkerCommand) ToggleNodeBoundaryMarkerCommand(facetmodeller.commands.ToggleNodeBoundaryMarkerCommand) Node(facetmodeller.plc.Node) SetNodeBoundaryMarkerCommand(facetmodeller.commands.SetNodeBoundaryMarkerCommand)

Example 4 with Command

use of facetmodeller.commands.Command in project facetmodeller by pglelievre.

the class ChangeNodeCoordsClickTask method mouseClick.

@Override
public void mouseClick(MyPoint2D p) {
    // Check for the required information:
    if (!check()) {
        return;
    }
    if (p == null) {
        return;
    }
    // Calculate the closest node to the clicked point:
    if (!controller.calculateClosestNode(p)) {
        return;
    }
    // just in case the closestNode object gets nullified by a mouse move (not sure if that is possible but better safe than sorry)
    Node node = controller.getClosestNode();
    if (node == null) {
        return;
    }
    // Nullify temporary objects:
    // (or else the old closest node point will be painted)
    controller.clearClosestNode();
    // Check for on-section node:
    boolean do3D = true;
    if (!node.isOff()) {
        // Ask user how to continue:
        int response = Dialogs.question(controller, "What coordinates do you want to specify for this on-section node?", title(), "3D spatial", "2D pixel", "Cancel");
        if (response == Dialogs.CANCEL_OPTION) {
            return;
        }
        do3D = (response == Dialogs.YES_OPTION);
        if (do3D) {
            response = Dialogs.confirm(controller, "The node will be changed to a 3D off-section node.", title());
            if (response != Dialogs.OK_OPTION) {
                return;
            }
        }
    }
    // Do whatever is required:
    Command com;
    if (do3D) {
        // it's an off-section node, or we're converting an no-section node to an off-section node, and we're changing the 3D spatial coordinates
        // Get the node's existing 3D coordinates:
        MyPoint3D p3 = node.getPoint3D();
        // Ask the user for the new node coordinates:
        String message = "You must enter three numeric values separated by spaces. Please try again.";
        String prompt = "Enter the new 3D spatial coordinates (x y z) for the node, separated by spaces:";
        String input = Dialogs.input(controller, prompt, title(), p3.toString());
        // user cancelled
        if (input == null) {
            return;
        }
        input = input.trim();
        String[] s;
        s = input.split("[ ]+");
        if (s.length != 3) {
            Dialogs.error(controller, message, title());
            return;
        }
        double x, y, z;
        try {
            x = Double.parseDouble(s[0].trim());
            y = Double.parseDouble(s[1].trim());
            z = Double.parseDouble(s[2].trim());
        } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
            Dialogs.error(controller, message, title());
            return;
        }
        // Create a new 3D point object:
        p3 = new MyPoint3D(x, y, z);
        if (node.isOff()) {
            // Change the 3D spatial coordinates of the off-section node:
            com = new ChangeNodeCoordinateCommand((NodeOffSection) node, p3);
            com.execute();
        } else {
            // Create a new off-section node object at the specified 3D spatial coordinates, attached to the same section and group as the old node:
            Node newNode = new NodeOffSection(p3, node.getSection(), node.getGroup());
            // Replace the old node with the new node:
            com = new MergeNodesCommand(controller.getModelManager(), node, newNode, title());
            com.execute();
        }
    } else {
        // it's an on-section node and we're changing the 2D pixel coordinates
        // Get the node's existing 2D coordinates:
        MyPoint2D p2 = node.getPoint2D();
        // Ask the user for the new node coordinates:
        String message = "You must enter two numeric values separated by spaces. Please try again.";
        String prompt = "Enter the new 2D pixel coordinates (x y) for the node, separated by spaces:";
        String input = Dialogs.input(controller, prompt, title(), p2.toString());
        // user cancelled
        if (input == null) {
            return;
        }
        input = input.trim();
        String[] s;
        s = input.split("[ ]+");
        if (s.length != 2) {
            Dialogs.error(controller, message, title());
            return;
        }
        double x, y;
        try {
            x = Double.parseDouble(s[0].trim());
            y = Double.parseDouble(s[1].trim());
        } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
            Dialogs.error(controller, message, title());
            return;
        }
        // Create a new 2D point object:
        p2 = new MyPoint2D(x, y);
        // Change the 2D pixel coordinates of the on-section node:
        com = new ChangeNodeCoordinateCommand((NodeOnSection) node, p2);
        com.execute();
    }
    // Add the command to the undo information:
    controller.undoVectorAdd(com);
    // Enable or disable menu items:
    controller.checkItemsEnabled();
    // Repaint:
    controller.redraw();
}
Also used : Node(facetmodeller.plc.Node) NodeOffSection(facetmodeller.plc.NodeOffSection) ChangeNodeCoordinateCommand(facetmodeller.commands.ChangeNodeCoordinateCommand) MyPoint2D(geometry.MyPoint2D) NodeOnSection(facetmodeller.plc.NodeOnSection) MyPoint3D(geometry.MyPoint3D) MergeNodesCommand(facetmodeller.commands.MergeNodesCommand) Command(facetmodeller.commands.Command) MergeNodesCommand(facetmodeller.commands.MergeNodesCommand) ChangeNodeCoordinateCommand(facetmodeller.commands.ChangeNodeCoordinateCommand)

Example 5 with Command

use of facetmodeller.commands.Command in project facetmodeller by pglelievre.

the class MarkFacetClickTask method mouseClick.

@Override
public void mouseClick(MyPoint2D p) {
    // Check for the required information:
    if (!check()) {
        return;
    }
    if (p == null) {
        return;
    }
    // Calculate the closest facet to the clicked point:
    if (!controller.calculateClosestFacet(p)) {
        return;
    }
    // just in case the closestFacet object gets nullified by a mouse move (not sure if that is possible but better safe than sorry)
    Facet facet = controller.getClosestFacet();
    if (facet == null) {
        return;
    }
    // Perform the change:
    Command com;
    if (opt > 0) {
        com = new SetFacetBoundaryMarkerCommand(facet, true);
    } else if (opt < 0) {
        com = new SetFacetBoundaryMarkerCommand(facet, false);
    } else {
        // opt==0
        com = new ToggleFacetBoundaryMarkerCommand(facet);
    }
    com.execute();
    controller.undoVectorAdd(com);
    // Enable or disable menu items:
    controller.checkItemsEnabled();
    // Repaint:
    // (or else the old closest facet point will be painted)
    controller.clearClosestFacet();
    controller.redraw();
}
Also used : SetFacetBoundaryMarkerCommand(facetmodeller.commands.SetFacetBoundaryMarkerCommand) Command(facetmodeller.commands.Command) ToggleFacetBoundaryMarkerCommand(facetmodeller.commands.ToggleFacetBoundaryMarkerCommand) SetFacetBoundaryMarkerCommand(facetmodeller.commands.SetFacetBoundaryMarkerCommand) ToggleFacetBoundaryMarkerCommand(facetmodeller.commands.ToggleFacetBoundaryMarkerCommand) Facet(facetmodeller.plc.Facet)

Aggregations

Command (facetmodeller.commands.Command)5 Node (facetmodeller.plc.Node)2 AddRegionCommand (facetmodeller.commands.AddRegionCommand)1 ChangeNodeCoordinateCommand (facetmodeller.commands.ChangeNodeCoordinateCommand)1 MergeNodesCommand (facetmodeller.commands.MergeNodesCommand)1 ReplaceRegionCommand (facetmodeller.commands.ReplaceRegionCommand)1 SetFacetBoundaryMarkerCommand (facetmodeller.commands.SetFacetBoundaryMarkerCommand)1 SetNodeBoundaryMarkerCommand (facetmodeller.commands.SetNodeBoundaryMarkerCommand)1 ToggleFacetBoundaryMarkerCommand (facetmodeller.commands.ToggleFacetBoundaryMarkerCommand)1 ToggleNodeBoundaryMarkerCommand (facetmodeller.commands.ToggleNodeBoundaryMarkerCommand)1 Group (facetmodeller.groups.Group)1 Facet (facetmodeller.plc.Facet)1 NodeOffSection (facetmodeller.plc.NodeOffSection)1 NodeOnSection (facetmodeller.plc.NodeOnSection)1 Region (facetmodeller.plc.Region)1 RegionVector (facetmodeller.plc.RegionVector)1 MyPoint2D (geometry.MyPoint2D)1 MyPoint3D (geometry.MyPoint3D)1