Пример #1
0
 private void imageToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (_image_form == null)
     {
         _image_form                    = new GCodeFromImage();
         _image_form.FormClosed        += formClosed_ImageToGCode;
         _image_form.btnGenerate.Click += getGCodeFromImage;      // assign btn-click event
     }
     else
     {
         _image_form.Visible = false;
     }
     _image_form.Show(this);
 }
Пример #2
0
        private void tBURL_TextChanged(object sender, EventArgs e)
        {
            var    parts = tBURL.Text.Split('.');
            string ext   = parts[parts.Length - 1]; // get extension

            if (ext.ToLower().IndexOf("svg") >= 0)
            {
                startConvertSVG(tBURL.Text);
                setLastLoadedFile("Data from URL: " + tBURL.Text);
                tBURL.Text = "";
            }
            else if (ext.ToLower().IndexOf("dxf") >= 0)
            {
                startConvertDXF(tBURL.Text);
                setLastLoadedFile("Data from URL: " + tBURL.Text);
                tBURL.Text = "";
            }
            else if ((ext.ToLower().IndexOf("bmp") >= 0) || (ext.ToLower().IndexOf("gif") >= 0) || (ext.ToLower().IndexOf("png") >= 0) || (ext.ToLower().IndexOf("jpg") >= 0))
            {
                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.loadURL(tBURL.Text);
                setLastLoadedFile("Data from URL: " + tBURL.Text);
                tBURL.Text = "";
            }
            else
            {
                if (tBURL.Text.Length > 5)
                {
                    MessageBox.Show("URL extension is not 'svg' or 'dxf'\r\nTry SVG import anyway, but without setting 'Recent File' list.");
                    startConvertSVG(tBURL.Text);
                }
            }
        }
Пример #3
0
        private void loadFile(string fileName)
        {
            if (fileName.IndexOf("http") >= 0)
            {
                tBURL.Text = fileName;
                return;
            }
            else
            {
                if (!File.Exists(fileName))
                {
                    MessageBox.Show("File not found: '" + fileName + "'");
                    return;
                }
            }
            preset2DView();

            String ext = Path.GetExtension(fileName).ToLower();

            if (ext == ".svg")
            {
                startConvertSVG(fileName);
            }
            else if (ext == ".dxf")
            {
                startConvertDXF(fileName);
            }
            else if ((ext == ".drd") || (ext == ".drl") || (ext == ".dri"))
            {
                startConvertDrill(fileName);
            }
            else if (ext == ".nc")
            {
                tbFile.Text = fileName;
                loadGcode();
            }
            else if ((ext == ".bmp") || (ext == ".gif") || (ext == ".png") || (ext == ".jpg"))
            {
                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.loadExtern(fileName);
            }
            SaveRecentFile(fileName);
            setLastLoadedFile("Data from file: " + fileName);

            if (ext == ".url")
            {
                getURL(fileName);
            }
            Cursor.Current = Cursors.Default;
            pBoxTransform.Reset();
        }
Пример #4
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);
            }
        }
Пример #5
0
 private void formClosed_ImageToGCode(object sender, FormClosedEventArgs e)
 {
     _image_form = null;
 }
Пример #6
0
        // paste from clipboard SVG or image
        private void loadFromClipboard()
        {
            string      svg_format1 = "image/x-inkscape-svg";
            string      svg_format2 = "image/svg+xml";
            IDataObject iData       = Clipboard.GetDataObject();

            if (iData.GetDataPresent(DataFormats.Text))
            {
                fCTBCode.Text = (String)iData.GetData(DataFormats.Text);
                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);
            }
        }