Ejemplo n.º 1
0
        public static bool ComputePositionDefault(IEntityContainer factory, Box2D boxBorder, Vector2D spaceBetween, ref List <BPosition> lPos, ref Box2D bbox)
        {
            if (boxBorder.Width <= 0.0 || boxBorder.Height <= 0.0)
            {
                return(false);
            }

            ImpositionTool tool = Instantiate(factory, new ImpositionSettings(boxBorder.Width, boxBorder.Height));

            tool.SpaceBetween = spaceBetween;
            tool.AllowOrthogonalImposition = true;
            tool.AllowBothDirection        = false;
            tool.HorizontalAlignment       = ImpositionSettings.HAlignment.HALIGN_LEFT;
            tool.VerticalAlignment         = ImpositionSettings.VAlignment.VALIGN_BOTTOM;
            tool.GenerateSortedSolutionList(null, out List <ImpositionSolution> solutions);
            if (solutions.Count > 0)
            {
                ImpositionSolution impSol       = solutions[0];
                Vector2D           cardboardPos = impSol.CardboardPosition;
                foreach (var p in impSol.Positions)
                {
                    BPosition pos = p;
                    pos.Pt += boxBorder.PtMin - cardboardPos;
                    lPos.Add(pos);
                }
                Vector2D ptMin = impSol.Bbox.PtMin + boxBorder.PtMin;
                Vector2D ptMax = impSol.Bbox.PtMax + boxBorder.PtMin;
                bbox = new Box2D(ptMin, ptMax);
            }
            return(lPos.Count > 0);
        }
Ejemplo n.º 2
0
        /*
         * internal ImpositionPattern GeneratePattern(int id, Vector2D minDistance, Vector2D impositionOffset, bool orthoImp)
         * {
         *  ImpositionPattern pattern = null;
         *
         *  KeyValuePair<int, bool> kvpIndexOrtho = new KeyValuePair<int, bool>(id, orthoImp);
         *  switch (id)
         *  {
         *      case 0: pattern = new PatternDefault(); break;
         *      case 1: pattern = new PatternRotationInRow(); break;
         *      case 2: pattern = new PatternRotationInColumn(); break;
         *  }
         *  return pattern;
         * }
         */
        #endregion

        #region Public methods
        public bool GenerateEntities(string patternName, bool orthogonalImposition, ref PicFactory factory)
        {
            ImpositionPattern pattern = GetPatternByName(patternName);

            pattern.GeneratePattern(InitialEntities, SpaceBetween, ImpositionOffset, orthogonalImposition);
            ImpositionSolution solution = GenerateSolution(pattern, orthogonalImposition);

            solution.CreateEntities(factory);
            return(true);
        }
        public bool GenerateSortedSolutionList(IProgressCallback callback, out List <ImpositionSolution> solutions)
        {
            // get applicable pattern list
            List <ImpositionPattern> patternList = GetPatternList();
            // need to compute orthogonal positions ?
            bool processOrthogonalImposition = AllowOrthogonalImposition;

            /*_allowOrthogonalImposition && (_cardboardFormat.Width != _cardboardFormat.Height);*/
            // compute number of expected solutions
            if (null != callback)
            {
                callback.Begin(0, patternList.Count * (processOrthogonalImposition ? 4 : 2));
            }
            // instantiate solution list
            solutions = new List <ImpositionSolution>();
            // process pattern list
            foreach (ImpositionPattern pattern in patternList)
            {
                // generate pattern
                try
                {
                    pattern.GeneratePattern(InitialEntities, SpaceBetween, ImpositionOffset, false);
                }
                catch (Exception ex)
                {
                    _log.Error(ex.Message);
                    continue;
                }

                // default orientation
                ImpositionSolution solution = GenerateSolution(pattern);
                if (null != solution && solution.IsValid)
                {
                    solution.UnitLengthCut  = _unitLengthCut;
                    solution.UnitLengthFold = _unitLengthFold;
                    solution.UnitArea       = _unitArea;
                    solutions.Add(solution);
                }
                // increment progress dialog?
                if (null != callback)
                {
                    callback.Increment(solutions.Count);
                }

                // orthogonal direction
                if (processOrthogonalImposition)
                {
                    // generate pattern
                    try
                    {
                        pattern.GeneratePattern(InitialEntities, SpaceBetween, ImpositionOffset, true);
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex.Message);
                        continue;
                    }
                    solution = GenerateSolution(pattern);
                    if (null != solution && solution.IsValid)
                    {
                        solution.UnitLengthCut  = _unitLengthCut;
                        solution.UnitLengthFold = _unitLengthFold;
                        solution.UnitArea       = _unitArea;
                        solutions.Add(solution);
                    }
                }
                // increment progress dialog?
                if (null != callback)
                {
                    callback.Increment(solutions.Count);
                }
            }

            // generate thumbnails
            foreach (ImpositionSolution sol in solutions)
            {
                sol.GenerateThumbnail();
                // increment progress dialog?
                if (null != callback)
                {
                    callback.Increment(solutions.Count);
                }
            }

            // sort solution list
            solutions.Sort(new SolutionComparerFormat());

            if (null != callback)
            {
                callback.End();
            }

            return(solutions.Count > 0);
        }
Ejemplo n.º 4
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, 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);
        }
        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);
        }