1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke. If not, see
17 # <http://www.gnu.org/licenses/>.
19 #PLOT INTERACTION COMMANDS
20 #-------------------------------
24 Plots the current force curve
28 def do_plot(self,args):
29 if self.current.identify(self.drivers) == False:
31 self.plots=self.current.curve.default_plots()
33 self.plots=self.current.curve.default_plots()
35 print 'Unexpected error occurred in do_plot().'
39 #apply the plotmanip functions eventually present
40 nplots=len(self.plots)
43 for function in self.plotmanip: #FIXME: something strange happens about self.plotmanip[0]
44 self.plots[c]=function(self.plots[c], self.current)
46 self.plots[c].xaxes=self.config['xaxes'] #FIXME: in the future, xaxes and yaxes should be set per-plot
47 self.plots[c].yaxes=self.config['yaxes']
51 self._send_plot(self.plots)
53 def _delta(self, set=1):
55 calculates the difference between two clicked points
57 print 'Click two points'
58 points=self._measure_N_points(N=2, whatset=set)
59 dx=abs(points[0].graph_coords[0]-points[1].graph_coords[0])
60 dy=abs(points[0].graph_coords[1]-points[1].graph_coords[1])
61 unitx=self.plots[points[0].dest].units[0]
62 unity=self.plots[points[0].dest].units[1]
63 return dx,unitx,dy,unity
65 def do_delta(self,args):
69 Measures the delta X and delta Y between two points.
73 dx,unitx,dy,unity=self._delta()
74 print str(dx)+' '+unitx
75 print str(dy)+' '+unity
77 def _point(self, set=1):
78 '''calculates the coordinates of a single clicked point'''
80 print 'Click one point'
81 point=self._measure_N_points(N=1, whatset=set)
83 x=point[0].graph_coords[0]
84 y=point[0].graph_coords[1]
85 unitx=self.plots[point[0].dest].units[0]
86 unity=self.plots[point[0].dest].units[1]
87 return x,unitx,y,unity
89 def do_point(self,args):
93 Returns the coordinates of a point on the graph.
97 x,unitx,y,unity=self._point()
98 print str(x)+' '+unitx
99 print str(y)+' '+unity
100 to_dump='point '+self.current.path+' '+str(x)+' '+unitx+', '+str(y)+' '+unity
101 self.outlet.push(to_dump)
104 def do_close(self,args=None):
107 Closes one of the two plots. If no arguments are given, the bottom plot is closed.
109 Syntax: close [top,bottom]
118 close_plot=self.list_of_events['close_plot']
119 wx.PostEvent(self.frame, close_plot(to_close=to_close))
121 def do_show(self,args=None):
126 show_plots=self.list_of_events['show_plots']
127 wx.PostEvent(self.frame, show_plots())
130 #Everything sending an event should be here
131 def _measure_N_points(self, N, whatset=1):
133 general helper function for N-points measures
135 wx.PostEvent(self.frame,self.list_of_events['measure_points'](num_of_points=N, set=whatset))
138 points=self.frame.events_from_gui.get()
144 def _get_displayed_plot(self,dest=0):
146 returns the currently displayed plot.
148 wx.PostEvent(self.frame, self.list_of_events['get_displayed_plot'](dest=dest))
151 displayed_plot=self.events_from_gui.get()
156 return displayed_plot
158 def _send_plot(self,plots):
160 sends a plot to the GUI
162 wx.PostEvent(self.frame, self.list_of_events['plot_graph'](plots=plots))
165 def _find_plotmanip(self, name):
167 returns a plot manipulator function from its name
169 return self.plotmanip[self.config['plotmanips'].index(name)]
171 def _clickize(self, xvector, yvector, index):
173 returns a ClickedPoint() object from an index and vectors of x, y coordinates
177 point.absolute_coords=xvector[index],yvector[index]
178 point.find_graph_coords(xvector,yvector)