Exemple #1
0
        /// <summary>
        /// 保存产品
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnSave_Click(object sender, EventArgs e)
        {
            Form_Wait.ShowForm();
            await Task.Run(new Action(() =>
            {
                //需要保存当前产品的相关参数
                if (_operation != null)
                {
                    JFDLAFBoxRecipe jFDLAFBoxRecipe = JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")) as JFDLAFBoxRecipe;
                    jFDLAFBoxRecipe.MagezineBox = _operation.MagezineBox;
                    jFDLAFBoxRecipe.MgzIdx = _operation.MgzIdx;
                    jFDLAFBoxRecipe.SaveParamsToCfg();
                    _operation.SaveParamsToCfg();

                    JFHubCenter.Instance.RecipeManager.RemoveRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"));
                    JFHubCenter.Instance.RecipeManager.RemoveRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"));

                    JFHubCenter.Instance.RecipeManager.AddRecipe(_operation.Categoty, _operation.ID, _operation as IJFRecipe);
                    JFHubCenter.Instance.RecipeManager.AddRecipe("Box", _operation.ID, jFDLAFBoxRecipe as IJFRecipe);
                }

                JFHubCenter.Instance.RecipeManager.Save();
                if (_operation != null)
                {
                    if (_operation.MgzIdx == -1)
                    {
                        HTLog.Error("注意:当前产品未选择料盒型号,开始流程需要选择料盒型号.");
                        return;
                    }
                }
            }));

            Form_Wait.CloseForm();
        }
Exemple #2
0
        public void RefreshPdtUI()
        {
            prgProductMagzine.Refresh();
            HTLog.Info(String.Format("产品名:{0}", _operation.ID));
            //FormJobs.Instance.label5.Invoke(new Action(() => { FormJobs.Instance.label5.Text = "当前产品:" + _operation.ID + "  流程状态:待机"; }));
            groupBox1.Text      = "当前料片:" + _operation.ID;
            lblCurrentProd.Text = "当前产品:" + _operation.ID;

            if (File.Exists((string)JFHub.JFHubCenter.Instance.RecipeManager.GetInitParamValue(JFHub.JFHubCenter.Instance.RecipeManager.InitParamNames[2]) + "\\" + _operation.ID + "\\" + "ClipImage.tiff"))
            {
                FileStream fileStream = new FileStream((string)JFHub.JFHubCenter.Instance.RecipeManager.GetInitParamValue(JFHub.JFHubCenter.Instance.RecipeManager.InitParamNames[2]) + "\\" + _operation.ID + "\\" + "ClipImage.tiff", FileMode.Open, FileAccess.Read);
                int        byteLength = (int)fileStream.Length;
                byte[]     fileBytes  = new byte[byteLength];
                fileStream.Read(fileBytes, 0, byteLength);
                //文件流关閉,文件解除锁定
                fileStream.Close();
                pictureBox1.BackgroundImage = Image.FromStream(new MemoryStream(fileBytes));
            }
            else
            {
                pictureBox1.BackgroundImage = null;
            }
            HObject imgActivePdt = null;

            if (File.Exists((string)JFHub.JFHubCenter.Instance.RecipeManager.GetInitParamValue(JFHub.JFHubCenter.Instance.RecipeManager.InitParamNames[2]) + "\\" + _operation.ID + "\\" + "frameMapImg.tiff"))
            {
                HOperatorSet.ReadImage(out imgActivePdt, (string)JFHub.JFHubCenter.Instance.RecipeManager.GetInitParamValue(JFHub.JFHubCenter.Instance.RecipeManager.InitParamNames[2]) + "\\" + _operation.ID + "\\" + "frameMapImg.tiff");
                ShowImage(htWindow1, imgActivePdt, null);
            }
            else
            {
                imgActivePdt = null;
                ShowImage(htWindow1, imgActivePdt, null);
            }
        }
Exemple #3
0
        private void btnSaveUVXY2D_Click(object sender, EventArgs e)
        {
            this.btnSaveUVXY2D.Focus();
            HTuple uvHxy = null;

            try
            {
                GetDGVValue(dgvUVXY2D, new int[] { 0, 1 }, new int[] { 0, 2 }, ref uvHxy);
            }
            catch (Exception)
            {
                MessageBox.Show("获取2D相机UV-XY矩阵数据失败!");
                return;
            }
            //保存
            string filePath = _station.SystemUV2XYDir + "\\Camera_" + _station.SelectedIndex + "\\" + "UV2XY" + ".dat";

            try
            {
                string dir = Directory.GetParent(filePath).FullName;
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                tool_vision.save_hom2d(filePath, uvHxy);
                _station.List_UV2XYResult[_station.SelectedIndex] = uvHxy;
            }
            catch (Exception ex)
            {
                HTUi.PopError("2D相机UV-XY矩阵保存失败!\n" + ex.ToString());
                return;
            }
            HTUi.TipHint("2D相机UV-XY矩阵保存成功!");
            HTLog.Info("2D相机UV-XY矩阵保存成功!");
        }
Exemple #4
0
        /// <summary>
        /// 加载产品
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnLoadProduct_Click(object sender, EventArgs e)
        {
            string Errstring = "";

            if (lbxProductCategory.SelectedIndex == -1)
            {
                return;
            }
            btnLoadProduct.Enabled = false;

            string pdt = null;

            pdt = lbxProductCategory.SelectedValue.ToString();

            btnLoadProduct.Enabled = true;
            Form_Wait.ShowForm();
            await Task.Run(new Action(() =>
            {
                try
                {
                    //需要加载当前产品相关的参数
                    _operation = JFHubCenter.Instance.RecipeManager.GetRecipe("Product", pdt) as JFDLAFProductRecipe;
                    if (_operation == null)
                    {
                        HTUi.TipError("Recipe Manager中不存在配方:" + pdt);
                        return;
                    }

                    if (Errstring == "")
                    {
                        HTLog.Info("加载产品完成.");
                        HTUi.TipHint("加载产品完成");
                        if (_operation.MgzIdx == -1)
                        {
                            HTLog.Error("注意:当前产品未选择料盒型号,开始流程需要选择料盒型号.");
                        }
                    }
                    else
                    {
                        HTLog.Error("加载产品失败!!!" + Errstring);
                        HTUi.TipError("加载产品失败");
                        HTUi.PopWarn("产品加载失败\n" + Errstring);
                    }
                }
                catch (Exception EXP)
                {
                    HTLog.Error(String.Format("{0}加载新产品失败\n", EXP.ToString()));
                    HTUi.TipError("加载新产品失败");
                }
            }));

            if (_operation != null)
            {
                SetupUI();
            }
            JFHubCenter.Instance.SystemCfg.SetItemValue("CurrentID", pdt);
            JFHubCenter.Instance.SystemCfg.Save();
            Form_Wait.CloseForm();
        }
Exemple #5
0
        private async void btnUVXYCalib2D_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.aoiModels == null)
                {
                    this.aoiModels = new Model();
                    string folderPath = _station.SystemUV2XYDir + "\\Camera_" + _station.SelectedIndex;
                    if (!this.aoiModels.ReadModel(folderPath))
                    {
                        HTUi.PopError("未创建2D标定模板!");
                        return;
                    }
                    HOperatorSet.ReadTuple(folderPath + "\\Pos_Uv2Xy.tup", out Pos_Uv2Xy);
                }
                //设定走位范围
                CalibSearchRange csRangeFrm = new CalibSearchRange();
                if (csRangeFrm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                double xyRange = csRangeFrm.Range;
                //条件:标定板中心在2D相机视野中心位置时的chuck x y的粗略位置已知,即
                //料片视野为左下芯片为中心作为初始点位
                _station.operation.XUv2xy = Pos_Uv2Xy[0]; //App.obj_Chuck.ref_x + ((App.obj_Pdt.BlockNumber - 1) * App.obj_Pdt.BlockSpace + (App.obj_Pdt.ColumnNumber - 1) * App.obj_Pdt.ColomnSpace)/2 + App.obj_Pdt.RightEdge;
                _station.operation.YUv2xy = Pos_Uv2Xy[1]; //App.obj_Chuck.ref_y + App.obj_Pdt.TopEdge + (App.obj_Pdt.RowNumber - 1) * App.obj_Pdt.RowSpace/2;
                _station.operation.ZUv2xy = Pos_Uv2Xy[2]; //App.obj_Pdt.ZFocus;
                HTuple uvHxy  = new HTuple();
                bool   status = await Task.Run(() =>
                {
                    return(_station.operation.calibUV2XY
                           (
                               _station.SelectedIndex,
                               ref uvHxy,
                               this.aoiModels,
                               xyRange, 20
                           ));
                });

                if (!status)
                {
                    HTUi.PopError("2D相机uvHxy标定失败!");
                    return;
                }
                for (int i = 0; i < dgvUVXY2D.RowCount; i++)
                {
                    dgvUVXY2D.Rows[i].Cells[0].Value = uvHxy[i * 3].D;
                    dgvUVXY2D.Rows[i].Cells[1].Value = uvHxy[i * 3 + 1].D;
                    dgvUVXY2D.Rows[i].Cells[2].Value = uvHxy[i * 3 + 2].D;
                }
                HTUi.TipHint("2D相机uvHxy标定成功!");
                HTLog.Info("2D相机uvHxy标定成功!");
            }
            catch (Exception ex)
            {
                HTUi.PopError("2D相机uvHxy标定失败:" + ex.Message);
                btnSnap.Enabled = true;
            }
        }
Exemple #6
0
        private void btnCreateCalibModel2D_Click(object sender, EventArgs e)
        {
            try
            {
                if (modelForm == null || modelForm.IsDisposed)
                {
                    modelForm = new Form();
                    if (this.mTmpFrm != null && !this.mTmpFrm.IsDisposed)
                    {
                        this.mTmpFrm.Dispose();
                    }
                    this.mTmpFrm = new MainTemplateForm(ToolKits.TemplateEdit.MainTemplateForm.TemplateScence.Match,
                                                        this.htWindowCalibration, new MainTemplateForm.TemplateParam());
                    modelForm.Controls.Clear();
                    this.modelForm.Controls.Add(this.mTmpFrm);
                    this.mTmpFrm.Dock = DockStyle.Fill;
                    modelForm.Size    = new Size(300, 450);
                    modelForm.TopMost = true;
                    modelForm.Show();
                    int SH = Screen.PrimaryScreen.Bounds.Height;
                    int SW = Screen.PrimaryScreen.Bounds.Width;
                    modelForm.Location = new Point(SW - modelForm.Size.Width, SH / 8);

                    Task.Run(() =>
                    {
                        while (!mTmpFrm.WorkOver)
                        {
                            Thread.Sleep(200);
                        }
                        HTUi.TipHint("创建标定模板完成!");
                        HTLog.Info("创建标定模板完成!");
                        modelForm.Close();
                    });
                }
                else
                {
                    modelForm.Activate();
                }
            }
            catch (Exception ex)
            {
                HTUi.PopError("创建标定模板失败:" + ex.Message);
                btnSnap.Enabled = true;
            }
        }
Exemple #7
0
        /// <summary>
        /// 创建产品
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateProduct_Click(object sender, EventArgs e)
        {
            String newfile = "";

            if (!MSG.Inputbox("Copy&New", "请输入新的产品名", out newfile))
            {
                return;
            }

            if (newfile == string.Empty)
            {
                HTUi.PopWarn("命名错误,名字不能为空");
                return;
            }
            //新增Product Recipe到recipe Dictionary中
            JFDLAFProductRecipe jFDLAFProductRecipe = new JFDLAFProductRecipe();

            if (JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")) != null)
            {
                jFDLAFProductRecipe = ((JFDLAFProductRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))).Clone();
            }

            jFDLAFProductRecipe.ID       = newfile;
            jFDLAFProductRecipe.Categoty = "Product";
            jFDLAFProductRecipe.SaveParamsToCfg();
            JFHubCenter.Instance.RecipeManager.AddRecipe(jFDLAFProductRecipe.Categoty, jFDLAFProductRecipe.ID, jFDLAFProductRecipe as IJFRecipe);


            ////新增Box Recipe到recipe Dictionary中
            JFDLAFBoxRecipe jFDLAFBoxRecipe = new JFDLAFBoxRecipe();

            if (JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")) != null)
            {
                jFDLAFBoxRecipe = ((JFDLAFBoxRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Box", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))).Clone();
            }
            jFDLAFBoxRecipe.MagezineBox = jFDLAFProductRecipe.MagezineBox;
            jFDLAFBoxRecipe.MgzIdx      = jFDLAFProductRecipe.MgzIdx;
            jFDLAFBoxRecipe.ID          = newfile;
            jFDLAFBoxRecipe.Categoty    = "Box";
            jFDLAFBoxRecipe.SaveParamsToCfg();
            JFHubCenter.Instance.RecipeManager.AddRecipe(jFDLAFBoxRecipe.Categoty, jFDLAFBoxRecipe.ID, jFDLAFBoxRecipe as IJFRecipe);

            //此处后面需要保存
            JFHubCenter.Instance.RecipeManager.Save();

            var pdtlist = GetProductList();

            foreach (var pdt in pdtlist)
            {
                if (pdt == newfile)
                {
                    HTUi.PopWarn("无法新建,当前产品已存在");
                    return;
                }
            }
            string souce = (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID");

            if (!CreateProduct(souce, newfile))
            {
                HTUi.PopWarn("产品创建失败!");
                return;
            }
            HTLog.Info("产品创建成功!");
            HTUi.TipHint("产品创建成功!");
            lbxProductCategory.DataSource = GetProductList();
            return;
        }
Exemple #8
0
        private async void btnSaveCalibModel2D_Click(object sender, EventArgs e)
        {
            if (!this.mTmpFrm.tmpResult.createTmpOK)
            {
                HTUi.PopError("创建标定模板失败!");
                return;
            }
            Form_Wait.ShowForm();
            bool result = await Task.Run(() =>
            {
                try
                {
                    this.aoiModels = new Model();
                    this.aoiModels.Dispose();
                    this.aoiModels.showContour = this.mTmpFrm.tmpResult.showContour.CopyObj(1, -1);
                    this.aoiModels.defRows     = this.mTmpFrm.tmpResult.defRows;
                    this.aoiModels.defCols     = this.mTmpFrm.tmpResult.defCols;
                    this.aoiModels.modelType   = this.mTmpFrm.tmpResult.modelType;
                    this.aoiModels.modelID     = Vision.CopyModel(this.mTmpFrm.tmpResult.modelID, this.mTmpFrm.tmpResult.modelType);
                    this.aoiModels.scoreThresh = this.mTmpFrm.mte_TmpPrmValues.Score;
                    this.aoiModels.angleStart  = this.mTmpFrm.mte_TmpPrmValues.AngleStart;
                    this.aoiModels.angleExtent = this.mTmpFrm.mte_TmpPrmValues.AngleExtent;
                    //保存至硬盘
                    string folderPath             = _station.SystemUV2XYDir + "\\Camera_" + _station.SelectedIndex;
                    _station.CalibrUV2XYModelPath = folderPath;
                    if (!this.aoiModels.WriteModel(folderPath))
                    {
                        HTLog.Error("保存标定模板失败!");
                        HTUi.PopError("保存标定模板失败!");
                        return(false);
                    }

                    string errMsg = "";
                    Pos_Uv2Xy     = new HTuple();
                    double xUV2xy = 0, yUV2xy = 0, zUV2xy = 0;

                    if (!_station.GetAxisPosition(_station.AxisXYZ[0], out xUV2xy, out errMsg))
                    {
                        HTLog.Error(errMsg + ":保存获取X轴反馈坐标失败!");
                        HTUi.PopError(errMsg + ":保存获取X轴反馈坐标失败!");
                        return(false);
                    }

                    if (!_station.GetAxisPosition(_station.AxisXYZ[1], out yUV2xy, out errMsg))
                    {
                        HTLog.Error(errMsg + ":保存获取Y轴反馈坐标失败!");
                        HTUi.PopError(errMsg + ":保存获取Y轴反馈坐标失败!");
                        return(false);
                    }

                    if (!_station.GetAxisPosition(_station.AxisXYZ[2], out zUV2xy, out errMsg))
                    {
                        HTLog.Error(errMsg + ":保存获取Z轴反馈坐标失败!");
                        HTUi.PopError(errMsg + ":保存获取Z轴反馈坐标失败!");
                        return(false);
                    }

                    _station.operation.YUv2xy = yUV2xy;
                    _station.operation.XUv2xy = xUV2xy;
                    _station.operation.ZUv2xy = zUV2xy;

                    Pos_Uv2Xy.Append(_station.operation.XUv2xy);
                    Pos_Uv2Xy.Append(_station.operation.YUv2xy);
                    Pos_Uv2Xy.Append(_station.operation.ZUv2xy);
                    HOperatorSet.WriteTuple(Pos_Uv2Xy, folderPath + "\\Pos_Uv2Xy.tup");
                    HTUi.TipHint("保存标定模板成功!");
                    HTLog.Info("保存标定模板成功!");
                    return(true);
                }
                catch (Exception ex)
                {
                    HTLog.Error(ex.ToString());
                    HTUi.PopError(ex.ToString());

                    return(false);
                }
            });

            Form_Wait.CloseForm();
            if (!result)
            {
                HTLog.Error("保存标定模板失败!");
                HTUi.PopError("保存标定模板失败!");
                return;
            }
            HTUi.TipHint("保存标定模板成功!");
            HTLog.Info("保存标定模板成功!");
        }