void WriteFromMsaglCurve(Node node) { NodeAttr attr = node.Attr; var iCurve = node.GeometryNode.BoundaryCurve; var c = iCurve as Curve; if (c != null) { WriteCurve(c, node); } else { var ellipse = iCurve as Ellipse; if (ellipse != null)//a bug when the axis are rotated { WriteEllipseOnPosition(node.Attr, ellipse.Center, ellipse.AxisA.Length, ellipse.AxisB.Length); } else { var poly = iCurve as Polyline; if (poly != null) { WritePolyline(poly, attr); } else { throw new NotImplementedException(); } } } }
void WriteEllipseOnPosition(NodeAttr nodeAttr, Point center, double rx, double ry) { WriteStartElement("ellipse"); WriteFill(nodeAttr); WriteStroke(nodeAttr); WriteFullEllipseGeometry(center, rx, ry); WriteEndElement(); }
/// <summary> /// a helper function to creat a node boundary curve /// </summary> /// <param name="node">the node</param> /// <param name="width">the node width</param> /// <param name="height">the node height</param> /// <returns></returns> public static ICurve GetNodeBoundaryCurve(Node node, double width, double height) { if (node == null) { throw new InvalidOperationException(); } NodeAttr nodeAttr = node.Attr; switch (nodeAttr.Shape) { case Shape.Ellipse: case Shape.DoubleCircle: return(CurveFactory.CreateEllipse(width, height, new P2(0, 0))); case Shape.Circle: { double r = Math.Max(width / 2, height / 2); return(CurveFactory.CreateEllipse(r, r, new P2(0, 0))); } case Shape.Box: if (nodeAttr.XRadius != 0 || nodeAttr.YRadius != 0) { return(CurveFactory.CreateRectangleWithRoundedCorners( width, height, nodeAttr.XRadius, nodeAttr.YRadius, new P2(0, 0))); } return(CurveFactory.CreateRectangle(width, height, new P2(0, 0))); case Shape.Diamond: return(CurveFactory.CreateDiamond(width, height, new P2(0, 0))); case Shape.House: return(CurveFactory.CreateHouse(width, height, new P2())); case Shape.InvHouse: return(CurveFactory.CreateInvertedHouse(width, height, new P2())); case Shape.Octagon: return(CurveFactory.CreateOctagon(width, height, new P2())); #if DEBUG case Shape.TestShape: return(CurveFactory.CreateTestShape(width, height)); #endif default: { // Debug.WriteLine("creating ellipse for shape {0}",nodeAttr.Shape); return(new Ellipse( new P2(width / 2, 0), new P2(0, height / 2), new P2())); } } }
private void WriteNodeAttr(NodeAttr na) { WriteStartElement(Tokens.NodeAttribute); WriteBaseAttr(na); WriteColorElement(Tokens.Fillcolor, na.FillColor); WriteStringElement(Tokens.LabelMargin, na.LabelMargin); WriteStringElement(Tokens.Padding, na.Padding); WriteStringElement(Tokens.Shape, na.Shape); WriteStringElement(Tokens.XRad, na.XRadius); WriteStringElement(Tokens.YRad, na.YRadius); WriteEndElement(); }
/// <summary> /// Creates a Node instance /// </summary> /// <param name="id">node name</param> public Node(string id) { this.DefaultStyleKey = typeof(Node); Label = new Label(); Label.GeometryLabel = null; Label.Owner = this; Label.Text = id; // one can change the label text later - TJT: Huh??? Attr = new NodeAttr(); attr.Id = id; }
private void ReadNodeAttr(NodeAttr na) { CheckToken(Tokens.NodeAttribute); XmlRead(); ReadBaseAttr(na); na.FillColor = ReadColorElement(Tokens.Fillcolor); na.LabelMargin = ReadIntElement(Tokens.LabelMargin); na.Padding = ReadDoubleElement(Tokens.Padding); na.Shape = (Shape)Enum.Parse(typeof(Shape), ReadStringElement(Tokens.Shape), false); na.XRadius = ReadDoubleElement(Tokens.XRad); na.YRadius = ReadDoubleElement(Tokens.YRad); ReadEndElement(); }
void WriteFill(NodeAttr attr) { var color = attr.FillColor; if (color.A == 0 && !attr.Styles.Contains(Style.Filled)) { WriteAttribute("fill", "none"); } else { WriteAttribute("fill", MsaglColorToSvgColor(color)); WriteAttribute("fill-opacity", MsaglColorToSvgOpacity(color)); } }
void WriteDiamond(Node node) { NodeAttr nodeAttr = node.Attr; double w2 = node.GeometryNode.Width / 2.0f; double h2 = node.GeometryNode.Height / 2.0f; double cx = node.GeometryNode.Center.X; double cy = node.GeometryNode.Center.Y; var ps = new[] { new Point(cx - w2, cy), new Point(cx, cy + h2), new Point(cx + w2, cy), new Point(cx, cy - h2) }; DrawPolygon(node.Attr, ps); }
void ReadNodeContent() { XmlRead(); object userData = null; if (TokenIs(Tokens.UserData)) { userData = ReadUserData(); } var nodeAttr = new NodeAttr(); ReadNodeAttr(nodeAttr); var node = graph.AddNode(nodeAttr.Id); node.Label = null; node.Attr = nodeAttr; node.UserData = userData; ReadLabel(node); ReadEndElement(); }
Subgraph ReadSubgraphContent() { object userData = null; if (TokenIs(Tokens.UserData)) { userData = ReadUserData(); } var nodeAttr = new NodeAttr(); ReadNodeAttr(nodeAttr); var subgraph = new Subgraph(nodeAttr.Id) { Label = null, Attr = nodeAttr, UserData = userData }; ReadLabel(subgraph); ReadEndElement(); return(subgraph); }
void WriteFillAndStroke(NodeAttr attr) { WriteFill(attr); WriteStroke(attr); }
void WritePolyline(Polyline poly, NodeAttr attr) { throw new NotImplementedException(); }