/// <summary> /// Code Check Entrance /// </summary> protected bool Code_Check(List<string> code_segment, int row_index, ref bool macro_flag, ref DataStore step_compile_data, ref Vector3 display_position, ref MotionInfo step_motion_data, ref Vector3 virtual_position) { bool temp_flag = true; bool return_flag = true; string Address = ""; Vector3 program_position = new Vector3(0, 0, 0); macro_flag = false; Regex macro_Reg = new Regex(@"((#+)|(\[+)|(\]+)|(=+))", RegexOptions.IgnoreCase); MatchCollection macro_Col; for(int i = 0; i < code_segment.Count; i++) { // 检查是否有宏代码,如果有宏代码 macro_Col = macro_Reg.Matches(code_segment[i]); //如果程序中含有宏代码,中断编译过程,返回宏代码错误,宏代码的编译暂不处理 if(macro_Col.Count > 0) { temp_flag = false; macro_flag = true; break; } if(code_segment[i] != ";") { _errorMessage = ""; Address = code_segment[i][0].ToString().ToUpper(); switch(Address) { case "G": return_flag = G_Check(code_segment[i], row_index, ref step_compile_data, ref ModalState); break; case "M": return_flag = M_Check(code_segment[i], row_index, ref step_compile_data); break; /// A, B, C, I, J, K, U, V, W, X, Y, Z, R; F case "A": case "B": case "C": case "I": case "J": case "K": case "U": case "V": case "W": case "X": case "Y": case "Z": case "R": case "F": return_flag = F_Check(code_segment[i], row_index, ref step_compile_data); break; case "/": return_flag = Slash_Check(code_segment[i], row_index, ref step_compile_data); break; /// D, H; L, P; N, Q; O; S; T; case "D": case "H": case "L": case "P": case "N": case "Q": case "O": case "S": case "T": return_flag = I_Check(code_segment[i], row_index, ref step_compile_data); break; default: _errorMessage = "(Line:" + row_index + "): " + Address + "地址不存在"; return_flag = false; break; } if(return_flag == false) { if(temp_flag) { temp_flag = false; } _compileInfo.Add(ErrorMessage); } } } if(temp_flag) {//compile level //Todo: 分析此段代码,生成相关运动信息; //是否为空 if(step_compile_data.IsEmpty()) return true; else {//1 level //立即执行代码处理 if(step_compile_data.immediate_execution != "") {//2 level step_motion_data.Immediate_Motion = step_compile_data.immediate_execution; for(int i = 0; i < step_compile_data.immediate_execution.Length; i++) { switch((char)step_compile_data.immediate_execution[i]) { //Todo: 考虑下当前行只有T代码或者只有M06的情况 case (char)ImmediateMotionType.ToolChanging: step_motion_data.Tool_Number = step_compile_data.tool_number; break; case (char)ImmediateMotionType.M03: case (char)ImmediateMotionType.M04: if(step_compile_data.s_value == 0) { _errorMessage = "(Line:" + row_index + "): " + "当前程序段中未指定主轴转速"; _compileInfo.Add(ErrorMessage); return false; } step_motion_data.Rotate_Speed = step_compile_data.s_value; break; case (char)ImmediateMotionType.G54: case (char)ImmediateMotionType.G55: case (char)ImmediateMotionType.G56: case (char)ImmediateMotionType.G57: case (char)ImmediateMotionType.G58: case (char)ImmediateMotionType.G59: display_position = virtual_position - ModalState.LocalCoordinate(); break; default: break; } } }//2 level //计算运动信息 if(step_compile_data.HasMotion()) {//3 level step_motion_data.Motion_Type = step_compile_data.MotionTypeIndex(ModalState.Modal_Code[0]); if(step_motion_data.Motion_Type == -1) { _errorMessage = "(Line:" + row_index + "): " + "未知运动方式错误!"; _compileInfo.Add(ErrorMessage); return false; } switch(step_motion_data.Motion_Type) { case (int)MotionType.DryRunning: step_motion_data.SetStartPosition(display_position, virtual_position); //公制单位 if(ModalState.UnitCheck() == (int)CheckInformation.MetricSystem) { //绝对坐标 if(ModalState.AbsoluteCooCheck() == (int)CheckInformation.AbsouteCoo) { program_position = step_compile_data.AbsolutePosition(display_position); step_motion_data.Direction = program_position - display_position; step_motion_data.SetRemainingMovement(); step_motion_data.Velocity = SystemArguments.RapidMoveSpeed; step_motion_data.Time_Value = step_motion_data.Direction.magnitude / SystemArguments.RapidMoveSpeed * 60; virtual_position += step_motion_data.Direction; step_motion_data.SetTargetPosition(program_position, virtual_position); } //增量坐标 else { } } //英制单位 else { } break; case (int)MotionType.Line: if(ModalState.Feedrate == 0) { _errorMessage = "(Line:" + row_index + "): " + "未指定进给速率!"; _compileInfo.Add(ErrorMessage); return false; } step_motion_data.SetStartPosition(display_position, virtual_position); //公制单位 if(ModalState.UnitCheck() == (int)CheckInformation.MetricSystem) { //绝对坐标 if(ModalState.AbsoluteCooCheck() == (int)CheckInformation.AbsouteCoo) { program_position = step_compile_data.AbsolutePosition(display_position); step_motion_data.Direction = program_position - display_position; step_motion_data.SetRemainingMovement(); step_motion_data.Velocity = ModalState.Feedrate; step_motion_data.Time_Value = step_motion_data.Direction.magnitude / step_motion_data.Velocity * 60; virtual_position += step_motion_data.Direction; step_motion_data.SetTargetPosition(program_position, virtual_position); } //增量坐标 else { } } //英制单位 else { } break; case (int)MotionType.Circular02: if(ModalState.Feedrate == 0) { _errorMessage = "(Line:" + row_index + "): " + "未指定进给速率!"; _compileInfo.Add(ErrorMessage); return false; } step_motion_data.SetStartPosition(display_position, virtual_position); //公制单位 if(ModalState.UnitCheck() == (int)CheckInformation.MetricSystem) { //绝对坐标 Vector3 xyz_coo = new Vector3(0, 0, 0); Vector3 ijk_coo = new Vector3(0, 0, 0); float rValue = 0; if(ModalState.AbsoluteCooCheck() == (int)CheckInformation.AbsouteCoo) { switch(step_compile_data.CircleArguJudge(ref _errorMessage, ModalState, ref ijk_coo, ref xyz_coo, ref rValue)) { case -1: _errorMessage = "(Line:" + row_index + "): " + _errorMessage; _compileInfo.Add(ErrorMessage); return false; case 0: step_motion_data.Motion_Type = -1; return true; case 1: step_motion_data.Center_Point = display_position + ijk_coo; step_motion_data.Rotate_Degree = 360f; break; } program_position = step_compile_data.AbsolutePosition(display_position); step_motion_data.Direction = program_position - display_position; step_motion_data.SetRemainingMovement(); step_motion_data.Velocity = ModalState.Feedrate; step_motion_data.Time_Value = step_motion_data.Direction.magnitude / step_motion_data.Velocity * 60; virtual_position += step_motion_data.Direction; step_motion_data.SetTargetPosition(program_position, virtual_position); } //增量坐标 else { } } //英制单位 else { } break; case (int)MotionType.Circular03: break; default: _errorMessage = "(Line:" + row_index + "): " + "当前系统暂不支持Motion Type: " + step_compile_data.motion_type; _compileInfo.Add(ErrorMessage); return false; } }//3 level }//1 level if(step_compile_data.slash_value > 0) { if(ModalState.Slash) return true; } return true; }//compile level else return false; }