@2112-lab/central-plant 0.1.49 → 0.1.51

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.
@@ -79,6 +79,20 @@ var TransformOperationsManager = /*#__PURE__*/function () {
79
79
  this.fixUndergroundComponent(component);
80
80
  }
81
81
 
82
+ // Auto-update paths if enabled (matches behavior of translateSegment and translateGateway)
83
+ if (this.sceneViewer.shouldUpdatePaths) {
84
+ try {
85
+ if (this.sceneViewer && typeof this.sceneViewer.updatePaths === 'function') {
86
+ this.sceneViewer.updatePaths();
87
+ console.log('🔄 Paths auto-updated after component translation');
88
+ } else {
89
+ console.warn('âš ī¸ updatePaths method not available on sceneViewer');
90
+ }
91
+ } catch (error) {
92
+ console.error('❌ Error auto-updating paths:', error);
93
+ }
94
+ }
95
+
82
96
  // Emit transform event if available
83
97
  if (this.sceneViewer.emit && typeof this.sceneViewer.emit === 'function') {
84
98
  this.sceneViewer.emit('objectTransformed', {
@@ -102,7 +116,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
102
116
  }, {
103
117
  key: "translateSegment",
104
118
  value: function translateSegment(segmentId, axis, value) {
105
- var _segment$userData, _segment$userData2, _this$sceneViewer3, _this$sceneViewer$man3, _this$sceneViewer$man4, _this$sceneViewer$man5;
119
+ var _segment$userData, _segment$userData2, _segment$userData3, _this$sceneViewer2, _this$sceneViewer$man2, _this$sceneViewer$man3, _this$sceneViewer$man4;
106
120
  var skipPathUpdate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
107
121
  // Validate parameters
108
122
  if (!segmentId || !axis || value === undefined || value === null) {
@@ -143,6 +157,12 @@ var TransformOperationsManager = /*#__PURE__*/function () {
143
157
  return false;
144
158
  }
145
159
 
160
+ // Check if segment is immutable (computed from pathfinder)
161
+ if (((_segment$userData3 = segment.userData) === null || _segment$userData3 === void 0 ? void 0 : _segment$userData3.immutable) === true) {
162
+ console.warn("\u26A0\uFE0F translateSegment(): Segment '".concat(segmentId, "' is immutable (computed from pathfinder)"));
163
+ return false;
164
+ }
165
+
146
166
  // Check segment orientation and cancel invalid translations
147
167
  // Get the segment's direction vector to determine which axis it runs along
148
168
  var direction = new THREE.Vector3(0, 1, 0);
@@ -188,66 +208,6 @@ var TransformOperationsManager = /*#__PURE__*/function () {
188
208
  parentType: (_c$parent2 = c.parent) === null || _c$parent2 === void 0 || (_c$parent2 = _c$parent2.userData) === null || _c$parent2 === void 0 ? void 0 : _c$parent2.objectType
189
209
  };
190
210
  }));
191
-
192
- // Filter out segment connectors - we only care about component connectors
193
- var componentConnectorsAtEndpoints = connectorsAtEndpoints.filter(function (connector) {
194
- var _connector$userData;
195
- return ((_connector$userData = connector.userData) === null || _connector$userData === void 0 ? void 0 : _connector$userData.objectType) !== 'segment-connector';
196
- });
197
- console.log("\uD83D\uDD0D After filtering, ".concat(componentConnectorsAtEndpoints.length, " component connectors at endpoints"));
198
- if (componentConnectorsAtEndpoints.length > 0) {
199
- var _this$sceneViewer2, _this$sceneViewer$man2;
200
- console.warn("\u26A0\uFE0F translateSegment(): Segment '".concat(segmentId, "' has component connectors at endpoints."));
201
- console.log(" Found ".concat(componentConnectorsAtEndpoints.length, " component connector(s):"), componentConnectorsAtEndpoints.map(function (c) {
202
- var _c$parent3;
203
- return {
204
- uuid: c.uuid,
205
- parent: (_c$parent3 = c.parent) === null || _c$parent3 === void 0 ? void 0 : _c$parent3.uuid
206
- };
207
- }));
208
-
209
- // Check if segment splitting is enabled in settings
210
- var splitSegmentsEnabled = (_this$sceneViewer2 = this.sceneViewer) === null || _this$sceneViewer2 === void 0 || (_this$sceneViewer2 = _this$sceneViewer2.managers) === null || _this$sceneViewer2 === void 0 || (_this$sceneViewer2 = _this$sceneViewer2.settingsManager) === null || _this$sceneViewer2 === void 0 ? void 0 : _this$sceneViewer2.getSetting('scene', 'splitSegmentsWithComponentConnectors');
211
- if (splitSegmentsEnabled === false) {
212
- console.warn('âš ī¸ Segment splitting is disabled. Cannot translate segments with component connectors at endpoints.');
213
- return false;
214
- }
215
-
216
- // Split the segment and translate the free half
217
- console.log('âœ‚ī¸ Splitting segment to enable translation of the free half...');
218
-
219
- // Get sceneOperationsManager
220
- var _sceneOperationsManager = (_this$sceneViewer$man2 = this.sceneViewer.managers) === null || _this$sceneViewer$man2 === void 0 ? void 0 : _this$sceneViewer$man2.sceneOperationsManager;
221
- if (!_sceneOperationsManager) {
222
- console.error('❌ translateSegment(): SceneOperationsManager not available for splitting');
223
- return false;
224
- }
225
- try {
226
- var splitResult = _sceneOperationsManager.splitSegment(segment, this.sceneViewer.currentSceneData);
227
- if (splitResult) {
228
- console.log("\u2705 Segment split and shortened: ".concat(splitResult.uuid, " (new length: ").concat(splitResult.geometry.parameters.height, ")"));
229
-
230
- // The splitResult is now a shortened manual segment
231
- // Translate this shortened segment
232
- console.log("\uD83C\uDFAF Translating shortened manual segment: ".concat(splitResult.uuid));
233
-
234
- // Now translate the shortened manual segment (recursive call with the new segment)
235
- var translateSuccess = this.translateSegment(splitResult.uuid, axis, value);
236
- if (!translateSuccess) {
237
- console.error('❌ translateSegment(): Failed to translate shortened manual segment');
238
- return false;
239
- }
240
- console.log('✅ Split, shorten, and translate operation completed successfully');
241
- return true;
242
- } else {
243
- console.error('❌ translateSegment(): Split operation failed');
244
- return false;
245
- }
246
- } catch (error) {
247
- console.error('❌ translateSegment(): Error splitting segment:', error);
248
- return false;
249
- }
250
- }
251
211
  console.log("\uD83D\uDD04 translateSegment(): Translating segment ".concat(segmentId, " on ").concat(axis, " axis by ").concat(value));
252
212
 
253
213
  // Temporarily apply the translation to check for collisions
@@ -277,7 +237,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
277
237
  segment.updateMatrixWorld(true);
278
238
 
279
239
  // Check if translationalOverrideForAutomaticSegments is enabled
280
- var translationalOverride = (_this$sceneViewer3 = this.sceneViewer) === null || _this$sceneViewer3 === void 0 || (_this$sceneViewer3 = _this$sceneViewer3.managers) === null || _this$sceneViewer3 === void 0 || (_this$sceneViewer3 = _this$sceneViewer3.settingsManager) === null || _this$sceneViewer3 === void 0 ? void 0 : _this$sceneViewer3.getSetting('scene', 'translationalOverrideForAutomaticSegments');
240
+ var translationalOverride = (_this$sceneViewer2 = this.sceneViewer) === null || _this$sceneViewer2 === void 0 || (_this$sceneViewer2 = _this$sceneViewer2.managers) === null || _this$sceneViewer2 === void 0 || (_this$sceneViewer2 = _this$sceneViewer2.settingsManager) === null || _this$sceneViewer2 === void 0 ? void 0 : _this$sceneViewer2.getSetting('scene', 'translationalOverrideForAutomaticSegments');
281
241
 
282
242
  // If override is disabled (false), check for intersections with computed segments
283
243
  if (translationalOverride === false) {
@@ -311,8 +271,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
311
271
  }
312
272
 
313
273
  // Validate PathfindingManager and SceneOperationsManager availability
314
- var pathfindingManager = (_this$sceneViewer$man3 = this.sceneViewer.managers) === null || _this$sceneViewer$man3 === void 0 ? void 0 : _this$sceneViewer$man3.pathfindingManager;
315
- var sceneOperationsManager = (_this$sceneViewer$man4 = this.sceneViewer.managers) === null || _this$sceneViewer$man4 === void 0 ? void 0 : _this$sceneViewer$man4.sceneOperationsManager;
274
+ var pathfindingManager = (_this$sceneViewer$man2 = this.sceneViewer.managers) === null || _this$sceneViewer$man2 === void 0 ? void 0 : _this$sceneViewer$man2.pathfindingManager;
275
+ var sceneOperationsManager = (_this$sceneViewer$man3 = this.sceneViewer.managers) === null || _this$sceneViewer$man3 === void 0 ? void 0 : _this$sceneViewer$man3.sceneOperationsManager;
316
276
  if (!pathfindingManager || !sceneOperationsManager) {
317
277
  console.error('❌ translateSegment(): PathfindingManager or SceneOperationsManager not available');
318
278
  return false;
@@ -333,21 +293,11 @@ var TransformOperationsManager = /*#__PURE__*/function () {
333
293
 
334
294
  // ALWAYS update connector positions after segment movement (first or subsequent moves)
335
295
  this.updateSegmentConnectorPositions(segment);
336
-
337
- // NEW: Update adjacent manual segments to follow this segment's new position
338
- var maintainedConnections = this.snapSegmentConnectorsToNearbyEndpoints(segment);
339
-
340
- // NOTE: We do NOT remove connections from scene data
341
- // The connections remain valid - the manual segments are maintaining those connections
342
- // The pathfinding algorithm should detect that connectors are at the same position
343
- // and skip creating computed segments for them
344
- if (maintainedConnections.length > 0) {
345
- console.log("\u2139\uFE0F ".concat(maintainedConnections.length, " connection(s) maintained by manual segments"));
346
- }
296
+ this.snapSegmentConnectorsToNearbyEndpoints(segment);
347
297
 
348
298
  // Store transform parameters using the OperationHistoryManager BEFORE updatePaths
349
299
  // This is critical so that intersection detection can undo the operation
350
- if ((_this$sceneViewer$man5 = this.sceneViewer.managers) !== null && _this$sceneViewer$man5 !== void 0 && _this$sceneViewer$man5.operationHistory) {
300
+ if ((_this$sceneViewer$man4 = this.sceneViewer.managers) !== null && _this$sceneViewer$man4 !== void 0 && _this$sceneViewer$man4.operationHistory) {
351
301
  this.sceneViewer.managers.operationHistory.addToOperationHistory('translateSegment', {
352
302
  segmentId: segmentId,
353
303
  axis: axis,
@@ -360,9 +310,6 @@ var TransformOperationsManager = /*#__PURE__*/function () {
360
310
  // UNLESS skipPathUpdate is true (for batch operations)
361
311
  if (!skipPathUpdate) {
362
312
  console.log('🔄 Regenerating paths to create connecting pipe segments...');
363
- if (maintainedConnections.length > 0) {
364
- console.log("\u2139\uFE0F Manual segments are maintaining connections - pathfinding should skip connectors at same position");
365
- }
366
313
  try {
367
314
  if (this.sceneViewer && typeof this.sceneViewer.updatePaths === 'function') {
368
315
  this.sceneViewer.updatePaths();
@@ -400,11 +347,11 @@ var TransformOperationsManager = /*#__PURE__*/function () {
400
347
  }, {
401
348
  key: "translateGateway",
402
349
  value: function translateGateway(gatewayId, axis, value) {
403
- var _this$sceneViewer$man6, _this$sceneViewer$man7;
350
+ var _this$sceneViewer$man5, _this$sceneViewer$man6;
404
351
  console.log("[Pathfinder] translateGateway started");
405
352
 
406
353
  // Store transform parameters using the OperationHistoryManager
407
- if ((_this$sceneViewer$man6 = this.sceneViewer.managers) !== null && _this$sceneViewer$man6 !== void 0 && _this$sceneViewer$man6.operationHistoryManager) {
354
+ if ((_this$sceneViewer$man5 = this.sceneViewer.managers) !== null && _this$sceneViewer$man5 !== void 0 && _this$sceneViewer$man5.operationHistoryManager) {
408
355
  this.sceneViewer.managers.operationHistoryManager.addToOperationHistory('translateGateway', {
409
356
  gatewayId: gatewayId,
410
357
  axis: axis,
@@ -455,7 +402,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
455
402
 
456
403
  // Handle manual gateway transformation (convert to declared and process connections)
457
404
  console.log('🔧 Handling manual gateway transformation via SceneOperationsManager');
458
- var sceneOperationsManager = (_this$sceneViewer$man7 = this.sceneViewer.managers) === null || _this$sceneViewer$man7 === void 0 ? void 0 : _this$sceneViewer$man7.sceneOperationsManager;
405
+ var sceneOperationsManager = (_this$sceneViewer$man6 = this.sceneViewer.managers) === null || _this$sceneViewer$man6 === void 0 ? void 0 : _this$sceneViewer$man6.sceneOperationsManager;
459
406
  if (!sceneOperationsManager) {
460
407
  console.error('❌ translateGateway(): SceneOperationsManager not available');
461
408
  return false;
@@ -557,6 +504,20 @@ var TransformOperationsManager = /*#__PURE__*/function () {
557
504
  component.updateMatrix();
558
505
  component.updateMatrixWorld(true);
559
506
 
507
+ // Auto-update paths if enabled (matches behavior of translateComponent)
508
+ if (this.sceneViewer.shouldUpdatePaths) {
509
+ try {
510
+ if (this.sceneViewer && typeof this.sceneViewer.updatePaths === 'function') {
511
+ this.sceneViewer.updatePaths();
512
+ console.log('🔄 Paths auto-updated after component rotation');
513
+ } else {
514
+ console.warn('âš ī¸ updatePaths method not available on sceneViewer');
515
+ }
516
+ } catch (error) {
517
+ console.error('❌ Error auto-updating paths:', error);
518
+ }
519
+ }
520
+
560
521
  // Emit transform event if available
561
522
  if (this.sceneViewer.emit && typeof this.sceneViewer.emit === 'function') {
562
523
  this.sceneViewer.emit('objectTransformed', {
@@ -739,9 +700,9 @@ var TransformOperationsManager = /*#__PURE__*/function () {
739
700
  }, {
740
701
  key: "findConnectorsAtPositions",
741
702
  value: function findConnectorsAtPositions(positions) {
742
- var _this$sceneViewer4;
703
+ var _this$sceneViewer3;
743
704
  var tolerance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.15;
744
- if (!((_this$sceneViewer4 = this.sceneViewer) !== null && _this$sceneViewer4 !== void 0 && _this$sceneViewer4.scene)) {
705
+ if (!((_this$sceneViewer3 = this.sceneViewer) !== null && _this$sceneViewer3 !== void 0 && _this$sceneViewer3.scene)) {
745
706
  return [];
746
707
  }
747
708
  var foundConnectors = [];
@@ -785,9 +746,9 @@ var TransformOperationsManager = /*#__PURE__*/function () {
785
746
  }, {
786
747
  key: "updateSegmentConnectorPositions",
787
748
  value: function updateSegmentConnectorPositions(segment) {
788
- var _this$sceneViewer5;
749
+ var _this$sceneViewer4;
789
750
  console.log("updateSegmentConnectorPositions started:", segment);
790
- if (!segment || !((_this$sceneViewer5 = this.sceneViewer) !== null && _this$sceneViewer5 !== void 0 && (_this$sceneViewer5 = _this$sceneViewer5.currentSceneData) !== null && _this$sceneViewer5 !== void 0 && _this$sceneViewer5.scene)) {
751
+ if (!segment || !((_this$sceneViewer4 = this.sceneViewer) !== null && _this$sceneViewer4 !== void 0 && (_this$sceneViewer4 = _this$sceneViewer4.currentSceneData) !== null && _this$sceneViewer4 !== void 0 && _this$sceneViewer4.scene)) {
791
752
  console.warn('âš ī¸ updateSegmentConnectorPositions(): Missing segment or scene data');
792
753
  return;
793
754
  }
@@ -813,8 +774,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
813
774
 
814
775
  // First, find the segment in scene data
815
776
  var sceneDataSegment = this.sceneViewer.currentSceneData.scene.children.find(function (child) {
816
- var _segment$userData3;
817
- return child.uuid === segment.uuid || child.uuid === ((_segment$userData3 = segment.userData) === null || _segment$userData3 === void 0 ? void 0 : _segment$userData3.originalUuid);
777
+ var _segment$userData4;
778
+ return child.uuid === segment.uuid || child.uuid === ((_segment$userData4 = segment.userData) === null || _segment$userData4 === void 0 ? void 0 : _segment$userData4.originalUuid);
818
779
  });
819
780
  if (!sceneDataSegment) {
820
781
  console.warn("\u26A0\uFE0F Segment ".concat(segment.uuid, " not found in scene data"));
@@ -834,8 +795,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
834
795
 
835
796
  // Find the connector in the segment's children array (not root scene.children)
836
797
  var sceneDataConnector = sceneDataSegment.children.find(function (child) {
837
- var _connector$userData2;
838
- return child.uuid === connector.uuid || child.uuid === ((_connector$userData2 = connector.userData) === null || _connector$userData2 === void 0 ? void 0 : _connector$userData2.originalUuid);
798
+ var _connector$userData;
799
+ return child.uuid === connector.uuid || child.uuid === ((_connector$userData = connector.userData) === null || _connector$userData === void 0 ? void 0 : _connector$userData.originalUuid);
839
800
  });
840
801
  if (sceneDataConnector && sceneDataConnector.userData) {
841
802
  // Update position as array [x, y, z] for pathfinder compatibility
@@ -857,9 +818,9 @@ var TransformOperationsManager = /*#__PURE__*/function () {
857
818
  }, {
858
819
  key: "checkSegmentIntersection",
859
820
  value: function checkSegmentIntersection(segment) {
860
- var _this$sceneViewer6,
821
+ var _this$sceneViewer5,
861
822
  _this = this;
862
- if (!((_this$sceneViewer6 = this.sceneViewer) !== null && _this$sceneViewer6 !== void 0 && _this$sceneViewer6.scene)) {
823
+ if (!((_this$sceneViewer5 = this.sceneViewer) !== null && _this$sceneViewer5 !== void 0 && _this$sceneViewer5.scene)) {
863
824
  return false;
864
825
  }
865
826
 
@@ -929,8 +890,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
929
890
  }, {
930
891
  key: "checkSegmentPathConnectorCollision",
931
892
  value: function checkSegmentPathConnectorCollision(segment) {
932
- var _this$sceneViewer7;
933
- if (!((_this$sceneViewer7 = this.sceneViewer) !== null && _this$sceneViewer7 !== void 0 && _this$sceneViewer7.scene) || !segment) {
893
+ var _this$sceneViewer6;
894
+ if (!((_this$sceneViewer6 = this.sceneViewer) !== null && _this$sceneViewer6 !== void 0 && _this$sceneViewer6.scene) || !segment) {
934
895
  return null;
935
896
  }
936
897
  var collisionRadius = 0.5; // Radius around connector that triggers collision
@@ -1044,8 +1005,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1044
1005
  }, {
1045
1006
  key: "checkComponentConnectorCollision",
1046
1007
  value: function checkComponentConnectorCollision(newPosition) {
1047
- var _this$sceneViewer8;
1048
- if (!((_this$sceneViewer8 = this.sceneViewer) !== null && _this$sceneViewer8 !== void 0 && _this$sceneViewer8.scene)) {
1008
+ var _this$sceneViewer7;
1009
+ if (!((_this$sceneViewer7 = this.sceneViewer) !== null && _this$sceneViewer7 !== void 0 && _this$sceneViewer7.scene)) {
1049
1010
  return null;
1050
1011
  }
1051
1012
  var tolerance = 0.01; // Small tolerance for floating-point comparison
@@ -1201,10 +1162,10 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1201
1162
  }, {
1202
1163
  key: "snapSegmentConnectorsToNearbyEndpoints",
1203
1164
  value: function snapSegmentConnectorsToNearbyEndpoints(movedSegment) {
1204
- var _this$sceneViewer9,
1205
- _this$sceneViewer0,
1165
+ var _this$sceneViewer8,
1166
+ _this$sceneViewer9,
1206
1167
  _this2 = this;
1207
- if (!movedSegment || !((_this$sceneViewer9 = this.sceneViewer) !== null && _this$sceneViewer9 !== void 0 && _this$sceneViewer9.scene)) {
1168
+ if (!movedSegment || !((_this$sceneViewer8 = this.sceneViewer) !== null && _this$sceneViewer8 !== void 0 && _this$sceneViewer8.scene)) {
1208
1169
  return [];
1209
1170
  }
1210
1171
  console.log('🔗 Finding adjacent segments connected to moved segment...');
@@ -1226,7 +1187,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1226
1187
  var newEndpoints = this.calculateSegmentEndpoints(movedSegment);
1227
1188
 
1228
1189
  // Check scene data for connections involving the moved segment's connectors
1229
- var connections = ((_this$sceneViewer0 = this.sceneViewer) === null || _this$sceneViewer0 === void 0 || (_this$sceneViewer0 = _this$sceneViewer0.currentSceneData) === null || _this$sceneViewer0 === void 0 ? void 0 : _this$sceneViewer0.connections) || [];
1190
+ var connections = ((_this$sceneViewer9 = this.sceneViewer) === null || _this$sceneViewer9 === void 0 || (_this$sceneViewer9 = _this$sceneViewer9.currentSceneData) === null || _this$sceneViewer9 === void 0 ? void 0 : _this$sceneViewer9.connections) || [];
1230
1191
  var movedConnectorIds = movedConnectors.map(function (c) {
1231
1192
  return c.uuid;
1232
1193
  });
@@ -1382,9 +1343,9 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1382
1343
  }, {
1383
1344
  key: "updateConnectorPositionInSceneData",
1384
1345
  value: function updateConnectorPositionInSceneData(connector, worldPosition, parentSegment) {
1385
- var _this$sceneViewer1;
1346
+ var _this$sceneViewer0;
1386
1347
  // Update scene data if available
1387
- if (!((_this$sceneViewer1 = this.sceneViewer) !== null && _this$sceneViewer1 !== void 0 && _this$sceneViewer1.currentSceneData)) {
1348
+ if (!((_this$sceneViewer0 = this.sceneViewer) !== null && _this$sceneViewer0 !== void 0 && _this$sceneViewer0.currentSceneData)) {
1388
1349
  return;
1389
1350
  }
1390
1351
  var cleanPosition = function cleanPosition(value) {
@@ -1407,8 +1368,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1407
1368
  }
1408
1369
 
1409
1370
  /**
1410
- * Recreate segment mesh with new length based on connector positions
1411
- * @param {THREE.Object3D} segment - The segment to recreate
1371
+ * Adjust segment geometry and transform to match new endpoint positions
1372
+ * @param {THREE.Object3D} segment - The segment to adjust
1412
1373
  * @param {Array<THREE.Object3D>} connectors - The segment's connectors
1413
1374
  * @param {THREE.Vector3} endPoint1 - Explicit world position for first endpoint (optional)
1414
1375
  * @param {THREE.Vector3} endPoint2 - Explicit world position for second endpoint (optional)
@@ -1422,7 +1383,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1422
1383
  var endPoint2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
1423
1384
  var activeSegment = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
1424
1385
  if (!segment || connectors.length !== 2) {
1425
- console.warn('âš ī¸ Cannot recreate segment: invalid segment or connectors');
1386
+ console.warn('âš ī¸ Cannot adjust segment: invalid segment or connectors');
1426
1387
  return;
1427
1388
  }
1428
1389
  var _connectors = _slicedToArray(connectors, 2),
@@ -1465,21 +1426,28 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1465
1426
  this._removeZeroLengthSegment(segment, connectors, activeSegment);
1466
1427
  return;
1467
1428
  }
1468
- console.log("\uD83D\uDD27 Recreating segment with new length: ".concat(newLength.toFixed(3), " (was ").concat(segment.geometry.parameters.height.toFixed(3), ")"));
1429
+ var oldLength = segment.geometry.parameters.height;
1430
+ console.log("\uD83D\uDD27 Adjusting segment geometry: ".concat(oldLength.toFixed(3), " \u2192 ").concat(newLength.toFixed(3)));
1431
+
1432
+ // Only recreate geometry if length has changed significantly
1433
+ if (Math.abs(newLength - oldLength) > 1e-6) {
1434
+ var oldGeometry = segment.geometry;
1435
+ var pipeRadius = oldGeometry.parameters.radiusTop || 0.1;
1469
1436
 
1470
- // Store old geometry and material references
1471
- var oldGeometry = segment.geometry;
1472
- segment.material;
1473
- var pipeRadius = oldGeometry.parameters.radiusTop || 0.1;
1437
+ // Create new cylinder geometry with updated length
1438
+ var newGeometry = new THREE.CylinderGeometry(pipeRadius, pipeRadius, newLength, 16, 1, false);
1474
1439
 
1475
- // Create new cylinder geometry with updated length
1476
- var newGeometry = new THREE.CylinderGeometry(pipeRadius, pipeRadius, newLength, 16, 1, false);
1440
+ // Replace geometry
1441
+ segment.geometry = newGeometry;
1477
1442
 
1478
- // Update segment mesh
1479
- segment.geometry = newGeometry;
1443
+ // Dispose old geometry
1444
+ oldGeometry.dispose();
1445
+ }
1446
+
1447
+ // Update segment position to new center
1480
1448
  segment.position.copy(newCenter);
1481
1449
 
1482
- // Calculate and apply rotation
1450
+ // Calculate and apply rotation to align with new direction
1483
1451
  var quaternion = new THREE.Quaternion();
1484
1452
  var up = new THREE.Vector3(0, 1, 0);
1485
1453
  quaternion.setFromUnitVectors(up, direction.clone().normalize());
@@ -1488,12 +1456,7 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1488
1456
  // Update matrices
1489
1457
  segment.updateMatrix();
1490
1458
  segment.updateMatrixWorld(true);
1491
-
1492
- // Dispose old geometry
1493
- if (oldGeometry && oldGeometry !== newGeometry) {
1494
- oldGeometry.dispose();
1495
- }
1496
- console.log("\u2705 Segment mesh recreated: new length = ".concat(newLength.toFixed(3), ", center = [").concat(newCenter.x.toFixed(2), ", ").concat(newCenter.y.toFixed(2), ", ").concat(newCenter.z.toFixed(2), "]"));
1459
+ console.log("\u2705 Segment adjusted: length = ".concat(newLength.toFixed(3), ", center = [").concat(newCenter.x.toFixed(2), ", ").concat(newCenter.y.toFixed(2), ", ").concat(newCenter.z.toFixed(2), "]"));
1497
1460
  }
1498
1461
 
1499
1462
  /**
@@ -1610,8 +1573,8 @@ var TransformOperationsManager = /*#__PURE__*/function () {
1610
1573
  // Remove segment from scene data
1611
1574
  if (currentSceneData.scene && currentSceneData.scene.children) {
1612
1575
  var segmentIndex = currentSceneData.scene.children.findIndex(function (child) {
1613
- var _segment$userData4;
1614
- return child.uuid === segment.uuid || child.uuid === ((_segment$userData4 = segment.userData) === null || _segment$userData4 === void 0 ? void 0 : _segment$userData4.originalUuid);
1576
+ var _segment$userData5;
1577
+ return child.uuid === segment.uuid || child.uuid === ((_segment$userData5 = segment.userData) === null || _segment$userData5 === void 0 ? void 0 : _segment$userData5.originalUuid);
1615
1578
  });
1616
1579
  if (segmentIndex !== -1) {
1617
1580
  currentSceneData.scene.children.splice(segmentIndex, 1);
@@ -14,21 +14,12 @@ var KeyboardControlsManager = /*#__PURE__*/function () {
14
14
  return _createClass(KeyboardControlsManager, [{
15
15
  key: "setupKeyboardControls",
16
16
  value: function setupKeyboardControls() {
17
- var _this = this;
18
17
  this.handleKeyDown = function (event) {
19
18
  // Sample Ctrl+Z example
20
19
  if (event.ctrlKey && (event.key.toLowerCase() === 'z' || event.code === 'KeyZ')) {
21
20
  // method call here
22
21
  return;
23
22
  }
24
-
25
- // Shift+D to split selected segment
26
- if (event.shiftKey && (event.key.toLowerCase() === 'd' || event.code === 'KeyD')) {
27
- _this.handleSegmentSplit();
28
- event.preventDefault();
29
- event.stopPropagation();
30
- return;
31
- }
32
23
  switch (event.key.toLowerCase()) {
33
24
  }
34
25
  };
@@ -42,53 +33,6 @@ var KeyboardControlsManager = /*#__PURE__*/function () {
42
33
  console.log('Keyboard controls initialized with Ctrl+Z undo override and Shift+D segment split');
43
34
  }
44
35
 
45
- /**
46
- * Handle segment split operation (Shift+D)
47
- * Splits the currently selected segment in half if it's a pipe segment
48
- */
49
- }, {
50
- key: "handleSegmentSplit",
51
- value: function handleSegmentSplit() {
52
- var sceneViewer = this.sceneViewer;
53
-
54
- // Check if transform controls are active with a selected object
55
- if (!sceneViewer.transformManager || !sceneViewer.transformManager.selectedObjects || sceneViewer.transformManager.selectedObjects.length === 0) {
56
- console.log('â„šī¸ No object selected for segment split');
57
- return;
58
- }
59
- var selectedObject = sceneViewer.transformManager.selectedObjects[0];
60
-
61
- // Verify it's a segment
62
- if (!selectedObject.userData || selectedObject.userData.objectType !== 'segment') {
63
- console.log('â„šī¸ Selected object is not a segment, cannot split');
64
- return;
65
- }
66
- console.log('âœ‚ī¸ Shift+D pressed - splitting segment:', selectedObject.uuid);
67
-
68
- // Access CentralPlant through sceneViewer
69
- var centralPlant = sceneViewer.centralPlant;
70
- if (!centralPlant || typeof centralPlant.splitSegment !== 'function') {
71
- console.error('❌ CentralPlant or splitSegment method not available');
72
- return;
73
- }
74
-
75
- // Call the public API to split the segment
76
- var result = centralPlant.splitSegment(selectedObject.uuid);
77
- if (result) {
78
- console.log('✅ Segment split successful:', result);
79
-
80
- // Deselect the original segment (now removed) and optionally select one of the new segments
81
- sceneViewer.transformManager.deselectObject();
82
-
83
- // Optionally select the first new segment
84
- if (result.segment1) {
85
- sceneViewer.transformManager.selectObject(result.segment1);
86
- }
87
- } else {
88
- console.error('❌ Segment split failed');
89
- }
90
- }
91
-
92
36
  /**
93
37
  * Toggle auto-rotation of the camera
94
38
  */