Exemple #1
0
        public override Box2D ComputeBox(Transform2D transform)
        {
            Box2D box = Box2D.Initial;

            box.Extend(transform.transform(_pt0));
            box.Extend(transform.transform(_pt1));
            return(box);
        }
Exemple #2
0
        public Box2D Transform(Transform2D transf)
        {
            Box2D box = Initial;

            box.Extend(transf.transform(_ptMin));
            box.Extend(transf.transform(_ptMax));
            return(box);
        }
Exemple #3
0
            public override Box2D ComputeBox(Transform2D transform)
            {
                Box2D box = Box2D.Initial;

                box.Extend(transform.transform(_pt0));
                box.Extend(transform.transform(_pt1));
                GetOffsetPoints(out Vector2D pt2, out Vector2D pt3);
                box.Extend(transform.transform(pt2));
                box.Extend(transform.transform(pt3));
                return(box);
            }
Exemple #4
0
 public override void Initialize(PicFactory factory)
 {
     _box.Reset();
     try
     {
         if (null != factory.Format)
         {
             _box.Extend(factory.Format.Box);
         }
         else if (factory.IsEmpty)
         {
             _box.Extend(Sharp3D.Math.Core.Vector2D.Zero);
         }
     }
     catch (Exception ex)
     {
         _log.Error(ex.ToString());
     }
 }
Exemple #5
0
        public override Box2D ComputeBox(Transform2D transf)
        {
            Box2D box = new Box2D();

            foreach (var entity in _entities)
            {
                if (entity is PicDrawable drawable)
                {
                    box.Extend(drawable.ComputeBox(transf));
                }
            }
            return(box);
        }
Exemple #6
0
        public override Box2D ComputeBox(Transform2D transf)
        {
            Box2D box = new Box2D();

            foreach (PicEntity entity in _entities)
            {
                PicDrawable drawable = entity as PicDrawable;
                if (null != drawable)
                {
                    box.Extend(drawable.ComputeBox(transf));
                }
            }
            return(box);
        }
Exemple #7
0
        public override Box2D ComputeBox(Transform2D transform)
        {
            Box2D box = Box2D.Initial;

            foreach (var entity in Block)
            {
                if (entity is PicDrawable drawable)
                {
                    if (!(drawable is PicTypedDrawable typeDrawable) ||
                        typeDrawable.LineType != PicGraphics.LT.LT_CONSTRUCTION)
                    {
                        box.Extend(drawable.ComputeBox(transform * BlockTransformation));
                    }
                }
            }
            return(box);
        }
Exemple #8
0
        public override Box2D ComputeBox(Transform2D transform)
        {
            Box2D box = Box2D.Initial;

            foreach (PicEntity entity in _block)
            {
                PicDrawable drawable = entity as PicDrawable;
                if (null != drawable)
                {
                    PicTypedDrawable typeDrawable = drawable as PicTypedDrawable;
                    if (null == typeDrawable || typeDrawable.LineType != PicGraphics.LT.LT_CONSTRUCTION)
                    {
                        box.Extend(drawable.ComputeBox(transform * BlockTransformation));
                    }
                }
            }
            return(box);
        }
Exemple #9
0
            public override Box2D ComputeBox(Transform2D transform)
            {
                // instantiate bounding box
                Box2D box = Box2D.Initial;

                // 6 points to be considered
                // arc extremities
                _box.Extend(transform.transform(PointAtAngle(AngleBegActual)));
                _box.Extend(transform.transform(PointAtAngle(AngleEndActual)));
                // horizontal and vertical tangent points
                double[] tab = new double[] { 0.0, 90.0, 180.0, 270.0 };
                foreach (double d in tab)
                {
                    if (PointOnArc(d))
                    {
                        box.Extend(transform.transform(PointAtAngle(d)));
                    }
                }
                return(box);
            }
        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);
        }
Exemple #12
0
        // build horizontal quotation
        private void BuildHQuotation(PicFactory factory, short grp, Box2D box)
        {
            // get entities
            PicVisitorAutoQuotationEntities visitor = new PicVisitorAutoQuotationEntities(grp);

            factory.ProcessVisitor(visitor);
            List <PicTypedDrawable> list = visitor.Entities;
            // list of vertical segments
            List <PicSegment> vSegments = new List <PicSegment>();
            Box2D             bbox      = new Box2D();
            double            minY_Xmin = double.MaxValue;
            double            minY_Xmax = double.MaxValue;

            foreach (PicTypedDrawable typedDrawable in list)
            {
                // get entity bounding box
                Box2D entityBox = typedDrawable.Box;
                // save y of minx
                if (entityBox.XMin <= bbox.XMin)
                {
                    if (Math.Abs(entityBox.XMin - bbox.XMin) < 0.1)
                    {
                        minY_Xmin = Math.Min(entityBox.YMin, minY_Xmin);
                    }
                    else
                    {
                        minY_Xmin = entityBox.YMin;
                    }
                }
                if (entityBox.XMax >= bbox.XMax)
                {
                    if (Math.Abs(entityBox.XMax - bbox.XMax) < 0.1)
                    {
                        minY_Xmax = Math.Min(entityBox.YMin, minY_Xmax);
                    }
                    else
                    {
                        minY_Xmax = entityBox.YMin;
                    }
                }
                // expand global bounding box
                bbox.Extend(entityBox);
                // save vertical fold segments
                if (typedDrawable is PicSegment &&
                    (
                        (typedDrawable.LineType == PicGraphics.LT.LT_CREASING) ||
                        (typedDrawable.LineType == PicGraphics.LT.LT_HALFCUT) ||
                        (typedDrawable.LineType == PicGraphics.LT.LT_PERFO) ||
                        (typedDrawable.LineType == PicGraphics.LT.LT_PERFOCREASING)
                    )
                    )
                {
                    PicSegment seg = typedDrawable as PicSegment;
                    if (Math.Abs(seg.Pt1.X - seg.Pt0.X) / seg.Length < 0.01)
                    {
                        vSegments.Add(seg);
                    }
                }
            }
            // exit if no horizontal folds
            if (vSegments.Count == 0)
            {
                return;
            }
            // sort vertical segments by increasing x
            vSegments.Sort(new ComparerVerticalFoldsByIncreasingX());
            // remove redundants x abscissa
            double            prevx = bbox.XMin;
            List <PicSegment> sameAbscissaSegments = new List <PicSegment>();
            List <PicSegment> resultSegments       = new List <PicSegment>();

            foreach (PicSegment seg in vSegments)
            {
                if (sameAbscissaSegments.Count > 0)
                {
                    if (seg.Pt0.X - sameAbscissaSegments[0].Pt0.X > _tolerance)
                    {
                        // sort segments vertically
                        sameAbscissaSegments.Sort(new ComparerVerticalFoldsByIncreasingY());
                        resultSegments.Add(sameAbscissaSegments[0]);
                        sameAbscissaSegments.Clear();
                    }
                }
                sameAbscissaSegments.Add(seg);
            }

            // add last segment if any
            if (sameAbscissaSegments.Count > 0)
            {
                // sort segments vertically
                sameAbscissaSegments.Sort(new ComparerVerticalFoldsByIncreasingY());
                resultSegments.Add(sameAbscissaSegments[0]);
                sameAbscissaSegments.Clear();
            }

            // ### create horizontal quotations
            double   delta  = 0.05 * Math.Max(bbox.Width, bbox.Height);
            double   ypos   = bbox.YMin - delta;
            Vector2D ptPrev = bbox.PtMin;
            int      i      = 0;

            if (resultSegments.Count > 0 && (bbox.XMin + _tolerance < resultSegments[0].Pt0.X))
            {
                ptPrev = new Vector2D(bbox.XMin, minY_Xmin);
            }
            else
            {
                ptPrev = GetLowestPoint(resultSegments[i]);
                ++i;
            }

            // between folds
            for (; i < resultSegments.Count; ++i)
            {
                Vector2D pt = GetLowestPoint(resultSegments[i]);
                CreateQuotationH(factory, ptPrev, pt, ypos, grp);
                ptPrev = pt;
            }
            // last : from last fold to maxx
            double yposTemp = bbox.XMax - ptPrev.X > delta ? ypos : ptPrev.Y;

            if (resultSegments.Count == 0)
            {
                CreateQuotationH(factory, ptPrev, new Vector2D(), ypos, grp);
            }
            else if (resultSegments[resultSegments.Count - 1].Pt0.X + _tolerance < bbox.XMax)
            {
                CreateQuotationH(factory, ptPrev, new Vector2D(bbox.XMax, minY_Xmax), ypos, grp);
            }
        }
Exemple #13
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;
        }