Example #1
0
        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);
        }
Example #2
0
 /// <summary>
 /// Creates a new instance of <see cref="GraphNodeStyle"/>.
 /// </summary>
 /// <param name="shape">The shape of the node.</param>
 /// <param name="fillColor">The fill color of the node.</param>
 /// <param name="lineColor">The line color of the node.</param>
 /// <param name="lineWidth">The line width of the node.</param>
 public GraphNodeStyle(GraphNodeShape shape, Color fillColor, Color lineColor, int lineWidth)
 {
     Shape     = shape;
     FillColor = fillColor;
     LineColor = lineColor;
     LineWidth = lineWidth;
 }
Example #3
0
        public void Convert_WithGraphNode_ReturnPointedTreeElementVertex(GraphNodeShape graphNodeShape,
                                                                         PointedTreeVertexType expectedVertexType)
        {
            // Setup
            var random = new Random(21);

            const string content      = "<text>Node</text>";
            bool         isSelectable = random.NextBoolean();
            int          lineWidth    = random.Next();
            Color        fillColor    = Color.Aquamarine;
            Color        lineColor    = Color.Coral;

            var graphNode = new GraphNode(content, new GraphNode[0], isSelectable,
                                          new GraphNodeStyle(graphNodeShape, fillColor,
                                                             lineColor, lineWidth));

            // Call
            PointedTreeElementVertex vertex = GraphNodeConverter.Convert(graphNode);

            // Assert
            Assert.AreEqual(content, vertex.Content);
            Assert.AreEqual(isSelectable, vertex.IsSelectable);
            Assert.AreEqual(expectedVertexType, vertex.Type);
            Assert.AreEqual(lineWidth, vertex.LineWidth);
            AssertColors(fillColor, vertex.FillColor);
            AssertColors(lineColor, vertex.LineColor);
        }
 private void AddNodeTemplate(string templateName, string nameTemplate, GraphNodeShape shape,
                              float width, float height, Color backColor, Color lineColor, Color selectedLineColor, Color textColor, Color hatchedColor, Type tagType)
 {
     if (typeof(BaseNodeConfig).IsAssignableFrom(tagType))
     {
         _templates[templateName] = new GraphNodeTemplate(nameTemplate, shape,
                                                          width, height, backColor, lineColor, selectedLineColor, textColor, hatchedColor, tagType);
     }
     else
     {
         throw new ArgumentException("Invalid node config type for editor template");
     }
 }
Example #5
0
        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);
        }
Example #6
0
        /// <summary>
        /// Converts a <see cref="GraphNodeShape"/> to a <see cref="PointedTreeVertexType"/>.
        /// </summary>
        /// <param name="shape">The shape to convert.</param>
        /// <returns>The converted <see cref="PointedTreeVertexType"/>.</returns>
        /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="shape"/>
        /// is an invalid value.</exception>
        /// <exception cref="NotSupportedException">Thrown when <paramref name="shape"/>
        /// is a valid value, but unsupported.</exception>
        private static PointedTreeVertexType ConvertType(GraphNodeShape shape)
        {
            if (!Enum.IsDefined(typeof(GraphNodeShape), shape))
            {
                throw new InvalidEnumArgumentException(nameof(shape),
                                                       (int)shape,
                                                       typeof(GraphNodeShape));
            }

            switch (shape)
            {
            case GraphNodeShape.Rectangle:
                return(PointedTreeVertexType.Rectangle);

            case GraphNodeShape.None:
                return(PointedTreeVertexType.None);

            default:
                throw new NotSupportedException();
            }
        }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="nameTemplate"></param>
 /// <param name="shape"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="backColor"></param>
 /// <param name="lineColor"></param>
 /// <param name="selectedLineColor"></param>
 /// <param name="textColor"></param>
 /// <param name="hatchedColor"></param>
 /// <param name="tagType"></param>
 public GraphNodeTemplate(string nameTemplate,
                          GraphNodeShape shape,
                          float width,
                          float height,
                          Color backColor,
                          Color lineColor,
                          Color selectedLineColor,
                          Color textColor,
                          Color hatchedColor,
                          Type tagType)
 {
     NameTemplate      = nameTemplate;
     Shape             = shape;
     Width             = width;
     Height            = height;
     BackColor         = backColor;
     LineColor         = lineColor;
     SelectedLineColor = selectedLineColor;
     TextColor         = textColor;
     HatchedColor      = hatchedColor;
     TagType           = tagType;
 }
Example #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="nameTemplate"></param>
 /// <param name="shape"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="backColor"></param>
 /// <param name="lineColor"></param>
 /// <param name="selectedLineColor"></param>
 /// <param name="textColor"></param>
 /// <param name="hatchedColor"></param>
 /// <param name="tagType"></param>
 public GraphNodeTemplate(string nameTemplate, 
     GraphNodeShape shape, 
     float width, 
     float height, 
     Color backColor, 
     Color lineColor, 
     Color selectedLineColor, 
     Color textColor, 
     Color hatchedColor, 
     Type tagType)
 {
     NameTemplate = nameTemplate;
     Shape = shape;
     Width = width;
     Height = height;
     BackColor = backColor;
     LineColor = lineColor;
     SelectedLineColor = selectedLineColor;
     TextColor = textColor;
     HatchedColor = hatchedColor;
     TagType = tagType;
 }
Example #9
0
        /// <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);
        }
Example #10
0
 /// <summary>
 /// Add a pre configured node to the graph
 /// </summary>
 /// <param name="p">The point location of the centre (in client 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>
 public GraphNode AddNode(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)
 {
     return(AddNodeInternal(ClientToDocumentPoint(p), z, id, name, shape, width, height,
                            backColor, lineColor, selectedLineColor, textColor, hatchedColor, tag));
 }
Example #11
0
        /// <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;
        }
Example #12
0
 /// <summary>
 /// Add a pre configured node to the graph
 /// </summary>
 /// <param name="p">The point location of the centre (in client 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>
 public GraphNode AddNode(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)
 {
     return AddNodeInternal(ClientToDocumentPoint(p), z, id, name, shape, width, height,
         backColor, lineColor, selectedLineColor, textColor, hatchedColor, tag);
 }
Example #13
0
 private void AddNodeTemplate(string templateName, string nameTemplate, GraphNodeShape shape, 
     float width, float height, Color backColor, Color lineColor, Color selectedLineColor, Color textColor, Color hatchedColor, Type tagType)
 {
     if (typeof(BaseNodeConfig).IsAssignableFrom(tagType))
     {
         _templates[templateName] = new GraphNodeTemplate(nameTemplate, shape,
             width, height, backColor, lineColor, selectedLineColor, textColor, hatchedColor, tagType);
     }
     else
     {
         throw new ArgumentException("Invalid node config type for editor template");
     }
 }