mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 16:33:15 +01:00
112 lines
2.9 KiB
TypeScript
112 lines
2.9 KiB
TypeScript
import {roundValueForPresentation as r} from 'cad/craft/operationHelper';
|
|
import {MFace} from "cad/model/mface";
|
|
import {ApplicationContext} from "context";
|
|
import {EntityKind} from "cad/model/entities";
|
|
import {BooleanDefinition} from "cad/craft/schema/common/BooleanDefinition";
|
|
import Axis from "math/axis";
|
|
import {OperationDescriptor} from "cad/craft/operationPlugin";
|
|
import { Edge } from "brep/topo/edge";
|
|
import { FaceRef } from "cad/craft/e0/OCCUtils";
|
|
import { GetRef } from "cad/craft/e0/interact";
|
|
import {
|
|
FromMObjectProductionAnalyzer,
|
|
FromSketchProductionAnalyzer,
|
|
ProductionAnalyzer
|
|
} from "cad/craft/production/productionAnalyzer";
|
|
|
|
interface RevolveParams {
|
|
angle: number;
|
|
face: MFace;
|
|
axis: Axis,
|
|
boolean: BooleanDefinition
|
|
}
|
|
|
|
export const RevolveOperation: OperationDescriptor<RevolveParams> = {
|
|
id: 'REVOLVE',
|
|
label: 'Revolve',
|
|
icon: 'img/cad/revolve',
|
|
info: 'Revolves 2D sketch',
|
|
paramsInfo: ({angle}) => `(${r(angle)})`,
|
|
run: (params: RevolveParams, ctx: ApplicationContext) => {
|
|
console.log(params);
|
|
let occ = ctx.occService;
|
|
const oci = occ.commandInterface;
|
|
|
|
const face = params.face;
|
|
|
|
let sketchId = face.id;
|
|
let sketch = ctx.sketchStorageService.readSketch(sketchId);
|
|
|
|
|
|
let sweepSources: FaceRef[];
|
|
|
|
if (!sketch) {
|
|
if (face instanceof MBrepFace) {
|
|
occ.io.pushModel(face, face.id)
|
|
const edges = face.edges;
|
|
edges.forEach(e => occ.io.pushModel(e, e.id));
|
|
sweepSources = [{
|
|
face: face.id,
|
|
edges: edges.map(e => e.id)
|
|
}];
|
|
} else {
|
|
throw "can't extrude an empty surface";
|
|
}
|
|
} else {
|
|
let csys = face.csys;
|
|
if (params.doubleSided) {
|
|
csys = csys.clone();
|
|
csys.origin._minus(extrusionVector);
|
|
extrusionVector._scale(2);
|
|
}
|
|
sweepSources = occ.utils.sketchToFaces(sketch, csys)
|
|
}
|
|
|
|
const productionAnalyzer = new FromSketchProductionAnalyzer(sweepSources);
|
|
|
|
const tools = sweepSources.map((faceRef, i) => {
|
|
const faceName = faceRef.face;
|
|
const shapeName = "Tool/" + i;
|
|
var args = [shapeName, faceName, ...params.axis.origin.data(), ...params.axis.direction.data(), params.angle];
|
|
oci.revol(...args);
|
|
|
|
return shapeName;
|
|
});
|
|
|
|
return occ.utils.applyBooleanModifier(tools, params.boolean, productionAnalyzer, [face]);
|
|
|
|
},
|
|
form: [
|
|
{
|
|
type: 'number',
|
|
label: 'angle',
|
|
name: 'angle',
|
|
defaultValue: 360,
|
|
},
|
|
{
|
|
type: 'selection',
|
|
name: 'face',
|
|
capture: [EntityKind.FACE],
|
|
label: 'face',
|
|
multi: false,
|
|
defaultValue: {
|
|
usePreselection: true,
|
|
preselectionIndex: 0
|
|
},
|
|
},
|
|
{
|
|
type: 'axis',
|
|
name: 'axis',
|
|
label: 'axis',
|
|
optional: false
|
|
},
|
|
{
|
|
type: 'boolean',
|
|
name: 'boolean',
|
|
label: 'boolean',
|
|
optional: true,
|
|
defaultValue: 'NONE'
|
|
}
|
|
|
|
],
|
|
}
|