Example #1
0
 private void stop()
 {
     timer1.Enabled = false;
     BaseTunnel.endAnimateMode();
     Utils.ReflushViewport(idarray);
     Global.AnimateMode = false;
 }
Example #2
0
        /// <summary>
        /// 刷新cad图形对象
        /// </summary>
        /// <param name="idArray">要刷新对象的id数组</param>
        static public void ReflushViewport(ObjectId[] idArray)
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            doc.LockDocument();

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            Utils.TransactionControl(() => {
                if (idArray == null)
                {
                    return;
                }

                foreach (ObjectId id in idArray)
                {
                    Entity entity = (Entity)tm.GetObject(id, OpenMode.ForWrite, false);

                    if (entity is BaseTunnel)
                    {
                        BaseTunnel tunnel = (BaseTunnel)entity;
                        tunnel.Reflesh();
                    }
                    else if (entity is Node && Global.AnimateMode == false)
                    {
                        Node node = (Node)entity;
                        node.reflesh();
                    }
                }
            });
        }
Example #3
0
        //设置巷道分段温度
        public void setTemperature(int segment)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptEntityOptions options = new PromptEntityOptions("选择物体");
            PromptEntityResult  res     = ed.GetEntity(options);

            if (res.Status == PromptStatus.Cancel)
            {
                return;
            }

            Autodesk.AutoCAD.DatabaseServices.ObjectId id1 = res.ObjectId;
            Database db = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            Utils.TransactionControl(() =>
            {
                Entity ent = (Entity)tm.GetObject(id1, OpenMode.ForWrite, false);

                if (ent is BaseTunnel)
                {
                    BaseTunnel tunnel = ent as BaseTunnel;
                }
            });
        }
Example #4
0
        /// <summary>
        /// 将当前dwg文件中的巷道关系数据导出
        /// </summary>
        static public void OutputRlv()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            OutRelationship outData = new OutRelationship();

            Utils.SelectAll("TUNNEL_SQUARE,TUNNEL_CYLINDER", (idArray) =>
            {
                foreach (var id in idArray)
                {
                    Entity entity = (Entity)tm.GetObject(id, OpenMode.ForRead, true);
                    if (entity is BaseTunnel)
                    {
                        BaseTunnel tunnel                 = entity as BaseTunnel;
                        List <OutVertice> outVertices     = new List <OutVertice>();
                        List <Edge <OutVertice> > inEdges = new List <Edge <OutVertice> >();

                        for (int i = 0; i < tunnel.BasePoints.Count; i++)
                        {
                            Point3d vt = tunnel.BasePoints[i];
                            outVertices.Add(new OutVertice(vt.X, vt.Y, vt.Z));
                            if (i > 0)
                            {
                                inEdges.Add(new Edge <OutVertice>(outVertices[i - 1], outVertices[i]));
                            }
                        }
                        AdjacencyGraph <OutVertice, Edge <OutVertice> > graph =
                            new AdjacencyGraph <OutVertice, Edge <OutVertice> >();
                        graph.AddVerticesAndEdgeRange(inEdges);
                        List <Tuple <OutVertice, OutVertice> > outEdges = new List <Tuple <OutVertice, OutVertice> >();

                        foreach (var edge in graph.Edges)
                        {
                            outEdges.Add(new Tuple <OutVertice, OutVertice>(edge.Source, edge.Target));
                        }
                        outData.VerticeList.AddRange(outVertices);
                        outData.EdgeList.AddRange(outEdges);
                    }
                }
            });
            string path = Project.Instance.DataPath + "relationship.json";

            if (File.Exists(path))
            {
                try
                {
                    File.Delete(path);
                }
                catch (IOException) { }
            }

            string str = JsonConvert.SerializeObject(outData);

            Fs.WriteStr(str, path);
        }
Example #5
0
        /// <summary>
        /// 将当前dwg文件中的巷道与节点几何数据导出
        /// </summary>
        public static void OutputGeo()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            List <OutGeometry> outDatas = new List <OutGeometry>();

            Utils.SelectAll("TUNNEL_SQUARE,TUNNEL_CYLINDER,TUNNELNODE", (idArray) =>
            {
                foreach (var id in idArray)
                {
                    Entity entity = (Entity)tm.GetObject(id, OpenMode.ForRead, true);
                    if (entity is BaseTunnel)
                    {
                        BaseTunnel tunnel       = entity as BaseTunnel;
                        List <int> faces        = tunnel.GetAllFaces();
                        List <Point3d> vertices = tunnel.GetAllVertices();

                        OutGeometry outData = new OutGeometry();
                        outData.Type        = "Tunnel";
                        outData.FaceList    = OutGeometry.toOutFace(faces);
                        outData.VerticeList = vertices.ConvertAll(
                            new Converter <Point3d, OutVertice>(OutVertice.Point3dToOutVertice));
                        outData.ColorList = tunnel.GetVerticesColors();

                        outDatas.Add(outData);
                    }
                    else if (entity is Node)
                    {
                        Node node           = entity as Node;
                        OutGeometry outData = new OutGeometry();
                        outData.Type        = "Node";
                        outData.Position    = new OutVertice(node.Position.X, node.Position.Y, node.Position.Z);
                        outData.Radius      = node.Radius;
                        outData.NodeColor   = node.NodeColor;

                        outDatas.Add(outData);
                    }
                }
            });

            string path = Project.Instance.DataPath + "geometry.json";

            if (File.Exists(path))
            {
                try
                {
                    File.Delete(path);
                }
                catch (IOException) { }
            }

            string str = JsonConvert.SerializeObject(outDatas);

            Fs.WriteStr(str, path);
        }
Example #6
0
 static public void nodesvisible()
 {
     Utils.SelectOne("选择巷道", (ent) => {
         if (ent is BaseTunnel)
         {
             BaseTunnel tunnel   = ent as BaseTunnel;
             bool visible        = tunnel.DisplayNodes;
             tunnel.DisplayNodes = !visible;
         }
     });
 }
Example #7
0
        static public void GetEntity()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptEntityOptions options = new PromptEntityOptions("选择物体");
            PromptEntityResult  res     = ed.GetEntity(options);

            if (res.Status == PromptStatus.Cancel)
            {
                return;
            }

            ObjectId id1 = res.ObjectId;

            Database db = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            Utils.TransactionControl(() =>
            {
                Entity ent = (Entity)tm.GetObject(id1, OpenMode.ForWrite, false);

                if (ent is BaseTunnel)
                {
                    BaseTunnel tunnel = ent as BaseTunnel;
                    Random rd         = new Random();
                    int s             = rd.Next(1, 10);
                    tunnel.Segment    = s;

                    List <uint> colors        = new List <uint>();
                    List <short> temperatures = new List <short>();
                    for (int i = 0; i < s + 1; i++)
                    {
                        short t = (short)rd.Next(1, 99);
                        temperatures.Add(t);
                        uint color = Utils.temperature2uint(t);
                        colors.Add(color);
                    }

                    tunnel.Colors       = colors;
                    tunnel.Temperatures = temperatures;
                }
                else if (ent is Node)
                {
                    Node node = ent as Node;
                }
            });
        }
Example #8
0
        //添加节点
        static void appendNode(BaseTunnel tunnel)
        {
            List <Handle> nodesHandle = new List <Handle>();

            for (int j = 0; j < tunnel.BasePoints.Count; j++)
            {
                Node node = new Node();
                node.Position = tunnel.BasePoints[j];
                node.Name     = "节点";
                node.Location = tunnel.Location;
                Utils.AppendEntity(node);
                node.AppendTunnel(tunnel.Handle, j);
                nodesHandle.Add(node.Handle);
                node.Dispose();
            }
            tunnel.NodesHandle = nodesHandle;
        }
Example #9
0
        private void Db_ObjectOpenedForModify(object sender, ObjectEventArgs e)
        {
            if (e.DBObject is BaseTunnel)
            {
                BaseTunnel tunnel = e.DBObject as BaseTunnel;

                Document        doc       = Application.DocumentManager.MdiActiveDocument;
                DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

                DBEntity oldTunnel = dbControl.FindOne
                                         (Query.EQ("HandleValue", e.DBObject.ObjectId.Handle.Value));
                if (oldTunnel != null && tunnel.Location != oldTunnel.Location)
                {
                    tunnel.Location = oldTunnel.Location;
                }
            }
        }
Example #10
0
        public void setTunnelClosed()
        {
            Utils.SelectOne("选择巷道", (entity) => {
                if (entity is BaseTunnel)
                {
                    BaseTunnel tunnel = entity as BaseTunnel;

                    if (tunnel.Closed == false)
                    {
                        tunnel.SetClose(true);
                    }
                    else
                    {
                        tunnel.SetClose(false);
                    }
                }
            });
        }
Example #11
0
        /// <summary>
        /// 点击后的事件,目前有将点击物体显示到表格
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void callback_PromptForSelectionEnding(object sender, PromptForSelectionEndingEventArgs e)
        {
            bool eq = true;

            if (e.Selection.Count != selectionHandleSet.Count)
            {
                eq = false;
            }
            else
            {
                for (int i = 0; i < e.Selection.Count; i++)
                {
                    eq = e.Selection[i].ObjectId.Handle.Equals(selectionHandleSet[i]);
                    if (!eq)
                    {
                        break;
                    }
                }
            }

            if (eq)
            {
                return;
            }
            selectionHandleSet.Clear();
            foreach (var objectid in e.Selection.GetObjectIds())
            {
                selectionHandleSet.Add(objectid.Handle);
            }

            if (!BaseTunnel.getIsNodifying() && !BaseTunnel.getIsAnimateMode())
            {
                Global.ChangeSelection(sender, e.Selection);
            }
            else
            {
                BaseTunnel.endNodifying();
            }
        }
Example #12
0
        private void dataUpdated(object sender, DBEntity dbEntity)
        {
            Document        doc       = Application.DocumentManager.MdiActiveDocument;
            Database        db        = doc.Database;
            DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

            if (dbControl.Senders.Contains(db))
            {
                return;
            }

            Handle handle = new Handle(dbEntity.HandleValue);

            using (DocumentLock docLock = doc.LockDocument())
            {
                Utils.TransactionControl(() =>
                {
                    Entity ent = Utils.OpenEntityByHandle(handle);

                    if (ent is Node)
                    {
                        Node node     = ent as Node;
                        DBNode dbNode = dbEntity as DBNode;

                        dbNode.ToCADObject(node);
                    }
                    else if (ent is BaseTunnel)
                    {
                        BaseTunnel tunnel = ent as BaseTunnel;
                        DBTunnel dbTunnel = dbEntity as DBTunnel;

                        dbTunnel.ToCADObject(tunnel);
                    }
                });
            }
        }
Example #13
0
        //添加标注
        static private void appendTag(BaseTunnel tunnel)
        {
            var vvs = tunnel.VerticalVectors;
            var vv  = vvs[vvs.Count / 2];

            var cvs = tunnel.CenterVectors;
            var cv  = cvs[cvs.Count / 2];

            var av = tunnel.BasePoints[tunnel.BasePoints.Count / 2 - 1] -
                     tunnel.BasePoints[tunnel.BasePoints.Count / 2];
            var stdPoint = tunnel.BasePoints[tunnel.BasePoints.Count / 2] + av / 2;
            var lfPoint  = stdPoint + vv * cv.Length / 5;

            var endPoint = lfPoint + cv / 7;
            Tag tag      = new Tag();

            tag.StartPoint      = stdPoint;
            tag.InflectionPoint = lfPoint;
            tag.EndPoint        = endPoint;
            Utils.AppendEntity(tag);
            tunnel.TagHandle = tag.Handle;

            tag.Dispose();
        }
Example #14
0
 private void arrowMove(object sender, EventArgs e)
 {
     BaseTunnel.startAnimateMode();
     Utils.ReflushViewport(idarray);
 }
Example #15
0
        //通过cad对象设置litedb对象
        public override void SetProperty(Entity ent)
        {
            base.SetProperty(ent);

            BaseTunnel tunnel = ent as BaseTunnel;

            if (tunnel.TunnelType == Tunnel_type_s)
            {
                this.Type    = Tunnel_type_s;
                this.Width_t = ((SquareTunnel)tunnel).Width_t;
                this.Width_b = ((SquareTunnel)tunnel).Width_b;
                this.Height  = ((SquareTunnel)tunnel).Height;
            }
            else if (tunnel.TunnelType == Tunnel_type_t)
            {
                this.Type    = Tunnel_type_t;
                this.Width_t = ((SquareTunnel)tunnel).Width_t;
                this.Width_b = ((SquareTunnel)tunnel).Width_b;
                this.Height  = ((SquareTunnel)tunnel).Height;
            }
            else if (tunnel.TunnelType == Tunnel_type_c)
            {
                this.Type   = Tunnel_type_c;
                this.Radius = ((CylinderTunnel)tunnel).Radius;
            }
            else
            {
                throw new System.Exception("类型错误");
            }

            this.Name = tunnel.Name;

            this.TagData = tunnel.TagData;

            this.Location = tunnel.Location;

            this.Segment = tunnel.Segment;

            this.Temperatures = tunnel.Temperatures;

            this.BasePoints = new List <DBVertice>();

            int i = 0;

            foreach (var point in tunnel.BasePoints)
            {
                DBVertice p;
                if (tunnel.NodesHandle.Count > 0)
                {
                    p = new DBVertice(point.X, point.Y, point.Z);
                    p.NodeHandleValue = tunnel.NodesHandle[i].Value;
                }
                else
                {
                    p = new DBVertice(point.X, point.Y, point.Z);
                }

                p.Index = i;
                if (tunnel.NodesHandle.Count > i)
                {
                    p.NodeHandleValue = tunnel.NodesHandle[i].Value;
                }
                this.BasePoints.Add(p);
                i++;
            }

            this.DisplayTag = tunnel.DisplayTag;
            this.IsClosed   = tunnel.Closed;
        }
Example #16
0
        //通过数据库对象修改cad对象
        public void ToCADObject(BaseTunnel tunnel)
        {
            int segmentCount = this.BasePoints.Count;

            var dbVertices = this.BasePoints;

            List <Point3d> points3d    = new List <Point3d>();
            List <Handle>  nodesHandle = new List <Handle>();

            foreach (var dbVertice in dbVertices)
            {
                points3d.Add(new Point3d(dbVertice.X, dbVertice.Y, dbVertice.Z));
                nodesHandle.Add(new Handle(dbVertice.NodeHandleValue));
            }
            for (int i = 0; i < nodesHandle.Count; i++)
            {
                if (nodesHandle[i].Value == 0)  //新产生的Node
                {
                    Node node = new Node();
                    node.Position = points3d[i];
                    node.Location = this.Location;
                    Utils.AppendEntity(node);
                    node.AppendTunnel(tunnel.Handle, i);
                    nodesHandle[i] = node.Handle;
                }
                else   //之前的Node,改变索引
                {
                    Node node = Utils.GetEntityByHandle(nodesHandle[i]) as Node;
                    if (node == null)
                    {
                        continue;
                    }

                    node.ChangeIndex(tunnel.Handle, i);
                }
            }

            if (this.Type == Tunnel_type_s || this.Type == Tunnel_type_t)
            {
                ((SquareTunnel)tunnel).Width_t = this.Width_t;
                ((SquareTunnel)tunnel).Width_b = this.Width_b;
                ((SquareTunnel)tunnel).Height  = this.Height;
            }
            else if (this.Type == Tunnel_type_c)
            {
                ((CylinderTunnel)tunnel).Radius = this.Radius;
            }
            else
            {
                throw new System.Exception("类型错误");
            }

            tunnel.TunnelType   = this.Type;
            tunnel.BasePoints   = points3d;
            tunnel.NodesHandle  = nodesHandle;
            tunnel.Name         = this.Name;
            tunnel.TagData      = this.TagData;
            tunnel.Location     = this.Location;
            tunnel.DisplayTag   = this.DisplayTag;
            tunnel.Segment      = this.Segment;
            tunnel.Temperatures = this.Temperatures;
            tunnel.Colors       = this.Colors;
            tunnel.SetClose(this.IsClosed);
        }
Example #17
0
 private void RModeButton_Click(object sender, EventArgs e)
 {
     BaseTunnel.setDisplayMode(3);
     selectAll();
     Utils.ReflushViewport(idarray);
 }