def test_remove_transformation(nexus_wrapper):
    instrument = Instrument(nexus_wrapper, NX_CLASS_DEFINITIONS)
    under_test = ComponentTreeModel(instrument)
    instrument.create_component("Some name", "some class", "desc")
    component_index = under_test.index(0, 0, QModelIndex())
    under_test.add_rotation(component_index)
    transformation_list_index = under_test.index(1, 0, component_index)
    transformation_index = under_test.index(0, 0, transformation_list_index)
    assert under_test.rowCount(transformation_list_index) == 1
    under_test.remove_node(transformation_index)
    assert under_test.rowCount(transformation_list_index) == 0
def test_remove_component_with_transformation(nexus_wrapper):
    instrument = Instrument(nexus_wrapper, NX_CLASS_DEFINITIONS)
    under_test = ComponentTreeModel(instrument)
    instrument.create_component("Some name", "some class", "desc")
    component_index = under_test.index(0, 0, QModelIndex())
    under_test.add_rotation(component_index)
    assert under_test.rowCount(QModelIndex()) == 1
    under_test.remove_node(component_index)
    assert under_test.rowCount(QModelIndex()) == 0, (
        "Expected component to be successfully deleted because it has "
        "a transformation that only has it as a dependent")
def test_add_rotation():
    data_under_test = FakeInstrument([])
    under_test = ComponentTreeModel(data_under_test)

    under_test.add_component(get_component())
    component_index = under_test.index(0, 0, QModelIndex())
    transformation_list_index = under_test.index(1, 0, component_index)
    assert under_test.rowCount(transformation_list_index) == 0
    under_test.add_rotation(component_index)
    assert under_test.rowCount(transformation_list_index) == 1
    transform_index = under_test.index(0, 0, transformation_list_index)
    assert transform_index.internalPointer().type == "Rotation"
def test_add_link_alt_3():
    data_under_test = FakeInstrument([])
    under_test = ComponentTreeModel(data_under_test)

    under_test.add_component(get_component())
    component_index = under_test.index(0, 0, QModelIndex())
    transformation_list_index = under_test.index(1, 0, component_index)
    under_test.add_rotation(component_index)
    transform_index = under_test.index(0, 0, transformation_list_index)
    assert under_test.rowCount(transformation_list_index) == 1
    under_test.add_link(transform_index)
    assert under_test.rowCount(transformation_list_index) == 2
    assert transformation_list_index.internalPointer().has_link
    assert len(transformation_list_index.internalPointer()) == 1
Ejemplo n.º 5
0
def add_transformation(
    transformation_type: TransformationType,
    component_tree_view: QTreeView,
    component_model: ComponentTreeModel,
):
    selected = component_tree_view.selectedIndexes()
    if len(selected) > 0:
        current_index = selected[0]
        if transformation_type == TransformationType.TRANSLATION:
            component_model.add_translation(current_index)
        elif transformation_type == TransformationType.ROTATION:
            component_model.add_rotation(current_index)
        else:
            raise ValueError(f"Unknown transformation type: {transformation_type}")
        expand_transformation_list(current_index, component_tree_view, component_model)
def test_duplicate_transform_fail():
    data_under_test = Instrument(
        NexusWrapper("test_component_model_duplicate_fail"),
        NX_CLASS_DEFINITIONS)
    under_test = ComponentTreeModel(data_under_test)

    under_test.add_component(get_component())
    component_index = under_test.index(0, 0, QModelIndex())
    under_test.add_rotation(component_index)
    transformation_list_index = under_test.index(1, 0, component_index)
    transformation_index = under_test.index(0, 0, transformation_list_index)
    try:
        under_test.duplicate_node(transformation_index)
    except (NotImplementedError, AttributeError):
        return  # Success
    assert False  # Failure