From b305388240025f26d31227c97f8e78775e8be0ae Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Thu, 16 Jul 2015 00:21:36 -0700 Subject: [PATCH] fix update bounds --- web/app/sketcher/canvas.js | 7 ++++- web/app/sketcher/io.js | 61 ++++++++++++++++++++++++++++++++++++++ web/app/sketcher/main2d.js | 54 --------------------------------- 3 files changed, 67 insertions(+), 55 deletions(-) diff --git a/web/app/sketcher/canvas.js b/web/app/sketcher/canvas.js index eae4891d..a314caa3 100644 --- a/web/app/sketcher/canvas.js +++ b/web/app/sketcher/canvas.js @@ -31,8 +31,13 @@ TCAD.TWO.Styles = { lineWidth : 1, strokeStyle : "#bcffc1", fillStyle : "#00FF00" - } + }, + BOUNDS : { + lineWidth : 2, + strokeStyle : "#fff5c3", + fillStyle : "#000000" + } }; TCAD.TWO.utils = {}; diff --git a/web/app/sketcher/io.js b/web/app/sketcher/io.js index 3e520a11..4ee24428 100644 --- a/web/app/sketcher/io.js +++ b/web/app/sketcher/io.js @@ -185,6 +185,58 @@ TCAD.IO.prototype._serializeSketch = function() { return sketch; }; +TCAD.IO.prototype.updateBoundary = function (boundary) { + if (this.boundaryLayer === undefined) { + this.boundaryLayer = new TCAD.TWO.Layer("bounds", TCAD.TWO.Styles.BOUNDS); + this.viewer.layers.push(this.boundaryLayer); + } + var edges = []; + var bbox = [Number.MAX_VALUE, Number.MAX_VALUE, - Number.MAX_VALUE, - Number.MAX_VALUE]; + var flattenPolygon = function(points) { + var n = points.length; + for ( var p = n - 1, q = 0; q < n; p = q ++ ) { + edges.push([points[p].x, points[p].y, points[q].x, points[q].y]); + bbox[0] = Math.min(bbox[0], points[p].x); + bbox[1] = Math.min(bbox[1], points[p].y); + bbox[2] = Math.max(bbox[2], points[q].x); + bbox[3] = Math.max(bbox[3], points[q].y); + } + }; + + flattenPolygon(boundary.shell); + for (var i = 0; i < boundary.holes.length; ++i ) { + flattenPolygon(boundary.holes[i]); + } +// if (bbox[0] < Number.MAX_VALUE && bbox[1] < Number.MAX_VALUE && -bbox[2] < Number.MAX_VALUE && -bbox[3] < Number.MAX_VALUE) { +// this.viewer.showBounds(bbox[0], bbox[1], bbox[2], bbox[3]) +// } + + for (var l = 0; l < this.viewer.layers.length; ++l) { + var layer = this.viewer.layers[l]; + for (var i = 0; i < layer.objects.length; ++i) { + var obj = layer.objects[i]; + if (obj.edge !== undefined) { + var edge = edges[obj.edge]; + if (edge !== undefined && edge != null) { + obj.a.x = edge[0]; + obj.a.y = edge[1]; + obj.b.x = edge[2]; + obj.b.y = edge[3]; + edges[obj.edge] = null; + } + } + } + } + for (var i = 0; i < edges.length; ++i ) { + var edge = edges[i]; + if (edge != null) { + var seg = this.viewer.addSegment(edge[0], edge[1], edge[2], edge[3], this.boundaryLayer); + seg.accept(function(o){o.aux = true; return true;}); + seg.edge = i; + } + } +}; + TCAD.IO.prototype.parseConstr = function (c, index) { function find(id) { var p = index[id]; @@ -206,3 +258,12 @@ TCAD.IO.prototype.serializeConstr = function (c) { return c.serialize(); }; +TCAD.IO.prototype.svgExport = function (c) { + + // + // + // + // + //var out = ""; + +}; diff --git a/web/app/sketcher/main2d.js b/web/app/sketcher/main2d.js index 10b85f1d..48a9a287 100644 --- a/web/app/sketcher/main2d.js +++ b/web/app/sketcher/main2d.js @@ -1,11 +1,6 @@ - -var magic_k = 500; - TCAD.App2D = function() { this.viewer = new TCAD.TWO.Viewer(document.getElementById('viewer')); - this.boundaryLayer = new TCAD.TWO.Layer("default", TCAD.TWO.Styles.DEFAULT); - this.viewer.layers.push(this.boundaryLayer); var app = this; this.actions = {}; @@ -149,55 +144,6 @@ TCAD.App2D.prototype.loadFromLocalStorage = function() { this.viewer.repaint(); }; -TCAD.App2D.prototype.updateBoundary = function (boundary) { - - var edges = []; - var bbox = [Number.MAX_VALUE, Number.MAX_VALUE, - Number.MAX_VALUE, - Number.MAX_VALUE]; - var flattenPolygon = function(points) { - var n = points.length; - for ( var p = n - 1, q = 0; q < n; p = q ++ ) { - edges.push([points[p].x, points[p].y, points[q].x, points[q].y]); - bbox[0] = Math.min(bbox[0], points[p].x); - bbox[1] = Math.min(bbox[1], points[p].y); - bbox[2] = Math.max(bbox[2], points[q].x); - bbox[3] = Math.max(bbox[3], points[q].y); - } - }; - - flattenPolygon(boundary.shell); - for (var i = 0; i < boundary.holes.length; ++i ) { - flattenPolygon(boundary.holes[i]); - } -// if (bbox[0] < Number.MAX_VALUE && bbox[1] < Number.MAX_VALUE && -bbox[2] < Number.MAX_VALUE && -bbox[3] < Number.MAX_VALUE) { -// this.viewer.showBounds(bbox[0], bbox[1], bbox[2], bbox[3]) -// } - - for (var l = 0; l < this.viewer.layers.length; ++l) { - var layer = this.viewer.layers[l]; - for (var i = 0; i < layer.objects.length; ++i) { - var obj = layer.objects[i]; - if (obj.edge !== undefined) { - var edge = edges[obj.edge]; - if (edge !== undefined && edge != null) { - obj.a.x = edge[0]; - obj.a.y = edge[1]; - obj.b.x = edge[2]; - obj.b.y = edge[3]; - edges[obj.edge] = null; - } - } - } - } - for (var i = 0; i < edges.length; ++i ) { - var edge = edges[i]; - if (edge != null) { - var seg = this.viewer.addSegment(edge[0], edge[1], edge[2], edge[3], this.boundaryLayer); - seg.accept(function(o){o.aux = true; return true;}); - seg.edge = i; - } - } -}; - TCAD.App2D.prototype.getSketchId = function() { var id = window.location.hash.substring(1); if (!id) {