internal override ImpositionSolution GenerateSolution(ImpositionPattern pattern, bool orthoImp)
        {
            // instantiate solution
            ImpositionSolution solution = new ImpositionSolution(InitialEntities, pattern.Name, orthoImp, pattern.RequiresRotationInRows, pattern.RequiresRotationInColumns);

            // pattern box
            Box2D boxPattern = pattern.BBox;

            // compute max number of patterns
            int noPatternX = NoPatternX(pattern);
            int noPatternY = NoPatternY(pattern);

            int[,] rowNumber = new int[pattern.NoRows, pattern.NoCols];
            int[,] colNumber = new int[pattern.NoRows, pattern.NoCols];

            int iMax = -1, jMax = -1;

            for (int i = 0; i < pattern.NoRows; ++i)
            {
                for (int j = 0; j < pattern.NoCols; ++j)
                {
                    if (pattern._bboxes[i, j].XMax + noPatternX * pattern.PatternStep.X - boxPattern.XMin < UsableFormat.Width)
                    {
                        rowNumber[i, j] = noPatternX + 1;
                        iMax            = i;
                    }
                    else
                    {
                        rowNumber[i, j] = noPatternX;
                    }

                    if (pattern._bboxes[i, j].YMax + noPatternY * pattern.PatternStep.Y - boxPattern.YMin < UsableFormat.Height)
                    {
                        colNumber[i, j] = noPatternY + 1;
                        jMax            = j;
                    }
                    else
                    {
                        colNumber[i, j] = noPatternY;
                    }
                }
            }

            // compute actual margin
            Box2D boxGen = Box2D.Initial;

            for (int i = 0; i < pattern.NoRows; ++i)
            {
                for (int j = 0; j < pattern.NoCols; ++j)
                {
                    for (int k = 0; k < rowNumber[i, j]; ++k)
                    {
                        for (int l = 0; l < colNumber[i, j]; ++l)
                        {
                            Vector2D vPatternStep = new Vector2D(k * pattern.PatternStep.X, l * pattern.PatternStep.Y);
                            boxGen.Extend(pattern._bboxes[i, j].PtMin + vPatternStep);
                            boxGen.Extend(pattern._bboxes[i, j].PtMax + vPatternStep);
                        }
                    }
                }
            }
            if (!boxGen.IsValid)
            {
                return(solution);
            }

            #region Additional both direction
            // ****
            // get remaining space in length and width
            double remainingX = UsableFormat.Width - boxGen.Width - SpaceBetween.X;
            double remainingY = UsableFormat.Height - boxGen.Height - SpaceBetween.Y;

            // here compute additionnal poses on right
            Box2D            bboxRight = Box2D.Initial;
            List <BPosition> lPosRight = new List <BPosition>();
            if (AllowBothDirection)
            {
                Vector2D vLowerLeft = new Vector2D(boxGen.PtMax.X, boxGen.PtMin.Y);
                Vector2D vTopRight  = vLowerLeft + new Vector2D(remainingX, UsableFormat.Height);
                if (ComputePositionDefault(InitialEntities, new Box2D(vLowerLeft, vTopRight), SpaceBetween, ref lPosRight, ref bboxRight))
                {
                    boxGen.Extend(bboxRight);
                }
            }
            // here compute additionnal poses on top
            Box2D            bboxTop = Box2D.Initial;
            List <BPosition> lPosTop = new List <BPosition>();
            if (AllowBothDirection)
            {
                Vector2D vLowerLeft = new Vector2D(boxGen.PtMin.X, boxGen.PtMax.Y);
                Vector2D vTopRight  = vLowerLeft + new Vector2D(UsableFormat.Width, remainingY);

                if (ComputePositionDefault(InitialEntities, new Box2D(vLowerLeft, vTopRight), SpaceBetween, ref lPosTop, ref bboxTop))
                {
                    boxGen.Extend(bboxTop);
                }
            }
            // ****
            #endregion

            double xMargin = 0.0;
            switch (HorizontalAlignment)
            {
            case ImpositionSettings.HAlignment.HALIGN_LEFT: xMargin = UsableFormat.XMin; break;

            case ImpositionSettings.HAlignment.HALIGN_RIGHT: xMargin = FormatDimensions.X - Margin.X - boxGen.Width; break;

            case ImpositionSettings.HAlignment.HALIGN_CENTER: xMargin = (FormatDimensions.X - boxGen.Width) * 0.5; break;

            default: break;
            }

            double yMargin = 0.0;
            switch (VerticalAlignment)
            {
            case ImpositionSettings.VAlignment.VALIGN_BOTTOM: yMargin = UsableFormat.YMin; break;

            case ImpositionSettings.VAlignment.VALIGN_TOP: yMargin = FormatDimensions.Y - Margin.Y - boxGen.Height; break;

            case ImpositionSettings.VAlignment.VALIGN_CENTER: yMargin = (FormatDimensions.Y - boxGen.Height) * 0.5; break;

            default: break;
            }

            // compute offsets
            Vector2D vOffset = new Vector2D(xMargin - boxPattern.XMin, yMargin - boxPattern.YMin);

            for (int i = 0; i < pattern.NoRows; ++i)
            {
                for (int j = 0; j < pattern.NoCols; ++j)
                {
                    for (int k = 0; k < rowNumber[i, j]; ++k)
                    {
                        for (int l = 0; l < colNumber[i, j]; ++l)
                        {
                            BPosition pos = pattern._relativePositions[i, j];
                            pos.Pt = vOffset + new Vector2D(
                                k * pattern.PatternStep.X + pos.Pt.X
                                , l * pattern.PatternStep.Y + pos.Pt.Y);
                            solution.Add(pos);
                        }
                    }
                }
            }
            foreach (var p in lPosRight)
            {
                solution.Add(new BPosition(p.Pt + vOffset + SpaceBetween.X * Vector2D.XAxis, p.Angle));
            }
            foreach (var p in lPosTop)
            {
                solution.Add(new BPosition(p.Pt + vOffset + SpaceBetween.Y * Vector2D.YAxis, p.Angle));
            }
            // noRows / noCols
            solution.Rows = pattern.NoCols * noPatternX + iMax + 1;
            solution.Cols = pattern.NoRows * noPatternY + jMax + 1;
            // cardboard position
            solution.CardboardPosition   = Vector2D.Zero;
            solution.CardboardDimensions = FormatDimensions;
            return(solution);
        }
Example #2
0
        internal override ImpositionSolution GenerateSolution(ImpositionPattern pattern)
        {
            // instantiate solution
            ImpositionSolution solution = new ImpositionSolution(InitialEntities, pattern.Name, pattern.RequiresRotationInRows, pattern.RequiresRotationInColumns);

            // noRows / noCols
            solution.Rows = NoRowsExpected;
            solution.Cols = NoColsExpected;

            // number of each row / col of the pattern
            int[,] rowNumber = new int[pattern.NoRows, pattern.NoCols];
            int[,] colNumber = new int[pattern.NoRows, pattern.NoCols];

            int iCount = 0;

            for (int i = 0; i < pattern.NoRows; ++i)
            {
                for (int j = 0; j < pattern.NoCols; ++j)
                {
                    colNumber[i, j] = NoRowsExpected / pattern.NoRows + (NoRowsExpected % pattern.NoRows) / (i + 1);
                    rowNumber[i, j] = NoColsExpected / pattern.NoCols + (NoColsExpected % pattern.NoCols) / (j + 1);

                    iCount += rowNumber[i, j] * colNumber[i, j];
                }
            }
            // verify count
            System.Diagnostics.Debug.Assert(iCount == NoRowsExpected * NoColsExpected);

            // compute offsets
            Box2D  boxGlobal = pattern.BBox;
            double xOffset   = _margin.X - boxGlobal.XMin;
            double yOffset   = _margin.Y - boxGlobal.YMin;

            _box = new Box2D();
            for (int i = 0; i < pattern.NoRows; ++i)
            {
                for (int j = 0; j < pattern.NoCols; ++j)
                {
                    Box2D localBox = pattern._bboxes[i, j];
                    for (int k = 0; k < rowNumber[i, j]; ++k)
                    {
                        for (int l = 0; l < colNumber[i, j]; ++l)
                        {
                            // insert Box position
                            BPosition pos = pattern._relativePositions[i, j];
                            pos._pt.X = xOffset + k * pattern.PatternStep.X + pos._pt.X;
                            pos._pt.Y = yOffset + l * pattern.PatternStep.Y + pos._pt.Y;
                            solution.Add(pos);
                            // extend bounding box
                            Vector2D vOffset = new Vector2D(xOffset + k * pattern.PatternStep.X, yOffset + l * pattern.PatternStep.Y);
                            _box.Extend(new Box2D(vOffset + localBox.PtMin, vOffset + localBox.PtMax));
                        }
                    }
                }
            }

            // compute actual margin
            solution.CardboardPosition   = new Vector2D(_margin.X, _margin.Y);
            solution.CardboardDimensions = new Vector2D(_box.XMax - _box.XMin + _margin.X + _minMargin.X, _box.YMax - _box.YMin + _margin.Y + _minMargin.Y);
            return(solution);
        }
        internal override ImpositionSolution GenerateSolution(ImpositionPattern pattern)
        {
            // instantiate solution
            ImpositionSolution solution = new ImpositionSolution(InitialEntities, pattern.Name, pattern.RequiresRotationInRows, pattern.RequiresRotationInColumns);

            // pattern global box
            Box2D boxGlobal = pattern.BBox;

            // compute max number of patterns
            int noPatternX = NoPatternX(pattern);
            int noPatternY = NoPatternY(pattern);

            int[,] rowNumber = new int[pattern.NoRows, pattern.NoCols];
            int[,] colNumber = new int[pattern.NoRows, pattern.NoCols];

            int iMax = -1, jMax = -1;

            for (int i = 0; i < pattern.NoRows; ++i)
            {
                for (int j = 0; j < pattern.NoCols; ++j)
                {
                    if (pattern._bboxes[i, j].XMax + noPatternX * pattern.PatternStep.X - boxGlobal.XMin < UsableFormat.Width)
                    {
                        rowNumber[i, j] = noPatternX + 1;
                        iMax            = i;
                    }
                    else
                    {
                        rowNumber[i, j] = noPatternX;
                    }

                    if (pattern._bboxes[i, j].YMax + noPatternY * pattern.PatternStep.Y - boxGlobal.YMin < UsableFormat.Height)
                    {
                        colNumber[i, j] = noPatternY + 1;
                        jMax            = j;
                    }
                    else
                    {
                        colNumber[i, j] = noPatternY;
                    }
                }
            }
            // compute actual margin
            double xMax = double.MinValue;
            double yMax = double.MinValue;

            for (int i = 0; i < pattern.NoRows; ++i)
            {
                for (int j = 0; j < pattern.NoCols; ++j)
                {
                    xMax = Math.Max(xMax, pattern._bboxes[i, j].XMax + (rowNumber[i, j] - 1) * pattern.PatternStep.X);
                    yMax = Math.Max(yMax, pattern._bboxes[i, j].YMax + (colNumber[i, j] - 1) * pattern.PatternStep.Y);
                }
            }

            double xMargin = 0.0;

            switch (HorizontalAlignment)
            {
            case ImpositionTool.HAlignment.HALIGN_LEFT: xMargin = UsableFormat.XMin; break;

            case ImpositionTool.HAlignment.HALIGN_RIGHT: xMargin = CardboardFormat.Width - Margin.X - xMax + boxGlobal.XMin; break;

            case ImpositionTool.HAlignment.HALIGN_CENTER: xMargin = (CardboardFormat.Width - xMax + boxGlobal.XMin) * 0.5; break;

            default: break;
            }

            double yMargin = 0.0;

            switch (VerticalAlignment)
            {
            case ImpositionTool.VAlignment.VALIGN_BOTTOM: yMargin = UsableFormat.YMin; break;

            case ImpositionTool.VAlignment.VALIGN_TOP: yMargin = CardboardFormat.Height - Margin.Y - yMax + boxGlobal.YMin; break;

            case ImpositionTool.VAlignment.VALIGN_CENTER: yMargin = (CardboardFormat.Height - yMax + boxGlobal.YMin) * 0.5; break;

            default: break;
            }

            // compute offsets
            double xOffset = xMargin - boxGlobal.XMin;
            double yOffset = yMargin - boxGlobal.YMin;

            for (int i = 0; i < pattern.NoRows; ++i)
            {
                for (int j = 0; j < pattern.NoCols; ++j)
                {
                    for (int k = 0; k < rowNumber[i, j]; ++k)
                    {
                        for (int l = 0; l < colNumber[i, j]; ++l)
                        {
                            BPosition pos = pattern._relativePositions[i, j];
                            pos._pt.X = xOffset + k * pattern.PatternStep.X + pos._pt.X;
                            pos._pt.Y = yOffset + l * pattern.PatternStep.Y + pos._pt.Y;
                            solution.Add(pos);
                        }
                    }
                }
            }
            // noRows / noCols
            solution.Rows = pattern.NoCols * noPatternX + iMax + 1;
            solution.Cols = pattern.NoRows * noPatternY + jMax + 1;
            // cardboard position
            solution.CardboardPosition   = new Vector2D(xMargin, yMargin);
            solution.CardboardDimensions = _cardboardFormat.Dimensions;
            return(solution);
        }