Skip to content

Commit 733976e

Browse files
committed
rename the "add" function and make it private
1 parent 4baad13 commit 733976e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

stlib/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__all__ = ["core","entities","prefabs","shapes"]
22

33
import Sofa.Core
4-
def addFromTypeName(self : Sofa.Core.Node, typeName, **kwargs):
4+
def __genericAdd(self : Sofa.Core.Node, typeName, **kwargs):
55
def findName(cname, names):
66
"""Compute a working unique name in the node"""
77
rname = cname
@@ -11,6 +11,7 @@ def findName(cname, names):
1111
rname = cname + str(i+1)
1212
return rname
1313

14+
# Check if a name is provided, if not, use the one of the class
1415
params = kwargs.copy()
1516
isNode = False
1617
if "name" not in params:
@@ -30,11 +31,13 @@ def findName(cname, names):
3031
else:
3132
raise RuntimeError("Invalid argument ", typeName)
3233

34+
# Check if the name already exists, if this happens, create a new one.
3335
if params["name"] in self.children or params["name"] in self.objects:
3436
names = {node.name.value for node in self.children}
3537
names = names.union({object.name.value for object in self.objects})
3638
params["name"] = findName(params["name"], names)
3739

40+
# Dispatch the creation to either addObject or addChild
3841
if isinstance(typeName, type) and issubclass(typeName, Sofa.Core.Node):
3942
pref = self.addChild(typeName(params["name"]))
4043
pref.init()
@@ -52,4 +55,4 @@ def findName(cname, names):
5255
return pref
5356

5457
# Inject the method so it become available as if it was part of Sofa.Core.Node
55-
Sofa.Core.Node.add = addFromTypeName
58+
Sofa.Core.Node.add = __genericAdd

0 commit comments

Comments
 (0)