private bool Initialize(string item) { bool valid = true; if (item != "BreakPointStart" && (this.lastOperation == "Idle" || this.lastOperation == "Stop")) { Messenger.Default.Send <object>(false, "CanvasMonitorChanged"); //this.UpdateDataProvider(); this.UpdateDrawObjectsCnt(); #region Step1: Check if empty //if (this.provider.IsEmpty) if (this.drawObjectsCnt == 0) { MsgBoxService.ShowMessage("没有可加工的图形!", "消息", MessageButton.OK, MessageIcon.Information); return(false); } #endregion #region Step2: Check if need to sort, then move figures and get dataprovider again //bool needToSort = false; //if (this.provider.DrawObjectCount > 1) if (this.drawObjectsCnt > 1) { //var res = this.MsgBoxService.ShowMessage("加工之前是否先进行排序?", "消息", MessageButton.YesNoCancel, MessageIcon.Question); //if (res == MessageResult.Cancel) //{ // return false; //} //needToSort = res == MessageResult.Yes; } int index = SystemContext.CoordinatePara.RefZeroIndex; if (index == 0) //Floating coordinate { var p = SystemContext.Hardware.GetCurrentPosition(); SystemContext.CoordinatePara.RefZeroSeries[0] = p; } var zeroPoint = SystemContext.CoordinatePara.RefZeroSeries[index]; //Messenger.Default.Send<object>(null, "OnMoveFigures"); //Messenger.Default.Send<object>(null, "OnPreview"); //Messenger.Default.Send<object>(zeroPoint, "RelativePosChanged"); //this.UpdateDataProvider(needToSort); var para = new CanvasOperParameter { OperType = CanvasOperTypes.Move | CanvasOperTypes.Preview, Selected = SystemContext.MachineControlPara.IsOnlyMachineSelected }; Messenger.Default.Send <object>(para, "OnOperation"); Messenger.Default.Send <object>(zeroPoint, "RelativePosChanged"); #endregion #region Step3: check if out of range if (SystemContext.MachineControlPara.SoftwareLimitEnabled) { var rect1 = this.provider.GetOutlineRect(); var rect2 = SystemContext.SystemPara.GetMachiningRegion(); if (!rect2.Contains(rect1.Value)) { MsgBoxService.ShowMessage("加工图形已经超出行程范围!", "消息", MessageButton.OK, MessageIcon.Error); return(false); } } #endregion #region Step4: Initialize OperationEngine.Instance.Intialize(this.provider); Messenger.Default.Send <object>(null, "ClearMark"); Messenger.Default.Send <object>(false, "CanvasStatusChanged"); //Messenger.Default.Send<object>(false, "CanvasMonitorChanged"); if (item != "Simulate") { Messenger.Default.Send <object>(true, "MenuInfoDisChanged"); Messenger.Default.Send <object>(TimerStatus.Restart, "TimerStatusChanged"); } #endregion #region Step5: Log string msg; if (index == 0) { msg = $"设置浮动坐标系的零点为({zeroPoint.X.ToString("0.###")},{zeroPoint.Y.ToString("0.###")})mm"; } else { msg = $"选择程序坐标系{index},其零点位于({zeroPoint.X.ToString("0.###")},{zeroPoint.Y.ToString("0.###")})mm"; } if (item == "Start") { this.AddSysLog("开始", Color.FromArgb(128, 0, 0)); this.AddSysLog(msg, Color.FromArgb(0, 128, 128)); this.AddSysLog("开始加工", Color.FromArgb(0, 0, 255)); if (this.drawObjectsCnt < 5000) { var info = this.GetMachineInfo(); msg = $"切割总长:{info.CutLen.ToString("0.##")}mm, 空移总长:{info.EmptyMoveLen.ToString("0.##")}mm, 穿孔次数:{info.PiercingTimes}次"; this.AddSysLog(msg, Color.FromArgb(0, 128, 0)); //msg = $"切割时间(估计):{info.CutTime.ToString("0.###")}s, 空移时间(估计):{info.EmptyMoveTime.ToString("0.###")}s, 延时:{info.Delay.ToString("0.###")}s, 总耗时(估计):{info.TotalTime.ToString("0.###")}s"; msg = $"切割时间(估计):{DelayHelper.GetTimeString(info.CutTime)}, 空移时间(估计):{DelayHelper.GetTimeString(info.EmptyMoveTime)}, 延时:{DelayHelper.GetTimeString(info.Delay)}, 总耗时(估计):{DelayHelper.GetTimeString(info.TotalTime)}"; this.AddSysLog(msg, Color.FromArgb(0, 128, 0)); } this.AddSysLog("停止-->正在加工", Color.Black); } if (item == "Outline") { this.AddSysLog("检边", Color.FromArgb(128, 0, 0)); this.AddSysLog(msg, Color.FromArgb(0, 128, 128)); this.AddSysLog("停止-->检边", Color.Black); } if (item == "Simulate") { this.AddSysLog("模拟", Color.FromArgb(128, 0, 0)); this.AddSysLog(msg, Color.FromArgb(0, 128, 128)); this.AddSysLog("停止-->模拟", Color.Black); } if (item == "Empty") { this.AddSysLog("空走", Color.FromArgb(128, 0, 0)); this.AddSysLog(msg, Color.FromArgb(0, 128, 128)); this.AddSysLog("停止-->空走", Color.Black); } #endregion } return(valid); }
private void OnLogMachineTime(object arg) { //this.AddSysLog($"加工结束!花费时间:{this.watch.Elapsed.TotalSeconds.ToString("0.###")}s", Color.FromArgb(0, 128, 0)); this.AddSysLog($"加工结束!花费时间:{DelayHelper.GetTimeString(this.watch.Elapsed.TotalSeconds)}", Color.FromArgb(0, 128, 0)); }