Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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");
            }
        }