Ejemplo n.º 1
0
 def _drawAxes(self, canvas, xaxis, yaxis,
               bb1, bb2, scale, shift, xticks, yticks):
     dict = {'anchor': N, 'fill': 'black'}
     if self.font is not None:
         dict['font'] = self.font
     if xaxis is not None:
     #draw x - axis
         lower, upper = xaxis
         text = 1
         once = 1
         for y, d in [(bb1[1], -3), (bb2[1], 3)]:
         #d=.5 of tick - length
             p1 = (scale[0] * lower) + shift[0], (scale[1] * y) + shift[1]
             if once: pp1 = p1
             p2 = (scale[0] * upper) + shift[0], (scale[1] * y) + shift[1]
             if once: pp2 = p2
             once = 0
             Line(self.canvas, p1[0], p1[1], p2[0], p2[1],
                  fill = 'black', width = 1)
             if xticks:
                 for x, label in xticks:
                     p = (scale[0] * x) + shift[0], \
                         (scale[1] * y) + shift[1]
                     Line(self.canvas, p[0], p[1], p[0], p[1] + d,
                          fill = 'black', width = 1)
                     if text:
                         dict['text'] = label
                         CanvasText(self.canvas, p[0],
                                            p[1] + 2, **dict)    ##KGM 14 Aug 03
             text = 0
         #write x - axis title
         CanvasText(self.canvas,(pp2[0] - pp1[0]) / 2.+pp1[0],pp1[1] + 22, text = self.xtitle)
     #write graph title
     CanvasText(self.canvas,(pp2[0] - pp1[0]) / 2.+pp1[0],7, text = self.title)
     dict['anchor'] = E
     if yaxis is not None:
         #draw y - axis
         lower, upper = yaxis
         text = 1
         once = 1
         for x, d in [(bb1[0], -3), (bb2[0], 3)]:
             p1 = (scale[0] * x) + shift[0], (scale[1] * lower) + shift[1]
             p2 = (scale[0] * x) + shift[0], (scale[1] * upper) + shift[1]
             if once: pp1 = p1 ;pp2 = p2
             once = 0
             Line(self.canvas, p1[0], p1[1], p2[0], p2[1],
                  fill = 'black', width = 1)
             if yticks:
                 for y, label in yticks:
                     p = (scale[0] * x) + shift[0], \
                         (scale[1] * y) + shift[1]
                     Line(self.canvas, p[0], p[1], p[0] - d, p[1],
                          fill = 'black', width = 1)
                     if text:
                         dict['text'] = label
                         CanvasText(self.canvas,
                                           p[0] - 4, p[1] + 2, **dict)
             text = 0
         #write y - axis title
         CanvasText(self.canvas, pp2[0],pp2[1] - 10, text = self.ytitle)
Ejemplo n.º 2
0
    def _drawAxes(self, canvas, xaxis, yaxis, bb1, bb2, scale, shift, xticks,
                  yticks):
        dict = {'anchor': Tkinter.N, 'fill': 'black'}
        if self.font is not None:
            dict['font'] = self.font
        if xaxis is not None:
            lower, upper = xaxis
            text = 1
            for y, d in [(bb1[1], -3), (bb2[1], 3)]:
                p1 = scale * Numeric.array([lower, y]) + shift
                p2 = scale * Numeric.array([upper, y]) + shift
                Line(self.canvas,
                     p1[0],
                     p1[1],
                     p2[0],
                     p2[1],
                     fill='black',
                     width=1)
                for x, label in xticks:
                    p = scale * Numeric.array([x, y]) + shift
                    Line(self.canvas,
                         p[0],
                         p[1],
                         p[0],
                         p[1] + d,
                         fill='black',
                         width=1)
                    if text:
                        dict['text'] = label
                        apply(CanvasText, (self.canvas, p[0], p[1]), dict)
                text = 0

        dict['anchor'] = Tkinter.E
        if yaxis is not None:
            lower, upper = yaxis
            text = 1
            for x, d in [(bb1[0], -3), (bb2[0], 3)]:
                p1 = scale * Numeric.array([x, lower]) + shift
                p2 = scale * Numeric.array([x, upper]) + shift
                Line(self.canvas,
                     p1[0],
                     p1[1],
                     p2[0],
                     p2[1],
                     fill='black',
                     width=1)
                for y, label in yticks:
                    p = scale * Numeric.array([x, y]) + shift
                    Line(self.canvas,
                         p[0],
                         p[1],
                         p[0] - d,
                         p[1],
                         fill='black',
                         width=1)
                    if text:
                        dict['text'] = label
                        apply(CanvasText, (self.canvas, p[0], p[1]), dict)
                text = 0
Ejemplo n.º 3
0
    def draw(self, graphics):
        """Draws the graphics object |graphics|, which can be
        a PolyLine3D or a VisualizationGraphics object."""
	self.last_draw = (graphics, )
	self.configure(cursor='watch')
	self.update_idletasks()
        graphics.project(self.axis, self.plane)
	p1, p2 = graphics.boundingBoxPlane()
        center = 0.5*(p1+p2)
	scale = self.plotbox_size / (p2-p1)
        sign = scale/Numeric.fabs(scale)
        if self.scale is None:
            minscale = Numeric.minimum.reduce(Numeric.fabs(scale))
            self.scale = 0.9*minscale
        scale = sign*self.scale
        box_center = self.plotbox_origin + 0.5*self.plotbox_size
	shift = -center*scale + box_center + self.translate
	graphics.scaleAndShift(scale, shift)
	items, depths = graphics.lines()
        sort = Numeric.argsort(depths)
        for index in sort:
            x1, y1, x2, y2, color, width = items[index]
            Line(self.canvas, x1, y1, x2, y2, fill=color, width=width)
	self.configure(cursor='top_left_arrow')
	self.update_idletasks()
Ejemplo n.º 4
0
    def plot_cut_cor(self, Canvas=None, length=20):
        start, start_ang = self.get_st_en_points(0)

        #BaseEntitie erstellen um auf oberster Ebene zu Fräsen
        BaseEntitie = EntitieContentClass(Nr=-1,
                                          Name='BaseEntitie',
                                          parent=None,
                                          children=[],
                                          p0=PointClass(x=0.0, y=0.0),
                                          pb=PointClass(x=0.0, y=0.0),
                                          sca=[1, 1, 1],
                                          rot=0.0)

        x_ca, y_ca = Canvas.get_can_coordinates(start.x, start.y)

        if self.cut_cor == 41:
            start_ang = start_ang + 90
        else:
            start_ang = start_ang - 90

        dx = cos(radians(start_ang)) * length
        dy = sin(radians(start_ang)) * length

        hdl = Line(Canvas.canvas,
                   x_ca,
                   -y_ca,
                   x_ca + dx,
                   -y_ca - dy,
                   fill='SteelBlue3',
                   arrow='last')
        return hdl
Ejemplo n.º 5
0
    def plot2can(self, canvas=None, parent=None, tag=None, col='black'):

        anf = self.Pa.rot_sca_abs(parent=parent)
        ende = self.Pe.rot_sca_abs(parent=parent)

        hdl = Line(canvas, anf.x, -anf.y, ende.x, -ende.y, tag=tag, fill=col)
        return [hdl]
Ejemplo n.º 6
0
    def plot2can(self, canvas=None, parent=None, tag=None, col='black'):

        x = []
        y = []
        hdl = []
        #Alle 10 Grad ein Segment => 120 Segmente für einen Kreis !!
        segments = int((abs(degrees(self.ext)) // 10) + 1)

        for i in range(segments + 1):

            ang = self.s_ang + i * self.ext / segments
            p_cur=PointClass(x=(self.O.x+cos(ang)*abs(self.r)),\
                       y=(self.O.y+sin(ang)*abs(self.r)))

            p_cur_rot = p_cur.rot_sca_abs(parent=parent)

            x.append(p_cur_rot.x)
            y.append(p_cur_rot.y)

            if i >= 1:
                hdl.append(
                    Line(canvas,
                         x[i - 1],
                         -y[i - 1],
                         x[i],
                         -y[i],
                         tag=tag,
                         fill=col))

        return hdl
Ejemplo n.º 7
0
    def _drawAxes(self, canvas, xaxis, yaxis,
                  bb1, bb2, scale, shift, xticks, yticks):
        dict = {'anchor': N, 'fill': 'black'}
        if self.font is not None:
            dict['font'] = self.font
        if xaxis is not None:
            lower, upper = xaxis
            text = 1
            for y, d in [(bb1[1], -3), (bb2[1], 3)]:
                p1 = (scale[0]*lower)+shift[0], (scale[1]*y)+shift[1]
                p2 = (scale[0]*upper)+shift[0], (scale[1]*y)+shift[1]
                Line(self.canvas, p1[0], p1[1], p2[0], p2[1],
                         fill = 'black', width = 1)
                if xticks:
                    for x, label in xticks:
                        p = (scale[0]*x)+shift[0], \
                            (scale[1]*y)+shift[1]
                        Line(self.canvas, p[0], p[1], p[0], p[1]+d,
                             fill = 'black', width = 1)
                        if text:
                            dict['text'] = label
                            apply(CanvasText, (self.canvas, p[0],
                                               p[1]), dict)
            text = 0

        dict['anchor'] = E
        if yaxis is not None:
            lower, upper = yaxis
            text = 1
            for x, d in [(bb1[0], -3), (bb2[0], 3)]:
                p1 = (scale[0]*x)+shift[0], (scale[1]*lower)+shift[1]
                p2 = (scale[0]*x)+shift[0], (scale[1]*upper)+shift[1]
                Line(self.canvas, p1[0], p1[1], p2[0], p2[1],
                             fill = 'black', width = 1)
                if yticks:
                    for y, label in yticks:
                        p = (scale[0]*x)+shift[0], \
                            (scale[1]*y)+shift[1]
                        Line(self.canvas, p[0], p[1], p[0]-d, p[1],
                             fill = 'black', width = 1)
                        if text:
                            dict['text'] = label
                            apply(CanvasText, (self.canvas,
                                               p[0]-2, p[1]), dict)
            text = 0
Ejemplo n.º 8
0
 def xTicks(xMin,xMax,Ax,Bx):
     # Plot ticks and labels for x-axis
     dx = tickSpace(xMin,xMax,px)
     yp = topMargin + height
     if xMin < 0.0: 
         x = 0.0
         while x >= xMin:
             if x <= xMax:
                 xp = Ax + Bx*x    
                 Line(cv,xp,yp,xp,yp - 8)
                 label = str(round(x,4))
                 CanvasText(cv,xp,yp+20,text=label)
             x = x - dx    
     if xMax > 0.0:
         x = 0.0
         while x <= xMax:
             if x >= xMin:
                 xp = Ax + Bx*x             
                 Line(cv,xp,yp,xp,yp - 8)
                 label = str(round(x,4))
                 CanvasText(cv,xp,yp+20,text=label)
             x = x + dx
Ejemplo n.º 9
0
 def yTicks(yMin,yMax,Ay,By):
     # Plot ticks and labels for y-axis
     dy = tickSpace(yMin,yMax,py)
     xp = leftMargin
     if yMin < 0.0: 
         y = 0.0
         while y >= yMin:
             if y <= yMax:
                 yp = Ay + By*y
                 Line(cv,xp,yp,xp+8,yp)
                 label = str(round(y,4))
                 xxp = xp-10-len(label)*3
                 CanvasText(cv,xxp,yp,text=label)
             y = y - dy 
     if yMax > 0.0:
         y = 0.0
         while y <= yMax:
             if y >= yMin:
                 yp = Ay + By*y
                 Line(cv,xp,yp,xp+8,yp)
                 label = str(round(y,4))
                 xxp = xp-10-len(label)*3
                 CanvasText(cv,xxp,yp,text=label)
             y = y + dy
Ejemplo n.º 10
0
    def plot_end(self, Canvas=None, length=20):
        ende, en_angle = self.get_st_en_points(1)

        dx = cos(radians(en_angle)) * length
        dy = sin(radians(en_angle)) * length

        x_ca, y_ca = Canvas.get_can_coordinates(ende.x, ende.y)

        hdl = Line(Canvas.canvas,
                   x_ca,
                   -y_ca,
                   x_ca + dx,
                   -y_ca - dy,
                   fill='PaleGreen2',
                   arrow='first')
        return hdl
Ejemplo n.º 11
0
 def draw(self, canvas):
     color  = self.attributes['color']
     width  = self.attributes['width']
     smooth = self.attributes['smooth']
     steps  = self.attributes['splinesteps']
     arguments = (canvas,)
     if smooth:
         for i in range(len(self.points)):
             x1, y1 = self.scaled[i]
             arguments = arguments + (x1, y1)
     else:
         for i in range(len(self.points) - 1):
             x1, y1 = self.scaled[i]
             x2, y2 = self.scaled[i + 1]
             arguments = arguments + (x1, y1, x2, y2)
     Line(*arguments, **{'fill': color, 'width': width,
                             'smooth': smooth, 'splinesteps':steps})
Ejemplo n.º 12
0
    def plot_end(self, CanvasClass):
        en_point, en_angle = self.geos[-1].get_start_end_points(1)
        ende = (en_point * self.sca) + self.p0

        x_ca, y_ca = CanvasClass.get_can_coordinates(ende.x, ende.y)
        length = 20
        dx = cos(radians(en_angle)) * length
        dy = sin(radians(en_angle)) * length

        hdl = Line(CanvasClass.canvas,
                   x_ca,
                   -y_ca,
                   x_ca + dx,
                   -y_ca - dy,
                   fill='PaleGreen2',
                   arrow='first')
        return hdl
Ejemplo n.º 13
0
 def plotting(xData,yData,symb,Ax,Bx,Ay,By):
     # Plots the data
     global cv
     for i in range(len(xData)-1):
         x1 = round(Ax + Bx*xData[i])
         y1 = round(Ay + By*yData[i])
         x2 = round(Ax + Bx*xData[i+1])
         y2 = round(Ay + By*yData[i+1])
         if symb[0] == 'l': Line(cv,x1,y1,x2,y2)
         if symb[1] == 'o':
             Oval(cv,x1-3,y1-3,x1+3,y1+3,fill="white")
         if symb[1] == 'b':
             Rectangle(cv,x1-3,y1-3,x1+3,y1+3,fill="white")
     if symb[1] == 'o':
             Oval(cv,x2-3,y2-3,x2+3,y2+3,fill="white")
     if symb[1] == 'b':
             Rectangle(cv,x2-3,y2-3,x2+3,y2+3,fill="white") 
Ejemplo n.º 14
0
    def plot_start(self, Canvas=None, length=20):
        #st_point, st_angle=self.geos[0].get_start_end_points(0,parent)

        start, start_ang = self.get_st_en_points(0)

        x_ca, y_ca = Canvas.get_can_coordinates(start.x, start.y)

        dx = cos(radians(start_ang)) * length
        dy = sin(radians(start_ang)) * length

        hdl = Line(Canvas.canvas,
                   x_ca,
                   -y_ca,
                   x_ca + dx,
                   -y_ca - dy,
                   fill='SteelBlue3',
                   arrow='last')
        return hdl
Ejemplo n.º 15
0
    def plot_start(self, CanvasClass):
        st_point, st_angle = self.geos[0].get_start_end_points(0)
        start = (st_point * self.sca) + self.p0

        x_ca, y_ca = CanvasClass.get_can_coordinates(start.x, start.y)

        length = 120
        dx = cos(radians(st_angle)) * length
        dy = sin(radians(st_angle)) * length

        hdl = Line(CanvasClass.canvas,
                   x_ca,
                   -y_ca,
                   x_ca + dx,
                   -y_ca - dy,
                   fill='SteelBlue3',
                   arrow='last')

        return hdl
Ejemplo n.º 16
0
 def __init__(self, master, data=None):
     self.master = master
     self.frame = Frame(self.master)
     self.frame.pack(fill=X)
     self.label = Label(self.frame)
     self.label.pack()
     self.canvas = Canvas(self.frame)
     self.canvas.pack()
     self.report = Label(self.frame)
     self.report.pack()
     self.left = Line(self.canvas, 0, 0, 0, 0)
     self.right = Line(self.canvas, 0, 0, 0, 0)
     self.pivot = Line(self.canvas, 0, 0, 0, 0)
     self.items = []
     self.size = self.maxvalue = 0
     if data:
         self.setdata(data)
Ejemplo n.º 17
0
#! /usr/bin/env python
Ejemplo n.º 18
0
class Array:

    def __init__(self, master, data=None):
        self.master = master
        self.frame = Frame(self.master)
        self.frame.pack(fill=X)
        self.label = Label(self.frame)
        self.label.pack()
        self.canvas = Canvas(self.frame)
        self.canvas.pack()
        self.report = Label(self.frame)
        self.report.pack()
        self.left = Line(self.canvas, 0, 0, 0, 0)
        self.right = Line(self.canvas, 0, 0, 0, 0)
        self.pivot = Line(self.canvas, 0, 0, 0, 0)
        self.items = []
        self.size = self.maxvalue = 0
        if data:
            self.setdata(data)

    def setdata(self, data):
        olditems = self.items
        self.items = []
        for item in olditems:
            item.delete()
        self.size = len(data)
        self.maxvalue = max(data)
        self.canvas.config(width=(self.size+1)*XGRID,
                           height=(self.maxvalue+1)*YGRID)
        for i in range(self.size):
            self.items.append(ArrayItem(self, i, data[i]))
        self.reset("Sort demo, size %d" % self.size)

    speed = "normal"

    def setspeed(self, speed):
        self.speed = speed

    def destroy(self):
        self.frame.destroy()

    in_mainloop = 0
    stop_mainloop = 0

    def cancel(self):
        self.stop_mainloop = 1
        if self.in_mainloop:
            self.master.quit()

    def step(self):
        if self.in_mainloop:
            self.master.quit()

    Cancelled = "Array.Cancelled"       # Exception

    def wait(self, msecs):
        if self.speed == "fastest":
            msecs = 0
        elif self.speed == "fast":
            msecs = msecs/10
        elif self.speed == "single-step":
            msecs = 1000000000
        if not self.stop_mainloop:
            self.master.update()
            id = self.master.after(msecs, self.master.quit)
            self.in_mainloop = 1
            self.master.mainloop()
            self.master.after_cancel(id)
            self.in_mainloop = 0
        if self.stop_mainloop:
            self.stop_mainloop = 0
            self.message("Cancelled")
            raise Array.Cancelled

    def getsize(self):
        return self.size

    def show_partition(self, first, last):
        for i in range(self.size):
            item = self.items[i]
            if first <= i < last:
                item.item.config(fill='red')
            else:
                item.item.config(fill='orange')
        self.hide_left_right_pivot()

    def hide_partition(self):
        for i in range(self.size):
            item = self.items[i]
            item.item.config(fill='red')
        self.hide_left_right_pivot()

    def show_left(self, left):
        if not 0 <= left < self.size:
            self.hide_left()
            return
        x1, y1, x2, y2 = self.items[left].position()
##      top, bot = HIRO
        self.left.coords([(x1-2, 0), (x1-2, 9999)])
        self.master.update()

    def show_right(self, right):
        if not 0 <= right < self.size:
            self.hide_right()
            return
        x1, y1, x2, y2 = self.items[right].position()
        self.right.coords(((x2+2, 0), (x2+2, 9999)))
        self.master.update()

    def hide_left_right_pivot(self):
        self.hide_left()
        self.hide_right()
        self.hide_pivot()

    def hide_left(self):
        self.left.coords(((0, 0), (0, 0)))

    def hide_right(self):
        self.right.coords(((0, 0), (0, 0)))

    def show_pivot(self, pivot):
        x1, y1, x2, y2 = self.items[pivot].position()
        self.pivot.coords(((0, y1-2), (9999, y1-2)))

    def hide_pivot(self):
        self.pivot.coords(((0, 0), (0, 0)))

    def swap(self, i, j):
        if i == j: return
        self.countswap()
        item = self.items[i]
        other = self.items[j]
        self.items[i], self.items[j] = other, item
        item.swapwith(other)

    def compare(self, i, j):
        self.countcompare()
        item = self.items[i]
        other = self.items[j]
        return item.compareto(other)

    def reset(self, msg):
        self.ncompares = 0
        self.nswaps = 0
        self.message(msg)
        self.updatereport()
        self.hide_partition()

    def message(self, msg):
        self.label.config(text=msg)

    def countswap(self):
        self.nswaps = self.nswaps + 1
        self.updatereport()

    def countcompare(self):
        self.ncompares = self.ncompares + 1
        self.updatereport()

    def updatereport(self):
        text = "%d cmps, %d swaps" % (self.ncompares, self.nswaps)
        self.report.config(text=text)
Ejemplo n.º 19
0
    def _drawAxes(self, canvas, xaxis, yaxis, bb1, bb2, scale, shift, xticks,
                  yticks):
        dict = {'anchor': N, 'fill': 'black'}
        width = 2
        s_ticks = 5
        if self.font is not None:
            dict['font'] = self.font
        if xaxis is not None:
            lower, upper = xaxis
            text = 1
            for y, d in [(bb1[1], -6), (bb2[1], 6)]:
                p1 = (scale[0] * lower) + shift[0], (scale[1] * y) + shift[1]
                p2 = (scale[0] * upper) + shift[0], (scale[1] * y) + shift[1]
                Line(self.canvas,
                     p1[0],
                     p1[1],
                     p2[0],
                     p2[1],
                     fill='black',
                     width=width)
                if xticks:
                    for x, label in xticks:
                        p = (scale[0]*x)+shift[0], \
                            (scale[1]*y)+shift[1]
                        Line(self.canvas,
                             p[0],
                             p[1],
                             p[0],
                             p[1] + d,
                             fill='black',
                             width=width)
                        if text:
                            dict['text'] = label
                            apply(CanvasText, (self.canvas, p[0], p[1]), dict)
                text = 0
                if xticks:
                    x1, lb1 = xticks[0]
                    x2, lb2 = xticks[1]
                    dx = (x2 - x1) / s_ticks
                    for i in range(len(xticks) - 1):
                        x1, lb1 = xticks[i]
                        for j in range(1, s_ticks):
                            x = x1 + dx * j
                            p = (scale[0] * x) + shift[0], (scale[1] *
                                                            y) + shift[1]
                            Line(self.canvas,
                                 p[0],
                                 p[1],
                                 p[0],
                                 p[1] + d,
                                 fill='black',
                                 width=1)

        dict['anchor'] = E
        if yaxis is not None:
            lower, upper = yaxis
            text = 1
            for x, d in [(bb1[0], -6), (bb2[0], 6)]:
                p1 = (scale[0] * x) + shift[0], (scale[1] * lower) + shift[1]
                p2 = (scale[0] * x) + shift[0], (scale[1] * upper) + shift[1]
                Line(self.canvas,
                     p1[0],
                     p1[1],
                     p2[0],
                     p2[1],
                     fill='black',
                     width=width)
                if yticks:
                    for y, label in yticks:
                        p = (scale[0]*x)+shift[0], \
                            (scale[1]*y)+shift[1]
                        Line(self.canvas,
                             p[0],
                             p[1],
                             p[0] - d,
                             p[1],
                             fill='black',
                             width=width)
                        if text:
                            dict['text'] = label
                            apply(CanvasText, (self.canvas, p[0] - 2, p[1]),
                                  dict)
                text = 0
                if yticks:
                    y1, lb1 = yticks[0]
                    y2, lb2 = yticks[1]
                    dy = (y2 - y1) / s_ticks
                    for i in range(len(yticks) - 1):
                        y1, lb1 = yticks[i]
                        for j in range(1, s_ticks):
                            y = y1 + dy * j
                            p = (scale[0] * x) + shift[0], (scale[1] *
                                                            y) + shift[1]
                            Line(self.canvas,
                                 p[0],
                                 p[1],
                                 p[0] - d,
                                 p[1],
                                 fill='black',
                                 width=1)
Ejemplo n.º 20
0
 def axes(xMin,xMax,yMin,yMax,Ax,Ay):
     # Draws the x = 0 and y = 0 lines
     if xMin*xMax < 0:
         Line(cv,Ax,topMargin,Ax,topMargin+height)
     if yMin*yMax < 0:
         Line(cv,leftMargin,Ay,leftMargin+width,Ay)