mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 16:33:15 +01:00
terminal
This commit is contained in:
parent
3693c1d7f3
commit
c97ed81575
4 changed files with 86 additions and 9 deletions
2
web/app/sketcher/commands.js
Normal file
2
web/app/sketcher/commands.js
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -31,3 +31,42 @@ ReferencePointTool.prototype.mousedown = function(e) {
|
||||||
|
|
||||||
ReferencePointTool.prototype.mousewheel = 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 ";
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ function App2D() {
|
||||||
|
|
||||||
this.constraintFilter = {};
|
this.constraintFilter = {};
|
||||||
this.actions = {};
|
this.actions = {};
|
||||||
|
this.commands = {};
|
||||||
|
|
||||||
//For debug view
|
//For debug view
|
||||||
this._actionsOrder = [];
|
this._actionsOrder = [];
|
||||||
|
|
@ -43,15 +44,17 @@ function App2D() {
|
||||||
let coord = this.viewer.screenToModel(e);
|
let coord = this.viewer.screenToModel(e);
|
||||||
$('.coordinates-info').text(coord.x.toFixed(3) + " : " + coord.y.toFixed(3));
|
$('.coordinates-info').text(coord.x.toFixed(3) + " : " + coord.y.toFixed(3));
|
||||||
});
|
});
|
||||||
new ui.Terminal(commandsWin, function(command) {
|
this.terminalHandeler = null;
|
||||||
return "Command " + command + " executed";
|
this.terminal = new ui.Terminal(commandsWin, (command) => this.handleTerminalInput(command));
|
||||||
});
|
this.bindToolsToTerminal();
|
||||||
|
|
||||||
|
|
||||||
this.winManager.registerResize(dockEl, ui.DIRECTIONS.EAST, function() {$('body').trigger('layout'); });
|
this.winManager.registerResize(dockEl, ui.DIRECTIONS.EAST, function() {$('body').trigger('layout'); });
|
||||||
$('body').on('layout', this.viewer.onWindowResize);
|
$('body').on('layout', this.viewer.onWindowResize);
|
||||||
|
|
||||||
this.registerAction = function(id, desc, action) {
|
this.registerAction = function(id, desc, action, command) {
|
||||||
app.actions[id] = {id: id, desc: desc, action: action};
|
app.actions[id] = {id, desc, action};
|
||||||
|
app.commands[command] = id;
|
||||||
app._actionsOrder.push(id);
|
app._actionsOrder.push(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -94,7 +97,7 @@ function App2D() {
|
||||||
|
|
||||||
this.registerAction('referencePoint', "Set Reference Point", function () {
|
this.registerAction('referencePoint', "Set Reference Point", function () {
|
||||||
app.viewer.toolManager.takeControl(new ReferencePointTool(app.viewer));
|
app.viewer.toolManager.takeControl(new ReferencePointTool(app.viewer));
|
||||||
});
|
}, "origin");
|
||||||
|
|
||||||
this.registerAction('addPoint', "Add Point", function () {
|
this.registerAction('addPoint', "Add Point", function () {
|
||||||
app.viewer.toolManager.takeControl(new AddPointTool(app.viewer));
|
app.viewer.toolManager.takeControl(new AddPointTool(app.viewer));
|
||||||
|
|
@ -367,6 +370,37 @@ App2D.prototype.getSketchId = function() {
|
||||||
return App2D.STORAGE_PREFIX + id;
|
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.";
|
App2D.STORAGE_PREFIX = "TCAD.projects.";
|
||||||
|
|
||||||
export default App2D;
|
export default App2D;-
|
||||||
|
|
@ -813,6 +813,7 @@ ReferencePoint.prototype.draw = function(ctx, scale) {
|
||||||
function ToolManager(viewer, defaultTool) {
|
function ToolManager(viewer, defaultTool) {
|
||||||
this.defaultTool = defaultTool;
|
this.defaultTool = defaultTool;
|
||||||
this.tool = defaultTool;
|
this.tool = defaultTool;
|
||||||
|
this.viewer = viewer;
|
||||||
var canvas = viewer.canvas;
|
var canvas = viewer.canvas;
|
||||||
var tm = this;
|
var tm = this;
|
||||||
canvas.addEventListener('mousemove', function (e) {
|
canvas.addEventListener('mousemove', function (e) {
|
||||||
|
|
@ -866,6 +867,7 @@ function ToolManager(viewer, defaultTool) {
|
||||||
|
|
||||||
ToolManager.prototype.takeControl = function(tool) {
|
ToolManager.prototype.takeControl = function(tool) {
|
||||||
this.tool = tool;
|
this.tool = tool;
|
||||||
|
this.viewer.bus.notify("tool-state");
|
||||||
};
|
};
|
||||||
|
|
||||||
ToolManager.prototype.releaseControl = function() {
|
ToolManager.prototype.releaseControl = function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue