private void trvCharacters_AfterSelect(object sender, TreeViewEventArgs e) { if (trvCharacters.SelectedNode != null && trvCharacters.SelectedNode.Tag != null) { CharacterPath cp = (CharacterPath)trvCharacters.SelectedNode.Tag; CharacterPath_Updated(cp); } }
private void CharacterPath_Updated(CharacterPath cp) { Cursor = Cursors.WaitCursor; //picCharacter.Image = cp.Draw( true); picCharacter.Image = cp.Draw(true); if (cp.EdgeDetector != null) { statPointCount.Text = cp.EdgeDetector.EdgeCrawler.Count().ToString() + " Paths"; } Cursor = Cursors.Default; GC.Collect(); }
public CharacterPath Add(CharacterPath cp) { this._charLib.Add(cp); return(_charLib[_charLib.Count - 1]); //if (!this.Contains(cp.Character)) //{ //} //else //{ // throw new DuplicateWaitObjectException(); //} }
private string CharacterToGCode(CharacterPath cp) { double imgWidth = cp.Image.Width; double imgHeight = cp.Image.Height; double ratHeight = Convert.ToDouble(Properties.Settings.Default.GCodeHeight); double ratWidth = ((imgWidth * ratHeight) / imgHeight); var strOut = new StringBuilder(); strOut.AppendLine("(CHARACTER: " + cp.Character + " HEIGHT: " + ratHeight.ToString("0.0000") + " WIDTH: " + ratWidth.ToString("0.0000") + ")"); strOut.AppendLine("G91 (BEGIN INCREMENTAL PATH)"); strOut.AppendLine("G51 X" + (((imgWidth / 2) / imgWidth) * ratWidth).ToString("0.00000") + " Y" + (((imgHeight / 2) / imgHeight) * ratHeight).ToString("0.00000") + " P#19 (SCALE)"); Point[][] nomPaths = cp.GetPaths(); Point[][] paths = cp.GetIncrementalPaths(); int tot = 0; for (int i = 0; i < paths.Count(); i++) { tot += paths[i].Count(); strOut.AppendLine("(PATH " + (i + 1).ToString() + ")"); for (int j = 0; j < paths[i].Count(); j++) { double x, y; x = (paths[i][j].X / imgWidth) * ratWidth; y = (paths[i][j].Y / imgHeight) * ratHeight; if (j == 0) { strOut.AppendLine("G00 X" + x.ToString("0.00000") + " Y" + y.ToString("0.00000") + " (GO TO FIRST POINT)"); strOut.AppendLine("G01 Z-#26 (INCREMENT DOWN TO CUT)"); } else { strOut.AppendLine("X" + x.ToString("0.00000") + " Y" + y.ToString("0.00000")); } } strOut.AppendLine("G00 Z#26 (INCREMENT OUT)"); strOut.AppendLine("X" + (((0 - nomPaths[i][nomPaths[i].Count() - 1].X) / imgWidth) * ratWidth).ToString("0.00000") + " Y-" + (((imgHeight - nomPaths[i][nomPaths[i].Count() - 1].Y) / imgHeight) * ratHeight).ToString("0.00000") + "(MOVE TO START)"); } //Console.WriteLine("Finished Length=" + tot.ToString()); strOut.AppendLine("X" + (ratWidth).ToString("0.00000") + "(MOVE TO NEXT CORNER)"); strOut.AppendLine("G50 (CANCEL SCALE)"); strOut.AppendLine("G90 (BACK TO ABSOLUTE FOR SAFETY)"); return(strOut.ToString()); }
private void Sv_FileOk_AllCharacters(object sender, CancelEventArgs e) { Cursor = Cursors.WaitCursor; SaveFileDialog sv = (SaveFileDialog)sender; var strOut = new StringBuilder(); int idx = 1; var strHead = new StringBuilder(); var strMacros = new StringBuilder(); strHead.AppendLine("O" + Properties.Settings.Default.GCodeProgram); strHead.AppendLine("(MACRO: " + mnuFontFamilies.SelectedItem.ToString() + " FONT " + Properties.Settings.Default.FontSize + "em)"); strHead.AppendLine("(DATE: " + DateTime.Now.ToString("yyyy-MM-dd hh-mm tt") + ")"); strHead.AppendLine(); strHead.AppendLine("(SHORTEST DISTANCE: {DISTANCE}in)"); strHead.AppendLine(); strHead.AppendLine("(-- USAGE --)"); strHead.AppendLine("( - USE G65 TO CALL THIS PROGRAM)"); strHead.AppendLine("( - PASS ARGUMENTS -SEE BELOW-, AT LEAST CHARACTER INDEX)"); strHead.AppendLine("( - REFERENCE THE LIST BELOW FOR CHARACTER INDICES)"); strHead.AppendLine("(EXAMPLES - G65 P" + Properties.Settings.Default.GCodeProgram + " C70 Z0.1 S1 (F 0.1 DEEP 1:1 SCALE))"); strHead.AppendLine("( G65 P" + Properties.Settings.Default.GCodeProgram + " C79 Z0.2 S1 (O 0.2 DEEP 1:1 SCALE))"); strHead.AppendLine("( G65 P" + Properties.Settings.Default.GCodeProgram + " C78 S1 (N 0.1 DEEP 1:1 SCALE))"); strHead.AppendLine("( G65 P" + Properties.Settings.Default.GCodeProgram + " C84 (T 0.1 DEEP 1:1 SCALE))"); strHead.AppendLine(); strHead.AppendLine("(-- VARIABLE DEFINITIONS --)"); strHead.AppendLine("([C]#3 = CHARACTER INDEX -SEE BELOW-)"); strHead.AppendLine("([S]#19 = SCALE PATTERN IN XY)"); strHead.AppendLine("([Z]#26 = DEPTH OF CUT)"); strHead.AppendLine(); strHead.AppendLine("IF[#19NE0]GOTO10 (SCALE PASSED IN MACRO CALL)"); strHead.AppendLine("#19 = 1 (SET DEFAULT SCALE)"); strHead.AppendLine("N10 (SKIPPED DEFAULT SCALE)"); strHead.AppendLine("IF[#26NE0]GOTO11 (DEPTH PASSED IN MACRO CALL)"); strHead.AppendLine("#26 = " + Convert.ToDouble(Properties.Settings.Default.GCodeDepth).ToString() + " (SET DEFAULT DEPTH)"); strHead.AppendLine("N11 (SKIPPED DEFAULT DEPTH)"); strHead.AppendLine(); strHead.AppendLine("(-- CHARACTER INDICES --)"); double dist = 0; double shortest = 999; double avgHeight = 0; foreach (TreeNode item in trvCharacters.Nodes[0].Nodes) { strHead.AppendLine("(" + ((int)item.Text[0]).ToString() + " = " + item.Text + ")"); strMacros.AppendLine("IF[#3EQ" + ((int)item.Text[0]).ToString() + "]H" + ((int)item.Text[0]).ToString() + " (CALL MACRO FOR " + item.Text + ")"); strOut.AppendLine("N" + ((int)item.Text[0]).ToString() + " (BEGIN CHARACTER: " + item.Text + ")"); strOut.AppendLine(Properties.Settings.Default.GCodeInit + " (INITIALIZE)"); trvCharacters.SelectedNode = item; trvCharacters_AfterSelect(trvCharacters, null); CharacterPath cp = (CharacterPath)trvCharacters.SelectedNode.Tag; strOut.AppendLine(CharacterToGCode(cp)); dist = (cp).EdgeDetector.GetShortestDistance(); if (dist < shortest) { shortest = dist; } avgHeight += cp.Image.Height; strOut.AppendLine("M99"); idx += 1; } avgHeight /= idx; strHead.Replace("{DISTANCE}", ((shortest / avgHeight) * Convert.ToDouble(Properties.Settings.Default.GCodeHeight)).ToString("0.0000")); strHead.AppendLine(); strHead.AppendLine(strMacros.ToString()); strHead.AppendLine("GOTO200 (SKIP ALL SUBS)"); strOut.Insert(0, strHead); strOut.AppendLine("N200 (SKIPPED SUBS)"); strOut.AppendLine("M99 (END)"); // Save file out System.IO.File.WriteAllText(sv.FileName, strOut.ToString()); statStatus.Text = "Saved!"; Cursor = Cursors.Default; }
public bool Contains(CharacterPath cpath) { return(this.IndexOf(cpath) >= 0); }
public int IndexOf(CharacterPath cpath) { return(this.IndexOf(cpath.Character)); }