Пример #1
0
        private void btn_Add_Click(object sender, EventArgs e)
        {
            if (txt_Name.Text.Trim() == "")
            {
                MessageBox.Show("请输入资源名称");
                return;
            }
            if (txt_Path.Text.Trim() == "")
            {
                MessageBox.Show("请输入资源路径");
                return;
            }

            string Typeobject = cbb_Type.SelectedItem.ToString();

            if (Typeobject == null)
            {
                MessageBox.Show("请选择类型,再填加");
                return;
            }
            HObject hobj;
            HTuple  obj_model = new HTuple();

            if (Typeobject == "region")
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (txt_Name.Text == row.Cells[0].Value.ToString())
                    {
                        MessageBox.Show("已包含同名资源,请重新设定");
                        return;
                    }
                }
                HOperatorSet.GenEmptyObj(out hobj);
                try
                {
                    HOperatorSet.ReadRegion(out hobj, txt_Path.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("载入区域region失败,请检测类型是否正确");
                    return;
                }
                Info_Source new_info = new Info_Source(txt_Name.Text + ".region", "region", txt_Path.Text);
                _sourceBuffer[Source_number]._s_ObjectBuffer.Add(new_info, hobj);
                int index = dataGridView1.Rows.Add();

                dataGridView1.Rows[index].Cells[0].Value = txt_Name.Text.Trim();
                dataGridView1.Rows[index].Cells[1].Value = cbb_Type.SelectedItem.ToString();
                dataGridView1.Rows[index].Cells[2].Value = txt_Path.Text;
                UpdateSourceBuffer.OnSendUpdateSourceBuffer(new UpdateSourceBufferEventArgs(_sourceBuffer, _executeBuffer));
            }


            if (Typeobject == "shapemode_contour" || Typeobject == "tuple" || Typeobject == "shapemode_grey")
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (txt_Name.Text == row.Cells[0].Value.ToString())
                    {
                        MessageBox.Show("已包含同名资源,请重新设定");
                        return;
                    }
                }
                // HOperatorSet.GenEmptyObj(out obj_model);
                Info_Source new_info = new Info_Source(txt_Name.Text, "region", txt_Path.Text);
                try
                {
                    if (Typeobject == "shapemode_contour")
                    {
                        HOperatorSet.ReadShapeModel(txt_Path.Text, out obj_model);
                        new_info.Name = txt_Name.Text + ".shapemode_contour";
                        new_info.Type = "shapemode_contour";
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("载入形状模板失败,请检查类型是否正确");
                    return;
                }


                try
                {
                    if (Typeobject == "shapemode_grey")
                    {
                        //HOperatorSet.ReadShapeModel(txt_Path.Text, out obj_model);
                        HOperatorSet.ReadTemplate(txt_Path.Text, out obj_model);
                        new_info.Name = txt_Name.Text + ".shapemode_grey";
                        new_info.Type = "shapemode_grey";
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("载入灰度模板失败,请检查类型是否正确");
                    return;
                }

                try
                {
                    if (Typeobject == "tuple")
                    {
                        HOperatorSet.ReadTuple(txt_Path.Text, out obj_model);
                        new_info.Name = txt_Name.Text + ".tuple";
                        new_info.Type = "tuple";
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("载入Tuple文件失败,请检查类型是否正确");
                    return;
                }

                _sourceBuffer[Source_number]._s_ControlBuffer.Add(new_info, obj_model);
                int index = dataGridView1.Rows.Add();

                dataGridView1.Rows[index].Cells[0].Value = txt_Name.Text.Trim();
                dataGridView1.Rows[index].Cells[1].Value = cbb_Type.SelectedItem.ToString();
                dataGridView1.Rows[index].Cells[2].Value = txt_Path.Text;
                UpdateSourceBuffer.OnSendUpdateSourceBuffer(new UpdateSourceBufferEventArgs(_sourceBuffer, _executeBuffer));
            }
        }
Пример #2
0
        public bool NinePointCalMake(SourceBuffer _sourceBuffer, ExecuteBuffer _executeBuffer, out SourceBuffer outsourcebuffer, out ExecuteBuffer outexecutebuffer)
        {
            outsourcebuffer  = _sourceBuffer;
            outexecutebuffer = _executeBuffer;
            m      = Convert.ToDouble(txt_m.Text.ToString());
            n      = Convert.ToDouble(txt_n.Text.ToString());
            WorldX = new HTuple(0, m, m, 0, -m, -m, -m, 0, m);
            WorldY = new HTuple(0, 0, -n, -n, -n, 0, n, n, n);
            for (int i = 0; i < x_point.Count; i++)
            {
                HOperatorSet.TupleConcat(temp_row, (HTuple)x_point[i], out temp_row_last);
                temp_row = temp_row_last;
                HOperatorSet.TupleConcat(temp_column, (HTuple)y_point[i], out temp_column_last);
                temp_column = temp_column_last;
            }
            try
            {
                HOperatorSet.VectorToHomMat2d(temp_column, temp_row, WorldY, WorldX, out PixToWorld);
                HOperatorSet.VectorToHomMat2d(WorldY, WorldX, temp_column, temp_row, out WorldToPixel);
            }
            catch (Exception)
            {
                MessageBox.Show("点位错误,请确认匹配是否正确");
                return(false);
            }
            //保存PixelToWorld到本地
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title            = "PixelToWorld保存";
            sfd.RestoreDirectory = true;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string strPath = sfd.FileName;
                if (!strPath.EndsWith(".tup"))
                {
                    strPath += ".tup";
                }
                Match match = Regex.Match(strPath, "(\\w+)(.tup)$");
                HOperatorSet.WriteTuple(PixToWorld, strPath);
                bool cPixToWorld_add = true;
                foreach (Info_Source keybuffcontrol in _sourceBuffer._s_ControlBuffer.Keys)
                {
                    if (keybuffcontrol.Name == match.Groups[1].ToString())
                    {
                        cPixToWorld_add = false;
                        break;
                    }
                }
                Info_Source control_add_key = new Info_Source();
                control_add_key.Name = match.Groups[1].ToString() + ".tuple";
                control_add_key.Path = strPath;
                control_add_key.Type = "tuple";
                if (cPixToWorld_add)
                {
                    _sourceBuffer._s_ControlBuffer.Add(control_add_key, PixToWorld);
                }
                else
                {
                    _sourceBuffer._s_ControlBuffer[control_add_key] = PixToWorld;
                }



                if (_executeBuffer.controlBuffer.ContainsKey(match.Groups[1].ToString()))
                {
                    _executeBuffer.controlBuffer[match.Groups[1].ToString()] = PixToWorld;
                }
                else
                {
                    _executeBuffer.controlBuffer.Add(match.Groups[1].ToString(), PixToWorld);
                }
            }

            //保存WorldToPixel到本地
            SaveFileDialog sfd2 = new SaveFileDialog();

            sfd2.Title            = "WorldToPixel保存";
            sfd2.RestoreDirectory = true;
            if (sfd2.ShowDialog() == DialogResult.OK)
            {
                string strPath = sfd2.FileName;
                if (!strPath.EndsWith(".tup"))
                {
                    strPath += ".tup";
                }
                Match match = Regex.Match(strPath, "(\\w+)(.tup)$");
                HOperatorSet.WriteTuple(WorldToPixel, strPath);
                bool WorldToPixel_add = true;
                foreach (Info_Source keybuffcontrol in _sourceBuffer._s_ControlBuffer.Keys)
                {
                    if (keybuffcontrol.Name == match.Groups[1].ToString())
                    {
                        WorldToPixel_add = false;
                        break;
                    }
                }
                Info_Source control_add_key = new Info_Source();
                control_add_key.Name = match.Groups[1].ToString() + ".tuple";
                control_add_key.Path = strPath;
                control_add_key.Type = "tuple";
                if (WorldToPixel_add)
                {
                    _sourceBuffer._s_ControlBuffer.Add(control_add_key, WorldToPixel);
                }
                else
                {
                    _sourceBuffer._s_ControlBuffer[control_add_key] = WorldToPixel;
                }



                if (_executeBuffer.controlBuffer.ContainsKey(match.Groups[1].ToString()))
                {
                    _executeBuffer.controlBuffer[match.Groups[1].ToString()] = WorldToPixel;
                }
                else
                {
                    _executeBuffer.controlBuffer.Add(match.Groups[1].ToString(), WorldToPixel);
                }
            }
            outsourcebuffer  = _sourceBuffer;
            outexecutebuffer = _executeBuffer;
            MessageBox.Show("9点标定成功");

            return(true);
        }
Пример #3
0
        private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int selectcount = dataGridView1.SelectedRows.Count;

            Info_Source Del_item = new Info_Source();

            int model = 0;

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                if (row.Cells[1].Value.ToString() == "region")
                {
                    model = 0;
                    foreach (Info_Source keybufferobject in _sourceBuffer[Source_number]._s_ObjectBuffer.Keys)
                    {
                        if (keybufferobject.Name == (row.Cells[0].Value.ToString() + ".region") && keybufferobject.Type == row.Cells[1].Value.ToString() && keybufferobject.Path == row.Cells[2].Value.ToString())
                        {
                            Del_item = keybufferobject;
                            break;
                        }
                    }
                    Clear_list(Del_item.Name, model);
                    _sourceBuffer[Source_number]._s_ObjectBuffer.Remove(Del_item);
                    //   Clear_list(Del_item.Name,model);
                    UpdateSourceBuffer.OnSendUpdateSourceBuffer(new UpdateSourceBufferEventArgs(_sourceBuffer, _executeBuffer));
                }

                else
                {
                    model = 1;
                    foreach (Info_Source keybuffcontrol in _sourceBuffer[Source_number]._s_ControlBuffer.Keys)
                    {
                        if (keybuffcontrol.Type == row.Cells[1].Value.ToString() && keybuffcontrol.Path == row.Cells[2].Value.ToString())
                        {
                            if (keybuffcontrol.Type == "shapemode_contour")
                            {
                                if (keybuffcontrol.Name == row.Cells[0].Value.ToString() + ".shapemode_contour")
                                {
                                    Del_item = keybuffcontrol;
                                    break;
                                }
                            }
                            if (keybuffcontrol.Type == "shapemode_grey")
                            {
                                if (keybuffcontrol.Name == row.Cells[0].Value.ToString() + ".shapemode_grey")
                                {
                                    Del_item = keybuffcontrol;
                                    break;
                                }
                            }
                            if (keybuffcontrol.Type == "tuple")
                            {
                                if (keybuffcontrol.Name == row.Cells[0].Value.ToString() + ".tuple")
                                {
                                    Del_item = keybuffcontrol;
                                    break;
                                }
                            }
                            if (keybuffcontrol.Type == "xld")
                            {
                                if (keybuffcontrol.Name == row.Cells[0].Value.ToString() + ".xld")
                                {
                                    Del_item = keybuffcontrol;
                                    break;
                                }
                            }
                        }
                    }
                    Clear_list(Del_item.Name, 1);
                    _sourceBuffer[Source_number]._s_ControlBuffer.Remove(Del_item);

                    UpdateSourceBuffer.OnSendUpdateSourceBuffer(new UpdateSourceBufferEventArgs(_sourceBuffer, _executeBuffer));
                }
            }
            while (selectcount > 0)
            {
                if (!dataGridView1.SelectedRows[0].IsNewRow)
                {
                    dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
                }
                selectcount--;
            }
        }