コード例 #1
0
        public override void Refresh()
        {
            try
            {
                // create entities
                if (this.Parent is IEntitySupplier)
                {
                    _entitySupplier = this.Parent as IEntitySupplier;
                }
                if (null != _entitySupplier)
                {
                    // clear factory
                    _factory.Clear();
                    // update factory
                    _entitySupplier.CreateEntities(_factory);
                }

                // get selected tab and compute data accordingly
                switch (tabControlData.SelectedIndex)
                {
                case 0:
                    // compute length
                    PicVisitorDieCutLength visitorLengthes = new PicVisitorDieCutLength();
                    _factory.ProcessVisitor(visitorLengthes);
                    // update controls
                    double lengthCut = 0.0, lengthFold = 0.0;
                    if (visitorLengthes.Lengths.ContainsKey(PicGraphics.LT.LT_CUT))
                    {
                        lengthCut = visitorLengthes.Lengths[PicGraphics.LT.LT_CUT];
                    }
                    lblValueLengthCut.Text = string.Format(": {0:0.###} m", lengthCut / 1000.0);
                    if (visitorLengthes.Lengths.ContainsKey(PicGraphics.LT.LT_CREASING))
                    {
                        lengthFold = visitorLengthes.Lengths[PicGraphics.LT.LT_CREASING];
                    }
                    lblValueLengthFold.Text  = string.Format(": {0:0.###} m", lengthFold / 1000.0);
                    lblValueLengthTotal.Text = string.Format(": {0:0.###} m", (lengthCut + lengthFold) / 1000.0);
                    break;

                case 1:
                    // compute bounding box
                    PicVisitorBoundingBox visitorBB = new PicVisitorBoundingBox();
                    _factory.ProcessVisitor(visitorBB, !PicFilter.FilterCotation);
                    // update controls
                    lblValueLength.Text = string.Format(": {0:0.#} mm", visitorBB.Box.Width);
                    lblValueWidth.Text  = string.Format(": {0:0.#} mm", visitorBB.Box.Height);
                    break;

                case 2:
                    // compute area
                    try
                    {
                        PicToolArea picToolArea = new PicToolArea();
                        _factory.ProcessTool(picToolArea);
                        lblAreaValue.Text = string.Format(": {0:0.###} m²", (picToolArea.Area * 1.0E-06));

                        lblNameFormat.Visible     = lblValueFormat.Visible = _factory.HasCardboardFormat;
                        lblNameEfficiency.Visible = lblValueEfficiency.Visible = _factory.HasCardboardFormat;

                        if (_factory.HasCardboardFormat)
                        {
                            lblValueFormat.Text     = string.Format(": {0:0.#} x {1:0.#}", _factory.Format.Width, _factory.Format.Height);
                            lblValueEfficiency.Text = string.Format(": {0:0.#} %", 100.0 * picToolArea.Area / (_factory.Format.Width * _factory.Format.Height));
                        }
                    }
                    catch (PicToolTooLongException /*ex*/)
                    {
                        lblAreaValue.Text          = Pic.Factory2D.Control.Properties.Resources.ID_ABANDONPROCESSING;
                        lblNameEfficiency.Visible  = false;
                        lblValueEfficiency.Visible = false;
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // set up a simple configuration that logs on the console.
            XmlConfigurator.Configure();

            try
            {
                _log.Info("Pic.Factory2D.Test.exe starting...");
                // testing Sharp3D.Math.Core.Matrix3D
                Transform2D transf0 = Transform2D.Translation(new Vector2D(10.0, 10.0)) * Transform2D.Rotation(45.0);
                Vector2D    pt0     = transf0.transform(new Vector2D(100.0, 100.0));
                _log.Info(pt0.ToString());
                Transform2D transf1 = transf0.Inverse();
                Vector2D    pt1     = transf1.transform(pt0);
                _log.Info(pt1.ToString());

                // instantiate factory1
                PicFactory factory0 = new PicFactory();
                factory0.AddPoint(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(0.0, 0.0));
                factory0.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(50.0, 50.0), new Vector2D(100.0, 100.0));
                factory0.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(-100.0, 100.0), new Vector2D(100.0, -100.0));
                factory0.AddArc(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(50.0, 50.0), 50.0 * Math.Sqrt(2.0), 0.0, 360.0);
                factory0.AddArc(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(75.0, 75.0), 25.0 * Math.Sqrt(2.0), 0.0, 360.0);
                factory0.AddNurb(PicGraphics.LT.LT_CUT, 0, 0);
                _log.Debug(factory0.ToString());

                // get bounding box + draw
                using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox())
                {
                    factory0.ProcessVisitor(visitor);
                    _log.Info(visitor.Box.ToString());

                    // save as image
                    string           filePath = Path.Combine(Path.GetTempPath(), "PicImage0.jpeg");
                    PicGraphicsImage picImage = new PicGraphicsImage();
                    picImage.ImageSize = new System.Drawing.Size(512, 512);
                    Box2D box = visitor.Box;
                    box.AddMargin(5);
                    picImage.DrawingBox = box;
                    factory0.Draw(picImage);
                    picImage.SaveAs(filePath);
                    _log.Debug("File path = " + filePath);
                    _log.Debug("Path = " + Path.Combine(Environment.SystemDirectory, "mspaint.exe"));
                    System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath);
                }

                // output to dxf file
                Pic.Factory2D.PicVisitorDxfOutput dxfOutputVisitor = new Pic.Factory2D.PicVisitorDxfOutput();
                factory0.ProcessVisitor(dxfOutputVisitor);

                // load dxf file
                PicFactory   factory1  = new PicFactory();
                PicLoaderDxf loaderDxf = new PicLoaderDxf(factory1);
                loaderDxf.Load(@"K:\Codesion\PicSharp\Samples\F1034.EV.DXF");
                loaderDxf.FillFactory();
                // save as image
                // get bounding box + draw
                using (PicVisitorBoundingBox visitor1 = new PicVisitorBoundingBox())
                {
                    factory1.ProcessVisitor(visitor1);
                    _log.Info(visitor1.Box.ToString());
                    string           filePath1 = Path.Combine(Path.GetTempPath(), "PicImage1.jpeg");
                    PicGraphicsImage picImage1 = new PicGraphicsImage();
                    picImage1.ImageSize = new System.Drawing.Size(512, 512);
                    Box2D box1 = visitor1.Box;
                    box1.AddMargin(5);
                    picImage1.DrawingBox = box1;
                    factory1.Draw(picImage1);
                    picImage1.SaveAs(filePath1);
                    _log.Debug("File path = " + filePath1);
                    _log.Debug("Path = " + Path.Combine(Environment.SystemDirectory, "mspaint.exe"));
                    System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath1);
                }

                // instantiate factory2
                PicFactory factory2 = new PicFactory();
                PicBlock   block    = factory2.AddBlock(factory0);
                factory2.AddBlockRef(block, new Vector2D(0.0, 0.0), 0.0);
                factory2.AddBlockRef(block, new Vector2D(400.0, 0.0), 0.0);
                factory2.AddBlockRef(block, new Vector2D(0.0, 400.0), 0.0);
                factory2.AddBlockRef(block, new Vector2D(400.0, 400.0), 45.0);

                // get bounding box of factory2
                using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox())
                {
                    factory2.ProcessVisitor(visitor);
                    _log.Info(visitor.Box.ToString());

                    // save as image
                    string           filePath = Path.Combine(Path.GetTempPath(), "PicImage2.jpeg");
                    PicGraphicsImage picImage = new PicGraphicsImage();
                    picImage.ImageSize = new System.Drawing.Size(512, 512);
                    Box2D box = visitor.Box;
                    box.AddMargin(5);
                    picImage.DrawingBox = box;
                    factory2.Draw(picImage);
                    picImage.SaveAs(filePath);
                    _log.Debug("File path = " + filePath);
                    _log.Debug("Path = " + Path.Combine(Environment.SystemDirectory, "mspaint.exe"));
                    System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath);
                }

                // compute area
                PicFactory factory3 = new PicFactory();
                factory3.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(-100.0, -100.0), new Vector2D(100.0, -100.0));
                factory3.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(100.0, -100.0), new Vector2D(100.0, 100.0));
                factory3.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(100.0, 100.0), new Vector2D(-100.0, 100.0));
                factory3.AddSegment(PicGraphics.LT.LT_CUT, 0, 0, new Vector2D(-100.0, 100.0), new Vector2D(-100.0, -100.0));

                PicToolArea picToolArea = new PicToolArea();
                factory3.ProcessTool(picToolArea);
                _log.Info(string.Format("Area of factory3 is {0}", picToolArea.Area));

                _log.Info("Pic.Factory2D.Test.exe finishing...");
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
コード例 #3
0
ファイル: FactoryDataCtrl.cs プロジェクト: minrogi/PLMPack
        public override void Refresh()
        {
            try
            {
                // create entities
                if (this.Parent is IEntitySupplier)
                    _entitySupplier = this.Parent as IEntitySupplier;
                if (null != _entitySupplier)
                {
                    // clear factory
                    _factory.Clear();
                    // update factory
                    _entitySupplier.CreateEntities(_factory);
                }

                // get selected tab and compute data accordingly
                switch (tabControlData.SelectedIndex)
                {
                    case 0:
                        // compute length
                        PicVisitorDieCutLength visitorLengthes = new PicVisitorDieCutLength();
                        _factory.ProcessVisitor(visitorLengthes);
                        // update controls
                        double lengthCut = 0.0, lengthFold = 0.0;
                        if (visitorLengthes.Lengths.ContainsKey(PicGraphics.LT.LT_CUT))
                            lengthCut = visitorLengthes.Lengths[PicGraphics.LT.LT_CUT];
                        lblValueLengthCut.Text = string.Format(": {0:0.###} m", lengthCut / 1000.0);
                        if (visitorLengthes.Lengths.ContainsKey(PicGraphics.LT.LT_CREASING))
                            lengthFold = visitorLengthes.Lengths[PicGraphics.LT.LT_CREASING];
                        lblValueLengthFold.Text = string.Format(": {0:0.###} m", lengthFold / 1000.0);
                        lblValueLengthTotal.Text = string.Format(": {0:0.###} m", (lengthCut + lengthFold) / 1000.0);
                        break;
                    case 1:
                        // compute bounding box
                        PicVisitorBoundingBox visitorBB = new PicVisitorBoundingBox();
                        _factory.ProcessVisitor(visitorBB, PicFilter.FilterCotation);
                        // update controls
                        lblValueLength.Text = string.Format(": {0:0.#} mm", visitorBB.Box.Width);
                        lblValueWidth.Text = string.Format(": {0:0.#} mm", visitorBB.Box.Height);
                        break;
                    case 2:
                        // compute area
                        try
                        {
                            PicToolArea picToolArea = new PicToolArea();
                            _factory.ProcessTool(picToolArea);
                            lblAreaValue.Text = string.Format(": {0:0.###} m²", (picToolArea.Area * 1.0E-06));
 
                        lblNameFormat.Visible = lblValueFormat.Visible = _factory.HasCardboardFormat;
                        lblNameEfficiency.Visible = lblValueEfficiency.Visible = _factory.HasCardboardFormat;

                        if (_factory.HasCardboardFormat)
                        {
                            lblValueFormat.Text = string.Format(": {0:0.#} x {1:0.#}", _factory.Format.Width, _factory.Format.Height);
                            lblValueEfficiency.Text = string.Format(": {0:0.#} %", 100.0 * picToolArea.Area / (_factory.Format.Width * _factory.Format.Height));
                        }
                       }
                        catch (PicToolTooLongException /*ex*/)
                        {
                            lblAreaValue.Text = Pic.Factory2D.Control.Properties.Resources.ID_ABANDONPROCESSING;
                            lblNameEfficiency.Visible = false;
                            lblValueEfficiency.Visible = false;
                        }
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }