def find(self, *args): _alen = len(args) if _alen < 5: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _r = util.get_float(args[2]) _sa = util.get_float(args[3]) _ea = util.get_float(args[4]) _t = tolerance.TOL if _alen > 5: _t = tolerance.toltest(args[5]) _axmin = _x - _r - _t _axmax = _x + _r + _t _aymin = _y - _r - _t _aymax = _y + _r + _t _arcs = [] for _arc in self.getInRegion(_axmin, _aymin, _axmax, _aymax): _cx, _cy = _arc.getCenter().getCoords() if ((abs(_cx - _x) < _t) and (abs(_cy - _y) < _t) and (abs(_arc.getRadius() - _r) < _t) and (abs(_arc.getStartAngle() - _sa) < 1e-10) and (abs(_arc.getEndAngle() - _ea) < 1e-10)): _arcs.append(_arc) return _arcs
def getClosest(self, x, y, tol=tolerance.TOL): _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _cline = _tsep = None _cdict = {} _nodes = [self.getTreeRoot()] while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): _nodes.extend(_node.getSubnodes()) else: for _c in _node.getObjects(): _cid = id(_c) if _cid not in _cdict: _cx, _cy = _c.getProjection(_x, _y) if abs(_cx - _x) < _t and abs(_cy - _y) < _t: _sep = math.hypot((_cx - _x), (_cy - _y)) if _tsep is None: _tsep = _sep _cline = _c else: if _sep < _tsep: _tsep = _sep _cline = _c return _cline
def getInRegion(self, xmin, ymin, xmax, ymax): _xmin = util.get_float(xmin) _ymin = util.get_float(ymin) _xmax = util.get_float(xmax) if _xmax < _xmin: raise ValueError, "Illegal values: xmax < xmin" _ymax = util.get_float(ymax) if _ymax < _ymin: raise ValueError, "Illegal values: ymax < ymin" _polylines = [] if not len(self): return _polylines _nodes = [self.getTreeRoot()] _pdict = {} while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): for _subnode in _node.getSubnodes(): _sxmin, _symin, _sxmax, _symax = _subnode.getBoundary() if ((_sxmin > _xmax) or (_symin > _ymax) or (_sxmax < _xmin) or (_symax < _ymin)): continue _nodes.append(_subnode) else: for _p in _node.getObjects(): _pid = id(_p) if _pid not in _pdict: if _p.inRegion(_xmin, _ymin, _xmax, _ymax): _polylines.append(_p) _pdict[_pid] = True return _polylines
def _movePolyline(self, obj, *args): if obj not in self: raise ValueError, "Polyline not stored in Quadtree: " + `obj` _alen = len(args) if _alen < 1: raise ValueError, "Invalid argument count: %d" % _alen if not isinstance(args[0], list): raise TypeError, "Invalid coordinate list: " + `type(args[0])` _pxmin = _pxmax = _pymin = _pymax = None for _arg in args[0]: if not isinstance(_arg, tuple): raise TypeError, "Invalid coordinate tuple: " + `type(_arg)` if len(_arg) != 2: raise ValueError, "Invalid coodinate tuple: " + str(_arg) _x = util.get_float(_arg[0]) _y = util.get_float(_arg[1]) if _pxmin is None or _x < _pxmin: _pxmin = _x if _pxmax is None or _x > _pxmax: _pxmax= _x if _pymin is None or _y < _pymin: _pymin = _y if _pymax is None or _y > _pymax: _pymax = _y for _node in self.getNodes(_pxmin, _pymin, _pxmax, _pymax): _node.delObject(obj) # polyline may not be in node ... super(PolylineQuadtree, self).delObject(obj) obj.disconnect(self) self.addObject(obj)
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the CCircle to a coordinate pair. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the x-coordinate y: A Float value giving the y-coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the CCircle. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _cx, _cy = self.__center.getCoords() _r = self.__radius _dist = math.hypot((_x - _cx), (_y - _cy)) if abs(_dist - _r) < _t: _angle = math.atan2((_y - _cy),(_x - _cx)) _xoff = _r * math.cos(_angle) _yoff = _r * math.sin(_angle) return (_cx + _xoff), (_cy + _yoff) return None
def move(self, dx, dy): """Move a Leader. move(dx, dy) The first argument gives the x-coordinate displacement, and the second gives the y-coordinate displacement. Both values should be floats. """ if (self.isLocked() or self.__p1.isLocked() or self.__p2.isLocked() or self.__p3.isLocked()): raise RuntimeError, "Moving Leader not allowed - object locked." _dx = util.get_float(dx) _dy = util.get_float(dy) if abs(_dx) > 1e-10 or abs(_dy) > 1e-10: _x1, _y1 = self.__p1.getCoords() _x2, _y2 = self.__p2.getCoords() _x3, _y3 = self.__p3.getCoords() self.ignore('moved') try: self.__p1.move(_dx, _dy) self.__p2.move(_dx, _dy) self.__p3.move(_dx, _dy) finally: self.receive('moved') self.calcArrowPoints() self.sendMessage('moved', _x1, _y1, _x2, _y2, _x3, _y3)
def find(self, *args): _alen = len(args) if _alen < 4: raise ValueError, "Invalid argument count: %d" % _alen _x1 = util.get_float(args[0]) _y1 = util.get_float(args[1]) _x2 = util.get_float(args[2]) _y2 = util.get_float(args[3]) _t = tolerance.TOL if _alen > 4: _t = tolerance.toltest(args[4]) _xmin = min(_x1, _x2) - _t _ymin = min(_y1, _y2) - _t _xmax = max(_x1, _x2) + _t _ymax = max(_y1, _y2) + _t _clines = [] for _cline in self.getInRegion(_xmin, _ymin, _xmax, _ymax): _p1, _p2 = _cline.getKeypoints() if ((abs(_p1.x - _x1) < _t) and (abs(_p1.y - _y1) < _t) and (abs(_p2.x - _x2) < _t) and (abs(_p2.y - _y2) < _t)): _clines.append(_cline) elif ((abs(_p1.x - _x2) < _t) and (abs(_p1.y - _y2) < _t) and (abs(_p2.x - _x1) < _t) and (abs(_p2.y - _y1) < _t)): _clines.append(_cline) else: pass return _clines
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the Polyline by the x/y coordinates. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to a Point object on the Polyline. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this method returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _count = len(self.__pts) - 1 for _i in range(_count): _x1, _y1 = self.__pts[_i].getCoords() _x2, _y2 = self.__pts[_i + 1].getCoords() _pt = util.map_coords(_x, _y, _x1, _y1, _x2, _y2, _t) if _pt is not None: return _pt return None
def getInRegion(self, xmin, ymin, xmax, ymax): _xmin = util.get_float(xmin) _ymin = util.get_float(ymin) _xmax = util.get_float(xmax) if _xmax < _xmin: raise ValueError, "Illegal values: xmax < xmin" _ymax = util.get_float(ymax) if _ymax < _ymin: raise ValueError, "Illegal values: ymax < ymin" _acls = [] if not len(self): return _acls _nodes = [self.getTreeRoot()] _adict = {} while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): _nodes.extend(_node.getSubnodes()) else: for _acl in _node.getObjects(): _aid = id(_acl) if _aid not in _adict: if _acl.inRegion(_xmin, _ymin, _xmax, _ymax): _acls.append(_acl) _adict[_aid] = True return _acls
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the VCLine to a coordinate pair. mapCoords(x, y[, tol]) The function has two required argument: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the VCLine. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _vx = self.__keypoint.x if abs(_vx - x) < _t: return _vx, _y return None
def __init__(self, center, major, minor, angle, st=None, lt=None, col=None, t=None, **kw): _cp = center if not isinstance(_cp, point._Point): _cp = point.Point(center) _major = util.get_float(major) if not _major > 0.0: raise ValueError, "Invalid major axis value: %g" % _major _minor = util.get_float(minor) if not _minor > 0.0: raise ValueError, "Invalid minor axis value: %g" % _minor if _minor > _major: raise ValueError, "Minor axis must be less than major axis" _angle = util.make_angle(angle) _st = st if _st is None: _st = self.getDefaultStyle() super(Ellipse, self).__init__(_st, lt, col, t, **kw) self.__center = _cp self.__major = _major self.__minor = _minor self.__angle = _angle _cp.storeUser(self) _cp.connect('moved', self.__movePoint) _cp.connect('change_pending', self.__pointChangePending) _cp.connect('change_complete', self.__pointChangeComplete)
def move(self, dx, dy): """Move a Polyline. move(dx, dy) The first argument gives the x-coordinate displacement, and the second gives the y-coordinate displacement. Both values should be floats. """ _locked = self.isLocked() if not _locked: for _pt in self.__pts: if _pt.isLocked(): _locked = True break if _locked: raise RuntimeError, "Moving polyline not allowed - object locked." _dx = util.get_float(dx) _dy = util.get_float(dy) if abs(_dx) > 1e-10 or abs(_dy) > 1e-10: _coords = [] self.ignore('moved') try: for _pt in self.__pts: _coords.append(_pt.getCoords()) _pt.move(_dx, _dy) finally: self.receive('moved') self.sendMessage('moved', _coords)
def __init__(self, center, major, minor, angle, st=None, lt=None, col=None, t=None, **kw): _cp = center if not isinstance(_cp, point._Point): _cp = point.Point(center) _major = util.get_float(major) if not _major > 0.0: raise ValueError, "Invalid major axis value: %g" % _major _minor = util.get_float(minor) if not _minor > 0.0: raise ValueError, "Invalid minor axis value: %g" % _minor if _minor > _major: raise ValueError, "Minor axis must be less than major axis" _angle = util.make_angle(angle) _st = st if _st is None: _st = self.getDefaultStyle() super(Ellipse, self).__init__(_st, lt, col, t, **kw) self.__center = _cp self.__major = _major self.__minor = _minor self.__angle = _angle _cp.storeUser(self) _cp.connect("moved", self.__movePoint) _cp.connect("change_pending", self.__pointChangePending) _cp.connect("change_complete", self.__pointChangeComplete)
def getInRegion(self, xmin, ymin, xmax, ymax): _xmin = util.get_float(xmin) _ymin = util.get_float(ymin) _xmax = util.get_float(xmax) if _xmax < _xmin: raise ValueError, "Illegal values: xmax < xmin" _ymax = util.get_float(ymax) if _ymax < _ymin: raise ValueError, "Illegal values: ymax < ymin" _pts = [] if not len(self): return _pts _nodes = [self.getTreeRoot()] while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): for _subnode in _node.getSubnodes(): _sxmin, _symin, _sxmax, _symax = _subnode.getBoundary() if ((_sxmin > _xmax) or (_symin > _ymax) or (_sxmax < _xmin) or (_symax < _ymin)): continue _nodes.append(_subnode) else: for _pt in _node.getObjects(): if _pt.inRegion(_xmin, _ymin, _xmax, _ymax): _pts.append(_pt) return _pts
def _movePolyline(self, obj, *args): if obj not in self: raise ValueError, "Polyline not stored in Quadtree: " + ` obj ` _alen = len(args) if _alen < 1: raise ValueError, "Invalid argument count: %d" % _alen if not isinstance(args[0], list): raise TypeError, "Invalid coordinate list: " + ` type(args[0]) ` _pxmin = _pxmax = _pymin = _pymax = None for _arg in args[0]: if not isinstance(_arg, tuple): raise TypeError, "Invalid coordinate tuple: " + ` type(_arg) ` if len(_arg) != 2: raise ValueError, "Invalid coodinate tuple: " + str(_arg) _x = util.get_float(_arg[0]) _y = util.get_float(_arg[1]) if _pxmin is None or _x < _pxmin: _pxmin = _x if _pxmax is None or _x > _pxmax: _pxmax = _x if _pymin is None or _y < _pymin: _pymin = _y if _pymax is None or _y > _pymax: _pymax = _y for _node in self.getNodes(_pxmin, _pymin, _pxmax, _pymax): _node.delObject(obj) # polyline may not be in node ... super(PolylineQuadtree, self).delObject(obj) obj.disconnect(self) self.addObject(obj)
def getInRegion(self, xmin, ymin, xmax, ymax): _xmin = util.get_float(xmin) _ymin = util.get_float(ymin) _xmax = util.get_float(xmax) if _xmax < _xmin: raise ValueError, "Illegal values: xmax < xmin" _ymax = util.get_float(ymax) if _ymax < _ymin: raise ValueError, "Illegal values: ymax < ymin" _hcls = [] if not len(self): return _hcls _nodes = [self.getTreeRoot()] _hdict = {} while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): for _subnode in _node.getSubnodes(): _bounds = _subnode.getBoundary() _bmin = _bounds[1] _bmax = _bounds[3] if (_bmin > _ymax) or (_bmax < _ymin): continue _nodes.append(_subnode) else: for _hcl in _node.getObjects(): _hid = id(_hcl) if _hid not in _hdict: if _hcl.inRegion(_xmin, _ymin, _xmax, _ymax): _hcls.append(_hcl) _hdict[_hid] = True return _hcls
def getInRegion(self, xmin, ymin, xmax, ymax): _xmin = util.get_float(xmin) _ymin = util.get_float(ymin) _xmax = util.get_float(xmax) if _xmax < _xmin: raise ValueError, "Illegal values: xmax < xmin" _ymax = util.get_float(ymax) if _ymax < _ymin: raise ValueError, "Illegal values: ymax < ymin" _leaders = [] if not len(self): return _leaders _nodes = [self.getTreeRoot()] _ldict = {} while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): for _subnode in _node.getSubnodes(): _lxmin, _lymin, _lxmax, _lymax = _subnode.getBoundary() if ((_lxmin > _xmax) or (_lymin > _ymax) or (_lxmax < _xmin) or (_lymax < _ymin)): continue _nodes.append(_subnode) else: for _l in _node.getObjects(): _lid = id(_l) if _lid not in _ldict: if _l.inRegion(_xmin, _ymin, _xmax, _ymax): _leaders.append(_l) _ldict[_lid] = True return _leaders
def getProjection(self, x, y): """Find the projection point of some coordinates on the ACLine. getProjection(x, y) Arguments 'x' and 'y' should be float values. """ _x = util.get_float(x) _y = util.get_float(y) _x1, _y1 = self.getLocation().getCoords() _angle = self.__angle if self.isHorizontal(): _px = _x _py = _y1 elif self.isVertical(): _px = _x1 _py = _y else: _rangle = _angle * _dtr _dx = math.cos(_rangle) _dy = math.sin(_rangle) _sqlen = pow(_dx, 2) + pow(_dy, 2) _rn = ((_x - _x1) * _dx) + ((_y - _y1) * _dy) _r = _rn/_sqlen _px = _x1 + (_r * _dx) _py = _y1 + (_r * _dy) return _px, _py
def __movePoint(self, p, *args): _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _p1 = self.__p1 _p2 = self.__p2 _p3 = self.__p3 if p is _p1: _x1 = _x _y1 = _y _x2, _y2 = _p2.getCoords() _x3, _y3 = _p3.getCoords() elif p is _p2: _x1, _y1 = _p1.getCoords() _x2 = _x _y2 = _y _x3, _y3 = _p3.getCoords() elif p is _p3: _x1, _y1 = _p1.getCoords() _x2, _y2 = _p2.getCoords() _x3 = _x _y3 = _y else: raise ValueError, "Unexpected Leader endpoint: " + `p` self.sendMessage('moved', _x1, _y1, _x2, _y2, _x3, _y3)
def getClosest(self, x, y, tol=tolerance.TOL): _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _acline = _tsep = None _adict = {} _nodes = [self.getTreeRoot()] while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): _nodes.extend(_node.getSubnodes()) else: for _a in _node.getObjects(): _aid = id(_a) if _aid not in _adict: _ax, _ay = _a.getProjection(_x, _y) if abs(_ax - _x) < _t and abs(_ay - _y) < _t: _sep = math.hypot((_ax - _x), (_ay - _y)) if _tsep is None: _tsep = _sep _acline = _a else: if _sep < _tsep: _tsep = _sep _acline = _a return _acline
def getInRegion(self, xmin, ymin, xmax, ymax): _xmin = util.get_float(xmin) _ymin = util.get_float(ymin) _xmax = util.get_float(xmax) if _xmax < _xmin: raise ValueError, "Illegal values: xmax < xmin" _ymax = util.get_float(ymax) if _ymax < _ymin: raise ValueError, "Illegal values: ymax < ymin" _vcls = [] if not len(self): return _vcls _nodes = [self.getTreeRoot()] _vdict = {} while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): for _subnode in _node.getSubnodes(): _bounds = _subnode.getBoundary() _bmin = _bounds[0] _bmax = _bounds[2] if ((_bmin > _xmax) or (_bmax < _xmin)): continue _nodes.append(_subnode) else: for _vcl in _node.getObjects(): _vid = id(_vcl) if _vid not in _vdict: if _vcl.inRegion(_xmin, _ymin, _xmax, _ymax): _vcls.append(_vcl) _vdict[_vid] = True return _vcls
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the CLine to a coordinate pair. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to a actual Point on the CLine. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _x1, _y1 = self.__p1.getCoords() _x2, _y2 = self.__p2.getCoords() _sqlen = pow((_x2 - _x1), 2) + pow((_y2 - _y1), 2) if _sqlen < 1e-10: # both points the same raise RuntimeError, "CLine points coincident." _r = ((_x - _x1) * (_x2 - _x1) + (_y - _y1) * (_y2 - _y1)) / _sqlen _px = _x1 + _r * (_x2 - _x1) _py = _y1 + _r * (_y2 - _y1) if abs(_px - _x) < _t and abs(_py - _y) < _t: return _px, _py return None
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the HCLine to a coordinate pair. mapCoords(x, y[, tol]) The function has two required argument: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the HCLine. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _hy = self.__keypoint.y if abs(_hy - _y) < _t: return _x, _hy return None
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the Leader to a coordinate pair. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the 'x' coordinate y: A Float value giving the 'y' coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the Leader. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _x1, _y1 = self.__p1.getCoords() _x2, _y2 = self.__p2.getCoords() _x3, _y3 = self.__p3.getCoords() _pt = util.map_coords(_x, _y, _x1, _y1, _x2, _y2, _t) if _pt is None: _pt = util.map_coords(_x, _y, _x2, _y2, _x3, _y3, _t) if _pt is not None: return _pt return None
def mapCoords(self, x, y, tol=tolerance.TOL): """Return the nearest Point on the Arc to a coordinate pair. mapCoords(x, y[, tol]) The function has two required arguments: x: A Float value giving the x-coordinate y: A Float value giving the y-coordinate There is a single optional argument: tol: A float value equal or greater than 0.0 This function is used to map a possibly near-by coordinate pair to an actual Point on the Arc. If the distance between the actual Point and the coordinates used as an argument is less than the tolerance, the actual Point is returned. Otherwise, this function returns None. """ _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _cx, _cy = self.__center.getCoords() _r = self.__radius _dist = math.hypot((_x - _cx), (_y - _cy)) if abs(_dist - _r) < _t: _ra = math.atan2((_y - _cy), (_x - _cx)) _da = _ra * _rtd if _da < 0.0: _da = _da + 360.0 if self.throughAngle(_da): _xoff = _r * math.cos(_ra) _yoff = _r * math.sin(_ra) return (_cx + _xoff), (_cy + _yoff) return None
def getInRegion(self, xmin, ymin, xmax, ymax): _xmin = util.get_float(xmin) _ymin = util.get_float(ymin) _xmax = util.get_float(xmax) if _xmax < _xmin: raise ValueError, "Illegal values: xmax < xmin" _ymax = util.get_float(ymax) if _ymax < _ymin: raise ValueError, "Illegal values: ymax < ymin" _clines = [] if not len(self): return _clines _nodes = [self.getTreeRoot()] _cdict = {} while len(_nodes): _node = _nodes.pop() if _node.hasSubnodes(): for _subnode in _node.getSubnodes(): _nodes.append(_subnode) else: for _cline in _node.getObjects(): _cid = id(_cline) if _cid not in _cdict: if _cline.inRegion(_xmin, _ymin, _xmax, _ymax): _clines.append(_cline) _cdict[_cid] = True return _clines
def move_objects(objs, dx, dy): """Move a list of objects. move_objects(objs, dx, dy) objs: A list or tuple containing the objects to move. dx: The displacement along the x-axis dy: The displacement along the y-axis """ if not isinstance(objs, (list, tuple)): raise TypeError, "Invalid object list/tuple: " + ` type(objs) ` _dx = util.get_float(dx) _dy = util.get_float(dy) if abs(_dx) > 1e-10 or abs(_dy) > 1e-10: _objdict = {} _fillets = [] for _obj in objs: if not isinstance(_obj, DimString): _objdict[id(_obj)] = True for _obj in objs: _oid = id(_obj) if _oid not in _objdict: continue if _objdict[_oid]: if isinstance(_obj, Point): _obj.move(_dx, _dy) for _user in _obj.getUsers(): _uid = id(_user) if (_uid in _objdict and not isinstance(_user, Dimension)): _objdict[_uid] = False elif isinstance(_obj, (Segment, CLine)): _move_seg_cline(_obj, _objdict, _dx, _dy) elif isinstance(_obj, (Circle, CCircle)): _move_circle(_obj, _objdict, _dx, _dy) elif isinstance(_obj, Arc): _move_arc(_obj, _objdict, _dx, _dy) elif isinstance(_obj, Leader): _move_leader(_obj, _objdict, _dx, _dy) elif isinstance(_obj, Polyline): _move_polyline(_obj, _objdict, _dx, _dy) elif isinstance(_obj, (TextBlock, Dimension)): _obj.move(_dx, _dy) elif isinstance(_obj, (HCLine, VCLine, ACLine)): _move_spcline(_obj, _objdict, _dx, _dy) elif isinstance(_obj, (Chamfer, Fillet)): _s1, _s2 = _obj.getSegments() if id(_s1) not in _objdict or id(_s2) not in _objdict: _layer = _obj.getParent() _layer.delObject(_obj) if isinstance(_obj, Fillet): _fillets.append(_obj) else: print "Unexpected entity type: " + ` type(_obj) ` _objdict[_oid] = False for _obj in _fillets: _obj._calculateCenter() # FIXME
def move_objects(objs, dx, dy): """Move a list of objects. move_objects(objs, dx, dy) objs: A list or tuple containing the objects to move. dx: The displacement along the x-axis dy: The displacement along the y-axis """ if not isinstance(objs, (list, tuple)): raise TypeError, "Invalid object list/tuple: " + `type(objs)` _dx = util.get_float(dx) _dy = util.get_float(dy) if abs(_dx) > 1e-10 or abs(_dy) > 1e-10: _objdict = {} _fillets = [] for _obj in objs: if not isinstance(_obj, DimString): _objdict[id(_obj)] = True for _obj in objs: _oid = id(_obj) if _oid not in _objdict: continue if _objdict[_oid]: if isinstance(_obj, Point): _obj.move(_dx, _dy) for _user in _obj.getUsers(): _uid = id(_user) if (_uid in _objdict and not isinstance(_user, Dimension)): _objdict[_uid] = False elif isinstance(_obj, (Segment, CLine)): _move_seg_cline(_obj, _objdict, _dx, _dy) elif isinstance(_obj, (Circle, CCircle)): _move_circle(_obj, _objdict, _dx, _dy) elif isinstance(_obj, Arc): _move_arc(_obj, _objdict, _dx, _dy) elif isinstance(_obj, Leader): _move_leader(_obj, _objdict, _dx, _dy) elif isinstance(_obj, Polyline): _move_polyline(_obj, _objdict, _dx, _dy) elif isinstance(_obj, (TextBlock, Dimension)): _obj.move(_dx, _dy) elif isinstance(_obj, (HCLine, VCLine, ACLine)): _move_spcline(_obj, _objdict, _dx, _dy) elif isinstance(_obj, (Chamfer, Fillet)): _s1, _s2 = _obj.getSegments() if id(_s1) not in _objdict or id(_s2) not in _objdict: _layer = _obj.getParent() _layer.delObject(_obj) if isinstance(_obj, Fillet): _fillets.append(_obj) else: print "Unexpected entity type: " + `type(_obj)` _objdict[_oid] = False for _obj in _fillets: _obj._calculateCenter() # FIXME
def getClosest(self, x, y, tol=tolerance.TOL): _x = util.get_float(x) _y = util.get_float(y) _t = tolerance.toltest(tol) _leader = _tsep = None _bailout = False _ldict = {} _nodes = [self.getTreeRoot()] while len(_nodes): _node = _nodes.pop() _xmin, _ymin, _xmax, _ymax = _node.getBoundary() if ((_x < (_xmin - _t)) or (_x > (_xmax + _t)) or (_y < (_ymin - _t)) or (_y > (_ymax + _t))): continue if _node.hasSubnodes(): _nodes.extend(_node.getSubnodes()) else: for _l in _node.getObjects(): _lid = id(_l) _p1, _p2, _p3 = _l.getPoints() if _lid not in _ldict: _px, _py = _p1.getCoords() if ((abs(_px - _x) < 1e-10) and (abs(_py - _y) < 1e-10)): _leader = _l _bailout = True break _px, _py = _p2.getCoords() if ((abs(_px - _x) < 1e-10) and (abs(_py - _y) < 1e-10)): _leader = _l _bailout = True break _px, _py = _p3.getCoords() if ((abs(_px - _x) < 1e-10) and (abs(_py - _y) < 1e-10)): _leader = _l _bailout = True break _ldict[_lid] = True _pt = _l.mapCoords(_x, _y, _t) if _pt is not None: _px, _py = _pt _sep = math.hypot((_px - _x), (_py - _y)) if _tsep is None: _tsep = _sep _leader = _l else: if _sep < _tsep: _tsep = _sep _leader = _l if _bailout: break return _leader
def find(self, *args): _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _t = tolerance.TOL if _alen > 2: _t = tolerance.toltest(args[2]) return self.getInRegion((_x - _t), (_y - _t), (_x + _t), (_y + _t))
def __movePoint(self, p, *args): _plen = len(args) if _plen < 2: raise ValueError, "Invalid argument count: %d" % _plen _x = util.get_float(args[0]) _y = util.get_float(args[1]) if p is not self.__keypoint: raise ValueError, "Invalid point for HCLine::movePoint()" + ` p ` if abs(p.y - _y) > 1e-10: self.sendMessage("moved", _x, _y)
def __movePoint(self, p, *args): _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) if p is not self.__center: raise ValueError, "Unexpected point in movePoint" + ` p ` self.sendMessage("moved", _x, _y, self.__major, self.__minor, self.__angle) self.modified()
def find(self, *args): _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _t = tolerance.TOL if _alen > 2 : _t = tolerance.toltest(args[2]) return self.getInRegion((_x - _t), (_y - _t), (_x + _t), (_y + _t))
def __movePoint(self, p, *args): _plen = len(args) if _plen < 2: raise ValueError, "Invalid argument count: %d" % _plen _x = util.get_float(args[0]) _y = util.get_float(args[1]) if p is not self.__keypoint: raise ValueError, "Invalid point for VCLine::movePoint()" + ` p ` if abs(p.x - _x) > 1e-10: self.sendMessage('moved', _x, _y)
def __movePoint(self, p, *args): _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) if p is not self.__center: raise ValueError, "Unexpected point in movePoint" + ` p ` self.sendMessage('moved', _x, _y, self.__major, self.__minor, self.__angle) self.modified()
def find(self, *args): _alen = len(args) if _alen < 1: raise ValueError, "Invalid argument count: %d" % _alen if not isinstance(args[0], list): raise TypeError, "Invalid coordinate list: " + `type(args[0])` _coords = [] _xmin = _xmax = _ymin = _ymax = None for _arg in args[0]: if not isinstance(_arg, tuple): raise TypeError, "Invalid coordinate tuple: " + `type(_arg)` if len(_arg) != 2: raise ValueError, "Invalid coodinate tuple: " + str(_arg) _x = util.get_float(_arg[0]) _y = util.get_float(_arg[1]) _coords.append((_x, _y)) if _xmin is None or _x < _xmin: _xmin = _x if _xmax is None or _x > _xmax: _xmax= _x if _ymin is None or _y < _ymin: _ymin = _y if _ymax is None or _y > _ymax: _ymax = _y _t = tolerance.TOL if _alen > 1: _t = tolerance.toltest(args[1]) _xmin = _xmin - _t _ymin = _ymin - _t _xmax = _xmax + _t _ymax = _ymax + _t _plines = [] for _pline in self.getInRegion(_xmin, _ymin, _xmax, _ymax): _pts = _pline.getPoints() if len(_pts) != len(_coords): continue _hit = False for _i in range(len(_pts)): _px, _py = _pts[_i].getCoords() if ((abs(_px - _coords[_i][0]) > _t) or (abs(_py - _coords[_i][1]) > _t)): continue _hit = True if not _hit: _pts.reverse() for _i in range(len(_pts)): _px, _py = _pts[_i].getCoords() if ((abs(_px - _coords[_i][0]) > _t) or (abs(_py - _coords[_i][1]) > _t)): continue _hit = True if _hit: _plines.append(_pline) return _plines
def __movePoint(self, p, *args): _plen = len(args) if _plen < 2: raise ValueError, "Invalid argument count: %d" % _plen _x = util.get_float(args[0]) _y = util.get_float(args[1]) if p is not self.__keypoint: raise ValueError, "Invalid point for ACLine::movePoint()" + `p` _px, _py = p.getCoords() if abs(_px - _x) > 1e-10 or abs(_py - _y) > 1e-10: self.sendMessage('moved', _x, _y, self.getAngle())
def find(self, *args): _alen = len(args) if _alen < 1: raise ValueError, "Invalid argument count: %d" % _alen if not isinstance(args[0], list): raise TypeError, "Invalid coordinate list: " + ` type(args[0]) ` _coords = [] _xmin = _xmax = _ymin = _ymax = None for _arg in args[0]: if not isinstance(_arg, tuple): raise TypeError, "Invalid coordinate tuple: " + ` type(_arg) ` if len(_arg) != 2: raise ValueError, "Invalid coodinate tuple: " + str(_arg) _x = util.get_float(_arg[0]) _y = util.get_float(_arg[1]) _coords.append((_x, _y)) if _xmin is None or _x < _xmin: _xmin = _x if _xmax is None or _x > _xmax: _xmax = _x if _ymin is None or _y < _ymin: _ymin = _y if _ymax is None or _y > _ymax: _ymax = _y _t = tolerance.TOL if _alen > 1: _t = tolerance.toltest(args[1]) _xmin = _xmin - _t _ymin = _ymin - _t _xmax = _xmax + _t _ymax = _ymax + _t _plines = [] for _pline in self.getInRegion(_xmin, _ymin, _xmax, _ymax): _pts = _pline.getPoints() if len(_pts) != len(_coords): continue _hit = False for _i in range(len(_pts)): _px, _py = _pts[_i].getCoords() if ((abs(_px - _coords[_i][0]) > _t) or (abs(_py - _coords[_i][1]) > _t)): continue _hit = True if not _hit: _pts.reverse() for _i in range(len(_pts)): _px, _py = _pts[_i].getCoords() if ((abs(_px - _coords[_i][0]) > _t) or (abs(_py - _coords[_i][1]) > _t)): continue _hit = True if _hit: _plines.append(_pline) return _plines
def __movePoint(self, p, *args): _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _cp = self.__center if p is not _cp: raise ValueError, "Point is not arc center: " + ` p ` _x, _y = _cp.getCoords() self.sendMessage('moved', _x, _y, self.__radius, self.__sa, self.__ea)
def __movePoint(self, p, *args): _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _cp = self.__center if p is not _cp: raise ValueError, "Point is not ccircle center: " + `p` _x, _y = _cp.getCoords() self.sendMessage('moved', _x, _y, self.__radius)
def clipToRegion(self, xmin, ymin, xmax, ymax): _xmin = util.get_float(xmin) _ymin = util.get_float(ymin) _xmax = util.get_float(xmax) if _xmax < _xmin: raise ValueError, "Illegal values: xmax < xmin" _ymax = util.get_float(ymax) if _ymax < _ymin: raise ValueError, "Illegal values: ymax < ymin" _x = self.__keypoint.x if _xmin < _x < _xmax: return _x, _ymin, _x, _ymax return None
def clipToRegion(self, xmin, ymin, xmax, ymax): _xmin = util.get_float(xmin) _ymin = util.get_float(ymin) _xmax = util.get_float(xmax) if _xmax < _xmin: raise ValueError, "Illegal values: xmax < xmin" _ymax = util.get_float(ymax) if _ymax < _ymin: raise ValueError, "Illegal values: ymax < ymin" _y = self.__keypoint.y if _ymin < _y < _ymax: return _xmin, _y, _xmax, _y return None
def _moveHCLine(self, obj, *args): if obj not in self: raise ValueError, "HCLine not stored in Quadtree: " + ` obj ` _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) for _node in self.getNodes(_y): _node.delObject(obj) # hcline may not be in node super(HCLineQuadtree, self).delObject(obj) obj.disconnect(self) self.addObject(obj)
def _moveVCLine(self, obj, *args): if obj not in self: raise ValueError, "VCLine not stored in Quadtree: " + ` obj ` _alen = len(args) if _alen < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) for _node in self.getNodes(_x): _node.delObject(obj) # vcline may not be in node super(VCLineQuadtree, self).delObject(obj) obj.disconnect(self) self.addObject(obj)
def _movePoint(self, obj, *args): if obj not in self: raise ValueError, "Point not stored in Quadtree: " + `obj` _alen = len(args) if len(args) < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) for _node in self.getNodes(_x, _y): _node.delObject(obj) super(PointQuadtree, self).delObject(obj) obj.disconnect(self) self.addObject(obj)
def _movePoint(self, obj, *args): if obj not in self: raise ValueError, "Point not stored in Quadtree: " + ` obj ` _alen = len(args) if len(args) < 2: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) for _node in self.getNodes(_x, _y): _node.delObject(obj) super(PointQuadtree, self).delObject(obj) obj.disconnect(self) self.addObject(obj)
def __init__(self, im, xmin=0.0, ymax=0.0, upp=1.0): if _debug is True: print "SDB debug: Created new ImageView class instance" if not isinstance(im, image.Image): raise TypeError, "Invalid Image type: " + `type(im)` _xmin = util.get_float(xmin) _ymax = util.get_float(ymax) _upp = util.get_float(upp) if not _upp > 0.0: raise ValueError, "Invalid units-per-pixel value: %g" % _upp self.__image = im self.__pixmap = None self.__gc = None self.__width = None self.__height = None _da = gtk.DrawingArea() _da.set_size_request(100, 100) _black = gtk.gdk.color_parse('black') _da.modify_fg(gtk.STATE_NORMAL, _black) _da.modify_bg(gtk.STATE_NORMAL, _black) _da.set_flags(gtk.CAN_FOCUS) _da.connect("expose_event", self.__exposeEvent) _da.connect("realize", self.__realizeEvent) _da.connect("configure_event", self.__configureEvent) _da.connect("key_press_event", self.__keyPressEvent) _da.connect("key_release_event", self.__keyPressEvent) _da.connect("enter_notify_event", self.__elNotifyEvent) _da.connect("leave_notify_event", self.__elNotifyEvent) _da.connect("focus_in_event", self.__focusChangedEvent) _da.connect("focus_out_event", self.__focusChangedEvent) _da.set_events(gtk.gdk.EXPOSURE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.ENTER_NOTIFY_MASK| gtk.gdk.LEAVE_NOTIFY_MASK| gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK | gtk.gdk.FOCUS_CHANGE_MASK | gtk.gdk.POINTER_MOTION_MASK) self.__da = _da self.__xmin = _xmin self.__ymax = _ymax self.__upp = _upp self.__view = None im.connect('added_child', self.__imageAddedChild) im.connect('removed_child', self.__imageRemovedChild) im.connect('modified', self.__objModified)
def coordsToPixels(self, x, y): """Convert from x-y coordinates to pixel coordinates coordsToPixels(x, y) Arguments 'x' and 'y' should be float values. This method returns a tuple holding two integer values """ _x = util.get_float(x) _y = util.get_float(y) _upp = self.__upp _xp = int((x - self.__xmin)/_upp) _yp = int((self.__ymax - y)/_upp) return _xp, _yp
def coordsToPixels(self, x, y): """Convert from x-y coordinates to pixel coordinates coordsToPixels(x, y) Arguments 'x' and 'y' should be float values. This method returns a tuple holding two integer values """ _x = util.get_float(x) _y = util.get_float(y) _upp = self.__upp _xp = int((x - self.__xmin) / _upp) _yp = int((self.__ymax - y) / _upp) return _xp, _yp
def _moveCCircle(self, obj, *args): if obj not in self: raise ValueError, "CCircle not stored in Quadtree: " + `obj` _alen = len(args) if _alen < 3: raise ValueError, "Invalid argument count: %d" % _alen _x = util.get_float(args[0]) _y = util.get_float(args[1]) _r = util.get_float(args[2]) for _node in self.getNodes(_x, _y, _r): _node.delObject(obj) # ccircle may not be in node ... super(CCircleQuadtree, self).delObject(obj) obj.disconnect(self) self.addObject(obj)
def _moveCLine(self, obj, *args): if obj not in self: raise ValueError, "CLine not stored in Quadtree: " + ` obj ` _alen = len(args) if _alen < 4: raise ValueError, "Invalid argument count: %d" % _alen _x1 = util.get_float(args[0]) _y1 = util.get_float(args[1]) _x2 = util.get_float(args[2]) _y2 = util.get_float(args[3]) for _node in self.getNodes(_x1, _y1, _x2, _y2): _node.delObject(obj) # cline may not be in node ... super(CLineQuadtree, self).delObject(obj) obj.disconnect(self) self.addObject(obj)