Exemple #1
0
    def draw_mesh(self, canvas):
        """
        Divide figure and it's air-rectangles by right triangles
        """
        M = self.mesh
        scale = self.generate_scaler()
        form = self.mesh.data["form"]

        # Draw air surroundings
        canvas.setPen(self.COL_AIR)
        if M.NAT != 0:
            self.draw_rect_mesh(canvas, 0, 0, M.NAL + M.NFX + M.NAR, M.NAT)
        if M.NAB != 0:
            self.draw_rect_mesh(canvas, 0, M.NAT + M.NFY,
                                M.NAL + M.NFX + M.NAR, M.NAB)
        if M.NAL != 0:
            self.draw_rect_mesh(canvas, 0, M.NAT, M.NAL, M.NFY)
        if M.NAR != 0:
            self.draw_rect_mesh(canvas, M.NAL + M.NFX, M.NAT, M.NAR, M.NFY)

        # Draw contour of mirrored air part
        most_left_x, most_left_y = scale(self.vertexes[0])
        most_right_x, most_right_y = scale(self.vertexes[1])
        third_x, third_y = scale(self.vertexes[2])
        if form == 0:
            canvas.drawLine(most_left_x, most_left_y, most_right_x,
                            most_left_y)
            canvas.drawLine(most_right_x, most_right_y, most_right_x,
                            most_left_y)
        elif form == 1:
            canvas.drawLine(most_left_x, most_right_y, most_right_x,
                            most_right_y)
            canvas.drawLine(most_left_x, most_right_y, most_left_x,
                            most_left_y)
        elif form == 2:
            canvas.drawLine(most_left_x, third_y, most_right_x, third_y)
            canvas.drawLine(most_right_x, most_right_y, most_right_x, third_y)
        elif form == 3:
            canvas.drawLine(most_left_x, third_y, most_right_x, third_y)
            canvas.drawLine(most_left_x, most_left_y, most_left_x, third_y)

        # Draw the figure and complete it to rectangle with air
        canvas.setPen(self.COL_FIG)
        self.draw_figure_mesh(canvas, form)

        # Fill the figure
        the_figure = QPolygon()
        for vertex in self.vertexes:
            x, y = scale(vertex)
            the_figure.append(QPoint(x, y))
        the_figure.append(the_figure.first())  # close the polygon
        canvas.setPen(self.COL_FIG)
        canvas.setBrush(QBrush(self.COL_FIG_INNNER))  # drawPolygon() use it
        canvas.drawPolygon(the_figure)
    def draw_mesh(self, canvas):
        """
        Divide figure and it's air-rectangles by right triangles
        """
        M = self.mesh
        scale = self.generate_scaler()
        form = self.mesh.data["form"]

        # Draw air surroundings
        canvas.setPen(self.COL_AIR)
        if M.NAT != 0:
            self.draw_rect_mesh(canvas, 0, 0, M.NAL + M.NFX + M.NAR, M.NAT)
        if M.NAB != 0:
            self.draw_rect_mesh(canvas, 0, M.NAT + M.NFY, M.NAL + M.NFX + M.NAR, M.NAB)
        if M.NAL != 0:
            self.draw_rect_mesh(canvas, 0, M.NAT, M.NAL, M.NFY)
        if M.NAR != 0:
            self.draw_rect_mesh(canvas, M.NAL + M.NFX, M.NAT, M.NAR, M.NFY)

        # Draw contour of mirrored air part
        most_left_x, most_left_y = scale(self.vertexes[0])
        most_right_x, most_right_y = scale(self.vertexes[1])
        third_x, third_y = scale(self.vertexes[2])
        if form == 0:
            canvas.drawLine(most_left_x, most_left_y, most_right_x, most_left_y)
            canvas.drawLine(most_right_x, most_right_y, most_right_x, most_left_y)
        elif form == 1:
            canvas.drawLine(most_left_x, most_right_y, most_right_x, most_right_y)
            canvas.drawLine(most_left_x, most_right_y, most_left_x, most_left_y)
        elif form == 2:
            canvas.drawLine(most_left_x, third_y, most_right_x, third_y)
            canvas.drawLine(most_right_x, most_right_y, most_right_x, third_y)
        elif form == 3:
            canvas.drawLine(most_left_x, third_y, most_right_x, third_y)
            canvas.drawLine(most_left_x, most_left_y, most_left_x, third_y)

        # Draw the figure and complete it to rectangle with air
        canvas.setPen(self.COL_FIG)
        self.draw_figure_mesh(canvas, form)

        # Fill the figure
        the_figure = QPolygon()
        for vertex in self.vertexes:
            x, y = scale(vertex)
            the_figure.append(QPoint(x, y))
        the_figure.append(the_figure.first())  # close the polygon
        canvas.setPen(self.COL_FIG)
        canvas.setBrush(QBrush(self.COL_FIG_INNNER))  # drawPolygon() use it
        canvas.drawPolygon(the_figure)