From c306f2f1bb0417db32c5a5b9650b8d123a474c8d Mon Sep 17 00:00:00 2001 From: Mike Molinari Date: Sun, 3 Jul 2022 02:06:24 +0000 Subject: [PATCH] added support to import brp and brep files --- .../features/importModel/docs/index.md | 13 ++++ .../importModel/importModel.operation.ts | 61 +++++++++++++++++++ modules/workbenches/modeler/index.ts | 8 ++- .../cad/craft/ui/SelectedModificationInfo.jsx | 2 +- 4 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 modules/workbenches/modeler/features/importModel/docs/index.md create mode 100644 modules/workbenches/modeler/features/importModel/importModel.operation.ts diff --git a/modules/workbenches/modeler/features/importModel/docs/index.md b/modules/workbenches/modeler/features/importModel/docs/index.md new file mode 100644 index 00000000..21d9779c --- /dev/null +++ b/modules/workbenches/modeler/features/importModel/docs/index.md @@ -0,0 +1,13 @@ +# BOOLEAN OPPERATIONS +Boolean operations allow for solids to be used as tools to shape and modify other solids. + +# UNION +Union allows solids to be combined to create a new solid. + +# SUBTRACT +Subtract allows one solid to be used as a cuttong tool for another sold. Usefull for making hole features. +Selection A will have selection B removed from it. + +# INTERSECTION +Intersection allows for the creation of a new solid in the space where 2 exising solids overlap. + diff --git a/modules/workbenches/modeler/features/importModel/importModel.operation.ts b/modules/workbenches/modeler/features/importModel/importModel.operation.ts new file mode 100644 index 00000000..30c9c543 --- /dev/null +++ b/modules/workbenches/modeler/features/importModel/importModel.operation.ts @@ -0,0 +1,61 @@ +import { roundValueForPresentation as r } from 'cad/craft/operationHelper'; +import { ApplicationContext } from "context"; +import { EntityKind } from "cad/model/entities"; +import { BooleanDefinition } from "cad/craft/schema/common/BooleanDefinition"; +import { OperationDescriptor } from "cad/craft/operationPlugin"; +import { param } from 'cypress/types/jquery'; +import { MObject } from 'cad/model/mobject'; +import { LocalFile } from "ui/components/controls/FileControl"; +import CadError from "../../../../../web/app/utils/errors"; + +interface ImportModelParams { + file: LocalFile; +} + +export const ImportModelOpperation: OperationDescriptor = { + id: 'IMPORT_MODEL', + label: 'Import', + icon: 'img/cad/intersection', + info: 'Imports STEP, BREP or FCStd file', + paramsInfo: ({ }) => `()`, + run: async (params: ImportModelParams, ctx: ApplicationContext) => { + console.log(params); + let occ = ctx.occService; + const oci = occ.commandInterface; + + let returnObject = { created: [], consumed: [] }; + + const FileName = params.file.fileName.toUpperCase() + + if (FileName.endsWith("BRP") || FileName.endsWith("BREP")) { + alert("Importing BREP file"); + + if (!params.file.content.startsWith("DBRep_DrawableShape")) { + params.file.content = `DBRep_DrawableShape\n` + params.file.content; + } + + await FS.writeFile("newStepObject", await (params.file.content)); + oci.readbrep("newStepObject", "newStepObject"); + returnObject.created.push(occ.io.getShell("newStepObject")); + } else { + throw new CadError({ + kind: CadError.KIND.INVALID_INPUT, + code: 'File type not supported at this time' + }); + + + } + + + return returnObject; + + }, + form: [ + { + type: 'file', + name: 'file', + label: 'Select File', + + }, + ], +} diff --git a/modules/workbenches/modeler/index.ts b/modules/workbenches/modeler/index.ts index f619f65b..4470bc37 100644 --- a/modules/workbenches/modeler/index.ts +++ b/modules/workbenches/modeler/index.ts @@ -16,8 +16,9 @@ import { ShellOperation } from "./features/shell/shell.operation"; import { SweepOperation } from "./features/sweep/sweep.operation"; import { ScaleOperation } from "./features/scaleBody/scaleBody.operation"; import { MirrorBodyOperation} from "./features/mirrorBody/mirrorBody.operation"; -import { PatternLinearOperation } from "./features/patternLinear/patternLinear.operation" -import { PatternRadialOperation } from "./features/patternRadial/patternRadial.operation" +import { PatternLinearOperation } from "./features/patternLinear/patternLinear.operation"; +import { PatternRadialOperation } from "./features/patternRadial/patternRadial.operation"; +import { ImportModelOpperation } from "./features/importModel/importModel.operation"; //imports of action type commands import { GetVolume } from './actions/getVolume/getVolume.action'; import {GiCubes} from "react-icons/gi"; @@ -44,6 +45,7 @@ export const ModelerWorkspace: WorkbenchConfig = { MirrorBodyOperation, PatternLinearOperation, PatternRadialOperation, + ImportModelOpperation, ], actions: [], ui: { @@ -54,7 +56,7 @@ export const ModelerWorkspace: WorkbenchConfig = { "SHELL_TOOL", "FILLET_TOOL", "SCALE_BODY","-", "MIRROR_BODY", "PATTERN_LINEAR", "PATTERN_RADIAL", "-", "CYLINDER", "BOX", "CONE", "SPHERE", "TORUS", "-", - "HOLE_TOOL", "-", 'GET_VOLUME', + "HOLE_TOOL", "-", 'GET_VOLUME', "IMPORT_MODEL" ] }, icon: GiCubes diff --git a/web/app/cad/craft/ui/SelectedModificationInfo.jsx b/web/app/cad/craft/ui/SelectedModificationInfo.jsx index b38545ce..a709d529 100644 --- a/web/app/cad/craft/ui/SelectedModificationInfo.jsx +++ b/web/app/cad/craft/ui/SelectedModificationInfo.jsx @@ -53,7 +53,7 @@ function SelectedModificationInfo({ history, index, onClose={close}>
- + {/**/}