我对我的应用程序很了解,但是这会使我的应用程序变慢,有人可以帮助我吗? 我的应用程序绘图就像AutoCAD绘图一样。我用eyeshot SDK开发它。 在我使用平移/旋转之前,看起来还不错。
这是我的代码
public SnapPoint[] GetSnapPoints(System.Drawing.Point mouseLocation)
{
//changed PickBoxSize to define a range for display snapPoints
var oldSize = PickBoxSize;
PickBoxSize = 10;
var snapPoints = new List<SnapPoint>();
var entityIndexs = GetAllEntitiesUnderMouseCursor(mouseLocation, false);
if (entityIndexs.Length>0)
{
var countindex = 0;
foreach (int index in entityIndexs)
{
if (Entities[index] is ICurve entCurve)
{
var indexVerTex = 0;
var entPoints = entCurve.GetPointsByLength(0.9);
foreach (Point3D vertex in Entities[index].Vertices)
{
snapPoints.Add(new SnapPoint(vertex, ObjectSnapType.End));
if (indexVerTex>0)
{
var midPoint = FindMidPoint3D(Entities[index].Vertices[indexVerTex - 1], vertex);
snapPoints.Add(new SnapPoint(midPoint,ObjectSnapType.Mid));
}
indexVerTex++;
}
if (entCurve is LinearPath linearPath)
{
var temptPoints = this.GetIntersectBySeft(linearPath);
if (temptPoints.Count > 0)
{
foreach (var temptPoint in temptPoints)
{
if (!CheckPointInSnapPoints(temptPoint, snapPoints))
{
snapPoints.Add(new SnapPoint(temptPoint, ObjectSnapType.Intersect));
}
}
}
}
if (countindex > 0)
{
Point3D intersectPoint3D = null;
if (Entities[entityIndexs[countindex - 1]] is ICurve line1 && Entities[entityIndexs[countindex]] is ICurve line2)
{
if (line1 is LinearPath linePath1)
{
var intersectPoints = linePath1.IntersectWith(line2);
foreach (Point3D intersectPoint in intersectPoints)
{
snapPoints.Add(new SnapPoint(intersectPoint, ObjectSnapType.Intersect));
}
}
else if (line2 is LinearPath linePath2)
{
var intersectPoints = linePath2.IntersectWith(line1);
foreach (Point3D intersectPoint in intersectPoints)
{
snapPoints.Add(new SnapPoint(intersectPoint, ObjectSnapType.Intersect));
}
}
else if (CompositeCurve.IntersectionLineLine(line1, line2, out intersectPoint3D))
{
snapPoints.Add(new SnapPoint(intersectPoint3D, ObjectSnapType.Intersect));
}
}
}
foreach (Point3D entPoint in entPoints)
{
if (!CheckPointInSnapPoints(entPoint, snapPoints))
{
snapPoints.Add(new SnapPoint(entPoint, ObjectSnapType.Nearest));
}
}
}
countindex++;
}
}
var entIndex = GetEntityUnderMouseCursor(mouseLocation);
Point3D tempPoint =null;
if (entIndex>-1)
{
}
var snaps = snapPoints.ToArray();
return snaps;
}
还有这个
public List<Point3D> GetIntersectBySeft(LinearPath linearPath)
{
var lines = linearPath.ConvertToLines();
var temPoint3Ds = new List<Point3D>();
for (int i = 0; i < lines.Length; i++)
{
for (int j = i+2;j<lines.Length; j++)
{
temPoint3Ds.AddRange(lines[i].IntersectWith(lines[j]));
}
}
var tempPoints2 = new List<Point3D>();
foreach (var temPoint in temPoint3Ds)
{
if (!tempPoints2.Contains(temPoint))
{
tempPoints2.Add(temPoint);
}
}
return tempPoints2;
}
还有这个
public bool CheckPointInSnapPoints(Point3D point, List<SnapPoint> snapPoints)
{
return snapPoints.Any(snapPoint => point.X == snapPoint.X && point.Y == snapPoint.Y);
}
public Point3D FindMidPoint3D(Point3D pointA, Point3D pointB)
{
return new Point3D((pointA.X+pointB.X)/2,(pointA.Y+pointB.Y)/2);
}
在这种情况下,任何人都可以帮助我解决此问题以获得最佳性能
答案 0 :(得分:0)
我在带有标签的MouseMove事件中构建快照点。参见图片。Example Arc在MouseDown中,您可以单击标签。 Label.Anchorpoint是您要搜索的点。
在MouseMove中(行示例)
如果TypeOf EntityUnderMouse为Line然后
Dim Line1 As Line = DirectCast(et, Line)
Model1.Labels.Add(New Labels.ImageOnly(Line1.StartPoint, GenerateLabelEndPoint(Color.Orange), 5, 5))
Model1.Labels.Add(New Labels.ImageOnly(Line1.MidPoint, GenerateLabelCenterLine(Color.Yellow), 6, 6))
Model1.Labels.Add(New Labels.ImageOnly(Line1.EndPoint, GenerateLabelEndPoint(Color.Orange), 5, 5))
Endif
在MouseDown中,只需单击“标签”并获取AnchorPoint。
希望我能帮忙。
致谢