-
Notifications
You must be signed in to change notification settings - Fork 2
/
ViewUtilities.ts
129 lines (116 loc) · 3.57 KB
/
ViewUtilities.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Utilities
*/
// cSpell:ignore classname
import type { ScreenViewport } from "@itwin/core-frontend";
import {
DrawingViewState,
OrthographicViewState,
SheetViewState,
SpatialViewState,
} from "@itwin/core-frontend";
/**
* Various View utility methods
* @public
*/
export class ViewUtilities {
/**
* Extracts the BisBaseClass from a full class name.
* @param classFullName full class name
* @returns BisBaseClass name
*/
public static getBisBaseClass(classFullName: string) {
const bisBaseClass = classFullName.substring(
classFullName.indexOf(":") + 1
);
return bisBaseClass;
}
/**
* Determines if given class is a spatial view.
* @param classname Name of class to check
*/
public static isSpatial(classname: string): boolean {
return (
classname === SpatialViewState.className ||
classname === OrthographicViewState.className
);
}
/**
* Determines if given class is a spatial view.
* @param classname Name of class to check
*/
public static isOrthographic(classname: string): boolean {
return classname === OrthographicViewState.className;
}
/**
* Determines if given class is a drawing view.
* @param classname Name of class to check
*/
public static isDrawing(classname: string): boolean {
return classname === DrawingViewState.className;
}
/**
* Determines if given class is a sheet view.
* @param classname Name of class to check
*/
public static isSheet(classname: string): boolean {
return classname === SheetViewState.className;
}
/**
* Determines if viewport displays a Sheet view.
* @param viewport ScreenViewport to check
*/
public static isSheetView(viewport: ScreenViewport): boolean {
return ViewUtilities.isSheet(
ViewUtilities.getBisBaseClass(viewport.view.classFullName)
);
}
/**
* Determines if viewport displays a Drawing view.
* @param viewport ScreenViewport to check
*/
public static isDrawingView(viewport: ScreenViewport): boolean {
return ViewUtilities.isDrawing(
ViewUtilities.getBisBaseClass(viewport.view.classFullName)
);
}
/**
* Determines if viewport displays a Orthographic view.
* @param viewport ScreenViewport to check
*/
public static isOrthographicView(viewport: ScreenViewport): boolean {
return ViewUtilities.isOrthographic(
ViewUtilities.getBisBaseClass(viewport.view.classFullName)
);
}
/**
* Determines if viewport displays a Spatial view.
* @param viewport ScreenViewport to check
*/
public static isSpatialView(viewport: ScreenViewport): boolean {
return ViewUtilities.isSpatial(
ViewUtilities.getBisBaseClass(viewport.view.classFullName)
);
}
/**
* Determines if viewport displays a 3d view.
* @param viewport ScreenViewport to check
*/
public static is3dView(viewport: ScreenViewport): boolean {
return viewport.view.is3d();
}
/**
* Determines if viewport supports use of a camera.
* @param viewport ScreenViewport to check
*/
public static viewSupportsCamera(viewport: ScreenViewport): boolean {
return (
SpatialViewState.className ===
ViewUtilities.getBisBaseClass(viewport.view.classFullName)
);
}
}