public RoadInfoItemModel GetRoadItemInfo(MText text)
        {
            RoadInfoItemModel item = new RoadInfoItemModel();

            item.RoadLength = "";
            item.RoadWidth  = "";
            item.RoadType   = "";
            item.ColorIndex = "";

            using (Transaction tran = CadHelper.Instance.Database.TransactionManager.StartTransaction())
            {
                item.RoadName         = text.Text.Replace(" ", "").Replace(" ", "").Replace("\r", "").Replace("\n", "");
                item.RoadNameLocaiton = new List <System.Drawing.PointF>();
                double textLen    = text.TextHeight * item.RoadName.Length + text.LineSpaceDistance * (item.RoadName.Length - 1);
                double partLength = textLen / item.RoadName.Length;

                for (int j = 1; j < item.RoadName.Length + 1; j++)
                {
                    item.RoadNameLocaiton.Add(MethodCommand.GetEndPointByTrigonometricHu(text.Rotation, MethodCommand.Point3d2Pointf(text.Location), partLength * j));
                }

                item.RoadNameLayer = text.Layer;
                item.RoadNameType  = "text";
            }
            return(item);
        }
Exemple #2
0
        public RoadInfoItemModel GetRoadItemInfo(Polyline line, List <DBText> txtList, List <Polyline> sectionLineList, List <DBText> sectionTextList)
        {
            RoadInfoItemModel item = new RoadInfoItemModel();

            item.RoadLength = line.Length.ToString();
            item.RoadWidth  = line.ConstantWidth.ToString();
            item.RoadType   = "polyline";
            item.ColorIndex = line.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(line.LayerId) : System.Drawing.ColorTranslator.ToHtml(line.Color.ColorValue);
            item.roadList   = PolylineMethod.GetPolyLineInfoPt(line);
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            using (Transaction tran = db.TransactionManager.StartTransaction())
            {
                int vtnum = line.NumberOfVertices;
                for (int i = 0; i < vtnum - 1; i++)
                {
                    foreach (DBText mText in txtList)
                    {
                        if (item.RoadName != null)
                        {
                            break;
                        }
                        Point2d pt = mText.AlignmentPoint.Convert2d(new Plane());



                        if (PolylineMethod.PtInPolyLine(pt, line.GetPoint2dAt(i), line.GetPoint2dAt(i + 1), 20) == 1)
                        {
                            item.RoadName         = mText.TextString.Replace(" ", "").Replace(" ", "");
                            item.RoadNameLocaiton = new List <System.Drawing.PointF>();
                            item.sectionList      = new List <RoadSectionItemModel>();

                            double middleLen  = MethodCommand.DistancePointToPoint(mText.Position, mText.AlignmentPoint);
                            double textLen    = MethodCommand.GetEndLengthByTheorem(middleLen, mText.Height / 2) * 2;
                            double partLength = textLen / item.RoadName.Length;

                            for (int j = 1; j < item.RoadName.Length + 1; j++)
                            {
                                item.RoadNameLocaiton.Add(MethodCommand.GetEndPointByTrigonometricHu(mText.Rotation, MethodCommand.Point3d2Pointf(mText.Position), partLength * j));
                            }

                            item.RoadNameLayer = mText.Layer;
                            item.RoadNameType  = "text";

                            break;
                        }
                    }
                    //获取横截面


                    foreach (Polyline pl in sectionLineList)
                    {
                        for (int j = 0; j < pl.NumberOfVertices; j++)
                        {
                            double dic = MethodCommand.DistancePointToSegment(pl.GetPoint2dAt(j), line.GetPoint2dAt(i), line.GetPoint2dAt(i + 1));
                            if (dic < 60)
                            {
                                RoadSectionItemModel modelsc = new RoadSectionItemModel();
                                modelsc.Line = AutoCad2ModelTools.Polyline2Model(pl);
                                DBText secMtext = MethodCommand.FindMTextIsInPolyineForPipe(pl, sectionTextList);
                                if (secMtext != null)
                                {
                                    modelsc.SectionName = AutoCad2ModelTools.DbText2Model(secMtext);
                                }
                                item.sectionList.Add(modelsc);
                            }
                        }
                    }
                }

                item.isDashed = MethodCommand.GetLayerLineTypeByIDEx(line);

                item.individualName   = "";
                item.individualFactor = "";
                item.individualCode   = "";
                item.individualStage  = "";

                // 增加个体编码、个体要素、个体名称
                System.Data.DataTable tb = Method.AutoGenerateNumMethod.GetAllPolylineNumsEx(line);
                if (tb.Rows != null && tb.Rows.Count > 0)
                {
                    foreach (System.Data.DataRow row in tb.Rows)
                    {
                        if ((string)row["多段线id"] == line.Id.Handle.Value.ToString())
                        {
                            item.individualName   = (string)row["个体名称"];
                            item.individualFactor = (string)row["个体要素"];
                            item.individualCode   = (string)row["个体编码"];
                            item.individualStage  = (string)row["个体阶段"];
                        }
                    }
                }
                return(item);
            }
        }