Example #1
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;
        }