use of com.willwinder.universalgcodesender.visualizer.GcodeViewParse in project Universal-G-Code-Sender by winder.
the class GcodeModel method generateObject.
/**
* Parse the gcodeFile and store the resulting geometry and data about it.
*/
private boolean generateObject() {
isDrawable = false;
if (this.gcodeFile == null) {
return false;
}
try {
GcodeViewParse gcvp = new GcodeViewParse();
logger.log(Level.INFO, "About to process {}", gcodeFile);
try {
GcodeStreamReader gsr = new GcodeStreamReader(new File(gcodeFile));
gcodeLineList = gcvp.toObjFromReader(gsr, 0.3);
} catch (GcodeStreamReader.NotGcodeStreamFile e) {
List<String> linesInFile;
linesInFile = VisualizerUtils.readFiletoArrayList(this.gcodeFile);
gcodeLineList = gcvp.toObjRedux(linesInFile, 0.3);
}
this.objectMin = gcvp.getMinimumExtremes();
this.objectMax = gcvp.getMaximumExtremes();
if (gcodeLineList.isEmpty()) {
return false;
}
// Grab the line number off the last line.
this.lastCommandNumber = gcodeLineList.get(gcodeLineList.size() - 1).getLineNumber();
System.out.println("Object bounds: X (" + objectMin.x + ", " + objectMax.x + ")");
System.out.println(" Y (" + objectMin.y + ", " + objectMax.y + ")");
System.out.println(" Z (" + objectMin.z + ", " + objectMax.z + ")");
Point3d center = VisualizerUtils.findCenter(objectMin, objectMax);
System.out.println("Center = " + center.toString());
System.out.println("Num Line Segments :" + gcodeLineList.size());
objectSize.x = this.objectMax.x - this.objectMin.x;
objectSize.y = this.objectMax.y - this.objectMin.y;
objectSize.z = this.objectMax.z - this.objectMin.z;
/*
this.scaleFactorBase = VisualizerUtils.findScaleFactor(this.xSize, this.ySize, this.objectMin, this.objectMax);
this.scaleFactor = this.scaleFactorBase * this.zoomMultiplier;
this.dimensionsLabel = Localization.getString("VisualizerCanvas.dimensions") + ": "
+ Localization.getString("VisualizerCanvas.width") + "=" + format.format(objectWidth) + " "
+ Localization.getString("VisualizerCanvas.height") + "=" + format.format(objectHeight);
*/
// Now that the object is known, fill the buffers.
this.isDrawable = true;
this.numberOfVertices = gcodeLineList.size() * 2;
this.lineVertexData = new float[numberOfVertices * 3];
this.lineColorData = new byte[numberOfVertices * 3];
this.updateVertexBuffers();
} catch (GcodeParserException | IOException e) {
String error = Localization.getString("mainWindow.error.openingFile") + " : " + e.getLocalizedMessage();
System.out.println(error);
GUIHelpers.displayErrorDialog(error);
return false;
}
return true;
}
Aggregations