public LogicalImageGenerator(ImageConstraints constraints)
 {
     _imageConstraints = constraints;
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Count() < 3)
            {
                Console.WriteLine("Arguments: <diagram_type> <number of images> <generated images path> ");
                Environment.Exit(1);
            }


            String diagram   = args[0].ToLower();
            int    numDiag   = Int32.Parse(args[1]);
            String directory = args[2];


            //specify diagram type here
            DiagramType diagramType;

            switch (diagram)
            {
            case "flowchart":
                diagramType = DiagramType.FlowChart;
                break;

            case "sequencediagram":
                diagramType = DiagramType.SequenceDiagram;
                break;

            case "statediagram":
                diagramType = DiagramType.StateDiagram;
                break;

            default:
                diagramType = DiagramType.FlowChart;
                break;
            }


            ImageLayout.ImageConstraints constraints = new ImageLayout.ImageConstraints();
            switch (diagramType)
            {
            case DiagramType.FlowChart:
                constraints.Width         = 299; constraints.Height = 299;
                constraints.AllowedShapes = new List <ShapeType>()
                {
                    ShapeType.Circle, ShapeType.Ellipse, ShapeType.Rectangle, ShapeType.Rhombus, ShapeType.Parallelogram
                };
                constraints.MandatoryShapes = new List <ShapeType>()
                {
                    ShapeType.Ellipse
                };
                constraints.SingleOccurrenceShapes = new List <ShapeType>()
                {
                    ShapeType.Ellipse
                };
                constraints.MaxShapes = 8; constraints.MinShapes = 3;

                constraints.ShapeConstraints.Add(ShapeType.Ellipse,
                                                 new ShapeConstraints()
                {
                    HasFixedLocation = true,
                    MinInDegree      = 0,
                    MaxInDegree      = 0,
                    MinOutDegree     = 1,
                    MaxOutDegree     = 1
                });

                var stopConstraints = new ShapeConstraints()
                {
                    PlacementConstraint = (row, col) => row > 0,
                    HasFixedLocation    = false,
                    MinInDegree         = 1,
                    MaxInDegree         = Int32.MaxValue,
                    MaxOutDegree        = 0,
                    MinOutDegree        = 0
                };

                constraints.ShapeConstraints.Add(ShapeType.Circle, stopConstraints);

                var processConstraints = new ShapeConstraints(stopConstraints);
                processConstraints.MaxInDegree  = 1;
                processConstraints.MinInDegree  = 1;
                processConstraints.MaxOutDegree = 1;
                processConstraints.MinOutDegree = 1;

                var conditionConstraints = new ShapeConstraints(stopConstraints);
                conditionConstraints.MaxInDegree  = 1;
                conditionConstraints.MaxOutDegree = 4;
                conditionConstraints.MinInDegree  = 1;
                conditionConstraints.MinOutDegree = 2;

                constraints.ShapeConstraints.Add(ShapeType.Rectangle, processConstraints);
                constraints.ShapeConstraints.Add(ShapeType.Parallelogram, processConstraints);
                constraints.ShapeConstraints.Add(ShapeType.Rhombus, conditionConstraints);
                break;

            case DiagramType.StateDiagram:
                constraints.Width         = 299; constraints.Height = 299;
                constraints.AllowedShapes = new List <ShapeType>()
                {
                    ShapeType.Circle, ShapeType.Ellipse, ShapeType.Rectangle
                };
                constraints.MaxShapes      = 4; constraints.MinShapes = 3;
                constraints.SameTypeShapes = true;

                var stateConstraints = new ShapeConstraints();
                stateConstraints.MaxInDegree  = 4;
                stateConstraints.MaxOutDegree = 4;
                stateConstraints.MinInDegree  = 1;
                stateConstraints.MinOutDegree = 1;

                constraints.ShapeConstraints.Add(ShapeType.Rectangle, stateConstraints);
                constraints.ShapeConstraints.Add(ShapeType.Circle, stateConstraints);
                constraints.ShapeConstraints.Add(ShapeType.Ellipse, stateConstraints);

                break;

            case DiagramType.SequenceDiagram:
                constraints.Width         = 299; constraints.Height = 299;
                constraints.AllowedShapes = new List <ShapeType>()
                {
                    ShapeType.Rectangle
                };
                constraints.MaxShapes      = 6; constraints.MinShapes = 3;
                constraints.SameTypeShapes = true;

                var objectConstraints = new ShapeConstraints();
                objectConstraints.MaxInDegree  = 4;
                objectConstraints.MaxOutDegree = 4;
                objectConstraints.MinInDegree  = 1;
                objectConstraints.MinOutDegree = 1;

                constraints.ShapeConstraints.Add(ShapeType.Rectangle, objectConstraints);
                break;
            }

            LogicalImageGenerator generator = new LogicalImageGenerator(constraints);
            int i = 1;

            if (diagramType == DiagramType.FlowChart || diagramType == DiagramType.StateDiagram)
            {
                foreach (var image in generator.GenerateImage(100))
                {
                    if (i > numDiag)
                    {
                        break;
                    }
                    Console.WriteLine($"Figure: {i}");
                    //printImage(image, constraints);
                    build_image(directory, image, constraints, i);
                    i++;
                }
            }
            else if (diagramType == DiagramType.SequenceDiagram)
            {
                foreach (var image in generator.GenerateImage(100))
                {
                    if (i > numDiag)
                    {
                        break;
                    }
                    Console.WriteLine($"Figure: {i}");
                    //printImage(image, constraints);
                    build_image_sd(directory, image, constraints, i);
                    i++;
                }
            }
        }