private void MainFrame_FormClosing(object sender, FormClosingEventArgs e) { if (isAdminstrator) { DialogResult result = MessageBox.Show("即将退出软件,是否保存当前设置?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); //新增取消软件关闭功能 if (result == DialogResult.Cancel) { e.Cancel = true; return; } else if (result == DialogResult.Yes) { try { AppManger.ProjectData.Instance.SaveProject(UserSetting.Instance.ProjectPath); } catch (Exception ex) { //Util.WriteLog(this.GetType(), ex); string message = ex.Message; MessageBox.Show("工程数据保存失败" + message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { DialogResult result = MessageBox.Show("确定要退出软件吗?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.Cancel) { e.Cancel = true; return; } } autoUnit.save_data_result(); //Application.Exit(); CameraManger.Close(); CommHandle.Instance.Close(); // PLC.PanasonicPLCComm.Instance.CloseCom(); //关闭所有相机处理线程 foreach (var item in autoUnit.runTheadDataDic.Values) { item.Stop(); } autoUnit.RunCommWriteDataThread.Stop(); autoUnit.RunCommReadDataThread.Stop(); Thread.Sleep(30); //关闭所有线程-此处有点暴力-待删除 Process.GetCurrentProcess().Kill(); Application.ExitThread(); }
//构造所有的管理类,初始化所有的管理类 private void InitManger() { uiManager = new UIManager(this); audioManger = new AudioManger(this); playManger = new PlayManger(this); cameraManger = new CameraManger(this); requestManger = new RequestManger(this); clientManger = new ClientManger(this); mangerList.Add(uiManager); mangerList.Add(audioManger); mangerList.Add(playManger); mangerList.Add(cameraManger); mangerList.Add(requestManger); mangerList.Add(clientManger); mangerList.ForEach(m => m.OnInit()); }
// Checks if the active camera sees the player. If the player is behind another object the player is not seen. // TODO: Only detects if the center of the player object is visible. Needs to be changed to the whole player collider. // player.collider.bounds.Contains (hit.transform.position) doesn't seem to be doing the trick :( bool CanSeePlayer() { Vector3 viewPos = CameraManger.getActiveCamera().WorldToViewportPoint(player.transform.position); Vector3 here = CameraManger.getActiveCamera().transform.position; Vector3 pos = player.transform.position; foreach (Vector3 v in corners) { RaycastHit rch; bool didhit = Physics.Linecast(here, pos + v, out rch); Debug.DrawRay(new Vector3(0, 0, 0), pos + v); if (checkViewPos(viewPos) && didhit) { if (rch.transform == player.transform) { Debug.Log("You are seen"); return(true); } // Debug.DrawRay (new Vector3 (0, 0, 0), rch.transform.position); } } return(false); }
/// <summary> /// 切换运行状态 /// </summary> public void btnRun_Click(object sender, EventArgs e) { int cameraCount = IniStatus.Instance.CamearCount; Dictionary <int, CameraBase> cameraDic = CameraManger.CameraDic; try { if (CommHandle.Instance.IsLink == false) { /*StatusManger status = StatusManger.Instance; * if (status.RuningStatus == RuningStatus.系统异常) * { * MessageBox.Show("系统出现异常,请检查设置", "提示", * MessageBoxButtons.OK, MessageBoxIcon.Error); * return; * }*/ if (CameraManger.CameraDic.Count > 0) { CameraManger.Close(); } if (CameraManger.Open() == false) { MessageBox.Show("没有相机连接,无法启动", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } for (int i = 0; i < cameraCount; i++) { if (cameraDic.ContainsKey(i + 1) == false) { //Util.Notify(string.Format("请注意相机{0}未连接", i+1)); MessageHelper.ShowError(string.Format("相机{0}没有找到", i + 1)); } } foreach (int key in cameraDic.Keys) { if (key > cameraCount || key < 1) { cameraDic.Remove(key); Util.Notify(Level.Err, $"相机{key}名称ID超出相机个数设定范围,请用相机软件重新设定"); return; } } Util.Notify("相机打开完成"); foreach (var item in ToolsFactory.ToolsDic.Values) { Tools.CreateImage.CreateImageTool createImageTool = item[0] as Tools.CreateImage.CreateImageTool; createImageTool.OffLineMode = false; } LoadProject(false); CommHandle.Instance.CommunicationParam = UserSetting.Instance.MainDeviceComParam; //两对象同是CommunicationParam类型。 CommHandle.Instance.Open(); } else { if (MessageBox.Show("确定中止运行吗?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { CommHandle.Instance.IsLink = false; foreach (var item in CameraManger.CameraDic.Values) { item.ContinuousShotStop(); if (item.IsContinuousShot) { item.ContinuousShotStop(); } } } } } catch (Exception) { } }
/// <summary> /// 打开相机,加载工程文件,通信参数设定,打开通讯。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmMain_Load(object sender, EventArgs e) { //Common.UI.FrmLoad frmLoad = new Common.UI.FrmLoad(Application.StartupPath + @"\Res\Loading\"); //Common.UI.Parameter.Name = frmAbout.AssemblyProduct; //Common.UI.Parameter.Year = DateTime.Now.ToString("yyyy"); //Common.UI.Parameter.Version = frmAbout.AssemblyVersion; //Common.UI.Parameter.CopyRight = frmAbout.AssemblyCopyright; //Common.UI.Parameter.CompanyName = frmAbout.AssemblyCompany; //Common.UI.Parameter.Status = "初始化中..."; //Common.UI.Parameter.StatusNum = 0; //frmLoad.Show(); //frmLoad.UpdateProgress("相机加载...", 0, 30, 500); //frmWait.AsyncMethod += ((obj, args) => { //注册认证 #if !DEBUG //string key = ""; //key = Common.RegisterHelper.getMNum(); // if (UserSetting.Instance.SoftKey == null || UserSetting.Instance.SoftKey != key) //{ // if (UserSetting.Instance.SoftKey == null) // { // MessageBox.Show("验证码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); // // Common.Util.Notify("验证码错误"); // } // else // { // // MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); // } // frmRegistered registered = new frmRegistered(); // registered.ShowDialog(); //} //if (UserSetting.Instance.SoftKey == null || UserSetting.Instance.SoftKey != key) //{ // // 终止此进程并为基础操作系统提供指定的退出代码。 // System.Environment.Exit(1); //} #endif bool isCameraOpenSuccess = false; try { //打开相机 if (CameraManger.Open()) { int cameraCount = IniStatus.Instance.CamearCount; Dictionary <int, CameraBase> cameraDic = CameraManger.CameraDic; for (int i = 0; i < cameraCount; i++) { if (cameraDic.ContainsKey(i + 1) == false) { MessageHelper.ShowError(string.Format("相机{0}没有找到", i + 1)); } } //查询相机名称是不是超出有效范围,如果超出,将其从字典中清除。 foreach (int key in cameraDic.Keys) { if (key > cameraCount || key < 1) { //cameraDic.Remove(key); Util.Notify(Level.Err, $"相机{key}已连接,但其名称ID超出相机个数设定范围,请通过相机软件修改"); } } isCameraOpenSuccess = true; Util.Notify("相机打开完成"); } else { StatusManger.Instance.RuningStatus = RuningStatus.系统异常; Util.Notify(Level.Err, "相机打开失败"); } } catch (Exception) { MessageHelper.ShowError("相机打开出现异常"); StatusManger.Instance.RuningStatus = RuningStatus.系统异常; Util.Notify(Level.Err, "相机打开出现异常"); } //加载工程文件 autoUnit.LoadProject(true); //放在此位置很重要,不能像以前一样放在最后。 try { //通信参数设定 CommHandle.Instance.CommunicationParam = UserSetting.Instance.MainDeviceComParam; //两对象同是CommunicationParam类型。 //打开通讯 if (isCameraOpenSuccess) { CommHandle.Instance.Open(); } } catch (Exception) { StatusManger.Instance.RuningStatus = RuningStatus.系统异常; Util.Notify(Level.Err, "通信端口打开异常"); } this.WindowState = FormWindowState.Maximized; } }