/// <summary> /// Scan a DGN model and return a list of elements /// </summary> /// <param name="criteria">ScanCriteria object</param> /// <returns>IEnumerable(Element) list of elements</returns> public static IEnumerable <BDPN.Elements.Element> Scan(this BDPN.ScanCriteria criteria) { var result = new List <BDPN.Elements.Element>(); criteria.Scan((e, m) => { result.Add(e); return(BDPN.StatusInt.Success); }); return(result); }
public static void LinestringUnite(string unparsed) { BD.ScanCriteria sc = new BD.ScanCriteria(); sc.SetModelRef(Program.GetActiveDgnModelRef()); BD.BitMask bm = new Bentley.DgnPlatformNET.BitMask(true); bm.Set((uint)BD.MSElementType.LineString); bm.Set((uint)BD.MSElementType.ComplexString); sc.SetElementTypeTest(bm); var cvlist = new List <BG.CurveVector>(); sc.Scan((ele, model) => { if (ele.ElementType == BD.MSElementType.LineString) { var stringEle = ele as BDE.LineStringElement; cvlist.Add(stringEle.GetCurveVector()); } if (ele.ElementType == BD.MSElementType.ComplexString) { var complexstring = ele as BDE.ComplexStringElement; cvlist.Add(complexstring.AsCurvePathEdit().GetCurveVector()); } return(BD.StatusInt.Success); }); var results = new List <BG.CurveVector>(); if (cvlist.Count > 0) { for (int i = 0; i < cvlist.Count - 1; i++) { for (int j = i + 1; j < cvlist.Count; j++) { var unitecv = BG.CurveVector.AreaUnion(cvlist[i], cvlist[j]); if (unitecv != null) { results.Add(unitecv); } } } } }
public void Add() { try { if (SelectedDgnLevel == null) { MessageBox.Show("未选择线段所在图层\n请重新选择图层", "未选择图层", MessageBoxButton.OK, MessageBoxImage.Error); return; } //扫描图中的线段 BD.ScanCriteria sc = new Bentley.DgnPlatformNET.ScanCriteria(); sc.SetModelRef(Program.GetActiveDgnModelRef()); BD.BitMask bm = new BD.BitMask(true); bm.Set((uint)BD.MSElementType.Line); sc.SetElementTypeTest(bm); var elelist = new List <BDE.Element>(); sc.Scan((ele, dgnmodel) => { var level = Program.GetActiveDgnModel().GetLevelCache().GetLevel(ele.LevelId, true); if (ele.ElementType == BD.MSElementType.Line && ele.LevelId == SelectedDgnLevel.LevelId) { elelist.Add(ele); } return(BD.StatusInt.Success); }); if (elelist.Count == 0) { MessageBox.Show("所选图层中不存在线段元素\n请重新选择图层或绘制代表桩的线段", "所选图层无线段", MessageBoxButton.OK, MessageBoxImage.Error); return; } PileFactory pilefactory = null; var pileproplist = new List <IPileProperty>(); var pilenamelist = new List <string>(); var pileIdlist = new List <long>(); switch (SelectedPileType) { case PileType.Solid: pilefactory = new SolidPileFactory(GammaR); foreach (var pile in elelist) { //BG.DRange3d range; //((BDE.LineElement)pile).CalcElementRange(out range);//有问题 BG.DPoint3d startp, endp; if (!((BDE.LineElement)pile).GetCurveVector().GetStartEnd(out startp, out endp)) { System.Windows.Forms.MessageBox.Show($"无法获取Pile ID:{pile.ElementId}的起始点和终点"); return; } switch (SelectedPileCrossSectionType) { case SoildPileCrossSectionType.SquareWithRoundHole: pileproplist.Add(new SquareWithRoundHolePileGeometry() { PileDiameter = this.PileDiameter, PileInnerDiameter = this.PileInnerDiameter, PileWeight = this.PileWeight, PileUnderWaterWeight = this.PileUnderwaterWeight, WaterLevel = WaterLevel, PileTopPoint = startp.DPoint3dToPoint3d(1e-4), PileBottomPoint = endp.DPoint3dToPoint3d(1e-4) }); break; case SoildPileCrossSectionType.Square: pileproplist.Add(new SquarePileGeometry() { PileDiameter = this.PileDiameter, PileWeight = this.PileWeight, PileUnderWaterWeight = this.PileUnderwaterWeight, WaterLevel = WaterLevel, PileTopPoint = startp.DPoint3dToPoint3d(1e-4), PileBottomPoint = endp.DPoint3dToPoint3d(1e-4) }); break; case SoildPileCrossSectionType.Polygon: pileproplist.Add(new PolygonPileGeometry() { CrossSectionArea = this.PolygonCrossSectionArea, PileCrossSectionPerimeter = this.PolygonCrossSectionPerimeter, PileWeight = this.PileWeight, PileUnderWaterWeight = this.PileUnderwaterWeight, WaterLevel = WaterLevel, PileTopPoint = startp.DPoint3dToPoint3d(1e-4), PileBottomPoint = endp.DPoint3dToPoint3d(1e-4) }); break; } var pilecodereaddatablock = pile.GetLinkage((ushort)BD.ElementLinkageId.String); string pilename = string.Empty; if (null != pilecodereaddatablock) { //throw new NotSupportedException($"Pile Id:{pile.ElementId} doesn't contain pilecode linkage"); pilename = pilecodereaddatablock.ReadString(); } else { pilename = pile.Description + " ID:" + pile.ElementId.ToString(); } pilenamelist.Add(PileName + pilename); pileIdlist.Add(pile.ElementId); } break; case PileType.SteelAndPercastConcrete: pilefactory = new SteelAndPercastConcretePileFactory(GammaR, Eta); foreach (var pile in elelist) { //BG.DRange3d range; //((BDE.LineElement)pile).CalcElementRange(out range); BG.DPoint3d startp, endp; if (!((BDE.LineElement)pile).GetCurveVector().GetStartEnd(out startp, out endp)) { System.Windows.Forms.MessageBox.Show($"无法获取Pile ID:{pile.ElementId}的起始点和终点"); return; } pileproplist.Add(new AnnularPileGeometry() { PileDiameter = this.PileDiameter, PileInnerDiameter = this.PileInnerDiameter, PileWeight = this.PileWeight, PileUnderWaterWeight = this.PileUnderwaterWeight, WaterLevel = WaterLevel, PileTopPoint = startp.DPoint3dToPoint3d(1e-4), PileBottomPoint = endp.DPoint3dToPoint3d(1e-4) }); var pilecodereaddatablock = pile.GetLinkage((ushort)BD.ElementLinkageId.String); string pilename = string.Empty; if (null != pilecodereaddatablock) { //throw new NotSupportedException($"Pile Id:{pile.ElementId} doesn't contain pilecode linkage"); pilename = pilecodereaddatablock.ReadString(); } pilenamelist.Add(PileName + pilename); pileIdlist.Add(pile.ElementId); } break; //case PileType.Filling: // pilefactory = new FillingPileFactory(); // break; //case PileType.Socketed: // pilefactory = new SocketedPileFactory(); // break; //case PileType.PostgroutingFilling: // pilefactory = new PostgroutingFillingPileFactory(); // break; } //foreach (var pile in elelist) //{ // BG.DRange3d range; // ((BDE.LineElement)pile).CalcElementRange(out range); // switch (SelectedPileCrossSectionType) // { // case PileCrossSectionType.Roundness: // pileproplist.Add(new RoundnessPileGeometry() { PileDiameter = this.PileDiameter, PileWeight = this.PileWeight, PileUnderWaterWeight = this.PileUnderwaterWeight, WaterLevel = WaterLevel, PileTopPoint = range.High.DPoint3dToPoint3d(1e-4), PileBottomPoint = range.Low.DPoint3dToPoint3d(1e-4) }); // break; // case PileCrossSectionType.Square: // pileproplist.Add(new SquarePileGeometry() { PileDiameter = this.PileDiameter, PileWeight = this.PileWeight, PileUnderWaterWeight = this.PileUnderwaterWeight, WaterLevel = WaterLevel, PileTopPoint = range.High.DPoint3dToPoint3d(1e-4), PileBottomPoint = range.Low.DPoint3dToPoint3d(1e-4) }); // break; // case PileCrossSectionType.Annular: // pileproplist.Add(new AnnularPileGeometry() { PileDiameter = this.PileDiameter, PileInnerDiameter = this.PileInnerDiameter, PileWeight = this.PileWeight, PileUnderWaterWeight = this.PileUnderwaterWeight, WaterLevel = WaterLevel, PileTopPoint = range.High.DPoint3dToPoint3d(1e-4), PileBottomPoint = range.Low.DPoint3dToPoint3d(1e-4) }); // break; // } // pilenamelist.Add(PileName + pile.GetLinkage((ushort)BD.ElementLinkageId.String).ReadString()); // pileIdlist.Add(pile.ElementId); //} var templist = pilefactory?.CreateNewPileArray(pileproplist.ToArray(), pilenamelist.ToArray(), pileIdlist.ToArray()); Piles.AddRange(templist); CloseAction(); } catch (Exception e) { MessageBox.Show(e.ToString()); } }