示例#1
0
        public static List <DBText> Command(string Text, double Size, TextPosition Position)
        {
            var Return = new List <DBText>();

            using (DocumentLock DL = AC.Doc.LockDocument())
            {
                var acSSet  = Utils.Select.MultiObjs();
                var acPolys = Utils.Get.GetEntity <Polyline>(acSSet);

                acPolys.ForEach(acPoly =>
                {
                    var CP = Utils.PointUtil.GetCenterP(acPoly);

                    var Vec = Utils.Vector.GetByLong(acPoly);

                    var Ang = Utils.Vector.To2D(Vec).Angle;

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

                    Return.Add(CADUtil.CreateText(CP, Size, Ang, Position, Text));
                });

                AC.Editor.PostCommandPrompt();
            }

            return(Return);
        }
示例#2
0
        public static ObjectId Create(LineSegment3d L, double H, ObjectId DimStyleId, ObjectId LayerId)
        {
            ObjectId Return = ObjectId.Null;

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

                var V       = L.Direction;
                var cross_V = V.CrossProduct(Vector3d.ZAxis);

                var CP = CADUtil.GetCenterPoint3d(L);       // center point
                var DP = CADUtil.MoveP(CP, cross_V, H);     // dimension point

                var acDim = new AlignedDimension(L.StartPoint, L.EndPoint, DP, string.Empty, DimStyleId);

                acDim.DimensionStyle = DimStyleId;
                acDim.LayerId        = LayerId;

                BTR.AppendEntity(acDim);
                T.AddNewlyCreatedDBObject(acDim, true);
                Return = acDim.Id;

                T.Commit();
            }
            #endregion

            return(Return);
        }
示例#3
0
        /// <summary>
        /// 폴리라인 중심에 면적 입력하기(복수 선택)
        /// </summary>
        /// <param name="TextSize">문자 크기</param>
        /// <param name="n">반올림 자리수</param>
        public void CreateMultiObj(double TextSize = 100, int n = 2)
        {
            #region 복수 객체 선택
            var acSSet = Utils.Select.MultiObjs();

            if (acSSet == null)
            {
                return;
            }

            var acEnts = Utils.Get.Entity(acSSet, typeof(Polyline));
            #endregion

            #region 면적 입력
            acEnts.ForEach(acEnt =>
            {
                var acPolyline = acEnt as Polyline;

                var p = Utils.PointUtil.GetCenterP(acPolyline);

                var PL_Area = acPolyline.Area;              // mm²

                var Area = Math.Round(PL_Area / 100000, n); // m²

                var acText = CADUtil.CreateText(p, TextSize, Area.ToString() + "m²", ColorIndex.Green);

                acDocEd.WriteMessage(" 폴리라인에 면적 [" + acText.TextString + "]이 입력되었습니다. \n");
            });
            #endregion

            acDocEd.PostCommandPrompt();
        }
示例#4
0
        // ListBox > 더블클릭
        void Lst_L_DoubleClick(object sender, EventArgs e)
        {
            var LBC = sender as DevExpress.XtraEditors.ListBoxControl;

            string LayerName = LBC.SelectedItem as string;

            #region 필터
            TypedValue[] tvs = new TypedValue[]
            {
                new TypedValue(Convert.ToInt32(DxfCode.Operator), "<or"),
                new TypedValue(Convert.ToInt32(DxfCode.LayerName), LayerName),
                new TypedValue(Convert.ToInt32(DxfCode.Operator), "or>"),
            };

            var selectFilter = new SelectionFilter(tvs);
            #endregion

            var PSR = AC.Editor.SelectAll(selectFilter);

            if (PSR.Status == PromptStatus.OK)
            {
                CADUtil.SetSelected(PSR);

                AC.Editor.WriteMessage("\n'" + LayerName + "' 레이어 객체" + PSR.Value.Count.ToString() + "개 선택. \n");
            }
            else
            {
                AC.Editor.WriteMessage("\n'" + LayerName + "' 레이어 객체가 없습니다. \n");
            }


            Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
        }
示例#5
0
        public static List <ObjectId> Create(Polyline acPoly, double H, bool updown, ObjectId DimStyleId, ObjectId LayerId)
        {
            List <ObjectId> Return = new List <ObjectId>();

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

                for (int i = 0; i < acPoly.NumberOfVertices; i++)
                {
                    try
                    {
                        var L       = acPoly.GetLineSegmentAt(i);
                        var V       = L.Direction;
                        var cross_V = V.CrossProduct(Vector3d.ZAxis);
                        var MP      = Utils.PointUtil.GetCenterP(L);     // Middle point

                        #region 폴리라인 내부에 입력되어야하는 경우
                        // updown이 true일 경우 폴리라인 외부, false인 경우 폴리라인 내부
                        if (!updown)
                        {
                            var CP = Utils.PointUtil.GetCenterP(acPoly);     // Center point

                            var p = Utils.PointUtil.Move(MP, cross_V);

                            var b = Utils.PointUtil.IsInsidePolyline(acPoly, p, false);

                            if (!b)
                            {
                                cross_V = -cross_V;
                            }
                        }
                        #endregion

                        var DP = CADUtil.MoveP(MP, cross_V, H);     // dimension point

                        var acDim = new AlignedDimension(L.StartPoint, L.EndPoint, DP, string.Empty, DimStyleId);

                        Return.Add(acDim.Id);

                        acDim.DimensionStyle = DimStyleId;
                        acDim.LayerId        = LayerId;

                        BTR.AppendEntity(acDim);
                        T.AddNewlyCreatedDBObject(acDim, true);
                    }
                    catch
                    {
                    }
                }

                T.Commit();
            }

            return(Return);
        }
示例#6
0
        void ResetListBox()
        {
            ReadData();

            var AllLayers = CADUtil.GetAllLayerNames();

            var L1  = Properties.Settings.Default.layers01.Cast <object>().Where(a => AllLayers.Contains(a.ToString()));
            var L2  = Properties.Settings.Default.layers02.Cast <object>().Where(a => AllLayers.Contains(a.ToString()));
            var L3  = Properties.Settings.Default.layers03.Cast <object>().Where(a => AllLayers.Contains(a.ToString()));
            var L4  = Properties.Settings.Default.layers04.Cast <object>().Where(a => AllLayers.Contains(a.ToString()));
            var L5  = Properties.Settings.Default.layers05.Cast <object>().Where(a => AllLayers.Contains(a.ToString()));
            var L6  = Properties.Settings.Default.layers05.Cast <object>().Where(a => AllLayers.Contains(a.ToString()));
            var L7  = Properties.Settings.Default.layers05.Cast <object>().Where(a => AllLayers.Contains(a.ToString()));
            var L8  = Properties.Settings.Default.layers05.Cast <object>().Where(a => AllLayers.Contains(a.ToString()));
            var L9  = Properties.Settings.Default.layers05.Cast <object>().Where(a => AllLayers.Contains(a.ToString()));
            var L10 = Properties.Settings.Default.layers05.Cast <object>().Where(a => AllLayers.Contains(a.ToString()));

            var L = (from a in AllLayers
                     where !L1.Contains(a)
                     where !L2.Contains(a)
                     where !L3.Contains(a)
                     where !L4.Contains(a)
                     where !L5.Contains(a)
                     where !L6.Contains(a)
                     where !L7.Contains(a)
                     where !L8.Contains(a)
                     where !L9.Contains(a)
                     where !L10.Contains(a)
                     let b = a as object
                             orderby b
                             select b);

            lst_L.Items.Clear();
            lst_L1.Items.Clear();
            lst_L2.Items.Clear();
            lst_L3.Items.Clear();
            lst_L4.Items.Clear();
            lst_L5.Items.Clear();
            lst_L6.Items.Clear();
            lst_L7.Items.Clear();
            lst_L8.Items.Clear();
            lst_L9.Items.Clear();
            lst_L10.Items.Clear();

            lst_L.Items.AddRange(L.ToArray());
            lst_L1.Items.AddRange(L1.ToArray());
            lst_L2.Items.AddRange(L2.ToArray());
            lst_L3.Items.AddRange(L3.ToArray());
            lst_L4.Items.AddRange(L4.ToArray());
            lst_L5.Items.AddRange(L5.ToArray());
            lst_L6.Items.AddRange(L6.ToArray());
            lst_L7.Items.AddRange(L7.ToArray());
            lst_L8.Items.AddRange(L8.ToArray());
            lst_L9.Items.AddRange(L9.ToArray());
            lst_L10.Items.AddRange(L10.ToArray());
        }
示例#7
0
        // 버튼 > LayerISO
        void Btn_LayerISO_Click(object sender, EventArgs e)
        {
            ReadData();

            CADUtil.TurnOffAllLayers();
            //CAD.TurnOnLayer(cbo_Layer1.Text);
            //CAD.TurnOnLayer(cbo_Layer2.Text);
            //CAD.TurnOnLayer(cbo_Layer3.Text);
            //CAD.TurnOnLayer(cbo_Layer4.Text);
        }
示例#8
0
        private void Sb_Refresh_Click(object sender, EventArgs e)
        {
            var R = GC.DataSource as List <Room>;

            R.ForEach(r =>
            {
                if (r.Handle == new Handle())
                {
                    return;
                }

                var handle = r.Handle;

                // Children 제거
                Utils.Get.ObjectIDs(r.ChildrenH).Where(id => !id.IsErased).ToList().ForEach(id => CADUtil.Erase(id));

                r.Children.Clear();
                r.ChildrenH.Clear();

                var ObjId = new ObjectId();
                AC.DB.TryGetObjectId(handle, out ObjId);
                if (ObjId.IsErased)
                {
                    r.IsLink = false;
                    r.Area   = 0;
                    return;
                }

                var acPoly = Utils.Get.GetObject <Polyline>(ObjId);
                if (acPoly == null)
                {
                    return;
                }

                r.Area = Math.Round(acPoly.Area / 1000000, 4);

                var cen  = Utils.PointUtil.GetCenterP(acPoly);
                var pos1 = new Point3d(cen.X, cen.Y + 150, cen.Z);
                var pos2 = new Point3d(cen.X, cen.Y - 150, cen.Z);

                // 이름 적기
                r.ChildrenH.Add(CADUtil.CreateText(pos1, 200, r.Name, ColorIndex.Red).Handle);

                // 길이 적기
                var objIds = Utils.DIMUtil.ReCreate(acPoly, DB.DimLayerId, DB.DimStyleId);
                r.ChildrenH.AddRange(Utils.Get.ObjHandles(objIds));

                // 면적 적기
                r.ChildrenH.Add(CADUtil.CreateText(pos2, 200, Math.Round(r.Area, 4).ToString(), ColorIndex.Red).Handle);
            });

            GV.RefreshData();

            DB.ROOM = GC.DataSource as List <Room>;
        }
示例#9
0
        /// <summary>
        /// 폴리라인 중심에 면적 입력하기(단일 선택)
        /// </summary>
        public void Create_PolylineAreaText()
        {
            bool B = true;

            while (B)
            {
                var acSSet = SelectAPolyline();

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

                    return;
                }

                using (Transaction T = AC.DB.TransactionManager.StartTransaction())
                {
                    #region 폴리라인 선택
                    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;
                    }

                    var acPolyline = Lines.ToList().First();
                    #endregion

                    #region 면적 입력
                    var p = acPolyline.NumberOfVertices == 4 ? GetCenterPoint(acPolyline) : GetVisualCenterPoint(acPolyline);

                    var PL_Area = acPolyline.Area;

                    var Area = Math.Round(PL_Area / 100000, 2);

                    var acText = CADUtil.CreateText(p, 100, Area.ToString() + "m²");

                    acText.Color = ColorIndex.Green;

                    AC.Editor.WriteMessage(" 폴리라인에 면적 [" + acText.TextString + "]이 입력되었습니다. \n");
                    #endregion

                    T.Commit();
                }
            }

            AC.Editor.PostCommandPrompt();
        }
示例#10
0
        void RefreshRoom(Handle handle)
        {
            var R = GC.DataSource as List <Room>;

            var A = R.Where(a => a.Handle.Equals(handle));

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

            var r = A.First();

            // Children 제거
            CADUtil.Erases(Utils.Get.ObjectIDs(r.ChildrenH));

            r.Children.Clear();
            r.ChildrenH.Clear();

            var ObjId = new ObjectId();

            AC.DB.TryGetObjectId(handle, out ObjId);

            var acPoly = Utils.Get.GetObject <Polyline>(ObjId);

            if (acPoly == null)
            {
                return;
            }

            r.Area = Math.Round(acPoly.Area / 1000000, 4);

            var cen  = Utils.PointUtil.GetCenterP(acPoly);
            var pos1 = new Point3d(cen.X, cen.Y + 150, cen.Z);
            var pos2 = new Point3d(cen.X, cen.Y - 150, cen.Z);

            // 이름 적기
            r.ChildrenH.Add(CADUtil.CreateText(pos1, 200, r.Name, ColorIndex.Red).Handle);

            // 길이 적기
            var objIds = Utils.DIMUtil.ReCreate(acPoly, DB.DimLayerId, DB.DimStyleId);

            r.ChildrenH.AddRange(Utils.Get.ObjHandles(objIds));

            // 면적 적기
            r.ChildrenH.Add(CADUtil.CreateText(pos2, 200, Math.Round(r.Area, 4).ToString(), ColorIndex.Red).Handle);

            GV.RefreshData();

            DB.ROOM = GC.DataSource as List <Room>;
        }
示例#11
0
        public static Vector3d GetVector(AlignedDimension dim)
        {
            var p1  = dim.XLine1Point;
            var p2  = dim.XLine2Point;
            var ls  = new LineSegment3d(p1, p2);
            var tp  = dim.TextPosition;
            var Vec = Utils.Vector.Get(p1, p2);

            var rotatedVec = Vec.RotateBy(Math.PI / 2, Vector3d.ZAxis);

            var ip = CADUtil.GetIntersectedPoint(tp, rotatedVec, ls);

            return(Utils.Vector.Get(ip, tp));
        }
示例#12
0
        /// <summary>
        /// 폴리라인 중심에 면적 입력하기(복수 선택)
        /// </summary>
        public void Create_PolylineAreaTexts()
        {
            var acSSet = SelectPolylines();

            if (acSSet == null)
            {
                return;
            }

            using (Transaction T = AC.DB.TransactionManager.StartTransaction())
            {
                #region 폴리라인 선택
                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
                                                     where acLine.Closed
                                                     select acLine;

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

                int n = 0;

                Lines.ToList().ForEach(acPolyline =>
                {
                    #region 면적 입력
                    var p = acPolyline.NumberOfVertices == 4 ? GetCenterPoint(acPolyline) : GetVisualCenterPoint(acPolyline);

                    var PL_Area = acPolyline.Area;

                    var Area = Math.Round(PL_Area / 100000, 2);

                    var acText = CADUtil.CreateText(p, 100, Area.ToString() + "m²");

                    acText.Color = ColorIndex.Green;

                    n++;
                    #endregion
                });

                T.Commit();

                AC.Editor.WriteMessage("\n" + n.ToString() + "개의 폴리라인에 면적이 입력되었습니다.");
                AC.Editor.PostCommandPrompt();
            }
        }
示例#13
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());
            }
        }
示例#14
0
        void RefreshRoom(ObjectId id)
        {
            var R = GC.DataSource as List <Room>;

            var A = R.Where(x => x.Id.Equals(id));

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

            var r = A.First();

            //MessageBox.Show("테스트1");
            r.Children.ForEach(cid => CADUtil.Erase(cid));

            //MessageBox.Show("테스트2");
            r.Children.Clear();

            var acPoly = Utils.Get.GetObject <Polyline>(id);

            if (acPoly == null)
            {
                return;
            }

            r.Area = Math.Round(acPoly.Area / 1000000, 4);

            var cen  = Utils.PointUtil.GetCenterP(acPoly);
            var pos1 = new Point3d(cen.X, cen.Y + 150, cen.Z);
            var pos2 = new Point3d(cen.X, cen.Y - 150, cen.Z);

            //var acDimLayerId = Utils.Layer.Create("HDC_Dimension", ColorIndex.Green);    // 레이어 생성
            //var acDimStyleId = Utils.DIMUtil.Create_HDC_DimensionStyle("HDC_Dim_Style");             // 치수 스타일 생성

            // 이름 적기
            r.Children.Add(CADUtil.CreateText(pos1, 200, r.Name).Id);

            // 길이 적기
            r.Children.AddRange(Utils.DIMUtil.ReCreate(acPoly, DB.DimLayerId, DB.DimStyleId));

            // 면적 적기
            //r.Children.Add(AC.Drawing.CreateText(pos2, Math.Round(r.Area, 4).ToString()));

            GV.RefreshData();

            DB.ROOM = GC.DataSource as List <Room>;
        }
示例#15
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);
            }
        }
示例#16
0
        public void CreateColumnPolyLine()
        {
            bool B = true;

            while (B)
            {
                var Polylines = select.Objects <Polyline>();

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

                #region 생성
                using (DocumentLock DL = AC.Doc.LockDocument())
                {
                    Polylines.ForEach(acPolyline =>
                    {
                        var Points = new List <Point3d>();

                        for (int i = 0; i < acPolyline.NumberOfVertices; i++)
                        {
                            Points.Add(acPolyline.GetPoint3dAt(i));
                        }

                        Points.Add(acPolyline.GetPoint3dAt(0));

                        var acNewPolyLine = CADUtil.CreateRectangle(Points);
                    });
                }
                #endregion
            }

            AC.Editor.WriteMessage("\n기둥 입력완료 ");
            AC.Editor.PostCommandPrompt();
        }
示例#17
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();
        }
示例#18
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();
        }
示例#19
0
        // 모든 레이어 켜기 / 끄기 / All Clear / Fitting
        void LCG_Main_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
        {
            ReadData();

            switch (e.Button.Properties.Caption)
            {
            case "모든 레이어 켜기": CADUtil.TurnOnAllLayers(); break;

            case "모든 레이어 끄기": CADUtil.TurnOffAllLayers(); break;

            case "C":
            {
                ClearListBox(lst_L1);
                ClearListBox(lst_L2);
                ClearListBox(lst_L3);
                ClearListBox(lst_L4);
                ClearListBox(lst_L5);
                ClearListBox(lst_L6);
                ClearListBox(lst_L7);
                ClearListBox(lst_L8);
                ClearListBox(lst_L9);
                ClearListBox(lst_L10);
            }
            break;

            case "F":
            {
                int n = 0;
                if (LCG_1.Expanded)
                {
                    n++;
                }
                if (LCG_2.Expanded)
                {
                    n++;
                }
                if (LCG_3.Expanded)
                {
                    n++;
                }
                if (LCG_4.Expanded)
                {
                    n++;
                }
                if (LCG_5.Expanded)
                {
                    n++;
                }
                if (LCG_6.Expanded)
                {
                    n++;
                }
                if (LCG_7.Expanded)
                {
                    n++;
                }
                if (LCG_8.Expanded)
                {
                    n++;
                }
                if (LCG_9.Expanded)
                {
                    n++;
                }
                if (LCG_10.Expanded)
                {
                    n++;
                }

                int width  = LCG_1.Size.Width;
                int height = LCG_0.Height / n;

                if (LCG_1.Expanded)
                {
                    LCG_1.Size = new Size(width, height);
                }
                if (LCG_2.Expanded)
                {
                    LCG_2.Size = new Size(width, height);
                }
                if (LCG_3.Expanded)
                {
                    LCG_3.Size = new Size(width, height);
                }
                if (LCG_4.Expanded)
                {
                    LCG_4.Size = new Size(width, height);
                }
                if (LCG_5.Expanded)
                {
                    LCG_5.Size = new Size(width, height);
                }
                if (LCG_6.Expanded)
                {
                    LCG_6.Size = new Size(width, height);
                }
                if (LCG_7.Expanded)
                {
                    LCG_7.Size = new Size(width, height);
                }
                if (LCG_8.Expanded)
                {
                    LCG_8.Size = new Size(width, height);
                }
                if (LCG_9.Expanded)
                {
                    LCG_9.Size = new Size(width, height);
                }
                if (LCG_10.Expanded)
                {
                    LCG_10.Size = new Size(width, height);
                }
            }
            break;
            }
        }
示例#20
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");
            }
        }
示例#21
0
        public List <Polyline> Create_Boundaries()
        {
            var Return = new List <Polyline>();

            using (DocumentLock DL = AC.Doc.LockDocument())
            {
                #region  택
                var acSSet = Utils.Select.MultiObjs();

                var acEnts = Utils.Get.Entity(acSSet, typeof(Polyline));
                #endregion

                #region 폴리라인 연장시켜 하나의 덩어리로 만들기
                var acLines     = new List <LineSegment3d>(); // 선택된 Polyline의 모든 선분을 담음(최대, 최소 좌표를 얻기위해)
                var acTempLines = new List <Line>();          // 작업 완료 후 지울 보조선

                acEnts.Where(x => x is Polyline).ToList().ForEach(acEnt =>
                {
                    var acEntsCopy = acEnts.Where(x => x != acEnt);
                    var acPoly     = acEnt as Polyline;

                    for (int i = 0; i < acPoly.NumberOfVertices; i++)
                    {
                        try
                        {
                            var acLine = acPoly.GetLineSegmentAt(i);

                            if (!acLines.Contains(acLine))
                            {
                                acLines.Add(acLine);
                            }

                            var Di = acLine.Direction;

                            var sp       = acLine.StartPoint;
                            var ep       = acLine.EndPoint;
                            var moved_sp = Utils.PointUtil.Move(acLine.StartPoint, -Di);
                            var moved_ep = Utils.PointUtil.Move(acLine.StartPoint, Di);

                            var LS1 = new LineSegment3d(sp, moved_sp);      // Line에서 연장된 선분
                            var LS2 = new LineSegment3d(ep, moved_ep);      // Line에서 연장된 선분

                            var IP1 = CADUtil.IntersectedLine(acEntsCopy.ToList(), LS1, sp, 500);
                            var IP2 = CADUtil.IntersectedLine(acEntsCopy.ToList(), LS2, ep, 500);

                            double d = 0;

                            if (IP1 != new Point3d())
                            {
                                var SP = Utils.PointUtil.Move(sp, Di * d);
                                var EP = Utils.PointUtil.Move(IP1, -Di * d);
                                var L1 = CADUtil.CreateLine(SP, EP, ColorIndex.DarkGray);
                                acTempLines.Add(L1);
                            }
                            if (IP2 != new Point3d())
                            {
                                var SP = Utils.PointUtil.Move(ep, -Di * d);
                                var EP = Utils.PointUtil.Move(IP2, Di * d);
                                var L2 = CADUtil.CreateLine(SP, EP, ColorIndex.DarkGray);
                                acTempLines.Add(L2);
                            }
                        }
                        catch { }
                    }
                });
                #endregion

                #region 폴리라인을 감싸는 Box객체를 생성
                var P_X = (from a in acLines
                           let p = a.StartPoint
                                   orderby p.X
                                   select p.X);

                var P_Y = (from a in acLines
                           let p = a.StartPoint
                                   orderby p.Y
                                   select p.Y);

                var Min_P = new Point3d(P_X.First() - 1000, P_Y.First() - 1000, 0);
                var Max_P = new Point3d(P_X.Last() + 1000, P_Y.Last() + 1000, 0);

                var Box = CADUtil.CreateRectangle(Min_P, Max_P);
                #endregion

                #region 밀폐된 공간에서 Boundary 추적
                var P1 = Utils.PointUtil.Move(Min_P, 500, 500);

                var objColl = AC.Editor.TraceBoundary(P1, true);

                var acObjs = from a in objColl.Cast <Entity>().ToList() select a;
                #endregion

                #region Boundary 생성
                if (acObjs.Any())
                {
                    using (Transaction T = AC.DB.TransactionManager.StartTransaction())
                    {
                        var BT  = T.GetObject(AC.DB.BlockTableId, OpenMode.ForRead) as BlockTable;
                        var BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                        acObjs.ToList().ForEach(a =>
                        {
                            var acPoly = a as Polyline;

                            if (Math.Abs(acPoly.Area - Box.Area) > 1)
                            {
                                BTR.AppendEntity(acPoly);
                                T.AddNewlyCreatedDBObject(acPoly, true);

                                Return.Add(acPoly);
                            }
                        });

                        T.Commit();
                    }
                }
                #endregion

                #region 제거
                CADUtil.Erase(Box.Id);

                acTempLines.ForEach(a => CADUtil.Erase(a.Id));
                #endregion
            }

            return(Return);
        }
示例#22
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();
        }
示例#23
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();
        }
示例#24
0
        public static List <ObjectId> Create2(Polyline acPoly, ObjectId LayerID, ObjectId StyleID)
        {
            List <ObjectId> Return = new List <ObjectId>();

            #region 객체 받기
            var A = Utils.Get.PointCollection(acPoly);

            var acCPSSet = AC.Editor.SelectCrossingPolygon(A).Value;
            if (acCPSSet.Count == 0)
            {
                return(new List <ObjectId>());
            }

            var Texts = Utils.Get.GetEntity <DBText>(acCPSSet);
            var Dims  = Utils.Get.GetEntity <AlignedDimension>(acCPSSet);
            #endregion

            #region 면적 지우기
            if (Texts.Any())
            {
                var acTexts = Texts.Where(x => Utils.Get.IsDouble(x.TextString)).ToList();

                if (acTexts.Count == 1)
                {
                    using (Transaction t = AC.DB.TransactionManager.StartTransaction())
                    {
                        acTexts.ForEach(text =>
                        {
                            var B = t.GetObject(text.Id, OpenMode.ForWrite) as DBText;

                            B.Erase(true);

                            t.Commit();
                        });
                    }
                }
            }
            #endregion

            #region 치수선 지우기 & 치수선 생성
            if (Dims.Any())
            {
                using (Transaction t = AC.DB.TransactionManager.StartTransaction())
                {
                    Dims.ToList().ForEach(Dim =>
                    {
                        var acDim = t.GetObject(Dim.Id, OpenMode.ForWrite) as AlignedDimension;

                        if (Utils.PointUtil.IsInsidePolyline(acPoly, acDim.TextPosition, true))
                        {
                            acDim.Erase(true);
                        }
                    });

                    t.Commit();
                }
            }

            Return.AddRange(Utils.DIMUtil.Create(A.Cast <Point3d>().ToList(), 100, false, StyleID, LayerID));
            #endregion

            #region 새로 면적 입력
            var p = Utils.PointUtil.Move(Utils.PointUtil.GetCenterP(acPoly), 0, -100);

            var PL_Area = acPoly.Area;                   // mm²

            var Area = Math.Round(PL_Area / 1000000, 3); // m²

            var acText = CADUtil.CreateText(p, 200, Area.ToString(), ColorIndex.Red);
            //var acText = CAD.CreateText(p, 100, Area.ToString() + "m²", TxtStyleId, ColorIndex.Green);

            Return.Add(acText.Id);
            #endregion

            return(Return);
        }
示例#25
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();
        }
示例#26
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();
        }
示例#27
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();
        }
示例#28
0
        /// <summary>
        /// 폴리라인의 중심점 구하기
        /// </summary>
        /// <param name="acPolyline"></param>
        /// <returns></returns>
        private Point3d GetVisualCenterPoint(Polyline acPolyline)
        {
            #region 폴리라인 내부 점 받기
            var min_P = acPolyline.Bounds.Value.MinPoint;
            var max_P = acPolyline.Bounds.Value.MaxPoint;

            int n = 20;

            double dis_X = (max_P.X - min_P.X) / n;
            double dis_Y = (max_P.Y - min_P.Y) / n;

            var Points = new List <Point3d>();

            for (int i = 0; i < n + 1; i++)
            {
                for (int j = 0; j < n + 1; j++)
                {
                    var p = CADUtil.MoveP(min_P, dis_X * j, dis_Y * i);

                    if (IsInsideInPolyline(acPolyline, p))
                    {
                        Points.Add(p);
                    }
                }
            }
            #endregion

            #region 무게중심
            double  value = double.MaxValue;
            Point3d cp    = new Point3d();

            Points.ForEach(p1 =>
            {
                double val = 0;
                Points.ForEach(p2 =>
                {
                    if (!p1.IsEqualTo(p2))
                    {
                        val += p1.DistanceTo(p2) * p1.DistanceTo(p2);
                    }
                });

                if (value > val)
                {
                    value = val;
                    cp    = p1;
                }
            });

            return(cp);

            #endregion

            #region 폴리라인의 중심점
            var X = 0.0;
            var Y = 0.0;

            Points.ForEach(p =>
            {
                X += (p.X) / Points.Count;
                Y += (p.Y) / Points.Count;
            });

            //return new Point3d(X, Y, 0);
            #endregion

            #region 점, 문자
            //using (Transaction T = acDb.TransactionManager.StartTransaction())
            //{
            //    BlockTable BT = T.GetObject(acDb.BlockTableId, OpenMode.ForRead) as BlockTable;
            //    BlockTableRecord BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            //    DBPoint p1 = new DBPoint(min_P);
            //    DBPoint p2 = new DBPoint(max_P);
            //    DBPoint p3 = new DBPoint(new Point3d(X, Y, 0));
            //    DBPoint p4 = new DBPoint(cp);

            //    //BTR.AppendEntity(p1);
            //    //BTR.AppendEntity(p2);
            //    //BTR.AppendEntity(p3);
            //    BTR.AppendEntity(p4);

            //    //T.AddNewlyCreatedDBObject(p1, true);
            //    //T.AddNewlyCreatedDBObject(p2, true);
            //    //T.AddNewlyCreatedDBObject(p3, true);
            //    T.AddNewlyCreatedDBObject(p4, true);

            //    for (int i = 0; i < Points.Count; i++)
            //    {
            //        //using (DBPoint acPoint = new DBPoint(Points[i]))
            //        //{
            //        //    BTR.AppendEntity(acPoint);
            //        //    T.AddNewlyCreatedDBObject(acPoint, true);
            //        //}
            //    }
            //    acDb.Pdmode = 34;
            //    acDb.Pdsize = 150;

            //    T.Commit();
            //}
            //return new Point3d();
            #endregion
        }
示例#29
0
        void LinkRoom()
        {
            // F = GC.SelectedRows
            // f = GC.GetFocusedRow();

            #region  택
            var F = Utils.GC.GetSelectedRows <Room>(GV);
            if (F.Count == 0)
            {
                return;
            }
            #endregion

            #region 치수
            foreach (Room f in F)
            {
                var msg = string.Format("실 {0} 을/를 선택하세요", f.Name);

                if (new U_Msgbox("실(공간) 선택", msg).ShowDialog() != DialogResult.OK)
                {
                    break;
                }

                var acSSet = Utils.Select.SingleObj(string.Format("실 {0} 를 선택하세요", f.Name));
                if (acSSet == null)
                {
                    continue;
                }

                var acPolys = Utils.Get.GetEntity <Polyline>(acSSet);
                if (acPolys.Count == 0)
                {
                    continue;
                }

                var acPoly = acPolys.First();
                if (acPoly.Id == ObjectId.Null)
                {
                    continue;
                }

                f.Id     = acPoly.Id;
                f.Handle = acPoly.Handle;
                f.IsLink = true;
                f.Area   = Math.Round(acPoly.Area / 1000000, 4);

                var A = F.Where(a => a.Handle.Equals(f.Handle));

                if (A.Any())
                {
                    RefreshRoom(f.Handle);
                }
                else
                {
                    var cen  = Utils.PointUtil.GetCenterP(acPoly);
                    var pos1 = new Point3d(cen.X, cen.Y + 150, cen.Z);
                    var pos2 = new Point3d(cen.X, cen.Y - 150, cen.Z);

                    // 이름 적기
                    f.ChildrenH.Add(CADUtil.CreateText(pos1, 200, f.Name, ColorIndex.Red).Handle);

                    // 길이 적기
                    var objIds = Utils.DIMUtil.ReCreate(acPoly, DB.DimLayerId, DB.DimStyleId);
                    f.ChildrenH.AddRange(Utils.Get.ObjHandles(objIds));

                    // 면적 적기
                    f.ChildrenH.Add(CADUtil.CreateText(pos2, 200, Math.Round(f.Area, 4).ToString(), ColorIndex.Red).Handle);
                }
            }
            #endregion

            GV.RefreshData();

            DB.ROOM = GC.DataSource as List <Room>;
        }
示例#30
0
        public List <Polyline> Create_Boundaries_Util(double Dis = 100)
        {
            var Return = new List <Polyline>();

            using (DocumentLock DL = AC.Doc.LockDocument())
            {
                #region  택
                var acSSet = Utils.Select.MultiObjs();

                var acEnts = Utils.Get.Entity(acSSet, typeof(Polyline));
                #endregion

                #region 폴리라인 연장시켜 폴리라인 생성
                acEnts.Where(x => x is Polyline).ToList().ForEach(acEnt =>
                {
                    var acPoly      = acEnt as Polyline;
                    var acTempLines = new List <Line>();         // 작업 완료 후 지울 보조선

                    #region 폴리라인 선분 연장선 생성
                    for (int i = 0; i < acPoly.NumberOfVertices; i++)
                    {
                        try
                        {
                            var acLine    = acPoly.GetLineSegmentAt(i);
                            var sp        = acLine.StartPoint;
                            var ep        = acLine.EndPoint;
                            var Direction = acLine.Direction;

                            var SP = sp - Direction * Dis;
                            var EP = ep + Direction * Dis;

                            var L = CADUtil.CreateLine(SP, EP);

                            acTempLines.Add(L);
                        }
                        catch { }
                    }
                    #endregion

                    #region  택된 폴리라인의 중앙점
                    var CP = Utils.PointUtil.GetCenterP(acPoly);
                    #endregion

                    #region 밀폐된 공간에서 Boundary 생성
                    // 선택된 객체 말고 모두 숨긴뒤에 실행해야 오류가 줄어듬


                    var objColl = AC.Editor.TraceBoundary(CP, true);

                    var acObjs = from a in objColl.Cast <Entity>().ToList() select a;

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

                            acObjs.ToList().ForEach(a =>
                            {
                                var Poly = a as Polyline;

                                BTR.AppendEntity(Poly);
                                T.AddNewlyCreatedDBObject(Poly, true);

                                Return.Add(Poly);
                            });

                            T.Commit();
                        }
                    }
                    #endregion

                    #region 연장선 제거
                    acTempLines.ForEach(a => CADUtil.Erase(a.Id));
                    #endregion
                });
                #endregion
            }

            return(Return);
        }