root / trunk / web / dojo / dojox / drawing / tools / custom / Vector.js
History | View | Annotate | Download (6.18 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.drawing.tools.custom.Vector"]){ |
9 |
dojo._hasResource["dojox.drawing.tools.custom.Vector"]=true; |
10 |
dojo.provide("dojox.drawing.tools.custom.Vector");
|
11 |
dojo.require("dojox.drawing.tools.Arrow");
|
12 |
dojo.require("dojox.drawing.util.positioning");
|
13 |
dojox.drawing.tools.custom.Vector=dojox.drawing.util.oo.declare(dojox.drawing.tools.Arrow,function(_1){
|
14 |
this.minimumSize=this.style.arrows.length; |
15 |
this.addShadow({size:3,mult:2}); |
16 |
},{draws:true,type:"dojox.drawing.tools.custom.Vector",minimumSize:30,showAngle:true,labelPosition:function(){ |
17 |
var d=this.data; |
18 |
var pt=dojox.drawing.util.positioning.label({x:d.x1,y:d.y1},{x:d.x2,y:d.y2}); |
19 |
return {x:pt.x,y:pt.y}; |
20 |
},changeAxis:function(_2){ |
21 |
_2=_2!==undefined?_2:this.style.zAxis?0:1; |
22 |
if(_2==0){ |
23 |
this.style.zAxis=false; |
24 |
this.data.cosphi=0; |
25 |
}else{
|
26 |
this.style.zAxis=true; |
27 |
var p=this.points; |
28 |
var pt=this.zPoint(); |
29 |
this.setPoints([{x:p[0].x,y:p[0].y},{x:pt.x,y:pt.y}]); |
30 |
} |
31 |
this.render();
|
32 |
},_createZeroVector:function(_3,d,_4){ |
33 |
var s=_3=="hit"?this.minimumSize:this.minimumSize/6; |
34 |
var f=_3=="hit"?_4.fill:null; |
35 |
d={cx:this.data.x1,cy:this.data.y1,rx:s,ry:s}; |
36 |
this.remove(this[_3]); |
37 |
this[_3]=this.container.createEllipse(d).setStroke(_4).setFill(f); |
38 |
this.util.attr(this[_3],"drawingType","stencil"); |
39 |
},_create:function(_5,d,_6){ |
40 |
this.remove(this[_5]); |
41 |
this[_5]=this.container.createLine(d).setStroke(_6); |
42 |
this._setNodeAtts(this[_5]); |
43 |
},onDrag:function(_7){ |
44 |
if(this.created){ |
45 |
return;
|
46 |
} |
47 |
var x1=_7.start.x,y1=_7.start.y,x2=_7.x,y2=_7.y;
|
48 |
if(this.keys.shift&&!this.style.zAxis){ |
49 |
var pt=this.util.snapAngle(_7,45/180); |
50 |
x2=pt.x; |
51 |
y2=pt.y; |
52 |
} |
53 |
if(this.keys.alt){ |
54 |
var dx=x2>x1?((x2-x1)/2):((x1-x2)/-2); |
55 |
var dy=y2>y1?((y2-y1)/2):((y1-y2)/-2); |
56 |
x1-=dx; |
57 |
x2-=dx; |
58 |
y1-=dy; |
59 |
y2-=dy; |
60 |
} |
61 |
if(this.style.zAxis){ |
62 |
var _8=this.zPoint(_7); |
63 |
x2=_8.x; |
64 |
y2=_8.y; |
65 |
} |
66 |
this.setPoints([{x:x1,y:y1},{x:x2,y:y2}]); |
67 |
this.render();
|
68 |
},onTransform:function(_9){ |
69 |
if(!this._isBeingModified){ |
70 |
this.onTransformBegin();
|
71 |
} |
72 |
this.setPoints(this.points); |
73 |
this.render();
|
74 |
},anchorConstrain:function(x,y){ |
75 |
if(!this.style.zAxis){ |
76 |
return null; |
77 |
} |
78 |
var _a=this.style.zAngle*Math.PI/180; |
79 |
var _b=x<0?x>-y:x<-y; |
80 |
var dx=_b?x:-y/Math.tan(_a);
|
81 |
var dy=!_b?y:-Math.tan(_a)*x;
|
82 |
return {x:dx,y:dy}; |
83 |
},zPoint:function(_c){ |
84 |
if(_c===undefined){ |
85 |
if(!this.points[0]){ |
86 |
return null; |
87 |
} |
88 |
var d=this.pointsToData(); |
89 |
_c={start:{x:d.x1,y:d.y1},x:d.x2,y:d.y2}; |
90 |
} |
91 |
var _d=this.util.length(_c); |
92 |
var _e=this.util.angle(_c); |
93 |
_e<0?_e=360+_e:_e; |
94 |
_e=_e>135&&_e<315?this.style.zAngle:this.util.oppAngle(this.style.zAngle); |
95 |
return this.util.pointOnCircle(_c.start.x,_c.start.y,_d,_e); |
96 |
},pointsToData:function(p){ |
97 |
p=p||this.points;
|
98 |
var _f=0; |
99 |
var obj={start:{x:p[0].x,y:p[0].y},x:p[1].x,y:p[1].y}; |
100 |
if(this.style.zAxis&&(this.util.length(obj)>this.minimumSize)){ |
101 |
var _10=this.util.angle(obj); |
102 |
_10<0?_10=360+_10:_10; |
103 |
_f=_10>135&&_10<315?1:-1; |
104 |
} |
105 |
this.data={x1:p[0].x,y1:p[0].y,x2:p[1].x,y2:p[1].y,cosphi:_f}; |
106 |
return this.data; |
107 |
},dataToPoints:function(o){ |
108 |
o=o||this.data;
|
109 |
if(o.radius||o.angle){
|
110 |
var _11=0; |
111 |
var pt=this.util.pointOnCircle(o.x,o.y,o.radius,o.angle); |
112 |
if(this.style.zAxis||(o.cosphi&&o.cosphi!=0)){ |
113 |
this.style.zAxis=true; |
114 |
_11=o.angle>135&&o.angle<315?1:-1; |
115 |
} |
116 |
this.data=o={x1:o.x,y1:o.y,x2:pt.x,y2:pt.y,cosphi:_11}; |
117 |
} |
118 |
this.points=[{x:o.x1,y:o.y1},{x:o.x2,y:o.y2}]; |
119 |
return this.points; |
120 |
},render:function(){ |
121 |
this.onBeforeRender(this); |
122 |
if(this.getRadius()>=this.minimumSize){ |
123 |
this._create("hit",this.data,this.style.currentHit); |
124 |
this._create("shape",this.data,this.style.current); |
125 |
}else{
|
126 |
this.data.cosphi=0; |
127 |
this._createZeroVector("hit",this.data,this.style.currentHit); |
128 |
this._createZeroVector("shape",this.data,this.style.current); |
129 |
} |
130 |
},onUp:function(obj){ |
131 |
if(this.created||!this._downOnCanvas){ |
132 |
return;
|
133 |
} |
134 |
this._downOnCanvas=false; |
135 |
if(!this.shape){ |
136 |
var d=100; |
137 |
obj.start.x=this.style.zAxis?obj.start.x+d:obj.start.x;
|
138 |
obj.y=obj.y+d; |
139 |
this.setPoints([{x:obj.start.x,y:obj.start.y},{x:obj.x,y:obj.y}]); |
140 |
this.render();
|
141 |
} |
142 |
if(this.getRadius()<this.minimumSize){ |
143 |
var p=this.points; |
144 |
this.setPoints([{x:p[0].x,y:p[0].y},{x:p[0].x,y:p[0].y}]); |
145 |
}else{
|
146 |
var p=this.points; |
147 |
var pt=this.style.zAxis?this.zPoint(obj):this.util.snapAngle(obj,this.angleSnap/180); |
148 |
this.setPoints([{x:p[0].x,y:p[0].y},{x:pt.x,y:pt.y}]); |
149 |
} |
150 |
this.renderedOnce=true; |
151 |
this.onRender(this); |
152 |
}}); |
153 |
dojox.drawing.tools.custom.Vector.setup={name:"dojox.drawing.tools.custom.Vector",tooltip:"Vector Tool",iconClass:"iconVector"}; |
154 |
if(dojox.drawing.defaults.zAxisEnabled){
|
155 |
dojox.drawing.tools.custom.Vector.setup.secondary={name:"vectorSecondary",label:"z-axis",funct:function(_12){ |
156 |
_12.selected?this.zDeselect(_12):this.zSelect(_12); |
157 |
var _13=this.drawing.stencils.selectedStencils; |
158 |
for(var nm in _13){ |
159 |
if(_13[nm].shortType=="vector"&&(_13[nm].style.zAxis!=dojox.drawing.defaults.zAxis)){ |
160 |
var s=_13[nm];
|
161 |
s.changeAxis(); |
162 |
if(s.style.zAxis){
|
163 |
s.deselect(); |
164 |
s.select(); |
165 |
} |
166 |
} |
167 |
} |
168 |
},setup:function(){ |
169 |
var _14=dojox.drawing.defaults.zAxis;
|
170 |
this.zSelect=function(_15){ |
171 |
if(!_15.enabled){
|
172 |
return;
|
173 |
} |
174 |
_14=true;
|
175 |
dojox.drawing.defaults.zAxis=true;
|
176 |
_15.select(); |
177 |
this.vectorTest();
|
178 |
this.zSelected=_15;
|
179 |
}; |
180 |
this.zDeselect=function(_16){ |
181 |
if(!_16.enabled){
|
182 |
return;
|
183 |
} |
184 |
_14=false;
|
185 |
dojox.drawing.defaults.zAxis=false;
|
186 |
_16.deselect(); |
187 |
this.vectorTest();
|
188 |
this.zSelected=null; |
189 |
}; |
190 |
this.vectorTest=function(){ |
191 |
dojo.forEach(this.buttons,function(b){ |
192 |
if(b.toolType=="vector"&&b.selected){ |
193 |
this.drawing.currentStencil.style.zAxis=_14;
|
194 |
} |
195 |
},this);
|
196 |
}; |
197 |
dojo.connect(this,"onRenderStencil",this,function(){ |
198 |
if(this.zSelected){ |
199 |
this.zDeselect(this.zSelected); |
200 |
} |
201 |
}); |
202 |
var c=dojo.connect(this.drawing,"onSurfaceReady",this,function(){ |
203 |
dojo.disconnect(c); |
204 |
dojo.connect(this.drawing.stencils,"onSelect",this,function(_17){ |
205 |
if(_17.shortType=="vector"){ |
206 |
if(_17.style.zAxis){
|
207 |
dojo.forEach(this.buttons,function(b){ |
208 |
if(b.toolType=="vectorSecondary"){ |
209 |
this.zSelect(b);
|
210 |
} |
211 |
},this);
|
212 |
}else{
|
213 |
dojo.forEach(this.buttons,function(b){ |
214 |
if(b.toolType=="vectorSecondary"){ |
215 |
this.zDeselect(b);
|
216 |
} |
217 |
},this);
|
218 |
} |
219 |
} |
220 |
}); |
221 |
}); |
222 |
},postSetup:function(btn){ |
223 |
dojo.connect(btn,"enable",function(){ |
224 |
dojox.drawing.defaults.zAxisEnabled=true;
|
225 |
}); |
226 |
dojo.connect(btn,"disable",function(){ |
227 |
dojox.drawing.defaults.zAxisEnabled=false;
|
228 |
}); |
229 |
}}; |
230 |
} |
231 |
dojox.drawing.register(dojox.drawing.tools.custom.Vector.setup,"tool");
|
232 |
} |