def CircleArrow(start,end,size=1.2): """draw a arrow with circle at the end.""" #distance can't less than size if start.DistanceToPoint(end)<=size: raise 'Given points is too close.' kcs_draft.line_new(Rline2D(start, end)) c=Circle2D(end,size) kcs_draft.circle_new(c)
def AddNote(): res=kcs_ui.string_req("请输入标注内容") if res[0]==kcs_util.ok(): content=res[1] cor1=Point2D() cor2=Point2D() res=kcs_ui.point2D_req("请选择标注点",cor1) if res[0]==kcs_util.ok(): res=kcs_ui.point2D_req("请选择标注文字位置",cor2) if res[0]==kcs_util.ok(): #开始标注 #记录原来状态 old=kcs_draft.subpicture_current_get() #创建component subView=ktDraft.GetKtSubView(SUB_VIEW_NAME) #检查是否在KNOT_VIEW下 parent=kcs_draft.element_parent_get(subView) parentName=kcs_draft.subpicture_name_get(parent) if parentName!="KNOT_VIEW": return kcs_draft.subpicture_current_set(subView) compName="NOTE_"+str(GetID(subView)) comp=kcs_draft.component_new(compName) kcs_draft.subpicture_current_set(comp) #写文字 txt=Text(content) txt.SetPosition(cor2) txt.SetColour(Colour("Red")) txt.SetFont("黑体") txt.SetHeight(5) hTxt=kcs_draft.text_new(txt) #画边框 rect=Rectangle2D() rect=kcs_draft.element_extent_get(hTxt) offset=1 rect.SetCorner1(Point2D(rect.Corner1.X-offset,rect.Corner1.Y-offset)) rect.SetCorner2(Point2D(rect.Corner2.X+offset,rect.Corner2.Y+offset)) hd=kcs_draft.rectangle_new(rect) kcs_draft.element_colour_set(hd,Colour("Red")) #画引线 sta=cor1 end=rect.GetCorner1() if end.X<sta.X: end.SetX(end.X+rect.Corner2.X-rect.Corner1.X) if end.Y<sta.Y: end.SetY(end.Y+rect.Corner2.Y-rect.Corner1.Y) line=Rline2D(sta,end) hd=kcs_draft.line_new(line) kcs_draft.element_colour_set(hd,Colour("Red")) #画圆圈 circle=Circle2D(sta,2) hd=kcs_draft.circle_new(circle) kcs_draft.element_colour_set(hd,Colour("Red")) #恢复原来状态 if len(old)==3: kcs_draft.subpicture_current_set(old[2]) else: kcs_draft.subpicture_current_set()
def Circle(self,r): "create a circle at current point." c=Circle2D(self.Sta,r) kcs_draft.circle_new(c)