示例#1
0
        public void CreateEntities(PicFactory factory)
        {
            if (null == _entities)
            {
                return;
            }
            // show entities
            for (int i = 0; i < Math.Min(_entities.Count, trackBarEntities.Value); ++i)
            {
                PicTypedDrawable entity = _entities[i];
                PicSegment       seg    = entity as PicSegment;
                if (null != seg)
                {
                    factory.AddSegment(seg.LineType, seg.Group, seg.Layer, seg.Pt0, seg.Pt1);
                }

                PicArc arc = entity as PicArc;
                if (null != arc)
                {
                    factory.AddArc(arc.LineType, arc.Group, arc.Layer, arc.Center, arc.Radius, arc.AngleBeg, arc.AngleEnd);
                }
            }
        }
示例#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
        /// <summary>
        /// 
        /// </summary>
        /// <param name="factory"></param>
        public override void ProcessFactory(PicFactory factory)
        {
            // will only work with 2 segments
            if (null == _picSeg0 || null == _picSeg1)
                throw new NotImplementedException("Only segment entities are supported");

            // get inner segments
            Segment seg0 = new Segment(_picSeg0.Pt0, _picSeg0.Pt1);
            Segment seg1 = new Segment(_picSeg1.Pt0, _picSeg1.Pt1);

            // find line intersection and extend segments so that they intersect
            Intersection2D interobj;
            if (!IntersectMethods.IntersectLines(seg0, seg1, out interobj) || interobj == null || interobj.Type != Intersection2D.IntersectionType.I2D_POINT)  return;
            Vector2D ptExt = (Vector2D)interobj.Result;
            seg0 = extendSegment(seg0, ptExt);
            seg1 = extendSegment(seg1, ptExt);

            // create parallel segments
            Segment seg00, seg01;
            getParalleleSegments(seg0, _radius, out seg00, out seg01);
            Segment seg10, seg11;
            getParalleleSegments(seg1, _radius, out seg10, out seg11);

            // compute intersection
            if (IntersectMethods.Intersect(seg00, seg10, out interobj)) { }
            else if (IntersectMethods.Intersect(seg00, seg11, out interobj)) { }
            else if (IntersectMethods.Intersect(seg01, seg10, out interobj)) { }
            else if (IntersectMethods.Intersect(seg01, seg11, out interobj)) { }

            if (interobj == null || interobj.Type != Intersection2D.IntersectionType.I2D_POINT) return;
            Vector2D ptCenter = (Vector2D)interobj.Result;

            // get intersection of normal with seg0
            if (IntersectMethods.Intersect(seg0, new Segment(ptCenter, ptCenter + new Vector2D(-(seg0.P1 - seg0.P0).Y, (seg0.P1 - seg0.P0).X)), out interobj)) { }
            else if (IntersectMethods.Intersect(seg0, new Segment(ptCenter, ptCenter + new Vector2D((seg0.P1 - seg0.P0).Y, -(seg0.P1 - seg0.P0).X)), out interobj)) { }
            else return;
            if (interobj == null && interobj.Type != Intersection2D.IntersectionType.I2D_POINT) return;
            Vector2D pt0 = (Vector2D)interobj.Result;

            if (IntersectMethods.Intersect(seg1, new Segment(ptCenter, ptCenter + new Vector2D(-(seg1.P1 - seg1.P0).Y, (seg1.P1 - seg1.P0).X)), out interobj)) { }
            else if (IntersectMethods.Intersect(seg1, new Segment(ptCenter, ptCenter + new Vector2D((seg1.P1 - seg1.P0).Y, -(seg1.P1 - seg1.P0).X)), out interobj)) { }
            else return;
            if (interobj == null && interobj.Type != Intersection2D.IntersectionType.I2D_POINT) return;
            Vector2D pt1 = (Vector2D)interobj.Result;

            // intersection of 2D segments
            if (!IntersectMethods.Intersect(seg0, seg1, out interobj)) return;
            if (interobj == null && interobj.Type != Intersection2D.IntersectionType.I2D_POINT) return;
            Vector2D ptInter = (Vector2D)interobj.Result;

            // modify segments
            if ((seg0.P0 - ptInter).GetLength() < (seg0.P1 - ptInter).GetLength())
            {
                _picSeg0.Pt0 = pt0;
                _picSeg0.Pt1 = seg0.P1;
            }
            else
            {
                _picSeg0.Pt0 = pt0;
                _picSeg0.Pt1 = seg0.P0;
            }

            if ((seg1.P0 - ptInter).GetLength() < (seg1.P1 - ptInter).GetLength())
            {
                _picSeg1.Pt0 = pt1;
                _picSeg1.Pt1 = seg1.P1;
            }
            else
            {
                _picSeg1.Pt0 = pt1;
                _picSeg1.Pt1 = seg1.P0;
            }

            // create new arc of circle
            if (Vector2D.KrossProduct(pt0 - ptCenter, pt1 - ptCenter) > 0) // go from pt0 to pt1
                factory.AddArc(_picSeg0.LineType, _picSeg0.Group, _picSeg0.Layer, ptCenter, pt0, pt1);
            else // from pt1 to pt0
                factory.AddArc(_picSeg0.LineType, _picSeg0.Group, _picSeg0.Layer, ptCenter, pt1, pt0);
        }
示例#4
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, new Vector2D(0.0, 0.0));
                factory0.AddSegment(PicGraphics.LT.LT_CUT, new Vector2D(50.0, 50.0), new Vector2D(100.0, 100.0));
                factory0.AddSegment(PicGraphics.LT.LT_CUT, new Vector2D(-100.0, 100.0), new Vector2D(100.0, -100.0));
                factory0.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(50.0, 50.0), 50.0 * Math.Sqrt(2.0), 0.0, 360.0);
                factory0.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(75.0, 75.0), 25.0 * Math.Sqrt(2.0), 0.0, 360.0);
                factory0.AddNurb(PicGraphics.LT.LT_CUT);
                _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, new Vector2D(-100.0, -100.0), new Vector2D(100.0, -100.0));
                factory3.AddSegment(PicGraphics.LT.LT_CUT, new Vector2D(100.0, -100.0), new Vector2D(100.0, 100.0));
                factory3.AddSegment(PicGraphics.LT.LT_CUT, new Vector2D(100.0, 100.0), new Vector2D(-100.0, 100.0));
                factory3.AddSegment(PicGraphics.LT.LT_CUT, 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());
            }
        }
示例#5
0
        public void CreateFactoryEntities(PicFactory factory, ParameterStack stack, Transform2D transform)
        {
            PicFactory fTemp = new PicFactory();
            const PicGraphics.LT ltCut = PicGraphics.LT.LT_CUT;
            const PicGraphics.LT ltFold = PicGraphics.LT.LT_CREASING;

            // get parameter values
            double L = stack.GetDoubleParameterValue("L");
            double H = stack.GetDoubleParameterValue("H");
            double E = stack.GetDoubleParameterValue("E");
            int PoignsurTete = stack.GetMultiParameterValue("PoignsurTete");

            short layer = 1;
            short grp = 1;
            PicGraphics.LT lt = ltCut;
            if (PoignsurTete >= 2)
            {
                lt = ltFold;
                layer = 2;
            }
            double x1 = (L-H)/2.0;
            double y1 = 0.0;
            double x2 = x1 - (L - H);
            double y2 = y1;
            fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

            lt = ltCut;
            double ry = H / 2.0;
            double xc = x2;
            double yc = - H / 2.0;
            fTemp.AddArc(lt, grp, layer, xc, yc, ry, 90.0, 270.0);

            x1 = xc;
            y1 = -H;
            x2 = x1 + (L - H);
            y2 = y1;
            fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

            ry = H / 2.0;
            xc = x2;
            yc = -H / 2.0;
            fTemp.AddArc(lt, grp, layer, xc, yc, ry, -90.0, 90.0);

            if (PoignsurTete == 3)
            {
                lt = ltCut;
                x1 = (L - H) / 2.0;
                y1 = 0.0;
                x2 = x1;
                y2 = y1 + E;
                fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

                x1 = x2;
                y1 = y2;
                x2 = x1 + E;
                y2 = y1;
                fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

                x1 = -(L - H) / 2.0;
                y1 = 0.0;
                x2 = x1;
                y2 = y1 + E;
                fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

                x1 = x2;
                y1 = y2;
                x2 = x1 - E;
                y2 = y1;
                fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

                lt = ltFold;
                x2 = x1 + (L - H);
                y2 = y1;
                fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);
            }

            factory.AddEntities(fTemp, transform);
        }
示例#6
0
        public void CreateFactoryEntities(PicFactory factory, ParameterStack stack, Transform2D transform)
        {
            PicFactory fTemp = new PicFactory();
            // free variables
            double a0 = stack.GetDoubleParameterValue("a0");
            double a1 = stack.GetDoubleParameterValue("a1");
            bool bbox = stack.GetBoolParameterValue("bbox");
            bool arcDefault = stack.GetBoolParameterValue("Arc default");
            bool arcReflX = stack.GetBoolParameterValue("Arc Refl X");
            bool arcReflY = stack.GetBoolParameterValue("Arc Refl Y");
            bool arcReflXY = stack.GetBoolParameterValue("Arc Refl XY");
            bool arcComplement = stack.GetBoolParameterValue("Complement");

            if (arcDefault)
            {
                PicArc arc0 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1);
                arc0.Transform(Transform2D.Identity);

                if (bbox)
                {
                    Box2D box = arc0.Box;
                    fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0
                        , box.PtMin.X	// x0
                        , box.PtMin.Y	// y0
                        , box.PtMax.X	// x1
                        , box.PtMin.Y	// y1
                        );
                    fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0
                        , box.PtMax.X	// x0
                        , box.PtMin.Y	// y0
                        , box.PtMax.X	// x1
                        , box.PtMax.Y	// y1
                        );
                    fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0
                        , box.PtMin.X	// x0
                        , box.PtMax.Y	// y0
                        , box.PtMax.X	// x1
                        , box.PtMax.Y	// y1
                        );
                    fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0
                        , box.PtMin.X	// x0
                        , box.PtMin.Y	// y0
                        , box.PtMin.X	// x1
                        , box.PtMax.Y	// y1
                        );
                }
            }
            if (arcReflY)
            {
                PicArc arc1 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1);
                arc1.Transform(Transform2D.ReflectionY);
            }
            if (arcReflX)
            {
                PicArc arc2 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1);
                arc2.Transform(Transform2D.ReflectionX);
            }
            if (arcReflXY)
            {
                PicArc arc3 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1);
                arc3.Transform(Transform2D.ReflectionX * Transform2D.ReflectionY);
            }
            if (arcComplement)
            {
                PicArc arc4 = fTemp.AddArc(PicGraphics.LT.LT_COTATION, new Vector2D(0.0, 0.0), 100.0, a0, a1);
                arc4.Complement();
            }
            
            // end
            factory.AddEntities(fTemp, transform);
        }
示例#7
0
        public void CreateFactoryEntities(PicFactory factory, ParameterStack stack, Transform2D transform)
        {
            PicFactory fTemp = new PicFactory();
            // free variables
            double a0            = stack.GetDoubleParameterValue("a0");
            double a1            = stack.GetDoubleParameterValue("a1");
            bool   bbox          = stack.GetBoolParameterValue("bbox");
            bool   arcDefault    = stack.GetBoolParameterValue("Arc default");
            bool   arcReflX      = stack.GetBoolParameterValue("Arc Refl X");
            bool   arcReflY      = stack.GetBoolParameterValue("Arc Refl Y");
            bool   arcReflXY     = stack.GetBoolParameterValue("Arc Refl XY");
            bool   arcComplement = stack.GetBoolParameterValue("Complement");

            if (arcDefault)
            {
                PicArc arc0 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1);
                arc0.Transform(Transform2D.Identity);

                if (bbox)
                {
                    Box2D box = arc0.Box;
                    fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0
                                     , box.PtMin.X // x0
                                     , box.PtMin.Y // y0
                                     , box.PtMax.X // x1
                                     , box.PtMin.Y // y1
                                     );
                    fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0
                                     , box.PtMax.X // x0
                                     , box.PtMin.Y // y0
                                     , box.PtMax.X // x1
                                     , box.PtMax.Y // y1
                                     );
                    fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0
                                     , box.PtMin.X // x0
                                     , box.PtMax.Y // y0
                                     , box.PtMax.X // x1
                                     , box.PtMax.Y // y1
                                     );
                    fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0
                                     , box.PtMin.X // x0
                                     , box.PtMin.Y // y0
                                     , box.PtMin.X // x1
                                     , box.PtMax.Y // y1
                                     );
                }
            }
            if (arcReflY)
            {
                PicArc arc1 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1);
                arc1.Transform(Transform2D.ReflectionY);
            }
            if (arcReflX)
            {
                PicArc arc2 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1);
                arc2.Transform(Transform2D.ReflectionX);
            }
            if (arcReflXY)
            {
                PicArc arc3 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1);
                arc3.Transform(Transform2D.ReflectionX * Transform2D.ReflectionY);
            }
            if (arcComplement)
            {
                PicArc arc4 = fTemp.AddArc(PicGraphics.LT.LT_COTATION, new Vector2D(0.0, 0.0), 100.0, a0, a1);
                arc4.Complement();
            }

            // end
            factory.AddEntities(fTemp, transform);
        }
示例#8
0
        public void CreateFactoryEntities(PicFactory factory, ParameterStack stack, Transform2D transform)
        {
            PicFactory           fTemp  = new PicFactory();
            const PicGraphics.LT ltCut  = PicGraphics.LT.LT_CUT;
            const PicGraphics.LT ltFold = PicGraphics.LT.LT_CREASING;

            // get parameter values
            double L            = stack.GetDoubleParameterValue("L");
            double H            = stack.GetDoubleParameterValue("H");
            double E            = stack.GetDoubleParameterValue("E");
            int    PoignsurTete = stack.GetMultiParameterValue("PoignsurTete");

            short layer = 1;
            short grp   = 1;

            PicGraphics.LT lt = ltCut;
            if (PoignsurTete >= 2)
            {
                lt    = ltFold;
                layer = 2;
            }
            double x1 = (L - H) / 2.0;
            double y1 = 0.0;
            double x2 = x1 - (L - H);
            double y2 = y1;

            fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

            lt = ltCut;
            double ry = H / 2.0;
            double xc = x2;
            double yc = -H / 2.0;

            fTemp.AddArc(lt, grp, layer, xc, yc, ry, 90.0, 270.0);

            x1 = xc;
            y1 = -H;
            x2 = x1 + (L - H);
            y2 = y1;
            fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

            ry = H / 2.0;
            xc = x2;
            yc = -H / 2.0;
            fTemp.AddArc(lt, grp, layer, xc, yc, ry, -90.0, 90.0);

            if (PoignsurTete == 3)
            {
                lt = ltCut;
                x1 = (L - H) / 2.0;
                y1 = 0.0;
                x2 = x1;
                y2 = y1 + E;
                fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

                x1 = x2;
                y1 = y2;
                x2 = x1 + E;
                y2 = y1;
                fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

                x1 = -(L - H) / 2.0;
                y1 = 0.0;
                x2 = x1;
                y2 = y1 + E;
                fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

                x1 = x2;
                y1 = y2;
                x2 = x1 - E;
                y2 = y1;
                fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);

                lt = ltFold;
                x2 = x1 + (L - H);
                y2 = y1;
                fTemp.AddSegment(lt, grp, layer, x1, y1, x2, y2);
            }

            factory.AddEntities(fTemp, transform);
        }
示例#9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="factory"></param>
        public override void ProcessFactory(PicFactory factory)
        {
            // will only work with 2 segments
            if (null == _picSeg0 || null == _picSeg1)
            {
                throw new NotImplementedException("Only segment entities are supported");
            }

            // get inner segments
            Segment seg0 = new Segment(_picSeg0.Pt0, _picSeg0.Pt1);
            Segment seg1 = new Segment(_picSeg1.Pt0, _picSeg1.Pt1);

            // find line intersection and extend segments so that they intersect
            Intersection2D interobj;

            if (!IntersectMethods.IntersectLines(seg0, seg1, out interobj) || interobj == null || interobj.Type != Intersection2D.IntersectionType.I2D_POINT)
            {
                return;
            }
            Vector2D ptExt = (Vector2D)interobj.Result;

            seg0 = extendSegment(seg0, ptExt);
            seg1 = extendSegment(seg1, ptExt);

            // create parallel segments
            Segment seg00, seg01;

            getParalleleSegments(seg0, _radius, out seg00, out seg01);
            Segment seg10, seg11;

            getParalleleSegments(seg1, _radius, out seg10, out seg11);

            // compute intersection
            if (IntersectMethods.Intersect(seg00, seg10, out interobj))
            {
            }
            else if (IntersectMethods.Intersect(seg00, seg11, out interobj))
            {
            }
            else if (IntersectMethods.Intersect(seg01, seg10, out interobj))
            {
            }
            else if (IntersectMethods.Intersect(seg01, seg11, out interobj))
            {
            }

            if (interobj == null || interobj.Type != Intersection2D.IntersectionType.I2D_POINT)
            {
                return;
            }
            Vector2D ptCenter = (Vector2D)interobj.Result;

            // get intersection of normal with seg0
            if (IntersectMethods.Intersect(seg0, new Segment(ptCenter, ptCenter + new Vector2D(-(seg0.P1 - seg0.P0).Y, (seg0.P1 - seg0.P0).X)), out interobj))
            {
            }
            else if (IntersectMethods.Intersect(seg0, new Segment(ptCenter, ptCenter + new Vector2D((seg0.P1 - seg0.P0).Y, -(seg0.P1 - seg0.P0).X)), out interobj))
            {
            }
            else
            {
                return;
            }
            if (interobj == null && interobj.Type != Intersection2D.IntersectionType.I2D_POINT)
            {
                return;
            }
            Vector2D pt0 = (Vector2D)interobj.Result;

            if (IntersectMethods.Intersect(seg1, new Segment(ptCenter, ptCenter + new Vector2D(-(seg1.P1 - seg1.P0).Y, (seg1.P1 - seg1.P0).X)), out interobj))
            {
            }
            else if (IntersectMethods.Intersect(seg1, new Segment(ptCenter, ptCenter + new Vector2D((seg1.P1 - seg1.P0).Y, -(seg1.P1 - seg1.P0).X)), out interobj))
            {
            }
            else
            {
                return;
            }
            if (interobj == null && interobj.Type != Intersection2D.IntersectionType.I2D_POINT)
            {
                return;
            }
            Vector2D pt1 = (Vector2D)interobj.Result;

            // intersection of 2D segments
            if (!IntersectMethods.Intersect(seg0, seg1, out interobj))
            {
                return;
            }
            if (interobj == null && interobj.Type != Intersection2D.IntersectionType.I2D_POINT)
            {
                return;
            }
            Vector2D ptInter = (Vector2D)interobj.Result;

            // modify segments
            if ((seg0.P0 - ptInter).GetLength() < (seg0.P1 - ptInter).GetLength())
            {
                _picSeg0.Pt0 = pt0;
                _picSeg0.Pt1 = seg0.P1;
            }
            else
            {
                _picSeg0.Pt0 = pt0;
                _picSeg0.Pt1 = seg0.P0;
            }

            if ((seg1.P0 - ptInter).GetLength() < (seg1.P1 - ptInter).GetLength())
            {
                _picSeg1.Pt0 = pt1;
                _picSeg1.Pt1 = seg1.P1;
            }
            else
            {
                _picSeg1.Pt0 = pt1;
                _picSeg1.Pt1 = seg1.P0;
            }

            // create new arc of circle
            if (Vector2D.KrossProduct(pt0 - ptCenter, pt1 - ptCenter) > 0) // go from pt0 to pt1
            {
                factory.AddArc(_picSeg0.LineType, _picSeg0.Group, _picSeg0.Layer, ptCenter, pt0, pt1);
            }
            else // from pt1 to pt0
            {
                factory.AddArc(_picSeg0.LineType, _picSeg0.Group, _picSeg0.Layer, ptCenter, pt1, pt0);
            }
        }