Exemplo n.º 1
0
    def drag(self, a, evt):
        if evt.inaxes is None: return 0
        if evt.xdata is None: return

        axes = a.axes
        x, y = self._eval_xy()
        dxd = evt.x - self._drag_backup[2]
        dyd = evt.y - self._drag_backup[3]

        if (evt.guiEvent.ShiftDown()):
            if abs(dxd) > 2 * abs(dyd):
                dyd = 0
            elif abs(dyd) > 2 * abs(dxd):
                dxd = 0
        i = 0
        for x0 in nd_iter(x):
            xd, void = transform_point(axes.transData, x0, evt.ydata)
            x1, void = transform_point(axes.transData.inverted(), xd + dxd,
                                       void)
            self._artists[i].set_xdata([x1, x1])
            i = i + 1
        for y0 in nd_iter(y):
            void, yd = transform_point(axes.transData, evt.xdata, y0)
            void, y1 = transform_point(axes.transData.inverted(), void,
                                       yd + dyd)

            self._artists[i].set_ydata([y1, y1])
            i = i + 1
        self._drag_delta = (dxd, dyd)
        return 1
Exemplo n.º 2
0
    def dragdone(self, a, evt):
        axes = a.axes
        x, y = self._eval_xy()
        dxd, dyd = self._drag_delta

        if (evt.xdata is not None and evt.ydata is not None):
            i = 0
            xdata = []
            ydata = []
            for x0 in nd_iter(x):
                xd, void = transform_point(axes.transData, x0, evt.ydata)
                x1, void = transform_point(axes.transData.inverted(), xd + dxd,
                                           void)
                xdata.append(x1)
                i = i + 1
            for y0 in nd_iter(y):
                void, yd = transform_point(axes.transData, evt.xdata, y0)
                void, y1 = transform_point(axes.transData.inverted(), void,
                                           yd + dyd)
                ydata.append(y1)

                i = i + 1
        else:
            xdata = x
            ydata = y

        action = UndoRedoFigobjMethod(self._artists[0], 'data',
                                      (np.array(xdata), np.array(ydata)))
        window = evt.guiEvent.GetEventObject().GetTopLevelParent()
        GlobalHistory().get_history(window).make_entry([action])
        return 1
Exemplo n.º 3
0
    def dragdone(self, a, evt):
        axes = a.axes
        x, y = self._eval_xy()
        dxd, dyd = self._drag_delta
   
        if (evt.xdata is not  None and
            evt.ydata is not None):
            i = 0
            xdata = []
            ydata = []
            for x0 in nd_iter(x):
                xd, void= transform_point(axes.transData,
                                          x0, evt.ydata)
                x1, void= transform_point(axes.transData.inverted(),
                                          xd+dxd, void)
                xdata.append(x1)
                i = i+1
            for y0 in nd_iter(y):
                void, yd= transform_point(axes.transData,
                                          evt.xdata, y0)
                void, y1= transform_point(axes.transData.inverted(),
                                          void, yd+dyd)
                ydata.append(y1)

                i = i+1
        else:
            xdata = x
            ydata = y

        action = UndoRedoFigobjMethod(self._artists[0], 
                                      'data', 
                                      (np.array(xdata), np.array(ydata)))
        window = evt.guiEvent.GetEventObject().GetTopLevelParent()
        GlobalHistory().get_history(window).make_entry([action])
        return 1
Exemplo n.º 4
0
    def drag(self, a, evt):
        if evt.inaxes is None: return 0
        if evt.xdata is None:return

        axes = a.axes
        x, y = self._eval_xy()
        dxd = evt.x - self._drag_backup[2]
        dyd = evt.y - self._drag_backup[3]
  
        if (evt.guiEvent.ShiftDown()):
           if abs(dxd) > 2*abs(dyd): 
               dyd = 0
           elif abs(dyd) > 2*abs(dxd): 
               dxd = 0
        i = 0
        for x0 in nd_iter(x):
            xd, void= transform_point(axes.transData,
                                      x0, evt.ydata)
            x1, void= transform_point(axes.transData.inverted(),
                                      xd+dxd, void)
            self._artists[i].set_xdata([x1, x1])
            i = i+1
        for y0 in nd_iter(y):
            void, yd= transform_point(axes.transData,
                                      evt.xdata, y0)
            void, y1= transform_point(axes.transData.inverted(),
                                      void, yd+dyd)

            self._artists[i].set_ydata([y1, y1])
            i = i+1
        self._drag_delta = (dxd, dyd)
        return 1
Exemplo n.º 5
0
    def calc_range_change_by_pan(self, xdata, ydata, sxdata, sydata):
        from ifigure.utils.geom import transform_point

        x0, y0 = transform_point(self.transAxes, 0.5, 0.5)
        x0, y0 = transform_point(self.transData.inverted(), x0, y0)

        dx = x0 - (xdata + sxdata) / 2.0
        dy = y0 - (ydata + sydata) / 2.0

        w = self._pseudo_w
        h = self._pseudo_h

        dx = dx / w
        dy = dy / h
        df = max(abs(xdata - sxdata) / w, abs(ydata - sydata) / h)

        minx, maxx, miny, maxy, minz, maxz = self.get_w_lims()

        midx = (minx + maxx) / 2.
        midy = (miny + maxy) / 2.
        midz = (minz + maxz) / 2.
        M = self.get_proj()
        dp = -np.array([dx, dy])

        xx = (np.dot(M, (1, midy, midz, 1)) - np.dot(M,
                                                     (0, midy, midz, 1)))[:2]
        dx1 = np.sum(xx * dp) / np.sum(xx * xx) if np.sum(xx *
                                                          xx) > 0.01 else 0.0
        yy = (np.dot(M, (midx, 1, midz, 1)) - np.dot(M,
                                                     (midx, 0, midz, 1)))[:2]
        dy1 = np.sum(yy * dp) / np.sum(yy * yy) if np.sum(yy *
                                                          yy) > 0.01 else 0.0
        zz = (np.dot(M, (midx, midy, 1, 1)) - np.dot(M,
                                                     (midx, midy, 0, 1)))[:2]
        dz1 = np.sum(zz * dp) / np.sum(zz * zz) if np.sum(zz *
                                                          zz) > 0.01 else 0.0

        minx, maxx = minx + dx1, maxx + dx1
        miny, maxy = miny + dy1, maxy + dy1
        minz, maxz = minz + dz1, maxz + dz1

        dx = (maxx - minx) * df / 2.
        dy = (maxy - miny) * df / 2.
        dz = (maxz - minz) * df / 2.
        x0 = (maxx + minx) / 2.0
        y0 = (maxy + miny) / 2.0
        z0 = (maxz + minz) / 2.0

        return ((x0 - dx, x0 + dx), (y0 - dy, y0 + dy), (z0 - dz, z0 + dz))
Exemplo n.º 6
0
    def dragdone(self, a, evt, idx = 'all'):
        axes = a.axes
        x, y = self._eval_xy()
        x = x.copy()
        y = y.copy()
        dxd, dyd = self._drag_delta

        if (evt.xdata is not  None and
            evt.ydata is not None):
            i = 0
            xdata = []
            ydata = []
            for x0 in x:
                x1 = x0[:]
                if idx == 'all' or idx == i: 
                    if (self._drag_mode==1 or 
                       self._drag_mode==2):
                       xd, void= transform_point(axes.transData,
                                              x0[0], evt.ydata)
                       x1[0], void= transform_point(axes.transData.inverted(),
                                              xd+dxd, void)
                    if (self._drag_mode==1 or 
                       self._drag_mode==3):
                       xd, void= transform_point(axes.transData,
                                              x0[1], evt.ydata)
                       x1[1], void= transform_point(axes.transData.inverted(),
                                              xd+dxd, void)
                xdata.append(x1)
                i = i + 1        
            for y0 in y:
                y1 = y0[:]
                if idx == 'all' or idx == i: 
                    if (self._drag_mode==1 or 
                        self._drag_mode==4):
                        void, yd= transform_point(axes.transData,
                                          evt.xdata, y0[0])
                        void, y1[0]= transform_point(axes.transData.inverted(),
                                          void, yd+dyd)
                    if (self._drag_mode==1 or 
                        self._drag_mode==5):
                        void, yd= transform_point(axes.transData,
                                          evt.xdata, y0[1])
                        void, y1[1]= transform_point(axes.transData.inverted(),
                                          void, yd+dyd)
                ydata.append(y1)
                i = i + 1        
        else:
            xdata = x
            ydata = y

        xdata = np.array(xdata)
        ydata = np.array(ydata)
        action = UndoRedoFigobjMethod(self._artists[0], 
                                     'data', (xdata,ydata))

        window = evt.guiEvent.GetEventObject().GetTopLevelParent()
        GlobalHistory().get_history(window).make_entry([action])
        return 1
Exemplo n.º 7
0
    def picker_a(self, a, evt):
        hit = False
        axes = a.axes
        if axes is None: return False, {}
        x = a.get_xdata()[0]
        xd, yd = transform_point(axes.transData, x, 0)
        if abs(evt.x - xd) < 5:
            hit = True
        y = a.get_ydata()[0]
        xd, yd = transform_point(axes.transData, 0, y)

        if abs(evt.y - yd) < 5:
            hit = True
        if hit:
            return True, {'child_artist': a}
        return False, {}
Exemplo n.º 8
0
    def calc_range_change_by_pan(self, xdata, ydata, sxdata, sydata):
        from ifigure.utils.geom import transform_point

        x0, y0 = transform_point(
                           self.transAxes, 0.5, 0.5)
        x0, y0 = transform_point(
                           self.transData.inverted(), x0, y0)
        
        dx = x0 - (xdata + sxdata)/2.0
        dy = y0 - (ydata + sydata)/2.0
        
        w = self._pseudo_w
        h = self._pseudo_h

        dx = dx/w; dy = dy/h
        df = max(abs(xdata - sxdata)/w, abs(ydata - sydata)/h)
        
        minx, maxx, miny, maxy, minz, maxz = self.get_w_lims()

        midx = (minx+maxx)/2.; midy = (miny+maxy)/2. ;midz = (minz+maxz)/2.
        M = self.get_proj()
        dp = -np.array([dx, dy])

        xx = (np.dot(M, (1,midy,midz,1)) - 
              np.dot(M, (0,midy,midz,1)))[:2]
        dx1 = np.sum(xx * dp)/np.sum(xx * xx) if np.sum(xx * xx) > 0.01 else 0.0
        yy = (np.dot(M, (midx,1,midz,1)) - 
              np.dot(M, (midx,0,midz,1)))[:2]
        dy1 = np.sum(yy * dp)/np.sum(yy * yy) if np.sum(yy * yy) > 0.01 else 0.0
        zz = (np.dot(M, (midx,midy,1,1)) -
              np.dot(M, (midx,midy,0,1)))[:2]
        dz1 = np.sum(zz * dp)/np.sum(zz * zz) if np.sum(zz * zz) > 0.01 else 0.0

        minx, maxx = minx + dx1, maxx + dx1
        miny, maxy = miny + dy1, maxy + dy1
        minz, maxz = minz + dz1, maxz + dz1
        
        dx = (maxx-minx)*df/2.
        dy = (maxy-miny)*df/2.
        dz = (maxz-minz)*df/2.
        x0 = (maxx+minx)/2.0
        y0 = (maxy+miny)/2.0
        z0 = (maxz+minz)/2.0

        return ((x0 - dx, x0 + dx),(y0 - dy, y0 + dy),(z0 - dz, z0 + dz))
Exemplo n.º 9
0
    def picker_a(self, a, evt): 
        hit = False
        axes = a.axes
        if axes is None: return False, {}
        x = a.get_xdata()[0]
        xd, yd= transform_point(axes.transData,
                                       x, 0)
        if abs(evt.x - xd) < 5:
              hit = True
        y = a.get_ydata()[0]
        xd, yd= transform_point(axes.transData,
                                       0, y)

        if abs(evt.y - yd) < 5:
            hit = True
        if hit: 
            return True, {'child_artist':a}
        return False, {}
Exemplo n.º 10
0
    def dragstart(self, a, evt):
        if evt.inaxes is None:
            return 0
        axes = a.axes
        if axes is None:
            return 0

        if not a in self._artists:
            return False, {}
        idx = self._artists.index(a)
        x = self.getp("x")
        if idx >= len(x):
            mode = 'h'
        else:
            mode = 'v'

        self._drag_backup = (evt.xdata, evt.ydata, evt.x, evt.y)
        self._drag_delta = (0, 0)
        self._drag_mode = 1
        # 1 transpose
        # 2 x expand(smaller edge)
        # 3 x expand(larger edge)
        # 4 y expand(smaller edge)
        # 5 y expand(smaller edge)
        xy = a.get_xy()
        x0d, y0d = transform_point(axes.transData, min(xy[:, 0]), min(xy[:,
                                                                         1]))
        x1d, y1d = transform_point(axes.transData, max(xy[:, 0]), max(xy[:,
                                                                         1]))
        #        print evt.x, x0d

        delta = 3
        if mode == 'v':
            if abs(evt.x - x0d) < delta:
                self._drag_mode = 2
            if abs(evt.x - x1d) < delta:
                self._drag_mode = 3
        else:
            if abs(evt.y - y0d) < delta:
                self._drag_mode = 4
            if abs(evt.y - y1d) < delta:
                self._drag_mode = 5

        return 0
Exemplo n.º 11
0
    def dragstart(self, a, evt):
        if evt.inaxes is None: return 0
        axes = a.axes
        if axes is None: return 0

        if not a in self._artists:return False, {}
        idx = self._artists.index(a)
        x = self.getp("x")
        if idx >= len(x):
            mode = 'h'
        else:
            mode = 'v'
        
        self._drag_backup = (evt.xdata, evt.ydata, evt.x, evt.y)
        self._drag_delta = (0,0)
        self._drag_mode = 1 
        # 1 transpose 
        # 2 x expand(smaller edge) 
        # 3 x expand(larger edge)
        # 4 y expand(smaller edge) 
        # 5 y expand(smaller edge)        
        xy = a.get_xy()
        x0d, y0d= transform_point(axes.transData,
                                  min(xy[:,0]), min(xy[:,1]))
        x1d, y1d= transform_point(axes.transData,
                                  max(xy[:,0]), max(xy[:,1]))
#        print evt.x, x0d

        delta = 3
        if mode == 'v':
           if abs(evt.x - x0d) < delta:
               self._drag_mode=2
           if abs(evt.x - x1d) < delta:
               self._drag_mode=3
        else:
           if abs(evt.y - y0d) < delta:
               self._drag_mode=4
           if abs(evt.y - y1d) < delta:
               self._drag_mode=5

        return 0
Exemplo n.º 12
0
    def picker_a(self, a, evt):
        ###
        ###  it does not use contain to catch edges
        ### 
        if not a in self._artists:return False, {}

        idx = self._artists.index(a)
        x = self.getp("x")
        if idx >= len(x):
            mode = 'h'
        else:
            mode = 'v'
        xy = a.get_xy()
        axes = a.axes
        x0d, y0d= transform_point(axes.transData, 
                                       min(xy[:,0]), min(xy[:,1]))
        x1d, y1d= transform_point(axes.transData, 
                                       max(xy[:,0]), max(xy[:,1]))
        x0da, y0da= transform_point(axes.transAxes, 
                                       min(xy[:,0]), min(xy[:,1]))
        x1da, y1da= transform_point(axes.transAxes, 
                                       max(xy[:,0]), max(xy[:,1]))

        hit = False
        if mode  == 'v':
           if (evt.x > x0d-5 and
               evt.x < x1d+5 and
               evt.y > y0da and
               evt.y < y1da):
               hit = True
        else:
           if (evt.x > x0da and
               evt.x < x1da and
               evt.y > y0d-5 and
               evt.y < y1d+5):
               hit = True
        if hit: 
            return True, {'child_artist':a}
        return False, {}
Exemplo n.º 13
0
    def drag(self, a, evt, idx='all'):
        if evt.xdata is None:
            return
        if evt.inaxes is None:
            return
        axes = a.axes
        x, y = self._eval_xy()
        dx = evt.xdata - self._drag_backup[0]
        dy = evt.ydata - self._drag_backup[1]
        dxd = (evt.x - self._drag_backup[2])
        dyd = (evt.y - self._drag_backup[3])
        if (evt.guiEvent.ShiftDown()):
            if abs(dxd) > 2 * abs(dyd):
                dyd = 0
            elif abs(dyd) > 2 * abs(dxd):
                dxd = 0

        i = 0
        for x0 in x:
            if idx != 'all' and idx != i:
                i = i + 1
                continue
            xd, void = transform_point(axes.transData, x0[0], evt.ydata)
            x1, void = transform_point(axes.transData.inverted(), xd + dxd,
                                       void)
            xd, void = transform_point(axes.transData, x0[1], evt.ydata)
            x2, void = transform_point(axes.transData.inverted(), xd + dxd,
                                       void)
            if self._drag_mode == 1:
                xx = [x1, x2]
            elif self._drag_mode == 2:
                xx = [x1, x0[1]]
            elif self._drag_mode == 3:
                xx = [x0[0], x2]
            elif self._drag_mode == 4:
                xx = x0
            elif self._drag_mode == 5:
                xx = x0
            xy = _make_xy_x(xx)
            self._artists[i].set_xy(xy)
            i = i + 1
        for y0 in y:
            if idx != 'all' and idx != i:
                i = i + 1
                continue
            void, yd = transform_point(axes.transData, evt.xdata, y0[0])
            void, y1 = transform_point(axes.transData.inverted(), void,
                                       yd + dyd)
            void, yd = transform_point(axes.transData, evt.xdata, y0[1])
            void, y2 = transform_point(axes.transData.inverted(), void,
                                       yd + dyd)
            if self._drag_mode == 1:
                yy = [y1, y2]
            elif self._drag_mode == 2:
                yy = y0
            elif self._drag_mode == 3:
                yy = y0
            elif self._drag_mode == 4:
                yy = [y1, y0[1]]
            elif self._drag_mode == 5:
                yy = [y0[0], y2]
            xy = _make_xy_y(yy)
            self._artists[i].set_xy(xy)
            i = i + 1
        self._drag_delta = (dxd, dyd)
Exemplo n.º 14
0
    def drag(self, a, evt, idx = 'all'):
        if evt.xdata is None: return
        if evt.inaxes is None: return
        axes = a.axes
        x, y = self._eval_xy()
        dx = evt.xdata - self._drag_backup[0]
        dy = evt.ydata - self._drag_backup[1]
        dxd = (evt.x - self._drag_backup[2])
        dyd = (evt.y - self._drag_backup[3])
        if (evt.guiEvent.ShiftDown()):
           if abs(dxd) > 2*abs(dyd): 
               dyd= 0
           elif abs(dyd) > 2*abs(dxd): 
               dxd = 0

        i = 0
        for x0 in x:
            if idx != 'all' and idx != i: 
                i = i+1
                continue
            xd, void= transform_point(axes.transData,
                                      x0[0], evt.ydata)
            x1, void= transform_point(axes.transData.inverted(),
                                      xd+dxd, void)
            xd, void= transform_point(axes.transData,
                                      x0[1], evt.ydata)
            x2, void= transform_point(axes.transData.inverted(),
                                      xd+dxd, void)
            if self._drag_mode==1:
               xx = [x1,x2]
            elif self._drag_mode==2:
               xx = [x1, x0[1]]
            elif self._drag_mode==3:
               xx = [x0[0], x2]
            elif self._drag_mode==4:
               xx = x0
            elif self._drag_mode==5:
               xx = x0
            xy = _make_xy_x(xx)
            self._artists[i].set_xy(xy)
            i = i+1
        for y0 in y:
            if idx != 'all' and idx != i: 
                i = i+1
                continue
            void, yd= transform_point(axes.transData,
                                      evt.xdata, y0[0])
            void, y1= transform_point(axes.transData.inverted(),
                                      void, yd+dyd)
            void, yd= transform_point(axes.transData,
                                      evt.xdata, y0[1])
            void, y2= transform_point(axes.transData.inverted(),
                                      void, yd+dyd)
            if self._drag_mode==1:
               yy = [y1,y2]
            elif self._drag_mode==2:
               yy = y0
            elif self._drag_mode==3:
               yy = y0
            elif self._drag_mode==4:
               yy = [y1, y0[1]]
            elif self._drag_mode==5:
               yy = [y0[0], y2]
            xy = _make_xy_y(yy)
            self._artists[i].set_xy(xy)
            i = i+1
        self._drag_delta = (dxd, dyd)