コード例 #1
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int iRow = e.RowIndex;

            if (iRow >= 0)
            {
                if (dataGridView1.Rows[iRow].Cells[0].Value != null && dataGridView1.Rows[iRow].Cells[1].Value != null)
                {
                    string taskName = dataGridView1.Rows[iRow].Cells[0].Value.ToString();
                    formSetting = CreatingHelper <TaskToolManager> .GetSingleObject();

                    VisionTaskInfo info = VisionTaskManger.GetTaskInfoInstance(taskName);
                    if (info != null)
                    {
                        formSetting.Info          = info;
                        formSetting.StartPosition = FormStartPosition.CenterScreen;
                        if (formSetting.IsShowing)
                        {
                            formSetting.IsShowing = false;
                            formSetting.Close();
                            System.Threading.Thread.Sleep(5);
                            formSetting.Show();
                            formSetting.IsShowing = true;
                        }
                        else
                        {
                            formSetting.Show();
                            formSetting.IsShowing = true;
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: VisionTask.cs プロジェクト: huangyukun417/JCVision
        public VisionTask(VisionTaskInfo info)
        {
            #region MyRegion
            result        = new ToolResult();
            ToolsDic      = new Dictionary <string, ITool>();
            ToolList      = new List <ITool>();
            ToolResultDic = new Dictionary <string, ToolResult>();
            InputRegion   = new HRegion();
            InputRegion.GenEmptyRegion();
            InputImage = new HImage();
            InputImage.GenEmptyObj();
            #endregion

            this.Info = info;
            TaskName  = info.TaskName;
            //显示界面布局
            foreach (var item in Info.TaskToolsInfo)
            {
                object[] paras = new object[] { item };
                ITool    tool  = CreatingHelper <ITool> .CreateInstance(@".//VisionTools/" + item.GetToolNameSpace() + ".dll", item.GetToolNameSpace(), item.GetToolClassName(), paras);

                if (tool != null)
                {
                    ToolsDic.Add(tool.TaskName, tool);
                    ToolList.Add(tool);
                }
            }
        }
コード例 #3
0
        public static bool AddCameraInfo(string cameraName, string camType)
        {
            if (doc != null)
            {
                if (!doc.CamerasInfoDic.ContainsKey(cameraName))
                {
                    IVisionCameraInfo info = CreatingHelper <IVisionCameraInfo> .CreateInstance(@".//CamerasDll/" + "Vision" + camType + ".dll", "Vision" + camType, camType + "Info");

                    info.UserID = cameraName;
                    doc.CamerasInfoList.Add(info);
                    doc.CamerasInfoDic.Add(info.UserID, info);
                    return(true);
                }
            }
            return(false);
        }
コード例 #4
0
        private void TaskToolManager_Load(object sender, EventArgs e)
        {
            #region 加载工具列表
            List <FileInfo> fileInfos = new List <FileInfo>();
            //获取所有工具
            if (!Directory.Exists(@".\\VisionTools\"))
            {
                if (MessageHelper.ShowWarning("没有找到任何图像工具文件,是否停用该软件?") == DialogResult.OK)
                {
                    //关闭软件
                }
            }
            string[] filePath = Directory.GetFiles(@".\\VisionTools\");
            if (filePath.Length > 0)
            {
                for (int i = 0; i < filePath.Length; i++)
                {
                    FileInfo info = new FileInfo(filePath[i]);
                    if (info.Exists && info.Extension == ".dll")
                    {
                        fileInfos.Add(info);
                    }
                }
            }
            foreach (var item in fileInfos)
            {
                string toolType        = string.Empty;
                string toolDescription = item.FullName;
                //通过反射获取工具名称并添加到列表中
                var value = CreatingHelper <IToolInfo> .CreateInstance(item.FullName, item.Name.Substring(0, item.Name.Length - 4), item.Name.Substring(6, item.Name.Length - 10));

                if (value != null)
                {
                    DataGridViewRow         newrow   = new DataGridViewRow();
                    DataGridViewTextBoxCell namecell = new DataGridViewTextBoxCell();
                    namecell.Value = value.GetToolType();
                    DataGridViewTextBoxCell desCell = new DataGridViewTextBoxCell();
                    desCell.Value = toolDescription;
                    newrow.Cells.Add(namecell);
                    newrow.Cells.Add(desCell);
                    ToolDataGridView.Rows.Add(newrow);
                }
            }
            #endregion
        }
コード例 #5
0
        public static void InitCamera()
        {
            LoadDoc();
            try
            {
                Cameras = new Dictionary <string, CameraBase>();
                if (doc == null)
                {
                    return;
                }
                if (doc.CamerasInfoList.Count != 0)
                {
                    foreach (var info in doc.CamerasInfoList)
                    {
                        object[] paras  = new object[] { info };
                        var      camera = CreatingHelper <CameraBase> .CreateInstance(@".//CamerasDll/" + "Vision" + info._CameraType + "Camera" + ".dll", "Vision" + info._CameraType + "Camera", info._CameraType.ToString() + "Camera", paras);

                        if (camera != null)
                        {
                            Cameras.Add(camera.UserID, camera);
                        }
                    }
                }
                else
                {
                    #region 枚举巴斯勒相机
                    List <string> baslerCams = CameraGeneral.GetBaslerCameraListInfo();
                    if (baslerCams.Count > 0)
                    {
                        foreach (var cam in baslerCams)
                        {
                            AddCameraInfo(cam, "Basler");
                            IVisionCameraInfo info  = GetCameraInfoInstance(cam);
                            object[]          paras = new object[] { info };
                            var camera = CreatingHelper <CameraBase> .CreateInstance(@".//CamerasDll/" + "Vision" + info._CameraType + "Camera" + ".dll", "Vision" + info._CameraType + "Camera", info._CameraType.ToString() + "Camera", paras);

                            if (camera != null)
                            {
                                Cameras.Add(camera.UserID, camera);
                            }
                        }
                    }
                    #endregion

                    #region 枚举海康相机
                    List <string> hikCams = CameraGeneral.GetHikCameraListInfo();
                    if (hikCams.Count > 0)
                    {
                        foreach (var cam in hikCams)
                        {
                            AddCameraInfo(cam, "Hik");
                            IVisionCameraInfo info  = GetCameraInfoInstance(cam);
                            object[]          paras = new object[] { info };
                            var camera = CreatingHelper <CameraBase> .CreateInstance(@".//CamerasDll/" + "Vision" + info._CameraType + "Camera" + ".dll", "Vision" + info._CameraType + "Camera", info._CameraType.ToString() + "Camera", paras);

                            if (camera != null)
                            {
                                Cameras.Add(camera.UserID, camera);
                            }
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                MessageHelper.ShowError(ex.ToString());
            }
            SaveDoc();
        }
コード例 #6
0
        private void InsertBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(toolNameTxt.Text))
            {
                MessageHelper.ShowWarning("请先输入工具名称");
                return;
            }
            if (ToolDataGridView.SelectedRows.Count == 1)
            {
                int iRow = ToolDataGridView.SelectedRows[0].Index;
                if (iRow >= 0)
                {
                    if (ToolDataGridView.Rows[iRow].Cells[0].Value == null || ToolDataGridView.Rows[iRow].Cells[1].Value == null)
                    {
                        return;
                    }
                    string   toolName    = toolNameTxt.Text.Trim();
                    string   toolType    = ToolDataGridView.Rows[iRow].Cells[0].Value.ToString();
                    string   toolDllPath = ToolDataGridView.Rows[iRow].Cells[1].Value.ToString();
                    FileInfo fileInfo    = new FileInfo(toolDllPath);
                    if (fileInfo.Exists)
                    {
                        try
                        {
                            object[] infoParam = new object[] { toolName };
                            var      toolInfo  = CreatingHelper <IToolInfo> .CreateInstance(fileInfo.FullName, fileInfo.Name.Substring(0, fileInfo.Name.Length - 4), fileInfo.Name.Substring(6, fileInfo.Name.Length - 10) + "Info", infoParam);

                            if (toolInfo != null)
                            {
                                object[] toolParam = new object[] { toolInfo };
                                //添加工具到任务中
                                var tool = CreatingHelper <ITool> .CreateInstance(fileInfo.FullName, fileInfo.Name.Substring(0, fileInfo.Name.Length - 4), fileInfo.Name.Substring(6, fileInfo.Name.Length - 10), toolParam);

                                if (tool != null)
                                {
                                    if (this.info != null && this.task != null)
                                    {
                                        if (this.task.InsertTool(TaskToolDatagridIndex, tool) && this.info.InsertToolInfo(TaskToolDatagridIndex, toolInfo))
                                        {
                                            //刷新工具界面
                                            UpdateToolGridView();
                                        }
                                        else
                                        {
                                            MessageHelper.ShowError("插入工具失败!");
                                        }
                                    }
                                    else
                                    {
                                        MessageHelper.ShowError("插入工具失败,不存在该任务!");
                                    }
                                }
                                else
                                {
                                    MessageHelper.ShowError("插入工具失败,生成工具出错!");
                                }
                            }
                            else
                            {
                                MessageHelper.ShowError("插入工具失败,生成工具信息出错!");
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageHelper.ShowError($"{ex.ToString()}");
                        }
                    }
                    else
                    {
                        MessageHelper.ShowError("工具插件不存在,请检查该工具的DLL文件!");
                    }
                }
            }
        }