c# netdxf solidworks 出dxf

        public void 出dxf()
        {
            Vector3 translation; Matrix4 translationMatrix;
            ModelDoc2 swModel = (ModelDoc2)this.sldWorks.ActiveDoc;
            PartDoc swPart = (PartDoc)swModel;
            //swModel.Extension.SelectByID2(this.展开用featurename, "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            // swModel.EditUnsuppress2();
            bool 要打点 = false;
            double[] dataAlignment = new double[12];
            dataAlignment[0] = 0.0;
            dataAlignment[1] = 0.0;
            dataAlignment[2] = 0.0;
            dataAlignment[3] = 1.0;
            dataAlignment[4] = 0.0;
            dataAlignment[5] = 0.0;
            dataAlignment[6] = 0.0;
            dataAlignment[7] = 1.0;
            dataAlignment[8] = 0.0;
            dataAlignment[9] = 1.0;
            dataAlignment[10] = 0.0;
            dataAlignment[11] = 0.0;
            int options; options = 97;
            // swPart.ExportToDWG(this.dxf, this.prt, (int)swExportToDWG_e.swExportToDWG_ExportSheetMetal, true, dataAlignment, false, false, options, null)
           
            if (!swPart.ExportFlatPatternView(this.dxf, 1))
                { Debug.Print("无法导出");
                return;
            }
           
          
              
          
            DxfDocument doc = DxfDocument.Load(this.dxf);
            var viewport = doc.Viewport;
            viewport.ShowGrid=false;
            DrawingEntities drawingEntitie = doc.Entities;

            沉孔实例[] 沉孔类型s = this.沉孔.ToArray();
            攻牙实例[] 攻牙类型s = this.攻牙.ToArray();
            压铆实例[] 压铆类型s = this.压铆.ToArray();
           

            //List<(double, double)> 工作圆心集 = 沉孔类型s.Select(item=>(item.沉孔坐标1, item.沉孔坐标2)).ToList();
            //工作圆心集.AddRange(攻牙类型s.Select(item => (item.攻牙坐标1, item.攻牙坐标2)).ToList());
            //工作圆心集.AddRange(压铆类型s.Select(item => (item.压铆坐标1, item.压铆坐标2)).ToList());

            var toRemove = new List<EntityObject>();
            List<(double, double)> 圆心集 = new List<(double, double)>();
           
            bool 是否转90度 = false;
            foreach (var entity in drawingEntitie.All)
            {

                if (entity is netDxf.Entities.Circle circle)
                {
                    圆心集.Add((Math.Round(circle.Center.X, 2), Math.Round(circle.Center.Y, 2)));

                }
            }


            System.Collections.Generic.HashSet<(double, double)> uniqueNumbers = new System.Collections.Generic.HashSet<(double, double)>(圆心集);
            List<double> xs = uniqueNumbers.Select(item => item.Item1).ToList();
            List<double> ys = uniqueNumbers.Select(item => item.Item2).ToList();

            List<EntityObject> entitylist = new List<EntityObject>();
            List<EntityObject> entitylist2 = new List<EntityObject>();
            List<EntityObject> entitylist3 = new List<EntityObject>();
            List<EntityObject> entitylist4 = new List<EntityObject>();
            if (xs.Count+ys.Count != 0)
            {

                double xsAverage = xs.Average();
                double ysAverage = ys.Average();

                double xs差和 = Math.Round(xs.Select(item => Math.Abs(item - xsAverage)).ToList().Sum());
                double ys差和 = Math.Round(ys.Select(item => Math.Abs(item - ysAverage)).ToList().Sum());
                List<(double, double)> 圆心集2 = new List<(double, double)>();

                是否转90度 = !(xs差和 > ys差和 && this.差和.Item1 > this.差和.Item2 || xs差和 < ys差和 && this.差和.Item1 < this.差和.Item2 || xs差和 == ys差和 && this.差和.Item1 == this.差和.Item2);
                Debug.WriteLine("是否转90度:" + 是否转90度 + "\n" +
                "xs差和:" + xs差和 + "---" + "ys差和:" + ys差和 + "\n" +
                 "this.差和.Item1:" + this.差和.Item1 + "---" + "this.差和.Item2:" + this.差和.Item2);

                Matrix4 rotateMatrix = Matrix4.RotationZ(-1.5707963267948966);

                //---------------------------------------------------------------------------------

                foreach (var entity in drawingEntitie.All)
                {
                    EntityObject cloneentity = (EntityObject)entity.Clone();
                    cloneentity.Color = AciColor.Cyan;
                    entitylist.Add(cloneentity);
                    if (是否转90度)
                    {
                        entity.TransformBy(rotateMatrix);
                    }

                }


                //---------------------------------------------------------------------------------
                foreach (var entity in drawingEntitie.All)
                {

                    if (entity is Circle circle)
                    {

                        圆心集2.Add((Math.Round(circle.Center.X, 2), Math.Round(circle.Center.Y, 2)));

                    }
                }
                圆心集2 = 圆心集2.OrderBy(item => Math.Round(item.Item1, 2)).ToList();
                圆心集2 = 圆心集2.OrderBy(item => Math.Round(item.Item2, 2)).ToList();

                System.Collections.Generic.HashSet<(double, double)> uniqueCenters = new System.Collections.Generic.HashSet<(double, double)>(圆心集2);
                List<double> xs2 = uniqueCenters.Select(item => item.Item1).ToList();
                List<double> ys2 = uniqueCenters.Select(item => item.Item2).ToList();
                double xsAverage2 = xs2.Average();
                double ysAverage2 = ys2.Average();
                List<double> x右侧集 = new List<double>();
                List<double> x左侧集 = new List<double>();
                x右侧集 = xs2.Where(item => Math.Round(item - xsAverage2,1) > 0).Select(item =>
                {

                    return Math.Round(item - xsAverage2,1);
                }).ToList();
              
                 x左侧集 = xs2.Where(item => Math.Round(item - xsAverage2,1) < 0).Select(item =>
                {

                    return Math.Round(xsAverage2 - item,1);
                }).ToList(); ;
                List<double> y上侧集 = new List<double>();
                List<double> y下侧集 = new List<double>();
                 y上侧集 = ys2.Where(item => Math.Round(item - ysAverage2,1) > 0).Select(item =>  Math.Round(item - ysAverage2,1)).ToList();
                 y下侧集 = ys2.Where(item => Math.Round(item - ysAverage2,1) < 0).Select(item => Math.Round(ysAverage2 - item,1)).ToList();
               
             
                var x右侧集Average = 0.0;
                var x左侧集Average = 0.0;
                List<double> x右右侧集 = new List<double>();
                List<double> x左左侧集 = new List<double>();
                double x右侧和 = 0;
                double x左侧和 = 0;
                if (x右侧集.Count > 0)
                {
                    Debug.WriteLine("x右侧集.Count:"+ x右侧集.Count);
                    x右侧集Average = x右侧集.Average();
                    x左侧集Average = x左侧集.Average();
                    x右右侧集 = x右侧集.Where(item => Math.Round(item - x右侧集Average, 1) > 0).Select(item => Math.Round(item - x右侧集Average, 1)).ToList();
                    x左左侧集 = x左侧集.Where(item => Math.Round(item - x左侧集Average, 1) < 0).Select(item => Math.Round(x左侧集Average - item, 1)).ToList();
                   if (x右右侧集.Count>0) x右侧和 = Math.Round(x右右侧集.Sum(), 2);
                    if (x左左侧集.Count > 0) x左侧和 = Math.Round(x左左侧集.Sum(), 2);
                }
                
                var y上侧集Average = 0.0;
                var y下侧集Average = 0.0;
                List<double> y上上侧集 = new List<double>();
                List<double> y下下侧集 = new List<double>();
                double y上侧和 = 0;
                double y下侧和 = 0;
              
                if (y上侧集.Count > 0)
                {
                   //.WriteLine("y上侧集.Count:"+ y上侧集.Count);
                    y上侧集Average = y上侧集.Average();
                    y下侧集Average = y下侧集.Average();
                   //.WriteLine($"{y上侧集Average},{y下侧集Average}");
                  
                    y上上侧集 = y上侧集.Where(item => Math.Round(item - y上侧集Average, 1) > 0).Select(item => Math.Round(item - y上侧集Average, 1)).ToList();
                    y下下侧集 = y下侧集.Where(item => Math.Round(item - y下侧集Average, 1) < 0).Select(item => Math.Round(y下侧集Average - item, 1)).ToList();

                    if (y上上侧集.Count > 0) y上侧和 = Math.Round(y上上侧集.Sum(), 2);
                    if (y下下侧集.Count > 0) y下侧和 = Math.Round(y下下侧集.Sum(), 2);
                }
               // .WriteLine($"{x右侧集.Count},{x左侧集.Count},{y上侧集.Count},{y下侧集.Count}");
              
                //
               
                (double, double, double, double) xy右左上下侧数 = (x右侧集.Count(), x左侧集.Count(), y上侧集.Count(), y下侧集.Count());

                bool x右侧和多 = Math.Round(x右侧和 - x左侧和, 2) > 0.1;
                bool y上侧和多 = Math.Round(y上侧和 - y下侧和, 2) > 0.1;
             
                bool x坐标轴是反向的 = false, y坐标轴是反向的 = false;
                if (this.x左右侧和相等)
                {
                    x坐标轴是反向的 = x右侧和多 == this.x右侧和多;
                }
                else
                {
                    x坐标轴是反向的 = xy右左上下侧数.Item1 > xy右左上下侧数.Item2
                        == this.xy右左上下侧数.Item1 > this.xy右左上下侧数.Item2;
                }

                if (this.y上下侧和相等)
                {
                    y坐标轴是反向的 = y上侧和多 == this.y上侧和多;
                }
                else
                {
                    y坐标轴是反向的 = xy右左上下侧数.Item3 > xy右左上下侧数.Item4
                       == this.xy右左上下侧数.Item3 > this.xy右左上下侧数.Item4;
                }


               
                Debug.WriteLine(

                    "x左右侧和相等:" + x左右侧和相等 + ",y上下侧和相等:" + y上下侧和相等
                 + "\n" + " x坐标轴是否反向:" + x坐标轴是反向的 + ",x右侧和多:" + x右侧和多 + ",x右侧和:" + x右侧和 + ",x左侧和:" + x左侧和 + "\n" +
                    ",this.x右侧和多:" + this.x右侧和多 + ",x右侧和:" + xy右左上下侧和.Item1 + ",x左侧和:" + xy右左上下侧和.Item2
                + "\n" + " y坐标轴是否反向:" + y坐标轴是反向的 + ",y上侧和多:" + y上侧和多 + ",y上侧和" + y上侧和 + ",y下侧和" + y下侧和 + "\n" +
                    ",this.y上侧和多:" + this.y上侧和多 + ",y上侧和" + xy右左上下侧和.Item3 + ",y下侧和" + xy右左上下侧和.Item4
                  + "\n" + "this. xsAverage:" + this.xsAverage + " this.ysAverage:" + this.ysAverage
                  + "\n" + " xsAverage:" + xsAverage2 + " ysAverage:" + ysAverage2
                  + "\n" + "this.xy右左上下侧数=" + string.Join(",", this.xy右左上下侧数)
                   + "\n" + "xy右左上下侧数=" + string.Join(",", xy右左上下侧数)
                  );

                Matrix4 rotateMatrix4 = Matrix4.RotationZ(Math.PI);

                //---------------------------------------------------------------------------------

                foreach (var entity in drawingEntitie.All)
                {
                    EntityObject cloneentity = (EntityObject)entity.Clone();
                    cloneentity.Color = AciColor.Cyan;
                    entitylist4.Add(cloneentity);
                    if (x坐标轴是反向的)
                    {
                        entity.TransformBy(rotateMatrix4);
                    }
                    if (y坐标轴是反向的)
                    {
                        entity.TransformBy(rotateMatrix4);
                    }

                }
                List<(double, double)> 圆心集3 = new List<(double, double)>();
                int roundnumber = 4;
                foreach (var entity in drawingEntitie.All)
                {

                    if (entity is Circle circle)
                    {

                        圆心集3.Add((Math.Round(circle.Center.X, roundnumber), Math.Round(circle.Center.Y, roundnumber)));

                    }
                }
                uniqueCenters = new System.Collections.Generic.HashSet<(double, double)>(圆心集3);

                var unique2 = 实例uniqueNumbers.ToList();
                unique2 = unique2.OrderBy(item => Math.Round(item.Item1, roundnumber)).ToList();
                unique2 = unique2.OrderBy(item => Math.Round(item.Item2, roundnumber)).ToList();
                var unique = uniqueCenters.ToList();

                Dictionary<(double, double), List<(double, double, double, double)>> 向量字典 = new Dictionary<(double, double), List<(double, double, double, double)>>();
                Dictionary<(double, double), List<( double, double)>> 匹配字典 = new Dictionary<(double, double), List<( double, double)>>();
                for (int i = 0; i < uniqueCenters.Count(); i++)
                {
                    var rowData = new Dictionary<string, object>();



                    int k = 0;
                    // 使用循环查找符合条件的向量2,同时确保不会数组越界
                    while (k < 实例uniqueNumbers.Count())
                    {

                        var vector2 = (Math.Round(unique[i].Item1 - unique2[k].Item1, roundnumber), Math.Round(unique[i].Item2 - unique2[k].Item2, roundnumber));
                        var 匹配vector2 = (Math.Round(unique[i].Item1 - unique2[k].Item1, 0), Math.Round(unique[i].Item2 - unique2[k].Item2, 0));
                        if (!向量字典.ContainsKey(vector2))
                            向量字典[vector2] = new List<(double, double, double, double)>();
                        向量字典[vector2].Add((unique[i].Item1, unique[i].Item2, unique2[k].Item1, unique2[k].Item2));
                        if (!匹配字典.ContainsKey(匹配vector2))
                            匹配字典[匹配vector2] = new List<( double, double)>();
                        匹配字典[匹配vector2].Add((unique2[k].Item1, unique2[k].Item2));
                        k++;

                    }



                }
                (double, double) 出现最多次的向量;
                double mostFrequentX, mostFrequentYInMostFrequentX;
                向量字典 = 向量字典.ToList().OrderByDescending(group => group.Value.Count()).ToDictionary(pair => pair.Key, pair => pair.Value);
                匹配字典= 匹配字典.ToList().OrderByDescending(group => group.Value.Count()).ToDictionary(pair => pair.Key, pair => pair.Value);
                mostFrequentX = 向量字典.ElementAt(0).Key.Item1;
                mostFrequentYInMostFrequentX = 向量字典.ElementAt(0).Key.Item2;
                var 位移终点list = 匹配字典.ElementAt(0).Value;
                Debug.WriteLine(" 位移终点list.count=" + 位移终点list.Count);
                出现最多次的向量.Item1 = mostFrequentX;
                出现最多次的向量.Item2 = mostFrequentYInMostFrequentX;
                List<Line> lines = new List<Line>();
                
                for (double j = 0; j < 向量字典.Count; j++)
                {

                    var 线段集 = 向量字典.ElementAt((int)j).Value;
                    double 增加数 = j / 向量字典.Count;

                    Console.WriteLine("增加数=" + 增加数 + ",线段集.count=" + 线段集.Count + ",j=" + j + ",向量字典.Count=" + 向量字典.Count + ",lines.count" + lines.Count);
                    foreach (var 线段 in 线段集)
                    {

                        Line line = new Line();
                        line.Color = AciColor.FromHsl(增加数, 0.9, 0.5);
                        line.StartPoint = new Vector3(线段.Item1, 线段.Item2, 0);
                        line.EndPoint = new Vector3(线段.Item3, 线段.Item4, 0);
                        lines.Add(line);
                        


                    }

                }

                //Process.Start(this.dxf);

                translation = new Vector3(-mostFrequentX, -mostFrequentYInMostFrequentX, 0);
                List<(double, double)> 圆心集4 = new List<(double, double)>();
                translationMatrix = Matrix4.Translation(translation);
                //-------------------------------------------------------------------------------------      

                foreach (var entity in drawingEntitie.All)
                {

                    EntityObject cloneentity = (EntityObject)entity.Clone();
                    cloneentity.Color = AciColor.Magenta;
                    entitylist2.Add(cloneentity);

                    entity.TransformBy(translationMatrix);
                    if (entity is netDxf.Entities.Circle circle)
                    {
                        
                            圆心集4.Add((Math.Round(circle.Center.X, roundnumber), Math.Round(circle.Center.Y, roundnumber)));
                       
                        
                    }


                }
                
                //------------------------------------------------------------------------------------- 
                System.Collections.Generic.HashSet<(double, double)> uniqueNumbers2 = new System.Collections.Generic.HashSet<(double, double)>(圆心集4);
                Debug.WriteLine(" uniqueNumbers2.count=" + uniqueNumbers2.Count);
                var uniqueavx = 位移终点list.Select(item => item.Item1).Average();
                var uniqueavy = 位移终点list.Select(item => item.Item2).Average();
                Debug.WriteLine("uniqueavx=" + uniqueavx + ",uniqueavy=" + uniqueavy);
                var transformations = new Func<(double, double), (double, double)>[]
            {
    x => (x.Item1, x.Item2),      // 不变
    x => (2*uniqueavx-x.Item1, x.Item2),    // 反转第一个元素
    x => (x.Item1, 2 * uniqueavy-x.Item2),    // 反转第二个元素
    x => (2*uniqueavx-x.Item1, 2*uniqueavy-x.Item2),    // 反转两个元素
  
            }; var transformationDescriptions = new string[] { "No change", "Invert first element", "Invert second element", "Invert both elements" };
                Dictionary<Func<(double, double), (double, double)>, string> funback = new Dictionary<Func<(double, double), (double, double)>, string>
                    { {transformations[0], transformationDescriptions[0]},
                {transformations[1], transformationDescriptions[1]},
                {transformations[2], transformationDescriptions[2]},
                {transformations[3], transformationDescriptions[3]},

                };
                // 定义一个浮点数比较的容差,用于处理浮点数的不精确性
                const double tolerance = 1;

                // 自定义相等判断,考虑浮点误差
                bool AreApproximatelyEqual((double, double) a, (double, double) b, string 变换名)
                {

                    bool areEqual = Math.Abs(a.Item1 - b.Item1) < tolerance && Math.Abs(a.Item2 - b.Item2) < tolerance;
                    if (areEqual)
                    {
                        Debug.WriteLine($"{变换名}-Match found: ({a.Item1}, {a.Item2}) ~ ({b.Item1}, {b.Item2})");
                    }
                    else
                    {
                        Console.WriteLine($"{变换名}-No match: ({a.Item1}, {a.Item2}) !== ({b.Item1}, {b.Item2})");
                    }
                    return areEqual;
                }

                List<(double, double)> filteredList = uniqueNumbers2.Where(x =>
           !uniqueNumbers2.Any(y => y.Item1 == 2 * uniqueavx - x.Item1 && y.Item2 == x.Item2)
       ).ToList();
                List<(double, double)> filteredList2 = uniqueNumbers2.Where(x =>
!filteredList.Any(y => y.Item1 == x.Item1 && y.Item2 == 2 * uniqueavy - x.Item2)
).ToList();
                List<(double, double)> filteredList合并 = filteredList.Concat(filteredList2).Distinct().ToList();
                Debug.WriteLine("工作圆心集.count:" + this.所有圆心集.Count + "----" + "filteredList合并.count:" + filteredList合并.Count);

                var allMatchesCounts = transformations
      .Select(transform => (
          Transform: transform,
          MatchCounts: this.所有圆心集.SelectMany(sourceItem =>

            filteredList合并.Select(transform).Select(targetItem =>
              {


                  var bestTransformationDescription = funback[transform];

                  return (SourceItem: sourceItem, TargetItem: targetItem, IsMatch: AreApproximatelyEqual(sourceItem, targetItem, bestTransformationDescription));
              }
                  )
              ).GroupBy(pair => pair.IsMatch)
              .ToDictionary(g => g.Key, g => g.Count())
      ))
      .ToList();

                // 现在allMatchesCounts包含了每个变换下匹配和不匹配的数量
                // 选取匹配数量最多的变换,注意需要从字典中提取出True对应的计数,即匹配的数量
                var bestMatch = allMatchesCounts.OrderByDescending(x =>

                getdictionarycount(x.MatchCounts))

                                               .FirstOrDefault();

                int getdictionarycount(Dictionary<bool, int> intdictionary)
                {
                    if (intdictionary.TryGetValue(true, out int dictionarycount))
                        return dictionarycount;
                    else return 0;
                }
                Func<string> returnMessage = () =>
                {
                    int matchCount = 0; object matchTransform = null;
                    string 输出值 = "不可能,绝对不可能";

                    bestMatch.MatchCounts.TryGetValue(true, out matchCount);
                    matchTransform = bestMatch.Transform;

                    if (matchTransform != null)
                    {

                        输出值 = funback[(Func<(double, double), (double, double)>)matchTransform];

                    }
                    Debug.WriteLine($"The best transformation is '{输出值}' which matches {matchCount} pairs.");
                    return 输出值;

                };



                string returnMessageResult1 = returnMessage();
                var translation2 = new Vector3(0, 0, 0);
                if (returnMessageResult1 == "Invert first element")
                {
                    Debug.WriteLine("translation:Invert first element,move:" + (-2 * uniqueavx));
                    translation2 = new Vector3(-2 * uniqueavx, 0, 0);
                }
                if (returnMessageResult1 == "Invert second element")
                {
                    translation2 = new Vector3(0, -2 * uniqueavy, 0);
                }
                if (returnMessageResult1 == "Invert both elements")
                {
                    translation2 = new Vector3(-2 * uniqueavx, -2 * uniqueavy, 0);
                }



                var translationMatrix2 = Matrix4.Translation(translation2);
                //-------------------------------------------------------------------------------------      

                foreach (var entity in drawingEntitie.All)
                {

                    entity.TransformBy(translationMatrix2);

                }
                List<(double, double, double, Circle)> 圆实例 = new List<(double, double, double, Circle)>();

                foreach (var entity in drawingEntitie.All)
                {
                    if (entity.Color != AciColor.Cyan && entity.Color != AciColor.Magenta)
                    {
                        if (entity is netDxf.Entities.Circle circle)
                        {
                            if (circle.Radius == 3.3 / 2) { circle.Radius = 3.4 / 2; }
                            if (circle.Radius == 3.5 / 2) { circle.Radius = 3.6 / 2; }
                            double 圆坐标1 = Math.Round(circle.Center.X, 2);
                            double 圆坐标2 = Math.Round(circle.Center.Y, 2);
                            if (returnMessageResult1 == "Invert first element")
                            {
                                圆坐标1 = -圆坐标1;
                            }
                            if (returnMessageResult1 == "Invert second element")
                            {
                                圆坐标2 = -圆坐标2;
                            }
                            if (returnMessageResult1 == "Invert both elements")
                            {
                                圆坐标1 = -圆坐标1;
                                圆坐标2 = -圆坐标2;
                            }
                            double 圆直径 = Math.Round(circle.Radius * 2, 1);
                            圆实例.Add((圆坐标1, 圆坐标2, 圆直径, circle));
                        }
                    }
                }

                bool 是沉孔面 = false;
                int 沉孔数 = 0;
                foreach (var 沉孔实例 in 沉孔类型s)
                {
                    foreach (var 圆 in 圆实例)
                    {
                        if (沉孔实例.沉孔坐标1 == 圆.Item1 && 沉孔实例.沉孔坐标2 == 圆.Item2)
                        {
                            if (圆.Item3 == 沉孔实例.小沉孔直径)
                            {
                                if (Math.Abs(圆.Item3 - 4.5)<0.1)
                                {
                                    沉孔数++;
                                    圆.Item4.Radius = 4.8 / 2;
                                }
                                else if (Math.Abs(圆.Item3 - 3.5) < 0.1)
                                {
                                    沉孔数++;
                                    圆.Item4.Radius = 3.8 / 2;
                                }
                                else if (Math.Abs(圆.Item3 - 5.5) < 0.1)
                                {
                                    沉孔数++;
                                    圆.Item4.Radius = 5.8 / 2;
                                }
                                圆.Item4.Color = AciColor.Green;
                            }
                            if (圆.Item3 == 沉孔实例.大沉孔直径) { toRemove.Add(圆.Item4); 是沉孔面 = true; }

                        }
                    }
                    Console.WriteLine("沉孔实例.沉孔坐标1:" + 沉孔实例.沉孔坐标1 + "沉孔实例.沉孔坐标2:" + 沉孔实例.沉孔坐标2);
                }
                if (沉孔数 != 0) showmsg.visable($"dxf有{沉孔数}个沉孔");
                var 蓝色 = AciColor.FromHsl(0.6, 0.9, 0.5);
                foreach (var 攻牙实例 in 攻牙类型s)
                {
                    foreach (var 圆 in 圆实例)
                    {
                        if (攻牙实例.攻牙坐标1 == 圆.Item1 && 攻牙实例.攻牙坐标2 == 圆.Item2)
                        {

                            圆.Item4.Color = 蓝色;
                        }
                        else { Console.WriteLine("攻牙坐标1=" + 攻牙实例.攻牙坐标1 + ",攻牙坐标2=" + 攻牙实例.攻牙坐标2 + "------圆坐标1=" + 圆.Item1 + ",圆坐标2=" + 圆.Item2); }
                    }
                }
                bool 是压铆面 = false; int 新增了几个孔 = 0; bool 不是压铆面 = false; int dxf压铆数 = 0;
                Debug.WriteLine("压铆实例数=" + 压铆类型s.Count());
        
                foreach (var 压铆实例 in 压铆类型s)
                {
                    bool 这个圆心有对应孔 = false;
                    Debug.WriteLine($"压铆坐标:{压铆实例.压铆坐标1},{压铆实例.压铆坐标2} 是焊接?{压铆实例.是焊接}");
                    var 橙色 = AciColor.FromHsl(0.1, 0.9, 0.5);
                    int rgbColor = 0xC71585;
                    int rgbColor2 = 0xFF7256;
                    int rgbColor3 = 0xFFDAB9;
                    int rgbColor4 = 0xDAA520;
                    foreach (var 圆 in 圆实例)
                    {

                        if (Math.Round(压铆实例.压铆坐标1 - 圆.Item1, 1) == 0 && Math.Round(压铆实例.压铆坐标2 - 圆.Item2, 1) == 0)
                        {

                            这个圆心有对应孔 = true;
                            if (压铆实例.压铆螺钉长度 != 0)
                            {
                                圆.Item4.Color = 橙色;
                                if (Math.Round(圆.Item3 - 3, 2) == 0 || Math.Round(圆.Item3 - 4, 2) == 0)
                                {
                                    圆.Item4.Radius = 2.4;
                                }
                                if (压铆实例.是焊接)
                                {
                                    圆.Item4.Radius = 0.5;
                                }
                                是压铆面 = true;
                                dxf压铆数++;

                            }
                            else if (压铆实例.压铆螺柱长度 != 0)
                            {
                                圆.Item4.Color = AciColor.FromTrueColor(rgbColor4);
                                if (圆.Item3 == 压铆实例.压铆原直径)
                                {

                                    Console.WriteLine("圆.Item3=" + 圆.Item3);
                                    圆.Item4.Radius = 常量.压铆螺柱映射字典[圆.Item3];
                                    if (压铆实例.是焊接)
                                    {
                                        圆.Item4.Radius = 0.5;
                                    }
                                }
                                else
                                {
                                    toRemove.Add(圆.Item4);
                                    dxf压铆数++;
                                    if (this.防涂孔圆心集.Any(item => item.Item1 == 圆.Item1 && item.Item2 == 圆.Item2))
                                    { }
                                    else { 是压铆面 = true; }
                                }
                            }
                            else
                            {

                                if (圆.Item3 == 压铆实例.压铆原直径)
                                {
                                    try {
                                    圆.Item4.Radius = 常量.压铆螺母映射字典[圆.Item3];
                                    }catch (Exception) {
                                        showmsg.visable("圆直径:"+圆.Item3);
                                    }
                                }
                                else
                                {
                                    dxf压铆数++;
                                    toRemove.Add(圆.Item4);
                                    if (this.防涂孔圆心集.Any(item => item.Item1 == 圆.Item1 && item.Item2 == 圆.Item2))
                                    { }
                                    else { 是压铆面 = true; }
                                }

                                if (圆.Item4.Radius == 2.1 && 压铆实例.是抽芽) { 圆.Item4.Radius = 0.75; 圆.Item4.Color = AciColor.FromTrueColor(rgbColor2); }
                                else if (圆.Item4.Radius == 2.7 && 压铆实例.是抽芽) { 圆.Item4.Radius = 1; 圆.Item4.Color = AciColor.FromTrueColor(rgbColor3); }
                                else if (圆.Item4.Radius == 2.1) { 圆.Item4.Color = AciColor.FromTrueColor(rgbColor); }
                                else if (圆.Item4.Radius == 2.7) { 圆.Item4.Color = AciColor.Cyan; }
                                else 圆.Item4.Color = AciColor.Red;
                            }

                        }
                        else { Console.WriteLine("压铆坐标1=" + 压铆实例.压铆坐标1 + ",压铆坐标2=" + 压铆实例.压铆坐标2 + "------圆坐标1=" + 圆.Item1 + ",圆坐标2=" + 圆.Item2); }
                    }
                    if (!这个圆心有对应孔)
                    {
                        不是压铆面 = true;
                        新增了几个孔++;
                        Circle circle = new Circle();
                        double 压铆坐标1 = 压铆实例.压铆坐标1;
                        double 压铆坐标2 = 压铆实例.压铆坐标2;

                        if (returnMessageResult1 == "Invert first element")
                        {
                            压铆坐标1 = -压铆坐标1;
                        }
                        if (returnMessageResult1 == "Invert second element")
                        {
                            压铆坐标2 = -压铆坐标2;
                        }
                        if (returnMessageResult1 == "Invert both elements")
                        {
                            压铆坐标1 = -压铆坐标1;
                            压铆坐标2 = -压铆坐标2;
                        }
                        if (压铆实例.压铆螺钉长度 != 0)
                        {
                            circle.Color = 橙色;
                            circle.Center = new Vector3(压铆坐标1, 压铆坐标2, 0);

                            if (Math.Round(压铆实例.压铆原直径 - 3, 2) == 0 || Math.Round(压铆实例.压铆原直径 - 4, 2) == 0)
                            {

                                circle.Radius = 2.4;
                            }
                      
                            else { circle.Radius = 压铆实例.压铆原直径 / 2; }
                            if (压铆实例.是焊接)
                            {
                                要打点 = true;
                                circle.Radius = 1;
                            }

                        }
                        else if (压铆实例.压铆螺柱长度 != 0)
                        {
                            circle.Color = AciColor.FromTrueColor(rgbColor4);
                            circle.Center = new Vector3(压铆坐标1, 压铆坐标2, 0);
                            circle.Radius = 常量.压铆螺柱映射字典[压铆实例.压铆原直径];
                            if (压铆实例.是焊接)
                            {
                                要打点=true;
                                circle.Radius = 1;
                            }
                        }
                        else
                        {
                            circle.Color = AciColor.Red;
                            circle.Center = new Vector3(压铆坐标1, 压铆坐标2, 0);
                            circle.Radius = 常量.压铆螺母映射字典[压铆实例.压铆原直径];

                        }
                        drawingEntitie.Add(circle);
                    }
                }


                if (新增了几个孔 != 0) { this.聊天记录 += ($"******新增了{新增了几个孔}个孔****\n"); }
                foreach (var item in toRemove)
                {
                    drawingEntitie.Remove(item); // 移除元素
                }
                bool 需要发生镜像 = true;

                if (是压铆面 == 是沉孔面 && !(是压铆面 == false && 是沉孔面 == false)) { 需要发生镜像 = false; this.聊天记录 += ("沉孔面压铆,需要发生镜像?" + 需要发生镜像 + "\n"); }
                int 三维压铆数 = 压铆类型s.Length;
                if (dxf压铆数 < 三维压铆数 && dxf压铆数 != 0)
                { 需要发生镜像 = false; this.聊天记录 += ("双面压铆," + "dxf压铆数=" + dxf压铆数 + ",三维压铆数=" + 三维压铆数 + ",需要发生镜像?" + 需要发生镜像 + "\n"); }
                else if (是压铆面 == 不是压铆面 && !(是压铆面 == false && 不是压铆面 == false)) { 需要发生镜像 = false; this.聊天记录 += ("双面压铆" + ",是压铆面:" + 是压铆面 + ",不是压铆面:" + 不是压铆面 + ",需要发生镜像?" + 需要发生镜像 + "\n"); }
                Debug.WriteLine("有抽牙?" + 有抽牙);
                if (this.有拉铆) { 聊天记录 += "有拉铆,底孔要加0.2\n"; }
                bool 最终镜像 = 是压铆面 && 需要发生镜像;
                if (有抽牙 ? !最终镜像 : 最终镜像)//需要发生镜像
                {

                    Vector3 原点 = new Vector3(0, 0, 0);
                    // 定义镜像平面(此处为YZ平面,沿X轴镜像)
                    netDxf.Vector3 normal = new netDxf.Vector3(1, 0, 0); // 法向量指向X轴正方向
                    Matrix3 mirrorMatrix = Matrix3.Reflection(normal);
                    if (有抽牙) this.聊天记录 += "有抽牙镜像,需标注抽牙方向\n";
                    this.聊天记录 += ("----*****----***发生镜像," + "dxf压铆数:" + dxf压铆数 + "\n");
                    Debug.WriteLine("----*****----***发生镜像");

                    //---------------------------------------------------------------------------------
                    var x色 = AciColor.FromHsl(0.9, 0.9, 0.5);

                    foreach (var entity in drawingEntitie.All)
                    {

                        EntityObject cloneentity = (EntityObject)entity.Clone();
                        cloneentity.Color = x色;
                        entitylist3.Add(cloneentity);

                        entity.TransformBy(mirrorMatrix, 原点);


                    }

                }

                //foreach (var entity in entitylist)
                //{
                //    drawingEntitie.Add(entity);
                //}
                //foreach (var entity in entitylist4)
                //{
                //    drawingEntitie.Add(entity);
                //}

                //foreach (var entity in entitylist2)
                //{
                //    drawingEntitie.Add(entity);
                //}

                //foreach (var entity in lines)
                //{

                //    drawingEntitie.Add(entity);

                //}

                //foreach (var entity in entitylist3)
                //{
                //    drawingEntitie.Add(entity);
                //}

                //------------------------------------------------------------------------------------------

            }
            else { this.聊天记录 += ("这个面没有孔,换个面"); };
            doc.Save(this.dxf);
            DxfFile dxfFile2 = DxfFile.Load(this.dxf);
            if (要打点) {
                this.聊天记录 += ("有焊接螺钉螺柱,要打点" + "\n");
            }
            var bound = dxfFile2.GetBoundingBox();
            this.聊天记录 += ("需要检查底孔,展开");
            double 差值和 = Math.Round((Math.Round((bound.Size.X + bound.Size.Y), 2) - (this.长度mm + this.宽度mm)), 1);
            if (差值和 != 0)
            { this.聊天记录 += ("dxf尺寸和展开尺寸不一样,差值和为" + 差值和 + "\n"); }

            if (this.有覆膜 ) { showmsg.visable("有覆膜,覆膜面需朝上"); }
            Process.Start(this.dxf);


        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值