Skip to content

Updates for the object version migration.#145

Open
glenn20 wants to merge 3 commits into
Stu142:masterfrom
glenn20:fix-migrate-version-add-thinlipstyle
Open

Updates for the object version migration.#145
glenn20 wants to merge 3 commits into
Stu142:masterfrom
glenn20:fix-migrate-version-add-thinlipstyle

Conversation

@glenn20

@glenn20 glenn20 commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

This PR makes changes to check_version.migrate_object_version() to:

  1. Rewrite to make decisions on migrating properties by inspecting the properties, rather than inspecting the object version number.
    • This makes it easier for PRs to add migrations without knowing what the version number will be when the PR is merged.
  2. Add migration for the StackingLipThinStyle property added in v0.12.1.
  3. Add migration for the MagnetHoleChamfer property for Magnet Baseplates added in v0.11.9.

I suggest that future PRs which add or modify object properties should be required to either:

  • ensure they work correctly when new expected properties are absent or in the wrong format OR
  • add code to check_version.py to update properties to ensure backward compatibility.

@Stu142 and @greg19: This PR is necessary to ensure the thin stacking lip style can be added to objects loaded from versions of the workbench prior to v0.12.1.

I have tested backward compatibility as far back as v0.11.8. Those tests have simply to ensure each of the objects can be recomputed without any errors or warnings and some minor changes to the object properties.

glenn20 added 2 commits March 1, 2026 10:17
…ate properties.

Use the presence of the properties themselves to determine whether to add new
properties or update existing ones, rather than relying on the object version.

This makes it easier for new PRs to introduce changes without knowing in
advance the version number when the PR will be merged.

diff --git a/freecad/gridfinity_workbench/check_version.py b/freecad/gridfinity_workbench/check_version.py
index 2a9e275..0f9d8e2 100644
--- a/freecad/gridfinity_workbench/check_version.py
+++ b/freecad/gridfinity_workbench/check_version.py
@@ -25,13 +25,10 @@ def migrate_object_version(obj: fc.DocumentObject) -> None:  # noqa: C901
     if check_object_version(obj):
         return

-    def versiontuple(v: str) -> tuple[int, ...]:
-        return tuple(map(int, (v.split("."))))
+    ### v0.11.9 Changes ###

-    migrated = False
-    if versiontuple(obj.version) < versiontuple("0.11.9"):
-        migrated = True
-        # v0.11.9: Changes to the magnet properties.
+    if hasattr(obj, "MagnetHoles"):
+        # Add properties for the crush ribs to hold magnets.
         if not hasattr(obj, "CrushRibsCount"):
             obj.addProperty(
                 "App::PropertyInteger",
@@ -47,7 +44,7 @@ def migrate_object_version(obj: fc.DocumentObject) -> None:  # noqa: C901
                 "Waviness of crush ribs, from range [0, 1]",
             ).CrushRibsWaviness = (const.CRUSH_RIB_WAVINESS, 0, 1, 0.05)

-        # v0.11.9: MagnetRelief property was renamed to MagnetRemoveChannel
+        # MagnetRelief property was renamed to MagnetRemoveChannel
         if not hasattr(obj, "MagnetRemoveChannel"):
             obj.addProperty(
                 "App::PropertyBool",
@@ -58,39 +55,39 @@ def migrate_object_version(obj: fc.DocumentObject) -> None:  # noqa: C901
         if hasattr(obj, "MagnetRelief"):
             obj.removeProperty("MagnetRelief")

-    if versiontuple(obj.version) < versiontuple("0.12.0"):
-        migrated = True
-        # v0.12.0: calculation of UsableHeight was changed to use object Expressions.
+    ### v0.12.0 Changes ###
+
+    # Calculation of UsableHeight was changed to use object Expressions.
+    if hasattr(obj, "UsableHeight") and not obj.getExpression("UsableHeight"):
         obj.setExpression("UsableHeight", "TotalHeight - HeightUnitValue")

-        # v0.12.0: xGridUnits and yGridUnits were changed from int to float properties.
-        xgridunits = getattr(obj, "xGridUnits", None)
-        if xgridunits is None or isinstance(xgridunits, int):
-            obj.removeProperty("xGridUnits")
-            obj.addProperty(
-                "App::PropertyFloat",
-                "xGridUnits",
-                "Gridfinity",
-                "Number of grid units in the x direction <br> <br> default = 2",
-            ).xGridUnits = float(xgridunits or const.X_GRID_UNITS)
-
-        ygridunits = getattr(obj, "yGridUnits", None)
-        if ygridunits is None or isinstance(ygridunits, int):
-            obj.removeProperty("yGridUnits")
-            obj.addProperty(
-                "App::PropertyFloat",
-                "yGridUnits",
-                "Gridfinity",
-                "Number of grid units in the y direction <br> <br> default = 2",
-            ).yGridUnits = float(ygridunits or const.Y_GRID_UNITS)
+    # xGridUnits and yGridUnits were changed from int to float properties.
+    if hasattr(obj, "xGridUnits") and isinstance(obj.xGridUnits, int):
+        xgridunits = obj.xGridUnits
+        obj.removeProperty("xGridUnits")
+        obj.addProperty(
+            "App::PropertyFloat",
+            "xGridUnits",
+            "Gridfinity",
+            "Number of grid units in the x direction <br> <br> default = 2",
+        ).xGridUnits = float(xgridunits)
+
+    if hasattr(obj, "yGridUnits") and isinstance(obj.yGridUnits, int):
+        ygridunits = obj.yGridUnits
+        obj.removeProperty("yGridUnits")
+        obj.addProperty(
+            "App::PropertyFloat",
+            "yGridUnits",
+            "Gridfinity",
+            "Number of grid units in the y direction <br> <br> default = 2",
+        ).yGridUnits = float(ygridunits)
+
+    fc.Console.PrintLog(
+        f"Gridfinity Workbench v{__version__}: "
+        f"updating '{obj.Name}' object properties from version v{obj.version}.\n"
+        f"'{obj.Name}' will be saved with v{__version__} properties.\n",
+    )

     # Update the version property to the current version after updating the object.
     obj.version = __version__
-
-    if migrated:
-        obj.recompute()  # Force re-evaluation of expressions after updating properties.
-        fc.Console.PrintLog(
-            f"Gridfinity Workbench v{__version__}: "
-            f"updating '{obj.Name}' object properties from version v{obj.version}.\n"
-            f"'{obj.Name}' will be saved with v{__version__} properties.\n",
-        )
+    obj.recompute()  # Force re-evaluation of expressions after updating properties.
…ion.

The StackingLipThinStyle property was added in v0.12.1 to toggle the
thin style stacking lip on or off. This commit adds a migration step
to the check_version.py script to add this property to existing objects
that have the StackingLip property but do not have the
StackingLipThinStyle property.
@glenn20 glenn20 force-pushed the fix-migrate-version-add-thinlipstyle branch from c27bc39 to 43fa358 Compare March 1, 2026 04:19
…ation.

MagnetHoleChamfer is needed for baseplates with magnet holes since v0.11.9.
@glenn20 glenn20 force-pushed the fix-migrate-version-add-thinlipstyle branch from 43fa358 to d879e37 Compare March 1, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants