1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
|
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script lang='Javascript'>
// Canvas
var acanvas;
var context;
// Clickstate 0 == No Click Clickstate 1 == Click Clickstate 2 == Drag !!??
// Startx/Starty contain coordinate for drag start
// Deltax/Deltay contain current distance from start
var clickstate=0;
var startx=0,starty=0;
var deltax=0,deltay=0;
var gridsize=20;
var gridx,gridy=0;
// Multi-select move offset
var offsx=0;
var offsy=0;
// Drawing Globals -- For while in transit drawing
var drawlinesx,drawlinesy;
var drawlinedx,drawlinedy;
var drawlinekind=0;
// List of objects
// List of identifiers
// List of selected object identifiers
// The context object
var Objects = new Array();
var Selected = new Array();
var Identifiers = new Array();
var ContextObj;
// Mouse Down Result
var downRes;
// User Interface Mode Variables
var multiselect=0;
var dragsensitivity=12;
var printstr;
/*
User interface callbacks
*/
function handler_mouseup()
{
if(clickstate==1){
// Either select on/off for multi or single select
if(multiselect){
if(Selected[downRes.objid]){
Selected[downRes.objid]=false;
}else{
Selected[downRes.objid]=true;
}
}else{
if(ContextObj==downRes.objid){
ContextObj="";
}else{
ContextObj=downRes.objid;
}
}
}else if(clickstate==8){
// Draw Attribute Line
upRes=mouseover(gridx,gridy);
if(upRes.code!="None"){
obj=Objects[downRes.objid];
if(upRes.typ=="ERAttribute"||upRes.typ=="Entity"||upRes.typ=="ERRel"){
obj.DrawtoID=upRes.objid;
obj.DrawfromSide = downRes.side;
if(upRes.side!="None"){
obj.DrawtoSide = upRes.side;
obj.DrawtoPerc = upRes.sideperc;
}else{
upobj=Objects[downRes.objid];
var sid=1;
var perco=0.5;
var x1g=Math.abs(upRes.x1-gridx);
var x2g=Math.abs(upRes.x2-gridx);
var y1g=Math.abs(upRes.y1-gridy);
var y2g=Math.abs(upRes.y2-gridy);
if(x1g<=x2g&&x1g<=y1g&&x1g<=y2g){
sid=1;
perco=makesideperc(gridy,upRes.y1,upRes.y2);
}else if(x2g<=x1g&&x2g<=y1g&&x2g<=y2g){
sid=3;
perco=makesideperc(gridy,upRes.y1,upRes.y2);
}else if(y1g<=x1g&&y1g<=x2g&&y1g<=y2g){
sid=4;
perco=makesideperc(gridx,upRes.x1,upRes.x2);
}else if(y2g<=x1g&&y2g<=x2g&&y2g<=y1g){
sid=2;
perco=makesideperc(gridx,upRes.x1,upRes.x2);
}
obj.DrawtoSide = sid;
obj.DrawtoPerc = perco;
}
if(upRes.typ=="ERAttribute"||upRes.typ=="ERRel") obj.DrawtoPerc=0.5;
}
}
}else if(clickstate==9){
// Draw Relationship line
upRes=mouseover(gridx,gridy);
if(upRes.code!="None"){
obj=Objects[downRes.objid];
if(upRes.side!="None"){
if(obj.DrawtoID=="None"){
obj.DrawtoID=upRes.objid;
obj.DrawtoSide = upRes.side;
obj.DrawtoPerc = upRes.sideperc;
obj.DrawfromSide = downRes.side;
}else{
obj.DrawtoIDDest=upRes.objid;
obj.DrawtoSideDest = upRes.side;
obj.DrawtoPercDest = upRes.sideperc;
obj.DrawfromSideDest = downRes.side;
}
}else{
upobj=Objects[downRes.objid];
var sid=1;
var perco=0.5;
var x1g=Math.abs(upRes.x1-gridx);
var x2g=Math.abs(upRes.x2-gridx);
var y1g=Math.abs(upRes.y1-gridy);
var y2g=Math.abs(upRes.y2-gridy);
if(x1g<=x2g&&x1g<=y1g&&x1g<=y2g){
sid=1;
perco=makesideperc(gridy,upRes.y1,upRes.y2);
}else if(x2g<=x1g&&x2g<=y1g&&x2g<=y2g){
sid=3;
perco=makesideperc(gridy,upRes.y1,upRes.y2);
}else if(y1g<=x1g&&y1g<=x2g&&y1g<=y2g){
sid=4;
perco=makesideperc(gridx,upRes.x1,upRes.x2);
}else if(y2g<=x1g&&y2g<=x2g&&y2g<=y1g){
sid=2;
perco=makesideperc(gridx,upRes.x1,upRes.x2);
}
if(obj.DrawtoID=="None"){
obj.DrawtoID=upRes.objid;
obj.DrawtoSide = sid;
obj.DrawtoPerc = perco;
obj.DrawfromSide = downRes.side;
}else{
obj.DrawtoIDDest=upRes.objid;
obj.DrawtoSideDest = sid;
obj.DrawtoPercDest = perco;
obj.DrawfromSideDest = downRes.side;
}
}
}
}
clickstate=0;
cpsel=0;
drawlinekind=0;
}
function handler_mousedown()
{
clickstate=1;
downRes=mouseover(gridx,gridy);
startx=gridx;
starty=gridy;
// Mouse Down State
}
function handler_mousemove(cx,cy)
{
// gridx=Math.round((cx-(gridsize/2.0))/gridsize)*gridsize;
// gridy=Math.round((cy-(gridsize/2.0))/gridsize)*gridsize;
gridx=cx;
gridy=cy;
deltax=startx-gridx;
deltay=starty-gridy;
// We start drag mode
if((distance(gridx,gridy,startx,starty)>dragsensitivity)&&clickstate==1){
clickstate=2;
}
// We are in drag mode
if(clickstate==2){
// Single Object Move - If Not Selected, Or if Selected and Center Area Is Dragged
if((downRes.typ=="Entity"||downRes.typ=="ERAttribute"||downRes.typ=="ERRel")&&(downRes.code=="NonSel"||(downRes.code=="Cont"&&downRes.side=="None")||(downRes.code=="ContDraw"&&downRes.side=="None"))){
clickstate=3;
}
if((downRes.typ=="Entity"||downRes.typ=="ERAttribute")&&(downRes.code=="Cont"&&downRes.side=="1")) clickstate=4; // Single Object Scale Left
if((downRes.typ=="Entity"||downRes.typ=="ERAttribute")&&(downRes.code=="Cont"&&downRes.side=="2")) clickstate=5; // Single Object Scale Bottom
if((downRes.typ=="Entity"||downRes.typ=="ERAttribute")&&(downRes.code=="Cont"&&downRes.side=="3")) clickstate=6; // Single Object Scale Right
if((downRes.typ=="Entity"||downRes.typ=="ERAttribute")&&(downRes.code=="Cont"&&downRes.side=="4")) clickstate=7; // Single Object Scale Top
if(downRes.typ=="ERAttribute"&&downRes.code=="ContDraw"&&downRes.side!="None"){
clickstate=8; // Attribute Connection Draw
drawlinekind=1; // Tell drawing engine to draw attribute line symbol
if(downRes.side=="1"){
drawlinesx=downRes.x1; // Initiate start parameters for line drawing left side
drawlinesy=downRes.y1+((downRes.y2-downRes.y1)*0.5);
}else if(downRes.side=="2"){
drawlinesx=downRes.x1+((downRes.x2-downRes.x1)*0.5); // Initiate start parameters for line drawing bottom side
drawlinesy=downRes.y2;
}else if(downRes.side=="3"){
drawlinesx=downRes.x2; // Initiate start parameters for line drawing left side
drawlinesy=downRes.y1+((downRes.y2-downRes.y1)*0.5);
}else if(downRes.side=="4"){
drawlinesx=downRes.x1+((downRes.x2-downRes.x1)*0.5); // Initiate start parameters for line drawing bottom side
drawlinesy=downRes.y1;
}
drawlinedx=drawlinesx;
drawlinedy=drawlinesy;
}
if(downRes.typ=="ERRel"&&downRes.code=="ContDraw"&&downRes.side!="None"){
var obj=Objects[downRes.objid];
if(downRes.side!=obj.DrawfromSide&&downRes.side!=obj.DrawfromSideDest){
clickstate=9; // Attribute Connection Draw
drawlinekind=1; // Tell drawing engine to draw relation line symbol
if(downRes.side=="1"){
drawlinesx=downRes.x1; // Initiate start parameters for line drawing left side
drawlinesy=downRes.y1+((downRes.y2-downRes.y1)*0.5);
}else if(downRes.side=="2"){
drawlinesx=downRes.x1+((downRes.x2-downRes.x1)*0.5); // Initiate start parameters for line drawing bottom side
drawlinesy=downRes.y2;
}else if(downRes.side=="3"){
drawlinesx=downRes.x2; // Initiate start parameters for line drawing left side
drawlinesy=downRes.y1+((downRes.y2-downRes.y1)*0.5);
}else if(downRes.side=="4"){
drawlinesx=downRes.x1+((downRes.x2-downRes.x1)*0.5); // Initiate start parameters for line drawing bottom side
drawlinesy=downRes.y1;
}
drawlinedx=drawlinesx;
drawlinedy=drawlinesy;
}
}
}
if(clickstate>2){
var obj=Objects[downRes.objid];
}
if(clickstate==3){ // We are in single rectangular object move
obj.x1=downRes.x1-deltax;
obj.y1=downRes.y1-deltay;
obj.x2=downRes.x2-deltax;
obj.y2=downRes.y2-deltay;
}else if(clickstate==4){ // We are in single rectangular object scale left
if((obj.x2-downRes.x1+deltax)>60) obj.x1=downRes.x1-deltax;
}else if(clickstate==5){ // We are in single rectangular object scale bottom
if((downRes.y2-obj.y1-deltay)>40) obj.y2=downRes.y2-deltay;
}else if(clickstate==6){ // We are in single rectangular object scale right
if((downRes.x2-obj.x1-deltax)>60) obj.x2=downRes.x2-deltax;
}else if(clickstate==7){ // We are in single rectangular object scale top
if((obj.y2-downRes.y1+deltay)>40) obj.y1=downRes.y1-deltay;
}else if(clickstate==8||clickstate==9){ // We are in straight connective line drawing mode
drawlinedx=gridx;
drawlinedy=gridy;
}
}
// Call-forward for mouse-over event
function mouseover(x,y)
{
// Code of touch, and if available object id and id of side of object that was touched
// Tolerances included as constant
var sidetol=12;
var obj_code="None";
var obj_id="None";
var obj_sidentifier="None";
var obj_sideperc=0;
var obj_centerdist=0;
var obj_type="None";
var obj_x1=0; var obj_y1=0; var obj_x2=0; var obj_y2=0;
var Cont;
var found=0;
var side;
for(j=0;j<Identifiers.length;j++){
var objid=Identifiers[j];
var obj=Objects[objid];
var Sel=Selected[objid];
if(ContextObj==objid) Cont=1
else Cont=0;
// Compute coordinates including offset
if(obj.type=="Entity"||obj.type=="ERAttribute"||obj.type=="ERRel"){
x1=obj.x1+offsx;
y1=obj.y1+offsy;
x2=obj.x2+offsx;
y2=obj.y2+offsy;
rx=(x2-x1)*0.5;
ry=(y2-y1)*0.5;
}
found=0;
// For each kind of clickable object, check if we are inside object and if so assign variables
// Any general properties for all object types are set when "found" is true
if(obj.type=="Entity"){
if(x>(x1-sidetol)&&y>(y1-sidetol)&&x<(x2+sidetol)&&y<(y2+sidetol)){
obj_code="NonSel";
if(Sel) obj_code="Sel";
if(Cont) obj_code="Cont";
side=computeside(x,y,x1,y1,x2,y2,sidetol);
obj_sidentifier=side.side;
obj_sideperc=side.perc;
obj_centerdist=side.dist;
found=1;
}
}else if(obj.type=="ERAttribute"){
if(x>(x1-sidetol)&&y>(y1-sidetol)&&x<(x2+sidetol)&&y<(y2+sidetol)){
obj_code="NonSel";
if(Sel) obj_code="Sel";
if(Cont){
if(obj.DrawtoID=="None"){
obj_code="ContDraw";
}else{
obj_code="Cont";
}
}
side=computeside(x,y,x1,y1,x2,y2,sidetol);
obj_sidentifier=side.side;
obj_sideperc=side.perc;
obj_centerdist=side.dist;
found=1;
}
}else if(obj.type=="ERRel"){
if(x>(x1-sidetol)&&y>(y1-sidetol)&&x<(x2+sidetol)&&y<(y2+sidetol)){
xk=x-x1;
// Colision detection against diamond
var inside=0;
if(xk<=rx){
if(y>(y1+ry-xk-sidetol)&&y<(y1+ry+xk+sidetol)) inside=1;
}else{
if(y>(y1-rx+xk-sidetol)&&y<(y2+rx-xk+sidetol)) inside=1;
}
if(inside){
if((x>(x1-sidetol))&&(x<(x1+sidetol))&&(y>(y1+ry-sidetol))&&(y<(y1+ry+sidetol))) obj_sidentifier=1;
if((x>(x1+rx-sidetol))&&(x<(x1+rx+sidetol))&&(y>(y2-sidetol))&&(y<(y2+sidetol))) obj_sidentifier=2;
if((x>(x2-sidetol))&&(x<(x2+sidetol))&&(y>(y1+ry-sidetol))&&(y<(y1+ry+sidetol))) obj_sidentifier=3;
if((x>(x1+rx-sidetol))&&(x<(x1+rx+sidetol))&&(y>(y1-sidetol))&&(y<(y1+sidetol))) obj_sidentifier=4;
obj_code="NonSel";
if(Sel) obj_code="Sel";
if(Cont){
if(obj.DrawtoID=="None"){
obj_code="ContDraw";
}else if(obj.DrawtoIDDest=="None"){
obj_code="ContDraw";
}else{
obj_code="Cont";
}
}
obj_sideperc=0.5;
found=1;
}
}
}
if(found==1){
// Save coordinates at time of click
obj_x1=x1;
obj_y1=y1;
obj_x2=x2;
obj_y2=y2;
obj_id=objid;
obj_type=obj.type;
printstr=obj_id+" "+obj_sidentifier+" "+obj_sideperc;
}
}
return {
objid:obj_id,
code:obj_code,
side:obj_sidentifier,
sideperc:obj_sideperc,
centerdist:obj_centerdist,
typ:obj_type,
x1:obj_x1,
y1:obj_y1,
x2:obj_x2,
y2:obj_y2
}
}
function importdata()
{
for(i=0;i<7;i++){
if(i==0) obj = jQuery.parseJSON('{"type":"ERAttribute","id":"ATT1","kind":"Multiple","name":"Address","x1":220,"y1":100,"x2":300,"y2":140, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"None", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":""}');
if(i==1) obj = jQuery.parseJSON('{"type":"Entity","id":"ENT2","kind":"Weak","name":"Car","x1":100,"y1":160,"x2":220,"y2":220}');
if(i==2) obj = jQuery.parseJSON('{"type":"ERAttribute","id":"ATT3","kind":"Key","name":"SSN","x1":160,"y1":260,"x2":260,"y2":300, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"None", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":""}');
if(i==3) obj = jQuery.parseJSON('{"type":"Entity","id":"ENT4","kind":"Strong","name":"Trailer","x1":320,"y1":260,"x2":420,"y2":320}');
if(i==4) obj = jQuery.parseJSON('{"type":"Entity","id":"ENT5","kind":"Strong","name":"Grail","x1":120,"y1":440,"x2":220,"y2":480}');
if(i==5) obj = jQuery.parseJSON('{"type":"ERRel","id":"REL6","kind":"Strong","name":"Fool","x1":460,"y1":160,"x2":520,"y2":220, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoIDDest":"None", "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
if(i==6) obj = jQuery.parseJSON('{"type":"ERRel","id":"REL7","kind":"Weak","name":"Drool","x1":360,"y1":360,"x2":420,"y2":420, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoIDDest":"None", "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
objid=obj.id;
Objects[objid]=obj;
Identifiers.push(objid);
}
}
// prepareobj
// Prepares all kinds of objects, with local movement-offset (scrolling offset is handled with transforms??)
// Ofss in prepare are not finished.
function prepareobj(obji)
{
var fromobj=Objects[obji];
// Attributes are prepared by re-pointing the DrawX1, DrawY1, DrawX2 and DrawY2 variables and Relationships are prepared by re-pointing DrawX1-DrawX4 and DrawY1-DrawY4
if((fromobj.type=="ERAttribute"||fromobj.type=="ERRel")&&fromobj.DrawtoID!="None"){
var toid=fromobj.DrawtoID;
var toobj=Objects[toid];
var sidek;
if(fromobj.DrawtoIDDest!="None"&&fromobj.DrawtoIDDest!=undefined){
var toiddest=fromobj.DrawtoIDDest;
var toobjdest=Objects[toiddest];
sidek=makeside(fromobj.DrawfromSideDest,fromobj.x1,fromobj.y1,fromobj.x2,fromobj.y2,0.5);
fromobj.DrawX3=sidek.x;
fromobj.DrawY3=sidek.y;
sidek=makeside(fromobj.DrawtoSideDest,toobjdest.x1,toobjdest.y1,toobjdest.x2,toobjdest.y2,fromobj.DrawtoPercDest);
fromobj.DrawX4=sidek.x;
fromobj.DrawY4=sidek.y;
}
//printstr=fromobj.DrawfromSide+" "+fromobj.x1+" "+fromobj.y1+" "+fromobj.x2+" "+fromobj.y2+" :: "+fromobj.DrawtoSide+" "+toobj.x1+" "+toobj.y1+" "+toobj.x2+" "+toobj.y2+" "+fromobj.DrawtoPerc;
sidek=makeside(fromobj.DrawfromSide,fromobj.x1,fromobj.y1,fromobj.x2,fromobj.y2,0.5);
fromobj.DrawX1=sidek.x;
fromobj.DrawY1=sidek.y;
sidek=makeside(fromobj.DrawtoSide,toobj.x1,toobj.y1,toobj.x2,toobj.y2,fromobj.DrawtoPerc);
fromobj.DrawX2=sidek.x;
fromobj.DrawY2=sidek.y;
}
}
// Drawobj
// Draws all kinds of objects, with local movement-offset (scrolling offset is handled with transforms??)
function drawobj(obji)
{
var obj=Objects[obji];
var Sel=Selected[obji];
if(ContextObj==obji) Cont=1
else Cont=0;
context.strokeStyle = '#000';
context.lineWidth = 2.0;
// Compute coordinates including offset
if(obj.type=="Entity"||obj.type=="ERAttribute"||obj.type=="ERRel"){
x1=obj.x1+offsx;
y1=obj.y1+offsy;
x2=obj.x2+offsx;
y2=obj.y2+offsy;
rx=(x2-x1)*0.5;
ry=(y2-y1)*0.5;
}
if(obj.type=="Entity"){
//Draw Local Graphic
context.strokeRect(x1,y1,x2-x1,y2-y1);
if(obj.kind=="Weak"){
context.strokeRect(x1+5,y1+5,x2-x1-10,y2-y1-10);
}
context.font = "20px Calibri";
context.textAlign = "center";
context.fillStyle = "#000";
context.fillText(obj.name, x1+rx, y2-ry+6);
// Draw Select Marker
if(Sel||Cont){
fourpoints(x1,y1+ry,x2,y1+ry,x1+rx,y1,x1+rx,y2,"#5f8");
}
}else if(obj.type=="ERAttribute"){
drawellipse(x1,y1,x2,y2);
context.font = "20px Calibri";
context.textAlign = "center";
context.fillStyle = "#000";
context.fillText(obj.name, x1+rx, y2-ry+6);
if(obj.DrawtoID!="None"){
drawline(obj.DrawX1,obj.DrawY1,obj.DrawX2,obj.DrawY2,"#000",2.0);
}
if(obj.kind=="Key"){
var metrics = context.measureText(obj.name);
var w = Math.round(metrics.width/2.0);
drawline(x1+rx-w,y2-ry+10,x1+rx+w,y2-ry+10,"#000",2.0);
}
// Draw Select Marker
if(Cont&&obj.DrawtoID=="None"){
fourpoints(x1,y1+ry,x2,y1+ry,x1+rx,y1,x1+rx,y2,"#fa2");
}else if(Sel||(Cont&&obj.DrawtoID!="None")){
fourpoints(x1,y1+ry,x2,y1+ry,x1+rx,y1,x1+rx,y2,"#5f8");
}
}else if(obj.type=="ERRel"){
if(obj.DrawtoID!="None"){
drawline(obj.DrawX1,obj.DrawY1,obj.DrawX2,obj.DrawY2,"#000",2.0);
}
if(obj.DrawtoIDDest!="None"){
drawline(obj.DrawX3,obj.DrawY3,obj.DrawX4,obj.DrawY4,"#000",2.0);
}
if(obj.kind=="Weak"){
drawdiamond(x1,y1,rx,ry,4);
drawdiamond(x1,y1,rx,ry,-4);
}else{
drawdiamond(x1,y1,rx,ry,0);
}
context.font = "20px Calibri";
context.textAlign = "center";
context.fillStyle = "#000";
context.fillText(obj.name, x1+rx, y2-ry+6);
if(Sel||(Cont&&obj.DrawtoID!="None"&&obj.DrawtoIDDest!="None")){
fourpoints(x1,y1+ry,x2,y1+ry,x1+rx,y1,x1+rx,y2,"#5f8");
}else if(Cont){
if(obj.DrawfromSide!=1&&obj.DrawfromSideDest!=1) point("#fa2",x1,y1+ry);
if(obj.DrawfromSide!=2&&obj.DrawfromSideDest!=2) point("#fa2",x1+rx,y2);
if(obj.DrawfromSide!=3&&obj.DrawfromSideDest!=3) point("#fa2",x2,y1+ry);
if(obj.DrawfromSide!=4&&obj.DrawfromSideDest!=4) point("#fa2",x1+rx,y1);
}
}
}
importdata();
function foo()
{
context.clearRect(0,0,600,600);
// Draw grid lines
context.strokeStyle = '#ddd';
context.lineWidth = 0.5;
context.beginPath();
for(i=0;i<600;i+=20){
context.moveTo(i,0);
context.lineTo(i,600);
context.moveTo(0,i);
context.lineTo(600,i);
}
context.stroke();
// Draw drawing line
if(drawlinekind==1){
drawline(drawlinesx,drawlinesy,drawlinedx,drawlinedy,"#000",1.0);
}
// Prepare model objects
for(i=0;i<Identifiers.length;i++){
var objid=Identifiers[i];
prepareobj(objid);
}
// Draw model objects
for(i=0;i<Identifiers.length;i++){
var objid=Identifiers[i];
drawobj(objid);
}
// Draw Crosshair
context.beginPath();
context.strokeStyle = '#444';
context.lineWidth = 1.0;
context.moveTo(gridx-gridsize,gridy);
context.lineTo(gridx+gridsize,gridy);
context.moveTo(gridx,gridy-gridsize);
context.lineTo(gridx,gridy+gridsize);
context.stroke();
context.strokeStyle = '#ddd';
context.fillStyle='#000';
context.font = "bold 16px Arial";
context.textAlign = "left";
context.fillText("currop: "+printstr, 20, 576);
setTimeout("foo();",100);
}
</script>
<script type="text/javascript" src="dugga.js"></script>
</head>
<body onload="setupcanvas();">
<table>
<tr>
<td>
<canvas id='a' width='600' height='600' style='border:2px solid black;'>
</canvas>
</td>
<td valign="top">
<div style="border:2px solid black;background-color:#fed;width:300;height:450;">
<div id="infobox" style="padding:4px;">
Change values to update diagram.<br>
</div>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>
|