예제 #1
0
def test_apply_parsed_view_exact():
    """Apply parsed view sanity check works"""

    import maya.cmds as cmds
    panel = "modelPanel1"

    cmds.modelEditor(panel, edit=True, displayAppearance="wireframe")
    parsed = capture.parse_view(panel)
    display = parsed["viewport_options"]["displayAppearance"]
    assert display == "wireframe"

    # important to test both, just in case wireframe was already
    # set when making the first query, and to make sure this
    # actually does something.
    cmds.modelEditor(panel, edit=True, displayAppearance="smoothShaded")
    parsed = capture.parse_view(panel)
    display = parsed["viewport_options"]["displayAppearance"]
    assert display == "smoothShaded"

    capture.apply_view(panel,
                       viewport_options={"displayAppearance": "wireframe"})
    assert cmds.modelEditor(panel, query=True,
                            displayAppearance=True) == "wireframe"
예제 #2
0
def test_apply_parsed_view_exact():
    """Apply parsed view sanity check works"""

    import maya.cmds as cmds
    panel = "modelPanel1"

    cmds.modelEditor(panel, edit=True, displayAppearance="wireframe")
    parsed = capture.parse_view(panel)
    display = parsed["viewport_options"]["displayAppearance"]
    assert display == "wireframe"

    # important to test both, just in case wireframe was already
    # set when making the first query, and to make sure this
    # actually does something.
    cmds.modelEditor(panel, edit=True, displayAppearance="smoothShaded")
    parsed = capture.parse_view(panel)
    display = parsed["viewport_options"]["displayAppearance"]
    assert display == "smoothShaded"

    capture.apply_view(panel,
                       viewport_options={"displayAppearance": "wireframe"})
    assert cmds.modelEditor(panel,
                            query=True,
                            displayAppearance=True) == "wireframe"
예제 #3
0
def test_apply_parsed_view_all():
    """Apply parsed view all options works"""

    # A set of options all trying to be different from the default
    # settings (in `capture.py`) so we can test "changing states"
    camera_options = {}
    display_options = {}
    viewport_options = {}
    viewport2_options = {}

    for key, value in capture.CameraOptions.items():
        if isinstance(value, bool):
            value = not value
        elif isinstance(value, (int, float)):
            value = value + 1
        else:
            raise Exception("Unexpected value in CameraOptions: %s=%s"
                            % (key, value))

    for key, value in capture.DisplayOptions.items():
        if isinstance(value, bool):
            value = not value
        elif isinstance(value, tuple):
            value = (1, 0, 1)
        else:
            raise Exception("Unexpected value in DisplayOptions: %s=%s"
                            % (key, value))

    for key, value in capture.ViewportOptions.items():
        if isinstance(value, bool):
            value = not value
        elif isinstance(value, (int, float)):
            value = value + 1
        elif isinstance(value, tuple):
            value = (1, 0, 1)
        elif isinstance(value, basestring):
            pass  # Don't bother, for now
        else:
            raise Exception("Unexpected value in ViewportOptions: %s=%s"
                            % (key, value))

    for key, value in capture.Viewport2Options.items():
        if isinstance(value, bool):
            value = not value
        elif isinstance(value, (int, float)):
            value = value + 1
        elif isinstance(value, tuple):
            value = (1, 0, 1)
        elif isinstance(value, basestring):
            pass  # Don't bother, for now
        else:
            raise Exception("Unexpected value in Viewport2Options: %s=%s"
                            % (key, value))

    defaults = {
        "camera_options": capture.CameraOptions.copy(),
        "display_options": capture.DisplayOptions.copy(),
        "viewport_options": capture.ViewportOptions.copy(),
        "viewport2_options": capture.Viewport2Options.copy(),
    }

    others = {
        "camera_options": camera_options,
        "display_options": display_options,
        "viewport_options": viewport_options,
        "viewport2_options": viewport2_options,
    }

    panel = "modelPanel1"

    def compare(this, other):
        """Compare options for only settings available in `this`

        Some color values will be returned with possible floating
        point precision errors as such result in a slightly
        different number. We'd need to compare whilst keeping
        such imprecisions in mind.
        """
        precision = 1e-4

        for opt in this:
            this_option = this[opt]
            other_option = other[opt]

            for key, value in this_option.iteritems():
                other_value = other_option[key]

                if isinstance(value, float) or isinstance(other_value, float):
                    if abs(value - other_value) > precision:
                        return False
                elif isinstance(value, (tuple, list)):
                    # Assuming for now that any tuple or list contains floats
                    if not all((abs(a-b) < precision)
                               for a, b in zip(value, other_value)):
                        return False
                else:
                    if value != other_value:
                        return False

        return True

    # Apply defaults and check
    capture.apply_view(panel, **defaults)
    parsed_defaults = capture.parse_view(panel)
    assert compare(defaults, parsed_defaults)

    # Apply others and check
    capture.apply_view(panel, **others)
    parsed_others = capture.parse_view(panel)
    assert compare(others, parsed_others)
예제 #4
0
def test_apply_parsed_view():
    """Apply parsed view works"""
    options = capture.parse_view("modelPanel1")
    capture.apply_view("modelPanel1", **options)
예제 #5
0
def test_apply_view():
    """Apply view works"""
    capture.apply_view("modelPanel1", camera_options={"overscan": 2})