Merged Rolf Schmidt's illysam branch
[hooke.git] / hooke / ui / gui / clickedpoint.py
1 #!/usr/bin/env python\r
2 \r
3 '''\r
4 clickedpoint.py\r
5 \r
6 ClickedPoint class for Hooke.\r
7 \r
8 Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)\r
9 \r
10 This program is released under the GNU General Public License version 2.\r
11 '''\r
12 \r
13 from scipy import arange\r
14 \r
15 class ClickedPoint(object):\r
16     '''\r
17     This class defines what a clicked point on the curve plot is.\r
18     '''\r
19     def __init__(self):\r
20 \r
21         self.is_marker = None #boolean ; decides if it is a marker\r
22         self.is_line_edge = None #boolean ; decides if it is the edge of a line (unused)\r
23         self.absolute_coords = (None, None) #(float,float) ; the absolute coordinates of the clicked point on the graph\r
24         self.graph_coords = (None, None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point\r
25         self.index = None #integer ; the index of the clicked point with respect to the vector selected\r
26         self.dest = None #0 or 1 ; 0=top plot 1=bottom plot\r
27 \r
28     def find_graph_coords(self, xvector, yvector):\r
29         '''\r
30         Given a clicked point on the plot, finds the nearest point in the dataset (in X) that\r
31         corresponds to the clicked point.\r
32         '''\r
33         dists = []\r
34         for index in arange(1, len(xvector), 1):\r
35             dists.append(((self.absolute_coords[0] - xvector[index]) ** 2)+((self.absolute_coords[1] - yvector[index]) ** 2))\r
36 \r
37         self.index=dists.index(min(dists))\r
38         self.graph_coords=(xvector[self.index], yvector[self.index])\r