Index: web/client/scripts/draw.js =================================================================== --- web/client/scripts/draw.js (revision 6890) +++ web/client/scripts/draw.js (revision 6891) @@ -8,8 +8,7 @@ * @param options.comm - communication interface * @param options.canvas - HTML canvas rendering context * @param options.colors - color chart for symbolic color names - * @param options.layerGroupMap - prescriptions based on layer group id - * @param options.purposeMap - prescriptions based on layer group purposes + * @param options.layerGroups - options based on layer group id * @param options.onNewLayerGroup - called when a new layer group is defined */ function GraphicEngine(options) { @@ -20,8 +19,8 @@ this.cc = this.mainCc; this.colors = options.colors; this.unit = options.unit || "mm"; - this.purposeMap = options.purposeMap && typeof options.purposeMap === "object" ? - options.purposeMap : {}; + this.layerGroupOptions = options.layerGroups && typeof options.layerGroups === "object" ? + options.layerGroups : {}; this.cc.imageSmoothingEnabled = false; this.mainCc.setTransform(1, 0, 0, 1, 0, 0); @@ -318,19 +317,7 @@ this.cc = this.mainCc; } this.currentLayerGroup = this.layerGroups[id]; - this.enableDrawing = true; - if (this.options.layerGroupMap[id] && this.options.layerGroupMap[id].hidden) { - this.enableDrawing = false; - } - if (this.currentLayerGroup) { - var purposes = this.currentLayerGroup.purposes; - for (var i = 0; i < purposes.length; ++i) { - pe = this.purposeMap[purposes[i]]; - if (pe && pe.hidden) { - this.enableDrawing = false; - } - } - } + this.enableDrawing = !this.layerGroupOptions[id] || this.layerGroupOptions[id].visible; if (this.enableDrawing && this.currentLayerGroup && this.currentLayerGroup.isMask) { this.cc = this.maskCc; this.mainCc.setTransform(1, 0, 0, 1, 0, 0); Index: web/testclient/draw.js =================================================================== --- web/testclient/draw.js (revision 6890) +++ web/testclient/draw.js (revision 6891) @@ -6,7 +6,7 @@ var draw = require("../client/scripts/draw"); var currentBuffer; var layerGroups = {}; -var purposes = {}; +var defaultDisabledPurposes = ["mask", "paste", "fab"]; buildFileList(); @@ -41,9 +41,9 @@ console.log("drawing", url); currentBuffer = new Uint8Array(req.response); layerGroups = {}; - purposes = {}; document.getElementById("layerGroupList").innerHTML = ""; drawBuffer(); + drawBuffer(); } }; req.responseType = 'arraybuffer'; @@ -58,9 +58,7 @@ var lgMap = {}; for (var id in layerGroups) { - if (layerGroups[id].hidden) { - lgMap[id] = { hidden: true }; - } + lgMap[id] = { visible: layerGroups[id].visible }; } var ge = new draw.GraphicEngine({ @@ -70,12 +68,7 @@ colors: { mask: "#274f29" }, - layerGroupMap: lgMap, - purposeMap: { - mask: { hidden: true }, - paste: { hidden: true }, - fab: { hidden: true } - }, + layerGroups: lgMap, onNewLayerGroup: onNewLayerGroup }); @@ -95,9 +88,20 @@ if (layerGroups[lg.id]) { return; } + + // determine initial visibility + var visible = true; + for (var i = 0; i < lg.purposes.length; ++i) { + for (var j = 0; j < defaultDisabledPurposes.length; ++j) { + if (lg.purposes[i] === defaultDisabledPurposes[j]) + visible = false; + } + } + layerGroups[lg.id] = { id: lg.id, - purposes: lg.purposes + purposes: lg.purposes, + visible: visible }; // list the group @@ -114,9 +118,9 @@ var cbox = document.createElement("input"); cbox.type = "checkbox"; cbox.id = "checkbox" + lg.id; - cbox.checked = true; + cbox.checked = visible; cbox.onchange = function () { - layerGroups[lg.id].hidden = !cbox.checked; + layerGroups[lg.id].visible = cbox.checked; drawBuffer(); } li.appendChild(cbox);