NodeAttr CreateNodeAttr(string id, bool isSelected) { NodeTypeEntry nte = Model.GraphEditor.NodeTypes.Last(); NodeAttr nodeAttr = new NodeAttr(); nodeAttr.Id = id; nodeAttr.Color = Styles.NODE_LINE_COLOR.ToMsAgl(); if (Entity.Virtual) { nodeAttr.FillColor = Styles.NODE_BGCOLOR_VIRTUAL.ToMsAgl(); } else if (Entity.Abstract) { nodeAttr.FillColor = Styles.NODE_BGCOLOR_ABSTRACT.ToMsAgl(); } else { nodeAttr.FillColor = Styles.NODE_BGCOLOR_NORMAL.ToMsAgl(); } if (isSelected) { nodeAttr.Color = Styles.SELECTED_NODE_LINE_COLOR.ToMsAgl(); } nodeAttr.Shape = nte.Shape; nodeAttr.LabelMargin = 8; nodeAttr.LineWidth = 4; return(nodeAttr); }
public static NodeAttr Copy(this NodeAttr attr, NodeAttr newAttr) { attr.Shape = newAttr.Shape; attr.Color = newAttr.Color; attr.FillColor = newAttr.FillColor; return(attr); }
/// <summary> /// Set the attributes of the nodes in the graph /// </summary> /// <param name="attribute">Attribute to be set on all nodes in the graph</param> public static void SetNodeAttribute(this Graph graph, NodeAttr attribute) { foreach (var node in graph.Nodes) { node.Attr = attribute.Clone(); } }
static void ApplyVertexStyle(NodeAttr attr, Type type) { if (type.IsGenericType) { Type openType = type.GetGenericTypeDefinition(); if (openType == typeof(TypedChannelAdapter <>)) { attr.Shape = Shape.Diamond; attr.Fillcolor = Microsoft.Glee.Drawing.Color.Blue; } else if (openType == typeof(BroadcastChannel <>)) { attr.Shape = Shape.Octagon; attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow; attr.Fontcolor = Microsoft.Glee.Drawing.Color.Black; } else if (openType == typeof(IntervalChannel <>) || openType == typeof(DistinctChannel <,>) || openType == typeof(ConvertChannel <,>) || openType == typeof(LastChannel <>)) { attr.Shape = Shape.Ellipse; attr.Fillcolor = Microsoft.Glee.Drawing.Color.PowderBlue; attr.Fontcolor = Microsoft.Glee.Drawing.Color.Black; } else if (openType == typeof(FilterChannel <>)) { attr.Shape = Shape.Ellipse; attr.Fillcolor = Microsoft.Glee.Drawing.Color.YellowGreen; attr.Fontcolor = Microsoft.Glee.Drawing.Color.Black; } else if (openType == typeof(ConsumerChannel <>) || openType == typeof(InstanceChannel <>)) { attr.Shape = Shape.Ellipse; attr.Fillcolor = Microsoft.Glee.Drawing.Color.Green; } else if (openType == typeof(InstanceChannelProvider <,>)) { attr.Shape = Shape.Diamond; attr.Fillcolor = Microsoft.Glee.Drawing.Color.Purple; } } else { if (type == typeof(ChannelAdapter)) { attr.Fillcolor = Microsoft.Glee.Drawing.Color.Orange; } else if (type == typeof(BroadcastChannel)) { attr.Shape = Shape.Octagon; attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow; attr.Fontcolor = Microsoft.Glee.Drawing.Color.Black; } } }
internal static void DrawEllipse(Canvas g, Brush pen, DNode dNode) { var node = dNode.DrawingNode; NodeAttr nodeAttr = node.Attr; var x = (float)(node.GeometryNode.Center.X - node.Width / 2.0); var y = (float)(node.GeometryNode.Center.Y - node.Height / 2.0); var width = (float)node.Width; var height = (float)node.Height; DrawEllipseOnPosition(dNode, nodeAttr, g, x, y, width, height, pen); }
static void DrawEllipseOnPosition(DNode dNode, NodeAttr nodeAttr, Canvas g, float x, float y, float width, float height, Brush pen) { throw new NotImplementedException(); /* * if (NeedToFill(dNode.FillColor)) * g.FillEllipse(new SolidBrush(dNode.FillColor), x, y, width, height); * if (nodeAttr.Shape == Shape.Point) * g.FillEllipse(new SolidBrush(pen.Color), x, y, width, height); * * g.DrawEllipse(pen, x, y, width, height); //*/ }
protected void WriteFill(NodeAttr attr) { var color = attr.FillColor; if (color.A == 0 && !attr.Styles.Contains(Style.Filled)) { writer.WriteAttribute("fill", "none"); } else { writer.WriteAttribute("fill", color); writer.WriteAttribute("fill-opacity", color); } }
private static void FillTheGraphicsPath(NodeAttr nodeAttr, float width, float height, ref float xRadius, ref float yRadius, GraphicsPath path) { float w = (float)(width / 2); if (xRadius > w) { xRadius = w; } float h = (float)(height / 2); if (yRadius > h) { yRadius = h; } float x = (float)nodeAttr.Pos.X; float y = (float)nodeAttr.Pos.Y; float ox = w - xRadius; float oy = h - yRadius; float top = y + h; float bottom = y - h; float left = x - w; float right = x + w; const float PI = 180; if (ox > 0) { path.AddLine(x - ox, bottom, x + ox, bottom); } path.AddArc(x + ox - xRadius, y - oy - yRadius, 2 * xRadius, 2 * yRadius, 1.5f * PI, 0.5f * PI); if (oy > 0) { path.AddLine(right, y - oy, right, y + oy); } path.AddArc(x + ox - xRadius, y + oy - yRadius, 2 * xRadius, 2 * yRadius, 0, 0.5f * PI); if (ox > 0) { path.AddLine(x + ox, top, x - ox, top); } path.AddArc(x - ox - xRadius, y + oy - yRadius, 2 * xRadius, 2 * yRadius, 0.5f * PI, 0.5f * PI); if (oy > 0) { path.AddLine(left, y + oy, left, y - oy); } path.AddArc(x - ox - xRadius, y - oy - yRadius, 2 * xRadius, 2 * yRadius, PI, 0.5f * PI); }
internal static void DrawFromMsaglCurve(Graphics g, Pen pen, DNode dNode) { NodeAttr attr = dNode.DrawingNode.Attr; Curve c = (Curve)attr.GeometryNode.BoundaryCurve; GraphicsPath p = new GraphicsPath(); foreach (ICurve seg in c.Segments) { AddSegToPath(seg, ref p); } if (NeedToFill(dNode.FillColor)) { g.FillPath(new SolidBrush(dNode.FillColor), p); } g.DrawPath(pen, p); }
static internal void DrawEllipse(Graphics g, Pen pen, DNode dNode) { NodeAttr nodeAttr = dNode.DrawingNode.Attr; double x = (double)nodeAttr.Pos.X - (double)nodeAttr.Width / 2.0f; double y = (double)nodeAttr.Pos.Y - (double)nodeAttr.Height / 2.0f; if (NeedToFill(dNode.FillColor)) { g.FillEllipse(new SolidBrush(dNode.FillColor), (float)x, (float)y, (float)nodeAttr.Width, (float)nodeAttr.Height); } if (nodeAttr.Shape == Shape.Point) { g.FillEllipse(new SolidBrush(pen.Color), (float)x, (float)y, (float)nodeAttr.Width, (float)nodeAttr.Height); } g.DrawEllipse(pen, (float)x, (float)y, (float)nodeAttr.Width, (float)nodeAttr.Height); }
static internal void DrawDiamond(Graphics g, Pen pen, DNode dNode) { NodeAttr nodeAttr = dNode.DrawingNode.Attr; double w2 = (double)nodeAttr.Width / 2.0f; double h2 = (double)nodeAttr.Height / 2.0f; double cx = (double)nodeAttr.Pos.X; double cy = (double)nodeAttr.Pos.Y; System.Drawing.PointF[] ps = new System.Drawing.PointF[] { new PointF((float)cx - (float)w2, (float)cy), new PointF((float)cx, (float)cy + (float)h2), new PointF((float)cx + (float)w2, (float)cy), new PointF((float)cx, (float)cy - (float)h2) }; if (NeedToFill(dNode.FillColor)) { System.Drawing.Color fc = FillColor(nodeAttr); g.FillPolygon(new SolidBrush(fc), ps); } g.DrawPolygon(pen, ps); }
static internal void DrawDoubleCircle(Graphics g, Pen pen, DNode dNode) { NodeAttr nodeAttr = dNode.DrawingNode.Attr; double x = (double)nodeAttr.Pos.X - (double)nodeAttr.Width / 2.0f; double y = (double)nodeAttr.Pos.Y - (double)nodeAttr.Height / 2.0f; if (NeedToFill(dNode.FillColor)) { g.FillEllipse(new SolidBrush(dNode.FillColor), (float)x, (float)y, (float)nodeAttr.Width, (float)nodeAttr.Height); } g.DrawEllipse(pen, (float)x, (float)y, (float)nodeAttr.Width, (float)nodeAttr.Height); float w = (float)nodeAttr.Width; float h = (float)nodeAttr.Height; float m = Math.Max(w, h); float coeff = (float)1.0 - (float)(DoubleCircleOffsetRatio); x += coeff * m / 2.0; y += coeff * m / 2.0; g.DrawEllipse(pen, (float)x, (float)y, w - coeff * m, h - coeff * m); }
internal void CreateNode() { IsNodeSelected = false; if (Model == null) { return; } if (drawingNode != null) { IsNodeSelected = drawingNode.Attr.Color == Styles.SELECTED_NODE_LINE_COLOR.ToMsAgl(); DeleteNode(); } GeometryPoint center = new GeometryPoint(Xcoordinate ?? 0.0, Ycoordinate ?? 0.0); NodeAttr attr = CreateNodeAttr(Label, IsNodeSelected); if (Model.Graph != null) { drawingNode = Model.Graph.AddNode(Label); drawingNode.Attr = attr; drawingNode.Label.Text = Entity.Label; drawingNode.UserData = this; CreateNodeGeometry(drawingNode, Model.Graph, Model.GeometryGraph, center, ConnectionToGraph.Connected); } else { drawingNode = new DrawingNode(Label); drawingNode.Attr = attr; drawingNode.Label.Text = Entity.Label; drawingNode.UserData = this; IViewerNode viewerNode = Model.GraphEditor.Viewer.CreateIViewerNode(drawingNode, center, null); Model.GraphEditor.Viewer.AddNode(viewerNode, false); Model.GraphEditor.Viewer.Invalidate(viewerNode); } Model.AutoResize(); }
static internal void DrawBox(Graphics g, Pen pen, DNode dNode) { NodeAttr nodeAttr = dNode.DrawingNode.Attr; if (nodeAttr.XRadius == 0 || nodeAttr.YRadius == 0) { double x = (double)nodeAttr.Pos.X - (double)nodeAttr.Width / 2.0f; double y = (double)nodeAttr.Pos.Y - (double)nodeAttr.Height / 2.0f; if (NeedToFill(dNode.FillColor)) { System.Drawing.Color fc = FillColor(nodeAttr); g.FillRectangle(new SolidBrush(fc), (float)x, (float)y, (float)nodeAttr.Width, (float)nodeAttr.Height); } g.DrawRectangle(pen, (float)x, (float)y, (float)nodeAttr.Width, (float)nodeAttr.Height); } else { float width = (float)nodeAttr.Width; float height = (float)nodeAttr.Height; float xRadius = (float)nodeAttr.XRadius; float yRadius = (float)nodeAttr.YRadius; using (GraphicsPath path = new GraphicsPath()) { FillTheGraphicsPath(nodeAttr, width, height, ref xRadius, ref yRadius, path); if (NeedToFill(dNode.FillColor)) { g.FillPath(new SolidBrush(dNode.FillColor), path); } g.DrawPath(pen, path); } } }
private static void setNodeAttributes(NodeAttr attr, NodeType type) { NodeClass c = EnumUtils.getClassFromType(type); attr.Shape = Shape.Circle; switch (c) { case NodeClass.directive: attr.Color = Color.Black; attr.Shape = Shape.Box; break; case NodeClass.numeric: attr.Color = Color.Red; break; case NodeClass.boolean: attr.Color = Color.Blue; break; default: attr.Color = Color.Gray; break; } switch (type) { case NodeType.dirTerminal: attr.Shape = Shape.Diamond; break; case NodeType.NumInput: //attr.FillColor = Color.DarkGoldenrod; attr.Shape = Shape.DoubleCircle; break; } }
internal void DrawNode(Graphics g, DNode dnode) { DrawingNode node = dnode.DrawingNode; if (node.IsVisible == false) { return; } if (node.DrawNodeDelegate != null) { if (node.DrawNodeDelegate(node, g)) { return; //the client draws instead } } if (node.GeometryNode == null || node.GeometryNode.BoundaryCurve == null) //node comes with non-initilalized attribute - should not be drawn { return; } NodeAttr attr = node.Attr; using (var pen = new Pen(dnode.Color, (float)attr.LineWidth)) { foreach (Style style in attr.Styles) { Draw.AddStyleForPen(dnode, pen, style); } switch (attr.Shape) { case Shape.DoubleCircle: Draw.DrawDoubleCircle(g, pen, dnode); break; case Shape.Box: Draw.DrawBox(g, pen, dnode); break; case Shape.Diamond: Draw.DrawDiamond(g, pen, dnode); break; case Shape.Point: Draw.DrawEllipse(g, pen, dnode); break; case Shape.Plaintext: { break; //do nothing } case Shape.Octagon: case Shape.House: case Shape.InvHouse: case Shape.Ellipse: case Shape.DrawFromGeometry: #if DEBUG case Shape.TestShape: #endif pen.EndCap = LineCap.Square; Draw.DrawFromMsaglCurve(g, pen, dnode); break; default: Draw.DrawEllipse(g, pen, dnode); break; } } Draw.DrawLabel(g, dnode.Label); node.PostDrawNodeDelegate?.Invoke(node, g); }
private static System.Drawing.Color FillColor(NodeAttr nodeAttr) { return(MsaglColorToDrawingColor(nodeAttr.FillColor)); }
void WriteFillAndStroke(NodeAttr attr) { WriteFill(attr); WriteStroke(attr); }
private static void DrawBox(Graphics g, DrawingNode drNode) { NodeAttr nodeAttr = drNode.Attr; var settings = drNode.UserData as NodeDisplaySettings; // Create the shape. var width = (float)drNode.Width; var height = (float)drNode.Height; var xRadius = (float)nodeAttr.XRadius; var yRadius = (float)nodeAttr.YRadius; var path = new GraphicsPath(); FillTheGraphicsPath(drNode, width, height, ref xRadius, ref yRadius, path); // Select line width. var lineWidth = (float)drNode.Attr.LineWidth; if (settings.HasErrors) { lineWidth += 2; } if (settings.IsHighlighted) { lineWidth += 2; } // Set up line pen. Color lineColor; if (settings.HasErrors) { lineColor = Color.Red; } else if (settings.IsHighlighted) { lineColor = Color.Blue; } else { lineColor = Draw.MsaglColorToDrawingColor(drNode.Attr.Color); } if (settings.IsFadedOut) { lineColor = Color.FromArgb(128, lineColor.R, lineColor.G, lineColor.B); } var pen = new Pen(lineColor, lineWidth); // Set up fill brush. Brush brush; Color fillColor = Draw.MsaglColorToDrawingColor(nodeAttr.FillColor); if (settings.IsFadedOut) { fillColor = Color.FromArgb(128, fillColor.R, fillColor.G, fillColor.B); } if (settings.HasUnsavedChanges) { var hashColor = Color.FromArgb((int)(fillColor.R * 0.9f + 128 * 0.1f), (int)(fillColor.G * 0.9f + 128 * 0.1f), (int)(fillColor.B * 0.9f + 128 * 0.1f)); brush = new HatchBrush(HatchStyle.WideUpwardDiagonal, hashColor, fillColor); } else { brush = new SolidBrush(fillColor); } // Paint. g.FillPath(brush, path); g.DrawPath(pen, path); }
static Color FillColor(NodeAttr nodeAttr) { return(MsaglColorToDrawingColor(nodeAttr.FillColor)); }