diff --git a/board/BezierBoard.java b/board/BezierBoard.java index 644dcf7..9e35826 100644 --- a/board/BezierBoard.java +++ b/board/BezierBoard.java @@ -39,6 +39,8 @@ import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Collections; +import java.util.Vector; + import javax.media.j3d.IndexedQuadArray; import javax.media.j3d.QuadArray; @@ -126,8 +128,6 @@ public class BezierBoard extends AbstractBoard implements Cloneable { private double mCenterOfMass = 0; private AbstractBezierBoardSurfaceModel.ModelType mInterpolationType = AbstractBezierBoardSurfaceModel.ModelType.ControlPointInterpolation; - - private Shape3D m3DModel = null; public BezierBoard() { @@ -979,40 +979,6 @@ public double getXFromTailByOverBottomCurveLength(double length) public double getDeckAtPos(double x, double y) { - -/* - //Calculate scales - double widthAtPos = getWidthAtPos(x); - double thicknessAtPos = getThicknessAtPos(x); - - //Get the position from function since we cheat with the crosssections at tip and tail - double pos1 = getPreviousCrossSectionPos(x); - double pos2 = getNextCrossSectionPos(x); - - //Get crosssections but use the first and last real crosssections if we're at the dummy crosssections at nose and tail - BezierBoardCrossSection c1 = getPreviousCrossSection(x); - BezierBoardCrossSection c2 = getNextCrossSection(x); - - //Get scales and values - double Scale1Y = c1.getWidth() / widthAtPos; - double Scale1Z = c1.getCenterThickness()/ thicknessAtPos; - - double Scale2Y = c2.getWidth() / widthAtPos; - double Scale2Z = c2.getCenterThickness()/ thicknessAtPos; - - double v1 = c1.getDeckAtPos(y*Scale1Y); - double v2 = c2.getDeckAtPos(y*Scale2Y); - - v1 /= Scale1Z; - v2 /= Scale2Z; - - //Get blended point - double p = (x - pos1)/(pos2 - pos1); - - double z = ((1-p)*v1) + (p*v2); - - return z; -*/ return AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(getInterpolationType()).getDeckAt(this,x, y).getZ(); } @@ -1041,12 +1007,12 @@ public Point2D.Double getSurfacePointAtPos(double x, double s) public Vector3d getDeckNormalAt(double x, double y) { - return AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(getInterpolationType()).getBottomNormalAt(this,x, y); + return AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(getInterpolationType()).getDeckNormalAt(this,x, y); } public Vector3d getBottomNormalAt(double x, double y) { - return AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(getInterpolationType()).getDeckNormalAt(this,x, y); + return AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(getInterpolationType()).getBottomNormalAt(this,x, y); } @@ -1767,7 +1733,7 @@ boolean deckCollisionTest(Point3d aabbCenter, double width, double depth, double { double y = aabbCenter.y - (width/2.0); - for(int j = 0; i <= widthSplits; i++) + for(int j = 0; j <= widthSplits; j++) { double z = getDeckAt(x, y); z += getRockerAtPos(x); @@ -1999,7 +1965,7 @@ public NurbsPoint getTuckedUnder3D(double x) BezierKnot myControlPoint=before_ControlPoints.getControlPoint(i); Point2D.Double ControlPoint_point=myControlPoint.getEndPoint(); - if(before_outline<=ControlPoint_point.getX()) + if(before_outline guidepointArray) { - try{ - if(spline != null) + try { + if (spline != null) { String strLine = cFile.readLine(); - while(strLine.startsWith("(cp")) + while (strLine.startsWith("(cp")) { spline.append(readControlPoint(strLine)); strLine = cFile.readLine(); } - if(strLine.startsWith("gps")) + if (strLine.startsWith("gps")) { - if(guidepointArray != null) + if (guidepointArray != null) { strLine = cFile.readLine(); - while(strLine.startsWith("(gp")) + while (strLine.startsWith("(gp")) { String[] splitString = strLine.split(" "); - String valuesStr = splitString[1].substring(1,splitString[1].length()-2); + String valuesStr = splitString[1].substring(1, splitString[1].length() - 2); String[] values = valuesStr.split(","); guidepointArray.add(new Point2D.Double(Double.valueOf(values[0]).doubleValue(), Double.valueOf(values[1]).doubleValue())); @@ -658,33 +656,34 @@ static void readArrayOfControlPointsAndGuidepoints(BufferedReader cFile, BezierS } } } - } - catch(Exception e) + } catch (Exception e) { String str = e.toString(); - System.out.printf("exception occured during load %s", str); -/*java 1.6 System.console().printf("exception occured during load %s", str);*/ + System.out.printf("exception occured during load %s", str); + /* + * java 1.6 + * System.console().printf("exception occured during load %s", str); + */ } } - static BezierKnot readControlPoint(String string) { BezierKnot controlPoint = new BezierKnot(); - if(string.startsWith("(cp")== false) + if (string.startsWith("(cp") == false) return null; - String[] splitString = string.substring(1,string.length()-1).split(" "); + String[] splitString = string.substring(1, string.length() - 1).split(" "); - String valuesStr = splitString[1].substring(1,splitString[1].length()-1); + String valuesStr = splitString[1].substring(1, splitString[1].length() - 1); String[] values = valuesStr.split(","); - for(int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { - double x = Double.valueOf(values[i*2]).doubleValue(); - double y = Double.valueOf(values[(i*2)+1]).doubleValue(); + double x = Double.valueOf(values[i * 2]).doubleValue(); + double y = Double.valueOf(values[(i * 2) + 1]).doubleValue(); - controlPoint.getPoints()[i].setLocation(x,y); + controlPoint.getPoints()[i].setLocation(x, y); } @@ -697,10 +696,10 @@ static BezierKnot readControlPoint(String string) static void readDoubleArray(String input, double[] returnValues) { - String valStr = input.substring(1,input.length()-1); + String valStr = input.substring(1, input.length() - 1); String[] values = valStr.split(","); - for(int i = 0; i < values.length; i++) + for (int i = 0; i < values.length; i++) { returnValues[i] = Double.valueOf(values[i]); } @@ -710,7 +709,7 @@ static void setErrorStr(String errorStr) { mErrorStr = errorStr; } - + static public String getErrorStr() { return mErrorStr; diff --git a/board/readers/BrdXmlReader.java b/board/readers/BrdXmlReader.java new file mode 100644 index 0000000..69bad54 --- /dev/null +++ b/board/readers/BrdXmlReader.java @@ -0,0 +1,5 @@ +package board.readers; + +public class BrdXmlReader { + +} diff --git a/board/readers/S3dReader.java b/board/readers/S3dReader.java index 6e1926f..979b721 100644 --- a/board/readers/S3dReader.java +++ b/board/readers/S3dReader.java @@ -27,248 +27,237 @@ public class S3dReader { static final int XY = 0; static final int XZ = 1; static final int YZ = 2; - + static String mErrorStr; - - static public int loadFile(BezierBoard brd, String aFilename) - { - System.out.printf("Loading %s\n", aFilename); + + static public int loadFile(BezierBoard brd, String aFilename) { int ret = 0; - + brd.reset(); - + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - - try { + + try { DocumentBuilder builder = factory.newDocumentBuilder(); - Document document = builder.parse( new File(aFilename) ); - - Element shape3Dnode = (Element)document.getElementsByTagName("Shape3d_design").item(0); - Element boardNode = (Element)shape3Dnode.getElementsByTagName("Board").item(0); - - Element bottom = (Element)boardNode.getElementsByTagName("Bottom").item(0); - Element deck = (Element)boardNode.getElementsByTagName("Deck").item(0); - Element outline = (Element)boardNode.getElementsByTagName("Outline").item(0); - + Document document = builder.parse(new File(aFilename)); + + Element shape3Dnode = (Element) document.getElementsByTagName("Shape3d_design").item(0); + Element boardNode = (Element) shape3Dnode.getElementsByTagName("Board").item(0); + + Element bottom = (Element) boardNode.getElementsByTagName("Bottom").item(0); + Element deck = (Element) boardNode.getElementsByTagName("Deck").item(0); + Element outline = (Element) boardNode.getElementsByTagName("Outline").item(0); + readBezierAndGuidePoints(outline, brd.getOutline(), brd.getOutlineGuidePoints(), XY); BezierKnot controlPoint; - //Add outline controlPoints at tail and nose - if(brd.getOutline().getControlPoint(0).getPoints()[0].y > 1.0) - { + // Add outline controlPoints at tail and nose + if (brd.getOutline().getControlPoint(0).getPoints()[0].y > 1.0) { brd.getOutline().getControlPoint(0).setContinous(false); - brd.getOutline().getControlPoint(0).getPoints()[1].y = brd.getOutline().getControlPoint(0).getPoints()[0].y*2/3; - + brd.getOutline().getControlPoint(0).getPoints()[1].y = brd.getOutline().getControlPoint(0).getPoints()[0].y * 2 / 3; + controlPoint = new BezierKnot(); - controlPoint.getPoints()[2].y = brd.getOutline().getControlPoint(0).getPoints()[0].y/3; + controlPoint.getPoints()[2].y = brd.getOutline().getControlPoint(0).getPoints()[0].y / 3; brd.getOutline().insert(0, controlPoint); } - - if(brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints()-1).getPoints()[0].y > 1.0) - { - brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints()-1).setContinous(false); - brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints()-1).getPoints()[2].x = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints()-1).getPoints()[0].x; - brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints()-1).getPoints()[2].y = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints()-1).getPoints()[0].y*2/3; - + + if (brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[0].y > 1.0) { + brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).setContinous(false); + brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[2].x = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[0].x; + brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[2].y = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[0].y * 2 / 3; + controlPoint = new BezierKnot(); - controlPoint.getPoints()[0].x = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints()-1).getPoints()[0].x; + controlPoint.getPoints()[0].x = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[0].x; controlPoint.getPoints()[1].x = controlPoint.getPoints()[0].x; - controlPoint.getPoints()[1].y = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints()-1).getPoints()[0].y/3; + controlPoint.getPoints()[1].y = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[0].y / 3; controlPoint.getPoints()[2].x = controlPoint.getPoints()[0].x; brd.getOutline().append(controlPoint); } - + readBezierAndGuidePoints(bottom, brd.getBottom(), brd.getBottomGuidePoints(), XZ); - if(deck != null) //Thickness curve instead? + if (deck != null) // Thickness curve instead? { readBezierAndGuidePoints(deck, brd.getDeck(), brd.getDeckGuidePoints(), XZ); - } - else - { - //TODO: Add generation of deck curve from thickness curve when curve fitting is implemented - - ret = 1; //Warning code, deck curve is no good - - //Dummy deck curve - controlPoint = (BezierKnot)brd.getBottom().getControlPoint(0).clone(); + } else { + // TODO: Add generation of deck curve from thickness curve when + // curve fitting is implemented + + ret = 1; // Warning code, deck curve is no good + + // Dummy deck curve + controlPoint = (BezierKnot) brd.getBottom().getControlPoint(0).clone(); controlPoint.setContinous(false); controlPoint.getPoints()[0].y += 1.5; controlPoint.getPoints()[2].x = 20; - controlPoint.getPoints()[2].y = controlPoint.getPoints()[0].y - 0.5; + controlPoint.getPoints()[2].y = controlPoint.getPoints()[0].y - 0.5; brd.getDeck().append(controlPoint); - - double thickness = ((( brd.getLength()/(12*UnitUtils.INCH)) - 5 )/4 * 1) + 2.125*UnitUtils.INCH; + + double thickness = (((brd.getLength() / (12 * UnitUtils.INCH)) - 5) / 4 * 1) + 2.125 * UnitUtils.INCH; controlPoint = new BezierKnot(); - controlPoint.getPoints()[0].x = brd.getLength()/2; + controlPoint.getPoints()[0].x = brd.getLength() / 2; controlPoint.getPoints()[0].y = thickness; controlPoint.getPoints()[1].x = controlPoint.getPoints()[0].x - 50; controlPoint.getPoints()[1].y = thickness; controlPoint.getPoints()[2].x = controlPoint.getPoints()[0].x + 50; controlPoint.getPoints()[2].y = thickness; brd.getDeck().append(controlPoint); - - controlPoint = (BezierKnot)brd.getBottom().getControlPoint(brd.getBottom().getNrOfControlPoints()-1).clone(); + + controlPoint = (BezierKnot) brd.getBottom().getControlPoint(brd.getBottom().getNrOfControlPoints() - 1).clone(); controlPoint.setContinous(false); controlPoint.getPoints()[0].y += 1.5; - controlPoint.getPoints()[1].y += controlPoint.getPoints()[0].y/2; + controlPoint.getPoints()[1].y += controlPoint.getPoints()[0].y / 2; controlPoint.getPoints()[2].x = controlPoint.getPoints()[0].x; controlPoint.getPoints()[2].y += 0.8; brd.getDeck().append(controlPoint); } - - //Add bottom end controlPoints to deck - controlPoint = (BezierKnot)brd.getBottom().getControlPoint(0).clone(); + + // Add bottom end controlPoints to deck + controlPoint = (BezierKnot) brd.getBottom().getControlPoint(0).clone(); controlPoint.getPoints()[2].x = 0; - controlPoint.getPoints()[2].y = (brd.getDeck().getControlPoint(0).getPoints()[0].y - controlPoint.getPoints()[0].y)/2 + controlPoint.getPoints()[0].y; + controlPoint.getPoints()[2].y = (brd.getDeck().getControlPoint(0).getPoints()[0].y - controlPoint.getPoints()[0].y) / 2 + controlPoint.getPoints()[0].y; brd.getDeck().insert(0, controlPoint); - - controlPoint = (BezierKnot)brd.getBottom().getControlPoint(brd.getBottom().getNrOfControlPoints()-1).clone(); + + controlPoint = (BezierKnot) brd.getBottom().getControlPoint(brd.getBottom().getNrOfControlPoints() - 1).clone(); controlPoint.getPoints()[1].x = controlPoint.getPoints()[0].x; - controlPoint.getPoints()[1].y = (brd.getDeck().getControlPoint(brd.getDeck().getNrOfControlPoints()-1).getPoints()[0].y - controlPoint.getPoints()[0].y)/2 + controlPoint.getPoints()[0].y; + controlPoint.getPoints()[1].y = (brd.getDeck().getControlPoint(brd.getDeck().getNrOfControlPoints() - 1).getPoints()[0].y - controlPoint.getPoints()[0].y) / 2 + controlPoint.getPoints()[0].y; brd.getDeck().append(controlPoint); - + BezierBoardCrossSection crossSection; - for(int i = 0; ;i++) - { + for (int i = 0;; i++) { String ident = "Couples_".concat(Integer.toString(i)); NodeList list = boardNode.getElementsByTagName(ident); - if(list.getLength() == 0) + if (list.getLength() == 0) break; - Element slice = (Element)list.item(0); - + Element slice = (Element) list.item(0); + crossSection = new BezierBoardCrossSection(); brd.getCrossSections().add(crossSection); - - Element bezierNode = (Element)slice.getElementsByTagName("Bezier3d").item(0); - - Element controlPointsNode = (Element)bezierNode.getElementsByTagName("Control_points").item(0); - Element controlPointsPolygone3dNode = (Element)controlPointsNode.getElementsByTagName("Polygone3d").item(0); + + Element bezierNode = (Element) slice.getElementsByTagName("Bezier3d").item(0); + + Element controlPointsNode = (Element) bezierNode.getElementsByTagName("Control_points").item(0); + Element controlPointsPolygone3dNode = (Element) controlPointsNode.getElementsByTagName("Polygone3d").item(0); NodeList controlPointsList = controlPointsPolygone3dNode.getElementsByTagName("Point3d"); - String value = ((Element)controlPointsList.item(1)).getElementsByTagName("x").item(0).getTextContent(); - + String value = ((Element) controlPointsList.item(1)).getElementsByTagName("x").item(0).getTextContent(); + double pos = Double.valueOf(value); crossSection.setPosition(pos); - + BezierSpline spline = crossSection.getBezierSpline(); readBezierAndGuidePoints(slice, spline, crossSection.getGuidePoints(), YZ); - - //Subtract however high the crosssection is above zero + + // Subtract however high the crosssection is above zero double height = spline.getControlPoint(0).getPoints()[0].y; - - for(int j = 0; j < spline.getNrOfControlPoints(); j++) - { + + for (int j = 0; j < spline.getNrOfControlPoints(); j++) { spline.getControlPoint(j).getPoints()[0].y -= height; spline.getControlPoint(j).getPoints()[1].y -= height; spline.getControlPoint(j).getPoints()[2].y -= height; } - + } - - //Move first and last crossSection as these are something special for shape3D + + // Move first and last crossSection as these are something special + // for shape3D brd.getCrossSections().get(0).setPosition(0.2); - brd.getCrossSections().get(brd.getCrossSections().size()-1).setPosition(brd.getLength()-0.2); - - - //Add crossection at tail like .brd + brd.getCrossSections().get(brd.getCrossSections().size() - 1).setPosition(brd.getLength() - 0.2); + + // Add crossection at tail like .brd crossSection = new BezierBoardCrossSection(); - crossSection.getBezierSpline().append(new BezierKnot(0,0,0,0,0,0)); + crossSection.getBezierSpline().append(new BezierKnot(0, 0, 0, 0, 0, 0)); crossSection.setPosition(0.0); brd.getCrossSections().add(0, crossSection); - - //Add crossection at tip like .brd + + // Add crossection at tip like .brd crossSection = new BezierBoardCrossSection(); - crossSection.getBezierSpline().append(new BezierKnot(0,0,0,0,0,0)); + crossSection.getBezierSpline().append(new BezierKnot(0, 0, 0, 0, 0, 0)); crossSection.setPosition(brd.getLength()); brd.getCrossSections().add(crossSection); - - //Read some board info + + // Read some board info brd.setModel(boardNode.getElementsByTagName("Name").item(0).getTextContent()); brd.setDesigner(boardNode.getElementsByTagName("Author").item(0).getTextContent()); brd.setComments(boardNode.getElementsByTagName("Comment").item(0).getTextContent()); - - //TODO: add reading of fins - brd.setFilename(aFilename); + // TODO: add reading of fins - brd.checkAndFixContinousy(false, true); + brd.setFilename(aFilename); + + brd.checkAndFixContinousy(false, true); + + brd.setLocks(); + } catch (IOException ioe) { + // I/O error + ioe.printStackTrace(); + + setErrorStr(LanguageResource.getString("S3DREADERRORMSG_STR") + ioe.getMessage()); + return -1; + } catch (SAXException sxe) { + // Error generated during parsing + Exception x = sxe; + if (sxe.getException() != null) + x = sxe.getException(); + setErrorStr(LanguageResource.getString("S3DREADERRORMSG_STR") + x.getMessage()); + return -1; + + } catch (ParserConfigurationException pce) { + // Parser with specified options can't be built + pce.printStackTrace(); + + setErrorStr(LanguageResource.getString("S3DREADERRORMSG_STR") + pce.getMessage()); - brd.setLocks(); - } - catch (IOException ioe) { - // I/O error - ioe.printStackTrace(); - - setErrorStr(LanguageResource.getString("S3DREADERRORMSG_STR") + ioe.getMessage()); - return -1; - } - catch (SAXException sxe) { - // Error generated during parsing - Exception x = sxe; - if (sxe.getException() != null) - x = sxe.getException(); - setErrorStr(LanguageResource.getString("S3DREADERRORMSG_STR") + x.getMessage()); return -1; - - } catch (ParserConfigurationException pce) { - // Parser with specified options can't be built - pce.printStackTrace(); - - setErrorStr(LanguageResource.getString("S3DREADERRORMSG_STR") + pce.getMessage()); - - return -1; - } - + } + return ret; } - - static boolean readBezierAndGuidePoints(Element parent, BezierSpline bezier, ArrayList guidePoints, int whichPlane) - { - Element bezierNode = (Element)parent.getElementsByTagName("Bezier3d").item(0); - - Element controlPointsNode = (Element)bezierNode.getElementsByTagName("Control_points").item(0); - Element tangents1Node = (Element)bezierNode.getElementsByTagName("Tangents_1").item(0); - Element tangents2Node = (Element)bezierNode.getElementsByTagName("Tangents_2").item(0); - - Element controlPointsPolygone3dNode = (Element)controlPointsNode.getElementsByTagName("Polygone3d").item(0); - Element tangents1Polygone3dNode = (Element)tangents1Node.getElementsByTagName("Polygone3d").item(0); - Element tangents2Polygone3dNode = (Element)tangents2Node.getElementsByTagName("Polygone3d").item(0); - + + static boolean readBezierAndGuidePoints(Element parent, BezierSpline bezier, ArrayList guidePoints, int whichPlane) { + Element bezierNode = (Element) parent.getElementsByTagName("Bezier3d").item(0); + + Element controlPointsNode = (Element) bezierNode.getElementsByTagName("Control_points").item(0); + Element tangents1Node = (Element) bezierNode.getElementsByTagName("Tangents_1").item(0); + Element tangents2Node = (Element) bezierNode.getElementsByTagName("Tangents_2").item(0); + + Element controlPointsPolygone3dNode = (Element) controlPointsNode.getElementsByTagName("Polygone3d").item(0); + Element tangents1Polygone3dNode = (Element) tangents1Node.getElementsByTagName("Polygone3d").item(0); + Element tangents2Polygone3dNode = (Element) tangents2Node.getElementsByTagName("Polygone3d").item(0); + String numberOfPointsStr = controlPointsPolygone3dNode.getElementsByTagName("Nb_of_points").item(0).getTextContent(); - + NodeList controlPointsList = controlPointsPolygone3dNode.getElementsByTagName("Point3d"); NodeList tangents1PointsList = tangents1Polygone3dNode.getElementsByTagName("Point3d"); NodeList tangents2PointsList = tangents2Polygone3dNode.getElementsByTagName("Point3d"); int nrOfPoints = Integer.parseInt(numberOfPointsStr); - - //Disregard first as it's the symetry point and we don't care about that(whatever that is) - for(int i = 1; i < nrOfPoints+1; i++) - { - System.out.printf("loop: i=%d\n", i); + + // Disregard first as it's the symetry point and we don't care about + // that(whatever that is) + for (int i = 1; i < nrOfPoints + 1; i++) { + // System.out.printf("loop: i=%d\n", i); BezierKnot newControlPoint = new BezierKnot(); - - String cx = ((Element)controlPointsList.item(i)).getElementsByTagName("x").item(0).getTextContent(); - String cy = ((Element)controlPointsList.item(i)).getElementsByTagName("y").item(0).getTextContent(); - String cz = ((Element)controlPointsList.item(i)).getElementsByTagName("z").item(0).getTextContent(); - - String t1x = ((Element)tangents1PointsList.item(i)).getElementsByTagName("x").item(0).getTextContent(); - String t1y = ((Element)tangents1PointsList.item(i)).getElementsByTagName("y").item(0).getTextContent(); - String t1z = ((Element)tangents1PointsList.item(i)).getElementsByTagName("z").item(0).getTextContent(); - - String t2x = ((Element)tangents2PointsList.item(i)).getElementsByTagName("x").item(0).getTextContent(); - String t2y = ((Element)tangents2PointsList.item(i)).getElementsByTagName("y").item(0).getTextContent(); - String t2z = ((Element)tangents2PointsList.item(i)).getElementsByTagName("z").item(0).getTextContent(); - + + String cx = ((Element) controlPointsList.item(i)).getElementsByTagName("x").item(0).getTextContent(); + String cy = ((Element) controlPointsList.item(i)).getElementsByTagName("y").item(0).getTextContent(); + String cz = ((Element) controlPointsList.item(i)).getElementsByTagName("z").item(0).getTextContent(); + + String t1x = ((Element) tangents1PointsList.item(i)).getElementsByTagName("x").item(0).getTextContent(); + String t1y = ((Element) tangents1PointsList.item(i)).getElementsByTagName("y").item(0).getTextContent(); + String t1z = ((Element) tangents1PointsList.item(i)).getElementsByTagName("z").item(0).getTextContent(); + + String t2x = ((Element) tangents2PointsList.item(i)).getElementsByTagName("x").item(0).getTextContent(); + String t2y = ((Element) tangents2PointsList.item(i)).getElementsByTagName("y").item(0).getTextContent(); + String t2z = ((Element) tangents2PointsList.item(i)).getElementsByTagName("z").item(0).getTextContent(); + String p1x, p1y, p2x, p2y, p3x, p3y; - - switch(whichPlane) - { + + switch (whichPlane) { default: case XY: p1x = cx; @@ -287,7 +276,7 @@ static boolean readBezierAndGuidePoints(Element parent, BezierSpline bezier, Arr p3x = t2x; p3y = t2z; break; - + case YZ: p1x = cy; p1y = cz; @@ -297,17 +286,16 @@ static boolean readBezierAndGuidePoints(Element parent, BezierSpline bezier, Arr p3y = t2z; break; } - + newControlPoint.getPoints()[0].setLocation(Double.parseDouble(p1x), Double.parseDouble(p1y)); newControlPoint.getPoints()[1].setLocation(Double.parseDouble(p2x), Double.parseDouble(p2y)); newControlPoint.getPoints()[2].setLocation(Double.parseDouble(p3x), Double.parseDouble(p3y)); - - String typeIdent = "Tangent_type_point_".concat(Integer.toString(i-1)); + + String typeIdent = "Tangent_type_point_".concat(Integer.toString(i - 1)); String typeStr = bezierNode.getElementsByTagName(typeIdent).item(0).getTextContent().trim(); int type = Integer.parseInt(typeStr); - - switch(type) - { + + switch (type) { case 0: newControlPoint.setContinous(false); break; @@ -315,38 +303,33 @@ static boolean readBezierAndGuidePoints(Element parent, BezierSpline bezier, Arr newControlPoint.setContinous(true); break; } - + bezier.append(newControlPoint); } - - System.out.printf("here\n"); - - //Read guidepoints + + // Read guidepoints int nrOfGuidePoints = 0; NodeList guidePointsElements = bezierNode.getElementsByTagName("Number_of_guides"); - if(guidePointsElements.getLength() > 0) - { + if (guidePointsElements.getLength() > 0) { String numberOfGuidePointsStr = guidePointsElements.item(0).getTextContent(); nrOfGuidePoints = Integer.parseInt(numberOfGuidePointsStr); } - + NodeList guidePointsList = bezierNode.getElementsByTagName("Guide"); - for(int i = 0; i < nrOfGuidePoints; i++) - { + for (int i = 0; i < nrOfGuidePoints; i++) { Point2D.Double gp = new Point2D.Double(); - - Element guideNode = (Element)guidePointsList.item(i); - Element guidePointNode = (Element)guideNode.getElementsByTagName("Point3d").item(0); - + + Element guideNode = (Element) guidePointsList.item(i); + Element guidePointNode = (Element) guideNode.getElementsByTagName("Point3d").item(0); + String gx = guidePointNode.getElementsByTagName("x").item(0).getTextContent(); String gy = guidePointNode.getElementsByTagName("y").item(0).getTextContent(); String gz = guidePointNode.getElementsByTagName("z").item(0).getTextContent(); - + String gpx, gpy; - - switch(whichPlane) - { + + switch (whichPlane) { default: case XY: gpx = gx; @@ -357,28 +340,26 @@ static boolean readBezierAndGuidePoints(Element parent, BezierSpline bezier, Arr gpx = gx; gpy = gz; break; - + case YZ: gpx = gy; gpy = gz; break; } - + gp.setLocation(Double.parseDouble(gpx), Double.parseDouble(gpy)); - + guidePoints.add(gp); } return true; } - - static void setErrorStr(String errorStr) - { + + static void setErrorStr(String errorStr) { mErrorStr = errorStr; } - - static public String getErrorStr() - { + + static public String getErrorStr() { return mErrorStr; } } \ No newline at end of file diff --git a/board/readers/S3dxReader.java b/board/readers/S3dxReader.java new file mode 100644 index 0000000..f058591 --- /dev/null +++ b/board/readers/S3dxReader.java @@ -0,0 +1,364 @@ +package board.readers; + +import java.awt.geom.Point2D; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import board.BezierBoard; +import cadcore.BezierKnot; +import cadcore.BezierSpline; +import cadcore.UnitUtils; +import boardcad.i18n.LanguageResource; +import cadcore.BezierBoardCrossSection; + +public class S3dxReader { + + static final int XY = 0; + static final int XZ = 1; + static final int YZ = 2; + + static String mErrorStr; + + static public int loadFile(BezierBoard brd, String aFilename) { + + int ret = 0; + + brd.reset(); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + + try { + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(new File(aFilename)); + + Element shape3Dnode = (Element) document.getElementsByTagName("Shape3d_design").item(0); + Element boardNode = (Element) shape3Dnode.getElementsByTagName("Board").item(0); + + Element bottom = (Element) boardNode.getElementsByTagName("curveDefSide0").item(0); + Element deck = (Element) boardNode.getElementsByTagName("curveDefSide4").item(0); + Element outline = (Element) boardNode.getElementsByTagName("curveDefTop2").item(0); + + readBezierAndGuidePoints(outline, brd.getOutline(), brd.getOutlineGuidePoints(), XY); + + BezierKnot controlPoint; + // Add outline controlPoints at tail and nose + if (brd.getOutline().getControlPoint(0).getPoints()[0].y > 1.0) { + brd.getOutline().getControlPoint(0).setContinous(false); + brd.getOutline().getControlPoint(0).getPoints()[1].y = brd.getOutline().getControlPoint(0).getPoints()[0].y * 2 / 3; + + controlPoint = new BezierKnot(); + controlPoint.getPoints()[2].y = brd.getOutline().getControlPoint(0).getPoints()[0].y / 3; + brd.getOutline().insert(0, controlPoint); + } + + if (brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[0].y > 1.0) { + brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).setContinous(false); + brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[2].x = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[0].x; + brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[2].y = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[0].y * 2 / 3; + + controlPoint = new BezierKnot(); + controlPoint.getPoints()[0].x = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[0].x; + controlPoint.getPoints()[1].x = controlPoint.getPoints()[0].x; + controlPoint.getPoints()[1].y = brd.getOutline().getControlPoint(brd.getOutline().getNrOfControlPoints() - 1).getPoints()[0].y / 3; + controlPoint.getPoints()[2].x = controlPoint.getPoints()[0].x; + brd.getOutline().append(controlPoint); + } + + readBezierAndGuidePoints(bottom, brd.getBottom(), brd.getBottomGuidePoints(), XZ); + if (deck != null) // Thickness curve instead? + { + readBezierAndGuidePoints(deck, brd.getDeck(), brd.getDeckGuidePoints(), XZ); + } else { + // TODO: Add generation of deck curve from thickness curve when + // curve fitting is implemented + + ret = 1; // Warning code, deck curve is no good + + // Dummy deck curve + controlPoint = (BezierKnot) brd.getBottom().getControlPoint(0).clone(); + controlPoint.setContinous(false); + controlPoint.getPoints()[0].y += 1.5; + controlPoint.getPoints()[2].x = 20; + controlPoint.getPoints()[2].y = controlPoint.getPoints()[0].y - 0.5; + brd.getDeck().append(controlPoint); + + double thickness = (((brd.getLength() / (12 * UnitUtils.INCH)) - 5) / 4 * 1) + 2.125 * UnitUtils.INCH; + controlPoint = new BezierKnot(); + controlPoint.getPoints()[0].x = brd.getLength() / 2; + controlPoint.getPoints()[0].y = thickness; + controlPoint.getPoints()[1].x = controlPoint.getPoints()[0].x - 50; + controlPoint.getPoints()[1].y = thickness; + controlPoint.getPoints()[2].x = controlPoint.getPoints()[0].x + 50; + controlPoint.getPoints()[2].y = thickness; + brd.getDeck().append(controlPoint); + + controlPoint = (BezierKnot) brd.getBottom().getControlPoint(brd.getBottom().getNrOfControlPoints() - 1).clone(); + controlPoint.setContinous(false); + controlPoint.getPoints()[0].y += 1.5; + controlPoint.getPoints()[1].y += controlPoint.getPoints()[0].y / 2; + controlPoint.getPoints()[2].x = controlPoint.getPoints()[0].x; + controlPoint.getPoints()[2].y += 0.8; + brd.getDeck().append(controlPoint); + + } + + // Add bottom end controlPoints to deck + controlPoint = (BezierKnot) brd.getBottom().getControlPoint(0).clone(); + controlPoint.getPoints()[2].x = 0; + controlPoint.getPoints()[2].y = (brd.getDeck().getControlPoint(0).getPoints()[0].y - controlPoint.getPoints()[0].y) / 2 + controlPoint.getPoints()[0].y; + brd.getDeck().insert(0, controlPoint); + + controlPoint = (BezierKnot) brd.getBottom().getControlPoint(brd.getBottom().getNrOfControlPoints() - 1).clone(); + controlPoint.getPoints()[1].x = controlPoint.getPoints()[0].x; + controlPoint.getPoints()[1].y = (brd.getDeck().getControlPoint(brd.getDeck().getNrOfControlPoints() - 1).getPoints()[0].y - controlPoint.getPoints()[0].y) / 2 + controlPoint.getPoints()[0].y; + brd.getDeck().append(controlPoint); + + BezierBoardCrossSection crossSection; + for (int i = 0;; i++) { + String ident = "Couples_".concat(Integer.toString(i)); + NodeList list = boardNode.getElementsByTagName(ident); + if (list.getLength() == 0) + break; + + Element slice = (Element) list.item(0); + + crossSection = new BezierBoardCrossSection(); + + brd.getCrossSections().add(crossSection); + + Element bezierNode = (Element) slice.getElementsByTagName("Bezier3d").item(0); + + Element controlPointsNode = (Element) bezierNode.getElementsByTagName("Control_points").item(0); + Element controlPointsPolygone3dNode = (Element) controlPointsNode.getElementsByTagName("Polygone3d").item(0); + NodeList controlPointsList = controlPointsPolygone3dNode.getElementsByTagName("Point3d"); + String value = ((Element) controlPointsList.item(1)).getElementsByTagName("x").item(0).getTextContent(); + + double pos = Double.valueOf(value); + + crossSection.setPosition(pos); + + BezierSpline spline = crossSection.getBezierSpline(); + + readBezierAndGuidePoints(slice, spline, crossSection.getGuidePoints(), YZ); + + // Subtract however high the crosssection is above zero + double height = spline.getControlPoint(0).getPoints()[0].y; + + for (int j = 0; j < spline.getNrOfControlPoints(); j++) { + spline.getControlPoint(j).getPoints()[0].y -= height; + spline.getControlPoint(j).getPoints()[1].y -= height; + spline.getControlPoint(j).getPoints()[2].y -= height; + } + + } + + // Move first and last crossSection as these are something special + // for shape3D + brd.getCrossSections().get(0).setPosition(0.2); + brd.getCrossSections().get(brd.getCrossSections().size() - 1).setPosition(brd.getLength() - 0.2); + + // Add crossection at tail like .brd + crossSection = new BezierBoardCrossSection(); + crossSection.getBezierSpline().append(new BezierKnot(0, 0, 0, 0, 0, 0)); + crossSection.setPosition(0.0); + brd.getCrossSections().add(0, crossSection); + + // Add crossection at tip like .brd + crossSection = new BezierBoardCrossSection(); + crossSection.getBezierSpline().append(new BezierKnot(0, 0, 0, 0, 0, 0)); + crossSection.setPosition(brd.getLength()); + brd.getCrossSections().add(crossSection); + + // Read some board info + brd.setModel(boardNode.getElementsByTagName("Name").item(0).getTextContent()); + brd.setDesigner(boardNode.getElementsByTagName("Author").item(0).getTextContent()); + brd.setComments(boardNode.getElementsByTagName("Comment").item(0).getTextContent()); + + // TODO: add reading of fins + + brd.setFilename(aFilename); + + brd.checkAndFixContinousy(false, true); + + brd.setLocks(); + } catch (IOException ioe) { + // I/O error + ioe.printStackTrace(); + + setErrorStr(LanguageResource.getString("S3DREADERRORMSG_STR") + ioe.getMessage()); + return -1; + } catch (SAXException sxe) { + // Error generated during parsing + Exception x = sxe; + if (sxe.getException() != null) + x = sxe.getException(); + setErrorStr(LanguageResource.getString("S3DREADERRORMSG_STR") + x.getMessage()); + return -1; + + } catch (ParserConfigurationException pce) { + // Parser with specified options can't be built + pce.printStackTrace(); + + setErrorStr(LanguageResource.getString("S3DREADERRORMSG_STR") + pce.getMessage()); + + return -1; + } + + return ret; + } + + static boolean readBezierAndGuidePoints(Element parent, BezierSpline bezier, ArrayList guidePoints, int whichPlane) { + Element bezierNode = (Element) parent.getElementsByTagName("Bezier3d").item(0); + + Element controlPointsNode = (Element) bezierNode.getElementsByTagName("Control_points").item(0); + Element tangents1Node = (Element) bezierNode.getElementsByTagName("Tangents_1").item(0); + Element tangents2Node = (Element) bezierNode.getElementsByTagName("Tangents_2").item(0); + + Element controlPointsPolygone3dNode = (Element) controlPointsNode.getElementsByTagName("Polygone3d").item(0); + Element tangents1Polygone3dNode = (Element) tangents1Node.getElementsByTagName("Polygone3d").item(0); + Element tangents2Polygone3dNode = (Element) tangents2Node.getElementsByTagName("Polygone3d").item(0); + + String numberOfPointsStr = controlPointsPolygone3dNode.getElementsByTagName("Nb_of_points").item(0).getTextContent(); + + NodeList controlPointsList = controlPointsPolygone3dNode.getElementsByTagName("Point3d"); + NodeList tangents1PointsList = tangents1Polygone3dNode.getElementsByTagName("Point3d"); + NodeList tangents2PointsList = tangents2Polygone3dNode.getElementsByTagName("Point3d"); + + int nrOfPoints = Integer.parseInt(numberOfPointsStr); + + // Disregard first as it's the symetry point and we don't care about + // that(whatever that is) + for (int i = 1; i < nrOfPoints + 1; i++) { + // System.out.printf("loop: i=%d\n", i); + BezierKnot newControlPoint = new BezierKnot(); + + String cx = ((Element) controlPointsList.item(i)).getElementsByTagName("x").item(0).getTextContent(); + String cy = ((Element) controlPointsList.item(i)).getElementsByTagName("y").item(0).getTextContent(); + String cz = ((Element) controlPointsList.item(i)).getElementsByTagName("z").item(0).getTextContent(); + + String t1x = ((Element) tangents1PointsList.item(i)).getElementsByTagName("x").item(0).getTextContent(); + String t1y = ((Element) tangents1PointsList.item(i)).getElementsByTagName("y").item(0).getTextContent(); + String t1z = ((Element) tangents1PointsList.item(i)).getElementsByTagName("z").item(0).getTextContent(); + + String t2x = ((Element) tangents2PointsList.item(i)).getElementsByTagName("x").item(0).getTextContent(); + String t2y = ((Element) tangents2PointsList.item(i)).getElementsByTagName("y").item(0).getTextContent(); + String t2z = ((Element) tangents2PointsList.item(i)).getElementsByTagName("z").item(0).getTextContent(); + + String p1x, p1y, p2x, p2y, p3x, p3y; + + switch (whichPlane) { + default: + case XY: + p1x = cx; + p1y = cy; + p2x = t1x; + p2y = t1y; + p3x = t2x; + p3y = t2y; + break; + + case XZ: + p1x = cx; + p1y = cz; + p2x = t1x; + p2y = t1z; + p3x = t2x; + p3y = t2z; + break; + + case YZ: + p1x = cy; + p1y = cz; + p2x = t1y; + p2y = t1z; + p3x = t2y; + p3y = t2z; + break; + } + + newControlPoint.getPoints()[0].setLocation(Double.parseDouble(p1x), Double.parseDouble(p1y)); + newControlPoint.getPoints()[1].setLocation(Double.parseDouble(p2x), Double.parseDouble(p2y)); + newControlPoint.getPoints()[2].setLocation(Double.parseDouble(p3x), Double.parseDouble(p3y)); + + String typeIdent = "Tangent_type_point_".concat(Integer.toString(i - 1)); + String typeStr = bezierNode.getElementsByTagName(typeIdent).item(0).getTextContent().trim(); + int type = Integer.parseInt(typeStr); + + switch (type) { + case 0: + newControlPoint.setContinous(false); + break; + default: + newControlPoint.setContinous(true); + break; + } + + bezier.append(newControlPoint); + } + + // Read guidepoints + int nrOfGuidePoints = 0; + NodeList guidePointsElements = bezierNode.getElementsByTagName("Number_of_guides"); + if (guidePointsElements.getLength() > 0) { + String numberOfGuidePointsStr = guidePointsElements.item(0).getTextContent(); + nrOfGuidePoints = Integer.parseInt(numberOfGuidePointsStr); + } + + NodeList guidePointsList = bezierNode.getElementsByTagName("Guide"); + + for (int i = 0; i < nrOfGuidePoints; i++) { + Point2D.Double gp = new Point2D.Double(); + + Element guideNode = (Element) guidePointsList.item(i); + Element guidePointNode = (Element) guideNode.getElementsByTagName("Point3d").item(0); + + String gx = guidePointNode.getElementsByTagName("x").item(0).getTextContent(); + String gy = guidePointNode.getElementsByTagName("y").item(0).getTextContent(); + String gz = guidePointNode.getElementsByTagName("z").item(0).getTextContent(); + + String gpx, gpy; + + switch (whichPlane) { + default: + case XY: + gpx = gx; + gpy = gy; + break; + + case XZ: + gpx = gx; + gpy = gz; + break; + + case YZ: + gpx = gy; + gpy = gz; + break; + } + + gp.setLocation(Double.parseDouble(gpx), Double.parseDouble(gpy)); + + guidePoints.add(gp); + } + + return true; + } + + static void setErrorStr(String errorStr) { + mErrorStr = errorStr; + } + + static public String getErrorStr() { + return mErrorStr; + } +} \ No newline at end of file diff --git a/board/writers/BrdXmlWriter.java b/board/writers/BrdXmlWriter.java new file mode 100644 index 0000000..ef8705b --- /dev/null +++ b/board/writers/BrdXmlWriter.java @@ -0,0 +1,5 @@ +package board.writers; + +public class BrdXmlWriter { + +} diff --git a/boardcad/AbstractDraw.java b/boardcad/AbstractDraw.java index f29c455..9edd527 100644 --- a/boardcad/AbstractDraw.java +++ b/boardcad/AbstractDraw.java @@ -14,10 +14,10 @@ /* - * Abstraction of drawing rutines + * Abstraction of drawing routines * Useful for 'printing' to other formats, like g-code, dxf, pdf, etc. * This way the same base functions can be used to print to several formats, - * making it possible to reuse significan portions of code for less code to maintain + * making it possible to reuse significant portions of code for less code to maintain * This is a minimum subset of Graphics2D for drawing a board * An alternative would be to extend Graphics2D for these operations, * however Graphics2D is quite extensive. By using a small subset of diff --git a/boardcad/DefaultBrds.java b/boardcad/DefaultBrds.java index a1299f5..f626660 100644 --- a/boardcad/DefaultBrds.java +++ b/boardcad/DefaultBrds.java @@ -571,14 +571,14 @@ public class DefaultBrds { "(cp [0.0,6.413541437064628,0.0,6.413541437064628,0.0,6.413541437064628] false false)\n" + "(cp [2.0372969384043866,5.938426622370623,0.4352967075788854,6.265849376563937,31.505670695706144,-0.08442899996709828] true false)\n" + "(cp [93.84005158846932,5.911698158414175E-4,64.80302765905056,5.911698158414175E-4,123.615494712459,5.911698158414175E-4] true false)\n" + -"(cp [185.00201789368649,11.662870290026836,155.10080629850802,-0.28686695561028536,187.0,12.5] true false)\n" + +"(cp [185.00201789368649,11.662870290026836,155.10080629850802,-0.28686695561028536,187.66794122341875,12.728281409101742] true false)\n" + "(cp [187.96,13.360421410740276,187.96,13.337136739108956,187.96,37.66452933343878] false false)\n" + ")\n" + "p34 : (\n" + "(cp [0.0,6.413541437064628,1.1089640000000003,6.202558557082126,0.0,7.323388462757916] false false)\n" + "(cp [2.228131161855172,7.3389721014970135,0.116050134107899,7.410076938994328,31.875543379285887,6.319464242654043] true false)\n" + "(cp [94.07041604627575,5.929755333114977,64.08024215542102,5.929755333114977,124.37187508456834,5.929755333114977] true false)\n" + -"(cp [185.054049884115,12.832745136704508,155.16805402094025,2.0739530506750636,187.0,13.5] true false)\n" + +"(cp [185.054049884115,12.832745136704508,155.16805402094025,2.0739530506750636,188.5335210790606,14.085335390920367] true false)\n" + "(cp [187.96,13.360421410740276,187.96,13.800442166914932,187.96,13.360421410740276] false false)\n" + ")\n" + "p35 : (\n" + diff --git a/boardcad/FileTools.java b/boardcad/FileTools.java index f0bc4a9..3a25e49 100644 --- a/boardcad/FileTools.java +++ b/boardcad/FileTools.java @@ -36,6 +36,15 @@ public static String setExtension(String filename, String setExt) { return tmp; } + //Remove the extension + public static String removeExtension(String filename) { + String ext = getExtension(filename); + int i = filename.lastIndexOf('.'); + String tmp = filename.substring(0,i); + + return tmp; + } + //Append without affecting the extension public static String append(String filename, String append) { String ext = getExtension(filename); diff --git a/boardcad/commands/BrdAbstractEditCommand.java b/boardcad/commands/BrdAbstractEditCommand.java new file mode 100644 index 0000000..f725804 --- /dev/null +++ b/boardcad/commands/BrdAbstractEditCommand.java @@ -0,0 +1,164 @@ +package boardcad.commands; + +import java.util.ArrayList; + +import board.BezierBoard; +import cadcore.BezierKnot; +import cadcore.BezierSpline; + +//Class with functions for storing changes to a brd for undo/redo functionality +//This is to pick up on changes from scaling and translation for fitting rocker to zero +//and fitting cross sections to width and thickness +abstract class BrdAbstractEditCommand extends BrdInputCommand implements Cloneable +{ + class ControlPointChange implements Cloneable + { + BezierKnot mChangedPoint; + BezierKnot mBefore; + BezierKnot mAfter; + + ControlPointChange(BezierKnot point, BezierKnot before, BezierKnot after) + { + mChangedPoint = point; + mBefore = before; + mAfter = after; + } + + void undo() + { + mChangedPoint.set(mBefore); + } + + void redo() + { + mChangedPoint.set(mAfter); + } + + public Object clone() + { + ControlPointChange controlPointChange = null; + try { + controlPointChange = (ControlPointChange)super.clone(); + } catch(CloneNotSupportedException e) { + System.out.println("BrdAbstractEditCommand.clone() Exception: " + e.toString()); + throw new Error("CloneNotSupportedException in BrdAbstractEditCommand"); + } + + controlPointChange.mChangedPoint = (BezierKnot)mChangedPoint; + controlPointChange.mBefore = (BezierKnot)mBefore.clone(); + controlPointChange.mAfter = (BezierKnot)mAfter.clone(); + + return controlPointChange; + } + + + } + + static private ArrayList mPoints = new ArrayList(); + static private ArrayList mBeforeChangePoints = new ArrayList(); + + private ArrayList mChanges; + + void saveBeforeChange(BezierBoard brd) + { + mPoints.clear(); + mBeforeChangePoints.clear(); + mChanges = new ArrayList(); + + BezierSpline currentBezier = null; + BezierKnot point = null; + for(int i=0;i(); + for(int i = 0; i < this.mChanges.size(); i++) + { + abstractEditCommand.mChanges.add((ControlPointChange)this.mChanges.get(i).clone()); + } + + return abstractEditCommand; + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdAddControlPointCommand.java b/boardcad/commands/BrdAddControlPointCommand.java new file mode 100644 index 0000000..766fe47 --- /dev/null +++ b/boardcad/commands/BrdAddControlPointCommand.java @@ -0,0 +1,92 @@ +package boardcad.commands; + +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.geom.Point2D; + +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; +import cadcore.BezierCurve; +import cadcore.BezierKnot; +import cadcore.BezierSpline; +import cadcore.VecMath; + +public class BrdAddControlPointCommand extends BrdAbstractEditCommand +{ + static double K = 1.0f; + + private int mIndex = 0; + private BezierKnot mNewControlPoint = null; + private BezierSpline mSpline; + + + public BrdAddControlPointCommand() + { + } + + public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) + { + super.saveBeforeChange(source.getCurrentBrd()); + + Point pos = event.getPoint(); + Point2D.Double brdPos = source.screenCoordinateToBrdCoordinate(pos); + + BezierSpline[] splines = source.getActiveBezierSplines(source.getCurrentBrd()); + mNewControlPoint = new BezierKnot(); + + for(int i = 0; i < splines.length; i++) + { + mIndex = splines[i].getSplitControlPoint(brdPos, mNewControlPoint); + + if(mIndex < 0) + continue; + + mSpline = splines[i]; + + mSpline.insert(mIndex, mNewControlPoint); + + Point2D.Double tmp = new Point2D.Double(); + + BezierKnot prev = mSpline.getControlPoint(mIndex-1); + BezierKnot next = mSpline.getControlPoint(mIndex+1); + + BezierCurve tmpCurve = new BezierCurve(prev, next); + + double t = tmpCurve.getClosestT(brdPos); + + VecMath.subVector(prev.getPoints()[0],prev.getPoints()[2],tmp); + VecMath.scaleVector(tmp, t); + VecMath.addVector(prev.getPoints()[0],tmp,prev.getPoints()[2]); + + VecMath.subVector(next.getPoints()[1],next.getPoints()[0],tmp); + VecMath.scaleVector(tmp, t-1); + VecMath.addVector(next.getPoints()[0],tmp,next.getPoints()[1]); + + source.onBrdChanged(); + + execute(); + + source.repaint(); + } + + } + + public void redo() + { + mSpline.insert(mIndex, mNewControlPoint); + + super.redo(); + } + + public void undo() + { + mSpline.remove(mIndex); + + super.undo(); + } + + public String getCommandString() + { + return LanguageResource.getString("ADDCONTROLPOINTCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdAddCrossSectionCommand.java b/boardcad/commands/BrdAddCrossSectionCommand.java new file mode 100644 index 0000000..bd9a33f --- /dev/null +++ b/boardcad/commands/BrdAddCrossSectionCommand.java @@ -0,0 +1,60 @@ +package boardcad.commands; + +import board.BezierBoard; +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; +import cadcore.BezierBoardCrossSection; + +public class BrdAddCrossSectionCommand extends BrdCommand +{ + double mPos; + BezierBoardCrossSection mNewCrossSection = null; + + + public BrdAddCrossSectionCommand(BoardEdit source, double pos) + { + mSource = source; + + mPos = pos; + } + + public void execute() + { + BezierBoard brd = mSource.getCurrentBrd(); + +// mNewCrossSection = (BezierBoardCrossSection)brd.getNearestCrossSection(mPos).clone(); + mNewCrossSection = (BezierBoardCrossSection)brd.getInterpolatedCrossSection(mPos).clone(); + + mNewCrossSection.setPosition(mPos); + + mNewCrossSection.scale(brd.getThicknessAtPos(mPos), brd.getWidthAtPos(mPos)); + + brd.addCrossSection(mNewCrossSection); + + super.execute(); + } + + public void undo() + { + BezierBoard brd = mSource.getCurrentBrd(); + + brd.removeCrossSection(mNewCrossSection); + + super.undo(); + + } + + public void redo() + { + BezierBoard brd = mSource.getCurrentBrd(); + + brd.addCrossSection(mNewCrossSection); + + super.redo(); + } + + public String getCommandString() + { + return LanguageResource.getString("ADDCROSSECTIONCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdAddGuidePointCommand.java b/boardcad/commands/BrdAddGuidePointCommand.java new file mode 100644 index 0000000..bee861e --- /dev/null +++ b/boardcad/commands/BrdAddGuidePointCommand.java @@ -0,0 +1,33 @@ +package boardcad.commands; + +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.geom.Point2D; + +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; + +public class BrdAddGuidePointCommand extends BrdInputCommand +{ + public BrdAddGuidePointCommand() + { + mCanUndo = false; + + } + + public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) + { + Point pos = event.getPoint(); + Point2D.Double guidePoint = source.screenCoordinateToBrdCoordinate(pos); + + source.getGuidePoints().add(guidePoint); + source.repaint(); + BoardCAD.getInstance().getGuidePointsDialog().update(); + } + + public String getCommandString() + { + return LanguageResource.getString("ADDGUIDEPOINTCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdCommand.java b/boardcad/commands/BrdCommand.java new file mode 100644 index 0000000..71ab546 --- /dev/null +++ b/boardcad/commands/BrdCommand.java @@ -0,0 +1,82 @@ +package boardcad.commands; + +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardEdit; + +public abstract class BrdCommand extends Object implements Cloneable{ + boolean mCanUndo = true; + BoardEdit mSource = null; + BrdCommand mPreviousCommand = null; + + public void setPreviousCommand(BrdCommand previousCommand) + { + mPreviousCommand = previousCommand; + } + + public void doAction() + { + + } + + public void execute() + { + if(canUndo()) + { + BrdCommandHistory.getInstance().addCommand((BrdCommand)this.clone()); + } + + if(mPreviousCommand != null) + { + BoardCAD.getInstance().setCurrentCommand(mPreviousCommand); + } + + }; //Do command including user interactions + + public void setSource(BoardEdit source) + { + mSource = source; + } + + public void redo() + { + if(mSource != null) + { + BoardCAD.getInstance().setSelectedEdit(mSource); + mSource.onBrdChanged(); + BoardCAD.getInstance().onControlPointChanged(); + } + + } + + public void undo() + { + if(mSource != null) + { + BoardCAD.getInstance().setSelectedEdit(mSource); + mSource.onBrdChanged(); + BoardCAD.getInstance().onControlPointChanged(); + } + } + public boolean canUndo(){return mCanUndo;}; + + public Object clone(){ + try { + return super.clone(); + } catch(CloneNotSupportedException e) { + System.out.println("BoardComand.clone() Exception: " + e.toString()); + throw new Error("CloneNotSupportedException in BrdCommand"); + } + } + + public void onSetCurrent() + { + + } + + public void onCurrentChanged() + { + + } + + public abstract String getCommandString(); +} \ No newline at end of file diff --git a/boardcad/commands/BrdCommandHistory.java b/boardcad/commands/BrdCommandHistory.java new file mode 100644 index 0000000..7cb8d6d --- /dev/null +++ b/boardcad/commands/BrdCommandHistory.java @@ -0,0 +1,70 @@ +package boardcad.commands; + +import java.util.LinkedList; + +public class BrdCommandHistory +{ + private LinkedList mCommandHistory; + private int mCurrentCommandIndex; + + private static BrdCommandHistory mInstance = null; + + private BrdCommandHistory() + { + mCommandHistory = new LinkedList(); + } + + public static BrdCommandHistory getInstance() + { + if(mInstance == null) { + mInstance = new BrdCommandHistory(); + } + return mInstance; + } + + public void clear() + { + mCommandHistory.clear(); + mCurrentCommandIndex = -1; + } + + public void addCommand(BrdCommand command) + { + if(mCurrentCommandIndex>=0 && mCommandHistory.size() > mCurrentCommandIndex+1) + { + /* Sometimes get java.util.ConcurrentModificationException with this code + * int size = mCommandHistory.size(); + java.util.List toBeRemoved = mCommandHistory.subList(mCurrentCommand+1, size); + mCommandHistory.removeAll(toBeRemoved); + */ + while(mCommandHistory.size() > mCurrentCommandIndex+1) + { + mCommandHistory.removeLast(); + } + } + mCommandHistory.add(command); + mCurrentCommandIndex = mCommandHistory.size()-1; + } + + public void undo() + { + if(mCurrentCommandIndex >= 0) + { + BrdCommand command = mCommandHistory.get(mCurrentCommandIndex--); + if(command == null) + return; + command.undo(); + } + } + + public void redo() + { + if(mCurrentCommandIndex < mCommandHistory.size()-1 && mCommandHistory.size() > 0) + { + BrdCommand command = mCommandHistory.get(++mCurrentCommandIndex); + if(command == null) + return; + command.redo(); + } + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdDeleteControlPointCommand.java b/boardcad/commands/BrdDeleteControlPointCommand.java new file mode 100644 index 0000000..faa47cb --- /dev/null +++ b/boardcad/commands/BrdDeleteControlPointCommand.java @@ -0,0 +1,106 @@ +package boardcad.commands; + +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; +import cadcore.BezierCurve; +import cadcore.BezierFit; +import cadcore.BezierKnot; +import cadcore.BezierSpline; +import cadcore.VecMath; + +public class BrdDeleteControlPointCommand extends BrdAbstractEditCommand +{ + BezierKnot mDeletedControlPoint; + BezierSpline mControlPoints; + int mIndex; + + public BrdDeleteControlPointCommand(BoardEdit source, BezierKnot ControlPoint, BezierSpline ControlPoints) + { + mSource = source; + + mDeletedControlPoint = ControlPoint; + + mControlPoints = ControlPoints; + } + + public void doAction() + { + super.saveBeforeChange(mSource.getCurrentBrd()); + + mIndex = mControlPoints.indexOf(mDeletedControlPoint); + + ArrayList points = new ArrayList(); + + int steps = 10; + + BezierCurve prevCurve = mControlPoints.getCurve(mIndex-1); + for(int i = 0; i <= steps; i++) + { + double t = (double)i/(double)steps; + points.add(new Point2D.Double(prevCurve.getXValue(t),prevCurve.getYValue(t)) ); + } + BezierCurve nextCurve = mControlPoints.getCurve(mIndex); + for(int i = 0; i < steps; i++) + { + double t = (double)i/(double)steps; + points.add(new Point2D.Double(nextCurve.getXValue(t),nextCurve.getYValue(t)) ); + } + + BezierKnot prev = mControlPoints.getControlPoint(mIndex-1); + BezierKnot next = mControlPoints.getControlPoint(mIndex+1); + + mSource.mSelectedControlPoints.remove(mDeletedControlPoint); + + super.removePoint(mDeletedControlPoint); + + mControlPoints.remove(mDeletedControlPoint); + + //Pass to bezierFit + BezierFit fitter = new BezierFit(); + Point2D[] ctrlPoints = fitter.bestFit(points); + + //Update bezier curve + prev.setContinous(false); + prev.setEndPoint(ctrlPoints[0].getX(),ctrlPoints[0].getY()); + prev.setTangentToNext(ctrlPoints[1].getX(),ctrlPoints[1].getY()); + next.setTangentToPrev(ctrlPoints[2].getX(),ctrlPoints[2].getY()); + next.setEndPoint(ctrlPoints[3].getX(),ctrlPoints[3].getY()); + next.setContinous(false); + + super.saveChanges(); + } + + public void execute() + { + doAction(); + + mSource.onBrdChanged(); + + super.execute(); + } + + public void undo() + { + mControlPoints.insert(mIndex, mDeletedControlPoint); + + super.undo(); + } + + public void redo() + { + mControlPoints.remove(mDeletedControlPoint); + + super.redo(); + } + + public String getCommandString() + { + return LanguageResource.getString("DELETECONTROLPOINTCMD_STR"); + + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdEditCommand.java b/boardcad/commands/BrdEditCommand.java new file mode 100644 index 0000000..9a98d42 --- /dev/null +++ b/boardcad/commands/BrdEditCommand.java @@ -0,0 +1,849 @@ +package boardcad.commands; + +import java.awt.Point; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; +import java.awt.geom.Point2D; +import java.util.ArrayList; + +import boardcad.gui.jdk.BezierBoardDrawUtil; +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardEdit; +import boardcad.gui.jdk.BoardHandler; +import boardcad.i18n.LanguageResource; +import cadcore.BezierKnot; +import cadcore.BezierSpline; +import cadcore.MathUtils; +import cadcore.NurbsPoint; +import cadcore.VecMath; + +public class BrdEditCommand extends BrdAbstractEditCommand +{ + static double KEY_MOVE_AMOUNT = 1.0f; + +// ArrayList mSelectedControlPointsCopy; + ArrayList mControlPointsBeforeChange; +// ArrayList mControlPointsAfterChange; + Point2D.Double mDragStartPos; + Point2D.Double mDragOffset; + Point mBoxSelectStartPos; + private int mWhich = 0; + boolean mIsDragging = false; + boolean mIsKeyEditing = false; + boolean mIsBoxSelecting = false; + int mCurrentKeyCode = 0; + int mRepeat = 1; + + BrdPanCommand mPanCommand = new BrdPanCommand(); + BrdZoomCommand mZoomCommand = new BrdZoomCommand(); + NurbsEditCommand mNurbsCommand = new NurbsEditCommand(); + + boolean mIsPaning = false; + + final double MAX_OFF = 4.0f; + + private static int clicked_x; + private static int clicked_y; + private static int dragged_x; + private static int dragged_y; + protected static boolean is_marked=false; + + private NurbsPoint p; + + + public BrdEditCommand() + { + } + + public void execute() + { + /* mControlPointsAfterChange = new ArrayList(); + for(int i = 0; i < mSelectedControlPointsCopy.size(); i++) + { + mControlPointsAfterChange.add((ControlPoint)mSelectedControlPointsCopy.get(i).clone()); + } + */ + mSource.onBrdChanged(); //adjust rocker to zero and cross sections to width and thickness + super.execute(); + mIsDragging = false; + mIsKeyEditing = false; + mCurrentKeyCode = 0; +// mSelectedControlPointsCopy = null; + mControlPointsBeforeChange = null; +// mControlPointsAfterChange = null; + mDragStartPos = null; + mDragOffset = null; + mSource = null; + mRepeat = 1; + } + + public void onSetCurrent() + { + BoardCAD.getInstance().getControlPointInfo().setEnabled(true); + } + + public void onCurrentChanged() + { + BoardCAD.getInstance().getControlPointInfo().setEnabled(false); + } + + void saveControlPointsBeforeChange(BoardEdit source) + { + ArrayList selectedControlPoints = source.getSelectedControlPoints(); + +// Save the original points + mControlPointsBeforeChange = new ArrayList(); +// mSelectedControlPointsCopy = new ArrayList(); + for(int i = 0; i < selectedControlPoints.size(); i++) + { + mControlPointsBeforeChange.add((BezierKnot)selectedControlPoints.get(i).clone()); +// mSelectedControlPointsCopy.add(selectedControlPoints.get(i)); + } +// mControlPointsAfterChange = null; + super.saveBeforeChange(source.getCurrentBrd()); + } + + public void moveControlPoints(double x_diff, double y_diff, int which) + { + + ArrayList selectedControlPoints = mSource.getSelectedControlPoints(); + if(selectedControlPoints.size() > 1 || which == 0) + { + for(int i = 0; i < selectedControlPoints.size(); i++) + { + BezierKnot sel = selectedControlPoints.get(i); + BezierKnot org = mControlPointsBeforeChange.get(i); + + sel.setControlPointLocation(org.getEndPoint().x+x_diff, org.getEndPoint().y+y_diff); + + } + } + else{ +// We know we only have a single point, so just use it directly + selectedControlPoints.get(0).setLocation(getWhich(), mControlPointsBeforeChange.get(0).getPoints()[getWhich()].x+x_diff, mControlPointsBeforeChange.get(0).getPoints()[getWhich()].y+y_diff); + + if(selectedControlPoints.get(0).isContinous()) + { + + int other = (which ==1)?2:1; + +// Calculate the length of the other end vector + double ox = (double)mControlPointsBeforeChange.get(0).getPoints()[other].x - mControlPointsBeforeChange.get(0).getPoints()[0].x; + double oy = (double)mControlPointsBeforeChange.get(0).getPoints()[other].y - mControlPointsBeforeChange.get(0).getPoints()[0].y; + + double ol = Math.sqrt(ox*ox+oy*oy); + if(ol == 0) + return; //Avoid multiply by zero + +// Length of current + double sx = (double)selectedControlPoints.get(0).getPoints()[which].x - mControlPointsBeforeChange.get(0).getPoints()[0].x; + double sy = (double)selectedControlPoints.get(0).getPoints()[which].y - mControlPointsBeforeChange.get(0).getPoints()[0].y; + + double sl = Math.sqrt(sx*sx+sy*sy); + if(sl == 0) + return; //Avoid division by zero + +// Normalize + sx /= sl; + sy /= sl; + + selectedControlPoints.get(0).setLocation(other, (double)(-sx*ol) + selectedControlPoints.get(0).getPoints()[0].x, + (double)(-sy*ol) + selectedControlPoints.get(0).getPoints()[0].y); + } + + /*Debug + System.out.println("Tangent to Prev angle: " + mSelectedControlPointsCopy.get(0).getTangentToPrevAngle() + " Tangent to Next angle: " + mSelectedControlPointsCopy.get(0).getTangentToNextAngle()); + double a = mSelectedControlPointsCopy.get(0).getTangentToPrevAngle(); + a = Math.abs(Math.PI - a); + double b = mSelectedControlPointsCopy.get(0).getTangentToNextAngle(); + boolean cont = (Math.abs(a-b) < 0.02)?true:false; + System.out.println("a: " + a + " b: " + b + " cont:" + cont); + */ + } + BoardCAD.getInstance().onBrdChanged(); + BoardCAD.getInstance().onControlPointChanged(); + mSource.repaint(); + } + + public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) + { + + //marking nurbs points + + clicked_x=event.getX(); + clicked_y=event.getY(); + + BoardHandler board_handler=BoardCAD.getInstance().getBoardHandler(); + + if(source.mDrawControl == 0) + { + clicked_x=event.getX(); + clicked_y=event.getY(); + board_handler.set_x((clicked_x-source.mOffsetX)/(source.mScale/10)); + board_handler.set_z((clicked_y-source.mOffsetY)/(source.mScale/10)); + is_marked=board_handler.outline_mark(source.mScale/10, source.mRotationMatrix); + if(is_marked) + { + p=new NurbsPoint(board_handler.get_x(), board_handler.get_y(), board_handler.get_z()); + } + } + else if(source.mDrawControl == BezierBoardDrawUtil.MirrorY) + { + board_handler.set_x((clicked_x-source.mOffsetX)/(source.mScale/10)); + board_handler.set_z((clicked_y-source.mOffsetY)/(source.mScale/10)); + is_marked=board_handler.outline_mark(source.mScale/10); + } + else if(source.mDrawControl == BezierBoardDrawUtil.FlipY) + { + board_handler.set_x((clicked_x-source.mOffsetX)/(source.mScale/10)); + board_handler.set_y((-clicked_y+source.mOffsetY)/(source.mScale/10)); + is_marked=board_handler.rocker_mark(source.mScale/10); + } + else if(source.mDrawControl == (BezierBoardDrawUtil.MirrorX | BezierBoardDrawUtil.FlipY)) + { + board_handler.set_z((clicked_x-source.mOffsetX)/(source.mScale/10)); + board_handler.set_y((-clicked_y+source.mOffsetY)/(source.mScale/10)); + is_marked=board_handler.edge_mark(source.mScale/10); + } + + if(is_marked) + { + BoardCAD.getInstance().status_panel.set_point_name(board_handler.get_point_name()); + BoardCAD.getInstance().status_panel.set_coordinates(board_handler.get_x(), board_handler.get_y(), board_handler.get_z()); + mNurbsCommand = new NurbsEditCommand(); + } + + + //marking bezier point + + Point pos = event.getPoint(); + Point2D.Double brdPos = source.screenCoordinateToBrdCoordinate(pos); + + BezierSpline[] splines = source.getActiveBezierSplines(BoardCAD.getInstance().getCurrentBrd()); + if(splines == null) + return; + + BezierKnot bestMatch = null; + boolean hitControlPoint = false; + for(int i = 0; i < splines.length; i++) + { + bestMatch = splines[i].findBestMatch(brdPos); + if(bestMatch != null) + { + setWhich(splines[0].getBestMatchWhich(brdPos)); + hitControlPoint = (double)brdPos.distance(bestMatch.getPoints()[getWhich()]) < (MAX_OFF/source.getScale()); + if(hitControlPoint) + break; + } + } + + if(bestMatch == null) + { + mSource = source; + mIsBoxSelecting = true; + mBoxSelectStartPos = pos; + return; + } + + if(!hitControlPoint) + { + mSource = source; + mIsBoxSelecting = true; + mBoxSelectStartPos = pos; + + if(!(event.isShiftDown() || event.isControlDown())) + { + source.clearSelectedControlPoints(); //If shift is held, don't clear + } + + } + else + { + boolean alreadySelected = source.mSelectedControlPoints.contains(bestMatch); + + if(!alreadySelected && (!(event.isShiftDown() || event.isControlDown())) ) + source.clearSelectedControlPoints(); //If shift or control is held or the ControlPoint is already selected, don't clear + + if(event.isControlDown()) + source.toggleSelectedControlPoint(bestMatch); + else + source.addSelectedControlPoint(bestMatch); + } + + if(hitControlPoint && source.mSelectedControlPoints.contains(bestMatch)) + { + mDragStartPos = source.screenCoordinateToBrdCoordinate(pos); + + mDragOffset = new Point2D.Double(bestMatch.getPoints()[getWhich()].x-mDragStartPos.x,bestMatch.getPoints()[getWhich()].y-mDragStartPos.y); + + } + + BoardCAD.getInstance().onControlPointChanged(); +// source.repaint(); + BoardCAD.getInstance().redraw(); + + } + + + public void onMouseDragged(BoardEdit source, MouseEvent event) + { + + + //dragging nurbs points + +// clicked_x=event.getX(); +// clicked_y=event.getY(); + + BoardHandler board_handler=BoardCAD.getInstance().getBoardHandler(); + + if(is_marked) + { + if(source.mDrawControl == 0) + { + + double[][] m=MathUtils.invert(source.mRotationMatrix); + double myy=(source.mRotationMatrix[1][0]*p.x+source.mRotationMatrix[1][1]*p.y+source.mRotationMatrix[1][2]*p.z); + + board_handler.set_x( m[0][0]*(event.getX()-source.mOffsetX)/(source.mScale/10) + m[0][1]*myy + m[0][2]*(event.getY()-source.mOffsetY)/(source.mScale/10) );// + m[0][2]*100); + board_handler.set_y( m[1][0]*(event.getX()-source.mOffsetX)/(source.mScale/10) + m[1][1]*myy + m[1][2]*(event.getY()-source.mOffsetY)/(source.mScale/10) );// + m[1][2]*100); + board_handler.set_z( m[2][0]*(event.getX()-source.mOffsetX)/(source.mScale/10) + m[2][1]*myy + m[2][2]*(event.getY()-source.mOffsetY)/(source.mScale/10) );// + m[2][2]*100); + + board_handler.set_point(source.mRotationMatrix); + } + else if(source.mDrawControl == BezierBoardDrawUtil.MirrorY) + { + if(!BoardCAD.getInstance().mIsLockedX.getState()) + board_handler.set_x((event.getX()-source.mOffsetX)/(source.mScale/10)); + if(!BoardCAD.getInstance().mIsLockedZ.getState()) + board_handler.set_z((event.getY()-source.mOffsetY)/(source.mScale/10)); + board_handler.set_point(); + } + else if(source.mDrawControl == BezierBoardDrawUtil.FlipY) + { + + if(!BoardCAD.getInstance().mIsLockedX.getState()) + board_handler.set_x((event.getX()-source.mOffsetX)/(source.mScale/10)); + if(!BoardCAD.getInstance().mIsLockedY.getState()) + board_handler.set_y((source.mOffsetY-event.getY())/(source.mScale/10)); + board_handler.set_point(); + } + else if(source.mDrawControl == (BezierBoardDrawUtil.MirrorX | BezierBoardDrawUtil.FlipY)) + { + if(!BoardCAD.getInstance().mIsLockedY.getState()) + board_handler.set_y((-event.getY()+source.mOffsetY)/(source.mScale/10)); + if(!BoardCAD.getInstance().mIsLockedZ.getState()) + board_handler.set_z((event.getX()-source.mOffsetX)/(source.mScale/10)); + board_handler.set_point(); + } + + BoardCAD.getInstance().redraw(); + } + + + //dragging bezier points + + + if(mIsKeyEditing) + return; + + if(mIsPaning) + { + mPanCommand.onMouseDragged(source, event); + return; + } + + if(mIsBoxSelecting) + { + mSource.setDrawZoomRectangle(mBoxSelectStartPos, event.getPoint()); + + return; + } + + ArrayList selectedControlPoints = source.getSelectedControlPoints(); + if(selectedControlPoints.size() == 0) + return; + + Point pos = event.getPoint(); + Point2D.Double brdPos = source.screenCoordinateToBrdCoordinate(pos); + + if(mIsDragging == false) + { + /* BezierPatch ControlPoints = source.getBezierControlPoints(BoardCAD.getInstance().getCurrentBrd()); + ControlPoint bestMatch = ControlPoints.findBestMatch(brdPos); + mWhich = ControlPoints.getBestMatchWhich(); + + double distance = (double)brdPos.distance(bestMatch.mPoints[mWhich]); + + if(distance > (MAX_OFF/source.getScale()) || bestMatch == null) + return; //trying to drag an unselected point + + if(!selectedControlPoints.contains(bestMatch)) + return; //trying to drag an unselected point + + mDragStartPos = source.screenCoordinateToBrdCoordinate(pos); + + mDragOffset = new Point2D.Double(bestMatch.mPoints[mWhich].x-mDragStartPos.x,bestMatch.mPoints[mWhich].y-mDragStartPos.y); + */ + saveControlPointsBeforeChange(source); + + mIsDragging = true; + mSource = source; + } + + brdPos.x += mDragOffset.x; + brdPos.y += mDragOffset.y; + + double x_diff = (brdPos.x - mDragStartPos.x)*(event.isAltDown()?.1f:1f); + double y_diff = (brdPos.y - mDragStartPos.y)*(event.isAltDown()?.1f:1f); + + moveControlPoints(x_diff, y_diff, getWhich()); + + + } + + public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) + { + if(is_marked) + { + mNurbsCommand.execute(); + is_marked=false; + } + + if(mIsBoxSelecting) + { + mSource.disableDrawZoomRectangle(); + + Point pos = event.getPoint(); + Point2D.Double boxStartPos = source.screenCoordinateToBrdCoordinate(mBoxSelectStartPos); + Point2D.Double boxEndPos = source.screenCoordinateToBrdCoordinate(pos); + + if(boxStartPos.x > boxEndPos.x) + { + double x = boxStartPos.x; + boxStartPos.x = boxEndPos.x; + boxEndPos.x = x; + } + + if(boxStartPos.y > boxEndPos.y) + { + double y = boxStartPos.y; + boxStartPos.y = boxEndPos.y; + boxEndPos.y = y; + } + + BezierSpline[] splines = source.getActiveBezierSplines(BoardCAD.getInstance().getCurrentBrd()); + if(splines == null) + return; + + + for(int k = 0; k < splines.length; k++) + { + for(int i = 0; i < splines[k].getNrOfControlPoints(); i++) + { + BezierKnot point = splines[k].getControlPoint(i); + for(int j = 0; j < 3; j++) + { + Point2D.Double p = point.getPoints()[j]; + + if(p.x > boxStartPos.x && p.x < boxEndPos.x && p.y > boxStartPos.y && p.y < boxEndPos.y ) //Check within box + { + setWhich(j); + + if(event.isControlDown()) + source.toggleSelectedControlPoint(point); + else + source.addSelectedControlPoint(point); + + break; + } + } + } + } + + BoardCAD.getInstance().onControlPointChanged(); + source.repaint(); + mIsBoxSelecting = false; + } + + ArrayList selectedControlPoints = source.getSelectedControlPoints(); + if(selectedControlPoints.size() == 0) + return; + + if(mIsDragging == true) + { + execute(); + } + } + + public void onMouseWheelMoved(BoardEdit source, MouseWheelEvent event) + { + int scroll = event.getWheelRotation(); + + int steps = Math.abs(scroll); + for(int i = 0; i < steps; i++) + { + if(scroll < 0) + { + mZoomCommand.zoomInStep(source, event.isAltDown()); + } + else + { + mZoomCommand.zoomOutStep(source, event.isAltDown()); + } + + } + event.consume(); + } + + public void onMouseWheelButtonPressed(BoardEdit source, MouseEvent event) + { + mPanCommand.onLeftMouseButtonPressed(source, event); + mIsPaning = true; + } + + public void onMouseWheelButtonReleased(BoardEdit source, MouseEvent event) + { + mPanCommand.onLeftMouseButtonReleased(source, event); + mIsPaning = false; + } + + public boolean onKeyEvent(BoardEdit source, KeyEvent event) + { + if(mIsDragging) + return false; + + ArrayList selectedControlPoints = source.getSelectedControlPoints(); + if(selectedControlPoints.size() == 0) + { + return mPanCommand.onKeyEvent(source, event); + } + + double mulX = ((source.mDrawControl&(BezierBoardDrawUtil.FlipX)) != 0)?-1.0f:1.0f; + double mulY = ((source.mDrawControl&(BezierBoardDrawUtil.FlipY)) != 0)?-1.0f:1.0f; + + if(event.getID() == KeyEvent.KEY_PRESSED) + { + int key = event.getKeyCode(); + + double x_diff = 0; + double y_diff = 0; + double movement = (KEY_MOVE_AMOUNT/source.getScale())*(event.isAltDown()?.1f:1f); + +// Length of current + double sx; + double sy; + if(mControlPointsBeforeChange == null || mControlPointsBeforeChange.size() == 0) + { + sx = (double)selectedControlPoints.get(0).getPoints()[getWhich()].x - selectedControlPoints.get(0).getPoints()[0].x; + sy = (double)selectedControlPoints.get(0).getPoints()[getWhich()].y - selectedControlPoints.get(0).getPoints()[0].y; + } + else + { + sx = (double)mControlPointsBeforeChange.get(0).getPoints()[getWhich()].x - mControlPointsBeforeChange.get(0).getPoints()[0].x; + sy = (double)mControlPointsBeforeChange.get(0).getPoints()[getWhich()].y - mControlPointsBeforeChange.get(0).getPoints()[0].y; + } + + double sl = Math.sqrt(sx*sx+sy*sy); + +// Normalize + double snx = sx/sl; + double sny = sy/sl; + + switch(key) + { + case KeyEvent.VK_LESS: + if(selectedControlPoints.size() > 1 || mIsKeyEditing == true) + return false; + + setWhich(getWhich() - 1); + if(getWhich() < 0) + setWhich(2); + + source.repaint(); + break; + + case KeyEvent.VK_C: + if(selectedControlPoints.size() > 1 || mIsKeyEditing == true) + return false; + + BezierSpline[] splines = source.getActiveBezierSplines(BoardCAD.getInstance().getCurrentBrd()); + if(splines == null) + return false; + + for(int i = 0; i < splines.length; i++) + { + int currentIndex = splines[i].indexOf(selectedControlPoints.get(0)); + if(currentIndex == -1) + continue; + + int newIndex = ++currentIndex%splines[i].getNrOfControlPoints(); + + selectedControlPoints.clear(); + + selectedControlPoints.add(splines[i].getControlPoint(newIndex)); + + source.repaint(); + } + break; + + case KeyEvent.VK_LEFT: + x_diff = -movement*mulX*mRepeat; + break; + + case KeyEvent.VK_RIGHT: + x_diff = movement*mulX*mRepeat; + break; + + case KeyEvent.VK_UP: + y_diff = -movement*mulY*mRepeat; + break; + + case KeyEvent.VK_DOWN: + y_diff = movement*mulY*mRepeat; + break; + + case KeyEvent.VK_E: + case KeyEvent.VK_R: + if(getWhich() == 0 || selectedControlPoints.size() > 1) + return false; + + x_diff = (double)(snx*movement*((key==KeyEvent.VK_R)?-1.0f:1.0f))*mRepeat; + y_diff = (double)(sny*movement*((key==KeyEvent.VK_R)?-1.0f:1.0f))*mRepeat; + break; + + case KeyEvent.VK_Q: + case KeyEvent.VK_W: + if(getWhich() == 0 || selectedControlPoints.size() > 1) + return false; + + double angle = (((double)Math.PI/180.0f)*mRepeat)*((key==KeyEvent.VK_Q)?-1.0f:1.0f)*(event.isAltDown()?.1f:1f); + x_diff = (double)((Math.cos(angle)*sx - Math.sin(angle)*sy) - sx); + y_diff = (double)((Math.sin(angle)*sx + Math.cos(angle)*sy) - sy); + break; + + default: + return false; + } + + if(mIsKeyEditing == false) + { + saveControlPointsBeforeChange(source); + + mIsKeyEditing = true; + mCurrentKeyCode = key; + + mRepeat = 1; + + mSource = source; + } + + mRepeat++; + + moveControlPoints(x_diff, y_diff, getWhich()); + + BoardCAD.getInstance().onControlPointChanged(); + source.repaint(); + return true; + } + else if(event.getID() == KeyEvent.KEY_RELEASED) + { + if(mIsKeyEditing == true) + { + if(mCurrentKeyCode == event.getKeyCode()) + { + execute(); + } + + } + + } + return false; + } + + public void setContinous(BoardEdit source, boolean continous) + { + if(source.getSelectedControlPoints().size() == 0) + return; + + mSource = source; + + saveControlPointsBeforeChange(mSource); + + mSource.getSelectedControlPoints().get(0).setContinous(continous); + + moveControlPoints(0, 0, (getWhich() == 0)?1:getWhich()); //If endpoint selected, select tangent + + execute(); + + } + + public void setControlPoint(BoardEdit source, Point2D.Double pos) + { + mSource = source; + + saveControlPointsBeforeChange(mSource); + + double dx = pos.x - mControlPointsBeforeChange.get(0).getPoints()[getWhich()].x; + double dy = pos.y - mControlPointsBeforeChange.get(0).getPoints()[getWhich()].y; + + moveControlPoints(dx, dy, getWhich()); + + execute(); + + } + + public void rotateControlPoint(BoardEdit source, double targetAngle) + { + mSource = source; + + saveControlPointsBeforeChange(mSource); + + ArrayList selectedControlPoints = source.getSelectedControlPoints(); + if(getWhich() == 0 || selectedControlPoints.size() > 1) + return; + + double sx = (double)selectedControlPoints.get(0).getPoints()[getWhich()].x - selectedControlPoints.get(0).getPoints()[0].x; + double sy = (double)selectedControlPoints.get(0).getPoints()[getWhich()].y - selectedControlPoints.get(0).getPoints()[0].y; + + Point2D.Double horAxis = new Point2D.Double(1.0,0.0); + Point2D.Double pointVec = new Point2D.Double(sx,sy); + + double pointAngle = VecMath.getVecAngle(horAxis, pointVec); + + double rotAngle = targetAngle - pointAngle; + + double x_diff = (double)((Math.cos(rotAngle)*sx - Math.sin(rotAngle)*sy) - sx); + double y_diff = (double)((Math.sin(rotAngle)*sx + Math.cos(rotAngle)*sy) - sy); + + moveControlPoints(x_diff, y_diff, getWhich()); + + BoardCAD.getInstance().onControlPointChanged(); + execute(); + } + + public void rotateControlPointToHorizontal(BoardEdit source) + { + ArrayList selectedControlPoints = source.getSelectedControlPoints(); + if(selectedControlPoints.size() != 1) + return; + + mSource = source; + + saveControlPointsBeforeChange(mSource); + + BezierKnot current = selectedControlPoints.get(0); + + double nextLength = current.getTangentToNextLength(); + double prevLength = current.getTangentToPrevLength(); + double x = current.getEndPoint().x; + double y = current.getEndPoint().y; + + double tanPrevSign = (current.getTangentToPrev().x-x>0)?1:-1; + double tanNextSign = (current.getTangentToNext().x-x>=0)?1:-1; + + if(getWhich() == 0 || getWhich() == 1) + { + current.setTangentToPrev((prevLength*tanPrevSign)+x, y); + if(current.isContinous()) + { + current.setTangentToNext((-nextLength*tanPrevSign)+x, y); + } + } + else if(getWhich() == 2 || current.isContinous()) + { + current.setTangentToNext((nextLength*tanNextSign)+x, y); + if(current.isContinous()) + { + current.setTangentToPrev((-prevLength*tanNextSign)+x, y); + } + } + + BoardCAD.getInstance().onControlPointChanged(); + execute(); + } + + public void rotateControlPointToVertical(BoardEdit source) + { + ArrayList selectedControlPoints = source.getSelectedControlPoints(); + if(selectedControlPoints.size() != 1) + return; + + mSource = source; + + saveControlPointsBeforeChange(mSource); + + BezierKnot current = selectedControlPoints.get(0); + + double nextLength = current.getTangentToNextLength(); + double prevLength = current.getTangentToPrevLength(); + double x = current.getEndPoint().x; + double y = current.getEndPoint().y; + + double tanPrevSign = (current.getTangentToPrev().y-y>0)?1:-1; + double tanNextSign = (current.getTangentToNext().y-y>=0)?1:-1; + + if(getWhich() == 0 || getWhich() == 1) + { + current.setTangentToPrev(x, (prevLength*tanPrevSign)+y); + if(current.isContinous()) + { + current.setTangentToNext(x, (-nextLength*tanPrevSign)+y); + } + } + if(getWhich() == 0 || getWhich() == 2) + { + current.setTangentToNext(x, (nextLength*tanNextSign)+y); + if(current.isContinous()) + { + current.setTangentToPrev(x, (-prevLength*tanNextSign)+y); + + } + } + + BoardCAD.getInstance().onControlPointChanged(); + execute(); + } + + public void redo() + { + /* for(int i = 0; i < mSelectedControlPointsCopy.size(); i++) + { + mSelectedControlPointsCopy.get(i).set(mControlPointsAfterChange.get(i)); + } + */ super.redo(); + } + + public void undo() + { + /* for(int i = 0; i < mSelectedControlPointsCopy.size(); i++) + { + mSelectedControlPointsCopy.get(i).set(mControlPointsBeforeChange.get(i)); + } + */ super.undo(); + } + + public Object clone(){ + BrdEditCommand cmd = null; + + cmd = (BrdEditCommand)super.clone(); + +// The arrays are instantiated in this class so there is no need to copy them + + return cmd; + } + + public String getCommandString() + { + return LanguageResource.getString("EDITCMD_STR"); + } + + public int getWhich() { + return mWhich; + } + + public void setWhich(int mWhich) { + this.mWhich = mWhich; + } + +} \ No newline at end of file diff --git a/boardcad/commands/BrdFitCurveCommand.java b/boardcad/commands/BrdFitCurveCommand.java new file mode 100644 index 0000000..5d6f333 --- /dev/null +++ b/boardcad/commands/BrdFitCurveCommand.java @@ -0,0 +1,112 @@ +package boardcad.commands; + +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +import board.BezierBoard; +import boardcad.gui.jdk.BoardCAD; +import boardcad.i18n.LanguageResource; +import cadcore.BezierCurve; +import cadcore.BezierFit; +import cadcore.BezierSpline; + +public class BrdFitCurveCommand extends BrdAbstractEditCommand { + + public BrdFitCurveCommand() { + + } + + public void execute() { + mPreviousCommand = BoardCAD.getInstance().getCurrentCommand(); + + fitCurve(); + + super.execute(); + } + + public void fitCurve() { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + saveBeforeChange(brd); + + boolean isCrossSection = BoardCAD.getInstance().getSelectedEdit().mIsCrossSectionEdit; + + ArrayList gpArray = BoardCAD.getInstance() + .getSelectedEdit().getGuidePoints(); + BezierSpline[] bs = BoardCAD.getInstance().getSelectedEdit() + .getActiveBezierSplines(brd); + + for (int i = 0; i < bs.length; i++) { + for (int k = 0; k < bs[i].getNrOfCurves(); k++) { + BezierCurve curve = bs[i].getCurve(k); + + double xmin = 0.0; + double xmax = 0.0; + double ymin = -10000000.0; + double ymax = 10000000.0; + if(isCrossSection) + { + xmin = curve.getMinX(); + xmax = curve.getMaxX(); + ymin = curve.getMinY(); + ymax = curve.getMaxY(); + } + else + { + xmin = curve.getStartKnot().getEndPoint().getX(); + xmax = curve.getEndKnot().getEndPoint().getX(); + } + + ArrayList currentGuidePoints = new ArrayList(); + + for (int l = 0; l < gpArray.size(); l++) { + Point2D.Double p = gpArray.get(l); + + if (p.x >= xmin && p.x <= xmax && p.y >= ymin + && p.y <= ymax) { + currentGuidePoints.add(p); + } + } + if (currentGuidePoints.isEmpty()) // No points + continue; + + currentGuidePoints.add(0, curve.getStartKnot().getEndPoint()); + currentGuidePoints.add(0, curve.getStartKnot().getEndPoint()); + currentGuidePoints.add(curve.getEndKnot().getEndPoint()); + currentGuidePoints.add(curve.getEndKnot().getEndPoint()); + + Collections.sort(currentGuidePoints, new Comparator() { + public int compare(Point2D p1, Point2D p2) { + return (p1.getX() > p2.getX()) ? 1 : -1; + } + }); + + // Pass to bezierFit + BezierFit fitter = new BezierFit(); + Point2D[] ctrlPoints = fitter.bestFit(currentGuidePoints); + + // Update bezier curve + curve.getStartKnot().setEndPoint(ctrlPoints[0].getX(), + ctrlPoints[0].getY()); + curve.getStartKnot().setTangentToNext(ctrlPoints[1].getX(), + ctrlPoints[1].getY()); + curve.getStartKnot().setContinous(false); + curve.getEndKnot().setTangentToPrev(ctrlPoints[2].getX(), + ctrlPoints[2].getY()); + curve.getEndKnot().setEndPoint(ctrlPoints[3].getX(), + ctrlPoints[3].getY()); + curve.getEndKnot().setContinous(false); + + } + } + + saveChanges(); + } + + @Override + public String getCommandString() { + return LanguageResource.getString("FITCURVECMD_STR"); + } + +} diff --git a/boardcad/commands/BrdImportCrossSectionCommand.java b/boardcad/commands/BrdImportCrossSectionCommand.java new file mode 100644 index 0000000..be8bf2a --- /dev/null +++ b/boardcad/commands/BrdImportCrossSectionCommand.java @@ -0,0 +1,107 @@ +package boardcad.commands; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; + +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; + +import board.BezierBoard; +import board.readers.BrdReader; +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; +import cadcore.BezierBoardCrossSection; +import cadcore.BezierSpline; + +public class BrdImportCrossSectionCommand extends BrdCommand +{ + BezierBoardCrossSection mCrossSection = null; + BezierSpline mOldCrossSectionBezier = null; + BezierSpline mNewCrossSectionBezier = null; + + + public BrdImportCrossSectionCommand(BoardEdit source) + { + mSource = source; + + } + + public void execute() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + + mCrossSection = brd.getCurrentCrossSection(); + + mOldCrossSectionBezier = mCrossSection.getBezierSpline(); + + double pos = mCrossSection.getPosition(); + + final JFileChooser fc = new JFileChooser(); + + fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); + + int returnVal = fc.showOpenDialog(BoardCAD.getInstance().getFrame()); + if (returnVal != JFileChooser.APPROVE_OPTION) + return; + + File file = fc.getSelectedFile(); + + String filename = file.getPath(); // Load and display selection + if(filename == null) + return; + + try + { + if(BrdReader.importCrossection(brd, new BufferedReader(new FileReader(filename))) < 0) + { + throw new FileNotFoundException(); + } + } + catch(Exception e) + { + String str = e.toString(); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("IMPORTCROSSECTIONFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); + + return; + } + + + mNewCrossSectionBezier = (BezierSpline)brd.getCurrentCrossSection().clone(); + + mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); + + super.execute(); + } + + public void undo() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + double pos = mCrossSection.getPosition(); + + mCrossSection.setBezierSpline(mOldCrossSectionBezier); + + mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); + + super.undo(); + } + + public void redo() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + double pos = mCrossSection.getPosition(); + + mCrossSection.setBezierSpline(mNewCrossSectionBezier); + + mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); + + super.redo(); + } + + public String getCommandString() + { + return LanguageResource.getString("IMPORTCROSSECTIONCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdImportOutlineCommand.java b/boardcad/commands/BrdImportOutlineCommand.java new file mode 100644 index 0000000..ebd2db6 --- /dev/null +++ b/boardcad/commands/BrdImportOutlineCommand.java @@ -0,0 +1,92 @@ +package boardcad.commands; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; + +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; + +import board.BezierBoard; +import board.readers.BrdReader; +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; +import cadcore.BezierSpline; + +public class BrdImportOutlineCommand extends BrdCommand +{ + BezierSpline mOldOutline = null; + BezierSpline mNewOutline = null; + + + public BrdImportOutlineCommand(BoardEdit source) + { + mSource = source; + } + + public void execute() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + + final JFileChooser fc = new JFileChooser(); + + fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); + + int returnVal = fc.showOpenDialog(BoardCAD.getInstance().getFrame()); + if (returnVal != JFileChooser.APPROVE_OPTION) + return; + + File file = fc.getSelectedFile(); + + String filename = file.getPath(); // Load and display selection + if(filename == null) + return; + + mOldOutline = brd.getOutline(); + + mNewOutline = new BezierSpline(); + brd.setOutline(mNewOutline); + + try + { + if(BrdReader.importOutline(brd, new BufferedReader(new FileReader(filename))) < 0) + { + throw new FileNotFoundException(); + } + } + catch(Exception e) + { + String str = e.toString(); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("IMPORTOUTLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); + + return; + } + + super.execute(); + } + + public void undo() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + + brd.setOutline(mOldOutline); + + super.undo(); + } + + public void redo() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + + brd.setOutline(mNewOutline); + + super.redo(); + } + + public String getCommandString() + { + return LanguageResource.getString("PASTECROSSECTIONCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdImportProfileCommand.java b/boardcad/commands/BrdImportProfileCommand.java new file mode 100644 index 0000000..aa4b728 --- /dev/null +++ b/boardcad/commands/BrdImportProfileCommand.java @@ -0,0 +1,98 @@ +package boardcad.commands; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; + +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; + +import board.BezierBoard; +import board.readers.BrdReader; +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; +import cadcore.BezierSpline; + +public class BrdImportProfileCommand extends BrdCommand +{ + BezierSpline mOldDeck = null; + BezierSpline mOldBottom = null; + BezierSpline mNewDeck = null; + BezierSpline mNewBottom = null; + + public BrdImportProfileCommand(BoardEdit source) + { + mSource = source; + } + + public void execute() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + + final JFileChooser fc = new JFileChooser(); + + fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); + + int returnVal = fc.showOpenDialog(BoardCAD.getInstance().getFrame()); + if (returnVal != JFileChooser.APPROVE_OPTION) + return; + + File file = fc.getSelectedFile(); + + String filename = file.getPath(); // Load and display selection + if(filename == null) + return; + + mOldDeck = brd.getDeck(); + mOldBottom = brd.getBottom(); + + mNewDeck = new BezierSpline(); + brd.setDeck(mNewDeck); + mNewBottom = new BezierSpline(); + brd.setBottom(mNewBottom); + + try + { + if(BrdReader.importProfile(brd, new BufferedReader(new FileReader(filename))) < 0) + { + throw new FileNotFoundException(); + } + } + catch(Exception e) + { + String str = e.toString(); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("IMPORTPROFILEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); + + return; + } + + super.execute(); + } + + public void undo() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + + brd.setDeck(mOldDeck); + brd.setBottom(mOldBottom); + + super.undo(); + } + + public void redo() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + + brd.setDeck(mNewDeck); + brd.setBottom(mNewBottom); + + super.redo(); + } + + public String getCommandString() + { + return LanguageResource.getString("PASTECROSSECTIONCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdInputCommand.java b/boardcad/commands/BrdInputCommand.java new file mode 100644 index 0000000..c391a04 --- /dev/null +++ b/boardcad/commands/BrdInputCommand.java @@ -0,0 +1,52 @@ +package boardcad.commands; + +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; + +import boardcad.gui.jdk.BoardEdit; + +public abstract class BrdInputCommand extends BrdCommand +{ + public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) + { + } + + public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) + { + } + + public void onRightMouseButtonPressed(BoardEdit source, MouseEvent event) + { + } + + public void onRightMouseButtonReleased(BoardEdit source, MouseEvent event) + { + } + + public void onMouseWheelButtonPressed(BoardEdit source, MouseEvent event) + { + } + + public void onMouseWheelButtonReleased(BoardEdit source, MouseEvent event) + { + } + + public void onMouseMove(BoardEdit source, MouseEvent event) + { + } + + public void onMouseDragged(BoardEdit source, MouseEvent event) + { + } + + + public boolean onKeyEvent(BoardEdit source, KeyEvent event) + { + return false; + } + + public void onMouseWheelMoved(BoardEdit source, MouseWheelEvent e) + { + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdMacroCommand.java b/boardcad/commands/BrdMacroCommand.java new file mode 100644 index 0000000..1330028 --- /dev/null +++ b/boardcad/commands/BrdMacroCommand.java @@ -0,0 +1,57 @@ +package boardcad.commands; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.ListIterator; + +import boardcad.i18n.LanguageResource; + +public class BrdMacroCommand extends BrdCommand { + + LinkedList mBrdCommand; + + public BrdMacroCommand() + { + mBrdCommand = new LinkedList(); + } + + public void add(BrdCommand cmd) + { + mBrdCommand.add(cmd); + } + + public void execute() + { + for(Iterator i = mBrdCommand.iterator(); i.hasNext();) + { + ((BrdCommand)i.next()).doAction(); + } + super.execute(); + } + public void redo() + { + for(Iterator i = mBrdCommand.iterator(); i.hasNext();) + ((BrdCommand)i.next()).redo(); + + super.redo(); + } + + public void undo() + { +// Java 6 for(Iterator i = mBrdCommand.descendingIterator(); i.hasNext();) +// ((BrdCommand)i.next()).undo(); + + for(ListIterator i = mBrdCommand.listIterator(mBrdCommand.size()); i.hasPrevious();) + { + ((BrdCommand)i.previous()).undo(); + } + + super.undo(); + } + + public String getCommandString() + { + return LanguageResource.getString("MACROCMD_STR"); + } + +} \ No newline at end of file diff --git a/boardcad/commands/BrdMoveCrossSectionCommand.java b/boardcad/commands/BrdMoveCrossSectionCommand.java new file mode 100644 index 0000000..351ed6c --- /dev/null +++ b/boardcad/commands/BrdMoveCrossSectionCommand.java @@ -0,0 +1,55 @@ +package boardcad.commands; + +import board.BezierBoard; +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; +import cadcore.BezierBoardCrossSection; + +public class BrdMoveCrossSectionCommand extends BrdCommand +{ + BezierBoardCrossSection mMovedCrossSection = null; + double mOldPos; + double mNewPos; + + + public BrdMoveCrossSectionCommand(BoardEdit source, BezierBoardCrossSection crossSection, double newPos) + { + mSource = source; + mMovedCrossSection = crossSection; + mNewPos = newPos; + } + + public void execute() + { + BezierBoard brd = mSource.getCurrentBrd(); + mMovedCrossSection.setPosition(mNewPos); + brd.sortCrossSections(); + + super.execute(); + + } + + public void undo() + { + BezierBoard brd = mSource.getCurrentBrd(); + mMovedCrossSection.setPosition(mOldPos); + brd.sortCrossSections(); + + super.undo(); + + } + + public void redo() + { + BezierBoard brd = mSource.getCurrentBrd(); + mMovedCrossSection.setPosition(mNewPos); + brd.sortCrossSections(); + + super.redo(); + } + + public String getCommandString() + { + return LanguageResource.getString("MOVECROSSECTIONCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdPanCommand.java b/boardcad/commands/BrdPanCommand.java new file mode 100644 index 0000000..5644b4b --- /dev/null +++ b/boardcad/commands/BrdPanCommand.java @@ -0,0 +1,84 @@ +package boardcad.commands; + +import java.awt.Point; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; + +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; + +public class BrdPanCommand extends BrdInputCommand +{ + double mOriginalOffsetX; + double mOriginalOffsetY; + Point mPressedPos; + boolean mButtonPressed = true; + + public BrdPanCommand() + { + mCanUndo = false; + } + + public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) + { + Point pos = event.getPoint(); + mOriginalOffsetX = source.getOffsetX(); + mOriginalOffsetY = source.getOffsetY(); + mPressedPos = (Point)pos.clone(); + mButtonPressed = true; + } + + + public void onMouseDragged(BoardEdit source, MouseEvent event) + { + Point pos = event.getPoint(); + source.setOffsetX(mOriginalOffsetX + (pos.x - mPressedPos.x)); + source.setOffsetY(mOriginalOffsetY + (pos.y - mPressedPos.y)); + source.repaint(); + } + + public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) + { + mButtonPressed = false; + } + + public boolean onKeyEvent(BoardEdit source, KeyEvent event) + { + if(event.getID() != KeyEvent.KEY_PRESSED) + return false; + + int key = event.getKeyCode(); + + if(key == KeyEvent.VK_LEFT) + { + source.setOffsetX(source.getOffsetX()-(1.0f*source.getScale())); + source.repaint(); + return true; + } + else if(key == KeyEvent.VK_RIGHT) + { + source.setOffsetX(source.getOffsetX()+(1.0f*source.getScale())); + source.repaint(); + return true; + } + if(key == KeyEvent.VK_UP) + { + source.setOffsetY(source.getOffsetY()-(1.0f*source.getScale())); + source.repaint(); + return true; + } + else if(key == KeyEvent.VK_DOWN) + { + source.setOffsetY(source.getOffsetY()+(1.0f*source.getScale())); + source.repaint(); + return true; + } + return false; + } + + public String getCommandString() + { + return LanguageResource.getString("PANCMD_STR"); + } + +} \ No newline at end of file diff --git a/boardcad/commands/BrdPasteCrossSectionCommand.java b/boardcad/commands/BrdPasteCrossSectionCommand.java new file mode 100644 index 0000000..4292bb4 --- /dev/null +++ b/boardcad/commands/BrdPasteCrossSectionCommand.java @@ -0,0 +1,65 @@ +package boardcad.commands; + +import board.BezierBoard; +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; +import cadcore.BezierBoardCrossSection; +import cadcore.BezierSpline; + +public class BrdPasteCrossSectionCommand extends BrdCommand +{ + BezierBoardCrossSection mCrossSection = null; + BezierSpline mOldCrossSectionBezier = null; + BezierSpline mNewCrossSectionBezier = null; + + + public BrdPasteCrossSectionCommand(BoardEdit source, BezierBoardCrossSection currentCrossSection, BezierBoardCrossSection copyCrossSection) + { + mSource = source; + mCrossSection = currentCrossSection; + mOldCrossSectionBezier = currentCrossSection.getBezierSpline(); + mNewCrossSectionBezier = (BezierSpline)copyCrossSection.getBezierSpline().clone(); + } + + public void execute() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + double pos = mCrossSection.getPosition(); + + mCrossSection.setBezierSpline(mNewCrossSectionBezier); + + mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); + + super.execute(); + } + + public void undo() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + double pos = mCrossSection.getPosition(); + + mCrossSection.setBezierSpline(mOldCrossSectionBezier); + + mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); + + super.undo(); + } + + public void redo() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + double pos = mCrossSection.getPosition(); + + mCrossSection.setBezierSpline(mNewCrossSectionBezier); + + mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); + + super.redo(); + } + + public String getCommandString() + { + return LanguageResource.getString("PASTECROSSECTIONCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdPositionCommand.java b/boardcad/commands/BrdPositionCommand.java new file mode 100644 index 0000000..84a9ff9 --- /dev/null +++ b/boardcad/commands/BrdPositionCommand.java @@ -0,0 +1,199 @@ +package boardcad.commands; + +import java.awt.Point; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; + +import javax.vecmath.Vector3d; + +import boardcad.gui.jdk.BoardEdit; +import boardcad.gui.jdk.Machine2DView; + +public class BrdPositionCommand extends BrdInputCommand +{ + double mOriginalOffsetX; + double mOriginalOffsetY; + Point mPressedPos; + boolean mButtonPressed = true; + + BrdPanCommand mPanCommand = new BrdPanCommand(); + BrdZoomCommand mZoomCommand = new BrdZoomCommand(); + boolean mIsPaning = false; + + Machine2DView mView = null; + + public BrdPositionCommand(Machine2DView view) + { + mView = view; + mCanUndo = false; + } + + public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) + { + if(!mView.mShowDeck) + return; + + Point pos = event.getPoint(); + Vector3d deckOffset = mView.mConfig.getBlankHoldingSystem().getBoardDeckOffsetPos(); + mOriginalOffsetX = deckOffset.x; + mOriginalOffsetY = deckOffset.z; + mPressedPos = (Point)pos.clone(); + mButtonPressed = true; + } + + + public void onMouseDragged(BoardEdit source, MouseEvent event) + { + if(mIsPaning) + { + mPanCommand.onMouseDragged(source, event); + return; + } + + if(!mView.mShowDeck) + return; + + if(!mButtonPressed) + return; + + Point pos = event.getPoint(); + + double offsetX = mOriginalOffsetX + (((pos.x - mPressedPos.x))*(event.isAltDown()?0.1:1.0)/mView.mScale); + double offsetY = mOriginalOffsetY - (((pos.y - mPressedPos.y))*(event.isAltDown()?0.1:1.0)/mView.mScale); +// System.out.printf("offsetX: %f, offsetY: %f\n",offsetX, offsetY); + mView.mConfig.getBlankHoldingSystem().setBoardDeckOffsetPos(new Vector3d(offsetX, 0.0, offsetY)); + + //System.out.printf("onMouseDragged mView.mConfig:%s this:%s\n", mView.mConfig.toString(), this.toString()); + + source.repaint(); + } + + public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) + { + mButtonPressed = false; + } + + public void onMouseWheelMoved(BoardEdit source, MouseWheelEvent event) + { + int scroll = event.getWheelRotation(); + + int steps = scroll*((scroll>0)?1:-1); + for(int i = 0; i < steps; i++) + { + if(scroll < 0) + { + mZoomCommand.zoomInStep(source, event.isAltDown()); + } + else + { + mZoomCommand.zoomOutStep(source, event.isAltDown()); + } + + } + event.consume(); + } + + public void onMouseWheelButtonPressed(BoardEdit source, MouseEvent event) + { + mPanCommand.onLeftMouseButtonPressed(source, event); + mIsPaning = true; + } + + public void onMouseWheelButtonReleased(BoardEdit source, MouseEvent event) + { + mPanCommand.onLeftMouseButtonReleased(source, event); + mIsPaning = false; + } + + public boolean onKeyEvent(BoardEdit source, KeyEvent event) + { + + if(event.getID() != KeyEvent.KEY_PRESSED) + return false; + + int key = event.getKeyCode(); + +// System.out.printf("onKeyEvent mView.mConfig:%s this:%s\n", mView.mConfig.toString(), this.toString()); + + if(key == KeyEvent.VK_LEFT) + { + if(!mView.mShowDeck) + return false; + + Vector3d deckOffset = mView.mConfig.getBlankHoldingSystem().getBoardDeckOffsetPos(); + double offsetX = (deckOffset.x-((event.isAltDown()?0.1:1.0f)/source.getScale())); + mView.mConfig.getBlankHoldingSystem().setBoardDeckOffsetPos(new Vector3d(offsetX, 0.0, deckOffset.z)); + source.repaint(); + return true; + } + else if(key == KeyEvent.VK_RIGHT) + { + if(!mView.mShowDeck) + return false; + + Vector3d deckOffset = mView.mConfig.getBlankHoldingSystem().getBoardDeckOffsetPos(); + double offsetX = (deckOffset.x+((event.isAltDown()?0.1:1.0f)/source.getScale())); + mView.mConfig.getBlankHoldingSystem().setBoardDeckOffsetPos(new Vector3d(offsetX, 0.0, deckOffset.z)); + source.repaint(); + return true; + } + else if(key == KeyEvent.VK_UP) + { + if(!mView.mShowDeck) + return false; + + Vector3d deckOffset = mView.mConfig.getBlankHoldingSystem().getBoardDeckOffsetPos(); + double offsetY = (deckOffset.z+((event.isAltDown()?0.1:1.0f)/source.getScale())); + mView.mConfig.getBlankHoldingSystem().setBoardDeckOffsetPos(new Vector3d(deckOffset.x, 0.0, offsetY)); + source.repaint(); + return true; + } + else if(key == KeyEvent.VK_DOWN) + { + if(!mView.mShowDeck) + return false; + + Vector3d deckOffset = mView.mConfig.getBlankHoldingSystem().getBoardDeckOffsetPos(); + double offsetY = (deckOffset.z-((event.isAltDown()?0.1:1.0f)/source.getScale())); + mView.mConfig.getBlankHoldingSystem().setBoardDeckOffsetPos(new Vector3d(deckOffset.x, 0.0, offsetY)); + source.repaint(); + return true; + } + if(key == KeyEvent.VK_Q) + { + if(!mView.mShowDeck) + return false; + + double rot = mView.mConfig.getBlankHoldingSystem().getBoardDeckOffsetAngle(); + rot = rot-(event.isAltDown()?0.0004:0.004f); + mView.mConfig.getBlankHoldingSystem().setBoardDeckOffsetAngle(rot); + source.repaint(); + return true; + } + else if(key == KeyEvent.VK_W) + { + if(!mView.mShowDeck) + return false; + + double rot = mView.mConfig.getBlankHoldingSystem().getBoardDeckOffsetAngle(); + rot = rot+(event.isAltDown()?0.0004:0.004f); + mView.mConfig.getBlankHoldingSystem().setBoardDeckOffsetAngle(rot); + source.repaint(); + return true; + } + else if(key == KeyEvent.VK_SPACE) + { + mView.mShowDeck = !mView.mShowDeck; + source.repaint(); + return true; + } + return false; + } + + public String getCommandString() + { + return "Position"; + } + +} diff --git a/boardcad/commands/BrdRemoveCrossSectionCommand.java b/boardcad/commands/BrdRemoveCrossSectionCommand.java new file mode 100644 index 0000000..17bbbc3 --- /dev/null +++ b/boardcad/commands/BrdRemoveCrossSectionCommand.java @@ -0,0 +1,52 @@ +package boardcad.commands; + +import board.BezierBoard; +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; +import cadcore.BezierBoardCrossSection; + +public class BrdRemoveCrossSectionCommand extends BrdCommand +{ + BezierBoardCrossSection mRemovedCrossSection = null; + + + public BrdRemoveCrossSectionCommand(BoardEdit source, BezierBoardCrossSection crossSection) + { + mSource = source; + + mRemovedCrossSection = crossSection; + } + + public void execute() + { + BezierBoard brd = mSource.getCurrentBrd(); + + brd.removeCrossSection(mRemovedCrossSection); + + super.execute(); + } + + public void undo() + { + BezierBoard brd = mSource.getCurrentBrd(); + + brd.addCrossSection(mRemovedCrossSection); + + super.undo(); + + } + + public void redo() + { + BezierBoard brd = mSource.getCurrentBrd(); + + brd.removeCrossSection(mRemovedCrossSection); + + super.redo(); + } + + public String getCommandString() + { + return LanguageResource.getString("REMOVECROSSECTIONCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdRotateViewCommand.java b/boardcad/commands/BrdRotateViewCommand.java new file mode 100644 index 0000000..626203c --- /dev/null +++ b/boardcad/commands/BrdRotateViewCommand.java @@ -0,0 +1,79 @@ +package boardcad.commands; + +import java.awt.Point; +import java.awt.event.MouseEvent; + +import cadcore.MathUtils; +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardEdit; +import boardcad.gui.jdk.BoardHandler; +import boardcad.i18n.LanguageResource; + +public class BrdRotateViewCommand extends BrdInputCommand +{ + Point mClickedPos; + Point mZoomRectCorner; + double mNewScale; + boolean mButtonPressed = false; + private static int clicked_x; + private static int clicked_y; + private static int dragged_x; + private static int dragged_y; + + public BrdRotateViewCommand() + { + mCanUndo = false; + + mClickedPos = new Point(); + mZoomRectCorner = new Point(); + } + + public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) + { + clicked_x=event.getX(); + clicked_y=event.getY(); + + } + + public void onMouseDragged(BoardEdit source, MouseEvent event) + { + BoardHandler board_handler=BoardCAD.getInstance().getBoardHandler(); + + if(source.mDrawControl == 0) + { + dragged_x=event.getX(); + dragged_y=event.getY(); + double theta2=source.theta+dragged_x-clicked_x; + double[][] m1 = {{Math.cos(-theta2*Math.PI/180.0), 0.0, -Math.sin(-theta2*Math.PI/180.0)}, + {0.0, 1.0, 0.0}, + {Math.sin(-theta2*Math.PI/180.0), 0.0, Math.cos(-theta2*Math.PI/180.0)}}; + double zeta2=source.zeta+dragged_y-clicked_y; + double[][] m2 = {{1.0, 0.0, 0.0}, + {0.0, Math.cos(-zeta2*Math.PI/180.0), -Math.sin(-zeta2*Math.PI/180.0)}, + {0.0, Math.sin(-zeta2*Math.PI/180.0), Math.cos(-zeta2*Math.PI/180.0)}}; + source.mRotationMatrix=MathUtils.cross_product(m1,m2); + //design_panel.redraw(); + } + } + + public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) + { + + source.theta=source.theta+dragged_x-clicked_x; + source.zeta=source.zeta+dragged_y-clicked_y; + + source.repaint(); + + execute(); + } + + + + public String getCommandString() + { + return LanguageResource.getString("ROTATEVIEWCMD_STR"); + } + + + +} \ No newline at end of file diff --git a/boardcad/commands/BrdScaleCommand.java b/boardcad/commands/BrdScaleCommand.java new file mode 100644 index 0000000..a97ec20 --- /dev/null +++ b/boardcad/commands/BrdScaleCommand.java @@ -0,0 +1,197 @@ +package boardcad.commands; + +import javax.swing.JOptionPane; + +import board.BezierBoard; +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardEdit; +import boardcad.gui.jdk.ScaleBoardInputDialog; +import boardcad.i18n.LanguageResource; + +public class BrdScaleCommand extends BrdCommand +{ + double mOldWidth; + double mOldLength; + double mOldThickness; + double mNewWidth; + double mNewLength; + double mNewThickness; + //double[] mFinsOld; + boolean mScaleFins; + boolean mScaleFinsFactor; + boolean mScaleBottomRocker; + + public BrdScaleCommand(BoardEdit source) + { + mSource = source; + } + + public void execute() + { + + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + + ScaleBoardInputDialog dialog = new ScaleBoardInputDialog(BoardCAD.getInstance().getFrame()); + dialog.setModal(true); + //dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + dialog.setTitle(LanguageResource.getString("SCALEBOARDTITLE_STR")); + dialog.setBoardLength(brd.getLength()); + dialog.setBoardWidth(brd.getMaxWidth()); + dialog.setBoardThick(brd.getMaxThickness()); + + dialog.setVisible(true); + + if(dialog.wasCancelled()) + { + dialog.dispose(); + return; + } + + //mFinsOld=brd.mFins; + mOldLength= brd.getLength(); + mOldWidth = brd.getMaxWidth(); + mOldThickness = brd.getMaxThickness(); + + if(!dialog.scaleThroughFactor()) + { + mNewLength = dialog.getBoardLength(); + mNewWidth = dialog.getBoardWidth(); + mNewThickness = dialog.getBoardThick(); + + mScaleFins = dialog.scaleFins(); + + mScaleBottomRocker = dialog.scaleBottomRocker(); + + boolean overCurve = dialog.useOverCurve(); + + dialog.dispose(); + + if(mNewLength <= 0 || mNewWidth <= 0 || mNewThickness <= 0) + { + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), LanguageResource.getString("SCALEBOARDINVALIDINPUTERRORMSG_STR"), LanguageResource.getString("SCALEBOARDINVALIDINPUTERRORTITLE_STR"), JOptionPane.ERROR_MESSAGE); + return; + } + + if(!overCurve) + { + if(mScaleBottomRocker) + { + brd.scaleAccordingly(mNewLength,mNewWidth,mNewThickness); + } + else { + brd.scale(mNewLength,mNewWidth,mNewThickness); + } + if(mScaleFins) + { + brd.finScaling(mNewLength/mOldLength,mNewWidth/mOldWidth); + } + } + else + { + double newLengthOverCurve = mNewLength; + double guestimatedNewLength = 0; + for(int i = 0; i < 5; i++) + { + guestimatedNewLength = brd.getLength() * (newLengthOverCurve/brd.getLengthOverCurve()) + 0.01; //cheat by adding 0.1 mm + if(mScaleBottomRocker) + { + brd.scaleAccordingly(guestimatedNewLength, mNewWidth, mNewThickness); + } + else + { + brd.scale(guestimatedNewLength, mNewWidth, mNewThickness); + } + } + if(mScaleFins) + { + brd.finScaling(guestimatedNewLength/mOldLength,mNewWidth/mOldWidth); + } + + //Get the actual new length, used for redo + mNewLength = brd.getLength(); +//...why is the actual length different from the length the user asked for, particularly when "constraint proportions is on"?? + } + + super.execute(); + + BoardCAD.getInstance().onBrdChanged(); + BoardCAD.getInstance().fitAll(); + }else + { //scaleTroughFactor: + + mNewLength = brd.getLength() * dialog.getFactor(); + mNewWidth = brd.getMaxWidth() * dialog.getFactor(); + mNewThickness = brd.getMaxThickness() * dialog.getFactor(); + + mScaleFinsFactor = dialog.scaleFinsFactor(); + + mScaleBottomRocker = true; + + dialog.dispose(); + + if(mNewLength <= 0 || mNewWidth <= 0 || mNewThickness <= 0 || dialog.getFactor()<=0) + { + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), LanguageResource.getString("SCALEBOARDINVALIDINPUTERRORMSG_STR"), LanguageResource.getString("SCALEBOARDINVALIDINPUTERRORTITLE_STR"), JOptionPane.ERROR_MESSAGE); + return; + } + + brd.scale(mNewLength,mNewWidth,mNewThickness); + if(mScaleFinsFactor) + { + brd.finScaling(dialog.getFactor(),dialog.getFactor()); + } + + super.execute(); + + BoardCAD.getInstance().onBrdChanged(); + BoardCAD.getInstance().fitAll(); + } + } + + public void undo() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + if(mScaleBottomRocker) + { + brd.scaleAccordingly(mOldLength,mOldWidth,mOldThickness); + } + else + { + brd.scale(mOldLength,mOldWidth,mOldThickness); + } + if(mScaleFins || mScaleFinsFactor) + { + brd.finScaling(mOldLength/mNewLength,mOldWidth/mNewWidth); + } + + super.undo(); + + BoardCAD.getInstance().fitAll(); + } + + public void redo() + { + BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); + if(mScaleBottomRocker) + { + brd.scaleAccordingly(mNewLength, mNewWidth, mNewThickness); + } + else + { + brd.scale(mNewLength, mNewWidth, mNewThickness); + } + if(mScaleFins || mScaleFinsFactor) + { + brd.finScaling(mNewLength/mOldLength,mNewWidth/mOldWidth); + } + + super.redo(); + + BoardCAD.getInstance().fitAll(); + } + + public String getCommandString() + { + return LanguageResource.getString("SCALEBOARDCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/BrdSpotCheckCommand.java b/boardcad/commands/BrdSpotCheckCommand.java new file mode 100644 index 0000000..325e079 --- /dev/null +++ b/boardcad/commands/BrdSpotCheckCommand.java @@ -0,0 +1,42 @@ +package boardcad.commands; + +import boardcad.gui.jdk.BoardCAD; +import boardcad.i18n.LanguageResource; + +public class BrdSpotCheckCommand extends BrdCommand +{ + double mOldOffsetX; + double mOldOffsetY; + double mOldScale; + + + public BrdSpotCheckCommand() + { + } + + public void spotCheck() + { + mSource = BoardCAD.getInstance().getSelectedEdit(); + + mOldOffsetX = mSource.getOffsetX(); + mOldOffsetY = mSource.getOffsetY(); + mOldScale = mSource.getScale(); + + mSource.fitBrd(); + mSource.repaint(); + } + + public void restore() + { + mSource.setOffsetX(mOldOffsetX); + mSource.setOffsetY(mOldOffsetY); + mSource.setScale(mOldScale); + mSource.repaint(); + } + + public String getCommandString() + { + return LanguageResource.getString("SPOTCHECKCMD_STR"); + } + +} \ No newline at end of file diff --git a/boardcad/commands/BrdZoomCommand.java b/boardcad/commands/BrdZoomCommand.java new file mode 100644 index 0000000..bbf62a7 --- /dev/null +++ b/boardcad/commands/BrdZoomCommand.java @@ -0,0 +1,153 @@ +package boardcad.commands; + +import java.awt.Dimension; +import java.awt.Point; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; + +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; + +public class BrdZoomCommand extends BrdInputCommand +{ + Point mClickedPos; + Point mZoomRectCorner; + double mNewScale; + boolean mButtonPressed = false; + + public BrdZoomCommand() + { + mCanUndo = false; + + mClickedPos = new Point(); + mZoomRectCorner = new Point(); + } + + public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) + { + Point pos = event.getPoint(); + mClickedPos.setLocation(pos); + mButtonPressed = true; + mNewScale = source.getScale(); + } + + public void onMouseDragged(BoardEdit source, MouseEvent event) + { + Point pos = event.getPoint(); + + zoomSetDims(source, pos); + } + + public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) + { + source.setScale(source.getScale()/mNewScale); + + source.setOffsetX((source.getOffsetX()-mClickedPos.x)/mNewScale); + source.setOffsetY((source.getOffsetY()-mClickedPos.y)/mNewScale); + + source.disableDrawZoomRectangle(); + source.repaint(); + + BoardCAD.getInstance().mLifeSizeButton.getModel().setSelected(false); + + execute(); + } + + public void zoomSetDims(BoardEdit source, Point pos) + { + Dimension dim = source.getSize(); + + double scaleX = (double)Math.abs(pos.x - mClickedPos.x)/(double)dim.width; + double scaleY = (double)Math.abs(pos.y - mClickedPos.y)/(double)dim.height; + double usedScale = (scaleX > scaleY)?scaleX:scaleY; + + mZoomRectCorner.setLocation(mClickedPos.x+(dim.width*usedScale), mClickedPos.y+(dim.height*usedScale)); + + mNewScale = usedScale; + + source.setDrawZoomRectangle(mClickedPos, mZoomRectCorner); + source.repaint(); + } + + public void zoom(BoardEdit source) + { + source.setScale(source.getScale()/mNewScale); + + source.setOffsetX((source.getOffsetX()-mClickedPos.x)/mNewScale); + source.setOffsetY((source.getOffsetY()-mClickedPos.y)/mNewScale); + + source.disableDrawZoomRectangle(); + source.repaint(); + +// BoardCAD.getInstance().mLifeSizeButton.getModel().setSelected(false); + + execute(); + } + + public void zoomInStep(BoardEdit source, boolean fine) + { + Dimension dim = source.getSize(); + Dimension scaledDim = source.getSize(); + scaledDim.width *= (fine?0.99:0.9); + scaledDim.height *= (fine?0.99:0.9); + + Point pos = new Point(); + mClickedPos.x = (dim.width - scaledDim.width)/2; + mClickedPos.y = (dim.height - scaledDim.height)/2; + + pos.x = mClickedPos.x + scaledDim.width; + pos.y = mClickedPos.y + scaledDim.height; + + zoomSetDims(source, pos); + + zoom(source); + } + + public void zoomOutStep(BoardEdit source, boolean fine) + { + Dimension dim = source.getSize(); + Dimension scaledDim = source.getSize(); + scaledDim.width *= (fine?1.01:1.1); + scaledDim.height *= (fine?1.01:1.1); + + Point pos = new Point(); + mClickedPos.x = (dim.width - scaledDim.width)/2; + mClickedPos.y = (dim.height - scaledDim.height)/2; + + pos.x = mClickedPos.x + scaledDim.width; + pos.y = mClickedPos.y + scaledDim.height; + + zoomSetDims(source, pos); + + zoom(source); + } + + public boolean onKeyEvent(BoardEdit source, KeyEvent event) + { + if(event.getID() != KeyEvent.KEY_PRESSED) + return false; + + int key = event.getKeyChar(); + + if(key == '+') + { + zoomInStep(source, event.isAltDown()); + + return true; + } + else if(key == '-') + { + zoomOutStep(source, event.isAltDown()); + + return true; + } + return false; + } + + public String getCommandString() + { + return LanguageResource.getString("ZOOMCMD_STR"); + } + +} \ No newline at end of file diff --git a/boardcad/commands/GhostCommand.java b/boardcad/commands/GhostCommand.java new file mode 100644 index 0000000..b3fbf59 --- /dev/null +++ b/boardcad/commands/GhostCommand.java @@ -0,0 +1,18 @@ +package boardcad.commands; + +import boardcad.i18n.LanguageResource; + +public class GhostCommand extends BrdInputCommand +{ + + public GhostCommand() + { + mCanUndo = false; + } + + public String getCommandString() + { + return LanguageResource.getString("GHOSTCMD_STR"); + } +} + diff --git a/boardcad/commands/NurbsEditCommand.java b/boardcad/commands/NurbsEditCommand.java new file mode 100644 index 0000000..028f081 --- /dev/null +++ b/boardcad/commands/NurbsEditCommand.java @@ -0,0 +1,46 @@ +package boardcad.commands; + +import board.NurbsBoard; +import boardcad.gui.jdk.BoardCAD; +import boardcad.gui.jdk.BoardHandler; +import boardcad.i18n.LanguageResource; + +public class NurbsEditCommand extends BrdCommand +{ + NurbsBoard oldBoard; + NurbsBoard newBoard; + BoardHandler board_handler; + + public NurbsEditCommand() + { + NurbsBoard board; + board_handler=BoardCAD.getInstance().getBoardHandler(); + board=board_handler.getActiveBoard(); + if(board!=null) + oldBoard = (NurbsBoard)board.clone(); + } + + public void execute() + { + NurbsBoard board; + board=board_handler.getActiveBoard(); + if(board!=null) + newBoard = (NurbsBoard)board.clone(); + super.execute(); + } + + public void redo() + { + board_handler.setActiveBoard(newBoard); + } + + public void undo() + { + board_handler.setActiveBoard(oldBoard); + } + + public String getCommandString() + { + return LanguageResource.getString("MACROCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/PointEditCommand.java b/boardcad/commands/PointEditCommand.java new file mode 100644 index 0000000..01a933b --- /dev/null +++ b/boardcad/commands/PointEditCommand.java @@ -0,0 +1,39 @@ +package boardcad.commands; + +import java.awt.geom.Point2D; + +import boardcad.i18n.LanguageResource; + +public class PointEditCommand extends BrdCommand +{ + Point2D.Double mEditedPoint; + Point2D.Double mOriginalPos; + Point2D.Double mNewPos; + + PointEditCommand(Point2D.Double point) + { + mEditedPoint = point; + mOriginalPos = (Point2D.Double)point.clone(); + } + + public void execute(Point2D.Double newPos) + { + mNewPos = (Point2D.Double)newPos.clone(); + redo(); + } + + public void redo() + { + mEditedPoint.setLocation(mNewPos); + } + + public void undo() + { + mEditedPoint.setLocation(mOriginalPos); + } + + public String getCommandString() + { + return LanguageResource.getString("MACROCMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/SetImageNoseCommand.java b/boardcad/commands/SetImageNoseCommand.java new file mode 100644 index 0000000..e1802b0 --- /dev/null +++ b/boardcad/commands/SetImageNoseCommand.java @@ -0,0 +1,29 @@ +package boardcad.commands; + +import java.awt.Point; +import java.awt.event.MouseEvent; + +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; + +public class SetImageNoseCommand extends BrdInputCommand +{ + + public SetImageNoseCommand() + { + mCanUndo = false; + } + + public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) + { + Point pos = event.getPoint(); + + source.adjustBackgroundImageNose(pos); + + } + + public String getCommandString() + { + return LanguageResource.getString("ADJUSTIMAGETONOSECMD_STR"); + } +} \ No newline at end of file diff --git a/boardcad/commands/SetImageTailCommand.java b/boardcad/commands/SetImageTailCommand.java new file mode 100644 index 0000000..7c5f359 --- /dev/null +++ b/boardcad/commands/SetImageTailCommand.java @@ -0,0 +1,30 @@ +package boardcad.commands; + +import java.awt.Point; +import java.awt.event.MouseEvent; + +import boardcad.gui.jdk.BoardEdit; +import boardcad.i18n.LanguageResource; + +public class SetImageTailCommand extends BrdInputCommand +{ + + public SetImageTailCommand() + { + mCanUndo = false; + } + + public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) + { + Point pos = event.getPoint(); + + source.adjustBackgroundImageTail(pos); + + } + + public String getCommandString() + { + return LanguageResource.getString("ADJUSTIMAGETOTAILCMD_STR"); + } + +} \ No newline at end of file diff --git a/boardcad/export/GCodeDraw.java b/boardcad/export/GCodeDraw.java index c142a48..f1b0691 100644 --- a/boardcad/export/GCodeDraw.java +++ b/boardcad/export/GCodeDraw.java @@ -1,5 +1,720 @@ package boardcad.export; -public class GCodeDraw { //TODO: implement using gcode writer +import java.awt.Color; +import java.awt.Stroke; +import java.awt.geom.AffineTransform; +import java.awt.geom.CubicCurve2D; +import java.awt.geom.Ellipse2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Line2D; +import java.awt.geom.PathIterator; +import java.awt.geom.Point2D; +import java.io.File; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Vector; +import cadcore.BezierCurve; +import cadcore.VecMath; +import boardcad.AbstractDraw; +import boardcad.FileTools; +import boardcam.writers.GCodeWriter; + +public class GCodeDraw extends AbstractDraw { + PrintStream mStream = null; + AffineTransform mTransform = new AffineTransform(); + + Vector mVerticies = new Vector(); + + GCodeWriter mGCodeWriter = new GCodeWriter(); + + double mToolDiameter; + double mCuttingDepth; + double mCuttingSpeed; + double mJogHeight; + double mJogSpeed; + double mSinkSpeed; + + boolean mFlipNormal = false; + + public GCodeDraw(String filename, double toolDiameter, double cuttingDepth, + double cuttingSpeed, double jogHeight, double jogSpeed, + double sinkSpeed) { + mTransform.setToIdentity(); + + mToolDiameter = toolDiameter; + mCuttingDepth = cuttingDepth; + mCuttingSpeed = cuttingSpeed; + mJogHeight = jogHeight; + mJogSpeed = jogSpeed; + mSinkSpeed = sinkSpeed; + + File file = new File(FileTools.setExtension(filename, "nc")); + + try { + mStream = new PrintStream(file); + } catch (Exception e) { + return; + } + + mGCodeWriter.writeComment(mStream, "G-Code Draw"); + + } + + public void writeComment(String comment) + { + mGCodeWriter.writeComment(mStream, comment); + } + + @Override + public void close() { + mGCodeWriter.writeEnd(mStream); + mStream.close(); + } + + public void setFlipNormal(boolean flip) { + mFlipNormal = flip; + } + + public void setCutterDiameter(double diam) { + mToolDiameter = diam; + } + + @Override + public void setColor(Color color) { + // Ignore color + + } + + @Override + public void setStroke(Stroke stroke) { + // Ignore stroke + + } + + @Override + public void transform(AffineTransform transform) { + mTransform.preConcatenate(transform); + } + + @Override + public void setTransform(AffineTransform transform) { + mTransform = transform; + } + + @Override + public AffineTransform getTransform() { + return mTransform; + } + + @Override + public void fill(Ellipse2D line) { + // Ignored + System.out.printf("Path fill not supported by GCodeDraw"); + + } + + @Override + public void fill(GeneralPath path) { + // Ignored + System.out.printf("Path fill not supported by GCodeDraw"); + } + + public void draw(GeneralPath path) { + Point2D.Double prevPoint = null; + Point2D.Double lastPoint = null; + Point2D.Double moveToPoint = null; + Point2D.Double afterMovePoint = null; + boolean isLastMoveTo = false; + + // System.out.printf("GCodeDraw draw Path\n"); + + double[] coords = new double[8]; + int segmentType; + + for (PathIterator it = path.getPathIterator(getTransform()); it + .isDone() == false; it.next()) { + segmentType = it.currentSegment(coords); + + switch (segmentType) { + + // The segment type constant for a point that specifies the starting + // location for a new subpath. + case PathIterator.SEG_MOVETO: { + // System.out.printf("Path SEG_MOVETO\n"); + + lastPoint = new Point2D.Double(coords[0], coords[1]); + moveToPoint = lastPoint; + isLastMoveTo = true; + + // Assuming there is only one close in path + prevPoint = getLastPointBeforeClose(path); + + } + break; + + // The segment type constant for a point that specifies the end + // point of a line to be drawn from the most recently specified + // point. + // NOTE: This will only work if the angle between lines is 90 + // degrees or more. Narrower angles will result in overshoot into + // the next line segment + case PathIterator.SEG_LINETO: { + // System.out.printf("Path SEG_LINETO\n"); + + Point2D.Double currentPoint = new Point2D.Double(coords[0], + coords[1]); + if (lastPoint.equals(currentPoint)) { + continue; + } + + // Assuming there is only one close in path + Point2D.Double nextPoint = getNextPoint(path, it); + if (currentPoint.equals(nextPoint)) { + continue; + } + + if (isLastMoveTo == true) // First cut after move + { + Point2D.Double startOffset = getCornerOffset(prevPoint, + lastPoint, currentPoint, mToolDiameter, mFlipNormal); + if (Double.isInfinite(startOffset.x) + || Double.isInfinite(startOffset.y)) + continue; + if (Double.isNaN(startOffset.x) || Double.isNaN(startOffset.y)) + continue; + + mGCodeWriter.writeSpeed(mStream, mJogSpeed); // Set jog + // speed + mGCodeWriter.writeZCoordinate(mStream, mJogHeight); // Jog + // height + + mGCodeWriter.writeCoordinate(mStream, lastPoint.getX() + + startOffset.x, lastPoint.getY() + startOffset.y, + mJogHeight); // Move to + mGCodeWriter.writeSpeed(mStream, mSinkSpeed); // Set sink + // speed + mGCodeWriter.writeCoordinate(mStream, lastPoint.getX() + + startOffset.x, lastPoint.getY() + startOffset.y, + mCuttingDepth); // Sink + + afterMovePoint = currentPoint; + } + + Point2D.Double currentOffset = getCornerOffset(lastPoint, + currentPoint, nextPoint, mToolDiameter, mFlipNormal); + if (Double.isInfinite(currentOffset.x) + || Double.isInfinite(currentOffset.y)) + continue; + if (Double.isNaN(currentOffset.x) || Double.isNaN(currentOffset.y)) + continue; + + Point2D.Double currentPointWithOffset = new Point2D.Double(); + VecMath.addVector(currentPoint, currentOffset, currentPointWithOffset); + + System.out.printf("pos x:%f y:%f final x:%f y:%f Offset x:%f y:%f\n", currentPoint.x, currentPoint.y, currentPointWithOffset.x, currentPointWithOffset.y, currentOffset.x, currentOffset.y); + + mGCodeWriter.writeSpeed(mStream, mCuttingSpeed); // Set cut + // speed + mGCodeWriter.writeCoordinate(mStream, currentPointWithOffset.x, currentPointWithOffset.y, mCuttingDepth); // Cut + + prevPoint = lastPoint; + lastPoint = currentPoint; + + isLastMoveTo = false; + } + break; + + // The segment type constant for the set of 3 points that specify a + // cubic parametric curve to be drawn from the most recently + // specified point. + case PathIterator.SEG_CUBICTO: { + // System.out.printf("Path SEG_CUBICTO\n"); + + CubicCurve2D curve = new CubicCurve2D.Double(lastPoint.getX(), + lastPoint.getY(), coords[0], coords[1], coords[2], + coords[3], coords[4], coords[5]); + BezierCurve bezier = new BezierCurve(curve.getX1(), + curve.getY1(), curve.getCtrlX1(), curve.getCtrlY1(), + curve.getCtrlX2(), curve.getCtrlY2(), curve.getX2(), + curve.getY2()); + + Point2D.Double startNormal = getCubicCurveStartNormal(curve); + + Point2D.Double startPos = bezier.getValue(0.0); + + if (isLastMoveTo == true) // First cut after move + { + Point2D.Double startOffset = getCornerOffset(prevPoint, + lastPoint, + new Point2D.Double(coords[0], coords[1]), + mToolDiameter, mFlipNormal); + + mGCodeWriter.writeSpeed(mStream, mJogSpeed); // Set jog + // speed + mGCodeWriter.writeZCoordinate(mStream, mJogHeight); // Lift + // to + // Jog + // height + + mGCodeWriter.writeCoordinate(mStream, startPos.getX() + + startOffset.x, startPos.getY() + startOffset.y, + mJogHeight); // Move to + mGCodeWriter.writeSpeed(mStream, mSinkSpeed); // Set sink + // speed + mGCodeWriter.writeCoordinate(mStream, startPos.getX() + + startOffset.x, startPos.getY() + startOffset.y, + mCuttingDepth); // Sink + + mGCodeWriter.writeSpeed(mStream, mCuttingSpeed); // Set cut + // speed + + afterMovePoint = new Point2D.Double(coords[0], coords[1]); + } + + double bezierLength = bezier.getLength() * 10.0; // convert to + // mm + + int steps = (int) bezierLength; + + for (int i = 0; i < steps; i++) { + double t = (double) i / (double) steps; + Point2D.Double pos = bezier.getValue(t); + + Point2D.Double perpendicularVec = bezier.getNormalVector(t); + + VecMath.scaleVector(perpendicularVec, mToolDiameter / 2.0); + + if (mFlipNormal) { + VecMath.scaleVector(perpendicularVec, -1.0); + } + + mGCodeWriter.writeCoordinate(mStream, pos.getX() + + perpendicularVec.x, pos.getY() + + perpendicularVec.y, mCuttingDepth); // Sink + + } + + prevPoint = new Point2D.Double(coords[2], coords[3]); + lastPoint = new Point2D.Double(coords[4], coords[5]); + + isLastMoveTo = false; + } + break; + + // The segment type constant for the pair of points that specify a + // quadratic parametric curve to be drawn from the most recently + // specified point. } + case PathIterator.SEG_QUADTO: { + // Unsupported + System.out.printf("Quad not supported by GCodeDraw\n"); + } + break; + + // The segment type constant that specifies that the preceding + // subpath should be closed by appending a line segment back to the + // point corresponding to the most recent SEG_MOVETO. + case PathIterator.SEG_CLOSE: { + // System.out.printf("Path SEG_CLOSE\n"); + + // Assuming there is only one move in the path + + Point2D.Double offset = getCornerOffset(lastPoint, moveToPoint, + afterMovePoint, mToolDiameter, mFlipNormal); + + mGCodeWriter.writeCoordinate(mStream, moveToPoint.getX() + + offset.x, moveToPoint.getY() + offset.y, + mCuttingDepth); // Cut + } + break; + } + + } + + // System.out.printf("GCodeDraw draw Path Ended\n"); + } + + @Override + public void draw(Line2D line) { + System.out.printf("GCodeDraw Draw Line\n"); + + Point2D startPoint = line.getP1(); + Point2D endPoint = line.getP2(); + + // Calculate normal vec to line + Point2D.Double perpendicularVec = getLineNormal(line); + VecMath.scaleVector(perpendicularVec, mToolDiameter / 2.0); + if (mFlipNormal) { + VecMath.scaleVector(perpendicularVec, -1.0); + } + + System.out.printf("Line start: %f, %f\n", startPoint.getX(), + startPoint.getY()); + System.out.printf("Line end: %f, %f\n", endPoint.getX(), + endPoint.getY()); + + System.out.printf("Offset: %f, %f\n", perpendicularVec.getX(), + perpendicularVec.getY()); + + mGCodeWriter.writeSpeed(mStream, mJogSpeed); // Set jog speed + mGCodeWriter.writeZCoordinate(mStream, mJogHeight); // Lift tool + // straight up for + // jog + + mGCodeWriter.writeCoordinate(mStream, startPoint.getX() + + perpendicularVec.x, startPoint.getY() + perpendicularVec.y, + mJogHeight); // Move to + mGCodeWriter.writeSpeed(mStream, mSinkSpeed); // Set sink speed + mGCodeWriter.writeCoordinate(mStream, startPoint.getX() + + perpendicularVec.x, startPoint.getY() + perpendicularVec.y, + mCuttingDepth); // Sink + mGCodeWriter.writeSpeed(mStream, mCuttingSpeed); // Set cut speed + mGCodeWriter.writeCoordinate(mStream, endPoint.getX() + + perpendicularVec.x, endPoint.getY() + perpendicularVec.y, + mCuttingDepth); // Cut + + mGCodeWriter.writeSpeed(mStream, mJogSpeed); // Set jog speed + mGCodeWriter.writeZCoordinate(mStream, mJogHeight); // Lift tool for jog + } + + @Override + public void draw(Ellipse2D elipse) { + // TODO Auto-generated method stub + + } + + @Override + public void draw(CubicCurve2D curve) { + + System.out.printf("GCodeDraw Draw Cubic Curve\n"); + + BezierCurve bezier = new BezierCurve(curve.getX1(), curve.getY1(), + curve.getCtrlX1(), curve.getCtrlY1(), curve.getCtrlX2(), + curve.getCtrlY2(), curve.getX2(), curve.getY2()); + + double bezierLength = bezier.getLength() * 10.0; // convert to mm + + int steps = (int) bezierLength; + + for (int i = 0; i < steps; i++) { + double t = (double) i / (double) steps; + Point2D.Double pos = bezier.getValue(t); + Point2D.Double perpendicularVec = bezier.getNormalVector(t); + VecMath.scaleVector(perpendicularVec, mToolDiameter / 2.0); + + if (mFlipNormal) { + VecMath.scaleVector(perpendicularVec, -1.0); + } + + if (i == 0) { + mGCodeWriter.writeSpeed(mStream, mJogSpeed); // Set jog speed + mGCodeWriter.writeZCoordinate(mStream, mJogHeight); // Lift tool + // straight + // up for + // jog + + mGCodeWriter.writeCoordinate(mStream, pos.getX() + + perpendicularVec.x, pos.getY() + perpendicularVec.y, + mJogHeight); // Move to + mGCodeWriter.writeSpeed(mStream, mSinkSpeed); // Set sink speed + } else { + mGCodeWriter.writeSpeed(mStream, mCuttingSpeed); // Set cut + // speed + } + + mGCodeWriter.writeCoordinate(mStream, pos.getX() + + perpendicularVec.x, pos.getY() + perpendicularVec.y, + mCuttingDepth); // Sink + + } + + mGCodeWriter.writeSpeed(mStream, mJogSpeed); // Set jog speed + mGCodeWriter.writeZCoordinate(mStream, mJogHeight); // Lift tool for jog + + } + + @Override + public void moveTo(Point2D point) { + System.out.printf("GCodeDraw moveTO\n"); + + mGCodeWriter.writeSpeed(mStream, mJogSpeed); // Set jog speed + mGCodeWriter.writeZCoordinate(mStream, mJogHeight); // Lift tool + // straight up for + // jog + + mGCodeWriter.writeCoordinate(mStream, point.getX(), point.getY(), + mJogHeight); // Move to + } + + Point2D.Double getLineNormal(Line2D line) { + Point2D startPoint = line.getP1(); + Point2D endPoint = line.getP2(); + + // Calculate normal vec to line + Point2D.Double perpendicularVec = new Point2D.Double(startPoint.getY() + - endPoint.getY(), endPoint.getX() - startPoint.getX()); // (-y,x) + // is + // perpendicular + VecMath.normalizeVector(perpendicularVec); + + return perpendicularVec; + } + + Point2D.Double getCubicCurveStartNormal(CubicCurve2D curve) { + Point2D startPoint = curve.getP1(); + Point2D endPoint = curve.getCtrlP1(); + + // Calculate normal vec to line + Point2D.Double perpendicularVec = new Point2D.Double(startPoint.getY() + - endPoint.getY(), endPoint.getX() - startPoint.getX()); // (-y,x) + // is + // perpendicular + VecMath.normalizeVector(perpendicularVec); + + return perpendicularVec; + } + + Point2D.Double getCubicCurveEndNormal(CubicCurve2D curve) { + Point2D startPoint = curve.getCtrlP2(); + Point2D endPoint = curve.getP2(); + + // Calculate normal vec to line + Point2D.Double perpendicularVec = new Point2D.Double(startPoint.getY() + - endPoint.getY(), endPoint.getX() - startPoint.getX()); // (-y,x) + // is + // perpendicular + VecMath.normalizeVector(perpendicularVec); + + return perpendicularVec; + } + + Point2D.Double getLastPointBeforeClose(GeneralPath path) { + Point2D.Double last = null; + + for (PathIterator it = path.getPathIterator(getTransform()); it + .isDone() == false; it.next()) { + + double[] coords = new double[8]; + int segmentType = it.currentSegment(coords); + + switch (segmentType) { + case PathIterator.SEG_MOVETO: + case PathIterator.SEG_LINETO: { + last = new Point2D.Double(coords[0], coords[1]); + } + break; + + case PathIterator.SEG_CUBICTO: { + last = new Point2D.Double(coords[4], coords[5]); + } + break; + + case PathIterator.SEG_CLOSE: + return last; + } + } + return null; + } + + Point2D.Double getNextPoint(GeneralPath path, PathIterator it) { + double[] coords = new double[8]; + int segmentType = it.currentSegment(coords); + + Point2D.Double lastMove = null; + + for (PathIterator tmp = path.getPathIterator(getTransform()); tmp + .isDone() == false; tmp.next()) { + double[] tmpCoords = new double[8]; + int tmpSegmentType = tmp.currentSegment(tmpCoords); + { + if (tmpSegmentType == PathIterator.SEG_MOVETO) { + lastMove = new Point2D.Double(tmpCoords[0], tmpCoords[1]); + } + + if (tmpSegmentType == segmentType + && Arrays.equals(coords, tmpCoords)) { + tmp.next(); + tmpSegmentType = tmp.currentSegment(coords); + + switch (tmpSegmentType) { + case PathIterator.SEG_MOVETO: + case PathIterator.SEG_LINETO: + case PathIterator.SEG_CUBICTO: { + Point2D.Double next = new Point2D.Double(coords[0], + coords[1]); + return next; + } + + case PathIterator.SEG_CLOSE: + return lastMove; + } + } + } + } + return null; + } + + Point2D.Double getCornerOffset(Point2D.Double start, Point2D.Double mid, + Point2D.Double end, double toolDiam, boolean flip) { + if (start == null) { + // Start of sequence, no previous point + Point2D.Double normal = new Point2D.Double(end.x -mid.x, mid.y - end.y); + VecMath.normalizeVector(normal); + return normal; + } + + //Point2D.Double a = new Point2D.Double(mid.x - start.x, mid.y - start.y); + //Point2D.Double b = new Point2D.Double(mid.x - end.x, mid.y - end.y); + + Point2D.Double an = new Point2D.Double(start.y - mid.y, mid.x - start.x); + Point2D.Double bn = new Point2D.Double(mid.y - end.y, end.x - mid.x ); + + Point2D.Double offsetVector = new Point2D.Double(); + //VecMath.addVector(a, b, offset); + VecMath.addVector(an, bn, offsetVector); + if (offsetVector.x == 0.0 && offsetVector.y == 0.0) + return offsetVector; + + VecMath.normalizeVector(offsetVector); + if (flip) { + VecMath.scaleVector(offsetVector, -1); + } + + //double angle = VecMath.getVecAngle(a, b); + //double offsetLength = toolDiam / Math.sin(angle / 2.0); + double angle = VecMath.getVecAngle(an, bn); + double offsetLength = toolDiam / Math.cos(angle / 2.0); + System.out.printf("angle:%f offsetLength:%f\n", angle/Math.PI*180.0, offsetLength); + + VecMath.scaleVector(offsetVector, offsetLength); + //System.out.printf("offsetVector %f,%f\n", offsetVector.x,offsetVector.y); + + return offsetVector; + } + + private boolean isPathClosed(GeneralPath path) { + + double[] coords = new double[8]; + + for (PathIterator it = path.getPathIterator(getTransform()); it + .isDone() == false; it.next()) { + int segmentType = it.currentSegment(coords); + + if (segmentType == PathIterator.SEG_CLOSE) { + return true; + } + + } + return false; + } + + private boolean isPathClosed(PathIterator it) { + double[] coords = new double[8]; + + for (; it.isDone() == false; it.next()) { + int segmentType = it.currentSegment(coords); + + if (segmentType == PathIterator.SEG_MOVETO) { + return false; + } + + if (segmentType == PathIterator.SEG_CLOSE) { + return true; + } + + } + return false; + } + + private Point2D.Double getLastPointBeforeClose(PathIterator it) { + double[] coords = new double[8]; + + Point2D.Double lastPoint = new Point2D.Double(); + + for (; it.isDone() == false; it.next()) { + int segmentType = it.currentSegment(coords); + + switch (segmentType) { + case PathIterator.SEG_LINETO: { + lastPoint.x = coords[0]; + lastPoint.y = coords[1]; + break; + } + case PathIterator.SEG_CUBICTO: { + lastPoint.x = coords[4]; + lastPoint.y = coords[5]; + break; + } + case PathIterator.SEG_CLOSE: { + return lastPoint; + } + default: { + break; // Not used + } + } + } + return null; + } + + private boolean isNextClose(PathIterator it) { + it.next(); + + if (it.isDone()) { + return false; + } + + double[] coords = new double[8]; + + int segmentType = it.currentSegment(coords); + + switch (segmentType) { + case PathIterator.SEG_CLOSE: { + return true; + } + default: { + return false; + } + } + } + + private Point2D.Double getNextPoint(PathIterator it) { + it.next(); + + if (it.isDone()) { + return null; + } + + double[] coords = new double[8]; + + Point2D.Double nextPoint = new Point2D.Double(); + + int segmentType = it.currentSegment(coords); + + switch (segmentType) { + + case PathIterator.SEG_LINETO: { + nextPoint.x = coords[0]; + nextPoint.y = coords[1]; + break; + } + case PathIterator.SEG_CUBICTO: { + nextPoint.x = coords[4]; + nextPoint.y = coords[5]; + break; + } + case PathIterator.SEG_CLOSE: { + // //Iterate backwards to find last move to + // for(; it.isDone() == false; it.previous()) + // { + // + // } + + return null; + } + default: { + return null; + } + } + return nextPoint; + } } diff --git a/boardcad/gui/jdk/AboutBox.java b/boardcad/gui/jdk/AboutBox.java index b896747..088012f 100644 --- a/boardcad/gui/jdk/AboutBox.java +++ b/boardcad/gui/jdk/AboutBox.java @@ -46,7 +46,7 @@ private void initialize() { private JTextArea getMText() { if (mText == null) { mText = new JTextArea(); - mText.setText(" BoardCAD v3.0.1 (February 23, 2015)\n \nProgramming by:\nJonas Hörnstein\nOla Helenius\nHåvard Nygård Jakobsen\nSven Wesley\n\nTranslation by:\nMocoloitam (Portugese)\nPere Antoni Comas (Spanish)\nStephen Kitchener (French)\nWouter Oosting (Dutch)\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see http://www.gnu.org/licenses\n===================================================================\n Enjoy... "); + mText.setText(" BoardCAD v3.1 (Feb 1, 2011)\n \nProgramming by:\nJonas Hörnstein\nOla Helenius\nHåvard Nygård Jakobsen\nSven Wesley\n\nTranslation by:\nMocoloitam (Portugese)\nPere Antoni Comas (Spanish)\nStephen Kitchener (French)\nWouter Oosting (Dutch)\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see http://www.gnu.org/licenses\n===================================================================\n Enjoy... "); mText.setEditable(false); mText.setBackground(Color.lightGray); mText.setFont(new Font("Dialog", Font.PLAIN, 14)); diff --git a/boardcad/gui/jdk/BezierBoardDrawUtil.java b/boardcad/gui/jdk/BezierBoardDrawUtil.java index 767f81c..2742c63 100644 --- a/boardcad/gui/jdk/BezierBoardDrawUtil.java +++ b/boardcad/gui/jdk/BezierBoardDrawUtil.java @@ -10,10 +10,11 @@ import cadcore.*; import cadcore.MathUtils.Function; import boardcad.*; +import boardcad.commands.BrdEditCommand; public class BezierBoardDrawUtil { - static final long serialVersionUID=1L; - + static final long serialVersionUID = 1L; + static public int FlipX = 0x01; static public int FlipY = 0x02; static public int MirrorX = 0x010; @@ -29,28 +30,25 @@ public class BezierBoardDrawUtil { static public final double SLIDING_CROSS_SECTION_MIN_LINE_LENGTH = 0.05; static public final double SLIDING_CROSS_SECTION_MAX_LINE_LENGTH = 1.0; static public final double SLIDING_CROSS_MIN_SPLIT = 0.00001; - static public final double S_BLEND_MIN_ANGLE = 2*(Math.PI/180.0) ; + static public final double S_BLEND_MIN_ANGLE = 2 * (Math.PI / 180.0); static public final double S_BLEND_MAX_LENGTH = 1.0; static public final double S_BLEND_MIN_LENGTH = 0.1; static public final double TUCK_UNDER_DEFINITION_ANGLE = 175.0; static public final double APEX_DEFINITION_ANGLE = 90; - static final Vector3d upVector = new Vector3d(0.0, 0.0, 1.0); - - //Shared variables so we don't need to pass them all the time - static double mMulX; - static double mMulY; - static BezierBoard mBrd; + static final Vector3d upVector = new Vector3d(0.0, 0.0, 1.0); + static final Vector3d downVector = new Vector3d(0.0, 0.0, 1.0); + // Shared variables so we don't need to pass them all the time + static BezierBoard mBrd; - public static GeneralPath makeBezierPathFromControlPoints(BezierSpline spline, boolean flipX, boolean flipY, boolean vertical, boolean reverse) - { - GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD); + public static GeneralPath makeBezierPathFromControlPoints(BezierSpline spline, boolean flipX, boolean flipY, boolean vertical, boolean reverse) { + GeneralPath path = new GeneralPath(Path2D.WIND_EVEN_ODD); - if(spline == null) + if (spline == null) return path; - if(spline.getNrOfControlPoints() == 0) + if (spline.getNrOfControlPoints() == 0) return path; double sx; @@ -68,321 +66,233 @@ public static GeneralPath makeBezierPathFromControlPoints(BezierSpline spline, b double ex; double ey; - + double tmp; - double mulX = flipX?-1:1; - double mulY= flipY?-1:1; + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; - if(reverse) - { + if (reverse) { - // Start + // Start sx = spline.getControlPoint(spline.getNrOfControlPoints() - 1).getEndPoint().x; sy = spline.getControlPoint(spline.getNrOfControlPoints() - 1).getEndPoint().y; - - if(vertical) - { + + if (vertical) { tmp = sx; sx = sy; - sy = tmp; + sy = tmp; } - + sx *= mulX; sy *= mulY; - - - path.moveTo((float)(sx),(float)(sy)); - - for(int i = spline.getNrOfControlPoints() - 1; i > 0; i--) { - - // Start control point + + path.moveTo((float) (sx), (float) (sy)); + + for (int i = spline.getNrOfControlPoints() - 1; i > 0; i--) { + + // Start control point scx = spline.getControlPoint(i).getTangentToPrev().x; scy = spline.getControlPoint(i).getTangentToPrev().y; - - // End control point - ecx = spline.getControlPoint(i-1).getTangentToNext().x; - ecy = spline.getControlPoint(i-1).getTangentToNext().y; - - // End point - ex = spline.getControlPoint(i-1).getEndPoint().x; - ey = spline.getControlPoint(i-1).getEndPoint().y; - - if(vertical) - { + + // End control point + ecx = spline.getControlPoint(i - 1).getTangentToNext().x; + ecy = spline.getControlPoint(i - 1).getTangentToNext().y; + + // End point + ex = spline.getControlPoint(i - 1).getEndPoint().x; + ey = spline.getControlPoint(i - 1).getEndPoint().y; + + if (vertical) { tmp = scx; scx = scy; scy = tmp; - + tmp = ecx; ecx = ecy; ecy = tmp; - + tmp = ex; ex = ey; ey = tmp; } - - path.curveTo((float)(scx*mulX), (float)(scy*mulY), (float)(ecx*mulX), (float)(ecy*mulY), (float)(ex*mulX), (float)(ey*mulY)); - - } - } - else - { - - // Start - sx = spline.getControlPoint(0).getEndPoint().x; - sy = spline.getControlPoint(0).getEndPoint().y; - - if(vertical) - { - tmp = sx; - sx = sy; - sy = tmp; - } - - sx *= mulX; - sy *= mulY; - - - path.moveTo((float)(sx),(float)(sy)); - - for(int i = 0; i < spline.getNrOfControlPoints()-1; i++) { - - // Start control point - scx = spline.getControlPoint(i).getTangentToNext().x; - scy = spline.getControlPoint(i).getTangentToNext().y; - - - - // End control point - ecx = spline.getControlPoint(i+1).getTangentToPrev().x; - ecy = spline.getControlPoint(i+1).getTangentToPrev().y; - - - - // End point - ex = spline.getControlPoint(i+1).getEndPoint().x; - ey = spline.getControlPoint(i+1).getEndPoint().y; - - if(vertical) - { - tmp = scx; - scx = scy; - scy = tmp; - - tmp = ecx; - ecx = ecy; - ecy = tmp; - - tmp = ex; - ex = ey; - ey = tmp; - } - - path.curveTo((float)(scx*mulX), (float)(scy*mulY), (float)(ecx*mulX), (float)(ecy*mulY), (float)(ex*mulX), (float)(ey*mulY)); - - } - } - return path; - } + path.curveTo((float) (scx * mulX), (float) (scy * mulY), (float) (ecx * mulX), (float) (ecy * mulY), (float) (ex * mulX), (float) (ey * mulY)); - public static void paintPath(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, GeneralPath path, boolean fill) - { - if(path == null) - return; + } + } else { - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); + // Start + sx = spline.getControlPoint(0).getEndPoint().x; + sy = spline.getControlPoint(0).getEndPoint().y; - if(fill) - { - try{ - GeneralPath fillPath = (GeneralPath)path.clone(); - fillPath.closePath(); - d.setColor(Color.white); - d.fill(fillPath); - } - catch(java.awt.geom.IllegalPathStateException e) - { + if (vertical) { + tmp = sx; + sx = sy; + sy = tmp; } - } - d.setColor(color); + sx *= mulX; + sy *= mulY; - d.setStroke(stroke); + path.moveTo((float) (sx), (float) (sy)); - d.draw(path); + for (int i = 0; i < spline.getNrOfControlPoints() - 1; i++) { - d.setTransform(savedTransform); + // Start control point + scx = spline.getControlPoint(i).getTangentToNext().x; + scy = spline.getControlPoint(i).getTangentToNext().y; + + // End control point + ecx = spline.getControlPoint(i + 1).getTangentToPrev().x; + ecy = spline.getControlPoint(i + 1).getTangentToPrev().y; + + // End point + ex = spline.getControlPoint(i + 1).getEndPoint().x; + ey = spline.getControlPoint(i + 1).getEndPoint().y; + + if (vertical) { + tmp = scx; + scx = scy; + scy = tmp; + + tmp = ecx; + ecx = ecy; + ecy = tmp; + + tmp = ex; + ex = ey; + ey = tmp; + } + + path.curveTo((float) (scx * mulX), (float) (scy * mulY), (float) (ecx * mulX), (float) (ecy * mulY), (float) (ex * mulX), (float) (ey * mulY)); + + } + } + + return path; } - public static void paintPath(AbstractDraw d, double offsetX, double offsetY, double rotation, double scale, Color color, Stroke stroke, GeneralPath path, boolean fill) - { - if(path == null) + public static void paintPath(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, GeneralPath path, boolean fill) { + if (path == null) return; - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, rotation, scale); - - //Draw fill - if(fill) - { - try - { + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + + // Draw fill + if (fill) { + try { GeneralPath closedPath = new GeneralPath(path); closedPath.closePath(); d.setColor(Color.white); d.fill(closedPath); - } - catch(java.awt.geom.IllegalPathStateException e) - { - //Ignore empty path + } catch (java.awt.geom.IllegalPathStateException e) { + // Ignore empty path } } - - //Draw path + + // Draw path d.setColor(color); d.setStroke(stroke); d.draw(path); - - d.setTransform(savedTransform); + + resetTransform(d, savedTransform); } - public static void fillPath(AbstractDraw d, double offsetX, double offsetY, double rotation, double scale, Color color, Stroke stroke, GeneralPath path) - { - if(path == null) + public static void fillPath(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, GeneralPath path) { + if (path == null) return; d.setColor(color); d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, rotation, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); d.fill(path); - - d.setTransform(savedTransform); - } - public static void paintBezierSpline(AbstractDraw d, double offsetX, + resetTransform(d, savedTransform); + } - double offsetY, double scale, Color color, Stroke stroke, BezierSpline mPoints, int DrawControl, boolean fill) - { - if(mPoints == null) + public static void paintBezierSpline(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierSpline mPoints, int DrawControl, boolean fill) { + if (mPoints == null) return; - GeneralPath path = makeBezierPathFromControlPoints(mPoints, (DrawControl&BezierBoardDrawUtil.FlipX)!=0, (DrawControl&BezierBoardDrawUtil.FlipY)!=0, (DrawControl&BezierBoardDrawUtil.Vertical)!=0, false); - paintPath(d, offsetX, offsetY, scale, color, stroke, path, fill); + GeneralPath path = makeBezierPathFromControlPoints(mPoints, (DrawControl & BezierBoardDrawUtil.FlipX) != 0, (DrawControl & BezierBoardDrawUtil.FlipY) != 0, + (DrawControl & BezierBoardDrawUtil.Vertical) != 0, false); + paintPath(d, offsetX, offsetY, scale, rotation, color, stroke, path, fill); - if((DrawControl&BezierBoardDrawUtil.MirrorX)!=0) - { - path = makeBezierPathFromControlPoints(mPoints, !((DrawControl&BezierBoardDrawUtil.FlipX)!=0), (DrawControl&BezierBoardDrawUtil.FlipY)!=0, (DrawControl&BezierBoardDrawUtil.Vertical)!=0, false); - paintPath(d, offsetX, offsetY, scale, color, stroke, path, fill); + if ((DrawControl & BezierBoardDrawUtil.MirrorX) != 0) { + path = makeBezierPathFromControlPoints(mPoints, !((DrawControl & BezierBoardDrawUtil.FlipX) != 0), (DrawControl & BezierBoardDrawUtil.FlipY) != 0, + (DrawControl & BezierBoardDrawUtil.Vertical) != 0, false); + paintPath(d, offsetX, offsetY, scale, rotation, color, stroke, path, fill); } - if((DrawControl&BezierBoardDrawUtil.MirrorY)!=0) - { - path = makeBezierPathFromControlPoints(mPoints, (DrawControl&BezierBoardDrawUtil.FlipX)!=0, !((DrawControl&BezierBoardDrawUtil.FlipY)!=0), (DrawControl&BezierBoardDrawUtil.Vertical)!=0, false); - paintPath(d, offsetX, offsetY, scale, color, stroke, path, fill); + if ((DrawControl & BezierBoardDrawUtil.MirrorY) != 0) { + path = makeBezierPathFromControlPoints(mPoints, (DrawControl & BezierBoardDrawUtil.FlipX) != 0, !((DrawControl & BezierBoardDrawUtil.FlipY) != 0), + (DrawControl & BezierBoardDrawUtil.Vertical) != 0, false); + paintPath(d, offsetX, offsetY, scale, rotation, color, stroke, path, fill); } } - public static void paintBezierSplines(AbstractDraw d, double offsetX, - - double offsetY, double scale, Color color, Stroke stroke, BezierSpline[] splines, int DrawControl, boolean fill) - { - if(splines == null) + public static void paintBezierSplines(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierSpline[] splines, int DrawControl, + boolean fill) { + if (splines == null) return; - + GeneralPath path = new GeneralPath(); - for(int i = 0; i < splines.length; i++) - { - GeneralPath tmp = makeBezierPathFromControlPoints(splines[i], (DrawControl&BezierBoardDrawUtil.FlipX)!=0, (DrawControl&BezierBoardDrawUtil.FlipY)!=0, (DrawControl&BezierBoardDrawUtil.Vertical)!=0, i%2!=0); + for (int i = 0; i < splines.length; i++) { + GeneralPath tmp = makeBezierPathFromControlPoints(splines[i], (DrawControl & BezierBoardDrawUtil.FlipX) != 0, (DrawControl & BezierBoardDrawUtil.FlipY) != 0, + (DrawControl & BezierBoardDrawUtil.Vertical) != 0, i % 2 != 0); path.append(tmp.getPathIterator(null), true); } - paintPath(d, offsetX, offsetY, 0.0, scale, color, stroke, path, fill); - - if((DrawControl&BezierBoardDrawUtil.MirrorX)!=0) - { + paintPath(d, offsetX, offsetY, scale, 0.0, color, stroke, path, fill); + + if ((DrawControl & BezierBoardDrawUtil.MirrorX) != 0) { path.reset(); - - for(int i = 0; i < splines.length; i++) - { - GeneralPath tmp = makeBezierPathFromControlPoints(splines[i], !((DrawControl&BezierBoardDrawUtil.FlipX)!=0), (DrawControl&BezierBoardDrawUtil.FlipY)!=0, (DrawControl&BezierBoardDrawUtil.Vertical)!=0, i%2!=0); + + for (int i = 0; i < splines.length; i++) { + GeneralPath tmp = makeBezierPathFromControlPoints(splines[i], !((DrawControl & BezierBoardDrawUtil.FlipX) != 0), (DrawControl & BezierBoardDrawUtil.FlipY) != 0, + (DrawControl & BezierBoardDrawUtil.Vertical) != 0, i % 2 != 0); path.append(tmp.getPathIterator(null), true); } - paintPath(d, offsetX, offsetY, 0.0, scale, color, stroke, path, fill); + paintPath(d, offsetX, offsetY, scale, 0.0, color, stroke, path, fill); } - if((DrawControl&BezierBoardDrawUtil.MirrorY)!=0) - { + if ((DrawControl & BezierBoardDrawUtil.MirrorY) != 0) { path.reset(); - for(int i = 0; i < splines.length; i++) - { - GeneralPath tmp = makeBezierPathFromControlPoints(splines[i], (DrawControl&BezierBoardDrawUtil.FlipX)!=0, !((DrawControl&BezierBoardDrawUtil.FlipY)!=0), (DrawControl&BezierBoardDrawUtil.Vertical)!=0, i%2!=0); + for (int i = 0; i < splines.length; i++) { + GeneralPath tmp = makeBezierPathFromControlPoints(splines[i], (DrawControl & BezierBoardDrawUtil.FlipX) != 0, !((DrawControl & BezierBoardDrawUtil.FlipY) != 0), + (DrawControl & BezierBoardDrawUtil.Vertical) != 0, i % 2 != 0); path.append(tmp.getPathIterator(null), true); } - paintPath(d, offsetX, offsetY, 0.0, scale, color, stroke, path, fill); + paintPath(d, offsetX, offsetY, scale, 0.0, color, stroke, path, fill); } } - public static void paintBezierSpline(AbstractDraw d, double offsetX, - - double offsetY, double rotation, double scale, Color color, Stroke stroke, BezierSpline mPoints, int DrawControl, boolean fill) - { - if(mPoints == null) - return; - - d.setColor(color); - - d.setStroke(stroke); - - //DEBUG -//AffineTransform savedTransform = setTransform(d, offsetX, offsetY, rotation, scale); -//d.draw(new Line2D.Double(0,0,0,0)); -//d.setTransform(savedTransform); - - GeneralPath path = makeBezierPathFromControlPoints(mPoints, (DrawControl&BezierBoardDrawUtil.FlipX)!=0, (DrawControl&BezierBoardDrawUtil.FlipY)!=0, (DrawControl&BezierBoardDrawUtil.Vertical)!=0, false); - paintPath(d, offsetX, offsetY, rotation, scale, color, stroke, path, fill); - - if((DrawControl&BezierBoardDrawUtil.MirrorX)!=0) - { - path = makeBezierPathFromControlPoints(mPoints, !((DrawControl&BezierBoardDrawUtil.FlipX)!=0), (DrawControl&BezierBoardDrawUtil.FlipY)!=0, (DrawControl&BezierBoardDrawUtil.Vertical)!=0, false); - paintPath(d, offsetX, offsetY, rotation, scale, color, stroke, path, fill); - } - - if((DrawControl&BezierBoardDrawUtil.MirrorY)!=0) - { - path = makeBezierPathFromControlPoints(mPoints, (DrawControl&BezierBoardDrawUtil.FlipX)!=0, !((DrawControl&BezierBoardDrawUtil.FlipY)!=0), (DrawControl&BezierBoardDrawUtil.Vertical)!=0, false); - paintPath(d, offsetX, offsetY, rotation, scale, color, stroke, path, fill); - } - } - - public static void paintBezierControlPoints(AbstractDraw d, double offsetX, - - double offsetY, double scale, Stroke stroke, BezierSpline mPoints, ArrayList mSelectedControlPoints, boolean flipX, boolean flipY) - { - if(mPoints == null) + public static void paintBezierControlPoints(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Stroke stroke, BezierSpline mPoints, + ArrayList mSelectedControlPoints, boolean flipX, boolean flipY) { + if (mPoints == null) return; double selectedCircleSize = BoardCAD.getInstance().getSelectedControlPointSize(); double unselectedCircleSize = BoardCAD.getInstance().getUnselectedControlPointSize(); - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); - double cpx,cpy,kx,ky,cnx,cny; + double cpx, cpy, kx, ky, cnx, cny; Line2D line = new Line2D.Double(); Ellipse2D circle = new Ellipse2D.Double(); Color selControlPointColor = BoardCAD.getInstance().getSelectedCenterControlPointColor(); - Color selTan1Color = (mSelectedControlPoints != null && mSelectedControlPoints.size() == 1)?BoardCAD.getInstance().getSelectedTangent1ControlPointColor():selControlPointColor; - Color selTan2Color = (mSelectedControlPoints != null && mSelectedControlPoints.size() == 1)?BoardCAD.getInstance().getSelectedTangent2ControlPointColor():selControlPointColor; + Color selTan1Color = (mSelectedControlPoints != null && mSelectedControlPoints.size() == 1) ? BoardCAD.getInstance().getSelectedTangent1ControlPointColor() : selControlPointColor; + Color selTan2Color = (mSelectedControlPoints != null && mSelectedControlPoints.size() == 1) ? BoardCAD.getInstance().getSelectedTangent2ControlPointColor() : selControlPointColor; Color selOutControlPointColor = BoardCAD.getInstance().getSelectedOutlineCenterControlPointColor(); - Color selOutTan1Color = (mSelectedControlPoints != null && mSelectedControlPoints.size() == 1)?BoardCAD.getInstance().getSelectedOutlineTangent1ControlPointColor():selControlPointColor; - Color selOutTan2Color = (mSelectedControlPoints != null && mSelectedControlPoints.size() == 1)?BoardCAD.getInstance().getSelectedOutlineTangent2ControlPointColor():selControlPointColor; + Color selOutTan1Color = (mSelectedControlPoints != null && mSelectedControlPoints.size() == 1) ? BoardCAD.getInstance().getSelectedOutlineTangent1ControlPointColor() : selControlPointColor; + Color selOutTan2Color = (mSelectedControlPoints != null && mSelectedControlPoints.size() == 1) ? BoardCAD.getInstance().getSelectedOutlineTangent2ControlPointColor() : selControlPointColor; Color unselControlPointColor = BoardCAD.getInstance().getUnselectedCenterControlPointColor(); Color unselTan1Color = BoardCAD.getInstance().getUnselectedTangent1ControlPointColor(); @@ -397,429 +307,391 @@ public static void paintBezierControlPoints(AbstractDraw d, double offsetX, boolean isControlPointSelected = false; int whichControlPointSelected = -1; - for(int i = 0; i < mPoints.getNrOfControlPoints(); i++) { + for (int i = 0; i < mPoints.getNrOfControlPoints(); i++) { BezierKnot currentControlPoint = mPoints.getControlPoint(i); isControlPointSelected = mSelectedControlPoints != null && mSelectedControlPoints.contains(currentControlPoint); - if(isControlPointSelected && mSelectedControlPoints.size() == 1 && BoardCAD.getInstance().getCurrentCommand().getClass().getName().compareTo(BrdEditCommand.class.getName())==0) - { - whichControlPointSelected = ((BrdEditCommand)BoardCAD.getInstance().getCurrentCommand()).mWhich; - } - else - { + if (isControlPointSelected && mSelectedControlPoints.size() == 1 && BoardCAD.getInstance().getCurrentCommand().getClass().getName().compareTo(BrdEditCommand.class.getName()) == 0) { + whichControlPointSelected = ((BrdEditCommand) BoardCAD.getInstance().getCurrentCommand()).getWhich(); + } else { whichControlPointSelected = -1; } - -// ControlPoint + + // ControlPoint kx = currentControlPoint.getEndPoint().x; ky = currentControlPoint.getEndPoint().y; -// control to previous + // control to previous cpx = currentControlPoint.getTangentToPrev().x; cpy = currentControlPoint.getTangentToPrev().y; -// next control point + // next control point cnx = currentControlPoint.getTangentToNext().x; cny = currentControlPoint.getTangentToNext().y; -// ControlPoint + // ControlPoint d.setStroke(stroke); - if(whichControlPointSelected==0 || (mSelectedControlPoints != null && mSelectedControlPoints.size() > 1 && mSelectedControlPoints.contains(currentControlPoint))) - { - circle.setFrameFromCenter(kx*mulX, ky*mulY, (kx*mulX)+(selectedCircleSize/scale), (ky*mulY)+(selectedCircleSize/scale)); + if (whichControlPointSelected == 0 || (mSelectedControlPoints != null && mSelectedControlPoints.size() > 1 && mSelectedControlPoints.contains(currentControlPoint))) { + circle.setFrameFromCenter(kx * mulX, ky * mulY, (kx * mulX) + (selectedCircleSize / scale), (ky * mulY) + (selectedCircleSize / scale)); d.setColor(selControlPointColor); d.fill(circle); d.setColor(selOutControlPointColor); - d.draw(circle); - } - else - { - circle.setFrameFromCenter(kx*mulX, ky*mulY, (kx*mulX)+(unselectedCircleSize/scale), (ky*mulY)+(unselectedCircleSize/scale)); + d.draw(circle); + } else { + circle.setFrameFromCenter(kx * mulX, ky * mulY, (kx * mulX) + (unselectedCircleSize / scale), (ky * mulY) + (unselectedCircleSize / scale)); d.setColor(unselControlPointColor); d.fill(circle); d.setColor(unselOutControlPointColor); - d.draw(circle); + d.draw(circle); } - // Previous - if(i !=0) - { - d.setColor(isControlPointSelected?selectedTangentColor:unselectedTangentColor); + // Previous + if (i != 0) { + d.setColor(isControlPointSelected ? selectedTangentColor : unselectedTangentColor); d.setStroke(stroke); - line.setLine(cpx*mulX, cpy*mulY, kx*mulX, ky*mulY); + line.setLine(cpx * mulX, cpy * mulY, kx * mulX, ky * mulY); d.draw(line); - if(whichControlPointSelected==1) - { - circle.setFrameFromCenter(cpx*mulX, cpy*mulY, (cpx*mulX)+(selectedCircleSize/scale), (cpy*mulY)+(selectedCircleSize/scale)); + if (whichControlPointSelected == 1) { + circle.setFrameFromCenter(cpx * mulX, cpy * mulY, (cpx * mulX) + (selectedCircleSize / scale), (cpy * mulY) + (selectedCircleSize / scale)); d.setColor(selTan1Color); d.fill(circle); d.setColor(selOutTan1Color); - d.draw(circle); - } - else - { - circle.setFrameFromCenter(cpx*mulX, cpy*mulY, (cpx*mulX)+(unselectedCircleSize/scale), (cpy*mulY)+(unselectedCircleSize/scale)); + d.draw(circle); + } else { + circle.setFrameFromCenter(cpx * mulX, cpy * mulY, (cpx * mulX) + (unselectedCircleSize / scale), (cpy * mulY) + (unselectedCircleSize / scale)); d.setColor(unselTan1Color); d.fill(circle); d.setColor(unselOutTan1Color); - d.draw(circle); + d.draw(circle); } } - if(i != mPoints.getNrOfControlPoints()-1) - { - d.setColor(isControlPointSelected?selectedTangentColor:unselectedTangentColor); + if (i != mPoints.getNrOfControlPoints() - 1) { + d.setColor(isControlPointSelected ? selectedTangentColor : unselectedTangentColor); d.setStroke(stroke); - line.setLine(kx*mulX, ky*mulY, cnx*mulX, cny*mulY); + line.setLine(kx * mulX, ky * mulY, cnx * mulX, cny * mulY); d.draw(line); - if(whichControlPointSelected==2) - { - circle.setFrameFromCenter(cnx*mulX, cny*mulY, (cnx*mulX)+(selectedCircleSize/scale), (cny*mulY)+(selectedCircleSize/scale)); + if (whichControlPointSelected == 2) { + circle.setFrameFromCenter(cnx * mulX, cny * mulY, (cnx * mulX) + (selectedCircleSize / scale), (cny * mulY) + (selectedCircleSize / scale)); d.setColor(selTan2Color); d.fill(circle); d.setColor(selOutTan2Color); - d.draw(circle); - } - else - { - circle.setFrameFromCenter(cnx*mulX, cny*mulY, (cnx*mulX)+(unselectedCircleSize/scale), (cny*mulY)+(unselectedCircleSize/scale)); + d.draw(circle); + } else { + circle.setFrameFromCenter(cnx * mulX, cny * mulY, (cnx * mulX) + (unselectedCircleSize / scale), (cny * mulY) + (unselectedCircleSize / scale)); d.setColor(unselTan2Color); d.fill(circle); d.setColor(unselOutTan2Color); - d.draw(circle); + d.draw(circle); } } } - - d.setTransform(savedTransform); + resetTransform(d, savedTransform); } - public static void paintBezierControlPoints(AbstractDraw d, double offsetX, - - double offsetY, double scale, Stroke stroke, BezierSpline[] splines, ArrayList mSelectedControlPoints, boolean flipX, boolean flipY) - { - if(splines == null) + public static void paintBezierControlPoints(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Stroke stroke, BezierSpline[] splines, + ArrayList mSelectedControlPoints, boolean flipX, boolean flipY) { + if (splines == null) return; - - for(int i = 0; i < splines.length; i++) - { - paintBezierControlPoints( d, offsetX, offsetY, scale, stroke, splines[i], mSelectedControlPoints, flipX, flipY); + + for (int i = 0; i < splines.length; i++) { + paintBezierControlPoints(d, offsetX, offsetY, scale, rotation, stroke, splines[i], mSelectedControlPoints, flipX, flipY); } - - } - public static void paintGuidePoints(AbstractDraw d, double offsetX, + } - double offsetY, double scale, Color color, Stroke stroke, ArrayList guidePoints, boolean flipX, boolean flipY) - { + public static void paintGuidePoints(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, ArrayList guidePoints, + boolean flipX, boolean flipY) { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale, rotation); d.setColor(BoardCAD.getInstance().getGuidePointColor()); - d.setStroke(new BasicStroke((float)(BoardCAD.getInstance().getGuidePointThickness()/scale))); + d.setStroke(new BasicStroke((float) (BoardCAD.getInstance().getGuidePointThickness() / scale))); - double crossSize = 4.0f/scale; + double crossSize = 4.0f / scale; - double mulX = (flipX?-1.0:1.0); - double mulY = (flipY?-1.0:1.0); + double mulX = (flipX ? -1.0 : 1.0); + double mulY = (flipY ? -1.0 : 1.0); Line2D.Double line = new Line2D.Double(); - Point2D.Double pos = new Point2D.Double();; - for(int i = 0; i < guidePoints.size(); i++) - { + Point2D.Double pos = new Point2D.Double(); + ; + for (int i = 0; i < guidePoints.size(); i++) { pos.setLocation(guidePoints.get(i)); - line.setLine((pos.x-crossSize)*mulX, (pos.y)*mulY, (pos.x+crossSize)*mulX, (pos.y)*mulY); + line.setLine((pos.x - crossSize) * mulX, (pos.y) * mulY, (pos.x + crossSize) * mulX, (pos.y) * mulY); d.draw(line); - line.setLine((pos.x)*mulX, (pos.y-crossSize)*mulY, (pos.x)*mulX, (pos.y+crossSize)*mulY); + line.setLine((pos.x) * mulX, (pos.y - crossSize) * mulY, (pos.x) * mulX, (pos.y + crossSize) * mulY); d.draw(line); } - d.setTransform(savedTransform); + resetTransform(d, savedTransform); } - public static void paintFins(AbstractDraw d, double offsetX, + public static void paintFins(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, double[] finCoords, boolean flipX, boolean flipY) { + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale, rotation); - double offsetY, double scale, Color color, Stroke stroke, double[] finCoords, boolean flipX, boolean flipY) - { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); - - double mulX = (flipX)?-1:1; - double mulY = (flipY)?-1:1; + double mulX = (flipX) ? -1 : 1; + double mulY = (flipY) ? -1 : 1; d.setColor(color); d.setStroke(stroke); -// x, y for back of fin, x,y for front of fin, bac of center, front of center, depth of center, depth of sidefin, splay angle + // x, y for back of fin, x,y for front of fin, bac of center, front of + // center, depth of center, depth of sidefin, splay angle final Line2D tmp = new Line2D.Double(); - tmp.setLine(finCoords[0]*mulX,finCoords[1]*mulY,finCoords[2]*mulX,finCoords[3]*mulY); + tmp.setLine(finCoords[0] * mulX, finCoords[1] * mulY, finCoords[2] * mulX, finCoords[3] * mulY); d.draw(tmp); - tmp.setLine(finCoords[0]*mulX,-finCoords[1]*mulY,finCoords[2]*mulX,-finCoords[3]*mulY); + tmp.setLine(finCoords[0] * mulX, -finCoords[1] * mulY, finCoords[2] * mulX, -finCoords[3] * mulY); d.draw(tmp); - tmp.setLine(finCoords[5]*mulX,0,finCoords[4]*mulX,0); + tmp.setLine(finCoords[5] * mulX, 0, finCoords[4] * mulX, 0); d.draw(tmp); - d.setTransform(savedTransform); + resetTransform(d, savedTransform); } public static void paintCircle(AbstractDraw d, double offsetX, - double offsetY, double scale, Color color, Stroke stroke, Point2D.Double pos, boolean flipX, boolean flipY) - { + double offsetY, double scale, double rotation, Color color, Stroke stroke, Point2D.Double pos, boolean flipX, boolean flipY) { double circleSize = 3.0; - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); Ellipse2D circle = new Ellipse2D.Double(); d.setColor(color); d.setStroke(stroke); - circle.setFrameFromCenter(pos.x*mulX, pos.y*mulY, (pos.x*mulX)+(circleSize/scale), (pos.y*mulY)+(circleSize/scale)); + circle.setFrameFromCenter(pos.x * mulX, pos.y * mulY, (pos.x * mulX) + (circleSize / scale), (pos.y * mulY) + (circleSize / scale)); d.draw(circle); - d.setTransform(savedTransform); + resetTransform(d, savedTransform); } - public static void paintGrid(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, double verticalToCover, double horizontalToCover, boolean flipX, boolean flipY) - { + public static void paintGrid(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, double verticalToCover, double horizontalToCover, boolean flipX, + boolean flipY) { - switch(UnitUtils.getCurrentUnit()) - { + switch (UnitUtils.getCurrentUnit()) { case UnitUtils.CENTIMETERS: case UnitUtils.MILLIMETERS: - paintGridMetric(d, offsetX, offsetY, scale, color, verticalToCover, horizontalToCover, flipX, flipY); + paintGridMetric(d, offsetX, offsetY, scale, rotation, color, verticalToCover, horizontalToCover, flipX, flipY); break; case UnitUtils.INCHES: case UnitUtils.INCHES_DECIMAL: - paintGridImperial(d, offsetX, offsetY, scale, color, verticalToCover, horizontalToCover, flipX, flipY); + paintGridImperial(d, offsetX, offsetY, scale, rotation, color, verticalToCover, horizontalToCover, flipX, flipY); break; } } - private static void paintGridMetric(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, double verticalToCover, double horizontalToCover, boolean flipX, boolean flipY) - { + private static void paintGridMetric(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, double verticalToCover, double horizontalToCover, boolean flipX, + boolean flipY) { - int verticalLines = (int)verticalToCover + 1; - verticalLines += 10 - verticalLines%10; - int horizontalLines = (int)horizontalToCover + 1; - horizontalLines += 10 - horizontalLines%10; + int verticalLines = (int) verticalToCover + 1; + verticalLines += 10 - verticalLines % 10; + int horizontalLines = (int) horizontalToCover + 1; + horizontalLines += 10 - horizontalLines % 10; - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); Line2D line = new Line2D.Double(); - for(int i = 0; i < verticalLines+1; i++) - { + for (int i = 0; i < verticalLines + 1; i++) { setMetricGridLineStrokeAndColor(d, color, i, scale); - line.setLine(i*1.0*mulX, 0*mulY, i*1.0*mulX, horizontalLines*1.0*mulY); + line.setLine(i * 1.0 * mulX, 0 * mulY, i * 1.0 * mulX, horizontalLines * 1.0 * mulY); d.draw(line); } - for(int i = 0; i < horizontalLines+1; i++) - { + for (int i = 0; i < horizontalLines + 1; i++) { setMetricGridLineStrokeAndColor(d, color, i, scale); - line.setLine(0*mulX, i*1.0*mulY, verticalLines*1.0*mulX, i*1.0*mulY); + line.setLine(0 * mulX, i * 1.0 * mulY, verticalLines * 1.0 * mulX, i * 1.0 * mulY); d.draw(line); } - d.setTransform(savedTransform); + resetTransform(d, savedTransform); } - private static void paintGridImperial(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, double verticalToCover, double horizontalToCover, boolean flipX, boolean flipY) { + private static void paintGridImperial(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, double verticalToCover, double horizontalToCover, boolean flipX, + boolean flipY) { - int verticalLines = (int)(verticalToCover/UnitUtils.INCH) + 1; - verticalLines += 6 - verticalLines%6; - int horizontalLines = (int)(horizontalToCover/UnitUtils.INCH) + 1; - horizontalLines += 6 - horizontalLines%6; + int verticalLines = (int) (verticalToCover / UnitUtils.INCH) + 1; + verticalLines += 6 - verticalLines % 6; + int horizontalLines = (int) (horizontalToCover / UnitUtils.INCH) + 1; + horizontalLines += 6 - horizontalLines % 6; - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); Line2D line = new Line2D.Double(); - for(int i = 0; i < verticalLines+1; i++) - { + for (int i = 0; i < verticalLines + 1; i++) { setImperialGridLineStrokeAndColor(d, color, i, scale); - line.setLine(i*2.54*mulX, 0*mulY, i*2.54*mulX, horizontalLines*2.54*mulY); + line.setLine(i * 2.54 * mulX, 0 * mulY, i * 2.54 * mulX, horizontalLines * 2.54 * mulY); d.draw(line); } - for(int i = 0; i < horizontalLines+1; i++) - { + for (int i = 0; i < horizontalLines + 1; i++) { setImperialGridLineStrokeAndColor(d, color, i, scale); - line.setLine(0*mulX, i*2.54*mulY, verticalLines*2.54*mulX, i*2.54*mulY); + line.setLine(0 * mulX, i * 2.54 * mulY, verticalLines * 2.54 * mulX, i * 2.54 * mulY); d.draw(line); } - d.setTransform(savedTransform); + resetTransform(d, savedTransform); } - public static void paintCurvature(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierSpline bezierSpline, boolean flipX, boolean flipY, double curvature_scale) - { - if(bezierSpline == null) + public static void paintCurvature(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierSpline bezierSpline, boolean flipX, + boolean flipY, double curvature_scale) { + if (bezierSpline == null) return; d.setColor(color); d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); - for(int i = 0; i < bezierSpline.getNrOfCurves(); i++) - { - paintCurvatureByT(d, bezierSpline.getCurve(i), 0,1, flipX, flipY, curvature_scale); + for (int i = 0; i < bezierSpline.getNrOfCurves(); i++) { + paintCurvatureByT(d, bezierSpline.getCurve(i), 0, 1, flipX, flipY, curvature_scale); } + // paintCurvatureByPos( 0,bezierPath.getMaxX(), flipX, + // flipY,curvature_scale); - -// paintCurvatureByPos( 0,bezierPath.getMaxX(), flipX, flipY,curvature_scale); - - - resetTransform(d,savedTransform); + resetTransform(d, savedTransform); } - public static void paintCurvature(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierSpline[] splines, boolean flipX, boolean flipY, double curvature_scale) - { - if(splines == null) + public static void paintCurvature(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierSpline[] splines, boolean flipX, boolean flipY, + double curvature_scale) { + if (splines == null) return; - - for(int i = 0; i < splines.length; i++) - { - paintCurvature(d, offsetX, offsetY, scale, color, stroke, splines[i], flipX, flipY, curvature_scale) ; + + for (int i = 0; i < splines.length; i++) { + paintCurvature(d, offsetX, offsetY, scale, rotation, color, stroke, splines[i], flipX, flipY, curvature_scale); } - + } - - public static void paintVolumeDistribution(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY, double graph_scale) - { - if(brd == null) + public static void paintVolumeDistribution(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipX, + boolean flipY, double graph_scale) { + if (brd == null) return; - - if(brd.isEmpty()) + + if (brd.isEmpty()) return; d.setColor(color); d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; int segments = 20; - double step = brd.getLength()/segments; + double step = brd.getLength() / segments; double lastVol = brd.getCrossSectionAreaAt(0, 8); - for(int i = 1; i <= segments; i++) - { - double currentVol = brd.getCrossSectionAreaAt(i*step, 8); + for (int i = 1; i <= segments; i++) { + double currentVol = brd.getCrossSectionAreaAt(i * step, 8); - ls.setLine((i-1)*step*mulX, lastVol*mulY*graph_scale, i*step*mulX, currentVol*mulY*graph_scale); + ls.setLine((i - 1) * step * mulX, lastVol * mulY * graph_scale, i * step * mulX, currentVol * mulY * graph_scale); d.draw(ls); - + lastVol = currentVol; } - - resetTransform(d,savedTransform); + resetTransform(d, savedTransform); } - - public static void paintOutlineFlowLines(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) - { - if(brd == null) + + public static void paintOutlineFlowLines(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) { + if (brd == null) return; - - if(brd.isEmpty()) + + if (brd.isEmpty()) return; d.setColor(color); d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; int segments = 10; - + GeneralPath path = new GeneralPath(); - for(int j = 0; j < 3; j++) - { + for (int j = 0; j < 3; j++) { d.setColor(color); path.reset(); double angle = 10.0; - if(j == 1) + if (j == 1) angle = 27.5; - else if(j == 2) + else if (j == 2) angle = 45.0; - - Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1,1); - if(pos == null) + + Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1, 1); + if (pos == null) continue; - - path.moveTo(pos.x*mulX, pos.y*mulY); + + path.moveTo(pos.x * mulX, pos.y * mulY); ArrayList crossSections = brd.getCrossSections(); - for(int i = 0; i < crossSections.size(); i++) - { - double previousCrsPos = (i==0)?0.0:crossSections.get(i-1).getPosition(); + for (int i = 0; i < crossSections.size(); i++) { + double previousCrsPos = (i == 0) ? 0.0 : crossSections.get(i - 1).getPosition(); double currentCrsPos = crossSections.get(i).getPosition(); - - double step = (currentCrsPos-previousCrsPos)/segments; - for(int k = 1; k <= segments; k++) - { - pos = brd.getSurfacePoint(previousCrsPos+(k*step), -45.0, angle, 1,1); - - path.lineTo(pos.x*mulX, pos.y*mulY); + + double step = (currentCrsPos - previousCrsPos) / segments; + for (int k = 1; k <= segments; k++) { + pos = brd.getSurfacePoint(previousCrsPos + (k * step), -45.0, angle, 1, 1); + + path.lineTo(pos.x * mulX, pos.y * mulY); } } d.draw(path); - + color = color.brighter(); } - - resetTransform(d,savedTransform); + + resetTransform(d, savedTransform); } - public static void paintOutlineTuckUnderLine(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) - { - if(brd == null) + public static void paintOutlineTuckUnderLine(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipX, + boolean flipY) { + if (brd == null) return; - - if(brd.isEmpty()) + + if (brd.isEmpty()) return; d.setColor(color); d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; int segments = 1000; - + GeneralPath path = new GeneralPath(); d.setColor(color); @@ -827,225 +699,205 @@ public static void paintOutlineTuckUnderLine(AbstractDraw d, double offsetX, dou double angle = 175.0; mulY = -mulY; - - Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1,1); - if(pos == null) - return; - - path.moveTo(pos.x*mulX, pos.y*mulY); - ArrayList crossSections = brd.getCrossSections(); - for(int i = 0; i < crossSections.size(); i++) - { - double previousCrsPos = (i==0)?0.0:crossSections.get(i-1).getPosition(); - double currentCrsPos = crossSections.get(i).getPosition(); - - double step = (currentCrsPos-previousCrsPos)/segments; - for(int k = 1; k <= segments; k++) - { - pos = brd.getSurfacePoint(previousCrsPos+(k*step), -45.0, angle, 1,1); - if(pos == null) - return; - - path.lineTo(pos.x*mulX, pos.y*mulY); + + Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1, 1); + if (pos != null) { + + path.moveTo(pos.x * mulX, pos.y * mulY); + ArrayList crossSections = brd.getCrossSections(); + for (int i = 0; i < crossSections.size(); i++) { + double previousCrsPos = (i == 0) ? 0.0 : crossSections.get(i - 1).getPosition(); + double currentCrsPos = crossSections.get(i).getPosition(); + + double step = (currentCrsPos - previousCrsPos) / segments; + for (int k = 1; k <= segments; k++) { + pos = brd.getSurfacePoint(previousCrsPos + (k * step), -45.0, angle, 1, 1); + if (pos == null) { + resetTransform(d, savedTransform); + return; + } + + path.lineTo(pos.x * mulX, pos.y * mulY); + } } + d.draw(path); } - d.draw(path); - - resetTransform(d,savedTransform); + + resetTransform(d, savedTransform); } - public static void paintProfileFlowLines(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) - { - if(brd == null) + public static void paintProfileFlowLines(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) { + if (brd == null) return; - - if(brd.isEmpty()) + + if (brd.isEmpty()) return; d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; int segments = 10; - + GeneralPath path = new GeneralPath(); - for(int j = 0; j < 3; j++) - { + for (int j = 0; j < 3; j++) { d.setColor(color); path.reset(); double angle = 10.0; - if(j == 1) + if (j == 1) angle = 27.5; - else if(j == 2) + else if (j == 2) angle = 45.0; - - Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1,1); - if(pos == null) + + Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1, 1); + if (pos == null) continue; - - path.moveTo(pos.x*mulX, pos.z*mulY); + + path.moveTo(pos.x * mulX, pos.z * mulY); ArrayList crossSections = brd.getCrossSections(); - for(int i = 0; i < crossSections.size(); i++) - { - double previousCrsPos = (i==0)?0.0:crossSections.get(i-1).getPosition(); + for (int i = 0; i < crossSections.size(); i++) { + double previousCrsPos = (i == 0) ? 0.0 : crossSections.get(i - 1).getPosition(); double currentCrsPos = crossSections.get(i).getPosition(); - - double step = (currentCrsPos-previousCrsPos)/segments; - for(int k = 1; k <= segments; k++) - { - pos = brd.getSurfacePoint(previousCrsPos+(k*step), -45.0, angle, 1,1); - - path.lineTo(pos.x*mulX, pos.z*mulY); + + double step = (currentCrsPos - previousCrsPos) / segments; + for (int k = 1; k <= segments; k++) { + pos = brd.getSurfacePoint(previousCrsPos + (k * step), -45.0, angle, 1, 1); + + path.lineTo(pos.x * mulX, pos.z * mulY); } } d.draw(path); color = color.brighter(); } - - resetTransform(d,savedTransform); + + resetTransform(d, savedTransform); } - public static void paintProfileApexline(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) - { - paintProfileApexLine(d, offsetX, offsetY, 0.0, scale, color, stroke, brd, flipX, flipY); + public static void paintProfileApexline(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) { + paintProfileApexLine(d, offsetX, offsetY, scale, rotation, color, stroke, brd, flipX, flipY); } - public static void paintProfileApexLine(AbstractDraw d, double offsetX, double offsetY, double rotation, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) - { - if(brd == null) + public static void paintProfileApexLine(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) { + if (brd == null) return; - - if(brd.isEmpty()) + + if (brd.isEmpty()) return; d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, rotation, scale); - - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; int segments = 10; - + GeneralPath path = new GeneralPath(); d.setColor(color); - double angle = APEX_DEFINITION_ANGLE; - - Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1,1); - - path.moveTo(pos.x*mulX, pos.z*mulY); + double angle = APEX_DEFINITION_ANGLE; + + Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1, 1); + + path.moveTo(pos.x * mulX, pos.z * mulY); ArrayList crossSections = brd.getCrossSections(); - for(int i = 0; i < crossSections.size(); i++) - { - double previousCrsPos = (i==0)?0.0:crossSections.get(i-1).getPosition(); + for (int i = 0; i < crossSections.size(); i++) { + double previousCrsPos = (i == 0) ? 0.0 : crossSections.get(i - 1).getPosition(); double currentCrsPos = crossSections.get(i).getPosition(); - - double step = (currentCrsPos-previousCrsPos)/segments; - for(int k = 1; k <= segments; k++) - { - pos = brd.getSurfacePoint(previousCrsPos+(k*step), -45.0, angle, 1,1); - - path.lineTo(pos.x*mulX, pos.z*mulY); + + double step = (currentCrsPos - previousCrsPos) / segments; + for (int k = 1; k <= segments; k++) { + pos = brd.getSurfacePoint(previousCrsPos + (k * step), -45.0, angle, 1, 1); + + path.lineTo(pos.x * mulX, pos.z * mulY); } } d.draw(path); - - resetTransform(d,savedTransform); - } - public static void paintProfileTuckUnderLine(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) - { - paintProfileTuckUnderLine(d, offsetX, offsetY, 0.0, scale, color, stroke, brd, flipX, flipY) ; + resetTransform(d, savedTransform); } - - public static void paintProfileTuckUnderLine(AbstractDraw d, double offsetX, double offsetY, double rotation, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipX, boolean flipY) - { - if(brd == null) + + public static void paintProfileTuckUnderLine(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipX, + boolean flipY) { + if (brd == null) return; - - if(brd.isEmpty()) + + if (brd.isEmpty()) return; d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, rotation, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; int segments = 10; - + GeneralPath path = new GeneralPath(); d.setColor(color); - double angle = TUCK_UNDER_DEFINITION_ANGLE; - - Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1,1); - - path.moveTo(pos.x*mulX, pos.z*mulY); + double angle = TUCK_UNDER_DEFINITION_ANGLE; + + Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1, 1); + + path.moveTo(pos.x * mulX, pos.z * mulY); ArrayList crossSections = brd.getCrossSections(); - for(int i = 0; i < crossSections.size(); i++) - { - double previousCrsPos = (i==0)?0.0:crossSections.get(i-1).getPosition(); + for (int i = 0; i < crossSections.size(); i++) { + double previousCrsPos = (i == 0) ? 0.0 : crossSections.get(i - 1).getPosition(); double currentCrsPos = crossSections.get(i).getPosition(); - - double step = (currentCrsPos-previousCrsPos)/segments; - for(int k = 1; k <= segments; k++) - { - pos = brd.getSurfacePoint(previousCrsPos+(k*step), -45.0, angle, 1,1); - - path.lineTo(pos.x*mulX, pos.z*mulY); + + double step = (currentCrsPos - previousCrsPos) / segments; + for (int k = 1; k <= segments; k++) { + pos = brd.getSurfacePoint(previousCrsPos + (k * step), -45.0, angle, 1, 1); + + path.lineTo(pos.x * mulX, pos.z * mulY); } } d.draw(path); - - resetTransform(d,savedTransform); - } + resetTransform(d, savedTransform); + } - public static void paintCrossSectionCenterline(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipY, boolean flattenRocker) - { - if(brd == null) + public static void paintCrossSectionCenterline(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipY, + boolean flattenRocker) { + if (brd == null) return; - - if(brd.isEmpty()) + + if (brd.isEmpty()) return; d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - - double mulY = flipY?-1:1; - int segments = 10; + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + double mulY = flipY ? -1 : 1; + int segments = 10; GeneralPath pathDeck = new GeneralPath(); GeneralPath pathBottom = new GeneralPath(); - + d.setColor(color); - + Point2D.Double deckPos = new Point2D.Double(0.01, brd.getDeck().getValueAt(0.01)); Point2D.Double bottomPos = new Point2D.Double(0.01, brd.getBottom().getValueAt(0.01)); - - if(flattenRocker) - { + + if (flattenRocker) { deckPos.y -= bottomPos.y; bottomPos.y = 0.0; } - + pathDeck.moveTo(0, deckPos.y); pathBottom.moveTo(0, bottomPos.y); ArrayList crossSections = brd.getCrossSections(); - for(int i = 0; i <= 20; i++) - { - double x = brd.getLength()/20*i; + for (int i = 0; i <= 20; i++) { + double x = brd.getLength() / 20 * i; deckPos = new Point2D.Double(x, brd.getDeck().getValueAt(0.01)); bottomPos = new Point2D.Double(x, brd.getBottom().getValueAt(0.01)); - - if(flattenRocker) - { + + if (flattenRocker) { deckPos.y -= bottomPos.y; bottomPos.y = 0.0; } @@ -1055,216 +907,200 @@ public static void paintCrossSectionCenterline(AbstractDraw d, double offsetX, d } d.draw(pathDeck); d.draw(pathBottom); - - resetTransform(d,savedTransform); + + resetTransform(d, savedTransform); } - public static void paintCrossSectionFlowLines(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipY, boolean flattenRocker) - { - if(brd == null) + public static void paintCrossSectionFlowLines(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipY, + boolean flattenRocker) { + if (brd == null) return; - - if(brd.isEmpty()) + + if (brd.isEmpty()) return; d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); - double mulY = flipY?-1:1; + double mulY = flipY ? -1 : 1; int segments = 10; - GeneralPath pathLeft = new GeneralPath(); GeneralPath pathRight = new GeneralPath(); - - for(int j = 0; j < 3; j++) - { + + for (int j = 0; j < 3; j++) { d.setColor(color); pathLeft.reset(); pathRight.reset(); double angle = 10.0; - if(j == 1) + if (j == 1) angle = 27.5; - else if(j == 2) + else if (j == 2) angle = 45.0; - - Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1,1); - if(pos == null) + + Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1, 1); + if (pos == null) continue; - - if(flattenRocker) - { + + if (flattenRocker) { double rocker = brd.getRockerAtPos(pos.x); pos.z -= rocker; } - - pathLeft.moveTo(pos.y*-1.0, pos.z*mulY); - pathRight.moveTo(pos.y, pos.z*mulY); + + pathLeft.moveTo(pos.y * -1.0, pos.z * mulY); + pathRight.moveTo(pos.y, pos.z * mulY); ArrayList crossSections = brd.getCrossSections(); - for(int i = 0; i < crossSections.size(); i++) - { - double previousCrsPos = (i==0)?0.0:crossSections.get(i-1).getPosition(); + for (int i = 0; i < crossSections.size(); i++) { + double previousCrsPos = (i == 0) ? 0.0 : crossSections.get(i - 1).getPosition(); double currentCrsPos = crossSections.get(i).getPosition(); - - double step = (currentCrsPos-previousCrsPos)/segments; - for(int k = 1; k <= segments; k++) - { - pos = brd.getSurfacePoint(previousCrsPos+(k*step), -45.0, angle, 1,1); - - if(flattenRocker) - { + + double step = (currentCrsPos - previousCrsPos) / segments; + for (int k = 1; k <= segments; k++) { + pos = brd.getSurfacePoint(previousCrsPos + (k * step), -45.0, angle, 1, 1); + + if (flattenRocker) { double rocker = brd.getRockerAtPos(pos.x); pos.z -= rocker; } - pathLeft.lineTo(pos.y*-1.0, pos.z*mulY); - pathRight.lineTo(pos.y, pos.z*mulY); + pathLeft.lineTo(pos.y * -1.0, pos.z * mulY); + pathRight.lineTo(pos.y, pos.z * mulY); } } d.draw(pathLeft); d.draw(pathRight); color = color.brighter(); } - - resetTransform(d,savedTransform); + + resetTransform(d, savedTransform); } - public static void paintCrossSectionApexline(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipY, boolean flattenRocker) - { - if(brd == null) + public static void paintCrossSectionApexline(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipY, + boolean flattenRocker) { + if (brd == null) return; - - if(brd.isEmpty()) + + if (brd.isEmpty()) return; d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); - double mulY = flipY?-1:1; + double mulY = flipY ? -1 : 1; int segments = 10; - GeneralPath pathLeft = new GeneralPath(); GeneralPath pathRight = new GeneralPath(); - + d.setColor(color); pathLeft.reset(); pathRight.reset(); double angle = 88.0; - - Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1,1); - if(pos == null) + + Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1, 1); + if (pos == null) return; - - if(flattenRocker) - { + + if (flattenRocker) { double rocker = brd.getRockerAtPos(pos.x); pos.z -= rocker; } - - pathLeft.moveTo(pos.y*-1.0, pos.z*mulY); - pathRight.moveTo(pos.y, pos.z*mulY); + + pathLeft.moveTo(pos.y * -1.0, pos.z * mulY); + pathRight.moveTo(pos.y, pos.z * mulY); ArrayList crossSections = brd.getCrossSections(); - for(int i = 0; i < crossSections.size(); i++) - { - double previousCrsPos = (i==0)?0.0:crossSections.get(i-1).getPosition(); + for (int i = 0; i < crossSections.size(); i++) { + double previousCrsPos = (i == 0) ? 0.0 : crossSections.get(i - 1).getPosition(); double currentCrsPos = crossSections.get(i).getPosition(); - - double step = (currentCrsPos-previousCrsPos)/segments; - for(int k = 1; k <= segments; k++) - { - pos = brd.getSurfacePoint(previousCrsPos+(k*step), -45.0, angle, 1,1); - - if(flattenRocker) - { + + double step = (currentCrsPos - previousCrsPos) / segments; + for (int k = 1; k <= segments; k++) { + pos = brd.getSurfacePoint(previousCrsPos + (k * step), -45.0, angle, 1, 1); + + if (flattenRocker) { double rocker = brd.getRockerAtPos(pos.x); pos.z -= rocker; } - pathLeft.lineTo(pos.y*-1.0, pos.z*mulY); - pathRight.lineTo(pos.y, pos.z*mulY); + pathLeft.lineTo(pos.y * -1.0, pos.z * mulY); + pathRight.lineTo(pos.y, pos.z * mulY); } } d.draw(pathLeft); d.draw(pathRight); color = color.brighter(); - - resetTransform(d,savedTransform); + + resetTransform(d, savedTransform); } - public static void paintCrossSectionTuckUnderLine(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierBoard brd, boolean flipY, boolean flattenRocker) - { - if(brd == null) + public static void paintCrossSectionTuckUnderLine(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierBoard brd, boolean flipY, + boolean flattenRocker) { + if (brd == null) return; - - if(brd.isEmpty()) + + if (brd.isEmpty()) return; d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - - double mulY = flipY?-1:1; + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + + double mulY = flipY ? -1 : 1; int segments = 10; - + GeneralPath pathLeft = new GeneralPath(); GeneralPath pathRight = new GeneralPath(); d.setColor(color); - double angle = TUCK_UNDER_DEFINITION_ANGLE; - - Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1,1); - - if(flattenRocker) - { + double angle = TUCK_UNDER_DEFINITION_ANGLE; + + Point3d pos = brd.getSurfacePoint(0.01, -45.0, angle, 1, 1); + + if (flattenRocker) { double rocker = brd.getRockerAtPos(pos.x); pos.z -= rocker; } - pathLeft.moveTo(pos.y*-1.0, pos.z*mulY); - pathRight.moveTo(pos.y, pos.z*mulY); + pathLeft.moveTo(pos.y * -1.0, pos.z * mulY); + pathRight.moveTo(pos.y, pos.z * mulY); ArrayList crossSections = brd.getCrossSections(); - for(int i = 0; i < crossSections.size(); i++) - { - double previousCrsPos = (i==0)?0.0:crossSections.get(i-1).getPosition(); + for (int i = 0; i < crossSections.size(); i++) { + double previousCrsPos = (i == 0) ? 0.0 : crossSections.get(i - 1).getPosition(); double currentCrsPos = crossSections.get(i).getPosition(); - - double step = (currentCrsPos-previousCrsPos)/segments; - for(int k = 1; k <= segments; k++) - { - pos = brd.getSurfacePoint(previousCrsPos+(k*step), -45.0, angle, 1,1); - - if(flattenRocker) - { + + double step = (currentCrsPos - previousCrsPos) / segments; + for (int k = 1; k <= segments; k++) { + pos = brd.getSurfacePoint(previousCrsPos + (k * step), -45.0, angle, 1, 1); + + if (flattenRocker) { double rocker = brd.getRockerAtPos(pos.x); pos.z -= rocker; } - pathLeft.lineTo(pos.y*-1.0, pos.z*mulY); - pathRight.lineTo(pos.y, pos.z*mulY); + pathLeft.lineTo(pos.y * -1.0, pos.z * mulY); + pathRight.lineTo(pos.y, pos.z * mulY); } } d.draw(pathLeft); d.draw(pathRight); - - resetTransform(d,savedTransform); + + resetTransform(d, savedTransform); } - static void paintCurvatureByT(AbstractDraw d, BezierCurve curve, double t0, double t1, boolean flipX, boolean flipY, double scale) - { + static void paintCurvatureByT(AbstractDraw d, BezierCurve curve, double t0, double t1, boolean flipX, boolean flipY, double scale) { -// Get t split point - double ts = (t1-t0)/2 + t0; + // Get t split point + double ts = (t1 - t0) / 2 + t0; - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; -// Get endpoints + // Get endpoints double x0 = curve.getXValue(t0); double y0 = curve.getCurvature(t0); double x1 = curve.getXValue(t1); @@ -1273,112 +1109,99 @@ static void paintCurvatureByT(AbstractDraw d, BezierCurve curve, double t0, doub double xs = curve.getXValue(ts); double ys = curve.getCurvature(ts); -// Distance between centerpoint and real split curvepoint - double length = VecMath.getVecLength(x0,y0,xs,ys) + VecMath.getVecLength(xs,ys,x1,y1); - double chord = VecMath.getVecLength(x0,y0,x1,y1); + // Distance between centerpoint and real split curvepoint + double length = VecMath.getVecLength(x0, y0, xs, ys) + VecMath.getVecLength(xs, ys, x1, y1); + double chord = VecMath.getVecLength(x0, y0, x1, y1); - if(Double.isInfinite(chord) || Double.isInfinite(length) || - Double.isNaN(chord) || Double.isNaN(length) ) + if (Double.isInfinite(chord) || Double.isInfinite(length) || Double.isNaN(chord) || Double.isNaN(length)) return; - if( (chord > CURVATURE_MAX_LINE_LENGTH || Math.abs(length - chord) > CURVATURE_TOLERANCE) && chord > CURVATURE_MIN_LINE_LENGTH && Math.abs(t1-t0) > CURVATURE_T_TOLERANCE) - { - paintCurvatureByT(d, curve, t0,ts, flipX, flipY, scale); - paintCurvatureByT(d, curve, ts,t1, flipX, flipY, scale); - } - else - { - ls.setLine(x0*mulX, y0*mulY*scale, xs*mulX, ys*mulY*scale); + if ((chord > CURVATURE_MAX_LINE_LENGTH || Math.abs(length - chord) > CURVATURE_TOLERANCE) && chord > CURVATURE_MIN_LINE_LENGTH && Math.abs(t1 - t0) > CURVATURE_T_TOLERANCE) { + paintCurvatureByT(d, curve, t0, ts, flipX, flipY, scale); + paintCurvatureByT(d, curve, ts, t1, flipX, flipY, scale); + } else { + ls.setLine(x0 * mulX, y0 * mulY * scale, xs * mulX, ys * mulY * scale); d.draw(ls); - ls.setLine(xs*mulX, ys*mulY*scale, x1*mulX, y1*mulY*scale); + ls.setLine(xs * mulX, ys * mulY * scale, x1 * mulX, y1 * mulY * scale); d.draw(ls); } - } - static void paintCurvatureByPos(AbstractDraw d, BezierCurve curve, double x0, double x1, boolean flipX, boolean flipY, double scale) - { + static void paintCurvatureByPos(AbstractDraw d, BezierCurve curve, double x0, double x1, boolean flipX, boolean flipY, double scale) { -// Get t split point - double xs = (x1-x0)/2 + x0; + // Get t split point + double xs = (x1 - x0) / 2 + x0; - double mulX = flipX?-1:1; - double mulY = flipY?-1:1; + double mulX = flipX ? -1 : 1; + double mulY = flipY ? -1 : 1; -// Get endpoints + // Get endpoints double y0 = curve.getCurvatureAt(x0); double y1 = curve.getCurvatureAt(x1); double ys = curve.getCurvatureAt(xs); -// Distance between centerpoint and real split curvepoint - double length = VecMath.getVecLength(x0,y0,xs,ys) + VecMath.getVecLength(xs,ys,x1,y1); - double chord = VecMath.getVecLength(x0,y0,x1,y1); + // Distance between centerpoint and real split curvepoint + double length = VecMath.getVecLength(x0, y0, xs, ys) + VecMath.getVecLength(xs, ys, x1, y1); + double chord = VecMath.getVecLength(x0, y0, x1, y1); - if(Double.isInfinite(chord) || Double.isInfinite(length) || - Double.isNaN(chord) || Double.isNaN(length) ) + if (Double.isInfinite(chord) || Double.isInfinite(length) || Double.isNaN(chord) || Double.isNaN(length)) return; - if( (chord > CURVATURE_MAX_LINE_LENGTH || Math.abs(length - chord) > CURVATURE_TOLERANCE) && chord > CURVATURE_MIN_LINE_LENGTH) - { - paintCurvatureByPos(d, curve, x0,xs, flipX, flipY, scale); - paintCurvatureByPos(d, curve, xs,x1, flipX, flipY, scale); - } - else - { - ls.setLine(x0*mulX, y0*mulY*scale, xs*mulX, ys*mulY*scale); + if ((chord > CURVATURE_MAX_LINE_LENGTH || Math.abs(length - chord) > CURVATURE_TOLERANCE) && chord > CURVATURE_MIN_LINE_LENGTH) { + paintCurvatureByPos(d, curve, x0, xs, flipX, flipY, scale); + paintCurvatureByPos(d, curve, xs, x1, flipX, flipY, scale); + } else { + ls.setLine(x0 * mulX, y0 * mulY * scale, xs * mulX, ys * mulY * scale); d.draw(ls); - ls.setLine(xs*mulX, ys*mulY*scale, x1*mulX, y1*mulY*scale); + ls.setLine(xs * mulX, ys * mulY * scale, x1 * mulX, y1 * mulY * scale); d.draw(ls); } - } - - - public static void paintSlidingCrossSection(AbstractDraw d, double offsetX, double offsetY, double rotation, double scale, Color color, Stroke stroke, boolean flipX, boolean flipY, double pos, BezierBoard brd) - { - if(brd.getCrossSections().size() <= 2) + + public static void paintSlidingCrossSection(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, boolean flipX, boolean flipY, double pos, + BezierBoard brd) { + if (brd.getCrossSections().size() <= 2) return; -//DEBUG -//paintSlidingCrossSectionNormals(d, offsetX, offsetY, scale, color, stroke, flipX, flipY, pos, brd); - - switch(BoardCAD.getInstance().getCrossSectionInterpolationType()) - { + // DEBUG + // paintSlidingCrossSectionNormals(d, offsetX, offsetY, scale, rotation, + // color, + // stroke, flipX, flipY, pos, brd); + + switch (BoardCAD.getInstance().getCrossSectionInterpolationType()) { case LinearInterpolation: - paintSlidingCrossSectionBlendInterpolation(d, offsetX, offsetY, rotation, scale, color, stroke, flipX, flipY, pos, brd); + paintSlidingCrossSectionBlendInterpolation(d, offsetX, offsetY, scale, rotation, color, stroke, flipX, flipY, pos, brd); break; case ControlPointInterpolation: - paintSlidingCrossSectionControlPointInterpolation(d, offsetX, offsetY, rotation, scale, color, stroke, flipX, flipY, pos, brd); + paintSlidingCrossSectionControlPointInterpolation(d, offsetX, offsetY, scale, rotation, color, stroke, flipX, flipY, pos, brd); break; case SLinearInterpolation: -// paintSlidingCrossSectionBlendFromSInterpolation(d, offsetX, offsetY, scale, color, stroke, flipX, flipY, pos, brd); - paintSlidingCrossSectionBlendFromSInterpolationSep(d, offsetX, offsetY, rotation, scale, color, stroke, flipX, flipY, pos, brd); + // paintSlidingCrossSectionBlendFromSInterpolation(d, offsetX, + // offsetY, scale, rotation, color, stroke, flipX, flipY, pos, brd); + paintSlidingCrossSectionBlendFromSInterpolationSep(d, offsetX, offsetY, scale, rotation, color, stroke, flipX, flipY, pos, brd); break; - default: //DEBUG - paintSlidingCrossSectionBlendInterpolation(d, offsetX, offsetY, rotation, scale, new Color(255,0,0), stroke, flipX, flipY, pos, brd); - paintSlidingCrossSectionControlPointInterpolation(d, offsetX, offsetY, rotation, scale, new Color(0,255,0), stroke, flipX, flipY, pos, brd); - paintSlidingCrossSectionBlendFromSInterpolationSep(d, offsetX, offsetY, rotation, scale, new Color(0,0,255), stroke, flipX, flipY, pos, brd); + default: // DEBUG + paintSlidingCrossSectionBlendInterpolation(d, offsetX, offsetY, scale, rotation, new Color(255, 0, 0), stroke, flipX, flipY, pos, brd); + paintSlidingCrossSectionControlPointInterpolation(d, offsetX, offsetY, scale, rotation, new Color(0, 255, 0), stroke, flipX, flipY, pos, brd); + paintSlidingCrossSectionBlendFromSInterpolationSep(d, offsetX, offsetY, scale, rotation, new Color(0, 0, 255), stroke, flipX, flipY, pos, brd); break; - + } - - } - public static void paintSlidingCrossSectionNormals(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, boolean flipX, boolean flipY, double pos, BezierBoard brd) - { - // - mMulX = flipX?-1:1; - mMulY = flipY?-1:1; + } + + public static void paintSlidingCrossSectionNormals(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, boolean flipX, boolean flipY, + double pos, BezierBoard brd) { mBrd = brd; d.setColor(color); d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation, flipX, flipY); double splitAngle = TUCK_UNDER_DEFINITION_ANGLE; @@ -1386,178 +1209,166 @@ public static void paintSlidingCrossSectionNormals(AbstractDraw d, double offset double shoulder = 25.0f; double end = 360.0; double a0, a1 = 0; - + double rocker = brd.getRockerAtPos(pos); - - for(int w = 0; w < 3; w++) - { - - if(w == 0) - { - d.setColor(new Color(0,0,255)); + + for (int w = 0; w < 3; w++) { + + if (w == 0) { + d.setColor(new Color(0, 0, 255)); a0 = start; - a1 = shoulder; - } - else if(w == 1) - { - d.setColor(new Color(255,0,255)); + a1 = shoulder; + } else if (w == 1) { + d.setColor(new Color(255, 0, 255)); a0 = shoulder; - a1 = splitAngle; - } - else - { - d.setColor(new Color(0,250,0)); - a0 = splitAngle; + a1 = splitAngle; + } else { + d.setColor(new Color(0, 250, 0)); + a0 = splitAngle; a1 = end; } - Line2D line = new Line2D.Double(); Point3d point; Vector3d normal; - double steps = 20; - for(int i = 1; i <= steps; i++) - { - point = AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(BoardCAD.getInstance().getCrossSectionInterpolationType()).getPointAt(mBrd, pos, (double)i/steps, a0, a1, true); - if(point == null) + double steps = 20; + for (int i = 1; i <= steps; i++) { + point = AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(BoardCAD.getInstance().getCrossSectionInterpolationType()).getPointAt(mBrd, pos, i / steps, a0, a1, true); + if (point == null) continue; point.z -= rocker; - normal = AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(BoardCAD.getInstance().getCrossSectionInterpolationType()).getNormalAt(mBrd, pos, (double)i/steps, a0, a1, true); - normal.scale(0.1f*scale); - + normal = AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(BoardCAD.getInstance().getCrossSectionInterpolationType()).getNormalAt(mBrd, pos, i / steps, a0, a1, true); + normal.scale(0.1f * scale); + Point3d otherEnd = new Point3d(point); otherEnd.add(normal); - - line.setLine(new Point2D.Double(point.y*mMulX, point.z*mMulY), new Point2D.Double(otherEnd.y*mMulX, otherEnd.z*mMulY)); + + line.setLine(new Point2D.Double(point.y, point.z), new Point2D.Double(otherEnd.y, otherEnd.z)); d.draw(line); } } - - resetTransform(d,savedTransform); - - } - - /* public static void paintSlidingCrossSectionBlendFromSInterpolation(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, boolean flipX, boolean flipY, double pos, BezierBoard brd) - { - // - mMulX = flipX?-1:1; - mMulY = flipY?-1:1; - - mBrd = brd; - - d.setColor(color); - d.setStroke(stroke); - - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - - ds = d; - - paintSlidingCrossSectionBlendFromSInterpolation(pos, 0.00001,0.99999); - - resetTransform(d,savedTransform); + resetTransform(d, savedTransform); } - */ - public static void paintSlidingCrossSectionBlendFromSInterpolationSep(AbstractDraw d, double offsetX, double offsetY, double rotation, double scale, Color color, Stroke stroke, boolean flipX, boolean flipY, double pos, BezierBoard brd) - { - // - mMulX = flipX?-1:1; - mMulY = flipY?-1:1; + /* + * public static void + * paintSlidingCrossSectionBlendFromSInterpolation(AbstractDraw d, double + * offsetX, double offsetY, double scale, double rotation, Color color, + * Stroke stroke, boolean flipX, boolean flipY, double pos, BezierBoard brd) + * { // mMulX = flipX?-1:1; mMulY = flipY?-1:1; + * + * mBrd = brd; + * + * d.setColor(color); d.setStroke(stroke); + * + * AffineTransform savedTransform = setTransform(d, offsetX, offsetY, + * scale); + * + * ds = d; + * + * paintSlidingCrossSectionBlendFromSInterpolation(pos, 0.00001,0.99999); + * + * resetTransform(d,savedTransform); + * + * + * } + */ + + public static void paintSlidingCrossSectionBlendFromSInterpolationSep(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, boolean flipX, + boolean flipY, double pos, BezierBoard brd) { mBrd = brd; d.setColor(color); d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, rotation, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation, flipX, flipY); double splitAngle = TUCK_UNDER_DEFINITION_ANGLE; -/* - BezierBoardCrossSection c1 = brd.getPreviousCrossSection(pos); - BezierBoardCrossSection c2 = brd.getNextCrossSection(pos); - - //Scaling - double targetWidth = mBrd.getWidthAt(pos); - double targetThickness = mBrd.getThicknessAtPos(pos); - - double c1Width = c1.getWidth(); - double c1Thickness = c1.getThicknessAtPos(BezierSpline.ZERO); - - double c2Width = c2.getWidth(); - double c2Thickness = c2.getThicknessAtPos(BezierSpline.ZERO); - - double c1ThicknessScale = targetThickness/c1Thickness; - double c1WidthScale = targetWidth/c1Width; - - double c2ThicknessScale = targetThickness/c2Thickness; - double c2WidthScale = targetWidth/c2Width; - -/* - System.out.printf("getSurfacePoint()\n"); - System.out.printf("Target width: %f thickness: %f\n", targetWidth, targetThickness); - System.out.printf("C1 width: %f thickness: %f\n", c1Width, c1Thickness); - System.out.printf("C2 width: %f thickness: %f\n", c2Width, c2Thickness); - System.out.printf("C1 width scale: %f thickness scale: %f\n", c1WidthScale, c1ThicknessScale); - System.out.printf("C2 width scale: %f thickness scale: %f\n", c2WidthScale, c2ThicknessScale); -*/ - -/* - double s1 = c1.getBezierSpline().getSByNormalReverseScaled(splitAngle, true, c1WidthScale, c1ThicknessScale); - double s2 = c2.getBezierSpline().getSByNormalReverseScaled(splitAngle, true, c2WidthScale, c2ThicknessScale); - -// d.setColor(new Color(0,0,255)); - paintSlidingCrossSectionBlendFromSInterpolation(pos, BezierSpline.ZERO, s1, BezierSpline.ZERO, s2); -// d.setColor(new Color(0,250,0)); - paintSlidingCrossSectionBlendFromSInterpolation(pos, s1, BezierSpline.ONE, s2, BezierSpline.ONE); -*/ + /* + * BezierBoardCrossSection c1 = brd.getPreviousCrossSection(pos); + * BezierBoardCrossSection c2 = brd.getNextCrossSection(pos); + * + * //Scaling double targetWidth = mBrd.getWidthAt(pos); double + * targetThickness = mBrd.getThicknessAtPos(pos); + * + * double c1Width = c1.getWidth(); double c1Thickness = + * c1.getThicknessAtPos(BezierSpline.ZERO); + * + * double c2Width = c2.getWidth(); double c2Thickness = + * c2.getThicknessAtPos(BezierSpline.ZERO); + * + * double c1ThicknessScale = targetThickness/c1Thickness; double + * c1WidthScale = targetWidth/c1Width; + * + * double c2ThicknessScale = targetThickness/c2Thickness; double + * c2WidthScale = targetWidth/c2Width; + * + * /* System.out.printf("getSurfacePoint()\n"); + * System.out.printf("Target width: %f thickness: %f\n", targetWidth, + * targetThickness); System.out.printf("C1 width: %f thickness: %f\n", + * c1Width, c1Thickness); + * System.out.printf("C2 width: %f thickness: %f\n", c2Width, + * c2Thickness); + * System.out.printf("C1 width scale: %f thickness scale: %f\n", + * c1WidthScale, c1ThicknessScale); + * System.out.printf("C2 width scale: %f thickness scale: %f\n", + * c2WidthScale, c2ThicknessScale); + */ + + /* + * double s1 = + * c1.getBezierSpline().getSByNormalReverseScaled(splitAngle, true, + * c1WidthScale, c1ThicknessScale); double s2 = + * c2.getBezierSpline().getSByNormalReverseScaled(splitAngle, true, + * c2WidthScale, c2ThicknessScale); + * + * // d.setColor(new Color(0,0,255)); + * paintSlidingCrossSectionBlendFromSInterpolation(pos, + * BezierSpline.ZERO, s1, BezierSpline.ZERO, s2); // d.setColor(new + * Color(0,250,0)); paintSlidingCrossSectionBlendFromSInterpolation(pos, + * s1, BezierSpline.ONE, s2, BezierSpline.ONE); + */ double start = -90.0; double shoulder = 25.0f; double end = 360.0; double a0, a1 = 0; - + double rocker = brd.getRockerAtPos(pos); - - for(int w = 0; w < 3; w++) - { - - if(w == 0) - { -// d.setColor(new Color(0,0,255)); + + for (int w = 0; w < 3; w++) { + + if (w == 0) { + // d.setColor(new Color(0,0,255)); a0 = start; - a1 = shoulder; - } - else if(w == 1) - { -// d.setColor(new Color(255,0,255)); + a1 = shoulder; + } else if (w == 1) { + // d.setColor(new Color(255,0,255)); a0 = shoulder; - a1 = splitAngle; - } - else - { -// d.setColor(new Color(0,250,0)); - a0 = splitAngle; + a1 = splitAngle; + } else { + // d.setColor(new Color(0,250,0)); + a0 = splitAngle; a1 = end; } - - + GeneralPath path = new GeneralPath(); Point3d point = AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(AbstractBezierBoardSurfaceModel.ModelType.SLinearInterpolation).getPointAt(mBrd, pos, 0.0, a0, a1, true); - + point.z -= rocker; - - path.moveTo(point.y*mMulX,point.z*mMulY); - double steps = 20; - for(int i = 1; i <= steps; i++) - { - point = AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(AbstractBezierBoardSurfaceModel.ModelType.SLinearInterpolation).getPointAt(mBrd, pos, (double)i/steps, a0, a1, true); + + path.moveTo(point.y, point.z); + double steps = 20; + for (int i = 1; i <= steps; i++) { + point = AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(AbstractBezierBoardSurfaceModel.ModelType.SLinearInterpolation).getPointAt(mBrd, pos, i / steps, a0, a1, true); point.z -= rocker; - path.lineTo(point.y*mMulX,point.z*mMulY); - + path.lineTo(point.y, point.z); + } d.draw(path); AffineTransform trans = new AffineTransform(); @@ -1565,311 +1376,246 @@ else if(w == 1) path.transform(trans); d.draw(path); } - - - resetTransform(d,savedTransform); + resetTransform(d, savedTransform); } - public static void paintSlidingCrossSectionBlendFromSInterpolation(double pos, double a0, double a1) - { - } - -/* - public static void paintSlidingCrossSectionBlendFromSInterpolation(double pos, double s0, double s1 ) - { -// Get endpoints - Point2D.Double p0 = mBrd.getPointAtPos(pos, s0); - Point2D.Double p1 = mBrd.getPointAtPos(pos, s1); - -// Get x split point - double ss = (s1-s0)/2 + s0; - Point2D.Double ps = mBrd.getPointAtPos(pos, ss); - -// Angle between vectors formed by - Point2D.Double v0 = new Point2D.Double(); - Point2D.Double v1 = new Point2D.Double(); - - BezierSpline.subVector(p0, ps, v0); - BezierSpline.subVector(ps, p1, v1); - - double length = BezierSpline.getVecLength(v0) + BezierSpline.getVecLength(v1); - - double angle = BezierSpline.getVecAngle(v0,v1); - - if( length > S_BLEND_MAX_LENGTH || (Math.abs(angle) > S_BLEND_MIN_ANGLE && length > S_BLEND_MIN_LENGTH) ) - { - paintSlidingCrossSectionBlendFromSInterpolation(pos, s0, ss); - paintSlidingCrossSectionBlendFromSInterpolation(pos, ss, s1); - } - else - { -/*Draw Normal for debug - Vector3d vec = mBrd.getNormalAtPos(pos, ss); - ls.setLine(ps.x*mMulX, ps.y*mMulY,(ps.x+vec.y)*mMulX, (ps.y+vec.z)*mMulY); - ds.draw(ls); -*/ - /* - ls.setLine(p0.x*mMulX, p0.y*mMulY, ps.x*mMulX, ps.y*mMulY); - ds.draw(ls); - ls.setLine(ps.x*mMulX, ps.y*mMulY, p1.x*mMulX, p1.y*mMulY); - ds.draw(ls); - ls.setLine(-p0.x*mMulX, p0.y*mMulY, -ps.x*mMulX, ps.y*mMulY); - ds.draw(ls); - ls.setLine(-ps.x*mMulX, ps.y*mMulY, -p1.x*mMulX, p1.y*mMulY); - ds.draw(ls); - } + public static void paintSlidingCrossSectionBlendFromSInterpolation(double pos, double a0, double a1) { } - */ -/* - public static void paintSlidingCrossSectionBlendFromSInterpolation(double pos, double a0, double a1, double b0, double b1 ) - { -// Get endpoints - Point2D.Double p0 = mBrd.getPointAtPos(pos, a0, b0); - Point2D.Double p1 = mBrd.getPointAtPos(pos, a1, b1); - -// Get x split point - double as = (a1-a0)/2 + a0; - double bs = (b1-b0)/2 + b0; - Point2D.Double ps = mBrd.getPointAtPos(pos, as, bs); - -// Angle between vectors formed by - Point2D.Double v0 = new Point2D.Double(); - Point2D.Double v1 = new Point2D.Double(); - - BezierSpline.subVector(p0, ps, v0); - BezierSpline.subVector(ps, p1, v1); - - double length = BezierSpline.getVecLength(v0) + BezierSpline.getVecLength(v1); - - double angle = BezierSpline.getVecAngle(v0,v1); - - if( length > S_BLEND_MAX_LENGTH || (Math.abs(angle) > S_BLEND_MIN_ANGLE && length > S_BLEND_MIN_LENGTH) ) - { - paintSlidingCrossSectionBlendFromSInterpolation(pos, a0, as, b0, bs); - paintSlidingCrossSectionBlendFromSInterpolation(pos, as, a1, bs, b1); - } - else - { -/* Draw normal for debug - * Vector3d vec = mBrd.getNormalAtPos(pos, as, bs); - ls.setLine(ps.x*mMulX, ps.y*mMulY,(ps.x+vec.y)*mMulX, (ps.y+vec.z)*mMulY); - ds.draw(ls); - - Draw tangent for debug - vec = mBrd.getTangentAtPos(pos, as, bs); - ls.setLine(ps.x*mMulX, ps.y*mMulY,(ps.x+vec.y)*mMulX, (ps.y+vec.z)*mMulY); - ds.setColor(new Color(0,0,250)); - ds.draw(ls); - ds.setColor(new Color(255,255,0)); -*/ -/* - ls.setLine(p0.x*mMulX, p0.y*mMulY, ps.x*mMulX, ps.y*mMulY); - ds.draw(ls); - ls.setLine(ps.x*mMulX, ps.y*mMulY, p1.x*mMulX, p1.y*mMulY); - ds.draw(ls); - ls.setLine(-p0.x*mMulX, p0.y*mMulY, -ps.x*mMulX, ps.y*mMulY); - ds.draw(ls); - ls.setLine(-ps.x*mMulX, ps.y*mMulY, -p1.x*mMulX, p1.y*mMulY); - ds.draw(ls); - } - } -*/ - public static void paintSlidingCrossSectionControlPointInterpolation(AbstractDraw d, double offsetX, double offsetY, double rotation, double scale, Color color, Stroke stroke, boolean flipX, boolean flipY, double pos, BezierBoard brd) - { + /* + * public static void paintSlidingCrossSectionBlendFromSInterpolation(double + * pos, double s0, double s1 ) { // Get endpoints Point2D.Double p0 = + * mBrd.getPointAtPos(pos, s0); Point2D.Double p1 = mBrd.getPointAtPos(pos, + * s1); + * + * // Get x split point double ss = (s1-s0)/2 + s0; Point2D.Double ps = + * mBrd.getPointAtPos(pos, ss); + * + * // Angle between vectors formed by Point2D.Double v0 = new + * Point2D.Double(); Point2D.Double v1 = new Point2D.Double(); + * + * BezierSpline.subVector(p0, ps, v0); BezierSpline.subVector(ps, p1, v1); + * + * double length = BezierSpline.getVecLength(v0) + + * BezierSpline.getVecLength(v1); + * + * double angle = BezierSpline.getVecAngle(v0,v1); + * + * if( length > S_BLEND_MAX_LENGTH || (Math.abs(angle) > S_BLEND_MIN_ANGLE + * && length > S_BLEND_MIN_LENGTH) ) { + * paintSlidingCrossSectionBlendFromSInterpolation(pos, s0, ss); + * paintSlidingCrossSectionBlendFromSInterpolation(pos, ss, s1); } else { + * /*Draw Normal for debug Vector3d vec = mBrd.getNormalAtPos(pos, ss); + * ls.setLine(ps.x*mMulX, ps.y*mMulY,(ps.x+vec.y)*mMulX, + * (ps.y+vec.z)*mMulY); ds.draw(ls); + */ + /* + * ls.setLine(p0.x*mMulX, p0.y*mMulY, ps.x*mMulX, ps.y*mMulY); ds.draw(ls); + * ls.setLine(ps.x*mMulX, ps.y*mMulY, p1.x*mMulX, p1.y*mMulY); ds.draw(ls); + * ls.setLine(-p0.x*mMulX, p0.y*mMulY, -ps.x*mMulX, ps.y*mMulY); + * ds.draw(ls); ls.setLine(-ps.x*mMulX, ps.y*mMulY, -p1.x*mMulX, + * p1.y*mMulY); ds.draw(ls); } + * + * } + */ + /* + * public static void paintSlidingCrossSectionBlendFromSInterpolation(double + * pos, double a0, double a1, double b0, double b1 ) { // Get endpoints + * Point2D.Double p0 = mBrd.getPointAtPos(pos, a0, b0); Point2D.Double p1 = + * mBrd.getPointAtPos(pos, a1, b1); + * + * // Get x split point double as = (a1-a0)/2 + a0; double bs = (b1-b0)/2 + + * b0; Point2D.Double ps = mBrd.getPointAtPos(pos, as, bs); + * + * // Angle between vectors formed by Point2D.Double v0 = new + * Point2D.Double(); Point2D.Double v1 = new Point2D.Double(); + * + * BezierSpline.subVector(p0, ps, v0); BezierSpline.subVector(ps, p1, v1); + * + * double length = BezierSpline.getVecLength(v0) + + * BezierSpline.getVecLength(v1); + * + * double angle = BezierSpline.getVecAngle(v0,v1); + * + * if( length > S_BLEND_MAX_LENGTH || (Math.abs(angle) > S_BLEND_MIN_ANGLE + * && length > S_BLEND_MIN_LENGTH) ) { + * paintSlidingCrossSectionBlendFromSInterpolation(pos, a0, as, b0, bs); + * paintSlidingCrossSectionBlendFromSInterpolation(pos, as, a1, bs, b1); } + * else { /* Draw normal for debug Vector3d vec = mBrd.getNormalAtPos(pos, + * as, bs); ls.setLine(ps.x*mMulX, ps.y*mMulY,(ps.x+vec.y)*mMulX, + * (ps.y+vec.z)*mMulY); ds.draw(ls); + * + * Draw tangent for debug vec = mBrd.getTangentAtPos(pos, as, bs); + * ls.setLine(ps.x*mMulX, ps.y*mMulY,(ps.x+vec.y)*mMulX, + * (ps.y+vec.z)*mMulY); ds.setColor(new Color(0,0,250)); ds.draw(ls); + * ds.setColor(new Color(255,255,0)); + */ + /* + * ls.setLine(p0.x*mMulX, p0.y*mMulY, ps.x*mMulX, ps.y*mMulY); ds.draw(ls); + * ls.setLine(ps.x*mMulX, ps.y*mMulY, p1.x*mMulX, p1.y*mMulY); ds.draw(ls); + * ls.setLine(-p0.x*mMulX, p0.y*mMulY, -ps.x*mMulX, ps.y*mMulY); + * ds.draw(ls); ls.setLine(-ps.x*mMulX, ps.y*mMulY, -p1.x*mMulX, + * p1.y*mMulY); ds.draw(ls); } + * + * } + */ + public static void paintSlidingCrossSectionControlPointInterpolation(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, boolean flipX, + boolean flipY, double pos, BezierBoard brd) { BezierBoardCrossSection interpol = brd.getInterpolatedCrossSection(pos); - if(interpol != null) - { - BezierBoardDrawUtil.paintBezierSpline(d,offsetX, offsetY, rotation, scale, color, stroke, interpol.getBezierSpline(), ((flipX==true)?BezierBoardDrawUtil.FlipX:0)|((flipY==true)?BezierBoardDrawUtil.FlipY:0), true); - BezierBoardDrawUtil.paintBezierSpline(d,offsetX, offsetY, rotation, scale, color, stroke, interpol.getBezierSpline(), ((flipX==true)?0:BezierBoardDrawUtil.FlipX)|((flipY==true)?BezierBoardDrawUtil.FlipY:0), true); -//DEBUG BrdDrawUtil.paintBezierControlPoints(d,offsetX, offsetY, scale, stroke, interpol.mCrossSectionControlPoints, new ArrayList(), flipX, flipY); //DEBUG! + if (interpol != null) { + BezierBoardDrawUtil.paintBezierSpline(d, offsetX, offsetY, scale, rotation, color, stroke, interpol.getBezierSpline(), ((flipX == true) ? BezierBoardDrawUtil.FlipX : 0) + | ((flipY == true) ? BezierBoardDrawUtil.FlipY : 0), true); + BezierBoardDrawUtil.paintBezierSpline(d, offsetX, offsetY, scale, rotation, color, stroke, interpol.getBezierSpline(), ((flipX == true) ? 0 : BezierBoardDrawUtil.FlipX) + | ((flipY == true) ? BezierBoardDrawUtil.FlipY : 0), true); + // DEBUG BrdDrawUtil.paintBezierControlPoints(d,offsetX, offsetY, + // scale, stroke, interpol.mCrossSectionControlPoints, new + // ArrayList(), flipX, flipY); //DEBUG! } } - public static void paintSlidingCrossSectionBlendInterpolation(AbstractDraw d, double offsetX, double offsetY, double rotation, double scale, Color color, Stroke stroke, boolean flipX, boolean flipY, double pos, BezierBoard brd) - { - - - // - mMulX = flipX?-1:1; - mMulY = flipY?-1:1; + public static void paintSlidingCrossSectionBlendInterpolation(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, boolean flipX, + boolean flipY, double pos, BezierBoard brd) { mBrd = brd; d.setColor(color); d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, rotation, scale); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation, flipX, flipY); - //Calculate scales - double halfWidth = mBrd.getWidthAtPos(pos)/2; + // Calculate scales + double halfWidth = mBrd.getWidthAtPos(pos) / 2; halfWidth -= .00001; - paintSlidingCrossSectionBlendInterpolation(d, pos,0, halfWidth/2); - paintSlidingCrossSectionBlendInterpolation(d, pos,halfWidth/2, halfWidth); - paintSlidingCrossSectionBlendInterpolationReverse(d, pos, 0, halfWidth/2); - paintSlidingCrossSectionBlendInterpolationReverse(d, pos, halfWidth/2, halfWidth); - + paintSlidingCrossSectionBlendInterpolation(d, pos, 0, halfWidth / 2); + paintSlidingCrossSectionBlendInterpolation(d, pos, halfWidth / 2, halfWidth); + paintSlidingCrossSectionBlendInterpolationReverse(d, pos, 0, halfWidth / 2); + paintSlidingCrossSectionBlendInterpolationReverse(d, pos, halfWidth / 2, halfWidth); double z0 = mBrd.getDeckAtPos(pos, halfWidth); double z1 = mBrd.getBottomAtPos(pos, halfWidth); - ls.setLine(halfWidth*mMulX, z0*mMulY, halfWidth*mMulX, z1*mMulY); + ls.setLine(halfWidth, z0, halfWidth, z1); d.draw(ls); - ls.setLine(-halfWidth*mMulX, z0*mMulY, -halfWidth*mMulX, z1*mMulY); + ls.setLine(-halfWidth, z0, -halfWidth, z1); d.draw(ls); - resetTransform(d,savedTransform); + resetTransform(d, savedTransform); } - /* - public static void paintSlidingCrossSectionS(double x, double s0, double s1 ) - { - -// Get endpoints - double z0 = mBrd.getDeckAtPos(x, y0); - double z1 = mBrd.getDeckAtPos(x, y1); - -// Get x split point - double ys = (y1-y0)/2 + y0; - double zs = mBrd.getDeckAtPos(x, ys); - -// Distance between centerpoint and real split curvepoint - double length = BezierPatch.getVecLength(y0,z0,ys,zs) + BezierPatch.getVecLength(ys,zs,y1,z1); - double chord = BezierPatch.getVecLength(y0,z0,y1,z1); - - if(Double.isInfinite(chord) || Double.isInfinite(length) || - Double.isNaN(chord) || Double.isNaN(length) ) - return; - - if(Math.abs(length - chord) > SLIDING_CROSS_SECTION_TOLERANCE && chord > SLIDING_CROSS_SECTION_MIN_LINE_LENGTH ) - { - paintSlidingCrossSection(x, y0, ys); - paintSlidingCrossSection(x, ys, y1); - } - else - { - ls.setLine(y0*mMulX, z0*mMulY, ys*mMulX, zs*mMulY); - ds.draw(ls); - ls.setLine(ys*mMulX, zs*mMulY, y1*mMulX, z1*mMulY); - ds.draw(ls); - } - } + /* + * public static void paintSlidingCrossSectionS(double x, double s0, double + * s1 ) { + * + * // Get endpoints double z0 = mBrd.getDeckAtPos(x, y0); double z1 = + * mBrd.getDeckAtPos(x, y1); + * + * // Get x split point double ys = (y1-y0)/2 + y0; double zs = + * mBrd.getDeckAtPos(x, ys); + * + * // Distance between centerpoint and real split curvepoint double length = + * BezierPatch.getVecLength(y0,z0,ys,zs) + + * BezierPatch.getVecLength(ys,zs,y1,z1); double chord = + * BezierPatch.getVecLength(y0,z0,y1,z1); + * + * if(Double.isInfinite(chord) || Double.isInfinite(length) || + * Double.isNaN(chord) || Double.isNaN(length) ) return; + * + * if(Math.abs(length - chord) > SLIDING_CROSS_SECTION_TOLERANCE && chord > + * SLIDING_CROSS_SECTION_MIN_LINE_LENGTH ) { paintSlidingCrossSection(x, y0, + * ys); paintSlidingCrossSection(x, ys, y1); } else { ls.setLine(y0*mMulX, + * z0*mMulY, ys*mMulX, zs*mMulY); ds.draw(ls); ls.setLine(ys*mMulX, + * zs*mMulY, y1*mMulX, z1*mMulY); ds.draw(ls); } + * + * } */ - public static void paintSlidingCrossSectionBlendInterpolation(AbstractDraw d, double x, double y0, double y1 ) - { -// Get endpoints + public static void paintSlidingCrossSectionBlendInterpolation(AbstractDraw d, double x, double y0, double y1) { + // Get endpoints double z0 = mBrd.getDeckAtPos(x, y0); double z1 = mBrd.getDeckAtPos(x, y1); -// Get x split point - double ys = (y1-y0)/2 + y0; + // Get x split point + double ys = (y1 - y0) / 2 + y0; double zs = mBrd.getDeckAtPos(x, ys); -// Distance between centerpoint and real split curvepoint - double length = VecMath.getVecLength(y0,z0,ys,zs) + VecMath.getVecLength(ys,zs,y1,z1); - double chord = VecMath.getVecLength(y0,z0,y1,z1); + // Distance between centerpoint and real split curvepoint + double length = VecMath.getVecLength(y0, z0, ys, zs) + VecMath.getVecLength(ys, zs, y1, z1); + double chord = VecMath.getVecLength(y0, z0, y1, z1); - if(Double.isInfinite(chord) || Double.isInfinite(length) || - Double.isNaN(chord) || Double.isNaN(length) ) + if (Double.isInfinite(chord) || Double.isInfinite(length) || Double.isNaN(chord) || Double.isNaN(length)) return; - if(Math.abs(y1 - y0) > SLIDING_CROSS_MIN_SPLIT && (chord > SLIDING_CROSS_SECTION_MAX_LINE_LENGTH || (Math.abs(length - chord) > SLIDING_CROSS_SECTION_TOLERANCE && chord > SLIDING_CROSS_SECTION_MIN_LINE_LENGTH ))) - { + if (Math.abs(y1 - y0) > SLIDING_CROSS_MIN_SPLIT + && (chord > SLIDING_CROSS_SECTION_MAX_LINE_LENGTH || (Math.abs(length - chord) > SLIDING_CROSS_SECTION_TOLERANCE && chord > SLIDING_CROSS_SECTION_MIN_LINE_LENGTH))) { paintSlidingCrossSectionBlendInterpolation(d, x, y0, ys); paintSlidingCrossSectionBlendInterpolation(d, x, ys, y1); - } - else - { - ls.setLine(y0*mMulX, z0*mMulY, ys*mMulX, zs*mMulY); + } else { + ls.setLine(y0, z0, ys, zs); d.draw(ls); - ls.setLine(ys*mMulX, zs*mMulY, y1*mMulX, z1*mMulY); + ls.setLine(ys, zs, y1, z1); d.draw(ls); - ls.setLine(-y0*mMulX, z0*mMulY, -ys*mMulX, zs*mMulY); + ls.setLine(-y0, z0, -ys, zs); d.draw(ls); - ls.setLine(-ys*mMulX, zs*mMulY, -y1*mMulX, z1*mMulY); + ls.setLine(-ys, zs, -y1, z1); d.draw(ls); } } - public static void paintSlidingCrossSectionBlendInterpolationReverse(AbstractDraw d, double x, double y0, double y1 ) - { -// Get endpoints + public static void paintSlidingCrossSectionBlendInterpolationReverse(AbstractDraw d, double x, double y0, double y1) { + // Get endpoints double z0 = mBrd.getBottomAtPos(x, y0); double z1 = mBrd.getBottomAtPos(x, y1); -// Get x split point - double ys = (y1-y0)/2 + y0; + // Get x split point + double ys = (y1 - y0) / 2 + y0; double zs = mBrd.getBottomAtPos(x, ys); -// Distance between centerpoint and real split curvepoint - double length = VecMath.getVecLength(y0,z0,ys,zs) + VecMath.getVecLength(ys,zs,y1,z1); - double chord = VecMath.getVecLength(y0,z0,y1,z1); + // Distance between centerpoint and real split curvepoint + double length = VecMath.getVecLength(y0, z0, ys, zs) + VecMath.getVecLength(ys, zs, y1, z1); + double chord = VecMath.getVecLength(y0, z0, y1, z1); - if(Double.isInfinite(chord) || Double.isInfinite(length) || - Double.isNaN(chord) || Double.isNaN(length) ) + if (Double.isInfinite(chord) || Double.isInfinite(length) || Double.isNaN(chord) || Double.isNaN(length)) return; - if(Math.abs(y1 - y0) > SLIDING_CROSS_MIN_SPLIT && (chord > SLIDING_CROSS_SECTION_MAX_LINE_LENGTH || (Math.abs(length - chord) > SLIDING_CROSS_SECTION_TOLERANCE && chord > SLIDING_CROSS_SECTION_MIN_LINE_LENGTH )) ) - { + if (Math.abs(y1 - y0) > SLIDING_CROSS_MIN_SPLIT + && (chord > SLIDING_CROSS_SECTION_MAX_LINE_LENGTH || (Math.abs(length - chord) > SLIDING_CROSS_SECTION_TOLERANCE && chord > SLIDING_CROSS_SECTION_MIN_LINE_LENGTH))) { paintSlidingCrossSectionBlendInterpolationReverse(d, x, y0, ys); paintSlidingCrossSectionBlendInterpolationReverse(d, x, ys, y1); - } - else - { - ls.setLine(y0*mMulX, z0*mMulY, ys*mMulX, zs*mMulY); + } else { + ls.setLine(y0, z0, ys, zs); d.draw(ls); - ls.setLine(ys*mMulX, zs*mMulY, y1*mMulX, z1*mMulY); + ls.setLine(ys, zs, y1, z1); d.draw(ls); - ls.setLine(-y0*mMulX, z0*mMulY, -ys*mMulX, zs*mMulY); + ls.setLine(-y0, z0, -ys, zs); d.draw(ls); - ls.setLine(-ys*mMulX, zs*mMulY, -y1*mMulX, z1*mMulY); - d.draw(ls); - } - } - - public static void paintDetails(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierSpline[] beziers, boolean flipX, boolean flipY, boolean mirrorX, boolean mirrorY, double posOffsetX, double posOffsetY, double measurementOffsetX, double measurementOffsetY) - { - for(int i = 0; i < beziers.length; i++ ) - { - paintBezierSpline(d,offsetX, offsetY, scale, color, stroke, beziers[i],((flipX==true)?BezierBoardDrawUtil.FlipX:0)|((flipY==true)?BezierBoardDrawUtil.FlipY:0)|((mirrorX==true)?BezierBoardDrawUtil.MirrorX:0)|((mirrorY==true)?BezierBoardDrawUtil.MirrorY:0), true); - } + ls.setLine(-ys, zs, -y1, z1); + d.draw(ls); + } } - public static void paintDetailsVertical(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, BezierSpline[] beziers, boolean flipX, boolean flipY, boolean mirrorX, boolean mirrorY, double posOffsetX, double posOffsetY, double measurementOffsetX, double measurementOffsetY) - { - for(int i = 0; i < beziers.length; i++ ) - { - paintBezierSpline(d,offsetX, offsetY, Math.PI/4.0, scale, color, stroke, beziers[i],((flipX==true)?BezierBoardDrawUtil.FlipX:0)|((flipY==true)?BezierBoardDrawUtil.FlipY:0)|((mirrorX==true)?BezierBoardDrawUtil.MirrorX:0)|((mirrorY==true)?BezierBoardDrawUtil.MirrorY:0), true); + public static void paintDetails(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierSpline[] beziers, boolean flipX, boolean flipY, + boolean mirrorX, boolean mirrorY, double posOffsetX, double posOffsetY, double measurementOffsetX, double measurementOffsetY) { + for (int i = 0; i < beziers.length; i++) { + paintBezierSpline(d, offsetX, offsetY, scale, rotation, color, stroke, beziers[i], ((flipX == true) ? BezierBoardDrawUtil.FlipX : 0) | ((flipY == true) ? BezierBoardDrawUtil.FlipY : 0) + | ((mirrorX == true) ? BezierBoardDrawUtil.MirrorX : 0) | ((mirrorY == true) ? BezierBoardDrawUtil.MirrorY : 0), true); } } - public static AffineTransform setTransform(AbstractDraw d, double offsetX, double offsetY, double scale) - { - - AffineTransform savedTransform = d.getTransform(); - - final AffineTransform at = new AffineTransform(); - - at.setToTranslation(offsetX, offsetY); - - d.transform(at); - - at.setToScale(scale, scale); - - d.transform(at); - - return savedTransform; + public static void paintDetailsVertical(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, BezierSpline[] beziers, boolean flipX, + boolean flipY, boolean mirrorX, boolean mirrorY, double posOffsetX, double posOffsetY, double measurementOffsetX, double measurementOffsetY) { + for (int i = 0; i < beziers.length; i++) { + paintBezierSpline(d, offsetX, offsetY, scale, Math.PI / 4.0, color, stroke, beziers[i], ((flipX == true) ? BezierBoardDrawUtil.FlipX : 0) + | ((flipY == true) ? BezierBoardDrawUtil.FlipY : 0) | ((mirrorX == true) ? BezierBoardDrawUtil.MirrorX : 0) | ((mirrorY == true) ? BezierBoardDrawUtil.MirrorY : 0), true); + } } - public static AffineTransform setTransform(AbstractDraw d, double offsetX, double offsetY, double scale, boolean mirrorX, boolean mirrorY) - { + static public AffineTransform setTransform(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation) { AffineTransform savedTransform = d.getTransform(); @@ -1877,155 +1623,133 @@ public static AffineTransform setTransform(AbstractDraw d, double offsetX, doubl at.setToTranslation(offsetX, offsetY); - d.transform(at); + at.scale(scale, scale); - at.setToScale(scale*(mirrorX?-1.0:1.0), scale*(mirrorY?-1.0:1.0)); + at.rotate(rotation); d.transform(at); return savedTransform; } - static AffineTransform setTransform(AbstractDraw d, double offsetX, double offsetY, double rotation, double scale) - { + public static AffineTransform setTransform(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, boolean mirrorX, boolean mirrorY) { AffineTransform savedTransform = d.getTransform(); final AffineTransform at = new AffineTransform(); - at.setToTranslation(offsetX, offsetY); - d.transform(at); + if (scale == 0.0) { + System.out.println("Error, scale is 0.0"); + } - at.setToScale(scale, scale); + at.scale(scale * (mirrorX ? -1.0 : 1.0), scale * (mirrorY ? -1.0 : 1.0)); - d.transform(at); - - at.setToRotation(rotation); + if (rotation != 0.0) { + at.rotate(rotation); + } d.transform(at); return savedTransform; } - - static void resetTransform(AbstractDraw d, AffineTransform savedTransform) - { + static void resetTransform(AbstractDraw d, AffineTransform savedTransform) { d.setTransform(savedTransform); } + // Old functions originating from printing + private static void setImperialGridLineStrokeAndColor(AbstractDraw d, Color color, int i, double scale) { -// Old functions orginating from printing - private static void setImperialGridLineStrokeAndColor(AbstractDraw d, Color color, int i, double scale) - { - - if (i%12 == 0) - { + if (i % 12 == 0) { d.setColor(color.darker().darker()); - d.setStroke(new BasicStroke((float)(1.5/scale))); - } - else if (i%6 == 0) - { + d.setStroke(new BasicStroke((float) (1.5 / scale))); + } else if (i % 6 == 0) { d.setColor(color.darker()); - d.setStroke(new BasicStroke((float)(1.2/scale))); - } - else - { + d.setStroke(new BasicStroke((float) (1.2 / scale))); + } else { d.setColor(color); - d.setStroke(new BasicStroke((float)(1.0/scale))); + d.setStroke(new BasicStroke((float) (1.0 / scale))); } } - -// Old functions orginating from printing - private static void setMetricGridLineStrokeAndColor(AbstractDraw d, Color color, int i, double scale) - { + // Old functions orginating from printing + private static void setMetricGridLineStrokeAndColor(AbstractDraw d, Color color, int i, double scale) { - if (i%100 == 0) - { + if (i % 100 == 0) { d.setColor(color.darker().darker().darker()); - d.setStroke(new BasicStroke((float)(1.5/scale))); - } - else - if (i%50 == 0) - { + d.setStroke(new BasicStroke((float) (1.5 / scale))); + } else if (i % 50 == 0) { d.setColor(color.darker().darker()); - d.setStroke(new BasicStroke((float)(1.3/scale))); - } - else if (i%10 == 0) - { + d.setStroke(new BasicStroke((float) (1.3 / scale))); + } else if (i % 10 == 0) { d.setColor(color.darker()); - d.setStroke(new BasicStroke((float)(1.1/scale))); - } - else - { + d.setStroke(new BasicStroke((float) (1.1 / scale))); + } else { d.setColor(color); - d.setStroke(new BasicStroke((float)(1.0/scale))); + d.setStroke(new BasicStroke((float) (1.0 / scale))); } } - public static void printOutline(AbstractDraw d, double offsetX, - double offsetY, double rotation, double scale, boolean paintGrid, BezierBoard brd, boolean printGuidePoints, boolean printFins) { + double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, boolean printGuidePoints, boolean printFins) { + + if (brd.isEmpty()) { - if(brd.isEmpty()) { - return; - + } - if(brd.getOutline().getNrOfControlPoints() < 2) { + if (brd.getOutline().getNrOfControlPoints() < 2) { return; } - paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), brd.getLength(), brd.getCenterWidth()/2.0, false, false); + paintGrid(d, offsetX, offsetY, scale, rotation, new Color(128, 128, 128), brd.getLength(), brd.getCenterWidth() / 2.0, false, false); + + GeneralPath outlineLower = makeBezierPathFromControlPoints(brd.getOutline(), false, false, false, false); - GeneralPath outlineLower = makeBezierPathFromControlPoints(brd.getOutline(),false,false, false, false); + GeneralPath outlineUpper = makeBezierPathFromControlPoints(brd.getOutline(), false, true, false, false); - GeneralPath outlineUpper = makeBezierPathFromControlPoints(brd.getOutline(),false,true, false, false); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, + // brd.mOutlineControlPoints, null, false, false); -// paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mOutlineControlPoints, null, false, false); + paintPath(d, offsetX, offsetY, scale, rotation, BoardCAD.getInstance().getBrdColor(), stroke, outlineLower, false); - - paintPath(d,offsetX, offsetY, rotation, scale, BoardCAD.getInstance().getBrdColor(), stroke, outlineLower, false); - - paintPath(d,offsetX, offsetY, rotation, scale, BoardCAD.getInstance().getBrdColor(), stroke, outlineUpper, false); + paintPath(d, offsetX, offsetY, scale, rotation, BoardCAD.getInstance().getBrdColor(), stroke, outlineUpper, false); - if(printGuidePoints == true) - { - BezierBoardDrawUtil.paintGuidePoints(d, offsetX, offsetY, scale, Color.GRAY, stroke, brd.getOutlineGuidePoints(), false, false); + if (printGuidePoints == true) { + BezierBoardDrawUtil.paintGuidePoints(d, offsetX, offsetY, scale, rotation, Color.GRAY, stroke, brd.getOutlineGuidePoints(), false, false); } - - if(printFins == true) - { - BezierBoardDrawUtil.paintFins(d, offsetX, offsetY, scale, Color.GRAY, stroke, brd.getFins(), false, false); + + if (printFins == true) { + BezierBoardDrawUtil.paintFins(d, offsetX, offsetY, scale, rotation, Color.GRAY, stroke, brd.getFins(), false, false); } } - public static void printOutlineOverCurve(AbstractDraw d, double offsetX, + public static void printOutlineOverCurve(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, boolean printGuidePoints, + boolean printFins, boolean mirrorX, boolean mirrorY) { - double offsetY, double rotation, double scale, boolean paintGrid, BezierBoard brd, boolean printGuidePoints, boolean printFins, boolean mirrorX, boolean mirrorY) { + if (brd.isEmpty()) { - if(brd.isEmpty()) { - return; - + } - if(brd.getOutline().getNrOfControlPoints() < 2) { + if (brd.getOutline().getNrOfControlPoints() < 2) { return; @@ -2033,299 +1757,308 @@ public static void printOutlineOverCurve(AbstractDraw d, double offsetX, System.out.printf("\nOUTLINE OVER CURVE\n"); - if(paintGrid) - { - paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), brd.getLength(), brd.getMaxWidth()/2.0, false, false); + if (paintGrid) { + paintGrid(d, offsetX, offsetY, scale, rotation, new Color(128, 128, 128), brd.getLength(), brd.getMaxWidth() / 2.0, false, false); } - - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(0,0,0)); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, false, false); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mBottomControlPoints, false, false); - - // paintBezierSpline(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, deck); - - // paintBezierSpline(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, bottom); - + d.setColor(new Color(0, 0, 0)); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, + // false, false); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, + // brd.mBottomControlPoints, false, false); + + // paintBezierSpline(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, deck); + + // paintBezierSpline(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, bottom); + double step = 0.3; BezierSpline outline = brd.getOutline(); BezierSpline bottom = brd.getBottom(); - + GeneralPath path = new GeneralPath(); - path.moveTo(0.0,0.0); - for(double ox = 0; ox <= brd.getLength(); ox += step) - { - //Get the outline point and the angle - double oy = outline.getValueAt(ox)*(mirrorY?-1.0:1.0); - - //Find the length over deck curve - double length = bottom.getLengthByX(ox)*(mirrorX?-1.0:1.0); - -// System.out.printf("OC: %f, width %f\n", length, oy*2.0); - - //Draw lines + path.moveTo(0.0, 0.0); + for (double ox = 0; ox <= brd.getLength(); ox += step) { + // Get the outline point and the angle + double oy = outline.getValueAt(ox) * (mirrorY ? -1.0 : 1.0); + + // Find the length over deck curve + double length = bottom.getLengthByX(ox) * (mirrorX ? -1.0 : 1.0); + + // System.out.printf("OC: %f, width %f\n", length, oy*2.0); + + // Draw lines path.lineTo(length, oy); } d.draw(path); - - d.setTransform(savedTransform); - - if(printGuidePoints == true) - { - BezierBoardDrawUtil.paintGuidePoints(d, offsetX, offsetY, scale, Color.GRAY, stroke, brd.getOutlineGuidePoints(), false, false); + + resetTransform(d, savedTransform); + + if (printGuidePoints == true) { + BezierBoardDrawUtil.paintGuidePoints(d, offsetX, offsetY, scale, rotation, Color.GRAY, stroke, brd.getOutlineGuidePoints(), false, false); } - - if(printFins == true) - { - BezierBoardDrawUtil.paintFins(d, offsetX, offsetY, scale, Color.GRAY, stroke, brd.getFins(), false, false); + + if (printFins == true) { + BezierBoardDrawUtil.paintFins(d, offsetX, offsetY, scale, rotation, Color.GRAY, stroke, brd.getFins(), false, false); } } public static void printSpinTemplate(AbstractDraw d, double offsetX, - double offsetY, double rotation, double scale, boolean paintGrid, BezierBoard brd, boolean printGuidePoints, boolean printFins) { + double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, boolean printGuidePoints, boolean printFins) { + + if (brd.isEmpty()) { - if(brd.isEmpty()) { - return; - + } - if(brd.getOutline().getNrOfControlPoints() < 2) { + if (brd.getOutline().getNrOfControlPoints() < 2) { return; } + paintGrid(d, offsetX, offsetY, scale, rotation, new Color(128, 128, 128), brd.getLength(), brd.getMaxWidth() / 2, false, false); - paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), brd.getLength(), brd.getMaxWidth()/2, false, false); + GeneralPath outlineLower = makeBezierPathFromControlPoints(brd.getOutline(), false, false, false, false); - GeneralPath outlineLower = makeBezierPathFromControlPoints(brd.getOutline(),false,false, false,false); + GeneralPath outlineUpper = makeBezierPathFromControlPoints(brd.getOutline(), false, true, false, false); - GeneralPath outlineUpper = makeBezierPathFromControlPoints(brd.getOutline(),false,true, false,false); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, + // brd.mOutlineControlPoints, null, false, false); -// paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mOutlineControlPoints, null, false, false); + paintPath(d, offsetX, offsetY, scale, rotation, BoardCAD.getInstance().getBrdColor(), stroke, outlineLower, false); - paintPath(d,offsetX, offsetY, rotation, scale, BoardCAD.getInstance().getBrdColor(), stroke, outlineLower, false); + // Calculate offset + double xOffset = brd.getLength() / 2.0; + double yOffset = brd.getWidthAt(xOffset) / 2.0; - //Calculate offset - double xOffset = brd.getLength()/2.0; - double yOffset = brd.getWidthAt(xOffset)/2.0; - xOffset *= scale; yOffset *= scale; - + double rotationOffset = 0.0; - paintPath(d,offsetX-xOffset, offsetY+yOffset, rotation+rotationOffset, scale, BoardCAD.getInstance().getBrdColor(), stroke, outlineUpper, false); + paintPath(d, offsetX - xOffset, offsetY + yOffset, rotation + rotationOffset, scale, BoardCAD.getInstance().getBrdColor(), stroke, outlineUpper, false); } public static void printSpinTemplateOverCurve(AbstractDraw d, double offsetX, - double offsetY, double rotation, double scale, boolean paintGrid, BezierBoard brd, boolean printGuidePoints, boolean printFins) { + double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, boolean printGuidePoints, boolean printFins) { - if(brd.getOutline().getNrOfControlPoints() < 2) { + if (brd.getOutline().getNrOfControlPoints() < 2) { return; } - paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), brd.getLength(), brd.getMaxWidth()/2.0, false, false); + paintGrid(d, offsetX, offsetY, scale, rotation, new Color(128, 128, 128), brd.getLength(), brd.getMaxWidth() / 2.0, false, false); + + printOutlineOverCurve(d, offsetX, offsetY, scale, rotation, false, brd, printGuidePoints, printFins, false, false); + + // Calculate offset + double xOffset = brd.getBottom().getLengthByX(brd.getLength() / 2.0); + double yOffset = brd.getWidthAt(xOffset) / 2.0; - printOutlineOverCurve(d,offsetX, offsetY, rotation, scale, false, brd, printGuidePoints, printFins, false, false); - - //Calculate offset - double xOffset = brd.getBottom().getLengthByX(brd.getLength()/2.0); - double yOffset = brd.getWidthAt(xOffset)/2.0; - xOffset *= scale; yOffset *= scale; - + double rotationOffset = 0.0; - printOutlineOverCurve(d,offsetX-xOffset, offsetY+yOffset, rotation+rotationOffset, scale, false, brd, printGuidePoints, printFins, false, true); + printOutlineOverCurve(d, offsetX - xOffset, offsetY + yOffset, scale, rotation + rotationOffset, false, brd, printGuidePoints, printFins, false, true); } - -// Old functions orginating from printing + // Old functions orginating from printing public static void printProfile(AbstractDraw d, double offsetX, - double offsetY, double scale, boolean paintGrid, BezierBoard brd, Boolean printGuidePoints) { + double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, Boolean printGuidePoints) { - if(brd.getDeck().getNrOfControlPoints() < 2) { + if (brd.getDeck().getNrOfControlPoints() < 2) { return; } - if(paintGrid) - paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), brd.getLength(), brd.getMaxRocker()/2.0, false, false); + if (paintGrid) + paintGrid(d, offsetX, offsetY, scale, rotation, new Color(128, 128, 128), brd.getLength(), brd.getMaxRocker() / 2.0, false, false); GeneralPath deck = makeBezierPathFromControlPoints(brd.getDeck(), false, false, false, false); GeneralPath bottom = makeBezierPathFromControlPoints(brd.getBottom(), false, false, false, false); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); -// paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, false, false); + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, + // false, false); -// paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mBottomControlPoints, false, false); + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, + // brd.mBottomControlPoints, false, false); - paintPath(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, deck, false); + paintPath(d, offsetX, offsetY, scale, rotation, BoardCAD.getInstance().getBrdColor(), stroke, deck, false); - paintPath(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, bottom, false); + paintPath(d, offsetX, offsetY, scale, rotation, BoardCAD.getInstance().getBrdColor(), stroke, bottom, false); - if(printGuidePoints == true) - { - BezierBoardDrawUtil.paintGuidePoints(d, offsetX, offsetY, scale, Color.GRAY, stroke, brd.getDeckGuidePoints(), false, false); - BezierBoardDrawUtil.paintGuidePoints(d, offsetX, offsetY, scale, Color.GRAY, stroke, brd.getBottomGuidePoints(), false, false); + if (printGuidePoints == true) { + BezierBoardDrawUtil.paintGuidePoints(d, offsetX, offsetY, scale, rotation, Color.GRAY, stroke, brd.getDeckGuidePoints(), false, false); + BezierBoardDrawUtil.paintGuidePoints(d, offsetX, offsetY, scale, rotation, Color.GRAY, stroke, brd.getBottomGuidePoints(), false, false); } } - - - -// Old functions orginating from printing - public static void printSlice(AbstractDraw d, double offsetX, double offsetY, double scale, boolean paintGrid, BezierBoard brd, int i, boolean printGuidePoints) { + // Old functions orginating from printing + public static void printSlice(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, int i, boolean printGuidePoints) { BezierBoardCrossSection crs = brd.getCrossSections().get(i); - if(crs.getBezierSpline().getNrOfControlPoints() < 2) { + if (crs.getBezierSpline().getNrOfControlPoints() < 2) { return; } - if(paintGrid) - paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), crs.getWidth(), crs.getCenterThickness(), false, false); + if (paintGrid) + paintGrid(d, offsetX, offsetY, scale, rotation, new Color(128, 128, 128), crs.getWidth(), crs.getCenterThickness(), false, false); GeneralPath crsPath = makeBezierPathFromControlPoints(crs.getBezierSpline(), false, false, false, false); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); -// paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, false, false); + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, + // false, false); -// paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mBottomControlPoints, false, false); + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, + // brd.mBottomControlPoints, false, false); - paintPath(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, crsPath, false); + paintPath(d, offsetX, offsetY, scale, rotation, BoardCAD.getInstance().getBrdColor(), stroke, crsPath, false); - if(printGuidePoints == true) - { - BezierBoardDrawUtil.paintGuidePoints(d, offsetX, offsetY, scale, Color.GRAY, stroke, crs.getGuidePoints(), false, false); + if (printGuidePoints == true) { + BezierBoardDrawUtil.paintGuidePoints(d, offsetX, offsetY, scale, rotation, Color.GRAY, stroke, crs.getGuidePoints(), false, false); } } - - //Old functions orginating from printing - public static void printRailTemplate(AbstractDraw d, double offsetX, double offsetY, double scale, boolean paintGrid, BezierBoard brd, double distanceFromRail, double skinThickness, double tailOffset, double noseOffset, boolean flatten) - { - - if(brd.isEmpty()) { + // Old functions orginating from printing + public static void printRailTemplate(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, double distanceFromRail, + double skinThickness, double tailOffset, double noseOffset, boolean flatten) { + + if (brd.isEmpty()) { return; } - - int verticalLines = 0; - int horizontalLines = 0; - while(brd.getLength()/2.54 > verticalLines)verticalLines+=6; - while((brd.getMaxRocker()/2)/2.54 > horizontalLines)horizontalLines+=6; - - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + int verticalLines = 0; + int horizontalLines = 0; + while (brd.getLength() / 2.54 > verticalLines) + verticalLines += 6; + while ((brd.getMaxRocker() / 2) / 2.54 > horizontalLines) + horizontalLines += 6; + + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(0,0,0)); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, false, false); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mBottomControlPoints, false, false); - - // paintBezierSpline(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, deck); - - // paintBezierSpline(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, bottom); - + d.setColor(new Color(0, 0, 255)); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, + // false, false); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, + // brd.mBottomControlPoints, false, false); + + // paintBezierSpline(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, deck); + + // paintBezierSpline(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, bottom); + BezierSpline outline = brd.getOutline(); - + System.out.printf("\nRAIL\n"); boolean first = true; - double lastPos = 0; + double lastPos = tailOffset; double lastX = 0; double lastY = 0; double lastDeck = 0; double lastBottom = 0; - Line2D line = new Line2D.Double(); - - double length = brd.getLength()-tailOffset-noseOffset; - int steps = (int)(length/0.5); - - double step = length/steps; + // Line2D line = new Line2D.Double(); + + double length = brd.getLength() - tailOffset - noseOffset; + int steps = (int) (length / 0.5); + + double step = length / steps; GeneralPath path = new GeneralPath(); int i = 0; double x = 0.0; double y = 0.0; double ox = 0; - for(; i <= steps; i++) - { + for (; i <= steps; i++) { + + ox = tailOffset + i * step; - ox = tailOffset + i*step; - - //Get the outline point and the angle + // Get the outline point and the angle double oy = outline.getValueAt(ox); double normalAngle = outline.getNormalAngle(ox); - - //Find the target point at distance from outline - x = ox - (distanceFromRail*Math.sin(normalAngle)); - y = oy - (distanceFromRail*Math.cos(normalAngle)); - if(first && y < 0) + // Find the target point at distance from outline + x = ox - (distanceFromRail * Math.sin(normalAngle)); + y = oy - (distanceFromRail * Math.cos(normalAngle)); + + if (first && y < 0) continue; - if(!first && y < 0) + if (!first && y < 0) break; - //Find thickness and rocker at pos - double deck = getDeck(brd, x, y, skinThickness); - double bottom = getBottom(brd, x, y, skinThickness); - - if(first && deck < bottom) + // Find thickness and rocker at pos + double deck = getDeckWithSkinCompensation(brd, x, y, skinThickness); + double bottom = getBottomWithSkinCompensation(brd, x, y, skinThickness); + + // System.out.printf("printRailTemplate ox: %f oy: %f Normal: %f x: %f y: %f Deck: %f Bottom: %f\n", + // ox,oy,normalAngle/MathUtils.DEG_TO_RAD, x,y, deck, bottom); + + if (first && deck < bottom) continue; - if(!first && deck < bottom) + if (!first && deck < bottom) break; - - if(flatten) - { - double deckRockerCompensation = brd.getDeck().getValueAt(x) - brd.getThickness(); + + if (flatten) { + double deckRockerCompensation = brd.getDeck().getValueAt(x) - brd.getThickness(); deck -= deckRockerCompensation; bottom -= deckRockerCompensation; } -// System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); + if (!first) { + // Find the 2D length from the last point on deck and bottom + double xd = x - lastX; + double yd = y - lastY; + double span = Math.sqrt((xd * xd) + (yd * yd)); - if(!first) - { - //Find the 2D length from the last point on deck and bottom - double xd = x-lastX; - double yd = y-lastY; - double span = Math.sqrt((xd*xd)+(yd*yd)); - double newPos = lastPos + span; - - //Draw lines - path.lineTo(newPos,deck); - - //Update last pos + + // Draw lines + path.lineTo(newPos, deck); + + // Update last pos lastPos = newPos; - } - else - { + } else { first = false; path.moveTo(lastPos, deck); } @@ -2334,176 +2067,185 @@ public static void printRailTemplate(AbstractDraw d, double offsetX, double offs lastY = y; lastDeck = deck; lastBottom = bottom; - + } + // d.draw(path); + // path.reset(); - System.out.printf("Rail tip of nose pos at %f, deck:%f bottom:%f", ox, lastDeck, lastBottom ); + System.out.printf("Rail tip of nose pos at %f, deck:%f bottom:%f\n", ox, lastDeck, lastBottom); first = true; - for(; i > 0; i--) - { + for (; i >= 0; i--) { + + ox = tailOffset + i * step; - ox = tailOffset + i*step; - - //Get the outline point and the angle + // Get the outline point and the angle double oy = outline.getValueAt(ox); double normalAngle = outline.getNormalAngle(ox); - - //Find the target point at distance from outline - x = ox - (distanceFromRail*Math.sin(normalAngle)); - y = oy - (distanceFromRail*Math.cos(normalAngle)); - if(first && y < 0) + // Find the target point at distance from outline + x = ox - (distanceFromRail * Math.sin(normalAngle)); + y = oy - (distanceFromRail * Math.cos(normalAngle)); + + if (first && y < 0) continue; - if(!first && y < 0) + if (!first && y < 0) break; - //Find thickness and rocker at pos - double deck = getDeck(brd, x, y, skinThickness); - double bottom = getBottom(brd, x, y, skinThickness); - - if(first && deck < bottom) + // Find thickness and rocker at pos + double deck = getDeckWithSkinCompensation(brd, x, y, skinThickness); + double bottom = getBottomWithSkinCompensation(brd, x, y, skinThickness); + + if (first && deck < bottom) continue; - if(!first && deck < bottom) + if (!first && deck < bottom) break; - - if(flatten) - { - double deckRockerCompensation = brd.getDeck().getValueAt(x) - brd.getThickness(); + + if (flatten) { + double deckRockerCompensation = brd.getDeck().getValueAt(x) - brd.getThickness(); deck -= deckRockerCompensation; bottom -= deckRockerCompensation; } -// System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); + // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", + // ox,oy,normalAngle/MathUtils.DEG_TO_RAD, x,y, deck, bottom); + + if (!first) { + // Find the 2D length from the last point on deck and bottom + double xd = x - lastX; + double yd = y - lastY; + double span = Math.sqrt((xd * xd) + (yd * yd)); - if(!first) - { - //Find the 2D length from the last point on deck and bottom - double xd = x-lastX; - double yd = y-lastY; - double span = Math.sqrt((xd*xd)+(yd*yd)); - double newPos = lastPos - span; - - //Draw lines + + // Draw lines path.lineTo(newPos, bottom); - - //Update last pos + + // Update last pos lastPos = newPos; - } - else - { + } else { first = false; + // Draw lines + path.lineTo(lastPos, bottom); } lastX = x; lastY = y; lastDeck = deck; lastBottom = bottom; - + + } + + if (hasMoveTo(path)) { + path.closePath(); } - path.closePath(); d.draw(path); - d.setTransform(savedTransform); - + resetTransform(d, savedTransform); + } - - //Old functions orginating from printing - public static void printDeckSkinTemplate(AbstractDraw d, double offsetX, double offsetY, double scale, boolean paintGrid, BezierBoard brd, double distanceFromRail) { - - if(brd.isEmpty()) { - + + // Old functions orginating from printing + public static void printDeckSkinTemplate(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, double distanceFromRail) { + + if (brd.isEmpty()) { + return; - + } - + System.out.printf("\nDECK\n"); - int verticalLines = 0; - int horizontalLines = 0; - while(brd.getLength()/2.54 > verticalLines)verticalLines+=6; - while((brd.getMaxWidth()/2)/2.54 > horizontalLines)horizontalLines+=6; - -// paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), verticalLines, horizontalLines, false, false); - - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + int verticalLines = 0; + int horizontalLines = 0; + while (brd.getLength() / 2.54 > verticalLines) + verticalLines += 6; + while ((brd.getMaxWidth() / 2) / 2.54 > horizontalLines) + horizontalLines += 6; + + // paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), + // verticalLines, horizontalLines, false, false); + + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(0,0,0)); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, false, false); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mBottomControlPoints, false, false); - - // paintBezierSpline(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, deck); - - // paintBezierSpline(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, bottom); - + d.setColor(new Color(0, 0, 0)); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, + // false, false); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, + // brd.mBottomControlPoints, false, false); + + // paintBezierSpline(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, deck); + + // paintBezierSpline(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, bottom); + double step = 1.0; BezierSpline outline = brd.getOutline(); BezierSpline deck = brd.getDeck(); - + boolean first = true; double lastPos = 0; double lastLength = 0; double lastWidth = 0; Line2D line = new Line2D.Double(); - for(double ox = 0; ox < brd.getLength(); ox += step) - { - //Get the outline point and the angle + for (double ox = 0; ox < brd.getLength(); ox += step) { + // Get the outline point and the angle double oy = outline.getValueAt(ox); double normalAngle = outline.getNormalAngle(ox); - - //Find the target point at distance from outline - double x = ox - (distanceFromRail*Math.sin(normalAngle)); - double y = oy - (distanceFromRail*Math.cos(normalAngle)); - if(first && y < 0) + // Find the target point at distance from outline + double x = ox - (distanceFromRail * Math.sin(normalAngle)); + double y = oy - (distanceFromRail * Math.cos(normalAngle)); + + if (first && y < 0) continue; - if(!first && y < 0) + if (!first && y < 0) break; - -// System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f\n", ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y); - //Find the length over deck curve + // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f\n", + // ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y); + + // Find the length over deck curve double length = deck.getLengthByX(x); - - //Find the width of the template at this point accounting for over curve + + // Find the width of the template at this point accounting for over + // curve double width = 0; double lastz = brd.getDeckAt(x, 0.0); double splits = 10; - double step_y = y/splits; - for(int i = 0; i < splits; i++) - { - double z = brd.getDeckAt(x, i*step_y); - + double step_y = y / splits; + for (int i = 0; i < splits; i++) { + double z = brd.getDeckAt(x, i * step_y); + double dz = z - lastz; - double span = Math.sqrt((step_y*step_y)+(dz*dz)); + double span = Math.sqrt((step_y * step_y) + (dz * dz)); -// System.out.printf("z %f\n", z); + // System.out.printf("z %f\n", z); lastz = z; width += span; } - -// System.out.printf("width %f\n", width); - - if(!first) - { - double newPos = lastPos + (length - lastLength); - - //Draw lines + + // System.out.printf("width %f\n", width); + + if (!first) { + double newPos = lastPos + (length - lastLength); + + // Draw lines line.setLine(lastPos, lastWidth, newPos, width); d.draw(line); - + lastPos = newPos; - } - else - { + } else { first = false; } @@ -2511,101 +2253,106 @@ public static void printDeckSkinTemplate(AbstractDraw d, double offsetX, double lastWidth = width; } - d.setTransform(savedTransform); - + resetTransform(d, savedTransform); + } - //Old functions orginating from printing - public static void printBottomSkinTemplate(AbstractDraw d, double offsetX, double offsetY, double scale, boolean paintGrid, BezierBoard brd, double distanceFromRail) - { - if(brd.isEmpty()) { - + // Old functions orginating from printing + public static void printBottomSkinTemplate(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, double distanceFromRail) { + if (brd.isEmpty()) { + return; - + } - + System.out.printf("\nBOTTOM\n"); - int verticalLines = 0; - int horizontalLines = 0; - while(brd.getLength()/2.54 > verticalLines)verticalLines+=6; - while((brd.getMaxWidth()/2)/2.54 > horizontalLines)horizontalLines+=6; - -// paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), verticalLines, horizontalLines, false, false); - - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + int verticalLines = 0; + int horizontalLines = 0; + while (brd.getLength() / 2.54 > verticalLines) + verticalLines += 6; + while ((brd.getMaxWidth() / 2) / 2.54 > horizontalLines) + horizontalLines += 6; + + // paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), + // verticalLines, horizontalLines, false, false); + + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(0,0,0)); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, false, false); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mBottomControlPoints, false, false); - - // paintBezierSpline(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, deck); - - // paintBezierSpline(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, bottom); - + d.setColor(new Color(0, 0, 0)); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, + // false, false); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, + // brd.mBottomControlPoints, false, false); + + // paintBezierSpline(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, deck); + + // paintBezierSpline(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, bottom); + double step = 1.0; BezierSpline outline = brd.getOutline(); BezierSpline bottom = brd.getBottom(); - + boolean first = true; double lastPos = 0; double lastLength = 0; double lastWidth = 0; Line2D line = new Line2D.Double(); - for(double ox = 0; ox < brd.getLength(); ox += step) - { - //Get the outline point and the angle + for (double ox = 0; ox < brd.getLength(); ox += step) { + // Get the outline point and the angle double oy = outline.getValueAt(ox); double normalAngle = outline.getNormalAngle(ox); - - //Find the target point at distance from outline - double x = ox - (distanceFromRail*Math.sin(normalAngle)); - double y = oy - (distanceFromRail*Math.cos(normalAngle)); - if(first && y < 0) + // Find the target point at distance from outline + double x = ox - (distanceFromRail * Math.sin(normalAngle)); + double y = oy - (distanceFromRail * Math.cos(normalAngle)); + + if (first && y < 0) continue; - if(!first && y < 0) + if (!first && y < 0) break; - -// System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f\n", ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y); - //Find the length over deck curve + // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f\n", + // ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y); + + // Find the length over deck curve double length = bottom.getLengthByX(x); - - //Find the width of the template at this point accounting for over curve + + // Find the width of the template at this point accounting for over + // curve double width = 0; double lastz = brd.getBottomAt(x, 0.0); double splits = 10; - double step_y = y/splits; - for(int i = 0; i < splits; i++) - { - double z = brd.getBottomAt(x, i*step_y); - + double step_y = y / splits; + for (int i = 0; i < splits; i++) { + double z = brd.getBottomAt(x, i * step_y); + double dz = z - lastz; - double span = Math.sqrt((step_y*step_y)+(dz*dz)); + double span = Math.sqrt((step_y * step_y) + (dz * dz)); lastz = z; width += span; } - -// System.out.printf("width %f\n", width); - - if(!first) - { - double newPos = lastPos + (length - lastLength); - - //Draw lines + + // System.out.printf("width %f\n", width); + + if (!first) { + double newPos = lastPos + (length - lastLength); + + // Draw lines line.setLine(lastPos, lastWidth, newPos, width); d.draw(line); - + lastPos = newPos; - } - else - { + } else { first = false; } @@ -2613,392 +2360,393 @@ public static void printBottomSkinTemplate(AbstractDraw d, double offsetX, doubl lastWidth = width; } - d.setTransform(savedTransform); - + resetTransform(d, savedTransform); + } - public static void printCrossSection(AbstractDraw d, double offsetX, double offsetY, double scale, boolean paintGrid, BezierBoard brd, double position) - { - if(brd.isEmpty()) { - + public static void printCrossSection(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, double position) { + if (brd.isEmpty()) { + return; - + } - - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(0,0,0)); - + d.setColor(new Color(0, 0, 0)); + System.out.printf("\nCROSSSECTION\n"); int steps = 300; - + double x = position; - + GeneralPath path = new GeneralPath(); - + double s = 0.0; - //Find thickness and rocker at pos + // Find thickness and rocker at pos Point2D.Double current = brd.getSurfacePointAtPos(x, s); path.moveTo(current.x, current.y); - for(int i = 1; i <= steps; i++) - { - s = (double)i/steps; - - //Find thickness and rocker at pos + for (int i = 1; i <= steps; i++) { + s = (double) i / steps; + + // Find thickness and rocker at pos current = brd.getSurfacePointAtPos(x, s); - - //System.out.printf("Outline x: %f s: %f current: %f %f \n", x, s, current.x, current.y); + + // System.out.printf("Outline x: %f s: %f current: %f %f \n", x, s, + // current.x, current.y); path.lineTo(current.x, current.y); - + } - path.closePath(); + + if (hasMoveTo(path)) { + path.closePath(); + } + d.draw(path); - d.setTransform(savedTransform); - + resetTransform(d, savedTransform); + } - //Old functions orginating from printing - public static void printCrossSection(AbstractDraw d, double offsetX, double offsetY, double scale, boolean paintGrid, BezierBoard brd, double position, double railOffset, double skinThickness) - { - if(brd.isEmpty()) { - + // Old functions orginating from printing + public static void printCrossSection(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, double position, double railOffset, + double skinThickness) { + if (brd.isEmpty()) { + return; - + } - - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(0,0,0)); - + d.setColor(new Color(0, 0, 0)); + System.out.printf("\nCROSSSECTION\n"); GeneralPath path = new GeneralPath(); + double halfWidth = brd.getWidthAt(position) / 2.0f; - double halfWidth = brd.getWidthAt(position)/2.0f; - double outlineAngle = Math.abs(brd.getOutline().getTangentAt(position)); - + double sinOutline = Math.sin(outlineAngle); - - halfWidth -= railOffset/sinOutline; - Vector3d upVector = new Vector3d(0.0, 0.0, 1.0); + halfWidth -= railOffset / sinOutline; int steps = 150; - + double x = position; - + boolean first = true; - //Deck - for(int i = 0; i <= steps; i++) - { - double y = i* halfWidth / steps; - - //Find thickness and rocker at pos + // Deck + for (int i = 0; i <= steps; i++) { + double y = i * halfWidth / steps; + + // Find thickness and rocker at pos double deck = brd.getDeckAt(x, y); - - if(skinThickness != 0.0) - { + + if (skinThickness != 0.0) { Vector3d deckNormal = brd.getDeckNormalAt(x, y); - + double upAngle = upVector.angle(deckNormal); - double deckSkinCompensation = skinThickness/Math.cos(upAngle); - + double deckSkinCompensation = skinThickness / Math.cos(upAngle); + deck += deckSkinCompensation; } - // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); + // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", + // ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); - if(!first) - { - //Draw lines + if (!first) { + // Draw lines path.lineTo(y, deck); - } - else - { + } else { path.moveTo(y, deck); first = false; } - } - - //Bottom - for(int i = 0; i <= steps; i++) - { - double y = halfWidth - (i* halfWidth / steps); - - //Find thickness and rocker at pos + + // Bottom + for (int i = 0; i <= steps; i++) { + double y = halfWidth - (i * halfWidth / steps); + + // Find thickness and rocker at pos double bottom = brd.getBottomAt(x, y); - - if(skinThickness != 0.0) - { + + if (skinThickness != 0.0) { Vector3d bottomNormal = brd.getBottomNormalAt(x, y); - - double downAngle = upVector.angle(bottomNormal); - double bottomSkinCompensation = skinThickness/Math.cos(downAngle); - + double downAngle = downVector.angle(bottomNormal); + + double bottomSkinCompensation = skinThickness / Math.cos(downAngle); + bottom -= bottomSkinCompensation; } - // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); + // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", + // ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); - //Draw lines + // Draw lines path.lineTo(y, bottom); - } - path.closePath(); + if (hasMoveTo(path)) { + path.closePath(); + } + d.draw(path); - if(railOffset > 0.0) - { - //Find thickness and rocker at pos + if (railOffset > 0.0) { + // Find thickness and rocker at pos double deck = brd.getDeckAt(x, halfWidth); - double bottom = brd.getBottomAt(x, halfWidth); + double bottom = brd.getBottomAt(x, halfWidth); d.draw(new Line2D.Double(halfWidth, deck, halfWidth, bottom)); } - - d.setTransform(savedTransform); - + + resetTransform(d, savedTransform); + } - - //Old functions orginating from printing - public static void printProfile(AbstractDraw d, double offsetX, double offsetY, double scale, boolean paintGrid, BezierBoard brd, double offset, double skinThickness, boolean flatten, double tailOffset, double noseOffset) - { - printProfile(d, new Color(0,0,0), 2.0, offsetX, offsetY, scale, paintGrid, brd, offset, skinThickness, flatten, tailOffset, noseOffset); + + // Old functions orginating from printing + public static void printProfile(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, double offset, double skinThickness, + boolean flatten, double tailOffset, double noseOffset) { + printProfile(d, new Color(0, 0, 0), 2.0, offsetX, offsetY, scale, rotation, paintGrid, brd, offset, skinThickness, flatten, tailOffset, noseOffset); } - - //Old functions orginating from printing - public static void printProfile(AbstractDraw d, Color color, double lineWidth, double offsetX, double offsetY, double scale, boolean paintGrid, BezierBoard brd, double offset, double skinThickness, boolean flatten, double tailOffset, double noseOffset) - { - if(brd.isEmpty()){ + + // Old functions orginating from printing + public static void printProfile(AbstractDraw d, Color color, double lineWidth, double offsetX, double offsetY, double scale, double rotation, boolean paintGrid, BezierBoard brd, double offset, + double skinThickness, boolean flatten, double tailOffset, double noseOffset) { + if (brd.isEmpty()) { return; } - + System.out.printf("\nPROFILE\n"); - if(paintGrid){ - paintGrid(d, offsetX, offsetY, scale, new Color(128,128,128), brd.getLength(), brd.getMaxRocker(), false, false); + if (paintGrid) { + paintGrid(d, offsetX, offsetY, scale, rotation, new Color(128, 128, 128), brd.getLength(), brd.getMaxRocker(), false, false); } - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(lineWidth/scale)); + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (lineWidth / scale)); d.setStroke(stroke); d.setColor(color); boolean first = true; - + double length = brd.getLength() - (tailOffset + noseOffset); - int steps = (int)(length/0.3); - double step = length/steps; + int steps = (int) (length / 0.3); + double step = length / steps; GeneralPath path = new GeneralPath(); - + double y = offset; - //Deck + // Deck double x = tailOffset; - for(int i = 0; i <= steps; i++) - { - x = i*step + tailOffset; - - //Find thickness and rocker at pos - double deck = (skinThickness!=0.0)?getDeck(brd, x, y, skinThickness):brd.getDeckAt(x, y); - - double bottom = (skinThickness!=0.0)?getBottom(brd, x, y, skinThickness):brd.getBottomAt(x, y); - if(flatten) - { - double deckRockerCompensation = brd.getDeck().getValueAt(x) - brd.getThickness(); + for (int i = 0; i <= steps; i++) { + x = i * step + tailOffset; + + // Find thickness and rocker at pos + double deck = (skinThickness != 0.0) ? getDeckWithSkinCompensation(brd, x, y, skinThickness) : brd.getDeckAt(x, y); + + double bottom = (skinThickness != 0.0) ? getBottomWithSkinCompensation(brd, x, y, skinThickness) : brd.getBottomAt(x, y); + if (flatten) { + double deckRockerCompensation = brd.getDeck().getValueAt(x) - brd.getThickness(); deck -= deckRockerCompensation; bottom -= deckRockerCompensation; } -// System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); - if(bottom >= deck) - { - if(first) - { - path.moveTo(x,deck); - } - else - { + // System.out.printf("Profile x: %f y: %f Deck: %f Bottom: %f\n", + // x,y, deck, bottom); + if (bottom >= deck) { + // System.out.printf("Profile bottom >= deck, skinThickness:%f x: %f y: %f Deck: %f Bottom: %f\n", + // skinThickness, x,y, deck, bottom); + bottom = (skinThickness != 0.0) ? getBottomWithSkinCompensation(brd, x, y, skinThickness) : brd.getBottomAt(x, y); + deck = (skinThickness != 0.0) ? getDeckWithSkinCompensation(brd, x, y, skinThickness) : brd.getDeckAt(x, y); + if (first) { + path.moveTo(x, deck); + } else { break; } - } - else{ - if(first) - { - path.moveTo(x,deck); + } else { + if (first) { + path.moveTo(x, deck); first = false; continue; } path.lineTo(x, deck); } } - - System.out.printf("At end of profile x:%f\n", x); - //Bottom + System.out.printf("At end of deck x:%f\n", x); + + // Bottom first = true; - for(int i = 0; i <= steps; i++) - { - x = length + tailOffset - (i*step); - - //Find thickness and rocker at pos - double bottom = (skinThickness!=0.0)? getBottom(brd, x, y, skinThickness):brd.getBottomAt(x, y); - - double deck = (skinThickness!=0.0)?getDeck(brd, x, y, skinThickness):brd.getDeckAt(x,y); - if(flatten) - { - double bottomRockerCompensation = brd.getDeck().getValueAt(x) - brd.getThickness(); + for (int i = 0; i <= steps; i++) { + x = length + tailOffset - (i * step); + + // Find thickness and rocker at pos + double bottom = (skinThickness != 0.0) ? getBottomWithSkinCompensation(brd, x, y, skinThickness) : brd.getBottomAt(x, y); + + double deck = (skinThickness != 0.0) ? getDeckWithSkinCompensation(brd, x, y, skinThickness) : brd.getDeckAt(x, y); + if (flatten) { + double bottomRockerCompensation = brd.getDeck().getValueAt(x) - brd.getThickness(); bottom -= bottomRockerCompensation; deck -= bottomRockerCompensation; } + // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f bottom: %f Bottom: %f\n", + // ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, bottom, bottom); -// System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f bottom: %f Bottom: %f\n", ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, bottom, bottom); - - - if(bottom >= deck) - { + if (bottom >= deck) { continue; -// path.moveTo(x,bottom); - } - else{ - if(first) - { -// path.moveTo(x,bottom); + // path.moveTo(x,bottom); + } else { + if (first) { + // path.moveTo(x,bottom); first = false; -// continue; + // continue; } path.lineTo(x, bottom); } } - - path.closePath(); + + if (hasMoveTo(path)) { + path.closePath(); + } + d.draw(path); - d.setTransform(savedTransform); - + resetTransform(d, savedTransform); + } - public static void paintFunction(AbstractDraw d, double offsetX, double offsetY, double scale, Color color, Stroke stroke, Function func, double minLimit, double maxLimit, double horizontalScale, double verticalScale) - { + public static void paintFunction(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, Color color, Stroke stroke, Function func, double minLimit, double maxLimit, + double horizontalScale, double verticalScale) { d.setColor(color); d.setStroke(stroke); - AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale); - + AffineTransform savedTransform = setTransform(d, offsetX, offsetY, scale, rotation); int splits = 100; - double step = (maxLimit-minLimit)/splits; - + double step = (maxLimit - minLimit) / splits; + double x = minLimit; double lastValue = func.f(x); - + Line2D.Double l = new Line2D.Double(); - for(int i = 1; i < splits; i++) - { - double currentValue = func.f(x+step); - - l.setLine(x*horizontalScale, lastValue*verticalScale, (x+step)*horizontalScale, currentValue*verticalScale); + for (int i = 1; i < splits; i++) { + double currentValue = func.f(x + step); + + l.setLine(x * horizontalScale, lastValue * verticalScale, (x + step) * horizontalScale, currentValue * verticalScale); d.draw(l); - + x += step; lastValue = currentValue; } - - resetTransform(d,savedTransform); + resetTransform(d, savedTransform); } - public static double getDeck(AbstractBoard board, double x, double y, double skinThickness) - { - //Find thickness and rocker at pos + public static double getDeckWithSkinCompensation(AbstractBoard board, double x, double y, double skinThickness) { + // Find thickness and rocker at pos double deck = board.getDeckAt(x, y); - + Vector3d deckNormal = board.getDeckNormalAt(x, y); - + double upAngle = upVector.angle(deckNormal); - - double deckSkinCompensation = skinThickness/Math.cos(upAngle); - + + double deckSkinCompensation = skinThickness / Math.cos(upAngle); + deck += deckSkinCompensation; return deck; } - - public static double getBottom(AbstractBoard board, double x, double y, double skinThickness) - { - //Find thickness and rocker at pos + public static double getBottomWithSkinCompensation(AbstractBoard board, double x, double y, double skinThickness) { + + // Find thickness and rocker at pos double bottom = board.getBottomAt(x, y); Vector3d bottomNormal = board.getBottomNormalAt(x, y); - - double upAngle = upVector.angle(bottomNormal); - double bottomSkinCompensation = skinThickness/Math.cos(upAngle); - + double normalAngle = downVector.angle(bottomNormal); + + double bottomSkinCompensation = skinThickness / Math.cos(normalAngle); + + // System.out.printf("getBottomWithSkinCompensation() bottom: %f, skinThickness:%f normal: %f, %f, %f normalAngle: %f\n", + // bottom, skinThickness, bottomNormal.x,bottomNormal.y,bottomNormal.z, + // normalAngle); + bottom -= bottomSkinCompensation; - + return bottom; } - public static Point2D.Double getOutline(AbstractBoard board, double x, double distanceFromRail) - { - BezierSpline outline = ((BezierBoard)board).getOutline(); - + public static Point2D.Double getOutline(AbstractBoard board, double x, double distanceFromRail) { + BezierSpline outline = ((BezierBoard) board).getOutline(); + double oy = outline.getValueAt(x); double normalAngle = outline.getNormalAngle(x); - + Point2D.Double point = new Point2D.Double(); - - //Find the point at distance from outline - point.x = x - ( (distanceFromRail )*Math.sin(normalAngle)); - point.y = oy - ( (distanceFromRail )*Math.cos(normalAngle)); - + + // Find the point at distance from outline + point.x = x - ((distanceFromRail) * Math.sin(normalAngle)); + point.y = oy - ((distanceFromRail) * Math.cos(normalAngle)); + return point; } - public static double getRailDeck(AbstractBoard board, double pos, double distanceFromRail, double skinThickness) - { - BezierSpline outline = ((BezierBoard)board).getOutline(); + public static double getRailDeck(AbstractBoard board, double pos, double distanceFromRail, double skinThickness) { + BezierSpline outline = ((BezierBoard) board).getOutline(); double oy = outline.getValueAt(pos); double normalAngle = outline.getNormalAngle(pos); - - //Find the target point at distance from outline - double x = pos - (distanceFromRail*Math.sin(normalAngle)); - double y = oy - (distanceFromRail*Math.cos(normalAngle)); - - return getDeck(board, x, y, skinThickness); + + // Find the target point at distance from outline + double x = pos - (distanceFromRail * Math.sin(normalAngle)); + double y = oy - (distanceFromRail * Math.cos(normalAngle)); + + System.out.printf("getRailDeck() pos:%f distanceFromRail:%f normalAngle:%f x:%f y:%f\n", pos, distanceFromRail, Math.toDegrees(normalAngle), x, y); + + return getDeckWithSkinCompensation(board, x, y, skinThickness); } - - public static double getRailBottom(AbstractBoard board, double pos, double distanceFromRail, double skinThickness) - { - BezierSpline outline = ((BezierBoard)board).getOutline(); + + public static double getRailBottom(AbstractBoard board, double pos, double distanceFromRail, double skinThickness) { + BezierSpline outline = ((BezierBoard) board).getOutline(); double oy = outline.getValueAt(pos); double normalAngle = outline.getNormalAngle(pos); - - //Find the target point at distance from outline - double x = pos - (distanceFromRail*Math.sin(normalAngle)); - double y = oy - (distanceFromRail*Math.cos(normalAngle)); - - return getBottom(board, x, y, skinThickness); + + // Find the target point at distance from outline + double x = pos - (distanceFromRail * Math.sin(normalAngle)); + double y = oy - (distanceFromRail * Math.cos(normalAngle)); + + System.out.printf("getRailBottom() pos:%f distanceFromRail:%f normalAngle:%f x:%f y:%f\n", pos, distanceFromRail, Math.toDegrees(normalAngle), x, y); + + return getBottomWithSkinCompensation(board, x, y, skinThickness); + } + + public static boolean hasMoveTo(GeneralPath path) { + PathIterator it = path.getPathIterator(null); + while (!it.isDone()) { + double[] coords = new double[6]; + if (it.currentSegment(coords) == PathIterator.SEG_MOVETO) { + return true; + } + it.next(); + } + return false; } } diff --git a/boardcad/gui/jdk/BoardCAD.java b/boardcad/gui/jdk/BoardCAD.java index 65446e9..ac46bbd 100644 --- a/boardcad/gui/jdk/BoardCAD.java +++ b/boardcad/gui/jdk/BoardCAD.java @@ -12,7 +12,17 @@ */ +/** + * @author Håvard + + * + + * To change the template for this generated type comment go to + + * Window>Preferences>Java>Code Generation>Code and Comments + + */ import java.awt.*; import java.awt.event.*; @@ -28,6 +38,7 @@ import java.io.PrintStream; import java.util.*; import java.util.Locale; +import java.util.Timer; import java.util.prefs.*; import javax.imageio.ImageIO; @@ -40,7 +51,6 @@ import cadcore.*; import board.*; - import boardcad.settings.*; import boardcad.gui.jdk.plugin.*; import boardcad.DefaultBrds; @@ -49,9 +59,10 @@ import boardcad.settings.Settings.Enumeration; import boardcad.settings.Settings.SettingChangedCallback; import boardcad.settings.Settings; +import boardcad.commands.*; import boardcad.export.DxfExport; +import boardcad.export.GCodeDraw; import boardcad.i18n.LanguageResource; - import boardcam.cutters.AbstractCutter; import boardcam.MachineConfig; import boardcam.Scan; @@ -62,12 +73,13 @@ import boardcam.writers.GCodeWriter; import board.readers.*; import board.writers.*; - import boardcad.ScriptLoader; public class BoardCAD implements Runnable, ActionListener, ItemListener, KeyEventDispatcher { - enum DeckOrBottom{DECK, BOTTOM, BOTH}; + enum DeckOrBottom { + DECK, BOTTOM, BOTH + }; protected BezierBoard mCurrentBrd; @@ -75,7 +87,7 @@ enum DeckOrBottom{DECK, BOTTOM, BOTH}; private BezierBoard mGhostBrd; - static protected Locale[] mSupportedLanguages = {new Locale("en",""), new Locale("fr",""), new Locale("pt",""), new Locale("es",""), new Locale("no",""), new Locale("nl","")}; + static protected Locale[] mSupportedLanguages = { new Locale("en", ""), new Locale("fr", ""), new Locale("pt", ""), new Locale("es", ""), new Locale("no", ""), new Locale("nl", "") }; private BrdCommand mCurrentCommand; @@ -86,18 +98,20 @@ enum DeckOrBottom{DECK, BOTTOM, BOTH}; private PrintSandwichTemplates mPrintSandwichTemplates; private PrintChamberedWoodTemplate mPrintChamberedWoodTemplate; private PrintHollowWoodTemplates mPrintHollowWoodTemplates; - + private boolean mBlockGUI = true; private QuadView fourView; + public QuadView getFourView() { - return fourView; + https: // www.facebook.com/nikolai.schirmer/videos/840922619608069/?t=330 + return fourView; } - public String getFourViewName() - { + + public String getFourViewName() { return getFourView().getActive().getName(); } - + private BoardEdit view1; private BoardEdit view2; private BoardEdit view3; @@ -127,7 +141,6 @@ public String getFourViewName() JPanel mNurbspanel; JPanel mRenderedpanel; - public JPanel mJOGLpanel; boolean mAlwaysApproximateNurbs = false; @@ -172,7 +185,7 @@ public String getFourViewName() private JCheckBoxMenuItem mIsPaintingCenterLineMenuItem; private JCheckBoxMenuItem mIsPaintingOverCurveMesurementsMenuItem; - + private JCheckBoxMenuItem mIsPaintingMomentOfInertiaMenuItem; private JCheckBoxMenuItem mIsPaintingCrossectionsPositionsMenuItem; @@ -184,7 +197,7 @@ public String getFourViewName() private JCheckBoxMenuItem mIsPaintingTuckUnderLineMenuItem; private JCheckBoxMenuItem mIsPaintingFootMarksMenuItem; - + private JCheckBoxMenuItem mIsAntialiasingMenuItem; private JCheckBoxMenuItem mUseFillMenuItem; @@ -201,20 +214,17 @@ public String getFourViewName() private JCheckBoxMenuItem mShowRenderInwireframe; - - JToggleButton mLifeSizeButton; + public JToggleButton mLifeSizeButton; private boolean mBoardChanged = false; - private boolean mBoardChangedFor3D = false; - protected boolean mGhostMode = false; protected boolean mOrgFocus = false; protected static BoardCAD mInstance = null; - private static final String appname = "BoardCAD v3.0"; + private static final String appname = "BoardCAD v3.1"; public static String defaultDirectory = ""; @@ -228,7 +238,7 @@ public String getFourViewName() protected DesignPanel design_panel; protected DesignPanel design_panel2; - public JOGLPanel joglpanel; + protected DesignPanel design_panel3; public StatusPanel status_panel; @@ -251,74 +261,39 @@ public String getFourViewName() private Settings mSizeSettings; private Settings mMiscSettings; - Switch mBezier3DOnSwitch; - Shape3D mBezier3DModel; - TransformGroup mScale; - - public JMenu scriptMenu; - BezierBoardCrossSection mCrossSectionCopy; + static private final String TEXTCOLOR = "textcolor"; static private final String BACKGROUNDCOLOR = "backgroundcolor"; - static private final String STRINGERCOLOR = "stringercolor"; - static private final String FLOWLINESCOLOR = "flowlinescolor"; - static private final String APEXLINECOLOR = "apexlinecolor"; - static private final String TUCKUNDERLINECOLOR = "tuckunderlinecolor"; - static private final String CENTERLINECOLOR = "centerlinecolor"; - static private final String BRDCOLOR = "brdcolor"; - static private final String ORIGINALCOLOR = "originalcolor"; - static private final String GHOSTCOLOR = "ghostcolor"; - static private final String BLANKCOLOR = "blankcolor"; - static private final String GRIDCOLOR = "gridcolor"; - static private final String FINSCOLOR = "finscolor"; - static private final String CURVATURECOLOR = "curvaturecolor"; - static private final String VOLUMEDISTRIBUTIONCOLOR = "volumedistributioncolor"; - static private final String CENTEROFMASSCOLOR = "centerofmasscolor"; - static private final String SELECTEDTANGENTCOLOR = "selectedtangentcolor"; - static private final String SELECTEDCONTROLPOINTCENTERCOLOR = "selectedcontrolpointcentercolor"; - static private final String SELECTEDCONTROLPOINTTANGENT1COLOR = "selectedcontrolpointtangent1color"; - static private final String SELECTEDCONTROLPOINTTANGENT2COLOR = "selectedcontrolpointtangent2color"; - static private final String SELECTEDCONTROLPOINTCENTEROUTLINECOLOR = "selectedcontrolpointcenteroutlinecolor"; - static private final String SELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR = "selectedcontrolpointtangent1outlinecolor"; - static private final String SELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR = "selectedcontrolpointtangent2outlinecolor"; - static private final String UNSELECTEDTANGENTCOLOR = "unselectedtangentcolor"; - static private final String UNSELECTEDCONTROLPOINTCENTERCOLOR = "unselectedcontrolpointcentercolor"; - static private final String UNSELECTEDCONTROLPOINTTANGENT1COLOR = "unselectedcontrolpointtangent1color"; - static private final String UNSELECTEDCONTROLPOINTTANGENT2COLOR = "unselectedcontrolpointtangent2color"; - static private final String UNSELECTEDCONTROLPOINTCENTEROUTLINECOLOR = "unselectedcontrolpointcenteroutlinecolor"; - static private final String UNSELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR = "unselectedcontrolpointtangent1outlinecolor"; - static private final String UNSELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR = "unselectedcontrolpointtangent2outlinecolor"; - static private final String UNSELECTEDBACKGROUNDCOLOR = "unselectedbackgroundcolor"; - static private final String GUIDEPOINTCOLOR = "guidepointcolor"; static private final String SELECTEDCONTROLPOINTSIZE = "selectedcontrolpointsize"; @@ -337,9 +312,9 @@ public String getFourViewName() static private final String BASELINETHICKNESS = "baselinethickness"; static private final String BASELINECOLOR = "baselinecolor"; - + static private final String LOOK_AND_FEEL = "lookandfeel"; - + static private final String PRINTGUIDEPOINTS = "printguidepoints"; static private final String PRINTFINS = "printfins"; @@ -350,6 +325,8 @@ public String getFourViewName() static private final String OFFSETINTERPLOATION = "offsetinterpolation"; + Timer mBezier3DModelUpdateTimer; + public static BoardCAD getInstance() { if (mInstance == null) { mInstance = new BoardCAD(); @@ -358,24 +335,39 @@ public static BoardCAD getInstance() { } protected BoardCAD() { - - - /* - * + /* + * // Test gcodedraw GeneralPath squarePath = new GeneralPath(); + * squarePath.moveTo(1.0, -1.0); squarePath.lineTo(1.0, 1.0); + * squarePath.lineTo(-1.0, 1.0); squarePath.lineTo(-1.0, -1.0); + * squarePath.closePath(); + * + * GeneralPath linePath = new GeneralPath(); linePath.moveTo(-1.0, 0.0); + * int steps = 100; for (int i = 0; i < steps; i++) { + * linePath.moveTo(-1.0 + ((2.0 * i) / steps), 0.0); } + * + * GCodeDraw gdrawSquare = new GCodeDraw( + * "C:/Users/Haavard/Desktop/G-Code/SquareTest.nc", 0.05, -0.05, 0.05, + * 0.01, 0.2, 0.03); GCodeDraw gdrawSquareNoOffset = new GCodeDraw( + * "C:/Users/Haavard/Desktop/G-Code/SquareTestNoOffset.nc", 0.0, -0.05, + * 0.05, 0.01, 0.2, 0.03); + * + * gdrawSquare.draw(squarePath); gdrawSquareNoOffset.draw(squarePath); + */ + /* + * * Tells the event-dispatching thread (used to - * + * * display and handle events of a Swing GUI) to - * + * * call the run method of "this" (the ClickMeApp - * + * * object this constructor created). The - * + * * argument to invokeLater must implement the - * + * * Runnable interface, which guarantees that - * + * * it defines the run method. - * */ LanguageResource.init(this); @@ -387,54 +379,53 @@ protected BoardCAD() { mColorSettings = mSettings.addCategory(LanguageResource.getString("COLORS_STR")); - mColorSettings.addColor(BACKGROUNDCOLOR, new Color(200, 200, 240),LanguageResource.getString("BACKGROUNDCOLOR_STR"), new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { - if(design_panel != null) + mColorSettings.addColor(TEXTCOLOR, new Color(0, 0, 0), LanguageResource.getString("TEXTCOLOR_STR")); + mColorSettings.addColor(BACKGROUNDCOLOR, new Color(200, 200, 240), LanguageResource.getString("BACKGROUNDCOLOR_STR"), new Settings.SettingChangedCallback() { + @Override + public void onSettingChanged(Object obj) { + if (design_panel != null) design_panel.get3DView().setBackgroundColor(mColorSettings.getColor(BACKGROUNDCOLOR)); - if(design_panel2 != null) + if (design_panel2 != null) design_panel2.get3DView().setBackgroundColor(mColorSettings.getColor(BACKGROUNDCOLOR)); -// if(mMachineView != null) -// mMachineView.get3DView().setBackgroundColor(mColorSettings.getColor(BACKGROUNDCOLOR)); - + if (design_panel3 != null) + design_panel3.get3DView().setBackgroundColor(mColorSettings.getColor(BACKGROUNDCOLOR)); } }); - mColorSettings.addColor(UNSELECTEDBACKGROUNDCOLOR, new Color(220, 220, 245),LanguageResource.getString("UNSELECTEDBACKGROUNDCOLOR_STR")); - mColorSettings.addColor(STRINGERCOLOR, new Color(100, 100, 100),LanguageResource.getString("STRINGERCOLOR_STR")); - mColorSettings.addColor(FLOWLINESCOLOR, new Color(100, 150, 100),LanguageResource.getString("FLOWLINESCOLOR_STR")); - mColorSettings.addColor(APEXLINECOLOR, new Color(80, 80, 200),LanguageResource.getString("APEXLINECOLOR_STR")); - mColorSettings.addColor(TUCKUNDERLINECOLOR, new Color(150, 50, 50),LanguageResource.getString("TUCKUNDERCOLOR_STR")); - mColorSettings.addColor(CENTERLINECOLOR, new Color(180, 180, 220),LanguageResource.getString("CENTERLINECOLOR_STR")); - - mColorSettings.addColor(BRDCOLOR, new Color(0, 0, 0),LanguageResource.getString("BRDCOLOR_STR")); - mColorSettings.addColor(ORIGINALCOLOR, new Color(240, 240, 240),LanguageResource.getString("ORIGINALCOLOR_STR")); - mColorSettings.addColor(GHOSTCOLOR, new Color(128, 128, 128),LanguageResource.getString("GHOSTCOLOR_STR")); + mColorSettings.addColor(UNSELECTEDBACKGROUNDCOLOR, new Color(220, 220, 245), LanguageResource.getString("UNSELECTEDBACKGROUNDCOLOR_STR")); + mColorSettings.addColor(STRINGERCOLOR, new Color(100, 100, 100), LanguageResource.getString("STRINGERCOLOR_STR")); + mColorSettings.addColor(FLOWLINESCOLOR, new Color(100, 150, 100), LanguageResource.getString("FLOWLINESCOLOR_STR")); + mColorSettings.addColor(APEXLINECOLOR, new Color(80, 80, 200), LanguageResource.getString("APEXLINECOLOR_STR")); + mColorSettings.addColor(TUCKUNDERLINECOLOR, new Color(150, 50, 50), LanguageResource.getString("TUCKUNDERCOLOR_STR")); + mColorSettings.addColor(CENTERLINECOLOR, new Color(180, 180, 220), LanguageResource.getString("CENTERLINECOLOR_STR")); + + mColorSettings.addColor(BRDCOLOR, new Color(0, 0, 0), LanguageResource.getString("BRDCOLOR_STR")); + mColorSettings.addColor(ORIGINALCOLOR, new Color(240, 240, 240), LanguageResource.getString("ORIGINALCOLOR_STR")); + mColorSettings.addColor(GHOSTCOLOR, new Color(128, 128, 128), LanguageResource.getString("GHOSTCOLOR_STR")); mColorSettings.addColor(BLANKCOLOR, new Color(128, 128, 128), LanguageResource.getString("BLANKCOLOR_STR")); mColorSettings.addColor(GRIDCOLOR, new Color(128, 128, 128), LanguageResource.getString("GRIDCOLOR_STR")); mColorSettings.addColor(FINSCOLOR, new Color(205, 128, 128), LanguageResource.getString("FINSCOLOR_STR")); - mColorSettings.addColor(CURVATURECOLOR, new Color(130, 130, 180),LanguageResource.getString("CURVATURECOLOR_STR")); - mColorSettings.addColor(VOLUMEDISTRIBUTIONCOLOR, new Color(80, 80, 80),LanguageResource.getString("VOLUMEDISTRIBUTIONCOLOR_STR")); - mColorSettings.addColor(CENTEROFMASSCOLOR, new Color(205, 10, 10),LanguageResource.getString("CENTEROFMASSCOLOR_STR")); + mColorSettings.addColor(CURVATURECOLOR, new Color(130, 130, 180), LanguageResource.getString("CURVATURECOLOR_STR")); + mColorSettings.addColor(VOLUMEDISTRIBUTIONCOLOR, new Color(80, 80, 80), LanguageResource.getString("VOLUMEDISTRIBUTIONCOLOR_STR")); + mColorSettings.addColor(CENTEROFMASSCOLOR, new Color(205, 10, 10), LanguageResource.getString("CENTEROFMASSCOLOR_STR")); mColorSettings.addColor(SELECTEDTANGENTCOLOR, new Color(0, 0, 0), LanguageResource.getString("SELECTEDTANGENTCOLOR_STR")); - mColorSettings.addColor(SELECTEDCONTROLPOINTCENTERCOLOR, new Color(30, 30, 200),LanguageResource.getString("SELECTEDCONTROLPOINTCENTERCOLOR_STR")); - mColorSettings.addColor(SELECTEDCONTROLPOINTTANGENT1COLOR, new Color(200, 200, 0),LanguageResource.getString("SELECTEDCONTROLPOINTTANGENT1COLOR_STR")); - mColorSettings.addColor(SELECTEDCONTROLPOINTTANGENT2COLOR, new Color(200, 0, 0),LanguageResource.getString("SELECTEDCONTROLPOINTTANGENT2COLOR_STR")); + mColorSettings.addColor(SELECTEDCONTROLPOINTCENTERCOLOR, new Color(30, 30, 200), LanguageResource.getString("SELECTEDCONTROLPOINTCENTERCOLOR_STR")); + mColorSettings.addColor(SELECTEDCONTROLPOINTTANGENT1COLOR, new Color(200, 200, 0), LanguageResource.getString("SELECTEDCONTROLPOINTTANGENT1COLOR_STR")); + mColorSettings.addColor(SELECTEDCONTROLPOINTTANGENT2COLOR, new Color(200, 0, 0), LanguageResource.getString("SELECTEDCONTROLPOINTTANGENT2COLOR_STR")); - mColorSettings.addColor(SELECTEDCONTROLPOINTCENTEROUTLINECOLOR, new Color(0, 0,0), LanguageResource.getString("SELECTEDCONTROLPOINTCENTEROUTLINECOLOR_STR")); - mColorSettings.addColor(SELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR, new Color(0,0, 0), LanguageResource.getString("SELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR_STR")); + mColorSettings.addColor(SELECTEDCONTROLPOINTCENTEROUTLINECOLOR, new Color(0, 0, 0), LanguageResource.getString("SELECTEDCONTROLPOINTCENTEROUTLINECOLOR_STR")); + mColorSettings.addColor(SELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR, new Color(0, 0, 0), LanguageResource.getString("SELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR_STR")); mColorSettings.addColor(SELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR, new Color(0, 0, 0), LanguageResource.getString("SELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR_STR")); mColorSettings.addColor(UNSELECTEDTANGENTCOLOR, new Color(100, 100, 100), LanguageResource.getString("UNSELECTEDTANGENTCOLOR_STR")); - mColorSettings.addColor(UNSELECTEDCONTROLPOINTCENTERCOLOR, new Color(200, 200, 240),LanguageResource.getString("UNSELECTEDCONTROLPOINTCENTERCOLOR_STR")); - mColorSettings.addColor(UNSELECTEDCONTROLPOINTTANGENT1COLOR, new Color(200,200,240),LanguageResource.getString("UNSELECTEDCONTROLPOINTTANGENT1COLOR_STR")); - mColorSettings.addColor(UNSELECTEDCONTROLPOINTTANGENT2COLOR, new Color(200,200,240),LanguageResource.getString("UNSELECTEDCONTROLPOINTTANGENT2COLOR_STR")); + mColorSettings.addColor(UNSELECTEDCONTROLPOINTCENTERCOLOR, new Color(200, 200, 240), LanguageResource.getString("UNSELECTEDCONTROLPOINTCENTERCOLOR_STR")); + mColorSettings.addColor(UNSELECTEDCONTROLPOINTTANGENT1COLOR, new Color(200, 200, 240), LanguageResource.getString("UNSELECTEDCONTROLPOINTTANGENT1COLOR_STR")); + mColorSettings.addColor(UNSELECTEDCONTROLPOINTTANGENT2COLOR, new Color(200, 200, 240), LanguageResource.getString("UNSELECTEDCONTROLPOINTTANGENT2COLOR_STR")); mColorSettings.addColor(UNSELECTEDCONTROLPOINTCENTEROUTLINECOLOR, new Color(80, 80, 150), LanguageResource.getString("UNSELECTEDCONTROLPOINTCENTEROUTLINECOLOR_STR")); mColorSettings.addColor(UNSELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR, new Color(150, 150, 80), LanguageResource.getString("UNSELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR_STR")); mColorSettings.addColor(UNSELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR, new Color(150, 80, 80), LanguageResource.getString("UNSELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR_STR")); - mColorSettings.addColor(GUIDEPOINTCOLOR, new Color(255, 0, 0),LanguageResource.getString("GUIDEPOINTCOLOR_STR")); + mColorSettings.addColor(GUIDEPOINTCOLOR, new Color(255, 0, 0), LanguageResource.getString("GUIDEPOINTCOLOR_STR")); mColorSettings.addColor(BASELINECOLOR, new Color(0, 0, 0), LanguageResource.getString("GUIDEPOINTCOLOR_STR")); mSizeSettings = mSettings.addCategory(LanguageResource.getString("SIZE_AND_THICKNESS_STR")); @@ -449,64 +440,57 @@ public void onSettingChanged(Object obj) mSizeSettings.addDouble(VOLUMEDISTRIBUTIONTHICKNESS, 1.2, LanguageResource.getString("VOLUMEDISTRIBUTIONTHICKNESS_STR")); mSizeSettings.addDouble(GUIDEPNTTHICKNESS, 1.2, LanguageResource.getString("GUIDEPNTTHICKNESS_STR")); mSizeSettings.addDouble(BASELINETHICKNESS, 1, LanguageResource.getString("BASELINETHICKNESS_STR")); - + HashMap looks = new HashMap(); - + mMiscSettings = mSettings.addCategory(LanguageResource.getString("MISC_STR")); String systemLookAndFeelName = UIManager.getSystemLookAndFeelClassName(); int systemLookAndFeelIndex = 0; - for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels() ){ + for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { looks.put(looks.size(), info.getName()); - if(systemLookAndFeelName == info.getClassName()) - { - systemLookAndFeelIndex = looks.size()-1; + if (systemLookAndFeelName == info.getClassName()) { + systemLookAndFeelIndex = looks.size() - 1; } } - mMiscSettings.addObject(LOOK_AND_FEEL, mMiscSettings.new Enumeration(systemLookAndFeelIndex, looks), LanguageResource.getString("LOOKANDFEEL_STR"), new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { - Enumeration e = (Enumeration)mMiscSettings.getObject(LOOK_AND_FEEL); - + mMiscSettings.addObject(LOOK_AND_FEEL, mMiscSettings.new Enumeration(systemLookAndFeelIndex, looks), LanguageResource.getString("LOOKANDFEEL_STR"), new Settings.SettingChangedCallback() { + @Override + public void onSettingChanged(Object obj) { + Enumeration e = (Enumeration) mMiscSettings.getObject(LOOK_AND_FEEL); + String selectedLookAndFeelName = e.getAlternatives().get(e.getValue()); - if(mBlockGUI==false) - { - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), String.format(LanguageResource.getString("LOOKANDFEELCHANGEDMSG_STR"), selectedLookAndFeelName), - LanguageResource.getString("LOOKANDFEELCHANGEDTITLE_STR"), JOptionPane.INFORMATION_MESSAGE); + if (mBlockGUI == false) { + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), String.format(LanguageResource.getString("LOOKANDFEELCHANGEDMSG_STR"), selectedLookAndFeelName), LanguageResource.getString("LOOKANDFEELCHANGEDTITLE_STR"), JOptionPane.INFORMATION_MESSAGE); } } }); mMiscSettings.getPreferences(); try { - Enumeration e = (Enumeration)mMiscSettings.getObject(LOOK_AND_FEEL); - + Enumeration e = (Enumeration) mMiscSettings.getObject(LOOK_AND_FEEL); + String selectedLookAndFeelName = e.getAlternatives().get(e.getValue()); - for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels() ){ - if (selectedLookAndFeelName.equals(info.getName())) { - UIManager.setLookAndFeel(info.getClassName()); - break; - } + for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { + if (selectedLookAndFeelName.equals(info.getName())) { + UIManager.setLookAndFeel(info.getClassName()); + break; + } } - } - catch (Exception e) { - System.err.println("Couldn't find class for specified look and feel:" - + UIManager.getSystemLookAndFeelClassName()); - System.err.println("Using the default look and feel."); - } + } catch (Exception e) { + System.err.println("Couldn't find class for specified look and feel:" + UIManager.getSystemLookAndFeelClassName()); + System.err.println("Using the default look and feel."); + } mMiscSettings.addBoolean(PRINTGUIDEPOINTS, false, LanguageResource.getString("PRINTGUIDEPOINTS_STR")); mMiscSettings.addBoolean(PRINTFINS, false, LanguageResource.getString("PRINTFINS_STR")); mMiscSettings.addInteger(FRACTIONACCURACY, 16, LanguageResource.getString("FRACTIONACCURACY_STR"), new Settings.SettingChangedCallback() { - + @Override public void onSettingChanged(Object obj) { - UnitUtils.setFractionAccuracy(((Integer)obj).intValue()); + UnitUtils.setFractionAccuracy(((Integer) obj).intValue()); } }); @@ -516,8 +500,89 @@ public void onSettingChanged(Object obj) { mRecentBrdFilesMenu.setText(LanguageResource.getString("RECENTFILES_STR")); - SwingUtilities.invokeLater(this); - + SwingUtilities.invokeLater(this); + } + + public void setDefaultTheme(){ + mColorSettings.setColor(TEXTCOLOR, new Color(0, 0, 0)); + mColorSettings.setColor(BACKGROUNDCOLOR, new Color(200, 200, 240)); + mColorSettings.setColor(UNSELECTEDBACKGROUNDCOLOR, new Color(220, 220, 245)); + mColorSettings.setColor(STRINGERCOLOR, new Color(100, 100, 100)); + mColorSettings.setColor(FLOWLINESCOLOR, new Color(100, 150, 100)); + mColorSettings.setColor(APEXLINECOLOR, new Color(80, 80, 200)); + mColorSettings.setColor(TUCKUNDERLINECOLOR, new Color(150, 50, 50)); + mColorSettings.setColor(CENTERLINECOLOR, new Color(180, 180, 220)); + + mColorSettings.setColor(BRDCOLOR, new Color(0, 0, 0)); + mColorSettings.setColor(ORIGINALCOLOR, new Color(240, 240, 240)); + mColorSettings.setColor(GHOSTCOLOR, new Color(128, 128, 128)); + mColorSettings.setColor(BLANKCOLOR, new Color(128, 128, 128)); + mColorSettings.setColor(GRIDCOLOR, new Color(128, 128, 128)); + mColorSettings.setColor(FINSCOLOR, new Color(205, 128, 128)); + mColorSettings.setColor(CURVATURECOLOR, new Color(130, 130, 180)); + mColorSettings.setColor(VOLUMEDISTRIBUTIONCOLOR, new Color(80, 80, 80)); + mColorSettings.setColor(CENTEROFMASSCOLOR, new Color(205, 10, 10)); + mColorSettings.setColor(SELECTEDTANGENTCOLOR, new Color(0, 0, 0)); + mColorSettings.setColor(SELECTEDCONTROLPOINTCENTERCOLOR, new Color(30, 30, 200)); + mColorSettings.setColor(SELECTEDCONTROLPOINTTANGENT1COLOR, new Color(200, 200, 0)); + mColorSettings.setColor(SELECTEDCONTROLPOINTTANGENT2COLOR, new Color(200, 0, 0)); + + mColorSettings.setColor(SELECTEDCONTROLPOINTCENTEROUTLINECOLOR, new Color(0, 0, 0)); + mColorSettings.setColor(SELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR, new Color(0, 0, 0)); + mColorSettings.setColor(SELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR, new Color(0, 0, 0)); + + mColorSettings.setColor(UNSELECTEDTANGENTCOLOR, new Color(100, 100, 100)); + mColorSettings.setColor(UNSELECTEDCONTROLPOINTCENTERCOLOR, new Color(200, 200, 240)); + mColorSettings.setColor(UNSELECTEDCONTROLPOINTTANGENT1COLOR, new Color(200, 200, 240)); + mColorSettings.setColor(UNSELECTEDCONTROLPOINTTANGENT2COLOR, new Color(200, 200, 240)); + + mColorSettings.setColor(UNSELECTEDCONTROLPOINTCENTEROUTLINECOLOR, new Color(80, 80, 150)); + mColorSettings.setColor(UNSELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR, new Color(150, 150, 80)); + mColorSettings.setColor(UNSELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR, new Color(150, 80, 80)); + + mColorSettings.setColor(GUIDEPOINTCOLOR, new Color(255, 0, 0)); + mColorSettings.setColor(BASELINECOLOR, new Color(0, 0, 0)); + } + + public void setDarkTheme(){ + mColorSettings.setColor(TEXTCOLOR, new Color(200, 200, 200)); + mColorSettings.setColor(BACKGROUNDCOLOR, new Color(200, 200, 240)); + mColorSettings.setColor(UNSELECTEDBACKGROUNDCOLOR, new Color(220, 220, 245)); + mColorSettings.setColor(STRINGERCOLOR, new Color(100, 100, 100)); + mColorSettings.setColor(FLOWLINESCOLOR, new Color(100, 150, 100)); + mColorSettings.setColor(APEXLINECOLOR, new Color(80, 80, 200)); + mColorSettings.setColor(TUCKUNDERLINECOLOR, new Color(150, 50, 50)); + mColorSettings.setColor(CENTERLINECOLOR, new Color(180, 180, 220)); + + mColorSettings.setColor(BRDCOLOR, new Color(0, 0, 0)); + mColorSettings.setColor(ORIGINALCOLOR, new Color(240, 240, 240)); + mColorSettings.setColor(GHOSTCOLOR, new Color(128, 128, 128)); + mColorSettings.setColor(BLANKCOLOR, new Color(128, 128, 128)); + mColorSettings.setColor(GRIDCOLOR, new Color(128, 128, 128)); + mColorSettings.setColor(FINSCOLOR, new Color(205, 128, 128)); + mColorSettings.setColor(CURVATURECOLOR, new Color(130, 130, 180)); + mColorSettings.setColor(VOLUMEDISTRIBUTIONCOLOR, new Color(80, 80, 80)); + mColorSettings.setColor(CENTEROFMASSCOLOR, new Color(205, 10, 10)); + mColorSettings.setColor(SELECTEDTANGENTCOLOR, new Color(0, 0, 0)); + mColorSettings.setColor(SELECTEDCONTROLPOINTCENTERCOLOR, new Color(30, 30, 200)); + mColorSettings.setColor(SELECTEDCONTROLPOINTTANGENT1COLOR, new Color(200, 200, 0)); + mColorSettings.setColor(SELECTEDCONTROLPOINTTANGENT2COLOR, new Color(200, 0, 0)); + + mColorSettings.setColor(SELECTEDCONTROLPOINTCENTEROUTLINECOLOR, new Color(0, 0, 0)); + mColorSettings.setColor(SELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR, new Color(0, 0, 0)); + mColorSettings.setColor(SELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR, new Color(0, 0, 0)); + + mColorSettings.setColor(UNSELECTEDTANGENTCOLOR, new Color(100, 100, 100)); + mColorSettings.setColor(UNSELECTEDCONTROLPOINTCENTERCOLOR, new Color(200, 200, 240)); + mColorSettings.setColor(UNSELECTEDCONTROLPOINTTANGENT1COLOR, new Color(200, 200, 240)); + mColorSettings.setColor(UNSELECTEDCONTROLPOINTTANGENT2COLOR, new Color(200, 200, 240)); + + mColorSettings.setColor(UNSELECTEDCONTROLPOINTCENTEROUTLINECOLOR, new Color(80, 80, 150)); + mColorSettings.setColor(UNSELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR, new Color(150, 150, 80)); + mColorSettings.setColor(UNSELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR, new Color(150, 80, 80)); + + mColorSettings.setColor(GUIDEPOINTCOLOR, new Color(255, 0, 0)); + mColorSettings.setColor(BASELINECOLOR, new Color(0, 0, 0)); } public static void print(Object object) throws IntrospectionException { @@ -537,105 +602,53 @@ public static void print(Object object) throws IntrospectionException { System.out.println("--- Object " + objectName + " End ----"); } - public void getPreferences() { + public void getPreferences() { // Preference keys for this package final Preferences prefs = Preferences.userNodeForPackage(BoardCAD.class); defaultDirectory = prefs.get("defaultDirectory", ""); - mIsPaintingGridMenuItem.setSelected(prefs - .getBoolean("mIsPaintingGridMenuItem", mIsPaintingGridMenuItem - .isSelected())); - mIsPaintingOriginalBrdMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingOriginalBrdMenuItem", - mIsPaintingOriginalBrdMenuItem.isSelected())); - mIsPaintingGhostBrdMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingGhostBrdMenuItem", mIsPaintingGhostBrdMenuItem - .isSelected())); - mIsPaintingControlPointsMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingControlPointsMenuItem", - mIsPaintingControlPointsMenuItem.isSelected())); - mIsPaintingNonActiveCrossSectionsMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingNonActiveCrossSectionsMenuItem", - mIsPaintingNonActiveCrossSectionsMenuItem.isSelected())); - mIsPaintingGuidePointsMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingGuidePointsMenuItem", - mIsPaintingGuidePointsMenuItem.isSelected())); - mIsPaintingCurvatureMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingCurvatureMenuItem", mIsPaintingCurvatureMenuItem - .isSelected())); - mIsPaintingVolumeDistributionMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingVolumeDistributionMenuItem", mIsPaintingVolumeDistributionMenuItem - .isSelected())); - mIsPaintingCenterOfMassMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingCenterOfMassMenuItem", - mIsPaintingCenterOfMassMenuItem.isSelected())); - mIsPaintingSlidingInfoMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingSlidingInfoMenuItem", - mIsPaintingSlidingInfoMenuItem.isSelected())); - mIsPaintingSlidingCrossSectionMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingSlidingCrossSectionMenuItem", - mIsPaintingSlidingCrossSectionMenuItem.isSelected())); - mIsPaintingFinsMenuItem.setSelected(prefs - .getBoolean("mIsPaintingFinsMenuItem", mIsPaintingFinsMenuItem - .isSelected())); - mIsPaintingBackgroundImageMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingBackgroundImageMenuItem", - mIsPaintingBackgroundImageMenuItem.isSelected())); - mIsAntialiasingMenuItem.setSelected(prefs - .getBoolean("mIsAntialiasingMenuItem", mIsAntialiasingMenuItem - .isSelected())); - mUseFillMenuItem.setSelected(prefs - .getBoolean("mUseFillMenuItem", mUseFillMenuItem - .isSelected())); - mIsPaintingBaseLineMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingBaseLineMenuItem", mIsPaintingBaseLineMenuItem - .isSelected())); - mIsPaintingCenterLineMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingCenterLineMenuItem", mIsPaintingCenterLineMenuItem - .isSelected())); - mIsPaintingOverCurveMesurementsMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingoverCurveMesurementsMenuItem", mIsPaintingOverCurveMesurementsMenuItem - .isSelected())); - mIsPaintingMomentOfInertiaMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingMomentOfInertiaMenuItem", mIsPaintingMomentOfInertiaMenuItem - .isSelected())); - - mIsPaintingCrossectionsPositionsMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingCrossectionsPositionsMenuItem", mIsPaintingCrossectionsPositionsMenuItem - .isSelected())); - - mIsPaintingFlowlinesMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingFlowlinesMenuItem", mIsPaintingFlowlinesMenuItem - .isSelected())); - - mIsPaintingApexlineMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingApexlineMenuItem", mIsPaintingApexlineMenuItem - .isSelected())); - - mIsPaintingTuckUnderLineMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingTuckUnderLineMenuItem", mIsPaintingTuckUnderLineMenuItem - .isSelected())); - mIsPaintingFootMarksMenuItem.setSelected(prefs.getBoolean( - "mIsPaintingFootMarksMenuItem", mIsPaintingFootMarksMenuItem - .isSelected())); - - mPrintMarginLeft = prefs - .getDouble("mPrintMarginLeft", mPrintMarginLeft); - mPrintMarginRight = prefs.getDouble("mPrintMarginRight", - mPrintMarginRight); + mIsPaintingGridMenuItem.setSelected(prefs.getBoolean("mIsPaintingGridMenuItem", mIsPaintingGridMenuItem.isSelected())); + mIsPaintingOriginalBrdMenuItem.setSelected(prefs.getBoolean("mIsPaintingOriginalBrdMenuItem", mIsPaintingOriginalBrdMenuItem.isSelected())); + mIsPaintingGhostBrdMenuItem.setSelected(prefs.getBoolean("mIsPaintingGhostBrdMenuItem", mIsPaintingGhostBrdMenuItem.isSelected())); + mIsPaintingControlPointsMenuItem.setSelected(prefs.getBoolean("mIsPaintingControlPointsMenuItem", mIsPaintingControlPointsMenuItem.isSelected())); + mIsPaintingNonActiveCrossSectionsMenuItem.setSelected(prefs.getBoolean("mIsPaintingNonActiveCrossSectionsMenuItem", mIsPaintingNonActiveCrossSectionsMenuItem.isSelected())); + mIsPaintingGuidePointsMenuItem.setSelected(prefs.getBoolean("mIsPaintingGuidePointsMenuItem", mIsPaintingGuidePointsMenuItem.isSelected())); + mIsPaintingCurvatureMenuItem.setSelected(prefs.getBoolean("mIsPaintingCurvatureMenuItem", mIsPaintingCurvatureMenuItem.isSelected())); + mIsPaintingVolumeDistributionMenuItem.setSelected(prefs.getBoolean("mIsPaintingVolumeDistributionMenuItem", mIsPaintingVolumeDistributionMenuItem.isSelected())); + mIsPaintingCenterOfMassMenuItem.setSelected(prefs.getBoolean("mIsPaintingCenterOfMassMenuItem", mIsPaintingCenterOfMassMenuItem.isSelected())); + mIsPaintingSlidingInfoMenuItem.setSelected(prefs.getBoolean("mIsPaintingSlidingInfoMenuItem", mIsPaintingSlidingInfoMenuItem.isSelected())); + mIsPaintingSlidingCrossSectionMenuItem.setSelected(prefs.getBoolean("mIsPaintingSlidingCrossSectionMenuItem", mIsPaintingSlidingCrossSectionMenuItem.isSelected())); + mIsPaintingFinsMenuItem.setSelected(prefs.getBoolean("mIsPaintingFinsMenuItem", mIsPaintingFinsMenuItem.isSelected())); + mIsPaintingBackgroundImageMenuItem.setSelected(prefs.getBoolean("mIsPaintingBackgroundImageMenuItem", mIsPaintingBackgroundImageMenuItem.isSelected())); + mIsAntialiasingMenuItem.setSelected(prefs.getBoolean("mIsAntialiasingMenuItem", mIsAntialiasingMenuItem.isSelected())); + mUseFillMenuItem.setSelected(prefs.getBoolean("mUseFillMenuItem", mUseFillMenuItem.isSelected())); + mIsPaintingBaseLineMenuItem.setSelected(prefs.getBoolean("mIsPaintingBaseLineMenuItem", mIsPaintingBaseLineMenuItem.isSelected())); + mIsPaintingCenterLineMenuItem.setSelected(prefs.getBoolean("mIsPaintingCenterLineMenuItem", mIsPaintingCenterLineMenuItem.isSelected())); + mIsPaintingOverCurveMesurementsMenuItem.setSelected(prefs.getBoolean("mIsPaintingoverCurveMesurementsMenuItem", mIsPaintingOverCurveMesurementsMenuItem.isSelected())); + mIsPaintingMomentOfInertiaMenuItem.setSelected(prefs.getBoolean("mIsPaintingMomentOfInertiaMenuItem", mIsPaintingMomentOfInertiaMenuItem.isSelected())); + + mIsPaintingCrossectionsPositionsMenuItem.setSelected(prefs.getBoolean("mIsPaintingCrossectionsPositionsMenuItem", mIsPaintingCrossectionsPositionsMenuItem.isSelected())); + + mIsPaintingFlowlinesMenuItem.setSelected(prefs.getBoolean("mIsPaintingFlowlinesMenuItem", mIsPaintingFlowlinesMenuItem.isSelected())); + + mIsPaintingApexlineMenuItem.setSelected(prefs.getBoolean("mIsPaintingApexlineMenuItem", mIsPaintingApexlineMenuItem.isSelected())); + + mIsPaintingTuckUnderLineMenuItem.setSelected(prefs.getBoolean("mIsPaintingTuckUnderLineMenuItem", mIsPaintingTuckUnderLineMenuItem.isSelected())); + mIsPaintingFootMarksMenuItem.setSelected(prefs.getBoolean("mIsPaintingFootMarksMenuItem", mIsPaintingFootMarksMenuItem.isSelected())); + + mPrintMarginLeft = prefs.getDouble("mPrintMarginLeft", mPrintMarginLeft); + mPrintMarginRight = prefs.getDouble("mPrintMarginRight", mPrintMarginRight); mPrintMarginTop = prefs.getDouble("mPrintMarginTop", mPrintMarginTop); - mPrintMarginBottom = prefs.getDouble("mPrintMarginBottom", - mPrintMarginBottom); + mPrintMarginBottom = prefs.getDouble("mPrintMarginBottom", mPrintMarginBottom); final int type = prefs.getInt("CrossSectionInterpolationType", getCrossSectionInterpolationTypeAsInt()); setCrossSectionInterpolationTypeFromInt(type); - for(int i = 8; i >= 0; i--) - { - String id = "mRecentBrdFiles"+i; - String string = prefs.get(id,""); - if(string == null || string.compareTo("") == 0) + for (int i = 8; i >= 0; i--) { + String id = "mRecentBrdFiles" + i; + String string = prefs.get(id, ""); + if (string == null || string.compareTo("") == 0) continue; addRecentBoardFile(string); @@ -649,102 +662,73 @@ public void putPreferences() { final Preferences prefs = Preferences.userNodeForPackage(BoardCAD.class); prefs.put("defaultDirectory", defaultDirectory); - prefs.putBoolean("mIsPaintingGridMenuItem", mIsPaintingGridMenuItem - .isSelected()); - prefs.putBoolean("mIsPaintingOriginalBrdMenuItem", - mIsPaintingOriginalBrdMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingGhostBrdMenuItem", - mIsPaintingGhostBrdMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingControlPointsMenuItem", - mIsPaintingControlPointsMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingNonActiveCrossSectionsMenuItem", - mIsPaintingNonActiveCrossSectionsMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingGuidePointsMenuItem", - mIsPaintingGuidePointsMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingCurvatureMenuItem", - mIsPaintingCurvatureMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingVolumeDistributionMenuItem", - mIsPaintingVolumeDistributionMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingCenterOfMassMenuItem", - mIsPaintingCenterOfMassMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingSlidingInfoMenuItem", - mIsPaintingSlidingInfoMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingSlidingCrossSectionMenuItem", - mIsPaintingSlidingCrossSectionMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingFinsMenuItem", mIsPaintingFinsMenuItem - .isSelected()); - prefs.putBoolean("mIsPaintingBackgroundImageMenuItem", - mIsPaintingCrossectionsPositionsMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingBaseLineMenuItem", - mIsPaintingBaseLineMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingCenterLineMenuItem", - mIsPaintingCenterLineMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingOverCurveMesurementsMenuItem", - mIsPaintingOverCurveMesurementsMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingMomentOfInertiaMenuItem", - mIsPaintingMomentOfInertiaMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingCrossectionsPositionsMenuItem", - mIsPaintingCrossectionsPositionsMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingFlowlinesMenuItem", - mIsPaintingFlowlinesMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingApexlineMenuItem", - mIsPaintingApexlineMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingTuckUnderLineMenuItem", - mIsPaintingTuckUnderLineMenuItem.isSelected()); - prefs.putBoolean("mIsPaintingFootMarksMenuItem", - mIsPaintingFootMarksMenuItem.isSelected()); - prefs.putBoolean("mIsAntialiasingMenuItem", - mIsAntialiasingMenuItem.isSelected()); - prefs.putBoolean("mUseFillMenuItem", - mUseFillMenuItem.isSelected()); - prefs.putInt("CrossSectionInterpolationType", - getCrossSectionInterpolationTypeAsInt()); + prefs.putBoolean("mIsPaintingGridMenuItem", mIsPaintingGridMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingOriginalBrdMenuItem", mIsPaintingOriginalBrdMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingGhostBrdMenuItem", mIsPaintingGhostBrdMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingControlPointsMenuItem", mIsPaintingControlPointsMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingNonActiveCrossSectionsMenuItem", mIsPaintingNonActiveCrossSectionsMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingGuidePointsMenuItem", mIsPaintingGuidePointsMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingCurvatureMenuItem", mIsPaintingCurvatureMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingVolumeDistributionMenuItem", mIsPaintingVolumeDistributionMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingCenterOfMassMenuItem", mIsPaintingCenterOfMassMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingSlidingInfoMenuItem", mIsPaintingSlidingInfoMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingSlidingCrossSectionMenuItem", mIsPaintingSlidingCrossSectionMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingFinsMenuItem", mIsPaintingFinsMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingBackgroundImageMenuItem", mIsPaintingCrossectionsPositionsMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingBaseLineMenuItem", mIsPaintingBaseLineMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingCenterLineMenuItem", mIsPaintingCenterLineMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingOverCurveMesurementsMenuItem", mIsPaintingOverCurveMesurementsMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingMomentOfInertiaMenuItem", mIsPaintingMomentOfInertiaMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingCrossectionsPositionsMenuItem", mIsPaintingCrossectionsPositionsMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingFlowlinesMenuItem", mIsPaintingFlowlinesMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingApexlineMenuItem", mIsPaintingApexlineMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingTuckUnderLineMenuItem", mIsPaintingTuckUnderLineMenuItem.isSelected()); + prefs.putBoolean("mIsPaintingFootMarksMenuItem", mIsPaintingFootMarksMenuItem.isSelected()); + prefs.putBoolean("mIsAntialiasingMenuItem", mIsAntialiasingMenuItem.isSelected()); + prefs.putBoolean("mUseFillMenuItem", mUseFillMenuItem.isSelected()); + prefs.putInt("CrossSectionInterpolationType", getCrossSectionInterpolationTypeAsInt()); prefs.putDouble("mPrintMarginLeft", mPrintMarginLeft); prefs.putDouble("mPrintMarginRight", mPrintMarginRight); prefs.putDouble("mPrintMarginTop", mPrintMarginTop); prefs.putDouble("mPrintMarginBottom", mPrintMarginBottom); - for(int i = 0; i 8) - { - mRecentBrdFilesMenu.remove(mRecentBrdFilesMenu.getMenuComponentCount()-1); + while (mRecentBrdFilesMenu.getMenuComponentCount() > 8) { + mRecentBrdFilesMenu.remove(mRecentBrdFilesMenu.getMenuComponentCount() - 1); + } + } + + public void updateBezier3DModel() { + if (mTabbedPane.getSelectedComponent() == mRenderedpanel) { + design_panel2.updateBezier3DModel(getCurrentBrd()); + } else if (mTabbedPane.getSelectedComponent() == fourView) { + design_panel3.updateBezier3DModel(getCurrentBrd()); } } @@ -786,14 +776,14 @@ public void setSelectedEdit(final Component edit) { mTabbedPane.setSelectedComponent(mOutlineAndProfileSplitPane); } else if (edit == mBottomAndDeckEdit) { mTabbedPane.setSelectedComponent(mBottomAndDeckEdit); - } else if (edit == view1 || edit==view2 || edit == view3) { + } else if (edit == view1 || edit == view2 || edit == view3) { mTabbedPane.setSelectedComponent(fourView); } else { mTabbedPane.setSelectedComponent(edit); } } - public JTabbedPane getmTabbedPane() { + public JTabbedPane getTabbedPane() { return mTabbedPane; } @@ -803,20 +793,13 @@ public BoardEdit getSelectedEdit() { if (component == mCrossSectionSplitPane) { return mCrossSectionEdit; - } - else if (component == mOutlineAndProfileSplitPane) { + } else if (component == mOutlineAndProfileSplitPane) { return mOutlineAndProfileSplitPane.getActive(); - } - else if (component == fourView) - { + } else if (component == fourView) { return fourView.getActive(); - } - else if(component instanceof BoardEdit) - { + } else if (component instanceof BoardEdit) { return (BoardEdit) component; - } - else - { + } else { return null; } } catch (final Exception e) { @@ -825,8 +808,7 @@ else if(component instanceof BoardEdit) } } - public BoardGuidePointsDialog getGuidePointsDialog() - { + public BoardGuidePointsDialog getGuidePointsDialog() { return mGuidePointsDialog; } @@ -834,9 +816,9 @@ public JFrame getFrame() { return mFrame; } -// public MachineView getMachineView() { -// return mMachineView; -// } + // public MachineView getMachineView() { + // return mMachineView; + // } public ControlPointInfo getControlPointInfo() { return mControlPointInfo; @@ -862,6 +844,11 @@ public Color getBlankColor() { return mColorSettings.getColor(BLANKCOLOR); } + public Color getTextColor() { + + return mColorSettings.getColor(TEXTCOLOR); + } + public Color getBackgroundColor() { return mColorSettings.getColor(BACKGROUNDCOLOR); @@ -1079,11 +1066,11 @@ public boolean isPaintingCenterLine() { public boolean isPaintingOverCurveMeasurements() { return mIsPaintingOverCurveMesurementsMenuItem.isSelected(); } - + public boolean isPaintingMomentOfInertia() { return mIsPaintingMomentOfInertiaMenuItem.isSelected(); } - + public boolean isPaintingCrossectionsPositions() { return mIsPaintingCrossectionsPositionsMenuItem.isSelected(); } @@ -1103,7 +1090,7 @@ public boolean isPaintingTuckUnderLine() { public boolean isPaintingFootMarks() { return mIsPaintingFootMarksMenuItem.isSelected(); } - + public boolean useFill() { return mUseFillMenuItem.isSelected(); } @@ -1127,15 +1114,13 @@ public boolean isUsingOffsetInterpolation() { public boolean isGhostMode() { return mGhostMode; } + public boolean isOrgFocus() { return mOrgFocus; } - - - public AbstractBezierBoardSurfaceModel.ModelType getCrossSectionInterpolationType() - { - if(mControlPointInterpolationButton == null) + public AbstractBezierBoardSurfaceModel.ModelType getCrossSectionInterpolationType() { + if (mControlPointInterpolationButton == null) return AbstractBezierBoardSurfaceModel.ModelType.SLinearInterpolation; if (mSBlendInterpolationButton.isSelected()) @@ -1143,16 +1128,15 @@ public AbstractBezierBoardSurfaceModel.ModelType getCrossSectionInterpolationTyp else return AbstractBezierBoardSurfaceModel.ModelType.ControlPointInterpolation; } - public int getCrossSectionInterpolationTypeAsInt() - { + + public int getCrossSectionInterpolationTypeAsInt() { AbstractBezierBoardSurfaceModel.ModelType type = getCrossSectionInterpolationType(); - switch(type) - { - default: - case ControlPointInterpolation: - return 2; - case SLinearInterpolation: - return 3; + switch (type) { + default: + case ControlPointInterpolation: + return 2; + case SLinearInterpolation: + return 3; } } @@ -1178,8 +1162,7 @@ public void setCrossSectionInterpolationTypeFromInt(int type) { mSBlendInterpolationButton.doClick(); break; } - if(mCurrentBrd != null) - { + if (mCurrentBrd != null) { mCurrentBrd.setInterpolationType(getCrossSectionInterpolationType()); } } @@ -1220,38 +1203,31 @@ public BezierBoard getGhostBrd() { return mGhostBrd; } - public BoardHandler getBoardHandler(){ + public BoardHandler getBoardHandler() { return board_handler; } - public void redraw() - { + public void redraw() { mOutlineEdit.repaint(); mBottomAndDeckEdit.repaint(); -// mOutlineEdit2.repaint(); -// mOutlineAndProfileSplitPane.getTopComponent().repaint(); -// mOutlineAndProfileSplitPane.getBottomComponent().repaint(); + // mOutlineEdit2.repaint(); + // mOutlineAndProfileSplitPane.getTopComponent().repaint(); + // mOutlineAndProfileSplitPane.getBottomComponent().repaint(); view1.repaint(); view2.repaint(); view3.repaint(); view4.repaint(); design_panel.redraw(); -// fourView.repaint(); -// mFrame.repaint(); + // fourView.repaint(); + // mFrame.repaint(); } - BezierBoard getFocusedBoard() - { - if(isGhostMode()) - { + BezierBoard getFocusedBoard() { + if (isGhostMode()) { return BoardCAD.getInstance().getGhostBrd(); - } - else if(mOrgFocus) - { + } else if (mOrgFocus) { return BoardCAD.getInstance().getOriginalBrd(); - } - else - { + } else { return BoardCAD.getInstance().getCurrentBrd(); } @@ -1259,7 +1235,7 @@ else if(mOrgFocus) public void fitAll() { mOutlineEdit.fit_all(); - //mOutlineEdit2.fit_all(); + // mOutlineEdit2.fit_all(); mBottomAndDeckEdit.fit_all(); mCrossSectionEdit.fit_all(); @@ -1269,54 +1245,69 @@ public void fitAll() { view4.fit_all(); design_panel.fit_all(); -// mMachineView.fit_all(); + // mMachineView.fit_all(); } public void onBrdChanged() { updateScreenValues(); - + mBoardChanged = true; - mBoardChangedFor3D = true; + setBoardChangedFor3D(); + + if (mBezier3DModelUpdateTimer != null) { + mBezier3DModelUpdateTimer.cancel(); + mBezier3DModelUpdateTimer = null; + } + + mBezier3DModelUpdateTimer = new Timer("Bezier3DModelUpdateTimer"); + TimerTask task = new TimerTask() { + @Override + public void run() { + mBezier3DModelUpdateTimer = null; + updateBezier3DModel(); + } + }; + mBezier3DModelUpdateTimer.schedule(task, 300); } public void updateScreenValues() { - if(getCurrentBrd().isEmpty()) - { + if (getCurrentBrd().isEmpty()) { return; } - + final double length = getCurrentBrd().getLength(); final double maxWidth = getCurrentBrd().getMaxWidth(); - mFrame.setTitle(appname + " - " + getCurrentBrd().getFilename() + " " - + UnitUtils.convertLengthToCurrentUnit(length, true) + " x " - + UnitUtils.convertLengthToCurrentUnit(maxWidth, false)); + mFrame.setTitle(appname + " - " + getCurrentBrd().getFilename() + " " + UnitUtils.convertLengthToCurrentUnit(length, true) + " x " + UnitUtils.convertLengthToCurrentUnit(maxWidth, false)); mBoardSpec.updateInfo(); - if(mWeightCalculatorDialog.isVisible()) + if (mWeightCalculatorDialog.isVisible()) mWeightCalculatorDialog.updateAll(); - if(mGuidePointsDialog.isVisible()) + if (mGuidePointsDialog.isVisible()) mGuidePointsDialog.update(); } - protected void setCurrentUnit(int unitType) - { + void setBoardChangedFor3D() { + design_panel2.setBoardChangedFor3D(); + design_panel3.setBoardChangedFor3D(); + } + + protected void setCurrentUnit(int unitType) { UnitUtils.setCurrentUnit(unitType); - if(mWeightCalculatorDialog != null) + if (mWeightCalculatorDialog != null) mWeightCalculatorDialog.updateAll(); - if(mGuidePointsDialog != null) + if (mGuidePointsDialog != null) mGuidePointsDialog.update(); updateScreenValues(); onControlPointChanged(); redraw(); } - public void onControlPointChanged() { final String className = getCurrentCommand().getClass().getSimpleName(); @@ -1327,11 +1318,10 @@ public void onControlPointChanged() { final BrdEditCommand cmd = (BrdEditCommand) getCurrentCommand(); mControlPointInfo.mCmd = cmd; mControlPointInfo.setEnabled(true); - final ArrayList controlPoints = edit - .getSelectedControlPoints(); + final ArrayList controlPoints = edit.getSelectedControlPoints(); final BezierKnot controlPoint = controlPoints.get(0); mControlPointInfo.setControlPoint(controlPoint); - mControlPointInfo.setWhich(cmd.mWhich); + mControlPointInfo.setWhich(cmd.getWhich()); } else { mControlPointInfo.setEnabled(false); } @@ -1343,32 +1333,23 @@ public void onSettingsChanged() { mFrame.repaint(); } - private void saveAs(String filename) - { + private void saveAs(String filename) { final String ext = FileTools.getExtension(filename); - if (ext != null && ext.compareTo("cad") == 0) - { + if (ext != null && ext.compareTo("cad") == 0) { board_handler.save_board_as(filename); - } - else if (ext != null && (ext.compareTo("stp") == 0 || ext.compareTo("step") == 0) ) - { + } else if (ext != null && (ext.compareTo("stp") == 0 || ext.compareTo("step") == 0)) { - try - { + try { board_handler.export_board(new PrintStream(new File(filename)), filename); - } - catch(IOException excep2) - { + } catch (IOException excep2) { System.out.println("Problem creating file"); } addRecentBoardFile(getCurrentBrd().getFilename()); onBrdChanged(); - mBoardChanged = false; - } - else - { + mBoardChanged = false; + } else { BrdWriter.saveFile(getCurrentBrd(), filename); addRecentBoardFile(getCurrentBrd().getFilename()); @@ -1379,18 +1360,10 @@ else if (ext != null && (ext.compareTo("stp") == 0 || ext.compareTo("step") == 0 } } - private int saveChangedBoard() - { + private int saveChangedBoard() { if (mBoardChanged == true) { final Object[] options = { LanguageResource.getString("YESBUTTON_STR"), LanguageResource.getString("NOBUTTON_STR"), LanguageResource.getString("CANCELBUTTON_STR") }; - final int n = JOptionPane - .showOptionDialog( - mFrame, - LanguageResource.getString("SAVECURRENTBOARDMSG_STR"), - LanguageResource.getString("SAVECURRENTBOARDTITLE_STR"), - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, null, - options, options[0]); + final int n = JOptionPane.showOptionDialog(mFrame, LanguageResource.getString("SAVECURRENTBOARDMSG_STR"), LanguageResource.getString("SAVECURRENTBOARDTITLE_STR"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); switch (n) { case 0: @@ -1409,6 +1382,7 @@ private int saveChangedBoard() } return 0; } + /** * * Creates and shows the GUI. This method should be @@ -1417,6 +1391,7 @@ private int saveChangedBoard() * */ + @Override public void run() { createAndShowGUI(); } @@ -1438,13 +1413,14 @@ private void createAndShowGUI() { // Create and set up the window. mFrame = new JFrame(" " + appname); - mFrame.setMinimumSize(new Dimension(1000,700)); + mFrame.setMinimumSize(new Dimension(1000, 700)); - mFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + mFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); mFrame.addWindowListener(new java.awt.event.WindowAdapter() { + @Override public void windowClosing(final WindowEvent e) { int r = saveChangedBoard(); - if(r == -1 || r==2) //closed dialog or cancel button pressed + if (r == -1 || r == 2) // closed dialog or cancel button pressed return; putPreferences(); System.exit(1); @@ -1455,12 +1431,12 @@ public void windowClosing(final WindowEvent e) { mFrame.getContentPane().setLayout(new BorderLayout()); // Insert 16x16 Icon on JFrame - try{ + try { ImageIcon icon = new ImageIcon(getClass().getResource("../../icons/BoardCAD png 16x16 upright.png")); mFrame.setIconImage(icon.getImage()); - }catch(Exception e) { + } catch (Exception e) { System.out.println("Jframe Icon error:\n" + e.getMessage()); - } + } JMenuBar menuBar; JPopupMenu popupMenu; @@ -1472,30 +1448,24 @@ public void windowClosing(final WindowEvent e) { fileMenu.setMnemonic(KeyEvent.VK_F); JPopupMenu.setDefaultLightWeightPopupEnabled(false); final AbstractAction newBrd = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("NEWBOARD_STR")); this.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("NEWBOARD_STR")); - this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK)); + this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK)); }; - + @Override public void actionPerformed(ActionEvent arg0) { - String str = (String) JOptionPane.showInputDialog(mFrame, - LanguageResource.getString("NEWBOARDMSG_STR"), - LanguageResource.getString("NEWBOARDTITLE_STR"), - JOptionPane.PLAIN_MESSAGE, null, DefaultBrds - .getInstance().getDefaultBoardsList(), - DefaultBrds.getInstance().getDefaultBoardsList()[0]); + String str = (String) JOptionPane.showInputDialog(mFrame, LanguageResource.getString("NEWBOARDMSG_STR"), LanguageResource.getString("NEWBOARDTITLE_STR"), JOptionPane.PLAIN_MESSAGE, null, DefaultBrds.getInstance().getDefaultBoardsList(), DefaultBrds.getInstance() + .getDefaultBoardsList()[0]); if (str == null) return; - BrdReader.loadFile(getCurrentBrd(), DefaultBrds.getInstance() - .getBoardArray(str), str); + BrdReader.loadFile(getCurrentBrd(), DefaultBrds.getInstance().getBoardArray(str), str); mOriginalBrd.set(getCurrentBrd()); fitAll(); onBrdChanged(); @@ -1504,27 +1474,27 @@ public void actionPerformed(ActionEvent arg0) { BrdCommandHistory.getInstance().clear(); mFrame.repaint(); mBoardChanged = false; - boolean selected = mShowBezier3DModelMenuItem.getModel().isSelected(); - if(selected && mTabbedPane.getSelectedComponent() == mRenderedpanel) - { - updateBezier3DModel(); - } + boolean selected = mShowBezier3DModelMenuItem.getModel().isSelected(); + if (selected) { + updateBezier3DModel(); + } } }; fileMenu.add(newBrd); final BoardLoadAction loadBrd = new BoardLoadAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { mBrd = mCurrentBrd; mCloneBrd = mOriginalBrd; }; + @Override public void actionPerformed(ActionEvent event) { int r = saveChangedBoard(); - if(r == -1 || r==2) //closed dialog or cancel button pressed + if (r == -1 || r == 2) // closed dialog or cancel button pressed return; super.actionPerformed(event); @@ -1535,38 +1505,36 @@ public void actionPerformed(ActionEvent event) { onBrdChanged(); onControlPointChanged(); mBoardChanged = false; - boolean selected = mShowBezier3DModelMenuItem.getModel().isSelected(); - if(selected && mTabbedPane.getSelectedComponent() == mRenderedpanel) - { - updateBezier3DModel(); - } - redraw(); - - + boolean selected = mShowBezier3DModelMenuItem.getModel().isSelected(); + if (selected) { + updateBezier3DModel(); + } + redraw(); + } }; - loadBrd.putValue(AbstractAction.NAME, LanguageResource.getString("BOARDOPEN_STR")); - loadBrd.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("BOARDOPEN_STR")); - loadBrd.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK)); + loadBrd.putValue(Action.NAME, LanguageResource.getString("BOARDOPEN_STR")); + loadBrd.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("BOARDOPEN_STR")); + loadBrd.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK)); fileMenu.add(loadBrd); fileMenu.add(mRecentBrdFilesMenu); fileMenu.addSeparator(); final AbstractAction saveBrd = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("BOARDSAVE_STR")); this.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("BOARDSAVE_STR")); - this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK)); + this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); }; + @Override public void actionPerformed(ActionEvent arg0) { saveAs(getCurrentBrd().getFilename()); -// BrdWriter.saveFile(getCurrentBrd(), getCurrentBrd().getFilename()); + // BrdWriter.saveFile(getCurrentBrd(), + // getCurrentBrd().getFilename()); mBoardChanged = false; } @@ -1575,12 +1543,13 @@ public void actionPerformed(ActionEvent arg0) { fileMenu.add(saveBrd); mSaveBrdAs = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("BOARDSAVEAS_STR")); - this.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/save-as.png"))); + this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/save-as.png"))); }; + @Override public void actionPerformed(final ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); @@ -1588,8 +1557,7 @@ public void actionPerformed(final ActionEvent arg0) { fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); fc.setSelectedFile(new File(getCurrentBrd().getFilename())); - final int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + final int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -1610,20 +1578,19 @@ public void actionPerformed(final ActionEvent arg0) { fileMenu.add(mSaveBrdAs); final AbstractAction SaveBrd = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("BOARDSAVEANDREFRESH_STR")); this.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("BOARDSAVEANDREFRESH_STR")); - this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK)); + this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK)); }; + @Override public void actionPerformed(ActionEvent arg0) { - BrdWriter.saveFile(getCurrentBrd(), getCurrentBrd() - .getFilename()); + BrdWriter.saveFile(getCurrentBrd(), getCurrentBrd().getFilename()); - mOriginalBrd = (BezierBoard)getCurrentBrd().clone(); + mOriginalBrd = (BezierBoard) getCurrentBrd().clone(); mBoardChanged = false; } @@ -1632,34 +1599,32 @@ public void actionPerformed(ActionEvent arg0) { fileMenu.add(SaveBrd); fileMenu.addSeparator(); - final BoardLoadAction loadGhost = new BoardLoadAction(mGhostBrd){ - public void actionPerformed(ActionEvent event) - { + final BoardLoadAction loadGhost = new BoardLoadAction(mGhostBrd) { + @Override + public void actionPerformed(ActionEvent event) { super.actionPerformed(event); mIsPaintingGhostBrdMenuItem.setSelected(true); getSelectedEdit().repaint(); } }; - loadGhost.putValue(AbstractAction.NAME, LanguageResource.getString("OPENGHOSTBOARD_STR")); - loadGhost.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_G, KeyEvent.CTRL_DOWN_MASK)); + loadGhost.putValue(Action.NAME, LanguageResource.getString("OPENGHOSTBOARD_STR")); + loadGhost.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK)); fileMenu.add(loadGhost); final AbstractAction loadImage = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("LOADBACKGROUNDIMAGE_STR")); - this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK)); + this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK)); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showOpenDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showOpenDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -1687,25 +1652,23 @@ public void actionPerformed(ActionEvent arg0) { final JMenu printMenu = new JMenu(LanguageResource.getString("PRINTMENU_STR")); final JMenuItem printOutline = new JMenuItem(LanguageResource.getString("PRINTOUTLINE_STR"), KeyEvent.VK_O); - printOutline.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, - ActionEvent.ALT_MASK)); + printOutline.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); printOutline.addActionListener(this); printMenu.add(printOutline); final JMenuItem printSpinTemplate = new JMenuItem(LanguageResource.getString("PRINTSPINTEMPLATE_STR"), KeyEvent.VK_T); -// printOutline.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, -// ActionEvent.ALT_MASK)); + // printOutline.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, + // ActionEvent.ALT_MASK)); printSpinTemplate.addActionListener(this); printMenu.add(printSpinTemplate); final JMenuItem printProfile = new JMenuItem(LanguageResource.getString("PRINTPROFILE_STR"), KeyEvent.VK_P); - printProfile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, - ActionEvent.ALT_MASK)); + printProfile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, ActionEvent.ALT_MASK)); printProfile.addActionListener(this); printMenu.add(printProfile); - final JMenuItem printSlices = new JMenuItem(LanguageResource.getString("PRINTCROSSECTION_STR"),KeyEvent.VK_S); - printSlices.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4,ActionEvent.ALT_MASK)); + final JMenuItem printSlices = new JMenuItem(LanguageResource.getString("PRINTCROSSECTION_STR"), KeyEvent.VK_S); + printSlices.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, ActionEvent.ALT_MASK)); printSlices.addActionListener(this); printMenu.add(printSlices); @@ -1714,11 +1677,12 @@ public void actionPerformed(ActionEvent arg0) { final JMenu printSandwichMenu = new JMenu(LanguageResource.getString("PRINTSANDWICHTEMPLATESMENU_STR")); final AbstractAction printProfileTemplate = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTSANDWICHPROFILETEMPLATE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); @@ -1735,7 +1699,7 @@ public void actionPerformed(ActionEvent arg0) { return; } - mPrintSandwichTemplates.printProfileTemplate(sandwichSettings.getMeasurement("SkinThickness"),sandwichSettings.getBoolean("Flatten"), 0.0); + mPrintSandwichTemplates.printProfileTemplate(sandwichSettings.getMeasurement("SkinThickness"), sandwichSettings.getBoolean("Flatten"), 0.0); settingsDialog.dispose(); } @@ -1743,21 +1707,22 @@ public void actionPerformed(ActionEvent arg0) { printSandwichMenu.add(printProfileTemplate); final AbstractAction printRailTemplate = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTSANDWICHRAILTEMPLATE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); String categoryName = LanguageResource.getString("SANDWICHPARAMETERSCATEGORY_STR"); Settings sandwichSettings = settings.addCategory(categoryName); sandwichSettings.addMeasurement("SkinThickness", 0.3, LanguageResource.getString("SANDWICHSKINTHICKNESS_STR")); - sandwichSettings.addMeasurement("ToRail", 2.54/2, LanguageResource.getString("SANDWICHDISTANCETORAIL_STR")); - sandwichSettings.addMeasurement("TailOffset", 2.0,LanguageResource.getString("SANDWICHTAILOFFSET")); + sandwichSettings.addMeasurement("ToRail", 2.54 / 2, LanguageResource.getString("SANDWICHDISTANCETORAIL_STR")); + sandwichSettings.addMeasurement("TailOffset", 2.0, LanguageResource.getString("SANDWICHTAILOFFSET")); sandwichSettings.addMeasurement("NoseOffset", 6.0, LanguageResource.getString("SANDWICHNOSEOFFSET")); - sandwichSettings.addBoolean("Flatten", false, LanguageResource.getString("SANDWICHFLATTEN_STR")); + sandwichSettings.addBoolean("Flatten", false, LanguageResource.getString("SANDWICHFLATTEN_STR")); SettingDialog settingsDialog = new SettingDialog(settings); settingsDialog.setTitle(LanguageResource.getString("PRINTSANDWICHRAILTEMPLATETITLE_STR")); settingsDialog.setModal(true); @@ -1767,7 +1732,7 @@ public void actionPerformed(ActionEvent arg0) { return; } - mPrintSandwichTemplates.printRailTemplate(sandwichSettings.getMeasurement("ToRail"), sandwichSettings.getMeasurement("SkinThickness"),sandwichSettings.getMeasurement("TailOffset"),sandwichSettings.getMeasurement("NoseOffset"), sandwichSettings.getBoolean("Flatten")); + mPrintSandwichTemplates.printRailTemplate(sandwichSettings.getMeasurement("ToRail"), sandwichSettings.getMeasurement("SkinThickness"), sandwichSettings.getMeasurement("TailOffset"), sandwichSettings.getMeasurement("NoseOffset"), sandwichSettings.getBoolean("Flatten")); settingsDialog.dispose(); } @@ -1775,17 +1740,18 @@ public void actionPerformed(ActionEvent arg0) { printSandwichMenu.add(printRailTemplate); final AbstractAction printDeckSkin = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTSANDWICHDECKSKINTEMPLATE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); String categoryName = LanguageResource.getString("SANDWICHPARAMETERSCATEGORY_STR"); Settings sandwichSettings = settings.addCategory(categoryName); - sandwichSettings.addMeasurement("ToRail", 2.54/2, LanguageResource.getString("SANDWICHDISTANCETORAIL_STR")); + sandwichSettings.addMeasurement("ToRail", 2.54 / 2, LanguageResource.getString("SANDWICHDISTANCETORAIL_STR")); SettingDialog settingsDialog = new SettingDialog(settings); settingsDialog.setTitle(LanguageResource.getString("PRINTSANDWICHDECKSKINTEMPLATETITLE_STR")); settingsDialog.setModal(true); @@ -1803,17 +1769,18 @@ public void actionPerformed(ActionEvent arg0) { printSandwichMenu.add(printDeckSkin); final AbstractAction printBottomSkin = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTSANDWICHBOTTOMSKINTEMPLATE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); String categoryName = LanguageResource.getString("SANDWICHPARAMETERSCATEGORY_STR"); Settings sandwichSettings = settings.addCategory(categoryName); - sandwichSettings.addMeasurement("ToRail", 2.54/2, LanguageResource.getString("SANDWICHDISTANCETORAIL_STR")); + sandwichSettings.addMeasurement("ToRail", 2.54 / 2, LanguageResource.getString("SANDWICHDISTANCETORAIL_STR")); SettingDialog settingsDialog = new SettingDialog(settings); settingsDialog.setTitle(LanguageResource.getString("PRINTSANDWICHBOTTOMSKINTEMPLATETITLE_STR")); settingsDialog.setModal(true); @@ -1837,11 +1804,12 @@ public void actionPerformed(ActionEvent arg0) { final JMenu printHWSMenu = new JMenu(LanguageResource.getString("PRINTHWSMENU_STR")); final AbstractAction printHWSSTringer = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTHWSSTRINGER_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); @@ -1863,7 +1831,7 @@ public void actionPerformed(ActionEvent arg0) { } settings.putPreferences(); - mPrintHollowWoodTemplates.printStringerTemplate(HWSSettings.getMeasurement("SkinThickness"),HWSSettings.getMeasurement("FrameThickness"), HWSSettings.getMeasurement("Webbing"), HWSSettings.getMeasurement("TailOffset"), HWSSettings.getMeasurement("NoseOffset")); + mPrintHollowWoodTemplates.printStringerTemplate(HWSSettings.getMeasurement("SkinThickness"), HWSSettings.getMeasurement("FrameThickness"), HWSSettings.getMeasurement("Webbing"), HWSSettings.getMeasurement("TailOffset"), HWSSettings.getMeasurement("NoseOffset")); settingsDialog.dispose(); } @@ -1871,11 +1839,12 @@ public void actionPerformed(ActionEvent arg0) { printHWSMenu.add(printHWSSTringer); final AbstractAction printHWSRibs = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTHWSRIBS_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); @@ -1896,7 +1865,7 @@ public void actionPerformed(ActionEvent arg0) { } settings.putPreferences(); - mPrintHollowWoodTemplates.printCrosssectionTemplates(HWSSettings.getMeasurement("DistanceFromRail"),HWSSettings.getMeasurement("SkinThickness"),HWSSettings.getMeasurement("FrameThickness"), HWSSettings.getMeasurement("Webbing")); + mPrintHollowWoodTemplates.printCrosssectionTemplates(HWSSettings.getMeasurement("DistanceFromRail"), HWSSettings.getMeasurement("SkinThickness"), HWSSettings.getMeasurement("FrameThickness"), HWSSettings.getMeasurement("Webbing")); settingsDialog.dispose(); } @@ -1904,11 +1873,12 @@ public void actionPerformed(ActionEvent arg0) { printHWSMenu.add(printHWSRibs); final AbstractAction printHWSRail = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTHWSRAIL_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); @@ -1931,7 +1901,8 @@ public void actionPerformed(ActionEvent arg0) { } settings.putPreferences(); - mPrintHollowWoodTemplates.printRailTemplate(HWSSettings.getMeasurement("DistanceFromRail"),HWSSettings.getMeasurement("SkinThickness"),HWSSettings.getMeasurement("FrameThickness"), HWSSettings.getMeasurement("Webbing"), HWSSettings.getMeasurement("TailOffset"), HWSSettings.getMeasurement("NoseOffset")); + mPrintHollowWoodTemplates.printRailTemplate(HWSSettings.getMeasurement("DistanceFromRail"), HWSSettings.getMeasurement("SkinThickness"), HWSSettings.getMeasurement("FrameThickness"), HWSSettings.getMeasurement("Webbing"), HWSSettings.getMeasurement("TailOffset"), + HWSSettings.getMeasurement("NoseOffset")); settingsDialog.dispose(); } @@ -1939,11 +1910,12 @@ public void actionPerformed(ActionEvent arg0) { printHWSMenu.add(printHWSRail); final AbstractAction printHWSNosePiece = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { - this.putValue(Action.NAME, LanguageResource.getString("PRINTHWSTAILPIECE_STR")); + this.putValue(Action.NAME, LanguageResource.getString("PRINTHWSNOSEPIECE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); @@ -1966,7 +1938,8 @@ public void actionPerformed(ActionEvent arg0) { } settings.putPreferences(); - mPrintHollowWoodTemplates.printNoseTemplate(HWSSettings.getMeasurement("DistanceFromRail"),HWSSettings.getMeasurement("SkinThickness"),HWSSettings.getMeasurement("FrameThickness"), HWSSettings.getMeasurement("Webbing"), HWSSettings.getMeasurement("TailOffset"), HWSSettings.getMeasurement("NoseOffset")); + mPrintHollowWoodTemplates.printNoseTemplate(HWSSettings.getMeasurement("DistanceFromRail"), HWSSettings.getMeasurement("SkinThickness"), HWSSettings.getMeasurement("FrameThickness"), HWSSettings.getMeasurement("Webbing"), HWSSettings.getMeasurement("TailOffset"), + HWSSettings.getMeasurement("NoseOffset")); settingsDialog.dispose(); } @@ -1974,11 +1947,12 @@ public void actionPerformed(ActionEvent arg0) { printHWSMenu.add(printHWSNosePiece); final AbstractAction printHWSTailPiece = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { - this.putValue(Action.NAME, LanguageResource.getString("PRINTHWSNOSEPIECE_STR")); + this.putValue(Action.NAME, LanguageResource.getString("PRINTHWSTAILPIECE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); @@ -2001,7 +1975,8 @@ public void actionPerformed(ActionEvent arg0) { } settings.putPreferences(); - mPrintHollowWoodTemplates.printTailTemplate(HWSSettings.getMeasurement("DistanceFromRail"),HWSSettings.getMeasurement("SkinThickness"),HWSSettings.getMeasurement("FrameThickness"), HWSSettings.getMeasurement("Webbing"), HWSSettings.getMeasurement("TailOffset"), HWSSettings.getMeasurement("NoseOffset")); + mPrintHollowWoodTemplates.printTailTemplate(HWSSettings.getMeasurement("DistanceFromRail"), HWSSettings.getMeasurement("SkinThickness"), HWSSettings.getMeasurement("FrameThickness"), HWSSettings.getMeasurement("Webbing"), HWSSettings.getMeasurement("TailOffset"), + HWSSettings.getMeasurement("NoseOffset")); settingsDialog.dispose(); } @@ -2009,11 +1984,12 @@ public void actionPerformed(ActionEvent arg0) { printHWSMenu.add(printHWSTailPiece); final AbstractAction printHWSDeckTemplate = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTHWSDECKTEMPLATE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); @@ -2041,11 +2017,12 @@ public void actionPerformed(ActionEvent arg0) { printHWSMenu.add(printHWSDeckTemplate); final AbstractAction printHWSBottomTemplate = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTHWSBOTTOMTEMPLATE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); @@ -2073,15 +2050,16 @@ public void actionPerformed(ActionEvent arg0) { printHWSMenu.add(printHWSBottomTemplate); printMenu.add(printHWSMenu); - + final JMenu printChamberedWoodMenu = new JMenu(LanguageResource.getString("PRINTCHAMBEREDWOODTEMPLATESMENU_STR")); final AbstractAction printChamberedWoodTemplate = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTCHAMBEREDWOODPROFILETEMPLATE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final CategorizedSettings settings = new CategorizedSettings(); @@ -2089,19 +2067,18 @@ public void actionPerformed(ActionEvent arg0) { final Settings chamberedWoodSettings = settings.addCategory(categoryName); chamberedWoodSettings.addBoolean("Draw grid", true, LanguageResource.getString("DRAWGRID_STR")); chamberedWoodSettings.addMeasurement("Start Offset from center", 0.0, LanguageResource.getString("CHAMBEREDWOODOFFSETFROMCENTER_STR")); - chamberedWoodSettings.addMeasurement("End Offset from center", mCurrentBrd.getMaxWidth()/2.0, LanguageResource.getString("CHAMBEREDWOODENDOFFSET_STR")); + chamberedWoodSettings.addMeasurement("End Offset from center", mCurrentBrd.getMaxWidth() / 2.0, LanguageResource.getString("CHAMBEREDWOODENDOFFSET_STR")); chamberedWoodSettings.addMeasurement("Plank thickness", 2.54, LanguageResource.getString("CHAMBEREDWOODPLANKTHICKNESS_STR")); chamberedWoodSettings.addMeasurement("Deck/Bottom thickness", 0.8, LanguageResource.getString("CHAMBEREDWOODDECKANDBOTTOMTHICKNESS_STR")); chamberedWoodSettings.addBoolean("Draw chambering", true, LanguageResource.getString("CHAMBEREDDRAWCHAMBERING_STR")); chamberedWoodSettings.addBoolean("Draw alignment marks", true, LanguageResource.getString("CHAMBEREDDRAWALIGNEMNETMARKS_STR")); chamberedWoodSettings.addBoolean("Print multiple", false, LanguageResource.getString("CHAMBEREDPRINTMULTIPLETEMPLATES_STR")); - + settings.getPreferences(); - - if(chamberedWoodSettings.getMeasurement("End Offset from center") > mCurrentBrd.getMaxWidth()/2.0) - { - chamberedWoodSettings.setMeasurement("End Offset from center", mCurrentBrd.getMaxWidth()/2.0); + + if (chamberedWoodSettings.getMeasurement("End Offset from center") > mCurrentBrd.getMaxWidth() / 2.0) { + chamberedWoodSettings.setMeasurement("End Offset from center", mCurrentBrd.getMaxWidth() / 2.0); } SettingDialog settingsDialog = new SettingDialog(settings); @@ -2112,22 +2089,18 @@ public void actionPerformed(ActionEvent arg0) { settingsDialog.dispose(); return; } - + double start = chamberedWoodSettings.getMeasurement("Start Offset from center"); double end = chamberedWoodSettings.getMeasurement("End Offset from center"); double plankThickness = chamberedWoodSettings.getMeasurement("Plank thickness"); boolean printMultiple = chamberedWoodSettings.getBoolean("Print multiple"); - if(printMultiple) - { - - int numberOfTemplates = (int)((end-start)/plankThickness); - - int selection = JOptionPane.showConfirmDialog( - BoardCAD.getInstance().getFrame(), - String.valueOf(numberOfTemplates) + " " + LanguageResource.getString("PRINTCHAMBEREDWOODMULTIPLETEMPLATESMSG_STR"), - LanguageResource.getString("PRINTCHAMBEREDWOODMULTIPLETEMPLATESTITLE_STR"), JOptionPane.WARNING_MESSAGE, - JOptionPane.YES_NO_OPTION); + if (printMultiple) { + + int numberOfTemplates = (int) ((end - start) / plankThickness); + + int selection = JOptionPane.showConfirmDialog(BoardCAD.getInstance().getFrame(), String.valueOf(numberOfTemplates) + " " + LanguageResource.getString("PRINTCHAMBEREDWOODMULTIPLETEMPLATESMSG_STR"), LanguageResource.getString("PRINTCHAMBEREDWOODMULTIPLETEMPLATESTITLE_STR"), + JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION); if (selection != JOptionPane.YES_OPTION) { return; @@ -2135,10 +2108,11 @@ public void actionPerformed(ActionEvent arg0) { } } - mPrintChamberedWoodTemplate.printTemplate(chamberedWoodSettings.getBoolean("Draw grid"), start, end, plankThickness, chamberedWoodSettings.getMeasurement("Deck/Bottom thickness"), chamberedWoodSettings.getBoolean("Draw chambering"), chamberedWoodSettings.getBoolean("Draw alignment marks"), printMultiple); - + mPrintChamberedWoodTemplate.printTemplate(chamberedWoodSettings.getBoolean("Draw grid"), start, end, plankThickness, chamberedWoodSettings.getMeasurement("Deck/Bottom thickness"), chamberedWoodSettings.getBoolean("Draw chambering"), + chamberedWoodSettings.getBoolean("Draw alignment marks"), printMultiple); + settingsDialog.dispose(); - + settings.putPreferences(); } @@ -2149,21 +2123,25 @@ public void actionPerformed(ActionEvent arg0) { printMenu.addSeparator(); - /* final JMenuItem printSpecSheet = new JMenuItem(LanguageResource.getString("PRINTSPECSHEET_STR"),KeyEvent.VK_H); - printSpecSheet.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5,ActionEvent.ALT_MASK)); - printSpecSheet.addActionListener(this); - printMenu.add(printSpecSheet); -*/ - + /* + * final JMenuItem printSpecSheet = new + * JMenuItem(LanguageResource.getString + * ("PRINTSPECSHEET_STR"),KeyEvent.VK_H); + * printSpecSheet.setAccelerator(KeyStroke + * .getKeyStroke(KeyEvent.VK_5,ActionEvent.ALT_MASK)); + * printSpecSheet.addActionListener(this); + * printMenu.add(printSpecSheet); + */ final AbstractAction printSpecSheet = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTSPECSHEET_STR")); this.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("PRINTSPECSHEET_STR")); this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_5, ActionEvent.ALT_MASK)); }; + @Override public void actionPerformed(ActionEvent arg0) { mPrintSpecSheet.printSpecSheet(); } @@ -2172,11 +2150,6 @@ public void actionPerformed(ActionEvent arg0) { printMenu.add(printSpecSheet); - - - - - mPrintBrd = new PrintBrd(); mPrintSpecSheet = new PrintSpecSheet(); mPrintChamberedWoodTemplate = new PrintChamberedWoodTemplate(); @@ -2184,15 +2157,15 @@ public void actionPerformed(ActionEvent arg0) { mPrintHollowWoodTemplates = new PrintHollowWoodTemplates(); final AbstractAction printSpecSheetToFile = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PRINTSPECSHEETTOFILE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { - TwoValuesInputDialog resDialog = new TwoValuesInputDialog( - mFrame); + TwoValuesInputDialog resDialog = new TwoValuesInputDialog(mFrame); resDialog.setMessageText(LanguageResource.getString("PRINTSPECSHEETTOFILERESOLUTIONMSG_STR")); resDialog.setValue1(1200); resDialog.setValue2(1600); @@ -2210,14 +2183,11 @@ public void actionPerformed(ActionEvent arg0) { width = (int) resDialog.getValue1(); height = (int) resDialog.getValue2(); } catch (Exception e) { - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), LanguageResource.getString("PRINTSPECSHEETTOFILEINVALIDPARAMETERSMSG_STR"), - LanguageResource.getString("PRINTSPECSHEETTOFILEINVALIDPARAMETERSTITLE_STR"), JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), LanguageResource.getString("PRINTSPECSHEETTOFILEINVALIDPARAMETERSMSG_STR"), LanguageResource.getString("PRINTSPECSHEETTOFILEINVALIDPARAMETERSTITLE_STR"), JOptionPane.ERROR_MESSAGE); return; } - BufferedImage img = new BufferedImage(height, width, - BufferedImage.TYPE_INT_RGB); + BufferedImage img = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB); Graphics2D g = img.createGraphics(); Graphics2D g2d = (Graphics2D) g.create(); @@ -2226,9 +2196,9 @@ public void actionPerformed(ActionEvent arg0) { g2d.setRenderingHint( - RenderingHints.KEY_ANTIALIASING, + RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + RenderingHints.VALUE_ANTIALIAS_ON); Paper paper = new Paper(); paper.setImageableArea(0, 0, width, height); @@ -2250,17 +2220,14 @@ public void actionPerformed(ActionEvent arg0) { FileFilter filter = new FileFilter() { // Accept all directories and graphics files. + @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } String extension = FileTools.getExtension(f); - if (extension != null - && (extension.equals("png") - || extension.equals("gif") - || extension.equals("bmp") || extension - .equals("jpg"))) { + if (extension != null && (extension.equals("png") || extension.equals("gif") || extension.equals("bmp") || extension.equals("jpg"))) { return true; } @@ -2268,6 +2235,7 @@ public boolean accept(File f) { } // The description of this filter + @Override public String getDescription() { return LanguageResource.getString("PRINTSPECSHEETTOFILEIMAGEFILES_STR"); } @@ -2275,8 +2243,7 @@ public String getDescription() { fc.setFileFilter(filter); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2287,8 +2254,7 @@ public String getDescription() { if (filename == null) return; - if(FileTools.getExtension(filename) == "") - { + if (FileTools.getExtension(filename) == "") { filename = FileTools.setExtension(filename, "jpg"); } @@ -2296,10 +2262,10 @@ public String getDescription() { try { File outputfile = new File(filename); - ImageIO.write(img, FileTools.getExtension(filename),outputfile); + ImageIO.write(img, FileTools.getExtension(filename), outputfile); } catch (Exception e) { String str = LanguageResource.getString("PRINTSPECSHEETTOFILEERRORMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("PRINTSPECSHEETTOFILEERRORTITLE_STR"), JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("PRINTSPECSHEETTOFILEERRORTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -2310,16 +2276,16 @@ public String getDescription() { fileMenu.add(printMenu); final JMenu importMenu = new JMenu(LanguageResource.getString("IMPORTMENU_STR")); - final JMenu importBezierMenu = new JMenu(LanguageResource.getString("IMPORTBEZIERMENU_STR")); importMenu.add(importBezierMenu); final AbstractAction importOutlineAction = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("IMPORTBEZIEROUTLINE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { BrdImportOutlineCommand cmd = new BrdImportOutlineCommand(mOutlineEdit); cmd.execute(); @@ -2328,11 +2294,12 @@ public void actionPerformed(ActionEvent arg0) { }; importBezierMenu.add(importOutlineAction); final AbstractAction importProfileAction = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("IMPORTBEZIERPROFILE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { BrdImportProfileCommand cmd = new BrdImportProfileCommand(mBottomAndDeckEdit); cmd.execute(); @@ -2341,11 +2308,12 @@ public void actionPerformed(ActionEvent arg0) { }; importBezierMenu.add(importProfileAction); final AbstractAction importCrossSectionAction = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("IMPORTBEZIERCROSSSECTION_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { BrdImportCrossSectionCommand cmd = new BrdImportCrossSectionCommand(mCrossSectionEdit); cmd.execute(); @@ -2359,17 +2327,17 @@ public void actionPerformed(ActionEvent arg0) { final JMenu exportMenu = new JMenu(LanguageResource.getString("EXPORTMENU_STR")); final AbstractAction exportStep = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXPORTNURBSTOSTEP_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2383,13 +2351,10 @@ public void actionPerformed(ActionEvent arg0) { BoardCAD.defaultDirectory = file.getPath(); try { - board_handler.export_board(new PrintStream(new File( - filename)), filename); + board_handler.export_board(new PrintStream(new File(filename)), filename); } catch (Exception e) { String str = LanguageResource.getString("EXPORTNURBSTOSTEPFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTNURBSTOSTEPFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTNURBSTOSTEPFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -2398,20 +2363,19 @@ public void actionPerformed(ActionEvent arg0) { exportMenu.add(exportStep); - final AbstractAction exportDxf3D = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXPORTNURBSTODXF_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2425,13 +2389,10 @@ public void actionPerformed(ActionEvent arg0) { BoardCAD.defaultDirectory = file.getPath(); try { - board_handler.export_board_dxf(new PrintStream(new File( - filename)), filename); + board_handler.export_board_dxf(new PrintStream(new File(filename)), filename); } catch (Exception e) { String str = LanguageResource.getString("EXPORTNURBSTODXFFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTNURBSTODXFFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTNURBSTODXFFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -2440,18 +2401,18 @@ public void actionPerformed(ActionEvent arg0) { exportMenu.add(exportDxf3D); final AbstractAction exportStl3D = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXPORTNURBSTOSTL_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2465,13 +2426,10 @@ public void actionPerformed(ActionEvent arg0) { BoardCAD.defaultDirectory = file.getPath(); try { - board_handler.export_board_stl(new PrintStream(new File( - filename)), filename); + board_handler.export_board_stl(new PrintStream(new File(filename)), filename); } catch (Exception e) { String str = LanguageResource.getString("EXPORTNURBSTOSTLFAILEDTITLE_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTNURBSTOSTLFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTNURBSTOSTLFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -2483,11 +2441,12 @@ public void actionPerformed(ActionEvent arg0) { JMenu beziersExportMenu = new JMenu(LanguageResource.getString("EXPORTBEZIERS_STR")); final AbstractAction exportBezierOutline = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIEROUTLINE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); @@ -2495,14 +2454,14 @@ public void actionPerformed(ActionEvent arg0) { fc.setFileFilter(new FileFilter() { // Accept all directories and brd and s3d files. + @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } String extension = FileTools.getExtension(f); - if (extension != null && extension.equals("otl") ) - { + if (extension != null && extension.equals("otl")) { return true; } @@ -2510,13 +2469,13 @@ public boolean accept(File f) { } // The description of this filter + @Override public String getDescription() { return LanguageResource.getString("OUTLINEFILES_STR"); } }); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2528,15 +2487,12 @@ public String getDescription() { return; try { - if(BrdWriter.exportOutline(getCurrentBrd(), filename) == false) - { + if (BrdWriter.exportOutline(getCurrentBrd(), filename) == false) { throw new Exception(); } } catch (Exception e) { String str = LanguageResource.getString("EXPORTBEZIEROUTLINEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTBEZIEROUTLINEFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTBEZIEROUTLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } @@ -2548,11 +2504,12 @@ public String getDescription() { beziersExportMenu.add(exportBezierOutline); final AbstractAction exportBezierProfile = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIERPROFILE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); @@ -2560,14 +2517,14 @@ public void actionPerformed(ActionEvent arg0) { fc.setFileFilter(new FileFilter() { // Accept all directories and pfl files. + @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } String extension = FileTools.getExtension(f); - if (extension != null && extension.equals("pfl") ) - { + if (extension != null && extension.equals("pfl")) { return true; } @@ -2575,13 +2532,13 @@ public boolean accept(File f) { } // The description of this filter + @Override public String getDescription() { return LanguageResource.getString("PROFILEFILES_STR"); } }); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2593,15 +2550,12 @@ public String getDescription() { return; try { - if(BrdWriter.exportProfile(getCurrentBrd(), filename) == false) - { + if (BrdWriter.exportProfile(getCurrentBrd(), filename) == false) { throw new Exception(); } } catch (Exception e) { String str = LanguageResource.getString("EXPORTBEZIERFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTBEZIERFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTBEZIERFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } @@ -2613,11 +2567,12 @@ public String getDescription() { beziersExportMenu.add(exportBezierProfile); final AbstractAction exportBezierCrossection = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIERCROSSECTION_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); @@ -2625,14 +2580,14 @@ public void actionPerformed(ActionEvent arg0) { fc.setFileFilter(new FileFilter() { // Accept all directories and brd and s3d files. + @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } String extension = FileTools.getExtension(f); - if (extension != null && extension.equals("crs") ) - { + if (extension != null && extension.equals("crs")) { return true; } @@ -2640,13 +2595,13 @@ public boolean accept(File f) { } // The description of this filter + @Override public String getDescription() { return LanguageResource.getString("CROSSECTIONFILES_STR"); } }); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2658,15 +2613,12 @@ public String getDescription() { return; try { - if(BrdWriter.exportCrossection(getCurrentBrd(), getCurrentBrd().getCurrentCrossSectionIndex(), filename) == false) - { + if (BrdWriter.exportCrossection(getCurrentBrd(), getCurrentBrd().getCurrentCrossSectionIndex(), filename) == false) { throw new Exception(); } } catch (Exception e) { String str = LanguageResource.getString("EXPORTBEZIERFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTBEZIERFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTBEZIERFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } @@ -2681,18 +2633,18 @@ public String getDescription() { exportMenu.addSeparator(); final AbstractAction exportProfileAsDxfSpline = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIERPROFILEASDXFSPLINE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2707,15 +2659,12 @@ public void actionPerformed(ActionEvent arg0) { try { BezierSpline[] patches = new BezierSpline[2]; - patches[0] = BoardCAD.getInstance().getCurrentBrd() - .getBottom(); + patches[0] = BoardCAD.getInstance().getCurrentBrd().getBottom(); patches[1] = new BezierSpline(); - BezierSpline org = BoardCAD.getInstance().getCurrentBrd() - .getDeck(); + BezierSpline org = BoardCAD.getInstance().getCurrentBrd().getDeck(); for (int i = 0; i < org.getNrOfControlPoints(); i++) { - BezierKnot controlPoint = (BezierKnot) org.getControlPoint( - (org.getNrOfControlPoints() - 1) - i).clone(); + BezierKnot controlPoint = (BezierKnot) org.getControlPoint((org.getNrOfControlPoints() - 1) - i).clone(); controlPoint.switch_tangents(); patches[1].append(controlPoint); } @@ -2723,9 +2672,7 @@ public void actionPerformed(ActionEvent arg0) { DxfExport.exportBezierSplines(filename, patches); } catch (Exception e) { String str = LanguageResource.getString("EXPORTBEZIERPROFILEASDXFSPLINEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTBEZIERPROFILEASDXFSPLINEFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTBEZIERPROFILEASDXFSPLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -2734,18 +2681,18 @@ public void actionPerformed(ActionEvent arg0) { exportMenu.add(exportProfileAsDxfSpline); final AbstractAction exportOutlineAsDxfSpline = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { - this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIEROUTLINEASDXFSPLINE_STR")); + this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIEROUTLINEASDXFSPLINE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2760,51 +2707,42 @@ public void actionPerformed(ActionEvent arg0) { try { BezierSpline[] patches = new BezierSpline[2]; - patches[0] = BoardCAD.getInstance().getCurrentBrd() - .getOutline(); + patches[0] = BoardCAD.getInstance().getCurrentBrd().getOutline(); patches[1] = new BezierSpline(); - BezierSpline org = BoardCAD.getInstance().getCurrentBrd() - .getOutline(); + BezierSpline org = BoardCAD.getInstance().getCurrentBrd().getOutline(); for (int i = 0; i < org.getNrOfControlPoints(); i++) { - BezierKnot controlPoint = (BezierKnot) org.getControlPoint( - (org.getNrOfControlPoints() - 1) - i).clone(); + BezierKnot controlPoint = (BezierKnot) org.getControlPoint((org.getNrOfControlPoints() - 1) - i).clone(); controlPoint.switch_tangents(); - controlPoint.getEndPoint().y = -controlPoint - .getEndPoint().y; - controlPoint.getTangentToPrev().y = -controlPoint - .getTangentToPrev().y; - controlPoint.getTangentToNext().y = -controlPoint - .getTangentToNext().y; + controlPoint.getEndPoint().y = -controlPoint.getEndPoint().y; + controlPoint.getTangentToPrev().y = -controlPoint.getTangentToPrev().y; + controlPoint.getTangentToNext().y = -controlPoint.getTangentToNext().y; patches[1].append(controlPoint); } DxfExport.exportBezierSplines(filename, patches); } catch (Exception e) { String str = LanguageResource.getString("EXPORTBEZIEROUTLINEASDXFSPLINEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTBEZIEROUTLINEASDXFSPLINEFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTBEZIEROUTLINEASDXFSPLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } }; exportMenu.add(exportOutlineAsDxfSpline); - final AbstractAction exportCurrentCrossSectionAsDxfSpline = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { - this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIERCROSSSECTIONASDXFSPLINE_STR")); + this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIERCROSSSECTIONASDXFSPLINE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2817,53 +2755,46 @@ public void actionPerformed(ActionEvent arg0) { BoardCAD.defaultDirectory = file.getPath(); - try - { + try { BezierSpline[] patches = new BezierSpline[2]; patches[0] = BoardCAD.getInstance().getCurrentBrd().getCurrentCrossSection().getBezierSpline(); patches[1] = new BezierSpline(); BezierSpline org = BoardCAD.getInstance().getCurrentBrd().getCurrentCrossSection().getBezierSpline(); - for (int i = 0; i < org.getNrOfControlPoints(); i++) - { - BezierKnot controlPoint = (BezierKnot)org.getControlPoint((org.getNrOfControlPoints() - 1) - i).clone(); + for (int i = 0; i < org.getNrOfControlPoints(); i++) { + BezierKnot controlPoint = (BezierKnot) org.getControlPoint((org.getNrOfControlPoints() - 1) - i).clone(); controlPoint.switch_tangents(); controlPoint.getEndPoint().x = -controlPoint.getEndPoint().x; - controlPoint.getTangentToPrev().x = -controlPoint .getTangentToPrev().x; - controlPoint.getTangentToNext().x = -controlPoint .getTangentToNext().x; + controlPoint.getTangentToPrev().x = -controlPoint.getTangentToPrev().x; + controlPoint.getTangentToNext().x = -controlPoint.getTangentToNext().x; patches[1].append(controlPoint); } DxfExport.exportBezierSplines(filename, patches); - } - catch (Exception e) - { + } catch (Exception e) { String str = LanguageResource.getString("EXPORTBEZIERCROSSSECTIONASDXFSPLINEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTBEZIERCROSSSECTIONASDXFSPLINEFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTBEZIERCROSSSECTIONASDXFSPLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } }; exportMenu.add(exportCurrentCrossSectionAsDxfSpline); - - exportMenu.addSeparator(); + exportMenu.addSeparator(); final AbstractAction exportProfileAsDxfPolyline = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIERPROFILEASDXFPOLYLINE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2878,15 +2809,12 @@ public void actionPerformed(ActionEvent arg0) { try { BezierSpline[] patches = new BezierSpline[2]; - patches[0] = BoardCAD.getInstance().getCurrentBrd() - .getBottom(); + patches[0] = BoardCAD.getInstance().getCurrentBrd().getBottom(); patches[1] = new BezierSpline(); - BezierSpline org = BoardCAD.getInstance().getCurrentBrd() - .getDeck(); + BezierSpline org = BoardCAD.getInstance().getCurrentBrd().getDeck(); for (int i = 0; i < org.getNrOfControlPoints(); i++) { - BezierKnot controlPoint = (BezierKnot) org.getControlPoint( - (org.getNrOfControlPoints() - 1) - i).clone(); + BezierKnot controlPoint = (BezierKnot) org.getControlPoint((org.getNrOfControlPoints() - 1) - i).clone(); controlPoint.switch_tangents(); patches[1].append(controlPoint); } @@ -2894,9 +2822,7 @@ public void actionPerformed(ActionEvent arg0) { DxfExport.exportPolylineFromSplines(filename, patches, 100); } catch (Exception e) { String str = LanguageResource.getString("EXPORTBEZIERPROFILEASDXFPOLYLINEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTBEZIERPROFILEASDXFPOLYLINEFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTBEZIERPROFILEASDXFPOLYLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -2905,18 +2831,18 @@ public void actionPerformed(ActionEvent arg0) { exportMenu.add(exportProfileAsDxfPolyline); final AbstractAction exportOutlineAsDxfPolyline = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIEROUTLINEASDXFPOLYLINE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2931,30 +2857,22 @@ public void actionPerformed(ActionEvent arg0) { try { BezierSpline[] patches = new BezierSpline[2]; - patches[0] = BoardCAD.getInstance().getCurrentBrd() - .getOutline(); + patches[0] = BoardCAD.getInstance().getCurrentBrd().getOutline(); patches[1] = new BezierSpline(); - BezierSpline org = BoardCAD.getInstance().getCurrentBrd() - .getOutline(); + BezierSpline org = BoardCAD.getInstance().getCurrentBrd().getOutline(); for (int i = 0; i < org.getNrOfControlPoints(); i++) { - BezierKnot controlPoint = (BezierKnot) org.getControlPoint( - (org.getNrOfControlPoints() - 1) - i).clone(); + BezierKnot controlPoint = (BezierKnot) org.getControlPoint((org.getNrOfControlPoints() - 1) - i).clone(); controlPoint.switch_tangents(); - controlPoint.getEndPoint().y = -controlPoint - .getEndPoint().y; - controlPoint.getTangentToPrev().y = -controlPoint - .getTangentToPrev().y; - controlPoint.getTangentToNext().y = -controlPoint - .getTangentToNext().y; + controlPoint.getEndPoint().y = -controlPoint.getEndPoint().y; + controlPoint.getTangentToPrev().y = -controlPoint.getTangentToPrev().y; + controlPoint.getTangentToNext().y = -controlPoint.getTangentToNext().y; patches[1].append(controlPoint); } DxfExport.exportPolylineFromSplines(filename, patches, 100); } catch (Exception e) { String str = LanguageResource.getString("EXPORTBEZIEROUTLINEASDXFPOLYLINEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTBEZIEROUTLINEASDXFPOLYLINEFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTBEZIEROUTLINEASDXFPOLYLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -2963,18 +2881,18 @@ public void actionPerformed(ActionEvent arg0) { exportMenu.add(exportOutlineAsDxfPolyline); final AbstractAction exportCrossSectionAsDxfPolyline = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXPORTBEZIERCROSSSECTIONASDXFPOLYLINE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -2987,16 +2905,14 @@ public void actionPerformed(ActionEvent arg0) { BoardCAD.defaultDirectory = file.getPath(); - try - { + try { BezierSpline[] patches = new BezierSpline[2]; patches[0] = BoardCAD.getInstance().getCurrentBrd().getCurrentCrossSection().getBezierSpline(); patches[1] = new BezierSpline(); BezierSpline org = BoardCAD.getInstance().getCurrentBrd().getCurrentCrossSection().getBezierSpline(); - for (int i = 0; i < org.getNrOfControlPoints(); i++) - { - BezierKnot controlPoint = (BezierKnot)org.getControlPoint((org.getNrOfControlPoints() - 1) - i).clone(); + for (int i = 0; i < org.getNrOfControlPoints(); i++) { + BezierKnot controlPoint = (BezierKnot) org.getControlPoint((org.getNrOfControlPoints() - 1) - i).clone(); controlPoint.switch_tangents(); controlPoint.getEndPoint().x = -controlPoint.getEndPoint().x; controlPoint.getTangentToPrev().x = -controlPoint.getTangentToPrev().x; @@ -3004,31 +2920,26 @@ public void actionPerformed(ActionEvent arg0) { patches[1].append(controlPoint); } DxfExport.exportPolylineFromSplines(filename, patches, 100); - } - catch (Exception e) - { + } catch (Exception e) { String str = LanguageResource.getString("EXPORTBEZIERCROSSSECTIONASDXFPOLYLINEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("EXPORTBEZIERCROSSECTIONASDXFPOLYLINEFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("EXPORTBEZIERCROSSECTIONASDXFPOLYLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } }; exportMenu.add(exportCrossSectionAsDxfPolyline); - + fileMenu.add(exportMenu); final JMenu gcodeMenu = new JMenu(LanguageResource.getString("GCODEMENU_STR")); - - AbstractAction exportGcode = new AbstractAction() - { + AbstractAction exportGcode = new AbstractAction() { { this.putValue(Action.NAME, "Nurbs to Gcode deck"); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); @@ -3040,13 +2951,13 @@ public void actionPerformed(ActionEvent arg0) { File file = fc.getSelectedFile(); - String filename = file.getPath(); // Load and display selection - if(filename == null) + String filename = file.getPath(); // Load and display selection + if (filename == null) return; BoardCAD.defaultDirectory = file.getPath(); - if(board_handler.is_empty()) { + if (board_handler.is_empty()) { board_handler.approximate_bezier(getCurrentBrd(), false); } board_handler.generateGCodeDeck(filename); @@ -3055,13 +2966,12 @@ public void actionPerformed(ActionEvent arg0) { }; gcodeMenu.add(exportGcode); - - AbstractAction exportGcodeBottom = new AbstractAction() - { + AbstractAction exportGcodeBottom = new AbstractAction() { { this.putValue(Action.NAME, "Nurbs to Gcode bottom"); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); @@ -3073,13 +2983,13 @@ public void actionPerformed(ActionEvent arg0) { File file = fc.getSelectedFile(); - String filename = file.getPath(); // Load and display selection - if(filename == null) + String filename = file.getPath(); // Load and display selection + if (filename == null) return; BoardCAD.defaultDirectory = file.getPath(); - if(board_handler.is_empty()) { + if (board_handler.is_empty()) { board_handler.approximate_bezier(getCurrentBrd(), false); } board_handler.generateGCodeBottom(filename); @@ -3091,47 +3001,48 @@ public void actionPerformed(ActionEvent arg0) { gcodeMenu.addSeparator(); final AbstractAction gcodeBezier = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("GCODEBEZIER_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { BezierBoard brd = getCurrentBrd(); MachineConfig machineConfig = new MachineConfig(); - machineConfig.setBoard((BezierBoard)brd.clone()); + machineConfig.setBoard((BezierBoard) brd.clone()); MachineDialog dialog = new MachineDialog(machineConfig); - //dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); - //dialog.setModal(false); - + // dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); + // dialog.setModal(false); + machineConfig.setMachineView(dialog.getMachineView()); machineConfig.initialize(); machineConfig.getPreferences(); - - //Turn of sandwich compensation so we don't use sandwich compensation by accident (lesson learned the hard way) + + // Turn of sandwich compensation so we don't use sandwich + // compensation by accident (lesson learned the hard way) Settings sandwichCompensationSettings = machineConfig.getCategory(LanguageResource.getString("SANDWICHCOMPENSATIONCATEGORY_STR")); sandwichCompensationSettings.setBoolean(SandwichCompensation.SANDWICH_DECK_COMPENSATION_ON, false); sandwichCompensationSettings.setBoolean(SandwichCompensation.SANDWICH_BOTTOM_COMPENSATION_ON, false); sandwichCompensationSettings.setBoolean(SandwichCompensation.SANDWICH_OUTLINE_COMPENSATION_ON, false); Settings generalSettings = machineConfig.getCategory(LanguageResource.getString("GENERALCATEGORY_STR")); - - if(generalSettings.getBoolean(MachineConfig.USE_BRD_SETTINGS) == true) - { + + if (generalSettings.getBoolean(MachineConfig.USE_BRD_SETTINGS) == true) { System.out.printf("Using board settings"); - if(generalSettings.getEnumeration(MachineConfig.BLANKHOLDINGSYSTEM_TYPE) == 0) - { - //generalSettings.getDouble(MachineConfig.TAILSTOP_POS, ); + if (generalSettings.getEnumeration(MachineConfig.BLANKHOLDINGSYSTEM_TYPE) == 0) { + // generalSettings.getDouble(MachineConfig.TAILSTOP_POS, + // ); Settings supportsSettings = machineConfig.getCategory(LanguageResource.getString("BLANKHOLDINGSYSTEMCATEGORY_STR")); supportsSettings.setObject(SupportsBlankHoldingSystem.SUPPORT_1_POS, new Double(brd.getStrut1()[0])); supportsSettings.setObject(SupportsBlankHoldingSystem.SUPPORT_2_POS, new Double(brd.getStrut2()[0])); - + supportsSettings.setObject(SupportsBlankHoldingSystem.SUPPORT_1_HEIGHT, new Double(brd.getStrut1()[1])); supportsSettings.setObject(SupportsBlankHoldingSystem.SUPPORT_2_HEIGHT, new Double(brd.getStrut2()[1])); } - + generalSettings.setObject(MachineConfig.BLANK, generalSettings.new FileName(brd.getBlankFile())); Settings cutsSettings = machineConfig.getCategory(LanguageResource.getString("CUTSCATEGORY_STR")); @@ -3140,37 +3051,36 @@ public void actionPerformed(ActionEvent arg0) { cutsSettings.setObject(MachineConfig.DECK_RAIL_CUTS, new Integer(brd.getTopShoulderCuts())); cutsSettings.setObject(MachineConfig.BOTTOM_CUTS, new Integer(brd.getBottomCuts())); cutsSettings.setObject(MachineConfig.BOTTOM_RAIL_CUTS, new Integer(brd.getBottomRailCuts())); - + cutsSettings.setObject(MachineConfig.DECK_ANGLE, new Double(brd.getTopShoulderAngle())); cutsSettings.setObject(MachineConfig.DECK_RAIL_ANGLE, new Double(brd.getMaxAngle())); - + Settings speedSettings = machineConfig.getCategory(LanguageResource.getString("SPEEDCATEGORY_STR")); - speedSettings.setObject(MachineConfig.CUTTING_SPEED, new Double(brd.getRegularSpeed())); - speedSettings.setObject(MachineConfig.CUTTING_SPEED_STRINGER, new Double(brd.getStringerSpeed())); - speedSettings.setObject(MachineConfig.CUTTING_SPEED_RAIL, new Double(brd.getRegularSpeed())); - speedSettings.setObject(MachineConfig.CUTTING_SPEED_OUTLINE, new Double(brd.getRegularSpeed())); - + speedSettings.setObject(MachineConfig.CUTTING_SPEED, new Double(brd.getRegularSpeed())); + speedSettings.setObject(MachineConfig.CUTTING_SPEED_STRINGER, new Double(brd.getStringerSpeed())); + speedSettings.setObject(MachineConfig.CUTTING_SPEED_RAIL, new Double(brd.getRegularSpeed())); + speedSettings.setObject(MachineConfig.CUTTING_SPEED_OUTLINE, new Double(brd.getRegularSpeed())); + } - - + dialog.setVisible(true); - - if(generalSettings.getBoolean(MachineConfig.USE_BRD_SETTINGS)) - { - if(generalSettings.getEnumeration(MachineConfig.BLANKHOLDINGSYSTEM_TYPE) == 0) - { - //generalSettings.getDouble(MachineConfig.TAILSTOP_POS, ); + + if (generalSettings.getBoolean(MachineConfig.USE_BRD_SETTINGS)) { + if (generalSettings.getEnumeration(MachineConfig.BLANKHOLDINGSYSTEM_TYPE) == 0) { + // generalSettings.getDouble(MachineConfig.TAILSTOP_POS, + // ); Settings supportsSettings = machineConfig.addCategory(LanguageResource.getString("BLANKHOLDINGSYSTEMCATEGORY_STR")); - //generalSettings.getDouble(MachineConfig.TAILSTOP_POS, ); + // generalSettings.getDouble(MachineConfig.TAILSTOP_POS, + // ); brd.getStrut1()[0] = supportsSettings.getDouble(SupportsBlankHoldingSystem.SUPPORT_1_POS); brd.getStrut2()[0] = supportsSettings.getDouble(SupportsBlankHoldingSystem.SUPPORT_2_POS); - + brd.getStrut1()[1] = supportsSettings.getDouble(SupportsBlankHoldingSystem.SUPPORT_1_HEIGHT); brd.getStrut2()[1] = supportsSettings.getDouble(SupportsBlankHoldingSystem.SUPPORT_2_HEIGHT); } - + brd.setBlankFile(generalSettings.getFileName(MachineConfig.BLANK)); Settings cutsSettings = machineConfig.getCategory(LanguageResource.getString("CUTSCATEGORY_STR")); @@ -3179,20 +3089,24 @@ public void actionPerformed(ActionEvent arg0) { brd.setTopShoulderCuts(cutsSettings.getInt(MachineConfig.DECK_RAIL_CUTS)); brd.setBottomCuts(cutsSettings.getInt(MachineConfig.BOTTOM_CUTS)); brd.setBottomRailCuts(cutsSettings.getInt(MachineConfig.BOTTOM_RAIL_CUTS)); - + brd.setTopShoulderAngle(cutsSettings.getDouble(MachineConfig.DECK_ANGLE)); brd.setMaxAngle(cutsSettings.getDouble(MachineConfig.DECK_RAIL_ANGLE)); -// cutsSettings.getDouble(MachineConfig.BOTTOM_ANGLE, new Double(90)); -// cutsSettings.getDouble(MachineConfig.BOTTOM_RAIL_ANGLE, new Double(90)); - + // cutsSettings.getDouble(MachineConfig.BOTTOM_ANGLE, new + // Double(90)); + // cutsSettings.getDouble(MachineConfig.BOTTOM_RAIL_ANGLE, + // new Double(90)); + Settings speedSettings = machineConfig.getCategory(LanguageResource.getString("SPEEDCATEGORY_STR")); - brd.setRegularSpeed((int)speedSettings.getDouble(MachineConfig.CUTTING_SPEED)); - brd.setStringerSpeed((int)speedSettings.getDouble(MachineConfig.CUTTING_SPEED_STRINGER)); - brd.setRegularSpeed((int)speedSettings.getDouble(MachineConfig.CUTTING_SPEED_RAIL)); -// speedSettings.getDouble(MachineConfig.CUTTING_SPEED_NOSE_REDUCTION, new Double(0.5)); -// speedSettings.getDouble(MachineConfig.CUTTING_SPEED_TAIL_REDUCTION, new Double(0.5)); -// brd.setNoseLength(speedSettings.getDouble(MachineConfig.CUTTING_SPEED_NOSE_REDUCTION_DIST)); -// brd.setTailLength(speedSettings.getDouble(MachineConfig.CUTTING_SPEED_TAIL_REDUCTION_DIST)); + brd.setRegularSpeed((int) speedSettings.getDouble(MachineConfig.CUTTING_SPEED)); + brd.setStringerSpeed((int) speedSettings.getDouble(MachineConfig.CUTTING_SPEED_STRINGER)); + brd.setRegularSpeed((int) speedSettings.getDouble(MachineConfig.CUTTING_SPEED_RAIL)); + // speedSettings.getDouble(MachineConfig.CUTTING_SPEED_NOSE_REDUCTION, + // new Double(0.5)); + // speedSettings.getDouble(MachineConfig.CUTTING_SPEED_TAIL_REDUCTION, + // new Double(0.5)); + // brd.setNoseLength(speedSettings.getDouble(MachineConfig.CUTTING_SPEED_NOSE_REDUCTION_DIST)); + // brd.setTailLength(speedSettings.getDouble(MachineConfig.CUTTING_SPEED_TAIL_REDUCTION_DIST)); } } }; @@ -3202,11 +3116,12 @@ public void actionPerformed(ActionEvent arg0) { gcodeMenu.addSeparator(); final AbstractAction gcodeOutline = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("GCODEOUTLINE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); @@ -3226,8 +3141,7 @@ public void actionPerformed(ActionEvent arg0) { fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -3242,22 +3156,18 @@ public void actionPerformed(ActionEvent arg0) { BoardCAD.defaultDirectory = file.getPath(); - HotwireToolpathGenerator2 toolpathGenerator = new HotwireToolpathGenerator2( - new AbstractCutter() { - public double[] calcOffset(Point3d point, Vector3d normal, - AbstractBoard board) { - return new double[] { point.x, point.y, point.z }; - } + HotwireToolpathGenerator2 toolpathGenerator = new HotwireToolpathGenerator2(new AbstractCutter() { + public double[] calcOffset(Point3d point, Vector3d normal, AbstractBoard board) { + return new double[] { point.x, point.y, point.z }; + } - }, new GCodeWriter(), hotwireSettings.getMeasurement("CuttingSpeed")*UnitUtils.MILLIMETER_PR_CENTIMETER); + }, new GCodeWriter(), hotwireSettings.getMeasurement("CuttingSpeed") * UnitUtils.MILLIMETER_PR_CENTIMETER); try { toolpathGenerator.writeOutline(filename, getCurrentBrd()); } catch (Exception e) { String str = LanguageResource.getString("GCODEOUTLINEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("GCODEOUTLINEFAILEDTITLE_STR") , - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("GCODEOUTLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -3266,11 +3176,12 @@ public double[] calcOffset(Point3d point, Vector3d normal, gcodeMenu.add(gcodeOutline); final AbstractAction gcodeProfile = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("GCODEPROFILE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { CategorizedSettings settings = new CategorizedSettings(); String categoryName = LanguageResource.getString("HOTWIRECATEGORY_STR"); @@ -3290,8 +3201,7 @@ public void actionPerformed(ActionEvent arg0) { fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -3305,31 +3215,28 @@ public void actionPerformed(ActionEvent arg0) { filename = FileTools.setExtension(filename, "nc"); BoardCAD.defaultDirectory = file.getPath(); - - HotwireToolpathGenerator2 toolpathGenerator = new HotwireToolpathGenerator2( - new AbstractCutter() { - public double[] calcOffset(Point3d point, Vector3d normal, - AbstractBoard board) { - -// double additionalThickness = hotwireSettings.getMeasurement("AdditionalThickness")*UnitUtils.MILLIMETER_PR_CENTIMETER; - - Point3d offsetPoint = new Point3d(point); -// Vector3d normalScaled = new Vector3d(normal); -// normalScaled.scale(additionalThickness); -// offsetPoint.add(normalScaled); - - return new double[] { offsetPoint.x, offsetPoint.y, offsetPoint.z }; - } - }, new GCodeWriter(), hotwireSettings.getMeasurement("CuttingSpeed")*UnitUtils.MILLIMETER_PR_CENTIMETER, hotwireSettings.getMeasurement("AdditionalThickness")*UnitUtils.MILLIMETER_PR_CENTIMETER); + HotwireToolpathGenerator2 toolpathGenerator = new HotwireToolpathGenerator2(new AbstractCutter() { + public double[] calcOffset(Point3d point, Vector3d normal, AbstractBoard board) { + + // double additionalThickness = + // hotwireSettings.getMeasurement("AdditionalThickness")*UnitUtils.MILLIMETER_PR_CENTIMETER; + + Point3d offsetPoint = new Point3d(point); + // Vector3d normalScaled = new Vector3d(normal); + // normalScaled.scale(additionalThickness); + // offsetPoint.add(normalScaled); + + return new double[] { offsetPoint.x, offsetPoint.y, offsetPoint.z }; + } + + }, new GCodeWriter(), hotwireSettings.getMeasurement("CuttingSpeed") * UnitUtils.MILLIMETER_PR_CENTIMETER, hotwireSettings.getMeasurement("AdditionalThickness") * UnitUtils.MILLIMETER_PR_CENTIMETER); try { toolpathGenerator.writeProfile(filename, getCurrentBrd()); } catch (Exception e) { String str = LanguageResource.getString("GCODEPROFILEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("GCODEPROFILEFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("GCODEPROFILEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -3338,11 +3245,12 @@ public double[] calcOffset(Point3d point, Vector3d normal, gcodeMenu.add(gcodeProfile); final AbstractAction gcodeDeck = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("GCODEDECK_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); @@ -3363,28 +3271,23 @@ public void actionPerformed(ActionEvent arg0) { MachineConfig config = new MachineConfig(); config.getPreferences(); - - AbstractToolpathGenerator toolpathGenerator = new WidthSplitsToolpathGenerator( - new AbstractCutter() { - public double[] calcOffset(Point3d point, Vector3d normal, - AbstractBoard board) { - return new double[] { point.x, point.y, point.z }; - } - public double calcSpeed(Point3d point, Vector3d normal, - AbstractBoard board, boolean isCuttingStringer) { - return 10; - } - - }, null, new GCodeWriter(), config); + AbstractToolpathGenerator toolpathGenerator = new WidthSplitsToolpathGenerator(new AbstractCutter() { + public double[] calcOffset(Point3d point, Vector3d normal, AbstractBoard board) { + return new double[] { point.x, point.y, point.z }; + } + + public double calcSpeed(Point3d point, Vector3d normal, AbstractBoard board, boolean isCuttingStringer) { + return 10; + } + + }, null, new GCodeWriter(), config); try { toolpathGenerator.writeToolpath(filename, getCurrentBrd(), null); } catch (Exception e) { String str = LanguageResource.getString("GCODEDECKFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("GCODEDECKFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("GCODEDECKFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -3393,18 +3296,18 @@ public double calcSpeed(Point3d point, Vector3d normal, gcodeMenu.add(gcodeDeck); final AbstractAction gcodeBottom = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("GCODEBOTTOM_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -3416,31 +3319,26 @@ public void actionPerformed(ActionEvent arg0) { return; BoardCAD.defaultDirectory = file.getPath(); - + MachineConfig config = new MachineConfig(); config.getPreferences(); - AbstractToolpathGenerator toolpathGenerator = new WidthSplitsToolpathGenerator( - new AbstractCutter() { - public double[] calcOffset(Point3d point, Vector3d normal, - AbstractBoard board) { - return new double[] { point.x, point.y, point.z }; - } + AbstractToolpathGenerator toolpathGenerator = new WidthSplitsToolpathGenerator(new AbstractCutter() { + public double[] calcOffset(Point3d point, Vector3d normal, AbstractBoard board) { + return new double[] { point.x, point.y, point.z }; + } - public double calcSpeed(Point3d point, Vector3d normal, - AbstractBoard board, boolean isCuttingStringer) { - return 10; - } + public double calcSpeed(Point3d point, Vector3d normal, AbstractBoard board, boolean isCuttingStringer) { + return 10; + } - }, null, new GCodeWriter(), config); + }, null, new GCodeWriter(), config); try { toolpathGenerator.writeToolpath(filename, getCurrentBrd(), null); } catch (Exception e) { String str = LanguageResource.getString("GCODEBOTTOMFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("GCODEBOTTOMFAILEDMSG_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("GCODEBOTTOMFAILEDMSG_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -3448,18 +3346,692 @@ public double calcSpeed(Point3d point, Vector3d normal, }; gcodeMenu.add(gcodeBottom); + final JMenu gcodeHWSMenu = new JMenu(LanguageResource.getString("GCODEHWSMENU_STR")); + + final AbstractAction gcodeHWSSTringer = new AbstractAction() { + static final long serialVersionUID = 1L; + { + this.putValue(Action.NAME, LanguageResource.getString("GCODEHWSSTRINGER_STR")); + }; + + @Override + public void actionPerformed(ActionEvent arg0) { + + CategorizedSettings settings = new CategorizedSettings(); + String categoryName = LanguageResource.getString("HWSPARAMETERSCATEGORY_STR"); + Settings HWSSettings = settings.addCategory(categoryName); + HWSSettings.addMeasurement("SkinThickness", 0.4, LanguageResource.getString("HWSSKINTHICKNESS_STR")); + HWSSettings.addMeasurement("FrameThickness", 0.5, LanguageResource.getString("HWSFRAMETHICKNESS_STR")); + HWSSettings.addMeasurement("Webbing", 1.5, LanguageResource.getString("HWSWEBBING_STR")); + HWSSettings.addMeasurement("NoseOffset", 3.5, LanguageResource.getString("HWSNOSEOFFSET_STR")); + HWSSettings.addMeasurement("TailOffset", 3.5, LanguageResource.getString("HWSTAILOFFSET_STR")); + HWSSettings.addMeasurement("DistanceFromRail", 3.0, LanguageResource.getString("HWSDISTANCEFROMRAIL_STR")); + HWSSettings.addMeasurement("CutterDiam", 5.0, LanguageResource.getString("CUTTERDIAMETER_STR")); + HWSSettings.addMeasurement("JogHeight", 5.0, LanguageResource.getString("JOGHEIGHT_STR")); + HWSSettings.addMeasurement("JogSpeed", 20.0, LanguageResource.getString("JOGSPEED_STR")); + HWSSettings.addMeasurement("SinkSpeed", 2.0, LanguageResource.getString("SINKSPEED_STR")); + HWSSettings.addMeasurement("CutDepth", 0.0, LanguageResource.getString("CUTDEPTH_STR")); + HWSSettings.addMeasurement("CutSpeed", 2.0, LanguageResource.getString("CUTSPEED_STR")); + settings.getPreferences(); + String filename = FileTools.removeExtension(getCurrentBrd().getFilename()); + filename.concat("HWSStringer.nc"); + HWSSettings.addFileName("StringerFilename", filename, LanguageResource.getString("FILENAME_STR")); + + SettingDialog settingsDialog = new SettingDialog(settings); + settingsDialog.setTitle(LanguageResource.getString("HWSSTRINGERTITLE_STR")); + settingsDialog.setModal(true); + settingsDialog.setVisible(true); + if (settingsDialog.wasCancelled()) { + settingsDialog.dispose(); + return; + } + settings.putPreferences(); + + GCodeDraw gdraw = new GCodeDraw(HWSSettings.getFileName("StringerFilename"), HWSSettings.getMeasurement("CutterDiam"), HWSSettings.getMeasurement("CutDepth"), HWSSettings.getMeasurement("CutSpeed"), HWSSettings.getMeasurement("JogHeight"), HWSSettings.getMeasurement("JogSpeed"), + HWSSettings.getMeasurement("SinkSpeed")); + + double skinThickness = HWSSettings.getMeasurement("SkinThickness"); + double frameThickness = HWSSettings.getMeasurement("FrameThickness"); + double webbing = HWSSettings.getMeasurement("Webbing"); + double tailOffset = HWSSettings.getMeasurement("TailOffset"); + double noseOffset = HWSSettings.getMeasurement("NoseOffset"); + double distanceToRail = HWSSettings.getMeasurement("DistanceFromRail"); + + gdraw.setFlipNormal(true); + + BezierBoardDrawUtil.printProfile(gdraw, 0.0, 0.0, 1.0, 0.0, false, BoardCAD.getInstance().getCurrentBrd(), 0.0, skinThickness, false, tailOffset, noseOffset); + + gdraw.setFlipNormal(false); + + PrintHollowWoodTemplates.printStringerWebbing(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), skinThickness, frameThickness, webbing); + + PrintHollowWoodTemplates.printStringerTailPieceCutOut(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset); + + PrintHollowWoodTemplates.printStringerNosePieceCutOut(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset); + + settingsDialog.dispose(); + gdraw.close(); + } + + }; + gcodeHWSMenu.add(gcodeHWSSTringer); + + final AbstractAction gcodeHWSRibs = new AbstractAction() { + static final long serialVersionUID = 1L; + { + this.putValue(Action.NAME, LanguageResource.getString("GCODEHWSRIBS_STR")); + }; + + @Override + public void actionPerformed(ActionEvent arg0) { + + CategorizedSettings settings = new CategorizedSettings(); + String categoryName = LanguageResource.getString("HWSPARAMETERSCATEGORY_STR"); + Settings HWSSettings = settings.addCategory(categoryName); + LanguageResource.getString("HWSSKINTHICKNESS_STR"); + HWSSettings.addMeasurement("FrameThickness", 0.5, LanguageResource.getString("HWSFRAMETHICKNESS_STR")); + HWSSettings.addMeasurement("Webbing", 1.5, LanguageResource.getString("HWSWEBBING_STR")); + HWSSettings.addMeasurement("NoseOffset", 3.5, LanguageResource.getString("HWSNOSEOFFSET_STR")); + HWSSettings.addMeasurement("TailOffset", 3.5, LanguageResource.getString("HWSTAILOFFSET_STR")); + HWSSettings.addMeasurement("DistanceFromRail", 3.0, LanguageResource.getString("HWSDISTANCEFROMRAIL_STR")); + HWSSettings.addMeasurement("CutterDiam", 5.0, LanguageResource.getString("CUTTERDIAMETER_STR")); + HWSSettings.addMeasurement("JogHeight", 5.0, LanguageResource.getString("JOGHEIGHT_STR")); + HWSSettings.addMeasurement("JogSpeed", 20.0, LanguageResource.getString("JOGSPEED_STR")); + HWSSettings.addMeasurement("SinkSpeed", 2.0, LanguageResource.getString("SINKSPEED_STR")); + HWSSettings.addMeasurement("CutDepth", 0.0, LanguageResource.getString("CUTDEPTH_STR")); + HWSSettings.addMeasurement("CutSpeed", 2.0, LanguageResource.getString("CUTSPEED_STR")); + settings.getPreferences(); + String filename = FileTools.removeExtension(getCurrentBrd().getFilename()); + filename.concat("HWSRibs.nc"); + HWSSettings.addFileName("Filename", filename, LanguageResource.getString("FILENAME_STR")); + + SettingDialog settingsDialog = new SettingDialog(settings); + settingsDialog.setTitle(LanguageResource.getString("GCODEHWSRAILSTITLE_STR")); + settingsDialog.setModal(true); + settingsDialog.setVisible(true); + if (settingsDialog.wasCancelled()) { + settingsDialog.dispose(); + return; + } + settings.putPreferences(); + + GCodeDraw gdraw = new GCodeDraw(HWSSettings.getFileName("Filename"), HWSSettings.getMeasurement("CutterDiam"), HWSSettings.getMeasurement("CutDepth"), HWSSettings.getMeasurement("CutSpeed"), HWSSettings.getMeasurement("JogHeight"), HWSSettings.getMeasurement("JogSpeed"), + HWSSettings.getMeasurement("SinkSpeed")); + + double skinThickness = HWSSettings.getMeasurement("SkinThickness"); + double frameThickness = HWSSettings.getMeasurement("FrameThickness"); + double webbing = HWSSettings.getMeasurement("Webbing"); + double tailOffset = HWSSettings.getMeasurement("TailOffset"); + double noseOffset = HWSSettings.getMeasurement("NoseOffset"); + double distanceToRail = HWSSettings.getMeasurement("DistanceFromRail"); + double cutterDiam = HWSSettings.getMeasurement("CutterDiam"); + + // + int nrOfCrossSections = (int) ((BoardCAD.getInstance().getCurrentBrd().getLength() - 9.0 * UnitUtils.INCH) / UnitUtils.FOOT); + double crosssectionPos = 0.0; + double verticalPos = 0.0; + for (int i = 0; i < nrOfCrossSections; i++) { + crosssectionPos = (i + 1) * UnitUtils.FOOT; + + PrintHollowWoodTemplates.printCrossSection(gdraw, 0.0, verticalPos, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), crosssectionPos, distanceToRail, skinThickness, frameThickness, webbing, false); + + PrintHollowWoodTemplates.printCrossSectionWebbing(gdraw, verticalPos, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), crosssectionPos, distanceToRail, skinThickness, frameThickness, webbing, false); + + double verticalStep = BoardCAD.getInstance().getCurrentBrd().getThicknessAtPos(crosssectionPos) - skinThickness + (cutterDiam * 2.0); + + verticalPos += verticalStep; + } + + settingsDialog.dispose(); + } + + }; + gcodeHWSMenu.add(gcodeHWSRibs); + + final AbstractAction gcodeHWSRail = new AbstractAction() { + static final long serialVersionUID = 1L; + { + this.putValue(Action.NAME, LanguageResource.getString("GCODEHWSRAIL_STR")); + }; + + @Override + public void actionPerformed(ActionEvent arg0) { + + CategorizedSettings settings = new CategorizedSettings(); + String categoryName = LanguageResource.getString("HWSPARAMETERSCATEGORY_STR"); + Settings HWSSettings = settings.addCategory(categoryName); + LanguageResource.getString("HWSSKINTHICKNESS_STR"); + HWSSettings.addMeasurement("FrameThickness", 0.5, LanguageResource.getString("HWSFRAMETHICKNESS_STR")); + HWSSettings.addMeasurement("Webbing", 1.5, LanguageResource.getString("HWSWEBBING_STR")); + HWSSettings.addMeasurement("NoseOffset", 3.5, LanguageResource.getString("HWSNOSEOFFSET_STR")); + HWSSettings.addMeasurement("TailOffset", 3.5, LanguageResource.getString("HWSTAILOFFSET_STR")); + HWSSettings.addMeasurement("DistanceFromRail", 3.0, LanguageResource.getString("HWSDISTANCEFROMRAIL_STR")); + HWSSettings.addMeasurement("CutterDiam", 5.0, LanguageResource.getString("CUTTERDIAMETER_STR")); + HWSSettings.addMeasurement("JogHeight", 5.0, LanguageResource.getString("JOGHEIGHT_STR")); + HWSSettings.addMeasurement("JogSpeed", 20.0, LanguageResource.getString("JOGSPEED_STR")); + HWSSettings.addMeasurement("SinkSpeed", 2.0, LanguageResource.getString("SINKSPEED_STR")); + HWSSettings.addMeasurement("CutDepth", 0.0, LanguageResource.getString("CUTDEPTH_STR")); + HWSSettings.addMeasurement("CutSpeed", 2.0, LanguageResource.getString("CUTSPEED_STR")); + settings.getPreferences(); + String filename = FileTools.removeExtension(getCurrentBrd().getFilename()); + filename.concat("HWSRibs.nc"); + HWSSettings.addFileName("StringerFilename", filename, LanguageResource.getString("FILENAME_STR")); + + SettingDialog settingsDialog = new SettingDialog(settings); + settingsDialog.setTitle(LanguageResource.getString("GCODEHWSRAILSTITLE_STR")); + settingsDialog.setModal(true); + settingsDialog.setVisible(true); + if (settingsDialog.wasCancelled()) { + settingsDialog.dispose(); + return; + } + settings.putPreferences(); + + GCodeDraw gdraw = new GCodeDraw(HWSSettings.getFileName("StringerFilename"), HWSSettings.getMeasurement("CutterDiam"), HWSSettings.getMeasurement("CutDepth"), HWSSettings.getMeasurement("CutSpeed"), HWSSettings.getMeasurement("JogHeight"), HWSSettings.getMeasurement("JogSpeed"), + HWSSettings.getMeasurement("SinkSpeed")); + + double skinThickness = HWSSettings.getMeasurement("SkinThickness"); + double frameThickness = HWSSettings.getMeasurement("FrameThickness"); + double webbing = HWSSettings.getMeasurement("Webbing"); + double tailOffset = HWSSettings.getMeasurement("TailOffset"); + double noseOffset = HWSSettings.getMeasurement("NoseOffset"); + double distanceToRail = HWSSettings.getMeasurement("DistanceFromRail"); + + PrintHollowWoodTemplates.printRailWebbing(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset); + + PrintHollowWoodTemplates.printRailNotching(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset); + + PrintHollowWoodTemplates.printRailNosePieceNotches(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset); + + PrintHollowWoodTemplates.printRailTailPieceNotches(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset); + + settingsDialog.dispose(); + } + + }; + gcodeHWSMenu.add(gcodeHWSRail); + + final AbstractAction gcodeHWSNosePiece = new AbstractAction() { + static final long serialVersionUID = 1L; + { + this.putValue(Action.NAME, LanguageResource.getString("GCODEHWSTAILPIECE_STR")); + }; + + @Override + public void actionPerformed(ActionEvent arg0) { + + CategorizedSettings settings = new CategorizedSettings(); + String categoryName = LanguageResource.getString("HWSPARAMETERSCATEGORY_STR"); + Settings HWSSettings = settings.addCategory(categoryName); + HWSSettings.addMeasurement("SkinThickness", 0.4, LanguageResource.getString("HWSSKINTHICKNESS_STR")); + HWSSettings.addMeasurement("FrameThickness", 0.5, LanguageResource.getString("HWSFRAMETHICKNESS_STR")); + HWSSettings.addMeasurement("Webbing", 1.5, LanguageResource.getString("HWSWEBBING_STR")); + HWSSettings.addMeasurement("NoseOffset", 3.5, LanguageResource.getString("HWSNOSEOFFSET_STR")); + HWSSettings.addMeasurement("TailOffset", 3.5, LanguageResource.getString("HWSTAILOFFSET_STR")); + HWSSettings.addMeasurement("DistanceFromRail", 3.0, LanguageResource.getString("HWSDISTANCEFROMRAIL_STR")); + HWSSettings.addMeasurement("CutterDiam", 5.0, LanguageResource.getString("CUTTERDIAMETER_STR")); + HWSSettings.addMeasurement("JogHeight", 5.0, LanguageResource.getString("JOGHEIGHT_STR")); + HWSSettings.addMeasurement("JogSpeed", 20.0, LanguageResource.getString("JOGSPEED_STR")); + HWSSettings.addMeasurement("SinkSpeed", 2.0, LanguageResource.getString("SINKSPEED_STR")); + HWSSettings.addMeasurement("CutDepth", 0.0, LanguageResource.getString("CUTDEPTH_STR")); + HWSSettings.addMeasurement("CutSpeed", 2.0, LanguageResource.getString("CUTSPEED_STR")); + settings.getPreferences(); + String filename = FileTools.removeExtension(getCurrentBrd().getFilename()); + filename.concat("HWSTail.nc"); + HWSSettings.addFileName("StringerFilename", filename, LanguageResource.getString("FILENAME_STR")); + + SettingDialog settingsDialog = new SettingDialog(settings); + settingsDialog.setTitle(LanguageResource.getString("GCODEHWSTAILPIECETITLE_STR")); + settingsDialog.setModal(true); + settingsDialog.setVisible(true); + if (settingsDialog.wasCancelled()) { + settingsDialog.dispose(); + return; + } + settings.putPreferences(); + + GCodeDraw gdraw = new GCodeDraw(HWSSettings.getFileName("StringerFilename"), HWSSettings.getMeasurement("CutterDiam"), HWSSettings.getMeasurement("CutDepth"), HWSSettings.getMeasurement("CutSpeed"), HWSSettings.getMeasurement("JogHeight"), HWSSettings.getMeasurement("JogSpeed"), + HWSSettings.getMeasurement("SinkSpeed")); + + double skinThickness = HWSSettings.getMeasurement("SkinThickness"); + double frameThickness = HWSSettings.getMeasurement("FrameThickness"); + double webbing = HWSSettings.getMeasurement("Webbing"); + double tailOffset = HWSSettings.getMeasurement("TailOffset"); + double noseOffset = HWSSettings.getMeasurement("NoseOffset"); + double distanceToRail = HWSSettings.getMeasurement("DistanceFromRail"); + + PrintHollowWoodTemplates.printNosePiece(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset, false); + + PrintHollowWoodTemplates.printNosePiece(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset, true); + + PrintHollowWoodTemplates.printNosePieceWebbing(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset, false); + + PrintHollowWoodTemplates.printNosePieceWebbing(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset, true); + + settingsDialog.dispose(); + } + + }; + gcodeHWSMenu.add(gcodeHWSNosePiece); + + final AbstractAction gcodeHWSTailPiece = new AbstractAction() { + static final long serialVersionUID = 1L; + { + this.putValue(Action.NAME, LanguageResource.getString("GCODEHWSNOSEPIECE_STR")); + }; + + @Override + public void actionPerformed(ActionEvent arg0) { + + CategorizedSettings settings = new CategorizedSettings(); + String categoryName = LanguageResource.getString("HWSPARAMETERSCATEGORY_STR"); + Settings HWSSettings = settings.addCategory(categoryName); + HWSSettings.addMeasurement("SkinThickness", 0.4, LanguageResource.getString("HWSSKINTHICKNESS_STR")); + HWSSettings.addMeasurement("FrameThickness", 0.5, LanguageResource.getString("HWSFRAMETHICKNESS_STR")); + HWSSettings.addMeasurement("Webbing", 1.5, LanguageResource.getString("HWSWEBBING_STR")); + HWSSettings.addMeasurement("NoseOffset", 3.5, LanguageResource.getString("HWSNOSEOFFSET_STR")); + HWSSettings.addMeasurement("TailOffset", 3.5, LanguageResource.getString("HWSTAILOFFSET_STR")); + HWSSettings.addMeasurement("DistanceFromRail", 3.0, LanguageResource.getString("HWSDISTANCEFROMRAIL_STR")); + HWSSettings.addMeasurement("CutterDiam", 5.0, LanguageResource.getString("CUTTERDIAMETER_STR")); + HWSSettings.addMeasurement("JogHeight", 5.0, LanguageResource.getString("JOGHEIGHT_STR")); + HWSSettings.addMeasurement("JogSpeed", 20.0, LanguageResource.getString("JOGSPEED_STR")); + HWSSettings.addMeasurement("SinkSpeed", 2.0, LanguageResource.getString("SINKSPEED_STR")); + HWSSettings.addMeasurement("CutDepth", 0.0, LanguageResource.getString("CUTDEPTH_STR")); + HWSSettings.addMeasurement("CutSpeed", 2.0, LanguageResource.getString("CUTSPEED_STR")); + settings.getPreferences(); + String filename = FileTools.removeExtension(getCurrentBrd().getFilename()); + filename.concat("HWSNose.nc"); + HWSSettings.addFileName("StringerFilename", filename, LanguageResource.getString("FILENAME_STR")); + + SettingDialog settingsDialog = new SettingDialog(settings); + settingsDialog.setTitle(LanguageResource.getString("GCODEHWSNOSEPIECETITLE_STR")); + settingsDialog.setModal(true); + settingsDialog.setVisible(true); + if (settingsDialog.wasCancelled()) { + settingsDialog.dispose(); + return; + } + settings.putPreferences(); + + GCodeDraw gdraw = new GCodeDraw(HWSSettings.getFileName("StringerFilename"), HWSSettings.getMeasurement("CutterDiam"), HWSSettings.getMeasurement("CutDepth"), HWSSettings.getMeasurement("CutSpeed"), HWSSettings.getMeasurement("JogHeight"), HWSSettings.getMeasurement("JogSpeed"), + HWSSettings.getMeasurement("SinkSpeed")); + + double skinThickness = HWSSettings.getMeasurement("SkinThickness"); + double frameThickness = HWSSettings.getMeasurement("FrameThickness"); + double webbing = HWSSettings.getMeasurement("Webbing"); + double tailOffset = HWSSettings.getMeasurement("TailOffset"); + double noseOffset = HWSSettings.getMeasurement("NoseOffset"); + double distanceToRail = HWSSettings.getMeasurement("DistanceFromRail"); + + PrintHollowWoodTemplates.printTailPiece(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset, false); + + PrintHollowWoodTemplates.printTailPiece(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset, true); + + PrintHollowWoodTemplates.printTailPieceWebbing(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset, false); + + PrintHollowWoodTemplates.printTailPieceWebbing(gdraw, 0.0, 0.0, 1.0, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset, true); + + settingsDialog.dispose(); + } + + }; + gcodeHWSMenu.add(gcodeHWSTailPiece); + + final AbstractAction gcodeHWSDeckTemplate = new AbstractAction() { + static final long serialVersionUID = 1L; + { + this.putValue(Action.NAME, LanguageResource.getString("GCODEHWSDECKTEMPLATE_STR")); + }; + + @Override + public void actionPerformed(ActionEvent arg0) { + + CategorizedSettings settings = new CategorizedSettings(); + String categoryName = LanguageResource.getString("HWSPARAMETERSCATEGORY_STR"); + Settings HWSSettings = settings.addCategory(categoryName); + HWSSettings.addMeasurement("SkinThickness", 0.4, LanguageResource.getString("HWSSKINTHICKNESS_STR")); + HWSSettings.addMeasurement("FrameThickness", 0.5, LanguageResource.getString("HWSFRAMETHICKNESS_STR")); + HWSSettings.addMeasurement("Webbing", 1.5, LanguageResource.getString("HWSWEBBING_STR")); + HWSSettings.addMeasurement("NoseOffset", 3.5, LanguageResource.getString("HWSNOSEOFFSET_STR")); + HWSSettings.addMeasurement("TailOffset", 3.5, LanguageResource.getString("HWSTAILOFFSET_STR")); + HWSSettings.addMeasurement("DistanceFromRail", 3.0, LanguageResource.getString("HWSDISTANCEFROMRAIL_STR")); + HWSSettings.addMeasurement("CutterDiam", 5.0, LanguageResource.getString("CUTTERDIAMETER_STR")); + HWSSettings.addMeasurement("JogHeight", 5.0, LanguageResource.getString("JOGHEIGHT_STR")); + HWSSettings.addMeasurement("JogSpeed", 20.0, LanguageResource.getString("JOGSPEED_STR")); + HWSSettings.addMeasurement("SinkSpeed", 2.0, LanguageResource.getString("SINKSPEED_STR")); + HWSSettings.addMeasurement("CutDepth", 0.0, LanguageResource.getString("CUTDEPTH_STR")); + HWSSettings.addMeasurement("CutSpeed", 2.0, LanguageResource.getString("CUTSPEED_STR")); + settings.getPreferences(); + String filename = FileTools.removeExtension(getCurrentBrd().getFilename()); + filename.concat("HWSRibs.nc"); + HWSSettings.addFileName("StringerFilename", filename, LanguageResource.getString("FILENAME_STR")); + + SettingDialog settingsDialog = new SettingDialog(settings); + settingsDialog.setTitle(LanguageResource.getString("HWSSTRINGERTITLE_STR")); + settingsDialog.setModal(true); + settingsDialog.setVisible(true); + if (settingsDialog.wasCancelled()) { + settingsDialog.dispose(); + return; + } + settings.putPreferences(); + + GCodeDraw gdraw = new GCodeDraw(HWSSettings.getFileName("StringerFilename"), HWSSettings.getMeasurement("CutterDiam"), HWSSettings.getMeasurement("CutDepth"), HWSSettings.getMeasurement("CutSpeed"), HWSSettings.getMeasurement("JogHeight"), HWSSettings.getMeasurement("JogSpeed"), + HWSSettings.getMeasurement("SinkSpeed")); + + double skinThickness = HWSSettings.getMeasurement("SkinThickness"); + double frameThickness = HWSSettings.getMeasurement("FrameThickness"); + double webbing = HWSSettings.getMeasurement("Webbing"); + double tailOffset = HWSSettings.getMeasurement("TailOffset"); + double noseOffset = HWSSettings.getMeasurement("NoseOffset"); + double distanceToRail = HWSSettings.getMeasurement("DistanceFromRail"); + + BezierBoardDrawUtil.printDeckSkinTemplate(gdraw, 0.0, 0.0, 1.0, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), distanceToRail); + + settingsDialog.dispose(); + } + + }; + gcodeHWSMenu.add(gcodeHWSDeckTemplate); + + final AbstractAction gcodeHWSBottomTemplate = new AbstractAction() { + static final long serialVersionUID = 1L; + { + this.putValue(Action.NAME, LanguageResource.getString("GCODEHWSBOTTOMTEMPLATE_STR")); + }; + + @Override + public void actionPerformed(ActionEvent arg0) { + + CategorizedSettings settings = new CategorizedSettings(); + String categoryName = LanguageResource.getString("HWSPARAMETERSCATEGORY_STR"); + Settings HWSSettings = settings.addCategory(categoryName); + HWSSettings.addMeasurement("SkinThickness", 0.4, LanguageResource.getString("HWSSKINTHICKNESS_STR")); + HWSSettings.addMeasurement("FrameThickness", 0.5, LanguageResource.getString("HWSFRAMETHICKNESS_STR")); + HWSSettings.addMeasurement("Webbing", 1.5, LanguageResource.getString("HWSWEBBING_STR")); + HWSSettings.addMeasurement("NoseOffset", 3.5, LanguageResource.getString("HWSNOSEOFFSET_STR")); + HWSSettings.addMeasurement("TailOffset", 3.5, LanguageResource.getString("HWSTAILOFFSET_STR")); + HWSSettings.addMeasurement("DistanceFromRail", 3.0, LanguageResource.getString("HWSDISTANCEFROMRAIL_STR")); + HWSSettings.addMeasurement("CutterDiam", 5.0, LanguageResource.getString("CUTTERDIAMETER_STR")); + HWSSettings.addMeasurement("JogHeight", 5.0, LanguageResource.getString("JOGHEIGHT_STR")); + HWSSettings.addMeasurement("JogSpeed", 20.0, LanguageResource.getString("JOGSPEED_STR")); + HWSSettings.addMeasurement("SinkSpeed", 2.0, LanguageResource.getString("SINKSPEED_STR")); + HWSSettings.addMeasurement("CutDepth", 0.0, LanguageResource.getString("CUTDEPTH_STR")); + HWSSettings.addMeasurement("CutSpeed", 2.0, LanguageResource.getString("CUTSPEED_STR")); + settings.getPreferences(); + String filename = FileTools.removeExtension(getCurrentBrd().getFilename()); + filename.concat("HWSRibs.nc"); + HWSSettings.addFileName("StringerFilename", filename, LanguageResource.getString("FILENAME_STR")); + + SettingDialog settingsDialog = new SettingDialog(settings); + settingsDialog.setTitle(LanguageResource.getString("HWSSTRINGERTITLE_STR")); + settingsDialog.setModal(true); + settingsDialog.setVisible(true); + if (settingsDialog.wasCancelled()) { + settingsDialog.dispose(); + return; + } + settings.putPreferences(); + + GCodeDraw gdraw = new GCodeDraw(HWSSettings.getFileName("StringerFilename"), HWSSettings.getMeasurement("CutterDiam"), HWSSettings.getMeasurement("CutDepth"), HWSSettings.getMeasurement("CutSpeed"), HWSSettings.getMeasurement("JogHeight"), HWSSettings.getMeasurement("JogSpeed"), + HWSSettings.getMeasurement("SinkSpeed")); + + double skinThickness = HWSSettings.getMeasurement("SkinThickness"); + double frameThickness = HWSSettings.getMeasurement("FrameThickness"); + double webbing = HWSSettings.getMeasurement("Webbing"); + double tailOffset = HWSSettings.getMeasurement("TailOffset"); + double noseOffset = HWSSettings.getMeasurement("NoseOffset"); + double distanceToRail = HWSSettings.getMeasurement("DistanceFromRail"); + + BezierBoardDrawUtil.printDeckSkinTemplate(gdraw, 0.0, 0.0, 1.0, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), distanceToRail); + + settingsDialog.dispose(); + } + + }; + + gcodeHWSMenu.add(gcodeHWSBottomTemplate); + + final AbstractAction gcodeHWSAllInternalTemplates = new AbstractAction() { + static final long serialVersionUID = 1L; + { + this.putValue(Action.NAME, LanguageResource.getString("GCODEHWSALLINTERNALTEMPLATES_STR")); + }; + + @Override + public void actionPerformed(ActionEvent arg0) { + + CategorizedSettings settings = new CategorizedSettings(); + String categoryName = LanguageResource.getString("HWSPARAMETERSCATEGORY_STR"); + Settings HWSSettings = settings.addCategory(categoryName); + HWSSettings.addMeasurement("FrameThickness", 0.5, LanguageResource.getString("HWSFRAMETHICKNESS_STR")); + HWSSettings.addMeasurement("SkinThickness", 0.4, LanguageResource.getString("HWSSKINTHICKNESS_STR")); + HWSSettings.addMeasurement("FrameThickness", 0.5, LanguageResource.getString("HWSFRAMETHICKNESS_STR")); + HWSSettings.addMeasurement("Webbing", 1.5, LanguageResource.getString("HWSWEBBING_STR")); + HWSSettings.addMeasurement("NoseOffset", 3.5, LanguageResource.getString("HWSNOSEOFFSET_STR")); + HWSSettings.addMeasurement("TailOffset", 3.5, LanguageResource.getString("HWSTAILOFFSET_STR")); + HWSSettings.addMeasurement("DistanceFromRail", 3.0, LanguageResource.getString("HWSDISTANCEFROMRAIL_STR")); + HWSSettings.addMeasurement("CutterDiam", 5.0, LanguageResource.getString("CUTTERDIAMETER_STR")); + HWSSettings.addMeasurement("JogHeight", 5.0, LanguageResource.getString("JOGHEIGHT_STR")); + HWSSettings.addMeasurement("JogSpeed", 20.0, LanguageResource.getString("JOGSPEED_STR")); + HWSSettings.addMeasurement("SinkSpeed", 2.0, LanguageResource.getString("SINKSPEED_STR")); + HWSSettings.addMeasurement("CutDepth", 0.0, LanguageResource.getString("CUTDEPTH_STR")); + HWSSettings.addMeasurement("CutSpeed", 2.0, LanguageResource.getString("CUTSPEED_STR")); + settings.getPreferences(); + String filename = FileTools.removeExtension(getCurrentBrd().getFilename()); + filename = filename.concat(" HWSFrame.nc"); + HWSSettings.addFileName("Filename", filename, LanguageResource.getString("FILENAME_STR")); + HWSSettings.addMeasurement("OffsetX", 0.0, LanguageResource.getString("OFFSET_X_STR")); + HWSSettings.addMeasurement("OffsetY", 0.0, LanguageResource.getString("OFFSET_Y_STR")); + + SettingDialog settingsDialog = new SettingDialog(settings); + settingsDialog.setTitle(LanguageResource.getString("GCODEHWSALLINTERNALTEMPLATESTITLE_STR")); + settingsDialog.setModal(true); + settingsDialog.setVisible(true); + if (settingsDialog.wasCancelled()) { + settingsDialog.dispose(); + return; + } + settings.putPreferences(); + + GCodeDraw gdraw = new GCodeDraw(HWSSettings.getFileName("Filename"), HWSSettings.getMeasurement("CutterDiam"), HWSSettings.getMeasurement("CutDepth"), HWSSettings.getMeasurement("CutSpeed"), HWSSettings.getMeasurement("JogHeight"), HWSSettings.getMeasurement("JogSpeed"), + HWSSettings.getMeasurement("SinkSpeed")); + + gdraw.writeComment("HWS Frame"); + gdraw.writeComment(BoardCAD.getInstance().getCurrentBrd().getName() + " - " + BoardCAD.getInstance().getCurrentBrd().getAuthor()); + + double skinThickness = HWSSettings.getMeasurement("SkinThickness"); + double frameThickness = HWSSettings.getMeasurement("FrameThickness"); + double webbing = HWSSettings.getMeasurement("Webbing"); + double tailOffset = HWSSettings.getMeasurement("TailOffset"); + double noseOffset = HWSSettings.getMeasurement("NoseOffset"); + double distanceToRail = HWSSettings.getMeasurement("DistanceFromRail"); + double cutterDiam = HWSSettings.getMeasurement("CutterDiam"); + double offsetX = HWSSettings.getMeasurement("OffsetX"); + double offsetY = HWSSettings.getMeasurement("OffsetY"); + + // Cut Stringer + gdraw.writeComment("Stringer"); + gdraw.setFlipNormal(true); + + double x = offsetX; + double y = offsetY; + double scale = 1.0; + + /* + * PrintHollowWoodTemplates.printStringerWebbing(gdraw, x, y, + * scale, BoardCAD.getInstance().getCurrentBrd(), skinThickness, + * frameThickness, webbing); + * + * gdraw.setFlipNormal(false); + * + * + * BezierBoardDrawUtil.printProfile(gdraw, x, y, scale, false, + * BoardCAD.getInstance().getCurrentBrd(), 0.0, skinThickness, + * false, tailOffset, noseOffset); + * + * //Debug without offset gdraw.setCutterDiameter(0.0); + * BezierBoardDrawUtil.printProfile(gdraw, x, y, scale, false, + * BoardCAD.getInstance().getCurrentBrd(), 0.0, skinThickness, + * false, tailOffset, noseOffset); + * + * + * PrintHollowWoodTemplates.printStringerTailPieceCutOut(gdraw, + * x, y, scale, BoardCAD.getInstance().getCurrentBrd(), + * distanceToRail, skinThickness, frameThickness, webbing, + * tailOffset, noseOffset); + * + * PrintHollowWoodTemplates.printStringerNosePieceCutOut(gdraw, + * x, y, scale, BoardCAD.getInstance().getCurrentBrd(), + * distanceToRail, skinThickness, frameThickness, webbing, + * tailOffset, noseOffset); + * + * y+= + * BoardCAD.getInstance().getCurrentBrd().getThickness()*10.0; + * y+= cutterDiam*2.0; + */ + // Print rails twice + gdraw.writeComment("Rails"); + + BezierBoardDrawUtil.printRailTemplate(gdraw, x, y, scale, 0.0, false, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, tailOffset, noseOffset, false); + + PrintHollowWoodTemplates.printRailWebbing(gdraw, x, y, scale, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset); + + PrintHollowWoodTemplates.printRailNotching(gdraw, x, y, scale, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset); + + PrintHollowWoodTemplates.printRailNosePieceNotches(gdraw, x, y, scale, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset); + + PrintHollowWoodTemplates.printRailTailPieceNotches(gdraw, x, y, scale, 0.0, BoardCAD.getInstance().getCurrentBrd(), distanceToRail, skinThickness, frameThickness, webbing, tailOffset, noseOffset); + settingsDialog.dispose(); + gdraw.close(); + return; + /* + * x+= BoardCAD.getInstance().getCurrentBrd().getThickness(); + * x+= cutterDiam*2.0; + * + * BezierBoardDrawUtil.printRailTemplate(gdraw, x, y, scale, + * false, BoardCAD.getInstance().getCurrentBrd(), + * distanceToRail, skinThickness, tailOffset, noseOffset, + * false); + * + * PrintHollowWoodTemplates.printRailWebbing(gdraw, x, y, scale, + * BoardCAD.getInstance().getCurrentBrd(), distanceToRail, + * skinThickness, frameThickness, webbing, tailOffset, + * noseOffset); + * + * PrintHollowWoodTemplates.printRailNotching(gdraw, x, y, + * scale, BoardCAD.getInstance().getCurrentBrd(), + * distanceToRail, skinThickness, frameThickness, webbing, + * tailOffset, noseOffset); + * + * PrintHollowWoodTemplates.printRailNosePieceNotches(gdraw, x, + * y, scale, BoardCAD.getInstance().getCurrentBrd(), + * distanceToRail, skinThickness, frameThickness, webbing, + * tailOffset, noseOffset); + * + * PrintHollowWoodTemplates.printRailTailPieceNotches(gdraw, x, + * y, scale, BoardCAD.getInstance().getCurrentBrd(), + * distanceToRail, skinThickness, frameThickness, webbing, + * tailOffset, noseOffset); + * + * //Print cross sections gdraw.writeComment("Ribs"); x+= + * BoardCAD.getInstance().getCurrentBrd().getThickness(); x+= + * cutterDiam*2.0; y=offsetY; + * + * int nrOfCrossSections = + * (int)((BoardCAD.getInstance().getCurrentBrd().getLength() - + * 9.0*UnitUtils.INCH)/UnitUtils.FOOT); double crosssectionPos = + * 0.0; for(int i = 0; i < nrOfCrossSections; i++) { + * crosssectionPos = (i+1)* UnitUtils.FOOT; + * + * gdraw.writeComment("Rib at " + + * UnitUtils.convertLengthToCurrentUnit(crosssectionPos, true)); + * + * PrintHollowWoodTemplates.printCrossSection(gdraw, x, y, + * scale, BoardCAD.getInstance().getCurrentBrd(), + * crosssectionPos, distanceToRail, skinThickness, + * frameThickness, webbing, false); + * + * PrintHollowWoodTemplates.printCrossSectionWebbing(gdraw, x, + * y, scale, BoardCAD.getInstance().getCurrentBrd(), + * crosssectionPos, distanceToRail, skinThickness, + * frameThickness, webbing, false); + * + * double verticalStep = + * BoardCAD.getInstance().getCurrentBrd().getThicknessAtPos + * (crosssectionPos) - skinThickness + (cutterDiam*2.0); + * + * y += verticalStep; } + * + * + * //Nose piece gdraw.writeComment("Nose"); + * PrintHollowWoodTemplates.printNosePiece(gdraw, x, y, scale, + * BoardCAD.getInstance().getCurrentBrd(), distanceToRail, + * skinThickness, frameThickness, webbing, tailOffset, + * noseOffset, false); + * + * PrintHollowWoodTemplates.printNosePiece(gdraw, x, y, scale, + * BoardCAD.getInstance().getCurrentBrd(), distanceToRail, + * skinThickness, frameThickness, webbing, tailOffset, + * noseOffset, true); + * + * PrintHollowWoodTemplates.printNosePieceWebbing(gdraw, x, y, + * scale, BoardCAD.getInstance().getCurrentBrd(), + * distanceToRail, skinThickness, frameThickness, webbing, + * tailOffset, noseOffset, false); + * + * PrintHollowWoodTemplates.printNosePieceWebbing(gdraw, x, y, + * scale, BoardCAD.getInstance().getCurrentBrd(), + * distanceToRail, skinThickness, frameThickness, webbing, + * tailOffset, noseOffset, true); + * + * //Tail piece gdraw.writeComment("Tail"); y += UnitUtils.FOOT; + * PrintHollowWoodTemplates.printTailPiece(gdraw, x, y, scale, + * BoardCAD.getInstance().getCurrentBrd(), distanceToRail, + * skinThickness, frameThickness, webbing, tailOffset, + * noseOffset, false); + * + * PrintHollowWoodTemplates.printTailPiece(gdraw, x, y, scale, + * BoardCAD.getInstance().getCurrentBrd(), distanceToRail, + * skinThickness, frameThickness, webbing, tailOffset, + * noseOffset, true); + * + * PrintHollowWoodTemplates.printTailPieceWebbing(gdraw, x, y, + * scale, BoardCAD.getInstance().getCurrentBrd(), + * distanceToRail, skinThickness, frameThickness, webbing, + * tailOffset, noseOffset, false); + * + * PrintHollowWoodTemplates.printTailPieceWebbing(gdraw, x, y, + * scale, BoardCAD.getInstance().getCurrentBrd(), + * distanceToRail, skinThickness, frameThickness, webbing, + * tailOffset, noseOffset, true); + * + * + * settingsDialog.dispose(); + * + * gdraw.close(); + */ + } + + }; + + gcodeHWSMenu.add(gcodeHWSAllInternalTemplates); + + gcodeMenu.add(gcodeHWSMenu); + fileMenu.add(gcodeMenu); final JMenu extensionsMenu = new JMenu(LanguageResource.getString("EXTENSIONSMENU_STR")); final JMenu atuaCoresMenu = new JMenu(LanguageResource.getString("ATUACORESMENU_STR")); final AbstractAction atuaCoresProfile = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("ATUACORESPROFILE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { - + CategorizedSettings settings = new CategorizedSettings(); String categoryName = LanguageResource.getString("ATUAPARAMETERSCATEGORY_STR"); Settings atuaSettings = settings.addCategory(categoryName); @@ -3472,13 +4044,12 @@ public void actionPerformed(ActionEvent arg0) { if (settingsDialog.wasCancelled()) { return; } - + final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -3498,9 +4069,7 @@ public void actionPerformed(ActionEvent arg0) { toolpathGenerator.writeProfile(filename, getCurrentBrd(), atuaSettings.getBoolean("NoRotation")); } catch (Exception e) { String str = LanguageResource.getString("ATUACORESPROFILEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("ATUACORESPROFILEFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("ATUACORESPROFILEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -3509,18 +4078,18 @@ public void actionPerformed(ActionEvent arg0) { atuaCoresMenu.add(atuaCoresProfile); final AbstractAction atuaCoresOutline = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("ATUACORESOUTLINE_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showSaveDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -3540,9 +4109,7 @@ public void actionPerformed(ActionEvent arg0) { toolpathGenerator.writeOutline(filename, getCurrentBrd()); } catch (Exception e) { String str = LanguageResource.getString("ATUACORESOUTLINEFAILEDMSG_STR") + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, LanguageResource.getString("ATUACORESOUTLINEFAILEDTITLE_STR"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("ATUACORESOUTLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); } } @@ -3556,21 +4123,22 @@ public void actionPerformed(ActionEvent arg0) { fileMenu.addSeparator(); - final AbstractAction loadscript = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, "Load script"); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_I, + // KeyEvent.CTRL_DOWN_MASK)); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showOpenDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showOpenDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -3580,10 +4148,10 @@ public void actionPerformed(ActionEvent arg0) { // selection if (filename == null) return; - -// ScriptLoader sl=new ScriptLoader(); -// sl.loadScript(filename); - + + // ScriptLoader sl=new ScriptLoader(); + // sl.loadScript(filename); + BoardCAD.defaultDirectory = file.getPath(); } @@ -3593,84 +4161,88 @@ public void actionPerformed(ActionEvent arg0) { fileMenu.addSeparator(); - - - final AbstractAction test = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, "Test"); }; - public void actionPerformed(ActionEvent arg0) - { -/* CategorizedSettings settings = new CategorizedSettings(); - settings.addCategory("test"); - settings.getSettings("test").addBoolean("Test1", true, "Test 1"); - - SettingDialog dialog = new SettingDialog(settings); - dialog.setModal(true); - dialog.setVisible(true); - if(!dialog.wasCancelled()) - { - boolean test1 = settings.getSettings("test").getBoolean("Test1"); - System.out.printf("Test1: %s", test1?"true":"false"); - } - - BezierSpline b = getCurrentBrd().getNearestCrossSection(getCurrentBrd().getLength()/2.0f).getBezierSpline(); - double startAngle = b.getNormalByS(BezierSpline.ZERO); - double endAngle = b.getNormalByS(BezierSpline.ONE); - - System.out.printf("startAngle: %f endAngle: %f\n", startAngle/BezierBoard.DEG_TO_RAD, endAngle/BezierBoard.DEG_TO_RAD); - - int steps = 20; - - System.out.printf("----------------------------------------\n"); - System.out.printf("----------------------------------------\n"); - System.out.printf("---------------TEST BEGIN---------------\n"); - System.out.printf("----------------------------------------\n"); - - for(int i = 0; i < steps; i++) - { - double currentAngle = b.getNormalByS((double)i/(double)steps); - System.out.printf("Angle:%f\n", currentAngle/BezierBoard.DEG_TO_RAD); - } - - System.out.printf("----------------------------------------\n"); - System.out.printf("----------------------------------------\n"); - - double angleStep = (endAngle-startAngle) / steps; - - for(int i = 0; i < steps; i++) - { - System.out.printf("----------------------------------------\n"); - double currentAngle = startAngle + (angleStep*i); - double s = b.getSByNormalReverse(currentAngle); - double checkAngle = b.getNormalByS(s); - System.out.printf("Target Angle:%f Result s:%f Angle for s:%f\n", currentAngle/BezierBoard.DEG_TO_RAD, s, checkAngle/BezierBoard.DEG_TO_RAD); - } -*/ + @Override + public void actionPerformed(ActionEvent arg0) { + /* + * CategorizedSettings settings = new CategorizedSettings(); + * settings.addCategory("test"); + * settings.getSettings("test").addBoolean("Test1", true, + * "Test 1"); + * + * SettingDialog dialog = new SettingDialog(settings); + * dialog.setModal(true); dialog.setVisible(true); + * if(!dialog.wasCancelled()) { boolean test1 = + * settings.getSettings("test").getBoolean("Test1"); + * System.out.printf("Test1: %s", test1?"true":"false"); } + * + * BezierSpline b = + * getCurrentBrd().getNearestCrossSection(getCurrentBrd + * ().getLength()/2.0f).getBezierSpline(); double startAngle = + * b.getNormalByS(BezierSpline.ZERO); double endAngle = + * b.getNormalByS(BezierSpline.ONE); + * + * System.out.printf("startAngle: %f endAngle: %f\n", + * startAngle/BezierBoard.DEG_TO_RAD, + * endAngle/BezierBoard.DEG_TO_RAD); + * + * int steps = 20; + * + * System.out.printf("----------------------------------------\n" + * ); + * System.out.printf("----------------------------------------\n" + * ); + * System.out.printf("---------------TEST BEGIN---------------\n" + * ); + * System.out.printf("----------------------------------------\n" + * ); + * + * for(int i = 0; i < steps; i++) { double currentAngle = + * b.getNormalByS((double)i/(double)steps); + * System.out.printf("Angle:%f\n", + * currentAngle/BezierBoard.DEG_TO_RAD); } + * + * System.out.printf("----------------------------------------\n" + * ); + * System.out.printf("----------------------------------------\n" + * ); + * + * double angleStep = (endAngle-startAngle) / steps; + * + * for(int i = 0; i < steps; i++) { + * System.out.printf("----------------------------------------\n" + * ); double currentAngle = startAngle + (angleStep*i); double s + * = b.getSByNormalReverse(currentAngle); double checkAngle = + * b.getNormalByS(s); + * System.out.printf("Target Angle:%f Result s:%f Angle for s:%f\n" + * , currentAngle/BezierBoard.DEG_TO_RAD, s, + * checkAngle/BezierBoard.DEG_TO_RAD); } + */ System.out.printf("__________________________________\n"); - //Test SimpleBullnoseCutter + // Test SimpleBullnoseCutter SimpleBullnoseCutter cutter = new SimpleBullnoseCutter(50, 10, 100); System.out.printf("TEST!!! Cutter diam: 50 corner: 10 height: 100\n"); - Point3d point = new Point3d(0.0,0.0,0.0); + Point3d point = new Point3d(0.0, 0.0, 0.0); Vector testVectors = new Vector(); - testVectors.add(new Vector3d(1.0,1.0,1.0)); -// testVectors.add(new Vector3d(1.0,0.0,1.0)); -// testVectors.add(new Vector3d(-1.0,0.0,1.0)); -// testVectors.add(new Vector3d(0.0,1.0,1.0)); -// testVectors.add(new Vector3d(0.0,-1.0,1.0)); -// testVectors.add(new Vector3d(0.0,-1.0,0.0)); -// testVectors.add(new Vector3d(1.0,0.0,1.0)); + testVectors.add(new Vector3d(1.0, 1.0, 1.0)); + // testVectors.add(new Vector3d(1.0,0.0,1.0)); + // testVectors.add(new Vector3d(-1.0,0.0,1.0)); + // testVectors.add(new Vector3d(0.0,1.0,1.0)); + // testVectors.add(new Vector3d(0.0,-1.0,1.0)); + // testVectors.add(new Vector3d(0.0,-1.0,0.0)); + // testVectors.add(new Vector3d(1.0,0.0,1.0)); System.out.printf("\n__________________________________\n"); - for(int i = 0; i < testVectors.size(); i++) - { + for (int i = 0; i < testVectors.size(); i++) { Vector3d vector = testVectors.elementAt(i); vector.normalize(); System.out.printf("\nTEST!!! Vector%d: %f,%f,%f\n", i, vector.x, vector.y, vector.z); @@ -3681,18 +4253,18 @@ public void actionPerformed(ActionEvent arg0) } }; -// fileMenu.add(test); + fileMenu.add(test); final AbstractAction exit = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("EXIT_STR")); }; - public void actionPerformed(ActionEvent arg0) - { + @Override + public void actionPerformed(ActionEvent arg0) { mFrame.dispose(); -// mFrame.setVisible(false); + // mFrame.setVisible(false); } }; @@ -3703,15 +4275,15 @@ public void actionPerformed(ActionEvent arg0) final JMenu editMenu = new JMenu(LanguageResource.getString("EDITMENU_STR")); editMenu.setMnemonic(KeyEvent.VK_E); final AbstractAction undo = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("UNDO_STR")); this.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("UNDO_STR")); - this.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/edit-undo.png"))); - this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK)); + this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/edit-undo.png"))); + this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK)); }; + @Override public void actionPerformed(ActionEvent arg0) { BrdCommandHistory.getInstance().undo(); mFrame.repaint(); @@ -3721,16 +4293,16 @@ public void actionPerformed(ActionEvent arg0) { editMenu.add(undo); final AbstractAction redo = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("REDO_STR")); this.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("REDO_STR")); - this.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/edit-redo.png"))); + this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/edit-redo.png"))); - this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_Y, KeyEvent.CTRL_DOWN_MASK)); + this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_DOWN_MASK)); }; + @Override public void actionPerformed(ActionEvent arg0) { BrdCommandHistory.getInstance().redo(); mFrame.repaint(); @@ -3741,178 +4313,187 @@ public void actionPerformed(ActionEvent arg0) { menuBar.add(editMenu); - final JMenu viewMenu = new JMenu( LanguageResource.getString("VIEWMENU_STR")); + final JMenu viewMenu = new JMenu(LanguageResource.getString("VIEWMENU_STR")); viewMenu.setMnemonic(KeyEvent.VK_V); - mIsPaintingGridMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWGRID_STR")); + mIsPaintingGridMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWGRID_STR")); mIsPaintingGridMenuItem.setMnemonic(KeyEvent.VK_R); mIsPaintingGridMenuItem.setSelected(true); mIsPaintingGridMenuItem.addItemListener(this); viewMenu.add(mIsPaintingGridMenuItem); - mIsPaintingGhostBrdMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWGHOSTBOARD_STR")); + mIsPaintingGhostBrdMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWGHOSTBOARD_STR")); mIsPaintingGhostBrdMenuItem.setMnemonic(KeyEvent.VK_G); mIsPaintingGhostBrdMenuItem.setSelected(true); mIsPaintingGhostBrdMenuItem.addItemListener(this); viewMenu.add(mIsPaintingGhostBrdMenuItem); - mIsPaintingOriginalBrdMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWORIGINALBOARD_STR")); + mIsPaintingOriginalBrdMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWORIGINALBOARD_STR")); mIsPaintingOriginalBrdMenuItem.setMnemonic(KeyEvent.VK_O); mIsPaintingOriginalBrdMenuItem.setSelected(true); mIsPaintingOriginalBrdMenuItem.addItemListener(this); viewMenu.add(mIsPaintingOriginalBrdMenuItem); - mIsPaintingControlPointsMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWCONTROLPOINTS_STR")); + mIsPaintingControlPointsMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWCONTROLPOINTS_STR")); mIsPaintingControlPointsMenuItem.setMnemonic(KeyEvent.VK_C); - mIsPaintingControlPointsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, 0));// , KeyEvent.CTRL_DOWN_MASK)); + mIsPaintingControlPointsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, 0));// , + // KeyEvent.CTRL_DOWN_MASK)); mIsPaintingControlPointsMenuItem.setSelected(true); mIsPaintingControlPointsMenuItem.addItemListener(this); viewMenu.add(mIsPaintingControlPointsMenuItem); - mIsPaintingNonActiveCrossSectionsMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWNONEACTIVECROSSECTIONS_STR")); + mIsPaintingNonActiveCrossSectionsMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWNONEACTIVECROSSECTIONS_STR")); mIsPaintingNonActiveCrossSectionsMenuItem.setMnemonic(KeyEvent.VK_N); mIsPaintingNonActiveCrossSectionsMenuItem.setSelected(true); mIsPaintingNonActiveCrossSectionsMenuItem.addItemListener(this); viewMenu.add(mIsPaintingNonActiveCrossSectionsMenuItem); - mIsPaintingGuidePointsMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWGUIDEPOINTS_STR")); + mIsPaintingGuidePointsMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWGUIDEPOINTS_STR")); mIsPaintingGuidePointsMenuItem.setMnemonic(KeyEvent.VK_P); mIsPaintingGuidePointsMenuItem.setSelected(true); mIsPaintingGuidePointsMenuItem.addItemListener(this); viewMenu.add(mIsPaintingGuidePointsMenuItem); - mIsPaintingCurvatureMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWCURVATURE_STR")); + mIsPaintingCurvatureMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWCURVATURE_STR")); mIsPaintingCurvatureMenuItem.setMnemonic(KeyEvent.VK_V); - mIsPaintingCurvatureMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0));// , KeyEvent.CTRL_DOWN_MASK)); + mIsPaintingCurvatureMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0));// , + // KeyEvent.CTRL_DOWN_MASK)); mIsPaintingCurvatureMenuItem.setSelected(true); mIsPaintingCurvatureMenuItem.addItemListener(this); viewMenu.add(mIsPaintingCurvatureMenuItem); mIsPaintingVolumeDistributionMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWVOLUMEDISTRIBUTION_STR")); mIsPaintingVolumeDistributionMenuItem.setMnemonic(KeyEvent.VK_V); - mIsPaintingVolumeDistributionMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, 0));// , KeyEvent.CTRL_DOWN_MASK)); + mIsPaintingVolumeDistributionMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, 0));// , + // KeyEvent.CTRL_DOWN_MASK)); mIsPaintingVolumeDistributionMenuItem.setSelected(true); mIsPaintingVolumeDistributionMenuItem.addItemListener(this); viewMenu.add(mIsPaintingVolumeDistributionMenuItem); - mIsPaintingCenterOfMassMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWCENTEROFMASS_STR")); + mIsPaintingCenterOfMassMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWCENTEROFMASS_STR")); mIsPaintingCenterOfMassMenuItem.setMnemonic(KeyEvent.VK_M); mIsPaintingCenterOfMassMenuItem.setSelected(true); mIsPaintingCenterOfMassMenuItem.addItemListener(this); viewMenu.add(mIsPaintingCenterOfMassMenuItem); - mIsPaintingSlidingInfoMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWSLIDINGINFO_STR")); + mIsPaintingSlidingInfoMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWSLIDINGINFO_STR")); mIsPaintingSlidingInfoMenuItem.setMnemonic(KeyEvent.VK_S); mIsPaintingSlidingInfoMenuItem.setSelected(true); mIsPaintingSlidingInfoMenuItem.addItemListener(this); viewMenu.add(mIsPaintingSlidingInfoMenuItem); - mIsPaintingSlidingCrossSectionMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWSLIDINGCROSSECTION_STR")); + mIsPaintingSlidingCrossSectionMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWSLIDINGCROSSECTION_STR")); mIsPaintingSlidingCrossSectionMenuItem.setMnemonic(KeyEvent.VK_X); - mIsPaintingSlidingCrossSectionMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, 0));// , KeyEvent.CTRL_DOWN_MASK)); + mIsPaintingSlidingCrossSectionMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, 0));// , + // KeyEvent.CTRL_DOWN_MASK)); mIsPaintingSlidingCrossSectionMenuItem.setSelected(true); mIsPaintingSlidingCrossSectionMenuItem.addItemListener(this); viewMenu.add(mIsPaintingSlidingCrossSectionMenuItem); - mIsPaintingFinsMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWFINS_STR")); + mIsPaintingFinsMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWFINS_STR")); mIsPaintingFinsMenuItem.setMnemonic(KeyEvent.VK_F); mIsPaintingFinsMenuItem.setSelected(true); mIsPaintingFinsMenuItem.addItemListener(this); viewMenu.add(mIsPaintingFinsMenuItem); - mIsPaintingBackgroundImageMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWBACKGROUNDIMAGE_STR")); + mIsPaintingBackgroundImageMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWBACKGROUNDIMAGE_STR")); mIsPaintingBackgroundImageMenuItem.setMnemonic(KeyEvent.VK_B); mIsPaintingBackgroundImageMenuItem.setSelected(true); mIsPaintingBackgroundImageMenuItem.addItemListener(this); viewMenu.add(mIsPaintingBackgroundImageMenuItem); - mIsAntialiasingMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("USEANTIALIASING_STR")); + mIsAntialiasingMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("USEANTIALIASING_STR")); mIsAntialiasingMenuItem.setMnemonic(KeyEvent.VK_A); mIsAntialiasingMenuItem.setSelected(true); mIsAntialiasingMenuItem.addItemListener(this); viewMenu.add(mIsAntialiasingMenuItem); - mIsPaintingBaseLineMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWBASELINE_STR")); + mIsPaintingBaseLineMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWBASELINE_STR")); mIsPaintingBaseLineMenuItem.setMnemonic(KeyEvent.VK_L); mIsPaintingBaseLineMenuItem.setSelected(true); mIsPaintingBaseLineMenuItem.addItemListener(this); viewMenu.add(mIsPaintingBaseLineMenuItem); - mIsPaintingCenterLineMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWCENTERLINE_STR")); + mIsPaintingCenterLineMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWCENTERLINE_STR")); mIsPaintingCenterLineMenuItem.setMnemonic(KeyEvent.VK_J); mIsPaintingCenterLineMenuItem.setSelected(true); mIsPaintingCenterLineMenuItem.addItemListener(this); viewMenu.add(mIsPaintingCenterLineMenuItem); - mIsPaintingOverCurveMesurementsMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWOVERBOTTOMCURVEMEASUREMENTS_STR")); + mIsPaintingOverCurveMesurementsMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWOVERBOTTOMCURVEMEASUREMENTS_STR")); mIsPaintingOverCurveMesurementsMenuItem.setMnemonic(KeyEvent.VK_D); - mIsPaintingOverCurveMesurementsMenuItem.setAccelerator( KeyStroke.getKeyStroke("shift V") ); + mIsPaintingOverCurveMesurementsMenuItem.setAccelerator(KeyStroke.getKeyStroke("shift V")); mIsPaintingOverCurveMesurementsMenuItem.setSelected(true); mIsPaintingOverCurveMesurementsMenuItem.addItemListener(this); viewMenu.add(mIsPaintingOverCurveMesurementsMenuItem); - mIsPaintingMomentOfInertiaMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWMOMENTOFINERTIA_STR")); + mIsPaintingMomentOfInertiaMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWMOMENTOFINERTIA_STR")); mIsPaintingMomentOfInertiaMenuItem.setMnemonic(KeyEvent.VK_D); -// mIsPaintingMomentOfInertiaMenuItem.setAccelerator( KeyStroke.getKeyStroke("shift V") ); + // mIsPaintingMomentOfInertiaMenuItem.setAccelerator( + // KeyStroke.getKeyStroke("shift V") ); mIsPaintingMomentOfInertiaMenuItem.setSelected(true); mIsPaintingMomentOfInertiaMenuItem.addItemListener(this); viewMenu.add(mIsPaintingMomentOfInertiaMenuItem); - - mIsPaintingCrossectionsPositionsMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWCROSSECTIONSPOSITIONS_STR")); + + mIsPaintingCrossectionsPositionsMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWCROSSECTIONSPOSITIONS_STR")); mIsPaintingCrossectionsPositionsMenuItem.setMnemonic(KeyEvent.VK_D); -// mIsPaintingCrossectionsPositionsMenuItem.setAccelerator( KeyStroke.getKeyStroke("shift V") ); + // mIsPaintingCrossectionsPositionsMenuItem.setAccelerator( + // KeyStroke.getKeyStroke("shift V") ); mIsPaintingCrossectionsPositionsMenuItem.setSelected(true); mIsPaintingCrossectionsPositionsMenuItem.addItemListener(this); viewMenu.add(mIsPaintingCrossectionsPositionsMenuItem); - mIsPaintingFlowlinesMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWFLOWLINES_STR")); + mIsPaintingFlowlinesMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWFLOWLINES_STR")); mIsPaintingFlowlinesMenuItem.setMnemonic(KeyEvent.VK_D); -// mIsPaintingFlowlinesMenuItem.setAccelerator( KeyStroke.getKeyStroke("shift V") ); + // mIsPaintingFlowlinesMenuItem.setAccelerator( + // KeyStroke.getKeyStroke("shift V") ); mIsPaintingFlowlinesMenuItem.setSelected(true); mIsPaintingFlowlinesMenuItem.addItemListener(this); viewMenu.add(mIsPaintingFlowlinesMenuItem); - mIsPaintingApexlineMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWAPEXLINE_STR")); + mIsPaintingApexlineMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWAPEXLINE_STR")); mIsPaintingApexlineMenuItem.setMnemonic(KeyEvent.VK_D); -// mIsPaintingApexlineMenuItem.setAccelerator( KeyStroke.getKeyStroke("shift V") ); + // mIsPaintingApexlineMenuItem.setAccelerator( + // KeyStroke.getKeyStroke("shift V") ); mIsPaintingApexlineMenuItem.setSelected(true); mIsPaintingApexlineMenuItem.addItemListener(this); viewMenu.add(mIsPaintingApexlineMenuItem); - mIsPaintingTuckUnderLineMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWTUCKUNDERLINE_STR")); + mIsPaintingTuckUnderLineMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWTUCKUNDERLINE_STR")); mIsPaintingTuckUnderLineMenuItem.setMnemonic(KeyEvent.VK_D); -// mIsPaintingTuckUnderLineMenuItem.setAccelerator( KeyStroke.getKeyStroke("shift V") ); + // mIsPaintingTuckUnderLineMenuItem.setAccelerator( + // KeyStroke.getKeyStroke("shift V") ); mIsPaintingTuckUnderLineMenuItem.setSelected(true); mIsPaintingTuckUnderLineMenuItem.addItemListener(this); viewMenu.add(mIsPaintingTuckUnderLineMenuItem); - mIsPaintingFootMarksMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWFOOTMARKS_STR")); + mIsPaintingFootMarksMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWFOOTMARKS_STR")); mIsPaintingFootMarksMenuItem.setMnemonic(KeyEvent.VK_D); - mIsPaintingFootMarksMenuItem.setAccelerator(KeyStroke.getKeyStroke("shift F") ); + mIsPaintingFootMarksMenuItem.setAccelerator(KeyStroke.getKeyStroke("shift F")); mIsPaintingFootMarksMenuItem.setSelected(false); mIsPaintingFootMarksMenuItem.addItemListener(this); viewMenu.add(mIsPaintingFootMarksMenuItem); - mUseFillMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("USEFILL_STR")); - //mUseFillMenuItem.setMnemonic(KeyEvent.VK_D); - //mUseFillMenuItem.setAccelerator(KeyStroke.getKeyStroke("shift F") ); + mUseFillMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("USEFILL_STR")); + // mUseFillMenuItem.setMnemonic(KeyEvent.VK_D); + // mUseFillMenuItem.setAccelerator(KeyStroke.getKeyStroke("shift F") ); mUseFillMenuItem.setSelected(true); mUseFillMenuItem.addItemListener(this); viewMenu.add(mUseFillMenuItem); - + menuBar.add(viewMenu); final JMenu crossSectionsMenu = new JMenu(LanguageResource.getString("CROSSECTIONSMENU_STR")); crossSectionsMenu.setMnemonic(KeyEvent.VK_C); mNextCrossSection = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("NEXTCROSSECTION_STR")); - this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_PLUS, 0)); + this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { if (isGhostMode()) { BoardCAD.getInstance().getGhostBrd().nextCrossSection(); @@ -3928,22 +4509,20 @@ public void actionPerformed(ActionEvent arg0) { crossSectionsMenu.add(mNextCrossSection); mPreviousCrossSection = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PREVIOUSCROSSECTION_STR")); - this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_MINUS, 0)); + this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { if (isGhostMode()) { BoardCAD.getInstance().getGhostBrd().previousCrossSection(); } else if (mOrgFocus) { - BoardCAD.getInstance().getOriginalBrd() - .previousCrossSection(); + BoardCAD.getInstance().getOriginalBrd().previousCrossSection(); } else { - BoardCAD.getInstance().getCurrentBrd() - .previousCrossSection(); + BoardCAD.getInstance().getCurrentBrd().previousCrossSection(); } mFrame.repaint(); } @@ -3953,36 +4532,30 @@ public void actionPerformed(ActionEvent arg0) { crossSectionsMenu.addSeparator(); final AbstractAction addCrossSection = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("ADDCROSSECTION_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { setSelectedEdit(mCrossSectionEdit); double pos = 0.0f; - String posStr = JOptionPane.showInputDialog(mFrame, - LanguageResource.getString("ADDCROSSECTIONMSG_STR"), - LanguageResource.getString("ADDCROSSECTIONTITLE_STR"), JOptionPane.PLAIN_MESSAGE); + String posStr = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("ADDCROSSECTIONMSG_STR"), LanguageResource.getString("ADDCROSSECTIONTITLE_STR"), JOptionPane.PLAIN_MESSAGE); if (posStr == null) return; pos = UnitUtils.convertInputStringToInternalLengthUnit(posStr); if (pos <= 0 || pos > getCurrentBrd().getLength()) { - JOptionPane - .showMessageDialog( - getFrame(), - LanguageResource.getString("ADDCROSSECTIONPOSITIONINVALIDMSG_STR"), - LanguageResource.getString("ADDCROSSECTIONPOSITIONINVALIDTITLE_STR"), JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(getFrame(), LanguageResource.getString("ADDCROSSECTIONPOSITIONINVALIDMSG_STR"), LanguageResource.getString("ADDCROSSECTIONPOSITIONINVALIDTITLE_STR"), JOptionPane.WARNING_MESSAGE); return; } - BrdAddCrossSectionCommand cmd = new BrdAddCrossSectionCommand( - mCrossSectionEdit, pos); + BrdAddCrossSectionCommand cmd = new BrdAddCrossSectionCommand(mCrossSectionEdit, pos); cmd.execute(); mFrame.repaint(); @@ -3992,37 +4565,30 @@ public void actionPerformed(ActionEvent arg0) { crossSectionsMenu.add(addCrossSection); final AbstractAction moveCrossSection = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("MOVECROSSECTION_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { setSelectedEdit(mCrossSectionEdit); double pos = 0.0f; - String posStr = JOptionPane.showInputDialog(mFrame, - LanguageResource.getString("MOVECROSSECTIONMSG_STR"), - LanguageResource.getString("MOVECROSSECTIONTITLE_STR"), JOptionPane.PLAIN_MESSAGE); + String posStr = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("MOVECROSSECTIONMSG_STR"), LanguageResource.getString("MOVECROSSECTIONTITLE_STR"), JOptionPane.PLAIN_MESSAGE); if (posStr == null) return; pos = UnitUtils.convertInputStringToInternalLengthUnit(posStr); if (pos <= 0 || pos > getCurrentBrd().getLength()) { - JOptionPane - .showMessageDialog( - getFrame(), - LanguageResource.getString("MOVECROSSECTIONPOSITIONINVALIDMSG_STR"), - LanguageResource.getString("MOVECROSSECTIONPOSITIONINVALIDTITLE_STR"), JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(getFrame(), LanguageResource.getString("MOVECROSSECTIONPOSITIONINVALIDMSG_STR"), LanguageResource.getString("MOVECROSSECTIONPOSITIONINVALIDTITLE_STR"), JOptionPane.WARNING_MESSAGE); return; } - BrdMoveCrossSectionCommand cmd = new BrdMoveCrossSectionCommand( - mCrossSectionEdit, mCrossSectionEdit.getCurrentBrd() - .getCurrentCrossSection(), pos); + BrdMoveCrossSectionCommand cmd = new BrdMoveCrossSectionCommand(mCrossSectionEdit, mCrossSectionEdit.getCurrentBrd().getCurrentCrossSection(), pos); cmd.execute(); mFrame.repaint(); @@ -4032,27 +4598,24 @@ public void actionPerformed(ActionEvent arg0) { crossSectionsMenu.add(moveCrossSection); final AbstractAction deleteCrossSection = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("REMOVECROSSECTION_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { setSelectedEdit(mCrossSectionEdit); if (mCrossSectionEdit.getCurrentBrd().getCrossSections().size() <= 3) { - JOptionPane.showMessageDialog(getFrame(), - LanguageResource.getString("REMOVECROSSECTIONDELETELASTERRORMSG_STR"), - LanguageResource.getString("REMOVECROSSECTIONDELETELASTERRORTITLE_STR"), JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(getFrame(), LanguageResource.getString("REMOVECROSSECTIONDELETELASTERRORMSG_STR"), LanguageResource.getString("REMOVECROSSECTIONDELETELASTERRORTITLE_STR"), JOptionPane.WARNING_MESSAGE); return; } - BrdRemoveCrossSectionCommand cmd = new BrdRemoveCrossSectionCommand( - mCrossSectionEdit, mCrossSectionEdit.getCurrentBrd() - .getCurrentCrossSection()); + BrdRemoveCrossSectionCommand cmd = new BrdRemoveCrossSectionCommand(mCrossSectionEdit, mCrossSectionEdit.getCurrentBrd().getCurrentCrossSection()); cmd.execute(); mFrame.repaint(); @@ -4063,16 +4626,16 @@ public void actionPerformed(ActionEvent arg0) { crossSectionsMenu.addSeparator(); final AbstractAction copyCrossSection = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("COPYCROSSECTION_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - mCrossSectionCopy = (BezierBoardCrossSection) getCurrentBrd() - .getCurrentCrossSection().clone(); + mCrossSectionCopy = (BezierBoardCrossSection) getCurrentBrd().getCurrentCrossSection().clone(); mFrame.repaint(); } @@ -4081,22 +4644,21 @@ public void actionPerformed(ActionEvent arg0) { crossSectionsMenu.add(copyCrossSection); final AbstractAction pasteCrossSection = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("PASTECROSSECTION_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { if (mCrossSectionCopy == null) return; setSelectedEdit(mCrossSectionEdit); - BrdPasteCrossSectionCommand cmd = new BrdPasteCrossSectionCommand( - mCrossSectionEdit, getCurrentBrd() - .getCurrentCrossSection(), mCrossSectionCopy); + BrdPasteCrossSectionCommand cmd = new BrdPasteCrossSectionCommand(mCrossSectionEdit, getCurrentBrd().getCurrentCrossSection(), mCrossSectionCopy); cmd.execute(); mFrame.repaint(); @@ -4111,13 +4673,14 @@ mCrossSectionEdit, getCurrentBrd() boardMenu.setMnemonic(KeyEvent.VK_B); final AbstractAction scale = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("SCALECURRENT_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { BrdScaleCommand cmd = new BrdScaleCommand(getSelectedEdit()); @@ -4130,16 +4693,16 @@ public void actionPerformed(ActionEvent arg0) { boardMenu.add(scale); final AbstractAction scaleGhost = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("SCALEGHOST_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - getGhostBrd().scale(getCurrentBrd().getLength(), - getCurrentBrd().getCenterWidth(), getCurrentBrd().getThickness()); + getGhostBrd().scale(getCurrentBrd().getLength(), getCurrentBrd().getCenterWidth(), getCurrentBrd().getThickness()); mFrame.repaint(); } @@ -4147,20 +4710,20 @@ public void actionPerformed(ActionEvent arg0) { }; boardMenu.add(scaleGhost); - final AbstractAction info = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("INFO_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { BoardInfo dialog = new BoardInfo(getCurrentBrd()); dialog.setModal(true); - //dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + // dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.setVisible(true); dialog.dispose(); mFrame.repaint(); @@ -4171,16 +4734,17 @@ public void actionPerformed(ActionEvent arg0) { boardMenu.add(info); final AbstractAction fins = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { - this.putValue(Action.NAME, LanguageResource.getString("FINS_STR")); + this.putValue(Action.NAME, LanguageResource.getString("FINS_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { BoardFinsDialog dialog = new BoardFinsDialog(getCurrentBrd()); dialog.setModal(true); - //dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + // dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.setVisible(true); dialog.dispose(); mFrame.repaint(); @@ -4190,13 +4754,13 @@ public void actionPerformed(ActionEvent arg0) { boardMenu.add(fins); final AbstractAction guidePoints = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("GUIDEPOINTS_STR")); }; - public void actionPerformed(ActionEvent arg0) - { + @Override + public void actionPerformed(ActionEvent arg0) { mGuidePointsDialog.setVisible(true); mFrame.repaint(); } @@ -4206,13 +4770,13 @@ public void actionPerformed(ActionEvent arg0) boardMenu.add(guidePoints); final AbstractAction weightCalc = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("WEIGHTCALC_STR")); }; - public void actionPerformed(ActionEvent arg0) - { + @Override + public void actionPerformed(ActionEvent arg0) { mWeightCalculatorDialog.setDefaults(); mWeightCalculatorDialog.updateAll(); mWeightCalculatorDialog.setVisible(true); @@ -4223,17 +4787,18 @@ public void actionPerformed(ActionEvent arg0) boardMenu.add(weightCalc); final AbstractAction flip = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("FLIP_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { mOutlineEdit.setFlipped(!mOutlineEdit.isFlipped()); - if(mOutlineEdit2 != null) + if (mOutlineEdit2 != null) mOutlineEdit2.setFlipped(!mOutlineEdit2.isFlipped()); mBottomAndDeckEdit.setFlipped(!mBottomAndDeckEdit.isFlipped()); mCrossSectionOutlineEdit.setFlipped(!mCrossSectionOutlineEdit.isFlipped()); @@ -4256,16 +4821,16 @@ public void actionPerformed(ActionEvent arg0) { miscMenu.setMnemonic(KeyEvent.VK_M); final AbstractAction settings = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("SETTINGS_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - BoardCADSettingsDialog dlg = new BoardCADSettingsDialog( - mSettings); + BoardCADSettingsDialog dlg = new BoardCADSettingsDialog(mSettings); dlg.setModal(true); dlg.setVisible(true); @@ -4277,21 +4842,21 @@ public void actionPerformed(ActionEvent arg0) { miscMenu.add(settings); final AbstractAction language = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("LANGUAGE_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { ComboBoxDialog languageDlg = new ComboBoxDialog(mFrame); languageDlg.setTitle(LanguageResource.getString("LANGUAGE_STR")); languageDlg.setMessageText(LanguageResource.getString("SELECTLANGUAGE_STR")); String[] languages = new String[mSupportedLanguages.length]; - for(int i = 0; i < mSupportedLanguages.length; i++) - { + for (int i = 0; i < mSupportedLanguages.length; i++) { languages[i] = mSupportedLanguages[i].getDisplayName(); } @@ -4301,10 +4866,8 @@ public void actionPerformed(ActionEvent arg0) { String languageStr = prefs.get("Language", "en"); String selectedLanguage = "English"; int i; - for(i = 0; i < mSupportedLanguages.length; i++) - { - if(mSupportedLanguages[i].getLanguage().equals(languageStr)) - { + for (i = 0; i < mSupportedLanguages.length; i++) { + if (mSupportedLanguages[i].getLanguage().equals(languageStr)) { selectedLanguage = mSupportedLanguages[i].getDisplayName(); break; } @@ -4317,21 +4880,16 @@ public void actionPerformed(ActionEvent arg0) { if (!languageDlg.wasCancelled()) { selectedLanguage = languageDlg.getSelectedItem(); - for(i = 0; i < mSupportedLanguages.length; i++) - { - if(mSupportedLanguages[i].getDisplayName().equals(selectedLanguage)) - { + for (i = 0; i < mSupportedLanguages.length; i++) { + if (mSupportedLanguages[i].getDisplayName().equals(selectedLanguage)) { languageStr = mSupportedLanguages[i].getLanguage(); break; } } + prefs.put("Language", languageStr); - prefs.put("Language", languageStr ); - - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), LanguageResource.getString("LANGUAGECHANGEDMSG_STR"), - LanguageResource.getString("LANGUAGECHANGEDTITLE_STR"), JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), LanguageResource.getString("LANGUAGECHANGEDMSG_STR"), LanguageResource.getString("LANGUAGECHANGEDTITLE_STR"), JOptionPane.INFORMATION_MESSAGE); } languageDlg.dispose(); @@ -4343,28 +4901,19 @@ public void actionPerformed(ActionEvent arg0) { miscMenu.addSeparator(); + final JMenu crossSectionInterpolationMenu = new JMenu(LanguageResource.getString("CROSSECTIONINTERPOLATIONMENU_STR")); + mControlPointInterpolationButton = new JRadioButtonMenuItem(LanguageResource.getString("CROSSECTIONINTERPOLATIONTYPECONTROLPOINT_STR")); + mSBlendInterpolationButton = new JRadioButtonMenuItem(LanguageResource.getString("CROSSECTIONINTERPOLATIONTYPESBLEND_STR")); - final JMenu crossSectionInterpolationMenu = new JMenu( - LanguageResource.getString("CROSSECTIONINTERPOLATIONMENU_STR")); - mControlPointInterpolationButton = new JRadioButtonMenuItem( - LanguageResource.getString("CROSSECTIONINTERPOLATIONTYPECONTROLPOINT_STR")); - mSBlendInterpolationButton = new JRadioButtonMenuItem( - LanguageResource.getString("CROSSECTIONINTERPOLATIONTYPESBLEND_STR")); - - ActionListener interpolationTypeListener = new ActionListener() - { + ActionListener interpolationTypeListener = new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { + setBoardChangedFor3D(); boolean selected = mShowBezier3DModelMenuItem.getModel().isSelected(); - if(selected && mTabbedPane.getSelectedComponent() == mRenderedpanel) - { + if (selected) { updateBezier3DModel(); - } - else - { - mBoardChangedFor3D = true; - } - if(mCurrentBrd != null) - { + } + if (mCurrentBrd != null) { mCurrentBrd.setInterpolationType(getCrossSectionInterpolationType()); } } @@ -4373,7 +4922,6 @@ public void actionPerformed(ActionEvent e) { mControlPointInterpolationButton.addActionListener(interpolationTypeListener); mSBlendInterpolationButton.addActionListener(interpolationTypeListener); - final ButtonGroup interpolationButtonGroup = new ButtonGroup(); interpolationButtonGroup.add(mControlPointInterpolationButton); interpolationButtonGroup.add(mSBlendInterpolationButton); @@ -4383,24 +4931,20 @@ public void actionPerformed(ActionEvent e) { miscMenu.add(crossSectionInterpolationMenu); - menuBar.add(miscMenu); - - final JMenu scanMenu = new JMenu("Scan"); scanMenu.setMnemonic(KeyEvent.VK_S); - final AbstractAction scanBoard = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, "Read scanned board"); }; - public void actionPerformed(ActionEvent arg0) - { - Scan myScan=new Scan(); + @Override + public void actionPerformed(ActionEvent arg0) { + Scan myScan = new Scan(); myScan.readScan(); mFrame.repaint(); } @@ -4411,15 +4955,16 @@ public void actionPerformed(ActionEvent arg0) scanMenu.addSeparator(); final AbstractAction manual_scan = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, "Fit curve to guide points"); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - Scan myScan=new Scan(); + Scan myScan = new Scan(); myScan.approximateCurrentView(); mFrame.repaint(); } @@ -4429,15 +4974,15 @@ public void actionPerformed(ActionEvent arg0) { scanMenu.addSeparator(); - final AbstractAction read_scanned_points = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, "Open scanned blank position"); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { board_handler.read_guide_points(); design_panel.fit_all(); @@ -4448,13 +4993,14 @@ public void actionPerformed(ActionEvent arg0) { scanMenu.add(read_scanned_points); final AbstractAction close_scanned_points = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, "Hide scanned blank position"); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { board_handler.close_guide_points(); design_panel.fit_all(); @@ -4466,114 +5012,112 @@ public void actionPerformed(ActionEvent arg0) { menuBar.add(scanMenu); - - final JMenu menu3D = new JMenu(LanguageResource.getString("3DMODELMENU_STR")); menu3D.setMnemonic(KeyEvent.VK_D); final AbstractAction approximate = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("3DAPPROXFROMBEZIER_STR") + " (closed model)"); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { board_handler.approximate_bezier(getCurrentBrd(), true); -// design_panel.update_3d(); -// design_panel.fit_all(); + // design_panel.update_3d(); + // design_panel.fit_all(); mBoardSpec.updateInfoInstantly(); panel.remove(mControlPointInfo); panel.repaint(); -// redraw(); -// design_panel.redraw(); + // redraw(); + // design_panel.redraw(); } }; - + menu3D.add(approximate); + final AbstractAction approximate_open = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("3DAPPROXFROMBEZIER_STR") + " (open model)"); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { board_handler.approximate_bezier(getCurrentBrd(), false); -// design_panel.update_3d(); -// design_panel.fit_all(); + // design_panel.update_3d(); + // design_panel.fit_all(); mBoardSpec.updateInfoInstantly(); panel.remove(mControlPointInfo); panel.repaint(); -// redraw(); -// design_panel.redraw(); + // redraw(); + // design_panel.redraw(); } }; - + menu3D.add(approximate_open); final AbstractAction approximate2 = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, "Approximate outline and rocker"); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { board_handler.approximate_bezier2(getCurrentBrd(), false); -// design_panel.update_3d(); -// design_panel.fit_all(); + // design_panel.update_3d(); + // design_panel.fit_all(); mBoardSpec.updateInfoInstantly(); panel.remove(mControlPointInfo); panel.repaint(); -// redraw(); -// design_panel.redraw(); + // redraw(); + // design_panel.redraw(); } }; + menu3D.add(approximate2); final AbstractAction bezier_patch = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { - this.putValue(Action.NAME, "Create 3D model using Bezier patches"); + this.putValue(Action.NAME, "Create Bezier patch"); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - - if(board_handler.approximate_bezier_patch(getCurrentBrd(), false)<0) + if (board_handler.approximate_bezier_patch(getCurrentBrd(), false) < 0) JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), "All cross sections must have 4 or 5 control points", "Couldn't create bezier patch", JOptionPane.ERROR_MESSAGE); - -// design_panel.update_3d(); -// design_panel.fit_all(); + // design_panel.update_3d(); + // design_panel.fit_all(); mBoardSpec.updateInfoInstantly(); panel.remove(mControlPointInfo); panel.repaint(); -// redraw(); -// design_panel.redraw(); + // redraw(); + // design_panel.redraw(); } }; menu3D.add(bezier_patch); - menu3D.add(approximate); - menu3D.add(approximate_open); - menu3D.add(approximate2); - - - //3D object clear function + // 3D object clear function final AbstractAction clearApproximate = new AbstractAction() { static final long serialVersionUID = 12345L; { this.putValue(Action.NAME, LanguageResource.getString("CLEARAPPROXIMATION_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { board_handler.clearBezier(); mBoardSpec.updateInfoInstantly(); @@ -4586,46 +5130,43 @@ public void actionPerformed(ActionEvent arg0) { menu3D.addSeparator(); JRadioButtonMenuItem rbMenuItem; -/* final ButtonGroup burbsViewGroup = new ButtonGroup(); - rbMenuItem = new JRadioButtonMenuItem(LanguageResource.getString("VIEW3D_STR")); - rbMenuItem.setSelected(true); - rbMenuItem.addActionListener(this); - menu3D.add(rbMenuItem); - burbsViewGroup.add(rbMenuItem); - rbMenuItem = new JRadioButtonMenuItem(LanguageResource.getString("EDITNURBS_STR")); - rbMenuItem.addActionListener(this); - burbsViewGroup.add(rbMenuItem); - menu3D.add(rbMenuItem); - - menu3D.addSeparator(); -*/ + /* + * final ButtonGroup burbsViewGroup = new ButtonGroup(); rbMenuItem = + * new JRadioButtonMenuItem(LanguageResource.getString("VIEW3D_STR")); + * rbMenuItem.setSelected(true); rbMenuItem.addActionListener(this); + * menu3D.add(rbMenuItem); burbsViewGroup.add(rbMenuItem); rbMenuItem = + * new + * JRadioButtonMenuItem(LanguageResource.getString("EDITNURBS_STR")); + * rbMenuItem.addActionListener(this); burbsViewGroup.add(rbMenuItem); + * menu3D.add(rbMenuItem); + * + * menu3D.addSeparator(); + */ - ButtonGroup bnurbsEditGroup=new ButtonGroup(); - rbMenuItem=new JRadioButtonMenuItem(LanguageResource.getString("SIMPLEEDITING_STR")); + ButtonGroup bnurbsEditGroup = new ButtonGroup(); + rbMenuItem = new JRadioButtonMenuItem(LanguageResource.getString("SIMPLEEDITING_STR")); rbMenuItem.setSelected(true); rbMenuItem.addActionListener(this); menu3D.add(rbMenuItem); bnurbsEditGroup.add(rbMenuItem); - rbMenuItem=new JRadioButtonMenuItem(LanguageResource.getString("ADVANCEDEDITING_STR")); + rbMenuItem = new JRadioButtonMenuItem(LanguageResource.getString("ADVANCEDEDITING_STR")); rbMenuItem.addActionListener(this); bnurbsEditGroup.add(rbMenuItem); menu3D.add(rbMenuItem); - - menu3D.addSeparator(); final AbstractAction addsegment = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("ADDSEGMENT_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - String s = (String) JOptionPane.showInputDialog(mFrame, - LanguageResource.getString("DISTANCEFROMTAIL_STR")); + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("DISTANCEFROMTAIL_STR")); board_handler.add_segment(Double.parseDouble(s)); design_panel.redraw(); @@ -4635,19 +5176,19 @@ public void actionPerformed(ActionEvent arg0) { menu3D.add(addsegment); final AbstractAction taildesigner = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("TAILDESIGNER_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - String s = (String) JOptionPane.showInputDialog(mFrame, - LanguageResource.getString("SWALLOWTAIL_STR")); + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("SWALLOWTAIL_STR")); board_handler.set_tail(Double.parseDouble(s)); -// board_handler.set_tail(2); + // board_handler.set_tail(2); design_panel.redraw(); } @@ -4655,19 +5196,17 @@ public void actionPerformed(ActionEvent arg0) { }; menu3D.add(taildesigner); - - final AbstractAction setnrofsegments = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("SETNROFSEGMENT_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - String s = (String) JOptionPane.showInputDialog(mFrame, - LanguageResource.getString("NROFSEGMENT_STR")); + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("NROFSEGMENT_STR")); board_handler.set_nr_of_segments(Integer.parseInt(s)); board_handler.approximate_bezier(getCurrentBrd(), true); @@ -4680,16 +5219,16 @@ public void actionPerformed(ActionEvent arg0) { menu3D.add(setnrofsegments); final AbstractAction setnrofpoints = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("SETNROFPOINTS_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - String s = (String) JOptionPane.showInputDialog(mFrame, - LanguageResource.getString("NROFPOINTS_STR")); + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("NROFPOINTS_STR")); board_handler.set_nr_of_points(Integer.parseInt(s)); board_handler.approximate_bezier(getCurrentBrd(), true); @@ -4701,41 +5240,36 @@ public void actionPerformed(ActionEvent arg0) { }; menu3D.add(setnrofpoints); - menu3D.addSeparator(); - - AbstractAction setasblank = new AbstractAction() - { + AbstractAction setasblank = new AbstractAction() { { this.putValue(Action.NAME, LanguageResource.getString("SETASBLANK_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { + @Override + public void actionPerformed(ActionEvent arg0) { board_handler.set_as_blank(); } }; menu3D.add(setasblank); - - final JMenu transform3DMenu = new JMenu("Transform"); - - AbstractAction rotate = new AbstractAction() - { + AbstractAction rotate = new AbstractAction() { { this.putValue(Action.NAME, LanguageResource.getString("ROTATE_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { - String s=(String)JOptionPane.showInputDialog(mFrame, LanguageResource.getString("ROTATIONANGLE_STR")); - NurbsEditCommand mnurbsCommand=new NurbsEditCommand(); + @Override + public void actionPerformed(ActionEvent arg0) { + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("ROTATIONANGLE_STR")); + NurbsEditCommand mnurbsCommand = new NurbsEditCommand(); board_handler.rotate(Double.parseDouble(s)); mnurbsCommand.execute(); design_panel.redraw(); @@ -4744,19 +5278,18 @@ public void actionPerformed(ActionEvent arg0) }; transform3DMenu.add(rotate); - - AbstractAction translatex = new AbstractAction() - { + AbstractAction translatex = new AbstractAction() { { this.putValue(Action.NAME, LanguageResource.getString("TRANSLATEX_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { - String s=(String)JOptionPane.showInputDialog(mFrame, LanguageResource.getString("TRANLATIONINMM_STR")); + @Override + public void actionPerformed(ActionEvent arg0) { + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("TRANLATIONINMM_STR")); - NurbsEditCommand mnurbsCommand=new NurbsEditCommand(); + NurbsEditCommand mnurbsCommand = new NurbsEditCommand(); board_handler.translate(Double.parseDouble(s), 0.0, 0.0); mnurbsCommand.execute(); design_panel.redraw(); @@ -4765,18 +5298,18 @@ public void actionPerformed(ActionEvent arg0) }; transform3DMenu.add(translatex); - AbstractAction translatey = new AbstractAction() - { + AbstractAction translatey = new AbstractAction() { { this.putValue(Action.NAME, LanguageResource.getString("TRANSLATEY_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { - String s=(String)JOptionPane.showInputDialog(mFrame, LanguageResource.getString("TRANLATIONINMM_STR")); + @Override + public void actionPerformed(ActionEvent arg0) { + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("TRANLATIONINMM_STR")); - NurbsEditCommand mnurbsCommand=new NurbsEditCommand(); + NurbsEditCommand mnurbsCommand = new NurbsEditCommand(); board_handler.translate(0.0, Double.parseDouble(s), 0.0); mnurbsCommand.execute(); design_panel.redraw(); @@ -4785,16 +5318,16 @@ public void actionPerformed(ActionEvent arg0) }; transform3DMenu.add(translatey); - AbstractAction scale_length = new AbstractAction() - { + AbstractAction scale_length = new AbstractAction() { { this.putValue(Action.NAME, LanguageResource.getString("SCALELENGTH_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { - String s=(String)JOptionPane.showInputDialog(mFrame, LanguageResource.getString("SCALELENGTHFACTOR_STR")); + @Override + public void actionPerformed(ActionEvent arg0) { + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("SCALELENGTHFACTOR_STR")); board_handler.scale_length(Double.parseDouble(s)); design_panel.redraw(); @@ -4803,16 +5336,16 @@ public void actionPerformed(ActionEvent arg0) }; transform3DMenu.add(scale_length); - AbstractAction scale_width = new AbstractAction() - { + AbstractAction scale_width = new AbstractAction() { { - this.putValue(Action.NAME, LanguageResource.getString("SCALEWIDTH_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + this.putValue(Action.NAME, LanguageResource.getString("SCALEWIDTH_STR")); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { - String s=(String)JOptionPane.showInputDialog(mFrame, LanguageResource.getString("SCALEWIDTHFACTOR_STR")); + @Override + public void actionPerformed(ActionEvent arg0) { + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("SCALEWIDTHFACTOR_STR")); board_handler.scale_width(Double.parseDouble(s)); design_panel.redraw(); @@ -4821,16 +5354,16 @@ public void actionPerformed(ActionEvent arg0) }; transform3DMenu.add(scale_width); - AbstractAction scale_thickness = new AbstractAction() - { + AbstractAction scale_thickness = new AbstractAction() { { this.putValue(Action.NAME, LanguageResource.getString("SCALETHICKNESS_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { - String s=(String)JOptionPane.showInputDialog(mFrame, LanguageResource.getString("SCALETHICKNESSFACTOR_STR")); + @Override + public void actionPerformed(ActionEvent arg0) { + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("SCALETHICKNESSFACTOR_STR")); board_handler.scale_thickness(Double.parseDouble(s)); design_panel.redraw(); @@ -4839,16 +5372,16 @@ public void actionPerformed(ActionEvent arg0) }; transform3DMenu.add(scale_thickness); - AbstractAction scale_rocker = new AbstractAction() - { + AbstractAction scale_rocker = new AbstractAction() { { this.putValue(Action.NAME, LanguageResource.getString("SCALEROCKER_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { - String s=(String)JOptionPane.showInputDialog(mFrame, LanguageResource.getString("SCALEROCKERFACTOR_STR")); + @Override + public void actionPerformed(ActionEvent arg0) { + String s = JOptionPane.showInputDialog(mFrame, LanguageResource.getString("SCALEROCKERFACTOR_STR")); board_handler.scale_rocker(Double.parseDouble(s)); design_panel.redraw(); @@ -4857,16 +5390,15 @@ public void actionPerformed(ActionEvent arg0) }; transform3DMenu.add(scale_rocker); - - AbstractAction flipnurbs = new AbstractAction() - { + AbstractAction flipnurbs = new AbstractAction() { { this.putValue(Action.NAME, LanguageResource.getString("FLIPBOARD_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { + @Override + public void actionPerformed(ActionEvent arg0) { board_handler.flip(); design_panel.redraw(); @@ -4875,15 +5407,15 @@ public void actionPerformed(ActionEvent arg0) }; transform3DMenu.add(flipnurbs); - AbstractAction placeboard = new AbstractAction() - { + AbstractAction placeboard = new AbstractAction() { { this.putValue(Action.NAME, LanguageResource.getString("PLACEBOARD_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { + @Override + public void actionPerformed(ActionEvent arg0) { board_handler.place_board(); design_panel.redraw(); @@ -4892,15 +5424,15 @@ public void actionPerformed(ActionEvent arg0) }; transform3DMenu.add(placeboard); - AbstractAction placeblank = new AbstractAction() - { + AbstractAction placeblank = new AbstractAction() { { this.putValue(Action.NAME, LanguageResource.getString("PLACEBLANK_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - public void actionPerformed(ActionEvent arg0) - { + @Override + public void actionPerformed(ActionEvent arg0) { board_handler.place_blank(); design_panel.redraw(); @@ -4911,112 +5443,90 @@ public void actionPerformed(ActionEvent arg0) menu3D.add(transform3DMenu); -/* - - AbstractAction repair = new AbstractAction() - { - { - this.putValue(Action.NAME, LanguageResource.getString("REPAIR_STR")); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); - }; - - public void actionPerformed(ActionEvent arg0) - { - - board_handler.repair(); - design_panel.redraw(); - } - - }; - menu3D.add(repair); -*/ -/* - AbstractAction loadairbrush = new AbstractAction() - { - { - this.putValue(Action.NAME, "Load airbrush"); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); - }; - - public void actionPerformed(ActionEvent arg0) - { - - design_panel2.set_airbrush("airbrush.jpg"); - design_panel2.redraw(); - } - - }; - menu3D.add(loadairbrush); -*/ - - - - - - + /* + * + * AbstractAction repair = new AbstractAction() { { + * this.putValue(Action.NAME, LanguageResource.getString("REPAIR_STR")); + * // this.putValue(Action.ACCELERATOR_KEY, + * KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + * + * public void actionPerformed(ActionEvent arg0) { + * + * board_handler.repair(); design_panel.redraw(); } + * + * }; menu3D.add(repair); + */ + /* + * AbstractAction loadairbrush = new AbstractAction() { { + * this.putValue(Action.NAME, "Load airbrush"); // + * this.putValue(Action.ACCELERATOR_KEY, + * KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + * + * public void actionPerformed(ActionEvent arg0) { + * + * design_panel2.set_airbrush("airbrush.jpg"); design_panel2.redraw(); } + * + * }; menu3D.add(loadairbrush); + */ /* * AbstractAction settolerance = new AbstractAction() { { * this.putValue(Action.NAME, "Set tolerance"); // * this.putValue(Action.ACCELERATOR_KEY, * KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - * + * * public void actionPerformed(ActionEvent arg0) { String * s=(String)JOptionPane.showInputDialog(mFrame, "Set tolerance (mm)"); - * - * board_handler.set_tolerance(Double.parseDouble(s)); } - * }; menu3D.add(settolerance); - * + * + * board_handler.set_tolerance(Double.parseDouble(s)); } }; + * menu3D.add(settolerance); + * * AbstractAction setmaxiterations = new AbstractAction() { { * this.putValue(Action.NAME, "Set max iterations"); // * this.putValue(Action.ACCELERATOR_KEY, * KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; - * + * * public void actionPerformed(ActionEvent arg0) { String * s=(String)JOptionPane.showInputDialog(mFrame, "Max iterations"); - * - * board_handler.set_iterations(Integer.parseInt(s)); } - * }; menu3D.add(setmaxiterations); + * + * board_handler.set_iterations(Integer.parseInt(s)); } }; + * menu3D.add(setmaxiterations); */ - menuBar.add(menu3D); - - final JMenu menuRender = new JMenu(LanguageResource.getString("RENDERMENU_STR")); menuRender.setMnemonic(KeyEvent.VK_R); - final AbstractAction update3d = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("RENDER_STR")); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - if(board_handler.is_empty()) { + if (board_handler.is_empty()) { board_handler.approximate_bezier(getCurrentBrd(), false); } design_panel2.update_3d(); + design_panel3.update_3d(); } }; menuRender.add(update3d); - mShowRenderInwireframe = new JCheckBoxMenuItem( LanguageResource.getString("SHOWWIREFRAME_STR")); + mShowRenderInwireframe = new JCheckBoxMenuItem(LanguageResource.getString("SHOWWIREFRAME_STR")); mShowRenderInwireframe.setMnemonic(KeyEvent.VK_S); mShowRenderInwireframe.setSelected(false); - mShowRenderInwireframe.addItemListener(new ItemListener() - { - public void itemStateChanged(final ItemEvent e) - { + mShowRenderInwireframe.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(final ItemEvent e) { Appearance a = new Appearance(); PolygonAttributes pa = new PolygonAttributes(); - if(mShowRenderInwireframe.isSelected()) - { + if (mShowRenderInwireframe.isSelected()) { Color3f ambient = new Color3f(0.1f, 0.5f, 0.1f); Color3f emissive = new Color3f(0.0f, 0.0f, 0.0f); Color3f diffuse = new Color3f(0.1f, 1.0f, 0.1f); @@ -5026,11 +5536,10 @@ public void itemStateChanged(final ItemEvent e) a.setMaterial(new Material(ambient, emissive, diffuse, specular, 115.0f)); pa.setPolygonMode(PolygonAttributes.POLYGON_LINE); - pa.setCullFace(PolygonAttributes.CULL_BACK); // experiment with it + pa.setCullFace(PolygonAttributes.CULL_BACK); // experiment + // with it a.setPolygonAttributes(pa); - } - else - { + } else { Color3f ambient = new Color3f(0.4f, 0.4f, 0.45f); Color3f emissive = new Color3f(0.0f, 0.0f, 0.0f); Color3f diffuse = new Color3f(0.8f, 0.8f, 0.8f); @@ -5040,40 +5549,48 @@ public void itemStateChanged(final ItemEvent e) a.setMaterial(new Material(ambient, emissive, diffuse, specular, 115.0f)); pa.setPolygonMode(PolygonAttributes.POLYGON_FILL); - pa.setCullFace(PolygonAttributes.CULL_BACK); // experiment with it + pa.setCullFace(PolygonAttributes.CULL_BACK); // experiment + // with it a.setPolygonAttributes(pa); } - if(mBezier3DModel != null) - { - mBezier3DModel.setAppearance(a); + if (design_panel2.getBezier3DModel() != null) { + design_panel2.getBezier3DModel().setAppearance(a); + } + + if (design_panel3.getBezier3DModel() != null) { + design_panel3.getBezier3DModel().setAppearance(a); } - if(design_panel2.getShape() != null) - { + if (design_panel2.getShape() != null) { design_panel2.getShape().setAppearance(a); } + if (design_panel3.getShape() != null) { + design_panel3.getShape().setAppearance(a); + } + } }); menuRender.add(mShowRenderInwireframe); - final AbstractAction loadairbrush = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, "Load airbrush"); -// this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK)); + // this.putValue(Action.ACCELERATOR_KEY, + // KeyStroke.getKeyStroke(KeyEvent.VK_I, + // KeyEvent.CTRL_DOWN_MASK)); }; + @Override public void actionPerformed(ActionEvent arg0) { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - int returnVal = fc.showOpenDialog(BoardCAD.getInstance() - .getFrame()); + int returnVal = fc.showOpenDialog(BoardCAD.getInstance().getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; @@ -5089,74 +5606,68 @@ public void actionPerformed(ActionEvent arg0) { design_panel2.set_airbrush(filename); design_panel2.redraw(); -/* - BoardEdit edit = getSelectedEdit(); - if (edit == null) - return; + design_panel3.set_airbrush(filename); + design_panel3.redraw(); - edit.loadBackgroundImage(filename); - edit.repaint(); -*/ + /* + * BoardEdit edit = getSelectedEdit(); if (edit == null) return; + * + * edit.loadBackgroundImage(filename); edit.repaint(); + */ } }; menuRender.add(loadairbrush); - mShowBezier3DModelMenuItem = new JCheckBoxMenuItem( LanguageResource.getString("SHOWBEZIER3DMODEL_STR")); + mShowBezier3DModelMenuItem = new JCheckBoxMenuItem(LanguageResource.getString("SHOWBEZIER3DMODEL_STR")); mShowBezier3DModelMenuItem.setMnemonic(KeyEvent.VK_B); - mShowBezier3DModelMenuItem.setSelected(false); + mShowBezier3DModelMenuItem.setSelected(true); ActionListener showBezier3DListener = new ActionListener() { - public void actionPerformed(ActionEvent event) { - AbstractButton aButton = (AbstractButton) event.getSource(); - boolean selected = mShowBezier3DModelMenuItem.getModel().isSelected(); - if(mBezier3DOnSwitch != null) - { - mBezier3DOnSwitch.setWhichChild(selected?Switch.CHILD_ALL:Switch.CHILD_NONE); - if(selected && mBoardChangedFor3D && mTabbedPane.getSelectedComponent() == mRenderedpanel) - { - updateBezier3DModel(); - } - } - } + @Override + public void actionPerformed(ActionEvent event) { + boolean selected = mShowBezier3DModelMenuItem.getModel().isSelected(); + design_panel2.setShowBezierModel(selected); + design_panel3.setShowBezierModel(selected); + if (selected) { + updateBezier3DModel(); + } + } }; mShowBezier3DModelMenuItem.addActionListener(showBezier3DListener); menuRender.add(mShowBezier3DModelMenuItem); menuBar.add(menuRender); - scriptMenu = new JMenu("Script"); - scriptMenu.setMnemonic(KeyEvent.VK_P); - menuBar.add(scriptMenu); - final JMenu helpMenu = new JMenu(LanguageResource.getString("HELPMENU_STR")); helpMenu.setMnemonic(KeyEvent.VK_H); final AbstractAction onlineHelp = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("ONLINEHELP_STR")); - this.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/Help16.gif"))); + this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/Help16.gif"))); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { - BrowserControl - .displayURL("http://boardcad.org/index.php/Help:Contents"); + BrowserControl.displayURL("http://boardcad.org/index.php/Help:Contents"); } }; helpMenu.add(onlineHelp); final AbstractAction about = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("ABOUT_STR")); - this.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/Information16.gif"))); + this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/Information16.gif"))); // this.putValue(Action.ACCELERATOR_KEY, // KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { AboutBox box = new AboutBox(); box.setModal(true); @@ -5173,34 +5684,34 @@ public void actionPerformed(ActionEvent arg0) { mToolBar = new JToolBar(); - newBrd.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/new.png"))); + newBrd.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/new.png"))); mToolBar.add(newBrd); - loadBrd.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/open.png"))); + loadBrd.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/open.png"))); mToolBar.add(loadBrd); - saveBrd.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/save.png"))); + saveBrd.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/save.png"))); mToolBar.add(saveBrd); - SaveBrd.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/save-refresh.png"))); + SaveBrd.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/save-refresh.png"))); mToolBar.add(SaveBrd); - printSpecSheet.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/print.png"))); + printSpecSheet.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/print.png"))); mToolBar.add(printSpecSheet); mToolBar.addSeparator(); mToolBar.addSeparator(); - final SetCurrentOneShotCommandAction zoom = new SetCurrentOneShotCommandAction( - new BrdZoomCommand()); - zoom.putValue(AbstractAction.NAME, LanguageResource.getString("ZOOMBUTTON_STR")); - zoom.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("ZOOMBUTTON_STR")); - zoom.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/zoom-in.png"))); + final SetCurrentOneShotCommandAction zoom = new SetCurrentOneShotCommandAction(new BrdZoomCommand()); + zoom.putValue(Action.NAME, LanguageResource.getString("ZOOMBUTTON_STR")); + zoom.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("ZOOMBUTTON_STR")); + zoom.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/zoom-in.png"))); mToolBar.add(zoom); - final AbstractAction fit = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; + + @Override public void actionPerformed(ActionEvent event) { fitAll(); mLifeSizeButton.getModel().setPressed(false); @@ -5208,41 +5719,40 @@ public void actionPerformed(ActionEvent event) { } }; - fit.putValue(AbstractAction.NAME, LanguageResource.getString("FITBUTTON_STR")); - fit.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("FITBUTTON_STR")); - fit.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/zoom-fit-best.png"))); + fit.putValue(Action.NAME, LanguageResource.getString("FITBUTTON_STR")); + fit.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("FITBUTTON_STR")); + fit.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/zoom-fit-best.png"))); mToolBar.add(fit); popupMenu.add(fit); mLifeSizeButton = new JToggleButton(); mLifeSizeButton.setIcon(new ImageIcon(getClass().getResource("../../icons/zoom-1to1.png"))); - mLifeSizeButton.addMouseListener(new MouseAdapter(){ - public void mouseClicked(MouseEvent e){ - if(e.getID() == MouseEvent.MOUSE_CLICKED && e.getButton() == MouseEvent.BUTTON3) - { - BoardEdit edit = getSelectedEdit(); - if(edit != null) - { - edit.setCurrentAsLifeSizeScale(); - } - } - } + mLifeSizeButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getButton() == MouseEvent.BUTTON3) { + BoardEdit edit = getSelectedEdit(); + if (edit != null) { + edit.setCurrentAsLifeSizeScale(); + } + } + } }); final ChangeListener lifeSizeChangeListner = new ChangeListener() { + @Override public void stateChanged(ChangeEvent e) { boolean isLifeSize = mLifeSizeButton.isSelected(); BoardEdit edit = getSelectedEdit(); - if(edit != null) - { - if(edit.isLifeSize() == isLifeSize) + if (edit != null) { + if (edit.isLifeSize() == isLifeSize) return; edit.setLifeSize(isLifeSize); - if(!isLifeSize) + if (!isLifeSize) edit.resetToPreviousScale(); edit.repaint(); @@ -5252,8 +5762,10 @@ public void stateChanged(ChangeEvent e) { }; mLifeSizeButton.addChangeListener(lifeSizeChangeListner); -// lifeSize.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("LIFESIZEBUTTON_STR")); -// lifeSize.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/zoom-fit-best.png"))); + // lifeSize.putValue(AbstractAction.SHORT_DESCRIPTION, + // LanguageResource.getString("LIFESIZEBUTTON_STR")); + // lifeSize.putValue(AbstractAction.SMALL_ICON, new + // ImageIcon(getClass().getResource("../../icons/zoom-fit-best.png"))); mToolBar.add(mLifeSizeButton); mToolBar.addSeparator(); @@ -5261,32 +5773,27 @@ public void stateChanged(ChangeEvent e) { board_handler = new BoardHandler(); - final SetCurrentCommandAction edit = new SetCurrentCommandAction( - new BrdEditCommand()); - edit.putValue(AbstractAction.NAME, LanguageResource.getString("EDITBUTTON_STR")); - edit.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("EDITBUTTON_STR")); - edit.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/BoardCADedit24.gif"))); + final SetCurrentCommandAction edit = new SetCurrentCommandAction(new BrdEditCommand()); + edit.putValue(Action.NAME, LanguageResource.getString("EDITBUTTON_STR")); + edit.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("EDITBUTTON_STR")); + edit.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/BoardCADedit24.gif"))); mToolBar.add(edit); -// popupMenu.add(edit); + // popupMenu.add(edit); + // JButton bt = new JButton(new ImageIcon("../../icons/Zoom24.gif")); + // mToolBar.add(bt); -// JButton bt = new JButton(new ImageIcon("../../icons/Zoom24.gif")); -// mToolBar.add(bt); - - final SetCurrentCommandAction pan = new SetCurrentCommandAction( - new BrdPanCommand()); - pan.putValue(AbstractAction.NAME, LanguageResource.getString("PANBUTTON_STR")); - pan.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("PANBUTTON_STR")); - pan.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/BoardCADpan24.gif"))); + final SetCurrentCommandAction pan = new SetCurrentCommandAction(new BrdPanCommand()); + pan.putValue(Action.NAME, LanguageResource.getString("PANBUTTON_STR")); + pan.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("PANBUTTON_STR")); + pan.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/BoardCADpan24.gif"))); mToolBar.add(pan); - - final SetCurrentCommandAction rotate_view = new SetCurrentCommandAction( - new BrdRotateViewCommand()); - rotate_view.putValue(AbstractAction.NAME, LanguageResource.getString("ROTATEVIEWBUTTON_STR")); - rotate_view.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("ROTATEVIEWBUTTON_STR")); - rotate_view.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/BoardCADrotateview24.gif"))); + final SetCurrentCommandAction rotate_view = new SetCurrentCommandAction(new BrdRotateViewCommand()); + rotate_view.putValue(Action.NAME, LanguageResource.getString("ROTATEVIEWBUTTON_STR")); + rotate_view.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("ROTATEVIEWBUTTON_STR")); + rotate_view.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/BoardCADrotateview24.gif"))); mToolBar.add(rotate_view); @@ -5326,10 +5833,8 @@ public void stateChanged(ChangeEvent e) { mViewBottomCut.addItemListener(this); popupMenu.add(mViewBottomCut); - popupMenu.addSeparator(); - final JButton spotCheck = new JButton(); final JButton spotCheck2 = new JButton(); @@ -5341,6 +5846,7 @@ public void stateChanged(ChangeEvent e) { boolean mIsSpotChecking = false; + @Override public void stateChanged(ChangeEvent e) { ButtonModel model = ((JButton) e.getSource()).getModel(); if (model.isPressed()) { @@ -5357,7 +5863,7 @@ public void stateChanged(ChangeEvent e) { spotCheck.addChangeListener(spotCheckChangeListner); spotCheck2.addChangeListener(spotCheckChangeListner); -// mToolBar.add(spotCheck); + // mToolBar.add(spotCheck); popupMenu.add(spotCheck2); mToolBar.add(undo); @@ -5365,63 +5871,55 @@ public void stateChanged(ChangeEvent e) { mToolBar.addSeparator(); - final SetCurrentCommandAction toggleDeckAndBottom = new SetCurrentCommandAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; + + @Override public void actionPerformed(ActionEvent event) { toggleBottomAndDeck(); } }; - toggleDeckAndBottom.putValue(AbstractAction.NAME, LanguageResource.getString("TOGGLEDECKBOTTOMBUTTON_STR")); - toggleDeckAndBottom.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("TOGGLEDECKBOTTOMBUTTON_STR")); - toggleDeckAndBottom.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/BoardCADtoggle24x35.png"))); + toggleDeckAndBottom.putValue(Action.NAME, LanguageResource.getString("TOGGLEDECKBOTTOMBUTTON_STR")); + toggleDeckAndBottom.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("TOGGLEDECKBOTTOMBUTTON_STR")); + toggleDeckAndBottom.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/BoardCADtoggle24x35.png"))); mToolBar.add(toggleDeckAndBottom); popupMenu.add(toggleDeckAndBottom); - - mToolBar.addSeparator(); - final SetCurrentCommandAction addGuidePoint = new SetCurrentCommandAction( - new BrdAddGuidePointCommand()); - addGuidePoint.putValue(AbstractAction.NAME, LanguageResource.getString("ADDGUIDEPOINTBUTTON_STR")); - addGuidePoint.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("ADDGUIDEPOINTBUTTON_STR")); - addGuidePoint.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/add-guidepoint.png"))); + final SetCurrentCommandAction addGuidePoint = new SetCurrentCommandAction(new BrdAddGuidePointCommand()); + addGuidePoint.putValue(Action.NAME, LanguageResource.getString("ADDGUIDEPOINTBUTTON_STR")); + addGuidePoint.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("ADDGUIDEPOINTBUTTON_STR")); + addGuidePoint.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/add-guidepoint.png"))); mToolBar.add(addGuidePoint); popupMenu.add(addGuidePoint); popupMenu.add(guidePoints); - final SetCurrentCommandAction addControlPoint = new SetCurrentOneShotCommandAction( - new BrdAddControlPointCommand()); - addControlPoint.putValue(AbstractAction.NAME, LanguageResource.getString("ADDCONTROLPOINTBUTTON_STR")); - addControlPoint.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("ADDCONTROLPOINTBUTTON_STR")); - addControlPoint.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/add-controlpoint.png"))); + final SetCurrentCommandAction addControlPoint = new SetCurrentOneShotCommandAction(new BrdAddControlPointCommand()); + addControlPoint.putValue(Action.NAME, LanguageResource.getString("ADDCONTROLPOINTBUTTON_STR")); + addControlPoint.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("ADDCONTROLPOINTBUTTON_STR")); + addControlPoint.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/add-controlpoint.png"))); mToolBar.add(addControlPoint); popupMenu.add(addControlPoint); final SetCurrentCommandAction deleteControlPoint = new SetCurrentCommandAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; + + @Override public void actionPerformed(ActionEvent event) { BoardEdit edit = getSelectedEdit(); - if(edit == null) + if (edit == null) return; - ArrayList selectedControlPoints = edit - .getSelectedControlPoints(); + ArrayList selectedControlPoints = edit.getSelectedControlPoints(); if (selectedControlPoints.size() == 0) { - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), LanguageResource.getString("NOCONTROLPOINTSELECTEDMSG_STR"), - LanguageResource.getString("NOCONTROLPOINTSELECTEDTITLE_STR"), JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), LanguageResource.getString("NOCONTROLPOINTSELECTEDMSG_STR"), LanguageResource.getString("NOCONTROLPOINTSELECTEDTITLE_STR"), JOptionPane.WARNING_MESSAGE); return; } - int selection = JOptionPane.showConfirmDialog( - BoardCAD.getInstance().getFrame(), - LanguageResource.getString("DELETECONTROLPOINTSMSG_STR"), - LanguageResource.getString("DELETECONTROLPOINTSTITLE_STR"), JOptionPane.WARNING_MESSAGE, - JOptionPane.YES_NO_OPTION); + int selection = JOptionPane.showConfirmDialog(BoardCAD.getInstance().getFrame(), LanguageResource.getString("DELETECONTROLPOINTSMSG_STR"), LanguageResource.getString("DELETECONTROLPOINTSTITLE_STR"), JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION); if (selection == JOptionPane.NO_OPTION) { @@ -5431,22 +5929,17 @@ public void actionPerformed(ActionEvent event) { BrdMacroCommand macroCmd = new BrdMacroCommand(); macroCmd.setSource(edit); - BezierSpline[] splines = edit.getActiveBezierSplines(edit - .getCurrentBrd()); + BezierSpline[] splines = edit.getActiveBezierSplines(edit.getCurrentBrd()); - for(int j=0; j < splines.length; j++) - { + for (int j = 0; j < splines.length; j++) { for (int i = 0; i < selectedControlPoints.size(); i++) { BezierKnot ControlPoint = selectedControlPoints.get(i); - if (ControlPoint == splines[j].getControlPoint(0) - || ControlPoint == splines[j].getControlPoint(splines[j] - .getNrOfControlPoints() - 1)) { + if (ControlPoint == splines[j].getControlPoint(0) || ControlPoint == splines[j].getControlPoint(splines[j].getNrOfControlPoints() - 1)) { continue; } - BrdDeleteControlPointCommand deleteControlPointCommand = new BrdDeleteControlPointCommand( - edit, ControlPoint, splines[j]); + BrdDeleteControlPointCommand deleteControlPointCommand = new BrdDeleteControlPointCommand(edit, ControlPoint, splines[j]); macroCmd.add(deleteControlPointCommand); @@ -5459,95 +5952,112 @@ public void actionPerformed(ActionEvent event) { } }; - deleteControlPoint.putValue(AbstractAction.NAME, LanguageResource.getString("DELETECONTROLPOINTSBUTTON_STR")); - deleteControlPoint.putValue(AbstractAction.SHORT_DESCRIPTION, LanguageResource.getString("DELETECONTROLPOINTSBUTTON_STR")); - deleteControlPoint.putValue(AbstractAction.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/remove-controlpoint.png"))); + deleteControlPoint.putValue(Action.NAME, LanguageResource.getString("DELETECONTROLPOINTSBUTTON_STR")); + deleteControlPoint.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("DELETECONTROLPOINTSBUTTON_STR")); + deleteControlPoint.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../../icons/remove-controlpoint.png"))); mToolBar.add(deleteControlPoint); popupMenu.add(deleteControlPoint); - mToolBar.addSeparator(); -/* - final JRadioButton millimeterButton = new JRadioButton(LanguageResource.getString("MILLIMETERSRADIOBUTTON_STR")); - millimeterButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setCurrentUnit(UnitUtils.MILLIMETERS); - } - }); - final JRadioButton imperialButton = new JRadioButton(LanguageResource.getString("FEETINCHESRADIOBUTTON_STR")); - imperialButton.setSelected(true); - imperialButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setCurrentUnit(UnitUtils.INCHES); - } - }); - final JRadioButton imperialDecimalButton = new JRadioButton(LanguageResource.getString("DECIMALFEETINCHESRADIOBUTTON_STR")); - imperialDecimalButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setCurrentUnit(UnitUtils.INCHES_DECIMAL); - } - }); - final JRadioButton centimeterButton = new JRadioButton(LanguageResource.getString("CENTIMETERSRADIOBUTTON_STR")); - centimeterButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - setCurrentUnit(UnitUtils.CENTIMETERS); - } - }); + popupMenu.addSeparator(); + final SetCurrentCommandAction fitCurveCmd = new SetCurrentCommandAction() { + static final long serialVersionUID = 1L; + + @Override + public void actionPerformed(ActionEvent event) { + + BoardEdit edit = getSelectedEdit(); + if (edit == null) + return; + + BrdFitCurveCommand cmd = new BrdFitCurveCommand(); + cmd.execute(); + }; + + }; + fitCurveCmd.putValue(Action.NAME, LanguageResource.getString("FITCONTROLPOINTS_STR")); + fitCurveCmd.putValue(Action.SHORT_DESCRIPTION, LanguageResource.getString("FITCONTROLPOINTS_STR")); + // addControlPoint.putValue(AbstractAction.SMALL_ICON, new ImageIcon( + // getClass().getResource("../../icons/add-controlpoint.png"))); + // mToolBar.add(fitCurveCmd); + popupMenu.add(fitCurveCmd); - final ButtonGroup unitButtonGroup = new ButtonGroup(); - unitButtonGroup.add(imperialButton); - unitButtonGroup.add(millimeterButton); - unitButtonGroup.add(centimeterButton); - unitButtonGroup.add(imperialDecimalButton); - mToolBar.add(imperialButton); - //mToolBar.addSeparator(); - mToolBar.add(millimeterButton); - //mToolBar.addSeparator(); - mToolBar.add(centimeterButton); - //mToolBar.addSeparator(); - mToolBar.add(imperialDecimalButton); -*/ + popupMenu.addSeparator(); + + mToolBar.addSeparator(); + /* + * final JRadioButton millimeterButton = new + * JRadioButton(LanguageResource + * .getString("MILLIMETERSRADIOBUTTON_STR")); + * millimeterButton.addActionListener(new ActionListener() { public void + * actionPerformed(final ActionEvent e) { + * setCurrentUnit(UnitUtils.MILLIMETERS); } }); final JRadioButton + * imperialButton = new + * JRadioButton(LanguageResource.getString("FEETINCHESRADIOBUTTON_STR" + * )); imperialButton.setSelected(true); + * imperialButton.addActionListener(new ActionListener() { public void + * actionPerformed(final ActionEvent e) { + * setCurrentUnit(UnitUtils.INCHES); } }); final JRadioButton + * imperialDecimalButton = new JRadioButton(LanguageResource.getString( + * "DECIMALFEETINCHESRADIOBUTTON_STR")); + * imperialDecimalButton.addActionListener(new ActionListener() { public + * void actionPerformed(final ActionEvent e) { + * setCurrentUnit(UnitUtils.INCHES_DECIMAL); } }); final JRadioButton + * centimeterButton = new + * JRadioButton(LanguageResource.getString("CENTIMETERSRADIOBUTTON_STR" + * )); centimeterButton.addActionListener(new ActionListener() { public + * void actionPerformed(final ActionEvent e) { + * setCurrentUnit(UnitUtils.CENTIMETERS); } }); + * + * final ButtonGroup unitButtonGroup = new ButtonGroup(); + * unitButtonGroup.add(imperialButton); + * unitButtonGroup.add(millimeterButton); + * unitButtonGroup.add(centimeterButton); + * unitButtonGroup.add(imperialDecimalButton); + * mToolBar.add(imperialButton); //mToolBar.addSeparator(); + * mToolBar.add(millimeterButton); //mToolBar.addSeparator(); + * mToolBar.add(centimeterButton); //mToolBar.addSeparator(); + * mToolBar.add(imperialDecimalButton); + */ JLabel unitLabel = new JLabel(LanguageResource.getString("UNIT_STR")); + unitLabel.setForeground(getTextColor()); mToolBar.add(unitLabel); - - String[] unitsStrList = new String[]{LanguageResource.getString("FEETINCHESRADIOBUTTON_STR"), - LanguageResource.getString("DECIMALFEETINCHESRADIOBUTTON_STR"), - LanguageResource.getString("MILLIMETERSRADIOBUTTON_STR"), - LanguageResource.getString("CENTIMETERSRADIOBUTTON_STR"), - LanguageResource.getString("METERSRADIOBUTTON_STR") - }; + + String[] unitsStrList = new String[] { LanguageResource.getString("FEETINCHESRADIOBUTTON_STR"), LanguageResource.getString("DECIMALFEETINCHESRADIOBUTTON_STR"), LanguageResource.getString("MILLIMETERSRADIOBUTTON_STR"), LanguageResource.getString("CENTIMETERSRADIOBUTTON_STR"), + LanguageResource.getString("METERSRADIOBUTTON_STR") }; JComboBox unitComboBox = new JComboBox(unitsStrList); + unitComboBox.setForeground(getTextColor()); unitComboBox.setEditable(false); unitComboBox.addActionListener(new ActionListener() { + @Override public void actionPerformed(final ActionEvent e) { - JComboBox cb = (JComboBox)e.getSource(); - switch(cb.getSelectedIndex()) - { - default: - case 0: - setCurrentUnit(UnitUtils.INCHES); - break; - case 1: - setCurrentUnit(UnitUtils.INCHES_DECIMAL); - break; - case 2: - setCurrentUnit(UnitUtils.MILLIMETERS); - break; - case 3: - setCurrentUnit(UnitUtils.CENTIMETERS); - break; - case 4: - setCurrentUnit(UnitUtils.METERS); - break; - } + JComboBox cb = (JComboBox) e.getSource(); + unitComboBox.setForeground(getTextColor()); + switch (cb.getSelectedIndex()) { + default: + case 0: + setCurrentUnit(UnitUtils.INCHES); + break; + case 1: + setCurrentUnit(UnitUtils.INCHES_DECIMAL); + break; + case 2: + setCurrentUnit(UnitUtils.MILLIMETERS); + break; + case 3: + setCurrentUnit(UnitUtils.CENTIMETERS); + break; + case 4: + setCurrentUnit(UnitUtils.METERS); + break; + } } }); - mToolBar.addSeparator(new Dimension(5,0)); + mToolBar.addSeparator(new Dimension(5, 0)); mToolBar.add(unitComboBox); unitComboBox.setMaximumSize(new Dimension(140, 30)); mFrame.getContentPane().add(mToolBar, BorderLayout.NORTH); - final JMenu crossSectionsForPopupMenu = new JMenu(LanguageResource.getString("CROSSECTIONSMENU_STR")); crossSectionsForPopupMenu.add(mNextCrossSection); crossSectionsForPopupMenu.add(mPreviousCrossSection); @@ -5558,57 +6068,53 @@ public void actionPerformed(final ActionEvent e) { crossSectionsForPopupMenu.add(pasteCrossSection); popupMenu.add(crossSectionsForPopupMenu); - - - mTabbedPane = new JTabbedPane(); - - fourView=new QuadView(); - view1 = new BoardEdit() - { - static final long serialVersionUID=1L; + fourView = new QuadView(); + + view1 = new BoardEdit() { + static final long serialVersionUID = 1L; { setPreferredSize(new Dimension(300, 200)); mDrawControl = BezierBoardDrawUtil.MirrorY; } + @Override public BezierSpline[] getActiveBezierSplines(final BezierBoard brd) { - return new BezierSpline[]{brd.getOutline()}; + return new BezierSpline[] { brd.getOutline() }; } + @Override public ArrayList getGuidePoints() { - return BoardCAD.getInstance().getCurrentBrd() - .getOutlineGuidePoints(); + return BoardCAD.getInstance().getCurrentBrd().getOutlineGuidePoints(); } - public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, - final BezierBoard brd, boolean fill) { + @Override + public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd, boolean fill) { super.drawPart(g, color, stroke, brd, fill); - if(isPaintingCenterLine()) - { - drawCenterLine(g, getCenterLineColor(), stroke, brd.getLength()/2.0, brd.getCenterWidth()*1.1); + if (isPaintingCenterLine()) { + drawCenterLine(g, getCenterLineColor(), stroke, brd.getLength() / 2.0, brd.getCenterWidth() * 1.1); } - if(isPaintingCrossectionsPositions()) - drawOutlineCrossections(this,g,color,stroke,brd); - if(isPaintingFlowlines()) - drawOutlineFlowlines(this,g,getFlowLinesColor(),stroke,brd); - if(isPaintingTuckUnderLine()) - drawOutlineTuckUnderLine(this,g,getTuckUnderLineColor(),stroke,brd); - if(isPaintingFootMarks() && (brd == getCurrentBrd() || (brd == getGhostBrd() && isGhostMode()) || (brd == getOriginalBrd() && isOrgFocus()))) - drawOutlineFootMarks(this,g,new BasicStroke(2.0f/(float)this.mScale),brd); - drawStringer(g, getStringerColor(), - stroke, brd); + if (isPaintingCrossectionsPositions()) + drawOutlineCrossections(this, g, color, stroke, brd); + if (isPaintingFlowlines()) + drawOutlineFlowlines(this, g, getFlowLinesColor(), stroke, brd); + if (isPaintingTuckUnderLine()) + drawOutlineTuckUnderLine(this, g, getTuckUnderLineColor(), stroke, brd); + if (isPaintingFootMarks() && (brd == getCurrentBrd() || (brd == getGhostBrd() && isGhostMode()) || (brd == getOriginalBrd() && isOrgFocus()))) + drawOutlineFootMarks(this, g, new BasicStroke(2.0f / (float) this.mScale), brd); + drawStringer(g, getStringerColor(), stroke, brd); if (isPaintingFins()) { drawFins(g, getFinsColor(), stroke, brd); } } - public void drawSlidingInfo(final Graphics2D g, final Color color, - final Stroke stroke, final BezierBoard brd) { + @Override + public void drawSlidingInfo(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { drawOutlineSlidingInfo(this, g, color, stroke, brd); } + @Override public void onBrdChanged() { getCurrentBrd().onOutlineChanged(); @@ -5616,28 +6122,25 @@ public void onBrdChanged() { view2.repaint(); } + @Override public void mousePressed(final MouseEvent e) { super.mousePressed(e); - if(mSelectedControlPoints.size() == 0) - { + if (mSelectedControlPoints.size() == 0) { final Point pos = e.getPoint(); final Point2D.Double brdPos = screenCoordinateToBrdCoordinate(pos); final int index = getCurrentBrd().getNearestCrossSectionIndex(brdPos.x); double tolerance = 5.0; - if (index != -1 && Math.abs(getCurrentBrd().getCrossSections().get(index).getPosition() - brdPos.x) < tolerance) - { + if (index != -1 && Math.abs(getCurrentBrd().getCrossSections().get(index).getPosition() - brdPos.x) < tolerance) { getCurrentBrd().setCurrentCrossSection(index); } - if(getOriginalBrd() != null) - { + if (getOriginalBrd() != null) { final int indexOriginal = getOriginalBrd().getNearestCrossSectionIndex(brdPos.x); if (indexOriginal != -1 && Math.abs(getOriginalBrd().getCrossSections().get(indexOriginal).getPosition() - brdPos.x) < tolerance) { getOriginalBrd().setCurrentCrossSection(indexOriginal); } } - if(getGhostBrd() != null) - { + if (getGhostBrd() != null) { final int indexGhost = getGhostBrd().getNearestCrossSectionIndex(brdPos.x); if (indexGhost != -1 && Math.abs(getGhostBrd().getCrossSections().get(indexGhost).getPosition() - brdPos.x) < tolerance) { getGhostBrd().setCurrentCrossSection(indexGhost); @@ -5648,6 +6151,7 @@ public void mousePressed(final MouseEvent e) { } + @Override public void mouseMoved(final MouseEvent e) { super.mouseMoved(e); @@ -5657,43 +6161,44 @@ public void mouseMoved(final MouseEvent e) { }; view1.add(popupMenu); - view2 = new BoardEdit() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { + mIsCrossSectionEdit = true; setPreferredSize(new Dimension(300, 200)); mDrawControl = BezierBoardDrawUtil.MirrorX | BezierBoardDrawUtil.FlipY; mCurvatureScale = 25; } + @Override public BezierSpline[] getActiveBezierSplines(final BezierBoard brd) { final BezierBoardCrossSection currentCrossSection = brd.getCurrentCrossSection(); if (currentCrossSection == null) return null; - return new BezierSpline[]{brd.getCurrentCrossSection().getBezierSpline()}; + return new BezierSpline[] { brd.getCurrentCrossSection().getBezierSpline() }; } + @Override public ArrayList getGuidePoints() { - final BezierBoardCrossSection currentCrossSection = BoardCAD.getInstance() - .getCurrentBrd().getCurrentCrossSection(); + final BezierBoardCrossSection currentCrossSection = BoardCAD.getInstance().getCurrentBrd().getCurrentCrossSection(); if (currentCrossSection == null) return null; return currentCrossSection.getGuidePoints(); } - protected boolean isPaintingVolumeDistribution() - { + @Override + protected boolean isPaintingVolumeDistribution() { return false; } - public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, - final BezierBoard brd, boolean fill) { + @Override + public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd, boolean fill) { - if(brd.isEmpty()) + if (brd.isEmpty()) return; if (isPaintingNonActiveCrossSections()) { @@ -5702,141 +6207,124 @@ public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, final BasicStroke bs = (BasicStroke) stroke; final float[] dashPattern = new float[] { 0.8f, 0.2f }; - final BasicStroke stapled = new BasicStroke((float) (bs - .getLineWidth() / 2.0), bs.getEndCap(), bs - .getLineJoin(), bs.getMiterLimit(), dashPattern, 0f); + final BasicStroke stapled = new BasicStroke((float) (bs.getLineWidth() / 2.0), bs.getEndCap(), bs.getLineJoin(), bs.getMiterLimit(), dashPattern, 0f); final Color noneActiveColor = color.brighter(); double currentCrossSectionRocker = brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition()); JavaDraw d = new JavaDraw(g); for (int i = 0; i < crossSections.size(); i++) { - if (crossSections.get(i) != brd - .getCurrentCrossSection()) { + if (crossSections.get(i) != brd.getCurrentCrossSection()) { double rockerOffset = 0; - if(BoardCAD.getInstance().isUsingOffsetInterpolation()) - { + if (BoardCAD.getInstance().isUsingOffsetInterpolation()) { rockerOffset = brd.getRockerAtPos(crossSections.get(i).getPosition()) - currentCrossSectionRocker; rockerOffset *= this.mScale; } - BezierBoardDrawUtil.paintBezierSpline(d, mOffsetX, mOffsetY-rockerOffset, - mScale, noneActiveColor, stapled, - crossSections.get(i).getBezierSpline(), - mDrawControl, fill); + BezierBoardDrawUtil.paintBezierSpline(d, mOffsetX, mOffsetY - rockerOffset, mScale, 0.0, noneActiveColor, stapled, crossSections.get(i).getBezierSpline(), mDrawControl, fill); } } } - + if (isPaintingSlidingCrossSection()) { final Color col = (isGhostMode()) ? color : Color.GRAY; - double pos = view3.hasMouse()?view3.mBrdCoord.x:view1.mBrdCoord.x; + double pos = view3.hasMouse() ? view3.mBrdCoord.x : view1.mBrdCoord.x; double rockerOffset = 0; - if(BoardCAD.getInstance().isUsingOffsetInterpolation()) - { + if (BoardCAD.getInstance().isUsingOffsetInterpolation()) { double currentCrossSectionRocker = brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition()); rockerOffset = brd.getRockerAtPos(pos) - currentCrossSectionRocker; rockerOffset *= this.mScale; } + // DEBUG System.out.printf("rockerOffset: %f\n", + // rockerOffset); -//DEBUG System.out.printf("rockerOffset: %f\n", rockerOffset); - - BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g), mOffsetX, mOffsetY-rockerOffset, - 0.0, mScale, col, stroke, - (mDrawControl & BezierBoardDrawUtil.FlipX) != 0, - (mDrawControl & BezierBoardDrawUtil.FlipY) != 0, - pos, brd); + BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g), mOffsetX, mOffsetY - rockerOffset, mScale, 0.0, col, stroke, (mDrawControl & BezierBoardDrawUtil.FlipX) != 0, (mDrawControl & BezierBoardDrawUtil.FlipY) != 0, pos, brd); if (isGhostMode()) { - if(BoardCAD.getInstance().isUsingOffsetInterpolation()) - { + if (BoardCAD.getInstance().isUsingOffsetInterpolation()) { double currentCrossSectionRocker = getCurrentBrd().getRockerAtPos(getCurrentBrd().getCurrentCrossSection().getPosition()); rockerOffset = getCurrentBrd().getRockerAtPos(pos) - currentCrossSectionRocker; rockerOffset *= this.mScale; } - BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g), mOffsetX, - mOffsetY-rockerOffset, 0.0, mScale, getGhostBrdColor(), stroke, - (mDrawControl & BezierBoardDrawUtil.FlipX) != 0, - (mDrawControl & BezierBoardDrawUtil.FlipY) != 0, - pos, - getCurrentBrd()); + BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g), mOffsetX, mOffsetY - rockerOffset, mScale, 0.0, getGhostBrdColor(), stroke, (mDrawControl & BezierBoardDrawUtil.FlipX) != 0, (mDrawControl & BezierBoardDrawUtil.FlipY) != 0, pos, getCurrentBrd()); } } super.drawPart(g, color, stroke, brd, fill); - if(isPaintingCenterLine()) + if (isPaintingCenterLine()) drawCrossSectionCenterline(this, g, getCenterLineColor(), stroke, brd); - if(isPaintingTuckUnderLine()) + if (isPaintingTuckUnderLine()) drawCrossSectionTuckUnderLine(this, g, getTuckUnderLineColor(), stroke, brd); - if(isPaintingFlowlines()) + if (isPaintingFlowlines()) drawCrossSectionFlowlines(this, g, getFlowLinesColor(), stroke, brd); - if(isPaintingApexline()) + if (isPaintingApexline()) drawCrossSectionApexline(this, g, getApexLineColor(), stroke, brd); } - - public void drawBrdCoordinate(Graphics2D g) - { + + @Override + public void drawBrdCoordinate(Graphics2D g) { super.drawBrdCoordinate(g); BezierBoard brd = getCurrentBrd(); - if(brd.isEmpty()) + if (brd.isEmpty()) return; - + BezierBoardCrossSection crs = brd.getCurrentCrossSection(); - if(crs == null) + if (crs == null) return; - + g.setColor(Color.BLACK); - // get metrics from the graphics + // get metrics from the graphics FontMetrics metrics = g.getFontMetrics(mBrdCoordFont); - - // get the height of a line of text in this font and render context + + // get the height of a line of text in this font and render + // context int hgt = metrics.getHeight(); - String posStr = LanguageResource.getString("CROSSECTIONPOS_STR") + UnitUtils.convertLengthToCurrentUnit(mBoardSpec.isOverCurveSelected()?brd.getBottom().getLengthByX(crs.getPosition()):crs.getPosition(), false) + (mBoardSpec.isOverCurveSelected()?" O.C":""); + String posStr = LanguageResource.getString("CROSSECTIONPOS_STR") + UnitUtils.convertLengthToCurrentUnit(mBoardSpec.isOverCurveSelected() ? brd.getBottom().getLengthByX(crs.getPosition()) : crs.getPosition(), false) + (mBoardSpec.isOverCurveSelected() ? " O.C" : ""); - g.drawString(posStr, 10, hgt*3); + g.drawString(posStr, 10, hgt * 3); - // get the height of a line of text in this font and render context + // get the height of a line of text in this font and render + // context - String widthStr = LanguageResource.getString("CROSSECTIONWIDTH_STR") + UnitUtils.convertLengthToCurrentUnit(crs.getWidth(), false) ; + String widthStr = LanguageResource.getString("CROSSECTIONWIDTH_STR") + UnitUtils.convertLengthToCurrentUnit(crs.getWidth(), false); + + g.drawString(widthStr, 10, hgt * 4); - g.drawString(widthStr, 10, hgt*4); - final Dimension dim = getSize(); - - String releaseAngleStr = LanguageResource.getString("RELEASEANGLE_STR") + String.format("%1$.1f degrees", crs.getReleaseAngle()/MathUtils.DEG_TO_RAD); + + String releaseAngleStr = LanguageResource.getString("RELEASEANGLE_STR") + String.format("%1$.1f degrees", crs.getReleaseAngle() / MathUtils.DEG_TO_RAD); final int releaseAngleStrLength = metrics.stringWidth(releaseAngleStr); - g.drawString(releaseAngleStr, dim.width - releaseAngleStrLength - 10, hgt*1); + g.drawString(releaseAngleStr, dim.width - releaseAngleStrLength - 10, hgt * 1); - String tuckUnderRadiusStr = LanguageResource.getString("TUCKRADIUS_STR") + UnitUtils.convertLengthToCurrentUnit(crs.getTuckRadius(),false); + String tuckUnderRadiusStr = LanguageResource.getString("TUCKRADIUS_STR") + UnitUtils.convertLengthToCurrentUnit(crs.getTuckRadius(), false); final int tuckUnderRadiusStrLength = metrics.stringWidth(tuckUnderRadiusStr); - g.drawString(tuckUnderRadiusStr, dim.width - tuckUnderRadiusStrLength - 10, hgt*2); + g.drawString(tuckUnderRadiusStr, dim.width - tuckUnderRadiusStrLength - 10, hgt * 2); } - - public void drawSlidingInfo(final Graphics2D g, final Color color, - final Stroke stroke, final BezierBoard brd) { - + + @Override + public void drawSlidingInfo(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { + if (brd.getCrossSections().size() == 0) return; - this.setName("QuadViewCrossSection"); if (brd.getCurrentCrossSection() == null) @@ -5863,8 +6351,7 @@ public void drawSlidingInfo(final Graphics2D g, final Color color, final Dimension dim = getSize(); String thicknessStr = LanguageResource.getString("CROSSECTIONSLIDINGINFOTHICKNESS_STR"); - mSlidingInfoString = thicknessStr - + UnitUtils.convertLengthToCurrentUnit(thickness, false) + String.format("(%02d%%)", (int)((thickness*100)/centerThickness)); + mSlidingInfoString = thicknessStr + UnitUtils.convertLengthToCurrentUnit(thickness, false) + String.format("(%02d%%)", (int) ((thickness * 100) / centerThickness)); g.setColor(Color.BLUE); @@ -5889,87 +6376,70 @@ public void drawSlidingInfo(final Graphics2D g, final Color color, if (textX + size.width + 10 > dim.width) textX = dim.width - size.width - 10; - g.setStroke(new BasicStroke((float) (1.0 / mScale))); - g.drawString(mSlidingInfoString, textX, dim.height - - (size.height * 2 + 5)); + g.drawString(mSlidingInfoString, textX, dim.height - (size.height * 2 + 5)); + mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOBOTTOM_STR") + UnitUtils.convertLengthToCurrentUnit(bottom, false); - mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOBOTTOM_STR") - + UnitUtils.convertLengthToCurrentUnit(bottom, false); - g.setColor(Color.RED); - g.drawString(mSlidingInfoString, textX, dim.height - - size.height); + g.drawString(mSlidingInfoString, textX, dim.height - size.height); g.setColor(Color.BLACK); final double fromCenter = Math.abs(mBrdCoord.x); - final double fromRail = crs.getWidth()/2 - Math.abs(mBrdCoord.x); - - - mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOFROMRAIL_STR") - + UnitUtils.convertLengthToCurrentUnit(fromRail, false); - + final double fromRail = crs.getWidth() / 2 - Math.abs(mBrdCoord.x); - g.drawString(mSlidingInfoString, textX, dim.height - - (size.height + 2) * 4); + mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOFROMRAIL_STR") + UnitUtils.convertLengthToCurrentUnit(fromRail, false); - mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOFROMCENTER_STR") - + UnitUtils.convertLengthToCurrentUnit(fromCenter, false); + g.drawString(mSlidingInfoString, textX, dim.height - (size.height + 2) * 4); + mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOFROMCENTER_STR") + UnitUtils.convertLengthToCurrentUnit(fromCenter, false); - g.drawString(mSlidingInfoString, textX, dim.height - - (size.height + 2) * 3); + g.drawString(mSlidingInfoString, textX, dim.height - (size.height + 2) * 3); - - //sets the color of the +ve sliding info (above Y base line) + // sets the color of the +ve sliding info (above Y base line) g.setColor(Color.BLUE); + final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0); - final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), - mOffsetX, mOffsetY, mScale); - - - mSlidingInfoLine.setLine(mBrdCoord.x * mulX, bottom * mulY, - mBrdCoord.x * mulX, (bottom + thickness) * mulY); + mSlidingInfoLine.setLine(mBrdCoord.x * mulX, bottom * mulY, mBrdCoord.x * mulX, (bottom + thickness) * mulY); g.draw(mSlidingInfoLine); - //sets the color of the Bottom sliding info (-ve# when concaved +ve# when Vee) + // sets the color of the Bottom sliding info (-ve# when concaved + // +ve# when Vee) g.setColor(Color.RED); - mSlidingInfoLine.setLine(mBrdCoord.x * mulX, 0 * mulY, - mBrdCoord.x * mulX, bottom * mulY); + mSlidingInfoLine.setLine(mBrdCoord.x * mulX, 0 * mulY, mBrdCoord.x * mulX, bottom * mulY); g.draw(mSlidingInfoLine); - g.setTransform(savedTransform); } + @Override public void fitBrd() { final BezierBoard brd = getCurrentBrd(); final Dimension dim = getSize(); - double width=board_handler.get_segment_width()/10; - if (width<10) - width=10; - - if (width getGuidePoints() - { - switch(mEditDeckorBottom) - { - case DECK: - return BoardCAD.getInstance().getCurrentBrd() - .getDeckGuidePoints(); - case BOTTOM: - return BoardCAD.getInstance().getCurrentBrd() - .getBottomGuidePoints(); - case BOTH: - default: - { - ArrayList list = new ArrayList(); - list.addAll(BoardCAD.getInstance().getCurrentBrd() - .getDeckGuidePoints()); - list.addAll(BoardCAD.getInstance().getCurrentBrd() - .getBottomGuidePoints()); - return list; - } + @Override + public ArrayList getGuidePoints() { + switch (mEditDeckorBottom) { + case DECK: + return BoardCAD.getInstance().getCurrentBrd().getDeckGuidePoints(); + case BOTTOM: + return BoardCAD.getInstance().getCurrentBrd().getBottomGuidePoints(); + case BOTH: + default: { + ArrayList list = new ArrayList(); + list.addAll(BoardCAD.getInstance().getCurrentBrd().getDeckGuidePoints()); + list.addAll(BoardCAD.getInstance().getCurrentBrd().getBottomGuidePoints()); + return list; + } } } - public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, - final BezierBoard brd, boolean fill) { - + @Override + public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd, boolean fill) { + if (isPaintingBaseLine()) { - drawStringer(g, mColorSettings.getColor(BASELINECOLOR), - new BasicStroke((float) (mSizeSettings.getDouble(BASELINETHICKNESS) / mScale)), - brd); + drawStringer(g, mColorSettings.getColor(BASELINECOLOR), new BasicStroke((float) (mSizeSettings.getDouble(BASELINETHICKNESS) / mScale)), brd); } - if(isPaintingFlowlines()) - drawProfileFlowlines(this,g,getFlowLinesColor(),stroke,brd); - if(isPaintingApexline()) - drawProfileApexline(this,g,getApexLineColor(),stroke,brd); - if(isPaintingTuckUnderLine()) - drawProfileTuckUnderLine(this,g,getTuckUnderLineColor(),stroke,brd); - if(isPaintingFootMarks() && (brd == getCurrentBrd() || (brd == getGhostBrd() && isGhostMode()) || (brd == getOriginalBrd() && isOrgFocus()))) - drawProfileFootMarks(this,g,new BasicStroke(2.0f/(float)this.mScale),brd); + if (isPaintingFlowlines()) + drawProfileFlowlines(this, g, getFlowLinesColor(), stroke, brd); + if (isPaintingApexline()) + drawProfileApexline(this, g, getApexLineColor(), stroke, brd); + if (isPaintingTuckUnderLine()) + drawProfileTuckUnderLine(this, g, getTuckUnderLineColor(), stroke, brd); + if (isPaintingFootMarks() && (brd == getCurrentBrd() || (brd == getGhostBrd() && isGhostMode()) || (brd == getOriginalBrd() && isOrgFocus()))) + drawProfileFootMarks(this, g, new BasicStroke(2.0f / (float) this.mScale), brd); if (isPaintingBaseLine()) { - drawStringer(g, mColorSettings.getColor(BASELINECOLOR), - new BasicStroke((float) (mSizeSettings.getDouble(BASELINETHICKNESS) / mScale)), - brd); + drawStringer(g, mColorSettings.getColor(BASELINECOLOR), new BasicStroke((float) (mSizeSettings.getDouble(BASELINETHICKNESS) / mScale)), brd); } - if(isPaintingCenterLine()) - { - drawCenterLine(g, getCenterLineColor(), stroke, brd.getLength()/2.0, brd.getThickness()*2.2); + if (isPaintingCenterLine()) { + drawCenterLine(g, getCenterLineColor(), stroke, brd.getLength() / 2.0, brd.getThickness() * 2.2); } - BezierBoardDrawUtil.paintBezierSplines(new JavaDraw(g), mOffsetX, mOffsetY, mScale, - color, stroke, new BezierSpline[]{brd.getBottom(), brd.getDeck()}, mDrawControl, fill); + BezierBoardDrawUtil.paintBezierSplines(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0, color, stroke, new BezierSpline[] { brd.getBottom(), brd.getDeck() }, mDrawControl, fill); super.drawPart(g, color, stroke, brd, false); } - public void drawSlidingInfo(final Graphics2D g, final Color color, - final Stroke stroke, final BezierBoard brd) { + @Override + public void drawSlidingInfo(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { drawProfileSlidingInfo(this, g, color, stroke, brd); } + @Override public void onBrdChanged() { getCurrentBrd().onRockerChanged(); @@ -6096,39 +6555,36 @@ public void onBrdChanged() { view2.repaint(); } + @Override public void mousePressed(final MouseEvent e) { super.mousePressed(e); - if(mSelectedControlPoints.size() == 0) - { + if (mSelectedControlPoints.size() == 0) { final Point pos = e.getPoint(); final Point2D.Double brdPos = screenCoordinateToBrdCoordinate(pos); final int index = getCurrentBrd().getNearestCrossSectionIndex(brdPos.x); double tolerance = 5.0; - if (index != -1 && Math.abs(getCurrentBrd().getCrossSections().get(index).getPosition() - brdPos.x) < tolerance) - { + if (index != -1 && Math.abs(getCurrentBrd().getCrossSections().get(index).getPosition() - brdPos.x) < tolerance) { getCurrentBrd().setCurrentCrossSection(index); } - if(getOriginalBrd() != null) - { + if (getOriginalBrd() != null) { final int indexOriginal = getOriginalBrd().getNearestCrossSectionIndex(brdPos.x); if (indexOriginal != -1 && Math.abs(getOriginalBrd().getCrossSections().get(index).getPosition() - brdPos.x) < tolerance) { getOriginalBrd().setCurrentCrossSection(indexOriginal); } } - if(getGhostBrd() != null) - { + if (getGhostBrd() != null) { final int indexOriginal = getGhostBrd().getNearestCrossSectionIndex(brdPos.x); if (indexOriginal != -1 && Math.abs(getGhostBrd().getCrossSections().get(index).getPosition() - brdPos.x) < tolerance) { getGhostBrd().setCurrentCrossSection(indexOriginal); } } - view2.repaint(); } } + @Override public void mouseMoved(final MouseEvent e) { super.mouseMoved(e); @@ -6138,54 +6594,51 @@ public void mouseMoved(final MouseEvent e) { }; view3.add(popupMenu); - - - view4 = new BoardEdit() - { - static final long serialVersionUID=1L; + view4 = new BoardEdit() { + static final long serialVersionUID = 1L; { setPreferredSize(new Dimension(300, 200)); - //mDrawControl = BezierBoardDrawUtil.MirrorY; - mDrawControl=0; + // mDrawControl = BezierBoardDrawUtil.MirrorY; + mDrawControl = 0; } + @Override public BezierSpline[] getActiveBezierSplines(final BezierBoard brd) { - return new BezierSpline[]{brd.getOutline()}; + return new BezierSpline[] { brd.getOutline() }; } + @Override public ArrayList getGuidePoints() { - return BoardCAD.getInstance().getCurrentBrd() - .getOutlineGuidePoints(); + return BoardCAD.getInstance().getCurrentBrd().getOutlineGuidePoints(); } - public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, - final BezierBoard brd, boolean fill) { + @Override + public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd, boolean fill) { super.drawPart(g, color, stroke, brd, fill); - if(isPaintingCenterLine()) - { - drawCenterLine(g, getCenterLineColor(), stroke, brd.getLength()/2.0, brd.getCenterWidth()*1.1); + if (isPaintingCenterLine()) { + drawCenterLine(g, getCenterLineColor(), stroke, brd.getLength() / 2.0, brd.getCenterWidth() * 1.1); } - if(isPaintingCrossectionsPositions()) - drawOutlineCrossections(this,g,color,stroke,brd); - if(isPaintingFlowlines()) - drawOutlineFlowlines(this,g,getFlowLinesColor(),stroke,brd); - if(isPaintingTuckUnderLine()) - drawOutlineTuckUnderLine(this,g,getTuckUnderLineColor(),stroke,brd); - if(isPaintingFootMarks() && (brd == getCurrentBrd() || (brd == getGhostBrd() && isGhostMode()) || (brd == getOriginalBrd() && isOrgFocus()))) - drawOutlineFootMarks(this,g,new BasicStroke(2.0f/(float)this.mScale),brd); - drawStringer(g, getStringerColor(), - stroke, brd); + if (isPaintingCrossectionsPositions()) + drawOutlineCrossections(this, g, color, stroke, brd); + if (isPaintingFlowlines()) + drawOutlineFlowlines(this, g, getFlowLinesColor(), stroke, brd); + if (isPaintingTuckUnderLine()) + drawOutlineTuckUnderLine(this, g, getTuckUnderLineColor(), stroke, brd); + if (isPaintingFootMarks() && (brd == getCurrentBrd() || (brd == getGhostBrd() && isGhostMode()) || (brd == getOriginalBrd() && isOrgFocus()))) + drawOutlineFootMarks(this, g, new BasicStroke(2.0f / (float) this.mScale), brd); + drawStringer(g, getStringerColor(), stroke, brd); if (isPaintingFins()) { drawFins(g, getFinsColor(), stroke, brd); } } - public void drawSlidingInfo(final Graphics2D g, final Color color, - final Stroke stroke, final BezierBoard brd) { + @Override + public void drawSlidingInfo(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { drawOutlineSlidingInfo(this, g, color, stroke, brd); } + @Override public void onBrdChanged() { getCurrentBrd().onOutlineChanged(); @@ -6193,28 +6646,25 @@ public void onBrdChanged() { view2.repaint(); } + @Override public void mousePressed(final MouseEvent e) { super.mousePressed(e); - if(mSelectedControlPoints.size() == 0) - { + if (mSelectedControlPoints.size() == 0) { final Point pos = e.getPoint(); final Point2D.Double brdPos = screenCoordinateToBrdCoordinate(pos); final int index = getCurrentBrd().getNearestCrossSectionIndex(brdPos.x); double tolerance = 5.0; - if (index != -1 && Math.abs(getCurrentBrd().getCrossSections().get(index).getPosition() - brdPos.x) < tolerance) - { + if (index != -1 && Math.abs(getCurrentBrd().getCrossSections().get(index).getPosition() - brdPos.x) < tolerance) { getCurrentBrd().setCurrentCrossSection(index); } - if(getOriginalBrd() != null) - { + if (getOriginalBrd() != null) { final int indexOriginal = getOriginalBrd().getNearestCrossSectionIndex(brdPos.x); if (indexOriginal != -1 && Math.abs(getOriginalBrd().getCrossSections().get(index).getPosition() - brdPos.x) < tolerance) { getOriginalBrd().setCurrentCrossSection(indexOriginal); } } - if(getGhostBrd() != null) - { + if (getGhostBrd() != null) { final int indexOriginal = getGhostBrd().getNearestCrossSectionIndex(brdPos.x); if (indexOriginal != -1 && Math.abs(getGhostBrd().getCrossSections().get(index).getPosition() - brdPos.x) < tolerance) { getGhostBrd().setCurrentCrossSection(indexOriginal); @@ -6225,6 +6675,7 @@ public void mousePressed(final MouseEvent e) { } + @Override public void mouseMoved(final MouseEvent e) { super.mouseMoved(e); @@ -6234,12 +6685,10 @@ public void mouseMoved(final MouseEvent e) { }; view4.add(popupMenu); - - mNurbspanel = new JPanel(); mNurbspanel.setLayout(new BorderLayout()); -// board_handler = new BoardHandler(); + // board_handler = new BoardHandler(); // window.setMenuBar(menu); // window.setBackground(Color.lightGray); @@ -6253,63 +6702,68 @@ public void mouseMoved(final MouseEvent e) { // window.add("Center", design_panel); -// mTabbedPane.addTab(LanguageResource.getString("3DMODELEDIT_STR"), mNurbspanel); + // mTabbedPane.addTab(LanguageResource.getString("3DMODELEDIT_STR"), + // mNurbspanel); // board_handler.new_board(); // design_panel.update_3d(); + design_panel3 = new DesignPanel(board_handler, status_panel); + design_panel3.view_rendered(); view1.setParentContainer(fourView); view2.setParentContainer(fourView); view3.setParentContainer(fourView); + // view4.setParentContainer(fourView); + + view1.setParentContainer(fourView); fourView.add(view1); fourView.add(view2); fourView.add(view3); - fourView.add(view4); -// fourView.add(mNurbspanel); + // fourView.add(view4); + // fourView.add(mNurbspanel); + fourView.add(design_panel3); mTabbedPane.add(LanguageResource.getString("QUADVIEW_STR"), fourView); - - mOutlineEdit = new BoardEdit() - { - static final long serialVersionUID=1L; + mOutlineEdit = new BoardEdit() { + static final long serialVersionUID = 1L; { mDrawControl = BezierBoardDrawUtil.MirrorY; } + @Override public BezierSpline[] getActiveBezierSplines(final BezierBoard brd) { - return new BezierSpline[]{brd.getOutline()}; + return new BezierSpline[] { brd.getOutline() }; } + @Override public ArrayList getGuidePoints() { - return BoardCAD.getInstance().getCurrentBrd() - .getOutlineGuidePoints(); + return BoardCAD.getInstance().getCurrentBrd().getOutlineGuidePoints(); } - public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, - final BezierBoard brd, boolean fill) { + @Override + public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd, boolean fill) { super.drawPart(g, color, stroke, brd, fill); - if(isPaintingFlowlines()) - drawOutlineFlowlines(this,g,getFlowLinesColor(),stroke,brd); - if(isPaintingTuckUnderLine()) - drawOutlineTuckUnderLine(this,g,getTuckUnderLineColor(),stroke,brd); - if(isPaintingFootMarks() && (brd == getCurrentBrd() || (brd == getGhostBrd() && isGhostMode()) || (brd == getOriginalBrd() && isOrgFocus()))) - drawOutlineFootMarks(this,g,new BasicStroke(2.0f/(float)this.mScale),brd); - if(isPaintingCenterLine()) - { - drawCenterLine(g, getCenterLineColor(), stroke, brd.getLength()/2.0, brd.getCenterWidth()*1.1); + if (isPaintingFlowlines()) + drawOutlineFlowlines(this, g, getFlowLinesColor(), stroke, brd); + if (isPaintingTuckUnderLine()) + drawOutlineTuckUnderLine(this, g, getTuckUnderLineColor(), stroke, brd); + if (isPaintingFootMarks() && (brd == getCurrentBrd() || (brd == getGhostBrd() && isGhostMode()) || (brd == getOriginalBrd() && isOrgFocus()))) + drawOutlineFootMarks(this, g, new BasicStroke(2.0f / (float) this.mScale), brd); + if (isPaintingCenterLine()) { + drawCenterLine(g, getCenterLineColor(), stroke, brd.getLength() / 2.0, brd.getCenterWidth() * 1.1); } - drawStringer(g, getStringerColor(), - stroke, brd); + drawStringer(g, getStringerColor(), stroke, brd); if (isPaintingFins()) { drawFins(g, getFinsColor(), stroke, brd); } } - public void drawSlidingInfo(final Graphics2D g, final Color color, - final Stroke stroke, final BezierBoard brd) { + @Override + public void drawSlidingInfo(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { drawOutlineSlidingInfo(this, g, color, stroke, brd); } + @Override public void onBrdChanged() { getCurrentBrd().onOutlineChanged(); @@ -6321,7 +6775,7 @@ public void onBrdChanged() { mTabbedPane.add(LanguageResource.getString("OUTLINEEDIT_STR"), mOutlineEdit); mBottomAndDeckEdit = new BoardEdit() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { setPreferredSize(new Dimension(400, 150)); @@ -6329,76 +6783,65 @@ public void onBrdChanged() { mCurvatureScale = 1000; } - public BezierSpline[] getActiveBezierSplines(final BezierBoard brd) - { - switch(mEditDeckorBottom) - { - case DECK: - return new BezierSpline[]{brd.getDeck()}; - case BOTTOM: - return new BezierSpline[]{brd.getBottom()}; - case BOTH: - default: - return new BezierSpline[]{brd.getDeck(),brd.getBottom()}; + @Override + public BezierSpline[] getActiveBezierSplines(final BezierBoard brd) { + switch (mEditDeckorBottom) { + case DECK: + return new BezierSpline[] { brd.getDeck() }; + case BOTTOM: + return new BezierSpline[] { brd.getBottom() }; + case BOTH: + default: + return new BezierSpline[] { brd.getDeck(), brd.getBottom() }; } } - public ArrayList getGuidePoints() - { - switch(mEditDeckorBottom) - { - case DECK: - return BoardCAD.getInstance().getCurrentBrd() - .getDeckGuidePoints(); - case BOTTOM: - return BoardCAD.getInstance().getCurrentBrd() - .getBottomGuidePoints(); - case BOTH: - default: - { - ArrayList list = new ArrayList(); - list.addAll(BoardCAD.getInstance().getCurrentBrd() - .getDeckGuidePoints()); - list.addAll(BoardCAD.getInstance().getCurrentBrd() - .getBottomGuidePoints()); - return list; - } + @Override + public ArrayList getGuidePoints() { + switch (mEditDeckorBottom) { + case DECK: + return BoardCAD.getInstance().getCurrentBrd().getDeckGuidePoints(); + case BOTTOM: + return BoardCAD.getInstance().getCurrentBrd().getBottomGuidePoints(); + case BOTH: + default: { + ArrayList list = new ArrayList(); + list.addAll(BoardCAD.getInstance().getCurrentBrd().getDeckGuidePoints()); + list.addAll(BoardCAD.getInstance().getCurrentBrd().getBottomGuidePoints()); + return list; + } } } - public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, - final BezierBoard brd, boolean fill) { - if(isPaintingFlowlines()) - drawProfileFlowlines(this,g,getFlowLinesColor(),stroke,brd); - if(isPaintingApexline()) - drawProfileApexline(this,g,getApexLineColor(),stroke,brd); - if(isPaintingTuckUnderLine()) - drawProfileTuckUnderLine(this,g,getTuckUnderLineColor(),stroke,brd); - if(isPaintingFootMarks() && (brd == getCurrentBrd() || (brd == getGhostBrd() && isGhostMode()) || (brd == getOriginalBrd() && isOrgFocus()))) - drawProfileFootMarks(this,g,new BasicStroke(2.0f/(float)this.mScale),brd); + @Override + public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd, boolean fill) { + if (isPaintingFlowlines()) + drawProfileFlowlines(this, g, getFlowLinesColor(), stroke, brd); + if (isPaintingApexline()) + drawProfileApexline(this, g, getApexLineColor(), stroke, brd); + if (isPaintingTuckUnderLine()) + drawProfileTuckUnderLine(this, g, getTuckUnderLineColor(), stroke, brd); + if (isPaintingFootMarks() && (brd == getCurrentBrd() || (brd == getGhostBrd() && isGhostMode()) || (brd == getOriginalBrd() && isOrgFocus()))) + drawProfileFootMarks(this, g, new BasicStroke(2.0f / (float) this.mScale), brd); if (isPaintingBaseLine()) { - drawStringer(g, mColorSettings.getColor(BASELINECOLOR), - new BasicStroke((float) (mSizeSettings.getDouble(BASELINETHICKNESS) / mScale)), - brd); + drawStringer(g, mColorSettings.getColor(BASELINECOLOR), new BasicStroke((float) (mSizeSettings.getDouble(BASELINETHICKNESS) / mScale)), brd); } - if(isPaintingCenterLine()) - { - drawCenterLine(g, getCenterLineColor(), stroke, brd.getLength()/2.0, brd.getThickness()*2.2); + if (isPaintingCenterLine()) { + drawCenterLine(g, getCenterLineColor(), stroke, brd.getLength() / 2.0, brd.getThickness() * 2.2); } - BezierBoardDrawUtil.paintBezierSplines(new JavaDraw(g), mOffsetX, mOffsetY, mScale, - color, stroke, new BezierSpline[]{brd.getBottom(), brd.getDeck()}, mDrawControl, fill); + BezierBoardDrawUtil.paintBezierSplines(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0, color, stroke, new BezierSpline[] { brd.getBottom(), brd.getDeck() }, mDrawControl, fill); - super.drawPart(g, color, stroke, brd, false); } - public void drawSlidingInfo(final Graphics2D g, final Color color, - final Stroke stroke, final BezierBoard brd) { + @Override + public void drawSlidingInfo(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { drawProfileSlidingInfo(this, g, color, stroke, brd); } + @Override public void onBrdChanged() { getCurrentBrd().onRockerChanged(); @@ -6410,50 +6853,52 @@ public void onBrdChanged() { mTabbedPane.add(LanguageResource.getString("BOTTOMANDDECKEDIT_STR"), mBottomAndDeckEdit); - - -/* mOutlineAndProfileSplitPane = new BrdEditSplitPane( - JSplitPane.VERTICAL_SPLIT, mOutlineEdit2, mBottomAndDeckEdit); - mOutlineAndProfileSplitPane.setOneTouchExpandable(true); - mOutlineAndProfileSplitPane.setResizeWeight(0.7); - - mTabbedPane.add(LanguageResource.getString("OUTLINEPROFILEEDIT_STR"), mOutlineAndProfileSplitPane); -*/ + /* + * mOutlineAndProfileSplitPane = new BrdEditSplitPane( + * JSplitPane.VERTICAL_SPLIT, mOutlineEdit2, mBottomAndDeckEdit); + * mOutlineAndProfileSplitPane.setOneTouchExpandable(true); + * mOutlineAndProfileSplitPane.setResizeWeight(0.7); + * + * mTabbedPane.add(LanguageResource.getString("OUTLINEPROFILEEDIT_STR"), + * mOutlineAndProfileSplitPane); + */ mCrossSectionEdit = new BoardEdit() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { + mIsCrossSectionEdit = true; setPreferredSize(new Dimension(400, 200)); mDrawControl = BezierBoardDrawUtil.MirrorX | BezierBoardDrawUtil.FlipY; mCurvatureScale = 25; } + @Override public BezierSpline[] getActiveBezierSplines(final BezierBoard brd) { final BezierBoardCrossSection currentCrossSection = brd.getCurrentCrossSection(); if (currentCrossSection == null) return null; - return new BezierSpline[]{brd.getCurrentCrossSection().getBezierSpline()}; + return new BezierSpline[] { brd.getCurrentCrossSection().getBezierSpline() }; } + @Override public ArrayList getGuidePoints() { - final BezierBoardCrossSection currentCrossSection = BoardCAD.getInstance() - .getCurrentBrd().getCurrentCrossSection(); + final BezierBoardCrossSection currentCrossSection = BoardCAD.getInstance().getCurrentBrd().getCurrentCrossSection(); if (currentCrossSection == null) return null; return currentCrossSection.getGuidePoints(); } - protected boolean isPaintingVolumeDistribution() - { + @Override + protected boolean isPaintingVolumeDistribution() { return false; } - public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, - final BezierBoard brd, boolean fill) { - if(brd.isEmpty()) + @Override + public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd, boolean fill) { + if (brd.isEmpty()) return; if (isPaintingNonActiveCrossSections()) { @@ -6462,131 +6907,112 @@ public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, final BasicStroke bs = (BasicStroke) stroke; final float[] dashPattern = new float[] { 0.8f, 0.2f }; - final BasicStroke stapled = new BasicStroke((float) (bs - .getLineWidth() / 2.0), bs.getEndCap(), bs - .getLineJoin(), bs.getMiterLimit(), dashPattern, 0f); + final BasicStroke stapled = new BasicStroke((float) (bs.getLineWidth() / 2.0), bs.getEndCap(), bs.getLineJoin(), bs.getMiterLimit(), dashPattern, 0f); final Color noneActiveColor = color.brighter(); double currentCrossSectionRocker = brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition()); for (int i = 0; i < crossSections.size(); i++) { - if (crossSections.get(i) != brd - .getCurrentCrossSection()) { + if (crossSections.get(i) != brd.getCurrentCrossSection()) { double rockerOffset = 0; - if(BoardCAD.getInstance().isUsingOffsetInterpolation()) - { + if (BoardCAD.getInstance().isUsingOffsetInterpolation()) { rockerOffset = brd.getRockerAtPos(crossSections.get(i).getPosition()) - currentCrossSectionRocker; rockerOffset *= this.mScale; } - BezierBoardDrawUtil.paintBezierSpline(new JavaDraw(g), mOffsetX, mOffsetY-rockerOffset, - mScale, noneActiveColor, stapled, - crossSections.get(i).getBezierSpline(), - mDrawControl, fill); + BezierBoardDrawUtil.paintBezierSpline(new JavaDraw(g), mOffsetX, mOffsetY - rockerOffset, mScale, 0.0, noneActiveColor, stapled, crossSections.get(i).getBezierSpline(), mDrawControl, fill); } } } - if (isPaintingSlidingCrossSection()) { final Color col = (isGhostMode()) ? color : Color.GRAY; - double rockerOffset = 0; - if(BoardCAD.getInstance().isUsingOffsetInterpolation()) - { + if (BoardCAD.getInstance().isUsingOffsetInterpolation()) { double currentCrossSectionRocker = brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition()); rockerOffset = brd.getRockerAtPos(mCrossSectionOutlineEdit.mBrdCoord.x) - currentCrossSectionRocker; rockerOffset *= this.mScale; } - BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g), mOffsetX, mOffsetY-rockerOffset, - 0.0, mScale, col, stroke, - (mDrawControl & BezierBoardDrawUtil.FlipX) != 0, - (mDrawControl & BezierBoardDrawUtil.FlipY) != 0, - mCrossSectionOutlineEdit.mBrdCoord.x, brd); + BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g), mOffsetX, mOffsetY - rockerOffset, mScale, 0.0, col, stroke, (mDrawControl & BezierBoardDrawUtil.FlipX) != 0, (mDrawControl & BezierBoardDrawUtil.FlipY) != 0, mCrossSectionOutlineEdit.mBrdCoord.x, brd); if (isGhostMode()) { - if(BoardCAD.getInstance().isUsingOffsetInterpolation()) - { + if (BoardCAD.getInstance().isUsingOffsetInterpolation()) { double currentCrossSectionRocker = getCurrentBrd().getRockerAtPos(getCurrentBrd().getCurrentCrossSection().getPosition()); rockerOffset = getCurrentBrd().getRockerAtPos(mCrossSectionOutlineEdit.mBrdCoord.x) - currentCrossSectionRocker; rockerOffset *= this.mScale; } - BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g), mOffsetX, - mOffsetY-rockerOffset, 0.0, mScale, getGhostBrdColor(), stroke, - (mDrawControl & BezierBoardDrawUtil.FlipX) != 0, - (mDrawControl & BezierBoardDrawUtil.FlipY) != 0, - mCrossSectionOutlineEdit.mBrdCoord.x, + BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g), mOffsetX, mOffsetY - rockerOffset, 0.0, mScale, getGhostBrdColor(), stroke, (mDrawControl & BezierBoardDrawUtil.FlipX) != 0, (mDrawControl & BezierBoardDrawUtil.FlipY) != 0, mCrossSectionOutlineEdit.mBrdCoord.x, getCurrentBrd()); } } super.drawPart(g, color, stroke, brd, fill); - - if(isPaintingTuckUnderLine()) + if (isPaintingTuckUnderLine()) drawCrossSectionTuckUnderLine(this, g, getTuckUnderLineColor(), stroke, brd); - if(isPaintingApexline()) + if (isPaintingApexline()) drawCrossSectionApexline(this, g, getApexLineColor(), stroke, brd); - if(isPaintingFlowlines()) + if (isPaintingFlowlines()) drawCrossSectionFlowlines(this, g, getFlowLinesColor(), stroke, brd); } - public void drawBrdCoordinate(Graphics2D g) - { + @Override + public void drawBrdCoordinate(Graphics2D g) { super.drawBrdCoordinate(g); BezierBoard brd = getCurrentBrd(); - if(brd.isEmpty()) + if (brd.isEmpty()) return; - + BezierBoardCrossSection crs = brd.getCurrentCrossSection(); - if(crs == null) + if (crs == null) return; - + g.setColor(Color.BLACK); - // get metrics from the graphics + // get metrics from the graphics FontMetrics metrics = g.getFontMetrics(mBrdCoordFont); - - // get the height of a line of text in this font and render context + + // get the height of a line of text in this font and render + // context int hgt = metrics.getHeight(); - String posStr = LanguageResource.getString("CROSSECTIONPOS_STR") + UnitUtils.convertLengthToCurrentUnit(mBoardSpec.isOverCurveSelected()?brd.getBottom().getLengthByX(crs.getPosition()):crs.getPosition(), false) + (mBoardSpec.isOverCurveSelected()?" O.C":""); + String posStr = LanguageResource.getString("CROSSECTIONPOS_STR") + UnitUtils.convertLengthToCurrentUnit(mBoardSpec.isOverCurveSelected() ? brd.getBottom().getLengthByX(crs.getPosition()) : crs.getPosition(), false) + (mBoardSpec.isOverCurveSelected() ? " O.C" : ""); + + g.drawString(posStr, 10, hgt * 3); - g.drawString(posStr, 10, hgt*3); + // get the height of a line of text in this font and render + // context - // get the height of a line of text in this font and render context + String widthStr = LanguageResource.getString("CROSSECTIONWIDTH_STR") + UnitUtils.convertLengthToCurrentUnit(crs.getWidth(), false); - String widthStr = LanguageResource.getString("CROSSECTIONWIDTH_STR") + UnitUtils.convertLengthToCurrentUnit(crs.getWidth(), false) ; + g.drawString(widthStr, 10, hgt * 4); - g.drawString(widthStr, 10, hgt*4); - final Dimension dim = getSize(); - - String releaseAngleStr = LanguageResource.getString("RELEASEANGLE_STR") + String.format("%1$.1f degrees", crs.getReleaseAngle()/MathUtils.DEG_TO_RAD); + + String releaseAngleStr = LanguageResource.getString("RELEASEANGLE_STR") + String.format("%1$.1f degrees", crs.getReleaseAngle() / MathUtils.DEG_TO_RAD); final int releaseAngleStrLength = metrics.stringWidth(releaseAngleStr); - g.drawString(releaseAngleStr, dim.width - releaseAngleStrLength - 10, hgt*1); + g.drawString(releaseAngleStr, dim.width - releaseAngleStrLength - 10, hgt * 1); - String tuckUnderRadiusStr = LanguageResource.getString("TUCKRADIUS_STR") + UnitUtils.convertLengthToCurrentUnit(crs.getTuckRadius(),false); + String tuckUnderRadiusStr = LanguageResource.getString("TUCKRADIUS_STR") + UnitUtils.convertLengthToCurrentUnit(crs.getTuckRadius(), false); final int tuckUnderRadiusStrLength = metrics.stringWidth(tuckUnderRadiusStr); - g.drawString(tuckUnderRadiusStr, dim.width - tuckUnderRadiusStrLength - 10, hgt*2); + g.drawString(tuckUnderRadiusStr, dim.width - tuckUnderRadiusStrLength - 10, hgt * 2); } - public void drawSlidingInfo(final Graphics2D g, final Color color, - final Stroke stroke, final BezierBoard brd) { + @Override + public void drawSlidingInfo(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { if (brd.getCrossSections().size() == 0) return; - if (brd.getCurrentCrossSection() == null) return; @@ -6611,12 +7037,10 @@ public void drawSlidingInfo(final Graphics2D g, final Color color, final Dimension dim = getSize(); String thicknessStr = LanguageResource.getString("CROSSECTIONSLIDINGINFOTHICKNESS_STR"); - mSlidingInfoString = thicknessStr - + UnitUtils.convertLengthToCurrentUnit(thickness, false) + String.format("(%02d%%)", (int)((thickness*100)/centerThickness)); + mSlidingInfoString = thicknessStr + UnitUtils.convertLengthToCurrentUnit(thickness, false) + String.format("(%02d%%)", (int) ((thickness * 100) / centerThickness)); g.setColor(Color.BLUE); - // get the advance of my text in this font and render context final int adv = metrics.stringWidth(mSlidingInfoString); @@ -6638,91 +7062,76 @@ public void drawSlidingInfo(final Graphics2D g, final Color color, if (textX + size.width + 10 > dim.width) textX = dim.width - size.width - 10; - g.setStroke(new BasicStroke((float) (1.0 / mScale))); - g.drawString(mSlidingInfoString, textX, dim.height - - (size.height * 2 + 5)); - + g.drawString(mSlidingInfoString, textX, dim.height - (size.height * 2 + 5)); - mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOBOTTOM_STR") - + UnitUtils.convertLengthToCurrentUnit(bottom, false); + mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOBOTTOM_STR") + UnitUtils.convertLengthToCurrentUnit(bottom, false); g.setColor(Color.RED); - g.drawString(mSlidingInfoString, textX, dim.height - - size.height); + g.drawString(mSlidingInfoString, textX, dim.height - size.height); g.setColor(Color.BLACK); final double fromCenter = Math.abs(mBrdCoord.x); - final double fromRail = crs.getWidth()/2.0 - Math.abs(mBrdCoord.x); - - - mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOFROMRAIL_STR") - + UnitUtils.convertLengthToCurrentUnit(fromRail, false); + final double fromRail = crs.getWidth() / 2.0 - Math.abs(mBrdCoord.x); + mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOFROMRAIL_STR") + UnitUtils.convertLengthToCurrentUnit(fromRail, false); - g.drawString(mSlidingInfoString, textX, dim.height - - (size.height + 2) * 4); + g.drawString(mSlidingInfoString, textX, dim.height - (size.height + 2) * 4); - mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOFROMCENTER_STR") - + UnitUtils.convertLengthToCurrentUnit(fromCenter, false); + mSlidingInfoString = LanguageResource.getString("CROSSECTIONSLIDINGINFOFROMCENTER_STR") + UnitUtils.convertLengthToCurrentUnit(fromCenter, false); + g.drawString(mSlidingInfoString, textX, dim.height - (size.height + 2) * 3); - g.drawString(mSlidingInfoString, textX, dim.height - - (size.height + 2) * 3); - - //sets the color of the +ve sliding info (above Y base line) + // sets the color of the +ve sliding info (above Y base line) g.setColor(Color.BLUE); + final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0); - final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), - mOffsetX, mOffsetY, mScale); - - - mSlidingInfoLine.setLine(mBrdCoord.x * mulX, bottom * mulY, - mBrdCoord.x * mulX, (bottom + thickness) * mulY); + mSlidingInfoLine.setLine(mBrdCoord.x * mulX, bottom * mulY, mBrdCoord.x * mulX, (bottom + thickness) * mulY); g.draw(mSlidingInfoLine); - //sets the color of the Bottom sliding info (-ve# when concaved +ve# when Vee) + // sets the color of the Bottom sliding info (-ve# when concaved + // +ve# when Vee) g.setColor(Color.RED); - mSlidingInfoLine.setLine(mBrdCoord.x * mulX, 0 * mulY, - mBrdCoord.x * mulX, bottom * mulY); + mSlidingInfoLine.setLine(mBrdCoord.x * mulX, 0 * mulY, mBrdCoord.x * mulX, bottom * mulY); g.draw(mSlidingInfoLine); - g.setTransform(savedTransform); } + @Override public void fitBrd() { final BezierBoard brd = getCurrentBrd(); final Dimension dim = getSize(); - double width=board_handler.get_segment_width()/10; - if (width<10) - width=10; - - if (width ghostCrossSections = ghost.getCrossSections(); for (int i = 1; i < ghostCrossSections.size() - 1; i++) { final double pos = ghostCrossSections.get(i).getPosition(); @@ -6914,15 +7286,13 @@ public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, } else { g.setColor(color); } - line.setLine(pos * mulX, (-width / 2) * mulY, pos * mulX, - (width / 2) * mulY); + line.setLine(pos * mulX, (-width / 2) * mulY, pos * mulX, (width / 2) * mulY); g.draw(line); } } - if(BoardCAD.getInstance().isOrgFocus() && org != null && !org.isEmpty()) - { + if (BoardCAD.getInstance().isOrgFocus() && org != null && !org.isEmpty()) { final ArrayList orgCrossSections = org.getCrossSections(); for (int i = 1; i < orgCrossSections.size() - 1; i++) { final double pos = orgCrossSections.get(i).getPosition(); @@ -6933,8 +7303,7 @@ public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, } else { g.setColor(color); } - line.setLine(pos * mulX, (-width / 2) * mulY, pos * mulX, - (width / 2) * mulY); + line.setLine(pos * mulX, (-width / 2) * mulY, pos * mulX, (width / 2) * mulY); g.draw(line); } @@ -6944,28 +7313,26 @@ public void drawPart(final Graphics2D g, final Color color, final Stroke stroke, } - public void drawSlidingInfo(final Graphics2D g, final Color color, - final Stroke stroke, final BezierBoard brd) { + @Override + public void drawSlidingInfo(final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { drawOutlineSlidingInfo(this, g, color, stroke, brd); } + @Override public void mousePressed(final MouseEvent e) { final Point pos = e.getPoint(); final Point2D.Double brdPos = screenCoordinateToBrdCoordinate(pos); final int index = getCurrentBrd().getNearestCrossSectionIndex(brdPos.x); - if (index != -1) - { + if (index != -1) { getCurrentBrd().setCurrentCrossSection(index); } - if(getOriginalBrd() != null) - { + if (getOriginalBrd() != null) { final int indexOriginal = getOriginalBrd().getNearestCrossSectionIndex(brdPos.x); if (indexOriginal != -1) { getOriginalBrd().setCurrentCrossSection(indexOriginal); } } - if(getGhostBrd() != null) - { + if (getGhostBrd() != null) { final int indexOriginal = getGhostBrd().getNearestCrossSectionIndex(brdPos.x); if (indexOriginal != -1) { getGhostBrd().setCurrentCrossSection(indexOriginal); @@ -6975,6 +7342,7 @@ public void mousePressed(final MouseEvent e) { } + @Override public void mouseMoved(final MouseEvent e) { super.mouseMoved(e); @@ -6983,14 +7351,12 @@ public void mouseMoved(final MouseEvent e) { }; - mCrossSectionSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, - mCrossSectionEdit, mCrossSectionOutlineEdit); + mCrossSectionSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mCrossSectionEdit, mCrossSectionOutlineEdit); mCrossSectionSplitPane.setOneTouchExpandable(true); mCrossSectionSplitPane.setResizeWeight(0.7); mTabbedPane.add(LanguageResource.getString("CROSSECTIONEDIT_STR"), mCrossSectionSplitPane); - mRenderedpanel = new JPanel(); mRenderedpanel.setLayout(new BorderLayout()); @@ -7006,135 +7372,88 @@ public void mouseMoved(final MouseEvent e) { // board_handler.new_board(); // design_panel.update_3d(); - //DEBUG! - - mJOGLpanel = new JPanel(); - mJOGLpanel.setLayout(new BorderLayout()); - joglpanel = new JOGLPanel(board_handler); - mJOGLpanel.add(joglpanel, BorderLayout.CENTER); - mJOGLpanel.add(status_panel, BorderLayout.SOUTH); -// mTabbedPane.addTab("JOGL view", mJOGLpanel); - joglpanel.redraw(); - - - -// mTabbedPane.add("PrintBrd",mPrintBrd); //Only for debugging -// mTabbedPane.add("PrintSpecSheet",mPrintSpecSheet); //Only for debugging -// mTabbedPane.add("PrintChamberedWood",mPrintChamberedWoodTemplate); //Only for debugging -// mTabbedPane.add("PrintSandwich",mPrintSandwichTemplates); //Only for debugging -// mTabbedPane.add("PrintHWS",mPrintHollowWoodTemplates); //Only for debugging + // DEBUG! + mTabbedPane.add("PrintBrd", mPrintBrd); // Only for debugging + mTabbedPane.add("PrintSpecSheet", mPrintSpecSheet); // Only for + // debugging + mTabbedPane.add("PrintChamberedWood", mPrintChamberedWoodTemplate); // Only + // for + // debugging + mTabbedPane.add("PrintSandwich", mPrintSandwichTemplates); // Only for + // debugging + mTabbedPane.add("PrintHWS", mPrintHollowWoodTemplates); // Only for + // debugging mTabbedPane.addChangeListener(new ChangeListener() { - boolean setModel = false; - public void stateChanged(final ChangeEvent e) - { + + @Override + public void stateChanged(final ChangeEvent e) { mGuidePointsDialog.update(); - if (mTabbedPane.getSelectedComponent() == mRenderedpanel) - { - if(!setModel) - { - BranchGroup root = new BranchGroup(); - mBezier3DOnSwitch = new Switch(); - mBezier3DOnSwitch.setCapability(Switch.ALLOW_SWITCH_READ); - mBezier3DOnSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); - boolean selected = mShowBezier3DModelMenuItem.getModel().isSelected(); - mBezier3DOnSwitch.setWhichChild(selected?Switch.CHILD_ALL:Switch.CHILD_NONE); - root.addChild(mBezier3DOnSwitch); - mScale = new TransformGroup(); - mScale.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); - mBezier3DOnSwitch.addChild(mScale); - mBezier3DModel = new Shape3D(); - mBezier3DModel.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); - mBezier3DModel.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); - // Create an Appearance. - Appearance a = new Appearance(); - Color3f ambient = new Color3f(0.4f, 0.4f, 0.45f); - Color3f emissive = new Color3f(0.0f, 0.0f, 0.0f); - Color3f diffuse = new Color3f(0.8f, 0.8f, 0.8f); - Color3f specular = new Color3f(1.0f, 1.0f, 1.0f); - - // Set up the material properties - a.setMaterial(new Material(ambient, emissive, diffuse, specular, 115.0f)); - mBezier3DModel.setAppearance(a); - mScale.addChild(mBezier3DModel); - - design_panel2.addModel(root); - - setModel = true; - } + if (mTabbedPane.getSelectedComponent() == mRenderedpanel || mTabbedPane.getSelectedComponent() == fourView) { boolean selected = mShowBezier3DModelMenuItem.getModel().isSelected(); - if(selected && mBoardChangedFor3D) - { + if (selected) { updateBezier3DModel(); - } + } -// design_panel2.update_3d(); + // design_panel2.update_3d(); design_panel2.fit_all(); design_panel2.redraw(); + design_panel3.redraw(); } -/* - if (mTabbedPane.getSelectedComponent() == mNurbspanel) { - if (mNeverApproximateNurbs == true) - return; - - if (mAlwaysApproximateNurbs == false) { - - final Object[] options = { "Always", "Yes", "No", "Never" }; - final int n = JOptionPane.showOptionDialog(mFrame, - "Approximate Nurbs/3D from beziers?", - "Nurbs/3D", JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, null, options, - options[1]); - - switch (n) { - case 0: - mAlwaysApproximateNurbs = true; - break; - case 1: - break; - case 3: - mNeverApproximateNurbs = true; - case 2: - return; // break out - - } - } - board_handler.approximate_bezier(getCurrentBrd(), false); - design_panel.update_3d(); - // design_panel.fit_all(); - design_panel.redraw(); - - } -*/ + /* + * if (mTabbedPane.getSelectedComponent() == mNurbspanel) { if + * (mNeverApproximateNurbs == true) return; + * + * if (mAlwaysApproximateNurbs == false) { + * + * final Object[] options = { "Always", "Yes", "No", "Never" }; + * final int n = JOptionPane.showOptionDialog(mFrame, + * "Approximate Nurbs/3D from beziers?", "Nurbs/3D", + * JOptionPane.YES_NO_CANCEL_OPTION, + * JOptionPane.QUESTION_MESSAGE, null, options, options[1]); + * + * switch (n) { case 0: mAlwaysApproximateNurbs = true; break; + * case 1: break; case 3: mNeverApproximateNurbs = true; case 2: + * return; // break out + * + * } } board_handler.approximate_bezier(getCurrentBrd(), false); + * design_panel.update_3d(); // design_panel.fit_all(); + * design_panel.redraw(); + * + * } + */ } }); final JMenu pluginMenu = new JMenu(LanguageResource.getString("PLUGINSMENU_STR")); final AbstractPluginHandler pluginLoader = new AbstractPluginHandler() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; + + @Override public void onNewPluginMenu(JMenu menu) { pluginMenu.add(menu); } + @Override public void onNewPluginComponent(JComponent component) { mTabbedPane.add(component); } }; - //pluginLoader.loadPlugins("plugins"); + // pluginLoader.loadPlugins("plugins"); if (pluginMenu.getItemCount() > 0) { menuBar.add(pluginMenu); } - //mFrame.getContentPane().add(mTabbedPane, BorderLayout.CENTER); + // mFrame.getContentPane().add(mTabbedPane, BorderLayout.CENTER); getPreferences(); - mTabbedPane2 = new JTabbedPane(JTabbedPane.BOTTOM); + mTabbedPane2 = new JTabbedPane(SwingConstants.BOTTOM); - panel=new JPanel(); + panel = new JPanel(); panel.setLayout(new BorderLayout()); @@ -7146,41 +7465,37 @@ public void onNewPluginComponent(JComponent component) { mBoardSpec = new BoardSpec(); panel.add(mBoardSpec, BorderLayout.WEST); - - mTabbedPane2 = new JTabbedPane(JTabbedPane.BOTTOM); + mTabbedPane2 = new JTabbedPane(SwingConstants.BOTTOM); mTabbedPane2.addTab("Board specification", panel); -// mFrame.getContentPane().add(panel, BorderLayout.SOUTH); -// mFrame.getContentPane().add(mTabbedPane2, BorderLayout.SOUTH); - //mFrame.getContentPane().add(mTabbedPane, BorderLayout.CENTER); - mSplitPane=new JSplitPane(JSplitPane.VERTICAL_SPLIT, mTabbedPane, mTabbedPane2); + // mFrame.getContentPane().add(panel, BorderLayout.SOUTH); + // mFrame.getContentPane().add(mTabbedPane2, BorderLayout.SOUTH); + // mFrame.getContentPane().add(mTabbedPane, BorderLayout.CENTER); + mSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mTabbedPane, mTabbedPane2); mSplitPane.setResizeWeight(1.0); mSplitPane.setOneTouchExpandable(true); mFrame.getContentPane().add(mSplitPane, BorderLayout.CENTER); - Dimension mindim=new Dimension(0,0); + Dimension mindim = new Dimension(0, 0); mTabbedPane.setMinimumSize(mindim); mTabbedPane2.setMinimumSize(mindim); - mTabbedPane.setPreferredSize(new Dimension(600,230)); - mTabbedPane2.setPreferredSize(new Dimension(600,230)); - - //load jython script - String scriptname="boardcad_init.py"; - File file=new File(scriptname); - if (file.exists()) - { + mTabbedPane.setPreferredSize(new Dimension(600, 230)); + mTabbedPane2.setPreferredSize(new Dimension(600, 230)); + + // load jython script + String scriptname = "boardcad_init.py"; + File file = new File(scriptname); + if (file.exists()) { ScriptLoader.loadScript(scriptname); - } - - KeyboardFocusManager.getCurrentKeyboardFocusManager() - .addKeyEventDispatcher(this); + } + KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int width = screenSize.width * 9 / 10; int height = screenSize.height * 9 / 10; - mFrame.setLocation((screenSize.width - width) / 2, (screenSize.height - height) / 2); + mFrame.setLocation((screenSize.width - width) / 2, (screenSize.height - height) / 2); - mFrame.setSize(width, height); + mFrame.setSize(width, height); mFrame.setVisible(true); @@ -7195,8 +7510,8 @@ public void onNewPluginComponent(JComponent component) { mGuidePointsDialog.setModal(false); mGuidePointsDialog.setAlwaysOnTop(true); mGuidePointsDialog.setVisible(false); - - //Set current unit after all and everything is initialized + + // Set current unit after all and everything is initialized unitComboBox.setSelectedIndex(1); // DEBUG @@ -7216,19 +7531,19 @@ public void onNewPluginComponent(JComponent component) { * BrdReader.loadFile(getCurrentBrd(), * DefaultBrds.getInstance().getBoardArray("Funboard"), "funboard"); * mOriginalBrd.set(getCurrentBrd()); fitAll(); onBrdChanged(); - * + * * getSelectedEdit().loadBackgroundImage("F:\\Gfx\\Misc\\Surfboards\\horan * 6'8 keelboard outline.jpg"); */ - + mBlockGUI = false; } + @Override public void actionPerformed(final ActionEvent e) { final String cmdStr = e.getActionCommand(); - if (cmdStr == LanguageResource.getString("PRINTOUTLINE_STR")) - { + if (cmdStr == LanguageResource.getString("PRINTOUTLINE_STR")) { CategorizedSettings settings = new CategorizedSettings(); String categoryName = LanguageResource.getString("PRINTOUTLINEPARAMETERSCATEGORY_STR"); Settings printOutlineSettings = settings.addCategory(categoryName); @@ -7243,11 +7558,9 @@ public void actionPerformed(final ActionEvent e) { return; } - mPrintBrd.printOutline(printOutlineSettings.getBoolean("PrintGrid"),printOutlineSettings.getBoolean("OverCurve")); + mPrintBrd.printOutline(printOutlineSettings.getBoolean("PrintGrid"), printOutlineSettings.getBoolean("OverCurve")); - } - else if (cmdStr == LanguageResource.getString("PRINTSPINTEMPLATE_STR")) - { + } else if (cmdStr == LanguageResource.getString("PRINTSPINTEMPLATE_STR")) { CategorizedSettings settings = new CategorizedSettings(); String categoryName = LanguageResource.getString("PRINTSPINTEMPLATEPARAMETERSCATEGORY_STR"); Settings printOutlineSettings = settings.addCategory(categoryName); @@ -7262,37 +7575,40 @@ else if (cmdStr == LanguageResource.getString("PRINTSPINTEMPLATE_STR")) return; } - mPrintBrd.printSpinTemplate(printOutlineSettings.getBoolean("PrintGrid"),printOutlineSettings.getBoolean("OverCurve")); - } - else if (cmdStr == LanguageResource.getString("PRINTPROFILE_STR")) { + mPrintBrd.printSpinTemplate(printOutlineSettings.getBoolean("PrintGrid"), printOutlineSettings.getBoolean("OverCurve")); + } else if (cmdStr == LanguageResource.getString("PRINTPROFILE_STR")) { mPrintBrd.printProfile(); } else if (cmdStr == LanguageResource.getString("PRINTCROSSECTION_STR")) { mPrintBrd.printSlices(); -// } else if (cmdStr == LanguageResource.getString("PRINTSPECSHEET_STR")) { -// mPrintBrd.printSpecSheet(); -// } else if (cmdStr == LanguageResource.getString("VIEW3D_STR")) { -// design_panel.view_3d(); -// } else if (cmdStr == LanguageResource.getString("EDITNURBS_STR")) { -// design_panel.view_all(); -// design_panel.fit_all(); + // } else if (cmdStr == + // LanguageResource.getString("PRINTSPECSHEET_STR")) { + // mPrintBrd.printSpecSheet(); + // } else if (cmdStr == LanguageResource.getString("VIEW3D_STR")) { + // design_panel.view_3d(); + // } else if (cmdStr == LanguageResource.getString("EDITNURBS_STR")) + // { + // design_panel.view_all(); + // design_panel.fit_all(); } else if (cmdStr == LanguageResource.getString("SIMPLEEDITING_STR")) { board_handler.set_single_point_editing(false); - //design_panel.fit_all(); + // design_panel.fit_all(); redraw(); } else if (cmdStr == LanguageResource.getString("ADVANCEDEDITING_STR")) { board_handler.set_single_point_editing(true); - //design_panel.fit_all(); + // design_panel.fit_all(); redraw(); } } + @Override public void itemStateChanged(final ItemEvent e) { mFrame.repaint(); } + @Override public boolean dispatchKeyEvent(final KeyEvent e) { if (mControlPointInfo != null && mControlPointInfo.isEditing()) return false; @@ -7304,25 +7620,23 @@ public boolean dispatchKeyEvent(final KeyEvent e) { return false; BoardEdit edit = getSelectedEdit(); - if(edit == null) + if (edit == null) return false; - - if(this.getFrame().getFocusOwner() == null) + + if (this.getFrame().getFocusOwner() == null) return false; - -// System.out.printf("dispatchKeyEvent() event %s\n",e.toString()); + + // System.out.printf("dispatchKeyEvent() event %s\n",e.toString()); switch (e.getKeyCode()) { case KeyEvent.VK_ADD: - if (e.getID() == KeyEvent.KEY_PRESSED) - { + if (e.getID() == KeyEvent.KEY_PRESSED) { mNextCrossSection.actionPerformed(null); } break; case KeyEvent.VK_SUBTRACT: - if (e.getID() == KeyEvent.KEY_PRESSED) - { + if (e.getID() == KeyEvent.KEY_PRESSED) { mPreviousCrossSection.actionPerformed(null); } break; @@ -7332,26 +7646,24 @@ public boolean dispatchKeyEvent(final KeyEvent e) { if (e.isControlDown()) break; - if(mGhostMode == false) - { + if (mGhostMode == false) { mGhostMode = true; if (mPreviousCommand == null) { mPreviousCommand = getCurrentCommand(); setCurrentCommand(new GhostCommand()); } - if(edit != null) + if (edit != null) edit.repaint(); mBoardSpec.updateInfoInstantly(); } } else if (e.getID() == KeyEvent.KEY_RELEASED) { - if(mGhostMode == true) - { + if (mGhostMode == true) { mGhostMode = false; if (mPreviousCommand != null) { setCurrentCommand(mPreviousCommand); mPreviousCommand = null; } - if(edit != null) + if (edit != null) edit.repaint(); mBoardSpec.updateInfoInstantly(); } @@ -7364,18 +7676,16 @@ public boolean dispatchKeyEvent(final KeyEvent e) { if (e.isControlDown()) break; - if(mOrgFocus != true) - { + if (mOrgFocus != true) { mOrgFocus = true; - if(edit != null) + if (edit != null) edit.repaint(); mBoardSpec.updateInfoInstantly(); } } else if (e.getID() == KeyEvent.KEY_RELEASED) { - if(mOrgFocus != false) - { + if (mOrgFocus != false) { mOrgFocus = false; - if(edit != null) + if (edit != null) edit.repaint(); mBoardSpec.updateInfoInstantly(); } @@ -7383,7 +7693,7 @@ public boolean dispatchKeyEvent(final KeyEvent e) { return true; case KeyEvent.VK_ESCAPE: setCurrentCommand(new BrdEditCommand()); - if(edit != null) + if (edit != null) edit.repaint(); break; } @@ -7392,33 +7702,33 @@ public boolean dispatchKeyEvent(final KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { switch (e.getKeyCode()) { case KeyEvent.VK_UP: - if(edit != null) - edit.mGhostOffsetY -= (e.isAltDown() ? .1f : 1f)/edit.getScale(); + if (edit != null) + edit.mGhostOffsetY -= (e.isAltDown() ? .1f : 1f) / edit.getScale(); mFrame.repaint(); return true; case KeyEvent.VK_DOWN: - if(edit != null) - edit.mGhostOffsetY += (e.isAltDown() ? .1f : 1f)/edit.getScale(); + if (edit != null) + edit.mGhostOffsetY += (e.isAltDown() ? .1f : 1f) / edit.getScale(); mFrame.repaint(); return true; case KeyEvent.VK_LEFT: - if(edit != null) - edit.mGhostOffsetX -= (e.isAltDown() ? .1f : 1f)/edit.getScale(); + if (edit != null) + edit.mGhostOffsetX -= (e.isAltDown() ? .1f : 1f) / edit.getScale(); mFrame.repaint(); return true; case KeyEvent.VK_RIGHT: - if(edit != null) - edit.mGhostOffsetX += (e.isAltDown() ? .1f : 1f)/edit.getScale(); + if (edit != null) + edit.mGhostOffsetX += (e.isAltDown() ? .1f : 1f) / edit.getScale(); mFrame.repaint(); return true; case KeyEvent.VK_Q: - if(edit != null) - edit.mGhostRot -= ((double)Math.PI/180.0f)*(e.isAltDown() ? .1f : 1f)/edit.getScale(); + if (edit != null) + edit.mGhostRot -= (Math.PI / 180.0f) * (e.isAltDown() ? .1f : 1f) / edit.getScale(); mFrame.repaint(); return true; case KeyEvent.VK_W: - if(edit != null) - edit.mGhostRot += ((double)Math.PI/180.0f)*(e.isAltDown() ? .1f : 1f)/edit.getScale(); + if (edit != null) + edit.mGhostRot += (Math.PI / 180.0f) * (e.isAltDown() ? .1f : 1f) / edit.getScale(); mFrame.repaint(); return true; default: @@ -7427,29 +7737,28 @@ public boolean dispatchKeyEvent(final KeyEvent e) { } } - if (mOrgFocus) - { + if (mOrgFocus) { if (e.getID() == KeyEvent.KEY_PRESSED) { switch (e.getKeyCode()) { case KeyEvent.VK_UP: - if(edit != null) - edit.mOriginalOffsetY -= (e.isAltDown() ? .1f : 1f)/edit.getScale(); + if (edit != null) + edit.mOriginalOffsetY -= (e.isAltDown() ? .1f : 1f) / edit.getScale(); mFrame.repaint(); return true; case KeyEvent.VK_DOWN: - if(edit != null) - edit.mOriginalOffsetY += (e.isAltDown() ? .1f : 1f)/edit.getScale(); + if (edit != null) + edit.mOriginalOffsetY += (e.isAltDown() ? .1f : 1f) / edit.getScale(); mFrame.repaint(); return true; case KeyEvent.VK_LEFT: - if(edit != null) - edit.mOriginalOffsetX -= (e.isAltDown() ? .1f : 1f)/edit.getScale(); + if (edit != null) + edit.mOriginalOffsetX -= (e.isAltDown() ? .1f : 1f) / edit.getScale(); mFrame.repaint(); return true; case KeyEvent.VK_RIGHT: - if(edit != null) - edit.mOriginalOffsetX += (e.isAltDown() ? .1f : 1f)/edit.getScale(); + if (edit != null) + edit.mOriginalOffsetX += (e.isAltDown() ? .1f : 1f) / edit.getScale(); mFrame.repaint(); return true; default: @@ -7501,8 +7810,7 @@ public boolean dispatchKeyEvent(final KeyEvent e) { } public void toggleBottomAndDeck() { - switch(mEditDeckorBottom) - { + switch (mEditDeckorBottom) { case DECK: mEditDeckorBottom = DeckOrBottom.BOTTOM; break; @@ -7524,78 +7832,66 @@ public static void main(final String[] args) { BoardCAD.getInstance(); } - public void drawOutlineFootMarks(final BoardEdit source, final Graphics2D g, - final Stroke stroke, final BezierBoard brd) { - - if(brd.isEmpty()) + public void drawOutlineFootMarks(final BoardEdit source, final Graphics2D g, final Stroke stroke, final BezierBoard brd) { + + if (brd.isEmpty()) return; g.setStroke(stroke); - Point centerPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(brd.getLength()/2.0, 0.0)); - Point widthPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(0,brd.getMaxWidth()/2)); + Point centerPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(brd.getLength() / 2.0, 0.0)); + Point widthPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(0, brd.getMaxWidth() / 2)); // get metrics from the graphics final FontMetrics metrics = g.getFontMetrics(source.mSlidingInfoFont); // get the height of a line of text in this font and render context final int hgt = metrics.getHeight(); - for(int i = 0; i < 7; i++) - { + for (int i = 0; i < 7; i++) { double pos = 0.0; String label; - if(i < 3) - { - pos = (i==0)?UnitUtils.INCH:i*UnitUtils.INCH*UnitUtils.INCHES_PR_FOOT; + if (i < 3) { + pos = (i == 0) ? UnitUtils.INCH : i * UnitUtils.INCH * UnitUtils.INCHES_PR_FOOT; label = UnitUtils.convertLengthToCurrentUnit(pos, false); - } - else if( i == 3) - { + } else if (i == 3) { pos = brd.getMaxWidthPos(); - label = "W.P:" + UnitUtils.convertLengthToCurrentUnit(mBoardSpec.isOverCurveSelected()? brd.getBottom().getPointByCurveLength(pos).x - brd.getBottom().getPointByCurveLength(brd.getLength()/2.0).x : - pos - brd.getLength()/2.0, - false); - } - else - { - pos = (mBoardSpec.isOverCurveSelected()?brd.getBottom().getLength():brd.getLength()) - ((i==6)?UnitUtils.INCH:(6-i)*UnitUtils.INCH*UnitUtils.INCHES_PR_FOOT); - label = UnitUtils.convertLengthToCurrentUnit(-((i==6)?UnitUtils.INCH:(6-i)*UnitUtils.INCH*UnitUtils.INCHES_PR_FOOT), false); + label = "W.P:" + UnitUtils.convertLengthToCurrentUnit(mBoardSpec.isOverCurveSelected() ? brd.getBottom().getPointByCurveLength(pos).x - brd.getBottom().getPointByCurveLength(brd.getLength() / 2.0).x : pos - brd.getLength() / 2.0, false); + } else { + pos = (mBoardSpec.isOverCurveSelected() ? brd.getBottom().getLength() : brd.getLength()) - ((i == 6) ? UnitUtils.INCH : (6 - i) * UnitUtils.INCH * UnitUtils.INCHES_PR_FOOT); + label = UnitUtils.convertLengthToCurrentUnit(-((i == 6) ? UnitUtils.INCH : (6 - i) * UnitUtils.INCH * UnitUtils.INCHES_PR_FOOT), false); } - if(mBoardSpec.isOverCurveSelected()) - { + if (mBoardSpec.isOverCurveSelected()) { pos = brd.getBottom().getPointByCurveLength(pos).x; label = label.concat(" O.C"); } - double width = brd.getWidthAt(pos); String widthStr = UnitUtils.convertLengthToCurrentUnit(width, false); g.setColor(Color.BLUE); - // get the advance of my text in this font and render context final int labelWidth = metrics.stringWidth(label); // get the advance of my text in this font and render context final int widthOfWidthString = metrics.stringWidth(widthStr); - Point outlinePoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(pos,width/2.0)); - Point upperOutlinePoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(pos,-width/2.0)); + Point outlinePoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(pos, width / 2.0)); + Point upperOutlinePoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(pos, -width / 2.0)); g.setColor(Color.BLACK); - g.drawString(label, outlinePoint.x - (labelWidth/2), centerPoint.y); + g.drawString(label, outlinePoint.x - (labelWidth / 2), centerPoint.y); g.setColor(Color.BLUE); g.drawLine(outlinePoint.x, upperOutlinePoint.y, outlinePoint.x, outlinePoint.y); - g.drawString(widthStr, outlinePoint.x - (widthOfWidthString/2), widthPoint.y + hgt); + g.drawString(widthStr, outlinePoint.x - (widthOfWidthString / 2), widthPoint.y + hgt); g.setColor(Color.DARK_GRAY); @@ -7604,51 +7900,42 @@ else if( i == 3) } - public void drawProfileFootMarks(final BoardEdit source, final Graphics2D g, - final Stroke stroke, final BezierBoard brd) { + public void drawProfileFootMarks(final BoardEdit source, final Graphics2D g, final Stroke stroke, final BezierBoard brd) { g.setStroke(stroke); - Point centerPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(brd.getLength()/2.0, 0.0)); - Point maxThicknessPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(0,brd.getMaxThickness())); - Point maxRockerPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(0,brd.getMaxRocker())); - Point bottomPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(0,0)); + Point centerPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(brd.getLength() / 2.0, 0.0)); + Point maxThicknessPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(0, brd.getMaxThickness())); + Point maxRockerPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(0, brd.getMaxRocker())); + Point bottomPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(0, 0)); // get metrics from the graphics final FontMetrics metrics = g.getFontMetrics(source.mSlidingInfoFont); // get the height of a line of text in this font and render context final int hgt = metrics.getHeight(); - for(int i = 0; i < 7; i++) - { + for (int i = 0; i < 7; i++) { double pos = 0.0; String label; - if(i < 3) - { - pos = (i==0)?0.001:i*UnitUtils.INCH*UnitUtils.INCHES_PR_FOOT; - label = (i==0)?"":UnitUtils.convertLengthToCurrentUnit(pos, false); - } - else if( i == 3) - { - pos = brd.getLength()/2.0; - label = "Center: " + UnitUtils.convertLengthToCurrentUnit(mBoardSpec.isOverCurveSelected()? brd.getBottom().getPointByCurveLength(pos).x: pos, false); - } - else - { - pos = (mBoardSpec.isOverCurveSelected()?brd.getBottom().getLength():brd.getLength()) - ((i==6)?0.005:(6-i)*UnitUtils.INCH*UnitUtils.INCHES_PR_FOOT); - label = (i==6)?"":UnitUtils.convertLengthToCurrentUnit(-(6-i)*UnitUtils.INCH*UnitUtils.INCHES_PR_FOOT, false); + if (i < 3) { + pos = (i == 0) ? 0.001 : i * UnitUtils.INCH * UnitUtils.INCHES_PR_FOOT; + label = (i == 0) ? "" : UnitUtils.convertLengthToCurrentUnit(pos, false); + } else if (i == 3) { + pos = brd.getLength() / 2.0; + label = "Center: " + UnitUtils.convertLengthToCurrentUnit(mBoardSpec.isOverCurveSelected() ? brd.getBottom().getPointByCurveLength(pos).x : pos, false); + } else { + pos = (mBoardSpec.isOverCurveSelected() ? brd.getBottom().getLength() : brd.getLength()) - ((i == 6) ? 0.005 : (6 - i) * UnitUtils.INCH * UnitUtils.INCHES_PR_FOOT); + label = (i == 6) ? "" : UnitUtils.convertLengthToCurrentUnit(-(6 - i) * UnitUtils.INCH * UnitUtils.INCHES_PR_FOOT, false); } - if(mBoardSpec.isOverCurveSelected()) - { + if (mBoardSpec.isOverCurveSelected()) { pos = brd.getBottom().getPointByCurveLength(pos).x; - if(label != "") + if (label != "") label = label.concat(" O.C"); } - double thickness = brd.getThicknessAtPos(pos); double rocker = brd.getRockerAtPos(pos); @@ -7664,30 +7951,29 @@ else if( i == 3) final int widthOfThicknessString = metrics.stringWidth(thicknessStr); final int widthOfRockerString = metrics.stringWidth(rockerStr); - Point deckPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(pos,rocker+thickness)); - Point rockerPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(pos,rocker)); + Point deckPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(pos, rocker + thickness)); + Point rockerPoint = source.brdCoordinateToScreenCoordinateTo(new Point2D.Double(pos, rocker)); g.setColor(Color.BLACK); - g.drawString(label, deckPoint.x - (labelWidth/2), (maxThicknessPoint.y + maxRockerPoint.y)/2); + g.drawString(label, deckPoint.x - (labelWidth / 2), (maxThicknessPoint.y + maxRockerPoint.y) / 2); g.setColor(Color.RED); - g.drawString(thicknessStr, deckPoint.x - (widthOfThicknessString/2), bottomPoint.y + hgt); + g.drawString(thicknessStr, deckPoint.x - (widthOfThicknessString / 2), bottomPoint.y + hgt); g.drawLine(deckPoint.x, deckPoint.y, rockerPoint.x, rockerPoint.y); g.setColor(Color.BLUE); - g.drawString(rockerStr, deckPoint.x - (widthOfRockerString/2), bottomPoint.y + hgt*2); + g.drawString(rockerStr, deckPoint.x - (widthOfRockerString / 2), bottomPoint.y + hgt * 2); g.drawLine(rockerPoint.x, rockerPoint.y, rockerPoint.x, bottomPoint.y); } } - public void drawOutlineSlidingInfo(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) { + public void drawOutlineSlidingInfo(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { final double width = brd.getWidthAtPos(source.mBrdCoord.x); if (width <= 0.0) @@ -7697,8 +7983,7 @@ public void drawOutlineSlidingInfo(final BoardEdit source, final Graphics2D g, final double mulY = (source.mDrawControl & BezierBoardDrawUtil.FlipY) != 0 ? -1 : 1; String widthStr = LanguageResource.getString("OUTLINESLIDINGINFOWIDTH_STR"); - source.mSlidingInfoString = widthStr - + UnitUtils.convertLengthToCurrentUnit(width, false); + source.mSlidingInfoString = widthStr + UnitUtils.convertLengthToCurrentUnit(width, false); g.setColor(Color.BLUE); @@ -7720,7 +8005,6 @@ public void drawOutlineSlidingInfo(final BoardEdit source, final Graphics2D g, // calculate the size of a box to hold the text with some padding. final Dimension sizeOfWidthStr = new Dimension(advOfWidthStr, hgt + 1); - int textX = source.mScreenCoord.x - (sizeOfWidthStr.width); if (textX < 10) textX = 10; @@ -7728,103 +8012,70 @@ public void drawOutlineSlidingInfo(final BoardEdit source, final Graphics2D g, if (textX + size.width + 10 > dim.width) textX = dim.width - size.width - 10; - if(BoardCAD.getInstance().isPaintingOverCurveMeasurements()) - { + if (BoardCAD.getInstance().isPaintingOverCurveMeasurements()) { source.mSlidingInfoString = LanguageResource.getString("OUTLINESLIDINGINFOOVERCURVE_STR"); g.setColor(Color.BLACK); - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * 4); - - + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * 4); final double fromNose = brd.getFromNoseOverBottomCurveAtPos(source.mBrdCoord.x); final double fromTail = brd.getFromTailOverBottomCurveAtPos(source.mBrdCoord.x); + source.mSlidingInfoString = LanguageResource.getString("OUTLINESLIDINGINFOFROMTAIL_STR") + UnitUtils.convertLengthToCurrentUnit(fromTail, false); - source.mSlidingInfoString = LanguageResource.getString("OUTLINESLIDINGINFOFROMTAIL_STR") - + UnitUtils.convertLengthToCurrentUnit(fromTail, false); - + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * 3); - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * 3); - - source.mSlidingInfoString = LanguageResource.getString("OUTLINESLIDINGINFOFROMNOSE_STR") - +(" ")+ UnitUtils.convertLengthToCurrentUnit(fromNose, false); - - - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * 2); + source.mSlidingInfoString = LanguageResource.getString("OUTLINESLIDINGINFOFROMNOSE_STR") + (" ") + UnitUtils.convertLengthToCurrentUnit(fromNose, false); + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * 2); } - - if(BoardCAD.getInstance().isPaintingMomentOfInertia()) - { + + if (BoardCAD.getInstance().isPaintingMomentOfInertia()) { final double momentOfInertia = brd.getMomentOfInertia(source.mBrdCoord.x, source.mBrdCoord.y); - source.mSlidingInfoString = LanguageResource.getString("SLIDINGINFOMOMENTOFINERTIA_STR") - + UnitUtils.convertMomentOfInertiaToCurrentUnit(momentOfInertia); + source.mSlidingInfoString = LanguageResource.getString("SLIDINGINFOMOMENTOFINERTIA_STR") + UnitUtils.convertMomentOfInertiaToCurrentUnit(momentOfInertia); - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * (BoardCAD.getInstance().isPaintingOverCurveMeasurements()?5:2)); + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * (BoardCAD.getInstance().isPaintingOverCurveMeasurements() ? 5 : 2)); } - source.mSlidingInfoString = LanguageResource.getString("OUTLINESLIDINGINFOWIDTH_STR") - + UnitUtils.convertLengthToCurrentUnit(width, false); + source.mSlidingInfoString = LanguageResource.getString("OUTLINESLIDINGINFOWIDTH_STR") + UnitUtils.convertLengthToCurrentUnit(width, false); g.setColor(Color.BLUE); - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * 1); + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * 1); + final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, 0.0); - final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), - source.mOffsetX, source.mOffsetY, source.mScale); - - source.mSlidingInfoLine.setLine(source.mBrdCoord.x * mulX, -(width / 2) - * mulY, source.mBrdCoord.x * mulX, (width / 2) * mulY); - + source.mSlidingInfoLine.setLine(source.mBrdCoord.x * mulX, -(width / 2) * mulY, source.mBrdCoord.x * mulX, (width / 2) * mulY); g.draw(source.mSlidingInfoLine); g.setTransform(savedTransform); } - public void drawOutlineCrossections(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) { - - final double mulX = (source.mDrawControl & BezierBoardDrawUtil.FlipX) != 0 ? -1 : 1; - final double mulY = (source.mDrawControl & BezierBoardDrawUtil.FlipY) != 0 ? -1 : 1; - + public void drawOutlineCrossections(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { - final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), - source.mOffsetX, source.mOffsetY, source.mScale); + final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, 0.0, (source.mDrawControl & BezierBoardDrawUtil.FlipX) != 0, (source.mDrawControl & BezierBoardDrawUtil.FlipY) != 0); - Line2D.Double crossSectionLine = new Line2D.Double(); // @jve:decl-index=0: + Line2D.Double crossSectionLine = new Line2D.Double(); // @jve:decl-index=0: - BezierBoardCrossSection currentCrossSection = brd.getCurrentCrossSection(); + BezierBoardCrossSection currentCrossSection = brd.getCurrentCrossSection(); final float[] dashPattern = new float[] { 5.0f, 1.0f }; - final BasicStroke bs = (BasicStroke)stroke; - final BasicStroke stapled = new BasicStroke((float) (bs - .getLineWidth() / 2.0), bs.getEndCap(), bs - .getLineJoin(), bs.getMiterLimit(), dashPattern, 0f); + final BasicStroke bs = (BasicStroke) stroke; + final BasicStroke stapled = new BasicStroke((float) (bs.getLineWidth() / 2.0), bs.getEndCap(), bs.getLineJoin(), bs.getMiterLimit(), dashPattern, 0f); final Color noneActiveColor = color.brighter(); - for(int i = 0; i < brd.getCrossSections().size(); i++) - { - BezierBoardCrossSection tmp = brd.getCrossSections().get(i); + for (int i = 0; i < brd.getCrossSections().size(); i++) { + BezierBoardCrossSection tmp = brd.getCrossSections().get(i); - if(tmp == currentCrossSection) - { + if (tmp == currentCrossSection) { g.setColor(color); g.setStroke(stroke); - } - else - { + } else { g.setColor(noneActiveColor); g.setStroke(stapled); } @@ -7835,7 +8086,7 @@ public void drawOutlineCrossections(final BoardEdit source, final Graphics2D g, if (width <= 0.0) continue; - crossSectionLine.setLine(pos * mulX, -(width / 2) * mulY, pos * mulX, (width / 2) * mulY); + crossSectionLine.setLine(pos, -(width / 2), pos, (width / 2)); g.draw(crossSectionLine); } @@ -7843,8 +8094,7 @@ public void drawOutlineCrossections(final BoardEdit source, final Graphics2D g, g.setTransform(savedTransform); } - public void drawProfileSlidingInfo(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) { + public void drawProfileSlidingInfo(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { final double thickness = brd.getThicknessAtPos(source.mBrdCoord.x); if (thickness <= 0.0) @@ -7865,21 +8115,17 @@ public void drawProfileSlidingInfo(final BoardEdit source, final Graphics2D g, final Dimension dim = source.getSize(); String thicknessStr = LanguageResource.getString("PROFILESLIDINGINFOTHICKNESS_STR"); - source.mSlidingInfoString = thicknessStr - + UnitUtils.convertLengthToCurrentUnit(thickness, false); - + source.mSlidingInfoString = thicknessStr + UnitUtils.convertLengthToCurrentUnit(thickness, false); // get the advance of my text in this font and render context final int adv = metrics.stringWidth(source.mSlidingInfoString); - // calculate the size of a box to hold the text with some padding. final Dimension size = new Dimension(adv, hgt + 1); // get the advance of my text in this font and render context final int advOfThicknessStr = metrics.stringWidth(thicknessStr); - // calculate the size of a box to hold the text with some padding. final Dimension sizeOfThicknessStr = new Dimension(advOfThicknessStr, hgt + 1); @@ -7890,117 +8136,86 @@ public void drawProfileSlidingInfo(final BoardEdit source, final Graphics2D g, if (textX + size.width + 10 > dim.width) textX = dim.width - size.width - 10; - g.setColor(Color.BLUE); - - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * 3); + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * 3); g.setColor(Color.RED); - source.mSlidingInfoString = LanguageResource.getString("PROFILESLIDINGINFOROCKER_STR") - + UnitUtils.convertLengthToCurrentUnit(rocker, false); - - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * 2); + source.mSlidingInfoString = LanguageResource.getString("PROFILESLIDINGINFOROCKER_STR") + UnitUtils.convertLengthToCurrentUnit(rocker, false); + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * 2); - source.mSlidingInfoString = LanguageResource.getString("PROFILESLIDINGINFORADIUS_STR") - + UnitUtils.convertLengthToCurrentUnit(radius, true); + source.mSlidingInfoString = LanguageResource.getString("PROFILESLIDINGINFORADIUS_STR") + UnitUtils.convertLengthToCurrentUnit(radius, true); - g.setColor(new Color(102,102,102)); + g.setColor(new Color(102, 102, 102)); - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * 1); + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * 1); - - - if(BoardCAD.getInstance().isPaintingOverCurveMeasurements()) - { + if (BoardCAD.getInstance().isPaintingOverCurveMeasurements()) { source.mSlidingInfoString = LanguageResource.getString("PROFILESLIDINGINFOOVERCURVE_STR"); g.setColor(Color.BLACK); - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * 6); - + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * 6); final double fromNose = brd.getFromNoseOverBottomCurveAtPos(source.mBrdCoord.x); final double fromTail = brd.getFromTailOverBottomCurveAtPos(source.mBrdCoord.x); - source.mSlidingInfoString = LanguageResource.getString("PROFILESLIDINGINFOFROMTAIL_STR") - + UnitUtils.convertLengthToCurrentUnit(fromTail, false); - - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * 5); + source.mSlidingInfoString = LanguageResource.getString("PROFILESLIDINGINFOFROMTAIL_STR") + UnitUtils.convertLengthToCurrentUnit(fromTail, false); + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * 5); - source.mSlidingInfoString = LanguageResource.getString("PROFILESLIDINGINFOFROMNOSE_STR") - + UnitUtils.convertLengthToCurrentUnit(fromNose, false); + source.mSlidingInfoString = LanguageResource.getString("PROFILESLIDINGINFOFROMNOSE_STR") + UnitUtils.convertLengthToCurrentUnit(fromNose, false); - g.drawString(source.mSlidingInfoString, textX, dim.height - - (size.height + 2) * 4); + g.drawString(source.mSlidingInfoString, textX, dim.height - (size.height + 2) * 4); } - final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), - source.mOffsetX, source.mOffsetY, source.mScale); + final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, 0.0); // sets the color of the thickness sliding info bar (inside board) g.setColor(Color.BLUE); - source.mSlidingInfoLine.setLine(source.mBrdCoord.x * mulX, rocker - * mulY, source.mBrdCoord.x * mulX, (rocker + thickness) * mulY); + source.mSlidingInfoLine.setLine(source.mBrdCoord.x * mulX, rocker * mulY, source.mBrdCoord.x * mulX, (rocker + thickness) * mulY); g.draw(source.mSlidingInfoLine); // sets the color of the rocker sliding info bar (outside board) g.setColor(Color.RED); - source.mSlidingInfoLine.setLine(source.mBrdCoord.x * mulX, 0 * mulY, - source.mBrdCoord.x * mulX, rocker * mulY); + source.mSlidingInfoLine.setLine(source.mBrdCoord.x * mulX, 0 * mulY, source.mBrdCoord.x * mulX, rocker * mulY); g.draw(source.mSlidingInfoLine); g.setTransform(savedTransform); - } - public void drawProfileCrossections(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) { + public void drawProfileCrossections(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { final double mulX = (source.mDrawControl & BezierBoardDrawUtil.FlipX) != 0 ? -1 : 1; final double mulY = (source.mDrawControl & BezierBoardDrawUtil.FlipY) != 0 ? -1 : 1; + final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, 0.0); - final AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), - source.mOffsetX, source.mOffsetY, source.mScale); - - Line2D.Double crossSectionLine = new Line2D.Double(); // @jve:decl-index=0: + Line2D.Double crossSectionLine = new Line2D.Double(); // @jve:decl-index=0: - BezierBoardCrossSection currentCrossSection = brd.getCurrentCrossSection(); + BezierBoardCrossSection currentCrossSection = brd.getCurrentCrossSection(); final float[] dashPattern = new float[] { 5.0f, 1.0f }; - final BasicStroke bs = (BasicStroke)stroke; - final BasicStroke stapled = new BasicStroke((float) (bs - .getLineWidth() / 2.0), bs.getEndCap(), bs - .getLineJoin(), bs.getMiterLimit(), dashPattern, 0f); + final BasicStroke bs = (BasicStroke) stroke; + final BasicStroke stapled = new BasicStroke((float) (bs.getLineWidth() / 2.0), bs.getEndCap(), bs.getLineJoin(), bs.getMiterLimit(), dashPattern, 0f); final Color noneActiveColor = color.brighter(); - for(int i = 0; i < brd.getCrossSections().size(); i++) - { - BezierBoardCrossSection tmp = brd.getCrossSections().get(i); + for (int i = 0; i < brd.getCrossSections().size(); i++) { + BezierBoardCrossSection tmp = brd.getCrossSections().get(i); - if(tmp == currentCrossSection) - { + if (tmp == currentCrossSection) { g.setColor(color); g.setStroke(stroke); - } - else - { + } else { g.setColor(noneActiveColor); g.setStroke(stapled); } @@ -8012,8 +8227,7 @@ public void drawProfileCrossections(final BoardEdit source, final Graphics2D g, if (deck <= 0.0) continue; - crossSectionLine.setLine(pos * mulX, deck * mulY, - pos * mulX, rocker * mulY); + crossSectionLine.setLine(pos * mulX, deck * mulY, pos * mulX, rocker * mulY); g.draw(crossSectionLine); } @@ -8021,78 +8235,44 @@ public void drawProfileCrossections(final BoardEdit source, final Graphics2D g, g.setTransform(savedTransform); } - public void drawOutlineFlowlines(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) - { - BezierBoardDrawUtil.paintOutlineFlowLines(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, color, stroke, brd, (source.mDrawControl&BezierBoardDrawUtil.FlipX)!=0, true); + public void drawOutlineFlowlines(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { + BezierBoardDrawUtil.paintOutlineFlowLines(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, 0.0, color, stroke, brd, (source.mDrawControl & BezierBoardDrawUtil.FlipX) != 0, true); } - public void drawOutlineTuckUnderLine(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) - { - BezierBoardDrawUtil.paintOutlineTuckUnderLine(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, color, stroke, brd, (source.mDrawControl&BezierBoardDrawUtil.FlipX)!=0, true); + public void drawOutlineTuckUnderLine(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { + BezierBoardDrawUtil.paintOutlineTuckUnderLine(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, 0.0, color, stroke, brd, (source.mDrawControl & BezierBoardDrawUtil.FlipX) != 0, true); } - public void drawProfileFlowlines(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) - { - BezierBoardDrawUtil.paintProfileFlowLines(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, color, stroke, brd, (source.mDrawControl&BezierBoardDrawUtil.FlipX)!=0, true); + public void drawProfileFlowlines(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { + BezierBoardDrawUtil.paintProfileFlowLines(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, 0.0, color, stroke, brd, (source.mDrawControl & BezierBoardDrawUtil.FlipX) != 0, true); } - public void drawProfileApexline(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) - { - BezierBoardDrawUtil.paintProfileApexline(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, color, stroke, brd, (source.mDrawControl&BezierBoardDrawUtil.FlipX)!=0, true); + public void drawProfileApexline(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { + BezierBoardDrawUtil.paintProfileApexline(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, 0.0, color, stroke, brd, (source.mDrawControl & BezierBoardDrawUtil.FlipX) != 0, true); } - public void drawProfileTuckUnderLine(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) - { - BezierBoardDrawUtil.paintProfileTuckUnderLine(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, color, stroke, brd, (source.mDrawControl&BezierBoardDrawUtil.FlipX)!=0, true); + public void drawProfileTuckUnderLine(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { + BezierBoardDrawUtil.paintProfileTuckUnderLine(new JavaDraw(g), source.mOffsetX, source.mOffsetY, source.mScale, 0.0, color, stroke, brd, (source.mDrawControl & BezierBoardDrawUtil.FlipX) != 0, true); } - public void drawCrossSectionCenterline(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) - { + public void drawCrossSectionCenterline(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { boolean isCompensatedForRocker = BoardCAD.getInstance().isUsingOffsetInterpolation(); - BezierBoardDrawUtil.paintCrossSectionCenterline(new JavaDraw(g), source.mOffsetX, source.mOffsetY + (isCompensatedForRocker?brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition())*source.mScale:0), source.mScale, color, stroke, brd, true, !isCompensatedForRocker); + BezierBoardDrawUtil.paintCrossSectionCenterline(new JavaDraw(g), source.mOffsetX, source.mOffsetY + (isCompensatedForRocker ? brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition()) * source.mScale : 0), source.mScale, 0.0, color, stroke, brd, true, !isCompensatedForRocker); } - public void drawCrossSectionFlowlines(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) - { + public void drawCrossSectionFlowlines(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { boolean isCompensatedForRocker = BoardCAD.getInstance().isUsingOffsetInterpolation(); - BezierBoardDrawUtil.paintCrossSectionFlowLines(new JavaDraw(g), source.mOffsetX, source.mOffsetY + (isCompensatedForRocker?brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition())*source.mScale:0), source.mScale, color, stroke, brd, true, !isCompensatedForRocker); + BezierBoardDrawUtil.paintCrossSectionFlowLines(new JavaDraw(g), source.mOffsetX, source.mOffsetY + (isCompensatedForRocker ? brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition()) * source.mScale : 0), source.mScale, 0.0, color, stroke, brd, true, !isCompensatedForRocker); } - public void drawCrossSectionApexline(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) - { + public void drawCrossSectionApexline(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { boolean isCompensatedForRocker = BoardCAD.getInstance().isUsingOffsetInterpolation(); - BezierBoardDrawUtil.paintCrossSectionApexline(new JavaDraw(g), source.mOffsetX, source.mOffsetY + (isCompensatedForRocker?brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition())*source.mScale:0), source.mScale, color, stroke, brd, true, !isCompensatedForRocker); + BezierBoardDrawUtil.paintCrossSectionApexline(new JavaDraw(g), source.mOffsetX, source.mOffsetY + (isCompensatedForRocker ? brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition()) * source.mScale : 0), source.mScale, 0.0, color, stroke, brd, true, !isCompensatedForRocker); } - public void drawCrossSectionTuckUnderLine(final BoardEdit source, final Graphics2D g, - final Color color, final Stroke stroke, final BezierBoard brd) - { + public void drawCrossSectionTuckUnderLine(final BoardEdit source, final Graphics2D g, final Color color, final Stroke stroke, final BezierBoard brd) { boolean isCompensatedForRocker = BoardCAD.getInstance().isUsingOffsetInterpolation(); - BezierBoardDrawUtil.paintCrossSectionTuckUnderLine(new JavaDraw(g), source.mOffsetX, source.mOffsetY + (isCompensatedForRocker?brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition())*source.mScale:0), source.mScale, color, stroke, brd, true, !isCompensatedForRocker); - } - - protected void updateBezier3DModel() - { - if(getCurrentBrd().isEmpty()) - return; - - double scale = 0.0075; - Transform3D transform = new Transform3D(); - transform.setScale(scale); - transform.setTranslation(new Vector3d(-getCurrentBrd().getLength()*scale/2.0,0.0,0.0)); - transform.setRotation(new AxisAngle4d(1.0, 0.0, 0.0, -Math.PI/2.0)); - mScale.setTransform(transform); - - getCurrentBrd().update3DModel(mBezier3DModel); - mBoardChangedFor3D = false; + BezierBoardDrawUtil.paintCrossSectionTuckUnderLine(new JavaDraw(g), source.mOffsetX, source.mOffsetY + (isCompensatedForRocker ? brd.getRockerAtPos(brd.getCurrentCrossSection().getPosition()) * source.mScale : 0), source.mScale, 0.0, color, stroke, brd, true, !isCompensatedForRocker); } static public Frame findParentFrame(Container container) { @@ -8103,7 +8283,7 @@ static public Frame findParentFrame(Container container) { container = container.getParent(); } - return (Frame) null; + return null; } } @@ -8158,8 +8338,7 @@ public static void displayURL(final String url) { p = Runtime.getRuntime().exec(cmd); } } catch (final InterruptedException x) { - System.err.println("Error bringing up browser, cmd='" + cmd - + "'"); + System.err.println("Error bringing up browser, cmd='" + cmd + "'"); System.err.println("Caught: " + x); } } @@ -8186,7 +8365,7 @@ public static boolean isWindowsPlatform() { } class SetCurrentCommandAction extends AbstractAction { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; BrdCommand mCommand; SetCurrentCommandAction() { @@ -8197,6 +8376,7 @@ class SetCurrentCommandAction extends AbstractAction { mCommand = command; } + @Override public void actionPerformed(final ActionEvent event) { if (BoardCAD.getInstance().getCurrentCommand() != null) { BoardCAD.getInstance().getCurrentCommand().onCurrentChanged(); @@ -8212,16 +8392,17 @@ public void actionPerformed(final ActionEvent event) { } class SetCurrentOneShotCommandAction extends SetCurrentCommandAction { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; + SetCurrentOneShotCommandAction(final BrdCommand command) { super(command); } + @Override public void actionPerformed(final ActionEvent event) { mCommand.setPreviousCommand(BoardCAD.getInstance().getCurrentCommand()); super.actionPerformed(event); } - } diff --git a/boardcad/gui/jdk/BoardCommands.java b/boardcad/gui/jdk/BoardCommands.java deleted file mode 100644 index 84e4e6e..0000000 --- a/boardcad/gui/jdk/BoardCommands.java +++ /dev/null @@ -1,2599 +0,0 @@ -package boardcad.gui.jdk; - -import java.awt.Dimension; -import java.awt.Point; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.event.MouseWheelEvent; -import java.awt.geom.Point2D; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.ListIterator; - -import javax.swing.JFileChooser; -import javax.swing.JOptionPane; - -import board.*; - -import cadcore.*; -import boardcad.i18n.LanguageResource; -import board.readers.*; - -class BrdCommandHistory -{ - LinkedList mCommandHistory = new LinkedList(); - int mCurrentCommand = -1; - private static BrdCommandHistory mInstance = null; - - public static BrdCommandHistory getInstance() - { - if(mInstance == null) { - mInstance = new BrdCommandHistory(); - } - return mInstance; - } - - public void clear() - { - mCommandHistory.clear(); - mCurrentCommand = -1; - } - - public void addCommand(BrdCommand command) - { - if(mCurrentCommand>=0 && mCommandHistory.size() > mCurrentCommand+1) - { - /* Sometimes get java.util.ConcurrentModificationException with this code - * int size = mCommandHistory.size(); - java.util.List toBeRemoved = mCommandHistory.subList(mCurrentCommand+1, size); - mCommandHistory.removeAll(toBeRemoved); - */ - while(mCommandHistory.size() > mCurrentCommand+1) - { - mCommandHistory.removeLast(); - } - } - mCommandHistory.add(command); - mCurrentCommand = mCommandHistory.size()-1; - } - - public void undo() - { - if(mCurrentCommand >= 0) - { - BrdCommand command = mCommandHistory.get(mCurrentCommand--); - if(command == null) - return; - command.undo(); - } - } - - public void redo() - { - if(mCurrentCommand < mCommandHistory.size()-1 && mCommandHistory.size() > 0) - { - BrdCommand command = mCommandHistory.get(++mCurrentCommand); - if(command == null) - return; - command.redo(); - } - } -} - -abstract class BrdCommand extends Object implements Cloneable{ - boolean mCanUndo = true; - BoardEdit mSource = null; - BrdCommand mPreviousCommand = null; - - void setPreviousCommand(BrdCommand previousCommand) - { - mPreviousCommand = previousCommand; - } - - public void doAction() - { - - } - - public void execute() - { - if(canUndo()) - { - BrdCommandHistory.getInstance().addCommand((BrdCommand)this.clone()); - } - - if(mPreviousCommand != null) - { - BoardCAD.getInstance().setCurrentCommand(mPreviousCommand); - } - - }; //Do command including user interactions - - public void setSource(BoardEdit source) - { - mSource = source; - } - - public void redo() - { - if(mSource != null) - { - BoardCAD.getInstance().setSelectedEdit(mSource); - mSource.onBrdChanged(); - BoardCAD.getInstance().onControlPointChanged(); - } - - } - - public void undo() - { - if(mSource != null) - { - BoardCAD.getInstance().setSelectedEdit(mSource); - mSource.onBrdChanged(); - BoardCAD.getInstance().onControlPointChanged(); - } - } - public boolean canUndo(){return mCanUndo;}; - - public Object clone(){ - try { - return super.clone(); - } catch(CloneNotSupportedException e) { - System.out.println("BoardComand.clone() Exception: " + e.toString()); - throw new Error("CloneNotSupportedException in BrdCommand"); - } - } - - public void onSetCurrent() - { - - } - - public void onCurrentChanged() - { - - } - - public abstract String getCommandString(); -} - -class BrdMacroCommand extends BrdCommand { - - LinkedList mBrdCommand; - - BrdMacroCommand() - { - mBrdCommand = new LinkedList(); - } - - public void add(BrdCommand cmd) - { - mBrdCommand.add(cmd); - } - - public void execute() - { - for(Iterator i = mBrdCommand.iterator(); i.hasNext();) - { - ((BrdCommand)i.next()).doAction(); - } - super.execute(); - } - public void redo() - { - for(Iterator i = mBrdCommand.iterator(); i.hasNext();) - ((BrdCommand)i.next()).redo(); - - super.redo(); - } - - public void undo() - { -// Java 6 for(Iterator i = mBrdCommand.descendingIterator(); i.hasNext();) -// ((BrdCommand)i.next()).undo(); - - for(ListIterator i = mBrdCommand.listIterator(mBrdCommand.size()); i.hasPrevious();) - { - ((BrdCommand)i.previous()).undo(); - } - - super.undo(); - } - - public String getCommandString() - { - return LanguageResource.getString("MACROCMD_STR"); - } - -} - - - -class PointEditCommand extends BrdCommand -{ - Point2D.Double mEditedPoint; - Point2D.Double mOriginalPos; - Point2D.Double mNewPos; - - PointEditCommand(Point2D.Double point) - { - mEditedPoint = point; - mOriginalPos = (Point2D.Double)point.clone(); - } - - public void execute(Point2D.Double newPos) - { - mNewPos = (Point2D.Double)newPos.clone(); - redo(); - } - - public void redo() - { - mEditedPoint.setLocation(mNewPos); - } - - public void undo() - { - mEditedPoint.setLocation(mOriginalPos); - } - - public String getCommandString() - { - return LanguageResource.getString("MACROCMD_STR"); - } -} - - -class NurbsEditCommand extends BrdCommand -{ - NurbsBoard oldBoard; - NurbsBoard newBoard; - BoardHandler board_handler; - - NurbsEditCommand() - { - NurbsBoard board; - board_handler=BoardCAD.getInstance().getBoardHandler(); - board=board_handler.getActiveBoard(); - if(board!=null) - oldBoard = (NurbsBoard)board.clone(); - } - - public void execute() - { - NurbsBoard board; - board=board_handler.getActiveBoard(); - if(board!=null) - newBoard = (NurbsBoard)board.clone(); - super.execute(); - } - - public void redo() - { - board_handler.setActiveBoard(newBoard); - } - - public void undo() - { - board_handler.setActiveBoard(oldBoard); - } - - public String getCommandString() - { - return LanguageResource.getString("MACROCMD_STR"); - } -} - - - -abstract class BrdInputCommand extends BrdCommand -{ - public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) - { - } - - public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) - { - } - - public void onRightMouseButtonPressed(BoardEdit source, MouseEvent event) - { - } - - public void onRightMouseButtonReleased(BoardEdit source, MouseEvent event) - { - } - - public void onMouseWheelButtonPressed(BoardEdit source, MouseEvent event) - { - } - - public void onMouseWheelButtonReleased(BoardEdit source, MouseEvent event) - { - } - - public void onMouseMove(BoardEdit source, MouseEvent event) - { - } - - public void onMouseDragged(BoardEdit source, MouseEvent event) - { - } - - - public boolean onKeyEvent(BoardEdit source, KeyEvent event) - { - return false; - } - - public void onMouseWheelMoved(BoardEdit source, MouseWheelEvent e) - { - } -} - - -class BrdPanCommand extends BrdInputCommand -{ - double mOriginalOffsetX; - double mOriginalOffsetY; - Point mPressedPos; - boolean mButtonPressed = true; - - BrdPanCommand() - { - mCanUndo = false; - } - - public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) - { - Point pos = event.getPoint(); - mOriginalOffsetX = source.getOffsetX(); - mOriginalOffsetY = source.getOffsetY(); - mPressedPos = (Point)pos.clone(); - mButtonPressed = true; - } - - - public void onMouseDragged(BoardEdit source, MouseEvent event) - { - Point pos = event.getPoint(); - source.setOffsetX(mOriginalOffsetX + (pos.x - mPressedPos.x)); - source.setOffsetY(mOriginalOffsetY + (pos.y - mPressedPos.y)); - source.repaint(); - } - - public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) - { - mButtonPressed = false; - } - - public boolean onKeyEvent(BoardEdit source, KeyEvent event) - { - if(event.getID() != KeyEvent.KEY_PRESSED) - return false; - - int key = event.getKeyCode(); - - if(key == KeyEvent.VK_LEFT) - { - source.setOffsetX(source.getOffsetX()-(1.0f*source.getScale())); - source.repaint(); - return true; - } - else if(key == KeyEvent.VK_RIGHT) - { - source.setOffsetX(source.getOffsetX()+(1.0f*source.getScale())); - source.repaint(); - return true; - } - if(key == KeyEvent.VK_UP) - { - source.setOffsetY(source.getOffsetY()-(1.0f*source.getScale())); - source.repaint(); - return true; - } - else if(key == KeyEvent.VK_DOWN) - { - source.setOffsetY(source.getOffsetY()+(1.0f*source.getScale())); - source.repaint(); - return true; - } - return false; - } - - public String getCommandString() - { - return LanguageResource.getString("PANCMD_STR"); - } - -} - - - - -class BrdZoomCommand extends BrdInputCommand -{ - Point mClickedPos; - Point mZoomRectCorner; - double mNewScale; - boolean mButtonPressed = false; - - BrdZoomCommand() - { - mCanUndo = false; - - mClickedPos = new Point(); - mZoomRectCorner = new Point(); - } - - public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) - { - Point pos = event.getPoint(); - mClickedPos.setLocation(pos); - mButtonPressed = true; - mNewScale = source.getScale(); - } - - public void onMouseDragged(BoardEdit source, MouseEvent event) - { - Point pos = event.getPoint(); - - zoomSetDims(source, pos); - } - - public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) - { - source.setScale(source.getScale()/mNewScale); - - source.setOffsetX((source.getOffsetX()-mClickedPos.x)/mNewScale); - source.setOffsetY((source.getOffsetY()-mClickedPos.y)/mNewScale); - - source.disableDrawZoomRectangle(); - source.repaint(); - - BoardCAD.getInstance().mLifeSizeButton.getModel().setSelected(false); - - execute(); - } - - public void zoomSetDims(BoardEdit source, Point pos) - { - Dimension dim = source.getSize(); - - double scaleX = (double)Math.abs(pos.x - mClickedPos.x)/(double)dim.width; - double scaleY = (double)Math.abs(pos.y - mClickedPos.y)/(double)dim.height; - double usedScale = (scaleX > scaleY)?scaleX:scaleY; - - mZoomRectCorner.setLocation(mClickedPos.x+(dim.width*usedScale), mClickedPos.y+(dim.height*usedScale)); - - mNewScale = usedScale; - - source.setDrawZoomRectangle(mClickedPos, mZoomRectCorner); - source.repaint(); - } - - public void zoom(BoardEdit source) - { - source.setScale(source.getScale()/mNewScale); - - source.setOffsetX((source.getOffsetX()-mClickedPos.x)/mNewScale); - source.setOffsetY((source.getOffsetY()-mClickedPos.y)/mNewScale); - - source.disableDrawZoomRectangle(); - source.repaint(); - -// BoardCAD.getInstance().mLifeSizeButton.getModel().setSelected(false); - - execute(); - } - - public void zoomInStep(BoardEdit source, boolean fine) - { - Dimension dim = source.getSize(); - Dimension scaledDim = source.getSize(); - scaledDim.width *= (fine?0.99:0.9); - scaledDim.height *= (fine?0.99:0.9); - - Point pos = new Point(); - mClickedPos.x = (dim.width - scaledDim.width)/2; - mClickedPos.y = (dim.height - scaledDim.height)/2; - - pos.x = mClickedPos.x + scaledDim.width; - pos.y = mClickedPos.y + scaledDim.height; - - zoomSetDims(source, pos); - - zoom(source); - } - - public void zoomOutStep(BoardEdit source, boolean fine) - { - Dimension dim = source.getSize(); - Dimension scaledDim = source.getSize(); - scaledDim.width *= (fine?1.01:1.1); - scaledDim.height *= (fine?1.01:1.1); - - Point pos = new Point(); - mClickedPos.x = (dim.width - scaledDim.width)/2; - mClickedPos.y = (dim.height - scaledDim.height)/2; - - pos.x = mClickedPos.x + scaledDim.width; - pos.y = mClickedPos.y + scaledDim.height; - - zoomSetDims(source, pos); - - zoom(source); - } - - public boolean onKeyEvent(BoardEdit source, KeyEvent event) - { - if(event.getID() != KeyEvent.KEY_PRESSED) - return false; - - int key = event.getKeyChar(); - - if(key == '+') - { - zoomInStep(source, event.isAltDown()); - - return true; - } - else if(key == '-') - { - zoomOutStep(source, event.isAltDown()); - - return true; - } - return false; - } - - public String getCommandString() - { - return LanguageResource.getString("ZOOMCMD_STR"); - } - -} - - -class BrdRotateViewCommand extends BrdInputCommand -{ - Point mClickedPos; - Point mZoomRectCorner; - double mNewScale; - boolean mButtonPressed = false; - private static int clicked_x; - private static int clicked_y; - private static int dragged_x; - private static int dragged_y; - - BrdRotateViewCommand() - { - mCanUndo = false; - - mClickedPos = new Point(); - mZoomRectCorner = new Point(); - } - - public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) - { - clicked_x=event.getX(); - clicked_y=event.getY(); - - } - - public void onMouseDragged(BoardEdit source, MouseEvent event) - { - BoardHandler board_handler=BoardCAD.getInstance().getBoardHandler(); - - if(source.mDrawControl == 0) - { - dragged_x=event.getX(); - dragged_y=event.getY(); - double theta2=source.theta+dragged_x-clicked_x; - double[][] m1 = {{Math.cos(-theta2*3.1415/180.0), 0.0, -Math.sin(-theta2*3.1415/180.0)}, - {0.0, 1.0, 0.0}, - {Math.sin(-theta2*3.1415/180.0), 0.0, Math.cos(-theta2*3.1415/180.0)}}; - double zeta2=source.zeta+dragged_y-clicked_y; - double[][] m2 = {{1.0, 0.0, 0.0}, - {0.0, Math.cos(-zeta2*3.1415/180.0), -Math.sin(-zeta2*3.1415/180.0)}, - {0.0, Math.sin(-zeta2*3.1415/180.0), Math.cos(-zeta2*3.1415/180.0)}}; - source.mRotationMatrix=cross_product(m1,m2); - //design_panel.redraw(); - } - } - - public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) - { - - source.theta=source.theta+dragged_x-clicked_x; - source.zeta=source.zeta+dragged_y-clicked_y; - - source.repaint(); - - execute(); - } - - - - public String getCommandString() - { - return LanguageResource.getString("ROTATEVIEWCMD_STR"); - } - - private double[][] cross_product(double[][] m1, double[][] m2) - { - double[][] m=new double[3][3]; - - m[0][0]=m1[0][0]*m2[0][0]+m1[1][0]*m2[0][1]+m1[2][0]*m2[0][2]; - m[1][0]=m1[0][0]*m2[1][0]+m1[1][0]*m2[1][1]+m1[2][0]*m2[1][2]; - m[2][0]=m1[0][0]*m2[2][0]+m1[1][0]*m2[2][1]+m1[2][0]*m2[2][2]; - - m[0][1]=m1[0][1]*m2[0][0]+m1[1][1]*m2[0][1]+m1[2][1]*m2[0][2]; - m[1][1]=m1[0][1]*m2[1][0]+m1[1][1]*m2[1][1]+m1[2][1]*m2[1][2]; - m[2][1]=m1[0][1]*m2[2][0]+m1[1][1]*m2[2][1]+m1[2][1]*m2[2][2]; - - m[0][2]=m1[0][2]*m2[0][0]+m1[1][2]*m2[0][1]+m1[2][2]*m2[0][2]; - m[1][2]=m1[0][2]*m2[1][0]+m1[1][2]*m2[1][1]+m1[2][2]*m2[1][2]; - m[2][2]=m1[0][2]*m2[2][0]+m1[1][2]*m2[2][1]+m1[2][2]*m2[2][2]; - - return m; - - } - - -} - - -class BrdAddGuidePointCommand extends BrdInputCommand -{ - BrdAddGuidePointCommand() - { - mCanUndo = false; - - } - - public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) - { - Point pos = event.getPoint(); - Point2D.Double guidePoint = source.screenCoordinateToBrdCoordinate(pos); - - source.getGuidePoints().add(guidePoint); - source.repaint(); - BoardCAD.getInstance().getGuidePointsDialog().update(); - } - - public String getCommandString() - { - return LanguageResource.getString("ADDGUIDEPOINTCMD_STR"); - } -} - -//Class with functions for storing changes to a brd for undo/redo functionality -//This is to pick up on changes from scaling and translation for fitting rocker to zero -//and fitting cross sections to width and thickness -abstract class BrdAbstractEditCommand extends BrdInputCommand implements Cloneable -{ - class ControlPointChange implements Cloneable - { - BezierKnot mChangedPoint; - BezierKnot mBefore; - BezierKnot mAfter; - - ControlPointChange(BezierKnot point, BezierKnot before, BezierKnot after) - { - mChangedPoint = point; - mBefore = before; - mAfter = after; - } - - void undo() - { - mChangedPoint.set(mBefore); - } - - void redo() - { - mChangedPoint.set(mAfter); - } - - public Object clone() - { - ControlPointChange controlPointChange = null; - try { - controlPointChange = (ControlPointChange)super.clone(); - } catch(CloneNotSupportedException e) { - System.out.println("BrdAbstractEditCommand.clone() Exception: " + e.toString()); - throw new Error("CloneNotSupportedException in BrdAbstractEditCommand"); - } - - controlPointChange.mChangedPoint = (BezierKnot)mChangedPoint; - controlPointChange.mBefore = (BezierKnot)mBefore.clone(); - controlPointChange.mAfter = (BezierKnot)mAfter.clone(); - - return controlPointChange; - } - - - } - - static private ArrayList mPoints = new ArrayList(); - static private ArrayList mBeforeChangePoints = new ArrayList(); - - private ArrayList mChanges; - - void saveBeforeChange(BezierBoard brd) - { - mPoints.clear(); - mBeforeChangePoints.clear(); - mChanges = new ArrayList(); - - BezierSpline currentBezier = null; - BezierKnot point = null; - for(int i=0;i(); - for(int i = 0; i < this.mChanges.size(); i++) - { - abstractEditCommand.mChanges.add((ControlPointChange)this.mChanges.get(i).clone()); - } - - return abstractEditCommand; - } -} - -class BrdEditCommand extends BrdAbstractEditCommand -{ - static double KEY_MOVE_AMOUNT = 1.0f; - -// ArrayList mSelectedControlPointsCopy; - ArrayList mControlPointsBeforeChange; -// ArrayList mControlPointsAfterChange; - Point2D.Double mDragStartPos; - Point2D.Double mDragOffset; - Point mBoxSelectStartPos; - int mWhich = 0; - boolean mIsDragging = false; - boolean mIsKeyEditing = false; - boolean mIsBoxSelecting = false; - int mCurrentKeyCode = 0; - int mRepeat = 1; - - BrdPanCommand mPanCommand = new BrdPanCommand(); - BrdZoomCommand mZoomCommand = new BrdZoomCommand(); - NurbsEditCommand mNurbsCommand = new NurbsEditCommand(); - - boolean mIsPaning = false; - - final double MAX_OFF = 4.0f; - - private static int clicked_x; - private static int clicked_y; - private static int dragged_x; - private static int dragged_y; - protected static boolean is_marked; - - private NurbsPoint p; - - - BrdEditCommand() - { - } - - public void execute() - { - /* mControlPointsAfterChange = new ArrayList(); - for(int i = 0; i < mSelectedControlPointsCopy.size(); i++) - { - mControlPointsAfterChange.add((ControlPoint)mSelectedControlPointsCopy.get(i).clone()); - } - */ - mSource.onBrdChanged(); //adjust rocker to zero and cross sections to width and thickness - super.execute(); - mIsDragging = false; - mIsKeyEditing = false; - mCurrentKeyCode = 0; -// mSelectedControlPointsCopy = null; - mControlPointsBeforeChange = null; -// mControlPointsAfterChange = null; - mDragStartPos = null; - mDragOffset = null; - mSource = null; - mRepeat = 1; - } - - public void onSetCurrent() - { - BoardCAD.getInstance().getControlPointInfo().setEnabled(true); - } - - public void onCurrentChanged() - { - BoardCAD.getInstance().getControlPointInfo().setEnabled(false); - } - - void saveControlPointsBeforeChange(BoardEdit source) - { - ArrayList selectedControlPoints = source.getSelectedControlPoints(); - -// Save the original points - mControlPointsBeforeChange = new ArrayList(); -// mSelectedControlPointsCopy = new ArrayList(); - for(int i = 0; i < selectedControlPoints.size(); i++) - { - mControlPointsBeforeChange.add((BezierKnot)selectedControlPoints.get(i).clone()); -// mSelectedControlPointsCopy.add(selectedControlPoints.get(i)); - } -// mControlPointsAfterChange = null; - super.saveBeforeChange(source.getCurrentBrd()); - } - - public void moveControlPoints(double x_diff, double y_diff, int which) - { - - ArrayList selectedControlPoints = mSource.getSelectedControlPoints(); - if(selectedControlPoints.size() > 1 || which == 0) - { - for(int i = 0; i < selectedControlPoints.size(); i++) - { - BezierKnot sel = selectedControlPoints.get(i); - BezierKnot org = mControlPointsBeforeChange.get(i); - - sel.setControlPointLocation(org.getEndPoint().x+x_diff, org.getEndPoint().y+y_diff); - - } - } - else{ -// We know we only have a single point, so just use it directly - selectedControlPoints.get(0).setLocation(mWhich, mControlPointsBeforeChange.get(0).getPoints()[mWhich].x+x_diff, mControlPointsBeforeChange.get(0).getPoints()[mWhich].y+y_diff); - - if(selectedControlPoints.get(0).isContinous()) - { - - int other = (which ==1)?2:1; - -// Calculate the length of the other end vector - double ox = (double)mControlPointsBeforeChange.get(0).getPoints()[other].x - mControlPointsBeforeChange.get(0).getPoints()[0].x; - double oy = (double)mControlPointsBeforeChange.get(0).getPoints()[other].y - mControlPointsBeforeChange.get(0).getPoints()[0].y; - - double ol = Math.sqrt(ox*ox+oy*oy); - if(ol == 0) - return; //Avoid multiply by zero - -// Length of current - double sx = (double)selectedControlPoints.get(0).getPoints()[which].x - mControlPointsBeforeChange.get(0).getPoints()[0].x; - double sy = (double)selectedControlPoints.get(0).getPoints()[which].y - mControlPointsBeforeChange.get(0).getPoints()[0].y; - - double sl = Math.sqrt(sx*sx+sy*sy); - if(sl == 0) - return; //Avoid division by zero - -// Normalize - sx /= sl; - sy /= sl; - - selectedControlPoints.get(0).setLocation(other, (double)(-sx*ol) + selectedControlPoints.get(0).getPoints()[0].x, - (double)(-sy*ol) + selectedControlPoints.get(0).getPoints()[0].y); - } - - /*Debug - System.out.println("Tangent to Prev angle: " + mSelectedControlPointsCopy.get(0).getTangentToPrevAngle() + " Tangent to Next angle: " + mSelectedControlPointsCopy.get(0).getTangentToNextAngle()); - double a = mSelectedControlPointsCopy.get(0).getTangentToPrevAngle(); - a = Math.abs(Math.PI - a); - double b = mSelectedControlPointsCopy.get(0).getTangentToNextAngle(); - boolean cont = (Math.abs(a-b) < 0.02)?true:false; - System.out.println("a: " + a + " b: " + b + " cont:" + cont); - */ - } - BoardCAD.getInstance().onBrdChanged(); - BoardCAD.getInstance().onControlPointChanged(); - mSource.repaint(); - } - - public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) - { - - //marking nurbs points - - clicked_x=event.getX(); - clicked_y=event.getY(); - - BoardHandler board_handler=BoardCAD.getInstance().getBoardHandler(); - - if(source.mDrawControl == 0) - { - clicked_x=event.getX(); - clicked_y=event.getY(); - board_handler.set_x((clicked_x-source.mOffsetX)/(source.mScale/10)); - board_handler.set_z((clicked_y-source.mOffsetY)/(source.mScale/10)); - is_marked=board_handler.outline_mark(source.mScale/10, source.mRotationMatrix); - if(is_marked) - { - p=new NurbsPoint(board_handler.get_x(), board_handler.get_y(), board_handler.get_z()); - } - } - else if(source.mDrawControl == BezierBoardDrawUtil.MirrorY) - { - board_handler.set_x((clicked_x-source.mOffsetX)/(source.mScale/10)); - board_handler.set_z((clicked_y-source.mOffsetY)/(source.mScale/10)); - is_marked=board_handler.outline_mark(source.mScale/10); - } - else if(source.mDrawControl == BezierBoardDrawUtil.FlipY) - { - board_handler.set_x((clicked_x-source.mOffsetX)/(source.mScale/10)); - board_handler.set_y((-clicked_y+source.mOffsetY)/(source.mScale/10)); - is_marked=board_handler.rocker_mark(source.mScale/10); - } - else if(source.mDrawControl == (BezierBoardDrawUtil.MirrorX | BezierBoardDrawUtil.FlipY)) - { - board_handler.set_z((clicked_x-source.mOffsetX)/(source.mScale/10)); - board_handler.set_y((-clicked_y+source.mOffsetY)/(source.mScale/10)); - is_marked=board_handler.edge_mark(source.mScale/10); - } - - if(is_marked) - { - BoardCAD.getInstance().status_panel.set_point_name(board_handler.get_point_name()); - BoardCAD.getInstance().status_panel.set_coordinates(board_handler.get_x(), board_handler.get_y(), board_handler.get_z()); - mNurbsCommand = new NurbsEditCommand(); - } - - - //marking bezier point - - Point pos = event.getPoint(); - Point2D.Double brdPos = source.screenCoordinateToBrdCoordinate(pos); - - BezierSpline[] splines = source.getActiveBezierSplines(BoardCAD.getInstance().getCurrentBrd()); - if(splines == null) - return; - - BezierKnot bestMatch = null; - boolean hitControlPoint = false; - for(int i = 0; i < splines.length; i++) - { - bestMatch = splines[i].findBestMatch(brdPos); - if(bestMatch != null) - { - mWhich = splines[0].getBestMatchWhich(); - hitControlPoint = (double)brdPos.distance(bestMatch.getPoints()[mWhich]) < (MAX_OFF/source.getScale()); - if(hitControlPoint) - break; - } - } - - if(bestMatch == null) - { - mSource = source; - mIsBoxSelecting = true; - mBoxSelectStartPos = pos; - return; - } - - if(!hitControlPoint) - { - mSource = source; - mIsBoxSelecting = true; - mBoxSelectStartPos = pos; - - if(!(event.isShiftDown() || event.isControlDown())) - { - source.clearSelectedControlPoints(); //If shift is held, don't clear - } - - } - else - { - boolean alreadySelected = source.mSelectedControlPoints.contains(bestMatch); - - if(!alreadySelected && (!(event.isShiftDown() || event.isControlDown())) ) - source.clearSelectedControlPoints(); //If shift or control is held or the ControlPoint is already selected, don't clear - - if(event.isControlDown()) - source.toggleSelectedControlPoint(bestMatch); - else - source.addSelectedControlPoint(bestMatch); - } - - if(hitControlPoint && source.mSelectedControlPoints.contains(bestMatch)) - { - mDragStartPos = source.screenCoordinateToBrdCoordinate(pos); - - mDragOffset = new Point2D.Double(bestMatch.getPoints()[mWhich].x-mDragStartPos.x,bestMatch.getPoints()[mWhich].y-mDragStartPos.y); - - } - - BoardCAD.getInstance().onControlPointChanged(); - source.repaint(); - BoardCAD.getInstance().redraw(); - - } - - - public void onMouseDragged(BoardEdit source, MouseEvent event) - { - - - //dragging nurbs points - -// clicked_x=event.getX(); -// clicked_y=event.getY(); - - BoardHandler board_handler=BoardCAD.getInstance().getBoardHandler(); - - if(is_marked) - { - if(source.mDrawControl == 0) - { - - double[][] m=invert(source.mRotationMatrix); - double myy=(source.mRotationMatrix[1][0]*p.x+source.mRotationMatrix[1][1]*p.y+source.mRotationMatrix[1][2]*p.z); - - board_handler.set_x( m[0][0]*(event.getX()-source.mOffsetX)/(source.mScale/10) + m[0][1]*myy + m[0][2]*(event.getY()-source.mOffsetY)/(source.mScale/10) );// + m[0][2]*100); - board_handler.set_y( m[1][0]*(event.getX()-source.mOffsetX)/(source.mScale/10) + m[1][1]*myy + m[1][2]*(event.getY()-source.mOffsetY)/(source.mScale/10) );// + m[1][2]*100); - board_handler.set_z( m[2][0]*(event.getX()-source.mOffsetX)/(source.mScale/10) + m[2][1]*myy + m[2][2]*(event.getY()-source.mOffsetY)/(source.mScale/10) );// + m[2][2]*100); - - board_handler.set_point(source.mRotationMatrix); - } - else if(source.mDrawControl == BezierBoardDrawUtil.MirrorY) - { - if(!BoardCAD.getInstance().mIsLockedX.getState()) - board_handler.set_x((event.getX()-source.mOffsetX)/(source.mScale/10)); - if(!BoardCAD.getInstance().mIsLockedZ.getState()) - board_handler.set_z((event.getY()-source.mOffsetY)/(source.mScale/10)); - board_handler.set_point(); - } - else if(source.mDrawControl == BezierBoardDrawUtil.FlipY) - { - - if(!BoardCAD.getInstance().mIsLockedX.getState()) - board_handler.set_x((event.getX()-source.mOffsetX)/(source.mScale/10)); - if(!BoardCAD.getInstance().mIsLockedY.getState()) - board_handler.set_y((source.mOffsetY-event.getY())/(source.mScale/10)); - board_handler.set_point(); - } - else if(source.mDrawControl == (BezierBoardDrawUtil.MirrorX | BezierBoardDrawUtil.FlipY)) - { - if(!BoardCAD.getInstance().mIsLockedY.getState()) - board_handler.set_y((-event.getY()+source.mOffsetY)/(source.mScale/10)); - if(!BoardCAD.getInstance().mIsLockedZ.getState()) - board_handler.set_z((event.getX()-source.mOffsetX)/(source.mScale/10)); - board_handler.set_point(); - } - - BoardCAD.getInstance().redraw(); - } - - - //dragging bezier points - - - if(mIsKeyEditing) - return; - - if(mIsPaning) - { - mPanCommand.onMouseDragged(source, event); - return; - } - - if(mIsBoxSelecting) - { - mSource.setDrawZoomRectangle(mBoxSelectStartPos, event.getPoint()); - - return; - } - - ArrayList selectedControlPoints = source.getSelectedControlPoints(); - if(selectedControlPoints.size() == 0) - return; - - Point pos = event.getPoint(); - Point2D.Double brdPos = source.screenCoordinateToBrdCoordinate(pos); - - if(mIsDragging == false) - { - /* BezierPatch ControlPoints = source.getBezierControlPoints(BoardCAD.getInstance().getCurrentBrd()); - ControlPoint bestMatch = ControlPoints.findBestMatch(brdPos); - mWhich = ControlPoints.getBestMatchWhich(); - - double distance = (double)brdPos.distance(bestMatch.mPoints[mWhich]); - - if(distance > (MAX_OFF/source.getScale()) || bestMatch == null) - return; //trying to drag an unselected point - - if(!selectedControlPoints.contains(bestMatch)) - return; //trying to drag an unselected point - - mDragStartPos = source.screenCoordinateToBrdCoordinate(pos); - - mDragOffset = new Point2D.Double(bestMatch.mPoints[mWhich].x-mDragStartPos.x,bestMatch.mPoints[mWhich].y-mDragStartPos.y); - */ - saveControlPointsBeforeChange(source); - - mIsDragging = true; - mSource = source; - } - - brdPos.x += mDragOffset.x; - brdPos.y += mDragOffset.y; - - double x_diff = (brdPos.x - mDragStartPos.x)*(event.isAltDown()?.1f:1f); - double y_diff = (brdPos.y - mDragStartPos.y)*(event.isAltDown()?.1f:1f); - - moveControlPoints(x_diff, y_diff, mWhich); - - - } - - public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) - { - if(is_marked) - { - mNurbsCommand.execute(); - is_marked=false; - } - - if(mIsBoxSelecting) - { - mSource.disableDrawZoomRectangle(); - - Point pos = event.getPoint(); - Point2D.Double boxStartPos = source.screenCoordinateToBrdCoordinate(mBoxSelectStartPos); - Point2D.Double boxEndPos = source.screenCoordinateToBrdCoordinate(pos); - - if(boxStartPos.x > boxEndPos.x) - { - double x = boxStartPos.x; - boxStartPos.x = boxEndPos.x; - boxEndPos.x = x; - } - - if(boxStartPos.y > boxEndPos.y) - { - double y = boxStartPos.y; - boxStartPos.y = boxEndPos.y; - boxEndPos.y = y; - } - - BezierSpline[] splines = source.getActiveBezierSplines(BoardCAD.getInstance().getCurrentBrd()); - if(splines == null) - return; - - - for(int k = 0; k < splines.length; k++) - { - for(int i = 0; i < splines[k].getNrOfControlPoints(); i++) - { - BezierKnot point = splines[k].getControlPoint(i); - for(int j = 0; j < 3; j++) - { - Point2D.Double p = point.getPoints()[j]; - - if(p.x > boxStartPos.x && p.x < boxEndPos.x && p.y > boxStartPos.y && p.y < boxEndPos.y ) //Check within box - { - mWhich = j; - - if(event.isControlDown()) - source.toggleSelectedControlPoint(point); - else - source.addSelectedControlPoint(point); - - break; - } - } - } - } - - BoardCAD.getInstance().onControlPointChanged(); - source.repaint(); - mIsBoxSelecting = false; - } - - ArrayList selectedControlPoints = source.getSelectedControlPoints(); - if(selectedControlPoints.size() == 0) - return; - - if(mIsDragging == true) - { - execute(); - } - } - - public void onMouseWheelMoved(BoardEdit source, MouseWheelEvent event) - { - int scroll = event.getWheelRotation(); - - int steps = Math.abs(scroll); - for(int i = 0; i < steps; i++) - { - if(scroll < 0) - { - mZoomCommand.zoomInStep(source, event.isAltDown()); - } - else - { - mZoomCommand.zoomOutStep(source, event.isAltDown()); - } - - } - event.consume(); - } - - public void onMouseWheelButtonPressed(BoardEdit source, MouseEvent event) - { - mPanCommand.onLeftMouseButtonPressed(source, event); - mIsPaning = true; - } - - public void onMouseWheelButtonReleased(BoardEdit source, MouseEvent event) - { - mPanCommand.onLeftMouseButtonReleased(source, event); - mIsPaning = false; - } - - public boolean onKeyEvent(BoardEdit source, KeyEvent event) - { - if(mIsDragging) - return false; - - ArrayList selectedControlPoints = source.getSelectedControlPoints(); - if(selectedControlPoints.size() == 0) - return false; - - double mulX = ((source.mDrawControl&(BezierBoardDrawUtil.FlipX)) != 0)?-1.0f:1.0f; - double mulY = ((source.mDrawControl&(BezierBoardDrawUtil.FlipY)) != 0)?-1.0f:1.0f; - - if(event.getID() == KeyEvent.KEY_PRESSED) - { - int key = event.getKeyCode(); - - double x_diff = 0; - double y_diff = 0; - double movement = (KEY_MOVE_AMOUNT/source.getScale())*(event.isAltDown()?.1f:1f); - -// Length of current - double sx; - double sy; - if(mControlPointsBeforeChange == null || mControlPointsBeforeChange.size() == 0) - { - sx = (double)selectedControlPoints.get(0).getPoints()[mWhich].x - selectedControlPoints.get(0).getPoints()[0].x; - sy = (double)selectedControlPoints.get(0).getPoints()[mWhich].y - selectedControlPoints.get(0).getPoints()[0].y; - } - else - { - sx = (double)mControlPointsBeforeChange.get(0).getPoints()[mWhich].x - mControlPointsBeforeChange.get(0).getPoints()[0].x; - sy = (double)mControlPointsBeforeChange.get(0).getPoints()[mWhich].y - mControlPointsBeforeChange.get(0).getPoints()[0].y; - } - - double sl = Math.sqrt(sx*sx+sy*sy); - -// Normalize - double snx = sx/sl; - double sny = sy/sl; - - switch(key) - { - case KeyEvent.VK_LESS: - if(selectedControlPoints.size() > 1 || mIsKeyEditing == true) - return false; - - --mWhich; - if(mWhich < 0) - mWhich = 2; - - source.repaint(); - break; - - case KeyEvent.VK_C: - if(selectedControlPoints.size() > 1 || mIsKeyEditing == true) - return false; - - BezierSpline[] splines = source.getActiveBezierSplines(BoardCAD.getInstance().getCurrentBrd()); - if(splines == null) - return false; - - for(int i = 0; i < splines.length; i++) - { - int currentIndex = splines[i].indexOf(selectedControlPoints.get(0)); - if(currentIndex == -1) - continue; - - int newIndex = ++currentIndex%splines[i].getNrOfControlPoints(); - - selectedControlPoints.clear(); - - selectedControlPoints.add(splines[i].getControlPoint(newIndex)); - - source.repaint(); - } - break; - - case KeyEvent.VK_LEFT: - x_diff = -movement*mulX*mRepeat; - break; - - case KeyEvent.VK_RIGHT: - x_diff = movement*mulX*mRepeat; - break; - - case KeyEvent.VK_UP: - y_diff = -movement*mulY*mRepeat; - break; - - case KeyEvent.VK_DOWN: - y_diff = movement*mulY*mRepeat; - break; - - case KeyEvent.VK_E: - case KeyEvent.VK_R: - if(mWhich == 0 || selectedControlPoints.size() > 1) - return false; - - x_diff = (double)(snx*movement*((key==KeyEvent.VK_R)?-1.0f:1.0f))*mRepeat; - y_diff = (double)(sny*movement*((key==KeyEvent.VK_R)?-1.0f:1.0f))*mRepeat; - break; - - case KeyEvent.VK_Q: - case KeyEvent.VK_W: - if(mWhich == 0 || selectedControlPoints.size() > 1) - return false; - - double angle = (((double)Math.PI/180.0f)*mRepeat)*((key==KeyEvent.VK_Q)?-1.0f:1.0f)*(event.isAltDown()?.1f:1f); - x_diff = (double)((Math.cos(angle)*sx - Math.sin(angle)*sy) - sx); - y_diff = (double)((Math.sin(angle)*sx + Math.cos(angle)*sy) - sy); - break; - - default: - return false; - } - - if(mIsKeyEditing == false) - { - saveControlPointsBeforeChange(source); - - mIsKeyEditing = true; - mCurrentKeyCode = key; - - mRepeat = 1; - - mSource = source; - } - - mRepeat++; - - moveControlPoints(x_diff, y_diff, mWhich); - - BoardCAD.getInstance().onControlPointChanged(); - source.repaint(); - return true; - } - else if(event.getID() == KeyEvent.KEY_RELEASED) - { - if(mIsKeyEditing == true) - { - if(mCurrentKeyCode == event.getKeyCode()) - { - execute(); - } - - } - - } - return false; - } - - public void setContinous(BoardEdit source, boolean continous) - { - if(source.getSelectedControlPoints().size() == 0) - return; - - mSource = source; - - saveControlPointsBeforeChange(mSource); - - mSource.getSelectedControlPoints().get(0).setContinous(continous); - - moveControlPoints(0, 0, (mWhich == 0)?1:mWhich); //If endpoint selected, select tangent - - execute(); - - } - - public void setControlPoint(BoardEdit source, Point2D.Double pos) - { - mSource = source; - - saveControlPointsBeforeChange(mSource); - - double dx = pos.x - mControlPointsBeforeChange.get(0).getPoints()[mWhich].x; - double dy = pos.y - mControlPointsBeforeChange.get(0).getPoints()[mWhich].y; - - moveControlPoints(dx, dy, mWhich); - - execute(); - - } - - public void rotateControlPoint(BoardEdit source, double targetAngle) - { - mSource = source; - - saveControlPointsBeforeChange(mSource); - - ArrayList selectedControlPoints = source.getSelectedControlPoints(); - if(mWhich == 0 || selectedControlPoints.size() > 1) - return; - - double sx = (double)selectedControlPoints.get(0).getPoints()[mWhich].x - selectedControlPoints.get(0).getPoints()[0].x; - double sy = (double)selectedControlPoints.get(0).getPoints()[mWhich].y - selectedControlPoints.get(0).getPoints()[0].y; - - Point2D.Double horAxis = new Point2D.Double(1.0,0.0); - Point2D.Double pointVec = new Point2D.Double(sx,sy); - - double pointAngle = VecMath.getVecAngle(horAxis, pointVec); - - double rotAngle = targetAngle - pointAngle; - - double x_diff = (double)((Math.cos(rotAngle)*sx - Math.sin(rotAngle)*sy) - sx); - double y_diff = (double)((Math.sin(rotAngle)*sx + Math.cos(rotAngle)*sy) - sy); - - moveControlPoints(x_diff, y_diff, mWhich); - - BoardCAD.getInstance().onControlPointChanged(); - execute(); - } - - public void rotateControlPointToHorizontal(BoardEdit source) - { - ArrayList selectedControlPoints = source.getSelectedControlPoints(); - if(selectedControlPoints.size() != 1) - return; - - mSource = source; - - saveControlPointsBeforeChange(mSource); - - BezierKnot current = selectedControlPoints.get(0); - - double nextLength = current.getTangentToNextLength(); - double prevLength = current.getTangentToPrevLength(); - double x = current.getEndPoint().x; - double y = current.getEndPoint().y; - - double tanPrevSign = (current.getTangentToPrev().x-x>0)?1:-1; - double tanNextSign = (current.getTangentToNext().x-x>=0)?1:-1; - - if(mWhich == 0 || mWhich == 1) - { - current.setTangentToPrev((prevLength*tanPrevSign)+x, y); - if(current.isContinous()) - { - current.setTangentToNext((-nextLength*tanPrevSign)+x, y); - } - } - else if(mWhich == 2 || current.isContinous()) - { - current.setTangentToNext((nextLength*tanNextSign)+x, y); - if(current.isContinous()) - { - current.setTangentToPrev((-prevLength*tanNextSign)+x, y); - } - } - - BoardCAD.getInstance().onControlPointChanged(); - execute(); - } - - public void rotateControlPointToVertical(BoardEdit source) - { - ArrayList selectedControlPoints = source.getSelectedControlPoints(); - if(selectedControlPoints.size() != 1) - return; - - mSource = source; - - saveControlPointsBeforeChange(mSource); - - BezierKnot current = selectedControlPoints.get(0); - - double nextLength = current.getTangentToNextLength(); - double prevLength = current.getTangentToPrevLength(); - double x = current.getEndPoint().x; - double y = current.getEndPoint().y; - - double tanPrevSign = (current.getTangentToPrev().y-y>0)?1:-1; - double tanNextSign = (current.getTangentToNext().y-y>=0)?1:-1; - - if(mWhich == 0 || mWhich == 1) - { - current.setTangentToPrev(x, (prevLength*tanPrevSign)+y); - if(current.isContinous()) - { - current.setTangentToNext(x, (-nextLength*tanPrevSign)+y); - } - } - if(mWhich == 0 || mWhich == 2) - { - current.setTangentToNext(x, (nextLength*tanNextSign)+y); - if(current.isContinous()) - { - current.setTangentToPrev(x, (-prevLength*tanNextSign)+y); - - } - } - - BoardCAD.getInstance().onControlPointChanged(); - execute(); - } - - public void redo() - { - /* for(int i = 0; i < mSelectedControlPointsCopy.size(); i++) - { - mSelectedControlPointsCopy.get(i).set(mControlPointsAfterChange.get(i)); - } - */ super.redo(); - } - - public void undo() - { - /* for(int i = 0; i < mSelectedControlPointsCopy.size(); i++) - { - mSelectedControlPointsCopy.get(i).set(mControlPointsBeforeChange.get(i)); - } - */ super.undo(); - } - - public Object clone(){ - BrdEditCommand cmd = null; - - cmd = (BrdEditCommand)super.clone(); - -// The arrays are instansiated in this class so there is no need to copy them - - return cmd; - } - - public String getCommandString() - { - return LanguageResource.getString("EDITCMD_STR"); - } - - - private double[][] invert(double[][] a) - { - /* - - | a11 a12 a13 |-1 | a33a22-a32a23 -(a33a12-a32a13) a23a12-a22a13 | - | a21 a22 a23 | = 1/DET(A) * | -(a33a21-a31a23) a33a11-a31a13 -(a23a11-a21a13) | - | a31 a32 a33 | | a32a21-a31a22 -(a32a11-a31a12) a22a11-a21a12 | - - DET(A) = a11(a33a22-a32a23)-a21(a33a12-a32a13)+a31(a23a12-a22a13) - - */ - - double det=a[0][0]*(a[2][2]*a[1][1]-a[2][1]*a[1][2])-a[1][0]*(a[2][2]*a[0][1]-a[2][1]*a[0][2])+a[2][0]*(a[1][2]*a[0][1]-a[1][1]*a[0][2]); - - double[][] b={ {(a[2][2]*a[1][1]-a[2][1]*a[1][2])/det, -(a[2][2]*a[0][1]-a[2][1]*a[0][2])/det, (a[1][2]*a[0][1]-a[1][1]*a[0][2])/det }, - {-(a[2][2]*a[1][0]-a[2][0]*a[1][2])/det, (a[2][2]*a[0][0]-a[2][0]*a[0][2])/det, -(a[1][2]*a[0][0]-a[1][0]*a[0][2])/det }, - {(a[2][1]*a[1][0]-a[2][0]*a[1][1])/det, -(a[2][1]*a[0][0]-a[2][0]*a[0][1])/det, (a[1][1]*a[0][0]-a[1][0]*a[0][1])/det }}; - - - return b; - - - } - - private double[][] cross_product(double[][] m1, double[][] m2) - { - double[][] m=new double[3][3]; - - m[0][0]=m1[0][0]*m2[0][0]+m1[1][0]*m2[0][1]+m1[2][0]*m2[0][2]; - m[1][0]=m1[0][0]*m2[1][0]+m1[1][0]*m2[1][1]+m1[2][0]*m2[1][2]; - m[2][0]=m1[0][0]*m2[2][0]+m1[1][0]*m2[2][1]+m1[2][0]*m2[2][2]; - - m[0][1]=m1[0][1]*m2[0][0]+m1[1][1]*m2[0][1]+m1[2][1]*m2[0][2]; - m[1][1]=m1[0][1]*m2[1][0]+m1[1][1]*m2[1][1]+m1[2][1]*m2[1][2]; - m[2][1]=m1[0][1]*m2[2][0]+m1[1][1]*m2[2][1]+m1[2][1]*m2[2][2]; - - m[0][2]=m1[0][2]*m2[0][0]+m1[1][2]*m2[0][1]+m1[2][2]*m2[0][2]; - m[1][2]=m1[0][2]*m2[1][0]+m1[1][2]*m2[1][1]+m1[2][2]*m2[1][2]; - m[2][2]=m1[0][2]*m2[2][0]+m1[1][2]*m2[2][1]+m1[2][2]*m2[2][2]; - - return m; - - } - -} - -class BrdAddControlPointCommand extends BrdAbstractEditCommand -{ - static double K = 1.0f; - - private int mIndex = 0; - private BezierKnot mNewControlPoint = null; - private BezierSpline mSpline; - - - BrdAddControlPointCommand() - { - } - - public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) - { - super.saveBeforeChange(source.getCurrentBrd()); - - Point pos = event.getPoint(); - Point2D.Double brdPos = source.screenCoordinateToBrdCoordinate(pos); - - BezierSpline[] splines = source.getActiveBezierSplines(source.getCurrentBrd()); - mNewControlPoint = new BezierKnot(); - - for(int i = 0; i < splines.length; i++) - { - mIndex = splines[i].getSplitControlPoint(brdPos, mNewControlPoint); - - if(mIndex < 0) - continue; - - mSpline = splines[i]; - - mSpline.insert(mIndex, mNewControlPoint); - - Point2D.Double tmp = new Point2D.Double(); - - BezierKnot prev = mSpline.getControlPoint(mIndex-1); - BezierKnot next = mSpline.getControlPoint(mIndex+1); - - BezierCurve tmpCurve = new BezierCurve(prev, next); - - double t = tmpCurve.getClosestT(brdPos); - - VecMath.subVector(prev.getPoints()[0],prev.getPoints()[2],tmp); - VecMath.scaleVector(tmp, t); - VecMath.addVector(prev.getPoints()[0],tmp,prev.getPoints()[2]); - - VecMath.subVector(next.getPoints()[1],next.getPoints()[0],tmp); - VecMath.scaleVector(tmp, t-1); - VecMath.addVector(next.getPoints()[0],tmp,next.getPoints()[1]); - - source.onBrdChanged(); - - execute(); - - source.repaint(); - } - - } - - public void redo() - { - mSpline.insert(mIndex, mNewControlPoint); - - super.redo(); - } - - public void undo() - { - mSpline.remove(mIndex); - - super.undo(); - } - - public String getCommandString() - { - return LanguageResource.getString("ADDCONTROLPOINTCMD_STR"); - } -} - -class BrdDeleteControlPointCommand extends BrdAbstractEditCommand -{ - BezierKnot mDeletedControlPoint; - BezierSpline mControlPoints; - int mIndex; - - BrdDeleteControlPointCommand(BoardEdit source, BezierKnot ControlPoint, BezierSpline ControlPoints) - { - mSource = source; - - mDeletedControlPoint = ControlPoint; - - mControlPoints = ControlPoints; - } - - public void doAction() - { - super.saveBeforeChange(mSource.getCurrentBrd()); - - mSource.mSelectedControlPoints.remove(mDeletedControlPoint); - - super.removePoint(mDeletedControlPoint); - - mIndex = mControlPoints.indexOf(mDeletedControlPoint); - BezierKnot prev = mControlPoints.getControlPoint(mIndex-1); - BezierKnot next = mControlPoints.getControlPoint(mIndex+1); - - BezierCurve tmpCurve = new BezierCurve(prev, next); - - double t = tmpCurve.getClosestT(mDeletedControlPoint.getEndPoint()); - if(t != 0 && t != 1) //To prevent divide by zero - { - Point2D.Double tmp = new Point2D.Double(); - - VecMath.subVector(prev.getPoints()[0],prev.getPoints()[2],tmp); - VecMath.scaleVector(tmp, 1/(t)); - VecMath.addVector(prev.getPoints()[0],tmp,prev.getPoints()[2]); - - VecMath.subVector(next.getPoints()[0],next.getPoints()[1],tmp); - VecMath.scaleVector(tmp, 1/(1-t)); - VecMath.addVector(next.getPoints()[0],tmp,next.getPoints()[1]); - } - - - mControlPoints.remove(mDeletedControlPoint); - - super.saveChanges(); - } - - public void execute() - { - doAction(); - - mSource.onBrdChanged(); - - super.execute(); - } - - public void undo() - { - mControlPoints.insert(mIndex, mDeletedControlPoint); - - super.undo(); - } - - public void redo() - { - mControlPoints.remove(mDeletedControlPoint); - - super.redo(); - } - - public String getCommandString() - { - return LanguageResource.getString("DELETECONTROLPOINTCMD_STR"); - - } -} - - -class BrdAddCrossSectionCommand extends BrdCommand -{ - double mPos; - BezierBoardCrossSection mNewCrossSection = null; - - - BrdAddCrossSectionCommand(BoardEdit source, double pos) - { - mSource = source; - - mPos = pos; - } - - public void execute() - { - BezierBoard brd = mSource.getCurrentBrd(); - -// mNewCrossSection = (BezierBoardCrossSection)brd.getNearestCrossSection(mPos).clone(); - mNewCrossSection = (BezierBoardCrossSection)brd.getInterpolatedCrossSection(mPos).clone(); - - mNewCrossSection.setPosition(mPos); - - mNewCrossSection.scale(brd.getThicknessAtPos(mPos), brd.getWidthAtPos(mPos)); - - brd.addCrossSection(mNewCrossSection); - - super.execute(); - } - - public void undo() - { - BezierBoard brd = mSource.getCurrentBrd(); - - brd.removeCrossSection(mNewCrossSection); - - super.undo(); - - } - - public void redo() - { - BezierBoard brd = mSource.getCurrentBrd(); - - brd.addCrossSection(mNewCrossSection); - - super.redo(); - } - - public String getCommandString() - { - return LanguageResource.getString("ADDCROSSECTIONCMD_STR"); - } -} - -class BrdRemoveCrossSectionCommand extends BrdCommand -{ - BezierBoardCrossSection mRemovedCrossSection = null; - - - BrdRemoveCrossSectionCommand(BoardEdit source, BezierBoardCrossSection crossSection) - { - mSource = source; - - mRemovedCrossSection = crossSection; - } - - public void execute() - { - BezierBoard brd = mSource.getCurrentBrd(); - - brd.removeCrossSection(mRemovedCrossSection); - - super.execute(); - } - - public void undo() - { - BezierBoard brd = mSource.getCurrentBrd(); - - brd.addCrossSection(mRemovedCrossSection); - - super.undo(); - - } - - public void redo() - { - BezierBoard brd = mSource.getCurrentBrd(); - - brd.removeCrossSection(mRemovedCrossSection); - - super.redo(); - } - - public String getCommandString() - { - return LanguageResource.getString("REMOVECROSSECTIONCMD_STR"); - } -} - -class BrdMoveCrossSectionCommand extends BrdCommand -{ - BezierBoardCrossSection mMovedCrossSection = null; - double mOldPos; - double mNewPos; - - - BrdMoveCrossSectionCommand(BoardEdit source, BezierBoardCrossSection crossSection, double newPos) - { - mSource = source; - mMovedCrossSection = crossSection; - mNewPos = newPos; - } - - public void execute() - { - BezierBoard brd = mSource.getCurrentBrd(); - mMovedCrossSection.setPosition(mNewPos); - brd.sortCrossSections(); - - super.execute(); - - } - - public void undo() - { - BezierBoard brd = mSource.getCurrentBrd(); - mMovedCrossSection.setPosition(mOldPos); - brd.sortCrossSections(); - - super.undo(); - - } - - public void redo() - { - BezierBoard brd = mSource.getCurrentBrd(); - mMovedCrossSection.setPosition(mNewPos); - brd.sortCrossSections(); - - super.redo(); - } - - public String getCommandString() - { - return LanguageResource.getString("MOVECROSSECTIONCMD_STR"); - } -} - -class BrdPasteCrossSectionCommand extends BrdCommand -{ - BezierBoardCrossSection mCrossSection = null; - BezierSpline mOldCrossSectionBezier = null; - BezierSpline mNewCrossSectionBezier = null; - - - BrdPasteCrossSectionCommand(BoardEdit source, BezierBoardCrossSection currentCrossSection, BezierBoardCrossSection copyCrossSection) - { - mSource = source; - mCrossSection = currentCrossSection; - mOldCrossSectionBezier = currentCrossSection.getBezierSpline(); - mNewCrossSectionBezier = (BezierSpline)copyCrossSection.getBezierSpline().clone(); - } - - public void execute() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - double pos = mCrossSection.getPosition(); - - mCrossSection.setBezierSpline(mNewCrossSectionBezier); - - mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); - - super.execute(); - } - - public void undo() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - double pos = mCrossSection.getPosition(); - - mCrossSection.setBezierSpline(mOldCrossSectionBezier); - - mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); - - super.undo(); - } - - public void redo() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - double pos = mCrossSection.getPosition(); - - mCrossSection.setBezierSpline(mNewCrossSectionBezier); - - mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); - - super.redo(); - } - - public String getCommandString() - { - return LanguageResource.getString("PASTECROSSECTIONCMD_STR"); - } -} - -class BrdImportCrossSectionCommand extends BrdCommand -{ - BezierBoardCrossSection mCrossSection = null; - BezierSpline mOldCrossSectionBezier = null; - BezierSpline mNewCrossSectionBezier = null; - - - BrdImportCrossSectionCommand(BoardEdit source) - { - mSource = source; - - } - - public void execute() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - - mCrossSection = brd.getCurrentCrossSection(); - - mOldCrossSectionBezier = mCrossSection.getBezierSpline(); - - double pos = mCrossSection.getPosition(); - - final JFileChooser fc = new JFileChooser(); - - fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - - int returnVal = fc.showOpenDialog(BoardCAD.getInstance().getFrame()); - if (returnVal != JFileChooser.APPROVE_OPTION) - return; - - File file = fc.getSelectedFile(); - - String filename = file.getPath(); // Load and display selection - if(filename == null) - return; - - try - { - if(BrdReader.importCrossection(brd, new BufferedReader(new FileReader(filename))) < 0) - { - throw new FileNotFoundException(); - } - } - catch(Exception e) - { - String str = e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("IMPORTCROSSECTIONFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); - - return; - } - - - mNewCrossSectionBezier = (BezierSpline)brd.getCurrentCrossSection().clone(); - - mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); - - super.execute(); - } - - public void undo() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - double pos = mCrossSection.getPosition(); - - mCrossSection.setBezierSpline(mOldCrossSectionBezier); - - mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); - - super.undo(); - } - - public void redo() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - double pos = mCrossSection.getPosition(); - - mCrossSection.setBezierSpline(mNewCrossSectionBezier); - - mCrossSection.scale(brd.getThicknessAtPos(pos), brd.getWidthAtPos(pos)); - - super.redo(); - } - - public String getCommandString() - { - return LanguageResource.getString("IMPORTCROSSECTIONCMD_STR"); - } -} - -class BrdImportOutlineCommand extends BrdCommand -{ - BezierSpline mOldOutline = null; - BezierSpline mNewOutline = null; - - - BrdImportOutlineCommand(BoardEdit source) - { - mSource = source; - } - - public void execute() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - - final JFileChooser fc = new JFileChooser(); - - fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - - int returnVal = fc.showOpenDialog(BoardCAD.getInstance().getFrame()); - if (returnVal != JFileChooser.APPROVE_OPTION) - return; - - File file = fc.getSelectedFile(); - - String filename = file.getPath(); // Load and display selection - if(filename == null) - return; - - mOldOutline = brd.getOutline(); - - mNewOutline = new BezierSpline(); - brd.setOutline(mNewOutline); - - try - { - if(BrdReader.importOutline(brd, new BufferedReader(new FileReader(filename))) < 0) - { - throw new FileNotFoundException(); - } - } - catch(Exception e) - { - String str = e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("IMPORTOUTLINEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); - - return; - } - - super.execute(); - } - - public void undo() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - - brd.setOutline(mOldOutline); - - super.undo(); - } - - public void redo() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - - brd.setOutline(mNewOutline); - - super.redo(); - } - - public String getCommandString() - { - return LanguageResource.getString("PASTECROSSECTIONCMD_STR"); - } -} - -class BrdImportProfileCommand extends BrdCommand -{ - BezierSpline mOldDeck = null; - BezierSpline mOldBottom = null; - BezierSpline mNewDeck = null; - BezierSpline mNewBottom = null; - - BrdImportProfileCommand(BoardEdit source) - { - mSource = source; - } - - public void execute() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - - final JFileChooser fc = new JFileChooser(); - - fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - - int returnVal = fc.showOpenDialog(BoardCAD.getInstance().getFrame()); - if (returnVal != JFileChooser.APPROVE_OPTION) - return; - - File file = fc.getSelectedFile(); - - String filename = file.getPath(); // Load and display selection - if(filename == null) - return; - - mOldDeck = brd.getDeck(); - mOldBottom = brd.getBottom(); - - mNewDeck = new BezierSpline(); - brd.setDeck(mNewDeck); - mNewBottom = new BezierSpline(); - brd.setBottom(mNewBottom); - - try - { - if(BrdReader.importProfile(brd, new BufferedReader(new FileReader(filename))) < 0) - { - throw new FileNotFoundException(); - } - } - catch(Exception e) - { - String str = e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), str, LanguageResource.getString("IMPORTPROFILEFAILEDTITLE_STR"), JOptionPane.ERROR_MESSAGE); - - return; - } - - super.execute(); - } - - public void undo() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - - brd.setDeck(mOldDeck); - brd.setBottom(mOldBottom); - - super.undo(); - } - - public void redo() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - - brd.setDeck(mNewDeck); - brd.setBottom(mNewBottom); - - super.redo(); - } - - public String getCommandString() - { - return LanguageResource.getString("PASTECROSSECTIONCMD_STR"); - } -} - -class BrdScaleCommand extends BrdCommand -{ - double mOldWidth; - double mOldLength; - double mOldThickness; - double mNewWidth; - double mNewLength; - double mNewThickness; - //double[] mFinsOld; - boolean mScaleFins; - boolean mScaleFinsFactor; - boolean mScaleBottomRocker; - - BrdScaleCommand(BoardEdit source) - { - mSource = source; - } - - public void execute() - { - - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - - ScaleBoardInputDialog dialog = new ScaleBoardInputDialog(BoardCAD.getInstance().getFrame()); - dialog.setModal(true); - //dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); - dialog.setTitle(LanguageResource.getString("SCALEBOARDTITLE_STR")); - dialog.setBoardLength(brd.getLength()); - dialog.setBoardWidth(brd.getMaxWidth()); - dialog.setBoardThick(brd.getMaxThickness()); - - dialog.setVisible(true); - - if(dialog.wasCancelled()) - { - dialog.dispose(); - return; - } - - //mFinsOld=brd.mFins; - mOldLength= brd.getLength(); - mOldWidth = brd.getMaxWidth(); - mOldThickness = brd.getMaxThickness(); - - if(!dialog.scaleThroughFactor()) - { - mNewLength = dialog.getBoardLength(); - mNewWidth = dialog.getBoardWidth(); - mNewThickness = dialog.getBoardThick(); - - mScaleFins = dialog.scaleFins(); - - mScaleBottomRocker = dialog.scaleBottomRocker(); - - boolean overCurve = dialog.useOverCurve(); - - dialog.dispose(); - - if(mNewLength <= 0 || mNewWidth <= 0 || mNewThickness <= 0) - { - JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), LanguageResource.getString("SCALEBOARDINVALIDINPUTERRORMSG_STR"), LanguageResource.getString("SCALEBOARDINVALIDINPUTERRORTITLE_STR"), JOptionPane.ERROR_MESSAGE); - return; - } - - if(!overCurve) - { - if(mScaleBottomRocker) - { - brd.scaleAccordingly(mNewLength,mNewWidth,mNewThickness); - } - else { - brd.scale(mNewLength,mNewWidth,mNewThickness); - } - if(mScaleFins) - { - brd.finScaling(mNewLength/mOldLength,mNewWidth/mOldWidth); - } - } - else - { - double newLengthOverCurve = mNewLength; - double guestimatedNewLength = 0; - for(int i = 0; i < 5; i++) - { - guestimatedNewLength = brd.getLength() * (newLengthOverCurve/brd.getLengthOverCurve()) + 0.01; //cheat by adding 0.1 mm - if(mScaleBottomRocker) - { - brd.scaleAccordingly(guestimatedNewLength, mNewWidth, mNewThickness); - } - else - { - brd.scale(guestimatedNewLength, mNewWidth, mNewThickness); - } - } - if(mScaleFins) - { - brd.finScaling(guestimatedNewLength/mOldLength,mNewWidth/mOldWidth); - } - - //Get the actual new length, used for redo - mNewLength = brd.getLength(); -//...why is the actual length different from the length the user asked for, particularly when "constraint proportions is on"?? - } - - super.execute(); - - BoardCAD.getInstance().onBrdChanged(); - BoardCAD.getInstance().fitAll(); - }else - { //scaleTroughFactor: - - mNewLength = brd.getLength() * dialog.getFactor(); - mNewWidth = brd.getMaxWidth() * dialog.getFactor(); - mNewThickness = brd.getMaxThickness() * dialog.getFactor(); - - mScaleFinsFactor = dialog.scaleFinsFactor(); - - mScaleBottomRocker = true; - - dialog.dispose(); - - if(mNewLength <= 0 || mNewWidth <= 0 || mNewThickness <= 0 || dialog.getFactor()<=0) - { - JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), LanguageResource.getString("SCALEBOARDINVALIDINPUTERRORMSG_STR"), LanguageResource.getString("SCALEBOARDINVALIDINPUTERRORTITLE_STR"), JOptionPane.ERROR_MESSAGE); - return; - } - - brd.scale(mNewLength,mNewWidth,mNewThickness); - if(mScaleFinsFactor) - { - brd.finScaling(dialog.getFactor(),dialog.getFactor()); - } - - super.execute(); - - BoardCAD.getInstance().onBrdChanged(); - BoardCAD.getInstance().fitAll(); - } - } - - public void undo() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - if(mScaleBottomRocker) - { - brd.scaleAccordingly(mOldLength,mOldWidth,mOldThickness); - } - else - { - brd.scale(mOldLength,mOldWidth,mOldThickness); - } - if(mScaleFins || mScaleFinsFactor) - { - brd.finScaling(mOldLength/mNewLength,mOldWidth/mNewWidth); - } - - super.undo(); - - BoardCAD.getInstance().fitAll(); - } - - public void redo() - { - BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); - if(mScaleBottomRocker) - { - brd.scaleAccordingly(mNewLength, mNewWidth, mNewThickness); - } - else - { - brd.scale(mNewLength, mNewWidth, mNewThickness); - } - if(mScaleFins || mScaleFinsFactor) - { - brd.finScaling(mNewLength/mOldLength,mNewWidth/mOldWidth); - } - - super.redo(); - - BoardCAD.getInstance().fitAll(); - } - - public String getCommandString() - { - return LanguageResource.getString("SCALEBOARDCMD_STR"); - } -} - -class BrdSpotCheckCommand extends BrdCommand -{ - double mOldOffsetX; - double mOldOffsetY; - double mOldScale; - - - BrdSpotCheckCommand() - { - } - - public void spotCheck() - { - mSource = BoardCAD.getInstance().getSelectedEdit(); - - mOldOffsetX = mSource.getOffsetX(); - mOldOffsetY = mSource.getOffsetY(); - mOldScale = mSource.getScale(); - - mSource.fitBrd(); - mSource.repaint(); - } - - public void restore() - { - mSource.setOffsetX(mOldOffsetX); - mSource.setOffsetY(mOldOffsetY); - mSource.setScale(mOldScale); - mSource.repaint(); - } - - public String getCommandString() - { - return LanguageResource.getString("SPOTCHECKCMD_STR"); - } - -} - -class SetImageTailCommand extends BrdInputCommand -{ - - SetImageTailCommand() - { - mCanUndo = false; - } - - public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) - { - Point pos = event.getPoint(); - - source.adjustBackgroundImageTail(pos); - - } - - public String getCommandString() - { - return LanguageResource.getString("ADJUSTIMAGETOTAILCMD_STR"); - } - -} - - -class SetImageNoseCommand extends BrdInputCommand -{ - - SetImageNoseCommand() - { - mCanUndo = false; - } - - public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) - { - Point pos = event.getPoint(); - - source.adjustBackgroundImageNose(pos); - - } - - public String getCommandString() - { - return LanguageResource.getString("ADJUSTIMAGETONOSECMD_STR"); - } -} - - -class GhostCommand extends BrdInputCommand -{ - - GhostCommand() - { - mCanUndo = false; - } - - public String getCommandString() - { - return LanguageResource.getString("GHOSTCMD_STR"); - } -} - diff --git a/boardcad/gui/jdk/BoardEdit.java b/boardcad/gui/jdk/BoardEdit.java index 56d6878..24d91af 100644 --- a/boardcad/gui/jdk/BoardEdit.java +++ b/boardcad/gui/jdk/BoardEdit.java @@ -7,7 +7,6 @@ import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.GridLayout; import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; @@ -24,36 +23,36 @@ import javax.swing.BorderFactory; import javax.swing.JComponent; -import javax.swing.JPanel; import javax.swing.JPopupMenu; -import javax.swing.JSplitPane; import javax.swing.event.MouseInputListener; import board.BezierBoard; - import cadcore.BezierKnot; import cadcore.BezierSpline; +import cadcore.MathUtils; import cadcore.UnitUtils; import cadcore.VecMath; +import boardcad.commands.BrdCommand; +import boardcad.commands.BrdInputCommand; import boardcad.i18n.LanguageResource; public class BoardEdit extends JComponent implements AbstractEditor, MouseInputListener, MouseWheelListener { static final long serialVersionUID=1L; - protected double mOffsetX; - protected double mOffsetY; - protected double mScale = 1.0f; - ArrayList mSelectedControlPoints = new ArrayList(); - protected double mGhostOffsetX = 0; - protected double mGhostOffsetY = 0; - protected double mGhostRot = 0; - protected double mOriginalOffsetX = 0; - protected double mOriginalOffsetY = 0; - - protected int mDrawControl = 0; - protected double theta=30; - protected double zeta=45; - - protected double[][] mRotationMatrix; + public double mOffsetX; + public double mOffsetY; + public double mScale = 1.0f; + public ArrayList mSelectedControlPoints = new ArrayList(); + public double mGhostOffsetX = 0; + public double mGhostOffsetY = 0; + public double mGhostRot = 0; + public double mOriginalOffsetX = 0; + public double mOriginalOffsetY = 0; + + public int mDrawControl = 0; + public double theta=30; + public double zeta=45; + + public double[][] mRotationMatrix; double BORDER = 2; //% of width @@ -97,18 +96,20 @@ public class BoardEdit extends JComponent implements AbstractEditor, MouseInputL protected double mPreviousOffsetX=0.0; protected double mPreviousOffsetY=0.0; + public boolean mIsCrossSectionEdit=false; + public BoardEdit() { super(); - double[][] m1 = {{Math.cos(-theta*3.1415/180.0), 0.0, -Math.sin(-theta*3.1415/180.0)}, + double[][] m1 = {{Math.cos(-theta*Math.PI/180.0), 0.0, -Math.sin(-theta*Math.PI/180.0)}, {0.0, 1.0, 0.0}, - {Math.sin(-theta*3.1415/180.0), 0.0, Math.cos(-theta*3.1415/180.0)}}; + {Math.sin(-theta*Math.PI/180.0), 0.0, Math.cos(-theta*Math.PI/180.0)}}; double[][] m2 = {{1.0, 0.0, 0.0}, - {0.0, Math.cos(-zeta*3.1415/180.0), -Math.sin(-zeta*3.1415/180.0)}, - {0.0, Math.sin(-zeta*3.1415/180.0), Math.cos(-zeta*3.1415/180.0)}}; + {0.0, Math.cos(-zeta*Math.PI/180.0), -Math.sin(-zeta*Math.PI/180.0)}, + {0.0, Math.sin(-zeta*Math.PI/180.0), Math.cos(-zeta*Math.PI/180.0)}}; - mRotationMatrix=cross_product(m1,m2); + mRotationMatrix=MathUtils.cross_product(m1,m2); // Hint at good sizes for this component. @@ -243,7 +244,7 @@ protected boolean isPaintingVolumeDistribution() return BoardCAD.getInstance().isPaintingVolumeDistribution(); } - protected BezierBoard getCurrentBrd() + public BezierBoard getCurrentBrd() { return BoardCAD.getInstance().getCurrentBrd(); } @@ -365,8 +366,8 @@ public Point2D.Double screenCoordinateToBrdCoordinate(Point scrPoint) { Point2D.Double brdPoint = new Point2D.Double(); - brdPoint.x = ((double)scrPoint.x - mOffsetX)/ mScale*((mDrawControl&BezierBoardDrawUtil.FlipX)!=0?-1.0f:1.0f); - brdPoint.y = ((double)scrPoint.y - mOffsetY)/ mScale*((mDrawControl&BezierBoardDrawUtil.FlipY)!=0?-1.0f:1.0f); + brdPoint.x = (scrPoint.x - mOffsetX)/ mScale*((mDrawControl&BezierBoardDrawUtil.FlipX)!=0?-1.0f:1.0f); + brdPoint.y = (scrPoint.y - mOffsetY)/ mScale*((mDrawControl&BezierBoardDrawUtil.FlipY)!=0?-1.0f:1.0f); return brdPoint; } @@ -511,25 +512,9 @@ Point2D.Double getNose() return (Point2D.Double)getActiveBezierSplines(getCurrentBrd())[0].getControlPoint(getActiveBezierSplines(getCurrentBrd())[0].getNrOfControlPoints()-1).getEndPoint().clone(); } - private double[][] cross_product(double[][] m1, double[][] m2) - { - double[][] m=new double[3][3]; - - m[0][0]=m1[0][0]*m2[0][0]+m1[1][0]*m2[0][1]+m1[2][0]*m2[0][2]; - m[1][0]=m1[0][0]*m2[1][0]+m1[1][0]*m2[1][1]+m1[2][0]*m2[1][2]; - m[2][0]=m1[0][0]*m2[2][0]+m1[1][0]*m2[2][1]+m1[2][0]*m2[2][2]; - m[0][1]=m1[0][1]*m2[0][0]+m1[1][1]*m2[0][1]+m1[2][1]*m2[0][2]; - m[1][1]=m1[0][1]*m2[1][0]+m1[1][1]*m2[1][1]+m1[2][1]*m2[1][2]; - m[2][1]=m1[0][1]*m2[2][0]+m1[1][1]*m2[2][1]+m1[2][1]*m2[2][2]; - - m[0][2]=m1[0][2]*m2[0][0]+m1[1][2]*m2[0][1]+m1[2][2]*m2[0][2]; - m[1][2]=m1[0][2]*m2[1][0]+m1[1][2]*m2[1][1]+m1[2][2]*m2[1][2]; - m[2][2]=m1[0][2]*m2[2][0]+m1[1][2]*m2[2][1]+m1[2][2]*m2[2][2]; - - return m; - } + @Override public void paintComponent(Graphics g) { adjustScaleAndOffset(); @@ -543,9 +528,7 @@ public void paintComponent(Graphics g) { */ Graphics2D g2d = (Graphics2D)g.create(); - - - + // Turn on antialiasing, so painting is smooth. if(BoardCAD.getInstance().isAntialiasing()) { @@ -559,8 +542,6 @@ public void paintComponent(Graphics g) { RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } - - // Paint the background. Color bkgColor = BoardCAD.getInstance().getBackgroundColor(); if(mParentContainer != null && !mParentContainer.isActive(this)) @@ -572,10 +553,6 @@ public void paintComponent(Graphics g) { g2d.fillRect(0, 0, getWidth() - 1, getHeight() - 1); - - - - if(mDrawControl == 0) { //draw nurbs board @@ -616,7 +593,7 @@ public void paintComponent(Graphics g) { if(BoardCAD.getInstance().isPaintingGrid()) { - BezierBoardDrawUtil.paintGrid(new JavaDraw(g2d), (double)mOffsetX, (double)mOffsetY, (double)mScale, BoardCAD.getInstance().getGridColor(), currentBrd.getLength(), currentBrd.getMaxWidth()/2.0, (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, (mDrawControl&BezierBoardDrawUtil.FlipY)!=0); + BezierBoardDrawUtil.paintGrid(new JavaDraw(g2d), mOffsetX, mOffsetY, mScale, 0.0, BoardCAD.getInstance().getGridColor(), currentBrd.getLength(), currentBrd.getMaxWidth()/2.0, (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, (mDrawControl&BezierBoardDrawUtil.FlipY)!=0); } @@ -628,7 +605,7 @@ public void paintComponent(Graphics g) { { if(orgBrd != null && getActiveBezierSplines(orgBrd) != null) { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mOriginalOffsetX*mScale, mOriginalOffsetY*mScale, 1.0); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mOriginalOffsetX*mScale, mOriginalOffsetY*mScale, 1.0, 0.0); drawPart(g2d, BoardCAD.getInstance().getOriginalBrdColor(), stroke, orgBrd, BoardCAD.getInstance().useFill()); g2d.setTransform(savedTransform); } @@ -652,7 +629,7 @@ public void paintComponent(Graphics g) { } if(ghostBrd != null && getActiveBezierSplines(ghostBrd) != null) { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mGhostOffsetX*mScale, mGhostOffsetY*mScale, mGhostRot, 1.0); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mGhostOffsetX*mScale, mGhostOffsetY*mScale, 1.0, mGhostRot); drawPart(g2d, BoardCAD.getInstance().getBrdColor(), stroke, ghostBrd, BoardCAD.getInstance().useFill()); @@ -686,7 +663,7 @@ else if(BoardCAD.getInstance().mOrgFocus && orgBrd.isEmpty() == false) { if(ghostBrd != null && getActiveBezierSplines(ghostBrd) != null) { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mGhostOffsetX*mScale, mGhostOffsetY*mScale, mGhostRot, 1.0); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mGhostOffsetX*mScale, mGhostOffsetY*mScale, 1.0, mGhostRot); drawPart(g2d, BoardCAD.getInstance().getGhostBrdColor(), stroke, ghostBrd, BoardCAD.getInstance().useFill()); g2d.setTransform(savedTransform); } @@ -711,7 +688,7 @@ else if(BoardCAD.getInstance().mOrgFocus && orgBrd.isEmpty() == false) if(orgBrd != null && getActiveBezierSplines(orgBrd) != null) { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mOriginalOffsetX*mScale, mOriginalOffsetY*mScale, 1.0); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mOriginalOffsetX*mScale, mOriginalOffsetY*mScale, 1.0, 0.0); drawPart(g2d, BoardCAD.getInstance().getBrdColor(), stroke, orgBrd, BoardCAD.getInstance().useFill()); @@ -744,7 +721,7 @@ else if(BoardCAD.getInstance().mOrgFocus && orgBrd.isEmpty() == false) { if(orgBrd != null && getActiveBezierSplines(orgBrd) != null) { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mOriginalOffsetX*mScale, mOriginalOffsetY*mScale, 1.0); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mOriginalOffsetX*mScale, mOriginalOffsetY*mScale, 1.0, 0.0); drawPart(g2d, BoardCAD.getInstance().getOriginalBrdColor(), stroke, orgBrd, BoardCAD.getInstance().useFill()); g2d.setTransform(savedTransform); } @@ -754,7 +731,7 @@ else if(BoardCAD.getInstance().mOrgFocus && orgBrd.isEmpty() == false) { if(ghostBrd != null && getActiveBezierSplines(ghostBrd) != null) { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mGhostOffsetX*mScale, mGhostOffsetY*mScale, mGhostRot, 1.0); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g2d), mGhostOffsetX*mScale, mGhostOffsetY*mScale, 1.0, mGhostRot); drawPart(g2d, BoardCAD.getInstance().getGhostBrdColor(), stroke, ghostBrd, BoardCAD.getInstance().useFill()); g2d.setTransform(savedTransform); } @@ -825,27 +802,27 @@ else if(mDrawControl == (BezierBoardDrawUtil.MirrorX | BezierBoardDrawUtil.FlipY public void drawCircle(Graphics2D g, Color color, Stroke stroke, Point2D.Double pos) { - BezierBoardDrawUtil.paintCircle(new JavaDraw(g),mOffsetX, mOffsetY, mScale, color, stroke, pos, (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, (mDrawControl&BezierBoardDrawUtil.FlipY)!=0); + BezierBoardDrawUtil.paintCircle(new JavaDraw(g),mOffsetX, mOffsetY, mScale, 0.0, color, stroke, pos, (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, (mDrawControl&BezierBoardDrawUtil.FlipY)!=0); } public void drawPart(Graphics2D g, Color color, Stroke stroke, BezierBoard brd, boolean fill) { - BezierBoardDrawUtil.paintBezierSplines(new JavaDraw(g),mOffsetX, mOffsetY, mScale, color, stroke, getActiveBezierSplines(brd), mDrawControl, fill); + BezierBoardDrawUtil.paintBezierSplines(new JavaDraw(g),mOffsetX, mOffsetY, mScale, 0.0, color, stroke, getActiveBezierSplines(brd), mDrawControl, fill); } public void drawControlPoints(Graphics2D g, Stroke stroke, BezierBoard brd) { - BezierBoardDrawUtil.paintBezierControlPoints(new JavaDraw(g),mOffsetX, mOffsetY, mScale, stroke, getActiveBezierSplines(brd), (mParentContainer==null || mParentContainer.isActive(this))? mSelectedControlPoints:null, (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, (mDrawControl&BezierBoardDrawUtil.FlipY)!=0); + BezierBoardDrawUtil.paintBezierControlPoints(new JavaDraw(g),mOffsetX, mOffsetY, mScale, 0.0, stroke, getActiveBezierSplines(brd), (mParentContainer==null || mParentContainer.isActive(this))? mSelectedControlPoints:null, (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, (mDrawControl&BezierBoardDrawUtil.FlipY)!=0); } public void drawCurvature(Graphics2D g, Color color, Stroke stroke, BezierBoard brd) { - BezierBoardDrawUtil.paintCurvature(new JavaDraw(g), mOffsetX, mOffsetY, mScale, color, stroke, getActiveBezierSplines(brd), (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, (mDrawControl&BezierBoardDrawUtil.FlipY)!=0, mCurvatureScale ); + BezierBoardDrawUtil.paintCurvature(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0, color, stroke, getActiveBezierSplines(brd), (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, (mDrawControl&BezierBoardDrawUtil.FlipY)!=0, mCurvatureScale ); } public void drawVolumeDistribution(Graphics2D g, Color color, Stroke stroke, BezierBoard brd) { - BezierBoardDrawUtil.paintVolumeDistribution(new JavaDraw(g), mOffsetX, mOffsetY, mScale, color, stroke, brd, (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, true, mVolumeDistributionScale ); + BezierBoardDrawUtil.paintVolumeDistribution(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0, color, stroke, brd, (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, true, mVolumeDistributionScale ); } public void drawSlidingInfo(Graphics2D g, Color color, Stroke stroke, BezierBoard brd) @@ -854,12 +831,12 @@ public void drawSlidingInfo(Graphics2D g, Color color, Stroke stroke, BezierBoar public void drawFins(Graphics2D g, Color color, Stroke stroke, BezierBoard brd) { - BezierBoardDrawUtil.paintFins(new JavaDraw(g), mOffsetX, mOffsetY, mScale, color, stroke, brd.getFins(), (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, (mDrawControl&BezierBoardDrawUtil.FlipY)!=0 ); + BezierBoardDrawUtil.paintFins(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0, color, stroke, brd.getFins(), (mDrawControl&BezierBoardDrawUtil.FlipX)!=0, (mDrawControl&BezierBoardDrawUtil.FlipY)!=0 ); } public void drawStringer(Graphics2D g, Color color, Stroke stroke, BezierBoard brd) { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), mOffsetX, mOffsetY, mScale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0); double mulX = ((mDrawControl&BezierBoardDrawUtil.FlipX)!=0)?-1:1; // double mulY = ((mDrawControl&Brd.FlipY)!=0)?-1:1; @@ -876,7 +853,7 @@ public void drawStringer(Graphics2D g, Color color, Stroke stroke, BezierBoard b public void drawCenterLine(Graphics2D g, Color color, Stroke stroke, double pos, double length) { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), mOffsetX, mOffsetY, mScale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0 ); double mulX = ((mDrawControl&BezierBoardDrawUtil.FlipX)!=0)?-1:1; // double mulY = ((mDrawControl&Brd.FlipY)!=0)?-1:1; @@ -895,7 +872,7 @@ public void drawBackgroundImage(Graphics2D g) { if(mBackgroundImage != null) { - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), mOffsetX, mOffsetY, mScale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0); final AffineTransform tmp = new AffineTransform(); @@ -956,7 +933,7 @@ public void drawGuidePoints(Graphics2D g) g.setStroke(new BasicStroke((float)(BoardCAD.getInstance().getGuidePointThickness()/mScale))); - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), mOffsetX, mOffsetY, mScale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(new JavaDraw(g), mOffsetX, mOffsetY, mScale, 0.0); double crossSize = 4.0f/mScale; @@ -986,6 +963,7 @@ public void onBrdChanged() } + @Override public void mousePressed(MouseEvent e) { if(mParentContainer != null) @@ -1019,6 +997,7 @@ public void mousePressed(MouseEvent e) { } } + @Override public void mouseReleased(MouseEvent e) { if (mPopupMenu != null && e.isPopupTrigger()) { @@ -1047,10 +1026,12 @@ public void mouseReleased(MouseEvent e) { } } + @Override public void mouseEntered(MouseEvent e) { mHasMouse = true; } + @Override public void mouseExited(MouseEvent e) { mHasMouse = false; } @@ -1060,9 +1041,11 @@ public boolean hasMouse() return mHasMouse; } + @Override public void mouseClicked(MouseEvent e) { } + @Override public void mouseMoved(MouseEvent e) { mScreenCoord = e.getPoint(); @@ -1104,6 +1087,7 @@ else if(mDrawControl == (BezierBoardDrawUtil.MirrorX | BezierBoardDrawUtil.FlipY cmd.onMouseMove(this, e); } + @Override public void mouseDragged(MouseEvent e) { mScreenCoord = e.getPoint(); mBrdCoord.setLocation(screenCoordinateToBrdCoordinate(mScreenCoord)); @@ -1118,6 +1102,7 @@ public void mouseDragged(MouseEvent e) { } + @Override public void mouseWheelMoved(MouseWheelEvent e) { BrdInputCommand cmd = (BrdInputCommand)getCurrentCommand(); @@ -1128,77 +1113,9 @@ public void mouseWheelMoved(MouseWheelEvent e) } + @Override public void fit_all() { fitBrd(); } } - -interface BrdEditParentContainer -{ - public void setActive(BoardEdit edit); - public boolean isActive(BoardEdit edit); - public BoardEdit getActive(); -} - -class BrdEditSplitPane extends JSplitPane implements BrdEditParentContainer -{ - static final long serialVersionUID=1L; - BoardEdit mActive = null; - - BrdEditSplitPane(int arg1, BoardEdit first, BoardEdit second) - { - super(arg1, first, second); - mActive = first; - first.mParentContainer = this; - second.mParentContainer = this; - } - - public void setActive(BoardEdit edit) - { - mActive = edit; - this.repaint(); - } - - public boolean isActive(BoardEdit edit) - { - return (edit == mActive); - } - - public BoardEdit getActive() - { - return mActive; - } -} - -class QuadView extends JPanel implements BrdEditParentContainer -{ - static final long serialVersionUID=1L; - BoardEdit mActive = null; - - QuadView() - { - this.setLayout(new GridLayout(2,2,3,3)); - } - - public void setActive(BoardEdit edit) - { - mActive = edit; - this.repaint(); - BoardCAD.getInstance().getGuidePointsDialog().update(); - } - - public boolean isActive(BoardEdit edit) - { - return (edit == mActive); - } - - public BoardEdit getActive() - { - if(mActive == null) - return (BoardEdit)getComponent(0); - - return mActive; - } - -} diff --git a/boardcad/gui/jdk/BoardFileView.java b/boardcad/gui/jdk/BoardFileView.java index ed46785..55e856b 100644 --- a/boardcad/gui/jdk/BoardFileView.java +++ b/boardcad/gui/jdk/BoardFileView.java @@ -6,7 +6,6 @@ import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.RenderingHints; -import java.awt.geom.Line2D; import java.awt.image.BufferedImage; import java.io.File; @@ -21,132 +20,163 @@ import boardcad.FileTools; public class BoardFileView extends FileView { - + private Font mSpecsFont = new Font("Dialog", Font.PLAIN, 10); private Font mTypeFont = new Font("Ariel", Font.PLAIN, 8); - - public String getTypeDescription(File f) { - String extension = FileTools.getExtension(f); - String type = null; - - if (extension != null) { - if (extension.equals("srf")) { - type = "SurfCAD file"; - } else if (extension.equals("brd")){ - type = "APS3000 file"; - } else if (extension.equals("s3d")) { - type = "Shape3D file"; - } else if (extension.equals("cad")){ - type = "BoardCAD file"; - } - } - return type; - } - //Returns an icon representing the file or its type. Here is ImageFileView's implementation of this method: - public Icon getIcon(File f) { - - BufferedImage image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB); - Icon icon = null; - - String extension = FileTools.getExtension(f); - if (extension != null) { - if (extension.equals("srf")) { - BezierBoard brd = new BezierBoard(); - SrfReader.loadFile(brd, f.getAbsolutePath()); - - icon = paintBoard(image, brd, "srf"); - } - else if (extension.equals("brd")){ - BezierBoard brd = new BezierBoard(); - BrdReader.loadFile(brd, f.getAbsolutePath()); - - icon = paintBoard(image, brd, "brd"); - } - else if (extension.equals("s3d")) { - BezierBoard brd = new BezierBoard(); - S3dReader.loadFile(brd, f.getAbsolutePath()); - - icon = paintBoard(image, brd, "s3d"); - } - else if (extension.equals("stp") || extension.equals("step")) { - BezierBoard brd = new BezierBoard(); - StepReader.loadPreview(brd, f.getAbsolutePath()); - - icon = paintBoard(image, brd, "step"); - } - else if (extension.equals("cad")){ - //TODO: implement - } - } - - return icon; - } - - Icon paintBoard(BufferedImage image, BezierBoard brd, String type) - { - Graphics2D g = image.createGraphics(); - g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - - g.setBackground(new Color(1.0f,1.0f,1.0f,1.0f)); - g.clearRect(0,0,image.getHeight(), image.getWidth()); + + @Override + public String getTypeDescription(File f) { + String extension = FileTools.getExtension(f); + String type = null; + + if (extension != null) { + if (extension.equals("srf")) { + type = "SurfCAD file"; + } else if (extension.equals("brd")) { + type = "APS3000 file"; + } else if (extension.equals("s3d")) { + type = "Shape3D file"; + } else if (extension.equals("s3dx")) { + type = "Shape3D X file"; + } else if (extension.equals("cad")) { + type = "BoardCAD file"; + } + } + return type; + } + + // Returns an icon representing the file or its type. Here is + // ImageFileView's implementation of this method: + @Override + public Icon getIcon(File f) { + + BufferedImage image = new BufferedImage(64, 64, + BufferedImage.TYPE_INT_RGB); + Icon icon = null; + + String extension = FileTools.getExtension(f); + if (extension != null) { + if (extension.equals("srf")) { + BezierBoard brd = new BezierBoard(); + SrfReader.loadFile(brd, f.getAbsolutePath()); + + icon = paintBoard(image, brd, "srf"); + } else if (extension.equals("brd")) { + BezierBoard brd = new BezierBoard(); + BrdReader.loadFile(brd, f.getAbsolutePath()); + + icon = paintBoard(image, brd, "brd"); + } else if (extension.equals("s3d")) { + BezierBoard brd = new BezierBoard(); + S3dReader.loadFile(brd, f.getAbsolutePath()); + + icon = paintBoard(image, brd, "s3d"); + } else if (extension.equals("s3dx")) { + BezierBoard brd = new BezierBoard(); + S3dxReader.loadFile(brd, f.getAbsolutePath()); + + icon = paintBoard(image, brd, "s3dx"); + } else if (extension.equals("cad")) { + // TODO: implement + } + } + + return icon; + } + + Icon paintBoard(BufferedImage image, BezierBoard brd, String type) { + Graphics2D g = image.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + g.setBackground(new Color(1.0f, 1.0f, 1.0f, 1.0f)); + g.clearRect(0, 0, image.getHeight(), image.getWidth()); double leftMargin = 2.0; double topMargin = 3.0; double bottomMargin = 3.0; - + double height = image.getHeight(); double width = image.getWidth(); - + JavaDraw jd = new JavaDraw(g); - - //Draw type text + + // Draw type text FontMetrics sf = g.getFontMetrics(mSpecsFont); FontMetrics tf = g.getFontMetrics(mTypeFont); double typeStringLength = tf.stringWidth(type); - - g.setColor(new Color(0.6f,0.6f,0.6f)); + + g.setColor(new Color(0.6f, 0.6f, 0.6f)); g.setFont(mTypeFont); - g.drawString(type, (int)(width-typeStringLength - leftMargin), (int)(tf.getHeight())); - - //Vertical -// double scale = (height-topMargin*2.0)/brd.getLength(); -// BezierBoardDrawUtil.paintBezierPaths(new JavaDraw(g), leftMargin, height-topMargin, scale , Color.BLACK, new BasicStroke(1.0f/(float)scale), new BezierSpline[]{brd.getDeck(), brd.getBottom()}, BezierBoardDrawUtil.Vertical | BezierBoardDrawUtil.FlipY); -// BezierBoardDrawUtil.paintBezierPaths(new JavaDraw(g), image.getWidth()/2.0, height-topMargin, scale, Color.BLACK, new BasicStroke(1.0f/(float)scale), new BezierSpline[]{brd.getOutline()}, BezierBoardDrawUtil.Vertical | BezierBoardDrawUtil.FlipY | BezierBoardDrawUtil.MirrorX); - - //Horizontal - double scale = (width-leftMargin*2.0)/brd.getLength(); - BasicStroke stroke = new BasicStroke(1.0f/(float)scale); - double outlinePos = height/2 - (brd.getThickness() + 10.0)*scale/2; - BezierBoardDrawUtil.paintBezierSplines(jd, leftMargin, outlinePos, scale, Color.BLACK, stroke, new BezierSpline[]{brd.getOutline()}, BezierBoardDrawUtil.FlipY | BezierBoardDrawUtil.MirrorY, true); -// g.setStroke(new BasicStroke(1.0f)); -// jd.draw(new Line2D.Double(leftMargin, topMargin + brd.getMaxWidth()*scale, width-leftMargin, topMargin + brd.getMaxWidth()*scale)); -// jd.draw(new Line2D.Double(leftMargin + brd.getMaxWidthPos()*scale, topMargin + brd.getMaxWidth()*0.5*scale, leftMargin + brd.getMaxWidthPos()*scale, topMargin + brd.getMaxWidth()*1.5*scale)); - BezierBoardDrawUtil.paintBezierSplines(jd, leftMargin, outlinePos + (brd.getMaxWidth()/2.0 + brd.getThickness() + 10.0)*scale, scale , Color.BLACK, stroke, new BezierSpline[]{brd.getDeck(), brd.getBottom()}, BezierBoardDrawUtil.FlipY, true); -// BezierBoardDrawUtil.paintFins(jd, leftMargin, topMargin + brd.getMaxWidth()*scale, scale, Color.BLACK, stroke, brd.mFins, false, false); - -// g.setFont(mSpecsFont); -// String lengthStr = UnitUtils.convertLengthToCurrentUnit(brd.getLength(), true); -// double lengthStrLength = sf.stringWidth(lengthStr); -// g.drawString(lengthStr, (int)(width-lengthStrLength)/2, (int)((topMargin + brd.getMaxWidth()*scale))); - + g.drawString(type, (int) (width - typeStringLength - leftMargin), + (tf.getHeight())); + + // Vertical + // double scale = (height-topMargin*2.0)/brd.getLength(); + // BezierBoardDrawUtil.paintBezierPaths(new JavaDraw(g), leftMargin, + // height-topMargin, scale , Color.BLACK, new + // BasicStroke(1.0f/(float)scale), new BezierSpline[]{brd.getDeck(), + // brd.getBottom()}, BezierBoardDrawUtil.Vertical | + // BezierBoardDrawUtil.FlipY); + // BezierBoardDrawUtil.paintBezierPaths(new JavaDraw(g), + // image.getWidth()/2.0, height-topMargin, scale, Color.BLACK, new + // BasicStroke(1.0f/(float)scale), new BezierSpline[]{brd.getOutline()}, + // BezierBoardDrawUtil.Vertical | BezierBoardDrawUtil.FlipY | + // BezierBoardDrawUtil.MirrorX); + + // Horizontal + double scale = (width - leftMargin * 2.0) / brd.getLength(); + BasicStroke stroke = new BasicStroke(1.0f / (float) scale); + double outlinePos = height / 2 - (brd.getThickness() + 10.0) * scale + / 2; + BezierBoardDrawUtil.paintBezierSplines(jd, leftMargin, outlinePos, + scale, 0.0, Color.BLACK, stroke, + new BezierSpline[] { brd.getOutline() }, + BezierBoardDrawUtil.FlipY | BezierBoardDrawUtil.MirrorY, true); + // g.setStroke(new BasicStroke(1.0f)); + // jd.draw(new Line2D.Double(leftMargin, topMargin + + // brd.getMaxWidth()*scale, width-leftMargin, topMargin + + // brd.getMaxWidth()*scale)); + // jd.draw(new Line2D.Double(leftMargin + brd.getMaxWidthPos()*scale, + // topMargin + brd.getMaxWidth()*0.5*scale, leftMargin + + // brd.getMaxWidthPos()*scale, topMargin + + // brd.getMaxWidth()*1.5*scale)); + BezierBoardDrawUtil.paintBezierSplines(jd, leftMargin, + outlinePos + + (brd.getMaxWidth() / 2.0 + brd.getThickness() + 10.0) + * scale, scale, 0.0, Color.BLACK, stroke, + new BezierSpline[] { brd.getDeck(), brd.getBottom() }, + BezierBoardDrawUtil.FlipY, true); + // BezierBoardDrawUtil.paintFins(jd, leftMargin, topMargin + + // brd.getMaxWidth()*scale, scale, Color.BLACK, stroke, brd.mFins, + // false, false); + + // g.setFont(mSpecsFont); + // String lengthStr = + // UnitUtils.convertLengthToCurrentUnit(brd.getLength(), true); + // double lengthStrLength = sf.stringWidth(lengthStr); + // g.drawString(lengthStr, (int)(width-lengthStrLength)/2, + // (int)((topMargin + brd.getMaxWidth()*scale))); + return new ImageIcon(image); - } - - public String getName(File f) - { - return null; - } - - public String getDescription(File f) - { - return null; - } - - public Boolean isTraversable(File f) - { - return null; - } + } + + @Override + public String getName(File f) { + return null; + } + + @Override + public String getDescription(File f) { + return null; + } + + @Override + public Boolean isTraversable(File f) { + return null; + } } diff --git a/boardcad/gui/jdk/BoardGuidePointsDialog.java b/boardcad/gui/jdk/BoardGuidePointsDialog.java index f475931..cbfc6a1 100644 --- a/boardcad/gui/jdk/BoardGuidePointsDialog.java +++ b/boardcad/gui/jdk/BoardGuidePointsDialog.java @@ -74,13 +74,19 @@ public void update() * @return javax.swing.JTable */ private JTable getGuidePointsTable() { - final JTabbedPane mTabbedPane = BoardCAD.getInstance().getmTabbedPane(); + final JTabbedPane mTabbedPane = BoardCAD.getInstance().getTabbedPane(); if (mGuidePointsTable == null) { mGuidePointsTable = new JTable() { + /** + * + */ + private static final long serialVersionUID = 1L; + /* * Override to provide Select All editing functionality */ + @Override public boolean editCellAt(int row, int column, EventObject e) { boolean result = super.editCellAt(row, column, e); @@ -131,6 +137,7 @@ private void selectAll(EventObject e) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { ((JTextComponent)editor).selectAll(); @@ -144,6 +151,7 @@ public void run() // JAVA 6 GuidePointsTable.setFillsViewportHeight(true); mGuidePointsTable.setModel(new AbstractTableModel() { static final long serialVersionUID=1L; + @Override public String getColumnName(int col) { switch(col) { @@ -165,6 +173,7 @@ public String getColumnName(int col) { return ""; } } + @Override public int getRowCount() { BoardEdit edit = BoardCAD.getInstance().getSelectedEdit(); @@ -173,6 +182,7 @@ public int getRowCount() return edit.getGuidePoints().size(); } + @Override public int getColumnCount() { @@ -184,6 +194,7 @@ public int getColumnCount() return 4; } } + @Override public Object getValueAt(int row, int col) { Point2D.Double pnt = BoardCAD.getInstance().getSelectedEdit().getGuidePoints().get(row); @@ -212,6 +223,7 @@ public Object getValueAt(int row, int col) { } } + @Override public boolean isCellEditable(int row, int col) { switch(col) @@ -225,6 +237,7 @@ public boolean isCellEditable(int row, int col) return true; } } + @Override public void setValueAt(Object value, int row, int col) { BoardEdit edit = BoardCAD.getInstance().getSelectedEdit(); if(edit == null) @@ -265,6 +278,7 @@ public void setValueAt(Object value, int row, int col) { // this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { addGuidePoint(); @@ -280,6 +294,7 @@ public void actionPerformed(ActionEvent arg0) { // this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { int[] ai = mGuidePointsTable.getSelectedRows(); @@ -302,9 +317,11 @@ public void actionPerformed(ActionEvent arg0) { mGuidePointsTable.add(menu); mGuidePointsTable.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(MouseEvent e) { showPopup(e); } + @Override public void mouseReleased(MouseEvent e) { showPopup(e); } @@ -317,6 +334,7 @@ private void showPopup(MouseEvent e) { mScrollPane.add(menu); mScrollPane.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); @@ -325,6 +343,7 @@ public void mousePressed(MouseEvent e) { addGuidePoint(); } } + @Override public void mouseReleased(MouseEvent e) { showPopup(e); } diff --git a/boardcad/gui/jdk/BoardLoadAction.java b/boardcad/gui/jdk/BoardLoadAction.java index 0c717ad..a3ee98c 100644 --- a/boardcad/gui/jdk/BoardLoadAction.java +++ b/boardcad/gui/jdk/BoardLoadAction.java @@ -46,20 +46,22 @@ public BoardLoadAction(JFrame frame, BezierBoard brd) } + @Override public void actionPerformed(ActionEvent event) { // Create a file dialog box to prompt for a new file to display - FileFilter filter = new FileFilter() + FileFilter boardFilesFilter = new FileFilter() { // Accept all directories and brd and s3d files. + @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } String extension = FileTools.getExtension(f); - if (extension != null && (extension.equals("brd") || extension.equals("s3d") || extension.equals("srf") || extension.equals("cad") || extension.equals("stp") || extension.equals("step"))) + if (extension != null && (extension.equals("brd") || extension.equals("s3d") || extension.equals("s3dx") || extension.equals("srf") || extension.equals("cad") || extension.equals("stp") || extension.equals("step"))) { return true; } @@ -68,18 +70,49 @@ public boolean accept(File f) { } // The description of this filter + @Override public String getDescription() { return "Board files"; } + }; + + FileFilter allFilesFilter = new FileFilter() + { + +// Accept all directories and brd and s3d files. + @Override + public boolean accept(File f) { + if (f.isDirectory()) { + return true; + } + + String extension = FileTools.getExtension(f); + if (extension != null) + { + return true; + } + + return false; + } + +// The description of this filter + @Override + public String getDescription() { + return "All files"; + } + + + }; final JFileChooser fc = new JFileChooser(); fc.setFileView(new BoardFileView()); fc.setAccessory(new BoardPreview(fc)); - fc.addChoosableFileFilter(filter); + fc.addChoosableFileFilter(boardFilesFilter); + fc.addChoosableFileFilter(allFilesFilter); fc.setAcceptAllFileFilterUsed(false); @@ -121,6 +154,20 @@ public void load(String filename) errorStr = S3dReader.getErrorStr(); } } + else if(ext.compareToIgnoreCase("s3dx")==0) + { + ret = S3dxReader.loadFile(mBrd, filename); + + if(ret == 1) //Show warning dialog + { + JOptionPane.showMessageDialog(BoardCAD.getInstance().getFrame(), LanguageResource.getString("S3DTHICKNESSCURVENOTSUPPOSTEDMSG_STR"), LanguageResource.getString("S3DTHICKNESSCURVENOTSUPPOSTEDTITLE_STR"), JOptionPane.WARNING_MESSAGE); + } + + if(ret < 0) + { + errorStr = S3dReader.getErrorStr(); + } + } else if(ext.compareToIgnoreCase("srf")==0) { ret = SrfReader.loadFile(mBrd, filename); diff --git a/boardcad/gui/jdk/BoardPreview.java b/boardcad/gui/jdk/BoardPreview.java index bbe4cbd..31d23e6 100644 --- a/boardcad/gui/jdk/BoardPreview.java +++ b/boardcad/gui/jdk/BoardPreview.java @@ -53,14 +53,14 @@ else if (extension.equals("brd")){ else if (extension.equals("s3d")) { mBrd = new BezierBoard(); S3dReader.loadFile(mBrd, mFile.getAbsolutePath()); + } + else if (extension.equals("s3dx")) { + mBrd = new BezierBoard(); + S3dxReader.loadFile(mBrd, mFile.getAbsolutePath()); } - - else if (extension.equals("stp") || (extension.equals("step"))) { - - mBrd = new BezierBoard(); - StepReader.loadPreview(mBrd, mFile.getAbsolutePath()); - - } + else if (extension.equals("stp") || (extension.equals("step"))) { + StepReader.loadPreview(mBrd, mFile.getAbsolutePath()); + } else if (extension.equals("cad")){ //TODO: implement } @@ -68,7 +68,8 @@ else if (extension.equals("cad")){ } - public void propertyChange(PropertyChangeEvent e) + @Override + public void propertyChange(PropertyChangeEvent e) { boolean update = false; String prop = e.getPropertyName(); @@ -93,7 +94,8 @@ else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) { //If a file } } - protected void paintComponent(Graphics gr) + @Override + protected void paintComponent(Graphics gr) { Graphics2D g = (Graphics2D)gr; FontMetrics fontMetrics = g.getFontMetrics(mFont); @@ -117,7 +119,7 @@ protected void paintComponent(Graphics gr) double upperFrameHeight = height - lowerFrameHeight - frameMargins; g.setColor(Color.GRAY); - g.drawRect((int)frameMargins, (int)0, (int)(width-frameMargins-1), (int)upperFrameHeight); + g.drawRect((int)frameMargins, 0, (int)(width-frameMargins-1), (int)upperFrameHeight); g.drawRect((int)frameMargins, (int)(upperFrameHeight + frameMargins), (int)(width-frameMargins-1), (int)lowerFrameHeight-1); @@ -137,8 +139,8 @@ protected void paintComponent(Graphics gr) double outlineDrawPos = width/2 - (mBrd.getThickness()*scale + 5.0*scale)/2; - BezierBoardDrawUtil.paintBezierSplines(jd, outlineDrawPos, upperFrameHeight-bottomMargin, scale, Color.BLACK, stroke, new BezierSpline[]{mBrd.getOutline()}, BezierBoardDrawUtil.Vertical | BezierBoardDrawUtil.FlipY | BezierBoardDrawUtil.MirrorX, true); - BezierBoardDrawUtil.paintBezierSplines(jd, outlineDrawPos + mBrd.getMaxWidth()*scale/2+ mBrd.getThickness()*scale + 5.0*scale, upperFrameHeight-bottomMargin, scale , Color.BLACK, stroke, new BezierSpline[]{mBrd.getDeck(), mBrd.getBottom()}, BezierBoardDrawUtil.Vertical | BezierBoardDrawUtil.FlipX | BezierBoardDrawUtil.FlipY, true); + BezierBoardDrawUtil.paintBezierSplines(jd, outlineDrawPos, upperFrameHeight-bottomMargin, scale, 0.0, Color.BLACK, stroke, new BezierSpline[]{mBrd.getOutline()}, BezierBoardDrawUtil.Vertical | BezierBoardDrawUtil.FlipY | BezierBoardDrawUtil.MirrorX, true); + BezierBoardDrawUtil.paintBezierSplines(jd, outlineDrawPos + mBrd.getMaxWidth()*scale/2+ mBrd.getThickness()*scale + 5.0*scale, 0.0, upperFrameHeight-bottomMargin, scale , Color.BLACK, stroke, new BezierSpline[]{mBrd.getDeck(), mBrd.getBottom()}, BezierBoardDrawUtil.Vertical | BezierBoardDrawUtil.FlipX | BezierBoardDrawUtil.FlipY, true); //Text double strLength = fontMetrics.stringWidth(mFile.getName()); diff --git a/boardcad/gui/jdk/BoardSpec.java b/boardcad/gui/jdk/BoardSpec.java index 38d0098..d1db2ea 100644 --- a/boardcad/gui/jdk/BoardSpec.java +++ b/boardcad/gui/jdk/BoardSpec.java @@ -13,9 +13,9 @@ import javax.swing.JRadioButton; import board.BezierBoard; - import cadcore.BezierSpline; import cadcore.UnitUtils; +import boardcad.commands.BrdScaleCommand; import boardcad.i18n.LanguageResource; public class BoardSpec extends JPanel { @@ -526,6 +526,7 @@ private JButton getMScaleButton() { mScaleButton.setText( LanguageResource.getString("SCALEBUTTON_STR")); mScaleButton.setToolTipText(LanguageResource.getString("SCALEBUTTONTOOLTIP_STR")); mScaleButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { BrdScaleCommand scaleCmd = new BrdScaleCommand(BoardCAD.getInstance().getSelectedEdit()); scaleCmd.execute(); @@ -543,6 +544,7 @@ private JRadioButton getOverCurveRadioButton() { mOverCurveRadioButton.setToolTipText(LanguageResource.getString("OVERCURVERADIOBUTTONTOOLTIP_STR")); mOverCurveRadioButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { mOverCurveRadioButton.setSelected(true); setVisible(true); @@ -560,6 +562,7 @@ private JRadioButton getStraightLineRadioButton() { mStraightLineRadioButton.setToolTipText(LanguageResource.getString("STRAIGHTLINERADIOBUTTONTOOLTIP_STR")); mStraightLineRadioButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { mStraightLineRadioButton.setSelected(true); setVisible(true); @@ -580,6 +583,7 @@ public void updateInfo() { mTimer = new java.util.Timer(); mTimer.schedule(new TimerTask(){ + @Override public void run() { updateMeasurements(); @@ -598,6 +602,7 @@ public void run() mIntegralTimer = new java.util.Timer(); mIntegralTimer.schedule(new TimerTask(){ + @Override public void run() { updateAreaAndVolume(); diff --git a/boardcad/gui/jdk/Brd3DModelGenerator.java b/boardcad/gui/jdk/Brd3DModelGenerator.java new file mode 100644 index 0000000..69610b8 --- /dev/null +++ b/boardcad/gui/jdk/Brd3DModelGenerator.java @@ -0,0 +1,242 @@ +package boardcad.gui.jdk; + +import java.util.Vector; + +import javax.media.j3d.*; +import javax.vecmath.*; + +import board.BezierBoard; + +public class Brd3DModelGenerator { + + boolean mCancelExecuting = false; + Vector mThreads = new Vector(); + boolean mInitialModelRun = true; + + public void update3DModel(BezierBoard brd, Shape3D model, int numTasks) { + if (brd.isEmpty()) + return; + + mCancelExecuting = true; + + System.out + .println("BezierBoard.update3DModel() cancel execution, wait for futures"); + + for (Thread thread : mThreads) { + try { + thread.join(); + } catch (InterruptedException e) { + System.out + .println("BezierBoard.update3DModel() InterruptedException"); + } + } + + mThreads.clear(); + + System.out.println("BezierBoard.update3DModel() Wait finished"); + + if (model.numGeometries() != numTasks) { + System.out + .printf("BezierBoard.update3DModel() Need initial run geom:%d tasks:%d", + model.numGeometries(), numTasks); + + model.removeAllGeometries(); + mInitialModelRun = true; + } else { + mInitialModelRun = false; + } + + mCancelExecuting = false; + double length = brd.getLength(); + + for (int i = 0; i < numTasks; i++) { + final double sx = (length / numTasks) * i; + final double ex = (length / numTasks) * (i + 1); + final int index = i; + Runnable task = () -> { + update3DModel((BezierBoard) brd.clone(), model, sx, ex, index); + }; + + Thread thread = new Thread(task); + mThreads.add(thread); + thread.start(); + } + + } + + public void update3DModel(BezierBoard brd, Shape3D model, double startX, + double endX, int index) { + double lengthAccuracy = 1.0; + double deckWidthAccuracy = 1.0; + double bottomWidthAccuracy = 1.0; + + double spanLength = endX - startX; + double width = brd.getCenterWidth(); + + int lengthSteps = (int) (spanLength / lengthAccuracy) + 1; + // int lengthSteps = 200; + int deckSteps = (int) ((width / 2.0) / deckWidthAccuracy) + 1; + int railSteps = 0; + int bottomSteps = (int) (width / 2.0 / bottomWidthAccuracy) + 1; + + double lengthStep = spanLength / lengthSteps; + + int nrOfCoords = (lengthSteps) * (deckSteps + railSteps + bottomSteps) + * 4 * 2; + + QuadArray quads; + quads = new QuadArray(nrOfCoords, IndexedQuadArray.COORDINATES + | IndexedQuadArray.NORMALS); + + Point3d[] vertices = new Point3d[4]; + Vector3f[] normals = new Vector3f[4]; + Point3d[] mirrorVertices = new Point3d[4]; + Vector3f[] mirrorNormals = new Vector3f[4]; + for (int i = 0; i < 4; i++) { + vertices[i] = new Point3d(); + normals[i] = new Vector3f(); + mirrorVertices[i] = new Point3d(); + mirrorNormals[i] = new Vector3f(); + } + + int nrOfQuads = 0; + double xPos = 0.0; + + // Deck + double minAngle = -45.0; + double maxAngle = 45.0; + for (int i = 0; i < deckSteps; i++) { + if (mCancelExecuting) + return; + + xPos = startX; + + // first coords in lengthwise strip + vertices[0].set(brd.getSurfacePoint(xPos, minAngle, maxAngle, i, + deckSteps)); + normals[0].set(brd.getSurfaceNormal(xPos, minAngle, maxAngle, i, + deckSteps)); + + vertices[3].set(brd.getSurfacePoint(xPos, minAngle, maxAngle, + i + 1, deckSteps)); + normals[3].set(brd.getSurfaceNormal(xPos, minAngle, maxAngle, + i + 1, deckSteps)); + + xPos += lengthStep; + + for (int j = 1; j <= lengthSteps; j++) { + + vertices[1].set(brd.getSurfacePoint(xPos, minAngle, maxAngle, + i, deckSteps)); + normals[1].set(brd.getSurfaceNormal(xPos, minAngle, maxAngle, + i, deckSteps)); + + vertices[2].set(brd.getSurfacePoint(xPos, minAngle, maxAngle, + i + 1, deckSteps)); + normals[2].set(brd.getSurfaceNormal(xPos, minAngle, maxAngle, + i + 1, deckSteps)); + + // Build one quad + quads.setCoordinates(nrOfQuads * 4, vertices); + quads.setNormals(nrOfQuads * 4, normals); + nrOfQuads++; + + // Mirror + for (int n = 0; n < 4; n++) { + mirrorVertices[n].set(vertices[3 - n]); + mirrorNormals[n].set(normals[3 - n]); + + mirrorVertices[n].y = -mirrorVertices[n].y; + mirrorNormals[n].y = -mirrorNormals[n].y; + } + + // Build mirrored quad + quads.setCoordinates(nrOfQuads * 4, mirrorVertices); + quads.setNormals(nrOfQuads * 4, mirrorNormals); + nrOfQuads++; + + // Get ready for next step + vertices[0].set(vertices[1]); + normals[0].set(normals[1]); + + vertices[3].set(vertices[2]); + normals[3].set(normals[2]); + + xPos += lengthStep; + + } + } + + // Bottom + minAngle = maxAngle; + maxAngle = 360.0; + for (int i = 0; i < bottomSteps; i++) { + if (mCancelExecuting) + return; + + xPos = startX; + + // first coords in lengthwise strip + vertices[0].set(brd.getSurfacePoint(xPos, minAngle, maxAngle, i, + bottomSteps)); + normals[0].set(brd.getSurfaceNormal(xPos, minAngle, maxAngle, i, + bottomSteps)); + + vertices[3].set(brd.getSurfacePoint(xPos, minAngle, maxAngle, + i + 1, bottomSteps)); + normals[3].set(brd.getSurfaceNormal(xPos, minAngle, maxAngle, + i + 1, bottomSteps)); + + xPos += lengthStep; + + for (int j = 1; j <= lengthSteps; j++) { + // Two next coords + vertices[1].set(brd.getSurfacePoint(xPos, minAngle, maxAngle, + i, bottomSteps)); + normals[1].set(brd.getSurfaceNormal(xPos, minAngle, maxAngle, + i, bottomSteps)); + + vertices[2].set(brd.getSurfacePoint(xPos, minAngle, maxAngle, + i + 1, bottomSteps)); + normals[2].set(brd.getSurfaceNormal(xPos, minAngle, maxAngle, + i + 1, bottomSteps)); + + // Build one quad + quads.setCoordinates(nrOfQuads * 4, vertices); + quads.setNormals(nrOfQuads * 4, normals); + nrOfQuads++; + + // Mirror + for (int n = 0; n < 4; n++) { + mirrorVertices[n].set(vertices[3 - n]); + mirrorNormals[n].set(normals[3 - n]); + + mirrorVertices[n].y = -mirrorVertices[n].y; + mirrorNormals[n].y = -mirrorNormals[n].y; + } + + // Build mirrored quad + quads.setCoordinates(nrOfQuads * 4, mirrorVertices); + quads.setNormals(nrOfQuads * 4, mirrorNormals); + nrOfQuads++; + + // Get ready for next step + vertices[0].set(vertices[1]); + normals[0].set(normals[1]); + + vertices[3].set(vertices[2]); + normals[3].set(normals[2]); + + xPos += lengthStep; + + } + } + + if (mInitialModelRun) { + model.addGeometry(quads); + } else { + model.setGeometry(quads, index); + } + + } +} diff --git a/boardcad/gui/jdk/BrdEditParentContainer.java b/boardcad/gui/jdk/BrdEditParentContainer.java new file mode 100644 index 0000000..646e3f3 --- /dev/null +++ b/boardcad/gui/jdk/BrdEditParentContainer.java @@ -0,0 +1,8 @@ +package boardcad.gui.jdk; + +interface BrdEditParentContainer +{ + public void setActive(BoardEdit edit); + public boolean isActive(BoardEdit edit); + public BoardEdit getActive(); +} \ No newline at end of file diff --git a/boardcad/gui/jdk/BrdEditSplitPane.java b/boardcad/gui/jdk/BrdEditSplitPane.java new file mode 100644 index 0000000..ab61e93 --- /dev/null +++ b/boardcad/gui/jdk/BrdEditSplitPane.java @@ -0,0 +1,36 @@ +package boardcad.gui.jdk; + +import javax.swing.JSplitPane; + +class BrdEditSplitPane extends JSplitPane implements BrdEditParentContainer +{ + static final long serialVersionUID=1L; + BoardEdit mActive = null; + + BrdEditSplitPane(int arg1, BoardEdit first, BoardEdit second) + { + super(arg1, first, second); + mActive = first; + first.mParentContainer = this; + second.mParentContainer = this; + } + + @Override + public void setActive(BoardEdit edit) + { + mActive = edit; + this.repaint(); + } + + @Override + public boolean isActive(BoardEdit edit) + { + return (edit == mActive); + } + + @Override + public BoardEdit getActive() + { + return mActive; + } +} \ No newline at end of file diff --git a/boardcad/gui/jdk/BrdGuidePointsDialog.java b/boardcad/gui/jdk/BrdGuidePointsDialog.java index bcb15c9..cb137d7 100644 --- a/boardcad/gui/jdk/BrdGuidePointsDialog.java +++ b/boardcad/gui/jdk/BrdGuidePointsDialog.java @@ -68,6 +68,7 @@ private JTable getGuidePointsTable() { // JAVA 6 GuidePointsTable.setFillsViewportHeight(true); mGuidePointsTable.setModel(new AbstractTableModel() { static final long serialVersionUID=1L; + @Override public String getColumnName(int col) { switch(col) { @@ -81,8 +82,11 @@ public String getColumnName(int col) { return ""; } } + @Override public int getRowCount() { return BoardCAD.getInstance().getSelectedEdit().getGuidePoints().size(); } + @Override public int getColumnCount() { return 3; } + @Override public Object getValueAt(int row, int col) { switch(col) @@ -100,6 +104,7 @@ public Object getValueAt(int row, int col) { } } + @Override public boolean isCellEditable(int row, int col) { switch(col) @@ -112,6 +117,7 @@ public boolean isCellEditable(int row, int col) return true; } } + @Override public void setValueAt(Object value, int row, int col) { Point2D.Double pnt = BoardCAD.getInstance().getSelectedEdit().getGuidePoints().get(row); double val = UnitUtils.convertInputStringToInternalLengthUnit((String)value); @@ -139,6 +145,7 @@ public void setValueAt(Object value, int row, int col) { // this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { BoardCAD.getInstance().getSelectedEdit().getGuidePoints().add(new Point2D.Double()); @@ -155,6 +162,7 @@ public void actionPerformed(ActionEvent arg0) { // this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); }; + @Override public void actionPerformed(ActionEvent arg0) { int[] ai = mGuidePointsTable.getSelectedRows(); @@ -176,9 +184,11 @@ public void actionPerformed(ActionEvent arg0) { mGuidePointsTable.add(menu); mGuidePointsTable.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(MouseEvent e) { showPopup(e); } + @Override public void mouseReleased(MouseEvent e) { showPopup(e); } diff --git a/boardcad/gui/jdk/CategorizedSettingsComponent.java b/boardcad/gui/jdk/CategorizedSettingsComponent.java index 720703b..88c96bd 100644 --- a/boardcad/gui/jdk/CategorizedSettingsComponent.java +++ b/boardcad/gui/jdk/CategorizedSettingsComponent.java @@ -29,6 +29,7 @@ public CategorizedSettingsComponent(final CategorizedSettings settings) initialize(); mCategorizedSettings.addCategorySettingsChangeListener(new CategorySettingsChangeListener(){ + @Override public void onCategoryRemoved(String categoryName) { for(int i = 0; i < mTabbedPane.getTabCount(); i++) @@ -40,6 +41,7 @@ public void onCategoryRemoved(String categoryName) } } } + @Override public void onCategoryAdded(String categoryName) { final Settings settings = mCategorizedSettings.getCategory(categoryName); diff --git a/boardcad/gui/jdk/ComboBoxDialog.java b/boardcad/gui/jdk/ComboBoxDialog.java index a3bf2d8..4a45186 100644 --- a/boardcad/gui/jdk/ComboBoxDialog.java +++ b/boardcad/gui/jdk/ComboBoxDialog.java @@ -108,6 +108,7 @@ private JButton getOkButton() { OkButton.setText(LanguageResource.getString("OKBUTTON_STR") ); OkButton.setMinimumSize(new Dimension(50, 14)); OkButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { setVisible(false); mWasCancelled = false; @@ -128,6 +129,7 @@ private JButton getCancelButton() { CancelButton.setText(LanguageResource.getString("CANCELBUTTON_STR") ); CancelButton.setMinimumSize(new Dimension(50, 14)); CancelButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { setVisible(false); } diff --git a/boardcad/gui/jdk/ControlPointInfo.java b/boardcad/gui/jdk/ControlPointInfo.java index a159078..a999f47 100644 --- a/boardcad/gui/jdk/ControlPointInfo.java +++ b/boardcad/gui/jdk/ControlPointInfo.java @@ -21,6 +21,8 @@ import cadcore.BezierKnot; import cadcore.UnitUtils; +import boardcad.commands.BrdCommand; +import boardcad.commands.BrdEditCommand; import boardcad.i18n.LanguageResource; public class ControlPointInfo extends JPanel { @@ -50,6 +52,11 @@ public ControlPointInfo() { super(); initialize(); } + + public BrdEditCommand getCmd() + { + return mCmd; + } /** * This method initializes this @@ -260,6 +267,7 @@ private JCheckBox getMContinous() { mContinous.setText(LanguageResource.getString("CONTROLPOINTCONTINOUS_STR")); mContinous.setToolTipText(LanguageResource.getString("CONTROLPOINTCONTINOUSTOOLTIP_STR")); mContinous.addItemListener(new java.awt.event.ItemListener() { + @Override public void itemStateChanged(java.awt.event.ItemEvent e) { if(mBlockActions) return; @@ -283,6 +291,7 @@ private JButton getSetButton() SetButton.setText(LanguageResource.getString("CONTROLPOINTSET_STR")); SetButton.setToolTipText(LanguageResource.getString("CONTROLPOINTSETTOOLTIP_STR")); SetButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { if(mBlockActions) return; @@ -294,6 +303,7 @@ public void actionPerformed(java.awt.event.ActionEvent e) { return SetButton; } + @Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); @@ -385,6 +395,7 @@ private JButton getSetControlPointVerticalButton() { setControlPointVerticalButton.setHorizontalTextPosition(SwingConstants.CENTER); setControlPointVerticalButton .addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { BrdCommand cmd = BoardCAD.getInstance().getCurrentCommand(); @@ -411,6 +422,7 @@ private JButton getSetControlPointHorizontalButton() { setControlPointHorizontalButton.setToolTipText(LanguageResource.getString("CONTROLPOINTHORIZONTALTOOLTIP_STR")); setControlPointHorizontalButton .addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { BrdCommand cmd = BoardCAD.getInstance().getCurrentCommand(); diff --git a/boardcad/gui/jdk/DesignPanel.java b/boardcad/gui/jdk/DesignPanel.java index 5376bb0..7ec0580 100644 --- a/boardcad/gui/jdk/DesignPanel.java +++ b/boardcad/gui/jdk/DesignPanel.java @@ -25,164 +25,144 @@ import java.awt.event.MouseMotionAdapter; import java.awt.event.MouseMotionListener; -import javax.media.j3d.AmbientLight; -import javax.media.j3d.Appearance; -import javax.media.j3d.Background; -import javax.media.j3d.BoundingSphere; -import javax.media.j3d.BranchGroup; -import javax.media.j3d.Canvas3D; -import javax.media.j3d.ColoringAttributes; -import javax.media.j3d.DirectionalLight; -import javax.media.j3d.Group; -import javax.media.j3d.Light; -import javax.media.j3d.Material; -import javax.media.j3d.Shape3D; -import javax.media.j3d.TextureAttributes; -import javax.media.j3d.Transform3D; -import javax.media.j3d.TransformGroup; -import javax.media.j3d.TriangleArray; +import javax.media.j3d.*; import javax.swing.JCheckBoxMenuItem; import javax.swing.JPopupMenu; -import javax.vecmath.Color3f; -import javax.vecmath.Point3d; -import javax.vecmath.Vector3f; - -import cadcore.NurbsPoint; +import javax.vecmath.*; import com.sun.j3d.utils.behaviors.vp.OrbitBehavior; import com.sun.j3d.utils.image.TextureLoader; -import com.sun.j3d.utils.universe.PlatformGeometry; -import com.sun.j3d.utils.universe.SimpleUniverse; -import com.sun.j3d.utils.universe.ViewingPlatform; - -import com.sun.j3d.exp.swing.JCanvas3D; -import com.sun.j3d.utils.behaviors.mouse.MouseRotate; +import com.sun.j3d.utils.universe.*; +import board.BezierBoard; +import cadcore.MathUtils; +import cadcore.NurbsPoint; -interface AbstractEditor -{ +interface AbstractEditor { void fit_all(); } -//=========================================================Design Panel -class DesignPanel extends Panel implements AbstractEditor -{ -/** +// =========================================================Design Panel +class DesignPanel extends Panel implements AbstractEditor { + /** * */ private static final long serialVersionUID = 1L; - // private UserInterface user_interface; + // private UserInterface user_interface; private StatusPanel status_panel; private RockerView rocker_view; private EdgeView edge_view; private OutlineView outline_view; - private ThreeDView rendered_view; + private ThreeDView rendered_view; private ThreeDView2 threed_view; - - - public DesignPanel(BoardHandler board_handler, StatusPanel sp) - { -// user_interface=ui; - status_panel=sp; - threed_view=new ThreeDView2(board_handler, this); - rocker_view=new RockerView(board_handler, this); - edge_view=new EdgeView(board_handler, this); - outline_view=new OutlineView(board_handler, this); - rendered_view=new ThreeDView(board_handler, this); + BranchGroup mRoot; + Switch mBezier3DOnSwitch; + Shape3D mBezier3DModel; + TransformGroup mScaleTransform; -/* - setLayout(new GridLayout(2,2,3,3)); - - add(rocker_view); - add(edge_view); - add(outline_view); + boolean mBezierBoardChangedFor3D = false; + +// Brd3DModelGenerator mBrd3DModelGenerator = new Brd3DModelGenerator(); + FasterBrd3DModelGenerator mBrd3DModelGenerator = new FasterBrd3DModelGenerator(); + + public DesignPanel(BoardHandler board_handler, StatusPanel sp) { + // user_interface=ui; + status_panel = sp; + + rocker_view = new RockerView(board_handler, this); + edge_view = new EdgeView(board_handler, this); + outline_view = new OutlineView(board_handler, this); + rendered_view = new ThreeDView(board_handler, this); + threed_view = new ThreeDView2(board_handler, this); + + /* + * setLayout(new GridLayout(2,2,3,3)); + * + * add(rocker_view); add(edge_view); add(outline_view); + * add(threed_view); + * + * doLayout(); redraw(); // threed_view.setSize(getPreferredSize()); + * threed_view.doLayout(); + */ + setLayout(new GridLayout(1, 1)); add(threed_view); - doLayout(); + + initBezierModel(); + redraw(); -// threed_view.setSize(getPreferredSize()); - threed_view.doLayout(); -*/ - setLayout(new GridLayout(1,1)); - add(threed_view); - doLayout(); -// redraw(); -// threed_view.setSize(getPreferredSize()); -// threed_view.doLayout(); + // threed_view.setSize(getPreferredSize()); + // threed_view.doLayout(); } - public void view_outline() - { + public void view_outline() { remove(rocker_view); remove(edge_view); remove(outline_view); remove(threed_view); - setLayout(new GridLayout(1,1)); + setLayout(new GridLayout(1, 1)); add(outline_view); doLayout(); redraw(); } - public void view_rocker() - { + public void view_rocker() { remove(rocker_view); remove(edge_view); remove(outline_view); remove(threed_view); - setLayout(new GridLayout(1,1)); + setLayout(new GridLayout(1, 1)); add(rocker_view); doLayout(); redraw(); } - public void view_edge() - { + + public void view_edge() { remove(rocker_view); remove(edge_view); remove(outline_view); remove(threed_view); - setLayout(new GridLayout(1,1)); + setLayout(new GridLayout(1, 1)); add(edge_view); doLayout(); redraw(); } - public void view_3d() - { + + public void view_3d() { remove(rocker_view); remove(edge_view); remove(outline_view); remove(threed_view); - setLayout(new GridLayout(1,1)); + setLayout(new GridLayout(1, 1)); add(threed_view); doLayout(); -// redraw(); -// threed_view.setSize(getPreferredSize()); -// threed_view.doLayout(); + redraw(); + // threed_view.setSize(getPreferredSize()); + // threed_view.doLayout(); } - public void view_rendered() - { + public void view_rendered() { remove(rocker_view); remove(edge_view); remove(outline_view); remove(threed_view); - setLayout(new GridLayout(1,1)); + setLayout(new GridLayout(1, 1)); add(rendered_view); doLayout(); -// redraw(); + redraw(); rendered_view.setSize(getPreferredSize()); rendered_view.doLayout(); } - public void view_all() - { + public void view_all() { remove(rocker_view); remove(edge_view); remove(outline_view); remove(threed_view); - setLayout(new GridLayout(2,2,3,3)); + setLayout(new GridLayout(2, 2, 3, 3)); add(rocker_view); add(edge_view); @@ -193,69 +173,131 @@ public void view_all() redraw(); } - public void fit_all() - { + @Override + public void fit_all() { rocker_view.fit(); edge_view.fit(); outline_view.fit(); threed_view.fit(); } - public void set_point_name(String text) - { + public void set_point_name(String text) { status_panel.set_point_name(text); status_panel.doLayout(); } - public void set_coordinates(double x, double y, double z) - { - status_panel.set_coordinates(x,y,z); + public void set_coordinates(double x, double y, double z) { + status_panel.set_coordinates(x, y, z); status_panel.doLayout(); } - public void update_3d() - { + public void update_3d() { rendered_view.update(); - } - public void addModel(BranchGroup model) - { + public void addModel(BranchGroup model) { rendered_view.addModel(model); } - public Shape3D getShape() - { + public Shape3D getShape() { return rendered_view.getShape(); } - public void set_airbrush(String filename) - { + public void set_airbrush(String filename) { rendered_view.set_airbrush(filename); } - public void redraw() - { + public void redraw() { rocker_view.repaint(); edge_view.repaint(); outline_view.repaint(); threed_view.repaint(); rendered_view.repaint(); -// rendered_view.doLayout(); + rendered_view.doLayout(); } - - public ThreeDView get3DView() - { + + public ThreeDView get3DView() { return rendered_view; } + + public void setShowBezierModel(boolean show) { + mBezier3DOnSwitch.setWhichChild(show ? Switch.CHILD_ALL + : Switch.CHILD_NONE); + } + + public boolean getShowBezierMode(boolean show) { + return (mBezier3DOnSwitch.getWhichChild() == Switch.CHILD_ALL); + } + + void initBezierModel() { + + mRoot = new BranchGroup(); + + mBezier3DOnSwitch = new Switch(); + mBezier3DOnSwitch.setCapability(Switch.ALLOW_SWITCH_READ); + mBezier3DOnSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); + + mBezier3DOnSwitch.setWhichChild(Switch.CHILD_ALL); + + mRoot.addChild(mBezier3DOnSwitch); + mScaleTransform = new TransformGroup(); + mScaleTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + mBezier3DOnSwitch.addChild(mScaleTransform); + mBezier3DModel = new Shape3D(); + mBezier3DModel.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); + mBezier3DModel.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); + // Create an Appearance. + Appearance a = new Appearance(); + Color3f ambient = new Color3f(0.4f, 0.4f, 0.4f); + Color3f emissive = new Color3f(0.0f, 0.0f, 0.0f); + Color3f diffuse = new Color3f(0.8f, 0.8f, 0.8f); + Color3f specular = new Color3f(1.0f, 1.0f, 1.0f); + + // Set up the material properties + a.setMaterial(new Material(ambient, emissive, diffuse, specular, 115.0f)); + mBezier3DModel.setAppearance(a); + mScaleTransform.addChild(mBezier3DModel); + + // BranchGroup copy = (BranchGroup)root.cloneTree(); + + addModel(mRoot); + } + + public Shape3D getBezier3DModel() { + return mBezier3DModel; + } + + public void setBezierScale(double scale, double offset) { + Transform3D transform = new Transform3D(); + transform.setScale(scale); + transform.setTranslation(new Vector3d(offset, 0.0, 0.0)); + transform.setRotation(new AxisAngle4d(1.0, 0.0, 0.0, -Math.PI / 2.0)); + mScaleTransform.setTransform(transform); + } + + public void updateBezier3DModel(BezierBoard brd) { + + System.out.println("DesignPanel.updateBezier3DModel()"); + + double scale = 0.008; + double offset = -brd.getLength() * scale / 2.0; + if (brd != null && mBezierBoardChangedFor3D) { + setBezierScale(scale, offset); + mBrd3DModelGenerator.update3DModel(brd, getBezier3DModel(), 8); + mBezierBoardChangedFor3D = false; + } + } + + public void setBoardChangedFor3D() { + mBezierBoardChangedFor3D = true; + } } -//=========================================================Views +// =========================================================Views -abstract class View extends Canvas -{ +abstract class View extends Canvas { /** * */ @@ -269,16 +311,15 @@ abstract class View extends Canvas protected Dimension off_dimension; protected Image off_image; protected Graphics g; - protected double scale; //transforms between image and board coordinates - protected int offset_x; //position of origo in image coordinates + protected double scale; // transforms between image and board coordinates + protected int offset_x; // position of origo in image coordinates protected int offset_y; - protected void clear_graphics() - { - Dimension d=getSize(); + protected void clear_graphics() { + Dimension d = getSize(); - if (g==null || d.width!=off_dimension.width || d.height!=off_dimension.height) - { + if (g == null || d.width != off_dimension.width + || d.height != off_dimension.height) { off_dimension = d; off_image = createImage(d.width, d.height); g = off_image.getGraphics(); @@ -286,17 +327,15 @@ protected void clear_graphics() g.setColor(BoardCAD.getInstance().getBackgroundColor()); g.fillRect(0, 0, d.width, d.height); -// g.setColor(getBackground()); -// g.fillRect(0, 0, d.width, d.height); -// g.draw3DRect(0,0,d.width-1,d.height-1,true); -// g.draw3DRect(3,3,d.width-7,d.height-7,false); + // g.setColor(getBackground()); + // g.fillRect(0, 0, d.width, d.height); + // g.draw3DRect(0,0,d.width-1,d.height-1,true); + // g.draw3DRect(3,3,d.width-7,d.height-7,false); } } - -class EdgeView extends View implements ItemListener, ActionListener -{ +class EdgeView extends View implements ItemListener, ActionListener { /** * */ @@ -316,23 +355,22 @@ class EdgeView extends View implements ItemListener, ActionListener private View the_view; - public EdgeView(BoardHandler bh, DesignPanel dp) - { - board_handler=bh; - design_panel=dp; - view_menu=new PopupMenu(); + public EdgeView(BoardHandler bh, DesignPanel dp) { + board_handler = bh; + design_panel = dp; + view_menu = new PopupMenu(); - is_marked=false; - is_dragged=false; - scale=1; - offset_x=0; - offset_y=0; + is_marked = false; + is_dragged = false; + scale = 1; + offset_x = 0; + offset_y = 0; - vee_item=new MenuItem("Set Vee"); - concave_item=new MenuItem("Set Concave"); - y_locked_item=new CheckboxMenuItem("y locked", false); - z_locked_item=new CheckboxMenuItem("z locked", false); - fit_item=new MenuItem("Fit"); + vee_item = new MenuItem("Set Vee"); + concave_item = new MenuItem("Set Concave"); + y_locked_item = new CheckboxMenuItem("y locked", false); + z_locked_item = new CheckboxMenuItem("z locked", false); + fit_item = new MenuItem("Fit"); vee_item.addActionListener(this); concave_item.addActionListener(this); @@ -348,202 +386,186 @@ public EdgeView(BoardHandler bh, DesignPanel dp) view_menu.add(vee_item); view_menu.add(concave_item); - add(view_menu); - the_view=this; + add(view_menu); + the_view = this; addMouseListener(EdgeMouse); addMouseMotionListener(EdgeMouseMotion); } - public void fit() - { - if(getSize().width == 0) + public void fit() { + if (getSize().width == 0) return; - - if(off_dimension==null) + + if (off_dimension == null) return; - - double width=board_handler.get_segment_width(); - if (width<100) - width=100; - scale=(double)(off_dimension.width-40)/width; - offset_y=(int)(board_handler.get_edge_offset()*scale+2*off_dimension.height/3); - offset_x=off_dimension.width/2; + double width = board_handler.get_segment_width(); + if (width < 100) + width = 100; + + scale = (off_dimension.width - 40) / width; + offset_y = (int) (board_handler.get_edge_offset() * scale + 2 * off_dimension.height / 3); + offset_x = off_dimension.width / 2; repaint(); } - public void actionPerformed(ActionEvent e) - { - if(e.getSource()==vee_item) - { - } - else if(e.getSource()==concave_item) - { - } - else if(e.getSource()==fit_item) - { + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == vee_item) { + } else if (e.getSource() == concave_item) { + } else if (e.getSource() == fit_item) { fit(); } } - public void itemStateChanged(ItemEvent e) - { + @Override + public void itemStateChanged(ItemEvent e) { } - public void paint(Graphics g2) - { + @Override + public void paint(Graphics g2) { update(g2); } - public void update(Graphics g2) - { - clear_graphics(); - - /** + @Override + public void update(Graphics g2) { + clear_graphics(); + /** + * * Copy the graphics context so we can change it. - + * * Cast it to Graphics2D so we can use antialiasing. - */ - Graphics2D g2d = (Graphics2D)g.create(); + Graphics2D g2d = (Graphics2D) g.create(); -// Turn on antialiasing, so painting is smooth. - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,BoardCAD.getInstance().isAntialiasing()?RenderingHints.VALUE_ANTIALIAS_ON:RenderingHints.VALUE_ANTIALIAS_OFF); - g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,BoardCAD.getInstance().isAntialiasing()?RenderingHints.VALUE_TEXT_ANTIALIAS_ON:RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); + // Turn on antialiasing, so painting is smooth. + g2d.setRenderingHint( + RenderingHints.KEY_ANTIALIASING, + BoardCAD.getInstance().isAntialiasing() ? RenderingHints.VALUE_ANTIALIAS_ON + : RenderingHints.VALUE_ANTIALIAS_OFF); + g2d.setRenderingHint( + RenderingHints.KEY_TEXT_ANTIALIASING, + BoardCAD.getInstance().isAntialiasing() ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON + : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); - if(is_dragged && !is_marked) - { + if (is_dragged && !is_marked) { g2d.setColor(Color.black); g2d.drawRect(zoom_x, zoom_y, zoom_width, zoom_height); } - board_handler.draw_edge(g2d, off_dimension.width, off_dimension.height, scale, offset_x, offset_y); + board_handler.draw_edge(g2d, off_dimension.width, off_dimension.height, + scale, offset_x, offset_y); g2.drawImage(off_image, 0, 0, this); } - MouseMotionListener EdgeMouseMotion=new MouseMotionAdapter() - { - public void mouseDragged(MouseEvent e) - { - if(e.isMetaDown()) - { - } - else if(e.isControlDown()) - { - } - else - { - is_dragged=true; - if(is_marked) - { - if(!y_locked_item.getState()) - board_handler.set_y((-e.getY()+offset_y)/scale); - if(!z_locked_item.getState()) - board_handler.set_z((e.getX()-offset_x)/scale); + MouseMotionListener EdgeMouseMotion = new MouseMotionAdapter() { + @Override + public void mouseDragged(MouseEvent e) { + if (e.isMetaDown()) { + } else if (e.isControlDown()) { + } else { + is_dragged = true; + if (is_marked) { + if (!y_locked_item.getState()) + board_handler.set_y((-e.getY() + offset_y) / scale); + if (!z_locked_item.getState()) + board_handler.set_z((e.getX() - offset_x) / scale); board_handler.set_point(); - design_panel.set_coordinates(board_handler.get_x(), board_handler.get_y(), board_handler.get_z()); + design_panel.set_coordinates(board_handler.get_x(), + board_handler.get_y(), board_handler.get_z()); design_panel.redraw(); - } - else - { - dragged_x=e.getX(); - dragged_y=e.getY(); - if(dragged_y>clicked_y) - dragged_y=clicked_y+(int)(Math.abs(dragged_x-clicked_x)*(double)off_dimension.height/(double)off_dimension.width); + } else { + dragged_x = e.getX(); + dragged_y = e.getY(); + if (dragged_y > clicked_y) + dragged_y = clicked_y + + (int) (Math.abs(dragged_x - clicked_x) + * (double) off_dimension.height / off_dimension.width); else - dragged_y=clicked_y-(int)(Math.abs(dragged_x-clicked_x)*(double)off_dimension.height/(double)off_dimension.width); - if(clicked_xclicked_y) - dragged_y=clicked_y+(int)(Math.abs(dragged_x-clicked_x)*(double)off_dimension.height/(double)off_dimension.width); + } else { + dragged_x = e.getX(); + dragged_y = e.getY(); + if (dragged_y > clicked_y) + dragged_y = clicked_y + + (int) (Math.abs(dragged_x - clicked_x) + * (double) off_dimension.height / off_dimension.width); else - dragged_y=clicked_y-(int)(Math.abs(dragged_x-clicked_x)*(double)off_dimension.height/(double)off_dimension.width); - if(clicked_xclicked_y) - dragged_y=clicked_y+(int)(Math.abs(dragged_x-clicked_x)*(double)off_dimension.height/(double)off_dimension.width); + } else { + dragged_x = e.getX(); + dragged_y = e.getY(); + if (dragged_y > clicked_y) + dragged_y = clicked_y + + (int) (Math.abs(dragged_x - clicked_x) + * (double) off_dimension.height / off_dimension.width); else - dragged_y=clicked_y-(int)(Math.abs(dragged_x-clicked_x)*(double)off_dimension.height/(double)off_dimension.width); - if(clicked_xclicked_y) - dragged_y=clicked_y+(int)(Math.abs(dragged_x-clicked_x)*(double)off_dimension.height/(double)off_dimension.width); + } else { + dragged_x = e.getX(); + dragged_y = e.getY(); + if (dragged_y > clicked_y) + dragged_y = clicked_y + + (int) (Math.abs(dragged_x - clicked_x) + * (double) off_dimension.height / off_dimension.width); else - dragged_y=clicked_y-(int)(Math.abs(dragged_x-clicked_x)*(double)off_dimension.height/(double)off_dimension.width); - if(clicked_x mThreads = new Vector(); + boolean mInitialModelRun = true; + + public void update3DModel(BezierBoard brd, Shape3D model, int numTasks) { + if (brd.isEmpty()) + return; + + mCancelExecuting = true; + + System.out + .println("BezierBoard.update3DModel() cancel execution, wait for threads"); + + for (Thread thread : mThreads) { + try { + thread.join(); + } catch (InterruptedException e) { + System.out + .println("BezierBoard.update3DModel() InterruptedException"); + } + } + + mThreads.clear(); + + System.out.println("BezierBoard.update3DModel() Wait finished"); + + if (model.numGeometries() != numTasks) { + System.out + .printf("BezierBoard.update3DModel() Need initial run geom:%d tasks:%d", + model.numGeometries(), numTasks); + + model.removeAllGeometries(); + mInitialModelRun = true; + } else { + mInitialModelRun = false; + } + + mCancelExecuting = false; + double length = brd.getLength(); + + for (int i = 0; i < numTasks; i++) { + final double sx = (length / numTasks) * i; + final double ex = (length / numTasks) * (i + 1); + final int index = i; + Runnable task = () -> { + update3DModel((BezierBoard) brd.clone(), model, sx, ex, index); + }; + + Thread thread = new Thread(task); + mThreads.add(thread); + thread.start(); + } + + } + + public void update3DModel(BezierBoard brd, Shape3D model, double startX, + double endX, int index) { + double lengthAccuracy = 1.0; + double deckWidthAccuracy = 1.0; + double bottomWidthAccuracy = 1.0; + + double spanLength = endX - startX; + double width = brd.getCenterWidth(); + + int lengthSteps = (int) (spanLength / lengthAccuracy) + 1; + // int lengthSteps = 200; + int deckSteps = (int) ((width / 2.0) / deckWidthAccuracy) + 1; + int railSteps = 0; + int bottomSteps = (int) (width / 2.0 / bottomWidthAccuracy) + 1; + + double lengthStep = spanLength / lengthSteps; + + int nrOfCoords = (lengthSteps) * (deckSteps + railSteps + bottomSteps) + * 4 * 2; + + QuadArray quads; + quads = new QuadArray(nrOfCoords, IndexedQuadArray.COORDINATES + | IndexedQuadArray.NORMALS); + + Point3d[][] vertices = new Point3d[deckSteps+1][lengthSteps+1]; + Vector3f[][] normals = new Vector3f[deckSteps+1][lengthSteps+1]; + Point3d[] quadCoords = new Point3d[lengthSteps*4]; + Vector3f[] quadNormals = new Vector3f[lengthSteps*4]; + + int nrOfQuads = 0; + double xPos = 0.0; + + // Deck + double minAngle = -45.0; + double maxAngle = 150.0; + + //Generate deck coordinates + for (int i = 0; i <= deckSteps; i++) { + if (mCancelExecuting) + return; + + xPos = startX; + + for (int j = 0; j <= lengthSteps; j++) { + + vertices[i][j] = new Point3d(brd.getSurfacePoint(xPos, minAngle, maxAngle, i, deckSteps)); + normals[i][j] = new Vector3f(brd.getSurfaceNormal(xPos, minAngle, maxAngle,i, deckSteps)); + + xPos += lengthStep; + + } + } + + //Generate quads + for (int i = 0; i < deckSteps; i++) { + if (mCancelExecuting) + return; + + int q = 0; + for (int j = 0; j < lengthSteps; j++) { + quadCoords[q] = vertices[i][j]; + quadNormals[q] = normals[i][j]; + ++q; + quadCoords[q] = vertices[i][j+1]; + quadNormals[q] = normals[i][j+1]; + ++q; + quadCoords[q] = vertices[i+1][j+1]; + quadNormals[q] = normals[i+1][j+1]; + ++q; + quadCoords[q] = vertices[i+1][j]; + quadNormals[q] = normals[i+1][j]; + ++q; + } + quads.setCoordinates(nrOfQuads * 4, quadCoords); + quads.setNormals(nrOfQuads * 4, quadNormals); + nrOfQuads += lengthSteps; + } + + //Mirror deck coordinates + for (int i = 0; i <= deckSteps; i++) { + if (mCancelExecuting) + return; + + for (int j = 0; j <= lengthSteps; j++) { + + vertices[i][j].setY(-vertices[i][j].getY()); + normals[i][j].setY(-normals[i][j].getY()); + } + } + + //Generate mirrored quads + for (int i = 0; i < deckSteps; i++) { + if (mCancelExecuting) + return; + + int q = 0; + for (int j = 0; j < lengthSteps; j++) { + quadCoords[q] = vertices[i+1][j]; + quadNormals[q] = normals[i+1][j]; + ++q; + quadCoords[q] = vertices[i+1][j+1]; + quadNormals[q] = normals[i+1][j+1]; + ++q; + quadCoords[q] = vertices[i][j+1]; + quadNormals[q] = normals[i][j+1]; + ++q; + quadCoords[q] = vertices[i][j]; + quadNormals[q] = normals[i][j]; + ++q; + } + quads.setCoordinates(nrOfQuads * 4, quadCoords); + quads.setNormals(nrOfQuads * 4, quadNormals); + nrOfQuads += lengthSteps; + } + + //Generate bottom + minAngle = maxAngle; + maxAngle = 360.0; + for (int i = 0; i <= bottomSteps; i++) { + if (mCancelExecuting) + return; + + xPos = startX; + + for (int j = 0; j <= lengthSteps; j++) { + + vertices[i][j] = brd.getSurfacePoint(xPos, minAngle, maxAngle, i, bottomSteps); + normals[i][j] = new Vector3f(brd.getSurfaceNormal(xPos, minAngle, maxAngle,i, bottomSteps)); + + xPos += lengthStep; + + } + } + + //Generate quads + for (int i = 0; i < bottomSteps; i++) { + if (mCancelExecuting) + return; + + int q = 0; + for (int j = 0; j < lengthSteps; j++) { + quadCoords[q] = vertices[i][j]; + quadNormals[q] = normals[i][j]; + ++q; + quadCoords[q] = vertices[i][j+1]; + quadNormals[q] = normals[i][j+1]; + ++q; + quadCoords[q] = vertices[i+1][j+1]; + quadNormals[q] = normals[i+1][j+1]; + ++q; + quadCoords[q] = vertices[i+1][j]; + quadNormals[q] = normals[i+1][j]; + ++q; + } + quads.setCoordinates(nrOfQuads * 4, quadCoords); + quads.setNormals(nrOfQuads * 4, quadNormals); + nrOfQuads += lengthSteps; + } + + //Mirror bottom coordinates + for (int i = 0; i <= bottomSteps; i++) { + if (mCancelExecuting) + return; + + for (int j = 0; j <= lengthSteps; j++) { + + vertices[i][j].setY(-vertices[i][j].getY()); + normals[i][j].setY(-normals[i][j].getY()); + } + } + + //Generate mirrored quads + for (int i = 0; i < bottomSteps; i++) { + if (mCancelExecuting) + return; + + int q = 0; + for (int j = 0; j < lengthSteps; j++) { + quadCoords[q] = vertices[i+1][j]; + quadNormals[q] = normals[i+1][j]; + ++q; + quadCoords[q] = vertices[i+1][j+1]; + quadNormals[q] = normals[i+1][j+1]; + ++q; + quadCoords[q] = vertices[i][j+1]; + quadNormals[q] = normals[i][j+1]; + ++q; + quadCoords[q] = vertices[i][j]; + quadNormals[q] = normals[i][j]; + ++q; + } + quads.setCoordinates(nrOfQuads * 4, quadCoords); + quads.setNormals(nrOfQuads * 4, quadNormals); + nrOfQuads += lengthSteps; + } + + if (mInitialModelRun) { + model.addGeometry(quads); + } else { + model.setGeometry(quads, index); + } + + } +} diff --git a/boardcad/gui/jdk/JOGLPanel.java b/boardcad/gui/jdk/JOGLPanel.java index f25045e..d20113e 100755 --- a/boardcad/gui/jdk/JOGLPanel.java +++ b/boardcad/gui/jdk/JOGLPanel.java @@ -1,5 +1,5 @@ package boardcad.gui.jdk; - +/* import board.NurbsBoard; import cadcore.NurbsSurface; import cadcore.NurbsPoint; @@ -29,51 +29,22 @@ import java.awt.event.MouseMotionAdapter; import java.awt.event.MouseMotionListener; - - -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.GLProfile; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.awt.GLCanvas; -import javax.media.opengl.awt.GLJPanel; - - -import javax.media.opengl.GL; -import javax.media.opengl.GL2; -import javax.media.opengl.glu.GLU; - - -import cadcore.NurbsPoint; - +import com.jogamp.opengl.*; +import com.jogamp.opengl.awt.*; +import com.jogamp.opengl.glu.*; import com.sun.j3d.utils.behaviors.vp.OrbitBehavior; import com.sun.j3d.utils.image.TextureLoader; import com.sun.j3d.utils.universe.PlatformGeometry; import com.sun.j3d.utils.universe.SimpleUniverse; - - - import java.awt.*; import java.awt.event.*; -import javax.swing.*; -import javax.media.opengl.GL2; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.awt.GLCanvas; -import javax.media.opengl.glu.GLU; -import com.jogamp.opengl.util.FPSAnimator; -import static javax.media.opengl.GL.*; // GL constants -import static javax.media.opengl.GL2.*; // GL2 constants - - +import javax.swing.*; import com.sun.j3d.utils.universe.ViewingPlatform; - - //=========================================================JOGL Panel class JOGLPanel extends Panel { @@ -124,9 +95,9 @@ protected void init( GL2 gl, int width, int height ) glu = new GLU(); // get GL Utilities gl.glClearColor(0.4f, 0.4f, 0.4f, 0.0f); // set background (clear) color gl.glClearDepth(1.0f); // set clear depth value to farthest - gl.glEnable(GL_DEPTH_TEST); // enables depth testing - gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do - gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction + gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing + gl.glDepthFunc(GL.GL_LEQUAL); // the type of depth test to do + gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); // best perspective correction // gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting } @@ -141,22 +112,22 @@ protected void setup( GL2 gl, int width, int height ) float[] lightPos = {0.0f, 0.0f, 10.0f, SHINE_ALL_DIRECTIONS}; float[] lightColorAmbient = {0.2f, 0.2f, 0.2f, 1f}; float[] lightColorSpecular = {0.6f, 0.6f, 0.6f, 1f}; - gl.glLightfv(GL_LIGHT0, GL_POSITION, lightPos, 0); - gl.glLightfv(GL_LIGHT0, GL_AMBIENT, lightColorAmbient, 0); + gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lightPos, 0); + gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, lightColorAmbient, 0); // gl.glLightfv(GL_LIGHT0, GL_SPECULAR, lightColorSpecular, 0); gl.glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColorSpecular, 0); // Enable lighting in GL. - gl.glEnable(GL_LIGHTING); - gl.glEnable(GL_LIGHT0); + gl.glEnable(GL.GL_LIGHTING); + gl.glEnable(GL.GL_LIGHT0); // Set material properties. float[] rgba = {1.0f, 1.0f, 1.0f, 1.0f}; - gl.glMaterialfv(GL_FRONT, GL_AMBIENT, rgba, 0); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, rgba, 0); // gl.glMaterialfv(GL_FRONT, GL_SPECULAR, rgba, 0); - gl.glMaterialfv(GL_FRONT, GL_DIFFUSE, rgba, 0); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, rgba, 0); // gl.glMaterialf(GL_FRONT, GL_SHININESS, 0.5f); - gl.glShadeModel(GL_FLAT); + gl.glShadeModel(GL.GL_FLAT); // Set the view port (display area) to cover the entire window @@ -405,4 +376,4 @@ public void setBackgroundColor(Color color) - +*/ diff --git a/boardcad/gui/jdk/JavaDraw.java b/boardcad/gui/jdk/JavaDraw.java index 3a73250..8ebe8dc 100644 --- a/boardcad/gui/jdk/JavaDraw.java +++ b/boardcad/gui/jdk/JavaDraw.java @@ -24,6 +24,7 @@ public JavaDraw(Graphics2D graphics) g = graphics; } + @Override public void close() { @@ -34,62 +35,74 @@ Graphics2D getGraphics2D() return g; } + @Override public void setColor(Color color) { g.setColor(color); } + @Override public void setStroke(Stroke stroke) { g.setStroke(stroke); } + @Override public void transform(AffineTransform transform) { g.transform(transform); } + @Override public void setTransform(AffineTransform transform) { g.setTransform(transform); } + @Override public AffineTransform getTransform() { return g.getTransform(); } + @Override public void draw(Line2D line) { g.draw(line); } + @Override public void draw(Ellipse2D line) { g.draw(line); } + @Override public void draw(CubicCurve2D curve) { g.draw(curve); } + @Override public void draw(GeneralPath path) { g.draw(path); } + @Override public void fill(Ellipse2D ellipse) { g.fill(ellipse); } + @Override public void fill(GeneralPath path) { g.fill(path); } + @Override public void moveTo(Point2D point) { } diff --git a/boardcad/gui/jdk/Machine2DView.java b/boardcad/gui/jdk/Machine2DView.java index b8b6cc1..243afe2 100644 --- a/boardcad/gui/jdk/Machine2DView.java +++ b/boardcad/gui/jdk/Machine2DView.java @@ -6,45 +6,38 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Point; import java.awt.RenderingHints; import java.awt.Stroke; import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.event.MouseWheelEvent; import java.awt.geom.AffineTransform; import java.awt.geom.Line2D; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JPopupMenu; -import javax.vecmath.Point3d; -import javax.vecmath.Vector3d; - -import cadcore.UnitUtils; +import javax.vecmath.*; import board.BezierBoard; +import boardcad.commands.BrdCommand; +import boardcad.commands.BrdPositionCommand; import boardcad.i18n.LanguageResource; import boardcam.MachineConfig; import boardcam.holdingsystems.AbstractBlankHoldingSystem; -public class Machine2DView extends BoardEdit{ +public class Machine2DView extends BoardEdit { static final double fixedHeightBorder = 0; - boolean mShowDeck = true; + public boolean mShowDeck = true; double BORDER = 10; BrdCommand mBrdPosCommand; - - MachineConfig mConfig; - - Point3d mCutterOffset = new Point3d(0.0,0.0,0.0); - - - Machine2DView(MachineConfig config) - { + + public MachineConfig mConfig; + + Point3d mCutterOffset = new Point3d(0.0, 0.0, 0.0); + + Machine2DView(MachineConfig config) { super(); - + mConfig = config; System.out.printf("Machine2DView constructor mConfig:%s this:%s\n", mConfig.toString(), this.toString()); @@ -52,11 +45,12 @@ public class Machine2DView extends BoardEdit{ final JPopupMenu menu = new JPopupMenu(); final AbstractAction toggleDeckBottom = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("TOGGLEDECKBOTTOM_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { mShowDeck = !mShowDeck; repaint(); @@ -64,51 +58,48 @@ public void actionPerformed(ActionEvent arg0) { }; menu.add(toggleDeckBottom); add(menu); - - setPreferredSize(new Dimension(400,100)); + + setPreferredSize(new Dimension(400, 100)); setLayout(new BorderLayout()); - - mBrdPosCommand = new BrdPositionCommand(); - + + mBrdPosCommand = new BrdPositionCommand(this); }; - public void fit_all() - { + @Override + public void fit_all() { Dimension dim = getSize(); double len = 0.0; BezierBoard brd = mConfig.getBoard(); - if(brd != null) - { + if (brd != null) { len = brd.getLength(); } - if(mConfig.getBlankHoldingSystem() != null) - { + if (mConfig.getBlankHoldingSystem() != null) { len += mConfig.getBlankHoldingSystem().getBlankDeckOffsetPos().x; } - mScale = (dim.width-((BORDER*dim.width/100)*2))/len; + mScale = (dim.width - ((BORDER * dim.width / 100) * 2)) / len; - mOffsetX = (BORDER*dim.width/100); + mOffsetX = (BORDER * dim.width / 100); - mOffsetY = dim.height*1/2; + mOffsetY = dim.height * 1 / 2; mLastWidth = dim.width; mLastHeight = dim.height; - + calcViewOffset(); repaint(); } - public void adjustScaleAndOffset() - { + @Override + public void adjustScaleAndOffset() { double currentWidth = getWidth(); double currentHeight = getHeight(); - double widthChange = (currentWidth/mLastWidth); - double heightChange = (currentHeight/mLastHeight); + double widthChange = (currentWidth / mLastWidth); + double heightChange = (currentHeight / mLastHeight); mScale *= widthChange; @@ -120,101 +111,94 @@ public void adjustScaleAndOffset() } - public void setCutterOffset(Point3d pos){ + public void setCutterOffset(Point3d pos) { mCutterOffset = pos; repaint(); } - + + @Override public void paintComponent(Graphics g) { adjustScaleAndOffset(); - /** - + * * Copy the graphics context so we can change it. - - * Cast it to Graphics2D so we can use antialiasing. - + * + * Cast it to Graphics2D so we can use anti-aliasing. */ - Graphics2D g2d = (Graphics2D)g.create(); - + Graphics2D g2d = (Graphics2D) g.create(); - -// Turn on antialiasing, so painting is smooth. + // Turn on anti-aliasing, so painting is smooth. g2d.setRenderingHint( - RenderingHints.KEY_ANTIALIASING, + RenderingHints.KEY_ANTIALIASING, + + RenderingHints.VALUE_ANTIALIAS_ON); - RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, - RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - -// Paint the background. + // Paint the background. Color bkgColor = Color.LIGHT_GRAY; g2d.setColor(bkgColor); - + g2d.fillRect(0, 0, getWidth() - 1, getHeight() - 1); - //Draw the blank holding system + // Draw the blank holding system AbstractBlankHoldingSystem holdingSystem = mConfig.getBlankHoldingSystem(); - if(holdingSystem == null) - { + if (holdingSystem == null) { return; } holdingSystem.draw(g2d, mOffsetX, mOffsetY, mScale, mShowDeck); - - //Draw the blank and the board - Vector3d boardOffset = mShowDeck?holdingSystem.getBoardDeckOffsetPos():holdingSystem.getBoardBottomOffsetPos(); - double boardAngle = mShowDeck?holdingSystem.getBoardDeckOffsetAngle():holdingSystem.getBoardBottomOffsetAngle(); - - Vector3d blankOffset = mShowDeck?holdingSystem.getBlankDeckOffsetPos():holdingSystem.getBlankBottomOffsetPos(); - double blankAngle = mShowDeck?holdingSystem.getBlankDeckOffsetAngle():holdingSystem.getBlankBottomOffsetAngle(); - + + // Draw the blank and the board + Vector3d boardOffset = mShowDeck ? holdingSystem.getBoardDeckOffsetPos() : holdingSystem.getBoardBottomOffsetPos(); + double boardAngle = mShowDeck ? holdingSystem.getBoardDeckOffsetAngle() : holdingSystem.getBoardBottomOffsetAngle(); + + Vector3d blankOffset = mShowDeck ? holdingSystem.getBlankDeckOffsetPos() : holdingSystem.getBlankBottomOffsetPos(); + double blankAngle = mShowDeck ? holdingSystem.getBlankDeckOffsetAngle() : holdingSystem.getBlankBottomOffsetAngle(); + JavaDraw jd = new JavaDraw(g2d); - - // System.out.printf("OffsetX: %f, OffsetY: %f, boardOffset: %f,%f boardAngle: %f, blankOffset: %f,%f blankAngle: %f\n", mOffsetX, mOffsetY, boardOffset.x, boardOffset.z, boardAngle, blankOffset.x, blankOffset.z, blankAngle); - - Stroke stroke = new BasicStroke((float)(1.0/mScale)); + + // System.out.printf("OffsetX: %f, OffsetY: %f, boardOffset: %f,%f boardAngle: %f, blankOffset: %f,%f blankAngle: %f\n", + // mOffsetX, mOffsetY, boardOffset.x, boardOffset.z, boardAngle, + // blankOffset.x, blankOffset.z, blankAngle); + + Stroke stroke = new BasicStroke((float) (1.2 / mScale)); g2d.setStroke(stroke); - + BezierBoard brd = mConfig.getBoard(); - if(brd != null) - { - BezierBoardDrawUtil.paintBezierSpline(jd, mOffsetX+(boardOffset.x*mScale), mOffsetY-(boardOffset.z*mScale), boardAngle, mScale, BoardCAD.getInstance().getBrdColor(), stroke, brd.getDeck(), (mShowDeck?BezierBoardDrawUtil.FlipY:0), false); - BezierBoardDrawUtil.paintBezierSpline(jd, mOffsetX+(boardOffset.x*mScale), mOffsetY-(boardOffset.z*mScale), boardAngle, mScale, BoardCAD.getInstance().getBrdColor(), stroke, brd.getBottom(), mShowDeck?BezierBoardDrawUtil.FlipY:0, false); + if (brd != null) { + BezierBoardDrawUtil.paintBezierSpline(jd, mOffsetX + (boardOffset.x * mScale), mOffsetY - (boardOffset.z * mScale), mScale, boardAngle, BoardCAD.getInstance().getBrdColor(), stroke, brd.getDeck(), (mShowDeck ? BezierBoardDrawUtil.FlipY : 0), false); + BezierBoardDrawUtil.paintBezierSpline(jd, mOffsetX + (boardOffset.x * mScale), mOffsetY - (boardOffset.z * mScale), mScale, boardAngle, BoardCAD.getInstance().getBrdColor(), stroke, brd.getBottom(), mShowDeck ? BezierBoardDrawUtil.FlipY : 0, false); } - //Draw blank + // Draw blank BezierBoard blank = mConfig.getBlank(); - if(blank != null && !blank.isEmpty()) - { + if (blank != null && !blank.isEmpty()) { Color blankColor = BoardCAD.getInstance().getBlankColor(); - BezierBoardDrawUtil.paintBezierSpline(jd, mOffsetX+(blankOffset.x*mScale), mOffsetY-(blankOffset.z*mScale), blankAngle, mScale, blankColor, stroke, blank.getDeck(), mShowDeck?BezierBoardDrawUtil.FlipY:0, false); - BezierBoardDrawUtil.paintBezierSpline(jd, mOffsetX+(blankOffset.x*mScale), mOffsetY-(blankOffset.z*mScale), blankAngle, mScale, blankColor, stroke, blank.getBottom(), mShowDeck?BezierBoardDrawUtil.FlipY:0, false); + BezierBoardDrawUtil.paintBezierSpline(jd, mOffsetX + (blankOffset.x * mScale), mOffsetY - (blankOffset.z * mScale), mScale, blankAngle, blankColor, stroke, blank.getDeck(), mShowDeck ? BezierBoardDrawUtil.FlipY : 0, false); + BezierBoardDrawUtil.paintBezierSpline(jd, mOffsetX + (blankOffset.x * mScale), mOffsetY - (blankOffset.z * mScale), mScale, blankAngle, blankColor, stroke, blank.getBottom(), mShowDeck ? BezierBoardDrawUtil.FlipY : 0, false); } - - //Setup for drawing + + // Setup for drawing AffineTransform savedTransform = g2d.getTransform(); - + AffineTransform at = new AffineTransform(); - + at.setToTranslation(mOffsetX, mOffsetY); - - g2d.transform(at); - - at.setToScale(mScale, mScale); - + + at.scale(mScale, mScale); + g2d.transform(at); - - //Draw cutter offset + + // Draw cutter offset g2d.setColor(Color.BLUE); - + final double halfCrossWidth = 5.0; Line2D line = new Line2D.Double(); line.setLine(-halfCrossWidth + mCutterOffset.x, -mCutterOffset.z, halfCrossWidth + mCutterOffset.x, -mCutterOffset.z); @@ -222,206 +206,80 @@ public void paintComponent(Graphics g) { line.setLine(mCutterOffset.x, -halfCrossWidth - mCutterOffset.z, mCutterOffset.x, halfCrossWidth - mCutterOffset.z); g2d.draw(line); - g2d.setTransform(savedTransform); - } - - public void drawSlidingInfo(Graphics2D g, Color color, Stroke stroke, BezierBoard brd) - { -// drawProfileSlidingInfo(this, g, color, stroke, brd); - } - - public BrdCommand getCurrentCommand() - { - return mBrdPosCommand; - } + g2d.setTransform(savedTransform); - void calcViewOffset() - { - //mOffsetY = getCurrentMachineConfig().getDouble(MachineConfig.SUPPORT_1_HEIGHT)/UnitUtils.MILLIMETER_PR_CENTIMETER; - } + // Draw sliding line on brd + double brdX = (mBrdCoord.x / Math.cos(boardAngle)) - boardOffset.x; + if (brdX < 0 || brdX > brd.getLength()) + return; - class BrdPositionCommand extends BrdInputCommand - { - double mOriginalOffsetX; - double mOriginalOffsetY; - Point mPressedPos; - boolean mButtonPressed = true; - - BrdPanCommand mPanCommand = new BrdPanCommand(); - BrdZoomCommand mZoomCommand = new BrdZoomCommand(); - boolean mIsPaning = false; - - BrdPositionCommand() - { - mCanUndo = false; - } + g2d.setColor(Color.RED); + savedTransform = g2d.getTransform(); + at = new AffineTransform(); - public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) - { - if(!mShowDeck) - return; - - Point pos = event.getPoint(); - Vector3d deckOffset = mConfig.getBlankHoldingSystem().getBoardDeckOffsetPos(); - mOriginalOffsetX = deckOffset.x; - mOriginalOffsetY = deckOffset.z; - mPressedPos = (Point)pos.clone(); - mButtonPressed = true; - } + at.setToTranslation(mOffsetX, mOffsetY); + g2d.transform(at); + at.setToScale(mScale, mScale); + g2d.transform(at); + at.setToTranslation(boardOffset.x, -boardOffset.z); + g2d.transform(at); + at.setToRotation(boardAngle); + g2d.transform(at); + double deckY = -brd.getDeckAtPos(brdX); + double bottomY = -brd.getRockerAtPos(brdX); + line.setLine(brdX, deckY * (mShowDeck ? 1 : -1), brdX, bottomY * (mShowDeck ? 1 : -1)); + g2d.draw(line); - public void onMouseDragged(BoardEdit source, MouseEvent event) - { - if(mIsPaning) - { - mPanCommand.onMouseDragged(source, event); - return; - } - - if(!mShowDeck) - return; - - if(!mButtonPressed) - return; - - Point pos = event.getPoint(); - - double offsetX = mOriginalOffsetX + (((pos.x - mPressedPos.x))*(event.isAltDown()?0.1:1.0)/mScale); - double offsetY = mOriginalOffsetY - (((pos.y - mPressedPos.y))*(event.isAltDown()?0.1:1.0)/mScale); -// System.out.printf("offsetX: %f, offsetY: %f\n",offsetX, offsetY); - mConfig.getBlankHoldingSystem().setBoardDeckOffsetPos(new Vector3d(offsetX, 0.0, offsetY)); - - //System.out.printf("onMouseDragged mConfig:%s this:%s\n", mConfig.toString(), this.toString()); - - source.repaint(); - } + g2d.setTransform(savedTransform); - public void onLeftMouseButtonReleased(BoardEdit source, MouseEvent event) - { - mButtonPressed = false; - } - - public void onMouseWheelMoved(BoardEdit source, MouseWheelEvent event) - { - int scroll = event.getWheelRotation(); + // TODO Draw sliding line on blank + g2d.setColor(Color.BLUE); + savedTransform = g2d.getTransform(); + at = new AffineTransform(); - int steps = scroll*((scroll>0)?1:-1); - for(int i = 0; i < steps; i++) - { - if(scroll < 0) - { - mZoomCommand.zoomInStep(source, event.isAltDown()); - } - else - { - mZoomCommand.zoomOutStep(source, event.isAltDown()); - } + at.setToTranslation(mOffsetX, mOffsetY); + g2d.transform(at); + at.setToScale(mScale, mScale); + g2d.transform(at); + at.setToTranslation(blankOffset.x, -blankOffset.z); + g2d.transform(at); + at.setToRotation(blankAngle); + g2d.transform(at); - } - event.consume(); - } + double blankX = (mBrdCoord.x / Math.cos(blankAngle)) - blankOffset.x; + double blankDeckY = -blank.getDeckAtPos(blankX); + double blankBottomY = -blank.getRockerAtPos(blankX); + line.setLine(blankX, blankDeckY * (mShowDeck ? 1 : -1), blankX, blankBottomY * (mShowDeck ? 1 : -1)); + g2d.draw(line); - public void onMouseWheelButtonPressed(BoardEdit source, MouseEvent event) - { - mPanCommand.onLeftMouseButtonPressed(source, event); - mIsPaning = true; - } + g2d.setTransform(savedTransform); - public void onMouseWheelButtonReleased(BoardEdit source, MouseEvent event) - { - mPanCommand.onLeftMouseButtonReleased(source, event); - mIsPaning = false; - } - - public boolean onKeyEvent(BoardEdit source, KeyEvent event) - { + // Draw cross section of brd + double crsScale = mScale * 2; + Stroke crsStroke = new BasicStroke((float) (1.3 / crsScale)); + double crsY = getHeight() / 6 + (-boardOffset.z + bottomY + brdX * Math.sin(boardAngle)) * crsScale; + BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g2d), getWidth() / 2, crsY, crsScale, 0.0, Color.RED, crsStroke, false, mShowDeck, brdX, brd); - if(event.getID() != KeyEvent.KEY_PRESSED) - return false; + // Draw cross section blank + double blankCrsY = getHeight() / 6 + (-blankOffset.z + blankBottomY + blankX * Math.sin(blankAngle)) * crsScale; + BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g2d), getWidth() / 2, blankCrsY, crsScale, 0.0, Color.BLUE, crsStroke, false, mShowDeck, blankX, blank); - int key = event.getKeyCode(); - -// System.out.printf("onKeyEvent mConfig:%s this:%s\n", mConfig.toString(), this.toString()); + } - if(key == KeyEvent.VK_LEFT) - { - if(!mShowDeck) - return false; - - Vector3d deckOffset = mConfig.getBlankHoldingSystem().getBoardDeckOffsetPos(); - double offsetX = (deckOffset.x-((event.isAltDown()?0.1:1.0f)/source.getScale())); - mConfig.getBlankHoldingSystem().setBoardDeckOffsetPos(new Vector3d(offsetX, 0.0, deckOffset.z)); - source.repaint(); - return true; - } - else if(key == KeyEvent.VK_RIGHT) - { - if(!mShowDeck) - return false; - - Vector3d deckOffset = mConfig.getBlankHoldingSystem().getBoardDeckOffsetPos(); - double offsetX = (deckOffset.x+((event.isAltDown()?0.1:1.0f)/source.getScale())); - mConfig.getBlankHoldingSystem().setBoardDeckOffsetPos(new Vector3d(offsetX, 0.0, deckOffset.z)); - source.repaint(); - return true; - } - else if(key == KeyEvent.VK_UP) - { - if(!mShowDeck) - return false; - - Vector3d deckOffset = mConfig.getBlankHoldingSystem().getBoardDeckOffsetPos(); - double offsetY = (deckOffset.z+((event.isAltDown()?0.1:1.0f)/source.getScale())); - mConfig.getBlankHoldingSystem().setBoardDeckOffsetPos(new Vector3d(deckOffset.x, 0.0, offsetY)); - source.repaint(); - return true; - } - else if(key == KeyEvent.VK_DOWN) - { - if(!mShowDeck) - return false; - - Vector3d deckOffset = mConfig.getBlankHoldingSystem().getBoardDeckOffsetPos(); - double offsetY = (deckOffset.z-((event.isAltDown()?0.1:1.0f)/source.getScale())); - mConfig.getBlankHoldingSystem().setBoardDeckOffsetPos(new Vector3d(deckOffset.x, 0.0, offsetY)); - source.repaint(); - return true; - } - if(key == KeyEvent.VK_Q) - { - if(!mShowDeck) - return false; - - double rot = mConfig.getBlankHoldingSystem().getBoardDeckOffsetAngle(); - rot = rot-(event.isAltDown()?0.0004:0.004f); - mConfig.getBlankHoldingSystem().setBoardDeckOffsetAngle(rot); - source.repaint(); - return true; - } - else if(key == KeyEvent.VK_W) - { - if(!mShowDeck) - return false; - - double rot = mConfig.getBlankHoldingSystem().getBoardDeckOffsetAngle(); - rot = rot+(event.isAltDown()?0.0004:0.004f); - mConfig.getBlankHoldingSystem().setBoardDeckOffsetAngle(rot); - source.repaint(); - return true; - } - else if(key == KeyEvent.VK_SPACE) - { - mShowDeck = !mShowDeck; - source.repaint(); - return true; - } - return false; - } + @Override + public void drawSlidingInfo(Graphics2D g, Color color, Stroke stroke, BezierBoard brd) { + // drawProfileSlidingInfo(this, g, color, stroke, brd); + } - public String getCommandString() - { - return "Position"; - } + @Override + public BrdCommand getCurrentCommand() { + return mBrdPosCommand; + } + void calcViewOffset() { + // mOffsetY = + // getCurrentMachineConfig().getDouble(MachineConfig.SUPPORT_1_HEIGHT)/UnitUtils.MILLIMETER_PR_CENTIMETER; } + } \ No newline at end of file diff --git a/boardcad/gui/jdk/Machine3DView.java b/boardcad/gui/jdk/Machine3DView.java index 3f018c2..b254099 100644 --- a/boardcad/gui/jdk/Machine3DView.java +++ b/boardcad/gui/jdk/Machine3DView.java @@ -6,51 +6,32 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import javax.media.j3d.AmbientLight; -import javax.media.j3d.Appearance; -import javax.media.j3d.Background; -import javax.media.j3d.BoundingSphere; -import javax.media.j3d.BranchGroup; -import javax.media.j3d.Canvas3D; -import javax.media.j3d.ColoringAttributes; -import javax.media.j3d.DirectionalLight; -import javax.media.j3d.GeometryArray; -import javax.media.j3d.Group; -import javax.media.j3d.LineArray; -import javax.media.j3d.LineStripArray; -import javax.media.j3d.Shape3D; -import javax.media.j3d.Switch; -import javax.media.j3d.Transform3D; -import javax.media.j3d.TransformGroup; -import javax.media.j3d.ViewPlatform; +import javax.media.j3d.*; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JComponent; import javax.swing.JPopupMenu; -import javax.vecmath.Color3f; -import javax.vecmath.Point3d; -import javax.vecmath.Vector3d; -import javax.vecmath.Vector3f; - -import cadcore.UnitUtils; +import javax.vecmath.*; import com.sun.j3d.utils.behaviors.vp.OrbitBehavior; -import com.sun.j3d.utils.universe.SimpleUniverse; -import com.sun.j3d.utils.universe.ViewingPlatform; -import boardcad.i18n.LanguageResource; +import com.sun.j3d.utils.universe.*; +import cadcore.UnitUtils; +import boardcad.i18n.LanguageResource; -public class Machine3DView extends JComponent{ - static final long serialVersionUID=1L; +public class Machine3DView extends JComponent { + static final long serialVersionUID = 1L; TransformGroup mScale; Transform3D mTransform; double mNormalsScale; - + Background mBackgroundNode; + DirectionalLight mHeadLight; + TransformGroup mToolpathsGroup; Transform3D mToolpathsTransform; - + Switch mDeckOrBottomToolpathSwitch; Group mDeckToolpathGroup; Group mBottomToolpathGroup; @@ -62,11 +43,11 @@ public class Machine3DView extends JComponent{ TransformGroup mModelTransformGroup; Transform3D mModelTransform; - + Switch mDeckOrBottomModelSwitch; Group mDeckModelGroup; Group mBottomModelGroup; - + Switch mDeckSurfacePathsSwitch; Switch mDeckNormalsSwitch; @@ -75,21 +56,21 @@ public class Machine3DView extends JComponent{ Shape3D mDeckSurfacePaths; Shape3D mDeckSurfaceNormals; - + Shape3D mBottomSurfacePaths; Shape3D mBottomSurfaceNormals; - + BranchGroup mBlankHoldingSystemModel; - + BranchGroup mCutter; TransformGroup mCutterTransformGroup; Transform3D mCutterTransform; + Vector3d mCutterPos; - LineStripArray mDeckSurfacePathsArray; LineArray mDeckNormalsArray; LineStripArray mDeckToolpathsArray; - + int mDeckCurrentSurfacePathIndex = 0; int mDeckCurrentNormalIndex = 0; int mDeckCurrentToolpathIndex = 0; @@ -97,81 +78,127 @@ public class Machine3DView extends JComponent{ LineStripArray mBottomSurfacePathsArray; LineArray mBottomNormalsArray; LineStripArray mBottomToolpathsArray; - + int mBottomCurrentSurfacePathIndex = 0; int mBottomCurrentNormalIndex = 0; int mBottomCurrentToolpathIndex = 0; + + Switch mBlankSwitch; + Shape3D mBlankModel; + TransformGroup mBlankTransformGroup; + Transform3D mBlankTransform; + Point3d mBlankDeckOffset; + double mBlankDeckRotation; + Point3d mBlankBottomOffset; + double mBlankBottomRotation; - public Machine3DView() - { + Switch mBrdSwitch; + Shape3D mBrdModel; + TransformGroup mBrdTransformGroup; + Transform3D mBrdTransform; + Point3d mBrdDeckOffset; + double mBrdDeckRotation; + Point3d mBrdBottomOffset; + double mBrdBottomRotation; + + public Machine3DView() { JPopupMenu.setDefaultLightWeightPopupEnabled(false); final JPopupMenu menu = new JPopupMenu(); final AbstractAction toggleDeckBottom = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("TOGGLEDECKBOTTOM_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { toggleDeckOrBottom(); } }; menu.add(toggleDeckBottom); - + menu.addSeparator(); final AbstractAction toggleSurfacePaths = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("TOGGLESURFACEPATHS_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { - mDeckSurfacePathsSwitch.setWhichChild((mDeckSurfacePathsSwitch.getWhichChild()==Switch.CHILD_ALL)?Switch.CHILD_NONE:Switch.CHILD_ALL); - mBottomSurfacePathsSwitch.setWhichChild((mBottomSurfacePathsSwitch.getWhichChild()==Switch.CHILD_ALL)?Switch.CHILD_NONE:Switch.CHILD_ALL); + mDeckSurfacePathsSwitch.setWhichChild((mDeckSurfacePathsSwitch.getWhichChild() == Switch.CHILD_ALL) ? Switch.CHILD_NONE : Switch.CHILD_ALL); + mBottomSurfacePathsSwitch.setWhichChild((mBottomSurfacePathsSwitch.getWhichChild() == Switch.CHILD_ALL) ? Switch.CHILD_NONE : Switch.CHILD_ALL); } }; menu.add(toggleSurfacePaths); final AbstractAction toggleNormals = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("TOGGLENORMALS_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { - mDeckNormalsSwitch.setWhichChild((mDeckNormalsSwitch.getWhichChild()==Switch.CHILD_ALL)?Switch.CHILD_NONE:Switch.CHILD_ALL); - mBottomSurfaceNormalsSwitch.setWhichChild((mBottomSurfaceNormalsSwitch.getWhichChild()==Switch.CHILD_ALL)?Switch.CHILD_NONE:Switch.CHILD_ALL); + mDeckNormalsSwitch.setWhichChild((mDeckNormalsSwitch.getWhichChild() == Switch.CHILD_ALL) ? Switch.CHILD_NONE : Switch.CHILD_ALL); + mBottomSurfaceNormalsSwitch.setWhichChild((mBottomSurfaceNormalsSwitch.getWhichChild() == Switch.CHILD_ALL) ? Switch.CHILD_NONE : Switch.CHILD_ALL); } }; menu.add(toggleNormals); final AbstractAction toggleToolpaths = new AbstractAction() { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; { this.putValue(Action.NAME, LanguageResource.getString("TOGGLETOOLPATHS_STR")); }; + @Override public void actionPerformed(ActionEvent arg0) { - mDeckToolpathsSwitch.setWhichChild((mDeckToolpathsSwitch.getWhichChild()==Switch.CHILD_ALL)?Switch.CHILD_NONE:Switch.CHILD_ALL); - mBottomToolpathsSwitch.setWhichChild((mBottomToolpathsSwitch.getWhichChild()==Switch.CHILD_ALL)?Switch.CHILD_NONE:Switch.CHILD_ALL); + mDeckToolpathsSwitch.setWhichChild((mDeckToolpathsSwitch.getWhichChild() == Switch.CHILD_ALL) ? Switch.CHILD_NONE : Switch.CHILD_ALL); + mBottomToolpathsSwitch.setWhichChild((mBottomToolpathsSwitch.getWhichChild() == Switch.CHILD_ALL) ? Switch.CHILD_NONE : Switch.CHILD_ALL); } }; menu.add(toggleToolpaths); - add(menu); - + add(menu); + + final AbstractAction toggleBlank = new AbstractAction() { + static final long serialVersionUID = 1L; + { + this.putValue(Action.NAME, LanguageResource.getString("TOGGLEBLANK_STR")); + }; + + @Override + public void actionPerformed(ActionEvent arg0) { + mBlankSwitch.setWhichChild((mBlankSwitch.getWhichChild() == Switch.CHILD_ALL) ? Switch.CHILD_NONE : Switch.CHILD_ALL); + } + }; + menu.add(toggleBlank); + + final AbstractAction toggleBrd = new AbstractAction() { + static final long serialVersionUID = 1L; + { + this.putValue(Action.NAME, LanguageResource.getString("TOGGLEBRD_STR")); + }; + + @Override + public void actionPerformed(ActionEvent arg0) { + mBrdSwitch.setWhichChild((mBrdSwitch.getWhichChild() == Switch.CHILD_ALL) ? Switch.CHILD_NONE : Switch.CHILD_ALL); + } + }; + menu.add(toggleBrd); + setLayout(new BorderLayout()); final Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add("Center", canvas); - canvas.addMouseListener(new MouseAdapter() - { - public void mouseClicked(MouseEvent e) - { - if(e.isMetaDown()) + canvas.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.isMetaDown()) menu.show(canvas, e.getX(), e.getY()); } @@ -194,23 +221,33 @@ public void mouseClicked(MouseEvent e) // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); - universe.addBranchGraph(scene); - + universe.addBranchGraph(scene); + canvas.getView().setFrontClipPolicy(javax.media.j3d.View.VIRTUAL_EYE); canvas.getView().setFrontClipDistance(0.01); + // Headlight + PlatformGeometry pg = new PlatformGeometry(); + + mHeadLight = new DirectionalLight(new Color3f(0.8f, 0.8f, 0.8f), + new Vector3f(0.0f, 0.0f, -1.0f)); + mHeadLight.setInfluencingBounds(bounds); + mHeadLight.setCapability(Light.ALLOW_STATE_WRITE); + mHeadLight.setEnable(true); + pg.addChild(mHeadLight); + viewingPlatform.setPlatformGeometry(pg); + } - + private void initialize() { - + } - private BranchGroup createSceneGraph() - { + private BranchGroup createSceneGraph() { BranchGroup branchRoot = new BranchGroup(); // Create a bounds for the background and lights - BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000.0); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0); // Set up the background Color3f bgColor = new Color3f(BoardCAD.getInstance().getBackgroundColor()); @@ -227,9 +264,9 @@ private BranchGroup createSceneGraph() // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); - Vector3f light1Direction = new Vector3f(0.0f, 1.0f, 0.0f); + Vector3f light1Direction = new Vector3f(0.0f, 1.0f, 0.0f); Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); - Vector3f light2Direction = new Vector3f(0.0f, -1.0f, 0.0f); + Vector3f light2Direction = new Vector3f(0.0f, -1.0f, 0.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); @@ -239,33 +276,32 @@ private BranchGroup createSceneGraph() light2.setInfluencingBounds(bounds); branchRoot.addChild(light2); - // Create an Appearance and set up the material properties Appearance surfacePathsApperance = new Appearance(); ColoringAttributes surfacePathsColor = new ColoringAttributes(); - surfacePathsColor.setColor (1.0f, 1.0f, 1.0f); + surfacePathsColor.setColor(1.0f, 1.0f, 1.0f); surfacePathsApperance.setColoringAttributes(surfacePathsColor); Appearance normalsApperance = new Appearance(); ColoringAttributes normalsColor = new ColoringAttributes(); - normalsColor.setColor (0.5f, 0.5f, 0.9f); + normalsColor.setColor(0.5f, 0.5f, 0.9f); normalsApperance.setColoringAttributes(normalsColor); - + Appearance toolpathsApperance = new Appearance(); ColoringAttributes toolpathsColor = new ColoringAttributes(); - toolpathsColor.setColor (0.1f, 0.1f, 0.3f); + toolpathsColor.setColor(0.1f, 0.1f, 0.3f); toolpathsApperance.setColoringAttributes(toolpathsColor); Appearance supportStructureApperance = new Appearance(); ColoringAttributes supportStructtureColor = new ColoringAttributes(); - supportStructtureColor.setColor (0.1f, 0.1f, 0.3f); + supportStructtureColor.setColor(0.1f, 0.1f, 0.3f); supportStructureApperance.setColoringAttributes(supportStructtureColor); Appearance cutterApperance = new Appearance(); ColoringAttributes cutterApperanceColor = new ColoringAttributes(); - cutterApperanceColor.setColor (0.1f, 0.1f, 0.3f); + cutterApperanceColor.setColor(0.1f, 0.1f, 0.3f); cutterApperance.setColoringAttributes(cutterApperanceColor); - + // Create a Transformgroup to scale all objects so they // appear in the scene. mScale = new TransformGroup(); @@ -277,7 +313,7 @@ private BranchGroup createSceneGraph() mScale.setTransform(mTransform); branchRoot.addChild(mScale); - //Toolpaths + // Toolpaths mToolpathsGroup = new TransformGroup(); mToolpathsGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); mToolpathsGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); @@ -287,24 +323,25 @@ private BranchGroup createSceneGraph() mToolpathsGroup.setTransform(mToolpathsTransform); mScale.addChild(mToolpathsGroup); - LineArray referencePointArray = new LineArray(6, LineArray.COORDINATES); + LineArray referencePointArray = new LineArray(6, LineArray.COORDINATES); referencePointArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); double size = 40.0; - referencePointArray.setCoordinates(mDeckCurrentNormalIndex, new Point3d[]{new Point3d(-size, 0.0, 0.0), new Point3d(size, 0.0, 0.0), new Point3d(0.0, -size, 0.0),new Point3d(0.0, size, 0.0),new Point3d(0.0, 0.0, -size),new Point3d(0.0, 0.0, size)}); + referencePointArray.setCoordinates(mDeckCurrentNormalIndex, new Point3d[] { new Point3d(-size, 0.0, 0.0), new Point3d(size, 0.0, 0.0), new Point3d(0.0, -size, 0.0), new Point3d(0.0, size, 0.0), new Point3d(0.0, 0.0, -size), new Point3d(0.0, 0.0, size) }); referencePointArray.setValidVertexCount(6); - + Appearance toolpathsReferencePointApperance = new Appearance(); ColoringAttributes toolpathsReferencePointColor = new ColoringAttributes(); - toolpathsReferencePointColor.setColor (0.0f, 1.0f, 0.0f); + toolpathsReferencePointColor.setColor(0.0f, 1.0f, 0.0f); toolpathsReferencePointApperance.setColoringAttributes(toolpathsReferencePointColor); - + Shape3D toolpathsReferencePoint = new Shape3D(); toolpathsReferencePoint.setGeometry(referencePointArray); toolpathsReferencePoint.setAppearance(normalsApperance); mToolpathsGroup.addChild(toolpathsReferencePoint); - - //Cutter + + // Cutter + mCutterPos = new Vector3d(0.0, 0.0, 0.0); mCutterTransformGroup = new TransformGroup(); mCutterTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); mCutterTransformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); @@ -313,7 +350,7 @@ private BranchGroup createSceneGraph() mCutterTransform.setIdentity(); mCutterTransformGroup.setTransform(mCutterTransform); mToolpathsGroup.addChild(mCutterTransformGroup); - + mDeckOrBottomToolpathSwitch = new Switch(); mDeckOrBottomToolpathSwitch.setCapability(Switch.ALLOW_SWITCH_READ); mDeckOrBottomToolpathSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); @@ -330,21 +367,21 @@ private BranchGroup createSceneGraph() mDeckToolpathsSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); mDeckToolpathsSwitch.setWhichChild(Switch.CHILD_ALL); mDeckToolpathGroup.addChild(mDeckToolpathsSwitch); - + mDeckToolpaths = new Shape3D(); mDeckToolpaths.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); -// mDeckToolpaths.setCapability(Shape3D.ALLOW_GEOMETRY_READ); + // mDeckToolpaths.setCapability(Shape3D.ALLOW_GEOMETRY_READ); mDeckToolpaths.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); -// mDeckToolpaths.setCapability(Shape3D.ALLOW_APPEARANCE_READ); + // mDeckToolpaths.setCapability(Shape3D.ALLOW_APPEARANCE_READ); - mDeckToolpathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[]{200000}); + mDeckToolpathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[] { 200000 }); mDeckToolpathsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); mDeckToolpaths.setGeometry(mDeckToolpathsArray); mDeckToolpaths.setAppearance(toolpathsApperance); mDeckToolpathsSwitch.addChild(mDeckToolpaths); - - mDeckToolpathsArray.setCoordinates(3, new double[]{-1,-1,-1,0,0,0,1,1,1}); - + + mDeckToolpathsArray.setCoordinates(3, new double[] { -1, -1, -1, 0, 0, 0, 1, 1, 1 }); + mBottomToolpathGroup = new Group(); mBottomToolpathGroup.setCapability(Switch.ALLOW_SWITCH_READ); mBottomToolpathGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); @@ -362,15 +399,15 @@ private BranchGroup createSceneGraph() mBottomToolpaths.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); mBottomToolpaths.setCapability(Shape3D.ALLOW_APPEARANCE_READ); - mBottomToolpathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[]{200000}); + mBottomToolpathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[] { 200000 }); mBottomToolpathsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); mBottomToolpaths.setGeometry(mBottomToolpathsArray); mBottomToolpaths.setAppearance(toolpathsApperance); mBottomToolpathsSwitch.addChild(mBottomToolpaths); - - mBottomToolpathsArray.setCoordinates(3, new double[]{-1,-1,-1,0,0,0,1,1,1}); - - //Model + + mBottomToolpathsArray.setCoordinates(3, new double[] { -1, -1, -1, 0, 0, 0, 1, 1, 1 }); + + // Model mModelTransformGroup = new TransformGroup(); mModelTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); mModelTransformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); @@ -382,9 +419,9 @@ private BranchGroup createSceneGraph() Appearance modelReferencePointApperance = new Appearance(); ColoringAttributes modelReferencePointColor = new ColoringAttributes(); - modelReferencePointColor.setColor (1.0f, 1.0f, 1.0f); + modelReferencePointColor.setColor(1.0f, 1.0f, 1.0f); modelReferencePointApperance.setColoringAttributes(modelReferencePointColor); - + Shape3D modelReferencePoint = new Shape3D(); modelReferencePoint.setGeometry(referencePointArray); modelReferencePoint.setAppearance(modelReferencePointApperance); @@ -400,20 +437,20 @@ private BranchGroup createSceneGraph() mDeckModelGroup.setCapability(Switch.ALLOW_SWITCH_READ); mDeckModelGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); mDeckOrBottomModelSwitch.addChild(mDeckModelGroup); - + mDeckSurfacePathsSwitch = new Switch(); -// mDeckSurfacePathsSwitch.setCapability(Switch.ALLOW_SWITCH_READ); + // mDeckSurfacePathsSwitch.setCapability(Switch.ALLOW_SWITCH_READ); mDeckSurfacePathsSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); mDeckSurfacePathsSwitch.setWhichChild(Switch.CHILD_ALL); mDeckModelGroup.addChild(mDeckSurfacePathsSwitch); - + mDeckSurfacePaths = new Shape3D(); mDeckSurfacePaths.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); -// mDeckSurfacePaths.setCapability(Shape3D.ALLOW_GEOMETRY_READ); + // mDeckSurfacePaths.setCapability(Shape3D.ALLOW_GEOMETRY_READ); mDeckSurfacePaths.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); -// mDeckSurfacePaths.setCapability(Shape3D.ALLOW_APPEARANCE_READ); + // mDeckSurfacePaths.setCapability(Shape3D.ALLOW_APPEARANCE_READ); - mDeckSurfacePathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[]{200000}); + mDeckSurfacePathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[] { 200000 }); mDeckSurfacePathsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); mDeckSurfacePaths.setGeometry(mDeckSurfacePathsArray); mDeckSurfacePaths.setAppearance(surfacePathsApperance); @@ -422,14 +459,14 @@ private BranchGroup createSceneGraph() mDeckNormalsSwitch = new Switch(); mDeckNormalsSwitch.setCapability(Switch.ALLOW_SWITCH_READ); mDeckNormalsSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); - mDeckNormalsSwitch.setWhichChild(Switch.CHILD_ALL); + mDeckNormalsSwitch.setWhichChild(Switch.CHILD_NONE); mDeckModelGroup.addChild(mDeckNormalsSwitch); mDeckSurfaceNormals = new Shape3D(); mDeckSurfaceNormals.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); -// mDeckNormals.setCapability(Shape3D.ALLOW_GEOMETRY_READ); + // mDeckNormals.setCapability(Shape3D.ALLOW_GEOMETRY_READ); mDeckSurfaceNormals.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); -// mDeckNormals.setCapability(Shape3D.ALLOW_APPEARANCE_READ); + // mDeckNormals.setCapability(Shape3D.ALLOW_APPEARANCE_READ); mDeckNormalsArray = new LineArray(200000, LineArray.COORDINATES); mDeckNormalsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); @@ -450,11 +487,11 @@ private BranchGroup createSceneGraph() mBottomSurfacePaths = new Shape3D(); mBottomSurfacePaths.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); -// mBottomSurfacePaths.setCapability(Shape3D.ALLOW_GEOMETRY_READ); + // mBottomSurfacePaths.setCapability(Shape3D.ALLOW_GEOMETRY_READ); mBottomSurfacePaths.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); -// mBottomSurfacePaths.setCapability(Shape3D.ALLOW_APPEARANCE_READ); + // mBottomSurfacePaths.setCapability(Shape3D.ALLOW_APPEARANCE_READ); - mBottomSurfacePathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[]{200000}); + mBottomSurfacePathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[] { 200000 }); mBottomSurfacePathsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); mBottomSurfacePaths.setGeometry(mBottomSurfacePathsArray); mBottomSurfacePaths.setAppearance(surfacePathsApperance); @@ -468,9 +505,9 @@ private BranchGroup createSceneGraph() mBottomSurfaceNormals = new Shape3D(); mBottomSurfaceNormals.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); -// mBottomNormals.setCapability(Shape3D.ALLOW_GEOMETRY_READ); + // mBottomNormals.setCapability(Shape3D.ALLOW_GEOMETRY_READ); mBottomSurfaceNormals.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); -// mBottomNormals.setCapability(Shape3D.ALLOW_APPEARANCE_READ); + // mBottomNormals.setCapability(Shape3D.ALLOW_APPEARANCE_READ); mBottomNormalsArray = new LineArray(200000, LineArray.COORDINATES); mBottomNormalsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); @@ -478,245 +515,406 @@ private BranchGroup createSceneGraph() mBottomSurfaceNormals.setAppearance(normalsApperance); mBottomSurfaceNormalsSwitch.addChild(mBottomSurfaceNormals); -//DEBUG -// mDeckGroup.addChild(new com.sun.j3d.utils.geometry.Box(100.0f,100.0f, 100.0f, new Appearance())); -// mBottomGroup.addChild(new com.sun.j3d.utils.geometry.Box()); + // Blank + mBlankSwitch = new Switch(); + mBlankSwitch.setCapability(Switch.ALLOW_SWITCH_READ); + mBlankSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); + mBlankSwitch.setWhichChild(Switch.CHILD_ALL); + mScale.addChild(mBlankSwitch); + + mBlankTransformGroup = new TransformGroup(); + mBlankTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + mBlankTransformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); + mBlankTransformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE); + mBlankTransform = new Transform3D(); + mBlankTransform.setIdentity(); + mBlankTransform.setScale(10); + mBlankTransformGroup.setTransform(mBlankTransform); + mBlankSwitch.addChild(mBlankTransformGroup); + + mBlankModel = new Shape3D(); + mBlankModel.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); + mBlankModel.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); + + // Create an Appearance. + Appearance blankApperance = new Appearance(); + Color3f ambient = new Color3f(0.4f, 0.4f, 0.4f); + Color3f emissive = new Color3f(0.0f, 0.0f, 0.0f); + Color3f diffuse = new Color3f(0.8f, 0.8f, 0.8f); + Color3f specular = new Color3f(1.0f, 1.0f, 1.0f); + TransparencyAttributes blankTransparencyAttributes = new TransparencyAttributes(); + blankTransparencyAttributes.setTransparencyMode(TransparencyAttributes.NICEST); + blankTransparencyAttributes.setTransparency(0.5f); + + // Set up the material properties + blankApperance.setMaterial(new Material(ambient, emissive, diffuse, specular, 115.0f)); + blankApperance.setTransparencyAttributes(blankTransparencyAttributes); + + mBlankModel.setAppearance(blankApperance); + mBlankTransformGroup.addChild(mBlankModel); + + // Brd + mBrdSwitch = new Switch(); + mBrdSwitch.setCapability(Switch.ALLOW_SWITCH_READ); + mBrdSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); + mBrdSwitch.setWhichChild(Switch.CHILD_ALL); + mScale.addChild(mBrdSwitch); + + mBrdTransformGroup = new TransformGroup(); + mBrdTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + mBrdTransformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); + mBrdTransformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE); + mBrdTransform = new Transform3D(); + mBrdTransform.setIdentity(); + mBrdTransform.setScale(10); + mBrdTransformGroup.setTransform(mBrdTransform); + mBrdSwitch.addChild(mBrdTransformGroup); + + mBrdModel = new Shape3D(); + mBrdModel.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); + mBrdModel.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); + + // Create an Appearance. + Appearance brdApperance = new Appearance(); + Color3f brdAmbient = new Color3f(0.4f, 0.4f, 0.4f); + Color3f brdEmissive = new Color3f(0.0f, 0.0f, 0.0f); + Color3f brdDiffuse = new Color3f(0.8f, 0.8f, 0.8f); + Color3f brdSpecular = new Color3f(1.0f, 1.0f, 1.0f); + TransparencyAttributes brdTransparencyAttributes = new TransparencyAttributes(); + brdTransparencyAttributes.setTransparencyMode(TransparencyAttributes.NICEST); + brdTransparencyAttributes.setTransparency(0.5f); + + // Set up the material properties + brdApperance.setMaterial(new Material(brdAmbient, brdEmissive, brdDiffuse, brdSpecular, 115.0f)); + brdApperance.setTransparencyAttributes(brdTransparencyAttributes); + mBrdModel.setAppearance(brdApperance); + mBrdTransformGroup.addChild(mBrdModel); + + + // DEBUG + // mDeckGroup.addChild(new com.sun.j3d.utils.geometry.Box(100.0f,100.0f, + // 100.0f, new Appearance())); + // mBottomGroup.addChild(new com.sun.j3d.utils.geometry.Box()); + // Have Java 3D perform optimizations on this scene graph. -// branchRoot.compile(); CANNOT ADD AND REMOVE NODES THEN + // branchRoot.compile(); CANNOT ADD AND REMOVE NODES THEN return branchRoot; } - - public void reset() - { + + public void reset() { mDeckCurrentSurfacePathIndex = 0; mDeckCurrentNormalIndex = 0; - mDeckCurrentToolpathIndex = 0; + mDeckCurrentToolpathIndex = 0; - //TODO: Test refactor to only reset linestrips by setting count to zero - mDeckSurfacePathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[]{200000}); + // TODO: Test refactor to only reset linestrips by setting count to zero + mDeckSurfacePathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[] { 200000 }); mDeckSurfacePathsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); - mDeckSurfacePathsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); + mDeckSurfacePathsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); mDeckSurfacePaths.setGeometry(mDeckSurfacePathsArray); mDeckNormalsArray = new LineArray(200000, LineArray.COORDINATES); mDeckNormalsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); - mDeckNormalsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); + mDeckNormalsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); mDeckSurfaceNormals.setGeometry(mDeckNormalsArray); - - mDeckToolpathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[]{200000}); + + mDeckToolpathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[] { 200000 }); mDeckToolpathsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); - mDeckToolpathsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); + mDeckToolpathsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); mDeckToolpaths.setGeometry(mDeckToolpathsArray); mBottomCurrentSurfacePathIndex = 0; mBottomCurrentNormalIndex = 0; - mBottomCurrentToolpathIndex = 0; + mBottomCurrentToolpathIndex = 0; - mBottomSurfacePathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[]{200000}); + mBottomSurfacePathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[] { 200000 }); mBottomSurfacePathsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); - mBottomSurfacePathsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); + mBottomSurfacePathsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); mBottomSurfacePaths.setGeometry(mBottomSurfacePathsArray); mBottomNormalsArray = new LineArray(200000, LineArray.COORDINATES); mBottomNormalsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); - mBottomNormalsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); + mBottomNormalsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); mBottomSurfaceNormals.setGeometry(mBottomNormalsArray); - - mBottomToolpathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[]{200000}); + + mBottomToolpathsArray = new LineStripArray(200000, LineStripArray.COORDINATES, new int[] { 200000 }); mBottomToolpathsArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); - mBottomToolpathsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); + mBottomToolpathsArray.setCapability(GeometryArray.ALLOW_COUNT_WRITE); mBottomToolpaths.setGeometry(mBottomToolpathsArray); } - - void setOffset(double offset) - { + + void setOffset(double offset) { double scale = 0.0005; - // Vector3d deckOffset = BoardCAD.getInstance().getMachineView().getBoardDeckOffsetPos(); + // Vector3d deckOffset = + // BoardCAD.getInstance().getMachineView().getBoardDeckOffsetPos(); Vector3d deckTranslation = new Vector3d(); - // deckTranslation.sub(deckOffset); + // deckTranslation.sub(deckOffset); String generalStr = LanguageResource.getString("GENERALCATEGORY_STR"); -// deckTranslation.x -= (BoardCAD.getInstance().getCurrentBrd().getLength() + (.getCategory(generalStr).getDouble(MachineConfig.TAILSTOP_POS)/UnitUtils.MILLIMETER_PR_CENTIMETER))/2.0; - deckTranslation.scale(scale*10); //Since the board coordinates are in cm, scaled to millimeters used by g-code + // deckTranslation.x -= + // (BoardCAD.getInstance().getCurrentBrd().getLength() + + // (.getCategory(generalStr).getDouble(MachineConfig.TAILSTOP_POS)/UnitUtils.MILLIMETER_PR_CENTIMETER))/2.0; + deckTranslation.scale(scale * 10); // Since the board coordinates are in + // cm, scaled to millimeters used by + // g-code mTransform.set(scale, deckTranslation); mScale.setTransform(mTransform); } - - public void setBackgroundColor(Color color) - { + + public void setBackgroundColor(Color color) { float[] components = color.getRGBComponents(null); mBackgroundNode.setColor(new Color3f(components[0], components[1], components[2])); } - public void setDeckSurfaceStart(Point3d point) - { - mDeckCurrentSurfacePathIndex=0; - mDeckSurfacePathsArray.setCoordinates(mDeckCurrentSurfacePathIndex++, new Point3d[]{point}); + public void setDeckSurfaceStart(Point3d point) { + mDeckCurrentSurfacePathIndex = 0; + mDeckSurfacePathsArray.setCoordinates(mDeckCurrentSurfacePathIndex++, new Point3d[] { point }); } - public void addDeckSurfaceLine(Point3d point) - { - mDeckSurfacePathsArray.setCoordinates(mDeckCurrentSurfacePathIndex++, new Point3d[]{point}); - mDeckSurfacePathsArray.setStripVertexCounts(new int[]{(mDeckCurrentSurfacePathIndex>2)?mDeckCurrentSurfacePathIndex:2}); + public void addDeckSurfaceLine(Point3d point) { + mDeckSurfacePathsArray.setCoordinates(mDeckCurrentSurfacePathIndex++, new Point3d[] { point }); + mDeckSurfacePathsArray.setStripVertexCounts(new int[] { (mDeckCurrentSurfacePathIndex > 2) ? mDeckCurrentSurfacePathIndex : 2 }); } - public void addDeckNormal(Point3d location, Vector3d normal) - { + public void addDeckNormal(Point3d location, Vector3d normal) { final Point3d normalCopy = new Point3d(normal); final Point3d tmp = new Point3d(location); normalCopy.scale(40.0); tmp.add(normalCopy); - mDeckNormalsArray.setCoordinates(mDeckCurrentNormalIndex, new Point3d[]{location,tmp}); + mDeckNormalsArray.setCoordinates(mDeckCurrentNormalIndex, new Point3d[] { location, tmp }); mDeckCurrentNormalIndex += 2; mDeckNormalsArray.setValidVertexCount(mDeckCurrentNormalIndex); } - public void setDeckToolpathStart(Point3d point) - { + public void setDeckToolpathStart(Point3d point) { mDeckCurrentToolpathIndex = 0; - mDeckToolpathsArray.setCoordinates(mDeckCurrentToolpathIndex++, new Point3d[]{point}); + mDeckToolpathsArray.setCoordinates(mDeckCurrentToolpathIndex++, new Point3d[] { point }); mCutterTransform.setIdentity(); mCutterTransform.setTranslation(new Vector3d(point)); mCutterTransformGroup.setTransform(mCutterTransform); } - public void addDeckToolpathLine(Point3d point) - { - mDeckToolpathsArray.setCoordinates(mDeckCurrentToolpathIndex++, new Point3d[]{point}); - mDeckToolpathsArray.setStripVertexCounts(new int[]{(mDeckCurrentToolpathIndex>2)?mDeckCurrentToolpathIndex:2}); - - mCutterTransform.setIdentity(); - mCutterTransform.setTranslation(new Vector3d(point)); - mCutterTransformGroup.setTransform(mCutterTransform); + public void addDeckToolpathLine(Point3d point) { + mDeckToolpathsArray.setCoordinates(mDeckCurrentToolpathIndex++, new Point3d[] { point }); + mDeckToolpathsArray.setStripVertexCounts(new int[] { (mDeckCurrentToolpathIndex > 2) ? mDeckCurrentToolpathIndex : 2 }); + + if (isDeckActive()) { + updateCutterPos(point); + } } - public void setBottomSurfaceStart(Point3d point) - { - mBottomCurrentSurfacePathIndex=0; - mBottomSurfacePathsArray.setCoordinates(mDeckCurrentSurfacePathIndex++, new Point3d[]{point}); + public void setBottomSurfaceStart(Point3d point) { + mBottomCurrentSurfacePathIndex = 0; + mBottomSurfacePathsArray.setCoordinates(mDeckCurrentSurfacePathIndex++, new Point3d[] { point }); } - public void addBottomSurfaceLine(Point3d point) - { - mBottomSurfacePathsArray.setCoordinates(mBottomCurrentSurfacePathIndex++, new Point3d[]{point}); - mBottomSurfacePathsArray.setStripVertexCounts(new int[]{(mBottomCurrentSurfacePathIndex>2)?mBottomCurrentSurfacePathIndex:2}); + public void addBottomSurfaceLine(Point3d point) { + mBottomSurfacePathsArray.setCoordinates(mBottomCurrentSurfacePathIndex++, new Point3d[] { point }); + mBottomSurfacePathsArray.setStripVertexCounts(new int[] { (mBottomCurrentSurfacePathIndex > 2) ? mBottomCurrentSurfacePathIndex : 2 }); } - public void addBottomNormal(Point3d location, Vector3d normal) - { + public void addBottomNormal(Point3d location, Vector3d normal) { final Point3d normalCopy = new Point3d(normal); final Point3d tmp = new Point3d(location); normalCopy.scale(40.0); tmp.add(normalCopy); - mBottomNormalsArray.setCoordinates(mBottomCurrentNormalIndex, new Point3d[]{location,tmp}); + mBottomNormalsArray.setCoordinates(mBottomCurrentNormalIndex, new Point3d[] { location, tmp }); mBottomCurrentNormalIndex += 2; mBottomNormalsArray.setValidVertexCount(mBottomCurrentNormalIndex); } - public void setBottomToolpathStart(Point3d point) - { + public void setBottomToolpathStart(Point3d point) { mBottomCurrentToolpathIndex = 0; - mBottomToolpathsArray.setCoordinates(mBottomCurrentToolpathIndex++, new Point3d[]{point}); + mBottomToolpathsArray.setCoordinates(mBottomCurrentToolpathIndex++, new Point3d[] { point }); - mCutterTransform.setTranslation(new Vector3d(point)); - mCutterTransformGroup.setTransform(mCutterTransform); } - public void addBottomToolpathLine(Point3d point) - { - mBottomToolpathsArray.setCoordinates(mBottomCurrentToolpathIndex++, new Point3d[]{point}); - mBottomToolpathsArray.setStripVertexCounts(new int[]{(mBottomCurrentToolpathIndex>2)?mBottomCurrentToolpathIndex:2}); + public void addBottomToolpathLine(Point3d point) { + mBottomToolpathsArray.setCoordinates(mBottomCurrentToolpathIndex++, new Point3d[] { point }); + mBottomToolpathsArray.setStripVertexCounts(new int[] { (mBottomCurrentToolpathIndex > 2) ? mBottomCurrentToolpathIndex : 2 }); - mCutterTransform.setTranslation(new Vector3d(point)); + if (isBottomActive()) { + updateCutterPos(point); + } + } + + public void updateCutterPos(Point3d point) { + // mCutterTransform.setIdentity(); + mCutterPos.x = point.x; + mCutterPos.y = point.y; + mCutterPos.z = point.z; + mCutterTransform.setTranslation(mCutterPos); mCutterTransformGroup.setTransform(mCutterTransform); } - public void toggleDeckOrBottom(){ - mDeckOrBottomToolpathSwitch.setWhichChild((mDeckOrBottomToolpathSwitch.getWhichChild()==0)?1:0); - mDeckOrBottomModelSwitch.setWhichChild((mDeckOrBottomModelSwitch.getWhichChild()==0)?1:0); + public void toggleDeckOrBottom() { + mDeckOrBottomToolpathSwitch.setWhichChild((mDeckOrBottomToolpathSwitch.getWhichChild() == 0) ? 1 : 0); + mDeckOrBottomModelSwitch.setWhichChild((mDeckOrBottomModelSwitch.getWhichChild() == 0) ? 1 : 0); + + if (isDeckActive()) { + setBlankOffset(mBlankDeckOffset, mBlankDeckRotation, false); + setBrdOffset(mBrdDeckOffset, mBrdDeckRotation, false); + } else { + setBlankOffset(mBlankBottomOffset, mBlankBottomRotation, true); + setBrdOffset(mBrdBottomOffset, mBrdBottomRotation, true); + } } - public void setDeckActive(){ + public void setDeckActive() { mDeckOrBottomToolpathSwitch.setWhichChild(0); mDeckOrBottomModelSwitch.setWhichChild(0); } - public void setBottomActive(){ + public boolean isDeckActive() { + return mDeckOrBottomToolpathSwitch.getWhichChild() == 0; + } + + public void setBottomActive() { mDeckOrBottomToolpathSwitch.setWhichChild(1); mDeckOrBottomModelSwitch.setWhichChild(1); } - public void setCutterModel(BranchGroup model){ - try{ - if(mCutter != null) - { + public boolean isBottomActive() { + return !isDeckActive(); + } + + public void setCutterModel(BranchGroup model) { + try { + if (mCutter != null) { mCutterTransformGroup.removeChild(mCutter); } mCutter = model; - if(model != null) - { + if (model != null) { mCutterTransformGroup.addChild(mCutter); } - } - catch(Exception e) - { + } catch (Exception e) { System.out.println("Exception in Machine3Dview::setCutterModel(): " + e.toString()); } -// System.out.println("setCutterModel()\n"); + // System.out.println("setCutterModel()\n"); } - public void setBlankHoldingSystemModel(BranchGroup model){ - try{ - if(mBlankHoldingSystemModel != null) - { - mModelTransformGroup.removeChild(mBlankHoldingSystemModel); //remove old + public void setBlankHoldingSystemModel(BranchGroup model) { + try { + if (mBlankHoldingSystemModel != null) { + mModelTransformGroup.removeChild(mBlankHoldingSystemModel); // remove + // old } mBlankHoldingSystemModel = model; - if(model != null) - { + if (model != null) { mModelTransformGroup.addChild(mBlankHoldingSystemModel); } - }catch(Exception e) - { + } catch (Exception e) { System.out.println("Exception in Machine3DView::setBlankHoldingSystemModel(): " + e.toString()); } -// System.out.println("setBlankHoldingSystemModel()\n"); - + // System.out.println("setBlankHoldingSystemModel()\n"); + } - - public void fit_all() - { - + + public void fit_all() { + } - public void setCutterpos(Point3d pos){ + public void setCutterPos(Point3d pos) { mCutterTransform.setTranslation(new Vector3d(pos)); mCutterTransformGroup.setTransform(mCutterTransform); } - public void setCutterOffset(Point3d pos){ - mToolpathsTransform.setTranslation(new Vector3d(pos.x*UnitUtils.MILLIMETER_PR_CENTIMETER, pos.y*UnitUtils.MILLIMETER_PR_CENTIMETER, pos.z*UnitUtils.MILLIMETER_PR_CENTIMETER)); + public void setCutterOffset(Point3d pos) { + mToolpathsTransform.setTranslation(new Vector3d(pos.x * UnitUtils.MILLIMETER_PR_CENTIMETER, pos.y * UnitUtils.MILLIMETER_PR_CENTIMETER, pos.z * UnitUtils.MILLIMETER_PR_CENTIMETER)); mToolpathsGroup.setTransform(mToolpathsTransform); } - - public void update() - { + + public void update() { reset(); } - public void addCutterModel(Shape3D cutterModel) - { + public void addCutterModel(Shape3D cutterModel) { mScale.addChild(cutterModel); } - - public void setModelRotation(double angle) - { + + public void setModelRotation(double angle) { mModelTransform.setIdentity(); mModelTransform.rotX(angle); mModelTransformGroup.setTransform(mModelTransform); } -} + public void setBlankDeckOffset(Point3d pos, double angle) { + System.out.printf("setBlankDeckOffset"); + mBlankDeckOffset = pos; + mBlankDeckRotation = angle; + + if (isDeckActive()) { + setBlankOffset(mBlankDeckOffset, mBlankDeckRotation, false); + } + } + + public void setBlankBottomOffset(Point3d pos, double angle) { + System.out.printf("setBlankDeckOffset"); + mBlankBottomOffset = pos; + mBlankBottomRotation = angle; + + if (isBottomActive()) { + setBlankOffset(mBlankBottomOffset, mBlankBottomRotation, true); + } + } + + private void setBlankOffset(Point3d pos, double angle, boolean flip) { + System.out.printf("setBlankOffset angle:%f", angle); + mBlankTransform.rotY(angle); + if(flip){ + Transform3D flipRot = new Transform3D(); + flipRot.rotX(Math.PI); + mBlankTransform.mul(flipRot); + } + Vector3d vec = new Vector3d(pos); + vec.scale(10); + mBlankTransform.setTranslation(vec); + mBlankTransform.setScale(10); + mBlankTransformGroup.setTransform(mBlankTransform); + } + + public void setBrdDeckOffset(Point3d pos, double angle) { + System.out.printf("setBrdDeckOffset"); + mBrdDeckOffset = pos; + mBrdDeckRotation = angle; + + if (isDeckActive()) { + setBrdOffset(mBrdDeckOffset, mBrdDeckRotation, false); + } + } + + public void setBrdBottomOffset(Point3d pos, double angle) { + System.out.printf("setBrdDeckOffset"); + mBrdBottomOffset = pos; + mBrdBottomRotation = angle; + + if (isBottomActive()) { + setBrdOffset(mBrdBottomOffset, mBrdBottomRotation, true); + } + } + + private void setBrdOffset(Point3d pos, double angle, boolean flip) { + System.out.printf("setBrdOffset angle:%f", angle); + mBrdTransform.rotY(angle); + if(flip){ + Transform3D flipRot = new Transform3D(); + flipRot.rotX(Math.PI); + mBrdTransform.mul(flipRot); + } + Vector3d vec = new Vector3d(pos); + vec.scale(10); + mBrdTransform.setTranslation(vec); + mBrdTransform.setScale(10); + mBrdTransformGroup.setTransform(mBrdTransform); + } + + public Shape3D getBlankModel() { + return mBlankModel; + } + + public Shape3D getBrdModel() { + return mBrdModel; + } +} diff --git a/boardcad/gui/jdk/MachineDialog.java b/boardcad/gui/jdk/MachineDialog.java index 7765e06..6a79388 100644 --- a/boardcad/gui/jdk/MachineDialog.java +++ b/boardcad/gui/jdk/MachineDialog.java @@ -14,13 +14,13 @@ import javax.swing.BoxLayout; import javax.swing.ImageIcon; import javax.swing.JButton; -import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import boardcad.FileTools; +import boardcad.commands.BrdInputCommand; import boardcad.i18n.LanguageResource; import boardcam.MachineConfig; @@ -67,7 +67,7 @@ private void initialize() { // CNC JDialog Icon try { ImageIcon icon = new ImageIcon(getClass().getResource( - "icons/mill png 16x16.png")); + "../../icons/mill png 16x16.png")); super.setIconImage(icon.getImage()); } catch (Exception e) { @@ -80,6 +80,7 @@ private void initialize() { .setText(LanguageResource.getString("GENERATEBUTTON_STR")); generateButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { final JFileChooser fc = new JFileChooser(); @@ -142,6 +143,7 @@ public MachineView getMachineView() { return mMachineView; } + @Override public boolean dispatchKeyEvent(KeyEvent event) { if(getFocusOwner() != null) { diff --git a/boardcad/gui/jdk/MachineView.java b/boardcad/gui/jdk/MachineView.java index 8918309..c8d3496 100644 --- a/boardcad/gui/jdk/MachineView.java +++ b/boardcad/gui/jdk/MachineView.java @@ -78,6 +78,7 @@ public void init() add(splitPane,BorderLayout.CENTER); } + @Override public void fit_all() { mMachine2DView.fit_all(); diff --git a/boardcad/gui/jdk/QuadView.java b/boardcad/gui/jdk/QuadView.java new file mode 100644 index 0000000..ddf9006 --- /dev/null +++ b/boardcad/gui/jdk/QuadView.java @@ -0,0 +1,40 @@ +package boardcad.gui.jdk; + +import java.awt.GridLayout; + +import javax.swing.JPanel; + +class QuadView extends JPanel implements BrdEditParentContainer +{ + static final long serialVersionUID=1L; + BoardEdit mActive = null; + + QuadView() + { + this.setLayout(new GridLayout(2,2,3,3)); + } + + @Override + public void setActive(BoardEdit edit) + { + mActive = edit; + this.repaint(); + BoardCAD.getInstance().getGuidePointsDialog().update(); + } + + @Override + public boolean isActive(BoardEdit edit) + { + return (edit == mActive); + } + + @Override + public BoardEdit getActive() + { + if(mActive == null) + return (BoardEdit)getComponent(0); + + return mActive; + } + +} \ No newline at end of file diff --git a/boardcad/gui/jdk/ScaleBoardInputDialog.java b/boardcad/gui/jdk/ScaleBoardInputDialog.java index d7388f6..5c007a5 100644 --- a/boardcad/gui/jdk/ScaleBoardInputDialog.java +++ b/boardcad/gui/jdk/ScaleBoardInputDialog.java @@ -125,6 +125,7 @@ private JPanel getmContentPane () { mContentPane.add(myTabbedPane, BorderLayout.CENTER); ChangeListener changeListener = new ChangeListener() { + @Override public void stateChanged(ChangeEvent changeEvent) { JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource(); if(sourceTabbedPane.getSelectedIndex()==0) @@ -177,6 +178,7 @@ private JRadioButton getOverCurveRadioButton() { OverCurveRadioButton.setBounds(new Rectangle(41, 68, 145, 20)); OverCurveRadioButton.setText(LanguageResource.getString("OVERCURVERADIOBUTTON_STR") ); OverCurveRadioButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { OverCurveRadioButton.setSelected(true); setVisible(true); @@ -193,6 +195,7 @@ private JRadioButton getStraightLineRadioButton() { StraightLineRadioButton.setBounds(new Rectangle(41, 86, 145, 20)); StraightLineRadioButton.setText(LanguageResource.getString("STRAIGHTLINERADIOBUTTON_STR") ); StraightLineRadioButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { StraightLineRadioButton.setSelected(true); setVisible(true); @@ -222,6 +225,7 @@ private JCheckBox getScaleFinsCheckBox() { ScaleFinsCheckBox.setToolTipText(LanguageResource.getString("SCALEFINSMSGDETAILED")); ScaleFinsCheckBox.setSelected(true); ScaleFinsCheckBox.addItemListener(new java.awt.event.ItemListener() { + @Override public void itemStateChanged(java.awt.event.ItemEvent e) { //setVisible(false); //mWasCancelled = false; @@ -250,6 +254,7 @@ private JCheckBox getScaleFinsCheckBoxFactor() { ScaleFinsCheckBoxFactor.setToolTipText(LanguageResource.getString("SCALEFINSMSGDETAILED")); ScaleFinsCheckBoxFactor.setSelected(true); ScaleFinsCheckBoxFactor.addItemListener(new java.awt.event.ItemListener() { + @Override public void itemStateChanged(java.awt.event.ItemEvent e) { //setVisible(false); //mWasCancelled = false; @@ -272,6 +277,7 @@ private JButton getOkButton() { OkButton.setBounds(new Rectangle(95, 167, 110, 25)); OkButton.setText(LanguageResource.getString("OKBUTTON_STR")); OkButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { setVisible(false); mWasCancelled = false; @@ -292,6 +298,7 @@ private JButton getCancelButton() { CancelButton.setBounds(new Rectangle(216, 370, 110, 25)); CancelButton.setText(LanguageResource.getString("CANCELBUTTON_STR")); CancelButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { setVisible(false); } @@ -310,7 +317,8 @@ private JTextField getLengthTextField() { LengthTextField = new JTextField(); LengthTextField.setBounds(new Rectangle(149, 120, 80, 20)); LengthTextField.addFocusListener(new java.awt.event.FocusListener() { - public void focusLost(java.awt.event.FocusEvent e) { + @Override + public void focusLost(java.awt.event.FocusEvent e) { if(ConstraintProportionsCheckBox.isSelected()) { double new_length=UnitUtils.convertInputStringToInternalLengthUnit(LengthTextField.getText()); @@ -319,7 +327,8 @@ public void focusLost(java.awt.event.FocusEvent e) { mContentPane.repaint(); } } - public void focusGained(java.awt.event.FocusEvent e) { + @Override + public void focusGained(java.awt.event.FocusEvent e) { original_length=UnitUtils.convertInputStringToInternalLengthUnit(LengthTextField.getText()); original_width=UnitUtils.convertInputStringToInternalLengthUnit(WidthTextField.getText()); original_thickness=UnitUtils.convertInputStringToInternalLengthUnit(ThickTextField.getText()); @@ -339,7 +348,8 @@ private JTextField getWidthTextField() { WidthTextField = new JTextField(); WidthTextField.setBounds(new Rectangle(149, 150, 80, 20)); WidthTextField.addFocusListener(new java.awt.event.FocusListener() { - public void focusLost(java.awt.event.FocusEvent e) { + @Override + public void focusLost(java.awt.event.FocusEvent e) { if(ConstraintProportionsCheckBox.isSelected()) { @@ -349,7 +359,8 @@ public void focusLost(java.awt.event.FocusEvent e) { mContentPane.repaint(); } } - public void focusGained(java.awt.event.FocusEvent e) { + @Override + public void focusGained(java.awt.event.FocusEvent e) { original_length=UnitUtils.convertInputStringToInternalLengthUnit(LengthTextField.getText()); original_width=UnitUtils.convertInputStringToInternalLengthUnit(WidthTextField.getText()); original_thickness=UnitUtils.convertInputStringToInternalLengthUnit(ThickTextField.getText()); @@ -369,7 +380,8 @@ private JTextField getThickTextField() { ThickTextField = new JTextField(); ThickTextField.setBounds(new Rectangle(149, 180, 80, 20)); ThickTextField.addFocusListener(new java.awt.event.FocusListener() { - public void focusLost(java.awt.event.FocusEvent e) { + @Override + public void focusLost(java.awt.event.FocusEvent e) { if(ConstraintProportionsCheckBox.isSelected()) { double new_thickness=UnitUtils.convertInputStringToInternalLengthUnit(ThickTextField.getText()); @@ -378,7 +390,8 @@ public void focusLost(java.awt.event.FocusEvent e) { mContentPane.repaint(); } } - public void focusGained(java.awt.event.FocusEvent e) { + @Override + public void focusGained(java.awt.event.FocusEvent e) { original_length=UnitUtils.convertInputStringToInternalLengthUnit(LengthTextField.getText()); original_width=UnitUtils.convertInputStringToInternalLengthUnit(WidthTextField.getText()); original_thickness=UnitUtils.convertInputStringToInternalLengthUnit(ThickTextField.getText()); @@ -401,67 +414,67 @@ private JTextField getFactorTextField() { return FactorTextField; } - void setBoardLength(double length) + public void setBoardLength(double length) { LengthTextField.setText(UnitUtils.convertLengthToCurrentUnit(length, true)); } - void setBoardWidth(double width) + public void setBoardWidth(double width) { WidthTextField.setText(UnitUtils.convertLengthToCurrentUnit(width, true)); } - void setBoardThick(double thick) + public void setBoardThick(double thick) { ThickTextField.setText(UnitUtils.convertLengthToCurrentUnit(thick, true)); } - double getBoardLength() + public double getBoardLength() { return UnitUtils.convertInputStringToInternalLengthUnit(LengthTextField.getText()); } - double getBoardWidth() + public double getBoardWidth() { return UnitUtils.convertInputStringToInternalLengthUnit(WidthTextField.getText()); } - double getBoardThick() + public double getBoardThick() { return UnitUtils.convertInputStringToInternalLengthUnit(ThickTextField.getText()); } - double getFactor() + public double getFactor() { return Double.parseDouble(FactorTextField.getText()); } - boolean useOverCurve() + public boolean useOverCurve() { return OverCurveRadioButton.isSelected(); } - boolean scaleFins() + public boolean scaleFins() { return ScaleFinsCheckBox.isSelected(); } - boolean scaleBottomRocker() + public boolean scaleBottomRocker() { return ScaleBottomRockerCheckBox.isSelected(); } - boolean scaleFinsFactor() + public boolean scaleFinsFactor() { return ScaleFinsCheckBoxFactor.isSelected(); } - boolean wasCancelled() + public boolean wasCancelled() { return mWasCancelled; } - boolean scaleThroughFactor() + public boolean scaleThroughFactor() { return mScaleThroughFactor; } diff --git a/boardcad/gui/jdk/SettingDialog.java b/boardcad/gui/jdk/SettingDialog.java index d375490..040f6b9 100644 --- a/boardcad/gui/jdk/SettingDialog.java +++ b/boardcad/gui/jdk/SettingDialog.java @@ -29,6 +29,7 @@ public class SettingDialog extends JDialog { JButton okButton = new JButton(); okButton.setText(LanguageResource.getString("OKBUTTON_STR")); okButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { setVisible(false); mWasCancelled = false; @@ -37,6 +38,7 @@ public void actionPerformed(java.awt.event.ActionEvent e) { JButton cancelButton = new JButton(); cancelButton.setText(LanguageResource.getString("CANCELBUTTON_STR")); cancelButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { setVisible(false); } diff --git a/boardcad/gui/jdk/SettingsComponent.java b/boardcad/gui/jdk/SettingsComponent.java index 9d5be45..c9f1413 100644 --- a/boardcad/gui/jdk/SettingsComponent.java +++ b/boardcad/gui/jdk/SettingsComponent.java @@ -156,8 +156,11 @@ public String getColumnName(final int col) return ""; } } + @Override public int getRowCount() { return mSettings.size(); } + @Override public int getColumnCount() { return 2; } + @Override public Object getValueAt(final int row, final int col) { if(mSettings.isHidden(row)) @@ -249,6 +252,7 @@ public ColorRenderer() { setOpaque(true); //MUST do this for background to show up. } + @Override public Component getTableCellRendererComponent( final JTable table, final Object color, final boolean isSelected, final boolean hasFocus, @@ -291,6 +295,7 @@ public ColorEditor() { null); //no CANCEL button handler } + @Override public void actionPerformed(final ActionEvent e) { if (EDIT.equals(e.getActionCommand())) { // The user has clicked the cell, so @@ -307,11 +312,13 @@ public void actionPerformed(final ActionEvent e) { } // Implement the one CellEditor method that AbstractCellEditor doesn't. + @Override public Object getCellEditorValue() { return currentColor; } // Implement the one method defined by TableCellEditor. + @Override public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, @@ -344,6 +351,7 @@ public FileNameEditor() { } + @Override public void actionPerformed(final ActionEvent e) { if (EDIT.equals(e.getActionCommand())) { // The user has clicked the cell, so @@ -361,6 +369,7 @@ public void actionPerformed(final ActionEvent e) { } // Implement the one CellEditor method that AbstractCellEditor doesn't. + @Override public Object getCellEditorValue() { final File file = fileChooser.getSelectedFile(); if(file == null) @@ -372,6 +381,7 @@ public Object getCellEditorValue() { } // Implement the one method defined by TableCellEditor. + @Override public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, @@ -399,6 +409,7 @@ public ActionEditor() { button.setBorderPainted(true); } + @Override public void actionPerformed(final ActionEvent e) { if (EDIT.equals(e.getActionCommand())) { // The user has clicked the cell, so @@ -412,17 +423,19 @@ public void actionPerformed(final ActionEvent e) { } // Implement the one CellEditor method that AbstractCellEditor doesn't. + @Override public Object getCellEditorValue() { return value; } // Implement the one method defined by TableCellEditor. + @Override public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) { - this.value = ((SettingsAction)value); + this.value = (value); return button; } } @@ -443,7 +456,8 @@ public EnumEditor() { comboBox.setEditable(false); comboBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + @Override + public void actionPerformed(ActionEvent e) { fireEditingStopped(); } }); @@ -451,6 +465,7 @@ public void actionPerformed(ActionEvent e) { // Implement the one CellEditor method that AbstractCellEditor doesn't. + @Override public Object getCellEditorValue() { for(Map.Entry entry : enu.getAlternatives().entrySet()) { @@ -464,6 +479,7 @@ public Object getCellEditorValue() { } // Implement the one method defined by TableCellEditor. + @Override public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, diff --git a/boardcad/gui/jdk/StatusPanel.java b/boardcad/gui/jdk/StatusPanel.java index 6cbf5f6..2ba1e2a 100644 --- a/boardcad/gui/jdk/StatusPanel.java +++ b/boardcad/gui/jdk/StatusPanel.java @@ -7,7 +7,7 @@ import boardcad.i18n.LanguageResource; //=========================================================Status Panel -class StatusPanel extends JPanel +public class StatusPanel extends JPanel { private static final long serialVersionUID = 1L; // private UserInterface user_interface; diff --git a/boardcad/gui/jdk/TwoValuesInputDialog.java b/boardcad/gui/jdk/TwoValuesInputDialog.java index 3f84b71..85f6391 100644 --- a/boardcad/gui/jdk/TwoValuesInputDialog.java +++ b/boardcad/gui/jdk/TwoValuesInputDialog.java @@ -105,6 +105,7 @@ private JButton getOkButton() { OkButton.setBounds(new Rectangle(21, 139, 106, 25)); OkButton.setText(LanguageResource.getString("OKBUTTON_STR") ); OkButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { setVisible(false); mWasCancelled = false; @@ -125,6 +126,7 @@ private JButton getCancelButton() { CancelButton.setBounds(new Rectangle(135, 139, 106, 25)); CancelButton.setText(LanguageResource.getString("CANCELBUTTON_STR") ); CancelButton.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent e) { setVisible(false); } @@ -208,7 +210,7 @@ void setValue2(int value) case DOUBLE: return Double.parseDouble(val); case INTEGER: - return (double)Integer.parseInt(val); + return Integer.parseInt(val); } } @@ -224,7 +226,7 @@ void setValue2(int value) case DOUBLE: return Double.parseDouble(val); case INTEGER: - return (double)Integer.parseInt(val); + return Integer.parseInt(val); } } diff --git a/boardcad/gui/jdk/WeightCalculatorDialog.java b/boardcad/gui/jdk/WeightCalculatorDialog.java index cbc1689..7c850e9 100644 --- a/boardcad/gui/jdk/WeightCalculatorDialog.java +++ b/boardcad/gui/jdk/WeightCalculatorDialog.java @@ -4,10 +4,11 @@ import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.geom.Point2D; import javax.swing.BorderFactory; -import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; @@ -17,7 +18,6 @@ import javax.vecmath.Point3d; import board.BezierBoard; - import cadcore.*; import boardcad.i18n.LanguageResource; @@ -26,7 +26,6 @@ public class WeightCalculatorDialog extends JDialog { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; - private JButton mCalcButton = null; private JLabel mStringerWidthLabel = null; private JLabel mStringerDensityLabel = null; private JLabel mFoamDensityLabel = null; @@ -91,6 +90,9 @@ public class WeightCalculatorDialog extends JDialog { double mPlugsAndFinsWeight = 0.2; double mTotalBoardWeight = 0; + public interface Func { + public void func(); + } /** * This method initializes @@ -164,7 +166,7 @@ void updateAll() * */ private void initialize() { - this.setSize(new Dimension(465, 437)); + this.setSize(new Dimension(465, 400)); this.setResizable(false); this.setModal(true); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); @@ -215,7 +217,6 @@ private JPanel getJContentPane() { jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); - jContentPane.add(getMCalcButton(), null); jContentPane.add(mStringerWidthLabel, null); jContentPane.add(mStringerDensityLabel, null); jContentPane.add(mFoamDensityLabel, null); @@ -257,25 +258,6 @@ private JPanel getJContentPane() { return jContentPane; } - /** - * This method initializes mCalcButton - * - * @return javax.swing.JButton - */ - private JButton getMCalcButton() { - if (mCalcButton == null) { - mCalcButton = new JButton(); - mCalcButton.setText(LanguageResource.getString("WeightCalculatorDialog.12")); //$NON-NLS-1$ - mCalcButton.setBounds(new Rectangle(30, 360, 391, 28)); - mCalcButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - updateTotalWeight(); - } - }); - } - return mCalcButton; - } - /** * This method initializes mStringerWidthEdit * @@ -284,9 +266,10 @@ public void actionPerformed(java.awt.event.ActionEvent e) { private JTextField getMStringerWidthEdit() { if (mStringerWidthEdit == null) { mStringerWidthEdit = new JTextField(); - mStringerWidthEdit.setBounds(new Rectangle(255, 15, 76, 20)); + mStringerWidthEdit.setBounds(new Rectangle(165, 15, 76, 20)); mStringerWidthEdit.setToolTipText(LanguageResource.getString("WeightCalculatorDialog.13")); //$NON-NLS-1$ - mStringerWidthEdit.addFocusListener(new java.awt.event.FocusListener() { + java.awt.event.FocusAdapter adapt = new java.awt.event.FocusAdapter() { + @Override public void focusLost(java.awt.event.FocusEvent e) { mStringerWidth = UnitUtils.convertInputStringToInternalLengthUnit(mStringerWidthEdit.getText()); mStringerWidthEdit.setText(UnitUtils.convertLengthToCurrentUnit(mStringerWidth, false)); @@ -294,10 +277,11 @@ public void focusLost(java.awt.event.FocusEvent e) { updateStringerWeight(); updateFoamVolume(); updateFoamWeight(); - } - public void focusGained(java.awt.event.FocusEvent e) { - } - }); + }; + }; + mStringerWidthEdit.addFocusListener(adapt); + mStringerWidthEdit.addActionListener((e) -> {adapt.focusLost(null);}); + } return mStringerWidthEdit; } @@ -312,13 +296,16 @@ private JTextField getMStringerDensity() { mStringerDensityEdit = new JTextField(); mStringerDensityEdit.setBounds(new Rectangle(255, 45, 76, 20)); mStringerDensityEdit.setToolTipText(LanguageResource.getString("WeightCalculatorDialog.14")); //$NON-NLS-1$ - mStringerDensityEdit.addFocusListener(new java.awt.event.FocusAdapter() { + java.awt.event.FocusAdapter adapt = new java.awt.event.FocusAdapter() { + @Override public void focusLost(java.awt.event.FocusEvent e) { mStringerDensity = UnitUtils.convertInputStringToInternalDensityUnit(mStringerDensityEdit.getText()); mStringerDensityEdit.setText(UnitUtils.convertDensityToCurrentUnit(mStringerDensity)); updateStringerWeight(); } - }); + }; + mStringerDensityEdit.addFocusListener(adapt); + mStringerDensityEdit.addActionListener((e) -> {adapt.focusLost(null);}); } return mStringerDensityEdit; } @@ -348,13 +335,16 @@ private JTextField getMFoamDensityEdit() { if (mFoamDensityEdit == null) { mFoamDensityEdit = new JTextField(); mFoamDensityEdit.setBounds(new Rectangle(255, 75, 76, 20)); - mFoamDensityEdit.addFocusListener(new java.awt.event.FocusAdapter() { + java.awt.event.FocusAdapter adapt = new java.awt.event.FocusAdapter() { + @Override public void focusLost(java.awt.event.FocusEvent e) { mFoamDensity = UnitUtils.convertInputStringToInternalDensityUnit(mFoamDensityEdit.getText()); mFoamDensityEdit.setText(UnitUtils.convertDensityToCurrentUnit(mFoamDensity)); updateFoamWeight(); } - }); + }; + mFoamDensityEdit.addFocusListener(adapt); + mFoamDensityEdit.addActionListener((e) -> {adapt.focusLost(null);}); } return mFoamDensityEdit; } @@ -368,7 +358,8 @@ private JTextField getMDeckGlassEdit() { if (mDeckGlassEdit == null) { mDeckGlassEdit = new JTextField(); mDeckGlassEdit.setBounds(new Rectangle(255, 105, 76, 20)); - mDeckGlassEdit.addFocusListener(new java.awt.event.FocusAdapter() { + java.awt.event.FocusAdapter adapt = new java.awt.event.FocusAdapter() { + @Override public void focusLost(java.awt.event.FocusEvent e) { mDeckGlassUnitWeight = UnitUtils.convertInputStringToInternalWeightUnit(mDeckGlassEdit.getText()); mDeckGlassEdit.setText(UnitUtils.convertWeightToCurrentUnit(mDeckGlassUnitWeight, true)); @@ -376,7 +367,9 @@ public void focusLost(java.awt.event.FocusEvent e) { updateTotalGlassWeight(); updateResinWeight(); } - }); + }; + mDeckGlassEdit.addFocusListener(adapt); + mDeckGlassEdit.addActionListener((e) -> {adapt.focusLost(null);}); } return mDeckGlassEdit; } @@ -390,7 +383,8 @@ private JTextField getMDeckLapWidthEdit() { if (mDeckLapWidthEdit == null) { mDeckLapWidthEdit = new JTextField(); mDeckLapWidthEdit.setBounds(new Rectangle(255, 135, 76, 20)); - mDeckLapWidthEdit.addFocusListener(new java.awt.event.FocusAdapter() { + java.awt.event.FocusAdapter adapt = new java.awt.event.FocusAdapter() { + @Override public void focusLost(java.awt.event.FocusEvent e) { mDeckLapWidth = UnitUtils.convertInputStringToInternalLengthUnit(mDeckLapWidthEdit.getText()); mDeckLapWidthEdit.setText(UnitUtils.convertLengthToCurrentUnit(mDeckLapWidth, true)); @@ -399,8 +393,10 @@ public void focusLost(java.awt.event.FocusEvent e) { updateTotalGlassWeight(); updateResinWeight(); } - }); - } + }; + mDeckLapWidthEdit.addFocusListener(adapt); + mDeckLapWidthEdit.addActionListener((e) -> {adapt.focusLost(null);}); + } return mDeckLapWidthEdit; } @@ -413,7 +409,8 @@ private JTextField getMBottomGlassEdit() { if (mBottomGlassEdit == null) { mBottomGlassEdit = new JTextField(); mBottomGlassEdit.setBounds(new Rectangle(255, 165, 76, 20)); - mBottomGlassEdit.addFocusListener(new java.awt.event.FocusAdapter() { + java.awt.event.FocusAdapter adapt = new java.awt.event.FocusAdapter() { + @Override public void focusLost(java.awt.event.FocusEvent e) { mBottomGlassUnitWeight = UnitUtils.convertInputStringToInternalWeightUnit(mBottomGlassEdit.getText()); mBottomGlassEdit.setText(UnitUtils.convertWeightToCurrentUnit(mBottomGlassUnitWeight, true)); @@ -421,7 +418,9 @@ public void focusLost(java.awt.event.FocusEvent e) { updateTotalGlassWeight(); updateResinWeight(); } - }); + }; + mBottomGlassEdit.addFocusListener(adapt); + mBottomGlassEdit.addActionListener((e) -> {adapt.focusLost(null);}); } return mBottomGlassEdit; } @@ -435,7 +434,8 @@ private JTextField getMBottomLapWidth() { if (mBottomLapWidthEdit == null) { mBottomLapWidthEdit = new JTextField(); mBottomLapWidthEdit.setBounds(new Rectangle(255, 195, 76, 20)); - mBottomLapWidthEdit.addFocusListener(new java.awt.event.FocusAdapter() { + java.awt.event.FocusAdapter adapt = new java.awt.event.FocusAdapter() { + @Override public void focusLost(java.awt.event.FocusEvent e) { mBottomLapWidth = UnitUtils.convertInputStringToInternalLengthUnit(mBottomLapWidthEdit.getText()); mBottomLapWidthEdit.setText(UnitUtils.convertLengthToCurrentUnit(mBottomLapWidth, true)); @@ -444,7 +444,9 @@ public void focusLost(java.awt.event.FocusEvent e) { updateTotalGlassWeight(); updateResinWeight(); } - }); + }; + mBottomLapWidthEdit.addFocusListener(adapt); + mBottomLapWidthEdit.addActionListener((e) -> {adapt.focusLost(null);}); } return mBottomLapWidthEdit; } @@ -458,13 +460,16 @@ private JTextField getMResinRatioEdit() { if (mResinRatioEdit == null) { mResinRatioEdit = new JTextField(); mResinRatioEdit.setBounds(new Rectangle(255, 225, 76, 20)); - mResinRatioEdit.addFocusListener(new java.awt.event.FocusAdapter() { + java.awt.event.FocusAdapter adapt = new java.awt.event.FocusAdapter() { + @Override public void focusLost(java.awt.event.FocusEvent e) { mResinRatio = Double.valueOf(mResinRatioEdit.getText()); mResinRatioEdit.setText(Double.toString(mResinRatio)); updateResinWeight(); } - }); + }; + mResinRatioEdit.addFocusListener(adapt); + mResinRatioEdit.addActionListener((e) -> {adapt.focusLost(null);}); } return mResinRatioEdit; } @@ -479,12 +484,17 @@ private JTextField getMHotcoatWeightEdit() { mHotcoatWeightEdit = new JTextField(); mHotcoatWeightEdit.setBounds(new Rectangle(345, 255, 76, 20)); mHotcoatWeightEdit.setToolTipText(LanguageResource.getString("WeightCalculatorDialog.15")); //$NON-NLS-1$ - mHotcoatWeightEdit.addFocusListener(new java.awt.event.FocusAdapter() { + java.awt.event.FocusAdapter adapt = new java.awt.event.FocusAdapter() { + @Override public void focusLost(java.awt.event.FocusEvent e) { mHotcoatWeight = UnitUtils.convertInputStringToInternalWeightUnit(mHotcoatWeightEdit.getText()); mHotcoatWeightEdit.setText(UnitUtils.convertWeightToCurrentUnit(mHotcoatWeight, true)); + + updateTotalWeight(); } - }); + }; + mHotcoatWeightEdit.addFocusListener(adapt); + mHotcoatWeightEdit.addActionListener((e) -> {adapt.focusLost(null);}); } return mHotcoatWeightEdit; } @@ -499,12 +509,17 @@ private JTextField getMPlugsAndFinsWeightEdit() { mPlugsAndFinsWeightEdit = new JTextField(); mPlugsAndFinsWeightEdit.setBounds(new Rectangle(345, 285, 76, 20)); mPlugsAndFinsWeightEdit.setToolTipText(LanguageResource.getString("WeightCalculatorDialog.16")); //$NON-NLS-1$ - mPlugsAndFinsWeightEdit.addFocusListener(new java.awt.event.FocusAdapter() { + java.awt.event.FocusAdapter adapt = new java.awt.event.FocusAdapter() { + @Override public void focusLost(java.awt.event.FocusEvent e) { mPlugsAndFinsWeight = UnitUtils.convertInputStringToInternalWeightUnit(mPlugsAndFinsWeightEdit.getText()); mPlugsAndFinsWeightEdit.setText(UnitUtils.convertWeightToCurrentUnit(mPlugsAndFinsWeight, true)); + + updateTotalWeight(); } - }); + }; + mPlugsAndFinsWeightEdit.addFocusListener(adapt); + mPlugsAndFinsWeightEdit.addActionListener((e) -> {adapt.focusLost(null);}); } return mPlugsAndFinsWeightEdit; } @@ -763,15 +778,17 @@ void calcFoamWeight() void calcDeckGlassArea() { - final BezierBoard brd = (BezierBoard)BoardCAD.getInstance().getCurrentBrd(); + final BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); if(brd == null || brd.isEmpty()) return; MathUtils.Function curveLenghtFunc = new MathUtils.Function(){ - public double f(final double x) + @Override + public double f(final double x) { MathUtils.FunctionXY deckFunc = new MathUtils.FunctionXY(){ - public Point2D.Double f(double s){ + @Override + public Point2D.Double f(double s){ Point3d point = AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(BoardCAD.getInstance().getCrossSectionInterpolationType()).getPointAt(brd,x,s,-90.0,90.0,true); return new Point2D.Double(point.y,point.z); } @@ -807,15 +824,17 @@ void calcDeckLapWeight() void calcBottomGlassArea() { - final BezierBoard brd = (BezierBoard)BoardCAD.getInstance().getCurrentBrd(); + final BezierBoard brd = BoardCAD.getInstance().getCurrentBrd(); if(brd == null || brd.isEmpty()) return; MathUtils.Function curveLenghtFunc = new MathUtils.Function(){ - public double f(final double x) + @Override + public double f(final double x) { MathUtils.FunctionXY BottomFunc = new MathUtils.FunctionXY(){ - public Point2D.Double f(double s){ + @Override + public Point2D.Double f(double s){ Point3d point = AbstractBezierBoardSurfaceModel.getBezierBoardSurfaceModel(BoardCAD.getInstance().getCrossSectionInterpolationType()).getPointAt(brd,x,s,90.0,360.0,true); return new Point2D.Double(point.y,point.z); } @@ -870,6 +889,8 @@ void updateStringerVolume() calcStringerVolume(); mStringerVolumeEdit.setText(UnitUtils.convertVolumeToCurrentUnit(mStringerVolume)); + + updateTotalWeight(); } void updateStringerWeight() @@ -877,6 +898,8 @@ void updateStringerWeight() calcStringerWeight(); mStringerWeightEdit.setText(UnitUtils.convertWeightToCurrentUnit(mStringerWeight,false)); + + updateTotalWeight(); } void updateFoamVolume() @@ -884,6 +907,8 @@ void updateFoamVolume() calcFoamVolume(); mFoamVolumeEdit.setText(UnitUtils.convertVolumeToCurrentUnit(mFoamVolume)); + + updateTotalWeight(); } void updateFoamWeight() @@ -891,6 +916,8 @@ void updateFoamWeight() calcFoamWeight(); mFoamWeightEdit.setText(UnitUtils.convertWeightToCurrentUnit(mFoamWeight,false)); + + updateTotalWeight(); } void updateDeckGlassArea() @@ -898,6 +925,8 @@ void updateDeckGlassArea() calcDeckGlassArea(); mDeckAreaEdit.setText(UnitUtils.convertAreaToCurrentUnit(mDeckGlassArea)); + + updateTotalWeight(); } void updateDeckGlassWeight() @@ -905,6 +934,8 @@ void updateDeckGlassWeight() calcDeckGlassWeight(); mDeckGlassWeightEdit.setText(UnitUtils.convertWeightToCurrentUnit(mDeckGlassWeight,false)); + + updateTotalWeight(); } void updateDeckLapArea() @@ -912,6 +943,8 @@ void updateDeckLapArea() calcDeckLapArea(); mDeckLapAreaEdit.setText(UnitUtils.convertAreaToCurrentUnit(mDeckLapArea)); + + updateTotalWeight(); } void updateDeckLapWeight() @@ -919,12 +952,16 @@ void updateDeckLapWeight() calcDeckLapWeight(); mDeckLapWeightEdit.setText(UnitUtils.convertWeightToCurrentUnit(mDeckLapWeight,false)); + + updateTotalWeight(); } void updateBottomGlassArea() { calcBottomGlassArea(); mBottomAreaEdit.setText(UnitUtils.convertAreaToCurrentUnit(mBottomGlassArea)); + + updateTotalWeight(); } void updateBottomGlassWeight() @@ -932,6 +969,8 @@ void updateBottomGlassWeight() calcBottomGlassWeight(); mBottomGlassWeightEdit.setText(UnitUtils.convertWeightToCurrentUnit(mBottomGlassWeight,false)); + + updateTotalWeight(); } void updateBottomLapArea() @@ -939,6 +978,8 @@ void updateBottomLapArea() calcBottomLapArea(); mBottomLapAreaEdit.setText(UnitUtils.convertAreaToCurrentUnit(mBottomLapArea)); + + updateTotalWeight(); } void updateBottomLapWeight() @@ -946,6 +987,8 @@ void updateBottomLapWeight() calcBottomLapWeight(); mBottomLapWeightEdit.setText(UnitUtils.convertWeightToCurrentUnit(mBottomLapWeight,false)); + + updateTotalWeight(); } void updateTotalGlassWeight() @@ -953,6 +996,8 @@ void updateTotalGlassWeight() calcTotalGlassWeight(); mGlassWeightEdit.setText(UnitUtils.convertWeightToCurrentUnit(mTotalGlassWeight,false)); + + updateTotalWeight(); } void updateResinWeight() @@ -960,6 +1005,8 @@ void updateResinWeight() calcResinWeight(); mResinWeightEdit.setText(UnitUtils.convertWeightToCurrentUnit(mResinWeight,false)); + + updateTotalWeight(); } void updateTotalWeight() diff --git a/boardcad/i18n/LanguageResource.properties b/boardcad/i18n/LanguageResource.properties index cb8cced..2c25aa1 100644 --- a/boardcad/i18n/LanguageResource.properties +++ b/boardcad/i18n/LanguageResource.properties @@ -831,7 +831,7 @@ BLANKVERTICALOFFSET_STR=Blank vertical offset OUTLINECUTTINGSPEED_STR=Outline cutting speed -LENGTHWISERESOLUTION_STR=lengthwise resolution +LENGTHWISERESOLUTION_STR=Lengthwise resolution CONTROLCATEGORY_STR=Control BEFOREDECKCUT_STR=Before deck cut DECKSTARTPOS_STR=Deck start at @@ -864,4 +864,40 @@ UNITKILOGRAMSPRMETERSQUARED_STR= kgm SHOWMOMENTOFINERTIA_STR=Show moment of inertia USEFILL_STR=Use fill -ADDITIONALTHICKNESS_STR=Additional thickness \ No newline at end of file +ADDITIONALTHICKNESS_STR=Additional thickness +HWSSTRINGERTITLE_STR=Hollow wood surfboard - Stringer + +HWSPARAMETERSCATEGORY_STR=Hollow wood surfboard parameters +HWSFRAMETHICKNESS_STR=Frame thickness +HWSWEBBING_STR=Webbing +HWSNOSEOFFSET_STR=Nose offset +HWSTAILOFFSET_STR=Tail offset +HWSDISTANCEFROMRAIL_STR=Distance from rail +JOGHEIGHT_STR=Jog height +JOGSPEED_STR=Jog speed +SINKSPEED_STR=Sink speed +CUTDEPTH_STR=Cut depth +CUTSPEED_STR=Cut speed + +GCODEHWSSTRINGER_STR=HWS Stringer +GCODEHWSRIBS_STR=HWS Ribs +GCODEHWSRIBSTITLE_STR=HWS Ribs +GCODEHWSRAIL_STR=HWS Rail +GCODEHWSRAILTITLE_STR=HWS Rail +GCODEHWSTAILPIECE_STR=HWS Tail +GCODEHWSTAILPIECETITLE_STR=HWS Tail +GCODEHWSNOSEPIECE_STR=HWS Nose +GCODEHWSNOSEPIECETITLE_STR=HWS Nose +GCODEHWSDECKTEMPLATE_STR=HWS Deck +GCODEHWSDECKTEMPLATETITLE_STR=HWS Deck +GCODEHWSBOTTOMTEMPLATE_STR=HWS Bottom +GCODEHWSBOTTOMTEMPLATETITLE_STR=HWS Bottom +GCODEHWSALLINTERNALTEMPLATES_STR=HWS Templates +GCODEHWSALLINTERNALTEMPLATESTITLE_STR=HWS Templates + +GCODEHWSMENU_STR=HWS +FILENAME_STR=Filename +HWSSKINTHICKNESS_STR=Skin thickness + +FITCURVECMD_STR=Fit curve to guidepoints +FITCONTROLPOINTS_STR=Fit curve to guidepoints \ No newline at end of file diff --git a/boardcad/i18n/LanguageResource_en.properties b/boardcad/i18n/LanguageResource_en.properties index 2c716bf..c46e01d 100644 --- a/boardcad/i18n/LanguageResource_en.properties +++ b/boardcad/i18n/LanguageResource_en.properties @@ -15,6 +15,13 @@ VOLUMEDISTRIBUTIONCOLOR_STR=Volume distribution color CENTEROFMASSCOLOR_STR=Center of mass color TANGENTCOLOR_STR=Tangent color +CONTROLPOINTCENTERCOLOR_STR=Center control point color +CONTROLPOINTTANGENT1COLOR_STR=Tangent1 control point color +CONTROLPOINTTANGENT2COLOR_STR=Tangent2 control point color +CONTROLPOINTCENTEROUTLINECOLOR_STR=Center control point outline color +CONTROLPOINTTANGENT1OUTLINECOLOR_STR=Tangent1 control point outline color +CONTROLPOINTTANGENT2OUTLINECOLOR_STR= Tangent2 control point outline color +UNSELECTEDCONTROLPOINTCOLOR_STR=Unselected control point color GUIDEPOINTCOLOR_STR=Guide point color BASELINECOLOR_STR=Base line color SIZE_AND_THICKNESS_STR=Size and thickness @@ -436,6 +443,7 @@ SPEEDCATEGORY_STR=Speed CUTTINGSPEED_STR=Cutting speed STRINGERCUTTINGSPEED_STR=Stringer cutting speed RAILCUTTINGSPEED_STR=Rail cutting speed +OUTLINECUTTINGSPEED_STR=Outline cutting speed NOSESPEEDREDUCTION_STR=Nose speed reduction TAILSPEEDREDUCTION_STR=Tail speed reduction NOSESPEEDREDUCTIONDISTANCE_STR=Nose speed reduction distance @@ -823,3 +831,75 @@ CLAMPOVERLAP_STR=Clamp overlap on stringer BLANKVERTICALOFFSET_STR=Blank vertical offset OUTLINECUTTINGSPEED_STR=Outline cutting speed + + +LENGTHWISERESOLUTION_STR=Lengthwise resolution +CONTROLCATEGORY_STR=Control +BEFOREDECKCUT_STR=Before deck cut +DECKSTARTPOS_STR=Deck start at +AFTERDECKCUT_STR=After deck cut +BEFOREBOTTOMCUT_STR=Before bottom cut +BOTTOMSTARTPOS_STR=Bottom start at +AFTERBOTTOMCUT_STR=After bottom cut + +BEFOREDECKCUTSCRIPT_STR=Before deck cut script +AFTERDECKCUTSCRIPT_STR=After deck cut script +BEFOREBOTTOMCUTSCRIPT_STR=Before bottom cut script +AFTERBOTTOMCUTSCRIPT_STR=After bottom cut script + +NOTHING_STR=Do nothing +HOME_STR=Home +HOMEREF_STR=Home Ref. +LIFTCLEAR_STR=Lift clear +HOMESCRIPT_STR=Script + +PREVIOUS_STR=Previous from deck cut + +DECKOUTLINETOAPEXDEPTH_STR=To rail apex +DECKOUTLINETOBOTTOMDEPTH_STR=To bottom +DECKOUTLINECUTDEPTH_STR=Deck outline cut depth + +SLIDINGINFOMOMENTOFINERTIA_STR=Moment of inertia: +UNITPOUNDSPRFOOTSQUARED_STR= lbft² +UNITKILOGRAMSPRMETERSQUARED_STR= kgm² + +SHOWMOMENTOFINERTIA_STR=Show moment of inertia +USEFILL_STR=Use fill + +ADDITIONALTHICKNESS_STR=Additional thickness +HWSSTRINGERTITLE_STR=Hollow wood surfboard - Stringer + +HWSPARAMETERSCATEGORY_STR=Hollow wood surfboard parameters +HWSFRAMETHICKNESS_STR=Frame thickness +HWSWEBBING_STR=Webbing +HWSNOSEOFFSET_STR=Nose offset +HWSTAILOFFSET_STR=Tail offset +HWSDISTANCEFROMRAIL_STR=Distance from rail +JOGHEIGHT_STR=Jog height +JOGSPEED_STR=Jog speed +SINKSPEED_STR=Sink speed +CUTDEPTH_STR=Cut depth +CUTSPEED_STR=Cut speed + +GCODEHWSSTRINGER_STR=HWS Stringer +GCODEHWSRIBS_STR=HWS Ribs +GCODEHWSRIBSTITLE_STR=HWS Ribs +GCODEHWSRAIL_STR=HWS Rail +GCODEHWSRAILTITLE_STR=HWS Rail +GCODEHWSTAILPIECE_STR=HWS Tail +GCODEHWSTAILPIECETITLE_STR=HWS Tail +GCODEHWSNOSEPIECE_STR=HWS Nose +GCODEHWSNOSEPIECETITLE_STR=HWS Nose +GCODEHWSDECKTEMPLATE_STR=HWS Deck +GCODEHWSDECKTEMPLATETITLE_STR=HWS Deck +GCODEHWSBOTTOMTEMPLATE_STR=HWS Bottom +GCODEHWSBOTTOMTEMPLATETITLE_STR=HWS Bottom +GCODEHWSALLINTERNALTEMPLATES_STR=HWS Templates +GCODEHWSALLINTERNALTEMPLATESTITLE_STR=HWS Templates + +GCODEHWSMENU_STR=HWS +FILENAME_STR=Filename +HWSSKINTHICKNESS_STR=Skin thickness + +FITCURVECMD_STR=Fit curve to guidepoints +FITCONTROLPOINTS_STR=Fit curve to guidepoints \ No newline at end of file diff --git a/boardcad/i18n/LanguageResource_en_US.properties b/boardcad/i18n/LanguageResource_en_US.properties index 84d139a..b754bea 100644 --- a/boardcad/i18n/LanguageResource_en_US.properties +++ b/boardcad/i18n/LanguageResource_en_US.properties @@ -823,3 +823,76 @@ CLAMPOVERLAP_STR=Clamp overlap on stringer BLANKVERTICALOFFSET_STR=Blank vertical offset OUTLINECUTTINGSPEED_STR=Outline cutting speed + + +LENGTHWISERESOLUTION_STR=Lengthwise resolution +CONTROLCATEGORY_STR=Control +BEFOREDECKCUT_STR=Before deck cut +DECKSTARTPOS_STR=Deck start at +AFTERDECKCUT_STR=After deck cut +BEFOREBOTTOMCUT_STR=Before bottom cut +BOTTOMSTARTPOS_STR=Bottom start at +AFTERBOTTOMCUT_STR=After bottom cut + +BEFOREDECKCUTSCRIPT_STR=Before deck cut script +AFTERDECKCUTSCRIPT_STR=After deck cut script +BEFOREBOTTOMCUTSCRIPT_STR=Before bottom cut script +AFTERBOTTOMCUTSCRIPT_STR=After bottom cut script + +NOTHING_STR=Do nothing +HOME_STR=Home +HOMEREF_STR=Home Ref. +LIFTCLEAR_STR=Lift clear +HOMESCRIPT_STR=Script + +PREVIOUS_STR=Previous from deck cut + +DECKOUTLINETOAPEXDEPTH_STR=To rail apex +DECKOUTLINETOBOTTOMDEPTH_STR=To bottom +DECKOUTLINECUTDEPTH_STR=Deck outline cut depth + +SLIDINGINFOMOMENTOFINERTIA_STR=Moment of inertia: +UNITPOUNDSPRFOOTSQUARED_STR= lbft² +UNITKILOGRAMSPRMETERSQUARED_STR= kgm² + +SHOWMOMENTOFINERTIA_STR=Show moment of inertia +USEFILL_STR=Use fill + +ADDITIONALTHICKNESS_STR=Additional thickness +HWSSTRINGERTITLE_STR=Hollow wood surfboard - Stringer + +HWSPARAMETERSCATEGORY_STR=Hollow wood surfboard parameters +HWSFRAMETHICKNESS_STR=Frame thickness +HWSWEBBING_STR=Webbing +HWSNOSEOFFSET_STR=Nose offset +HWSTAILOFFSET_STR=Tail offset +HWSDISTANCEFROMRAIL_STR=Distance from rail +JOGHEIGHT_STR=Jog height +JOGSPEED_STR=Jog speed +SINKSPEED_STR=Sink speed +CUTDEPTH_STR=Cut depth +CUTSPEED_STR=Cut speed + +GCODEHWSSTRINGER_STR=HWS Stringer +GCODEHWSRIBS_STR=HWS Ribs +GCODEHWSRIBSTITLE_STR=HWS Ribs +GCODEHWSRAIL_STR=HWS Rail +GCODEHWSRAILTITLE_STR=HWS Rail +GCODEHWSTAILPIECE_STR=HWS Tail +GCODEHWSTAILPIECETITLE_STR=HWS Tail +GCODEHWSNOSEPIECE_STR=HWS Nose +GCODEHWSNOSEPIECETITLE_STR=HWS Nose +GCODEHWSDECKTEMPLATE_STR=HWS Deck +GCODEHWSDECKTEMPLATETITLE_STR=HWS Deck +GCODEHWSBOTTOMTEMPLATE_STR=HWS Bottom +GCODEHWSBOTTOMTEMPLATETITLE_STR=HWS Bottom +GCODEHWSALLINTERNALTEMPLATES_STR=HWS Templates +GCODEHWSALLINTERNALTEMPLATESTITLE_STR=HWS Templates + + +GCODEHWSMENU_STR=HWS +FILENAME_STR=Filename +HWSSKINTHICKNESS_STR=Skin thickness + +FITCURVECMD_STR=Fit curve to guidepoints +FITCONTROLPOINTS_STR=Fit curve to guidepoints \ No newline at end of file diff --git a/boardcad/i18n/LanguageResource_es.properties b/boardcad/i18n/LanguageResource_es.properties index 0255fd1..0cc4881 100644 --- a/boardcad/i18n/LanguageResource_es.properties +++ b/boardcad/i18n/LanguageResource_es.properties @@ -218,6 +218,10 @@ NROFSEGMENT_STR=Nr de segmentos SETNROFPOINTS_STR=Establecer nr de puntos NROFPOINTS_STR=Número de puntos +#CONTEXT MENU +NURBSCONTROLPOINTXLOCKED_STR=X locked +NURBSCONTROLPOINTYLOCKED_STR=Y locked +NURBSCONTROLPOINTZLOCKED_STR=Z locked RENDERMENU_STR=Render RENDER_STR=Render modelo nurbs @@ -492,6 +496,20 @@ S3DTHICKNESSCURVENOTSUPPOSTEDMSG_STR=Archivos shape3D de curva de grosor no son S3DTHICKNESSCURVENOTSUPPOSTEDTITLE_STR=Aviso S3DREADERRORMSG_STR=Archivo Shape3D .s3d xml no se puede leer S3DREADERRORTITLE_STR=Error al cargar archivo .s3d xml +#ScaleBoardInptDialog.java +MAXWIDTHLABEL_STR=Width: +LENGTHLABEL_STR=Length: +MAXTHICKLABEL_STR=Thickness: +FACTORLABEL_STR=Factor: +FACTORSCALEMSG_STR=Enter a scale factor... +SCALEMSG_STR=Enter measurements +OVERCURVERADIOBUTTON_STR=Over Curve +STRAIGHTLINERADIOBUTTON_STR=Straight Line +SCALEFINSMSG=Scale fins position accordingly +SCALEFINSMSGDETAILED=Scale fins position according to the length and width scaling +CONSTRAINTPROPORTIONSMSG=Constrain Proportions +CONSTRAINTPROPORTIONSMSGDETAILED=If checked, when you change one of the dimensions, the two others change with the same factor +SCALEBOTTOMROCKERMSG=Scale bottom rocker accordingly #SettingsDialog.java SETTINGSTITLE_STR=Ajustes @@ -728,6 +746,48 @@ ROTATINGBOARD_STR=Rotating board system ROTATINGBOARDCUTTERTYPE_STR=Rotating board system cutter ROTATINGBOARDCUTTERTYPE_STR=Rotating board system cutter +PRINTHWSMENU_STR=Hollow wood surfboard +PRINTHWSSTRINGER_STR=Stringer +PRINTHWSRIBS_STR=Ribs +PRINTHWSRAIL_STR=Rail +PRINTHWSTAILPIECE_STR=Tail piece +PRINTHWSNOSEPIECE_STR=Nose piece +PRINTHWSDECKTEMPLATE_STR=Deck template +PRINTHWSBOTTOMTEMPLATE_STR=Bottom template + +IMPORTBEZIERPROFILE_STR=Profile +IMPORTBEZIERCROSSSECTION_STR=Cross section + +CANCEL_STR=Cancel + +CUTTER_SCALE_X=Scale X +CUTTER_SCALE_Y=Scale Y +CUTTER_SCALE_Z=Scale Z +CUTTER_STL_FILENAME=Filename + +IMPORTBEZIERPROFILE_STR=Profile +IMPORTBEZIERCROSSSECTION_STR=Cross section + +SELECTEDCONTROLPOINTSIZE_STR=Selected control point size +SELECTEDCONTROLPOINTOUTLINETHICKNESS_STR=Selected control point outline thickness +UNSELECTEDCONTROLPOINTSIZE_STR=Unselected control point size +UNSELECTEDCONTROLPOINTOUTLINETHICKNESS_STR=Unselected control point outline thickness + +SELECTEDTANGENTCOLOR_STR=I think this is deprecated, pls check Haavard, Mocol. +SELECTEDCONTROLPOINTCENTERCOLOR_STR=Selected control point center color +SELECTEDCONTROLPOINTCENTEROUTLINECOLOR_STR=Selected control point center outline color +SELECTEDCONTROLPOINTTANGENT1COLOR_STR=Selected control point tangent 1 color +SELECTEDCONTROLPOINTTANGENT2COLOR_STR=Selected control point tangent 2 color +SELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR_STR=Selected control point tangent 1 outline color +SELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR_STR=Selected control point tangent 2 outline color + +UNSELECTEDTANGENTCOLOR_STR=I think this is deprecated, pls check Haavard, Mocol. +UNSELECTEDCONTROLPOINTCENTERCOLOR_STR=Unselected control point center color +UNSELECTEDCONTROLPOINTCENTEROUTLINECOLOR_STR=Unselected control point center outline color +UNSELECTEDCONTROLPOINTTANGENT1COLOR_STR=Unselected control point tangent 1 color +UNSELECTEDCONTROLPOINTTANGENT2COLOR_STR=Unselected control point tangent 2 color +UNSELECTEDCONTROLPOINTTANGENT1OUTLINECOLOR_STR=Unselected control point tangent 1 outline color +UNSELECTEDCONTROLPOINTTANGENT2OUTLINECOLOR_STR=Unselected control point tangent 2 outline color VOLUMEDISTRIBUTIONTHICKNESS_STR=Volume distribution thickness EXPORTBEZIERCROSSSECTIONASDXFSPLINE_STR=Bezier Cross-section as DXF Spline @@ -771,3 +831,75 @@ CLAMPOVERLAP_STR=Clamp overlap on stringer BLANKVERTICALOFFSET_STR=Blank vertical offset OUTLINECUTTINGSPEED_STR=Outline cutting speed + + +LENGTHWISERESOLUTION_STR=lengthwise resolution +CONTROLCATEGORY_STR=Control +BEFOREDECKCUT_STR=Before deck cut +DECKSTARTPOS_STR=Deck start at +AFTERDECKCUT_STR=After deck cut +BEFOREBOTTOMCUT_STR=Before bottom cut +BOTTOMSTARTPOS_STR=Bottom start at +AFTERBOTTOMCUT_STR=After bottom cut + +BEFOREDECKCUTSCRIPT_STR=Before deck cut script +AFTERDECKCUTSCRIPT_STR=After deck cut script +BEFOREBOTTOMCUTSCRIPT_STR=Before bottom cut script +AFTERBOTTOMCUTSCRIPT_STR=After bottom cut script + +NOTHING_STR=Do nothing +HOME_STR=Home +HOMEREF_STR=Home Ref. +LIFTCLEAR_STR=Lift clear +HOMESCRIPT_STR=Script + +PREVIOUS_STR=Previous from deck cut + +DECKOUTLINETOAPEXDEPTH_STR=To rail apex +DECKOUTLINETOBOTTOMDEPTH_STR=To bottom +DECKOUTLINECUTDEPTH_STR=Deck outline cut depth + +SLIDINGINFOMOMENTOFINERTIA_STR=Moment of inertia: +UNITPOUNDSPRFOOTSQUARED_STR= lbft² +UNITKILOGRAMSPRMETERSQUARED_STR= kgm² + +SHOWMOMENTOFINERTIA_STR=Show moment of inertia +USEFILL_STR=Use fill + +ADDITIONALTHICKNESS_STR=Additional thickness +HWSSTRINGERTITLE_STR=Hollow wood surfboard - Stringer + +HWSPARAMETERSCATEGORY_STR=Hollow wood surfboard parameters +HWSFRAMETHICKNESS_STR=Frame thickness +HWSWEBBING_STR=Webbing +HWSNOSEOFFSET_STR=Nose offset +HWSTAILOFFSET_STR=Tail offset +HWSDISTANCEFROMRAIL_STR=Distance from rail +JOGHEIGHT_STR=Jog height +JOGSPEED_STR=Jog speed +SINKSPEED_STR=Sink speed +CUTDEPTH_STR=Cut depth +CUTSPEED_STR=Cut speed + +GCODEHWSSTRINGER_STR=HWS Stringer +GCODEHWSRIBS_STR=HWS Ribs +GCODEHWSRIBSTITLE_STR=HWS Ribs +GCODEHWSRAIL_STR=HWS Rail +GCODEHWSRAILTITLE_STR=HWS Rail +GCODEHWSTAILPIECE_STR=HWS Tail +GCODEHWSTAILPIECETITLE_STR=HWS Tail +GCODEHWSNOSEPIECE_STR=HWS Nose +GCODEHWSNOSEPIECETITLE_STR=HWS Nose +GCODEHWSDECKTEMPLATE_STR=HWS Deck +GCODEHWSDECKTEMPLATETITLE_STR=HWS Deck +GCODEHWSBOTTOMTEMPLATE_STR=HWS Bottom +GCODEHWSBOTTOMTEMPLATETITLE_STR=HWS Bottom +GCODEHWSALLINTERNALTEMPLATES_STR=HWS Templates +GCODEHWSALLINTERNALTEMPLATESTITLE_STR=HWS Templates + +GCODEHWSMENU_STR=HWS +FILENAME_STR=Filename +HWSSKINTHICKNESS_STR=Skin thickness + +FITCURVECMD_STR=Fit curve to guidepoints +FITCONTROLPOINTS_STR=Fit curve to guidepoints \ No newline at end of file diff --git a/boardcad/i18n/LanguageResource_fr.properties b/boardcad/i18n/LanguageResource_fr.properties index 02f918f..55fa76a 100644 --- a/boardcad/i18n/LanguageResource_fr.properties +++ b/boardcad/i18n/LanguageResource_fr.properties @@ -745,3 +745,74 @@ CLAMPOVERLAP_STR=Clamp overlap on stringer BLANKVERTICALOFFSET_STR=Blank vertical offset OUTLINECUTTINGSPEED_STR=Outline cutting speed + +LENGTHWISERESOLUTION_STR=lengthwise resolution +CONTROLCATEGORY_STR=Control +BEFOREDECKCUT_STR=Before deck cut +DECKSTARTPOS_STR=Deck start at +AFTERDECKCUT_STR=After deck cut +BEFOREBOTTOMCUT_STR=Before bottom cut +BOTTOMSTARTPOS_STR=Bottom start at +AFTERBOTTOMCUT_STR=After bottom cut + +BEFOREDECKCUTSCRIPT_STR=Before deck cut script +AFTERDECKCUTSCRIPT_STR=After deck cut script +BEFOREBOTTOMCUTSCRIPT_STR=Before bottom cut script +AFTERBOTTOMCUTSCRIPT_STR=After bottom cut script + +NOTHING_STR=Do nothing +HOME_STR=Home +HOMEREF_STR=Home Ref. +LIFTCLEAR_STR=Lift clear +HOMESCRIPT_STR=Script + +PREVIOUS_STR=Previous from deck cut + +DECKOUTLINETOAPEXDEPTH_STR=To rail apex +DECKOUTLINETOBOTTOMDEPTH_STR=To bottom +DECKOUTLINECUTDEPTH_STR=Deck outline cut depth + +SLIDINGINFOMOMENTOFINERTIA_STR=Moment of inertia: +UNITPOUNDSPRFOOTSQUARED_STR= lbft² +UNITKILOGRAMSPRMETERSQUARED_STR= kgm² + +SHOWMOMENTOFINERTIA_STR=Show moment of inertia +USEFILL_STR=Use fill + +ADDITIONALTHICKNESS_STR=Additional thickness +HWSSTRINGERTITLE_STR=Hollow wood surfboard - Stringer + +HWSPARAMETERSCATEGORY_STR=Hollow wood surfboard parameters +HWSFRAMETHICKNESS_STR=Frame thickness +HWSWEBBING_STR=Webbing +HWSNOSEOFFSET_STR=Nose offset +HWSTAILOFFSET_STR=Tail offset +HWSDISTANCEFROMRAIL_STR=Distance from rail +JOGHEIGHT_STR=Jog height +JOGSPEED_STR=Jog speed +SINKSPEED_STR=Sink speed +CUTDEPTH_STR=Cut depth +CUTSPEED_STR=Cut speed + +GCODEHWSSTRINGER_STR=HWS Stringer +GCODEHWSRIBS_STR=HWS Ribs +GCODEHWSRIBSTITLE_STR=HWS Ribs +GCODEHWSRAIL_STR=HWS Rail +GCODEHWSRAILTITLE_STR=HWS Rail +GCODEHWSTAILPIECE_STR=HWS Tail +GCODEHWSTAILPIECETITLE_STR=HWS Tail +GCODEHWSNOSEPIECE_STR=HWS Nose +GCODEHWSNOSEPIECETITLE_STR=HWS Nose +GCODEHWSDECKTEMPLATE_STR=HWS Deck +GCODEHWSDECKTEMPLATETITLE_STR=HWS Deck +GCODEHWSBOTTOMTEMPLATE_STR=HWS Bottom +GCODEHWSBOTTOMTEMPLATETITLE_STR=HWS Bottom +GCODEHWSALLINTERNALTEMPLATES_STR=HWS Templates +GCODEHWSALLINTERNALTEMPLATESTITLE_STR=HWS Templates + +GCODEHWSMENU_STR=HWS +FILENAME_STR=Filename +HWSSKINTHICKNESS_STR=Skin thickness + +FITCURVECMD_STR=Fit curve to guidepoints +FITCONTROLPOINTS_STR=Fit curve to guidepoints \ No newline at end of file diff --git a/boardcad/i18n/LanguageResource_nl.properties b/boardcad/i18n/LanguageResource_nl.properties index 522c26a..69efdf7 100644 --- a/boardcad/i18n/LanguageResource_nl.properties +++ b/boardcad/i18n/LanguageResource_nl.properties @@ -755,3 +755,74 @@ CLAMPOVERLAP_STR=Clamp overlap on stringer BLANKVERTICALOFFSET_STR=Blank vertical offset OUTLINECUTTINGSPEED_STR=Outline cutting speed + +LENGTHWISERESOLUTION_STR=lengthwise resolution +CONTROLCATEGORY_STR=Control +BEFOREDECKCUT_STR=Before deck cut +DECKSTARTPOS_STR=Deck start at +AFTERDECKCUT_STR=After deck cut +BEFOREBOTTOMCUT_STR=Before bottom cut +BOTTOMSTARTPOS_STR=Bottom start at +AFTERBOTTOMCUT_STR=After bottom cut + +BEFOREDECKCUTSCRIPT_STR=Before deck cut script +AFTERDECKCUTSCRIPT_STR=After deck cut script +BEFOREBOTTOMCUTSCRIPT_STR=Before bottom cut script +AFTERBOTTOMCUTSCRIPT_STR=After bottom cut script + +NOTHING_STR=Do nothing +HOME_STR=Home +HOMEREF_STR=Home Ref. +LIFTCLEAR_STR=Lift clear +HOMESCRIPT_STR=Script + +PREVIOUS_STR=Previous from deck cut + +DECKOUTLINETOAPEXDEPTH_STR=To rail apex +DECKOUTLINETOBOTTOMDEPTH_STR=To bottom +DECKOUTLINECUTDEPTH_STR=Deck outline cut depth + +SLIDINGINFOMOMENTOFINERTIA_STR=Moment of inertia: +UNITPOUNDSPRFOOTSQUARED_STR= lbft² +UNITKILOGRAMSPRMETERSQUARED_STR= kgm² + +SHOWMOMENTOFINERTIA_STR=Show moment of inertia +USEFILL_STR=Use fill + +ADDITIONALTHICKNESS_STR=Additional thickness +HWSSTRINGERTITLE_STR=Hollow wood surfboard - Stringer + +HWSPARAMETERSCATEGORY_STR=Hollow wood surfboard parameters +HWSFRAMETHICKNESS_STR=Frame thickness +HWSWEBBING_STR=Webbing +HWSNOSEOFFSET_STR=Nose offset +HWSTAILOFFSET_STR=Tail offset +HWSDISTANCEFROMRAIL_STR=Distance from rail +JOGHEIGHT_STR=Jog height +JOGSPEED_STR=Jog speed +SINKSPEED_STR=Sink speed +CUTDEPTH_STR=Cut depth +CUTSPEED_STR=Cut speed + +GCODEHWSSTRINGER_STR=HWS Stringer +GCODEHWSRIBS_STR=HWS Ribs +GCODEHWSRIBSTITLE_STR=HWS Ribs +GCODEHWSRAIL_STR=HWS Rail +GCODEHWSRAILTITLE_STR=HWS Rail +GCODEHWSTAILPIECE_STR=HWS Tail +GCODEHWSTAILPIECETITLE_STR=HWS Tail +GCODEHWSNOSEPIECE_STR=HWS Nose +GCODEHWSNOSEPIECETITLE_STR=HWS Nose +GCODEHWSDECKTEMPLATE_STR=HWS Deck +GCODEHWSDECKTEMPLATETITLE_STR=HWS Deck +GCODEHWSBOTTOMTEMPLATE_STR=HWS Bottom +GCODEHWSBOTTOMTEMPLATETITLE_STR=HWS Bottom +GCODEHWSALLINTERNALTEMPLATES_STR=HWS Templates +GCODEHWSALLINTERNALTEMPLATESTITLE_STR=HWS Templates + +GCODEHWSMENU_STR=HWS +FILENAME_STR=Filename +HWSSKINTHICKNESS_STR=Skin thickness + +FITCURVECMD_STR=Fit curve to guidepoints +FITCONTROLPOINTS_STR=Fit curve to guidepoints \ No newline at end of file diff --git a/boardcad/i18n/LanguageResource_no.properties b/boardcad/i18n/LanguageResource_no.properties index 71c8aef..4622526 100644 --- a/boardcad/i18n/LanguageResource_no.properties +++ b/boardcad/i18n/LanguageResource_no.properties @@ -21,7 +21,7 @@ CONTROLPOINTCENTEROUTLINECOLOR_STR=Senter kontrollpunkt omriss farge CONTROLPOINTTANGENT1OUTLINECOLOR_STR=Tangent1 kontrollpunkt omriss farge CONTROLPOINTTANGENT2OUTLINECOLOR_STR= Tangent2 kontrollpunkt omriss farge UNSELECTEDCONTROLPOINTCOLOR_STR=inaktivt kontrollpunkt farge -GUIDEPOINTCOLOR_STR=Guide punkt farge +GUIDEPOINTCOLOR_STR=Guidepunkt farge BASELINECOLOR_STR=Bunnlinje farge SIZE_AND_THICKNESS_STR=Størrelse og tykkelse CONTROLPOINTSIZE_STR=Kontrollpunkt size @@ -769,3 +769,75 @@ CLAMPOVERLAP_STR=Clamp overlap on stringer BLANKVERTICALOFFSET_STR=Blank vertical offset OUTLINECUTTINGSPEED_STR=Outline cutting speed + + +LENGTHWISERESOLUTION_STR=lengthwise resolution +CONTROLCATEGORY_STR=Control +BEFOREDECKCUT_STR=Before deck cut +DECKSTARTPOS_STR=Deck start at +AFTERDECKCUT_STR=After deck cut +BEFOREBOTTOMCUT_STR=Before bottom cut +BOTTOMSTARTPOS_STR=Bottom start at +AFTERBOTTOMCUT_STR=After bottom cut + +BEFOREDECKCUTSCRIPT_STR=Before deck cut script +AFTERDECKCUTSCRIPT_STR=After deck cut script +BEFOREBOTTOMCUTSCRIPT_STR=Before bottom cut script +AFTERBOTTOMCUTSCRIPT_STR=After bottom cut script + +NOTHING_STR=Do nothing +HOME_STR=Home +HOMEREF_STR=Home Ref. +LIFTCLEAR_STR=Lift clear +HOMESCRIPT_STR=Script + +PREVIOUS_STR=Previous from deck cut + +DECKOUTLINETOAPEXDEPTH_STR=To rail apex +DECKOUTLINETOBOTTOMDEPTH_STR=To bottom +DECKOUTLINECUTDEPTH_STR=Deck outline cut depth + +SLIDINGINFOMOMENTOFINERTIA_STR=Moment of inertia: +UNITPOUNDSPRFOOTSQUARED_STR= lbft² +UNITKILOGRAMSPRMETERSQUARED_STR= kgm² + +SHOWMOMENTOFINERTIA_STR=Show moment of inertia +USEFILL_STR=Use fill + +ADDITIONALTHICKNESS_STR=Additional thickness +HWSSTRINGERTITLE_STR=Hollow wood surfboard - Stringer + +HWSPARAMETERSCATEGORY_STR=Hollow wood surfboard parameters +HWSFRAMETHICKNESS_STR=Frame thickness +HWSWEBBING_STR=Webbing +HWSNOSEOFFSET_STR=Nose offset +HWSTAILOFFSET_STR=Tail offset +HWSDISTANCEFROMRAIL_STR=Distance from rail +JOGHEIGHT_STR=Jog height +JOGSPEED_STR=Jog speed +SINKSPEED_STR=Sink speed +CUTDEPTH_STR=Cut depth +CUTSPEED_STR=Cut speed + +GCODEHWSSTRINGER_STR=HWS Stringer +GCODEHWSRIBS_STR=HWS Ribs +GCODEHWSRIBSTITLE_STR=HWS Ribs +GCODEHWSRAIL_STR=HWS Rail +GCODEHWSRAILTITLE_STR=HWS Rail +GCODEHWSTAILPIECE_STR=HWS Tail +GCODEHWSTAILPIECETITLE_STR=HWS Tail +GCODEHWSNOSEPIECE_STR=HWS Nose +GCODEHWSNOSEPIECETITLE_STR=HWS Nose +GCODEHWSDECKTEMPLATE_STR=HWS Deck +GCODEHWSDECKTEMPLATETITLE_STR=HWS Deck +GCODEHWSBOTTOMTEMPLATE_STR=HWS Bottom +GCODEHWSBOTTOMTEMPLATETITLE_STR=HWS Bottom +GCODEHWSALLINTERNALTEMPLATES_STR=HWS Templates +GCODEHWSALLINTERNALTEMPLATESTITLE_STR=HWS Templates + +GCODEHWSMENU_STR=HWS +FILENAME_STR=Filename +HWSSKINTHICKNESS_STR=Skin thickness + +FITCURVECMD_STR=Fit curve to guidepoints +FITCONTROLPOINTS_STR=Fit curve to guidepoints \ No newline at end of file diff --git a/boardcad/i18n/LanguageResource_pt.properties b/boardcad/i18n/LanguageResource_pt.properties index 9c2fbde..355d4b3 100644 --- a/boardcad/i18n/LanguageResource_pt.properties +++ b/boardcad/i18n/LanguageResource_pt.properties @@ -807,3 +807,75 @@ CLAMPOVERLAP_STR=Clamp overlap on stringer BLANKVERTICALOFFSET_STR=Blank vertical offset OUTLINECUTTINGSPEED_STR=Outline cutting speed + + +LENGTHWISERESOLUTION_STR=lengthwise resolution +CONTROLCATEGORY_STR=Control +BEFOREDECKCUT_STR=Before deck cut +DECKSTARTPOS_STR=Deck start at +AFTERDECKCUT_STR=After deck cut +BEFOREBOTTOMCUT_STR=Before bottom cut +BOTTOMSTARTPOS_STR=Bottom start at +AFTERBOTTOMCUT_STR=After bottom cut + +BEFOREDECKCUTSCRIPT_STR=Before deck cut script +AFTERDECKCUTSCRIPT_STR=After deck cut script +BEFOREBOTTOMCUTSCRIPT_STR=Before bottom cut script +AFTERBOTTOMCUTSCRIPT_STR=After bottom cut script + +NOTHING_STR=Do nothing +HOME_STR=Home +HOMEREF_STR=Home Ref. +LIFTCLEAR_STR=Lift clear +HOMESCRIPT_STR=Script + +PREVIOUS_STR=Previous from deck cut + +DECKOUTLINETOAPEXDEPTH_STR=To rail apex +DECKOUTLINETOBOTTOMDEPTH_STR=To bottom +DECKOUTLINECUTDEPTH_STR=Deck outline cut depth + +SLIDINGINFOMOMENTOFINERTIA_STR=Moment of inertia: +UNITPOUNDSPRFOOTSQUARED_STR= lbft² +UNITKILOGRAMSPRMETERSQUARED_STR= kgm² + +SHOWMOMENTOFINERTIA_STR=Show moment of inertia +USEFILL_STR=Use fill + +ADDITIONALTHICKNESS_STR=Additional thickness +HWSSTRINGERTITLE_STR=Hollow wood surfboard - Stringer + +HWSPARAMETERSCATEGORY_STR=Hollow wood surfboard parameters +HWSFRAMETHICKNESS_STR=Frame thickness +HWSWEBBING_STR=Webbing +HWSNOSEOFFSET_STR=Nose offset +HWSTAILOFFSET_STR=Tail offset +HWSDISTANCEFROMRAIL_STR=Distance from rail +JOGHEIGHT_STR=Jog height +JOGSPEED_STR=Jog speed +SINKSPEED_STR=Sink speed +CUTDEPTH_STR=Cut depth +CUTSPEED_STR=Cut speed + +GCODEHWSSTRINGER_STR=HWS Stringer +GCODEHWSRIBS_STR=HWS Ribs +GCODEHWSRIBSTITLE_STR=HWS Ribs +GCODEHWSRAIL_STR=HWS Rail +GCODEHWSRAILTITLE_STR=HWS Rail +GCODEHWSTAILPIECE_STR=HWS Tail +GCODEHWSTAILPIECETITLE_STR=HWS Tail +GCODEHWSNOSEPIECE_STR=HWS Nose +GCODEHWSNOSEPIECETITLE_STR=HWS Nose +GCODEHWSDECKTEMPLATE_STR=HWS Deck +GCODEHWSDECKTEMPLATETITLE_STR=HWS Deck +GCODEHWSBOTTOMTEMPLATE_STR=HWS Bottom +GCODEHWSBOTTOMTEMPLATETITLE_STR=HWS Bottom +GCODEHWSALLINTERNALTEMPLATES_STR=HWS Templates +GCODEHWSALLINTERNALTEMPLATESTITLE_STR=HWS Templates + +GCODEHWSMENU_STR=HWS +FILENAME_STR=Filename +HWSSKINTHICKNESS_STR=Skin thickness + +FITCURVECMD_STR=Fit curve to guidepoints +FITCONTROLPOINTS_STR=Fit curve to guidepoints \ No newline at end of file diff --git a/boardcad/print/PrintBrd.java b/boardcad/print/PrintBrd.java index 33d29e7..d2ffd2f 100644 --- a/boardcad/print/PrintBrd.java +++ b/boardcad/print/PrintBrd.java @@ -452,7 +452,7 @@ int printOutline(PageFormat pageFormat, int pageIndex, Graphics g) -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 0.0, 72/2.54, mPrintGrid ,BoardCAD.getInstance().getCurrentBrd(),BoardCAD.getInstance().isPrintingControlPoints(),BoardCAD.getInstance().isPrintingFins(), false, false); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, mPrintGrid ,BoardCAD.getInstance().getCurrentBrd(),BoardCAD.getInstance().isPrintingControlPoints(),BoardCAD.getInstance().isPrintingFins(), false, false); } else { @@ -460,7 +460,7 @@ int printOutline(PageFormat pageFormat, int pageIndex, Graphics g) -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 0.0, 72/2.54, mPrintGrid ,BoardCAD.getInstance().getCurrentBrd(),BoardCAD.getInstance().isPrintingControlPoints(),BoardCAD.getInstance().isPrintingFins()); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, mPrintGrid ,BoardCAD.getInstance().getCurrentBrd(),BoardCAD.getInstance().isPrintingControlPoints(),BoardCAD.getInstance().isPrintingFins()); } return 0; @@ -515,13 +515,13 @@ int printSpinTemplate(PageFormat pageFormat, int pageIndex, Graphics g) { BezierBoardDrawUtil.printSpinTemplateOverCurve(new JavaDraw(g2d), -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 0.0, 72/2.54, mPrintGrid,brd,BoardCAD.getInstance().isPrintingControlPoints(),BoardCAD.getInstance().isPrintingFins()); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, mPrintGrid,brd,BoardCAD.getInstance().isPrintingControlPoints(),BoardCAD.getInstance().isPrintingFins()); } else { BezierBoardDrawUtil.printSpinTemplate(new JavaDraw(g2d), -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 0.0, 72/2.54, mPrintGrid,brd,BoardCAD.getInstance().isPrintingControlPoints(),BoardCAD.getInstance().isPrintingFins()); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, mPrintGrid,brd,BoardCAD.getInstance().isPrintingControlPoints(),BoardCAD.getInstance().isPrintingFins()); } return 0; @@ -569,7 +569,7 @@ int printProfile(PageFormat pageFormat, int pageIndex, Graphics g) -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(),BoardCAD.getInstance().isPrintingControlPoints()); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, true, BoardCAD.getInstance().getCurrentBrd(),BoardCAD.getInstance().isPrintingControlPoints()); return 0; } @@ -619,7 +619,7 @@ int printSlices(PageFormat pageFormat, int pageIndex, Graphics g) -pageFormat.getImageableWidth()*(pageIndex%widthPrSliceInPages), - -BoardCAD.getInstance().getCurrentBrd().getCrossSections().get((pageIndex/widthPrSliceInPages + 1)).getBezierSpline().getMinY()*(72/2.54), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), + -BoardCAD.getInstance().getCurrentBrd().getCrossSections().get((pageIndex/widthPrSliceInPages + 1)).getBezierSpline().getMinY()*(72/2.54), 72/2.54, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), pageIndex/widthPrSliceInPages + 1,BoardCAD.getInstance().isPrintingControlPoints()); return 0; @@ -698,7 +698,7 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) Line2D.Double line = new Line2D.Double(); JavaDraw jd = new JavaDraw(g2d); - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, scale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, scale, 0.0); g2d.setStroke(linestroke); g2d.setColor(Color.GRAY); @@ -733,8 +733,8 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) g2d.setTransform(savedTransform); Stroke stroke = new BasicStroke((float)(1.5/scale)); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, Color.BLACK, stroke, brd.getOutline(), BezierBoardDrawUtil.MirrorY, false); - BezierBoardDrawUtil.paintFins(jd, xm+5, currentY, scale, Color.BLACK, stroke, brd.getFins(), false,false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, 0.0, Color.BLACK, stroke, brd.getOutline(), BezierBoardDrawUtil.MirrorY, false); + BezierBoardDrawUtil.paintFins(jd, xm+5, currentY, scale, 0.0, Color.BLACK, stroke, brd.getFins(), false,false); currentY += (brd.getCenterWidth()/2)*scale + hgt + 5; @@ -762,7 +762,7 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) currentY += brd.getMaxRocker()*scale +10; - savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, scale); + savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, scale, 0.0); g2d.setStroke(linestroke); line.setLine(tailpos, -(tailThickness+tail1Rocker), tailpos, -tail1Rocker); @@ -784,8 +784,8 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) g2d.setTransform(savedTransform); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, Color.BLACK, stroke, brd.getDeck(), BezierBoardDrawUtil.FlipY, false); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, Color.BLACK, stroke, brd.getBottom(), BezierBoardDrawUtil.FlipY, false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, 0.0, Color.BLACK, stroke, brd.getDeck(), BezierBoardDrawUtil.FlipY, false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, 0.0, Color.BLACK, stroke, brd.getBottom(), BezierBoardDrawUtil.FlipY, false); currentY += hgt + 5; @@ -824,7 +824,7 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) currentY += brd.getThickness()*scale + 5; - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+width/2, currentY, 0.0, scale, Color.BLACK, linestroke, false, true, brd.getLength()/2, brd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+width/2, currentY, scale, 0.0, Color.BLACK, linestroke, false, true, brd.getLength()/2, brd); currentY += hgt; @@ -834,9 +834,9 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) currentY += hgt+10; - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((width/3)*1), currentY, 0.0, scale, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((width/3)*1), currentY, scale, 0.0, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((width/3)*2), currentY, 0.0, scale, Color.BLACK, linestroke, false, true, brd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((width/3)*2), currentY, scale, 0.0, Color.BLACK, linestroke, false, true, brd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); currentY += hgt; String tailString = LanguageResource.getString("TAIL_STR"); @@ -985,7 +985,7 @@ int printDetailedSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) Line2D.Double line = new Line2D.Double(); JavaDraw jd = new JavaDraw(g2d); - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, scale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, scale, 0.0); //Outline Crossection lines g2d.setStroke(linestroke); @@ -1021,8 +1021,8 @@ int printDetailedSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) g2d.setTransform(savedTransform); Stroke stroke = new BasicStroke((float)(1.5/scale)); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, Color.BLACK, stroke, brd.getOutline(), BezierBoardDrawUtil.MirrorY, false); - BezierBoardDrawUtil.paintFins(jd, xm+5, currentY, scale, Color.BLACK, stroke, brd.getFins(), false,false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, 0.0, Color.BLACK, stroke, brd.getOutline(), BezierBoardDrawUtil.MirrorY, false); + BezierBoardDrawUtil.paintFins(jd, xm+5, currentY, scale, 0.0, Color.BLACK, stroke, brd.getFins(), false, false); currentY += (brd.getCenterWidth()/2)*scale + hgt + 5; @@ -1068,7 +1068,7 @@ else if(i == 3) currentY += brd.getMaxRocker()*scale +10; - savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, scale); + savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, scale, 0.0); //Draw lines from numbers g2d.setStroke(linestroke); @@ -1091,8 +1091,8 @@ else if(i == 3) g2d.setTransform(savedTransform); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, Color.BLACK, stroke, brd.getDeck(), BezierBoardDrawUtil.FlipY, false); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, Color.BLACK, stroke, brd.getBottom(), BezierBoardDrawUtil.FlipY, false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, 0.0, Color.BLACK, stroke, brd.getDeck(), BezierBoardDrawUtil.FlipY, false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, scale, 0.0, Color.BLACK, stroke, brd.getBottom(), BezierBoardDrawUtil.FlipY, false); currentY += hgt + 5; @@ -1133,7 +1133,7 @@ else if(i == 3) currentY += brd.getThickness()*scale + 5; - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+width/2, currentY, Math.PI/2.0, scale, Color.BLACK, linestroke, false, true, brd.getLength()/2, brd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+width/2, currentY, scale, Math.PI/2.0, Color.BLACK, linestroke, false, true, brd.getLength()/2, brd); currentY += hgt; @@ -1144,9 +1144,9 @@ else if(i == 3) currentY += hgt+10; //Draw - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((width/3)*1), currentY, Math.PI/2.0, scale, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((width/3)*1), currentY, scale, Math.PI/2.0, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((width/3)*2), currentY, Math.PI/2.0, scale, Color.BLACK, linestroke, false, true, brd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((width/3)*2), currentY, scale, Math.PI/2.0, Color.BLACK, linestroke, false, true, brd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); currentY += hgt; String tailString = LanguageResource.getString("TAIL_STR"); diff --git a/boardcad/print/PrintChamberedWoodTemplate.java b/boardcad/print/PrintChamberedWoodTemplate.java index a9ae42b..06d1174 100644 --- a/boardcad/print/PrintChamberedWoodTemplate.java +++ b/boardcad/print/PrintChamberedWoodTemplate.java @@ -183,10 +183,10 @@ public void paintComponent(Graphics g) { paper.setImageableArea(0,0,dim.width, dim.height); format.setPaper(paper); - BezierBoardDrawUtil.printProfile(jd, border, dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), mPaintGrid,BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, 0.0, false, 0.0, 0.0); - printChambering(jd, border, dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()),BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, mPlankThickness, mDeckAndBottomMinimumThickness); - BezierBoardDrawUtil.printProfile(jd, new Color(200,200,200), 1.0, border, dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), false, BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter + mPlankThickness, 0.0, false, 0.0, 0.0); - printAlignmentMarks(jd, border, dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()),BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, mPlankThickness, mDeckAndBottomMinimumThickness); + BezierBoardDrawUtil.printProfile(jd, border, dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), 0.0, mPaintGrid,BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, 0.0, false, 0.0, 0.0); + printChambering(jd, border, dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), 0.0, BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, mPlankThickness, mDeckAndBottomMinimumThickness); + BezierBoardDrawUtil.printProfile(jd, new Color(200,200,200), 1.0, border, dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), 0.0, false, BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter + mPlankThickness, 0.0, false, 0.0, 0.0); + printAlignmentMarks(jd, border, dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), 0.0, BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, mPlankThickness, mDeckAndBottomMinimumThickness); } @@ -256,23 +256,23 @@ int printTemplate(PageFormat pageFormat, int pageIndex, Graphics g) BezierBoardDrawUtil.printProfile(jd, -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, mPaintGrid,BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, 0.0, false, 0.0, 0.0); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, mPaintGrid,BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, 0.0, false, 0.0, 0.0); if(mDrawChambering) { printChambering(jd, -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54,BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, mPlankThickness, mDeckAndBottomMinimumThickness); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, mPlankThickness, mDeckAndBottomMinimumThickness); BezierBoardDrawUtil.printProfile(jd, new Color(200,200,200), 1.0, -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, false, BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter + mPlankThickness, 0.0, false, 0.0, 0.0); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, false, BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter + mPlankThickness, 0.0, false, 0.0, 0.0); } if(mDrawAlignmentMarks) { printAlignmentMarks(jd, -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, mPlankThickness, mDeckAndBottomMinimumThickness); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, BoardCAD.getInstance().getCurrentBrd(), mOffsetFromCenter, mPlankThickness, mDeckAndBottomMinimumThickness); } return 0; @@ -281,7 +281,7 @@ int printTemplate(PageFormat pageFormat, int pageIndex, Graphics g) return -1; } - public static void printChambering(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double centerOffset, double plankThickness, double deckAndBottomMinimumThickness) + public static void printChambering(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, BezierBoard brd, double centerOffset, double plankThickness, double deckAndBottomMinimumThickness) { if(brd.isEmpty()) { return; @@ -289,7 +289,7 @@ public static void printChambering(AbstractDraw d, double offsetX, double offset System.out.printf("\nCHAMBERING\n"); - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale, rotation); Stroke stroke = new BasicStroke((float)(2.0/scale)); d.setStroke(stroke); d.setColor(new Color(0,0,0)); @@ -370,7 +370,7 @@ public static void printChambering(AbstractDraw d, double offsetX, double offset d.setTransform(savedTransform); } - public static void printAlignmentMarks(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double centerOffset, double plankThickness, double deckAndBottomMinimumThickness) + public static void printAlignmentMarks(AbstractDraw d, double offsetX, double offsetY, double scale, double rotation, BezierBoard brd, double centerOffset, double plankThickness, double deckAndBottomMinimumThickness) { if(brd.isEmpty()) { return; @@ -378,7 +378,7 @@ public static void printAlignmentMarks(AbstractDraw d, double offsetX, double of System.out.printf("\nALIGNMENT MARKS\n"); - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale, rotation); Stroke stroke = new BasicStroke((float)(1.0/scale)); d.setStroke(stroke); d.setColor(new Color(255,20,20)); @@ -395,8 +395,8 @@ public static void printAlignmentMarks(AbstractDraw d, double offsetX, double of double x = i*UnitUtils.FOOT; //Check if there is some template to draw upon - double deck = BezierBoardDrawUtil.getDeck(brd, x, y, deckAndBottomMinimumThickness); - double bottom = BezierBoardDrawUtil.getBottom(brd, x, y, deckAndBottomMinimumThickness); + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, x, y, deckAndBottomMinimumThickness); + double bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation(brd, x, y, deckAndBottomMinimumThickness); if(deck < bottom) { diff --git a/boardcad/print/PrintHollowWoodTemplates.java b/boardcad/print/PrintHollowWoodTemplates.java index 4e285d3..3c072f4 100644 --- a/boardcad/print/PrintHollowWoodTemplates.java +++ b/boardcad/print/PrintHollowWoodTemplates.java @@ -33,1281 +33,1610 @@ import javax.swing.BorderFactory; import javax.swing.JComponent; -import board.BezierBoard; +import org.ujmp.core.util.MathUtil; +import board.BezierBoard; import cadcore.BezierSpline; +import cadcore.MathUtils; import cadcore.UnitUtils; import boardcad.AbstractDraw; import boardcad.i18n.LanguageResource; - import boardcad.gui.jdk.*; public class PrintHollowWoodTemplates extends JComponent implements Printable { - static final long serialVersionUID=1L; + static final long serialVersionUID = 1L; - private PageFormat myPageFormat; - private PrinterJob myPrintJob; + private PageFormat myPageFormat; + private PrinterJob myPrintJob; - protected enum PrintState {NO_STATE, - PRINT_DECKSKIN_TEMPLATE, - PRINT_BOTTOMSKIN_TEMPLATE, - PRINT_RAIL_TEMPLATE, - PRINT_STRINGER_TEMPLATE, - PRINT_CROSSSECTION_TEMPLATES, - - - PRINT_NOSE_SECTION_TEMPLATE, - PRINT_TAIL_SECTION_TEMPLATE + protected enum PrintState { + NO_STATE, PRINT_DECKSKIN_TEMPLATE, PRINT_BOTTOMSKIN_TEMPLATE, PRINT_RAIL_TEMPLATE, PRINT_STRINGER_TEMPLATE, PRINT_CROSSSECTION_TEMPLATES, + + PRINT_NOSE_SECTION_TEMPLATE, PRINT_TAIL_SECTION_TEMPLATE }; public PrintState mCurrentPrintState; - + private Font mPrintFontSmall = new Font("Dialog", Font.PLAIN, 10); private double mSkinThickness = 0.5; private double mFrameThickness = 0.5; - private double mWebbing = 2.0; - private double mDistanceToRail = 3.5; + private double mWebbing = 1.5; + private double mDistanceToRail = 5.0; private double mTailOffset = 4.0; private double mNoseOffset = 4.0; private double mCrosssectionPos = 3.0; - /** Creates and initializes the ClickMe component. */ public PrintHollowWoodTemplates() { -// Hint at good sizes for this component. + // Hint at good sizes for this component. setPreferredSize(new Dimension(800, 600)); setMinimumSize(new Dimension(600, 480)); -// Request a black line around this component. + // Request a black line around this component. setBorder(BorderFactory.createLineBorder(Color.BLACK)); } + /** + * + * Paints the PrintBrd component. This method is + * + * invoked by the Swing component-painting system. + */ + public void paintComponent(Graphics g) { - public BezierBoard getBrd() { + /** + * + * Copy the graphics context so we can change it. + * + * Cast it to Graphics2D so we can use antialiasing. + */ - return BoardCAD.getInstance().getCurrentBrd(); + Graphics2D g2d = (Graphics2D) g.create(); + + // Turn on antialiasing, so painting is smooth. + + g2d.setRenderingHint( + + RenderingHints.KEY_ANTIALIASING, + + RenderingHints.VALUE_ANTIALIAS_ON); + + // Paint the background. + + g2d.setColor(Color.WHITE); + + g2d.fillRect(0, 0, getWidth() - 1, getHeight() - 1); + + Dimension dim = getSize(); + double border = 30; + + if (BoardCAD.getInstance().getCurrentBrd() == null + || BoardCAD.getInstance().getCurrentBrd().isEmpty()) + return; + + JavaDraw jd = new JavaDraw(g2d); + + // BezierBoardDrawUtil.printRailTemplate(jd, border, dim.height*offset2, + // (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), + // true,BoardCAD.getInstance().getCurrentBrd(), 5.0, 0.8, 8.0, 15.0, + // trues); + // BezierBoardDrawUtil.printDeckSkinTemplate(jd, border, + // dim.height*offset3, + // (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), + // true,BoardCAD.getInstance().getCurrentBrd(), 3.0); + // BezierBoardDrawUtil.printBottomSkinTemplate(jd, border, + // dim.height*4.0/5.0, + // (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), + // true,BoardCAD.getInstance().getCurrentBrd(), 3.0); + // BezierBoardDrawUtil.printCrossSection(jd, border, dim.height*offset2, + // (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), + // true,BoardCAD.getInstance().getCurrentBrd(), 50.0, 3.0, 0.8); + // BezierBoardDrawUtil.printCrossSection(jd, border, dim.height*offset2, + // (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), + // true,BoardCAD.getInstance().getCurrentBrd(), 50.0); + // BezierBoardDrawUtil.printProfile(jd, border, dim.height*offset2, + // (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), + // true,BoardCAD.getInstance().getCurrentBrd(), 0.0, 0.0, false); + // BezierBoardDrawUtil.printProfile(jd, border, dim.height*offset2, + // (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), + // true,BoardCAD.getInstance().getCurrentBrd(), 5.0, 0.0, false); + // BezierBoardDrawUtil.printProfile(jd, border, dim.height*offset2, + // (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), + // true,BoardCAD.getInstance().getCurrentBrd(), 20.0, 0.0, false); + + double offset1 = 1.0 / 5.0; + double offset2 = 2.0 / 5.0; + double offset3 = 3.0 / 5.0; + + double scale = (dim.width - (border * 2)) + / (BoardCAD.getInstance().getCurrentBrd().getLength()); + + + //Print stringer + printStringerDebug(jd, border, dim.height * offset3, + scale, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), 0.0, + mSkinThickness, false, mTailOffset, mNoseOffset); + + + /* + * //Print crosssections printCrossSections(jd, border + 200, + * dim.height*offset2, scale, 0.0, + * BoardCAD.getInstance().getCurrentBrd(), UnitUtils.INCH, + * mSkinThickness, mFrameThickness, mWebbing, false); + */ + + // Print rails + BezierBoardDrawUtil.printRailTemplate(jd, border, dim.height * offset3, + scale, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), + mDistanceToRail, mSkinThickness, mTailOffset, mNoseOffset, + false); + + printRailWebbing(jd, border, dim.height * offset3, scale, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset); + + printRailNotching(jd, border, dim.height * offset3, scale, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset); + + // TODO: Needs fixing + printRailTailPieceNotches(jd, border, dim.height * offset3, scale, + 0.0, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset); + /* + * printRailNosePieceNotches(jd, border, dim.height * offset3, scale, + * 0.0, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + * mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); + */ + + /* + * //Print tail piece printTailPiece(jd, border, dim.height * offset3, + * scale, 0.0, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + * mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset, + * false); + * + * printTailPiece(jd, border, dim.height * offset3, scale, 0.0, + * BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + * mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset, + * true); + * + * printTailPieceWebbing(jd, border, dim.height * offset3, scale, 0.0, + * BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + * mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset, + * false); + * + * printTailPieceWebbing(jd, border, dim.height * offset3, scale, 0.0, + * BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + * mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset, + * true); + */ + + /* + * //Print nose piece printNosePiece(jd, border+300, dim.height * + * offset3, scale, 0.0, BoardCAD.getInstance().getCurrentBrd(), + * mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, + * mTailOffset, mNoseOffset, false); + * + * printNosePiece(jd, border+300, dim.height * offset3, scale, 0.0, + * BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + * mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset, + * true); + * + * printNosePieceWebbing(jd, border+300, dim.height * offset3, scale, + * 0.0, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + * mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset, + * false); + * + * printNosePieceWebbing(jd, border+300, dim.height * offset3, scale, + * 0.0, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + * mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset, + * true); + */ } - - void initPrint() - { - myPrintJob = PrinterJob.getPrinterJob(); - myPageFormat = PrintBrd.getPageFormat(this, myPrintJob, BoardCAD.getInstance().getCurrentBrd().getMaxRocker()); - if(myPageFormat == null) - return; - - - myPrintJob.setPrintable(this,myPageFormat); - } + void printStringerDebug(AbstractDraw d, double offsetX, double offsetY, + double scale, double rotation, boolean paintGrid, BezierBoard brd, + double offset, double skinThickness, boolean flatten, + double tailOffset, double noseOffset) { + + // Print stringer + BezierBoardDrawUtil.printProfile(d, offsetX, offsetY, scale, rotation, + paintGrid, brd, offset, skinThickness, flatten, tailOffset, + noseOffset); + /* + * BezierBoardDrawUtil.printProfile(jd, border, dim.height*offset2, + * (dim. + * width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength + * ()), 0.0, true, BoardCAD.getInstance().getCurrentBrd(), 0.0, + * mSkinThickness, false, 0.0, 0.0); + * + * BezierBoardDrawUtil.printProfile(jd, border, dim.height*offset2, + * (dim. + * width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength + * ()), 0.0, true, BoardCAD.getInstance().getCurrentBrd(), 0.0, 0.0, + * false, 0.0, 0.0); + */ + printStringerWebbing(d, offsetX, offsetY, scale, rotation, brd, + mSkinThickness, mFrameThickness, mWebbing); - public void printStringerTemplate(double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset) { + printStringerTailPieceCutOut(d, offsetX, offsetY, scale, rotation, brd, + mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, + mTailOffset, mNoseOffset); - initPrint(); + printStringerNosePieceCutOut(d, offsetX, offsetY, scale, rotation, brd, + mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, + mTailOffset, mNoseOffset); - try { + } - mSkinThickness = skinThickness; - mFrameThickness = frameThickness; - mWebbing = webbing; - mCurrentPrintState = PrintState.PRINT_STRINGER_TEMPLATE; + void printCrossSectionsDebug(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double railDistance, double skinThickness, double frameThickness, + double webbing, boolean mirror) { + double crossSectionPos = 1 * UnitUtils.FOOT; - myPrintJob.print(); + while (crossSectionPos < brd.getLength()) { + printCrossSection(d, offsetX, offsetY, scale, rotation, brd, + crossSectionPos, railDistance, skinThickness, + frameThickness, webbing, mirror); - } catch(PrinterException pe) { + printCrossSection(d, offsetX, offsetY, scale, rotation, brd, + crossSectionPos, railDistance, skinThickness, + frameThickness, webbing, mirror); - System.out.println("Error printing: " + pe); + printCrossSectionWebbing(d, offsetX, offsetY, scale, rotation, brd, + crossSectionPos, railDistance, skinThickness, + frameThickness, webbing, mirror); - } + printCrossSectionWebbing(d, offsetX, offsetY, scale, rotation, brd, + crossSectionPos, railDistance, skinThickness, + frameThickness, webbing, mirror); + crossSectionPos += UnitUtils.FOOT; + offsetY += scale * 10; } + } - public void printRailTemplate(double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset) - { - initPrint(); + public BezierBoard getBrd() { - try { + return BoardCAD.getInstance().getCurrentBrd(); - mDistanceToRail = distanceFromRail; - mSkinThickness = skinThickness; - mFrameThickness = frameThickness; - mWebbing = webbing; - mTailOffset = tailOffset; - mNoseOffset = noseOffset; - mCurrentPrintState = PrintState.PRINT_RAIL_TEMPLATE; + } - myPrintJob.print(); + void initPrint() { + myPrintJob = PrinterJob.getPrinterJob(); - } catch(PrinterException pe) { + myPageFormat = PrintBrd.getPageFormat(this, myPrintJob, BoardCAD + .getInstance().getCurrentBrd().getMaxRocker()); + if (myPageFormat == null) + return; - System.out.println("Error printing: " + pe); + myPrintJob.setPrintable(this, myPageFormat); + } - } + public void printStringerTemplate(double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset) { - } + initPrint(); - public void printDeckSkinTemplate(double distanceFromRail, double tailOffset, double noseOffset) { + try { - initPrint(); + mSkinThickness = skinThickness; + mFrameThickness = frameThickness; + mWebbing = webbing; + mCurrentPrintState = PrintState.PRINT_STRINGER_TEMPLATE; - try { + myPrintJob.print(); - mDistanceToRail = distanceFromRail; - mTailOffset = tailOffset; - mNoseOffset = noseOffset; - mCurrentPrintState = PrintState.PRINT_DECKSKIN_TEMPLATE; + } catch (PrinterException pe) { - myPrintJob.print(); + System.out.println("Error printing: " + pe); + + } - } catch(PrinterException pe) { + } - System.out.println("Error printing: " + pe); + public void printRailTemplate(double distanceFromRail, + double skinThickness, double frameThickness, double webbing, + double tailOffset, double noseOffset) { + initPrint(); - } + try { + + mDistanceToRail = distanceFromRail; + mSkinThickness = skinThickness; + mFrameThickness = frameThickness; + mWebbing = webbing; + mTailOffset = tailOffset; + mNoseOffset = noseOffset; + mCurrentPrintState = PrintState.PRINT_RAIL_TEMPLATE; + + myPrintJob.print(); + + } catch (PrinterException pe) { + + System.out.println("Error printing: " + pe); } - public void printBottomSkinTemplate(double distanceFromRail, double tailOffset, double noseOffset) { + } - initPrint(); + public void printDeckSkinTemplate(double distanceFromRail, + double tailOffset, double noseOffset) { - try { + initPrint(); - mDistanceToRail = distanceFromRail; - mTailOffset = tailOffset; - mNoseOffset = noseOffset; - mCurrentPrintState = PrintState.PRINT_BOTTOMSKIN_TEMPLATE; + try { - myPrintJob.print(); + mDistanceToRail = distanceFromRail; + mTailOffset = tailOffset; + mNoseOffset = noseOffset; + mCurrentPrintState = PrintState.PRINT_DECKSKIN_TEMPLATE; - } catch(PrinterException pe) { + myPrintJob.print(); - System.out.println("Error printing: " + pe); + } catch (PrinterException pe) { - } + System.out.println("Error printing: " + pe); } - - public void printCrosssectionTemplates(double distanceFromRail, double skinThickness, double frameThickness, double webbing) { - - initPrint(); - - try { - - mDistanceToRail = distanceFromRail; - mSkinThickness = skinThickness; - mFrameThickness = frameThickness; - mWebbing = webbing; - mCurrentPrintState = PrintState.PRINT_CROSSSECTION_TEMPLATES; - - int nrOfCrossSections = (int)((BoardCAD.getInstance().getCurrentBrd().getLength() - 9.0*UnitUtils.INCH)/UnitUtils.FOOT); - - for(int i = 0; i < nrOfCrossSections; i++) - { - mCrosssectionPos = (i+1)* UnitUtils.FOOT; - myPrintJob.print(); - } - - } catch(PrinterException pe) { - - System.out.println("Error printing: " + pe); - - } - - } - public void printNoseTemplate(double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset) { - - initPrint(); - - try { - - mDistanceToRail = distanceFromRail; - mSkinThickness = skinThickness; - mFrameThickness = frameThickness; - mWebbing = webbing; - mTailOffset = tailOffset; - mNoseOffset = noseOffset; - mCurrentPrintState = PrintState.PRINT_TAIL_SECTION_TEMPLATE; - - myPrintJob.print(); - - } catch(PrinterException pe) { - - System.out.println("Error printing: " + pe); - - } - - } + } + + public void printBottomSkinTemplate(double distanceFromRail, + double tailOffset, double noseOffset) { + + initPrint(); + + try { + + mDistanceToRail = distanceFromRail; + mTailOffset = tailOffset; + mNoseOffset = noseOffset; + mCurrentPrintState = PrintState.PRINT_BOTTOMSKIN_TEMPLATE; + + myPrintJob.print(); + + } catch (PrinterException pe) { + + System.out.println("Error printing: " + pe); - public void printTailTemplate(double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset) { - - initPrint(); - - try { - - mDistanceToRail = distanceFromRail; - mSkinThickness = skinThickness; - mFrameThickness = frameThickness; - mWebbing = webbing; - mTailOffset = tailOffset; - mNoseOffset = noseOffset; - mCurrentPrintState = PrintState.PRINT_TAIL_SECTION_TEMPLATE; - - myPrintJob.print(); - - } catch(PrinterException pe) { - - System.out.println("Error printing: " + pe); - - } - } - /** - * Paints the PrintBrd component. This method is + } - * invoked by the Swing component-painting system. + public void printCrosssectionTemplates(double distanceFromRail, + double skinThickness, double frameThickness, double webbing) { - */ + initPrint(); - public void paintComponent(Graphics g) { + try { - /** + mDistanceToRail = distanceFromRail; + mSkinThickness = skinThickness; + mFrameThickness = frameThickness; + mWebbing = webbing; + mCurrentPrintState = PrintState.PRINT_CROSSSECTION_TEMPLATES; - * Copy the graphics context so we can change it. + int nrOfCrossSections = (int) ((BoardCAD.getInstance() + .getCurrentBrd().getLength() - 9.0 * UnitUtils.INCH) / UnitUtils.FOOT); - * Cast it to Graphics2D so we can use antialiasing. + for (int i = 0; i < nrOfCrossSections; i++) { + mCrosssectionPos = (i + 1) * UnitUtils.FOOT; + myPrintJob.print(); + } - */ + } catch (PrinterException pe) { - Graphics2D g2d = (Graphics2D)g.create(); + System.out.println("Error printing: " + pe); + } + } -// Turn on antialiasing, so painting is smooth. + public void printNoseTemplate(double distanceFromRail, + double skinThickness, double frameThickness, double webbing, + double tailOffset, double noseOffset) { - g2d.setRenderingHint( + initPrint(); - RenderingHints.KEY_ANTIALIASING, + try { - RenderingHints.VALUE_ANTIALIAS_ON); + mDistanceToRail = distanceFromRail; + mSkinThickness = skinThickness; + mFrameThickness = frameThickness; + mWebbing = webbing; + mTailOffset = tailOffset; + mNoseOffset = noseOffset; + mCurrentPrintState = PrintState.PRINT_NOSE_SECTION_TEMPLATE; + myPrintJob.print(); + } catch (PrinterException pe) { -// Paint the background. + System.out.println("Error printing: " + pe); - g2d.setColor(Color.WHITE); + } - g2d.fillRect(0, 0, getWidth() - 1, getHeight() - 1); + } - Dimension dim = getSize(); + public void printTailTemplate(double distanceFromRail, + double skinThickness, double frameThickness, double webbing, + double tailOffset, double noseOffset) { - double border = 10; + initPrint(); - if(BoardCAD.getInstance().getCurrentBrd() == null || BoardCAD.getInstance().getCurrentBrd().isEmpty()) - return; - - JavaDraw jd = new JavaDraw(g2d); + try { -// BezierBoardDrawUtil.printRailTemplate(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 5.0, 0.8, 8.0, 15.0, trues); -// BezierBoardDrawUtil.printDeckSkinTemplate(jd, border, dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 3.0); -// BezierBoardDrawUtil.printBottomSkinTemplate(jd, border, dim.height*4.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 3.0); -// BezierBoardDrawUtil.printCrossSection(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 50.0, 3.0, 0.8); -// BezierBoardDrawUtil.printCrossSection(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 50.0); -// BezierBoardDrawUtil.printProfile(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 0.0, 0.0, false); -// BezierBoardDrawUtil.printProfile(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 5.0, 0.0, false); -// BezierBoardDrawUtil.printProfile(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 20.0, 0.0, false); + mDistanceToRail = distanceFromRail; + mSkinThickness = skinThickness; + mFrameThickness = frameThickness; + mWebbing = webbing; + mTailOffset = tailOffset; + mNoseOffset = noseOffset; + mCurrentPrintState = PrintState.PRINT_TAIL_SECTION_TEMPLATE; - + myPrintJob.print(); + } catch (PrinterException pe) { - BezierBoardDrawUtil.printProfile(jd, - border, - dim.height*1.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true, BoardCAD.getInstance().getCurrentBrd(), 0.0, mSkinThickness, false, mTailOffset, mNoseOffset); -/* - BezierBoardDrawUtil.printProfile(jd, - border, - dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true, BoardCAD.getInstance().getCurrentBrd(), 0.0, mSkinThickness, false, 0.0, 0.0); - - BezierBoardDrawUtil.printProfile(jd, - border, - dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true, BoardCAD.getInstance().getCurrentBrd(), 0.0, 0.0, false, 0.0, 0.0); - - printStringerWebbing(jd, - border, - dim.height*1.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mSkinThickness, mFrameThickness, mWebbing); - */ - printStringerTailPieceCutOut(jd, - border, - dim.height*1.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); - - printStringerNosePieceCutOut(jd, - border, - dim.height*1.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); - -/* printCrossSection(jd, - border, - dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), 3*UnitUtils.FOOT, 2*UnitUtils.INCH, mSkinThickness, mFrameThickness, mWebbing, false); - - printCrossSection(jd, - border, - dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), 3*UnitUtils.FOOT, 2*UnitUtils.INCH, mSkinThickness, mFrameThickness, mWebbing, true); + System.out.println("Error printing: " + pe); - printCrossSectionWebbing(jd, - border, - dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), 3*UnitUtils.FOOT, 2*UnitUtils.INCH, mSkinThickness, mFrameThickness, mWebbing, false); + } - printCrossSectionWebbing(jd, - border, - dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), 3*UnitUtils.FOOT, 2*UnitUtils.INCH, mSkinThickness, mFrameThickness, mWebbing, true); + } + public int print(Graphics g, PageFormat pageFormat, int pageIndex) { - - BezierBoardDrawUtil.printRailTemplate(jd, - border, - dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mTailOffset, mNoseOffset, false); + /* + * DEBUG!!! + * + * if(pageIndex >=2) + * + * { + * + * isPrintingProfile = false; + * + * isPrintingOutline = false; + * + * return NO_SUCH_PAGE; + * + * } + */ - printRailWebbing(jd, - border, - dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); - - printRailNotching(jd, - border, - dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); + switch (mCurrentPrintState) { - printRailTailPieceNotches(jd, - border, - dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); + case PRINT_STRINGER_TEMPLATE: { + if (printStringerTemplate(pageFormat, pageIndex, g) == 0) + return PAGE_EXISTS; - printRailNosePieceNotches(jd, - border, - dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); - - - printTailPiece(jd, - border, - dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, false); + break; + } - printTailPiece(jd, - border, - dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, true); - - printTailPieceWebbing(jd, - border, - dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, false); + case PRINT_RAIL_TEMPLATE: { + if (printRailTemplate(pageFormat, pageIndex, g) == 0) + return PAGE_EXISTS; - printTailPieceWebbing(jd, - border, - dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, true); - - -*/ - printNosePiece(jd, - border, - dim.height*3.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset, false); -/* - printNosePiece(jd, - border, - dim.height*3.0/5.0, 3*(dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mNoseOffset, true); - - printNosePieceWebbing(jd, - border, - dim.height*3.0/5.0, 3*(dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mNoseOffset, false); - - printNosePieceWebbing(jd, - border, - dim.height*3.0/5.0, 3*(dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mNoseOffset, true); - */ -} + break; + } + case PRINT_DECKSKIN_TEMPLATE: { + if (printDeckSkinTemplate(pageFormat, pageIndex, g) == 0) + return PAGE_EXISTS; + break; + } - public int print(Graphics g, PageFormat pageFormat, int pageIndex) { + case PRINT_BOTTOMSKIN_TEMPLATE: { + if (printBottomSkinTemplate(pageFormat, pageIndex, g) == 0) + return PAGE_EXISTS; + break; + } + case PRINT_CROSSSECTION_TEMPLATES: { + if (printCrosssectionTemplate(pageFormat, pageIndex, g) == 0) + return PAGE_EXISTS; - - /*DEBUG!!! - - if(pageIndex >=2) - - { - - isPrintingProfile = false; - - isPrintingOutline = false; - - return NO_SUCH_PAGE; - - } - - */ - - switch(mCurrentPrintState) - { - - case PRINT_STRINGER_TEMPLATE: - { - if(printStringerTemplate(pageFormat, pageIndex, g) == 0) - return PAGE_EXISTS; - - break; - } - - case PRINT_RAIL_TEMPLATE: - { - if(printRailTemplate(pageFormat, pageIndex, g) == 0) - return PAGE_EXISTS; - - break; - } + break; + } + case PRINT_NOSE_SECTION_TEMPLATE: { + if (printNosePieceTemplate(pageFormat, pageIndex, g) == 0) + return PAGE_EXISTS; - case PRINT_DECKSKIN_TEMPLATE: - { - if(printDeckSkinTemplate(pageFormat, pageIndex, g) == 0) - return PAGE_EXISTS; - - break; - } + break; + } + case PRINT_TAIL_SECTION_TEMPLATE: { + if (printTailPieceTemplate(pageFormat, pageIndex, g) == 0) + return PAGE_EXISTS; - case PRINT_BOTTOMSKIN_TEMPLATE: - { - if(printBottomSkinTemplate(pageFormat, pageIndex, g) == 0) - return PAGE_EXISTS; - - break; - } - case PRINT_CROSSSECTION_TEMPLATES: - { - if(printCrosssectionTemplate(pageFormat, pageIndex, g) == 0) - return PAGE_EXISTS; - - break; - } + break; } - + } + return NO_SUCH_PAGE; - + } - - int printStringerTemplate(PageFormat pageFormat, int pageIndex, Graphics g) - { - System.out.printf("printStringerTemplate() Page width: %f, page height: %f, orientation: %s, Margins x:%f, y: %f\n", pageFormat.getImageableWidth(), pageFormat.getImageableHeight(), pageFormat.getOrientation() == PageFormat.LANDSCAPE?"Landscape":"Portrait", pageFormat.getImageableX(), pageFormat.getImageableY()); + + int printStringerTemplate(PageFormat pageFormat, int pageIndex, Graphics g) { + System.out + .printf("printStringerTemplate() Page width: %f, page height: %f, orientation: %s, Margins x:%f, y: %f\n", + pageFormat.getImageableWidth(), + pageFormat.getImageableHeight(), + pageFormat.getOrientation() == PageFormat.LANDSCAPE ? "Landscape" + : "Portrait", pageFormat.getImageableX(), + pageFormat.getImageableY()); double width = pageFormat.getImageableWidth(); double height = pageFormat.getImageableHeight(); - - int widthInPages = (int)(BoardCAD.getInstance().getCurrentBrd().getLength() - / ((width/72)*2.54) ) + 2; - - int heightInPages = (int)(BoardCAD.getInstance().getCurrentBrd().getMaxRocker() - / ((height/72)*2.54)) + 1; - + + int widthInPages = (int) (BoardCAD.getInstance().getCurrentBrd() + .getLength() / ((width / 72) * 2.54)) + 2; + + int heightInPages = (int) (BoardCAD.getInstance().getCurrentBrd() + .getMaxRocker() / ((height / 72) * 2.54)) + 1; + int xm = 0; int ym = 0; - xm = (int)pageFormat.getImageableX(); - ym = (int)pageFormat.getImageableY(); + xm = (int) pageFormat.getImageableX(); + ym = (int) pageFormat.getImageableY(); System.out.printf("Width: %f, Height: %f\n", width, height); - - if (pageIndex < widthInPages*heightInPages) { - - Graphics2D g2d = (Graphics2D)g; + + if (pageIndex < widthInPages * heightInPages) { + + Graphics2D g2d = (Graphics2D) g; g2d.setFont(mPrintFontSmall); - + FontMetrics metrics = g2d.getFontMetrics(mPrintFontSmall); // get the height of a line of text in this font and render context int hgt = metrics.getHeight(); - - String mModelString = LanguageResource.getString("BOARDFILE_STR") + BoardCAD.getInstance().getCurrentBrd().getFilename() + LanguageResource.getString("STRINGER_STR"); - String mRowString = LanguageResource.getString("ROW_STR")+ ((pageIndex%widthInPages)+1) + "/" + widthInPages; - String mColumnString = LanguageResource.getString("COLUMN_STR") + ((pageIndex/widthInPages)+1) + "/" + heightInPages; - + + String mModelString = LanguageResource.getString("BOARDFILE_STR") + + BoardCAD.getInstance().getCurrentBrd().getFilename() + + LanguageResource.getString("STRINGER_STR"); + String mRowString = LanguageResource.getString("ROW_STR") + + ((pageIndex % widthInPages) + 1) + "/" + widthInPages; + String mColumnString = LanguageResource.getString("COLUMN_STR") + + ((pageIndex / widthInPages) + 1) + "/" + heightInPages; + g2d.setColor(Color.BLACK); - //g2d.setStroke(new BasicStroke((float)(1.0/mScale))); - g.drawString(mModelString, xm, ym+(hgt+2)*1); - g.drawString(mRowString, xm, ym+(hgt+2)*2); - g.drawString(mColumnString, xm, ym+(hgt+2)*3); - - g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); - - BezierBoardDrawUtil.printProfile(new JavaDraw(g2d), - -width*(pageIndex%widthInPages), - -height*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), 0.0, mSkinThickness, false, mTailOffset, mNoseOffset); - - printStringerWebbing(new JavaDraw(g2d), - -width*(pageIndex%widthInPages), - -height*(pageIndex/widthInPages), 72/2.54, BoardCAD.getInstance().getCurrentBrd(), mSkinThickness, mFrameThickness, mWebbing); - + // g2d.setStroke(new BasicStroke((float)(1.0/mScale))); + g.drawString(mModelString, xm, ym + (hgt + 2) * 1); + g.drawString(mRowString, xm, ym + (hgt + 2) * 2); + g.drawString(mColumnString, xm, ym + (hgt + 2) * 3); + + g2d.translate(pageFormat.getImageableX(), + pageFormat.getImageableY()); + + BezierBoardDrawUtil.printProfile(new JavaDraw(g2d), -width + * (pageIndex % widthInPages), -height + * (pageIndex / widthInPages), 72 / 2.54, 0.0, true, + BoardCAD.getInstance().getCurrentBrd(), 0.0, + mSkinThickness, false, mTailOffset, mNoseOffset); + + printStringerWebbing(new JavaDraw(g2d), -width + * (pageIndex % widthInPages), -height + * (pageIndex / widthInPages), 72 / 2.54, 0.0, BoardCAD + .getInstance().getCurrentBrd(), mSkinThickness, + mFrameThickness, mWebbing); + printStringerTailPieceCutOut(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset); printStringerNosePieceCutOut(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); - + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset); + return 0; } - + return -1; } - int printRailTemplate(PageFormat pageFormat, int pageIndex, Graphics g) - { - int widthInPages = (int)((BoardCAD.getInstance().getCurrentBrd().getLength() - (mNoseOffset + mTailOffset) + 7.5) - / ((pageFormat.getImageableWidth()/72)*2.54) ) + 1; - - int heightInPages = (int)(BoardCAD.getInstance().getCurrentBrd().getMaxRocker() - / ((pageFormat.getImageableHeight()/72)*2.54)) + 1; - - int xm = (int)pageFormat.getImageableX(); - int ym = (int)pageFormat.getImageableY(); - - if (pageIndex < widthInPages*heightInPages) { - - Graphics2D g2d = (Graphics2D)g; + int printRailTemplate(PageFormat pageFormat, int pageIndex, Graphics g) { + int widthInPages = (int) ((BoardCAD.getInstance().getCurrentBrd() + .getLength() + - (mNoseOffset + mTailOffset) + 7.5) / ((pageFormat + .getImageableWidth() / 72) * 2.54)) + 1; + + int heightInPages = (int) (BoardCAD.getInstance().getCurrentBrd() + .getMaxRocker() / ((pageFormat.getImageableHeight() / 72) * 2.54)) + 1; + + int xm = (int) pageFormat.getImageableX(); + int ym = (int) pageFormat.getImageableY(); + + if (pageIndex < widthInPages * heightInPages) { + + Graphics2D g2d = (Graphics2D) g; g2d.setFont(mPrintFontSmall); - + FontMetrics metrics = g2d.getFontMetrics(mPrintFontSmall); // get the height of a line of text in this font and render context int hgt = metrics.getHeight(); - - String mModelString = LanguageResource.getString("BOARDFILE_STR") + BoardCAD.getInstance().getCurrentBrd().getFilename() + " "+ LanguageResource.getString("PRINTHWSRAIL_STR"); - String mRowString = LanguageResource.getString("ROW_STR") + ((pageIndex%widthInPages)+1) + "/" + widthInPages; - String mColumnString = LanguageResource.getString("COLUMN_STR") + ((pageIndex/widthInPages)+1) + "/" + heightInPages; - + + String mModelString = LanguageResource.getString("BOARDFILE_STR") + + BoardCAD.getInstance().getCurrentBrd().getFilename() + + " " + LanguageResource.getString("PRINTHWSRAIL_STR"); + String mRowString = LanguageResource.getString("ROW_STR") + + ((pageIndex % widthInPages) + 1) + "/" + widthInPages; + String mColumnString = LanguageResource.getString("COLUMN_STR") + + ((pageIndex / widthInPages) + 1) + "/" + heightInPages; + g2d.setColor(Color.BLACK); - //g2d.setStroke(new BasicStroke((float)(1.0/mScale))); - g.drawString(mModelString, xm, ym+(hgt+2)*1); - g.drawString(mRowString, xm, ym+(hgt+2)*2); - g.drawString(mColumnString, xm, ym+(hgt+2)*3); - - g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); - - BezierBoardDrawUtil.printRailTemplate(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mTailOffset, mNoseOffset, false); + // g2d.setStroke(new BasicStroke((float)(1.0/mScale))); + g.drawString(mModelString, xm, ym + (hgt + 2) * 1); + g.drawString(mRowString, xm, ym + (hgt + 2) * 2); + g.drawString(mColumnString, xm, ym + (hgt + 2) * 3); + + g2d.translate(pageFormat.getImageableX(), + pageFormat.getImageableY()); - printRailWebbing(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); + BezierBoardDrawUtil.printRailTemplate(new JavaDraw(g2d), + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, true, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mTailOffset, mNoseOffset, false); + + printRailWebbing(new JavaDraw(g2d), -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset); printRailNotching(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset); printRailNosePieceNotches(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset); printRailTailPieceNotches(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, mTailOffset, mNoseOffset); + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset); return 0; } - + return -1; } - int printDeckSkinTemplate(PageFormat pageFormat, int pageIndex, Graphics g) - { - int widthInPages = (int)(BoardCAD.getInstance().getCurrentBrd().getLength() - / ((pageFormat.getImageableWidth()/72)*2.54) ) + 2; - - int heightInPages = (int)((BoardCAD.getInstance().getCurrentBrd().getMaxWidth()/2.0) - / ((pageFormat.getImageableHeight()/72)*2.54)) + 1; - - int xm = (int)pageFormat.getImageableX(); - int ym = (int)pageFormat.getImageableY(); - - if (pageIndex < widthInPages*heightInPages) { - - Graphics2D g2d = (Graphics2D)g; + int printDeckSkinTemplate(PageFormat pageFormat, int pageIndex, Graphics g) { + int widthInPages = (int) (BoardCAD.getInstance().getCurrentBrd() + .getLength() / ((pageFormat.getImageableWidth() / 72) * 2.54)) + 2; + + int heightInPages = (int) ((BoardCAD.getInstance().getCurrentBrd() + .getMaxWidth() / 2.0) / ((pageFormat.getImageableHeight() / 72) * 2.54)) + 1; + + int xm = (int) pageFormat.getImageableX(); + int ym = (int) pageFormat.getImageableY(); + + if (pageIndex < widthInPages * heightInPages) { + + Graphics2D g2d = (Graphics2D) g; g2d.setFont(mPrintFontSmall); - + FontMetrics metrics = g2d.getFontMetrics(mPrintFontSmall); // get the height of a line of text in this font and render context int hgt = metrics.getHeight(); - - String mModelString =LanguageResource.getString("BOARDFILE_STR") + BoardCAD.getInstance().getCurrentBrd().getFilename() + LanguageResource.getString("DECKSKINTEMPLATE_STR"); - String mRowString = LanguageResource.getString("ROW_STR") + ((pageIndex%widthInPages)+1) + "/" + widthInPages; - String mColumnString = LanguageResource.getString("COLUMN_STR") + ((pageIndex/widthInPages)+1) + "/" + heightInPages; - + + String mModelString = LanguageResource.getString("BOARDFILE_STR") + + BoardCAD.getInstance().getCurrentBrd().getFilename() + + LanguageResource.getString("DECKSKINTEMPLATE_STR"); + String mRowString = LanguageResource.getString("ROW_STR") + + ((pageIndex % widthInPages) + 1) + "/" + widthInPages; + String mColumnString = LanguageResource.getString("COLUMN_STR") + + ((pageIndex / widthInPages) + 1) + "/" + heightInPages; + g2d.setColor(Color.BLACK); - //g2d.setStroke(new BasicStroke((float)(1.0/mScale))); - g.drawString(mModelString, xm, ym+(hgt+2)*1); - g.drawString(mRowString, xm, ym+(hgt+2)*2); - g.drawString(mColumnString, xm, ym+(hgt+2)*3); - - g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); - - - + // g2d.setStroke(new BasicStroke((float)(1.0/mScale))); + g.drawString(mModelString, xm, ym + (hgt + 2) * 1); + g.drawString(mRowString, xm, ym + (hgt + 2) * 2); + g.drawString(mColumnString, xm, ym + (hgt + 2) * 3); + + g2d.translate(pageFormat.getImageableX(), + pageFormat.getImageableY()); + BezierBoardDrawUtil.printDeckSkinTemplate(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail); - + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, true, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail); + return 0; } - + return -1; } - - int printBottomSkinTemplate(PageFormat pageFormat, int pageIndex, Graphics g) - { - int widthInPages = (int)(BoardCAD.getInstance().getCurrentBrd().getLength() - / ((pageFormat.getImageableWidth()/72)*2.54) ) + 2; - - int heightInPages = (int)((BoardCAD.getInstance().getCurrentBrd().getMaxWidth()/2.0) - / ((pageFormat.getImageableHeight()/72)*2.54)) + 1; - - int xm = (int)pageFormat.getImageableX(); - int ym = (int)pageFormat.getImageableY(); - - if (pageIndex < widthInPages*heightInPages) { - - Graphics2D g2d = (Graphics2D)g; + + int printBottomSkinTemplate(PageFormat pageFormat, int pageIndex, Graphics g) { + int widthInPages = (int) (BoardCAD.getInstance().getCurrentBrd() + .getLength() / ((pageFormat.getImageableWidth() / 72) * 2.54)) + 2; + + int heightInPages = (int) ((BoardCAD.getInstance().getCurrentBrd() + .getMaxWidth() / 2.0) / ((pageFormat.getImageableHeight() / 72) * 2.54)) + 1; + + int xm = (int) pageFormat.getImageableX(); + int ym = (int) pageFormat.getImageableY(); + + if (pageIndex < widthInPages * heightInPages) { + + Graphics2D g2d = (Graphics2D) g; g2d.setFont(mPrintFontSmall); - + FontMetrics metrics = g2d.getFontMetrics(mPrintFontSmall); // get the height of a line of text in this font and render context int hgt = metrics.getHeight(); - - String mModelString = LanguageResource.getString("BOARDFILE_STR") + BoardCAD.getInstance().getCurrentBrd().getFilename() + LanguageResource.getString("BOTTOMSKIN_STR"); - String mRowString = LanguageResource.getString("ROW_STR")+ ((pageIndex%widthInPages)+1) + "/" + widthInPages; - String mColumnString = LanguageResource.getString("COLUMN_STR") + ((pageIndex/widthInPages)+1) + "/" + heightInPages; - + + String mModelString = LanguageResource.getString("BOARDFILE_STR") + + BoardCAD.getInstance().getCurrentBrd().getFilename() + + LanguageResource.getString("BOTTOMSKIN_STR"); + String mRowString = LanguageResource.getString("ROW_STR") + + ((pageIndex % widthInPages) + 1) + "/" + widthInPages; + String mColumnString = LanguageResource.getString("COLUMN_STR") + + ((pageIndex / widthInPages) + 1) + "/" + heightInPages; + g2d.setColor(Color.BLACK); - //g2d.setStroke(new BasicStroke((float)(1.0/mScale))); - g.drawString(mModelString, xm, ym+(hgt+2)*1); - g.drawString(mRowString, xm, ym+(hgt+2)*2); - g.drawString(mColumnString, xm, ym+(hgt+2)*3); - - g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); - - - + // g2d.setStroke(new BasicStroke((float)(1.0/mScale))); + g.drawString(mModelString, xm, ym + (hgt + 2) * 1); + g.drawString(mRowString, xm, ym + (hgt + 2) * 2); + g.drawString(mColumnString, xm, ym + (hgt + 2) * 3); + + g2d.translate(pageFormat.getImageableX(), + pageFormat.getImageableY()); + BezierBoardDrawUtil.printBottomSkinTemplate(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail); - + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, true, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail); + return 0; } - + return -1; } - int printCrosssectionTemplate(PageFormat pageFormat, int pageIndex, Graphics g) - { - int widthInPages = (int)(BoardCAD.getInstance().getCurrentBrd().getWidthAt(mCrosssectionPos)/2.0f - / ((pageFormat.getImageableWidth()/72)*2.54) ) + 1; - - int heightInPages = (int)((BoardCAD.getInstance().getCurrentBrd().getMaxWidth()/2.0) - / ((pageFormat.getImageableHeight()/72)*2.54)) + 1; - - int xm = (int)pageFormat.getImageableX(); - int ym = (int)pageFormat.getImageableY(); - - if (pageIndex < widthInPages*heightInPages) { - - Graphics2D g2d = (Graphics2D)g; + int printCrosssectionTemplate(PageFormat pageFormat, int pageIndex, + Graphics g) { + int widthInPages = (int) (BoardCAD.getInstance().getCurrentBrd() + .getWidthAt(mCrosssectionPos) / 2.0f / ((pageFormat + .getImageableWidth() / 72) * 2.54)) + 1; + + int heightInPages = (int) ((BoardCAD.getInstance().getCurrentBrd() + .getMaxWidth() / 2.0) / ((pageFormat.getImageableHeight() / 72) * 2.54)) + 1; + + int xm = (int) pageFormat.getImageableX(); + int ym = (int) pageFormat.getImageableY(); + + if (pageIndex < widthInPages * heightInPages) { + + Graphics2D g2d = (Graphics2D) g; g2d.setFont(mPrintFontSmall); - + FontMetrics metrics = g2d.getFontMetrics(mPrintFontSmall); // get the height of a line of text in this font and render context int hgt = metrics.getHeight(); - - String mModelString = LanguageResource.getString("BOARDFILE_STR") + BoardCAD.getInstance().getCurrentBrd().getFilename() + " " +LanguageResource.getString("CROSSECTION_STR"); - String mPosString = LanguageResource.getString("CROSSECTIONPOSITION_STR") + " " + UnitUtils.convertLengthToCurrentUnit(mCrosssectionPos, true); - String mRowString = LanguageResource.getString("ROW_STR")+ ((pageIndex%widthInPages)+1) + "/" + widthInPages; - String mColumnString = LanguageResource.getString("COLUMN_STR") + ((pageIndex/widthInPages)+1) + "/" + heightInPages; - + + String mModelString = LanguageResource.getString("BOARDFILE_STR") + + BoardCAD.getInstance().getCurrentBrd().getFilename() + + " " + LanguageResource.getString("CROSSECTION_STR"); + String mPosString = LanguageResource + .getString("CROSSECTIONPOSITION_STR") + + " " + + UnitUtils.convertLengthToCurrentUnit(mCrosssectionPos, + true); + String mRowString = LanguageResource.getString("ROW_STR") + + ((pageIndex % widthInPages) + 1) + "/" + widthInPages; + String mColumnString = LanguageResource.getString("COLUMN_STR") + + ((pageIndex / widthInPages) + 1) + "/" + heightInPages; + g2d.setColor(Color.BLACK); - //g2d.setStroke(new BasicStroke((float)(1.0/mScale))); - g.drawString(mModelString, xm, ym+(hgt+2)*1); - g.drawString(mPosString, xm, ym+(hgt+2)*2); - g.drawString(mRowString, xm, ym+(hgt+2)*3); - g.drawString(mColumnString, xm, ym+(hgt+2)*4); - - g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY() + UnitUtils.INCH*72); - + // g2d.setStroke(new BasicStroke((float)(1.0/mScale))); + g.drawString(mModelString, xm, ym + (hgt + 2) * 1); + g.drawString(mPosString, xm, ym + (hgt + 2) * 2); + g.drawString(mRowString, xm, ym + (hgt + 2) * 3); + g.drawString(mColumnString, xm, ym + (hgt + 2) * 4); + + g2d.translate(pageFormat.getImageableX(), + pageFormat.getImageableY() + UnitUtils.INCH * 72); + printCrossSection(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, BoardCAD.getInstance().getCurrentBrd(), mCrosssectionPos, mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, false); - + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mCrosssectionPos, + mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, + false); + BezierBoardDrawUtil.printCrossSection(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), mCrosssectionPos); - + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, true, + BoardCAD.getInstance().getCurrentBrd(), mCrosssectionPos); + printCrossSectionWebbing(new JavaDraw(g2d), - -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, BoardCAD.getInstance().getCurrentBrd(), mCrosssectionPos, mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, false); + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mCrosssectionPos, + mDistanceToRail, mSkinThickness, mFrameThickness, mWebbing, + false); return 0; } - + return -1; } - - public static void printStringerWebbing(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double skinThickness, double frameThickness, double webbing) - { - if(brd.isEmpty()) { - return; + + int printNosePieceTemplate(PageFormat pageFormat, int pageIndex, Graphics g) { + int widthInPages = (int) (BoardCAD.getInstance().getCurrentBrd() + .getWidthAt(9.0 * UnitUtils.INCH - mNoseOffset) / 2.0f / ((pageFormat + .getImageableWidth() / 72) * 2.54)) + 1; + + int heightInPages = (int) ((9.0 * UnitUtils.INCH - mNoseOffset / 2.0) / ((pageFormat + .getImageableHeight() / 72) * 2.54)) + 1; + + int xm = (int) pageFormat.getImageableX(); + int ym = (int) pageFormat.getImageableY(); + + if (pageIndex < widthInPages * heightInPages) { + + Graphics2D g2d = (Graphics2D) g; + g2d.setFont(mPrintFontSmall); + + FontMetrics metrics = g2d.getFontMetrics(mPrintFontSmall); + // get the height of a line of text in this font and render context + int hgt = metrics.getHeight(); + + String mModelString = LanguageResource.getString("BOARDFILE_STR") + + BoardCAD.getInstance().getCurrentBrd().getFilename() + + " " + LanguageResource.getString("NOSEPIECE_STR"); + String mPosString = LanguageResource + .getString("NOSEPIECEPOSITION_STR") + + " " + + UnitUtils.convertLengthToCurrentUnit(mNoseOffset, true); + String mRowString = LanguageResource.getString("ROW_STR") + + ((pageIndex % widthInPages) + 1) + "/" + widthInPages; + String mColumnString = LanguageResource.getString("COLUMN_STR") + + ((pageIndex / widthInPages) + 1) + "/" + heightInPages; + + g2d.setColor(Color.BLACK); + // g2d.setStroke(new BasicStroke((float)(1.0/mScale))); + g.drawString(mModelString, xm, ym + (hgt + 2) * 1); + g.drawString(mPosString, xm, ym + (hgt + 2) * 2); + g.drawString(mRowString, xm, ym + (hgt + 2) * 3); + g.drawString(mColumnString, xm, ym + (hgt + 2) * 4); + + g2d.translate(pageFormat.getImageableX(), + pageFormat.getImageableY() + UnitUtils.INCH * 72); + + printNosePiece(new JavaDraw(g2d), -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset, false); + + printNosePiece(new JavaDraw(g2d), -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset, true); + + printNosePieceWebbing(new JavaDraw(g2d), + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset, false); + + printNosePieceWebbing(new JavaDraw(g2d), + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset, true); + + return 0; } - + + return -1; + } + + int printTailPieceTemplate(PageFormat pageFormat, int pageIndex, Graphics g) { + + int widthInPages = (int) (BoardCAD.getInstance().getCurrentBrd() + .getWidthAt(9.0 * UnitUtils.INCH - mTailOffset) / 2.0f / ((pageFormat + .getImageableWidth() / 72) * 2.54)) + 1; + + int heightInPages = (int) ((9.0 * UnitUtils.INCH - mTailOffset / 2.0) / ((pageFormat + .getImageableHeight() / 72) * 2.54)) + 1; + + int xm = (int) pageFormat.getImageableX(); + int ym = (int) pageFormat.getImageableY(); + + if (pageIndex < widthInPages * heightInPages) { + + Graphics2D g2d = (Graphics2D) g; + g2d.setFont(mPrintFontSmall); + + FontMetrics metrics = g2d.getFontMetrics(mPrintFontSmall); + // get the height of a line of text in this font and render context + int hgt = metrics.getHeight(); + + String mModelString = LanguageResource.getString("BOARDFILE_STR") + + BoardCAD.getInstance().getCurrentBrd().getFilename() + + " " + LanguageResource.getString("TAILPIECE_STR"); + String mPosString = LanguageResource + .getString("TAILPIECEPOSITION_STR") + + " " + + UnitUtils.convertLengthToCurrentUnit(mTailOffset, true); + String mRowString = LanguageResource.getString("ROW_STR") + + ((pageIndex % widthInPages) + 1) + "/" + widthInPages; + String mColumnString = LanguageResource.getString("COLUMN_STR") + + ((pageIndex / widthInPages) + 1) + "/" + heightInPages; + + g2d.setColor(Color.BLACK); + // g2d.setStroke(new BasicStroke((float)(1.0/mScale))); + g.drawString(mModelString, xm, ym + (hgt + 2) * 1); + g.drawString(mPosString, xm, ym + (hgt + 2) * 2); + g.drawString(mRowString, xm, ym + (hgt + 2) * 3); + g.drawString(mColumnString, xm, ym + (hgt + 2) * 4); + + g2d.translate(pageFormat.getImageableX(), + pageFormat.getImageableY() + UnitUtils.INCH * 72); + + printTailPiece(new JavaDraw(g2d), -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset, false); + + printTailPiece(new JavaDraw(g2d), -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset, true); + + printTailPieceWebbing(new JavaDraw(g2d), + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset, false); + + printTailPieceWebbing(new JavaDraw(g2d), + -pageFormat.getImageableWidth() + * (pageIndex % widthInPages), + -pageFormat.getImageableHeight() + * (pageIndex / widthInPages), 72 / 2.54, 0.0, + BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, + mSkinThickness, mFrameThickness, mWebbing, mTailOffset, + mNoseOffset, true); + + return 0; + } + + return -1; + } + + public static void printStringerWebbing(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double skinThickness, double frameThickness, double webbing) { + if (brd.isEmpty()) { + return; + } + System.out.printf("\nSTRINGER WEBBING\n"); - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(0,0,0)); - + d.setColor(new Color(0, 0, 0)); + GeneralPath path = new GeneralPath(); - - double span = (UnitUtils.FOOT/2.0) - webbing; - int nrOfSteps = 20; - double step = span/nrOfSteps; - - int nrOfHoles = 2*(int)((brd.getLength()/UnitUtils.FOOT) ); - - //For each foot of board - for(int i = 0; i != nrOfHoles; i++) - { - double x = (UnitUtils.FOOT/2.0) + (i*UnitUtils.FOOT/2.0) - span/2.0; + + double span = (UnitUtils.FOOT / 2.0) - webbing; + int nrOfSteps = 3;// 20; + double step = span / nrOfSteps; + + int nrOfHoles = 2 * (int) ((brd.getLength() / UnitUtils.FOOT)) - 1; + if (nrOfHoles <= 0) + return; + + // For each foot of board + for (int i = 0; i != nrOfHoles; i++) { + double x = UnitUtils.FOOT + + /* (UnitUtils.FOOT/2.0) */+(i * UnitUtils.FOOT / 2.0) + - span / 2.0; double bottom; - double deck = BezierBoardDrawUtil.getDeck(brd, x, 0.0, skinThickness); + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, + x, 0.0, skinThickness); path.moveTo(x, deck - webbing); boolean first = true; int n = 0; - for(; n < nrOfSteps-1; n++) - { + for (; n < nrOfSteps - 1; n++) { x += step; - deck = BezierBoardDrawUtil.getDeck(brd, x, 0.0, skinThickness) - webbing; - bottom = BezierBoardDrawUtil.getBottom(brd, x, 0.0, skinThickness) + webbing; - if(bottom > deck) - { - if(first){ - path.moveTo(x,deck); - continue; - } - else - { + deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, x, + 0.0, skinThickness) - webbing; + bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation(brd, + x, 0.0, skinThickness) + webbing; + if (bottom > deck) { + if (first) { + path.moveTo(x, deck); + continue; + } else { x -= step; break; } } first = false; - path.lineTo(x,deck); + path.lineTo(x, deck); } - - for(; n >= 0; n--) - { - bottom = BezierBoardDrawUtil.getBottom(brd, x, 0.0, skinThickness) + webbing; - deck = BezierBoardDrawUtil.getDeck(brd, x, 0.0, skinThickness) - webbing; - if(bottom > deck) - { + + for (; n >= 0; n--) { + bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation(brd, + x, 0.0, skinThickness) + webbing; + deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, x, + 0.0, skinThickness) - webbing; + if (bottom > deck) { break; } - path.lineTo(x,bottom); + path.lineTo(x, bottom); x -= step; } - path.closePath(); - d.draw(path); - + if (path.getCurrentPoint() != null) // Test for empty path + { + path.closePath(); + d.draw(path); + } + path.reset(); } - d.setTransform(savedTransform); + d.setTransform(savedTransform); } - public static void printCrossSection(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double position, double railDistance, double skinThickness, double frameThickness, double webbing, boolean mirror) - { - if(brd.isEmpty()) { - return; + public static void printCrossSection(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double position, double railDistance, double skinThickness, + double frameThickness, double webbing, boolean mirror) { + if (brd.isEmpty()) { + return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale, mirror, false); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation, mirror, false); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(0,0,0)); - - System.out.printf("\nHWS CROSSSECTION\n"); + d.setColor(new Color(0, 0, 0)); + + System.out.printf("\nHWS CROSSSECTION at %f\n", position); GeneralPath path = new GeneralPath(); - double span = brd.getWidthAt(position)/2.0f; - + double span = brd.getWidthAt(position) / 2.0f; + double outlineAngle = Math.abs(brd.getOutline().getTangentAt(position)); - + double sinOutline = Math.sin(outlineAngle); - - span -= railDistance/sinOutline; - - span -= frameThickness*1.5; + + span -= railDistance / sinOutline; + + span -= frameThickness * 1.5; final int steps = 150; - + double x = position; - - //First the notch at stringer - double deck = BezierBoardDrawUtil.getDeck(brd, x, frameThickness/2.0, skinThickness); - + + // First the notch at stringer + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, x, + frameThickness / 2.0, skinThickness); + path.moveTo(0.0, deck - webbing); - path.lineTo(frameThickness/2.0, deck - webbing); - + path.lineTo(frameThickness / 2.0, deck - webbing); + double y = 0; - //Deck - for(int i = 0; i <= steps; i++) - { - y = i* span / steps + (frameThickness/2.0); - - //Find thickness and rocker at pos - deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness); - - // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); - - //Draw lines - path.lineTo(y, deck); + // Deck + for (int i = 0; i <= steps; i++) { + y = i * span / steps + (frameThickness / 2.0); + + // Find thickness and rocker at pos + deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, x, y, + skinThickness); + + // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", + // ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); + + // Draw lines + path.lineTo(y, deck); } - double bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness); - + double bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation(brd, + x, y, skinThickness); + double thickness = deck - bottom; double notch = thickness / 4.0; - if(notch < 0.5) - { + if (notch < 0.5) { notch = 0.5; } - double cutout = (thickness - notch)/2.0; - - //Rail notch + double cutout = (thickness - notch) / 2.0; + + // Rail notch path.lineTo(y, deck - cutout); path.lineTo(y + frameThickness, deck - cutout); path.lineTo(y + frameThickness, deck - cutout - notch); path.lineTo(y, deck - cutout - notch); path.lineTo(y, bottom); - - //Bottom - for(int i = 1; i <= steps; i++) - { - y = span - (i* span / steps) + (frameThickness/2.0); - - //Find thickness and rocker at pos - bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness); - - // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); - - //Draw lines + + // Bottom + for (int i = 1; i <= steps; i++) { + y = span - (i * span / steps) + (frameThickness / 2.0); + + // Find thickness and rocker at pos + bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation(brd, x, + y, skinThickness); + + // System.out.printf("Outline x: %f y: %f Normal: %f Template x: %f y: %f Deck: %f Bottom: %f\n", + // ox,oy,normalAngle/BezierBoard.DEG_TO_RAD, x,y, deck, bottom); + + // Draw lines path.lineTo(y, bottom); } - bottom = BezierBoardDrawUtil.getBottom(brd, x, frameThickness/2.0, skinThickness); + bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation(brd, x, + frameThickness / 2.0, skinThickness); - path.lineTo(frameThickness/2.0, bottom + webbing); + path.lineTo(frameThickness / 2.0, bottom + webbing); path.lineTo(0.0, bottom + webbing); - + d.draw(path); - + d.setTransform(savedTransform); - + } - public static void printCrossSectionWebbing(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double position, double railDistance, double skinThickness, double frameThickness, double webbing, boolean mirror) - { - if(brd.isEmpty()) { - return; + public static void printCrossSectionWebbing(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double position, double railDistance, double skinThickness, + double frameThickness, double webbing, boolean mirror) { + if (brd.isEmpty()) { + return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale, mirror, false); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation, mirror, false); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(0,0,0)); - + d.setColor(new Color(0, 0, 0)); + System.out.printf("\nHWS CROSSSECTION WEBBING\n"); GeneralPath path = new GeneralPath(); - double span = brd.getWidthAt(position)/2.0f; - + double span = brd.getWidthAt(position) / 2.0f; + double outlineAngle = Math.abs(brd.getOutline().getTangentAt(position)); - + double sinOutline = Math.sin(outlineAngle); - - span -= railDistance/sinOutline; - - span -= frameThickness*1.5; - - span -= webbing*3.0; - + + span -= railDistance / sinOutline; + + span -= frameThickness * 1.5; + + span -= webbing * 3.0; + span /= 2.0; final int steps = 20; - - double step = span/steps; - - + double step = span / steps; + double x = position; - - for(int i = 0; i < 2; i++) - { - double y = (frameThickness/2.0) + webbing + (i*(span + webbing)); - + for (int i = 0; i < 2; i++) { + double y = (frameThickness / 2.0) + webbing + + (i * (span + webbing)); + double bottom; - double deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness); + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, + x, y, skinThickness); path.moveTo(y, deck - webbing); boolean first = true; int n = 0; - for(; n < steps-1; n++) - { + for (; n < steps - 1; n++) { y += step; - deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness) - webbing; - bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness) + webbing; - if(bottom > deck) - { - if(first){ + deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, x, + y, skinThickness) - webbing; + bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation(brd, + x, y, skinThickness) + webbing; + if (bottom > deck) { + if (first) { path.moveTo(y, deck); - continue; - } - else - { + continue; + } else { y -= step; break; } } first = false; - path.lineTo(y,deck); + path.lineTo(y, deck); } - - for(; n >= 0; n--) - { - bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness) + webbing; - deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness) - webbing; - if(bottom > deck) - { + + for (; n >= 0; n--) { + bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation(brd, + x, y, skinThickness) + webbing; + deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, x, + y, skinThickness) - webbing; + if (bottom > deck) { break; } - path.lineTo(y,bottom); + path.lineTo(y, bottom); y -= step; } path.closePath(); d.draw(path); - + path.reset(); - - + } - + d.setTransform(savedTransform); - + } + public static void printRailWebbing(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset) { + + if (brd.isEmpty()) { + return; + } + + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); + d.setStroke(stroke); + /* d.setColor(new Color(0,0,255)); */ + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, + // false, false); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, + // brd.mBottomControlPoints, false, false); + + // paintBezierPath(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, deck); + + // paintBezierPath(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, bottom); - public static void printRailWebbing(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset) - { - - if(brd.isEmpty()) { - return; - } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); - d.setStroke(stroke); -/* d.setColor(new Color(0,0,255));*/ - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, false, false); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mBottomControlPoints, false, false); - - // paintBezierPath(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, deck); - - // paintBezierPath(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, bottom); - BezierSpline outline = brd.getOutline(); - + System.out.printf("\nRAIL WEBBING\n"); boolean first = true; - double lastPos = 0; + double lastPos = tailOffset; double lastX = 0; double lastY = 0; double lastDeck = 0; GeneralPath path = new GeneralPath(); - + double ox = tailOffset; - + int steps; double span; double step; boolean noDraw = true; - + boolean end = false; - - //Calculate how many sections to do - int sections = (((int)(brd.getLength()/UnitUtils.FOOT)-1) * 5) + 2; - - for(int n = 0; n < sections; n++) - { -/* System.out.printf("section: %d pos: %s", n, UnitUtils.convertLengthToUnit(ox, true, UnitUtils.INCHES));*/ - - if(n == 0) - { - //No cutouts in first section + + // Calculate how many sections to do + int sections = (((int) (brd.getLength() / UnitUtils.FOOT) - 1) * 5) + 2; + + for (int n = 0; n < sections; n++) { + /* + * System.out.printf("section: %d pos: %s", n, + * UnitUtils.convertLengthToUnit(ox, true, UnitUtils.INCHES)); + */ + + if (n == 0) { + // No cutouts in first section span = UnitUtils.FOOT - tailOffset; noDraw = true; System.out.printf(" first\n"); - } - else - { - if(((n-1)%5)%2 == 0) - { + } else { + if (((n - 1) % 5) % 2 == 0) { span = webbing; noDraw = true; -/* System.out.printf(" webbing\n");*/ - } - else - { - span = UnitUtils.FOOT/ 2.0 - webbing*1.5; + /* System.out.printf(" webbing\n"); */ + } else { + span = UnitUtils.FOOT / 2.0 - webbing * 1.5; noDraw = false; -/* System.out.printf(" hole\n");*/ + /* System.out.printf(" hole\n"); */ } } - - steps = (int)(span/0.5); - step = span/steps; + + steps = (int) (span / 0.5); + step = span / steps; boolean firstInSection = true; ArrayList bottomCoordinates = new ArrayList(); - for(int i = 0; i < steps; i++) - { - //Get the outline point and the angle + for (int i = 0; i < steps; i++) { + // Get the outline point and the angle double oy = outline.getValueAt(ox); double normalAngle = outline.getNormalAngle(ox); - - //Find the target point at distance from outline - double x = ox - (distanceFromRail*Math.sin(normalAngle)); - double y = oy - (distanceFromRail*Math.cos(normalAngle)); - if(first && y < 0) - { + // Find the target point at distance from outline + double x = ox - (distanceFromRail * Math.sin(normalAngle)); + double y = oy - (distanceFromRail * Math.cos(normalAngle)); + + if (first && y < 0) { ox += step; continue; } - if(!first && y < 0) + if (!first && y < 0) break; - //Find thickness and rocker at pos - double deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness); - double bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness); + // Find thickness and rocker at pos + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation( + brd, x, y, skinThickness); + double bottom = BezierBoardDrawUtil + .getBottomWithSkinCompensation(brd, x, y, skinThickness); - if(first && deck < bottom) - { + if (first && deck < bottom) { ox += step; continue; } - if(!first && deck < bottom) + if (!first && deck < bottom) break; - - if(first) - { + if (first) { first = false; - } - else - { + } else { deck -= webbing; bottom += webbing; - - //Find the 2D length from the last point on deck and bottom - double xd = x-lastX; - double yd = y-lastY; - double stepLength = Math.sqrt((xd*xd)+(yd*yd)); - + + // Find the 2D length from the last point on deck and bottom + double xd = x - lastX; + double yd = y - lastY; + double stepLength = Math.sqrt((xd * xd) + (yd * yd)); + double newPos = lastPos + stepLength; - - if(deck < bottom) - { - if(!firstInSection) - { + + if (deck < bottom) { + if (!firstInSection) { end = true; } - - } - else - { - if(!noDraw) - { - if(firstInSection) - { + + } else { + if (!noDraw) { + if (firstInSection) { path.moveTo(lastPos, lastDeck); - bottomCoordinates.add(new Point2D.Double(lastPos, bottom)); + bottomCoordinates.add(new Point2D.Double( + lastPos, bottom)); firstInSection = false; } - + path.lineTo(newPos, deck); - bottomCoordinates.add(new Point2D.Double(newPos, bottom)); + bottomCoordinates.add(new Point2D.Double(newPos, + bottom)); } } - - //Update last pos + + // Update last pos lastPos = newPos; } lastX = x; lastY = y; lastDeck = deck; - + ox += step; } - for(int i = bottomCoordinates.size()-1 ; i >= 0; i--) - { + for (int i = bottomCoordinates.size() - 1; i >= 0; i--) { Point2D.Double point = bottomCoordinates.get(i); path.lineTo(point.x, point.y); } - if(!noDraw && !first && !firstInSection) - { + if (!noDraw && !first && !firstInSection) { path.closePath(); - + d.draw(path); } - if(end) - { + if (end) { break; } } d.setTransform(savedTransform); - + } + public static void printRailNotching(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset) { - public static void printRailNotching(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset) - { - - if(brd.isEmpty()) { + if (brd.isEmpty()) { return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - // d.setColor(new Color(255,0,0)); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, false, false); - - // paintBezierControlPoints(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, brd.mBottomControlPoints, false, false); - - // paintBezierPath(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, deck); - - // paintBezierPath(d,offsetX, offsetY, scale, BoardCAD.getInstance().getBrdColor(), stroke, bottom); - + // d.setColor(new Color(255,0,0)); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, brd.mDeckControlPoints, + // false, false); + + // paintBezierControlPoints(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, + // brd.mBottomControlPoints, false, false); + + // paintBezierPath(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, deck); + + // paintBezierPath(d,offsetX, offsetY, scale, + // BoardCAD.getInstance().getBrdColor(), stroke, bottom); + BezierSpline outline = brd.getOutline(); - + System.out.printf("\nRAIL NOTCHING\n"); boolean first = true; - double lastPos = 0; + double lastPos = tailOffset; double lastX = 0; double lastY = 0; double lastDeck = 0; double lastBottom = 0; GeneralPath path = new GeneralPath(); - + double ox = tailOffset; - + int steps; double span; double step; - + boolean end = false; - - //Calculate how many sections to do - int sections = (int)(brd.getLength()/UnitUtils.FOOT)-1; - - for(int n = 0; n < sections; n++) - { - if(n == 0) - { - //No cutouts in first section + + // Calculate how many sections to do + int sections = (int) (brd.getLength() / UnitUtils.FOOT) - 1; + + for (int n = 0; n < sections; n++) { + if (n == 0) { + // No cutouts in first section span = UnitUtils.FOOT - tailOffset; + } else { + span = UnitUtils.FOOT; } - else - { - span = UnitUtils.FOOT; - } - - steps = (int)(span/0.5); - step = span/steps; - for(int i = 0; i < steps; i++) - { - //Get the outline point and the angle + steps = (int) (span / 0.5); + step = span / steps; + + for (int i = 0; i < steps; i++) { + // Get the outline point and the angle double oy = outline.getValueAt(ox); double normalAngle = outline.getNormalAngle(ox); - - //Find the target point at distance from outline - double x = ox - (distanceFromRail*Math.sin(normalAngle)); - double y = oy - (distanceFromRail*Math.cos(normalAngle)); - if(first && y < 0) - { + // Find the target point at distance from outline + double x = ox - (distanceFromRail * Math.sin(normalAngle)); + double y = oy - (distanceFromRail * Math.cos(normalAngle)); + + if (first && y < 0) { ox += step; continue; } - if(!first && y < 0) + if (!first && y < 0) break; - //Find thickness and rocker at pos - double deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness); - double bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness); + // Find thickness and rocker at pos + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation( + brd, x, y, skinThickness); + double bottom = BezierBoardDrawUtil + .getBottomWithSkinCompensation(brd, x, y, skinThickness); - if(first && deck < bottom) - { + if (first && deck < bottom) { ox += step; continue; } - if(!first && deck < bottom) + if (!first && deck < bottom) break; - if(first) - { + if (first) { first = false; - } - else - { - //Find the 2D length from the last point on deck and bottom - double xd = x-lastX; - double yd = y-lastY; - double stepLength = Math.sqrt((xd*xd)+(yd*yd)); - + } else { + // Find the 2D length from the last point on deck and bottom + double xd = x - lastX; + double yd = y - lastY; + double stepLength = Math.sqrt((xd * xd) + (yd * yd)); + double newPos = lastPos + stepLength; - - //Update last pos + + // Update last pos lastPos = newPos; } @@ -1315,1216 +1644,1120 @@ public static void printRailNotching(AbstractDraw d, double offsetX, double offs lastY = y; lastDeck = deck; lastBottom = bottom; - + ox += step; } - + double thickness = lastDeck - lastBottom; double notch = thickness / 4.0; - if(notch < 0.5) - { + if (notch < 0.5) { notch = 0.5; } - double cutout = (thickness - notch)/2.0; + double cutout = (thickness - notch) / 2.0; + + path.moveTo(lastPos - frameThickness / 2.0, lastDeck - cutout); + path.lineTo(lastPos + frameThickness / 2.0, lastDeck - cutout); + path.lineTo(lastPos + frameThickness / 2.0, lastBottom + cutout); + path.lineTo(lastPos - frameThickness / 2.0, lastBottom + cutout); - path.moveTo(lastPos - frameThickness/2.0, lastDeck-cutout); - path.lineTo(lastPos + frameThickness/2.0, lastDeck-cutout); - path.lineTo(lastPos + frameThickness/2.0, lastBottom+cutout); - path.lineTo(lastPos - frameThickness/2.0, lastBottom+cutout); - path.closePath(); - + d.draw(path); - if(end) - { + if (end) { break; } } d.setTransform(savedTransform); - + } - public static void printTailPiece(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset, boolean mirror) - { - - if(brd.isEmpty()) { + public static void printTailPiece(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset, boolean mirror) { + + if (brd.isEmpty()) { return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale, false, mirror); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation, false, mirror); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(255,0,0)); + d.setColor(new Color(255, 0, 0)); BezierSpline outline = brd.getOutline(); - + System.out.printf("\nTAIL PIECE\n"); boolean first = true; GeneralPath path = new GeneralPath(); - + double ox = tailOffset; double oy = 0.0; - - double tailPieceLength = 9.0*UnitUtils.INCH - tailOffset; - double span; + double tailPieceLength = 9.0 * UnitUtils.INCH - tailOffset; - double angle = getTailPieceStringerAngle(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); + double span = tailPieceLength; + + double angle = getTailPieceStringerAngle(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset); double x = 0.0; double y = 0.0; - - double normalAngle = 0.0; - - double xf = 0.0; - - for(int n = 0; n < 5; n++) - { - if(tailPieceLength > 5.0*UnitUtils.INCH) - { - switch(n) - { - case 0: - case 1: - case 3: - case 4: - span = 1.0*UnitUtils.INCH; - break; - default: - span = tailPieceLength - 4.0*UnitUtils.INCH; - break; - } - } - else - { - span = (n+1)/5.0*tailPieceLength; - } - - int steps = (int)(span/0.5); - double step = span/steps; - for(int i = 0; i < steps; i++) - { - //Get the outline point and the angle - oy = outline.getValueAt(ox); - normalAngle = outline.getNormalAngle(ox); - - //Find the point at distance from outline - x = ox - ((distanceFromRail - ((n%2==1)?frameThickness:0.0) )*Math.sin(normalAngle)); - y = oy - ((distanceFromRail - ((n%2==1)?frameThickness:0.0) )*Math.cos(normalAngle)); - - if(first && y < 0) - { - ox += step; - continue; - } + double normalAngle = 0.0; - if(!first && y < 0) - break; + int steps = (int) (span / 0.25); + double step = span / steps; - //Find thickness and rocker at pos - double deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness); - double bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness); + for (int i = 0; i < steps; i++) { + // Get the outline point and the angle + oy = outline.getValueAt(ox); + normalAngle = outline.getNormalAngle(ox); - if(first && deck < bottom) - { - ox += step; - continue; - } + // Find the point at distance from outline + double offsetFromRail = distanceFromRail + frameThickness + + ((i * 5 / steps) % 2 == 1 ? 0.0 : frameThickness); + x = ox - offsetFromRail * Math.sin(normalAngle); + y = oy - offsetFromRail * Math.cos(normalAngle); - if(!first && deck < bottom) - break; + if (first && y < 0) { + ox += step; + continue; + } - if(first) - { - first = false; + // Find thickness and rocker at pos + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, + x, y, skinThickness); + double bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation( + brd, x, y, skinThickness); - xf = x; - - path.moveTo((x-xf)/Math.cos(angle), 0.0); - } - - path.lineTo((x-xf)/Math.cos(angle), y); - + if (first && deck < bottom) { ox += step; + continue; } - if(n<4) - { - ox -= step; - x = ox - ((distanceFromRail - ((n%2==0)?frameThickness:0.0) )*Math.sin(normalAngle)); - y = oy - ((distanceFromRail - ((n%2==0)?frameThickness:0.0) )*Math.cos(normalAngle)); - path.lineTo((x-xf)/Math.cos(angle), y); - ox += step; + + if (first) { + first = false; + path.moveTo(x / Math.cos(angle), 0.0); } + path.lineTo(x / Math.cos(angle), y); + + ox += step; } - - path.lineTo((x-xf)/Math.cos(angle), frameThickness/2.0); - path.lineTo((x-xf)/Math.cos(angle) - 2.0*UnitUtils.INCH, frameThickness/2.0); - path.lineTo((x-xf)/Math.cos(angle) - 2.0*UnitUtils.INCH, 0.0); - + + path.lineTo(x / Math.cos(angle), frameThickness / 2.0); + path.lineTo(x / Math.cos(angle) - 2.0 * UnitUtils.INCH, + frameThickness / 2.0); + path.lineTo(x / Math.cos(angle) - 2.0 * UnitUtils.INCH, 0.0); + d.draw(path); - System.out.printf("\nTAIL PIECE\n"); + System.out.printf("\nTAIL PIECE DONE\n"); - d.setTransform(savedTransform); } - - public static void printTailPieceWebbing(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset, boolean mirror) - { - if(brd.isEmpty()) { + + public static void printTailPieceWebbing(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset, boolean mirror) { + if (brd.isEmpty()) { return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale, false, mirror); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation, false, mirror); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(255,0,0)); + d.setColor(new Color(255, 0, 0)); BezierSpline outline = brd.getOutline(); - + System.out.printf("\nTAIL WEBBING\n"); boolean first = true; GeneralPath path = new GeneralPath(); - - double tailPieceLength = 9.0*UnitUtils.INCH - tailOffset; - double span = (tailPieceLength - webbing*5.0)/2.0; + double tailPieceLength = 9.0 * UnitUtils.INCH - tailOffset; - double angle = getTailPieceStringerAngle(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); + double span = (tailPieceLength - webbing * 3.0) / 2.0; + + double angle = getTailPieceStringerAngle(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset); Point2D.Double point = null; - - int steps = (int)(span/0.5); - double step = span/steps; - double comp = (webbing)*Math.sin(outline.getNormalAngle(9.0*UnitUtils.INCH)); + int steps = (int) (span / 0.5); + double step = span / steps; - double ox = tailOffset + webbing*2.0 + comp; - - double xf = 0.0; + double comp = (webbing) + * Math.sin(outline.getNormalAngle(9.0 * UnitUtils.INCH)); + + double ox = tailOffset + webbing + comp; - for(int n = 0; n < 2; n++) - { + for (int n = 0; n < 2; n++) { boolean firstInSection = true; - for(int i = 0; i < steps; i++) - { - //Use point from tail piece for end calculation - point = BezierBoardDrawUtil.getOutline(brd, ox, distanceFromRail); + for (int i = 0; i < steps; i++) { + // Use point from tail piece for end calculation + point = BezierBoardDrawUtil.getOutline(brd, ox, + distanceFromRail); - if(first && point.y < 0) - { + if (first && point.y < 0) { ox += step; continue; } - if(!first && point.y < 0) + if (!first && point.y < 0) break; - //Find thickness and rocker at pos - double deck = BezierBoardDrawUtil.getDeck(brd, point.x, point.y, skinThickness); - double bottom = BezierBoardDrawUtil.getBottom(brd, point.x, point.y, skinThickness); + // Find thickness and rocker at pos + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation( + brd, point.x, point.y, skinThickness); + double bottom = BezierBoardDrawUtil + .getBottomWithSkinCompensation(brd, point.x, point.y, + skinThickness); - if(first && deck < bottom) - { + if (first && deck < bottom) { ox += step; continue; } - if(!first && deck < bottom) + if (!first && deck < bottom) break; - if(first) - { + if (first) { first = false; - - xf = point.x - webbing*2.0 - comp; - + } - - //Get the webbing point - point = BezierBoardDrawUtil.getOutline(brd, ox, distanceFromRail + webbing); - if(firstInSection) - { + // Get the webbing point + point = BezierBoardDrawUtil.getOutline(brd, ox, + distanceFromRail + webbing + frameThickness); + + if (firstInSection) { firstInSection = false; - path.moveTo((point.x - xf)/Math.cos(angle), webbing); + path.moveTo((point.x) / Math.cos(angle), webbing); } - - path.lineTo((point.x - xf)/Math.cos(angle), point.y); - + + path.lineTo((point.x) / Math.cos(angle), point.y); + ox += step; } - path.lineTo((point.x - xf)/Math.cos(angle), webbing); - path.closePath(); - - d.draw(path); - + if (!firstInSection) { + path.lineTo((point.x) / Math.cos(angle), webbing); + path.closePath(); + + d.draw(path); + } + path.reset(); - + ox += webbing; } - - + d.setTransform(savedTransform); } - public static void printStringerTailPieceCutOut(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset) - { - if(brd.isEmpty()) { + public static void printStringerTailPieceCutOut(AbstractDraw d, + double offsetX, double offsetY, double scale, double rotation, + BezierBoard brd, double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset) { + if (brd.isEmpty()) { return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); - d.setStroke(stroke); - d.setColor(new Color(255,0,0)); - + + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation); + System.out.printf("\nSTRINGER TAIL PIECE CUTOUT\n"); BezierSpline outline = brd.getOutline(); - + GeneralPath path = new GeneralPath(); - - double tailPieceLength = 9.0f*UnitUtils.INCH - tailOffset; - - double angle = getTailPieceStringerAngle(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); - double thicknessXOffset = Math.sin(angle)*frameThickness/2.0; - double thicknessYOffset = Math.cos(angle)*frameThickness/2.0; - - //Get the tail pos - double tailX = getRailMinPos(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); - double tailDeck = BezierBoardDrawUtil.getRailDeck(brd, tailX, distanceFromRail, skinThickness); - double tailBottom = BezierBoardDrawUtil.getRailBottom(brd, tailX, distanceFromRail, skinThickness); - double tailZ = (tailDeck +tailBottom)/2.0; - double tailNormalAngle = outline.getNormalAngle(tailX); - //Find the point at distance from outline - tailX = tailX - (distanceFromRail *Math.sin(tailNormalAngle)); - - //Get the second tail pos - double tailPieceFrontX = 9.0*UnitUtils.INCH; - double tailPieceFrontDeck = BezierBoardDrawUtil.getRailDeck(brd, tailPieceFrontX, distanceFromRail, skinThickness); - double tailPieceFrontBottom = BezierBoardDrawUtil.getRailBottom(brd, tailPieceFrontX, distanceFromRail, skinThickness); - double tailPieceFrontZ = (tailPieceFrontDeck +tailPieceFrontBottom)/2.0; - double tailPieceFrontNormalAngle = outline.getNormalAngle(tailPieceFrontX); - //Find the point at distance from outline - tailPieceFrontX = tailPieceFrontX - (distanceFromRail *Math.sin(tailPieceFrontNormalAngle)); - - double tailPieceCutoutX = tailPieceFrontX - (2.0*UnitUtils.INCH); - double tailPieceCutoutZ = tailPieceFrontZ - (2.0*UnitUtils.INCH)/Math.cos(angle)*Math.sin(angle); - - double tailEndX = tailPieceFrontX - tailPieceLength; - double tailEndZ = tailPieceFrontZ - (tailPieceLength)*Math.sin(angle); - - path.moveTo(tailX-thicknessXOffset, tailZ+thicknessYOffset); - path.lineTo(tailPieceFrontX-thicknessXOffset, tailPieceFrontZ+thicknessYOffset); - path.lineTo(tailPieceFrontX+thicknessXOffset, tailPieceFrontZ-thicknessYOffset); - path.lineTo(tailX+thicknessXOffset, tailZ-thicknessYOffset); - path.closePath(); - - - d.draw(path); - path.reset(); - - d.setColor(new Color(0,255,0)); - path.moveTo(tailPieceCutoutX-thicknessXOffset, tailPieceCutoutZ+thicknessYOffset); - path.lineTo(tailEndX-thicknessXOffset, tailEndZ+thicknessYOffset); - path.lineTo(tailEndX+thicknessXOffset, tailEndZ-thicknessYOffset); - path.lineTo(tailPieceCutoutX+thicknessXOffset, tailPieceCutoutZ-thicknessYOffset); + double tailPieceLength = 9.0f * UnitUtils.INCH - tailOffset; + + double angle = getTailPieceStringerAngle(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset); + + double thicknessXOffset = Math.sin(angle) * frameThickness / 2.0; + double thicknessYOffset = Math.cos(angle) * frameThickness / 2.0; + + // Get the tail pos + double tailX = getRailMinPos(brd, distanceFromRail, skinThickness, + frameThickness, tailOffset, noseOffset); + double tailDeck = BezierBoardDrawUtil.getRailDeck(brd, tailX, + distanceFromRail, skinThickness); + double tailBottom = BezierBoardDrawUtil.getRailBottom(brd, tailX, + distanceFromRail, skinThickness); + double tailZ = (tailDeck + tailBottom) / 2.0; + double tailNormalAngle = outline.getNormalAngle(tailX); + // Find the point at distance from outline + tailX = tailX - (distanceFromRail * Math.sin(tailNormalAngle)); + + // Get the front tail pos + double tailPieceFrontX = 9.0 * UnitUtils.INCH; + double tailPieceFrontDeck = BezierBoardDrawUtil.getRailDeck(brd, + tailPieceFrontX, distanceFromRail, skinThickness); + double tailPieceFrontBottom = BezierBoardDrawUtil.getRailBottom(brd, + tailPieceFrontX, distanceFromRail, skinThickness); + double tailPieceFrontZ = (tailPieceFrontDeck + tailPieceFrontBottom) / 2.0; + double tailPieceFrontNormalAngle = outline + .getNormalAngle(tailPieceFrontX); + + // Find the point at distance from outline + tailPieceFrontX = tailPieceFrontX + - (distanceFromRail * Math.sin(tailPieceFrontNormalAngle)); + + double tailPieceCutoutX = tailPieceFrontX - (2.0 * UnitUtils.INCH); + double tailPieceCutoutZ = tailPieceFrontZ - (2.0 * UnitUtils.INCH) + / Math.cos(angle) * Math.sin(angle); + + double tailEndX = tailOffset; + double tailEndZ = tailPieceFrontZ - (tailPieceFrontX - tailEndX) + * Math.sin(angle); + + path.moveTo(tailPieceCutoutX - thicknessXOffset, tailPieceCutoutZ + + thicknessYOffset); + path.lineTo(tailEndX - thicknessXOffset, tailEndZ + thicknessYOffset); + path.lineTo(tailEndX + thicknessXOffset, tailEndZ - thicknessYOffset); + path.lineTo(tailPieceCutoutX + thicknessXOffset, tailPieceCutoutZ + - thicknessYOffset); path.closePath(); d.draw(path); + path.reset(); d.setTransform(savedTransform); } - public static void printRailTailPieceNotches(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset) - { - - if(brd.isEmpty()) { + public static void printRailTailPieceNotches(AbstractDraw d, + double offsetX, double offsetY, double scale, double rotation, + BezierBoard brd, double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset) { + + if (brd.isEmpty()) { return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); - d.setStroke(stroke); - d.setColor(new Color(255,0,0)); - BezierSpline outline = brd.getOutline(); - - System.out.printf("\nRAIL TAIL PIECE NOTCHING\n"); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); + d.setStroke(stroke); + d.setColor(new Color(255, 0, 0)); - boolean first = true; GeneralPath path = new GeneralPath(); - - double ox = tailOffset; - - double tailPieceLength = 9.0*UnitUtils.INCH - tailOffset; - - double span; - - double angle = getTailPieceRailAngle(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); - double x = 0.0; - - double endPointX = 0.0; - double endPointZ = 0.0; - - double lastX = 0.0; - double lastY = 0.0; - double lastPos = 0.0; - - double notchX = 0.0; - double notchZ = 0.0; - - double thicknessXOffset = 0.0; - double thicknessYOffset = 0.0; - - double deck = 0.0; - for(int n = 0; n < 5; n++) - { - if(tailPieceLength > 5.0*UnitUtils.INCH) - { - switch(n) - { - case 0: - case 1: - case 3: - case 4: - span = 1.0*UnitUtils.INCH; - break; - default: - span = tailPieceLength - 4.0*UnitUtils.INCH; - break; - } - } - else - { - span = (n+1)/5.0*tailPieceLength; - } - - int steps = (int)(span/0.5); - double step = span/steps; - - for(int i = 0; i < steps; i++) - { - //Get the outline point and the angle - double oy = outline.getValueAt(ox); - double normalAngle = outline.getNormalAngle(ox); - - //Find the point at distance from outline - x = ox - (distanceFromRail *Math.sin(normalAngle)); - double y = oy - (distanceFromRail*Math.cos(normalAngle)); - - if(first && y < 0) - { - ox += step; - continue; - } - - if(!first && y < 0) - break; - - //Find thickness and rocker at pos - deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness); - double bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness); - - if(deck < bottom) - { - ox += step; - continue; - } - - if(deck < bottom) - break; - - if(first) - { - //Calculate angle for tailpiece (tail piece sit halfway between deck and bottom on the rail template at both ends) - double z1 = (bottom+deck)/2.0; - - System.out.printf("angle: %f", angle*180.0/Math.PI); - endPointX = ox; - endPointZ = z1; - first = false; + double tailPieceLength = 9.0 * UnitUtils.INCH - tailOffset; + + double angle = getTailPieceStringerAngle(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset); + + double thicknessXOffset = Math.sin(angle) * frameThickness / 2.0; + double thicknessYOffset = Math.cos(angle) * frameThickness / 2.0; + + // Use same Y start pos reference as stringer cutout + double tailPieceFrontX = 9.0 * UnitUtils.INCH; + // Find the point at distance from outline + double tailPieceFrontNormalAngle = brd.getOutline().getNormalAngle( + tailPieceFrontX); + tailPieceFrontX = tailPieceFrontX + - (distanceFromRail * Math.sin(tailPieceFrontNormalAngle)); + double tailPieceFrontDeck = BezierBoardDrawUtil.getRailDeck(brd, + tailPieceFrontX, distanceFromRail, skinThickness); + double tailPieceFrontBottom = BezierBoardDrawUtil.getRailBottom(brd, + tailPieceFrontX, distanceFromRail, skinThickness); + double tailPieceFrontZ = (tailPieceFrontDeck + tailPieceFrontBottom) / 2.0; + + // Positions along board + double firstStartX = tailOffset + (tailPieceLength / 5); + double firstEndX = tailOffset + (tailPieceLength / 5) * 2; + + // Calculate Y for start and end + double firstStartZ = tailPieceFrontZ - (tailPieceFrontX - firstStartX) + * Math.tan(angle); + double firstEndZ = tailPieceFrontZ - (tailPieceFrontX - firstEndX) + * Math.tan(angle); + + // Calculate X along rail for start and end + double firstStartRailX = getRailLength(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset, tailOffset, + firstStartX); + double firstEndRailX = getRailLength(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset, tailOffset, + firstEndX); + + System.out.printf("tailOffset:%f firstStartX::%f firstStartRailX:%f", tailOffset, firstStartX, firstStartRailX); + + // Draw + path.moveTo(firstStartRailX - thicknessXOffset + tailOffset, firstStartZ + + thicknessYOffset); + path.lineTo(firstEndRailX - thicknessXOffset + tailOffset, firstEndZ + + thicknessYOffset); + path.lineTo(firstEndRailX + thicknessXOffset + tailOffset, firstEndZ + - thicknessYOffset); + path.lineTo(firstStartRailX + thicknessXOffset + tailOffset, firstStartZ + - thicknessYOffset); + path.closePath(); - thicknessXOffset = Math.sin(angle)*frameThickness/2.0; - thicknessYOffset = Math.cos(angle)*frameThickness/2.0; - } - else - { - //Find the 2D length from the last point on deck and bottom - double xd = x-lastX; - double yd = y-lastY; - double stepLength = Math.sqrt((xd*xd)+(yd*yd)); - - double newPos = lastPos + stepLength; - - //Update last pos - lastPos = newPos; - } + d.draw(path); - lastX = x; - lastY = y; - - ox += step; - } -/* - Line2D.Double line = new Line2D.Double(); - line.setLine(lastPos, deck, lastPos, deck + 8.0); - d.draw(line); -*/ - //Check if we should store pos - if(n%2==0) - { - //Store for notching - notchX = lastPos; - notchZ = endPointZ + (((ox - endPointX)/Math.cos(angle))*Math.sin(angle)); - } - else if(n%2==1) - { - double otherEndX = lastPos; - double otherEndZ = endPointZ + (((ox - endPointX)/Math.cos(angle))*Math.sin(angle)); + path.reset(); + + // Positions along board + double secondStartX = tailOffset + (tailPieceLength / 5) * 3; + double secondEndX = tailOffset + (tailPieceLength / 5) * 4; + + // Calculate Y for start and end + double secondStartZ = tailPieceFrontZ + - (tailPieceFrontX - secondStartX) * Math.tan(angle); + double secondEndZ = tailPieceFrontZ - (tailPieceFrontX - secondEndX) + * Math.tan(angle); + + // Calculate X along rail for start and end + double secondStartRailX = getRailLength(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset, tailOffset, + secondStartX); + double secondEndRailX = getRailLength(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset, tailOffset, + secondEndX); + + // Draw + path.moveTo(secondStartRailX - thicknessXOffset + tailOffset, secondStartZ + + thicknessYOffset); + path.lineTo(secondEndRailX - thicknessXOffset + tailOffset, secondEndZ + + thicknessYOffset); + path.lineTo(secondEndRailX + thicknessXOffset + tailOffset, secondEndZ + - thicknessYOffset); + path.lineTo(secondStartRailX + thicknessXOffset + tailOffset, secondStartZ + - thicknessYOffset); + path.closePath(); + + d.draw(path); - path.moveTo(endPointX + notchX-thicknessXOffset - endPointX, notchZ+thicknessYOffset); - path.lineTo(endPointX + otherEndX-thicknessXOffset - endPointX, otherEndZ+thicknessYOffset); - path.lineTo(endPointX + otherEndX+thicknessXOffset - endPointX, otherEndZ-thicknessYOffset); - path.lineTo(endPointX + notchX+thicknessXOffset - endPointX, notchZ-thicknessYOffset); - path.closePath(); - d.draw(path); - - path.reset(); - } - - } - d.setTransform(savedTransform); } - public static void printNosePiece(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset, boolean mirror) - { - - if(brd.isEmpty()) { + public static void printNosePiece(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset, boolean mirror) { + + if (brd.isEmpty()) { return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale, false, mirror); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation, false, mirror); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(255,0,0)); + // d.setColor(new Color(255,0,0)); BezierSpline outline = brd.getOutline(); - + System.out.printf("\nNose PIECE\n"); boolean first = true; GeneralPath path = new GeneralPath(); - - - double nosePieceLength = 9.0*UnitUtils.INCH - noseOffset; - double ox = brd.getLength() - 9.0*UnitUtils.INCH; + double nosePieceLength = 9.0 * UnitUtils.INCH - noseOffset; + + double startX = brd.getLength() - 9.0 * UnitUtils.INCH; + double ox = startX; double oy = 0.0; - double span; + double span = nosePieceLength; + + double angle = getNosePieceStringerAngle(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset); - double angle = getNosePieceStringerAngle(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); double x = 0.0; double y = 0.0; - - double normalAngle = 0.0; - - double xf = 0.0; - - for(int n = 0; n < 5; n++) - { - if(nosePieceLength > 5.0*UnitUtils.INCH) - { - switch(n) - { - case 0: - case 1: - case 3: - case 4: - span = 1.0*UnitUtils.INCH; - break; - default: - span = nosePieceLength - 4.0*UnitUtils.INCH; - break; - } - } - else - { - span = (n+1)/5.0*nosePieceLength; - } - - int steps = (int)(span/0.5); - double step = span/steps; - for(int i = 0; i < steps; i++) - { - //Get the outline point and the angle - oy = outline.getValueAt(ox); - normalAngle = outline.getNormalAngle(ox); - - //Find the point at distance from outline - x = ox - ((distanceFromRail - ((n%2==1)?frameThickness:0.0) )*Math.sin(normalAngle)); - y = oy - ((distanceFromRail - ((n%2==1)?frameThickness:0.0) )*Math.cos(normalAngle)); - - if(first && y < 0) - { - ox += step; - continue; - } + double normalAngle = 0.0; - if(!first && y < 0) - break; + int steps = (int) (span / 0.25); + double step = span / steps; - //Find thickness and rocker at pos - double deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness); - double bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness); + for (int i = 0; i < steps; i++) { + // Get the outline point and the angle + oy = outline.getValueAt(ox); + normalAngle = outline.getNormalAngle(ox); - if(first && deck < bottom) - { - ox += step; - continue; - } + // Find the point at distance from outline + double offsetFromRail = distanceFromRail + frameThickness + + ((i * 5 / steps) % 2 == 1 ? 0.0 : frameThickness); + x = ox - offsetFromRail * Math.sin(normalAngle); + y = oy - offsetFromRail * Math.cos(normalAngle); - if(!first && deck < bottom) - { - path.lineTo(path.getCurrentPoint().getX(),0.0); - d.draw(path); - d.setTransform(savedTransform); - return; - } + System.out.printf( + "i:%d ox:%f oy:%f offsetFromRail:%f x:%f y:%f \n", i, ox, + oy, offsetFromRail, x, y); - if(first) - { - first = false; + // Find thickness and rocker at pos + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, + x, y, skinThickness); + double bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation( + brd, x, y, skinThickness); - xf = x; - - path.moveTo((x-xf + 2.0*UnitUtils.INCH)/Math.cos(angle), 0.0); - path.lineTo((x-xf + 2.0*UnitUtils.INCH)/Math.cos(angle), frameThickness/2.0); - path.lineTo((x-xf)/Math.cos(angle), frameThickness/2.0); - } - - path.lineTo((x-xf)/Math.cos(angle), y); + if (!first && deck < bottom) { + break; + } - ox += step; + if (y < 0) { + break; } - if(n < 4) - { - ox -= step; - x = ox - ((distanceFromRail - ((n%2==0)?frameThickness:0.0) )*Math.sin(normalAngle)); - y = oy - ((distanceFromRail - ((n%2==0)?frameThickness:0.0) )*Math.cos(normalAngle)); - path.lineTo((x-xf)/Math.cos(angle), y); - ox += step; + + if (first) { + first = false; + path.moveTo((x - startX) / Math.cos(angle) + 2.0 + * UnitUtils.INCH, 0.0); + path.lineTo((x - startX) / Math.cos(angle) + 2.0 + * UnitUtils.INCH, frameThickness / 2.0); + path.lineTo((x - startX) / Math.cos(angle), + frameThickness / 2.0); } + path.lineTo((x - startX) / Math.cos(angle), y); + + ox += step; } - path.lineTo((x-xf)/Math.cos(angle), 0); - - + + path.lineTo((x - startX) / Math.cos(angle), 0.0); + d.draw(path); - System.out.printf("\nNOSE PIECE\n"); + System.out.printf("\nNose PIECE DONE\n"); - d.setTransform(savedTransform); } - public static void printNosePieceWebbing(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset, boolean mirror) - { - if(brd.isEmpty()) { + public static void printNosePieceWebbing(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset, boolean mirror) { + if (brd.isEmpty()) { return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale, false, mirror); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation, false, mirror); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); - d.setColor(new Color(255,0,0)); - BezierSpline outline = brd.getOutline(); - System.out.printf("\nNose WEBBING\n"); - boolean first = true; - GeneralPath path = new GeneralPath(); - - double nosePieceLength = 9.0*UnitUtils.INCH - noseOffset; + double nosePieceLength = 9.0 * UnitUtils.INCH - noseOffset; - double span = (nosePieceLength - webbing*5.0)/2.0; + double span = (nosePieceLength - webbing * 3.0) / 2.0; - double angle = getNosePieceStringerAngle(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); - Point2D.Double point = null; - - int steps = (int)(span/0.5); - double step = span/steps; + double angle = getNosePieceStringerAngle(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset); - double ox = brd.getLength() - 9.0*UnitUtils.INCH - noseOffset + webbing*2.0; + double positionOffset = brd.getLength() - 9.0 * UnitUtils.INCH; - double comp = (webbing)*Math.sin(outline.getNormalAngle(ox)); - - double xf = 0.0; + for (int n = 0; n < 2; n++) { - for(int n = 0; n < 2; n++) - { - boolean firstInSection = true; + double webbingStartPos = brd.getLength() - 9.0 * UnitUtils.INCH + + (webbing * (n + 1)) + (span * n); + double webbingEndPos = webbingStartPos + span; - for(int i = 0; i < steps; i++) - { - //Use point from nose piece for end calculation - point = BezierBoardDrawUtil.getOutline(brd, ox, distanceFromRail); + printPieceWebbing(d, 0.0, 0.0, 1.0, 0.0, brd, distanceFromRail, + skinThickness, frameThickness, webbing, tailOffset, + noseOffset, mirror, positionOffset, webbingStartPos, + webbingEndPos, angle); + } - if(first && point.y < 0) - { - ox += step; - continue; - } + d.setTransform(savedTransform); + } - if(!first && point.y < 0) - break; + public static void printPieceWebbing(AbstractDraw d, double offsetX, + double offsetY, double scale, double rotation, BezierBoard brd, + double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset, boolean mirror, double positionOffset, + double webbingStartPos, double webbingEndPos, double angle) { + if (brd.isEmpty()) { + return; + } - //Find thickness and rocker at pos - double deck = BezierBoardDrawUtil.getDeck(brd, point.x, point.y, skinThickness); - double bottom = BezierBoardDrawUtil.getBottom(brd, point.x, point.y, skinThickness); + System.out.printf("\nWEBBING\n"); - if(first && deck < bottom) - { - ox += step; - continue; - } + GeneralPath path = new GeneralPath(); + + double span = webbingEndPos - webbingStartPos; - if(!first && deck < bottom) + int steps = (int) (span / 0.5); + double step = span / steps; + + double ox = webbingStartPos; + + double railOffset = distanceFromRail + frameThickness + webbing; + + Point2D.Double point = null; + boolean first = true; + for (int i = 0; i < steps; i++) { + // Use point from nose piece for end calculation + point = BezierBoardDrawUtil.getOutline(brd, ox, railOffset); + + System.out.printf("point(%f, %f)\n", point.x, point.y); + + if (point.y < webbing) { + if (first) + return; // Break out if there is somewhere without enough + // width + else break; + } - if(first) - { - first = false; - - //Calculate angle for nosepiece (Nose piece sit halfway between deck and bottom on the rail template at both ends) - double z1 = (bottom+deck)/2.0; - - double tmp = brd.getLength()-noseOffset; - double tmpDeck; - double tmpBottom; - Point2D.Double tmpPoint; - do{ - tmpPoint = BezierBoardDrawUtil.getOutline(brd, tmp, distanceFromRail); - - tmpDeck = BezierBoardDrawUtil.getDeck(brd, tmpPoint.x, tmpPoint.y, skinThickness); - tmpBottom = BezierBoardDrawUtil.getBottom(brd, tmpPoint.x, tmpPoint.y, skinThickness); - - tmp -= step; - }while(tmpDeck < tmpBottom); - - double z2 = (tmpBottom+tmpDeck)/2.0; - - angle = Math.atan2(z2-z1, tmp - ox); - - System.out.printf("angle: %f", angle*180.0/Math.PI); - - xf = point.x - webbing*2.0 - comp; - - } - - //Get the webbing point - point = BezierBoardDrawUtil.getOutline(brd, ox, distanceFromRail + webbing); + // Find thickness and rocker at pos + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, + point.x, point.y, skinThickness); - if(firstInSection) - { - firstInSection = false; - path.moveTo((point.x - xf)/Math.cos(angle), webbing); - } - - path.lineTo((point.x - xf)/Math.cos(angle), point.y); - - ox += step; + double bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation( + brd, point.x, point.y, skinThickness); + + if (deck < bottom) { + System.out.printf("Too thin, deck:%f, bottom:%f\n", deck, + bottom); + return; // Break out if there is somewhere without enough + // thickness } - path.lineTo((point.x - xf)/Math.cos(angle), webbing); - path.closePath(); - - d.draw(path); - - path.reset(); - - ox += webbing; + if (first) { + first = false; + path.moveTo((point.x - positionOffset) / Math.cos(angle), + webbing); + } + + path.lineTo((point.x - positionOffset) / Math.cos(angle), point.y); + + ox += step; } - - - d.setTransform(savedTransform); + + path.lineTo((point.x - positionOffset) / Math.cos(angle), webbing); + path.closePath(); + + d.draw(path); + } - public static void printStringerNosePieceCutOut(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset) - { - - if(brd.isEmpty()) { + public static void printStringerNosePieceCutOut(AbstractDraw d, + double offsetX, double offsetY, double scale, double rotation, + BezierBoard brd, double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset) { + + if (brd.isEmpty()) { return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); - d.setStroke(stroke); - d.setColor(new Color(255,0,0)); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); + d.setStroke(stroke); BezierSpline outline = brd.getOutline(); - + System.out.printf("\nSTRINGER NOSE PIECE CUTOUT\n"); GeneralPath path = new GeneralPath(); - - double nosePieceLength = 9.0*UnitUtils.INCH - noseOffset; - double angle = getNosePieceStringerAngle(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); - - double thicknessXOffset = Math.sin(angle)*frameThickness/2.0; - double thicknessYOffset = Math.cos(angle)*frameThickness/2.0; - - //Get the nose pos - double noseX = getRailMaxPos(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); - double noseDeck = BezierBoardDrawUtil.getRailDeck(brd, noseX, distanceFromRail, skinThickness); - double noseBottom = BezierBoardDrawUtil.getRailBottom(brd, noseX, distanceFromRail, skinThickness); - double noseZ = (noseDeck + noseBottom)/2.0; - double noseNormalAngle = outline.getNormalAngle(noseX); - //Find the point at distance from outline - noseX = noseX - (distanceFromRail *Math.sin(noseNormalAngle)); - - //Get the nose piece rear end pos - double nosePieceRearX = brd.getLength() - 9.0*UnitUtils.INCH ; - double nosePieceRearDeck = BezierBoardDrawUtil.getRailDeck(brd, nosePieceRearX, distanceFromRail, skinThickness); - double nosePieceRearBottom = BezierBoardDrawUtil.getRailBottom(brd, nosePieceRearX, distanceFromRail, skinThickness); - double nosePieceRearZ = (nosePieceRearDeck +nosePieceRearBottom)/2.0; - double nosePieceRearNormalAngle = outline.getNormalAngle(nosePieceRearX); - //Find the point at distance from outline - nosePieceRearX = nosePieceRearX - (distanceFromRail *Math.sin(nosePieceRearNormalAngle)); - - double nosePieceCutoutX = nosePieceRearX + (2.0*UnitUtils.INCH); - double nosePieceCutoutZ = nosePieceRearZ + (2.0*UnitUtils.INCH)/Math.cos(angle)*Math.sin(angle); + double nosePieceLength = 9.0 * UnitUtils.INCH - noseOffset; - double noseEndX = nosePieceRearX + nosePieceLength; - double noseEndZ = nosePieceRearZ + (nosePieceLength)*Math.sin(angle); - - d.setColor(new Color(255,0,0)); - path.moveTo(nosePieceRearX-thicknessXOffset, nosePieceRearZ+thicknessYOffset); - path.lineTo(noseX-thicknessXOffset, noseZ+thicknessYOffset); - path.lineTo(noseX+thicknessXOffset, noseZ-thicknessYOffset); - path.lineTo(nosePieceRearX+thicknessXOffset, nosePieceRearZ-thicknessYOffset); - path.closePath(); - - d.draw(path); - path.reset(); - - d.setColor(new Color(0,255,0)); - path.moveTo(nosePieceCutoutX-thicknessXOffset, nosePieceCutoutZ+thicknessYOffset); - path.lineTo(noseEndX-thicknessXOffset, noseEndZ+thicknessYOffset); - path.lineTo(noseEndX+thicknessXOffset, noseEndZ-thicknessYOffset); - path.lineTo(nosePieceCutoutX+thicknessXOffset, nosePieceCutoutZ-thicknessYOffset); + double angle = getNosePieceStringerAngle(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset); + + double thicknessXOffset = Math.sin(angle) * frameThickness / 2.0; + double thicknessYOffset = Math.cos(angle) * frameThickness / 2.0; + + // Get the nose pos + double noseX = getRailMaxPos(brd, distanceFromRail, skinThickness, + frameThickness, tailOffset, noseOffset); + double noseDeck = BezierBoardDrawUtil.getRailDeck(brd, noseX, + distanceFromRail, skinThickness); + double noseBottom = BezierBoardDrawUtil.getRailBottom(brd, noseX, + distanceFromRail, skinThickness); + double noseZ = (noseDeck + noseBottom) / 2.0; + double noseNormalAngle = outline.getNormalAngle(noseX); + // Find the point at distance from outline + noseX = noseX - (distanceFromRail * Math.sin(noseNormalAngle)); + + // Get the nose piece rear end pos + double nosePieceRearX = brd.getLength() - 9.0 * UnitUtils.INCH; + double nosePieceRearDeck = BezierBoardDrawUtil.getRailDeck(brd, + nosePieceRearX, distanceFromRail, skinThickness); + double nosePieceRearBottom = BezierBoardDrawUtil.getRailBottom(brd, + nosePieceRearX, distanceFromRail, skinThickness); + double nosePieceRearZ = (nosePieceRearDeck + nosePieceRearBottom) / 2.0; + double nosePieceRearNormalAngle = outline + .getNormalAngle(nosePieceRearX); + // Find the point at distance from outline + nosePieceRearX = nosePieceRearX + - (distanceFromRail * Math.sin(nosePieceRearNormalAngle)); + + double nosePieceCutoutX = nosePieceRearX + (2.0 * UnitUtils.INCH); + double nosePieceCutoutZ = nosePieceRearZ + (2.0 * UnitUtils.INCH) + / Math.cos(angle) * Math.sin(angle); + + double noseEndX = brd.getLength() - noseOffset; + double noseEndZ = nosePieceRearZ + (noseEndX - nosePieceRearX) + * Math.sin(angle); + + path.moveTo(nosePieceCutoutX - thicknessXOffset, nosePieceCutoutZ + + thicknessYOffset); + path.lineTo(noseEndX - thicknessXOffset, noseEndZ + thicknessYOffset); + path.lineTo(noseEndX + thicknessXOffset, noseEndZ - thicknessYOffset); + path.lineTo(nosePieceCutoutX + thicknessXOffset, nosePieceCutoutZ + - thicknessYOffset); path.closePath(); d.draw(path); - + d.setTransform(savedTransform); } - public static void printRailNosePieceNotches(AbstractDraw d, double offsetX, double offsetY, double scale, BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double webbing, double tailOffset, double noseOffset) - { - - if(brd.isEmpty()) { + public static void printRailNosePieceNotches(AbstractDraw d, + double offsetX, double offsetY, double scale, double rotation, + BezierBoard brd, double distanceFromRail, double skinThickness, + double frameThickness, double webbing, double tailOffset, + double noseOffset) { + + if (brd.isEmpty()) { return; } - - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, offsetX, offsetY, scale); - Stroke stroke = new BasicStroke((float)(2.0/scale)); + + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(d, + offsetX, offsetY, scale, rotation); + Stroke stroke = new BasicStroke((float) (2.0 / scale)); d.setStroke(stroke); -// d.setColor(new Color(255,0,0)); + d.setColor(new Color(0, 0, 255)); BezierSpline outline = brd.getOutline(); - - System.out.printf("\nRAIL TAIL PIECE NOTCHING\n"); + + System.out.printf("\nRAIL NOSE PIECE NOTCHING\n"); boolean first = true; GeneralPath path = new GeneralPath(); - + double ox = tailOffset; - - double nosePieceLength = 9.0*UnitUtils.INCH - noseOffset; - double span; + double nosePieceLength = 9.0 * UnitUtils.INCH - noseOffset; - double angle = getNosePieceRailAngle(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); + double span; + + double angle = getNosePieceRailAngle(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset); double x = 0.0; - + double endPointX = 0.0; double endPointZ = 0.0; double endPointPos = 0.0; - + double lastX = 0.0; double lastY = 0.0; double lastPos = 0.0; - + double notchX = 0.0; double notchZ = 0.0; - + double thicknessXOffset = 0.0; double thicknessYOffset = 0.0; - + double deck = 0.0; boolean endFound = false; - for(int n = 0; n < 6; n++) - { - if(nosePieceLength > 5.0*UnitUtils.INCH) - { - switch(n) - { + for (int n = 0; n < 6; n++) { + if (nosePieceLength > 5.0 * UnitUtils.INCH) { + switch (n) { case 0: - span = brd.getLength() - 9.0*UnitUtils.INCH; + span = brd.getLength() - 9.0 * UnitUtils.INCH - noseOffset; break; case 1: - case 2: + case 2: case 4: case 5: - span = 1.0*UnitUtils.INCH; + span = 1.0 * UnitUtils.INCH; break; default: - span = nosePieceLength - 4.0*UnitUtils.INCH; + span = nosePieceLength - 4.0 * UnitUtils.INCH; break; } - } - else - { - if(n == 0){ - span = brd.getLength() - 9.0*UnitUtils.INCH - noseOffset; - } - else - { - span = (n+1)/5.0*nosePieceLength; + } else { + if (n == 0) { + span = brd.getLength() - 9.0 * UnitUtils.INCH - noseOffset; + } else { + span = (n + 1) / 5.0 * nosePieceLength; } } - - int steps = (int)(span/0.5); - double step = span/steps; + int steps = (int) (span / 0.5); + double step = span / steps; -/* System.out.printf("n: %d, span: %f, steps: %d, step: %f\n", n, span, steps, step);*/ + /* + * System.out.printf("n: %d, span: %f, steps: %d, step: %f\n", n, + * span, steps, step); + */ double bottom = 0.0; - for(int i = 0; i < steps; i++) - { - //Get the outline point and the angle + for (int i = 0; i < steps; i++) { + // Get the outline point and the angle double oy = outline.getValueAt(ox); double normalAngle = outline.getNormalAngle(ox); - - //Find the point at distance from outline - x = ox - (distanceFromRail *Math.sin(normalAngle)); - double y = oy - (distanceFromRail*Math.cos(normalAngle)); - - if(first && y < 0) - { + + // Find the point at distance from outline + x = ox - (distanceFromRail * Math.sin(normalAngle)); + double y = oy + (distanceFromRail * Math.cos(normalAngle)); + + if (first && y < 0) { ox += step; continue; } - - if(!first && y < 0) + + if (!first && y < 0) break; - - //Find thickness and rocker at pos - deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness); - bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness); - - if(deck < bottom) - { + + // Find thickness and rocker at pos + deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, x, + y, skinThickness); + bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation(brd, + x, y, skinThickness); + + if (deck < bottom) { ox += step; continue; } - - if(deck < bottom) - { + + if (deck < bottom) { break; } - - if(n > 0){ - //Find stringer thickness and rocker at pos - double deckAtStringer = BezierBoardDrawUtil.getDeck(brd, ox, 0.0, skinThickness); - double bottomAtStringer = BezierBoardDrawUtil.getBottom(brd, ox, 0.0, skinThickness); - - if(deckAtStringer < bottomAtStringer) - { - // break; + + if (n > 0) { + // Find stringer thickness and rocker at pos + double deckAtStringer = BezierBoardDrawUtil + .getDeckWithSkinCompensation(brd, ox, 0.0, + skinThickness); + double bottomAtStringer = BezierBoardDrawUtil + .getBottomWithSkinCompensation(brd, ox, 0.0, + skinThickness); + + if (deckAtStringer < bottomAtStringer) { + // break; } } - if(!endFound && n>0) - { - double z1 = (bottom+deck)/2.0; - + if (!endFound && n > 0) { + double z1 = (bottom + deck) / 2.0; + endPointX = ox; endPointZ = z1; endPointPos = lastPos; first = false; - /* - Line2D.Double point = new Line2D.Double(); - point.setLine(lastPos, endPointZ,lastPos, endPointZ); - d.draw(point); -*/ - thicknessXOffset = Math.sin(angle)*frameThickness/2.0; - thicknessYOffset = Math.cos(angle)*frameThickness/2.0; - + /* + * Line2D.Double point = new Line2D.Double(); + * point.setLine(lastPos, endPointZ,lastPos, endPointZ); + * d.draw(point); + */ + thicknessXOffset = Math.sin(angle) * frameThickness / 2.0; + thicknessYOffset = Math.cos(angle) * frameThickness / 2.0; + endFound = true; } - if(!first) - { - //Find the 2D length from the last point on deck and bottom - double xd = x-lastX; - double yd = y-lastY; - double stepLength = Math.sqrt((xd*xd)+(yd*yd)); - + if (!first) { + // Find the 2D length from the last point on deck and bottom + double xd = x - lastX; + double yd = y - lastY; + double stepLength = Math.sqrt((xd * xd) + (yd * yd)); + double newPos = lastPos + stepLength; - /* - Line2D.Double line = new Line2D.Double(); - line.setLine(lastPos, bottom, newPos, bottom); - d.draw(line); -*/ - //Update last pos + /* + * Line2D.Double line = new Line2D.Double(); + * line.setLine(lastPos, bottom, newPos, bottom); + * d.draw(line); + */ + // Update last pos lastPos = newPos; - } - else - { + } else { first = false; } - /*Debug*/ - + /* Debug */ + lastX = x; lastY = y; - + ox += step; } - -/* System.out.printf("-------------------spanned: %f\n", ox-temp);*/ -/* - Line2D.Double line = new Line2D.Double(); - line.setLine(lastPos, deck, lastPos, deck + 8.0); - d.draw(line); -*/ - System.out.printf("ox: %f, x: %f, lastPos: %f deck:%f bottom:%f\n", ox, x, lastPos,deck,bottom); - - //Check if we should store pos - if(n%2==1) - { - //Store for notching + + /* System.out.printf("-------------------spanned: %f\n", ox-temp); */ + /* + * Line2D.Double line = new Line2D.Double(); line.setLine(lastPos, + * deck, lastPos, deck + 8.0); d.draw(line); + */ + System.out.printf("ox: %f, x: %f, lastPos: %f deck:%f bottom:%f\n", + ox, x, lastPos, deck, bottom); + + // Check if we should store pos + if (n % 2 == 1) { + // Store for notching notchX = lastPos; - notchZ = endPointZ + (((ox - endPointX)/Math.cos(angle))*Math.sin(angle)); -/* System.out.printf("notchX: %f, notchY: %f\n", notchX, notchZ);*/ - -/* Line2D.Double line = new Line2D.Double(); - line.setLine(notchX, notchZ, notchX, notchZ); - d.draw(line); -*/ } - else if(n%2==0 && n > 0) - { + notchZ = endPointZ + + (((ox - endPointX) / Math.cos(angle)) * Math + .sin(angle)); + /* + * System.out.printf("notchX: %f, notchY: %f\n", notchX, + * notchZ); + */ + + /* + * Line2D.Double line = new Line2D.Double(); + * line.setLine(notchX, notchZ, notchX, notchZ); d.draw(line); + */} else if (n % 2 == 0 && n > 0) { double otherEndX = lastPos; - double otherEndZ = endPointZ + (((ox - endPointX)/Math.cos(angle))*Math.sin(angle)); -/* System.out.printf("otherEndX: %f, otherEndZ: %f\n", otherEndX, otherEndZ);*/ -/* - Line2D.Double line = new Line2D.Double(); - line.setLine(otherEndX, otherEndZ, otherEndX, otherEndZ); - d.draw(line); - path.moveTo(notchX, notchZ); - path.lineTo(otherEndX, otherEndZ);*/ - d.setColor(new Color(255,0,0)); - path.moveTo(notchX-thicknessXOffset, notchZ+thicknessYOffset); - path.lineTo(otherEndX-thicknessXOffset, otherEndZ+thicknessYOffset); - path.lineTo(endPointX + otherEndX+thicknessXOffset - endPointX, otherEndZ-thicknessYOffset); - path.lineTo(endPointX + notchX+thicknessXOffset - endPointX, notchZ-thicknessYOffset); - - System.out.printf("notchX:%f notchZ:%f otherEndX:%f otherEndZ:%f\n", notchX, notchZ, otherEndX, otherEndZ); + double otherEndZ = endPointZ + + (((ox - endPointX) / Math.cos(angle)) * Math + .sin(angle)); + /* + * System.out.printf("otherEndX: %f, otherEndZ: %f\n", + * otherEndX, otherEndZ); + */ + /* + * Line2D.Double line = new Line2D.Double(); + * line.setLine(otherEndX, otherEndZ, otherEndX, otherEndZ); + * d.draw(line); path.moveTo(notchX, notchZ); + * path.lineTo(otherEndX, otherEndZ); + */ + d.setColor(new Color(255, 0, 0)); + path.moveTo(notchX - thicknessXOffset, notchZ + + thicknessYOffset); + path.lineTo(otherEndX - thicknessXOffset, otherEndZ + + thicknessYOffset); + path.lineTo(endPointX + otherEndX + thicknessXOffset + - endPointX, otherEndZ - thicknessYOffset); + path.lineTo(endPointX + notchX + thicknessXOffset - endPointX, + notchZ - thicknessYOffset); + + System.out.printf( + "notchX:%f notchZ:%f otherEndX:%f otherEndZ:%f\n", + notchX, notchZ, otherEndX, otherEndZ); path.closePath(); d.draw(path); - + path.reset(); } - - } -/* Line2D.Double line = new Line2D.Double(); - d.setColor(new Color(0,255,0)); - line.setLine(endPointPos, endPointZ, lastPos, deck+bottom/2); - d.draw(line); - - d.setColor(new Color(0,0,255)); - line.setLine(endPointPos, endPointZ, lastPos, endPointZ + (((ox-step-endPointX)/Math.cos(angle))*Math.sin(angle))); - d.draw(line); -*/ + } + /* + * Line2D.Double line = new Line2D.Double(); d.setColor(new + * Color(0,255,0)); line.setLine(endPointPos, endPointZ, lastPos, + * deck+bottom/2); d.draw(line); + * + * d.setColor(new Color(0,0,255)); line.setLine(endPointPos, endPointZ, + * lastPos, endPointZ + + * (((ox-step-endPointX)/Math.cos(angle))*Math.sin(angle))); + * d.draw(line); + */ d.setTransform(savedTransform); } - - //helper functions - static double getTailPieceStringerAngle(BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double tailOffset, double noseOffset){ - + + // helper functions + static double getTailPieceStringerAngle(BezierBoard brd, + double distanceFromRail, double skinThickness, + double frameThickness, double tailOffset, double noseOffset) { + BezierSpline outline = brd.getOutline(); - - //Get the tail pos - double tailX = getRailMinPos(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); - double tailDeck = BezierBoardDrawUtil.getRailDeck(brd, tailX, distanceFromRail, skinThickness); - double tailBottom = BezierBoardDrawUtil.getRailBottom(brd, tailX, distanceFromRail, skinThickness); - double tailZ = (tailDeck +tailBottom)/2.0; - double tailNormalAngle = outline.getNormalAngle(tailX); - tailX = tailX - (distanceFromRail *Math.sin(tailNormalAngle)); - - //Get the second tail pos - double tailPieceFrontX = 9.0*UnitUtils.INCH; + + // Get the tail pos + double railMin = getRailMinPos(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); + System.out.printf("getTailPieceStringerAngle() railMin:%f\n", railMin); + double tailDeck = BezierBoardDrawUtil.getRailDeck(brd, railMin, distanceFromRail, skinThickness); + double tailBottom = BezierBoardDrawUtil.getRailBottom(brd, railMin, distanceFromRail, skinThickness); + double tailZ = (tailDeck + tailBottom) / 2.0; + double tailNormalAngle = outline.getNormalAngle(railMin); + System.out.printf("getTailPieceStringerAngle() distanceFromRail:%f tailNormalAngle:%f\n", distanceFromRail, Math.toDegrees(tailNormalAngle)); + double tailX = railMin - (distanceFromRail * Math.sin(tailNormalAngle)); + System.out.printf("getTailPieceStringerAngle() tailDeck:%f tailBottom:%f\n", tailDeck, tailBottom); + System.out.printf("getTailPieceStringerAngle() tailX:%f tailZ:%f\n", tailX, tailZ); + + // Get the second tail pos + double tailPieceFrontX = 9.0 * UnitUtils.INCH; + System.out.printf( "getTailPieceStringerAngle() tailPieceFrontX:%f\n", tailPieceFrontX); double tailPieceFrontDeck = BezierBoardDrawUtil.getRailDeck(brd, tailPieceFrontX, distanceFromRail, skinThickness); double tailPieceFrontBottom = BezierBoardDrawUtil.getRailBottom(brd, tailPieceFrontX, distanceFromRail, skinThickness); - double tailPieceFrontZ = (tailPieceFrontDeck +tailPieceFrontBottom)/2.0; - double tailPieceFrontNormalAngle = outline.getNormalAngle(tailPieceFrontX); - //Find the point at distance from outline - tailPieceFrontX = tailPieceFrontX - (distanceFromRail *Math.sin(tailPieceFrontNormalAngle)); - - //Calculate angle - double angle = Math.atan2(tailPieceFrontZ-tailZ, tailPieceFrontX - tailX); - - return angle; - } + System.out.printf("getTailPieceStringerAngle() tailPieceFrontDeck:%f tailPieceFrontBottom:%f\n", tailPieceFrontDeck, tailPieceFrontBottom); - static double getTailPieceRailAngle(BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double tailOffset, double noseOffset){ - - //Calculate angle - double angle = getTailPieceStringerAngle(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); + double tailPieceFrontZ = (tailPieceFrontDeck + tailPieceFrontBottom) / 2.0; + double tailPieceFrontNormalAngle = outline.getNormalAngle(tailPieceFrontX); + // Find the point at distance from outline + System.out.printf( "getTailPieceStringerAngle() tailPieceFrontNormalAngle:%f\n", Math.toDegrees(tailPieceFrontNormalAngle)); + tailPieceFrontX = tailPieceFrontX - (distanceFromRail * Math.sin(tailPieceFrontNormalAngle)); + System.out.printf( "getTailPieceStringerAngle() tailPieceFrontX:%f tailPieceFrontZ:%f\n", tailPieceFrontX, tailPieceFrontZ); + + // Calculate angle + double h = tailPieceFrontZ - tailZ; + double w = tailPieceFrontX - tailX; + System.out.printf("getTailPieceStringerAngle() h:%f w:%f\n", h, w); +// double angle = Math.atan2(tailPieceFrontZ - tailZ, tailPieceFrontX - tailX); + double angle = Math.atan2(h, w); + System.out.printf("getTailPieceStringerAngle() angle:%f\n", Math.toDegrees(angle)); + return angle; } - static double getNosePieceStringerAngle(BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double tailOffset, double noseOffset){ + static double getNosePieceStringerAngle(BezierBoard brd, + double distanceFromRail, double skinThickness, + double frameThickness, double tailOffset, double noseOffset) { BezierSpline outline = brd.getOutline(); - //Get the nose pos - double noseX = getRailMaxPos(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); - double noseDeck = BezierBoardDrawUtil.getRailDeck(brd, noseX, distanceFromRail, skinThickness); - double noseBottom = BezierBoardDrawUtil.getRailBottom(brd, noseX, distanceFromRail, skinThickness); - double noseZ = (noseDeck +noseBottom)/2.0; + // Get the nose pos + double noseX = getRailMaxPos(brd, distanceFromRail, skinThickness, + frameThickness, tailOffset, noseOffset); + double noseDeck = BezierBoardDrawUtil.getRailDeck(brd, noseX, + distanceFromRail, skinThickness); + double noseBottom = BezierBoardDrawUtil.getRailBottom(brd, noseX, + distanceFromRail, skinThickness); + double noseZ = (noseDeck + noseBottom) / 2.0; double noseNormalAngle = outline.getNormalAngle(noseX); - noseX = noseX - (distanceFromRail *Math.sin(noseNormalAngle)); - - //Get the nose piece rear end pos - double nosePieceRearX = brd.getLength() - 9.0*UnitUtils.INCH ; - double nosePieceRearDeck = BezierBoardDrawUtil.getRailDeck(brd, nosePieceRearX, distanceFromRail, skinThickness); - double nosePieceRearBottom = BezierBoardDrawUtil.getRailBottom(brd, nosePieceRearX, distanceFromRail, skinThickness); - double nosePieceRearZ = (nosePieceRearDeck +nosePieceRearBottom)/2.0; - double nosePieceRearNormalAngle = outline.getNormalAngle(nosePieceRearX); - //Find the point at distance from outline - nosePieceRearX = nosePieceRearX - (distanceFromRail *Math.sin(nosePieceRearNormalAngle)); - - //Calculate angle - double angle = Math.atan2(noseZ-nosePieceRearZ, noseX - nosePieceRearX); - + noseX = noseX - (distanceFromRail * Math.sin(noseNormalAngle)); + + // Get the nose piece rear end pos + double nosePieceRearX = brd.getLength() - 9.0 * UnitUtils.INCH; + double nosePieceRearDeck = BezierBoardDrawUtil.getRailDeck(brd, + nosePieceRearX, distanceFromRail, skinThickness); + double nosePieceRearBottom = BezierBoardDrawUtil.getRailBottom(brd, + nosePieceRearX, distanceFromRail, skinThickness); + double nosePieceRearZ = (nosePieceRearDeck + nosePieceRearBottom) / 2.0; + double nosePieceRearNormalAngle = outline + .getNormalAngle(nosePieceRearX); + // Find the point at distance from outline + nosePieceRearX = nosePieceRearX + - (distanceFromRail * Math.sin(nosePieceRearNormalAngle)); + + // Calculate angle + double angle = Math.atan2(noseZ - nosePieceRearZ, noseX + - nosePieceRearX); + System.out.printf("\noseZ:%f\n", noseZ); + System.out.printf("nosePieceRearZ:%f\n", nosePieceRearZ); + System.out.printf("noseX:%f\n", noseX); + System.out.printf("nosePieceRearX:%f\n", nosePieceRearX); + System.out.printf("angle:%f\n", angle); + return angle; - + } - static double getNosePieceRailAngle(BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double tailOffset, double noseOffset){ - double angle = getNosePieceStringerAngle(brd, distanceFromRail, skinThickness, frameThickness, tailOffset, noseOffset); - - System.out.printf("getNosePieceRailAngle() Angle: %f\n", angle*180.0/Math.PI); -/* - double endz = nosePieceRearZ + (((nosePieceRailLength)/Math.cos(angle))*Math.sin(angle)); - System.out.printf("getNosePieceRailAngle() endz: %f\n", endz); -*/ + static double getNosePieceRailAngle(BezierBoard brd, + double distanceFromRail, double skinThickness, + double frameThickness, double tailOffset, double noseOffset) { + double angle = getNosePieceStringerAngle(brd, distanceFromRail, + skinThickness, frameThickness, tailOffset, noseOffset); + + System.out.printf("getNosePieceRailAngle() Angle: %f\n", angle * 180.0 + / Math.PI); + /* + * double endz = nosePieceRearZ + + * (((nosePieceRailLength)/Math.cos(angle))*Math.sin(angle)); + * System.out.printf("getNosePieceRailAngle() endz: %f\n", endz); + */ return angle; } - - static double getRailMinPos(BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double tailOffset, double noseOffset){ + + static double getRailMinPos(BezierBoard brd, double distanceFromRail, + double skinThickness, double frameThickness, double tailOffset, + double noseOffset) { double ox = tailOffset; double oy = 0.0; - + double x = 0.0; double y = 0.0; - + double normalAngle = 0.0; - - double span = brd.getLength(); - - int steps = (int)(span/0.5); - double step = span/steps; + + double span = brd.getLength(); + + int steps = (int) (span / 0.5); + double step = span / steps; BezierSpline outline = brd.getOutline(); - - for(int i = 0; i < steps; i++) - { - //Get the outline point and the angle + + for (int i = 0; i < steps; i++) { + // Get the outline point and the angle oy = outline.getValueAt(ox); normalAngle = outline.getNormalAngle(ox); - - //Find the point at distance from outline - x = ox - (distanceFromRail*Math.sin(normalAngle)); - y = oy - (distanceFromRail*Math.cos(normalAngle)); - if(y < 0) - { + // Find the point at distance from outline + x = ox - (distanceFromRail * Math.sin(normalAngle)); + y = oy - (distanceFromRail * Math.cos(normalAngle)); + + if (y < 0) { ox += step; continue; } - //Find thickness and rocker at pos - double deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness); - double bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness); + // Find thickness and rocker at pos + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, + x, y, skinThickness); + double bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation( + brd, x, y, skinThickness); - if(deck < bottom) - { + if (deck < bottom) { ox += step; continue; } - + break; } return ox; } - static double getRailMaxPos(BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double tailOffset, double noseOffset) - { + static double getRailMaxPos(BezierBoard brd, double distanceFromRail, + double skinThickness, double frameThickness, double tailOffset, + double noseOffset) { double ox = brd.getLength() - noseOffset; double oy = 0.0; - + double x = 0.0; double y = 0.0; - + double normalAngle = 0.0; - - double span = brd.getLength() - noseOffset - tailOffset; - - int steps = (int)(span/0.5); - double step = span/steps; + + double span = brd.getLength() - noseOffset - tailOffset; + + int steps = (int) (span / 0.5); + double step = span / steps; BezierSpline outline = brd.getOutline(); - - for(int i = 0; i < steps; i++) - { - //Get the outline point and the angle + + for (int i = 0; i < steps; i++) { + // Get the outline point and the angle oy = outline.getValueAt(ox); normalAngle = outline.getNormalAngle(ox); - - //Find the point at distance from outline - x = ox - (distanceFromRail*Math.sin(normalAngle)); - y = oy - (distanceFromRail*Math.cos(normalAngle)); - if(y < 0) - { + // Find the point at distance from outline + x = ox - (distanceFromRail * Math.sin(normalAngle)); + y = oy - (distanceFromRail * Math.cos(normalAngle)); + + if (y < 0) { ox -= step; continue; } - //Find thickness and rocker at pos - double deck = BezierBoardDrawUtil.getDeck(brd, x, y, skinThickness); - double bottom = BezierBoardDrawUtil.getBottom(brd, x, y, skinThickness); + // Find thickness and rocker at pos + double deck = BezierBoardDrawUtil.getDeckWithSkinCompensation(brd, + x, y, skinThickness); + double bottom = BezierBoardDrawUtil.getBottomWithSkinCompensation( + brd, x, y, skinThickness); - if(deck > bottom) - { + if (deck > bottom) { break; } @@ -2533,59 +2766,56 @@ static double getRailMaxPos(BezierBoard brd, double distanceFromRail, double ski return ox; } - static double getRailLength(BezierBoard brd, double distanceFromRail, double skinThickness, double frameThickness, double tailOffset, double noseOffset, double from, double to) - { + static double getRailLength(BezierBoard brd, double distanceFromRail, + double skinThickness, double frameThickness, double tailOffset, + double noseOffset, double from, double to) { double ox = from; double oy = 0.0; - + double x = 0.0; double y = 0.0; - + double normalAngle = 0.0; - - double span = to-from; - - int steps = (int)(span/0.5); - double step = span/steps; + + double span = to - from; + + int steps = (int) (span / 0.5); + double step = span / steps; BezierSpline outline = brd.getOutline(); boolean first = true; double lastX = 0.0; double lastY = 0.0; - double lastPos = 0.0; - for(int i = 0; i < steps; i++) - { - //Get the outline point and the angle + double length = 0.0; + for (int i = 0; i < steps; i++) { + // Get the outline point and the angle oy = outline.getValueAt(ox); normalAngle = outline.getNormalAngle(ox); - - //Find the point at distance from outline - x = ox - (distanceFromRail*Math.sin(normalAngle)); - y = oy - (distanceFromRail*Math.cos(normalAngle)); - if(!first) - { - double xd = x-lastX; - double yd = y-lastY; - double stepLength = Math.sqrt((xd*xd)+(yd*yd)); - - double newPos = lastPos + stepLength; - - //Update last pos - lastPos = newPos; - } - else - { + // Find the point at distance from outline + x = ox - (distanceFromRail * Math.sin(normalAngle)); + y = oy - (distanceFromRail * Math.cos(normalAngle)); + + if (!first) { + double xd = x - lastX; + double yd = y - lastY; + double stepLength = Math.sqrt((xd * xd) + (yd * yd)); + + double newLength = length + stepLength; + + // Update last pos + length = newLength; + } else { first = false; } - + lastX = x; lastY = y; - + ox += step; } - return lastPos; + return length; } - + } diff --git a/boardcad/print/PrintSandwichTemplates.java b/boardcad/print/PrintSandwichTemplates.java index 0a2f40a..da217e1 100644 --- a/boardcad/print/PrintSandwichTemplates.java +++ b/boardcad/print/PrintSandwichTemplates.java @@ -259,9 +259,9 @@ public void paintComponent(Graphics g) { // BezierBoardDrawUtil.printBottomSkinTemplate(jd, border, dim.height*4.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 3.0); // BezierBoardDrawUtil.printCrossSection(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 50.0, 3.0, 0.8); // BezierBoardDrawUtil.printCrossSection(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 50.0); - BezierBoardDrawUtil.printProfile(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), false,BoardCAD.getInstance().getCurrentBrd(), 0.0, 0.0, false, 0.0, 0.0); - BezierBoardDrawUtil.printProfile(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 5.0, 0.0, false, 0.0, 0.0); - BezierBoardDrawUtil.printProfile(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 20.0, 0.0, false, 0.0, 0.0); + BezierBoardDrawUtil.printProfile(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), 0.0, false,BoardCAD.getInstance().getCurrentBrd(), 0.0, 0.0, false, 0.0, 0.0); + BezierBoardDrawUtil.printProfile(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), 0.0, true,BoardCAD.getInstance().getCurrentBrd(), 5.0, 0.0, false, 0.0, 0.0); + BezierBoardDrawUtil.printProfile(jd, border, dim.height*2.0/5.0, (dim.width-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), 0.0, true,BoardCAD.getInstance().getCurrentBrd(), 20.0, 0.0, false, 0.0, 0.0); } @@ -368,7 +368,7 @@ int printProfileTemplate(PageFormat pageFormat, int pageIndex, Graphics g) BezierBoardDrawUtil.printProfile(new JavaDraw(g2d), -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), mProfileOffset, mSkinThickness, mFlatten, 0.0, 0.0); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), mProfileOffset, mSkinThickness, mFlatten, 0.0, 0.0); return 0; } @@ -412,7 +412,7 @@ int printRailTemplate(PageFormat pageFormat, int pageIndex, Graphics g) BezierBoardDrawUtil.printRailTemplate(new JavaDraw(g2d), -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mTailOffset, mNoseOffset, mFlatten); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail, mSkinThickness, mTailOffset, mNoseOffset, mFlatten); return 0; } @@ -456,7 +456,7 @@ int printDeckSkinTemplate(PageFormat pageFormat, int pageIndex, Graphics g) BezierBoardDrawUtil.printDeckSkinTemplate(new JavaDraw(g2d), -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail); return 0; } @@ -500,7 +500,7 @@ int printBottomSkinTemplate(PageFormat pageFormat, int pageIndex, Graphics g) BezierBoardDrawUtil.printBottomSkinTemplate(new JavaDraw(g2d), -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), mDistanceToRail); return 0; } @@ -544,11 +544,11 @@ int printCrosssectionTemplate(PageFormat pageFormat, int pageIndex, Graphics g) BezierBoardDrawUtil.printCrossSection(new JavaDraw(g2d), -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), mCrosssectionPos, mDistanceToRail, mSkinThickness); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), mCrosssectionPos, mDistanceToRail, mSkinThickness); BezierBoardDrawUtil.printCrossSection(new JavaDraw(g2d), -pageFormat.getImageableWidth()*(pageIndex%widthInPages), - -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, true, BoardCAD.getInstance().getCurrentBrd(), mCrosssectionPos); + -pageFormat.getImageableHeight()*(pageIndex/widthInPages), 72/2.54, 0.0, true, BoardCAD.getInstance().getCurrentBrd(), mCrosssectionPos); return 0; } diff --git a/boardcad/print/PrintSpecSheet.java b/boardcad/print/PrintSpecSheet.java index ff3e538..d256fc6 100644 --- a/boardcad/print/PrintSpecSheet.java +++ b/boardcad/print/PrintSpecSheet.java @@ -192,18 +192,18 @@ public void paintComponent(Graphics g) { format.setPaper(paper); // printDetailedSpecSheet(format, 0, g2d); printNewSpecSheet(format, 0, g2d); -// BezierBoardDrawUtil.printOutline(jd, border, dim.height*1.0/5.0, 0.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true, BoardCAD.getInstance().getCurrentBrd(), false, false); -// BezierBoardDrawUtil.printOutlineOverCurve(jd, border, dim.height*1.0/5.0, 0.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true, BoardCAD.getInstance().getCurrentBrd(), false, false, false, false); +// BezierBoardDrawUtil.printOutline(jd, border, dim.height*1.0/5.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()),0.0, true, BoardCAD.getInstance().getCurrentBrd(), false, false); +// BezierBoardDrawUtil.printOutlineOverCurve(jd, border, dim.height*1.0/5.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), 0.0, true, BoardCAD.getInstance().getCurrentBrd(), false, false, false, false); -// BezierBoardDrawUtil.printSpinTemplate(jd, border, dim.height*2.0/5.0, 0.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true, BoardCAD.getInstance().getCurrentBrd(), false, false); -// BezierBoardDrawUtil.printSpinTemplateOverCurve(jd, border, dim.height*2.0/5.0, 0.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true, BoardCAD.getInstance().getCurrentBrd(), false, false); +// BezierBoardDrawUtil.printSpinTemplate(jd, border, dim.height*2.0/5.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), 0.0, true, BoardCAD.getInstance().getCurrentBrd(), false, false); +// BezierBoardDrawUtil.printSpinTemplateOverCurve(jd, border, dim.height*2.0/5.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()),0.0, true, BoardCAD.getInstance().getCurrentBrd(), false, false); /* - BezierBoardDrawUtil.printProfile(jd, border, dim.height*3.0/5.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(),false); - BezierBoardDrawUtil.printRailTemplate(jd, border, dim.height*3.0/5.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), 3.0); + BezierBoardDrawUtil.printProfile(jd, border, dim.height*3.0/5.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()),0.0, true,BoardCAD.getInstance().getCurrentBrd(),false); + BezierBoardDrawUtil.printRailTemplate(jd, border, dim.height*3.0/5.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()),0.0, true,BoardCAD.getInstance().getCurrentBrd(), 3.0); for(int i = 1; i < BoardCAD.getInstance().getCurrentBrd().getCrossSections().size()-1; i++) { - BezierBoardDrawUtil.printSlice(jd, border, dim.height*4.0/5.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()), true,BoardCAD.getInstance().getCurrentBrd(), i,false); + BezierBoardDrawUtil.printSlice(jd, border, dim.height*4.0/5.0, (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()),0.0, true,BoardCAD.getInstance().getCurrentBrd(), i,false); } final BezierSpline p = BoardCAD.getInstance().getCurrentBrd().getInterpolatedCrossSection(BoardCAD.getInstance().getCurrentBrd().getLength()/2.0).getBezierSpline(); @@ -212,7 +212,7 @@ public void paintComponent(Graphics g) { double mScale = (dim.mImagableWidth-(border*2))/(BoardCAD.getInstance().getCurrentBrd().getLength()); - BezierBoardDrawUtil.paintFunction(jd, border, dim.height/2.0, mScale, new Color(0,0,0), new BasicStroke((float)(2.0/mScale)), func, 0.0, 1.0, 200.0, 10.0); + BezierBoardDrawUtil.paintFunction(jd, border, dim.height/2.0, mScale,0.0, new Color(0,0,0), new BasicStroke((float)(2.0/mScale)), func, 0.0, 1.0, 200.0, 10.0); */ } @@ -315,7 +315,7 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) Line2D.Double line = new Line2D.Double(); JavaDraw jd = new JavaDraw(g2d); - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, mScale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, mScale, 0.0); g2d.setStroke(linestroke); g2d.setColor(Color.GRAY); @@ -350,8 +350,8 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) g2d.setTransform(savedTransform); Stroke stroke = new BasicStroke((float)(1.5/mScale)); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, Color.BLACK, stroke, mBrd.getOutline(), BezierBoardDrawUtil.MirrorY, false); - BezierBoardDrawUtil.paintFins(jd, xm+5, currentY, mScale, Color.BLACK, stroke, mBrd.getFins(), false,false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getOutline(), BezierBoardDrawUtil.MirrorY, false); + BezierBoardDrawUtil.paintFins(jd, xm+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getFins(), false,false); currentY += (mBrd.getCenterWidth()/2)*mScale + hgt + 5; @@ -379,7 +379,7 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) currentY += mBrd.getMaxRocker()*mScale +10; - savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, mScale); + savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, mScale, 0.0); g2d.setStroke(linestroke); line.setLine(tailpos, -(tailThickness+tail1Rocker), tailpos, -tail1Rocker); @@ -401,8 +401,8 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) g2d.setTransform(savedTransform); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, Color.BLACK, stroke, mBrd.getDeck(), BezierBoardDrawUtil.FlipY, false); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, Color.BLACK, stroke, mBrd.getBottom(), BezierBoardDrawUtil.FlipY, false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getDeck(), BezierBoardDrawUtil.FlipY, false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getBottom(), BezierBoardDrawUtil.FlipY, false); currentY += hgt + 5; @@ -441,7 +441,7 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) currentY += mBrd.getThickness()*mScale + 5; - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+mImagableWidth/2, currentY, 0.0, mScale, Color.BLACK, linestroke, false, true, mBrd.getLength()/2, mBrd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+mImagableWidth/2, currentY, mScale, 0.0, Color.BLACK, linestroke, false, true, mBrd.getLength()/2, mBrd); currentY += hgt; @@ -451,9 +451,9 @@ int printSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) currentY += hgt+10; - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((mImagableWidth/3)*1), currentY, 0.0, mScale, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((mImagableWidth/3)*1), currentY, mScale, 0.0, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((mImagableWidth/3)*2), currentY, 0.0, mScale, Color.BLACK, linestroke, false, true, mBrd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((mImagableWidth/3)*2), currentY, mScale, 0.0, Color.BLACK, linestroke, false, true, mBrd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); currentY += hgt; String tailString = LanguageResource.getString("TAIL_STR"); @@ -602,7 +602,7 @@ int printDetailedSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) Line2D.Double line = new Line2D.Double(); JavaDraw jd = new JavaDraw(g2d); - AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, mScale); + AffineTransform savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, mScale, 0.0); //Outline Crossection lines g2d.setStroke(linestroke); @@ -638,8 +638,8 @@ int printDetailedSpecSheet(PageFormat pageFormat, int pageIndex, Graphics g) g2d.setTransform(savedTransform); Stroke stroke = new BasicStroke((float)(1.5/mScale)); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, Color.BLACK, stroke, mBrd.getOutline(), BezierBoardDrawUtil.MirrorY, false); - BezierBoardDrawUtil.paintFins(jd, xm+5, currentY, mScale, Color.BLACK, stroke, mBrd.getFins(), false,false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getOutline(), BezierBoardDrawUtil.MirrorY, false); + BezierBoardDrawUtil.paintFins(jd, xm+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getFins(), false,false); currentY += (mBrd.getCenterWidth()/2)*mScale + hgt + 5; @@ -685,7 +685,7 @@ else if(i == 3) currentY += mBrd.getMaxRocker()*mScale +10; - savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, mScale); + savedTransform = BezierBoardDrawUtil.setTransform(jd, xm+5, currentY, mScale, 0.0); //Draw lines from numbers g2d.setStroke(linestroke); @@ -708,8 +708,8 @@ else if(i == 3) g2d.setTransform(savedTransform); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, Color.BLACK, stroke, mBrd.getDeck(), BezierBoardDrawUtil.FlipY, false); - BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, Color.BLACK, stroke, mBrd.getBottom(), BezierBoardDrawUtil.FlipY, false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getDeck(), BezierBoardDrawUtil.FlipY, false); + BezierBoardDrawUtil.paintBezierSpline(jd, xm+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getBottom(), BezierBoardDrawUtil.FlipY, false); currentY += hgt + 5; @@ -761,9 +761,9 @@ else if(i == 3) currentY += hgt+10; //Draw - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((mImagableWidth/3)*1), currentY, Math.PI/2.0, mScale, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((mImagableWidth/3)*1), currentY, mScale, Math.PI/2.0, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); - BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((mImagableWidth/3)*2), currentY, Math.PI/2.0, mScale, Color.BLACK, linestroke, false, true, mBrd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, xm+5+((mImagableWidth/3)*2), currentY, mScale, Math.PI/2.0, Color.BLACK, linestroke, false, true, mBrd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, brd); currentY += hgt; String tailString = LanguageResource.getString("TAIL_STR"); @@ -903,8 +903,8 @@ float printBoardHorizontal(Graphics2D g2d, float currentY) //Outline Stroke stroke = new BasicStroke((float)(1.5/mScale)); - BezierBoardDrawUtil.paintBezierSpline(jd, mImagableX+5, currentY, mScale, Color.BLACK, stroke, mBrd.getOutline(), BezierBoardDrawUtil.MirrorY, false); - BezierBoardDrawUtil.paintFins(jd, mImagableX+5, currentY, mScale, Color.BLACK, stroke, mBrd.getFins(), false, false); + BezierBoardDrawUtil.paintBezierSpline(jd, mImagableX+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getOutline(), BezierBoardDrawUtil.MirrorY, false); + BezierBoardDrawUtil.paintFins(jd, mImagableX+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getFins(), false, false); //Stringer Line2D.Double line = new Line2D.Double(); @@ -914,8 +914,8 @@ float printBoardHorizontal(Graphics2D g2d, float currentY) currentY += (mBrd.getCenterWidth()/2)*mScale + mBrd.getMaxRocker()*mScale; //Profile - BezierBoardDrawUtil.paintBezierSpline(jd, mImagableX+5, currentY, mScale, Color.BLACK, stroke, mBrd.getDeck(), BezierBoardDrawUtil.FlipY, false); - BezierBoardDrawUtil.paintBezierSpline(jd, mImagableX+5, currentY, mScale, Color.BLACK, stroke, mBrd.getBottom(), BezierBoardDrawUtil.FlipY, false); + BezierBoardDrawUtil.paintBezierSpline(jd, mImagableX+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getDeck(), BezierBoardDrawUtil.FlipY, false); + BezierBoardDrawUtil.paintBezierSpline(jd, mImagableX+5, currentY, mScale, 0.0, Color.BLACK, stroke, mBrd.getBottom(), BezierBoardDrawUtil.FlipY, false); return currentY; } @@ -1060,7 +1060,7 @@ float printCrossSections(Graphics2D g2d, float currentY) Stroke linestroke = new BasicStroke((float)(1.5/mScale)); - BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+mImagableWidth/2, currentY, 0, mScale, Color.BLACK, linestroke, false, true, mBrd.getLength()/2, mBrd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+mImagableWidth/2, currentY, mScale, 0, Color.BLACK, linestroke, false, true, mBrd.getLength()/2, mBrd); g2d.setFont(mPrintFontNormal); @@ -1073,9 +1073,9 @@ float printCrossSections(Graphics2D g2d, float currentY) currentY += mBrd.getMaxThickness()*mScale; //Draw - BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+((mImagableWidth/3)*1), currentY, 0.0, mScale, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+((mImagableWidth/3)*1), currentY, mScale, 0.0, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); - BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+((mImagableWidth/3)*2), currentY, 0.0, mScale, Color.BLACK, linestroke, false, true, mBrd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+((mImagableWidth/3)*2), currentY, mScale, 0.0, Color.BLACK, linestroke, false, true, mBrd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); currentY += mNormalFontHeight; String tailString = LanguageResource.getString("TAIL_STR"); @@ -1100,7 +1100,7 @@ float printOverlayedCrossSections(Graphics2D g2d, float currentY) Stroke linestroke = new BasicStroke((float)(2.0/mScale)); - BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+mImagableWidth/2, currentY, Math.PI/2.0, mScale, Color.BLACK, linestroke, false, true, mBrd.getLength()/2, mBrd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+mImagableWidth/2, currentY, mScale, Math.PI/2.0, Color.BLACK, linestroke, false, true, mBrd.getLength()/2, mBrd); g2d.setFont(mPrintFontNormal); @@ -1113,9 +1113,9 @@ float printOverlayedCrossSections(Graphics2D g2d, float currentY) currentY += mNormalFontHeight+10; //Draw - BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+((mImagableWidth/3)*1), currentY, Math.PI/2.0, mScale, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+((mImagableWidth/3)*1), currentY, mScale, Math.PI/2.0, Color.BLACK, linestroke, false, true, UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); - BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+((mImagableWidth/3)*2), currentY, Math.PI/2.0, mScale, Color.BLACK, linestroke, false, true, mBrd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); + BezierBoardDrawUtil.paintSlidingCrossSection(jd, mImagableX+5+((mImagableWidth/3)*2), currentY, mScale, Math.PI/2.0, Color.BLACK, linestroke, false, true, mBrd.getLength() - UnitUtils.INCHES_PR_FOOT*UnitUtils.INCH, mBrd); currentY += mNormalFontHeight; String tailString = LanguageResource.getString("TAIL_STR"); diff --git a/boardcad/settings/Settings.java b/boardcad/settings/Settings.java index 1938623..00b1a12 100644 --- a/boardcad/settings/Settings.java +++ b/boardcad/settings/Settings.java @@ -181,6 +181,11 @@ public void setEnumeration(final String key, final int value) { ((Enumeration)mSettings.get(key).mValue).setValue(value); } + + public boolean containsSetting(final String key) + { + return mSettings.containsKey(key); + } public Setting getSetting(final String key) { diff --git a/boardcam/BoardMachine.java b/boardcam/BoardMachine.java index fb42d69..591c1e6 100644 --- a/boardcam/BoardMachine.java +++ b/boardcam/BoardMachine.java @@ -1,6 +1,6 @@ package boardcam; -import cadcore.*; +import cadcore.*; import boardcad.ScriptLoader; import javax.vecmath.*; @@ -20,52 +20,51 @@ public class BoardMachine { public static NurbsSurface deck; public static NurbsSurface bottom; - - public static String deckFileName=new String("deck.ngc"); - public static String bottomFileName=new String("deck.ngc"); - - public static String deckScript; - public static String bottomScript; - - public static int deckCuts; - public static int deckRailCuts; - public static int bottomCuts; - public static int bottomRailCuts; - public static double deckRailAngle; - public static double bottomRailAngle; + + public static String deckFileName=new String("deck.ngc"); + public static String bottomFileName=new String("deck.ngc"); + + public static String deckScript; + public static String bottomScript; + + public static int deckCuts; + public static int deckRailCuts; + public static int bottomCuts; + public static int bottomRailCuts; + public static double deckRailAngle; + public static double bottomRailAngle; public static double speed; public static double stringerSpeed; - public static double outlineSpeed; - + public static double outlineSpeed; + public static boolean cutStringer; public static double stringerOffset; - public static double stringerCutoff; + public static double stringerCutoff; public static double outlineOffset; - public static String toolName; + public static String toolName; public static double toolScaleX; public static double toolScaleY; public static double toolScaleZ; - - public static double zMaxHeight; - + + public static double zMaxHeight; + public static double[][] machineCoordinates; public static double[] endSupportPosition; public static NurbsPoint support1; public static double support1_radius; public static NurbsPoint support2; public static double support2_radius; - + public static NurbsPoint scan_coord; public static double scan_comp; public static String scan_path; public static NurbsPoint axis4_offset; public static double axis4_offsetRotation; - public static double axis5_offsetRotation; public static double axis4_rail_start; public static double axis4_rail_stop; - + // public boolean check_collision; // public String collision_toolname; // public double collision_toolscale_x; @@ -89,9 +88,9 @@ public class BoardMachine deck_collision=new boolean[100000]; nr_of_cuts_bottom=0; nr_of_cuts_deck=0; - deckFileName=new String("deck.ngc"); - bottomFileName=new String("bottom.ngc"); - + deckFileName=new String("deck.ngc"); + bottomFileName=new String("bottom.ngc"); + read_machine_data(); } */ @@ -102,9 +101,9 @@ public class BoardMachine * @param filename */ public static void generateGCodeDeck(String filename) - { - read_machine_data(); - deckFileName=new String(filename); + { + read_machine_data(); + deckFileName=new String(filename); ScriptLoader.loadScript(deckScript); } @@ -118,7 +117,7 @@ public static void generateGCodeDeck(String filename) */ public static void generateGCodeBottom(String filename) { - read_machine_data(); + read_machine_data(); bottomFileName=new String(filename); ScriptLoader.loadScript(bottomScript); } @@ -140,12 +139,12 @@ public static void read_machine_data() { // This string is used to read the setting from the properties file. // If a String-to-double parse fails, an exception will occur and // if the string is set to correct value the exception message will - // tell what string that failed. - - // Script files for toolpath generation - deckScript = properties.getProperty("toolpathGenerator.deckScript"); - bottomScript = properties.getProperty("toolpathGenerator.bottomScript"); - + // tell what string that failed. + + // Script files for toolpath generation + deckScript = properties.getProperty("toolpathGenerator.deckScript"); + bottomScript = properties.getProperty("toolpathGenerator.bottomScript"); + // Define number of cuts setting = "Define number of cuts"; deckCuts = Integer.parseInt(properties.getProperty("g.deckCuts")); @@ -154,32 +153,32 @@ public static void read_machine_data() { bottomRailCuts = Integer.parseInt(properties.getProperty("g.bottomRailCuts")); deckRailAngle = Double.parseDouble(properties.getProperty("g.deckRailAngle")); bottomRailAngle = Double.parseDouble(properties.getProperty("g.bottomRailAngle")); - - // Speed for cutting the board + + // Speed for cutting the board setting = "Speed for cutting the board"; speed = Double.parseDouble(properties.getProperty("g.speed")); stringerSpeed = Double.parseDouble(properties.getProperty("g.stringerSpeed")); - outlineSpeed = Double.parseDouble(properties.getProperty("g.outlineSpeed")); - - // Define extra parameters - setting = "Define extra parameters"; + outlineSpeed = Double.parseDouble(properties.getProperty("g.outlineSpeed")); + + // Define extra parameters + setting = "Define extra parameters"; cutStringer = (Integer.parseInt(properties.getProperty("g.cutStringer")) != 0); - stringerOffset=Double.parseDouble(properties.getProperty("g.stringerOffset")); - stringerCutoff=Double.parseDouble(properties.getProperty("g.stringerCutoff")); - outlineOffset=Double.parseDouble(properties.getProperty("g.outlineOffset")); - + stringerOffset=Double.parseDouble(properties.getProperty("g.stringerOffset")); + stringerCutoff=Double.parseDouble(properties.getProperty("g.stringerCutoff")); + outlineOffset=Double.parseDouble(properties.getProperty("g.outlineOffset")); + // Define cutter setting = "Define cutter"; toolName = properties.getProperty("g.toolName"); toolScaleX = Double.parseDouble(properties.getProperty("g.toolScaleX")); toolScaleY = Double.parseDouble(properties.getProperty("g.toolScaleY")); toolScaleZ = Double.parseDouble(properties.getProperty("g.toolScaleZ")); - - // Safe height for traversing, transport etc. + + // Safe height for traversing, transport etc. setting = "Safe height for traversing, transport etc."; zMaxHeight = Double.parseDouble(properties.getProperty("g.zMaxHeight")); - - + + // End support setting = "End support"; double[] t = {Double.parseDouble(properties.getProperty("machine.supportEndX")), @@ -218,14 +217,12 @@ public static void read_machine_data() { // 4-axis settings setting = "4 axis"; + + axis4_offset=new NurbsPoint(Double.parseDouble(properties.getProperty("machine.axis4.offsetX")), + Double.parseDouble(properties.getProperty("machine.axis4.offsetY")), + Double.parseDouble(properties.getProperty("machine.axis4.offsetZ"))); - axis4_offset=new NurbsPoint(Double.parseDouble(properties.getProperty("machine.offsetX")), - Double.parseDouble(properties.getProperty("machine.offsetY")), - Double.parseDouble(properties.getProperty("machine.offsetZ"))); - - axis4_offsetRotation = Double.parseDouble(properties.getProperty("machine.offsetRotation4")); - - axis5_offsetRotation = Double.parseDouble(properties.getProperty("machine.offsetRotation5")); + axis4_offsetRotation = Double.parseDouble(properties.getProperty("machine.axis4.offsetRotation")); // setting = "collision test"; @@ -273,8 +270,7 @@ else if (axis.equals("-Z")) return array; } - - /** + /** * Transform point from machine coordinates to BoardCAD coordinates * * @param p diff --git a/boardcam/MachineConfig.java b/boardcam/MachineConfig.java index e15e659..5f3a2ad 100644 --- a/boardcam/MachineConfig.java +++ b/boardcam/MachineConfig.java @@ -1,53 +1,48 @@ package boardcam; - import java.util.HashMap; - import javax.vecmath.Point3d; -import cadcore.UnitUtils; - - import board.BezierBoard; import boardcad.settings.*; import boardcad.settings.Settings.*; import boardcam.cutters.*; import boardcam.holdingsystems.AbstractBlankHoldingSystem; +import boardcam.holdingsystems.TableBlockHoldingSystem; import boardcam.toolpathgenerators.*; import boardcam.holdingsystems.*; import boardcad.i18n.LanguageResource; import boardcad.FileTools; -import boardcam.writers.GCodeWriter; import boardcam.writers.GCodeWriterWithScaling; -import boardcad.gui.jdk.MachineView; //TODO: Bad dependency +import boardcad.gui.jdk.FasterBrd3DModelGenerator; +import boardcad.gui.jdk.MachineView; //TODO: Bad dependency import board.readers.*; -public class MachineConfig extends CategorizedSettings -{ - public static String USE_BRD_SETTINGS = "UseBrdSettings"; +public class MachineConfig extends CategorizedSettings { + public static String USE_BRD_SETTINGS = "UseBrdSettings"; + + public static String CUTTER_TYPE = "CutterType"; + public static String BLANKHOLDINGSYSTEM_TYPE = "BlankHoldingSystemType"; - public static String CUTTER_TYPE = "CutterType"; - public static String BLANKHOLDINGSYSTEM_TYPE = "BlankHoldingSystemType"; - - public static String DECK_ANGLE = "DeckAngle"; - public static String DECK_RAIL_ANGLE = "DeckRailAngle"; - public static String BOTTOM_ANGLE = "BottomAngle"; + public static String DECK_ANGLE = "DeckAngle"; + public static String DECK_RAIL_ANGLE = "DeckRailAngle"; + public static String BOTTOM_ANGLE = "BottomAngle"; public static String BOTTOM_RAIL_ANGLE = "BottomRailAngle"; public static String LENGTHWISE_RESOLUTION = "LengthwiseResolution"; - - public static String DECK_CUTS = "DeckCuts"; - public static String DECK_RAIL_CUTS = "DeckRailCuts"; - public static String BOTTOM_CUTS = "BottomCuts"; - public static String BOTTOM_RAIL_CUTS = "BottomRailCuts"; - public static String BLANK = "Blank"; + + public static String DECK_CUTS = "DeckCuts"; + public static String DECK_RAIL_CUTS = "DeckRailCuts"; + public static String BOTTOM_CUTS = "BottomCuts"; + public static String BOTTOM_RAIL_CUTS = "BottomRailCuts"; + public static String BLANK = "Blank"; public static String DECK_CLEAN_UP_CUTS = "DeckCleanUpCuts"; public static String BOTTOM_CLEAN_UP_CUTS = "BottomCleanUpCuts"; public static String DECK_STRINGER_CUT = "DeckStringerCut"; public static String BOTTOM_STRINGER_CUT = "BottomStringerCut"; - + public static String STAY_AWAY_FROM_STRINGER = "StayAwayFromStringer"; public static String STRINGER_WIDTH = "StringerWidth"; @@ -57,7 +52,7 @@ public class MachineConfig extends CategorizedSettings public static String CUT_OFF_NOSE = "Cut off nose"; public static String CUT_OFF_TAIL = "Cut off tail"; - + public static final String CUTTING_SPEED = "CuttingSpeed"; public static final String CUTTING_SPEED_STRINGER = "StringerCuttingSpeed"; public static final String CUTTING_SPEED_RAIL = "RailCuttingSpeed"; @@ -66,145 +61,166 @@ public class MachineConfig extends CategorizedSettings public static final String CUTTER_X_OFFSET = "CutterXOffset"; public static final String CUTTER_Y_OFFSET = "CutterYOffset"; public static final String CUTTER_Z_OFFSET = "CutterZOffset"; - + public static final String BEFORE_DECK_CUT = "BeforeDeckCut"; public static final String BEFORE_DECK_CUT_SCRIPT = "BeforeDeckCutScript"; public static final String DECK_START_POS = "DeckStartPos"; public static final String AFTER_DECK_CUT = "AfterDeckCut"; public static final String AFTER_DECK_CUT_SCRIPT = "AfterDeckCutScript"; - + public static final String BEFORE_BOTTOM_CUT = "BeforeBottomCut"; public static final String BEFORE_BOTTOM_CUT_SCRIPT = "BeforeBottomCutScript"; public static final String BOTTOM_START_POS = "BottomStartPos"; public static final String AFTER_BOTTOM_CUT = "AfterBottomCut"; public static final String AFTER_BOTTOM_CUT_SCRIPT = "AfterBottomCutScript"; public static final String CLEAR_HEIGHT = "ClearHeight"; - + public static final String SAVE_G_CODE = "SaveGCode"; - + protected AbstractCutter mCutter = null; protected AbstractBlankHoldingSystem mBlankHoldingSystem = null; protected AbstractToolpathGenerator mToolpathGenerator = null; - + protected BezierBoard mBrd; protected BezierBoard mBlank; - + protected MachineView mMachineView = null; - + Point3d mCutterOffset = new Point3d(0.0, 0.0, 0.0); - - public MachineConfig() - { + + FasterBrd3DModelGenerator mBlank3DModelGenerator = new FasterBrd3DModelGenerator(); + FasterBrd3DModelGenerator mBrd3DModelGenerator = new FasterBrd3DModelGenerator(); + + public MachineConfig() { } - - public void initialize() - { - Settings.SettingChangedCallback onSupportSettingsChanged = new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { - if(mMachineView != null) - { + + public void initialize() { + Settings.SettingChangedCallback onSupportSettingsChanged = new Settings.SettingChangedCallback() { + public void onSettingChanged(Object obj) { + if (mMachineView != null) { mMachineView.update(); } } }; - - Settings.SettingChangedCallback onCutterTypeChanged = new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { + + Settings.SettingChangedCallback onCutterTypeChanged = new Settings.SettingChangedCallback() { + public void onSettingChanged(Object obj) { System.out.printf("Cutter Setting changed\n"); - + Settings cutterSettings = getCategory(LanguageResource.getString("CUTTERCATEGORY_STR")); - Settings generalSettings = getCategory(LanguageResource.getString("GENERALCATEGORY_STR")); + Settings generalSettings = getCategory(LanguageResource.getString("GENERALCATEGORY_STR")); cutterSettings.putPreferences(); cutterSettings.clear(); - + mMachineView.get3DView().setModelRotation(0.0); - Enumeration enu = (Enumeration)obj; - - switch(enu.getValue()) - { + Enumeration enu = (Enumeration) obj; + + switch (enu.getValue()) { case 0: mCutter = new SimpleBullnoseCutter(MachineConfig.this); generalSettings.removeObject(RotatingBoardCutter.ROTATINGBOARDCUTTER_TYPE); - if(generalSettings.getEnumeration(BLANKHOLDINGSYSTEM_TYPE) == 2) - { + if (generalSettings.getEnumeration(BLANKHOLDINGSYSTEM_TYPE) == 2) { generalSettings.setEnumeration(BLANKHOLDINGSYSTEM_TYPE, 0); } break; case 1: mCutter = new STLCutter(MachineConfig.this); - generalSettings.removeObject(RotatingBoardCutter.ROTATINGBOARDCUTTER_TYPE); - if(generalSettings.getEnumeration(BLANKHOLDINGSYSTEM_TYPE) == 2) - { + generalSettings.removeObject(RotatingBoardCutter.ROTATINGBOARDCUTTER_TYPE); + if (generalSettings.getEnumeration(BLANKHOLDINGSYSTEM_TYPE) == 2) { generalSettings.setEnumeration(BLANKHOLDINGSYSTEM_TYPE, 0); } break; case 2: mCutter = new RotatingBoardCutter(MachineConfig.this, mMachineView.get3DView()); generalSettings.setEnumeration(BLANKHOLDINGSYSTEM_TYPE, 2); - break; + break; } - + cutterSettings.getPreferences(); - if(mMachineView != null) - { + if (mMachineView != null) { mMachineView.get3DView().setCutterModel(mCutter.get3DModel()); mMachineView.update(); } } }; - Settings.SettingChangedCallback onBlankHoldingSystemChanged = new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { + Settings.SettingChangedCallback onBlankHoldingSystemChanged = new Settings.SettingChangedCallback() { + public void onSettingChanged(Object obj) { System.out.printf("Blankholdingsystem Setting changed\n"); MachineConfig.this.getCategory(LanguageResource.getString("BLANKHOLDINGSYSTEMCATEGORY_STR")).putPreferences(); - Settings generalSettings = getCategory(LanguageResource.getString("GENERALCATEGORY_STR")); + Settings generalSettings = getCategory(LanguageResource.getString("GENERALCATEGORY_STR")); - Enumeration enu = (Enumeration)obj; - - switch(enu.getValue()) - { + Enumeration enu = (Enumeration) obj; + + Setting blankSetting = generalSettings.getSetting(BLANK); + switch (enu.getValue()) { case 0: mBlankHoldingSystem = new SupportsBlankHoldingSystem(MachineConfig.this); - if(generalSettings.getEnumeration(CUTTER_TYPE) == 2) - { + if (generalSettings.getEnumeration(CUTTER_TYPE) == 2) { generalSettings.setEnumeration(CUTTER_TYPE, 0); } + blankSetting.setHidden(false); + blankSetting.signal(); break; case 1: mBlankHoldingSystem = new EndClampsBlankHoldingSystem(MachineConfig.this); - if(generalSettings.getEnumeration(CUTTER_TYPE) == 2) - { + if (generalSettings.getEnumeration(CUTTER_TYPE) == 2) { generalSettings.setEnumeration(CUTTER_TYPE, 0); } + blankSetting.setHidden(false); + blankSetting.signal(); break; case 2: mBlankHoldingSystem = new RotatingBoardBlankHoldingSystem(MachineConfig.this); generalSettings.setEnumeration(CUTTER_TYPE, 2); generalSettings.getSetting(CUTTER_TYPE).signal(); - break; + blankSetting.setHidden(false); + blankSetting.signal(); + break; + case 3: + mBlankHoldingSystem = new TableBlockHoldingSystem(MachineConfig.this); + if (generalSettings.getEnumeration(CUTTER_TYPE) == 2) { + generalSettings.setEnumeration(CUTTER_TYPE, 0); + } + generalSettings.getSetting(CUTTER_TYPE).signal(); + blankSetting.setHidden(true); + blankSetting.signal(); + break; } - + + mBlankHoldingSystem.setChangeListener(new ChangeListener() { + + @Override + public void onChange() { + if (mMachineView != null) { + System.out.printf("On change %f, %f, %f\n", mBlankHoldingSystem.getBlankDeckOffsetPos().x, mBlankHoldingSystem.getBlankDeckOffsetPos().y, mBlankHoldingSystem.getBlankDeckOffsetPos().z); + + mMachineView.get3DView().setBlankDeckOffset(new Point3d(mBlankHoldingSystem.getBlankDeckOffsetPos()), mBlankHoldingSystem.getBlankDeckOffsetAngle()); + mMachineView.get3DView().setBlankBottomOffset(new Point3d(mBlankHoldingSystem.getBlankBottomOffsetPos()), mBlankHoldingSystem.getBlankBottomOffsetAngle()); + mMachineView.get3DView().setBrdDeckOffset(new Point3d(mBlankHoldingSystem.getBoardDeckOffsetPos()), mBlankHoldingSystem.getBoardDeckOffsetAngle()); + mMachineView.get3DView().setBrdBottomOffset(new Point3d(mBlankHoldingSystem.getBoardBottomOffsetPos()), mBlankHoldingSystem.getBoardBottomOffsetAngle()); + } + } + }); + getCategory(LanguageResource.getString("BLANKHOLDINGSYSTEMCATEGORY_STR")).getPreferences(); - if(mMachineView != null) - { + if (mMachineView != null) { mMachineView.get3DView().setBlankHoldingSystemModel(mBlankHoldingSystem.get3DModel()); + mMachineView.get3DView().setBlankDeckOffset(new Point3d(mBlankHoldingSystem.getBlankDeckOffsetPos()), mBlankHoldingSystem.getBlankDeckOffsetAngle()); + mMachineView.get3DView().setBlankBottomOffset(new Point3d(mBlankHoldingSystem.getBlankBottomOffsetPos()), mBlankHoldingSystem.getBlankBottomOffsetAngle()); + mMachineView.get3DView().setBrdDeckOffset(new Point3d(mBlankHoldingSystem.getBoardDeckOffsetPos()), mBlankHoldingSystem.getBoardDeckOffsetAngle()); + mMachineView.get3DView().setBrdBottomOffset(new Point3d(mBlankHoldingSystem.getBoardBottomOffsetPos()), mBlankHoldingSystem.getBoardBottomOffsetAngle()); mMachineView.update(); } } }; Settings generalSettings = addCategory(LanguageResource.getString("GENERALCATEGORY_STR")); - + generalSettings.addObject(USE_BRD_SETTINGS, new Boolean(true), LanguageResource.getString("USEBRDSETTINGS_STR"), onSupportSettingsChanged); HashMap cutterTypes = new HashMap(); @@ -212,88 +228,73 @@ public void onSettingChanged(Object obj) cutterTypes.put(1, LanguageResource.getString("STLCUTTER_STR")); cutterTypes.put(2, LanguageResource.getString("ROTATINGBOARDCUTTER_STR")); generalSettings.addEnumeration(CUTTER_TYPE, 0, cutterTypes, LanguageResource.getString("CUTTERTYPE_STR"), onCutterTypeChanged); - + HashMap holdingSystemTypes = new HashMap(); holdingSystemTypes.put(0, LanguageResource.getString("SUPPORTS_STR")); holdingSystemTypes.put(1, LanguageResource.getString("ENDCLAMPS_STR")); holdingSystemTypes.put(2, LanguageResource.getString("ROTATINGBOARD_STR")); - generalSettings.addEnumeration(BLANKHOLDINGSYSTEM_TYPE, 0,holdingSystemTypes, LanguageResource.getString("BLANKHOLDINGSYSTEMTYPE_STR"), onBlankHoldingSystemChanged); + holdingSystemTypes.put(3, LanguageResource.getString("BLOCKTABLE_STR")); + generalSettings.addEnumeration(BLANKHOLDINGSYSTEM_TYPE, 0, holdingSystemTypes, LanguageResource.getString("BLANKHOLDINGSYSTEMTYPE_STR"), onBlankHoldingSystemChanged); - generalSettings.addFileName(BLANK, "", LanguageResource.getString("BLANK_STR"), new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { + generalSettings.addFileName(BLANK, "", LanguageResource.getString("BLANK_STR"), new Settings.SettingChangedCallback() { + public void onSettingChanged(Object obj) { String filename = obj.toString(); - if(filename == null || filename == "") + if (filename == null || filename == "") return; - - String ext = FileTools.getExtension(filename); - + mBlank = new BezierBoard(); - if(ext.compareToIgnoreCase("s3d")==0) - { - S3dReader.loadFile(mBlank, filename); - } - else if(ext.compareToIgnoreCase("srf")==0) - { - SrfReader.loadFile(mBlank, filename); - } - else if(ext.compareToIgnoreCase("cad")==0) - { - //TODO: CANNOT USE THIS AS BLANK YET. Fix - } - else - { - BrdReader.loadFile(mBlank, filename); + if (!generalSettings.getSetting(BLANK).isHidden()) { + String ext = FileTools.getExtension(filename); + if (ext.compareToIgnoreCase("s3d") == 0) { + S3dReader.loadFile(mBlank, filename); + } else if (ext.compareToIgnoreCase("srf") == 0) { + SrfReader.loadFile(mBlank, filename); + } else if (ext.compareToIgnoreCase("cad") == 0) { + // TODO: CANNOT USE THIS AS BLANK YET. Fix + } else { + BrdReader.loadFile(mBlank, filename); + } } - if(mMachineView != null) - { + if (mMachineView != null) { + mBlank3DModelGenerator.update3DModel(mBlank, mMachineView.get3DView().getBlankModel(), 8); mMachineView.update(); } - } - } - ); -/* Example of an action inside settings - generalSettings.addAction(SAVE_G_CODE, "...", "Save g-code", new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { - final JFileChooser fc = new JFileChooser(); - - fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); - - int returnVal = fc.showSaveDialog(BoardCAD.getInstance() - .getFrame()); - if (returnVal != JFileChooser.APPROVE_OPTION) - return; - - File file = fc.getSelectedFile(); - - String filename = file.getPath(); // Load and display - // selection - if (filename == null) - return; - - BoardCAD.defaultDirectory = file.getPath(); - - SurfaceSplitsToolpathGenerator toolpathGenerator = new SurfaceSplitsToolpathGenerator(new BullnoseCutter(), BoardCAD.getInstance().getCurrentMachineConfig()); - - try { - toolpathGenerator.writeDeck(filename, BoardCAD.getInstance().getCurrentBrd()); - } catch (Exception e) { - String str = "Failed to write g-code file :" + e.toString(); - JOptionPane.showMessageDialog(BoardCAD.getInstance() - .getFrame(), str, "Error when writing g-code file", - JOptionPane.ERROR_MESSAGE); - - } - } - } - ); -*/ + } + }); + /* + * Example of an action inside settings + * generalSettings.addAction(SAVE_G_CODE, "...", "Save g-code", new + * Settings.SettingChangedCallback() { public void + * onSettingChanged(Object obj) { final JFileChooser fc = new + * JFileChooser(); + * + * fc.setCurrentDirectory(new File(BoardCAD.defaultDirectory)); + * + * int returnVal = fc.showSaveDialog(BoardCAD.getInstance() + * .getFrame()); if (returnVal != JFileChooser.APPROVE_OPTION) return; + * + * File file = fc.getSelectedFile(); + * + * String filename = file.getPath(); // Load and display // selection if + * (filename == null) return; + * + * BoardCAD.defaultDirectory = file.getPath(); + * + * SurfaceSplitsToolpathGenerator toolpathGenerator = new + * SurfaceSplitsToolpathGenerator(new BullnoseCutter(), + * BoardCAD.getInstance().getCurrentMachineConfig()); + * + * try { toolpathGenerator.writeDeck(filename, + * BoardCAD.getInstance().getCurrentBrd()); } catch (Exception e) { + * String str = "Failed to write g-code file :" + e.toString(); + * JOptionPane.showMessageDialog(BoardCAD.getInstance() .getFrame(), + * str, "Error when writing g-code file", JOptionPane.ERROR_MESSAGE); + * + * } } } ); + */ Settings cutsSettings = addCategory(LanguageResource.getString("CUTSCATEGORY_STR")); - + cutsSettings.addMeasurement(LENGTHWISE_RESOLUTION, 1.0, LanguageResource.getString("LENGTHWISERESOLUTION_STR")); cutsSettings.addObject(DECK_CUTS, new Integer(28), LanguageResource.getString("DECKCUTS_STR")); @@ -302,7 +303,7 @@ public void onSettingChanged(Object obj) cutsSettings.addObject(BOTTOM_RAIL_CUTS, new Integer(0), LanguageResource.getString("BOTTOMRAILCUTS_STR")); cutsSettings.addObject(BOTTOM_CLEAN_UP_CUTS, new Integer(2), LanguageResource.getString("BOTTOMCLEANUPCUTS_STR")); cutsSettings.addObject(DECK_CLEAN_UP_CUTS, new Integer(2), LanguageResource.getString("DECKCLEANUPCUTS_STR")); - + cutsSettings.addObject(DECK_STRINGER_CUT, new Boolean(true), LanguageResource.getString("DECKSTRINGERCUT_STR")); cutsSettings.addObject(BOTTOM_STRINGER_CUT, new Boolean(true), LanguageResource.getString("BOTTOMSTRINGERCUT_STR")); @@ -314,7 +315,7 @@ public void onSettingChanged(Object obj) outlineDepthTypes.put(0, LanguageResource.getString("DECKOUTLINETOAPEXDEPTH_STR")); outlineDepthTypes.put(1, LanguageResource.getString("DECKOUTLINETOBOTTOMDEPTH_STR")); cutsSettings.addEnumeration(DECK_OUTLINE_CUT_DEPTH, 0, outlineDepthTypes, LanguageResource.getString("DECKOUTLINECUTDEPTH_STR")); - + cutsSettings.addObject(BOTTOM_OUTLINE_CUT, new Boolean(true), LanguageResource.getString("BOTTOMOUTLINECUT_STR")); cutsSettings.addObject(CUT_OFF_NOSE, new Boolean(false), LanguageResource.getString("CUTOFFNOSE_STR")); @@ -324,28 +325,26 @@ public void onSettingChanged(Object obj) cutsSettings.addObject(DECK_RAIL_ANGLE, new Double(130), LanguageResource.getString("DECKRAILDEFINITIONANGLE_STR")); cutsSettings.addObject(BOTTOM_ANGLE, new Double(90), LanguageResource.getString("BOTTOMDEFINITIONANGLE_STR")); cutsSettings.addObject(BOTTOM_RAIL_ANGLE, new Double(90), LanguageResource.getString("BOTTOMRAILDEFINITIONANGLE_STR")); - + Settings speedSettings = addCategory(LanguageResource.getString("SPEEDCATEGORY_STR")); - speedSettings.addObject(CUTTING_SPEED, new Double(80), LanguageResource.getString("CUTTINGSPEED_STR")); - speedSettings.addObject(CUTTING_SPEED_STRINGER, new Double(254), LanguageResource.getString("STRINGERCUTTINGSPEED_STR")); - speedSettings.addObject(CUTTING_SPEED_RAIL, new Double(254), LanguageResource.getString("RAILCUTTINGSPEED_STR")); - speedSettings.addObject(CUTTING_SPEED_OUTLINE, new Double(254), LanguageResource.getString("OUTLINECUTTINGSPEED_STR")); - + speedSettings.addObject(CUTTING_SPEED, new Double(80), LanguageResource.getString("CUTTINGSPEED_STR")); + speedSettings.addObject(CUTTING_SPEED_STRINGER, new Double(254), LanguageResource.getString("STRINGERCUTTINGSPEED_STR")); + speedSettings.addObject(CUTTING_SPEED_RAIL, new Double(254), LanguageResource.getString("RAILCUTTINGSPEED_STR")); + speedSettings.addObject(CUTTING_SPEED_OUTLINE, new Double(254), LanguageResource.getString("OUTLINECUTTINGSPEED_STR")); + final Settings controlSettings = addCategory(LanguageResource.getString("CONTROLCATEGORY_STR")); HashMap homeingTypes = new HashMap(); homeingTypes.put(0, LanguageResource.getString("NOTHING_STR")); homeingTypes.put(1, LanguageResource.getString("HOME_STR")); homeingTypes.put(2, LanguageResource.getString("HOMEREF_STR")); - //homeingTypes.put(3, LanguageResource.getString("HOME_Z_STR")); TODO: Dunno how to do home on z only, have to wait + // homeingTypes.put(3, LanguageResource.getString("HOME_Z_STR")); TODO: + // Dunno how to do home on z only, have to wait homeingTypes.put(3, LanguageResource.getString("LIFTCLEAR_STR")); homeingTypes.put(4, LanguageResource.getString("HOMESCRIPT_STR")); - controlSettings.addEnumeration(BEFORE_DECK_CUT, 1, homeingTypes, LanguageResource.getString("BEFOREDECKCUT_STR"), new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { - Enumeration enu = (Enumeration)obj; - switch(enu.getValue()) - { + controlSettings.addEnumeration(BEFORE_DECK_CUT, 1, homeingTypes, LanguageResource.getString("BEFOREDECKCUT_STR"), new Settings.SettingChangedCallback() { + public void onSettingChanged(Object obj) { + Enumeration enu = (Enumeration) obj; + switch (enu.getValue()) { default: case 0: case 1: @@ -355,27 +354,24 @@ public void onSettingChanged(Object obj) case 3: controlSettings.removeObject(BEFORE_DECK_CUT_SCRIPT); break; - - case 4: + + case 4: controlSettings.addFileName(BEFORE_DECK_CUT_SCRIPT, "", LanguageResource.getString("BEFOREDECKCUTSCRIPT_STR")); break; } updateClearHeightSetting(); } }); - + HashMap startOnDeckTypes = new HashMap(); startOnDeckTypes.put(0, LanguageResource.getString("NOSE_STR")); startOnDeckTypes.put(1, LanguageResource.getString("TAIL_STR")); controlSettings.addEnumeration(DECK_START_POS, 1, startOnDeckTypes, LanguageResource.getString("DECKSTARTPOS_STR")); - - controlSettings.addEnumeration(AFTER_DECK_CUT, 1, homeingTypes, LanguageResource.getString("AFTERDECKCUT_STR"), new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { - Enumeration enu = (Enumeration)obj; - switch(enu.getValue()) - { + + controlSettings.addEnumeration(AFTER_DECK_CUT, 1, homeingTypes, LanguageResource.getString("AFTERDECKCUT_STR"), new Settings.SettingChangedCallback() { + public void onSettingChanged(Object obj) { + Enumeration enu = (Enumeration) obj; + switch (enu.getValue()) { default: case 0: case 1: @@ -383,8 +379,8 @@ public void onSettingChanged(Object obj) case 3: controlSettings.removeObject(AFTER_DECK_CUT_SCRIPT); break; - - case 4: + + case 4: controlSettings.addFileName(AFTER_DECK_CUT_SCRIPT, "", LanguageResource.getString("AFTERDECKCUTSCRIPT_STR")); break; } @@ -392,13 +388,10 @@ public void onSettingChanged(Object obj) } }); - controlSettings.addEnumeration(BEFORE_BOTTOM_CUT, 1, homeingTypes, LanguageResource.getString("BEFOREBOTTOMCUT_STR"), new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { - Enumeration enu = (Enumeration)obj; - switch(enu.getValue()) - { + controlSettings.addEnumeration(BEFORE_BOTTOM_CUT, 1, homeingTypes, LanguageResource.getString("BEFOREBOTTOMCUT_STR"), new Settings.SettingChangedCallback() { + public void onSettingChanged(Object obj) { + Enumeration enu = (Enumeration) obj; + switch (enu.getValue()) { default: case 0: case 1: @@ -406,8 +399,8 @@ public void onSettingChanged(Object obj) case 3: controlSettings.removeObject(BEFORE_BOTTOM_CUT_SCRIPT); break; - - case 4: + + case 4: controlSettings.addFileName(BEFORE_BOTTOM_CUT_SCRIPT, "", LanguageResource.getString("BEFOREBOTTOMCUTSCRIPT_STR")); break; } @@ -421,13 +414,10 @@ public void onSettingChanged(Object obj) startOnBottomTypes.put(2, LanguageResource.getString("PREVIOUS_STR")); controlSettings.addEnumeration(BOTTOM_START_POS, 0, startOnBottomTypes, LanguageResource.getString("BOTTOMSTARTPOS_STR")); - controlSettings.addEnumeration(AFTER_BOTTOM_CUT, 1, homeingTypes, LanguageResource.getString("AFTERBOTTOMCUT_STR"), new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { - Enumeration enu = (Enumeration)obj; - switch(enu.getValue()) - { + controlSettings.addEnumeration(AFTER_BOTTOM_CUT, 1, homeingTypes, LanguageResource.getString("AFTERBOTTOMCUT_STR"), new Settings.SettingChangedCallback() { + public void onSettingChanged(Object obj) { + Enumeration enu = (Enumeration) obj; + switch (enu.getValue()) { default: case 0: case 1: @@ -435,105 +425,94 @@ public void onSettingChanged(Object obj) case 3: controlSettings.removeObject(AFTER_BOTTOM_CUT_SCRIPT); break; - - case 4: + + case 4: controlSettings.addFileName(AFTER_BOTTOM_CUT_SCRIPT, "", LanguageResource.getString("AFTERBOTTOMCUTSCRIPT_STR")); break; } updateClearHeightSetting(); } }); - - Settings.SettingChangedCallback onCutterOffsetChanged = new Settings.SettingChangedCallback() - { - public void onSettingChanged(Object obj) - { + + Settings.SettingChangedCallback onCutterOffsetChanged = new Settings.SettingChangedCallback() { + public void onSettingChanged(Object obj) { Settings cutterOffsetSettings = getCategory(LanguageResource.getString("CUTTEROFFSETCATEGORY_STR")); mCutterOffset = new Point3d(cutterOffsetSettings.getMeasurement(CUTTER_X_OFFSET), cutterOffsetSettings.getMeasurement(CUTTER_Y_OFFSET), cutterOffsetSettings.getMeasurement(CUTTER_Z_OFFSET)); - mMachineView.get2DView().setCutterOffset(mCutterOffset); + mMachineView.get2DView().setCutterOffset(mCutterOffset); mMachineView.get3DView().setCutterOffset(mCutterOffset); } }; - + Settings cutterOffsetSettings = addCategory(LanguageResource.getString("CUTTEROFFSETCATEGORY_STR")); cutterOffsetSettings.addMeasurement(CUTTER_X_OFFSET, 0.0, LanguageResource.getString("CUTTER_X_OFFSET_STR"), onCutterOffsetChanged); cutterOffsetSettings.addMeasurement(CUTTER_Y_OFFSET, 0.0, LanguageResource.getString("CUTTER_Y_OFFSET_STR"), onCutterOffsetChanged); cutterOffsetSettings.addMeasurement(CUTTER_Z_OFFSET, 0.0, LanguageResource.getString("CUTTER_Z_OFFSET_STR"), onCutterOffsetChanged); - + mCutter = new SimpleBullnoseCutter(this); - mBlankHoldingSystem = new SupportsBlankHoldingSystem(this); + mBlankHoldingSystem = new SupportsBlankHoldingSystem(this); mToolpathGenerator = new SurfaceSplitsToolpathGenerator(this, new GCodeWriterWithScaling(this), this.getMachineView()); - //Read cutter and blank holding system settings here so we don't overwrite with default values when getting the full set of settings result in changed of cutter or holding system + // Read cutter and blank holding system settings here so we don't + // overwrite with default values when getting the full set of settings + // result in changed of cutter or holding system getCategory(LanguageResource.getString("CUTTERCATEGORY_STR")).getPreferences(); getCategory(LanguageResource.getString("BLANKHOLDINGSYSTEMCATEGORY_STR")).getPreferences(); - + mMachineView.get3DView().setCutterModel(mCutter.get3DModel()); mMachineView.get3DView().setBlankHoldingSystemModel(mBlankHoldingSystem.get3DModel()); + + mBrd3DModelGenerator.update3DModel(mBrd, mMachineView.get3DView().getBrdModel(), 8); } - - public void updateClearHeightSetting() - { + + public void updateClearHeightSetting() { final Settings controlSettings = getCategory(LanguageResource.getString("CONTROLCATEGORY_STR")); int bd = controlSettings.getEnumeration(BEFORE_DECK_CUT); int ad = controlSettings.getEnumeration(AFTER_DECK_CUT); int bb = controlSettings.getEnumeration(BEFORE_BOTTOM_CUT); int ab = controlSettings.getEnumeration(AFTER_BOTTOM_CUT); - - if(bd == 3 || ad == 3 || bb == 3 || ab == 3) - { - controlSettings.addMeasurement(CLEAR_HEIGHT, 20.0, LanguageResource.getString("CLEARHEIGHT_STR")); - } - else - { + + if (bd == 3 || ad == 3 || bb == 3 || ab == 3) { + controlSettings.addMeasurement(CLEAR_HEIGHT, 20.0, LanguageResource.getString("CLEARHEIGHT_STR")); + } else { controlSettings.removeObject(CLEAR_HEIGHT); } } - - public void setBoard(BezierBoard brd) - { + + public void setBoard(BezierBoard brd) { mBrd = brd; } - - public BezierBoard getBoard() - { + + public BezierBoard getBoard() { return mBrd; } - - public BezierBoard getBlank() - { + + public BezierBoard getBlank() { return mBlank; } - - public AbstractCutter getCutter() - { + + public AbstractCutter getCutter() { return mCutter; } - - public Point3d getCutterOffset() - { + + public Point3d getCutterOffset() { return mCutterOffset; } - - public AbstractBlankHoldingSystem getBlankHoldingSystem() - { + + public AbstractBlankHoldingSystem getBlankHoldingSystem() { return mBlankHoldingSystem; } - public AbstractToolpathGenerator getToolpathGenerator() - { + public AbstractToolpathGenerator getToolpathGenerator() { return mToolpathGenerator; } - - public MachineView getMachineView() - { + + public MachineView getMachineView() { return mMachineView; } - - public void setMachineView(MachineView view) - { - mMachineView = view;; + + public void setMachineView(MachineView view) { + mMachineView = view; + ; } } - diff --git a/boardcam/Scan.java b/boardcam/Scan.java index 4420076..d77a211 100644 --- a/boardcam/Scan.java +++ b/boardcam/Scan.java @@ -1373,7 +1373,7 @@ public void approximateCurrentView() ArrayList gpArray=BoardCAD.getInstance().getSelectedEdit().getGuidePoints(); BezierSpline[] bs=BoardCAD.getInstance().getSelectedEdit().getActiveBezierSplines(brd); - final JTabbedPane mTabbedPane = BoardCAD.getInstance().getmTabbedPane(); + final JTabbedPane mTabbedPane = BoardCAD.getInstance().getTabbedPane(); if (mTabbedPane.getSelectedIndex() == 5 || (mTabbedPane.getSelectedIndex() == 2 && BoardCAD.getInstance().getFourViewName() == "QuadViewCrossSection" )) { approximateCrossSection(bs[0], gpArray); diff --git a/boardcam/cutters/AbstractCutter.java b/boardcam/cutters/AbstractCutter.java index 8b7186d..2f316ab 100644 --- a/boardcam/cutters/AbstractCutter.java +++ b/boardcam/cutters/AbstractCutter.java @@ -7,7 +7,7 @@ import board.AbstractBoard; import cadcore.AxisAlignedBoundingBox; -public abstract class AbstractCutter +public abstract class AbstractCutter implements Cloneable { protected boolean mStayAwayFromStringer = false; protected double mStringerWidth = 0.3; @@ -81,5 +81,10 @@ public AxisAlignedBoundingBox getBoundingBox(Point3d pos) { return null; //Breaks out when returning null } + + public Object clone() throws CloneNotSupportedException{ + return super.clone(); + } + } diff --git a/boardcam/holdingsystems/AbstractBlankHoldingSystem.java b/boardcam/holdingsystems/AbstractBlankHoldingSystem.java index 48b4f8a..7dc26ef 100644 --- a/boardcam/holdingsystems/AbstractBlankHoldingSystem.java +++ b/boardcam/holdingsystems/AbstractBlankHoldingSystem.java @@ -35,6 +35,11 @@ public class AbstractBlankHoldingSystem { double mBoardBottomRotation=0; BranchGroup mModelRoot = new BranchGroup(); + ChangeListener mChangeListener = null; + + public void setChangeListener(ChangeListener changeListener){ + mChangeListener = changeListener; + } public void init() { @@ -74,13 +79,19 @@ public double getBlankBottomOffsetAngle() public void setBoardDeckOffsetPos(Vector3d offset) { mBoardDeckOffset.set(offset); - //System.out.printf("AbstractBlankHoldingSystem.setBoardDeckOffsetPos: %s, %f,%f,%f\n", toString(), mBoardDeckOffset.x, mBoardDeckOffset.y, mBoardDeckOffset.z); + System.out.printf("AbstractBlankHoldingSystem.setBoardDeckOffsetPos: %s, %f,%f,%f\n", toString(), mBoardDeckOffset.x, mBoardDeckOffset.y, mBoardDeckOffset.z); + if(mChangeListener != null){ + mChangeListener.onChange(); + } } public void setBoardDeckOffsetAngle(double angle) { mBoardDeckRotation = angle; System.out.printf("AbstractBlankHoldingSystem.setBoardDeckOffsetAngle: %s %f\n", toString(), mBoardDeckRotation); + if(mChangeListener != null){ + mChangeListener.onChange(); + } } public Vector3d getBoardDeckOffsetPos() diff --git a/boardcam/holdingsystems/ChangeListener.java b/boardcam/holdingsystems/ChangeListener.java new file mode 100644 index 0000000..a7f2be0 --- /dev/null +++ b/boardcam/holdingsystems/ChangeListener.java @@ -0,0 +1,5 @@ +package boardcam.holdingsystems; + +public interface ChangeListener { + public void onChange(); +} diff --git a/boardcam/holdingsystems/EndClampsBlankHoldingSystem.java b/boardcam/holdingsystems/EndClampsBlankHoldingSystem.java index 61b5361..8e51b0e 100644 --- a/boardcam/holdingsystems/EndClampsBlankHoldingSystem.java +++ b/boardcam/holdingsystems/EndClampsBlankHoldingSystem.java @@ -16,13 +16,17 @@ import javax.media.j3d.GeometryArray; import javax.media.j3d.IndexedQuadArray; import javax.media.j3d.LineArray; +import javax.media.j3d.Material; import javax.media.j3d.Shape3D; +import javax.media.j3d.TransparencyAttributes; import cadcore.BezierSpline; import cadcore.UnitUtils; import cadcore.AxisAlignedBoundingBox; import com.sun.j3d.utils.geometry.Box; + +import javax.vecmath.Color3f; import javax.vecmath.Point2d; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; @@ -121,13 +125,13 @@ public void onSettingChanged(Object object) { } public void setBoardDeckOffsetPos(Vector3d offset) { - super.setBoardDeckOffsetPos(offset); mBoardBottomOffset.set(offset.x, offset.y, -offset.z); + super.setBoardDeckOffsetPos(offset); } public void setBoardDeckOffsetAngle(double angle) { - super.setBoardDeckOffsetAngle(angle); mBoardBottomRotation = -angle; + super.setBoardDeckOffsetAngle(angle); } public Vector3d getBoardDeckOffsetPos() { @@ -153,6 +157,8 @@ public void calcBlankOffset() { String holdingSystemStr = LanguageResource .getString("BLANKHOLDINGSYSTEMCATEGORY_STR"); Settings holdingSystemSettings = mConfig.getCategory(holdingSystemStr); + if(!holdingSystemSettings.containsSetting(CLAMP_LENGTH))return; + double clampLength = holdingSystemSettings.getMeasurement(CLAMP_LENGTH); double clampHeight = holdingSystemSettings.getMeasurement(CLAMP_HEIGHT); double clampWidth = holdingSystemSettings.getMeasurement(CLAMP_WIDTH); @@ -194,6 +200,10 @@ public void calcBlankOffset() { mRotatedLength = (Math.sin(rotAngle) * (noseBottom - tailBottom)) + (Math.cos(rotAngle) * blank.getLength()); } + + if(mChangeListener != null){ + mChangeListener.onChange(); + } } public boolean checkCollision(Point3d pos, AbstractCutter cutter) { @@ -497,6 +507,16 @@ void init3DModel() { mTailClampShape = new Shape3D(mTailClampBox); Appearance supportStructureApperance = new Appearance(); +/* Color3f ambient = new Color3f(0.1f, 0.1f, 0.5f); + Color3f emissive = new Color3f(0.0f, 0.0f, 0.0f); + Color3f diffuse = new Color3f(0.1f, 0.1f, 0.6f); + Color3f specular = new Color3f(0.1f, 0.1f, 0.8f); +// TransparencyAttributes supportStructureTransparencyAttributes = new TransparencyAttributes(); +// supportStructureTransparencyAttributes.setTransparency(0.0f); + + // Set up the material properties + supportStructureApperance.setMaterial(new Material(ambient, emissive, diffuse, specular, 128.0f)); +// supportStructureApperance.setTransparencyAttributes(supportStructureTransparencyAttributes);*/ ColoringAttributes supportStructureColor = new ColoringAttributes(); supportStructureColor.setColor(0.1f, 0.1f, 0.5f); supportStructureApperance.setColoringAttributes(supportStructureColor); @@ -514,6 +534,8 @@ public void update3DModel() { String holdingSystemStr = LanguageResource .getString("BLANKHOLDINGSYSTEMCATEGORY_STR"); Settings holdingSystemSettings = mConfig.getCategory(holdingSystemStr); + if(!holdingSystemSettings.containsSetting(CLAMP_LENGTH))return; + double clampLength = holdingSystemSettings.getMeasurement(CLAMP_LENGTH) * UnitUtils.MILLIMETER_PR_CENTIMETER; double clampHeight = holdingSystemSettings.getMeasurement(CLAMP_HEIGHT) @@ -569,6 +591,8 @@ public void updateBoundingBoxes() { String holdingSystemStr = LanguageResource .getString("BLANKHOLDINGSYSTEMCATEGORY_STR"); Settings holdingSystemSettings = mConfig.getCategory(holdingSystemStr); + if(!holdingSystemSettings.containsSetting(CLAMP_LENGTH))return; + double clampLength = holdingSystemSettings.getMeasurement(CLAMP_LENGTH) * UnitUtils.MILLIMETER_PR_CENTIMETER; double clampHeight = holdingSystemSettings.getMeasurement(CLAMP_HEIGHT) diff --git a/boardcam/holdingsystems/TableBlockHoldingSystem.java b/boardcam/holdingsystems/TableBlockHoldingSystem.java new file mode 100644 index 0000000..47eb777 --- /dev/null +++ b/boardcam/holdingsystems/TableBlockHoldingSystem.java @@ -0,0 +1,277 @@ +package boardcam.holdingsystems; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.geom.AffineTransform; +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; + +import javax.media.j3d.Appearance; +import javax.media.j3d.ColoringAttributes; +import javax.media.j3d.GeometryArray; +import javax.media.j3d.IndexedQuadArray; +import javax.media.j3d.LineArray; +import javax.media.j3d.Shape3D; +import javax.media.j3d.TransparencyAttributes; + +import cadcore.BezierSpline; +import cadcore.UnitUtils; +import cadcore.AxisAlignedBoundingBox; + +import com.sun.j3d.utils.geometry.Box; + +import javax.vecmath.Point2d; +import javax.vecmath.Point3d; +import javax.vecmath.Vector3d; + +import board.AbstractBoard; +import board.BezierBoard; +import boardcad.settings.Setting; +import boardcad.settings.Settings; +import boardcad.settings.Settings.SettingChangedCallback; +import boardcam.MachineConfig; +import boardcam.cutters.AbstractCutter; +import boardcad.i18n.LanguageResource; + +public class TableBlockHoldingSystem extends AbstractBlankHoldingSystem { + + static String BLOCK_WIDTH = "BlockWidth"; + static String BLOCK_THICKNESS = "BlockHeight"; + static String BLOCK_LENGTH = "BlockLength"; + + MachineConfig mConfig = null; + + IndexedQuadArray mBlockBox; + Shape3D mBlockShape; + + public TableBlockHoldingSystem(MachineConfig config) { + super.init(); + mConfig = config; + System.out.printf( + "TableBlockHoldingSystem mConfig set to %s in %s\n", + mConfig.toString(), this.toString()); + + Settings blockSettings = mConfig.addCategory(LanguageResource + .getString("BLANKHOLDINGSYSTEMCATEGORY_STR")); + blockSettings.putPreferences(); // Save previous + blockSettings.clear(); + SettingChangedCallback cb = new Settings.SettingChangedCallback() { + public void onSettingChanged(Object object) { + calcBlankOffset(); + update3DModel(); + } + }; + + blockSettings.addMeasurement(BLOCK_LENGTH, 244, + LanguageResource.getString("BLOCKLENGTH_STR"), cb); + blockSettings.addMeasurement(BLOCK_THICKNESS, 15, + LanguageResource.getString("BLOCKTHICKNESS_STR"), cb); + blockSettings.addMeasurement(BLOCK_WIDTH, 60, + LanguageResource.getString("BLOCKWIDTH_STR"), cb); + + setBoardDeckOffsetPos(getBoardDeckOffsetPos()); + // + init3DModel(); + } + + public void setBoardDeckOffsetPos(Vector3d offset) { + super.setBoardDeckOffsetPos(offset); + String holdingSystemStr = LanguageResource.getString("BLANKHOLDINGSYSTEMCATEGORY_STR"); + Settings holdingSystemSettings = mConfig.getCategory(holdingSystemStr); + double blockThickness = holdingSystemSettings.getMeasurement(BLOCK_THICKNESS); + mBoardBottomOffset.set(offset.x, offset.y, blockThickness-offset.z); + } + + public void setBoardDeckOffsetAngle(double angle) { + super.setBoardDeckOffsetAngle(angle); + mBoardBottomRotation = -angle; + } + + public Vector3d getBoardDeckOffsetPos() { + return mBoardDeckOffset; + } + + public Vector3d getBoardBottomOffsetPos() { + return mBoardBottomOffset; + } + + public void calcBlankOffset() { + } + + public boolean checkCollision(Point3d pos, AbstractCutter cutter) { + return false; + } + + public ArrayList handleCollision(Point3d point, AbstractCutter cutter, AbstractBoard board) { + + ArrayList res = new ArrayList(); + + return res; + } + + public void draw(Graphics2D g2d, double offsetX, double offsetY, + double scale, boolean showDeck) { + // Setup for drawing + AffineTransform savedTransform = g2d.getTransform(); + + g2d.setColor(Color.BLACK); + + Stroke stroke = new BasicStroke((float) (1.0 / scale)); + g2d.setStroke(stroke); + + AffineTransform at = new AffineTransform(); + + at.setToTranslation(offsetX, offsetY); + + g2d.transform(at); + + at.setToScale(scale, scale); + + g2d.transform(at); + + // Get parameters + String holdingSystemStr = LanguageResource.getString("BLANKHOLDINGSYSTEMCATEGORY_STR"); + Settings holdingSystemSettings = mConfig.getCategory(holdingSystemStr); + double blockLength = holdingSystemSettings.getMeasurement(BLOCK_LENGTH); + double blockThickness = holdingSystemSettings.getMeasurement(BLOCK_THICKNESS); + double blockWidth = holdingSystemSettings.getMeasurement(BLOCK_WIDTH); + + // Draw offset line + Line2D line = new Line2D.Double(); + + // Draw center reference line + line.setLine(-blockLength*0.05, 0, blockLength*1.1, 0); + g2d.setColor(Color.GRAY); + g2d.draw(line); + + // Draw blocks + Rectangle2D blockRect = new Rectangle2D.Double(); + blockRect.setFrame(0, -blockThickness, blockLength, blockThickness); + + g2d.setColor(Color.WHITE); + g2d.setStroke(new BasicStroke((float) (1.0 / scale))); + g2d.draw(blockRect); + + g2d.setTransform(savedTransform); + + super.draw(g2d, offsetX, offsetY, scale, showDeck); + } + + void init3DModel() { + + mBlockBox = new IndexedQuadArray(8, GeometryArray.COORDINATES, + 6 * 4); + + mBlockBox.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); + + mBlockBox.setCoordinateIndex(0, 0); // Front end + mBlockBox.setCoordinateIndex(1, 1); + mBlockBox.setCoordinateIndex(2, 2); + mBlockBox.setCoordinateIndex(3, 3); + + mBlockBox.setCoordinateIndex(4, 7); // Back end + mBlockBox.setCoordinateIndex(5, 6); + mBlockBox.setCoordinateIndex(6, 5); + mBlockBox.setCoordinateIndex(7, 4); + + mBlockBox.setCoordinateIndex(8, 0); // Top + mBlockBox.setCoordinateIndex(9, 3); + mBlockBox.setCoordinateIndex(10, 7); + mBlockBox.setCoordinateIndex(11, 4); + + mBlockBox.setCoordinateIndex(12, 1); // Bottom + mBlockBox.setCoordinateIndex(13, 5); + mBlockBox.setCoordinateIndex(14, 6); + mBlockBox.setCoordinateIndex(15, 2); + + mBlockBox.setCoordinateIndex(16, 0); // Left + mBlockBox.setCoordinateIndex(17, 4); + mBlockBox.setCoordinateIndex(18, 5); + mBlockBox.setCoordinateIndex(19, 1); + + mBlockBox.setCoordinateIndex(20, 7); // Right + mBlockBox.setCoordinateIndex(21, 3); + mBlockBox.setCoordinateIndex(22, 2); + mBlockBox.setCoordinateIndex(23, 6); + + mBlockShape = new Shape3D(mBlockBox); + + Appearance blockApperance = new Appearance(); + ColoringAttributes blockColor = new ColoringAttributes(); + blockColor.setColor(0.3f, 0.3f, 0.5f); + TransparencyAttributes transparency = new TransparencyAttributes(); + transparency.setTransparency(0.5f); + transparency.setTransparencyMode(TransparencyAttributes.BLENDED); + blockApperance.setColoringAttributes(blockColor); + blockApperance.setTransparencyAttributes(transparency); + mBlockShape.setAppearance(blockApperance); + + mModelRoot.addChild(mBlockShape); + + update3DModel(); + + } + + public void update3DModel() { + String holdingSystemStr = LanguageResource + .getString("BLANKHOLDINGSYSTEMCATEGORY_STR"); + Settings holdingSystemSettings = mConfig.getCategory(holdingSystemStr); + double blockLength = holdingSystemSettings.getMeasurement(BLOCK_LENGTH) * UnitUtils.MILLIMETER_PR_CENTIMETER; + double blockThickness = holdingSystemSettings.getMeasurement(BLOCK_THICKNESS) * UnitUtils.MILLIMETER_PR_CENTIMETER; + double blockWidth = holdingSystemSettings.getMeasurement(BLOCK_WIDTH) * UnitUtils.MILLIMETER_PR_CENTIMETER; + + mBlockBox.setCoordinate(0, new Point3d(0, blockWidth / 2.0, blockThickness )); + mBlockBox.setCoordinate(1, new Point3d(0, blockWidth / 2.0, 0.0)); + mBlockBox.setCoordinate(2, new Point3d(0, -blockWidth / 2.0, 0.0)); + mBlockBox.setCoordinate(3, new Point3d(0, -blockWidth / 2.0, blockThickness)); + + mBlockBox.setCoordinate(4, new Point3d(blockLength, blockWidth / 2.0, blockThickness)); + mBlockBox.setCoordinate(5, new Point3d(blockLength, blockWidth / 2.0, 0.0)); + mBlockBox.setCoordinate(6, new Point3d(blockLength, -blockWidth / 2.0, 0.0)); + mBlockBox.setCoordinate(7, new Point3d(blockLength, -blockWidth / 2.0, blockThickness)); + + } + + public void updateBoundingBoxes() { + String holdingSystemStr = LanguageResource + .getString("BLANKHOLDINGSYSTEMCATEGORY_STR"); + Settings holdingSystemSettings = mConfig.getCategory(holdingSystemStr); + double blockLength = holdingSystemSettings.getMeasurement(BLOCK_LENGTH) * UnitUtils.MILLIMETER_PR_CENTIMETER; + double blockThickness = holdingSystemSettings.getMeasurement(BLOCK_THICKNESS) * UnitUtils.MILLIMETER_PR_CENTIMETER; + double blockWidth = holdingSystemSettings.getMeasurement(BLOCK_WIDTH) * UnitUtils.MILLIMETER_PR_CENTIMETER; + + // TODO: No collision checks + } + + public String toString(boolean isDeckCut) { + String holdingSystemStr = LanguageResource + .getString("BLANKHOLDINGSYSTEMCATEGORY_STR"); + Settings holdingSystemSettings = mConfig.getCategory(holdingSystemStr); + double blockLength = holdingSystemSettings.getMeasurement(BLOCK_LENGTH) * UnitUtils.MILLIMETER_PR_CENTIMETER; + double blockThickness = holdingSystemSettings.getMeasurement(BLOCK_THICKNESS) * UnitUtils.MILLIMETER_PR_CENTIMETER; + double blockWidth = holdingSystemSettings.getMeasurement(BLOCK_WIDTH) * UnitUtils.MILLIMETER_PR_CENTIMETER; + + String str = new String(); + str.concat(LanguageResource.getString("ENDBLOCKS_STR")); + str.concat(" "); + str.concat(holdingSystemStr); + str.concat("\n"); + + String details = String.format( + "%s:%f, %s:%f, %s:%f\n", + LanguageResource.getString("BLOCKLENGTH_STR"), blockLength, + LanguageResource.getString("BLOCKHEIGHT_STR"), blockThickness, + LanguageResource.getString("BLOCKWIDTH_STR"), blockWidth); + str.concat(details); + + str.concat(super.toString(isDeckCut)); + + return str; + } + + } diff --git a/boardcam/toolpathgenerators/SurfaceSplitsToolpathGenerator.java b/boardcam/toolpathgenerators/SurfaceSplitsToolpathGenerator.java index 072dfe7..db6472d 100644 --- a/boardcam/toolpathgenerators/SurfaceSplitsToolpathGenerator.java +++ b/boardcam/toolpathgenerators/SurfaceSplitsToolpathGenerator.java @@ -13,7 +13,6 @@ import javax.vecmath.Vector3d; import cadcore.BezierSpline; - import board.AbstractBoard; import board.BezierBoard; import boardcad.FileTools; @@ -21,10 +20,12 @@ import boardcad.i18n.LanguageResource; import boardcad.settings.Settings; import boardcam.MachineConfig; +import boardcam.cutters.AbstractCutter; import boardcam.toolpathgenerators.ext.SandwichCompensation; import boardcam.writers.AbstractMachineWriter; -public class SurfaceSplitsToolpathGenerator extends AbstractToolpathGenerator { +public class SurfaceSplitsToolpathGenerator extends AbstractToolpathGenerator + implements Cloneable { public class State { public static final int NO_STATE = 0; @@ -63,8 +64,6 @@ public class State { double mLengthwiseResolution = 1.0; - protected int mCurrentState = State.NO_STATE; - boolean mDeckStringerCut = true; boolean mBottomStringerCut = true; boolean mStayAwayFromStringer = false; @@ -100,28 +99,17 @@ public class State { private boolean mHasCutBottomStringer = false; - private int mCutNumber = 0; private int mTotalCuts = 0; protected double mLength = 0; protected int mNrOfLengthSplits = 0; - protected double y = 0; - protected int i = 0; - protected int j = 0; - protected Vector3d mNormal; - protected Point3d mPoint; - protected boolean mIsCuttingStringer = false; - protected boolean mIsCuttingRail = false; - protected boolean mIsCuttingOutline = false; - - protected boolean mFirstCoordinate = false; protected int mMoveToNextToolpathSteps = 5; protected int mBottomSideChangeSteps = 10; protected int mDeckSideChangeSteps = 10; - protected boolean mNoseToTail = false; + protected boolean mFirstCoordinate = false; protected MachineConfig mConfig; @@ -129,6 +117,27 @@ public class State { protected SandwichCompensation mSandwichCompensation; + protected boolean mNoseToTail = false; + protected int mCurrentState = State.NO_STATE; + protected int mCutNumber = 0; + protected double y = 0; + protected int i = 0; + protected int j = 0; + protected Vector3d mNormal; + protected Point3d mPoint; + protected boolean mIsCuttingStringer = false; + protected boolean mIsCuttingRail = false; + protected boolean mIsCuttingOutline = false; + + static int mDeckProgress = 0; + static int mBottomProgress = 0; + + + protected BezierBoard mBrd; + + protected SurfaceSplitsToolpathGenerator mDeckGenerator = null; + protected SurfaceSplitsToolpathGenerator mBottomGenerator = null; + public SurfaceSplitsToolpathGenerator(MachineConfig config, AbstractMachineWriter writer, MachineView view) { super(writer, view); @@ -146,6 +155,10 @@ protected void initDeck() { mLastSurfacePoint = null; mLastToolpathPoint = null; mFirstCoordinate = true; + + mPoint = new Point3d(0.0, 0.0, 0.0); + mNormal = new Vector3d(0.0, 0.0, 0.0); + mNoseToTail = mStartDeckCutAtTail ? false : true; mCurrentState = mStartDeckCutAtTail ? State.DECK_STRINGER_CUT @@ -154,15 +167,6 @@ protected void initDeck() { mIsCuttingRail = false; mIsCuttingOutline = false; - mCurrentCutter.update3DModel(); - mMachineView.get3DView().setDeckActive(); - - mCurrentCutter.setStayAwayFromStringer(mStayAwayFromStringer); - mCurrentCutter.setStringerWidth(mStringerWidth); - mMachineView.get3DView().setCutterpos(new Point3d(0.0, 0.0, 0.0)); - - setCutterOffset(mConfig.getCutterOffset()); - setOffsetAndRotation( mCurrentBlankHoldingSystem.getBoardDeckOffsetPos(), mCurrentBlankHoldingSystem.getBoardDeckOffsetAngle(), 10.0); @@ -192,10 +196,13 @@ protected void initBottom() { y = 0; i = 0; j = 0; - mLastSurfacePoint = null; - mLastToolpathPoint = null; + mLastSurfacePoint = new Point3d(0.0, 0.0, 0.0); + mLastToolpathPoint = new Point3d(0.0, 0.0, 0.0); mFirstCoordinate = true; + mPoint = new Point3d(0.0, 0.0, 0.0); + mNormal = new Vector3d(0.0, 0.0, 0.0); + mHasCutBottomStringer = false; switch (mBottomStartPos) { @@ -216,13 +223,14 @@ protected void initBottom() { mIsCuttingRail = false; mIsCuttingOutline = false; - mCurrentCutter.update3DModel(); - mMachineView.get3DView().setBottomActive(); - mMachineView.get3DView().setCutterModel(mCurrentCutter.get3DModel()); - mMachineView.get3DView().setCutterpos(new Point3d(0.0, 0.0, 0.0)); - - setCutterOffset(mConfig.getCutterOffset()); - + /* + * mCurrentCutter.update3DModel(); + * mMachineView.get3DView().setBottomActive(); + * mMachineView.get3DView().setCutterModel(mCurrentCutter.get3DModel()); + * mMachineView.get3DView().setCutterpos(new Point3d(0.0, 0.0, 0.0)); + * + * setCutterOffset(mConfig.getCutterOffset()); + */ setOffsetAndRotation( mCurrentBlankHoldingSystem.getBoardBottomOffsetPos(), mCurrentBlankHoldingSystem.getBoardBottomOffsetAngle(), 10.0); @@ -249,7 +257,7 @@ protected void initBottom() { } protected void writeToolpathBegin() { - mCurrentWriter.writeComment(mStream, "Generated with BoardCAD v2.0"); + mCurrentWriter.writeComment(mStream, "Generated with BoardCAD v3.1"); // TODO: Write time and date mCurrentWriter.writeComment(mStream, isDeckCut() ? LanguageResource.getString("DECKCUT_STR") @@ -410,35 +418,99 @@ public void writeToolpath(String filename, AbstractBoard board, mBoard = board; mBlank = blank; - mCurrentCutter = mConfig.getCutter(); + BezierBoard brd = (BezierBoard) mBoard; + mBrd = (BezierBoard) brd.clone(); + + try{ + mCurrentCutter = (AbstractCutter)mConfig.getCutter().clone(); + } catch (CloneNotSupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } mCurrentBlankHoldingSystem = mConfig.getBlankHoldingSystem(); - SwingWorker worker = getNewWorker(); - worker.execute(); + mProgress.setProgress(0); + mDeckProgress = 0; + mBottomProgress = 0; + + mCutNumber = 0; + + mMachineView.get3DView().reset(); + + getSettings(mConfig); + + mLength = mBoard.getLength() - 0.1;// BezierPatch.ZERO; + mNrOfLengthSplits = ((int) (mLength / mLengthwiseResolution)) + 1; + + mCurrentCutter.init(); + + mCurrentCutter.update3DModel(); + mMachineView.get3DView().setDeckActive(); + + mCurrentCutter.setStayAwayFromStringer(mStayAwayFromStringer); + mCurrentCutter.setStringerWidth(mStringerWidth); + mMachineView.get3DView().setCutterPos(new Point3d(0.0, 0.0, 0.0)); + + setCutterOffset(mConfig.getCutterOffset()); + + try { + mDeckGenerator = (SurfaceSplitsToolpathGenerator) this.clone(); + mBottomGenerator = (SurfaceSplitsToolpathGenerator) this.clone(); + } catch (CloneNotSupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + SwingWorker deckWorker = getDeckWorker(); + deckWorker.execute(); + + SwingWorker bottomWorker = getBottomWorker(); + bottomWorker.execute(); } - protected SwingWorker getNewWorker() { + protected SwingWorker getDeckWorker() { return new SwingWorker() { protected Void doInBackground() throws Exception { try { - mProgress.setProgress(0); - mMachineView.get3DView().reset(); + mDeckGenerator.initDeck(); + mDeckGenerator.writeToolpath(); - getSettings(mConfig); + mProgress.close(); + } catch (Exception e) { + System.out + .println("Exception in SwingWorker::doInBackground(): " + + e.toString()); - mLength = mBoard.getLength() - 0.1;// BezierPatch.ZERO; - mNrOfLengthSplits = ((int) (mLength / mLengthwiseResolution)) + 1; + mProgress.close(); - mCurrentCutter.init(); + JOptionPane.showMessageDialog( + mConfig.getMachineView(), + "An error occured when writing g-code, error:" + + e.toString(), + "Error when writing G-Code file", + JOptionPane.ERROR_MESSAGE); + + return null; + } + + return null; + } + }; + + } + + protected SwingWorker getBottomWorker() { + return new SwingWorker() { + + protected Void doInBackground() throws Exception { - initDeck(); - writeToolpath(); + try { - initBottom(); - writeToolpath(); + mBottomGenerator.initBottom(); + mBottomGenerator.writeToolpath(); mProgress.close(); } catch (Exception e) { @@ -484,7 +556,7 @@ protected void getSettings(MachineConfig config) { mDeckCutOutline = cutsSettings .getBoolean(MachineConfig.DECK_OUTLINE_CUT); mDeckCutOutlineDepth = cutsSettings - .getEnumeration(MachineConfig.DECK_OUTLINE_CUT_DEPTH); + .getEnumeration(MachineConfig.DECK_OUTLINE_CUT_DEPTH); mBottomCutOutline = cutsSettings .getBoolean(MachineConfig.BOTTOM_OUTLINE_CUT); mCutOffNose = cutsSettings.getBoolean(MachineConfig.CUT_OFF_NOSE); @@ -539,8 +611,7 @@ protected boolean isDeckCut() { || mCurrentState == State.DECK_LEFT_CUT || mCurrentState == State.DECK_LEFT_RAIL_CUT || mCurrentState == State.DECK_LEFT_OUTLINE_CUT - || mCurrentState == State.DECK_LEFT_CLEANUP_CUT - || mCurrentState == State.DECK_FINISHED); + || mCurrentState == State.DECK_LEFT_CLEANUP_CUT || mCurrentState == State.DECK_FINISHED); } protected boolean isBottomCut() { @@ -553,8 +624,7 @@ protected boolean isBottomCut() { || mCurrentState == State.BOTTOM_LEFT_CUT || mCurrentState == State.BOTTOM_LEFT_RAIL_CUT || mCurrentState == State.BOTTOM_LEFT_OUTLINE_CUT - || mCurrentState == State.BOTTOM_LEFT_CLEANUP_CUT - || mCurrentState == State.BOTTOM_FINISHED); + || mCurrentState == State.BOTTOM_LEFT_CLEANUP_CUT || mCurrentState == State.BOTTOM_FINISHED); } protected boolean isOutlineCut() { @@ -562,8 +632,7 @@ protected boolean isOutlineCut() { || mCurrentState == State.DECK_RIGHT_CLEANUP_CUT || mCurrentState == State.DECK_LEFT_OUTLINE_CUT || mCurrentState == State.DECK_LEFT_CLEANUP_CUT - || mCurrentState == State.BOTTOM_RIGHT_OUTLINE_CUT - || mCurrentState == State.BOTTOM_LEFT_OUTLINE_CUT); + || mCurrentState == State.BOTTOM_RIGHT_OUTLINE_CUT || mCurrentState == State.BOTTOM_LEFT_OUTLINE_CUT); } protected boolean isRightCut() { @@ -575,27 +644,29 @@ protected boolean isRightCut() { || mCurrentState == State.BOTTOM_RIGHT_CUT || mCurrentState == State.BOTTOM_RIGHT_RAIL_CUT || mCurrentState == State.BOTTOM_RIGHT_OUTLINE_CUT - || mCurrentState == State.BOTTOM_RIGHT_CLEANUP_CUT - || mCurrentState == State.BOTTOM_FINISHED); + || mCurrentState == State.BOTTOM_RIGHT_CLEANUP_CUT || mCurrentState == State.BOTTOM_FINISHED); } - + protected boolean isSideChange() { - return (mCurrentState == State.DECK_SIDE_CHANGE - || mCurrentState == State.BOTTOM_SIDE_CHANGE); + return (mCurrentState == State.DECK_SIDE_CHANGE || mCurrentState == State.BOTTOM_SIDE_CHANGE); } public Point3d getToolpathCoordinate() { getCurrentStateCut(); - if(mPoint != null) - { - if (mSandwichCompensation.compensateOutlineCuts() && isOutlineCut() && !isSideChange()) { - mPoint = mSandwichCompensation - .compensateOutlineCut(mPoint, mNormal); - } else if (mSandwichCompensation.compensateDeckCuts() && isDeckCut() && !isSideChange()) { - mPoint = mSandwichCompensation.compensateDeckCut(mPoint, mNormal); - } else if (mSandwichCompensation.compensateBottomCuts() && isBottomCut() && !isSideChange()) { - mPoint = mSandwichCompensation.compensateBottomCut(mPoint, mNormal); + if (mPoint != null) { + if (mSandwichCompensation.compensateOutlineCuts() && isOutlineCut() + && !isSideChange()) { + mPoint = mSandwichCompensation.compensateOutlineCut(mPoint, + mNormal); + } else if (mSandwichCompensation.compensateDeckCuts() + && isDeckCut() && !isSideChange()) { + mPoint = mSandwichCompensation.compensateDeckCut(mPoint, + mNormal); + } else if (mSandwichCompensation.compensateBottomCuts() + && isBottomCut() && !isSideChange()) { + mPoint = mSandwichCompensation.compensateBottomCut(mPoint, + mNormal); } } @@ -659,12 +730,25 @@ protected void nextToolpath() { } protected void updateProgress() { - setProgressDone((int) (((double) mCutNumber / (double) mTotalCuts) * 100.0)); + + if(isBottomCut()) + { + mBottomProgress = (int) (((double) mCutNumber / (double) mTotalCuts) * 100.0); + } + else + { + mDeckProgress = (int) (((double) mCutNumber / (double) mTotalCuts) * 100.0); + } + + int progress = mDeckProgress + mBottomProgress; + + setProgressDone(progress); } protected void getCurrentStateCut() { - double x = getX(i, j); //DEBUG -// System.out.printf("SurfaceSplitToolpathGenerator.getCurrentStateCut() state:%s, i:%d, j:%d, x:%f\n",getStateString(mCurrentState), i, j, x); + double x = getX(i, j); // DEBUG + // System.out.printf("SurfaceSplitToolpathGenerator.getCurrentStateCut() state:%s, i:%d, j:%d, x:%f\n",getStateString(mCurrentState), + // i, j, x); switch (mCurrentState) { case State.DECK_STRINGER_CUT: @@ -1027,8 +1111,8 @@ protected void nextState() { break; } -// System.out.printf("Changed state to %s\n", -// getStateString(mCurrentState)); + // System.out.printf("Changed state to %s\n", + // getStateString(mCurrentState)); i = 0; j = 0; @@ -1138,12 +1222,15 @@ protected void getDeckStringerCut() { // mPoint = getSurfacePoint(x, DECK_EXTREME_ANGLE, mDeckAngle, 0, 1); // mPoint = getSurfacePoint(x, 0.0); // mNormal = getSurfaceNormal(x, DECK_EXTREME_ANGLE, mDeckAngle, 0, 1); - BezierBoard brd = (BezierBoard) mBoard; - double y = brd.getDeck().getValueAt(x); - Point2D.Double normal2d = brd.getDeck().getNormalAt(x); + double y = mBrd.getDeck().getValueAt(x); + Point2D.Double normal2d = mBrd.getDeck().getNormalAt(x); - mPoint = new Point3d(x, 0.0, y); - mNormal = new Vector3d(normal2d.x, 0.0, normal2d.y); + mPoint.x = x; + mPoint.y = 0.0; + mPoint.z = y; + mNormal.x = normal2d.x; + mNormal.y = 0.0; + mNormal.z = normal2d.y; } @@ -1195,19 +1282,23 @@ protected void getDeckOutlineRightCut() { double x = getX(i, j); // system.out.printf("getDeckOutlineRightCut() Cut: %d x: %f\n", i+1, // x); - Point3d bottomPoint = getSurfacePoint(x, mBottomAngle, - mBottomAngle, 0, 1); // Find z value for tuck under - Point3d apexPoint = getSurfacePoint(x, NINTY_ANGLE, - NINTY_ANGLE, 0, 1); // Find z value for apex - BezierBoard brd = (BezierBoard) mBoard; - double bottomZ = brd.getBottom().getValueAt(x); - //System.out.printf("getDeckOutlineRightCut: apex z:%f bottom z:%f bottomPoint.z:%f", apexPoint.z, bottomZ, bottomPoint.z); + Point3d bottomPoint = getSurfacePoint(x, mBottomAngle, mBottomAngle, 0, + 1); // Find z value for tuck under + Point3d apexPoint = getSurfacePoint(x, NINTY_ANGLE, NINTY_ANGLE, 0, 1); // Find + // z + // value + // for + // apex + double bottomZ = mBrd.getBottom().getValueAt(x); + // System.out.printf("getDeckOutlineRightCut: apex z:%f bottom z:%f bottomPoint.z:%f", + // apexPoint.z, bottomZ, bottomPoint.z); // Point3d railPoint = getSurfacePoint(x, DECK_EXTREME_ANGLE,90.0,1,1); // //Find rail point double railPoint = ((BezierBoard) mBoard).getOutline().getValueAt(x); // Find // rail // point - mPoint = new Point3d(x, railPoint, mDeckCutOutlineDepth==0?apexPoint.z:bottomPoint.z); + mPoint = new Point3d(x, railPoint, + mDeckCutOutlineDepth == 0 ? apexPoint.z : bottomPoint.z); Point2D.Double normal = ((BezierBoard) mBoard).getOutline() .getNormalAt(x); // Find rail point @@ -1230,13 +1321,14 @@ protected void getDeckRailCleanupRightCut() { protected void getDeckLeftCut() { if (j < mMoveToNextToolpathSteps) { double x = getX(i, 0); - //System.out.printf("getDeckRightCut() Move to next cut: %d step: %d\n", i+1, j); + // System.out.printf("getDeckRightCut() Move to next cut: %d step: %d\n", + // i+1, j); getMoveBetweenCuts(x, DECK_EXTREME_ANGLE, mDeckAngle, i * mMoveToNextToolpathSteps + j, mDeckCuts * mMoveToNextToolpathSteps, false, false, true); } else { double x = getX(i, j - mMoveToNextToolpathSteps); - System.out.printf("getDeckLeftCut() Cut: %d x: %f\n", i+1, x); + System.out.printf("getDeckLeftCut() Cut: %d x: %f\n", i + 1, x); mPoint = getSurfacePoint(x, DECK_EXTREME_ANGLE, mDeckAngle, i + 1, mDeckCuts); mNormal = getSurfaceNormal(x, DECK_EXTREME_ANGLE, mDeckAngle, @@ -1300,21 +1392,20 @@ protected void getDeckSideChange() { if (stepsLeft >= 2) { double startAngle = (mDeckRailCuts > 0) ? mDeckRailAngle : mDeckAngle; - if (startAngle > 90) { //Move if undercut + if (startAngle > 90) { // Move if undercut getMoveBetweenCuts(x, 90.0, startAngle, mDeckSideChangeSteps - j, mDeckSideChangeSteps, false, false, true); - } - else{ - //Do nothing, just wait to go over stringer + } else { + // Do nothing, just wait to go over stringer } } else { - mNormal = new Vector3d( mNoseToTail?1.0:-1.0, 0.0, 0.0); + mNormal = new Vector3d(mNoseToTail ? 1.0 : -1.0, 0.0, 0.0); mPoint = new Point3d(mPoint); if (stepsLeft == 1) { mPoint.z = mPoint.z + 5.0; } else { - mPoint.y = -mStringerWidth*5 / 2; + mPoint.y = -mStringerWidth * 5 / 2; } } @@ -1330,14 +1421,13 @@ protected void getDeckSideChange() { protected void getBottomStringerCut() { double x = getX(i, j); - BezierBoard brd = (BezierBoard) mBoard; // system.out.printf("getBottomStringerCut() Cut: %d x: %f\n", i+1, x); // mPoint = getSurfacePoint(x, BezierSpline.ONE); - // mPoint = new Point3d(0.0,0.0,brd.getRockerAtPos(x)); + // mPoint = new Point3d(0.0,0.0,mBrd.getRockerAtPos(x)); // mPoint = getSurfacePoint(x, BOTTOM_EXTREME_ANGLE, mBottomAngle, 0, 1, // false); - double y = brd.getBottom().getValueAt(x); - Point2D.Double normal = brd.getBottom().getNormalAt(x); + double y = mBrd.getBottom().getValueAt(x); + Point2D.Double normal = mBrd.getBottom().getNormalAt(x); mPoint = new Point3d(x, 0.0, y); mNormal = new Vector3d(normal.x, 0.0, normal.y); @@ -1347,29 +1437,30 @@ protected void getBottomStringerCut() { } protected void getBottomRightCut() { - //System.out.printf("-------------------------------------------------------\n"); + // System.out.printf("-------------------------------------------------------\n"); if (j < mMoveToNextToolpathSteps) { - //System.out.printf("#### Move between paths\n"); + // System.out.printf("#### Move between paths\n"); double x = getX(i, 0); // system.out.printf("getBottomRightCut() Move to next cut: %d step: %d\n", // i+1, j-mNrOfLengthSplits); getMoveBetweenCuts(x, BOTTOM_EXTREME_ANGLE, mBottomAngle, i * mMoveToNextToolpathSteps + j, mBottomCuts * mMoveToNextToolpathSteps, false, false, true); - } - else - { - //System.out.printf("**** Cut\n"); + } else { + // System.out.printf("**** Cut\n"); double x = getX(i, j - mMoveToNextToolpathSteps); // system.out.printf("getBottomRightCut() Cut: %d x: %f\n", i+1, x); mPoint = getSurfacePoint(x, BOTTOM_EXTREME_ANGLE, mBottomAngle, i + 1, mBottomCuts, true); mNormal = getSurfaceNormal(x, BOTTOM_EXTREME_ANGLE, mBottomAngle, i + 1, mBottomCuts, true); - //System.out.printf("getBottomRightCut() Step: %d/%d x:%f, minAngle:%f, maxAngle:%f,\n", i + 1, mBottomCuts, x, BOTTOM_EXTREME_ANGLE, mBottomAngle); - //System.out.printf("getBottomRightCut() mPoint: %f, %f, %f mNormal: %f, %f, %f\n", mPoint.x, mPoint.y, mPoint.z, mNormal.x, mNormal.y, mNormal.z); + // System.out.printf("getBottomRightCut() Step: %d/%d x:%f, minAngle:%f, maxAngle:%f,\n", + // i + 1, mBottomCuts, x, BOTTOM_EXTREME_ANGLE, mBottomAngle); + // System.out.printf("getBottomRightCut() mPoint: %f, %f, %f mNormal: %f, %f, %f\n", + // mPoint.x, mPoint.y, mPoint.z, mNormal.x, mNormal.y, mNormal.z); } - //System.out.printf("getBottomRightCut() i:%d j:%d mPoint: %f, %f, %f\n",i,j, mPoint.x, mPoint.y, mPoint.z); + // System.out.printf("getBottomRightCut() i:%d j:%d mPoint: %f, %f, %f\n",i,j, + // mPoint.x, mPoint.y, mPoint.z); flip(); } @@ -1458,7 +1549,7 @@ protected void getBottomSideChange() { true, false, (mBottomRailCuts > 0) ? true : false); } } else { - mNormal = new Vector3d( mNoseToTail?1.0:-1.0, 0.0, 0.0); + mNormal = new Vector3d(mNoseToTail ? 1.0 : -1.0, 0.0, 0.0); mPoint = new Point3d(mPoint); if (stepsLeft == 1) { mPoint.z = mPoint.z + 5.0; @@ -1476,17 +1567,25 @@ protected void getBottomSideChange() { } } - protected void getMoveBetweenCuts(double x, double minAngle, double maxAngle, int i, int cuts, boolean flip, boolean mirror, boolean useMinimumAngleOnSharpCorners) - { - System.out.printf("getMoveBetweenCuts() Step: %d/%d x:%f, minAngle:%f, maxAngle:%f,\n", i, cuts,x, minAngle, maxAngle); + protected void getMoveBetweenCuts(double x, double minAngle, + double maxAngle, int i, int cuts, boolean flip, boolean mirror, + boolean useMinimumAngleOnSharpCorners) { + System.out + .printf("getMoveBetweenCuts() Step: %d/%d x:%f, minAngle:%f, maxAngle:%f,\n", + i, cuts, x, minAngle, maxAngle); if (i > cuts) i = cuts; - mPoint = getSurfacePoint(x, minAngle, maxAngle, i, cuts, useMinimumAngleOnSharpCorners); - mNormal = getSurfaceNormal(x, minAngle, maxAngle, i, cuts, useMinimumAngleOnSharpCorners); + mPoint = getSurfacePoint(x, minAngle, maxAngle, i, cuts, + useMinimumAngleOnSharpCorners); + mNormal = getSurfaceNormal(x, minAngle, maxAngle, i, cuts, + useMinimumAngleOnSharpCorners); - System.out.printf("getMoveBetweenCuts() mPoint: %f, %f, %f mNormal: %f, %f, %f\n", mPoint.x, mPoint.y, mPoint.z, mNormal.x, mNormal.y, mNormal.z); + System.out + .printf("getMoveBetweenCuts() mPoint: %f, %f, %f mNormal: %f, %f, %f\n", + mPoint.x, mPoint.y, mPoint.z, mNormal.x, mNormal.y, + mNormal.z); // mPoint.add(mNormal); //Lift @@ -1511,8 +1610,7 @@ protected void flip() { protected Point3d getSurfacePoint(double x, double minAngle, double maxAngle, int currentSplit, int totalSplits) { - BezierBoard brd = (BezierBoard) mBoard; // Only Brd supported yet - return brd.getSurfacePoint(x, minAngle, maxAngle, currentSplit, + return mBrd.getSurfacePoint(x, minAngle, maxAngle, currentSplit, totalSplits); } @@ -1520,31 +1618,30 @@ protected Point3d getSurfacePoint(double x, double minAngle, protected Point3d getSurfacePoint(double x, double minAngle, double maxAngle, int currentSplit, int totalSplits, boolean useMinimumAngleOnSharpCorners) { - //System.out.printf("getSurfacePoint(x:%f, minAngle:%f, maxAngle:%f, currentSplit:%d, totalSplits:%d, useMinimumAngleOnSharpCorners:%s)\n",x,minAngle,maxAngle,currentSplit,totalSplits, useMinimumAngleOnSharpCorners?"true":"false"); - BezierBoard brd = (BezierBoard) mBoard; // Only Brd supported yet - return brd.getSurfacePoint(x, minAngle, maxAngle, currentSplit, + // System.out.printf("getSurfacePoint(x:%f, minAngle:%f, maxAngle:%f, currentSplit:%d, totalSplits:%d, useMinimumAngleOnSharpCorners:%s)\n",x,minAngle,maxAngle,currentSplit,totalSplits, + // useMinimumAngleOnSharpCorners?"true":"false"); + return mBrd.getSurfacePoint(x, minAngle, maxAngle, currentSplit, totalSplits, useMinimumAngleOnSharpCorners); } protected Point3d getSurfacePoint(double x, double s) { - BezierBoard brd = (BezierBoard) mBoard; // Only Brd supported yet - return brd.getSurfacePoint(x, s); + return mBrd.getSurfacePoint(x, s); } protected Vector3d getSurfaceNormal(double x, double minAngle, double maxAngle, int currentSplit, int totalSplits) { - - //System.out.printf("getSurfaceNormal(double x:%f, double minAngle:%f, double maxAngle:%f, int currentSplit:%d, int totalSplits:%d)\n", x, minAngle, maxAngle, currentSplit, totalSplits); - + + // System.out.printf("getSurfaceNormal(double x:%f, double minAngle:%f, double maxAngle:%f, int currentSplit:%d, int totalSplits:%d)\n", + // x, minAngle, maxAngle, currentSplit, totalSplits); + if (x < 1.0) x = 1.0; if (x > mLength - 1.0) x = mLength - 1.0; - BezierBoard brd = (BezierBoard) mBoard; // Only Brd supported yet - return brd.getSurfaceNormal(x, minAngle, maxAngle, currentSplit, + return mBrd.getSurfaceNormal(x, minAngle, maxAngle, currentSplit, totalSplits); } @@ -1556,10 +1653,12 @@ protected Vector3d getSurfaceNormal(double x, double minAngle, if (x > mLength - 0.1) x = mLength - 0.1; - System.out.printf("getSurfaceNormal(double x:%f, double minAngle:%f, double maxAngle:%f, int currentSplit:%d, int totalSplits:%d, boolean useMinimumAngleOnSharpCorners:%s)\n", x, minAngle, maxAngle, currentSplit, totalSplits, useMinimumAngleOnSharpCorners?"true":"false"); + System.out + .printf("getSurfaceNormal(double x:%f, double minAngle:%f, double maxAngle:%f, int currentSplit:%d, int totalSplits:%d, boolean useMinimumAngleOnSharpCorners:%s)\n", + x, minAngle, maxAngle, currentSplit, totalSplits, + useMinimumAngleOnSharpCorners ? "true" : "false"); - BezierBoard brd = (BezierBoard) mBoard; // Only Brd supported yet - return brd.getSurfaceNormal(x, minAngle, maxAngle, currentSplit, + return mBrd.getSurfaceNormal(x, minAngle, maxAngle, currentSplit, totalSplits, useMinimumAngleOnSharpCorners); } @@ -1569,8 +1668,7 @@ protected Vector3d getSurfaceNormal(double x, double s) { if (x > mLength - 1.0) x = mLength - 1.0; - BezierBoard brd = (BezierBoard) mBoard; // Only Brd supported yet - return brd.getSurfaceNormal(x, s); + return mBrd.getSurfaceNormal(x, s); } /* @@ -1710,72 +1808,88 @@ protected void setToolpathStart(Point3d point) { mMachineView.get3DView().setBottomToolpathStart(point); } } - + protected boolean checkCollision(Point3d pos, AbstractBoard board) { -//TODO: pseudo-implementation, implement the missing function to provide a simpler way to avoid hitting the stringer -// if(mStayAwayFromStringer && mCurrentCutter.checkCollisionWithStringer(pos)) -// { -// double blankZ = isDeckCut()?mBlankholdingSystem.getBlankDeckAt(pos.x, pos.y):mBlankholdingSystem.getBlankBottomAt(pos.x, pos.y); -// double liftZ = blankZ + 25.0f; //One inch above blank; -// -// if(mLastToolpathPoint != null) -// { -// Point3d lift = new Point3d(mLastToolpathPoint); -// if(lift.z < liftZ) -// { -// lift.z = liftZ; -// -// addToolpathLine(lift); -// writeCoordinate(new double[]{lift.x, lift.y, lift.z}); -// } -// } -// -// Point3d aboveStringerPos = new Point3d(pos); -// aboveStringerPos.z = liftZ; -// aboveStringerPos.sub(mCutterOffset); -// -// if (mLastToolpathPoint == null) -// { -// setToolpathStart(aboveStringerPos); -// } -// else -// { -// addToolpathLine(aboveStringerPos); -// } -// -// writeCoordinate(new double[]{aboveStringerPos.x, aboveStringerPos.y, aboveStringerPos.z}); -// -// mLastToolpathPoint = aboveStringerPos; -// -// mPreviousCollisionWithStringer = true; -// -// } -// else if(mPreviousCollisionWithStringer) -// { -// double blankZ = isDeckCut()?mBlankholdingSystem.getBlankDeckAt(pos.x, pos.y):mBlankholdingSystem.getBlankBottomAt(pos.x, pos.y); -// double liftZ = blankZ + 25.0f; //One inch above blank; -// -// Point3d aboveStringerPos = new Point3d(pos); -// aboveStringerPos.z = liftZ; -// aboveStringerPos.sub(mCutterOffset); -// -// if (mLastToolpathPoint == null) -// { -// setToolpathStart(aboveStringerPos); -// } -// else -// { -// addToolpathLine(aboveStringerPos); -// } -// -// writeCoordinate(new double[]{aboveStringerPos.x, aboveStringerPos.y, aboveStringerPos.z}); -// -// mLastToolpathPoint = aboveStringerPos; -// -// mPreviousCollisionWithStringer = false; -// } - + // TODO: pseudo-implementation, implement the missing function to + // provide a simpler way to avoid hitting the stringer + // if(mStayAwayFromStringer && + // mCurrentCutter.checkCollisionWithStringer(pos)) + // { + // double blankZ = isDeckCut()?mBlankholdingSystem.getBlankDeckAt(pos.x, + // pos.y):mBlankholdingSystem.getBlankBottomAt(pos.x, pos.y); + // double liftZ = blankZ + 25.0f; //One inch above blank; + // + // if(mLastToolpathPoint != null) + // { + // Point3d lift = new Point3d(mLastToolpathPoint); + // if(lift.z < liftZ) + // { + // lift.z = liftZ; + // + // addToolpathLine(lift); + // writeCoordinate(new double[]{lift.x, lift.y, lift.z}); + // } + // } + // + // Point3d aboveStringerPos = new Point3d(pos); + // aboveStringerPos.z = liftZ; + // aboveStringerPos.sub(mCutterOffset); + // + // if (mLastToolpathPoint == null) + // { + // setToolpathStart(aboveStringerPos); + // } + // else + // { + // addToolpathLine(aboveStringerPos); + // } + // + // writeCoordinate(new double[]{aboveStringerPos.x, aboveStringerPos.y, + // aboveStringerPos.z}); + // + // mLastToolpathPoint = aboveStringerPos; + // + // mPreviousCollisionWithStringer = true; + // + // } + // else if(mPreviousCollisionWithStringer) + // { + // double blankZ = isDeckCut()?mBlankholdingSystem.getBlankDeckAt(pos.x, + // pos.y):mBlankholdingSystem.getBlankBottomAt(pos.x, pos.y); + // double liftZ = blankZ + 25.0f; //One inch above blank; + // + // Point3d aboveStringerPos = new Point3d(pos); + // aboveStringerPos.z = liftZ; + // aboveStringerPos.sub(mCutterOffset); + // + // if (mLastToolpathPoint == null) + // { + // setToolpathStart(aboveStringerPos); + // } + // else + // { + // addToolpathLine(aboveStringerPos); + // } + // + // writeCoordinate(new double[]{aboveStringerPos.x, aboveStringerPos.y, + // aboveStringerPos.z}); + // + // mLastToolpathPoint = aboveStringerPos; + // + // mPreviousCollisionWithStringer = false; + // } + return mCurrentCutter.checkCollision(pos, board); } + + public Object clone() throws CloneNotSupportedException { + + SurfaceSplitsToolpathGenerator gen = (SurfaceSplitsToolpathGenerator) super + .clone(); + + gen.mBrd = (BezierBoard) mBrd.clone(); + + return gen; + } } \ No newline at end of file diff --git a/boardcam/writers/GCodeWriter.java b/boardcam/writers/GCodeWriter.java index 0bdc9ae..9e10934 100644 --- a/boardcam/writers/GCodeWriter.java +++ b/boardcam/writers/GCodeWriter.java @@ -10,6 +10,7 @@ public class GCodeWriter extends AbstractMachineWriter{ private static String mAxis = "XYZAF"; + private double mLastSpeed = 0.0; public GCodeWriter() { @@ -32,6 +33,12 @@ public void writePause(PrintStream stream, double seconds) public void writeComment(PrintStream stream, String comment) { + if(!comment.contains("\n")) + { + stream.printf("(%s)\n", comment); + return; + } + String[] list = comment.split("\n"); for(int i = 0; i < list.length; i++) @@ -57,7 +64,20 @@ public void writeToolOff(PrintStream stream) public void writeSpeed(PrintStream stream, int speed) { - stream.printf("F%d\n", speed); + if(mLastSpeed != speed) + { + stream.printf("F%d\n", speed); + mLastSpeed = speed; + } + } + + public void writeSpeed(PrintStream stream, double speed) + { + if(mLastSpeed != speed) + { + stream.printf("F%f\n", speed); + mLastSpeed = speed; + } } public void writeBeginGoTo(PrintStream stream) @@ -72,6 +92,17 @@ public void writeBeginJogTo(PrintStream stream) public void writeCoordinate(PrintStream stream, double x, double y, double z) { +// System.out.printf("GCodeWriter.writeCoordinate X%4.4f Y%4.4f Z%4.4f\n", x, y, z); + + if(Double.isInfinite(x) || Double.isInfinite(y) || Double.isInfinite(z)) + { + System.out.printf("GCodeWriter.writeCoordinate INFINITE VALUE X%4.4f Y%4.4f Z%4.4f\n", x, y, z); + } + if(Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z)) + { + System.out.printf("GCodeWriter.writeCoordinate NAN VALUE X%4.4f Y%4.4f Z%4.4f\n", x, y, z); + } + stream.printf("X%4.4f Y%4.4f Z%4.4f\n", x, y, z); } diff --git a/cadcore/AbstractBezierBoardSurfaceModel.java b/cadcore/AbstractBezierBoardSurfaceModel.java index 79e03d8..4511a6d 100644 --- a/cadcore/AbstractBezierBoardSurfaceModel.java +++ b/cadcore/AbstractBezierBoardSurfaceModel.java @@ -11,6 +11,10 @@ abstract public class AbstractBezierBoardSurfaceModel //LinearInterpolation is obsolete, keep for reference public enum ModelType{LinearInterpolation, ControlPointInterpolation, SLinearInterpolation}; + static private BezierBoardControlPointInterpolationSurfaceModel mControlPointInterpolationInstance = new BezierBoardControlPointInterpolationSurfaceModel(); + + static private BezierBoardSLinearInterpolationSurfaceModel mSLinearInterpolationInstance = new BezierBoardSLinearInterpolationSurfaceModel(); + static public AbstractBezierBoardSurfaceModel getBezierBoardSurfaceModel(ModelType modelType) { @@ -19,10 +23,10 @@ static public AbstractBezierBoardSurfaceModel getBezierBoardSurfaceModel(ModelTy default: case ControlPointInterpolation: - return new BezierBoardControlPointInterpolationSurfaceModel(); + return mControlPointInterpolationInstance; case SLinearInterpolation: - return new BezierBoardSLinearInterpolationSurfaceModel(); + return mSLinearInterpolationInstance; } } @@ -48,9 +52,9 @@ public Vector3d getDeckNormalAt(final BezierBoard brd, final double x, final dou Point3d p1 = getDeckAt(brd,x,y); Point3d p2 = getDeckAt(brd,x,yo); - Vector3d pv = new Vector3d(0, y-yo, p2.z-p1.z); - Point3d p3 = getDeckAt(brd,xo,y); + + Vector3d pv = new Vector3d(0, y-yo, p2.z-p1.z); Vector3d lv = new Vector3d(x-xo, 0, p3.z-p1.z); Vector3d normalVec = new Vector3d(); diff --git a/cadcore/BezierBoardControlPointInterpolationSurfaceModel.java b/cadcore/BezierBoardControlPointInterpolationSurfaceModel.java index f6aa58f..211e94d 100644 --- a/cadcore/BezierBoardControlPointInterpolationSurfaceModel.java +++ b/cadcore/BezierBoardControlPointInterpolationSurfaceModel.java @@ -12,7 +12,7 @@ class BezierBoardControlPointInterpolationSurfaceModel extends AbstractBezierBoardSurfaceModel { - synchronized public Point3d getDeckAt(final BezierBoard brd, final double x, + public Point3d getDeckAt(final BezierBoard brd, final double x, final double y) { Function func = new Function() { public double f(double s) { @@ -29,8 +29,9 @@ public double f(double s) { return point; } - synchronized public Point3d getBottomAt(final BezierBoard brd, final double x, + public Point3d getBottomAt(final BezierBoard brd, final double x, final double y) { + Function func = new Function() { public double f(double s) { return getPointAt(brd, x, s, 90.0, 270.0, true).y; @@ -41,9 +42,10 @@ public double f(double s) { return getPointAt(brd, x, s, 90.0, 270.0, true); } - synchronized public Point3d getPointAt(final BezierBoard brd, double x, double s, + public Point3d getPointAt(final BezierBoard brd, double x, double s, double minAngle, double maxAngle, boolean useMinimumAngleOnSharpCorners) { + if (x < 0.1) x = 0.1; @@ -84,7 +86,7 @@ synchronized public Point3d getPointAt(final BezierBoard brd, double x, double s return point; } - synchronized public Vector3d getNormalAt(final BezierBoard brd, double x, double s, + public Vector3d getNormalAt(final BezierBoard brd, double x, double s, double minAngle, double maxAngle, boolean useMinimumAngleOnSharpCorners) { if (x < 0.1) @@ -105,11 +107,12 @@ synchronized public Vector3d getNormalAt(final BezierBoard brd, double x, double x = brd.getLength() - 1.0; } - BezierBoardCrossSection crossSection = (BezierBoardCrossSection) (brd - .getInterpolatedCrossSection(x).clone()); + BezierBoardCrossSection crossSection = brd .getInterpolatedCrossSection(x); if (crossSection == null) return new Vector3d(0.0, 0.0, 0.0); + crossSection = (BezierBoardCrossSection)crossSection.clone(); + double minS = BezierSpline.ONE; double maxS = BezierSpline.ZERO; @@ -195,7 +198,7 @@ synchronized public Vector3d getNormalAt(final BezierBoard brd, double x, double return normalVec; } - synchronized public double getCrosssectionAreaAt(final BezierBoard brd, final double x, + public double getCrosssectionAreaAt(final BezierBoard brd, final double x, int splits) { final BezierBoardCrossSection crossSection = brd .getInterpolatedCrossSection(x); diff --git a/cadcore/BezierBoardCrossSection.java b/cadcore/BezierBoardCrossSection.java index 5cc6162..e933a47 100644 --- a/cadcore/BezierBoardCrossSection.java +++ b/cadcore/BezierBoardCrossSection.java @@ -180,27 +180,14 @@ public boolean equals(Object other) { } - public synchronized BezierBoardCrossSection interpolate( + public BezierBoardCrossSection interpolate( BezierBoardCrossSection target, double t) { try { // boolean hasChanged = false; BezierBoardCrossSection interpolationClone = new BezierBoardCrossSection(); - BezierBoardCrossSection interpolationTargetClone = new BezierBoardCrossSection(); - // if(!interpolationClone.equals(this)) - // { interpolationClone.set(this); - // hasChanged = true; - // } - - // if(!interpolationTargetClone.equals(target)) - // { - // interpolationTargetClone.set(target); - // - // hasChanged = true; - // - // } BezierBoardCrossSection interpolationSandboxCopy = new BezierBoardCrossSection(); BezierBoardCrossSection interpolationTargetSandboxCopy = new BezierBoardCrossSection(); @@ -333,7 +320,7 @@ public synchronized BezierBoardCrossSection interpolate( next.getPoints()[1]); } else { - return this; + return interpolationClone; } } } @@ -364,7 +351,9 @@ public synchronized BezierBoardCrossSection interpolate( } return interpolated; - } catch (Exception e) { + + } + catch (Exception e) { System.out.println("Error occured in Brd::interpolate() " + e.toString()); return null; diff --git a/cadcore/BezierBoardLinearInterpolationSurfaceModel.java b/cadcore/BezierBoardLinearInterpolationSurfaceModel.java index 2fca3be..46bee13 100644 --- a/cadcore/BezierBoardLinearInterpolationSurfaceModel.java +++ b/cadcore/BezierBoardLinearInterpolationSurfaceModel.java @@ -7,7 +7,7 @@ class BezierBoardLinearInterpolationSurfaceModel extends AbstractBezierBoardSurfaceModel { - synchronized public Point3d getDeckAt(BezierBoard brd, final double x, final double y) + public Point3d getDeckAt(BezierBoard brd, final double x, final double y) { //Calculate scales double widthAtPos = brd.getWidthAtPos(x); @@ -43,7 +43,7 @@ synchronized public Point3d getDeckAt(BezierBoard brd, final double x, final dou } - synchronized public Point3d getBottomAt(final BezierBoard brd, final double x, final double y) + public Point3d getBottomAt(final BezierBoard brd, final double x, final double y) { //Calculate scales double widthAtPos = brd.getWidthAtPos(x); @@ -76,12 +76,12 @@ synchronized public Point3d getBottomAt(final BezierBoard brd, final double x, f return new Point3d(x,y,z); } - synchronized public Point3d getPointAt(BezierBoard brd, final double x, final double s, final double minAngle, final double maxAngle, boolean useMinimumAngleOnSharpCorners) + public Point3d getPointAt(BezierBoard brd, final double x, final double s, final double minAngle, final double maxAngle, boolean useMinimumAngleOnSharpCorners) { return null; } - synchronized public double getCrosssectionAreaAt(final BezierBoard brd, final double x, int splits) + public double getCrosssectionAreaAt(final BezierBoard brd, final double x, int splits) { double a = 0.01; double b = (brd.getWidthAtPos(x)/2) - 0.01; diff --git a/cadcore/BezierBoardSLinearInterpolationSurfaceModel.java b/cadcore/BezierBoardSLinearInterpolationSurfaceModel.java index 04c21bf..ef0609c 100644 --- a/cadcore/BezierBoardSLinearInterpolationSurfaceModel.java +++ b/cadcore/BezierBoardSLinearInterpolationSurfaceModel.java @@ -9,286 +9,325 @@ import cadcore.MathUtils.Function; - -class BezierBoardSLinearInterpolationSurfaceModel extends AbstractBezierBoardSurfaceModel -{ - BezierSpline c1Spline = new BezierSpline(); - BezierSpline c2Spline = new BezierSpline(); - - synchronized public Point3d getDeckAt(final BezierBoard brd,final double x, final double y) - { - final Function func = new Function(){public double f(double s){return getPointAt(brd,x,s,-90.0,90.0, true).y;};}; +class BezierBoardSLinearInterpolationSurfaceModel extends + AbstractBezierBoardSurfaceModel { + public Point3d getDeckAt(final BezierBoard brd, final double x, + final double y) { + final Function func = new Function() { + public double f(double s) { + return getPointAt(brd, x, s, -90.0, 90.0, true).y; + }; + }; double s = MathUtils.RootFinder.getRoot(func, y); - - return getPointAt(brd,x,s,-90.0,90.0, true); + + return getPointAt(brd, x, s, -90.0, 90.0, true); } - - synchronized public Point3d getBottomAt(final BezierBoard brd,final double x, final double y) - { - final Function func = new Function(){public double f(double s){return getPointAt(brd,x,s,90.0,270.0, true).y;};}; + + public Point3d getBottomAt(final BezierBoard brd, final double x, + final double y) { + final Function func = new Function() { + public double f(double s) { + return getPointAt(brd, x, s, 90.0, 270.0, true).y; + }; + }; double s = MathUtils.RootFinder.getRoot(func, y); - - return getPointAt(brd,x,s,90.0,270.0, true); + + return getPointAt(brd, x, s, 90.0, 270.0, true); } - - synchronized public Point3d getPointAt(final BezierBoard brd,double x, double s, double minAngle, double maxAngle, boolean useMinimumAngleOnSharpCorners) - { - if(x < 0.1) + + public Point3d getPointAt(final BezierBoard brd, double x, double s, + double minAngle, double maxAngle, + boolean useMinimumAngleOnSharpCorners) { + if (x < 0.1) x = 0.1; - - if(x > brd.getLength()-0.1) - x = brd.getLength()-0.1; + + if (x > brd.getLength() - 0.1) + x = brd.getLength() - 0.1; BezierBoardCrossSection c1 = brd.getPreviousCrossSection(x); BezierBoardCrossSection c2 = brd.getNextCrossSection(x); - //Scaling + // Scaling double targetWidth = brd.getWidthAt(x); double targetThickness = brd.getThicknessAtPos(x); double c1Width = c1.getWidth(); double c1Thickness = c1.getThicknessAtPos(BezierSpline.ZERO); - + double c2Width = c2.getWidth(); double c2Thickness = c2.getThicknessAtPos(BezierSpline.ZERO); - - double c1ThicknessScale = targetThickness/c1Thickness; - double c1WidthScale = targetWidth/c1Width; - - double c2ThicknessScale = targetThickness/c2Thickness; - double c2WidthScale = targetWidth/c2Width; - + + double c1ThicknessScale = targetThickness / c1Thickness; + double c1WidthScale = targetWidth / c1Width; + + double c2ThicknessScale = targetThickness / c2Thickness; + double c2WidthScale = targetWidth / c2Width; + + BezierSpline c1Spline = new BezierSpline(); + BezierSpline c2Spline = new BezierSpline(); + c1Spline.set(c1.getBezierSpline()); c1Spline.scale(c1ThicknessScale, c1WidthScale); - + c2Spline.set(c2.getBezierSpline()); c2Spline.scale(c2ThicknessScale, c2WidthScale); - -// double c1SplineWidth = c1Spline.getMaxX(); -// double c2SplineWidth = c2Spline.getMaxX(); -// -// double c1SplineThick = c1Spline.getMaxY(); -// double c2SplineThick = c2Spline.getMaxY(); - -// System.out.printf("targetWidth: %f targetThickness: %f c1SplineWidth x2: %f c2SplineWidth x2: %f c1SplineThick: %f c2SplineThick: %f\n", targetWidth, targetThickness, c1SplineWidth*2.0, c2SplineWidth*2.0, c1SplineThick, c2SplineThick); - -// System.out.printf("getSurfacePoint()\n"); -// System.out.printf("Target width: %f thickness: %f\n", targetWidth, targetThickness); -// System.out.printf("C1 width: %f thickness: %f\n", c1Width, c1Thickness); -// System.out.printf("C2 width: %f thickness: %f\n", c2Width, c2Thickness); -// System.out.printf("C1 width scale: %f thickness scale: %f\n", c1WidthScale, c1ThicknessScale); -// System.out.printf("C2 width scale: %f thickness scale: %f\n", c2WidthScale, c2ThicknessScale); + + // double c1SplineWidth = c1Spline.getMaxX(); + // double c2SplineWidth = c2Spline.getMaxX(); + // + // double c1SplineThick = c1Spline.getMaxY(); + // double c2SplineThick = c2Spline.getMaxY(); + + // System.out.printf("targetWidth: %f targetThickness: %f c1SplineWidth x2: %f c2SplineWidth x2: %f c1SplineThick: %f c2SplineThick: %f\n", + // targetWidth, targetThickness, c1SplineWidth*2.0, c2SplineWidth*2.0, + // c1SplineThick, c2SplineThick); + + // System.out.printf("getSurfacePoint()\n"); + // System.out.printf("Target width: %f thickness: %f\n", targetWidth, + // targetThickness); + // System.out.printf("C1 width: %f thickness: %f\n", c1Width, + // c1Thickness); + // System.out.printf("C2 width: %f thickness: %f\n", c2Width, + // c2Thickness); + // System.out.printf("C1 width scale: %f thickness scale: %f\n", + // c1WidthScale, c1ThicknessScale); + // System.out.printf("C2 width scale: %f thickness scale: %f\n", + // c2WidthScale, c2ThicknessScale); double s1min = BezierSpline.ONE; double s2min = BezierSpline.ONE; double s1max = BezierSpline.ZERO; double s2max = BezierSpline.ZERO; - if(minAngle > 0.0) - { - s1min = c1Spline.getSByNormalReverse(minAngle*MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); - s2min = c2Spline.getSByNormalReverse(minAngle*MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); + if (minAngle > 0.0) { + s1min = c1Spline.getSByNormalReverse(minAngle + * MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); + s2min = c2Spline.getSByNormalReverse(minAngle + * MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); } - if(maxAngle < 270.0) - { - s1max = c1Spline.getSByNormalReverse(maxAngle*MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); - s2max = c2Spline.getSByNormalReverse(maxAngle*MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); + if (maxAngle < 270.0) { + s1max = c1Spline.getSByNormalReverse(maxAngle + * MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); + s2max = c2Spline.getSByNormalReverse(maxAngle + * MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); } - double current1S = ((s1max-s1min)*s) + s1min; - double current2S = ((s2max-s2min)*s) + s2min; - + double current1S = ((s1max - s1min) * s) + s1min; + double current2S = ((s2max - s2min) * s) + s2min; - //Get the position first since we cheat with the crosssections at tip and tail + // Get the position first since we cheat with the crosssections at tip + // and tail double pos1 = brd.getPreviousCrossSectionPos(x); double pos2 = brd.getNextCrossSectionPos(x); - - //New + + // New Point2D.Double v1 = c1Spline.getPointByS(current1S); Point2D.Double v2 = c2Spline.getPointByS(current2S); - -// System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getPointAt() v1:%f, %f\n", v1.x, v1.y); -// System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getPointAt() v2:%f, %f\n", v2.x, v2.y); - //Get blended point - double d = (x - pos1)/(pos2 - pos1); + // System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getPointAt() v1:%f, %f\n", + // v1.x, v1.y); + // System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getPointAt() v2:%f, %f\n", + // v2.x, v2.y); + + // Get blended point + double d = (x - pos1) / (pos2 - pos1); Point2D.Double ret = new Point2D.Double(); - ret.x = ((1-d)*v1.x) + (d*v2.x); - ret.y = ((1-d)*v1.y) + (d*v2.y); + ret.x = ((1 - d) * v1.x) + (d * v2.x); + ret.y = ((1 - d) * v1.y) + (d * v2.y); double rockerAtPos = brd.getRockerAtPos(x); - + Point3d point = new Point3d(x, ret.x, ret.y + rockerAtPos); -// System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getPointAt() x:%f, result: %f, %f, %f\n", x, point.x, point.y, point.z); + // System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getPointAt() x:%f, result: %f, %f, %f\n", + // x, point.x, point.y, point.z); return point; } - synchronized public Vector3d getNormalAt(final BezierBoard brd, double x, double s, double minAngle, double maxAngle, boolean useMinimumAngleOnSharpCorners) - { - if(x < 0.1) + public Vector3d getNormalAt(final BezierBoard brd, double x, double s, + double minAngle, double maxAngle, + boolean useMinimumAngleOnSharpCorners) { + if (x < 0.1) x = 0.1; - - if(x > brd.getLength()-0.1) - x = brd.getLength()-0.1; + + if (x > brd.getLength() - 0.1) + x = brd.getLength() - 0.1; final double X_OFFSET = 0.1; final double S_OFFSET = 0.01; boolean flipNormal = false; - //Get first blended point - Point3d pointS = getPointAt(brd, x, s, minAngle, maxAngle, useMinimumAngleOnSharpCorners); + // Get first blended point + Point3d pointS = getPointAt(brd, x, s, minAngle, maxAngle, + useMinimumAngleOnSharpCorners); -// System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getNormalAt() first point x:%f, result: %f, %f, %f\n", x, pointS.x, pointS.y, pointS.z); + // System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getNormalAt() first point x:%f, result: %f, %f, %f\n", + // x, pointS.x, pointS.y, pointS.z); - - //Get second blended point + // Get second blended point BezierBoardCrossSection c1 = brd.getPreviousCrossSection(x); BezierBoardCrossSection c2 = brd.getNextCrossSection(x); - //Scaling + // Scaling double targetWidth = brd.getWidthAt(x); double targetThickness = brd.getThicknessAtPos(x); double c1Width = c1.getWidth(); double c1Thickness = c1.getThicknessAtPos(BezierSpline.ZERO); - + double c2Width = c2.getWidth(); double c2Thickness = c2.getThicknessAtPos(BezierSpline.ZERO); - - double c1ThicknessScale = targetThickness/c1Thickness; - double c1WidthScale = targetWidth/c1Width; - - double c2ThicknessScale = targetThickness/c2Thickness; - double c2WidthScale = targetWidth/c2Width; - + + double c1ThicknessScale = targetThickness / c1Thickness; + double c1WidthScale = targetWidth / c1Width; + + double c2ThicknessScale = targetThickness / c2Thickness; + double c2WidthScale = targetWidth / c2Width; + + BezierSpline c1Spline = new BezierSpline(); + BezierSpline c2Spline = new BezierSpline(); + c1Spline.set(c1.getBezierSpline()); c1Spline.scale(c1ThicknessScale, c1WidthScale); - + c2Spline.set(c2.getBezierSpline()); c2Spline.scale(c2ThicknessScale, c2WidthScale); -// System.out.printf("getNormalAt()\n"); -// System.out.printf("Target width: %f thickness: %f\n", targetWidth, targetThickness); -// System.out.printf("C1 width: %f thickness: %f\n", c1Width, c1Thickness); -// System.out.printf("C2 width: %f thickness: %f\n", c2Width, c2Thickness); -// System.out.printf("C1 width scale: %f thickness scale: %f\n", c1WidthScale, c1ThicknessScale); -// System.out.printf("C2 width scale: %f thickness scale: %f\n", c2WidthScale, c2ThicknessScale); + // System.out.printf("getNormalAt()\n"); + // System.out.printf("Target width: %f thickness: %f\n", targetWidth, + // targetThickness); + // System.out.printf("C1 width: %f thickness: %f\n", c1Width, + // c1Thickness); + // System.out.printf("C2 width: %f thickness: %f\n", c2Width, + // c2Thickness); + // System.out.printf("C1 width scale: %f thickness scale: %f\n", + // c1WidthScale, c1ThicknessScale); + // System.out.printf("C2 width scale: %f thickness scale: %f\n", + // c2WidthScale, c2ThicknessScale); double s1min = BezierSpline.ONE; double s2min = BezierSpline.ONE; double s1max = BezierSpline.ZERO; double s2max = BezierSpline.ZERO; - if(minAngle > 0.0) - { - s1min = c1Spline.getSByNormalReverse(minAngle*MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); - s2min = c2Spline.getSByNormalReverse(minAngle*MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); + if (minAngle > 0.0) { + s1min = c1Spline.getSByNormalReverse(minAngle + * MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); + s2min = c2Spline.getSByNormalReverse(minAngle + * MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); } - if(maxAngle < 270.0) - { - s1max = c1Spline.getSByNormalReverse(maxAngle*MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); - s2max = c2Spline.getSByNormalReverse(maxAngle*MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); + if (maxAngle < 270.0) { + s1max = c1Spline.getSByNormalReverse(maxAngle + * MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); + s2max = c2Spline.getSByNormalReverse(maxAngle + * MathUtils.DEG_TO_RAD, useMinimumAngleOnSharpCorners); } - double current1S = ((s1max-s1min)*s) + s1min; - double current2S = ((s2max-s2min)*s) + s2min; - + double current1S = ((s1max - s1min) * s) + s1min; + double current2S = ((s2max - s2min) * s) + s2min; - double current1SO = current1S+S_OFFSET; - double current2SO = current2S+S_OFFSET; - if(current1SO > 1.0 || current2SO > 1.0|| useMinimumAngleOnSharpCorners==false) - { - current1SO = current1S-S_OFFSET; - current2SO = current2S-S_OFFSET; + double current1SO = current1S + S_OFFSET; + double current2SO = current2S + S_OFFSET; + if (current1SO > 1.0 || current2SO > 1.0 + || useMinimumAngleOnSharpCorners == false) { + current1SO = current1S - S_OFFSET; + current2SO = current2S - S_OFFSET; flipNormal = true; } - - //Get the position first since we cheat with the crosssections at tip and tail + + // Get the position first since we cheat with the crosssections at tip + // and tail double pos1 = brd.getPreviousCrossSectionPos(x); double pos2 = brd.getNextCrossSectionPos(x); Point2D.Double v1so = c1Spline.getPointByS(current1SO); Point2D.Double v2so = c2Spline.getPointByS(current2SO); -// System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getPointAt() v1:%f, %f\n", v1.x, v1.y); -// System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getPointAt() v2:%f, %f\n", v2.x, v2.y); + // System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getPointAt() v1:%f, %f\n", + // v1.x, v1.y); + // System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getPointAt() v2:%f, %f\n", + // v2.x, v2.y); - double pSO = (x - pos1)/(pos2 - pos1); + double pSO = (x - pos1) / (pos2 - pos1); Point2D.Double retSO = new Point2D.Double(); - retSO.x = ((1-pSO)*v1so.x) + (pSO*v2so.x); - retSO.y = ((1-pSO)*v1so.y) + (pSO*v2so.y); + retSO.x = ((1 - pSO) * v1so.x) + (pSO * v2so.x); + retSO.y = ((1 - pSO) * v1so.y) + (pSO * v2so.y); double rockerAtX = brd.getRockerAtPos(x); Point3d pointSO = new Point3d(x, retSO.x, retSO.y + rockerAtX); -// System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getNormalAt() second point x:%f, result: %f, %f, %f\n", x, pointSO.x, pointSO.y, pointSO.z); - - - //Get third blended point - double xo = x+X_OFFSET; - - Point3d pointXO = getPointAt(brd, xo, s, minAngle, maxAngle, useMinimumAngleOnSharpCorners); - -// System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getNormalAt() third point x:%f, result: %f, %f, %f\n", x, pointXO.x, pointXO.y, pointXO.z); - - - //Calculate normal - Vector3d vc = new Vector3d(0, pointS.y-pointSO.y, pointS.z-pointSO.z); //Vector across -// vc.normalize(); - - Vector3d vl = new Vector3d(xo-x, pointXO.y-pointS.y, pointXO.z-pointS.z); //Vector lengthwise -// vl.normalize(); - + // System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getNormalAt() second point x:%f, result: %f, %f, %f\n", + // x, pointSO.x, pointSO.y, pointSO.z); + + // Get third blended point + double xo = x + X_OFFSET; + + Point3d pointXO = getPointAt(brd, xo, s, minAngle, maxAngle, + useMinimumAngleOnSharpCorners); + + // System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getNormalAt() third point x:%f, result: %f, %f, %f\n", + // x, pointXO.x, pointXO.y, pointXO.z); + + // Calculate normal + Vector3d vc = new Vector3d(0, pointS.y - pointSO.y, pointS.z + - pointSO.z); // Vector across + // vc.normalize(); + + Vector3d vl = new Vector3d(xo - x, pointXO.y - pointS.y, pointXO.z + - pointS.z); // Vector lengthwise + // vl.normalize(); + Vector3d normalVec = new Vector3d(); - normalVec.cross(vl,vc); + normalVec.cross(vl, vc); normalVec.normalize(); - - if(flipNormal == true) - { + + if (flipNormal == true) { normalVec.scale(-1.0); } -// System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getNormalAt() third point x:%f, result: %f, %f, %f\n", x, pointXO.x, pointXO.y, pointXO.z); + // System.out.printf("BezierBoardSLinearInterpolationSurfaceModel.getNormalAt() third point x:%f, result: %f, %f, %f\n", + // x, pointXO.x, pointXO.y, pointXO.z); return normalVec; - + } - synchronized public double getCrosssectionAreaAt(final BezierBoard brd,final double x, int splits) - { - MathUtils.FunctionXY deckFunc = new MathUtils.FunctionXY(){ - public Point2D.Double f(double s){ - Point3d point = getPointAt(brd,x,s,-90.0,90.0,true); - return new Point2D.Double(point.y,point.z); - } - }; - double deckIntegral = MathUtils.Integral.getIntegral(deckFunc, 0.0, 1.0, BezierBoard.AREA_SPLITS); - - MathUtils.FunctionXY bottomFunc = new MathUtils.FunctionXY(){ - public Point2D.Double f(double s){ - Point3d point = getPointAt(brd,x,s,90.0,360.0,true); - return new Point2D.Double(point.y,point.z); - } - }; - double bottomIntegral = MathUtils.Integral.getIntegral(bottomFunc, 0.0, 1.0, BezierBoard.AREA_SPLITS); - - double area = deckIntegral-bottomIntegral; + public double getCrosssectionAreaAt(final BezierBoard brd, final double x, + int splits) { + MathUtils.FunctionXY deckFunc = new MathUtils.FunctionXY() { + public Point2D.Double f(double s) { + Point3d point = getPointAt(brd, x, s, -90.0, 90.0, true); + return new Point2D.Double(point.y, point.z); + } + }; + double deckIntegral = MathUtils.Integral.getIntegral(deckFunc, 0.0, + 1.0, BezierBoard.AREA_SPLITS); + + MathUtils.FunctionXY bottomFunc = new MathUtils.FunctionXY() { + public Point2D.Double f(double s) { + Point3d point = getPointAt(brd, x, s, 90.0, 360.0, true); + return new Point2D.Double(point.y, point.z); + } + }; + double bottomIntegral = MathUtils.Integral.getIntegral(bottomFunc, 0.0, + 1.0, BezierBoard.AREA_SPLITS); + + double area = deckIntegral - bottomIntegral; area *= 2.0; - - if(area < 0) + + if (area < 0) area = 0.0; -// System.out.printf("getCrosssectionAreaAt() x:%f area:%f\n", x, area); - + // System.out.printf("getCrosssectionAreaAt() x:%f area:%f\n", x, area); + return area; } - + } diff --git a/cadcore/BezierCurve.java b/cadcore/BezierCurve.java index 16a03c6..08dc40f 100644 --- a/cadcore/BezierCurve.java +++ b/cadcore/BezierCurve.java @@ -5,11 +5,10 @@ import cadcore.BezierKnot; -public class BezierCurve implements Cloneable, BezierKnotChangeListener -{ +public class BezierCurve implements Cloneable, BezierKnotChangeListener { BezierKnot mStartKnot; BezierKnot mEndKnot; - + protected double coeff0 = 0.0; protected double coeff1 = 0.0; protected double coeff2 = 0.0; @@ -18,757 +17,717 @@ public class BezierCurve implements Cloneable, BezierKnotChangeListener protected double coeff5 = 0.0; protected double coeff6 = 0.0; protected double coeff7 = 0.0; - + boolean mCoeffDirty = true; boolean mLengthDirty = true; - + double mLength = 0.0; - public BezierCurve(BezierKnot startKnot, BezierKnot endKnot) - { + public BezierCurve(double P0X, double P0Y, double P1X, double P1Y, + double P2X, double P2Y, double P3X, double P3Y) { + mStartKnot = new BezierKnot(P0X, P0Y, 0.0, 0.0, P1X, P1Y); + mEndKnot = new BezierKnot(P3X, P3Y, P2X, P2Y, 0.0, 0.0); + } + + public BezierCurve(BezierKnot startKnot, BezierKnot endKnot) { mStartKnot = startKnot; mEndKnot = endKnot; - - if(mStartKnot != null) + + if (mStartKnot != null) mStartKnot.addChangeListener(this); - if(mEndKnot != null) + if (mEndKnot != null) mEndKnot.addChangeListener(this); } - - BezierKnot getStartKnot() - { + + public BezierKnot getStartKnot() { return mStartKnot; } - BezierKnot getEndKnot() - { + public BezierKnot getEndKnot() { return mEndKnot; } - - void setStartKnot(BezierKnot startKnot) - { + + void setStartKnot(BezierKnot startKnot) { mStartKnot = startKnot; - if(mStartKnot != null) + if (mStartKnot != null) mStartKnot.addChangeListener(this); setDirty(); } - void setEndKnot(BezierKnot endKnot) - { + void setEndKnot(BezierKnot endKnot) { mEndKnot = endKnot; - if(mEndKnot != null) + if (mEndKnot != null) mEndKnot.addChangeListener(this); setDirty(); } - - private void calculateCoeff() - { - if(!mCoeffDirty) + + private void calculateCoeff() { + if (!mCoeffDirty) return; - - // MORE ON CUBIC SPLINE MATH - // ========================= - // by Don Lancaster - - // In graph space, the cubic spline is defined by eight points. A pair of - // initial points x0 and y0. A pair of end points x3 and y3. A pair of - // first influence points x1 and y1. And a pair of second influence points - // x2 and y2. - - // A cubic spline consists of two parametric equations in t (or time) space... - - // x = At^3 + Bt^2 + Ct + D - // y = Dt^3 + Et^2 + Ft + G - - // Cubing can be a real pain, so the above equations can be rewritten in a - // "cubeless" form that calculates quickly... - - // x = ((At + B)t + C)t + D - // y = ((Dt + E)t + F)t + G -/* - double A = p3.x - (3*t2.x) + (3*t1.x) - p0.x; //A = x3 - 3x2 + 3x1 - x0 - double B = (3*t2.x) - (6*t1.x) + (3*p0.x); //B = 3x2 - 6x1 + 3x0 - double C = (3*t1.x) - (3*p0.x); //C = 3x1 - 3x0 - double D = p0.x; //D = x0 - - double E = p3.y - (3*t2.y) + (3*t1.y) - p0.y; //E = y3 - 3y2 + 3y1 - y0 - double F = (3*t2.y) - (6*t1.y) + (3*p0.y); //F = 3y2 - 6y1 + 3y0 - double G = (3*t1.y) - (3*p0.y); //G = 3y1 - 3y0 - double H = p0.y; //H = y0 - - coeff0 = A; - coeff1 = B; - coeff2 = C; - coeff3 = D; - coeff4 = E; - coeff5 = F; - coeff6 = G; - coeff7 = H; -*/ + + // MORE ON CUBIC SPLINE MATH + // ========================= + // by Don Lancaster + + // In graph space, the cubic spline is defined by eight points. A pair + // of + // initial points x0 and y0. A pair of end points x3 and y3. A pair of + // first influence points x1 and y1. And a pair of second influence + // points + // x2 and y2. + + // A cubic spline consists of two parametric equations in t (or time) + // space... + + // x = At^3 + Bt^2 + Ct + D + // y = Dt^3 + Et^2 + Ft + G + + // Cubing can be a real pain, so the above equations can be rewritten in + // a + // "cubeless" form that calculates quickly... + + // x = ((At + B)t + C)t + D + // y = ((Dt + E)t + F)t + G + /* + * double A = p3.x - (3*t2.x) + (3*t1.x) - p0.x; //A = x3 - 3x2 + 3x1 - + * x0 double B = (3*t2.x) - (6*t1.x) + (3*p0.x); //B = 3x2 - 6x1 + 3x0 + * double C = (3*t1.x) - (3*p0.x); //C = 3x1 - 3x0 double D = p0.x; //D + * = x0 + * + * double E = p3.y - (3*t2.y) + (3*t1.y) - p0.y; //E = y3 - 3y2 + 3y1 - + * y0 double F = (3*t2.y) - (6*t1.y) + (3*p0.y); //F = 3y2 - 6y1 + 3y0 + * double G = (3*t1.y) - (3*p0.y); //G = 3y1 - 3y0 double H = p0.y; //H + * = y0 + * + * coeff0 = A; coeff1 = B; coeff2 = C; coeff3 = D; coeff4 = E; coeff5 = + * F; coeff6 = G; coeff7 = H; + */ final Point2D.Double p0 = mStartKnot.getEndPoint(); - final Point2D.Double t1 = mStartKnot.getTangentToNext(); - final Point2D.Double t2 = mEndKnot.getTangentToPrev(); + final Point2D.Double t1 = mStartKnot.getTangentToNext(); + final Point2D.Double t2 = mEndKnot.getTangentToPrev(); final Point2D.Double p3 = mEndKnot.getEndPoint(); - - coeff0 = p3.x + (3*(-t2.x + t1.x)) - p0.x; //A = x3 - 3x2 + 3x1 - x0 - coeff1 = 3*(t2.x - (2*t1.x) + p0.x); //B = 3x2 - 6x1 + 3x0 - coeff2 = 3*(t1.x - p0.x); //C = 3x1 - 3x0 - coeff3 = p0.x; //D = x0 - - coeff4 = p3.y + (3*(-t2.y + t1.y)) - p0.y; //E = y3 - 3y2 + 3y1 - y0 - coeff5 = 3*(t2.y - (2*t1.y) + p0.y); //F = 3y2 - 6y1 + 3y0 - coeff6 = 3*(t1.y - p0.y); //G = 3y1 - 3y0 - coeff7 = p0.y; //H = y0 - - mCoeffDirty = false; -/* - if(coeff0 != A) - return; - if(coeff1 != B) - return; - if(coeff2 != C) - return; - if(coeff3 != D) - return; - if(coeff4 != E) - return; - if(coeff5 != F) - return; - if(coeff6 != G) - return; - if(coeff7 != H) - return; - */ -//Debug copyCoeff(); - } -/*Debug - void copyCoeff() - { - for(int i = 0; i < 8; i++) - { - coeffCopy[i] = coeff[i]; - } - } - void compareCoeff() - { - for(int i = 0; i < 8; i++) - { - double val2 = coeffCopy[i]; - double val1 = coeff[i]; + coeff0 = p3.x + (3 * (-t2.x + t1.x)) - p0.x; // A = x3 - 3x2 + 3x1 - x0 + coeff1 = 3 * (t2.x - (2 * t1.x) + p0.x); // B = 3x2 - 6x1 + 3x0 + coeff2 = 3 * (t1.x - p0.x); // C = 3x1 - 3x0 + coeff3 = p0.x; // D = x0 - double diff = Math.abs(val1 - val2); - if(diff > 0.1) - { - System.out.println("Coeff changed i:" + i + " diff:" + diff + " values:" + val1 + " " + val2); - } - } - } -*/ - public double getTForX(final double x) - { - double t = (x-getEndKnot().getEndPoint().x)/(getStartKnot().getEndPoint().x-getEndKnot().getEndPoint().x); - - return getTForX(x,t); - } - - public double getTForX(final double x, final double start_t) - { + coeff4 = p3.y + (3 * (-t2.y + t1.y)) - p0.y; // E = y3 - 3y2 + 3y1 - y0 + coeff5 = 3 * (t2.y - (2 * t1.y) + p0.y); // F = 3y2 - 6y1 + 3y0 + coeff6 = 3 * (t1.y - p0.y); // G = 3y1 - 3y0 + coeff7 = p0.y; // H = y0 + + mCoeffDirty = false; + /* + * if(coeff0 != A) return; if(coeff1 != B) return; if(coeff2 != C) + * return; if(coeff3 != D) return; if(coeff4 != E) return; if(coeff5 != + * F) return; if(coeff6 != G) return; if(coeff7 != H) return; + */ + // Debug copyCoeff(); + } + + /* + * Debug void copyCoeff() { for(int i = 0; i < 8; i++) { coeffCopy[i] = + * coeff[i]; } } + * + * void compareCoeff() { for(int i = 0; i < 8; i++) { double val2 = + * coeffCopy[i]; double val1 = coeff[i]; + * + * double diff = Math.abs(val1 - val2); if(diff > 0.1) { + * System.out.println("Coeff changed i:" + i + " diff:" + diff + " values:" + * + val1 + " " + val2); } } } + */ + public double getTForX(final double x) { + double t = (x - getEndKnot().getEndPoint().x) + / (getStartKnot().getEndPoint().x - getEndKnot().getEndPoint().x); + + return getTForX(x, t); + } + + public double getTForX(final double x, final double start_t) { calculateCoeff(); - + return getTForXInternal(x, start_t); } - - private double getTForXInternal(final double x, final double start_t) - { - // I don't know how to find an exact and closed solution to finding y given - // x. You first have to use x to solve for t and then you solve t for y. - - // One useful way to do this is to take a guess for a t value. See what x - // you get. Note the error. Reduce the error and try again. Keep this up - // till you have a root to acceptable accuracy. + + private double getTForXInternal(final double x, final double start_t) { + // I don't know how to find an exact and closed solution to finding y + // given + // x. You first have to use x to solve for t and then you solve t for y. + + // One useful way to do this is to take a guess for a t value. See what + // x + // you get. Note the error. Reduce the error and try again. Keep this up + // till you have a root to acceptable accuracy. // - // A good first guess is to normalize x so it ranges from 0 to 1 and then - // simply guess that x = t. This will be fairly close for curves that aren't - // bent very much. And a useful guess for ALL spline curves. + // A good first guess is to normalize x so it ranges from 0 to 1 and + // then + // simply guess that x = t. This will be fairly close for curves that + // aren't + // bent very much. And a useful guess for ALL spline curves. - //Guess initial t + // Guess initial t double tn = start_t; // Now, on any triangle... // - // rise = run x (rise/run) + // rise = run x (rise/run) // - // This gives us a very good improvement for our next approximation. It - // turns out that the "adjust for slope" method converges very rapidly. - // Three passes are usually good enough. + // This gives us a very good improvement for our next approximation. It + // turns out that the "adjust for slope" method converges very rapidly. + // Three passes are usually good enough. // - // If our curve has an equation of... + // If our curve has an equation of... // - // x = At^3 + Bt^2 + Ct + D + // x = At^3 + Bt^2 + Ct + D // - // ...its slope will be... + // ...its slope will be... // - // x' = 3At^2 +2Bt + C + // x' = 3At^2 +2Bt + C // - // And the dt/dx slope will be its inverse or 1/(3At^2 + 2Bt +C) + // And the dt/dx slope will be its inverse or 1/(3At^2 + 2Bt +C) // - // This is easily calculated. We'll have code and an example in just a bit. + // This is easily calculated. We'll have code and an example in just a + // bit. // - // The next guess will be... + // The next guess will be... // - // nextguess = currentt + (curentx - x)(currentslope) + // nextguess = currentt + (curentx - x)(currentslope) double xn = getXValue(tn); - double error = x-xn; -// double lasterror = error; + double error = x - xn; + // double lasterror = error; int n = 0; - while(Math.abs(error) > BezierSpline.POS_TOLERANCE && n++ < BezierSpline.POS_MAX_ITERATIONS) - { - double currentSlope = 1/getXDerivate(tn); + while (Math.abs(error) > BezierSpline.POS_TOLERANCE + && n++ < BezierSpline.POS_MAX_ITERATIONS) { + double currentSlope = 1 / getXDerivate(tn); - tn = tn + (error*currentSlope); + tn = tn + (error * currentSlope); xn = getXValue(tn); - error = x-xn; + error = x - xn; /* -if(Math.abs(error) > Math.abs(lasterror)) - System.out.println("getTForX(): increasing error: " + error + " last error:" + lasterror + " slope:" + currentSlope + " tn:" + tn); - -lasterror = error; - */ } - - //Sanity check - if(tn < 0 || tn > 1 || Double.isNaN(tn) || n >= BezierSpline.POS_MAX_ITERATIONS || Math.abs(error) > BezierSpline.POS_TOLERANCE) - { -//System.out.printf("getTForX(): converge failed, error: %f t:%f\n", Math.abs(xn-x), tn); - tn = getTForX(x,0,1,BezierSpline.MIN_MAX_SPLITS); + * if(Math.abs(error) > Math.abs(lasterror)) + * System.out.println("getTForX(): increasing error: " + error + + * " last error:" + lasterror + " slope:" + currentSlope + " tn:" + + * tn); + * + * lasterror = error; + */} + + // Sanity check + if (tn < 0 || tn > 1 || Double.isNaN(tn) + || n >= BezierSpline.POS_MAX_ITERATIONS + || Math.abs(error) > BezierSpline.POS_TOLERANCE) { + // System.out.printf("getTForX(): converge failed, error: %f t:%f\n", + // Math.abs(xn-x), tn); + tn = getTForX(x, 0, 1, BezierSpline.MIN_MAX_SPLITS); xn = getXValue(tn); -/*Debug - if(Math.abs(xn-x) < POS_TOLERANCE) - { - st++; - } - else - { - tf++; -System.out.printf("getTForX() failed, error:%f t:%f ct:%f: st:%f tf:%f\n", Math.abs(xn-x), tn , ct , st , tf); - } -*/ - } -/*Debug else - { - ct++; + /* + * Debug if(Math.abs(xn-x) < POS_TOLERANCE) { st++; } else { tf++; + * System + * .out.printf("getTForX() failed, error:%f t:%f ct:%f: st:%f tf:%f\n" + * , Math.abs(xn-x), tn , ct , st , tf); } + */ } -*/ - return tn; + /* + * Debug else { ct++; } + */ + return tn; } - - private double getTForX(final double x, double t0, double t1, int nrOfSplits) - { + + private double getTForX(final double x, double t0, double t1, int nrOfSplits) { double best_t = 0; double best_error = 1000000000; double best_value = 0; double current_t; double current_value; - double seg = (t1-t0)/nrOfSplits; + double seg = (t1 - t0) / nrOfSplits; double error = 0; - for(int i = 1; i < nrOfSplits; i++) - { - current_t = seg*i + t0; - if(current_t < 0 || current_t > 1) + for (int i = 1; i < nrOfSplits; i++) { + current_t = seg * i + t0; + if (current_t < 0 || current_t > 1) continue; current_value = getXValue(current_t); - error = Math.abs(x-current_value); + error = Math.abs(x - current_value); - if(error < best_error) - { + if (error < best_error) { best_error = error; best_t = current_t; best_value = current_value; } } - if(best_error < BezierSpline.POS_TOLERANCE) + if (best_error < BezierSpline.POS_TOLERANCE) return best_t; - else if(Math.abs(best_t - (t1-t0)/2) < BezierSpline.MIN_MAX_TOLERANCE) + else if (Math.abs(best_t - (t1 - t0) / 2) < BezierSpline.MIN_MAX_TOLERANCE) return best_t; - else if(nrOfSplits <= 2) + else if (nrOfSplits <= 2) return best_t; else - return getTForX(x, best_t-seg,best_t+seg, nrOfSplits/2); - } - + return getTForX(x, best_t - seg, best_t + seg, nrOfSplits / 2); + } - private double getTForTangent(final double angle, double t0, double t1, int nrOfSplits) - { + private double getTForTangent(final double angle, double t0, double t1, + int nrOfSplits) { double best_t = 0; double best_error = 1000000000; - double current_t=0; - double current_value=0; - double seg = (t1-t0)/nrOfSplits; + double current_t = 0; + double current_value = 0; + double seg = (t1 - t0) / nrOfSplits; double error = 0; - for(int i = 1; i <= nrOfSplits; i++) - { - current_t = seg*i + t0; - if(current_t < 0 || current_t > 1) + for (int i = 1; i <= nrOfSplits; i++) { + current_t = seg * i + t0; + if (current_t < 0 || current_t > 1) continue; current_value = getTangent(current_t); - error = Math.abs(angle-current_value); + error = Math.abs(angle - current_value); - if(error < best_error) - { + if (error < best_error) { best_error = error; best_t = current_t; } } error = current_t; - if(best_error < BezierSpline.ANGLE_TOLERANCE) - { + if (best_error < BezierSpline.ANGLE_TOLERANCE) { return best_t; - } - else if(Math.abs(best_t - (t1-t0)/2) < BezierSpline.ANGLE_T_TOLERANCE) - { + } else if (Math.abs(best_t - (t1 - t0) / 2) < BezierSpline.ANGLE_T_TOLERANCE) { return best_t; - } - else if(nrOfSplits <= 2) - { + } else if (nrOfSplits <= 2) { return best_t; - } - else - return getTForTangent(angle, best_t-seg,best_t+seg, nrOfSplits/2); - } + } else + return getTForTangent(angle, best_t - seg, best_t + seg, + nrOfSplits / 2); + } - double getTForTangent2(double target_angle, double current_t, double last_t) - { - //Search for the angle using secant method + double getTForTangent2(double target_angle, double current_t, double last_t) { + // Search for the angle using secant method double current_angle = getTangent(current_t); double last_angle = getTangent(last_t); - double current_error = target_angle-current_angle; + double current_error = target_angle - current_angle; + + // System.out.printf("getTForTangent2(): target_angle:%f, current_t:%f, last_t:%f\n", + // target_angle/BezierBoard.DEG_TO_RAD, current_t, last_t); -// System.out.printf("getTForTangent2(): target_angle:%f, current_t:%f, last_t:%f\n", target_angle/BezierBoard.DEG_TO_RAD, current_t, last_t); - int n = 0; - while(Math.abs(current_error) > BezierSpline.ANGLE_TOLERANCE && n++ < BezierSpline.ANGLE_MAX_ITERATIONS && current_t > BezierSpline.ZERO && current_t < BezierSpline.ONE) - { - double current_slope = (current_angle-last_angle)/(current_t-last_t); + while (Math.abs(current_error) > BezierSpline.ANGLE_TOLERANCE + && n++ < BezierSpline.ANGLE_MAX_ITERATIONS + && current_t > BezierSpline.ZERO + && current_t < BezierSpline.ONE) { + double current_slope = (current_angle - last_angle) + / (current_t - last_t); last_t = current_t; - current_t = current_t + (current_error*current_slope); + current_t = current_t + (current_error * current_slope); last_angle = current_angle; current_angle = getTangent(current_t); - current_error = target_angle-current_angle; + current_error = target_angle - current_angle; -// System.out.printf("getTForTangent2(): current_slope:%f, current_error:%f, current_t:%f last_angle:%f current_angle:%f target_angle:%f\n", current_slope, current_error/BezierBoard.DEG_TO_RAD, current_t, last_angle/BezierBoard.DEG_TO_RAD, current_angle/BezierBoard.DEG_TO_RAD, target_angle/BezierBoard.DEG_TO_RAD); + // System.out.printf("getTForTangent2(): current_slope:%f, current_error:%f, current_t:%f last_angle:%f current_angle:%f target_angle:%f\n", + // current_slope, current_error/BezierBoard.DEG_TO_RAD, current_t, + // last_angle/BezierBoard.DEG_TO_RAD, + // current_angle/BezierBoard.DEG_TO_RAD, + // target_angle/BezierBoard.DEG_TO_RAD); } - //Sanity check - if(Math.abs(getTangent(current_t)-target_angle) > BezierSpline.ANGLE_TOLERANCE || (current_t < BezierSpline.ZERO || current_t > BezierSpline.ONE) ) - { -// System.out.printf("getTForTangent(): converge failed, error: %f\n", current_error/BezierBoard.DEG_TO_RAD); + // Sanity check + if (Math.abs(getTangent(current_t) - target_angle) > BezierSpline.ANGLE_TOLERANCE + || (current_t < BezierSpline.ZERO || current_t > BezierSpline.ONE)) { + // System.out.printf("getTForTangent(): converge failed, error: %f\n", + // current_error/BezierBoard.DEG_TO_RAD); n = 0; double lt = 0.0; double ht = 1.0; - while(Math.abs(current_error) > BezierSpline.ANGLE_TOLERANCE && n++ < BezierSpline.ANGLE_MAX_ITERATIONS && ht-lt > 0.00001) - { - current_t = lt + ((ht-lt)/2.0); + while (Math.abs(current_error) > BezierSpline.ANGLE_TOLERANCE + && n++ < BezierSpline.ANGLE_MAX_ITERATIONS + && ht - lt > 0.00001) { + current_t = lt + ((ht - lt) / 2.0); current_angle = getTangent(current_t); - current_error = target_angle-current_angle; - - if(current_error < 0.0) + current_error = target_angle - current_angle; + + if (current_error < 0.0) lt = current_t; else - ht = current_t; - -// System.out.printf("getTForTangent2(): current_error:%f, current_t:%f lt:%f ht:%f current_angle:%f target_angle:%f \n", current_error, current_t, lt, ht, current_angle, target_angle); + ht = current_t; + + // System.out.printf("getTForTangent2(): current_error:%f, current_t:%f lt:%f ht:%f current_angle:%f target_angle:%f \n", + // current_error, current_t, lt, ht, current_angle, + // target_angle); } - - + } - return current_t; - } - - synchronized double getTForLength(double lengthLeft) - { + return current_t; + } + + double getTForLength(double lengthLeft) { return getTForLength(BezierSpline.ZERO, BezierSpline.ONE, lengthLeft); } - - synchronized double getTForLength(double t0, double t1, double lengthLeft) - { + + double getTForLength(double t0, double t1, double lengthLeft) { calculateCoeff(); - - //Get t split point - double ts = (t1-t0)/2 + t0; + + // Get t split point + double ts = (t1 - t0) / 2 + t0; double sl = getLength(t0, ts); - - try - { - if(Math.abs(t0-t1) < 0.00001) - { + + try { + if (Math.abs(t0 - t1) < 0.00001) { return t0; } - if(Math.abs(sl - lengthLeft) > BezierSpline.LENGTH_TOLERANCE) - { - if(sl > lengthLeft) - { + if (Math.abs(sl - lengthLeft) > BezierSpline.LENGTH_TOLERANCE) { + if (sl > lengthLeft) { return getTForLength(t0, ts, lengthLeft); + } else { + return getTForLength(ts, t1, lengthLeft - sl); } - else - { - return getTForLength(ts, t1, lengthLeft-sl); - } - } - else - { - return ts; + } else { + return ts; } - } - catch(Exception e) - { - System.out.println("Exception in BezierSpline::getTForLength(): " + e.toString()); + } catch (Exception e) { + System.out.println("Exception in BezierSpline::getTForLength(): " + + e.toString()); return 0.0; } } - public double getXValue(final double t) - { + public double getXValue(final double t) { calculateCoeff(); -// compareCoeff(); - // A cubic spline consists of two parametric equations in t (or time) space... + // compareCoeff(); + // A cubic spline consists of two parametric equations in t (or time) + // space... - // x = At^3 + Bt^2 + Ct + D - // y = Dt^3 + Et^2 + Ft + G + // x = At^3 + Bt^2 + Ct + D + // y = Dt^3 + Et^2 + Ft + G - // Cubing can be a real pain, so the above equations can be rewritten in a - // "cubeless" form that calculates quickly... + // Cubing can be a real pain, so the above equations can be rewritten in + // a + // "cubeless" form that calculates quickly... - // x = ((At + B)t + C)t + D - double value = (((((coeff0*t) + coeff1)*t) + coeff2)*t) + coeff3; + // x = ((At + B)t + C)t + D + double value = (((((coeff0 * t) + coeff1) * t) + coeff2) * t) + coeff3; -// compareCoeff(); + // compareCoeff(); return value; } - public double getYValue(final double t) - { + public double getYValue(final double t) { calculateCoeff(); - // compareCoeff(); - // A cubic spline consists of two parametric equations in t (or time) space... + // compareCoeff(); + // A cubic spline consists of two parametric equations in t (or time) + // space... - // x = At^3 + Bt^2 + Ct + D - // y = Dt^3 + Et^2 + Ft + G + // x = At^3 + Bt^2 + Ct + D + // y = Dt^3 + Et^2 + Ft + G - // Cubing can be a real pain, so the above equations can be rewritten in a - // "cubeless" form that calculates quickly... + // Cubing can be a real pain, so the above equations can be rewritten in + // a + // "cubeless" form that calculates quickly... - // y = ((Dt + E)t + F)t + G - double value = (((((coeff4*t) + coeff5)*t) + coeff6)*t) + coeff7; + // y = ((Dt + E)t + F)t + G + double value = (((((coeff4 * t) + coeff5) * t) + coeff6) * t) + coeff7; -// compareCoeff(); + // compareCoeff(); return value; } - - public Point2D.Double getValue(final double t) - { + + public Point2D.Double getValue(final double t) { calculateCoeff(); - - return new Point2D.Double(getXValue(t),getYValue(t)); + + return new Point2D.Double(getXValue(t), getYValue(t)); } - private double getXDerivate(final double t) - { -// compareCoeff(); - //If our curve has an equation of... + private double getXDerivate(final double t) { + // compareCoeff(); + // If our curve has an equation of... // - // x = At^3 + Bt^2 + Ct + D + // x = At^3 + Bt^2 + Ct + D // - // ...its slope will be... + // ...its slope will be... // - // x' = 3At^2 + 2Bt + C - // x' = (3At + 2B)t + C - double value = ((((3*coeff0)*t) + (2*coeff1))*t) + coeff2; -// compareCoeff(); + // x' = 3At^2 + 2Bt + C + // x' = (3At + 2B)t + C + double value = ((((3 * coeff0) * t) + (2 * coeff1)) * t) + coeff2; + // compareCoeff(); return value; - } + } - private double getYDerivate(final double t) - { - //If our curve has an equation of... + private double getYDerivate(final double t) { + // If our curve has an equation of... // - // y = At^3 + Bt^2 + Ct + D + // y = At^3 + Bt^2 + Ct + D // - // ...its slope will be... + // ...its slope will be... // - // y' = 3Et^2 +2Ft + G - // y' = (3Et + 2F)t + G - double value = ((((3*coeff4)*t) + (2*coeff5))*t) + coeff6; + // y' = 3Et^2 +2Ft + G + // y' = (3Et + 2F)t + G + double value = ((((3 * coeff4) * t) + (2 * coeff5)) * t) + coeff6; return value; } - double getXSecondDerivate(final double t) - { - double value = (6*coeff0*t) + (2*coeff1); + double getXSecondDerivate(final double t) { + double value = (6 * coeff0 * t) + (2 * coeff1); return value; - } + } - double getYSecondDerivate(final double t) - { - double value = (6*coeff4*t) + (2*coeff5); + double getYSecondDerivate(final double t) { + double value = (6 * coeff4 * t) + (2 * coeff5); return value; - } + } - synchronized double getYForX(final double x) - { + double getYForX(final double x) { calculateCoeff(); - // I don't know how to find an exact and closed solution to finding y given - // x. You first have to use x to solve for t and then you solve t for y. + // I don't know how to find an exact and closed solution to finding y + // given + // x. You first have to use x to solve for t and then you solve t for y. - // One useful way to do this is to take a guess for a t value. See what x - // you get. Note the error. Reduce the error and try again. Keep this up - // till you have a root to acceptable accuracy. + // One useful way to do this is to take a guess for a t value. See what + // x + // you get. Note the error. Reduce the error and try again. Keep this up + // till you have a root to acceptable accuracy. // - // A good first guess is to normalize x so it ranges from 0 to 1 and then - // simply guess that x = t. This will be fairly close for curves that aren't - // bent very much. And a useful guess for ALL spline curves. + // A good first guess is to normalize x so it ranges from 0 to 1 and + // then + // simply guess that x = t. This will be fairly close for curves that + // aren't + // bent very much. And a useful guess for ALL spline curves. - //Guess initial t - double t = (x-mStartKnot.getEndPoint().x)/(mEndKnot.getEndPoint().x-mStartKnot.getEndPoint().x); + // Guess initial t + double t = (x - mStartKnot.getEndPoint().x) + / (mEndKnot.getEndPoint().x - mStartKnot.getEndPoint().x); - t = getTForXInternal(x,t); + t = getTForXInternal(x, t); double value = getYValue(t); - -/* - double xvalue = getXValue(t); - - if(Math.abs(xvalue - x) > POS_TOLERANCE) - { - System.out.println("find x: " + x + " real x: " + xvalue + " t:" + t + " p0 x:" + p0.x + " p3 x: " + p3.x); - xvalue = getXValue(t); - } -*/ + + /* + * double xvalue = getXValue(t); + * + * if(Math.abs(xvalue - x) > POS_TOLERANCE) { + * System.out.println("find x: " + x + " real x: " + xvalue + " t:" + t + * + " p0 x:" + p0.x + " p3 x: " + p3.x); xvalue = getXValue(t); } + */ return value; } - - public double getMinX() - { + + public double getMinX() { return getMinMaxNumerical(BezierSpline.X, BezierSpline.MIN); } - public double getMinY() - { + public double getMinY() { return getMinMaxNumerical(BezierSpline.Y, BezierSpline.MIN); } - public double getMaxX() - { + public double getMaxX() { return getMinMaxNumerical(BezierSpline.X, BezierSpline.MAX); } - public double getMaxY() - { + public double getMaxY() { return getMinMaxNumerical(BezierSpline.Y, BezierSpline.MAX); } - public synchronized double getMinMaxNumerical(int XorY, int MinOrMax) - { + public double getMinMaxNumerical(int XorY, int MinOrMax) { calculateCoeff(); - return getMinMaxNumerical(0, 1, BezierSpline.MIN_MAX_SPLITS, XorY, MinOrMax); + return getMinMaxNumerical(0, 1, BezierSpline.MIN_MAX_SPLITS, XorY, + MinOrMax); } - private synchronized double getMinMaxNumerical(int XorY, int MinOrMax, double t0, double t1) - { + private double getMinMaxNumerical(int XorY, int MinOrMax, + double t0, double t1) { calculateCoeff(); - - return getMinMaxNumerical(t0, t1, BezierSpline.MIN_MAX_SPLITS, XorY, MinOrMax); + + return getMinMaxNumerical(t0, t1, BezierSpline.MIN_MAX_SPLITS, XorY, + MinOrMax); } - public double getTForMinMaxNumerical(int XorY, int MinOrMax) - { - return getTForMinMaxNumerical(XorY, MinOrMax,0.0, 1.0); + public double getTForMinMaxNumerical(int XorY, int MinOrMax) { + return getTForMinMaxNumerical(XorY, MinOrMax, 0.0, 1.0); } - private synchronized double getTForMinMaxNumerical(int XorY, int MinOrMax, double t0, double t1) - { + private double getTForMinMaxNumerical(int XorY, int MinOrMax, + double t0, double t1) { calculateCoeff(); - return getTForMinMaxNumerical(t0, t1, BezierSpline.MIN_MAX_SPLITS, XorY, MinOrMax); + return getTForMinMaxNumerical(t0, t1, BezierSpline.MIN_MAX_SPLITS, + XorY, MinOrMax); } - public double getMinMaxNumerical(double t0, double t1, int nrOfSplits,int XorY, int MinOrMax) - { + public double getMinMaxNumerical(double t0, double t1, int nrOfSplits, + int XorY, int MinOrMax) { double best_t = 0; - double best_value = (MinOrMax==BezierSpline.MAX)?-10000000:10000000; + double best_value = (MinOrMax == BezierSpline.MAX) ? -10000000 + : 10000000; double current_t; double current_value; - double seg = ((t1-t0)/nrOfSplits); - for(int i = 0; i < nrOfSplits; i++) - { - current_t = seg*i + t0; - if(current_t < 0 || current_t > 1) + double seg = ((t1 - t0) / nrOfSplits); + for (int i = 0; i < nrOfSplits; i++) { + current_t = seg * i + t0; + if (current_t < 0 || current_t > 1) continue; - current_value = (XorY==BezierSpline.X)?getXValue(current_t):getYValue(current_t); + current_value = (XorY == BezierSpline.X) ? getXValue(current_t) + : getYValue(current_t); - if(MinOrMax==BezierSpline.MAX) - { - if(current_value >= best_value) - { + if (MinOrMax == BezierSpline.MAX) { + if (current_value >= best_value) { best_value = current_value; best_t = current_t; } - } - else - { - if(current_value <= best_value) - { + } else { + if (current_value <= best_value) { best_value = current_value; best_t = current_t; - } + } } } - if((best_t - ((t1-t0)/2)) < BezierSpline.MIN_MAX_TOLERANCE) + if ((best_t - ((t1 - t0) / 2)) < BezierSpline.MIN_MAX_TOLERANCE) return best_value; - else if(nrOfSplits <= 2) + else if (nrOfSplits <= 2) return best_value; else - return getMinMaxNumerical(best_t-seg,best_t+seg, nrOfSplits/2,XorY,MinOrMax); + return getMinMaxNumerical(best_t - seg, best_t + seg, + nrOfSplits / 2, XorY, MinOrMax); } - double getTForMinMaxNumerical(double t0, double t1, int nrOfSplits,int XorY, int MinOrMax) - { + double getTForMinMaxNumerical(double t0, double t1, int nrOfSplits, + int XorY, int MinOrMax) { double best_t = 0; - double best_value = (MinOrMax==BezierSpline.MAX)?-10000000:10000000; + double best_value = (MinOrMax == BezierSpline.MAX) ? -10000000 + : 10000000; double current_t; double current_value; - double seg = ((t1-t0)/nrOfSplits); - for(int i = 0; i < nrOfSplits; i++) - { - current_t = seg*i + t0; - if(current_t < 0 || current_t > 1) + double seg = ((t1 - t0) / nrOfSplits); + for (int i = 0; i < nrOfSplits; i++) { + current_t = seg * i + t0; + if (current_t < 0 || current_t > 1) continue; - current_value = (XorY==BezierSpline.X)?getXValue(current_t):getYValue(current_t); + current_value = (XorY == BezierSpline.X) ? getXValue(current_t) + : getYValue(current_t); - if(MinOrMax==BezierSpline.MAX) - { - if(current_value >= best_value) - { + if (MinOrMax == BezierSpline.MAX) { + if (current_value >= best_value) { best_value = current_value; best_t = current_t; } - } - else - { - if(current_value <= best_value) - { + } else { + if (current_value <= best_value) { best_value = current_value; best_t = current_t; - } + } } } - if((best_t - ((t1-t0)/2)) < BezierSpline.MIN_MAX_TOLERANCE) + if ((best_t - ((t1 - t0) / 2)) < BezierSpline.MIN_MAX_TOLERANCE) return best_t; - else if(nrOfSplits <= 2) + else if (nrOfSplits <= 2) return best_t; else - return getTForMinMaxNumerical(best_t-seg,best_t+seg, nrOfSplits/2,XorY,MinOrMax); + return getTForMinMaxNumerical(best_t - seg, best_t + seg, + nrOfSplits / 2, XorY, MinOrMax); } - + public double getTangent(double t) { - + calculateCoeff(); - + double dx = getXDerivate(t); double dy = getYDerivate(t); - double angle = Math.atan2(dx,dy); + double angle = Math.atan2(dx, dy); return angle; } - - synchronized double getLength() - { + public double getNormal(double t) { + return getTangent(t) + (Math.PI / 2.0); + } + + public Point2D.Double getTangentVector(double t) { + + double angle = getTangent(t); + + return new Point2D.Double(Math.cos(angle), Math.sin(angle)); + } + + public Point2D.Double getNormalVector(double t) { + double angle = getTangent(t) + (Math.PI / 2.0); + + return new Point2D.Double(Math.cos(angle), Math.sin(angle)); + } + + public double getLength() { calculateCoeff(); - if(mLengthDirty) - { + if (mLengthDirty) { mLength = getLength(BezierSpline.ZERO, BezierSpline.ONE); mLengthDirty = false; } return mLength; } - public double getLength(double t0, double t1) - { + public double getLength(double t0, double t1) { calculateCoeff(); - - //Get endpoints + + // Get endpoints double x0 = getXValue(t0); double y0 = getYValue(t0); double x1 = getXValue(t1); double y1 = getYValue(t1); - //Get t split point - double ts = (t1-t0)/2 + t0; + // Get t split point + double ts = (t1 - t0) / 2 + t0; double sx = getXValue(ts); double sy = getYValue(ts); - //Distance between centerpoint and real split curvepoint - double length = VecMath.getVecLength(x0,y0,sx,sy) + VecMath.getVecLength(sx,sy,x1,y1); - double chord = VecMath.getVecLength(x0,y0,x1,y1); + // Distance between centerpoint and real split curvepoint + double length = VecMath.getVecLength(x0, y0, sx, sy) + + VecMath.getVecLength(sx, sy, x1, y1); + double chord = VecMath.getVecLength(x0, y0, x1, y1); - if(length - chord > BezierSpline.LENGTH_TOLERANCE && t1-t0 > 0.001) - { + if (length - chord > BezierSpline.LENGTH_TOLERANCE && t1 - t0 > 0.001) { return getLength(t0, ts) + getLength(ts, t1); - } - else - { - return length; + } else { + return length; } - } - - - synchronized public double getTForDistance(Point2D.Double fromPoint, double distance) - { + public double getTForDistance(Point2D.Double fromPoint, + double distance) { calculateCoeff(); - return getTForDistance(0, 1, BezierSpline.MIN_MAX_SPLITS, fromPoint, distance); + return getTForDistance(0, 1, BezierSpline.MIN_MAX_SPLITS, fromPoint, + distance); } - private double getTForDistance(double t0, double t1, int nrOfSplits, Point2D.Double fromPoint, double distance) - { + private double getTForDistance(double t0, double t1, int nrOfSplits, + Point2D.Double fromPoint, double distance) { double best_t = 0; double best_error = 100000000; @@ -776,41 +735,38 @@ private double getTForDistance(double t0, double t1, int nrOfSplits, Point2D.Dou Point2D.Double current_point; double current_distance; double current_error; - double seg = ((t1-t0)/nrOfSplits); - for(int i = 0; i < nrOfSplits; i++) - { - current_t = seg*i + t0; - if(current_t < 0 || current_t > 1) + double seg = ((t1 - t0) / nrOfSplits); + for (int i = 0; i < nrOfSplits; i++) { + current_t = seg * i + t0; + if (current_t < 0 || current_t > 1) continue; current_point = getValue(current_t); - + current_distance = VecMath.getVecLength(fromPoint, current_point); - - current_error = Math.abs(current_distance-distance); - if(current_error < best_error) - { + + current_error = Math.abs(current_distance - distance); + if (current_error < best_error) { best_error = current_error; best_t = current_t; } } - if((best_t - ((t1-t0)/2)) < BezierSpline.DISTANCE_TOLERANCE) + if ((best_t - ((t1 - t0) / 2)) < BezierSpline.DISTANCE_TOLERANCE) return best_t; - else if(nrOfSplits <= 2) + else if (nrOfSplits <= 2) return best_t; else - return getTForDistance(best_t-seg,best_t+seg, nrOfSplits/2,fromPoint,distance); + return getTForDistance(best_t - seg, best_t + seg, nrOfSplits / 2, + fromPoint, distance); } - public synchronized double getClosestT(Point2D.Double point) - { + public double getClosestT(Point2D.Double point) { calculateCoeff(); - return getClosestT(0, 1, 32, point.x, point.y); + return getClosestT(0, 1, 32, point.x, point.y); } - double getClosestT(double t0, double t1, int nrOfSplits, double x, double y) - { + double getClosestT(double t0, double t1, int nrOfSplits, double x, double y) { double best_t = 0; double min_dist = 1000000000; @@ -818,11 +774,10 @@ public synchronized double getClosestT(Point2D.Double point) double current_x; double current_y; double current_dist; - double seg = ((t1-t0)/nrOfSplits); - for(int i = 0; i < nrOfSplits; i++) - { - current_t = seg*i + t0; - if(current_t < 0 || current_t > 1) + double seg = ((t1 - t0) / nrOfSplits); + for (int i = 0; i < nrOfSplits; i++) { + current_t = seg * i + t0; + if (current_t < 0 || current_t > 1) continue; current_x = getXValue(current_t); @@ -830,32 +785,29 @@ public synchronized double getClosestT(Point2D.Double point) current_dist = VecMath.getVecLength(current_x, current_y, x, y); - if(current_dist <= min_dist) - { + if (current_dist <= min_dist) { min_dist = current_dist; best_t = current_t; } } - if((best_t - ((t1-t0)/2)) < 0.001) + if ((best_t - ((t1 - t0) / 2)) < 0.001) return best_t; - else if(nrOfSplits <= 2) + else if (nrOfSplits <= 2) return best_t; else - return getClosestT(best_t-seg,best_t+seg, nrOfSplits/2, x, y); + return getClosestT(best_t - seg, best_t + seg, nrOfSplits / 2, x, y); } - public synchronized double getCurvatureAt(double pos) - { + public double getCurvatureAt(double pos) { calculateCoeff(); - return getCurvature(getTForX(pos)); + return getCurvature(getTForX(pos)); } - public double getCurvature(double t) - { + public double getCurvature(double t) { calculateCoeff(); - //K(t) = (x'y" - y'x") / (x'^2 + y'^2)^(3/2) + // K(t) = (x'y" - y'x") / (x'^2 + y'^2)^(3/2) double dx = getXDerivate(t); double dy = getYDerivate(t); @@ -863,43 +815,45 @@ public double getCurvature(double t) double ddx = getXSecondDerivate(t); double ddy = getYSecondDerivate(t); - return ((dx*ddy) - (dy*ddx))/Math.pow((dx*dx) + (dy*dy), 1.5); + return ((dx * ddy) - (dy * ddx)) / Math.pow((dx * dx) + (dy * dy), 1.5); } - BezierKnot getSplitControlPoint(double t) - { - //Split using de Casteljau's algorithm + BezierKnot getSplitControlPoint(double t) { + // Split using de Casteljau's algorithm Point2D.Double q1 = new Point2D.Double(); Point2D.Double q2 = new Point2D.Double(); Point2D.Double q3 = new Point2D.Double(); - VecMath.subVector(getStartKnot().getEndPoint(),getStartKnot().getTangentToNext(),q1); + VecMath.subVector(getStartKnot().getEndPoint(), getStartKnot() + .getTangentToNext(), q1); VecMath.scaleVector(q1, t); - VecMath.addVector(getStartKnot().getEndPoint(),q1,q1); + VecMath.addVector(getStartKnot().getEndPoint(), q1, q1); - VecMath.subVector(getStartKnot().getTangentToNext(),getEndKnot().getTangentToPrev(),q2); + VecMath.subVector(getStartKnot().getTangentToNext(), getEndKnot() + .getTangentToPrev(), q2); VecMath.scaleVector(q2, t); - VecMath.addVector(getStartKnot().getTangentToNext(),q2,q2); + VecMath.addVector(getStartKnot().getTangentToNext(), q2, q2); - VecMath.subVector(getEndKnot().getTangentToPrev(),getEndKnot().getEndPoint(),q3); + VecMath.subVector(getEndKnot().getTangentToPrev(), getEndKnot() + .getEndPoint(), q3); VecMath.scaleVector(q3, t); - VecMath.addVector(getEndKnot().getTangentToPrev(),q3,q3); + VecMath.addVector(getEndKnot().getTangentToPrev(), q3, q3); Point2D.Double r1 = new Point2D.Double(); Point2D.Double r2 = new Point2D.Double(); Point2D.Double r3 = new Point2D.Double(); - VecMath.subVector(q1,q2,r2); + VecMath.subVector(q1, q2, r2); VecMath.scaleVector(r2, t); - VecMath.addVector(q1,r2,r2); + VecMath.addVector(q1, r2, r2); - VecMath.subVector(q2,q3,r3); + VecMath.subVector(q2, q3, r3); VecMath.scaleVector(r3, t); - VecMath.addVector(q2,r3,r3); + VecMath.addVector(q2, r3, r3); - VecMath.subVector(r2,r3,r1); + VecMath.subVector(r2, r3, r1); VecMath.scaleVector(r1, t); - VecMath.addVector(r2,r1,r1); + VecMath.addVector(r2, r1, r1); BezierKnot ret = new BezierKnot(); ret.getPoints()[0].setLocation(r1); @@ -909,44 +863,39 @@ BezierKnot getSplitControlPoint(double t) return ret; } - synchronized double getTForLength(Point2D.Double p0, Point2D.Double t1, Point2D.Double t2, Point2D.Double p3, double length) - { + double getTForLength(Point2D.Double p0, Point2D.Double t1, + Point2D.Double t2, Point2D.Double p3, double length) { calculateCoeff(); - return getTForLength(0, 1, length); + return getTForLength(0, 1, length); } - private double getTangent2(double t) - { + private double getTangent2(double t) { BezierKnot cp = getSplitControlPoint(t); - Point2D.Double u = new Point2D.Double(0,1); + Point2D.Double u = new Point2D.Double(0, 1); Point2D.Double v = new Point2D.Double(); VecMath.subVector(cp.getEndPoint(), cp.getTangentToNext(), v); double angle = VecMath.getVecAngle(u, v); return angle; } - public double getTangentAt(double pos) - { + public double getTangentAt(double pos) { calculateCoeff(); double t = getTForX(pos); - + return getTangent(t); } - - public void onChange(BezierKnot knot) - { + + public void onChange(BezierKnot knot) { setDirty(); } - - void setDirty() - { + + void setDirty() { mCoeffDirty = true; mLengthDirty = true; - - } + } + } - diff --git a/cadcore/BezierFit.java b/cadcore/BezierFit.java new file mode 100644 index 0000000..99c54ac --- /dev/null +++ b/cadcore/BezierFit.java @@ -0,0 +1,905 @@ +package cadcore; + +/** + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for + software and other kinds of works. + + The licenses for most software and other practical works are designed + to take away your freedom to share and change the works. By contrast, + the GNU General Public License is intended to guarantee your freedom to + share and change all versions of a program--to make sure it remains free + software for all its users. We, the Free Software Foundation, use the + GNU General Public License for most of our software; it applies also to + any other work released this way by its authors. You can apply it to + your programs, too. + + When we speak of free software, we are referring to freedom, not + price. Our General Public Licenses are designed to make sure that you + have the freedom to distribute copies of free software (and charge for + them if you wish), that you receive source code or can get it if you + want it, that you can change the software or use pieces of it in new + free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you + these rights or asking you to surrender the rights. Therefore, you have + certain responsibilities if you distribute copies of the software, or if + you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether + gratis or for a fee, you must pass on to the recipients the same + freedoms that you received. You must make sure that they, too, receive + or can get the source code. And you must show them these terms so they + know their rights. + + Developers that use the GNU GPL protect your rights with two steps: + (1) assert copyright on the software, and (2) offer you this License + giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains + that there is no warranty for this free software. For both users' and + authors' sake, the GPL requires that modified versions be marked as + changed, so that their problems will not be attributed erroneously to + authors of previous versions. + + Some devices are designed to deny users access to install or run + modified versions of the software inside them, although the manufacturer + can do so. This is fundamentally incompatible with the aim of + protecting users' freedom to change the software. The systematic + pattern of such abuse occurs in the area of products for individuals to + use, which is precisely where it is most unacceptable. Therefore, we + have designed this version of the GPL to prohibit the practice for those + products. If such problems arise substantially in other domains, we + stand ready to extend this provision to those domains in future versions + of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. + States should not allow patents to restrict development and use of + software on general-purpose computers, but in those that do, we wish to + avoid the special danger that patents applied to a free program could + make it effectively proprietary. To prevent this, the GPL assures that + patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and + modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of + works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this + License. Each licensee is addressed as "you". "Licensees" and + "recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work + in a fashion requiring copyright permission, other than the making of an + exact copy. The resulting work is called a "modified version" of the + earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based + on the Program. + + To "propagate" a work means to do anything with it that, without + permission, would make you directly or secondarily liable for + infringement under applicable copyright law, except executing it on a + computer or modifying a private copy. Propagation includes copying, + distribution (with or without modification), making available to the + public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other + parties to make or receive copies. Mere interaction with a user through + a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" + to the extent that it includes a convenient and prominently visible + feature that (1) displays an appropriate copyright notice, and (2) + tells the user that there is no warranty for the work (except to the + extent that warranties are provided), that licensees may convey the + work under this License, and how to view a copy of this License. If + the interface presents a list of user commands or options, such as a + menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work + for making modifications to it. "Object code" means any non-source + form of a work. + + A "Standard Interface" means an interface that either is an official + standard defined by a recognized standards body, or, in the case of + interfaces specified for a particular programming language, one that + is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other + than the work as a whole, that (a) is included in the normal form of + packaging a Major Component, but which is not part of that Major + Component, and (b) serves only to enable use of the work with that + Major Component, or to implement a Standard Interface for which an + implementation is available to the public in source code form. A + "Major Component", in this context, means a major essential component + (kernel, window system, and so on) of the specific operating system + (if any) on which the executable work runs, or a compiler used to + produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all + the source code needed to generate, install, and (for an executable + work) run the object code and to modify the work, including scripts to + control those activities. However, it does not include the work's + System Libraries, or general-purpose tools or generally available free + programs which are used unmodified in performing those activities but + which are not part of the work. For example, Corresponding Source + includes interface definition files associated with source files for + the work, and the source code for shared libraries and dynamically + linked subprograms that the work is specifically designed to require, + such as by intimate data communication or control flow between those + subprograms and other parts of the work. + + The Corresponding Source need not include anything that users + can regenerate automatically from other parts of the Corresponding + Source. + + The Corresponding Source for a work in source code form is that + same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of + copyright on the Program, and are irrevocable provided the stated + conditions are met. This License explicitly affirms your unlimited + permission to run the unmodified Program. The output from running a + covered work is covered by this License only if the output, given its + content, constitutes a covered work. This License acknowledges your + rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not + convey, without conditions so long as your license otherwise remains + in force. You may convey covered works to others for the sole purpose + of having them make modifications exclusively for you, or provide you + with facilities for running those works, provided that you comply with + the terms of this License in conveying all material for which you do + not control copyright. Those thus making or running the covered works + for you must do so exclusively on your behalf, under your direction + and control, on terms that prohibit them from making any copies of + your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under + the conditions stated below. Sublicensing is not allowed; section 10 + makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological + measure under any applicable law fulfilling obligations under article + 11 of the WIPO copyright treaty adopted on 20 December 1996, or + similar laws prohibiting or restricting circumvention of such + measures. + + When you convey a covered work, you waive any legal power to forbid + circumvention of technological measures to the extent such circumvention + is effected by exercising rights under this License with respect to + the covered work, and you disclaim any intention to limit operation or + modification of the work as a means of enforcing, against the work's + users, your or third parties' legal rights to forbid circumvention of + technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you + receive it, in any medium, provided that you conspicuously and + appropriately publish on each copy an appropriate copyright notice; + keep intact all notices stating that this License and any + non-permissive terms added in accord with section 7 apply to the code; + keep intact all notices of the absence of any warranty; and give all + recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, + and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to + produce it from the Program, in the form of source code under the + terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent + works, which are not by their nature extensions of the covered work, + and which are not combined with it such as to form a larger program, + in or on a volume of a storage or distribution medium, is called an + "aggregate" if the compilation and its resulting copyright are not + used to limit the access or legal rights of the compilation's users + beyond what the individual works permit. Inclusion of a covered work + in an aggregate does not cause this License to apply to the other + parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms + of sections 4 and 5, provided that you also convey the + machine-readable Corresponding Source under the terms of this License, + in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded + from the Corresponding Source as a System Library, need not be + included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any + tangible personal property which is normally used for personal, family, + or household purposes, or (2) anything designed or sold for incorporation + into a dwelling. In determining whether a product is a consumer product, + doubtful cases shall be resolved in favor of coverage. For a particular + product received by a particular user, "normally used" refers to a + typical or common use of that class of product, regardless of the status + of the particular user or of the way in which the particular user + actually uses, or expects or is expected to use, the product. A product + is a consumer product regardless of whether the product has substantial + commercial, industrial or non-consumer uses, unless such uses represent + the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, + procedures, authorization keys, or other information required to install + and execute modified versions of a covered work in that User Product from + a modified version of its Corresponding Source. The information must + suffice to ensure that the continued functioning of the modified object + code is in no case prevented or interfered with solely because + modification has been made. + + If you convey an object code work under this section in, or with, or + specifically for use in, a User Product, and the conveying occurs as + part of a transaction in which the right of possession and use of the + User Product is transferred to the recipient in perpetuity or for a + fixed term (regardless of how the transaction is characterized), the + Corresponding Source conveyed under this section must be accompanied + by the Installation Information. But this requirement does not apply + if neither you nor any third party retains the ability to install + modified object code on the User Product (for example, the work has + been installed in ROM). + + The requirement to provide Installation Information does not include a + requirement to continue to provide support service, warranty, or updates + for a work that has been modified or installed by the recipient, or for + the User Product in which it has been modified or installed. Access to a + network may be denied when the modification itself materially and + adversely affects the operation of the network or violates the rules and + protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, + in accord with this section must be in a format that is publicly + documented (and with an implementation available to the public in + source code form), and must require no special password or key for + unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this + License by making exceptions from one or more of its conditions. + Additional permissions that are applicable to the entire Program shall + be treated as though they were included in this License, to the extent + that they are valid under applicable law. If additional permissions + apply only to part of the Program, that part may be used separately + under those permissions, but the entire Program remains governed by + this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option + remove any additional permissions from that copy, or from any part of + it. (Additional permissions may be written to require their own + removal in certain cases when you modify the work.) You may place + additional permissions on material, added by you to a covered work, + for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you + add to a covered work, you may (if authorized by the copyright holders of + that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further + restrictions" within the meaning of section 10. If the Program as you + received it, or any part of it, contains a notice stating that it is + governed by this License along with a term that is a further + restriction, you may remove that term. If a license document contains + a further restriction but permits relicensing or conveying under this + License, you may add to a covered work material governed by the terms + of that license document, provided that the further restriction does + not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you + must place, in the relevant source files, a statement of the + additional terms that apply to those files, or a notice indicating + where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the + form of a separately written license, or stated as exceptions; + the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly + provided under this License. Any attempt otherwise to propagate or + modify it is void, and will automatically terminate your rights under + this License (including any patent licenses granted under the third + paragraph of section 11). + + However, if you cease all violation of this License, then your + license from a particular copyright holder is reinstated (a) + provisionally, unless and until the copyright holder explicitly and + finally terminates your license, and (b) permanently, if the copyright + holder fails to notify you of the violation by some reasonable means + prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is + reinstated permanently if the copyright holder notifies you of the + violation by some reasonable means, this is the first time you have + received notice of violation of this License (for any work) from that + copyright holder, and you cure the violation prior to 30 days after + your receipt of the notice. + + Termination of your rights under this section does not terminate the + licenses of parties who have received copies or rights from you under + this License. If your rights have been terminated and not permanently + reinstated, you do not qualify to receive new licenses for the same + material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or + run a copy of the Program. Ancillary propagation of a covered work + occurring solely as a consequence of using peer-to-peer transmission + to receive a copy likewise does not require acceptance. However, + nothing other than this License grants you permission to propagate or + modify any covered work. These actions infringe copyright if you do + not accept this License. Therefore, by modifying or propagating a + covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically + receives a license from the original licensors, to run, modify and + propagate that work, subject to this License. You are not responsible + for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an + organization, or substantially all assets of one, or subdividing an + organization, or merging organizations. If propagation of a covered + work results from an entity transaction, each party to that + transaction who receives a copy of the work also receives whatever + licenses to the work the party's predecessor in interest had or could + give under the previous paragraph, plus a right to possession of the + Corresponding Source of the work from the predecessor in interest, if + the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the + rights granted or affirmed under this License. For example, you may + not impose a license fee, royalty, or other charge for exercise of + rights granted under this License, and you may not initiate litigation + (including a cross-claim or counterclaim in a lawsuit) alleging that + any patent claim is infringed by making, using, selling, offering for + sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this + License of the Program or a work on which the Program is based. The + work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims + owned or controlled by the contributor, whether already acquired or + hereafter acquired, that would be infringed by some manner, permitted + by this License, of making, using, or selling its contributor version, + but do not include claims that would be infringed only as a + consequence of further modification of the contributor version. For + purposes of this definition, "control" includes the right to grant + patent sublicenses in a manner consistent with the requirements of + this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free + patent license under the contributor's essential patent claims, to + make, use, sell, offer for sale, import and otherwise run, modify and + propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express + agreement or commitment, however denominated, not to enforce a patent + (such as an express permission to practice a patent or covenant not to + sue for patent infringement). To "grant" such a patent license to a + party means to make such an agreement or commitment not to enforce a + patent against the party. + + If you convey a covered work, knowingly relying on a patent license, + and the Corresponding Source of the work is not available for anyone + to copy, free of charge and under the terms of this License, through a + publicly available network server or other readily accessible means, + then you must either (1) cause the Corresponding Source to be so + available, or (2) arrange to deprive yourself of the benefit of the + patent license for this particular work, or (3) arrange, in a manner + consistent with the requirements of this License, to extend the patent + license to downstream recipients. "Knowingly relying" means you have + actual knowledge that, but for the patent license, your conveying the + covered work in a country, or your recipient's use of the covered work + in a country, would infringe one or more identifiable patents in that + country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or + arrangement, you convey, or propagate by procuring conveyance of, a + covered work, and grant a patent license to some of the parties + receiving the covered work authorizing them to use, propagate, modify + or convey a specific copy of the covered work, then the patent license + you grant is automatically extended to all recipients of the covered + work and works based on it. + + A patent license is "discriminatory" if it does not include within + the scope of its coverage, prohibits the exercise of, or is + conditioned on the non-exercise of one or more of the rights that are + specifically granted under this License. You may not convey a covered + work if you are a party to an arrangement with a third party that is + in the business of distributing software, under which you make payment + to the third party based on the extent of your activity of conveying + the work, and under which the third party grants, to any of the + parties who would receive the covered work from you, a discriminatory + patent license (a) in connection with copies of the covered work + conveyed by you (or copies made from those copies), or (b) primarily + for and in connection with specific products or compilations that + contain the covered work, unless you entered into that arrangement, + or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting + any implied license or other defenses to infringement that may + otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or + otherwise) that contradict the conditions of this License, they do not + excuse you from the conditions of this License. If you cannot convey a + covered work so as to satisfy simultaneously your obligations under this + License and any other pertinent obligations, then as a consequence you may + not convey it at all. For example, if you agree to terms that obligate you + to collect a royalty for further conveying from those to whom you convey + the Program, the only way you could satisfy both those terms and this + License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have + permission to link or combine any covered work with a work licensed + under version 3 of the GNU Affero General Public License into a single + combined work, and to convey the resulting work. The terms of this + License will continue to apply to the part which is the covered work, + but the special requirements of the GNU Affero General Public License, + section 13, concerning interaction through a network will apply to the + combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of + the GNU General Public License from time to time. Such new versions will + be similar in spirit to the present version, but may differ in detail to + address new problems or concerns. + + Each version is given a distinguishing version number. If the + Program specifies that a certain numbered version of the GNU General + Public License "or any later version" applies to it, you have the + option of following the terms and conditions either of that numbered + version or of any later version published by the Free Software + Foundation. If the Program does not specify a version number of the + GNU General Public License, you may choose any version ever published + by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future + versions of the GNU General Public License can be used, that proxy's + public statement of acceptance of a version permanently authorizes you + to choose that version for the Program. + + Later license versions may give you additional or different + permissions. However, no additional obligations are imposed on any + author or copyright holder as a result of your choosing to follow a + later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY + APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT + HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY + OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM + IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF + ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING + WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS + THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY + GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE + USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF + DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD + PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), + EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF + SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided + above cannot be given local legal effect according to their terms, + reviewing courts shall apply local law that most closely approximates + an absolute waiver of all civil liability in connection with the + Program, unless a warranty or assumption of liability accompanies a + copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest + possible use to the public, the best way to achieve this is to make it + free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest + to attach them to the start of each source file to most effectively + state the exclusion of warranty; and each file should have at least + the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short + notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + + The hypothetical commands `show w' and `show c' should show the appropriate + parts of the General Public License. Of course, your program's commands + might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, + if any, to sign a "copyright disclaimer" for the program, if necessary. + For more information on this, and how to apply and follow the GNU GPL, see + . + + The GNU General Public License does not permit incorporating your program + into proprietary programs. If your program is a subroutine library, you + may consider it more useful to permit linking proprietary applications with + the library. If this is what you want to do, use the GNU Lesser General + Public License instead of this License. But first, please read + . + */ +import java.util.ArrayList; +import java.awt.geom.Point2D; + +import org.ujmp.core.Matrix; + +/** + * Class used to fit a bezier curve to a list of points. Imposes 4 constraints + * leaving 4 unknowns which are optimized using simulated annealing. + * + * @author jhero + * + */ + +public class BezierFit { +/* + public static void main(String[] args) { + + ArrayList points = new ArrayList(); + + points.add(new Point2D.Double(0, 0)); + points.add(new Point2D.Double(1, 1)); + points.add(new Point2D.Double(2, 0)); + points.add(new Point2D.Double(3, 2)); + + bestFitTest(points); + + } + + private static void bestFitTest(ArrayList points) { + BezierFit bf = new BezierFit(); + + Point2D[] controlPoints = bf.bestFit(points); + + System.out.print("X:"); + for (Point2D p : points) + System.out.print(p.getX() + ","); + System.out.println(); + + System.out.print("Y:"); + for (Point2D p : points) + System.out.print(p.getY() + ","); + System.out.println(); + + System.out.print("Bx:"); + for (double ti = 0; ti <= 1; ti += 0.01) + System.out.print(bf.pointOnCurve(ti, controlPoints[0], + controlPoints[1], controlPoints[2], controlPoints[3]) + .getX() + + ","); + System.out.println(); + + System.out.print("By:"); + for (double ti = 0; ti <= 1; ti += 0.01) + System.out.print(bf.pointOnCurve(ti, controlPoints[0], + controlPoints[1], controlPoints[2], controlPoints[3]) + .getY() + + ","); + System.out.println(); + + System.out.print("Cx:"); + for (Point2D p : controlPoints) + System.out.print(p.getX() + ","); + System.out.println(); + + System.out.print("Cy:"); + for (Point2D p : controlPoints) + System.out.print(p.getY() + ","); + System.out.println(); + + } +*/ + /** + * Computes the best bezier fit of the supplied points using a simple RSS + * minimization. Returns a list of 4 points, the control points + * + * @param points + * @return + */ + public Point2D[] bestFit(ArrayList points) { + Matrix M = M(); + Matrix Minv; + if (M.det() == 0) + Minv = M.invSPD(); + else + Minv = M.inv(); + Matrix U = U(points); + Matrix UT = U.transpose(); + Matrix X = X(points); + Matrix Y = Y(points); + + Matrix A = UT.mtimes(U); + Matrix B; + if (A.det() == 0) + B = A.invSPD(); + else + B = A.inv(); + Matrix C = Minv.mtimes(B); + Matrix D = C.mtimes(UT); + Matrix E = D.mtimes(X); + Matrix F = D.mtimes(Y); + + Point2D[] P = new Point2D[4]; + for (int i = 0; i < 4; i++) { + double x = E.getAsDouble(i, 0); + double y = F.getAsDouble(i, 0); + + Point2D p = new Point2D.Double(x, y); + P[i] = p; + } + + return P; + } + + private Matrix Y(ArrayList points) { + Matrix Y = Matrix.Factory.fill(0.0, points.size(), 1); + + for (int i = 0; i < points.size(); i++) + Y.setAsDouble(points.get(i).getY(), i, 0); + + return Y; + } + + private Matrix X(ArrayList points) { + Matrix X = Matrix.Factory.fill(0.0, points.size(), 1); + + for (int i = 0; i < points.size(); i++) + X.setAsDouble(points.get(i).getX(), i, 0); + + return X; + } + + private Matrix U(ArrayList points) { + double[] npls = normalizedPathLengths(points); + + Matrix U = Matrix.Factory.fill(0.0, npls.length, 4); + for (int i = 0; i < npls.length; i++) { + U.setAsDouble(Math.pow(npls[i], 3), i, 0); + U.setAsDouble(Math.pow(npls[i], 2), i, 1); + U.setAsDouble(Math.pow(npls[i], 1), i, 2); + U.setAsDouble(Math.pow(npls[i], 0), i, 3); + } + + return U; + } + + private Matrix M() { + Matrix M = Matrix.Factory.fill(0.0, 4, 4); + M.setAsDouble(-1, 0, 0); + M.setAsDouble(3, 0, 1); + M.setAsDouble(-3, 0, 2); + M.setAsDouble(1, 0, 3); + M.setAsDouble(3, 1, 0); + M.setAsDouble(-6, 1, 1); + M.setAsDouble(3, 1, 2); + M.setAsDouble(0, 1, 3); + M.setAsDouble(-3, 2, 0); + M.setAsDouble(3, 2, 1); + M.setAsDouble(0, 2, 2); + M.setAsDouble(0, 2, 3); + M.setAsDouble(1, 3, 0); + M.setAsDouble(0, 3, 1); + M.setAsDouble(0, 3, 2); + M.setAsDouble(0, 3, 3); + return M; + } + + /** + * Computes b(t). + * + * @param t + * @param v1 + * @param v2 + * @param v3 + * @param v4 + * @return + */ +/* private Point2D pointOnCurve(double t, Point2D v1, Point2D v2, Point2D v3, Point2D v4) { + Point2D p; + + double x1 = v1.getX(); + double x2 = v2.getX(); + double x3 = v3.getX(); + double x4 = v4.getX(); + + double y1 = v1.getY(); + double y2 = v2.getY(); + double y3 = v3.getY(); + double y4 = v4.getY(); + + double xt, yt; + + xt = x1 * Math.pow((1 - t), 3) + 3 * x2 * t * Math.pow((1 - t), 2) + 3 + * x3 * Math.pow(t, 2) * (1 - t) + x4 * Math.pow(t, 3); + + yt = y1 * Math.pow((1 - t), 3) + 3 * y2 * t * Math.pow((1 - t), 2) + 3 + * y3 * Math.pow(t, 2) * (1 - t) + y4 * Math.pow(t, 3); + + p = new Point2D.Double(xt, yt); + + return p; + } +*/ + /** + * Computes the percentage of path length at each point. Can directly be + * used as t-indices into the bezier curve. + */ + private double[] normalizedPathLengths(ArrayList points) { + double pathLength[] = new double[points.size()]; + + pathLength[0] = 0; + + for (int i = 1; i < points.size(); i++) { + Point2D p1 = points.get(i); + Point2D p2 = points.get(i - 1); + double distance = Math.sqrt(Math.pow(p1.getX() - p2.getX(), 2) + + Math.pow(p1.getY() - p2.getY(), 2)); + pathLength[i] += pathLength[i - 1] + distance; + } + + double[] zpl = new double[pathLength.length]; + for (int i = 0; i < zpl.length; i++) + zpl[i] = pathLength[i] / pathLength[pathLength.length - 1]; + + return zpl; + } + +} \ No newline at end of file diff --git a/cadcore/BezierKnot.java b/cadcore/BezierKnot.java index 4356d00..00f5e44 100644 --- a/cadcore/BezierKnot.java +++ b/cadcore/BezierKnot.java @@ -27,7 +27,7 @@ public class BezierKnot extends Object implements Cloneable protected double Y_mask = 1.0f; protected int mTangent1Locks = 0; protected int mTangent2Locks = 0; - + List mChangeListeners = new Vector(); public BezierKnot(){ @@ -442,7 +442,7 @@ public Object clone(){ throw new Error("CloneNotSupportedException in BrdCommand"); } - controlPoint.setPoints(new Point2D.Double[3]); + controlPoint.initPoints(); for(int i = 0; i < 3; i++) { controlPoint.getPoints()[i] = (Point2D.Double)this.getPoints()[i].clone(); @@ -480,6 +480,10 @@ public void fromString(String string) onChange(); } + public void initPoints() { + this.mPoints = new Point2D.Double[3]; + } + public void setPoints(Point2D.Double mPoints[]) { this.mPoints = mPoints; onChange(); @@ -502,7 +506,7 @@ void addChangeListener(BezierKnotChangeListener listener) mChangeListeners.add(listener); } - public void onChange() + public void onChange() //TODO: THIS FUNCTION SHOULD NOT BE PUBLIC, FUNCTIONS WHICH CALL onChange() SHOULD BE USED FOR SETTING KNOT VALUES { for(BezierKnotChangeListener listener : mChangeListeners) { diff --git a/cadcore/BezierSpline.java b/cadcore/BezierSpline.java index 6673755..1380588 100644 --- a/cadcore/BezierSpline.java +++ b/cadcore/BezierSpline.java @@ -1,47 +1,39 @@ package cadcore; + import java.awt.geom.Point2D; import java.util.ArrayList; - - public class BezierSpline implements Cloneable { - - - - public static final double ZERO = 0.0000000001; - public static final double ONE = 0.9999999999; + public static final double ZERO = 0.0000000001; + public static final double ONE = 0.9999999999; static final int X = 0; static final int Y = 1; static final int MIN = 0; static final int MAX = 1; - static final double ANGLE_TOLERANCE = 0.05*MathUtils.DEG_TO_RAD; //0.1degrees - static final double ANGLE_T_TOLERANCE = 0.000002; - static final int ANGLE_MAX_ITERATIONS = 50; - static final int ANGLE_SPLITS = 112; + static final double ANGLE_TOLERANCE = 0.05 * MathUtils.DEG_TO_RAD; // 0.1degrees + static final double ANGLE_T_TOLERANCE = 0.000002; + static final int ANGLE_MAX_ITERATIONS = 50; + static final int ANGLE_SPLITS = 112; + + static final double POS_TOLERANCE = 0.003; // 0.03mm + static final int POS_MAX_ITERATIONS = 30; - static final double POS_TOLERANCE = 0.003; //0.03mm - static final int POS_MAX_ITERATIONS = 30; - static final double LENGTH_TOLERANCE = 0.001; - - static final double MIN_MAX_TOLERANCE = 0.0001; + + static final double MIN_MAX_TOLERANCE = 0.0001; static final int MIN_MAX_SPLITS = 96; - + static final double DISTANCE_TOLERANCE = 0.0001; - + protected ArrayList mCurves = new ArrayList(); - - protected int mBestMatchPointIndex; - public BezierSpline() - { + public BezierSpline() { } - - public void set(BezierSpline spline) - { + + public void set(BezierSpline spline) { // Remove extra control points while (getNrOfControlPoints() > spline.getNrOfControlPoints()) { remove(0); @@ -53,138 +45,107 @@ public void set(BezierSpline spline) int nrControlPoints = getNrOfControlPoints(); for (int i = 0; i < nrControlPoints; i++) { - getControlPoint(i).set( - spline.getControlPoint(i)); + getControlPoint(i).set(spline.getControlPoint(i)); } } - public void append(BezierKnot controlPoint) - { - if(mCurves.size() == 0) - { + public void append(BezierKnot controlPoint) { + if (mCurves.size() == 0) { mCurves.add(new BezierCurve(controlPoint, null)); - } - else if(mCurves.size() == 1 && mCurves.get(0).getEndKnot() == null) - { + } else if (mCurves.size() == 1 && mCurves.get(0).getEndKnot() == null) { mCurves.get(0).setEndKnot(controlPoint); - } - else - { - mCurves.add(new BezierCurve(mCurves.get(mCurves.size()-1).getEndKnot(), controlPoint)); + } else { + mCurves.add(new BezierCurve(mCurves.get(mCurves.size() - 1) + .getEndKnot(), controlPoint)); } } - public void insert(int i, BezierKnot controlPoint) - { + public void insert(int i, BezierKnot controlPoint) { BezierKnot next = null; - if(i < getNrOfControlPoints()) - { + if (i < getNrOfControlPoints()) { next = getControlPoint(i); } - if(i > 0 && i-1 < mCurves.size()) - { - BezierCurve prevCurve = mCurves.get(i-1); + if (i > 0 && i - 1 < mCurves.size()) { + BezierCurve prevCurve = mCurves.get(i - 1); prevCurve.setEndKnot(controlPoint); - } - + } + BezierCurve newCurve = new BezierCurve(controlPoint, next); mCurves.add(i, newCurve); } - public void remove(BezierKnot controlPoint) - { + public void remove(BezierKnot controlPoint) { int i = indexOf(controlPoint); - + remove(i); } - public void remove(int i) - { + public void remove(int i) { BezierCurve removeCurve = null; - if(i < mCurves.size()) - { + if (i < mCurves.size()) { removeCurve = mCurves.get(i); } - if(i > 0 && i-1 < mCurves.size()) - { - BezierCurve prevCurve = mCurves.get(i-1); - prevCurve.setEndKnot(removeCurve != null?removeCurve.getEndKnot():null); + if (i > 0 && i - 1 < mCurves.size()) { + BezierCurve prevCurve = mCurves.get(i - 1); + prevCurve.setEndKnot(removeCurve != null ? removeCurve.getEndKnot() + : null); } mCurves.remove(removeCurve); } - public BezierKnot getControlPoint(int i) - { - if(mCurves.size() == 0 || mCurves.size() < i-1) - { + public BezierKnot getControlPoint(int i) { + if (mCurves.size() == 0 || mCurves.size() < i - 1) { return null; } - - if(i == 0) - { + + if (i == 0) { return mCurves.get(0).getStartKnot(); - } - else - { - return mCurves.get(i-1).getEndKnot(); + } else { + return mCurves.get(i - 1).getEndKnot(); } } - - public BezierCurve getCurve(int i) - { + + public BezierCurve getCurve(int i) { return mCurves.get(i); } - - public boolean isLastControlPointNull() - { - if(mCurves.size() == 0) - { + + public boolean isLastControlPointNull() { + if (mCurves.size() == 0) { return true; } - - return (mCurves.get(mCurves.size()-1).getEndKnot() == null); + + return (mCurves.get(mCurves.size() - 1).getEndKnot() == null); } - public int indexOf(BezierKnot controlPoint) - { - for(int i = 0; i < mCurves.size()+1; i++) - { - if(controlPoint == getControlPoint(i)) + public int indexOf(BezierKnot controlPoint) { + for (int i = 0; i < mCurves.size() + 1; i++) { + if (controlPoint == getControlPoint(i)) return i; } return -1; } - - - public int getNrOfControlPoints() - { - return mCurves.size()+(isLastControlPointNull()?0:1); + public int getNrOfControlPoints() { + return mCurves.size() + (isLastControlPointNull() ? 0 : 1); } - public int getNrOfCurves() - { + public int getNrOfCurves() { return mCurves.size(); } - - public void clear() - { + + public void clear() { mCurves.clear(); } - - - public double getValueAt(double pos) - { + public double getValueAt(double pos) { int index = findMatchingBezierSegment(pos); - if(index == -1) - { + if (index == -1) { return 0.0; } @@ -192,56 +153,49 @@ public double getValueAt(double pos) return value; } - public double getValueAtReverse(double pos) - { + public double getValueAtReverse(double pos) { int index = findMatchingBezierSegmentReverse(pos); - if(index != -1) - { + if (index != -1) { BezierCurve curve = mCurves.get(index); - + return curve.getYForX(pos); } - + return 0.0; } - public double getCurvatureAt(double pos) - { + public double getCurvatureAt(double pos) { int index = findMatchingBezierSegment(pos); - if(index == -1) //Not within patch + if (index == -1) // Not within patch return 0.0; BezierCurve curve = mCurves.get(index); - return curve.getCurvature(pos); + return curve.getCurvatureAt(pos); } - public double getMaxX() - { + public double getMaxX() { double max = -100000; - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); double current = curve.getMaxX(); - if(current > max) + if (current > max) max = current; } return max; } - public Point2D.Double getPointByTT(double tt) - { - int index = (int)(tt*getNrOfCurves()); - double t = (tt*getNrOfCurves()) - index; - if(tt >= 1) - { - index = getNrOfCurves()-1; + public Point2D.Double getPointByTT(double tt) { + int index = (int) (tt * getNrOfCurves()); + double t = (tt * getNrOfCurves()) - index; + if (tt >= 1) { + index = getNrOfCurves() - 1; t = ONE; } @@ -249,468 +203,428 @@ public Point2D.Double getPointByTT(double tt) return curve.getValue(t); } - - public double getNormalByTT(double tt) - { - int index = (int)(tt*getNrOfCurves()); - double t = (tt*getNrOfCurves()) - index; - if(tt >= 1) - { - index = getNrOfCurves()-1; + + public double getNormalByTT(double tt) { + int index = (int) (tt * getNrOfCurves()); + double t = (tt * getNrOfCurves()) - index; + if (tt >= 1) { + index = getNrOfCurves() - 1; t = ONE; } -// System.out.printf("getNormalByTT() tt:%f index:%d t:%f\n", tt, index, t); + // System.out.printf("getNormalByTT() tt:%f index:%d t:%f\n", tt, index, + // t); BezierCurve curve = mCurves.get(index); - return curve.getTangent(t) + (Math.PI/2.0); + return curve.getTangent(t) + (Math.PI / 2.0); } - public double getTTByLineIntersect(final Point2D.Double a, final Point2D.Double b) - { - final double slope = (b.y - a.y)/(b.x-a.x); - final double p = a.y - (slope*a.x); - - MathUtils.Function func = new MathUtils.Function(){ - public double f(double tt){ - - //Bezier - Point2D.Double bezierPos = getPointByTT(tt); - - //Line - double lineY = (slope*bezierPos.x) + p; - - return bezierPos.y - lineY; - } - }; - - double aTT = getTTByX(a.x); - double bTT = getTTByX(b.x); - - if(aTT == bTT) - { - return bTT; - } - - double tt = MathUtils.RootFinder.getRoot(func, 0.0, Math.min(aTT, bTT), Math.max(aTT, bTT) ); - - return tt; - } - - public double getTTByX(double x) - { - MathUtils.Function func = new MathUtils.Function(){public double f(double tt){return getPointByTT(tt).x;}}; - - double tt = MathUtils.RootFinder.getRoot(func, x); - - return tt; + public double getTTByLineIntersect(final Point2D.Double a, + final Point2D.Double b) { + final double slope = (b.y - a.y) / (b.x - a.x); + final double p = a.y - (slope * a.x); + + MathUtils.Function func = new MathUtils.Function() { + public double f(double tt) { + + // Bezier + Point2D.Double bezierPos = getPointByTT(tt); + + // Line + double lineY = (slope * bezierPos.x) + p; + + return bezierPos.y - lineY; + } + }; + + double aTT = getTTByX(a.x); + double bTT = getTTByX(b.x); + + if (aTT == bTT) { + return bTT; + } + + double tt = MathUtils.RootFinder.getRoot(func, 0.0, Math.min(aTT, bTT), + Math.max(aTT, bTT)); + + return tt; } - public double getTTByNormal(double angle) - { - MathUtils.Function func = new MathUtils.Function(){public double f(double tt){return getNormalByTT(tt);}}; - - double tt = MathUtils.RootFinder.getRoot(func, angle); - - return tt; + public double getTTByX(double x) { + MathUtils.Function func = new MathUtils.Function() { + public double f(double tt) { + return getPointByTT(tt).x; + } + }; + + double tt = MathUtils.RootFinder.getRoot(func, x); + + return tt; } - public double getLengthByTT(double tt) - { - int index = (int)(tt*getNrOfControlPoints()); - if(tt >= 1) - { - index = getNrOfControlPoints()-1; + public double getTTByNormal(double angle) { + MathUtils.Function func = new MathUtils.Function() { + public double f(double tt) { + return getNormalByTT(tt); + } + }; + + double tt = MathUtils.RootFinder.getRoot(func, angle); + + return tt; + } + + public double getLengthByTT(double tt) { + int index = (int) (tt * getNrOfControlPoints()); + if (tt >= 1) { + index = getNrOfControlPoints() - 1; } double length = 0.0; - - for(int i = 0; i < index; i++) - { + + for (int i = 0; i < index; i++) { BezierCurve curve = mCurves.get(i); length += curve.getLength(); } - + BezierCurve curve = mCurves.get(index); double t = tt - index; - length += curve.getLength(0,t); + length += curve.getLength(0, t); return length; } - - public double getSByTT(double tt) - { - return getLengthByTT(tt)/getLength(); + + public double getSByTT(double tt) { + return getLengthByTT(tt) / getLength(); } - public double getMinX() - { + public double getMinX() { double min = Double.MAX_VALUE; - for(int i = 0; i < mCurves.size()-1; i++) - { + for (int i = 0; i < mCurves.size() - 1; i++) { BezierCurve curve = mCurves.get(i); double current = curve.getMinX(); - if(current < min) + if (current < min) min = current; } return min; } - public double getMaxY() - { + public double getMaxY() { double max = -Double.MAX_VALUE; - for(int i = 0; i < mCurves.size()-1; i++) - { + for (int i = 0; i < mCurves.size() - 1; i++) { BezierCurve curve = mCurves.get(i); double current = curve.getMaxY(); - if(current > max) + if (current > max) max = current; } return max; } - public double getMaxYInRange(double x0, double x1) - { + public double getMaxYInRange(double x0, double x1) { double max = -100000; double current = 0.0; - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); - - double minX = curve.getMinMaxNumerical(0.0, 1.0, MIN_MAX_SPLITS, X, MIN); - double maxX = curve.getMinMaxNumerical(0.0, 1.0, MIN_MAX_SPLITS, X, MAX); - - if(minX > x1) + + double minX = curve.getMinMaxNumerical(0.0, 1.0, MIN_MAX_SPLITS, X, + MIN); + double maxX = curve.getMinMaxNumerical(0.0, 1.0, MIN_MAX_SPLITS, X, + MAX); + + if (minX > x1) continue; - - if(maxX < x0) + + if (maxX < x0) continue; - + double t0 = curve.getTForX(x0, 0.1); double t1 = curve.getTForX(x1, 0.9); current = curve.getMinMaxNumerical(t0, t1, MIN_MAX_SPLITS, Y, MAX); - if(current > max) + if (current > max) max = current; - + } return max; } - public double getXForMaxY() - { + public double getXForMaxY() { double max = -100000; BezierCurve maxCurve = null; - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); double current = curve.getMinMaxNumerical(Y, MAX); - if(current > max) - { + if (current > max) { max = current; maxCurve = curve; } } - - double tMax = maxCurve.getTForMinMaxNumerical(0, 1, MIN_MAX_SPLITS, Y, MAX); + + double tMax = maxCurve.getTForMinMaxNumerical(0, 1, MIN_MAX_SPLITS, Y, + MAX); double x = maxCurve.getXValue(tMax); return x; } - public double getXForMaxYInRange(double x0, double x1) - { + public double getXForMaxYInRange(double x0, double x1) { double max = -100000; BezierCurve maxCurve = null; - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); - - - double minX = curve.getMinMaxNumerical(0.0, 1.0, MIN_MAX_SPLITS, X, MIN); - double maxX = curve.getMinMaxNumerical(0.0, 1.0, MIN_MAX_SPLITS, X, MAX); - - if(minX > x1) + + double minX = curve.getMinMaxNumerical(0.0, 1.0, MIN_MAX_SPLITS, X, + MIN); + double maxX = curve.getMinMaxNumerical(0.0, 1.0, MIN_MAX_SPLITS, X, + MAX); + + if (minX > x1) continue; - - if(maxX < x0) + + if (maxX < x0) continue; - + double t0 = curve.getTForX(x0, 0.1); double t1 = curve.getTForX(x1, 0.9); - double current = curve.getMinMaxNumerical(t0, t1, MIN_MAX_SPLITS, Y, MAX); + double current = curve.getMinMaxNumerical(t0, t1, MIN_MAX_SPLITS, + Y, MAX); - if(current > max) - { + if (current > max) { maxCurve = curve; max = current; } - } + double tMax = maxCurve.getTForMinMaxNumerical(0, 1, MIN_MAX_SPLITS, Y, + MAX); - double tMax = maxCurve.getTForMinMaxNumerical(0, 1, MIN_MAX_SPLITS, Y, MAX); - double x = maxCurve.getXValue(tMax); - + return x; } - public double getMinY() - { + public double getMinY() { double min = 100000; - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); double current = curve.getMinY(); - if(current < min) + if (current < min) min = current; } return min; } - - public double getLengthByX(double pos) - { + + public double getLengthByX(double pos) { double length = 0; int index = findMatchingBezierSegment(pos); - if(index == -1) //Not within patch + if (index == -1) // Not within patch { return 0.0; } BezierCurve curve = mCurves.get(index); - + double t = curve.getTForX(pos, ONE); - length += curve.getLength(ZERO,t); - - for(int i = 0; i < index; i++) - { + length += curve.getLength(ZERO, t); + + for (int i = 0; i < index; i++) { curve = mCurves.get(i); - double currentLength = curve.getLength(); - + double currentLength = curve.getLength(); + length += currentLength; } - return length; } - public double getSByX(double pos) - { - return getLengthByX(pos)/getLength(); + public double getSByX(double pos) { + return getLengthByX(pos) / getLength(); } - - public Point2D.Double getPointByS(double s) - { - return getPointByCurveLength(s*getLength()); + + public Point2D.Double getPointByS(double s) { + return getPointByCurveLength(s * getLength()); } - - public Point2D.Double getPointByCurveLength(double curveLength) - { + + public Point2D.Double getPointByCurveLength(double curveLength) { double l = curveLength; double t = -1; - + BezierCurve curve = null; - - //Return endpoints if input curvelength is out of range - if(curveLength <= 0.0) - { + + // Return endpoints if input curvelength is out of range + if (curveLength <= 0.0) { curve = mCurves.get(0); - - return new Point2D.Double(curve.getXValue(ZERO), curve.getYValue(ZERO)); + + return new Point2D.Double(curve.getXValue(ZERO), + curve.getYValue(ZERO)); } - if(curveLength >= getLength()) - { - curve = mCurves.get(mCurves.size()-1); - - return new Point2D.Double(curve.getXValue(ONE), curve.getYValue(ONE)); + if (curveLength >= getLength()) { + curve = mCurves.get(mCurves.size() - 1); + + return new Point2D.Double(curve.getXValue(ONE), + curve.getYValue(ONE)); } - - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { curve = mCurves.get(i); double currentLength = curve.getLength(); - if(l < currentLength) - { + if (l < currentLength) { t = curve.getTForLength(l); break; } - + l -= currentLength; } - + double x = curve.getXValue(t); double y = curve.getYValue(t); - return new Point2D.Double(x,y); + return new Point2D.Double(x, y); } - - - //Returns the first point found that is the given distance from - public Point2D.Double getPointByDistance(Point2D.Double point, double distance) - { + // Returns the first point found that is the given distance from + public Point2D.Double getPointByDistance(Point2D.Double point, + double distance) { Point2D.Double best = null; double best_error = 10000; - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); - + double t = curve.getTForDistance(point, distance); Point2D.Double current = curve.getValue(t); - double error = Math.abs(VecMath.getVecLength(point,current)); - - if(error < best_error) - { + double error = Math.abs(VecMath.getVecLength(point, current)); + + if (error < best_error) { best = current; best_error = error; } } - + return best; } - - public Point2D.Double getPointByLineIntersection(Point2D.Double a, Point2D.Double b){ + + public Point2D.Double getPointByLineIntersection(Point2D.Double a, + Point2D.Double b) { return getPointByTT(getTTByLineIntersect(a, b)); } - public double getSByNormal(double angle) - { - return getSByTangent(angle - Math.PI/2.0); + public double getSByNormal(double angle) { + return getSByTangent(angle - Math.PI / 2.0); } - - public double getSByTangent(double angle) - { - return getLengthByTangent(angle)/getLength(); + + public double getSByTangent(double angle) { + return getLengthByTangent(angle) / getLength(); } - - public double getLengthByNormal(double angle) - { - return getLengthByTangent(angle - Math.PI/2.0)/getLength(); + + public double getLengthByNormal(double angle) { + return getLengthByTangent(angle - Math.PI / 2.0) / getLength(); } - public double getLengthByTangent(double angle) - { + public double getLengthByTangent(double angle) { double length = 0; double t = 0; - - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); - - synchronized(this) - { - double endAngle = curve.getTangent(ZERO); - double otherEndAngle = curve.getTangent(ONE); - - double initial_t = (angle-endAngle)/(otherEndAngle-endAngle); - if(initial_t < 0.0) - initial_t = 0.0; - if(initial_t > 1.0) - initial_t = 1.0; - double last_t = initial_t +0.1; - if(last_t > 1.0) - last_t -= 0.2; - - t = curve.getTForTangent2(angle,initial_t,last_t); - - double tAngle = curve.getTangent(t); - if(Math.abs(tAngle-angle) < ANGLE_TOLERANCE) - { - length += curve.getLength(ZERO,t); - break; - } - - length += curve.getLength(); + + double endAngle = curve.getTangent(ZERO); + double otherEndAngle = curve.getTangent(ONE); + + double initial_t = (angle - endAngle) / (otherEndAngle - endAngle); + if (initial_t < 0.0) + initial_t = 0.0; + if (initial_t > 1.0) + initial_t = 1.0; + double last_t = initial_t + 0.1; + if (last_t > 1.0) + last_t -= 0.2; + + t = curve.getTForTangent2(angle, initial_t, last_t); + + double tAngle = curve.getTangent(t); + if (Math.abs(tAngle - angle) < ANGLE_TOLERANCE) { + length += curve.getLength(ZERO, t); + break; } + length += curve.getLength(); + } return length; } - public double getSByNormalReverse(double angle) - { - return getSByTangentReverse(angle - Math.PI/2.0); + public double getSByNormalReverse(double angle) { + return getSByTangentReverse(angle - Math.PI / 2.0); } - - public double getSByNormalReverse(double angle, boolean useMinimumAngleOnSharpCorners) - { - return getSByTangentReverse(angle - Math.PI/2.0,useMinimumAngleOnSharpCorners); - } - + public double getSByNormalReverse(double angle, + boolean useMinimumAngleOnSharpCorners) { + return getSByTangentReverse(angle - Math.PI / 2.0, + useMinimumAngleOnSharpCorners); + } - public double getSByTangentReverse(double angle) - { - double s = getLengthByTangentReverse(angle)/getLength(); + public double getSByTangentReverse(double angle) { + double s = getLengthByTangentReverse(angle) / getLength(); s = MathUtils.clamp(s, ZERO, ONE); return s; } - - - public double getSByTangentReverse(double angle, boolean useMinimumAngleOnSharpCorners) - { - double s = getLengthByTangentReverse(angle, useMinimumAngleOnSharpCorners)/getLength(); + public double getSByTangentReverse(double angle, + boolean useMinimumAngleOnSharpCorners) { + double s = getLengthByTangentReverse(angle, + useMinimumAngleOnSharpCorners) / getLength(); s = MathUtils.clamp(s, ZERO, ONE); return s; } - - - public double getLengthByNormalReverse(double angle) - { - return getLengthByTangentReverse(angle - Math.PI/2.0)/getLength(); + public double getLengthByNormalReverse(double angle) { + return getLengthByTangentReverse(angle - Math.PI / 2.0) / getLength(); } - - public double getLengthByNormalReverse(double angle, boolean useMinimumAngleOnSharpCorners) - { - return getLengthByTangentReverse(angle - Math.PI/2.0, useMinimumAngleOnSharpCorners)/getLength(); + public double getLengthByNormalReverse(double angle, + boolean useMinimumAngleOnSharpCorners) { + return getLengthByTangentReverse(angle - Math.PI / 2.0, + useMinimumAngleOnSharpCorners) / getLength(); } - - public double getLengthByTangentReverse(double angle) - { + public double getLengthByTangentReverse(double angle) { return getLengthByTangentReverse(angle, true); } - - public double getLengthByTangentReverse(double targetAngle, boolean useMinimumAngleOnSharpCorners) - { -// System.out.printf("getLengthByTangentReverseScaled() targetAngle:%f\n", targetAngle/BezierBoard.DEG_TO_RAD); + public double getLengthByTangentReverse(double targetAngle, + boolean useMinimumAngleOnSharpCorners) { + // System.out.printf("getLengthByTangentReverseScaled() targetAngle:%f\n", + // targetAngle/BezierBoard.DEG_TO_RAD); double length = 0; double t = 0; @@ -718,279 +632,267 @@ public double getLengthByTangentReverse(double targetAngle, boolean useMinimumAn double minAngleError = 10000; double minErrorT = -1; int minAngleErrorSection = -1; - + boolean targetFound = false; - - int i; - for(i = mCurves.size()-1; i >= 0; i--) - { + + int i; + for (i = mCurves.size() - 1; i >= 0; i--) { BezierCurve curve = mCurves.get(i); - + double startAngle = curve.getTangent(ZERO); - double endAngle = curve.getTangent(ONE); -// System.out.printf("getLengthByTangentReverseScaled() StartAngle:%f EndAngle:%f TargetAngle:%f\n", startAngle/BezierBoard.DEG_TO_RAD +90.0, endAngle/BezierBoard.DEG_TO_RAD + 90.0, targetAngle/BezierBoard.DEG_TO_RAD +90.0); - if(startAngle >= targetAngle && endAngle <= targetAngle) - { -// System.out.printf("getLengthByTangentReverseScaled() Value should be in this span, StartAngle:%f EndAngle:%f TargetAngle:%f\n", startAngle/BezierBoard.DEG_TO_RAD +90.0, endAngle/BezierBoard.DEG_TO_RAD + 90.0, targetAngle/BezierBoard.DEG_TO_RAD +90.0); + double endAngle = curve.getTangent(ONE); + // System.out.printf("getLengthByTangentReverseScaled() StartAngle:%f EndAngle:%f TargetAngle:%f\n", + // startAngle/BezierBoard.DEG_TO_RAD +90.0, + // endAngle/BezierBoard.DEG_TO_RAD + 90.0, + // targetAngle/BezierBoard.DEG_TO_RAD +90.0); + if (startAngle >= targetAngle && endAngle <= targetAngle) { + // System.out.printf("getLengthByTangentReverseScaled() Value should be in this span, StartAngle:%f EndAngle:%f TargetAngle:%f\n", + // startAngle/BezierBoard.DEG_TO_RAD +90.0, + // endAngle/BezierBoard.DEG_TO_RAD + 90.0, + // targetAngle/BezierBoard.DEG_TO_RAD +90.0); } - // if(k1.mContinous == false) -// { - if(endAngle > targetAngle) - { -// System.out.printf("getLengthByTangentReverseScaled() i:%d, endAngle > targetAngle endAngle:%f targetAngle:%f\n",i, endAngle/BezierBoard.DEG_TO_RAD, targetAngle/BezierBoard.DEG_TO_RAD); - if(useMinimumAngleOnSharpCorners == true) - { - i += 1; -// System.out.printf("getLengthByTangentReverseScaled() Target found by endAngle(%f) > targetAngle(%f) with use minimun angle on shape corner\n", endAngle/BezierBoard.DEG_TO_RAD+90.0, targetAngle/BezierBoard.DEG_TO_RAD+90.0); - } - else - { - length = curve.getLength(ZERO, ONE-.05); -// System.out.printf("getLengthByTangentReverseScaled() Target found by endAngle(%f) > targetAngle(%f)\n", endAngle/BezierBoard.DEG_TO_RAD+90.0, targetAngle/BezierBoard.DEG_TO_RAD+90.0); - } - targetFound = true; - break; + // if(k1.mContinous == false) + // { + if (endAngle > targetAngle) { + // System.out.printf("getLengthByTangentReverseScaled() i:%d, endAngle > targetAngle endAngle:%f targetAngle:%f\n",i, + // endAngle/BezierBoard.DEG_TO_RAD, + // targetAngle/BezierBoard.DEG_TO_RAD); + if (useMinimumAngleOnSharpCorners == true) { + i += 1; + // System.out.printf("getLengthByTangentReverseScaled() Target found by endAngle(%f) > targetAngle(%f) with use minimun angle on shape corner\n", + // endAngle/BezierBoard.DEG_TO_RAD+90.0, + // targetAngle/BezierBoard.DEG_TO_RAD+90.0); + } else { + length = curve.getLength(ZERO, ONE - .05); + // System.out.printf("getLengthByTangentReverseScaled() Target found by endAngle(%f) > targetAngle(%f)\n", + // endAngle/BezierBoard.DEG_TO_RAD+90.0, + // targetAngle/BezierBoard.DEG_TO_RAD+90.0); } -// } - -// t = getTForTangent(angle,ZERO,ONE, ANGLE_SPLITS); - double initial_t = (targetAngle-startAngle)/(endAngle-startAngle); - if(initial_t < 0.0) + targetFound = true; + break; + } + // } + + // t = getTForTangent(angle,ZERO,ONE, ANGLE_SPLITS); + double initial_t = (targetAngle - startAngle) + / (endAngle - startAngle); + if (initial_t < 0.0) initial_t = 0.0; - if(initial_t > 1.0) + if (initial_t > 1.0) initial_t = 1.0; - double last_t = initial_t +0.1; - if(last_t > 1.0) + double last_t = initial_t + 0.1; + if (last_t > 1.0) last_t -= 0.2; - -// System.out.printf("getLengthByTangentReverseScaled() i:%d startAngle:%f end_angle:%f initial_t:%f last_t:%f\n",i, startAngle/BezierBoard.DEG_TO_RAD, endAngle/BezierBoard.DEG_TO_RAD, initial_t, last_t); - - t = curve.getTForTangent2(targetAngle,initial_t,last_t); + + // System.out.printf("getLengthByTangentReverseScaled() i:%d startAngle:%f end_angle:%f initial_t:%f last_t:%f\n",i, + // startAngle/BezierBoard.DEG_TO_RAD, + // endAngle/BezierBoard.DEG_TO_RAD, initial_t, last_t); + + t = curve.getTForTangent2(targetAngle, initial_t, last_t); double tAngle = curve.getTangent(t); - double angleError = Math.abs(tAngle-targetAngle); - if(minAngleError > angleError) - { + double angleError = Math.abs(tAngle - targetAngle); + if (minAngleError > angleError) { minAngleError = angleError; minErrorT = t; minAngleErrorSection = i; - } - if(angleError <= ANGLE_TOLERANCE) - { - length = curve.getLength(ZERO,t); + } + if (angleError <= ANGLE_TOLERANCE) { + length = curve.getLength(ZERO, t); targetFound = true; -// System.out.printf("getLengthByTangentReverseScaled() Target found by matching angle: %f, error: %f\n", tAngle/BezierBoard.DEG_TO_RAD+90.0, angleError/BezierBoard.DEG_TO_RAD); + // System.out.printf("getLengthByTangentReverseScaled() Target found by matching angle: %f, error: %f\n", + // tAngle/BezierBoard.DEG_TO_RAD+90.0, + // angleError/BezierBoard.DEG_TO_RAD); break; + } else if (startAngle >= targetAngle && endAngle <= targetAngle) { + // System.out.printf("getLengthByTangentReverseScaled() Value should be in this span but error is too large, StartAngle:%f EndAngle:%f Target: %f Returned: %f t:%f\n", + // startAngle/BezierBoard.DEG_TO_RAD +90.0, + // endAngle/BezierBoard.DEG_TO_RAD +90.0, + // targetAngle/BezierBoard.DEG_TO_RAD +90.0, + // tAngle/BezierBoard.DEG_TO_RAD+90.0, t); + t = curve.getTForTangent2(targetAngle, initial_t, last_t); } - else if(startAngle >= targetAngle && endAngle <= targetAngle) - { -// System.out.printf("getLengthByTangentReverseScaled() Value should be in this span but error is too large, StartAngle:%f EndAngle:%f Target: %f Returned: %f t:%f\n", startAngle/BezierBoard.DEG_TO_RAD +90.0, endAngle/BezierBoard.DEG_TO_RAD +90.0, targetAngle/BezierBoard.DEG_TO_RAD +90.0, tAngle/BezierBoard.DEG_TO_RAD+90.0, t); - t = curve.getTForTangent2(targetAngle,initial_t,last_t); - } - + } - if(targetFound == false && minAngleErrorSection != -1) - { - //Use the nearest target + if (targetFound == false && minAngleErrorSection != -1) { + // Use the nearest target BezierCurve curve = mCurves.get(minAngleErrorSection); - + length = curve.getLength(ZERO, minErrorT); } - length += getLengthByControlPointIndex(0,i); - - //DEBUG sanity check + length += getLengthByControlPointIndex(0, i); + + // DEBUG sanity check double tangent = getTangentByCurveLength(length); - if(Math.abs(tangent - targetAngle) > 0.5 && targetFound) - { -// System.out.printf("getLengthByTangentReverseScaled() getTangentByCurveLength() returned different angle. Target: %f Returned: %f length:%f curveLength:%f\n", targetAngle/BezierBoard.DEG_TO_RAD +90.0, tangent/BezierBoard.DEG_TO_RAD + 90.0, length, lengthScaled(scaleX, scaleY)); + if (Math.abs(tangent - targetAngle) > 0.5 && targetFound) { + // System.out.printf("getLengthByTangentReverseScaled() getTangentByCurveLength() returned different angle. Target: %f Returned: %f length:%f curveLength:%f\n", + // targetAngle/BezierBoard.DEG_TO_RAD +90.0, + // tangent/BezierBoard.DEG_TO_RAD + 90.0, length, + // lengthScaled(scaleX, scaleY)); targetFound = !targetFound; } - + return length; } - - public double getLengthByControlPointIndex(int startIndex, int endIndex) - { + public double getLengthByControlPointIndex(int startIndex, int endIndex) { double length = 0; - - for(int i = startIndex; i < endIndex; i++) - { + + for (int i = startIndex; i < endIndex; i++) { BezierCurve curve = mCurves.get(i); - + length += curve.getLength(); } return length; } - - public double getNormalAngle(double pos) - { - return getTangentAt(pos) + Math.PI/2.0; + public double getNormalAngle(double pos) { + return getTangentAt(pos) - Math.PI / 2.0; } - public Point2D.Double getNormalAt(double pos) - { + public Point2D.Double getNormalAt(double pos) { double angle = getNormalAngle(pos); - + double x = Math.sin(angle); double y = Math.cos(angle); - - return new Point2D.Double(x,y); + + return new Point2D.Double(x, y); } - - public double getNormalByS(double s) - { - return getNormalByCurveLength(s*getLength()); + + public double getNormalByS(double s) { + return getNormalByCurveLength(s * getLength()); } - - public double getNormalByCurveLength(double curveLength) - { - return getTangentByCurveLength(curveLength) + Math.PI/2.0; + + public double getNormalByCurveLength(double curveLength) { + return getTangentByCurveLength(curveLength) + Math.PI / 2.0; } - public double getCurvatureByS(double s) - { - return getCurvatureByCurveLength(s*getLength()); + public double getCurvatureByS(double s) { + return getCurvatureByCurveLength(s * getLength()); } - public double getCurvatureByCurveLength(double curveLength) - { + public double getCurvatureByCurveLength(double curveLength) { double left = curveLength; double t = -1; - - if(curveLength <= 0.0) - { + + if (curveLength <= 0.0) { return 0.0; } - - if(curveLength >= getLength()) - { + + if (curveLength >= getLength()) { return 0.0; } - + BezierCurve curve = null; - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { curve = mCurves.get(i); - + double currentLength = curve.getLength(); - - if(left < currentLength) - { + + if (left < currentLength) { break; } - + left -= currentLength; } - + t = curve.getTForLength(left); double curvature = curve.getCurvature(t); - + return curvature; } - - public double getTangentAt(double pos) - { + public double getTangentAt(double pos) { int index = findMatchingBezierSegment(pos); - if(index == -1) - { + if (index == -1) { return 0.0; } - - BezierCurve curve = mCurves.get(index); + + BezierCurve curve = mCurves.get(index); return curve.getTangentAt(pos); } - - public double getTangentByS(double s) - { - return getTangentByCurveLength(s*getLength()); + public double getTangentByS(double s) { + return getTangentByCurveLength(s * getLength()); } - - public double getTangentByCurveLength(double curveLength) - { + + public double getTangentByCurveLength(double curveLength) { double l = curveLength; double t = -1; - + BezierCurve curve = null; - - for(int i = 0; i < mCurves.size(); i++) - { + + for (int i = 0; i < mCurves.size(); i++) { curve = mCurves.get(i); double currentLength = curve.getLength(); - if(l < currentLength) - { + if (l < currentLength) { t = curve.getTForLength(l); break; } - + l -= currentLength; } - + return curve.getTangent(t); } - - public double getIntegral(double a, double b, int splits) //Numerical integration using composite simpsons rule + public double getIntegral(double a, double b, int splits) // Numerical + // integration + // using + // composite + // simpsons rule { - MathUtils.Function deckFunc = new MathUtils.Function(){public double f(double x){return getValueAt(x);}}; - - double result = MathUtils.Integral.getIntegral(deckFunc, a, b, splits); + MathUtils.Function deckFunc = new MathUtils.Function() { + public double f(double x) { + return getValueAt(x); + } + }; + + double result = MathUtils.Integral.getIntegral(deckFunc, a, b, splits); return result; } - - public double getLength() - { + public double getLength() { double length = 0; - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); length += curve.getLength(); } - + return length; } - - public void scale(double verticalScale, double horizontalScale) - { - for(int i = 0; i < mCurves.size(); i++) - { - if(i == 0) - { + public void scale(double verticalScale, double horizontalScale) { + for (int i = 0; i < mCurves.size(); i++) { + if (i == 0) { BezierKnot startKnot = mCurves.get(i).getStartKnot(); - startKnot.scale(horizontalScale, verticalScale); + startKnot.scale(horizontalScale, verticalScale); } BezierKnot endKnot = mCurves.get(i).getEndKnot(); - if(endKnot != null) - { + if (endKnot != null) { endKnot.scale(horizontalScale, verticalScale); } } } - public int getSplitControlPoint(Point2D.Double nearPoint, BezierKnot returned) - { + public int getSplitControlPoint(Point2D.Double nearPoint, + BezierKnot returned) { double nearestDist = 100000000; int index = 0; double t = 0; - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); double tc = curve.getClosestT(nearPoint); @@ -999,8 +901,7 @@ public int getSplitControlPoint(Point2D.Double nearPoint, BezierKnot returned) double y = curve.getYValue(tc); double dist = VecMath.getVecLength(x, y, nearPoint.x, nearPoint.y); - if(nearestDist > dist) - { + if (nearestDist > dist) { nearestDist = dist; index = i; t = tc; @@ -1011,18 +912,16 @@ public int getSplitControlPoint(Point2D.Double nearPoint, BezierKnot returned) BezierCurve curve = mCurves.get(index); returned.set(curve.getSplitControlPoint(t)); - return index+1; //Insertion point + return index + 1; // Insertion point } - public double getDistanceToPoint(Point2D.Double point) - { + public double getDistanceToPoint(Point2D.Double point) { double nearestDist = 100000000; -// int index = 0; -// double t = 0; + // int index = 0; + // double t = 0; - for(int i = 0; i < mCurves.size(); i++) - { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); double tc = curve.getClosestT(point); @@ -1031,105 +930,88 @@ public double getDistanceToPoint(Point2D.Double point) double y = curve.getYValue(tc); double dist = VecMath.getVecLength(x, y, point.x, point.y); - if(nearestDist > dist) - { + if (nearestDist > dist) { nearestDist = dist; -// index = i; -// t = tc; + // index = i; + // t = tc; } } - return nearestDist; //Insertion point + return nearestDist; // Insertion point } - int findMatchingBezierSegment(double pos) - { + int findMatchingBezierSegment(double pos) { int result = findMatchingBezierSegmentSimple(pos); - if(result < 0) - { + if (result < 0) { result = findMatchingBezierSegmentMinMax(pos); } - + return result; } - int findMatchingBezierSegmentSimple(double pos) - { - for(int i = 0; i < mCurves.size(); i++) - { + int findMatchingBezierSegmentSimple(double pos) { + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); double lx = curve.getStartKnot().getEndPoint().x; - double ux = curve.getEndKnot().getEndPoint().x; - if(lx <= pos && ux >= pos) - { + double ux = curve.getEndKnot().getEndPoint().x; + if (lx <= pos && ux >= pos) { return i; } } return -1; } - int findMatchingBezierSegmentMinMax(double pos) - { - //Didn't find any matching segment + int findMatchingBezierSegmentMinMax(double pos) { + // Didn't find any matching segment - //Iterate through all segments and see if we're within max/min x value - for(int i = 0; i < mCurves.size(); i++) - { + // Iterate through all segments and see if we're within max/min x value + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); double lx = curve.getMinMaxNumerical(X, MIN); double ux = curve.getMinMaxNumerical(X, MAX); - if((lx <= pos && ux >= pos) || (ux <= pos && lx >= pos)) - { + if ((lx <= pos && ux >= pos) || (ux <= pos && lx >= pos)) { return i; } } return -1; } - - int findMatchingBezierSegmentReverse(double pos) - { + + int findMatchingBezierSegmentReverse(double pos) { int result = findMatchingBezierSegmentSimpleReverse(pos); - if(result < 0) - { + if (result < 0) { result = findMatchingBezierSegmentMinMaxReverse(pos); } - return result; + return result; } - - int findMatchingBezierSegmentSimpleReverse(double pos) - { + + int findMatchingBezierSegmentSimpleReverse(double pos) { int index = -1; - for(int i = mCurves.size()-1; i >= 0 ; i--) - { + for (int i = mCurves.size() - 1; i >= 0; i--) { BezierCurve curve = mCurves.get(i); double lx = curve.getStartKnot().getEndPoint().x; - double ux = curve.getEndKnot().getEndPoint().x; - if((lx <= pos && ux >= pos ) || (ux <= pos && lx >= pos )) - { + double ux = curve.getEndKnot().getEndPoint().x; + if ((lx <= pos && ux >= pos) || (ux <= pos && lx >= pos)) { return i; } } return -1; } - int findMatchingBezierSegmentMinMaxReverse(double pos) - { - //Iterate through all segments and see if we're within max/min x value - for(int i = mCurves.size()-1; i >= 0 ; i--) - { + int findMatchingBezierSegmentMinMaxReverse(double pos) { + // Iterate through all segments and see if we're within max/min x value + for (int i = mCurves.size() - 1; i >= 0; i--) { BezierCurve curve = mCurves.get(i); double lx = curve.getMinMaxNumerical(X, MIN); double ux = curve.getMinMaxNumerical(X, MAX); - if(lx <= pos && ux >= pos) - { + if (lx <= pos && ux >= pos) { return i; } @@ -1137,105 +1019,143 @@ int findMatchingBezierSegmentMinMaxReverse(double pos) return -1; } - public BezierKnot findBestMatch(Point2D.Double brdPos) - { + public BezierKnot findBestMatch(Point2D.Double brdPos) { BezierKnot bestMatch = null; - mBestMatchPointIndex = -1; + int bestMatchPointIndex = -1; double bestMatchDistance = Double.MAX_VALUE; - - for(int i = 0; i < mCurves.size(); i++) - { + + for (int i = 0; i < mCurves.size(); i++) { BezierCurve curve = mCurves.get(i); - + BezierKnot startKnot = curve.getStartKnot(); BezierKnot endKnot = curve.getEndKnot(); - - if(endKnot == null) //Incomplete curve, must be at end so break out + + if (endKnot == null) // Incomplete curve, must be at end so break + // out break; - //Check tangent to next for startknot - double distance = (double)brdPos.distance(startKnot.getTangentToNext()); - if(distance < bestMatchDistance) - { + // Check tangent to next for startknot + double distance = (double) brdPos.distance(startKnot + .getTangentToNext()); + if (distance < bestMatchDistance) { bestMatch = startKnot; - mBestMatchPointIndex = BezierKnot.NEXT_TANGENT; + bestMatchPointIndex = BezierKnot.NEXT_TANGENT; bestMatchDistance = distance; } - - //Check tangent to prev for endknot - distance = (double)brdPos.distance(endKnot.getTangentToPrev()); - if(distance < bestMatchDistance) - { + + // Check tangent to prev for endknot + distance = (double) brdPos.distance(endKnot.getTangentToPrev()); + if (distance < bestMatchDistance) { bestMatch = endKnot; - mBestMatchPointIndex = BezierKnot.PREVIOUS_TANGENT; + bestMatchPointIndex = BezierKnot.PREVIOUS_TANGENT; bestMatchDistance = distance; } - - //Check endpoint for startknot - distance = (double)brdPos.distance(startKnot.getEndPoint()); - if(distance < bestMatchDistance) - { + + // Check endpoint for startknot + distance = (double) brdPos.distance(startKnot.getEndPoint()); + if (distance < bestMatchDistance) { bestMatch = startKnot; - mBestMatchPointIndex = BezierKnot.END_POINT; + bestMatchPointIndex = BezierKnot.END_POINT; bestMatchDistance = distance; - } - - //Check tangent to prev for endknot - distance = (double)brdPos.distance(endKnot.getEndPoint()); - if(distance < bestMatchDistance) - { + } + + // Check tangent to prev for endknot + distance = (double) brdPos.distance(endKnot.getEndPoint()); + if (distance < bestMatchDistance) { bestMatch = endKnot; - mBestMatchPointIndex = BezierKnot.END_POINT; + bestMatchPointIndex = BezierKnot.END_POINT; bestMatchDistance = distance; } - + } return bestMatch; } - public int getBestMatchWhich() - { - return mBestMatchPointIndex; - } + public int getBestMatchWhich(Point2D.Double brdPos) { + BezierKnot bestMatch = null; + int bestMatchPointIndex = -1; + double bestMatchDistance = Double.MAX_VALUE; + + for (int i = 0; i < mCurves.size(); i++) { + BezierCurve curve = mCurves.get(i); + + BezierKnot startKnot = curve.getStartKnot(); + BezierKnot endKnot = curve.getEndKnot(); + + if (endKnot == null) // Incomplete curve, must be at end so break + // out + break; + + // Check tangent to next for startknot + double distance = (double) brdPos.distance(startKnot + .getTangentToNext()); + if (distance < bestMatchDistance) { + bestMatch = startKnot; + bestMatchPointIndex = BezierKnot.NEXT_TANGENT; + bestMatchDistance = distance; + } + + // Check tangent to prev for endknot + distance = (double) brdPos.distance(endKnot.getTangentToPrev()); + if (distance < bestMatchDistance) { + bestMatch = endKnot; + bestMatchPointIndex = BezierKnot.PREVIOUS_TANGENT; + bestMatchDistance = distance; + } + + // Check endpoint for startknot + distance = (double) brdPos.distance(startKnot.getEndPoint()); + if (distance < bestMatchDistance) { + bestMatch = startKnot; + bestMatchPointIndex = BezierKnot.END_POINT; + bestMatchDistance = distance; + } + // Check tangent to prev for endknot + distance = (double) brdPos.distance(endKnot.getEndPoint()); + if (distance < bestMatchDistance) { + bestMatch = endKnot; + bestMatchPointIndex = BezierKnot.END_POINT; + bestMatchDistance = distance; + } + } - public Object clone(){ + return bestMatchPointIndex; + } + + public Object clone() { BezierSpline spline = null; try { - spline = (BezierSpline)super.clone(); - } catch(CloneNotSupportedException e) { - System.out.println("Exception in BezierSpline::clone(): " + e.toString()); + spline = (BezierSpline) super.clone(); + } catch (CloneNotSupportedException e) { + System.out.println("Exception in BezierSpline::clone(): " + + e.toString()); throw new Error("CloneNotSupportedException in BrdCommand"); } spline.mCurves = new ArrayList(); - for(int i = 0; i < this.getNrOfControlPoints(); i++) - { - spline.append((BezierKnot)this.getControlPoint(i).clone()); + for (int i = 0; i < this.getNrOfControlPoints(); i++) { + spline.append((BezierKnot) this.getControlPoint(i).clone()); } return spline; } - public String toString() - { + public String toString() { String string = new String(); - for(int i = 0; i < this.getNrOfControlPoints(); i++) - { - if(string.length() > 0) + for (int i = 0; i < this.getNrOfControlPoints(); i++) { + if (string.length() > 0) string.concat(";"); string.concat(this.getControlPoint(i).toString()); } - + return string; } - public void fromString(String string) - { + public void fromString(String string) { String[] values = string.split(";"); - for(int i = 0; i < values.length; i++) - { + for (int i = 0; i < values.length; i++) { BezierKnot point = new BezierKnot(); point.fromString(values[i]); this.append(point); @@ -1243,4 +1163,3 @@ public void fromString(String string) } } - diff --git a/cadcore/Least Squares Bezier Fit _ Jim Herold, Computer Scientist.pdf b/cadcore/Least Squares Bezier Fit _ Jim Herold, Computer Scientist.pdf new file mode 100644 index 0000000..8f10b3f Binary files /dev/null and b/cadcore/Least Squares Bezier Fit _ Jim Herold, Computer Scientist.pdf differ diff --git a/cadcore/MathUtils.java b/cadcore/MathUtils.java index b53b31e..6598431 100644 --- a/cadcore/MathUtils.java +++ b/cadcore/MathUtils.java @@ -64,7 +64,7 @@ public static double clamp(double value, double minLimit, double maxLimit) public static class RootFinder { - static public double ROOTFINER_VALUE_TOLERANCE = 0.001; + static public double ROOTFINER_VALUE_TOLERANCE = 0.005; static public double getRoot(Function function, double targetValue) { @@ -76,15 +76,31 @@ static public double getRoot(Function function, double targetValue, double minLi double x = SecantRootFinder.getRoot(function, targetValue, minLimit, maxLimit); //Sanity check - if(Math.abs(function.f(x)-targetValue) > ROOTFINER_VALUE_TOLERANCE) + double sec_actualValue = function.f(x); + if(Math.abs(sec_actualValue-targetValue) > ROOTFINER_VALUE_TOLERANCE) { // System.out.printf("getRoot(): SecantRootFinder failed, x:%f, value:%f, targetValue:%f, error: %f\n", x, function.f(x), targetValue, function.f(x)-targetValue); - x = BisectRootFinder.getRoot(function, targetValue, minLimit, maxLimit); + double bis_x = BisectRootFinder.getRoot(function, targetValue, minLimit, maxLimit); - if(Math.abs(function.f(x)-targetValue) > ROOTFINER_VALUE_TOLERANCE) + double bis_actualValue = function.f(x); + if(Math.abs(bis_actualValue-targetValue) > ROOTFINER_VALUE_TOLERANCE) + { +// System.out.printf("getRoot(): BisectRootFinder failed, x:%f, value:%f, targetValue:%f, error: %f\n", x, function.f(x), targetValue, function.f(x)-targetValue); + + if(Math.abs(bis_actualValue-targetValue) < Math.abs(sec_actualValue-targetValue) ) //Test which is closest and return best result + { + x = bis_x; +// System.out.printf("getRoot(): Best result with bisect, x:%f, value:%f, targetValue:%f, error: %f\n", x, bis_actualValue, targetValue, bis_actualValue-targetValue); + } + else + { +// System.out.printf("getRoot(): Best result with secant, x:%f, value:%f, targetValue:%f, error: %f\n", x, sec_actualValue, targetValue, sec_actualValue-targetValue); + } + } + else { -// System.out.printf("getRoot(): BisectRootFinder failed, x:%f, value:%f, targetValue:%f, error: %f\n", x, function.f(x), targetValue, function.f(x)-targetValue); + x = bis_x; } } @@ -359,4 +375,54 @@ static public double getCurveLength(FunctionXY function, double min, double max) return getCurveLength(function, min, max, 10); } } + + static public double[][] cross_product(double[][] m1, double[][] m2) + { + double[][] m=new double[3][3]; + + m[0][0]=m1[0][0]*m2[0][0]+m1[1][0]*m2[0][1]+m1[2][0]*m2[0][2]; + m[1][0]=m1[0][0]*m2[1][0]+m1[1][0]*m2[1][1]+m1[2][0]*m2[1][2]; + m[2][0]=m1[0][0]*m2[2][0]+m1[1][0]*m2[2][1]+m1[2][0]*m2[2][2]; + + m[0][1]=m1[0][1]*m2[0][0]+m1[1][1]*m2[0][1]+m1[2][1]*m2[0][2]; + m[1][1]=m1[0][1]*m2[1][0]+m1[1][1]*m2[1][1]+m1[2][1]*m2[1][2]; + m[2][1]=m1[0][1]*m2[2][0]+m1[1][1]*m2[2][1]+m1[2][1]*m2[2][2]; + + m[0][2]=m1[0][2]*m2[0][0]+m1[1][2]*m2[0][1]+m1[2][2]*m2[0][2]; + m[1][2]=m1[0][2]*m2[1][0]+m1[1][2]*m2[1][1]+m1[2][2]*m2[1][2]; + m[2][2]=m1[0][2]*m2[2][0]+m1[1][2]*m2[2][1]+m1[2][2]*m2[2][2]; + + return m; + } + + static public double[][] invert(double[][] a) { + /* + * + * | a11 a12 a13 |-1 | a33a22-a32a23 -(a33a12-a32a13) a23a12-a22a13 | | + * a21 a22 a23 | = 1/DET(A) * | -(a33a21-a31a23) a33a11-a31a13 + * -(a23a11-a21a13) | | a31 a32 a33 | | a32a21-a31a22 -(a32a11-a31a12) + * a22a11-a21a12 | + * + * DET(A) = a11(a33a22-a32a23)-a21(a33a12-a32a13)+a31(a23a12-a22a13) + */ + + double det = a[0][0] * (a[2][2] * a[1][1] - a[2][1] * a[1][2]) + - a[1][0] * (a[2][2] * a[0][1] - a[2][1] * a[0][2]) + a[2][0] + * (a[1][2] * a[0][1] - a[1][1] * a[0][2]); + + double[][] b = { + { (a[2][2] * a[1][1] - a[2][1] * a[1][2]) / det, + -(a[2][2] * a[0][1] - a[2][1] * a[0][2]) / det, + (a[1][2] * a[0][1] - a[1][1] * a[0][2]) / det }, + { -(a[2][2] * a[1][0] - a[2][0] * a[1][2]) / det, + (a[2][2] * a[0][0] - a[2][0] * a[0][2]) / det, + -(a[1][2] * a[0][0] - a[1][0] * a[0][2]) / det }, + { (a[2][1] * a[1][0] - a[2][0] * a[1][1]) / det, + -(a[2][1] * a[0][0] - a[2][0] * a[0][1]) / det, + (a[1][1] * a[0][0] - a[1][0] * a[0][1]) / det } }; + + return b; + + } + } diff --git a/cadcore/NurbsSurface.java b/cadcore/NurbsSurface.java index 53b4ae5..9371f72 100644 --- a/cadcore/NurbsSurface.java +++ b/cadcore/NurbsSurface.java @@ -956,7 +956,6 @@ public void transform(double[][] m, double[] t) double tx,ty,tz; //transform control points - System.out.println("Transforming surface"); for(i=0;iv[points_per_segment-1]-step3) t=v[points_per_segment-1]-step3; - //---end fix + //---end fix double t1=t-step2/2; double t2=t+step2/2; diff --git a/cadcore/UnitUtils.java b/cadcore/UnitUtils.java index 9dcce6b..a4791e1 100644 --- a/cadcore/UnitUtils.java +++ b/cadcore/UnitUtils.java @@ -1,7 +1,10 @@ package cadcore; +import com.sun.j3d.utils.shader.StringIO; + import boardcad.i18n.LanguageResource; + public class UnitUtils { static public final int CENTIMETERS = 0; @@ -60,7 +63,7 @@ public static double convertInputStringToInternalLengthUnit(String string) double value = 0; try{ - string = string.replace(",", "."); + string = string.replace(',', '.'); if(string.contains("\'") || string.contains("\"") ) { if(string.contains("\'")) @@ -436,17 +439,8 @@ public static String convertLengthToUnit(double value, boolean useLargeUnits, in format = format.concat("%1$d'"); } - if(inches >= 0.01) - { - format = format.concat("%2$." + mNrOfDecimals + "f"); - } - - if(format.length() == 0 || format.equalsIgnoreCase("-")) - { - format = format.concat("0"); - } - format = format.concat("\""); + format = format.concat("%2$." + mNrOfDecimals + "f\""); return String.format(format, feet, inches); } diff --git a/cadcore/VecMath.java b/cadcore/VecMath.java index 45f4103..780146d 100644 --- a/cadcore/VecMath.java +++ b/cadcore/VecMath.java @@ -38,6 +38,12 @@ public static void scaleVector(Point2D.Double p0, double v) { p0.setLocation(p0.x*v,p0.y*v); } + + public static void normalizeVector(Point2D.Double p0) + { + + scaleVector(p0, 1.0/getVecLength(p0)); + } static double getVecDot(Point2D.Double p0, Point2D.Double p1) { diff --git a/gluegen-rt-natives-linux-amd64.jar b/gluegen-rt-natives-linux-amd64.jar index 15c8a2c..a2466f4 100644 Binary files a/gluegen-rt-natives-linux-amd64.jar and b/gluegen-rt-natives-linux-amd64.jar differ diff --git a/gluegen-rt-natives-linux-i586.jar b/gluegen-rt-natives-linux-i586.jar index e8db01f..914a259 100644 Binary files a/gluegen-rt-natives-linux-i586.jar and b/gluegen-rt-natives-linux-i586.jar differ diff --git a/gluegen-rt-natives-macosx-universal.jar b/gluegen-rt-natives-macosx-universal.jar index 0fb2734..15df5e8 100644 Binary files a/gluegen-rt-natives-macosx-universal.jar and b/gluegen-rt-natives-macosx-universal.jar differ diff --git a/gluegen-rt-natives-windows-amd64.jar b/gluegen-rt-natives-windows-amd64.jar index 5f97e47..517fb84 100644 Binary files a/gluegen-rt-natives-windows-amd64.jar and b/gluegen-rt-natives-windows-amd64.jar differ diff --git a/gluegen-rt-natives-windows-i586.jar b/gluegen-rt-natives-windows-i586.jar index a9e84f1..1c393b7 100644 Binary files a/gluegen-rt-natives-windows-i586.jar and b/gluegen-rt-natives-windows-i586.jar differ diff --git a/gluegen-rt.jar b/gluegen-rt.jar index 472b0b3..742fdb2 100644 Binary files a/gluegen-rt.jar and b/gluegen-rt.jar differ diff --git a/j3dcore.jar b/j3dcore.jar index 78e5dcc..4d5f158 100644 Binary files a/j3dcore.jar and b/j3dcore.jar differ diff --git a/j3dutils.jar b/j3dutils.jar index 7713946..d82b279 100644 Binary files a/j3dutils.jar and b/j3dutils.jar differ diff --git a/jogl-all-natives-linux-amd64.jar b/jogl-all-natives-linux-amd64.jar index d3b65e6..e57b8c7 100644 Binary files a/jogl-all-natives-linux-amd64.jar and b/jogl-all-natives-linux-amd64.jar differ diff --git a/jogl-all-natives-linux-i586.jar b/jogl-all-natives-linux-i586.jar index 1243b09..88a27ce 100644 Binary files a/jogl-all-natives-linux-i586.jar and b/jogl-all-natives-linux-i586.jar differ diff --git a/jogl-all-natives-macosx-universal.jar b/jogl-all-natives-macosx-universal.jar index 4cb7746..c65ea99 100644 Binary files a/jogl-all-natives-macosx-universal.jar and b/jogl-all-natives-macosx-universal.jar differ diff --git a/jogl-all-natives-windows-amd64.jar b/jogl-all-natives-windows-amd64.jar index f1d5c37..9577bf1 100644 Binary files a/jogl-all-natives-windows-amd64.jar and b/jogl-all-natives-windows-amd64.jar differ diff --git a/jogl-all-natives-windows-i586.jar b/jogl-all-natives-windows-i586.jar index c7bf521..4439f1d 100644 Binary files a/jogl-all-natives-windows-i586.jar and b/jogl-all-natives-windows-i586.jar differ diff --git a/jogl-all.jar b/jogl-all.jar index 03a6e49..f73174f 100644 Binary files a/jogl-all.jar and b/jogl-all.jar differ diff --git a/ujmp/ujmp-complete-0.3.0.jar b/ujmp/ujmp-complete-0.3.0.jar new file mode 100644 index 0000000..a04cd61 Binary files /dev/null and b/ujmp/ujmp-complete-0.3.0.jar differ diff --git a/vecmath.jar b/vecmath.jar index aa86d84..f8994cb 100644 Binary files a/vecmath.jar and b/vecmath.jar differ