UI / selectionPlugin

This commit is contained in:
Val Erastov 2018-01-05 02:27:56 -08:00
parent 046a10fe16
commit dce2918530
8 changed files with 21 additions and 22 deletions

View file

@ -3,7 +3,7 @@ export default class Bus {
constructor() {
this.listeners = {};
this.state = {};
this.recordFor = new Set();
this.keepStateFor = new Set();
this.lock = new Set();
}
@ -15,7 +15,7 @@ export default class Bus {
}
listenerList.push(callback);
if (this.recordFor.has(key)) {
if (this.keepStateFor.has(key)) {
callback(this.state[key]);
}
return callback;
@ -36,6 +36,9 @@ export default class Bus {
console.warn('recursive dispatch');
return
}
if (this.keepStateFor.has(key)) {
this.state[key] = data;
}
this.lock.add(key);
try {
let listenerList = this.listeners[key];
@ -51,19 +54,16 @@ export default class Bus {
}
} finally {
this.lock.delete(key);
if (this.recordFor.has(key)) {
this.state[key] = data;
}
}
};
enableState(forEvent, initValue) {
this.recordFor.add(forEvent);
this.keepStateFor.add(forEvent);
this.state[forEvent] = initValue;
}
disableState(forEvent) {
this.recordFor.delete(forEvent);
this.keepStateFor.delete(forEvent);
}
}

View file

@ -5,7 +5,7 @@ export const EditFace = {
label: 'sketch',
icon96: 'img/3d/face-edit96.png',
info: 'open sketcher for a face/plane',
listens: ['selection'],
listens: ['selection:face'],
update: ActionHelpers.checkForSelectedFaces(1),
invoke: (app) => app.editFace()
};

View file

@ -63,11 +63,11 @@ requiresSolidSelection(DIFFERENCE, 2);
requiresSolidSelection(UNION, 2);
function requiresFaceSelection(action, amount) {
action.listens = ['selection'];
action.listens = ['selection:face'];
action.update = ActionHelpers.checkForSelectedFaces(amount)
}
function requiresSolidSelection(action, amount) {
action.listens = ['selection'];
action.listens = ['selection:face'];
action.update = ActionHelpers.checkForSelectedSolids(amount)
}

View file

@ -16,7 +16,7 @@ export function RevolveWizard(app, face, initParams) {
this.synch();
this.autoResoltion = true;
this.selectionListener = () => {
const object = this.app.viewer.sketchSelectionMgr.selection[0];
const object = this.app.getFirstSelectedFace();
if (canBePivot(object, this.face)) {
this.ui.pivotSketchObjectId.input.val(object.__TCAD_SketchObject.id);
this.synch();
@ -31,7 +31,7 @@ function canBePivot(sketchObject, face) {
function findDefaultAxis(app, face) {
let line;
const preSelected = app.viewer.sketchSelectionMgr.selection[0];
const preSelected = app.getFirstSelectedFace();
if (canBePivot(preSelected, face)) {
line = preSelected;
} else {

View file

@ -239,7 +239,7 @@ const DebugActions = {
cssIcons: ['cutlery'],
label: 'print face',
info: 'print a face out as JSON',
listens: ['selection'],
listens: ['selection:face'],
update: checkForSelectedFaces(1),
invoke: (app) => {
var s = app.getFirstSelectedFace();
@ -254,7 +254,7 @@ const DebugActions = {
cssIcons: ['cutlery'],
label: 'print face id',
info: 'print a face id',
listens: ['selection'],
listens: ['selection:face'],
update: checkForSelectedFaces(1),
invoke: (app) => {
console.log(app.getFirstSelectedFace().id);
@ -265,7 +265,7 @@ const DebugActions = {
cssIcons: ['cutlery'],
label: 'print face sketch',
info: 'print face sketch stripping constraints and boundary',
listens: ['selection'],
listens: ['selection:face'],
update: checkForSelectedFaces(1),
invoke: (app) => {
const faceId = app.getFirstSelectedFace().id;

View file

@ -81,7 +81,7 @@ function App() {
this.bus.subscribe("craft", function() {
var historyEditMode = app.craft.historyPointer != app.craft.history.length;
if (!historyEditMode) {
app.viewer.selectionMgr.clear();
//app.viewer.selectionMgr.clear();
}
app._refreshSketches();
});
@ -423,11 +423,10 @@ App.prototype.projectStorageKey = function(polyFaceId) {
App.prototype.editFace = function() {
if (this.viewer.selectionMgr.selection.length == 0) {
return;
const polyFace = this.getFirstSelectedFace();
if (polyFace) {
this.sketchFace(polyFace);
}
const polyFace = this.viewer.selectionMgr.selection[0];
this.sketchFace(polyFace);
};
App.prototype.sketchFace = function(sceneFace) {

View file

@ -161,7 +161,7 @@ UI.prototype.createWizardForOperation = function(op) {
var initParams = op.params;
var face = op.face !== undefined ? this.app.findFace(op.face) : null;
if (face != null) {
this.app.context.bus.dispatch('selection:face', face);
this.app.context.bus.dispatch('selection:face', [face]);
}
return this.createWizard(op.type, true, initParams, face);
};

View file

@ -154,7 +154,7 @@ function setSketch(win, app, faceId, data) {
}
function selectFace(app, faceId) {
app.viewer.selectionMgr.select(app.findFace(faceId));
app.bus.dispatch('selection:face', [app.findFace(faceId)]);
}
function assertScene(app, env, expected) {