Example #1
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Parses out the line and gets the required information from it
        /// </summary>
        /// <param name="processedLineStr">a line string without block terminator or format parameters</param>
        /// <param name="stateMachine">The state machine containing the implied modal values</param>
        /// <returns>z success, nz fail</returns>
        public override int ParseLine(string processedLineStr, ExcellonFileStateMachine stateMachine)
        {
            int  outInt       = -1;
            int  nextStartPos = 0;
            bool retBool;

            //DebugMessage("Excellon ParseLine(TChange) started");

            if (processedLineStr == null)
            {
                return(100);
            }
            if (processedLineStr.StartsWith("T") == false)
            {
                return(200);
            }

            // now the TCode line will have an T tag

            // LOOK FOR THE T TAG
            nextStartPos = 0;
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(processedLineStr, 'T', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > processedLineStr.Length))
            {
                // this is not an error - just means we did not find one
            }
            else
            {
                // this will have a integer number
                retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetInteger(processedLineStr, nextStartPos, ref outInt, ref nextStartPos);
                if (retBool != true)
                {
                    LogMessage("Excellon ParseLine(T) failed on call to ParseNumberFromString_TillNonDigit_RetInteger");
                    return(333);
                }
                else
                {
                    // set the value now
                    toolNumber = outInt;
                }
            }

            return(0);
        }
Example #2
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Parses out the line and gets the required information from it
        /// </summary>
        /// <param name="processedLineStr">a line string without block terminator or format parameters</param>
        /// <param name="stateMachine">The state machine containing the implied modal values</param>
        /// <returns>z success, nz fail</returns>
        public override int ParseLine(string processedLineStr, ExcellonFileStateMachine stateMachine)
        {
            int  outInt       = -1;
            int  nextStartPos = 0;
            bool retBool;

            //DebugMessage("Excellon ParseLine(M) started");

            if (processedLineStr == null)
            {
                return(100);
            }
            if (processedLineStr.StartsWith("G") == false)
            {
                return(200);
            }

            // now the GCode line will have an G tag

            // LOOK FOR THE G TAG
            nextStartPos = 0;
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(processedLineStr, 'G', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > processedLineStr.Length))
            {
                // this is not an error - just means we did not find one
                LogMessage("Excellon ParseLine(G) failed on call to FindCharacterReturnNextPos  no next char found.");
                return(101);
            }
            else
            {
                // this will have a integer number
                retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetInteger(processedLineStr, nextStartPos, ref outInt, ref nextStartPos);
                if (retBool != true)
                {
                    LogMessage("Excellon ParseLine(G) failed on call to ParseNumberFromString_TillNonDigit_RetInteger");
                    return(333);
                }
                else
                {
                    // set the value now
                    currentGCode = outInt;
                }

                // validate the GCode
                switch (currentGCode)
                {
                case 0:
                    // this is not ok, it is Rout Mode
                    LogMessage("Excellon ParseLine(G) code G00, routing mode is not supported");
                    return(1091);

                case 5:
                    // this is ok, it is just Drill Mode
                    return(0);

                case 90:
                    // this is ok, it is just absolute mode
                    return(0);

                case 91:
                    // this is not ok, it is incrememtal mode
                    LogMessage("Excellon ParseLine(G) code G91, incremental mode is not supported");
                    return(1095);

                default:
                    LogMessage("Excellon ParseLine(G) unknown code G" + CurrentGCode.ToString());
                    return(102);
                }
            }
        }
Example #3
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Adds a Excellon file line to the SourceLines
        /// </summary>
        /// <param name="lineStr">The line to add</param>
        /// <param name="lineNumber">The line number</param>
        public int AddLine(string lineStr, int lineNumber)
        {
            int    retInt;
            string tmpLine1;

            if (lineStr == null)
            {
                return(100);
            }
            // trim it up, remove comments
            tmpLine1 = GerberParseUtils.RemoveTrailingCommentsFromString(lineStr, ANSI349COMMENTDELIMITER).Trim();

            // Are we a INCH header Code?
            if (tmpLine1.StartsWith("INCH") == true)
            {
                ExcellonLine_Misc mObj = new ExcellonLine_Misc(lineStr, tmpLine1, lineNumber);
                retInt = mObj.ParseLine(tmpLine1, StateMachine);
                if (retInt != 0)
                {
                    LogMessage("lineStr(INCH), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                    return(702);
                }
                // it is good, add it
                sourceLines.Add(mObj);
                // set the dimension mode now
                StateMachine.ExcellonFileUnits = ApplicationUnitsEnum.INCHES;
                return(0);
            }
            // Are we a METRIC header Code?
            else if (tmpLine1.StartsWith("METRIC") == true)
            {
                ExcellonLine_Misc mObj = new ExcellonLine_Misc(lineStr, tmpLine1, lineNumber);
                retInt = mObj.ParseLine(tmpLine1, StateMachine);
                if (retInt != 0)
                {
                    LogMessage("lineStr(METRIC), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                    return(703);
                }
                // it is good, add it
                sourceLines.Add(mObj);
                // set the dimension mode now
                StateMachine.ExcellonFileUnits = ApplicationUnitsEnum.MILLIMETERS;
                return(0);
            }
            else if (tmpLine1.StartsWith("M") == true)
            {
                ExcellonLine_MCode mObj = new ExcellonLine_MCode(lineStr, tmpLine1, lineNumber);
                retInt = mObj.ParseLine(tmpLine1, StateMachine);
                if (retInt != 0)
                {
                    LogMessage("lineStr(M), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                    return(700);
                }
                // it is good, add it
                sourceLines.Add(mObj);
                // are we M72?
                if (mObj.CurrentMCode == 72)
                {
                    // set the dimension mode now
                    StateMachine.ExcellonFileUnits = ApplicationUnitsEnum.INCHES;
                }
                // are we M71?
                if (mObj.CurrentMCode == 71)
                {
                    // set the dimension mode now
                    StateMachine.ExcellonFileUnits = ApplicationUnitsEnum.MILLIMETERS;
                }
                return(0);
            }
            else if (tmpLine1.StartsWith("G") == true)
            {
                ExcellonLine_GCode gObj = new ExcellonLine_GCode(lineStr, tmpLine1, lineNumber);
                retInt = gObj.ParseLine(tmpLine1, StateMachine);
                if (retInt != 0)
                {
                    LogMessage("lineStr(G), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                    return(7001);
                }
                // it is good, add it
                sourceLines.Add(gObj);
                return(0);
            }
            else if (tmpLine1.StartsWith("ICI") == true)
            {
                // this is Incremental Input of Part Program Coordinates
                if (tmpLine1.Contains("OFF") == false)
                {
                    LogMessage("lIncremental coordinate mode not supported. Error on line " + lineNumber.ToString());
                    return(3001);
                }
                else
                {
                    // we just ignore this
                    ExcellonLine_Misc mObj = new ExcellonLine_Misc(lineStr, tmpLine1, lineNumber);
                    retInt = mObj.ParseLine(tmpLine1, StateMachine);
                    if (retInt != 0)
                    {
                        LogMessage("lineStr(ICI), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                        return(3002);
                    }
                    // it is good, add it
                    sourceLines.Add(mObj);
                    return(0);
                }
            }
            // Are we a T Code?
            else if (tmpLine1.StartsWith("T") == true)
            {
                // Are we a "TCST" flag
                if (tmpLine1.Contains("TCST") == true)
                {
                    // we just ignore this
                    ExcellonLine_Misc mObj = new ExcellonLine_Misc(lineStr, tmpLine1, lineNumber);
                    retInt = mObj.ParseLine(tmpLine1, StateMachine);
                    if (retInt != 0)
                    {
                        LogMessage("lineStr(TCST), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                        return(807);
                    }
                    // it is good, add it
                    sourceLines.Add(mObj);
                    return(0);
                }
                else
                {
                    // this is a tool change, have we seen the end of the header?
                    if (lineNumber > StateMachine.HeaderEndLine)
                    {
                        // yes, we have. This must be a tool change
                        ExcellonLine_ToolChange tObj = new ExcellonLine_ToolChange(lineStr, tmpLine1, lineNumber);
                        retInt = tObj.ParseLine(tmpLine1, StateMachine);
                        if (retInt != 0)
                        {
                            LogMessage("lineStr(ToolChange), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                            return(7011);
                        }
                        // it is good, add it
                        sourceLines.Add(tObj);
                    }
                    else
                    {
                        // no, we have not. This must be a tool table definition
                        ExcellonLine_ToolTable tObj = new ExcellonLine_ToolTable(lineStr, tmpLine1, lineNumber);
                        retInt = tObj.ParseLine(tmpLine1, StateMachine);
                        if (retInt != 0)
                        {
                            LogMessage("lineStr(ToolTable), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                            return(7012);
                        }
                        // it is good, add it
                        sourceLines.Add(tObj);
                        // add this to the tool collection
                        StateMachine.ToolCollection.Add(tObj);
                    }
                    return(0);
                }
            }
            // Are we a "%" header Stop Code?
            else if (tmpLine1.StartsWith("%") == true)
            {
                ExcellonLine_Misc mObj = new ExcellonLine_Misc(lineStr, tmpLine1, lineNumber);
                retInt = mObj.ParseLine(tmpLine1, StateMachine);
                if (retInt != 0)
                {
                    LogMessage("lineStr(%), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                    return(704);
                }
                // it is good, add it
                sourceLines.Add(mObj);
                // note this now
                StateMachine.HeaderEndLine = lineNumber;
                return(0);
            }
            else if ((tmpLine1.StartsWith("X") || (tmpLine1.StartsWith("Y"))) == true)
            {
                ExcellonLine_XYCode xyObj = new ExcellonLine_XYCode(lineStr, tmpLine1, lineNumber);
                retInt = xyObj.ParseLine(tmpLine1, StateMachine);
                if (retInt != 0)
                {
                    LogMessage("lineStr(XY), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                    return(705);
                }
                // it is good, add it
                sourceLines.Add(xyObj);
                // record this
                RecordMinMaxXYCoords(xyObj.XCoord, xyObj.YCoord);
                return(0);
            }
            else if (tmpLine1.StartsWith("R") == true)
            {
                // several commands can start with R
                if ((tmpLine1.Contains("R,T") == true) ||
                    (tmpLine1.Contains("R,C") == true) ||
                    (tmpLine1.Contains("R,D") == true) ||
                    (tmpLine1.Contains("R,H") == true))
                {
                    // "R,T" just Reset Tool Data - ignore
                    // "R,C" just Reset clocks - ignore
                    // "R,CP" just Reset program clocks - ignore
                    // "R,CR" just Reset run clocks - ignore
                    // "R,D" just Reset All Cutter Distances - ignore
                    // "R,H" just RReset All Hit Counters - ignore
                    ExcellonLine_Misc mObj = new ExcellonLine_Misc(lineStr, tmpLine1, lineNumber);
                    retInt = mObj.ParseLine(tmpLine1, StateMachine);
                    if (retInt != 0)
                    {
                        LogMessage("lineStr(R,), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                        return(804);
                    }
                    // it is good, add it
                    sourceLines.Add(mObj);
                    return(0);
                }
                else
                {
                    // assume this
                    ExcellonLine_RCode rObj = new ExcellonLine_RCode(lineStr, tmpLine1, lineNumber);
                    retInt = rObj.ParseLine(tmpLine1, StateMachine);
                    if (retInt != 0)
                    {
                        LogMessage("lineStr(R), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                        return(706);
                    }
                    // it is good, add it
                    sourceLines.Add(rObj);
                }
                return(0);
            }
            // Are we a "VER" flag
            else if (tmpLine1.StartsWith("VER") == true)
            {
                // we just ignore this
                ExcellonLine_Misc mObj = new ExcellonLine_Misc(lineStr, tmpLine1, lineNumber);
                retInt = mObj.ParseLine(tmpLine1, StateMachine);
                if (retInt != 0)
                {
                    LogMessage("lineStr(ver), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                    return(805);
                }
                // it is good, add it
                sourceLines.Add(mObj);
                return(0);
            }
            // Are we a "FMAT" flag
            else if (tmpLine1.StartsWith("FMAT") == true)
            {
                // we just ignore this
                ExcellonLine_Misc mObj = new ExcellonLine_Misc(lineStr, tmpLine1, lineNumber);
                retInt = mObj.ParseLine(tmpLine1, StateMachine);
                if (retInt != 0)
                {
                    LogMessage("lineStr(FMAT), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                    return(806);
                }
                // it is good, add it
                sourceLines.Add(mObj);
                return(0);
            }
            // Are we a "ATC" flag
            else if (tmpLine1.StartsWith("ATC") == true)
            {
                // we just ignore this
                ExcellonLine_Misc mObj = new ExcellonLine_Misc(lineStr, tmpLine1, lineNumber);
                retInt = mObj.ParseLine(tmpLine1, StateMachine);
                if (retInt != 0)
                {
                    LogMessage("lineStr(ATC), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                    return(8071);
                }
                // it is good, add it
                sourceLines.Add(mObj);
                return(0);
            }
            else if (tmpLine1.Length == 0)
            {
                // probably all comments or blank
                ExcellonLine_Misc mObj = new ExcellonLine_Misc(lineStr, tmpLine1, lineNumber);
                retInt = mObj.ParseLine(tmpLine1, StateMachine);
                if (retInt != 0)
                {
                    LogMessage("lineStr(%), call to ParseLine returned " + retInt.ToString() + " Error on line " + lineNumber.ToString());
                    return(704);
                }
                // it is good, add it
                sourceLines.Add(mObj);
                return(0);
            }
            else
            {
                // if we get here we are a line of unknown type
                LogMessage("Unknown Excellon line type >" + lineStr + "< on line " + lineNumber.ToString());
                if (lineStr.Length > 20)
                {
                    throw new NotImplementedException("Cannot cope with unknown Excellon code on line " + lineNumber.ToString() + " code is >" + lineStr.Substring(0, 20) + "<");
                }
                else
                {
                    throw new NotImplementedException("Cannot cope with unknown Excellon code on line " + lineNumber.ToString() + " code is >" + lineStr + "<");
                }
            }
        }
Example #4
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Parses out the line and gets the required information from it
        /// </summary>
        /// <param name="processedLineStr">a line string without block terminator or format parameters</param>
        /// <param name="stateMachine">The state machine containing the implied modal values</param>
        /// <returns>z success, nz fail</returns>
        public override int ParseLine(string processedLineStr, GerberFileStateMachine stateMachine)
        {
            int  outInt       = -1;
            int  nextStartPos = 0;
            bool retBool;

            //LogMessage("ParseLine(G) started");

            if (processedLineStr == null)
            {
                return(100);
            }
            if (processedLineStr.StartsWith("G") == false)
            {
                return(200);
            }

            // now the GCode line will have an G tag

            // LOOK FOR THE G TAG
            nextStartPos = 0;
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(processedLineStr, 'G', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > processedLineStr.Length))
            {
                // this is an error - we have to find one
                LogMessage("ParseLine(G) failed on call to FindCharacterReturnNextPos");
                return(332);
            }
            // this will have a float number
            retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetInteger(processedLineStr, nextStartPos, ref outInt, ref nextStartPos);
            if (retBool != true)
            {
                LogMessage("ParseLine(G) failed on call to ParseNumberFromString_TillNonDigit_RetInteger");
                return(333);
            }

            switch (outInt)
            {
            case 1:
            {
                // This is just an linear interpolation
                currentGCode = outInt;
                break;
            }

            case 4:
            {
                // This is just an Ignore data block we can just ignore its contents
                // set the value now
                currentGCode = outInt;
                break;
            }

            case 70:
            {
                // This is INCHES mode
                currentGCode = outInt;
                stateMachine.GerberFileUnits = ApplicationUnitsEnum.INCHES;
                break;
            }

            case 71:
            {
                // This is Millimeters mode
                currentGCode = outInt;
                stateMachine.GerberFileUnits = ApplicationUnitsEnum.MILLIMETERS;
                break;
            }

            case 75:
            {
                // This is just circular interpolation enabled
                // we ignore it
                currentGCode = outInt;
                break;
            }

            case 90:
            {
                // This is absolute coordinates enabled
                currentGCode = outInt;
                stateMachine.GerberFileCoordinateMode = GerberCoordinateModeEnum.COORDINATE_ABSOLUTE;
                break;
            }

            case 91:
            {
                // This is incremental coordinates enabled
                currentGCode = outInt;
                stateMachine.GerberFileCoordinateMode = GerberCoordinateModeEnum.COORDINATE_INCREMENTAL;
                break;
            }

            default:
            {
                LogMessage("ParseLine(G) failed. Unknown GCode of" + outInt.ToString());
                return(334);
            }
            }
            return(0);
        }
Example #5
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Populate the object from an Aperture Definition pararameter
        /// </summary>
        /// <param name="adParamBlock">The AD string param block, no param, or block
        /// delimiters. Just the AD block</param>
        /// <param name="nextStartPos">the next start position after all of the ADX leading text</param>
        /// <returns>z success, nz fail</returns>
        public override int PopulateFromParameter(string adParamBlock, int nextStartPos)
        {
            float outFloat = 0;
            bool  retBool;

            if (adParamBlock == null)
            {
                return(100);
            }
            if (adParamBlock.StartsWith(GerberFile.RS274_AD_CMD) == false)
            {
                return(200);
            }

            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                LogMessage("PopulateFromParameter (C) malformed adParamBlock. No data after comma");
                return(722);
            }

            // set this now
            DefinitionBlock = adParamBlock;

            // od x <XAxisHoleDimension> x <YAxisHoleDimension>
            retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetFloat(adParamBlock, nextStartPos, ref outFloat, ref nextStartPos);
            if (retBool != true)
            {
                LogMessage("PopulateFromParameter (Ca) failed on call to ParseNumberFromString_TillNonDigit_RetFloat");
                return(133);
            }
            else
            {
                // set the value now
                outerDiameter = outFloat;
            }
            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                // we are done
                return(0);
            }
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(adParamBlock, 'X', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                // this is not an error - just means we are all done
                return(0);
            }
            // ###
            // These are optional
            // ###
            retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetFloat(adParamBlock, nextStartPos, ref outFloat, ref nextStartPos);
            if (retBool != true)
            {
                LogMessage("PopulateFromParameter (Ce) failed on call to ParseNumberFromString_TillNonDigit_RetFloat");
                return(135);
            }
            else
            {
                // set the value now
                HoleDiameter = outFloat;
            }

            return(0);
        }
Example #6
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Parses out the line and gets the required information from it
        /// </summary>
        /// <param name="processedLineStr">a line string without block terminator or format parameters</param>
        /// <param name="stateMachine">The state machine containing the implied modal values</param>
        /// <returns>z success, nz fail</returns>
        public override int ParseLine(string processedLineStr, ExcellonFileStateMachine stateMachine)
        {
            float outFloat     = 0;
            int   outInt       = 0;
            int   nextStartPos = 0;
            bool  retBool;

            //LogMessage("ParseLine(XY) started");

            if (processedLineStr == null)
            {
                return(100);
            }
            if (processedLineStr.StartsWith("R") == false)
            {
                return(200);
            }

            // now the line will have some combination of R, X and Y tags in some order
            // LOOK FOR THE X TAG
            nextStartPos = 0;
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(processedLineStr, 'R', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > processedLineStr.Length))
            {
                // we have to have this
                LogMessage("ParseLine(R) lineNumber=" + LineNumber.ToString() + " failed. No R repeat quantity found.");
                return(3331);
            }
            else
            {
                // this will have a integer number
                retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetInteger(processedLineStr, nextStartPos, ref outInt, ref nextStartPos);
                if (retBool != true)
                {
                    LogMessage("ParseLine(R) failed on call to ParseNumberFromString_TillNonDigit_RetInteger");
                    return(3332);
                }
                else
                {
                    // set the value now
                    repeatCount = outInt;
                }
            }


            // LOOK FOR THE X TAG
            nextStartPos = 0;
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(processedLineStr, 'X', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > processedLineStr.Length))
            {
                // we have to have this
                LogMessage("ParseLine(R) lineNumber=" + LineNumber.ToString() + " failed. No X coordinate found.");
                return(1331);
            }
            else
            {
                // this will have a float number
                retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetFloat(processedLineStr, nextStartPos, ref outFloat, ref nextStartPos);
                if (retBool != true)
                {
                    // just means not found
                }
                else
                {
                    // set the value now
                    xOffset = DecimalScaleNumber(outFloat, stateMachine.ExcellonFileManager.DrillingNumberOfDecimalPlaces, stateMachine.ExcellonFileManager.DrillingCoordinateZerosMode);
                }
            }

            // LOOK FOR THE Y TAG
            nextStartPos = 0;
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(processedLineStr, 'Y', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > processedLineStr.Length))
            {
                // just means not found
            }
            else
            {
                // this will have a float number
                retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetFloat(processedLineStr, nextStartPos, ref outFloat, ref nextStartPos);
                if (retBool != true)
                {
                    LogMessage("ParseLine(R) failed on call to ParseNumberFromString_TillNonDigit_RetFloat");
                    return(2332);
                }
                else
                {
                    // set the value now
                    yOffset = DecimalScaleNumber(outFloat, stateMachine.ExcellonFileManager.DrillingNumberOfDecimalPlaces, stateMachine.ExcellonFileManager.DrillingCoordinateZerosMode);
                }
            }
            return(0);
        }
Example #7
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Populate the object from an Aperture Definition pararameter
        /// </summary>
        /// <param name="adParamBlock">The AD string param block, no param, or block
        /// delimiters. Just the AD block</param>
        /// <param name="nextStartPos">the next start position after all of the ADX leading text</param>
        /// <returns>z success, nz fail</returns>
        public override int PopulateFromParameter(string adParamBlock, int nextStartPos)
        {
            float outFloat = 0;
            bool  retBool;

            if (adParamBlock == null)
            {
                return(100);
            }
            if (adParamBlock.StartsWith(GerberFile.RS274_AD_CMD) == false)
            {
                return(200);
            }

            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                LogMessage("PopulateFromParameter (P) malformed adParamBlock. No data after comma");
                return(722);
            }

            // set this now
            DefinitionBlock = adParamBlock;

            // OutsideDimension x NumSides X <degreesRotation> x <HoleDiameter> x <YAxisHoleDimension>
            retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetFloat(adParamBlock, nextStartPos, ref outFloat, ref nextStartPos);
            if (retBool != true)
            {
                LogMessage("PopulateFromParameter (Pa) failed on call to ParseNumberFromString_TillNonDigit_RetFloat");
                return(163);
            }
            else
            {
                // set the value now
                outsideDimension = outFloat;
            }
            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                LogMessage("PopulateFromParameter (Pb) failed on call to ParseNumberFromString_TillNonDigit_RetFloat");
                return(1631);
            }
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(adParamBlock, 'X', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                LogMessage("PopulateFromParameter (Pc) failed on call to ParseNumberFromString_TillNonDigit_RetFloat");
                return(1631);
            }
            retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetFloat(adParamBlock, nextStartPos, ref outFloat, ref nextStartPos);
            if (retBool != true)
            {
                LogMessage("PopulateFromParameter (Pd) failed on call to ParseNumberFromString_TillNonDigit_RetFloat");
                return(164);
            }
            else
            {
                int workingNumSides = (int)outFloat;
                if (workingNumSides < 3)
                {
                    LogMessage("PopulateFromParameter (Pe) failed numSides < 3 is " + workingNumSides.ToString());
                    return(165);
                }
                // set the value now
                numSides = workingNumSides;
            }
            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                // we are done
                return(0);
            }
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(adParamBlock, 'X', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                // this is not an error - just means we are all done
                return(0);
            }
            // ###
            // These are optional
            // ###
            retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetFloat(adParamBlock, nextStartPos, ref outFloat, ref nextStartPos);
            if (retBool != true)
            {
                LogMessage("PopulateFromParameter (Pe) failed on call to ParseNumberFromString_TillNonDigit_RetFloat");
                return(166);
            }
            else
            {
                // set the value now
                DegreesRotation = outFloat;
            }
            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                // this is not an error - just means we are all done
                return(0);
            }
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(adParamBlock, 'X', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                // this is not an error - just means we are all done
                return(0);
            }
            retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetFloat(adParamBlock, nextStartPos, ref outFloat, ref nextStartPos);
            if (retBool != true)
            {
                // this is not an error - just means we are all done
                return(0);
            }
            else
            {
                // set the value now
                HoleDiameter = outFloat;
            }

            return(0);
        }
Example #8
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Parses out the line and gets the required information from it
        /// </summary>
        /// <param name="processedLineStr">a line string without block terminator or format parameters</param>
        /// <param name="stateMachine">The state machine containing the implied modal values</param>
        /// <returns>z success, nz fail</returns>
        public override int ParseLine(string processedLineStr, GerberFileStateMachine stateMachine)
        {
            float outFloat     = 0;
            int   nextStartPos = 0;
            bool  retBool;

            LogMessage("ParseLine(OF) started");

            if (processedLineStr == null)
            {
                return(100);
            }
            if (processedLineStr.StartsWith(GerberFile.RS274_OF_CMD) == false)
            {
                return(200);
            }

            // now the line will have some combination of A and B tags in some order
            // LOOK FOR THE A TAG
            nextStartPos = 0;
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(processedLineStr, 'A', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > processedLineStr.Length))
            {
                // just means not found
            }
            else
            {
                retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetFloat(processedLineStr, nextStartPos, ref outFloat, ref nextStartPos);
                if (retBool != true)
                {
                    // this is not an error - just means we are all done
                    return(0);
                }
                else
                {
                    // set the value now
                    xOffset = outFloat;
                }
            }

            // LOOK FOR THE B TAG
            nextStartPos = 0;
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(processedLineStr, 'B', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > processedLineStr.Length))
            {
                // just means not found
            }
            else
            {
                retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetFloat(processedLineStr, nextStartPos, ref outFloat, ref nextStartPos);
                if (retBool != true)
                {
                    // this is not an error - just means we are all done
                    return(0);
                }
                else
                {
                    // set the value now
                    yOffset = outFloat;
                }
            }
            return(0);
        }
Example #9
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Populate the object from an Aperture Definition prarameter
        /// </summary>
        /// <param name="adParamBlock">The AD string param block, no param, or block
        /// delimiters. Just the AD block</param>
        /// <returns>z success, nz fail</returns>
        public int PopulateFromParameter(string adParamBlock)
        {
            //DebugMessage("PopulateFromParameter() started");
            int  outInt       = -1;
            int  nextStartPos = -1;
            bool retBool;

            if (adParamBlock == null)
            {
                return(100);
            }
            if (adParamBlock.StartsWith(GerberFile.RS274_AD_CMD) == false)
            {
                return(200);
            }

            // convert to a character array
            char[] adChars = adParamBlock.ToCharArray();
            if (adChars == null)
            {
                return(300);
            }
            if (adChars.Length < 5)
            {
                return(400);
            }
            // we have to have a 'D' here to define the D number
            if (adChars[2] != 'D')
            {
                return(200);
            }

            // get the D number
            retBool = GerberParseUtils.ParseNumberFromString_TillNonDigit_RetInteger(adParamBlock, 3, ref outInt, ref nextStartPos);
            if (retBool != true)
            {
                LogMessage("PopulateFromParameter failed on call to ParseNumberFromString_TillNonDigit_RetInteger");
                return(322);
            }
            else
            {
                // set the dNumber now
                dNumber = outInt;
            }

            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                LogMessage("PopulateFromParameter malformed adParamBlock. No data after Dnumber");
                return(422);
            }

            // at this point we have to take care. if the aperature definitition contains one of a
            // specific set of chars then we are dealing with a normal aperture. If it does not it must
            // be a named aperture referring to a macro

            // set the aperture object
            adCodeAperture = GetApertureObjFromString(adParamBlock.Substring(nextStartPos));
            nextStartPos++;
            if (adCodeAperture == null)
            {
                LogMessage("PopulateFromParameter failed on call to GetApertureObjFromCharacter");
                return(522);
            }
            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                LogMessage("PopulateFromParameter malformed adParamBlock. No data after ADType");
                return(622);
            }

            // re-sync and position just after the ',' char in the aperture parameter definition
            nextStartPos = GerberParseUtils.FindCharacterReturnNextPos(adParamBlock, ',', nextStartPos);
            if ((nextStartPos < 0) || (nextStartPos > adParamBlock.Length))
            {
                if ((adCodeAperture is GerberAperture_Macro) == false)
                {
                    // have to have this for normal apertures
                    LogMessage("PopulateFromParameter malformed adParamBlock. No data after comma");
                    return(722);
                }
                else
                {
                    // we are a macro aperture with no params
                    nextStartPos = adParamBlock.Length;
                }
            }

            // now let the aperture object populate itself
            int retInt = adCodeAperture.PopulateFromParameter(adParamBlock, nextStartPos);

            if (retInt != 0)
            {
                LogMessage("PopulateFromParameter call to adCodeAperture.PopulateFromParameter returned " + retInt.ToString());
                return(723);
            }

            return(0);
        }