/// <summary> 将所有无效的字体样式修改为 HZTXT 字体 </summary> private ExternalCmdResult ModifyTextStyles(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; var textStyles = docMdf.acTransaction.GetObject (docMdf.acDataBase.TextStyleTableId, OpenMode.ForRead) as TextStyleTable; docMdf.WriteLineIntoDebuger("字体集合的修改情况"); foreach (var textStyleId in textStyles) { bool modified = false; var textStyle = docMdf.acTransaction.GetObject(textStyleId, OpenMode.ForRead) as TextStyleTableRecord; if (IsValidTextStyle(textStyle) && KeepUnchanged(textStyle)) { modified = false; // 不进行更改 } else { textStyle.UpgradeOpen(); textStyle.FileName = "romans.shx"; textStyle.BigFontFileName = "hztxt.shx"; textStyle.XScale = 0.7; // 宽度因子 textStyle.DowngradeOpen(); // textStyle.ObliquingAngle = 0; // f(倾斜角度) = ObliquingAngle // modified = true; } docMdf.WriteLineIntoDebuger($"{textStyle.Name} 被修改: {modified}"); } 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); }
/// <summary> 根据 AutoCAD 中的几何图形构造出完整的路基横断面信息系统 </summary> public ExternalCmdResult ConstructSections(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; SQUtils.SubgradeEnvironmentConfiguration(docMdf); // 方法一:在界面中选择指定的断面 // var axisLines = SQUtils.SelecteSectionLines(docMdf.acEditor); // 方法二:直接提取整个文档中所有的断面 var axisLines = SQUtils.GetAllSectionLines(docMdf.acEditor); if (axisLines != null && axisLines.Count > 0) { // 先检查以前是否进行过横断面构造,免得由于误点击而将原来的数据删除 bool hasConstructed = true; // if (hasConstructed) { var res = MessageBox.Show("是否要重新构造横断面系统?\r\n此操作会覆盖以前的横断面系统数据!", "提示", MessageBoxButton.YesNo, MessageBoxImage.Information); if (res == MessageBoxResult.No) { return(ExternalCmdResult.Cancel); } } var f = new SectionsConstructorForm(docMdf, axisLines); f.ShowDialog(); // var stations = f.SectionAxes.Select(r => r.XData.Station).ToArray(); //检查是否有重复的桩号出现 var duplicated = stations.GroupBy(x => x).Where(g => g.Count() > 1).ToArray(); if (duplicated.Length > 0) { MessageBox.Show("路基系统中出现重复的桩号,请核对后再操作!\r\n重复的桩号见命令行提示。", "提示", MessageBoxButton.OK, MessageBoxImage.Error); docMdf.WriteLineIntoDebuger("重复的桩号,重复的次数"); foreach (var d in duplicated) { docMdf.WriteLineIntoDebuger(d.Key, d.Count()); } } else { // 将桩号从小到大排序 Array.Sort(stations); Options_Collections.AllSortedStations = stations; DbXdata.FlushXData(docMdf, DbXdata.DatabaseXdataType.AllSortedStations); } } else { MessageBox.Show("未找到有效的横断面轴线,请核对后再操作!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } return(ExternalCmdResult.Commit); }
/// <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 CopyColumnsFromClipboard(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; // var pl = AddinManagerDebuger.PickObject<Curve>(docMdf.acEditor); // AutoCAD中的一列数据,并从高到低排序 var texts = SelectTexts(); if (texts == null || texts.Count == 0) { return(ExternalCmdResult.Cancel); } // 剪切板中的一列数据 var col = true; var lines = GetTextsFromClipboard(out col); if (lines == null || lines.Length == 0) { return(ExternalCmdResult.Cancel); } // if (col) { texts.Sort(RowsComparer); } else { texts.Sort(ColsComparer); } // var rowCount = Math.Min(lines.Length, texts.Count); var changedTextIds = new ObjectId[rowCount]; for (int i = 0; i < rowCount; i++) { var t = texts[i]; t.UpgradeOpen(); if (t is DBText) { (t as DBText).TextString = lines[i]; } else if (t is MText) { (t as MText).Contents = lines[i]; } t.DowngradeOpen(); // changedTextIds[i] = (t.ObjectId); } docMdf.acEditor.SetImpliedSelection(changedTextIds); docMdf.WriteLineIntoDebuger($"剪切板中数据行数:{lines.Length}"); docMdf.WriteLineIntoDebuger($"AutoCAD中选择的数据行数:{texts.Count}"); return(ExternalCmdResult.Commit); }
// This event handler is where the time-consuming work is done. private void ConstructSections_DoWork(System.Object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; var errorCenterLine = new Dictionary <Line, string>(); string errorMsg = ""; for (int i = 0; i < _count; i++) { var axis = _centerLines[i]; var cenA = SubgradeSection.Create(_docMdf, axis, out errorMsg); if (cenA != null) { cenA.CenterLine.UpgradeOpen(); cenA.ClearXData(true); var succ = cenA.CalculateSectionInfoToXData(errorMsg); if (succ) { cenA.FlushXData(); SectionAxes.Add(cenA); } else { errorCenterLine.Add(axis, errorMsg); } cenA.CenterLine.DowngradeOpen(); } else { errorCenterLine.Add(axis, errorMsg); } // 显示进度 worker.ReportProgress(i); } // 列出出错的断面 if (errorCenterLine.Count > 0) { _docMdf.WriteLineIntoDebuger("提取出错的断面:"); _docMdf.WriteLineIntoDebuger("序号 起点 终点 报错"); int index = 0; var acPoly = new Polyline(); foreach (var ecl in errorCenterLine) { var pt = new Point2d(ecl.Key.StartPoint.X, ecl.Key.StartPoint.Y); acPoly.AddVertexAt(index, pt, 0, startWidth: 0, endWidth: 0); _docMdf.WriteLineIntoDebuger(index + 1, ecl.Key.StartPoint, ecl.Key.EndPoint, ecl.Value); index += 1; } } }
/// <summary> 找到边坡线附近所属的中心轴线 </summary> /// <param name="pl"></param> /// <remarks>未找到则返回 null </remarks> private static SubgradeSection FindCenterAxisOnScreen(DocumentModifier docMdf, Polyline pl) { var pline = pl; var bdbl = pline.Bounds.Value.MinPoint; // 左下角点 bdbl = new Point3d(bdbl.X - Options_General.RoadWidth / 2, bdbl.Y - 0, bdbl.Z); var bdtr = pline.Bounds.Value.MaxPoint; // 右上角点 bdtr = new Point3d(bdtr.X + Options_General.RoadWidth / 2, bdtr.Y + 0, bdtr.Z); var res = docMdf.acEditor.SelectCrossingWindow(bdbl, bdtr, SubgradeSection.Filter); if (res.Status == PromptStatus.OK) { var ids = res.Value.GetObjectIds(); Line minLine = null; var minDis = double.MaxValue; // 可能找到多条轴线,比较轴线中点到边坡线两个端点距离最小的那个轴线 foreach (var id in ids) { var l = id.GetObject(OpenMode.ForRead) as Line; var dir = l.StartPoint - l.EndPoint; if (dir.IsParallelTo(new Vector3d(0, 1, 0))) { // 根据距离最近的原则来从众多的轴线中寻找匹配项 var centMid = l.StartPoint.Add((l.EndPoint - l.StartPoint).DivideBy(2)); // 轴线的中点 var d1 = centMid.DistanceTo(pl.StartPoint); var d2 = centMid.DistanceTo(pl.StartPoint); var minD = Math.Min(d1, d2); if (minD < minDis) { minLine = l; minDis = minD; } } } // 构造 CenterAxis 对象 SubgradeSection centerLine = null; var si = SectionInfo.FromCenterLine(minLine); if (si != null && si.FullyCalculated) { centerLine = new SubgradeSection(docMdf, minLine, si); } if (centerLine == null) { string errorMsg = ""; centerLine = SubgradeSection.Create(docMdf, minLine, out errorMsg); if (centerLine == null) { } } return(centerLine); } docMdf.WriteLineIntoDebuger("在边坡线周围没有找到中心轴线。请检查边坡线数据中是否保存有道路中线句柄值,或者将视图缩小以在屏幕中显示出对应的轴线。轴线搜索范围:" + "\r\n" + bdbl + " ~ " + bdtr); return(null); }
private void ConstructWorld(DocumentModifier docMdf, BlockTableRecord btr, string[] categories, double minMile, double maxMile) { var l = new Line(new Point3d(0, 0, 0), new Point3d(maxMile, 0, 0)); btr.AppendEntity(l); docMdf.acTransaction.AddNewlyCreatedDBObject(l, true); // var txt = new DBText { TextString = "左", Height = Item.TextHeight, HorizontalMode = TextHorizontalMode.TextRight, VerticalMode = TextVerticalMode.TextVerticalMid, AlignmentPoint = new Point3d(0, Item.BarHeight / 2, 0) }; btr.AppendEntity(txt); docMdf.acTransaction.AddNewlyCreatedDBObject(txt, true); txt = new DBText { TextString = "右", Height = Item.TextHeight, HorizontalMode = TextHorizontalMode.TextRight, VerticalMode = TextVerticalMode.TextVerticalMid, AlignmentPoint = new Point3d(0, -Item.BarHeight / 2, 0) }; btr.AppendEntity(txt); docMdf.acTransaction.AddNewlyCreatedDBObject(txt, true); // foreach (var category in categories) { var middleVLeft = Item.GetMiddleV(categories, category, true); var middleVRight = Item.GetMiddleV(categories, category, false); docMdf.WriteLineIntoDebuger(middleVRight.ToString(), middleVLeft.ToString()); txt = new DBText { TextString = category, Height = Item.TextHeight, HorizontalMode = TextHorizontalMode.TextRight, VerticalMode = TextVerticalMode.TextVerticalMid, AlignmentPoint = new Point3d(0, middleVLeft, 0) }; btr.AppendEntity(txt); docMdf.acTransaction.AddNewlyCreatedDBObject(txt, true); txt = new DBText { TextString = category, Height = Item.TextHeight, HorizontalMode = TextHorizontalMode.TextRight, VerticalMode = TextVerticalMode.TextVerticalMid, AlignmentPoint = new Point3d(0, middleVRight, 0) }; btr.AppendEntity(txt); docMdf.acTransaction.AddNewlyCreatedDBObject(txt, true); } }
/// <summary> 计算选择的所有曲线的面积与长度之和 </summary> public ExternalCmdResult SumupArea(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; // var pl = AddinManagerDebuger.PickObject<Curve>(docMdf.acEditor); var curves = SelectCurves(); var area = 0.0; var length = 0.0; foreach (var c in curves) { if (c.Area > 0) { area += c.Area; } length += c.GetDistanceAtParameter(c.EndParam); } docMdf.WriteLineIntoDebuger($"选中曲线数量:{curves.Count}"); docMdf.WriteLineIntoDebuger($"曲线总长度:{length}"); docMdf.WriteLineIntoDebuger($"曲线总面积:{area}"); return(ExternalCmdResult.Commit); }
/// <summary> <seealso cref="CommandDescription"/> </summary> public ExternalCmdResult GetExtension(DocumentModifier docMdf, SelectionSet impliedSelection) { _docMdf = docMdf; // var entis = SelectUtils.PickEntities <Entity>(_docMdf.acEditor, "选择多个对象,提取几何定位"); if (entis == null || entis.Length == 0) { return(ExternalCmdResult.Cancel); } // var sb = new StringBuilder(); sb.AppendLine("Min;Max;Center;Width;Height;Depth;"); foreach (var ent in entis) { AppendDescription(ent.GeometricExtents, ref sb); sb.AppendLine(); } docMdf.WriteLineIntoDebuger("选择的元素个数:", entis.Length); _docMdf.WriteLineIntoDebuger(sb.ToString()); // return(ExternalCmdResult.Commit); }
public void Execute(DocumentModifier docMdf) { List <Item> items = null; try { items = GetItemsFromExcel(); } catch (Exception ex) { DebugUtils.ShowDebugCatch(ex, "提取Excel中的信息出错"); } if (items != null && items.Count > 0) { var categories = items.Select(r => r.Category).Distinct().ToArray(); var paperIdss = items.Select(r => r.PaperId).Distinct().ToArray(); var minStation = items.Select(r => r.Start).Min(); var maxStation = items.Select(r => r.End).Max(); var paperIds = new Dictionary <string, ObjectIdCollection>(); foreach (var paperId in paperIdss) { paperIds.Add(paperId, new ObjectIdCollection()); } // 以只读方式打开块表 Open the Block table for read var acBlkTbl = docMdf.acTransaction.GetObject(docMdf.acDataBase.BlockTableId, OpenMode.ForRead) as BlockTable; // 以写方式打开模型空间块表记录 Open the Block table record Model space for write var acBlkTblRec = docMdf.acTransaction.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // 绘制基本坐标系与分界线等 ConstructWorld(docMdf, acBlkTblRec, categories, minStation, maxStation); // FindIntersections(docMdf, acBlkTblRec, items, categories, paperIds); // 将每一个单子中的对象添加到一个组Group中 var groups = docMdf.acTransaction.GetObject(docMdf.acDataBase.GroupDictionaryId, OpenMode.ForWrite) as DBDictionary; var colors = ColorUtils.ClassicalExpand(paperIds.Count); var ind = 0; foreach (var paperId in paperIds) { var gp = new Group(paperId.Key, true); // ProtectionUtils.OverlayDictValue(trans, container, DictKey_Platforms, dbPlatforms); groups.SetAt(paperId.Key, gp); gp.Append(paperId.Value); // gp.Selectable = false; // 默认为 true,如果设置为 false,则即使 PICKSTYLE 系统变量设置为1,这个 group 也不能被作为一个整体进行选择。 docMdf.WriteLineIntoDebuger("添加组 ", gp.Name, "成员个数:", gp.GetAllEntityIds().Length.ToString()); gp.SetColor(Color.FromColor(colors[ind])); // docMdf.acTransaction.AddNewlyCreatedDBObject(gp, true); ind += 1; } } }