コード例 #1
0
        public void BuildChildGroups(List <BoundingBox> boxes, ProjectionAxisEnum axis, GroupBox parent)
        {
            GroupBox g = new GroupBox();

            g.IsEmpty = false;


            if (axis == ProjectionAxisEnum.X)
            {
                g.Direction = GroupBox.GroupDirectionEnum.Horizontal;
            }
            else
            {
                g.Direction = GroupBox.GroupDirectionEnum.Vertical;
            }

            parent.Groups.Add(g);

            if (boxes.Count > 1)
            {
                g.X      = boxes.Min(p => p.Left);
                g.Y      = boxes.Min(p => p.Top);
                g.Width  = boxes.Max(p => p.Width);
                g.Height = boxes.Max(p => p.Height);

                ProjectionRuler ruler = BuildProjectionRuler(boxes, axis);

                foreach (Section sec in ruler.Sections)
                {
                    if (axis == ProjectionAxisEnum.X)
                    {
                        BuildChildGroups(sec.Boxes, ProjectionAxisEnum.Y, g);
                    }
                    else
                    {
                        BuildChildGroups(sec.Boxes, ProjectionAxisEnum.X, g);
                    }
                }
            }
            else
            {
                if (boxes.Count == 0)
                {
                    g.IsEmpty = true;
                }
                if (boxes.Count == 1)
                {
                    g.X      = boxes.Min(p => p.Left);
                    g.Y      = boxes.Min(p => p.Top);
                    g.Width  = boxes.Max(p => p.Width);
                    g.Height = boxes.Max(p => p.Height);

                    //Add the box to the structure
                    g.Boxes.Add(boxes[0]);

                    CalculateAlignments(g);
                }
            }
        }
コード例 #2
0
ファイル: Geometry.cs プロジェクト: mohitchhabra/Sketch2Code
        public ProjectionRuler BuildProjectionRuler(List <BoundingBox> boxes, ProjectionAxisEnum axis)
        {
            ProjectionRuler ruler = new ProjectionRuler();

            List <SliceSection> slices = buildSlices(boxes, axis);

            fillSlices(boxes, slices, axis);

            Section s = new Section();

            s.Slices.Add(slices[0]);
            ruler.Sections.Add(s);

            bool isEmpty = false;

            for (int i = 1; i < slices.Count; i++)
            {
                if (!isEmpty)
                {
                    if (slices[i].IsEmpty)
                    {
                        //close previous section
                        s = new Section();
                        s.Slices.Add(slices[i]);
                        isEmpty = true;
                        ruler.Sections.Add(s);
                    }
                    else
                    {
                        //modify previous section
                        s.Slices.Add(slices[i]);
                    }
                }
                else
                {
                    if (!slices[i].IsEmpty)
                    {
                        //close previous section
                        s = new Section();
                        s.Slices.Add(slices[i]);
                        isEmpty = false;
                        ruler.Sections.Add(s);
                    }
                    else
                    {
                        //modify previous section
                        s.Slices.Add(slices[i]);
                    }
                }
            }

            return(ruler);
        }
コード例 #3
0
ファイル: Geometry.cs プロジェクト: mohitchhabra/Sketch2Code
        public void BuildChildGroups(List <BoundingBox> boxes, ProjectionAxisEnum axis, GroupBox parent)
        {
            LoopCounter++;
            if (LoopCounter > 500)
            {
                // Hack to avoid the StackOverflow crash which is caused by recursively calling this function.
                // This hack will result in an image being generated without crashing the application.
                return;
            }
            GroupBox g = new GroupBox();

            g.IsEmpty = false;


            if (axis == ProjectionAxisEnum.X)
            {
                g.Direction = GroupBox.GroupDirectionEnum.Horizontal;
            }
            else
            {
                g.Direction = GroupBox.GroupDirectionEnum.Vertical;
            }

            parent.Groups.Add(g);

            if (boxes.Count > 1)
            {
                g.X      = boxes.Min(p => p.Left);
                g.Y      = boxes.Min(p => p.Top);
                g.Width  = boxes.Max(p => p.Width);
                g.Height = boxes.Max(p => p.Height);

                ProjectionRuler ruler = BuildProjectionRuler(boxes, axis);

                foreach (Section sec in ruler.Sections)
                {
                    if (axis == ProjectionAxisEnum.X)
                    {
                        BuildChildGroups(sec.Boxes, ProjectionAxisEnum.Y, g);
                    }
                    else
                    {
                        BuildChildGroups(sec.Boxes, ProjectionAxisEnum.X, g);
                    }
                }
            }
            else
            {
                if (boxes.Count == 0)
                {
                    g.IsEmpty = true;
                }
                if (boxes.Count == 1)
                {
                    g.X      = boxes.Min(p => p.Left);
                    g.Y      = boxes.Min(p => p.Top);
                    g.Width  = boxes.Max(p => p.Width);
                    g.Height = boxes.Max(p => p.Height);

                    //Add the box to the structure
                    g.Boxes.Add(boxes[0]);

                    CalculateAlignments(g);
                }
            }
        }