def normal_left_down(self, event): super(MapCanvas, self).normal_left_down(event) if self.current_hole is not None: # and not event.handled ca = self.calibration_item if ca is not None: if hasattr(event, 'item'): if hasattr(ca, 'right'): if event.item.right is ca.right: return rot = ca.rotation cpos = ca.center aff = AffineTransform() aff.translate(*cpos) aff.rotate(rot) aff.translate(-cpos[0], -cpos[1]) aff.translate(*cpos) mpos = self.mp.get_hole_pos(self.current_hole) # dpos = aff.transformPt(mpos) dpos = aff.transform(*mpos) spos = self.map_data((event.x, event.y)) # not much point in adding an indicator because the hole # renders its own # self.markupdict['tweak'] = Indicator(*spos, canvas = self) tweak = spos[0] - dpos[0], spos[1] - dpos[1] ca.tweak_dict[self.current_hole] = tweak self.request_redraw()
def raster_rubberband_pattern(cx, cy, offset, l, dx, rotation, single_pass): a = AffineTransform() a.translate(cx, cy) a.rotate(rotation) a.translate(-cx, -cy) # print offset, l n = int((l + 2 * offset) / dx) if n*dx<=l+2*offset: n = n+1 if n%2 else n dx = (l+2*offset)/float(n+1) n = int((l + 2 * offset) / dx) for i in xrange(0, n+1): y = cy - offset if i % 2 else cy + offset yield a.transform(cx - offset + dx * i, y) if not single_pass: for i in xrange(0, n+1): y = cy - offset if i % 2 else cy + offset yield a.transform(cx +l+offset - dx * i, y) yield a.transform(cx-offset, cy+offset)
def map_to_uncalibration(self, pos, cpos=None, rot=None, scale=None): cpos, rot, scale = self._get_calibration_params(cpos, rot, scale) a = AffineTransform() a.scale(1 / scale, 1 / scale) a.rotate(-rot) a.translate(cpos[0], cpos[1]) # a.translate(-cpos[0], -cpos[1]) # a.translate(*cpos) # a.rotate(-rot) # a.translate(-cpos[0], -cpos[1]) pos = a.transform(*pos) return pos
def rubberband_pattern(cx, cy, offset, l, rotation): p1 = cx - offset, cy + offset p2 = cx + l + offset, cy + offset p3 = cx + l + offset, cy - offset p4 = cx - offset, cy - offset a = AffineTransform() a.translate(cx, cy) a.rotate(rotation) a.translate(-cx, -cy) ps = (p1, p2, p3, p4, p1) for p in ps: yield a.transform(*p)
def line_pattern(cx, cy, length, rotation, n): p1 = (cx, cy) p2 = (cx + length, cy) for i in xrange(n): a = AffineTransform() a.translate(cx, cy) a.rotate(rotation) a.translate(-cx, -cy) if i % 2 == 0: ps = (p1, p2) else: ps = (p2, p1) for x, y in ps: yield a.transform(x, y)
def map_to_calibration(self, pos, cpos=None, rot=None, use_modified=False, scale=None, translate=None): cpos, rot, scale = self._get_calibration_params(cpos, rot, scale) a = AffineTransform() # if translate: # a.translate(*translate) # if scale: a.scale(scale, scale) if use_modified: a.translate(*cpos) # print cpos, rot, scale a.rotate(rot) a.translate(-cpos[0], -cpos[1]) if use_modified: a.translate(*cpos) pos = a.transform(*pos) return pos
def trough_pattern(cx, cy, length, width, rotation, use_x): """ 1 -------------- 2 | | 4 -------------- 3 """ p1 = (cx, cy) p2 = (cx + length, cy) p3 = (cx + length, cy - width) p4 = (cx, cy - width) a = AffineTransform() a.translate(cx, cy) a.rotate(rotation) a.translate(-cx, -cy) if use_x: ps = (p1, p2, p4, p3, p1) else: ps = (p1, p2, p3, p4, p1) for p in ps: yield a.transform(*p)