source: sasview/guiframe/local_perspectives/plotting/Edge.py @ 2d107b8

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.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 2d107b8 was 2d107b8, checked in by Gervaise Alina <gervyh@…>, 16 years ago

small changes circular averaging

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