Moved plot commands from hooke_cli -> hooke.ui.gui.plotcommands stub.
[hooke.git] / hooke / ui / gui / plotcommands.py
1 #PLOT INTERACTION COMMANDS
2 #-------------------------------
3     def help_plot(self):
4         print '''
5 PLOT
6 Plots the current force curve
7 -------
8 Syntax: plot
9         '''
10     def do_plot(self,args):
11         if self.current.identify(self.drivers) == False:
12             return
13         self.plots=self.current.curve.default_plots()
14         try:
15             self.plots=self.current.curve.default_plots()
16         except Exception, e:
17             print 'Unexpected error occurred in do_plot().'
18             print e
19             return
20
21         #apply the plotmanip functions eventually present
22         nplots=len(self.plots)
23         c=0
24         while c<nplots:
25             for function in self.plotmanip: #FIXME: something strange happens about self.plotmanip[0]
26                 self.plots[c]=function(self.plots[c], self.current)
27
28             self.plots[c].xaxes=self.config['xaxes'] #FIXME: in the future, xaxes and yaxes should be set per-plot
29             self.plots[c].yaxes=self.config['yaxes']
30
31             c+=1
32
33         self._send_plot(self.plots)
34
35     def _delta(self, set=1):
36         '''
37         calculates the difference between two clicked points
38         '''
39         print 'Click two points'
40         points=self._measure_N_points(N=2, whatset=set)
41         dx=abs(points[0].graph_coords[0]-points[1].graph_coords[0])
42         dy=abs(points[0].graph_coords[1]-points[1].graph_coords[1])
43         unitx=self.plots[points[0].dest].units[0]
44         unity=self.plots[points[0].dest].units[1]
45         return dx,unitx,dy,unity
46
47     def do_delta(self,args):
48         '''
49         DELTA
50
51         Measures the delta X and delta Y between two points.
52         ----
53         Syntax: delta
54         '''
55         dx,unitx,dy,unity=self._delta()
56         print str(dx)+' '+unitx
57         print str(dy)+' '+unity
58
59     def _point(self, set=1):
60         '''calculates the coordinates of a single clicked point'''
61
62         print 'Click one point'
63         point=self._measure_N_points(N=1, whatset=set)
64
65         x=point[0].graph_coords[0]
66         y=point[0].graph_coords[1]
67         unitx=self.plots[point[0].dest].units[0]
68         unity=self.plots[point[0].dest].units[1]
69         return x,unitx,y,unity
70
71     def do_point(self,args):
72         '''
73         POINT
74
75         Returns the coordinates of a point on the graph.
76         ----
77         Syntax: point
78         '''
79         x,unitx,y,unity=self._point()
80         print str(x)+' '+unitx
81         print str(y)+' '+unity
82         to_dump='point '+self.current.path+' '+str(x)+' '+unitx+', '+str(y)+' '+unity
83         self.outlet.push(to_dump)
84
85
86     def do_close(self,args=None):
87         '''
88         CLOSE
89         Closes one of the two plots. If no arguments are given, the bottom plot is closed.
90         ------
91         Syntax: close [top,bottom]
92         '''
93         if args=='top':
94             to_close=0
95         elif args=='bottom':
96             to_close=1
97         else:
98             to_close=1
99
100         close_plot=self.list_of_events['close_plot']
101         wx.PostEvent(self.frame, close_plot(to_close=to_close))
102
103     def do_show(self,args=None):
104         '''
105         SHOW
106         Shows both plots.
107         '''
108         show_plots=self.list_of_events['show_plots']
109         wx.PostEvent(self.frame, show_plots())