@itwin/core-backend 3.0.0-dev.100

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.
Files changed (245) hide show
  1. package/CHANGELOG.md +1525 -0
  2. package/LICENSE.md +9 -0
  3. package/README.md +11 -0
  4. package/lib/cjs/AliCloudStorageService.d.ts +12 -0
  5. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -0
  6. package/lib/cjs/AliCloudStorageService.js +70 -0
  7. package/lib/cjs/AliCloudStorageService.js.map +1 -0
  8. package/lib/cjs/BackendHubAccess.d.ts +208 -0
  9. package/lib/cjs/BackendHubAccess.d.ts.map +1 -0
  10. package/lib/cjs/BackendHubAccess.js +42 -0
  11. package/lib/cjs/BackendHubAccess.js.map +1 -0
  12. package/lib/cjs/BackendLoggerCategory.d.ts +83 -0
  13. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -0
  14. package/lib/cjs/BackendLoggerCategory.js +91 -0
  15. package/lib/cjs/BackendLoggerCategory.js.map +1 -0
  16. package/lib/cjs/BisCoreSchema.d.ts +22 -0
  17. package/lib/cjs/BisCoreSchema.d.ts.map +1 -0
  18. package/lib/cjs/BisCoreSchema.js +61 -0
  19. package/lib/cjs/BisCoreSchema.js.map +1 -0
  20. package/lib/cjs/BriefcaseManager.d.ts +167 -0
  21. package/lib/cjs/BriefcaseManager.d.ts.map +1 -0
  22. package/lib/cjs/BriefcaseManager.js +406 -0
  23. package/lib/cjs/BriefcaseManager.js.map +1 -0
  24. package/lib/cjs/Category.d.ts +154 -0
  25. package/lib/cjs/Category.d.ts.map +1 -0
  26. package/lib/cjs/Category.js +244 -0
  27. package/lib/cjs/Category.js.map +1 -0
  28. package/lib/cjs/ChangeSummaryManager.d.ts +188 -0
  29. package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -0
  30. package/lib/cjs/ChangeSummaryManager.js +444 -0
  31. package/lib/cjs/ChangeSummaryManager.js.map +1 -0
  32. package/lib/cjs/ChangedElementsDb.d.ts +97 -0
  33. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -0
  34. package/lib/cjs/ChangedElementsDb.js +166 -0
  35. package/lib/cjs/ChangedElementsDb.js.map +1 -0
  36. package/lib/cjs/ChangedElementsManager.d.ts +40 -0
  37. package/lib/cjs/ChangedElementsManager.d.ts.map +1 -0
  38. package/lib/cjs/ChangedElementsManager.js +89 -0
  39. package/lib/cjs/ChangedElementsManager.js.map +1 -0
  40. package/lib/cjs/CheckpointManager.d.ts +101 -0
  41. package/lib/cjs/CheckpointManager.d.ts.map +1 -0
  42. package/lib/cjs/CheckpointManager.js +257 -0
  43. package/lib/cjs/CheckpointManager.js.map +1 -0
  44. package/lib/cjs/ClassRegistry.d.ts +72 -0
  45. package/lib/cjs/ClassRegistry.d.ts.map +1 -0
  46. package/lib/cjs/ClassRegistry.js +154 -0
  47. package/lib/cjs/ClassRegistry.js.map +1 -0
  48. package/lib/cjs/CloudStorageBackend.d.ts +46 -0
  49. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -0
  50. package/lib/cjs/CloudStorageBackend.js +157 -0
  51. package/lib/cjs/CloudStorageBackend.js.map +1 -0
  52. package/lib/cjs/CodeSpecs.d.ts +51 -0
  53. package/lib/cjs/CodeSpecs.d.ts.map +1 -0
  54. package/lib/cjs/CodeSpecs.js +113 -0
  55. package/lib/cjs/CodeSpecs.js.map +1 -0
  56. package/lib/cjs/ConcurrentQuery.d.ts +12 -0
  57. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -0
  58. package/lib/cjs/ConcurrentQuery.js +24 -0
  59. package/lib/cjs/ConcurrentQuery.js.map +1 -0
  60. package/lib/cjs/DevTools.d.ts +72 -0
  61. package/lib/cjs/DevTools.d.ts.map +1 -0
  62. package/lib/cjs/DevTools.js +155 -0
  63. package/lib/cjs/DevTools.js.map +1 -0
  64. package/lib/cjs/DisplayStyle.d.ts +107 -0
  65. package/lib/cjs/DisplayStyle.d.ts.map +1 -0
  66. package/lib/cjs/DisplayStyle.js +292 -0
  67. package/lib/cjs/DisplayStyle.js.map +1 -0
  68. package/lib/cjs/ECDb.d.ts +196 -0
  69. package/lib/cjs/ECDb.d.ts.map +1 -0
  70. package/lib/cjs/ECDb.js +354 -0
  71. package/lib/cjs/ECDb.js.map +1 -0
  72. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -0
  73. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -0
  74. package/lib/cjs/ECSchemaXmlContext.js +36 -0
  75. package/lib/cjs/ECSchemaXmlContext.js.map +1 -0
  76. package/lib/cjs/ECSqlStatement.d.ts +467 -0
  77. package/lib/cjs/ECSqlStatement.d.ts.map +1 -0
  78. package/lib/cjs/ECSqlStatement.js +783 -0
  79. package/lib/cjs/ECSqlStatement.js.map +1 -0
  80. package/lib/cjs/Element.d.ts +1082 -0
  81. package/lib/cjs/Element.d.ts.map +1 -0
  82. package/lib/cjs/Element.js +1392 -0
  83. package/lib/cjs/Element.js.map +1 -0
  84. package/lib/cjs/ElementAspect.d.ts +157 -0
  85. package/lib/cjs/ElementAspect.d.ts.map +1 -0
  86. package/lib/cjs/ElementAspect.js +179 -0
  87. package/lib/cjs/ElementAspect.js.map +1 -0
  88. package/lib/cjs/ElementGraphics.d.ts +10 -0
  89. package/lib/cjs/ElementGraphics.d.ts.map +1 -0
  90. package/lib/cjs/ElementGraphics.js +42 -0
  91. package/lib/cjs/ElementGraphics.js.map +1 -0
  92. package/lib/cjs/Entity.d.ts +57 -0
  93. package/lib/cjs/Entity.d.ts.map +1 -0
  94. package/lib/cjs/Entity.js +63 -0
  95. package/lib/cjs/Entity.js.map +1 -0
  96. package/lib/cjs/ExportGraphics.d.ts +302 -0
  97. package/lib/cjs/ExportGraphics.d.ts.map +1 -0
  98. package/lib/cjs/ExportGraphics.js +206 -0
  99. package/lib/cjs/ExportGraphics.js.map +1 -0
  100. package/lib/cjs/ExternalSource.d.ts +95 -0
  101. package/lib/cjs/ExternalSource.d.ts.map +1 -0
  102. package/lib/cjs/ExternalSource.js +126 -0
  103. package/lib/cjs/ExternalSource.js.map +1 -0
  104. package/lib/cjs/GeometrySummary.d.ts +5 -0
  105. package/lib/cjs/GeometrySummary.d.ts.map +1 -0
  106. package/lib/cjs/GeometrySummary.js +378 -0
  107. package/lib/cjs/GeometrySummary.js.map +1 -0
  108. package/lib/cjs/IModelCloneContext.d.ts +74 -0
  109. package/lib/cjs/IModelCloneContext.d.ts.map +1 -0
  110. package/lib/cjs/IModelCloneContext.js +130 -0
  111. package/lib/cjs/IModelCloneContext.js.map +1 -0
  112. package/lib/cjs/IModelDb.d.ts +1107 -0
  113. package/lib/cjs/IModelDb.d.ts.map +1 -0
  114. package/lib/cjs/IModelDb.js +2161 -0
  115. package/lib/cjs/IModelDb.js.map +1 -0
  116. package/lib/cjs/IModelHost.d.ts +284 -0
  117. package/lib/cjs/IModelHost.d.ts.map +1 -0
  118. package/lib/cjs/IModelHost.js +411 -0
  119. package/lib/cjs/IModelHost.js.map +1 -0
  120. package/lib/cjs/IModelJsFs.d.ts +63 -0
  121. package/lib/cjs/IModelJsFs.d.ts.map +1 -0
  122. package/lib/cjs/IModelJsFs.js +141 -0
  123. package/lib/cjs/IModelJsFs.js.map +1 -0
  124. package/lib/cjs/IModelSchemaLoader.d.ts +26 -0
  125. package/lib/cjs/IModelSchemaLoader.d.ts.map +1 -0
  126. package/lib/cjs/IModelSchemaLoader.js +95 -0
  127. package/lib/cjs/IModelSchemaLoader.js.map +1 -0
  128. package/lib/cjs/IpcHost.d.ts +99 -0
  129. package/lib/cjs/IpcHost.d.ts.map +1 -0
  130. package/lib/cjs/IpcHost.js +234 -0
  131. package/lib/cjs/IpcHost.js.map +1 -0
  132. package/lib/cjs/LineStyle.d.ts +312 -0
  133. package/lib/cjs/LineStyle.d.ts.map +1 -0
  134. package/lib/cjs/LineStyle.js +296 -0
  135. package/lib/cjs/LineStyle.js.map +1 -0
  136. package/lib/cjs/LocalhostIpcHost.d.ts +19 -0
  137. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -0
  138. package/lib/cjs/LocalhostIpcHost.js +52 -0
  139. package/lib/cjs/LocalhostIpcHost.js.map +1 -0
  140. package/lib/cjs/Material.d.ts +102 -0
  141. package/lib/cjs/Material.d.ts.map +1 -0
  142. package/lib/cjs/Material.js +146 -0
  143. package/lib/cjs/Material.js.map +1 -0
  144. package/lib/cjs/Model.d.ts +387 -0
  145. package/lib/cjs/Model.d.ts.map +1 -0
  146. package/lib/cjs/Model.js +469 -0
  147. package/lib/cjs/Model.js.map +1 -0
  148. package/lib/cjs/NativeAppStorage.d.ts +52 -0
  149. package/lib/cjs/NativeAppStorage.d.ts.map +1 -0
  150. package/lib/cjs/NativeAppStorage.js +203 -0
  151. package/lib/cjs/NativeAppStorage.js.map +1 -0
  152. package/lib/cjs/NativeHost.d.ts +71 -0
  153. package/lib/cjs/NativeHost.d.ts.map +1 -0
  154. package/lib/cjs/NativeHost.js +221 -0
  155. package/lib/cjs/NativeHost.js.map +1 -0
  156. package/lib/cjs/NavigationRelationship.d.ts +157 -0
  157. package/lib/cjs/NavigationRelationship.d.ts.map +1 -0
  158. package/lib/cjs/NavigationRelationship.js +226 -0
  159. package/lib/cjs/NavigationRelationship.js.map +1 -0
  160. package/lib/cjs/PromiseMemoizer.d.ts +52 -0
  161. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -0
  162. package/lib/cjs/PromiseMemoizer.js +93 -0
  163. package/lib/cjs/PromiseMemoizer.js.map +1 -0
  164. package/lib/cjs/Relationship.d.ts +400 -0
  165. package/lib/cjs/Relationship.d.ts.map +1 -0
  166. package/lib/cjs/Relationship.js +460 -0
  167. package/lib/cjs/Relationship.js.map +1 -0
  168. package/lib/cjs/RpcBackend.d.ts +23 -0
  169. package/lib/cjs/RpcBackend.d.ts.map +1 -0
  170. package/lib/cjs/RpcBackend.js +94 -0
  171. package/lib/cjs/RpcBackend.js.map +1 -0
  172. package/lib/cjs/SQLiteDb.d.ts +66 -0
  173. package/lib/cjs/SQLiteDb.d.ts.map +1 -0
  174. package/lib/cjs/SQLiteDb.js +140 -0
  175. package/lib/cjs/SQLiteDb.js.map +1 -0
  176. package/lib/cjs/Schema.d.ts +56 -0
  177. package/lib/cjs/Schema.d.ts.map +1 -0
  178. package/lib/cjs/Schema.js +84 -0
  179. package/lib/cjs/Schema.js.map +1 -0
  180. package/lib/cjs/ServerBasedLocks.d.ts +64 -0
  181. package/lib/cjs/ServerBasedLocks.d.ts.map +1 -0
  182. package/lib/cjs/ServerBasedLocks.js +177 -0
  183. package/lib/cjs/ServerBasedLocks.js.map +1 -0
  184. package/lib/cjs/SqliteStatement.d.ts +264 -0
  185. package/lib/cjs/SqliteStatement.d.ts.map +1 -0
  186. package/lib/cjs/SqliteStatement.js +417 -0
  187. package/lib/cjs/SqliteStatement.js.map +1 -0
  188. package/lib/cjs/Texture.d.ts +59 -0
  189. package/lib/cjs/Texture.d.ts.map +1 -0
  190. package/lib/cjs/Texture.js +83 -0
  191. package/lib/cjs/Texture.js.map +1 -0
  192. package/lib/cjs/TxnManager.d.ts +203 -0
  193. package/lib/cjs/TxnManager.d.ts.map +1 -0
  194. package/lib/cjs/TxnManager.js +354 -0
  195. package/lib/cjs/TxnManager.js.map +1 -0
  196. package/lib/cjs/ViewDefinition.d.ts +432 -0
  197. package/lib/cjs/ViewDefinition.d.ts.map +1 -0
  198. package/lib/cjs/ViewDefinition.js +623 -0
  199. package/lib/cjs/ViewDefinition.js.map +1 -0
  200. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -0
  201. package/lib/cjs/core-backend.d.ts +162 -0
  202. package/lib/cjs/core-backend.d.ts.map +1 -0
  203. package/lib/cjs/core-backend.js +181 -0
  204. package/lib/cjs/core-backend.js.map +1 -0
  205. package/lib/cjs/domains/FunctionalElements.d.ts +102 -0
  206. package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -0
  207. package/lib/cjs/domains/FunctionalElements.js +146 -0
  208. package/lib/cjs/domains/FunctionalElements.js.map +1 -0
  209. package/lib/cjs/domains/FunctionalSchema.d.ts +14 -0
  210. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -0
  211. package/lib/cjs/domains/FunctionalSchema.js +41 -0
  212. package/lib/cjs/domains/FunctionalSchema.js.map +1 -0
  213. package/lib/cjs/domains/GenericElements.d.ts +178 -0
  214. package/lib/cjs/domains/GenericElements.d.ts.map +1 -0
  215. package/lib/cjs/domains/GenericElements.js +264 -0
  216. package/lib/cjs/domains/GenericElements.js.map +1 -0
  217. package/lib/cjs/domains/GenericSchema.d.ts +11 -0
  218. package/lib/cjs/domains/GenericSchema.d.ts.map +1 -0
  219. package/lib/cjs/domains/GenericSchema.js +29 -0
  220. package/lib/cjs/domains/GenericSchema.js.map +1 -0
  221. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +16 -0
  222. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts.map +1 -0
  223. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +33 -0
  224. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -0
  225. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +40 -0
  226. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -0
  227. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +207 -0
  228. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -0
  229. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +21 -0
  230. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -0
  231. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +193 -0
  232. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -0
  233. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +37 -0
  234. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -0
  235. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +162 -0
  236. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -0
  237. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +17 -0
  238. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts.map +1 -0
  239. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +44 -0
  240. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -0
  241. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +16 -0
  242. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts.map +1 -0
  243. package/lib/cjs/rpc-impl/WipRpcImpl.js +35 -0
  244. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -0
  245. package/package.json +101 -0
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DevTools = exports.DevToolsStatsFormatter = void 0;
8
+ const os = require("os");
9
+ const process = require("process");
10
+ const core_bentley_1 = require("@itwin/core-bentley");
11
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
12
+ const IModelHost_1 = require("./IModelHost");
13
+ // cspell:ignore ppid elap
14
+ const loggerCategory = BackendLoggerCategory_1.BackendLoggerCategory.DevTools;
15
+ /** Utility to format the JSON created by DevTools.stats() to include the appropriate units
16
+ * @internal
17
+ */
18
+ class DevToolsStatsFormatter {
19
+ /** Converts the input stats to another JSON object with the appropriate units setup for various fields */
20
+ static toFormattedJson(stats) {
21
+ // Serialize the stats to a string with a replacer that sets up units during the serialization
22
+ const statsStr = JSON.stringify(stats, DevToolsStatsFormatter._replacer);
23
+ // Deserialize back to JSON
24
+ return JSON.parse(statsStr);
25
+ }
26
+ }
27
+ exports.DevToolsStatsFormatter = DevToolsStatsFormatter;
28
+ DevToolsStatsFormatter._megaByteProps = ["totalmem", "freemem", "rss", "heapTotal", "heapUsed", "external"];
29
+ DevToolsStatsFormatter._percentProps = ["user", "nice", "sys", "idle", "irq", "cpuUsage"];
30
+ DevToolsStatsFormatter._mHzProps = ["speed"];
31
+ DevToolsStatsFormatter._secondsProps = ["uptime"];
32
+ /** Replacer that includes units - can be used with JSON.stringify() */
33
+ DevToolsStatsFormatter._replacer = (key, value) => {
34
+ if (DevToolsStatsFormatter._megaByteProps.includes(key))
35
+ return `${value.toFixed()} MB`;
36
+ if (DevToolsStatsFormatter._percentProps.includes(key))
37
+ return `${value.toFixed()}%`;
38
+ if (DevToolsStatsFormatter._mHzProps.includes(key))
39
+ return `${value.toString()} MHz`;
40
+ if (DevToolsStatsFormatter._secondsProps.includes(key))
41
+ return `${value.toFixed()} secs`;
42
+ return value;
43
+ };
44
+ /**
45
+ * Internal diagnostic utility
46
+ * @internal
47
+ */
48
+ class DevTools {
49
+ /** Receives a ping and returns true */
50
+ static ping() {
51
+ core_bentley_1.Logger.logInfo(loggerCategory, "Received ping at backend");
52
+ return true;
53
+ }
54
+ static hrtimeToMS(hrtime) {
55
+ return hrtime[0] * 1000 + hrtime[1] / 1000000;
56
+ }
57
+ static bytesToMegaBytes(bytes) {
58
+ const megaBytes = bytes / Math.pow(1024, 2);
59
+ return Math.round(megaBytes * 100) / 100;
60
+ }
61
+ static evaluateCpuUsage() {
62
+ const NUMBER_OF_CPUS = os.cpus().length;
63
+ const startTime = process.hrtime();
64
+ const startUsage = process.cpuUsage();
65
+ // spin the CPU for 500 milliseconds
66
+ const now = Date.now();
67
+ while (Date.now() - now < 500)
68
+ ;
69
+ const elapTime = process.hrtime(startTime);
70
+ const elapUsage = process.cpuUsage(startUsage);
71
+ const elapTimeMS = this.hrtimeToMS(elapTime);
72
+ const elapUserMS = elapUsage.user / 1000; // microseconds to milliseconds
73
+ const elapSystMS = elapUsage.system / 1000;
74
+ const cpuPercent = Math.round((100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CPUS));
75
+ return cpuPercent;
76
+ }
77
+ static evaluateCpus() {
78
+ // Create a clone
79
+ const srcCpus = os.cpus();
80
+ const cpus = new Array(srcCpus.length);
81
+ let ii = 0;
82
+ for (const srcCpu of srcCpus)
83
+ cpus[ii++] = { ...srcCpu };
84
+ // Evaluate cpu usage as percentages
85
+ for (const cpu of Object.values(cpus)) {
86
+ const total = Object.values(cpu.times).reduce((_total, currValue) => _total += currValue, 0);
87
+ const cpuTimes = cpu.times;
88
+ for (const type of Object.keys(cpuTimes)) {
89
+ const cpuPercent = Math.round(100 * cpuTimes[type] / total);
90
+ cpuTimes[type] = cpuPercent;
91
+ }
92
+ }
93
+ return cpus;
94
+ }
95
+ static evaluateMemoryUsage() {
96
+ // Create a clone
97
+ const memUsage = { ...process.memoryUsage() };
98
+ const memUsageObj = memUsage;
99
+ // Evaluate memory usage as mega bytes
100
+ for (const type of Object.keys(memUsageObj)) {
101
+ memUsageObj[type] = this.bytesToMegaBytes(memUsageObj[type]);
102
+ }
103
+ return memUsage;
104
+ }
105
+ static evaluateProcessStats() {
106
+ return {
107
+ uptime: process.uptime(),
108
+ pid: process.pid,
109
+ ppid: process.ppid,
110
+ memoryUsage: this.evaluateMemoryUsage(),
111
+ };
112
+ }
113
+ static evaluateOsStats() {
114
+ return {
115
+ platform: os.platform(),
116
+ hostname: os.hostname(),
117
+ totalmem: this.bytesToMegaBytes(os.totalmem()),
118
+ freemem: this.bytesToMegaBytes(os.freemem()),
119
+ uptime: os.uptime(),
120
+ cpus: this.evaluateCpus(),
121
+ cpuUsage: this.evaluateCpuUsage(),
122
+ };
123
+ }
124
+ /** Returns JSON object with backend statistics */
125
+ static stats() {
126
+ try {
127
+ const stats = {
128
+ os: this.evaluateOsStats(),
129
+ process: this.evaluateProcessStats(),
130
+ };
131
+ return stats;
132
+ }
133
+ catch (error) {
134
+ core_bentley_1.Logger.logError(loggerCategory, "Could not fetch stats at backend");
135
+ throw error;
136
+ }
137
+ }
138
+ /** Sets up a log level at the backend and returns the old log level */
139
+ static setLogLevel(inLoggerCategory, newLevel) {
140
+ const oldLevel = core_bentley_1.Logger.getLevel(inLoggerCategory);
141
+ core_bentley_1.Logger.logInfo(loggerCategory, `Setting log level`, () => ({ loggerCategory: inLoggerCategory, oldLevel, newLevel }));
142
+ core_bentley_1.Logger.setLevel(inLoggerCategory, newLevel);
143
+ IModelHost_1.IModelHost.platform.clearLogLevelCache();
144
+ return oldLevel;
145
+ }
146
+ /** Obtains the backend application and iModel.js versions */
147
+ static versions() {
148
+ return {
149
+ application: IModelHost_1.IModelHost.applicationVersion,
150
+ iModelJs: require("../../package.json").version, // eslint-disable-line @typescript-eslint/no-var-requires
151
+ };
152
+ }
153
+ }
154
+ exports.DevTools = DevTools;
155
+ //# sourceMappingURL=DevTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DevTools.js","sourceRoot":"","sources":["../../src/DevTools.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,mCAAmC;AACnC,sDAAuD;AACvD,mEAAgE;AAChE,6CAA0C;AAE1C,0BAA0B;AAE1B,MAAM,cAAc,GAAW,6CAAqB,CAAC,QAAQ,CAAC;AAwC9D;;GAEG;AACH,MAAa,sBAAsB;IAmBjC,0GAA0G;IACnG,MAAM,CAAC,eAAe,CAAC,KAAU;QACtC,8FAA8F;QAC9F,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAEzE,2BAA2B;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;;AA1BH,wDA2BC;AA1ByB,qCAAc,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AACrF,oCAAa,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AACnE,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,CAAC,CAAC,OAAO,EAAE,yDAAyD;SAC3G,CAAC;IACJ,CAAC;CACF;AAxHD,4BAwHC","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\r\nimport * as os from \"os\";\r\nimport * as process from \"process\";\r\nimport { Logger, LogLevel } from \"@itwin/core-bentley\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { IModelHost } from \"./IModelHost\";\r\n\r\n// cspell:ignore ppid elap\r\n\r\nconst loggerCategory: string = BackendLoggerCategory.DevTools;\r\n\r\ninterface StringIndexedObject<T> {\r\n [index: string]: T;\r\n}\r\n\r\n/**\r\n * Performance and Memory statistics of backend\r\n * @internal\r\n */\r\nexport interface DevToolsStats {\r\n os: DevToolsOsStats;\r\n process: DevToolsProcessStats;\r\n}\r\n\r\n/**\r\n * OS stats of backend\r\n * @internal\r\n */\r\nexport interface DevToolsOsStats {\r\n platform: NodeJS.Platform;\r\n hostname: string;\r\n totalmem: number;\r\n freemem: number;\r\n uptime: number;\r\n cpus: os.CpuInfo[];\r\n cpuUsage: number;\r\n}\r\n\r\n/**\r\n * Process stats of backend\r\n * @internal\r\n */\r\nexport interface DevToolsProcessStats {\r\n uptime: number;\r\n pid: number;\r\n ppid: number;\r\n memoryUsage: NodeJS.MemoryUsage;\r\n}\r\n\r\n/** Utility to format the JSON created by DevTools.stats() to include the appropriate units\r\n * @internal\r\n */\r\nexport class DevToolsStatsFormatter {\r\n private static readonly _megaByteProps = [\"totalmem\", \"freemem\", \"rss\", \"heapTotal\", \"heapUsed\", \"external\"];\r\n private static readonly _percentProps = [\"user\", \"nice\", \"sys\", \"idle\", \"irq\", \"cpuUsage\"];\r\n private static readonly _mHzProps = [\"speed\"];\r\n private static readonly _secondsProps = [\"uptime\"];\r\n\r\n /** Replacer that includes units - can be used with JSON.stringify() */\r\n private static _replacer = (key: string, value: any) => {\r\n if (DevToolsStatsFormatter._megaByteProps.includes(key))\r\n return `${value.toFixed()} MB`;\r\n if (DevToolsStatsFormatter._percentProps.includes(key))\r\n return `${value.toFixed()}%`;\r\n if (DevToolsStatsFormatter._mHzProps.includes(key))\r\n return `${value.toString()} MHz`;\r\n if (DevToolsStatsFormatter._secondsProps.includes(key))\r\n return `${value.toFixed()} secs`;\r\n return value;\r\n };\r\n\r\n /** Converts the input stats to another JSON object with the appropriate units setup for various fields */\r\n public static toFormattedJson(stats: any) {\r\n // Serialize the stats to a string with a replacer that sets up units during the serialization\r\n const statsStr = JSON.stringify(stats, DevToolsStatsFormatter._replacer);\r\n\r\n // Deserialize back to JSON\r\n return JSON.parse(statsStr);\r\n }\r\n}\r\n\r\n/**\r\n * Internal diagnostic utility\r\n * @internal\r\n */\r\nexport class DevTools {\r\n\r\n /** Receives a ping and returns true */\r\n public static ping(): boolean {\r\n Logger.logInfo(loggerCategory, \"Received ping at backend\");\r\n return true;\r\n }\r\n\r\n private static hrtimeToMS(hrtime: any) {\r\n return hrtime[0] * 1000 + hrtime[1] / 1000000;\r\n }\r\n\r\n private static bytesToMegaBytes(bytes: number): number {\r\n const megaBytes = bytes / Math.pow(1024, 2);\r\n return Math.round(megaBytes * 100) / 100;\r\n }\r\n\r\n private static evaluateCpuUsage(): number {\r\n const NUMBER_OF_CPUS = os.cpus().length;\r\n const startTime = process.hrtime();\r\n const startUsage = process.cpuUsage();\r\n\r\n // spin the CPU for 500 milliseconds\r\n const now = Date.now();\r\n while (Date.now() - now < 500);\r\n\r\n const elapTime = process.hrtime(startTime);\r\n const elapUsage = process.cpuUsage(startUsage);\r\n\r\n const elapTimeMS = this.hrtimeToMS(elapTime);\r\n\r\n const elapUserMS = elapUsage.user / 1000; // microseconds to milliseconds\r\n const elapSystMS = elapUsage.system / 1000;\r\n const cpuPercent = Math.round((100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CPUS));\r\n\r\n return cpuPercent;\r\n }\r\n\r\n private static evaluateCpus(): os.CpuInfo[] {\r\n // Create a clone\r\n const srcCpus = os.cpus();\r\n const cpus = new Array<os.CpuInfo>(srcCpus.length);\r\n let ii = 0;\r\n for (const srcCpu of srcCpus)\r\n cpus[ii++] = { ...srcCpu };\r\n\r\n // Evaluate cpu usage as percentages\r\n for (const cpu of Object.values(cpus)) {\r\n const total = Object.values(cpu.times).reduce((_total: number, currValue) => _total += currValue, 0);\r\n const cpuTimes = cpu.times as StringIndexedObject<number>;\r\n for (const type of Object.keys(cpuTimes)) {\r\n const cpuPercent = Math.round(100 * cpuTimes[type] / total);\r\n cpuTimes[type] = cpuPercent;\r\n }\r\n }\r\n return cpus;\r\n }\r\n\r\n private static evaluateMemoryUsage() {\r\n // Create a clone\r\n const memUsage = { ...process.memoryUsage() } as NodeJS.MemoryUsage;\r\n const memUsageObj = (memUsage as any) as StringIndexedObject<number>;\r\n // Evaluate memory usage as mega bytes\r\n for (const type of Object.keys(memUsageObj)) {\r\n memUsageObj[type] = this.bytesToMegaBytes(memUsageObj[type]);\r\n }\r\n return memUsage;\r\n }\r\n\r\n private static evaluateProcessStats(): DevToolsProcessStats {\r\n return {\r\n uptime: process.uptime(),\r\n pid: process.pid,\r\n ppid: process.ppid,\r\n memoryUsage: this.evaluateMemoryUsage(),\r\n } as DevToolsProcessStats;\r\n }\r\n\r\n private static evaluateOsStats(): DevToolsOsStats {\r\n return {\r\n platform: os.platform(),\r\n hostname: os.hostname(),\r\n totalmem: this.bytesToMegaBytes(os.totalmem()),\r\n freemem: this.bytesToMegaBytes(os.freemem()),\r\n uptime: os.uptime(),\r\n cpus: this.evaluateCpus(),\r\n cpuUsage: this.evaluateCpuUsage(),\r\n } as DevToolsOsStats;\r\n }\r\n\r\n /** Returns JSON object with backend statistics */\r\n public static stats(): DevToolsStats {\r\n try {\r\n const stats = {\r\n os: this.evaluateOsStats(),\r\n process: this.evaluateProcessStats(),\r\n } as DevToolsStats;\r\n return stats;\r\n } catch (error) {\r\n Logger.logError(loggerCategory, \"Could not fetch stats at backend\");\r\n throw error;\r\n }\r\n }\r\n\r\n /** Sets up a log level at the backend and returns the old log level */\r\n public static setLogLevel(inLoggerCategory: string, newLevel: LogLevel): LogLevel | undefined {\r\n const oldLevel = Logger.getLevel(inLoggerCategory);\r\n Logger.logInfo(loggerCategory, `Setting log level`, () => ({ loggerCategory: inLoggerCategory, oldLevel, newLevel }));\r\n Logger.setLevel(inLoggerCategory, newLevel);\r\n IModelHost.platform.clearLogLevelCache();\r\n return oldLevel;\r\n }\r\n\r\n /** Obtains the backend application and iModel.js versions */\r\n public static versions() {\r\n return {\r\n application: IModelHost.applicationVersion,\r\n iModelJs: require(\"../../package.json\").version, // eslint-disable-line @typescript-eslint/no-var-requires\r\n };\r\n }\r\n}\r\n"]}
@@ -0,0 +1,107 @@
1
+ /** @packageDocumentation
2
+ * @module ViewDefinitions
3
+ */
4
+ import { Id64Set, Id64String } from "@itwin/core-bentley";
5
+ import { Code, CodeScopeProps, ColorDef, DisplayStyle3dProps, DisplayStyle3dSettings, DisplayStyle3dSettingsProps, DisplayStyleProps, DisplayStyleSettings, RenderSchedule, ViewFlags } from "@itwin/core-common";
6
+ import { DefinitionElement } from "./Element";
7
+ import { IModelCloneContext } from "./IModelCloneContext";
8
+ import { IModelDb } from "./IModelDb";
9
+ /** A DisplayStyle defines the parameters for 'styling' the contents of a view.
10
+ * Internally a DisplayStyle consists of a dictionary of several named 'styles' describing specific aspects of the display style as a whole.
11
+ * Many ViewDefinitions may share the same DisplayStyle.
12
+ * @public
13
+ */
14
+ export declare abstract class DisplayStyle extends DefinitionElement implements DisplayStyleProps {
15
+ /** @internal */
16
+ static get className(): string;
17
+ abstract get settings(): DisplayStyleSettings;
18
+ /** @internal */
19
+ protected constructor(props: DisplayStyleProps, iModel: IModelDb);
20
+ /** Create a Code for a DisplayStyle given a name that is meant to be unique within the scope of the specified DefinitionModel.
21
+ * @param iModel The IModelDb
22
+ * @param scopeModelId The Id of the DefinitionModel that contains the DisplayStyle and provides the scope for its name.
23
+ * @param codeValue The DisplayStyle name
24
+ */
25
+ static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, codeValue: string): Code;
26
+ /** @alpha */
27
+ protected collectPredecessorIds(predecessorIds: Id64Set): void;
28
+ /** @alpha */
29
+ protected static onCloned(context: IModelCloneContext, sourceElementProps: DisplayStyleProps, targetElementProps: DisplayStyleProps): void;
30
+ loadScheduleScript(): RenderSchedule.ScriptReference | undefined;
31
+ }
32
+ /** A DisplayStyle for 2d views.
33
+ * @public
34
+ */
35
+ export declare class DisplayStyle2d extends DisplayStyle {
36
+ /** @internal */
37
+ static get className(): string;
38
+ private readonly _settings;
39
+ get settings(): DisplayStyleSettings;
40
+ /** @internal */
41
+ constructor(props: DisplayStyleProps, iModel: IModelDb);
42
+ /** Create a DisplayStyle2d for use by a ViewDefinition.
43
+ * @param iModelDb The iModel
44
+ * @param definitionModelId The [[DefinitionModel]]
45
+ * @param name The name/CodeValue of the DisplayStyle2d
46
+ * @returns The newly constructed DisplayStyle2d element.
47
+ * @throws [[IModelError]] if unable to create the element.
48
+ */
49
+ static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string): DisplayStyle2d;
50
+ /** Insert a DisplayStyle2d for use by a ViewDefinition.
51
+ * @param iModelDb Insert into this iModel
52
+ * @param definitionModelId Insert the new DisplayStyle2d into this DefinitionModel
53
+ * @param name The name of the DisplayStyle2d
54
+ * @returns The Id of the newly inserted DisplayStyle2d element.
55
+ * @throws [[IModelError]] if unable to insert the element.
56
+ */
57
+ static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string): Id64String;
58
+ }
59
+ /** Describes initial settings for a new [[DisplayStyle3d]].
60
+ * Most properties are inherited from [DisplayStyle3dSettingsProps]($common), but for backwards compatibility reasons, this interface is slightly awkward:
61
+ * - It adds a `viewFlags` member that differs only in case and type from [DisplayStyleSettingsProps.viewflags]($common); and
62
+ * - It extends the type of [DisplayStyleSettingsProps.backgroundColor]($common) to include [ColorDef]($common).
63
+ * These idiosyncrasies will be addressed in a future version of core-backend.
64
+ * @see [[DisplayStyle3d.create]].
65
+ * @public
66
+ */
67
+ export interface DisplayStyleCreationOptions extends Omit<DisplayStyle3dSettingsProps, "backgroundColor" | "scheduleScript"> {
68
+ /** If supplied, the [ViewFlags]($common) applied by the display style.
69
+ * If undefined, [DisplayStyle3dSettingsProps.viewflags]($common) will be used if present (note the difference in case); otherwise, default-constructed [ViewFlags]($common) will be used.
70
+ */
71
+ viewFlags?: ViewFlags;
72
+ backgroundColor?: ColorDef | number;
73
+ }
74
+ /** A DisplayStyle for 3d views.
75
+ * See [how to create a DisplayStyle3d]$(docs/learning/backend/CreateElements.md#DisplayStyle3d).
76
+ * @public
77
+ */
78
+ export declare class DisplayStyle3d extends DisplayStyle implements DisplayStyle3dProps {
79
+ /** @internal */
80
+ static get className(): string;
81
+ private readonly _settings;
82
+ get settings(): DisplayStyle3dSettings;
83
+ /** @internal */
84
+ constructor(props: DisplayStyle3dProps, iModel: IModelDb);
85
+ /** @alpha */
86
+ protected collectPredecessorIds(predecessorIds: Id64Set): void;
87
+ /** @alpha */
88
+ protected static onCloned(context: IModelCloneContext, sourceElementProps: DisplayStyle3dProps, targetElementProps: DisplayStyle3dProps): void;
89
+ /** Create a DisplayStyle3d for use by a ViewDefinition.
90
+ * @param iModelDb The iModel
91
+ * @param definitionModelId The [[DefinitionModel]]
92
+ * @param name The name/CodeValue of the DisplayStyle3d
93
+ * @returns The newly constructed DisplayStyle3d element.
94
+ * @throws [[IModelError]] if unable to create the element.
95
+ */
96
+ static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): DisplayStyle3d;
97
+ /**
98
+ * Insert a DisplayStyle3d for use by a ViewDefinition.
99
+ * @param iModelDb Insert into this iModel
100
+ * @param definitionModelId Insert the new DisplayStyle3d into this [[DefinitionModel]]
101
+ * @param name The name of the DisplayStyle3d
102
+ * @returns The Id of the newly inserted DisplayStyle3d element.
103
+ * @throws [[IModelError]] if unable to insert the element.
104
+ */
105
+ static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): Id64String;
106
+ }
107
+ //# sourceMappingURL=DisplayStyle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DisplayStyle.d.ts","sourceRoot":"","sources":["../../src/DisplayStyle.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAsC,OAAO,EAAE,UAAU,EAAuB,MAAM,qBAAqB,CAAC;AACnH,OAAO,EACQ,IAAI,EAAE,cAAc,EAAY,QAAQ,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,2BAA2B,EAC/H,iBAAiB,EAAE,oBAAoB,EAA+B,cAAc,EAAoB,SAAS,EAClH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAkB,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;;GAIG;AACH,8BAAsB,YAAa,SAAQ,iBAAkB,YAAW,iBAAiB;IACvF,gBAAgB;IAChB,WAA2B,SAAS,IAAI,MAAM,CAA2B;IACzE,aAAoB,QAAQ,IAAI,oBAAoB,CAAC;IAErD,gBAAgB;IAChB,SAAS,aAAa,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ;IAIhE;;;;OAIG;WACW,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAKjG,aAAa;cACM,qBAAqB,CAAC,cAAc,EAAE,OAAO,GAAG,IAAI;IAkBvE,aAAa;qBACa,QAAQ,CAAC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,iBAAiB,GAAG,IAAI;IAmD5I,kBAAkB,IAAI,cAA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AAC,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,cAAc;IAyB5I;;;;;;;OAOG;WACW,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,UAAU;CAIzI"}
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module ViewDefinitions
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.DisplayStyle3d = exports.DisplayStyle2d = exports.DisplayStyle = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_common_1 = require("@itwin/core-common");
13
+ const Element_1 = require("./Element");
14
+ /** A DisplayStyle defines the parameters for 'styling' the contents of a view.
15
+ * Internally a DisplayStyle consists of a dictionary of several named 'styles' describing specific aspects of the display style as a whole.
16
+ * Many ViewDefinitions may share the same DisplayStyle.
17
+ * @public
18
+ */
19
+ class DisplayStyle extends Element_1.DefinitionElement {
20
+ /** @internal */
21
+ static get className() { return "DisplayStyle"; }
22
+ /** @internal */
23
+ constructor(props, iModel) {
24
+ super(props, iModel);
25
+ }
26
+ /** Create a Code for a DisplayStyle given a name that is meant to be unique within the scope of the specified DefinitionModel.
27
+ * @param iModel The IModelDb
28
+ * @param scopeModelId The Id of the DefinitionModel that contains the DisplayStyle and provides the scope for its name.
29
+ * @param codeValue The DisplayStyle name
30
+ */
31
+ static createCode(iModel, scopeModelId, codeValue) {
32
+ const codeSpec = iModel.codeSpecs.getByName(core_common_1.BisCodeSpec.displayStyle);
33
+ return new core_common_1.Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });
34
+ }
35
+ /** @alpha */
36
+ collectPredecessorIds(predecessorIds) {
37
+ super.collectPredecessorIds(predecessorIds);
38
+ for (const [id] of this.settings.subCategoryOverrides) {
39
+ predecessorIds.add(id);
40
+ }
41
+ for (const excludedElementId of this.settings.excludedElementIds)
42
+ predecessorIds.add(excludedElementId);
43
+ if (this.settings.renderTimeline) {
44
+ predecessorIds.add(this.settings.renderTimeline);
45
+ }
46
+ else {
47
+ const script = this.loadScheduleScript();
48
+ if (script)
49
+ script.script.discloseIds(predecessorIds);
50
+ }
51
+ }
52
+ /** @alpha */
53
+ static onCloned(context, sourceElementProps, targetElementProps) {
54
+ var _a;
55
+ super.onCloned(context, sourceElementProps, targetElementProps);
56
+ if (!context.isBetweenIModels || !((_a = targetElementProps.jsonProperties) === null || _a === void 0 ? void 0 : _a.styles))
57
+ return;
58
+ const settings = targetElementProps.jsonProperties.styles;
59
+ if (settings.subCategoryOvr) {
60
+ for (let i = 0; i < settings.subCategoryOvr.length; /* */) {
61
+ const ovr = settings.subCategoryOvr[i];
62
+ ovr.subCategory = context.findTargetElementId(core_bentley_1.Id64.fromJSON(ovr.subCategory));
63
+ if (core_bentley_1.Id64.invalid === ovr.subCategory)
64
+ settings.subCategoryOvr.splice(i, 1);
65
+ else
66
+ i++;
67
+ }
68
+ }
69
+ if (settings.excludedElements) {
70
+ const excluded = "string" === typeof settings.excludedElements ? core_bentley_1.CompressedId64Set.decompressArray(settings.excludedElements) : settings.excludedElements;
71
+ for (let i = 0; i < excluded.length; /* */) {
72
+ const remapped = context.findTargetElementId(excluded[i]);
73
+ if (core_bentley_1.Id64.invalid === remapped)
74
+ excluded.splice(i, 1);
75
+ else
76
+ excluded[i++] = remapped;
77
+ }
78
+ if (0 === excluded.length)
79
+ delete settings.excludedElements;
80
+ else
81
+ settings.excludedElements = core_bentley_1.CompressedId64Set.compressIds(core_bentley_1.OrderedId64Iterable.sortArray(excluded));
82
+ }
83
+ // eslint-disable-next-line deprecation/deprecation
84
+ if (settings.renderTimeline) {
85
+ const renderTimeline = context.findTargetElementId(settings.renderTimeline);
86
+ if (core_bentley_1.Id64.isValid(renderTimeline))
87
+ settings.renderTimeline = renderTimeline;
88
+ else
89
+ delete settings.renderTimeline;
90
+ }
91
+ else if (settings.scheduleScript) { // eslint-disable-line deprecation/deprecation
92
+ // eslint-disable-next-line deprecation/deprecation
93
+ const scheduleScript = Element_1.RenderTimeline.remapScript(context, settings.scheduleScript);
94
+ if (scheduleScript.length > 0)
95
+ settings.scheduleScript = scheduleScript; // eslint-disable-line deprecation/deprecation
96
+ else
97
+ delete settings.scheduleScript; // eslint-disable-line deprecation/deprecation
98
+ }
99
+ }
100
+ loadScheduleScript() {
101
+ let script;
102
+ let sourceId;
103
+ if (this.settings.renderTimeline) {
104
+ const timeline = this.iModel.elements.tryGetElement(this.settings.renderTimeline);
105
+ if (timeline) {
106
+ script = core_common_1.RenderSchedule.Script.fromJSON(timeline.scriptProps);
107
+ sourceId = timeline.id;
108
+ }
109
+ }
110
+ else if (this.settings.scheduleScriptProps) { // eslint-disable-line deprecation/deprecation
111
+ // eslint-disable-next-line deprecation/deprecation
112
+ script = core_common_1.RenderSchedule.Script.fromJSON(this.settings.scheduleScriptProps);
113
+ sourceId = this.id;
114
+ }
115
+ return undefined !== sourceId && undefined !== script ? new core_common_1.RenderSchedule.ScriptReference(sourceId, script) : undefined;
116
+ }
117
+ }
118
+ exports.DisplayStyle = DisplayStyle;
119
+ /** A DisplayStyle for 2d views.
120
+ * @public
121
+ */
122
+ class DisplayStyle2d extends DisplayStyle {
123
+ /** @internal */
124
+ constructor(props, iModel) {
125
+ super(props, iModel);
126
+ this._settings = new core_common_1.DisplayStyleSettings(this.jsonProperties);
127
+ }
128
+ /** @internal */
129
+ static get className() { return "DisplayStyle2d"; }
130
+ get settings() { return this._settings; }
131
+ /** Create a DisplayStyle2d for use by a ViewDefinition.
132
+ * @param iModelDb The iModel
133
+ * @param definitionModelId The [[DefinitionModel]]
134
+ * @param name The name/CodeValue of the DisplayStyle2d
135
+ * @returns The newly constructed DisplayStyle2d element.
136
+ * @throws [[IModelError]] if unable to create the element.
137
+ */
138
+ static create(iModelDb, definitionModelId, name) {
139
+ const displayStyleProps = {
140
+ classFullName: this.classFullName,
141
+ code: this.createCode(iModelDb, definitionModelId, name),
142
+ model: definitionModelId,
143
+ isPrivate: false,
144
+ jsonProperties: {
145
+ styles: {
146
+ backgroundColor: 0,
147
+ monochromeColor: core_common_1.ColorDef.white.toJSON(),
148
+ viewflags: core_common_1.ViewFlags.defaults,
149
+ },
150
+ },
151
+ };
152
+ return new DisplayStyle2d(displayStyleProps, iModelDb);
153
+ }
154
+ /** Insert a DisplayStyle2d for use by a ViewDefinition.
155
+ * @param iModelDb Insert into this iModel
156
+ * @param definitionModelId Insert the new DisplayStyle2d into this DefinitionModel
157
+ * @param name The name of the DisplayStyle2d
158
+ * @returns The Id of the newly inserted DisplayStyle2d element.
159
+ * @throws [[IModelError]] if unable to insert the element.
160
+ */
161
+ static insert(iModelDb, definitionModelId, name) {
162
+ const displayStyle = this.create(iModelDb, definitionModelId, name);
163
+ return iModelDb.elements.insertElement(displayStyle);
164
+ }
165
+ }
166
+ exports.DisplayStyle2d = DisplayStyle2d;
167
+ /** A DisplayStyle for 3d views.
168
+ * See [how to create a DisplayStyle3d]$(docs/learning/backend/CreateElements.md#DisplayStyle3d).
169
+ * @public
170
+ */
171
+ class DisplayStyle3d extends DisplayStyle {
172
+ /** @internal */
173
+ constructor(props, iModel) {
174
+ super(props, iModel);
175
+ this._settings = new core_common_1.DisplayStyle3dSettings(this.jsonProperties);
176
+ }
177
+ /** @internal */
178
+ static get className() { return "DisplayStyle3d"; }
179
+ get settings() { return this._settings; }
180
+ /** @alpha */
181
+ collectPredecessorIds(predecessorIds) {
182
+ var _a, _b;
183
+ super.collectPredecessorIds(predecessorIds);
184
+ const skyBoxImageProps = (_b = (_a = this.settings.environment) === null || _a === void 0 ? void 0 : _a.sky) === null || _b === void 0 ? void 0 : _b.image;
185
+ if (skyBoxImageProps === null || skyBoxImageProps === void 0 ? void 0 : skyBoxImageProps.texture) {
186
+ predecessorIds.add(core_bentley_1.Id64.fromJSON(skyBoxImageProps.texture));
187
+ }
188
+ if (skyBoxImageProps === null || skyBoxImageProps === void 0 ? void 0 : skyBoxImageProps.textures) {
189
+ if (skyBoxImageProps.textures.back) {
190
+ predecessorIds.add(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.back));
191
+ }
192
+ if (skyBoxImageProps.textures.bottom) {
193
+ predecessorIds.add(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.bottom));
194
+ }
195
+ if (skyBoxImageProps.textures.front) {
196
+ predecessorIds.add(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.front));
197
+ }
198
+ if (skyBoxImageProps.textures.left) {
199
+ predecessorIds.add(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.left));
200
+ }
201
+ if (skyBoxImageProps.textures.right) {
202
+ predecessorIds.add(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.right));
203
+ }
204
+ if (skyBoxImageProps.textures.top) {
205
+ predecessorIds.add(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.top));
206
+ }
207
+ }
208
+ if (this.settings.planProjectionSettings) {
209
+ for (const planProjectionSetting of this.settings.planProjectionSettings) {
210
+ predecessorIds.add(planProjectionSetting[0]);
211
+ }
212
+ }
213
+ }
214
+ /** @alpha */
215
+ static onCloned(context, sourceElementProps, targetElementProps) {
216
+ var _a, _b, _c, _d, _e, _f;
217
+ super.onCloned(context, sourceElementProps, targetElementProps);
218
+ if (context.isBetweenIModels) {
219
+ const skyBoxImageProps = (_d = (_c = (_b = (_a = targetElementProps === null || targetElementProps === void 0 ? void 0 : targetElementProps.jsonProperties) === null || _a === void 0 ? void 0 : _a.styles) === null || _b === void 0 ? void 0 : _b.environment) === null || _c === void 0 ? void 0 : _c.sky) === null || _d === void 0 ? void 0 : _d.image;
220
+ if (skyBoxImageProps === null || skyBoxImageProps === void 0 ? void 0 : skyBoxImageProps.texture) {
221
+ const textureId = context.findTargetElementId(core_bentley_1.Id64.fromJSON(skyBoxImageProps.texture));
222
+ skyBoxImageProps.texture = core_bentley_1.Id64.isValidId64(textureId) ? textureId : undefined;
223
+ }
224
+ if (skyBoxImageProps === null || skyBoxImageProps === void 0 ? void 0 : skyBoxImageProps.textures) {
225
+ const backTextureId = context.findTargetElementId(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.back));
226
+ skyBoxImageProps.textures.back = core_bentley_1.Id64.isValidId64(backTextureId) ? backTextureId : undefined;
227
+ const bottomTextureId = context.findTargetElementId(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.bottom));
228
+ skyBoxImageProps.textures.bottom = core_bentley_1.Id64.isValidId64(bottomTextureId) ? bottomTextureId : undefined;
229
+ const frontTextureId = context.findTargetElementId(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.front));
230
+ skyBoxImageProps.textures.front = core_bentley_1.Id64.isValidId64(frontTextureId) ? frontTextureId : undefined;
231
+ const leftTextureId = context.findTargetElementId(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.left));
232
+ skyBoxImageProps.textures.left = core_bentley_1.Id64.isValidId64(leftTextureId) ? leftTextureId : undefined;
233
+ const rightTextureId = context.findTargetElementId(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.right));
234
+ skyBoxImageProps.textures.right = core_bentley_1.Id64.isValidId64(rightTextureId) ? rightTextureId : undefined;
235
+ const topTextureId = context.findTargetElementId(core_bentley_1.Id64.fromJSON(skyBoxImageProps.textures.top));
236
+ skyBoxImageProps.textures.top = core_bentley_1.Id64.isValidId64(topTextureId) ? topTextureId : undefined;
237
+ }
238
+ if ((_f = (_e = targetElementProps === null || targetElementProps === void 0 ? void 0 : targetElementProps.jsonProperties) === null || _e === void 0 ? void 0 : _e.styles) === null || _f === void 0 ? void 0 : _f.planProjections) {
239
+ const remappedPlanProjections = {};
240
+ for (const entry of Object.entries(targetElementProps.jsonProperties.styles.planProjections)) {
241
+ const remappedModelId = context.findTargetElementId(entry[0]);
242
+ if (core_bentley_1.Id64.isValidId64(remappedModelId)) {
243
+ remappedPlanProjections[remappedModelId] = entry[1];
244
+ }
245
+ }
246
+ targetElementProps.jsonProperties.styles.planProjections = remappedPlanProjections;
247
+ }
248
+ }
249
+ }
250
+ /** Create a DisplayStyle3d for use by a ViewDefinition.
251
+ * @param iModelDb The iModel
252
+ * @param definitionModelId The [[DefinitionModel]]
253
+ * @param name The name/CodeValue of the DisplayStyle3d
254
+ * @returns The newly constructed DisplayStyle3d element.
255
+ * @throws [[IModelError]] if unable to create the element.
256
+ */
257
+ static create(iModelDb, definitionModelId, name, options) {
258
+ var _a, _b;
259
+ options = options !== null && options !== void 0 ? options : {};
260
+ let viewflags = (_a = options.viewFlags) === null || _a === void 0 ? void 0 : _a.toJSON();
261
+ if (!viewflags)
262
+ viewflags = (_b = options.viewflags) !== null && _b !== void 0 ? _b : new core_common_1.ViewFlags().toJSON();
263
+ const backgroundColor = options.backgroundColor instanceof core_common_1.ColorDef ? options.backgroundColor.toJSON() : options.backgroundColor;
264
+ const settings = {
265
+ ...options,
266
+ viewflags,
267
+ backgroundColor,
268
+ };
269
+ const displayStyleProps = {
270
+ classFullName: this.classFullName,
271
+ code: this.createCode(iModelDb, definitionModelId, name),
272
+ model: definitionModelId,
273
+ jsonProperties: { styles: settings },
274
+ isPrivate: false,
275
+ };
276
+ return new DisplayStyle3d(displayStyleProps, iModelDb);
277
+ }
278
+ /**
279
+ * Insert a DisplayStyle3d for use by a ViewDefinition.
280
+ * @param iModelDb Insert into this iModel
281
+ * @param definitionModelId Insert the new DisplayStyle3d into this [[DefinitionModel]]
282
+ * @param name The name of the DisplayStyle3d
283
+ * @returns The Id of the newly inserted DisplayStyle3d element.
284
+ * @throws [[IModelError]] if unable to insert the element.
285
+ */
286
+ static insert(iModelDb, definitionModelId, name, options) {
287
+ const displayStyle = this.create(iModelDb, definitionModelId, name, options);
288
+ return iModelDb.elements.insertElement(displayStyle);
289
+ }
290
+ }
291
+ exports.DisplayStyle3d = DisplayStyle3d;
292
+ //# sourceMappingURL=DisplayStyle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DisplayStyle.js","sourceRoot":"","sources":["../../src/DisplayStyle.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAmH;AACnH,oDAG4B;AAC5B,uCAA8D;AAI9D;;;;GAIG;AACH,MAAsB,YAAa,SAAQ,2BAAiB;IAC1D,gBAAgB;IACT,MAAM,KAAc,SAAS,KAAa,OAAO,cAAc,CAAC,CAAC,CAAC;IAGzE,gBAAgB;IAChB,YAAsB,KAAwB,EAAE,MAAgB;QAC9D,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAU,CAAC,MAAgB,EAAE,YAA4B,EAAE,SAAiB;QACxF,MAAM,QAAQ,GAAa,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,yBAAW,CAAC,YAAY,CAAC,CAAC;QAChF,OAAO,IAAI,kBAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAChF,CAAC;IAED,aAAa;IACM,qBAAqB,CAAC,cAAuB;QAC9D,KAAK,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;QAC5C,KAAK,MAAM,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,oBAAoB,EAAE;YACrD,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SACxB;QAED,KAAK,MAAM,iBAAiB,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB;YAC9D,cAAc,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAExC,IAAI,IAAI,CAAC,QAAQ,C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CAAC,MAAM,EAAE,CAAC;QAE5D,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,YAAY,sBAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC;QAEjI,MAAM,QAAQ,GAAgC;YAC5C,GAAG,OAAO;YACV,SAAS;YACT,eAAe;SAChB,CAAC;QAEF,MAAM,iBAAiB,GAAwB;YAC7C,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,CAAC;YACxD,KAAK,EAAE,iBAAiB;YACxB,cAAc,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;YACpC,SAAS,EAAE,KAAK;SAEjB,CAAC;QAEF,OAAO,IAAI,cAAc,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;IACD;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CAAC,QAAkB,EAAE,iBAA6B,EAAE,IAAY,EAAE,OAAqC;QACzH,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC7E,OAAO,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IACvD,CAAC;CACF;AAlHD,wCAkHC","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 ViewDefinitions\r\n */\r\n\r\nimport { CompressedId64Set, Id64, Id64Array, Id64Set, Id64String, OrderedId64Iterable } from \"@itwin/core-bentley\";\r\nimport {\r\n BisCodeSpec, Code, CodeScopeProps, CodeSpec, ColorDef, DisplayStyle3dProps, DisplayStyle3dSettings, DisplayStyle3dSettingsProps,\r\n DisplayStyleProps, DisplayStyleSettings, PlanProjectionSettingsProps, RenderSchedule, SkyBoxImageProps, ViewFlags,\r\n} from \"@itwin/core-common\";\r\nimport { DefinitionElement, RenderTimeline } from \"./Element\";\r\nimport { IModelCloneContext } from \"./IModelCloneContext\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\n/** A DisplayStyle defines the parameters for 'styling' the contents of a view.\r\n * Internally a DisplayStyle consists of a dictionary of several named 'styles' describing specific aspects of the display style as a whole.\r\n * Many ViewDefinitions may share the same DisplayStyle.\r\n * @public\r\n */\r\nexport abstract class DisplayStyle extends DefinitionElement implements DisplayStyleProps {\r\n /** @internal */\r\n public static override get className(): string { return \"DisplayStyle\"; }\r\n public abstract get settings(): DisplayStyleSettings;\r\n\r\n /** @internal */\r\n protected constructor(props: DisplayStyleProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n }\r\n\r\n /** Create a Code for a DisplayStyle given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModelDb\r\n * @param scopeModelId The Id of the DefinitionModel that contains the DisplayStyle and provides the scope for its name.\r\n * @param codeValue The DisplayStyle name\r\n */\r\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, codeValue: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.displayStyle);\r\n return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });\r\n }\r\n\r\n /** @alpha */\r\n protected override collectPredecessorIds(predecessorIds: Id64Set): void {\r\n super.collectPredecessorIds(predecessorIds);\r\n for (const [id] of this.settings.subCategoryOverrides) {\r\n predecessorIds.add(id);\r\n }\r\n\r\n for (const excludedElementId of this.settings.excludedElementIds)\r\n predecessorIds.add(excludedElementId);\r\n\r\n if (this.settings.renderTimeline) {\r\n predecessorIds.add(this.settings.renderTimeline);\r\n } else {\r\n const script = this.loadScheduleScript();\r\n if (script)\r\n script.script.discloseIds(predecessorIds);\r\n }\r\n }\r\n\r\n /** @alpha */\r\n protected static override onCloned(context: IModelCloneContext, sourceElementProps: DisplayStyleProps, targetElementProps: DisplayStyleProps): void {\r\n super.onCloned(context, sourceElementProps, targetElementProps);\r\n\r\n if (!context.isBetweenIModels || !targetElementProps.jsonProperties?.styles)\r\n return;\r\n\r\n const settings = targetElementProps.jsonProperties.styles;\r\n if (settings.subCategoryOvr) {\r\n for (let i = 0; i < settings.subCategoryOvr.length; /* */) {\r\n const ovr = settings.subCategoryOvr[i];\r\n ovr.subCategory = context.findTargetElementId(Id64.fromJSON(ovr.subCategory));\r\n if (Id64.invalid === ovr.subCategory)\r\n settings.subCategoryOvr.splice(i, 1);\r\n else\r\n i++;\r\n }\r\n }\r\n\r\n if (settings.excludedElements) {\r\n const excluded: Id64Array = \"string\" === typeof settings.excludedElements ? CompressedId64Set.decompressArray(settings.excludedElements) : settings.excludedElements;\r\n for (let i = 0; i < excluded.length; /* */) {\r\n const remapped = context.findTargetElementId(excluded[i]);\r\n if (Id64.invalid === remapped)\r\n excluded.splice(i, 1);\r\n else\r\n excluded[i++] = remapped;\r\n }\r\n\r\n if (0 === excluded.length)\r\n delete settings.excludedElements;\r\n else\r\n settings.excludedElements = CompressedId64Set.compressIds(OrderedId64Iterable.sortArray(excluded));\r\n }\r\n\r\n // eslint-disable-next-line deprecation/deprecation\r\n if (settings.renderTimeline) {\r\n const renderTimeline = context.findTargetElementId(settings.renderTimeline);\r\n if (Id64.isValid(renderTimeline))\r\n settings.renderTimeline = renderTimeline;\r\n else\r\n delete settings.renderTimeline;\r\n } else if (settings.scheduleScript) { // eslint-disable-line deprecation/deprecation\r\n // eslint-disable-next-line deprecation/deprecation\r\n const scheduleScript = RenderTimeline.remapScript(context, settings.scheduleScript);\r\n if (scheduleScript.length > 0)\r\n settings.scheduleScript = scheduleScript; // eslint-disable-line deprecation/deprecation\r\n else\r\n delete settings.scheduleScript; // eslint-disable-line deprecation/deprecation\r\n }\r\n }\r\n\r\n public loadScheduleScript(): RenderSchedule.ScriptReference | undefined {\r\n let script;\r\n let sourceId;\r\n if (this.settings.renderTimeline) {\r\n const timeline = this.iModel.elements.tryGetElement<RenderTimeline>(this.settings.renderTimeline);\r\n if (timeline) {\r\n script = RenderSchedule.Script.fromJSON(timeline.scriptProps);\r\n sourceId = timeline.id;\r\n }\r\n } else if (this.settings.scheduleScriptProps) { // eslint-disable-line deprecation/deprecation\r\n // eslint-disable-next-line deprecation/deprecation\r\n script = RenderSchedule.Script.fromJSON(this.settings.scheduleScriptProps);\r\n sourceId = this.id;\r\n }\r\n\r\n return undefined !== sourceId && undefined !== script ? new RenderSchedule.ScriptReference(sourceId, script) : undefined;\r\n }\r\n}\r\n\r\n/** A DisplayStyle for 2d views.\r\n * @public\r\n */\r\nexport class DisplayStyle2d extends DisplayStyle {\r\n /** @internal */\r\n public static override get className(): string { return \"DisplayStyle2d\"; }\r\n private readonly _settings: DisplayStyleSettings;\r\n\r\n public get settings(): DisplayStyleSettings { return this._settings; }\r\n\r\n /** @internal */\r\n public constructor(props: DisplayStyleProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this._settings = new DisplayStyleSettings(this.jsonProperties);\r\n }\r\n /** Create a DisplayStyle2d for use by a ViewDefinition.\r\n * @param iModelDb The iModel\r\n * @param definitionModelId The [[DefinitionModel]]\r\n * @param name The name/CodeValue of the DisplayStyle2d\r\n * @returns The newly constructed DisplayStyle2d element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n */\r\n public static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string): DisplayStyle2d {\r\n const displayStyleProps: DisplayStyleProps = {\r\n classFullName: this.classFullName,\r\n code: this.createCode(iModelDb, definitionModelId, name),\r\n model: definitionModelId,\r\n isPrivate: false,\r\n jsonProperties: {\r\n styles: {\r\n backgroundColor: 0,\r\n monochromeColor: ColorDef.white.toJSON(),\r\n viewflags: ViewFlags.defaults,\r\n },\r\n },\r\n };\r\n return new DisplayStyle2d(displayStyleProps, iModelDb);\r\n }\r\n /** Insert a DisplayStyle2d for use by a ViewDefinition.\r\n * @param iModelDb Insert into this iModel\r\n * @param definitionModelId Insert the new DisplayStyle2d into this DefinitionModel\r\n * @param name The name of the DisplayStyle2d\r\n * @returns The Id of the newly inserted DisplayStyle2d element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n */\r\n public static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string): Id64String {\r\n const displayStyle = this.create(iModelDb, definitionModelId, name);\r\n return iModelDb.elements.insertElement(displayStyle);\r\n }\r\n}\r\n\r\n/** Describes initial settings for a new [[DisplayStyle3d]].\r\n * Most properties are inherited from [DisplayStyle3dSettingsProps]($common), but for backwards compatibility reasons, this interface is slightly awkward:\r\n * - It adds a `viewFlags` member that differs only in case and type from [DisplayStyleSettingsProps.viewflags]($common); and\r\n * - It extends the type of [DisplayStyleSettingsProps.backgroundColor]($common) to include [ColorDef]($common).\r\n * These idiosyncrasies will be addressed in a future version of core-backend.\r\n * @see [[DisplayStyle3d.create]].\r\n * @public\r\n */\r\nexport interface DisplayStyleCreationOptions extends Omit<DisplayStyle3dSettingsProps, \"backgroundColor\" | \"scheduleScript\"> {\r\n /** If supplied, the [ViewFlags]($common) applied by the display style.\r\n * If undefined, [DisplayStyle3dSettingsProps.viewflags]($common) will be used if present (note the difference in case); otherwise, default-constructed [ViewFlags]($common) will be used.\r\n */\r\n viewFlags?: ViewFlags;\r\n backgroundColor?: ColorDef | number;\r\n}\r\n\r\n/** A DisplayStyle for 3d views.\r\n * See [how to create a DisplayStyle3d]$(docs/learning/backend/CreateElements.md#DisplayStyle3d).\r\n * @public\r\n */\r\nexport class DisplayStyle3d extends DisplayStyle implements DisplayStyle3dProps {\r\n /** @internal */\r\n public static override get className(): string { return \"DisplayStyle3d\"; }\r\n private readonly _settings: DisplayStyle3dSettings;\r\n\r\n public get settings(): DisplayStyle3dSettings { return this._settings; }\r\n\r\n /** @internal */\r\n public constructor(props: DisplayStyle3dProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this._settings = new DisplayStyle3dSettings(this.jsonProperties);\r\n }\r\n\r\n /** @alpha */\r\n protected override collectPredecessorIds(predecessorIds: Id64Set): void {\r\n super.collectPredecessorIds(predecessorIds);\r\n const skyBoxImageProps: SkyBoxImageProps | undefined = this.settings.environment?.sky?.image;\r\n if (skyBoxImageProps?.texture) {\r\n predecessorIds.add(Id64.fromJSON(skyBoxImageProps.texture));\r\n }\r\n if (skyBoxImageProps?.textures) {\r\n if (skyBoxImageProps.textures.back) { predecessorIds.add(Id64.fromJSON(skyBoxImageProps.textures.back)); }\r\n if (skyBoxImageProps.textures.bottom) { predecessorIds.add(Id64.fromJSON(skyBoxImageProps.textures.bottom)); }\r\n if (skyBoxImageProps.textures.front) { predecessorIds.add(Id64.fromJSON(skyBoxImageProps.textures.front)); }\r\n if (skyBoxImageProps.textures.left) { predecessorIds.add(Id64.fromJSON(skyBoxImageProps.textures.left)); }\r\n if (skyBoxImageProps.textures.right) { predecessorIds.add(Id64.fromJSON(skyBoxImageProps.textures.right)); }\r\n if (skyBoxImageProps.textures.top) { predecessorIds.add(Id64.fromJSON(skyBoxImageProps.textures.top)); }\r\n }\r\n if (this.settings.planProjectionSettings) {\r\n for (const planProjectionSetting of this.settings.planProjectionSettings) {\r\n predecessorIds.add(planProjectionSetting[0]);\r\n }\r\n }\r\n }\r\n /** @alpha */\r\n protected static override onCloned(context: IModelCloneContext, sourceElementProps: DisplayStyle3dProps, targetElementProps: DisplayStyle3dProps): void {\r\n super.onCloned(context, sourceElementProps, targetElementProps);\r\n if (context.isBetweenIModels) {\r\n const skyBoxImageProps: SkyBoxImageProps | undefined = targetElementProps?.jsonProperties?.styles?.environment?.sky?.image;\r\n if (skyBoxImageProps?.texture) {\r\n const textureId: Id64String = context.findTargetElementId(Id64.fromJSON(skyBoxImageProps.texture));\r\n skyBoxImageProps.texture = Id64.isValidId64(textureId) ? textureId : undefined;\r\n }\r\n if (skyBoxImageProps?.textures) {\r\n const backTextureId: Id64String = context.findTargetElementId(Id64.fromJSON(skyBoxImageProps.textures.back));\r\n skyBoxImageProps.textures.back = Id64.isValidId64(backTextureId) ? backTextureId : undefined;\r\n const bottomTextureId: Id64String = context.findTargetElementId(Id64.fromJSON(skyBoxImageProps.textures.bottom));\r\n skyBoxImageProps.textures.bottom = Id64.isValidId64(bottomTextureId) ? bottomTextureId : undefined;\r\n const frontTextureId: Id64String = context.findTargetElementId(Id64.fromJSON(skyBoxImageProps.textures.front));\r\n skyBoxImageProps.textures.front = Id64.isValidId64(frontTextureId) ? frontTextureId : undefined;\r\n const leftTextureId: Id64String = context.findTargetElementId(Id64.fromJSON(skyBoxImageProps.textures.left));\r\n skyBoxImageProps.textures.left = Id64.isValidId64(leftTextureId) ? leftTextureId : undefined;\r\n const rightTextureId: Id64String = context.findTargetElementId(Id64.fromJSON(skyBoxImageProps.textures.right));\r\n skyBoxImageProps.textures.right = Id64.isValidId64(rightTextureId) ? rightTextureId : undefined;\r\n const topTextureId: Id64String = context.findTargetElementId(Id64.fromJSON(skyBoxImageProps.textures.top));\r\n skyBoxImageProps.textures.top = Id64.isValidId64(topTextureId) ? topTextureId : undefined;\r\n }\r\n if (targetElementProps?.jsonProperties?.styles?.planProjections) {\r\n const remappedPlanProjections: { [modelId: string]: PlanProjectionSettingsProps } = {};\r\n for (const entry of Object.entries(targetElementProps.jsonProperties.styles.planProjections)) {\r\n const remappedModelId: Id64String = context.findTargetElementId(entry[0]);\r\n if (Id64.isValidId64(remappedModelId)) {\r\n remappedPlanProjections[remappedModelId] = entry[1];\r\n }\r\n }\r\n targetElementProps.jsonProperties.styles.planProjections = remappedPlanProjections;\r\n }\r\n }\r\n }\r\n\r\n /** Create a DisplayStyle3d for use by a ViewDefinition.\r\n * @param iModelDb The iModel\r\n * @param definitionModelId The [[DefinitionModel]]\r\n * @param name The name/CodeValue of the DisplayStyle3d\r\n * @returns The newly constructed DisplayStyle3d element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n */\r\n public static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): DisplayStyle3d {\r\n options = options ?? {};\r\n let viewflags = options.viewFlags?.toJSON();\r\n if (!viewflags)\r\n viewflags = options.viewflags ?? new ViewFlags().toJSON();\r\n\r\n const backgroundColor = options.backgroundColor instanceof ColorDef ? options.backgroundColor.toJSON() : options.backgroundColor;\r\n\r\n const settings: DisplayStyle3dSettingsProps = {\r\n ...options,\r\n viewflags,\r\n backgroundColor,\r\n };\r\n\r\n const displayStyleProps: DisplayStyle3dProps = {\r\n classFullName: this.classFullName,\r\n code: this.createCode(iModelDb, definitionModelId, name),\r\n model: definitionModelId,\r\n jsonProperties: { styles: settings },\r\n isPrivate: false,\r\n\r\n };\r\n\r\n return new DisplayStyle3d(displayStyleProps, iModelDb);\r\n }\r\n /**\r\n * Insert a DisplayStyle3d for use by a ViewDefinition.\r\n * @param iModelDb Insert into this iModel\r\n * @param definitionModelId Insert the new DisplayStyle3d into this [[DefinitionModel]]\r\n * @param name The name of the DisplayStyle3d\r\n * @returns The Id of the newly inserted DisplayStyle3d element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n */\r\n public static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): Id64String {\r\n const displayStyle = this.create(iModelDb, definitionModelId, name, options);\r\n return iModelDb.elements.insertElement(displayStyle);\r\n }\r\n}\r\n"]}