diff --git a/modules/workbenches/examples/features/occ_bottle/index.ts b/modules/workbenches/examples/features/occ_bottle/index.ts index d7165f79..2f72c8a7 100644 --- a/modules/workbenches/examples/features/occ_bottle/index.ts +++ b/modules/workbenches/examples/features/occ_bottle/index.ts @@ -8,7 +8,10 @@ import icon from './icon.svg'; export default { id: 'OCC_BOTTLE', label: 'OCC Bottle', - icon, + icon: { + iconType: 'svg', + iconContent: icon + }, info: 'create occ bottle', mutualExclusiveFields: [], paramsInfo: ({ width, height, thickness }) => `(${r(width)} ${r(height)} ${r(thickness)})`, diff --git a/package-lock.json b/package-lock.json index 2284c42b..9f8925f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -74,6 +74,7 @@ "integrity": "sha512-XXLgAm6LBbaNxaGhMAznXXaxtCWfuv6PIDJ9Alsy9JYTOh+j2jJz+L/162kkfU1j/pTSxK1xGmlwI4pdIMkoag==", "dev": true, "dependencies": { + "chokidar": "^2.1.8", "commander": "^4.0.1", "convert-source-map": "^1.1.0", "fs-readdir-recursive": "^1.1.0", @@ -3285,6 +3286,7 @@ "anymatch": "^2.0.0", "async-each": "^1.0.1", "braces": "^2.3.2", + "fsevents": "^1.2.7", "glob-parent": "^3.1.0", "inherits": "^2.0.3", "is-binary-path": "^1.0.0", @@ -8492,9 +8494,12 @@ "clone": "^2.1.2", "errno": "^0.1.1", "graceful-fs": "^4.1.2", + "image-size": "~0.5.0", "mime": "^1.4.1", "mkdirp": "^0.5.0", "promise": "^7.1.1", + "request": "^2.83.0", + "source-map": "~0.6.0", "tslib": "^1.10.0" }, "bin": { diff --git a/web/app/cad/dom/components/PlugableToolbar.jsx b/web/app/cad/dom/components/PlugableToolbar.jsx index 84f0c667..37ac31ea 100644 --- a/web/app/cad/dom/components/PlugableToolbar.jsx +++ b/web/app/cad/dom/components/PlugableToolbar.jsx @@ -40,7 +40,7 @@ function ActionButton({label, icon, icon96, icon32, cssIcons, symbol, size, noLa let smallOrMedium = size === 'medium' || size === 'small'; if (icon) { const Icon = icon; - icon = ; + icon = ; } if (!icon) { if (smallOrMedium) { diff --git a/web/app/cad/icons/DeclarativeIcon.tsx b/web/app/cad/icons/DeclarativeIcon.tsx new file mode 100644 index 00000000..3e6cceb0 --- /dev/null +++ b/web/app/cad/icons/DeclarativeIcon.tsx @@ -0,0 +1,58 @@ +import React from 'react' +import { SvgIcon } from 'svg/SvgIcon'; +import ImgIcon from 'ui/components/ImgIcon'; +import { IconContent, IconDeclaration, IconSetDef, IconSize, IconType } from './IconDeclaration'; + + +interface IconRenderProps { + size: IconSize +} + +export function DeclaredIcon(props: IconRenderProps & IconDeclaration & React.HTMLAttributes) { + + if (props.iconSet) { + return + } else { + return + } +} + +function IconSet(props: IconRenderProps & IconSetDef & React.HTMLAttributes) { + + const {iconSet} = props; + + let iconDef = iconSet[props.size] | iconSet[IconSize.large] | iconSet[IconSize.medium] | iconSet[IconSize.small] + + return ; +} + +function Icon(props: { + iconType: IconType, + iconContent: IconContent + size: IconSize +} & React.HTMLAttributes) { + + const {iconContent, size, iconType, ...htmlProps} = props; + + const sizeInPx = getSizeInPx(size); + + if (iconType === 'image') { + return + } else if (props.iconType === 'svg') { + return + } else { + throw 'unsupported icon type ' + iconType; + } + + +} + +function getSizeInPx(sizeName: IconSize): number { + switch (sizeName) { + case 'small': return 16; + case 'medium': return 24; + case 'large': + default: + return 48; + } +} \ No newline at end of file diff --git a/web/app/cad/icons/IconDeclaration.ts b/web/app/cad/icons/IconDeclaration.ts new file mode 100644 index 00000000..628f31cc --- /dev/null +++ b/web/app/cad/icons/IconDeclaration.ts @@ -0,0 +1,24 @@ +export type IconDeclaration = IconSetDef | IconDef; + +export enum IconSize { + small = 'small', + medium = 'medium', + large = 'large' +}; + +export interface IconSetDef { + iconType: IconType; + + iconSet: { + [key in IconSize]: IconDef + } +} + +export type IconType = 'image' | 'svg'; + +export type IconContent = any; + +export type IconDef = IconContent | { + iconType: IconType; + iconContent: IconContent; +}; diff --git a/web/app/cad/mdf/mdf.ts b/web/app/cad/mdf/mdf.ts index e23ef3c7..c95cbd0a 100644 --- a/web/app/cad/mdf/mdf.ts +++ b/web/app/cad/mdf/mdf.ts @@ -1,3 +1,4 @@ +import { IconDeclaration } from "cad/icons/IconDeclaration"; import { CoreContext } from "context"; import { IconType } from "react-icons"; import { OperationResult } from "../craft/craftPlugin"; @@ -10,7 +11,7 @@ interface MDFCommand { id: string; label: string; info: string; - icon: IconType | string; + icon: IconType | IconDeclaration; run: (request: R, opContext: CoreContext) => OperationResult | Promise; paramsInfo: (params: R) => string, schema: OperationSchema, diff --git a/web/app/cad/mdf/mdfIconResolver.tsx b/web/app/cad/mdf/mdfIconResolver.tsx index d0c1c07b..17c0e780 100644 --- a/web/app/cad/mdf/mdfIconResolver.tsx +++ b/web/app/cad/mdf/mdfIconResolver.tsx @@ -1,6 +1,16 @@ +import { DeclaredIcon } from 'cad/icons/DeclarativeIcon'; +import { IconDeclaration } from 'cad/icons/IconDeclaration'; import React from 'react'; -import { SvgIcon } from "svg/SvgIcon"; +import { AiOutlineQuestion } from 'react-icons/ai'; +import { IconType } from 'react-icons/lib'; -export function resolveMDFIcon(iconDef: any) { - return () => +export function resolveMDFIcon(iconDef: IconDeclaration | IconType) { + if (iconDef.iconType) { + return (props) => + } else { + if (!iconDef || typeof(iconDef) !== 'object') { + return AiOutlineQuestion; + } + return iconDef; + } } \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index f1e2fade..1c90e437 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -99,11 +99,16 @@ module.exports = { { test: /\.svg$/, loader: 'raw-loader' - }, { - test: /\.png$/, - loader: 'url-loader?mimetype=image/png' - } - ], + }, + { + test: /\.(png|jpg|gif)$/i, + use: [ + { + loader: 'url-loader' + }, + ], + }, + ] }, node: { fs: "empty" diff --git a/workbenches/modeler/features/primitive_box/index.ts b/workbenches/modeler/features/primitive_box/index.ts new file mode 100644 index 00000000..efdf0cbe --- /dev/null +++ b/workbenches/modeler/features/primitive_box/index.ts @@ -0,0 +1,56 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_box', + label: 'primitive_box', + icon: 'img/cad/extrude', + info: 'primitive_box', + mutualExclusiveFields: [], + paramsInfo: ({ boxX, boxY, boxZ }) => `(${r(boxX)} ${r(boxY)}) ${r(boxZ)})`, + run: ({ boxX, boxY, boxZ }, 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); + console.log(boxX, boxY, boxZ, oc.BRepPrimAPI_MakeBox_1(boxX, boxY, boxZ)) + + let myBody = new oc.BRepPrimAPI_MakeBox_1(boxX, boxY, boxZ ); + //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: { + boxX: { + type: 'number', + defaultValue: 200, + label: 'X' + }, + boxY: { + type: 'number', + defaultValue: 280, + label: 'Y' + }, + BoxZ: { + type: 'number', + defaultValue: 280, + label: 'Z' + }, + } +} + diff --git a/workbenches/modeler/features/primitive_cone/index.ts b/workbenches/modeler/features/primitive_cone/index.ts new file mode 100644 index 00000000..5940f2fa --- /dev/null +++ b/workbenches/modeler/features/primitive_cone/index.ts @@ -0,0 +1,50 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_cone', + label: 'primitive_cone', + icon: 'img/cad/extrude', + info: 'primitive_cone', + mutualExclusiveFields: [], + paramsInfo: ({ diameter, height }) => `(${r(diameter)} ${r(height)})`, + run: ({ diameter, height, }, ctx: ApplicationContext) => { + //const occObj = createcone(diameter, height, ctx.occService.occContext); + const oc = ctx.occService.occContext; + + const myLocation = new oc.gp_Pnt_3(0, 0, 0); + const coneCenterline = oc.gp.DZ(); + const coneOrientationAndLocation = new oc.gp_Ax2_3(myLocation, coneCenterline); + + let myBody = new oc.BRepPrimAPI_MakeCone_1(10,20,100); + //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' + }, + } +} + diff --git a/workbenches/modeler/features/primitive_cylinder/index.ts b/workbenches/modeler/features/primitive_cylinder/index.ts new file mode 100644 index 00000000..0b413f0f --- /dev/null +++ b/workbenches/modeler/features/primitive_cylinder/index.ts @@ -0,0 +1,51 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_cylinder', + label: 'primitive_cylinder', + icon: 'img/cad/extrude', + 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); + + + 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' + }, + } +} + diff --git a/workbenches/modeler/features/primitive_sphere/index.ts b/workbenches/modeler/features/primitive_sphere/index.ts new file mode 100644 index 00000000..47511e2b --- /dev/null +++ b/workbenches/modeler/features/primitive_sphere/index.ts @@ -0,0 +1,46 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_sphere', + label: 'primitive_sphere', + icon: 'img/cad/extrude', + info: 'primitive_sphere', + mutualExclusiveFields: [], + paramsInfo: ({ diameter }) => `(${r(diameter)} )`, + run: ({ diameter, }, ctx: ApplicationContext) => { + + const oc = ctx.occService.occContext; + + const myLocation = new oc.gp_Pnt_3(0, 0, 0); + const sphereCenterline = oc.gp.DZ(); + const sphereOrientationAndLocation = new oc.gp_Ax2_3(myLocation, sphereCenterline); + + + let myBody = new oc.BRepPrimAPI_MakeSphere_1(diameter); + //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' + }, + } +} + diff --git a/workbenches/modeller/feature/primitive_box/index.ts b/workbenches/modeller/feature/primitive_box/index.ts new file mode 100644 index 00000000..efdf0cbe --- /dev/null +++ b/workbenches/modeller/feature/primitive_box/index.ts @@ -0,0 +1,56 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_box', + label: 'primitive_box', + icon: 'img/cad/extrude', + info: 'primitive_box', + mutualExclusiveFields: [], + paramsInfo: ({ boxX, boxY, boxZ }) => `(${r(boxX)} ${r(boxY)}) ${r(boxZ)})`, + run: ({ boxX, boxY, boxZ }, 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); + console.log(boxX, boxY, boxZ, oc.BRepPrimAPI_MakeBox_1(boxX, boxY, boxZ)) + + let myBody = new oc.BRepPrimAPI_MakeBox_1(boxX, boxY, boxZ ); + //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: { + boxX: { + type: 'number', + defaultValue: 200, + label: 'X' + }, + boxY: { + type: 'number', + defaultValue: 280, + label: 'Y' + }, + BoxZ: { + type: 'number', + defaultValue: 280, + label: 'Z' + }, + } +} + diff --git a/workbenches/modeller/feature/primitive_cone/index.ts b/workbenches/modeller/feature/primitive_cone/index.ts new file mode 100644 index 00000000..5940f2fa --- /dev/null +++ b/workbenches/modeller/feature/primitive_cone/index.ts @@ -0,0 +1,50 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_cone', + label: 'primitive_cone', + icon: 'img/cad/extrude', + info: 'primitive_cone', + mutualExclusiveFields: [], + paramsInfo: ({ diameter, height }) => `(${r(diameter)} ${r(height)})`, + run: ({ diameter, height, }, ctx: ApplicationContext) => { + //const occObj = createcone(diameter, height, ctx.occService.occContext); + const oc = ctx.occService.occContext; + + const myLocation = new oc.gp_Pnt_3(0, 0, 0); + const coneCenterline = oc.gp.DZ(); + const coneOrientationAndLocation = new oc.gp_Ax2_3(myLocation, coneCenterline); + + let myBody = new oc.BRepPrimAPI_MakeCone_1(10,20,100); + //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' + }, + } +} + diff --git a/workbenches/modeller/feature/primitive_cylinder/index.ts b/workbenches/modeller/feature/primitive_cylinder/index.ts new file mode 100644 index 00000000..0b413f0f --- /dev/null +++ b/workbenches/modeller/feature/primitive_cylinder/index.ts @@ -0,0 +1,51 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_cylinder', + label: 'primitive_cylinder', + icon: 'img/cad/extrude', + 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); + + + 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' + }, + } +} + diff --git a/workbenches/modeller/feature/primitive_sphere/index.ts b/workbenches/modeller/feature/primitive_sphere/index.ts new file mode 100644 index 00000000..47511e2b --- /dev/null +++ b/workbenches/modeller/feature/primitive_sphere/index.ts @@ -0,0 +1,46 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_sphere', + label: 'primitive_sphere', + icon: 'img/cad/extrude', + info: 'primitive_sphere', + mutualExclusiveFields: [], + paramsInfo: ({ diameter }) => `(${r(diameter)} )`, + run: ({ diameter, }, ctx: ApplicationContext) => { + + const oc = ctx.occService.occContext; + + const myLocation = new oc.gp_Pnt_3(0, 0, 0); + const sphereCenterline = oc.gp.DZ(); + const sphereOrientationAndLocation = new oc.gp_Ax2_3(myLocation, sphereCenterline); + + + let myBody = new oc.BRepPrimAPI_MakeSphere_1(diameter); + //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' + }, + } +} + diff --git a/workbenches/modeller/feature/primitive_torus/index.ts b/workbenches/modeller/feature/primitive_torus/index.ts new file mode 100644 index 00000000..52bfdeaf --- /dev/null +++ b/workbenches/modeller/feature/primitive_torus/index.ts @@ -0,0 +1,51 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_torus', + label: 'primitive_torus', + icon: 'img/cad/extrude', + info: 'primitive_torus', + mutualExclusiveFields: [], + paramsInfo: ({ radius, tubeRadius }) => `(${r(radius)} ${r(tubeRadius)} )`, + run: ({ radius, tubeRadius }, ctx: ApplicationContext) => { + + const oc = ctx.occService.occContext; + + const myLocation = new oc.gp_Pnt_3(0, 0, 0); + const torusCenterline = oc.gp.DZ(); + const torusOrientationAndLocation = new oc.gp_Ax2_3(myLocation, torusCenterline); + + + let myBody = new oc.BRepPrimAPI_MakeTorus_1(radius, tubeRadius); + //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: { + radius : { + type: 'number', + defaultValue: 200, + label: 'radius' + }, + tubeRadius: { + type: 'number', + defaultValue: 50, + label: 'tube radius' + }, + } +} + diff --git a/workbenches/modeller/features/primitive_box/index.ts b/workbenches/modeller/features/primitive_box/index.ts new file mode 100644 index 00000000..efdf0cbe --- /dev/null +++ b/workbenches/modeller/features/primitive_box/index.ts @@ -0,0 +1,56 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_box', + label: 'primitive_box', + icon: 'img/cad/extrude', + info: 'primitive_box', + mutualExclusiveFields: [], + paramsInfo: ({ boxX, boxY, boxZ }) => `(${r(boxX)} ${r(boxY)}) ${r(boxZ)})`, + run: ({ boxX, boxY, boxZ }, 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); + console.log(boxX, boxY, boxZ, oc.BRepPrimAPI_MakeBox_1(boxX, boxY, boxZ)) + + let myBody = new oc.BRepPrimAPI_MakeBox_1(boxX, boxY, boxZ ); + //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: { + boxX: { + type: 'number', + defaultValue: 200, + label: 'X' + }, + boxY: { + type: 'number', + defaultValue: 280, + label: 'Y' + }, + BoxZ: { + type: 'number', + defaultValue: 280, + label: 'Z' + }, + } +} + diff --git a/workbenches/modeller/features/primitive_cone/index.ts b/workbenches/modeller/features/primitive_cone/index.ts new file mode 100644 index 00000000..5940f2fa --- /dev/null +++ b/workbenches/modeller/features/primitive_cone/index.ts @@ -0,0 +1,50 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_cone', + label: 'primitive_cone', + icon: 'img/cad/extrude', + info: 'primitive_cone', + mutualExclusiveFields: [], + paramsInfo: ({ diameter, height }) => `(${r(diameter)} ${r(height)})`, + run: ({ diameter, height, }, ctx: ApplicationContext) => { + //const occObj = createcone(diameter, height, ctx.occService.occContext); + const oc = ctx.occService.occContext; + + const myLocation = new oc.gp_Pnt_3(0, 0, 0); + const coneCenterline = oc.gp.DZ(); + const coneOrientationAndLocation = new oc.gp_Ax2_3(myLocation, coneCenterline); + + let myBody = new oc.BRepPrimAPI_MakeCone_1(10,20,100); + //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' + }, + } +} + diff --git a/workbenches/modeller/features/primitive_cylinder/index.ts b/workbenches/modeller/features/primitive_cylinder/index.ts new file mode 100644 index 00000000..0b413f0f --- /dev/null +++ b/workbenches/modeller/features/primitive_cylinder/index.ts @@ -0,0 +1,51 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_cylinder', + label: 'primitive_cylinder', + icon: 'img/cad/extrude', + 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); + + + 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' + }, + } +} + diff --git a/workbenches/modeller/features/primitive_sphere/index.ts b/workbenches/modeller/features/primitive_sphere/index.ts new file mode 100644 index 00000000..47511e2b --- /dev/null +++ b/workbenches/modeller/features/primitive_sphere/index.ts @@ -0,0 +1,46 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_sphere', + label: 'primitive_sphere', + icon: 'img/cad/extrude', + info: 'primitive_sphere', + mutualExclusiveFields: [], + paramsInfo: ({ diameter }) => `(${r(diameter)} )`, + run: ({ diameter, }, ctx: ApplicationContext) => { + + const oc = ctx.occService.occContext; + + const myLocation = new oc.gp_Pnt_3(0, 0, 0); + const sphereCenterline = oc.gp.DZ(); + const sphereOrientationAndLocation = new oc.gp_Ax2_3(myLocation, sphereCenterline); + + + let myBody = new oc.BRepPrimAPI_MakeSphere_1(diameter); + //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' + }, + } +} + diff --git a/workbenches/modeller/features/primitive_torus/index.ts b/workbenches/modeller/features/primitive_torus/index.ts new file mode 100644 index 00000000..52bfdeaf --- /dev/null +++ b/workbenches/modeller/features/primitive_torus/index.ts @@ -0,0 +1,51 @@ +import { ApplicationContext } from 'context'; +import { MBrepShell } from '../../../../../web/app/cad/model/mshell'; +import { roundValueForPresentation as r } from '../../../../../web/app/cad/craft/operationHelper'; +import { occ2brep } from '../../../../../web/app/cad/occ/occ2models'; + +export default { + id: 'primitive_torus', + label: 'primitive_torus', + icon: 'img/cad/extrude', + info: 'primitive_torus', + mutualExclusiveFields: [], + paramsInfo: ({ radius, tubeRadius }) => `(${r(radius)} ${r(tubeRadius)} )`, + run: ({ radius, tubeRadius }, ctx: ApplicationContext) => { + + const oc = ctx.occService.occContext; + + const myLocation = new oc.gp_Pnt_3(0, 0, 0); + const torusCenterline = oc.gp.DZ(); + const torusOrientationAndLocation = new oc.gp_Ax2_3(myLocation, torusCenterline); + + + let myBody = new oc.BRepPrimAPI_MakeTorus_1(radius, tubeRadius); + //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: { + radius : { + type: 'number', + defaultValue: 200, + label: 'radius' + }, + tubeRadius: { + type: 'number', + defaultValue: 50, + label: 'tube radius' + }, + } +} +