PartDesign: Prevent user to remove core properties

This commit is contained in:
Florian Foinant-Willig
2025-03-16 22:57:53 +01:00
committed by Kacper Donat
parent b4c41d8c62
commit 2729cfa0df
7 changed files with 24 additions and 24 deletions

View File

@@ -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:

View File

@@ -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):

View File

@@ -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):

View File

@@ -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):

View File

@@ -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):

View File

@@ -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):

View File

@@ -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: