This commit is contained in:
Val Erastov 2016-11-11 19:52:06 -08:00
parent 3693c1d7f3
commit c97ed81575
4 changed files with 86 additions and 9 deletions

View file

@ -0,0 +1,2 @@

View file

@ -31,3 +31,42 @@ ReferencePointTool.prototype.mousedown = function(e) {
ReferencePointTool.prototype.mousewheel = function(e) {
};
ReferencePointTool.prototype.hint = function(e) {
return "specify point"
};
ReferencePointTool.prototype.processCommand = function(command) {
var referencePoint = this.viewer.referencePoint;
let point = ParseVector(referencePoint, command);
referencePoint.x += point.x;
referencePoint.y += point.y;
this.viewer.refresh();
};
const VECTOR_PATTERNS = /^(@)?(.+)(,|<)(.+)$/;
function ParseVector(referencePoint, command) {
command = str.replace(/\s+/g, '');
const match = command.match(VECTOR_PATTERNS);
if (match) {
const ref = !match[1];
let x = parseFloat(match[2]);
if (isNaN(x)) return "wrong input for number: " + match[2];
const polar = match[3] == '<';
let y = parseFloat(match[4]);
if (isNaN(y)) return "wrong input for number: " + match[4];
if (polar) {
y = y * Math.sin(x);
x = x * Math.cos(x);
}
if (ref) {
x += referencePoint.x;
y += referencePoint.y;
}
return {x, y};
}
return "wrong input, point is expected: x,y | @x,y | r<polar ";
}

View file

@ -23,6 +23,7 @@ function App2D() {
this.constraintFilter = {};
this.actions = {};
this.commands = {};
//For debug view
this._actionsOrder = [];
@ -43,15 +44,17 @@ function App2D() {
let coord = this.viewer.screenToModel(e);
$('.coordinates-info').text(coord.x.toFixed(3) + " : " + coord.y.toFixed(3));
});
new ui.Terminal(commandsWin, function(command) {
return "Command " + command + " executed";
});
this.terminalHandeler = null;
this.terminal = new ui.Terminal(commandsWin, (command) => this.handleTerminalInput(command));
this.bindToolsToTerminal();
this.winManager.registerResize(dockEl, ui.DIRECTIONS.EAST, function() {$('body').trigger('layout'); });
$('body').on('layout', this.viewer.onWindowResize);
this.registerAction = function(id, desc, action) {
app.actions[id] = {id: id, desc: desc, action: action};
this.registerAction = function(id, desc, action, command) {
app.actions[id] = {id, desc, action};
app.commands[command] = id;
app._actionsOrder.push(id);
};
@ -94,7 +97,7 @@ function App2D() {
this.registerAction('referencePoint', "Set Reference Point", function () {
app.viewer.toolManager.takeControl(new ReferencePointTool(app.viewer));
});
}, "origin");
this.registerAction('addPoint', "Add Point", function () {
app.viewer.toolManager.takeControl(new AddPointTool(app.viewer));
@ -367,6 +370,37 @@ App2D.prototype.getSketchId = function() {
return App2D.STORAGE_PREFIX + id;
};
App2D.prototype.bindToolsToTerminal = function() {
};
App2D.STATIC_COMMANDS = {
"time" : () => new Date(),
"help" : (app) => app.getAllCommandList().join(", ")
};
App2D.prototype.getAllCommandList = function() {
const commands = this.commands.slice();
commands.push.apply(commands, App2D.STATIC_COMMANDS);
return commands;
};
App2D.prototype.handleTerminalInput = function(commandStr) {
commandStr = commandStr.trim();
if (this.terminalHandeler != null) {
this.terminalHandeler(commandStr);
} else {
let cmd = App2D.STATIC_COMMANDS[commandStr];
if (cmd) {
cmd(this);
}
let actionDef = this.commands[cmd];
if (actionDef) {
actionDef();
}
}
};
App2D.STORAGE_PREFIX = "TCAD.projects.";
export default App2D;
export default App2D;-

View file

@ -813,6 +813,7 @@ ReferencePoint.prototype.draw = function(ctx, scale) {
function ToolManager(viewer, defaultTool) {
this.defaultTool = defaultTool;
this.tool = defaultTool;
this.viewer = viewer;
var canvas = viewer.canvas;
var tm = this;
canvas.addEventListener('mousemove', function (e) {
@ -866,6 +867,7 @@ function ToolManager(viewer, defaultTool) {
ToolManager.prototype.takeControl = function(tool) {
this.tool = tool;
this.viewer.bus.notify("tool-state");
};
ToolManager.prototype.releaseControl = function() {