/// <summary> 将选择的曲线按指定的长度分割为多段线 </summary> public ExternalCmdResult CreatePolylineFromCurveByIntervals(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; // var pl = AddinManagerDebuger.PickObject<Curve>(docMdf.acEditor); // AutoCAD中的一列数据,并从高到低排序 var cv = SelectCurve(); if (cv == null) { return(ExternalCmdResult.Cancel); } var segLength = GetDistance(docMdf); var curve = cv.GetGeCurve(); var cp = eZcad.Utility.Utils.GetThinedPolyline(curve, segLength); // 绘制多段线 var pline = Polyline.CreateFromGeCurve(cp); if (pline == null) { return(ExternalCmdResult.Cancel); } var cs = EditStateIdentifier.GetCurrentEditState(docMdf); cs.CurrentBTR.UpgradeOpen(); cs.CurrentBTR.AppendEntity(pline); docMdf.acTransaction.AddNewlyCreatedDBObject(pline, true); cs.CurrentBTR.DowngradeOpen(); return(ExternalCmdResult.Commit); }
private void SetProtectionMethods(List <SlopeLine> slopeLines, string protMethod, int[] slopeLevels) { // 提取规则 var fp = new ForceProtection(protMethod, slopeLevels); var es = EditStateIdentifier.GetCurrentEditState(_docMdf); es.CurrentBTR.UpgradeOpen(); //var layer_Slope = Utils.GetOrCreateLayer(_docMdf, ProtectionConstants.LayerName_ProtectionMethod_Slope); //var layer_Platform = Utils.GetOrCreateLayer(_docMdf, ProtectionConstants.LayerName_ProtectionMethod_Platform); // 先修改内存中的防护 foreach (var slp in slopeLines) { slp.ForceProtect(fp); } // 再刷新到 AutoCAD 文档与界面中 var protLayers = ProtectionTags.MapProtectionLayers(_docMdf, slopeLines); foreach (var slp in slopeLines) { // 将数据刷新到界面与边坡线中 slp.Pline.UpgradeOpen(); slp.PrintProtectionMethod(es.CurrentBTR, protLayers); slp.FlushXData(); slp.Pline.DowngradeOpen(); } _docMdf.acEditor.UpdateScreen(); }
/// <summary> 计算选择的所有曲线的面积与长度之和 </summary> public ExternalCmdResult Polyline2Point(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; // var pl = SelectUtils.PickEntity <Polyline3d>(docMdf.acEditor, message: "选择一个三维多段线对象"); if (pl == null) { return(ExternalCmdResult.Cancel); } // var cs = EditStateIdentifier.GetCurrentEditState(docMdf); cs.CurrentBTR.UpgradeOpen(); foreach (ObjectId id in pl) { var vert = id.GetObject(OpenMode.ForRead) as PolylineVertex3d; if (vert != null) { var pt = vert.Position; DBPoint p = new DBPoint(pt); cs.CurrentBTR.AppendEntity(p); docMdf.acTransaction.AddNewlyCreatedDBObject(p, true); } } cs.CurrentBTR.DowngradeOpen(); return(ExternalCmdResult.Commit); }
/// <summary> 将分割开的多个子边坡进行合并 </summary> public ExternalCmdResult MergeSlopeSegs(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; SQUtils.SubgradeEnvironmentConfiguration(docMdf); // var selectedSlopes = SQUtils.SelecteExistingSlopeLines(docMdf, left: null, sort: true); if (selectedSlopes == null || selectedSlopes.Count == 0) { return(ExternalCmdResult.Cancel); } // MergeProtectionDirection dir; var succ = GetProtectionDirection(docMdf, out dir); if (!succ) { return(ExternalCmdResult.Cancel); } // //var layer_Slope = Utils.GetOrCreateLayer(_docMdf, ProtectionConstants.LayerName_ProtectionMethod_Slope); //var layer_WaterLine = Utils.GetOrCreateLayer_WaterLine(_docMdf); //var layer_Platform = Utils.GetOrCreateLayer(_docMdf, ProtectionConstants.LayerName_ProtectionMethod_Platform); var es = EditStateIdentifier.GetCurrentEditState(_docMdf); es.CurrentBTR.UpgradeOpen(); bool haveSegsMerged = false; int mergedCount = 0; docMdf.WriteLineIntoDebuger("合并的边坡对象:"); var protLayers = ProtectionTags.MapProtectionLayers(_docMdf, selectedSlopes); foreach (var slp in selectedSlopes) { haveSegsMerged = MergeSlope(slp.XData, dir); if (haveSegsMerged) { // 将刷新后的数据保存到 AutoCAD 文档与界面中 slp.Pline.UpgradeOpen(); // slp.ClearAllWaterlines(_docMdf.acDataBase); SlopeConstructor.SetSlopeUI(slp); slp.PrintProtectionMethod(es.CurrentBTR, protLayers); slp.FlushXData(); // slp.Pline.DowngradeOpen(); mergedCount += 1; docMdf.WriteLineIntoDebuger(slp); } } docMdf.WriteLineIntoDebuger($"总计:{mergedCount} 个"); // return(ExternalCmdResult.Commit); }
// 开始具体的调试操作 private void DoSomething(DocumentModifier docMdf, SelectionSet impliedSelection) { object srcTxt = null; var conti = GetText(_docMdf.acEditor, out srcTxt); if (!conti) { return; } string srcStr = GetText(srcTxt);; if (srcStr == null) { return; } string prefix; double num; double increment; string suffix; var succ = GetPrefixAndValue(srcStr, out prefix, out num, out suffix); // var st = EditStateIdentifier.GetCurrentEditState(_docMdf); st.CurrentBTR.UpgradeOpen(); if (succ) { increment = GetIncrement(_docMdf.acEditor); // txt 为 单行文字 或者 多选文字 对象 object txt = null; conti = GetText(_docMdf.acEditor, out txt); while (txt != null) { num += increment; var newText = prefix + num.ToString() + suffix; RefreshText(txt, newText); // conti = GetText(_docMdf.acEditor, out txt); } } else { // 只起到复制的功能 // object txt = null; conti = GetText(_docMdf.acEditor, out txt); while (txt != null) { RefreshText(txt, srcStr); // conti = GetText(_docMdf.acEditor, out txt); } } st.CurrentBTR.DowngradeOpen(); }
/// <summary> 按标高将边坡对象进行分割,以实现同一级边坡中分别设置不同的防护形式 </summary> private void CutSlopes(DocumentModifier docMdf, SlopeLine[] selectedSlopes, CutMethod method, double elev, double waterLineLength) { // ProtectionUtils.SubgradeEnvironmentConfiguration(docMdf); // //var layer_Slope = Utils.GetOrCreateLayer(docMdf, ProtectionConstants.LayerName_ProtectionMethod_Slope); var layer_WaterLine = eZcad.SubgradeQuantity.Utility.SQUtils.GetOrCreateLayer_WaterLine(docMdf); //var layer_Platform = Utils.GetOrCreateLayer(docMdf, ProtectionConstants.LayerName_ProtectionMethod_Platform); var es = EditStateIdentifier.GetCurrentEditState(docMdf); es.CurrentBTR.UpgradeOpen(); // Point2d intersPt; Slope intersSlopeSeg; int cutCount = 0; docMdf.WriteLineIntoDebuger("被分割的边坡对象:"); var protLayers = ProtectionTags.MapProtectionLayers(_docMdf, selectedSlopes); foreach (var slp in selectedSlopes) { var inters = ValidateElevation(slp, method, elev, out intersPt, out intersSlopeSeg); if (inters) { // 将子边坡按指定的交点进行剪切 var newSegs = CutSlopeSegment(slp.XData, intersSlopeSeg, new Point3d(intersPt.X, intersPt.Y, 0)); slp.XData.Slopes = newSegs; // 将被剪切掉的子边坡所绑定的文字删除 SlopeLine.EraseText(intersSlopeSeg, docMdf.acDataBase); // 绘制水位线 var line = new Line(new Point3d(intersPt.X - waterLineLength / 2, intersPt.Y, 0), new Point3d(intersPt.X + waterLineLength / 2, intersPt.Y, 0)); line.LayerId = layer_WaterLine.Id; es.CurrentBTR.AppendEntity(line); docMdf.acTransaction.AddNewlyCreatedDBObject(line, true); slp.XData.Waterlines.Add(line.Handle); // 将刷新后的数据保存到 AutoCAD 文档与界面中 slp.Pline.UpgradeOpen(); SlopeConstructor.SetSlopeUI(slp); slp.PrintProtectionMethod(es.CurrentBTR, protLayers); slp.FlushXData(); slp.Pline.DowngradeOpen(); // cutCount += 1; docMdf.WriteLineIntoDebuger(slp); } } es.CurrentBTR.DowngradeOpen(); docMdf.WriteLineIntoDebuger($"总计:{cutCount} 个"); }
/// <summary> 将边坡对象清理为一般的边坡线,并删除其中所有与边坡相关的数据 </summary> public ExternalCmdResult EraseSlope(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; SQUtils.SubgradeEnvironmentConfiguration(docMdf); // 所有的断面 // var allSections = ProtectionUtils.GetAllSections(docMdf,sort:true); var slopes = SQUtils.SelecteExistingSlopeLines(docMdf, left: null, sort: false); var es = EditStateIdentifier.GetCurrentEditState(_docMdf); es.CurrentBTR.UpgradeOpen(); foreach (var slp in slopes) { slp.ClearXData(); } es.CurrentBTR.DowngradeOpen(); return(ExternalCmdResult.Commit); }
/// <summary> 沿着道路纵向绘制边坡线 </summary> public ExternalCmdResult LongitudinalSection(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; SQUtils.SubgradeEnvironmentConfiguration(docMdf); var allSections = SQUtils.GetAllSections(docMdf, sort: true); if (allSections == null || allSections.Length <= 2) { return(ExternalCmdResult.Cancel); } if (allSections.Length > 1) { // var allStations = allSections.Select(r => r.XData.Station).ToArray(); var minStation = allStations.First(); // // 每一个桩号所对应的某一侧的挡墙顶与挡墙底相对于道路中线的高度,如果某桩号中没有挡墙,则其值为 null var leftRetainingWalls = new Dictionary <double, double[]>(); var rightRetainingWalls = new Dictionary <double, double[]>(); var leftSlps = ConstructLeftSlope(allSections, true, out leftRetainingWalls); var rightSlps = ConstructLeftSlope(allSections, false, out rightRetainingWalls); // 选择绘图的基点 Point3d p3; var succ = GetBasePt(_docMdf, out p3); if (!succ) { return(ExternalCmdResult.Cancel); } var basePt2D = new Point2d(p3.X, p3.Y); // double rx = 0.25; double ry = 2; // var ss = EditStateIdentifier.GetCurrentEditState(_docMdf); ss.CurrentBTR.UpgradeOpen(); var layer_Slope = SymbolTableUtils.GetOrCreateLayer(_docMdf.acTransaction, _docMdf.acDataBase, SQConstants.LayerName_LongitudinalSlopes); var originalLayer = docMdf.acDataBase.Clayer; docMdf.acDataBase.Clayer = layer_Slope.Id; // 绘制中轴线 var roadCenterPl = CreatePolyline(allStations, new double[allStations.Length], basePt2D, minStation, rx, ry); ss.CurrentBTR.AppendEntity(roadCenterPl); _docMdf.acTransaction.AddNewlyCreatedDBObject(roadCenterPl, true); // 绘制桩号 var txts = CreateDbTexts(allStations, new double[allStations.Length], basePt2D, minStation, rx, ry); foreach (var txt in txts) { ss.CurrentBTR.AppendEntity(txt); _docMdf.acTransaction.AddNewlyCreatedDBObject(txt, true); } // 绘制左边坡线 var leftPl = CreatePolyline(leftSlps.Keys.ToArray(), leftSlps.Values.ToArray(), basePt2D, minStation, rx, ry); leftPl.LineWeight = LineWeight.LineWeight013; leftPl.Color = Color.FromColor(System.Drawing.Color.Green); ss.CurrentBTR.AppendEntity(leftPl); _docMdf.acTransaction.AddNewlyCreatedDBObject(leftPl, true); // 绘制右边坡线 var rightPl = CreatePolyline(rightSlps.Keys.ToArray(), rightSlps.Values.ToArray(), basePt2D, minStation, rx, ry); rightPl.LineWeight = LineWeight.LineWeight013; rightPl.Color = Color.FromColor(System.Drawing.Color.Red); ss.CurrentBTR.AppendEntity(rightPl); _docMdf.acTransaction.AddNewlyCreatedDBObject(rightPl, true); // 绘制左边挡墙 var leftRetainingWallRanges = GetRetainingWallRanges(leftRetainingWalls); foreach (var rwr in leftRetainingWallRanges) { var pl = CreatePolyline(ArrayConstructor.GetColumn(rwr, 0), ArrayConstructor.GetColumn(rwr, 1), basePt2D, minStation, rx, ry); pl.Closed = true; pl.Color = Color.FromColor(System.Drawing.Color.LightGreen); pl.LineWeight = LineWeight.LineWeight050; ss.CurrentBTR.AppendEntity(pl); _docMdf.acTransaction.AddNewlyCreatedDBObject(pl, true); } // 绘制右边挡墙 var rightRetainingWallRanges = GetRetainingWallRanges(rightRetainingWalls); foreach (var rwr in rightRetainingWallRanges) { var pl = CreatePolyline(ArrayConstructor.GetColumn(rwr, 0), ArrayConstructor.GetColumn(rwr, 1), basePt2D, minStation, rx, ry); pl.Closed = true; pl.Color = Color.FromColor(System.Drawing.Color.DeepPink); pl.LineWeight = LineWeight.LineWeight050; ss.CurrentBTR.AppendEntity(pl); _docMdf.acTransaction.AddNewlyCreatedDBObject(pl, true); } // docMdf.acDataBase.Clayer = originalLayer; ss.CurrentBTR.DowngradeOpen(); } return(ExternalCmdResult.Commit); }
/// <summary> 根据边坡多段线进行道路边坡的筛选、信息提取、防护方式的设置等操作 </summary> public void ConfigerSlopes(IList <Polyline> slopeLines, bool justModifyCalculated) { if (slopeLines == null || slopeLines.Count == 0) { return; } // var app = SymbolTableUtils.GetOrCreateAppName(_docMdf.acDataBase, _docMdf.acTransaction, SlopeData.AppName); var selectedSlpLines = new List <SlopeLine>(); string errMsg; foreach (var sl in slopeLines) { var slpLine = SlopeLine.Create(_docMdf, sl, out errMsg); if (slpLine != null) { // 将存储的数据导入边坡对象 slpLine.ImportSlopeData(slpLine.XData); // if (!slpLine.XData.FullyCalculated || !justModifyCalculated) { slpLine.CalculateXData(); } selectedSlpLines.Add(slpLine); } else { _docMdf.WriteNow(errMsg); } } if (selectedSlpLines.Count == 0) { return; } var slopesWithSlopesegs = new List <SlopeLine>(); var slopesWithoutSlopesegs = new List <SlopeLine>(); foreach (var slp in selectedSlpLines) { if (slp.XData.Slopes.Count + slp.XData.Platforms.Count > 0) { slopesWithSlopesegs.Add(slp); } else { slopesWithoutSlopesegs.Add(slp); } } // var es = EditStateIdentifier.GetCurrentEditState(_docMdf); es.CurrentBTR.UpgradeOpen(); //var layer_Slope = Utils.GetOrCreateLayer(_docMdf, ProtectionConstants.LayerName_ProtectionMethod_Slope); //var layer_Platform = Utils.GetOrCreateLayer(_docMdf, ProtectionConstants.LayerName_ProtectionMethod_Platform); // _docMdf.acDataBase.Clayer = layer_Slope.ObjectId; // // 1. 对有子边坡的边坡对象进行操作:显示界面,以进行填挖方与防护设置 var listerForm = new SlopeSegLister(slopesWithSlopesegs); listerForm.ShowDialog(null); if (listerForm.ValueChanged) { var protLayers = ProtectionTags.MapProtectionLayers(_docMdf, slopesWithSlopesegs); foreach (var slp in slopesWithSlopesegs) { slp.Pline.UpgradeOpen(); SetSlopeUI(slp); slp.PrintProtectionMethod(es.CurrentBTR, protLayers); // slp.FlushXData(); slp.Pline.DowngradeOpen(); if (slp.XDataToBeCleared) { slp.ClearXData(); } } } // 2. 对没有子边坡的边坡对象进行操作 foreach (var slp in slopesWithoutSlopesegs) { slp.Pline.UpgradeOpen(); SetSlopeUI(slp); slp.FlushXData(); slp.Pline.DowngradeOpen(); } es.CurrentBTR.DowngradeOpen(); }
/// <summary> 计算选择的所有曲线的面积与长度之和 </summary> public ExternalCmdResult SumupClosedArea(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; double areaSum = 0; Point3d pt; bool cont; int count = 0; var polyLines = new List <Entity>(); pt = GetPoint(docMdf.acEditor, out cont); var cs = EditStateIdentifier.GetCurrentEditState(docMdf); cs.CurrentBTR.UpgradeOpen(); while (cont) { // 选择的点所在的封闭图形 DBObjectCollection objs = docMdf.acEditor.TraceBoundary(seedPoint: pt, detectIslands: true); if (objs.Count == 0) { docMdf.WriteNow("\n请点击一个封闭的区域,并将其在界面中显示出来。"); } // Add our boundary objects to the drawing foreach (DBObject obj in objs) { var ent = obj as Polyline; // 一般来说,ent 都是 Polyline 对象,而且这些多段线对象并没有添加到数据库中 if (ent != null) { // Set our boundary objects to be of our auto-incremented colour index ent.ColorIndex = 5; // Set the lineweight of our object ent.LineWeight = LineWeight.LineWeight050; // Add each boundary object to the modelspace and add its ID to a collection cs.CurrentBTR.AppendEntity(ent); docMdf.acTransaction.AddNewlyCreatedDBObject(ent, true); ent.Draw(); } var area = ent.Area; areaSum += area; count += 1; docMdf.WriteNow($"\n区域数量:{count},\t当前区域的面积为:{area},\t面积求和:{areaSum}"); // polyLines.Add(ent); } // pt = GetPoint(docMdf.acEditor, out cont); } ; // 将所有的线条删除 bool deleteCurves; // deleteCurves = DeleteCurves(docMdf); deleteCurves = true; if (deleteCurves) { foreach (var pl in polyLines) { pl.UpgradeOpen(); pl.Erase(); pl.DowngradeOpen(); } } cs.CurrentBTR.DowngradeOpen(); return(ExternalCmdResult.Commit); }