private void Button_Save_ForSetup_Click(object sender, RoutedEventArgs e)
        {
            int i = -1;
            int iBright = -1, iContract = -1, iSaturation = -1, iColor = -1, iAngle = -1, iDelay = -1;
            try
            {
                for ( i = 0; i < 6; i++)
                {
                    switch (i)
                    {
                        case 0:
                            iBright = int.Parse(textBox_Bright_ForSetup.Text.Trim());
                            if (iBright < -100 || iBright > 100)
                            {
                                throw new Exception("参数值错误");
                            }
                            break;
                        case 1:
                            iContract = int.Parse(textBox_Contract_ForSetup.Text.Trim());
                            if (iContract < -100 || iContract > 100)
                            {
                                throw new Exception("参数值错误");
                            }
                            break;
                        case 2:
                            iSaturation = int.Parse(textBox_Saturation_ForSetup.Text.Trim());
                            if (iSaturation < -100 || iSaturation > 100)
                            {
                                throw new Exception("参数值错误");
                            }
                            break;
                        case 3:
                            iColor = combo_Box_Color_ForSetup.SelectedIndex;
                            break;
                        case 4:
                            iAngle = int.Parse(textBox_Angle_ForSetup.Text.Trim());
                            if (iAngle < 0 || iAngle > 360)
                            {
                                throw new Exception("参数值错误");
                            }
                            break;
                        case 5:
                            iDelay = int.Parse(textBox_Delay_ForSetup.Text.Trim());
                            if (iDelay < 0 || iDelay > 5000)
                            {
                                throw new Exception("参数值错误");
                            }
                            break;
                    }
                }
            }
            catch(Exception ex)
            {
                string sField = "图像亮度,图像对比,图像平滑,图像颜色,截面角度,播放间隔,".Substring(i * 5, 4);
                MyTools.ShowMsg("“" + sField + "”参数错误。", ex.Message);
                return;
            }

            MessageBoxResult rt = MessageBox.Show("把当前参数保存为默认配置吗?", "温馨提示", MessageBoxButton.YesNo, MessageBoxImage.Warning);
            if (rt == MessageBoxResult.Yes)
            {
                MyData.BrightDefault = iBright;
                MyData.ContractDefault = iContract;
                MyData.SaturationDefault = iSaturation;
                MyData.ColorDefault = iColor;
                MyData.AngleDefault = iAngle;
                MyData.DelayDefault = iDelay;

                MyData.BrightCurrent = iBright;
                MyData.ContractCurrent = iContract;
                MyData.SaturationCurrent = iSaturation;
                MyData.ColorCurrent = iColor;
                MyData.AngleCurrent = iAngle;
                MyData.DelayCurrent = iDelay;

                string sErr = "";
                if (!MyData.MySqlite.SetRefe(ref sErr))
                {
                    MyTools.ShowMsg("把参数写入文件时出错", sErr);
                }
                else
                {
                    MyTools.ShowMsg("默认参数保存成功", sErr);
                }
            }
        }
示例#2
0
        public bool ReadAllFramDataFromFile(ref byte[] AllFrameInfo, ref byte[] AllRaw, ref double[,] BeltData, double Angle0, UserControl_ReadFileBar RBar, ref string sErrString)
        {
            bool bResult = false;

            sErrString = "";
            double dBarStep = RBar.iBarValue;

            if (ggData.m_szFileName == "")   // 还没关联gg文件
            {
                sErrString = "尚未打开相关文件。";
                return(bResult);
            }

            if (ggData.numberof_frames <= 0)
            {
                AllRaw   = null;       // 没有数据
                BeltData = null;
                return(bResult);
            }

            dBarStep      += 5.0;
            RBar.iBarValue = (int)(dBarStep);
            MyTools.DoEvents();

            double Angle = 2 * PI_360 * Angle0 / 360;

            BeltData = null;
            IntPtr buffer = Marshal.AllocHGlobal(1);

            try
            {
                int iFrameInfoSize = Marshal.SizeOf(typeof(ggFrame_struct));

                AllFrameInfo = new byte[ggData.numberof_frames * iFrameInfoSize];
                mod_ReadGen2.Gen2_Struct Gen2Current = new mod_ReadGen2.Gen2_Struct();
                //Gen2Array = new mod_ReadGen2.Gen2_Struct[ggData.numberof_frames];
                mod_ShowPict PB = new mod_ShowPict();

                byte[] FirstLine  = new byte[ggData.numberof_frames * ggData.numberofpointofline * 2];
                byte[] SecondLine = new byte[ggData.numberof_frames * ggData.numberofpointofline * 2];

                int iFirstLine = 0, iSeconLine = 0;   // 取出第几线
                iFirstLine = (int)((ggData.numberofline / (PI_360 * 2)) * (Angle + ggData.Angle2));
                if (iFirstLine > ggData.numberofline)
                {
                    iFirstLine -= ggData.numberofline;
                }

                iSeconLine = iFirstLine + ggData.numberofline / 2;
                if (iSeconLine > ggData.numberofline)
                {
                    iSeconLine -= ggData.numberofline;
                }

                for (int i = 0; i < ggData.numberof_frames; i++)
                {
                    if (ggFileMoveToFrame("Goto", i, ref sErrString))
                    {
                        // 计算从第几帧取数据

                        if (ReadRawFrameDataFromFile(ref ggData.m_ggframe_info, ref ggData.m_lprawdata, ref ggData.m_lpimagedata, ref sErrString))
                        {
                            if (i == 0)
                            {
                                ggData.m_sizeofrawdata = ggData.m_ggframe_info.rawdatasize;
                                AllRaw = new byte[ggData.numberof_frames * ggData.m_sizeofrawdata];
                            }

                            Marshal.FreeHGlobal(buffer);                          // 释放以前分配的空间
                            buffer = Marshal.AllocHGlobal(iFrameInfoSize);        // 重新分配
                            Marshal.StructureToPtr((ggFrame_struct)ggData.m_ggframe_info, buffer, false);
                            Marshal.Copy(buffer, AllFrameInfo, i * iFrameInfoSize, iFrameInfoSize);

                            Array.Copy(ggData.m_lprawdata, 0, AllRaw, i * ggData.m_sizeofrawdata, ggData.m_sizeofrawdata);
                            //Gen2Current = new mod_ReadGen2.Gen2_Struct();
                            //if (mod_ReadGen2.ReadGen2FromGGClass(this, ref Gen2Current, ref sErrString) != MyData.iErr_Succ)
                            //{
                            //    MyTools.ShowMsg("读取数据失败!", "从gg类读数据失败 = " + sErrString);
                            //    goto Eend;
                            //}
                            //PB.pGen2 = Gen2Current;
                            //PB.Gen2ToData();                        // 转变成 PictData
                            //Gen2Array[i] = PB.pGen2;

                            Array.Copy(ggData.m_lprawdata, iFirstLine * ggData.numberofpointofline * 2, FirstLine, i * ggData.numberofpointofline * 2, ggData.numberofpointofline * 2);       // To First Line
                            Array.Copy(ggData.m_lprawdata, iSeconLine * ggData.numberofpointofline * 2, SecondLine, i * ggData.numberofpointofline * 2, ggData.numberofpointofline * 2);      // To First Line

                            dBarStep      += (double)(85.0 / ggData.numberof_frames);
                            RBar.iBarValue = (int)(dBarStep);
                            MyTools.DoEvents();
                        }
                        else
                        {
                            sErrString = "移动到第" + i.ToString() + "帧时出错";
                            goto Eend;
                        }
                    }
                    else
                    {
                        sErrString = "移动到第" + i.ToString() + "帧时出错";
                        goto Eend;
                    }
                }

                BeltData = new double[ggData.numberof_frames * 2, ggData.numberofpointofline];
                ushort uSi = 0;
                ushort uMax = 0, uMin = 0;

                for (int i = 0; i < ggData.numberof_frames; i++)
                {
                    for (int j = 0; j < ggData.numberofpointofline; j++)
                    {
                        uSi            = BitConverter.ToUInt16(FirstLine, i * ggData.numberofpointofline * 2 + j * 2);
                        BeltData[i, j] = (double)uSi;
                        if (uMin > uSi)
                        {
                            uMin = uSi;
                        }

                        if (uMax < uSi)
                        {
                            uMax = uSi;
                        }

                        uSi = BitConverter.ToUInt16(SecondLine, i * ggData.numberofpointofline * 2 + j * 2);
                        BeltData[ggData.numberof_frames + i, j] = (double)uSi;
                        if (uMin > uSi)
                        {
                            uMin = uSi;
                        }

                        if (uMax < uSi)
                        {
                            uMax = uSi;
                        }
                    }
                }

                for (int i = 0; i < ggData.numberof_frames; i++)
                {
                    for (int j = 0; j < ggData.numberofpointofline; j++)
                    {
                        //BeltData[i, j] = (BeltData[i, j] / 65535.0) * (uMax - uMin) + uMin;
                        //BeltData[ggData.numberof_frames + i, j] = (BeltData[ggData.numberof_frames + i, j] / 65535.0) * (uMax - uMin) + uMin;

                        BeltData[i, j] = BeltData[i, j] * 255 / 65535.0;
                        BeltData[ggData.numberof_frames + i, j] = BeltData[ggData.numberof_frames + i, j] * 255 / 65535.0;
                    }
                }

                bResult    = true;
                sErrString = "";
            }
            catch (OutOfMemoryException)
            {
                sErrString = "内存不足";
            }
            catch (Exception ex)
            {
                sErrString = ex.Message;
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }

Eend:
            return(bResult);
        }
示例#3
0
        public static int ReadGen2FromFile(string sFileName, ref Gen2_Struct ThisGen1, ref string sErrString)
        {
            Gen2_Struct ThisGen2 = new Gen2_Struct();

            //StreamReader sr = null;
            BinaryReader br = null;
            FileStream   fs = null;
            //FileStream ws = null;
            //StreamWriter sw = null;

            int len_lastname       = 0;
            int len_firstname      = 0;
            int len_patientid      = 0;
            int len_sex            = 0;
            int len_dateofbirth    = 0;
            int len_physican1      = 0;
            int len_physican2      = 0;
            int len_image_datatime = 0;
            int len_Procedures     = 0;
            int len_Note           = 0;

            int    iTmp = 0;
            double dTmp = 0;

            int SumData1 = 0;
            int iResult = iErr_UnknowErr;
            int i = 0, j = 0;

            if (sFileName == "")
            {
                sErrString = "没有文件名";
                return(iErr_NoFile);
            }

            if (!File.Exists(sFileName))
            {
                sErrString = "文件不存在";
                return(iErr_NoFile);
            }

            try
            {
                ThisGen2.m_FileName = sFileName;
                fs = new FileStream(sFileName, FileMode.Open, FileAccess.Read);
                //sr = new StreamReader(fs);
                br = new BinaryReader(fs);

                string   sTmp = "";
                string[] sData;
                for (i = 0; i < 10; i++)
                {
                    //sTmp = sr.ReadLine();
                    sTmp     = MyTools.ReadFileLine(br);
                    sData    = sTmp.Split(':');
                    sData[0] = sData[0].ToUpper().Trim();
                    if (sData[0] == "LAST NAME")
                    {
                        len_lastname        = MyTools.GetStringCode(sData[1]);
                        ThisGen2.m_lastname = sData[1].Trim();
                    }
                    else if (sData[0] == "FIRST NAME")
                    {
                        len_firstname        = MyTools.GetStringCode(sData[1]);
                        ThisGen2.m_firstname = sData[1].Trim();
                    }
                    else if (sData[0] == "PATIENT ID")
                    {
                        len_patientid        = MyTools.GetStringCode(sData[1]);
                        ThisGen2.m_patientid = sData[1].Trim();
                    }
                    else if (sData[0] == "SEX")
                    {
                        len_sex        = MyTools.GetStringCode(sData[1]);
                        ThisGen2.m_sex = sData[1].Trim();
                    }
                    else if (sData[0] == "DATE OF BIRTH")
                    {
                        len_dateofbirth        = MyTools.GetStringCode(sData[1]);
                        sTmp                   = sData[1].Trim();
                        ThisGen2.m_dateofbirth = sTmp.Substring(6, 4) + "-" + sTmp.Substring(0, 2) + "-" + sTmp.Substring(3, 2) + " 00:00:00";
                    }
                    else if (sData[0] == "PHYSICAN1")
                    {
                        len_physican1        = MyTools.GetStringCode(sData[1]);
                        ThisGen2.m_physican1 = sData[1].Trim();
                    }
                    else if (sData[0] == "PHYSICAN2")
                    {
                        len_physican2        = MyTools.GetStringCode(sData[1]);
                        ThisGen2.m_physican2 = sData[1].Trim();
                    }
                    else if (sData[0] == "IMAGE DATE AND TIME")
                    {
                        len_image_datatime = MyTools.GetStringCode(sData[1]);

                        // 可能有多种格式:Image Date and Time:20170210-1154-41
                        bool     DateIsOK = false;
                        DateTime dt       = DateTime.Now;
                        sTmp = sData[1].Trim();

                        while (!DateIsOK)
                        {
                            for (int m = 0; m < 2; m++)
                            {
                                try
                                {
                                    switch (m)
                                    {
                                    case 0:
                                        dt       = DateTime.Parse(sTmp);
                                        DateIsOK = true;
                                        break;

                                    case 1:
                                        dt = DateTime.Parse(sTmp.Substring(0, 4) + "-" + sTmp.Substring(4, 2) + "-" + sTmp.Substring(6, 2) + " " +
                                                            sTmp.Substring(9, 2) + ":" + sTmp.Substring(11, 2) + ":" + sTmp.Substring(14, 2));
                                        DateIsOK = true;
                                        break;
                                    }
                                }
                                catch
                                {
                                }

                                if (DateIsOK)
                                {
                                    break;
                                }
                            }

                            if (DateIsOK)
                            {
                                break;
                            }
                            else
                            {
                                string sEditTopic = "注意:检查记录的'检查时间'不是标准的时间格式,请按照'yyyy-mm-dd hh:mm:ss'更正。";
                                string sEditFiled = "检查时间";
                                string sEditText  = sTmp;
                                bool   bEditOK    = false;

                                frm_EditDateTime Frm_EditDateTime = new frm_EditDateTime();
                                Frm_EditDateTime.sEditTopic = sEditTopic;
                                Frm_EditDateTime.sEditFiled = sEditFiled;
                                Frm_EditDateTime.sEditText  = sEditText;
                                Frm_EditDateTime.bEditOK    = bEditOK;
                                Frm_EditDateTime.ShowDialog();

                                sEditText = Frm_EditDateTime.sEditText;
                                bEditOK   = Frm_EditDateTime.bEditOK;
                                Frm_EditDateTime.Close();

                                if (bEditOK)     // 修改过了
                                {
                                    sTmp = sEditText;
                                }
                                else            // 不要修改
                                {
                                    break;
                                }
                            }
                        }

                        if (!DateIsOK)
                        {
                            sErrString = "Gen2文件的'检查时间'数据无效";
                            iResult    = iErr_ValidData;
                            goto Eend;
                        }
                        else
                        {
                            ThisGen2.m_image_datatime = dt.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                    }
                    else if (sData[0] == "PROCEDURES")
                    {
                        len_Procedures        = MyTools.GetStringCode(sData[1]);
                        ThisGen2.m_Procedures = sData[1].Trim();
                    }
                    else if (sData[0] == "NOTES")
                    {
                        len_Note        = MyTools.GetStringCode(sData[1]);
                        ThisGen2.m_Note = sData[1].Trim();
                    }
                }

                // 补充
                ThisGen2.m_FileID     = 0;
                ThisGen2.m_Address    = "";
                ThisGen2.m_Tele       = "";
                ThisGen2.m_IdentifyID = "";
                // 补充 End

                ThisGen2.m_NScanSave       = int.Parse(MyTools.ReadFileLine(br).Trim());
                ThisGen2.m_Angle2          = int.Parse(MyTools.ReadFileLine(br).Trim());
                ThisGen2.m_Number_line_360 = int.Parse(MyTools.ReadFileLine(br).Trim());
                ThisGen2.m_SN = int.Parse(MyTools.ReadFileLine(br).Trim());
                ThisGen2.m_DD = int.Parse(MyTools.ReadFileLine(br).Trim());
                ThisGen2.m_G  = int.Parse(MyTools.ReadFileLine(br).Trim());

                //dTmp = double.Parse(MyTools.ReadFileLine(br).Trim());
                iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                while (true)
                {
                    if (iTmp != 1000)
                    {
                        break;
                    }
                    iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                }
                //iTmp = (int)(dTmp + 0.1);
                if (iTmp != len_lastname)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                if (iTmp != len_firstname)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                if (iTmp != len_patientid)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                if (iTmp != len_sex)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                if (iTmp != len_dateofbirth)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                if (iTmp != len_physican1)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                if (iTmp != len_physican2)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                if (iTmp != len_image_datatime)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                if (iTmp != len_Procedures)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                iTmp = int.Parse(MyTools.ReadFileLine(br).Trim());
                if (iTmp != len_Note)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                ThisGen2.m_NData    = int.Parse(MyTools.ReadFileLine(br).Trim());
                ThisGen2.m_maxValue = double.Parse(MyTools.ReadFileLine(br).Trim());       // 记录这组Data中的最大值与最小值
                ThisGen2.m_minValue = double.Parse(MyTools.ReadFileLine(br).Trim());
                // fscanf(fpp, "%c", &cr);				 // 还要多读一个字符 = 10 0x0A

                ThisGen2.ampplot_sI = new Int32[ThisGen2.m_NScanSave, ThisGen2.m_NData];
                ThisGen2.ampplot_s  = new double[ThisGen2.m_NScanSave, ThisGen2.m_NData];
                SumData1            = 0;
                sbyte d1 = 0;
                sbyte d2 = 0;
                byte  c  = 0;

                // For Print ========================================
                //FileStream FileForPrint = File.Open(Directory.GetCurrentDirectory() + "\\gen2_Ampplot_sI.txt", FileMode.Create);
                //StreamWriter w = new StreamWriter(FileForPrint);
                // ==================================================

                for (j = 0; j < ThisGen2.m_NScanSave; j++)
                {
                    for (i = 0; i < ThisGen2.m_NData; i++)
                    {
                        //d1 = (sbyte)br.ReadByte();
                        //d2 = (sbyte)br.ReadByte();

                        d1 = (sbyte)br.ReadByte();
                        if (d1 == 0x0D)
                        {
                            if (br.BaseStream.Position < (br.BaseStream.Length - 1))
                            {
                                c = br.ReadByte();
                                if (c == 0x0A)
                                {
                                    d1 = (sbyte)c;
                                }
                                else
                                {
                                    br.BaseStream.Seek(-1, SeekOrigin.Current);
                                }
                            }
                        }
                        d2 = (sbyte)br.ReadByte();
                        if (d2 == 0x0D)
                        {
                            if (br.BaseStream.Position < (br.BaseStream.Length - 1))
                            {
                                c = br.ReadByte();
                                if (c == 0x0A)
                                {
                                    d2 = (sbyte)c;
                                }
                                else
                                {
                                    br.BaseStream.Seek(-1, SeekOrigin.Current);
                                }
                            }
                        }

                        //while (true)
                        //{
                        //    d2 = (sbyte)br.ReadByte();
                        //    if (d2 == 0x0D)
                        //    {
                        //        continue;
                        //    }
                        //    break;
                        //}

                        iTmp = d1;
                        if (iTmp < 0)
                        {
                            iTmp += 256;
                        }
                        ThisGen2.ampplot_sI[j, i] = iTmp * 256;

                        iTmp = d2;
                        if (iTmp < 0)
                        {
                            iTmp += 256;
                        }
                        ThisGen2.ampplot_sI[j, i] += iTmp;

                        // For Print ========================
                        //w.Write("ThisGen2.ampplot_sI[" + j.ToString() + "," + i.ToString() + "] = " + ThisGen2.ampplot_sI[j, i].ToString() + Environment.NewLine);
                        // ==================================


                        ThisGen2.ampplot_s[j, i] = (ThisGen2.ampplot_sI[j, i] / 65535.0) * (ThisGen2.m_maxValue - ThisGen2.m_minValue) + ThisGen2.m_minValue;
                        //  temp save raw data for background
                        // U16_RawData.RawData[j][i] = (unsigned short) ampplot_sI[j][i];//ampplot_s[j][i];

                        SumData1 = SumData1 + d1 + d2;
                        //sTmp = "ampot(" + j.ToString("D3") + "," + i.ToString("D3") + ") = " + d1.ToString("X2") + "," + d2.ToString("X2") + "," + ThisGen2.ampplot_sI[j, i].ToString("D6") + ",P = " + br.BaseStream.Position.ToString("X");
                        //sw.WriteLine(sTmp);
                    }
                }

                // For Print ========================
                //w.Close();
                //FileForPrint.Close();
                // ==================================

                sTmp = MyTools.ReadFileLine(br).Trim();      //fscanf(fpp, "%c", &cr);

                sTmp = MyTools.ReadFileLine(br).Trim();
                if (sTmp.Length > 0)
                {
                    iTmp = int.Parse(sTmp);
                }
                else
                {
                    iTmp = 0;
                }

                if (iTmp != SumData1)
                {
                    sErrString = "Gen2文件数据无效";
                    iResult    = iErr_ValidData;
                    goto Eend;
                }

                iTmp = 0;
                ThisGen2.m_CheckNote = "";
                while (true)
                {
                    if (br.BaseStream.Position >= (br.BaseStream.Length - 1))
                    {
                        break;
                    }
                    else
                    {
                        sTmp = MyTools.ReadFileLine(br).Trim();
                        ThisGen2.m_CheckNote += "\r\n" + sTmp;
                    }
                }

                ThisGen1   = ThisGen2;
                iResult    = iErr_Succ;
                sErrString = "";

                br.Close();
                fs.Close();
                // 读完文件后,数据就存放在 FileStruct 中
            }
            catch (Exception ex)
            {
                sErrString = "读Gen文件出错(" + ex.Message + ") j = " + j.ToString() + ",i = " + i.ToString();
                iResult    = iErr_Exception;
            }

Eend:
            if (br != null)
            {
                br.Close();
            }
            if (fs != null)
            {
                fs.Close();
            }
            return(iResult);
        }