Ejemplo n.º 1
0
        // This event handler is where the actual, potentially time-consuming work is done.
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            switch (type)
            {
            case Graphic.SourceTypes.SVG:
            { GCodeFromSVG.ConvertFromFile(source, worker, e); break; }

            case Graphic.SourceTypes.DXF:
            { GCodeFromDXF.ConvertFromFile(source, worker, e); break; }

            case Graphic.SourceTypes.HPGL:
            { GCodeFromHPGL.ConvertFromFile(source, worker, e); break; }

            case Graphic.SourceTypes.CSV:
            { GCodeFromCSV.ConvertFromFile(source, worker, e); break; }

            case Graphic.SourceTypes.Drill:
            { GCodeFromDrill.ConvertFromFile(source, worker, e); break; }

            case Graphic.SourceTypes.Gerber:
            { GCodeFromGerber.ConvertFromFile(source, worker, e); break; }
            }
//            VisuGCode.xyzSize.addDimensionXY(Graphic.actualDimension);
//            VisuGCode.calcDrawingArea();                                // calc ruler dimension
        }
Ejemplo n.º 2
0
        private void startConvertDXF(string source)
        {
            lastSource  = source;                       // store current file-path/name
            this.Cursor = Cursors.WaitCursor;
            string gcode = GCodeFromDXF.ConvertFile(source);

            if (gcode.Length > 2)
            {
                fCTBCode.Text = gcode;
                fCTBCode.UnbookmarkLine(fCTBCodeClickedLineLast);
                redrawGCodePath();
                SaveRecentFile(source);
                this.Text = appName + " | Source: " + source;
            }
            this.Cursor = Cursors.Default;
            updateControls();
        }
Ejemplo n.º 3
0
        // paste from clipboard SVG or image
        private void loadFromClipboard()
        {
            preset2DView();
            string      svg_format1 = "image/x-inkscape-svg";
            string      svg_format2 = "image/svg+xml";
            IDataObject iData       = Clipboard.GetDataObject();

            if (iData.GetDataPresent(DataFormats.Text))
            {
                string   checkContent = (String)iData.GetData(DataFormats.Text);
                string[] checkLines   = checkContent.Split('\n');
                int      posSVG       = checkContent.IndexOf("<svg ");
                if ((posSVG >= 0) && (posSVG < 2))
                {
                    MemoryStream stream = new MemoryStream();
                    stream = (MemoryStream)iData.GetData("text");
                    byte[] bytes = stream.ToArray();
                    string txt   = "";
                    if (!(checkContent.IndexOf("<?xml version") >= 0))
                    {
                        txt += "<?xml version=\"1.0\"?>\r\n";
                    }
                    txt += System.Text.Encoding.Default.GetString(bytes);
                    if (!(txt.IndexOf("xmlns") >= 0))
                    {
                        txt = txt.Replace("<svg", "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" ");
                    }

                    this.Cursor = Cursors.WaitCursor;
                    //MessageBox.Show(txt);
                    string gcode = GCodeFromSVG.convertFromText(txt.Trim((char)0x00), true);    // import as mm
                    if (gcode.Length > 2)
                    {
                        fCTBCode.Text = gcode;
                        fCTBCode.UnbookmarkLine(fCTBCodeClickedLineLast);
                        redrawGCodePath();
                        this.Text = appName + " | Source: from Clipboard";
                    }
                    this.Cursor = Cursors.Default;
                    updateControls();
                    setLastLoadedFile("Data from Clipboard: SVG");
                }
                else if ((checkLines[0].Trim() == "0") && (checkLines[1].Trim() == "SECTION"))
                {
                    MemoryStream stream = new MemoryStream();
                    stream = (MemoryStream)iData.GetData("text");
                    byte[] bytes = stream.ToArray();
                    string txt   = System.Text.Encoding.Default.GetString(bytes);

                    this.Cursor = Cursors.WaitCursor;
                    //MessageBox.Show(txt);
                    string gcode = GCodeFromDXF.convertFromText(txt);
                    if (gcode.Length > 2)
                    {
                        fCTBCode.Text = gcode;
                        fCTBCode.UnbookmarkLine(fCTBCodeClickedLineLast);
                        redrawGCodePath();
                        this.Text = appName + " | Source: from Clipboard";
                    }
                    this.Cursor = Cursors.Default;
                    updateControls();
                    setLastLoadedFile("Data from Clipboard: DXF");
                }
                else
                {
                    fCTBCode.Text = (String)iData.GetData(DataFormats.Text);
                    fCTBCode.UnbookmarkLine(fCTBCodeClickedLineLast);
                    redrawGCodePath();
                    setLastLoadedFile("Data from Clipboard: Text");
                }
            }
            else if (iData.GetDataPresent(svg_format1) || iData.GetDataPresent(svg_format2))
            {
                MemoryStream stream = new MemoryStream();
                if (iData.GetDataPresent(svg_format1))
                {
                    stream = (MemoryStream)iData.GetData(svg_format1);
                }
                else
                {
                    stream = (MemoryStream)iData.GetData(svg_format2);
                }

                byte[] bytes = stream.ToArray();
                string txt   = System.Text.Encoding.Default.GetString(bytes);
                this.Cursor = Cursors.WaitCursor;

                string gcode = GCodeFromSVG.convertFromText(txt);
                if (gcode.Length > 2)
                {
                    fCTBCode.Text = gcode;
                    fCTBCode.UnbookmarkLine(fCTBCodeClickedLineLast);
                    redrawGCodePath();
                    this.Text = appName + " | Source: from Clipboard";
                }
                this.Cursor = Cursors.Default;
                updateControls();
                setLastLoadedFile("Data from Clipboard: SVG");
            }
            else if (iData.GetDataPresent(DataFormats.Bitmap))
            {
                if (_image_form == null)
                {
                    _image_form                    = new GCodeFromImage(true);
                    _image_form.FormClosed        += formClosed_ImageToGCode;
                    _image_form.btnGenerate.Click += getGCodeFromImage;      // assign btn-click event
                }
                else
                {
                    _image_form.Visible = false;
                }
                _image_form.Show(this);
                _image_form.loadClipboard();
                setLastLoadedFile("Data from Clipboard: Image");
            }
            else
            {
                string tmp = "";
                foreach (string format in iData.GetFormats())
                {
                    tmp += format + "\r\n";
                }
                MessageBox.Show(tmp);
            }
        }