Ejemplo n.º 1
0
 def Back(self):
     """
     Use it after operation is done.
     Set previous current subpicture before operation.
     if view was set as current,subview and component would be created automatically
     """
     if len(self.Pre)==0:    #Empty: Define as automatic
         kcs_draft.subpicture_current_set()
     else:
         kcs_draft.subpicture_current_set(self.Pre[2])
Ejemplo n.º 2
0
 def Set(self,hd):
     """
     User it before draw operation.
     Or the subpicture of the drawing will be chaos.
     """
     #set current subpicture same as given handle.
     if not kcs_draft.element_is_subpicture(hd):
         father=kcs_draft.element_parent_get(hd)
         kcs_draft.subpicture_current_set(father)
     #only subpicture can be set as current.
     else:
         kcs_draft.subpicture_current_set(hd)
Ejemplo n.º 3
0
def CreateForm():
    "create a form with n pages."
    #check whether view exist.
    ViewName = 'KT_FORM'
    for view in ktDraft.GetViews():
        if view[1] == 'KT_FORM':
            print 'view already exist.'
            return
    hd = kcs_draft.view_new(ViewName)
    res = kcs_ui.int_req("How many pages do you want?", 1)
    if res[0] == kcs_util.ok():
        for i in range(res[1]):
            pg = Page()
            pg.Location = Point2D(i * 420, 0)
            pg.Index = i + 1
            kcs_draft.subpicture_current_set(hd)
            pg.Draw()
    kcs_draft.dwg_purge()
Ejemplo n.º 4
0
def GetKtComponent(compName, subView): #obsolete, do not use it.
    """返回指定名称的component,若没有则新建一个"""
    # subView=GetTitSubView(subViewName)
    name = kcs_draft.subpicture_name_get(subView)
    try:
        comp = kcs_draft.element_child_first_get(subView)
        name = kcs_draft.subpicture_name_get(comp)
        if name == compName:
            return comp
        while True:
            comp = kcs_draft.element_sibling_next_get(comp)
            name = kcs_draft.subpicture_name_get(comp)
            kcs_ui.message_noconfirm(name)
            if name == compName:
                return comp
    except:
        old = kcs_draft.subpicture_current_get()
        kcs_draft.subpicture_current_set(subView)
        comp = kcs_draft.component_new(compName)
        if len(old) == 3:
            kcs_draft.subpicture_current_set(old[2])
        return comp
Ejemplo n.º 5
0
    def Draw(self):
        "draw the drawing form on current drawing"
        #check whether view exist
        hd = kcs_draft.subview_new('KT_FORM%s' % (self.Index))
        kcs_draft.subpicture_current_set(hd)
        hd = kcs_draft.component_new('FORM_CONTOUR')
        kcs_draft.subpicture_current_set(hd)

        #drawing form lines
        #outer rectangle
        lm = LineMaker(self.Location.X, self.Location.Y)
        lm.LineX(self.Width)
        lm.LineY(self.Height)
        lm.LineX(-self.Width)
        lm.LineY(-self.Height)
        #inner rectangle
        lm.Move(self.PaddingLeft, self.PaddingBottom)
        lm.LineX(self.Width - self.PaddingRight - self.PaddingLeft)
        lm.LineY(self.Height - self.PaddingBottom - self.PaddingTop)
        lm.LineX(-self.Width + self.PaddingRight + self.PaddingLeft)
        lm.LineY(-self.Height + self.PaddingBottom + self.PaddingTop)
        #onter lines
        lm.MoveTo(self.Location.X + self.PaddingLeft,
                  self.Location.Y + self.Height - self.PaddingTop - 13)
        lm.LineX(60)
        lm.LineY(13)
        lm.MoveTo(self.Location.X + self.Width - self.PaddingRight,
                  self.Location.Y + self.Height - self.PaddingTop - 13)
        lm.LineX(-14)
        lm.LineY(13)
        lm.MoveY(-13)
        lm.LineX(-46)
        lm.LineY(13)
        lm.MoveY(-13)
        lm.LineX(-65)
        lm.LineY(13)
        lm.Move(111, -13)
        lm.Line(14, 13)
Ejemplo n.º 6
0
def FormatSingle():
    pt = Point2D()
    res = kcs_ui.point2D_req("请选择文字获取文字属性", pt)
    if res[0] == kcs_util.ok():
        hd = kcs_draft.text_identify(pt)
        ori = Text()
        kcs_draft.text_properties_get(hd, ori)
#         old = kcs_draft.subpicture_current_get()  # 当前图层
        while True:
            "select single text"
            pt2=Point2D()
            res = kcs_ui.point2D_req("请选择要替换的文字", pt2)
            if res[0]==kcs_util.ok():
                hdText=kcs_draft.text_identify(pt2)
                father = kcs_draft.element_parent_get(hdText)  # 文字所在图层
                t = Text()
                kcs_draft.text_properties_get(hdText, t)
                ori.SetString(t.GetString())
                ori.SetPosition(t.GetPosition())
                kcs_draft.element_delete(hdText)  # 删除原文字
                kcs_draft.subpicture_current_set(father)  # 重设图层
                kcs_draft.text_new(ori)  # 写文字
            else:
                break
Ejemplo n.º 7
0
def ReplaceOne(hdText):
    "replace one text"
    txt=Text()
    kcs_draft.text_properties_get(hdText,txt)
    res=kcs_ui.string_req('请输入要替换的文本',txt.String)
    if res[0]==kcs_util.ok():
        old = kcs_draft.subpicture_current_get() #make the old subpicture
        father = kcs_draft.element_parent_get(hdText)  # 文字所在图层
        txt.SetString(res[1])
        kcs_draft.element_delete(hdText)  # 删除原文字
        kcs_draft.subpicture_current_set(father)  # 重设图层
        kcs_draft.text_new(txt)  # 写文字
        if len(old) == 3:
            kcs_draft.subpicture_current_set(old[2])
        else:
            kcs_draft.subpicture_current_set()
Ejemplo n.º 8
0
    def Draw(self):
        "Draw the cell on drawing."
#         if self.Handle!=None: #clear the cell first
#             for ee in ktDraft.GetSubElements(self.Handle):
#                 print ee
#                 kcs_draft.element_delete(ee)
#         else:
#             # !make sure the parrent sub view is set current
        if self.Handle!=None:
            prt=kcs_draft.element_parent_get(self.Handle)
            kcs_draft.element_delete(self.Handle)
            kcs_draft.subpicture_current_set(prt)
        self.Handle=kcs_draft.component_new(self.GetCompName())
        kcs_draft.subpicture_current_set(self.Handle)
        if len(self.String)>0:
            kcs_draft.text_new(self.GetText())
        kcs_draft.rectangle_new(self.Rect)
        kcs_draft.subpicture_current_set()
Ejemplo n.º 9
0
def Replace(hdList):
    res = kcs_ui.answer_req("文字替换", "是否要替换文字?")
    if res == kcs_util.yes():
        txt = Text()
        kcs_draft.text_properties_get(hdList[0], txt)
        res = kcs_ui.string_req("请输入要替换的文字", txt.GetString())
        if res[0] == kcs_util.ok():
            content = res[1]
            old = kcs_draft.subpicture_current_get()
            for hd in hdList:
                father = kcs_draft.element_parent_get(hd)  # 文字所在图层
                kcs_draft.text_properties_get(hd, txt)
                txt.SetString(content)
                kcs_draft.element_delete(hd)  # 删除原文字
                kcs_draft.subpicture_current_set(father)  # 重设图层
                kcs_draft.text_new(txt)  # 写文字
            if len(old) == 3:
                kcs_draft.subpicture_current_set(old[2])
            else:
                kcs_draft.subpicture_current_set()
Ejemplo n.º 10
0
def FormatRegion():
    pt = Point2D()
    res = kcs_ui.point2D_req("请选择文字获取文字属性", pt)
    if res[0] == kcs_util.ok():
        hd = kcs_draft.text_identify(pt)
        ori = Text()
        kcs_draft.text_properties_get(hd, ori)
        objs = SelectTexts()
        old = kcs_draft.subpicture_current_get()  # 当前图层
        for obj in objs[1:]:  # 重写文字
            father = kcs_draft.element_parent_get(obj)  # 文字所在图层
            t = Text()
            kcs_draft.text_properties_get(obj, t)
            ori.SetString(t.GetString())
            ori.SetPosition(t.GetPosition())
            kcs_draft.element_delete(obj)  # 删除原文字
            kcs_draft.subpicture_current_set(father)  # 重设图层
            kcs_draft.text_new(ori)  # 写文字
        if len(old) == 3:
            kcs_draft.subpicture_current_set(old[2])
        else:
            kcs_draft.subpicture_current_set()
Ejemplo n.º 11
0
 def Draw(self):
     "Draw table on current drawing"
     if self.Handle==None:   #create a new view for this table
         #get the max index and create view
         tbViews=ktDraft.GetViews(r'^KT_TABLE_.\d*$')
         maxIndex=1
         if len(tbViews)>0:
             maxIndex=max([int(i[1][9:]) for i in tbViews])+1
         viewName='KT_TABLE_%s'%(maxIndex)
         self.Handle=kcs_draft.view_new(viewName)
         kcs_draft.subpicture_current_set(self.Handle)
         
         #create subview
         subName='KT%sX%s'%(self.NColumn,self.NRow)
         hdSub=kcs_draft.subview_new(subName)
         
         #create component for cells
         for c in self.Cells:
             kcs_draft.subpicture_current_set(hdSub)
             c.Draw()
     else:
         for c in self.Cells:
             c.Draw()
     kcs_draft.subpicture_current_set()
Ejemplo n.º 12
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()