@itwin/core-common 4.6.0-dev.24 → 4.6.0-dev.25
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/lib/cjs/annotation/TextAnnotation.d.ts +9 -14
- package/lib/cjs/annotation/TextAnnotation.d.ts.map +1 -1
- package/lib/cjs/annotation/TextAnnotation.js +15 -16
- package/lib/cjs/annotation/TextAnnotation.js.map +1 -1
- package/lib/esm/annotation/TextAnnotation.d.ts +9 -14
- package/lib/esm/annotation/TextAnnotation.d.ts.map +1 -1
- package/lib/esm/annotation/TextAnnotation.js +15 -16
- package/lib/esm/annotation/TextAnnotation.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Annotation
|
|
3
3
|
*/
|
|
4
|
-
import { Point3d, Range2d, Transform,
|
|
4
|
+
import { Point3d, Range2d, Transform, YawPitchRollAngles, YawPitchRollProps } from "@itwin/core-geometry";
|
|
5
5
|
import { TextBlock, TextBlockProps } from "./TextBlock";
|
|
6
6
|
/**
|
|
7
|
-
* Describes the horizontal and vertical alignment of a [[TextAnnotation]]'s text relative to [
|
|
7
|
+
* Describes the horizontal and vertical alignment of a [[TextAnnotation]]'s text relative to the [Placement]($common) origin of
|
|
8
|
+
* the [TextAnnotation2d]($backend) or [TextAnnotation3d]($backend) host element, also referred to as the annotation's "anchor point".
|
|
9
|
+
* For example, if the anchor is specified as middle-center, the text will be centered on the element's origin.
|
|
10
|
+
* The anchor point also serves as the pivot point for [[TextAnnotation.rotation]], such that the text is rotated about the
|
|
11
|
+
* anchor point while the anchor point remains fixed.
|
|
8
12
|
* @beta
|
|
9
13
|
* @preview
|
|
10
14
|
* @extensions
|
|
@@ -32,8 +36,6 @@ export interface TextAnnotationAnchor {
|
|
|
32
36
|
* @extensions
|
|
33
37
|
*/
|
|
34
38
|
export interface TextAnnotationProps {
|
|
35
|
-
/** See [[TextAnnotation.origin]]. Default: [0, 0, 0]*/
|
|
36
|
-
origin?: XYZProps;
|
|
37
39
|
/** See [[TextAnnotation.orientation]]. Default: no rotation. */
|
|
38
40
|
orientation?: YawPitchRollProps;
|
|
39
41
|
/** See [[TextAnnotation.textBlock]]. Default: an empty text block. */
|
|
@@ -47,8 +49,6 @@ export interface TextAnnotationProps {
|
|
|
47
49
|
* @extensions
|
|
48
50
|
*/
|
|
49
51
|
export interface TextAnnotationCreateArgs {
|
|
50
|
-
/** See [[TextAnnotation.origin]]. Default: [0, 0, 0]*/
|
|
51
|
-
origin?: Point3d;
|
|
52
52
|
/** See [[TextAnnotation.orientation]]. Default: no rotation. */
|
|
53
53
|
orientation?: YawPitchRollAngles;
|
|
54
54
|
/** See [[TextAnnotation.textBlock]]. Default: an empty text block. */
|
|
@@ -65,13 +65,6 @@ export interface TextAnnotationCreateArgs {
|
|
|
65
65
|
* @extensions
|
|
66
66
|
*/
|
|
67
67
|
export declare class TextAnnotation {
|
|
68
|
-
/**
|
|
69
|
-
* The point considered to be the origin of the annotation. The [[textBlock]]'s content is justified relative to this point as specified by [[anchor]].
|
|
70
|
-
* This point is also considered the origin by [AccuSnap]($frontend) when using [SnapMode.Origin]($frontend).
|
|
71
|
-
* Often, the origin is specified by a user clicking in a viewport when placing text annotations interactively.
|
|
72
|
-
* @note When defining an annotation for a [TextAnnotation2d]($backend), the `z` component should be zero.
|
|
73
|
-
*/
|
|
74
|
-
origin: Point3d;
|
|
75
68
|
/**
|
|
76
69
|
* The rotation of the annotation.
|
|
77
70
|
* @note When defining an annotation for a [TextAnnotation2d]($backend), only the `yaw` component (rotation around the Z axis) is used.
|
|
@@ -82,7 +75,7 @@ export declare class TextAnnotation {
|
|
|
82
75
|
*/
|
|
83
76
|
textBlock: TextBlock;
|
|
84
77
|
/**
|
|
85
|
-
* Describes how the [[textBlock]]'s content should be aligned relative to the
|
|
78
|
+
* Describes how the [[textBlock]]'s content should be aligned relative to the host element's origin.
|
|
86
79
|
*/
|
|
87
80
|
anchor: TextAnnotationAnchor;
|
|
88
81
|
private constructor();
|
|
@@ -100,6 +93,8 @@ export declare class TextAnnotation {
|
|
|
100
93
|
* @internal used by produceTextAnnotationGeometry; requires layoutRange computed by layoutTextBlock.
|
|
101
94
|
*/
|
|
102
95
|
computeDocumentTransform(layoutRange: Range2d): Transform;
|
|
96
|
+
/** @internal */
|
|
97
|
+
computeAnchorPoint(layoutRange: Range2d): Point3d;
|
|
103
98
|
/** Returns true if this annotation is logically equivalent to `other`. */
|
|
104
99
|
equals(other: TextAnnotation): boolean;
|
|
105
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotation.d.ts","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"TextAnnotation.d.ts","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC1G,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAEtC;;;;;OAKG;IACH,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;CACzC;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,sEAAsE;IACtE,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,wDAAwD;IACxD,MAAM,CAAC,EAAE,oBAAoB,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,gEAAgE;IAChE,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,sEAAsE;IACtE,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,wDAAwD;IACxD,MAAM,CAAC,EAAE,oBAAoB,CAAC;CAC/B;AACD;;;;;;;GAOG;AACH,qBAAa,cAAc;IACzB;;;OAGG;IACI,WAAW,EAAE,kBAAkB,CAAC;IACvC;;OAEG;IACI,SAAS,EAAE,SAAS,CAAC;IAC5B;;OAEG;IACI,MAAM,EAAE,oBAAoB,CAAC;IAEpC,OAAO;IAMP,oCAAoC;WACtB,MAAM,CAAC,IAAI,CAAC,EAAE,wBAAwB,GAAG,cAAc;IAQrE;;OAEG;WACW,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,SAAS,GAAG,cAAc;IAQ9E;;OAEG;IACI,MAAM,IAAI,mBAAmB;IAkBpC;;OAEG;IACI,wBAAwB,CAAC,WAAW,EAAE,OAAO,GAAG,SAAS;IAOhE,gBAAgB;IACT,kBAAkB,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO;IAyBxD,0EAA0E;IACnE,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO;CAI9C"}
|
|
@@ -19,26 +19,23 @@ const TextBlock_1 = require("./TextBlock");
|
|
|
19
19
|
* @extensions
|
|
20
20
|
*/
|
|
21
21
|
class TextAnnotation {
|
|
22
|
-
constructor(
|
|
23
|
-
this.origin = origin;
|
|
22
|
+
constructor(angles, textBlock, anchor) {
|
|
24
23
|
this.orientation = angles;
|
|
25
24
|
this.textBlock = textBlock;
|
|
26
25
|
this.anchor = anchor;
|
|
27
26
|
}
|
|
28
27
|
/** Creates a new TextAnnotation. */
|
|
29
28
|
static create(args) {
|
|
30
|
-
const origin = args?.origin ?? new core_geometry_1.Point3d();
|
|
31
29
|
const angles = args?.orientation ?? new core_geometry_1.YawPitchRollAngles();
|
|
32
30
|
const textBlock = args?.textBlock ?? TextBlock_1.TextBlock.createEmpty();
|
|
33
31
|
const anchor = args?.anchor ?? { vertical: "top", horizontal: "left" };
|
|
34
|
-
return new TextAnnotation(
|
|
32
|
+
return new TextAnnotation(angles, textBlock, anchor);
|
|
35
33
|
}
|
|
36
34
|
/**
|
|
37
35
|
* Creates a new TextAnnotation instance from its JSON representation.
|
|
38
36
|
*/
|
|
39
37
|
static fromJSON(props) {
|
|
40
38
|
return TextAnnotation.create({
|
|
41
|
-
origin: props?.origin ? core_geometry_1.Point3d.fromJSON(props.origin) : undefined,
|
|
42
39
|
orientation: props?.orientation ? core_geometry_1.YawPitchRollAngles.fromJSON(props.orientation) : undefined,
|
|
43
40
|
textBlock: props?.textBlock ? TextBlock_1.TextBlock.create(props.textBlock) : undefined,
|
|
44
41
|
anchor: props?.anchor ? { ...props.anchor } : undefined,
|
|
@@ -52,9 +49,6 @@ class TextAnnotation {
|
|
|
52
49
|
// Even if the text block is empty, we want to record its style name and overrides, e.g.,
|
|
53
50
|
// so the user can pick up where they left off editing it next time.
|
|
54
51
|
props.textBlock = this.textBlock.toJSON();
|
|
55
|
-
if (!this.origin.isZero) {
|
|
56
|
-
props.origin = this.origin.toJSON();
|
|
57
|
-
}
|
|
58
52
|
if (!this.orientation.isIdentity()) {
|
|
59
53
|
props.orientation = this.orientation.toJSON();
|
|
60
54
|
}
|
|
@@ -67,31 +61,36 @@ class TextAnnotation {
|
|
|
67
61
|
* @internal used by produceTextAnnotationGeometry; requires layoutRange computed by layoutTextBlock.
|
|
68
62
|
*/
|
|
69
63
|
computeDocumentTransform(layoutRange) {
|
|
70
|
-
const origin = this.
|
|
64
|
+
const origin = this.computeAnchorPoint(layoutRange);
|
|
71
65
|
const matrix = this.orientation.toMatrix3d();
|
|
66
|
+
return core_geometry_1.Transform.createFixedPointAndMatrix(origin, matrix);
|
|
67
|
+
}
|
|
68
|
+
/** @internal */
|
|
69
|
+
computeAnchorPoint(layoutRange) {
|
|
70
|
+
let x = 0;
|
|
71
|
+
let y = 0;
|
|
72
72
|
switch (this.anchor.horizontal) {
|
|
73
73
|
case "center":
|
|
74
|
-
|
|
74
|
+
x += layoutRange.xLength() / 2;
|
|
75
75
|
break;
|
|
76
76
|
case "right":
|
|
77
|
-
|
|
77
|
+
x += layoutRange.xLength();
|
|
78
78
|
break;
|
|
79
79
|
}
|
|
80
80
|
switch (this.anchor.vertical) {
|
|
81
81
|
case "middle":
|
|
82
|
-
|
|
82
|
+
y -= layoutRange.yLength() / 2;
|
|
83
83
|
break;
|
|
84
84
|
case "bottom":
|
|
85
|
-
|
|
85
|
+
y -= layoutRange.yLength();
|
|
86
86
|
break;
|
|
87
87
|
}
|
|
88
|
-
return core_geometry_1.
|
|
88
|
+
return new core_geometry_1.Point3d(x, y, 0);
|
|
89
89
|
}
|
|
90
90
|
/** Returns true if this annotation is logically equivalent to `other`. */
|
|
91
91
|
equals(other) {
|
|
92
92
|
return this.anchor.horizontal === other.anchor.horizontal && this.anchor.vertical === other.anchor.vertical
|
|
93
|
-
&& this.orientation.isAlmostEqual(other.orientation) && this.
|
|
94
|
-
&& this.textBlock.equals(other.textBlock);
|
|
93
|
+
&& this.orientation.isAlmostEqual(other.orientation) && this.textBlock.equals(other.textBlock);
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
exports.TextAnnotation = TextAnnotation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotation.js","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAAoH;AACpH,2CAAwD;AA0DxD;;;;;;;GAOG;AACH,MAAa,cAAc;IAsBzB,YAAoB,MAAe,EAAE,MAA0B,EAAE,SAAoB,EAAE,MAA4B;QACjH,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,M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,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;gBAClC,MAAM;QACV,CAAC;QAED,OAAO,yBAAS,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,0EAA0E;IACnE,MAAM,CAAC,KAAqB;QACjC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,KAAK,CAAC,MAAM,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,QAAQ;eACtG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;eAC5F,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;CACF;AA9GD,wCA8GC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Annotation\r\n */\r\n\r\nimport { Point3d, Range2d, Transform, XYZProps, YawPitchRollAngles, YawPitchRollProps } from \"@itwin/core-geometry\";\r\nimport { TextBlock, TextBlockProps } from \"./TextBlock\";\r\n\r\n/**\r\n * Describes the horizontal and vertical alignment of a [[TextAnnotation]]'s text relative to [[TextAnnotation.origin]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationAnchor {\r\n /**\r\n * The vertical alignment of the anchor point.\r\n * \"top\" aligns the top of the text with the anchor point.\r\n * \"middle\" aligns the middle of the text with the anchor point.\r\n * \"bottom\" aligns the bottom of the text with the anchor point.\r\n */\r\n vertical: \"top\" | \"middle\" | \"bottom\";\r\n\r\n /**\r\n * The horizontal alignment of the anchor point.\r\n * \"left\" aligns the left side of the text with the anchor point.\r\n * \"center\" aligns the center of the text with the anchor point.\r\n * \"right\" aligns the right side of the text with the anchor point.\r\n */\r\n horizontal: \"left\" | \"center\" | \"right\";\r\n}\r\n\r\n/**\r\n * JSON representation of a [[TextAnnotation]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationProps {\r\n /** See [[TextAnnotation.origin]]. Default: [0, 0, 0]*/\r\n origin?: XYZProps;\r\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\r\n orientation?: YawPitchRollProps;\r\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\r\n textBlock?: TextBlockProps;\r\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\r\n anchor?: TextAnnotationAnchor;\r\n}\r\n\r\n/** Arguments supplied to [[TextAnnotation.create]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationCreateArgs {\r\n /** See [[TextAnnotation.origin]]. Default: [0, 0, 0]*/\r\n origin?: Point3d;\r\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\r\n orientation?: YawPitchRollAngles;\r\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\r\n textBlock?: TextBlock;\r\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\r\n anchor?: TextAnnotationAnchor;\r\n}\r\n/**\r\n * Represents a formatted block of text positioned in 2d or 3d space.\r\n * [TextAnnotation2d]($backend) and [TextAnnotation3d]($backend) elements store a TextAnnotation from which their geometric representation is generated.\r\n * @see [produceTextAnnotationGeometry]($backend) to decompose the annotation into a set of geometric primitives suitable for use with [[GeometryStreamBuilder.appendTextBlock]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport class TextAnnotation {\r\n /**\r\n * The point considered to be the origin of the annotation. The [[textBlock]]'s content is justified relative to this point as specified by [[anchor]].\r\n * This point is also considered the origin by [AccuSnap]($frontend) when using [SnapMode.Origin]($frontend).\r\n * Often, the origin is specified by a user clicking in a viewport when placing text annotations interactively.\r\n * @note When defining an annotation for a [TextAnnotation2d]($backend), the `z` component should be zero.\r\n */\r\n public origin: Point3d;\r\n /**\r\n * The rotation of the annotation.\r\n * @note When defining an annotation for a [TextAnnotation2d]($backend), only the `yaw` component (rotation around the Z axis) is used.\r\n */\r\n public orientation: YawPitchRollAngles;\r\n /**\r\n * The formatted document.\r\n */\r\n public textBlock: TextBlock;\r\n /**\r\n * Describes how the [[textBlock]]'s content should be aligned relative to the [[origin]].\r\n */\r\n public anchor: TextAnnotationAnchor;\r\n\r\n private constructor(origin: Point3d, angles: YawPitchRollAngles, textBlock: TextBlock, anchor: TextAnnotationAnchor) {\r\n this.origin = origin;\r\n this.orientation = angles;\r\n this.textBlock = textBlock;\r\n this.anchor = anchor;\r\n }\r\n\r\n /** Creates a new TextAnnotation. */\r\n public static create(args?: TextAnnotationCreateArgs): TextAnnotation {\r\n const origin = args?.origin ?? new Point3d();\r\n const angles = args?.orientation ?? new YawPitchRollAngles();\r\n const textBlock = args?.textBlock ?? TextBlock.createEmpty();\r\n const anchor = args?.anchor ?? { vertical: \"top\", horizontal: \"left\" };\r\n\r\n return new TextAnnotation(origin, angles, textBlock, anchor);\r\n }\r\n\r\n /**\r\n * Creates a new TextAnnotation instance from its JSON representation.\r\n */\r\n public static fromJSON(props: TextAnnotationProps | undefined): TextAnnotation {\r\n return TextAnnotation.create({\r\n origin: props?.origin ? Point3d.fromJSON(props.origin) : undefined,\r\n orientation: props?.orientation ? YawPitchRollAngles.fromJSON(props.orientation) : undefined,\r\n textBlock: props?.textBlock ? TextBlock.create(props.textBlock) : undefined,\r\n anchor: props?.anchor ? { ...props.anchor } : undefined,\r\n });\r\n }\r\n\r\n /**\r\n * Converts this annotation to its JSON representation.\r\n */\r\n public toJSON(): TextAnnotationProps {\r\n const props: TextAnnotationProps = {};\r\n\r\n // Even if the text block is empty, we want to record its style name and overrides, e.g.,\r\n // so the user can pick up where they left off editing it next time.\r\n props.textBlock = this.textBlock.toJSON();\r\n\r\n if (!this.origin.isZero) {\r\n props.origin = this.origin.toJSON();\r\n }\r\n\r\n if (!this.orientation.isIdentity()) {\r\n props.orientation = this.orientation.toJSON();\r\n }\r\n\r\n if (this.anchor.vertical !== \"top\" || this.anchor.horizontal !== \"left\") {\r\n props.anchor = { ...this.anchor };\r\n }\r\n\r\n return props;\r\n }\r\n\r\n /**\r\n * @internal used by produceTextAnnotationGeometry; requires layoutRange computed by layoutTextBlock.\r\n */\r\n public computeDocumentTransform(layoutRange: Range2d): Transform {\r\n const origin = this.origin.clone();\r\n const matrix = this.orientation.toMatrix3d();\r\n\r\n switch (this.anchor.horizontal) {\r\n case \"center\":\r\n origin.x -= layoutRange.xLength() / 2;\r\n break;\r\n case \"right\":\r\n origin.x -= layoutRange.xLength();\r\n break;\r\n }\r\n\r\n switch (this.anchor.vertical) {\r\n case \"middle\":\r\n origin.y += layoutRange.yLength() / 2;\r\n break;\r\n case \"bottom\":\r\n origin.y += layoutRange.yLength();\r\n break;\r\n }\r\n\r\n return Transform.createRefs(origin, matrix);\r\n }\r\n\r\n /** Returns true if this annotation is logically equivalent to `other`. */\r\n public equals(other: TextAnnotation): boolean {\r\n return this.anchor.horizontal === other.anchor.horizontal && this.anchor.vertical === other.anchor.vertical\r\n && this.orientation.isAlmostEqual(other.orientation) && this.origin.isAlmostEqual(other.origin)\r\n && this.textBlock.equals(other.textBlock);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"TextAnnotation.js","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAA0G;AAC1G,2CAAwD;AA0DxD;;;;;;;GAOG;AACH,MAAa,cAAc;IAezB,YAAoB,MAA0B,EAAE,SAAoB,EAAE,MAA4B;QAChG,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;I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AU,KAAK,KAAK,CAAC,MAAM,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,QAAQ;eACtG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACnG,CAAC;CACF;AAvGD,wCAuGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Annotation\r\n */\r\n\r\nimport { Point3d, Range2d, Transform, YawPitchRollAngles, YawPitchRollProps } from \"@itwin/core-geometry\";\r\nimport { TextBlock, TextBlockProps } from \"./TextBlock\";\r\n\r\n/**\r\n * Describes the horizontal and vertical alignment of a [[TextAnnotation]]'s text relative to the [Placement]($common) origin of\r\n * the [TextAnnotation2d]($backend) or [TextAnnotation3d]($backend) host element, also referred to as the annotation's \"anchor point\".\r\n * For example, if the anchor is specified as middle-center, the text will be centered on the element's origin.\r\n * The anchor point also serves as the pivot point for [[TextAnnotation.rotation]], such that the text is rotated about the\r\n * anchor point while the anchor point remains fixed.\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationAnchor {\r\n /**\r\n * The vertical alignment of the anchor point.\r\n * \"top\" aligns the top of the text with the anchor point.\r\n * \"middle\" aligns the middle of the text with the anchor point.\r\n * \"bottom\" aligns the bottom of the text with the anchor point.\r\n */\r\n vertical: \"top\" | \"middle\" | \"bottom\";\r\n\r\n /**\r\n * The horizontal alignment of the anchor point.\r\n * \"left\" aligns the left side of the text with the anchor point.\r\n * \"center\" aligns the center of the text with the anchor point.\r\n * \"right\" aligns the right side of the text with the anchor point.\r\n */\r\n horizontal: \"left\" | \"center\" | \"right\";\r\n}\r\n\r\n/**\r\n * JSON representation of a [[TextAnnotation]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationProps {\r\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\r\n orientation?: YawPitchRollProps;\r\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\r\n textBlock?: TextBlockProps;\r\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\r\n anchor?: TextAnnotationAnchor;\r\n}\r\n\r\n/** Arguments supplied to [[TextAnnotation.create]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationCreateArgs {\r\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\r\n orientation?: YawPitchRollAngles;\r\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\r\n textBlock?: TextBlock;\r\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\r\n anchor?: TextAnnotationAnchor;\r\n}\r\n/**\r\n * Represents a formatted block of text positioned in 2d or 3d space.\r\n * [TextAnnotation2d]($backend) and [TextAnnotation3d]($backend) elements store a TextAnnotation from which their geometric representation is generated.\r\n * @see [produceTextAnnotationGeometry]($backend) to decompose the annotation into a set of geometric primitives suitable for use with [[GeometryStreamBuilder.appendTextBlock]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport class TextAnnotation {\r\n /**\r\n * The rotation of the annotation.\r\n * @note When defining an annotation for a [TextAnnotation2d]($backend), only the `yaw` component (rotation around the Z axis) is used.\r\n */\r\n public orientation: YawPitchRollAngles;\r\n /**\r\n * The formatted document.\r\n */\r\n public textBlock: TextBlock;\r\n /**\r\n * Describes how the [[textBlock]]'s content should be aligned relative to the host element's origin.\r\n */\r\n public anchor: TextAnnotationAnchor;\r\n\r\n private constructor(angles: YawPitchRollAngles, textBlock: TextBlock, anchor: TextAnnotationAnchor) {\r\n this.orientation = angles;\r\n this.textBlock = textBlock;\r\n this.anchor = anchor;\r\n }\r\n\r\n /** Creates a new TextAnnotation. */\r\n public static create(args?: TextAnnotationCreateArgs): TextAnnotation {\r\n const angles = args?.orientation ?? new YawPitchRollAngles();\r\n const textBlock = args?.textBlock ?? TextBlock.createEmpty();\r\n const anchor = args?.anchor ?? { vertical: \"top\", horizontal: \"left\" };\r\n\r\n return new TextAnnotation(angles, textBlock, anchor);\r\n }\r\n\r\n /**\r\n * Creates a new TextAnnotation instance from its JSON representation.\r\n */\r\n public static fromJSON(props: TextAnnotationProps | undefined): TextAnnotation {\r\n return TextAnnotation.create({\r\n orientation: props?.orientation ? YawPitchRollAngles.fromJSON(props.orientation) : undefined,\r\n textBlock: props?.textBlock ? TextBlock.create(props.textBlock) : undefined,\r\n anchor: props?.anchor ? { ...props.anchor } : undefined,\r\n });\r\n }\r\n\r\n /**\r\n * Converts this annotation to its JSON representation.\r\n */\r\n public toJSON(): TextAnnotationProps {\r\n const props: TextAnnotationProps = {};\r\n\r\n // Even if the text block is empty, we want to record its style name and overrides, e.g.,\r\n // so the user can pick up where they left off editing it next time.\r\n props.textBlock = this.textBlock.toJSON();\r\n\r\n if (!this.orientation.isIdentity()) {\r\n props.orientation = this.orientation.toJSON();\r\n }\r\n\r\n if (this.anchor.vertical !== \"top\" || this.anchor.horizontal !== \"left\") {\r\n props.anchor = { ...this.anchor };\r\n }\r\n\r\n return props;\r\n }\r\n\r\n /**\r\n * @internal used by produceTextAnnotationGeometry; requires layoutRange computed by layoutTextBlock.\r\n */\r\n public computeDocumentTransform(layoutRange: Range2d): Transform {\r\n const origin = this.computeAnchorPoint(layoutRange);\r\n const matrix = this.orientation.toMatrix3d();\r\n\r\n return Transform.createFixedPointAndMatrix(origin, matrix);\r\n }\r\n\r\n /** @internal */\r\n public computeAnchorPoint(layoutRange: Range2d): Point3d {\r\n let x = 0;\r\n let y = 0;\r\n\r\n switch (this.anchor.horizontal) {\r\n case \"center\":\r\n x += layoutRange.xLength() / 2;\r\n break;\r\n case \"right\":\r\n x += layoutRange.xLength();\r\n break;\r\n }\r\n\r\n switch (this.anchor.vertical) {\r\n case \"middle\":\r\n y -= layoutRange.yLength() / 2;\r\n break;\r\n case \"bottom\":\r\n y -= layoutRange.yLength();\r\n break;\r\n }\r\n\r\n return new Point3d(x, y, 0);\r\n }\r\n\r\n /** Returns true if this annotation is logically equivalent to `other`. */\r\n public equals(other: TextAnnotation): boolean {\r\n return this.anchor.horizontal === other.anchor.horizontal && this.anchor.vertical === other.anchor.vertical\r\n && this.orientation.isAlmostEqual(other.orientation) && this.textBlock.equals(other.textBlock);\r\n }\r\n}\r\n"]}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Annotation
|
|
3
3
|
*/
|
|
4
|
-
import { Point3d, Range2d, Transform,
|
|
4
|
+
import { Point3d, Range2d, Transform, YawPitchRollAngles, YawPitchRollProps } from "@itwin/core-geometry";
|
|
5
5
|
import { TextBlock, TextBlockProps } from "./TextBlock";
|
|
6
6
|
/**
|
|
7
|
-
* Describes the horizontal and vertical alignment of a [[TextAnnotation]]'s text relative to [
|
|
7
|
+
* Describes the horizontal and vertical alignment of a [[TextAnnotation]]'s text relative to the [Placement]($common) origin of
|
|
8
|
+
* the [TextAnnotation2d]($backend) or [TextAnnotation3d]($backend) host element, also referred to as the annotation's "anchor point".
|
|
9
|
+
* For example, if the anchor is specified as middle-center, the text will be centered on the element's origin.
|
|
10
|
+
* The anchor point also serves as the pivot point for [[TextAnnotation.rotation]], such that the text is rotated about the
|
|
11
|
+
* anchor point while the anchor point remains fixed.
|
|
8
12
|
* @beta
|
|
9
13
|
* @preview
|
|
10
14
|
* @extensions
|
|
@@ -32,8 +36,6 @@ export interface TextAnnotationAnchor {
|
|
|
32
36
|
* @extensions
|
|
33
37
|
*/
|
|
34
38
|
export interface TextAnnotationProps {
|
|
35
|
-
/** See [[TextAnnotation.origin]]. Default: [0, 0, 0]*/
|
|
36
|
-
origin?: XYZProps;
|
|
37
39
|
/** See [[TextAnnotation.orientation]]. Default: no rotation. */
|
|
38
40
|
orientation?: YawPitchRollProps;
|
|
39
41
|
/** See [[TextAnnotation.textBlock]]. Default: an empty text block. */
|
|
@@ -47,8 +49,6 @@ export interface TextAnnotationProps {
|
|
|
47
49
|
* @extensions
|
|
48
50
|
*/
|
|
49
51
|
export interface TextAnnotationCreateArgs {
|
|
50
|
-
/** See [[TextAnnotation.origin]]. Default: [0, 0, 0]*/
|
|
51
|
-
origin?: Point3d;
|
|
52
52
|
/** See [[TextAnnotation.orientation]]. Default: no rotation. */
|
|
53
53
|
orientation?: YawPitchRollAngles;
|
|
54
54
|
/** See [[TextAnnotation.textBlock]]. Default: an empty text block. */
|
|
@@ -65,13 +65,6 @@ export interface TextAnnotationCreateArgs {
|
|
|
65
65
|
* @extensions
|
|
66
66
|
*/
|
|
67
67
|
export declare class TextAnnotation {
|
|
68
|
-
/**
|
|
69
|
-
* The point considered to be the origin of the annotation. The [[textBlock]]'s content is justified relative to this point as specified by [[anchor]].
|
|
70
|
-
* This point is also considered the origin by [AccuSnap]($frontend) when using [SnapMode.Origin]($frontend).
|
|
71
|
-
* Often, the origin is specified by a user clicking in a viewport when placing text annotations interactively.
|
|
72
|
-
* @note When defining an annotation for a [TextAnnotation2d]($backend), the `z` component should be zero.
|
|
73
|
-
*/
|
|
74
|
-
origin: Point3d;
|
|
75
68
|
/**
|
|
76
69
|
* The rotation of the annotation.
|
|
77
70
|
* @note When defining an annotation for a [TextAnnotation2d]($backend), only the `yaw` component (rotation around the Z axis) is used.
|
|
@@ -82,7 +75,7 @@ export declare class TextAnnotation {
|
|
|
82
75
|
*/
|
|
83
76
|
textBlock: TextBlock;
|
|
84
77
|
/**
|
|
85
|
-
* Describes how the [[textBlock]]'s content should be aligned relative to the
|
|
78
|
+
* Describes how the [[textBlock]]'s content should be aligned relative to the host element's origin.
|
|
86
79
|
*/
|
|
87
80
|
anchor: TextAnnotationAnchor;
|
|
88
81
|
private constructor();
|
|
@@ -100,6 +93,8 @@ export declare class TextAnnotation {
|
|
|
100
93
|
* @internal used by produceTextAnnotationGeometry; requires layoutRange computed by layoutTextBlock.
|
|
101
94
|
*/
|
|
102
95
|
computeDocumentTransform(layoutRange: Range2d): Transform;
|
|
96
|
+
/** @internal */
|
|
97
|
+
computeAnchorPoint(layoutRange: Range2d): Point3d;
|
|
103
98
|
/** Returns true if this annotation is logically equivalent to `other`. */
|
|
104
99
|
equals(other: TextAnnotation): boolean;
|
|
105
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotation.d.ts","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"TextAnnotation.d.ts","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC1G,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAEtC;;;;;OAKG;IACH,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;CACzC;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,sEAAsE;IACtE,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,wDAAwD;IACxD,MAAM,CAAC,EAAE,oBAAoB,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,gEAAgE;IAChE,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,sEAAsE;IACtE,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,wDAAwD;IACxD,MAAM,CAAC,EAAE,oBAAoB,CAAC;CAC/B;AACD;;;;;;;GAOG;AACH,qBAAa,cAAc;IACzB;;;OAGG;IACI,WAAW,EAAE,kBAAkB,CAAC;IACvC;;OAEG;IACI,SAAS,EAAE,SAAS,CAAC;IAC5B;;OAEG;IACI,MAAM,EAAE,oBAAoB,CAAC;IAEpC,OAAO;IAMP,oCAAoC;WACtB,MAAM,CAAC,IAAI,CAAC,EAAE,wBAAwB,GAAG,cAAc;IAQrE;;OAEG;WACW,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,SAAS,GAAG,cAAc;IAQ9E;;OAEG;IACI,MAAM,IAAI,mBAAmB;IAkBpC;;OAEG;IACI,wBAAwB,CAAC,WAAW,EAAE,OAAO,GAAG,SAAS;IAOhE,gBAAgB;IACT,kBAAkB,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO;IAyBxD,0EAA0E;IACnE,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO;CAI9C"}
|
|
@@ -16,26 +16,23 @@ import { TextBlock } from "./TextBlock";
|
|
|
16
16
|
* @extensions
|
|
17
17
|
*/
|
|
18
18
|
export class TextAnnotation {
|
|
19
|
-
constructor(
|
|
20
|
-
this.origin = origin;
|
|
19
|
+
constructor(angles, textBlock, anchor) {
|
|
21
20
|
this.orientation = angles;
|
|
22
21
|
this.textBlock = textBlock;
|
|
23
22
|
this.anchor = anchor;
|
|
24
23
|
}
|
|
25
24
|
/** Creates a new TextAnnotation. */
|
|
26
25
|
static create(args) {
|
|
27
|
-
const origin = args?.origin ?? new Point3d();
|
|
28
26
|
const angles = args?.orientation ?? new YawPitchRollAngles();
|
|
29
27
|
const textBlock = args?.textBlock ?? TextBlock.createEmpty();
|
|
30
28
|
const anchor = args?.anchor ?? { vertical: "top", horizontal: "left" };
|
|
31
|
-
return new TextAnnotation(
|
|
29
|
+
return new TextAnnotation(angles, textBlock, anchor);
|
|
32
30
|
}
|
|
33
31
|
/**
|
|
34
32
|
* Creates a new TextAnnotation instance from its JSON representation.
|
|
35
33
|
*/
|
|
36
34
|
static fromJSON(props) {
|
|
37
35
|
return TextAnnotation.create({
|
|
38
|
-
origin: props?.origin ? Point3d.fromJSON(props.origin) : undefined,
|
|
39
36
|
orientation: props?.orientation ? YawPitchRollAngles.fromJSON(props.orientation) : undefined,
|
|
40
37
|
textBlock: props?.textBlock ? TextBlock.create(props.textBlock) : undefined,
|
|
41
38
|
anchor: props?.anchor ? { ...props.anchor } : undefined,
|
|
@@ -49,9 +46,6 @@ export class TextAnnotation {
|
|
|
49
46
|
// Even if the text block is empty, we want to record its style name and overrides, e.g.,
|
|
50
47
|
// so the user can pick up where they left off editing it next time.
|
|
51
48
|
props.textBlock = this.textBlock.toJSON();
|
|
52
|
-
if (!this.origin.isZero) {
|
|
53
|
-
props.origin = this.origin.toJSON();
|
|
54
|
-
}
|
|
55
49
|
if (!this.orientation.isIdentity()) {
|
|
56
50
|
props.orientation = this.orientation.toJSON();
|
|
57
51
|
}
|
|
@@ -64,31 +58,36 @@ export class TextAnnotation {
|
|
|
64
58
|
* @internal used by produceTextAnnotationGeometry; requires layoutRange computed by layoutTextBlock.
|
|
65
59
|
*/
|
|
66
60
|
computeDocumentTransform(layoutRange) {
|
|
67
|
-
const origin = this.
|
|
61
|
+
const origin = this.computeAnchorPoint(layoutRange);
|
|
68
62
|
const matrix = this.orientation.toMatrix3d();
|
|
63
|
+
return Transform.createFixedPointAndMatrix(origin, matrix);
|
|
64
|
+
}
|
|
65
|
+
/** @internal */
|
|
66
|
+
computeAnchorPoint(layoutRange) {
|
|
67
|
+
let x = 0;
|
|
68
|
+
let y = 0;
|
|
69
69
|
switch (this.anchor.horizontal) {
|
|
70
70
|
case "center":
|
|
71
|
-
|
|
71
|
+
x += layoutRange.xLength() / 2;
|
|
72
72
|
break;
|
|
73
73
|
case "right":
|
|
74
|
-
|
|
74
|
+
x += layoutRange.xLength();
|
|
75
75
|
break;
|
|
76
76
|
}
|
|
77
77
|
switch (this.anchor.vertical) {
|
|
78
78
|
case "middle":
|
|
79
|
-
|
|
79
|
+
y -= layoutRange.yLength() / 2;
|
|
80
80
|
break;
|
|
81
81
|
case "bottom":
|
|
82
|
-
|
|
82
|
+
y -= layoutRange.yLength();
|
|
83
83
|
break;
|
|
84
84
|
}
|
|
85
|
-
return
|
|
85
|
+
return new Point3d(x, y, 0);
|
|
86
86
|
}
|
|
87
87
|
/** Returns true if this annotation is logically equivalent to `other`. */
|
|
88
88
|
equals(other) {
|
|
89
89
|
return this.anchor.horizontal === other.anchor.horizontal && this.anchor.vertical === other.anchor.vertical
|
|
90
|
-
&& this.orientation.isAlmostEqual(other.orientation) && this.
|
|
91
|
-
&& this.textBlock.equals(other.textBlock);
|
|
90
|
+
&& this.orientation.isAlmostEqual(other.orientation) && this.textBlock.equals(other.textBlock);
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
//# sourceMappingURL=TextAnnotation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotation.js","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAW,SAAS,EAAY,kBAAkB,EAAqB,MAAM,sBAAsB,CAAC;AACpH,OAAO,EAAE,SAAS,EAAkB,MAAM,aAAa,CAAC;AA0DxD;;;;;;;GAOG;AACH,MAAM,OAAO,cAAc;IAsBzB,YAAoB,MAAe,EAAE,MAA0B,EAAE,SAAoB,EAAE,MAA4B;QACjH,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,oCAAoC;IAC7B,MAAM,CAAC,MAAM,CAAC,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CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,0EAA0E;IACnE,MAAM,CAAC,KAAqB;QACjC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,KAAK,CAAC,MAAM,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,QAAQ;eACtG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;eAC5F,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Annotation\r\n */\r\n\r\nimport { Point3d, Range2d, Transform, XYZProps, YawPitchRollAngles, YawPitchRollProps } from \"@itwin/core-geometry\";\r\nimport { TextBlock, TextBlockProps } from \"./TextBlock\";\r\n\r\n/**\r\n * Describes the horizontal and vertical alignment of a [[TextAnnotation]]'s text relative to [[TextAnnotation.origin]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationAnchor {\r\n /**\r\n * The vertical alignment of the anchor point.\r\n * \"top\" aligns the top of the text with the anchor point.\r\n * \"middle\" aligns the middle of the text with the anchor point.\r\n * \"bottom\" aligns the bottom of the text with the anchor point.\r\n */\r\n vertical: \"top\" | \"middle\" | \"bottom\";\r\n\r\n /**\r\n * The horizontal alignment of the anchor point.\r\n * \"left\" aligns the left side of the text with the anchor point.\r\n * \"center\" aligns the center of the text with the anchor point.\r\n * \"right\" aligns the right side of the text with the anchor point.\r\n */\r\n horizontal: \"left\" | \"center\" | \"right\";\r\n}\r\n\r\n/**\r\n * JSON representation of a [[TextAnnotation]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationProps {\r\n /** See [[TextAnnotation.origin]]. Default: [0, 0, 0]*/\r\n origin?: XYZProps;\r\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\r\n orientation?: YawPitchRollProps;\r\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\r\n textBlock?: TextBlockProps;\r\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\r\n anchor?: TextAnnotationAnchor;\r\n}\r\n\r\n/** Arguments supplied to [[TextAnnotation.create]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationCreateArgs {\r\n /** See [[TextAnnotation.origin]]. Default: [0, 0, 0]*/\r\n origin?: Point3d;\r\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\r\n orientation?: YawPitchRollAngles;\r\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\r\n textBlock?: TextBlock;\r\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\r\n anchor?: TextAnnotationAnchor;\r\n}\r\n/**\r\n * Represents a formatted block of text positioned in 2d or 3d space.\r\n * [TextAnnotation2d]($backend) and [TextAnnotation3d]($backend) elements store a TextAnnotation from which their geometric representation is generated.\r\n * @see [produceTextAnnotationGeometry]($backend) to decompose the annotation into a set of geometric primitives suitable for use with [[GeometryStreamBuilder.appendTextBlock]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport class TextAnnotation {\r\n /**\r\n * The point considered to be the origin of the annotation. The [[textBlock]]'s content is justified relative to this point as specified by [[anchor]].\r\n * This point is also considered the origin by [AccuSnap]($frontend) when using [SnapMode.Origin]($frontend).\r\n * Often, the origin is specified by a user clicking in a viewport when placing text annotations interactively.\r\n * @note When defining an annotation for a [TextAnnotation2d]($backend), the `z` component should be zero.\r\n */\r\n public origin: Point3d;\r\n /**\r\n * The rotation of the annotation.\r\n * @note When defining an annotation for a [TextAnnotation2d]($backend), only the `yaw` component (rotation around the Z axis) is used.\r\n */\r\n public orientation: YawPitchRollAngles;\r\n /**\r\n * The formatted document.\r\n */\r\n public textBlock: TextBlock;\r\n /**\r\n * Describes how the [[textBlock]]'s content should be aligned relative to the [[origin]].\r\n */\r\n public anchor: TextAnnotationAnchor;\r\n\r\n private constructor(origin: Point3d, angles: YawPitchRollAngles, textBlock: TextBlock, anchor: TextAnnotationAnchor) {\r\n this.origin = origin;\r\n this.orientation = angles;\r\n this.textBlock = textBlock;\r\n this.anchor = anchor;\r\n }\r\n\r\n /** Creates a new TextAnnotation. */\r\n public static create(args?: TextAnnotationCreateArgs): TextAnnotation {\r\n const origin = args?.origin ?? new Point3d();\r\n const angles = args?.orientation ?? new YawPitchRollAngles();\r\n const textBlock = args?.textBlock ?? TextBlock.createEmpty();\r\n const anchor = args?.anchor ?? { vertical: \"top\", horizontal: \"left\" };\r\n\r\n return new TextAnnotation(origin, angles, textBlock, anchor);\r\n }\r\n\r\n /**\r\n * Creates a new TextAnnotation instance from its JSON representation.\r\n */\r\n public static fromJSON(props: TextAnnotationProps | undefined): TextAnnotation {\r\n return TextAnnotation.create({\r\n origin: props?.origin ? Point3d.fromJSON(props.origin) : undefined,\r\n orientation: props?.orientation ? YawPitchRollAngles.fromJSON(props.orientation) : undefined,\r\n textBlock: props?.textBlock ? TextBlock.create(props.textBlock) : undefined,\r\n anchor: props?.anchor ? { ...props.anchor } : undefined,\r\n });\r\n }\r\n\r\n /**\r\n * Converts this annotation to its JSON representation.\r\n */\r\n public toJSON(): TextAnnotationProps {\r\n const props: TextAnnotationProps = {};\r\n\r\n // Even if the text block is empty, we want to record its style name and overrides, e.g.,\r\n // so the user can pick up where they left off editing it next time.\r\n props.textBlock = this.textBlock.toJSON();\r\n\r\n if (!this.origin.isZero) {\r\n props.origin = this.origin.toJSON();\r\n }\r\n\r\n if (!this.orientation.isIdentity()) {\r\n props.orientation = this.orientation.toJSON();\r\n }\r\n\r\n if (this.anchor.vertical !== \"top\" || this.anchor.horizontal !== \"left\") {\r\n props.anchor = { ...this.anchor };\r\n }\r\n\r\n return props;\r\n }\r\n\r\n /**\r\n * @internal used by produceTextAnnotationGeometry; requires layoutRange computed by layoutTextBlock.\r\n */\r\n public computeDocumentTransform(layoutRange: Range2d): Transform {\r\n const origin = this.origin.clone();\r\n const matrix = this.orientation.toMatrix3d();\r\n\r\n switch (this.anchor.horizontal) {\r\n case \"center\":\r\n origin.x -= layoutRange.xLength() / 2;\r\n break;\r\n case \"right\":\r\n origin.x -= layoutRange.xLength();\r\n break;\r\n }\r\n\r\n switch (this.anchor.vertical) {\r\n case \"middle\":\r\n origin.y += layoutRange.yLength() / 2;\r\n break;\r\n case \"bottom\":\r\n origin.y += layoutRange.yLength();\r\n break;\r\n }\r\n\r\n return Transform.createRefs(origin, matrix);\r\n }\r\n\r\n /** Returns true if this annotation is logically equivalent to `other`. */\r\n public equals(other: TextAnnotation): boolean {\r\n return this.anchor.horizontal === other.anchor.horizontal && this.anchor.vertical === other.anchor.vertical\r\n && this.orientation.isAlmostEqual(other.orientation) && this.origin.isAlmostEqual(other.origin)\r\n && this.textBlock.equals(other.textBlock);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"TextAnnotation.js","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAW,SAAS,EAAE,kBAAkB,EAAqB,MAAM,sBAAsB,CAAC;AAC1G,OAAO,EAAE,SAAS,EAAkB,MAAM,aAAa,CAAC;AA0DxD;;;;;;;GAOG;AACH,MAAM,OAAO,cAAc;IAezB,YAAoB,MAA0B,EAAE,SAAoB,EAAE,MAA4B;QAChG,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;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KAAK,KAAK,CAAC,MAAM,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,QAAQ;eACtG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACnG,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Annotation\r\n */\r\n\r\nimport { Point3d, Range2d, Transform, YawPitchRollAngles, YawPitchRollProps } from \"@itwin/core-geometry\";\r\nimport { TextBlock, TextBlockProps } from \"./TextBlock\";\r\n\r\n/**\r\n * Describes the horizontal and vertical alignment of a [[TextAnnotation]]'s text relative to the [Placement]($common) origin of\r\n * the [TextAnnotation2d]($backend) or [TextAnnotation3d]($backend) host element, also referred to as the annotation's \"anchor point\".\r\n * For example, if the anchor is specified as middle-center, the text will be centered on the element's origin.\r\n * The anchor point also serves as the pivot point for [[TextAnnotation.rotation]], such that the text is rotated about the\r\n * anchor point while the anchor point remains fixed.\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationAnchor {\r\n /**\r\n * The vertical alignment of the anchor point.\r\n * \"top\" aligns the top of the text with the anchor point.\r\n * \"middle\" aligns the middle of the text with the anchor point.\r\n * \"bottom\" aligns the bottom of the text with the anchor point.\r\n */\r\n vertical: \"top\" | \"middle\" | \"bottom\";\r\n\r\n /**\r\n * The horizontal alignment of the anchor point.\r\n * \"left\" aligns the left side of the text with the anchor point.\r\n * \"center\" aligns the center of the text with the anchor point.\r\n * \"right\" aligns the right side of the text with the anchor point.\r\n */\r\n horizontal: \"left\" | \"center\" | \"right\";\r\n}\r\n\r\n/**\r\n * JSON representation of a [[TextAnnotation]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationProps {\r\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\r\n orientation?: YawPitchRollProps;\r\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\r\n textBlock?: TextBlockProps;\r\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\r\n anchor?: TextAnnotationAnchor;\r\n}\r\n\r\n/** Arguments supplied to [[TextAnnotation.create]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport interface TextAnnotationCreateArgs {\r\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\r\n orientation?: YawPitchRollAngles;\r\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\r\n textBlock?: TextBlock;\r\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\r\n anchor?: TextAnnotationAnchor;\r\n}\r\n/**\r\n * Represents a formatted block of text positioned in 2d or 3d space.\r\n * [TextAnnotation2d]($backend) and [TextAnnotation3d]($backend) elements store a TextAnnotation from which their geometric representation is generated.\r\n * @see [produceTextAnnotationGeometry]($backend) to decompose the annotation into a set of geometric primitives suitable for use with [[GeometryStreamBuilder.appendTextBlock]].\r\n * @beta\r\n * @preview\r\n * @extensions\r\n */\r\nexport class TextAnnotation {\r\n /**\r\n * The rotation of the annotation.\r\n * @note When defining an annotation for a [TextAnnotation2d]($backend), only the `yaw` component (rotation around the Z axis) is used.\r\n */\r\n public orientation: YawPitchRollAngles;\r\n /**\r\n * The formatted document.\r\n */\r\n public textBlock: TextBlock;\r\n /**\r\n * Describes how the [[textBlock]]'s content should be aligned relative to the host element's origin.\r\n */\r\n public anchor: TextAnnotationAnchor;\r\n\r\n private constructor(angles: YawPitchRollAngles, textBlock: TextBlock, anchor: TextAnnotationAnchor) {\r\n this.orientation = angles;\r\n this.textBlock = textBlock;\r\n this.anchor = anchor;\r\n }\r\n\r\n /** Creates a new TextAnnotation. */\r\n public static create(args?: TextAnnotationCreateArgs): TextAnnotation {\r\n const angles = args?.orientation ?? new YawPitchRollAngles();\r\n const textBlock = args?.textBlock ?? TextBlock.createEmpty();\r\n const anchor = args?.anchor ?? { vertical: \"top\", horizontal: \"left\" };\r\n\r\n return new TextAnnotation(angles, textBlock, anchor);\r\n }\r\n\r\n /**\r\n * Creates a new TextAnnotation instance from its JSON representation.\r\n */\r\n public static fromJSON(props: TextAnnotationProps | undefined): TextAnnotation {\r\n return TextAnnotation.create({\r\n orientation: props?.orientation ? YawPitchRollAngles.fromJSON(props.orientation) : undefined,\r\n textBlock: props?.textBlock ? TextBlock.create(props.textBlock) : undefined,\r\n anchor: props?.anchor ? { ...props.anchor } : undefined,\r\n });\r\n }\r\n\r\n /**\r\n * Converts this annotation to its JSON representation.\r\n */\r\n public toJSON(): TextAnnotationProps {\r\n const props: TextAnnotationProps = {};\r\n\r\n // Even if the text block is empty, we want to record its style name and overrides, e.g.,\r\n // so the user can pick up where they left off editing it next time.\r\n props.textBlock = this.textBlock.toJSON();\r\n\r\n if (!this.orientation.isIdentity()) {\r\n props.orientation = this.orientation.toJSON();\r\n }\r\n\r\n if (this.anchor.vertical !== \"top\" || this.anchor.horizontal !== \"left\") {\r\n props.anchor = { ...this.anchor };\r\n }\r\n\r\n return props;\r\n }\r\n\r\n /**\r\n * @internal used by produceTextAnnotationGeometry; requires layoutRange computed by layoutTextBlock.\r\n */\r\n public computeDocumentTransform(layoutRange: Range2d): Transform {\r\n const origin = this.computeAnchorPoint(layoutRange);\r\n const matrix = this.orientation.toMatrix3d();\r\n\r\n return Transform.createFixedPointAndMatrix(origin, matrix);\r\n }\r\n\r\n /** @internal */\r\n public computeAnchorPoint(layoutRange: Range2d): Point3d {\r\n let x = 0;\r\n let y = 0;\r\n\r\n switch (this.anchor.horizontal) {\r\n case \"center\":\r\n x += layoutRange.xLength() / 2;\r\n break;\r\n case \"right\":\r\n x += layoutRange.xLength();\r\n break;\r\n }\r\n\r\n switch (this.anchor.vertical) {\r\n case \"middle\":\r\n y -= layoutRange.yLength() / 2;\r\n break;\r\n case \"bottom\":\r\n y -= layoutRange.yLength();\r\n break;\r\n }\r\n\r\n return new Point3d(x, y, 0);\r\n }\r\n\r\n /** Returns true if this annotation is logically equivalent to `other`. */\r\n public equals(other: TextAnnotation): boolean {\r\n return this.anchor.horizontal === other.anchor.horizontal && this.anchor.vertical === other.anchor.vertical\r\n && this.orientation.isAlmostEqual(other.orientation) && this.textBlock.equals(other.textBlock);\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-common",
|
|
3
|
-
"version": "4.6.0-dev.
|
|
3
|
+
"version": "4.6.0-dev.25",
|
|
4
4
|
"description": "iTwin.js components common to frontend and backend",
|
|
5
5
|
"main": "lib/cjs/core-common.js",
|
|
6
6
|
"module": "lib/esm/core-common.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"js-base64": "^3.6.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@itwin/core-bentley": "^4.6.0-dev.
|
|
31
|
-
"@itwin/core-geometry": "^4.6.0-dev.
|
|
30
|
+
"@itwin/core-bentley": "^4.6.0-dev.25",
|
|
31
|
+
"@itwin/core-geometry": "^4.6.0-dev.25"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@itwin/eslint-plugin": "4.0.0-dev.52",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"nyc": "^15.1.0",
|
|
44
44
|
"rimraf": "^3.0.2",
|
|
45
45
|
"typescript": "~5.3.3",
|
|
46
|
-
"@itwin/build-tools": "4.6.0-dev.
|
|
47
|
-
"@itwin/core-
|
|
48
|
-
"@itwin/core-
|
|
46
|
+
"@itwin/build-tools": "4.6.0-dev.25",
|
|
47
|
+
"@itwin/core-geometry": "4.6.0-dev.25",
|
|
48
|
+
"@itwin/core-bentley": "4.6.0-dev.25"
|
|
49
49
|
},
|
|
50
50
|
"nyc": {
|
|
51
51
|
"extends": "./node_modules/@itwin/build-tools/.nycrc",
|