/// <summary> /// Add a pre configured node to the graph /// </summary> /// <param name="p">The point location of the centre (in document co-ordinates)</param> /// <param name="z">The z level of the node</param> /// <param name="id">The ID of the node</param> /// <param name="name">The text for the node</param> /// <param name="shape">The shape type</param> /// <param name="width">The width</param> /// <param name="height">The height</param> /// <param name="backColor">The back color</param> /// <param name="lineColor">The line color</param> /// <param name="selectedLineColor">The selected line color</param> /// <param name="textColor">The text color</param> /// <param name="hatchedColor">The hatched color</param> /// <param name="tag">A opaque object to store in the node</param> /// <exception cref="System.ArgumentException">Throw if node shape is unknown</exception> /// <returns>The created node</returns> private GraphNode AddNodeInternal(PointF p, float z, Guid id, string name, GraphNodeShape shape, float width, float height, Color backColor, Color lineColor, Color selectedLineColor, Color textColor, Color hatchedColor, object tag) { GraphNode s; switch (shape) { case GraphNodeShape.Ellipse: s = new GraphNodeCircle(id, CreateBoundary(p, width, height), z, backColor, lineColor, selectedLineColor, textColor, hatchedColor); break; case GraphNodeShape.Rectangle: s = new GraphNodeRectangle(id, CreateBoundary(p, width, height), z, backColor, lineColor, selectedLineColor, textColor, hatchedColor); break; case GraphNodeShape.RoundedRectangle: s = new GraphNodeRoundedRectangle(id, CreateBoundary(p, width, height), z, backColor, lineColor, selectedLineColor, textColor, hatchedColor); break; case GraphNodeShape.Triangle: s = new GraphNodeTriangle(id, CreateBoundary(p, width, height), z, backColor, lineColor, selectedLineColor, textColor, hatchedColor); break; case GraphNodeShape.Rhombus: s = new GraphNodeRhombus(id, CreateBoundary(p, width, height), z, backColor, lineColor, selectedLineColor, textColor, hatchedColor); break; default: throw new ArgumentException(CANAPE.Controls.GraphEditor.Properties.Resources.GraphEditorControl_InvalidNodeType); } GraphLine line = GetHitObjectInternal(p) as GraphLine; if (line != null) { if (MessageBox.Show(this, CANAPE.Controls.GraphEditor.Properties.Resources.GraphEditorControl_SplitLineMessage, CANAPE.Controls.GraphEditor.Properties.Resources.GraphEditorControl_SplitLineCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string label = line.Label; _lines.Remove(line); if (_selectedObject == line) { SelectedObject = null; } AddNewLine(line.SourceShape, s, line.BiDirection, label); AddNewLine(s, line.DestShape, line.BiDirection, null); } } s.Label = name; s.Tag = tag; _nodes.Add(s); // Use the move location function to adjust the position to fit within the boundary s.MoveLocation(new SizeF(), new RectangleF(0, 0, DocumentWidth, DocumentHeight)); Dirty = true; Invalidate(); return(s); }
/// <summary> /// Add a pre configured node to the graph /// </summary> /// <param name="p">The point location of the centre (in document co-ordinates)</param> /// <param name="z">The z level of the node</param> /// <param name="id">The ID of the node</param> /// <param name="name">The text for the node</param> /// <param name="shape">The shape type</param> /// <param name="width">The width</param> /// <param name="height">The height</param> /// <param name="backColor">The back color</param> /// <param name="lineColor">The line color</param> /// <param name="selectedLineColor">The selected line color</param> /// <param name="textColor">The text color</param> /// <param name="hatchedColor">The hatched color</param> /// <param name="tag">A opaque object to store in the node</param> /// <exception cref="System.ArgumentException">Throw if node shape is unknown</exception> /// <returns>The created node</returns> private GraphNode AddNodeInternal(PointF p, float z, Guid id, string name, GraphNodeShape shape, float width, float height, Color backColor, Color lineColor, Color selectedLineColor, Color textColor, Color hatchedColor, object tag) { GraphNode s; switch (shape) { case GraphNodeShape.Ellipse: s = new GraphNodeCircle(id, CreateBoundary(p, width, height), z, backColor, lineColor, selectedLineColor, textColor, hatchedColor); break; case GraphNodeShape.Rectangle: s = new GraphNodeRectangle(id, CreateBoundary(p, width, height), z, backColor, lineColor, selectedLineColor, textColor, hatchedColor); break; case GraphNodeShape.RoundedRectangle: s = new GraphNodeRoundedRectangle(id, CreateBoundary(p, width, height), z, backColor, lineColor, selectedLineColor, textColor, hatchedColor); break; case GraphNodeShape.Triangle: s = new GraphNodeTriangle(id, CreateBoundary(p, width, height), z, backColor, lineColor, selectedLineColor, textColor, hatchedColor); break; case GraphNodeShape.Rhombus: s = new GraphNodeRhombus(id, CreateBoundary(p, width, height), z, backColor, lineColor, selectedLineColor, textColor, hatchedColor); break; default: throw new ArgumentException(CANAPE.Controls.GraphEditor.Properties.Resources.GraphEditorControl_InvalidNodeType); } GraphLine line = GetHitObjectInternal(p) as GraphLine; if (line != null) { if (MessageBox.Show(this, CANAPE.Controls.GraphEditor.Properties.Resources.GraphEditorControl_SplitLineMessage, CANAPE.Controls.GraphEditor.Properties.Resources.GraphEditorControl_SplitLineCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string label = line.Label; _lines.Remove(line); if (_selectedObject == line) { SelectedObject = null; } AddNewLine(line.SourceShape, s, line.BiDirection, label); AddNewLine(s, line.DestShape, line.BiDirection, null); } } s.Label = name; s.Tag = tag; _nodes.Add(s); // Use the move location function to adjust the position to fit within the boundary s.MoveLocation(new SizeF(), new RectangleF(0, 0, MAX_DOCUMENT_WIDTH, MAX_DOCUMENT_HEIGHT)); Dirty = true; Invalidate(); return s; }