Exemple #1
0
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)
Exemple #2
0
def PrintColors():
    colors=KcsColour.ColourStrings
    pos=0
    for i in range(len(colors)):
        col=KcsColour.Colour(colors[i])
        kcs_draft.colour_set(col)
        
        p1=Point2D(0,pos)
        p2=Point2D(100,pos)
        ln=Rline2D(p1,p2)
        kcs_draft.line_new(ln)
        kcs_draft.text_new(colors[i],Point2D(p2.X+20,p2.Y))
        
        pos+=20
Exemple #3
0
def SetUnderline():
    "add underline for text"
    hdText=SelectText()
    if hdText!=None:
        csm=ktDraft.CurrentSubpictureManager()
        rect=kcs_draft.element_extent_get(hdText)
        #begin to draw underline
        x1=min(rect.Corner1.X,rect.Corner2.X)
        x2=max(rect.Corner1.X,rect.Corner2.X)
        y=min(rect.Corner1.Y,rect.Corner2.Y)-1
        csm.Set(hdText)
        line=Rline2D(Point2D(x1,y),Point2D(x2,y))
        kcs_draft.line_new(line)
        csm.Back()
Exemple #4
0
def PrintColors():
    colors = KcsColour.ColourStrings
    pos = 0
    for i in range(len(colors)):
        col = KcsColour.Colour(colors[i])
        kcs_draft.colour_set(col)

        p1 = Point2D(0, pos)
        p2 = Point2D(100, pos)
        ln = Rline2D(p1, p2)
        kcs_draft.line_new(ln)
        kcs_draft.text_new(colors[i], Point2D(p2.X + 20, p2.Y))

        pos += 20
Exemple #5
0
def Grid():
    """Create a grid on a new view"""
    res=kcs_ui.string_req('请输入格子的长,宽、列数,行数','30,10,8,5')
    if res[0]==kcs_util.ok():
        w,h,m,n=[float(i) for i in res[1].split(',')]
        pt=Point2D()
        res=kcs_ui.point2D_req('请选择Grid左上角位置,回车设为原点',pt)
        if res[0]==kcs_util.ok():
            csm=CurrentSubpictureManager()
            hd=kcs_draft.view_new('')
            csm.Set(hd)
            for i in range(n+1):    #horizontal line
                p1=Point2D(pt.X,pt.Y-h*i)
                p2=Point2D(pt.X+w*m,pt.Y-h*i)
                kcs_draft.line_new(Rline2D(p1,p2))
            for j in range(m+1):    #vertical line
                p1=Point2D(pt.X+j*w,pt.Y)
                p2=Point2D(pt.X+j*w,pt.Y-h*n)
                kcs_draft.line_new(Rline2D(p1,p2))
            csm.Back()
        elif res[0]==kcs_util.operation_complete():
            pt=Point2D(0,0)
            csm=CurrentSubpictureManager()
            hd=kcs_draft.view_new('')
            csm.Set(hd)
            for i in range(n+1):    #horizontal line
                p1=Point2D(pt.X,pt.Y-h*i)
                p2=Point2D(pt.X+w*m,pt.Y-h*i)
                kcs_draft.line_new(Rline2D(p1,p2))
            for j in range(m+1):    #vertical line
                p1=Point2D(pt.X+j*w,pt.Y)
                p2=Point2D(pt.X+j*w,pt.Y-h*n)
                kcs_draft.line_new(Rline2D(p1,p2))
            csm.Back()
def PrintLinetypes():
    tps = KcsLinetype.GetLinetypes()
    pos = 0
    for i in range(len(tps)):
        msg(i)
        tp = tps.keys()[i]
        name = KcsLinetype.GetSystemName(tp)
        lt = KcsLinetype.Linetype(name)
        kcs_draft.linetype_set(lt)

        p1 = Point2D(0, pos)
        p2 = Point2D(100, pos)
        ln = Rline2D(p1, p2)
        kcs_draft.line_new(ln)
        kcs_draft.text_new(name, Point2D(p2.X + 20, p2.Y))

        pos += 20
Exemple #7
0
def Arrow(start,end,size=2.5,angle=15):
    #distance can't less than size
    if start.DistanceToPoint(end)<=size:
        raise 'Given points is too close.'
    length=start.DistanceToPoint(end)
    scale=(length-size)/size
    x=(start.X+scale*end.X)/(1+scale)
    y=(start.Y+scale*end.Y)/(1+scale)
    theta=GetAngle(start, end)
    d=size*math.tan(math.radians(angle))
    dx=d*math.sin(theta)
    dy=d*math.cos(theta)
    p3=Point2D(x+dx,y-dy)
    p4=Point2D(x-dx,y+dy)
    
    kcs_draft.line_new(Rline2D(start, end))
    kcs_draft.line_new(Rline2D(p3, end))
    kcs_draft.line_new(Rline2D(p4, end))
    kcs_draft.line_new(Rline2D(p3, p4))
Exemple #8
0
def NewArrow(start, end, size=2.5, angle=15):
    """画水平箭头"""
    arrowHeight = math.tan(angle * math.pi / 180) * size
    
    line = Rline2D(start, end)
    kcs_draft.line_new(line)
    
    pt = Point2D()
    pt.X = end.X - size
    pt.Y = end.Y + arrowHeight
    line = Rline2D(end, pt)
    kcs_draft.line_new(line)
    
    pt2 = Point2D()
    pt2.X = pt.X
    pt2.Y = pt.Y - 2 * arrowHeight
    line = Rline2D(pt, pt2)
    kcs_draft.line_new(line)
    
    line = Rline2D(pt2, end)
    kcs_draft.line_new(line)
Exemple #9
0
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()
Exemple #10
0
def DrawLines(pts):
    """connect all points"""
    for i in range(len(pts)-1):
        kcs_draft.line_new(Rline2D(pts[i],pts[i+1]))
    kcs_draft.line_new(Rline2D(pts[0],pts[-1]))
Exemple #11
0
 def LineTo(self,x,y):
     "create new line from current point to given x and y"
     end=Point2D(x,y)
     line=Rline2D(self.Sta,end)
     kcs_draft.line_new(line)
     self.Sta=end