mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-20 15:32:57 +01:00
fix tests for plane operations
This commit is contained in:
parent
ca590f60ee
commit
8b3f4dcb63
14 changed files with 89 additions and 47 deletions
|
|
@ -1,11 +1,13 @@
|
|||
import {roundValueForPresentation as r} from 'cad/craft/operationHelper';
|
||||
import {MFace} from "cad/model/mface";
|
||||
import {MBrepFace, MFace} from "cad/model/mface";
|
||||
import {ApplicationContext} from "context";
|
||||
import {EntityKind} from "cad/model/entities";
|
||||
import {BooleanDefinition} from "cad/craft/schema/common/BooleanDefinition";
|
||||
import {UnitVector} from "math/vector";
|
||||
import {OperationDescriptor} from "cad/craft/operationPlugin";
|
||||
import {MObject} from "cad/model/mobject";
|
||||
import {Edge} from "brep/topo/edge";
|
||||
import {FaceRef} from "cad/craft/e0/OCCUtils";
|
||||
|
||||
|
||||
interface ExtrudeParams {
|
||||
|
|
@ -30,9 +32,6 @@ export const ExtrudeOperation: OperationDescriptor<ExtrudeParams> = {
|
|||
|
||||
const face = params.face;
|
||||
|
||||
|
||||
let occFaces = [];
|
||||
|
||||
if (params.profiles?.length > 0) {
|
||||
|
||||
params.profiles
|
||||
|
|
@ -42,8 +41,21 @@ export const ExtrudeOperation: OperationDescriptor<ExtrudeParams> = {
|
|||
let extrusionVector = dir._multiply(params.length);
|
||||
|
||||
let sketch = ctx.sketchStorageService.readSketch(face.id);
|
||||
|
||||
let sweepSources: FaceRef[];
|
||||
|
||||
if (!sketch) {
|
||||
occFaces.push(params.face);
|
||||
if (face instanceof MBrepFace) {
|
||||
occ.io.pushModel(face, face.id)
|
||||
const edges = face.edges;
|
||||
edges.forEach(e => occ.io.pushModel(e, e.id));
|
||||
sweepSources = [{
|
||||
face: face.id,
|
||||
edges: edges.map(e => e.id)
|
||||
}];
|
||||
} else {
|
||||
throw "can't extrude an empty surface";
|
||||
}
|
||||
} else {
|
||||
let csys = face.csys;
|
||||
if (params.doubleSided) {
|
||||
|
|
@ -51,13 +63,33 @@ export const ExtrudeOperation: OperationDescriptor<ExtrudeParams> = {
|
|||
csys.origin._minus(extrusionVector);
|
||||
extrusionVector._scale(2);
|
||||
}
|
||||
occFaces = occ.utils.sketchToFaces(sketch, csys);
|
||||
sweepSources = occ.utils.sketchToFaces(sketch, csys)
|
||||
}
|
||||
|
||||
const tools = occFaces.map((faceName, i) => {
|
||||
const tools = sweepSources.map((faceRef, i) => {
|
||||
const faceName = faceRef.face;
|
||||
const shapeName = "Tool/" + i;
|
||||
oci.prism(shapeName, faceName, ...extrusionVector.data());
|
||||
|
||||
// oci.recordHistory({
|
||||
// input: [faceName]
|
||||
// });
|
||||
|
||||
oci.savehistory('history');
|
||||
|
||||
oci.explode(faceName, 'E');
|
||||
oci.explode(shapeName, 'F');
|
||||
|
||||
for (let edge of faceRef.edges) {
|
||||
oci.generated('gen_' + i, 'history', faceName + '_' + i);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 4; ++i) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// occIterateFaces(oc, shape, face => {
|
||||
// let role;
|
||||
// if (face.IsSame(prismAPI.FirstShape())) {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export const LoftOperation: OperationDescriptor<LoftParams> = {
|
|||
|
||||
const wires = params.loops.map((loop, i) => {
|
||||
const shapeName = "loop/" + i;
|
||||
return occ.io.sketchLoader.pushContourAsWire(loop.contour, shapeName, loop.face.csys)
|
||||
return occ.io.sketchLoader.pushContourAsWire(loop.contour, shapeName, loop.face.csys).wire
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export const RevolveOperation: OperationDescriptor<RevolveParams> = {
|
|||
if (!sketch) {
|
||||
occFaces.push(params.face);
|
||||
}else{
|
||||
occFaces = occ.utils.sketchToFaces(sketch, face.csys);
|
||||
occFaces = occ.utils.sketchToFaces(sketch, face.csys).map(ref => ref.face);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ export const SweepOperation: OperationDescriptor<SweepParams> = {
|
|||
const oci = occ.commandInterface;
|
||||
|
||||
const myProfile = params.profile;
|
||||
const profile = occ.io.sketchLoader.pushContourAsWire(myProfile.contour, "sweepFace", myProfile.face.csys);
|
||||
const profile = occ.io.sketchLoader.pushContourAsWire(myProfile.contour, "sweepFace", myProfile.face.csys).wire;
|
||||
|
||||
const myPath = params.sweepPath;
|
||||
const path = occ.io.sketchLoader.pushContourAsWire(myPath.contour, "sweepPath", myPath.face.csys);
|
||||
const path = occ.io.sketchLoader.pushContourAsWire(myPath.contour, "sweepPath", myPath.face.csys).wire;
|
||||
|
||||
|
||||
oci.mksweep(path);
|
||||
|
|
|
|||
|
|
@ -33,16 +33,15 @@ export const smTabOperation: OperationDescriptor<smTabParams> = {
|
|||
let sketch = ctx.sketchStorageService.readSketch(face.id);
|
||||
if (!sketch) throw 'sketch not found for the face ' + face.id;
|
||||
|
||||
const occFaces = occ.utils.sketchToFaces(sketch, face.csys);
|
||||
const occFaces = occ.utils.sketchToFaces(sketch, face.csys).map(ref => ref.face);
|
||||
|
||||
const dir: UnitVector= face.normal();
|
||||
|
||||
let extrusionVector =[];
|
||||
if(params.flipper == true){
|
||||
if (params.flipper == true){
|
||||
extrusionVector = dir.normalize()._multiply(params.thickness).data();
|
||||
}else{
|
||||
} else {
|
||||
extrusionVector = dir.normalize()._multiply(params.thickness).negate().data();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ export function defineCypressTests(groupName, module) {
|
|||
|
||||
test.loadStream(win).attach(ready => {
|
||||
if (ready) {
|
||||
test.func(testEnv, subject).then(() => {
|
||||
onDone();
|
||||
});
|
||||
test.func(testEnv, subject)
|
||||
.then(onDone)
|
||||
.catch(reject);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ export default ctx => {
|
|||
}
|
||||
|
||||
function getWizardContext() {
|
||||
return ctx.streams.wizard.wizardContext.value
|
||||
return ctx.wizardService;
|
||||
}
|
||||
|
||||
function openSketcher() {
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ export async function testExtrudeFromSketch(env, ui) {
|
|||
|
||||
}
|
||||
|
||||
testExtrudeFromSketch.only = true
|
||||
|
||||
export async function testExtrudeArc(env, ui) {
|
||||
let sketcherUI = await createPlaneAndOpenSketcher(ui);
|
||||
let sketchedFace = ui.context.services.selection.face.single;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ export async function testCreatePlaneParallelToOther(env, ui) {
|
|||
let baseFace = captured[0];
|
||||
|
||||
ui.openWizard('PLANE');
|
||||
ui.wizardContext.updateParam('parallelTo', baseFace.id);
|
||||
ui.wizardContext.updateParam('datum', baseFace.id);
|
||||
ui.wizardContext.updateParam('depth', 100);
|
||||
await ui.wizardOK();
|
||||
|
||||
|
|
@ -70,4 +70,3 @@ export async function testCreatePlaneParallelToOther(env, ui) {
|
|||
assertTrue(captured[0].id === baseFace.id);
|
||||
assertTrue(captured[1].id !== baseFace.id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,42 +4,43 @@ import CSys from "math/csys";
|
|||
import {OperationResult} from "cad/craft/craftPlugin";
|
||||
import {BooleanDefinition, BooleanKind} from "cad/craft/schema/common/BooleanDefinition";
|
||||
import {MShell} from "cad/model/mshell";
|
||||
import {WireRef} from "cad/craft/e0/occSketchLoader";
|
||||
|
||||
export interface OCCUtils {
|
||||
|
||||
wiresToFaces(wires: string[]): string[];
|
||||
wiresToFaces(wires: WireRef[]): FaceRef[];
|
||||
|
||||
sketchToFaces(sketch: SketchGeom, csys: CSys): string[];
|
||||
sketchToFaces(sketch: SketchGeom, csys: CSys): FaceRef[];
|
||||
|
||||
// applyBoolean(tools: string[], kind: BooleanKind): string[];
|
||||
|
||||
applyBooleanModifier(tools: string[], booleanDef?: BooleanDefinition): OperationResult;
|
||||
}
|
||||
|
||||
export interface FaceRef extends WireRef {
|
||||
face: string;
|
||||
}
|
||||
|
||||
export function createOCCUtils(ctx: CoreContext): OCCUtils {
|
||||
|
||||
function sketchToFaces(sketch: SketchGeom, csys: CSys): string[] {
|
||||
function sketchToFaces(sketch: SketchGeom, csys: CSys): FaceRef[] {
|
||||
const occ = ctx.occService;
|
||||
const wires = occ.io.sketchLoader.pushSketchAsWires(sketch.contours, csys);
|
||||
return wiresToFaces(wires);
|
||||
}
|
||||
|
||||
function wiresToFaces(wires: string[]): string[] {
|
||||
function wiresToFaces(wires: WireRef[]): FaceRef[] {
|
||||
const oci = ctx.occService.commandInterface;
|
||||
return wires.map((wire, i) => {
|
||||
const faceName = "Face/" + i;
|
||||
oci.mkplane(faceName, wire);
|
||||
return faceName;
|
||||
oci.mkplane(faceName, wire.wire);
|
||||
return {
|
||||
face: faceName,
|
||||
...wire
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function applyBoolean(tools: string[], target: string[], kind: BooleanKind): string[] {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function applyBooleanModifier(tools: string[], booleanDef?: BooleanDefinition): OperationResult {
|
||||
const occ = ctx.occService;
|
||||
const oci = ctx.occService.commandInterface;
|
||||
|
|
|
|||
|
|
@ -2,17 +2,26 @@ import {Contour} from "cad/sketch/sketchModel";
|
|||
import {OCCCommandInterface} from "cad/craft/e0/occCommandInterface";
|
||||
import CSys from "math/csys";
|
||||
|
||||
export interface WireRef {
|
||||
|
||||
wire?: string;
|
||||
|
||||
edges?: string[];
|
||||
|
||||
curves?: string[];
|
||||
}
|
||||
|
||||
export interface OCCSketchLoader {
|
||||
|
||||
pushSketchAsWires(sketch: Contour[], csys: CSys): string[];
|
||||
pushSketchAsWires(sketch: Contour[], csys: CSys): WireRef[];
|
||||
|
||||
pushContourAsWire(contour: Contour, id: string|number, csys: CSys): string;
|
||||
pushContourAsWire(contour: Contour, id: string|number, csys: CSys): WireRef;
|
||||
|
||||
}
|
||||
|
||||
export function createOCCSketchLoader(oci: OCCCommandInterface): OCCSketchLoader {
|
||||
|
||||
function pushContourAsWire(contour: Contour, id: string|number, csys: CSys): string {
|
||||
function pushContourAsWire(contour: Contour, id: string|number, csys: CSys): WireRef {
|
||||
|
||||
const boundCurves = contour.segments.map(s => {
|
||||
const geomId = "SketchGeom:" + s.id;
|
||||
|
|
@ -30,11 +39,14 @@ export function createOCCSketchLoader(oci: OCCCommandInterface): OCCSketchLoader
|
|||
|
||||
oci.wire(wireName, ...edges);
|
||||
|
||||
return wireName;
|
||||
|
||||
return {
|
||||
wire: wireName,
|
||||
edges,
|
||||
curves: boundCurves
|
||||
};
|
||||
}
|
||||
|
||||
const pushSketchAsWires = (sketch: Contour[], csys: CSys): string[] => sketch.map((c, i) => pushContourAsWire(c, i, csys));
|
||||
const pushSketchAsWires = (sketch: Contour[], csys: CSys): WireRef[] => sketch.map((c, i) => pushContourAsWire(c, i, csys));
|
||||
|
||||
return {
|
||||
pushSketchAsWires, pushContourAsWire
|
||||
|
|
|
|||
|
|
@ -151,10 +151,6 @@ export function activate(ctx: ApplicationContext) {
|
|||
return getWorkingRequest();
|
||||
},
|
||||
|
||||
get materializedWorkingRequest() {
|
||||
return materializedWorkingRequest$.value;
|
||||
},
|
||||
|
||||
get operation(): Operation<any> {
|
||||
const req = getWorkingRequest();
|
||||
if (!req) {
|
||||
|
|
|
|||
|
|
@ -37,8 +37,6 @@ export interface WizardService {
|
|||
|
||||
workingRequest: OperationRequest;
|
||||
|
||||
materializedWorkingRequest: any;
|
||||
|
||||
updateParams: (mutator: (params: OperationParams) => void) => void;
|
||||
|
||||
updateParam: (path: ParamsPath, value: OperationParamValue) => void;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ export function activate(ctx: ApplicationContext) {
|
|||
return;
|
||||
}
|
||||
const {type, params} = materializedWorkingRequest;
|
||||
const operation = ctx.wizardService.operation;
|
||||
if (!ctx.wizardService.operation) {
|
||||
return;
|
||||
}
|
||||
const operation = ctx.operationService.get(type);
|
||||
if (operation.previewGeomProvider || operation.previewer) {
|
||||
if (previewer === null) {
|
||||
let newPreviewer;
|
||||
|
|
|
|||
Loading…
Reference in a new issue