Skip to content

Conversation

cbentejac
Copy link
Contributor

@cbentejac cbentejac commented Aug 7, 2024

Description

This PR adds a new property called instanceType in the attribute description classes that contains the class of the corresponding attribute object.

This property is then used to instantiate directly attribute objects, rather than performing tests on the type of the description class to determine which constructor to use.

This solves an issue where any description that would inherit from an existing one would lead to instantiating an attribute of the parent class, e.g. having a description class inheriting ChoiceParam would always lead to a ChoiceParam attribute being created, even if a dedicated attribute class corresponding to that description existed.

To set instanceType in a description class, the getInstanceType method can be overriden. By default, instanceType will always be set to Attribute.

Below is an example of custom description and attribute classes that inherit ChoiceParam, and a node using this new attribute:

from meshroom.common import Property, Variant
from meshroom.core import attribute, desc

class TestAttribute(attribute.ChoiceParam):
    # custom implementation
    pass

class TestDescription(desc.ChoiceParam):
    def getInstanceType(self):
        return TestAttribute

    instanceType = Property(Variant, getInstanceType, constant=True)
    type = Property(str, lambda self: self.__class__.__base__.__name__, constant=True)  # allows the parameter to be interpreted as a ChoiceParam from a UI standpoint
__version__ = "1.0"

from meshroom.core import desc, custom

class TestAttributeType(desc.InputNode):
    documentation = """ """
    category = 'Test'

    # Inputs to the node
    inputs = [
        custom.TestDescription(
            name="testAttribute",
            label="Test Attribute",
            description="Custom attribute inheriting ChoiceParam.",
            value="a",
            values=["a", "b", "c", "d"],
            exclusive=True,
            uid=[0],
        )
    ]

@cbentejac cbentejac added this to the Meshroom 2024.1.0 milestone Aug 7, 2024
@cbentejac cbentejac self-assigned this Aug 7, 2024
@fabiencastan fabiencastan added the feature new feature (proposed as PR or issue planned by dev) label Aug 12, 2024
@cbentejac cbentejac force-pushed the dev/inheritedAttributes branch from 8cfffa6 to cc88120 Compare August 13, 2024 13:38
@fabiencastan fabiencastan merged commit d356199 into develop Aug 19, 2024
4 checks passed
@fabiencastan fabiencastan deleted the dev/inheritedAttributes branch August 19, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature (proposed as PR or issue planned by dev)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants