public XNode(Node node, string category = null) { Node = node; _category = category; Border b = new Border(); double size = node.Label.Text.Length * 9; b.Width = size + 12; b.Height = size * 2 / 3 + 4; _visualObject = b; Brush strokeBrush = CommonX.BrushFromMsaglColor(Node.Attr.Color); if (category != null) { Brush brush = Categories.GetBrush(_category); if (brush != null) { strokeBrush = brush; } } BoundaryPath = new Path { //Data = CreatePathFromNodeBoundary(), Stroke = strokeBrush, Fill = CommonX.BrushFromMsaglColor(Node.Attr.FillColor), StrokeThickness = Node.Attr.LineWidth }; Node.Attr.LineWidthHasChanged += AttrLineWidthHasChanged; //Node.Attr.GeometryNode.LayoutChangeEvent += GeometryNodeBeforeLayoutChangeEvent; }
void AddArrow(Edge drawingEdge, StreamGeometryContext context, Point start, Point end, double lineWidthOfAttachedNode) { Point dir = end - start; double dl = dir.Length; double scaling = (dl < 12? 1 : 12 / dl) / _scale; Point new_start = end - (end - start) * scaling; //take into account the widths double delta = Math.Min(dl / 2, drawingEdge.Attr.LineWidth + lineWidthOfAttachedNode / 2); //dir *= (dl - delta) / dl; end = start + dir; dir = dir.Rotate(Math.PI / 2); Point s = dir * HalfArrowAngleTan * scaling; context.BeginFigure(CommonX.WpfPoint(start), true, true); context.LineTo(CommonX.WpfPoint(new_start), true, true); if (_category == "References") { double r = dl * scaling / 2; context.ArcTo(CommonX.WpfPoint(end), new Size(r, r), 0, true, SweepDirection.Clockwise, true, true); context.ArcTo(CommonX.WpfPoint(new_start), new Size(r, r), 0, true, SweepDirection.Clockwise, true, true); } else { context.LineTo(CommonX.WpfPoint(new_start + s), true, true); context.LineTo(CommonX.WpfPoint(end), true, true); context.LineTo(CommonX.WpfPoint(new_start - s), true, true); context.LineTo(CommonX.WpfPoint(new_start), true, true); } }
static void FillContexForPolyline(StreamGeometryContext context, Polyline poly) { for (PolylinePoint pp = poly.StartPoint.Next; pp != null; pp = pp.Next) { context.LineTo(CommonX.WpfPoint(pp.Point), true, false); } }
Geometry CreateGeometryFromMsaglCurve(ICurve iCurve) { var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure { IsClosed = true, IsFilled = true }; Point c = Node.Attr.GeometryNode.Center; //we need to move the center to the origin, because the node position is later shifted to the center pathFigure.StartPoint = CommonX.WpfPoint(iCurve.Start - c); var curve = iCurve as Curve; if (curve != null) { AddCurve(pathFigure, c, curve); } else { var rect = iCurve as RoundedRect; if (rect != null) { AddCurve(pathFigure, c, rect.Curve); } else { throw new Exception(); } } pathGeometry.Figures.Add(pathFigure); return(pathGeometry); }
private Rectangle CreateDescription(Point origin, out Visual visual) { if (_vsGraphNodeInfo != null) { DrawingVisual desc = new DrawingVisual(); DrawingContext context = desc.RenderOpen(); string properties = ""; foreach (KeyValuePair <GraphProperty, object> kvp in _vsGraphNodeInfo.Properties) { string name = kvp.Key.ToString(); bool value = (kvp.Value is bool && ((bool)kvp.Value) == true); if (name.StartsWith("CodeSchemaProperty_Is") && value) { properties += (properties.Length > 0 ? " : " : "") + name.Replace("CodeSchemaProperty_Is", ""); } } FormattedText fText = new FormattedText(properties, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Calibri"), _fontSize * 0.8, Brushes.Black); fText.SetFontStyle(FontStyles.Italic); fText.TextAlignment = TextAlignment.Center; context.DrawText(fText, CommonX.WpfPoint(origin)); context.Close(); _textMeasurer.FontSize = _fontSize * 0.8; _textMeasurer.Text = properties; Size size = CommonX.Measure(_textMeasurer); visual = desc; return(new Rectangle(origin.X - size.Width / 2, origin.Y, origin.X + size.Width / 2, origin.Y + size.Height)); } visual = null; return(new Rectangle()); }
Geometry CreateGeometryFromMsaglCurve(ICurve iCurve) { var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure { IsClosed = true, IsFilled = true, StartPoint = CommonX.WpfPoint(iCurve.Start) }; var curve = iCurve as Curve; if (curve != null) { AddCurve(pathFigure, curve); } else { var rect = iCurve as RoundedRect; if (rect != null) { AddCurve(pathFigure, rect.Curve); } else { throw new Exception(); } } pathGeometry.Figures.Add(pathFigure); return(pathGeometry); }
void CreateBackgroundRectangle(GeometryGraph geomGraph) { rectToFillGraphBackground = new System.Windows.Shapes.Rectangle(); SetBackgroundRectanglePositionAndSize(geomGraph); rectToFillGraphBackground.Fill = CommonX.BrushFromMsaglColor(drawingGraph.Attr.BackgroundColor); Panel.SetZIndex(rectToFillGraphBackground, -1); graphCanvas.Children.Add(rectToFillGraphBackground); }
private Rectangle CreateTitle(Point origin, out Visual visual) { DrawingVisual title = new DrawingVisual(); DrawingContext context = title.RenderOpen(); FormattedText fText = new FormattedText(Node.LabelText, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Calibri"), _fontSize, Brushes.Black); context.DrawText(fText, CommonX.WpfPoint(origin)); context.Close(); visual = title; _textMeasurer.FontSize = _fontSize; _textMeasurer.Text = Node.LabelText; Size size = CommonX.Measure(_textMeasurer); return(new Rectangle(origin.X, origin.Y, origin.X + size.Width, origin.Y + size.Height)); }
internal void FillContextForICurve(StreamGeometryContext context, ICurve iCurve) { if (iCurve == null) { return; } context.BeginFigure(CommonX.WpfPoint(iCurve.Start), false, false); var c = iCurve as Curve; if (c != null) { FillContexForCurve(context, c); } else { var cubicBezierSeg = iCurve as CubicBezierSegment; if (cubicBezierSeg != null) { context.BezierTo(CommonX.WpfPoint(cubicBezierSeg.B(1)), CommonX.WpfPoint(cubicBezierSeg.B(2)), CommonX.WpfPoint(cubicBezierSeg.B(3)), true, false); } else { var ls = iCurve as LineSegment; if (ls != null) { context.LineTo(CommonX.WpfPoint(ls.End), true, false); } else { var rr = iCurve as RoundedRect; if (rr != null) { FillContexForCurve(context, rr.Curve); } else { var poly = iCurve as Polyline; FillContexForPolyline(context, poly); } } } } }
static void FillContexForCurve(StreamGeometryContext context, Curve c) { foreach (ICurve seg in c.Segments) { var bezSeg = seg as CubicBezierSegment; if (bezSeg != null) { context.BezierTo(CommonX.WpfPoint(bezSeg.B(1)), CommonX.WpfPoint(bezSeg.B(2)), CommonX.WpfPoint(bezSeg.B(3)), true, false); } else { var ls = seg as LineSegment; if (ls != null) { context.LineTo(CommonX.WpfPoint(ls.End), true, false); } else { var ellipse = seg as Ellipse; if (ellipse != null) { // context.LineTo(Common.WpfPoint(ellipse.End),true,false); double sweepAngle = EllipseSweepAngle(ellipse); bool largeArc = Math.Abs(sweepAngle) >= Math.PI; Rectangle box = ellipse.FullBox(); context.ArcTo(CommonX.WpfPoint(ellipse.End), new Size(box.Width / 2, box.Height / 2), sweepAngle, largeArc, sweepAngle < 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise, true, true); } else { throw new NotImplementedException(); } } } } }
public void Invalidate(double scale = 1) { if (BoundaryCurveIsDirty) { BoundaryPath.Data = CreatePathFromNodeBoundary(); BoundaryCurveIsDirty = false; } double node_scale = Scale(); Rectangle bounds = LgNodeInfo.OriginalCurveOfGeomNode.BoundingBox; Size real_size = new Size(bounds.Width * node_scale * scale, bounds.Height * node_scale * scale); if (node_scale < 0.5 && (real_size.Width < _fontSize || real_size.Height < _fontSize)) { _visualObject.LevelOfDetail = 0; } else { if (_visualObject.MaxLevelOfDetail == 0) { // First time becoming visible: generate visuals InitiateContainer(); Visual visual; Rectangle rect; rect = CreateIcon(new Point(), out visual); _visualObject.AddDetail(visual, rect); rect = CreateTitle(rect.RightBottom, out visual); _visualObject.AddDetail(visual, rect); rect = CreateDescription(new Point(rect.Center.X, rect.Top), out visual); _visualObject.AddDetail(visual, rect); } _visualObject.LevelOfDetail = _visualObject.MeasureLevelOfDetail(real_size); CommonX.PositionElement(_visualObject, _visualObject.BoundingBox, Node.BoundingBox, 1 / scale); } }
public XLabel(Edge edge) { if (false) { TextBlock tb = null; if (edge.Label != null) { tb = new TextBlock { Text = edge.Label.Text }; System.Windows.Size size = CommonX.Measure(tb); tb.Width = size.Width; tb.Height = size.Height; CommonX.PositionElement(tb, edge.Label.Center, 1); } _visualObject = tb; } DrawingObject = edge; }
public XEdge(Edge edge, string category = null) { Edge = edge; _category = category; _strokePathThickness = edge.Attr.LineWidth; if (edge.Label != null) { XLabel label = new XLabel(edge); this.XLabel = label; _visualObject = label.VisualObject; } Path = new Path { Stroke = CommonX.BrushFromMsaglColor(edge.Attr.Color), StrokeThickness = _strokePathThickness, StrokeDashArray = EdgeCategories.GetDashArray(category), Tag = this }; }
static void AddCurve(PathFigure pathFigure, Point c, Curve curve) { foreach (ICurve seg in curve.Segments) { var ls = seg as LineSegment; if (ls != null) { pathFigure.Segments.Add(new System.Windows.Media.LineSegment(CommonX.WpfPoint(ls.End - c), true)); } else { var ellipse = seg as Ellipse; pathFigure.Segments.Add(new ArcSegment(CommonX.WpfPoint(ellipse.End - c), new Size(ellipse.AxisA.Length, ellipse.AxisB.Length), Point.Angle(new Point(1, 0), ellipse.AxisA), ellipse.ParEnd - ellipse.ParEnd >= Math.PI, !ellipse.OrientedCounterclockwise() ? SweepDirection.Counterclockwise : SweepDirection.Clockwise, true)); } } }
public XNode(Node node, GraphNode gnode = null) { Node = node; _vsGraphNodeInfo = gnode; _visualObject = new LevelOfDetailsContainer(); Brush strokeBrush = CommonX.BrushFromMsaglColor(Node.Attr.Color); _fill = CommonX.BrushFromMsaglColor(Node.Attr.FillColor); if (gnode != null) { if (gnode.Categories.Count() > 0) { _category = gnode.Categories.ElementAt(0).ToString().Replace("CodeSchema_", ""); _fill = NodeCategories.GetFill(_category); Brush brush = NodeCategories.GetStroke(_category); if (brush != null) { strokeBrush = brush; } } } BoundaryPath = new Path { //Data = CreatePathFromNodeBoundary(), Stroke = strokeBrush, Fill = _fill, StrokeThickness = Node.Attr.LineWidth, Tag = this }; BoundaryCurveIsDirty = true; Node.Attr.VisualsChanged += AttrLineWidthHasChanged; //Node.Attr.GeometryNode.LayoutChangeEvent += GeometryNodeBeforeLayoutChangeEvent; }
public void Invalidate(double scale = 1) { if (BoundaryCurveIsDirty) { BoundaryPath.Data = CreatePathFromNodeBoundary(); BoundaryCurveIsDirty = false; } PositionPath(Node.BoundingBox); var node_scale = Scale(); if (_visualObject != null) { if (node_scale < 0.5) { if (_visualObject.Visibility != Visibility.Hidden) { _visualObject.Visibility = Visibility.Hidden; BoundaryPath.Fill = BoundaryPath.Stroke; } } else { if (_visualObject.Visibility != Visibility.Visible) { _visualObject.Visibility = Visibility.Visible; BoundaryPath.Fill = CommonX.BrushFromMsaglColor(Node.Attr.FillColor); } if (_vTitle == null) { Grid g = new Grid(); ((Border)_visualObject).Child = g; g.Margin = new Thickness(4); g.VerticalAlignment = VerticalAlignment.Center; g.HorizontalAlignment = HorizontalAlignment.Center; g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); _vTitle = new TextBlock { Text = Node.Label.Text, Name = "Title" }; _vTitle.VerticalAlignment = VerticalAlignment.Center; g.Children.Add(_vTitle); Grid.SetColumn(_vTitle, 1); if (_category != null) { ImageSource src = Categories.GetIcon(_category); if (src != null) { _vIcon = new Image { Source = src }; _vIcon.VerticalAlignment = VerticalAlignment.Center; RenderOptions.SetBitmapScalingMode(_vIcon, BitmapScalingMode.HighQuality); g.Children.Add(_vIcon); } } } double fontSize = Math.Min(12 / (node_scale * scale), 12); _vTitle.FontSize = fontSize; if (_vIcon != null) { _vIcon.Width = fontSize * 2; } CommonX.PositionElement(_visualObject, Node.BoundingBox.Center, node_scale); } } }
Geometry GetEllipseGeometry() { return(new EllipseGeometry(CommonX.WpfPoint(Node.BoundingBox.Center), Node.BoundingBox.Width / 2, Node.BoundingBox.Height / 2)); }