code cleanup

This commit is contained in:
Val Erastov 2022-08-12 23:54:10 -07:00
parent 3bcbc4125b
commit f0310522b4
13 changed files with 30 additions and 65 deletions

View file

@ -19,7 +19,6 @@ export const OCCBottle:OperationDescriptor<any> = {
run: ({width, height, thickness, color}, ctx: ApplicationContext) => { run: ({width, height, thickness, color}, ctx: ApplicationContext) => {
const occObj = createOCCBottle(width, height, thickness, ctx.occService.occContext); const occObj = createOCCBottle(width, height, thickness, ctx.occService.occContext);
const mobject = new MBrepShell(occ2brep(occObj, ctx.occService.occContext)); const mobject = new MBrepShell(occ2brep(occObj, ctx.occService.occContext));
console.log(color);
return { return {
consumed: [], consumed: [],
created: [mobject] created: [mobject]

View file

@ -25,8 +25,6 @@ export const FilletOperation: OperationDescriptor<any> = {
const occ = ctx.occService; const occ = ctx.occService;
const oci = occ.commandInterface; const oci = occ.commandInterface;
console.log(params.edges);
//add all the edges and size to seperate arrays for each shell that edges are selected from //add all the edges and size to seperate arrays for each shell that edges are selected from
const groups = new Map<MShell, any[]>() const groups = new Map<MShell, any[]>()
@ -69,8 +67,6 @@ export const FilletOperation: OperationDescriptor<any> = {
result.created.push(occ.io.getShell(newShellName, analyzer)); result.created.push(occ.io.getShell(newShellName, analyzer));
}); });
console.log(result);
return result; return result;
}, },
form: [ form: [

View file

@ -33,11 +33,10 @@ export const HoleOperation: OperationDescriptor<HoleParams> = {
}) => `(${r(depth)} ${r(counterBoreDiameter)}) ${r(counterBoreDepth)})`, }) => `(${r(depth)} ${r(counterBoreDiameter)}) ${r(counterBoreDepth)})`,
run: (params: HoleParams, ctx: ApplicationContext) => { run: (params: HoleParams, ctx: ApplicationContext) => {
console.log(params);
let occ = ctx.occService; let occ = ctx.occService;
const oci = occ.commandInterface; const oci = occ.commandInterface;
var returnObject = { const returnObject = {
consumed: [], consumed: [],
created: [] created: []
}; };
@ -45,7 +44,6 @@ export const HoleOperation: OperationDescriptor<HoleParams> = {
//let sketch = ctx.sketchStorageService.readSketch(params.sketch.id); //let sketch = ctx.sketchStorageService.readSketch(params.sketch.id);
//console.log(sketch, "sketch info here"); //console.log(sketch, "sketch info here");
oci.pcylinder("result", params.diameter / 2, params.depth); oci.pcylinder("result", params.diameter / 2, params.depth);
// if (params.holeType == "normal") { // if (params.holeType == "normal") {

View file

@ -30,7 +30,6 @@ export const ImportModelOpperation: OperationDescriptor<ImportModelParams> = {
if (FileName.endsWith("BRP") || FileName.endsWith("BREP")) { if (FileName.endsWith("BRP") || FileName.endsWith("BREP")) {
//FreeCAD some times omits this text from the top of BRP files //FreeCAD some times omits this text from the top of BRP files
//as part of the brp files stored in the .FCStf file archive format //as part of the brp files stored in the .FCStf file archive format
console.log(rawContent);
if (!rawContent.startsWith("DBRep_DrawableShape")) { if (!rawContent.startsWith("DBRep_DrawableShape")) {
rawContent = `DBRep_DrawableShape\n` + rawContent; rawContent = `DBRep_DrawableShape\n` + rawContent;
} }
@ -65,9 +64,8 @@ export const ImportModelOpperation: OperationDescriptor<ImportModelParams> = {
FS.writeFile(importBrepShapeName, `DBRep_DrawableShape\n` + zipContent); FS.writeFile(importBrepShapeName, `DBRep_DrawableShape\n` + zipContent);
oci.readbrep(importBrepShapeName, importBrepShapeName); oci.readbrep(importBrepShapeName, importBrepShapeName);
returnObject.created.push(occ.io.getShell(importBrepShapeName)); returnObject.created.push(occ.io.getShell(importBrepShapeName));
console.log(importBrepShapeName);
} catch (e) { } catch (e) {
console.log(e) console.warn(e)
} }
} }
} }

View file

@ -28,8 +28,6 @@ export const LoftOperation: OperationDescriptor<LoftParams> = {
if (params.loftType == "smooth") loftType = 0; if (params.loftType == "smooth") loftType = 0;
if (params.loftType == "sharp") loftType = 1; if (params.loftType == "sharp") loftType = 1;
//console.log(params.loops);
let sketches = []; let sketches = [];
const wires = params.loops.map((loop, i) => { const wires = params.loops.map((loop, i) => {
@ -39,16 +37,13 @@ export const LoftOperation: OperationDescriptor<LoftParams> = {
return occ.io.sketchLoader.pushContourAsWire(loop.contour, shapeName, loop.face.csys).wire return occ.io.sketchLoader.pushContourAsWire(loop.contour, shapeName, loop.face.csys).wire
}); });
//console.log("This is the info you are looking for", sketches);
let sweepSources = []; let sweepSources = [];
let indexOfMostSegments = 0; let indexOfMostSegments = 0;
let longestPath = 0; let longestPath = 0;
let primarySketch = {}; let primarySketch = {};
sketches.forEach(function (item, index) { sketches.forEach((item, index) => {
//console.log(item, index);
if(params.loops[index].contour.segments.length > longestPath){ if(params.loops[index].contour.segments.length > longestPath){
longestPath = params.loops[index].contour.segments.length; longestPath = params.loops[index].contour.segments.length;

View file

@ -18,7 +18,6 @@ export const MirrorBodyOperation: OperationDescriptor<MirrorBodyParams> = {
info: 'Mirrors selected body along plane of symytry.', info: 'Mirrors selected body along plane of symytry.',
paramsInfo: ({ }) => `(${r()})`, paramsInfo: ({ }) => `(${r()})`,
run: (params: MirrorBodyParams, ctx: ApplicationContext) => { run: (params: MirrorBodyParams, ctx: ApplicationContext) => {
console.log(params);
let occ = ctx.occService; let occ = ctx.occService;
const oci = occ.commandInterface; const oci = occ.commandInterface;

View file

@ -27,7 +27,6 @@ export const PatternLinearOperation: OperationDescriptor<patternLinearParams> =
info: 'Creates a linear pattern.', info: 'Creates a linear pattern.',
paramsInfo: ({ }) => `(?)`, paramsInfo: ({ }) => `(?)`,
run: (params: patternLinearParams, ctx: ApplicationContext) => { run: (params: patternLinearParams, ctx: ApplicationContext) => {
console.log(params);
let occ = ctx.occService; let occ = ctx.occService;
const oci = occ.commandInterface; const oci = occ.commandInterface;

View file

@ -29,7 +29,6 @@ export const RevolveOperation: OperationDescriptor<RevolveParams> = {
info: 'Revolves 2D sketch', info: 'Revolves 2D sketch',
paramsInfo: ({angle}) => `(${r(angle)})`, paramsInfo: ({angle}) => `(${r(angle)})`,
run: (params: RevolveParams, ctx: ApplicationContext) => { run: (params: RevolveParams, ctx: ApplicationContext) => {
console.log(params);
let occ = ctx.occService; let occ = ctx.occService;
const oci = occ.commandInterface; const oci = occ.commandInterface;
@ -42,7 +41,7 @@ export const RevolveOperation: OperationDescriptor<RevolveParams> = {
if (!sketch) { if (!sketch) {
if (face instanceof MBrepFace) { if (face instanceof MBrepFace) {
var args = ["FaceTool", face, ...params.axis.origin.data(), ...params.axis.direction.data(), params.angle]; const args = ["FaceTool", face, ...params.axis.origin.data(), ...params.axis.direction.data(), params.angle];
oci.revol(...args); oci.revol(...args);
return occ.utils.applyBooleanModifier([occ.io.getShell("FaceTool")], params.boolean, face, [], return occ.utils.applyBooleanModifier([occ.io.getShell("FaceTool")], params.boolean, face, [],
(targets, tools) => new FromMObjectProductionAnalyzer(targets, [face])); (targets, tools) => new FromMObjectProductionAnalyzer(targets, [face]));
@ -60,7 +59,7 @@ export const RevolveOperation: OperationDescriptor<RevolveParams> = {
const tools = sweepSources.map((faceRef, i) => { const tools = sweepSources.map((faceRef, i) => {
const faceName = faceRef.face; const faceName = faceRef.face;
const shapeName = "Tool/" + i; const shapeName = "Tool/" + i;
var args = [shapeName, faceName, ...params.axis.origin.data(), ...params.axis.direction.data(), params.angle]; const args = [shapeName, faceName, ...params.axis.origin.data(), ...params.axis.direction.data(), params.angle];
oci.revol(...args); oci.revol(...args);
return shapeName; return shapeName;
}).map(shapeName => occ.io.getShell(shapeName, productionAnalyzer)); }).map(shapeName => occ.io.getShell(shapeName, productionAnalyzer));

View file

@ -1,7 +1,5 @@
import { CSys } from 'math/csys';
import {MShell} from 'cad/model/mshell'; import {MShell} from 'cad/model/mshell';
import {roundValueForPresentation as r} from 'cad/craft/operationHelper'; import {roundValueForPresentation as r} from 'cad/craft/operationHelper';
import { MFace } from "cad/model/mface";
import {ApplicationContext} from "context"; import {ApplicationContext} from "context";
import {EntityKind} from "cad/model/entities"; import {EntityKind} from "cad/model/entities";
import {OperationDescriptor} from "cad/craft/operationPlugin"; import {OperationDescriptor} from "cad/craft/operationPlugin";
@ -19,16 +17,14 @@ export const ScaleOperation: OperationDescriptor<scaleParams> = {
info: 'Scale Body', info: 'Scale Body',
paramsInfo: ({ distance }) => `(${r(distance)})`, paramsInfo: ({ distance }) => `(${r(distance)})`,
run: (params: scaleParams, ctx: ApplicationContext) => { run: (params: scaleParams, ctx: ApplicationContext) => {
console.log(params);
let occ = ctx.occService; let occ = ctx.occService;
const oci = occ.commandInterface; const oci = occ.commandInterface;
var returnObject = { const returnObject = {
consumed: params.shells, consumed: params.shells,
created: [] created: []
}; };
params.shells.forEach((currentShell) => { params.shells.forEach((currentShell) => {
const newShellId = currentShell.id + ":scaled"; const newShellId = currentShell.id + ":scaled";
oci.copy(currentShell, newShellId); oci.copy(currentShell, newShellId);
@ -36,9 +32,6 @@ export const ScaleOperation: OperationDescriptor<scaleParams> = {
returnObject.created.push(occ.io.getShell(newShellId)); returnObject.created.push(occ.io.getShell(newShellId));
}); });
console.log(returnObject);
return returnObject; return returnObject;
}, },

View file

@ -17,13 +17,12 @@ export const ShellOperation: OperationDescriptor<ShellParams> = {
info: 'Shells 2D sketch', info: 'Shells 2D sketch',
paramsInfo: ({thickness}) => `(${r(thickness)})`, paramsInfo: ({thickness}) => `(${r(thickness)})`,
run: (params: ShellParams, ctx: ApplicationContext) => { run: (params: ShellParams, ctx: ApplicationContext) => {
console.log(params);
let occ = ctx.occService; let occ = ctx.occService;
const oci = occ.commandInterface; const oci = occ.commandInterface;
var bodiesToShell = []; const bodiesToShell = [];
var returnObject = { const returnObject = {
consumed: [], consumed: [],
created: [] created: []
}; };
@ -41,20 +40,15 @@ export const ShellOperation: OperationDescriptor<ShellParams> = {
//perform the opperations on each of the bodies. //perform the opperations on each of the bodies.
Object.keys(bodiesToShell).forEach((shellToOpperateOnName) => { Object.keys(bodiesToShell).forEach((shellToOpperateOnName) => {
var shellToOpperateOn = bodiesToShell[shellToOpperateOnName]; const shellToOpperateOn = bodiesToShell[shellToOpperateOnName];
var newShellName = shellToOpperateOnName + "f"; const newShellName = shellToOpperateOnName + "f";
console.log(shellToOpperateOn); const bodyToPerformShellOpperationOn = shellToOpperateOn[0].shell;
var bodyToPerformShellOpperationOn = shellToOpperateOn[0].shell;
oci.offsetcompshape(newShellName, bodyToPerformShellOpperationOn, -params.thickness, "1.e-3", ...shellToOpperateOn) oci.offsetcompshape(newShellName, bodyToPerformShellOpperationOn, -params.thickness, "1.e-3", ...shellToOpperateOn)
returnObject.created.push(occ.io.getShell(newShellName)); returnObject.created.push(occ.io.getShell(newShellName));
}); });
console.log(returnObject);
return returnObject; return returnObject;
}, },
form: [ form: [
{ {

View file

@ -20,7 +20,6 @@ export const smFlangeOperation: OperationDescriptor<smFlangeParams> = {
info: 'Creates Sheet metal flange', info: 'Creates Sheet metal flange',
paramsInfo: ({ angle }) => `(${r(angle)})`, paramsInfo: ({ angle }) => `(${r(angle)})`,
run: (params: smFlangeParams, ctx: ApplicationContext) => { run: (params: smFlangeParams, ctx: ApplicationContext) => {
console.log(params);
let occ = ctx.occService; let occ = ctx.occService;
const oci = occ.commandInterface; const oci = occ.commandInterface;
@ -33,7 +32,6 @@ export const smFlangeOperation: OperationDescriptor<smFlangeParams> = {
for (let i = 0; i < face.edges.length; i++) { for (let i = 0; i < face.edges.length; i++) {
const edgeKind = face.edges[i].productionInfo.sheetMetal.kind; const edgeKind = face.edges[i].productionInfo.sheetMetal.kind;
console.log(edgeKind);
if (edgeKind == "FLAT/A" && !params.flip) { if (edgeKind == "FLAT/A" && !params.flip) {
revolveVector = face.edges[i].toAxis(); revolveVector = face.edges[i].toAxis();
revolveVectorOrigin = revolveVector.origin; revolveVectorOrigin = revolveVector.origin;
@ -48,7 +46,6 @@ export const smFlangeOperation: OperationDescriptor<smFlangeParams> = {
} }
} }
console.log(revolveVectorOrigin);
//revolveVectorOrigin.y -=0; //revolveVectorOrigin.y -=0;
//revolveVectorOrigin.z +=2; //revolveVectorOrigin.z +=2;
@ -65,24 +62,19 @@ export const smFlangeOperation: OperationDescriptor<smFlangeParams> = {
targets: [params.face.shell] targets: [params.face.shell]
} }
console.log(params.face.shell); tools[0].edges.forEach((newEdge) => {
params.face.shell.edges.forEach((edgeToLookAt) => {
tools[0].edges.forEach(async (newEdge) => {
params.face.shell.edges.forEach(async (edgeToLookAt) => {
if (JSON.stringify(newEdge.topology.data.tessellation) == JSON.stringify(edgeToLookAt.topology.data.tessellation)) { if (JSON.stringify(newEdge.topology.data.tessellation) == JSON.stringify(edgeToLookAt.topology.data.tessellation)) {
console.log("We have a match", edgeToLookAt.productionInfo.sheetMetal.kind); console.debug("We have a match", edgeToLookAt.productionInfo.sheetMetal.kind);
newEdge.productionInfo ={}; newEdge.productionInfo ={};
newEdge.productionInfo = {sheetMetal: {kind: edgeToLookAt.productionInfo.sheetMetal.kind}}; newEdge.productionInfo = {sheetMetal: {kind: edgeToLookAt.productionInfo.sheetMetal.kind}};
//newEdge.productionInfo.sheetMetal.kind = edgeToLookAt.productionInfo.sheetMetal.kind; //newEdge.productionInfo.sheetMetal.kind = edgeToLookAt.productionInfo.sheetMetal.kind;
console.log(newEdge, edgeToLookAt); console.debug(newEdge, edgeToLookAt);
console.log(newEdge.productionInfo); console.debug(newEdge.productionInfo);
} }
}); });
}); });
//return occ.utils.applyBooleanModifier(tools, booleanOperation);
return { return {
created: tools, created: tools,
consumed: [] consumed: []

View file

@ -33,15 +33,14 @@ export const smTabOperation: OperationDescriptor<smTabParams> = {
run: (params: smTabParams, ctx: ApplicationContext) => { run: (params: smTabParams, ctx: ApplicationContext) => {
let occ = ctx.occService; let occ = ctx.occService;
console.log(ctx.craftService.modifications$.value.history);
const oci = occ.commandInterface; const oci = occ.commandInterface;
const face = params.sketch; const face = params.sketch;
let sketch = ctx.sketchStorageService.readSketch(face.id); let sketch = ctx.sketchStorageService.readSketch(face.id);
if (!sketch) throw 'sketch not found for the face ' + face.id; if (!sketch) {
throw 'sketch not found for the face ' + face.id;
}
const occFaces = occ.utils.sketchToFaces(sketch, face.csys); const occFaces = occ.utils.sketchToFaces(sketch, face.csys);

View file

@ -13,6 +13,7 @@ import {EntityKind} from "cad/model/entities";
import {Matrix3x4} from "math/matrix"; import {Matrix3x4} from "math/matrix";
import {TopoObject} from "brep/topo/topo-object"; import {TopoObject} from "brep/topo/topo-object";
import Axis from "math/axis"; import Axis from "math/axis";
import {MEdge} from "cad/model/medge";
export class MFace extends MObject { export class MFace extends MObject {
@ -180,6 +181,9 @@ export class MFace extends MObject {
return this.brepFace; return this.brepFace;
} }
get edges(): MEdge[] {
return [];
}
} }
export class MBrepFace extends MFace { export class MBrepFace extends MFace {
@ -192,7 +196,7 @@ export class MBrepFace extends MFace {
this.brepFace = brepFace; this.brepFace = brepFace;
} }
get edges() { get edges(): MEdge[] {
let out = []; let out = [];
for (let he of this.brepFace.edges) { for (let he of this.brepFace.edges) {
let edge = (this.shell as MBrepShell).brepRegistry.get(he.edge); let edge = (this.shell as MBrepShell).brepRegistry.get(he.edge);