Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def test_GIVEN_components_WHEN_calling_add_components_to_entity_THEN_components_added(
    mock,
):

    mock_parent = Mock()
    mock_components = [Mock() for _ in range(4)]
    calls = [call(mock_component) for mock_component in mock_components]

    mock_entity = create_qentity(mock_components, mock_parent)
    mock_entity.addComponent.assert_has_calls(calls)

    mock.assert_called_once_with(mock_parent)
Ejemplo n.º 4
0
    def create_gnomon_cylinders(self):
        """
        Configures three cylinder meshes and translates them in order to create a basic gnomon shape.
        """
        x_axis_matrix, y_axis_matrix, z_axis_matrix = self.create_cylinder_matrices(
            self.gnomon_cylinder_length)
        for matrix, material in [
            (x_axis_matrix, self.x_material),
            (y_axis_matrix, self.y_material),
            (z_axis_matrix, self.z_material),
        ]:
            axis_mesh = Qt3DExtras.QCylinderMesh(self.gnomon_root_entity)

            self.configure_gnomon_cylinder(axis_mesh,
                                           self.gnomon_cylinder_length)

            axis_transformation = Qt3DCore.QTransform(self.gnomon_root_entity)
            axis_transformation.setMatrix(matrix)

            create_qentity([axis_mesh, axis_transformation, material],
                           self.gnomon_root_entity)
Ejemplo n.º 5
0
    def create_gnomon_cones(self):
        """
        Prepares the gnomon cones by configuring the meshes and then placing them at the ends of the cylinders.
        """
        x_cone_matrix, y_cone_matrix, z_cone_matrix = self.create_cone_matrices(
            self.gnomon_cylinder_length)

        for matrix, material in [
            (x_cone_matrix, self.x_material),
            (y_cone_matrix, self.y_material),
            (z_cone_matrix, self.z_material),
        ]:
            cone_mesh = Qt3DExtras.QConeMesh(self.gnomon_root_entity)

            self.configure_gnomon_cone(cone_mesh, self.gnomon_cylinder_length)

            cone_transformation = Qt3DCore.QTransform(self.gnomon_root_entity)
            cone_transformation.setMatrix(matrix)

            create_qentity([cone_mesh, cone_transformation, material],
                           self.gnomon_root_entity)
Ejemplo n.º 6
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
     )
    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)
Ejemplo n.º 8
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
        )