mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-14 20:33:30 +01:00
Updated primitive cylinder to be created with the new widget toolkit
This commit is contained in:
parent
031afce603
commit
a5de7d85ab
1 changed files with 64 additions and 58 deletions
|
|
@ -1,64 +1,70 @@
|
|||
import { ApplicationContext } from 'context';
|
||||
import { MBrepShell } from 'cad/model/mshell';
|
||||
import { roundValueForPresentation as r } from 'cad/craft/operationHelper';
|
||||
import { occ2brep } from 'cad/occ/occ2models';
|
||||
import icon32 from './icon32.png';
|
||||
import icon96 from './icon96.png';
|
||||
|
||||
export default {
|
||||
id: 'primitive_cylinder',
|
||||
label: 'primitive_cylinder',
|
||||
icon: {
|
||||
iconSet: {
|
||||
medium: {
|
||||
iconType: 'image',
|
||||
iconContent: icon32
|
||||
},
|
||||
large: {
|
||||
iconType: 'image',
|
||||
iconContent: icon96
|
||||
}
|
||||
},
|
||||
},
|
||||
info: 'primitive_cylinder',
|
||||
mutualExclusiveFields: [],
|
||||
paramsInfo: ({ diameter, height }) => `(${r(diameter)} ${r(height)})`,
|
||||
run: ({ diameter, height, }, ctx: ApplicationContext) => {
|
||||
//const occObj = createCylinder(diameter, height, ctx.occService.occContext);
|
||||
const oc = ctx.occService.occContext;
|
||||
|
||||
const myLocation = new oc.gp_Pnt_3(0, 0, 0);
|
||||
const cylinderCenterline = oc.gp.DZ();
|
||||
const cylinderOrientationAndLocation = new oc.gp_Ax2_3(myLocation, cylinderCenterline);
|
||||
import { EntityKind } from "cad/model/entities";
|
||||
import { BooleanDefinition } from "cad/craft/schema/common/BooleanDefinition";
|
||||
import { OperationDescriptor } from "cad/craft/operationPlugin";
|
||||
|
||||
|
||||
let myBody = new oc.BRepPrimAPI_MakeCylinder_3(cylinderOrientationAndLocation, diameter, height,);
|
||||
//let myBody = new oc.BRepPrimAPI_Make
|
||||
|
||||
const aRes = new oc.TopoDS_Compound();
|
||||
const aBuilder = new oc.BRep_Builder();
|
||||
aBuilder.MakeCompound(aRes);
|
||||
aBuilder.Add(aRes, myBody.Shape());
|
||||
|
||||
|
||||
|
||||
const mobject = new MBrepShell(occ2brep(aRes, ctx.occService.occContext));
|
||||
return {
|
||||
consumed: [],
|
||||
created: [mobject]
|
||||
};
|
||||
},
|
||||
schema: {
|
||||
diameter: {
|
||||
type: 'number',
|
||||
defaultValue: 200,
|
||||
label: 'diameter'
|
||||
},
|
||||
height: {
|
||||
type: 'number',
|
||||
defaultValue: 280,
|
||||
label: 'height'
|
||||
},
|
||||
}
|
||||
interface PrimitiveCylinderParams {
|
||||
diameter: number,
|
||||
height: number,
|
||||
locations: {},
|
||||
boolean: BooleanDefinition,
|
||||
}
|
||||
|
||||
const PrimitiveCylinderOperation: OperationDescriptor<PrimitiveCylinderParams> = {
|
||||
id: 'primitive_cylinder',
|
||||
label: 'Primitive cylinder',
|
||||
icon: 'img/cad/cylinder',
|
||||
info: 'Primitive Box',
|
||||
paramsInfo: ({ height, diameter}) => `(${r(height)} , ${r(diameter)} )`,
|
||||
form: [
|
||||
{
|
||||
type: 'number',
|
||||
label: 'Diameter',
|
||||
name: 'diameter',
|
||||
defaultValue: 50,
|
||||
},
|
||||
{
|
||||
type: 'number',
|
||||
label: 'Height',
|
||||
name: 'height',
|
||||
defaultValue: 50,
|
||||
},
|
||||
{
|
||||
type: 'selection',
|
||||
name: 'locations',
|
||||
capture: [EntityKind.DATUM],
|
||||
label: 'locations',
|
||||
multi: false,
|
||||
optional: true,
|
||||
defaultValue: {
|
||||
usePreselection: true,
|
||||
preselectionIndex: 0
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
type: 'boolean',
|
||||
name: 'boolean',
|
||||
label: 'boolean',
|
||||
optional: true,
|
||||
}
|
||||
|
||||
],
|
||||
|
||||
|
||||
run: (params: PrimitiveCylinderParams, ctx: ApplicationContext) => {
|
||||
|
||||
let occ = ctx.occService;
|
||||
const oci = occ.commandInterface;
|
||||
|
||||
//pcylinder cy 5 10
|
||||
oci.pcylinder("cy", params.diameter/2, params.height);
|
||||
|
||||
return occ.utils.applyBooleanModifier(["cy"], params.boolean);
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
export default PrimitiveCylinderOperation;
|
||||
Loading…
Reference in a new issue