Search in sources :

Example 1 with AddRegionCommand

use of facetmodeller.commands.AddRegionCommand 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)

Aggregations

AddRegionCommand (facetmodeller.commands.AddRegionCommand)1 Command (facetmodeller.commands.Command)1 ReplaceRegionCommand (facetmodeller.commands.ReplaceRegionCommand)1 Group (facetmodeller.groups.Group)1 Region (facetmodeller.plc.Region)1 RegionVector (facetmodeller.plc.RegionVector)1