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.
{ fileDescription : List String
, fileName : String
, timeStamp : String
, author : List String
, organization : List String
, preprocessorVersion : String
, originatingSystem : String
, authorization : String
, schemaIdentifiers : List String
}
A Header
represents the data stored in the header section of a STEP file:
fileDescription
should be an informal description of the contents of the
file.fileName
may be the file name of the actual file, or it may be an abstract
name for the contents of the file used when cross-referencing between files.timeStamp
should be an
ISO 8601-formatted date and time.author
should include the name and address of the person who created the
file.organization
should be the organization that the author
is associated
with.preprocessorVersion
or originatingSystem
should identify what CAD
program was used to generate the file. This does not seem to be used
terribly consistently!authorization
should include the name and address of whoever authorized
sending the file.schemaIdentifiers
identifies the EXPRESS schema used by entities in the
file. This will usually be a list containing a single string, which may be
either a simple string like "IFC2X3" or an 'object identifier' such as
"AUTOMOTIVE_DESIGN { 1 0 10303 214 1 1 1 1 }" (more commonly known as
AP214).StepFile.Types.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.));
StepFile.Types.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 : Basics.Int -> Attribute
Construct an integer-valued attribute.
float : Basics.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 are sometimes needed when dealing with SELECT types.
intAs : String -> Basics.Int -> Attribute
Construct a type-tagged integer-valued attribute.
floatAs : String -> Basics.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.