4 Where Records Get Their Meaning: The Schema
The file says ADVANCED_. Nothing in the file says what those four values are. The schema does — and reading enough of the schema language to look them up is the one prerequisite for everything else in this book.
Every entity type in a STEP file — PRODUCT, ADVANCED_, SI_ — is defined in a schema written in a language called EXPRESS, which is ISO 10303-11. The schema for AP214 is a single text file of about 19,000 lines; AP242’s is nearly three times that. It lists every entity, its attributes in order, its relationship to other entities, and a body of constraints. The Part 21 file is a dump of instances of those entities, and it deliberately omits everything the schema already says: attribute names, attribute types, inheritance. To read a record you look its type up in the schema and lay the parameters against the attributes.
This chapter is EXPRESS as a reader needs it. The language also has functions, rules and procedures for validating data; they are skipped here, and you will not miss them.
4.1 An entity declaration
Here is the definition of product, from Part 41, exactly as it appears in the AP214 schema apart from spacing:
ENTITY product;
id : identifier;
name : label;
description : OPTIONAL text;
frame_of_reference : SET [1:?] OF product_context;
END_ENTITY;Lay record #7 from the block file against it:
#7 = PRODUCT('BLOCK','block 60x20x10','',(#8));Referred to above: 2 records from block.step
#2 = APPLICATION_CONTEXT(
'core data for automotive mechanical design processes');
#8 = PRODUCT_CONTEXT('',#2,'mechanical');| Attribute | Type | Value in #7 |
|---|---|---|
id |
identifier (a string) |
'BLOCK' |
name |
label (a string) |
'block 60x20x10' |
description |
text, optional |
'' |
frame_ |
set of 1 or more product_ |
(#8) |
Four attributes, four parameters, in order. Several things in the declaration are worth naming.
identifier, label and text are defined types — names given to a base type so the schema can say what a string is for. All three are declared elsewhere as TYPE label = STRING; and so on. The file does not distinguish them; a string is a string.
OPTIONAL means the attribute may be absent, in which case the file writes $. An attribute without OPTIONAL must have a value. #7 supplies '' for its optional description, which is a value (an empty one), not an absence.
SET [1:?] OF product_ is an aggregate: an unordered collection of at least one, at most any number, of references to product_ instances. EXPRESS has four aggregate kinds — SET (unordered, no duplicates), BAG (unordered, duplicates allowed), LIST (ordered) and ARRAY (ordered, fixed bounds) — and the file writes all four as a parenthesised list. The bounds are constraints on valid data, not storage instructions.
4.2 Inheritance and the flattened record
Most entities are not declared from scratch. ADVANCED_, the workhorse of every B-rep file, is the bottom of a chain:
ENTITY representation_item;
name : label;
END_ENTITY;
ENTITY topological_representation_item
SUBTYPE OF (representation_item);
END_ENTITY;
ENTITY face
SUBTYPE OF (topological_representation_item);
bounds : SET [1:?] OF face_bound;
END_ENTITY;
ENTITY face_surface
SUBTYPE OF (face, geometric_representation_item);
face_geometry : surface;
same_sense : BOOLEAN;
END_ENTITY;
ENTITY advanced_face
SUBTYPE OF (face_surface);
END_ENTITY;(Constraints and supertype clauses removed; they return below.) advanced_ adds no attributes of its own. It is a face_ with extra rules about what kinds of surface and edge it may use. face_ has two supertypes — it is both a face and a geometric_, and both of those descend from representation_. EXPRESS allows multiple inheritance, including the diamond.
Now the record:
#17 = ADVANCED_FACE('',(#18),#52,.F.);Referred to above: 39 records from block.step
#18 = FACE_BOUND('',#19,.F.);
#19 = EDGE_LOOP('',(#20,#30,#38,#46));
#20 = ORIENTED_EDGE('',*,*,#21,.F.);
#21 = EDGE_CURVE('',#22,#24,#26,.T.);
#22 = VERTEX_POINT('',#23);
#23 = CARTESIAN_POINT('',(0.,0.,0.));
#24 = VERTEX_POINT('',#25);
#25 = CARTESIAN_POINT('',(0.,0.,10.));
#26 = LINE('',#27,#28);
#27 = CARTESIAN_POINT('',(0.,0.,0.));
#28 = VECTOR('',#29,1.);
#29 = DIRECTION('',(0.,0.,1.));
#30 = ORIENTED_EDGE('',*,*,#31,.T.);
#31 = EDGE_CURVE('',#22,#32,#34,.T.);
#32 = VERTEX_POINT('',#33);
#33 = CARTESIAN_POINT('',(0.,20.,0.));
#34 = LINE('',#35,#36);
#35 = CARTESIAN_POINT('',(0.,0.,0.));
#36 = VECTOR('',#37,1.);
#37 = DIRECTION('',(0.,1.,0.));
#38 = ORIENTED_EDGE('',*,*,#39,.T.);
#39 = EDGE_CURVE('',#32,#40,#42,.T.);
#40 = VERTEX_POINT('',#41);
#41 = CARTESIAN_POINT('',(0.,20.,10.));
#42 = LINE('',#43,#44);
#43 = CARTESIAN_POINT('',(0.,20.,0.));
#44 = VECTOR('',#45,1.);
#45 = DIRECTION('',(0.,0.,1.));
#46 = ORIENTED_EDGE('',*,*,#47,.F.);
#47 = EDGE_CURVE('',#24,#40,#48,.T.);
#48 = LINE('',#49,#50);
#49 = CARTESIAN_POINT('',(0.,0.,10.));
#50 = VECTOR('',#51,1.);
#51 = DIRECTION('',(0.,1.,0.));
#52 = PLANE('',#53);
#53 = AXIS2_PLACEMENT_3D('',#54,#55,#56);
#54 = CARTESIAN_POINT('',(0.,0.,0.));
#55 = DIRECTION('',(1.,0.,0.));
#56 = DIRECTION('',(0.,0.,1.));Four parameters, and advanced_ declares zero attributes. They come from the ancestors, flattened into one list: each entity’s attributes appear once, in the order given by walking the supertype graph depth-first, supertypes before subtypes, and multiple supertypes in the order they are listed.
| Parameter | Attribute | Declared in |
|---|---|---|
'' |
name |
representation_ |
(#18) |
bounds |
face |
#52 |
face_ |
face_ |
.F. |
same_ |
face_ |
geometric_ and topological_ declare nothing, and representation_ is visited once even though there are two paths to it. This is the rule that makes ordinary records readable, and it is the rule that must be got exactly right: shift one attribute and every value lands in the wrong slot.
A record like this — one leaf type name, all inherited attributes flattened in — is what Part 21 calls the internal mapping. It is the normal case.
4.3 Derived attributes and *
Some attributes are declared with a formula instead of a stored value. From Part 41:
ENTITY named_unit;
dimensions : dimensional_exponents;
END_ENTITY;
ENTITY si_unit
SUBTYPE OF (named_unit);
prefix : OPTIONAL si_prefix;
name : si_unit_name;
DERIVE
SELF\named_unit.dimensions : dimensional_exponents
:= dimensions_for_si_unit(name);
END_ENTITY;named_ stores its dimensions — length\(^{1}\), mass\(^{0}\), and so on. si_ inherits that attribute and redeclares it as derived: an SI unit knows its dimensions from its name, so the value is computed by a function rather than stored. Attribute slots are positional, so the file cannot simply omit it; it writes * in the slot:
#166 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );* is “there is a value here, but you compute it.” $ is “there is no value.” What sits behind a * is not always unimportant: in ORIENTED_ the two starred slots are the edge’s start and end vertices, which every reader of a B-rep needs. The point of a derived attribute is that the value is always recoverable from what the record does store — here from the edge #21 and the orientation flag — so nothing is lost by not writing it.
4.4 Inverse attributes
Declarations may also contain an INVERSE clause:
ENTITY representation_context;
context_identifier : identifier;
context_type : text;
INVERSE
representations_in_context : SET [1:?] OF representation
FOR context_of_items;
END_ENTITY;An inverse attribute is the schema saying: you can find the representations that use this context by looking for representation instances whose context_ points here. It declares the reverse of a reference that exists elsewhere. Inverse attributes never appear in the file. REPRESENTATION_ has two parameters, not three. They are worth knowing about for two reasons: the schema uses them in constraints, and they are a map of exactly the reverse lookups a reader will end up building for itself.
4.5 Complex instances and the external mapping
Chapter 2 introduced records with several type names and promised the explanation. It is in the SUPERTYPE OF clause, which I removed from the declarations above. Here is named_ in full:
ENTITY named_unit
SUPERTYPE OF (ONEOF (si_unit, conversion_based_unit, context_dependent_unit)
ANDOR
ONEOF (length_unit, mass_unit, time_unit, electric_current_unit,
thermodynamic_temperature_unit, amount_of_substance_unit,
luminous_intensity_unit, plane_angle_unit,
solid_angle_unit, ratio_unit));
dimensions : dimensional_exponents;
END_ENTITY;A supertype clause constrains how an entity’s subtypes may be combined in a single instance. ONEOF (a, b, c) means at most one of them: they are mutually exclusive, and only if the supertype is declared ABSTRACT must one of them be chosen. a ANDOR b means either, or both. a AND b means both. An entity with no supertype clause allows any combination, as if every pair were ANDOR.
Read named_’s clause: an instance is one of {SI, conversion-based, context-dependent} and/or one of {length, mass, time, …}. A millimetre is an SI unit and a length unit. There is no entity named si_; the schema deliberately does not enumerate the thirty combinations. So there is no leaf type to name in an internal-mapping record, and the file falls back to the external mapping:
#166 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );The rules of the external mapping:
- Every entity type the instance is appears as a block: the leaves, and every supertype above them, up to the root.
NAMED_is present because both leaves descend from it.UNIT - Each block carries only the attributes that entity declares itself, not inherited ones.
SI_getsUNIT prefixandname;NAMED_getsUNIT dimensions;LENGTH_declares nothing and gets an empty pair of parentheses.UNIT - Blocks are in alphabetical order of entity name. Not hierarchical order — alphabetical. L before N before S.
- The set of leaves must be one the supertype clauses permit.
(LENGTH_would violate the secondUNIT() MASS_ UNIT() ...) ONEOF.
The other complex record in the block file works the same way with a different reason. representation_ has no supertype clause, so any combination of its subtypes is legal, and a 3D context that also carries units and an uncertainty is three of them at once:
#165 = ( GEOMETRIC_REPRESENTATION_CONTEXT(3)
GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#169))
GLOBAL_UNIT_ASSIGNED_CONTEXT((#166,#167,#168))
REPRESENTATION_CONTEXT('Context #1','3D Context with UNIT and UNCERTAINTY') );Referred to above: 4 records from block.step
#166 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );
#167 = ( NAMED_UNIT(*) PLANE_ANGLE_UNIT() SI_UNIT($,.RADIAN.) );
#168 = ( NAMED_UNIT(*) SI_UNIT($,.STERADIAN.) SOLID_ANGLE_UNIT() );
#169 = UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(1.E-07),#166,
'distance_accuracy_value','confusion accuracy');Each subtype adds one attribute — dimension count, uncertainty set, unit set — and the root carries the two it declares.
Why list the supertypes at all, when a reader with the schema could derive them from the leaves? Partly because the supertype blocks are carrying attribute values that have to go somewhere. Mostly because the format was designed to be readable by a program that does not have the schema: a tool that only cares about REPRESENTATION_ can find that block and take its two values without knowing the other three types exist. The redundancy is the price of that. It is also a free consistency check — if the supertypes listed do not match what the schema derives from the leaves, the file was written against a different schema than it claims.
Exporters are supposed to use the internal mapping whenever a leaf name exists and the external mapping only when it does not. A few use the external form more liberally, so a reader must accept either form for any entity.
4.6 Enumerations
An enumeration is a closed list of names:
TYPE si_prefix = ENUMERATION OF
(exa, peta, tera, giga, mega, kilo, hecto, deca,
deci, centi, milli, micro, nano, pico, femto, atto);
END_TYPE;
TYPE si_unit_name = ENUMERATION OF
(metre, gram, second, ampere, kelvin, mole, candela, radian, steradian,
hertz, newton, pascal, joule, watt, coulomb, volt, farad, ohm, siemens,
weber, tesla, henry, degree_celsius, lumen, lux, becquerel, gray, sievert);
END_TYPE;In the file the chosen name is upper-cased and dotted: .MILLI., .METRE.. The base type BOOLEAN is written as an enumeration too — .T. or .F., and only those — and its cousin LOGICAL adds a third value, .U. for unknown.
4.7 SELECT types and the typed wrapper
One record in the block file has a value that is wrapped in a type name:
#169 = UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(1.E-07),#166,
'distance_accuracy_value','confusion accuracy');Referred to above: 1 record from block.step
#166 = ( LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT(.MILLI.,.METRE.) );The first attribute, value_, is declared with a SELECT type — EXPRESS’s tagged union:
TYPE measure_value = SELECT
(amount_of_substance_measure, area_measure, celsius_temperature_measure,
context_dependent_measure, count_measure, descriptive_measure,
electric_current_measure, length_measure, luminous_intensity_measure,
mass_measure, numeric_measure, non_negative_length_measure, parameter_value,
plane_angle_measure, positive_length_measure, positive_plane_angle_measure,
positive_ratio_measure, ratio_measure, solid_angle_measure,
thermodynamic_temperature_measure, time_measure, volume_measure);
END_TYPE;
TYPE length_measure = REAL; END_TYPE;
TYPE plane_angle_measure = REAL; END_TYPE;A measure_ is any one of those twenty-two; AP242’s list runs to forty-two. But length_ and plane_ are both plain REAL underneath, so a bare 1.E-07 would be ambiguous — a length or an angle? The file resolves this by wrapping the value in the name of the alternative chosen: LENGTH_.
The rule for when a wrapper appears is exact. A parameter is wrapped when both hold:
- the attribute’s declared type is a
SELECT, and - the alternative chosen is not an entity type.
The second attribute of #169, unit_, is also a SELECT — TYPE unit = SELECT (derived_ — but both alternatives are entities, so the value is a bare reference: #166. The record at #166 already says what it is. Wrappers exist only for values that have no record of their own to carry a type.
You will meet wrappers most often with measures (LENGTH_, PLANE_, POSITIVE_), with curve parameters (PARAMETER_ in trimmed curves), and in PMI, where DESCRIPTIVE_ carries text. A SELECT can include another SELECT, so wrappers can in principle nest; in practice they rarely do.
4.8 Case
EXPRESS identifiers are case-insensitive, and published schemas are written in lower case: representation_. Part 21 keywords — entity names, enumeration values, the wrapper names — are required to be upper case; the grammar admits nothing else. So the mapping from schema to file is “upper-case the name,” and the mapping back is the reverse. With one caveat: Part 21 also lets an AP define short names, abbreviations that a file may use in place of entity type names and enumeration values. Nothing in mechanical CAD writes them, and a file declaring '2;1' is promising it has not used them for enumeration values, but the abbreviation cannot be derived from the name, so a reader that meets one needs the AP’s short-name table. Strings, being data, keep their case: 'BLOCK' and 'block' are different values.
4.9 What to skip, and where to find the rest
The schema also contains WHERE clauses on entities (per-instance constraints), global RULEs (constraints across instances), FUNCTIONs used by both, ABSTRACT SUPERTYPE declarations (an entity that can only appear as part of a subtype), UNIQUE clauses, and the SCHEMA/USE FROM machinery that assembles AP242 from hundreds of modules. A validator needs all of it. A reader of files needs none of it, and this book will not use any of it again except to explain, in passing, why a particular record has the shape it has.
The schemas themselves are free even though the standard is not. STEP Tools publishes the long-form EXPRESS for AP203, AP214 and AP242 at steptools.com/stds/step/, and that is the text every declaration in this book was checked against. Opening the AP242 long form and searching for ENTITY next_ is the best twenty minutes you can spend before Chapter 8.
A record’s parameters are its entity’s attributes, flattened from the root of the inheritance chain down, supertypes first. $ is an absent optional; * is a derived value. A record with several type names in parentheses is one object whose combination of subtypes has no single name; blocks are alphabetical and carry only their own attributes. A value is wrapped in a type name only when its attribute is a SELECT and the chosen alternative is not an entity.