mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 16:33:15 +01:00
Added fully working mirror body and added start of sheet metal commands in inwork state
This commit is contained in:
parent
6237fa3f27
commit
12f4d5761e
7 changed files with 272 additions and 4 deletions
|
|
@ -0,0 +1,66 @@
|
||||||
|
import { roundValueForPresentation as r } from 'cad/craft/operationHelper';
|
||||||
|
import { MFace } from "cad/model/mface";
|
||||||
|
import { ApplicationContext } from "context";
|
||||||
|
import { EntityKind } from "cad/model/entities";
|
||||||
|
import Axis from "math/axis";
|
||||||
|
import { OperationDescriptor } from "cad/craft/operationPlugin";
|
||||||
|
import { MShell } from 'cad/model/mshell';
|
||||||
|
|
||||||
|
interface MirrorBodyParams {
|
||||||
|
inputBodies: MShell[];
|
||||||
|
face:MFace;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MirrorBodyOperation: OperationDescriptor<MirrorBodyParams> = {
|
||||||
|
id: 'MIRROR_BODY',
|
||||||
|
label: 'Mirror Body',
|
||||||
|
icon: 'img/cad/MirrorBody',
|
||||||
|
info: 'Mirrors selected body along plane of symytry.',
|
||||||
|
paramsInfo: ({ }) => `(${r()})`,
|
||||||
|
run: (params: MirrorBodyParams, ctx: ApplicationContext) => {
|
||||||
|
console.log(params);
|
||||||
|
let occ = ctx.occService;
|
||||||
|
const oci = occ.commandInterface;
|
||||||
|
|
||||||
|
let created =[];
|
||||||
|
|
||||||
|
params.inputBodies.forEach((shellToMirror) => {
|
||||||
|
const newShellName = shellToMirror.id + ":mirror";
|
||||||
|
oci.copy(shellToMirror, newShellName);
|
||||||
|
params.face.csys.origin.data();
|
||||||
|
oci.tmirror(newShellName, ...params.face.csys.origin.data(), ...params.face.csys.origin.normalize().data());
|
||||||
|
created.push(occ.io.getShell(newShellName));
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
created,
|
||||||
|
consumed: []
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'face',
|
||||||
|
capture: [EntityKind.FACE],
|
||||||
|
label: 'Mirror Plane',
|
||||||
|
multi: false,
|
||||||
|
defaultValue: {
|
||||||
|
usePreselection: false,
|
||||||
|
preselectionIndex: 0
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'inputBodies',
|
||||||
|
capture: [EntityKind.SHELL],
|
||||||
|
label: 'Bodies',
|
||||||
|
multi: true,
|
||||||
|
defaultValue: {
|
||||||
|
usePreselection: true,
|
||||||
|
preselectionIndex: 0
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
import { roundValueForPresentation as r } from 'cad/craft/operationHelper';
|
||||||
|
import { MFace } from "cad/model/mface";
|
||||||
|
import { ApplicationContext } from "context";
|
||||||
|
import { EntityKind } from "cad/model/entities";
|
||||||
|
import { BooleanDefinition } from "cad/craft/schema/common/BooleanDefinition";
|
||||||
|
import Axis from "math/axis";
|
||||||
|
import { OperationDescriptor } from "cad/craft/operationPlugin";
|
||||||
|
|
||||||
|
interface smFlangeParams {
|
||||||
|
angle: number;
|
||||||
|
face: MFace;
|
||||||
|
axis: Axis,
|
||||||
|
boolean: BooleanDefinition
|
||||||
|
}
|
||||||
|
|
||||||
|
export const smFlangeOperation: OperationDescriptor<smFlangeParams> = {
|
||||||
|
id: 'SM_FLANGE',
|
||||||
|
label: 'Flange',
|
||||||
|
icon: 'img/cad/smFlange',
|
||||||
|
info: 'Creates Sheet metal flange',
|
||||||
|
paramsInfo: ({ angle }) => `(${r(angle)})`,
|
||||||
|
run: (params: smFlangeParams, ctx: ApplicationContext) => {
|
||||||
|
console.log(params);
|
||||||
|
let occ = ctx.occService;
|
||||||
|
const oci = occ.commandInterface;
|
||||||
|
|
||||||
|
const face = params.face;
|
||||||
|
|
||||||
|
let occFaces = [face];
|
||||||
|
|
||||||
|
const tools = occFaces.map((faceName, i) => {
|
||||||
|
const shapeName = "Tool/" + i;
|
||||||
|
var args = [shapeName, faceName, ...params.axis.origin.data(), ...params.axis.direction.negate().data(), params.angle];
|
||||||
|
oci.revol(...args);
|
||||||
|
|
||||||
|
return shapeName;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return occ.utils.applyBooleanModifier(tools, params.boolean);
|
||||||
|
|
||||||
|
},
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
type: 'number',
|
||||||
|
label: 'angle',
|
||||||
|
name: 'angle',
|
||||||
|
defaultValue: 90,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'face',
|
||||||
|
capture: [EntityKind.FACE],
|
||||||
|
label: 'face',
|
||||||
|
multi: false,
|
||||||
|
defaultValue: {
|
||||||
|
usePreselection: true,
|
||||||
|
preselectionIndex: 0
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'Edge',
|
||||||
|
capture: [EntityKind.EDGE],
|
||||||
|
label: 'Edge',
|
||||||
|
multi: false,
|
||||||
|
defaultValue: {
|
||||||
|
usePreselection: true,
|
||||||
|
preselectionIndex: 0
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
type: 'axis',
|
||||||
|
name: 'axis',
|
||||||
|
label: 'axis',
|
||||||
|
optional: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'boolean',
|
||||||
|
name: 'boolean',
|
||||||
|
label: 'boolean',
|
||||||
|
optional: true,
|
||||||
|
defaultValue: 'UNION'
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
}
|
||||||
106
modules/workbenches/modeler/features/smTab/smTab.operation.ts
Normal file
106
modules/workbenches/modeler/features/smTab/smTab.operation.ts
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
import { roundValueForPresentation as r } from 'cad/craft/operationHelper';
|
||||||
|
import { 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";
|
||||||
|
|
||||||
|
|
||||||
|
interface smTabParams {
|
||||||
|
thickness: number;
|
||||||
|
bendRadius: number;
|
||||||
|
kFactor: number;
|
||||||
|
flipper: boolean;
|
||||||
|
sketch: MFace;
|
||||||
|
boolean: BooleanDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const smTabOperation: OperationDescriptor<smTabParams> = {
|
||||||
|
id: 'SM_TAB',
|
||||||
|
label: 'SM Tab',
|
||||||
|
icon: 'img/cad/smTab',
|
||||||
|
info: 'Create tab from sketch',
|
||||||
|
paramsInfo: ({ thickness, bendRadius }) => `(${r(thickness)} ${r(bendRadius)} )`,
|
||||||
|
run: (params: smTabParams, ctx: ApplicationContext) => {
|
||||||
|
|
||||||
|
let occ = ctx.occService;
|
||||||
|
console.log(ctx.craftService.modifications$.value.history);
|
||||||
|
const oci = occ.commandInterface;
|
||||||
|
|
||||||
|
const face = params.sketch;
|
||||||
|
|
||||||
|
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 dir: UnitVector= face.normal();
|
||||||
|
|
||||||
|
let extrusionVector =[];
|
||||||
|
if(params.flipper == true){
|
||||||
|
extrusionVector = dir.normalize()._multiply(params.thickness).data();
|
||||||
|
}else{
|
||||||
|
extrusionVector = dir.normalize()._multiply(params.thickness).negate().data();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const tools = occFaces.map((faceName, i) => {
|
||||||
|
const shapeName = "Tool/" + i;
|
||||||
|
const bla = oci.prism(shapeName, faceName, ...extrusionVector);
|
||||||
|
console.log(bla);
|
||||||
|
return shapeName;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return occ.utils.applyBooleanModifier(tools, params.boolean);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
type: 'number',
|
||||||
|
label: 'Thickness',
|
||||||
|
name: 'thickness',
|
||||||
|
defaultValue: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'number',
|
||||||
|
label: 'Bend Radius',
|
||||||
|
name: 'bendRadius',
|
||||||
|
defaultValue: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'number',
|
||||||
|
label: 'K-Factor',
|
||||||
|
name: 'kFactor',
|
||||||
|
defaultValue: 0.35,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'checkbox',
|
||||||
|
label: 'flip',
|
||||||
|
name: 'flipper',
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'sketch',
|
||||||
|
capture: [EntityKind.FACE],
|
||||||
|
label: 'Sketch',
|
||||||
|
multi: false,
|
||||||
|
defaultValue: {
|
||||||
|
usePreselection: true,
|
||||||
|
preselectionIndex: 0
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'boolean',
|
||||||
|
name: 'boolean',
|
||||||
|
label: 'boolean',
|
||||||
|
optional: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,10 @@ import { BooleanOperation } from "./features/boolean/boolean.operation";
|
||||||
import { RevolveOperation } from "./features/revolve/revolve.operation";
|
import { RevolveOperation } from "./features/revolve/revolve.operation";
|
||||||
import { ShellOperation } from "./features/shell/shell.operation";
|
import { ShellOperation } from "./features/shell/shell.operation";
|
||||||
import { SweepOperation } from "./features/sweep/sweep.operation";
|
import { SweepOperation } from "./features/sweep/sweep.operation";
|
||||||
import { offsetOperation } from "./features/offsetFace/offsetFace.operation"
|
import { offsetOperation } from "./features/offsetFace/offsetFace.operation";
|
||||||
|
import { smTabOperation } from "./features/smTab/smTab.operation";
|
||||||
|
import { smFlangeOperation } from "./features/smFlange/smFlange.operation";
|
||||||
|
import { MirrorBodyOperation} from "./features/mirrorBody/mirrorBody.operation";
|
||||||
|
|
||||||
export const ModelerWorkspace: WorkbenchConfig = {
|
export const ModelerWorkspace: WorkbenchConfig = {
|
||||||
|
|
||||||
|
|
@ -31,7 +34,10 @@ export const ModelerWorkspace: WorkbenchConfig = {
|
||||||
ShellOperation,
|
ShellOperation,
|
||||||
LoftOperation,
|
LoftOperation,
|
||||||
SweepOperation,
|
SweepOperation,
|
||||||
offsetOperation
|
offsetOperation,
|
||||||
|
smTabOperation,
|
||||||
|
smFlangeOperation,
|
||||||
|
MirrorBodyOperation
|
||||||
],
|
],
|
||||||
actions: [],
|
actions: [],
|
||||||
ui: {
|
ui: {
|
||||||
|
|
@ -39,10 +45,11 @@ export const ModelerWorkspace: WorkbenchConfig = {
|
||||||
'DATUM_CREATE', 'PLANE', 'EditFace', '-',
|
'DATUM_CREATE', 'PLANE', 'EditFace', '-',
|
||||||
"EXTRUDE", "REVOLVE", "LOFT", "SWEEP", "-",
|
"EXTRUDE", "REVOLVE", "LOFT", "SWEEP", "-",
|
||||||
"BOOLEAN", "-",
|
"BOOLEAN", "-",
|
||||||
"SHELL_TOOL", "FILLET_TOOL", "OFFSET_TOOL", "-",
|
"SHELL_TOOL", "FILLET_TOOL", "OFFSET_TOOL", "MIRROR_BODY", "-",
|
||||||
"PRIMITIVE_CYLINDER", "PRIMITIVE_BOX", "PRIMITIVE_CONE", "PRIMITIVE_SPHERE", "PRIMITIVE_TORUS", "-",
|
"PRIMITIVE_CYLINDER", "PRIMITIVE_BOX", "PRIMITIVE_CONE", "PRIMITIVE_SPHERE", "PRIMITIVE_TORUS", "-",
|
||||||
"HOLE_TOOL", "-",
|
"HOLE_TOOL", "-",
|
||||||
"OCC_BOTTLE", '-',
|
"OCC_BOTTLE", '-',
|
||||||
|
"SM_TAB","SM_FLANGE"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ import {ModelerWorkspace} from "workbenches/modeler";
|
||||||
import {ExampleWorkspace} from "workbenches/examples";
|
import {ExampleWorkspace} from "workbenches/examples";
|
||||||
import {WorkbenchConfig} from "cad/workbench/workbenchService";
|
import {WorkbenchConfig} from "cad/workbench/workbenchService";
|
||||||
|
|
||||||
|
|
||||||
export const WorkbenchRegistry: WorkbenchConfig[] = [
|
export const WorkbenchRegistry: WorkbenchConfig[] = [
|
||||||
ModelerWorkspace,
|
ModelerWorkspace,
|
||||||
// ExampleWorkspace,
|
|
||||||
]
|
]
|
||||||
BIN
web/img/cad/smFlange96.png
Normal file
BIN
web/img/cad/smFlange96.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 604 B |
BIN
web/img/cad/smTab96.png
Normal file
BIN
web/img/cad/smTab96.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 431 B |
Loading…
Reference in a new issue