CAM: Simplify annotation handling in GCode and improve annotation parsing
src/Mod/CAM/App/Command.cpp: - Removed requirement for annotations= prefix; now all text after ; is treated as annotation data. - Updated Command::toGCode to output annotations as key-value pairs in comments. - Improved setFromGCode to extract annotations from any comment after ;. - Enhanced annotation parsing to handle quoted strings and floating-point numbers. - Simplified XML serialization and restoration logic for annotations. src/Mod/CAM/App/Path.cpp: - Added addCommandNoRecalc, allowing bulk loading of commands without repeated recalculation. - Refactored RestoreDocFile to read GCode files line-by-line, parse each command, and call recalculate() only once after all commands are loaded. - Added explanatory comment above the old implementation. src/Mod/CAM/App/Path.h: - Declared addCommandNoRecalc in the Toolpath class. src/Mod/CAM/CAMTests/TestPathCommandAnnotations.py: - Adjusted unit test for scientific notation annotation to check only 6 decimal places. - Adjusted unit test 10 to properly handle assertions with the toGCode method src/Mod/CAM/PathSimulator/AppGL/GCodeParser.cpp: - GCodeParser::ParseLine: Truncate at first semicolon (annotations / comment)
This commit is contained in:
@@ -208,9 +208,16 @@ class TestPathCommandAnnotations(PathTestBase):
|
||||
self.assertEqual(c.Annotations["depth"], "10mm")
|
||||
|
||||
# Annotations should not appear in gcode output
|
||||
self.assertNotIn("operation", gcode)
|
||||
self.assertNotIn("tapping", gcode)
|
||||
self.assertNotIn("thread", gcode)
|
||||
gcode_parts = gcode.split(";", 1)
|
||||
main_gcode = gcode_parts[0]
|
||||
comment = gcode_parts[1] if len(gcode_parts) > 1 else ""
|
||||
|
||||
self.assertIn("operation:'tapping'", comment)
|
||||
self.assertIn("thread:'M6x1.0'", comment)
|
||||
self.assertIn("depth:'10mm'", comment)
|
||||
self.assertNotIn("operation", main_gcode)
|
||||
self.assertNotIn("thread", main_gcode)
|
||||
self.assertNotIn("depth", main_gcode)
|
||||
|
||||
def test11(self):
|
||||
"""Test save/restore with mixed string and numeric annotations (in-memory)."""
|
||||
@@ -301,6 +308,6 @@ class TestPathCommandAnnotations(PathTestBase):
|
||||
self.assertIsInstance(complex_restored.Annotations["operation_id"], str)
|
||||
self.assertIsInstance(complex_restored.Annotations["thread_spec"], str)
|
||||
|
||||
# Check scientific notation
|
||||
self.assertAlmostEqual(complex_restored.Annotations["scientific"], 1.23e-6, places=8)
|
||||
# Check scientific notation (now only 6 decimal places)
|
||||
self.assertAlmostEqual(complex_restored.Annotations["scientific"], 1.23e-6, places=6)
|
||||
self.assertIsInstance(complex_restored.Annotations["scientific"], float)
|
||||
|
||||
Reference in New Issue
Block a user