/// <summary> /// 检查配方管理器是否存在 /// </summary> /// <param name="errorInfo"></param> /// <returns></returns> bool CheckRecipeMgr(out string errorInfo) { IJFRecipeManager rm = JFHubCenter.Instance.RecipeManager; if (null == rm) { errorInfo = "配方管理器未创建"; return(false); } if (rm.GetType() != typeof(JFDLAFRecipeManager) && !typeof(JFDLAFRecipeManager).IsAssignableFrom(rm.GetType())) { errorInfo = "当前配方管理器类型错误:" + rm.GetType().Name; return(false); } if (!rm.IsInitOK) { errorInfo = "配方管理器初始化未完成,ErrorInfo:" + rm.GetInitErrorInfo(); return(false); } errorInfo = "Success"; return(true); }
void AdjustManagerView2UI() { panel1.Controls.Clear(); IJFRecipeManager recipeMgr = JFHubCenter.Instance.RecipeManager; if (null == recipeMgr) { toolStripMenuItemReset.Text = "新建配方管理器"; toolStripTbTips.Text = "系统不存在配方管理器"; toolStripMenuItemInitMgr.Visible = false; toolStripMenuItemInitParam.Visible = false; toolStripMenuItemDialog.Visible = false; return; } else { toolStripMenuItemReset.Text = "重置配方管理器"; toolStripMenuItemInitMgr.Visible = true; toolStripMenuItemInitParam.Visible = true; if (!recipeMgr.IsInitOK) { toolStripTbTips.Text = "管理器初始化错误:" + recipeMgr.GetInitErrorInfo(); return; } toolStripTbTips.Text = "管理器已初始化!"; if (recipeMgr is IJFConfigUIProvider) { toolStripMenuItemDialog.Visible = true; } else { toolStripMenuItemDialog.Visible = false; } if (recipeMgr is IJFRealtimeUIProvider) { JFRealtimeUI ui = (recipeMgr as IJFRealtimeUIProvider).GetRealtimeUI(); ui.Dock = DockStyle.Fill; panel1.Controls.Add(ui); ui.Show(); ui.UpdateSrc2UI(); } } }
/// <summary> /// 配方管理器初始化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItemInitMgr_Click(object sender, EventArgs e) { IJFRecipeManager recipeMgr = JFHubCenter.Instance.RecipeManager; if (null == recipeMgr) { MessageBox.Show("系统配置中不存在配方管理器"); return; } bool isOK = recipeMgr.Initialize(); if (!isOK) { MessageBox.Show("配方管理器初始化失败,ErrorInfo:" + recipeMgr.GetInitErrorInfo()); return; } AdjustManagerView2UI(); }
private void btOK_Click(object sender, EventArgs e) { if (null == _mgr) { MessageBox.Show("无效操作,RecipeManager未设置"); return; } if (!_mgr.IsInitOK) { MessageBox.Show("无效操作,RecipeManager未初始化,ErrorInfo:" + _mgr.GetInitErrorInfo()); return; } if (string.IsNullOrWhiteSpace(cbGenCate.Text)) { MessageBox.Show("参数项 Categoty 不能为空值!"); return; } if (string.IsNullOrWhiteSpace(tbGenID.Text)) { MessageBox.Show("参数项 RecipeID 不能为空值!"); return; } string[] existIDs = _mgr.AllRecipeIDsInCategoty(cbGenCate.Text); if (null != existIDs && existIDs.Contains(tbGenID.Text)) { MessageBox.Show("添加Recipe失败,Categoty = " + cbGenCate.Text + "已包含当前RecipeID = " + tbGenID.Text); return; } JFCommonRecipe newRecipe = new JFCommonRecipe(); newRecipe.Categoty = cbGenCate.Text; newRecipe.ID = tbGenID.Text; if (chkCopy.Checked) //以拷贝的方式创建新的Recipe { if (string.IsNullOrEmpty(cbCopyCate.Text)) { MessageBox.Show("请选择待拷贝的Categoty!"); return; } if (string.IsNullOrEmpty(cbCopyID.Text)) { MessageBox.Show("请选择待拷贝的RecipeID!"); return; } JFCommonRecipe recipe = _mgr.GetRecipe(cbCopyCate.Text, cbCopyID.Text) as JFCommonRecipe; string xmlTxt; string typeTxt; JFFunctions.ToXTString(recipe.Dict, out xmlTxt, out typeTxt); newRecipe.Dict = JFFunctions.FromXTString(xmlTxt, typeTxt) as JFXmlDictionary <string, object>; } _mgr.AddRecipe(cbGenCate.Text, tbGenID.Text, newRecipe); _mgr.Save(); DialogResult = DialogResult.OK; }
protected override bool ActionGenuine(out string errorInfo) { string recipeID = GetMethodInputValue("RecipeID") as string; if (string.IsNullOrEmpty(recipeID)) { errorInfo = "输入参数RecipeID 为空字串"; return(false); } IJFImage markImg1 = GetMethodInputValue("MarkImage1") as IJFImage; if (null == markImg1) { errorInfo = "MarkImage1 is null"; return(false); } IJFImage markImg2 = GetMethodInputValue("MarkImage2") as IJFImage; if (null == markImg1) { errorInfo = "MarkImage1 is null"; return(false); } IDLAFProductFixReceiver rcver = GetMethodInputValue("定位结果接收者") as IDLAFProductFixReceiver; if (null == rcver) { errorInfo = "定位结果接收者 未设置"; return(false); } double markSnapX1 = Convert.ToDouble(GetMethodInputValue("MarkSanpX1")); double markSnapY1 = Convert.ToDouble(GetMethodInputValue("MarkSanpY1")); double markSnapX2 = Convert.ToDouble(GetMethodInputValue("MarkSanpX2")); double markSnapY2 = Convert.ToDouble(GetMethodInputValue("MarkSanpY2")); double[] icCenterX = null; double[] icCenterY = null; double[] fovOffsetX = null; double[] fovOffsetY = null; int fixErrorCode = -1; string fixErrorInfo = "软件功能未实现"; //////////////////////////////////////////////添加定位算法流程 IJFRecipeManager irm = JFHubCenter.Instance.RecipeManager; if (null == irm) { errorInfo = "配方管理器未设置"; rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } if (!irm.IsInitOK) { errorInfo = "配方管理器未初始化 :" + irm.GetInitErrorInfo(); rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } JFDLAFRecipeManager rm = irm as JFDLAFRecipeManager; if (null == rm) { errorInfo = "配方管理器类型错误 :" + irm.GetType().Name; rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } JFDLAFProductRecipe recipe = rm.GetRecipe("Product", recipeID) as JFDLAFProductRecipe; if (null == recipe) { errorInfo = "RecipeID =\"" + recipeID + "\" 在配方管理器中不存在"; rcver.PFErrorInfo = errorInfo; rcver.PFErrorCode = -1; return(false); } ///使用原始拍照点位 icCenterX = new double[recipe.ICCount]; icCenterY = new double[recipe.ICCount]; for (int i = 0; i < recipe.RowCount; i++) { for (int j = 0; j < recipe.ColCount; j++) { recipe.GetICSnapCenter(i, j, out icCenterX[i * recipe.ColCount + j], out icCenterY[i * recipe.ColCount + j]); } } ///使用原始Fov偏移量 fovOffsetX = new double[recipe.FovCount]; fovOffsetY = new double[recipe.FovCount]; for (int i = 0; i < recipe.FovCount; i++) { recipe.GetFovOffset(recipe.FovNames()[i], out fovOffsetX[i], out fovOffsetY[i]); } fixErrorCode = 0; //当前为演示代码,返回模板图像拍照位置 rcver.PFRecipeID = recipeID; rcver.PFErrorInfo = fixErrorInfo; rcver.PFICCenterX = icCenterX; rcver.PFICCenterY = icCenterY; rcver.PFFovOffsetX = fovOffsetX; rcver.PFFovOffsetY = fovOffsetY; rcver.PFErrorCode = fixErrorCode; errorInfo = "Success"; return(true); }