替代AutoCAD GripData的WorldDraw方法会使AutoCAD崩溃



我使用的是用于AutoCAD的C#.NET API。我有一个GripData 的派生类

class PanelMidGrips : GripData
{
private readonly PanelPerimeterLine _line;
public PanelMidGrips(PanelPerimeterLine line)
{
this.GripPoint = line.TranslateToWCS(line.MidPoint);//GripPoint comes from GripData
_line = line;
}
}

TranslateToWCS()不应该很重要。它获取块的OCS中的一个点,并将其转换为模型空间中的一点,以便可以在块上的适当位置正确渲染夹点。

我的问题是当我尝试覆盖WorldDraw()AutoCAD崩溃时。

public override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, double dGripSize)
{
return base.WorldDraw(worldDraw, entityId, type, imageGripPoint, dGripSize);    
}

当我在返回基处使用断点进行调试时。。。。。行,我可以看到基本方法正在运行。但是,当我继续执行该方法时,我的AutoCAD会冻结10秒左右,然后崩溃,没有给出StackTrace或信息。

编辑0:我尝试添加一个try/catch块,看看是否会发生任何不同的情况。但同样的事情发生了,基本方法返回一个false,当该方法结束时,我的IDE和AutoCAD冻结,然后崩溃。

public override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, double dGripSize)
{
try
{
return base.WorldDraw(worldDraw, entityId, type, imageGripPoint, dGripSize);
}
catch(Autodesk.AutoCAD.Runtime.Exception e)
{
return false;
}
}

编辑1:非常奇怪的行为。当我为ViewPortDraw()本身添加覆盖时,没有WorldDraw()覆盖,没有崩溃。在模型空间中或通过视口查看块时不会发生崩溃。但现在握把不起作用了。

但当我也添加回WorldDraw()覆盖时,有了ViewportDraw()覆盖,就没有崩溃了!不会在模型空间或视口中崩溃!但与以前一样,夹点不再渲染。

如果我删除这两种方法的覆盖,夹点将渲染为正常??

public override bool ViewportDraw(Autodesk.AutoCAD.GraphicsInterface.ViewportDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, int gripSizeInPixels)
{
try
{
return base.ViewportDraw(worldDraw, entityId, type, imageGripPoint, gripSizeInPixels);
}
catch
{
return false;
}
}
public override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, double dGripSize)
{
try
{
return base.WorldDraw(worldDraw, entityId, type, imageGripPoint, dGripSize);
}
catch (System.Exception e)
{
return false;
}
}

我想事实证明WorldDraw()不是我需要重写的方法。我不确定它在这一点上做了什么。我只知道ViewportDraw()是我需要重写的方法。一旦我这样做并相应地调整了几何图形,一切都很好。

我认为ViewportDraw((只是用于通过图纸空间中的视口查看被覆盖的东西,但我想事实并非如此。如果您也在模型空间中,它也适用。

这就是我用来画一个盒子作为抓握点的地方

public override bool ViewportDraw(Autodesk.AutoCAD.GraphicsInterface.ViewportDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, int gripSizeInPixels)
{
try
{
Point2d glyphSize = worldDraw.Viewport.GetNumPixelsInUnitSquare(this.GripPoint);
Double glyphHeight = (gripSizeInPixels / glyphSize.Y);
Matrix3d e2w = worldDraw.Viewport.EyeToWorldTransform;
Point3d pt = this.GripPoint.TransformBy(e2w);
Point3dCollection pnts = new Point3dCollection
{
new Point3d(pt.X - glyphHeight, pt.Y + (glyphHeight), pt.Z),
new Point3d(pt.X - glyphHeight, pt.Y - (glyphHeight), pt.Z),
new Point3d(pt.X + glyphHeight, pt.Y - (glyphHeight), pt.Z),
new Point3d(pt.X + glyphHeight, pt.Y + (glyphHeight), pt.Z),
new Point3d(pt.X - glyphHeight, pt.Y + (glyphHeight), pt.Z)
};
worldDraw.Geometry.DeviceContextPolygon(pnts);
return false;

}
catch
{
return base.ViewportDraw(worldDraw, entityId, type, imageGripPoint, gripSizeInPixels);
}
}

最新更新