/// <summary>Calculate / create a directed graph from model</summary> public void CalculateDirectedGraph() { if (directedGraphInfo == null) { directedGraphInfo = new DirectedGraph(); } directedGraphInfo.Begin(); bool needAtmosphereNode = false; foreach (NutrientPool pool in Apsim.Children(this, typeof(NutrientPool))) { directedGraphInfo.AddNode(pool.Name, ColourUtilities.ChooseColour(3), Color.Black); foreach (CarbonFlow cFlow in Apsim.Children(pool, typeof(CarbonFlow))) { foreach (string destinationName in cFlow.destinationNames) { string destName = destinationName; if (destName == null) { destName = "Atmosphere"; needAtmosphereNode = true; } directedGraphInfo.AddArc(null, pool.Name, destName, Color.Black); } } } foreach (Solute solute in Apsim.Children(this, typeof(Solute))) { directedGraphInfo.AddNode(solute.Name, ColourUtilities.ChooseColour(2), Color.Black); foreach (NFlow nitrogenFlow in Apsim.Children(solute, typeof(NFlow))) { string destName = nitrogenFlow.destinationName; if (destName == null) { destName = "Atmosphere"; needAtmosphereNode = true; } directedGraphInfo.AddArc(null, nitrogenFlow.sourceName, destName, Color.Black); } } if (needAtmosphereNode) { directedGraphInfo.AddTransparentNode("Atmosphere"); } directedGraphInfo.End(); }
/// <summary>Calculate / create a directed graph from model</summary> public void CalculateDirectedGraph() { DirectedGraph oldGraph = directedGraphInfo; if (directedGraphInfo == null) { directedGraphInfo = new DirectedGraph(); } directedGraphInfo.Begin(); bool needAtmosphereNode = false; foreach (NutrientPool pool in this.FindAllChildren <NutrientPool>()) { Point location = default(Point); Node oldNode; if (oldGraph != null && pool.Name != null && (oldNode = oldGraph.Nodes.Find(f => f.Name == pool.Name)) != null) { location = oldNode.Location; } directedGraphInfo.AddNode(pool.Name, ColourUtilities.ChooseColour(3), Color.Black, location); foreach (CarbonFlow cFlow in pool.FindAllChildren <CarbonFlow>()) { foreach (string destinationName in cFlow.destinationNames) { string destName = destinationName; if (destName == null) { destName = "Atmosphere"; needAtmosphereNode = true; } location = default(Point); Arc oldArc; if (oldGraph != null && pool.Name != null && (oldArc = oldGraph.Arcs.Find(f => f.SourceName == pool.Name && f.DestinationName == destName)) != null) { location = oldArc.Location; } directedGraphInfo.AddArc(null, pool.Name, destName, Color.Black, location); } } } foreach (Solute solute in this.FindAllChildren <Solute>()) { directedGraphInfo.AddNode(solute.Name, ColourUtilities.ChooseColour(2), Color.Black); foreach (NFlow nitrogenFlow in solute.FindAllChildren <NFlow>()) { string destName = nitrogenFlow.destinationName; if (destName == null) { destName = "Atmosphere"; needAtmosphereNode = true; } directedGraphInfo.AddArc(null, nitrogenFlow.sourceName, destName, Color.Black); } } if (needAtmosphereNode) { directedGraphInfo.AddTransparentNode("Atmosphere"); } directedGraphInfo.End(); }