Just boilerplate at this point. I'd be happy to open source the actual code once there's something usable, but I need to get clearance from TPTB at work.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using CamBam;
using CamBam.CAD;
using CamBam.CAM;
using CamBam.Geom;
using CamBam.UI;
using CamBam.Util;
using CamBam.Values;
namespace VCarve_Plugin
{
public class VCarve
{
private static CamBamUI _ui;
public VCarve() {}
public static void InitPlugin(CamBamUI ui)
{
_ui = ui;
ToolStripMenuItem insertCAM_VcarveCommand = new ToolStripMenuItem();
insertCAM_VcarveCommand.Text = "V-Carve";
insertCAM_VcarveCommand.Image = Properties.VCarveResources.VCarveButton;
insertCAM_VcarveCommand.Click += new EventHandler(InsertCAM_VCarve);
// this bit is just to control where in the menu the new mop appears.
for (int i = 0; i < ui.Menus.mnuMachining.DropDownItems.Count; ++i)
{
ToolStripItem item = ui.Menus.mnuMachining.DropDownItems[i];
if (item is ToolStripSeparator)
{
ui.Menus.mnuMachining.DropDownItems.Insert(i, insertCAM_VcarveCommand);
insertCAM_VcarveCommand = null;
break;
}
}
// Just add it at the end if we didn't find a better place to put it.
if (insertCAM_VcarveCommand != null)
{
ui.Menus.mnuMachining.DropDownItems.Add(insertCAM_VcarveCommand);
}
}
public static void InsertCAM_VCarve(object sender, EventArgs e)
{
ICADView view = CamBamUI.MainUI.ActiveView;
CADFile file = view.CADFile;
object[] objects = view.SelectedEntities;
MOPVCarve mop = new MOPVCarve(file, objects);
view.CADFile.EnsureActivePart(true);
view.CADFile.ActivePart.MachineOps.Add(mop, /* fireparentevents*/ true);
// --- this bit doesn't seem to actually work ---
view.DrawingTree.SelectedMOPs.Clear();
view.DrawingTree.SelectedMOPs.Add(mop);
// ---
view.CADFile.Modified = true;
}
}
public class MOPVCarve : MOPFromGeometry
{
public MOPVCarve() {}
public MOPVCarve(MOPVCarve src)
: base(src)
{}
public MOPVCarve(CADFile file, object[] objects)
: base(file, objects)
{}
public override string MOPTypeName
{
get { return "VCarve"; }
}
public override CamBam.CAM.MachineOp Clone()
{
return new MOPVCarve(this);
}
public override void GenerateToolpaths(CADFile cadFile)
{
Toolpaths2 = new ToolpathSequence(this);
Point3F start = StartPoint.Value;
// this is just dummy code to stick something into the toolpath
for (int n = 0; n < PrimitiveIds.Length; ++n)
{
Entity entity = cadFile.FindPrimitive(PrimitiveIds[n]);
if (entity is Polyline)
{
Polyline toolpath = (Polyline)entity;
int parentID = 0;
if (entity.Parent is Entity)
{
parentID = ((Entity)entity.Parent).ID;
}
Toolpaths2.Add(/* depthIndex */ 0,
/* offsetIndex */ 0,
new EntityIdentifier(entity.ID),
parentID,
(Polyline) toolpath.Clone(),
toolpath.Direction,
StartPoint.Value,
/* zoffset */ 0.0);
}
}
}
// These overrides are just to see if the methods are being called. They aren't :(
public override bool PreProcess(CamBam.CAM.MachineOpToGCode gcg)
{
CamBamUI.MainUI.Messages.Items.Add("base.Preprocess");
bool result = base.PreProcess(gcg);
CamBamUI.MainUI.Messages.Items.Add("base.Preprocess returned " + (result ? "true" : "false"));
return result;
}
public override void PostProcess(CamBam.CAM.MachineOpToGCode gcg)
{
CamBamUI.MainUI.Messages.Items.Add("base.Preprocess");
base.PostProcess(gcg);
CamBamUI.MainUI.Messages.Items.Add("base.Postprocess returned");
}
}
}