Exemplo n.º 1
0
        private void CreateRectangle(Line L1, List <Line> Ls)
        {
            var C2 = Ls.First();

            var sp1 = L1.StartPoint;
            var ep1 = L1.EndPoint;
            var Ps1 = new List <Point3d> {
                sp1, ep1
            };

            var sp2 = C2.StartPoint;
            var ep2 = C2.EndPoint;
            var Ps2 = new List <Point3d> {
                sp2, ep2
            };

            var Ps = from p1 in Ps1
                     from p2 in Ps2
                     let d = p1.DistanceTo(p2)
                             orderby d descending
                             select new List <Point3d> {
                p1, p2
            };

            if (Ps.Any())
            {
                var Points = Ps.First();

                var P1 = new Point3d(Points[0].X, Points[0].Y, 0);
                var P2 = new Point3d(Points[1].X, Points[1].Y, 0);

                var Vec1 = CADUtil.GetVector(L1);
                var Vec2 = CADUtil.GetVector(P1, P2);

                if (Vec1.GetAngleTo(Vec2) > Math.PI / 2)
                {
                    Vec1 = -Vec1;
                }

                double Ang = Math.Abs(Vec1.GetAngleTo(Vec2));

                var acPolyline = CADUtil.CreateRectangle(P1, P2, Vec1, Ang);

                //MessageBox.Show(P1.ToString() + "\n" + P2.ToString() + "\n" + Vec1.ToString() + "\n" + Ang.ToString());

                //MessageBox.Show(acPolyline.StartPoint.ToString() + "\n" + acPolyline.EndPoint.ToString());
            }
        }
Exemplo n.º 2
0
        private void CreateRectangle(Curve2d C1, List <Curve2d> Cs)
        {
            var C2 = Cs.First();

            var sp1 = C1.StartPoint;
            var ep1 = C1.EndPoint;
            var Ps1 = new List <Point2d> {
                sp1, ep1
            };

            var sp2 = C2.StartPoint;
            var ep2 = C2.EndPoint;
            var Ps2 = new List <Point2d> {
                sp2, ep2
            };

            var Ps = from p1 in Ps1
                     from p2 in Ps2
                     let d = p1.GetDistanceTo(p2)
                             orderby d descending
                             select new List <Point2d> {
                p1, p2
            };

            if (Ps.Any())
            {
                var Points = Ps.First();

                var Vec1 = CADUtil.GetVector(C1);
                var Vec2 = CADUtil.GetVector(Points[0], Points[1]);

                if (Vec1.GetAngleTo(Vec2) > Math.PI / 2)
                {
                    Vec1 = -Vec1;
                }

                double Ang = Math.Abs(Vec1.GetAngleTo(Vec2));

                var P1 = CADUtil.ToPoint3D(Points[0]);
                var P2 = CADUtil.ToPoint3D(Points[1]);

                CADUtil.CreateRectangle(P1, P2, Vec1, Ang);
            }
        }
Exemplo n.º 3
0
        public void CreateWallPolyLine()
        {
            bool B = true;

            do
            {
                try
                {
                    #region  택한 폴리선에서 각 선들 받기 [edgePtrs]
                    var edgePtrs  = new Curve2dCollection();
                    var edgeTypes = new IntegerCollection();

                    select.Objects <Polyline>().ForEach(p =>
                    {
                        GetEdgeInformation(p, ref edgePtrs, ref edgeTypes);
                    });

                    //using (Transaction t = AC.DB.TransactionManager.StartTransaction())
                    //{
                    //SelectionSet acSSet = SelectPolylines();

                    //if (acSSet == null)
                    //{
                    //    AC.Editor.PostCommandPrompt();
                    //    return;
                    //}

                    //var Polylines = from id in acSSet.GetObjectIds()
                    //                let acEnt = t.GetObject(id, OpenMode.ForWrite) as Entity
                    //                where acEnt is Polyline
                    //                let acPolyLine = acEnt as Polyline
                    //                select acPolyLine;

                    //if (Polylines.Any())
                    //{
                    //    Polylines.ToList().ForEach(p =>
                    //    {
                    //        GetEdgeInformation(p, ref edgePtrs, ref edgeTypes);
                    //    });
                    //}
                    //}
                    #endregion

                    var acPolylines = from a in edgePtrs.Cast <Curve2d>()
                                      orderby a.StartPoint.GetDistanceTo(a.EndPoint) descending
                                      select a;

                    var usedCurve = new List <Point2d>();

                    using (DocumentLock DL = AC.Doc.LockDocument())
                    {
                        acPolylines.Cast <Curve2d>().ToList().ForEach(c =>
                        {
                            var CenterP = point.GetCenterP(c.StartPoint, c.EndPoint);

                            var curves = from a in edgePtrs.Cast <Curve2d>().ToList()
                                         where a != c
                                         select a;

                            // c와 평행한 선을 받음
                            var MatchedCurves                 = from a in curves
                                                        let d = Math.Round(a.GetDistanceTo(c))
                                                                where CADUtil.GetVector(a).GetNormal().IsEqualTo(-CADUtil.GetVector(c).GetNormal())
                                                                where d >= Min && d <= Max
                                                                let cp1                     = CADUtil.GetCenterPoint2d(c)
                                                                                    let cp2 = CADUtil.GetCenterPoint2d(a)
                                                                                              orderby cp1.GetDistanceTo(cp2) ascending
                                                                                              select a;

                            if (MatchedCurves.Any())
                            {
                                //CAD.CreateLine(c.StartPoint, c.EndPoint);

                                bool B1 = true;

                                MatchedCurves.ToList().ForEach(c1 =>
                                {
                                    var cp1 = CADUtil.GetCenterPoint2d(c1);

                                    usedCurve.ForEach(cp2 =>
                                    {
                                        if (cp1.IsEqualTo(cp2))
                                        {
                                            B1 = false;
                                        }
                                    });
                                });

                                if (B1)
                                {
                                    CreateRectangle(c, MatchedCurves.ToList());

                                    usedCurve.Add(CADUtil.GetCenterPoint2d(c));
                                }
                            }
                        });
                    }
                }
                catch
                {
                    B = false;
                }
            } while (B);

            AC.Editor.WriteMessage("\n벽 입력완료 ");
            AC.Editor.PostCommandPrompt();
        }
Exemplo n.º 4
0
        public void CreateKeyLine2()
        {
            var selectedPolyLines = new List <Polyline>();
            var acPolylines       = new List <Polyline>();

            #region 폴리라인 선택
            using (Transaction T = AC.DB.TransactionManager.StartTransaction())
            {
                try
                {
                    SelectionSet acSSet = SelectLines();

                    var Lines = from id in acSSet.GetObjectIds()
                                let acEnt = T.GetObject(id, OpenMode.ForWrite) as Entity
                                            where acEnt is Polyline
                                            let acLine = acEnt as Polyline
                                                         select acLine;

                    if (!Lines.Any())
                    {
                        return;
                    }

                    selectedPolyLines.AddRange(Lines.ToArray());
                }
                catch (System.Exception ex)
                {
                    AC.Editor.WriteMessage(Convert.ToString(ex));
                }
            }
            #endregion

            using (DocumentLock DL = AC.Doc.LockDocument())
            {
                #region 입력
                selectedPolyLines.ForEach(pl =>
                {
                    #region 폴리라인에서 커브 담기
                    var curves = new List <Curve3d>();

                    for (int i = 0; i < pl.NumberOfVertices; i++)
                    {
                        try
                        {
                            var l = pl.GetLineSegmentAt(i).Length;

                            if (l >= Min && l <= Max)
                            {
                                curves.Add(pl.GetLineSegmentAt(i));
                            }
                        }
                        catch (System.Exception)
                        {
                        }
                    }
                    #endregion

                    if (curves.Count == 2)
                    {
                        var cv1 = curves[0];
                        var cv2 = curves[1];

                        var p1 = CADUtil.GetCenterPoint3d(cv1);
                        var p2 = CADUtil.GetCenterPoint3d(cv2);

                        var vec = CADUtil.GetVector(p1, p2);

                        var X = (vec * extend).X;
                        var Y = (vec * extend).Y;

                        var sp = CADUtil.MoveP(p1, -X, -Y, 0);
                        var ep = CADUtil.MoveP(p2, X, Y, 0);

                        var acPolyline = CADUtil.CreatePolyline(sp, ep);

                        acPolylines.Add(acPolyline);
                    }
                });
                #endregion

                #region 검토 & 연속된 선 연결
                // 제거할 선들
                var deletePolylines = new List <Polyline>();

                acPolylines.ForEach(pl1 =>
                {
                    var direction = pl1.GetLineSegmentAt(0).Direction;
                    direction     = direction.X < 0 ? -direction : direction;
                    var Ang       = Math.Round(Math.Atan2(direction.Y, direction.X) / Math.PI * 180) % 180;
                    var A         = Math.Abs(Ang) == 90 || Ang == 0 ? 0 : Math.Tan(Ang / 180 * Math.PI);

                    //MessageBox.Show(Ang + "\n" + A.ToString());

                    // 같은 2차 그래프에 존재하는 선들
                    var parallelPolylines = from pl2 in acPolylines
                                            where !deletePolylines.Contains(pl2)
                                            let line1                         = pl1.GetLineSegmentAt(0)
                                                                    let line2 = pl2.GetLineSegmentAt(0)
                                                                                where line1.IsParallelTo(line2, new Tolerance(1, 1))
                                                                                //let b1 = line1.StartPoint.Y - A * line1.StartPoint.X
                                                                                //let b2 = line2.StartPoint.Y - A * line2.StartPoint.X
                                                                                //let sp1 = line1.StartPoint
                                                                                //let sp2 = line2.StartPoint
                                                                                //where (Ang == 0 && IsAlmostEqual(sp1.Y, sp2.Y)) ||
                                                                                //      (Math.Abs(Ang) == 90 && IsAlmostEqual(sp1.X, sp2.X)) ||
                                                                                //      (Ang != 0 && Math.Abs(Ang) != 90 && IsAlmostEqual(line1,line2))
                                                                                where IsAlmostEqual(line1, line2)
                                                                                select pl2;

                    if (parallelPolylines.Any())
                    {
                        var Ps = CADUtil.getFurPoints(parallelPolylines.ToList());

                        var acPolyline = CADUtil.CreatePolyline(Ps[0], Ps[1]);

                        deletePolylines.AddRange(parallelPolylines);
                    }
                });

                #endregion

                #region 제거
                using (OpenCloseTransaction T = AC.DB.TransactionManager.StartOpenCloseTransaction())
                {
                    deletePolylines.ForEach(a =>
                    {
                        var entity = T.GetObject(a.Id, OpenMode.ForWrite) as Entity;

                        if (!entity.IsErased)
                        {
                            entity.Erase(true);
                        }
                    });

                    T.Commit();
                }
                #endregion
            }

            AC.Editor.WriteMessage("\n키라인 입력완료 ");
            AC.Editor.PostCommandPrompt();
        }
Exemplo n.º 5
0
        public void CreateKeyLine()
        {
            bool B = true;

            while (B)
            {
                //#region PRE
                //SelectionSet acSSet = SelectLines();

                //if (acSSet == null)
                //{
                //    B = false;
                //    return;
                //}
                //#endregion

                //#region 폴리라인 선택
                //var selectedPolyLines = new List<Polyline>();
                //var acPolylines = new List<Polyline>();

                //using (Transaction T = AC.DB.TransactionManager.StartTransaction())
                //{
                //    var Lines = from id in acSSet.GetObjectIds()
                //                let acEnt = T.GetObject(id, OpenMode.ForWrite) as Entity
                //                where acEnt is Polyline
                //                let acLine = acEnt as Polyline
                //                select acLine;

                //    if (!Lines.Any())
                //        return;

                //    selectedPolyLines.AddRange(Lines.ToArray());
                //}
                //#endregion

                var Polylines   = select.Objects <Polyline>();
                var acPolylines = new List <Polyline>();

                #region 폴리라인 정리
                Polylines.ForEach(pl =>
                {
                    #region 폴리라인에서 커브 담기
                    var curves = new List <Curve3d>();

                    for (int i = 0; i < pl.NumberOfVertices; i++)
                    {
                        try
                        {
                            var l = pl.GetLineSegmentAt(i).Length;

                            if (l >= Min && l <= Max)
                            {
                                curves.Add(pl.GetLineSegmentAt(i));
                            }
                        }
                        catch (System.Exception)
                        {
                        }
                    }
                    #endregion

                    #region 폴리라인 장축 중심을 읻는 선
                    if (curves.Count == 2)
                    {
                        var cv1 = curves[0];
                        var cv2 = curves[1];

                        var p1 = CADUtil.GetCenterPoint3d(cv1);
                        var p2 = CADUtil.GetCenterPoint3d(cv2);

                        var vec = CADUtil.GetVector(p1, p2);

                        var X = (vec * extend).X;
                        var Y = (vec * extend).Y;

                        var sp = CADUtil.MoveP(p1, -X, -Y, 0);
                        var ep = CADUtil.MoveP(p2, X, Y, 0);

                        var acPolyline = CADUtil.CreatePolyline(sp, ep);

                        acPolylines.Add(acPolyline);
                    }
                    #endregion
                });
                #endregion

                using (DocumentLock DL = AC.Doc.LockDocument())
                {
                    #region 검토 & 연속된 선 연결
                    // 제거할 선들
                    var deletePolylines = new List <Polyline>();

                    acPolylines.ForEach(pl1 =>
                    {
                        var contiPolylines = new List <Polyline>();

                        // 평행하고 같은 선상에 있는 선들
                        var paralPolylines = from pl2 in acPolylines
                                             where !deletePolylines.Contains(pl2)
                                             let line1                         = pl1.GetLineSegmentAt(0)
                                                                     let line2 = pl2.GetLineSegmentAt(0)
                                                                                 where line1.IsParallelTo(line2, new Tolerance(1, 1))
                                                                                 where IsAlmostEqual(line1, line2)
                                                                                 select pl2;

                        // 평행하고 같은 선상에 있는 선들 개수
                        int N = paralPolylines.Count();

                        var paralNearPolylines                                                             = from pl2 in paralPolylines
                                                                         let line1                         = pl1.GetLineSegmentAt(0)
                                                                                                 let line2 = pl2.GetLineSegmentAt(0)
                                                                                                             where CADUtil.getNearDistance(line1, line2) < distance
                                                                                                             select pl2;

                        if (paralNearPolylines.Any())
                        {
                            contiPolylines.AddRange(paralNearPolylines);

                            for (int j = 0; j < N; j++)
                            {
                                contiPolylines.ToList().ForEach(a =>
                                {
                                    var srtPolylines = from pl2 in acPolylines
                                                       where !contiPolylines.Contains(pl2)
                                                       let line1                         = a.GetLineSegmentAt(0)
                                                                               let line2 = pl2.GetLineSegmentAt(0)
                                                                                           where line1.IsParallelTo(line2, new Tolerance(1, 1))
                                                                                           where IsAlmostEqual(line1, line2)
                                                                                           where CADUtil.getNearDistance(line1, line2) < 2 * extend + distance
                                                                                           select pl2;

                                    if (srtPolylines.Any())
                                    {
                                        contiPolylines.AddRange(srtPolylines);
                                    }
                                });
                            }
                        }

                        if (contiPolylines.Any())
                        {
                            var Ps = CADUtil.getFurPoints(contiPolylines.ToList());

                            var acPolyline = CADUtil.CreatePolyline(Ps[0], Ps[1]);

                            deletePolylines.AddRange(contiPolylines);
                        }
                    });

                    #endregion

                    #region 제거
                    using (OpenCloseTransaction T = AC.DB.TransactionManager.StartOpenCloseTransaction())
                    {
                        deletePolylines.ForEach(a =>
                        {
                            var entity = T.GetObject(a.Id, OpenMode.ForWrite) as Entity;

                            if (!entity.IsErased)
                            {
                                entity.Erase(true);
                            }
                        });

                        T.Commit();
                    }
                    #endregion
                }
            }

            AC.Editor.WriteMessage("\n키라인 입력완료 ");
            AC.Editor.PostCommandPrompt();
        }
Exemplo n.º 6
0
        public void CreateBeamPolyLine()
        {
            bool B = true;

            while (B)
            {
                var Lines = select.Objects <Line>();

                if (Lines == null)
                {
                    B = false;
                    return;
                }

                var usedLines = new List <Point3d>();

                using (DocumentLock DL = AC.Doc.LockDocument())
                {
                    Lines.ForEach(acLine =>
                    {
                        try
                        {
                            var lines = from l in Lines.ToList()
                                        where acLine != l
                                        select l;

                            if (lines.Any())
                            {
                                #region 규칙 적용
                                var matchedLines                                              = from a in lines
                                                                     let A1                   = Math.Abs(Math.Round(CADUtil.GetVector(acLine).Angle / Math.PI * 180)) % 180
                                                                                       let A2 = Math.Abs(Math.Round(CADUtil.GetVector(a).Angle / Math.PI * 180)) % 180
                                                                                                where Math.Abs(A1 - A2) < 5
                                                                                                //where CAD.GetVector(a).IsParallelTo(CAD.GetVector(acLine))
                                                                                                //|| CAD.GetVector(a).IsParallelTo(-CAD.GetVector(acLine))
                                                                                                let curve                 = acLine as Curve
                                                                                                                    let d = Math.Round(acLine.GetGeCurve().GetDistanceTo(CADUtil.GetCenterPoint3d(a)), 0)
                                                                                                                            where d >= Min && d <= Max
                                                                                                                            select a;

                                //MessageBox.Show(matchedLines.Count().ToString());
                                #endregion

                                #region 생성
                                if (matchedLines.Any())
                                {
                                    bool B1 = true;

                                    #region 중복 판별
                                    matchedLines.ToList().ForEach(l1 =>
                                    {
                                        var cp1 = CADUtil.GetCenterPoint3d(l1);

                                        usedLines.ForEach(cp2 =>
                                        {
                                            if (cp1.IsEqualTo(cp2))
                                            {
                                                B1 = false;
                                            }
                                        });
                                    });
                                    #endregion

                                    if (B1)
                                    {
                                        CreateRectangle(acLine, matchedLines.ToList());

                                        usedLines.Add(CADUtil.GetCenterPoint3d(acLine));
                                    }
                                }
                                #endregion
                            }
                        }
                        catch { }
                    });
                }
            }

            AC.Editor.WriteMessage("\n보 입력완료 ");
            AC.Editor.PostCommandPrompt();
        }
Exemplo n.º 7
0
        public void CreateText_Polyline_Center()
        {
            var acPolyLines = new List <Polyline>();

            using (Transaction T = AC.DB.TransactionManager.StartTransaction())
            {
                try
                {
                    #region 폴리라인 선택
                    SelectionSet acSSet = SelectLines();

                    var Lines = from id in acSSet.GetObjectIds()
                                let acEnt = T.GetObject(id, OpenMode.ForWrite) as Entity
                                            where acEnt is Polyline
                                            let acLine = acEnt as Polyline
                                                         select acLine;

                    if (!Lines.Any())
                    {
                        return;
                    }

                    acPolyLines.AddRange(Lines.ToArray());
                    #endregion
                }
                catch (System.Exception ex)
                {
                    AC.Editor.WriteMessage(Convert.ToString(ex));
                }
            }

            #region 실행
            acPolyLines.ForEach(acPolyline =>
            {
                double X      = 0;
                double Y      = 0;
                int N         = acPolyline.NumberOfVertices;
                double length = 0;
                double ang    = 0;

                if (U002.Instance.rotate)
                {
                    for (int i = 0; i < N; i++)
                    {
                        try
                        {
                            var L  = acPolyline.GetLineSegment2dAt(i);
                            var CP = CADUtil.GetCenterPoint2d(L);

                            X += CP.X;
                            Y += CP.Y;

                            if (length < L.Length)
                            {
                                length = L.Length;
                                ang    = CADUtil.GetVector(L).Angle;
                            }
                        }
                        catch
                        {
                            N = N - 1;
                        }
                    }

                    if (ang > Math.PI / 2 && ang <= Math.PI / 2 * 3)
                    {
                        ang += Math.PI;
                    }
                }

                var P = acPolyline.NumberOfVertices == 4 ? GetCenterPoint(acPolyline) : GetVisualCenterPoint(acPolyline);

                var acText = CADUtil.CreateText(P, T_Size, ang, T_Position, Txt);
            });
            #endregion

            AC.Editor.WriteMessage("\nPolyline 내부에 Text생성이 완료되었습니다.");
            AC.Editor.PostCommandPrompt();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 폴리선과 텍스트를 한번에 선택하여 폴리선 내부의 텍스트를 회전한다.
        /// </summary>
        public void RotateTexts_by_Polyline()
        {
            var acPolyLines = new List <Polyline>();
            var acTexts     = new List <DBText>();

            using (DocumentLock DL = AC.Doc.LockDocument())
            {
                using (Transaction T = AC.DB.TransactionManager.StartTransaction())
                {
                    #region 폴리라인 | 텍스트 선택
                    SelectionSet acSSet = SelectLinesAndTexts();

                    #region 폴리라인
                    var Polylines = from id in acSSet.GetObjectIds()
                                    let acEnt = T.GetObject(id, OpenMode.ForWrite) as Entity
                                                where acEnt is Polyline
                                                let acLine = acEnt as Polyline
                                                             select acLine;

                    if (!Polylines.Any())
                    {
                        MessageBox.Show("선택된 폴리선이 없습니다.");
                        return;
                    }

                    acPolyLines.AddRange(Polylines.ToArray());
                    #endregion

                    #region 텍스트 받기
                    var Texts = from id in acSSet.GetObjectIds()
                                let acEnt = T.GetObject(id, OpenMode.ForWrite) as Entity
                                            where acEnt is DBText
                                            let acText = acEnt as DBText
                                                         select acText;

                    if (!Texts.Any())
                    {
                        MessageBox.Show("선택된 텍스트가 없습니다.");
                        return;
                    }

                    acTexts.AddRange(Texts.ToArray());
                    #endregion

                    #endregion

                    acTexts.ForEach(t =>
                    {
                        #region 텍스트가 입력된 폴리라인 찾기
                        var matchedPL = from pl in acPolyLines
                                        where IsInsideInPolyline(pl, t.Position)
                                        select pl;
                        #endregion

                        if (matchedPL.Any())
                        {
                            var acPolyline = matchedPL.First();

                            #region 각도 구하기
                            bool shape    = U002.Instance.shape;
                            double X      = 0;
                            double Y      = 0;
                            int N         = acPolyline.NumberOfVertices;
                            double length = shape ? 0 : double.MaxValue;
                            double ang    = t.Rotation;

                            if (U002.Instance.rotate2)
                            {
                                for (int i = 0; i < N; i++)
                                {
                                    try
                                    {
                                        var L  = acPolyline.GetLineSegment2dAt(i);
                                        var CP = CADUtil.GetCenterPoint2d(L);

                                        X += CP.X;
                                        Y += CP.Y;

                                        #region 장축
                                        if (shape)
                                        {
                                            // 장축
                                            if (length < L.Length)
                                            {
                                                length = L.Length;
                                                ang    = CADUtil.GetVector(L).Angle;
                                            }
                                        }
                                        #endregion

                                        #region 단축
                                        else
                                        {
                                            // 단축
                                            if (length > L.Length)
                                            {
                                                length = L.Length;
                                                ang    = CADUtil.GetVector(L).Angle;
                                            }
                                        }
                                        #endregion
                                    }
                                    catch
                                    {
                                        N = N - 1;
                                    }
                                }
                                // 둔각일 경우
                                if (ang > Math.PI / 2 && ang <= Math.PI / 2 * 3)
                                {
                                    ang += Math.PI;
                                }
                            }
                            else if (U002.Instance.rotate3)
                            {
                                ang = double.Parse(U002.Instance.T_angle) / 180 * Math.PI;
                            }
                            #endregion

                            #region 텍스트 이동 | 회전
                            var acText = T.GetObject(t.Id, OpenMode.ForWrite) as DBText;

                            if (U002.Instance.move)
                            {
                                var p = acPolyline.NumberOfVertices == 4 ? GetCenterPoint(acPolyline) : GetVisualCenterPoint(acPolyline);

                                MoveText(acText, p);
                                //acText.Position = p;
                            }

                            if (U002.Instance.rotate2 || U002.Instance.rotate3)
                            {
                                acText.Rotation = ang;
                            }
                            #endregion
                        }
                    });

                    T.Commit();
                }
            }

            AC.Editor.WriteMessage("\nText 정렬이 완료되었습니다.");
            AC.Editor.PostCommandPrompt();
        }
Exemplo n.º 9
0
        /// <summary>
        /// 폴리선과 텍스트를 각각 선택하여 폴리선에 맞게 텍스트를 회전한다.
        /// </summary>
        public void RotateText_by_Polyline()
        {
            bool B = true;

            while (B)
            {
                #region PRE
                SelectionSet acSSet1 = SelectAPolyline();

                if (acSSet1 == null)
                {
                    B = false;

                    return;
                }

                SelectionSet acSSet2 = SelectAText();

                if (acSSet2 == null)
                {
                    B = false;

                    return;
                }
                #endregion

                using (DocumentLock DL = AC.Doc.LockDocument())
                {
                    using (Transaction T = AC.DB.TransactionManager.StartTransaction())
                    {
                        #region 폴리라인 선택
                        var Lines = from id in acSSet1.GetObjectIds()
                                    let acEnt = T.GetObject(id, OpenMode.ForWrite) as Entity
                                                where acEnt is Polyline
                                                let acLine = acEnt as Polyline
                                                             select acLine;

                        if (!Lines.Any())
                        {
                            return;
                        }
                        #endregion

                        #region 각도 구하기 [ang]
                        var acPolyline = Lines.ToList().First();

                        bool   shape  = U002.Instance.shape; // 장축 & 단축 판별
                        double X      = 0;
                        double Y      = 0;
                        int    N      = acPolyline.NumberOfVertices;
                        double length = shape ? 0 : double.MaxValue;
                        double ang    = 0;

                        if (U002.Instance.rotate2)
                        {
                            for (int i = 0; i < N; i++)
                            {
                                try
                                {
                                    var L  = acPolyline.GetLineSegment2dAt(i);
                                    var CP = CADUtil.GetCenterPoint2d(L);

                                    X += CP.X;
                                    Y += CP.Y;

                                    #region 장축
                                    if (shape)
                                    {
                                        // 장축
                                        if (length < L.Length)
                                        {
                                            length = L.Length;
                                            ang    = CADUtil.GetVector(L).Angle;
                                        }
                                    }
                                    #endregion

                                    #region 단축
                                    else
                                    {
                                        // 단축
                                        if (length > L.Length)
                                        {
                                            length = L.Length;
                                            ang    = CADUtil.GetVector(L).Angle;
                                        }
                                    }
                                    #endregion
                                }
                                catch
                                {
                                    N = N - 1;
                                }
                            }
                            // 둔각인 경우
                            if (ang > Math.PI / 2 && ang <= Math.PI / 2 * 3)
                            {
                                ang += Math.PI;
                            }
                        }
                        else if (U002.Instance.rotate3)
                        {
                            ang = double.Parse(U002.Instance.T_angle) / 180 * Math.PI;
                        }
                        #endregion

                        #region 텍스트 선택
                        var Entities = from id in acSSet2.GetObjectIds()
                                       let acEnt = T.GetObject(id, OpenMode.ForWrite) as Entity
                                                   where acEnt is DBText
                                                   select acEnt;

                        if (!Entities.Any())
                        {
                            return;
                        }
                        #endregion

                        #region 텍스트 이동 | 회전
                        var acText = T.GetObject(Entities.First().Id, OpenMode.ForWrite) as DBText;

                        if (U002.Instance.move)
                        {
                            var p = acPolyline.NumberOfVertices == 4 ? GetCenterPoint(acPolyline) : GetVisualCenterPoint(acPolyline);

                            MoveText(acText, p);
                        }

                        if (U002.Instance.rotate2 || U002.Instance.rotate3)
                        {
                            acText.Rotation = ang;
                        }
                        #endregion

                        T.Commit();
                    }
                }
            }

            AC.Editor.WriteMessage("\nText 정렬이 완료되었습니다.");
            AC.Editor.PostCommandPrompt();
        }
Exemplo n.º 10
0
        public void Play()
        {
            //Doc = Application.DocumentManager.MdiActiveDocument;
            //Db = Doc.Database;
            //DL = Doc.LockDocument(DocumentLockMode.ProtectedAutoWrite, null, null, true);

            //Editor Editor = Application.DocumentManager.MdiActiveDocument.Editor;

            PromptSelectionResult acPSR = AC.Editor.GetSelection();

            // 선택한 객체를 받음
            if (acPSR.Status == PromptStatus.OK)
            {
                var edgePtrs  = new Curve2dCollection();
                var edgeTypes = new IntegerCollection();

                using (Transaction T = AC.DB.TransactionManager.StartTransaction())
                {
                    BlockTable       BT  = T.GetObject(AC.DB.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    BlockTableRecord BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                    SelectionSet acSSet = acPSR.Value;

                    foreach (var objID in acSSet.GetObjectIds())
                    {
                        var acEnt = T.GetObject(objID, OpenMode.ForWrite) as Entity;

                        if (acEnt is Polyline)
                        {
                            Polyline acPL = acEnt as Polyline;

                            GetEdgeInformation(acPL, ref edgePtrs, ref edgeTypes);
                        }
                    }
                }

                var acPolylines = from a in edgePtrs.Cast <Curve2d>()
                                  orderby a.StartPoint.GetDistanceTo(a.EndPoint) descending
                                  select a;

                //var usedCurve = new List<Curve2d>();
                var usedCurve = new List <Point2d>();

                acPolylines.Cast <Curve2d>().ToList().ForEach(c =>
                {
                    var CenterP = CADUtil.GetCenterPoint2d(c.StartPoint, c.EndPoint);

                    var curves = from a in edgePtrs.Cast <Curve2d>().ToList()
                                 where a != c
                                 select a;

                    // c와 평행한 선을 받음
                    var MatchedCurves                 = from a in curves
                                                let d = a.GetDistanceTo(c)
                                                        where CADUtil.GetVector(a).GetNormal().IsEqualTo(-CADUtil.GetVector(c).GetNormal())
                                                        where d > Min && d < Max
                                                        let cp1                     = CADUtil.GetCenterPoint2d(c)
                                                                            let cp2 = CADUtil.GetCenterPoint2d(a)
                                                                                      orderby cp1.GetDistanceTo(cp2) ascending
                                                                                      select a;

                    if (MatchedCurves.Any())
                    {
                        //CAD.CreateLine(c.StartPoint, c.EndPoint);

                        bool B = true;

                        MatchedCurves.ToList().ForEach(c1 =>
                        {
                            var cp1 = CADUtil.GetCenterPoint2d(c1);

                            usedCurve.ForEach(cp2 =>
                            {
                                if (cp1.IsEqualTo(cp2))
                                {
                                    B = false;
                                }
                            });
                        });

                        if (B)
                        {
                            CreateRectangle(c, MatchedCurves.ToList());

                            usedCurve.Add(CADUtil.GetCenterPoint2d(c));
                        }
                    }
                });
            }
            else
            {
                Application.ShowAlertDialog("Number of objects selected: 0");
            }
        }