Esempio n. 1
0
def ldim_third_left_button_press_cb(doc, event, tool):
    _loc = event.locationInWindow()
    _da = doc.getDA()
    _viewLoc = _da.convertPoint_fromView_(_loc, None)
    _ldim = tool.getDimension()
    _ldim.setLocation(_viewLoc.x, _viewLoc.y)
    _ldim.calcDimValues()
    _ldim.reset()
    CocoaEntities.create_entity(doc, tool)
Esempio n. 2
0
def cline_tan_2circ_third_left_button_press_cb(doc, event, tool):
    _loc = event.locationInWindow()
    _da = doc.getDA()
    _viewLoc = _da.convertPoint_fromView_(_loc, None)
    tool.setLocation(_viewLoc.x, _viewLoc.y)
    CocoaEntities.create_entity(doc, tool)
    # there's got to be a better way to do this,
    # but I give up.  Just redraw everything.
    _da.setNeedsDisplay_(True)
Esempio n. 3
0
def angular_fourth_left_button_press_cb(doc, event, tool):
    _loc = event.locationInWindow()
    _da = doc.getDA()
    (_x, _y) = _da.convertPoint_fromView_(_loc, None)
    _adim = tool.getDimension()
    _adim.setLocation(_x, _y)
    _adim.calcDimValues()
    _adim.reset()
    CocoaEntities.create_entity(doc, tool)
def ldim_third_left_button_press_cb(doc, event, tool):
    _loc = event.locationInWindow()
    _da = doc.getDA()
    _viewLoc = _da.convertPoint_fromView_(_loc, None)
    _ldim = tool.getDimension()
    _ldim.setLocation(_viewLoc.x, _viewLoc.y)
    _ldim.calcDimValues()
    _ldim.reset()
    CocoaEntities.create_entity(doc, tool)
def angular_fourth_left_button_press_cb(doc, event, tool):
    _loc = event.locationInWindow()
    _da = doc.getDA()
    (_x, _y) = _da.convertPoint_fromView_(_loc, None)
    _adim = tool.getDimension()
    _adim.setLocation(_x, _y)
    _adim.calcDimValues()
    _adim.reset()
    CocoaEntities.create_entity(doc, tool)
Esempio n. 6
0
def cline_tan_left_button_press_cb(doc, event, tool):
    _loc = event.locationInWindow()
    _da = doc.getDA()
    _viewLoc = _da.convertPoint_fromView_(_loc, None)
    _tol = _da.pointSize().width
    _image = doc.getImage()
    _pt, _new_pt = _image.findPoint(_viewLoc.x, _viewLoc.y, _tol)
    if _pt is not None:
        _x, _y = _pt.getCoords()
        _layer = _image.getActiveLayer()
        _rtd = 180.0/pi
        # I think this is just supposed to be active layer
        _cobj = None
        _angle = None
        _circles = (_layer.getLayerEntities("circle") +
                    _layer.getLayerEntities("ccircle"))
        for _circle in _circles:
            _cx, _cy = _circle.getCenter().getCoords()
            _rad = _circle.getRadius()
            if hypot((_x - _cx), (_y - _cy)) - _rad < 1e-10:
                _cobj = _circle
                _angle = _rtd * atan2((_y - _cy), (_x - _cx))
                if _angle < 0.0:
                    _angle = _angle + 360.0
                break
        if _cobj is None:
            for _arc in _layer.getLayerEntities("arc"):
                _cx, _cy = _arc.getCenter().getCoords()
                _rad = _arc.getRadius()
                if hypot((_cx - _x), (_cy - _y)) - _rad < 1e-10:
                    _angle = _rtd * atan2((_y - _cy), (_x - _cx))
                    if _angle < 0.0:
                        _angle = _angle + 360.0
                    if _arc.throughAngle(_angle):
                        _cobj = _arc
                        break
        if _cobj is not None:
            if _new_pt:
                _image.addObject(_pt)
            if (abs(_angle) < 1e-6 or
                abs(_angle - 180.0) < 1e-6 or
                abs(_angle - 360.0) < 1e-6):
                _tcl = PythonCAD.Generic.vcline.VCLine(_pt)
            elif (abs(_angle - 90.0) < 1e-6 or
                  abs(_angle - 270.0) < 1e-6):
                _tcl = PythonCAD.Generic.hcline.HCLine(_pt)
            else:
                _slope = _angle + 90.0
                _tcl = PythonCAD.Generic.acline.ACLine(_pt, _slope)
            _image.addObject(_tcl)
            # we have to call another function to generate
            # an event to flush out the notification system
            # and draw what we just added.  This one works
            # ok, I guess.
            CocoaEntities.create_entity(doc, tool)
            return   
Esempio n. 7
0
def cline_par_second_left_button_press_cb(doc, event, tool):
    _x1, _y1 = tool.getLocation()
    _loc = event.locationInWindow()
    _da = doc.getDA()
    _sp = _da.convertPoint_fromView_(_loc, None)
    _x2, _y2 = _sp
    _offset = hypot((_x2 - _x1), (_y2 - _y1))
    tool.setOffset(_offset)
    tool.setReferencePoint(_sp.x, _sp.y)
    CocoaEntities.create_entity(doc, tool)
Esempio n. 8
0
def ccircle_final_left_button_press_cb(doc, event, tool):
    _loc = event.locationInWindow()
    _da = doc.getDA()
    _viewLoc = _da.convertPoint_fromView_(_loc, None)
    _tol = _da.pointSize().width
    _image = doc.getImage()
    _pt, _flag = _image.findPoint(_viewLoc.x, _viewLoc.y, _tol)
    if _pt is not None:
        _x, _y = _pt.getCoords()
        _viewLoc = NSMakePoint(_x, _y)
    tool.setLocation(_viewLoc.x, _viewLoc.y)
    CocoaEntities.create_entity(doc, tool)
Esempio n. 9
0
def acline_second_left_button_press_cb(doc, event, tool):
    _loc = event.locationInWindow()
    _da = doc.getDA()
    _sp = _da.convertPoint_fromView_(_loc, None)
    tool.setLocation(_sp.x, _sp.y)
    CocoaEntities.create_entity(doc, tool)
Esempio n. 10
0
def vcline_entry_event_cb(doc, text, tool):
    if len(text):
        _x, _y = CocoaEntities.make_tuple(text)
        tool.setPoint(_x, _y)
        CocoaEntities.create_entity(doc, tool)
Esempio n. 11
0
def vcline_left_button_press_cb(doc, event, tool):
    _loc = event.locationInWindow()
    _da = doc.getDA()
    _viewLoc = _da.convertPoint_fromView_(_loc, None)
    tool.setPoint(_viewLoc.x, _viewLoc.y)
    CocoaEntities.create_entity(doc, tool)
Esempio n. 12
0
def cline_perp_left_button_press_cb(doc, event, tool):
    _loc = event.locationInWindow()
    _da = doc.getDA()
    _viewLoc = _da.convertPoint_fromView_(_loc, None)
    _tol = _da.pointSize().width
    _image = doc.getImage()
    _layer = _image.getActiveLayer()
    _hits = _layer.mapPoint((_viewLoc.x, _viewLoc.y), _tol, 1)
    if len(_hits):
        _obj, _pt = _hits[0]
        _lp = _layer.findObject(_pt)
        if _lp is None:
            _lp = _pt
            _image.addObject(_lp)
        if isinstance(_obj, PythonCAD.Generic.segment.Segment):
            _p1, _p2 = _obj.getEndpoints()
            _p1x, _p1y = _p1.getCoords()
            _p2x, _p2y = _p2.getCoords()
            if abs(_p1x - _p2x) < 1e-10: # vertical
                _image.addObject(PythonCAD.Generic.hcline.HCLine(_lp))
            elif abs(_p1y - _p2y) < 1e-10: # horizontal
                _image.addObject(PythonCAD.Generic.vcline.VCLine(_lp))
            else:
                _slope = (180.0/pi) * atan2((_p2y - _p1y),
                                            (_p2x - _p1x)) + 90.0
                _image.addObject(PythonCAD.Generic.acline.ACLine(_lp, _slope))
        elif isinstance(_obj, PythonCAD.Generic.circle.Circle):
            _cp = _obj.getCenter()
            _image.addObject(PythonCAD.Generic.cline.CLine(_cp, _lp))
        elif isinstance(_obj, PythonCAD.Generic.hcline.HCLine):
            _image.addObject(PythonCAD.Generic.vcline.VCLine(_lp))
        elif isinstance(_obj, PythonCAD.Generic.vcline.VCLine):
            _image.addObject(PythonCAD.Generic.hcline.HCLine(_lp))
        elif isinstance(_obj, PythonCAD.Generic.acline.ACLine):
            _angle = _obj.getAngle()
            if abs(_angle) < 1e-10: # horizontal
                _image.addObject(PythonCAD.Generic.vcline.VCLine(_lp))
            elif abs(abs(_angle) - 90.0) < 1e-10: # vertical
                _image.addObject(PythonCAD.Generic.hcline.HCLine(_lp))
            else:
                _slope = _angle + 90.0
                _image.addObject(PythonCAD.Generic.acline.ACLine(_lp, _slope))
        elif isinstance(_obj, PythonCAD.Generic.cline.CLine):
            _p1, _p2 = _obj.getKeypoints()
            _p1x, _p1y = _p1.getCoords()
            _p2x, _p2y = _p2.getCoords()
            if abs(_p1x - _p2x) < 1e-10: # vertical
                _image.addObject(PythonCAD.Generic.hcline.HCLine(_lp))
            elif abs(_p1y - _p2y) < 1e-10: # horizontal
                _image.addObject(PythonCAD.Generic.vcline.VCLine(_lp))
            else:
                _slope = (180.0/pi) * atan2((_p2y - _p1y),
                                            (_p2x - _p1x)) + 90.0
                _image.addObject(PythonCAD.Generic.acline.ACLine(_lp, _slope))
        else:
            _image.delObject(_lp)
            return
        # we have to call another function to generate
        # an event to flush out the notification system
        # and draw what we just added.  This one works
        # ok, I guess.
        CocoaEntities.create_entity(doc, tool)
Esempio n. 13
0
def acline_second_entry_event_cb(doc, text, tool):
    if len(text):
        _angle = CocoaEntities.make_angle(text)
        tool.setAngle(_angle)
        CocoaEntities.create_entity(doc, tool)