@bitbybit-dev/ifc 1.5.0 → 1.6.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 +11 -5
- package/lib/api/dto-registry.js +3 -1
- package/lib/api/ifc-service.d.ts +10 -5
- package/lib/api/ifc-service.js +7 -5
- package/lib/api/inputs/ifc-inputs.d.ts +121 -5
- package/lib/api/inputs/ifc-inputs.js +162 -5
- package/lib/api/resolved-inputs/index.d.ts +6 -3
- package/lib/api/services/doors.js +4 -1
- package/lib/api/services/elements.d.ts +28 -0
- package/lib/api/services/elements.js +60 -0
- package/lib/api/services/geometry.js +3 -3
- package/lib/api/services/index.d.ts +1 -0
- package/lib/api/services/index.js +1 -0
- package/lib/api/services/member-support.js +2 -2
- package/lib/api/services/model.js +3 -3
- package/lib/api/services/openings.js +16 -11
- package/lib/api/services/properties.js +4 -3
- package/lib/api/services/site.js +3 -1
- package/lib/api/services/spaces.js +1 -0
- package/lib/api/services/walls.d.ts +7 -5
- package/lib/api/services/walls.js +15 -7
- package/lib/api/services/windows.js +5 -2
- package/lib/build/assemblies.js +1 -1
- package/lib/build/bodied-elements.d.ts +5 -0
- package/lib/build/bodied-elements.js +35 -0
- package/lib/build/build-types.d.ts +29 -2
- package/lib/build/checks.d.ts +2 -0
- package/lib/build/checks.js +14 -0
- package/lib/build/clipping-registry.d.ts +3 -0
- package/lib/build/clipping-registry.js +39 -0
- package/lib/build/constants.d.ts +0 -1
- package/lib/build/constants.js +0 -1
- package/lib/build/entity-writer.js +4 -6
- package/lib/build/exact-bodies.d.ts +4 -0
- package/lib/build/exact-bodies.js +273 -0
- package/lib/build/fillings.js +1 -1
- package/lib/build/math.d.ts +3 -2
- package/lib/build/math.js +24 -16
- package/lib/build/measure.js +11 -11
- package/lib/build/moving.js +12 -11
- package/lib/build/openings.js +1 -1
- package/lib/build/outlines.d.ts +2 -0
- package/lib/build/outlines.js +14 -2
- package/lib/build/placement.js +4 -3
- package/lib/build/project.js +1 -1
- package/lib/build/quantities.js +13 -11
- package/lib/build/roof-clipping.js +5 -5
- package/lib/build/roofs.js +17 -16
- package/lib/build/site.js +9 -13
- package/lib/build/slab-openings.js +4 -4
- package/lib/build/slabs-columns-beams.js +16 -19
- package/lib/build/solids.js +3 -2
- package/lib/build/spaces.js +8 -6
- package/lib/build/spatial.js +1 -1
- package/lib/build/wall-edits.js +21 -15
- package/lib/build/wall-geometry.d.ts +2 -1
- package/lib/build/wall-geometry.js +48 -18
- package/lib/build/wall-parameters.js +7 -3
- package/lib/build/walls.js +15 -8
- package/lib/geometry/advanced.js +12 -13
- package/lib/geometry/curves.d.ts +2 -1
- package/lib/geometry/curves.js +27 -10
- package/lib/geometry/edges.js +6 -9
- package/lib/geometry/elements.d.ts +1 -1
- package/lib/geometry/elements.js +22 -5
- package/lib/geometry/exact-brep.constants.d.ts +1 -0
- package/lib/geometry/exact-brep.constants.js +1 -0
- package/lib/geometry/exact-brep.d.ts +11 -0
- package/lib/geometry/exact-brep.js +371 -0
- package/lib/geometry/faceted.d.ts +1 -0
- package/lib/geometry/faceted.js +20 -8
- package/lib/geometry/geometry-types.d.ts +9 -1
- package/lib/geometry/items.d.ts +2 -0
- package/lib/geometry/items.js +34 -5
- package/lib/geometry/operators.js +1 -1
- package/lib/geometry/profiles.js +9 -5
- package/lib/geometry/surfaces.constants.d.ts +1 -0
- package/lib/geometry/surfaces.constants.js +1 -0
- package/lib/geometry/surfaces.d.ts +1 -1
- package/lib/geometry/surfaces.js +8 -6
- package/lib/geometry/swept-solids.constants.d.ts +1 -0
- package/lib/geometry/swept-solids.constants.js +1 -0
- package/lib/geometry/swept-solids.js +22 -12
- package/lib/model/io.js +1 -1
- package/lib/model/owner-history.d.ts +2 -0
- package/lib/model/owner-history.js +101 -0
- package/lib/model/snapshot.d.ts +1 -0
- package/lib/model/snapshot.js +4 -0
- package/lib/model/transaction.js +19 -10
- package/lib/model/upgrade-rows.d.ts +26 -0
- package/lib/model/upgrade-rows.js +240 -0
- package/lib/model/upgrade-types.d.ts +9 -0
- package/lib/model/upgrade-types.js +1 -0
- package/lib/model/upgrade.js +20 -7
- package/lib/schema/registry.js +1 -1
- package/package.json +2 -3
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { enumValue, isEnumeration, isList, isReference, referencesIn, ref } from "../step/values";
|
|
2
|
+
import { automaticGlobalId, randomGlobalId } from "./guid";
|
|
3
|
+
const CALENDAR_DATE = "IFCCALENDARDATE";
|
|
4
|
+
const LOCAL_TIME = "IFCLOCALTIME";
|
|
5
|
+
const DATE_AND_TIME = "IFCDATEANDTIME";
|
|
6
|
+
const TIME_OFFSET = "IFCCOORDINATEDUNIVERSALTIMEOFFSET";
|
|
7
|
+
const DATE_ROWS = new Set([CALENDAR_DATE, LOCAL_TIME, DATE_AND_TIME, TIME_OFFSET]);
|
|
8
|
+
const USER_DEFINED = "USERDEFINED";
|
|
9
|
+
const NOT_DEFINED = "NOTDEFINED";
|
|
10
|
+
const STRING = "STRING";
|
|
11
|
+
const BEHIND = "BEHIND";
|
|
12
|
+
const VIRTUAL = "VIRTUAL";
|
|
13
|
+
const MIDNIGHT = "00:00:00";
|
|
14
|
+
const YEAR_DIGITS = 4;
|
|
15
|
+
const TWO_DIGITS = 2;
|
|
16
|
+
const SPACE_BOUNDARY = "IfcRelSpaceBoundary";
|
|
17
|
+
const BOUNDED_BY = "RelatedBuildingElement";
|
|
18
|
+
const VIRTUAL_ELEMENT = "IfcVirtualElement";
|
|
19
|
+
const VIRTUAL_ELEMENT_NAME = "Virtual boundary";
|
|
20
|
+
const NAMED_BY = ["ElementType", "ObjectType"];
|
|
21
|
+
const DROPPED_TRAILING = new Map([
|
|
22
|
+
["IfcLShapeProfileDef", 2],
|
|
23
|
+
["IfcTShapeProfileDef", 1],
|
|
24
|
+
["IfcUShapeProfileDef", 1],
|
|
25
|
+
["IfcCShapeProfileDef", 1],
|
|
26
|
+
["IfcDistributionControlElement", 1],
|
|
27
|
+
["IfcTransportElement", 2],
|
|
28
|
+
]);
|
|
29
|
+
const DIRECTION = "IfcDirection";
|
|
30
|
+
const TRUE_NORTH = "TrueNorth";
|
|
31
|
+
const PREDEFINED_TYPE = "PredefinedType";
|
|
32
|
+
const SPATIAL = 3;
|
|
33
|
+
const TYPE_PRODUCT_ATTRIBUTES = 8;
|
|
34
|
+
const RESTYLED = new Map([
|
|
35
|
+
["IfcDoorStyle", { type: "IfcDoorType", kind: "DOOR", operation: 0 }],
|
|
36
|
+
["IfcWindowStyle", { type: "IfcWindowType", kind: "WINDOW", operation: 1 }],
|
|
37
|
+
]);
|
|
38
|
+
const PRECEDENCE = 2;
|
|
39
|
+
const FACETED_BREPS = new Set(["IfcFacetedBrep", "IfcFacetedBrepWithVoids"]);
|
|
40
|
+
const SURFACE_MODEL = "SurfaceModel";
|
|
41
|
+
const SHELL_SURFACE_MODEL = "IfcShellBasedSurfaceModel";
|
|
42
|
+
const SHAPE_REPRESENTATION = "IfcShapeRepresentation";
|
|
43
|
+
const PRESENTATION = ["IfcStyledItem", "IfcPresentationLayerAssignment"];
|
|
44
|
+
const OWNER_HISTORY = "IfcOwnerHistory";
|
|
45
|
+
const DATED_ACTIONS = new Set(["ADDED", "MODIFIED", "DELETED"]);
|
|
46
|
+
function twoDigits(value) {
|
|
47
|
+
return String(Math.trunc(value)).padStart(TWO_DIGITS, "0");
|
|
48
|
+
}
|
|
49
|
+
function secondsText(value) {
|
|
50
|
+
const [whole, fraction] = String(value).split(".");
|
|
51
|
+
return `${whole.padStart(TWO_DIGITS, "0")}${fraction === undefined ? "" : `.${fraction}`}`;
|
|
52
|
+
}
|
|
53
|
+
function numberIn(args, index, id) {
|
|
54
|
+
const value = args === null || args === void 0 ? void 0 : args[index];
|
|
55
|
+
if (typeof value !== "number") {
|
|
56
|
+
throw new Error(`#${id} is an IFC2X3 date or time without the number IFC4's text needs, so the file cannot be upgraded`);
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
function optionalNumberIn(args, index) {
|
|
61
|
+
const value = args === null || args === void 0 ? void 0 : args[index];
|
|
62
|
+
return typeof value === "number" ? value : 0;
|
|
63
|
+
}
|
|
64
|
+
function dateTextFor(type, parts) {
|
|
65
|
+
var _a;
|
|
66
|
+
switch (type) {
|
|
67
|
+
case "IfcDate": return parts.date;
|
|
68
|
+
case "IfcDateTime": return parts.date === undefined ? undefined : `${parts.date}T${(_a = parts.time) !== null && _a !== void 0 ? _a : MIDNIGHT}`;
|
|
69
|
+
default: return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export class Ifc2x3Rows {
|
|
73
|
+
constructor(model) {
|
|
74
|
+
this.model = model;
|
|
75
|
+
this.created = [];
|
|
76
|
+
this.issued = 0;
|
|
77
|
+
this.nextId = model.nextId;
|
|
78
|
+
}
|
|
79
|
+
get next() {
|
|
80
|
+
return this.nextId;
|
|
81
|
+
}
|
|
82
|
+
get schema() {
|
|
83
|
+
return this.model.schema;
|
|
84
|
+
}
|
|
85
|
+
isDate(id) {
|
|
86
|
+
var _a, _b, _c;
|
|
87
|
+
return DATE_ROWS.has((_c = (_b = (_a = this.model.source) === null || _a === void 0 ? void 0 : _a.rawTypeOf(id)) === null || _b === void 0 ? void 0 : _b.toUpperCase()) !== null && _c !== void 0 ? _c : "");
|
|
88
|
+
}
|
|
89
|
+
restyled(entity) {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
const successor = RESTYLED.get(entity.type);
|
|
92
|
+
if (successor === undefined) {
|
|
93
|
+
return entity;
|
|
94
|
+
}
|
|
95
|
+
const own = entity.args.slice(TYPE_PRODUCT_ATTRIBUTES);
|
|
96
|
+
return { id: entity.id, type: successor.type, args: [...entity.args.slice(0, TYPE_PRODUCT_ATTRIBUTES), null, enumValue(successor.kind), (_a = own[successor.operation]) !== null && _a !== void 0 ? _a : null, (_b = own[PRECEDENCE]) !== null && _b !== void 0 ? _b : null, null] };
|
|
97
|
+
}
|
|
98
|
+
surfaced(entity) {
|
|
99
|
+
if (!FACETED_BREPS.has(entity.type)) {
|
|
100
|
+
return entity;
|
|
101
|
+
}
|
|
102
|
+
const users = this.model.referencesTo(entity.id);
|
|
103
|
+
const representations = users.filter((user) => this.model.typeOf(user) === SHAPE_REPRESENTATION);
|
|
104
|
+
const presentations = users.filter((user) => PRESENTATION.some((type) => { var _a; return this.schema.isSubtypeOf((_a = this.model.typeOf(user)) !== null && _a !== void 0 ? _a : "", type); }));
|
|
105
|
+
if (!representations.length || representations.length + presentations.length !== users.length || representations.some((user) => this.model.attribute(user, "RepresentationType") !== SURFACE_MODEL)) {
|
|
106
|
+
return entity;
|
|
107
|
+
}
|
|
108
|
+
const [outer, voids] = entity.args;
|
|
109
|
+
return { id: entity.id, type: SHELL_SURFACE_MODEL, args: [[outer !== null && outer !== void 0 ? outer : null, ...(isList(voids) ? voids : [])]] };
|
|
110
|
+
}
|
|
111
|
+
given(info, args) {
|
|
112
|
+
var _a;
|
|
113
|
+
const dropped = (_a = DROPPED_TRAILING.get(info.name)) !== null && _a !== void 0 ? _a : 0;
|
|
114
|
+
return dropped > 0 && args.length === info.attributes.length + dropped ? args.slice(0, info.attributes.length) : args;
|
|
115
|
+
}
|
|
116
|
+
missing(info, entity, attribute) {
|
|
117
|
+
var _a, _b, _c;
|
|
118
|
+
if (Array.isArray(attribute.type) && attribute.type[1] === 0) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
const boundary = entity.args[(_a = info.positions.get("PhysicalOrVirtualBoundary")) !== null && _a !== void 0 ? _a : -1];
|
|
122
|
+
if (!this.schema.isSubtypeOf(info.name, SPACE_BOUNDARY) || attribute.name !== BOUNDED_BY || !isEnumeration(boundary) || boundary.enum !== VIRTUAL) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
const id = this.nextId++;
|
|
126
|
+
const owner = (_c = entity.args[(_b = info.positions.get("OwnerHistory")) !== null && _b !== void 0 ? _b : -1]) !== null && _c !== void 0 ? _c : null;
|
|
127
|
+
const values = { GlobalId: this.globalId(), OwnerHistory: owner, Name: VIRTUAL_ELEMENT_NAME };
|
|
128
|
+
const element = this.schema.entity(VIRTUAL_ELEMENT);
|
|
129
|
+
this.created.push([id, { id, type: element.name, args: element.attributes.map((each) => { var _a; return (_a = values[each.name]) !== null && _a !== void 0 ? _a : null; }) }]);
|
|
130
|
+
return ref(id);
|
|
131
|
+
}
|
|
132
|
+
converted(attribute, entity, value) {
|
|
133
|
+
if (isList(value) && value.length === 0 && attribute.optional && Array.isArray(attribute.type) && attribute.type[1] > 0) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const north = attribute.name === TRUE_NORTH && attribute.type === DIRECTION && isReference(value) ? this.flatNorth(value.ref) : undefined;
|
|
137
|
+
if (north !== undefined) {
|
|
138
|
+
return north;
|
|
139
|
+
}
|
|
140
|
+
if (isReference(value) && this.isDate(value.ref)) {
|
|
141
|
+
const text = dateTextFor(attribute.type, this.partsOf(value.ref));
|
|
142
|
+
if (text === undefined) {
|
|
143
|
+
throw new Error(`#${entity.id} ${attribute.name} refers to the IFC2X3 date or time #${value.ref}, which IFC4 has no place for there, so the file cannot be upgraded`);
|
|
144
|
+
}
|
|
145
|
+
return text;
|
|
146
|
+
}
|
|
147
|
+
return isEnumeration(value) && typeof attribute.type === "string" ? this.enumerationFor(attribute.type, value) : undefined;
|
|
148
|
+
}
|
|
149
|
+
completed(info, entity, args) {
|
|
150
|
+
const leftover = args.flatMap((value) => referencesIn(value)).find((id) => this.isDate(id));
|
|
151
|
+
if (leftover !== undefined) {
|
|
152
|
+
throw new Error(`#${entity.id} refers to the IFC2X3 date or time #${leftover} where IFC4 takes no text, so the file cannot be upgraded`);
|
|
153
|
+
}
|
|
154
|
+
const renamed = info.attributes.findIndex((_, index) => {
|
|
155
|
+
const before = entity.args[index];
|
|
156
|
+
const after = args[index];
|
|
157
|
+
return isEnumeration(before) && isEnumeration(after) && after.enum === USER_DEFINED && before.enum !== USER_DEFINED;
|
|
158
|
+
});
|
|
159
|
+
const token = entity.args[renamed];
|
|
160
|
+
const slots = NAMED_BY.map((name) => info.positions.get(name)).filter((position) => position !== undefined);
|
|
161
|
+
const slot = slots.find((position) => args[position] === null);
|
|
162
|
+
const named = [...args];
|
|
163
|
+
if (isEnumeration(token) && slot !== undefined) {
|
|
164
|
+
named[slot] = token.enum;
|
|
165
|
+
}
|
|
166
|
+
const predefined = info.positions.get(PREDEFINED_TYPE);
|
|
167
|
+
const kind = predefined === undefined ? undefined : named[predefined];
|
|
168
|
+
const kinds = predefined === undefined ? undefined : this.enumerationTokens(info.attributes[predefined].type);
|
|
169
|
+
if (predefined !== undefined && isEnumeration(kind) && kind.enum === USER_DEFINED && (kinds === null || kinds === void 0 ? void 0 : kinds.includes(NOT_DEFINED)) && slots.every((position) => named[position] === null)) {
|
|
170
|
+
named[predefined] = enumValue(NOT_DEFINED);
|
|
171
|
+
}
|
|
172
|
+
return info.name === OWNER_HISTORY ? this.dated(info, named) : named;
|
|
173
|
+
}
|
|
174
|
+
dated(info, args) {
|
|
175
|
+
var _a;
|
|
176
|
+
const action = args[info.positions.get("ChangeAction")];
|
|
177
|
+
const modified = info.positions.get("LastModifiedDate");
|
|
178
|
+
if (!isEnumeration(action) || !DATED_ACTIONS.has(action.enum) || args[modified] !== null) {
|
|
179
|
+
return args;
|
|
180
|
+
}
|
|
181
|
+
const dated = [...args];
|
|
182
|
+
dated[modified] = (_a = args[info.positions.get("CreationDate")]) !== null && _a !== void 0 ? _a : null;
|
|
183
|
+
return dated;
|
|
184
|
+
}
|
|
185
|
+
enumerationTokens(spec) {
|
|
186
|
+
const type = typeof spec === "string" ? this.schema.type(spec) : undefined;
|
|
187
|
+
return type !== undefined && "e" in type ? type.e : undefined;
|
|
188
|
+
}
|
|
189
|
+
flatNorth(direction) {
|
|
190
|
+
const ratios = this.model.attribute(direction, "DirectionRatios");
|
|
191
|
+
if (!isList(ratios) || ratios.length !== SPATIAL) {
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
const [x, y] = ratios;
|
|
195
|
+
if (typeof x !== "number" || typeof y !== "number" || (x === 0 && y === 0)) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
const id = this.nextId++;
|
|
199
|
+
this.created.push([id, { id, type: DIRECTION, args: [[x, y]] }]);
|
|
200
|
+
return ref(id);
|
|
201
|
+
}
|
|
202
|
+
enumerationFor(typeName, value) {
|
|
203
|
+
const tokens = this.enumerationTokens(typeName);
|
|
204
|
+
if (tokens === undefined) {
|
|
205
|
+
return this.schema.underlying(typeName) === STRING ? value.enum : undefined;
|
|
206
|
+
}
|
|
207
|
+
if (tokens.includes(value.enum)) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
const fallback = [USER_DEFINED, NOT_DEFINED].find((token) => tokens.includes(token));
|
|
211
|
+
return fallback === undefined ? undefined : enumValue(fallback);
|
|
212
|
+
}
|
|
213
|
+
partsOf(id) {
|
|
214
|
+
var _a, _b, _c;
|
|
215
|
+
const args = (_a = this.model.source) === null || _a === void 0 ? void 0 : _a.rawArguments(id);
|
|
216
|
+
switch ((_c = (_b = this.model.source) === null || _b === void 0 ? void 0 : _b.rawTypeOf(id)) === null || _c === void 0 ? void 0 : _c.toUpperCase()) {
|
|
217
|
+
case CALENDAR_DATE:
|
|
218
|
+
return { date: `${String(numberIn(args, 2, id)).padStart(YEAR_DIGITS, "0")}-${twoDigits(numberIn(args, 1, id))}-${twoDigits(numberIn(args, 0, id))}` };
|
|
219
|
+
case LOCAL_TIME: {
|
|
220
|
+
const zone = args === null || args === void 0 ? void 0 : args[3];
|
|
221
|
+
return { time: `${twoDigits(numberIn(args, 0, id))}:${twoDigits(optionalNumberIn(args, 1))}:${secondsText(optionalNumberIn(args, 2))}${isReference(zone) ? this.offsetOf(zone.ref) : ""}` };
|
|
222
|
+
}
|
|
223
|
+
case DATE_AND_TIME: {
|
|
224
|
+
const [date, time] = [args === null || args === void 0 ? void 0 : args[0], args === null || args === void 0 ? void 0 : args[1]];
|
|
225
|
+
return Object.assign(Object.assign({}, (isReference(date) ? this.partsOf(date.ref) : {})), (isReference(time) ? this.partsOf(time.ref) : {}));
|
|
226
|
+
}
|
|
227
|
+
default:
|
|
228
|
+
return {};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
offsetOf(id) {
|
|
232
|
+
var _a;
|
|
233
|
+
const args = (_a = this.model.source) === null || _a === void 0 ? void 0 : _a.rawArguments(id);
|
|
234
|
+
const sense = args === null || args === void 0 ? void 0 : args[2];
|
|
235
|
+
return `${isEnumeration(sense) && sense.enum === BEHIND ? "-" : "+"}${twoDigits(numberIn(args, 0, id))}:${twoDigits(optionalNumberIn(args, 1))}`;
|
|
236
|
+
}
|
|
237
|
+
globalId() {
|
|
238
|
+
return this.model.seededIds ? automaticGlobalId(this.model.keySeed, `${this.model.nextId}.${this.issued++}`) : randomGlobalId();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/model/upgrade.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { encoderFor } from "../step/encoder";
|
|
2
2
|
import { DERIVED, enumValue, isDerived, isList, isReference } from "../step/values";
|
|
3
3
|
import { ModelSnapshot } from "./snapshot";
|
|
4
|
+
import { Ifc2x3Rows } from "./upgrade-rows";
|
|
4
5
|
const IFC4 = "IFC4";
|
|
5
6
|
const NOT_DEFINED = "NOTDEFINED";
|
|
6
7
|
const SET = "SET";
|
|
@@ -22,7 +23,8 @@ function withoutRepeats(values) {
|
|
|
22
23
|
});
|
|
23
24
|
return kept.length === values.length ? values : kept;
|
|
24
25
|
}
|
|
25
|
-
function upgradedValue(schema, info, entity, index, value) {
|
|
26
|
+
function upgradedValue(rows, schema, info, entity, index, value) {
|
|
27
|
+
var _a;
|
|
26
28
|
const attribute = info.attributes[index];
|
|
27
29
|
if (attribute.derived) {
|
|
28
30
|
return isDerived(value) ? value : DERIVED;
|
|
@@ -31,12 +33,16 @@ function upgradedValue(schema, info, entity, index, value) {
|
|
|
31
33
|
if (attribute.optional) {
|
|
32
34
|
return value === null ? value : null;
|
|
33
35
|
}
|
|
34
|
-
const fallback = notDefinedFor(schema, attribute);
|
|
36
|
+
const fallback = (_a = notDefinedFor(schema, attribute)) !== null && _a !== void 0 ? _a : rows.missing(info, entity, attribute);
|
|
35
37
|
if (fallback === undefined) {
|
|
36
38
|
throw new Error(`#${entity.id} ${info.name}.${attribute.name} is required by IFC4 and the file leaves it out, so the file cannot be upgraded`);
|
|
37
39
|
}
|
|
38
40
|
return fallback;
|
|
39
41
|
}
|
|
42
|
+
const converted = rows.converted(attribute, entity, value);
|
|
43
|
+
if (converted !== undefined) {
|
|
44
|
+
return converted;
|
|
45
|
+
}
|
|
40
46
|
return Array.isArray(attribute.type) && attribute.type[0] === SET && isList(value) ? withoutRepeats(value) : value;
|
|
41
47
|
}
|
|
42
48
|
function upgradedEntity(model, id) {
|
|
@@ -60,19 +66,26 @@ export function upgradeToIfc4(model) {
|
|
|
60
66
|
throw new Error(`Only an IFC2X3 model is upgraded to IFC4, and this one is ${model.schemaName}`);
|
|
61
67
|
}
|
|
62
68
|
const encoder = encoderFor(model.schema);
|
|
69
|
+
const rows = new Ifc2x3Rows(model);
|
|
63
70
|
const changes = [];
|
|
64
71
|
for (const id of model.ids()) {
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
if (model.typeOf(id) === undefined && rows.isDate(id)) {
|
|
73
|
+
changes.push([id, null]);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const read = rows.surfaced(rows.restyled(upgradedEntity(model, id)));
|
|
77
|
+
const info = model.schema.entity(read.type);
|
|
78
|
+
const entity = Object.assign(Object.assign({}, read), { args: rows.given(info, read.args) });
|
|
67
79
|
if (entity.args.length > info.attributes.length) {
|
|
68
80
|
throw new Error(`#${id} gives ${entity.args.length} values where IFC4's ${info.name} takes ${info.attributes.length}, so the file cannot be upgraded`);
|
|
69
81
|
}
|
|
70
|
-
const args = info.attributes.map((_, index) => { var _a; return upgradedValue(model.schema, info, entity, index, (_a = entity.args[index]) !== null && _a !== void 0 ? _a : null); });
|
|
82
|
+
const args = rows.completed(info, entity, info.attributes.map((_, index) => { var _a; return upgradedValue(rows, model.schema, info, entity, index, (_a = entity.args[index]) !== null && _a !== void 0 ? _a : null); }));
|
|
71
83
|
const normalized = encoder.normalizeArguments(info.name, args, `#${id}`);
|
|
72
|
-
const changed = entity.type !== model.typeOf(id) ||
|
|
84
|
+
const changed = entity.type !== model.typeOf(id) || read.args.length !== args.length || args.some((value, index) => value !== read.args[index]);
|
|
73
85
|
if (changed) {
|
|
74
86
|
changes.push([id, { id, type: info.name, args: normalized }]);
|
|
75
87
|
}
|
|
76
88
|
}
|
|
77
|
-
|
|
89
|
+
const created = rows.created.map(([id, entity]) => [id, Object.assign(Object.assign({}, entity), { args: encoder.normalizeArguments(entity.type, entity.args, `#${id}`) })]);
|
|
90
|
+
return new ModelSnapshot(Object.assign(Object.assign({}, model.parts), { header: Object.assign(Object.assign({}, model.header), { schemaIdentifiers: [IFC4] }), overlay: model.overlay.withChanges([...changes, ...created]), nextId: rows.next }));
|
|
78
91
|
}
|
package/lib/schema/registry.js
CHANGED
|
@@ -4,7 +4,7 @@ import { IfcSchema } from "./schema";
|
|
|
4
4
|
const loaded = new Map();
|
|
5
5
|
const TABLES = new Map([[IFC4_SCHEMA.name, IFC4_SCHEMA], [IFC4X3_ADD2_SCHEMA.name, IFC4X3_ADD2_SCHEMA]]);
|
|
6
6
|
const READ_THROUGH = new Map([["IFC2X3", IFC4_SCHEMA.name], ["IFC4X3", IFC4X3_ADD2_SCHEMA.name]]);
|
|
7
|
-
const EDITABLE = new Set([IFC4_SCHEMA.name]);
|
|
7
|
+
const EDITABLE = new Set([IFC4_SCHEMA.name, IFC4X3_ADD2_SCHEMA.name]);
|
|
8
8
|
export const SUPPORTED_SCHEMAS = [...TABLES.keys()];
|
|
9
9
|
export function describeSupportedSchemas() {
|
|
10
10
|
const through = [...READ_THROUGH].map(([file, table]) => `${file} through ${table}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitbybit-dev/ifc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Bit By Bit Developers IFC library to write, read and author BIM models in TypeScript",
|
|
5
5
|
"homepage": "https://docs.bitbybit.dev/classes/Bit.IFC",
|
|
6
6
|
"main": "index.js",
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"IFC",
|
|
17
17
|
"BIM",
|
|
18
18
|
"Industry Foundation Classes",
|
|
19
|
-
"buildingSMART",
|
|
20
19
|
"IFC4",
|
|
21
20
|
"STEP",
|
|
22
21
|
"ISO 10303-21",
|
|
@@ -47,6 +46,6 @@
|
|
|
47
46
|
"types": "./index.d.ts",
|
|
48
47
|
"type": "module",
|
|
49
48
|
"dependencies": {
|
|
50
|
-
"@bitbybit-dev/base": "1.
|
|
49
|
+
"@bitbybit-dev/base": "1.6.0"
|
|
51
50
|
}
|
|
52
51
|
}
|