コード例 #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);
            }
        }
コード例 #2
0
ファイル: PluginViewCtrl.cs プロジェクト: minrogi/PLMPackLib
        public byte[] GetExportFile(string fileExt, Pic.Plugin.ParameterStack stack)
        {
            // build factory
            Pic.Factory2D.PicFactory factory = new Pic.Factory2D.PicFactory();
            Component.CreateFactoryEntities(factory, stack);
            if (_reflectionX) factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX));
            if (_reflectionY) 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);

            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))
            {
                Pic.Factory2D.PicVisitorDesOutput visitor = new Pic.Factory2D.PicVisitorDesOutput();
                visitor.Author = author;
                factory.ProcessVisitor(visitor, filter);
                return visitor.GetResultByteArray();
            }
            else if (string.Equals("dxf", fileFormat))
            {
                Pic.Factory2D.PicVisitorOutput visitor = new Pic.Factory2D.PicVisitorDxfOutput();
                visitor.Author = author;
                factory.ProcessVisitor(visitor, filter);
                return visitor.GetResultByteArray();
            }
            else if (string.Equals("pdf", fileFormat))
            {
                Pic.Factory2D.PicGraphicsPdf graphics = new PicGraphicsPdf(box);
                graphics.Author = author;
                graphics.Title = title;
                factory.Draw(graphics, filter);
                return graphics.GetResultByteArray();
            }
            else if (string.Equals("ai", fileFormat) || string.Equals("cf2", fileFormat))
            {
                Pic.Factory2D.PicVisitorDiecutOutput visitor = new Pic.Factory2D.PicVisitorDiecutOutput(fileFormat);
                visitor.Author = author;
                visitor.Title = title;
                factory.ProcessVisitor(visitor, filter);
                return visitor.GetResultByteArray();
            }
            else
                throw new Exception("Invalid file format:" + fileFormat);
        }
コード例 #3
0
ファイル: Pic.Plugin.Tools.cs プロジェクト: minrogi/PLMPack
        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);
        }
コード例 #4
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);
            }
        }
コード例 #5
0
ファイル: FactoryViewerBase.cs プロジェクト: minrogi/PLMPack
        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 fileFormat = fileExt.TrimStart('.').ToLower();

                byte[] byteArray;
                // get file content
                if (string.Equals("des", fileFormat))
                {   // DES
                    using (Pic.Factory2D.PicVisitorDesOutput visitor = new Pic.Factory2D.PicVisitorDesOutput())
                    {
                        visitor.Author = "treeDiM";
                        _factory.ProcessVisitor(visitor, filter);
                        byteArray = visitor.GetResultByteArray();
                    }
                }
                else if (string.Equals("dxf", fileFormat))
                {   // DXF
                    using (Pic.Factory2D.PicVisitorDxfOutput visitor = new Pic.Factory2D.PicVisitorDxfOutput())
                    {
                        visitor.Author = "treeDiM";
                        _factory.ProcessVisitor(visitor, filter);
                        byteArray = visitor.GetResultByteArray();
                    }
                }
                else if (string.Equals("pdf", fileFormat))
                {   // PDF
                    using (Pic.Factory2D.PicGraphicsPdf graphics = new PicGraphicsPdf(box))
                    {
                        graphics.Author = Application.ProductName + "(" + Application.CompanyName + ")";
                        graphics.Title = Path.GetFileNameWithoutExtension(filePath);
                        _factory.Draw(graphics, filter);
                        byteArray = graphics.GetResultByteArray();
                    }
                }
                else if (string.Equals("ai", fileFormat) || string.Equals("cf2", fileFormat))
                { // AI || CF2
                    using (Pic.Factory2D.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 (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;
            }
        }