mirror of
https://github.com/xibyte/jsketcher
synced 2026-02-28 02:03:11 +01:00
working on the test infrastructure
This commit is contained in:
parent
0c586935c7
commit
5a42a77e2f
7 changed files with 134 additions and 35 deletions
|
|
@ -16,6 +16,7 @@ export default function Menu({children, x, y, orientationUp, centered, menuId, .
|
|||
top={orientationUp ? undefined : y}
|
||||
bottom={orientationUp ? y : undefined}
|
||||
centered={centered}
|
||||
data-menu-id={menuId}
|
||||
{...props}>
|
||||
{children}
|
||||
</AuxWidget>;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import {
|
|||
PICK_KIND,
|
||||
traversePickResults
|
||||
} from '../../../web/app/cad/scene/controls/pickControlPlugin';
|
||||
import {Vector3} from "three";
|
||||
|
||||
export default ctx => {
|
||||
|
||||
|
|
@ -59,11 +60,22 @@ export default ctx => {
|
|||
function selectFirst(type) {
|
||||
ctx.services.pickControl.pick(ctx.services.cadRegistry.models.find(m => m.TYPE === type));
|
||||
}
|
||||
|
||||
|
||||
function simulateClickByRayCast(from, to) {
|
||||
ctx.services.pickControl.simulatePickFromRay(from, to);
|
||||
|
||||
const {x, y} = ctx.services.viewer.sceneSetup.modelToScreen( new Vector3().fromArray(from) );
|
||||
|
||||
const hits = ctx.services.viewer.customRaycast(from, to, ctx.services.cadScene.workGroup.children);
|
||||
ctx.services.modelMouseEventSystem.dispatchMousemove(mouseEvent('mousemove', x, y), hits);
|
||||
ctx.services.modelMouseEventSystem.dispatchMousedown(mouseEvent('mousedown', x, y), hits);
|
||||
ctx.services.modelMouseEventSystem.dispatchMouseup(mouseEvent('mouseup', x, y), hits);
|
||||
}
|
||||
|
||||
function getWizardContext() {
|
||||
return ctx.streams.wizard.wizardContext.value
|
||||
}
|
||||
|
||||
|
||||
function openSketcher() {
|
||||
ctx.services.action.run('EditFace');
|
||||
return createSubjectFromInPlaceSketcher(ctx);
|
||||
|
|
@ -75,7 +87,7 @@ export default ctx => {
|
|||
|
||||
return {
|
||||
context: ctx,
|
||||
openWizard, wizardOK, sceneMouseEvent, clickOnScene,
|
||||
openWizard, wizardOK, sceneMouseEvent, clickOnScene, simulateClickByRayCast,
|
||||
rayCast, rayCastFaces, select, selectFaces, selectFirst, openSketcher, commitSketch,
|
||||
get wizardContext() { return getWizardContext()},
|
||||
__DEBUG__: ctx.services.debug.utils
|
||||
|
|
|
|||
|
|
@ -50,15 +50,20 @@ describe("Wizrds", () => {
|
|||
|
||||
});
|
||||
|
||||
it("move datum", () => {
|
||||
it.only("move datum", () => {
|
||||
createDatum();
|
||||
cy.simulateClickByRayCast([10, 15, 76], [154, -25, -56]);
|
||||
cy.getMenu('datum').within(() => {
|
||||
cy.getActionButton('DATUM_ROTATE').click()
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function createDatum() {
|
||||
cy.visit("http://localhost:3000");
|
||||
|
||||
cy.get('[info="originates a new datum from origin or off of a selected face"]').click();
|
||||
cy.get('.x-Field-active > .number > input').type("100");
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import modellerUISubject from "../../coreTests/subjects/modellerTPI";
|
|||
|
||||
|
||||
Cypress.Commands.add("openModeller", () => {
|
||||
return cy.visit("http://localhost:3000?test&LOG.PICK=true");;
|
||||
return cy.visit("http://localhost:3000?test&LOG.PICK=true");
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -10,6 +10,9 @@ Cypress.Commands.add("getActionButton", (actionId) => {
|
|||
return cy.get(`[data-action-id='${actionId}']`);
|
||||
});
|
||||
|
||||
Cypress.Commands.add("getMenu", (menuId) => {
|
||||
return cy.get(`[data-menu-id='${menuId}']`);
|
||||
});
|
||||
|
||||
Cypress.Commands.add("getActiveWizardField", (fieldName) => {
|
||||
|
||||
|
|
@ -24,6 +27,14 @@ Cypress.Commands.add("selectRaycasting", (from, to) => {
|
|||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add("simulateClickByRayCast", (from, to) => {
|
||||
cy.getModellerTPI().then(tpi => {
|
||||
tpi.simulateClickByRayCast(from, to);
|
||||
tpi.__DEBUG__.AddSegment3(from, to);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Cypress.Commands.add("openSketcher", () => {
|
||||
return cy.getModellerTPI().then(tpi => tpi.openSketcher());
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import {printRaycastDebugInfo, RayCastDebugInfo} from "./rayCastDebug";
|
||||
import {LOG_FLAGS} from "../../logFlags";
|
||||
|
||||
export function activate(context) {
|
||||
const {services, streams} = context;
|
||||
|
|
@ -10,7 +12,7 @@ export function activate(context) {
|
|||
domElement.addEventListener('mouseup', mouseup, false);
|
||||
domElement.addEventListener('mousemove', mousemove, false);
|
||||
|
||||
let performRaycast = e => services.viewer.raycast(e, services.cadScene.workGroup.children);
|
||||
let performRaycast = e => services.viewer.raycast(e, services.cadScene.workGroup.children, RayCastDebugInfo);
|
||||
|
||||
let toDrag = null;
|
||||
let pressed = new Set();
|
||||
|
|
@ -30,12 +32,20 @@ export function activate(context) {
|
|||
}
|
||||
|
||||
function mousedown(e) {
|
||||
event.mouseEvent = e;
|
||||
pressed.clear();
|
||||
let hits = performRaycast(e);
|
||||
dispatchMousedown(e, hits);
|
||||
}
|
||||
|
||||
function dispatchMousedown(e, hits) {
|
||||
event.mouseEvent = e;
|
||||
event.hits = hits;
|
||||
|
||||
pressed.clear();
|
||||
|
||||
for (let hit of hits) {
|
||||
if (LOG_FLAGS.PICK) {
|
||||
printRaycastDebugInfo('mouseDown', hit);
|
||||
}
|
||||
|
||||
let obj = hit.object;
|
||||
if (obj && obj.onMouseDown) {
|
||||
obj.onMouseDown(event);
|
||||
|
|
@ -54,24 +64,33 @@ export function activate(context) {
|
|||
mousemove(e);
|
||||
} else {
|
||||
let hits = performRaycast(e);
|
||||
event.hits = hits;
|
||||
|
||||
for (let hit of hits) {
|
||||
let obj = hit.object;
|
||||
if (obj && obj.onMouseUp) {
|
||||
obj.onMouseUp(event);
|
||||
}
|
||||
if (pressed.has(obj) && obj.onMouseClick) {
|
||||
obj.onMouseClick(event);
|
||||
}
|
||||
if (!hit.object.passMouseEvent || !hit.object.passMouseEvent(event)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
pressed.clear();
|
||||
dispatchMouseup(e, hits);
|
||||
}
|
||||
}
|
||||
|
||||
function dispatchMouseup(e, hits) {
|
||||
|
||||
event.mouseEvent = e;
|
||||
event.hits = hits;
|
||||
|
||||
for (let hit of hits) {
|
||||
if (LOG_FLAGS.PICK) {
|
||||
printRaycastDebugInfo('mouseUp', hit);
|
||||
}
|
||||
let obj = hit.object;
|
||||
if (obj && obj.onMouseUp) {
|
||||
obj.onMouseUp(event);
|
||||
}
|
||||
if (pressed.has(obj) && obj.onMouseClick) {
|
||||
obj.onMouseClick(event);
|
||||
}
|
||||
if (!hit.object.passMouseEvent || !hit.object.passMouseEvent(event)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
pressed.clear();
|
||||
}
|
||||
|
||||
let entered = new Set();
|
||||
let valid = new Set();
|
||||
|
||||
|
|
@ -82,6 +101,7 @@ export function activate(context) {
|
|||
toDrag.dragMove(event);
|
||||
} else {
|
||||
let hits = performRaycast(e);
|
||||
dispatchMousemove(e, hits)
|
||||
event.hits = hits;
|
||||
|
||||
valid.clear();
|
||||
|
|
@ -113,6 +133,43 @@ export function activate(context) {
|
|||
valid.clear();
|
||||
}
|
||||
}
|
||||
|
||||
function dispatchMousemove(e, hits) {
|
||||
event.mouseEvent = e;
|
||||
event.hits = hits;
|
||||
|
||||
valid.clear();
|
||||
for (let hit of hits) {
|
||||
valid.add(hit.object);
|
||||
if (!hit.object.passMouseEvent || !hit.object.passMouseEvent(event)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
entered.forEach(el => {
|
||||
if (!valid.has(el) && el.onMouseLeave) {
|
||||
el.onMouseLeave(event);
|
||||
}
|
||||
});
|
||||
|
||||
valid.forEach(el => {
|
||||
if (!entered.has(el) && el.onMouseEnter) {
|
||||
el.onMouseEnter(event);
|
||||
}
|
||||
if (el.onMouseMove) {
|
||||
el.onMouseMove(event);
|
||||
}
|
||||
});
|
||||
|
||||
let t = valid;
|
||||
valid = entered;
|
||||
entered = t;
|
||||
valid.clear();
|
||||
}
|
||||
|
||||
context.services.modelMouseEventSystem = {
|
||||
dispatchMousedown, dispatchMouseup, dispatchMousemove
|
||||
}
|
||||
}
|
||||
|
||||
export function hasObject(hits, object) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {getAttribute, setAttribute} from 'scene/objectData';
|
|||
import {FACE, EDGE, SKETCH_OBJECT, DATUM, SHELL, DATUM_AXIS, LOOP} from '../entites';
|
||||
import {LOG_FLAGS} from '../../logFlags';
|
||||
import * as vec from 'math/vec';
|
||||
import {initRayCastDebug, printRaycastDebugInfo, RayCastDebugInfo} from "./rayCastDebug";
|
||||
|
||||
export const PICK_KIND = {
|
||||
FACE: mask.type(1),
|
||||
|
|
@ -22,7 +23,6 @@ const DEFAULT_SELECTION_MODE = Object.freeze({
|
|||
datum: true
|
||||
});
|
||||
|
||||
let RayCastDebugInfo;
|
||||
|
||||
export const ALL_EXCLUDING_SOLID_KINDS = PICK_KIND.FACE | PICK_KIND.SKETCH | PICK_KIND.EDGE | PICK_KIND.DATUM_AXIS | PICK_KIND.LOOP;
|
||||
|
||||
|
|
@ -147,7 +147,7 @@ export function activate(context) {
|
|||
};
|
||||
|
||||
if (LOG_FLAGS.PICK) {
|
||||
RayCastDebugInfo = {};
|
||||
initRayCastDebug();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +212,6 @@ export function traversePickResults(event, pickResults, kind, visitor) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function printPickInfo(model, rayCastData) {
|
||||
console.log("PICKED MODEL:");
|
||||
console.dir(model);
|
||||
|
|
@ -221,12 +220,6 @@ function printPickInfo(model, rayCastData) {
|
|||
console.dir(rayCastData);
|
||||
let pt = rayCastData.point;
|
||||
console.log('POINT: ' + pt.x + ', ' + pt.y + ',' + pt.z);
|
||||
if (RayCastDebugInfo && RayCastDebugInfo.ray) {
|
||||
//generating test data
|
||||
const BUFFER = 100;
|
||||
const r = vec.fromXYZ(pt).map(Math.round);
|
||||
const dir = vec._mul(vec.fromXYZ(RayCastDebugInfo.ray.direction), BUFFER);
|
||||
console.log('cy.selectRaycasting(['+ vec.sub(r, dir).map(Math.round).join(', ') + '], [' + vec.add(r, dir).map(Math.round).join(', ') + '])');
|
||||
}
|
||||
printRaycastDebugInfo('selection', rayCastData);
|
||||
}
|
||||
}
|
||||
20
web/app/cad/scene/controls/rayCastDebug.js
Normal file
20
web/app/cad/scene/controls/rayCastDebug.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import * as vec from "math/vec";
|
||||
|
||||
export let RayCastDebugInfo;
|
||||
|
||||
export function initRayCastDebug() {
|
||||
RayCastDebugInfo = {};
|
||||
}
|
||||
|
||||
export function printRaycastDebugInfo(tag , hit) {
|
||||
if (RayCastDebugInfo && RayCastDebugInfo.ray) {
|
||||
const pt = hit.point;
|
||||
//generating test data
|
||||
const BUFFER = 100;
|
||||
const r = vec.fromXYZ(pt).map(Math.round);
|
||||
const dir = vec._mul(vec.fromXYZ(RayCastDebugInfo.ray.direction), BUFFER);
|
||||
console.log(tag);
|
||||
console.log('cy.simulateClickByRayCast(['+ vec.sub(r, dir).map(Math.round).join(', ') + '], [' + vec.add(r, dir).map(Math.round).join(', ') + '])');
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue