mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 17:04:58 +01:00
fit sketch to screen action
This commit is contained in:
parent
f0e0bbf3e5
commit
66d26e49db
3 changed files with 44 additions and 6 deletions
|
|
@ -258,14 +258,16 @@ TCAD.TWO.Viewer.prototype.cleanSnap = function() {
|
|||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.showBounds = function(x1, y1, x2, y2) {
|
||||
this.translate.x = -x1;
|
||||
this.translate.y = -y1;
|
||||
TCAD.TWO.Viewer.prototype.showBounds = function(x1, y1, x2, y2, offset) {
|
||||
var dx = x2 - x1;
|
||||
var dy = y2 - y1;
|
||||
console.log(this.scale);
|
||||
this.scale = this.canvas.width / dx;
|
||||
this.scale *= 0.7;
|
||||
if (this.canvas.width > this.canvas.height) {
|
||||
this.scale = this.canvas.height / dy;
|
||||
} else {
|
||||
this.scale = this.canvas.width / dx;
|
||||
}
|
||||
this.translate.x = -x1 * this.scale;
|
||||
this.translate.y = -y1 * this.scale;
|
||||
};
|
||||
|
||||
TCAD.TWO.Viewer.prototype.screenToModel2 = function(x, y, out) {
|
||||
|
|
|
|||
|
|
@ -372,6 +372,15 @@ TCAD.io.BBox = function() {
|
|||
bbox[2] += by;
|
||||
bbox[3] += by;
|
||||
};
|
||||
|
||||
this.width = function() {
|
||||
return bbox[2] - bbox[0];
|
||||
};
|
||||
|
||||
this.height = function() {
|
||||
return bbox[3] - bbox[1];
|
||||
};
|
||||
|
||||
this.bbox = bbox;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -166,6 +166,33 @@ TCAD.App2D = function() {
|
|||
app.cleanUpData();
|
||||
app.viewer.refresh();
|
||||
});
|
||||
|
||||
this.registerAction('fit', "Fit Sketch On Screen", function () {
|
||||
app.fit();
|
||||
app.viewer.refresh();
|
||||
});
|
||||
};
|
||||
|
||||
TCAD.App2D.prototype.fit = function() {
|
||||
|
||||
var bbox = new TCAD.io.BBox();
|
||||
|
||||
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];
|
||||
obj.accept(function(obj) {
|
||||
if (obj._class === 'TCAD.TWO.EndPoint') {
|
||||
bbox.checkBounds(obj.x, obj.y);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
var bounds = bbox.bbox;
|
||||
this.viewer.showBounds(bounds[0], bounds[1], bounds[2], bounds[3]);
|
||||
bbox.inc(20 / this.viewer.scale);
|
||||
this.viewer.showBounds(bounds[0], bounds[1], bounds[2], bounds[3]);
|
||||
};
|
||||
|
||||
TCAD.App2D.prototype.cloneSketch = function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue