public PipeItemModel GetPipeItemInfo(Polyline line, List <MText> txtList) { PipeItemModel item = new PipeItemModel(); try { item.PipeLength = line.Length.ToString(); item.Style.LineWidth = line.ConstantWidth.ToString(); item.ColorIndex = line.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(line.LayerId) : System.Drawing.ColorTranslator.ToHtml(line.Color.ColorValue); Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction tran = db.TransactionManager.StartTransaction()) { int vtnum = line.NumberOfVertices; MText mText = MethodCommand.FindMTextIsInPolyineForPipe(line, txtList); if (mText != null) { item.TxtLocation = new System.Drawing.PointF((float)mText.Location.X, (float)mText.Location.Y); item.PipeType = mText.Text; //Replace(" ", "").Replace(" ", ""); item.PipeLayer = mText.Layer; } } item.pipeList = PolylineMethod.GetPolyLineInfoPt(line); } catch { } return(item); }
public static Dictionary <int, List <PointF> > GetPolylinesPoints(string layerName) { Dictionary <int, List <System.Drawing.PointF> > pts = new Dictionary <int, List <System.Drawing.PointF> >(); List <Polyline> list = GetPolyliness(layerName); for (int i = 0; i < list.Count; i++) { pts.Add(i, PolylineMethod.GetPolyLineInfoPt(list[i])); } return(pts); }
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); } }
public void GetAllLengedGemo(T model) { List <BlockInfoModel> list = new List <BlockInfoModel>(); List <Polyline> allLengenPolyine = new List <Polyline>(); Document doc = Application.DocumentManager.MdiActiveDocument; ObjectIdCollection ids = new ObjectIdCollection(); TypedValue[] filList = new TypedValue[1] { new TypedValue((int)DxfCode.LayerName, "图例") }; PromptSelectionResult ProSset = null; SelectionFilter sfilter = new SelectionFilter(filList); LayoutManager layoutMgr = LayoutManager.Current; string ss = layoutMgr.CurrentLayout; ProSset = doc.Editor.SelectAll(sfilter); // List<ObjectId> idss= GetEntitiesInModelSpace(); Database db = doc.Database; List <BlockReference> blockTableRecords = new List <BlockReference>(); if (ProSset.Status == PromptStatus.OK) { using (Transaction tran = db.TransactionManager.StartTransaction()) { SelectionSet sst = ProSset.Value; ObjectId[] oids = sst.GetObjectIds(); int ad = 0; List <string> aa = new List <string>(); LayerModel lm = new LayerModel(); LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead); foreach (ObjectId layerId in lt) { LayerTableRecord ltr = (LayerTableRecord)tran.GetObject(layerId, OpenMode.ForRead); if (ltr.Name == MethodCommand.LegendLayer) { lm.Color = System.Drawing.ColorTranslator.ToHtml(ltr.Color.ColorValue); } } for (int i = 0; i < oids.Length; i++) { // if (idss.Contains(oids[i])) // { DBObject ob = tran.GetObject(oids[i], OpenMode.ForRead); // if (!aa.Contains((ob as Polyline).BlockName)) { aa.Add((ob as Polyline).BlockName); } if (ob is Polyline && (((ob as Polyline).BlockName.ToLower() == "*model_space" && UI.MainForm.isOnlyModel) || (!UI.MainForm.isOnlyModel))) { if (ob == null) { } else { allLengenPolyine.Add((ob as Polyline)); }// lengedList.Add(ob as Polyline); // model.LegendPoints.Add(ad, PolylineMethod.GetPolyLineInfoPt(ob as Polyline)); // ad++; } else if (ob is BlockReference && (((ob as BlockReference).BlockName.ToLower() == "*model_space" && UI.MainForm.isOnlyModel) || (!UI.MainForm.isOnlyModel))) { blockTableRecords.Add(ob as BlockReference); } } Dictionary <int, List <Polyline> > plList = MethodCommand.FindMaxAreaPoline(allLengenPolyine); model.LegendList = new List <LengedModel>(); this.lengedList = plList[0]; foreach (Polyline polyline in plList[0]) { LengedModel legm = new LengedModel(); legm.GemoModels = new List <BlockInfoModel>(); legm.BoxPointList = PolylineMethod.GetPolyLineInfoPt(polyline); List <ObjectId> ois = GetCrossObjectIds(doc.Editor, polyline, sfilter, tran); if (ois != null) { foreach (ObjectId lengGemo in ois) { DBObject ob = tran.GetObject(lengGemo, OpenMode.ForRead); BlockInfoModel plModel = MethodCommand.AnalysisBlcokInfo(ob); if (plModel != null) { if (plModel.Hatch != null) { HatchModel rem = new HatchModel(); foreach (HatchModel hatchModel in plModel.Hatch) { if (polyline.Closed && hatchModel.Area.ToString("F2") == polyline.Area.ToString("F2")) { legm.BackGround = hatchModel.loopPoints.Count > 0? hatchModel.loopPoints[0].Color:""; rem = hatchModel; break; } } plModel.Hatch.Remove(rem); } List <object> obj = new List <object>() { plModel }; legm.GemoModels.Add(plModel); } //if (ob is Polyline && (ob as Polyline).BlockName.ToLower() == "*model_space") //{ // BlockInfoModel plModel = new BlockInfoModel(); // plModel.PolyLine = AutoCad2ModelTools.Polyline2Model(ob as Polyline); // legm.GemoModels.Add(plModel); //} //else if (ob is BlockReference && (ob as BlockReference).BlockName.ToLower() == "*model_space") //{ // legm.GemoModels.Add(BlockCommand.AnalysisEntryAndExitbr(ob as BlockReference)); //} //else if (ob is DBText && (ob as DBText).BlockName.ToLower() == "*model_space") //{ // BlockInfoModel plModel = new BlockInfoModel(); // plModel.DbText = AutoCad2ModelTools.DbText2Model(ob as DBText); // legm.GemoModels.Add(plModel); //} //else if (ob is MText && (ob as MText).BlockName.ToLower() == "*model_space") //{ // BlockInfoModel plModel = new BlockInfoModel(); // plModel.DbText = AutoCad2ModelTools.DbText2Model(ob as MText); // legm.GemoModels.Add(plModel); //} //else if (ob is Hatch && (ob as Hatch).BlockName.ToLower() == "*model_space") //{ // BlockInfoModel plModel = new BlockInfoModel(); // plModel.Hatch = AutoCad2ModelTools.Hatch2Model(ob as Hatch); // legm.GemoModels.Add(plModel); //} //else if (ob is Circle && (ob as Circle).BlockName.ToLower() == "*model_space") //{ // BlockInfoModel plModel = new BlockInfoModel(); // plModel.Circle.Add(AutoCad2ModelTools.Circle2Model(ob as Circle)); // legm.GemoModels.Add(plModel); //} //else if (ob is Entity) //{ //} } } model.LegendList.Add(legm); } } } }