public static bool HasDuplicateLines(IReadOnlyList <TreeLine> treeLines) { // Treelines are ordered, so we only need to compare with the previous element, not all elements in the tree TreeLine lastLine = null; using (var it = treeLines.GetEnumerator()) { if (it.MoveNext()) { lastLine = it.Current; } while (it.MoveNext()) { var treeLine = it.Current; if (treeLine.TextBytes.Span.SpanEquals(lastLine.TextBytes.Span)) { return(true); } lastLine = treeLine; } } return(false); }
public override void RenderElement(IRenderable element, Graphics graphics, Render render) { TreeLine line = element as TreeLine; if (line.Points == null || line.Points.Count < 2) { return; } base.RenderElement(element, graphics, render); }
//Implement a base rendering of an element public override void RenderShadow(IRenderable element, Graphics graphics, Render render) { TreeLine line = element as TreeLine; if (line.Points == null) { return; } if (line.Points.Count < 2) { return; } PointF startLocation = (PointF)line.Points[0]; PointF startReference = (PointF)line.Points[1]; PointF endLocation = (PointF)line.Points[line.Points.Count - 1]; PointF endReference = (PointF)line.Points[line.Points.Count - 2]; Layer layer = line.Layer; Pen shadowPen = new Pen(layer.ShadowColor); GraphicsPath shadowPath = line.GetPath(); shadowPen.Color = render.AdjustColor(layer.ShadowColor, 0, line.Opacity); //Save the current region Region current = graphics.Clip; graphics.TranslateTransform(layer.ShadowOffset.X, layer.ShadowOffset.Y); //Draw line if (layer.SoftShadows) { shadowPen.Color = Color.FromArgb(20, shadowPen.Color); graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality; } graphics.DrawPath(shadowPen, shadowPath); if (layer.SoftShadows) { graphics.CompositingQuality = render.CompositingQuality; graphics.SmoothingMode = line.SmoothingMode; } graphics.TranslateTransform(-layer.ShadowOffset.X, -layer.ShadowOffset.Y); }
public override void RenderAction(IRenderable element, Graphics graphics, ControlRender render) { TreeLine line = element as TreeLine; if (line.Points == null || line.Points.Count < 2) { return; } PointF startLocation = (PointF)line.Points[0]; PointF startReference = (PointF)line.Points[1]; PointF endLocation = (PointF)line.Points[line.Points.Count - 1]; PointF endReference = (PointF)line.Points[line.Points.Count - 2]; //Render element action base.RenderAction(element, graphics, render); }
//Implement a base rendering of an element selection public override void RenderSelection(IRenderable renderable, Graphics graphics, ControlRender render) { TreeLine line = renderable as TreeLine; if (line.Handles == null) { return; } SmoothingMode smoothing = graphics.SmoothingMode; graphics.SmoothingMode = SmoothingMode.AntiAlias; Handle previousHandle = null; SolidBrush brushWhite = new SolidBrush(Color.White); Pen pen = Singleton.Instance.SelectionStartPen; SolidBrush brush = Singleton.Instance.SelectionStartBrush; foreach (Handle handle in line.Handles) { if (previousHandle != null) { graphics.FillPath(brushWhite, previousHandle.Path); graphics.FillPath(brush, previousHandle.Path); graphics.DrawPath(pen, previousHandle.Path); pen = Singleton.Instance.SelectionPen; //Set to normal brush brush = Singleton.Instance.SelectionBrush; //Set to normal pen } previousHandle = handle; } graphics.FillPath(brushWhite, previousHandle.Path); graphics.FillPath(Singleton.Instance.SelectionEndBrush, previousHandle.Path); graphics.DrawPath(Singleton.Instance.SelectionEndPen, previousHandle.Path); graphics.SmoothingMode = smoothing; }
public frmTreeLine() { InitializeComponent(); Model model = diagram1.Model; diagram1.Model.SetSize(new Size(1000, 1000)); Shape shape = new Shape(); shape.Location = new PointF(300, 50); model.Shapes.Add("a1", shape); shape = new Shape(); shape.Location = new PointF(200, 200); model.Shapes.Add("b1", shape); shape = new Shape(); shape.Location = new PointF(400, 200); model.Shapes.Add("b2", shape); shape = new Shape(); shape.Location = new PointF(100, 300); model.Shapes.Add("c1", shape); shape = new Shape(); shape.Location = new PointF(200, 300); model.Shapes.Add("c2", shape); shape = new Shape(); shape.Location = new PointF(300, 300); model.Shapes.Add("c3", shape); shape = new Shape(); shape.Location = new PointF(400, 300); model.Shapes.Add("c4", shape); shape = new Shape(); shape.Location = new PointF(500, 300); model.Shapes.Add("c5", shape); //Add tree lines Link line = new Link(); TreeLine treeLine = new TreeLine(); treeLine.AddStart(model.Shapes["a1"]); treeLine.AddEnd(model.Shapes["b1"]); treeLine.AddEnd(model.Shapes["b2"]); model.Lines.Add(treeLine); treeLine = new TreeLine(); treeLine.AddStart(model.Shapes["b1"]); treeLine.AddEnd(model.Shapes["c1"]); treeLine.AddEnd(model.Shapes["c2"]); treeLine.AddEnd(model.Shapes["c3"]); model.Lines.Add(treeLine); treeLine = new TreeLine(); treeLine.AddStart(model.Shapes["b2"]); treeLine.AddEnd(model.Shapes["c4"]); treeLine.AddEnd(model.Shapes["c5"]); model.Lines.Add(treeLine); model.ApplyTheme(Themes.LightBlue); foreach (Shape item in model.Shapes.Values) { item.Width = 60; } }