Commit 35b27bbc authored by Christoffer Ackelman's avatar Christoffer Ackelman

JS: Move common functionality to a library file.

parent e014403c
"use strict";
var Bitmaps = {
leaf: 0,
map: 2,
openmap: 4,
object: 6,
attrenum: 8,
attrarra: 10,
attrarel: 12,
attr: 14,
crrwrite: 16,
crrread: 18,
ack: 20,
alarm: 22,
eventacked: 24,
eventalarm: 26,
eventreturn: 28,
info: 30,
system: 32,
maintenance: 34,
blockl: 36,
blockr: 38,
img: [null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null],
pending: [null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null],
images: [
// leaf
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAASElEQVQokWP4jwMwMDBgYBR5XBpwGYZVIzYNGDZB+QyEFOBiM+CyCacGBI0hgEGjsxkYGCiwkSI/4tKMz0DqxCM2A4hOOcQCAObFEQyI2PpKAAAAAElFTkSuQmCC',
// leaf inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAQUlEQVQokWNgYGD4jw1jA2hqsGvAZRhWjdg0oIsh8QkqwMXGbhMuDXAxdAFsNDobyifTRor8SFGoUhSPFKUcYjEAMsMz2y6w8kgAAAAASUVORK5CYII=',
// map
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAKElEQVQokWP4DwUMDAwYGB9gwKUQm0FoGL/JOGwb1TgINZKFSbYOCgD1JxQJG0vK9AAAAABJRU5ErkJggg==',
// map inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAK0lEQVQokWNgYGD4z8DA8B8bgMlhxbgUEgIMBE3Ggkc1Dk6N5AAGUm2DYQAkYTDe0vu7CAAAAABJRU5ErkJggg==',
// openmap
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAQklEQVQokaXOwQ4AIAgCUP7/p+nUlpMSzY2bDwWHA5IEkFJCtaiKxE7dvsue8HZNJEPneoAuSq+OYAf9wy4K0Mk5C+d++RWimsw3AAAAAElFTkSuQmCC',
// openmap inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAPUlEQVQokaXRQQoAQAgCQP//6brKZmSt0M2hIACI4yBURqiKXQp0ThuhGwmt7Vy00XvqCa7QN1wjhtYLCCYyCkvDVnkJOQAAAABJRU5ErkJggg==',
// object
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAH0lEQVQokWP4TyJgYGBg+E8iZiDFdHrZMKqBGA2kYAD8gaJsjwzf9wAAAABJRU5ErkJggg==',
// object inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIklEQVQokWNgYGD4TxL+TyJg+P//P9GmwzXQ3oZRDdSOBwAGOSrkrXppgQAAAABJRU5ErkJggg==',
// attrenum
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAPklEQVQokWP4////fwYGBgxMCDBgU4jNICyYsOlYbENoJNIW7BqJsYm2NuJyBVE2EqWRfjbiUoQ3oAgpwgUANLqccvbgec0AAAAASUVORK5CYII=',
// attrenum inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAPElEQVQokWNgYGD4jw0wMDDgx9gUEgMYiDIdDaNoJBZg1UiUTTS1EZcriLKRKI30sxGXIgKBhF8RrqgBAOTOqGZ5aiCnAAAAAElFTkSuQmCC',
// attrarra
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAMElEQVQokWP4////fwYGBgxMCDBgU4jNICwYv+nY5InWOGojXW0khLEahtc6PDYCAB9hxkjBPICvAAAAAElFTkSuQmCC',
// attrarray inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAALUlEQVQokWNgYGD4jw0wMDDgx9gUEgMYCJmOTZ5ojaM20tVGQgCHK/AnLVwAAPonfpBwU5f4AAAAAElFTkSuQmCC',
// attrarel
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIklEQVQokWP4////fwYGBpwYHTDANGADeDWM2jAEbSAFAADB26JsIjYj1AAAAABJRU5ErkJggg==',
// attrarel inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIElEQVQokWNgYGD4jw8wMDCgYwZcEvg1jNowBG0gBQMAQN8q5COZl1cAAAAASUVORK5CYII=',
// attr
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIUlEQVQokWP4TyJgGIQaGBgY/pOIibcEroEkTLIfhoEGADzs8B5gcUg/AAAAAElFTkSuQmCC',
// attr inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAJUlEQVQokWNgYGD4TyIedBr+kwgY/v//T7TpcA0k2TAIQ4nmGgDFzt0jExR7hgAAAABJRU5ErkJggg==',
// crrwrite
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAN0lEQVQokaWNQQoAMAjD8v9P633WVWhBkJIotQQoYPYbrHYrqC9D+MG54OBMuMC54GApuPBed9OxiMNLGke1JwAAAABJRU5ErkJggg==',
// crrwrite inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAANElEQVQokWNgYGD4jw3DABY57IqxsQlqwGELSYop1ECEYgo0EKmYQg1EKMbUQEAxRAMpAABRMgoFjbTzXgAAAABJRU5ErkJggg==',
// crrread
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWNgYGD4j4yRATY5BmyKkGks4qgS2BSj2UYFDdgAdW2gvpOwhDW6ItwaCGI8JuHWgMOtWD0PACufaaWhXDFDAAAAAElFTkSuQmCC',
// crrread inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWP4jwYYGBjgGKscNkXINLo4hgZsipFto44GbJi6NlDfSehhjUxjyGMVxQMYcJmEVwPB5ICEAdcbY6vf9TVAAAAAAElFTkSuQmCC',
// ack
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAS0lEQVQokZ2Q2w4AIAhCz///ND11M3RVmxuDUBRAtw8QHRyC4SSJSDjDht1Yhxdudks+bFNxYsX9G6rz2qVHxqRspGi2Wpoji/dqaLh22DbO2VuXAAAAAElFTkSuQmCC',
// ack inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAASklEQVQokWP4////fwYGBqIwVC2cgSKBTQzKxhDA0ICmGau12BRCMLJp2BQgy8H9gM9ELGJkasAXvFg9TQjgDCVc8YBXAwFMmgYASkT1C9E5Ya0AAAAASUVORK5CYII=',
// alarm
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAARklEQVQokZ2QQQoAMAjD+v9Pu9PA1ThQQRBtoFUBJSkk0SlwOwKykCAEcn+BK8hih/aAe++y7IDuhWgXfcKHCuBBfX6ASR3Vn8ZINQzCrQAAAABJRU5ErkJggg==',
// alarm inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAQ0lEQVQokWNgYGD4j45hAJscA8UakBXi0ITddDy2YJqOrBiLJjI1oLsdj1/I0IAnCLFpwtSALYQwNKB7FJ2NooEUDAAtGwcI+Svs4gAAAABJRU5ErkJggg==',
// eventacked
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAL0lEQVQokWP4TyJgGCkaGBgQyhhwSeASw9CAYho2A3CZiE0xVg34FOPUgA+QrAEA1FYi+tWeG/cAAAAASUVORK5CYII=',
// eventacked inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAMElEQVQokWNgYGD4TyIeGRr+//+PXQOaBC4xVElkBdgMwHASTBEOxdj9gEcxHYIVAC5kqlZXl5JMAAAAAElFTkSuQmCC',
// eventalarm
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAJ0lEQVQokWP4jwMwMDBgF8elGIZHNeDSANOEVRyXBpwGUcUGqvoBAK+H8xt0qXFWAAAAAElFTkSuQmCC',
// eventalarm inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAJ0lEQVQokWNgYGD4jw3///8fqzgDLsUwMKoBlwaSg5UAHoiIw2cDAFMz2iY65DAoAAAAAElFTkSuQmC',
// eventreturn
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAASUlEQVQokZ2RUQoAIAjFdv9L11dhskeUEIQ2mcYIAXjeisA+EahFA9ad/siAA0wqSUsnu87wDZh3VEodO6Rr1c51rc8fd9OoMQHLk7dXak3qLwAAAABJRU5ErkJggg==',
// eventreturn inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAR0lEQVQokZ2S2woAIAhD9/8/vV6tjgMNhLxMN1SSTGYb46JkfS2gJglQ/ncRAZ5JTCXQYsFRwxpAvFtKoeMvmoqDv1jc5DQONycV+bfOetgAAAAASUVORK5CYII=',
// info
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAOUlEQVQokWNgYGD4///////E0AwMDP8hPDQAk8QhjlMCuzg2G3AB6tlAez8MglAiCZNiw/////8DACmmtFrq9aGNAAAAAElFTkSuQmCC',
// info inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAN0lEQVQokWP4////fwYGhv/E0FA2w390jCSJIc6ASwKnBmw24MLUs4H2fhgEoUQKIMkGBgaG/wDZFBj2pVi3HgAAAABJRU5ErkJggg==',
// system
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAN0lEQVQokWNgYGD4TyJm+E8sgGugig3YxHFqwGcIQQ3obAwN6G7GawMuhVg1EFKMUwM+QJ+IAwDD1Gyi1EZc6gAAAABJRU5ErkJggg==',
// system inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAO0lEQVQokWP4TyJg+P///38GBgaiMFwDVWzAJo5TA15DCGnAYKNrwHAzPhtwKcSqgZBinBqIigeaRhwAPuZgrlZXy70AAAAASUVORK5CYII=',
// maintenance
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAP0lEQVQokZWPQQoAMAzC8v9Pu8soDOxaBS82QkWNgPKTJ/BYsLekAOxfquwHWyfws6ED7OgtfNk9bAuTSGBJOufqnHIsmYkzAAAAAElFTkSuQmCC',
// maintenance inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAQUlEQVQokZWPQQ4AMAQE5/+f1kuTCkuROGAmADCVPsJsBfdCsX0u3N7sJFfXsAqW8BMaID+9gE3SJayEFo7CFwY7GtAw3ouVj50AAAAASUVORK5CYII=',
// blockl
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAQElEQVQokZ2QQQ4AMAjC+v9Pu9MWl5AJ42a0IlKBgCIadgGgQ8imqo9D3zDBvJoyR+zwlWHS9SUHaOf4QOywtQCQGucn0g2dEQAAAABJRU5ErkJggg==',
// blockl inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAOklEQVQokWNgYGD4Tyz+////fwZSFBOtAaoQQsM46JLY+HAbUEwgrJmwyZTZQJYfSAolmsQDWTENwwByoOYaWbAqegAAAABJRU5ErkJggg==',
// blockr
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWP4jwMwMDBgF8enAZsmvBqw2cSARQBDIQqbGEUoaggpQBcj3Qay/IAN4AwlfBrIigeiNeACADpU5yeYXn+XAAAAAElFTkSuQmCC',
// blockr inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWNgYGD4jw3///8fqzgDPg04NOG3AUMTugA2hWhqiFKEzCeoAF2MRBvI8gNJoUT1eCBaAy4MAMhm5hr5iTaWAAAAAElFTkSuQmCC'
]
};
var Plow = {
DRAWOFFSET: 2,
DEST_INTOLAST: 0,
DEST_INTOFIRST: 1,
DEST_AFTER: 2,
DEST_BEFORE: 3,
TREE_INDENTATION: 1.0,
OPEN_ATTRIBUTES: 1,
OPEN_CHILDREN: 2,
OPEN_CROSSREFERENCES: 4,
OPEN_ALL: 7,
COLOR_BLACK: 1,
COLOR_RED: 2,
COLOR_GRAY: 3,
COLOR_DARKGRAY: 4,
COLOR_LIGHTGRAY: 5,
COLOR_WHITE: 6,
COLOR_YELLOW: 7,
COLOR_GREEN: 8,
COLOR_LIGHTBLUE: 9,
COLOR_BLUE: 10,
COLOR_VIOLET: 11,
eEvent_MB1Click: 0,
eEvent_MB1ClickShift: 1,
eEvent_Key_Up: 2,
eEvent_Key_Down: 3,
eEvent_Key_Right: 4,
eEvent_Key_Left: 5,
eEvent_Key_ShiftRight: 6,
eEvent_Key_CtrlR: 7,
eEvent_Key_CtrlL: 8,
eEvent_Key_CtrlG: 9,
eEvent_ObjectDeleted: 10,
RELATIVE_POSITION: 1,
NEXT_RELATIVE_POSITION: 2
}
function PlowGeometry() {
this.ll_x = 0;
this.ll_y = 0;
this.ur_x = 0;
this.ur_y = 0;
}
function PlowNodeClass(ctx) {
this.a = new PlowArray(ctx);
this.ctx = ctx;
this.nc_name = "";
this.group = 0;
this.node_open = 0;
this.draw = function (g, p, node, highlight) {
this.a.draw(g, p, node, highlight);
}
this.insert = function (elem) {
this.a.add(elem);
}
}
function PlowArray(ctx) {
this.a = [];
this.ctx = ctx;
this.add = function (elem) {
this.a.push(elem);
}
this.insertNode = function (elem, destination, code) {
var idx = this.find(elem);
if (idx != -1)
return;
if (destination == null) {
switch (code) {
case Plow.DEST_INTOLAST:
case Plow.DEST_AFTER:
this.a.push(elem);
elem.level = 0;
break;
default:
elem.level = 0;
this.a.unshift(elem);
}
}
else {
var dest_idx = this.find(destination);
if (dest_idx == -1)
return;
switch (code) {
case Plow.DEST_INTOFIRST:
if (dest_idx == this.a.length - 1)
this.a.push(elem);
else
this.a.splice(dest_idx + 1, 0, elem);
elem.level = destination.level + 1;
break;
case Plow.DEST_INTOLAST: {
if (dest_idx == this.a.length - 1)
this.a.push(elem);
else {
idx = this.a.length;
for (var i = dest_idx + 1; i < this.a.length; i++) {
if (this.a[i].level <= destination.level) {
idx = i;
break;
}
}
if (idx == this.a.length)
this.a.push(elem);
else
this.a.splice(idx, 0, elem);
}
elem.level = destination.level + 1;
break;
}
case Plow.DEST_AFTER: {
if (dest_idx == this.a.length - 1)
this.a.push(elem);
else {
var i;
for (i = idx; i < this.a.length; i++) {
if (this.a[i].level < destination.level)
break;
}
this.a.splice(i, 0, elem);
}
elem.level = destination.level;
break;
}
case Plow.DEST_BEFORE:
if (idx > 0)
idx--;
this.a.splice(idx, 0, elem);
elem.level = destination.level;
break;
}
}
}
this.remove = function (elem) {
var idx = this.find(elem);
if (idx == -1)
return;
this.ctx.event_cb(Plow.eEvent_ObjectDeleted, this.a[idx + 1], 0, 0);
this.a.splice(idx, 1);
}
this.size = function () {
return this.a.length;
}
this.get = function (idx) {
return this.a[idx];
}
this.draw = function (g, p, node, highlight) {
for (var i = 0; i < this.a.length; i++)
this.a[i].draw(g, p, node, highlight);
}
this.set_borders = function (node) {
for (var i = 0; i < this.a.length; i++)
this.a[i].set_borders(node);
}
this.configure = function () {
for (var i = 0; i < this.a.length; i++) {
this.a[i].pos.x = this.a[i].level * 1.0;
this.a[i].pos.y = i * 1.0;
}
}
this.close_node = function (node) {
var idx = this.find(node);
if (idx == -1)
return;
var level = node.level;
var i;
for (i = idx + 1; i < this.a.length; i++) {
if (this.a[i].level <= level)
break;
}
var next_idx = i;
if (next_idx == idx + 1)
return;
for (i = idx + 1; i < next_idx; i++) {
// Event backcall
if (ctx.select_object == this.a[idx + 1])
ctx.select_object = null;
this.ctx.event_cb(Plow.eEvent_ObjectDeleted, this.a[idx + 1], 0, 0);
this.a.splice(idx + 1, 1);
}
}
this.get_parent_object = function (node) {
var idx = this.find(node);
if (idx == -1)
return null;
for (var i = idx; i >= 0; i--) {
if (this.a[i].level < node.level)
return this.a[i];
}
return null;
}
this.get_first_child = function (node) {
var idx = this.find(node);
if (idx == -1)
return null;
if (this.a.length == idx - 1)
return null;
if (this.a[idx + 1].level > node.level)
return this.a[idx + 1];
return null;
}
this.get_next_sibling = function (node) {
var found = false;
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == node) {
found = true;
continue;
}
if (found) {
if (this.a[i].level == node.level)
return this.a[i];
if (this.a[i].level < node.level)
return null;
}
}
return null;
}
this.get_next_object = function (node) {
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == node) {
if (i == this.a.length - 1)
return null;
return this.a[i + 1];
}
}
return null;
}
this.get_previous_object = function (node) {
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == node) {
if (i == 0)
return null;
return this.a[i - 1];
}
}
return null;
}
this.get_first_object = function () {
if (this.a.length == 0)
return null;
return this.a[0];
}
this.get_last_object = function () {
if (this.a.length == 0)
return null;
return this.a[this.a.length - 1];
}
this.find = function (elem) {
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == elem)
return i;
}
return -1;
}
}
function PlowNode(ctx, nc, level) {
this.ctx = ctx;
this.userdata = null;
this.OFFSET = 2;
this.x_right = 0.0;
this.x_left = 0.0;
this.y_high = 0.0;
this.y_low = 0.0;
this.nc = nc;
this.pos = new PlowPoint(ctx, 0, 0);
this.n_name = "";
this.annotv = [];
this.annotsize = [];
this.pixmapv = [];
this.trace_object = "";
this.trace_attribute = "";
this.trace_attr_type = 0;
this.highlight = false;
this.select = false;
this.invert = false;
this.level = level;
this.node_open = false;
this.fill_color = 0;
this.p = 0;
this.old_value = 0;
this.first_scan = true;
this.relative_position = 0;
this.set_annotation = function (number, text) {
if (number >= 10)
return;
this.annotv[number] = text;
}
this.set_annotation_pixmap = function (number, pixmap) {
if (number >= 10)
return;
this.pixmapv[number] = pixmap;
}
this.draw_object = function () {
this.draw(this.ctx.gdraw.gctx, null, null, false);
}
this.draw = function (g, p, node, highlight) {
var x = this.x_left * this.ctx.zoom_factor;
var y = this.y_low * this.ctx.zoom_factor - 1;
var width = (this.x_right - this.x_left) * this.ctx.zoom_factor;
var height = (this.y_high - this.y_low) * this.ctx.zoom_factor + 2;
g.fillStyle = "white";
if (this.select)
g.fillStyle = "lightblue";
g.fillRect(x, y, width, height);
this.nc.draw(g, this.pos, this, this.highlight);
}
this.connect = function () {
if (this.trace_object == "" || this.trace_attribute == "")
return;
var n = this.trace_attribute.indexOf('#');
if (n != -1)
this.trace_attribute = this.trace_attribute.substring(0, n);
var o = this.trace_object + "." + this.trace_attribute;
this.p = ctx.gdh.refObjectInfo(o, this.trace_attr_type);
console.log("connecting", o, this.p);
}
this.scan = function () {
if (this.p == 0)
return;
var v1 = ctx.gdh.getRefObjectInfo(this.p);
var evaluate = true;
if (this.first_scan)
this.first_scan = false;
else if (v1 == this.old_value)
return;
if (v1)
this.highlight = true;
else
this.highlight = false;
this.old_value = v1;
this.draw_object();
}
this.set_borders = function () {
this.x_left = 1e37;
this.x_right = -1e37;
this.y_low = 1e37;
this.y_high = -1e37;
nc.a.set_borders(this);
}
this.event_handler = function (event, x, y) {
if ((x - this.ctx.offset_x) / this.ctx.zoom_factor >= this.x_left &&
(x - this.ctx.offset_x) / this.ctx.zoom_factor <= this.x_right &&
(y - this.ctx.offset_y) / this.ctx.zoom_factor >= this.y_low &&
(y - this.ctx.offset_y) / this.ctx.zoom_factor <= this.y_high) {
ctx.event_object = this;
return 1;
}
return 0;
}
this.set_select = function (select) {
if (select) {
this.select = true;
this.ctx.select_object = this;
}
else {
this.select = false;
if (this.ctx.select_object == this)
this.ctx.select_object = null;
}
if (select != this.select)
this.draw_object();
}
this.set_invert = function (invert) {
this.invert = invert;
this.draw_object();
}
this.set_userdata = function (userdata) {
this.userdata = userdata;
}
this.get_userdata = function () {
return this.userdata;
}
this.in_icon = function (x, y) {
if (x >= this.x_left * this.ctx.zoom_factor &&
x <= (this.x_left + 1.75) * this.ctx.zoom_factor)
return true;
return false;
}
this.measure = function () {
var geom = new PlowGeometry();
geom.ll_x = this.x_left * this.ctx.zoom_factor;
geom.ll_y = this.y_low * this.ctx.zoom_factor;
geom.ur_x = this.x_right * this.ctx.zoom_factor;
geom.ur_y = this.y_high * this.ctx.zoom_factor;
return geom;
};
}
function PlowPoint(ctx, x, y) {
this.x = x;
this.y = y;
this.ctx = ctx;
}
function PlowAnnot(ctx, x, y, text_size, text_color, annot_type, number) {
this.RELATIVE_OFFSET = 1;
this.p = new PlowPoint(ctx, x, y);
this.draw_type = text_color;
this.text_size = text_size;
this.annot_type = annot_type;
this.number = number;
this.ctx = ctx;
this.draw = function (g, p0, node, highlight) {
if (node == null)
return;
if (node.annotv[this.number] == null)
return;
var tsize = 0;
var idx = this.ctx.zoom_factor / this.ctx.base_zoom_factor * (this.text_size + 4) - 4;
if (idx < 0) return;
switch (idx) {
case 0:
tsize = 8;
break;
case 1:
tsize = 10;
break;
case 2:
tsize = 12;
break;
case 3:
tsize = 14;
break;
case 4:
tsize = 14;
break;
case 5:
tsize = 18;
break;
case 6:
tsize = 18;
break;
case 7:
tsize = 18;
break;
default:
tsize = idx * 3;
}
g.font = tsize + "px Arial";
if (node.invert)
g.fillStyle = "white";
else
g.fillStyle = "black";
if (highlight)
g.fillStyle = "red";
g.lineWidth = 0.5;
var x = (this.p.x + p0.x) * this.ctx.zoom_factor;
var y = (this.p.y + p0.y) * this.ctx.zoom_factor - tsize / 4;
if ((this.annot_type & Plow.RELATIVE_POSITION) != 0) {
var rel_x = (p0.x + node.relative_position + this.RELATIVE_OFFSET) * this.ctx.zoom_factor;
if (x < rel_x)
x = rel_x;
}
var tokens = node.annotv[this.number].split('\n');
for (var i = 0; i < tokens.length; i++) {
g.fillText(tokens[i], x, y);
y += tsize * 1.4;
}
if ((this.annot_type & Plow.NEXT_RELATIVE_POSITION) != 0 || (this.annot_type & Plow.RELATIVE_POSITION) != 0) {
node.relative_position = (x + g.measureText(node.annotv[this.number]).width) / this.ctx.zoom_factor - p0.x;
}
}
this.set_borders = function (node) {
}
}
function PlowAnnotPixmap(ctx, x, y, number) {
this.p = new PlowPoint(ctx, x, y);
this.number = number;
this.ctx = ctx;
this.draw = function (gctx, p0, node, highlight) {
var x = (this.p.x + p0.x) * this.ctx.zoom_factor;
var y = (this.p.y + p0.y) * this.ctx.zoom_factor;
var img;
var bix = node.pixmapv[this.number];
if (typeof bix === 'undefined' || bix === null)
return;
if (node.invert)
bix++;
img = Bitmaps.img[bix];
if (img == null) {
var img = new Image();
img.src = Bitmaps.images[bix];
Bitmaps.img[bix] = img;
Bitmaps.pending[bix] = [];
Bitmaps.pending[bix].push(new PlowPoint(this.ctx, x, y));
img.onload = function () {
for (var i = 0; i < Bitmaps.pending[bix].length; i++)
gctx.drawImage(img, Bitmaps.pending[bix][i].x, Bitmaps.pending[bix][i].y);
Bitmaps.pending[bix] = null;
}
}
else {
if (!img.complete)
Bitmaps.pending[bix].push(new PlowPoint(this.ctx, x, y));
else
gctx.drawImage(img, x, y);
}
}
this.set_borders = function (node) {
}
}
function PlowRect(ctx, x, y, width, height, fill_color, border_color, fill, fix_color) {
this.ll = new PlowPoint(ctx, x, y);
this.ur = new PlowPoint(ctx, x + width, y + height);
this.border_color = border_color;
this.fill_color = fill_color;
this.fill = fill;
this.fix_color = fix_color;
this.ctx = ctx;
this.draw = function (g, p, node, highlight) {
var x = (this.ll.x + p.x) * this.ctx.zoom_factor;
var y = (this.ll.y + p.y) * this.ctx.zoom_factor;
var width = (this.ur.x - this.ll.x) * this.ctx.zoom_factor;
var height = (this.ur.y - this.ll.y) * this.ctx.zoom_factor;
g.lineWidth = 1;
switch (this.border_color) {
case Plow.COLOR_GRAY:
g.strokeStyle = "grey";
break;
case Plow.COLOR_RED:
g.strokeStyle = "red";
break;
case Plow.COLOR_WHITE:
g.strokeStyle = "white";
break;
default:
g.strokeStyle = "black";
}
if (highlight)
g.strokeStyle = "red";
g.strokeRect(x, y, width, height);
if (this.fill) {
switch (this.fill_color) {
case Plow.COLOR_GRAY:
g.fillStyle = "grey";
break;
case Plow.COLOR_RED:
g.fillStyle = "red";
break;
case Plow.COLOR_YELLOW:
g.fillStyle = "yellow";
break;
case Plow.COLOR_GREEN:
g.fillStyle = "lightgreen";
break;
case Plow.COLOR_WHITE:
if (node.invert)
g.fillStyle = "black";
else
g.fillStyle = "white";
break;
default:
if (node.invert)
g.fillStyle = "white";
else
g.fillStyle = "black";
}
g.fillRect(x, y, width, height);
}
}
this.set_borders = function (node) {
if (this.ll.x + node.pos.x < node.x_left)
node.x_left = this.ll.x + node.pos.x;
if (this.ur.x + node.pos.x > node.x_right)
node.x_right = this.ur.x + node.pos.x;
if (this.ll.y + node.pos.y < node.y_low)
node.y_low = this.ll.y + node.pos.y;
if (this.ur.y + node.pos.y > node.y_high)
node.y_high = this.ur.y + node.pos.y;
}
}
function GDraw(ctx) {
this.ctx = ctx;
this.canvas = document.querySelector("canvas");
this.gctx = this.canvas.getContext("2d");
this.offset_top = this.canvas.offsetTop;
}
function PlowCtx() {
this.gdh = 0;
this.debug = false;
this.nodraw = 0;
this.zoom_factor = 20.0;
this.base_zoom_factor = 20.0;
this.offset_x = 0;
this.offset_y = 0;
this.x_right = 0.0;
this.x_left = 0.0;
this.y_high = 0.0;
this.y_low = 0.0;
this.a = new PlowArray(this);
this.a_nc = new PlowArray(this);
this.name = "Claes context";
this.gdraw = new GDraw(this);
this.selct_object = null;
this.event_cb = null;
this.event_object = null;
this.draw = function () {
if (this.nodraw > 0)
return;
this.gdraw.gctx.fillStyle = "white";
this.gdraw.gctx.fillRect(0, 0, this.gdraw.canvas.width, this.gdraw.canvas.height);
this.a.draw(this.gdraw.gctx, null, null, false);
};
this.connect = function () {
for (var i = 0; i < this.a.size(); i++)
this.a.get(i).connect();
};
this.scan = function () {
console.log("ctx scan", this.a.size());
for (var i = 0; i < this.a.size(); i++)
this.a.get(i).scan();
};
this.set_nodraw = function () {
this.nodraw++;
};
this.reset_nodraw = function () {
this.nodraw--;
};
this.size = function () {
return this.a.size()
};
this.event_handler = function (event, x, y) {
var sts = 0;
switch (event) {
case Plow.eEvent_MB1Click:
case Plow.eEvent_MB1ClickShift:
for (var i = 0; i < this.a.size(); i++) {
if (this.a.get(i) instanceof PlowNode) {
sts = this.a.get(i).event_handler(event, x, y);
if (sts == 1)
break;
}
}
if (sts == 1) {
this.event_cb(event, this.event_object, x, y);
this.draw();
}
break;
case Plow.eEvent_Key_Up:
case Plow.eEvent_Key_Down:
case Plow.eEvent_Key_Left:
case Plow.eEvent_Key_Right:
case Plow.eEvent_Key_ShiftRight:
case Plow.eEvent_Key_CtrlR:
case Plow.eEvent_Key_CtrlL:
case Plow.eEvent_Key_CtrlG:
this.event_cb(event, null, 0, 0);
break;
}
};
this.set_select = function (select) {
for (var i = 0; i < this.a.size(); i++) {
if (this.a.get(i) instanceof PlowNode)
this.a.get(i).set_select(select);
}
};
this.set_invert = function (invert) {
for (var i = 0; i < this.a.size(); i++) {
if (this.a.get(i) instanceof PlowNode)
this.a.get(i).set_invert(invert);
}
};
this.get_select = function () {
return this.select_object;
};
this.insert = function (n, dest) {
this.a.add(n);
};
this.insertNode = function (n, destination, destCode) {
this.a.insertNode(n, destination, destCode);
};
this.remove = function (n) {
if (this.select_object == n)
this.select_object = null;
this.a.remove(n);
};
this.insert_nc = function (nc) {
this.a_nc.add(nc);
};
this.configure = function () {
this.a.configure();
this.a.set_borders();
var height = this.a.a.length * 1.0 * this.zoom_factor;
this.gdraw.canvas.height = height;
};
this.get_parent_object = function (o) {
return this.a.get_parent_object(o);
};
this.get_next_object = function (o) {
return this.a.get_next_object(o);
};
this.get_last_object = function () {
return this.a.get_last_object();
};
this.get_first_object = function () {
return this.a.get_first_object();
};
this.get_previous_object = function (o) {
return this.a.get_previous_object(o);
};
this.close_node = function (o) {
this.a.close_node(o);
};
this.is_visible = function (o) {
if ((o.y_high * this.zoom_factor <= window.pageYOffset + window.innerHeight - this.gdraw.offset_top) &&
(o.y_low * this.zoom_factor >= window.pageYOffset - this.gdraw.offset_top))
return true;
return false;
};
this.scroll = function (y, factor) {
window.scrollTo(window.scrollX, y * this.zoom_factor - window.innerHeight * factor + this.gdraw.offset_top)
};
}
\ No newline at end of file
......@@ -21,10 +21,11 @@
<div id="toolitem12" tabindex="-1" class="toolbar-item" role="button"><img src="toolbar_classhelp.png"><img></div>
</div>
<canvas id="flowcanvas" width="1200" height="800"></canvas>
<script src=pwr.js></script>
<script src=cli.js></script>
<script src=gdh.js></script>
<script src=ev.js></script>
<script src="pwr.js"></script>
<script src="cli.js"></script>
<script src="gdh.js"></script>
<script src="plow.js"></script>
<script src="ev.js"></script>
<hr>
<address><a href="mailto:claes@debian86.ssab.com"></a></address>
</body>
......
......@@ -50,892 +50,6 @@ function MhEvent() {
this.syncIdx;
}
/** Start Plow **/
var Bitmaps = {
leaf: 0,
map: 2,
openmap: 4,
object: 6,
attrenum: 8,
attrarra: 10,
attrarel: 12,
attr: 14,
crrwrite: 16,
crrread: 18,
ack: 20,
alarm: 22,
eventacked: 24,
eventalarm: 26,
eventreturn: 28,
info: 30,
system: 32,
maintenance: 34,
blockl: 36,
blockr: 38,
img: [null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null],
pending: [null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null],
images: [
// leaf
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAASElEQVQokWP4jwMwMDBgYBR5XBpwGYZVIzYNGDZB+QyEFOBiM+CyCacGBI0hgEGjsxkYGCiwkSI/4tKMz0DqxCM2A4hOOcQCAObFEQyI2PpKAAAAAElFTkSuQmCC',
// leaf inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAQUlEQVQokWNgYGD4jw1jA2hqsGvAZRhWjdg0oIsh8QkqwMXGbhMuDXAxdAFsNDobyifTRor8SFGoUhSPFKUcYjEAMsMz2y6w8kgAAAAASUVORK5CYII=',
// map
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAKElEQVQokWP4DwUMDAwYGB9gwKUQm0FoGL/JOGwb1TgINZKFSbYOCgD1JxQJG0vK9AAAAABJRU5ErkJggg==',
// map inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAK0lEQVQokWNgYGD4z8DA8B8bgMlhxbgUEgIMBE3Ggkc1Dk6N5AAGUm2DYQAkYTDe0vu7CAAAAABJRU5ErkJggg==',
// openmap
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAQklEQVQokaXOwQ4AIAgCUP7/p+nUlpMSzY2bDwWHA5IEkFJCtaiKxE7dvsue8HZNJEPneoAuSq+OYAf9wy4K0Mk5C+d++RWimsw3AAAAAElFTkSuQmCC',
// openmap inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAPUlEQVQokaXRQQoAQAgCQP//6brKZmSt0M2hIACI4yBURqiKXQp0ThuhGwmt7Vy00XvqCa7QN1wjhtYLCCYyCkvDVnkJOQAAAABJRU5ErkJggg==',
// object
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAH0lEQVQokWP4TyJgYGBg+E8iZiDFdHrZMKqBGA2kYAD8gaJsjwzf9wAAAABJRU5ErkJggg==',
// object inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIklEQVQokWNgYGD4TxL+TyJg+P//P9GmwzXQ3oZRDdSOBwAGOSrkrXppgQAAAABJRU5ErkJggg==',
// attrenum
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAPklEQVQokWP4////fwYGBgxMCDBgU4jNICyYsOlYbENoJNIW7BqJsYm2NuJyBVE2EqWRfjbiUoQ3oAgpwgUANLqccvbgec0AAAAASUVORK5CYII=',
// attrenum inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAPElEQVQokWNgYGD4jw0wMDDgx9gUEgMYiDIdDaNoJBZg1UiUTTS1EZcriLKRKI30sxGXIgKBhF8RrqgBAOTOqGZ5aiCnAAAAAElFTkSuQmCC',
// attrarra
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAMElEQVQokWP4////fwYGBgxMCDBgU4jNICwYv+nY5InWOGojXW0khLEahtc6PDYCAB9hxkjBPICvAAAAAElFTkSuQmCC',
// attrarray inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAALUlEQVQokWNgYGD4jw0wMDDgx9gUEgMYCJmOTZ5ojaM20tVGQgCHK/AnLVwAAPonfpBwU5f4AAAAAElFTkSuQmCC',
// attrarel
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIklEQVQokWP4////fwYGBpwYHTDANGADeDWM2jAEbSAFAADB26JsIjYj1AAAAABJRU5ErkJggg==',
// attrarel inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIElEQVQokWNgYGD4jw8wMDCgYwZcEvg1jNowBG0gBQMAQN8q5COZl1cAAAAASUVORK5CYII=',
// attr
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIUlEQVQokWP4TyJgGIQaGBgY/pOIibcEroEkTLIfhoEGADzs8B5gcUg/AAAAAElFTkSuQmCC',
// attr inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAJUlEQVQokWNgYGD4TyIedBr+kwgY/v//T7TpcA0k2TAIQ4nmGgDFzt0jExR7hgAAAABJRU5ErkJggg==',
// crrwrite
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAN0lEQVQokaWNQQoAMAjD8v9P633WVWhBkJIotQQoYPYbrHYrqC9D+MG54OBMuMC54GApuPBed9OxiMNLGke1JwAAAABJRU5ErkJggg==',
// crrwrite inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAANElEQVQokWNgYGD4jw3DABY57IqxsQlqwGELSYop1ECEYgo0EKmYQg1EKMbUQEAxRAMpAABRMgoFjbTzXgAAAABJRU5ErkJggg==',
// crrread
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWNgYGD4j4yRATY5BmyKkGks4qgS2BSj2UYFDdgAdW2gvpOwhDW6ItwaCGI8JuHWgMOtWD0PACufaaWhXDFDAAAAAElFTkSuQmCC',
// crrread inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWP4jwYYGBjgGKscNkXINLo4hgZsipFto44GbJi6NlDfSehhjUxjyGMVxQMYcJmEVwPB5ICEAdcbY6vf9TVAAAAAAElFTkSuQmCC',
// ack
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAS0lEQVQokZ2Q2w4AIAhCz///ND11M3RVmxuDUBRAtw8QHRyC4SSJSDjDht1Yhxdudks+bFNxYsX9G6rz2qVHxqRspGi2Wpoji/dqaLh22DbO2VuXAAAAAElFTkSuQmCC',
// ack inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAASklEQVQokWP4////fwYGBqIwVC2cgSKBTQzKxhDA0ICmGau12BRCMLJp2BQgy8H9gM9ELGJkasAXvFg9TQjgDCVc8YBXAwFMmgYASkT1C9E5Ya0AAAAASUVORK5CYII=',
// alarm
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAARklEQVQokZ2QQQoAMAjD+v9Pu9PA1ThQQRBtoFUBJSkk0SlwOwKykCAEcn+BK8hih/aAe++y7IDuhWgXfcKHCuBBfX6ASR3Vn8ZINQzCrQAAAABJRU5ErkJggg==',
// alarm inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAQ0lEQVQokWNgYGD4j45hAJscA8UakBXi0ITddDy2YJqOrBiLJjI1oLsdj1/I0IAnCLFpwtSALYQwNKB7FJ2NooEUDAAtGwcI+Svs4gAAAABJRU5ErkJggg==',
// eventacked
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAL0lEQVQokWP4TyJgGCkaGBgQyhhwSeASw9CAYho2A3CZiE0xVg34FOPUgA+QrAEA1FYi+tWeG/cAAAAASUVORK5CYII=',
// eventacked inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAMElEQVQokWNgYGD4TyIeGRr+//+PXQOaBC4xVElkBdgMwHASTBEOxdj9gEcxHYIVAC5kqlZXl5JMAAAAAElFTkSuQmCC',
// eventalarm
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAJ0lEQVQokWP4jwMwMDBgF8elGIZHNeDSANOEVRyXBpwGUcUGqvoBAK+H8xt0qXFWAAAAAElFTkSuQmCC',
// eventalarm inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAJ0lEQVQokWNgYGD4jw3///8fqzgDLsUwMKoBlwaSg5UAHoiIw2cDAFMz2iY65DAoAAAAAElFTkSuQmC',
// eventreturn
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAASUlEQVQokZ2RUQoAIAjFdv9L11dhskeUEIQ2mcYIAXjeisA+EahFA9ad/siAA0wqSUsnu87wDZh3VEodO6Rr1c51rc8fd9OoMQHLk7dXak3qLwAAAABJRU5ErkJggg==',
// eventreturn inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAR0lEQVQokZ2S2woAIAhD9/8/vV6tjgMNhLxMN1SSTGYb46JkfS2gJglQ/ncRAZ5JTCXQYsFRwxpAvFtKoeMvmoqDv1jc5DQONycV+bfOetgAAAAASUVORK5CYII=',
// info
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAOUlEQVQokWNgYGD4///////E0AwMDP8hPDQAk8QhjlMCuzg2G3AB6tlAez8MglAiCZNiw/////8DACmmtFrq9aGNAAAAAElFTkSuQmCC',
// info inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAN0lEQVQokWP4////fwYGhv/E0FA2w390jCSJIc6ASwKnBmw24MLUs4H2fhgEoUQKIMkGBgaG/wDZFBj2pVi3HgAAAABJRU5ErkJggg==',
// system
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAN0lEQVQokWNgYGD4TyJm+E8sgGugig3YxHFqwGcIQQ3obAwN6G7GawMuhVg1EFKMUwM+QJ+IAwDD1Gyi1EZc6gAAAABJRU5ErkJggg==',
// system inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAO0lEQVQokWP4TyJg+P///38GBgaiMFwDVWzAJo5TA15DCGnAYKNrwHAzPhtwKcSqgZBinBqIigeaRhwAPuZgrlZXy70AAAAASUVORK5CYII=',
// maintenance
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAP0lEQVQokZWPQQoAMAzC8v9Pu8soDOxaBS82QkWNgPKTJ/BYsLekAOxfquwHWyfws6ED7OgtfNk9bAuTSGBJOufqnHIsmYkzAAAAAElFTkSuQmCC',
// maintenance inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAQUlEQVQokZWPQQ4AMAQE5/+f1kuTCkuROGAmADCVPsJsBfdCsX0u3N7sJFfXsAqW8BMaID+9gE3SJayEFo7CFwY7GtAw3ouVj50AAAAASUVORK5CYII=',
// blockl
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAQElEQVQokZ2QQQ4AMAjC+v9Pu9MWl5AJ42a0IlKBgCIadgGgQ8imqo9D3zDBvJoyR+zwlWHS9SUHaOf4QOywtQCQGucn0g2dEQAAAABJRU5ErkJggg==',
// blockl inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAOklEQVQokWNgYGD4Tyz+////fwZSFBOtAaoQQsM46JLY+HAbUEwgrJmwyZTZQJYfSAolmsQDWTENwwByoOYaWbAqegAAAABJRU5ErkJggg==',
// blockr
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWP4jwMwMDBgF8enAZsmvBqw2cSARQBDIQqbGEUoaggpQBcj3Qay/IAN4AwlfBrIigeiNeACADpU5yeYXn+XAAAAAElFTkSuQmCC',
// blockr inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWNgYGD4jw3///8fqzgDPg04NOG3AUMTugA2hWhqiFKEzCeoAF2MRBvI8gNJoUT1eCBaAy4MAMhm5hr5iTaWAAAAAElFTkSuQmCC'
]
};
var Plow = {
DRAWOFFSET: 2,
DEST_INTOLAST: 0,
DEST_INTOFIRST: 1,
DEST_AFTER: 2,
DEST_BEFORE: 3,
TREE_INDENTATION: 1.0,
OPEN_ATTRIBUTES: 1,
OPEN_CHILDREN: 2,
OPEN_CROSSREFERENCES: 4,
OPEN_ALL: 7,
COLOR_BLACK: 1,
COLOR_RED: 2,
COLOR_GRAY: 3,
COLOR_DARKGRAY: 4,
COLOR_LIGHTGRAY: 5,
COLOR_WHITE: 6,
COLOR_YELLOW: 7,
COLOR_GREEN: 8,
COLOR_LIGHTBLUE: 9,
COLOR_BLUE: 10,
COLOR_VIOLET: 11,
eEvent_MB1Click: 0,
eEvent_MB1ClickShift: 1,
eEvent_Key_Up: 2,
eEvent_Key_Down: 3,
eEvent_Key_Right: 4,
eEvent_Key_Left: 5,
eEvent_Key_ShiftRight: 6,
eEvent_Key_CtrlR: 7,
eEvent_Key_CtrlL: 8,
eEvent_Key_CtrlG: 9,
eEvent_ObjectDeleted: 10,
RELATIVE_POSITION: 1,
NEXT_RELATIVE_POSITION: 2
}
function PlowGeometry() {
this.ll_x = 0;
this.ll_y = 0;
this.ur_x = 0;
this.ur_y = 0;
}
function PlowNodeClass(ctx) {
this.a = new PlowArray(ctx);
this.ctx = ctx;
this.nc_name = "";
this.group = 0;
this.node_open = 0;
this.draw = function (g, p, node, highlight) {
this.a.draw(g, p, node, highlight);
}
this.insert = function (elem) {
this.a.add(elem);
}
}
function PlowArray(ctx) {
this.a = [];
this.ctx = ctx;
this.add = function (elem) {
this.a.push(elem);
}
this.insertNode = function (elem, destination, code) {
var idx = this.find(elem);
if (idx != -1)
return;
if (destination == null) {
switch (code) {
case Plow.DEST_INTOLAST:
case Plow.DEST_AFTER:
this.a.push(elem);
elem.level = 0;
break;
default:
elem.level = 0;
this.a.unshift(elem);
}
}
else {
var dest_idx = this.find(destination);
if (dest_idx == -1)
return;
switch (code) {
case Plow.DEST_INTOFIRST:
if (dest_idx == this.a.length - 1)
this.a.push(elem);
else
this.a.splice(dest_idx + 1, 0, elem);
elem.level = destination.level + 1;
break;
case Plow.DEST_INTOLAST: {
if (dest_idx == this.a.length - 1)
this.a.push(elem);
else {
idx = this.a.length;
for (var i = dest_idx + 1; i < this.a.length; i++) {
if (this.a[i].level <= destination.level) {
idx = i;
break;
}
}
if (idx == this.a.length)
this.a.push(elem);
else
this.a.splice(idx, 0, elem);
}
elem.level = destination.level + 1;
break;
}
case Plow.DEST_AFTER: {
if (dest_idx == this.a.length - 1)
this.a.push(elem);
else {
var i;
for (i = idx; i < this.a.length; i++) {
if (this.a[i].level < destination.level)
break;
}
this.a.splice(i, 0, elem);
}
elem.level = destination.level;
break;
}
case Plow.DEST_BEFORE:
if (idx > 0)
idx--;
this.a.splice(idx, 0, elem);
elem.level = destination.level;
break;
}
}
}
this.remove = function (elem) {
var idx = this.find(elem);
if (idx == -1)
return;
this.ctx.event_cb(Plow.eEvent_ObjectDeleted, this.a[idx + 1], 0, 0);
this.a.splice(idx, 1);
}
this.size = function () {
return this.a.length;
}
this.get = function (idx) {
return this.a[idx];
}
this.draw = function (g, p, node, highlight) {
for (var i = 0; i < this.a.length; i++)
this.a[i].draw(g, p, node, highlight);
}
this.set_borders = function (node) {
for (var i = 0; i < this.a.length; i++)
this.a[i].set_borders(node);
}
this.configure = function () {
for (var i = 0; i < this.a.length; i++) {
this.a[i].pos.x = this.a[i].level * 1.0;
this.a[i].pos.y = i * 1.0;
}
}
this.close_node = function (node) {
var idx = this.find(node);
if (idx == -1)
return;
var level = node.level;
var i;
for (i = idx + 1; i < this.a.length; i++) {
if (this.a[i].level <= level)
break;
}
var next_idx = i;
if (next_idx == idx + 1)
return;
for (i = idx + 1; i < next_idx; i++) {
// Event backcall
if (ctx.select_object == this.a[idx + 1])
ctx.select_object = null;
this.ctx.event_cb(Plow.eEvent_ObjectDeleted, this.a[idx + 1], 0, 0);
this.a.splice(idx + 1, 1);
}
}
this.get_parent_object = function (node) {
var idx = this.find(node);
if (idx == -1)
return null;
for (var i = idx; i >= 0; i--) {
if (this.a[i].level < node.level)
return this.a[i];
}
return null;
}
this.get_first_child = function (node) {
var idx = this.find(node);
if (idx == -1)
return null;
if (this.a.length == idx - 1)
return null;
if (this.a[idx + 1].level > node.level)
return this.a[idx + 1];
return null;
}
this.get_next_sibling = function (node) {
var found = false;
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == node) {
found = true;
continue;
}
if (found) {
if (this.a[i].level == node.level)
return this.a[i];
if (this.a[i].level < node.level)
return null;
}
}
return null;
}
this.get_next_object = function (node) {
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == node) {
if (i == this.a.length - 1)
return null;
return this.a[i + 1];
}
}
return null;
}
this.get_previous_object = function (node) {
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == node) {
if (i == 0)
return null;
return this.a[i - 1];
}
}
return null;
}
this.get_first_object = function () {
if (this.a.length == 0)
return null;
return this.a[0];
}
this.get_last_object = function () {
if (this.a.length == 0)
return null;
return this.a[this.a.length - 1];
}
this.find = function (elem) {
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == elem)
return i;
}
return -1;
}
}
function PlowNode(ctx, nc, level) {
this.ctx = ctx;
this.userdata = null;
this.OFFSET = 2;
this.x_right = 0.0;
this.x_left = 0.0;
this.y_high = 0.0;
this.y_low = 0.0;
this.nc = nc;
this.pos = new PlowPoint(ctx, 0, 0);
this.n_name = "";
this.annotv = [];
this.annotsize = [];
this.pixmapv = [];
this.trace_object = "";
this.trace_attribute = "";
this.trace_attr_type = 0;
this.highlight = false;
this.select = false;
this.invert = false;
this.level = level;
this.node_open = false;
this.fill_color = 0;
this.p = 0;
this.old_value = 0;
this.first_scan = true;
this.relative_position = 0;
this.set_annotation = function (number, text) {
if (number >= 10)
return;
this.annotv[number] = text;
}
this.set_annotation_pixmap = function (number, pixmap) {
if (number >= 10)
return;
this.pixmapv[number] = pixmap;
}
this.draw_object = function () {
this.draw(this.ctx.gdraw.gctx, null, null, false);
}
this.draw = function (g, p, node, highlight) {
var x = this.x_left * this.ctx.zoom_factor;
var y = this.y_low * this.ctx.zoom_factor - 1;
var width = (this.x_right - this.x_left) * this.ctx.zoom_factor;
var height = (this.y_high - this.y_low) * this.ctx.zoom_factor + 2;
g.fillStyle = "white";
if (this.select)
g.fillStyle = "lightblue";
g.fillRect(x, y, width, height);
this.nc.draw(g, this.pos, this, this.highlight);
}
this.connect = function () {
if (this.trace_object == "" || this.trace_attribute == "")
return;
var n = this.trace_attribute.indexOf('#');
if (n != -1)
this.trace_attribute = this.trace_attribute.substring(0, n);
var o = this.trace_object + "." + this.trace_attribute;
this.p = ctx.gdh.refObjectInfo(o, this.trace_attr_type);
console.log("connecting", o, this.p);
}
this.scan = function () {
if (this.p == 0)
return;
var v1 = ctx.gdh.getRefObjectInfo(this.p);
var evaluate = true;
if (this.first_scan)
this.first_scan = false;
else if (v1 == this.old_value)
return;
if (v1)
this.highlight = true;
else
this.highlight = false;
this.old_value = v1;
this.draw_object();
}
this.set_borders = function () {
this.x_left = 1e37;
this.x_right = -1e37;
this.y_low = 1e37;
this.y_high = -1e37;
nc.a.set_borders(this);
}
this.event_handler = function (event, x, y) {
if ((x - this.ctx.offset_x) / this.ctx.zoom_factor >= this.x_left &&
(x - this.ctx.offset_x) / this.ctx.zoom_factor <= this.x_right &&
(y - this.ctx.offset_y) / this.ctx.zoom_factor >= this.y_low &&
(y - this.ctx.offset_y) / this.ctx.zoom_factor <= this.y_high) {
ctx.event_object = this;
return 1;
}
return 0;
}
this.set_select = function (select) {
if (select) {
this.select = true;
this.ctx.select_object = this;
}
else {
this.select = false;
if (this.ctx.select_object == this)
this.ctx.select_object = null;
}
if (select != this.select)
this.draw_object();
}
this.set_invert = function (invert) {
this.invert = invert;
this.draw_object();
}
this.set_userdata = function (userdata) {
this.userdata = userdata;
}
this.get_userdata = function () {
return this.userdata;
}
this.in_icon = function (x, y) {
if (x >= this.x_left * this.ctx.zoom_factor &&
x <= (this.x_left + 1.75) * this.ctx.zoom_factor)
return true;
return false;
}
this.measure = function () {
var geom = new PlowGeometry();
geom.ll_x = this.x_left * this.ctx.zoom_factor;
geom.ll_y = this.y_low * this.ctx.zoom_factor;
geom.ur_x = this.x_right * this.ctx.zoom_factor;
geom.ur_y = this.y_high * this.ctx.zoom_factor;
return geom;
};
}
function PlowPoint(ctx, x, y) {
this.x = x;
this.y = y;
this.ctx = ctx;
}
function PlowAnnot(ctx, x, y, text_size, text_color, annot_type, number) {
this.RELATIVE_OFFSET = 1;
this.p = new PlowPoint(ctx, x, y);
this.draw_type = text_color;
this.text_size = text_size;
this.annot_type = annot_type;
this.number = number;
this.ctx = ctx;
this.draw = function (g, p0, node, highlight) {
if (node == null)
return;
if (node.annotv[this.number] == null)
return;
var tsize = 0;
var idx = this.ctx.zoom_factor / this.ctx.base_zoom_factor * (this.text_size + 4) - 4;
if (idx < 0) return;
switch (idx) {
case 0:
tsize = 8;
break;
case 1:
tsize = 10;
break;
case 2:
tsize = 12;
break;
case 3:
tsize = 14;
break;
case 4:
tsize = 14;
break;
case 5:
tsize = 18;
break;
case 6:
tsize = 18;
break;
case 7:
tsize = 18;
break;
default:
tsize = idx * 3;
}
g.font = tsize + "px Arial";
if (node.invert)
g.fillStyle = "white";
else
g.fillStyle = "black";
if (highlight)
g.fillStyle = "red";
g.lineWidth = 0.5;
var x = (this.p.x + p0.x) * this.ctx.zoom_factor;
var y = (this.p.y + p0.y) * this.ctx.zoom_factor - tsize / 4;
if ((this.annot_type & Plow.RELATIVE_POSITION) != 0) {
var rel_x = (p0.x + node.relative_position + this.RELATIVE_OFFSET) * this.ctx.zoom_factor;
if (x < rel_x)
x = rel_x;
}
var tokens = node.annotv[this.number].split('\n');
for (var i = 0; i < tokens.length; i++) {
g.fillText(tokens[i], x, y);
y += tsize * 1.4;
}
if ((this.annot_type & Plow.NEXT_RELATIVE_POSITION) != 0 || (this.annot_type & Plow.RELATIVE_POSITION) != 0) {
node.relative_position = (x + g.measureText(node.annotv[this.number]).width) / this.ctx.zoom_factor - p0.x;
}
}
this.set_borders = function (node) {
}
}
function PlowAnnotPixmap(ctx, x, y, number) {
this.p = new PlowPoint(ctx, x, y);
this.number = number;
this.ctx = ctx;
this.draw = function (gctx, p0, node, highlight) {
var x = (this.p.x + p0.x) * this.ctx.zoom_factor;
var y = (this.p.y + p0.y) * this.ctx.zoom_factor;
var img;
var bix = node.pixmapv[this.number];
if (typeof bix === 'undefined' || bix === null)
return;
if (node.invert)
bix++;
img = Bitmaps.img[bix];
if (img == null) {
var img = new Image();
img.src = Bitmaps.images[bix];
Bitmaps.img[bix] = img;
Bitmaps.pending[bix] = [];
Bitmaps.pending[bix].push(new PlowPoint(this.ctx, x, y));
img.onload = function () {
for (var i = 0; i < Bitmaps.pending[bix].length; i++)
gctx.drawImage(img, Bitmaps.pending[bix][i].x, Bitmaps.pending[bix][i].y);
Bitmaps.pending[bix] = null;
}
}
else {
if (!img.complete)
Bitmaps.pending[bix].push(new PlowPoint(this.ctx, x, y));
else
gctx.drawImage(img, x, y);
}
}
this.set_borders = function (node) {
}
}
function PlowRect(ctx, x, y, width, height, fill_color, border_color, fill, fix_color) {
this.ll = new PlowPoint(ctx, x, y);
this.ur = new PlowPoint(ctx, x + width, y + height);
this.border_color = border_color;
this.fill_color = fill_color;
this.fill = fill;
this.fix_color = fix_color;
this.ctx = ctx;
this.draw = function (g, p, node, highlight) {
var x = (this.ll.x + p.x) * this.ctx.zoom_factor;
var y = (this.ll.y + p.y) * this.ctx.zoom_factor;
var width = (this.ur.x - this.ll.x) * this.ctx.zoom_factor;
var height = (this.ur.y - this.ll.y) * this.ctx.zoom_factor;
g.lineWidth = 1;
switch (this.border_color) {
case Plow.COLOR_GRAY:
g.strokeStyle = "grey";
break;
case Plow.COLOR_RED:
g.strokeStyle = "red";
break;
case Plow.COLOR_WHITE:
g.strokeStyle = "white";
break;
default:
g.strokeStyle = "black";
}
if (highlight)
g.strokeStyle = "red";
g.strokeRect(x, y, width, height);
if (this.fill) {
switch (this.fill_color) {
case Plow.COLOR_GRAY:
g.fillStyle = "grey";
break;
case Plow.COLOR_RED:
g.fillStyle = "red";
break;
case Plow.COLOR_YELLOW:
g.fillStyle = "yellow";
break;
case Plow.COLOR_GREEN:
g.fillStyle = "lightgreen";
break;
case Plow.COLOR_WHITE:
if (node.invert)
g.fillStyle = "black";
else
g.fillStyle = "white";
break;
default:
if (node.invert)
g.fillStyle = "white";
else
g.fillStyle = "black";
}
g.fillRect(x, y, width, height);
}
}
this.set_borders = function (node) {
if (this.ll.x + node.pos.x < node.x_left)
node.x_left = this.ll.x + node.pos.x;
if (this.ur.x + node.pos.x > node.x_right)
node.x_right = this.ur.x + node.pos.x;
if (this.ll.y + node.pos.y < node.y_low)
node.y_low = this.ll.y + node.pos.y;
if (this.ur.y + node.pos.y > node.y_high)
node.y_high = this.ur.y + node.pos.y;
}
}
function GDraw(ctx) {
this.ctx = ctx;
this.canvas = document.querySelector("canvas");
this.gctx = this.canvas.getContext("2d");
this.offset_top = this.canvas.offsetTop;
}
function PlowCtx() {
this.gdh = 0;
this.debug = false;
this.nodraw = 0;
this.zoom_factor = 20.0;
this.base_zoom_factor = 20.0;
this.offset_x = 0;
this.offset_y = 0;
this.x_right = 0.0;
this.x_left = 0.0;
this.y_high = 0.0;
this.y_low = 0.0;
this.a = new PlowArray(this);
this.a_nc = new PlowArray(this);
this.name = "Claes context";
this.gdraw = new GDraw(this);
this.selct_object = null;
this.event_cb = null;
this.event_object = null;
this.draw = function () {
if (this.nodraw > 0)
return;
this.gdraw.gctx.fillStyle = "white";
this.gdraw.gctx.fillRect(0, 0, this.gdraw.canvas.width, this.gdraw.canvas.height);
this.a.draw(this.gdraw.gctx, null, null, false);
};
this.connect = function () {
for (var i = 0; i < this.a.size(); i++)
this.a.get(i).connect();
};
this.scan = function () {
console.log("ctx scan", this.a.size());
for (var i = 0; i < this.a.size(); i++)
this.a.get(i).scan();
};
this.set_nodraw = function () {
this.nodraw++;
};
this.reset_nodraw = function () {
this.nodraw--;
};
this.size = function () {
return this.a.size()
};
this.event_handler = function (event, x, y) {
var sts = 0;
switch (event) {
case Plow.eEvent_MB1Click:
case Plow.eEvent_MB1ClickShift:
for (var i = 0; i < this.a.size(); i++) {
if (this.a.get(i) instanceof PlowNode) {
sts = this.a.get(i).event_handler(event, x, y);
if (sts == 1)
break;
}
}
if (sts == 1) {
this.event_cb(event, this.event_object, x, y);
this.draw();
}
break;
case Plow.eEvent_Key_Up:
case Plow.eEvent_Key_Down:
case Plow.eEvent_Key_Left:
case Plow.eEvent_Key_Right:
case Plow.eEvent_Key_ShiftRight:
case Plow.eEvent_Key_CtrlR:
case Plow.eEvent_Key_CtrlL:
case Plow.eEvent_Key_CtrlG:
this.event_cb(event, null, 0, 0);
break;
}
};
this.set_select = function (select) {
for (var i = 0; i < this.a.size(); i++) {
if (this.a.get(i) instanceof PlowNode)
this.a.get(i).set_select(select);
}
};
this.set_invert = function (invert) {
for (var i = 0; i < this.a.size(); i++) {
if (this.a.get(i) instanceof PlowNode)
this.a.get(i).set_invert(invert);
}
};
this.get_select = function () {
return this.select_object;
};
this.insert = function (n, dest) {
this.a.add(n);
};
this.insertNode = function (n, destination, destCode) {
this.a.insertNode(n, destination, destCode);
};
this.remove = function (n) {
if (this.select_object == n)
this.select_object = null;
this.a.remove(n);
};
this.insert_nc = function (nc) {
this.a_nc.add(nc);
};
this.configure = function () {
this.a.configure();
this.a.set_borders();
var height = this.a.a.length * 1.0 * this.zoom_factor;
this.gdraw.canvas.height = height;
};
this.get_parent_object = function (o) {
return this.a.get_parent_object(o);
};
this.get_next_object = function (o) {
return this.a.get_next_object(o);
};
this.get_last_object = function () {
return this.a.get_last_object();
};
this.get_first_object = function () {
return this.a.get_first_object();
};
this.get_previous_object = function (o) {
return this.a.get_previous_object(o);
};
this.close_node = function (o) {
this.a.close_node(o);
};
this.is_visible = function (o) {
if ((o.y_high * this.zoom_factor <= window.pageYOffset + window.innerHeight - this.gdraw.offset_top) &&
(o.y_low * this.zoom_factor >= window.pageYOffset - this.gdraw.offset_top))
return true;
return false;
};
this.scroll = function (y, factor) {
window.scrollTo(window.scrollX, y * this.zoom_factor - window.innerHeight * factor + this.gdraw.offset_top)
};
}
/** End Plow **/
/** Start Ev **/
function EvOpenChildrenData(node, open_next) {
this.node = node;
......
......@@ -13,9 +13,9 @@
<div id="toolitem4" tabindex="-1" class="toolbar-item" role="button"><img src="toolbar_object.png"><img></div>
</div>
<canvas id="flowcanvas" width="1200" height="800"></canvas>
<script src=pwr.js></script>
<script src=gdh.js></script>
<script src=flow.js></script>
<script src="pwr.js"></script>
<script src="gdh.js"></script>
<script src="flow.js"></script>
<hr>
<address><a href="mailto:claes@debian86.ssab.com"></a></address>
</body>
......
......@@ -7,10 +7,10 @@
<body>
<canvas id="flowcanvas" width="1200" height="800"></canvas>
<script src=pwr.js></script>
<script src=cli.js></script>
<script src=gdh.js></script>
<script src=ge.js></script>
<script src="pwr.js"></script>
<script src="cli.js"></script>
<script src="gdh.js"></script>
<script src="ge.js"></script>
<hr>
<address><a href="mailto:claes@debian86.ssab.com"></a></address>
</body>
......
......@@ -21,9 +21,10 @@
<button id="logout_button" type="button" class="leftmenu-button">Logout</button>
</div>
</div>
<script src=crypt.js></script>
<script src=pwr.js></script>
<script src=opwind.js></script>
<script src="crypt.js"></script>
<script src="pwr.js"></script>
<script src="gdh.js"></script>
<script src="opwind.js"></script>
<hr>
<address><a href="mailto:claes@debian86.ssab.com"></a></address>
</body>
......
......@@ -17,10 +17,11 @@
<div id="toolitem8" tabindex="-1" class="toolbar-item" role="button"><img src="toolbar_classhelp.png"><img></div>
</div>
<canvas id="flowcanvas" width="1200" height="800"></canvas>
<script src=pwr.js></script>
<script src=cli.js></script>
<script src=gdh.js></script>
<script src=xtt.js></script>
<script src="pwr.js"></script>
<script src="cli.js"></script>
<script src="gdh.js"></script>
<script src="plow.js"></script>
<script src="xtt.js"></script>
<hr>
<address><a href="mailto:claes@debian86.ssab.com"></a></address>
</body>
......
......@@ -4,892 +4,6 @@ var GraphIfc = {
eType_Bit: (1 << 15) + 1
};
/** Start Plow **/
var Bitmaps = {
leaf: 0,
map: 2,
openmap: 4,
object: 6,
attrenum: 8,
attrarra: 10,
attrarel: 12,
attr: 14,
crrwrite: 16,
crrread: 18,
ack: 20,
alarm: 22,
eventacked: 24,
eventalarm: 26,
eventreturn: 28,
info: 30,
system: 32,
maintenance: 34,
blockl: 36,
blockr: 38,
img: [null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null],
pending: [null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null],
images: [
// leaf
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAASElEQVQokWP4jwMwMDBgYBR5XBpwGYZVIzYNGDZB+QyEFOBiM+CyCacGBI0hgEGjsxkYGCiwkSI/4tKMz0DqxCM2A4hOOcQCAObFEQyI2PpKAAAAAElFTkSuQmCC',
// leaf inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAQUlEQVQokWNgYGD4jw1jA2hqsGvAZRhWjdg0oIsh8QkqwMXGbhMuDXAxdAFsNDobyifTRor8SFGoUhSPFKUcYjEAMsMz2y6w8kgAAAAASUVORK5CYII=',
// map
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAKElEQVQokWP4DwUMDAwYGB9gwKUQm0FoGL/JOGwb1TgINZKFSbYOCgD1JxQJG0vK9AAAAABJRU5ErkJggg==',
// map inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAK0lEQVQokWNgYGD4z8DA8B8bgMlhxbgUEgIMBE3Ggkc1Dk6N5AAGUm2DYQAkYTDe0vu7CAAAAABJRU5ErkJggg==',
// openmap
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAQklEQVQokaXOwQ4AIAgCUP7/p+nUlpMSzY2bDwWHA5IEkFJCtaiKxE7dvsue8HZNJEPneoAuSq+OYAf9wy4K0Mk5C+d++RWimsw3AAAAAElFTkSuQmCC',
// openmap inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAPUlEQVQokaXRQQoAQAgCQP//6brKZmSt0M2hIACI4yBURqiKXQp0ThuhGwmt7Vy00XvqCa7QN1wjhtYLCCYyCkvDVnkJOQAAAABJRU5ErkJggg==',
// object
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAH0lEQVQokWP4TyJgYGBg+E8iZiDFdHrZMKqBGA2kYAD8gaJsjwzf9wAAAABJRU5ErkJggg==',
// object inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIklEQVQokWNgYGD4TxL+TyJg+P//P9GmwzXQ3oZRDdSOBwAGOSrkrXppgQAAAABJRU5ErkJggg==',
// attrenum
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAPklEQVQokWP4////fwYGBgxMCDBgU4jNICyYsOlYbENoJNIW7BqJsYm2NuJyBVE2EqWRfjbiUoQ3oAgpwgUANLqccvbgec0AAAAASUVORK5CYII=',
// attrenum inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAPElEQVQokWNgYGD4jw0wMDDgx9gUEgMYiDIdDaNoJBZg1UiUTTS1EZcriLKRKI30sxGXIgKBhF8RrqgBAOTOqGZ5aiCnAAAAAElFTkSuQmCC',
// attrarra
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAAMElEQVQokWP4////fwYGBgxMCDBgU4jNICwYv+nY5InWOGojXW0khLEahtc6PDYCAB9hxkjBPICvAAAAAElFTkSuQmCC',
// attrarray inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAMCAYAAABSgIzaAAAALUlEQVQokWNgYGD4jw0wMDDgx9gUEgMYCJmOTZ5ojaM20tVGQgCHK/AnLVwAAPonfpBwU5f4AAAAAElFTkSuQmCC',
// attrarel
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIklEQVQokWP4////fwYGBpwYHTDANGADeDWM2jAEbSAFAADB26JsIjYj1AAAAABJRU5ErkJggg==',
// attrarel inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIElEQVQokWNgYGD4jw8wMDCgYwZcEvg1jNowBG0gBQMAQN8q5COZl1cAAAAASUVORK5CYII=',
// attr
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAIUlEQVQokWP4TyJgGIQaGBgY/pOIibcEroEkTLIfhoEGADzs8B5gcUg/AAAAAElFTkSuQmCC',
// attr inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAJUlEQVQokWNgYGD4TyIedBr+kwgY/v//T7TpcA0k2TAIQ4nmGgDFzt0jExR7hgAAAABJRU5ErkJggg==',
// crrwrite
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAN0lEQVQokaWNQQoAMAjD8v9P633WVWhBkJIotQQoYPYbrHYrqC9D+MG54OBMuMC54GApuPBed9OxiMNLGke1JwAAAABJRU5ErkJggg==',
// crrwrite inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAANElEQVQokWNgYGD4jw3DABY57IqxsQlqwGELSYop1ECEYgo0EKmYQg1EKMbUQEAxRAMpAABRMgoFjbTzXgAAAABJRU5ErkJggg==',
// crrread
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWNgYGD4j4yRATY5BmyKkGks4qgS2BSj2UYFDdgAdW2gvpOwhDW6ItwaCGI8JuHWgMOtWD0PACufaaWhXDFDAAAAAElFTkSuQmCC',
// crrread inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWP4jwYYGBjgGKscNkXINLo4hgZsipFto44GbJi6NlDfSehhjUxjyGMVxQMYcJmEVwPB5ICEAdcbY6vf9TVAAAAAAElFTkSuQmCC',
// ack
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAS0lEQVQokZ2Q2w4AIAhCz///ND11M3RVmxuDUBRAtw8QHRyC4SSJSDjDht1Yhxdudks+bFNxYsX9G6rz2qVHxqRspGi2Wpoji/dqaLh22DbO2VuXAAAAAElFTkSuQmCC',
// ack inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAASklEQVQokWP4////fwYGBqIwVC2cgSKBTQzKxhDA0ICmGau12BRCMLJp2BQgy8H9gM9ELGJkasAXvFg9TQjgDCVc8YBXAwFMmgYASkT1C9E5Ya0AAAAASUVORK5CYII=',
// alarm
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAARklEQVQokZ2QQQoAMAjD+v9Pu9PA1ThQQRBtoFUBJSkk0SlwOwKykCAEcn+BK8hih/aAe++y7IDuhWgXfcKHCuBBfX6ASR3Vn8ZINQzCrQAAAABJRU5ErkJggg==',
// alarm inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAQ0lEQVQokWNgYGD4j45hAJscA8UakBXi0ITddDy2YJqOrBiLJjI1oLsdj1/I0IAnCLFpwtSALYQwNKB7FJ2NooEUDAAtGwcI+Svs4gAAAABJRU5ErkJggg==',
// eventacked
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAL0lEQVQokWP4TyJgGCkaGBgQyhhwSeASw9CAYho2A3CZiE0xVg34FOPUgA+QrAEA1FYi+tWeG/cAAAAASUVORK5CYII=',
// eventacked inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAMElEQVQokWNgYGD4TyIeGRr+//+PXQOaBC4xVElkBdgMwHASTBEOxdj9gEcxHYIVAC5kqlZXl5JMAAAAAElFTkSuQmCC',
// eventalarm
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAJ0lEQVQokWP4jwMwMDBgF8elGIZHNeDSANOEVRyXBpwGUcUGqvoBAK+H8xt0qXFWAAAAAElFTkSuQmCC',
// eventalarm inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAJ0lEQVQokWNgYGD4jw3///8fqzgDLsUwMKoBlwaSg5UAHoiIw2cDAFMz2iY65DAoAAAAAElFTkSuQmC',
// eventreturn
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAASUlEQVQokZ2RUQoAIAjFdv9L11dhskeUEIQ2mcYIAXjeisA+EahFA9ad/siAA0wqSUsnu87wDZh3VEodO6Rr1c51rc8fd9OoMQHLk7dXak3qLwAAAABJRU5ErkJggg==',
// eventreturn inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAR0lEQVQokZ2S2woAIAhD9/8/vV6tjgMNhLxMN1SSTGYb46JkfS2gJglQ/ncRAZ5JTCXQYsFRwxpAvFtKoeMvmoqDv1jc5DQONycV+bfOetgAAAAASUVORK5CYII=',
// info
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAOUlEQVQokWNgYGD4///////E0AwMDP8hPDQAk8QhjlMCuzg2G3AB6tlAez8MglAiCZNiw/////8DACmmtFrq9aGNAAAAAElFTkSuQmCC',
// info inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAN0lEQVQokWP4////fwYGhv/E0FA2w390jCSJIc6ASwKnBmw24MLUs4H2fhgEoUQKIMkGBgaG/wDZFBj2pVi3HgAAAABJRU5ErkJggg==',
// system
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAN0lEQVQokWNgYGD4TyJm+E8sgGugig3YxHFqwGcIQQ3obAwN6G7GawMuhVg1EFKMUwM+QJ+IAwDD1Gyi1EZc6gAAAABJRU5ErkJggg==',
// system inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAO0lEQVQokWP4TyJg+P///38GBgaiMFwDVWzAJo5TA15DCGnAYKNrwHAzPhtwKcSqgZBinBqIigeaRhwAPuZgrlZXy70AAAAASUVORK5CYII=',
// maintenance
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAP0lEQVQokZWPQQoAMAzC8v9Pu8soDOxaBS82QkWNgPKTJ/BYsLekAOxfquwHWyfws6ED7OgtfNk9bAuTSGBJOufqnHIsmYkzAAAAAElFTkSuQmCC',
// maintenance inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAQUlEQVQokZWPQQ4AMAQE5/+f1kuTCkuROGAmADCVPsJsBfdCsX0u3N7sJFfXsAqW8BMaID+9gE3SJayEFo7CFwY7GtAw3ouVj50AAAAASUVORK5CYII=',
// blockl
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAQElEQVQokZ2QQQ4AMAjC+v9Pu9MWl5AJ42a0IlKBgCIadgGgQ8imqo9D3zDBvJoyR+zwlWHS9SUHaOf4QOywtQCQGucn0g2dEQAAAABJRU5ErkJggg==',
// blockl inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAOklEQVQokWNgYGD4Tyz+////fwZSFBOtAaoQQsM46JLY+HAbUEwgrJmwyZTZQJYfSAolmsQDWTENwwByoOYaWbAqegAAAABJRU5ErkJggg==',
// blockr
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWP4jwMwMDBgF8enAZsmvBqw2cSARQBDIQqbGEUoaggpQBcj3Qay/IAN4AwlfBrIigeiNeACADpU5yeYXn+XAAAAAElFTkSuQmCC',
// blockr inverted
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAPElEQVQokWNgYGD4jw3///8fqzgDPg04NOG3AUMTugA2hWhqiFKEzCeoAF2MRBvI8gNJoUT1eCBaAy4MAMhm5hr5iTaWAAAAAElFTkSuQmCC'
]
};
var Plow = {
DRAWOFFSET: 2,
DEST_INTOLAST: 0,
DEST_INTOFIRST: 1,
DEST_AFTER: 2,
DEST_BEFORE: 3,
TREE_INDENTATION: 1.0,
OPEN_ATTRIBUTES: 1,
OPEN_CHILDREN: 2,
OPEN_CROSSREFERENCES: 4,
OPEN_ALL: 7,
COLOR_BLACK: 1,
COLOR_RED: 2,
COLOR_GRAY: 3,
COLOR_DARKGRAY: 4,
COLOR_LIGHTGRAY: 5,
COLOR_WHITE: 6,
COLOR_YELLOW: 7,
COLOR_GREEN: 8,
COLOR_LIGHTBLUE: 9,
COLOR_BLUE: 10,
COLOR_VIOLET: 11,
eEvent_MB1Click: 0,
eEvent_MB1ClickShift: 1,
eEvent_Key_Up: 2,
eEvent_Key_Down: 3,
eEvent_Key_Right: 4,
eEvent_Key_Left: 5,
eEvent_Key_ShiftRight: 6,
eEvent_Key_CtrlR: 7,
eEvent_Key_CtrlL: 8,
eEvent_Key_CtrlG: 9,
eEvent_ObjectDeleted: 10,
RELATIVE_POSITION: 1,
NEXT_RELATIVE_POSITION: 2
}
function PlowGeometry() {
this.ll_x = 0;
this.ll_y = 0;
this.ur_x = 0;
this.ur_y = 0;
}
function PlowNodeClass(ctx) {
this.a = new PlowArray(ctx);
this.ctx = ctx;
this.nc_name = "";
this.group = 0;
this.node_open = 0;
this.draw = function (g, p, node, highlight) {
this.a.draw(g, p, node, highlight);
}
this.insert = function (elem) {
this.a.add(elem);
}
}
function PlowArray(ctx) {
this.a = [];
this.ctx = ctx;
this.add = function (elem) {
this.a.push(elem);
}
this.insertNode = function (elem, destination, code) {
var idx = this.find(elem);
if (idx != -1)
return;
if (destination == null) {
switch (code) {
case Plow.DEST_INTOLAST:
case Plow.DEST_AFTER:
this.a.push(elem);
elem.level = 0;
break;
default:
elem.level = 0;
this.a.unshift(elem);
}
}
else {
var dest_idx = this.find(destination);
if (dest_idx == -1)
return;
switch (code) {
case Plow.DEST_INTOFIRST:
if (dest_idx == this.a.length - 1)
this.a.push(elem);
else
this.a.splice(dest_idx + 1, 0, elem);
elem.level = destination.level + 1;
break;
case Plow.DEST_INTOLAST: {
if (dest_idx == this.a.length - 1)
this.a.push(elem);
else {
idx = this.a.length;
for (var i = dest_idx + 1; i < this.a.length; i++) {
if (this.a[i].level <= destination.level) {
idx = i;
break;
}
}
if (idx == this.a.length)
this.a.push(elem);
else
this.a.splice(idx, 0, elem);
}
elem.level = destination.level + 1;
break;
}
case Plow.DEST_AFTER: {
if (dest_idx == this.a.length - 1)
this.a.push(elem);
else {
var i;
for (i = idx; i < this.a.length; i++) {
if (this.a[i].level < destination.level)
break;
}
this.a.splice(i, 0, elem);
}
elem.level = destination.level;
break;
}
case Plow.DEST_BEFORE:
if (idx > 0)
idx--;
this.a.splice(idx, 0, elem);
elem.level = destination.level;
break;
}
}
}
this.remove = function (elem) {
var idx = this.find(elem);
if (idx == -1)
return;
this.ctx.event_cb(Plow.eEvent_ObjectDeleted, this.a[idx + 1], 0, 0);
this.a.splice(idx, 1);
}
this.size = function () {
return this.a.length;
}
this.get = function (idx) {
return this.a[idx];
}
this.draw = function (g, p, node, highlight) {
for (var i = 0; i < this.a.length; i++)
this.a[i].draw(g, p, node, highlight);
}
this.set_borders = function (node) {
for (var i = 0; i < this.a.length; i++)
this.a[i].set_borders(node);
}
this.configure = function () {
for (var i = 0; i < this.a.length; i++) {
this.a[i].pos.x = this.a[i].level * 1.0;
this.a[i].pos.y = i * 1.0;
}
}
this.close_node = function (node) {
var idx = this.find(node);
if (idx == -1)
return;
var level = node.level;
var i;
for (i = idx + 1; i < this.a.length; i++) {
if (this.a[i].level <= level)
break;
}
var next_idx = i;
if (next_idx == idx + 1)
return;
for (i = idx + 1; i < next_idx; i++) {
// Event backcall
if (ctx.select_object == this.a[idx + 1])
ctx.select_object = null;
this.ctx.event_cb(Plow.eEvent_ObjectDeleted, this.a[idx + 1], 0, 0);
this.a.splice(idx + 1, 1);
}
}
this.get_parent_object = function (node) {
var idx = this.find(node);
if (idx == -1)
return null;
for (var i = idx; i >= 0; i--) {
if (this.a[i].level < node.level)
return this.a[i];
}
return null;
}
this.get_first_child = function (node) {
var idx = this.find(node);
if (idx == -1)
return null;
if (this.a.length == idx - 1)
return null;
if (this.a[idx + 1].level > node.level)
return this.a[idx + 1];
return null;
}
this.get_next_sibling = function (node) {
var found = false;
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == node) {
found = true;
continue;
}
if (found) {
if (this.a[i].level == node.level)
return this.a[i];
if (this.a[i].level < node.level)
return null;
}
}
return null;
}
this.get_next_object = function (node) {
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == node) {
if (i == this.a.length - 1)
return null;
return this.a[i + 1];
}
}
return null;
}
this.get_previous_object = function (node) {
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == node) {
if (i == 0)
return null;
return this.a[i - 1];
}
}
return null;
}
this.get_first_object = function () {
if (this.a.length == 0)
return null;
return this.a[0];
}
this.get_last_object = function () {
if (this.a.length == 0)
return null;
return this.a[this.a.length - 1];
}
this.find = function (elem) {
for (var i = 0; i < this.a.length; i++) {
if (this.a[i] == elem)
return i;
}
return -1;
}
}
function PlowNode(ctx, nc, level) {
this.ctx = ctx;
this.userdata = null;
this.OFFSET = 2;
this.x_right = 0.0;
this.x_left = 0.0;
this.y_high = 0.0;
this.y_low = 0.0;
this.nc = nc;
this.pos = new PlowPoint(ctx, 0, 0);
this.n_name = "";
this.annotv = [];
this.annotsize = [];
this.pixmapv = [];
this.trace_object = "";
this.trace_attribute = "";
this.trace_attr_type = 0;
this.highlight = false;
this.select = false;
this.invert = false;
this.level = level;
this.node_open = false;
this.fill_color = 0;
this.p = 0;
this.old_value = 0;
this.first_scan = true;
this.relative_position = 0;
this.set_annotation = function (number, text) {
if (number >= 10)
return;
this.annotv[number] = text;
}
this.set_annotation_pixmap = function (number, pixmap) {
if (number >= 10)
return;
this.pixmapv[number] = pixmap;
}
this.draw_object = function () {
this.draw(this.ctx.gdraw.gctx, null, null, false);
}
this.draw = function (g, p, node, highlight) {
var x = this.x_left * this.ctx.zoom_factor;
var y = this.y_low * this.ctx.zoom_factor - 1;
var width = (this.x_right - this.x_left) * this.ctx.zoom_factor;
var height = (this.y_high - this.y_low) * this.ctx.zoom_factor + 2;
g.fillStyle = "white";
if (this.select)
g.fillStyle = "lightblue";
g.fillRect(x, y, width, height);
this.nc.draw(g, this.pos, this, this.highlight);
}
this.connect = function () {
if (this.trace_object == "" || this.trace_attribute == "")
return;
var n = this.trace_attribute.indexOf('#');
if (n != -1)
this.trace_attribute = this.trace_attribute.substring(0, n);
var o = this.trace_object + "." + this.trace_attribute;
this.p = ctx.gdh.refObjectInfo(o, this.trace_attr_type);
console.log("connecting", o, this.p);
}
this.scan = function () {
if (this.p == 0)
return;
var v1 = ctx.gdh.getRefObjectInfo(this.p);
var evaluate = true;
if (this.first_scan)
this.first_scan = false;
else if (v1 == this.old_value)
return;
if (v1)
this.highlight = true;
else
this.highlight = false;
this.old_value = v1;
this.draw_object();
}
this.set_borders = function () {
this.x_left = 1e37;
this.x_right = -1e37;
this.y_low = 1e37;
this.y_high = -1e37;
nc.a.set_borders(this);
}
this.event_handler = function (event, x, y) {
if ((x - this.ctx.offset_x) / this.ctx.zoom_factor >= this.x_left &&
(x - this.ctx.offset_x) / this.ctx.zoom_factor <= this.x_right &&
(y - this.ctx.offset_y) / this.ctx.zoom_factor >= this.y_low &&
(y - this.ctx.offset_y) / this.ctx.zoom_factor <= this.y_high) {
ctx.event_object = this;
return 1;
}
return 0;
}
this.set_select = function (select) {
if (select) {
this.select = true;
this.ctx.select_object = this;
}
else {
this.select = false;
if (this.ctx.select_object == this)
this.ctx.select_object = null;
}
if (select != this.select)
this.draw_object();
}
this.set_invert = function (invert) {
this.invert = invert;
this.draw_object();
}
this.set_userdata = function (userdata) {
this.userdata = userdata;
}
this.get_userdata = function () {
return this.userdata;
}
this.in_icon = function (x, y) {
if (x >= this.x_left * this.ctx.zoom_factor &&
x <= (this.x_left + 1.75) * this.ctx.zoom_factor)
return true;
return false;
}
this.measure = function () {
var geom = new PlowGeometry();
geom.ll_x = this.x_left * this.ctx.zoom_factor;
geom.ll_y = this.y_low * this.ctx.zoom_factor;
geom.ur_x = this.x_right * this.ctx.zoom_factor;
geom.ur_y = this.y_high * this.ctx.zoom_factor;
return geom;
};
}
function PlowPoint(ctx, x, y) {
this.x = x;
this.y = y;
this.ctx = ctx;
}
function PlowAnnot(ctx, x, y, text_size, text_color, annot_type, number) {
this.RELATIVE_OFFSET = 1;
this.p = new PlowPoint(ctx, x, y);
this.draw_type = text_color;
this.text_size = text_size;
this.annot_type = annot_type;
this.number = number;
this.ctx = ctx;
this.draw = function (g, p0, node, highlight) {
if (node == null)
return;
if (node.annotv[this.number] == null)
return;
var tsize = 0;
var idx = this.ctx.zoom_factor / this.ctx.base_zoom_factor * (this.text_size + 4) - 4;
if (idx < 0) return;
switch (idx) {
case 0:
tsize = 8;
break;
case 1:
tsize = 10;
break;
case 2:
tsize = 12;
break;
case 3:
tsize = 14;
break;
case 4:
tsize = 14;
break;
case 5:
tsize = 18;
break;
case 6:
tsize = 18;
break;
case 7:
tsize = 18;
break;
default:
tsize = idx * 3;
}
g.font = tsize + "px Arial";
if (node.invert)
g.fillStyle = "white";
else
g.fillStyle = "black";
if (highlight)
g.fillStyle = "red";
g.lineWidth = 0.5;
var x = (this.p.x + p0.x) * this.ctx.zoom_factor;
var y = (this.p.y + p0.y) * this.ctx.zoom_factor - tsize / 4;
if ((this.annot_type & Plow.RELATIVE_POSITION) != 0) {
var rel_x = (p0.x + node.relative_position + this.RELATIVE_OFFSET) * this.ctx.zoom_factor;
if (x < rel_x)
x = rel_x;
}
var tokens = node.annotv[this.number].split('\n');
for (var i = 0; i < tokens.length; i++) {
g.fillText(tokens[i], x, y);
y += tsize * 1.4;
}
if ((this.annot_type & Plow.NEXT_RELATIVE_POSITION) != 0 || (this.annot_type & Plow.RELATIVE_POSITION) != 0) {
node.relative_position = (x + g.measureText(node.annotv[this.number]).width) / this.ctx.zoom_factor - p0.x;
}
}
this.set_borders = function (node) {
}
}
function PlowAnnotPixmap(ctx, x, y, number) {
this.p = new PlowPoint(ctx, x, y);
this.number = number;
this.ctx = ctx;
this.draw = function (gctx, p0, node, highlight) {
var x = (this.p.x + p0.x) * this.ctx.zoom_factor;
var y = (this.p.y + p0.y) * this.ctx.zoom_factor;
var img;
var bix = node.pixmapv[this.number];
if (typeof bix === 'undefined' || bix === null)
return;
if (node.invert)
bix++;
img = Bitmaps.img[bix];
if (img == null) {
var img = new Image();
img.src = Bitmaps.images[bix];
Bitmaps.img[bix] = img;
Bitmaps.pending[bix] = [];
Bitmaps.pending[bix].push(new PlowPoint(this.ctx, x, y));
img.onload = function () {
for (var i = 0; i < Bitmaps.pending[bix].length; i++)
gctx.drawImage(img, Bitmaps.pending[bix][i].x, Bitmaps.pending[bix][i].y);
Bitmaps.pending[bix] = null;
}
}
else {
if (!img.complete)
Bitmaps.pending[bix].push(new PlowPoint(this.ctx, x, y));
else
gctx.drawImage(img, x, y);
}
}
this.set_borders = function (node) {
}
}
function PlowRect(ctx, x, y, width, height, fill_color, border_color, fill, fix_color) {
this.ll = new PlowPoint(ctx, x, y);
this.ur = new PlowPoint(ctx, x + width, y + height);
this.border_color = border_color;
this.fill_color = fill_color;
this.fill = fill;
this.fix_color = fix_color;
this.ctx = ctx;
this.draw = function (g, p, node, highlight) {
var x = (this.ll.x + p.x) * this.ctx.zoom_factor;
var y = (this.ll.y + p.y) * this.ctx.zoom_factor;
var width = (this.ur.x - this.ll.x) * this.ctx.zoom_factor;
var height = (this.ur.y - this.ll.y) * this.ctx.zoom_factor;
g.lineWidth = 1;
switch (this.border_color) {
case Plow.COLOR_GRAY:
g.strokeStyle = "grey";
break;
case Plow.COLOR_RED:
g.strokeStyle = "red";
break;
case Plow.COLOR_WHITE:
g.strokeStyle = "white";
break;
default:
g.strokeStyle = "black";
}
if (highlight)
g.strokeStyle = "red";
g.strokeRect(x, y, width, height);
if (this.fill) {
switch (this.fill_color) {
case Plow.COLOR_GRAY:
g.fillStyle = "grey";
break;
case Plow.COLOR_RED:
g.fillStyle = "red";
break;
case Plow.COLOR_YELLOW:
g.fillStyle = "yellow";
break;
case Plow.COLOR_GREEN:
g.fillStyle = "lightgreen";
break;
case Plow.COLOR_WHITE:
if (node.invert)
g.fillStyle = "black";
else
g.fillStyle = "white";
break;
default:
if (node.invert)
g.fillStyle = "white";
else
g.fillStyle = "black";
}
g.fillRect(x, y, width, height);
}
}
this.set_borders = function (node) {
if (this.ll.x + node.pos.x < node.x_left)
node.x_left = this.ll.x + node.pos.x;
if (this.ur.x + node.pos.x > node.x_right)
node.x_right = this.ur.x + node.pos.x;
if (this.ll.y + node.pos.y < node.y_low)
node.y_low = this.ll.y + node.pos.y;
if (this.ur.y + node.pos.y > node.y_high)
node.y_high = this.ur.y + node.pos.y;
}
}
function GDraw(ctx) {
this.ctx = ctx;
this.canvas = document.querySelector("canvas");
this.gctx = this.canvas.getContext("2d");
this.offset_top = this.canvas.offsetTop;
}
function PlowCtx() {
this.gdh = 0;
this.debug = false;
this.nodraw = 0;
this.zoom_factor = 20.0;
this.base_zoom_factor = 20.0;
this.offset_x = 0;
this.offset_y = 0;
this.x_right = 0.0;
this.x_left = 0.0;
this.y_high = 0.0;
this.y_low = 0.0;
this.a = new PlowArray(this);
this.a_nc = new PlowArray(this);
this.name = "Claes context";
this.gdraw = new GDraw(this);
this.selct_object = null;
this.event_cb = null;
this.event_object = null;
this.draw = function () {
if (this.nodraw > 0)
return;
this.gdraw.gctx.fillStyle = "white";
this.gdraw.gctx.fillRect(0, 0, this.gdraw.canvas.width, this.gdraw.canvas.height);
this.a.draw(this.gdraw.gctx, null, null, false);
};
this.connect = function () {
for (var i = 0; i < this.a.size(); i++)
this.a.get(i).connect();
};
this.scan = function () {
console.log("ctx scan", this.a.size());
for (var i = 0; i < this.a.size(); i++)
this.a.get(i).scan();
};
this.set_nodraw = function () {
this.nodraw++;
};
this.reset_nodraw = function () {
this.nodraw--;
};
this.size = function () {
return this.a.size()
};
this.event_handler = function (event, x, y) {
var sts = 0;
switch (event) {
case Plow.eEvent_MB1Click:
case Plow.eEvent_MB1ClickShift:
for (var i = 0; i < this.a.size(); i++) {
if (this.a.get(i) instanceof PlowNode) {
sts = this.a.get(i).event_handler(event, x, y);
if (sts == 1)
break;
}
}
if (sts == 1) {
this.event_cb(event, this.event_object, x, y);
this.draw();
}
break;
case Plow.eEvent_Key_Up:
case Plow.eEvent_Key_Down:
case Plow.eEvent_Key_Left:
case Plow.eEvent_Key_Right:
case Plow.eEvent_Key_ShiftRight:
case Plow.eEvent_Key_CtrlR:
case Plow.eEvent_Key_CtrlL:
case Plow.eEvent_Key_CtrlG:
this.event_cb(event, null, 0, 0);
break;
}
};
this.set_select = function (select) {
for (var i = 0; i < this.a.size(); i++) {
if (this.a.get(i) instanceof PlowNode)
this.a.get(i).set_select(select);
}
};
this.set_invert = function (invert) {
for (var i = 0; i < this.a.size(); i++) {
if (this.a.get(i) instanceof PlowNode)
this.a.get(i).set_invert(invert);
}
};
this.get_select = function () {
return this.select_object;
};
this.insert = function (n, dest) {
this.a.add(n);
};
this.insertNode = function (n, destination, destCode) {
this.a.insertNode(n, destination, destCode);
};
this.remove = function (n) {
if (this.select_object == n)
this.select_object = null;
this.a.remove(n);
};
this.insert_nc = function (nc) {
this.a_nc.add(nc);
};
this.configure = function () {
this.a.configure();
this.a.set_borders();
var height = this.a.a.length * 1.0 * this.zoom_factor;
this.gdraw.canvas.height = height;
};
this.get_parent_object = function (o) {
return this.a.get_parent_object(o);
};
this.get_next_object = function (o) {
return this.a.get_next_object(o);
};
this.get_last_object = function () {
return this.a.get_last_object();
};
this.get_first_object = function () {
return this.a.get_first_object();
};
this.get_previous_object = function (o) {
return this.a.get_previous_object(o);
};
this.close_node = function (o) {
this.a.close_node(o);
};
this.is_visible = function (o) {
if ((o.y_high * this.zoom_factor <= window.pageYOffset + window.innerHeight - this.gdraw.offset_top) &&
(o.y_low * this.zoom_factor >= window.pageYOffset - this.gdraw.offset_top))
return true;
return false;
};
this.scroll = function (y, factor) {
window.scrollTo(window.scrollX, y * this.zoom_factor - window.innerHeight * factor + this.gdraw.offset_top)
};
}
/** End Plow **/
/** Start Xtt **/
function XttOpenChildrenData(node, open_next) {
this.node = node;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment