def _getModelXYforCoord(self, row, column):
     radius = DEFAULT_RADIUS
     if self.griditem.grid_type is GridType.HONEYCOMB:
         return HoneycombDnaPart.latticeCoordToQtXY(radius, row, column)
     elif self.griditem.grid_type is GridType.SQUARE:
         return SquareDnaPart.latticeCoordToQtXY(radius, row, column)
     else:
         return None
Example #2
0
def determineLatticeType(part_dict: dict) -> EnumType:
    """Guess the lattice type based on the sum of the vector distances between
    VHs and the closest lattice position.


    Args:
        part_dict:  the ``dict`` corresponding to the part to be imported

    Returns:
        ``GridEnum.HONEYCOMB`` or ``GridEnum.SQUARE`` or ``GridEnum.NONE``
    """
    grid_type = part_dict.get('grid_type')
    if grid_type is not None:
        return grid_type

    vh_id_list = part_dict.get('vh_list')
    origins = part_dict.get('origins')

    square_delta_x = 0.
    square_delta_y = 0.

    honeycomb_delta_x = 0.
    honeycomb_delta_y = 0.

    for vh_id, _ in vh_id_list:
        vh_x, vh_y = origins[vh_id]
        hcd, honeycomb_guess_coordinates = HoneycombDnaPart.distanceFromClosestLatticeCoord(
            DEFAULT_RADIUS, vh_x, vh_y)
        sqd, square_guess_coordinates = SquareDnaPart.distanceFromClosestLatticeCoord(
            DEFAULT_RADIUS, vh_x, vh_y)

        honeycomb_guess_x, honeycomb_guess_y = HoneycombDnaPart.latticeCoordToQtXY(
            DEFAULT_RADIUS, honeycomb_guess_coordinates[0],
            honeycomb_guess_coordinates[1])
        square_guess_x, square_guess_y = SquareDnaPart.latticeCoordToQtXY(
            DEFAULT_RADIUS, square_guess_coordinates[0],
            square_guess_coordinates[1])

        honeycomb_delta_x += (vh_x - honeycomb_guess_x)
        honeycomb_delta_y += (vh_y - honeycomb_guess_y)

        square_delta_x += (vh_x - square_guess_x)
        square_delta_y += (vh_y - square_guess_y)

    sum_honeycomb_distance = (honeycomb_delta_x**2 + honeycomb_delta_y**2)**0.5
    sum_square_distance = (square_delta_x**2 + square_delta_y**2)**0.5

    if abs(sum_honeycomb_distance) < abs(sum_square_distance):
        return GridEnum.HONEYCOMB
    else:
        return GridEnum.SQUARE
Example #3
0
def determineLatticeType(part_dict: dict) -> EnumType:
    """Guess the lattice type based on the sum of the vector distances between
    VHs and the closest lattice position.


    Args:
        part_dict:  the ``dict`` corresponding to the part to be imported

    Returns:
        ``GridEnum.HONEYCOMB`` or ``GridEnum.SQUARE`` or ``GridEnum.NONE``
    """
    grid_type = part_dict.get('grid_type')
    if grid_type is not None:
        return grid_type

    vh_id_list = part_dict.get('vh_list')
    origins = part_dict.get('origins')

    square_delta_x = 0.
    square_delta_y = 0.

    honeycomb_delta_x = 0.
    honeycomb_delta_y = 0.

    for vh_id, _ in vh_id_list:
        vh_x, vh_y = origins[vh_id]
        hcd, honeycomb_guess_coordinates = HoneycombDnaPart.distanceFromClosestLatticeCoord(DEFAULT_RADIUS, vh_x, vh_y)
        sqd, square_guess_coordinates = SquareDnaPart.distanceFromClosestLatticeCoord(DEFAULT_RADIUS, vh_x, vh_y)

        honeycomb_guess_x, honeycomb_guess_y = HoneycombDnaPart.latticeCoordToQtXY(DEFAULT_RADIUS,
                                                                                   honeycomb_guess_coordinates[0],
                                                                                   honeycomb_guess_coordinates[1])
        square_guess_x, square_guess_y = SquareDnaPart.latticeCoordToQtXY(DEFAULT_RADIUS,
                                                                          square_guess_coordinates[0],
                                                                          square_guess_coordinates[1])

        honeycomb_delta_x += (vh_x - honeycomb_guess_x)
        honeycomb_delta_y += (vh_y - honeycomb_guess_y)

        square_delta_x += (vh_x - square_guess_x)
        square_delta_y += (vh_y - square_guess_y)

    sum_honeycomb_distance = (honeycomb_delta_x**2 + honeycomb_delta_y**2)**0.5
    sum_square_distance = (square_delta_x**2 + square_delta_y**2)**0.5

    if abs(sum_honeycomb_distance) < abs(sum_square_distance):
        return GridEnum.HONEYCOMB
    else:
        return GridEnum.SQUARE