Commit Graph

845 Commits

Author SHA1 Message Date
Billy Huddleston
a7b6078b1d CAM: Add open-route optimizations to point-based TSP solver
Improves the point-based TSP solver to match tunnel solver behavior
for open routes (no endpoint constraint). Now applies 2-opt and
relocation optimizations that allow reversing or relocating segments
to the end of the route, resulting in better path optimization when
the ending point is flexible. Now links tsp_solver with
Python3::Python and uses add_library for compatibility with FreeCAD
and Fedora packaging.

src/Mod/CAM/App/tsp_solver.cpp:
- Add optimization limit variables for controlled iteration
- Add 2-opt and relocation optimizations for open routes
- Use Base::Precision::Confusion() for epsilon values
- Track last improvement step for efficient loop control

src/Mod/CAM/App/CMakeLists.txt:
- Switch tsp_solver from pybind11_add_module to add_library
- Link tsp_solver with pybind11::module and Python3::Python
- Update include directories for consistency
2025-12-18 12:15:22 -05:00
sliptonic
a13502dccb Merge pull request #26205 from Connor9220/PreserveTSPTunnelExtraData
CAM: Update TSP tunnel solver
2025-12-16 09:31:14 -06:00
Billy Huddleston
646b0f4492 CAM: Update TSP tunnel solver
Update TSP tunnel solver to match revised Pythonlogic, including
improved early exit, open-ended route handling, and performance tweaks.
Also ensure extra data in tunnel dictionaries is preserved through the
C++/Python interface and add a test for passthrough of extra keys.

src/Mod/CAM/App/tsp_solver.cpp:
- Refactor optimization loop to use lastImprovementAtStep and limit
variables
- Add special handling for open-ended routes (no end point)
- Change epsilon to 10e-6 for consistency with Python
- Cache distance calculations for relocation step

src/Mod/CAM/App/tsp_solver_pybind.cpp:
- Preserve extra keys from input tunnel dicts in output
- Set tunnel index for passthrough

src/Mod/CAM/CAMTests/TestTSPSolver.py:
- Add test to verify extra data in tunnel dicts is preserved through
TSP solver
- Print extra data for debugging
2025-12-15 21:50:51 -05:00
Billy Huddleston
04df03cea1 CAM: Preserve extra tunnel data through TSP solver
Ensures that all extra keys in tunnel dictionaries are preserved after
TSP solving by copying the original input dict and updating solver
results. Adds a dedicated test to verify passthrough of extra data and
prints extra keys for debugging.

src/Mod/CAM/App/tsp_solver_pybind.cpp:
- Copy original tunnel dict and update with solver results to preserve extra keys

src/Mod/CAM/CAMTests/TestTSPSolver.py:
- Add test_09_tunnels_extra_data_passthrough to verify extra data preservation
- Print extra tunnel data in print_tunnels for easier debugging
2025-12-15 16:32:03 -05:00
sliptonic
d116764dc3 CAM: Avoid bosses when pocketing. (#24723) 2025-12-15 12:29:28 -06:00
sliptonic
12355f37e9 Merge pull request #25826 from tarman3/pathcommands_qtcore
CAM: PathCommands - Remove unused import QtCore
2025-12-15 11:59:37 -06:00
sliptonic
e1e8323dc1 Merge pull request #25839 from tarman3/slot_remove_0
CAM: Slot - Remove .0
2025-12-15 11:58:59 -06:00
sliptonic
44a5960d57 Merge pull request #26123 from Connor9220/AddCommandAnnotationsTests
CAM: Add comprehensive tests for Command constructor annotations
2025-12-15 11:57:28 -06:00
Billy Huddleston
095cdb14a7 CAM: Add comprehensive TSP tunnel solver tests and wrapper function
Added extensive test coverage for the TSP tunnel solver including linear
 tunnels, pentagram diagonals, and complex wire geometries with various
 constraint combinations. Introduced a Python wrapper function for
 tunnel sorting that integrates with the C++ solver.

src/Mod/CAM/CAMTests/TestTSPSolver.py:
- Renumbered existing tests to run in sequential order
(test_01_simple_tsp, test_02_start_point, etc.)
- Added print_tunnels() helper function for displaying tunnel
information with original indices
- Added test_06_tunnels_tsp: Tests 7 linear tunnels with varying
lengths, connectivity, and flipping behavior
- Added test_07_pentagram_tunnels_tsp: Tests pentagram diagonal tunnels
 with no constraints, start+end constraints, and start-only constraints
- Added test_08_open_wire_end_only: Tests end-only constraint on complex
 wire with 8 tunnels including crossings and diagonals

src/Mod/CAM/PathScripts/PathUtils.py:
- Added sort_tunnels_tsp() wrapper function that interfaces with the C++
tsp_solver.solveTunnels()
- Supports allowFlipping, routeStartPoint, and routeEndPoint parameters
2025-12-14 16:45:51 -05:00
Billy Huddleston
d940c499b7 CAM: Add TSP tunnel solver with flipping and Python bindings
Introduce TSPTunnel struct and implement TSPSolver::solveTunnels
for optimizing tunnel order with support for flipping and start/end points.
Expose the new functionality to Python via pybind11, returning tunnel
dictionaries with flipped status.

src/Mod/CAM/App/tsp_solver.cpp:
- Add solveTunnels implementation for tunnel TSP with flipping and route endpoints

src/Mod/CAM/App/tsp_solver.h:
- Define TSPTunnel struct
- Declare solveTunnels static method in TSPSolver

src/Mod/CAM/App/tsp_solver_pybind.cpp:
- Add Python wrapper for solveTunnels
- Expose solveTunnels to Python with argument parsing and result conversion
2025-12-13 10:59:47 -05:00
Billy Huddleston
b2b9f03086 CAM: Add comprehensive tests for Command constructor annotations
Add detailed test coverage for the new Command constructor that accepts
annotations parameter, including positional and keyword arguments,
string and numeric annotations, empty annotations, and backward
compatibility. Split existing save/restore tests for better granularity.

src/Mod/CAM/CAMTests/TestPathCommandAnnotations.py:
- Added test14-test20 for Command constructor with annotations
- Split test12 into test12 (empty annotations) and test13
(complex annotations) for focused testing
2025-12-12 20:45:02 -05:00
Billy Huddleston
005cbb937d Rewrite TSP solver for improved path optimization and clarity
- Completely re-implemented the TSP algorithm in C++ for better path quality
- Added detailed comments and documentation to clarify each step
- Improved nearest neighbor, 2-opt, and relocation logic
- Enhanced handling of start/end point constraints
- Updated PathUtils.py docstring to accurately describe start point behavior
2025-12-12 19:39:29 -05:00
Billy Huddleston
428948699a Add startPoint and endPoint support to TSP solver and Python wrapper; add tests
- Enhanced the C++ TSP solver to accept optional start and end points, so the route can begin and/or end at the closest point to specified coordinates.
- Updated the Python pybind11 wrapper and PathUtils.sort_locations_tsp to support startPoint and endPoint as named parameters.
- Added a new Python test suite (TestTSPSolver.py) to verify correct handling of start/end points and integration with PathUtils.
- Registered the new test in TestCAMApp.py and CMakeLists.txt for automatic test discovery.
2025-12-12 19:39:28 -05:00
Billy Huddleston
f9347c781b Add 2-Opt TSP solver
This update introduces a new C++ 2-Opt TSP solver with Python bindings.

src/Mod/CAM/App/CMakeLists.txt:
- Add build and install rules for the new pybind11-based tsp_solver Python module

src/Mod/CAM/App/tsp_solver.cpp:
- Add new C++ implementation of a 2-Opt TSP solver with nearest-neighbor initialization

src/Mod/CAM/App/tsp_solver.h:
- Add TSPPoint struct and TSPSolver class with 2-Opt solve method

src/Mod/CAM/App/tsp_solver_pybind.cpp:
- Add pybind11 wrapper exposing the TSP solver to Python as tsp_solver.solve

src/Mod/CAM/PathScripts/PathUtils.py:
- Add sort_locations_tsp Python wrapper for the C++ TSP solver
- Use tsp_solver.solve for TSP-based
2025-12-12 19:39:28 -05:00
sliptonic
442a36bea6 Merge pull request #25285 from tarman3/profile_restore
CAM: Profile - clean areaOpOnDocumentRestored()
2025-12-12 12:59:55 -06:00
sliptonic
293038762c Merge pull request #25960 from Connor9220/FixBoundaryDressup
CAM: Refactor stock used as boundary to be distinct from regular stock
2025-12-12 12:39:16 -06:00
tarman3
8fcecc97cb CAM: PathCommands - Remove unused import QtCore 2025-12-12 20:32:23 +02:00
sliptonic
7a0b613561 Merge pull request #25218 from tarman3/geom_tol
CAM: Path.Geom.cmdsForEdge() - add tolerance
2025-12-12 12:29:04 -06:00
sliptonic
0135bba534 Merge pull request #24297 from tarman3/simplecopy
CAM: SimpleCopy - Allow multiple selection
2025-12-12 12:23:35 -06:00
sliptonic
b5185a0a22 Merge pull request #25827 from tarman3/pathcommands_looperror
CAM: PathCommands - Remove pop message about loop error
2025-12-12 12:19:38 -06:00
sliptonic
72bc4ef1bd Merge pull request #25938 from Connor9220/AddAnnotationsToCommand
CAM: Add annotations support to Command constructor and Python bindings
2025-12-12 12:17:09 -06:00
sliptonic
c495890491 Merge pull request #25786 from Connor9220/FixLinuxCNCPostprocesor
CAM: Add rigid Tapping back to legacy LinuxCNC postprocessor
2025-12-12 11:44:36 -06:00
sliptonic
45386cdcb7 Merge pull request #25783 from Connor9220/AddUnitsPerToolbit
CAM: Add Units (Metric/Imperial) property to ToolBit
2025-12-12 10:46:42 -06:00
sliptonic
96d1084484 Merge pull request #25850 from petterreinholdtsen/cam-fanuc-post-fixes
CAM: Get Fanuc post processor working and implement several improvements
2025-12-12 10:41:51 -06:00
sliptonic
78102d294d Merge pull request #26008 from tarman3/editor_setText
CAM: CodeEditor - stub for setText()
2025-12-12 10:34:17 -06:00
luzpaz
5c0ff4bd8a Fix typos
Fixes various documentation/source-comment typos
2025-12-12 13:59:38 +01:00
Petter Reinholdtsen
9c78ced00c CAM: Made Fanuc post processor compatible with FreeCAD 1.1.
Use setPlainText() if available, otherwise use setText().
Workaround for a regression from #23862.
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
8386f1394e CAM: Adjusted Fanuc post processor to move Z to tool change position before M6
A "G28 G91 Z0" is needed according to testing and page 195 (6-1-2 Procedure for ATC operation) in
<URL: https://www.milco.bg/source/Technical%20Service/Documentation%20Dahlih/MCV%20510_1250B%20Operation%20and%20maintenance%20manual%20V2_2.pdf >
to get the spindle into the correct position for a tool change.
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
e6c95dbb91 CAM: Added test of Fanuc post processor
Used TestMach3Mach4LegacyPost.py as the starting point with input from
other test scripts too.

The test demonstrate a fix for #25723, as the Fanuc post processor has not been not updated to the latest changes in
the Path module.

This is related to #24676, where thread tapping was added to LinuxCNC, but the equivalent code in the Fanuc
postprocessor were not adjusted to cope, and #25677 where it was observed that the Fanuc postprocessor was
broken in versions 0.20 and 1.0.

Added MockTool class to provide ShapeName to fanuc_post.py, used to
convert drill cycles to threading cycles if the tool has shapeid "tap".
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
38c3eebd7a CAM: Made Fanuc post processor compatible with FreeCAD 1.0.
Several methods introduced 2025-05-04 are preferred, but the methods
available in version 1.0 are used as fallback sources
for active status and coolent enabled.
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
34a5301862 CAM: Switched Fanuc post processor to end program with M30, not M2.
The difference according to the documentation is that M30 will rewind
the paper tape while M2 will not.  The effect on a CNC from 1994 is
that M30 turn on the indicator light marking that the program has
completed, while M2 do not, and the light is wanted to know when
the machine is done.
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
8b500ca9a3 CAM: Adjusted Fanuc post processor to use M05 consistently everywhere. 2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
4c18ac6c54 CAM: Provide correct and more relevant header from Fanuc post processor
Fanuc only understand upper case letters, no point in providing the
file name in lower case letters.  The provided file name is always "-",
so drop it completely. The first comment is presented in the Fanuc user
interface, it should get more relevant content.

Dropped useless semicolon.
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
e4862572ae CAM: Avoid Z overtravel error on Fanuc tool changes
Enabling tool height compensation will cause the axis to move up
the length of the tool, which will cause a Z overtravel error when
the tool change take place close to the top of the machine.  To
counter this move, ask the machine to move its commanded position
down the length of the tool height, which in effect causes no upward
movement after the tool change.  The #4120 variable contain the
current tool number, and #2000 - #20XX contain the tool heights.
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
bcb569977d CAM: Avoid adding trailing space to all M6 lines.
The Fanuc post processor add a trailing space to all M6 lines.
This make it problematic to write test for the generated output,
when compiled with the automatic policy enforcer on github
removing trialing space from the expected output.  Avoid the
problem by removing the trailing space from the generated
output.
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
3c5f39c0ca CAM: Corrected Fanuc post processor M3 handling
The thread tapping implementation in the Fanuc post processor change
behaviour of M3, G81 and G82 when the tool ShapeID matches "tap".
but the code not not expect that the parse() method will be
called with two different classes as arguments.

Rewrite the M3 handling to handle ToolController arguments
instead of crashing with an AttributeError.

Issues:

Fixes #14016
Fixes #25723
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
06fe4b37ba CAM: Switch Fanuc post processor default for M6T0 to disable by default. 2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
87185c8135 CAM: Made empty spindle at the end optional in Fanuc CAM post processing script
Some Fanuc machines do not understand the 'M6 T0' instructions in the
preamble.  Move it out of the preamble and controlled by a new
command line argument --no-end-spindle-empty for the machines
where running to cause a "Tool Number Alarm" and the program to crash
as tool zero is not a valid tool.

Fixes: #25677
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
0cdf9abc4b CAM: Adjusted Fanuc post processing script to always start with a percent
The percent signal to the machine that a program follows, and is not
part of the header but a required part when uploading programs into
the machine.
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
ef794c31bd CAM: Adjusted Fanuc post processing script to not inherit behaviour between calls
Reset line number when using --line-numbers.  Restore all default values when a
command line argument is not used.

This helps the test scripts ensure that the arguments passed during one test is the only
one taking effect during this test.
2025-12-11 00:57:21 +01:00
Petter Reinholdtsen
533e957f80 CAM: Print "Show editor" status boolean as string, not integer
This get rid of a Python style warning and make the output easier
to understand.
2025-12-11 00:57:20 +01:00
Billy Huddleston
5085a286bd CAM: Add Units (Metric/Imperial) property to ToolBit
This PR allows each Toolbit to have its own Units property (Metric/Imperial) for better unit management.

Short Summary:
- Adds a Units property (Metric/Imperial) to ToolBit objects for better unit management.
- Ensures ToolBit schema is set and restored properly in the editor and utilities.
- Updates formatting and property handling to respect the selected units.
- Improves the ToolBit editor widget to refresh and sync schema/UI when units change.
- Uses FreeCAD.Units.setSchema and getSchema to switch between unit schemas.

NOTE: Toolbit dimensions are read from JSON in their native units  (as specified by the Units property),
converted to metric for all internal calculations, and displayed in the UI using the
toolbit's selected units. This ensures both accurate internal computation and user-friendly
display, while storing the correct units in the JSON. This can cause some rounding differences
when switching units. Example: 2 mm becomes 0.0787 inches. If you save that as imperial and then
switch back to metric, it will show 1.9999 mm

src/Mod/CAM/Path/Tool/toolbit/models/base.py:
- Add Units property to ToolBit and ensure it's set and synced with toolbit shape parameters.
- Update property creation and value formatting to use Units.

src/Mod/CAM/Path/Tool/toolbit/ui/editor.py:
- Use setToolBitSchema to set schema based on toolbit units.
- Add logic to refresh property editor widget when units change.
- Restore original schema on close.
- Improve docstrings and signal handling.

src/Mod/CAM/Path/Tool/toolbit/util.py:
- Add setToolBitSchema function for robust schema switching.
- Update format_value to use schema and units.
- Add docstrings and clarify formatting logic.

src/Mod/CAM/Path/Tool/library/ui/browser.py:
- Restore original schema after editing toolbit.

src/Mod/CAM/Path/Tool/library/ui/editor.py:
- Ensure correct schema is set for new toolbits.
2025-12-10 14:57:33 -05:00
jffmichi
8058f824e2 CAM: revert accidental icon name change from #25440 2025-12-09 05:53:05 +01:00
freecad-gh-actions-translation-bot
f7483a08b4 Update translations from Crowdin 2025-12-08 22:31:48 -06:00
tarman3
76d939c21f CAM: CodeEditor - stub for setText() 2025-12-07 20:23:14 +02:00
Billy Huddleston
8e2dc8cd19 CAM: Refactor stock used as boundary to be distinct from regular stock
This commit makes boundary stock objects distinct from regular stock by
setting a boundary flag and label, and prevents editing of boundary
objects in the job view provider.

src/Mod/CAM/Path/Dressup/Boundary.py:
- Add promoteStockToBoundary method, set boundary properties, handle
missing stock/shape

src/Mod/CAM/Path/Main/Gui/Job.py:
- Block editing for objects flagged as boundary stock
2025-12-04 12:43:43 -05:00
Billy Huddleston
047cd38c24 CAM: Add annotations support to Command constructor and Python bindings
This commit introduces support for passing an 'annotations' dictionary
to the Command class constructor and its Python bindings. The annotations
dictionary can contain string or numeric values for each key, allowing for
richer metadata on CAM commands. Each annotation must be provided as a
key-value pair within a dictionary.

Examples:

cmd = Command("G1", {"X": 10.0, "Y": 5.0}, {"note": "Rapid move"})

cmd = Command("G2", {"X": 20.0, "Y": 15.0}, {"priority": 1})

cmd = Command("G3", {"X": 30.0, "Y": 25.0}, {"note": "Arc move", "speed": 1500})

cmd = Command("G0", {"X": 0.0, "Y": 0.0}, {})

cmd = Command("G0", {"X": 0.0, "Y": 0.0})

cmd = Command("G1", {"X": 10.0, "Y": 5.0}, annotations={"note": "Rapid move"})

src/Mod/CAM/App/Command.cpp:
- Added new Command constructor accepting annotations

src/Mod/CAM/App/Command.h:
- Declared new Command constructor with annotations parameter

src/Mod/CAM/App/Command.pyi:
- Updated docstring to describe annotations argument

src/Mod/CAM/App/CommandPyImp.cpp:
- Extended Python init to parse and set annotations dictionary
2025-12-03 15:44:18 -05:00
Billy Huddleston
ab817f8dc5 CAM: Fix job assignment and model/stock initialization in ObjectOp
This PR fixes a bug introduced with PR #25800
It updates the ObjectOp class to correctly assign the job, model,
and stock properties from the parentJob object. Previously, only
PathUtils.addToJob was called, which did not set these attributes directly.

This change ensures that when creating a new operation, the job, model,
and stock fields are properly initialized from the parent job. This
fixes issues where operations did not inherit the correct job context,
leading to missing or incorrect references to the model and stock, and
potential errors in downstream processing.
2025-12-03 00:23:23 -05:00
sliptonic
20c2eee9db CAM: Suppress rendering of first rapids (#25440) 2025-12-02 12:20:07 -06:00
Billy Huddleston
b5d97057be CAM: Introduce unified ToolBit parameter migration logic for Bullnose tools
- Added new migration system to handle legacy parameter conversion for ToolBit assets and objects.
- Implemented ParameterAccessor abstraction for consistent access to dicts and FreeCAD objects.
- Centralized migration logic for CornerRadius from TorusRadius or FlatRadius/Diameter, restricted to Bullnose shape-type.
- Updated asset and object initialization to use migration logic and filter Bullnose parameters.

src/Mod/CAM/Path/Tool/camassets.py:
- Integrate new migration logic for ToolBit assets using ParameterAccessor and migrate_parameters.
- Ensure shape-type is set before parameter migration; only write changes if migration occurred.

src/Mod/CAM/Path/Tool/toolbit/migration.py:
- Add ParameterAccessor class and migrate_parameters function for unified migration.
- Handle legacy parameter conversion for Bullnose tools.

src/Mod/CAM/Path/Tool/toolbit/models/base.py:
- Apply migration logic to ToolBit objects on restore.
- Filter Bullnose parameters to remove FlatRadius after migration.

src/Mod/CAM/Path/Tool/shape/models/bullnose.py:
- Add filter_parameters method to remove FlatRadius for Bullnose.

src/Mod/CAM/Path/Op/SurfaceSupport.py:
- Derive FlatRadius from CornerRadius and Diameter if both are present.

src/Mod/CAM/Path/Op/Surface.py:
- Remove obsolete setOclCutter method.
2025-12-01 11:30:00 -06:00