Exemplo n.º 1
0
        private void DoLocationLayout(Node[] nodearray, double xlimit, int climit, double spacex, double spacey)
        {
            // calculate how wide each cell should be
            double cellW = Math.Max(this.CellSize.Width, 1);
            double cellL = 0;
            double cellR = 0;

            foreach (Node n in nodearray)
            {
                Size sz = n.GetEffectiveSize(null);
                // when AlignsLocation, accumulate separate maximums for left of the Location, and for right
                Point relloc = n.GetRelativeElementPoint(n.LocationElement, n.LocationSpot);
                cellL = Math.Max(cellL, relloc.X);
                cellR = Math.Max(cellR, sz.Width - relloc.X);
            }
            // account for space; which side depends on Arrangement
            GridArrangement arr = this.Arrangement;

            switch (arr)
            {
            case GridArrangement.RightToLeft: cellL += spacex; break;

            default:                          cellR += spacex; break;
            }
            if (Double.IsNaN(cellW) || Double.IsInfinity(cellW)) // unknown -- calculate maximums
            {
                cellW = Math.Max(cellL + cellR, 1);
            }
            else
            {
                cellW = Math.Max(cellW + spacex, 1);
            }

            // calculate how tall each cell should be
            double cellH = Math.Max(this.CellSize.Height, 1);
            double cellT = 0;
            double cellB = 0;

            foreach (Node n in nodearray)
            {
                Size sz = n.GetEffectiveSize(null);
                // when AlignsLocation, accumulate separate maximums for above the Location, and for below
                Point relloc = n.GetRelativeElementPoint(n.LocationElement, n.LocationSpot);
                cellT = Math.Max(cellT, relloc.Y);
                cellB = Math.Max(cellB, sz.Height - relloc.Y);
            }
            // assume all space on bottom
            cellB += spacey;
            if (Double.IsNaN(cellH) || Double.IsInfinity(cellH)) // unknown -- calculate maximums
            {
                cellH = Math.Max(cellT + cellB, 1);
            }
            else
            {
                cellH = Math.Max(cellH + spacey, 1);
            }

            this.ActualCellSize = new Size(cellW, cellH);

            // iterate through the nodes, placing each node's Location at (X,Y)
            double originx   = this.ArrangementOrigin.X;
            double originy   = this.ArrangementOrigin.Y;
            double x         = originx;
            double y         = originy;
            int    rowcount  = 0;
            double rowheight = 0;

            // changed to fix problems with distance betwen rows
            double maxhei = 0;

            foreach (Node n in nodearray)
            {
                maxhei = Math.Max(maxhei, n.GetEffectiveSize(null).Height);
            }
            double rowhei = Math.Max(maxhei + spacey, cellH);
            //Diagram.Debug("GivenCellSize: " + Diagram.Str(this.CellSize) + "  ActualCellSize: " + Diagram.Str(this.ActualCellSize) + "  rowhei: " + Diagram.Str(rowhei));
            double xpos = 0;

            foreach (Node n in nodearray)
            {
                // figure out how many cells the node needs
                Size  sz     = n.GetEffectiveSize(null);
                Point relloc = n.GetRelativeElementPoint(n.LocationElement, n.LocationSpot);
                // assign new node Position
                if (rowcount > 0)
                {
                    switch (arr)
                    {
                    case GridArrangement.RightToLeft: x = Math.Floor((x - originx - (sz.Width - relloc.X)) / cellW) * cellW + originx; break;

                    default: x = Math.Ceiling((x - originx + relloc.X) / cellW) * cellW + originx; break;
                    }
                }
                else // rowcount == 0
                {
                    switch (arr)
                    {
                    case GridArrangement.RightToLeft: xpos = n.Position.X + sz.Width; break;

                    default: xpos = n.Position.X; break;
                    }
                }
                // maybe need to wrap to next row
                double needed;
                // subtract the stuff sticking out beyond the end of the grid from the XLIMIT
                // changed fix problems with premature wrapping with RTL
                switch (arr)
                {
                case GridArrangement.RightToLeft: needed = -(x + relloc.X) + originx + xpos; break;

                default: needed = x + sz.Width - relloc.X - originx - xpos; break;
                }

                // check the column limit or the width limit or both
                //Diagram.Debug(xlimit.ToString() + " " + needed.ToString() + " x: " + x.ToString() + " " + Diagram.Str(sz) + " " + relloc.X.ToString() + " " + n.ToString());
                if ((climit > 0 && rowcount > climit - 1) || (xlimit > 0 && rowcount > 0 && needed > xlimit))
                {
                    rowcount = 0;
                    x        = originx;

                    // changed to fix problems with row spacing
                    y += rowhei;

                    rowheight = 0; // minimum rowheight is the maximum amount above location point
                }
                // consider the height of the node below the location point
                rowheight = Math.Max(rowheight, Math.Ceiling(((sz.Height - relloc.Y) + spacey) / cellH) * cellH);
                // the Position is just the Location minus the RelativeElementPoint
                //Diagram.Debug("gridlayout: " + Diagram.Str(new Point(x-relloc.X, y-relloc.Y)) + n.ToString());
                Move(n, new Point(x - relloc.X, y - relloc.Y));

                // changed to account for space
                // advance to next column
                switch (arr)
                {
                case GridArrangement.RightToLeft: x -= relloc.X + spacex; break;

                default:                          x += sz.Width - relloc.X + spacex; break;
                }
                rowcount++;
            }
        }
Exemplo n.º 2
0
        private void DoPositionLayout(Node[] nodearray, double xlimit, int climit, double spacex, double spacey)
        {
            // calculate how wide each cell should be
            double cellW = Math.Max(this.CellSize.Width, 1);

            if (Double.IsNaN(cellW) || Double.IsInfinity(cellW)) // unknown -- calculate maximums
            {
                cellW = 0;
                foreach (Node n in nodearray)
                {
                    Size sz = n.GetEffectiveSize(null);
                    cellW = Math.Max(cellW, sz.Width);
                }
            }
            cellW += spacex;
            cellW  = Math.Max(cellW, 1);

            // calculate how tall each cell should be
            double cellH = Math.Max(this.CellSize.Height, 1);

            if (Double.IsNaN(cellH) || Double.IsInfinity(cellH))
            {
                cellH = 0;
                foreach (Node n in nodearray)
                {
                    Size sz = n.GetEffectiveSize(null);
                    cellH = Math.Max(cellH, sz.Height);
                }
            }
            cellH += spacey;
            cellH  = Math.Max(cellH, 1);

            this.ActualCellSize = new Size(cellW, cellH);

            // iterate through the nodes, placing each one
            GridArrangement arr       = this.Arrangement;
            double          originx   = this.ArrangementOrigin.X;
            double          originy   = this.ArrangementOrigin.Y;
            double          x         = originx;
            double          y         = originy;
            int             rowcount  = 0;
            double          rowheight = 0;

            foreach (Node n in nodearray)
            {
                // figure out how many cells the node needs
                Size   sz  = n.GetEffectiveSize(null);
                double w   = Math.Ceiling((sz.Width + spacex) / cellW);
                double h   = Math.Ceiling((sz.Height + spacey) / cellH);
                Size   csz = new Size(w * cellW, h * cellH);

                // maybe need to wrap to next row
                double needed;
                switch (arr)
                {
                case GridArrangement.RightToLeft: needed = Math.Abs(x - sz.Width) + originx; break;

                default:                          needed = x + sz.Width - originx; break;
                }
                // changed to account for location of origin
                if ((climit > 0 && rowcount > climit - 1) || (xlimit > 0 && rowcount > 0 && needed > xlimit))
                {
                    rowcount  = 0;
                    x         = originx;
                    y        += rowheight;
                    rowheight = 0;
                }

                rowheight = Math.Max(rowheight, csz.Height);

                // assign new node Position
                double coff;
                switch (arr)
                {
                case GridArrangement.RightToLeft: coff = -sz.Width; break;

                default:                          coff = 0; break;
                }
                Move(n, new Point(x + coff, y));

                // advance to next column
                switch (arr)
                {
                case GridArrangement.RightToLeft: x -= csz.Width; break;

                default:                          x += csz.Width; break;
                }
                rowcount++;
            }
        }