Esempio n. 1
0
        internal static bool openJobfile(string path)
        {
            bool result = false;

            try
            {
                if (m_scriptFile != null)
                {
                    m_scriptFile.Close();
                }
                m_scriptFile = new StreamReader(path);

                m_settingStace = SettingStace.globalSpace;
                initGloballStettingStyle();
                m_globalStyle       = m_cs.style1;
                m_isPreambuleFinish = false;
                startPosition       = 0;
                endPosition         = 0;
                addCommandAtEnd(Command.Nop, 0, 0, 0, 0);
                Array.Clear(actualArgs, 0, 3);
                m_layerReaded = 0;
                isValidFile   = 1;
                m_fileName    = path;
                result        = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not read file from disk. Error: " + ex.Message + "  " + path);
            }
            return(result);
        }
Esempio n. 2
0
 static fileLoader()
 {
     runPermission  = 1;
     isValidFile    = 0;
     m_settingStace = SettingStace.globalSpace;
     initGloballStettingStyle();
     m_loaThread = new Thread(fillJobList);
     m_loaThread.Start();
 }
Esempio n. 3
0
        static void fillJobList()
        {
            int multilp = 0;

            while (runPermission == 1)
            {
                m_mut.WaitOne();
                if (m_resetFile)
                {
                    m_resetFile = false;

                    try { m_scriptFile.Close(); }
                    catch { }

                    openJobfile(m_fileName);
                }
                else if (isValidFile == 1 && isNextFree())
                {
                    multilp += 1;
                    try
                    {
                        m_isBufferFull = false;

                        string str = m_scriptFile.ReadLine();
                        if (str != null)
                        {
                            string command = "";

                            Match matchC = comand.Match(str);
                            if (matchC.Success)
                            {
                                command = matchC.Value;
                            }

                            if (command == "F_In")
                            {
                                m_layerReaded++;
                                m_isPreambuleFinish = true;
                            }
                            if (m_isPreambuleFinish && m_layerReaded < m_cs.startLayer)
                            {
                                command = "IGNORE";
                            }


                            switch (command)
                            {
                            case "IGNORE":

                                break;

                            case "Image.Line":

                                MatchCollection matches = regexOperand.Matches(str);

                                if (matches.Count == 4)
                                {
                                    //string[] arg = new string[4];
                                    // matches.CopyTo(arg, 0);
                                    for (int i = 0; i < 4; i++)
                                    {
                                        string str1 = matches[i].Value;
                                        float  f1   = float.Parse(matches[i].Value, System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture) * m_cs.scale;
                                        //  if (i == 0 || i == 2) f1 *= m_cs.korrX;
                                        //  else f1 *= m_cs.korrY;
                                        actualArgs[i] = (Int16)(f1);
                                    }
                                    Int16 x0 = actualArgs[0];
                                    Int16 y0 = actualArgs[1];
                                    Int16 x1 = actualArgs[2];
                                    Int16 y1 = actualArgs[3];
                                    correctLastPol(x0, y0);
                                    if (isPolA(x0, y0))
                                    {
                                        addCommandAtEnd(Command.Jamp, x0, y0, 0, 0);
                                        addCommandAtEnd(Command.PolA_Abs, x1, y1, 0, 0, str);
                                    }
                                    else if (isPolB(x0, y0))
                                    {
                                        addCommandAtEnd(Command.PolB_Abs, x1, y1, 0, 0, str);
                                    }

                                    else
                                    {
                                        isValidFile = 0;
                                        MessageBox.Show("Can't determinate command type, str = " + str);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Invalid command:  str = " + str + ", requre 4 arg for Image.Line");
                                    isValidFile = 0;
                                }
                                break;

                            case "F_In":
                                addCommandAtEnd(Command.StarLayer, (Int16)m_layerReaded, 0, 0, 0, str);
                                m_settingStace = SettingStace.listSpace;
                                break;

                            case "F_Out":
                                correctLastPol(Int16.MaxValue, Int16.MaxValue, true);
                                addCommandAtEnd(Command.EndLayer, (Int16)m_layerReaded, 0, 0, 0, str);
                                m_settingStace = SettingStace.globalSpace;
                                break;

                            case "Laser.Power":
                                if (m_cs.ignoreLocalSetting)
                                {
                                    break;
                                }
                                correctLastPol(Int16.MaxValue, Int16.MaxValue, true);
                                UInt32          power        = 0;
                                MatchCollection matchesPower = regexOperand.Matches(str);
                                if (matchesPower.Count == 1)
                                {
                                    string strPower = matchesPower[0].Value;
                                    power = UInt32.Parse(strPower);
                                }
                                else
                                {
                                    MessageBox.Show("Invalid command:  str = " + str + ", requre 1 arg for Laser.Power");
                                    isValidFile = 0;
                                }

                                //power = (power >> 24);
                                if (m_settingStace == SettingStace.globalSpace)
                                {
                                    m_globalStyle.lPower = power;
                                    if (m_cs.debug)
                                    {
                                        printDebug(string.Format("{0, 10}:  {1, -12}  {2, -10} {3, -10}   => {4}", "global", command, power, 0, str));
                                    }
                                }
                                else
                                {
                                    addCommandAtEnd(Command.Power, (Int16)power, 0, 0, 0, str);
                                }
                                break;

                            case "Laser.MarkSpeed":
                                if (m_cs.ignoreLocalSetting)
                                {
                                    break;
                                }
                                correctLastPol(Int16.MaxValue, Int16.MaxValue, true);

                                UInt32          markSpeed = 0;
                                MatchCollection speed     = regexOperand.Matches(str);
                                if (speed.Count == 1)
                                {
                                    string strPower = speed[0].Value;
                                    markSpeed = UInt32.Parse(strPower);
                                }
                                else
                                {
                                    MessageBox.Show("Invalid command:  str = " + str + ", requre 1 arg for Laser.MarkSpeed");
                                    isValidFile = 0;
                                }

                                UInt32 markSize = (UInt32)helpers.speedToJampPeriod((Int64)m_cs.style1.lStep, (float)markSpeed, m_cs.scale);
                                if (m_settingStace == SettingStace.globalSpace)
                                {
                                    m_globalStyle.lMarkSize = markSize;
                                    if (m_cs.debug)
                                    {
                                        printDebug(string.Format("{0, 10}:  {1, -12}  {2, -10} {3, -10}   => {4}", "global", command, markSize, 0, str));
                                    }
                                }
                                else
                                {
                                    addCommandAtEnd(Command.MarkSize, (Int16)m_cs.style1.lStep, (Int16)markSize, 0, 0, str);
                                }

                                break;

                            case "Image.Polyline3D":

                                MatchCollection pol3D = regexOperand.Matches(str.Substring(16));

                                correctLastPol(0, 0, true);
                                int endPol = (int)(pol3D.Count / 3);
                                if (endPol > 900)
                                {
                                    isValidFile = 0;
                                    MessageBox.Show("polyline3D имеет слишком много аргументов :" + endPol.ToString());
                                }
                                for (int i = 0; i < endPol; i++)
                                {
                                    int   itX = i * 3;
                                    int   itY = i * 3 + 1;
                                    Int16 x   = (Int16)(float.Parse(pol3D[itX].Value, System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture) * m_cs.scale /* m_cs.korrX*/);
                                    Int16 y   = (Int16)(float.Parse(pol3D[itY].Value, System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture) * m_cs.scale /* m_cs.korrY*/);

                                    if (i == 0)
                                    {
                                        addCommandAtEnd(Command.Jamp, x, y, 0, 0, string.Format("Image.Polyline3D #{0, 5}  ( {1, 5}, {2, 5} )", i, pol3D[itX].Value, pol3D[itY].Value));
                                    }
                                    else if (i == 1)
                                    {
                                        addCommandAtEnd(Command.PolA_Abs, x, y, 0, 0, string.Format("Image.Polyline3D #{0, 5}  ( {1, 5}, {2, 5} )", i, pol3D[itX].Value, pol3D[itY].Value));
                                    }
                                    else if (i == endPol - 1)
                                    {
                                        addCommandAtEnd(Command.PolC_Abs, x, y, 0, 0, string.Format("Image.Polyline3D #{0, 5}  ( {1, 5}, {2, 5} )", i, pol3D[itX].Value, pol3D[itY].Value));
                                    }
                                    else
                                    {
                                        addCommandAtEnd(Command.PolB_Abs, x, y, 0, 0, string.Format("Image.Polyline3D #{0, 5}  ( {1, 5}, {2, 5} )", i, pol3D[itX].Value, pol3D[itY].Value));
                                    }
                                }

                                break;
                            }
                        }
                        else
                        {
                            correctLastPol(0, 0, true);
                            addCommandAtEnd(Command.Nop, 0, 0, 0, 0);
                            addCommandAtEnd(Command.EndF, 0, 0, 0, 0);
                            isValidFile = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: Could not read file from disk. Error: " + ex.Message);
                        isValidFile = 0;
                    }
                }
                else
                {
                    m_isBufferFull = true;
                }

                m_mut.ReleaseMutex();
                if (m_isBufferFull)
                {
                    Thread.Sleep(10);
                }
                else if (multilp > 100000)
                {
                    // Thread.Sleep(0);
                    multilp = 0;
                }
                //  else
                //      Thread.Sleep(0);
            }
        }