-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(obc): display units in ElementProperties
- Loading branch information
Showing
4 changed files
with
110 additions
and
9 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/obc/src/components/tables/ElementProperties/src/get-model-unit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import * as FRAGS from "@thatopen/fragments"; | ||
import * as WEBIFC from "web-ifc"; | ||
|
||
const map: Record<string, any> = { | ||
IFCLENGTHMEASURE: "LENGTHUNIT", | ||
IFCAREAMEASURE: "AREAUNIT", | ||
IFCVOLUMEMEASURE: "VOLUMEUNIT", | ||
IFCPLANEANGLEMEASURE: "PLANEANGLEUNIT", | ||
}; | ||
|
||
const ifcUnitSymbols: Record<string, { symbol: string; digits: number }> = { | ||
MILLIMETRE: { symbol: "mm", digits: 0 }, | ||
METRE: { symbol: "m", digits: 2 }, | ||
KILOMETRE: { symbol: "km", digits: 2 }, | ||
SQUARE_METRE: { symbol: "m²", digits: 2 }, | ||
CUBIC_METRE: { symbol: "m³", digits: 2 }, | ||
DEGREE: { symbol: "°", digits: 2 }, | ||
RADIAN: { symbol: "rad", digits: 2 }, | ||
GRAM: { symbol: "g", digits: 0 }, | ||
KILOGRAM: { symbol: "kg", digits: 2 }, | ||
MILLISECOND: { symbol: "ms", digits: 0 }, | ||
SECOND: { symbol: "s", digits: 0 }, | ||
}; | ||
|
||
export const getModelUnit = async ( | ||
model: FRAGS.FragmentsGroup, | ||
type: string, | ||
) => { | ||
const units = Object.values( | ||
(await model.getAllPropertiesOfType(WEBIFC.IFCUNITASSIGNMENT))!, | ||
)[0]; | ||
let unit: string | undefined; | ||
for (const handle of units.Units) { | ||
const unitAttrs = await model.getProperties(handle.value); | ||
if (unitAttrs && unitAttrs.UnitType?.value === map[type]) { | ||
unit = `${unitAttrs.Prefix?.value ?? ""}${unitAttrs.Name?.value ?? ""}`; | ||
break; | ||
} | ||
} | ||
if (unit) return ifcUnitSymbols[unit]; | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters