Updates for the object version migration.#145
Open
glenn20 wants to merge 3 commits into
Open
Conversation
…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.
c27bc39 to
43fa358
Compare
…ation. MagnetHoleChamfer is needed for baseplates with magnet holes since v0.11.9.
43fa358 to
d879e37
Compare
greg19
approved these changes
Mar 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes changes to
check_version.migrate_object_version()to:StackingLipThinStyleproperty added in v0.12.1.MagnetHoleChamferproperty for Magnet Baseplates added in v0.11.9.I suggest that future PRs which add or modify object properties should be required to either:
check_version.pyto 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.