use of facetmodeller.commands.AddNodeCommandVector in project facetmodeller by pglelievre.
the class DefineNodesSectionMenuTask method execute.
@Override
public void execute() {
// Check for the required information:
if (!check()) {
return;
}
// Define 8 new on-section nodes:
Section currentSection = controller.getSelectedCurrentSection();
Group currentGroup = controller.getSelectedCurrentGroup();
if (currentSection == null) {
return;
}
if (currentGroup == null) {
return;
}
NodeVector nodes = new NodeVector();
MyPoint2DVector p = currentSection.getCorners();
if (p == null) {
return;
}
int n = p.size();
if (n != 4) {
return;
}
for (int i = 0; i < n; i++) {
// new node is not added to the section or group yet
nodes.add(new NodeOnSection(p.get(i), currentSection, currentGroup));
}
// Add the nodes:
// adds each node to its section and group
AddNodeCommandVector com = new AddNodeCommandVector(controller.getModelManager(), nodes, "");
// adds each node to its section and group
com.execute();
controller.undoVectorAdd(com);
// Enable or disable menu items:
controller.checkItemsEnabled();
// Repaint:
controller.redraw();
}
use of facetmodeller.commands.AddNodeCommandVector in project facetmodeller by pglelievre.
the class FileIOManager method loadNodeAndEle.
public String loadNodeAndEle(NoImageDepthSection section) {
// Get the node and ele files:
File nodeFile = section.getNodeFile();
File eleFile = section.getEleFile();
// Check for a node file:
if (nodeFile == null) {
return null;
}
// Read the node file:
NodeVector nodes = new NodeVector();
NodeVector.ReadNodesReturnObject readNodesReturnObj = nodes.readNodes(nodeFile, -2);
String errmsg = readNodesReturnObj.getErrmsg();
if (errmsg != null) {
return errmsg + System.lineSeparator() + nodeFile;
}
// Get number of dimensions:
int ndim = controller.numberOfDimensions();
// Read the ele file if present:
FacetVector facets = new FacetVector();
if (eleFile != null) {
int startInd = readNodesReturnObj.getStartingIndex();
FacetVector.ReadFacetsReturnObject readFacetsReturnObj = facets.readEle(controller, "", eleFile, startInd, nodes, ndim, false);
errmsg = readFacetsReturnObj.getErrmsg();
if (errmsg != null) {
return errmsg + System.lineSeparator() + eleFile;
}
// Delete any unrequired nodes:
if (readFacetsReturnObj.getDoRem()) {
nodes.removeUnused();
}
}
// Define a new group for the nodes and facets:
Group group = new Group("TOPOGRAPHY");
// Add section and group membership to the new nodes and optional facets:
nodes.setSection(section);
nodes.setGroup(group);
facets.setGroup(group);
// Calculate the range of the nodes:
MyPoint3D p1 = nodes.rangeMin();
MyPoint3D p2 = nodes.rangeMax();
// Add a little padding:
// HARDWIRE
p1.times(1.1);
// HARDWIRE
p2.times(1.1);
// Calibrate the section:
double x1 = p1.getX();
double x2 = p2.getX();
double y1 = p1.getY();
double y2 = p2.getY();
double z1 = p1.getZ();
double z2 = p2.getZ();
// corresponds to top left pixel (0,0)
section.setTyped1(new MyPoint3D(x1, y2, z1));
// corresponds to bottom right pixel (height,width)
section.setTyped2(new MyPoint3D(x2, y1, z2));
// Add the new group:
new AddGroupCommand(controller, group, 0).execute();
// Add the new nodes and optional facets to the plc, section, group:
ModelManager model = controller.getModelManager();
new AddNodeCommandVector(model, nodes, "").execute();
new AddFacetCommandVector(model, facets).execute();
// Return successfully:
return null;
}
use of facetmodeller.commands.AddNodeCommandVector in project facetmodeller by pglelievre.
the class LoadNodesAndFacetsMenuTask method execute.
@Override
public void execute() {
// Check for the required information:
if (!check()) {
return;
}
// Get the current section and group:
Section currentSection = controller.getSelectedCurrentSection();
Group currentGroup = controller.getSelectedCurrentGroup();
// Check the current section is appropriate for adding off-section nodes to:
if (currentSection instanceof SnapshotSection) {
Dialogs.error(controller, "You can't add nodes to a snapshot section.", title());
return;
}
// Ask for the name of the .node file:
JFileChooser chooser = new JFileChooser();
NodeFilter nodeFilter = new NodeFilter();
chooser.setCurrentDirectory(controller.getOpenDirectory());
chooser.addChoosableFileFilter(nodeFilter);
chooser.setFileFilter(nodeFilter);
chooser.setDialogTitle("Select .node file");
chooser.setMultiSelectionEnabled(false);
int response = chooser.showOpenDialog(controller);
// Check response and get the selected file:
if (response != JFileChooser.APPROVE_OPTION) {
return;
}
File nodeFile = chooser.getSelectedFile();
// Set the load directory to the chosen directory:
File loadDirectory = chooser.getCurrentDirectory();
controller.setOpenDirectory(loadDirectory);
// Check for .ele file of similar name to .node file:
File eleFile = null;
String s = nodeFile.getName();
int idot = s.indexOf(".");
if (idot >= 0) {
// replaces .node extension with .ele
s = s.substring(0, idot + 1) + "ele";
eleFile = new File(nodeFile.getParent(), s);
if (!eleFile.exists()) {
eleFile = null;
}
}
// Ask for the name of the .ele file:
chooser = new JFileChooser();
EleFilter eleFilter = new EleFilter();
chooser.setCurrentDirectory(loadDirectory);
chooser.addChoosableFileFilter(eleFilter);
chooser.setFileFilter(eleFilter);
chooser.setDialogTitle("Select .ele file (cancel if none)");
chooser.setMultiSelectionEnabled(false);
if (eleFile != null) {
chooser.setSelectedFile(eleFile);
}
response = chooser.showOpenDialog(controller);
// Check response:
if (response == JFileChooser.APPROVE_OPTION) {
// Get the selected file:
eleFile = chooser.getSelectedFile();
// Set the load directory to the chosen directory:
controller.setOpenDirectory(chooser.getCurrentDirectory());
} else {
// User cancelled - take this to mean that there is no ele file to load:
eleFile = null;
}
// Read the node file:
NodeVector nodes = new NodeVector();
NodeVector.ReadNodesReturnObject readNodesReturnObj = nodes.readNodes(nodeFile, -2);
String errmsg = readNodesReturnObj.getErrmsg();
if (errmsg != null) {
Dialogs.error(controller, errmsg, title());
return;
}
// Check for attributes:
boolean doNodeAtts = false;
boolean newNodeAtts = false;
if (readNodesReturnObj.getDoAtts()) {
String prompt = "Do you want to use the NODE attributes to split the NODES into groups?";
response = Dialogs.question(controller, prompt, title());
if (response == Dialogs.CANCEL_OPTION) {
return;
}
doNodeAtts = (response == Dialogs.YES_OPTION);
if (doNodeAtts) {
prompt = "Do you want split the nodes into the existing defined groups or new groups?";
response = Dialogs.question(controller, prompt, title(), "Existing", "New", "Cancel");
if (response == Dialogs.CANCEL_OPTION) {
return;
}
newNodeAtts = (response == Dialogs.NO_OPTION);
}
}
// Get number of dimensions:
int ndim = controller.numberOfDimensions();
// Read the ele file (unless user cancelled when asked for .ele file):
FacetVector facets = new FacetVector();
boolean doFacetAtts = false;
boolean doNodeAttsFromFacetAtts = false;
boolean doNodeAttsFromFacetDefs = false;
FacetVector.ReadFacetsReturnObject readFacetsReturnObj = null;
if (eleFile != null) {
int startingIndex = readNodesReturnObj.getStartingIndex();
readFacetsReturnObj = facets.readEle(controller, title(), eleFile, startingIndex, nodes, ndim, true);
// user cancelled
if (readFacetsReturnObj == null) {
return;
}
errmsg = readFacetsReturnObj.getErrmsg();
if (errmsg != null) {
Dialogs.error(controller, errmsg, title());
return;
}
// Check for attributes:
if (readFacetsReturnObj.getDoAtts()) {
String prompt = "Do you want to use the FACET attributes to define new FACET groups?";
response = Dialogs.question(controller, prompt, title());
if (response == Dialogs.CANCEL_OPTION) {
return;
}
doFacetAtts = (response == Dialogs.YES_OPTION);
if (!doNodeAtts) {
prompt = "Do you want to use the FACET attributes to define new NODE groups?";
response = Dialogs.question(controller, prompt, title());
if (response == Dialogs.CANCEL_OPTION) {
return;
}
doNodeAttsFromFacetAtts = (response == Dialogs.YES_OPTION);
doNodeAttsFromFacetDefs = doNodeAttsFromFacetAtts;
}
} else {
if (ndim == 3) {
String prompt = "Do you want to use the FACET definitions to define a NODE boundary group?";
response = Dialogs.question(controller, prompt, title());
if (response == Dialogs.CANCEL_OPTION) {
return;
}
doNodeAttsFromFacetDefs = (response == Dialogs.YES_OPTION);
}
}
// Delete any unrequired nodes:
if (readFacetsReturnObj.getDoRem()) {
nodes.removeUnused();
}
}
// Define new node groups:
GroupVector newNodeGroups = null;
int nUniqueIDs = readNodesReturnObj.getN();
if (doNodeAtts) {
if (newNodeAtts) {
// splitting nodes into new groups named similarly to the current group name but with numbered suffixes
newNodeGroups = new GroupVector();
// Loop over the new groups:
for (int i = 0; i < nUniqueIDs; i++) {
// Create a new group object with default name:
String name = currentGroup.getName() + "_NodeAtts" + (i + 1);
Group g = new Group(name);
// Set colours to equal those for current group:
g.setNodeColor(currentGroup.getNodeColor());
g.setFacetColor(currentGroup.getFacetColor());
g.setRegionColor(currentGroup.getRegionColor());
// Add the group object to the list of new groups:
newNodeGroups.add(g);
}
// Set the node group memberships:
for (int i = 0; i < nodes.size(); i++) {
Node node = nodes.get(i);
// the ID links to the new group objects
int id = node.getID();
Group g = newNodeGroups.get(id);
node.setGroup(g);
}
} else {
// Check the number of groups is greater or equal to the number of unique node ID's:
if (nUniqueIDs > controller.numberOfGroups()) {
Dialogs.error(controller, "There are fewer groups defined in the GUI than unique node groups in the file.", title());
return;
}
// Set the node group memberships:
for (int i = 0; i < nodes.size(); i++) {
Node node = nodes.get(i);
// the ID links to the existing group objects
int id = node.getID();
Group g = controller.getGroup(id);
node.setGroup(g);
}
}
}
// Define new facet groups:
GroupVector newFacetGroups = null;
if (doFacetAtts && readFacetsReturnObj != null) {
// && ... avoids compiler warning
newFacetGroups = new GroupVector();
// Loop over the new groups:
int n = readFacetsReturnObj.getN();
for (int i = 0; i < n; i++) {
// Create a new group object with default name:
String name = "_FacetAtts" + (i + 1);
// default colour will be black
Group g = new Group(name);
// Add the group object to the list of new groups:
newFacetGroups.add(g);
}
// Set the facet group memberships:
for (int i = 0; i < facets.size(); i++) {
Facet facet = facets.get(i);
// the ID links to the new group objects
int id = facet.getID();
Group g = newFacetGroups.get(id);
facet.setGroup(g);
}
}
// Define new NODE groups from FACET attributes:
Group newGroupWithin = null;
Group newGroupBetween = null;
if (doNodeAttsFromFacetAtts) {
// Define two new groups:
// default colour will be black
newGroupWithin = new Group("NodeWithin");
newGroupBetween = new Group("NodeBetween");
newGroupBetween.setNodeColor(Color.WHITE);
// Loop over each node:
for (int i = 0; i < nodes.size(); i++) {
// Get all the facets for the current node:
Node node = nodes.get(i);
FacetVector nodeFacets = node.getFacets();
// Check if all the ID's/groups for those facets are the same:
boolean same = true;
Group g0 = nodeFacets.get(0).getGroup();
for (int k = 1; k < nodeFacets.size(); k++) {
Group gk = nodeFacets.get(k).getGroup();
if (!g0.equals(gk)) {
same = false;
break;
}
}
// Add the node to the appropriate group (and add that group to the node):
Group g;
if (same) {
// all facets the same so must be within a region
g = newGroupWithin;
} else {
// facets different so must be on boundary of a region
g = newGroupBetween;
}
g.addNode(node);
node.setGroup(g);
}
}
// Define new NODE boundary group from FACET definitions:
Group newGroupBoundary = null;
if (doNodeAttsFromFacetDefs) {
// Define a new group:
String name = currentGroup.getName() + "_NodeBoundary";
newGroupBoundary = new Group(name);
newGroupBoundary.setNodeColor(Color.WHITE);
// Figure out the other group to stick the non-boundary nodes into:
Group otherGroup;
if (doNodeAttsFromFacetAtts) {
// node groups already set above (I'll be overwriting them below)
otherGroup = null;
} else {
otherGroup = currentGroup;
}
// Find the boundary nodes:
NodeVector boundaryNodes = facets.findBoundaryNodes();
// Add those nodes to the appropriate group (and add that group to the nodes):
for (int i = 0; i < nodes.size(); i++) {
Node node = nodes.get(i);
Group g;
if (boundaryNodes != null && boundaryNodes.contains(node)) {
g = newGroupBoundary;
} else {
g = otherGroup;
}
if (g != null) {
g.addNode(node);
node.setGroup(g);
}
}
}
// Add section and group membership to the new nodes and optional facets:
nodes.setSection(currentSection);
if (!doNodeAtts && !doNodeAttsFromFacetAtts && !doNodeAttsFromFacetDefs) {
nodes.setGroup(currentGroup);
}
if (!doFacetAtts) {
facets.setGroup(currentGroup);
}
// Save the node and facet group selections:
GroupVector selectedNodeGroups = controller.getSelectedNodeGroups();
GroupVector selectedFacetGroups = controller.getSelectedFacetGroups();
// Add any new groups to the group vectors:
if (doNodeAtts && newNodeAtts) {
// Add all the new groups to the main list of groups:
controller.addGroups(newNodeGroups);
}
if (doFacetAtts && readFacetsReturnObj != null) {
// && ... avoids compiler warning
// Add all the new groups to the main list of groups:
controller.addGroups(newFacetGroups);
}
if (doNodeAttsFromFacetAtts) {
// Add the new groups to the main list of groups:
controller.addGroup(newGroupWithin);
// this new group should be added second (see code below when updating selector objects)
controller.addGroup(newGroupBetween);
}
if (doNodeAttsFromFacetDefs) {
// Add the new group to the main list of groups:
controller.addGroup(newGroupBoundary);
}
// Add the new nodes and optional facets to the plc, section, group:
ModelManager model = controller.getModelManager();
new AddNodeCommandVector(model, nodes, "").execute();
new AddFacetCommandVector(model, facets).execute();
// Update the graphical selector objects:
if (doNodeAtts || doFacetAtts || doNodeAttsFromFacetAtts || doNodeAttsFromFacetDefs) {
controller.updateGroupSelectors();
// maintains the current selected group
controller.setSelectedCurrentGroup(currentGroup);
// maintains the current selected groups
controller.setSelectedNodeGroups(selectedNodeGroups);
// maintains the current selected groups
controller.setSelectedFacetGroups(selectedFacetGroups);
}
// Enable or disable menu items:
controller.checkItemsEnabled();
// Repaint:
controller.redraw();
// Inform user of success:
Dialogs.inform(controller, "File(s) loaded successfully.", title());
}
use of facetmodeller.commands.AddNodeCommandVector in project facetmodeller by pglelievre.
the class DefineNodesVOIMenuTask method execute.
@Override
public void execute() {
// Check for the required information:
if (!check()) {
return;
}
// Ask the user for confirmation:
int response = Dialogs.confirm(controller, "The nodes will be added as 3D off-section nodes.", title());
if (response != Dialogs.OK_OPTION) {
return;
}
// Define 8 new off-section nodes:
NodeVector nodes = new NodeVector();
MyPoint3D[] p = controller.getVOICorners();
for (int i = 0; i < 8; i++) {
// new node is not added to the section or group yet
nodes.add(new NodeOffSection(p[i], controller.getSelectedCurrentSection(), controller.getSelectedCurrentGroup()));
}
// Add the nodes:
// adds each node to its section and group
AddNodeCommandVector com = new AddNodeCommandVector(controller.getModelManager(), nodes, "");
// adds each node to its section and group
com.execute();
controller.undoVectorAdd(com);
// Enable or disable menu items:
controller.checkItemsEnabled();
// Repaint:
controller.redraw();
}
use of facetmodeller.commands.AddNodeCommandVector in project facetmodeller by pglelievre.
the class NodesAtCalibrationMenuTask method execute.
@Override
public void execute() {
// Check for the required information:
if (!check()) {
return;
}
// Get the current section and group:
Section currentSection = controller.getSelectedCurrentSection();
Group currentGroup = controller.getSelectedCurrentGroup();
// Add 4 new nodes to the section,
MyPoint2D p1 = currentSection.getClicked1();
MyPoint2D p2 = currentSection.getClicked2();
MyPoint2D[] p = new MyPoint2D[4];
p[0] = p1.deepCopy();
p[1] = p2.deepCopy();
p[2] = new MyPoint2D(p1.getX(), p2.getY());
p[3] = new MyPoint2D(p2.getX(), p1.getY());
NodeVector nodes = new NodeVector();
for (int i = 0; i < 4; i++) {
// new node is not added to the section or group yet
Node n = new NodeOnSection(p[i], currentSection, currentGroup);
nodes.add(n);
}
// adds the node to the section and group
AddNodeCommandVector com = new AddNodeCommandVector(controller.getModelManager(), nodes, title());
// adds the node to the section and group
com.execute();
controller.undoVectorAdd(com);
// Enable or disable menu items:
controller.checkItemsEnabled();
// Redraw:
controller.redraw();
}
Aggregations