Beispiel #1
0
def _adjust_endpoint(arc, pt, objdict, dx, dy):
    _layer = arc.getParent()
    if pt.getParent() is not _layer:
        raise RuntimeError, "Arc/Endpoint parent object conflict!"
    _pid = id(pt)
    _users = []
    for _user in pt.getUsers():
        _users.append(_user)
    if len(_users) == 1 and _users[0] is arc:
        if objdict.get(_pid) is not False:
            pt.move(dx, dy)
    else:
        pt.freeUser(arc)
        _x, _y = pt.getCoords()
        _nx = _x + dx
        _ny = _y + dy
        _pts = _layer.find('point', _nx, _ny)
        if len(_pts) == 0:
            _np = Point(_nx, _ny)
            _layer.addObject(_np)
        else:
            _np = _most_used(_pts)
        _np.storeUser(arc)
        _adjust_dimensions(pt, _np)
        _layer.delObject(pt)
    if objdict.get(_pid) is not False:
        objdict[_pid] = False
def _adjust_endpoint(arc, pt, objdict, dx, dy):
    _layer = arc.getParent()
    if pt.getParent() is not _layer:
        raise RuntimeError, "Arc/Endpoint parent object conflict!"
    _pid = id(pt)
    _users = []
    for _user in pt.getUsers():
        _users.append(_user)
    if len(_users) == 1 and _users[0] is arc:
        if objdict.get(_pid) is not False:
            pt.move(dx, dy)
    else:
        pt.freeUser(arc)
        _x, _y = pt.getCoords()
        _nx = _x + dx
        _ny = _y + dy
        _pts = _layer.find('point', _nx, _ny)
        if len(_pts) == 0:
            _np = Point(_nx, _ny)
            _layer.addObject(_np)
        else:
            _np = _most_used(_pts)
        _np.storeUser(arc)
        _adjust_dimensions(pt, _np)
        _layer.delObject(pt)
    if objdict.get(_pid) is not False:
        objdict[_pid] = False
Beispiel #3
0
def _copy_leader(obj, objdict, dx, dy):
    _p1, _p2, _p3 = obj.getPoints()
    _p1id = id(_p1)
    _p2id = id(_p2)
    _p3id = id(_p3)
    _layer = obj.getParent()
    if _can_move(_p1, objdict) and objdict.get(_p1id) is not False:
        _p1.move(dx, dy)
    else:
        _x, _y = _p1.getCoords()
        _nx = _x + dx
        _ny = _y + dy
        _pts = _layer.find('point', _nx, _ny)
        if len(_pts) == 0:
            _np = Point(_nx, _ny)
            _layer.addObject(_np)
        else:
            _np = _most_used(_pts)
        obj.setP1(_np)
        _adjust_dimensions(_p1, _np)
        _layer.delObject(_p1)
    if _can_move(_p2, objdict) and objdict.get(_p2id) is not False:
        _p2.move(dx, dy)
    else:
        _x, _y = _p2.getCoords()
        _nx = _x + dx
        _ny = _y + dy
        _pts = _layer.find('point', _nx, _ny)
        if len(_pts) == 0:
            _np = Point(_nx, _ny)
            _layer.addObject(_np)
        else:
            _np = _most_used(_pts)
        obj.setP2(_np)
        _adjust_dimensions(_p2, _np)
        _layer.delObject(_p2)
    if _can_move(_p3, objdict) and objdict.get(_p3id) is not False:
        _p3.move(dx, dy)
    else:
        _x, _y = _p3.getCoords()
        _nx = _x + dx
        _ny = _y + dy
        _pts = _layer.find('point', _nx, _ny)
        if len(_pts) == 0:
            _np = Point(_nx, _ny)
            _layer.addObject(_np)
        else:
            _np = _most_used(_pts)
        obj.setP3(_np)
        _adjust_dimensions(_p3, _np)
        _layer.delObject(_p3)
    if objdict.get(_p1id) is not False:
        objdict[_p1id] = False
    if objdict.get(_p2id) is not False:
        objdict[_p2id] = False
    if objdict.get(_p3id) is not False:
        objdict[_p3id] = False
def _test_point(layer, x, y):
    _pts = layer.find('point', x, y)
    if len(_pts) == 0:
        _p = Point(x, y)
        layer.addObject(_p)
    else:
        _p = _pts.pop()
        _max = _p.countUsers()
        for _pt in _pts:
            _count = _pt.countUsers()
            if _count > _max:
                _max = _count
                _p = _pt
    return _p
Beispiel #5
0
def _test_point(layer, x, y):
    _pts = layer.find('point', x, y)
    if len(_pts) == 0:
        _p = Point(x, y)
        layer.addObject(_p)
    else:
        _p = _pts.pop()
        _max = _p.countUsers()
        for _pt in _pts:
            _count = _pt.countUsers()
            if _count > _max:
                _max = _count
                _p = _pt
    return _p
Beispiel #6
0
def _copy_seg_cline(obj, objdict, dx, dy):
    if isinstance(obj, Segment):
        _p1, _p2 = obj.getEndpoints()
    elif isinstance(obj, CLine):
        _p1, _p2 = obj.getKeypoints()
    else:
        raise TypeError, "Unexpected object type: " + ` type(obj) `
    _p1id = id(_p1)
    _p2id = id(_p2)
    _mp1 = _mp2 = False
    if _can_move(obj, objdict):
        _mp1 = _can_move(_p1, objdict) and objdict.get(_p1id) is not False
        _mp2 = _can_move(_p2, objdict) and objdict.get(_p2id) is not False
    _layer = obj.getParent()
    if _mp1:
        _p1.move(dx, dy)
    else:
        _x, _y = _p1.getCoords()
        _nx = _x + dx
        _ny = _y + dy
        _pts = _layer.find('point', _nx, _ny)
        if len(_pts) == 0:
            _np = Point(_nx, _ny)
            _layer.addObject(_np)
        else:
            _np = _most_used(_pts)
        obj.setP1(_np)
        _adjust_dimensions(_p1, _np)
        _layer.delObject(_p1)
    if _mp2:
        _p2.move(dx, dy)
    else:
        _x, _y = _p2.getCoords()
        _nx = _x + dx
        _ny = _y + dy
        _pts = _layer.find('point', _nx, _ny)
        if len(_pts) == 0:
            _np = Point(_nx, _ny)
            _layer.addObject(_np)
        else:
            _np = _most_used(_pts)
        obj.setP2(_np)
        _adjust_dimensions(_p2, _np)
        _layer.delObject(_p2)
    if objdict.get(_p1id) is not False:
        objdict[_p1id] = False
    if objdict.get(_p2id) is not False:
        objdict[_p2id] = False
def _rotate_polyline(obj, objdict, cx, cy, ra):
    _pts = obj.getPoints()
    _layer = obj.getParent()
    if _layer is None:
        raise RuntimeError, "Polyline parent is None"
    _move = True
    for _pt in _pts:
        if _pt.getParent() is not _layer:
            raise RuntimeError, "Polyline/point parent object conflict!"
        _move = (_can_move(_pt, objdict) and
                 (objdict.get(id(_pt)) is not False))
        if not _move:
            break
    if _move:
        for _pt in _pts:
            _x, _y = _calc_coords(_pt, cx, cy, ra)
            _pt.setCoords(_x, _y)
            _pid = id(_pt)
            objdict[_pid] = False
    else:
        for _i in range(len(_pts)):
            _pt = _pts[_i]
            if objdict.get(_pid) is True:
                _x, _y = _calc_coords(_pt, cx, cy, ra)
                _pts = _layer.find('point', _x, _y)
                if len(_pts) == 0:
                    _np = Point(_x, _y)
                    _layer.addObject(_np)
                else:
                    _np = _most_used(_pts)
                obj.setPoint(_i, _np)
                objdict[_pid] = False
                _layer.delObject(_pt)
def _rotate_hcline(obj, objdict, cx, cy, ra):
    _layer = obj.getParent()
    if _layer is None:
        raise RuntimeError, "HCLine parent is None"
    _lp = obj.getLocation()
    if _lp.getParent() is not _layer:
        raise RuntimeError, "HCLine/Point parent object conflict!"
    _x, _y = _calc_coords(_lp, cx, cy, ra)
    _pts = _layer.find('point', _x, _y)
    if len(_pts) == 0:
        _np = Point(_x, _y)
        _layer.addObject(_np)
    else:
        _np = _most_used(_pts)
    _da = ra/_dtr
    if abs(fmod(_da, 180.0)) < 1e-10:
        obj.setLocation(_np)
        if _adjust_dimension(_lp, _np):
            _layer.delObject(_lp)
    elif abs(fmod(_da, 90.0)) < 1e-10:
        _layer.addObject(VCLine(_np))
        if _adjust_dimension(_lp, _np):
            _layer.delObject(obj)
    else:
        _layer.addObject(ACLine(_np, _da))
        _layer.delObject(obj)
    _pid = id(_lp)
    if objdict.get(_pid) is not False:
        objdict[_pid] = False
Beispiel #9
0
def _copy_arc(obj, objdict, dx, dy):
    _cp = obj.getCenter()
    _pid = id(_cp)
    _layer = obj.getParent()
    _ep1, _ep2 = obj.getEndpoints()
    _pts = _layer.find('point', _ep1[0], _ep1[1])
    _lp1 = _used_by(obj, _pts)
    if _lp1 is None:
        raise RuntimeError, "Lost Arc first endpoint: " + str(_ep1)
    _adjust_endpoint(obj, _lp1, objdict, dx, dy)
    _pts = _layer.find('point', _ep2[0], _ep2[1])
    _lp2 = _used_by(obj, _pts)
    if _lp2 is None:
        raise RuntimeError, "Lost Arc second endpoint: " + str(_ep2)
    _adjust_endpoint(obj, _lp2, objdict, dx, dy)
    _x, _y = _cp.getCoords()
    _nx = _x + dx
    _ny = _y + dy
    _pts = _layer.find('point', _nx, _ny)
    if len(_pts) == 0:
        _np = Point(_nx, _ny)
        _layer.addObject(_np)
    else:
        _np = _most_used(_pts)
    obj.setCenter(_np)
    _adjust_dimensions(_cp, _np)
    _layer.delObject(_cp)
    if objdict.get(_pid) is not False:
        objdict[_pid] = False
Beispiel #10
0
def _copy_polyline(obj, objdict, dx, dy):
    _pts = obj.getPoints()
    _mp = {}
    for _pt in _pts:
        _pid = id(_pt)
        _mp[_pid] = False
    if _can_move(obj, objdict):
        for _pt in _pts:
            _pid = id(_pt)
            if _can_move(_pt, objdict) and objdict.get(_pid) is not False:
                _mp[_pid] = True
    _layer = obj.getParent()
    for _i in range(len(_pts)):
        _pt = _pts[_i]
        _pid = id(_pt)
        if _mp[_pid]:
            _pt.move(dx, dy)
        else:
            _x, _y = _pt.getCoords()
            _nx = _x + dx
            _ny = _y + dy
            _lpts = _layer.find('point', _nx, _ny)
            if len(_lpts) == 0:
                _np = Point(_nx, _ny)
                _layer.addObject(_np)
            else:
                _np = _most_used(_lpts)
            obj.setPoint(_i, _np)
            _adjust_dimensions(_pt, _np)
            _layer.delObject(_pt)
        if objdict.get(_pid) is not False:
            objdict[_pid] = False
def _adjust_endpoint(arc, pt, objdict, cx, cy, ra):
    _layer = arc.getParent()
    if pt.getParent() is not _layer:
        raise RuntimeError, "Arc/Endpoint parent object conflict!"
    _pid = id(pt)
    _users = []
    for _user in pt.getUsers():
        _users.append(_user)
    _np = None
    _x, _y = _calc_coords(pt, cx, cy, ra)    
    if len(_users) == 1 and _users[0] is arc:
        if _can_move(pt, objdict) and objdict.get(_pid) is not False:
            pt.setCoords(_x, _y)
        else:
            _pts = _layer.find('point', _x, _y)
            if len(_pts) == 0:
                _np = Point(_x, _y)
                _layer.addObject(_np)
            else:
                _np = _most_used(_pts)
    else:
        pt.freeUser(arc)
        _pts = _layer.find('point', _x, _y)
        if len(_pts) == 0:
            _np = Point(_x, _y)
            _layer.addObject(_np)
        else:
            _np = _most_used(_pts)
    if _np is not None:
        _np.storeUser(arc)
        if _adjust_dimensions(pt, _np):
            _layer.delObject(pt)
    if objdict.get(_pid) is not False:
        objdict[_pid] = False
def _xfrm_point(pt, objdict, cx, cy, ra):
    _layer = pt.getParent()
    _pid = id(pt)
    _np = None
    _x, _y = _calc_coords(pt, cx, cy, ra)
    if _can_move(pt, objdict) and objdict.get(_pid) is not False:
        pt.setCoords(_x, _y)
    else:
        _pts = _layer.find('point', _x, _y)
        if len(_pts) == 0:
            _np = Point(_x, _y)
            _layer.addObject(_np)
        else:
            _np = _most_used(_pts)
    return _np
Beispiel #13
0
def _copy_spcline(obj, objdict, dx, dy):
    _lp = obj.getLocation()
    _pid = id(_lp)
    _layer = obj.getParent()
    _x, _y = _lp.getCoords()
    _nx = _x + dx
    _ny = _y + dy
    _pts = _layer.find('point', _nx, _ny)
    if len(_pts) == 0:
        _np = Point(_nx, _ny)
        _layer.addObject(_np)
    else:
        _np = _most_used(_pts)
    obj.setLocation(_np)
    _adjust_dimensions(_lp, _np)
    _layer.delObject(_lp)
    if objdict.get(_pid) is not False:
        objdict[_pid] = False
def _rotate_acline(obj, objdict, cx, cy, ra):
    _layer = obj.getParent()
    if _layer is None:
        raise RuntimeError, "ACLine parent is None"
    _lp = obj.getLocation()
    if _lp.getParent() is not _layer:
        raise RuntimeError, "ACLine/Point parent object conflict!"
    _x, _y = _calc_coords(_lp, cx, cy, ra)
    _pts = _layer.find('point', _x, _y)
    if len(_pts) == 0:
        _np = Point(_x, _y)
        _layer.addObject(_np)
    else:
        _np = _most_used(_pts)
    _racl = (obj.getAngle() * _dtr) + ra
    obj.setLocation(_np)
    obj.setAngle(_racl/_dtr)
    if _adjust_dimension(_lp, _np):
        _layer.delObject(_lp)
    _pid = id(_lp)
    if objdict.get(_pid) is not False:
        objdict[_pid] = False
Beispiel #15
0
def paste_button_press_cb(gtkimage, widget, event, tool):
    # print "called paste_button_press_cb()"
    _image = gtkimage.getImage()
    _x, _y = _image.getCurrentPoint()
    # print "x: %g; y: %g" % (_x, _y)
    _active_layer = _image.getActiveLayer()
    _objs = PythonCAD.Generic.globals.selectobj.getObjects()
    _objmap = {}
    _image.startAction()
    try:
        for _obj in _objs:
            if isinstance(_obj, Point):
                if not _objmap.has_key('point'):
                    _objmap['point'] = {}
                _pt = Point(_x, _y)
                _ept = _active_layer.findObject(_pt)
                if _ept is None:
                    _active_layer.addObject(_pt)
                    _objmap['point'][_obj] = _pt
                else:
                    _objmap['point'][_obj] = _ept
            elif isinstance(_obj, Segment):
                if not _objmap.has_key('segment'):
                    _objmap['segment'] = {}
                _cseg = _obj.clone()
                _cseg.move(_x, _y)
                _eseg = _active_layer.findObject(_cseg)
                if _eseg is None:
                    _p1, _p2 = _cseg.getEndpoints()
                    _ep = _active_layer.findObject(_p1)
                    if _ep is None:
                        _active_layer.addObject(_p1)
                    else:
                        _cseg.setP1(_ep)
                    _ep = _active_layer.findObject(_p2)
                    if _ep is None:
                        _active_layer.addObject(_p2)
                    else:
                        _cseg.setP2(_ep)
                    _active_layer.addObject(_cseg)
                else:
                    _objmap['segment'][_obj] = _eseg
            elif isinstance(_obj, (Circle, Arc, CCircle)):
                _cc = _obj.clone()
                _cc.move(_x, _y)
                _ec = _active_layer.findObject(_cc)
                if _ec is None:
                    _cp = _cc.getCenter()
                    _ep = _active_layer.findObject(_cp)
                    if _ep is None:
                        _active_layer.addObject(_cp)
                    else:
                        _cc.setLocation(_ep)
                    _active_layer.addObject(_cc)
            elif isinstance(_obj, (HCLine, VCLine, ACLine)):
                _ccl = _obj.clone()
                _ccl.move(_x, _y)
                _ecl = _active_layer.findObject(_ccl)
                if _ecl is None:
                    _lp = _ccl.getLocation()
                    _ep = _active_layer.findObject(_lp)
                    if _ep is None:
                        _active_layer.addObject(_lp)
                    else:
                        _ccl.setLocation(_ep)
                    _active_layer.addObject(_ccl)
            elif isinstance(_obj, CLine):
                _ccl = _obj.clone()
                _ccl.move(_x, _y)
                _ecl = _active_layer.findObject(_ccl)
                if _ecl is None:
                    _p1, _p2 = _ccl.getKeypoints()
                    _ep = _active_layer.findObject(_p1)
                    if _ep is None:
                        _active_layer.addObject(_p1)
                    else:
                        _ccl.setP1(_ep)
                    _ep = _active_layer.findObject(_p2)
                    if _ep is None:
                        _active_layer.addObject(_p2)
                    else:
                        _ccl.setP2(_ep)
                    _active_layer.addObject(_ccl)
            elif isinstance(_obj, LinearDimension):
                if _active_layer.findObject(_obj) is None:
                    _l1, _l2 = _obj.getDimLayers()
                    if _image.hasLayer(_l1) and _image.hasLayer(_l2):
                        _p1, _p2 = _obj.getDimPoints()
                        _ds = _obj.getDimStyle()
                        if isinstance(_obj, HorizontalDimension):
                            _dtype = HorizontalDimension
                        elif isinstance(_obj, VerticalDimension):
                            _dtype = VerticalDimension
                        else:
                            _dtype = LinearDimension
                        _dim = _dtype(_l1, _p1, _l2, _p2, _x, _y, _ds)
                        _active_layer.addObject(_dim)
            elif isinstance(_obj, RadialDimension):
                if _active_layer.findObject(_obj) is None:
                    _lyr = _obj.getDimLayer()
                    if _image.hasLayer(_lyr):
                        _dc = _obj.getDimCircle()
                        _ds = _obj.getDimStyle()
                        _dim = RadialDimension(_lyr, _dc, _x, _y, _ds)
                        _active_layer.addObject(_dim)
            elif isinstance(_obj, AngularDimension):
                if _active_layer.findObject(_obj) is None:
                    _cl, _l1, _l2 = _obj.getDimLayers()
                    if (_image.hasLayer(_cl) and
                        _image.hasLayer(_l1) and
                        _image.hasLayer(_l2)):
                        _cp, _p1, _p2 = _obj.getDimPoints()
                        _ds = _obj.getDimStyle()
                        _dim = AngularDimension(_cl, _cp, _l1, _p1, _l2, _p2, _x, _y, _ds)
                        _active_layer.addObject(_dim)
            elif isinstance(_obj, text.TextBlock):
                _ntb = _obj.clone()
                _ntb.setLocation(_x, _y)
                _active_layer.addObject(_ntb)
            else:
                print "Unexpected type for pasting: " + `type(_obj)`
    finally:
        _image.endAction()