Beispiel #1
0
    def __init__(self, root_entity, main_camera):
        """
        A class that houses the Qt3D items (entities, transformations, etc) related to the gnomon (or axis indicator).
        The gnomon/axis indicator is an object that appears in the bottom right-hand corner of the instrument view that
        shows the direction of the x, y, and z axes.
        :param root_entity: The root entity for the gnomon.
        :param main_camera: The main component view camera.
        """

        self.gnomon_root_entity = root_entity
        self.gnomon_cylinder_length = 4
        self.main_camera = main_camera
        self.gnomon_camera = self.create_gnomon_camera(main_camera)

        self.x_text_transformation = Qt3DCore.QTransform()
        self.y_text_transformation = Qt3DCore.QTransform()
        self.z_text_transformation = Qt3DCore.QTransform()

        # Set the text translation value to be the length of the cylinder plus some extra space so that it doesn't
        # overlap with the cylinder or the cones.
        text_translation = self.gnomon_cylinder_length * 1.3

        # The text translation value calculated above is used in addition to some "extra" values in order to make the
        # text placement look good and appear centered next to the cone point. This extra values were found via trial
        # and error and will likely have to be figured out again if you decide to change the font/size/height/etc of
        # the text.
        self.x_text_vector = QVector3D(text_translation, -0.5, 0)
        self.y_text_vector = QVector3D(-0.4, text_translation, 0)
        self.z_text_vector = QVector3D(-0.5, -0.5, text_translation)

        diffuse_color = QColor("grey")

        self.x_material = create_material(AxisColors.X.value,
                                          diffuse_color,
                                          root_entity,
                                          remove_shininess=True)
        self.y_material = create_material(AxisColors.Y.value,
                                          diffuse_color,
                                          root_entity,
                                          remove_shininess=True)
        self.z_material = create_material(AxisColors.Z.value,
                                          diffuse_color,
                                          root_entity,
                                          remove_shininess=True)

        self.num_neutrons = 9

        self.neutron_animation_length = self.gnomon_cylinder_length * 1.5
Beispiel #2
0
    def setup_neutrons(self):
        """
        Sets up the neutrons and their animations by preparing their meshes and then giving offset and
        distance parameters to an animation controller.
        """

        # Create lists of x, y, and time offsets for the neutron animations
        x_offsets = [0, 0, 0, 2, -2, 1.4, 1.4, -1.4, -1.4]
        y_offsets = [0, 2, -2, 0, 0, 1.4, -1.4, 1.4, -1.4]
        time_span_offsets = [0, -5, -7, 5, 7, 19, -19, 23, -23]

        neutron_radius = 1.5

        for i in range(self.num_neutrons):
            mesh = Qt3DExtras.QSphereMesh(self.gnomon_root_entity)
            self.set_sphere_mesh_radius(mesh, neutron_radius)

            transform = Qt3DCore.QTransform(self.gnomon_root_entity)
            neutron_animation_controller = NeutronAnimationController(
                x_offsets[i] * 0.5, y_offsets[i] * 0.5, transform)
            neutron_animation_controller.set_target(transform)

            neutron_animation = QPropertyAnimation(transform)
            self.set_neutron_animation_properties(
                neutron_animation,
                neutron_animation_controller,
                self.neutron_animation_length,
                time_span_offsets[i],
            )

            neutron_material = create_material(QColor("black"), QColor("grey"),
                                               self.gnomon_root_entity)

            create_qentity([mesh, neutron_material, transform],
                           self.gnomon_root_entity)
Beispiel #3
0
def test_GIVEN_material_properties_WHEN_calling_set_material_properties_THEN_properties_set(
    mock,
):

    ambient = Mock()
    diffuse = Mock()

    mock_material = create_material(ambient, diffuse, None)

    mock_material.setAmbient.assert_called_once_with(ambient)
    mock_material.setDiffuse.assert_called_once_with(diffuse)
    mock_material.setAlpha.assert_not_called()
    mock_material.setShininess.assert_not_called()
Beispiel #4
0
def test_GIVEN_shininess_argument_WHEN_calling_set_material_properties_THEN_shininess_set_to_zero(
    mock,
):

    ambient = Mock()
    diffuse = Mock()

    mock_material = create_material(ambient, diffuse, None, remove_shininess=True)

    mock_material.setAmbient.assert_called_once_with(ambient)
    mock_material.setDiffuse.assert_called_once_with(diffuse)
    mock_material.setAlpha.assert_not_called()
    mock_material.setShininess.assert_called_once_with(0)
Beispiel #5
0
 def setup_sample_cube(self):
     """
     Sets up the cube that represents a sample in the 3D view by giving the cube entity a mesh and a material.
     """
     cube_mesh = Qt3DExtras.QCuboidMesh(self.component_root_entity)
     self.set_cube_mesh_dimensions(cube_mesh, *[0.1, 0.1, 0.1])
     dark_red = QColor("#b00")
     sample_material = create_material(
         QColor("red"), dark_red, self.component_root_entity, alpha=0.5
     )
     self.component_entities["sample"] = create_qentity(
         [cube_mesh, sample_material], self.component_root_entity
     )
Beispiel #6
0
 def setup_beam_cylinder(self):
     """
     Sets up the beam cylinder by giving the cylinder entity a mesh, a material, and a transformation.
     """
     # Initialise beam objects
     cylinder_mesh = Qt3DExtras.QCylinderMesh(self.gnomon_root_entity)
     cylinder_transform = Qt3DCore.QTransform(self.gnomon_root_entity)
     self.set_cylinder_mesh_dimensions(cylinder_mesh, 1.5,
                                       self.neutron_animation_length, 2)
     self.set_beam_transform(cylinder_transform,
                             self.neutron_animation_length)
     beam_material = create_material(QColor("blue"),
                                     QColor("lightblue"),
                                     self.gnomon_root_entity,
                                     alpha=0.5)
     create_qentity([cylinder_mesh, beam_material, cylinder_transform],
                    self.gnomon_root_entity)
Beispiel #7
0
    def add_component(
        self, name: str, geometry: OFFGeometry, positions: List[QVector3D] = None
    ):
        """
        Add a component to the instrument view given a name and its geometry.
        :param name: The name of the component.
        :param geometry: The geometry information of the component that is used to create a mesh.
        :param positions: Mesh is repeated at each of these positions
        """
        if geometry is None:
            return

        mesh = OffMesh(geometry.off_geometry, self.component_root_entity, positions)
        material = create_material(
            QColor("black"), QColor("grey"), self.component_root_entity
        )

        self.component_entities[name] = create_qentity(
            [mesh, material], self.component_root_entity
        )
    def __init__(self, component_root_entity: Qt3DCore.QEntity, line_length: float):
        """
        Class for housing the objects that create the axes in the instrument view.
        :param component_root_entity: The root entity for the instrument view components.
        :param line_length: The length of the line in the axes.
        """
        vertices = [0 for _ in range(3)]

        for i, color in enumerate(
            [AxisColors.X.value, AxisColors.Y.value, AxisColors.Z.value]
        ):
            mesh = Qt3DRender.QGeometryRenderer(component_root_entity)

            line_vertices = vertices[:]
            line_vertices[i] = line_length
            geometry = LineGeometry(
                QtCore.QByteArray(self.create_data_array(line_vertices)),
                component_root_entity,
            )

            self.set_mesh_properties(mesh, geometry)
            material = create_material(color, color, component_root_entity)
            create_qentity([mesh, material], component_root_entity)