明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1151|回复: 3

[几何] 带弧形的POLYLINE的绘制过程

[复制链接]
发表于 2017-11-13 13:23 | 显示全部楼层 |阅读模式
本帖最后由 zjzkz 于 2017-12-8 15:53 编辑

自己搞定!
Create Table BaseLine
        (
        Id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
        RBID SMALLINT UNSIGNED NOT NULL,
        OperatorID SMALLINT UNSIGNED NOT NULL,
        Vertex_Index SMALLINT UNSIGNED NOT NULL,
        Bugle DOUBLE NOT NULL,
        Vertex_x DOUBLE NOT NULL,
        Vertex_Y DOUBLE NOT NULL,
        Vertex_Z DOUBLE NOT NULL
    )
Bugle :1/4圆弧角度的正切值。------------------------
1、写入数据库
------------------------
#region【8、将标准层基线的节点信息写入数据库表Building_Baseline】
        public static void VertexToMysql(int RBID, int OperatorId,Polyline pLine,Boolean insert)
        {
            try
            {
                if (pLine == null)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("没有选择基线!");
                }
                else
                {
                    int VertexNum = pLine.NumberOfVertices;
                    for (int i = 0; i < VertexNum; i++)
                    {
                        if (insert)
                        {
                            string sql1 = "insert into Building_Baseline (RBID,OperatorId,Vertex_Index,Bugle,Vertex_x,Vertex_y,Vertex_z) values ('"
                                  sql1 += RBID + "','"
                                  sql1 += OperatorId + "','"
                                  sql1 +=  i + "','"
                                  sql1 += pLine.GetBulgeAt(i) + "','"
                                  sql1 += pLine.GetPoint3dAt(i).X + "','"
                                  sql1 += pLine.GetPoint3dAt(i).Y + "','"
                                  sql1 += pLine.GetPoint3dAt(i).Z + "')";
                            DbMysql.Excute(sql1);           
                        }
                        else
                        {
                            string sql2 = "UPDATE Building_Baseline SET OperatorId='" + OperatorId + "',Bugle='" + pLine.GetBulgeAt(i) + "',Vertex_x='" + pLine.GetPoint3dAt(i).X + "',Vertex_y='" + pLine.GetPoint3dAt(i).Y + "',Vertex_z='" + pLine.GetPoint3dAt(i).Z + "' WHERE  RBID='" + RBID + "' AND Vertex_Index='" + i + "'";
                            DbMysql.Excute(sql2);           
                        }                                       
                    }
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("信息更新成功!");
                }
            }
            catch (MySqlException error)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(error.Message);
            }
            catch (Autodesk.AutoCAD.Runtime.Exception error)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(error.Message);
            }
        }
        #endregion

------------------------------
2、从数据库读取
------------------------------
  #region【5、从Mysql按RBID取得一个Polyline】
        public static Polyline BaseLine(int RBID)
        {
            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            Polyline thisPolyline = new Polyline();
            using (acDoc.LockDocument())
            {
                MySqlConnection conn = DbMysql.MyConn();
                try
                {
                    conn.Open();
                    string sql = "SELECT Vertex_Index,Bugle,Vertex_x,Vertex_y,Vertex_z from Baseline where RBID ='" + RBID + "'";
                    MySqlCommand cmd = new MySqlCommand(sql, conn);
                    MySqlDataReader PolyLineFromMysql = cmd.ExecuteReader();
                    using (Transaction tans = acCurDb.TransactionManager.StartTransaction())
                    {
                        int Vertex_Index;
                        double Bugle;
                        double Vertex_X;
                        double Vertex_Y;
                        //double Vertex_Z;
                        Point2d thisPoint;
                        while (PolyLineFromMysql.Read())
                        {
                            Vertex_Index = PolyLineFromMysql.GetInt32(0);
                            Bugle = PolyLineFromMysql.GetDouble(1);
                            Vertex_X = PolyLineFromMysql.GetDouble(2);
                            Vertex_Y = PolyLineFromMysql.GetDouble(3);
                            //Vertex_Z = PolyLineFromMysql.GetOrdinal("Vertex_z");
                            thisPoint = new Point2d(Vertex_X, Vertex_Y);
                            thisPolyline.AddVertexAt(Vertex_Index, thisPoint, Bugle, 0, 0);
                            thisPolyline.Closed = true;
                        }
                    }
                    conn.Close();
                    conn.Dispose();
                }
                catch (MySqlException sqlerr)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("数据库错误:" + sqlerr);
                }
                catch (System.Exception syserr)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("系统错误:" + syserr.ToString());
                }
                return thisPolyline;
            }
        }
        #endregion
----------------------------
3、写入当前模型空间
----------------------------
#region【1、以指定基点,角度,写入一条闭合的复合线】
        public static void BaseLineDraw(Point3d InsertPoint, double Angle,int RBID)
        {
            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            using (acDoc.LockDocument())
            {                              
                try
                {
                    Point3d BasePoint = DbMysql.BasePoint(RBID);
                    Polyline BaseLine = DbMysql.BaseLine(RBID);
                    Vector3d MoveVec = BasePoint.GetVectorTo(InsertPoint);
                    Vector3d RotateVec = new Vector3d(0, 0, 1);
                    //先旋转,再移动!
                    BaseLine.TransformBy(Matrix3d.Rotation(Angle,RotateVec,BasePoint));
                    BaseLine.TransformBy(Matrix3d.Displacement(MoveVec));
                    using (Transaction trans = acCurDb.TransactionManager.StartTransaction())
                    {
                        ObjectId id = new ObjectId();
                        BlockTable bt = (BlockTable)trans.GetObject(acCurDb.BlockTableId, OpenMode.ForWrite);
                        BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                        id = btr.AppendEntity(BaseLine);
                        trans.AddNewlyCreatedDBObject(BaseLine, true);
                        trans.Commit();
                        trans.Dispose();
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception caderr)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("CAD错误:" + caderr);
                }
                catch (System.Exception syserr)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("系统错误:" + syserr.ToString());
                }

            }
        }
        #endregion





发表于 2017-12-5 18:24 来自手机 | 显示全部楼层
没懂你到底求助什么?
 楼主| 发表于 2017-12-8 15:52 | 显示全部楼层
自己搞定了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-27 10:09 , Processed in 0.550373 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表