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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations