Example #1
0
        public void GenerateImage(Size size, ParameterStack stack, out Image bmp)
        {
            // check if plugin was instantiated
            if (null == _component)
            {
                throw new Exception("No valid plugin instance loaded!");
            }

            // instantiate factory
            PicFactory factory = new PicFactory();

            // generate entities
            _component.CreateFactoryEntities(factory, stack);
            // apply any needed transformation
            if (_reflexionX)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX));
            }
            if (_reflexionY)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY));
            }
            // get bounding box
            PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();

            factory.ProcessVisitor(visitor);
            Pic.Factory2D.Box2D box = visitor.Box;
            box.AddMarginRatio(0.05);
            // draw image
            PicGraphicsImage picImage = new PicGraphicsImage(size, box);

            factory.Draw(picImage, _showCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation);

            bmp = picImage.Bitmap;
        }
Example #2
0
            /// <summary>
            /// Drawing method used to draw factory content
            /// </summary>
            /// <param name="graphics">Graphic environment parameters</param>
            public void Draw(PicGraphics graphics, PicFilter filter)
            {
                graphics.Initialize();

                // bounding box
                if (!graphics.DrawingBox.IsValid)
                {
                    // compute bounding box
                    using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox())
                    {
                        ProcessVisitor(visitor);
                        Box2D box = visitor.Box;
                        box.AddMarginRatio(0.01);
                        // set as drawing box
                        graphics.DrawingBox = box;
                    }
                }

                // first, draw cotation
                foreach (PicEntity entity in _entities)
                {
                    try
                    {
                        // cotation
                        PicCotation cotation = entity as PicCotation;
                        if (cotation != null && !cotation.Deleted && filter.Accept(entity))
                        {
                            cotation.Draw(graphics);
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex.Message);
                    }
                }
                // then other entities
                foreach (Object o in _entities)
                {
                    try
                    {
                        // drawable entities
                        PicDrawable drawable = o as PicDrawable;
                        if (drawable != null && !drawable.Deleted && !(drawable is PicCotation) && filter.Accept(drawable))
                        {
                            drawable.Draw(graphics);
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex.Message);
                    }
                }
                // cardboard format
                if (null != _cardboardFormat)
                {
                    _cardboardFormat.Draw(graphics);
                }

                graphics.Finish();
            }
Example #3
0
        public static void GenerateImage(Size size, PicFactory factory, bool showCotations, out Image bmp)
        {
            // get bounding box
            PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();

            factory.ProcessVisitor(visitor);
            Box2D box = visitor.Box;

            box.AddMarginRatio(0.05);
            // draw image
            PicGraphicsImage picImage = new PicGraphicsImage(size, box);

            factory.Draw(picImage, showCotations ? PicFilter.FilterNone : PicFilter.FilterCotation);

            bmp = picImage.Bitmap;
        }
        public static Box2D BoundingBox(PicFactory factory, double marginRatio = 0.0, bool takePicBlocsIntoAccount = true)
        {
            var visitor = new PicVisitorBoundingBox()
            {
                TakePicBlocksIntoAccount = takePicBlocsIntoAccount
            };

            factory.ProcessVisitor(visitor, !PicFilter.FilterCotation);
            Box2D box = visitor.Box;

            if (box.IsValid && marginRatio > 0.0)
            {
                box.AddMarginRatio(marginRatio);
            }
            return(box);
        }
Example #5
0
        public override void ProcessFactory(PicFactory factory)
        {
            // initialization
            _segList.Clear();
            _box = new Box2D();
            _area = 0.0;

            // build list of segments with entities that belongs to group
            factory.ProcessToolAllEntities(this);
            _box.AddMarginRatio(0.2);

            // exit if no of segments exceeds MAXSEG
            int maxSeg = Pic.Factory2D.Properties.Settings.Default.AreaMaxNoSegments;
            if (_segList.Count > maxSeg)
                throw new PicToolTooLongException(string.Format("No of segments exceeds {0}", maxSeg));

            // compute actual step size
            uint iNoStep = (uint)(_box.Width / _stepSize);
            iNoStep = Math.Min(iNoStep, _iNoStepMax);
            double stepDefault = _box.Width / iNoStep;

            // compute area
            for (int i = 0; i < iNoStep; ++i)
            {
                double xh = _box.XMin + i * stepDefault;
                int nby = 1;
                double stepCurrent = stepDefault;
                List<double> tabyh = new List<double>();

                tabyh.Add(double.MaxValue);

                bool bAgain = false;
                do
                {
                    bAgain = false;
                    stepCurrent = stepDefault;

                    foreach (Segment segTemp in _segList)
                    {
                        Segment seg;
                        if (segTemp.P0.X <= segTemp.P1.X)
                            seg = segTemp;
                        else
                            seg = new Segment(segTemp.P1, segTemp.P0);

                        if (xh >= seg.P0.X && xh <= seg.P1.X)
                        {
                            // cas intersections confondues
                            if ((Math.Abs(xh - seg.P0.X) < 0.001) || (Math.Abs(seg.P1.X - xh) < 0.001))
                            {
                                // restart loop from the beginning
                                nby = 1;
                                tabyh[0] = double.MaxValue;
                                stepCurrent = 0.9 * stepDefault;
                                xh -= stepDefault * 0.1;
                                bAgain = true;
                                break;
                            }
                            else
                            {
                                double yh = seg.P0.Y + (xh - seg.P0.X) * ((seg.P1.Y - seg.P0.Y) / (seg.P1.X - seg.P0.X));
                                tabyh.Add(yh);
                            }
                        }
                    }
                }
                while (bAgain);

                tabyh.Sort();
                nby = tabyh.Count;

                // increment area
                if (nby > 1 && (nby % 2 != 0))
                {
                    for (int l = 0; l < nby - 1; l += 2)
                    {
                        _area = _area + stepCurrent * (tabyh[l + 1] - tabyh[l]);
                    }
                }
            }
        }
Example #6
0
        public override void ProcessFactory(PicFactory factory)
        {
            // initialization
            _segList.Clear();
            _box  = new Box2D();
            _area = 0.0;

            // build list of segments with entities that belongs to group
            factory.ProcessToolAllEntities(this);
            _box.AddMarginRatio(0.2);

            // exit if no of segments exceeds MAXSEG
            int maxSeg = Pic.Factory2D.Properties.Settings.Default.AreaMaxNoSegments;

            if (_segList.Count > maxSeg)
            {
                throw new PicToolTooLongException(string.Format("No of segments exceeds {0}", maxSeg));
            }

            // compute actual step size
            uint iNoStep = (uint)(_box.Width / _stepSize);

            iNoStep = Math.Min(iNoStep, _iNoStepMax);
            double stepDefault = _box.Width / iNoStep;

            // compute area
            for (int i = 0; i < iNoStep; ++i)
            {
                double        xh          = _box.XMin + i * stepDefault;
                int           nby         = 1;
                double        stepCurrent = stepDefault;
                List <double> tabyh       = new List <double>();

                tabyh.Add(double.MaxValue);

                bool bAgain = false;
                do
                {
                    bAgain      = false;
                    stepCurrent = stepDefault;

                    foreach (Segment segTemp in _segList)
                    {
                        Segment seg;
                        if (segTemp.P0.X <= segTemp.P1.X)
                        {
                            seg = segTemp;
                        }
                        else
                        {
                            seg = new Segment(segTemp.P1, segTemp.P0);
                        }

                        if (xh >= seg.P0.X && xh <= seg.P1.X)
                        {
                            // cas intersections confondues
                            if ((Math.Abs(xh - seg.P0.X) < 0.001) || (Math.Abs(seg.P1.X - xh) < 0.001))
                            {
                                // restart loop from the beginning
                                nby         = 1;
                                tabyh[0]    = double.MaxValue;
                                stepCurrent = 0.9 * stepDefault;
                                xh         -= stepDefault * 0.1;
                                bAgain      = true;
                                break;
                            }
                            else
                            {
                                double yh = seg.P0.Y + (xh - seg.P0.X) * ((seg.P1.Y - seg.P0.Y) / (seg.P1.X - seg.P0.X));
                                tabyh.Add(yh);
                            }
                        }
                    }
                }while (bAgain);

                tabyh.Sort();
                nby = tabyh.Count;

                // increment area
                if (nby > 1 && (nby % 2 != 0))
                {
                    for (int l = 0; l < nby - 1; l += 2)
                    {
                        _area = _area + stepCurrent * (tabyh[l + 1] - tabyh[l]);
                    }
                }
            }
        }