mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-08 01:13:27 +01:00
support enum fields
This commit is contained in:
parent
9bb8c8c012
commit
db3dd8dadf
7 changed files with 40 additions and 7 deletions
|
|
@ -33,6 +33,19 @@ export default {
|
|||
defaultValue: 150
|
||||
}
|
||||
},
|
||||
color: {
|
||||
type: 'enum',
|
||||
options: [
|
||||
{
|
||||
label: 'Red',
|
||||
value: 'red'
|
||||
},
|
||||
{
|
||||
label: 'Green',
|
||||
value: 'green'
|
||||
}
|
||||
]
|
||||
},
|
||||
run: ({ width, height, thickness }, ctx: ApplicationContext) => {
|
||||
const occObj = createOCCBottle(width, height, thickness, ctx.occService.occContext);
|
||||
const mobject = new MBrepShell(occ2brep(occObj, ctx.occService.occContext));
|
||||
|
|
@ -40,5 +53,5 @@ export default {
|
|||
consumed: [],
|
||||
created: [mobject]
|
||||
};
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,24 @@ import { ApplicationContext } from 'context';
|
|||
import { MBrepShell } from 'cad/model/mshell';
|
||||
import { roundValueForPresentation as r } from 'cad/craft/operationHelper';
|
||||
import { occ2brep } from 'cad/occ/occ2models';
|
||||
import icon from './icon.svg';
|
||||
import icon32 from './icon32.png';
|
||||
import icon96 from './icon96.png';
|
||||
|
||||
export default {
|
||||
id: 'primitive_cone',
|
||||
label: 'primitive_cone',
|
||||
icon,
|
||||
icon: {
|
||||
iconSet: {
|
||||
medium: {
|
||||
iconType: 'image',
|
||||
iconContent: icon32
|
||||
},
|
||||
large: {
|
||||
iconType: 'image',
|
||||
iconContent: icon96
|
||||
}
|
||||
},
|
||||
},
|
||||
info: 'primitive_cone',
|
||||
mutualExclusiveFields: [],
|
||||
paramsInfo: ({ diameter_A, diameter_B, height }) => `(${r(diameter_A)} ${r(diameter_A)} ${r(height)})`,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export function ToolbarActionButtons({actions, showTitles, size}) {
|
|||
});
|
||||
}
|
||||
|
||||
function ActionButton({label, icon, icon96, icon32, cssIcons, symbol, size, noLabel, enabled, visible, actionId, ...props}) {
|
||||
function ActionButton({label, icon, icon96, icon32, cssIcons, symbol, size = 'large', noLabel, enabled, visible, actionId, ...props}) {
|
||||
if (!visible) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ function IconSet(props: IconRenderProps & IconSetDef & React.HTMLAttributes<HTML
|
|||
|
||||
const {iconSet} = props;
|
||||
|
||||
let iconDef = iconSet[props.size] | iconSet[IconSize.large] | iconSet[IconSize.medium] | iconSet[IconSize.small]
|
||||
let iconDef = iconSet[props.size] || iconSet[IconSize.large] || iconSet[IconSize.medium] || iconSet[IconSize.small];
|
||||
|
||||
return <Icon {...iconDef} {...props} />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import React from 'react';
|
||||
import { ComboBoxOption } from 'ui/components/controls/ComboBoxControl';
|
||||
import Entity from '../craft/wizard/components/form/Entity';
|
||||
import { CheckboxField, NumberField, ComboBoxField, TextField} from '../craft/wizard/components/form/Fields';
|
||||
import { Group } from '../craft/wizard/components/form/Form';
|
||||
|
|
@ -19,6 +20,12 @@ export function generateForm(schema: OperationSchema) {
|
|||
return <TextField name={key} label={label} />;
|
||||
} else if (['face', 'edge', 'sketchObject', 'datumAxis'].includes(fieldDef.type)) {
|
||||
return <Entity name={key} label={label} />;
|
||||
} else if (fieldDef.type === 'enum') {
|
||||
return <ComboBoxField name={key} label={label}>
|
||||
{fieldDef.options.map(opt => <ComboBoxOption key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</ComboBoxOption>)}
|
||||
</ComboBoxField>
|
||||
} else if (fieldDef.type === 'boolean') {
|
||||
return <CheckboxField name={key} label={label} />;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ export type OperationSchema = {
|
|||
};
|
||||
|
||||
export interface SchemaField {
|
||||
type: 'number' | 'face' | 'datumAxis' | 'edge' | 'sketchObject' | 'boolean'
|
||||
type: 'number' | 'face' | 'datumAxis' | 'edge' | 'sketchObject' | 'boolean' | 'enum'
|
||||
options: string[] | number[],
|
||||
defaultValue: Coercable,
|
||||
optional: boolean,
|
||||
label?: string
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { AiOutlineQuestion } from 'react-icons/ai';
|
|||
import { IconType } from 'react-icons/lib';
|
||||
|
||||
export function resolveMDFIcon(iconDef: IconDeclaration | IconType) {
|
||||
if (iconDef.iconType) {
|
||||
if (iconDef.iconType || iconDef.iconSet) {
|
||||
return (props) => <DeclaredIcon {...iconDef} {...props}/>
|
||||
} else {
|
||||
if (!iconDef || typeof(iconDef) !== 'object') {
|
||||
|
|
|
|||
Loading…
Reference in a new issue