Esempio 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();
        }
Esempio n. 2
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");
            }
        }