attach a dimension right on a segment

This commit is contained in:
Val Erastov (xibyte) 2020-03-26 23:45:27 -07:00
parent 7605a61709
commit 1c4796d249
2 changed files with 17 additions and 1 deletions

View file

@ -3,6 +3,8 @@ import Vector from 'math/vector';
import {EndPoint} from '../shapes/point'
import {Tool} from './tool'
import {DragTool} from "./drag";
import {isInstanceOf} from "../actions/matchUtils";
import {Segment} from "../shapes/segment";
export class AddDimTool extends Tool {
@ -27,6 +29,20 @@ export class AddDimTool extends Tool {
mouseup(e) {
if (this.viewer.snapped == null) {
if (this.dim === null) {
const result = this.viewer.pick(e);
if (result.length >= 0) {
const segment = result.find(e => isInstanceOf(e, Segment));
if (segment) {
this.dim = this.dimCreation(segment.a, segment.b);
this.dim.offset = 0;
this.layer.add(this.dim);
this.viewer.toolManager.switchTool(new DragTool(this.dim, this.viewer));
this.viewer.toolManager.tool.mousedown(e);
this.viewer.refresh();
}
}
}
return;
}

View file

@ -467,7 +467,7 @@ class Viewer {
}
pick(e) {
var m = this.screenToModel(e);
const m = this.screenToModel(e);
return this.search(m.x, m.y, 20 / this.scale, true, false, []);
};