Example #1
0
        private void LoadFile(string s)
        {

            string outfile = Path.Combine(Path.GetDirectoryName(s), Path.GetFileNameWithoutExtension(s) + "_carved.gcode");
            try
            {

                var P = FenixSVG.LoadSVGToPolies(s,0,0);
                double tantoolangle = Math.Tan(toolangle / 2);
                cuttingdepth = -toolradiusatcuttingdepth / tantoolangle;

                Bounds B = new Bounds();
                foreach(var a in P)
                {
                    foreach( var b in a)
                    {
                        B.AddPolygon(b.ToPath());
                    }
                    
                }
                var C = B.Center();
                
    	        ClipPaths subj = new ClipPaths();
                foreach(var a in P)
                {
                    foreach( var b in a)
                    {
                        subj.Add(b.ToPath(-C.X*100000, -C.Y*100000));   
                    }
                }

                GCodeFile F = new GCodeFile();

                var R1 = ClipperLib.Clipper.OffsetPolygons(subj, (toolradiusatcuttingdepth * 1.5)*100000.0);

                // t = o / a
                // a = o / t

//              F.RectangularFillBetweenPolygons(R1, cuttingdepth, rapiddepth, toolradiusatcuttingdepth * 0.75, -B.Width() / 2 - 2, B.Width() / 2 + 2, -B.Height() / 2 - 2, B.Height() / 2 + 2, 0.2);
//              F.AddClipperPolygonsToCarve(R1, cuttingdepth, rapiddepth,0.5);


                var R =  ClipperLib.Clipper.OffsetPolygons(subj, toolradiusatcuttingdepth * 100000.0);                                
                F.AddClipperPolygonsToCarve(R, cuttingdepth, rapiddepth,0.5);
                
                toolradiusatcuttingdepth = 0.25;
                cuttingdepth = -toolradiusatcuttingdepth / tantoolangle;

                var R3 = ClipperLib.Clipper.OffsetPolygons(subj, toolradiusatcuttingdepth * 100000.0);
                F.AddClipperPolygonsToCarve(R3, cuttingdepth, rapiddepth,0.5);


                F.MoveTo(0, 0, rapiddepth, GCodeFile.MoveMode.Fast);
                F.MoveTo(0, 0, 0, GCodeFile.MoveMode.Slow);
                F.Write(outfile);

            }
            catch (Exception)
            {
                BackColor = Color.Red;
            }
        }