public static ToolDefinition CurrentTool(this MachineOp mop) { ToolDefinition def = mop.CurrentTool; if (def == null) { def = new ToolDefinition(mop.Name + " current (from MOP)", mop.ToolNumber.Value, mop.ToolDiameter.Value, 0, 2); } if (mop.ToolDiameter.Value != def.Diameter) { def.Diameter = mop.ToolDiameter.Value; } if (mop.ToolProfile.Value != def.ToolProfile) { def.ToolProfile = mop.ToolProfile.Value; } if (mop.ToolNumber.Value != def.Index) { def.Index = mop.ToolNumber.Value; } return(def); }
private void ToolChange(ToolDefinition tooldef) { if (ToolChanged != null) { ToolChanged(tooldef); } }
public string Tool(ToolType type) { // Ensure the tool type provided is valid. if (!VerifierConstants.Tools.ContainsKey(type)) { throw new ArgumentException($"Unknown tool type: {type}"); } // Retrieve the tool. ToolDefinition tool = VerifierConstants.Tools[type]; // Retrive the tool type's corresponding filename. string fileName = tool.FileName; // Retrieve the tool's root path. string toolRootPath = this.ToolRoot(type); // Combine the tools path (or root path) with the tool's filename. string toolPath = Path.Combine(toolRootPath, fileName); // Resolve the tool path into an absolute path. toolPath = Path.GetFullPath(toolPath); // Return the resulting path. return(toolPath); }
public string ToolRoot(ToolType type) { // Ensure the tool type provided is valid. if (!VerifierConstants.Tools.ContainsKey(type)) { throw new ArgumentException($"Unknown tool type: {type}"); } // Retrieve the tool. ToolDefinition tool = VerifierConstants.Tools[type]; // Resolve tools path. string toolsPath = Paths.BaseDirectory(this.Options.ToolsPath); // Initialize the tool's root path to be the previously resolved tools path. string toolRootPath = toolsPath; // Prepare the tool's root path if applicable. if (tool.Root != null) { // Combine the tools path with the tool's root path. toolRootPath = Path.Combine(toolsPath, tool.Root); } // Return the resulting tool's root path. return(toolRootPath); }
public string Tool(ToolType type) { // Ensure the tool type provided is valid. if (!ToolConstants.Tools.ContainsKey(type)) { throw new ArgumentException($"Unknown tool type: {type}"); } // Retrieve the tool. ToolDefinition tool = ToolConstants.Tools[type]; // Retrive the tool type's corresponding filename. string fileName = tool.FileName; // TODO: Subtly hard-coded. // Append the executable extension if on Windows. if (Util.IsWindowsOS) { fileName += $".{FileExtension.WindowsExecutable}"; } // Retrieve the tool's root path. string toolRootPath = this.ToolRoot(type); // Combine the tools path (or root path) with the tool's filename. string toolPath = Path.Combine(toolRootPath, fileName); // Resolve the tool path into an absolute path. toolPath = Path.GetFullPath(toolPath); // Return the resulting path. return(toolPath); }
public void Invoke(ToolType toolType, string[] args) { // Ensure that the corresponding tool definition exists. if (!ToolConstants.Tools.ContainsKey(toolType)) { throw new Exception("Tool definition for the provided tool type does not exist"); } // Retrieve the tool definition. ToolDefinition tool = ToolConstants.Tools[toolType]; // Resolve the tool's executable path. string resolvedToolPath = this.options.PathResolver.Tool(toolType); // Inform the user that tool's path verification is taking place. Log.Verbose($"Verifying tool '{tool.FileName}' path: {resolvedToolPath}"); // Ensure tool path exists. if (!File.Exists(resolvedToolPath)) { Log.Error($"Tool '{tool.FileName}' does not exist."); } // Otherwise, inform the user that the tool path exists. Log.Verbose($"Tool path for '{tool.FileName}' exists."); // Create the runnable object instance. Runnable runnable = new Runnable { Path = resolvedToolPath, Arguments = args }; // Inform the user of the tool being started. Log.Verbose($"Invoking tool: {tool.FileName}"); // Invoke the runnable. string output = runnable.Run(); // Process the tool output. Log.Output(output, tool.FileName); }
public void Invoke(ToolType toolType, string[] args) { // Create a new process instance. Process process = new Process(); // Ensure that the corresponding tool definition exists. if (!VerifierConstants.Tools.ContainsKey(toolType)) { throw new Exception("Tool definition for the provided tool type does not exist"); } // Retrieve the tool definition. ToolDefinition tool = VerifierConstants.Tools[toolType]; // Resolve the tool's executable path. string resolvedToolPath = this.options.PathResolver.Tool(toolType); // Ensure tool path exists. if (!File.Exists(resolvedToolPath)) { Log.Error($"Tool '{tool.FileName}' does not exist."); } // Otherwise, inform the user that the tool path exists. Log.Verbose($"Tool path for '{tool.FileName}' exists."); // Set the process' target file. process.StartInfo.FileName = resolvedToolPath; // Do not create a window. process.StartInfo.CreateNoWindow = true; // Do not execute from shell. process.StartInfo.UseShellExecute = false; // Fill all provided arguments. foreach (string arg in args) { process.StartInfo.ArgumentList.Add(arg); } // Instruct process to redirect output. process.StartInfo.RedirectStandardOutput = true; // TODO: Handle error stream too? // Instruct process to redirect errors. process.StartInfo.RedirectStandardError = true; // Inform the user of the tool being started. Log.Verbose($"Invoking tool: {tool.FileName}"); // Start the process. process.Start(); // Inform the user of the waiting state. Log.Verbose($"Awaiting tool: {tool.FileName}"); // Capture the output of the tool. string output = process.StandardOutput.ReadToEnd(); // Process the tool's trimmed output. Log.ExternalOutput(output.Trim(), tool.FileName); // Wait for completion. process.WaitForExit(); }
public void SetToolFromGCODE(string toolGCODE) { if (toolGCODE != null) { string[] codesAndComment = toolGCODE.Split('(', ')'); if (codesAndComment.Length != 0) { string[] codes = codesAndComment[0].Split(' '); int index = -1; ToolDefinition def = null; if (codesAndComment.Length > 2) { string[] partAndMop = codesAndComment[1].Split('\\'); if (partAndMop.Length > 1) { foreach (CAMPart part in CamBamUI.MainUI.CADFileTree.CADFile.Parts) { if (part.Name == partAndMop[0]) { foreach (MachineOp mop in part.MachineOps) { if (mop.Name == partAndMop[1]) { def = mop.CurrentTool(); break; } } break; } } } } if (def == null) { foreach (string s in codes) { if (s.ToUpper().StartsWith("T")) { if (int.TryParse(s.Substring(1), out index)) { break; } } } if (index != -1) { } } if (def == null) { def = CamBamUI.MainUI.ActiveTool(); //ICADView view = CamBamUI.MainUI.ActiveView; //if (view != null && view.CADFile != null) //{ // CADFile file = view.CADFile; // if (file.Parts != null && file.Parts.Count != 0) // if (file.Parts[0].MachineOps != null && file.Parts[0].MachineOps.Count != 0) // def = file.Parts[0].MachineOps[0].CurrentTool(); //} if (def == null) { def = new ToolDefinition(); def.Diameter = GRBLMachinePlugin.Props.DefaultToolDiameter; def.FluteLength = GRBLMachinePlugin.Props.DefaultToolFluteLength; def.ToolProfile = ToolProfiles.EndMill; def.Name = "GRBLMachine Default"; foreach (TreeNode root in this.ToolLibraryTree.Nodes) { root.ExpandAll(); } } } TreeNode node = new TreeNode("Current Tool", 2, 2) { Tag = def.Clone() }; ToolLibraryTree.Nodes.Insert(0, node); ToolLibraryTree.SelectedNode = node; propertyInspector.SelectedObject = node.Tag; OK_Button.Enabled = Apply_Button.Enabled = true; } } /// do default }
/// <summary> /// Build a new tool-visual /// </summary> private void CreateTool(ToolDefinition tool) { _toolDiameter = GRBLMachinePlugin.Props.LaserModeEnable == EnabledDisabled.Enabled ? GRBLMachinePlugin.Props.DefaultLaserDiameter : GRBLMachinePlugin.Props.DefaultToolDiameter; _toolFluteLength = GRBLMachinePlugin.Props.DefaultToolFluteLength; _toolTotalLength = GRBLMachinePlugin.Props.DefaultToolTotalLength; _toolShankDiameter = GRBLMachinePlugin.Props.DefaultToolShankDiameter; _toolVAngle = GRBLMachinePlugin.Props.DefaultToolVAngle; _toolProfile = GRBLMachinePlugin.Props.DefaultToolProfile; if (tool != null) { if (tool.Diameter != 0) { _toolDiameter = tool.Diameter; } if (tool.FluteLength != 0) { _toolFluteLength = tool.FluteLength; } if (tool.Length != 0) { _toolTotalLength = tool.Length; } if (tool.ShankDiameter != 0) { _toolShankDiameter = tool.ShankDiameter; } if (tool.VeeAngle != 0) { _toolVAngle = tool.VeeAngle; } if (tool.ToolProfile != ToolProfiles.Unspecified) { _toolProfile = tool.ToolProfile; } } _toolDef = tool; if (GRBLMachinePlugin.Props.LaserModeEnable == EnabledDisabled.Enabled) { _tool = new Laser(_toolDiameter); } else { switch (_toolProfile) { case ToolProfiles.BallNose: _tool = new BallNose(_toolDiameter, _toolFluteLength, _toolShankDiameter, _toolTotalLength); break; case ToolProfiles.BullNose: _tool = new EndMill(_toolDiameter, _toolFluteLength, _toolShankDiameter, _toolTotalLength); break; case ToolProfiles.Drill: _tool = new Drill(_toolDiameter, _toolFluteLength, _toolShankDiameter, _toolTotalLength); break; case ToolProfiles.EndMill: _tool = new EndMill(_toolDiameter, _toolFluteLength, _toolShankDiameter, _toolTotalLength); break; case ToolProfiles.VCutter: _tool = new V_Cutter(_toolDiameter, _toolVAngle, _toolShankDiameter, _toolTotalLength); break; default: _tool = new EndMill(_toolDiameter, _toolFluteLength, _toolShankDiameter, _toolTotalLength); break; } } _lastX = 0; _lastY = 0; _lastZ = 0; }
private void ToolChanger_Applied(ToolChanger toolChanger, ToolDefinition tooldef) { ToolChange(toolChanger.SelectedToolDefinition); }
public static ToolDefinition ActiveTool(this ICADView view) { ToolDefinition tool = view.CADFile != null?view.CADFile.ActiveTool() : null; return(tool != null ? tool : (view.CADFile != null ? view.CADFile.FirstTool() : null)); }