Permalink
Browse files

Updated convert to use data.cosphi

  • Loading branch information...
1 parent 0d8d54a commit 1d99463eb87be786440160451f202ef63c083340 Ace Sorensen committed Jun 6, 2010
View
2 web-UI/andes/convert.js
@@ -270,7 +270,7 @@ dojo.provide("andes.convert");
}
if(type=="vector" || type=="axes"){
- obj.cosphi = item.cosphi;
+ obj.cosphi = item.data.cosphi===undefined ? 0 : item.data.cosphi;
}
if(combo){
View
104 web-UI/dojox/drawing/annotations/Angle.js
@@ -1,104 +0,0 @@
-dojo.provide("dojox.drawing.annotations.Angle");
-
-dojox.drawing.annotations.Angle = dojox.drawing.util.oo.declare(
- // summary:
- // When initiated, an HTML box will hover near the Stencil,
- // displaying it's angle while drawn or modified. Currently
- // only works with Vector, Line, Arrow, and Axes.
- // description:
- // Annotation is positioned with dojox.drawing.util.positioning.angle
- // That method should be overwritten for custom placement.
- // Called internally. To initiaize:
- // TODO: currently always on
- //
- function(/*Object*/options){
- // arguments:
- // options: Object
- // One key value: the stencil that called this.
- //
- this.stencil = options.stencil;
- this.util = options.stencil.util;
- this.mouse = options.stencil.mouse;
-
- this.stencil.connectMult([
- ["onDrag", this, "showAngle"],
- ["onUp", this, "hideAngle"],
- ["onTransformBegin", this, "showAngle"],
- ["onTransform", this, "showAngle"],
- ["onTransformEnd", this, "hideAngle"]
- ]);
- },
- {
- type:"dojox.drawing.tools.custom",
- angle:0,
-
- showAngle: function(){
- // summary:
- // Called to display angle
- //
- if(!this.stencil.selected && this.stencil.created){ return; }
- if(this.stencil.getRadius() < this.stencil.minimumSize){
- this.hideAngle();
- return;
- }
- var node = this.getAngleNode();
- var d = this.stencil.pointsToData();
- var pt = dojox.drawing.util.positioning.angle({x:d.x1,y:d.y1},{x:d.x2,y:d.y2});
- var sc = this.mouse.scrollOffset();
- var mx = this.stencil.getTransform();
- var dx = mx.dx / this.mouse.zoom;
- var dy = mx.dy / this.mouse.zoom;
- pt.x /= this.mouse.zoom;
- pt.y /= this.mouse.zoom;
-
- // adding _offX & _offY since this is HTML
- // and we are from the page corner, not
- // the canvas corner
- var x = this.stencil._offX + pt.x - sc.left + dx;
- var y = this.stencil._offY + pt.y - sc.top + dy;
- dojo.style(node, {
- left: x + "px",
- top: y + "px",
- align:pt.align
- });
-
- var angle=this.stencil.getAngle();
- if(this.stencil.style.zAxis && this.stencil.shortType=="vector"){
- node.innerHTML = this.stencil.cosphi > 0 ? "out of" : "into";
- }else if(this.stencil.shortType=="line"){
- node.innerHTML = this.stencil.style.zAxis?"out of":Math.ceil(angle%180);
- }else{
- node.innerHTML = Math.ceil(angle);
- }
- },
-
- getAngleNode: function(){
- // summary:
- // Gets or creates HTMLNode used for display
- if(!this._angleNode){
- this._angleNode = dojo.create("span", null, dojo.body());
- dojo.addClass(this._angleNode, "textAnnotation");
- dojo.style(this._angleNode, "opacity", 1);
- }
- return this._angleNode; //HTMLNode
- },
-
- hideAngle: function(){
- // summary:
- // Turns display off.
- //
- if(this._angleNode && dojo.style(this._angleNode, "opacity")>0.9){
-
- dojo.fadeOut({node:this._angleNode,
- duration:500,
- onEnd: function(node){
- dojo.destroy(node);
- }
- }).play();
- this._angleNode = null;
- }
-
- }
- }
-
-)
View
319 web-UI/dojox/drawing/annotations/BoxShadow.js
@@ -1,319 +0,0 @@
-dojo.provide("dojox.drawing.annotations.BoxShadow");
-
-dojox.drawing.annotations.BoxShadow = dojox.drawing.util.oo.declare(
- // summary:
- // Creates a box shadow under solid objects. Can change the
- // shadow direction, color, size, and intensity. Can center
- // the shadow and make it a Glow.
- // description:
- // This is a psuedo shadow, created by duplicating the
- // original stencil and increasing the line weight while
- // reducing the opacity. Therefore it will not work with
- // text. Also won't look very good if the Stencil has no
- // fill or is transparent. Can't do knockouts or inner
- // shadows. Currently can't do paths - while doable, it
- // will most likely choke IE into certain death.
- //
- function(/*Object*/options){
- this.stencil = options.stencil;
- this.util = options.stencil.util;
- this.mouse = options.stencil.mouse;
- this.style = options.stencil.style;
-
- var shadowDefaults = {
- // summary:
- // When passing a shadow object into a stencil, that shadow
- // object will be mixed in with these defaults.
- //
- // size: Number, mult: Number
- // These two props work together. Both affect the size and quality
- // of the shadow. size affects the actual size and mult affects the
- // lineWidths that overlap to make the shadow. Generally you want a
- // bigger 'size' than 'mult'. The defaults are good for a shadow, but
- // you will want to increase them when making a glow.
- // TODO: Make this more clear or use other properties.
- size:6,
- mult:4,
- // alpha: Float
- // Affects the alpha of the shadow. Because this is multiple shapes
- // overlapped, you want much less than you may think. .1 is pretty
- // dark and . is black. Higher numbers also give a sharper edge.
- alpha:.05,
- // place: String
- // Tells the position of the shadow:
- // B: bottom
- // T: top
- // L: left
- // R: right
- // C: center, or a glow
- // Can be used in combinations such as BR, BL, L, T, etc. 'C' should
- // be used by itself.
- place:"BR",
- // color: String
- // The color of the shadow or glow.
- color:"#646464"
- }
-
- delete options.stencil;
- this.options = dojo.mixin(shadowDefaults, options);
- this.options.color = new dojo.Color(this.options.color)
- this.options.color.a = this.options.alpha;
- switch(this.stencil.shortType){
- case "image":
- case "vector":
- this.method = "createForZArrow"; break;
- case "rect":
- this.method = "createForRect"; break;
- case "ellipse":
- this.method = "createForEllipse"; break;
- case "line":
- this.method = "createForLine"; break;
- case "path":
- this.method = "createForPath"; break;
- // path is a bit of a hassle. Plus I think in IE it would be
- //slower than than the political process. Maybe TODO.
- default:
- console.warn("A shadow cannot be made for Stencil type ", this.stencil.type);
- }
-
- if(this.method == "createForZArrow"){
- this.stencil.connectMult([
- [this.stencil, "onTransform", this, "onTransform"],
- [this.stencil, "onDelete", this, "destroy"],
- [this.stencil, "render", this, "render"]
- ]);
- } else if(this.method){
- this.render();
- this.stencil.connectMult([
- [this.stencil, "onTransform", this, "onTransform"],
- [this.stencil, "render", this, "onRender"],
- [this.stencil, "onDelete", this, "destroy"]
- ]);
- }
- },
- {
- showing:true,
- render: function(){
- if(this.container){
- this.container.removeShape();
- }
- this.container = this.stencil.container.createGroup();
- this.container.moveToBack();
-
- var o = this.options,
- size = o.size,
- mult = o.mult,
- d = this.method == "createForPath"
- ? this.stencil.points
- : this.stencil.data,
- r = d.r || 1,
- p = o.place,
- c = o.color;
-
- this[this.method](o, size, mult, d, r, p, c);
- },
-
- hide: function(){
- if(this.showing){
- this.showing = false;
- this.container.removeShape();
- }
- },
-
- show: function(){
- if(!this.showing){
- this.showing = true;
- this.stencil.container.add(this.container);
- }
- },
-
- createForPath: function(o, size, mult, pts, r, p, c){
- var sh = size * mult / 4,
- shy = /B/.test(p) ? sh : /T/.test(p) ? sh*-1 : 0,
- shx = /R/.test(p) ? sh : /L/.test(p) ? sh*-1 : 0;
-
- var closePath = true;
-
- for(var i=1;i<=size;i++){
- var lineWidth = i * mult;
- //var rect = this.container.createLine({x1:d.x1+shx, y1:d.y1+shy, x2:d.x2+shx, y2:d.y2+shy})
- // .setStroke({width:lineWidth, color:c, cap:"round"})
-
- if(dojox.gfx.renderer=="svg"){
- var strAr = [];
- dojo.forEach(pts, function(o, i){
- if(i==0){
- strAr.push("M " + (o.x+shx) +" "+ (o.y+shy));
- }else{
- var cmd = o.t || "L ";
- strAr.push(cmd + (o.x+shx) +" "+ (o.y+shy)); // Z + undefined works here
- }
- }, this);
- if(closePath){
- strAr.push("Z");
- }
- this.container.createPath(strAr.join(", ")).setStroke({width:lineWidth, color:c, cap:"round"})
-
- }else{
- // Leaving this code for VML. It seems slightly faster but times vary.
- var pth = this.container.createPath({}).setStroke({width:lineWidth, color:c, cap:"round"})
-
- dojo.forEach(this.points, function(o, i){
- if(i==0 || o.t=="M"){
- pth.moveTo(o.x+shx, o.y+shy);
- }else if(o.t=="Z"){
- closePath && pth.closePath();
- }else{
- pth.lineTo(o.x+shx, o.y+shy);
- }
- }, this);
-
- closePath && pth.closePath();
- }
-
-
- }
- },
-
- createForLine: function(o, size, mult, d, r, p, c){
-
- var sh = size * mult / 4,
- shy = /B/.test(p) ? sh : /T/.test(p) ? sh*-1 : 0,
- shx = /R/.test(p) ? sh : /L/.test(p) ? sh*-1 : 0;
- for(var i=1;i<=size;i++){
- var lineWidth = i * mult;
- this.container.createLine({x1:d.x1+shx, y1:d.y1+shy, x2:d.x2+shx, y2:d.y2+shy})
- .setStroke({width:lineWidth, color:c, cap:"round"})
- }
- },
- createForEllipse: function(o, size, mult, d, r, p, c){
-
- var sh = size * mult / 8,
- shy = /B/.test(p) ? sh : /T/.test(p) ? sh*-1 : 0,
- shx = /R/.test(p) ? sh*.8 : /L/.test(p) ? sh*-.8 : 0;
-
- for(var i=1;i<=size;i++){
- var lineWidth = i * mult;
- this.container.createEllipse({cx:d.cx+shx, cy:d.cy+shy, rx:d.rx-sh, ry:d.ry-sh, r:r})
- .setStroke({width:lineWidth, color:c})
- }
- },
-
- createForRect: function(o, size, mult, d, r, p, c){
-
- var sh = size * mult / 2,
- shy = /B/.test(p) ? sh : /T/.test(p) ? 0 : sh /2,
- shx = /R/.test(p) ? sh : /L/.test(p) ? 0 : sh /2;
-
- for(var i=1;i<=size;i++){
- var lineWidth = i * mult;
- this.container.createRect({x:d.x+shx, y:d.y+shy, width:d.width-sh, height:d.height-sh, r:r})
- .setStroke({width:lineWidth, color:c})
- }
- },
-
- arrowPoints: function(){
- // summary:
- // Creates data used to draw arrow head.
- //
- var d = this.stencil.data;
- d.radius = this.stencil.getRadius();
- d.angle = this.style.zAngle + 30;
-
- var pt = this.util.pointOnCircle(d.x1, d.y1, d.radius*.75, d.angle);
- var p = [
- {x:d.x1, y:d.y1},
- {x:pt.x, y:pt.y}
- ];
-
- var obj = {
- start:{
- x:p[0].x,
- y:p[0].y
- },
- x:p[1].x,
- y:p[1].y
- }
- var angle = this.util.angle(obj);
- var lineLength = this.util.length(obj);
- var al = this.style.arrows.length;
- var aw = this.style.arrows.width/3;
- if(lineLength<al){
- al = lineLength/2;
- }
-
- var p1 = this.util.pointOnCircle(p[1].x, p[1].y, -al, angle-aw);
- var p2 = this.util.pointOnCircle(p[1].x, p[1].y, -al, angle+aw);
- return [
- {x:p[1].x, y:p[1].y},
- p1,
- p2
- ];
- },
-
- createForZArrow: function(o, size, mult, pts, r, p, c){
- if(this.stencil.cosphi<1 || (this.stencil.getRadius()<this.stencil.minimumSize)){ return; }
- var sh = size * mult / 4,
- shy = /B/.test(p) ? sh : /T/.test(p) ? sh*-1 : 0,
- shx = /R/.test(p) ? sh : /L/.test(p) ? sh*-1 : 0;
- var closePath = true;
-
- for(var i=1;i<=size;i++){
- var lineWidth = i * mult;
- var pts = this.arrowPoints();
- if(!pts){ return; }
- var p = this.stencil.points;
- if(dojox.gfx.renderer=="svg"){
-
- var strAr = [];
- dojo.forEach(pts, function(o, i){
- if(i==0){
- strAr.push("M " + (o.x+shx) +" "+ (o.y+shy));
- }else{
- var cmd = o.t || "L ";
- strAr.push(cmd + (o.x+shx) +" "+ (o.y+shy)); // Z + undefined works here
- }
- }, this);
- if(closePath){
- strAr.push("Z");
- }
-
- this.container.createPath(strAr.join(", ")).setStroke({width:lineWidth, color:c, cap:"round"}).setFill(c);
-
- }else{
- // Leaving this code for VML. It seems slightly faster but times vary.
- var pth = this.container.createPath({}).setStroke({width:lineWidth, color:c, cap:"round"})
-
- dojo.forEach(pts, function(o, i){
- if(i==0 || o.t=="M"){
- pth.moveTo(o.x+shx, o.y+shy);
- }else if(o.t=="Z"){
- closePath && pth.closePath();
- }else{
- pth.lineTo(o.x+shx, o.y+shy);
- }
- }, this);
-
- closePath && pth.closePath();
- }
-
- this.container.createLine({x1:p[0].x, y1:p[0].y, x2:pts[0].x, y2:pts[0].y})
- .setStroke({width:lineWidth, color:c, cap:"round"});
-
- }
- },
-
-
- onTransform: function(){
- this.render();
- },
- onRender: function(){
- this.container.moveToBack();
- },
- destroy: function(){
- if(this.container){
- this.container.removeShape();
- }
- }
- }
-);
View
288 web-UI/dojox/drawing/defaults.js
@@ -1,288 +0,0 @@
-dojo.provide("dojox.drawing.defaults");
-
-dojox.drawing.defaults = {
- // summary:
- // Styles and defaults used for Drawing stencils and text.
- // description:
- // This object contains defaults for objects used in Drawing.
- // To change one item's style, use item.attr();
- // To change all these styles, create a copy of this file
- // and point to it in the Drawing properties:
- // | <div dojoType="dojox.drawing.Drawing" id="drawing" defaults="MyCustom.defaults"></div>
- // See:
- // Drawing.changeDefaults
- //
- // Determines whether in draw or edit mode (whether stencils
- // are clickable. If clickMode is false, the original
- // functionality of silently switching between select modes
- // is enabled. If clickMode is true, it allows powerpoint-
- // like functionality. Clickable is used by powerpoint to
- // distinguish when things can be selected and when they can't
- clickMode:true,
- clickable:true,
-
- // current: Object
- // current will point to either null or selected
- current:null,
- // currentHit: Object
- // currentHit will point to either hitNorm or hitSelected
- currentHit:null,
-
- // angleSnap: Number
- // Line, arrows, vector and axes will all snap to this angle on mouse up
- // shown angle also reflects the snap
- // currently cannot accept less than 1 degree
- angleSnap:1,
-
- // zAxis: Boolean
- // If true, draw current object in z-direction.
- // zAxisEnabled: Boolean
- // If true, render axes with Z-axis included, allow objects drawn in z-direction.
- // If false the z-axis button will not show up.
- zAxis: false,
- zAxisEnabled: true,
- zAngle: 225,
-
- // renderHitLines: Boolean
- // If true, renders a second, larger layer for lines to make
- // them more easily clickable.
- renderHitLines: true,
- //
- // renderHitLayer:
- // If true, renders a second layer for each Stencil, one
- // acting as a 'hit' object for a wider mouse-click area.
- // It also doubles as a hilight. If true, overrides
- // renderHitLines setting.
- renderHitLayer:true,
-
- // labelSameColor:
- // If true, the label text color will be the same as the
- // Stencil's line color.
- labelSameColor:false,
-
- //
- useSelectedStyle: true,
-
- norm:{
- // summary:
- // Normal style of all shapes
- // will get overridden by
- // above andes styles
- width:1,
- color:"#000000",
- style:"Solid",
- cap:"round", // square, butt, round
- fill:"#CCCCCC"
- },
-
- selected:{
- // summary:
- // Selected style of all shapes
- // styles not shown will used from
- // norm
- width:6,
- color:"#00FF00"
- },
-
- highlighted:{
- // summary:
- // Highlighted style of all shapes
- // NOT CURRENTLY BEING USED
- width:6,
- color:"#FF00FF",
- style:"Solid",
- cap:"round",
- fill:"#E11EBB"
- },
-
- disabled:{
- // summary:
- // Disabled or "locked" or "fade" style of all shapes
- width:1,
- color:"#666666",
- style:"solid",
- cap:"round",
- fill:"#cccccc"
- },
-
- // "hit" refers to the hidden object below the shape
- // that is usually larger than the object to give a
- // larger 'target' to click upon. These hit objects
- // double as highlights.
- //
- hitNorm:{
- // summary:
- // Normal style of a hit area
- width:6,
- color:{r:0, g:255, b:255, a:0},
- style:"Solid",
- cap:"round",
- fill:{r:255, g:255, b:255, a:0}
- },
- hitSelected:{
- // summary:
- // Selected style of a hit area
- width:6,
- color:"#FF9900",
- style:"Solid",
- cap:"round",
- fill:{r:255, g:255, b:255, a:0}
- },
- hitHighlighted:{
- // summary:
- // Highlighted style of a hit area
- width:6,
- color:"#FFFF00",
- style:"Solid",
- cap:"round",
- fill:{r:255, g:255, b:255, a:0}
- },
-
-
- anchors:{
- // summary:
- // Style for the anchor resize-points
- size:10,
- width:2,
- color:"#999",
- style:"solid",
- fill:"#fff",
- cap:"square",
- minSize:10,
- marginZero:5 // not really an anchor prop
- },
- arrows:{
- // summary:
- // Size of arrows on vectors.
- // length is in pixels
- // width is actually an angle
- // but is close to pixels in size
- length:30,
- width:16
- },
- text:{
- // summary:
- // Style of text
- minWidth:100,
- deleteEmptyCreate:true,
- deleteEmptyModify:true,
- pad:3,
- size:"18px",
- family:"sans-serif",
- weight:"normal",
- color:"#000000"
- },
- textDisabled:{
- // summary:
- // Style of disabled text
- size:"18px",
- family:"sans-serif",
- weight:"normal",
- color:"#cccccc"
- },
-
- textMode:{
- // summary:
- // These styles apply to the containing
- // text box (edit mode), and not the text itself
- create:{
- width:2,
- style:"dotted",
- color:"#666666",
- fill:null
- },
- edit:{
- width:1,
- style:"dashed",
- color:"#666",
- fill:null
- }
-
- },
-
- button:{
- norm:{
- "color": "#cccccc",
- "fill": {
- type:"linear",
- x1:0, x2:0, y1:0, y2:100,
- colors:[
- {offset:.5, color:"#ffffff"},
- {offset:1, color:"#e5e5e5"}
- ]
- }
- },
- over:{
- "fill": {
- type:"linear",
- x1:0, x2:0, y1:0, y2:100,
- colors:[{offset:.5, color:"#ffffff"}, {offset:1, color:"#e1eaf5"}]
- },
- "color": "#92a0b3"
- },
- down:{
- "fill": {
- type:"linear",
- x1:0, x2:0, y1:0, y2:100,
- colors:[{offset:0, color:"#e1eaf5"}, {offset:1, color:"#ffffff"}]
- },
- "color": "#92a0b3"
- },
- selected:{
- "fill": {
- type:"linear",
- x1:0, x2:0, y1:0, y2:100,
- colors:[{offset:0, color:"#97b4bf"}, {offset:1, color:"#c8dae1"}]
- },
- "color": "#92a0b3"
- },
- icon:{
- norm:{
- fill:null,
- color:"#92a0b3"
- },
- selected:{
- fill:"#ffffff",
- color:"#92a0b3"
- }
- }
- },
-
- copy: function(){
- // summary
- // Each shape gets its own copy
- // of these styles so that instances
- // do not change each other's styles
- //
- var cpy = function(obj){
- if(typeof(obj)!="object" || obj===null || obj===undefined){
- return obj;
- }
- var o;
- if(obj.push){
- o = [];
- for(var i=0; i<obj.length;i++){
- o.push(cpy(obj[i]))
- }
- return o;
- }
- o = {};
- for(var nm in obj){
- if(nm!="copy"){
- if(typeof(obj[nm])=="object"){
- o[nm] = cpy(obj[nm]);
- }else{
- o[nm] = obj[nm]
- }
- }
- }
- return o;
- }
- var o = cpy(this);
- o.current = o.norm;
- o.currentHit = o.hitNorm;
- o.currentText = o.text;
- return o;
- }
-
-};
View
464 web-UI/dojox/drawing/manager/Anchors.js
@@ -1,464 +0,0 @@
-dojo.provide("dojox.drawing.manager.Anchors");
-
-dojox.drawing.manager.Anchors = dojox.drawing.util.oo.declare(
- // summary:
- // Creates and manages the anchor points that are attached to
- // (usually) the corners of a Stencil.
- // description:
- // Used internally, but there are some things that should be known:
- // Anchors attach to a Stencil's 'points' (See stencil.points)
- // To not display an anchor on a certain point, add noAnchor:true
- // to the point.
-
- function(/* dojox.__stencilArgs */options){
- // arguments: See stencil._Base
- this.mouse = options.mouse;
- this.undo = options.undo;
- this.util = options.util;
- this.drawing = options.drawing;
- this.items = {};
- },
- {
- onAddAnchor: function(/*Anchor*/anchor){
- // summary:
- // Event fires when anchor is created
- },
-
-
- onReset: function(/*Stencil*/stencil){
- // summary:
- // Event fires when an anchor's reset method is called
- //
- // a desperate hack in order to get the anchor point to reset.
- // FIXME: Is this still used? I think its item.deselect();item.select();
- var st = this.util.byId("drawing").stencils;
- st.onDeselect(stencil);
- st.onSelect(stencil);
- },
-
- onRenderStencil: function(){
- // summary:
- // Event fires when an anchor calls a Stencil's render method
- //
- for(var nm in this.items){
- dojo.forEach(this.items[nm].anchors, function(a){
- a.shape.moveToFront();
- });
- }
- },
-
- onTransformPoint: function(/*Anchor*/anchor){
- // summary:
- // Event fired on anchor drag
- //
- // If anchors are a "group", it's corresponding anchor
- // is set. All anchors then moved to front.
- var anchors = this.items[anchor.stencil.id].anchors;
- var item = this.items[anchor.stencil.id].item;
- var pts = [];
- dojo.forEach(anchors, function(a, i){
-
-
- if(anchor.id == a.id || anchor.stencil.anchorType!="group"){
- // nothing
- }else{
- if(anchor.org.y == a.org.y){
- a.setPoint({
- dx: 0,
- dy: anchor.shape.getTransform().dy - a.shape.getTransform().dy
- });
- }else if(anchor.org.x == a.org.x){
- a.setPoint({
- dx: anchor.shape.getTransform().dx - a.shape.getTransform().dx,
- dy: 0
- });
- }
- a.shape.moveToFront();
- }
-
- var mx = a.shape.getTransform();
- pts.push({x:mx.dx + a.org.x, y:mx.dy+ a.org.y});
-
- if(a.point.t){
- pts[pts.length-1].t = a.point.t;
- }
-
- }, this);
- item.setPoints(pts);
- item.onTransform(anchor);
- this.onRenderStencil();
- },
-
- onAnchorUp: function(/*Anchor*/anchor){
- // summary:
- // Event fired on anchor mouseup
- },
-
- onAnchorDown: function(/*Anchor*/anchor){
- // summary:
- // Event fired on anchor mousedown
- },
-
- onAnchorDrag: function(/*Anchor*/anchor){
- // summary:
- // Event fired when anchor is moved
- },
-
- onChangeStyle: function(/*Object*/stencil){
- // summary:
- // if the Stencil changes color while were's selected
- // this moves the anchors to the back. Fix it.
-
- for(var nm in this.items){
- dojo.forEach(this.items[nm].anchors, function(a){
- a.shape.moveToFront();
- });
- }
- },
-
- add: function(/*Stencil*/item){
- // summary:
- // Creates anchor points on a Stencil, based on the
- // Stencil's points.
- //
- this.items[item.id] = {
- item:item,
- anchors:[]
- };
- if(item.anchorType=="none"){ return; }
- var pts = item.points;
- dojo.forEach(pts, function(p, i){
- if(p.noAnchor){ return; }
- if(i==0 || i == item.points.length-1){
- console.log("ITEM TYPE:", item.type, item.shortType);
- }
- var a = new dojox.drawing.manager.Anchor({stencil:item, point:p, pointIdx:i, mouse:this.mouse, util:this.util});
- this.items[item.id]._cons = [
- dojo.connect(a, "onRenderStencil", this, "onRenderStencil"),
- dojo.connect(a, "reset", this, "onReset"),
- dojo.connect(a, "onAnchorUp", this, "onAnchorUp"),
- dojo.connect(a, "onAnchorDown", this, "onAnchorDown"),
- dojo.connect(a, "onAnchorDrag", this, "onAnchorDrag"),
- dojo.connect(a, "onTransformPoint", this, "onTransformPoint"),
- // FIXME: this will fire for each anchor. yech.
- dojo.connect(item, "onChangeStyle", this, "onChangeStyle")
- ];
-
- this.items[item.id].anchors.push(a);
- this.onAddAnchor(a);
- }, this);
-
- if(item.shortType=="path"){
- // check if we have a double-point of a closed-curve-path
- var f = pts[0], l = pts[pts.length-1], a = this.items[item.id].anchors;
- if(f.x ==l.x && f.y==l.y){
- console.warn("LINK ANVHROS", a[0], a[a.length-1]);
- a[0].linkedAnchor = a[a.length-1];
- a[a.length-1].linkedAnchor = a[0];
- }
- }
-
- if(item.anchorType=="group"){
- dojo.forEach(this.items[item.id].anchors, function(anchor){
- dojo.forEach(this.items[item.id].anchors, function(a){
- if(anchor.id != a.id){
- if(anchor.org.y == a.org.y){
- anchor.x_anchor = a;
- }else if(anchor.org.x == a.org.x){
- anchor.y_anchor = a;
- }
- }
- },this);
- },this);
-
- }
- },
-
- remove: function(/*Stencil*/item){
- // summary:
- // Destroys the anchor points for a Stencil.
- //
- if(!this.items[item.id]){
- return;
- }
- dojo.forEach(this.items[item.id].anchors, function(a){
- a.destroy();
- });
- dojo.forEach(this.items[item.id]._cons, dojo.disconnect, dojo);
- this.items[item.id].anchors = null;
- delete this.items[item.id];
- }
- }
-);
-
-dojox.drawing.manager.Anchor = dojox.drawing.util.oo.declare(
- // summary:
- // An anchor point that is attached to (usually) one of the
- // corners of a Stencil.
- // Used internally.
- function(/* Object */options){
- // summary:
- // constructor.
- // arguments:
- // dojox.__stencilArgs plus some additional
- // data, like which point this is (pointIdx)
- //
- this.defaults = dojox.drawing.defaults.copy();
- this.mouse = options.mouse;
- this.point = options.point;
- this.pointIdx = options.pointIdx;
- this.util = options.util;
- this.id = options.id || this.util.uid("anchor");
- this.org = dojo.mixin({}, this.point);
- this.stencil = options.stencil;
- if(this.stencil.anchorPositionCheck){
- this.anchorPositionCheck = dojo.hitch(this.stencil, this.stencil.anchorPositionCheck);
- }
- if(this.stencil.anchorConstrain){
- this.anchorConstrain = dojo.hitch(this.stencil, this.stencil.anchorConstrain);
- }
- this._zCon = dojo.connect(this.mouse, "setZoom", this, "render");
- this.render();
- this.connectMouse();
- },
- {
- y_anchor:null,
- x_anchor:null,
- render: function(){
- // summary:
- // Creates the anchor point. Unlike most render methods
- // in Drawing, this is only called once.
- //
- this.shape && this.shape.removeShape();
- var d = this.defaults.anchors,
- z = this.mouse.zoom,
- b = d.width * z,
- s = d.size * z,
- p = s/2,
- line = {
- width:b,
- style:d.style,
- color:d.color,
- cap:d.cap
- };
-
-
- var _r = {
- x: this.point.x-p,
- y: this.point.y-p,
- width: s,
- height: s
- };
- this.shape = this.stencil.container.createRect(_r)
- .setStroke(line)
- .setFill(d.fill);
-
- this.shape.setTransform({dx:0, dy:0});
- this.util.attr(this, "drawingType", "anchor");
- this.util.attr(this, "id", this.id);
- },
- onRenderStencil: function(/*Anchor*/anchor){
- // summary:
- // Event fires when an anchor calls a Stencil's render method
- },
- onTransformPoint: function(/*Anchor*/anchor){
- // summary:
- // Event fires when an anchor changes the points of a Stencil
- },
- onAnchorDown: function(/*Mouse.EventObject*/obj){
- // summary:
- // Event fires for mousedown on anchor
- this.selected = obj.id == this.id;
- },
- onAnchorUp: function(/*Mouse.EventObject*/obj){
- // summary:
- // Event fires for mouseup on anchor
- this.selected = false;
- this.stencil.onTransformEnd(this);
- },
-
- onAnchorDrag: function(/*Mouse.EventObject*/obj){
- // summary:
- // Event fires for on dragging of an anchor
- if(this.selected){
- // mx is the original transform from when the anchor
- // was created. It does not change
- var mx = this.shape.getTransform();
-
- var pmx = this.shape.getParent().getParent().getTransform();
-
- var marginZero = this.defaults.anchors.marginZero;
-
- var orgx = pmx.dx + this.org.x,
- orgy = pmx.dy + this.org.y,
- x = obj.x - orgx,
- y = obj.y - orgy,
- s = this.defaults.anchors.minSize;
-
- var conL, conR, conT, conB;
-
- var chk = this.anchorPositionCheck(x, y, this);
- if(chk.x<0){
- console.warn("X<0 Shift");
- while(this.anchorPositionCheck(x, y, this).x<0){
- this.shape.getParent().getParent().applyTransform({dx:2, dy:0});
- }
- }
- if(chk.y<0){
- console.warn("Y<0 Shift");
- while(this.anchorPositionCheck(x, y, this).y<0){
- this.shape.getParent().getParent().applyTransform({dx:0, dy:2});
- }
- }
-
- if(this.y_anchor){
- // prevent y overlap of opposite anchor
- if(this.org.y > this.y_anchor.org.y){
- // bottom anchor
-
- conT = this.y_anchor.point.y + s - this.org.y;
- conB = Infinity;
-
- if(y < conT){
- // overlapping other anchor
- y = conT;
- }
-
-
- }else{
- // top anchor
-
- conT = -orgy + marginZero;
- conB = this.y_anchor.point.y - s - this.org.y;
-
- if(y < conT){
- // less than zero
- y = conT;
- }else if(y > conB){
- // overlapping other anchor
- y = conB;
- }
- }
- }else{
- // Lines - check for zero
- conT = -orgy + marginZero;
- if(y < conT){
- // less than zero
- y = conT;
- }
- }
-
-
-
-
- if(this.x_anchor){
- // prevent x overlap of opposite anchor
-
- if(this.org.x>this.x_anchor.org.x){
- // right anchor
-
- conL = this.x_anchor.point.x + s - this.org.x;
- conR = Infinity;
-
- if(x < conL){
- // overlapping other anchor
- x = conL;
- }
-
- }else{
- // left anchor
-
- conL = -orgx + marginZero;
- conR = this.x_anchor.point.x - s - this.org.x;
-
- if(x < conL){
- x = conL;
- }else if(x > conR){
- // overlapping other anchor
- x = conR;
- }
- }
- }else{
- // Lines check for zero
- conL = -orgx + marginZero;
- if(x < conL){
- x = conL;
- }
- }
- //Constrains anchor point, returns null if not overwritten by stencil
- var constrained = this.anchorConstrain(x, y);
- if(constrained != null){
- x=constrained.x;
- y=constrained.y;
- }
-
- this.shape.setTransform({
- dx:x,
- dy:y
- });
- if(this.linkedAnchor){
- // first and last points of a closed-curve-path
- this.linkedAnchor.shape.setTransform({
- dx:x,
- dy:y
- });
- }
- this.onTransformPoint(this);
- }
- },
-
- anchorConstrain: function(/* Number */x,/* Number */ y){
- // summary:
- // To be over written by tool!
- // Add an anchorConstrain method to the tool
- // and it will automatically overwrite this stub.
- // Should return a constrained x & y value.
- return null;
- },
-
- anchorPositionCheck: function(/* Number */x,/* Number */ y, /* Anchor */anchor){
- // summary:
- // To be over written by tool!
- // Add a anchorPositionCheck method to the tool
- // and it will automatically overwrite this stub.
- // Should return x and y coords. Success is both
- // being greater than zero, fail is if one or both
- // are less than zero.
- return {x:1, y:1};
- },
-
- setPoint: function(mx){
- // summary:
- // Internal. Sets the Stencil's point
- this.shape.applyTransform(mx);
- },
-
- connectMouse: function(){
- // summary:
- // Internal. Connects anchor to manager.mouse
- this._mouseHandle = this.mouse.register(this);
- },
-
- disconnectMouse: function(){
- // summary:
- // Internal. Disconnects anchor to manager.mouse
- this.mouse.unregister(this._mouseHandle);
- },
-
- reset: function(stencil){
- // summary:
- // Called (usually) from a Stencil when that Stencil
- // needed to make modifications to the position of the
- // point. Basically used when teh anchor causes a
- // less than zero condition.
- },
-
- destroy: function(){
- // summary:
- // Destroys anchor.
- dojo.disconnect(this._zCon);
- this.disconnectMouse();
- this.shape.removeShape();
- }
- }
-);
View
242 web-UI/dojox/drawing/plugins/tools/Pan.js
@@ -1,242 +0,0 @@
-dojo.provide("dojox.drawing.plugins.tools.Pan");
-dojo.require("dojox.drawing.plugins._Plugin");
-
-dojox.drawing.plugins.tools.Pan = dojox.drawing.util.oo.declare(
- // summary:
- // A plugin that allows for a scrolling canvas. An action
- // tool is added to the toolbar that allows for panning. Holding
- // the space bar is a shortcut to that action. The canvas will
- // only pan and scroll if there are objects out of the viewable
- // area.
- // example:
- // | <div dojoType="dojox.drawing.Toolbar" drawingId="drawingNode" class="drawingToolbar vertical">
- // | <div tool="dojox.drawing.tools.Line" selected="true">Line</div>
- // | <div plugin="dojox.drawing.plugins.tools.Pan" options="{}">Pan</div>
- // | </div>
- //
- dojox.drawing.plugins._Plugin,
- function(options){
- this.domNode = options.node;
- var _scrollTimeout;
- this.toolbar = options.scope;
- this.connect(this.toolbar, "onToolClick", this, function(){
- this.onSetPan(false)
- });
- this.connect(this.keys, "onKeyUp", this, "onKeyUp");
- this.connect(this.keys, "onKeyDown", this, "onKeyDown");
- this.connect(this.keys, "onArrow", this, "onArrow");
- this.connect(this.anchors, "onAnchorUp", this, "checkBounds");
- this.connect(this.stencils, "register", this, "checkBounds");
- this.connect(this.canvas, "resize", this, "checkBounds");
- this.connect(this.canvas, "setZoom", this, "checkBounds");
- this.connect(this.canvas, "onScroll", this, function(){
- if(this._blockScroll){
- this._blockScroll = false;
- return;
- }
- _scrollTimeout && clearTimeout(_scrollTimeout);
- _scrollTimeout = setTimeout(dojo.hitch(this, "checkBounds"), 200);
- });
- this._mouseHandle = this.mouse.register(this);
- // This HAS to be called after setting initial objects or things get screwy.
- //this.checkBounds();
-
- },{
- selected:false,
- keyScroll:false,
- type:"dojox.drawing.plugins.tools.Pan",
-
- onPanUp: function(obj){
- if(obj.id == this.button.id){
- this.onSetPan(false);
- }
- },
-
- onKeyUp: function(evt){
- switch(evt.keyCode){
- case 32:
- this.onSetPan(false);
- break;
- case 39: case 37: case 38: case 40:
- clearInterval(this._timer);
- break;
- }
- },
-
- onKeyDown: function(evt){
- if(evt.keyCode == 32){
- this.onSetPan(true);
- }
- },
-
- interval: 20,
-
- onArrow: function(evt){
- if(this._timer){ clearInterval(this._timer); }
- this._timer = setInterval(dojo.hitch(this,function(evt){
- this.canvas.domNode.parentNode.scrollLeft += evt.x*10;
- this.canvas.domNode.parentNode.scrollTop += evt.y*10;
- },evt), this.interval);
- },
-
- onSetPan: function(/*Boolean | Event*/ bool){
- if(bool === true || bool === false){
- this.selected = !bool;
- }
- console.log('ON SET PAN:', this.selected)
- if(this.selected){
- this.selected = false;
- this.button.deselect();
- }else{
- this.selected = true;
- this.button.select();
- }
- this.mouse.setEventMode(this.selected ? "pan" : "");
- },
-
- onPanDrag: function(obj){
- var x = obj.x - obj.last.x;
- var y = obj.y - obj.last.y;
- this.canvas.domNode.parentNode.scrollTop -= obj.move.y;
- this.canvas.domNode.parentNode.scrollLeft -= obj.move.x;
- this.canvas.onScroll();
- },
-
- onUp: function(obj){
- if(obj.withinCanvas){
- this.keyScroll = true;
- }else{
- this.keyScroll = false;
- }
- },
-
- onStencilUp: function(obj){
- // this gets called even on click-off because of the
- // issues with TextBlock deselection
- this.checkBounds();
- },
- onStencilDrag: function(obj){
- // this gets called even on click-off because of the
- // issues with TextBlock deselection
- //this.checkBounds();
- },
-
- checkBounds: function(){
-
- //watch("CHECK BOUNDS DISABLED", true); return;
-
-
- // summary:
- // Scans all items on the canvas and checks if they are out of
- // bounds. If so, a scroll bar (in Canvas) is shown. If the position
- // is left or top, the canvas is scrolled all items are relocated
- // the distance of the scroll. Ideally, it should look as if the
- // items do not move.
-
- // logging stuff here so it can be turned on and off. This method is
- // very high maintenance.
- var log = function(){
- //console.log.apply(console, arguments);
- }
- var warn = function(){
- //console.warn.apply(console, arguments);
- }
- //console.clear();
- //console.time("check bounds");
-
- // initialize a shot-tin of vars
- var t=Infinity, r=-Infinity, b=-10000, l=10000,
- sx=0, sy=0, dy=0, dx=0,
- mx = this.stencils.group ? this.stencils.group.getTransform() : {dx:0, dy:0},
- sc = this.mouse.scrollOffset(),
- // scY, scX: the scrollbar creates the need for extra dimension
- scY = sc.left ? 10 : 0,
- scX = sc.top ? 10 : 0,
- // ch, cw: the current size of the canvas
- ch = this.canvas.height,
- cw = this.canvas.width,
- z = this.canvas.zoom,
- // pch, pcw: the normal size of the canvas (not scrolled)
- // these could change if the container resizes.
- pch = this.canvas.parentHeight,
- pcw = this.canvas.parentWidth;
-
-
- this.stencils.withSelected(function(m){
- var o = m.getBounds();
- warn("SEL BOUNDS:", o);
- t = Math.min(o.y1 + mx.dy, t);
- r = Math.max(o.x2 + mx.dx, r);
- b = Math.max(o.y2 + mx.dy, b);
- l = Math.min(o.x1 + mx.dx, l);
- });
-
- this.stencils.withUnselected(function(m){
- var o = m.getBounds();
- warn("UN BOUNDS:", o);
- t = Math.min(o.y1, t);
- r = Math.max(o.x2, r);
- b = Math.max(o.y2, b);
- l = Math.min(o.x1, l);
- log("----------- B:", b, o.y2)
- });
-
- b *= z;
- var xscroll = 0, yscroll = 0;
- log("Bottom test", "b:", b, "z:", z, "ch:", ch, "pch:", pch, "top:", sc.top, "sy:", sy, "mx.dy:", mx.dy);
- if(b > pch || sc.top ){
- log("*bottom scroll*");
- // item off bottom
- ch = Math.max(b, pch + sc.top);
- sy = sc.top;
- xscroll += this.canvas.getScrollWidth();
- }else if(!sy && ch>pch){
- log("*bottom remove*");
- // item moved from bottom
- ch = pch;
- }
-
- r *= z;
- if(r > pcw || sc.left){
- //log("*right scroll*");
- // item off right
- cw = Math.max(r, pcw + sc.left);
- sx = sc.left;
- yscroll += this.canvas.getScrollWidth();
- }else if(!sx && cw>pcw){
- //log("*right remove*");
- // item moved from right
- cw = pcw;
- }
-
- // add extra space for scrollbars
- // double it to give some breathing room
- cw += xscroll*2;
- ch += yscroll*2;
-
- this._blockScroll = true;
-
- // selected items are not transformed. The selection itself is
- // and the items are on de-select
- this.stencils.group && this.stencils.group.applyTransform({dx:dx, dy:dy});
-
- // non-selected items are transformed
- this.stencils.withUnselected(function(m){
- m.transformPoints({dx:dx, dy:dy});
- });
-
- this.canvas.setDimensions(cw, ch, sx, sy);
-
- //console.timeEnd("check bounds");
- }
- }
-);
-
-dojox.drawing.plugins.tools.Pan.setup = {
- name:"dojox.drawing.plugins.tools.Pan",
- tooltip:"Pan Tool",
- iconClass:"iconPan",
- button:false
-};
-
-dojox.drawing.register(dojox.drawing.plugins.tools.Pan.setup, "plugin");
View
1,209 web-UI/dojox/drawing/stencil/_Base.js
@@ -1,1209 +0,0 @@
-dojo.provide("dojox.drawing.stencil._Base");
-dojo.require("dojo.fx.easing");
-
-/*=====
-StencilArgs = {
-// container: [readonly] dojo.gfx.group
-// The parent shape that contains all
-// shapes used in a Stencil
-container:null,
-//
-// anchorType: String
-// Optionally blank or 'group'. 'group' tells
-// an anchor point that it must constrain
-// itself to other anchor points.
-anchorType:"",
-//
-// isText: Boolean
-// Whether this is a text object or not
-// (either stencil.text or tools.TextBlock)
-isText:false,
-//
-// shortType: String
-// The type of stencil that corresponds with the types and
-// constructors used in Drawing.registerTool
-shortType:"",
-//
-// annotation: Boolean
-// A Stencil used within a Stencil. An annotation
-// is not selectable or clickable. A Label would
-// be one example.
-annotation:false,
-//
-// subShape: Boolean
-// A Stencil used within a Stencil. A subShape
-// is clickable. An arrow head would be an example.
-subShape:false,
-//
-// style: Object
-// An instance of the styles and defaults used within
-// the Stencil.
-style:null,
-//
-// util: Object
-// Pointer to util.common
-util:null,
-//
-// mouse: Object
-// Pointer to the mouse instance
-mouse:null,
-//
-// keys: Object
-// Pointer to the keys class
-keys:null,
-//
-// points: StencilPoints
-// Points is an array of objects that make up the
-// description of a Stencil. The points to a Rect
-// that is 100x100 and at x:10 and y:10 would look like:
-// [{x:10,y:10}, {x:110, y:10}, {x:110, y:110}, {x:10, y:110}]
-// Points go clockwise from the top left. In the case of Paths,
-// they would go in the order that the Stencil would be drawn.
-// Always when the points Array is set, a data Object is created
-// as well. So never set points directly, always use setPoints().
-// See:
-// setPoints()
-points:[],
-//
-// data: StencilData
-// A data object typically (but not always) resembles the data
-// that is used to create the dojox.gfx Shape. The same Rect
-// example shown in points above would look like:
-// {x:10, y:10, width:100, height:100}
-// And an Ellipse with the same coordinates:
-// {cx:55, cy:55, rx:50, ry:50}
-// The only Stencil that does not support data (at this time)
-// is the Path. While x1,x2,x3... culd be used in a data object
-// it doesn't provide much benefit.
-// Always when a data object is set, a set of points is created
-// as well. So never set data directly, always use setData().
-// See:
-// setData()
-data:null,
-//
-// marginZero [readonly] Number
-// How closely shape can get to y:0 or x:0. Less than zero has
-// bugs in VML. This is set with defaults, and should be equal
-// to half the size of an anchor point (5 px)
-marginZero:0,
-//
-// created [readonly] Boolean
-// Whether the Stencil has been rendered for the first time or
-// not.
-created: false,
-//
-// highlighted [readonly] Boolean
-// Whether the Stencil is highlighted or not.
-highlighted:false,
-//
-// selected [readonly] Boolean
-// Whether the Stencil is selected or not.
-selected:false,
-//
-// draws [readonly] Boolean
-// Whether the Stencil can draw with a mouse drag or can just
-// be created programmtically. If the Stencil comes from the
-// stencil package, it should be draw:false. If it comes from
-// the tools package it should be draw:true.
-draws:false
-}
-
-StencilPoint = {
-// summary:
-// One point Object in the points Array
-// x: Number
-// x position of point
-// y: Number
-// y position of point
-}
-
-ToolsSetup = {
-// summary:
-// An object attached to a Tool's constructor
-// used to inform the toolbar of its information
-// and properties.
-// description:
-// This object is inserted into the *function* of
-// a tool (not a stencil). Like: function.ToolsSetup
-// It must be attached after constructr creation, so
-// this object is found at the botton of the file.
-//
-// name:String
-// Fully qualified name of constructor
-// tooltip: Stirng
-// Text to display on toolbar button hover
-// iconClass: String
-// CSS class with icon information to attach
-// to toolbar button.
-}
-=====*/
-
-dojox.drawing.stencil._Base = dojox.drawing.util.oo.declare(
- // summary:
- // The base class used for all Stencils.
- // description:
- // All stencils extend this base class.
- // Most methods and events can be found here.
- //
- function(options){
- //console.log("______Base", this.type, options)
- // clone style so changes are reflected in future shapes
- dojo.mixin(this, options);
- this.style = options.style || dojox.drawing.defaults.copy();
- if(options.stencil){
- this.stencil = options.stencil;
- this.util = options.stencil.util;
- this.mouse = options.stencil.mouse;
- this.container = options.stencil.container;
- this.style = options.stencil.style;
- }
-
- // don't use the 'g' on these, it affects
- // the global RegExp
- var lineTypes = /Line|Vector|Axes|Arrow/;
- var textTypes = /Text/;
-
- this.shortType = this.util.abbr(this.type);
- this.isText = textTypes.test(this.type);
- this.isLine = lineTypes.test(this.type);
-
- this.renderHit = this.style.renderHitLayer;
- if(!this.renderHit && this.style.renderHitLines && this.isLine){
- this.renderHit = true;
- }
- if(!this.renderHit && this.style.useSelectedStyle){
- this.useSelectedStyle = true;
- this.selCopy = dojo.clone(this.style.selected);
- for(var nm in this.style.norm){
- if(this.style.selected[nm]===undefined){
- this.style.selected[nm] = this.style.norm[nm];
- }
- }
- this.textSelected = dojo.clone(this.style.text);
- this.textSelected.color = this.style.selected.fill;
-
- }
-
-
- this.angleSnap = this.style.angleSnap || 1;
-
- this.marginZero = options.marginZero || this.style.anchors.marginZero;
- this.id = options.id || this.util.uid(this.type);
- this._cons = [];
-
- if(!this.annotation && !this.subShape){
- this.util.attr(this.container, "id", this.id);
- }
-
- this.connect(this, "onBeforeRender", "preventNegativePos");
-
- this._offX = this.mouse.origin.x;
- this._offY = this.mouse.origin.y;
-
- if(this.isText){
- this.align = options.align || this.align;
- this.valign = options.valign || this.valign;
- if(options.data && options.data.makeFit){
- var textObj = this.makeFit(options.data.text, options.data.width);
- this.textSize = this.style.text.size = textObj.size;
- this._lineHeight = textObj.box.h;
- }else{
- this.textSize = parseInt(this.style.text.size, 10);
- this._lineHeight = this.textSize * 1.4;
- }
-
-
- // TODO: thinner text selection
- //this.style.hitSelected.width *= 0.5;
- //
- // ouch. how verbose. My mixin is weak....
- this.deleteEmptyCreate = options.deleteEmptyCreate!==undefined ? options.deleteEmptyCreate : this.style.text.deleteEmptyCreate;
- this.deleteEmptyModify = options.deleteEmptyModify!==undefined ? options.deleteEmptyModify : this.style.text.deleteEmptyModify;
- }
-
- //this.drawingType
-
- this.attr(options.data);
-
- // make truthy
- // add to renders below
- // this.baseRender && render()
- //if(this.type == "dojox.drawing.tools.TextBlock"){
- if(this.noBaseRender){
- // TextBlock will handle rendering itself
- return;
- }
-
- //console.log("BASE OPTS:", options)
- if(options.points){
- //console.log("__________Base.constr >>>> ", this.type, "points", options.points)
- if(options.data && options.data.closePath===false){
- this.closePath = false;
- }
- this.setPoints(options.points);
- this.connect(this, "render", this, "onRender", true);
- this.baseRender && this.enabled && this.render();
- options.label && this.setLabel(options.label);
- options.shadow && this.addShadow(options.shadow);
-
- }else if(options.data){
- //console.log("___________Base.constr", this.type, "options data", options.data)
- options.data.width = options.data.width ? options.data.width : this.style.text.minWidth;
- options.data.height = options.data.height ? options.data.height : this._lineHeight;
- this.setData(options.data);
- this.connect(this, "render", this, "onRender", true);
- this.baseRender && this.enabled && this.render(options.data.text);
- options.label && this.setLabel(options.label);
- options.shadow && this.addShadow(options.shadow);
-
- }else if(this.draws){
- //console.log("_____________Base.constr", this.type, "draws")
- this.points = [];
- this.data = {};
- this.connectMouse();
- this._postRenderCon = dojo.connect(this, "render", this, "_onPostRender");
- }
- if(this.showAngle){
- this.angleLabel = new dojox.drawing.annotations.Angle({stencil:this});
- }
-
- if(!this.enabled){
- this.disable();
- this.moveToBack();
- // some things render some don't...
- this.render(options.data.text);
- }
-
- if(this.shortType == "vector" && !options.data){
- options.data = { cosphi:0 };
- }
-
- },
- {
-
- // type: String
- // The type of Stencil this is. Should be overridden
- // by extending classes.
- // FIXME: should this be declaredClass?
- type:"dojox.drawing.stencil",
- //
- // minimumSize: Number
- // The minimum size allowed for a render. If the size
- // is less, the shape is destroyed.
- minimumSize:10,
- //
- // enabled [readonly] Boolean
- // Whether the Stencil is enabled or not.
- enabled:true,
-
-
- drawingType:"stencil",
-
- //points:[],
-
- setData: function(/*StencilData*/data){
- // summary:
- // Setter for Stencil data; also converts
- // data to points. See individual Stencils
- // for specific data properties.
- this.data = data;
- this.points = this.dataToPoints();
- },
-
- setPoints: function(/*StencilPoints*/points){
- // summary:
- // Setter for Stencil points; also converts
- // points to data. See individual Stencils
- // for specific points properties.
- this.points = points;
- // Path doesn't do data
- if(this.pointsToData){
- this.data = this.pointsToData();
- }
- },
-
- onDelete: function(/* Stencil */ stencil){
- // summary:
- // Stub - fires before this is destroyed
- console.info("onDelete", this.id);
- },
-
- onBeforeRender: function(/*Object*/ stencil){
- // summary:
- // Stub - Fires before render occurs.
- },
-
- onModify: function(/*Object*/stencil){
- // summary:
- // Stub - fires on change of any property,
- // including style properties
-
- },
-
- onChangeData: function(/*Object*/ stencil){
- // summary:
- // Stub - fires on change of dimensional
- // properties or a text change
- },
-
- onChangeText: function(value){ // value or 'this' ?
- // summary:
- // Stub - fires on change of text in a
- // TextBlock tool only
- },
-
- onRender: function(/*Object*/ stencil){
- // summary:
- // Stub - Fires on creation.
- // Drawing connects to this (once!) to be
- // notified of drag completion. But only if it
- // was registered as a Tool. Creating Stencil in and of
- // itself does not register it.
- //
- // This should fire
- // at the *end* of creation (not during drag)
- //
- // FIXME:
- // This should probably be onCreate. It should
- // only fire once. But the mechanism for determining
- // this is more complicated than it sounds.
- //
- //if(!this._postRenderCon){
- this._postRenderCon = dojo.connect(this, "render", this, "_onPostRender");
- //}
- this.created = true;
- this.disconnectMouse();
-
- // for Silverlight
- if(this.shape){
- this.shape.superClass = this;
- }else{
- this.container.superClass = this;
- }
- this._setNodeAtts(this);
- //console.warn("ONRENDER", this.id, this)
- },
-
- onChangeStyle: function(/*Object*/stencil){
- // summary:
- // Fires when styles of shape has changed
- //
- this._isBeingModified = true; // need this to prevent onRender
- if(!this.enabled){
- this.style.current = this.style.disabled;
- this.style.currentText = this.style.textDisabled;
- this.style.currentHit = this.style.hitNorm;
-
- }else{
- this.style.current = this.style.norm;
- this.style.currentHit = this.style.hitNorm;
- this.style.currentText = this.style.text;
- }
-
- if(this.selected){
- if(this.useSelectedStyle){
- this.style.current = this.style.selected;
- this.style.currentText = this.textSelected;
- }
- this.style.currentHit = this.style.hitSelected;
-
- }else if(this.highlighted){
- //this.style.current = this.style.highlighted;
- this.style.currentHit = this.style.hitHighlighted;
- //this.style.currentText = this.style.textHighlighted;
- }
-
- // NOTE: Can't just change props like setStroke
- // because Silverlight throws error
- this.render();
- },
-
- animate: function(options, create){
- console.warn("ANIMATE..........................")
- var d = options.d || options.duration || 1000;
- var ms = options.ms || 20;
- var ease = options.ease || dojo.fx.easing.linear;
- var steps = options.steps;
- var ts = new Date().getTime();
- var w = 100;
- var cnt = 0;
- var isArray = true;
- var sp, ep;
-
- if(dojo.isArray(options.start)){
- sp = options.start;
- ep = options.end;
-
- }else if(dojo.isObject(options.start)){
- sp = options.start;
- ep = options.end;
- isArray = false;
- }else{
-
- console.warn("No data provided to animate")
- }
-
- var v = setInterval(dojo.hitch(this, function(){
- var t = new Date().getTime() - ts;
- var p = ease(1-t/d);
- if(t > d || cnt++ > 100){
- clearInterval(v);
- return;
- }
-
- if(isArray){
- var pnts = [];
- dojo.forEach(sp, function(pt, i){
-
- var o = {
- x: (ep[i].x-sp[i].x)*p + sp[i].x,
- y: (ep[i].y-sp[i].y)*p + sp[i].y
- };
- pnts.push(o);
- });
- this.setPoints(pnts);
- this.render();
-
- }else{
-
- var o = {};
- for(var nm in sp){
- o[nm] = (ep[nm] - sp[nm]) * p + sp[nm];
- }
-
- this.attr(o);
-
- }
- //console.dir(pnts)
-
-
- //this.attr("height", w);
- ////console.log("W:", w)
- //w += 5;
-
- }), ms);
- },
-
- attr: function(/*String | Object*/key, /* ? String | Number */value){
- // summary
- // Changes properties in the style or disabled styles,
- // depending on whether the object is enabled.
- // Also can be used to change most position and size props.
-
- // NOTE: JUST A SETTTER!! TODO!
-
- // WARNING:
- // Not doing any Stencil-type checking here. Setting a height
- // on a line or an angle on a rectangle will just not render.
-
- // FIXME
- // 'width' attr is used for line width. How to change the width of a stencil?
- var n = this.enabled?this.style.norm:this.style.disabled;
- var t = this.enabled?this.style.text:this.style.textDisabled;
- var ts = this.textSelected || {},
- o,
- nm,
- width,
- styleWas = dojo.toJson(n),
- textWas = dojo.toJson(t);
-
- var coords = {
- x:true,
- y:true,
- r:true,
- height:true,
- width:true,
- radius:true,
- angle:true
- };
- var propChange = false;
- if(typeof(key)!="object"){
- o = {};
- o[key] = value;
- }else{
- // prevent changing actual data
- o = dojo.clone(key);
- }
-
- if(o.width){
- // using width for size,
- // borderWidth should be used
- // for line thickness
- width = o.width;
- delete o.width;
- }
-
- for(nm in o){
- if(nm in n){ n[nm] = o[nm]; }
- if(nm in t){ t[nm] = o[nm]; }
- if(nm in ts){ ts[nm] = o[nm]; }
-
- if(nm in coords){
- coords[nm] = o[nm];
- propChange = true;
- if(nm == "radius" && o.angle===undefined){
- o.angle = coords.angle = this.getAngle();
- }else if(nm == "angle" && o.radius===undefined){
- o.radius = coords.radius = this.getRadius();
- }
-
- }
- if(nm == "text"){
- this.setText(o.text);
- }
- if(nm == "label"){
- this.setLabel(o.label);
- }
- }
- if(o.borderWidth!==undefined){
- n.width = o.borderWidth;
- }
- if(o.cosphi!=undefined){
- this.cosphi = o.cosphi;
- this.style.zAxis = o.cosphi!=0 ? true : false;
- }
- if(this.useSelectedStyle){
- // using the orginal selected style copy as
- // a reference map of what props to copy
- for(nm in this.style.norm){
- if(this.selCopy[nm]===undefined){
- this.style.selected[nm] = this.style.norm[nm];
- }
- }
- this.textSelected.color = this.style.selected.color;
-
- }
-
- if(!this.created){
- return;
- }
-
- // basic transform
- if(o.x!==undefined || o.y!==undefined){
- var box = this.getBounds(true);
- var mx = { dx:0, dy:0 };
- for(nm in o){
- if(nm=="x" || nm =="y" || nm =="r"){
- mx["d"+nm] = o[nm] - box[nm];
- }
- }
- this.transformPoints(mx);
- }
-
-
- var p = this.points;
- if(o.angle!==undefined){
- this.dataToPoints({
- x:this.data.x1,
- y:this.data.y1,
- angle:o.angle,
- radius:o.radius
- });
-
- } else if(width!==undefined){
- p[1].x = p[2].x = p[0].x + width;
- this.pointsToData(p);
- }
-
- if(o.height!==undefined && o.angle===undefined){
- console.log("Doing P2D-2");
- p[2].y = p[3].y = p[0].y + o.height;
- this.pointsToData(p);
- }
-
- if(o.r!==undefined){
- this.data.r = Math.max(0, o.r);
- }
-
- //console.dir(this.data);
- if(propChange || textWas!=dojo.toJson(t) || styleWas != dojo.toJson(n)){
- // to trigger the render
- // other events will be called post render
- this.onChangeStyle(this);
- }
- o.width = width;
- },
-
- exporter: function(){
- // summary:
- // Exports Stencil data
- //
- var type = this.type.substring(this.type.lastIndexOf(".")+1).charAt(0).toLowerCase()
- + this.type.substring(this.type.lastIndexOf(".")+2);
- var o = dojo.clone(this.style.norm);
- o.borderWidth = o.width;
- delete o.width;
- if(type=="path"){
- o.points = this.points;
- }else{
- o = dojo.mixin(o, this.data);
- }
- o.type = type;
- if(this.isText){
- o.text = this.getText();
- o = dojo.mixin(o, this.style.text);
- delete o.minWidth;
- delete o.deleteEmptyCreate;
- delete o.deleteEmptyModify;
- }
- var lbl = this.getLabel();
- if(lbl){
- o.label = lbl;
- }
- return o;
- },
-
-
- // TODO:
- // Makes these all called by att()
- // Should points and data be?
- //
- disable: function(){
- // summary:
- // Disables Stencil so it is not selectable.
- // Changes the color to the disabled style.
- this.enabled = false;
- this.renderHit = false;
- this.onChangeStyle(this);
- },
-
- enable: function(){
- // summary:
- // Enables Stencil so it is not selectable (if
- // it was selectable to begin with). Changes the
- // color to the current style.
- this.enabled = true;
- this.renderHit = true;
- this.onChangeStyle(this);
- },
-
- select: function(){
- // summary:
- // Called when the Stencil is selected.
- // NOTE: Calling this will not select the Stencil
- // calling this just sets the style to the 'selected'
- // theme. 'manager.Stencil' should be used for selecting
- // Stencils.
- //
- this.selected = true;
- this.onChangeStyle(this);
- },
-
- deselect: function(/*Boolean*/useDelay){
- // summary:
- // Called when the Stencil is deselected.
- // NOTE: Calling this will not deselect the Stencil
- // calling this just sets the style to the current
- // theme. 'manager.Stencil' should be used for selecting
- // and deselecting Stencils.
- //
- // arguments:
- // useDelay: Boolean
- // Adds slight delay before the style is set.
- //
- // should not have to render here because the deselection
- // re-renders after the transform
- // but... oh well.
- if(useDelay){
- setTimeout(dojo.hitch(this, function(){
- this.selected = false;
- this.onChangeStyle(this);
- }),200);
- }else{
- this.selected = false;
- this.onChangeStyle(this);
- }
- },
- _toggleSelected: function(){
- if(!this.selected){ return; }
- this.deselect();
- setTimeout(dojo.hitch(this, "select"), 0);
- },
-
- highlight: function(){
- // summary:
- // Changes style to the highlight theme.
- this.highlighted = true;
- this.onChangeStyle(this);
- },
-
- unhighlight: function(){
- // summary:
- // Changes style to the current theme.
- this.highlighted = false;
- this.onChangeStyle(this);
- },
-
- moveToFront: function(){
- // summary:
- // Moves Stencil to the front of all other items
- // on the canvas.
- this.container && this.container.moveToFront();
- },
-
- moveToBack: function(){
- // summary:
- // Moves Stencil to the back of all other items
- // on the canvas.
- this.container && this.container.moveToBack();
- },
-
- onTransformBegin: function(/* ? manager.Anchor */anchor){
- // summary:
- // Fired at the start of a transform. This would be
- // an anchor drag or a selection.
- //
- this._isBeingModified = true;
- },
-
- onTransformEnd: function(/* manager.Anchor */anchor){
- // summary:
- // Called from anchor point up mouse up
- this._isBeingModified = false;
- this.onModify(this);
- },
-
- onTransform: function(/* ? manager.Anchor */anchor){
- // summary:
- // Called from anchor point mouse drag
- // also called from plugins.Pan.checkBounds
- if(!this._isBeingModified){
- this.onTransformBegin();
- }
- // this is not needed for anchor moves, but it
- // is for stencil move:
- this.setPoints(this.points);
- this.render();
- },
-
- transformPoints: function(mx){
- // summary:
- // Moves object to a new X Y location
- // mx is additive. So mx.dx=1 will move the stencil
- // 1 pixel to the right from wherever it was.
- //
- // An attempt is made to prevent < 0 errors, but
- // this won't work on all shapes (like Axes)
- //
- if(!mx.dx && !mx.dy){
- // no change
- return;
- }
- var backup = dojo.clone(this.points), abort = false;
- dojo.forEach(this.points, function(o){
- o.x += mx.dx;
- o.y += mx.dy;
- if(o.x<this.marginZero || o.y<this.marginZero){
- abort = true;
- }
- });
- if(abort){
- this.points = backup;
- console.error("Attempt to set object '"+this.id+"' to less than zero.");
- return;
- }
- this.onTransform();
- this.onTransformEnd();
- },
-
- applyTransform: function(mx){
- // summary:
- // Applies the transform to the stencil
- // NOTE: PARTIALLY IMPLEMENTED
- // Only applies x y coords
- this.transformPoints(mx);
- },
-
- setTransform: function(/*Object*/mx){
- // summary:
- // Sets the transform to the stencil
- // NOTE: PARTIALLY IMPLEMENTED
- // Only applies x y coords
- this.attr({
- x:mx.dx,
- y:mx.dy
- });
- },
-
- getTransform: function(){
- // summary:
- // Returns the current transform (position) of the Stencil's
- // container
- return this.selected ? this.container.getParent().getTransform() : {dx:0, dy:0}; // Object
- },
-
- addShadow: function(/*Object*/args){
- args = args===true ? {} : args;
- args.stencil = this;
- this.shadow = new dojox.drawing.annotations.BoxShadow(args);
- },
-
- removeShadow: function(){
- this.shadow.destroy();
- },
-
- setLabel: function(/*String*/text){
- // summary:
- // Creates and sets a label annotation for the Stencil.
- // If Stencil contains a labelPosition method, that will
- // be used for positioning. Otherwise
- // dojox.drawing.util.positioning.label is used.
- // arguments:
- // text: String
- // The text to set as the label.
- //
- if(!this._label){
- this._label = new dojox.drawing.annotations.Label({
- text:text,
- util:this.util,
- mouse:this.mouse,
- stencil:this,
- annotation:true,
- container:this.container,
- labelPosition:this.labelPosition
- });
- }else if(text){
- this._label.setLabel(text);
- }
- },
-
- getLabel: function(){
- // summary:
- // Get the text of the label.
- //
- if(this._label){
- return this._label.getText(); // String
- }
- return null; //null
- },
-
- getAngle: function(){
- // summary:
- // Gets angle of Stencil
- // NOTE: Only works for Lines, Arrows, Vectors and Axes
- // (works on points, not transforms)
- var d = this.pointsToData();
- var obj = {
- start:{
- x:d.x1,
- y:d.y1
- },
- x:d.x2,
- y:d.y2
- };
- var angle = this.util.angle(obj, this.angleSnap);
- // converting the angle for display: -180 -> 180, -90 -> 270
- angle<0 ? angle = 360 + angle : angle;
- return angle;
- },
- getRadius: function(){
- // summary:
- // Gets radius (length) of Stencil
- // NOTE: Only works for Lines, Arrows, Vectors and Axes
- // (not for Ellipse)
- //
- var box = this.getBounds(true);
- var line = {start:{x:box.x1, y:box.y1}, x:box.x2, y:box.y2};
- return this.util.length(line);
- },
- getBounds: function(/* ? Boolean*/absolute){
- // summary:
- // Returns the coordinates of the Stencil. This is often
- // different than the data or the points.
- // arguments:
- // absolute: Boolean
- // Keeps lines from flipping (see note).
- //
- // NOTE: Won't work for paths or annotations (labels, Axes, arrow tips)
- // They should overwrite.</