Ejemplo n.º 1
0
    public void ModeSelectButton()
    {
        GUI.DrawTexture(new Rect((mode_x + 1) / 1000f * Main.width, (mode_y + 1) / 1000f * Main.height, mode_width / 1000f * Main.width, mode_height / 1000f * Main.height), Main.t2d_ModeSelect, ScaleMode.ScaleAndCrop, true, 893 / 511f);
        if (GUI.Button(new Rect((mode1_x + 10f) / 1000f * Main.width, mode1_y / 1000f * Main.height, mode1_width / 1000f * Main.width, mode1_height / 1000f * Main.height), "", Main.sty_ButtonEmpty))
        {
            Main.ProgramNum  = Main.Progname_Backup;
            Main.MenuDisplay = "编辑";
            if (!Main.editDisplay)
            {
                Main.ExchangeVar();
            }
            Main.t2d_ModeSelect = Main.t2d_ModeSelectEDIT;
            PlayerPrefs.SetInt("ModeSelect", 1);
            Main.ProgEDIT    = true;
            Main.ProgDNC     = false;
            Main.ProgAUTO    = false;
            Main.ProgMDI     = false;
            Main.ProgHAN     = false;
            Main.ProgJOG     = false;
            Main.ProgREF     = false;
            Main.editDisplay = true;
            HandWheel_script.closeWheel();
        }

        if (GUI.Button(new Rect((mode2_x + 10f) / 1000f * Main.width, mode2_y / 1000f * Main.height, mode2_width / 1000f * Main.width, mode2_height / 1000f * Main.height), "", Main.sty_ButtonEmpty))
        {
            Main.ProgramNum     = Main.Progname_Backup;
            Main.MenuDisplay    = "DNC";
            Main.t2d_ModeSelect = Main.t2d_ModeSelectDNC;
            PlayerPrefs.SetInt("ModeSelect", 2);
            Main.ProgEDIT = false;
            Main.ProgDNC  = true;
            Main.ProgAUTO = false;
            Main.ProgMDI  = false;
            Main.ProgHAN  = false;
            Main.ProgJOG  = false;
            Main.ProgREF  = false;
            HandWheel_script.closeWheel();
            Main.AutoDisplayFindRows(Main.autoSelecedProgRow, true);
        }

        if (GUI.Button(new Rect((mode3_x + 10f) / 1000f * Main.width, mode3_y / 1000f * Main.height, mode3_width / 1000f * Main.width, mode3_height / 1000f * Main.height), "", Main.sty_ButtonEmpty))
        {
            Main.ProgramNum     = Main.Progname_Backup;
            Main.MenuDisplay    = "MEM";
            Main.t2d_ModeSelect = Main.t2d_ModeSelectAUTO;
            PlayerPrefs.SetInt("ModeSelect", 3);
            //NC代码编译
            if (!Main.ProgAUTO && Main.beModifed)
            {
                if (!Main.ProgMDI)
                {
                    Main.AutoProgName       = Main.ProgramNum;
                    Main.beModifed          = false;
                    Main.CodeForAUTO        = Main.CodeForAll;
                    Main.autoSelecedProgRow = 0;
                    if (Main.ProgAUTOFlip == 2 || Main.ProgAUTOFlip == 4)
                    {
                        Main.AutoDisplayFindRows(Main.autoSelecedProgRow, false);
                    }
                    else
                    {
                        Main.AutoDisplayFindRows(Main.autoSelecedProgRow, true);
                    }
                    Main.Compile_flag = AutoRunning_Script.AutoCodeCompile(Main.CodeForAUTO, ref error_string);
                    if (!Main.Compile_flag)
                    {
                        Debug.LogError(error_string);
                    }
                }
            }
            Main.ProgEDIT = false;
            Main.ProgDNC  = false;
            Main.ProgAUTO = true;
            Main.ProgMDI  = false;
            Main.ProgHAN  = false;
            Main.ProgJOG  = false;
            Main.ProgREF  = false;
            HandWheel_script.closeWheel();
            if (Main.ProgAUTOFlip == 2 || Main.ProgAUTOFlip == 4)
            {
                Main.AutoDisplayFindRows(Main.autoSelecedProgRow, false);
            }
            else
            {
                Main.AutoDisplayFindRows(Main.autoSelecedProgRow, true);
            }
        }

        if (GUI.Button(new Rect((mode4_x + 10f) / 1000f * Main.width, mode4_y / 1000f * Main.height, mode4_width / 1000f * Main.width, mode4_height / 1000f * Main.height), "", Main.sty_ButtonEmpty))
        {
            Main.Progname_Backup = Main.ProgramNum;
            Main.ProgramNum      = 0;
            Main.MenuDisplay     = "MDI";
            if (Main.editDisplay)
            {
                Main.ExchangeVar();
            }
            if (Main.CodeForAll.Count == 0)
            {
                Main.CodeForAll.Add("O0000");
                Main.CodeForAll.Add(";");
                Main.MDIpos_flag = true;
            }
            Softkey_Script.calcSepo(Main.CodeForAll, SystemArguments.EditLength1);
            Main.t2d_ModeSelect = Main.t2d_ModeSelectMDI;
            PlayerPrefs.SetInt("ModeSelect", 4);
            Main.ProgEDIT    = false;
            Main.ProgDNC     = false;
            Main.ProgAUTO    = false;
            Main.ProgMDI     = true;
            Main.ProgHAN     = false;
            Main.ProgJOG     = false;
            Main.ProgREF     = false;
            Main.editDisplay = false;
            HandWheel_script.closeWheel();
            Main.AutoDisplayFindRows(Main.autoSelecedProgRow, true);
        }

        if (GUI.Button(new Rect((mode5_x + 10f) / 1000f * Main.width, mode5_y / 1000f * Main.height, mode5_width / 1000f * Main.width, mode5_height / 1000f * Main.height), "", Main.sty_ButtonEmpty))
        {
            Main.ProgramNum     = Main.Progname_Backup;
            Main.MenuDisplay    = "HAN";
            Main.t2d_ModeSelect = Main.t2d_ModeSelectHANDLE;
            PlayerPrefs.SetInt("ModeSelect", 5);
            Main.ProgEDIT = false;
            Main.ProgDNC  = false;
            Main.ProgAUTO = false;
            Main.ProgMDI  = false;
            Main.ProgHAN  = true;
            Main.ProgJOG  = false;
            Main.ProgREF  = false;
            HandWheel_script.showWheel();
            Main.AutoDisplayFindRows(Main.autoSelecedProgRow, true);
        }
//		if (GUI.Button(new Rect(317f/1000f*Main.width, 650f/1000f*Main.height, 50f/1000f*Main.width, 25f/1000f*Main.height), "", Main.sty_ButtonEmpty))
//		{
//			Main.ProgramNum = Main.Progname_Backup;
//			Main.MenuDisplay = "HAN";
//			Main.t2d_ModeSelect = Main.t2d_ModeSelectHANDLE;
//			PlayerPrefs.SetInt("ModeSelect", 5);
//			Main.ProgEDIT = false;
//			Main.ProgDNC = false;
//			Main.ProgAUTO = false;
//			Main.ProgMDI = false;
//			Main.ProgHAN =true;
//			Main.ProgJOG = false;
//			Main.ProgREF = false;
//			HandWheel_script.showWheel();
//
//		}

        if (GUI.Button(new Rect((mode6_x + 10f) / 1000f * Main.width, (mode6_y + 7) / 1000f * Main.height, mode6_width / 1000f * Main.width, (mode6_height - 7) / 1000f * Main.height), "", Main.sty_ButtonEmpty))
        {
            Main.ProgramNum     = Main.Progname_Backup;
            Main.MenuDisplay    = "JOG";
            Main.t2d_ModeSelect = Main.t2d_ModeSelectJOG;
            PlayerPrefs.SetInt("ModeSelect", 6);
            MoveControl_script.speed_to_move = 0.08333F;
            MoveControl_script.move_rate     = Main.move_rate;
            Main.ProgEDIT = false;
            Main.ProgDNC  = false;
            Main.ProgAUTO = false;
            Main.ProgMDI  = false;
            Main.ProgHAN  = false;
            Main.ProgJOG  = true;
            Main.ProgREF  = false;
            HandWheel_script.closeWheel();
            Main.AutoDisplayFindRows(Main.autoSelecedProgRow, true);
        }
        if (GUI.Button(new Rect(mode7_x / 1000f * Main.width, mode7_y / 1000f * Main.height, mode7_width / 1000f * Main.width, mode7_height / 1000f * Main.height), "", Main.sty_ButtonEmpty))
        {
            Main.ProgramNum     = Main.Progname_Backup;
            Main.MenuDisplay    = "REF";
            Main.t2d_ModeSelect = Main.t2d_ModeSelectREF;
            PlayerPrefs.SetInt("ModeSelect", 7);
            MoveControl_script.speed_to_move = 0.16667F;
            MoveControl_script.move_rate     = 1.0f;
            Main.ProgEDIT = false;
            Main.ProgDNC  = false;
            Main.ProgAUTO = false;
            Main.ProgMDI  = false;
            Main.ProgHAN  = false;
            Main.ProgJOG  = false;
            Main.ProgREF  = true;
            HandWheel_script.closeWheel();
            Main.AutoDisplayFindRows(Main.autoSelecedProgRow, true);
        }
    }
Ejemplo n.º 2
0
//	public void EmergencyCall()
//	{
//		motion_info_list.Clear();
//	}

    public IEnumerator MotionStart()
    {
        CooZeroPoint = CooSystem_Script.AbsoluteZero;         //获取当前绝对坐标系零点
//		Main.AutoRunning_flag = true;
        if (Main.AutoRunning_flag)
        {
            DisplayStart();
        }
        Main.CycleTimeH          = 0;
        Main.CycleTimeM          = 0;
        Main.CycleTimeS          = 0;
        Auto_Script.cycling_time = 0;
        Auto_Script.runningH     = Main.RunningTimeH;
        Auto_Script.runningM     = Main.RunningTimeM;
        for (int index = 0; index < motion_info_list.Count; index++)
        {        //1level
            Debug.Log(index + " >>> " + motion_info_list[index].index);
            //黄色光标跳转
//			Main.autoSelecedProgRow = motion_info_list[index].index;
            if (Main.AutoRunning_flag)
            {
                Main.AutoDisplayFindRows(motion_info_list[index].index, Main.autoDisplayNormal);
            }
            if (Main.MDI_RunningFlag)
            {
                Main.MDIDisplayFindRows(motion_info_list[index].index);
            }
            Main.RunningSpeed = 0;
            Main.T_Value      = Main.ToolNo;
            Main.D_value      = motion_info_list[index].D_Value;
            Main.H_value      = motion_info_list[index].H_Value;
            //判断是否内容为空
            if (motion_info_list[index].NotEmpty())
            {            //2level
                //画面变化
                if (Main.AutoRunning_flag)
                {
                    //G_Display
                    ProgramModule_Script.CurrentCodeDisplay(motion_info_list[index].G_Display, motion_info_list[index].G_Address, motion_info_list[index].Address_Value, motion_info_list[index].G_Display2, motion_info_list[index].G_Address2, motion_info_list[index].Address_Value2);
                    //ModalIndex, ModalString
                    ProgramModule_Script.SetModalState(motion_info_list[index].ModalIndex, motion_info_list[index].ModalString);
                    //运动坐标信息
                }
                //如果跳过功能启用,判断是否要跳过当前行
                if (Slash_on)
                {
                    if (motion_info_list[index].Slash > 0)
                    {
                        continue;
                    }
                }
                //立即执行的功能
                if (motion_info_list[index].Immediate_Motion != "")
                {
                    for (int i = 0; i < motion_info_list[index].Immediate_Motion.Length; i++)
                    {
                        switch ((char)motion_info_list[index].Immediate_Motion[i])
                        {
//						case (char)ImmediateMotionType.ToolChanging:
//							Main.ToolNo = motion_info_list[index].Tool_Number;
//							break;
                        case (char)ImmediateMotionType.M00:
                            Auto_Script.SetPause();
                            Main.AutoPause_flag = true;
                            break;

                        case (char)ImmediateMotionType.M01:
                            if (Main.OSP_On)
                            {
                                Auto_Script.SetPause();
                                Main.AutoPause_flag = true;
                            }
                            break;

                        case (char)ImmediateMotionType.M02:
                            Auto_Script.EmergencyCall();
                            Auto_Script.StopAllCoroutines();
                            Main.SpindleStop();
                            Main.AutoRunning_flag = false;
                            Main.RunningSpeed     = 0;
                            break;

                        case (char)ImmediateMotionType.M03:
                            CurrentModal.RotateSpeed = motion_info_list[index].SpindleSpeed;
                            Main.SpindleCW(CurrentModal.RotateSpeed);
                            Main.SpindleSpeed = (int)CurrentModal.RotateSpeed;
                            break;

                        case (char)ImmediateMotionType.M04:
                            CurrentModal.RotateSpeed = motion_info_list[index].SpindleSpeed;
                            Main.SpindleCCW(CurrentModal.RotateSpeed);
                            Main.SpindleSpeed = (int)CurrentModal.RotateSpeed;
                            break;

                        case (char)ImmediateMotionType.M05:
                            Main.SpindleStop();
                            Main.SpindleSpeed = 0;
                            break;

//						case (char)ImmediateMotionType.M06:
//							//更换刀具的过程
//							break;
                        case (char)ImmediateMotionType.M07:
                        case (char)ImmediateMotionType.M08:
                        case (char)ImmediateMotionType.M09:
                            break;

                        case (char)ImmediateMotionType.M30:
                            Auto_Script.EmergencyCall();
                            Auto_Script.StopAllCoroutines();
                            Main.SpindleStop();
                            Main.AutoRunning_flag = false;
                            Main.RunningSpeed     = 0;
                            if (Main.AutoRunning_flag)
                            {
                                Main.AutoDisplayFindRows(0, Main.autoDisplayNormal);
                            }
                            if (Main.MDI_RunningFlag)
                            {
                                Main.MDIDisplayFindRows(0);
                            }
//							Main.autoSelecedProgRow = 0;
                            break;

                        case (char)ImmediateMotionType.M98:
                        case (char)ImmediateMotionType.M99:

                            break;

                        case (char)ImmediateMotionType.G52:                          //局部坐标系变换
                            if (motion_info_list[index].CooTransformation.x == 0)
                            {
                                CooSystem_Script.AbsoluteZero.x = CooZeroPoint.x;
                            }
                            else
                            {
                                CooSystem_Script.AbsoluteZero.x = CooZeroPoint.x - motion_info_list[index].CooTransformation.x;
                            }
                            if (motion_info_list[index].CooTransformation.y == 0)
                            {
                                CooSystem_Script.AbsoluteZero.y = CooZeroPoint.y;
                            }
                            else
                            {
                                CooSystem_Script.AbsoluteZero.y = CooZeroPoint.y - motion_info_list[index].CooTransformation.y;
                            }
                            if (motion_info_list[index].CooTransformation.z == 0)
                            {
                                CooSystem_Script.AbsoluteZero.z = CooZeroPoint.z;
                            }
                            else
                            {
                                CooSystem_Script.AbsoluteZero.z = CooZeroPoint.z - motion_info_list[index].CooTransformation.z;
                            }
                            break;

                        case (char)ImmediateMotionType.G53:
                            //已经作为一种运动方式处理,这里直接跳过,去下面的流程中.
                            break;

                        case (char)ImmediateMotionType.G54:                         //工件坐标系设定
                            CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G54;
                            CooSystem_Script.Workpiece_Change();
                            CooZeroPoint = CooSystem_Script.AbsoluteZero;
                            CurrentModal.SetModalCode("G54", 13);
                            break;

                        case (char)ImmediateMotionType.G55:
                            CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G55;
                            CooSystem_Script.Workpiece_Change();
                            CooZeroPoint = CooSystem_Script.AbsoluteZero;
                            CurrentModal.SetModalCode("G55", 13);
                            break;

                        case (char)ImmediateMotionType.G56:
                            CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G56;
                            CooSystem_Script.Workpiece_Change();
                            CooZeroPoint = CooSystem_Script.AbsoluteZero;
                            CurrentModal.SetModalCode("G56", 13);
                            break;

                        case (char)ImmediateMotionType.G57:
                            CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G57;
                            CooSystem_Script.Workpiece_Change();
                            CooZeroPoint = CooSystem_Script.AbsoluteZero;
                            CurrentModal.SetModalCode("G57", 13);
                            break;

                        case (char)ImmediateMotionType.G58:
                            CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G58;
                            CooSystem_Script.Workpiece_Change();
                            CooZeroPoint = CooSystem_Script.AbsoluteZero;
                            CurrentModal.SetModalCode("G58", 13);
                            break;

                        case (char)ImmediateMotionType.G59:
                            CooSystem_Script.workpiece_flag = (int)WorkpieceCooSys.G59;
                            CooSystem_Script.Workpiece_Change();
                            CooZeroPoint = CooSystem_Script.AbsoluteZero;
                            CurrentModal.SetModalCode("G59", 13);
                            break;

                        case (char)ImmediateMotionType.G92:
                            if (motion_info_list[index].CooState[0])
                            {
                                CooSystem_Script.AbsoluteZero.x = motion_info_list[index].CooTransformation.x - Move_Script.MachineCoo.x;
                                CooZeroPoint.x = CooSystem_Script.AbsoluteZero.x;
                                CooSystem_Script.RelativeZero.x = CooSystem_Script.AbsoluteZero.x;
                            }
                            if (motion_info_list[index].CooState[1])
                            {
                                CooSystem_Script.AbsoluteZero.y = motion_info_list[index].CooTransformation.y - Move_Script.MachineCoo.y;
                                CooZeroPoint.y = CooSystem_Script.AbsoluteZero.y;
                                CooSystem_Script.RelativeZero.y = CooSystem_Script.AbsoluteZero.y;
                            }
                            if (motion_info_list[index].CooState[2])
                            {
                                CooSystem_Script.AbsoluteZero.z = motion_info_list[index].CooTransformation.z - Move_Script.MachineCoo.z;
                                CooZeroPoint.z = CooSystem_Script.AbsoluteZero.z;
                                CooSystem_Script.RelativeZero.z = CooSystem_Script.AbsoluteZero.z;
                            }
                            break;

                        case (char)ImmediateMotionType.Pause:
                            //已经作为一种运动方式处理,这里直接跳过,去下面的流程中.
                            break;

                        case (char)ImmediateMotionType.AutoReturnRP:
                            //已经作为一种运动方式处理,这里直接跳过,去下面的流程中.
                            break;

                        case (char)ImmediateMotionType.BackFromRP:
                            //已经作为一种运动方式处理,这里直接跳过,去下面的流程中.
                            break;

                        case (char)ImmediateMotionType.RadiusCompensationCancel:
                        case (char)ImmediateMotionType.RadiusCompensationLeft:
                        case (char)ImmediateMotionType.RadiusCompensationRight:
                        case (char)ImmediateMotionType.LengthCompensationCancel:
                        case (char)ImmediateMotionType.LengthCompensationNegative:
                        case (char)ImmediateMotionType.LengthCompensationPositive:

                            break;

                        case (char)ImmediateMotionType.RotateSpeed:
                            CurrentModal.RotateSpeed = motion_info_list[index].Rotate_Speed;
                            break;

                        default:
                            break;
                        }
                    }
                }
                //常规运动
                if (motion_info_list[index].Motion_Type != -1)
                {
                    Main.RunningSpeed = (int)(motion_info_list[index].Velocity * Main.move_rate);
                    SpeedNow          = (int)motion_info_list[index].Velocity;
                    Main.M_value      = motion_info_list[index].M_Code;
                    switch (motion_info_list[index].Motion_Type)
                    {
                    case (int)MotionType.DryRunning:
//						CurrentModal.SetModalCode("G00", 0);
                        yield return(StartCoroutine(Auto_Script.LineMovement(motion_info_list[index].Direction, motion_info_list[index].Time_Value, motion_info_list[index].VirtualTarget, index, 0)));

                        break;

                    case (int)MotionType.MachineCooSys:
                        yield return(StartCoroutine(Auto_Script.LineMovement(motion_info_list[index].Direction, motion_info_list[index].Time_Value, motion_info_list[index].VirtualTarget, index, 0)));

                        break;

                    case (int)MotionType.Line:
//						CurrentModal.SetModalCode("G01", 0);
                        yield return(StartCoroutine(Auto_Script.LineMovement(motion_info_list[index].Direction, motion_info_list[index].Time_Value, motion_info_list[index].VirtualTarget, index, 0)));

                        break;

                    case (int)MotionType.Circular02:
//						CurrentModal.SetModalCode("G02", 0);
                        yield return(StartCoroutine(Auto_Script.CircularMovement(motion_info_list[index].Direction, motion_info_list[index].VirtualTarget, motion_info_list[index].DisplayTarget,
                                                                                 motion_info_list[index].DisplayStart, motion_info_list[index].Time_Value, motion_info_list[index].Center_Point, motion_info_list[index].Rotate_Speed, true, motion_info_list[index].Current_Plane, index, motion_info_list[index].Slices)));

                        break;

                    case (int)MotionType.Circular03:
//						CurrentModal.SetModalCode("G03", 0);
                        yield return(StartCoroutine(Auto_Script.CircularMovement(motion_info_list[index].Direction, motion_info_list[index].VirtualTarget, motion_info_list[index].DisplayTarget,
                                                                                 motion_info_list[index].DisplayStart, motion_info_list[index].Time_Value, motion_info_list[index].Center_Point, motion_info_list[index].Rotate_Speed, false, motion_info_list[index].Current_Plane, index, motion_info_list[index].Slices)));

                        break;

                    case (int)MotionType.AutoReturnRP:
                    case (int)MotionType.BackFromRP:
                        yield return(StartCoroutine(Auto_Script.LineMovement(motion_info_list[index].Direction, motion_info_list[index].Time_Value, motion_info_list[index].VirtualTarget, index, 1)));

                        yield return(StartCoroutine(Auto_Script.LineMovement(motion_info_list[index].Direction2, motion_info_list[index].Time_Value2, motion_info_list[index].VirtualTarget2, index, 2)));

                        break;

                    case (int)MotionType.Pause:
                        Auto_Script.SetPause();
                        yield return(StartCoroutine(Auto_Script.PauseTimer(motion_info_list[index].Time_Value)));

                        break;

                    default:
                        Debug.Log("未知常规运动!");
                        break;
                    }
                }
            }            //2level
            //Todo:解决换刀过程不能被紧急停止的功能
            for (int i = 0; i < motion_info_list[index].ToolChange_Motion.Length; i++)
            {
                switch (motion_info_list[index].ToolChange_Motion[i])
                {
                case (char)ToolChange.T:
                    yield return(StartCoroutine(AutoToolChange_Script.ChooseTool(motion_info_list[index].Tool_Number)));

                    break;

                case (char)ToolChange.M:
                    if (tool_motion_list[0].TimeValue > 0)
                    {
                        yield return(StartCoroutine(Auto_Script.LineMovement(tool_motion_list[0].Direction, tool_motion_list[0].TimeValue, tool_motion_list[0].VirtualTarget, motion_info_list.Count + tool_motion_list.Count, 0)));
                    }
                    tool_motion_list.RemoveAt(0);
                    yield return(StartCoroutine(AutoToolChange_Script.ChangeToolProcess()));

                    break;

                default:
                    break;
                }
            }

            //单步运行
            Main.RunningSpeed = 0;
            SpeedNow          = 0;
            Main.M_value      = 0;
            if (Main.SingleStep)
            {
                singleStepEnd = 100;
                yield return(StartCoroutine(SingleStepTimer()));
            }
        }                                                                          //1level
        ProgramModule_Script.SetModalState(new List <int>(), new List <string>()); //模态变化的蓝色光标清空
        if (Main.MDI_RunningFlag)
        {
            MDIStop();
        }
        Main.AutoRunning_flag = false;
        Main.Compile_flag     = false;
        Main.MDI_RunningFlag  = false;
        Main.MDI_CompileFlag  = false;
        Main.PartsNum++;         //加工零件数+1
        DisplayEnd();
        Main.SpindleSpeed = 0;
        Main.T_Value      = 0;
        Main.D_value      = 0;
        Main.H_value      = 0;
        ProgramModule_Script.CurrentCodeDisplay(new List <string>(), new List <string>(), new List <float>(), new List <string>(), new List <string>(), new List <float>());   //当前段和下一段显示清空
    }