public MaximumFlowDemo() { graph = new AdjacencyGraph( new NamedVertexProvider(), new EdgeProvider(), true); s = (NamedVertex)graph.AddVertex(); s.Name = "s"; x = (NamedVertex)graph.AddVertex(); x.Name = "x"; v = (NamedVertex)graph.AddVertex(); v.Name = "v"; w = (NamedVertex)graph.AddVertex(); w.Name = "w"; t = (NamedVertex)graph.AddVertex(); t.Name = "t"; sx = graph.AddEdge(s, x); capacities[sx] = 5; sv = graph.AddEdge(s, v); capacities[sv] = 7; xv = graph.AddEdge(x, v); capacities[xv] = 3; xw = graph.AddEdge(x, w); capacities[xw] = 7; wv = graph.AddEdge(w, v); capacities[wv] = 5; wt = graph.AddEdge(w, t); capacities[wt] = 4; vt = graph.AddEdge(v, t); capacities[vt] = 6; this.graphviz = new GraphvizAlgorithm(this.graph); this.graphviz.ImageType = NGraphviz.Helpers.GraphvizImageType.Svg; this.graphviz.GraphFormat.RankDirection = NGraphviz.Helpers.GraphvizRankDirection.LR; this.graphviz.FormatVertex+=new FormatVertexEventHandler(graphviz_FormatVertex); this.graphviz.FormatEdge+=new FormatEdgeEventHandler(graphviz_FormatEdge); this.reversedEdgeAugmentor = new ReversedEdgeAugmentorAlgorithm(this.graph); this.reversedEdgeAugmentor.ReversedEdgeAdded += new EdgeEventHandler(reversedEdgeAugmentor_ReversedEdgeAdded); }
public void ChangeEventsEnabled_When_False_Prevents_NetworkChanged_Fired_When_RemoveEdge_Is_Called(int nodeCount, int edgeCount, int edgesToRemove) { //Arrange var net = new BasicAdjList(Guid.NewGuid()); Random rand = new Random(); for (int i = 0; i < nodeCount; i++) net.CreateNode(); INode nodeA = null; INode nodeB = null; IEdge[] edges = new IEdge[edgeCount]; for (int i = 0; i < edgeCount; i++) { nodeA = net.Nodes[rand.Next(nodeCount)]; nodeB = net.Nodes[rand.Next(nodeCount)]; edges[i] = net.CreateEdge(nodeA, nodeB); } //--------------------- var helper = new NetworkChangedEventsTestHelper(); net.NetworkChanged += new NetworkChangedEventHandler<INetwork, NetworkChangedEventArgs>(helper.NetworkChanged_DummyHandler); net.ChangeEventsEnabled = false; for (int i = 0; i < edges.Length; i++) { net.RemoveEdge(edges[i]); } Assert.Equal(0, helper.NetworkChanged_TimesCalled); }
/// <summary> /// Inserts the Edge object to the Graph. /// <para>Connecting IVertex objects should already be present in the graph before attempting to add a connection.</para> /// </summary> /// <param name="edge">IEdge object to add.</param> public void AddEdge(IEdge edge) { if (_vertices.ContainsKey(edge.ParentId) && _vertices.ContainsKey(edge.ChildId)) _edges.AddOrUpdate(edge.ParentId, edge.ChildId, edge); else throw new InvalidOperationException("Invalid vertex index specified in edge"); }
public AGSEdges(IEdge left, IEdge right, IEdge top, IEdge bottom) { Left = left; Right = right; Top = top; Bottom = bottom; }
public void addEdge(IEdge e) { if (e == null) {return; } //neplatný graf if (!innerGraph.Vertices.Contains(e.Vertex_1) || !innerGraph.Vertices.Contains(e.Vertex_2)) { return; } //multihrana /* foreach(Edge ed in innerGraph.Edges) { if ((ed.vertex_1 == e.vertex_1 && ed.vertex_2 == e.vertex_2) || (ed.vertex_1 == e.vertex_2 && ed.vertex_2 == e.vertex_1)) { return; } } */ if (GraphForEdit.Edges.Contains(e, GraphForEdit.getEdgeComparer())) { return; } innerGraph.Edges.Add(e); if (eHandler != null) eHandler(this, new EdgeChangeArgs(e, ChangeType.Add)); }
public void FromEdges(IEdges edges) { Left = edges.Left; Right = edges.Right; Top = edges.Top; Bottom = edges.Bottom; }
public static void DrawParallelEdgeSelected(Graphics g, IEdge e, IEnumerable<IEdge> es, Font f, PointF pSource, PointF pTarget, int Radius = 5) { var ps = pSource; var pt = pTarget; String s = ""; List<float> Heights = new List<float>(); foreach (var et in es) { string str = et.AttributesToString(); s += str; Heights.Add(g.MeasureString(str, f).Height); } SizeF size = g.MeasureString(s, f); PointF location = new PointF((pt.X * 2 + 3 * ps.X) / 5 - 4, (pt.Y * 2 + ps.Y * 3) / 5 - 4); RectangleF rect = new RectangleF(location, size); GraphicsPath roundedRect = GetRoundedRect(rect, Radius); g.DrawLine(penHover, ps, pt); g.FillEllipse(brushHover, (pt.X + ps.X) / 2 - 2, (pt.Y + ps.Y) / 2 - 2, 4, 4); float hM = -1; g.FillPath(brushAttrPanel, roundedRect); foreach (var h in Heights) { hM += h; g.DrawLine(penAttrBorderSlipt, location.X + Radius, location.Y + hM, location.X + size.Width - Radius, location.Y + hM); } g.DrawPath(penAttrBorder, roundedRect); g.DrawString(s, f, brushText, rect); }
public ReversedEdge(IEdge e) { if (e==null) throw new ArgumentNullException("e"); this.wrapped = e; }
private static IComparable GetValue(this IPropertyDefinition myProperty, IEdge myEdge) { if (myProperty.RelatedType == null) throw new ArgumentException("A property with nor related type is not allowed."); if (!myProperty.RelatedType.Name.Equals(GlobalConstants.Edge)) return myEdge.GetProperty<IComparable>(myProperty.ID); switch (myProperty.Name) { case GlobalConstants.EdgeDotComment: return myEdge.Comment; case GlobalConstants.EdgeDotCreationDate: return myEdge.CreationDate; case GlobalConstants.EdgeDotModificationDate: return myEdge.ModificationDate; case GlobalConstants.EdgeDotEdgeTypeID: return myEdge.EdgeTypeID; case GlobalConstants.EdgeDotEdgeTypeName: return myProperty.RelatedType.GetDescendantTypesAndSelf().Where(_ => _.ID == myEdge.EdgeTypeID).Select(__ => __.Name).FirstOrDefault(); default: throw new System.Exception( "A new property was added to the edeg type Edge, but this switch stement was not changed."); } }
private bool checkEdgeCross(IEdge edge, float previous, float current, Func<IEdge,float,float,bool> check) { if (!edge.Enabled) return false; if (!check(edge,previous,current)) return false; edge.OnEdgeCrossed.Invoke(edge, new AGSEventArgs()); return true; }
private static void PrintEdgeTrack(IEdge[] edge) { Console.WriteLine("Edge tracks:"); for (int i = 0; i < edge.Count(); i++) { Console.WriteLine("{0}: {1}", i + 1, edge[i]); } }
/// <summary> /// Adds the elements of an array to the end of this EdgeCollection. /// </summary> /// <param name="items"> /// The array whose elements are to be added to the end of this EdgeCollection. /// </param> public void AddRange(IEdge[] items) { foreach (IEdge item in items) { this.List.Add(item); } }
public virtual void CopyTo(IEdge edge) { edge.Graph = this.Graph; var e = edge as Edge; e.Vertices[0] = this.Vertices[0]; e.Vertices[1] = this.Vertices[1]; }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <returns></returns> public bool Test(IEdge e) { if (e == null) throw new ArgumentNullException("e"); return m_EdgePredicate.Test(e) && m_VertexPredicate.Test(e.Source); }
/// <summary> /// Calculates the attraction or tension on the given edge. /// </summary> /// <param name="edge">The edge.</param> public void CalculateAttraction(IEdge edge) { INode n1, n2; Params n1p = new Params(); Params n2p = new Params(); if (edge.SourceNode != null) { n2 = edge.SourceNode; n2p = Pars[n2.Uid.ToString()]; }; if (edge.TargetNode != null) { n1 = edge.TargetNode; n1p = Pars[n1.Uid.ToString()]; }; double xDelta = n1p.loc[0] - n2p.loc[0]; double yDelta = n1p.loc[1] - n2p.loc[1]; double deltaLength = Math.Max(EPSILON, Math.Sqrt(xDelta * xDelta + yDelta * yDelta)); double force = (deltaLength * deltaLength) / forceConstant; if (Double.IsNaN(force)) { System.Diagnostics.Trace.WriteLine("Oops, the layout resulted in a NaN problem."); return; } double xDisp = (xDelta / deltaLength) * force; double yDisp = (yDelta / deltaLength) * force; n1p.disp[0] -= xDisp; n1p.disp[1] -= yDisp; n2p.disp[0] += xDisp; n2p.disp[1] += yDisp; }
/// <summary> /// Graphviz format edge parameter object /// </summary> /// <param name="edgeFormatter">edge formatter</param> /// <param name="e">edge</param> public FormatEdgeEventArgs(GraphvizEdge edgeFormatter, IEdge e) : base(e) { if (edgeFormatter==null) throw new ArgumentNullException("edgeFormatter"); m_EdgeFormatter = edgeFormatter; }
/// <summary> /// Test if edge e has a positive residual capacity /// </summary> /// <param name="e">edge to test</param> /// <returns>0 < ResidualCapacities[e]</returns> /// <exception cref="ArgumentNullException">e is null</exception> public bool Test(IEdge e) { if (e == null) throw new ArgumentNullException("e"); return 0 < (double)this.residualCapacities[e]; }
public void Add(IEdge item) { SaveVertex(item.From); SaveVertex(item.To); _edges.Add(item); }
public bool Test(IEdge e) { NamedEdge ne = e as NamedEdge; if (ne==null) return false; return ne.Name == name; }
internal void UpdateRegister(VertexRegister milestoneRegister, IEdge edge) { TotalWeight = milestoneRegister.TotalWeight + edge.Weight; EdgeTracks.Clear(); EdgeTracks = milestoneRegister.EdgeTracks.Select(et => et).ToList(); EdgeTracks.Add(edge); }
public IRoad BuildRoad(IEdge edge, IPlayer owner) { if (edge == null) throw new ArgumentNullException(nameof(edge)); if (owner == null) throw new ArgumentNullException(nameof(owner)); if (!Edges.Contains(edge)) throw new ArgumentException("Edge does not exist on the board"); if (roads.Any(r => r.Edge == edge)) throw new ArgumentException("There already is a road build on the given edge"); if (Tiles.Where(t => t.IsAdjacentTo(edge)).All(t => t.Rawmaterial == MaterialType.Sea)) throw new ArgumentException("Can't build roads on sea!"); var adjacentVertices = Vertices.Where(v => v.IsAdjacentTo(edge)); var adjacentEdges = Edges.Where(e => e.IsAdjacentTo(edge)); //CvB Todo: fix readability if (establishments.All(e => !adjacentVertices.Contains(e.Vertex) || e.Owner != owner) && roads.All(r => !adjacentEdges.Contains(r.Edge) || r.Owner != owner)) throw new ArgumentException("Road should have an adjacent establisment or road of the player"); var road = new Road(edge, owner); roads.Add(road); logger.Info($"Road build; Player {owner.Name}, {edge.ToString()}"); return road; }
public IEdge AddEdge(IEdge e) { if (e != null && Graph.Equals(e.Graph)) return e; if(Graph.AddEdge(e)) return e; return null; }
private double GetEdgeScore(IEdge edge, HashSet<IEdge> checkedEdges, Dictionary<IVertex, double> vertexScores, int level) { if (checkedEdges.Contains(edge)) { return 0.0; } checkedEdges.Add(edge); double score = 0.0; // get adjacent vertex scores foreach (IVertex vertex in edge.Adjacent.Vertices) { if (vertexScores.ContainsKey(vertex)) { score += vertexScores[vertex]; vertexScores.Remove(vertex); } } score /= level; // other edge scores foreach (IEdge nextEdge in edge.Adjacent.Edges) { if (nextEdge.Color == null) { score += GetEdgeScore(nextEdge, checkedEdges, vertexScores, level + 1); } } return score; }
/// <summary> /// Draw a Vertex /// </summary> public static void DrawEdge(Graphics g, IEdge e, PointF pSource, PointF pTarget, bool highLight = false) { var ps = pSource; var pt = pTarget; g.DrawLine(highLight ? penHighLight : penEdge, ps, pt); g.FillEllipse(highLight ? brushHighLight : brushEdgePoint, (pt.X + ps.X) / 2 - 2, (pt.Y + ps.Y) / 2 - 2, 4, 4); g.FillEllipse(highLight ? brushHighLight : brushEdgePoint, (pt.X * 2 + 3 * ps.X) / 5 - 4, (pt.Y * 2 + ps.Y * 3) / 5 - 4, 8, 8); }
/// <summary> /// Test if edge connects source and target vertex /// </summary> /// <param name="e">edge to test</param> /// <returns>true if e connects source and target</returns> public bool Test(IEdge e) { if (graph.IsDirected) return e.Source == source && e.Target == target; else return (e.Source == source && e.Target == target) ||(e.Source == target && e.Target == source); }
private void PutEdge(Orientation edgeLocation, IEdge edge) { var oldEdge = Edges.FirstOrDefault(x => x.Item1 == edgeLocation); if (oldEdge != null) Edges.Remove(oldEdge); Edges.Add(new Tuple<Orientation, IEdge>(edgeLocation, edge)); }
public ServiceEdgeInstance(IEdge myEdge, Nullable<Int64> myEdgePropertyID) : base(myEdge.EdgeTypeID) { this.EdgePropertyID = myEdgePropertyID; this.Comment = myEdge.Comment; var SourceVertex = myEdge.GetSourceVertex(); this.SourceVertex = new ServiceVertexInstance(SourceVertex); }
public bool Test(IEdge e) { if (e == null) throw new ArgumentNullException("e"); if (th && e==re) throw new Exception("e == re"); return e==re; }
public void Init() { _left = new AGSEdge { Value = 100 }; _right = new AGSEdge { Value = 200 }; _top = new AGSEdge { Value = 200 }; _bottom = new AGSEdge { Value = 100 }; _edges = new AGSEdges (_left, _right, _top, _bottom); _mocks = Mocks.Init(); }
private static IEdge CreateRemappedEdge( IEdge edge, Dictionary<INode, INode> remap) { IEdge newEdge = edge.Clone(); newEdge.Source = remap[edge.Source]; newEdge.Target = remap[edge.Target]; return newEdge; }
static public void CreateEdgeAndCreateOrReplaceEdgeByMeta(IVertex baseVertex, IVertex metaVertex, IEdge Edge) { IEdge toReplace = GraphUtil.FindEdgeByMetaVertex(baseVertex, metaVertex); IVertex edge; if (toReplace == null) { edge = baseVertex.AddVertex(metaVertex, null); } else { baseVertex.DeleteEdge(toReplace); edge = baseVertex.AddVertex(toReplace.Meta, null); } IVertex r = MinusZero.Instance.Root; edge.AddEdge(r.Get(@"System\Meta\ZeroTypes\Edge\From"), Edge.From); edge.AddEdge(r.Get(@"System\Meta\ZeroTypes\Edge\Meta"), Edge.Meta); edge.AddEdge(r.Get(@"System\Meta\ZeroTypes\Edge\To"), Edge.To); }
public void Init(MissionController mission, IEdge iedge) { this.mission = mission; this.iEdge = iedge; }
/// <summary> /// Creates an object containing all necessary data to create an edge visual /// </summary> private RenderDataCache CreateRenderDataCache(IRenderContext context, IEdge edge) { return(new RenderDataCache(PathThickness, GetPath(edge), Arrows)); }
/// <inheritdoc /> protected override Visual UpdateVisual(IRenderContext context, Visual oldVisual, IEdge edge) { return(Style.Renderer.GetVisualCreator(edge, Style).UpdateVisual(context, oldVisual)); }
/// <inheritdoc /> protected override bool IsHit(IInputModeContext context, PointD location, IEdge edge) { return(Style.Renderer.GetHitTestable(edge, Style).IsHit(context, location)); }
/// <inheritdoc /> protected override Tangent?GetTangent(IEdge edge, int segmentIndex, double ratio) { return(Style.Renderer.GetPathGeometry(edge, Style).GetTangent(ratio)); }
/// <summary> /// Creates a new node discovery event. /// </summary> /// <param name="newNode">The node that was discovered.</param> /// <param name="origin">The edge that was traversed to discover the node.</param> public NodeDiscoveryEventArgs(INode newNode, IEdge origin) { NewNode = newNode; Origin = origin; }
protected override Pen GetPen(CanvasControl context, IEdge edge) { return(null); }
/// <summary> /// Determines whether the visual representation of the edge has been hit at the given location. /// Overridden method to include the <see cref="PathThickness"/> and the HitTestRadius specified in the context /// in the calculation. /// </summary> protected override bool IsHit(IInputModeContext context, PointD location, IEdge edge) { // Use the convenience method in GeneralPath return(GetPath(edge).PathContains(location, context.HitTestRadius + PathThickness * 0.5d)); }
IsParallelTo ( IEdge otherEdge ) { AssertValid(); const String MethodName = "IsParallelTo"; const String ArgumentName = "otherEdge"; this.ArgumentChecker.CheckArgumentNotNull( MethodName, ArgumentName, otherEdge); IVertex oOtherVertex1, oOtherVertex2; // Get the other edge's vertices. EdgeUtil.EdgeToVertices(otherEdge, this.ClassName, MethodName, out oOtherVertex1, out oOtherVertex2); // The following code implements the table in the documentation for // IEdge.IsParallelTo(). if ( !( (m_oVertex1 == oOtherVertex1 && m_oVertex2 == oOtherVertex2) || (m_oVertex1 == oOtherVertex2 && m_oVertex2 == oOtherVertex1) ) ) { // The two edges do not connect the same two vertices. return(false); } switch (this.ParentGraph.Directedness) { case GraphDirectedness.Directed: Debug.Assert(this.IsDirected && otherEdge.IsDirected); return(m_oVertex1 == oOtherVertex1); case GraphDirectedness.Undirected: Debug.Assert(!this.IsDirected && !otherEdge.IsDirected); return(true); case GraphDirectedness.Mixed: if (!this.IsDirected || !otherEdge.IsDirected) { return(true); } return(m_oVertex1 == oOtherVertex1); default: Debug.Assert(false); return(false); } }
/// <summary> /// Create a new instance of the Berico.LinkAnalysis.ViewModel.StandardEdgeViewModel /// class using the provided parent edge /// </summary> /// <param name="parentEdge">The edge data represented by the view and viewmodel</param> /// <param name="scope">Identifies the scope of this edge view model</param> public StandardEdgeViewModel(IEdge parentEdge, string scope) : base(parentEdge, scope) { }
public static void Disconnect(IEdge edge) { edge.First.IncidentEdges.Remove(edge); edge.Second.IncidentEdges.Remove(edge); }
public BezierEdgeHandleProvider(IEdge edge, IHandleProvider coreImpl) { this.edge = edge; this.coreImpl = coreImpl; }
ReadEdgeTable ( ListObject oEdgeTable, ReadWorkbookContext oReadWorkbookContext, IGraph oGraph ) { Debug.Assert(oEdgeTable != null); Debug.Assert(oReadWorkbookContext != null); Debug.Assert(oGraph != null); AssertValid(); Boolean bReadAllEdgeAndVertexColumns = oReadWorkbookContext.ReadAllEdgeAndVertexColumns; if (oReadWorkbookContext.FillIDColumns) { FillIDColumn(oEdgeTable); } Dictionary <String, IVertex> oVertexNameDictionary = oReadWorkbookContext.VertexNameDictionary; EdgeVisibilityConverter oEdgeVisibilityConverter = new EdgeVisibilityConverter(); Boolean bGraphIsDirected = (oGraph.Directedness == GraphDirectedness.Directed); ExcelTableReader oExcelTableReader = new ExcelTableReader(oEdgeTable); IVertexCollection oVertices = oGraph.Vertices; IEdgeCollection oEdges = oGraph.Edges; HashSet <String> oColumnNamesToExclude = new HashSet <String>( new String[] { EdgeTableColumnNames.Vertex1Name, EdgeTableColumnNames.Vertex2Name }); foreach (ExcelTableReader.ExcelTableRow oRow in oExcelTableReader.GetRows()) { // Get the names of the edge's vertices. String sVertex1Name, sVertex2Name; Boolean bVertex1IsEmpty = !oRow.TryGetNonEmptyStringFromCell( EdgeTableColumnNames.Vertex1Name, out sVertex1Name); Boolean bVertex2IsEmpty = !oRow.TryGetNonEmptyStringFromCell( EdgeTableColumnNames.Vertex2Name, out sVertex2Name); if (bVertex1IsEmpty && bVertex2IsEmpty) { // Skip empty rows. continue; } if (bVertex1IsEmpty || bVertex2IsEmpty) { // A half-empty row is an error. OnHalfEmptyEdgeRow(oRow, bVertex1IsEmpty); } // Assume a default visibility. Visibility eVisibility = Visibility.Show; String sVisibility; if ( oRow.TryGetNonEmptyStringFromCell( CommonTableColumnNames.Visibility, out sVisibility) && !oEdgeVisibilityConverter.TryWorkbookToGraph( sVisibility, out eVisibility) ) { OnInvalidVisibility(oRow); } if (eVisibility == Visibility.Skip) { // Skip the edge an continue to the next edge. continue; } // Create the specified vertices or retrieve them from the // dictionary. IVertex oVertex1 = VertexNameToVertex( sVertex1Name, oVertices, oVertexNameDictionary); IVertex oVertex2 = VertexNameToVertex( sVertex2Name, oVertices, oVertexNameDictionary); // Add an edge connecting the vertices. IEdge oEdge = oEdges.Add(oVertex1, oVertex2, bGraphIsDirected); // If there is an ID column, add the edge to the edge row ID // dictionary and set the edge's Tag to the row ID. AddToRowIDDictionary(oRow, oEdge, oReadWorkbookContext.EdgeRowIDDictionary); if (bReadAllEdgeAndVertexColumns) { // All columns except the vertex names should be read and // stored as metadata on the edge. ReadAllColumns(oExcelTableReader, oRow, oEdge, oColumnNamesToExclude); continue; } if (eVisibility == Visibility.Hide) { // Hide the edge and continue to the next edge. oEdge.SetValue(ReservedMetadataKeys.Visibility, VisibilityKeyValue.Hidden); continue; } // Alpha. Boolean bAlphaIsZero = ReadAlpha(oRow, oEdge); if (bAlphaIsZero) { continue; } // Color. ReadColor(oRow, EdgeTableColumnNames.Color, oEdge, ReservedMetadataKeys.PerColor, oReadWorkbookContext.ColorConverter2); // Width. ReadWidth(oRow, oReadWorkbookContext.EdgeWidthConverter, oEdge); // Style. ReadStyle(oRow, oReadWorkbookContext.EdgeStyleConverter, oEdge); // Label. if (oReadWorkbookContext.ReadEdgeLabels) { ReadCellAndSetMetadata(oRow, EdgeTableColumnNames.Label, oEdge, ReservedMetadataKeys.PerEdgeLabel); } // Weight. if (oReadWorkbookContext.ReadEdgeWeights) { ReadEdgeWeight(oRow, oEdge); } } if (bReadAllEdgeAndVertexColumns) { // Store the edge column names on the graph. oGraph.SetValue(ReservedMetadataKeys.AllEdgeMetadataKeys, FilterColumnNames(oExcelTableReader, oColumnNamesToExclude)); } }
/// <inheritdoc /> protected override int GetSegmentCount(IEdge edge) { return(Style.Renderer.GetPathGeometry(edge, Style).GetSegmentCount()); }
public virtual void RemoveEdge(IEdge e) { RemoveEdgeNoValidate(e); ValidateGraph(); }
/// <inheritdoc /> protected override GeneralPath GetPath(IEdge edge) { return(Style.Renderer.GetPathGeometry(edge, Style).GetPath()); }
/// <summary> /// Re-renders the edge using the old visual for performance reasons. /// </summary> protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup oldVisual, IEdge edge) { // get the data with which the old visual was created RenderDataCache oldCache = oldVisual.GetRenderDataCache <RenderDataCache>(); // get the data for the new visual RenderDataCache newCache = CreateRenderDataCache(context, edge); // check if something changed if (!newCache.StateEquals(oldCache)) { // more than only the path changed - re-render the visual oldVisual.Children.Clear(); Render(context, edge, oldVisual, newCache); return(oldVisual); } if (!newCache.PathEquals(oldCache)) { // only the path changed - update the old visual UpdatePath(context, edge, oldVisual, newCache); } return(oldVisual); }
/// <inheritdoc /> protected override bool IsInBox(IInputModeContext context, RectD rectangle, IEdge edge) { return(Style.Renderer.GetMarqueeTestable(edge, Style).IsInBox(context, rectangle)); }
public static TVertex OtherVertex <TVertex>(this IEdge <TVertex> edge, TVertex thisVertex) { return(edge.Source.Equals(thisVertex) ? edge.Target : edge.Source); }
/// <inheritdoc /> protected override RectD GetBounds(ICanvasContext context, IEdge edge) { return(Style.Renderer.GetBoundsProvider(edge, Style).GetBounds(context)); }
private static void DumpEdge(IEdge edge, GrColor textColor, GrColor color, GrLineStyle style, int thickness, IDumper dumper, DumpInfo dumpInfo) { dumper.DumpEdge(edge.Source, edge.Target, GetElemLabel(edge, dumpInfo), DumpAttributes(edge), textColor, color, style, thickness); }
/// <inheritdoc /> protected override Visual CreateVisual(IRenderContext context, IEdge edge) { return(Style.Renderer.GetVisualCreator(edge, Style).CreateVisual(context)); }
public IEdgeObject(IEdge IEdgeinstance) { IEdgeInstance = IEdgeinstance; }
/// <summary> /// Gets the locations of the source and target port as <see cref="PointD" />s. /// </summary> /// <param name="edge">The edge.</param> /// <param name="source">A variable to store the source port's location.</param> /// <param name="target">A variable to store the target port's location.</param> private static void GetPoints(IEdge edge, out PointD source, out PointD target) { source = GetLocation(edge.SourcePort); target = GetLocation(edge.TargetPort); }
private bool FindAnchorTangent(IEdge edge, out double upX, out double upY, out double cx, out double cy) { IEdgeStyle style = edge.Style; if (style != null) { IEdgeStyleRenderer renderer = style.Renderer; IPathGeometry geometry = renderer.GetPathGeometry(edge, style); if (geometry != null) { var t = geometry.GetTangent(ratio); if (t != null) { var tangent = t.Value; upX = -tangent.Vector.Y; upY = tangent.Vector.X; cx = tangent.Point.X; cy = tangent.Point.Y; return(true); } } } double l = 0; var spl = edge.SourcePort.GetLocation(); double x1 = spl.X; double y1 = spl.Y; var tpl = edge.TargetPort.GetLocation(); double x2 = tpl.X; double y2 = tpl.Y; { double lx = x1; double ly = y1; var bends = edge.Bends; for (int i = 0; i < bends.Count; i++) { IBend bend = bends[i]; double bx = bend.Location.X; double by = bend.Location.Y; double dx = bx - lx; double dy = by - ly; l += Math.Sqrt(dx * dx + dy * dy); lx = bx; ly = by; } { double dx = x2 - lx; double dy = y2 - ly; l += Math.Sqrt(dx * dx + dy * dy); } } double tl = ratio * l; if (l == 0) { // no length, no path, no label upX = 0; upY = -1; cx = x1; cy = y1; return(false); } l = 0; { double lx = x1; double ly = y1; var bends = edge.Bends; for (int i = 0; i < bends.Count; i++) { IBend bend = bends[i]; double bx = bend.Location.X; double by = bend.Location.Y; double dx = bx - lx; double dy = by - ly; double sl = Math.Sqrt(dx * dx + dy * dy); if (sl > 0 && l + sl >= tl) { tl -= l; cx = lx + tl * dx / sl; cy = ly + tl * dy / sl; upX = -dy; upY = dx; return(true); } l += sl; lx = bx; ly = by; } { double dx = x2 - lx; double dy = y2 - ly; double sl = Math.Sqrt(dx * dx + dy * dy); if (sl > 0) { tl -= l; cx = lx + tl * dx / sl; cy = ly + tl * dy / sl; upX = -dy; upY = dx; return(true); } else { upX = 0; upY = -1; cx = x1; cy = y1; return(false); } } } }
/// <summary> /// Creates a sample graph and introduces all important graph elements present in /// yFiles WPF. Additionally, this method now overrides the label placement for some specific labels. /// </summary> private void PopulateGraph() { #region Sample Graph creation // Creates two nodes with the default node size // The location is specified for the _center_ INode node1 = Graph.CreateNode(new PointD(50, 50)); INode node2 = Graph.CreateNode(new PointD(150, 50)); // Creates a third node with a different size of 80x40 // In this case, the location of (360,280) describes the _upper left_ // corner of the node bounds INode node3 = Graph.CreateNode(new RectD(260, 180, 80, 40)); // Creates some edges between the nodes IEdge edge1 = Graph.CreateEdge(node1, node2); IEdge edge2 = Graph.CreateEdge(node2, node3); // Creates the first bend for edge2 at (400, 50) IBend bend1 = Graph.AddBend(edge2, new PointD(300, 50)); // Actually, edges connect "ports", not nodes directly. // If necessary, you can manually create ports at nodes // and let the edges connect to these. // Creates a port in the center of the node layout IPort port1AtNode1 = Graph.AddPort(node1, FreeNodePortLocationModel.NodeCenterAnchored); // Creates a port at the middle of the left border // Note to use absolute locations when placing ports using PointD. IPort port1AtNode3 = Graph.AddPort(node3, new PointD(node3.Layout.X, node3.Layout.GetCenter().Y)); // Creates an edge that connects these specific ports IEdge edgeAtPorts = Graph.CreateEdge(port1AtNode1, port1AtNode3); // Adds labels to several graph elements Graph.AddLabel(node1, "Node 1"); Graph.AddLabel(node2, "Node 2"); Graph.AddLabel(node3, "Node 3"); Graph.AddLabel(edgeAtPorts, "Edge at Ports"); // Add some more elements to have a larger graph to edit var n4 = Graph.CreateNode(new PointD(50, -50)); Graph.AddLabel(n4, "Node 4"); var n5 = Graph.CreateNode(new PointD(50, -150)); Graph.AddLabel(n5, "Node 5"); var n6 = Graph.CreateNode(new PointD(-50, -50)); Graph.AddLabel(n6, "Node 6"); var n7 = Graph.CreateNode(new PointD(-50, -150)); Graph.AddLabel(n7, "Node 7"); var n8 = Graph.CreateNode(new PointD(150, -50)); Graph.AddLabel(n8, "Node 8"); Graph.CreateEdge(n4, node1); Graph.CreateEdge(n5, n4); Graph.CreateEdge(n7, n6); var e6_1 = Graph.CreateEdge(n6, node1); Graph.AddBend(e6_1, new PointD(-50, 50), 0); // Creates a group node programmatically which groups the child nodes n4, n5, and n8 var groupNode = CreateGroupNodes(n4, n5, n8); // creates an edge between the group node and node 2 var eg_2 = Graph.CreateEdge(groupNode, node2); Graph.AddBend(eg_2, new PointD(100, 0), 0); Graph.AddBend(eg_2, new PointD(150, 0), 1); #endregion }
/// <summary> /// Updates the visual which renders the edge. /// </summary> /// <param name="context">The render context.</param> /// <param name="group">The visual to update.</param> /// <param name="edge">The edge to render.</param> /// <returns>The updated visual.</returns> protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup group, IEdge edge) { EdgeVisual edgeVisual; if (group.Children.Count < 1 || (edgeVisual = group.Children[0] as EdgeVisual) == null) { return(CreateVisual(context, edge)); } var color = GetColor(context, edge); GeneralPath gp = GetPath(edge); edgeVisual.Update(gp, PathThickness, color); UpdateArrows(context, group, edge, gp, Arrows, Arrows); return(group); }
/// <inheritdoc /> protected override Visual UpdateVisual(IRenderContext context, Visual oldVisual, IEdge edge) { PointD source, target; GetPoints(edge, out source, out target); var zoom = context.Zoom; if (!ShouldDrawEdge(source, target, zoom)) { return(null); } var rdc = oldVisual.GetRenderDataCache <EdgeInfo>(); var oldSource = rdc.source; var oldTarget = rdc.target; var drawBends = ShouldDrawBends(zoom); var bendLocations = GetBendLocations(edge); // Did anything change at all? If not, we can just re-use the old visual if (source == oldSource && target == oldTarget && drawBends == rdc.drawBends && ArrayEqual(bendLocations, rdc.bendLocations)) { return(oldVisual); } // Otherwise re-create the geometry and update the cache ((Path)oldVisual).Data = CreateGeometry(source, target, edge, drawBends); oldVisual.SetRenderDataCache(new EdgeInfo(source, target, drawBends, bendLocations)); return(oldVisual); }
/// <summary> Сравнение рёбер </summary> public bool Equals(IEdge other) { return(Graphs.ValueEqualityComparer.EdgesEquals(this, other)); }