Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

huongmdc

// bai 1

        bool bIsInCirle(int hCirc, double x, double y)

        {

            double cx, cy, r;

            if (IsCircle(hCirc) == 1)

            {

                cx = Lcad.PropGetFloat(hCirc, Lcad.LC_PROP_CIRCLE_X);

                cy = Lcad.PropGetFloat(hCirc, Lcad.LC_PROP_CIRCLE_Y);

                r = Lcad.PropGetFloat(hCirc, Lcad.LC_PROP_CIRCLE_RAD);

            }

            else

            {

                cx = Lcad.PropGetFloat(hCirc, Lcad.LC_PROP_ARC_X);

                cy = Lcad.PropGetFloat(hCirc, Lcad.LC_PROP_ARC_Y);

                r = Lcad.PropGetFloat(hCirc, Lcad.LC_PROP_ARC_RAD);

            }

            cx = cx - x;

            cy = cy - y;

            double tmp = Math.Sqrt(cx * cx + cy * cy);

            tmp = Math.Round(tmp - r, 3);

            if (tmp == 0)

                return true;

            return false;

        }

        bool GetCenter(int hCirc, out double x, out  double y)

        {

            try

            {

                if (IsCircle(hCirc) == 1)

                {

                    x = Lcad.PropGetFloat(hCirc, Lcad.LC_PROP_CIRCLE_X);

                    y = Lcad.PropGetFloat(hCirc, Lcad.LC_PROP_CIRCLE_Y);

                }

                else

                {

                    x = Lcad.PropGetFloat(hCirc, Lcad.LC_PROP_ARC_X);

                    y = Lcad.PropGetFloat(hCirc, Lcad.LC_PROP_ARC_Y);

                }

            }

            catch (Exception)

            {

                x = y = 0;

                return false;

            }

            return true;

        }

        double x0, y0, x1, y1;

        int kt = 0;

        double cx1, cx2, cy1, cy2;

        void AddText(int hBlock, string szText, double X, double Y, int Align, double H, double WScale, double RotAngle, double Oblique)

        {

            int hTmp = Lcad.BlockAddTextWin2(hBlock, szText, X, Y, Align, H, WScale, RotAngle, Oblique);

            Lcad.PropPutInt(hTmp, Lcad.LC_PROP_TEXTW_DX, 0);

            Lcad.PropPutInt(hTmp, Lcad.LC_PROP_TEXTW_DY, 10);

        }

        int IsCircle(int hEnt)

        {

            int iType = Lcad.PropGetInt(hEnt, Lcad.LC_PROP_ENT_TYPE);

            if (iType == Lcad.LC_ENT_CIRCLE)

                return 1;

            if (iType == Lcad.LC_ENT_ARC)

                return 2;

            return 0;

        }

        int hEnt1, hEnt2, hLineTan;

        private void aToolStripMenuItem_Click(object sender, EventArgs e)

        {

            Lcad.WndSetFocus(hLcWnd);

            double x0, y0;

            int px, py;

            if (Lcad.WndGetPoint(hLcWnd, "Nhap doi tuong thu nhat: ", Lcad.LC_SNAP_ALL, 0, out x0, out y0))

            {

                Lcad.WndCoordFromDrw(hLcWnd, x0, y0, out px, out py);

                hEnt1 = Lcad.WndGetEntByPoint(hLcWnd, px, py);

                if (IsCircle(hEnt1) == 0)

                {

                    MessageBox.Show("Ban phai chon doi tuong la duong tron hoac cung tron");

                    return;

                }

                if (Lcad.WndGetPoint(hLcWnd, "Nhap doi tuong thu hai: ", Lcad.LC_SNAP_ALL, 0, out x0, out y0))

                {

                    Lcad.WndCoordFromDrw(hLcWnd, x0, y0, out px, out py);

                    hEnt2 = Lcad.WndGetEntByPoint(hLcWnd, px, py);

                    if (IsCircle(hEnt1) == 0)

                    {

                        MessageBox.Show("Ban phai chon doi tuong la duong tron hoac cung tron");

                        return;

                    }

                    hBlock = Lcad.DrwGetFirstObject(hDrw, Lcad.LC_OBJ_BLOCK);

                    hLineTan = Lcad.BlockAddLineTan(hBlock, hEnt1, hEnt2, 0);

                    Lcad.DrwRegenViews(hDrw, hLineTan);

                    Lcad.WndExeCommand(hLcWnd, Lcad.LC_CMD_EXTEND, 0);

                }

            }

        }

        private void bToolStripMenuItem_Click(object sender, EventArgs e)

        {

            Lcad.WndSetFocus(hLcWnd);

            hBlock = Lcad.DrwGetFirstObject(hDrw, Lcad.LC_OBJ_BLOCK);

            x0 = Lcad.PropGetFloat(hLineTan, Lcad.LC_PROP_LINE_X0);

            y0 = Lcad.PropGetFloat(hLineTan, Lcad.LC_PROP_LINE_Y0);

            x1 = Lcad.PropGetFloat(hLineTan, Lcad.LC_PROP_LINE_X1);

            y1 = Lcad.PropGetFloat(hLineTan, Lcad.LC_PROP_LINE_Y1);

            if (bIsInCirle(hEnt1, x0, y0))

            {

                GetCenter(hEnt1, out cx1, out cy1);

                Lcad.BlockAddLine(hBlock, cx1, cy1, x0, y0);

                GetCenter(hEnt2, out cx2, out cy2);

                Lcad.BlockAddLine(hBlock, cx2, cy2, x1, y1);

                Lcad.BlockAddLine(hBlock, cx1, cy1, cx2, cy2);

            }

            else

            {

                kt = 1;

                GetCenter(hEnt1, out cx1, out cy1);

                Lcad.BlockAddLine(hBlock, cx1, cy1, x1, y1);

                GetCenter(hEnt2, out cx2, out cy2);

                Lcad.BlockAddLine(hBlock, cx2, cy2, x0, y0);

                Lcad.BlockAddLine(hBlock, cx1, cy1, cx2, cy2);

            }

            Lcad.DrwRegenViews(hDrw, 0);

            Lcad.WndExeCommand(hLcWnd, Lcad.LC_CMD_EXTEND, 0);

        }

        private void cToolStripMenuItem_Click(object sender, EventArgs e)

        {

            Lcad.WndSetFocus(hLcWnd);

            hBlock = Lcad.DrwGetFirstObject(hDrw, Lcad.LC_OBJ_BLOCK);

            int hTextStyle = Lcad.DrwAddTextStyle(hDrw, "Hoangvankhieu", "Times New Roman");

            Lcad.PropPutHandle(hDrw, Lcad.LC_PROP_DRW_TEXTSTYLE, hTextStyle);

            if (kt == 0)

            {

                AddText(hBlock, "M1", x0, y0, Lcad.LC_TA_CENTER, -15, 1, 0, 0);

                AddText(hBlock, "M2", x1, y1, Lcad.LC_TA_CENTER, -15, 1, 0, 0);

                AddText(hBlock, "C1", cx1, cy1, Lcad.LC_TA_CENTER, -15, 1, 0, 0);

                AddText(hBlock, "C2", cx2, cy2, Lcad.LC_TA_CENTER, -15, 1, 0, 0);

            }

            else

            {

                AddText(hBlock, "M1", x1, y1, Lcad.LC_TA_CENTER, -15, 1, 0, 0);

                AddText(hBlock, "M2", x0, y0, Lcad.LC_TA_CENTER, -15, 1, 0, 0);

                AddText(hBlock, "C1", cx1, cy1, Lcad.LC_TA_CENTER, -15, 1, 0, 0);

                AddText(hBlock, "C2", cx2, cy2, Lcad.LC_TA_CENTER, -15, 1, 0, 0);

            }

            Lcad.DrwRegenViews(hDrw, 0);

            Lcad.WndExeCommand(hLcWnd, Lcad.LC_CMD_EXTEND, 0);

        }

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: #huong