From a70b485454f00128c5284227c331ba210e08f377 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Fri, 17 Jul 2015 14:46:09 -0700 Subject: [PATCH] user text builder --- web/app/sketcher/io.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/web/app/sketcher/io.js b/web/app/sketcher/io.js index ac502f9e..94288f0e 100644 --- a/web/app/sketcher/io.js +++ b/web/app/sketcher/io.js @@ -293,6 +293,13 @@ TCAD.io.PrettyColors = function() { } } +TCAD.io.TextBuilder = function() { + this.data = ""; + this.line = function (chunk, args) { + this.data += TCAD.io._format(chunk, args) + "\n" + } +} + TCAD.io.BBox = function() { var bbox = [Number.MAX_VALUE, Number.MAX_VALUE, - Number.MAX_VALUE, - Number.MAX_VALUE]; @@ -337,11 +344,7 @@ TCAD.io.BBox = function() { TCAD.IO.prototype.svgExport = function () { var T = TCAD.io.Types; - var svg = ""; - - function append(chunk, args) { - svg += TCAD.io._format(chunk, args) + "\n" - } + var out = new TCAD.io.TextBuilder(); var bbox = new TCAD.io.BBox(); @@ -356,28 +359,28 @@ TCAD.IO.prototype.svgExport = function () { var layer = layers[l]; if (layer.readOnly) continue; var color = prettyColors.next(); - append('', [layer.name, "none", color, '2']); + out.line('', [layer.name, "none", color, '2']); for (var i = 0; i < layer.objects.length; ++i) { var obj = layer.objects[i]; if (obj._class !== T.END_POINT) bbox.check(obj); if (obj._class === T.SEGMENT) { - append('', [obj.a.x, obj.a.y, obj.b.x, obj.b.y]); + out.line('', [obj.a.x, obj.a.y, obj.b.x, obj.b.y]); } else if (obj._class === T.ARC) { a.set(obj.a.x - obj.c.x, obj.a.y - obj.c.y, 0); b.set(obj.b.x - obj.c.x, obj.b.y - obj.c.y, 0); var dir = a.cross(b).z > 0 ? 0 : 1; var r = obj.r.get(); - append('', [obj.a.x, obj.a.y, r, r, dir, 1, obj.b.x, obj.b.y]); + out.line('', [obj.a.x, obj.a.y, r, r, dir, 1, obj.b.x, obj.b.y]); } else if (obj._class === T.CIRCLE) { - append('', [obj.c.x, obj.c.y, obj.r.get()]); + out.line('', [obj.c.x, obj.c.y, obj.r.get()]); } else if (obj._class === T.DIM || obj._class === T.HDIM || obj._class === T.VDIM) { } } - append(''); + out.line(''); } } bbox.inc(20) - return TCAD.io._format("\n", bbox.bbox) + svg + "" + return TCAD.io._format("\n", bbox.bbox) + out.data + "" }; TCAD.IO.prototype.dxfExport = function () {