예제 #1
0
        /// <summary>
        /// Convert an arrow shape into a string
        /// </summary>
        /// <param name="shape">Enumeration value to convert</param>
        /// <returns>String equivalent.</returns>
        private static string ValueOf(ArrowShape shape)
        {
            switch (shape)
            {
            case ArrowShape.Box:
                return("box");

            case ArrowShape.Crow:
                return("crow");

            case ArrowShape.Diamond:
                return("diamond");

            case ArrowShape.Dot:
                return("dot");

            case ArrowShape.Inv:
                return("inv");

            case ArrowShape.None:
                return("none");

            case ArrowShape.Normal:
                return("normal");

            case ArrowShape.Tee:
                return("tee");

            case ArrowShape.Vee:
                return("vee");

            default:
                return("normal");
            }
        }
예제 #2
0
        private void DrawMethod(CGNode node, ref Dictionary <CGNode, EllipseShape> visited)
        {
            ArrowShape arrow = null;
            // When autoSize is on the rectangle parameter will be 'ignored'.
            EllipseShape blockShape = new EllipseShape(new Rectangle(1, 1, 70, 70));

            blockShape.Title = String.Format("{0}", node.Method.Name);
            visited.Add(node, blockShape);
            scene.Shapes.Add(blockShape);

            ConnectorGluePoint gluePointStart = null;
            ConnectorGluePoint gluePointEnd   = null;

            foreach (CGNode child in node.MethodCalls)
            {
                DrawMethod(child, ref visited);
                gluePointStart = new ConnectorGluePoint(new PointD(visited[node].Location.X + visited[node].Width / 2, visited[node].Location.Y + visited[node].Height));
                gluePointEnd   = new ConnectorGluePoint(new PointD(visited[child].Location.X + visited[child].Width / 2, visited[child].Location.Y));

                arrow = new ArrowShape(visited[node], gluePointStart, visited[child], gluePointEnd);
                arrow.ArrowKindHead = SolidV.Cairo.ArrowKinds.TriangleRoundArrow;
                arrow.ArrowKindTail = SolidV.Cairo.ArrowKinds.NoArrow;

                gluePointEnd.Parent   = visited[child];
                gluePointStart.Parent = visited[node];

                scene.Shapes.Add(arrow);
                visited[node].Items.Add(gluePointStart);
                visited[child].Items.Add(gluePointEnd);
            }
        }
예제 #3
0
 private void host_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         switch (this.mouseState)
         {
         case MouseState.Connecting:
         {
             StateShape start = this.selectedShape as StateShape;
             StateShape end   = this.Manager.Pick(this.temporaryGraphics, e.Location + new Size(this.editor.ViewPosition)) as StateShape;
             if (start != null && end != null)
             {
                 ArrowShape arrow = new ArrowShape();
                 arrow.Start = start;
                 arrow.End   = end;
                 arrow.Name  = "New Arrow";
                 if (start == end)
                 {
                     arrow.ControlPoint = new Point(start.Position.X, start.Position.Y - start.Radius - 10);
                 }
                 else
                 {
                     arrow.ControlPoint = new Point((start.Position.X + end.Position.X) / 2, (start.Position.Y + end.Position.Y) / 2);
                 }
                 this.Manager.AddShape(arrow);
                 start.OutArrows.Add(arrow);
                 end.InArrows.Add(arrow);
                 UpdateViewSize();
             }
         }
         break;
         }
         this.mouseState = MouseState.Normal;
     }
 }
예제 #4
0
        private void FrmTool_Load(object sender, EventArgs e)
        {
            Rectangle rect = new Rectangle();

            rect.X    = 10; rect.Y = 10;
            rect.Size = new Size(LeMenu.Size * 2, LeMenu.Size * 2);

            btnCancel = new ArrowShape(rect.Location);
            btnCancel.Change();

            int i = 1;

            rect.X += rect.Width + 5;
            foreach (Type type in LeMenu.shapeMenus.Keys)
            {
                ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(Point) });
                LeShape         shape       = constructor.Invoke(new object[] { rect.Location }) as LeShape;
                shape.Boundary = rect;
                curTools.Add(shape);

                rect.X += rect.Width + 5;
                i++;
                if (i > 1)
                {
                    i       = 0;
                    rect.X  = 10;
                    rect.Y += rect.Height + 5;
                }
            }
        }
예제 #5
0
            private Tuple <Tuple <CompetitionClassState, CompetitionClassState>, ArrowShape> ComposeTransition(CompetitionClassState fromState,
                                                                                                               CompetitionClassState toState, HorizontalAlignment side, VerticalAlignment fromConnection, VerticalAlignment toConnection, int depth = 1)
            {
                Tuple <CompetitionClassState, CompetitionClassState> transition = GetTransition(fromState, toState);

                TextBlock fromBlock = owner.blocks.GetBlockForState(fromState);
                TextBlock toBlock   = owner.blocks.GetBlockForState(toState);

                PointF fromPoint = GetPointFor(fromBlock, side, fromConnection);
                PointF toPoint   = GetPointFor(toBlock, side, toConnection);

                ArrowShape arrow = CreateArrowFor(side, fromPoint, toPoint, depth);

                return(Tuple.Create(transition, arrow));
            }
예제 #6
0
        public void RenderGraph_givenArrowShape_generatesImage(
            [Values(ArrowShape.Box, ArrowShape.Crow, ArrowShape.Diamond, ArrowShape.Dot, ArrowShape.Inv, ArrowShape.None, ArrowShape.Normal, ArrowShape.Tee, ArrowShape.Vee)]
            ArrowShape arrowHead)
        {
            var edgeStyle = new EdgeStyle();

            edgeStyle.ArrowHead = arrowHead;

            var startStyles
                = new List <ArrowShape>
                {
                ArrowShape.Box,
                ArrowShape.Crow,
                ArrowShape.Diamond,
                ArrowShape.Dot,
                ArrowShape.Inv,
                ArrowShape.None,
                ArrowShape.Normal,
                ArrowShape.Tee,
                ArrowShape.Vee
                };

            var starts = new List <Node>();
            var edges  = new List <Edge>();
            var finish = new Node("finish", "Finish");

            foreach (var shape in startStyles)
            {
                var n = Enum.GetName(typeof(ArrowShape), shape);
                var s = new Node(n, n);
                edgeStyle.ArrowTail = shape;
                var e = new Edge(s, finish, edgeStyle);

                starts.Add(s);
                edges.Add(e);
            }

            var graphFactory = new GraphFactory();
            var graph        = graphFactory.CreateGraph(starts, finish, edges);

            var renderer = new DotRenderer(graph);

            var head     = Enum.GetName(typeof(ArrowShape), arrowHead);
            var filename = head + ".png";
            var image    = renderer.RenderImage();

            image.Save(filename);
        }
예제 #7
0
 private void host_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.A)
     {
         this.keyState = KeyState.Arrow;
     }
     else if (e.KeyCode == Keys.S)
     {
         this.keyState = KeyState.State;
     }
     else if (e.KeyCode == Keys.Delete)
     {
         if (this.selectedShape != null)
         {
             if (this.selectedShape is StateShape)
             {
                 StateShape state = (StateShape)this.selectedShape;
                 foreach (ArrowShape arrow in state.InArrows)
                 {
                     arrow.Start.OutArrows.Remove(arrow);
                     this.Manager.RemoveShape(arrow);
                 }
                 foreach (ArrowShape arrow in state.OutArrows)
                 {
                     arrow.End.InArrows.Remove(arrow);
                     this.Manager.RemoveShape(arrow);
                 }
                 this.Manager.RemoveShape(state);
             }
             else if (this.selectedShape is ArrowShape)
             {
                 ArrowShape arrow = (ArrowShape)this.selectedShape;
                 arrow.Start.OutArrows.Remove(arrow);
                 arrow.End.InArrows.Remove(arrow);
                 this.Manager.RemoveShape(arrow);
             }
             this.selectedShape = null;
             UpdateViewSize();
         }
     }
     else
     {
         this.keyState = KeyState.Normal;
     }
 }
예제 #8
0
        public void DrawFilter()
        {
            List <ArrowShape> arrows = new List <ArrowShape>();

            int          x = 100, y = 300;
            EllipseShape filter = new EllipseShape(new Cairo.Rectangle(x, y, 100, 50));

            filter.Style.Border = new SolidPattern(new Color(0, 0, 0));

            ConnectorGluePoint filterGlue = new ConnectorGluePoint(
                new PointD(filter.Location.X + (filter.Width / 2), filter.Location.Y));

            filter.Items.Add(filterGlue);
            filterGlue.Parent = filter;

            for (int i = 0; i < scene.Shapes.Count; i++)
            {
                var block = scene.Shapes[i];
                ConnectorGluePoint blockGlue = new ConnectorGluePoint(new PointD(block.Location.X
                                                                                 + block.Width / 2, block.Location.Y + block.Height));
                blockGlue.Parent = block;
                // Add the gluePoints to the shapes
                block.Items.Add(blockGlue);

                // Link the filter and the textBlock with an arrow
                ArrowShape arrow = new ArrowShape(block, blockGlue, filter, filterGlue);
                arrows.Add(arrow);
            }

            model.BeginUpdate();
            // Add all shapes to the scene
            scene.Shapes.Add(filter);
            foreach (ArrowShape a in arrows)
            {
                scene.Shapes.Add(a);
            }

            model.EndUpdate();
        }
예제 #9
0
        private void DrawBasicBlock(BasicBlock <Instruction> basicBlock,
                                    ref Dictionary <BasicBlock <Instruction>, TextBlockShape> visited)
        {
            if (visited.ContainsKey(basicBlock))
            {
                return;
            }

            ArrowShape arrow     = null;
            string     labelText = "";
            // When autoSize is on the rectangle parameter will be 'ignored'.
            TextBlockShape blockShape = new TextBlockShape(new Rectangle(1, 1, 50, 50), /*autosize*/ true);

            blockShape.Title     = String.Format("Block Name: {0}", basicBlock.Name);
            blockShape.BlockText = basicBlock.ToString();
            visited.Add(basicBlock, blockShape);
            scene.Shapes.Add(blockShape);

            ConnectorGluePoint gluePointStart = null;
            ConnectorGluePoint gluePointEnd   = null;

            SolidV.MVC.Label lb = null;

            foreach (BasicBlock <Instruction> successor in basicBlock.Successors)
            {
                DrawBasicBlock(successor, ref visited);

                gluePointStart = new ConnectorGluePoint(new PointD(visited[basicBlock].Location.X + visited[basicBlock].Width / 2, visited[basicBlock].Location.Y + visited[basicBlock].Height));
                gluePointEnd   = new ConnectorGluePoint(new PointD(visited[successor].Location.X + visited[successor].Width / 2, visited[successor].Location.Y));

                //arrow = new ArrowShape(visited[basicBlock], gluePointStart, visited[successor], gluePointEnd);
                arrow = new BezierCurvedArrowShape(visited[basicBlock], gluePointStart, visited[successor], gluePointEnd);
                arrow.ArrowKindHead = SolidV.Cairo.ArrowKinds.TriangleRoundArrow;
                arrow.ArrowKindTail = SolidV.Cairo.ArrowKinds.NoArrow;

                gluePointEnd.Parent   = visited[successor];
                gluePointStart.Parent = visited[basicBlock];

                switch (basicBlock.Last.OpCode.FlowControl)
                {
                case FlowControl.Cond_Branch:
                    if ((basicBlock.Last.Operand as Instruction).Offset == successor.First.Offset)
                    {
                        labelText = "IfTrue";
                    }
                    else
                    {
                        labelText = "IfFalse";
                    }
                    break;

                default:
                    labelText = "branch";
                    break;
                }

                lb        = new SolidV.MVC.Label(arrow, labelText);
                lb.Parent = arrow;
                arrow.Items.Add(lb);

                blockShape.Items.Add(arrow);

                visited[basicBlock].Items.Add(gluePointStart);
                visited[successor].Items.Add(gluePointEnd);
            }
        }
예제 #10
0
        public static string GenerateCSharpCode(ShapeManager manager, string namespaceName, string className)
        {
            string[] colorIds      = null;
            bool[]   partialStates = null;
            string[] stateIds      = null;
            int[]    charset       = null;
            int[,] transitions = null;
            int[] finalStateTokenIds = null;

            {
                List <StateShape> states = manager.Shapes[StateShape.StateShapeProprity]
                                           .Cast <StateShape>()
                                           .Where(s => s.Type == StateType.Start)
                                           .Concat(
                    manager.Shapes[StateShape.StateShapeProprity]
                    .Cast <StateShape>()
                    .Where(s => s.Type != StateType.Start)
                    )
                                           .ToList();

                List <ArrowShape> arrows = manager.Shapes[ArrowShape.ArrowShapeProprity]
                                           .Cast <ArrowShape>()
                                           .ToList();

                colorIds = manager.Shapes[StateShape.StateShapeProprity]
                           .Cast <StateShape>()
                           .Where(s => s.Type == StateType.Finish && !string.IsNullOrEmpty(s.Color))
                           .Select(s => s.Color)
                           .Distinct()
                           .ToArray();

                stateIds = states
                           .Select(s => s.Name)
                           .ToArray();

                partialStates = stateIds.Select(c => c.EndsWith("*")).ToArray();
                stateIds      = stateIds.Select(s => s.EndsWith("*") ? s.Substring(0, s.Length - 1) : s).ToArray();

                charset = CodeGeneratorHelper.MergeCharset(arrows.Select(a => CodeGeneratorHelper.GetCharsetFromArrow(a.Name)).ToArray());

                finalStateTokenIds =
                    states
                    .Select(s => Array.FindIndex(colorIds, x => s.Type == StateType.Finish && s.Color == x))
                    .ToArray();

                int fakeCharset = charset.Max() + 1;
                for (int i = 0; i < charset.Length; i++)
                {
                    if (charset[i] == -1)
                    {
                        charset[i] = fakeCharset;
                    }
                }
                transitions = new int[states.Count, fakeCharset + 1];
                for (int i = 0; i < states.Count; i++)
                {
                    StateShape state = states[i];
                    for (int j = 0; j <= fakeCharset; j++)
                    {
                        transitions[i, j] = -1;
                    }
                    for (int j = 0; j < state.OutArrows.Count; j++)
                    {
                        ArrowShape arrow    = state.OutArrows[j];
                        int[]      charsets = CodeGeneratorHelper.GetCharsetFromArrow(arrow.Name)
                                              .Select((b, c) => Tuple.Create(b, c))
                                              .Where(t => t.Item1)
                                              .Select(t => charset[t.Item2])
                                              .Distinct()
                                              .ToArray();
                        foreach (int k in charsets)
                        {
                            int end = states.IndexOf(arrow.End);
                            transitions[i, k] = end;
                        }
                    }
                }
            }
            return(GenerateCSharpCodeInternal(namespaceName, className, colorIds, stateIds, partialStates, charset, transitions, finalStateTokenIds));
        }