Example #1
0
 def read_plot(self, X, Y):
     if X * X + Y * Y > 1.:
         return ""
     x, y, z = self.inverse(X, Y)
     if self.settings.check_settings["rotate"]:
         x, y, z = self.Ri.dot((x, y, z))
     theta, phi = sphere(x, y, z)
     if phi >= 0.:
         return "Pole: %05.1f/%04.1f\nLine: %05.1f/%04.1f" %\
             (theta, phi, (theta - 180) % 360., 90. - phi)
     else:
         return ""
Example #2
0
    def measure_motion(self, event):
        if self.measure_from is None:
            return
        if event.inaxes != self.plotaxes:
            return
        a = np.array(self.projection.inverse(*self.measure_from))
        x, y = event.xdata, event.ydata
        if x * x + y * y > 1: return
        b = np.array(self.projection.inverse(event.xdata, event.ydata))
        theta = acos(np.dot(a, b))
        theta_range = np.arange(0, theta, radians(1))
        sin_range = np.sin(theta_range)
        cos_range = np.cos(theta_range)
        x, y = self.projection.project_data(*great_circle_arc(a, b),\
                                            rotate=False)
        c = np.cross(a, b)
        c /= np.linalg.norm(c)
        c = c if c[2] < 0. else -c
        full_gc = self.projection.project_data(*great_circle_simple(c, pi).T,\
                                            rotate=False)
        c_ = self.projection.project_data(*c, rotate=False)

        from_ = self.projection.project_data(*great_circle_arc(a, c),\
                                            rotate=False)
        to_   = self.projection.project_data(*great_circle_arc(b, c),\
                                            rotate=False)

        if self.projection.settings.check_settings["rotate"]:
            c = self.projection.Ri.dot(c)
        c_sphere = sphere(*c)

        if self.measure_line is None:  #make configurable
            self.measure_line, = self.plotaxes.plot(x, y,\
                **self.settings.mLine_settings)
            self.measure_line.set_clip_path(self.circle)
            if self.settings.check_settings['measurelinegc']:
                self.measure_gc,   = self.plotaxes.plot(*full_gc,\
                    **self.settings.mGC_settings)
                self.from_line,   = self.plotaxes.plot(\
                    *from_, **self.settings.mGC_settings)
                self.to_line,   = self.plotaxes.plot(\
                    *to_, **self.settings.mGC_settings)
                self.measure_gc.set_clip_path(self.circle)
                self.from_line.set_clip_path(self.circle)
                self.to_line.set_clip_path(self.circle)
        else:
            self.measure_line.set_data(x, y)
            if self.settings.check_settings['measurelinegc']:
                self.measure_gc.set_data(*full_gc)
                self.from_line.set_data(*from_)
                self.to_line.set_data(*to_)

        self.plot_toolbar.set_message("Angle: %3.2f\nPlane: %05.1f/%04.1f"\
            % (degrees(theta), c_sphere[0], c_sphere[1]))
        self.plot_canvas.restore_region(self.background)
        if self.settings.check_settings['measurelinegc']:
            self.plotaxes.draw_artist(self.measure_gc)
            self.plotaxes.draw_artist(self.from_line)
            self.plotaxes.draw_artist(self.to_line)
        self.plotaxes.draw_artist(self.measure_line)
        self.plot_canvas.blit(self.plotaxes.bbox)
Example #3
0
    def measure_motion(self, event):
        if self.measure_from is None:
            return
        if event.inaxes != self.plotaxes:
            return
        a = self.last_from_measure
        x, y = event.xdata, event.ydata
        if x * x + y * y > 1:
            return
        b = au.Vector(self.projection.inverse(event.xdata, event.ydata))
        self.last_to_measure = b
        theta = acos(np.dot(a, b))
        theta_range = np.arange(0, theta, radians(1))
        sin_range = np.sin(theta_range)
        cos_range = np.cos(theta_range)
        x, y = self.projection.project_data(
            *great_circle_arc(a, b), rotate=False
        )
        c = np.cross(a, b)
        c /= np.linalg.norm(c)

        au_c = au.Vector(c)

        c = c if c[2] < 0.0 else -c
        full_gc = self.projection.project_data(
            *great_circle_simple(c, pi).T, rotate=False
        )
        if self.button_pressed == 3:
            self.last_center = a
            self.last_theta = theta
            full_sc = self.projection.project_data(
                *a.get_small_circle(theta)[0].T,
                rotate=False,
                invert_positive=False
            )
        else:
            ab = (a + b) / 2
            ab /= ab.length
            self.last_center = ab
            self.last_theta = theta / 2
            full_sc = self.projection.project_data(
                *ab.get_small_circle(theta / 2)[0].T,
                rotate=False,
                invert_positive=False
            )

        c_ = self.projection.project_data(*c, rotate=False)

        from_ = self.projection.project_data(
            *great_circle_arc(a, c), rotate=False
        )
        to_ = self.projection.project_data(
            *great_circle_arc(b, c), rotate=False
        )

        if self.projection.settings.check_settings["rotate"]:
            c = self.projection.Ri.dot(c)
            au_c = au_c.dot(self.last_rotation.T).dot(self.projection.Ri.T)
        c_sphere = sphere(*c)

        if self.drag_rotate_mode:
            if event.name == "scroll_event":
                # https://stackoverflow.com/q/49316067/1457481
                self.scroll_rotation += (
                    5 * event.step
                    if QtWidgets.QApplication.keyboardModifiers()
                    == QtCore.Qt.ControlModifier
                    else event.step
                )
            rotation_matrix = self.last_rotation.dot(
                au_c.get_rotation_matrix(-theta)
            ) if self.button_pressed == 1 else self.last_rotation
            if self.button_pressed == 1:
                rotation_matrix = rotation_matrix.dot(
                    b.get_rotation_matrix(radians(self.scroll_rotation))
                )
            else:
                rotation_matrix = rotation_matrix.dot(
                    a.get_rotation_matrix(radians(self.scroll_rotation))
                )
            self.current_rotation = rotation_matrix
            for point, element in self.point_elements:
                Xp, Yp = self.project(*(point.dot(rotation_matrix)).T)
                element.set_data(Xp, Yp)

            for circles, element in self.circle_elements:
                projected_circles = [
                    np.transpose(
                        self.project(
                            *(circle.dot(rotation_matrix)).T,
                            invert_positive=False
                        )
                    )
                    for circle in circles
                ]
                element.set_segments(projected_circles)

        if self.measure_line is None:  # make configurable
            self.measure_line, = self.plotaxes.plot(
                x, y, **self.settings.mLine_settings
            )
            self.measure_line.set_clip_path(self.circle)
            if self.button_pressed in (2, 3):
                self.measure_sc, = self.plotaxes.plot(
                    *full_sc, **self.settings.mLine_settings
                )
                self.measure_sc.set_clip_path(self.circle)
            if self.settings.check_settings["measurelinegc"]:
                self.measure_gc, = self.plotaxes.plot(
                    *full_gc, **self.settings.mGC_settings
                )
                self.from_line, = self.plotaxes.plot(
                    *from_, **self.settings.mGC_settings
                )
                self.to_line, = self.plotaxes.plot(
                    *to_, **self.settings.mGC_settings
                )
                self.measure_gc.set_clip_path(self.circle)
                self.from_line.set_clip_path(self.circle)
                self.to_line.set_clip_path(self.circle)
        else:
            self.measure_line.set_data(x, y)
            if self.button_pressed in (2, 3):
                self.measure_sc.set_data(*full_sc)
            if self.settings.check_settings["measurelinegc"]:
                self.measure_gc.set_data(*full_gc)
                self.from_line.set_data(*from_)
                self.to_line.set_data(*to_)

        if self.button_pressed in (2, 3):
            self.plot_toolbar.set_message(
                "Angle: {:3.2f}\nAxis: {:05.1f}/{:04.1f}".format(
                    degrees(self.last_theta), *self.last_center.attitude
                )
            )
        else:
            self.plot_toolbar.set_message(
                "Angle: {:3.2f}\nLine: {:05.1f}/{:04.1f} Plane: {:05.1f}/{:04.1f}".format(
                    degrees(theta),
                    (c_sphere[0] - 180) % 360,
                    90 - c_sphere[1],
                    c_sphere[0],
                    c_sphere[1],
                )
            )
        self.plot_canvas.restore_region(self.background)
        if self.settings.check_settings["measurelinegc"]:
            self.plotaxes.draw_artist(self.measure_gc)
            if self.button_pressed in (2, 3):
                self.plotaxes.draw_artist(self.measure_sc)
            else:
                self.plotaxes.draw_artist(self.from_line)
                self.plotaxes.draw_artist(self.to_line)
        self.plotaxes.draw_artist(self.measure_line)
        # experimental
        if self.drag_rotate_mode:
            for point, element in self.point_elements:
                self.plotaxes.draw_artist(element)
            for circles, element in self.circle_elements:
                self.plotaxes.draw_artist(element)
        self.plot_canvas.blit(self.plotaxes.bbox)