Browse Source

1.修复burker过滤bug
2.添加测量边界颗粒功能

zty 2 years ago
parent
commit
9c63d54b51

+ 1 - 1
Bin/x64/Debug/Config/ProData/lj.psf

@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<XMLData FileMark="626" Name="LiJi1" Sizes="0,0.5,1,2,5,30,100" Version="1.1.1" />
+<XMLData FileMark="626" Name="LiJi1" Sizes="0,3,5,10,20,30,50" Version="1.1.1" />

+ 2 - 2
OTSCPP/OTSControl/Bruker/OTSBrukerImpl.cpp

@@ -3021,9 +3021,9 @@ BOOL COTSBrukerImpl::SetXRayPoints(CPosXraysList& a_listXrayPois, const DWORD a_
 		a_listXrayPois[i]->SetXrayData(nChannelData);
 
 		std::vector<CString> eleList;
-		for (size_t i = 0; i < a_listXrayPois[i]->GetElementQuantifyData().size(); i++)
+		for each (CElementChemistryPtr var in a_listXrayPois[i]->GetElementQuantifyData())
 		{
-			eleList.push_back(a_listXrayPois[i]->GetElementQuantifyData()[i]->GetName());
+			eleList.push_back(var->GetName());
 		}
 		bool isFilter = true;
 		if (eleList.size() != 0)

+ 2 - 2
OTSCPP/OTSControl/Simulate/OTSEDSSim.cpp

@@ -142,9 +142,9 @@ namespace OTSController {
 		for (auto pXrayPoi : a_vXRayPoints)
 		{
 			std::vector<CString> eleList;
-			for (size_t i = 0; i < pXrayPoi->GetElementQuantifyData().size(); i++)
+			for each (CElementChemistryPtr var in pXrayPoi->GetElementQuantifyData())
 			{
-				eleList.push_back(pXrayPoi->GetElementQuantifyData()[i]->GetName());
+				eleList.push_back(var->GetName());
 			}
 			bool isFilter = true;
 			if (eleList.size() != 0)

+ 2 - 0
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CMeasure.cs

@@ -610,6 +610,8 @@ namespace OTSModelSharp
             poMsrParams.SetImageScanParam(poImageScanParam);
             pHoleSample.SetMsrParams(poMsrParams);
 
+            poMsrParams.GetImageProcessParam().SetOverlapParam(GetListMeasurableSamples()[0].GetMsrParams().GetImageProcessParam().GetOverlapParam());
+
             return pHoleSample;
         }
 

+ 8 - 2
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CSmplMeasure.cs

@@ -856,12 +856,18 @@ namespace OTSModelSharp
         {
             COTSSample theSample = m_Sample;
             var pStatus = theSample.GetMsrStatus();
-            //merging particles
-            log.Info("Merging big particles which are crossing the field edge!");
+            
             CImageHandler imgpro = new CImageHandler();
             int scanfldsize = theSample.GetSEMDataMsr().GetScanFieldSize();
             List<COTSParticleClr> mergedParticles = new List<COTSParticleClr>();
             double pixelSize = theSample.CalculatePixelSize();
+            //Repeated particle treatment
+            if (theSample.GetMsrParams().GetImageProcessParam().GetPartCombin())
+            {
+                imgpro.RepeatedParticleTreatment(theSample.GetFieldsData(), theSample, m_pSampleRstFile.m_strdbPathName);
+            }
+            //merging particles
+            log.Info("Merging big particles which are crossing the field edge!");
             imgpro.MergeBigBoundaryParticles(theSample.GetFieldsData(), pixelSize, scanfldsize, theSample.GetResolutionSize(), ref mergedParticles);
 
             CalculateMergedPartProperty(mergedParticles, pixelSize);

+ 1 - 1
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CSmplMsrResult.cs

@@ -28,7 +28,7 @@ namespace OTSModelSharp
 
         // pathname
         string m_strRstFileName;
-        string m_strdbPathName;
+        public string m_strdbPathName;
 
         CIncAFileMgr m_DBFileMgr ;
  

+ 15 - 6
OTSIncAMeasureApp/0-OTSModel/OTSDataType/COTSImageProcParam.cs

@@ -24,6 +24,7 @@ namespace OTSDataType
         private OTS_AUTOBGREMOVE_TYPE m_autoBGRemoveType;
         int m_errodDilateParam;
         int m_OverlapParam;
+        bool m_partCombin;
 
         private CSpecialGrayRangeParam m_specialGreyRangeParam;
 
@@ -48,6 +49,7 @@ namespace OTSDataType
             m_autoBGRemoveType = OTS_AUTOBGREMOVE_TYPE.MIDDLE;
             m_errodDilateParam = 3;
             m_OverlapParam = 20;
+            m_partCombin = false;
         }
         public CDoubleRange GetIncAreaRange() { return m_oIncArea; }
         public void SetIncAreaRange(CDoubleRange a_oVal) { m_oIncArea = a_oVal; }
@@ -74,6 +76,10 @@ namespace OTSDataType
 
         public void SetOverlapParam(int a_oVal) { m_OverlapParam = a_oVal; }
 
+        public bool GetPartCombin() { return m_partCombin; }
+
+        public void SetPartCombin(bool a_oVal) { m_partCombin = a_oVal; }
+
 
         public void Duplicate(COTSImageProcParam a_oSource)
         {
@@ -90,19 +96,17 @@ namespace OTSDataType
             m_autoBGRemoveType = a_oSource.m_autoBGRemoveType;
             m_errodDilateParam = a_oSource.m_errodDilateParam;
             m_OverlapParam = a_oSource.m_OverlapParam;
-
-
+            m_partCombin = a_oSource.m_partCombin;
         }
         public bool Equals(COTSImageProcParam a_oSource)
         {
-
             // return test result
             return m_oIncArea == a_oSource.m_oIncArea &&
                 m_oBGGray == a_oSource.m_oBGGray &&
                 m_oParticleGray == a_oSource.m_oParticleGray &&
-                m_errodDilateParam == a_oSource.m_errodDilateParam&&
-                m_OverlapParam == a_oSource.m_OverlapParam;
-
+                m_errodDilateParam == a_oSource.m_errodDilateParam &&
+                m_OverlapParam == a_oSource.m_OverlapParam &&
+                m_partCombin == a_oSource.m_partCombin;
         }
 
 
@@ -123,6 +127,9 @@ namespace OTSDataType
             xInt xnOverlapParam = new xInt();
             slo.Register("OverlapParam", xnOverlapParam);
 
+            xBool xnPartCombin = new xBool();
+            slo.Register("PartCombin", xnPartCombin);
+
             xString xnBGRemoveType = new xString();
             xString xnautoBGRemoveType = new xString();
 
@@ -136,6 +143,7 @@ namespace OTSDataType
                 xnautoBGRemoveType.AssignValue((int)m_autoBGRemoveType+":"+m_autoBGRemoveType.ToString());
                 xnCorrosionExpansionCoefficient.AssignValue(m_errodDilateParam);
                 xnOverlapParam.AssignValue(m_OverlapParam);
+                xnPartCombin.AssignValue(m_partCombin);
                 slo.Serialize(true, classDoc, rootNode);
             }
             else
@@ -146,6 +154,7 @@ namespace OTSDataType
                 m_autoBGRemoveType = (OTS_AUTOBGREMOVE_TYPE)Convert.ToInt32( xnautoBGRemoveType.value().Split(':')[0]);
                 m_errodDilateParam = Convert.ToInt32(xnCorrosionExpansionCoefficient.value());
                 m_OverlapParam = Convert.ToInt32(xnOverlapParam.value());
+                m_partCombin = Convert.ToBoolean(xnPartCombin.value());
             }
         }
     }

+ 4 - 0
OTSIncAMeasureApp/7-OTSProgMgrInfo/ProgMgrInfoForm.cs

@@ -595,6 +595,8 @@ namespace OTSMeasureApp
             IDC_COMBO_CorrosionExpansionCoefficient.Text = m_cotsimgprocprm.GetErrodDilateParam().ToString();
             //重叠尺寸
             IDC_EDIT_Overlap.Text = m_cotsimgprocprm.GetOverlapParam().ToString();
+            //边界颗粒合并
+            IDC_COMBIN.Checked = m_cotsimgprocprm.GetPartCombin();
 
             //去背景方式
             foreach (ComboBoxItem cbi in IDC_COMBO_BGREMOVETYPE.Items)
@@ -821,6 +823,8 @@ namespace OTSMeasureApp
             m_cotsimgprocprm.SetErrodDilateParam(Convert.ToInt32(IDC_COMBO_CorrosionExpansionCoefficient.Text));
             //重叠像素
             m_cotsimgprocprm.SetOverlapParam(Convert.ToInt32(IDC_EDIT_Overlap.Text));
+            //边界颗粒合并
+            m_cotsimgprocprm.SetPartCombin(IDC_COMBIN.Checked);
         }
 
         /// <summary>

+ 44 - 18
OTSIncAMeasureApp/7-OTSProgMgrInfo/ProgMgrInfoForm.designer.cs

@@ -126,7 +126,9 @@
             this.IDC_BACK_MAX_SWITCH = new System.Windows.Forms.CheckBox();
             this.IDC_PART_MAX_SWITCH = new System.Windows.Forms.CheckBox();
             this.groupBox6 = new System.Windows.Forms.GroupBox();
+            this.IDC_FILTER = new System.Windows.Forms.CheckBox();
             this.IDC_EDIT_XrayLimit = new System.Windows.Forms.TextBox();
+            this.label52 = new System.Windows.Forms.Label();
             this.label47 = new System.Windows.Forms.Label();
             this.IDC_EDIT_SmallPartAQTime = new System.Windows.Forms.TextBox();
             this.label45 = new System.Windows.Forms.Label();
@@ -161,8 +163,8 @@
             this.groupBox7 = new System.Windows.Forms.GroupBox();
             this.IDC_EDIT_STOP_INCA_AREA = new System.Windows.Forms.TextBox();
             this.label48 = new System.Windows.Forms.Label();
-            this.label52 = new System.Windows.Forms.Label();
-            this.IDC_FILTER = new System.Windows.Forms.CheckBox();
+            this.label53 = new System.Windows.Forms.Label();
+            this.IDC_COMBIN = new System.Windows.Forms.CheckBox();
             this.groupBox1.SuspendLayout();
             this.groupBox2.SuspendLayout();
             this.groupBox3.SuspendLayout();
@@ -924,6 +926,8 @@
             // 
             // groupBox5
             // 
+            this.groupBox5.Controls.Add(this.IDC_COMBIN);
+            this.groupBox5.Controls.Add(this.label53);
             this.groupBox5.Controls.Add(this.IDC_COMBO_CorrosionExpansionCoefficient);
             this.groupBox5.Controls.Add(this.label50);
             this.groupBox5.Controls.Add(this.IDC_EDIT_Overlap);
@@ -1304,6 +1308,16 @@
             this.groupBox6.TabStop = false;
             this.groupBox6.Text = "X-ray参数";
             // 
+            // IDC_FILTER
+            // 
+            this.IDC_FILTER.AutoSize = true;
+            this.IDC_FILTER.Location = new System.Drawing.Point(276, 189);
+            this.IDC_FILTER.Margin = new System.Windows.Forms.Padding(2);
+            this.IDC_FILTER.Name = "IDC_FILTER";
+            this.IDC_FILTER.Size = new System.Drawing.Size(15, 14);
+            this.IDC_FILTER.TabIndex = 835;
+            this.IDC_FILTER.UseVisualStyleBackColor = true;
+            // 
             // IDC_EDIT_XrayLimit
             // 
             this.IDC_EDIT_XrayLimit.Location = new System.Drawing.Point(141, 162);
@@ -1313,6 +1327,16 @@
             this.IDC_EDIT_XrayLimit.Size = new System.Drawing.Size(150, 21);
             this.IDC_EDIT_XrayLimit.TabIndex = 834;
             // 
+            // label52
+            // 
+            this.label52.AutoSize = true;
+            this.label52.Location = new System.Drawing.Point(9, 189);
+            this.label52.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.label52.Name = "label52";
+            this.label52.Size = new System.Drawing.Size(77, 12);
+            this.label52.TabIndex = 833;
+            this.label52.Text = "是否启动过滤";
+            // 
             // label47
             // 
             this.label47.AutoSize = true;
@@ -1655,25 +1679,25 @@
             this.label48.Text = "终止测量面积";
             this.label48.Visible = false;
             // 
-            // label52
+            // label53
             // 
-            this.label52.AutoSize = true;
-            this.label52.Location = new System.Drawing.Point(9, 189);
-            this.label52.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
-            this.label52.Name = "label52";
-            this.label52.Size = new System.Drawing.Size(77, 12);
-            this.label52.TabIndex = 833;
-            this.label52.Text = "是否启动过滤";
+            this.label53.AutoSize = true;
+            this.label53.Location = new System.Drawing.Point(6, 208);
+            this.label53.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.label53.Name = "label53";
+            this.label53.Size = new System.Drawing.Size(77, 12);
+            this.label53.TabIndex = 833;
+            this.label53.Text = "边界颗粒合并";
             // 
-            // IDC_FILTER
+            // IDC_COMBIN
             // 
-            this.IDC_FILTER.AutoSize = true;
-            this.IDC_FILTER.Location = new System.Drawing.Point(276, 189);
-            this.IDC_FILTER.Margin = new System.Windows.Forms.Padding(2);
-            this.IDC_FILTER.Name = "IDC_FILTER";
-            this.IDC_FILTER.Size = new System.Drawing.Size(15, 14);
-            this.IDC_FILTER.TabIndex = 835;
-            this.IDC_FILTER.UseVisualStyleBackColor = true;
+            this.IDC_COMBIN.AutoSize = true;
+            this.IDC_COMBIN.Location = new System.Drawing.Point(272, 208);
+            this.IDC_COMBIN.Margin = new System.Windows.Forms.Padding(2);
+            this.IDC_COMBIN.Name = "IDC_COMBIN";
+            this.IDC_COMBIN.Size = new System.Drawing.Size(15, 14);
+            this.IDC_COMBIN.TabIndex = 836;
+            this.IDC_COMBIN.UseVisualStyleBackColor = true;
             // 
             // ProgMgrInfoForm
             // 
@@ -1879,5 +1903,7 @@
         public System.Windows.Forms.TextBox IDC_EDIT_Overlap;
         private System.Windows.Forms.Label label52;
         public System.Windows.Forms.CheckBox IDC_FILTER;
+        private System.Windows.Forms.Label label53;
+        public System.Windows.Forms.CheckBox IDC_COMBIN;
     }
 }

+ 244 - 0
OTSIncAMeasureApp/ServiceCenter/CImageHandler.cs

@@ -13,6 +13,7 @@ namespace OTSModelSharp.ServiceInterface
     using OpenCvSharp;
     using OTSCLRINTERFACE;
     using OTSIMGPROC;
+    using OTSModelSharp.DTLBase;
     using System.Drawing.Imaging;
     using System.Runtime.InteropServices;
     using System.Windows;
@@ -386,5 +387,248 @@ namespace OTSModelSharp.ServiceInterface
             return points;
         }
 
+        public bool RepeatedParticleTreatment(List<COTSFieldData> allFields, COTSSample theSample, string stdPath)
+        {
+            int maxPartCount = theSample.GetMsrParams().GetXRayParam().GetXrayLimit();
+            int overlap = theSample.GetMsrParams().GetImageProcessParam().GetOverlapParam();
+            double pixelSize = theSample.CalculatePixelSize();
+            System.Drawing.Size resolutionSize = theSample.GetResolutionSize();
+            int scanFieldSizeX = theSample.GetSEMDataMsr().GetScanFieldSize();
+            int scanFieldSizeY = scanFieldSizeX * resolutionSize.Height / resolutionSize.Width;
+            int offsetX = scanFieldSizeX - (int)(2 * overlap * pixelSize);
+            int offsetY = scanFieldSizeY - (int)(2 * overlap * pixelSize);
+            List<COTSParticleClr> deletePartList = new List<COTSParticleClr>();
+            List<COTSParticleClr> updatePartList = new List<COTSParticleClr>();
+
+            foreach (var item in allFields)
+            {
+                if (!item.GetIsMeasureComplete())
+                {
+                    break;
+                }
+                //找到上下左右四帧图
+                List<COTSFieldData> leftField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X - offsetX, item.OTSPos.Y)).ToList();
+                List<COTSFieldData> rightField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X + offsetX, item.OTSPos.Y)).ToList();
+                List<COTSFieldData> upField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X, item.OTSPos.Y + offsetY)).ToList();
+                List<COTSFieldData> downField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X, item.OTSPos.Y - offsetY)).ToList();
+                //判断是否有效
+                if (leftField.Count() == 1)//包含左帧图
+                {
+                    if (leftField[0].GetIsMeasureComplete() == true)//存在测量帧图
+                    {
+                        //寻找重叠颗粒
+                        deletePartList.AddRange(FieldFun(leftField[0], item, "left_right", resolutionSize, overlap));
+                    }
+                }
+                if (rightField.Count() == 1)//包含右帧图
+                {
+                    if (rightField[0].GetIsMeasureComplete() == true)//存在测量帧图
+                    {
+                        //寻找重叠颗粒
+                        deletePartList.AddRange(FieldFun(item, rightField[0], "left_right", resolutionSize, overlap));
+                    }
+                }
+                if (upField.Count() == 1)//包含上帧图
+                {
+                    if (upField[0].GetIsMeasureComplete() == true)//存在测量帧图
+                    {
+                        //寻找重叠颗粒
+                        deletePartList.AddRange(FieldFun(upField[0], item, "up_down", resolutionSize, overlap));
+                    }
+                }
+                if (downField.Count() == 1)//包含下帧图
+                {
+                    if (downField[0].GetIsMeasureComplete() == true)//存在测量帧图
+                    {
+                        //寻找重叠颗粒
+                        deletePartList.AddRange(FieldFun(item, downField[0], "up_down", resolutionSize, overlap));
+                    }
+                }
+            }
+
+            //数据库操作
+            SQLiteHelper sQLiteHelper = new SQLiteHelper(stdPath);
+            sQLiteHelper.GetDBConnection();
+            sQLiteHelper.BeginTransaction();
+
+            deletePartList = deletePartList.Distinct().ToList();//去重
+
+            if (!sQLiteHelper.DeletePartForTransaction(deletePartList))
+            {
+                return false;
+            }
+
+            sQLiteHelper.CommitTransaction();
+
+            return true;
+        }
+
+        private List<COTSParticleClr> FieldFun(COTSFieldData left_upField, COTSFieldData right_downField, string style, System.Drawing.Size resolutionSize, int overlap)
+        {
+            List<COTSParticleClr> particleClrs = new List<COTSParticleClr>();
+            if (style == "left_right")
+            {
+                //寻找左帧图的右侧区域颗粒
+                foreach (var leftParticles in left_upField.GetListAnalysisParticles())
+                {
+                    Rectangle leftRectangle = (Rectangle)leftParticles.GetParticleRect();
+                    if (leftRectangle.Right > resolutionSize.Width - overlap)//颗粒在左帧图的右侧重叠区域
+                    {
+                        particleClrs.Add(leftParticles);
+                    }
+                }
+                //寻找当前帧图的左侧区域颗粒
+                foreach (var centerParticles in right_downField.GetListAnalysisParticles())
+                {
+                    Rectangle centerRectangle = (Rectangle)centerParticles.GetParticleRect();
+                    if (centerRectangle.Left < overlap)//左侧颗粒在当前帧图的左侧重叠区域
+                    {
+                        particleClrs.Add(centerParticles);
+                    }
+                }
+            }
+            else
+            {
+                //寻找上帧图的下侧区域颗粒
+                foreach (var upParticles in left_upField.GetListAnalysisParticles())
+                {
+                    Rectangle upRectangle = (Rectangle)upParticles.GetParticleRect();
+                    if (upRectangle.Bottom > resolutionSize.Height - overlap)//颗粒在左帧图的右侧重叠区域
+                    {
+                        particleClrs.Add(upParticles);
+                    }
+                }
+                //寻找当前帧图的上侧区域颗粒
+                foreach (var downParticles in right_downField.GetListAnalysisParticles())
+                {
+                    Rectangle downRectangle = (Rectangle)downParticles.GetParticleRect();
+                    if (downRectangle.Top < overlap)//左侧颗粒在当前帧图的左侧重叠区域
+                    {
+                        particleClrs.Add(downParticles);
+                    }
+                }
+            }
+
+            return particleClrs;
+        }
+
+        private void CombinFun(Dictionary<COTSParticleClr, COTSParticleClr> combin, string style, System.Drawing.Size resolutionSize, int overlap, ref List<COTSParticleClr> deletePartList, ref List<COTSParticleClr> updatePartList)
+        {
+            foreach (var item in combin)
+            {
+                Rectangle left_topRectangle = (Rectangle)item.Key.GetParticleRect();
+                Rectangle right_bottomRectangle = (Rectangle)item.Value.GetParticleRect();
+
+                //左颗粒:跨右边界 右颗粒:跨左边界 
+                if (style == "left_right")
+                {
+                    if (left_topRectangle.Right == resolutionSize.Width - 1 && right_bottomRectangle.Left == 0)
+                    {
+                        int offset = right_bottomRectangle.Y - left_topRectangle.Y;
+                        if (item.Key.GetActualArea() > item.Value.GetActualArea())
+                        {
+                            Rectangle rectangle = new Rectangle(right_bottomRectangle.X, left_topRectangle.Y, right_bottomRectangle.Width, right_bottomRectangle.Height);
+                            item.Value.SetParticleRect(rectangle);
+                            COTSFeatureClr featureClr = item.Value.GetFeature();
+                            List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
+                            foreach (var Segment in segmentClrs)
+                            {
+                                Segment.SetHeight(Segment.GetHeight() - offset);
+                            }
+                            if (!updatePartList.Contains(item.Value))
+                            {
+                                updatePartList.Add(item.Value);
+                            }
+                        }
+                        else
+                        {
+                            Rectangle rectangle = new Rectangle(left_topRectangle.X, right_bottomRectangle.Y, left_topRectangle.Width, left_topRectangle.Height);
+                            item.Key.SetParticleRect(rectangle);
+                            COTSFeatureClr featureClr = item.Key.GetFeature();
+                            List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
+                            foreach (var Segment in segmentClrs)
+                            {
+                                Segment.SetHeight(Segment.GetHeight() + offset);
+                            }
+                            if (!updatePartList.Contains(item.Key))
+                            {
+                                updatePartList.Add(item.Key);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        if (item.Key.GetActualArea() > item.Value.GetActualArea())
+                        {
+                            if (!deletePartList.Contains(item.Value))
+                            {
+                                deletePartList.Add(item.Value);
+                            }
+                        }
+                        else
+                        {
+                            if (!deletePartList.Contains(item.Key))
+                            {
+                                deletePartList.Add(item.Key);
+                            }
+                        }
+                    }
+                }
+                else
+                {
+                    if (left_topRectangle.Bottom == resolutionSize.Height - 1 && right_bottomRectangle.Top == 0)
+                    {
+                        int offset = left_topRectangle.X - right_bottomRectangle.X;
+                        if (item.Key.GetActualArea() > item.Value.GetActualArea())
+                        {
+                            Rectangle rectangle = new Rectangle(left_topRectangle.X, right_bottomRectangle.Y, right_bottomRectangle.Width, right_bottomRectangle.Height);
+                            item.Value.SetParticleRect(rectangle);
+                            COTSFeatureClr featureClr = item.Value.GetFeature();
+                            List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
+                            foreach (var Segment in segmentClrs)
+                            {
+                                Segment.SetStart(Segment.GetStart() + offset);
+                            }
+                            if (!updatePartList.Contains(item.Value))
+                            {
+                                updatePartList.Add(item.Value);
+                            }
+                        }
+                        else
+                        {
+                            Rectangle rectangle = new Rectangle(right_bottomRectangle.X, left_topRectangle.Y, left_topRectangle.Width, left_topRectangle.Height);
+                            item.Key.SetParticleRect(rectangle);
+                            COTSFeatureClr featureClr = item.Key.GetFeature();
+                            List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
+                            foreach (var Segment in segmentClrs)
+                            {
+                                Segment.SetStart(Segment.GetStart() - offset);
+                            }
+                            if (!updatePartList.Contains(item.Key))
+                            {
+                                updatePartList.Add(item.Key);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        if (item.Key.GetActualArea() > item.Value.GetActualArea())
+                        {
+                            if (!deletePartList.Contains(item.Value))
+                            {
+                                deletePartList.Add(item.Value);
+                            }
+                        }
+                        else
+                        {
+                            if (!deletePartList.Contains(item.Key))
+                            {
+                                deletePartList.Add(item.Key);
+                            }
+                        }
+                    }
+                }
+            }
+        }
     }
 }

+ 36 - 7
OTSIncAMeasureApp/ServiceCenter/DTLBase/SQliteHelper.cs

@@ -1,9 +1,11 @@
-using OTSCommon.Model;
+using OTSCLRINTERFACE;
+using OTSCommon.Model;
 using OTSModelSharp.DTLBase;
 using System;
 using System.Collections.Generic;
 using System.Data;
 using System.Data.SQLite;
+using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -209,6 +211,27 @@ namespace OTSModelSharp.DTLBase
             return true;
         }
 
+        /// <summary>
+        /// 删除颗粒信息
+        /// </summary>
+        /// <param name="XrayId"></param>
+        /// <param name="FieldId"></param>
+        /// <param name="SegmentList"></param>
+        /// <returns></returns>
+        public bool DeletePartForTransaction(List<COTSParticleClr> deletePartList)
+        {
+            foreach (var item in deletePartList)
+            {
+                cmdForTrans.CommandText = "DELETE FROM IncAData WHERE FieldId = " + item.GetFieldId() + " AND XrayId = " + item.GetAnalysisId() + "";
+                if (cmdForTrans.ExecuteNonQuery() == 0)
+                {
+                    return false;
+                }
+            }
+
+            return true;
+        }
+
         /// <summary>
         /// 修改segment信息
         /// </summary>
@@ -216,18 +239,24 @@ namespace OTSModelSharp.DTLBase
         /// <param name="FieldId"></param>
         /// <param name="SegmentList"></param>
         /// <returns></returns>
-        public bool ExecuteSegmentForTransaction(int XrayId, int FieldId, List<Segment> SegmentList)
+        public bool UpdatePartForTransaction(List<COTSParticleClr> updatePartList)
         {
-            cmdForTrans.CommandText = "DELETE FROM Segment WHERE XRayId = " + XrayId + " AND FieldId = " + FieldId + "";
-            for (int i = 0; i < SegmentList.Count; i++)
+            foreach (var PartList in updatePartList)
             {
-                cmdForTrans.CommandText = "INSERT INTO Segment(XrayID, FieldID, SegmentId, SegmentNum, Start, Height, Length, ParticleId) VALUES ('"
-                    + XrayId + "','" + FieldId + "','" + i + "','" + SegmentList[0].SegmentNum + "','"
-                    + SegmentList[i].Start + "','" + SegmentList[i].Height + "','" + SegmentList[i].Length + "','" + SegmentList[i].ParticleId + "')";
+                Rectangle leftRectangle = (Rectangle)PartList.GetParticleRect();
+                cmdForTrans.CommandText = "UPDATE IncAData SET RectLeft = " + leftRectangle.Left + ", RectTop = '" + leftRectangle.Top + "' WHERE XrayId = " + PartList.GetAnalysisId() + " and FieldId = " + PartList.GetFieldId() + "";
                 if (cmdForTrans.ExecuteNonQuery() == 0)
                 {
                     return false;
                 }
+                foreach (var SegmentsList in PartList.GetFeature().GetSegmentsList())
+                {
+                    cmdForTrans.CommandText = "UPDATE Segment SET Start = " + SegmentsList.GetStart() + ", Height = '" + SegmentsList.GetHeight() + "' WHERE XrayId = " + PartList.GetAnalysisId() + " and FieldId = " + PartList.GetFieldId() + "";
+                    if (cmdForTrans.ExecuteNonQuery() == 0)
+                    {
+                        return false;
+                    }
+                }
             }
 
             return true;