def drawArc_(self, sender): _doc = self.getCurrentDocument() if _doc is None: return _tool = tools.ArcTool() _doc.setTool(_tool) CocoaEntities.arc_center_mode_init(_doc, _tool)
def drawCircleCentered_(self, sender): _doc = self.getCurrentDocument() if _doc is None: return _tool = tools.CircleTool() _doc.setTool(_tool) CocoaEntities.circle_center_mode_init(_doc, _tool)
def drawCircle2Point_(self, sender): _doc = self.getCurrentDocument() if _doc is None: return _tool = tools.TwoPointCircleTool() _doc.setTool(_tool) CocoaEntities.circle_tp_mode_init(_doc, _tool)
def drawLeader_(self, sender): _doc = self.getCurrentDocument() if _doc is None: return _tool = tools.LeaderTool() _doc.setTool(_tool) CocoaEntities.leader_mode_init(_doc, _tool)
def drawRect_(self, sender): _doc = self.getCurrentDocument() if _doc is None: return _tool = tools.RectangleTool() _doc.setTool(_tool) CocoaEntities.rectangle_mode_init(_doc, _tool)
def drawPolyline_(self, sender): _doc = self.getCurrentDocument() if _doc is None: return _tool = tools.PolylineTool() _doc.setTool(_tool) CocoaEntities.polyline_mode_init(_doc, _tool)
def drawFillet_(self, sender): _doc = self.getCurrentDocument() if _doc is None: return _tool = tools.Tool() _doc.setTool(_tool) CocoaEntities.fillet_mode_init(_doc, _tool)
def drawPolygon_(self, sender): _doc = self.getCurrentDocument() if _doc is None: return _tool = tools.PolygonTool() _doc.setTool(_tool) self.openPolygonPanel() CocoaEntities.polygon_mode_init(_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)
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 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)
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
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)
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)
def cline_tp_first_entry_event_cb(doc, text, tool): if len(text): _x, _y = CocoaEntities.make_tuple(text) tool.setFirstPoint(_x, _y) tool.setHandler("mouse_move", cline_tp_mouse_move_cb) tool.setHandler("left_button_press", cline_tp_second_left_button_press_cb) tool.setHandler("entry_event", cline_tp_second_entry_event_cb) doc.setPrompt("Click in the drawing area or enter the second point as 'x, y'") doc.getDA().setTempPoint(NSMakePoint(_x, _y))
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)
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)
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)
def ccircle_tp_first_entry_event_cb(doc, text, tool): if len(text): CocoaEntities.circle_tp_first_entry_event_cb(doc, text, tool) tool.setHandler("mouse_move", ccircle_tp_mouse_move_cb)
def ccircle_tp_first_left_button_press_cb(doc, event, tool): CocoaEntities.circle_tp_first_left_button_press_cb(doc, event, tool) tool.setHandler("mouse_move", ccircle_tp_mouse_move_cb)
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)
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)