source: sasview/src/sas/sasgui/guiframe/local_perspectives/plotting/Edge.py @ 39f0bf4

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 39f0bf4 was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[b06ef8c]1import math
[0d9dae8]2from BaseInteractor import _BaseInteractor
[b5de88e]3
[b06ef8c]4
5class RadiusInteractor(_BaseInteractor):
6    """
[d955bf19]7    Select an annulus through a 2D plot
[b06ef8c]8    """
[32c0841]9    def __init__(self, base, axes, color='black', zorder=5, arc1=None,
[b5de88e]10                 arc2=None, theta=math.pi / 8):
[32c0841]11        """
12        """
[b06ef8c]13        _BaseInteractor.__init__(self, base, axes, color=color)
14        self.markers = []
15        self.axes = axes
16        self.r1 = arc1.get_radius()
17        self.r2 = arc2.get_radius()
[32c0841]18        self.theta = theta
19        self.save_theta = theta
20        self.move_stop = False
21        self.theta_left = None
22        self.theta_right = None
23        self.arc1 = arc1
24        self.arc2 = arc2
25        x1 = self.r1 * math.cos(self.theta)
26        y1 = self.r1 * math.sin(self.theta)
27        x2 = self.r2 * math.cos(self.theta)
28        y2 = self.r2 * math.sin(self.theta)
29        self.line = self.axes.plot([x1, x2], [y1, y2],
[b5de88e]30                                   linestyle='-', marker='',
31                                   color=self.color,
32                                   visible=True)[0]
[32c0841]33        self.phi = theta
[b06ef8c]34        self.npts = 20
[32c0841]35        self.has_move = False
[b06ef8c]36        self.connect_markers([self.line])
37        self.update()
[b5de88e]38
[b06ef8c]39    def set_layer(self, n):
[d955bf19]40        """
41        """
[b06ef8c]42        self.layernum = n
43        self.update()
[b5de88e]44
[b06ef8c]45    def clear(self):
[d955bf19]46        """
47        """
[b06ef8c]48        self.clear_markers()
49        try:
50            self.line.remove()
51        except:
52            # Old version of matplotlib
53            for item in range(len(self.axes.lines)):
54                del self.axes.lines[0]
[b5de88e]55
[e8c96f5]56    def get_angle(self):
[d955bf19]57        """
58        """
[b06ef8c]59        return self.theta
[b5de88e]60
[32c0841]61    def update(self, r1=None, r2=None, theta=None):
[b06ef8c]62        """
63        Draw the new roughness on the graph.
64        """
[d955bf19]65        if r1 != None:
66            self.r1 = r1
67        if r2 != None:
68            self.r2 = r2
[32c0841]69        if theta != None:
70            self.theta = theta
71        x1 = self.r1 * math.cos(self.theta)
72        y1 = self.r1 * math.sin(self.theta)
73        x2 = self.r2 * math.cos(self.theta)
[b5de88e]74        y2 = self.r2 * math.sin(self.theta)
[32c0841]75        self.line.set(xdata=[x1, x2], ydata=[y1, y2])
[b5de88e]76
[b06ef8c]77    def save(self, ev):
78        """
79        Remember the roughness for this layer and the next so that we
80        can restore on Esc.
81        """
[b5de88e]82        self.save_theta = math.atan2(ev.y, ev.x)
[b06ef8c]83        self.base.freeze_axes()
[b5de88e]84
[b06ef8c]85    def moveend(self, ev):
[d955bf19]86        """
87        """
[32c0841]88        self.has_move = False
[b06ef8c]89        self.base.moveend(ev)
[b5de88e]90
[32c0841]91    def restore(self, ev):
[b06ef8c]92        """
93        Restore the roughness for this layer.
94        """
95        self.theta = self.save_theta
96
97    def move(self, x, y, ev):
98        """
99        Process move to a new position, making sure that the move is allowed.
100        """
[32c0841]101        self.theta = math.atan2(y, x)
102        self.has_move = True
[b06ef8c]103        self.base.base.update()
[b5de88e]104
[32c0841]105    def set_cursor(self, r_min, r_max, theta):
[d955bf19]106        """
107        """
[32c0841]108        self.theta = theta
109        self.r1 = r_min
110        self.r2 = r_max
[b06ef8c]111        self.update()
[b5de88e]112
[b06ef8c]113    def get_params(self):
[d955bf19]114        """
115        """
[b06ef8c]116        params = {}
117        params["radius1"] = self.r1
118        params["radius2"] = self.r2
[e8c96f5]119        params["theta"] = self.theta
[b06ef8c]120        return params
[b5de88e]121
[b06ef8c]122    def set_params(self, params):
[d955bf19]123        """
124        """
[b5de88e]125        x1 = params["radius1"]
126        x2 = params["radius2"]
127        theta = params["theta"]
[e8c96f5]128        self.set_cursor(x1, x2, theta)
Note: See TracBrowser for help on using the repository browser.