@ifc-lite/export 6.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -20
- package/dist/anonymize-types.d.ts +2 -0
- package/dist/anonymize-types.d.ts.map +1 -1
- package/dist/declared-property-type.d.ts +2 -110
- package/dist/declared-property-type.d.ts.map +1 -1
- package/dist/declared-property-type.js +15 -0
- package/dist/declared-property-type.js.map +1 -1
- package/dist/energy-artifact.d.ts +6 -0
- package/dist/energy-artifact.d.ts.map +1 -0
- package/dist/energy-artifact.js +33 -0
- package/dist/energy-artifact.js.map +1 -0
- package/dist/generated/ifc4-required-slots.d.ts +4 -1
- package/dist/generated/ifc4-required-slots.d.ts.map +1 -1
- package/dist/generated/ifc4-required-slots.js +704 -0
- package/dist/generated/ifc4-required-slots.js.map +1 -1
- package/dist/geometry-diagnostics.d.ts +14 -0
- package/dist/geometry-diagnostics.d.ts.map +1 -0
- package/dist/geometry-diagnostics.js +29 -0
- package/dist/geometry-diagnostics.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/merged-exporter.d.ts +1 -4
- package/dist/merged-exporter.d.ts.map +1 -1
- package/dist/merged-exporter.js +39 -23
- package/dist/merged-exporter.js.map +1 -1
- package/dist/merged-header.d.ts +2 -1
- package/dist/merged-header.d.ts.map +1 -1
- package/dist/merged-header.js +8 -0
- package/dist/merged-header.js.map +1 -1
- package/dist/merged-inherited-units.d.ts +8 -0
- package/dist/merged-inherited-units.d.ts.map +1 -0
- package/dist/merged-inherited-units.js +117 -0
- package/dist/merged-inherited-units.js.map +1 -0
- package/dist/merged-inverse-claims.d.ts +5 -6
- package/dist/merged-inverse-claims.d.ts.map +1 -1
- package/dist/merged-inverse-claims.js +29 -10
- package/dist/merged-inverse-claims.js.map +1 -1
- package/dist/merged-profile-units.d.ts +9 -0
- package/dist/merged-profile-units.d.ts.map +1 -0
- package/dist/merged-profile-units.js +44 -0
- package/dist/merged-profile-units.js.map +1 -0
- package/dist/related-entities.d.ts.map +1 -1
- package/dist/related-entities.js +11 -9
- package/dist/related-entities.js.map +1 -1
- package/dist/rust-artifact.d.ts +4 -0
- package/dist/rust-artifact.d.ts.map +1 -0
- package/dist/rust-artifact.js +15 -0
- package/dist/rust-artifact.js.map +1 -0
- package/dist/schema-calendar-date-values.d.ts +1 -0
- package/dist/schema-calendar-date-values.d.ts.map +1 -1
- package/dist/schema-calendar-date-values.js +4 -4
- package/dist/schema-calendar-date-values.js.map +1 -1
- package/dist/schema-calendar-dates.d.ts +16 -1
- package/dist/schema-calendar-dates.d.ts.map +1 -1
- package/dist/schema-calendar-dates.js +118 -19
- package/dist/schema-calendar-dates.js.map +1 -1
- package/dist/schema-conversion-loss-description.d.ts.map +1 -1
- package/dist/schema-conversion-loss-description.js +3 -0
- package/dist/schema-conversion-loss-description.js.map +1 -1
- package/dist/schema-conversion-loss-report.d.ts.map +1 -1
- package/dist/schema-conversion-loss-report.js +25 -36
- package/dist/schema-conversion-loss-report.js.map +1 -1
- package/dist/schema-conversion-loss-varying.d.ts +11 -0
- package/dist/schema-conversion-loss-varying.d.ts.map +1 -0
- package/dist/schema-conversion-loss-varying.js +44 -0
- package/dist/schema-conversion-loss-varying.js.map +1 -0
- package/dist/schema-converter-attr-maps.d.ts +6 -5
- package/dist/schema-converter-attr-maps.d.ts.map +1 -1
- package/dist/schema-converter-attr-maps.js +8 -6
- package/dist/schema-converter-attr-maps.js.map +1 -1
- package/dist/schema-converter-durations.d.ts +0 -3
- package/dist/schema-converter-durations.d.ts.map +1 -1
- package/dist/schema-converter-durations.js +0 -18
- package/dist/schema-converter-durations.js.map +1 -1
- package/dist/schema-converter-enums.d.ts +6 -3
- package/dist/schema-converter-enums.d.ts.map +1 -1
- package/dist/schema-converter-enums.js +25 -9
- package/dist/schema-converter-enums.js.map +1 -1
- package/dist/schema-converter-ifc4-slots.d.ts +10 -5
- package/dist/schema-converter-ifc4-slots.d.ts.map +1 -1
- package/dist/schema-converter-ifc4-slots.js +17 -20
- package/dist/schema-converter-ifc4-slots.js.map +1 -1
- package/dist/schema-converter-ifc4x3-upgrade.d.ts +5 -4
- package/dist/schema-converter-ifc4x3-upgrade.d.ts.map +1 -1
- package/dist/schema-converter-ifc4x3-upgrade.js +15 -8
- package/dist/schema-converter-ifc4x3-upgrade.js.map +1 -1
- package/dist/schema-converter-material-referent.d.ts +3 -0
- package/dist/schema-converter-material-referent.d.ts.map +1 -1
- package/dist/schema-converter-material-referent.js +24 -6
- package/dist/schema-converter-material-referent.js.map +1 -1
- package/dist/schema-converter-space-boundary.d.ts +47 -0
- package/dist/schema-converter-space-boundary.d.ts.map +1 -0
- package/dist/schema-converter-space-boundary.js +108 -0
- package/dist/schema-converter-space-boundary.js.map +1 -0
- package/dist/schema-converter-step-finish.d.ts.map +1 -1
- package/dist/schema-converter-step-finish.js +3 -2
- package/dist/schema-converter-step-finish.js.map +1 -1
- package/dist/schema-converter-structural-diagnostics.d.ts +6 -0
- package/dist/schema-converter-structural-diagnostics.d.ts.map +1 -1
- package/dist/schema-converter-structural-diagnostics.js +19 -4
- package/dist/schema-converter-structural-diagnostics.js.map +1 -1
- package/dist/schema-converter-structural-source.d.ts +3 -0
- package/dist/schema-converter-structural-source.d.ts.map +1 -1
- package/dist/schema-converter-structural-source.js.map +1 -1
- package/dist/schema-converter-structural-varying.d.ts +10 -2
- package/dist/schema-converter-structural-varying.d.ts.map +1 -1
- package/dist/schema-converter-structural-varying.js +28 -11
- package/dist/schema-converter-structural-varying.js.map +1 -1
- package/dist/schema-converter-structural.d.ts +3 -0
- package/dist/schema-converter-structural.d.ts.map +1 -1
- package/dist/schema-converter-structural.js +13 -5
- package/dist/schema-converter-structural.js.map +1 -1
- package/dist/schema-converter-typed-properties.js +1 -2
- package/dist/schema-converter-typed-properties.js.map +1 -1
- package/dist/schema-converter-unrooted-upgrade.d.ts +23 -6
- package/dist/schema-converter-unrooted-upgrade.d.ts.map +1 -1
- package/dist/schema-converter-unrooted-upgrade.js +62 -12
- package/dist/schema-converter-unrooted-upgrade.js.map +1 -1
- package/dist/schema-converter-value-forms.d.ts +28 -5
- package/dist/schema-converter-value-forms.d.ts.map +1 -1
- package/dist/schema-converter-value-forms.js +32 -19
- package/dist/schema-converter-value-forms.js.map +1 -1
- package/dist/schema-converter.d.ts +3 -4
- package/dist/schema-converter.d.ts.map +1 -1
- package/dist/schema-converter.js +25 -24
- package/dist/schema-converter.js.map +1 -1
- package/dist/schema-project-time-unit.d.ts +8 -0
- package/dist/schema-project-time-unit.d.ts.map +1 -0
- package/dist/schema-project-time-unit.js +123 -0
- package/dist/schema-project-time-unit.js.map +1 -0
- package/dist/schema-structural-varying-constant.d.ts +16 -0
- package/dist/schema-structural-varying-constant.d.ts.map +1 -0
- package/dist/schema-structural-varying-constant.js +36 -0
- package/dist/schema-structural-varying-constant.js.map +1 -0
- package/dist/schema-structural-varying-effective.d.ts +1 -1
- package/dist/schema-structural-varying-effective.d.ts.map +1 -1
- package/dist/schema-structural-varying-effective.js +12 -22
- package/dist/schema-structural-varying-effective.js.map +1 -1
- package/dist/schema-untranslatable.d.ts.map +1 -1
- package/dist/schema-untranslatable.js +5 -2
- package/dist/schema-untranslatable.js.map +1 -1
- package/dist/schema-work-control-durations.d.ts +13 -0
- package/dist/schema-work-control-durations.d.ts.map +1 -0
- package/dist/schema-work-control-durations.js +74 -0
- package/dist/schema-work-control-durations.js.map +1 -0
- package/dist/step-export-types.d.ts +3 -0
- package/dist/step-export-types.d.ts.map +1 -1
- package/dist/step-export-types.js.map +1 -1
- package/dist/step-exporter.d.ts.map +1 -1
- package/dist/step-exporter.js +2 -0
- package/dist/step-exporter.js.map +1 -1
- package/dist/step-omission-predicates.d.ts.map +1 -1
- package/dist/step-omission-predicates.js +3 -1
- package/dist/step-omission-predicates.js.map +1 -1
- package/dist/step-outer-args.d.ts +1 -1
- package/dist/step-outer-args.d.ts.map +1 -1
- package/dist/step-outer-args.js +10 -3
- package/dist/step-outer-args.js.map +1 -1
- package/dist/step-overlay-entities.d.ts.map +1 -1
- package/dist/step-overlay-entities.js +9 -0
- package/dist/step-overlay-entities.js.map +1 -1
- package/dist/step-pass-builder.d.ts.map +1 -1
- package/dist/step-pass-builder.js +21 -5
- package/dist/step-pass-builder.js.map +1 -1
- package/dist/step-property-set-readers.d.ts +4 -4
- package/dist/step-property-set-readers.d.ts.map +1 -1
- package/dist/step-property-set-readers.js +13 -13
- package/dist/step-property-set-readers.js.map +1 -1
- package/dist/step-retype-type-link.d.ts +7 -0
- package/dist/step-retype-type-link.d.ts.map +1 -0
- package/dist/step-retype-type-link.js +95 -0
- package/dist/step-retype-type-link.js.map +1 -0
- package/dist/step-source-iteration.d.ts.map +1 -1
- package/dist/step-source-iteration.js +10 -0
- package/dist/step-source-iteration.js.map +1 -1
- package/dist/step-subset-relations.d.ts +131 -0
- package/dist/step-subset-relations.d.ts.map +1 -0
- package/dist/step-subset-relations.js +342 -0
- package/dist/step-subset-relations.js.map +1 -0
- package/dist/step-subset-spatial-ancestors.d.ts +26 -0
- package/dist/step-subset-spatial-ancestors.d.ts.map +1 -0
- package/dist/step-subset-spatial-ancestors.js +103 -0
- package/dist/step-subset-spatial-ancestors.js.map +1 -0
- package/dist/step-subset-storey.d.ts +21 -0
- package/dist/step-subset-storey.d.ts.map +1 -0
- package/dist/step-subset-storey.js +319 -0
- package/dist/step-subset-storey.js.map +1 -0
- package/dist/step-subset.d.ts +68 -0
- package/dist/step-subset.d.ts.map +1 -0
- package/dist/step-subset.js +388 -0
- package/dist/step-subset.js.map +1 -0
- package/dist/unit-normalize.d.ts +14 -13
- package/dist/unit-normalize.d.ts.map +1 -1
- package/dist/unit-normalize.js +103 -85
- package/dist/unit-normalize.js.map +1 -1
- package/dist/xlsx-limits.d.ts +12 -0
- package/dist/xlsx-limits.d.ts.map +1 -0
- package/dist/xlsx-limits.js +48 -0
- package/dist/xlsx-limits.js.map +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
/**
|
|
5
|
+
* Spatial and nesting relations for an extracted subset: which ones join it, and
|
|
6
|
+
* what text each one emits.
|
|
7
|
+
*
|
|
8
|
+
* `IfcRelContainedInSpatialStructure` is one-to-MANY, and a real exporter
|
|
9
|
+
* writes exactly ONE of them per storey, naming every product in that storey.
|
|
10
|
+
* An all-or-nothing rule (keep the relation only when every id it mentions is
|
|
11
|
+
* kept) therefore drops containment on ANY strict subset of a real model: the
|
|
12
|
+
* extracted products land outside the spatial tree and a viewer shows the
|
|
13
|
+
* storey with nothing under it. So the `RelatedElements` SET is rewritten down
|
|
14
|
+
* to the kept members instead of the relation being dropped.
|
|
15
|
+
*
|
|
16
|
+
* The no-dangling-reference invariant is unchanged: every `#id` in an emitted
|
|
17
|
+
* record is an id the subset keeps, and since #4128 the caller's forward
|
|
18
|
+
* closure keeps only ids the file DEFINES, so kept implies defined. That covers
|
|
19
|
+
* the ids this module CHOOSES; it does not cover the references inside a kept
|
|
20
|
+
* record, which are emitted verbatim, so a source file that already dangles
|
|
21
|
+
* still dangles. That is the rest of the rules:
|
|
22
|
+
* - the RELATING object (`RelatingStructure` / `RelatingObject`, the spatial
|
|
23
|
+
* parent) is a hard requirement. A containment with no parent is
|
|
24
|
+
* meaningless, and it would dangle. `buildSubset` keeps every spatial
|
|
25
|
+
* ancestor of what it selected (a backward closure, #4124, see
|
|
26
|
+
* `step-subset-spatial-ancestors.ts`), so a kept product's parent is kept
|
|
27
|
+
* too, an `IfcSpace` included.
|
|
28
|
+
* - an empty intersection drops the relation.
|
|
29
|
+
* - every other non-set reference must be kept too. That is attribute 1,
|
|
30
|
+
* `OwnerHistory`; usually it already is, because each kept product's own
|
|
31
|
+
* body names the same shared `IfcOwnerHistory` and the products' forward
|
|
32
|
+
* closure keeps it. An exporter that writes a PER-RELATIONSHIP
|
|
33
|
+
* `IfcOwnerHistory` referenced by nothing else hits this rule every time,
|
|
34
|
+
* and dropping there was the orphaned-storey symptom again (#4126). This
|
|
35
|
+
* function still takes no `parsed`, so it cannot close over such a
|
|
36
|
+
* reference; it REPORTS it in {@link SpatialRelationPlan.blockedOn} and the
|
|
37
|
+
* caller, which does have `parsed`, decides whether to keep it and replan.
|
|
38
|
+
* Purity is intact: `blockedOn` is a finding, not a mutation.
|
|
39
|
+
*
|
|
40
|
+
* A KNOWN gap: {@link keepWhole}, the fallback for a record this module could
|
|
41
|
+
* not read as its six attributes, still drops on the same private
|
|
42
|
+
* `OwnerHistory` and reports nothing. That is deliberate. Its references are
|
|
43
|
+
* read off the raw body with no established string boundaries, so a `#6` it
|
|
44
|
+
* names may be text rather than a reference, and forward-closing over it would
|
|
45
|
+
* re-create the hash-in-a-Name bug the scanner exists to avoid.
|
|
46
|
+
*
|
|
47
|
+
* A relation that loses NO member re-emits its source line verbatim, so an
|
|
48
|
+
* extraction that happened to keep every member does not churn.
|
|
49
|
+
*
|
|
50
|
+
* ## Near-twins elsewhere in this package
|
|
51
|
+
*
|
|
52
|
+
* This module moved here from the CLI, where `@ifc-lite/export`'s internals
|
|
53
|
+
* were out of reach. Two near-twins remain, each different on purpose:
|
|
54
|
+
*
|
|
55
|
+
* - `filterHiddenRefsFromRelationshipLine` (`reference-collector.ts`) does
|
|
56
|
+
* the same job for EVERY parenthesised attribute of ANY `IFCREL*` line.
|
|
57
|
+
* Fed only today's three types it would change no behaviour, because the
|
|
58
|
+
* CALLER picks which lines it sees; widening the type set is the separate
|
|
59
|
+
* decision that changes which relations survive an extraction.
|
|
60
|
+
* - `splitTopLevelStepArguments` (`step-argument-parser.ts`): see
|
|
61
|
+
* {@link splitTopLevelArgs} for the two ways it differs.
|
|
62
|
+
*
|
|
63
|
+
* `merged-empty-containers.ts` keeps a private copy of `STRUCTURE_RELATIONS`.
|
|
64
|
+
*/
|
|
65
|
+
import { stepStringLiteralEnd } from '@ifc-lite/encoding';
|
|
66
|
+
import { skipStepComment, withoutComments } from './step-comment-skip.js';
|
|
67
|
+
import { slotRef } from './schema-converter-structural-source.js';
|
|
68
|
+
/**
|
|
69
|
+
* A selector that cannot be satisfied: `not-found` when it names nothing in the
|
|
70
|
+
* file, `invalid` when it names the wrong kind of record. Callers map `kind` to
|
|
71
|
+
* their own error codes instead of matching the message.
|
|
72
|
+
*/
|
|
73
|
+
export class SubsetSelectionError extends Error {
|
|
74
|
+
kind;
|
|
75
|
+
constructor(kind, message) {
|
|
76
|
+
super(message);
|
|
77
|
+
this.kind = kind;
|
|
78
|
+
this.name = 'SubsetSelectionError';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Spatial-structure relations, as `[relatingAttributeIndex, relatedAttributeIndex]`.
|
|
83
|
+
* `IfcRelAggregates` names the whole (`RelatingObject`) first; the two containment
|
|
84
|
+
* relations name the parts (`RelatedElements`) first. Same table as the private
|
|
85
|
+
* `STRUCTURE_RELATIONS` in `merged-empty-containers.ts`, which reads the same three
|
|
86
|
+
* records.
|
|
87
|
+
*
|
|
88
|
+
* `IfcRelReferencedInSpatialStructure` is here for the same reason the other two are:
|
|
89
|
+
* same shape (one relating parent, one related SET), same one-per-storey authoring,
|
|
90
|
+
* same claim in the command's own docs that the output "parses and renders on its
|
|
91
|
+
* own". It used to be missing entirely, so a referenced-but-not-contained product was
|
|
92
|
+
* always orphaned.
|
|
93
|
+
*/
|
|
94
|
+
export const STRUCTURE_RELATIONS = {
|
|
95
|
+
IFCRELAGGREGATES: [4, 5],
|
|
96
|
+
IFCRELCONTAINEDINSPATIALSTRUCTURE: [5, 4],
|
|
97
|
+
IFCRELREFERENCEDINSPATIALSTRUCTURE: [5, 4],
|
|
98
|
+
};
|
|
99
|
+
// Nesting has the same slots as aggregation. Its related objects are ordered,
|
|
100
|
+
// and the member filter below preserves their original order. Keep this row
|
|
101
|
+
// out of STRUCTURE_RELATIONS so nesting does not add spatial ancestors.
|
|
102
|
+
const SUBSET_RELATIONS = {
|
|
103
|
+
...STRUCTURE_RELATIONS,
|
|
104
|
+
IFCRELNESTS: STRUCTURE_RELATIONS.IFCRELAGGREGATES,
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* These relations are `GlobalId, OwnerHistory, Name, Description` plus the relating/related
|
|
108
|
+
* pair: exactly 6 attributes in every schema that defines them. A record that does not
|
|
109
|
+
* split into 6 was mis-scanned (or is not the entity the type name claims), so it falls
|
|
110
|
+
* back to keep-whole-or-drop-whole rather than having a slot index written into
|
|
111
|
+
* whatever it did split into.
|
|
112
|
+
*
|
|
113
|
+
* A relation type with a different attribute COUNT (`IfcRelAssignsToGroup` has 7)
|
|
114
|
+
* therefore cannot simply be added as a row above: it would fail this check on every
|
|
115
|
+
* record and fall silently back to keep-whole-or-drop-whole, which is the bug this
|
|
116
|
+
* module exists to fix. Such a type needs the count moved into the table value first,
|
|
117
|
+
* or the table derived from the schema registry, which returns 7 for that entity. Filed as #4123.
|
|
118
|
+
*/
|
|
119
|
+
export const STRUCTURE_RELATION_ATTRS = 6;
|
|
120
|
+
/**
|
|
121
|
+
* Decide every spatial or nesting relation against a kept-id set.
|
|
122
|
+
*
|
|
123
|
+
* Pure in both arguments: adding relation ids to `keep` afterwards cannot
|
|
124
|
+
* change any verdict, because a relation of these types references products,
|
|
125
|
+
* spatial containers and an OwnerHistory, never another relation.
|
|
126
|
+
*/
|
|
127
|
+
export function planSpatialRelations(instances, keep) {
|
|
128
|
+
const add = [];
|
|
129
|
+
const rewritten = new Map();
|
|
130
|
+
const blockedOn = [];
|
|
131
|
+
for (const inst of instances) {
|
|
132
|
+
const slots = SUBSET_RELATIONS[inst.type];
|
|
133
|
+
if (slots === undefined)
|
|
134
|
+
continue;
|
|
135
|
+
const line = relationLine(inst, slots, keep, blockedOn);
|
|
136
|
+
if (line === null)
|
|
137
|
+
continue;
|
|
138
|
+
add.push(inst.id);
|
|
139
|
+
if (line !== inst.full)
|
|
140
|
+
rewritten.set(inst.id, line);
|
|
141
|
+
}
|
|
142
|
+
return { add, rewritten, blockedOn };
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The record text this relation contributes to the subset, or null to drop it.
|
|
146
|
+
* Returns `inst.full` unchanged when nothing was filtered out. Appends ONE entry
|
|
147
|
+
* to `blocked` when the ONLY thing standing in the way is unkept non-member
|
|
148
|
+
* references; see {@link SpatialRelationPlan.blockedOn}.
|
|
149
|
+
*/
|
|
150
|
+
function relationLine(inst, [relatingIdx, relatedIdx], keep, blocked) {
|
|
151
|
+
// A null is a REJECTED scan, not an empty list: its parts are wherever the
|
|
152
|
+
// scanner happened to be, so reading `args[relatingIdx]` or writing
|
|
153
|
+
// `args[relatedIdx]` by index would land on the wrong attribute (#2470).
|
|
154
|
+
const args = splitTopLevelArgs(inst.body);
|
|
155
|
+
if (args === null || args.length !== STRUCTURE_RELATION_ATTRS)
|
|
156
|
+
return keepWhole(inst, keep);
|
|
157
|
+
// Comments around the member list and its references are trivia.
|
|
158
|
+
const setText = withoutComments(args[relatedIdx]);
|
|
159
|
+
if (!setText.startsWith('(') || !setText.endsWith(')'))
|
|
160
|
+
return keepWhole(inst, keep);
|
|
161
|
+
const members = splitTopLevelArgs(setText.slice(1, -1));
|
|
162
|
+
if (members === null)
|
|
163
|
+
return keepWhole(inst, keep);
|
|
164
|
+
const memberIds = [];
|
|
165
|
+
for (const member of members) {
|
|
166
|
+
const ref = slotRef(member);
|
|
167
|
+
// A member that is not a plain object reference is not something this
|
|
168
|
+
// rewrite understands; fall back rather than guess at it.
|
|
169
|
+
if (ref === null)
|
|
170
|
+
return keepWhole(inst, keep);
|
|
171
|
+
memberIds.push(ref);
|
|
172
|
+
}
|
|
173
|
+
// The relating parent must be a real, kept reference. The `every reference
|
|
174
|
+
// outside the member list is kept` loop below would pass VACUOUSLY on a `$` here,
|
|
175
|
+
// emitting a containment with no parent.
|
|
176
|
+
const relating = slotRef(args[relatingIdx]);
|
|
177
|
+
if (relating === null || !keep.has(relating))
|
|
178
|
+
return null;
|
|
179
|
+
const kept = memberIds.filter((id) => keep.has(id));
|
|
180
|
+
if (kept.length === 0)
|
|
181
|
+
return null;
|
|
182
|
+
// Every other reference (OwnerHistory) must be kept or the emitted
|
|
183
|
+
// record dangles. Ordered AFTER the intersection so `blocked` names only the
|
|
184
|
+
// references of a relation that would OTHERWISE survive; both checks drop the
|
|
185
|
+
// relation, so which one runs first changes no verdict.
|
|
186
|
+
const unkept = [];
|
|
187
|
+
for (let i = 0; i < args.length; i++) {
|
|
188
|
+
if (i === relatedIdx)
|
|
189
|
+
continue;
|
|
190
|
+
for (const id of refsOutsideStrings(args[i])) {
|
|
191
|
+
if (!keep.has(id))
|
|
192
|
+
unkept.push(id);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (unkept.length > 0) {
|
|
196
|
+
blocked.push(unkept);
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
if (kept.length === memberIds.length)
|
|
200
|
+
return inst.full;
|
|
201
|
+
return spliceArgument(inst, args, relatedIdx, `(${kept.map((id) => `#${id}`).join(',')})`);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The `#id` object references in one argument, ignoring any that sit inside a
|
|
205
|
+
* STEP string literal.
|
|
206
|
+
*
|
|
207
|
+
* A relation's `Name` and `Description` are free TEXT, and free text contains
|
|
208
|
+
* `#`; `parseStep` tokenizes rather than regexes precisely because Revit
|
|
209
|
+
* writes names like that. Read raw, the `#99` in `'Level #99 contents'` looks
|
|
210
|
+
* like a reference to entity 99, and one unkept lookalike drops the WHOLE
|
|
211
|
+
* relation: the orphaned-storey bug this module exists to fix, re-created for
|
|
212
|
+
* any model that names a relation that way.
|
|
213
|
+
*
|
|
214
|
+
* Correct only on an argument whose split VALIDATED, so the quote boundaries
|
|
215
|
+
* are the record's own. {@link keepWhole} deliberately does NOT use this. It
|
|
216
|
+
* runs when the split FAILED, and also when it succeeded but the record is not
|
|
217
|
+
* the six-attribute shape this module rewrites, so its boundaries are not
|
|
218
|
+
* established in general. There, over-counting references (drop the record) is
|
|
219
|
+
* the safe error, while under-counting (emit a dangling `#id`) is not.
|
|
220
|
+
*
|
|
221
|
+
* Exported for `step-subset.ts`'s `forwardClosure`, which has the same
|
|
222
|
+
* hazard scanning a whole record body for its reference closure: nothing here
|
|
223
|
+
* assumes `arg` is one split ARGUMENT rather than a whole body, since a comma
|
|
224
|
+
* or `)` outside a string does not affect the in-string/out-of-string state
|
|
225
|
+
* this walks.
|
|
226
|
+
*/
|
|
227
|
+
export function refsOutsideStrings(arg) {
|
|
228
|
+
const ids = [];
|
|
229
|
+
for (let i = 0; i < arg.length; i++) {
|
|
230
|
+
const char = arg[i];
|
|
231
|
+
if (char === '/' && arg[i + 1] === '*') {
|
|
232
|
+
// A comment is trivia: a `#id` inside it is not a reference.
|
|
233
|
+
i = skipStepComment(arg, i) - 1;
|
|
234
|
+
}
|
|
235
|
+
else if (char === "'") {
|
|
236
|
+
// #7589: the shared literal-end rule (`''`, PAGE-directive operand).
|
|
237
|
+
const end = stepStringLiteralEnd(arg, i);
|
|
238
|
+
if (end < 0)
|
|
239
|
+
break; // never closes: the rest is string text
|
|
240
|
+
i = end - 1;
|
|
241
|
+
}
|
|
242
|
+
else if (char === '#') {
|
|
243
|
+
let start = i + 1;
|
|
244
|
+
while (start < arg.length && /\s/.test(arg[start]))
|
|
245
|
+
start++;
|
|
246
|
+
let end = start;
|
|
247
|
+
while (end < arg.length && arg[end] >= '0' && arg[end] <= '9')
|
|
248
|
+
end++;
|
|
249
|
+
if (end > start)
|
|
250
|
+
ids.push(Number(arg.slice(start, end)));
|
|
251
|
+
i = end - 1;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return ids;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Keep-whole-or-drop-whole, for a record this module could not scan, or could
|
|
258
|
+
* not read as its six attributes. Reads references straight off the raw body,
|
|
259
|
+
* so it needs no argument boundaries to be correct. Same no-dangling guarantee,
|
|
260
|
+
* no rewriting.
|
|
261
|
+
*/
|
|
262
|
+
function keepWhole(inst, keep) {
|
|
263
|
+
// Comments are trivia; string text is still over-counted, the safe direction.
|
|
264
|
+
const refs = [...withoutComments(inst.body).matchAll(/#\s*(\d+)/g)].map((m) => Number(m[1]));
|
|
265
|
+
return refs.length > 0 && refs.every((r) => keep.has(r)) ? inst.full : null;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Re-emit the record with ONE top-level argument replaced. Rejoining the split
|
|
269
|
+
* arguments normalizes only the whitespace BETWEEN them (each argument's own
|
|
270
|
+
* text is untouched), and this runs only for a relation that actually lost a
|
|
271
|
+
* member, so an unfiltered subset stays byte-identical.
|
|
272
|
+
*/
|
|
273
|
+
function spliceArgument(inst, args, index, replacement) {
|
|
274
|
+
const open = inst.bodyStart !== undefined ? inst.bodyStart - 1 : inst.full.indexOf('(');
|
|
275
|
+
// `bodyStart` from the parser is the authority (a comment before the type
|
|
276
|
+
// may hold a `(`); the first `(` is only the fallback for records built
|
|
277
|
+
// without it. A mismatch would mean the parser and this module disagree about
|
|
278
|
+
// where the arguments are, and splicing on that offset corrupts the record,
|
|
279
|
+
// so drop it instead of emitting something malformed.
|
|
280
|
+
if (open < 0 || inst.full.slice(open + 1, open + 1 + inst.body.length) !== inst.body)
|
|
281
|
+
return null;
|
|
282
|
+
const next = [...args];
|
|
283
|
+
next[index] = replacement;
|
|
284
|
+
return inst.full.slice(0, open + 1) + next.join(',') + inst.full.slice(open + 1 + inst.body.length);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Split a STEP argument list on top-level commas, respecting nested parens,
|
|
288
|
+
* quoted strings, doubled-quote escapes, and `/* ... *\/` comments (#4227).
|
|
289
|
+
* Returns null on an unterminated string, an unbalanced paren depth, or a
|
|
290
|
+
* depth that ever goes negative -- {@link relationLine} writes a slot by
|
|
291
|
+
* index (#2470), so a mis-scanned list must not hand back parts that look
|
|
292
|
+
* like success. A comma/paren/quote inside a comment is skipped with it (see
|
|
293
|
+
* {@link skipStepComment}): unskipped, its comma shifts every later slot
|
|
294
|
+
* boundary and `relationLine` either mis-splices a member or falls back to
|
|
295
|
+
* {@link keepWhole}, dropping a relation that should have survived -- the
|
|
296
|
+
* orphaned-storey symptom (#4126) this module exists to fix, by a different
|
|
297
|
+
* route. An EMPTY INTERIOR slot (`a,,b`) is one part, not rejected.
|
|
298
|
+
*
|
|
299
|
+
* Near-twin of `splitTopLevelStepArguments` in `step-argument-parser.ts` (see
|
|
300
|
+
* the module header). Two differences: each part is `trim`med (because
|
|
301
|
+
* `slotRef` reads one reference per slot), and a TRAILING empty slot (`a,b,`)
|
|
302
|
+
* yields 2 parts, not 3.
|
|
303
|
+
*/
|
|
304
|
+
export function splitTopLevelArgs(text) {
|
|
305
|
+
const parts = [];
|
|
306
|
+
let start = 0;
|
|
307
|
+
let depth = 0;
|
|
308
|
+
for (let i = 0; i < text.length; i++) {
|
|
309
|
+
const char = text[i];
|
|
310
|
+
if (char === '/' && text[i + 1] === '*') {
|
|
311
|
+
// See skipStepComment's docstring: its content is skipped as one unit,
|
|
312
|
+
// not read as argument-list structure.
|
|
313
|
+
i = skipStepComment(text, i) - 1;
|
|
314
|
+
}
|
|
315
|
+
else if (char === "'") {
|
|
316
|
+
// `''` and the PAGE directive's apostrophe operand (#7589) stay inside.
|
|
317
|
+
const end = stepStringLiteralEnd(text, i);
|
|
318
|
+
if (end < 0)
|
|
319
|
+
return null; // unterminated string
|
|
320
|
+
i = end - 1;
|
|
321
|
+
}
|
|
322
|
+
else if (char === '(') {
|
|
323
|
+
depth++;
|
|
324
|
+
}
|
|
325
|
+
else if (char === ')') {
|
|
326
|
+
depth--;
|
|
327
|
+
if (depth < 0)
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
else if (char === ',' && depth === 0) {
|
|
331
|
+
parts.push(text.slice(start, i).trim());
|
|
332
|
+
start = i + 1;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (depth !== 0)
|
|
336
|
+
return null;
|
|
337
|
+
const tail = text.slice(start).trim();
|
|
338
|
+
if (tail)
|
|
339
|
+
parts.push(tail);
|
|
340
|
+
return parts;
|
|
341
|
+
}
|
|
342
|
+
//# sourceMappingURL=step-subset-relations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-subset-relations.js","sourceRoot":"","sources":["../src/step-subset-relations.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AAElE;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IACxB;IAArB,YAAqB,IAA6B,EAAE,OAAe;QACjE,KAAK,CAAC,OAAO,CAAC,CAAC;QADI,SAAI,GAAJ,IAAI,CAAyB;QAEhD,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AA8CD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAqC;IACnE,gBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACxB,iCAAiC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACzC,kCAAkC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;CAC3C,CAAC;AAEF,8EAA8E;AAC9E,4EAA4E;AAC5E,wEAAwE;AACxE,MAAM,gBAAgB,GAAqC;IACzD,GAAG,mBAAmB;IACtB,WAAW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CAAC;IACtC,IAAI,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type StepRecord } from './step-subset-relations.js';
|
|
2
|
+
/**
|
|
3
|
+
* Related-child id → its relating-parent id(s), across the three structure
|
|
4
|
+
* relation types.
|
|
5
|
+
*
|
|
6
|
+
* `IfcRelAggregates` ALSO expresses plain element decomposition (an
|
|
7
|
+
* `IfcElementAssembly` and its parts), which reuses this same relation type
|
|
8
|
+
* and six-attribute shape but is not a spatial ancestor: keeping the whole
|
|
9
|
+
* assembly because one of its parts was independently selected is a different
|
|
10
|
+
* bug, not this one (`step-subset.test.ts` pins the opposite behaviour).
|
|
11
|
+
* A row is only added for this table when the relating object's OWN type is a
|
|
12
|
+
* spatial-structure type, so a decomposition parent can never enter it.
|
|
13
|
+
*
|
|
14
|
+
* Silently skips a record `splitTopLevelArgs` cannot read cleanly, or that
|
|
15
|
+
* does not split into the six attributes every one of these types has: this
|
|
16
|
+
* map only ever ADDS candidate ancestors for `buildSubset` to keep, so
|
|
17
|
+
* skipping is the fail-closed direction, unlike `step-subset-relations.ts`'s own
|
|
18
|
+
* keep-whole-or-drop-whole fallback for the same shape.
|
|
19
|
+
*/
|
|
20
|
+
export declare function structureParents(instances: ReadonlyMap<number, StepRecord>, relations?: ReadonlySet<string>): Map<number, number[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Every ancestor of `seeds`, reached by climbing {@link structureParents}
|
|
23
|
+
* transitively. Order is unspecified; callers forward-close the result.
|
|
24
|
+
*/
|
|
25
|
+
export declare function spatialAncestors(seeds: Iterable<number>, instances: ReadonlyMap<number, StepRecord>): number[];
|
|
26
|
+
//# sourceMappingURL=step-subset-spatial-ancestors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-subset-spatial-ancestors.d.ts","sourceRoot":"","sources":["../src/step-subset-spatial-ancestors.ts"],"names":[],"mappings":"AAyBA,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,4BAA4B,CAAC;AAEpC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EAC1C,SAAS,GAAE,WAAW,CAAC,MAAM,CAA6C,GACzE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CA4BvB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,MAAM,EAAE,CAe9G"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
/**
|
|
5
|
+
* Backward closure over the spatial-structure relations, for `buildSubset`'s
|
|
6
|
+
* context-root seeding (#4124).
|
|
7
|
+
*
|
|
8
|
+
* `buildSubset` used to force-keep every `IfcProject` / `IfcSite` /
|
|
9
|
+
* `IfcBuilding` / `IfcBuildingStorey` as a context root, unconditionally. That
|
|
10
|
+
* both keeps every storey whether or not anything selected sits under it, AND
|
|
11
|
+
* never keeps an `IfcSpace` / `IfcSpatialZone` / IFC4X3 facility class, so a
|
|
12
|
+
* product contained in one of those has an unkept `RelatingStructure` and
|
|
13
|
+
* loses its containment relation (the same orphaning symptom #4113 fixed for
|
|
14
|
+
* storeys, from a different cause).
|
|
15
|
+
*
|
|
16
|
+
* The fix is a BACKWARD closure: from each id already kept, climb
|
|
17
|
+
* `IfcRelContainedInSpatialStructure` / `IfcRelReferencedInSpatialStructure` to
|
|
18
|
+
* its `RelatingStructure`, and `IfcRelAggregates` to its `RelatingObject`,
|
|
19
|
+
* transitively, up to `IfcProject`. That keeps exactly the ancestors of what
|
|
20
|
+
* was actually selected, and needs no type list at all.
|
|
21
|
+
*/
|
|
22
|
+
import { IfcTypeEnumFromString, isSpatialStructureType } from '@ifc-lite/data';
|
|
23
|
+
import { slotRef } from './schema-converter-structural-source.js';
|
|
24
|
+
import { withoutComments } from './step-comment-skip.js';
|
|
25
|
+
import { splitTopLevelArgs, STRUCTURE_RELATIONS, STRUCTURE_RELATION_ATTRS, } from './step-subset-relations.js';
|
|
26
|
+
/**
|
|
27
|
+
* Related-child id → its relating-parent id(s), across the three structure
|
|
28
|
+
* relation types.
|
|
29
|
+
*
|
|
30
|
+
* `IfcRelAggregates` ALSO expresses plain element decomposition (an
|
|
31
|
+
* `IfcElementAssembly` and its parts), which reuses this same relation type
|
|
32
|
+
* and six-attribute shape but is not a spatial ancestor: keeping the whole
|
|
33
|
+
* assembly because one of its parts was independently selected is a different
|
|
34
|
+
* bug, not this one (`step-subset.test.ts` pins the opposite behaviour).
|
|
35
|
+
* A row is only added for this table when the relating object's OWN type is a
|
|
36
|
+
* spatial-structure type, so a decomposition parent can never enter it.
|
|
37
|
+
*
|
|
38
|
+
* Silently skips a record `splitTopLevelArgs` cannot read cleanly, or that
|
|
39
|
+
* does not split into the six attributes every one of these types has: this
|
|
40
|
+
* map only ever ADDS candidate ancestors for `buildSubset` to keep, so
|
|
41
|
+
* skipping is the fail-closed direction, unlike `step-subset-relations.ts`'s own
|
|
42
|
+
* keep-whole-or-drop-whole fallback for the same shape.
|
|
43
|
+
*/
|
|
44
|
+
export function structureParents(instances, relations = new Set(Object.keys(STRUCTURE_RELATIONS))) {
|
|
45
|
+
const parents = new Map();
|
|
46
|
+
for (const inst of instances.values()) {
|
|
47
|
+
const slots = STRUCTURE_RELATIONS[inst.type];
|
|
48
|
+
if (slots === undefined || !relations.has(inst.type))
|
|
49
|
+
continue;
|
|
50
|
+
const [relatingIdx, relatedIdx] = slots;
|
|
51
|
+
const args = splitTopLevelArgs(inst.body);
|
|
52
|
+
if (args === null || args.length !== STRUCTURE_RELATION_ATTRS)
|
|
53
|
+
continue;
|
|
54
|
+
// Comments around a reference are trivia (slotRef / withoutComments).
|
|
55
|
+
const parentId = slotRef(args[relatingIdx]);
|
|
56
|
+
if (parentId === null)
|
|
57
|
+
continue;
|
|
58
|
+
if (inst.type === 'IFCRELAGGREGATES') {
|
|
59
|
+
const parentType = IfcTypeEnumFromString(instances.get(parentId)?.type ?? '');
|
|
60
|
+
if (!isSpatialStructureType(parentType))
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const setText = withoutComments(args[relatedIdx]);
|
|
64
|
+
if (!setText.startsWith('(') || !setText.endsWith(')'))
|
|
65
|
+
continue;
|
|
66
|
+
const members = splitTopLevelArgs(setText.slice(1, -1));
|
|
67
|
+
if (members === null)
|
|
68
|
+
continue;
|
|
69
|
+
for (const member of members) {
|
|
70
|
+
const childId = slotRef(member);
|
|
71
|
+
if (childId === null)
|
|
72
|
+
continue;
|
|
73
|
+
const existing = parents.get(childId);
|
|
74
|
+
if (existing)
|
|
75
|
+
existing.push(parentId);
|
|
76
|
+
else
|
|
77
|
+
parents.set(childId, [parentId]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return parents;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Every ancestor of `seeds`, reached by climbing {@link structureParents}
|
|
84
|
+
* transitively. Order is unspecified; callers forward-close the result.
|
|
85
|
+
*/
|
|
86
|
+
export function spatialAncestors(seeds, instances) {
|
|
87
|
+
const parents = structureParents(instances);
|
|
88
|
+
const visited = new Set();
|
|
89
|
+
const ancestors = [];
|
|
90
|
+
const stack = [...seeds];
|
|
91
|
+
while (stack.length) {
|
|
92
|
+
const id = stack.pop();
|
|
93
|
+
for (const parentId of parents.get(id) ?? []) {
|
|
94
|
+
if (visited.has(parentId))
|
|
95
|
+
continue;
|
|
96
|
+
visited.add(parentId);
|
|
97
|
+
ancestors.push(parentId);
|
|
98
|
+
stack.push(parentId);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return ancestors;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=step-subset-spatial-ancestors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-subset-spatial-ancestors.js","sourceRoot":"","sources":["../src/step-subset-spatial-ancestors.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,GAEzB,MAAM,4BAA4B,CAAC;AAEpC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAA0C,EAC1C,YAAiC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAE1E,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC5C,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,SAAS;QAC/D,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC;QACxC,MAAM,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,wBAAwB;YAAE,SAAS;QACxE,s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C,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IACzB,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,EAAG,CAAC;QACxB,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;YAC7C,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;gBAAE,SAAS;YACpC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACtB,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ParsedStep } from './step-subset.js';
|
|
2
|
+
/** Every product whose ObjectPlacement chains up through `storeyPlacementId`. */
|
|
3
|
+
export declare function productsUnderPlacement(storeyPlacementId: number, parsed: ParsedStep, schemaVersion?: string): Set<number>;
|
|
4
|
+
/** Resolve a --storey selector (GUID / name / expressId) to the storey and its placement. */
|
|
5
|
+
export declare function resolveStorey(token: string, parsed: ParsedStep): {
|
|
6
|
+
storeyId: number;
|
|
7
|
+
placementId: number | undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare function resolveStoreyArgument(token: string, parsed: ParsedStep, splitLists: boolean): ReturnType<typeof resolveStorey>[];
|
|
10
|
+
/**
|
|
11
|
+
* A storey's products: every element whose nearest storey in the spatial tree
|
|
12
|
+
* is this one (contained in it, or in a space or zone it aggregates), wherever
|
|
13
|
+
* it is placed; plus, for elements the spatial tree assigns to no storey, those
|
|
14
|
+
* whose placement chains through the storey's. Explicit ownership keeps
|
|
15
|
+
* assigned products separate even when storeys share a placement. A reference
|
|
16
|
+
* (IfcRelReferencedInSpatialStructure) is not ownership. A containment record
|
|
17
|
+
* that cannot be read leaves its element unowned, so the placement decides.
|
|
18
|
+
* Spatial-structure records other than IfcSpace are never products.
|
|
19
|
+
*/
|
|
20
|
+
export declare function storeyMembers(storeyId: number, placementId: number | undefined, parsed: ParsedStep, schemaVersion?: string): number[];
|
|
21
|
+
//# sourceMappingURL=step-subset-storey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-subset-storey.d.ts","sourceRoot":"","sources":["../src/step-subset-storey.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAoBnD,iFAAiF;AACjF,wBAAgB,sBAAsB,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CA0BzH;AAyBD,6FAA6F;AAC7F,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAqDtH;AAMD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,EAAE,CAchI;AAkDD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,MAAM,GAC5F,MAAM,EAAE,CAsEV"}
|