/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: galaxyAbstractor
  • Date: 2013-04-05 08:46:27 UTC
  • mfrom: (19.2.5 pvp2)
  • mto: (19.1.3 lenasys)
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: galaxyabstractor@gmail.com-20130405084627-uicdaj23ay0x8gw5
Elof'ss branch

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