internal void RemoveSegmentEnd(SegmentEndGeometry segmentEndGeo, GeometryCalculationMode calcMode) { #if DEBUGGEO if (GlobalConfig.Instance.Debug.Switches[5]) { Log._Debug($">>> NodeGeometry: Remove segment end {segmentEndGeo.SegmentId} @ {NodeId}, calcMode? {calcMode}"); } #endif if (calcMode == GeometryCalculationMode.Init) { return; } if (!IsValid()) { //Log.Warning($"NodeGeometry: Trying to remove segment {segmentId} @ invalid node {NodeId}"); RemoveAllSegmentEnds(); return; } for (int i = 0; i < MAX_NUM_SEGMENTS; ++i) { if (segmentEndGeo.Equals(SegmentEndGeometries[i])) { SegmentEndGeometries[i] = null; } } if (calcMode == GeometryCalculationMode.Propagate) { RecalculateSegments(segmentEndGeo.SegmentId); } Recalculate(); }
/// <summary> /// Registers an observer. /// </summary> /// <param name="observer"></param> /// <returns>An unsubscriber</returns> /*public IDisposable Subscribe(IObserver<NodeGeometry> observer) { * try { * Monitor.Enter(Lock); * observers.Add(observer); * } finally { * Monitor.Exit(Lock); * } * return new GenericUnsubscriber<NodeGeometry>(observers, observer, Lock); * }*/ internal void AddSegmentEnd(SegmentEndGeometry segEndGeo, GeometryCalculationMode calcMode) { #if DEBUGGEO if (GlobalConfig.Instance.Debug.Switches[5]) { Log._Debug($">>> NodeGeometry: Add segment end {segEndGeo.SegmentId}, start? {segEndGeo.StartNode} @ node {NodeId}"); } #endif if (!IsValid()) { //Log.Error($"NodeGeometry: Trying to add segment {segmentId} @ invalid node {NodeId}"); Invalidate(); return; } bool found = false; int freeIndex = -1; for (int i = 0; i < MAX_NUM_SEGMENTS; ++i) { SegmentEndGeometry storedEndGeo = SegmentEndGeometries[i]; if (segEndGeo.Equals(storedEndGeo)) { SegmentEndGeometries[i] = segEndGeo; found = true; break; } else if (storedEndGeo == null && freeIndex < 0) { freeIndex = i; } } if (!found) { if (freeIndex >= 0) { SegmentEndGeometries[freeIndex] = segEndGeo; } else { Log.Error($"NodeGeometry.AddSegmentEnd: Detected inconsistency. Unable to add segment end {segEndGeo} to node {NodeId}. Maximum segment end capacity reached."); } } if (calcMode == GeometryCalculationMode.Propagate) { RecalculateSegments(segEndGeo.SegmentId); } if (!found && lastRemovedSegmentEndId != null) { CurrentSegmentReplacement.oldSegmentEndId = lastRemovedSegmentEndId; CurrentSegmentReplacement.newSegmentEndId = segEndGeo; lastRemovedSegmentEndId = null; } Recalculate(); }