@shapediver/viewer.features.drawing-tools 3.1.0

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 (209) hide show
  1. package/LICENSE +73 -0
  2. package/README.md +161 -0
  3. package/dist/api/implementation/DrawingToolsApi.d.ts +31 -0
  4. package/dist/api/implementation/DrawingToolsApi.d.ts.map +1 -0
  5. package/dist/api/implementation/DrawingToolsApi.js +111 -0
  6. package/dist/api/implementation/DrawingToolsApi.js.map +1 -0
  7. package/dist/api/implementation/restrictions/AbstractRestrictionApi.d.ts +10 -0
  8. package/dist/api/implementation/restrictions/AbstractRestrictionApi.d.ts.map +1 -0
  9. package/dist/api/implementation/restrictions/AbstractRestrictionApi.js +38 -0
  10. package/dist/api/implementation/restrictions/AbstractRestrictionApi.js.map +1 -0
  11. package/dist/api/implementation/restrictions/AbstractSnapRestrictionApi.d.ts +11 -0
  12. package/dist/api/implementation/restrictions/AbstractSnapRestrictionApi.d.ts.map +1 -0
  13. package/dist/api/implementation/restrictions/AbstractSnapRestrictionApi.js +40 -0
  14. package/dist/api/implementation/restrictions/AbstractSnapRestrictionApi.js.map +1 -0
  15. package/dist/api/implementation/restrictions/axis/AxisRestrictionApi.d.ts +7 -0
  16. package/dist/api/implementation/restrictions/axis/AxisRestrictionApi.d.ts.map +1 -0
  17. package/dist/api/implementation/restrictions/axis/AxisRestrictionApi.js +24 -0
  18. package/dist/api/implementation/restrictions/axis/AxisRestrictionApi.js.map +1 -0
  19. package/dist/api/implementation/restrictions/geometry/GeometryRestrictionApi.d.ts +15 -0
  20. package/dist/api/implementation/restrictions/geometry/GeometryRestrictionApi.d.ts.map +1 -0
  21. package/dist/api/implementation/restrictions/geometry/GeometryRestrictionApi.js +54 -0
  22. package/dist/api/implementation/restrictions/geometry/GeometryRestrictionApi.js.map +1 -0
  23. package/dist/api/implementation/restrictions/plane/PlaneRestrictionApi.d.ts +18 -0
  24. package/dist/api/implementation/restrictions/plane/PlaneRestrictionApi.d.ts.map +1 -0
  25. package/dist/api/implementation/restrictions/plane/PlaneRestrictionApi.js +61 -0
  26. package/dist/api/implementation/restrictions/plane/PlaneRestrictionApi.js.map +1 -0
  27. package/dist/api/implementation/restrictions/plane/snap/AngularRestrictionApi.d.ts +10 -0
  28. package/dist/api/implementation/restrictions/plane/snap/AngularRestrictionApi.d.ts.map +1 -0
  29. package/dist/api/implementation/restrictions/plane/snap/AngularRestrictionApi.js +40 -0
  30. package/dist/api/implementation/restrictions/plane/snap/AngularRestrictionApi.js.map +1 -0
  31. package/dist/api/implementation/restrictions/plane/snap/GridRestrictionApi.d.ts +10 -0
  32. package/dist/api/implementation/restrictions/plane/snap/GridRestrictionApi.d.ts.map +1 -0
  33. package/dist/api/implementation/restrictions/plane/snap/GridRestrictionApi.js +40 -0
  34. package/dist/api/implementation/restrictions/plane/snap/GridRestrictionApi.js.map +1 -0
  35. package/dist/api/interfaces/IDrawingToolsApi.d.ts +89 -0
  36. package/dist/api/interfaces/IDrawingToolsApi.d.ts.map +1 -0
  37. package/dist/api/interfaces/IDrawingToolsApi.js +3 -0
  38. package/dist/api/interfaces/IDrawingToolsApi.js.map +1 -0
  39. package/dist/api/interfaces/IRestrictionApi.d.ts +11 -0
  40. package/dist/api/interfaces/IRestrictionApi.d.ts.map +1 -0
  41. package/dist/api/interfaces/IRestrictionApi.js +3 -0
  42. package/dist/api/interfaces/IRestrictionApi.js.map +1 -0
  43. package/dist/api/interfaces/ISnapRestrictionApi.d.ts +13 -0
  44. package/dist/api/interfaces/ISnapRestrictionApi.d.ts.map +1 -0
  45. package/dist/api/interfaces/ISnapRestrictionApi.js +3 -0
  46. package/dist/api/interfaces/ISnapRestrictionApi.js.map +1 -0
  47. package/dist/business/implementation/DrawingToolsManager.d.ts +95 -0
  48. package/dist/business/implementation/DrawingToolsManager.d.ts.map +1 -0
  49. package/dist/business/implementation/DrawingToolsManager.js +544 -0
  50. package/dist/business/implementation/DrawingToolsManager.js.map +1 -0
  51. package/dist/business/implementation/managers/HistoryManager.d.ts +19 -0
  52. package/dist/business/implementation/managers/HistoryManager.d.ts.map +1 -0
  53. package/dist/business/implementation/managers/HistoryManager.js +89 -0
  54. package/dist/business/implementation/managers/HistoryManager.js.map +1 -0
  55. package/dist/business/implementation/managers/TextVisualizationManager.d.ts +14 -0
  56. package/dist/business/implementation/managers/TextVisualizationManager.d.ts.map +1 -0
  57. package/dist/business/implementation/managers/TextVisualizationManager.js +228 -0
  58. package/dist/business/implementation/managers/TextVisualizationManager.js.map +1 -0
  59. package/dist/business/implementation/managers/geometry/GeometryManager.d.ts +23 -0
  60. package/dist/business/implementation/managers/geometry/GeometryManager.d.ts.map +1 -0
  61. package/dist/business/implementation/managers/geometry/GeometryManager.js +82 -0
  62. package/dist/business/implementation/managers/geometry/GeometryManager.js.map +1 -0
  63. package/dist/business/implementation/managers/geometry/GeometryMathManager.d.ts +73 -0
  64. package/dist/business/implementation/managers/geometry/GeometryMathManager.d.ts.map +1 -0
  65. package/dist/business/implementation/managers/geometry/GeometryMathManager.js +230 -0
  66. package/dist/business/implementation/managers/geometry/GeometryMathManager.js.map +1 -0
  67. package/dist/business/implementation/managers/geometry/GeometryState.d.ts +46 -0
  68. package/dist/business/implementation/managers/geometry/GeometryState.d.ts.map +1 -0
  69. package/dist/business/implementation/managers/geometry/GeometryState.js +323 -0
  70. package/dist/business/implementation/managers/geometry/GeometryState.js.map +1 -0
  71. package/dist/business/implementation/managers/geometry/helpers/GeometryManagerHelper.d.ts +16 -0
  72. package/dist/business/implementation/managers/geometry/helpers/GeometryManagerHelper.d.ts.map +1 -0
  73. package/dist/business/implementation/managers/geometry/helpers/GeometryManagerHelper.js +157 -0
  74. package/dist/business/implementation/managers/geometry/helpers/GeometryManagerHelper.js.map +1 -0
  75. package/dist/business/implementation/managers/interaction/EventManager.d.ts +26 -0
  76. package/dist/business/implementation/managers/interaction/EventManager.d.ts.map +1 -0
  77. package/dist/business/implementation/managers/interaction/EventManager.js +63 -0
  78. package/dist/business/implementation/managers/interaction/EventManager.js.map +1 -0
  79. package/dist/business/implementation/managers/interaction/InteractionManager.d.ts +39 -0
  80. package/dist/business/implementation/managers/interaction/InteractionManager.d.ts.map +1 -0
  81. package/dist/business/implementation/managers/interaction/InteractionManager.js +237 -0
  82. package/dist/business/implementation/managers/interaction/InteractionManager.js.map +1 -0
  83. package/dist/business/implementation/managers/interaction/RestrictionManager.d.ts +19 -0
  84. package/dist/business/implementation/managers/interaction/RestrictionManager.d.ts.map +1 -0
  85. package/dist/business/implementation/managers/interaction/RestrictionManager.js +117 -0
  86. package/dist/business/implementation/managers/interaction/RestrictionManager.js.map +1 -0
  87. package/dist/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.d.ts +10 -0
  88. package/dist/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.d.ts.map +1 -0
  89. package/dist/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.js +52 -0
  90. package/dist/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.js.map +1 -0
  91. package/dist/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.d.ts +14 -0
  92. package/dist/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.d.ts.map +1 -0
  93. package/dist/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.js +135 -0
  94. package/dist/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.js.map +1 -0
  95. package/dist/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.d.ts +16 -0
  96. package/dist/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.d.ts.map +1 -0
  97. package/dist/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.js +113 -0
  98. package/dist/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.js.map +1 -0
  99. package/dist/business/implementation/managers/interaction/helpers/InteractionManagerHelper.d.ts +58 -0
  100. package/dist/business/implementation/managers/interaction/helpers/InteractionManagerHelper.d.ts.map +1 -0
  101. package/dist/business/implementation/managers/interaction/helpers/InteractionManagerHelper.js +377 -0
  102. package/dist/business/implementation/managers/interaction/helpers/InteractionManagerHelper.js.map +1 -0
  103. package/dist/business/implementation/managers/interaction/restrictions/AbstractRestriction.d.ts +19 -0
  104. package/dist/business/implementation/managers/interaction/restrictions/AbstractRestriction.d.ts.map +1 -0
  105. package/dist/business/implementation/managers/interaction/restrictions/AbstractRestriction.js +105 -0
  106. package/dist/business/implementation/managers/interaction/restrictions/AbstractRestriction.js.map +1 -0
  107. package/dist/business/implementation/managers/interaction/restrictions/axis/AxisRestriction.d.ts +22 -0
  108. package/dist/business/implementation/managers/interaction/restrictions/axis/AxisRestriction.d.ts.map +1 -0
  109. package/dist/business/implementation/managers/interaction/restrictions/axis/AxisRestriction.js +96 -0
  110. package/dist/business/implementation/managers/interaction/restrictions/axis/AxisRestriction.js.map +1 -0
  111. package/dist/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.d.ts +39 -0
  112. package/dist/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.d.ts.map +1 -0
  113. package/dist/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.js +215 -0
  114. package/dist/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.js.map +1 -0
  115. package/dist/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.d.ts +58 -0
  116. package/dist/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.d.ts.map +1 -0
  117. package/dist/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.js +180 -0
  118. package/dist/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.js.map +1 -0
  119. package/dist/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.d.ts +38 -0
  120. package/dist/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.d.ts.map +1 -0
  121. package/dist/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.js +308 -0
  122. package/dist/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.js.map +1 -0
  123. package/dist/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.d.ts +37 -0
  124. package/dist/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.d.ts.map +1 -0
  125. package/dist/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.js +228 -0
  126. package/dist/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.js.map +1 -0
  127. package/dist/business/implementation/utils/numberCleaner.d.ts +2 -0
  128. package/dist/business/implementation/utils/numberCleaner.d.ts.map +1 -0
  129. package/dist/business/implementation/utils/numberCleaner.js +9 -0
  130. package/dist/business/implementation/utils/numberCleaner.js.map +1 -0
  131. package/dist/business/interfaces/IDrawingToolsManager.d.ts +270 -0
  132. package/dist/business/interfaces/IDrawingToolsManager.d.ts.map +1 -0
  133. package/dist/business/interfaces/IDrawingToolsManager.js +16 -0
  134. package/dist/business/interfaces/IDrawingToolsManager.js.map +1 -0
  135. package/dist/business/interfaces/IManager.d.ts +4 -0
  136. package/dist/business/interfaces/IManager.d.ts.map +1 -0
  137. package/dist/business/interfaces/IManager.js +3 -0
  138. package/dist/business/interfaces/IManager.js.map +1 -0
  139. package/dist/business/interfaces/IRestriction.d.ts +41 -0
  140. package/dist/business/interfaces/IRestriction.d.ts.map +1 -0
  141. package/dist/business/interfaces/IRestriction.js +13 -0
  142. package/dist/business/interfaces/IRestriction.js.map +1 -0
  143. package/dist/business/interfaces/IRestrictionBase.d.ts +19 -0
  144. package/dist/business/interfaces/IRestrictionBase.d.ts.map +1 -0
  145. package/dist/business/interfaces/IRestrictionBase.js +5 -0
  146. package/dist/business/interfaces/IRestrictionBase.js.map +1 -0
  147. package/dist/business/interfaces/ISnapRestriction.d.ts +50 -0
  148. package/dist/business/interfaces/ISnapRestriction.d.ts.map +1 -0
  149. package/dist/business/interfaces/ISnapRestriction.js +4 -0
  150. package/dist/business/interfaces/ISnapRestriction.js.map +1 -0
  151. package/dist/business/interfaces/events/EventResponseMapping.d.ts +19 -0
  152. package/dist/business/interfaces/events/EventResponseMapping.d.ts.map +1 -0
  153. package/dist/business/interfaces/events/EventResponseMapping.js +4 -0
  154. package/dist/business/interfaces/events/EventResponseMapping.js.map +1 -0
  155. package/dist/business/interfaces/events/IDrawingToolsEvent.d.ts +12 -0
  156. package/dist/business/interfaces/events/IDrawingToolsEvent.d.ts.map +1 -0
  157. package/dist/business/interfaces/events/IDrawingToolsEvent.js +3 -0
  158. package/dist/business/interfaces/events/IDrawingToolsEvent.js.map +1 -0
  159. package/dist/index.d.ts +32 -0
  160. package/dist/index.d.ts.map +1 -0
  161. package/dist/index.js +45 -0
  162. package/dist/index.js.map +1 -0
  163. package/dist/three/CSS2DRenderer.d.ts +32 -0
  164. package/dist/three/CSS2DRenderer.d.ts.map +1 -0
  165. package/dist/three/CSS2DRenderer.js +137 -0
  166. package/dist/three/CSS2DRenderer.js.map +1 -0
  167. package/package.json +55 -0
  168. package/src/api/implementation/DrawingToolsApi.ts +135 -0
  169. package/src/api/implementation/restrictions/AbstractRestrictionApi.ts +34 -0
  170. package/src/api/implementation/restrictions/AbstractSnapRestrictionApi.ts +36 -0
  171. package/src/api/implementation/restrictions/axis/AxisRestrictionApi.ts +19 -0
  172. package/src/api/implementation/restrictions/geometry/GeometryRestrictionApi.ts +56 -0
  173. package/src/api/implementation/restrictions/plane/PlaneRestrictionApi.ts +63 -0
  174. package/src/api/implementation/restrictions/plane/snap/AngularRestrictionApi.ts +35 -0
  175. package/src/api/implementation/restrictions/plane/snap/GridRestrictionApi.ts +35 -0
  176. package/src/api/interfaces/IDrawingToolsApi.ts +99 -0
  177. package/src/api/interfaces/IRestrictionApi.ts +15 -0
  178. package/src/api/interfaces/ISnapRestrictionApi.ts +18 -0
  179. package/src/business/implementation/DrawingToolsManager.ts +619 -0
  180. package/src/business/implementation/managers/HistoryManager.ts +101 -0
  181. package/src/business/implementation/managers/TextVisualizationManager.ts +245 -0
  182. package/src/business/implementation/managers/geometry/GeometryManager.ts +95 -0
  183. package/src/business/implementation/managers/geometry/GeometryMathManager.ts +273 -0
  184. package/src/business/implementation/managers/geometry/GeometryState.ts +436 -0
  185. package/src/business/implementation/managers/geometry/helpers/GeometryManagerHelper.ts +170 -0
  186. package/src/business/implementation/managers/interaction/EventManager.ts +80 -0
  187. package/src/business/implementation/managers/interaction/InteractionManager.ts +268 -0
  188. package/src/business/implementation/managers/interaction/RestrictionManager.ts +135 -0
  189. package/src/business/implementation/managers/interaction/handlers/DeletionInteractionHandler.ts +48 -0
  190. package/src/business/implementation/managers/interaction/handlers/InsertionInteractionHandler.ts +149 -0
  191. package/src/business/implementation/managers/interaction/handlers/MidPointInteractionHandler.ts +127 -0
  192. package/src/business/implementation/managers/interaction/helpers/InteractionManagerHelper.ts +411 -0
  193. package/src/business/implementation/managers/interaction/restrictions/AbstractRestriction.ts +99 -0
  194. package/src/business/implementation/managers/interaction/restrictions/axis/AxisRestriction.ts +107 -0
  195. package/src/business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction.ts +237 -0
  196. package/src/business/implementation/managers/interaction/restrictions/plane/PlaneRestriction.ts +257 -0
  197. package/src/business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction.ts +384 -0
  198. package/src/business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction.ts +262 -0
  199. package/src/business/implementation/utils/numberCleaner.ts +5 -0
  200. package/src/business/interfaces/IDrawingToolsManager.ts +313 -0
  201. package/src/business/interfaces/IManager.ts +7 -0
  202. package/src/business/interfaces/IRestriction.ts +64 -0
  203. package/src/business/interfaces/IRestrictionBase.ts +33 -0
  204. package/src/business/interfaces/ISnapRestriction.ts +70 -0
  205. package/src/business/interfaces/events/EventResponseMapping.ts +19 -0
  206. package/src/business/interfaces/events/IDrawingToolsEvent.ts +16 -0
  207. package/src/index.ts +72 -0
  208. package/src/three/CSS2DRenderer.ts +212 -0
  209. package/tsconfig.json +17 -0
@@ -0,0 +1,313 @@
1
+ import { AxisRestrictionProperties } from '../implementation/managers/interaction/restrictions/axis/AxisRestriction';
2
+ import { GeometryRestrictionProperties } from '../implementation/managers/interaction/restrictions/geometry/GeometryRestriction';
3
+ import { IManager } from './IManager';
4
+ import { IMapData, IMaterialBasicLineDataProperties, IMaterialMultiPointDataProperties } from '@shapediver/viewer.shared.types';
5
+ import { IRestriction, RestrictionProperties } from './IRestriction';
6
+ import { PlaneRestrictionProperties } from '../implementation/managers/interaction/restrictions/plane/PlaneRestriction';
7
+ import { vec3 } from 'gl-matrix';
8
+
9
+ // #region Type aliases (5)
10
+
11
+ /**
12
+ * The callbacks of the drawing tool.
13
+ *
14
+ * Here you can define the callbacks that are used when interacting with the drawing tool.
15
+ *
16
+ * @typedef Callbacks
17
+ */
18
+ export type Callbacks = {
19
+ /**
20
+ * The callback that is called when the drawing tool is cancelled.
21
+ */
22
+ onCancel(): void;
23
+ /**
24
+ * The callback that is called when the drawing tool is updated.
25
+ *
26
+ * @param pointsData The points data of the drawing tool.
27
+ */
28
+ onUpdate(pointsData: PointsData): void;
29
+ };
30
+ export type DefaultTextures = { [key: string]: Promise<IMapData> | IMapData }
31
+
32
+ /**
33
+ * The data of the points.
34
+ * The points are defined as an array of arrays, where each array contains the x, y and z coordinates of the point.
35
+ *
36
+ * @example [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 0]]
37
+ * @typedef PointsData
38
+ */
39
+ export type PointsData = number[][];
40
+ /**
41
+ * The initial settings of the drawing tool.
42
+ * Here you can define the initial settings of the drawing tool.
43
+ *
44
+ * @typedef Settings
45
+ *
46
+ */
47
+ export type Settings = {
48
+ /**
49
+ * The geometry settings of the drawing tool.
50
+ *
51
+ * Here you can define the points, the mode and specific details of the geometry.
52
+ */
53
+ geometry: {
54
+ /**
55
+ * The points that are used when starting the drawing tool.
56
+ * The points are defined as an array of arrays, where each array contains the x, y and z coordinates of the point.
57
+ *
58
+ * If the mode is set to 'lines', the points are connected in the order they are defined.
59
+ * If the mode is set to 'points', the points are not connected.
60
+ *
61
+ * @default []
62
+ * @example [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 0]]
63
+ */
64
+ points: PointsData;
65
+
66
+ /**
67
+ * The mode of the geometry.
68
+ *
69
+ * If the mode is set to 'lines', the points are connected in the order they are defined.
70
+ * If the mode is set to 'points', the points are not connected.
71
+ *
72
+ * @default 'lines'
73
+ */
74
+ mode: 'points' | 'lines';
75
+
76
+ /**
77
+ * The minimum amount of points, if undefined, the geometry is not restricted.
78
+ * This value is checked whenever the user tries to update or finish the drawing tool.
79
+ *
80
+ * @default undefined
81
+ */
82
+ minPoints?: number;
83
+
84
+ /**
85
+ * The maximum amount of points, if undefined, the geometry is not restricted.
86
+ * This value is checked whenever the user tries to update or finish the drawing tool.
87
+ *
88
+ * @default undefined
89
+ */
90
+ maxPoints?: number;
91
+
92
+ /**
93
+ * If the number of points is strictly checked during the drawing process.
94
+ * If this setting is set to true, once the minimum or maximum amount of points is reached, the user cannot add or remove points that would violate the restriction.
95
+ * If this setting is set to false, the user can add or remove points even if the minimum or maximum amount of points is exceeded temporarily.
96
+ * Once the user tries to update or finish the drawing tool, the amount of points is checked in either case.
97
+ *
98
+ * @default true
99
+ */
100
+ strictMinMaxPoints?: boolean;
101
+
102
+ /**
103
+ * If the mode is set to 'lines', if it is a closed line or not.
104
+ * If the mode is set to 'points', this setting is ignored.
105
+ *
106
+ * A line can be closed by connecting the last point with the first point.
107
+ *
108
+ * @default true
109
+ */
110
+ close: boolean;
111
+
112
+ /**
113
+ * If the mode is set to 'lines', if the line is automatically closed.
114
+ * If the mode is set to 'points', this setting is ignored.
115
+ *
116
+ * The first and last point are always connected if the line is automatically closed.
117
+ *
118
+ * @default true
119
+ */
120
+ autoClose: boolean;
121
+
122
+ },
123
+
124
+ /**
125
+ * The restrictions of the drawing tool.
126
+ *
127
+ * Here you can define the restrictions that are used when interacting with the drawing tool.
128
+ * At least one restriction is required, the plane and axis restrictions are added by default if no restrictions are defined.
129
+ */
130
+ restrictions: { [key: string]: RestrictionProperties | PlaneRestrictionProperties | GeometryRestrictionProperties | AxisRestrictionProperties };
131
+
132
+ /**
133
+ * The visualization settings of the drawing tool.
134
+ *
135
+ * Here you can define the visualization of the drawing tool.
136
+ */
137
+ visualization: {
138
+ /**
139
+ * The multiplication factor of the point size when interactions are performed.
140
+ * If the factor is set to 2, the point size is doubled when interacting.
141
+ *
142
+ * @default 2
143
+ */
144
+ distanceMultiplicationFactor: number,
145
+
146
+ /**
147
+ * If the point labels are shown.
148
+ * The point labels display the position of the points.
149
+ *
150
+ * @default false
151
+ */
152
+ pointLabels: boolean,
153
+
154
+ /**
155
+ * If the distance labels are shown.
156
+ * The distance labels display the distance between the points.
157
+ *
158
+ * @default true
159
+ */
160
+ distanceLabels: boolean,
161
+
162
+ /**
163
+ * The material properties of the points.
164
+ */
165
+ points: IMaterialMultiPointDataProperties,
166
+
167
+ /**
168
+ * The material properties of the lines.
169
+ */
170
+ lines: IMaterialBasicLineDataProperties
171
+
172
+ };
173
+
174
+ /**
175
+ * The control settings of the drawing tool.
176
+ *
177
+ * Here you can define which keys are used for the different actions of the drawing tool.
178
+ */
179
+ controls: {
180
+ /**
181
+ * The key that is used to insert a point.
182
+ *
183
+ * @default ['Insert','+']
184
+ */
185
+ insert: string | string[],
186
+
187
+ /**
188
+ * The key that is used to delete a point.
189
+ *
190
+ * @default ['Delete','-']
191
+ */
192
+ delete: string | string[],
193
+
194
+ /**
195
+ * The key that is used to confirm actions.
196
+ *
197
+ * @default 'Enter'
198
+ */
199
+ confirm: string | string[],
200
+
201
+ /**
202
+ * The key that is used to cancel drawing.
203
+ *
204
+ * @default 'Escape'
205
+ */
206
+ cancel: string | string[],
207
+
208
+ /**
209
+ * The keys that are used to undo the last action.
210
+ *
211
+ * @default 'Control+Z'
212
+ */
213
+ undo: string | string[],
214
+
215
+ /**
216
+ * The keys that are used to redo the last action.
217
+ *
218
+ * @default 'Control+Y'
219
+ */
220
+ redo: string | string[]
221
+ };
222
+
223
+ /**
224
+ * The general settings of the drawing tool.
225
+ *
226
+ * Here you can define general settings of the drawing tool.
227
+ */
228
+ general: {
229
+ /**
230
+ * If the drawing tool is started automatically when no points are defined.
231
+ *
232
+ * @default true
233
+ */
234
+ autoStart: boolean;
235
+
236
+ /**
237
+ * If the drawing tool is updated automatically when the drawing is changed.
238
+ *
239
+ * @default false
240
+ */
241
+ autoUpdate: boolean;
242
+ /**
243
+ * If the drawing tool is closed when the drawing is updated.
244
+ *
245
+ * @default false
246
+ */
247
+ closeOnUpdate: boolean;
248
+
249
+ /**
250
+ * The unit that will be displayed in the distance and point labels.
251
+ *
252
+ * @default ''
253
+ */
254
+ displayUnit: string;
255
+ }
256
+
257
+ };
258
+ export type SettingsOptional = {
259
+ geometry?: Partial<Settings['geometry']>;
260
+ restrictions?: Partial<Settings['restrictions']>;
261
+ visualization?: Partial<Settings['visualization']>;
262
+ controls?: Partial<Settings['controls']>;
263
+ general?: Partial<Settings['general']>;
264
+ };
265
+
266
+ // #endregion Type aliases (5)
267
+
268
+ // #region Interfaces (1)
269
+
270
+ export interface IDrawingToolsManager extends IManager {
271
+ // #region Properties (4)
272
+
273
+ readonly closed: boolean;
274
+ readonly restrictions: { [key: string]: IRestriction };
275
+
276
+ showDistanceLabels: boolean;
277
+ showPointLabels: boolean;
278
+
279
+ // #endregion Properties (4)
280
+
281
+ // #region Public Methods (13)
282
+
283
+ addPoint(index: number, position?: vec3, temporary?: boolean): void;
284
+ addRestriction(properties: RestrictionProperties, token?: string): string | undefined;
285
+ canRedo(): boolean;
286
+ canUndo(): boolean;
287
+ cancel(): void;
288
+ getPointsData(): PointsData;
289
+ movePoint(index: number, position: vec3, temporary?: boolean): void;
290
+ redo(): void;
291
+ removePoint(index: number, temporary?: boolean): void;
292
+ removePoints(indices: number[]): void;
293
+ removeRestriction(token: string): void;
294
+ undo(): void;
295
+ update(): PointsData | undefined;
296
+
297
+ // #endregion Public Methods (13)
298
+ }
299
+
300
+ // #endregion Interfaces (1)
301
+
302
+ // #region Enums (1)
303
+
304
+ export enum MATERIAL_INDEX {
305
+ DEFAULT = 0,
306
+ HOVERED = 1,
307
+ SELECTED = 2,
308
+ SELECTED_HOVERED = 3,
309
+ INSERTION = 4,
310
+ INSERTION_HOVERED = 5
311
+ }
312
+
313
+ // #endregion Enums (1)
@@ -0,0 +1,7 @@
1
+ export interface IManager {
2
+ // #region Public Methods (1)
3
+
4
+ close(): void;
5
+
6
+ // #endregion Public Methods (1)
7
+ }
@@ -0,0 +1,64 @@
1
+ import { IRay } from '@shapediver/viewer.features.interaction';
2
+ import { IRestrictionBase } from './IRestrictionBase';
3
+ import { ISnapRestriction } from './ISnapRestriction';
4
+ import { vec3 } from 'gl-matrix';
5
+
6
+ // #region Type aliases (2)
7
+
8
+ export type RestrictionMetaData = {
9
+ index?: number;
10
+ referencePoint?: vec3;
11
+ }
12
+
13
+ export type RestrictionProperties = {
14
+ /**
15
+ * Type of the restriction
16
+ */
17
+ type: RESTRICTION_TYPE;
18
+ };
19
+
20
+ // #endregion Type aliases (2)
21
+
22
+ // #region Interfaces (1)
23
+
24
+ export interface IRestriction extends IRestrictionBase {
25
+ // #region Properties (2)
26
+
27
+ /**
28
+ * Priority of the restriction
29
+ */
30
+ readonly priority: number;
31
+
32
+ /**
33
+ * The snap restrictions of the restriction.
34
+ */
35
+ snapRestrictions: { [key: string]: ISnapRestriction; }
36
+
37
+ // #endregion Properties (2)
38
+
39
+ // #region Public Methods (1)
40
+
41
+ /**
42
+ * Ray trace the restriction.
43
+ * If the ray does not intersect the restriction, the method returns undefined.
44
+ *
45
+ * @param ray The ray to trace.
46
+ * @param metaData The meta data of the ray.
47
+ * @returns The intersection point of the ray with the restriction.
48
+ */
49
+ rayTrace(ray: IRay, metaData?: RestrictionMetaData): vec3 | undefined;
50
+
51
+ // #endregion Public Methods (1)
52
+ }
53
+
54
+ // #endregion Interfaces (1)
55
+
56
+ // #region Enums (1)
57
+
58
+ export enum RESTRICTION_TYPE {
59
+ AXIS = 'axis',
60
+ PLANE = 'plane',
61
+ GEOMETRY = 'geometry',
62
+ }
63
+
64
+ // #endregion Enums (1)
@@ -0,0 +1,33 @@
1
+ // #region Interfaces (1)
2
+
3
+ export interface IRestrictionBase {
4
+ // #region Properties (3)
5
+
6
+ /**
7
+ * The unique identifier of the restriction.
8
+ */
9
+ readonly id: string;
10
+
11
+ /**
12
+ * Whether the restriction is enabled or not.
13
+ */
14
+ enabled: boolean;
15
+
16
+ /**
17
+ * Whether the visualization of the restriction is shown or not (if there is one).
18
+ */
19
+ showVisualization: boolean;
20
+
21
+ // #endregion Properties (3)
22
+
23
+ // #region Public Methods (1)
24
+
25
+ /**
26
+ * Remove the visualization of the restriction.
27
+ */
28
+ removeVisualization(): void;
29
+
30
+ // #endregion Public Methods (1)
31
+ }
32
+
33
+ // #endregion Interfaces (1)
@@ -0,0 +1,70 @@
1
+ import { IRestrictionBase } from './IRestrictionBase';
2
+ import { RestrictionMetaData } from './IRestriction';
3
+ import { vec3 } from 'gl-matrix';
4
+
5
+ // #region Type aliases (1)
6
+
7
+ export type SnapRestrictionProperties = {
8
+ /**
9
+ * If the restriction should be enabled by default.
10
+ */
11
+ enabled?: boolean;
12
+ /**
13
+ * If the enabling or disabling of the restriction is allowed to the end user.
14
+ * If it is not editable, the default value for enabling or disabling the restriction is used.
15
+ */
16
+ enabledEditable?: boolean;
17
+ /**
18
+ * Priority of the restriction.
19
+ * The higher the priority, the sooner the restriction is applied.
20
+ * If the priority is the same, the result that is closer to the original point is chosen.
21
+ */
22
+ priority?: number;
23
+ /**
24
+ * The activation key of the restriction.
25
+ * If the key is not provided, no key is assigned.
26
+ * If the key is provided, the restriction is only active when the key is pressed.
27
+ */
28
+ activationKey?: string;
29
+ };
30
+
31
+ // #endregion Type aliases (1)
32
+
33
+ // #region Interfaces (1)
34
+
35
+ export interface ISnapRestriction extends IRestrictionBase {
36
+ // #region Properties (2)
37
+
38
+ /**
39
+ * If the enabling or disabling of the restriction is allowed to the end user.
40
+ * If it is not editable, the default value for enabling or disabling the restriction is used.
41
+ */
42
+ enabledEditable: boolean;
43
+
44
+ /**
45
+ * If the restriction is actively being used at the moment.
46
+ */
47
+ active: boolean;
48
+
49
+ /**
50
+ * The priority of the restriction.
51
+ */
52
+ priority: number;
53
+
54
+ // #endregion Properties (2)
55
+
56
+ // #region Public Methods (1)
57
+
58
+ /**
59
+ * Restrict the position of a point.
60
+ *
61
+ * @param point The position of the point.
62
+ * @param metaData The meta data of the point.
63
+ * @returns The restricted position of the point.
64
+ */
65
+ snap(point: vec3, metaData?: RestrictionMetaData): vec3 | undefined;
66
+
67
+ // #endregion Public Methods (1)
68
+ }
69
+
70
+ // #endregion Interfaces (1)
@@ -0,0 +1,19 @@
1
+ import { EVENTTYPE_DRAWING_TOOLS } from '@shapediver/viewer';
2
+ import { IDrawingToolsEvent } from './IDrawingToolsEvent';
3
+
4
+ export type DrawingToolsEventResponseMapping = {
5
+ [EVENTTYPE_DRAWING_TOOLS.CANCEL]: IDrawingToolsEvent,
6
+ [EVENTTYPE_DRAWING_TOOLS.FINISH]: IDrawingToolsEvent,
7
+ [EVENTTYPE_DRAWING_TOOLS.ADDED]: IDrawingToolsEvent,
8
+ [EVENTTYPE_DRAWING_TOOLS.REMOVED]: IDrawingToolsEvent,
9
+ [EVENTTYPE_DRAWING_TOOLS.MOVED]: IDrawingToolsEvent,
10
+ [EVENTTYPE_DRAWING_TOOLS.GEOMETRY_CHANGED]: IDrawingToolsEvent,
11
+ [EVENTTYPE_DRAWING_TOOLS.SELECTED]: IDrawingToolsEvent,
12
+ [EVENTTYPE_DRAWING_TOOLS.DESELECTED]: IDrawingToolsEvent,
13
+ [EVENTTYPE_DRAWING_TOOLS.DRAG_START]: IDrawingToolsEvent,
14
+ [EVENTTYPE_DRAWING_TOOLS.DRAG_MOVE]: IDrawingToolsEvent,
15
+ [EVENTTYPE_DRAWING_TOOLS.DRAG_END]: IDrawingToolsEvent,
16
+ [EVENTTYPE_DRAWING_TOOLS.MINIMUM_POINTS]: IDrawingToolsEvent,
17
+ [EVENTTYPE_DRAWING_TOOLS.MAXIMUM_POINTS]: IDrawingToolsEvent,
18
+ [EVENTTYPE_DRAWING_TOOLS.UNCLOSED_LOOP]: IDrawingToolsEvent,
19
+ }
@@ -0,0 +1,16 @@
1
+ import { IViewportEvent } from '@shapediver/viewer';
2
+ import { PointsData } from '../IDrawingToolsManager';
3
+
4
+ export interface IDrawingToolsEvent extends IViewportEvent {
5
+ // #region Properties (7)
6
+
7
+ drawingToolId: string;
8
+ fromHistory?: boolean;
9
+ index?: number;
10
+ message?: string;
11
+ points?: PointsData;
12
+ recordHistory?: boolean;
13
+ temporary?: boolean;
14
+
15
+ // #endregion Properties (7)
16
+ }
package/src/index.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { AngularRestrictionApi } from './api/implementation/restrictions/plane/snap/AngularRestrictionApi';
2
+ import { AngularRestrictionProperties } from './business/implementation/managers/interaction/restrictions/plane/snap/AngularRestriction';
3
+ import { AxisRestrictionApi } from './api/implementation/restrictions/axis/AxisRestrictionApi';
4
+ import { AxisRestrictionProperties } from './business/implementation/managers/interaction/restrictions/axis/AxisRestriction';
5
+ import { Callbacks, PointsData, SettingsOptional } from './business/interfaces/IDrawingToolsManager';
6
+ import { DrawingToolsApi } from './api/implementation/DrawingToolsApi';
7
+ import { DrawingToolsEventResponseMapping } from './business/interfaces/events/EventResponseMapping';
8
+ import { GeometryRestrictionApi } from './api/implementation/restrictions/geometry/GeometryRestrictionApi';
9
+ import { GeometryRestrictionProperties } from './business/implementation/managers/interaction/restrictions/geometry/GeometryRestriction';
10
+ import { GridRestrictionApi } from './api/implementation/restrictions/plane/snap/GridRestrictionApi';
11
+ import { GridRestrictionProperties } from './business/implementation/managers/interaction/restrictions/plane/snap/GridRestriction';
12
+ import { IDrawingToolsApi } from './api/interfaces/IDrawingToolsApi';
13
+ import { IDrawingToolsEvent } from './business/interfaces/events/IDrawingToolsEvent';
14
+ import {
15
+ IMapData,
16
+ IViewportApi,
17
+ MaterialEngine,
18
+ ShapeDiverViewerDrawingToolsError
19
+ } from '@shapediver/viewer';
20
+ import {
21
+ IRestriction,
22
+ RESTRICTION_TYPE,
23
+ RestrictionMetaData,
24
+ RestrictionProperties
25
+ } from './business/interfaces/IRestriction';
26
+ import { IRestrictionApi } from './api/interfaces/IRestrictionApi';
27
+ import { IRestrictionBase } from './business/interfaces/IRestrictionBase';
28
+ import { ISnapRestriction, SnapRestrictionProperties } from './business/interfaces/ISnapRestriction';
29
+ import { PlaneRestrictionApi } from './api/implementation/restrictions/plane/PlaneRestrictionApi';
30
+ import { PlaneRestrictionProperties } from './business/implementation/managers/interaction/restrictions/plane/PlaneRestriction';
31
+ import { SystemInfo } from '@shapediver/viewer.shared.services';
32
+
33
+ export {
34
+ SettingsOptional as Settings, Callbacks,
35
+ DrawingToolsEventResponseMapping, IDrawingToolsEvent,
36
+ IDrawingToolsApi, DrawingToolsApi, PointsData,
37
+ PlaneRestrictionProperties, GridRestrictionProperties, AngularRestrictionProperties,
38
+ GeometryRestrictionProperties,
39
+ AxisRestrictionProperties,
40
+ IRestrictionApi, PlaneRestrictionApi, GridRestrictionApi, AngularRestrictionApi, GeometryRestrictionApi, AxisRestrictionApi,
41
+ IRestrictionBase, RestrictionProperties, IRestriction, RestrictionMetaData, RESTRICTION_TYPE, SnapRestrictionProperties, ISnapRestriction,
42
+ };
43
+
44
+ const defaultTextures: { [key: string]: Promise<IMapData> | IMapData } = {};
45
+
46
+ defaultTextures['variation_0'] = MaterialEngine.instance.loadMap('https://viewer.shapediver.com/v3/graphics/point_soft.png')
47
+ .then((mapData: IMapData | null) => {
48
+ defaultTextures['variation_0'] = mapData!;
49
+ return mapData!;
50
+ });
51
+
52
+ let drawingTools: IDrawingToolsApi | undefined;
53
+
54
+ /**
55
+ * Create a new instance of DrawingTools.
56
+ *
57
+ * @param viewport The viewport to which the DrawingTools should be attached.
58
+ * @param callback The callback function that is called when the drawing is finished.
59
+ * @param properties The customization properties for the DrawingTools.
60
+ * @returns The DrawingTools instance.
61
+ * @throws An error if there is already an active instance of DrawingTools.
62
+ */
63
+ export const createDrawingTools = (viewport: IViewportApi, callbacks: Callbacks, settings: SettingsOptional): IDrawingToolsApi => {
64
+ if (SystemInfo.instance.isMobile)
65
+ throw new ShapeDiverViewerDrawingToolsError('The DrawingTools are not supported on mobile devices.');
66
+
67
+ if (drawingTools && drawingTools.closed === false)
68
+ throw new ShapeDiverViewerDrawingToolsError('There can only be one instance of DrawingTools active at a time. Please close the current instance before creating a new one.');
69
+
70
+ drawingTools = new DrawingToolsApi(viewport, callbacks, settings, defaultTextures);
71
+ return drawingTools;
72
+ };