new Enumerator( [name] [, types])
Creates a new Array-based enumeration type.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
name |
string |
<optional> |
A unique name for this enumeration, typically the class name in all capitals. |
types |
Array.<object> |
<optional> |
An array of objects of the form |
Example
BIM.FIXTURE = new PD.Enumerator('BIM.FIXTURE', [
{ name: 'Other', description: 'A generic fixture not connected to any system.' },
{ name: 'Bath', description: 'A sanitary receptacle for the immersion of the human body, or parts of it.' },
{ name: 'Bidet', description: 'A waste water receptacle for washing the excretory organs while sitting astride the bowl.' },
{ name: 'Basin', description: 'A waste water receptacle for washing the upper parts of the human body.' },
{ name: 'Cistern', description: 'A separate water storage unit for a sanitary terminal such as a toilet pan, urinal or slop hopper.' },
{ name: 'Fountain', description: 'A sanitary terminal that provides a low pressure jet of water for a specific purpose.' },
{ name: 'Shower', description: 'An installation or waste water receptacle that emits a spray of water for washing the human body.' },
{ name: 'Sink', description: 'A waste water receptacle for receiving, retaining or disposing of domestic, culinary, laboratory or industrial process liquids.' },
{ name: 'Toilet', description: 'A soil receptacle for the disposal of excrement by directing it to a waste outlet.' },
{ name: 'Urinal', description: 'A soil receptacle that receives urine and directs it to a waste outlet.' }
]);
/// ...
fixtureElem.type = BIM.FIXTURE.FOUNTAIN;
/// ...
function setFixtureType(fixture, type) {
fixture.type = BIM.FIXTURE.getValue(type);
};
Members
-
:string
name
-
The unique name of this enumerator, typically the class name in all uppercase.
Type
- string
Methods
-
addNewType(type)
-
Adds a new enumeration value to the list.
Each entry in the array should be an object of the form {name, description[, key]}. For enumerations of component types, each entry may also contain a
classNameproperty with the name of the component class in thePD.Registry.Parameters:
Name Type Description typeobject An object of the form {name, description[, key, className, etc]}.
Throws:
-
Throws an error if the type key already exists.
- Type
- Error
Returns:
Returns the number of new enumerations added.
- Type
- number
Example
AJM.MY_TYPE.addNewType( { key: 'TYPE4', name: 'Type 4', description: 'This is the fourth subtype' } ); -
-
addNewTypes( [types])
-
Adds an array of new enumeration values to the list.
Each entry in the array should be an object of the form {name, description[, key]}. For enumerations of component types, each entry may also contain a
classNameproperty with the name of the component class in thePD.Registry.Parameters:
Name Type Argument Description typesArray.<object> <optional>
An array of objects, each in the form {name, description[, key]}.
Returns:
Returns the number of new enumerations added.
- Type
- number
Example
AJM.MY_TYPE.addNewTypes([ { key: 'TYPE4', name: 'Type 4', className: 'AJM.MyTypes.Type4', description: 'This is the fourth subtype' }, { key: 'TYPE5', name: 'Type 5', className: 'AJM.MyTypes.Type5', description: 'This is the fifth subtype' }, { key: 'TYPE6', name: 'Type 6', className: 'AJM.MyTypes.Type6', description: 'This is the sixth subtype' } ]); -
fromString(name [, default_value])
-
Converts an enumeration name string to an ordinal enumeration index/value.
Parameters:
Name Type Argument Description namestring The textual name of a enumeration.
default_valuenumber <optional>
An optional index/value to use if the name is unmatched.
Returns:
Returns the ordinal enumeration index/value of the given name.
- Type
- number
-
getAsOptionList()
-
Retrieve enumerators as an array of {name, value} objects compatible with a
PD.ParamTypeoptions list.Returns:
Returns a formatted {name, value} options list.
- Type
- Array
-
getMaxTypeIndex()
-
Retrieve the maximum allowable index value for this enumerator.
For array-based enumerators, this is essentially the number of items in the list subtract one.
Returns:
Returns the maximum type index value.
- Type
- number
-
getParamType()
-
Retrieve a selectable enumerator list as a
PD.ParamTypefrom global cache.Returns:
Returns a cached selectable parameter type.
- Type
- PD.ParamType
-
getType(nameOrValue)
-
Retrieve the type definition with the given value/name.
Parameters:
Name Type Description nameOrValuestring | number A string or integer index/value.
Returns:
Returns a type definition if found, or null.
- Type
- object | null
-
getValue(nameOrValue)
-
Returns the numeric integer index/value from the given string or number.
The aim of this method is to check if the
nameargument is a string, and then convert it to its associated enumeration index/value. Ifnameis already a number, it is returned immediately.This is typically used by UI methods where '
Parameters:
Name Type Description nameOrValuestring | number A string or integer index/value.
Returns:
Returns a numeric index/value.
- Type
- number
-
hasType(nameOrValue)
-
Retrieves whether or not there is a type definition for the given value/name.
Parameters:
Name Type Description nameOrValuestring | number A string or integer index/value.
Returns:
Returns true if a definition was found.
- Type
- boolean
-
toString(index)
-
Converts an ordinal enumeration index/value to a name string.
Parameters:
Name Type Description indexnumber The numeric enumeration index/value.
Returns:
Returns the textual name.
- Type
- string