dimensions scale

This commit is contained in:
Val Erastov 2016-02-19 16:16:52 -08:00
parent 0b2fafe28f
commit bf8a9bc806
5 changed files with 47 additions and 13 deletions

View file

@ -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);

View file

@ -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( " *****************<br><br><br><br>");

View file

@ -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);

View file

@ -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;

View file

@ -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 = $('<div/>', {class: 'tc-row tc-ctrl tc-ctrl-number'});
this.input = $("<input type='text' value='"+initValue+"' />");
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);
}
});
};