mirror of
https://github.com/xibyte/jsketcher
synced 2026-01-26 10:05:31 +01:00
working on radial pattern
This commit is contained in:
parent
b89b1b94fd
commit
6d8dc5fa69
2 changed files with 41 additions and 34 deletions
|
|
@ -1,13 +1,13 @@
|
|||
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 {roundValueForPresentation as r} from 'cad/craft/operationHelper';
|
||||
import {MFace} from "cad/model/mface";
|
||||
import {ApplicationContext} from "context";
|
||||
import {EntityKind} from "cad/model/entities";
|
||||
import Axis from "math/axis";
|
||||
import { UnitVector } from "math/vector";
|
||||
import { OperationDescriptor } from "cad/craft/operationPlugin";
|
||||
import { MShell } from 'cad/model/mshell';
|
||||
import {OperationDescriptor} from "cad/craft/operationPlugin";
|
||||
import {MShell} from 'cad/model/mshell';
|
||||
import {Matrix3x4} from "math/matrix";
|
||||
import {SetLocation} from "cad/craft/e0/interact";
|
||||
import {DEG_RAD} from "math/commons";
|
||||
|
||||
interface patternRadialParams {
|
||||
inputBodies: MShell[];
|
||||
|
|
@ -15,7 +15,7 @@ interface patternRadialParams {
|
|||
face: MFace;
|
||||
angle: number;
|
||||
qty: number;
|
||||
direction?: UnitVector,
|
||||
axis: Axis,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -24,11 +24,9 @@ export const PatternRadialOperation: OperationDescriptor<patternRadialParams> =
|
|||
label: 'Radial pattern',
|
||||
icon: 'img/cad/patternRadial',
|
||||
info: 'Creates a Radial pattern.',
|
||||
paramsInfo: ({ }) => `(${r()})`,
|
||||
paramsInfo: p => `( ${p.patternMethod} ${r(p.angle * DEG_RAD)})`,
|
||||
run: (params: patternRadialParams, ctx: ApplicationContext) => {
|
||||
|
||||
|
||||
console.log(params);
|
||||
let occ = ctx.occService;
|
||||
const oci = occ.commandInterface;
|
||||
|
||||
|
|
@ -36,15 +34,20 @@ export const PatternRadialOperation: OperationDescriptor<patternRadialParams> =
|
|||
|
||||
params.inputBodies.forEach((shellToPatern, index) => {
|
||||
for (let i = 2; i <= params.qty; i++) {
|
||||
let angleForInstance = 0;
|
||||
if(params.patternMethod == 'Step Angle') angleForInstance =params.angle*(i-1);
|
||||
if(params.patternMethod == 'Span Angle') angleForInstance =(params.angle / (params.qty-1))*(i-1);
|
||||
let angleForInstance;
|
||||
if (params.patternMethod == 'step') {
|
||||
angleForInstance = params.angle*(i-1);
|
||||
} else if (params.patternMethod == 'span') {
|
||||
angleForInstance = (params.angle / (params.qty-1))*(i-1);
|
||||
} else {
|
||||
throw 'unsupported pattern type: ' + params.patternMethod;
|
||||
}
|
||||
|
||||
//const tr = shellToPatern.location.rotate(degrees_to_radians(angleForInstance),params.direction.normalize(),params.direction.normalize());
|
||||
let tr = new Matrix3x4().rotate(degrees_to_radians(angleForInstance),params.direction.normalize(),params.direction.normalize());
|
||||
//tr = tr.rotateWithSphericalAxis(shellToPatern.location)
|
||||
|
||||
const newShellName = shellToPatern.id + ":patern/" + index + "/" +i;
|
||||
const angle = angleForInstance * DEG_RAD;
|
||||
|
||||
let tr = new Matrix3x4().rotate(angle, params.axis.direction, params.axis.origin);
|
||||
|
||||
const newShellName = shellToPatern.id + ":pattern/" + index + "/" +i;
|
||||
oci.copy(shellToPatern, newShellName);
|
||||
SetLocation(newShellName, tr.toFlatArray());
|
||||
|
||||
|
|
@ -76,8 +79,8 @@ export const PatternRadialOperation: OperationDescriptor<patternRadialParams> =
|
|||
label: 'Pattern Method',
|
||||
name: "patternMethod",
|
||||
style: "dropdown",
|
||||
defaultValue: "Step Angle",
|
||||
values: ['Step Angle', 'Span Angle',],
|
||||
defaultValue: "step",
|
||||
values: [['step', 'Step Angle'], ['span', 'Span Angle']],
|
||||
},
|
||||
{
|
||||
type: 'number',
|
||||
|
|
@ -92,17 +95,10 @@ export const PatternRadialOperation: OperationDescriptor<patternRadialParams> =
|
|||
defaultValue: 3,
|
||||
},
|
||||
{
|
||||
type: 'direction',
|
||||
name: 'direction',
|
||||
label: 'direction',
|
||||
optional: true
|
||||
type: 'axis',
|
||||
name: 'axis',
|
||||
label: 'axis',
|
||||
optional: false
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
function degrees_to_radians(degrees)
|
||||
{
|
||||
var pi = Math.PI;
|
||||
return degrees * (pi/180);
|
||||
}
|
||||
|
|
@ -4,13 +4,15 @@ import {FieldBasicProps, fieldToSchemaGeneric} from "cad/mdf/ui/field";
|
|||
import {Types} from "cad/craft/schema/types";
|
||||
import {ComboBoxOption} from "ui/components/controls/ComboBoxControl";
|
||||
|
||||
type ValueDef = [string, string] | string;
|
||||
|
||||
export interface ChoiceWidgetProps extends FieldBasicProps {
|
||||
|
||||
type: 'choice';
|
||||
|
||||
style?: 'dropdown' | 'radio';
|
||||
|
||||
values: string[];
|
||||
values: ValueDef[];
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -18,7 +20,16 @@ export function ChoiceWidget(props: ChoiceWidgetProps) {
|
|||
if (!props.style || props.style === 'dropdown') {
|
||||
|
||||
return <ComboBoxField name={props.name} defaultValue={props.defaultValue} label={props.label} includeNonExistent>
|
||||
{props.values.map(value => <ComboBoxOption value={value} key={value}>{value}</ComboBoxOption>)}
|
||||
{props.values.map((value: any) => {
|
||||
let val, name;
|
||||
if (Array.isArray(value)) {
|
||||
[val, name] = value;
|
||||
} else {
|
||||
val = value;
|
||||
name = value;
|
||||
}
|
||||
return <ComboBoxOption value={val} key={val}>{name}</ComboBoxOption>
|
||||
})}
|
||||
</ComboBoxField>;
|
||||
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue