source: sasview/guiframe/local_perspectives/plotting/Edge.py @ 356aea78

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 356aea78 was 356aea78, checked in by Gervaise Alina <gervyh@…>, 16 years ago

working on sector slicer

  • Property mode set to 100644
File size: 4.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        self.move_stop=False
30        self.theta_left=None
31        self.theta_right=None
32        self.arc1= arc1
33        self.arc2=arc2
34        #raise "Version error", message
35        x1= self.r1*math.cos(self.theta)
36        y1= self.r1*math.sin(self.theta)
37        x2= self.r2*math.cos(self.theta)
38        y2= self.r2*math.sin(self.theta)
39        self.line = self.axes.plot([x1,x2],[y1,y2],
40                                      linestyle='-', marker='',
41                                      color=self.color,
42                                      visible=True)[0]
43        self.phi= theta
44        self.npts = 20
45        self.has_move= False
46        self.connect_markers([self.line])
47        self.update()
48       
49       
50    def set_layer(self, n):
51        self.layernum = n
52        self.update()
53       
54    def clear(self):
55        self.clear_markers()
56        try:
57            self.line.remove()
58         
59        except:
60            # Old version of matplotlib
61            for item in range(len(self.axes.lines)):
62                del self.axes.lines[0]
63       
64       
65       
66    def get_radius(self):
67        return self.theta
68       
69    def update(self,r1=None, r2=None, theta_right=None, theta_left=None):
70        """
71        Draw the new roughness on the graph.
72        """
73        self.theta_left=theta_left
74        self.theta_right=theta_right
75        if r1 !=None:
76            self.r1=r1
77        if r2!=None:
78            self.r2=r2
79        if theta_right!=None:
80            if theta_right < self.theta:
81                self.move_stop=True
82            else:
83                self.move_stop=False
84        if theta_left !=None:
85            if theta_left > self.theta:
86                self.move_stop=True
87            else:
88                self.move_stop=False
89        if theta_left ==None and theta_right==None:
90            self.move_stop=True
91        print "in the edge theta_right theta_left",theta_right,theta_left,self.theta
92        x1= self.r1*math.cos(self.theta)
93        y1= self.r1*math.sin(self.theta)
94        x2= self.r2*math.cos(self.theta)
95        y2= self.r2*math.sin(self.theta) 
96             
97        self.line.set(xdata=[x1,x2], ydata=[y1,y2])
98       
99 
100    def save(self, ev):
101        """
102        Remember the roughness for this layer and the next so that we
103        can restore on Esc.
104        """
105        self.save_theta= self.theta
106        self.base.freeze_axes()
107   
108    def moveend(self, ev):
109        self.has_move= False
110        self.base.moveend(ev)
111           
112    def restore(self):
113        """
114        Restore the roughness for this layer.
115        """
116        self.theta = self.save_theta
117
118    def move(self, x, y, ev):
119        """
120        Process move to a new position, making sure that the move is allowed.
121        """
122        #print "on move theta left , theta right",self.theta_left,self.theta_right
123        theta= math.atan2(y,x)
124        print "on move theta left , theta right",self.theta_left,self.theta_right,theta
125        if self.theta_left !=None:
126            if self.theta_left >= theta:
127                print "went hier"
128                self.move_stop= True
129        if self.theta_right !=None:
130            if self.theta_right <= theta:
131                self.move_stop= True
132
133        if self.move_stop:
134            self.theta= math.atan2(y,x)
135            self.has_move= True
136           
137        self.base.base.update()
138       
139    def set_cursor(self, x, y):
140        self.move(x, y, None)
141        self.update()
142       
143       
144    def get_params(self):
145        params = {}
146        params["radius1"] = self.r1
147        params["radius2"] = self.r2
148        return params
149   
150    def set_params(self, params):
151
152        x1 = params["radius1"] 
153        x2 = params["radius2"] 
154        self.set_cursor(x, self._inner_mouse_y)
155       
156   
Note: See TracBrowser for help on using the repository browser.