public override void GeneratePattern(IEntityContainer container, Vector2D minDistance, Vector2D impositionOffset, bool ortho)
        {
            using (PicFactory factory = new PicFactory())
            {
                // instantiate block and BlockRef
                PicBlock    block      = factory.AddBlock(container);
                PicBlockRef blockRef00 = factory.AddBlockRef(block, new Vector2D(0.0, 0.0), ortho ? 90.0 : 0.0);

                // compute bounding box
                PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();
                visitor.TakePicBlocksIntoAccount = false;
                factory.ProcessVisitor(visitor, !PicFilter.FilterCotation);
                Box2D boxEntities = visitor.Box;

                // compute default X step
                PicBlockRef blockRef01         = factory.AddBlockRef(block, new Vector2D(5.0 * boxEntities.Width + minDistance.X, 0.0), ortho ? 90.0 : 0.0);
                double      horizontalDistance = 0.0;
                if (!PicBlockRef.Distance(blockRef00, blockRef01, PicBlockRef.DistDirection.HORIZONTAL_RIGHT, out horizontalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                _patternStep.X = 5.0 * boxEntities.Width - horizontalDistance + 2.0 * minDistance.X;

                // compute default Y step
                PicBlockRef blockRef10       = factory.AddBlockRef(block, new Vector2D(0.0, 5.0 * boxEntities.Height + minDistance.Y), ortho ? 90.0 : 0.0);
                double      verticalDistance = 0.0;
                if (!PicBlockRef.Distance(blockRef00, blockRef10, PicBlockRef.DistDirection.VERTICAL_TOP, out verticalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                _patternStep.Y = 5.0 * boxEntities.Height - verticalDistance + 2.0 * minDistance.Y;

                // positions
                _relativePositions = new BPosition[1, 1];
                BPosition position = new BPosition(Vector2D.Zero, ortho ? 90.0 : 0.0);
                _relativePositions[0, 0] = position;

                // bboxes
                _bboxes       = new Box2D[1, 1];
                _bboxes[0, 0] = blockRef00.Box;//boxEntities;
            }
        }
        public override void GeneratePattern(IEntityContainer container, Vector2D minDistance, Vector2D impositionOffset, bool ortho)
        {
            using (PicFactory factory = new PicFactory())
            {
                // 20 21
                // 10 11 12
                // 00 01 02
                //

                // instantiate block and BlockRef
                PicBlock    block      = factory.AddBlock(container);
                PicBlockRef blockRef00 = factory.AddBlockRef(block, new Vector2D(0.0, 0.0), ortho ? 90.0 : 0.0);

                // compute bounding box
                PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();
                visitor.TakePicBlocksIntoAccount = false;
                factory.ProcessVisitor(visitor, new PicFilter());
                Box2D boxEntities = visitor.Box;

                // compute second entity position
                PicBlockRef blockRef10 = factory.AddBlockRef(block
                                                             , new Vector2D(
                                                                 boxEntities.XMin + boxEntities.XMax + (ortho ? 0.0 : 1.0) * impositionOffset.X
                                                                 , boxEntities.YMin + boxEntities.YMax + 5.0 * boxEntities.Height + minDistance.Y + (ortho ? 1.0 : 0.0) * impositionOffset.Y
                                                                 ), ortho ? 270.0 : 180.0);
                double verticalDistance = 0.0;
                if (!PicBlockRef.Distance(blockRef00, blockRef10, PicBlockRef.DistDirection.VERTICAL_TOP, out verticalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                Vector2D vecPosition = new Vector2D(
                    boxEntities.XMin + boxEntities.XMax + (ortho ? 0.0 : 1.0) * impositionOffset.X
                    , boxEntities.YMin + boxEntities.YMax + 5.0 * boxEntities.Height + 2.0 * minDistance.Y - verticalDistance + (ortho ? 1.0 : 0.0) * impositionOffset.Y);
                blockRef10.Position = vecPosition;

                // positions
                _relativePositions       = new BPosition[2, 1];
                _relativePositions[0, 0] = new BPosition(Vector2D.Zero, ortho ? 90.0 : 0.0);
                _relativePositions[1, 0] = new BPosition(vecPosition, ortho ? 270.0 : 180.0);
                // bboxes
                _bboxes       = new Box2D[2, 1];
                _bboxes[0, 0] = blockRef00.Box;//boxEntities;
                _bboxes[1, 0] = blockRef10.Box;

                // compute X step (col1 / col0)
                // col0
                List <PicBlockRef> listCol0 = new List <PicBlockRef>();
                listCol0.Add(blockRef00);
                listCol0.Add(blockRef10);

                // col1
                PicBlockRef blockRef01 = factory.AddBlockRef(block
                                                             , new Vector2D(5.0 * boxEntities.Width + minDistance.X, 0.0)
                                                             , ortho ? 90.0 : 0.0);
                PicBlockRef blockRef11 = factory.AddBlockRef(block
                                                             , new Vector2D(5.0 * boxEntities.Width + minDistance.X + vecPosition.X, vecPosition.Y)
                                                             , ortho ? 270.0 : 180.0);
                List <PicBlockRef> listCol1 = new List <PicBlockRef>();
                listCol1.Add(blockRef01);
                listCol1.Add(blockRef11);
                double horizontalDistance = 0.0;
                if (!PicBlockRef.Distance(listCol0, listCol1, PicBlockRef.DistDirection.HORIZONTAL_RIGHT, out horizontalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                _patternStep.X      = 5.0 * boxEntities.Width - horizontalDistance + 2.0 * minDistance.X;
                blockRef01.Position = vecPosition;
                blockRef11.Position = new Vector2D(vecPosition.X + _patternStep.X, vecPosition.Y);

                // compute Y step (row2 / row1)
                // row1
                List <PicBlockRef> listRow1 = new List <PicBlockRef>();
                listRow1.Add(blockRef10);
                listRow1.Add(blockRef11);

                PicBlockRef blockRef20 = factory.AddBlockRef(block
                                                             , new Vector2D(0.0, 5.0 * (boxEntities.Height + minDistance.Y))
                                                             , ortho ? 90.0 : 0.0);
                PicBlockRef blockRef21 = factory.AddBlockRef(block
                                                             , new Vector2D(_patternStep.X, 5.0 * (boxEntities.Height + minDistance.Y))
                                                             , ortho ? 90.0 : 0.0);

                List <PicBlockRef> listRow2 = new List <PicBlockRef>();
                listRow2.Add(blockRef20);
                listRow2.Add(blockRef21);

                verticalDistance = 0.0;
                if (!PicBlockRef.Distance(listRow1, listRow2, PicBlockRef.DistDirection.VERTICAL_TOP, out verticalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                _patternStep.Y = 5.0 * boxEntities.Height - verticalDistance + 6.0 * minDistance.Y;
            }
        }
Пример #3
0
        public override void GeneratePattern(IEntityContainer container, Vector2D minDistance, Vector2D impositionOffset, bool ortho)
        {
            //
            // 10 11 12
            // 00 01 02
            //
            using (PicFactory factory = new PicFactory())
            {
                // instantiate block and BlockRef
                PicBlock    block      = factory.AddBlock(container);
                PicBlockRef blockRef00 = factory.AddBlockRef(block
                                                             , Vector2D.Zero
                                                             , ortho ? 90.0 : 0.0);

                // compute bounding box
                Box2D boxEntities = Tools.BoundingBox(factory, 0.0, false);

                // compute second entity position on row 0
                PicBlockRef blockRef01 = factory.AddBlockRef(block
                                                             , new Vector2D(
                                                                 boxEntities.XMax + boxEntities.XMin + 5.0 * boxEntities.Width + (ortho ? 1.0 : 0.0) * impositionOffset.X
                                                                 , boxEntities.YMax + boxEntities.YMin + (ortho ? 0.0 : 1.0) * impositionOffset.Y)
                                                             , ortho ? 270.0 : 180.0);
                if (!PicBlockRef.Distance(blockRef00, blockRef01, PicBlockRef.DistDirection.HORIZONTAL_RIGHT, out double horizontalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                Vector2D vecPosition = new Vector2D(
                    boxEntities.XMax + boxEntities.XMin + 5.0 * boxEntities.Width + minDistance.X - horizontalDistance + (ortho ? 1.0 : 0.0) * impositionOffset.X
                    , boxEntities.YMax + boxEntities.YMin + (ortho ? 0.0 : 1.0) * impositionOffset.Y);
                blockRef01.Position = vecPosition;

                // positions
                _relativePositions       = new BPosition[1, 2];
                _relativePositions[0, 0] = new BPosition(Vector2D.Zero, ortho ? 90.0 : 0.0);
                _relativePositions[0, 1] = new BPosition(vecPosition, ortho ? 270.0 : 180.0);
                // bboxes
                _bboxes       = new Box2D[1, 2];
                _bboxes[0, 0] = blockRef00.Box;//boxEntities;
                _bboxes[0, 1] = blockRef01.Box;

                // compute Y step (row1 / row0)
                // row0
                List <PicBlockRef> listRow0 = new List <PicBlockRef>
                {
                    blockRef00,
                    blockRef01
                };
                // row1
                List <PicBlockRef> listRow1   = new List <PicBlockRef>();
                PicBlockRef        blockRef10 = factory.AddBlockRef(
                    block
                    , new Vector2D(0.0, 5.0 * boxEntities.Height + minDistance.Y)
                    , ortho ? 90.0 : 0.0);
                PicBlockRef blockRef11 = factory.AddBlockRef(
                    block
                    , new Vector2D(vecPosition.X, vecPosition.Y + 5.0 * boxEntities.Height + minDistance.Y)
                    , ortho ? 270.0 : 180.0);
                listRow1.Add(blockRef10);
                listRow1.Add(blockRef11);

                if (!PicBlockRef.Distance(listRow0, listRow1, PicBlockRef.DistDirection.VERTICAL_TOP, out double verticalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                _patternStep.Y = 5.0 * boxEntities.Height - verticalDistance + 2.0 * minDistance.Y;

                blockRef10.Position = new Vector2D(0.0, _patternStep.Y);
                blockRef11.Position = new Vector2D(vecPosition.X, vecPosition.Y + _patternStep.Y);

                // compute X step (col1 / col2)
                PicBlockRef blockRef02 = factory.AddBlockRef(
                    block
                    , new Vector2D(boxEntities.XMin + 5.0 * boxEntities.Width + minDistance.X
                                   , 0.0)
                    , ortho ? 90.0 : 0.0);
                PicBlockRef blockRef12 = factory.AddBlockRef(
                    block
                    , new Vector2D(boxEntities.XMin + 5.0 * boxEntities.Width + minDistance.X
                                   , _patternStep.Y)
                    , ortho ? 90.0 : 0.0);

                List <PicBlockRef> listCol1 = new List <PicBlockRef> {
                    blockRef01, blockRef11
                };
                List <PicBlockRef> listCol2 = new List <PicBlockRef> {
                    blockRef02, blockRef12
                };

                horizontalDistance = 0.0;
                if (!PicBlockRef.Distance(listCol1, listCol2, PicBlockRef.DistDirection.HORIZONTAL_RIGHT, out horizontalDistance))
                {
                    throw new Exception("Failed to compute distance between to block refs");
                }
                _patternStep.X = boxEntities.XMin + 5.0 * boxEntities.Width - horizontalDistance + 2.0 * minDistance.X;
            }
        }