From 23536f0ff3c77085275abb074386c28a08c93eeb Mon Sep 17 00:00:00 2001 From: Samuel Abels Date: Tue, 27 May 2025 16:04:10 +0200 Subject: [PATCH] CAM: No need to copy defaultl shapes anymore, because the asset manager now dynamically fetches built-in shapes as a fallback --- src/Mod/CAM/CAMTests/PathTestUtils.py | 3 ++- src/Mod/CAM/Path/Tool/camassets.py | 22 ++++++++++++++++++-- src/Mod/CAM/Tools/Bit/30degree_Vbit.fctb | 1 + src/Mod/CAM/Tools/Bit/375-16_Tap.fctb | 1 + src/Mod/CAM/Tools/Bit/45degree_Vbit.fctb | 1 + src/Mod/CAM/Tools/Bit/45degree_chamfer.fctb | 1 + src/Mod/CAM/Tools/Bit/5mm-thread-cutter.fctb | 1 + src/Mod/CAM/Tools/Bit/5mm_Drill.fctb | 1 + src/Mod/CAM/Tools/Bit/5mm_Endmill.fctb | 1 + src/Mod/CAM/Tools/Bit/60degree_Vbit.fctb | 1 + src/Mod/CAM/Tools/Bit/6mm_Ball_End.fctb | 1 + src/Mod/CAM/Tools/Bit/6mm_Bullnose.fctb | 1 + src/Mod/CAM/Tools/Bit/90degree_Vbit.fctb | 1 + src/Mod/CAM/Tools/Bit/probe.fctb | 1 + src/Mod/CAM/Tools/Bit/slittingsaw.fctb | 1 + 15 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/Mod/CAM/CAMTests/PathTestUtils.py b/src/Mod/CAM/CAMTests/PathTestUtils.py index 34e073c017..45dca875e5 100644 --- a/src/Mod/CAM/CAMTests/PathTestUtils.py +++ b/src/Mod/CAM/CAMTests/PathTestUtils.py @@ -30,7 +30,7 @@ import unittest from Path.Tool.assets import AssetManager, MemoryStore, DummyAssetSerializer from Path.Tool.library.serializers import FCTLSerializer from Path.Tool.toolbit.serializers import FCTBSerializer -from Path.Tool.camassets import ensure_assets_initialized +from Path.Tool.camassets import ensure_assets_initialized, ensure_toolbitshape_assets_present from Path.Tool.library import Library from Path.Tool.toolbit import ToolBit from Path.Tool.shape import ToolBitShape @@ -235,6 +235,7 @@ class PathTestWithAssets(PathTestBase): # Include the built-in assets from src/Mod/CAM/Tools. # These functions only copy if there are no assets, so this # must be done BEFORE adding the additional test assets below. + ensure_toolbitshape_assets_present(self.assets, self.asset_store.name) ensure_assets_initialized(self.assets, self.asset_store.name) # Additional test assets. diff --git a/src/Mod/CAM/Path/Tool/camassets.py b/src/Mod/CAM/Path/Tool/camassets.py index 65001ee4e4..da6c019d29 100644 --- a/src/Mod/CAM/Path/Tool/camassets.py +++ b/src/Mod/CAM/Path/Tool/camassets.py @@ -85,10 +85,17 @@ def ensure_toolbit_assets_initialized(asset_manager: AssetManager, store_name: s ensure_toolbits_have_shape_type(asset_manager, store_name) -def ensure_toolbitshape_assets_initialized(asset_manager: AssetManager, store_name: str = "local"): +def ensure_toolbitshape_assets_present(asset_manager: AssetManager, store_name: str = "local"): """ Ensures the given store is initialized with built-in shapes - if it is currently empty. + if it is currently empty. This copies all built-in shapes, + which is generally not recommended, but is useful for + testing. + + In practice, the built-in tools don't need to be copied, + because the CamAssetManager will automatically fall back to + fetching them from the builtin store if they are not + present in the local store (=the user's Shape directory). """ builtin_shape_path = Preferences.getBuiltinShapePath() @@ -118,6 +125,17 @@ def ensure_toolbitshape_assets_initialized(asset_manager: AssetManager, store_na asset_manager.add_file("toolbitshapepng", path, asset_id=path.stem + ".png") +def ensure_toolbitshape_assets_initialized(asset_manager: AssetManager, store_name: str = "local"): + """ + Copies an example shape to the given store if it is currently empty. + """ + builtin_shape_path = Preferences.getBuiltinShapePath() + + if asset_manager.is_empty("toolbitshape", store=store_name): + path = builtin_shape_path / "endmill.fcstd" + asset_manager.add_file("toolbitshape", path, store=store_name, asset_id="example") + + def ensure_assets_initialized(asset_manager: AssetManager, store="local"): """ Ensures the given store is initialized with built-in assets. diff --git a/src/Mod/CAM/Tools/Bit/30degree_Vbit.fctb b/src/Mod/CAM/Tools/Bit/30degree_Vbit.fctb index 9469c6afd8..db4940610f 100644 --- a/src/Mod/CAM/Tools/Bit/30degree_Vbit.fctb +++ b/src/Mod/CAM/Tools/Bit/30degree_Vbit.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "30 Deg. V-Bit", "shape": "v-bit.fcstd", + "shape-type": "VBit", "parameter": { "CuttingEdgeAngle": "30.0000 \u00b0", "Diameter": "10.0000 mm", diff --git a/src/Mod/CAM/Tools/Bit/375-16_Tap.fctb b/src/Mod/CAM/Tools/Bit/375-16_Tap.fctb index e4032a36c8..2688479c5e 100644 --- a/src/Mod/CAM/Tools/Bit/375-16_Tap.fctb +++ b/src/Mod/CAM/Tools/Bit/375-16_Tap.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "375-16_Tap", "shape": "tap.fcstd", + "shape-type": "tap", "parameter": { "Coating": "None", "CuttingEdgeLength": "1.063 \"", diff --git a/src/Mod/CAM/Tools/Bit/45degree_Vbit.fctb b/src/Mod/CAM/Tools/Bit/45degree_Vbit.fctb index 9284f8cb7e..4a238aea38 100644 --- a/src/Mod/CAM/Tools/Bit/45degree_Vbit.fctb +++ b/src/Mod/CAM/Tools/Bit/45degree_Vbit.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "45 Deg. V-Bit", "shape": "v-bit.fcstd", + "shape-type": "VBit", "parameter": { "CuttingEdgeAngle": "45.0000 \u00b0", "Diameter": "10.0000 mm", diff --git a/src/Mod/CAM/Tools/Bit/45degree_chamfer.fctb b/src/Mod/CAM/Tools/Bit/45degree_chamfer.fctb index 3e501cedab..e56eb1e26b 100644 --- a/src/Mod/CAM/Tools/Bit/45degree_chamfer.fctb +++ b/src/Mod/CAM/Tools/Bit/45degree_chamfer.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "45 Deg. Chamfer", "shape": "chamfer.fcstd", + "shape-type": "Chamfer", "parameter": { "CuttingEdgeAngle": "45.0000 \u00b0", "CuttingEdgeHeight": "6.3500 mm", diff --git a/src/Mod/CAM/Tools/Bit/5mm-thread-cutter.fctb b/src/Mod/CAM/Tools/Bit/5mm-thread-cutter.fctb index 2a5f0253cd..41a558aff6 100644 --- a/src/Mod/CAM/Tools/Bit/5mm-thread-cutter.fctb +++ b/src/Mod/CAM/Tools/Bit/5mm-thread-cutter.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "5mm-thread-cutter", "shape": "thread-mill.fcstd", + "shape-type": "ThreadMill", "parameter": { "Crest": "0.10 mm", "Diameter": "5.00 mm", diff --git a/src/Mod/CAM/Tools/Bit/5mm_Drill.fctb b/src/Mod/CAM/Tools/Bit/5mm_Drill.fctb index afc4db9c30..f304d5324e 100644 --- a/src/Mod/CAM/Tools/Bit/5mm_Drill.fctb +++ b/src/Mod/CAM/Tools/Bit/5mm_Drill.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "5mm Drill", "shape": "drill.fcstd", + "shape-type": "Drill", "parameter": { "Diameter": "5.0000 mm", "Length": "50.0000 mm", diff --git a/src/Mod/CAM/Tools/Bit/5mm_Endmill.fctb b/src/Mod/CAM/Tools/Bit/5mm_Endmill.fctb index 7cc72ba33c..024b7bccaf 100644 --- a/src/Mod/CAM/Tools/Bit/5mm_Endmill.fctb +++ b/src/Mod/CAM/Tools/Bit/5mm_Endmill.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "5mm Endmill", "shape": "endmill.fcstd", + "shape-type": "Endmill", "parameter": { "CuttingEdgeHeight": "30.0000 mm", "Diameter": "5.0000 mm", diff --git a/src/Mod/CAM/Tools/Bit/60degree_Vbit.fctb b/src/Mod/CAM/Tools/Bit/60degree_Vbit.fctb index 9702ebda5c..d1eee54cdc 100644 --- a/src/Mod/CAM/Tools/Bit/60degree_Vbit.fctb +++ b/src/Mod/CAM/Tools/Bit/60degree_Vbit.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "60 Deg. V-Bit", "shape": "v-bit.fcstd", + "shape-type": "VBit", "parameter": { "CuttingEdgeAngle": "60.0000 \u00b0", "Diameter": "10.0000 mm", diff --git a/src/Mod/CAM/Tools/Bit/6mm_Ball_End.fctb b/src/Mod/CAM/Tools/Bit/6mm_Ball_End.fctb index 36f1abcfef..572cba4931 100644 --- a/src/Mod/CAM/Tools/Bit/6mm_Ball_End.fctb +++ b/src/Mod/CAM/Tools/Bit/6mm_Ball_End.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "6mm Ball End", "shape": "ballend.fcstd", + "shape-type": "Ballend", "parameter": { "CuttingEdgeHeight": "40.0000 mm", "Diameter": "6.0000 mm", diff --git a/src/Mod/CAM/Tools/Bit/6mm_Bullnose.fctb b/src/Mod/CAM/Tools/Bit/6mm_Bullnose.fctb index ccff179d77..b2830fd38c 100644 --- a/src/Mod/CAM/Tools/Bit/6mm_Bullnose.fctb +++ b/src/Mod/CAM/Tools/Bit/6mm_Bullnose.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "6 mm Bull Nose", "shape": "bullnose.fcstd", + "shape-type": "Bullnose", "parameter": { "CuttingEdgeHeight": "40.0000 mm", "Diameter": "6.0000 mm", diff --git a/src/Mod/CAM/Tools/Bit/90degree_Vbit.fctb b/src/Mod/CAM/Tools/Bit/90degree_Vbit.fctb index 9134dfc7db..5e7ad683bb 100644 --- a/src/Mod/CAM/Tools/Bit/90degree_Vbit.fctb +++ b/src/Mod/CAM/Tools/Bit/90degree_Vbit.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "90 Deg. V-Bit", "shape": "v-bit.fcstd", + "shape-type": "VBit", "parameter": { "CuttingEdgeAngle": "90.0000 \u00b0", "Diameter": "10.0000 mm", diff --git a/src/Mod/CAM/Tools/Bit/probe.fctb b/src/Mod/CAM/Tools/Bit/probe.fctb index 31fa354ff6..4d0cfde7c4 100644 --- a/src/Mod/CAM/Tools/Bit/probe.fctb +++ b/src/Mod/CAM/Tools/Bit/probe.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "Probe", "shape": "probe.fcstd", + "shape-type": "Probe", "parameter": { "Diameter": "6.0000 mm", "Length": "50.0000 mm", diff --git a/src/Mod/CAM/Tools/Bit/slittingsaw.fctb b/src/Mod/CAM/Tools/Bit/slittingsaw.fctb index 5b63c060ed..109cb70128 100644 --- a/src/Mod/CAM/Tools/Bit/slittingsaw.fctb +++ b/src/Mod/CAM/Tools/Bit/slittingsaw.fctb @@ -2,6 +2,7 @@ "version": 2, "name": "Slitting Saw", "shape": "slittingsaw.fcstd", + "shape-type": "SlittingSaw", "parameter": { "BladeThickness": "3.0000 mm", "CapHeight": "3.0000 mm",