// (C) Copyright 2016 by
//
using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsSystem;
using Autodesk.AutoCAD.EditorInput;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(Rivilis.MyCommands))]
namespace Rivilis
{
public class MyCommands
{
[CommandMethod("S3DOver")]
public void CmdSimpleOverrule()
{
if (_overrule == null)
{
_overrule = new Solid3dOverrule();
Overrule.AddOverrule(RXClass.GetClass(typeof(Circle)), _overrule, false);
}
else
{
Overrule.RemoveOverrule(RXClass.GetClass(typeof(Circle)), _overrule);
_overrule = null;
}
Application.DocumentManager.MdiActiveDocument.Editor.Regen();
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_REGEN3 ", true, false, false);
}
private static Solid3dOverrule _overrule = null;
}
public class Solid3dOverrule : AcGi.DrawableOverrule
{
public Dictionary<ObjectId, Solid3d> cash = null;
public override bool WorldDraw(AcGi.Drawable drawable, AcGi.WorldDraw wd)
{
base.WorldDraw(drawable, wd);
return false;
}
public override void ViewportDraw(AcGi.Drawable drawable, AcGi.ViewportDraw vd)
{
base.ViewportDraw(drawable, vd);
if (cash == null) cash = new Dictionary<ObjectId, Solid3d>();
Solid3d sol = new Solid3d();
if (!cash.ContainsKey(drawable.Id))
{
sol.CreateBox(100, 100, 100);
Circle pt = drawable as Circle;
if (pt != null) {
sol.TransformBy(Matrix3d.Displacement(pt.Center.GetAsVector()));
}
cash.Add(drawable.Id, sol);
}
else
{
sol = cash[drawable.Id];
}
vd.Geometry.Draw(sol);
}
}
}