diff --git a/web/app/3d/ctrl.js b/web/app/3d/ctrl.js index 793c8333..bc6c3e16 100644 --- a/web/app/3d/ctrl.js +++ b/web/app/3d/ctrl.js @@ -181,7 +181,7 @@ TCAD.UI.createCutExtrudeWizard = function (isCut, app, face, alignComponent, ini var folder = new tk.Folder(isCut ? "Cut Options" : "Extrude Options"); tk.add(box, folder); var theValue = new tk.Number(isCut ? "Depth" : "Height", def(0, 50)); - var scale = new tk.Number("Expansion", def(1, 1), 0.1); + var scale = new tk.Number("Expansion", def(1, 1), 0.1, 1); var deflection = new tk.Number("Deflection", def(2, 0), 1); var angle = new tk.Number("Angle", def(3, 0), 5); var wizard = new TCAD.wizards.ExtrudeWizard(app.viewer, polygons); diff --git a/web/app/app-init.js b/web/app/app-init.js index 67edabb5..bc3fef3d 100644 --- a/web/app/app-init.js +++ b/web/app/app-init.js @@ -104,9 +104,12 @@ function start() { } }); - var dimScale = new TCAD.toolkit.Number("Dim Scale", 1); + var dimScale = new TCAD.toolkit.Number("Dim Scale", 1, 0.1, 1); + dimScale.min = 0.1; app.dock.views['Properties'].node.append(dimScale.root); - + dimScale.input.on('t-change', function() { + app.viewer.dimScale = $(this).val(); + }); } window.___log = function(log) { $('#log').append( " *****************



"); diff --git a/web/app/sketcher/canvas.js b/web/app/sketcher/canvas.js index 7211d7b3..272a43e8 100644 --- a/web/app/sketcher/canvas.js +++ b/web/app/sketcher/canvas.js @@ -106,6 +106,9 @@ TCAD.TWO.Viewer = function(canvas) { this._serviceLayers = []; this.dimLayer = new TCAD.TWO.Layer("_dim", TCAD.TWO.Styles.DIM); this.dimLayers = [this.dimLayer]; + this.bus.defineObservable(this, 'dimScale', 'dimScale', 1); + this.bus.subscribe('dimScale', function(){ viewer.refresh(); }); + this._workspace = [this.dimLayers, this.layers, this._serviceLayers]; this.toolManager = new TCAD.TWO.ToolManager(this, new TCAD.TWO.PanTool(this)); this.parametricManager = new TCAD.TWO.ParametricManager(this); diff --git a/web/app/sketcher/shapes/dim.js b/web/app/sketcher/shapes/dim.js index 4b049a3b..c2b53143 100644 --- a/web/app/sketcher/shapes/dim.js +++ b/web/app/sketcher/shapes/dim.js @@ -23,8 +23,8 @@ TCAD.TWO.LinearDimension.prototype.getB = function() { return this.b }; TCAD.TWO.LinearDimension.prototype.drawImpl = function(ctx, scale, viewer) { - var off = 30; - var textOff = 3; + var off = 30 * viewer.dimScale; + var textOff = 3 * viewer.dimScale; var a, b, startA, startB; if (this.flip) { @@ -65,7 +65,7 @@ TCAD.TWO.LinearDimension.prototype.drawImpl = function(ctx, scale, viewer) { function drawRef(start, x, y) { var vec = new TCAD.Vector(x - start.x, y - start.y); vec._normalize(); - vec._multiply(7); + vec._multiply(7 * viewer.dimScale); ctx.moveTo(start.x, start.y ); ctx.lineTo(x, y); @@ -92,7 +92,7 @@ TCAD.TWO.LinearDimension.prototype.drawImpl = function(ctx, scale, viewer) { // drawArrow(_ax, _ay); // drawArrow(_bx, _by); - ctx.font="12px Arial"; + ctx.font= (12 * viewer.dimScale) + "px Arial"; var txt = d.toFixed(2); var h = d / 2 - ctx.measureText(txt).width / 2; diff --git a/web/app/ui/toolkit.js b/web/app/ui/toolkit.js index 81f8a2cf..3303505d 100644 --- a/web/app/ui/toolkit.js +++ b/web/app/ui/toolkit.js @@ -71,11 +71,14 @@ TCAD.toolkit.propLayout = function(root, name, valueEl) { .append(valueEl)); }; -TCAD.toolkit.Number = function(name, initValue, baseStep) { +TCAD.toolkit.Number = function(name, initValue, baseStep, round) { this.root = $('
', {class: 'tc-row tc-ctrl tc-ctrl-number'}); this.input = $(""); this.slide = false; baseStep = baseStep || 1; + round = round || 0; + this.min = null; + this.max = null; var scope = this; var lastValue = null; function trigger() { @@ -84,13 +87,13 @@ TCAD.toolkit.Number = function(name, initValue, baseStep) { lastValue = $(this).val(); } } + this.input.on('input', function(e) { var val = $(this).val(); - try { - parseFloat(val) - } catch (e) { - $(this).val(val.replace(/[^0-9\.]/g, '')); - } + //var floatRegex = /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/; + //if (!floatRegex.test(val)) { + // $(this).val(val.replace(/[^0-9\.-]/g, '')); + //} trigger.call(this); }); this.input.get(0).addEventListener('mousewheel', function (e) { @@ -104,6 +107,15 @@ TCAD.toolkit.Number = function(name, initValue, baseStep) { if (!val) val = 0; var step = baseStep * (e.shiftKey ? 100 : 1); val = parseFloat(val) + (delta < 0 ? -step : step); + if (scope.min != null && val < scope.min) { + val = scope.min; + } + if (scope.max != null && val > scope.min) { + val = scope.max; + } + if (round !== 0) { + val = val.toFixed(round); + } $(this).val(val); e.preventDefault(); e.stopPropagation(); @@ -205,3 +217,19 @@ TCAD.Bus.prototype.notify = function(event, data) { } } }; + +TCAD.Bus.Observable = function(initValue) { + this.value = initValue; +}; + +TCAD.Bus.prototype.defineObservable = function(scope, name, eventName, initValue) { + var observable = new TCAD.Bus.Observable(initValue); + var bus = this; + return Object.defineProperty(scope, name, { + get: function() { return observable.value;}, + set: function(value) { + observable.value = value; + bus.notify(eventName, value); + } + }); +}; \ No newline at end of file