From 2729cfa0dfe69da636a7e8f44d5bbc3a875f824b Mon Sep 17 00:00:00 2001 From: Florian Foinant-Willig Date: Sun, 16 Mar 2025 22:57:53 +0100 Subject: [PATCH] PartDesign: Prevent user to remove core properties --- src/Mod/PartDesign/InvoluteGearFeature.py | 2 +- src/Mod/PartDesign/Scripts/DistanceBolt.py | 8 ++++---- src/Mod/PartDesign/Scripts/Epitrochoid.py | 8 ++++---- src/Mod/PartDesign/Scripts/Parallelepiped.py | 12 ++++++------ src/Mod/PartDesign/Scripts/RadialCopy.py | 6 +++--- src/Mod/PartDesign/Scripts/Spring.py | 8 ++++---- src/Mod/PartDesign/SprocketFeature.py | 4 ++-- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Mod/PartDesign/InvoluteGearFeature.py b/src/Mod/PartDesign/InvoluteGearFeature.py index 8f88a2bb36..cd6f03d775 100644 --- a/src/Mod/PartDesign/InvoluteGearFeature.py +++ b/src/Mod/PartDesign/InvoluteGearFeature.py @@ -86,7 +86,7 @@ class _InvoluteGear: def _ensure_properties(self, obj, is_restore): def ensure_property(type_, name, doc, default): if not hasattr(obj, name): - obj.addProperty(type_, name, "Gear", doc) + obj.addProperty(type_, name, "Gear", doc, locked=True) if callable(default): setattr(obj, name, default()) else: diff --git a/src/Mod/PartDesign/Scripts/DistanceBolt.py b/src/Mod/PartDesign/Scripts/DistanceBolt.py index 46db12ff8b..f14ff40dfe 100644 --- a/src/Mod/PartDesign/Scripts/DistanceBolt.py +++ b/src/Mod/PartDesign/Scripts/DistanceBolt.py @@ -14,10 +14,10 @@ from FreeCAD import Base class DistanceBolt: def __init__(self, obj): ''' Add the properties: Length, Edges, Radius, Height ''' - obj.addProperty("App::PropertyInteger","Edges","Bolt","Number of edges of the outline").Edges=6 - obj.addProperty("App::PropertyLength","Length","Bolt","Length of the edges of the outline").Length=10.0 - obj.addProperty("App::PropertyLength","Radius","Bolt","Radius of the inner circle").Radius=4.0 - obj.addProperty("App::PropertyLength","Height","Bolt","Height of the extrusion").Height=20.0 + obj.addProperty("App::PropertyInteger","Edges","Bolt","Number of edges of the outline", locked=True).Edges=6 + obj.addProperty("App::PropertyLength","Length","Bolt","Length of the edges of the outline", locked=True).Length=10.0 + obj.addProperty("App::PropertyLength","Radius","Bolt","Radius of the inner circle", locked=True).Radius=4.0 + obj.addProperty("App::PropertyLength","Height","Bolt","Height of the extrusion", locked=True).Height=20.0 obj.Proxy = self def onChanged(self, fp, prop): diff --git a/src/Mod/PartDesign/Scripts/Epitrochoid.py b/src/Mod/PartDesign/Scripts/Epitrochoid.py index 9a78544450..0575b55843 100644 --- a/src/Mod/PartDesign/Scripts/Epitrochoid.py +++ b/src/Mod/PartDesign/Scripts/Epitrochoid.py @@ -10,10 +10,10 @@ from FreeCAD import Base class Epitrochoid: def __init__(self, obj): ''' Add the properties: Radius1, Radius2, Distance, Segments ''' - obj.addProperty("App::PropertyLength","Radius1","Epitrochoid","Interior radius").Radius1=60.0 - obj.addProperty("App::PropertyLength","Radius2","Epitrochoid","Exterior radius").Radius2=20.0 - obj.addProperty("App::PropertyLength","Distance","Epitrochoid","Distance").Distance=10.0 - obj.addProperty("App::PropertyInteger","Segments","Epitrochoid","Number of the line segments").Segments=72 + obj.addProperty("App::PropertyLength","Radius1","Epitrochoid","Interior radius", locked=True).Radius1=60.0 + obj.addProperty("App::PropertyLength","Radius2","Epitrochoid","Exterior radius", locked=True).Radius2=20.0 + obj.addProperty("App::PropertyLength","Distance","Epitrochoid","Distance", locked=True).Distance=10.0 + obj.addProperty("App::PropertyInteger","Segments","Epitrochoid","Number of the line segments", locked=True).Segments=72 obj.Proxy = self def onChanged(self, fp, prop): diff --git a/src/Mod/PartDesign/Scripts/Parallelepiped.py b/src/Mod/PartDesign/Scripts/Parallelepiped.py index 205b7ffe79..6ebb1eb503 100644 --- a/src/Mod/PartDesign/Scripts/Parallelepiped.py +++ b/src/Mod/PartDesign/Scripts/Parallelepiped.py @@ -14,9 +14,9 @@ from FreeCAD import Base class Parallelepiped: def __init__(self, obj): ''' Add the properties: Length, Edges, Radius, Height ''' - obj.addProperty("App::PropertyVector","A","Parallelepiped","Vector").A=Base.Vector(1,0,0) - obj.addProperty("App::PropertyVector","B","Parallelepiped","Vector").B=Base.Vector(0,1,0) - obj.addProperty("App::PropertyVector","C","Parallelepiped","Vector").C=Base.Vector(0,0,1) + obj.addProperty("App::PropertyVector","A","Parallelepiped","Vector", locked=True).A=Base.Vector(1,0,0) + obj.addProperty("App::PropertyVector","B","Parallelepiped","Vector", locked=True).B=Base.Vector(0,1,0) + obj.addProperty("App::PropertyVector","C","Parallelepiped","Vector", locked=True).C=Base.Vector(0,0,1) obj.Proxy = self def onChanged(self, fp, prop): @@ -43,9 +43,9 @@ class Parallelepiped: class BoxCylinder: def __init__(self, obj): - obj.addProperty("App::PropertyFloat","Length","BoxCylinder","Length").Length=10.0 - obj.addProperty("App::PropertyFloat","Width","BoxCylinder","Width").Width=10.0 - obj.addProperty("App::PropertyLink","Source","BoxCylinder","Source").Source=None + obj.addProperty("App::PropertyFloat","Length","BoxCylinder","Length", locked=True).Length=10.0 + obj.addProperty("App::PropertyFloat","Width","BoxCylinder","Width", locked=True).Width=10.0 + obj.addProperty("App::PropertyLink","Source","BoxCylinder","Source", locked=True).Source=None obj.Proxy = self def onChanged(self, fp, prop): diff --git a/src/Mod/PartDesign/Scripts/RadialCopy.py b/src/Mod/PartDesign/Scripts/RadialCopy.py index 167f1a966f..75f7e433e8 100644 --- a/src/Mod/PartDesign/Scripts/RadialCopy.py +++ b/src/Mod/PartDesign/Scripts/RadialCopy.py @@ -26,9 +26,9 @@ def makeCopy(shape, radius, angle): class RadialCopy: def __init__(self, obj): - obj.addProperty("App::PropertyLength","Radius","","Radius").Radius=10.0 - obj.addProperty("App::PropertyLength","Angle" ,"","Angle").Angle=20.0 - obj.addProperty("App::PropertyLink","Source" ,"","Source shape").Source=None + obj.addProperty("App::PropertyLength","Radius","","Radius", locked=True).Radius=10.0 + obj.addProperty("App::PropertyLength","Angle" ,"","Angle", locked=True).Angle=20.0 + obj.addProperty("App::PropertyLink","Source" ,"","Source shape", locked=True).Source=None obj.Proxy = self # def onChanged(self, fp, prop): diff --git a/src/Mod/PartDesign/Scripts/Spring.py b/src/Mod/PartDesign/Scripts/Spring.py index 5276f48c37..8b4d9f1a7a 100644 --- a/src/Mod/PartDesign/Scripts/Spring.py +++ b/src/Mod/PartDesign/Scripts/Spring.py @@ -9,10 +9,10 @@ from FreeCAD import Base class MySpring: def __init__(self, obj): ''' Add the properties: Pitch, Diameter, Height, BarDiameter ''' - obj.addProperty("App::PropertyLength", "Pitch", "MySpring", "Pitch of the helix").Pitch = 5.0 - obj.addProperty("App::PropertyLength", "Diameter", "MySpring", "Diameter of the helix").Diameter = 6.0 - obj.addProperty("App::PropertyLength", "Height", "MySpring", "Height of the helix").Height = 30.0 - obj.addProperty("App::PropertyLength", "BarDiameter", "MySpring", "Diameter of the bar").BarDiameter = 3.0 + obj.addProperty("App::PropertyLength", "Pitch", "MySpring", "Pitch of the helix", locked=True).Pitch = 5.0 + obj.addProperty("App::PropertyLength", "Diameter", "MySpring", "Diameter of the helix", locked=True).Diameter = 6.0 + obj.addProperty("App::PropertyLength", "Height", "MySpring", "Height of the helix", locked=True).Height = 30.0 + obj.addProperty("App::PropertyLength", "BarDiameter", "MySpring", "Diameter of the bar", locked=True).BarDiameter = 3.0 obj.Proxy = self def onChanged(self, fp, prop): diff --git a/src/Mod/PartDesign/SprocketFeature.py b/src/Mod/PartDesign/SprocketFeature.py index 626e597e58..530b819403 100644 --- a/src/Mod/PartDesign/SprocketFeature.py +++ b/src/Mod/PartDesign/SprocketFeature.py @@ -136,7 +136,7 @@ class Sprocket: "App::PropertyEnumeration", "SprocketReference", "Sprocket", - "Sprocket Reference", + "Sprocket Reference", locked=True, ) obj.SprocketReference = list(self.sprockRef) obj.Proxy = self @@ -148,7 +148,7 @@ class Sprocket: def _ensure_properties(self, obj, is_restore): def ensure_property(type_, name, doc, default): if not hasattr(obj, name): - obj.addProperty(type_, name, "Sprocket") + obj.addProperty(type_, name, "Sprocket", locked=True) if callable(default): setattr(obj, name, default()) else: