public void CreateGraphNode_FaultTreeIllustrationPointNodeDataWithoutChildren_ReturnsExpected() { // Setup var random = new Random(31); var illustrationPoint = new FaultTreeIllustrationPoint( "Illustration Point", random.NextRoundedDouble(), Enumerable.Empty <Stochast>(), random.NextEnumValue <CombinationType>()); // Call GraphNode graphNode = RiskeerGraphNodeFactory.CreateGraphNode(illustrationPoint, Enumerable.Empty <GraphNode>()); // Assert Assert.AreEqual(CreateExpectedGraphNodeContent(illustrationPoint.Name, illustrationPoint.Beta), graphNode.Content); Assert.IsTrue(graphNode.IsSelectable); var expectedStyle = new GraphNodeStyle(GraphNodeShape.Rectangle, Color.LightGray, Color.Black, 1); AssertEqualStyle(expectedStyle, graphNode.Style); Assert.AreEqual(1, graphNode.ChildNodes.Count()); GraphNode connectingNode = graphNode.ChildNodes.First(); AssertGraphConnectingNode(CreateExpectedGraphConnectingNodeContent(illustrationPoint.CombinationType), connectingNode); CollectionAssert.IsEmpty(connectingNode.ChildNodes); }
public void Constructor_WithStyling_ExpectedValues() { // Setup Color fillColor = Color.Aqua; Color lineColor = Color.Brown; const GraphNodeShape shape = GraphNodeShape.None; const int lineWidth = 3; var style = new GraphNodeStyle(shape, fillColor, lineColor, lineWidth); GraphNode[] childNodes = { new GraphNode("<text>node 1</text>", new GraphNode[0], false, style), new GraphNode("<text>node 2</text>", new[] { new GraphNode("<text>node 3</text>", new GraphNode[0], false, style) }, true, style) }; const string content = "<text>test</text>"; const bool isSelectable = false; // Call var node = new GraphNode(content, childNodes, isSelectable, style); // Assert Assert.AreEqual(content, node.Content); Assert.AreEqual(isSelectable, node.IsSelectable); Assert.AreSame(style, node.Style); Assert.AreSame(childNodes, node.ChildNodes); }
private static void AssertEqualStyle(GraphNodeStyle expected, GraphNodeStyle actual) { Assert.AreEqual(expected.FillColor, actual.FillColor); Assert.AreEqual(expected.LineColor, actual.LineColor); Assert.AreEqual(expected.LineWidth, actual.LineWidth); Assert.AreEqual(expected.Shape, actual.Shape); }
private static void AssertGraphConnectingNode(string expectedContent, GraphNode actualNode) { Assert.IsFalse(actualNode.IsSelectable); Assert.AreEqual(expectedContent, actualNode.Content); var expectedConnectingStyle = new GraphNodeStyle(GraphNodeShape.None, Color.BlanchedAlmond, Color.Black, 1); AssertEqualStyle(expectedConnectingStyle, actualNode.Style); }
//Fetches name and category from database public bool Load(uint techID, ref Dictionary <string, GraphNodeStyle> styles) { bool success = true; id = techID; MySqlCommand command = new MySqlCommand(); command.Connection = connection; command.CommandText = "SELECT name, category FROM tech " + "WHERE id=" + id + ";"; connection.Open(); MySqlDataReader reader; try { reader = command.ExecuteReader(); if (reader.Read()) { name = reader.GetString(0); category = reader.GetString(1); renderer = styles[category]; } else { success = false; } } catch (MySqlException ex) { techListView.QuietLog("An error occurred while loading graph node " + "information for id " + id + ": " + ex.Message, command.CommandText); success = false; } catch (KeyNotFoundException) { techListView.QuietLog("Error: category '" + category + "' not found in " + "GraphNodeStyles dictionary."); success = false; } catch (Exception ex) //Diaper handling because this function typically runs asynchronously { techListView.QuietLog("An unknown error occurred while loading " + "graph node information for id " + id + ": " + ex.Message, command.CommandText); success = false; } finally { connection.Close(); } valid = success; return(success); }
/// <summary> /// Converts a <see cref="GraphNode"/> to a <see cref="PointedTreeElementVertex"/>. /// </summary> /// <param name="graphNode">The graph node to convert.</param> /// <returns>The created <see cref="PointedTreeElementVertex"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="graphNode"/> /// is <c>null</c>.</exception> /// <exception cref="InvalidEnumArgumentException">Thrown when <see cref="GraphNodeStyle.Shape"/> /// is an invalid value.</exception> /// <exception cref="NotSupportedException">Thrown when <see cref="GraphNodeStyle.Shape"/> /// is a valid value, but unsupported.</exception> public static PointedTreeElementVertex Convert(GraphNode graphNode) { if (graphNode == null) { throw new ArgumentNullException(nameof(graphNode)); } GraphNodeStyle style = graphNode.Style; return(new PointedTreeElementVertex( graphNode.Content, ConvertColor(style.FillColor), ConvertColor(style.LineColor), style.LineWidth, ConvertType(style.Shape), graphNode.IsSelectable)); }
public void Constructor_ExpectedValues() { // Setup Color fillColor = Color.DarkRed; Color lineColor = Color.DarkBlue; const int lineWidth = 2; const GraphNodeShape shape = GraphNodeShape.None; // Call var style = new GraphNodeStyle(shape, fillColor, lineColor, lineWidth); // Assert Assert.AreEqual(shape, style.Shape); Assert.AreEqual(fillColor, style.FillColor); Assert.AreEqual(lineColor, style.LineColor); Assert.AreEqual(lineWidth, style.LineWidth); }
public void CreateGraphNode_WithSubMechanismIllustrationPointEmptyChildren_ReturnsGraphNodeWithExpectedStyling() { // Setup var illustrationPoint = new SubMechanismIllustrationPoint( "Illustration Point", new Random(31).NextRoundedDouble(), Enumerable.Empty <SubMechanismIllustrationPointStochast>(), Enumerable.Empty <IllustrationPointResult>()); // Call GraphNode graphNode = RiskeerGraphNodeFactory.CreateGraphNode(illustrationPoint, new[] { CreateTestGraphNode() }); // Assert Assert.AreEqual(CreateExpectedGraphNodeContent(illustrationPoint.Name, illustrationPoint.Beta), graphNode.Content); Assert.IsTrue(graphNode.IsSelectable); CollectionAssert.IsEmpty(graphNode.ChildNodes); var expectedStyle = new GraphNodeStyle(GraphNodeShape.Rectangle, Color.SkyBlue, Color.Black, 1); AssertEqualStyle(expectedStyle, graphNode.Style); }
private void InitializeStyles() { //Foundational is a blue rectangle with bold black border Foundational = new GraphNodeStyle(); Foundational.points = new Point[4]; Foundational.points[0] = new Point(-50, 23); Foundational.points[1] = new Point(50, 23); Foundational.points[2] = new Point(50, -23); Foundational.points[3] = new Point(-50, -23); Foundational.fillBrush = new SolidBrush(Color.LightSkyBlue); Foundational.font = new Font("Tahoma", 8f, FontStyle.Regular); Foundational.borderPen = new Pen(Color.Black, 2f); Foundational.textBrush = new SolidBrush(Color.Black); Foundational.connectors = new Dictionary <string, Point>(); Foundational.connectors.Add("left", new Point(-50, 0)); Foundational.connectors.Add("right", new Point(50, 0)); Foundational.connectors.Add("top", new Point(0, -23)); Foundational.connectors.Add("bottom", new Point(0, 23)); //Topical is a salmon parallelogram with a regular black border Topical = new GraphNodeStyle(); Topical.points = new Point[4]; Topical.points[0] = new Point(-46, 23); Topical.points[1] = new Point(54, 23); Topical.points[2] = new Point(46, -23); Topical.points[3] = new Point(-54, -23); Topical.fillBrush = new SolidBrush(Color.LightSalmon); Topical.font = new Font("Tahoma", 8f, FontStyle.Regular); Topical.textBrush = new SolidBrush(Color.Black); Topical.borderPen = new Pen(Color.Black, 1f); Topical.connectors = new Dictionary <string, Point>(); Topical.connectors.Add("left", new Point(-50, 0)); Topical.connectors.Add("right", new Point(50, 0)); Topical.connectors.Add("top", new Point(0, -23)); Topical.connectors.Add("bottom", new Point(0, 23)); //Specialized is a green 6-pointed star-like shape with a regular black border Specialized = new GraphNodeStyle(); Specialized.points = new Point[12]; Specialized.points[0] = new Point(-15, 21); Specialized.points[1] = new Point(0, 25); Specialized.points[2] = new Point(15, 21); Specialized.points[3] = new Point(52, 21); Specialized.points[4] = new Point(46, 0); Specialized.points[5] = new Point(52, -21); Specialized.points[6] = new Point(15, -21); Specialized.points[7] = new Point(0, -25); Specialized.points[8] = new Point(-15, -21); Specialized.points[9] = new Point(-52, -21); Specialized.points[10] = new Point(-46, 0); Specialized.points[11] = new Point(-52, 21); Specialized.fillBrush = new SolidBrush(Color.LightGreen); Specialized.font = new Font("Tahoma", 8f, FontStyle.Regular); Specialized.textBrush = new SolidBrush(Color.Black); Specialized.borderPen = new Pen(Color.Black, 1f); Specialized.connectors = new Dictionary <string, Point>(); Specialized.connectors.Add("left", new Point(-46, 0)); Specialized.connectors.Add("right", new Point(46, 0)); Specialized.connectors.Add("top", new Point(0, -25)); Specialized.connectors.Add("bottom", new Point(0, 25)); //Technology is yellow ellipse with a regular black border Technology = new GraphNodeStyle(); Technology.ellipse = true; Technology.fillBrush = new SolidBrush(Color.LemonChiffon); Technology.font = new Font("Tahoma", 8f, FontStyle.Regular); Technology.textBrush = new SolidBrush(Color.Black); Technology.borderPen = new Pen(Color.Black, 1f); Technology.connectors = new Dictionary <string, Point>(); Technology.connectors.Add("left", new Point(-50, 0)); Technology.connectors.Add("right", new Point(50, 0)); Technology.connectors.Add("top", new Point(0, 23)); Technology.connectors.Add("bottom", new Point(0, -23)); //Archival is a gray ellipse with a white border Archival = new GraphNodeStyle(); Archival.ellipse = true; Archival.fillBrush = new SolidBrush(Color.LightGray); Archival.font = new Font("Tahoma", 8f, FontStyle.Regular); Archival.textBrush = new SolidBrush(Color.Black); Archival.borderPen = new Pen(Color.White, 1f); Archival.connectors = new Dictionary <string, Point>(); Archival.connectors.Add("left", new Point(-50, 0)); Archival.connectors.Add("right", new Point(50, 0)); Archival.connectors.Add("top", new Point(0, -23)); Archival.connectors.Add("bottom", new Point(0, 23)); //Prereq edge style is a solid black arrow PrereqEdgeStyle = new Pen(Color.Black, 1f); AdjustableArrowCap cap = new AdjustableArrowCap(5f, 5f, true); cap.BaseInset = 5; cap.StrokeJoin = LineJoin.Bevel; PrereqEdgeStyle.EndCap = LineCap.Custom; PrereqEdgeStyle.CustomEndCap = cap; PrereqEdgeStyle.Width = 2f; //Grantreq edge style is a yellow-green dashed arrow GrantreqEdgeStyle = new Pen(Color.YellowGreen, 1f); GrantreqEdgeStyle.EndCap = LineCap.Custom; GrantreqEdgeStyle.CustomEndCap = cap; GrantreqEdgeStyle.DashStyle = DashStyle.Dash; GrantreqEdgeStyle.Width = 2f; //Initialize dictionary nodeStyles = new Dictionary <string, GraphNodeStyle>(); nodeStyles.Add("Foundational", Foundational); nodeStyles.Add("Topical", Topical); nodeStyles.Add("Specialized", Specialized); nodeStyles.Add("Technologies", Technology); nodeStyles.Add("Archival", Archival); }