private void HalconTemplateCreator_ParentChanged(object sender, EventArgs e) { if (Parent != null) { ParentForm.Text = "GenTemplate"; ParentForm.AutoSize = true; ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing); try { lineGuageParam = (LineGuageParam)FastData.SaveStatic.ReadBin(guagepath); } catch (Exception exp) { MessageBox.Show("读取文件失败!" + guagepath + exp); } transCom.Items.AddRange(new object[3] { CalipTrans.all, CalipTrans.negtive, CalipTrans.positive }); heightTxt.Text = lineGuageParam.CalipHeight.ToString(); widthTxt.Text = lineGuageParam.CalipWidth.ToString(); calipNumTxt.Text = lineGuageParam.CalipNum.ToString(); thresholdTxt.Text = lineGuageParam.CalipThreshold.ToString(); IgnoreTxt.Text = lineGuageParam.CalipIgnore.ToString(); transCom.Text = lineGuageParam.calipTrans.ToString(); if (Image != null) { button1.Enabled = false; button2.Enabled = false; engine = new HDevEngine(); program = new HDevProgram(mPath); programCall = new HDevProgramCall(program); if (impl == null) { impl = new HDevOpMultiWindowImpl(hWindowControltemp.HalconWindow); } engine.SetHDevOperators(impl); //string di = new DirectoryInfo(string.Format("{0}../../../../", Application.StartupPath)).FullName; //string aa = di + "Template"; //if (!Directory.Exists(aa)) // Directory.CreateDirectory(aa); SetTemplateOriginImage(Image); Excute(); } } }
public void initialengine(string filename) { programPath = System.Environment.CurrentDirectory + @"\" + filename + ".hdev"; procedurePath = System.Environment.CurrentDirectory + @"\"; if (!HalconAPI.isWindows) { programPath = programPath.Replace("\\", "/"); procedurePath = procedurePath.Replace("\\", "/"); } engine.SetProcedurePath(procedurePath); // viewPort.HalconWindow.SetLineWidth(4); MyHDevOperatorImpl = new HDevOpMultiWindowImpl(viewPort.HalconWindow); engine.SetHDevOperators(MyHDevOperatorImpl); }
private void VisualizeDetailsBtn_Click(object sender, System.EventArgs e) { this.Cursor = Cursors.WaitCursor; try { // enable HDevelop's display operators MyEngine.SetHDevOperators(MyHDevOperatorImpl); // execute procedure VisualizeDetailsProcCall.SetInputIconicParamObject("Image", Image); VisualizeDetailsProcCall.SetInputIconicParamObject("Region", FinRegion); VisualizeDetailsProcCall.SetInputCtrlParamTuple("ZoomScale", 2); VisualizeDetailsProcCall.SetInputCtrlParamTuple("Margin", 5); VisualizeDetailsProcCall.Execute(); // disable HDevelop's display operators MyEngine.SetHDevOperators(null); } catch (HDevEngineException Ex) { MessageBox.Show(Ex.Message, "HDevEngine Exception"); return; } this.Cursor = Cursors.Default; }
public void Excute() { if (task.Status == TaskStatus.Created || task.IsCompleted || task.IsFaulted || task.IsCanceled) { task = new Task(() => { engine = new HDevEngine(); program = new HDevProgram(Path); programCall = new HDevProgramCall(program); if (impl == null) { impl = new HDevOpMultiWindowImpl(hSmartWindowControlcamera.HalconWindow); } engine.SetHDevOperators(impl); programCall.Execute(); }, TaskCreationOptions.LongRunning); task.Start(); } }
/// <summary> /// 执行 /// </summary> /// <param name="timeout">处理超时时间,若小于等于0,则无限等待.单位:毫秒</param> /// <param name="outputs">输出结果</param> public void Execute(int timeout, out ItemCollection outputs) { try { stopwatch.Restart(); if (runningWindow == null) { try { runningWindow = (RunningWindow as HSmartWindowControlWPF).HalconWindow; hDevEngine.SetHDevOperators(new HDevOpMultiWindowImpl(runningWindow)); } catch (Exception) { } } //执行程序 hDevProgramCall.Execute(); //拼接输出结果 Outputs.Clear(); foreach (var item in valueName) { HTuple valueTuple = hDevProgramCall.GetCtrlVarTuple(item); switch (valueTuple.Type) { case HTupleType.EMPTY: break; case HTupleType.INTEGER: Outputs.Add(new ItemBase(item, valueTuple.IArr, item)); break; case HTupleType.LONG: Outputs.Add(new ItemBase(item, valueTuple.LArr, item)); break; case HTupleType.DOUBLE: Outputs.Add(new ItemBase(item, valueTuple.DArr, item)); break; case HTupleType.STRING: Outputs.Add(new ItemBase(item, valueTuple.SArr, item)); break; case HTupleType.MIXED: break; default: break; } } stopwatch.Stop(); RunStatus = new RunStatus(stopwatch.Elapsed.TotalMilliseconds); outputs = new ItemCollection(Outputs); UpdatePart(runningWindow); } catch (Exception ex) { RunStatus = new RunStatus(0, EResult.Error, ex.Message, ex); throw; } }
public void button1_Click(object sender, EventArgs e) { button1.Enabled = false; if (GetTaskStatus() == 0) { OpenFileDialog ofd = new OpenFileDialog(); string initdi = new DirectoryInfo(string.Format("{0}../../../../", Application.StartupPath)).FullName; //ofd.Filter = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx|所有文件|*.*"; ofd.CheckPathExists = true; ofd.CheckFileExists = true; ofd.InitialDirectory = initdi + "SavePic"; if (ofd.ShowDialog() == DialogResult.OK) { engine = new HDevEngine(); program = new HDevProgram(mPath); programCall = new HDevProgramCall(program); if (impl == null) { impl = new HDevOpMultiWindowImpl(hWindowControltemp.HalconWindow); } engine.SetHDevOperators(impl); //string di = new DirectoryInfo(string.Format("{0}../../../../", Application.StartupPath)).FullName; //string aa = di + "Template"; //if (!Directory.Exists(aa)) // Directory.CreateDirectory(aa); string strFileName = ofd.FileName; SetTemplateOriginPath(strFileName); Excute(); } } else//如已经在运行,将任务先停掉,然后再调用 { OpenFileDialog ofd = new OpenFileDialog(); //ofd.Filter = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx|所有文件|*.*"; ofd.CheckPathExists = true; ofd.CheckFileExists = true; if (ofd.ShowDialog() == DialogResult.OK) { StopTask(); Thread.Sleep(500); engine = new HDevEngine(); program = new HDevProgram(mPath); programCall = new HDevProgramCall(program); if (impl == null) { impl = new HDevOpMultiWindowImpl(hWindowControltemp.HalconWindow); } engine.SetHDevOperators(impl); //string di = new DirectoryInfo(string.Format("{0}../../../../", Application.StartupPath)).FullName; //string aa = di + "Template"; //if (!Directory.Exists(aa)) // Directory.CreateDirectory(aa); //textBox1.Text = aa + "\\template.tif"; string strFileName = ofd.FileName; SetTemplateOriginPath(strFileName); Excute(); } } button1.Enabled = true; }
private void 切换到本窗口ToolStripMenuItem_Click(object sender, EventArgs e) { impl = new HDevOpMultiWindowImpl(hSmartWindowControlcamera.HalconWindow); engine.SetHDevOperators(impl); }