Class: Fences

BIM. Fences

A core class for parametrically generating fence systems.

This class provides basic parameters for defining a component fence system. Other classes can build in this infrastructure to define additional parameters and generate more detailed and specific parametric shapes and infills.

Anatomy of a Fence

        Post                 Finial           Post
        +--+                    |             +--+
        |  |    /\    /\    /\  | /\    /\    |  |
        |  |    ||    ||    ||<-+ ||    ||    |  |
     --+|  |+---++----++----++----++----++---+|  |+--  <-- Top Rail
     --+|  |+---++----++----++----++----++---+|  |+--
        |  |    ||    ||    ||    ||    ||    |  |
        |  |    ||    ||    ||    ||<---||----|--|-------- Picket
        |  |    ||    ||    ||    ||    ||    |  |
     --+|  |+---++----++----++----++----++---+|  |+--  <-- Mid Rail
     --+|  |+---++----++----++----++----++---+|  |+--
        |  |    ||    ||    ||    ||    ||    |  |
        |  |    ||    ||    ||    ||    ||    |  |
        |  |    ||    ||    ||    ||    ||<---|--|-------- Picket
        |  |    ||    ||    ||    ||    ||    |  |
        |  |    ||    ||    ||    ||    ||    |  |
     --+|  |+---++----++----++----++----++---+|  |+--  <-- Base Rail
     --+|  |+--------------------------------+|  |+--
  ______+--+__________________________________+--+______
  ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\

                            OR


       Pier                  Finial            Pier
      +----+                    |             +----+
      |    |    /\    /\    /\  | /\    /\    |    |
      |    |    ||    ||    ||<-+ ||    ||    |    |
   --+|    |+---++----++----++----++----++---+|    |+--  <-- Top Rail
   --+|    |+---++----++----++----++----++---+|    |+--
      |    |    ||    ||    ||    ||    ||    |    |
      |    |    ||    ||    ||    ||<---||----|----|-------- Picket
      |    |    ||    ||    ||    ||    ||    |    |
      |    |    ||    ||    ||    ||    ||    |    |
   --+|    |+---++----++----++----++----++---+|    |+--  <-- Base Rail
   --+|    |+--------------------------------+|    |+--
      |    |                                  |    |
   ---+    +----------------------------------+    +---  <-- Plinth


 _________________________________________________________
 ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\///


new Fences( [config] [, typeName])

Creates a new basic fence representation.

Parameters:
Name Type Argument Description
config object <optional>

An optional configuration object.

Properties of config:
Name Type Argument Description
name string <optional>

A human-readable name for this component.

uuid string <optional>

A universally unique identifier of this component.

productRef string <optional>

The product reference number or identifier.

description string <optional>

A brief product or type description.

supplier BIM.Supplier <optional>

An optional supplier details data object.

railDepth number <optional>

The width of the top handrail and posts in mm, defaults to 50mm or 2".

bottomGap number <optional>

The height between floor and bottom rail or infill in mm, defaults to 100mm or 4".

maxSpan number <optional>

The maximum span between support posts in mm, defaults to 2400mm or 8'.

hasTopRail number <optional>

Whether or not there is a rail along the top of the fence, defaults to true.

topRailSize number <optional>

The depth or thickness of the top handrail in mm, defaults to 50mm or 2".

hasBaseRail number <optional>

Whether or not there is a rail along the bottom as well as the top, defaults to true.

baseRailSize number <optional>

The depth or thickness of the base rail at the bottom in mm, defaults to 50mm or 2".

infillType BIM.INFILL <optional>

The type of infill between start, support and end posts.

infillSpacing number <optional>

The spacing between infill rails or panels in mm, defaults to 100mm or 4".

infillWidth number <optional>

The width of infill pickets, slats or panels in mm, defaults to 25mm or 1".

infillDepth number <optional>

The depth of infill pickets, slats or panels in mm, defaults to 25mm or 1".

typeName string <optional>

An additional parameter typically used by subclasses to set the component type name without modifying the config object.

Author:
  • drajmarsh

Extends

Members


:number

baseBoardHeight

The height of the base or toe board in mm, defaults to 100mm or 4".

Type
  • number
Inherited From:
Overrides:

:number

baseBoardWidth

The width of the base or toe board in mm, defaults to 6mm or 1/4".

Type
  • number
Inherited From:
Overrides:

:number

baseRailSize

The depth or thickness of the base rail along the bottom in mm, defaults to 50mm or 2".

Type
  • number
Inherited From:
Overrides:

:number

bottomGap

The height between floor and bottom rail/infill in mm, defaults to 100mm or 4".

Type
  • number
Inherited From:
Overrides:

:string

className <readonly>

The name of the subclass for this object instance.

This name must match the name of this class within the PD.Registry. Thus, the base implementation simply references this.constructor.getClassName() to ensure that this is always the case even for subclasses. As a result, there is rarely any need to override this method.

This property is used when copying, storing and exporting data for subclass instances to ensure that they are recreated as instances of the right class.

Type
  • string
Inherited From:
Overrides:

:string

description

A brief product or type description, defaults to an empty string.

This description is typically used to provide additional information about the product to other team members, such as its reasons for selection. important features, specifications and/or intended use.

Type
  • string
Inherited From:
Overrides:

:string

displayName <readonly>

The name to display for this class within the user interface.

Type
  • string
Inherited From:
Overrides:

:number

finialHeight

The height of any masonry plinth under the fence in mm, defaults to zero.

Type
  • number

:boolean

hasBaseBoard

Whether or not to include a toe-board at the base of the railing, defaults to false.

Type
  • boolean
Inherited From:
Overrides:

:boolean

hasBaseRail

Whether or not to include a base or bottom rail, defaults to true.

Type
  • boolean
Inherited From:
Overrides:

:boolean

hasTopRail

Whether or not to include a top or hand rail, defaults to true.

Type
  • boolean
Inherited From:
Overrides:

:string

iconName <readonly>

The name of the SVG icon to associate with this object instance.

This name should match the name of the icon associated with this class within the PD.Registry. Thus, the default implementation simply references this.constructor.getClassName() to ensure that this is always the case, even for subclasses. However, you can override this property if you want a different icon dependant on other properties of the class instance, as shown in the example below.

Type
  • string
Inherited From:
Overrides:
Example
// Overriding the icon name.

MyElements.Table = class extends PD.Base {
    /// ...
    get iconName() {
        if (this.hasRoundTop) return 'MyElements.Table.Round';
        return this.constructor.getClassName();
    };
    /// ...
 };

:number

infillDepth

The depth of infill pickets, slats or panels in mm, defaults to 18mm or 3/4".

Type
  • number
Overrides:

:number

infillSpacing

The spacing between infill rails or panels in mm, defaults to 100mm or 4".

Type
  • number
Overrides:

:BIM.INFILL

infillType

The type of infill between start, end and support posts.

Type
Overrides:

:number

infillWidth

The width of infill pickets, slats or panels in mm, defaults to 25mm or 1".

Type
  • number
Overrides:

:boolean

isComponent <readonly>

A flag identifying this object as a shared BIM component.

Type
  • boolean
Inherited From:
Overrides:

:boolean

isFenceType <readonly>

A flag identifying this object as a fence type.

Type
  • boolean

:boolean

isLocked

Whether or not this component's parameters are fixed.

This property is used by the UI and framework to indicate that the component's parameters are fixed and therefore not editable. It is typically set by a 3rd-party manufacturer or supplier on products that they can only provide in one configuration.

For example, there is no point specifying a particular manufacturer's fridge and then adjusting its width to fit a hole in your cabinetry if that manufacturer cannot actually supply a fridge of that width.

Thus, when this property is true, you will not be able to edit the parameters, but you can always duplicate the component (or its configuration), but without the supplier details if you really do want to modify it.

Type
  • boolean
Inherited From:
Overrides:

:boolean

isRailingType <readonly>

A flag identifying this object as a railing type.

Type
  • boolean
Inherited From:
Overrides:

:number

maintainDepth

Strategy for maintaining full post depth at acute angled corners (0:None, 1:Sideways, 2:Inwards), defaults to 1 (Sideways).

Type
  • number
Inherited From:
Overrides:

:number

maxSpan

The maximum span between support posts in mm, defaults to 2400mm or 8'.

Type
  • number
Inherited From:
Overrides:

:string

name

A human-readable name for this item instance.

Type
  • string
Inherited From:
Overrides:

:number

postProjection

The projection height of the corner posts above the handrail in mm, defaults to zero.

Type
  • number
Inherited From:
Overrides:

:number

postWidth

The width of posts in mm, defaults to BIM.Railings#railDepth.

Type
  • number
Inherited From:
Overrides:

:string

productRef

The product reference number or identifier, defaults to an empty string.

The product reference is typically used to store a serial number, model number, SKU or other identifier provided by the manufacturer or supplier to uniquely identify this product.

Type
  • string
Inherited From:
Overrides:

:number

railDepth

The depth of rails and posts in mm, defaults to 50mm or 2".

Type
  • number
Inherited From:
Overrides:

:number

subType <readonly>

An element-specific subtype.

Type
  • number
Inherited From:
Overrides:

:string

supplier

The product supplier/manufacturer, defaults to null.

This property contains details of the supplier or manufacturer of this product or component. Multiple components can share the same supplier instance to avoid unnecessary duplication of data.

Type
  • string
Inherited From:
Overrides:

:number

topRailSize

The depth or thickness of the top handrail in mm, defaults to 50mm or 2".

Type
  • number
Inherited From:
Overrides:

:string

uuid

A universally unique identifier for the item instance.

Type
  • string
Inherited From:
Overrides:

:object

icon <static>

The icon associated with this class in the PD.Registry.

See PD.Base.icon for more information on this object format.

Type
  • object

Methods


addBackingRail(infill, z, size)

Adds a thinner locally horizontal rail at the given height between support post connectors.

Parameters:
Name Type Description
infill object

A cached data object defining the current rail span.

z number

The height in the local Z axis to the bottom of the rail.

size number

The size of the rail in the local Z axis.

Inherited From:
Overrides:

addBaseRail(infill)

Adds a locally horizontal bottom rail between support post connectors.

Parameters:
Name Type Description
infill object

A cached data object defining the current rail span.

Inherited From:
Overrides:

addMidSpanPost(infill)

Generates a mid-span support post at the current coordinates.

This method requires that the given local coordinates are already positioned at the center of the base of the post, and oriented appropriately.

Mid-span posts are not just prisms, as the four vertices at their base need to be horizontal to sit directly on a slab or stair, but their top four vertices need to be in line with the slope of the top handrail.

Parameters:
Name Type Description
infill object

A cached data object defining the current rail span.

Inherited From:
Overrides:

clone()

Creates a copy of this instance with different name and uuid.

Inherited From:
Overrides:
Returns:

Returns a new instance with copied values.

Type
PD.Base | null

generatePosts(path, infill)

Sets up a post at each junction and creates connectors on each side of it.

This is the first phase of generating the railing, where posts are created for each junction and incoming/outgoing connectors for the infill rail segments are computed and stored.

NOTE: When a railing segment is inclined (i.e.: the base of the post at each end have different positions in the Z-axis), you cannot base the local coordinate system on the junction-to-junction vectors. This is because the start and end posts must be the exact same width and depth so that the rail can turn corners without changing the width of the top rail. This means that the angle of the handrail does not run from the centre of the first post to the centre of the second, but rather from the outgoing face of the first post to the incoming face of the second. This creates a slightly different incline, as shown in the illustration below.

               |   |                     |   |
    +---+      |   |          +---+      |   |
    |   |      1-+-+          |   |      +-1-+
    |   |     /               |   |      _/
    |   |    /                |   |     /
    |   |   /                 |   |   _/
    |   |  /                  |   |  /
    |   | /                   |   |_/
    |   |/                    |  /|
    +-+-0                     +-0-+
    CORRECT ANGLE             WRONG ANGLE
    BETWEEN POST FACES        BETWEEN POST CENTERS

The connector created for each post is simply an array of 6 points ordered in a clockwise direction around its base. If a rail is to be added between posts 1 and 2, as in the illustration below, then its profile in plan view would join connector1[5], connector1[3], connector2[2] and connector2[0] to form the bottom facet with a normal facing downwards (as per the right-hand rule). The center line of the infill would run between connector1[4] and connector2[1].

    ^ Y
    : connector                    connector
    2-----------3  -  -  >  -  -  2-------+._
    |           |                 |          '-.3 _
    1     1     4  -  -  >  -  -  1      2      /   ' - _
    |           |                 |           4 _         ' - _
    0-----------5  -  -  >  -  -  0-----+._  /    ' - _
      clockwise                            '5 _         '
                                               ' - _
Parameters:
Name Type Description
path PD.Path

The path to generate posts along.

infill object

A shared data cache set by rebuild method.

Inherited From:
Overrides:

generateRailings(path, infill)

Generates the railings with infill between each post.

This is the second phase of the process where rails are joined between the outgoing connectors on one post and the incoming ones on the next. It also adds the infills between the posts.

Parameters:
Name Type Description
path PD.Path

The path containing connectors to infill between.

infill object

A shared data cache set by rebuild method.

Inherited From:
Overrides:

getNameAndSupplierParameters()

Provides a list of dynamic parameter groups for the component name, description and supplier.

See the PD.Base#getDynamicParameters method for more details.

Inherited From:
Overrides:
Returns:

Returns an array of PD.ParamGroup objects.

Type
Array

hasMethod(component, methodName)

Determines if this component has a callable method with the given name.

This method is useful for checking if the component has a particular method before attempting to call it, thereby avoiding potential runtime errors. It is used within the framework to check for the presence of life-cycle methods in an element's type component before delegating them.

Parameters:
Name Type Description
component BIM.Component

The component to check.

methodName string

The case-sensitive name of the function/method to check for.

Inherited From:
Overrides:
Returns:

Returns true if the component is valid and has the function name as a method, otherwise false.

Type
boolean

isCompatibleWith(obj)

Determines if this component can be added to the given entity.

Whilst a small number of components may be compatible with multiple entity types, most components are designed to be used only by a specific entity type, and will not allow you to assign them to an incompatible entity.

Parameters:
Name Type Description
obj BIM.ENTITY | BIM.Entity

The entity type or object instance to check for compatibility with.

Inherited From:
Overrides:
Returns:

Returns true if the component can be added to the object, otherwise false.

Type
boolean

render(meshes, view, level, element)

An opportunity for the railing type to render anything additional.

If defined on a railing type class, this method is called at the start of the element's own render() method.

Parameters:
Name Type Description
meshes BIM.Meshes

The collection of meshes to render to.

view PD.ViewData

The view definition to render the model within.

level BIM.Level

The level currently being rebuilt and rendered.

element BIM.Element

The element being rendered.

Inherited From:
Overrides:

setSharedInfillDataCache(element)

Sets up the shared infill data cache with initial values from the this component and the given element.

Parameters:
Name Type Description
element BIM.Railing

The railing element being built.

Inherited From:
Overrides:
Returns:
Type
object

updateDynamicParameters(param, group)

Sets the dynamic parameter value and returns true if it changed.

Most subclasses don't need to override this method as it automatically detects changes and rebuilds the element/component and model when required. However, if you do need to add your own custom logic or intercept the return value, please read the following examples carefully and use whichever best suits your needs.

NOTE: When overriding this method, you may not want to call super.updateDynamicParameters(param, group) as the parent class may have added its own logic that may interfere with what you want to do. Instead, either use the static PD.Base.updateDynamicParametersOnHost method to check if the value changed, or base it on the third example which replicates the code in that static method.

Parameters:
Name Type Description
param PD.Parameter

The dynamic parameter that changed.

group PD.ParamGroup

The group that the dynamic parameter belongs to.

Inherited From:
Overrides:
Returns:

Returns true if the value actually changed.

Type
boolean
Examples
updateDynamicParameters(param, group) {

     /// When you want parent class to use its logic.
     if (super.updateDynamicParameters(param, group)) {
         if (param.name == 'i_am_special') this.doSomethingSpecial();
         return true;
     }

     return false;

 };
updateDynamicParameters(param, group) {

     /// When you don't want parent to handle parameter updates.
     if (PD.Base.updateDynamicParametersOnHost(param, group, this)) {

         /// Invalidate geometry.
         if (this.typeComponent) {
             ++this.typeComponent.updateIndex;
         }

         /// Rebuild element.
         this.hasChanged = true;
         this.update();

         /// Only update site mesh.
         if (this.onlyUsesSiteMesh) {
             const level = this.level;
             if (level) { // Don't trigger whole level update.
                 level.rebuildSiteMesh();
                 PD.GlobalActions.redrawAndUpdateSelection();
                 return false;
             }
         }

         return true;

     }

     return false;

 };
updateDynamicParameters(param, group) {

     /// The following three lines of code replicate
     /// `PD.Base.updateDynamicParametersOnHost()`, which you can
     /// use if you need to access `target` without having to call
     /// `group.getTarget() || this` twice.

     const target = group.getTarget() || this;
     target.checkDynamicParameter(param, group, this);
     if (param.setValueOnHostIfDifferent(target, group, this)) {

         /// You can now use `target`.
         if (target.myOwnMeshThatIsUpdatedDuringRebuild) {

             /// Rebuild element.
             this.hasChanged = true;
             this.update();

             /// If no level meshes or other elements are affected,
             /// simply update the target locally and return false.
             this.myOwnMeshThatIsUpdatedDuringRebuild.update();

             /// Update selection meshes if the
             /// element's highlight geometry changed.
             PD.GlobalActions.updateSelectionMeshes();
             return false;

         }

         return true;

     }

     return false;

 };

getClassDescription() <static>

A brief description of this class to accompany its icon.

Returns:

Returns a brief description.

Type
string

getClassName() <static>

The name of this class within the PD.Registry.

See PD.Base.getClassName for more details as this is required for use with the PD.Registry.

Returns:

Returns the registered name of this class.

Type
string

getDisplayName() <static>

The name to display within the user interface.

Returns:

Returns the display name.

Type
string

getHostElementClass() <static>

Retrieves the class of the host element for this component.

See BIM.Component#getHostElementClass for more details on this static method.

Returns:

Returns the element class this component requires as a host.

Type
BIM.Fence

isCompatibleWith(obj) <static>

Determines if this component can be added to the given object.

Parameters:
Name Type Description
obj BIM.ENTITY | BIM.Entity

The entity type or object to check for compatibility with.

Returns:

Returns true if the component can be added to the object, otherwise false.

Type
boolean

subType() <static>

Retrieves the sub-type of railing this class represents.

See BIM.Component#subType for more details on this static method.

Returns:

Returns the sub-type enumerator of this class.

Type
BIM.RAILING