Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
qpding opened this issue May 10, 2022 · 0 comments

Comments

@qpding
Copy link

qpding commented May 10, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant