Пример #1
0
 internal void AddRail(Rail rail)
 {
     if (AddRailToDictionary(rail))
     {
         AddRailToRtree(rail);
     }
 }
Пример #2
0
        internal void PutOffEdgesPassingThroughTheRail(Rail rail)
        {
            var railLevel    = levels[(int)Math.Log(rail.ZoomLevel, 2)];
            var passingEdges = railLevel.GetEdgesPassingThroughRail(rail);

            PutOffEdges(passingEdges);
        }
 public object GetNodeOrRailUnderMouse(RectangleGeometry rect) {
     _nodeUnderMouse = null;
     _railUnderMouse = null;
     VisualTreeHelper.HitTest(_graphCanvas, null,
         NodeOrRailHitTestSelOnlyOneNodeCallback,
         new GeometryHitTestParameters(rect));
     return (object)_nodeUnderMouse ?? _railUnderMouse;
 }
        HitTestResultBehavior RailHitTestSelOneResultCallback(HitTestResult result) {
            var frameworkElement = result.VisualHit as FrameworkElement;

            if (frameworkElement == null || !(frameworkElement.Tag is Rail))
                return HitTestResultBehavior.Continue;

            _railUnderMouse = frameworkElement.Tag as Rail;
            return HitTestResultBehavior.Stop;
        }
Пример #5
0
/*
 *      void HiglightEdge(Edge edge) {
 *          Set<Rail> railsOfEdge = null;
 *          //adding highlight for edge rails in each level
 *          for (int i = levels.Count - 1; i >= 0; i--) {
 *              var level = levels[i];
 *
 *              Set<Rail> railsOfEdgeOfLevelWithHigherZoom;
 *              if (level._railsOfEdges.TryGetValue(edge, out railsOfEdgeOfLevelWithHigherZoom)) {
 *                  railsOfEdge = railsOfEdgeOfLevelWithHigherZoom;
 *              }
 *              else {
 *                  //the edge is not represented at the level, so we are reusing the rails from the level above
 *                  level._railsOfEdges[edge] = railsOfEdge;
 *                  foreach (var rail1 in railsOfEdge)
 *                      AddRailToRailTreeOfLowerLevel(rail1, level);
 *              }
 *              foreach (var rail1 in railsOfEdge) //highlight every rail: does not matter new or old
 *                  rail1.HiglightCount ++;
 *          }
 *      }
 */

        static void AddRailToRailTreeOfLowerLevel(Rail rail, LgLevel lowerLevel)
        {
            var pt  = rail.PointTuple();
            var box = new Rectangle(pt.Item1, pt.Item2);

            if (!lowerLevel._railTree.Contains(box, rail))
            {
                lowerLevel._railTree.Add(box, rail);
            }
        }
Пример #6
0
        /// <summary>
        /// records the fact that the edge passes through the rail
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="rail"></param>
        public void AssociateEdgeAndRail(Edge edge, Rail rail)
        {
            Set <Rail> railSet;

            if (!_railsOfEdges.TryGetValue(edge, out railSet))
            {
                _railsOfEdges[edge] = railSet = new Set <Rail>();
            }
            railSet.Insert(rail);
        }
Пример #7
0
        public void RemoveRailFromDictionary(Rail rail)
        {
            Point p0, p1;

            if (!rail.GetStartEnd(out p0, out p1))
            {
                return;
            }
            _railDictionary.Remove(new SymmetricSegment(p0, p1));
        }
Пример #8
0
        public void AddRailToRtree(Rail rail)
        {
            Point p0, p1;

            if (!rail.GetStartEnd(out p0, out p1))
            {
                return;
            }
            if (_railTree.Contains(new Rectangle(p0, p1), rail))
            {
                return;
            }
            _railTree.Add(new Rectangle(p0, p1), rail);
        }
Пример #9
0
        void CreateStatisticsForRail(Rail rail)
        {
            var arrowhead = rail.Geometry as Arrowhead;

            if (arrowhead != null)
            {
                CreateStatisticsForArrowhead(arrowhead);
            }
            else
            {
                foreach (var t in GetCurveTiles(rail.Geometry as ICurve))
                {
                    t.rails++;
                }
            }
        }
Пример #10
0
        public Rail CreateRail(Point ep0, Point ep1)
        {
            var  st = new SymmetricSegment(ep0, ep1);
            Rail rail;

            if (RailDictionary.TryGetValue(st, out rail))
            {
                return(rail);
            }
            var ls = new LineSegment(ep0, ep1);

            rail = new Rail(ls, ZoomLevel);
            RailTree.Add(rail.BoundingBox, rail);
            RailDictionary.Add(st, rail);
            return(rail);
        }
Пример #11
0
        /// <summary>
        /// try adding single rail to dictionary
        /// </summary>
        /// <param name="rail"></param>
        /// <returns>true iff the rail does not belong to _railDictionary</returns>
        public bool AddRailToDictionary(Rail rail)
        {
            Point p0, p1;

            if (!rail.GetStartEnd(out p0, out p1))
            {
                return(false);
            }
            var st = new SymmetricSegment(p0, p1);

            if (!_railDictionary.ContainsKey(st))
            {
                _railDictionary.Add(st, rail);
                return(true);
            }
            return(false);
        }
Пример #12
0
        void RegisterElementaryRail(LgEdgeInfo edgeInfo, ICurve seg)
        {
            Rail rail;
            var  tuple = new Tuple <Point, Point>(seg.Start, seg.End);

            //was the seg registered before?
            if (_railDictionary.TryGetValue(tuple, out rail))
            {
                if (rail.TopRankedEdgeInfoOfTheRail.Rank < edgeInfo.Rank) //newcoming edgeInfo is more important
                {
                    rail.TopRankedEdgeInfoOfTheRail = edgeInfo;
                }
            }
            else
            {
                _railDictionary[tuple] = new Rail(seg, edgeInfo, ZoomLevel);
            }
        }
Пример #13
0
        void RegisterRailsForArrowheads(LgEdgeInfo edgeInfo)
        {
            var edgeGeom = edgeInfo.Edge.EdgeGeometry;

            if (edgeGeom.SourceArrowhead != null)
            {
                var  tuple = new Tuple <Point, Point>(edgeGeom.SourceArrowhead.TipPosition, edgeGeom.Curve.Start);
                Rail rail;
                if (_railDictionary.TryGetValue(tuple, out rail))
                {
                    if (rail.TopRankedEdgeInfoOfTheRail.Rank < edgeInfo.Rank) //the newcoming edgeInfo is more important
                    {
                        rail.TopRankedEdgeInfoOfTheRail = edgeInfo;
                    }
                }
                else
                {
                    _railDictionary[tuple] = new Rail(edgeGeom.SourceArrowhead, edgeGeom.Curve.Start, edgeInfo,
                                                      ZoomLevel);
                }
            }

            if (edgeGeom.TargetArrowhead != null)
            {
                var  tuple = new Tuple <Point, Point>(edgeGeom.TargetArrowhead.TipPosition, edgeGeom.Curve.End);
                Rail rail;
                if (_railDictionary.TryGetValue(tuple, out rail))
                {
                    if (rail.TopRankedEdgeInfoOfTheRail.Rank < edgeInfo.Rank) //the newcoming edgeInfo is more important
                    {
                        _railDictionary[tuple] = new Rail(edgeGeom.TargetArrowhead, edgeGeom.Curve.End, edgeInfo,
                                                          ZoomLevel);
                    }
                }
                else
                {
                    _railDictionary[tuple] = new Rail(edgeGeom.TargetArrowhead, edgeGeom.Curve.End, edgeInfo,
                                                      ZoomLevel);
                }
            }
        }
        HitTestResultBehavior NodeOrRailHitTestSelOnlyOneNodeCallback(HitTestResult result) {
            var frameworkElement = result.VisualHit as FrameworkElement;

            if (!(frameworkElement is Path))
                return HitTestResultBehavior.Continue;
            object tag = frameworkElement.Tag;
            if (tag != null) {
                GraphmapsNode graphmapsNode = tag as GraphmapsNode;
                if (graphmapsNode != null) {
                    _nodeUnderMouse = graphmapsNode;
                    return HitTestResultBehavior.Stop;
                }
                else {
                    var rail = frameworkElement.Tag as Rail;
                    if (rail != null)
                        _railUnderMouse = rail;
                }
            }

            return HitTestResultBehavior.Continue;
        }
 public Rail RemoveRailFromRtree(Rail rail) {
     return _railTree.Remove(rail.BoundingBox, rail);
 }
 internal void AddRail(Rail rail) {
     if (AddRailToDictionary(rail))
         AddRailToRtree(rail);
 }
        public FrameworkElement CreateFrameworkElementForRailArrowhead(Rail rail, Arrowhead arrowhead, Point curveAttachmentPoint, byte edgeTransparency) {
            var streamGeometry = new StreamGeometry();

            using (StreamGeometryContext context = streamGeometry.Open()) {
                AddArrow(context, curveAttachmentPoint, arrowhead.TipPosition,
                         PathStrokeThickness);
                //arrowhead.BasePoint = curveAttachmentPoint;

            }

            var path=new Path
            {
                Data = streamGeometry,
                Tag = this
            };

            SetPathStrokeToRailPath(rail, path);
            return path;
        }
Пример #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rail"></param>
 internal void HighlightEdgesPassingThroughTheRail(Rail rail)
 {
     lgData.HighlightEdgesPassingThroughRail(rail);
 }
        Brush SetStrokeColorForRail(Rail rail)
        {
            // road colors: Brushes.PaleVioletRed; Brushes.PaleGoldenrod; Brushes.White;
            WpfColor brush;
            //brush = rail.IsHighlighted == false
            //           ? new SolidColorBrush(new System.Windows.Media.Color {
            //               A = 255, //transparency,
            //               R = Edge.Attr.Color.R,
            //               G = Edge.Attr.Color.G,
            //               B = Edge.Attr.Color.B
            //           })
            //           : Brushes.Red;
            brush = rail.IsHighlighted ? Brushes.Red.Color : Brushes.SlateGray.Color;
            if (rail.TopRankedEdgeInfoOfTheRail == null) return new SolidColorBrush(brush);

            if (lgSettings != null)
            {
                var col = lgSettings.GetColorForZoomLevel(rail.MinPassingEdgeZoomLevel);
                brush = ((SolidColorBrush)(new BrushConverter().ConvertFrom(col))).Color;
            }
            else
            {
                if (rail.MinPassingEdgeZoomLevel <= 1) brush = Brushes.LightSkyBlue.Color; //Brushes.DimGray.Color;
                else if (rail.MinPassingEdgeZoomLevel <= 2)
                    brush = Brushes.LightGoldenrodYellow.Color; //Brushes.SlateGray.Color;
                else brush = Brushes.WhiteSmoke.Color; //Brushes.Gray.Color;
            }

            if (rail.IsHighlighted)
            {
                if (rail.MinPassingEdgeZoomLevel <= 1) brush = Brushes.Red.Color;
                else if (rail.MinPassingEdgeZoomLevel <= 2) brush = new WpfColor{A = 255, R=235, G=48, B=68};
                else brush = new WpfColor { A = 255, R = 229, G = 92, B = 127 };
            }

            return new SolidColorBrush(brush);
        }
        void UpdateRailZindex(FrameworkElement fe, Rail rail) {
            var railZindex = 50 - (int) Math.Log(rail.MinPassingEdgeZoomLevel, 2);
            if (rail.IsHighlighted)
                railZindex += 50;

            Panel.SetZIndex(fe, railZindex);
            //if (rail.IsHighlighted)
            //{
            //    Panel.SetZIndex(fe, 100);
            //}
            //else
            //{
            //    Panel.SetZIndex(fe, 50);
            //}
        }
        void CreateFrameworkElementForSkeletonRail(Rail rail) {
            var iCurve = rail.Geometry as ICurve;
            if (iCurve == null) return;
            var path = new Path
            {
                Data = GraphmapsEdge.GetICurveWpfGeometry(iCurve),
            };

            InvalidateSkeletonRail(rail, path);

            path.Tag = rail;
            GraphCanvasChildrenAdd(path);
            _visibleRailsToFrameworkElems[rail] = path;
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="rail"></param>
 public void PutOffEdgesPassingThroughTheRail(Rail rail)
 {
     Algorithm.PutOffEdgesPassingThroughTheRail(rail);
 }
Пример #23
0
 internal bool TheRailLevelIsTooHigh(Rail rail)
 {
     return(lgData.GetRelevantEdgeLevel(rail.ZoomLevel) > lgData.GetRelevantEdgeLevel(GetZoomFactorToTheGraph()));
 }
Пример #24
0
 public Rail RemoveRailFromRtree(Rail rail)
 {
     return(_railTree.Remove(rail.BoundingBox, rail));
 }
Пример #25
0
 internal List <Edge> GetEdgesPassingThroughRail(Rail rail)
 {
     return((from kv in _railsOfEdges where kv.Value.Contains(rail) select kv.Key).ToList());
 }
Пример #26
0
 internal void PutOffEdgesPassingThroughTheRail(Rail rail)
 {
     lgData.PutOffEdgesPassingThroughTheRail(rail);
 }
        void CreateOrInvalidateFrameworksElementForVisibleRailWithoutChangingGeometry(Rail rail) {
            FrameworkElement fe;
            GraphmapsEdge vEdgeOfRail = GetVEdgeOfRail(rail);
            if (vEdgeOfRail == null) {
                CreateOrInvalidateFrameworkElementForSkeletonRail(rail);
                return; // skeleton rails
            }
            if (_visibleRailsToFrameworkElems.TryGetValue(rail, out fe)) {
                // added
                fe.Visibility = Visibility.Visible;

                vEdgeOfRail.Invalidate(fe, rail);
                // added
                UpdateRailZindex(fe, rail);
            }
            else {
                fe = vEdgeOfRail.CreateFrameworkElementForRail(rail);
                GraphCanvasChildrenAdd(fe);
                _visibleRailsToFrameworkElems[rail] = fe;

                // added
                UpdateRailZindex(fe, rail);
            }
        }
 GraphmapsEdge GetVEdgeOfRail(Rail rail) {
     if (rail.TopRankedEdgeInfoOfTheRail == null) return null; // skeleton edge
     var dEdge = (DrawingEdge) rail.TopRankedEdgeInfoOfTheRail.Edge.UserData;
     IViewerObject vEdge;
     if (_drawingObjectsToIViewerObjects.TryGetValue(dEdge, out vEdge))
         return (GraphmapsEdge) vEdge;
     return null;
 }
 void CreateOrInvalidateFrameworkElementForSkeletonRail(Rail rail) {
     FrameworkElement fe;
     if (_visibleRailsToFrameworkElems.TryGetValue(rail, out fe)) {
         var path = fe as Path;
         if (path == null) return;
         InvalidateSkeletonRail(rail, path);
         fe.Visibility = Visibility.Visible;
     }
     else {
         CreateFrameworkElementForSkeletonRail(rail);
     }
 }
        void HandleDoubleClickForRail(Rail rail) {
            
            if (SelectedNodeInfos.Any()) {
                _lgLayoutSettings.Interactor.SelectTopEdgePassingThroughRailWithEndpoint(rail, SelectedNodeInfos);
            }
            else if (rail.IsHighlighted) {}
                //PutOffEdgesPassingThroughTheRail(rail);
                //SelectAllRailsOfEdgesPassingThroughRail(rail, false);
            else
                //HighlightAllEdgesPassingThroughTheRail(rail);
                //SelectAllRailsOfEdgesPassingThroughRail(rail, true);
            {
                if (rail.TopRankedEdgeInfoOfTheRail != null) {
                    _lgLayoutSettings.Interactor.SelectEdge(rail.TopRankedEdgeInfoOfTheRail);
                }
            }

            ViewChangeEvent(null, null);
        }
 void InvalidateSkeletonRail(Rail rail, Path path) {
     path.StrokeThickness = rail.IsUsedOnPreviousLevel ? 2*GetBorderPathThickness() : GetBorderPathThickness();
     path.Stroke = (rail.IsHighlighted
         ? Brushes.Red
         : (rail.IsUsedOnPreviousLevel ? Brushes.SeaGreen : Brushes.Blue));
     UpdateRailZindex(path, rail);
 }
 internal void Invalidate(FrameworkElement fe, Rail rail) {
     var path = fe as Path;
     if (path != null)
         SetPathStrokeToRailPath(rail, path);
 }
 void RemoveRail(Rail rail) {
     _graphCanvas.Children.Remove(_visibleRailsToFrameworkElems[rail]);
     _visibleRailsToFrameworkElems.Remove(rail);
 }
 public void RemoveRailFromDictionary(Rail rail) {
     Point p0, p1;
     if (!rail.GetStartEnd(out p0, out p1)) return;
     _railDictionary.Remove(new SymmetricSegment(p0, p1));
 }
 void SetRailSelection(Rail rail, bool selected) {
     if (selected) {
         _selectedRails.Insert(rail);
     }
     else {
         _selectedRails.Remove(rail);
     }
     rail.IsHighlighted = selected;
 }
/*
        void HiglightEdge(Edge edge) {
            Set<Rail> railsOfEdge = null;
            //adding highlight for edge rails in each level
            for (int i = levels.Count - 1; i >= 0; i--) {                
                var level = levels[i];

                Set<Rail> railsOfEdgeOfLevelWithHigherZoom;
                if (level._railsOfEdges.TryGetValue(edge, out railsOfEdgeOfLevelWithHigherZoom)) {
                    railsOfEdge = railsOfEdgeOfLevelWithHigherZoom;
                }
                else {
                    //the edge is not represented at the level, so we are reusing the rails from the level above
                    level._railsOfEdges[edge] = railsOfEdge;
                    foreach (var rail1 in railsOfEdge)
                        AddRailToRailTreeOfLowerLevel(rail1, level);
                }
                foreach (var rail1 in railsOfEdge) //highlight every rail: does not matter new or old
                    rail1.HiglightCount ++;
            }
        }
*/

        static void AddRailToRailTreeOfLowerLevel(Rail rail, LgLevel lowerLevel) {
            var pt = rail.PointTuple();
            var box = new Rectangle(pt.Item1, pt.Item2);
            if (!lowerLevel._railTree.Contains(box, rail))
                lowerLevel._railTree.Add(box, rail);
        }
        public void SetPathStrokeToRailPath(Rail rail, Path path) {
            
            path.Stroke = SetStrokeColorForRail(rail);

            double thickness = 1.0;
            if (rail.TopRankedEdgeInfoOfTheRail != null)
            {
                thickness = Math.Max(5 - Math.Log(rail.MinPassingEdgeZoomLevel, 2), 1);
            }

            path.StrokeThickness = thickness * PathStrokeThickness / 2; // todo : figure out a way to do it nicer than dividing by 2

            foreach (var style in Edge.Attr.Styles) {
                if (style == Drawing.Style.Dotted) {
                    path.StrokeDashArray = new DoubleCollection {1, 1};
                } else if (style == Drawing.Style.Dashed) {
                    var f = DashSize();
                    path.StrokeDashArray = new DoubleCollection {f, f};
                    //CurvePath.StrokeDashOffset = f;
                }
            }
        }
 public void AddRailToRtree(Rail rail) {
     Point p0, p1;
     if (!rail.GetStartEnd(out p0, out p1)) return;
     if (_railTree.Contains(new Rectangle(p0, p1), rail))
         return;
     _railTree.Add(new Rectangle(p0, p1), rail);
 }
 public FrameworkElement CreateFrameworkElementForRail(Rail rail) {
     var iCurve = rail.Geometry as ICurve;
     Path fe = null;
     if (iCurve != null) {
         fe = (Path)CreateFrameworkElementForRailCurve(rail, iCurve);
         // test: rounded ends
         fe.StrokeEndLineCap = PenLineCap.Round;
         fe.StrokeStartLineCap = PenLineCap.Round;
         fe.Tag = rail;
     }            
     return fe;
 }
 void WriteRail(Rail rail, int railId) {
     WriteStartElement(GeometryToken.Rail);
     WriteAttribute(GeometryToken.Id, railId);
     WriteAttribute(GeometryToken.Zoomlevel, rail.ZoomLevel);
     if (rail.MinPassingEdgeZoomLevel != Double.MaxValue)
         WriteAttribute(GeometryToken.MinPassingEdgeZoomLevel, rail.MinPassingEdgeZoomLevel);
     Arrowhead ah = rail.Geometry as Arrowhead;
     if (ah != null) {
         WriteStartElement(GeometryToken.Arrowhead);
         WriteAttribute(GeometryToken.ArrowheadPosition, ah.TipPosition);
         WriteAttribute(GeometryToken.CurveAttachmentPoint, rail.CurveAttachmentPoint);
         WriteEndElement();
     }
     else {
         ICurve curve = rail.Geometry as ICurve;
         if (curve != null)
             WriteICurve(curve);
         else
             throw new InvalidOperationException();
     }
     WriteEndElement();
 }
 FrameworkElement CreateFrameworkElementForRailCurve(Rail rail, ICurve iCurve) {
     var path = new Path
     {
         Data = GetICurveWpfGeometry(iCurve),
     };
     SetPathStrokeToRailPath(rail, path);
     return path;
 }
 /// <summary>
 /// try adding single rail to dictionary
 /// </summary>
 /// <param name="rail"></param>
 /// <returns>true iff the rail does not belong to _railDictionary</returns>
 public bool AddRailToDictionary(Rail rail) {
     Point p0, p1;
     if (!rail.GetStartEnd(out p0, out p1)) return false;
     var st = new SymmetricSegment(p0, p1);
     if (!_railDictionary.ContainsKey(st)) {
         _railDictionary.Add(st, rail);
         return true;
     }
     return false;
 }
 internal void PutOffEdgesPassingThroughTheRail(Rail rail) {
     var railLevel = _levels[(int)Math.Log(rail.ZoomLevel, 2)];
     var passingEdges = railLevel.GetEdgesPassingThroughRail(rail);
     UnselectEdges(passingEdges);
 }
 void CreateStatisticsForRail(Rail rail) {
     var arrowhead = rail.Geometry as Arrowhead;
     if (arrowhead != null)
         CreateStatisticsForArrowhead(arrowhead);
     else
         foreach (var t in GetCurveTiles(rail.Geometry as ICurve))
             t.rails++;
 }
 public Rail GetOneRailInsideRect(RectangleGeometry rect) {
     _railUnderMouse = null;
     VisualTreeHelper.HitTest(_graphCanvas, null,
         RailHitTestSelOneResultCallback,
         new GeometryHitTestParameters(rect));
     return _railUnderMouse;
 }
 static bool RailBelongsToLevel(LgLevel level, Rail rail) {
     return level.ZoomLevel >= rail.ZoomLevel;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="rail"></param>
 public void HighlightEdgesPassingThroughTheRail(Rail rail)
 {
     Algorithm.HighlightEdgesPassingThroughTheRail(rail);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="rail"></param>
 /// <returns></returns>
 public bool TheRailLevelIsTooHigh(Rail rail)
 {
     return(Algorithm.TheRailLevelIsTooHigh(rail));
 }
Пример #49
0
 static bool RailBelongsToLevel(LgLevel level, Rail rail)
 {
     return(level.ZoomLevel >= rail.ZoomLevel);
 }
 internal List<Edge> GetEdgesPassingThroughRail(Rail rail) {
     return (from kv in _railsOfEdges where kv.Value.Contains(rail) select kv.Key).ToList();
 }