From b89a7ee8b956c96a1dcee995ea840feddc5d4b27 Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Thu, 22 Dec 2011 07:25:50 -0800 Subject: First commit of Ninja to ninja-internal Signed-off-by: Valerio Virgillito --- js/stage/stage-deps.js | 150 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 js/stage/stage-deps.js (limited to 'js/stage/stage-deps.js') diff --git a/js/stage/stage-deps.js b/js/stage/stage-deps.js new file mode 100644 index 00000000..7c6d58b4 --- /dev/null +++ b/js/stage/stage-deps.js @@ -0,0 +1,150 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component; + +var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; +var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; +var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; +var ElementPlanes = require("js/helper-classes/3D/element-planes").ElementPlanes; +var MathUtilsClass = require("js/helper-classes/3D/math-utils").MathUtilsClass; +var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; + +//TODO : This dependency needs to be reworked +var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase; + +exports.StageDeps = Montage.create(Component, { + viewUtils: { + value: viewUtils + }, + + snapManager: { + value: snapManager + }, + + currentStage: { + value: null + }, + + _currentDocument: { + value: null + }, + + currentDocument: { + get: function() { return this._currentDocument; }, + set: function(value) { + if(value) { + this._currentDocument = value; + this.currentStage = value.documentRoot; + } + } + }, + + _userContentLeft: { + value: null + }, + + userContentLeft: { + get: function() { return this._userContentLeft; }, + set: function(value) { + if(value) { + viewUtils.setUserContentLeft(value); + } + } + }, + + _userContentTop: { + value: null + }, + + userContentTop: { + get: function() { return this._userContentTop; }, + set: function(value) { + if(value) { + viewUtils.setUserContentTop(value); + } + } + }, + + deserializedFromTemplate: { + value: function() { + + this.eventManager.addEventListener( "appLoaded", this, false); + this.eventManager.addEventListener( "openDocument", this, false); + + // Initialize Deps + // HACK + // TODO Rework + window.MathUtils = MathUtilsClass; + window.VecUtils = VecUtils; + + snapManager.drawingCanvas = this.stage.drawingCanvas; + + // Setup the listeners for the draw-util and snapmanager when removing elements + // TODO Revisit when supporting multiple documents + drawUtils.initialize(); + snapManager.initialize(); + } + }, + + handleAppLoaded: { + value: function() { + + Object.defineBinding(this, "currentDocument", { + boundObject: this.application.ninja, + boundObjectPropertyPath: "currentDocument", + oneway: true + }); + + Object.defineBinding(this, "userContentLeft", { + boundObject: this.stage, + boundObjectPropertyPath: "_userContentLeft", + oneway: true + }); + + Object.defineBinding(this, "userContentTop", { + boundObject: this.stage, + boundObjectPropertyPath: "_userContentTop", + oneway: true + }); + + // Setup the snap manager pointer to the app model + snapManager.appModel = this.application.ninja.appModel; + // bind the snap properties to the snap manager + snapManager.bindSnap(); + + + } + }, + + handleOpenDocument: { + value: function() { + + workingPlane = Vector.create( [0,0,1,0] ); + + snapManager.setCurrentStage(this.currentStage); + + viewUtils.setCurrentDocument(this.currentDocument); + viewUtils.setRootElement(this.currentStage.parentNode); + viewUtils.setStageElement(this.currentStage); + + drawUtils.setDrawingSurfaceElement(this.stage.canvas); + drawUtils.setSourceSpaceElement( this.currentStage ); + drawUtils.setWorkingPlane( workingPlane ); + drawUtils.viewUtils = viewUtils; + drawUtils.snapManager = snapManager; + drawUtils.ElementPlanes = ElementPlanes; + + snapManager.setupDragPlaneFromPlane ( workingPlane ); + + DrawingToolBase.stage = this.currentStage; + DrawingToolBase.stageComponent = this.stage; + + } + } + +}); \ No newline at end of file -- cgit v1.2.3