mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 17:04:58 +01:00
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import {MShell} from 'cad/model/mshell';
|
|
import {roundValueForPresentation as r} from 'cad/craft/operationHelper';
|
|
import {ApplicationContext} from "context";
|
|
import {EntityKind} from "cad/model/entities";
|
|
import {OperationDescriptor} from "cad/craft/operationPlugin";
|
|
|
|
|
|
interface scaleParams {
|
|
distance: number;
|
|
shells: [MShell];
|
|
}
|
|
|
|
export const ScaleOperation: OperationDescriptor<scaleParams> = {
|
|
id: 'SCALE_BODY',
|
|
label: 'Scale',
|
|
icon: 'img/cad/scale',
|
|
info: 'Scale Body',
|
|
paramsInfo: ({ distance }) => `(${r(distance)})`,
|
|
run: (params: scaleParams, ctx: ApplicationContext) => {
|
|
let occ = ctx.occService;
|
|
const oci = occ.commandInterface;
|
|
|
|
const returnObject = {
|
|
consumed: params.shells,
|
|
created: []
|
|
};
|
|
|
|
params.shells.forEach((currentShell) => {
|
|
const newShellId = currentShell.id + ":scaled";
|
|
oci.copy(currentShell, newShellId);
|
|
oci.tscale(newShellId, currentShell.csys.x, currentShell.csys.y, currentShell.csys.z, params.distance);
|
|
returnObject.created.push(occ.io.getShell(newShellId));
|
|
});
|
|
|
|
return returnObject;
|
|
|
|
},
|
|
form: [
|
|
{
|
|
type: 'selection',
|
|
name: 'shells',
|
|
capture: [EntityKind.SHELL],
|
|
label: 'shells',
|
|
multi: true,
|
|
defaultValue: {
|
|
usePreselection: true,
|
|
preselectionIndex: 0
|
|
},
|
|
},
|
|
{
|
|
type: 'number',
|
|
name: 'distance',
|
|
label: 'distance',
|
|
defaultValue: 5,
|
|
},
|
|
],
|
|
}
|