From ead9e7773f3a529310927e1c198d644cf40ad63d Mon Sep 17 00:00:00 2001 From: Mike Molinari Date: Sun, 11 Sep 2022 19:01:53 +0000 Subject: [PATCH] Added wire line command. Code will not generate visible geometry yet. --- .../modeler/features/wireLine/WireLine.svg | 1 + .../modeler/features/wireLine/docs/index.md | 2 + .../modeler/features/wireLine/wireLine.ts | 73 +++++++++++++++++++ .../features/wireLine/wireLineTest.json | 10 +++ modules/workbenches/modeler/index.ts | 6 +- 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 modules/workbenches/modeler/features/wireLine/WireLine.svg create mode 100644 modules/workbenches/modeler/features/wireLine/docs/index.md create mode 100644 modules/workbenches/modeler/features/wireLine/wireLine.ts create mode 100644 modules/workbenches/modeler/features/wireLine/wireLineTest.json diff --git a/modules/workbenches/modeler/features/wireLine/WireLine.svg b/modules/workbenches/modeler/features/wireLine/WireLine.svg new file mode 100644 index 00000000..b96044c9 --- /dev/null +++ b/modules/workbenches/modeler/features/wireLine/WireLine.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/workbenches/modeler/features/wireLine/docs/index.md b/modules/workbenches/modeler/features/wireLine/docs/index.md new file mode 100644 index 00000000..16e20630 --- /dev/null +++ b/modules/workbenches/modeler/features/wireLine/docs/index.md @@ -0,0 +1,2 @@ +# Wire Line +This tool allows for creation of a line element by selecting two datum points. \ No newline at end of file diff --git a/modules/workbenches/modeler/features/wireLine/wireLine.ts b/modules/workbenches/modeler/features/wireLine/wireLine.ts new file mode 100644 index 00000000..18838d2f --- /dev/null +++ b/modules/workbenches/modeler/features/wireLine/wireLine.ts @@ -0,0 +1,73 @@ +import { roundValueForPresentation as r } from 'cad/craft/operationHelper'; +import { ApplicationContext } from "cad/context"; +import { EntityKind } from "cad/model/entities"; +import { OperationDescriptor } from "cad/craft/operationBundle"; +import icon from "./WireLine.svg"; +import { MDatum } from 'cad/model/mdatum'; + + +interface WireLineParams { + points: MDatum[]; +} + +export const WireLineOperation: OperationDescriptor = { + id: 'WIRE_LINE', + label: 'Line', + icon: icon, + info: 'Create Wire Line', + path: __dirname, + paramsInfo: ({ points }) => `(${r(points)})`, + run: (params: WireLineParams, ctx: ApplicationContext) => { + const occ = ctx.occService; + const oci = occ.commandInterface; + console.log(params); + oci.line("newLine", + params.points[0].csys.origin.x, + params.points[0].csys.origin.y, + params.points[0].csys.origin.z, + + params.points[1].csys.origin.x, + params.points[1].csys.origin.y, + params.points[1].csys.origin.z, + ); + + console.log( + params.points[0].csys.origin.x, + params.points[0].csys.origin.y, + params.points[0].csys.origin.z, + + params.points[1].csys.origin.x, + params.points[1].csys.origin.y, + params.points[1].csys.origin.z, ); + + oci.wire("newLineEdge", "newLine"); + oci.mkface("newLineFace","newLineEdge"); + oci.prism("newLinePrism", "newLineFace", 0 , 0, 1) + + const created = [occ.io.getShell("newLineFace")]; + const consumed = []; + + console.log(params.points); + + const returnObject = { + created, + consumed + } + return returnObject; + + }, + form: [ + { + type: 'selection', + name: 'points', + capture: [EntityKind.DATUM], + label: 'points', + optional: false, + multi: true, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, + }, + ], +} diff --git a/modules/workbenches/modeler/features/wireLine/wireLineTest.json b/modules/workbenches/modeler/features/wireLine/wireLineTest.json new file mode 100644 index 00000000..86b27a96 --- /dev/null +++ b/modules/workbenches/modeler/features/wireLine/wireLineTest.json @@ -0,0 +1,10 @@ +{ +"model": +{"history":[{"type":"DATUM_CREATE","params":{"x":"75.610","y":"60.041","z":"83.251","rotations":[]}},{"type":"DATUM_CREATE","params":{"x":"53.402","y":"24.307","z":"52.798","rotations":[]}},{"type":"WIRE_LINE","params":{"points":["D:1","D:0"]}}],"expressions":"","assembly":[]}, + "sketches": [ +{"id":"F:BASE", "data": {"version":3,"objects":[{"id":"52","type":"Segment","role":null,"stage":0,"data":{"a":{"x":0,"y":0},"b":{"x":13.60211439738466,"y":0}}},{"id":"61","type":"Segment","role":null,"stage":0,"data":{"a":{"x":13.60211439738466,"y":0},"b":{"x":13.60211439738466,"y":9.604682653709794}}},{"id":"70","type":"Segment","role":null,"stage":0,"data":{"a":{"x":13.60211439738466,"y":9.604682653709794},"b":{"x":0,"y":9.604682653709794}}},{"id":"79","type":"Segment","role":null,"stage":0,"data":{"a":{"x":0,"y":9.604682653709794},"b":{"x":0,"y":0}}}],"dimensions":[],"labels":[],"stages":[{"constraints":[{"typeId":"PCoincident","objects":["52:A","boundary/S:0/E:0:B"],"stage":0,"annotations":[]},{"typeId":"PCoincident","objects":["79:B","52:A"],"stage":0,"annotations":[]},{"typeId":"PCoincident","objects":["52:B","61:A"],"stage":0,"annotations":[]},{"typeId":"PCoincident","objects":["61:B","70:A"],"stage":0,"annotations":[]},{"typeId":"PCoincident","objects":["70:B","79:A"],"stage":0,"annotations":[]},{"typeId":"Horizontal","objects":["52"],"constants":{"angle":0},"stage":0,"annotations":[]},{"typeId":"Horizontal","objects":["70"],"constants":{"angle":180},"stage":0,"annotations":[]},{"typeId":"Vertical","objects":["79"],"constants":{"angle":270},"stage":0,"annotations":[]},{"typeId":"Vertical","objects":["61"],"constants":{"angle":90},"stage":0,"annotations":[]}],"generators":[]}],"constants":"","metadata":{"expressionsSignature":"1662874760956"}}} +,{"id":"S:1/F:2", "data": {"version":3,"objects":[{"id":"35","type":"Segment","role":null,"stage":0,"data":{"a":{"x":-2.365,"y":2.365},"b":{"x":2.365,"y":2.365}}},{"id":"44","type":"Segment","role":null,"stage":0,"data":{"a":{"x":2.365,"y":2.365},"b":{"x":2.365,"y":-2.365}}},{"id":"53","type":"Segment","role":null,"stage":0,"data":{"a":{"x":2.365,"y":-2.365},"b":{"x":-2.365,"y":-2.365}}},{"id":"62","type":"Segment","role":null,"stage":0,"data":{"a":{"x":-2.365,"y":-2.365},"b":{"x":-2.365,"y":2.365}}},{"id":"71","type":"Segment","role":"construction","stage":0,"data":{"a":{"x":2.365,"y":-2.365},"b":{"x":-2.365,"y":2.365}}}],"dimensions":[],"labels":[],"stages":[{"constraints":[{"typeId":"PCoincident","objects":["62:B","35:A"],"stage":0,"annotations":[]},{"typeId":"PCoincident","objects":["35:B","44:A"],"stage":0,"annotations":[]},{"typeId":"PCoincident","objects":["44:B","53:A"],"stage":0,"annotations":[]},{"typeId":"PCoincident","objects":["53:B","62:A"],"stage":0,"annotations":[]},{"typeId":"Horizontal","objects":["35"],"constants":{"angle":0},"stage":0,"annotations":[]},{"typeId":"Horizontal","objects":["53"],"constants":{"angle":180},"stage":0,"annotations":[]},{"typeId":"Vertical","objects":["62"],"constants":{"angle":90},"stage":0,"annotations":[]},{"typeId":"Vertical","objects":["44"],"constants":{"angle":270},"stage":0,"annotations":[]},{"typeId":"PCoincident","objects":["71:A","44:B"],"stage":0,"annotations":[]},{"typeId":"PCoincident","objects":["71:B","35:A"],"stage":0,"annotations":[]},{"typeId":"PointInMiddle","objects":["ground/ORIGIN","71"],"stage":0,"annotations":[]},{"typeId":"PointOnLine","objects":["ground/ORIGIN","71"],"stage":0,"annotations":[]},{"typeId":"EqualLength","objects":["35","62"],"stage":0,"annotations":[]},{"typeId":"SegmentLength","objects":["35"],"constants":{"length":"4.73"},"stage":0,"annotations":[{"offset":20}]}],"generators":[]}],"constants":"","metadata":{"expressionsSignature":"1662874760956"}}} +,{"id":"S:2/SURFACE", "data": {"version":3,"objects":[{"id":"3","type":"Circle","role":null,"stage":0,"data":{"c":{"x":0,"y":0},"r":3.800268700020518}}],"dimensions":[],"labels":[],"stages":[{"constraints":[{"typeId":"PCoincident","objects":["3:C","ground/ORIGIN"],"stage":0,"annotations":[]}],"generators":[]}],"constants":"","metadata":{"expressionsSignature":"1662874760956"}}} +,{"id":"F:LID", "data": {"version":3,"objects":[{"id":"57","type":"BezierCurve","role":null,"stage":0,"data":{"cp1":{"x":-22.892986374188528,"y":22.042262464523766},"cp2":{"x":-22.711942223122225,"y":29.615261619747223},"cp3":{"x":-18.61312446708757,"y":33.96476533111906},"cp4":{"x":-18.81753871279943,"y":23.71989819082065}}},{"id":"76","type":"BezierCurve","role":null,"stage":0,"data":{"cp1":{"x":-18.81753871279943,"y":23.71989819082065},"cp2":{"x":-19.081496434786285,"y":10.490821210056968},"cp3":{"x":-23.069196705934502,"y":14.671459897336204},"cp4":{"x":-22.892986374188528,"y":22.042262464523766}}}],"dimensions":[],"labels":[],"stages":[{"constraints":[{"typeId":"PCoincident","objects":["76:2:B","57:1:A"],"stage":0,"annotations":[]},{"typeId":"PCoincident","objects":["76:1:A","57:2:B"],"stage":0,"annotations":[]},{"typeId":"PointOnLine","objects":["76:1:B","57:2"],"stage":0,"annotations":[]},{"typeId":"PointOnLine","objects":["76:2:A","57:1"],"stage":0,"annotations":[]}],"generators":[]}],"constants":"","metadata":{"expressionsSignature":"1662874760956"}}} +] +} \ No newline at end of file diff --git a/modules/workbenches/modeler/index.ts b/modules/workbenches/modeler/index.ts index 4086da2d..af3e3bd8 100644 --- a/modules/workbenches/modeler/index.ts +++ b/modules/workbenches/modeler/index.ts @@ -21,6 +21,7 @@ import {PatternRadialOperation} from "./features/patternRadial/patternRadial.ope import {ImportModelOperation} from "./features/importModel/importModel.operation"; import {DeleteBodyOperation} from "./features/deleteBody/deleteBody.operation"; import {DefeatureRemoveFaceOperation} from "./features/defeatureRemoveFace/defeatureRemoveFace.operation"; +import { WireLineOperation } from "./features/wireLine/wireLine"; //imports of action type commands import {GiCubes} from "react-icons/gi"; @@ -49,6 +50,7 @@ export const ModelerWorkspace: WorkbenchConfig = { ImportModelOperation, DeleteBodyOperation, DefeatureRemoveFaceOperation, + WireLineOperation, ], actions: [ // GetVolume, @@ -67,7 +69,9 @@ export const ModelerWorkspace: WorkbenchConfig = { "CYLINDER", "BOX", "CONE", "SPHERE", "TORUS", "-", - "HOLE_TOOL", "-", 'GET_VOLUME', "IMPORT_MODEL", "DELETE_BODY", + "HOLE_TOOL", "-", 'GET_VOLUME', "IMPORT_MODEL", "DELETE_BODY", "-", + + "WIRE_LINE" ] }, icon: GiCubes