Exemple #1
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Revisits the excellon lines and figures out the pad center points
        /// </summary>
        public void SetPadCenterPointList()
        {
            // create a dummy statemachine We can only get a lot of the information from the DCodes
            // by simulating a run. They use the results of the previous DCode a lot
            ExcellonFileStateMachine workingStateMachine = new ExcellonFileStateMachine();

            workingStateMachine.ToolCollection = stateMachine.ToolCollection;

            // run through all of the DCode lines
            foreach (ExcellonLine gLineObj in SourceLines)
            {
                if ((gLineObj is ExcellonLine_ToolChange) == true)
                {
                    ExcellonLine_ToolTable toolTabObj = null;
                    // see if we can find the tool table object for this change
                    toolTabObj = workingStateMachine.GetToolTableObjectByToolNumber((gLineObj as ExcellonLine_ToolChange).ToolNumber);
                    if (toolTabObj != null)
                    {
                        workingStateMachine.LastDrillWidth = toolTabObj.DrillDiameter;
                    }
                    continue;
                }
                else if ((gLineObj is ExcellonLine_XYCode) == true)
                {
                    // set this now for convenience
                    ExcellonLine_XYCode elObj = (ExcellonLine_XYCode)gLineObj;
                    // record these centerpoints to our list, note that we save to the current statemachine but use the aperture from the working one
                    stateMachine.PadCenterPointList.Add(new GerberPad(elObj.XCoord, elObj.YCoord, workingStateMachine.LastDrillWidth));
                }
            }
        }
Exemple #2
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Performs the action the plot requires based on the current context
        /// </summary>
        /// <param name="graphicsObj">a graphics object on which to plot</param>
        /// <param name="stateMachine">the excellon plot state machine</param>
        /// <param name="errorString">the error string we return on fail</param>
        /// <param name="errorValue">the error value we return on fail, z success, nz fail </param>
        /// <returns>an enum value indicating what next action to take</returns>
        public override PlotActionEnum PerformPlotExcellonAction(Graphics graphicsObj, ExcellonFileStateMachine stateMachine, ref int errorValue, ref string errorString)
        {
            ExcellonLine_ToolTable toolTabObj = null;

            // see if we can find the tool table object for this change
            toolTabObj = stateMachine.GetToolTableObjectByToolNumber(toolNumber);
            if (toolTabObj != null)
            {
                stateMachine.LastDrillWidth = toolTabObj.DrillDiameter;
            }
            errorValue  = 0;
            errorString = "Successful End";
            return(PlotActionEnum.PlotAction_Continue);
        }
Exemple #3
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Converts the excellon line into a GCode line and returns it
        /// </summary>
        /// <param name="stateMachine">the state machine with the configuration</param>
        /// <param name="gcLineList">a list of the equivalent gcode line object. This can be
        /// empty if there is no direct conversion</param>
        /// <returns>z success, nz fail</returns>
        public override int GetGCodeCmd(ExcellonFileStateMachine stateMachine, out List <GCodeCmd> gcLineList)
        {
            GCodeCmd_ToolChange    tcLine;
            ExcellonLine_ToolTable toolTabObj = null;
            string commentStr = null;

            // see if we can find the tool table object for this change
            toolTabObj = stateMachine.GetToolTableObjectByToolNumber(toolNumber);
            if (toolTabObj != null)
            {
                commentStr = "ToolChange, ToolNum: " + toolNumber.ToString() + ", Drill Dia:" + toolTabObj.DrillDiameter.ToString();
                // also remember this
                stateMachine.LastDrillWidth = toolTabObj.DrillDiameter;
            }
            gcLineList = new List <GCodeCmd>();
            tcLine     = new GCodeCmd_ToolChange(toolNumber);
            if (commentStr != null)
            {
                tcLine.CommentText = commentStr;
            }
            gcLineList.Add(tcLine);
            return(0);
        }
Exemple #4
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 + "<");
                }
            }
        }