protected override void HandleSegmentEndReplacement(SegmentEndReplacement replacement, SegmentEndGeometry endGeo)
        {
            ISegmentEndId oldSegmentEndId = replacement.oldSegmentEndId;
            ISegmentEndId newSegmentEndId = replacement.newSegmentEndId;

            SegmentEndFlags flags;

            if (oldSegmentEndId.StartNode)
            {
                flags = invalidSegmentFlags[oldSegmentEndId.SegmentId].startNodeFlags;
                invalidSegmentFlags[oldSegmentEndId.SegmentId].startNodeFlags.Reset();
            }
            else
            {
                flags = invalidSegmentFlags[oldSegmentEndId.SegmentId].endNodeFlags;
                invalidSegmentFlags[oldSegmentEndId.SegmentId].endNodeFlags.Reset();
            }

            Services.NetService.ProcessNode(endGeo.NodeId(), delegate(ushort nId, ref NetNode node) {
                flags.UpdateDefaults(newSegmentEndId.SegmentId, newSegmentEndId.StartNode, ref node);
                return(true);
            });
            Log._Debug($"JunctionRestrictionsManager.HandleSegmentEndReplacement({replacement}): Segment replacement detected: {oldSegmentEndId.SegmentId} -> {newSegmentEndId.SegmentId} @ {newSegmentEndId.StartNode}");
            SetSegmentEndFlags(newSegmentEndId.SegmentId, newSegmentEndId.StartNode, flags);
        }
            protected override void HandleValidNode(NodeGeometry geometry)
            {
                if (geometry.CurrentSegmentReplacement.oldSegmentEndId != null && geometry.CurrentSegmentReplacement.newSegmentEndId != null)
                {
                    ISegmentEndId oldSegmentEndId = geometry.CurrentSegmentReplacement.oldSegmentEndId;
                    ISegmentEndId newSegmentEndId = geometry.CurrentSegmentReplacement.newSegmentEndId;

                    SegmentEndFlags flags;
                    if (oldSegmentEndId.StartNode)
                    {
                        flags = invalidSegmentFlags[oldSegmentEndId.SegmentId].startNodeFlags;
                    }
                    else
                    {
                        flags = invalidSegmentFlags[oldSegmentEndId.SegmentId].endNodeFlags;
                    }

                    if (flags.IsDefault())
                    {
                        return;
                    }

                    Log._Debug($"JunctionRestrictionsManager.NodeWatcher.HandleValidNode({geometry.NodeId}): Segment replacement detected: {oldSegmentEndId.SegmentId} -> {newSegmentEndId.SegmentId}\n" +
                               $"Moving segmend end flags {flags} to new segment end."
                               );

                    junctionRestrictionsManager.SetSegmentEndFlags(newSegmentEndId.SegmentId, newSegmentEndId.StartNode, flags);
                }
            }
 public bool Equals(ISegmentEndId otherSegEndId)
 {
     if (otherSegEndId == null)
     {
         return(false);
     }
     return(SegmentId == otherSegEndId.SegmentId && StartNode == otherSegEndId.StartNode);
 }
コード例 #4
0
        /// <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();
        }
        public short ClockwiseIndexOfSegmentEnd(ISegmentEndId endId)
        {
            SegmentEndGeometry endGeo = SegmentGeometry.Get(endId.SegmentId)?.GetEnd(endId.StartNode);

            if (endGeo == null)
            {
                return(0);
            }
            return(endGeo.GetClockwiseIndex());
        }
コード例 #6
0
 protected void Invalidate()
 {
     for (int i = 0; i < MAX_NUM_SEGMENTS; ++i)
     {
         SegmentEndGeometries[i] = null;
     }
     lastRemovedSegmentEndId   = null;
     CurrentSegmentReplacement = default(SegmentEndReplacement);
     NotifyGeomentryManager();
 }
            protected override void HandleValidNode(NodeGeometry geometry)
            {
                // update segment defaults
                foreach (SegmentEndGeometry endGeo in geometry.SegmentEndGeometries)
                {
                    if (endGeo == null)
                    {
                        continue;
                    }

                    SegmentGeometry segGeo = endGeo.GetSegmentGeometry(true);

                    if (segGeo.IsValid())
                    {
                        junctionRestrictionsManager.HandleValidSegment(segGeo);
                    }
                }

                if (geometry.CurrentSegmentReplacement.oldSegmentEndId != null && geometry.CurrentSegmentReplacement.newSegmentEndId != null)
                {
                    ISegmentEndId oldSegmentEndId = geometry.CurrentSegmentReplacement.oldSegmentEndId;
                    ISegmentEndId newSegmentEndId = geometry.CurrentSegmentReplacement.newSegmentEndId;

                    SegmentEndFlags flags;
                    if (oldSegmentEndId.StartNode)
                    {
                        flags = invalidSegmentFlags[oldSegmentEndId.SegmentId].startNodeFlags;
                        invalidSegmentFlags[oldSegmentEndId.SegmentId].startNodeFlags.Reset();
                    }
                    else
                    {
                        flags = invalidSegmentFlags[oldSegmentEndId.SegmentId].endNodeFlags;
                        invalidSegmentFlags[oldSegmentEndId.SegmentId].endNodeFlags.Reset();
                    }

                    if (!flags.IsDefault())
                    {
                        Log._Debug($"JunctionRestrictionsManager.NodeWatcher.HandleValidNode({geometry.NodeId}): Segment replacement detected: {oldSegmentEndId.SegmentId} -> {newSegmentEndId.SegmentId}\n" +
                                   $"Moving segmend end flags {flags} to new segment end."
                                   );

                        junctionRestrictionsManager.SetSegmentEndFlags(newSegmentEndId.SegmentId, newSegmentEndId.StartNode, flags);
                    }
                }
            }
コード例 #8
0
        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}");
                Invalidate();
                return;
            }

            for (int i = 0; i < MAX_NUM_SEGMENTS; ++i)
            {
                if (segmentEndGeo.Equals(SegmentEndGeometries[i]))
                {
                    SegmentEndGeometries[i] = null;
                    lastRemovedSegmentEndId = segmentEndGeo;
                }
            }

            if (calcMode == GeometryCalculationMode.Propagate)
            {
                RecalculateSegments(segmentEndGeo.SegmentId);
            }
            Recalculate();
        }
 public bool Equals(ISegmentEndId otherSegEndId)
 {
     return(otherSegEndId != null &&
            SegmentId == otherSegEndId.SegmentId &&
            StartNode == otherSegEndId.StartNode);
 }
コード例 #10
0
 public static SegmentEndGeometry Get(ISegmentEndId endId)
 {
     return(Get(endId.SegmentId, endId.StartNode));
 }
コード例 #11
0
 public bool UpdateSegmentEnd(ISegmentEndId endId)
 {
     return(UpdateSegmentEnd(endId.SegmentId, endId.StartNode));
 }
コード例 #12
0
 public void RemoveSegmentEnd(ISegmentEndId endId)
 {
     RemoveSegmentEnd(endId.SegmentId, endId.StartNode);
 }
コード例 #13
0
 public ISegmentEnd GetOrAddSegmentEnd(ISegmentEndId endId)
 {
     return(GetOrAddSegmentEnd(endId.SegmentId, endId.StartNode));
 }
コード例 #14
0
ファイル: ExtNode.cs プロジェクト: philatpeace/TrafMan
 public void Reset()
 {
     segmentIds.Clear();
     removedSegmentEndId = null;
 }
コード例 #15
0
ファイル: ExtNode.cs プロジェクト: philatpeace/TrafMan
 public ExtNode(ushort nodeId)
 {
     this.nodeId         = nodeId;
     segmentIds          = new HashSet <ushort>();
     removedSegmentEndId = null;
 }