#
# $Id: Plotter.py,v 1.1.1.1 2003/03/22 05:15:48 dbelan2 Exp $
#
# Front end to plot.py
# GUI access plot methods of this class.
# Owner of plot window.
#
# $Log: Plotter.py,v $
# Revision 1.1.1.1  2003/03/22 05:15:48  dbelan2
# Initial import of all public_html on www.cs.mcgill.ca.
#
# Revision 1.8  2001/10/01 20:44:03  dbelan2
# Bug fix: lines list emptied when plot clear.
#
# Revision 1.7  2001/10/01 16:11:26  dbelan2
# Move some Plotter functionnality to gui module.
#
# Revision 1.6  2001/10/01 15:58:31  dbelan2
# Bug fix: plot now uses a copy of points.
#
# Revision 1.5  2001/09/29 21:46:37  dbelan2
# Made plot square.
#
# Revision 1.4  2001/09/28 15:21:32  dbelan2
# Added colour switching.  Each new plot is done
# in a different colour.
#
# Revision 1.3  2001/09/28 03:02:56  dbelan2
# Plots several lines on same graph.
#
# Revision 1.2  2001/09/28 02:52:39  dbelan2
# Plot from file working.
#
# Revision 1.1  2001/09/26 20:30:55  dbelan2
# Added GUI files.
#
#
#
#

from plot import *

class Plotter:

    def __init__(self):

        self.root = Tk()   # plot window
        #self.graphLines = []    # all lines on plot
        self.lines = []
        
        #    di = 5.*pi/5.
        #    data = []
        #    for i in range(18):
        #        data.append((float(i)*di,
        #(math.sin(float(i)*di)-math.cos(float(i)*di))))
        #    line  = GraphLine(data, color='gray', smooth=0)
        #    linea = GraphLine(data, color='blue', smooth=1, splinesteps=500)
        #
        #    graphObject = GraphObjects([line, linea])
        #
        self.graph  = GraphBase(self.root, 500, 500, relief=SUNKEN, border=2)
        self.graph.pack(side=TOP, fill=BOTH, expand=YES)
        #
        #    graph.draw(graphObject, 'automatic', 'automatic')
        #
        #    Button(root, text='Clear',  command=graph.clear).pack(side=LEFT)
        #    Button(root, text='Redraw', command=graph.replot).pack(side=LEFT)
        #    Button(root, text='Quit',   command=root.quit).pack(side=RIGHT)
        #
        #    root.mainloop()


        # colours available for plot
        self.colours = ['red', 'blue', 'orange', 'green', 'gray']
        self.nextcolour = 0  # next colour to use for plot


    # line is a list of points
    # need to add code to let user specify smoothness
    def plot(self, data1):

        data = data1[:]  # make a copy



  
        line  = GraphLine(data, color=self.colours[self.nextcolour], smooth=0)
        self.nextcolour = (self.nextcolour + 1) % len(self.colours)
        #linea = GraphLine(data, color='blue', smooth=1, splinesteps=500)

        self.lines.append(line)
        self.graph.clear()
        graphObject = GraphObjects(self.lines)

#        self.graph  = GraphBase(self.root, 500, 400, relief=SUNKEN, border=2)
#        self.graph.pack(side=TOP, fill=BOTH, expand=YES)

        self.graph.draw(graphObject, 'automatic', 'automatic')

        #Button(root, text='Clear',  command=graph.clear).pack(side=LEFT)
        #Button(root, text='Redraw', command=graph.replot).pack(side=LEFT)
        #Button(root, text='Quit',   command=root.quit).pack(side=RIGHT)

        #root.mainloop()





##         graphLine = GraphLine(data, color='blue', smooth=0)
##         #self.graphLines.append(graphLine)
##         graphObject = GraphObjects(graphLine)
##         self.graph.draw(graphObject, 'automatic', 'automatic')
                        




    def clear(self):
        self.graph.clear()
        self.lines = []
        


    def closePlot(self):
        pass
        

    






