From 0b378ead3fd5bd512a09c0c69cdabdf478896e40 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 3 Aug 2010 06:51:55 -0400 Subject: [PATCH] Consolidated point-handling modules in hooke.ui.gui into gui.dialog.points --- hooke/ui/gui/clickedpoint.py | 38 -------- hooke/ui/gui/dialog/points.py | 33 ++++++- hooke/ui/gui/plotcommands.py | 179 ---------------------------------- hooke/ui/gui/point_request.py | 68 ------------- 4 files changed, 32 insertions(+), 286 deletions(-) delete mode 100644 hooke/ui/gui/clickedpoint.py delete mode 100644 hooke/ui/gui/plotcommands.py delete mode 100644 hooke/ui/gui/point_request.py diff --git a/hooke/ui/gui/clickedpoint.py b/hooke/ui/gui/clickedpoint.py deleted file mode 100644 index 35c244c..0000000 --- a/hooke/ui/gui/clickedpoint.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -''' -clickedpoint.py - -ClickedPoint class for Hooke. - -Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada) - -This program is released under the GNU General Public License version 2. -''' - -from scipy import arange - -class ClickedPoint(object): - ''' - This class defines what a clicked point on the curve plot is. - ''' - def __init__(self): - - self.is_marker = None #boolean ; decides if it is a marker - self.is_line_edge = None #boolean ; decides if it is the edge of a line (unused) - self.absolute_coords = (None, None) #(float,float) ; the absolute coordinates of the clicked point on the graph - self.graph_coords = (None, None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point - self.index = None #integer ; the index of the clicked point with respect to the vector selected - self.dest = None #0 or 1 ; 0=top plot 1=bottom plot - - def find_graph_coords(self, xvector, yvector): - ''' - Given a clicked point on the plot, finds the nearest point in the dataset (in X) that - corresponds to the clicked point. - ''' - dists = [] - for index in arange(1, len(xvector), 1): - dists.append(((self.absolute_coords[0] - xvector[index]) ** 2)+((self.absolute_coords[1] - yvector[index]) ** 2)) - - self.index=dists.index(min(dists)) - self.graph_coords=(xvector[self.index], yvector[self.index]) diff --git a/hooke/ui/gui/dialog/points.py b/hooke/ui/gui/dialog/points.py index 65ea3aa..e4d3652 100644 --- a/hooke/ui/gui/dialog/points.py +++ b/hooke/ui/gui/dialog/points.py @@ -1,4 +1,7 @@ -# Copyright (C) 2010 W. Trevor King +# Copyright (C) 2008-2010 Alberto Gomez-Casado +# Fabrizio Benedetti +# Massimo Sandal +# W. Trevor King # # This file is part of Hooke. # @@ -16,9 +19,37 @@ # License along with Hooke. If not, see # . +from numpy import arange + import wx +class ClickedPoint(object): + """Defines a clicked point from a curve plot. + """ + def __init__(self): + + self.is_marker=None #boolean ; decides if it is a marker + self.is_line_edge=None #boolean ; decides if it is the edge of a line (unused) + self.absolute_coords=(None,None) #(float,float) ; the absolute coordinates of the clicked point on the graph + self.graph_coords=(None,None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point + self.index=None #integer ; the index of the clicked point with respect to the vector selected + self.dest=None #0 or 1 ; 0=top plot 1=bottom plot + + def find_graph_coords(self,xvector,yvector): + """Find the point in the dataset that is closest to `self`. + + Given a clicked point on the plot, finds the nearest point in + the dataset (in X) that corresponds to the clicked point. + """ + dists=[] + for index in arange(1,len(xvector),1): + dists.append(((self.absolute_coords[0]-xvector[index])**2)+((self.absolute_coords[1]-yvector[index])**2)) + + self.index=dists.index(min(dists)) + self.graph_coords=(xvector[self.index],yvector[self.index]) + + def measure_N_points(hooke_frame, N, message='', block=0): ''' General helper function for N-points measurements diff --git a/hooke/ui/gui/plotcommands.py b/hooke/ui/gui/plotcommands.py deleted file mode 100644 index ae17f2e..0000000 --- a/hooke/ui/gui/plotcommands.py +++ /dev/null @@ -1,179 +0,0 @@ -# Copyright (C) 2010 W. Trevor King -# -# This file is part of Hooke. -# -# Hooke is free software: you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Hooke is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General -# Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with Hooke. If not, see -# . - -#PLOT INTERACTION COMMANDS -#------------------------------- - def help_plot(self): - print ''' -PLOT -Plots the current force curve -------- -Syntax: plot - ''' - def do_plot(self,args): - if self.current.identify(self.drivers) == False: - return - self.plots=self.current.curve.default_plots() - try: - self.plots=self.current.curve.default_plots() - except Exception, e: - print 'Unexpected error occurred in do_plot().' - print e - return - - #apply the plotmanip functions eventually present - nplots=len(self.plots) - c=0 - while c -# W. Trevor King -# -# This file is part of Hooke. -# -# Hooke is free software: you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Hooke is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General -# Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with Hooke. If not, see -# . - -class ClickedPoint(object): - ''' - this class defines what a clicked point on the curve plot is - ''' - def __init__(self): - - self.is_marker=None #boolean ; decides if it is a marker - self.is_line_edge=None #boolean ; decides if it is the edge of a line (unused) - self.absolute_coords=(None,None) #(float,float) ; the absolute coordinates of the clicked point on the graph - self.graph_coords=(None,None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point - self.index=None #integer ; the index of the clicked point with respect to the vector selected - self.dest=None #0 or 1 ; 0=top plot 1=bottom plot - - - def find_graph_coords_old(self, xvector, yvector): - ''' - Given a clicked point on the plot, finds the nearest point in the dataset (in X) that - corresponds to the clicked point. - OLD & DEPRECATED - to be removed - ''' - - #FIXME: a general algorithm using min() is needed! - best_index=0 - best_dist=10**9 #should be more than enough given the scale - - for index in scipy.arange(1,len(xvector),1): - dist=((self.absolute_coords[0]-xvector[index])**2)+(100*((self.absolute_coords[1]-yvector[index])))**2 - #TODO, generalize? y coordinate is multiplied by 100 due to scale differences in the plot - if dist