def test_GIVEN_component_with_cylindrical_shape_information_WHEN_duplicating_component_THEN_shape_information_is_stored_in_nexus_file(
    nexus_wrapper, ):

    instrument = Instrument(nexus_wrapper, NX_CLASS_DEFINITIONS)

    first_component_name = "component1"
    first_component_nx_class = "NXdetector"
    description = "desc"
    first_component = instrument.create_component(first_component_name,
                                                  first_component_nx_class,
                                                  description)

    axis_direction = QVector3D(1, 0, 0)
    height = 2
    radius = 3
    units = "cm"
    first_component.set_cylinder_shape(axis_direction=axis_direction,
                                       height=height,
                                       radius=radius,
                                       units=units)
    tree_model = ComponentTreeModel(instrument)

    first_component_index = tree_model.index(0, 0, QModelIndex())
    tree_model.duplicate_node(first_component_index)

    assert tree_model.rowCount(QModelIndex()) == 3
    second_component_index = tree_model.index(2, 0, QModelIndex())
    second_component = second_component_index.internalPointer()
    second_shape, _ = second_component.shape
    assert second_shape.axis_direction == axis_direction
    assert second_shape.height == height
    assert second_shape.units == units
def test_add_transformation_alt_1():
    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_translation(transformation_list_index)
    assert under_test.rowCount(transformation_list_index) == 1
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_add_link_alt_2():
    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_link(transformation_list_index)
    assert under_test.rowCount(transformation_list_index) == 1
    assert transformation_list_index.internalPointer().has_link
    assert len(transformation_list_index.internalPointer()) == 0
def test_add_translation():
    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_translation(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 == "Translation"
Exemple #6
0
def test_remove_link():
    wrapper = NexusWrapper("test_remove_link")
    instrument = Instrument(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_link(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
    assert len(transformation_list_index.internalPointer()) == 0
    under_test.remove_node(transformation_index)
    assert under_test.rowCount(transformation_list_index) == 0
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
def test_get_invalid_index():
    data_under_test = FakeInstrument([get_component()])
    under_test = ComponentTreeModel(data_under_test)

    test_index = QModelIndex()

    assert under_test.index(2, 0, test_index) == QModelIndex()
Exemple #9
0
def test_GIVEN_component_with_off_shape_information_WHEN_duplicating_component_THEN_shape_information_is_stored_in_nexus_file(
):
    wrapper = NexusWrapper("test_duplicate_off_shape")
    instrument = Instrument(wrapper, NX_CLASS_DEFINITIONS)

    first_component_name = "component1"
    first_component_nx_class = "NXdetector"
    description = "desc"
    first_component = instrument.create_component(first_component_name,
                                                  first_component_nx_class,
                                                  description)

    vertices = [
        QVector3D(-0.5, -0.5, 0.5),
        QVector3D(0.5, -0.5, 0.5),
        QVector3D(-0.5, 0.5, 0.5),
        QVector3D(0.5, 0.5, 0.5),
        QVector3D(-0.5, 0.5, -0.5),
        QVector3D(0.5, 0.5, -0.5),
        QVector3D(-0.5, -0.5, -0.5),
        QVector3D(0.5, -0.5, -0.5),
    ]

    faces = [
        [0, 1, 3, 2],
        [2, 3, 5, 4],
        [4, 5, 7, 6],
        [6, 7, 1, 0],
        [1, 7, 5, 3],
        [6, 0, 2, 4],
    ]

    first_component.set_off_shape(
        OFFGeometryNoNexus(vertices=vertices, faces=faces))

    tree_model = ComponentTreeModel(instrument)

    first_component_index = tree_model.index(0, 0, QModelIndex())
    tree_model.duplicate_node(first_component_index)

    assert tree_model.rowCount(QModelIndex()) == 3
    second_component_index = tree_model.index(2, 0, QModelIndex())
    second_component = second_component_index.internalPointer()
    second_shape, _ = second_component.shape

    assert second_shape.vertices == vertices
    assert second_shape.faces == faces
def test_remove_component(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())
    assert under_test.rowCount(QModelIndex()) == 1
    under_test.remove_node(component_index)
    assert under_test.rowCount(QModelIndex()) == 0
def test_duplicate_component():
    data_under_test = Instrument(
        NexusWrapper("test_component_model_duplicate"), NX_CLASS_DEFINITIONS)
    under_test = ComponentTreeModel(data_under_test)

    assert under_test.rowCount(QModelIndex()) == 1  # Sample
    under_test.add_component(get_component())
    component_index = under_test.index(0, 0, QModelIndex())
    under_test.duplicate_node(component_index)
    assert under_test.rowCount(QModelIndex()) == 3
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 get_transformation_or_link_index(
    component_model: ComponentTreeModel,
    component_tree_view: QTreeView,
    transformation_list_index: QModelIndex,
) -> QModelIndex:
    """
    Retrieves the index of a component's first transformation or link.
    :param component_model: The component tree model.
    :param component_tree_view: The component tree view.
    :param transformation_list_index: The index of the component's transformation list.
    :return: The index of the component's first transformation/link.
    """
    component_tree_view.expand(transformation_list_index)
    return component_model.index(0, 0, transformation_list_index)
def get_transformation_list_index(
    component_model: ComponentTreeModel,
    component_tree_view: QTreeView,
    component_index: QModelIndex,
) -> QModelIndex:
    """
    Retrieves the index of a component's transformation list from the component tree view.
    :param component_model: The component model.
    :param component_tree_view: The component tree view.
    :param component_index: The index of the component.
    :return: The index of the component's transformation list.
    """
    component_tree_view.expand(component_index)
    return component_model.index(1, 0, component_index)
Exemple #15
0
def expand_transformation_list(
    node: QModelIndex,
    component_tree_view: QTreeView,
    component_model: ComponentTreeModel,
):
    current_pointer = node.internalPointer()
    if isinstance(current_pointer, TransformationsList) or isinstance(
            current_pointer, Component):
        component_tree_view.expand(node)
        if isinstance(current_pointer, Component):
            trans_list_index = component_model.index(1, 0, node)
            component_tree_view.expand(trans_list_index)
        else:
            component_index = component_model.parent(node)
            component_tree_view.expand(component_index)
    elif isinstance(current_pointer, Transformation):
        trans_list_index = component_model.parent(node)
        component_tree_view.expand(trans_list_index)
        component_index = component_model.parent(trans_list_index)
        component_tree_view.expand(component_index)