コード例 #1
0
ファイル: FormModif.cs プロジェクト: 15831944/CadAutoDraw
        private void button1_Click(object sender, EventArgs e)
        {
            if (changeValues != null)
            {
                if (T_From_Name.Text != BiStation.FromStation.Name || T_From_Loc.Text != BiStation.FromStation.Location || T_To_Name.Text != BiStation.ToStation.Name || T_To_Loc.Text != BiStation.ToStation.Location)
                {
                    DialogResult messageboxResult = MessageBox.Show("确认变更?", "注意", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                    if (messageboxResult == DialogResult.Yes)
                    {
                        //from
                        Form1.StationAndLocation from = new Form1.StationAndLocation(BiStation.FromStation.ID.ToString(), T_From_Name.Text.Replace(" ", "").ToString(), T_From_Loc.Text.ToUpper());
                        //to
                        Form1.StationAndLocation to = new Form1.StationAndLocation(BiStation.ToStation.ID.ToString(), T_To_Name.Text.Replace(" ", "").ToString(), T_To_Loc.Text.ToUpper());

                        NewBiStation = new Form1.BinoStation(from, to);

                        Index_NewBiStation = new index_BinoStation(indexThis, NewBiStation);
                    }
                }
                changeValues(this, EventArgs.Empty);  //当窗体触发事件,传递自身引用
                MessageBox.Show(BiStation.FromStation.Name + "-->" + T_From_Name.Text + System.Environment.NewLine +
                                BiStation.FromStation.Location + "-->" + T_From_Loc.Text + System.Environment.NewLine +
                                BiStation.ToStation.Name + "-->" + T_To_Name.Text + System.Environment.NewLine +
                                BiStation.ToStation.Location + "-->" + T_To_Loc.Text, "已修改");
            }
        }
コード例 #2
0
        /*public class StationAndLocation
         * {
         *  private string _stationName;
         *  private string _stationLocation;
         *
         *  public string stationName
         *  {
         *      get { return _stationName; }
         *      set { _stationName = value; }
         *  }
         *
         *  public string stationLocation
         *  {
         *      get { return _stationLocation; }
         *      set { _stationLocation = value; }
         *  }
         *
         *  public StationAndLocation(string Name, string Location)
         *  {
         *      this.stationName = Name;
         *      this.stationLocation = Location;
         *  }
         * }
         */
        public bool drawSL(Form1.StationAndLocation station_location, string selectedLayer)//Point3d startDrawPoint, , string BlockName)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    DocumentLock m_DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();

                    //用于生成图块, 如站点图块,铁路标识
                    if (CheckBlock(db, trans)) //检查预设的块是否存在,如不存在新建
                    {
                        //绘制背景.
                        //为每张图生成块表
                        List <string> list_Block_Name = new List <string>();
                        drawRightSideBackGround(db, trans, new Point3d(0, 0, 0), list_Block_Name, selectedLayer);

                        //插入块
                        //在相应位置插入图块和实体
                        trans.Commit();
                    }
                    else
                    {
                        Application.ShowAlertDialog("Error");
                    }

                    //插入表示站点图形

                    //Point3d insertP = new Point3d();
                    //DrawStationMark(db, trans, insertP, true);
                    //DrawStationMark(db, trans, insertP, false);


                    m_DocumentLock.Dispose();
                }
                catch (Exception ee)
                {
                    Application.ShowAlertDialog("Message: " + ee.Message.ToString() + System.Environment.NewLine + "Source: " + ee.Source.ToString() + System.Environment.NewLine + "TargetSite: " + ee.TargetSite.ToString() + System.Environment.NewLine + "StackTrace: " + ee.StackTrace.ToString());
                }
            }
            bool   isSuc           = false;
            string stationName     = station_location.Name;
            string stationLocation = station_location.Location;

            //画表格



            //插入站名

            //插入站里程

            //插入站间距离


            return(isSuc);
        }
コード例 #3
0
        public bool CheckBlock(Database db, Transaction trans)
        {
            bool allCheck = false;

            BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
            bool       hasLeftSideMark  = false;
            bool       hasRightSideMark = false;
            bool       hasRailWayMark   = false;
            //查找是已存在站点标识

            Point3d insertPoint = new Point3d();

            //如果不存在右侧标识则新建块
            if (!bt.Has("到达站站点标示"))
            {
                Form1.StationAndLocation station_location = new Form1.StationAndLocation("1", "吉林站", "DK0+000");
                CreateStationMark(db, trans, insertPoint, false, station_location);
            }

            //如果不存在左侧标识则新建块
            //Point3d insertPoint2 = new Point3d(insertPoint.X + 100, insertPoint.Y, insertPoint.Z);
            if (!bt.Has("始发站站点标示"))
            {
                Form1.StationAndLocation station_location = new Form1.StationAndLocation("1", "蛟河西站", "DK66+535");
                CreateStationMark(db, trans, insertPoint, true, station_location);
            }

            //如果不存在铁轨标识则新建块
            if (!bt.Has("铁轨_Length_248"))
            {
                CreateRailWayMark(db, trans, insertPoint, "XX上行线/下行线");
            }

            allCheck = true;
            return(allCheck);
        }
コード例 #4
0
        //新建站点标识
        private void CreateStationMark(Database db, Transaction trans, Point3d insertPoint, bool isLeft, Form1.StationAndLocation station_location)
        {
            // Open the Block table for read
            BlockTable acBlkTbl;

            acBlkTbl = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

            // Open the Block table record Model space for write

            BlockTableRecord acBlkTblRec = new BlockTableRecord();

            acBlkTbl.UpgradeOpen();
            acBlkTbl.Add(acBlkTblRec);
            if (isLeft == false)
            {
                acBlkTblRec.Name = "到达站站点标示";
            }
            else
            {
                acBlkTblRec.Name = "始发站站点标示";
            }
            //acBlkTblRec = trans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;


            Point2d CircleCenter = new Point2d(insertPoint.X, insertPoint.Y);

            //画圆(左右两个半圆)
            //起始、终止角度
            double startAngle = 90;
            double endAngle   = 270;
            //内圆 由两个arc组成
            //左侧
            Arc InnerArcLeft = new Arc(new Point3d(CircleCenter.X, CircleCenter.Y, 0), 2, startAngle.DegreeToRadian(), endAngle.DegreeToRadian());

            acBlkTblRec.AppendEntity(InnerArcLeft);
            trans.AddNewlyCreatedDBObject(InnerArcLeft, true);

            //右侧
            Arc InnerArcRight = new Arc(new Point3d(CircleCenter.X, CircleCenter.Y, 0), 2, endAngle.DegreeToRadian(), startAngle.DegreeToRadian());

            acBlkTblRec.AppendEntity(InnerArcRight);
            trans.AddNewlyCreatedDBObject(InnerArcRight, true);

            //外圆 由两个arc组成
            //左侧
            Arc OuterArcLeft = new Arc(new Point3d(CircleCenter.X, CircleCenter.Y, 0), 4, startAngle.DegreeToRadian(), endAngle.DegreeToRadian());

            acBlkTblRec.AppendEntity(OuterArcLeft);
            trans.AddNewlyCreatedDBObject(OuterArcLeft, true);

            //右侧
            Arc OuterArcRight = new Arc(new Point3d(CircleCenter.X, CircleCenter.Y, 0), 4, endAngle.DegreeToRadian(), startAngle.DegreeToRadian());

            acBlkTblRec.AppendEntity(OuterArcRight);
            trans.AddNewlyCreatedDBObject(OuterArcRight, true);

            //直线
            Polyline pline = new Polyline();

            pline.CreatePolyline(new Point2d(CircleCenter.X, CircleCenter.Y + 4), new Point2d(CircleCenter.X, CircleCenter.Y - 36));
            acBlkTblRec.AppendEntity(pline);
            trans.AddNewlyCreatedDBObject(pline, true);

            //内辅助直线
            Polyline innerPline = new Polyline();

            innerPline.CreatePolyline(new Point2d(CircleCenter.X, CircleCenter.Y + 2), new Point2d(CircleCenter.X, CircleCenter.Y - 2));
            acBlkTblRec.AppendEntity(innerPline);
            trans.AddNewlyCreatedDBObject(innerPline, true);

            //外辅助直线
            Polyline outerPline = new Polyline();

            outerPline.CreatePolyline(new Point2d(CircleCenter.X, CircleCenter.Y + 4), new Point2d(CircleCenter.X, CircleCenter.Y - 4));
            acBlkTblRec.AppendEntity(outerPline);
            trans.AddNewlyCreatedDBObject(outerPline, true);

            //添加两个属性块: 站名,里程
            double textHeight = 3;
            AttributeDefinition AttStationName = new AttributeDefinition();

            //设置两个属性块对齐方式,对齐点
            AttStationName.TextString = "XXX站";
            AttStationName.Tag        = "站名";
            AttStationName.Prompt     = "输入站点名称";
            SetStyleForAttribut(AttStationName, textHeight, false);
            AttStationName.TextStyleId = ObjectId.Null;
            AttStationName.Justify     = AttachmentPoint.BaseCenter;

            //AttStationName.HorizontalMode = TextHorizontalMode.TextCenter; //水平方向取中点
            //AttStationName.VerticalMode = TextVerticalMode.TextVerticalMid;
            AttStationName.AlignmentPoint = new Point3d(insertPoint.X, insertPoint.Y + 6, 0);
            acBlkTblRec.AppendEntity(AttStationName);
            trans.AddNewlyCreatedDBObject(AttStationName, true);

            AttributeDefinition AttStationLocation = new AttributeDefinition();

            AttStationLocation.TextString = "XXX站";
            AttStationLocation.Tag        = "里程";
            AttStationLocation.Prompt     = "输入站点里程";
            SetStyleForAttribut(AttStationLocation, textHeight, false);
            AttStationLocation.TextStyleId = ObjectId.Null;
            AttStationLocation.Justify     = AttachmentPoint.TopLeft;

            /*
             * AttStationLocation.HorizontalMode = TextHorizontalMode.TextCenter; //水平方向取终点
             * AttStationLocation.VerticalMode = TextVerticalMode.TextBottom;
             * AttStationLocation.AlignmentPoint = new Point3d(insertPoint.X + 1, insertPoint.Y - 18, 0);
             */

            //double rotatedAngle = 90;
            //AttStationLocation.Rotation = rotatedAngle.DegreeToRadian();
            AttStationLocation.AlignmentPoint = new Point3d(insertPoint.X + 1, insertPoint.Y - 18, 0);

            acBlkTblRec.AppendEntity(AttStationLocation);
            trans.AddNewlyCreatedDBObject(AttStationLocation, true);


            if (isLeft == false)
            {
                ObjectIdCollection ids = new ObjectIdCollection();
                ids.Add(OuterArcLeft.ObjectId);
                ids.Add(outerPline.ObjectId);

                ObjectIdCollection ids2 = new ObjectIdCollection();
                ids2.Add(InnerArcLeft.ObjectId);
                ids2.Add(innerPline.ObjectId);

                Hatch hatch = new Hatch();
                acBlkTblRec.AppendEntity(hatch);

                trans.AddNewlyCreatedDBObject(hatch, true);

                hatch.SetDatabaseDefaults();

                hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");

                hatch.Associative = true;

                hatch.AppendLoop(HatchLoopTypes.Outermost, ids);

                hatch.AppendLoop(HatchLoopTypes.Default, ids2);

                hatch.EvaluateHatch(true);

                ids.Clear();
                ids2.Clear();
            }
            else
            {
                ObjectIdCollection ids = new ObjectIdCollection();
                ids.Add(OuterArcRight.ObjectId);
                ids.Add(outerPline.ObjectId);

                ObjectIdCollection ids2 = new ObjectIdCollection();
                ids2.Add(InnerArcRight.ObjectId);
                ids2.Add(innerPline.ObjectId);

                Hatch hatch = new Hatch();

                acBlkTblRec.AppendEntity(hatch);

                trans.AddNewlyCreatedDBObject(hatch, true);

                hatch.SetDatabaseDefaults();

                hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                //hatch.CreateHatch(HatchPatternType.PreDefined, "SOLID", true);
                hatch.Associative = true;

                hatch.AppendLoop(HatchLoopTypes.Outermost, ids);

                hatch.AppendLoop(HatchLoopTypes.Default, ids2);

                hatch.EvaluateHatch(true);

                ids.Clear();
                ids2.Clear();
            }
            //acBlkTbl.Add(acBlkTblRec);
            db.TransactionManager.AddNewlyCreatedDBObject(acBlkTblRec, true);
            acBlkTbl.DowngradeOpen();
        }