private void WriteEdgeAttr(EdgeAttr edgeAttr) { WriteStartElement(Tokens.EdgeAttribute); WriteBaseAttr(edgeAttr); WriteStringElement(Tokens.EdgeSeparation, edgeAttr.Separation); WriteStringElement(Tokens.Weight, edgeAttr.Weight); WriteStringElement(Tokens.ArrowStyle, edgeAttr.ArrowheadAtSource); WriteStringElement(Tokens.ArrowStyle, edgeAttr.ArrowheadAtTarget); WriteStringElement(Tokens.ArrowheadLength, edgeAttr.ArrowheadLength); WriteEndElement(); }
private void ReadEdgeAttr(EdgeAttr edgeAttr) { CheckToken(Tokens.EdgeAttribute); XmlRead(); ReadBaseAttr(edgeAttr); edgeAttr.Separation = ReadIntElement(Tokens.EdgeSeparation); edgeAttr.Weight = ReadIntElement(Tokens.Weight); edgeAttr.ArrowheadAtSource = (ArrowStyle)Enum.Parse(typeof(ArrowStyle), ReadStringElement(Tokens.ArrowStyle), false); edgeAttr.ArrowheadAtTarget = (ArrowStyle)Enum.Parse(typeof(ArrowStyle), ReadStringElement(Tokens.ArrowStyle), false); edgeAttr.ArrowheadLength = (float)ReadDoubleElement(Tokens.ArrowheadLength); ReadEndElement(); }
private void WriteEdgeAttr(EdgeAttr edgeAttr) { WriteStartElement(Tokens.EdgeAttribute); WriteBaseAttr(edgeAttr); WriteStringElement(Tokens.EdgeSeparation, edgeAttr.Separation); WriteStringElement(Tokens.Weight, edgeAttr.Weight); WriteStringElement(Tokens.ArrowStyle, edgeAttr.ArrowheadAtSource); WriteStringElement(Tokens.ArrowStyle, edgeAttr.ArrowheadAtTarget); WriteStringElement(Tokens.ArrowheadLength, edgeAttr.ArrowheadLength); var d = edgeAttr.DefinedDrawDelegateName; WriteStringElement(Tokens.DefinedDrawDelegateName, d == null?"":d); WriteEndElement(); }
/// <summary> /// source id, label ,target id /// </summary> /// <param name="source"> cannot be null</param> /// <param name="labelText">label can be null</param> /// <param name="target">cannot be null</param> public Edge(string source, string labelText, string target) { if (String.IsNullOrEmpty(source) || String.IsNullOrEmpty(target)) { throw new InvalidOperationException("Creating an edge with null or empty source or target IDs"); } this.source = source; this.target = target; this.attr = new EdgeAttr(); if (!String.IsNullOrEmpty(labelText)) { this.Label = new Label(labelText); } }
/// <summary> /// creates a detached edge /// </summary> /// <param name="sourceNode"></param> /// <param name="targetNode"></param> /// <param name="connection">controls is the edge will be connected to the graph</param> public Edge(Node sourceNode, Node targetNode, ConnectionToGraph connection, EdgeAttr edgeAttr = null) : this(sourceNode.Id, null, targetNode.Id, edgeAttr) { this.SourceNode = sourceNode; this.TargetNode = targetNode; if (connection == ConnectionToGraph.Connected) { if (sourceNode == targetNode) { sourceNode.AddSelfEdge(this); } else { sourceNode.AddOutEdge(this); targetNode.AddInEdge(this); } } }
/// <summary> /// Setting attribute from values. /// </summary> /// <param name="arrayList"></param> /// <param name="edge"></param> /// <returns></returns> public static void AddEdgeAttrs(ArrayList arrayList, Edge edge) { var label = new Label(); var edgeAttr = new EdgeAttr(); foreach (AttributeValuePair attrVal in arrayList) { if (AddAttributeKeyVal(new CoupleLabelBaseAttr(label, edgeAttr), attrVal)) continue; switch (attrVal.attributeTypeEnum) { case AttributeTypeEnum.LabelLocation: var posData = (PosData) attrVal.val; var cpList = posData.ControlPoints as List<P2>; if (cpList != null) label.GeometryLabel.Center = cpList[0]; break; case AttributeTypeEnum.Arrowhead: edgeAttr.ArrowheadAtTarget = (ArrowStyle) attrVal.val; break; case AttributeTypeEnum.Id: edgeAttr.Id = attrVal.val as String; break; case AttributeTypeEnum.ArrowTail: edgeAttr.ArrowheadAtSource = (ArrowStyle) attrVal.val; break; case AttributeTypeEnum.RGBColor: edgeAttr.Color = StringToMsaglColor((string) attrVal.val); break; case AttributeTypeEnum.Label: label.Text = attrVal.val as String; break; case AttributeTypeEnum.Color: edgeAttr.Color = StringToMsaglColor((string) attrVal.val); break; case AttributeTypeEnum.Fontcolor: label.FontColor = StringToMsaglColor((string) attrVal.val); break; case AttributeTypeEnum.Pos: { posData = (PosData) attrVal.val; //consider creating a Microsoft.Msagl.Splines.ICurve here InitGeomEdge(edge); if (posData.ArrowAtSource) edge.GeometryEdge.EdgeGeometry.SourceArrowhead = new Arrowhead { TipPosition = posData.ArrowAtSourcePosition }; if (posData.ArrowAtTarget) edge.GeometryEdge.EdgeGeometry.TargetArrowhead = new Arrowhead { TipPosition = posData.ArrowAtTargetPosition }; var list = posData.ControlPoints as List<P2>; if (list != null && list.Count%3 == 1) AddBezieSegsToEdgeFromPosData(edge, list); break; } case AttributeTypeEnum.Style: AddStyles(edgeAttr, attrVal.val); break; case AttributeTypeEnum.EdgeDirection: //edgeAttr.Dir=(EdgeDirection) attrVal.val; break; case AttributeTypeEnum.Weight: if(attrVal.val is String) edgeAttr.Weight=Int32.Parse( attrVal.val as String,AttributeBase.USCultureInfo); else edgeAttr.Weight=(int) attrVal.val; break; case AttributeTypeEnum.Ignore: {} break; case AttributeTypeEnum.ArrowSize: //Bug break; case AttributeTypeEnum.SameTail: //edgeAttr.Sametail=attrVal.val as String; break; case AttributeTypeEnum.SameHead: //edgeAttr.Samehead=attrVal.val as String; break; case AttributeTypeEnum.Constraint: //do nothing //edgeAttr.Constraint=(bool)attrVal.val; break; default: throw new Exception(string.Format("The attribute \"{0}\" is not supported for edges", attrVal.attributeTypeEnum)); } } edge.Attr = edge.Attr; if (!String.IsNullOrEmpty(label.Text)) edge.Label = new Label(label.Text) { Owner = edge }; }
private void ReadEdgeAttr(EdgeAttr edgeAttr) { CheckToken(Tokens.EdgeAttribute); XmlRead(); ReadBaseAttr(edgeAttr); edgeAttr.Separation = ReadIntElement(Tokens.EdgeSeparation); edgeAttr.Weight = ReadIntElement(Tokens.Weight); edgeAttr.ArrowheadAtSource = (ArrowStyle)Enum.Parse(typeof(ArrowStyle), ReadStringElement(Tokens.ArrowStyle), false); edgeAttr.ArrowheadAtTarget = (ArrowStyle)Enum.Parse(typeof(ArrowStyle), ReadStringElement(Tokens.ArrowStyle), false); edgeAttr.ArrowheadLength =(float) ReadDoubleElement(Tokens.ArrowheadLength); ReadEndElement(); }
/// <summary> /// source id, label ,target id /// </summary> /// <param name="source"> cannot be null</param> /// <param name="labelText">label can be null</param> /// <param name="target">cannot be null</param> public Edge(string source, string labelText, string target) { if (String.IsNullOrEmpty(source) || String.IsNullOrEmpty(target)) throw new InvalidOperationException("Creating an edge with null or empty source or target IDs"); this.source = source; this.target = target; this.attr = new EdgeAttr(); if (!String.IsNullOrEmpty(labelText)) { Label = new Label(labelText) {Owner = this}; } }