mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-22 16:33:38 +01:00
improve interactive input parameters for datum
This commit is contained in:
parent
14cdeb9356
commit
19c6551bbd
6 changed files with 52 additions and 12 deletions
|
|
@ -5,6 +5,7 @@ import DatumObject3D from '../datumObject';
|
|||
import * as SceneGraph from 'scene/sceneGraph';
|
||||
import CSys from '../../../../math/csys';
|
||||
import {MDatum} from '../../../model/mdatum';
|
||||
import {roundInteractiveInput} from '../../wizard/roundUtils';
|
||||
|
||||
function updateCSys(csys, params, findFace) {
|
||||
csys.move(0, 0, 0);
|
||||
|
|
@ -37,17 +38,20 @@ function previewer(ctx, initialParams, updateParams) {
|
|||
datum3D.onMove = (begin, end, delta) => {
|
||||
updateParams(params => {
|
||||
|
||||
params.x = end.x;
|
||||
params.y = end.y;
|
||||
params.z = end.z;
|
||||
let x = end.x;
|
||||
let y = end.y;
|
||||
let z = end.z;
|
||||
if (params.face) {
|
||||
let face = ctx.services.cadRegistry.findFace(params.face);
|
||||
if (face) {
|
||||
params.x -= face.csys.origin.x;
|
||||
params.y -= face.csys.origin.y;
|
||||
params.z -= face.csys.origin.z;
|
||||
x -= face.csys.origin.x;
|
||||
y -= face.csys.origin.y;
|
||||
z -= face.csys.origin.z;
|
||||
}
|
||||
}
|
||||
params.x = roundInteractiveInput(x);
|
||||
params.y = roundInteractiveInput(y);
|
||||
params.z = roundInteractiveInput(z);
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -113,6 +113,11 @@ export default class DatumObject3D extends Object3D {
|
|||
|
||||
let delta = dir.multiply(u);
|
||||
this.csys.origin._plus(delta);
|
||||
|
||||
if (e.shiftKey) {
|
||||
roundVector(this.csys.origin);
|
||||
}
|
||||
|
||||
this.viewer.requestRender();
|
||||
|
||||
this.onMove(this.dragInfo.csysOrigin, this.csys.origin, delta);
|
||||
|
|
@ -136,7 +141,7 @@ export default class DatumObject3D extends Object3D {
|
|||
function addOnHoverBehaviour(handle, viewer) {
|
||||
handle.onMouseDown = function(e, hits, startDrag) {
|
||||
let datum = this.parent.parent.parent;
|
||||
if (datum.freezeDraggin) {
|
||||
if (datum.freezeDragging) {
|
||||
return;
|
||||
}
|
||||
startDrag(datum);
|
||||
|
|
@ -148,4 +153,10 @@ function addOnHoverBehaviour(handle, viewer) {
|
|||
handle.onMouseLeave = function() {
|
||||
viewer.setVisualProp(handle.material, 'visible', false);
|
||||
};
|
||||
}
|
||||
|
||||
function roundVector(v) {
|
||||
v.x = Math.round(v.x);
|
||||
v.y = Math.round(v.y);
|
||||
v.z = Math.round(v.z);
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ import schema from './moveDatumOpSchema';
|
|||
import {renderPoint} from 'renders';
|
||||
import {MDatum} from '../../../model/mdatum';
|
||||
import MoveDatumWizard from './MoveDatumWizard';
|
||||
import {NOOP} from 'gems/func';
|
||||
import {roundInteractiveInput} from '../../wizard/roundUtils';
|
||||
|
||||
|
||||
function move(params, {cadRegistry}) {
|
||||
|
|
@ -35,9 +35,9 @@ function previewer(ctx, initialParams, updateParams) {
|
|||
datum3D.beginOperation();
|
||||
datum3D.onMove = (begin, end, delta) => {
|
||||
updateParams(params => {
|
||||
params.x = end.x - mDatum.csys.origin.x;
|
||||
params.y = end.y - mDatum.csys.origin.y;
|
||||
params.z = end.z - mDatum.csys.origin.z;
|
||||
params.x = roundInteractiveInput(end.x - mDatum.csys.origin.x);
|
||||
params.y = roundInteractiveInput(end.y - mDatum.csys.origin.y);
|
||||
params.z = roundInteractiveInput(end.z - mDatum.csys.origin.z);
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
|||
4
web/app/cad/craft/wizard/roundUtils.js
Normal file
4
web/app/cad/craft/wizard/roundUtils.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
export function roundInteractiveInput(num) {
|
||||
return num.toFixed(3)
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import {stream, state} from 'lstream';
|
||||
import initializeBySchema from '../intializeBySchema';
|
||||
import {clone, EMPTY_OBJECT} from 'gems/objects';
|
||||
import materializeParams from '../materializeParams';
|
||||
|
||||
export function activate(ctx) {
|
||||
|
||||
|
|
@ -70,6 +71,24 @@ export function activate(ctx) {
|
|||
return request
|
||||
}).remember(EMPTY_OBJECT);
|
||||
|
||||
streams.wizard.materializedWorkingRequest = streams.wizard.workingRequest.map(req => {
|
||||
if (req.type) {
|
||||
let operation = ctx.services.operation.get(req.type);
|
||||
let params = {};
|
||||
let errors = [];
|
||||
materializeParams(ctx.services, req.params, operation.schema, params, errors, []);
|
||||
if (errors.length !== 0) {
|
||||
console.log(errors);
|
||||
return INVALID_REQUEST;
|
||||
}
|
||||
return {
|
||||
type: req.type,
|
||||
params
|
||||
};
|
||||
}
|
||||
return EMPTY_OBJECT;
|
||||
}).filter(r => r !== INVALID_REQUEST).remember();
|
||||
|
||||
services.wizard = {
|
||||
|
||||
open: (type, initialOverrides) => {
|
||||
|
|
@ -99,3 +118,5 @@ export function activate(ctx) {
|
|||
function applyOverrides(params, initialOverrides) {
|
||||
Object.assign(params, initialOverrides);
|
||||
}
|
||||
|
||||
const INVALID_REQUEST = {};
|
||||
|
|
@ -10,7 +10,7 @@ export function activate(ctx) {
|
|||
previewer: null
|
||||
};
|
||||
|
||||
streams.wizard.workingRequest.attach(({type, params}) => {
|
||||
streams.wizard.materializedWorkingRequest.attach(({type, params}) => {
|
||||
if (!type) {
|
||||
if (previewContext.previewer) {
|
||||
previewContext.previewer.dispose();
|
||||
|
|
|
|||
Loading…
Reference in a new issue