SofaPython3 icon indicating copy to clipboard operation
SofaPython3 copied to clipboard

Raise a warning or an error when a property is not provided with the correct dimension

Open qpding opened this issue 3 years ago • 0 comments

This issue is linked to this discussion in the SoftRobots Plugin.

When defining a Prefab object, zero(s) will be concatenated to the end if a property of vector type is provided with a shorter vector. @EulalieCoevoet provided a good example:

import Sofa

class EmptyPrefab(Sofa.Prefab):

    properties = [
        {'name':'myProperty', 'type':'Vec4d', 'help':'',  'default':[1.,1.,1.,1.]}
    ]

    def __init__(self, *args, **kwargs):
        Sofa.Prefab.__init__(self, *args, **kwargs)
        print(self.myProperty.value)


def createScene(root):
    myPrefab = EmptyPrefab(myProperty=[1,1])
    root.addChild(myPrefab)

When running the above code, [1. 1. 0. 0.] will be printed. Although being a good and safe default behavior, this behavior can lead to confusion in some cases. For example, when creating a OglModel with node.addObject('OglModel', src="@mesh", color="0.8 0.7 0.7") the color property will be appended with a 0.0 to make it 4D, which makes the OglModel transparent, and misleads users to think that the Visual Models are not working properly.

So it could be beneficial to raise a warning when a property value is not provided with the correct dimension.

qpding avatar May 10 '22 13:05 qpding