/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
</copyright> */
var ShapeTool = require("js/tools/ShapeTool").ShapeTool;
var ShapesController = require("js/controllers/elements/shapes-controller").ShapesController;
var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase;
var defaultEventManager = require("montage/core/event/event-manager").defaultEventManager;
var Montage = require("montage/core/core").Montage;
var NJUtils = require("js/lib/NJUtils").NJUtils;
var ElementMediator = require("js/mediators/element-mediator").ElementMediator;
var TagTool = require("js/tools/TagTool").TagTool;
var ElementController = require("js/controllers/elements/element-controller").ElementController;
var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager;
var ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils;
var AnchorPoint = require("js/lib/geom/anchor-point").AnchorPoint;
var SubPath = require("js/lib/geom/sub-path").SubPath;
exports.PenTool = Montage.create(ShapeTool, {
_toolID: { value: "penTool" },
_imageID: { value: "penToolImg" },
_toolImageClass: { value: "penToolUp" },
_selectedToolImageClass: { value: "penToolDown" },
_toolTipText: { value: "Pen Tool" },
_penView: { value: null, writable: true },
_selectedToolClass: { value: "penToolSpecificProperties" },
_penToolProperties: { enumerable: false, value: null, writable: true },
_parentNode: { enumerable: false, value: null, writable: true },
_toolsPropertiesContainer: { enumerable: false, value: null, writable: true },
//set this to true if you want to keep making subpaths after closing current subpath (debugging only...should always be true)
_makeMultipleSubpaths: { value: true, writable: true },
//set this to false if you don't want the mouse move handler being called when the mouse is not down (debugging only...should always be true)
_trackMouseMoveWhenUp: {value: true, writable: false},
//whether the user has held down the Alt key
_isAltDown: { value: false, writable: true },
//whether the user has held down the Esc key
_isEscapeDown: {value: false, writable: true },
//whether we have just started a new path (may set true in mousedown, and always set false in mouse up
//todo this seems to be unnecessary
_isNewPath: {value: false, writable: true},
//whether we have clicked one of the endpoints after entering the pen tool in ENTRY_SELECT_PATH edit mode
_isPickedEndPointInSelectPathMode: {value: false, writable: true},
//when the user wants to place a selected anchor point on top of another point, this is the target where the point will be placed
_snapTargetIndex: { value: -1, writable: true },
//index of the anchor point that the user has hovered over
_hoveredAnchorIndex: {value: -1, writable: true},
//whether or not we're using webgl for drawing (set to false until we have webgl-ready stroke and fill regions)
_useWebGL: {value: false, writable: false },
//the _selectedSubpath is the active subpath currently being edited
_selectedSubpath: { value: null, writable: true },
//the canvas for the selected subpath...this is grown or shrunk by the pen tool with the subpath (if the canvas was not already provided)
_selectedSubpathCanvas: { value: null, writable: true },
//the plane matrix for the first click...so the entire path is on the same plane
// todo this might be unnecessary as we can get this from element mediator (but that may be slow)
_selectedSubpathPlaneMat: { value: null, writable: true },
//the center of the subpath center in stageworld space
_selectedSubpathCanvasCenter: {value: null, writable: true},
//constants used for picking points --- todo: these should be user-settable parameters
_PICK_POINT_RADIUS: { value: 4, writable: false },
_DISPLAY_ANCHOR_RADIUS: { value: 5, writable: false },
_DISPLAY_SELECTED_ANCHOR_RADIUS: { value: 10, writable: false },
_DISPLAY_SELECTED_ANCHOR_PREV_RADIUS: { value: 2, writable: false },
_DISPLAY_SELECTED_ANCHOR_NEXT_RADIUS: { value: 2, writable: false },
//constants used for editing modes (can be OR-ed)
EDIT_NONE: { value: 0, writable: false },
EDIT_ANCHOR: { value: 1, writable: false },
EDIT_PREV: { value: 2, writable: false },
EDIT_NEXT: { value: 4, writable: false },
EDIT_PREV_NEXT: { value: 8, writable: false },
_editMode: { value: this.EDIT_NONE, writable: true },
//constants used for selection modes on entry to pen tool (mutually exclusive i.e. cannot be OR-ed)
ENTRY_SELECT_NONE: { value: 0, writable: false},
ENTRY_SELECT_CANVAS: { value: 1, writable: false},
ENTRY_SELECT_PATH: { value: 2, writable: false},
_entryEditMode: {value: this.ENTRY_SELECT_NONE, writable: true},
//constants used for determining whether a subtool has been selected (mutually exclusive i.e. cannot be OR-ed)
SUBTOOL_NONE: {value: 0, writable: false},
SUBTOOL_PENPLUS: {value: 1, writable: false},
SUBTOOL_PENMINUS: {value: 2, writable: false},
_subtool: {value: this.SUBTOOL_NONE, writable: true},
//constants used for limiting size of the subpath canvas
_MAX_CANVAS_DIMENSION: {value: 3000, writable: false},
/*
// get the stage world position corresponding to the (x,y) mouse event position by querying the snap manager
// but temporarily turning off all snapping
_getMouseEventPosition : {
value: function(x,y, getStageWorld, doSnap){
var elemSnap = snapManager.elementSnapEnabled();
var gridSnap = snapManager.gridSnapEnabled();
var alignSnap = snapManager.snapAlignEnabled();
if (!doSnap){
snapManager.enableElementSnap(false);
snapManager.enableGridSnap(false);
snapM
|