示例#1
0
        private void LoadDrawing(string filePath, string fileExt)
        {
            factoryViewCtrl.Visible = true;

            PicFactory factory = factoryViewCtrl.Factory;

            if (string.Equals("des", fileExt, StringComparison.CurrentCultureIgnoreCase))
            {
                PicLoaderDes picLoaderDes = new PicLoaderDes(factory);
                using (DES_FileReader fileReader = new DES_FileReader())
                    fileReader.ReadFile(filePath, picLoaderDes);
                // remove existing quotations
                factory.Remove((new PicFilterCode(PicEntity.eCode.PE_COTATIONDISTANCE))
                               | (new PicFilterCode(PicEntity.eCode.PE_COTATIONHORIZONTAL))
                               | (new PicFilterCode(PicEntity.eCode.PE_COTATIONVERTICAL)));
                // build autoquotation
                PicAutoQuotation.BuildQuotation(factory);
            }
            else if (string.Equals("dxf", fileExt, StringComparison.CurrentCultureIgnoreCase))
            {
                using (PicLoaderDxf picLoaderDxf = new PicLoaderDxf(factory))
                {
                    picLoaderDxf.Load(filePath);
                    picLoaderDxf.FillFactory();
                }
            }
            // update factoryViewCtrl
            factoryViewCtrl.FitView();
        }
示例#2
0
        private void LoadDrawing(string filePath, string fileExt)
        {
            _log.Info($"Loading file {filePath}...");
            if (!System.IO.File.Exists(filePath))
            {
                _log.Error($"File ({filePath}) does not exist.");
                return;
            }
            factoryViewCtrl.Visible = true;
            PicFactory factory = factoryViewCtrl.Factory;

            switch (fileExt.ToLower())
            {
            case "des":
            {
                PicLoaderDes picLoaderDes = new PicLoaderDes(factory);
                using (DES_FileReader fileReader = new DES_FileReader())
                    fileReader.ReadFile(filePath, picLoaderDes);
                // remove existing quotations
                factory.Remove((new PicFilterCode(PicEntity.ECode.PE_COTATIONDISTANCE))
                               | (new PicFilterCode(PicEntity.ECode.PE_COTATIONHORIZONTAL))
                               | (new PicFilterCode(PicEntity.ECode.PE_COTATIONVERTICAL)));
                // build autoquotation
                PicAutoQuotation.BuildQuotation(factory);
            }
            break;

            case "dxf":
            {
                using (PicLoaderDXF picLoaderDxf = new PicLoaderDXF(factory))
                {
                    if (!picLoaderDxf.Load(filePath))
                    {
                        return;
                    }
                }
            }
            break;

            default:
                break;
            }
            // update factoryViewCtrl
            factoryViewCtrl.FitView();
        }
示例#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);
            }
        }
示例#4
0
        private void RePaint(PaintEventArgs e, ParameterStack stack)
        {
            try
            {
                SplitterPanel panel1 = splitContHorizLeft.Panel1;

                // instantiate PicGraphics
                if (_picGraphics == null)
                {
                    _picGraphics = new PicGraphicsCtrlBased(panel1.ClientSize, e.Graphics)
                    {
                        BackgroundColor = Factory2D.Control.Properties.Settings.Default.BackgroundColor
                    };
                }
                _picGraphics.GdiGraphics = e.Graphics;
                _picGraphics.Size        = panel1.ClientSize;

                // build factory
                using (PicFactory factory = new PicFactory())
                {
                    // create entities
                    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);
                    }

                    // filter
                    PicFilter filter = _showAxes ? PicFilter.FilterNone
                        : PicFilter.FilterCotation | !(new PicFilterLineType(PicGraphics.LT.LT_COTATION) | new PicFilterLineType(PicGraphics.LT.LT_AXIS));

                    // update drawing box?
                    if (_computeBbox)
                    {
                        PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();
                        factory.ProcessVisitor(visitor, filter);
                        Box = new Box2D(visitor.Box);
                        Box2D box = visitor.Box;
                        box.AddMarginRatio(0.05);
                        _picGraphics.DrawingBox = box;

                        // update factory data
                        if (null != factoryDataCtrl)
                        {
                            factoryDataCtrl.Factory = factory;
                        }

                        _computeBbox = false;
                    }
                    // draw
                    factory.Draw(_picGraphics, filter);
                }
            }
            catch (PluginException ex) { _picGraphics.ShowMessage(ex.Message); }
            catch (ComponentSearchException ex) { _picGraphics.ShowMessage(ex.Message); }
            catch (Exception ex) { _picGraphics.ShowMessage(ex.ToString()); log.Error(ex.ToString()); }
        }