using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
namespace BaseGeometryEdit
{
class LineOverrule : DrawableOverrule
{
protected LineOverrule()
{
}
protected static LineOverrule _instance;
public static LineOverrule GetInstance(bool overruling)
{
Overruling = overruling;
if (_instance == null)
{
_instance = new LineOverrule();
}
return _instance;
}
public override bool WorldDraw(Drawable drawable, WorldDraw wd)
{
if (drawable is Line)
{
Line line = drawable as Line;
Point3dCollection polyPts = new Point3dCollection();
double boxHalf = line.Length / 8.0;
Point2dCollection boundPts = new Point2dCollection();
boundPts.Add(new Point2d(line.StartPoint.X - boxHalf, line.StartPoint.Y - boxHalf));
boundPts.Add(new Point2d(line.StartPoint.X - boxHalf, line.StartPoint.Y + boxHalf));
boundPts.Add(new Point2d(line.StartPoint.X + boxHalf, line.StartPoint.Y + boxHalf));
boundPts.Add(new Point2d(line.StartPoint.X + boxHalf, line.StartPoint.Y - boxHalf));
boundPts.Add(new Point2d(line.StartPoint.X - boxHalf, line.StartPoint.Y - boxHalf));
//ClipBoundary clipBound = new ClipBoundary();
//clipBound.SetAptPoints(boundPts);
Wipeout wipeout = new Wipeout();
wipeout.SetDatabaseDefaults(HostApplicationServices.WorkingDatabase);
wipeout.SetFrom(boundPts, Vector3d.ZAxis);
wipeout.SetClipBoundary(ClipBoundaryType.Rectangle, boundPts);
wipeout.DisplayOptions = ImageDisplayOptions.Clip;
wipeout.ImageTransparency = false;
wd.Geometry.Draw(wipeout);
//wd.Geometry.PushClipBoundary(clipBound);
//polyPts.Add(new Point3d(line.StartPoint.X - boxHalf, line.StartPoint.Y - boxHalf, line.StartPoint.Z));
//polyPts.Add(new Point3d(line.StartPoint.X - boxHalf, line.StartPoint.Y + boxHalf, line.StartPoint.Z));
//polyPts.Add(new Point3d(line.StartPoint.X + boxHalf, line.StartPoint.Y + boxHalf, line.StartPoint.Z));
//polyPts.Add(new Point3d(line.StartPoint.X + boxHalf, line.StartPoint.Y - boxHalf, line.StartPoint.Z));
//polyPts.Add(new Point3d(line.StartPoint.X - boxHalf, line.StartPoint.Y - boxHalf, line.StartPoint.Z));
//wd.Geometry.Polygon(polyPts);
}
bool baseWd = base.WorldDraw(drawable, wd);
return baseWd;
}
}
}