Replies: 5 comments 10 replies
-
Where will this attribute information live? Will it just be in the CadHub database, or will it be attached to the model script somehow? |
Beta Was this translation helpful? Give feedback.
-
Thanks @hrgdavor, very comprehensive. I like the 'depends on' concept. 👍 I don't like the enums been represented by an array of values and labels separately, I think it makes for an awkward authoring experience. Essentially it's a list of key-values I think and object makes more sense. Although would be happy to support both an object or an array for strings in case you don't want to have separate labels for the strings-types. {
numName1: 1,
numName2: 2,
}
{
strName1: 'str1',
strName2: 'str2',
}
[
'str1',
'str2',
] To make sure I was thinking about it correctly I wrote demo code, but really it was mostly typescript types, I'm still struggling with the difference between int and decimal and I think that we should just have a number type that automatically becomes an int if the step and initial value is divisible by one. The following snippets are here https://github.com/Irev-Dev/cadhub/blob/kurt/cadhub-customizer-test-code-437/app/web/src/components/Customizer/customizerConverter.ts So here is my implementation of types for Hrg's work above. At this point I'm only supporting number strings and booleans, and I'm not implemented anything for groups, input parameter, or any type of select/enum to begin with. type CadhubTypeNames = 'int' | 'decimal' | 'string' | 'boolean'
interface CadhubParamBase {
type: CadhubTypeNames
caption: string
name: string
}
interface CadhubStringParam extends CadhubParamBase {
type: 'string'
initial: string
placeholder?: string
maxLength?: number
}
interface CadhubBooleanParam extends CadhubParamBase {
type: 'boolean'
initial?: boolean
}
interface CadhubNumberBase extends CadhubParamBase {
initial: number
min?: number
max?: number
step?: number
}
interface CadhubDecimalParam extends CadhubNumberBase {
type: 'decimal'
decimal?: number
}
interface CadhubIntParam extends CadhubNumberBase {
type: 'int'
}
type CadhubParams = CadhubStringParam | CadhubBooleanParam | CadhubDecimalParam | CadhubIntParam Likewise the following is an example of typing for JSCAD with an example convert function, with example input output for a subset of Params // JSCAD
type JscadTypeNames = 'group' | 'text' | 'int' | 'number' | 'slider' | 'email' | 'password' | 'date' | 'url' | 'checkbox' | 'color' | 'choice' | 'radio'
interface JscadParamBase {
type: JscadTypeNames
caption: string
name: string
}
interface JscadGroupParam extends JscadParamBase {
type: 'group'
initial?: 'open' | 'closed'
}
interface JscadTextParam extends JscadParamBase {
type: 'text'
initial: string
placeholder: string
size: number
maxLength: number
}
interface JscadIntNumberSliderParam extends JscadParamBase {
type: 'int' | 'number' | 'slider'
initial: number
min?: number
max?: number
step?: number
}
interface JscadDateParam extends JscadParamBase {
type: 'date'
initial: string
min: string
max: string
placeholder: string
}
interface JscadEmailPasswordColorParam extends JscadParamBase {
type: 'email' | 'password' | 'color'
initial: string
}
interface JscadUrlParam extends JscadParamBase {
type: 'url'
initial: string
maxLength: number
size: number
placeholder: string
}
interface JscadCheckboxParam extends JscadParamBase {
type: 'checkbox'
checked: boolean
initial: boolean
}
interface JscadChoiceRadioParam extends JscadParamBase {
type: 'choice' | 'radio'
initial: number | string
values: (string | number)[]
captions?: string[]
}
type JsCadParams = JscadGroupParam | JscadTextParam | JscadIntNumberSliderParam | JscadDateParam | JscadEmailPasswordColorParam | JscadUrlParam | JscadCheckboxParam | JscadChoiceRadioParam
jsCadToCadhubParams([
{ type:'slider', name:'length', initial:340, caption:'Length', min:210, max:1500},
{ name: 'text', type: 'text', initial: '', size: 20, maxLength: 20, caption: 'Plain Text:', placeholder: '20 characters' },
{ name: 'int', type: 'int', initial: 20, min: 1, max: 100, step: 1, caption: 'Integer:' },
{ name: 'number', type: 'number', initial: 2.0, min: 1.0, max: 10.0, step: 0.1, caption: 'Number:' },
{ name: 'date', type: 'date', initial: '2020-01-01', min: '2020-01-01', max: '2030-12-31', caption: 'Date:', placeholder: 'YYYY-MM-DD' },
{ name: 'checkbox', type: 'checkbox', checked: true, initial: true, caption: 'Checkbox:' },
])
function jsCadToCadhubParams(input: JsCadParams[]): CadhubParams[] {
// do some magic
return [
{ type: 'decimal', name:'length', initial:340, caption:'Length', min:210, max:1500},
{ name: 'text', type: 'string', initial: '', maxLength: 20, caption: 'Plain Text:', placeholder: '20 characters' },
{ name: 'int', type: 'int', initial: 20, min: 1, max: 100, step: 1, caption: 'Integer:' },
{ name: 'number', type: 'decimal', initial: 2.0, min: 1.0, max: 10.0, step: 0.1, caption: 'Number:' },
{ name: 'date', type: 'string', initial: '2020-01-01', caption: 'Date:', placeholder: 'YYYY-MM-DD' },
{ name: 'checkbox', type: 'boolean', initial: true, caption: 'Checkbox:' },
]
} For the OpenSCAD meta data output, I think it should all be able to fit into what's been outlined above, so I put together a little example openscad/openscad#3801. Although it's neglecting groups and that the reports for the time being. |
Beta Was this translation helpful? Give feedback.
-
added section for presets. I like this idea, and have been thinking about it for a while. Sby else mentioned this, so I decided it is worth defining here. Preset
|
Beta Was this translation helpful? Give feedback.
-
Hey everyone, to me it seems as if a lot of effort is invested in a customizer. |
Beta Was this translation helpful? Give feedback.
-
@jmwright, the short version is:
More details: The discussion above is mostly what the final shape for the customizer metadata should be for Cadhub internally, however it doesn't need to match the output of each package exactly since we can't really expect that, so we have a function for each package that converts it to the Cadhub structure, though of course the closer it matches, the simpler that conversion function will be, for reference the converting function are in these files for OpenSCAD and JSCAD, but that's something I'll handle anyway for CQ. In terms of what the CadHub param data structure is this file is the source of truth, but that's a bunch of typescript types not not easy to parse instead here's an example: This OpenSCAD code: // slider widget for number in range
sliderWithRange = 34; // [10:100]
// step slider for number
stepSlider = 2; // [0:5:100]
// slider widget for number in range
sliderCentered = 0; // [-10:0.1:10]
// Text box for string
string="hello";
// description for boolean
boolVariable = true;
// List selection with numbers
listOfNumbers = 3; // [1,3,5,7]
// List selection with numbers with labels
listOfNumbersWithLabels = 3; // [1:One,3:Three,5:Five,7:Seven] gets transformed to:
and like wise the params we feed back into OpenSCAD for the above is:
Is that enough information, anything unclear? |
Beta Was this translation helpful? Give feedback.
-
Top level object
Integrations would extract their parameter definitions and convert them to this format so UI can be displayed.
Attributes of the main document
title
- title for the scriptparameters
- list of [Parameter|Group] (defined in Group and Parameter section)presets
- a list of preset combinations of values for the parameters, so author can provide interesting combinations as additional showcase of the script posibilitiesdefinition for groups is yet to be decided
Preset
name
- name of the parameter combinationvalues
- object with key:value to fill the customizerGroup
This is a special type of parameter that defines a group of inputs that is usualy expandable in the UI to reduce the clutter when there is a long list of parameters.
type="group"
caption
- caption for the grouphint
- longer descriptive info about the group (like ? tooltip)initial
- [open|closed]for now, there is no hierarchy defined structurally (like a children property). If one of the parameters is a group those after it are part of that group
Parameter
Format for single parameter.
list of attributes
This is a list of attributes that define a parameter, but not all are used for every parameter type
Bare minimum
type
- actual data type UI should return, and also used to decide on default UIinitial
- initial value (also used to reset the form)name
- name of the parameter used in the scriptMinumum to support enums (select box)
options
- a list of values for enum can be and array of enum values, or object that is interpreted{enumValue:enumLabel}
A label with more descriptive name of the parameter and a hint/tooltip
caption
- Displayed name in the IU (name is used as fallback)hint
- longer descriptive info about the parameter (like ? tooltip)Extended options for different types of input elements
min
- for numerical typesmax
- for numerical typesstep
- for numerical typesdecimals
- number of decimals for floating point numbers (int
implies 0 decimals)maxLength
- maximum length for string typeinput
- author can use this hint to ask for different UI (slider for numbers)Extension for optional UI elements that only make sense if another parameter has specific value (this could be done without
dependsOn
by defining it structurally, so the depending parameters are children in the document structure). For example, a model for a box, where you have a parameter checkbox that decides if a hole is drilled in the box. And if it is unchecked, it would be nice to hide "holeDiameter" parameterdependsOn
- name of parameter that this one depends ondependsValue
- value ofdependsOn
that makes this parameter visibleattribute: type
...
supported types
number
- integral number or floating point number (like float or double, those will not be distinguished here)string
- textual valueboolean
-supported inputs
the very basic minimum inputs to implement and support most of the parameters. These are recognized by
type
or ifvalues
list is present.input
- default for int,string,decimal. Textual input box that could impose some constraints depending on typecheckbox
- for booleansselect
- for enums (if parameter definesvalues
atrribute)Extended inputs that allow for a bit different user experience. These are activated with
input
attribute.radio
- instead of select when smaller number of options makes it nicer to userange
- a range slider for numberscolor
- a color pickerdate
- very low priority, and with questionable utilityBeta Was this translation helpful? Give feedback.
All reactions