diff options
Diffstat (limited to 'js/tools/PenTool.js')
-rwxr-xr-x | js/tools/PenTool.js | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 02367328..6897c003 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js | |||
@@ -15,6 +15,9 @@ var TagTool = require("js/tools/TagTool").TagTool; | |||
15 | var ElementController = require("js/controllers/elements/element-controller").ElementController; | 15 | var ElementController = require("js/controllers/elements/element-controller").ElementController; |
16 | var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; | 16 | var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; |
17 | 17 | ||
18 | var AnchorPoint = require("js/lib/geom/anchor-point").AnchorPoint; | ||
19 | var SubPath = require("js/lib/geom/sub-path").SubPath; | ||
20 | |||
18 | //todo remove this global var | 21 | //todo remove this global var |
19 | var g_DoPenToolMouseMove = true; | 22 | var g_DoPenToolMouseMove = true; |
20 | 23 | ||
@@ -146,7 +149,7 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
146 | if (mouseDownPos) { | 149 | if (mouseDownPos) { |
147 | //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath | 150 | //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath |
148 | if (this._selectedSubpath === null) { | 151 | if (this._selectedSubpath === null) { |
149 | this._selectedSubpath = new GLSubpath(); | 152 | this._selectedSubpath = new SubPath(); |
150 | this._isNewPath = true; | 153 | this._isNewPath = true; |
151 | if (this._entryEditMode === this.ENTRY_SELECT_PATH){ | 154 | if (this._entryEditMode === this.ENTRY_SELECT_PATH){ |
152 | //this should not happen, as ENTRY_SELECT_PATH implies there was a selected subpath | 155 | //this should not happen, as ENTRY_SELECT_PATH implies there was a selected subpath |
@@ -212,13 +215,13 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
212 | this._penCanvas = null; | 215 | this._penCanvas = null; |
213 | this._penPlaneMat = null; | 216 | this._penPlaneMat = null; |
214 | this._snapTarget = null; | 217 | this._snapTarget = null; |
215 | this._selectedSubpath = new GLSubpath(); | 218 | this._selectedSubpath = new SubPath(); |
216 | this._isNewPath = true; | 219 | this._isNewPath = true; |
217 | } | 220 | } |
218 | 221 | ||
219 | //add an anchor point to end of the subpath, and make it the selected anchor point | 222 | //add an anchor point to end of the subpath, and make it the selected anchor point |
220 | if (!this._selectedSubpath.getIsClosed() || this._makeMultipleSubpaths) { | 223 | if (!this._selectedSubpath.getIsClosed() || this._makeMultipleSubpaths) { |
221 | this._selectedSubpath.addAnchor(new GLAnchorPoint()); | 224 | this._selectedSubpath.addAnchor(new AnchorPoint()); |
222 | var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); | 225 | var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); |
223 | newAnchor.setPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); | 226 | newAnchor.setPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); |
224 | newAnchor.setPrevPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); | 227 | newAnchor.setPrevPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); |
@@ -231,7 +234,7 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
231 | if (this._isPickedEndPointInSelectPathMode){ | 234 | if (this._isPickedEndPointInSelectPathMode){ |
232 | //TODO clean up this code...very similar to the code block above | 235 | //TODO clean up this code...very similar to the code block above |
233 | if (!this._selectedSubpath.getIsClosed()) { | 236 | if (!this._selectedSubpath.getIsClosed()) { |
234 | this._selectedSubpath.addAnchor(new GLAnchorPoint()); | 237 | this._selectedSubpath.addAnchor(new AnchorPoint()); |
235 | var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); | 238 | var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); |
236 | newAnchor.setPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); | 239 | newAnchor.setPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); |
237 | newAnchor.setPrevPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); | 240 | newAnchor.setPrevPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); |
@@ -399,7 +402,7 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
399 | var bboxMax = this._selectedSubpath.getBBoxMax(); | 402 | var bboxMax = this._selectedSubpath.getBBoxMax(); |
400 | var bboxWidth = bboxMax[0] - bboxMin[0]; | 403 | var bboxWidth = bboxMax[0] - bboxMin[0]; |
401 | var bboxHeight = bboxMax[1] - bboxMin[1]; | 404 | var bboxHeight = bboxMax[1] - bboxMin[1]; |
402 | var bboxMid = Vector.create([0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])]); | 405 | var bboxMid = [0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])]; |
403 | 406 | ||
404 | this._selectedSubpath.setCanvasX(bboxMid[0]); | 407 | this._selectedSubpath.setCanvasX(bboxMid[0]); |
405 | this._selectedSubpath.setCanvasY(bboxMid[1]); | 408 | this._selectedSubpath.setCanvasY(bboxMid[1]); |
@@ -648,7 +651,7 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
648 | var baseline = VecUtils.vecNormalize(3, baselineOrig); | 651 | var baseline = VecUtils.vecNormalize(3, baselineOrig); |
649 | var delta = VecUtils.vecSubtract(3, p2, p3); | 652 | var delta = VecUtils.vecSubtract(3, p2, p3); |
650 | //component of the delta along baseline | 653 | //component of the delta along baseline |
651 | var deltaB = Vector.create(baseline); | 654 | var deltaB = baseline; |
652 | VecUtils.vecScale(3, deltaB, VecUtils.vecDot(3, baseline, delta)); | 655 | VecUtils.vecScale(3, deltaB, VecUtils.vecDot(3, baseline, delta)); |
653 | //component of the delta orthogonal to baseline | 656 | //component of the delta orthogonal to baseline |
654 | var deltaO = VecUtils.vecSubtract(3, delta, deltaB); | 657 | var deltaO = VecUtils.vecSubtract(3, delta, deltaB); |
@@ -665,7 +668,7 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
665 | //if there is a selected anchor point | 668 | //if there is a selected anchor point |
666 | if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) { | 669 | if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) { |
667 | var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); | 670 | var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); |
668 | var pos = Vector.create([selAnchor.getPosX(), selAnchor.getPosY(), selAnchor.getPosZ()]); | 671 | var pos = [selAnchor.getPosX(), selAnchor.getPosY(), selAnchor.getPosZ()]; |
669 | var distToPrev = selAnchor.getPrevDistanceSq(pos[0], pos[1], pos[2]); | 672 | var distToPrev = selAnchor.getPrevDistanceSq(pos[0], pos[1], pos[2]); |
670 | var distToNext = selAnchor.getNextDistanceSq(pos[0], pos[1], pos[2]); | 673 | var distToNext = selAnchor.getNextDistanceSq(pos[0], pos[1], pos[2]); |
671 | var threshSq = 0; // 4 * this._PICK_POINT_RADIUS * this._PICK_POINT_RADIUS; | 674 | var threshSq = 0; // 4 * this._PICK_POINT_RADIUS * this._PICK_POINT_RADIUS; |
@@ -681,8 +684,8 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
681 | nextAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()+1); | 684 | nextAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()+1); |
682 | else | 685 | else |
683 | nextAnchor = this._selectedSubpath.getAnchor(0); | 686 | nextAnchor = this._selectedSubpath.getAnchor(0); |
684 | var nextAnchorPrev = Vector.create([nextAnchor.getPrevX(), nextAnchor.getPrevY(), nextAnchor.getPrevZ()]); | 687 | var nextAnchorPrev = [nextAnchor.getPrevX(), nextAnchor.getPrevY(), nextAnchor.getPrevZ()]; |
685 | var nextAnchorPos = Vector.create([nextAnchor.getPosX(), nextAnchor.getPosY(), nextAnchor.getPosZ()]) | 688 | var nextAnchorPos = [nextAnchor.getPosX(), nextAnchor.getPosY(), nextAnchor.getPosZ()]; |
686 | var newNext = this.BuildSecondCtrlPoint(pos, nextAnchorPrev, nextAnchorPos); | 689 | var newNext = this.BuildSecondCtrlPoint(pos, nextAnchorPrev, nextAnchorPos); |
687 | selAnchor.setNextPos(newNext[0], newNext[1], newNext[2]); | 690 | selAnchor.setNextPos(newNext[0], newNext[1], newNext[2]); |
688 | //check if the next is still not over the threshSq..if so, add a constant horizontal amount | 691 | //check if the next is still not over the threshSq..if so, add a constant horizontal amount |
@@ -698,8 +701,8 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
698 | prevAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()-1); | 701 | prevAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()-1); |
699 | else | 702 | else |
700 | prevAnchor = this._selectedSubpath.getAnchor(numAnchors-1); | 703 | prevAnchor = this._selectedSubpath.getAnchor(numAnchors-1); |
701 | var prevAnchorNext = Vector.create([prevAnchor.getNextX(), prevAnchor.getNextY(), prevAnchor.getNextZ()]); | 704 | var prevAnchorNext = [prevAnchor.getNextX(), prevAnchor.getNextY(), prevAnchor.getNextZ()]; |
702 | var prevAnchorPos = Vector.create([prevAnchor.getPosX(), prevAnchor.getPosY(), prevAnchor.getPosZ()]) | 705 | var prevAnchorPos = [prevAnchor.getPosX(), prevAnchor.getPosY(), prevAnchor.getPosZ()]; |
703 | var newPrev = this.BuildSecondCtrlPoint(pos, prevAnchorNext, prevAnchorPos); | 706 | var newPrev = this.BuildSecondCtrlPoint(pos, prevAnchorNext, prevAnchorPos); |
704 | selAnchor.setPrevPos(newPrev[0], newPrev[1], newPrev[2]); | 707 | selAnchor.setPrevPos(newPrev[0], newPrev[1], newPrev[2]); |
705 | //check if the prev is still not over the threshSq..if so, add a constant horizontal amount | 708 | //check if the prev is still not over the threshSq..if so, add a constant horizontal amount |