source: sasview/src/sas/plottools/arrow3d.py @ ef3445e2

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since ef3445e2 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1"""
2Module that draws multiple arrows in 3D coordinates
3"""
4
5from matplotlib.patches import FancyArrowPatch
6from mpl_toolkits.mplot3d import proj3d
7import time
8#from matplotlib.artist import allow_rasterization
9class Arrow3D(FancyArrowPatch):
10    """
11    Draw 3D arrow
12    """
13   
14    def __init__(self, base, xs, ys, zs, colors, *args, **kwargs):
15        """
16        Init
17           
18        :Params xs: [[x0, x0+dx0], [x1, x1+dx1], ...]
19        :Params ys: [[y0, y0+dy0], [y1, y1+dy1], ...]
20        :Params zs: [[z0, z0+dz0], [z1, z1+dz1], ...]
21        :Params colors: [[R0, G0, B0], [R1, G1, B1], ...]
22        where R, G, B ranges (0,1)
23        """
24        FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs)
25        self.leftdown = False
26        self.t_click = 0
27        self._verts3d = xs, ys, zs
28        self.colors = colors
29        self.base = base
30       
31        if base != None:
32            # To turn the updating off during dragging
33            base.canvas.mpl_connect('button_press_event', self.onLeftDown)
34            base.canvas.mpl_connect('button_release_event', self.onLeftUp)
35           
36    def onLeftDown(self, event):
37        """
38        """
39        self.leftdown = True
40        self.t_click = time.time()
41       
42    def onLeftUp(self, event):
43        """
44        """
45        t_up = time.time() - self.t_click
46        # Avoid just clicking
47        if t_up > 0.1:
48            self.leftdown = False
49            self.base.canvas.draw()
50   
51    def draw(self, renderer, rasterized=True):
52        """
53        Drawing actually happens here
54        """
55        # Draws only when the dragging finished
56        if self.leftdown:
57            return
58        xs3d, ys3d, zs3d = self._verts3d
59        for i in xrange(len(xs3d)):
60            xs, ys, _ = proj3d.proj_transform(xs3d[i], ys3d[i], zs3d[i], 
61                                               renderer.M)
62            self.set_positions((xs[0],ys[0]),(xs[1],ys[1]))
63            self.set_color(self.colors[i])
64            FancyArrowPatch.draw(self, renderer)
65           
66        self.leftdown = False
Note: See TracBrowser for help on using the repository browser.