连线(Connection)是怎么添加进Connection Layer的呢

本文介绍了Gef框架中AbstractConnectionEditPart类的addNotify方法实现细节,该方法通过调用activateFigure方法来激活连线的Figure组件,并将其添加到CONNECTION_LAYER图层。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

阅读源代码。
在AbstractConnectionEditPart方法中的addNotify实现为:
/**
 * @see org.eclipse.gef.EditPart#addNotify()
 */
public void addNotify() {
 activateFigure();
 super.addNotify();
}


我们需要再看一看acitvateFigure的实现。
protected void activateFigure() {
 getLayer(CONNECTION_LAYER).add(getFigure());
}


获取connection layer,将连线对应的Figure加进去

using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using System; using System.Collections.Generic; using System.Linq; public class CADUtilities { // 清理无用实体命令 (CLN) [CommandMethod("CLN")] public void CleanUpDrawing() { Document doc = Application.DocumentManager.MdiActiveDocument; if (doc == null) return; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction tr = db.TransactionManager.StartTransaction()) { try { BlockTableRecord btr = (BlockTableRecord)tr.GetObject( db.CurrentSpaceId, OpenMode.ForWrite ); int deletedCount = 0; // 清理空文本和无效标注(保留含'L'的文本) foreach (ObjectId id in btr) { DBText text = tr.GetObject(id, OpenMode.ForRead) as DBText; if (text != null && (string.IsNullOrWhiteSpace(text.TextString) || !IsValidAnnotation(text.TextString))) // 修改验证逻辑 { text.UpgradeOpen(); text.Erase(); deletedCount++; } } // 清理零长度线 foreach (ObjectId id in btr) { Line line = tr.GetObject(id, OpenMode.ForRead) as Line; if (line != null && line.Length < 0.001) { line.UpgradeOpen(); line.Erase(); deletedCount++; } } tr.Commit(); ed.WriteMessage($"\n清理完成,删除 {deletedCount} 个无用实体"); } catch (System.Exception ex) { ed.WriteMessage($"\n错误: {ex.Message}"); tr.Abort(); } } } // 梁标注修复命令 (FIXBL) [CommandMethod("FIXBL")] public void FixBeamLeaders() { Document doc = Application.DocumentManager.MdiActiveDocument; if (doc == null) return; Database db = doc.Database; Editor ed = doc.Editor; // 第一步:用户选择梁图层 string beamLayer = GetUserSelectedLayer(ed, db); if (string.IsNullOrEmpty(beamLayer)) return; using (Transaction tr = db.TransactionManager.StartTransaction()) { try { BlockTableRecord btr = (BlockTableRecord)tr.GetObject( db.CurrentSpaceId, OpenMode.ForWrite ); // 收集指定图层的梁实体 List<Curve> beamEntities = CollectEntitiesByLayer<Curve>(btr, tr, beamLayer); if (beamEntities.Count == 0) { ed.WriteMessage("\n未找到梁实体!"); return; } // 收集梁截面标注文本 List<DBText> dimensionTexts = new List<DBText>(); foreach (ObjectId id in btr) { DBText text = tr.GetObject(id, OpenMode.ForRead) as DBText; if (text != null && IsBeamDimensionText(text.TextString)) { dimensionTexts.Add(text); } } ed.WriteMessage($"\n找到 {beamEntities.Count} 个梁实体和 {dimensionTexts.Count} 个标注文本"); // 为每个标注创建垂直引线 foreach (DBText text in dimensionTexts) { Curve closestBeam = FindClosestBeam(text.Position, beamEntities); if (closestBeam == null) continue; // 计算引线终点(梁正上方) Point3d connectionPoint = CalculateVerticalConnectionPoint( text.Position, closestBeam ); // 创建垂直引线 CreateVerticalLeader( text.Position, connectionPoint, btr, tr ); } tr.Commit(); ed.WriteMessage("\n梁标注引线修复完成!"); } catch (System.Exception ex) { ed.WriteMessage($"\n错误: {ex.Message}"); tr.Abort(); } } } // 辅助方法:验证标注文本(保留含'L'的文本) private bool IsValidAnnotation(string text) { // 保留包含'L'的梁名称(如"3-Lg9(7)") if (text.IndexOf('L') >= 0 || text.IndexOf('l') >= 0) return true; // 清理空文本和无效标注 return !(string.IsNullOrWhiteSpace(text) || !(text.Contains("×") || text.Contains("X") || text.Contains("x") || text.Contains("*"))); } // 辅助方法:识别梁截面标注文本(如"200*500") private bool IsBeamDimensionText(string text) { // 匹配数字x数字格式(如200x500, 300*600) return System.Text.RegularExpressions.Regex.IsMatch( text, @"\d+\s*[xX×*]\s*\d+" ); } // 获取用户选择的图层 private string GetUserSelectedLayer(Editor ed, Database db) { PromptEntityOptions opt = new PromptEntityOptions("\n选择梁图层上的任意实体:"); PromptEntityResult res = ed.GetEntity(opt); if (res.Status != PromptStatus.OK) return null; using (Transaction tr = db.TransactionManager.StartTransaction()) { Entity ent = tr.GetObject(res.ObjectId, OpenMode.ForRead) as Entity; return ent?.Layer; } } // 收集指定图层的特定类型实体 private List<T> CollectEntitiesByLayer<T>(BlockTableRecord btr, Transaction tr, string layer) where T : Entity { List<T> entities = new List<T>(); foreach (ObjectId id in btr) { Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity; if (ent != null && ent.Layer == layer && ent is T) { entities.Add((T)ent); } } return entities; } // 查找最近的梁实体 private Curve FindClosestBeam(Point3d position, List<Curve> beams) { if (beams == null || beams.Count == 0) return null; Curve closestBeam = null; double minDistance = double.MaxValue; foreach (Curve beam in beams) { Point3d closestPoint = beam.GetClosestPointTo(position, false); double distance = position.DistanceTo(closestPoint); if (distance < minDistance) { minDistance = distance; closestBeam = beam; } } return closestBeam; } // 计算垂直连接点(梁正上方) private Point3d CalculateVerticalConnectionPoint(Point3d textPos, Curve beam) { // 获取梁上最近点 Point3d closestPoint = beam.GetClosestPointTo(textPos, false); // 返回正上方的点(保持X坐标不变) return new Point3d(textPos.X, closestPoint.Y, textPos.Z); } // 创建垂直引线 private void CreateVerticalLeader(Point3d textPos, Point3d beamPos, BlockTableRecord btr, Transaction tr) { using (Leader leader = new Leader()) { // 计算引线起点(文本正上方偏移) Point3d leaderStart = new Point3d( textPos.X, textPos.Y + GetTextHeightOffset(), textPos.Z ); leader.AppendVertex(leaderStart); leader.AppendVertex(beamPos); // 直接连接到梁正上方 // 设置引线属性 leader.HasArrowHead = true; leader.ArrowHeadType = ArrowHeadType.FilledDot; leader.Layer = "标注"; leader.ColorIndex = 2; // 黄色 btr.AppendEntity(leader); tr.AddNewlyCreatedDBObject(leader, true); } } // 获取文本高度偏移量 private double GetTextHeightOffset() { // 根据当前文本高度计算偏移(默认2倍文本高度) return 100; // 实际应用中应从数据库获取文本样式高度 } } CS1061“Leader”未包含”ArrowHeadType”的定义,并且找不到可接受第一个“Leader”类型参数的可访问扩展方法“ArrowHeadType”(是否缺少using 指令或程序集引用?) CS0103当前上下文中不存在名称ArrowHeadType” 重写
最新发布
07-05
innovus 7> setStreamOutMode -check_map_file true -labelAllPinShape true -streamVersion 5 -textSize 0.3 innovus 8> streamOut "/home/ic/LYF/TPZ018/Newwen/zhuang/output.gds" \ + -libName DesignLib \ + -mapFile "streamOut.map" \ + -merge "/home/ic/LYF/TPZ018/tpz018nv_280b_gdsu5lm/TSMCHOME/digital/Back_End/gds/tpz018nv_280b/mt_2/5lm/tpz018nv.gds" \ + -units 1000 \ + -mode ALL Merge file: /home/ic/LYF/TPZ018/tpz018nv_280b_gdsu5lm/TSMCHOME/digital/Back_End/gds/tpz018nv_280b/mt_2/5lm/tpz018nv.gds has version number: 5 Parse flat map file... Writing GDSII file ... ****** db unit per micron = 1000 ****** ****** output gds2 file unit per micron = 1000 ****** ****** unit scaling factor = 1 ****** Output for instance Output for bump Output for physical terminals Output for logical terminals Output for regular nets Output for special nets and metal fills Output for via structure generation total number 0 Statistics for GDS generated (version 5) ---------------------------------------- Stream Out Layer Mapping Information: GDS Layer Number GDS Layer Name ---------------------------------------- 79 COMP 80 DIEAREA 107 VIAD 167 VIAD 28 METAL3 17 VIA12 15 CONT 16 METAL1 18 METAL2 27 VIA23 40 METAL1 41 METAL2 42 METAL3 101 METAL1 103 METAL3 102 METAL2 Stream Out Information Processed for GDS version 5: Units: 1000 DBU Object Count ---------------------------------------- Instances 776 Ports/Pins 0 Nets 0 Via Instances 0 Special Nets 0 Via Instances 0 Metal Fills 0 Via Instances 0 Metal FillOPCs 0 Via Instances 0 Metal FillDRCs 0 Via Instances 0 Text 444 metal layer METAL1 321 metal layer METAL3 123 Blockages 0 Custom Text 0 Custom Box 0 Trim Metal 0 Scanning GDS file /home/ic/LYF/TPZ018/tpz018nv_280b_gdsu5lm/TSMCHOME/digital/Back_End/gds/tpz018nv_280b/mt_2/5lm/tpz018nv.gds to register cell name ...... Merging GDS file /home/ic/LYF/TPZ018/tpz018nv_280b_gdsu5lm/TSMCHOME/digital/Back_End/gds/tpz018nv_280b/mt_2/5lm/tpz018nv.gds ...... ****** Merge file: /home/ic/LYF/TPZ018/tpz018nv_280b_gdsu5lm/TSMCHOME/digital/Back_End/gds/tpz018nv_280b/mt_2/5lm/tpz018nv.gds has version number: 5. ****** Merge file: /home/ic/LYF/TPZ018/tpz018nv_280b_gdsu5lm/TSMCHOME/digital/Back_End/gds/tpz018nv_280b/mt_2/5lm/tpz018nv.gds has units: 1000 per micron. ****** unit scaling factor = 1 ****** ------------------------------------------------------------ The below objects exist in innovus database, but they are not mapped to gds file, please verify the layer map file to confirm it is expected.: Lef Layer Name Object Type Comment ------------------------------------------------------------ ------------------------------------------------------------ The below objects exist in innovus database, but they are not streamed out to gds file.: Object Count ------------------------------------------------------------ Ports/Pins 0 Nets 0 Via Instances 0 Special Nets 0 Via Instances 0 Metal Fills 0 Via Instances 0 Metal FillOPCs 0 Via Instances 0 Metal FillDRCs 0 Via Instances 0 Vias 0 Text 0 Blockages 0 Custom 0 Trim Metal 0 ######Streamout is finished! innovus 9>
07-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值