ianmackenzie/elm-step-file/1.0.0

NOTE: the latest version is 1.0.1

Renamed to ianmackenzie/elm-iso-10303. It is published under that name, and new versions come out there.

Versions published as ianmackenzie/elm-step-file still install under that name. 1 version of 2 come from the new location (see their notes).

Rerouted (renamed, needs approval). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/ianmackenzie/elm-iso-10303.

What we checked: The repo moved to github.com/ianmackenzie/elm-iso-10303 and tag 1.0.0 is there; its commit 212926a867bf is from 2018-11-13 21:23 UTC, after the version was published (2018-11-13 21:11 UTC); elm.json differs from package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one and nothing else confirms its contents.

We could not verify this copy against what was published, so the Lamdera compiler asks before using it (y/n). Without a terminal, as in CI, it stops with an error unless approved:

  • lamdera make --auto-approve-package-rerouting approves rerouted versions for that run,
  • LAMDERA_AUTO_APPROVE_PACKAGE_REROUTING=1 does the same for every run in that environment,
  • LAMDERA_CACHE=off skips the Lamdera package server altogether: packages come from package.elm-lang.org and GitHub only, as with elm, and a rerouted version then fails to download.

Details · package.elm-lang.org's zip: https://github.com/ianmackenzie/elm-step-file/zipball/1.0.0/

Iso10303

This module allows you to encode data in ISO 10303-21 (STEP file) format.

The module name was chosen to avoid naming conflicts (and to emphasize that this is a low-level package), but in most cases I recommend importing it as

import Iso10303 as Step

All examples below assume the module has been imported this way.

file : Header -> List Entity -> String

Build a string representing a complete STEP file from a header and a list of entities. Entities will be assigned integer IDs automatically, and nested entities (entities that reference other entities) will be 'flattened' into separate entities referring to each other by their automatically-generated IDs.

Note that it is not actually necessary to list all entities explicitly, only top-level ones; any entities that are referenced by entities in the given list will also get included in the output.

Header

Entities

type alias Entity =
Entity

An Entity represents a single entity stored in the data section of a STEP file. An entity may be a point, a curve, a part, an assembly, or even an entire building. Every entity has a type and a list of attributes (which can themselves be references to other entities).

entity : String -> List Attribute -> Entity

Construct a single entity with the given type and attributes. The type name will be capitalized if necessary. An IfcDirection representing the positive Y direction in 3D could be created using

direction =
    Step.entity "IFCDIRECTION"
        [ Step.list Step.float [ 0, 1, 0 ]
        ]

which might get encoded as #1=IFCDIRECTION((0.,1.,0.));.

If a given entity is only referred to by a single other entity, you can create it directly inside the definition of the parent entity. For example, to create entity #121 from this AP214 example, you could use

Step.entity "AXIS2_PLACEMENT_3D"
    [ Step.string ""
    , Step.referenceTo <|
        Step.entity "CARTESIAN_POINT"
            [ Step.list Step.float [ 20, 7.5, 0 ]
            ]
    , Step.referenceTo <|
        Step.entity "DIRECTION"
            [ Step.string ""
            , Step.list Step.float [ 1, 0, 0 ]
            ]
    , Step.referenceTo <|
        Step.entity "DIRECTION"
            [ Step.string ""
            , Step.list Step.float [ 0, 0, -1 ]
            ]
    ]

When actually encoded to a STEP file, this will get converted into four separate entities, with the top-level entity referring to the other three by their automatically-generated IDs, something like:

#1=AXIS2_PLACEMENT_3D('',#2,#3,#4);
#2=CARTESIAN_POINT('',(20.,7.5,0.));
#3=DIRECTION('',(1.,0.,0.));
#4=DIRECTION('',(0.,0.,-1.));

Attributes

type alias Attribute =
Attribute

An Attribute represents a single attribute of an Entity, such as an X coordinate value, a GUID string, or a reference to another entity.

default : Attribute

The special 'default value' attribute (* in the resulting STEP file).

null : Attribute

The special 'null value' attribute ($ in the resulting STEP file).

int : Int -> Attribute

Construct an integer-valued attribute.

float : Float -> Attribute

Construct a real-valued attribute.

string : String -> Attribute

Construct a string-valued attribute. Unicode characters will be properly escaped according to the (weird, custom) method specified in the STEP standard; for example,

Step.string "see § 4.1"

will end up being encoded as

'see \X\A7 4.1'
referenceTo : Entity -> Attribute

Construct a reference to another STEP entity (will end up being encoded using an integer ID in the resulting STEP file, e.g. #123).

enum : String -> Attribute

Construct an attribute that refers to an enumeration value defined in an EXPRESS schema. Enumeration values are always encoded as all-caps with leading and trailing periods, like .STEEL..

This function will capitalize and add periods if necessary, so both Step.enum "steel" and Step.enum ".STEEL." will be encoded as .STEEL..

binary : String -> Attribute

Construct a binary-valued attribute. The provided string is assumed to already be hex encoded as required by the STEP standard.

list : (a -> Attribute) -> List a -> Attribute

Construct an attribute which is itself a list of other attributes. You provide a list of values and a function to convert each of those values to an attribute (which will usually be one of the attribute construction functions in this module!). For example, to construct an attribute which is a list of floats:

Step.list Step.float [ 0, 1, 0 ]

To construct a list of references to various entities:

Step.list Step.referenceTo
    [ firstEntity
    , secondEntity
    , thirdEntity
    ]

In the odd case where you already have a List Attribute, you can use Elm's built-in identity function as the first argument:

Step.list identity
    [ firstAttribute
    , secondAttribute
    , thirdAttribute
    ]

Typed attributes

Typed attributes are sometimes needed when dealing with SELECT types.

intAs : String -> Int -> Attribute

Construct a type-tagged integer-valued attribute.

floatAs : String -> Float -> Attribute

Construct a type-tagged float-valued attribute.

stringAs : String -> String -> Attribute

Construct a type-tagged string-valued attribute.

enumAs : String -> String -> Attribute

Construct a type-tagged enumeration attribute.

binaryAs : String -> String -> Attribute

Construct a type-tagged binary-valued attribute.

listAs : String -> (a -> Attribute) -> List a -> Attribute

Construct a type-tagged list attribute.