@2112-lab/central-plant 0.1.39 → 0.1.41

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 (45) hide show
  1. package/dist/bundle/index.js +7991 -7054
  2. package/dist/cjs/src/core/centralPlant.js +48 -3
  3. package/dist/cjs/src/core/centralPlantInternals.js +75 -566
  4. package/dist/cjs/src/core/sceneViewer.js +38 -13
  5. package/dist/cjs/src/index.js +6 -4
  6. package/dist/cjs/src/managers/components/pathfindingManager.js +75 -60
  7. package/dist/cjs/src/managers/components/transformOperationsManager.js +929 -0
  8. package/dist/cjs/src/managers/controls/keyboardControlsManager.js +57 -1
  9. package/dist/cjs/src/managers/controls/transformControls.js +11 -3
  10. package/dist/cjs/src/managers/controls/transformControlsManager.js +563 -263
  11. package/dist/cjs/src/managers/pathfinding/ConnectorManager.js +385 -0
  12. package/dist/cjs/src/managers/pathfinding/PathIntersectionDetector.js +387 -0
  13. package/dist/cjs/src/managers/pathfinding/PathRenderingManager.js +401 -0
  14. package/dist/cjs/src/managers/pathfinding/pathfindingManager.js +378 -0
  15. package/dist/cjs/src/managers/pathfinding/sceneDataManager.js +256 -0
  16. package/dist/cjs/src/managers/scene/animationManager.js +145 -0
  17. package/dist/cjs/src/managers/scene/sceneExportManager.js +14 -13
  18. package/dist/cjs/src/managers/scene/sceneOperationsManager.js +516 -21
  19. package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +1 -8
  20. package/dist/cjs/src/managers/system/operationHistoryManager.js +414 -0
  21. package/dist/cjs/src/managers/system/settingsManager.js +2 -1
  22. package/dist/cjs/src/utils/objectTypes.js +5 -7
  23. package/dist/esm/src/core/centralPlant.js +48 -3
  24. package/dist/esm/src/core/centralPlantInternals.js +76 -567
  25. package/dist/esm/src/core/sceneViewer.js +38 -13
  26. package/dist/esm/src/index.js +4 -3
  27. package/dist/esm/src/managers/components/pathfindingManager.js +75 -60
  28. package/dist/esm/src/managers/components/transformOperationsManager.js +904 -0
  29. package/dist/esm/src/managers/controls/keyboardControlsManager.js +57 -1
  30. package/dist/esm/src/managers/controls/transformControls.js +11 -3
  31. package/dist/esm/src/managers/controls/transformControlsManager.js +564 -264
  32. package/dist/esm/src/managers/pathfinding/ConnectorManager.js +361 -0
  33. package/dist/esm/src/managers/pathfinding/PathIntersectionDetector.js +363 -0
  34. package/dist/esm/src/managers/pathfinding/PathRenderingManager.js +377 -0
  35. package/dist/esm/src/managers/pathfinding/pathfindingManager.js +374 -0
  36. package/dist/esm/src/managers/pathfinding/sceneDataManager.js +232 -0
  37. package/dist/esm/src/managers/scene/animationManager.js +141 -0
  38. package/dist/esm/src/managers/scene/sceneExportManager.js +14 -13
  39. package/dist/esm/src/managers/scene/sceneOperationsManager.js +516 -21
  40. package/dist/esm/src/managers/scene/sceneTooltipsManager.js +1 -8
  41. package/dist/esm/src/managers/system/operationHistoryManager.js +409 -0
  42. package/dist/esm/src/managers/system/settingsManager.js +2 -1
  43. package/dist/esm/src/utils/objectTypes.js +5 -7
  44. package/dist/index.d.ts +2 -2
  45. package/package.json +1 -1
@@ -0,0 +1,409 @@
1
+ import { inherits as _inherits, createClass as _createClass, superPropGet as _superPropGet, classCallCheck as _classCallCheck, callSuper as _callSuper } from '../../../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { BaseDisposable } from '../../core/baseDisposable.js';
3
+
4
+ /**
5
+ * OperationHistoryManager handles operation history with sessionStorage persistence
6
+ */
7
+ var OperationHistoryManager = /*#__PURE__*/function (_BaseDisposable) {
8
+ function OperationHistoryManager(sceneViewer) {
9
+ var _this;
10
+ _classCallCheck(this, OperationHistoryManager);
11
+ _this = _callSuper(this, OperationHistoryManager);
12
+ _this.sceneViewer = sceneViewer;
13
+ _this.storageKey = 'centralPlant_history';
14
+ _this.maxHistorySize = 10; // Limit history to prevent storage overflow
15
+
16
+ // Register this manager with the sceneViewer (using 'operationHistory' for consistency)
17
+ if (_this.sceneViewer && _this.sceneViewer.managers) {
18
+ _this.sceneViewer.managers.operationHistory = _this;
19
+ }
20
+ console.log('📜 OperationHistoryManager initialized');
21
+ return _this;
22
+ }
23
+
24
+ /**
25
+ * Check if sessionStorage is available
26
+ * @returns {boolean} True if sessionStorage is available
27
+ * @private
28
+ */
29
+ _inherits(OperationHistoryManager, _BaseDisposable);
30
+ return _createClass(OperationHistoryManager, [{
31
+ key: "_isSessionStorageAvailable",
32
+ value: function _isSessionStorageAvailable() {
33
+ try {
34
+ return typeof sessionStorage !== 'undefined';
35
+ } catch (error) {
36
+ return false;
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Add an operation to the history
42
+ * @param {string} operationName - Name of operation ('translateComponent', 'translateSegment', 'translateGateway', etc.)
43
+ * @param {Object} params - Operation parameters (segmentId/componentId/gatewayId, axis, value, etc.)
44
+ * @returns {boolean} True if operation was stored successfully, false otherwise
45
+ */
46
+ }, {
47
+ key: "addToOperationHistory",
48
+ value: function addToOperationHistory(operationName, params) {
49
+ try {
50
+ if (!this._isSessionStorageAvailable()) {
51
+ console.warn('⚠️ sessionStorage not available, cannot store operation history');
52
+ return false;
53
+ }
54
+
55
+ // Get existing history
56
+ var history = [];
57
+ var stored = sessionStorage.getItem(this.storageKey);
58
+ if (stored) {
59
+ history = JSON.parse(stored);
60
+ }
61
+
62
+ // Create new operation entry
63
+ var operationEntry = {
64
+ operationName: operationName,
65
+ timestamp: new Date().toISOString(),
66
+ params: params
67
+ };
68
+
69
+ // Add to history (newest first)
70
+ history.unshift(operationEntry);
71
+
72
+ // Trim history if too large
73
+ if (history.length > this.maxHistorySize) {
74
+ history = history.slice(0, this.maxHistorySize);
75
+ }
76
+
77
+ // Save back to sessionStorage
78
+ sessionStorage.setItem(this.storageKey, JSON.stringify(history));
79
+ console.log("\uD83D\uDCBE Operation stored to sessionStorage:", operationEntry);
80
+ return true;
81
+ } catch (error) {
82
+ console.error('❌ Error storing operation to sessionStorage:', error);
83
+ return false;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Get operation history from sessionStorage
89
+ * @param {Object} options - Filter options
90
+ * @param {string} [options.operationName] - Filter by operation name
91
+ * @param {number} [options.limit] - Limit number of results
92
+ * @returns {Array} Array of operation entries
93
+ */
94
+ }, {
95
+ key: "getOperationHistory",
96
+ value: function getOperationHistory() {
97
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
98
+ try {
99
+ if (!this._isSessionStorageAvailable()) {
100
+ console.warn('⚠️ sessionStorage not available');
101
+ return [];
102
+ }
103
+ var stored = sessionStorage.getItem(this.storageKey);
104
+ if (!stored) {
105
+ return [];
106
+ }
107
+ var history = JSON.parse(stored);
108
+
109
+ // Filter by operation name if specified
110
+ if (options.operationName) {
111
+ history = history.filter(function (entry) {
112
+ return entry.operationName === options.operationName;
113
+ });
114
+ }
115
+
116
+ // Limit results if specified
117
+ if (options.limit && options.limit > 0) {
118
+ history = history.slice(0, options.limit);
119
+ }
120
+ return history;
121
+ } catch (error) {
122
+ console.error('❌ Error reading operation history:', error);
123
+ return [];
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Clear operation history from sessionStorage
129
+ * @returns {boolean} True if history was cleared successfully, false otherwise
130
+ */
131
+ }, {
132
+ key: "clearOperationHistory",
133
+ value: function clearOperationHistory() {
134
+ try {
135
+ if (!this._isSessionStorageAvailable()) {
136
+ console.warn('⚠️ sessionStorage not available');
137
+ return false;
138
+ }
139
+ sessionStorage.removeItem(this.storageKey);
140
+ console.log('🗑️ Operation history cleared from sessionStorage');
141
+ return true;
142
+ } catch (error) {
143
+ console.error('❌ Error clearing operation history:', error);
144
+ return false;
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Get the most recent operation
150
+ * @returns {Object|null} The most recent operation entry or null if none exists
151
+ */
152
+ }, {
153
+ key: "getLastOperation",
154
+ value: function getLastOperation() {
155
+ var history = this.getOperationHistory({
156
+ limit: 1
157
+ });
158
+ return history.length > 0 ? history[0] : null;
159
+ }
160
+
161
+ /**
162
+ * Undo the most recent operation and remove it from history
163
+ * @returns {boolean} True if undo was successful, false otherwise
164
+ */
165
+ }, {
166
+ key: "undoLastOperation",
167
+ value: function undoLastOperation() {
168
+ try {
169
+ // Get the last operation
170
+ var lastOp = this.getLastOperation();
171
+ if (!lastOp) {
172
+ console.warn('⚠️ No operation to undo');
173
+ return false;
174
+ }
175
+ console.log('⏪ Undoing last operation:', lastOp);
176
+
177
+ // Execute the reverse operation based on operation type
178
+ var undoSuccess = false;
179
+ switch (lastOp.operationName) {
180
+ case 'translateSegment':
181
+ undoSuccess = this._undoTranslateSegment(lastOp.params);
182
+ break;
183
+ case 'translateComponent':
184
+ undoSuccess = this._undoTranslateComponent(lastOp.params);
185
+ break;
186
+ case 'translateGateway':
187
+ undoSuccess = this._undoTranslateGateway(lastOp.params);
188
+ break;
189
+ default:
190
+ console.warn("\u26A0\uFE0F Unknown operation type: ".concat(lastOp.operationName));
191
+ return false;
192
+ }
193
+ if (undoSuccess) {
194
+ // Remove the operation from history
195
+ this._removeLastOperationFromHistory();
196
+ console.log('✅ Undo successful');
197
+ return true;
198
+ } else {
199
+ console.error('❌ Undo failed');
200
+ return false;
201
+ }
202
+ } catch (error) {
203
+ console.error('❌ Error during undo:', error);
204
+ return false;
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Undo a translateSegment operation
210
+ * @param {Object} params - Original operation parameters
211
+ * @returns {boolean} Success status
212
+ * @private
213
+ */
214
+ }, {
215
+ key: "_undoTranslateSegment",
216
+ value: function _undoTranslateSegment(params) {
217
+ var _this$sceneViewer, _centralPlant$manager;
218
+ var segmentId = params.segmentId,
219
+ axis = params.axis,
220
+ value = params.value;
221
+
222
+ // Access centralPlant through sceneViewer
223
+ var centralPlant = (_this$sceneViewer = this.sceneViewer) === null || _this$sceneViewer === void 0 ? void 0 : _this$sceneViewer.centralPlant;
224
+ if (!centralPlant || !centralPlant.translateSegment) {
225
+ console.error('❌ CentralPlant translateSegment API not available for undo');
226
+ return false;
227
+ }
228
+
229
+ // Reverse the translation by applying negative value
230
+ // Note: We temporarily disable history tracking to avoid creating a new history entry
231
+ var historyManager = (_centralPlant$manager = centralPlant.managers) === null || _centralPlant$manager === void 0 ? void 0 : _centralPlant$manager.operationHistoryManager;
232
+ var originalAddMethod = historyManager === null || historyManager === void 0 ? void 0 : historyManager.addToOperationHistory;
233
+
234
+ // Disable history tracking during undo
235
+ if (historyManager) {
236
+ historyManager.addToOperationHistory = function () {
237
+ return true;
238
+ };
239
+ }
240
+ var success = centralPlant.translateSegment(segmentId, axis, -value);
241
+
242
+ // Restore history tracking
243
+ if (historyManager && originalAddMethod) {
244
+ historyManager.addToOperationHistory = originalAddMethod;
245
+ }
246
+ return success;
247
+ }
248
+
249
+ /**
250
+ * Undo a translateComponent operation
251
+ * @param {Object} params - Original operation parameters
252
+ * @returns {boolean} Success status
253
+ * @private
254
+ */
255
+ }, {
256
+ key: "_undoTranslateComponent",
257
+ value: function _undoTranslateComponent(params) {
258
+ var _this$sceneViewer2, _centralPlant$manager2;
259
+ var componentId = params.componentId,
260
+ axis = params.axis,
261
+ value = params.value;
262
+ var centralPlant = (_this$sceneViewer2 = this.sceneViewer) === null || _this$sceneViewer2 === void 0 ? void 0 : _this$sceneViewer2.centralPlant;
263
+ if (!centralPlant || !centralPlant.translateComponent) {
264
+ console.error('❌ CentralPlant translateComponent API not available for undo');
265
+ return false;
266
+ }
267
+
268
+ // Temporarily disable history tracking
269
+ var historyManager = (_centralPlant$manager2 = centralPlant.managers) === null || _centralPlant$manager2 === void 0 ? void 0 : _centralPlant$manager2.operationHistoryManager;
270
+ var originalAddMethod = historyManager === null || historyManager === void 0 ? void 0 : historyManager.addToOperationHistory;
271
+ if (historyManager) {
272
+ historyManager.addToOperationHistory = function () {
273
+ return true;
274
+ };
275
+ }
276
+ var success = centralPlant.translateComponent(componentId, axis, -value);
277
+ if (historyManager && originalAddMethod) {
278
+ historyManager.addToOperationHistory = originalAddMethod;
279
+ }
280
+ return success;
281
+ }
282
+
283
+ /**
284
+ * Undo a translateGateway operation
285
+ * @param {Object} params - Original operation parameters
286
+ * @returns {boolean} Success status
287
+ * @private
288
+ */
289
+ }, {
290
+ key: "_undoTranslateGateway",
291
+ value: function _undoTranslateGateway(params) {
292
+ var _this$sceneViewer3, _centralPlant$manager3;
293
+ var gatewayId = params.gatewayId,
294
+ axis = params.axis,
295
+ value = params.value;
296
+ var centralPlant = (_this$sceneViewer3 = this.sceneViewer) === null || _this$sceneViewer3 === void 0 ? void 0 : _this$sceneViewer3.centralPlant;
297
+ if (!centralPlant || !centralPlant.translateGateway) {
298
+ console.error('❌ CentralPlant translateGateway API not available for undo');
299
+ return false;
300
+ }
301
+
302
+ // Temporarily disable history tracking
303
+ var historyManager = (_centralPlant$manager3 = centralPlant.managers) === null || _centralPlant$manager3 === void 0 ? void 0 : _centralPlant$manager3.operationHistoryManager;
304
+ var originalAddMethod = historyManager === null || historyManager === void 0 ? void 0 : historyManager.addToOperationHistory;
305
+ if (historyManager) {
306
+ historyManager.addToOperationHistory = function () {
307
+ return true;
308
+ };
309
+ }
310
+ var success = centralPlant.translateGateway(gatewayId, axis, -value);
311
+ if (historyManager && originalAddMethod) {
312
+ historyManager.addToOperationHistory = originalAddMethod;
313
+ }
314
+ return success;
315
+ }
316
+
317
+ /**
318
+ * Remove the most recent operation from history
319
+ * @returns {boolean} Success status
320
+ * @private
321
+ */
322
+ }, {
323
+ key: "_removeLastOperationFromHistory",
324
+ value: function _removeLastOperationFromHistory() {
325
+ try {
326
+ if (!this._isSessionStorageAvailable()) {
327
+ return false;
328
+ }
329
+ var stored = sessionStorage.getItem(this.storageKey);
330
+ if (!stored) {
331
+ return false;
332
+ }
333
+ var history = JSON.parse(stored);
334
+
335
+ // Remove first item (most recent)
336
+ if (history.length > 0) {
337
+ history.shift();
338
+ sessionStorage.setItem(this.storageKey, JSON.stringify(history));
339
+ console.log('🗑️ Removed last operation from history');
340
+ return true;
341
+ }
342
+ return false;
343
+ } catch (error) {
344
+ console.error('❌ Error removing last operation from history:', error);
345
+ return false;
346
+ }
347
+ }
348
+
349
+ /**
350
+ * Get operation history count
351
+ * @returns {number} Number of operations in history
352
+ */
353
+ }, {
354
+ key: "getHistoryCount",
355
+ value: function getHistoryCount() {
356
+ var history = this.getOperationHistory();
357
+ return history.length;
358
+ }
359
+
360
+ /**
361
+ * Set the maximum history size
362
+ * @param {number} size - Maximum number of operations to store
363
+ */
364
+ }, {
365
+ key: "setMaxHistorySize",
366
+ value: function setMaxHistorySize(size) {
367
+ if (typeof size !== 'number' || size < 1) {
368
+ console.warn('⚠️ Invalid max history size, must be a positive number');
369
+ return;
370
+ }
371
+ this.maxHistorySize = size;
372
+ console.log("\uD83D\uDCCF Max history size set to ".concat(size));
373
+
374
+ // Trim existing history if needed
375
+ try {
376
+ if (this._isSessionStorageAvailable()) {
377
+ var stored = sessionStorage.getItem(this.storageKey);
378
+ if (stored) {
379
+ var history = JSON.parse(stored);
380
+ if (history.length > size) {
381
+ history = history.slice(0, size);
382
+ sessionStorage.setItem(this.storageKey, JSON.stringify(history));
383
+ console.log("\u2702\uFE0F Trimmed history to ".concat(size, " entries"));
384
+ }
385
+ }
386
+ }
387
+ } catch (error) {
388
+ console.error('❌ Error trimming history:', error);
389
+ }
390
+ }
391
+
392
+ /**
393
+ * Dispose method - clean up resources
394
+ * @override
395
+ */
396
+ }, {
397
+ key: "dispose",
398
+ value: function dispose() {
399
+ // Clear any references
400
+ this.sceneViewer = null;
401
+
402
+ // Call parent dispose
403
+ _superPropGet(OperationHistoryManager, "dispose", this, 3)([]);
404
+ console.log('🗑️ OperationHistoryManager disposed');
405
+ }
406
+ }]);
407
+ }(BaseDisposable);
408
+
409
+ export { OperationHistoryManager, OperationHistoryManager as default };
@@ -7,7 +7,8 @@ import { BaseDisposable } from '../../core/baseDisposable.js';
7
7
  var DEFAULT_SETTINGS = {
8
8
  scene: {
9
9
  autoRotation: false,
10
- checkUnderground: true
10
+ checkUnderground: true,
11
+ splitSegmentsWithComponentConnectors: true
11
12
  },
12
13
  viewport: {
13
14
  perspectiveFullscreen: true
@@ -17,7 +17,7 @@
17
17
  */
18
18
  function isComponent(obj) {
19
19
  if (!obj || !obj.userData) return false;
20
- return obj.userData.objectType === 'component' || obj.userData.objectType !== undefined;
20
+ return obj.userData.objectType === 'component';
21
21
  }
22
22
 
23
23
  /**
@@ -33,7 +33,7 @@ function isComponent(obj) {
33
33
  */
34
34
  function isSegment(obj) {
35
35
  if (!obj || !obj.userData) return false;
36
- return obj.userData.objectType === 'segment' || obj.userData.isPipeSegment === true;
36
+ return obj.userData.objectType === 'segment';
37
37
  }
38
38
 
39
39
  /**
@@ -49,7 +49,7 @@ function isSegment(obj) {
49
49
  */
50
50
  function isGateway(obj) {
51
51
  if (!obj || !obj.userData) return false;
52
- return obj.userData.objectType === 'gateway' || obj.userData.objectType === 'gateway';
52
+ return obj.userData.objectType === 'gateway';
53
53
  }
54
54
 
55
55
  /**
@@ -69,7 +69,7 @@ function isConnector(obj) {
69
69
  }
70
70
 
71
71
  /**
72
- * Check if object was declared (from scene definition or manually edited)
72
+ * Check if object is declared (manually placed/positioned)
73
73
  * Declared objects should be preserved during regeneration.
74
74
  *
75
75
  * @param {Object} obj - Three.js object to check
@@ -82,7 +82,7 @@ function isConnector(obj) {
82
82
  */
83
83
  function isDeclared(obj) {
84
84
  if (!obj || !obj.userData) return false;
85
- return obj.userData.isDeclared === true || obj.userData.origin === 'declared';
85
+ return obj.userData.isDeclared === true;
86
86
  }
87
87
 
88
88
  /**
@@ -194,7 +194,6 @@ function getObjectTypeName(obj) {
194
194
  function markAsDeclared(obj) {
195
195
  if (obj && obj.userData) {
196
196
  obj.userData.isDeclared = true;
197
- obj.userData.origin = 'declared'; // Backward compatibility
198
197
  }
199
198
  }
200
199
 
@@ -211,7 +210,6 @@ function markAsDeclared(obj) {
211
210
  function markAsComputed(obj) {
212
211
  if (obj && obj.userData) {
213
212
  obj.userData.isDeclared = false;
214
- obj.userData.origin = 'computed'; // Backward compatibility
215
213
  }
216
214
  }
217
215
 
package/dist/index.d.ts CHANGED
@@ -9,7 +9,6 @@
9
9
  export { CentralPlant } from './core/centralPlant.js';
10
10
  export { DebugLogger, logger, transformLogger, pathfinderLogger, modelLogger } from './core/debugLogger.js';
11
11
  export { generateUuidFromName, getHardcodedUuid, findObjectByHardcodedUuid } from './core/nameUtils.js';
12
- export { MathUtils } from './core/mathUtils.js';
13
12
 
14
13
  // Scene management
15
14
  export { SceneInitializationManager } from './managers/scene/sceneInitializationManager.js';
@@ -19,7 +18,7 @@ export { SceneTooltipsManager } from './managers/scene/sceneTooltipsManager.js';
19
18
 
20
19
  // Component management
21
20
  export { ComponentManager } from './managers/components/componentManager.js';
22
- export { AnimationManager } from './managers/components/animationManager.js';
21
+ export { AnimationManager } from './managers/scene/animationManager.js';
23
22
  export { PathfindingManager } from './managers/components/pathfindingManager.js';
24
23
 
25
24
  // Controls management
@@ -36,6 +35,7 @@ export { loadTextureSetAndCreateMaterial } from './managers/environment/textureC
36
35
  export { HotReloadManager } from './managers/system/hotReloadManager.js';
37
36
  export { DisposalManager } from './managers/system/disposalManager.js';
38
37
  export { PerformanceMonitor } from './managers/system/performanceMonitor.js';
38
+ export { OperationHistoryManager } from './managers/system/operationHistoryManager.js';
39
39
 
40
40
  // Rendering utilities
41
41
  export { default as modelPreloader } from './rendering/modelPreloader.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2112-lab/central-plant",
3
- "version": "0.1.39",
3
+ "version": "0.1.41",
4
4
  "description": "Utility modules for the Central Plant Application",
5
5
  "main": "dist/bundle/index.js",
6
6
  "module": "dist/esm/index.js",