Beispiel #1
0
        public byte[] GenerateExportFile(string fileFormat, ParameterStack stack)
        {
            // build factory
            Pic.Factory2D.PicFactory factory = new Pic.Factory2D.PicFactory();
            _component.CreateFactoryEntities(factory, stack);
            if (_reflexionX)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX));
            }
            if (_reflexionY)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY));
            }

            // instantiate filter
            PicFilter filter = (_showCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation) & PicFilter.FilterNoZeroEntities;

            // get bounding box
            Pic.Factory2D.PicVisitorBoundingBox visitorBoundingBox = new Pic.Factory2D.PicVisitorBoundingBox();
            factory.ProcessVisitor(visitorBoundingBox, filter);
            Pic.Factory2D.Box2D box = visitorBoundingBox.Box;
            // add margins : 5 % of the smallest value among height
            box.AddMarginHorizontal(box.Width * 0.05);
            box.AddMarginVertical(box.Height * 0.05);
            // get file content
            if ("des" == fileFormat)
            {
                Pic.Factory2D.PicVisitorDesOutput visitor = new Pic.Factory2D.PicVisitorDesOutput();
                visitor.Author = "treeDiM";
                // process visitor
                factory.ProcessVisitor(visitor, filter);
                return(visitor.GetResultByteArray());
            }
            else if ("dxf" == fileFormat)
            {
                Pic.Factory2D.PicVisitorOutput visitor = new Pic.Factory2D.PicVisitorDxfOutput();
                visitor.Author = "treeDiM";
                // process visitor
                factory.ProcessVisitor(visitor, filter);
                return(visitor.GetResultByteArray());
            }
            else if ("pdf" == fileFormat)
            {
                PicGraphicsPdf graphics = new PicGraphicsPdf(box);
                graphics.Author = "treeDiM";
                graphics.Title  = "Pdf Export";
                // draw
                factory.Draw(graphics, filter);
                return(graphics.GetResultByteArray());
            }
            else
            {
                throw new Exception("Invalid file format : " + fileFormat);
            }
        }
Beispiel #2
0
        public bool WriteExportFile(string filePath, string fileExt)
        {
            try
            {
                // instantiate filter
                PicFilter filter = (_showCotations ? PicFilter.FilterNone : PicFilter.FilterCotation) & PicFilter.FilterNoZeroEntities;
                // get bounding box
                Pic.Factory2D.PicVisitorBoundingBox visitorBoundingBox = new Pic.Factory2D.PicVisitorBoundingBox();
                _factory.ProcessVisitor(visitorBoundingBox, filter);
                Pic.Factory2D.Box2D box = visitorBoundingBox.Box;
                // add margins : 5 % of the smallest value among height
                box.AddMarginHorizontal(box.Width * 0.01);
                box.AddMarginVertical(box.Height * 0.01);

                string author     = Application.ProductName + " (" + Application.CompanyName + ")";
                string title      = System.IO.Path.GetFileNameWithoutExtension(filePath);
                string fileFormat = fileExt.TrimStart('.').ToLower();

                byte[] byteArray;
                // get file content
                if ("des" == fileFormat)
                {
                    using (Pic.Factory2D.PicVisitorDesOutput visitor = new Pic.Factory2D.PicVisitorDesOutput())
                    {
                        visitor.Author = author;
                        _factory.ProcessVisitor(visitor, filter);
                        byteArray = visitor.GetResultByteArray();
                    }
                }
                else if ("dxf" == fileFormat)
                {
                    using (Pic.Factory2D.PicVisitorDxfOutput visitor = new Pic.Factory2D.PicVisitorDxfOutput())
                    {
                        visitor.Author = author;
                        _factory.ProcessVisitor(visitor, filter);
                        byteArray = visitor.GetResultByteArray();
                    }
                }
                else if ("pdf" == fileFormat)
                {
                    using (Pic.Factory2D.PicGraphicsPdf graphics = new PicGraphicsPdf(box))
                    {
                        graphics.Author = author;
                        graphics.Title  = title;
                        _factory.Draw(graphics, filter);
                        byteArray = graphics.GetResultByteArray();
                    }
                }
                else if ("ai" == fileFormat || "cf2" == fileFormat)
                {
                    using (Pic.Factory2D.PicVisitorDiecutOutput visitor = new PicVisitorDiecutOutput(fileExt))
                    {
                        visitor.Author = author;
                        visitor.Title  = title;
                        _factory.ProcessVisitor(visitor, filter);
                        byteArray = visitor.GetResultByteArray();
                    }
                }
                else
                {
                    throw new Exception("Invalid file format: " + fileFormat);
                }
                // write byte array to stream
                using (System.IO.FileStream fstream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
                    fstream.Write(byteArray, 0, byteArray.GetLength(0));

                return(true);
            }
            catch (Exception ex)
            {
                _log.Error(string.Format("Exception: {0}", ex.ToString()));
                return(false);
            }
        }