/// <summary> /// Really draw the tool on the view /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> private void DrawTool(double x, double y, double z) { CamBamUI ui = CamBamUI.MainUI; // setup tool translation Matrix4x4F matrix4x4F = new Matrix4x4F(); // move the identity matrix to our delta? positions matrix4x4F.Translate(x - _lastX, y - _lastY, z - _lastZ); _lastX = x; _lastY = y; _lastZ = z; // tell the tool _tool.ApplyTransformation(matrix4x4F); // hijack the current EditMode _orgEditMode = _ActiveView.CurrentEditMode; _ActiveView.CurrentEditMode = this; // trigger OnPaint _ActiveView.RepaintEditMode(); _ActiveView.CurrentEditMode = _orgEditMode; _orgEditMode = null; }
public static void InitPlugin(CamBamUI ui) { #if DEBUG MessageBox.Show("Now it's time to attach the debugger :-)", "GRBLMachinePlugin"); #endif Page = new TabPage("Machine") { UseVisualStyleBackColor = false }; UpdatePostProcessor(); ReadConfig(); // // Controversial action #1: Should a plugin tamper with CamBam's UI ??? ;) :P // if (Props.EnableVisualStyles == EnabledDisabled.Enabled) { Application.EnableVisualStyles(); } // // Create the menu item. Basically does not do much :P // ToolStripDropDownItem gcodeMenuItem = new ToolStripMenuItem(); gcodeMenuItem.Text = "GRBL Machine"; gcodeMenuItem.Image = Resources.Grbl_Logo_150px; gcodeMenuItem.Click += new EventHandler(plugin_clicked); ui.Menus.mnuPlugins.DropDownItems.Add(gcodeMenuItem); // // Find ZoomToFit menu item and replace it by ZoomToFitEx // foreach (ToolStripItem item in ui.Menus.mnuView.DropDownItems) { if (item.Name == "mnuZoomToFit") { ToolStripMenuItem mnuZoomToFit = item as ToolStripMenuItem; int index = ui.Menus.mnuView.DropDownItems.IndexOf(mnuZoomToFit); if (index != -1) { ui.Menus.mnuView.DropDownItems.Insert(index, new ToolStripMenuItem(mnuZoomToFit.Text, mnuZoomToFit.Image, MnuZoomToFit_Click, mnuZoomToFit.ShortcutKeys)); ui.Menus.mnuView.DropDownItems.RemoveAt(index + 1); } break; } } // // As soon as CamBam is up and running, we will hookup our UI. Checking is done on App.Idle... // Application.Idle += Application_Idle; }
private static void Tabs_Selecting(object sender, TabControlCancelEventArgs e) { CamBamUI ui = CamBamUI.MainUI; rgObjectProperties[lastIndex] = ui.ObjectProperties.SelectedObject; lastIndex = ui.SysTabs.SelectedTab; }
public static void InitPlugin(CamBamUI ui) { ToolStripMenuItem menu_entry; menu_entry = new ToolStripMenuItem(); menu_entry.Text = profile_mop_name; menu_entry.Click += profile_mop_onclick; menu_entry.Image = resources.cam_trochoprof1; insert_in_top_menu(ui, menu_entry); menu_entry = new ToolStripMenuItem(); menu_entry.Text = profile_mop_name; menu_entry.Click += profile_mop_onclick; menu_entry.Image = resources.cam_trochoprof1; insert_in_context_menu(ui, menu_entry); menu_entry = new ToolStripMenuItem(); menu_entry.Text = pocket_mop_name; menu_entry.Click += pocket_mop_onclick; menu_entry.Image = resources.cam_trochopock1; insert_in_top_menu(ui, menu_entry); menu_entry = new ToolStripMenuItem(); menu_entry.Text = pocket_mop_name; menu_entry.Click += pocket_mop_onclick; menu_entry.Image = resources.cam_trochopock1; insert_in_context_menu(ui, menu_entry); // defer attachment to toolbar until the first show. // Custom CAM Toolbar plugin (if installed) may already attached us after Load event, so we react on later Shown event ThisApplication.TopWindow.Shown += on_window_shown; if (CADFile.ExtraTypes == null) { CADFile.ExtraTypes = new List <Type>(); } CADFile.ExtraTypes.Add(typeof(MOPTrochopock)); CADFile.ExtraTypes.Add(typeof(Mop_matmill)); CADFile.ExtraTypes.Add(typeof(MOPTrochoprof)); { MOPTrochopock o = new MOPTrochopock(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(MOPTrochopock)); MemoryStream stream = new MemoryStream(); xmlSerializer.Serialize(stream, o); } { MOPTrochoprof o = new MOPTrochoprof(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(MOPTrochoprof)); MemoryStream stream = new MemoryStream(); xmlSerializer.Serialize(stream, o); } }
private static void insert_in_top_menu(CamBamUI ui, ToolStripMenuItem entry) { for (int i = 0; i < ui.Menus.mnuMachining.DropDownItems.Count; ++i) { ToolStripItem tsi = ui.Menus.mnuMachining.DropDownItems[i]; if (tsi is ToolStripSeparator || i == ui.Menus.mnuMachining.DropDownItems.Count - 1) { ui.Menus.mnuMachining.DropDownItems.Insert(i, entry); return; } } }
private void Application_Idle(object sender, EventArgs e) { try { CamBamUI ui = CamBam.UI.CamBamUI.MainUI; TabControl tabs = ui.SysTabs.Tabs(); if (tabs.SelectedIndex == tabs.TabPages.IndexOf(GRBLMachinePlugin.Page) && ui.ObjectProperties.SelectedObject != GRBLMachinePlugin.Props) { ui.ObjectProperties.SelectedObject = GRBLMachinePlugin.Props; } } catch (Exception) { } }
public static void InitPlugin(CamBamUI ui) { #if DEBUG MessageBox.Show("Now it's time to attach the debugger :-)", "CamBam.CAD.Solids.Plugin"); #endif // // Create the menu item. It shows the config dialog // ui.Menus.mnuPlugins.DropDownItems.Add(new ToolStripMenuItem("3D Solids Plugin", null, new EventHandler((object sender, EventArgs e) => { new PluginOptions().ShowDialog(ThisApplication.TopWindow); }))); ThisApplication.TopWindow.Load += TopWindow_Load; ThisApplication.TopWindow.FormClosing += TopWindow_FormClosing; }
private static void insert_in_context_menu(CamBamUI ui, ToolStripMenuItem entry) { foreach (ToolStripItem tsi in ui.ViewContextMenus.ViewContextMenu.Items) { if (tsi is ToolStripMenuItem && tsi.Name == "machineToolStripMenuItem") { ToolStripMenuItem tsmi = (ToolStripMenuItem)tsi; for (int i = 0; i < tsmi.DropDownItems.Count; ++i) { if (tsmi.DropDownItems[i] is ToolStripSeparator || i == tsmi.DropDownItems.Count - 1) { tsmi.DropDownItems.Insert(i, entry); return; } } } } }
private static void Tabs_SelectedIndexChanged(object sender, EventArgs e) { CamBamUI ui = CamBamUI.MainUI; TabControl tabs = ui.SysTabs.Tabs(); if (tabs.SelectedIndex == tabs.TabPages.IndexOf(Page)) { // prevent a smaller size when dragging the splitter than our UI requires ui.ObjectProperties.SelectedObject = Props; ui.SysTabs.DividerPanel().MinimumSize = new Size(420, 0); } else { // back to default ui.ObjectProperties.SelectedObject = rgObjectProperties[tabs.SelectedIndex]; ui.SysTabs.DividerPanel().MinimumSize = new Size(0, 0); } }
// This is the main entry point into the plugin. public static void InitPlugin(CamBamUI ui) { // Store a reference to the CamBamUI object passed to InitPlugin _ui = ui; // Create a new menu item in the top Plugins menu ToolStripMenuItem mi = null; /* * mi = new ToolStripMenuItem (); * mi.Text = "SVG-Loader (About)"; * mi.Click += new EventHandler (TestPlugin_Click); * ui.Menus.mnuPlugins.DropDownItems.Add (mi); */ mi = new ToolStripMenuItem(); mi.Text = "SVG-Loader import..."; mi.Click += new EventHandler(OpenSVG_Click); ui.Menus.mnuPlugins.DropDownItems.Add(mi); CamBamUI.CADFileHandlers.Add(new Handler()); //ui.CADFileHandlers.Add(new Handler()); }
public OutputCAD(CamBamUI ui) { _ui = ui; }
private void PlayButton_Click(object sender, EventArgs e) { if (!CheckState()) { return; } if (GRBLMachinePlugin.Props.ToolChangeProcess == IgnoreProcessPassOn.Process) { string post = CamBamUI.MainUI.ActiveView.CADFile.MachiningOptions.PostProcessor; if (!string.IsNullOrEmpty(post) && post != "GRBLMachine") { switch (MessageBox.Show("The Post Processor in Machining Options is not 'GRBLMachine'.\r\n\r\nSet Post Processor to 'GRBLMachine' and regenerate GCODE ?", "GRBLMachine - Play", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)) { case DialogResult.Yes: CamBamUI.MainUI.ActiveView.CADFile.MachiningOptions.PostProcessor = "GRBLMachine"; CAMUtils.GenerateGCodeOutput(CamBamUI.MainUI.ActiveView); break; case DialogResult.Cancel: return; case DialogResult.No: break; } } } if (GRBLMachinePlugin.Props.TrackMachine == EnabledDisabled.Enabled) { CamBamUI ui = CamBamUI.MainUI; // turn toolpaths et al on ui.ActiveView.CADFile.ShowToolpaths = true; ui.ActiveView.CADFile.ShowRapids = true; ui.ActiveView.CADFile.ShowDirectionVector = true; ui.ViewContextMenus.RefreshCheckedMenus(); // runs in background, so just start it, we'll do something else in the meanwhile CAMUtils.GenerateToolpaths(ui.ActiveView); // fit current drawing and current perspective to fit view ui.ActiveView.ZoomToFitEx(); // setup ISO-like perspective ( inspired from ViewToolbarAddins (y) ) ViewProjection vp = ui.ActiveView.ViewProjection; Matrix4x4F mx = Matrix4x4F.Identity; mx.Scale(vp.ViewMatrix4x4F.GetScale()); mx.RotZ(-Math.PI / 4f); // 90 degrees mx.RotX(-Math.PI / (4f * (60f / 90f))); // 60 degrees mx.Translate(vp.ViewMatrix4x4F.m[12], vp.ViewMatrix4x4F.m[13], vp.ViewMatrix4x4F.m[14]); vp.ViewMatrix4x4F = mx; // re-zoom, since drawing may now be outside the view ui.ActiveView.ZoomToFitEx(); // wait until GenerateToolpaths is ready while (ui.ActiveView.IsThinking) { Application.DoEvents(); } // re-zoom, since toolpaths may be outside the view ui.ActiveView.ZoomToFitEx(); } _sendingFileName = FileName.Text; _writeThread = new Thread(WriteThread); _writeThread.Name = "GCODE-SenderThread"; _writeThread.IsBackground = true; PauseButton.Checked = false; EnableButtons(); FileName.Enabled = false; BrowseButton.Enabled = false; LinesSent.Text = LinesTotal.Text = "-"; _pauseEvent.Set(); _fileData.Clear(); _writeThread.Start(); }
private void Application_Idle(object sender, EventArgs e) { try { CamBamUI ui = CamBamUI.MainUI; if (_activeCambamFile != ui.CADFileTree.CADFile.Name) { _activeCambamFile = ui.CADFileTree.CADFile.Name; _lastOutfile = null; FileName.Text = ""; } // See if there is any outfile in the MachiningOptions if (!string.IsNullOrEmpty(ui.CADFileTree.CADFile.MachiningOptions.OutFile)) { if (string.IsNullOrEmpty(FileName.Text) || !ui.CADFileTree.CADFile.MachiningOptions.OutFile.Equals(_lastOutfile)) { FileName.Text = FileUtils.GetFullPath(ui.CADFileTree.CADFile, ui.CADFileTree.CADFile.MachiningOptions.OutFile); ToolChange(ui.CADFileTree.CADFile.ActiveTool()); _lastOutfile = ui.CADFileTree.CADFile.MachiningOptions.OutFile; } } else { // try to find a MOPNCFile, which has it's outfile not in 'Outfile' :( foreach (CAMPart part in ui.CADFileTree.CADFile.Parts) { if (part.MachineOps != null) { bool found = false; foreach (MachineOp mop in part.MachineOps) { if (mop is MOPNCFile) { MOPNCFile mopnc = mop as MOPNCFile; if (!string.IsNullOrEmpty(mopnc.SourceFile)) { if (string.IsNullOrEmpty(FileName.Text) || !mopnc.SourceFile.Equals(_lastOutfile)) { FileName.Text = FileUtils.GetFullPath(ui.CADFileTree.CADFile, mopnc.SourceFile); _lastOutfile = mopnc.SourceFile; } found = true; break; } } if (found) { break; } } } } } } catch (Exception) { } if (!PlayButton.Enabled && CanPlay()) { PlayButton.Enabled = true; } FileName.Enabled = _writeThread == null; }
public static ToolDefinition ActiveTool(this CamBamUI ui) { return(ui.ActiveView != null?ui.ActiveView.ActiveTool() : null); }
public static void InitPlugin(CamBamUI ui) { ThisApplication.TopWindow.Load += TopWindow_Load; }
/// <summary> /// This method does al the magic of integrating GRBLMachine's UI into CamBam's /// </summary> /// <returns></returns> private static bool InstallTab() { CamBamUI ui = CamBamUI.MainUI; // Since CamBam comes with an unconstructed UI, durin 'InitPlugin' there is no UI content yet... if (ui.SysTabs != null) { // get the tabcontrol which hosts CamBam's 'Drawing' and 'System' pages TabControl tabs = ui.SysTabs.Tabs(); // // Controversial action #2: Should a plugin tamper with CamBam's UI ??? ;) :P // if (Props.EnableVisualStyles == EnabledDisabled.Enabled) { // set some properties on SysTabs because it just looks better when VisualStyles ar on. ui.SysTabs.BackColor = SystemColors.Control; ui.SysTabs.Padding = new Padding(3, 6, 1, 0); foreach (TabPage p in tabs.TabPages) { p.UseVisualStyleBackColor = false; } } // // Just for conveniance: Add a right-click menu to clear the messages // ThisApplication.TextLogger.ContextMenu = new ContextMenu(); ThisApplication.TextLogger.ContextMenu.MenuItems.Add(new MenuItem("Clear Messages", (x, y) => { ThisApplication.ClearLogMessages(); })); // hook up all eventhandlers ThisApplication.TopWindow.FormClosing += TopWindow_FormClosing; tabs.SelectedIndexChanged += Tabs_SelectedIndexChanged; tabs.Selecting += Tabs_Selecting; State += GRBLMachinePlugin_State; ConnectionExpander.Connected += ConnectionExpander_Connected; ConnectionExpander.Disconnected += ConnectionExpander_Disconnected; // add the GRBL icon to the tabcontrol's imagelist tabs.ImageList.Images.Add(Resources.Grbl_Logo_150px); Page.ImageIndex = tabs.ImageList.Images.Count - 1; // add our UI to the new tabpage Page.Controls.Add(new GRBLMachinePage()); // finally add the Machine page to the tabcontrol tabs.TabPages.Add(Page); // set the various UI states according to what was saved in GRBLMachine.config (Page.Controls[0] as GRBLMachinePage).DisplayExpander.Expanded = Props.DisplayExpanded; (Page.Controls[0] as GRBLMachinePage).ProductionExpander.Expanded = Props.ProductionExpanded; (Page.Controls[0] as GRBLMachinePage).JoggingExpander.Expanded = Props.JoggingExpanded; (Page.Controls[0] as GRBLMachinePage).ConsoleExpander.Expanded = Props.ConsoleExpanded; (Page.Controls[0] as GRBLMachinePage).ConnectionExpander.Expanded = Props.ConnectionExpanded; (Page.Controls[0] as GRBLMachinePage).AboutExpander.Expanded = Props.AboutExpanded; CamBamUI.MainUI.SysTabs.SelectedTab = Props.SelectedTab; // greet the user :) GRBLMachinePlugin.Log("Welcome to GRBL Machine v" + Version + "\n\n"); return(true); } return(false); }