Skip to content

Commit 4b3014b

Browse files
committed
update location measurement to use coordinate koq as well
1 parent 0b54955 commit 4b3014b

File tree

2 files changed

+83
-13
lines changed

2 files changed

+83
-13
lines changed

packages/itwin/measure-tools/src/measurements/DistanceMeasurement.ts

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ export interface DistanceMeasurementProps extends MeasurementProps {
5959
export interface DistanceMeasurementFormattingProps {
6060
/** Defaults to "AecUnits.LENGTH" and "Units.M" */
6161
length?: MeasurementFormattingProps;
62-
/** Defaults to "RoadRailUnits.Bearing" and "Units.RAD" */
62+
/** Defaults to "RoadRailUnits.BEARING" and "Units.RAD" */
6363
bearing? : MeasurementFormattingProps;
64+
/** Defaults to "AecUnits.LENGTH_COORDINATE" and "Units.M" */
65+
coordinate?: MeasurementFormattingProps;
6466
}
6567

6668
/** Serializer for a [[DistanceMeasurement]]. */
@@ -109,6 +111,8 @@ export class DistanceMeasurement extends Measurement {
109111
private _lengthPersistenceUnitName: string;
110112
private _bearingKoQ?: string;
111113
private _bearingPersistenceUnitName?: string;
114+
private _coordinateKoQ: string;
115+
private _coordinatePersistenceUnitName: string;
112116

113117
private _isDynamic: boolean; // No serialize
114118
private _textMarker?: TextMarker; // No serialize
@@ -177,6 +181,22 @@ export class DistanceMeasurement extends Measurement {
177181
this.createTextMarker().catch(); // eslint-disable-line @typescript-eslint/no-floating-promises
178182
}
179183

184+
public get coordinateKoQ(): string {
185+
return this._coordinateKoQ;
186+
}
187+
188+
public set coordinateKoQ(value: string) {
189+
this._coordinateKoQ = value;
190+
}
191+
192+
public get coordinatePersistenceUnitName(): string {
193+
return this._coordinatePersistenceUnitName;
194+
}
195+
196+
public set coordinatePersistenceUnitName(value: string) {
197+
this._coordinatePersistenceUnitName = value;
198+
}
199+
180200
// eslint-disable-next-line @typescript-eslint/naming-convention
181201
private get isAxis(): boolean {
182202
return (
@@ -195,6 +215,8 @@ export class DistanceMeasurement extends Measurement {
195215
this._runRiseAxes = [];
196216
this._lengthKoQ = "AecUnits.LENGTH";
197217
this._lengthPersistenceUnitName = "Units.M";
218+
this._coordinateKoQ = "AecUnits.LENGTH_COORDINATE";
219+
this._coordinatePersistenceUnitName = "Units.M";
198220
if (props) this.readFromJSON(props);
199221

200222
this.populateFormattingSpecsRegistry().then(() => this.createTextMarker().catch())
@@ -240,6 +262,14 @@ export class DistanceMeasurement extends Measurement {
240262
await IModelApp.quantityFormatter.addFormattingSpecsToRegistry(this._lengthKoQ, this._lengthPersistenceUnitName, lengthFormatProps);
241263
}
242264
}
265+
266+
const coordinateEntry = IModelApp.quantityFormatter.getSpecsByName(this._coordinateKoQ);
267+
if (_force || !coordinateEntry || coordinateEntry.formatterSpec.persistenceUnit?.name !== this._coordinatePersistenceUnitName) {
268+
const coordinateFormatProps = await IModelApp.formatsProvider.getFormat(this._coordinateKoQ);
269+
if (coordinateFormatProps) {
270+
await IModelApp.quantityFormatter.addFormattingSpecsToRegistry(this._coordinateKoQ, this._coordinatePersistenceUnitName, coordinateFormatProps);
271+
}
272+
}
243273
}
244274

245275
public override testDecorationHit(
@@ -540,14 +570,11 @@ export class DistanceMeasurement extends Measurement {
540570
const adjustedStart = this.adjustPointForGlobalOrigin(this._startPoint);
541571
const adjustedEnd = this.adjustPointForGlobalOrigin(this._endPoint);
542572
const lengthSpec = IModelApp.quantityFormatter.getSpecsByName(this._lengthKoQ)?.formatterSpec;
573+
const coordinateSpec = IModelApp.quantityFormatter.getSpecsByName(this._coordinateKoQ)?.formatterSpec;
543574

544575
const fDistance = IModelApp.quantityFormatter.formatQuantity(distance, lengthSpec);
545-
const fStartCoords = FormatterUtils.formatCoordinatesImmediate(
546-
adjustedStart, lengthSpec
547-
);
548-
const fEndCoords = FormatterUtils.formatCoordinatesImmediate(
549-
adjustedEnd, lengthSpec
550-
);
576+
const fStartCoords = FormatterUtils.formatCoordinatesImmediate(adjustedStart, coordinateSpec);
577+
const fEndCoords = FormatterUtils.formatCoordinatesImmediate(adjustedEnd, coordinateSpec);
551578
const fSlope = FormatterUtils.formatSlope(slope, true);
552579
const fRun = IModelApp.quantityFormatter.formatQuantity(run, lengthSpec);
553580
const fDeltaX = IModelApp.quantityFormatter.formatQuantity(dx, lengthSpec);
@@ -721,6 +748,8 @@ export class DistanceMeasurement extends Measurement {
721748
if (jsonDist.formatting?.length?.persistenceUnitName) this._lengthPersistenceUnitName = jsonDist.formatting.length.persistenceUnitName;
722749
if (jsonDist.formatting?.bearing?.koqName) this._bearingKoQ = jsonDist.formatting.bearing.koqName;
723750
if (jsonDist.formatting?.bearing?.persistenceUnitName) this._bearingPersistenceUnitName = jsonDist.formatting.bearing.persistenceUnitName;
751+
if (jsonDist.formatting?.coordinate?.koqName) this._coordinateKoQ = jsonDist.formatting.coordinate.koqName;
752+
if (jsonDist.formatting?.coordinate?.persistenceUnitName) this._coordinatePersistenceUnitName = jsonDist.formatting.coordinate.persistenceUnitName;
724753

725754
this.buildRunRiseAxes();
726755
this.createTextMarker().catch(); // eslint-disable-line @typescript-eslint/no-floating-promises
@@ -746,6 +775,10 @@ export class DistanceMeasurement extends Measurement {
746775
koqName: this._bearingKoQ,
747776
persistenceUnitName: this._bearingPersistenceUnitName,
748777
},
778+
coordinate: {
779+
koqName: this._coordinateKoQ,
780+
persistenceUnitName: this._coordinatePersistenceUnitName,
781+
},
749782
};
750783
}
751784

packages/itwin/measure-tools/src/measurements/LocationMeasurement.ts

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export interface LocationMeasurementProps extends MeasurementProps {
5555

5656
/** Formatting properties for location measurement. */
5757
export interface LocationMeasurementFormattingProps {
58+
/** Defaults to "AecUnits.LENGTH_COORDINATE" and "Units.M" */
59+
coordinate?: MeasurementFormattingProps;
5860
/** Defaults to "AecUnits.LENGTH" and "Units.M" */
5961
length?: MeasurementFormattingProps;
6062
/** Defaults to "RoadRailUnits.STATION" and "Units.M" */
@@ -105,6 +107,8 @@ export class LocationMeasurement extends Measurement {
105107

106108
private _textMarker?: TextMarker; // No serialize
107109
private _isDynamic: boolean; // No serialize
110+
private _coordinateKoQ: string;
111+
private _coordinatePersistenceUnitName: string;
108112
private _lengthKoQ: string;
109113
private _lengthPersistenceUnitName: string;
110114
private _stationKoQ: string;
@@ -158,6 +162,21 @@ export class LocationMeasurement extends Measurement {
158162
if (this._textMarker) this._textMarker.pickable = !v;
159163
}
160164

165+
public get coordinateKoQ(): string {
166+
return this._coordinateKoQ;
167+
}
168+
public set coordinateKoQ(value: string) {
169+
this._coordinateKoQ = value;
170+
this.createTextMarker().catch(); // eslint-disable-line @typescript-eslint/no-floating-promises
171+
}
172+
public get coordinatePersistenceUnitName(): string {
173+
return this._coordinatePersistenceUnitName;
174+
}
175+
public set coordinatePersistenceUnitName(value: string) {
176+
this._coordinatePersistenceUnitName = value;
177+
this.createTextMarker().catch(); // eslint-disable-line @typescript-eslint/no-floating-promises
178+
}
179+
161180
public get lengthKoQ(): string {
162181
return this._lengthKoQ;
163182
}
@@ -204,6 +223,8 @@ export class LocationMeasurement extends Measurement {
204223

205224
this._location = Point3d.createZero();
206225
this._isDynamic = false;
226+
this._coordinateKoQ = "AecUnits.LENGTH_COORDINATE";
227+
this._coordinatePersistenceUnitName = "Units.M";
207228
this._lengthKoQ = "AecUnits.LENGTH";
208229
this._lengthPersistenceUnitName = "Units.M";
209230
this._stationKoQ = "RoadRailUnits.STATION";
@@ -272,6 +293,13 @@ export class LocationMeasurement extends Measurement {
272293
}
273294

274295
public override async populateFormattingSpecsRegistry(_force?: boolean): Promise<void> {
296+
const coordinateEntry = IModelApp.quantityFormatter.getSpecsByName(this._coordinateKoQ);
297+
if (_force || !coordinateEntry || coordinateEntry.formatterSpec.persistenceUnit?.name !== this._coordinatePersistenceUnitName) {
298+
const coordinateFormatProps = await IModelApp.formatsProvider.getFormat(this._coordinateKoQ);
299+
if (coordinateFormatProps) {
300+
await IModelApp.quantityFormatter.addFormattingSpecsToRegistry(this._coordinateKoQ, this._coordinatePersistenceUnitName, coordinateFormatProps);
301+
}
302+
}
275303
const lengthEntry = IModelApp.quantityFormatter.getSpecsByName(this._lengthKoQ);
276304
if (_force || !lengthEntry || lengthEntry.formatterSpec.persistenceUnit?.name !== this._lengthPersistenceUnitName) {
277305
const lengthFormatProps = await IModelApp.formatsProvider.getFormat(this._lengthKoQ);
@@ -320,26 +348,26 @@ export class LocationMeasurement extends Measurement {
320348

321349
private async createTextMarker(): Promise<void> {
322350
const adjustedLocation = this.adjustPointWithSheetToWorldTransform(this.adjustPointForGlobalOrigin(this._location));
323-
const lengthSpec = IModelApp.quantityFormatter.getSpecsByName(this._lengthKoQ)?.formatterSpec;
351+
const coordinateSpec = IModelApp.quantityFormatter.getSpecsByName(this._coordinateKoQ)?.formatterSpec;
324352

325353
const entries = [
326354
{
327355
label: MeasureTools.localization.getLocalizedString(
328356
"MeasureTools:tools.MeasureLocation.coordinate_x"
329357
),
330-
value: await FormatterUtils.formatLength(adjustedLocation.x, lengthSpec),
358+
value: await FormatterUtils.formatLength(adjustedLocation.x, coordinateSpec),
331359
},
332360
{
333361
label: MeasureTools.localization.getLocalizedString(
334362
"MeasureTools:tools.MeasureLocation.coordinate_y"
335363
),
336-
value: await FormatterUtils.formatLength(adjustedLocation.y, lengthSpec),
364+
value: await FormatterUtils.formatLength(adjustedLocation.y, coordinateSpec),
337365
},
338366
{
339367
label: MeasureTools.localization.getLocalizedString(
340368
"MeasureTools:tools.MeasureLocation.coordinate_z"
341369
),
342-
value: await FormatterUtils.formatLength(adjustedLocation.z, lengthSpec),
370+
value: await FormatterUtils.formatLength(adjustedLocation.z, coordinateSpec),
343371
},
344372
];
345373

@@ -376,12 +404,13 @@ export class LocationMeasurement extends Measurement {
376404
protected override async getDataForMeasurementWidgetInternal(): Promise<
377405
MeasurementWidgetData | undefined
378406
> {
407+
const coordinateSpec = IModelApp.quantityFormatter.getSpecsByName(this._coordinateKoQ)?.formatterSpec;
379408
const lengthSpec = IModelApp.quantityFormatter.getSpecsByName(this._lengthKoQ)?.formatterSpec;
380409
const angleSpec = IModelApp.quantityFormatter.getSpecsByName(this._angleKoQ)?.formatterSpec;
381410
const stationSpec = IModelApp.quantityFormatter.getSpecsByName(this._stationKoQ)?.formatterSpec;
382411

383412
const adjustedLocation = this.adjustPointWithSheetToWorldTransform(this.adjustPointForGlobalOrigin(this._location));
384-
const fCoordinates = FormatterUtils.formatCoordinatesImmediate(adjustedLocation, lengthSpec);
413+
const fCoordinates = FormatterUtils.formatCoordinatesImmediate(adjustedLocation, coordinateSpec);
385414

386415
let title = MeasureTools.localization.getLocalizedString(
387416
"MeasureTools:Measurements.locationMeasurement"
@@ -416,7 +445,7 @@ export class LocationMeasurement extends Measurement {
416445
"MeasureTools:tools.MeasureLocation.altitude"
417446
),
418447
name: "LocationMeasurement_Altitude",
419-
value: await FormatterUtils.formatLength(adjustedLocation.z, lengthSpec),
448+
value: await FormatterUtils.formatLength(adjustedLocation.z, coordinateSpec),
420449
});
421450
}
422451
if (this.drawingMetadata?.sheetToWorldTransform === undefined) {
@@ -566,6 +595,10 @@ export class LocationMeasurement extends Measurement {
566595
this._geoLocation = Cartographic.fromRadians(jsonLoc.geoLocation);
567596
else this._geoLocation = undefined;
568597

598+
if (jsonLoc.formatting?.coordinate?.koqName) this._coordinateKoQ = jsonLoc.formatting.coordinate.koqName;
599+
if (jsonLoc.formatting?.coordinate?.persistenceUnitName)
600+
this._coordinatePersistenceUnitName = jsonLoc.formatting.coordinate.persistenceUnitName;
601+
569602
if (jsonLoc.formatting?.length?.koqName) this._lengthKoQ = jsonLoc.formatting.length.koqName;
570603
if (jsonLoc.formatting?.length?.persistenceUnitName)
571604
this._lengthPersistenceUnitName = jsonLoc.formatting.length.persistenceUnitName;
@@ -609,6 +642,10 @@ export class LocationMeasurement extends Measurement {
609642
jsonLoc.station = this._station;
610643
jsonLoc.offset = this._offset;
611644
jsonLoc.formatting = {
645+
coordinate: {
646+
koqName: this._coordinateKoQ,
647+
persistenceUnitName: this._coordinatePersistenceUnitName,
648+
},
612649
length: {
613650
koqName: this._lengthKoQ,
614651
persistenceUnitName: this._lengthPersistenceUnitName,

0 commit comments

Comments
 (0)