/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to ErModeller/canvas.js

  • Committer: Erik Wikström
  • Date: 2013-04-09 09:21:05 UTC
  • mto: (21.1.1 lenasys)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: wikxen@gmail.com-20130409092105-u1u3gxbql1vx65a7
Added missing WebGL javascript files, moved bothe them and the existing ones to /js. Updated references

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var startx = 0;
 
2
var starty = 0;
 
3
var deltax = 0;
 
4
var deltay = 0; 
 
5
var gridsize = 20;
 
6
 
 
7
// Multi-select move offset
 
8
var offsx = 0;
 
9
var offsy = 0;
 
10
 
 
11
// Drawing Globals -- For while in transit drawing
 
12
var drawlinesx;
 
13
var drawlinesy;
 
14
var drawlinedx;
 
15
var drawlinedy;
 
16
var drawlinekind = 0;
 
17
 
 
18
// List of objects
 
19
var Objects = new Array();
 
20
 
 
21
// List of identifiers 
 
22
var Selected = new Array();
 
23
 
 
24
// List of selected object identifiers 
 
25
var Identifiers = new Array();
 
26
 
 
27
// The context object
 
28
var ContextObj;
 
29
 
 
30
// Mouse Down Result
 
31
var downRes;
 
32
// User Interface Mode Variables
 
33
var multiselect = 0;
 
34
var dragsensitivity = 12;
 
35
var sidetol = 12;
 
36
var printstr;
 
37
 
 
38
/*
 
39
 *  User interface callbacks
 
40
 */
 
41
function handler_mouseup() {
 
42
        if(clickstate == 1) {
 
43
 
 
44
                // Either select on/off for multi or single select
 
45
                if(multiselect) {
 
46
                        if(Selected[downRes.objid]) {
 
47
                                Selected[downRes.objid] = false;
 
48
                        } else {
 
49
                                Selected[downRes.objid] = true;
 
50
                        }
 
51
                } else {
 
52
                        if(ContextObj == downRes.objid) {
 
53
                                        ContextObj = "";
 
54
                        } else {
 
55
                                ContextObj = downRes.objid;
 
56
                        }
 
57
                }
 
58
        } else if(clickstate == 8) {
 
59
 
 
60
                // Draw Attribute Line
 
61
                upRes=mouseover(gridx,gridy);
 
62
                if(upRes.code != "None") {
 
63
                        obj = Objects[downRes.objid];
 
64
                        if(upRes.typ == "ERAttribute" || upRes.typ == "Entity" || upRes.typ == "ERRel") {
 
65
                                obj.DrawtoID = upRes.objid;
 
66
                                obj.DrawfromSide = downRes.side;
 
67
                                if(upRes.side != "None") {
 
68
                                        obj.DrawtoSide = upRes.side;
 
69
                                        obj.DrawtoPerc = upRes.sideperc;
 
70
                                } else {
 
71
                                        upobj = Objects[downRes.objid];
 
72
                                        var sid = 1;
 
73
                                        var     perco = 0.5;
 
74
                                        var x1g = Math.abs(upRes.x1 - gridx);
 
75
                                        var x2g = Math.abs(upRes.x2 - gridx);
 
76
                                        var y1g = Math.abs(upRes.y1 - gridy);
 
77
                                        var y2g = Math.abs(upRes.y2 - gridy);
 
78
                                        if(x1g <= x2g && x1g <= y1g && x1g <= y2g){
 
79
                                                sid = 1;
 
80
                                                perco = makesideperc(gridy, upRes.y1, upRes.y2);
 
81
                                        } else if(x2g <= x1g && x2g <= y1g && x2g <= y2g){
 
82
                                                sid = 3;
 
83
                                                perco = makesideperc(gridy, upRes.y1, upRes.y2);
 
84
                                        } else if(y1g <= x1g && y1g <= x2g && y1g <= y2g){
 
85
                                                sid = 4;
 
86
                                                perco = makesideperc(gridx, upRes.x1, upRes.x2);
 
87
                                        } else if(y2g <= x1g && y2g <= x2g && y2g <= y1g){
 
88
                                                sid = 2;
 
89
                                                perco = makesideperc(gridx, upRes.x1, upRes.x2);
 
90
                                        }
 
91
                                        obj.DrawtoSide = sid;
 
92
                                        obj.DrawtoPerc = perco;
 
93
                                }
 
94
                                if(upRes.typ == "ERAttribute" || upRes.typ == "ERRel") obj.DrawtoPerc = 0.5;
 
95
                        }
 
96
                }
 
97
        } else if(clickstate == 9) {
 
98
 
 
99
                // Draw Relationship line
 
100
                upRes = mouseover(gridx, gridy);
 
101
                if(upRes.code != "None") {
 
102
                        obj = Objects[downRes.objid];
 
103
                        if(upRes.side != "None") {
 
104
                                if(obj.DrawtoID == "None") {
 
105
                                        obj.DrawtoID = upRes.objid;
 
106
                                        obj.DrawtoSide = upRes.side;
 
107
                                        obj.DrawtoPerc = upRes.sideperc;
 
108
                                        obj.DrawfromSide = downRes.side;
 
109
                                } else {
 
110
                                        obj.DrawtoIDDest = upRes.objid;
 
111
                                        obj.DrawtoSideDest = upRes.side;
 
112
                                        obj.DrawtoPercDest = upRes.sideperc;
 
113
                                        obj.DrawfromSideDest = downRes.side;                                                                            
 
114
                                }
 
115
                        } else {
 
116
                                upobj = Objects[downRes.objid];
 
117
                                var sid = 1;
 
118
                                var     perco = 0.5;
 
119
                                var x1g = Math.abs(upRes.x1-gridx);
 
120
                                var x2g = Math.abs(upRes.x2-gridx);
 
121
                                var y1g = Math.abs(upRes.y1-gridy);
 
122
                                var y2g = Math.abs(upRes.y2-gridy);
 
123
                                if(x1g <= x2g && x1g <= y1g && x1g <= y2g) {
 
124
                                        sid = 1;
 
125
                                        perco = makesideperc(gridy, upRes.y1, upRes.y2);
 
126
                                } else if(x2g <= x1g && x2g <= y1g && x2g <= y2g) {
 
127
                                        sid = 3;
 
128
                                        perco = makesideperc(gridy, upRes.y1, upRes.y2);
 
129
                                } else if(y1g <= x1g && y1g <= x2g && y1g <= y2g) {
 
130
                                        sid = 4;
 
131
                                        perco = makesideperc(gridx, upRes.x1, upRes.x2);
 
132
                                } else if(y2g <= x1g && y2g <= x2g && y2g <= y1g){
 
133
                                        sid = 2;
 
134
                                        perco = makesideperc(gridx, upRes.x1, upRes.x2);
 
135
                                }                                                                       
 
136
                                if(obj.DrawtoID == "None") {
 
137
                                        obj.DrawtoID = upRes.objid;
 
138
                                        obj.DrawtoSide = sid;
 
139
                                        obj.DrawtoPerc = perco;
 
140
                                        obj.DrawfromSide = downRes.side;                                                                                
 
141
                                } else {
 
142
                                        obj.DrawtoIDDest = upRes.objid;
 
143
                                        obj.DrawtoSideDest = sid;
 
144
                                        obj.DrawtoPercDest = perco;
 
145
                                        obj.DrawfromSideDest = downRes.side;                                                                            
 
146
                                }
 
147
                        }                                                               
 
148
                }
 
149
        }
 
150
        clickstate = 0;
 
151
        cpsel = 0;
 
152
        drawlinekind = 0;               
 
153
}
 
154
/*
 
155
 *      Mouse down state
 
156
 */
 
157
function handler_mousedown() {
 
158
        clickstate = 1;
 
159
        downRes = mouseover(gridx, gridy);
 
160
        startx = gridx;
 
161
        starty = gridy; 
 
162
}
 
163
 
 
164
/*
 
165
 *      Mouse move
 
166
 */
 
167
function handler_mousemove(cx, cy) {
 
168
//                      gridx=Math.round((cx-(gridsize/2.0))/gridsize)*gridsize;
 
169
//                      gridy=Math.round((cy-(gridsize/2.0))/gridsize)*gridsize;                                
 
170
        gridx = cx;
 
171
        gridy = cy;
 
172
        deltax = startx - gridx;
 
173
        deltay = starty - gridy;                
 
174
        // We start drag mode
 
175
        if((distance(gridx, gridy, startx, starty) > dragsensitivity) && clickstate == 1) {
 
176
                clickstate = 2;
 
177
        }
 
178
        // We are in drag mode                          
 
179
        if(clickstate == 2) {                                                                                                                                                                                                           
 
180
                // Single Object Move - If Not Selected, Or if Selected and Center Area Is Dragged
 
181
                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"))) {
 
182
                        clickstate = 3;
 
183
                }
 
184
                // Single Object Scale Left
 
185
                if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "1")) {
 
186
                        clickstate=4;
 
187
                }
 
188
                // Single Object Scale Bottom
 
189
                if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "2")) {
 
190
                        clickstate=5;
 
191
                }
 
192
                // Single Object Scale Right
 
193
                if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "3")) {
 
194
                        clickstate=6;
 
195
                }
 
196
                // Single Object Scale Top
 
197
                if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "4")) {
 
198
                        clickstate=7;
 
199
                }
 
200
                if(downRes.typ == "ERAttribute" && downRes.code == "ContDraw" && downRes.side != "None") {                                                                                                      
 
201
                        clickstate=8; // Attribute Connection Draw
 
202
                        drawlinekind=1; // Tell drawing engine to draw attribute line symbol
 
203
                        if(downRes.side == "1") {
 
204
                                drawlinesx = downRes.x1; // Initiate start parameters for line drawing left side
 
205
                                drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);                                                                    
 
206
                        } else if(downRes.side == "2") {
 
207
                                drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
 
208
                                drawlinesy = downRes.y2;
 
209
                        } else if(downRes.side == "3") {
 
210
                                drawlinesx = downRes.x2; // Initiate start parameters for line drawing left side
 
211
                                drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);                                                                    
 
212
                        } else if(downRes.side == "4") {
 
213
                                drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
 
214
                                drawlinesy = downRes.y1;
 
215
                        }
 
216
                        drawlinedx = drawlinesx;
 
217
                        drawlinedy = drawlinesy;        
 
218
                }
 
219
                if(downRes.typ == "ERRel" && downRes.code == "ContDraw" && downRes.side != "None") {                                            
 
220
                        var obj=Objects[downRes.objid];                                                                                                 
 
221
                        if(downRes.side != obj.DrawfromSide && downRes.side != obj.DrawfromSideDest) {
 
222
                                clickstate = 9; // Attribute Connection Draw
 
223
                                drawlinekind = 1; // Tell drawing engine to draw relation line symbol 
 
224
                                if(downRes.side == "1") {
 
225
                                        drawlinesx = downRes.x1; // Initiate start parameters for line drawing left side
 
226
                                        drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);                                                                    
 
227
                                } else if(downRes.side == "2") {
 
228
                                        drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
 
229
                                        drawlinesy = downRes.y2;
 
230
                                } else if(downRes.side == "3") {
 
231
                                        drawlinesx = downRes.x2; // Initiate start parameters for line drawing left side
 
232
                                        drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);                                                                    
 
233
                                } else if(downRes.side == "4") {
 
234
                                        drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
 
235
                                        drawlinesy = downRes.y1;
 
236
                                }
 
237
                                drawlinedx = drawlinesx;
 
238
                                drawlinedy = drawlinesy;
 
239
                        }
 
240
                }                               
 
241
        }
 
242
        if(clickstate > 2) {
 
243
                var obj = Objects[downRes.objid];
 
244
        }
 
245
        if(clickstate == 3) { // We are in single rectangular object move 
 
246
                obj.x1 = downRes.x1 - deltax;
 
247
                obj.y1 = downRes.y1 - deltay;
 
248
                obj.x2 = downRes.x2 - deltax;
 
249
                obj.y2 = downRes.y2 - deltay;
 
250
        } else if(clickstate == 4) { // We are in single rectangular object scale left 
 
251
                if((obj.x2 - downRes.x1 + deltax) > 60) obj.x1 = downRes.x1 - deltax;
 
252
        } else if(clickstate == 5) { // We are in single rectangular object scale bottom
 
253
                if((downRes.y2 - obj.y1 - deltay) > 40) obj.y2 = downRes.y2 - deltay;
 
254
        } else if(clickstate==6) {      // We are in single rectangular object scale right
 
255
                if((downRes.x2 - obj.x1 - deltax) > 60) obj.x2 = downRes.x2 - deltax;
 
256
        } else if(clickstate == 7) { // We are in single rectangular object scale top
 
257
                if((obj.y2 - downRes.y1 + deltay) > 40) obj.y1 = downRes.y1 - deltay;
 
258
        } else if(clickstate == 8 || clickstate == 9) { // We are in straight connective line drawing mode 
 
259
                drawlinedx = gridx;
 
260
                drawlinedy = gridy;
 
261
        }
 
262
}
 
263
 
 
264
/*
 
265
 *      Call-forward for mouse-over event
 
266
 */
 
267
function mouseover(x, y) {
 
268
        // Code of touch, and if available object id and id of side of object that was touched
 
269
        // Tolerances included as constant
 
270
        var obj_code = "None";
 
271
        var obj_id = "None";
 
272
        var obj_sidentifier =" None";
 
273
        var obj_sideperc = 0;
 
274
        var obj_centerdist = 0;
 
275
        var obj_type = "None";
 
276
        var obj_x1 = 0; 
 
277
        var obj_y1 = 0; 
 
278
        var obj_x2 = 0; 
 
279
        var obj_y2 = 0;
 
280
        var Cont;
 
281
        var found = 0;
 
282
        var side;
 
283
        for(j = 0; j < Identifiers.length; j++) {
 
284
                var objid = Identifiers[j];
 
285
                var obj = Objects[objid];                               
 
286
                var Sel = Selected[objid];
 
287
                if(ContextObj == objid) {
 
288
                        Cont = 1;
 
289
                } else {
 
290
                        Cont = 0;
 
291
                }
 
292
                // Compute coordinates including offset
 
293
                if(obj.type == "Entity" || obj.type == "ERAttribute" || obj.type == "ERRel") {                                                                          
 
294
                        x1 = obj.x1 + offsx;
 
295
                        y1 = obj.y1 + offsy;
 
296
                        x2 = obj.x2 + offsx;
 
297
                        y2 = obj.y2 + offsy;
 
298
                        rx = (x2 - x1) * 0.5;
 
299
                        ry = (y2 - y1) * 0.5;
 
300
                }
 
301
                found = 0;
 
302
                // For each kind of clickable object, check if we are inside object and if so assign variables
 
303
                // Any general properties for all object types are set when "found" is true
 
304
                if(obj.type == "Entity") {                              
 
305
                        if(x > (x1 - sidetol) && y > (y1 - sidetol ) && x < (x2 + sidetol) && y < (y2 + sidetol)) {
 
306
                                obj_code = "NonSel";
 
307
                                if(Sel) {
 
308
                                        obj_code = "Sel";
 
309
                                }
 
310
                                if(Cont) {
 
311
                                        obj_code = "Cont";
 
312
                                }
 
313
                                side = computeside(x, y, x1, y1, x2, y2, sidetol);
 
314
                                obj_sidentifier = side.side;
 
315
                                obj_sideperc = side.perc;
 
316
                                obj_centerdist = side.dist;                                     
 
317
                                found = 1;                                                                                                                                      
 
318
                        }
 
319
                } else if(obj.type=="ERAttribute") {
 
320
                                if(x > (x1 - sidetol) && y > (y1 - sidetol) && x < (x2 + sidetol) && y < (y2 + sidetol)) {
 
321
                                        obj_code = "NonSel";
 
322
                                        if(Sel) {
 
323
                                                obj_code="Sel";
 
324
                                        }                                                       
 
325
                                        if(Cont) {
 
326
                                                if(obj.DrawtoID == "None") {
 
327
                                                        obj_code = "ContDraw";                                                                                  
 
328
                                                } else {
 
329
                                                        obj_code = "Cont";
 
330
                                                }
 
331
                                        } 
 
332
                                        side = computeside(x, y, x1, y1, x2, y2, sidetol);
 
333
                                        obj_sidentifier = side.side;
 
334
                                        obj_sideperc = side.perc;
 
335
                                        obj_centerdist = side.dist;
 
336
                                        found = 1;
 
337
                                }
 
338
                } else if(obj.type == "ERRel") {
 
339
                        if(x > (x1 - sidetol) && y > (y1 - sidetol) && x < (x2 + sidetol) && y < (y2 + sidetol)) {
 
340
                                xk = x - x1;
 
341
                                // Colision detection against diamond
 
342
                                var inside = 0;                                                                                                                                         
 
343
                                if(xk <= rx) {
 
344
                                        if(y > (y1 + ry - xk - sidetol) && y < (y1 + ry + xk + sidetol)) {
 
345
                                                inside = 1;
 
346
                                        }
 
347
                                } else {
 
348
                                        if(y > (y1 - rx + xk - sidetol) && y < ( y2 + rx - xk + sidetol)) {
 
349
                                                inside = 1;
 
350
                                        }
 
351
                                }
 
352
                                if(inside) {    
 
353
                                        if((x > (x1 - sidetol)) && (x < (x1 + sidetol)) && (y > (y1 + ry - sidetol)) && (y < (y1 + ry + sidetol))) {
 
354
                                                obj_sidentifier = 1;
 
355
                                        }
 
356
                                        if((x > (x1 + rx - sidetol)) && (x < (x1 + rx + sidetol)) && (y > (y2 - sidetol)) && (y < (y2 + sidetol))) {
 
357
                                                obj_sidentifier = 2;
 
358
                                        }
 
359
                                        if((x > (x2 - sidetol)) && (x < (x2 + sidetol)) && (y > (y1 + ry - sidetol)) && (y < (y1 + ry + sidetol))) {
 
360
                                                obj_sidentifier = 3;
 
361
                                        }
 
362
                                        if((x > (x1 + rx - sidetol)) && (x < (x1 + rx + sidetol)) && (y > (y1 - sidetol)) && (y < (y1 + sidetol))) {
 
363
                                                obj_sidentifier = 4;
 
364
                                        }
 
365
                                        obj_code = "NonSel";
 
366
                                        if(Sel) {
 
367
                                                obj_code = "Sel";
 
368
                                        }
 
369
                                        if(Cont) {
 
370
                                                if(obj.DrawtoID == "None"){
 
371
                                                        obj_code = "ContDraw";                                                                                  
 
372
                                                } else if(obj.DrawtoIDDest == "None") {
 
373
                                                        obj_code = "ContDraw";                                                                                  
 
374
                                                } else {
 
375
                                                        obj_code = "Cont";
 
376
                                                }
 
377
                                        } 
 
378
                                        obj_sideperc = 0.5;
 
379
                                        found = 1;
 
380
                                }
 
381
                        }                       
 
382
                }
 
383
                if(found == 1) {
 
384
                        // Save coordinates at time of click                                                                    
 
385
                        obj_x1 = x1;
 
386
                        obj_y1 = y1;
 
387
                        obj_x2 = x2;
 
388
                        obj_y2 = y2;                                            
 
389
                        obj_id = objid;
 
390
                        obj_type = obj.type;
 
391
                        printstr=obj_id + " " + obj_sidentifier + " " + obj_sideperc;
 
392
                }
 
393
        }                                               
 
394
        return {
 
395
                objid:obj_id,
 
396
                code:obj_code,
 
397
                side:obj_sidentifier,
 
398
                sideperc:obj_sideperc,
 
399
                centerdist:obj_centerdist,
 
400
                typ:obj_type,
 
401
                x1:obj_x1,
 
402
                y1:obj_y1,
 
403
                x2:obj_x2,
 
404
                y2:obj_y2
 
405
        }
 
406
}
 
407
 
 
408
/*
 
409
 * Turns JSON data into jQuery objects 
 
410
 */
 
411
function importdata() {                         
 
412
        for(i = 0; i < 7; i++) {
 
413
                if(i == 0) {
 
414
                        obj = jQuery.parseJSON('{"type":"ERAttribute","id":"ATT1","kind":"Multiple","name":"Addressfosoppooo","x1":220,"y1":100,"x2":300,"y2":140, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"None", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":""}');
 
415
                }
 
416
                if(i == 1) {
 
417
                        obj = jQuery.parseJSON('{"type":"Entity","id":"ENT2","kind":"Weak","name":"Carsmashoepppoloo","x1":100,"y1":160,"x2":220,"y2":220}');
 
418
                }
 
419
                if(i == 2) {
 
420
                        obj = jQuery.parseJSON('{"type":"ERAttribute","id":"ATT3","kind":"Key","name":"SSNFooomesPoo","x1":160,"y1":260,"x2":260,"y2":300, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"None", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":""}');
 
421
                }
 
422
                if(i == 3) {
 
423
                        obj = jQuery.parseJSON('{"type":"Entity","id":"ENT4","kind":"Strong","name":"Trailerfpdddpeoooooe","x1":320,"y1":260,"x2":420,"y2":320}');
 
424
                }
 
425
                if(i == 4) {
 
426
                        obj = jQuery.parseJSON('{"type":"Entity","id":"ENT5","kind":"Strong","name":"Grail","x1":120,"y1":440,"x2":220,"y2":480}');
 
427
                }
 
428
                if(i == 5) {
 
429
                        obj = jQuery.parseJSON('{"type":"ERRel","id":"REL6","kind":"Strong","name":"FGFool","x1":460,"y1":160,"x2":520,"y2":220, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"N", "DrawtoRole":"Fumo", "DrawtoXoffs":"20", "DrawtoYoffs":"50", "DrawtoIDDest":"None",  "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"N", "DrawtoDestRole":"Luma", "DrawtoDestXoffs":"0", "DrawtoDestYoffs":"-50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
 
430
                }
 
431
                if(i == 6) {
 
432
                        obj = jQuery.parseJSON('{"type":"ERRel","id":"REL7","kind":"Weak","name":"PODrool","x1":360,"y1":360,"x2":420,"y2":420, "DrawtoID":"None",  "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"N", "DrawtoRole":"Kumo", "DrawtoXoffs":"60", "DrawtoYoffs":"70", "DrawtoIDDest":"None",  "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"N", "DrawtoDestRole":"Zuuma", "DrawtoDestXoffs":"40", "DrawtoDestYoffs":"50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
 
433
                }
 
434
                objid = obj.id;
 
435
                Objects[objid] = obj;
 
436
                Identifiers.push(objid);
 
437
        }
 
438
}
 
439
 
 
440
/* 
 
441
 *      prepareobj
 
442
 *      Prepares all kinds of objects, with local movement-offset (scrolling offset is handled with transforms??)
 
443
 *      Ofss in prepare are not finished.
 
444
 */
 
445
function prepareobj(obji) {
 
446
        var fromobj = Objects[obji];
 
447
        // 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
 
448
        if((fromobj.type == "ERAttribute" || fromobj.type == "ERRel") && fromobj.DrawtoID != "None") {                                                                  
 
449
                var toid = fromobj.DrawtoID;
 
450
                var toobj = Objects[toid];
 
451
                var sidek;
 
452
                if(fromobj.DrawtoIDDest != "None" && fromobj.DrawtoIDDest != undefined) {
 
453
                        var toiddest = fromobj.DrawtoIDDest;
 
454
                        var toobjdest = Objects[toiddest];                                              
 
455
                        sidek = makeside(fromobj.DrawfromSideDest, fromobj.x1, fromobj.y1, fromobj.x2, fromobj.y2, 0.5);
 
456
                        fromobj.DrawX3 = sidek.x;
 
457
                        fromobj.DrawY3 = sidek.y;
 
458
                        sidek = makeside(fromobj.DrawtoSideDest, toobjdest.x1, toobjdest.y1, toobjdest.x2, toobjdest.y2, fromobj.DrawtoPercDest);
 
459
                        fromobj.DrawX4 = sidek.x;
 
460
                        fromobj.DrawY4 = sidek.y;
 
461
                }
 
462
                //printstr=fromobj.DrawfromSide+" "+fromobj.x1+" "+fromobj.y1+" "+fromobj.x2+" "+fromobj.y2+" :: "+fromobj.DrawtoSide+" "+toobj.x1+" "+toobj.y1+" "+toobj.x2+" "+toobj.y2+" "+fromobj.DrawtoPerc;                               
 
463
                sidek = makeside(fromobj.DrawfromSide, fromobj.x1, fromobj.y1, fromobj.x2, fromobj.y2, 0.5);
 
464
                fromobj.DrawX1 = sidek.x;
 
465
                fromobj.DrawY1 = sidek.y;                               
 
466
                sidek = makeside(fromobj.DrawtoSide, toobj.x1, toobj.y1, toobj.x2, toobj.y2, fromobj.DrawtoPerc);
 
467
                fromobj.DrawX2 = sidek.x; 
 
468
                fromobj.DrawY2 = sidek.y;                                               
 
469
        }
 
470
}
 
471
 
 
472
/*
 
473
 *      Drawobj
 
474
 *      Draws all kinds of objects, with local movement-offset (scrolling offset is handled with transforms??)
 
475
 */
 
476
function drawobj(obji) {
 
477
        var obj = Objects[obji];
 
478
        var Sel = Selected[obji];
 
479
        if(ContextObj == obji) {
 
480
                Cont = 1;
 
481
        } else {
 
482
                Cont = 0;
 
483
        }
 
484
        context.strokeStyle = '#000';
 
485
        context.lineWidth = 2.0;
 
486
        // Compute coordinates including offset
 
487
        if(obj.type == "Entity" || obj.type == "ERAttribute" || obj.type == "ERRel") {                                                                  
 
488
                x1 = obj.x1 + offsx;
 
489
                y1 = obj.y1 + offsy;
 
490
                x2 = obj.x2 + offsx;
 
491
                y2 = obj.y2 + offsy;
 
492
                rx = (x2 - x1) * 0.5;
 
493
                ry = (y2 - y1) * 0.5;
 
494
        }
 
495
        if(obj.type == "Entity") {                              
 
496
                //Draw Local Graphic
 
497
                drawrect(x1, y1, x2, y2, "#000");
 
498
                if(obj.kind == "Weak") {
 
499
                        drawrect(x1 + 5, y1 + 5, x2 - 5, y2 - 5, "#000");
 
500
                        cliptext(x1 + 5, y1 + 5, x2 - 5, y2 - 5, obj.name, "20px Calibri", "center", 8, 6, "#000", 1, 0);               
 
501
 
 
502
                } else {
 
503
                        cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 1, 0);                                               
 
504
                }
 
505
                // Draw Select Marker
 
506
                if(Sel || Cont) {
 
507
                        fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#5f8");                                                         
 
508
                }
 
509
        } else if(obj.type == "ERAttribute") {
 
510
                drawellipse(x1, y1, x2, y2);
 
511
                if(obj.kind == "Key") {
 
512
                        cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 2, 1);                                               
 
513
                } else {
 
514
                        cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 2, 0);                                                                                               
 
515
                }
 
516
                if(obj.DrawtoID != "None") {
 
517
                        drawline(obj.DrawX1, obj.DrawY1, obj.DrawX2, obj.DrawY2, "#000", 2.0);
 
518
                }
 
519
                // Draw Select Marker
 
520
                if(Cont && obj.DrawtoID == "None") {
 
521
                        fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#fa2");
 
522
                } else if(Sel || (Cont && obj.DrawtoID != "None")) {
 
523
                        fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#5f8");
 
524
                }
 
525
        } else if(obj.type == "ERRel") {
 
526
                if(obj.DrawtoID != "None") {
 
527
                        drawline(obj.DrawX1, obj.DrawY1, obj.DrawX2, obj.DrawY2, "#000", 2.0);
 
528
                        drawcardinality(obj.DrawX2, obj.DrawY2, obj.DrawtoSide, obj.DrawtoCard, obj.DrawtoXoffsCard, obj.DrawtoYoffsCard, "20px Calibri", 20, 1, "#0a0");
 
529
                        drawcardinality(obj.DrawX2, obj.DrawY2, obj.DrawtoSide, obj.DrawtoRole, obj.DrawtoXoffsRole, obj.DrawtoYoffsRole, "20px Calibri", 20, 2, "#0a0");
 
530
                        //function drawcardinality(x,y,side,tex,xoffs,yoffs,font,baseline,sign,color)
 
531
                        //if(i==5) obj = jQuery.parseJSON('{"type":"ERRel","id":"REL6","kind":"Strong","name":"FGFool","x1":460,"y1":160,"x2":520,"y2":220, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"N", "DrawtoRole":"Fumo", "DrawtoXoffsCard":"20", "DrawtoYoffsCard":"50","DrawtoXoffsRole":"20", "DrawtoYoffsRole":"-50", "DrawtoIDDest":"None",  "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"1", "DrawtoDestRole":"Luma", "DrawtoDestXoffsCard":"0", "DrawtoDestYoffsCard":"-50","DrawtoDestXoffsRole":"0", "DrawtoDestYoffsRole":"-50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
 
532
                        //if(i==6) obj = jQuery.parseJSON('{"type":"ERRel","id":"REL7","kind":"Weak","name":"PODrool","x1":360,"y1":360,"x2":420,"y2":420, "DrawtoID":"None",  "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"1", "DrawtoRole":"Kumo", "DrawtoXoffsCard":"60", "DrawtoYoffsCard":"70", "DrawtoXoffsCard":"80", "DrawtoYoffsCard":"-70", "DrawtoIDDest":"None",  "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"N", "DrawtoDestRole":"Zuuma", "DrawtoDestXoffsCard":"40", "DrawtoDestYoffsCard":"50", "DrawtoDestXoffsRole":"40", "DrawtoDestYoffsRole":"50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
 
533
                }
 
534
                if(obj.DrawtoIDDest != "None") {
 
535
                        drawline(obj.DrawX3, obj.DrawY3, obj.DrawX4, obj.DrawY4, "#000", 2.0);
 
536
                }
 
537
                if(obj.kind == "Weak") {
 
538
                        drawdiamond(x1 - 4, y1 - 4, x2 + 4, y2 + 4);
 
539
                        drawdiamond(x1 + 4, y1 + 4, x2 - 4, y2 - 4);
 
540
                        cliptext(x1 + 8, y1 + 8, x2 - 8, y2 - 8, obj.name, "20px Calibri", "center", 8, 6, "#000", 3, 0);                                                                                               
 
541
                } else {
 
542
                        drawdiamond(x1, y1, x2, y2, 0);
 
543
                        cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 3, 0);                                                                                               
 
544
                }
 
545
                // Draw Select Markers
 
546
                if(Sel || (Cont && obj.DrawtoID != "None" && obj.DrawtoIDDest != "None")) {
 
547
                        fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#5f8");
 
548
                } else if(Cont) {
 
549
                        if(obj.DrawfromSide != 1 && obj.DrawfromSideDest != 1) {
 
550
                                point(x1, y1 + ry, "#fa2");
 
551
                        }
 
552
                        if(obj.DrawfromSide != 2 && obj.DrawfromSideDest != 2) {
 
553
                                point(x1 + rx, y2, "#fa2");
 
554
                        }
 
555
                        if(obj.DrawfromSide != 3 && obj.DrawfromSideDest != 3) {
 
556
                                point(x2, y1 + ry, "#fa2");
 
557
                        }
 
558
                        if(obj.DrawfromSide != 4 && obj.DrawfromSideDest != 4) {
 
559
                                point(x1 + rx, y1, "#fa2");
 
560
                        }
 
561
                }
 
562
        }
 
563
}
 
564
importdata();
 
565
 
 
566
/*
 
567
 * 
 
568
 */
 
569
function foo() {
 
570
        context.clearRect(0, 0, 600, 600);
 
571
//                      overline(gridx,gridy,150,550,550,300,8.0);
 
572
        // Draw grid lines                              
 
573
        context.strokeStyle = '#ddd';
 
574
        context.lineWidth = 0.5;
 
575
        context.beginPath();
 
576
        for(i = 0; i < 600; i += 20) {
 
577
                context.moveTo(i, 0);
 
578
                context.lineTo(i, 600);
 
579
                context.moveTo(0, i);
 
580
                context.lineTo(600, i);
 
581
        }
 
582
        context.stroke();                       
 
583
        // Draw drawing line                            
 
584
        if(drawlinekind == 1) {
 
585
                drawline(drawlinesx, drawlinesy, drawlinedx, drawlinedy, "#000", 1.0);
 
586
        }
 
587
        // Prepare model objects
 
588
        for(i = 0; i < Identifiers.length; i++){
 
589
                var objid = Identifiers[i];
 
590
                prepareobj(objid);
 
591
        }
 
592
        // Draw model objects
 
593
        for(i = 0; i < Identifiers.length; i++){
 
594
                var objid = Identifiers[i];
 
595
                drawobj(objid);
 
596
        }                                                               
 
597
        // Draw Crosshair
 
598
        context.beginPath();
 
599
        context.strokeStyle = '#444';
 
600
        context.lineWidth   = 1.0;
 
601
        context.moveTo(gridx - gridsize, gridy);
 
602
        context.lineTo(gridx + gridsize, gridy);
 
603
        context.moveTo(gridx, gridy - gridsize);
 
604
        context.lineTo(gridx, gridy + gridsize);
 
605
        context.stroke();                                                                                       
 
606
        context.strokeStyle = '#ddd';
 
607
        context.fillStyle = '#000';
 
608
        context.font = "bold 16px Arial";
 
609
        context.textAlign = "left";
 
610
        context.fillText("currop: " + printstr, 20, 576);
 
611
        setTimeout("foo();", 100);
 
612
}
 
 
b'\\ No newline at end of file'