use of geometry.Dir3D in project facetmodeller by pglelievre.
the class SessionLoader method loadSessionAscii2.
private static boolean loadSessionAscii2(FacetModeller controller, File file, boolean merge) {
int loadVersion = 2;
// We will be constructing some new objects as we read the file:
PLC plc = new PLC();
SectionVector sections = new SectionVector();
GroupVector groups = new GroupVector();
// We will be saving some information to set later:
int ndim;
// these colours will be overwritten
Color calibrationColor = Color.CYAN;
Color edgeColor = Color.BLACK;
Color defineFacetEdgeColor = Color.WHITE;
int pointWidth = 5;
int lineWidth = 1;
// Open the file for reading:
BufferedReader reader = FileUtils.openForReading(file);
if (reader == null) {
return false;
}
// Put everything below in an infinite loop that we can break out of when something goes wrong:
boolean ok = true;
while (true) {
// Read the floored version number:
String textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
String[] ss = textLine.split("[ ]+", 2);
int version;
try {
// converts to integer
version = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
if (!ok) {
break;
}
// Check the version number:
if (version != loadVersion) {
// Close the file:
FileUtils.close(reader);
// Return unsuccessfully:
return false;
}
// Read the number of dimensions, nodes, facets, regions, samples and groups:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
int nnodes, nregions, nfacets, nsections, ngroups;
textLine = textLine.trim();
ss = textLine.split("[ ]+", 7);
try {
// converts to integer
ndim = Integer.parseInt(ss[0].trim());
// converts to integer
nnodes = Integer.parseInt(ss[1].trim());
// converts to integer
nfacets = Integer.parseInt(ss[2].trim());
// converts to integer
nregions = Integer.parseInt(ss[3].trim());
// converts to integer
nsections = Integer.parseInt(ss[4].trim());
// converts to integer
ngroups = Integer.parseInt(ss[5].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
// Check ndim:
if (ndim != controller.numberOfDimensions()) {
ok = false;
break;
}
// Loop over each node:
for (int i = 0; i < nnodes; i++) {
// Read the coordinates of the ith node:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
boolean isTopo;
// initialization of z is needed to avoid compiler warning
double x, y, z = 0.0;
textLine = textLine.trim();
ss = textLine.split("[ ]+", 4);
try {
isTopo = Boolean.parseBoolean(ss[0].trim());
// converts to Double
x = Double.parseDouble(ss[1].trim());
// converts to Double
y = Double.parseDouble(ss[2].trim());
if (isTopo) {
z = Double.parseDouble(ss[3].trim());
}
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
// Add a new node to the plc:
if (isTopo) {
plc.addNode(new NodeOffSection(x, y, z));
} else {
plc.addNode(new NodeOnSection(x, y));
}
// section and group membership will be added later
}
if (!ok) {
break;
}
// Loop over each facet:
for (int i = 0; i < nfacets; i++) {
// Add a new empty facet to the plc (these facets are filled later):
plc.addFacet(new Facet());
}
// Loop over each region:
for (int i = 0; i < nregions; i++) {
// Read the coordinates of the ith region and the isControl information:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
double x, y;
boolean isCon;
textLine = textLine.trim();
ss = textLine.split("[ ]+", 4);
// Try parsing coordinates (must be able to do this):
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
// Check for iscontrol information:
if (ss.length < 3) {
isCon = false;
} else {
if (ss[2].trim().isEmpty()) {
// missing from file (old version of session saver was used)
isCon = false;
} else {
// converts to Boolean
isCon = Boolean.parseBoolean(ss[2].trim());
}
}
// Add a new region to the plc:
// section and group membership will be added later
plc.addRegion(new Region(isCon, x, y));
}
if (!ok) {
break;
}
for (int i = 0; i < nsections; i++) {
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
int sectionType;
try {
sectionType = Integer.parseInt(textLine);
} catch (NumberFormatException e) {
ok = false;
break;
}
if (!ok) {
break;
}
Section section = null;
switch(sectionType) {
case 1:
// Read the file name:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
File imageFile;
if (textLine.startsWith("null")) {
imageFile = null;
} else {
try {
URI uri = new URI(textLine);
// image file or .node file
imageFile = new File(uri);
} catch (URISyntaxException e) {
ok = false;
break;
}
}
// Make a new HasImage object associated with the file:
section = new ImageCrossSection(imageFile);
break;
case 3:
// Read the section name:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
String name = textLine.trim();
// Read the image height:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
int height;
try {
height = Integer.parseInt(textLine);
} catch (NumberFormatException e) {
ok = false;
break;
}
// Read the image color:
Color color;
try {
// parse from RGB string
color = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
section = new NoImageCrossSection(name, color);
break;
case 2:
File nodeFile = null;
File eleFile = null;
// Read the node file name:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
if (textLine.startsWith("null")) {
nodeFile = null;
} else {
URI uri = null;
try {
uri = new URI(textLine);
} catch (URISyntaxException e) {
ok = false;
}
if (!ok) {
break;
}
try {
// image file or .node file
nodeFile = new File(uri);
} catch (IllegalArgumentException e) {
ok = false;
}
}
if (!ok) {
break;
}
// Read the ele file name:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
if (textLine.startsWith("null")) {
eleFile = null;
} else {
try {
URI uri = new URI(textLine);
// image file or .node file
eleFile = new File(uri);
} catch (URISyntaxException e) {
ok = false;
}
}
if (!ok) {
break;
}
// formerly a TopoSection
section = new NoImageDepthSection(nodeFile, eleFile);
break;
default:
ok = false;
break;
}
if (!ok) {
break;
}
if (section == null) {
ok = false;
break;
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
Dir3D sliceDirection;
try {
// converts to integer
int idir = Integer.parseInt(ss[0].trim());
sliceDirection = Dir3D.fromInt(idir);
} catch (NumberFormatException e) {
ok = false;
break;
}
if (!ok) {
break;
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
double loc;
try {
// converts to Double
loc = Double.parseDouble(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
if (!ok) {
break;
}
double x, y;
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
if (!textLine.startsWith("null")) {
ss = textLine.split("[ ]+", 3);
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
section.setTyped1(new MyPoint3D(x, y, sliceDirection, loc));
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
if (!textLine.startsWith("null")) {
ss = textLine.split("[ ]+", 3);
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
section.setTyped2(new MyPoint3D(x, y, sliceDirection, loc));
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
if (!textLine.startsWith("null")) {
ss = textLine.split("[ ]+", 3);
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
section.setClicked1(new MyPoint2D(x, y));
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
if (!textLine.startsWith("null")) {
ss = textLine.split("[ ]+", 3);
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
section.setClicked2(new MyPoint2D(x, y));
}
sections.add(section);
}
if (!ok) {
break;
}
// Loop over each group:
for (int i = 0; i < ngroups; i++) {
// Create the group object:
Group group = new Group();
// Read the group name:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
group.setName(textLine.trim());
// Read the group colours:
Color col;
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
col = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
group.setNodeColor(col);
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
col = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
group.setFacetColor(col);
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
col = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
group.setRegionColor(col);
// Add the group to the list of groups:
groups.add(group);
}
if (!ok) {
break;
}
// Loop over each node:
for (int i = 0; i < nnodes; i++) {
Node node = plc.getNode(i);
// The node gets linked to the facets in the loop over each facet below.
// Read the section id and group id:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 3);
// section and group id
int sid, gid;
try {
// converts to integer
sid = Integer.parseInt(ss[0].trim());
// converts to integer
gid = Integer.parseInt(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
// Cross-link the node and section:
node.setSection(sections.get(sid));
sections.get(sid).addNode(node);
// Cross-link the node and group:
node.setGroup(groups.get(gid));
groups.get(gid).addNode(node);
}
if (!ok) {
break;
}
// Loop over each facet:
for (int i = 0; i < nfacets; i++) {
Facet facet = plc.getFacet(i);
// Read the node id's and link those nodes to the facet:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+");
// number of nodes
int n;
try {
// converts to integer
n = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
if (!ok) {
break;
}
for (int j = 0; j < n; j++) {
// node id
int id;
try {
// converts to integer
id = Integer.parseInt(ss[j + 1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
// Cross-link the facet and node:
facet.addNode(plc.getNode(id));
plc.getNode(id).addFacet(facet);
}
// Read the section id's:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
/*
textLine = textLine.trim();
ss = textLine.split("[ ]+");
try {
n = Integer.parseInt(ss[0].trim()); // converts to integer
} catch (NumberFormatException e) { ok=false; break; }
if (!ok) { break; }
for (int j=0 ; j<n ; j++ ) {
int id;
try {
id = Integer.parseInt(ss[j+1].trim()); // converts to integer
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { ok=false; break; }
// Cross-link the facet and section:
// facet.addSection( sections.get(id) ); // no longer necessary because facet sections defined by the facet nodes
sections.get(id).addFacet(facet);
}
*/
// Read the group id:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
int id;
try {
// converts to integer
id = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
// Cross-link the facet and group:
facet.setGroup(groups.get(id));
groups.get(id).addFacet(facet);
}
if (!ok) {
break;
}
// Loop over each region:
for (int i = 0; i < nregions; i++) {
Region region = plc.getRegion(i);
// Read the section id:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
int id;
try {
// converts to integer
id = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
// Cross-link the region and section:
region.setSection(sections.get(id));
sections.get(id).addRegion(region);
// Read the group id and link that group to the node:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
try {
// converts to integer
id = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
// Cross-link the region and group:
region.setGroup(groups.get(id));
// groups.get(id).setRegion(region);
groups.get(id).addRegion(region);
}
if (!ok) {
break;
}
// ---------- Finish with the rest of the information: ----------
// Read painting colours, etc.:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
calibrationColor = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
edgeColor = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
defineFacetEdgeColor = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
pointWidth = Integer.parseInt(textLine.trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
lineWidth = Integer.parseInt(textLine.trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
// Always break from while here:
break;
}
// Close the file:
FileUtils.close(reader);
// Check for a problem:
if (!ok) {
return false;
}
// Reset the FacetModeller plc, section lists and group lists:
controller.resetPLC(plc, merge);
controller.resetSectionVector(sections, merge);
controller.resetGroupVector(groups, merge);
// If it is a large model then don't display anything:
if (plc.numberOfNodes() >= LARGE_MODEL) {
controller.clearGroupSelections();
}
// Reset some other information:
if (!merge) {
controller.setCalibrationColor(calibrationColor);
controller.setEdgeColor(edgeColor);
controller.setDefineFacetEdgeColor(defineFacetEdgeColor);
controller.setPointWidth(pointWidth);
controller.setLineWidth(lineWidth);
}
// Return successfully:
return true;
}
use of geometry.Dir3D in project facetmodeller by pglelievre.
the class FileIOManager method exportPair.
/**
* Exports to node and ele files.
* @param whatToExport Specifies what to export using one of the EXPORT_* integers defined in this class.
*/
public void exportPair(int whatToExport) {
if (!controller.hasSections()) {
return;
}
// a title for some dialogs
String title = "Export .node/.ele Pair";
// Get or make the required plc and reset the ID's:
PLC plc;
controller.resetIDs();
switch(whatToExport) {
case EXPORT_CURRENT:
Group g = controller.getSelectedCurrentGroup();
plc = new PLC();
plc.addNodes(g.getNodes());
plc.addFacets(g.getFacets());
plc.resetIDs();
break;
case EXPORT_DISPLAYED:
GroupVector gn = controller.getSelectedNodeGroups();
GroupVector gf = controller.getSelectedFacetGroups();
if (gn == null && gf == null) {
Dialogs.error(controller, "There is nothing selected to export.", title);
return;
}
plc = new PLC();
if (gn != null) {
plc.addNodes(gn.getNodes());
}
if (gf != null) {
plc.addFacets(gf.getFacets());
}
plc.resetIDs();
break;
default:
plc = controller.getPLC();
break;
}
// Check nodes and facets exist:
if (!plc.hasNodes()) {
Dialogs.error(controller, "There are no nodes to export.", title);
return;
}
if (!plc.hasFacets()) {
Dialogs.warning(controller, "There are no facets to export: no .ele file will be written.", title);
}
// Ask for the file name for saving:
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(getSaveDirectory());
chooser.setDialogTitle(title);
chooser.setMultiSelectionEnabled(false);
File file = getSessionFile();
if (file != null) {
String root = FileUtils.getRoot(file);
file = new File(root);
chooser.setSelectedFile(file);
}
int response = chooser.showSaveDialog(controller);
// Check response and get the selected file:
if (response != JFileChooser.APPROVE_OPTION) {
return;
}
file = chooser.getSelectedFile();
// Check response:
if (file == null) {
return;
}
// Get the root of the file:
String root = FileUtils.getRoot(file);
// Set the save directory to the chosen directory:
setSaveDirectory(chooser.getCurrentDirectory());
// Check for file overwrite:
File file1 = new File(root + "." + NodeFilter.NODE);
File file2 = new File(root + "." + EleFilter.ELE);
if (file1.exists() || file2.exists()) {
response = Dialogs.confirm(controller, "Overwrite the existing file(s)?", title);
if (response != Dialogs.OK_OPTION) {
return;
}
}
// Write the files:
Dir3D dir = null;
final int ndim = controller.numberOfDimensions();
if (ndim == 2) {
dir = controller.getSelectedCurrentSection().getDir3D();
}
boolean ok;
ok = plc.writeNodes(file1, startingIndex, precision, ndim, dir);
if (!ok) {
Dialogs.error(controller, "Failed to save .node file.", title);
}
// don't write .ele file if there are no facets
if (!plc.hasFacets()) {
return;
}
// write non-standard variable facet type .ele file if required
ok = plc.writeFacets(file2, startingIndex, precision, ndim, true);
if (!ok) {
Dialogs.error(controller, "Failed to save .ele file.", title);
}
}
use of geometry.Dir3D in project facetmodeller by pglelievre.
the class FileIOManager method exportRegionsNode.
public void exportRegionsNode() {
if (!controller.hasSections()) {
return;
}
// a title for some dialogs
String title = "Export Regions to .node file";
// Check regions exist:
ModelManager model = controller.getModelManager();
if (!model.hasRegions()) {
Dialogs.error(controller, "There are no regions to export.", title);
return;
}
// Ask what to write for region attributes:
boolean byIndex;
String message = "The region attributes can be the region indices or region group IDs. Which would you like to use?";
int response = Dialogs.question(controller, message, title, "Indices", "Group IDs", "Cancel", "Indices");
switch(response) {
case Dialogs.YES_OPTION:
byIndex = true;
break;
case Dialogs.NO_OPTION:
byIndex = false;
break;
default:
// user cancelled
return;
}
// Ask for the file name for saving:
JFileChooser chooser = new JFileChooser();
NodeFilter filter = new NodeFilter();
chooser.setCurrentDirectory(getSaveDirectory());
chooser.addChoosableFileFilter(filter);
chooser.setFileFilter(filter);
chooser.setDialogTitle(title);
chooser.setMultiSelectionEnabled(false);
File file = getSessionFile();
if (file != null) {
String root = FileUtils.getRoot(file);
file = new File(root + "." + NodeFilter.NODE);
chooser.setSelectedFile(file);
}
response = chooser.showSaveDialog(controller);
// Check response and get the selected file:
if (response != JFileChooser.APPROVE_OPTION) {
return;
}
file = chooser.getSelectedFile();
// Check response:
if (file == null) {
return;
}
// Set the save directory to the chosen directory:
setSaveDirectory(chooser.getCurrentDirectory());
// Count number of regions:
int nRegion = model.numberOfRegionPoints();
int nControl = model.numberOfControlPoints();
// There may be two files written:
String root = FileUtils.getRoot(file);
File file1 = new File(root + "_regions." + NodeFilter.NODE);
File file2 = new File(root + "_controls." + NodeFilter.NODE);
// Check for file overwrite:
if ((nRegion > 0 && file1.exists()) || (nControl > 0 && file2.exists())) {
response = Dialogs.confirm(controller, "Overwrite the existing file(s)?", title);
if (response != Dialogs.OK_OPTION) {
return;
}
}
// Reset the id's:
controller.resetIDs();
// Only write the node files if there are regions to write in each:
Dir3D dir = null;
final int ndim = controller.numberOfDimensions();
if (ndim == 2) {
dir = controller.getSelectedCurrentSection().getDir3D();
}
boolean ok = true;
if (nRegion > 0) {
ok = model.writeRegionsNode(file1, startingIndex, precision, ndim, dir, false, byIndex);
}
if (ok && nControl > 0) {
ok = model.writeRegionsNode(file2, startingIndex, precision, ndim, dir, true, byIndex);
}
// } else {
if (!ok) {
Dialogs.error(controller, "Failed to save .node file(s).", title);
}
}
use of geometry.Dir3D in project facetmodeller by pglelievre.
the class FileIOManager method exportRegionsVTU.
public void exportRegionsVTU() {
if (!controller.hasSections()) {
return;
}
// a title for some dialogs
String title = "Export Regions to .vtu file";
// Check regions exist:
ModelManager model = controller.getModelManager();
if (!model.hasRegions()) {
Dialogs.error(controller, "There are no regions to export.", title);
return;
}
// Ask if the coordinate should have z flipped:
int response = Dialogs.questionNo(controller, "Do you want to flip the z-axis?", title);
if (response == Dialogs.CANCEL_OPTION) {
return;
}
boolean flipz = (response == Dialogs.YES_OPTION);
// Ask for the file name for saving:
JFileChooser chooser = new JFileChooser();
VTUFilter filter = new VTUFilter();
chooser.setCurrentDirectory(getSaveDirectory());
chooser.addChoosableFileFilter(filter);
chooser.setFileFilter(filter);
chooser.setDialogTitle(title);
chooser.setMultiSelectionEnabled(false);
File file = getSessionFile();
if (file != null) {
String root = FileUtils.getRoot(file);
file = new File(root + "." + VTUFilter.VTU);
chooser.setSelectedFile(file);
}
response = chooser.showSaveDialog(controller);
// Check response and get the selected file:
if (response != JFileChooser.APPROVE_OPTION) {
return;
}
file = chooser.getSelectedFile();
// Check response:
if (file == null) {
return;
}
// Set the save directory to the chosen directory:
setSaveDirectory(chooser.getCurrentDirectory());
// Count number of regions:
int nRegion = model.numberOfRegionPoints();
int nControl = model.numberOfControlPoints();
// There may be two files written:
String root = FileUtils.getRoot(file);
File file1 = new File(root + "_regions." + VTUFilter.VTU);
File file2 = new File(root + "_controls." + VTUFilter.VTU);
// Check for file overwrite:
if ((nRegion > 0 && file1.exists()) || (nControl > 0 && file2.exists())) {
response = Dialogs.confirm(controller, "Overwrite the existing file(s)?", title);
if (response != Dialogs.OK_OPTION) {
return;
}
}
// Reset the id's:
controller.resetIDs();
// Only write the vtu files if there are regions to write in each:
Dir3D dir = null;
final int ndim = controller.numberOfDimensions();
if (ndim == 2) {
dir = controller.getSelectedCurrentSection().getDir3D();
}
boolean ok = true;
if (nRegion > 0) {
// doControl=false
ok = model.writeRegionsVTU(file1, startingIndex, precision, ndim, dir, false, flipz);
}
if (ok && nControl > 0) {
// doControl=true
ok = model.writeRegionsVTU(file2, startingIndex, precision, ndim, dir, true, flipz);
}
// } else {
if (!ok) {
Dialogs.error(controller, "Failed to save .vtu file(s).", title);
}
}
use of geometry.Dir3D in project facetmodeller by pglelievre.
the class CopyCalibrationMenuTask method execute.
@Override
public void execute() {
// Check for the required information:
if (!check()) {
return;
}
// Make sure the current section has a natural direction:
Section currentSection = controller.getSelectedCurrentSection();
Dir3D dir = currentSection.getDir3D();
if (dir == null) {
Dialogs.error(controller, "The current section is not alligned with the Cartesian axes.", title());
return;
}
// Ask the user for the step:
String prompt = "Enter the step in the " + dir.toChar() + " direction:";
String s = Dialogs.input(controller, prompt, title());
// user cancelled
if (s == null) {
return;
}
s = s.trim();
String[] ss = s.split("[ ]+");
if (ss.length != 1) {
Dialogs.error(controller, "Please enter a single numeric value.", "Error");
return;
}
double step;
try {
step = Double.parseDouble(ss[0].trim());
} catch (NumberFormatException e) {
Dialogs.error(controller, "Please enter a valid numeric.", title());
return;
}
// Do it:
controller.copyCalibration(step);
}
Aggregations