//OFFSETPATH TOOL
//___________________________________________________________________________________________________
if (getSketchTools().getCurrentTool() == SketchTools.DRAW_OFFSETPATH_TOOL) {
boolean skip = false;
Vec2D pointOnPlan = new Vec2D(mouseX, mouseY);
if (getCurrentShape() != null
&& getCurrentShape().getType() == SketchShape.OFFSET_SPLINE
&& getSketchTools().getMouseButton() == PConstants.RIGHT
&& !getCurrentShape().getClosed() && !skip) {
SketchSpline spline = (SketchSpline) getCurrentShape();
spline.getCentrePath().remove(spline.getCentrePath().getLast());
getCurrentShape().setClosed(true);
spline.offset();
skip = true;
}
if (getCurrentShape() != null
&& (getCurrentShape().getType() != SketchShape.OFFSET_SPLINE || getCurrentShape()
.getClosed())
&& getSketchTools().getMouseButton() == PConstants.LEFT
&& !skip) {
SketchSpline sketch = new SketchSpline(this);
sketch.setType(SketchShape.OFFSET_SPLINE);
sketch.autoSmooth = false;
sketch.setOffsetSize(this.getSketchTools().brush_dia);
sketch.setJoinType(SketchSpline.JOIN_ROUND);
sketch.setCap(getSketchTools().getCurrentCapType());
add(sketch);
}
if (getCurrentShape() == null
&& getSketchTools().getMouseButton() == PConstants.LEFT
&& !skip) {
SketchSpline sketch = new SketchSpline(this);
sketch.setType(SketchShape.OFFSET_SPLINE);
sketch.autoSmooth = false;
sketch.setJoinType(SketchSpline.JOIN_ROUND);
sketch.setOffsetSize(this.getSketchTools().brush_dia);
sketch.setCap(getSketchTools().getCurrentCapType());
add(sketch);
}
//add a point
if (getCurrentShape() != null
&& getCurrentShape().getType() == SketchShape.OFFSET_SPLINE
&& getSketchTools().getMouseButton() == PConstants.LEFT
&& !skip) {
getCurrentShape().add(
new SketchPoint(pointOnPlan.x, pointOnPlan.y));
getCurrentShape().add(
new SketchPoint(pointOnPlan.x + 10, pointOnPlan.y + 1));
}
}
//PATH TOOL
//___________________________________________________________________________________________________
if (getSketchTools().getCurrentTool() == SketchTools.DRAW_PATH_TOOL) {
boolean skip = false;
//Remove vertex!
if (!skip && (getSketchTools().getMouseButton() == PConstants.LEFT|| getSketchTools().getMouseButton() == PConstants.RIGHT)
&& getSketchTools().keyPressed
&& getSketchTools().keyCode == PConstants.CONTROL) {
Vec2D pointOnPlane = new Vec2D(mouseX, mouseY);
SketchPoint pathVert = getClosestPathVertex(pointOnPlane);
if (pathVert != null && pointOnPlane.distanceTo(pathVert) < SETTINGS_SKETCH.select_dia) {
removeVertex(pathVert);
skip = true;
}
}
//check to see if we are adding a new point to an existing path
if (!skip && (getSketchTools().getMouseButton() == PConstants.LEFT || getSketchTools().getMouseButton() == PConstants.RIGHT)
&& getSketchTools().keyPressed
&& getSketchTools().keyCode == PConstants.CONTROL) {
Vec2D pointOnPlane = new Vec2D(mouseX, mouseY);
if (addPointAlongPath(pointOnPlane.x, pointOnPlane.y))
skip = true;
}
Vec2D pointOnPlan = new Vec2D(mouseX, mouseY);
/*
if (getSketchTools().getMouseButton() == PConstants.RIGHT && !skip) {
SketchPoint pathVert = getClosestPathVertex(pointOnPlan);
if (pathVert != null
&& pointOnPlan.distanceTo(pathVert) < SETTINGS_SKETCH.select_dia) {
removeVertex(pathVert);
skip = true;
}
}
*/
if (getCurrentShape() != null
&& getCurrentShape().getType() == SketchShape.TYPE_PATH
&& getSketchTools().getMouseButton() == PConstants.LEFT
&& !skip) {
SketchPath sketchP = (SketchPath) getCurrentShape();
if (sketchP.getClosed()) {
SketchPath sketch = new SketchPath(this);
sketch.setType(SketchShape.TYPE_PATH);
add(sketch);
getCurrentShape().add(
new SketchPoint(pointOnPlan.x, pointOnPlan.y));
}
}
if (getCurrentShape() == null
|| getCurrentShape().getType() != SketchShape.TYPE_PATH
&& getSketchTools().getMouseButton() == PConstants.LEFT
&& !skip) {
SketchPath sketch = new SketchPath(this);
sketch.setType(SketchShape.TYPE_PATH);
sketch.setClosed(false);
add(sketch);
getCurrentShape().add(
new SketchPoint(pointOnPlan.x, pointOnPlan.y));
}
if (getCurrentShape().getType() == SketchShape.TYPE_PATH
&& getSketchTools().getMouseButton() == PConstants.LEFT
&& !skip) {
if (getCurrentShape().getLength() > 2) {
Vec2D firstPoint = (Vec2D) ((SketchPath) getCurrentShape())
.get(0);
Vec2D mousePos = new Vec2D(mouseX, mouseY);
//mousePos = GLOBAL.uiTools.getPointOnPlane(mousePos, getCurrentShape().getParentSketch().getOnSketchPlane().getPlane());
if (firstPoint.distanceTo(mousePos) < SETTINGS_SKETCH.MIN_CLOSE_SHAPE_DIST) {
SketchPath path = (SketchPath) getCurrentShape();
path.remove(path.getLast());