Exemplo n.º 1
0
        public bool WriteExportFile(string filePath, string fileExt)
        {
            try
            {
                // instantiate filter
                PicFilter filter = (_showCotationAuto ? PicFilter.FilterNone : !PicFilter.FilterCotation) & PicFilter.FilterNoZeroEntities;
                // get bounding box
                PicVisitorBoundingBox visitorBoundingBox = new PicVisitorBoundingBox();
                Factory.ProcessVisitor(visitorBoundingBox, filter);
                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 fileFormat = fileExt.TrimStart('.').ToLower();

                byte[] byteArray;
                // get file content
                if (string.Equals("des", fileFormat))
                {   // DES
                    using (PicVisitorDesOutput visitor = new PicVisitorDesOutput())
                    {
                        visitor.Author = "treeDiM";
                        Factory.ProcessVisitor(visitor, filter);
                        byteArray = visitor.GetResultByteArray();
                    }
                }
                else if (string.Equals("dxf", fileFormat))
                {   // DXF
                    using (PicVisitorDxfOutput visitor = new PicVisitorDxfOutput())
                    {
                        visitor.Author = "treeDiM";
                        Factory.ProcessVisitor(visitor, filter);
                        byteArray = visitor.GetResultByteArray();
                    }
                }
#if PDFSharp
                else if (string.Equals("pdf", fileFormat))
                {   // PDF
                    using (PicGraphicsPdf graphics = new PicGraphicsPdf(box))
                    {
                        graphics.Author = Application.ProductName + "(" + Application.CompanyName + ")";
                        graphics.Title  = Path.GetFileNameWithoutExtension(filePath);
                        Factory.Draw(graphics, filter);
                        byteArray = graphics.GetResultByteArray();
                    }
                }
#endif
                else if (string.Equals("ai", fileFormat) || string.Equals("cf2", fileFormat))
                { // AI || CF2
                    using (PicVisitorDiecutOutput visitor = new PicVisitorDiecutOutput(fileExt))
                    {
                        visitor.Author = Application.ProductName + "(" + Application.CompanyName + ")";
                        visitor.Title  = Path.GetFileNameWithoutExtension(filePath);
                        Factory.ProcessVisitor(visitor, filter);
                        byteArray = visitor.GetResultByteArray();
                    }
                }
                else
                {
                    throw new Exception("Invalid file format:" + fileFormat);
                }
                // write byte array to stream
                using (FileStream fstream = new FileStream(filePath, FileMode.Create))
                    fstream.Write(byteArray, 0, byteArray.GetLength(0));

                return(true);
            }
            catch (Exception ex)
            {
                _log.Error(string.Format("Exception: {0}", ex.ToString()));
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool WriteExportFile(string filePath, string fileExt)
        {
            try
            {
                // instantiate filter : no quotations + no zero entitites
                PicFilter filter = PicFilter.FilterCotation & PicFilter.FilterNoZeroEntities;
                // get bounding box
                PicVisitorBoundingBox visitorBoundingBox = new PicVisitorBoundingBox();
                _factory.ProcessVisitor(visitorBoundingBox, filter);
                Box2D box = visitorBoundingBox.Box;
                box.AddMarginRatio(MarginPerc);

                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 (PicVisitorDesOutput visitor = new PicVisitorDesOutput())
                    {
                        visitor.Author = author;
                        _factory.ProcessVisitor(visitor, filter);
                        byteArray = visitor.GetResultByteArray();
                    }
                }
                else if ("dxf" == fileFormat)
                {
                    using (PicVisitorDxfOutput visitor = new PicVisitorDxfOutput())
                    {
                        visitor.Author = author;
                        _factory.ProcessVisitor(visitor, filter);
                        byteArray = visitor.GetResultByteArray();
                    }
                }
#if PDFSharp
                else if ("pdf" == fileFormat)
                {
                    using (PicGraphicsPdf graphics = new PicGraphicsPdf(box))
                    {
                        graphics.Author = author;
                        graphics.Title  = title;
                        _factory.Draw(graphics, filter);
                        byteArray = graphics.GetResultByteArray();
                    }
                }
#endif
                else if ("ai" == fileFormat || "cf2" == fileFormat)
                {
                    using (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);
            }
        }
Exemplo n.º 3
0
        public byte[] GetExportFile(string fileExt, ParameterStack stack)
        {
            // build factory
            PicFactory factory = new PicFactory();

            Component.CreateFactoryEntities(factory, stack);
            if (_reflectionX)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX));
            }
            if (_reflectionY)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY));
            }
            // remove existing quotations
            if (!_showCotationCode)
            {
                factory.Remove(PicFilter.FilterCotation);
            }
            // build auto quotations
            if (_showCotationAuto)
            {
                PicAutoQuotation.BuildQuotation(factory);
            }

            // instantiate filter
            PicFilter filter = !PicFilter.FilterCotation
                               & !(new PicFilterLineType(PicGraphics.LT.LT_COTATION) | new PicFilterLineType(PicGraphics.LT.LT_AXIS))
                               & PicFilter.FilterNoZeroEntities;

            // get bounding box
            PicVisitorBoundingBox visitorBoundingBox = new PicVisitorBoundingBox();

            factory.ProcessVisitor(visitorBoundingBox, filter);
            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);

            string author     = Application.ProductName + " (" + Application.CompanyName + ")";
            string title      = Application.ProductName + " export";
            string fileFormat = fileExt.StartsWith(".") ? fileExt.Substring(1) : fileExt;

            fileFormat = fileFormat.ToLower();

            // get file content
            if (string.Equals("des", fileFormat))
            {
                PicVisitorDesOutput visitor = new PicVisitorDesOutput {
                    Author = author
                };
                factory.ProcessVisitor(visitor, filter);
                return(visitor.GetResultByteArray());
            }
            else if (string.Equals("dxf", fileFormat))
            {
                PicVisitorOutput visitor = new PicVisitorDxfOutput {
                    Author = author
                };
                factory.ProcessVisitor(visitor, filter);
                return(visitor.GetResultByteArray());
            }
#if PDFSharp
            else if (string.Equals("pdf", fileFormat))
            {
                PicGraphicsPdf graphics = new PicGraphicsPdf(box)
                {
                    Author = author,
                    Title  = title
                };
                factory.Draw(graphics, filter);
                return(graphics.GetResultByteArray());
            }
#endif
            else if (string.Equals("ai", fileFormat) || string.Equals("cf2", fileFormat))
            {
                PicVisitorDiecutOutput visitor = new PicVisitorDiecutOutput(fileFormat)
                {
                    Author = author,
                    Title  = title
                };
                factory.ProcessVisitor(visitor, filter);
                return(visitor.GetResultByteArray());
            }
            else
            {
                throw new Exception("Invalid file format:" + fileFormat);
            }
        }
Exemplo n.º 4
0
        public byte[] GenerateExportFile(string fileFormat, ParameterStack stack)
        {
            // build factory
            PicFactory factory = new 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
            PicVisitorBoundingBox visitorBoundingBox = new PicVisitorBoundingBox();

            factory.ProcessVisitor(visitorBoundingBox, filter);
            Box2D box = visitorBoundingBox.Box;

            // add margins : 5 % of the smallest value among height
            box.AddMarginRatio(0.05);
            // get file content
            if ("des" == fileFormat)
            {
                PicVisitorDesOutput visitor = new PicVisitorDesOutput
                {
                    Author = "treeDiM"
                };
                // process visitor
                factory.ProcessVisitor(visitor, filter);
                return(visitor.GetResultByteArray());
            }
            else if ("dxf" == fileFormat)
            {
                PicVisitorOutput visitor = new PicVisitorDxfOutput();
                visitor.Author = "treeDiM";
                // process visitor
                factory.ProcessVisitor(visitor, filter);
                return(visitor.GetResultByteArray());
            }
            #if PDFSharp
            else if ("pdf" == fileFormat)
            {
                PicGraphicsPdf graphics = new PicGraphicsPdf(box)
                {
                    Author = "treeDiM",
                    Title  = "Pdf Export"
                };
                // draw
                factory.Draw(graphics, filter);
                return(graphics.GetResultByteArray());
            }
            #endif
            else
            {
                throw new Exception("Invalid file format : " + fileFormat);
            }
        }