def c_arc(par,x0,y0,xr1=None, yr1=None, xr2=None, yr2=None, width = None, sloy = None, fill = None, R = None, start = None, extent = None, ID = None, temp = None): if sloy == None: fill = par.color width = par.width sloy = par.sloy width = int(width) if not temp: if not ID: par.Narcd+=1 ID = par.Narc = 'a' + str(par.Narcd) if R == None: R = sqrt((xr1-x0)*(xr1-x0) + (yr1-y0)*(yr1-y0)) x1=x0-R x2=x0+R y1=y0-R y2=y0+R s = R/20.0 R = par.n_coordinator(R) id_dict = {} if start == None: aa = degrees(calc_angle(x0, y0, x2, y0, xr1, yr1)) bb = degrees(calc_angle(x0, y0, xr1, yr1, xr2, yr2)) else: aa = start bb = extent if aa < 0: aa = 360 - abs(aa) id = par.c.create_arc(x1,y1,x2,y2, start = aa, extent = bb, outline=fill, full=None,width=width,style = 'arc', tags = ('obj', ID))#['arc', par.Narc, 'a', 'obj', 'priv', sloy]) id_dict[id] = ('a', 'priv') id = par.c.create_line(x0-s,y0-s,x0+s,y0+s,fill=fill,tags = ('obj', ID, 'a_centr'))#['arc', par.Narc, 'line', 'a_centr', 'obj', 'priv', sloy]) id_dict[id] = ('line', 'priv', 'a_centr') id = par.c.create_line(x0+s,y0-s,x0-s,y0+s,fill=fill,tags = ('obj', ID, 'a_centr'))#['arc', par.Narc, 'line', 'a_centr', 'obj', 'priv', sloy]) id_dict[id] = ('line', 'priv', 'a_centr') par.ALLOBJECT[ID]={'object':'arc', 'fill':fill, 'width':width, 'sloy':sloy, 'start':aa, 'extent':bb, 'R':R, 'id':id_dict} else: if R == None: R = sqrt((xr1-x0)*(xr1-x0) + (yr1-y0)*(yr1-y0)) x1=x0-R x2=x0+R y1=y0-R y2=y0+R s = R/20.0 R = par.n_coordinator(R) if start == None: aa = degrees(calc_angle(x0, y0, x2, y0, xr1, yr1)) bb = degrees(calc_angle(x0, y0, xr1, yr1, xr2, yr2)) else: aa = start bb = extent if aa < 0: aa = 360 - abs(aa) par.c.create_arc(x1,y1,x2,y2, start = aa, extent = bb, outline=fill, full=None,width=width,style = 'arc', tags = ('obj', 'temp'))#['arc', par.Narc, 'a', 'obj', 'priv', sloy]) par.c.create_line(x0-s,y0-s,x0+s,y0+s,fill=fill,tags = ('obj', 'temp'))#['arc', par.Narc, 'line', 'a_centr', 'obj', 'priv', sloy]) par.c.create_line(x0+s,y0-s,x0-s,y0+s,fill=fill,tags = ('obj', 'temp'))#['arc', par.Narc, 'line', 'a_centr', 'obj', 'priv', sloy])
def tracer(par, x1, y1, x2, y2, snap_s, angle_s): angle = None x3 = x2 y3 = y1 i = 1 j = 1 if x2>x1: i = 1 elif x2<x1: i = -1 if y2>y1: j = 1 elif y2<y1: j = -1 if x1 == x2: angle = 90.0 if y1 == y2: angle = 0.0 if (x1, y1) == (x2, y2): return if angle == None: angle = abs(degrees(calc_angle(x1, y1, x3, y3, x2, y2))) a = 0 d = sqrt((x2-x1)**2 + (y2-y1)**2) while angle_s*a <= 90.0: if abs(angle)-snap_s/6.0 <= abs(angle_s*a) <= abs(angle)+snap_s/6.0: xi = cos(radians(angle_s*a))*d*10000.0*i + x1 yi = sin(radians(angle_s*a))*d*10000.0*j + y1 if 'trace' in par.ALLOBJECT: par.c.delete('text') par.c.create_text(x2+snap_s*2, y2+snap_s*2, fill = 'yellow', text = str(angle_s*a), tags = ('obj', 'trace', 'text')) a = None break else: id = par.c.create_line(x1, y1, xi, yi, fill = 'yellow', width = 1, tags = ('obj', 'trace')) par.c.create_text(x2+snap_s*2, y2+snap_s*2, fill = 'yellow', text = str(angle_s*a), tags = ('obj', 'trace', 'text')) id_dict = {id:('line', 'priv')} par.ALLOBJECT['trace'] = {'id':id_dict} a = None break else: a += 1 if a != None and 'trace' in par.ALLOBJECT: par.c.delete('trace') del par.ALLOBJECT['trace']
def editEvent2(self, event=None): delete_list = [] self.par.ex2 = self.par.priv_coord[0] self.par.ey2 = self.par.priv_coord[1] self.par.ex, self.par.ey = self.par.coordinator( self.par.ex, self.par.ey) self.par.set_coord() self.par.ex3 = None self.par.ey3 = None if self.par.ortoFlag == True and self.par.com == None: self.par.ex2, self.par.ey2 = self.par.orto(self.par.ex, self.par.ey, self.par.ex2, self.par.ey2) for content in self.par.collection: if content[0] == 'L': fill, width, sloy, stipple, coord, factor_stip = get_conf.get_line_conf( content, self.par) if coord[0] != coord[2]: if abs(coord[0] - self.par.ex) < self.par.min_e: if abs(coord[1] - self.par.ey) < self.par.min_e: coord[0] = self.par.ex2 coord[1] = self.par.ey2 self.par.ex3 = coord[2] self.par.ey3 = coord[3] elif abs(coord[2] - self.par.ex) < self.par.min_e: if abs(coord[3] - self.par.ey) < self.par.min_e: coord[2] = self.par.ex2 coord[3] = self.par.ey2 self.par.ex3 = coord[0] self.par.ey3 = coord[1] else: if abs(coord[1] - self.par.ey) < self.par.min_e: coord[0] = self.par.ex2 coord[1] = self.par.ey2 self.par.ex3 = coord[2] self.par.ey3 = coord[3] if abs(coord[3] - self.par.ey) < self.par.min_e: coord[2] = self.par.ex2 coord[3] = self.par.ey2 self.par.ex3 = coord[0] self.par.ey3 = coord[1] delete_list.append(content) if event: line.c_line(self.par, coord[0], coord[1], coord[2], coord[3], width=width, stipple=stipple, factor_stip=factor_stip, fill=fill, sloy=sloy) else: line.c_line(self.par, coord[0], coord[1], coord[2], coord[3], width=width, stipple=stipple, factor_stip=factor_stip, fill=fill, sloy=sloy, temp='Yes') if content[0] == 'd': text_prov = False fill = self.par.ALLOBJECT[content]['fill'] sloy = self.par.ALLOBJECT[content]['sloy'] text = self.par.ALLOBJECT[content]['text'] line1 = self.par.get_snap_line(content)[0] line2 = self.par.get_snap_line(content)[1] line3 = self.par.get_snap_line(content)[2] ort = self.par.ALLOBJECT[content]['ort'] size = self.par.ALLOBJECT[content]['size'] s = self.par.ALLOBJECT[content]['s'] vr_s = self.par.ALLOBJECT[content]['vr_s'] vv_s = self.par.ALLOBJECT[content]['vv_s'] arrow_s = self.par.ALLOBJECT[content]['arrow_s'] type_arrow = self.par.ALLOBJECT[content]['type_arrow'] s_s = self.par.ALLOBJECT[content]['s_s_dim'] w_text = self.par.ALLOBJECT[content]['w_text_dim'] font = self.par.ALLOBJECT[content]['font_dim'] coord_list = map(lambda i: self.par.c.coords(i), [line1, line2, line3]) if abs(coord_list[0][0] - self.par.ex) < self.par.min_e: if abs(coord_list[0][1] - self.par.ey) < self.par.min_e: coord_list[0] = [self.par.ex2, self.par.ey2] elif abs(coord_list[1][0] - self.par.ex) < self.par.min_e: if abs(coord_list[1][1] - self.par.ey) < self.par.min_e: coord_list[1] = [self.par.ex2, self.par.ey2] elif abs(coord_list[2][0] - self.par.ex) < self.par.min_e: coord_list[2] = [self.par.ex2, self.par.ey2] text_prov = True elif abs(coord_list[2][1] - self.par.ey) < self.par.min_e: coord_list[2] = [self.par.ex2, self.par.ey2] text_prov = True delete_list.append(content) if text_prov == True: text_change = self.par.ALLOBJECT[content]['text_change'] text_lines, priv_line, text_place = self.par.dim_text_place( content) if text_place[2] == 'hor': text_place[1] = self.par.ey + (self.par.ey2 - self.par.ey) else: text_place[0] = self.par.ex + (self.par.ex2 - self.par.ex) else: text_change = 'unchange' text_place = None if event: dimension.c_dim(self.par, coord_list[0][0], coord_list[0][1], coord_list[1][0], coord_list[1][1], coord_list[2][0], coord_list[2][1], text=text, sloy=sloy, fill=fill, size=size, ort=ort, text_change=text_change, text_place=text_place, s=s, vr_s=vr_s, vv_s=vv_s, arrow_s=arrow_s, type_arrow=type_arrow, s_s=s_s, w_text=w_text, font=font) else: dimension.c_dim(self.par, coord_list[0][0], coord_list[0][1], coord_list[1][0], coord_list[1][1], coord_list[2][0], coord_list[2][1], text=text, sloy=sloy, fill=fill, size=size, ort=ort, text_change=text_change, text_place=text_place, s=s, vr_s=vr_s, vv_s=vv_s, arrow_s=arrow_s, type_arrow=type_arrow, s_s=s_s, w_text=w_text, font=font, temp='Yes') if content[0] == 'r': xc, yc, x1, y1, size, fill, text, sloy, s, vr_s, arrow_s, type_arrow, s_s_dim, w_text_dim, font_dim, R = self.par.get_dimR_conf( content) x1 = self.par.ex2 y1 = self.par.ey2 delete_list.append(content) if event: dimension.c_dimR(self.par, xc, yc, x1, y1, Rn=R, text=text, sloy=sloy, fill=fill, size=size, s=s, vr_s=vr_s, arrow_s=arrow_s, type_arrow=type_arrow, s_s=s_s_dim, w_text=w_text_dim, font=font_dim) else: dimension.c_dimR(self.par, xc, yc, x1, y1, Rn=R, text=text, sloy=sloy, fill=fill, size=size, s=s, vr_s=vr_s, arrow_s=arrow_s, type_arrow=type_arrow, s_s=s_s_dim, w_text=w_text_dim, font=font_dim, temp='Yes') if content[0] == 'c': e = self.par.get_conf(content) x0 = e[1] y0 = e[2] R = sqrt((self.par.ex2 - x0)**2 + (self.par.ey2 - y0)**2) fill = e[4] width = e[5] sloy = e[6] delete_list.append(content) if event: circle.c_circle(self.par, x0, y0, fill=fill, width=width, sloy=sloy, R=R) else: circle.c_circle(self.par, x0, y0, fill=fill, width=width, sloy=sloy, R=R, temp='Yes') elif content[0] == 'a': find = self.par.ALLOBJECT[content]['id'] for i in find: tag = self.par.ALLOBJECT[content]['id'][i] if 'a' in tag: coord = self.par.c.coords(i) xc, yc, dx1, dy1, dx2, dy2, fill, width, sloy = get_arc_conf( content, self.par) ''' e = self.par.get_arc_conf(content) xc = e[1] yc = e[2] dx1 = e[3] dy1 = e[4] dx2 = e[5] dy2 = e[6] fill = e[7] width = e[8] sloy = e[9] ''' R = sqrt((dx1 - xc)**2 + (dy1 - yc)**2) if abs(self.par.ex - dx1) < self.par.min_e: if abs(self.par.ey - dy1) < self.par.min_e: dx1 = self.par.ex2 dy1 = self.par.ey2 elif abs(self.par.ex - dx2) < self.par.min_e: if abs(self.par.ey - dy2) < self.par.min_e: dx2 = self.par.ex2 dy2 = self.par.ey2 self.par.ex3 = xc self.par.ey3 = yc aa = degrees(calc_angle(xc, yc, coord[2], yc, dx1, dy1)) bb = degrees(calc_angle(xc, yc, dx1, dy1, dx2, dy2)) delete_list.append(content) if event: arc.c_arc(self.par, xc, yc, R=R, start=aa, extent=bb, fill=fill, width=width, sloy=sloy) else: arc.c_arc(self.par, xc, yc, R=R, start=aa, extent=bb, fill=fill, width=width, sloy=sloy, temp='Yes') if self.par.tracingFlag and self.par.ex3 != None: self.par.trace_on = True self.par.trace_x1, self.par.trace_y1 = self.par.ex3, self.par.ey3 self.par.trace_x2, self.par.trace_y2 = self.par.ex2, self.par.ey2 if event: if delete_list: self.par.delete(elements=delete_list) self.par.edit_clone = False self.par.c.delete('temp') self.par.changeFlag = True self.par.enumerator_p() self.par.collection = [] self.par.kill()
def c_dimR(par,x1,y1,x2,y2, text=None, sloy = None, fill = None, size = None, s=None, vr_s = None, arrow_s = None, type_arrow = None, s_s = None, w_text = None, font = None, Rn = None, temp = None): if sloy == None: sloy = par.sloy fill = par.color size = par.size_f s = old_s = par.s vr_s = old_vr_s = par.vr_s arrow_s = old_arrow_s = par.arrow_s type_arrow = par.type_arrow s_s = par.s_s_dim w_text = par.w_text_dim font = par.font_dim else: old_s = s old_vr_s = vr_s old_arrow_s = arrow_s if text == 'None': text = None if not temp: par.Ndimrd+=1 par.Ndimr = 'r' + str(par.Ndimrd) dx=x2-x1 dy=y2-y1 R = sqrt(dx*dx + dy*dy) id_dict = {} list_arrow = [] list_lines = [] list_text_lines = [] if par.zoomOLD==0: Rr = R else: if par.zoomOLD>0: s*=(zoomp**par.zoomOLD) arrow_s*=(zoomp**par.zoomOLD) vr_s*=(zoomp**par.zoomOLD) Rr=R*zoomm**par.zoomOLD else: zoomOLDx=par.zoomOLD*(-1) s/=(zoomp**zoomOLDx) arrow_s/=(zoomp**zoomOLDx) vr_s/=(zoomp**zoomOLDx) Rr=R*zoomp**zoomOLDx if Rn != None: Rr = Rn R = par.coordinator2(Rn) Rrr=format(Rr, '.0f') angle = abs(calc_angle(x1, y1, x2, y2, x1+R, y1)) i = 1 anchor = 'sw' if y2>y1: angle = -angle if x2<x1: i = -1 angle = angle-pi anchor = 'se' if text: textt = text else: textt = 'R ' + Rrr x1t = x1 + i*(R + arrow_s*2.0) y1t = y1 - s list_text_lines = symbols.font(x1t, y1t, textt, size, par.zoomOLD, s_s, w_text, anchor, font, 0) e = list_text_lines.nabor[0] if i > 0: list_lines.extend([[x1, y1, e[2], y1]]) else: list_lines.extend([[x1, y1, e[0], y1]]) if type_arrow == 'Arch': L1 = [x1+i*(R-arrow_s), y1+arrow_s, x1+i*(R+arrow_s), y1-arrow_s] list_arrow.extend([L1,]) elif type_arrow == 'Arrow': L1 = [x1+i*R,y1,x1+i*(R-arrow_s),y1-arrow_s/10.0] L2 = [x1+i*R,y1,x1+i*(R-arrow_s),y1+arrow_s/10.0] list_arrow.extend([L1, L2]) list_text_lines.nabor = rotate_lines(x1, y1, list_text_lines.nabor, angle) list_arrow = rotate_lines(x1, y1, list_arrow, angle) list_lines = rotate_lines(x1, y1, list_lines, angle) for i in list_arrow: id = par.c.create_line(i, fill=fill, tags = ('obj', par.Ndimr, 'sel')) id_dict[id] = ('line',) for i in list_lines: id = par.c.create_line(i, fill=fill, tags = ('obj', par.Ndimr, 'sel')) id_dict[id] = ('line', 'priv') for i in list_text_lines.nabor[1:]: try: id = par.c.create_line(i[0],i[1],i[2],i[3],fill=fill, tags = ('obj', par.Ndimr, 't_LOD', 'sel')) id_dict[id] = ('line', 'dim_text') except: pass snap_text = list_text_lines.nabor[0] id = par.c.create_line(snap_text[0],snap_text[1],snap_text[2],snap_text[3], width=8, fill = fill, stipple = ('@'+path.join(par.appPath, 'res', '00.xbm')), tags = ('obj', par.Ndimr, 'snap_text', 'sel')) id_dict[id] = ('line', 'priv', 'dim_text', 'dim_text_priv') par.ALLOBJECT[par.Ndimr]={'text':text,#Записать в ALLOBJECT параметры размера 'angle':angle, 'object':'dimr', 'fill':fill, 'size':size, 'sloy':sloy, 's' : old_s, 'R' : Rr, 'vr_s': old_vr_s, 'arrow_s': old_arrow_s, 'type_arrow':type_arrow, 's_s_dim':s_s, 'w_text_dim':w_text, 'font_dim':font, 'id':id_dict} else: dx=x2-x1 dy=y2-y1 R = sqrt(dx*dx + dy*dy) list_arrow = [] list_lines = [] list_text_lines = [] if par.zoomOLD==0: Rr = R else: if par.zoomOLD>0: s*=(zoomp**par.zoomOLD) arrow_s*=(zoomp**par.zoomOLD) vr_s*=(zoomp**par.zoomOLD) Rr=R*zoomm**par.zoomOLD else: zoomOLDx=par.zoomOLD*(-1) s/=(zoomp**zoomOLDx) arrow_s/=(zoomp**zoomOLDx) vr_s/=(zoomp**zoomOLDx) Rr=R*zoomp**zoomOLDx if Rn != None: Rr = Rn R = par.coordinator2(Rn) Rrr=format(Rr, '.0f') angle = abs(calc_angle(x1, y1, x2, y2, x1+R, y1)) i = 1 anchor = 'sw' if y2>y1: angle = -angle if x2<x1: i = -1 angle = angle-pi anchor = 'se' if text: textt = text else: textt = 'R ' + Rrr x1t = x1 + i*(R + arrow_s*2.0) y1t = y1 - s list_text_lines = symbols.font(x1t, y1t, textt, size, par.zoomOLD, s_s, w_text, anchor, font, 0) e = list_text_lines.nabor[0] if i > 0: list_lines.extend([[x1, y1, e[2], y1]]) else: list_lines.extend([[x1, y1, e[0], y1]]) if type_arrow == 'Arch': L1 = [x1+i*(R-arrow_s), y1+arrow_s, x1+i*(R+arrow_s), y1-arrow_s] list_arrow.extend([L1,]) elif type_arrow == 'Arrow': L1 = [x1+i*R,y1,x1+i*(R-arrow_s),y1-arrow_s/10.0] L2 = [x1+i*R,y1,x1+i*(R-arrow_s),y1+arrow_s/10.0] list_arrow.extend([L1, L2]) list_text_lines.nabor = rotate_lines(x1, y1, list_text_lines.nabor, angle) list_arrow = rotate_lines(x1, y1, list_arrow, angle) list_lines = rotate_lines(x1, y1, list_lines, angle) for i in list_arrow: par.c.create_line(i, fill=fill, tags = ('obj', 'temp')) for i in list_lines: par.c.create_line(i, fill=fill, tags = ('obj', 'temp')) for i in list_text_lines.nabor[1:]: try: par.c.create_line(i[0],i[1],i[2],i[3],fill=fill, tags = ('obj', 'temp')) except: pass snap_text = list_text_lines.nabor[0] par.c.create_line(snap_text[0],snap_text[1],snap_text[2],snap_text[3], width=8, fill = fill, stipple = ('@'+path.join(par.appPath, 'res', '00.xbm')), tags = ('obj', 'temp'))
def editEvent2(self, event = None): delete_list = [] self.par.ex2=self.par.priv_coord[0] self.par.ey2=self.par.priv_coord[1] self.par.ex,self.par.ey = self.par.coordinator(self.par.ex,self.par.ey) self.par.set_coord() self.par.ex3 = None self.par.ey3 = None if self.par.ortoFlag == True and self.par.com == None: self.par.ex2,self.par.ey2 = self.par.orto(self.par.ex,self.par.ey,self.par.ex2,self.par.ey2) for content in self.par.collection: if content[0] == 'L': fill, width, sloy, stipple, coord, factor_stip = get_conf.get_line_conf(content, self.par) if coord[0] != coord[2]: if abs(coord[0] - self.par.ex) < self.par.min_e: if abs(coord[1] - self.par.ey) < self.par.min_e: coord[0] = self.par.ex2 coord[1] = self.par.ey2 self.par.ex3 = coord[2] self.par.ey3 = coord[3] elif abs(coord[2] - self.par.ex) < self.par.min_e: if abs(coord[3] - self.par.ey) < self.par.min_e: coord[2] = self.par.ex2 coord[3] = self.par.ey2 self.par.ex3 = coord[0] self.par.ey3 = coord[1] else: if abs(coord[1] - self.par.ey) < self.par.min_e: coord[0] = self.par.ex2 coord[1] = self.par.ey2 self.par.ex3 = coord[2] self.par.ey3 = coord[3] if abs(coord[3] - self.par.ey) < self.par.min_e: coord[2] = self.par.ex2 coord[3] = self.par.ey2 self.par.ex3 = coord[0] self.par.ey3 = coord[1] delete_list.append(content) if event: line.c_line(self.par, coord[0],coord[1],coord[2],coord[3],width = width, stipple = stipple, factor_stip = factor_stip, fill = fill, sloy = sloy) else: line.c_line(self.par, coord[0],coord[1],coord[2],coord[3],width = width, stipple = stipple, factor_stip = factor_stip, fill = fill, sloy = sloy, temp = 'Yes') if content[0] == 'd': text_prov = False fill = self.par.ALLOBJECT[content]['fill'] sloy = self.par.ALLOBJECT[content]['sloy'] text = self.par.ALLOBJECT[content]['text'] line1 = self.par.get_snap_line(content)[0] line2 = self.par.get_snap_line(content)[1] line3 = self.par.get_snap_line(content)[2] ort = self.par.ALLOBJECT[content]['ort'] size = self.par.ALLOBJECT[content]['size'] s = self.par.ALLOBJECT[content]['s'] vr_s = self.par.ALLOBJECT[content]['vr_s'] vv_s = self.par.ALLOBJECT[content]['vv_s'] arrow_s = self.par.ALLOBJECT[content]['arrow_s'] type_arrow = self.par.ALLOBJECT[content]['type_arrow'] s_s = self.par.ALLOBJECT[content]['s_s_dim'] w_text = self.par.ALLOBJECT[content]['w_text_dim'] font = self.par.ALLOBJECT[content]['font_dim'] coord_list = map(lambda i: self.par.c.coords(i), [line1, line2, line3]) if abs(coord_list[0][0] - self.par.ex) < self.par.min_e: if abs(coord_list[0][1] - self.par.ey) < self.par.min_e: coord_list[0] = [self.par.ex2, self.par.ey2] elif abs(coord_list[1][0] - self.par.ex) < self.par.min_e: if abs(coord_list[1][1] - self.par.ey) < self.par.min_e: coord_list[1] = [self.par.ex2, self.par.ey2] elif abs(coord_list[2][0] - self.par.ex) < self.par.min_e: coord_list[2] = [self.par.ex2, self.par.ey2] text_prov = True elif abs(coord_list[2][1] - self.par.ey) < self.par.min_e: coord_list[2] = [self.par.ex2, self.par.ey2] text_prov = True delete_list.append(content) if text_prov == True: text_change = self.par.ALLOBJECT[content]['text_change'] text_lines, priv_line, text_place = self.par.dim_text_place(content) if text_place[2] == 'hor': text_place[1] = self.par.ey + (self.par.ey2-self.par.ey) else: text_place[0] = self.par.ex + (self.par.ex2-self.par.ex) else: text_change = 'unchange' text_place = None if event: dimension.c_dim(self.par, coord_list[0][0], coord_list[0][1], coord_list[1][0], coord_list[1][1], coord_list[2][0], coord_list[2][1], text = text, sloy = sloy, fill = fill, size = size, ort = ort, text_change = text_change, text_place = text_place, s = s, vr_s = vr_s, vv_s = vv_s, arrow_s = arrow_s, type_arrow = type_arrow, s_s = s_s, w_text = w_text, font = font) else: dimension.c_dim(self.par, coord_list[0][0], coord_list[0][1], coord_list[1][0], coord_list[1][1], coord_list[2][0], coord_list[2][1], text = text, sloy = sloy, fill = fill, size = size, ort = ort, text_change = text_change, text_place = text_place, s = s, vr_s = vr_s, vv_s = vv_s, arrow_s = arrow_s, type_arrow = type_arrow, s_s = s_s, w_text = w_text, font = font, temp = 'Yes') if content[0] == 'r': xc, yc, x1, y1, size, fill, text, sloy, s, vr_s, arrow_s, type_arrow, s_s_dim, w_text_dim, font_dim, R = self.par.get_dimR_conf(content) x1 = self.par.ex2 y1 = self.par.ey2 delete_list.append(content) if event: dimension.c_dimR(self.par, xc,yc,x1,y1, Rn = R, text = text, sloy = sloy, fill = fill, size = size, s = s, vr_s = vr_s, arrow_s = arrow_s, type_arrow = type_arrow, s_s = s_s_dim, w_text = w_text_dim, font = font_dim) else: dimension.c_dimR(self.par, xc,yc,x1,y1, Rn = R, text = text, sloy = sloy, fill = fill, size = size, s = s, vr_s = vr_s, arrow_s = arrow_s, type_arrow = type_arrow, s_s = s_s_dim, w_text = w_text_dim, font = font_dim, temp = 'Yes') if content[0] == 'c': e = self.par.get_conf(content) x0 = e[1] y0 = e[2] R = sqrt((self.par.ex2-x0)**2 + (self.par.ey2-y0)**2) fill = e[4] width = e[5] sloy = e[6] delete_list.append(content) if event: circle.c_circle(self.par, x0,y0,fill = fill, width = width, sloy = sloy, R = R) else: circle.c_circle(self.par, x0,y0,fill = fill, width = width, sloy = sloy, R = R, temp = 'Yes') elif content[0] == 'a': find = self.par.ALLOBJECT[content]['id'] for i in find: tag = self.par.ALLOBJECT[content]['id'][i] if 'a' in tag: coord = self.par.c.coords(i) xc, yc, dx1, dy1, dx2, dy2, fill, width, sloy = get_arc_conf(content, self.par) ''' e = self.par.get_arc_conf(content) xc = e[1] yc = e[2] dx1 = e[3] dy1 = e[4] dx2 = e[5] dy2 = e[6] fill = e[7] width = e[8] sloy = e[9] ''' R = sqrt((dx1-xc)**2 + (dy1-yc)**2) if abs(self.par.ex-dx1)<self.par.min_e: if abs(self.par.ey-dy1)<self.par.min_e: dx1 = self.par.ex2 dy1 = self.par.ey2 elif abs(self.par.ex-dx2)<self.par.min_e: if abs(self.par.ey-dy2)<self.par.min_e: dx2 = self.par.ex2 dy2 = self.par.ey2 self.par.ex3 = xc self.par.ey3 = yc aa = degrees(calc_angle(xc, yc, coord[2], yc, dx1, dy1)) bb = degrees(calc_angle(xc, yc, dx1, dy1, dx2, dy2)) delete_list.append(content) if event: arc.c_arc(self.par, xc, yc, R = R, start = aa, extent = bb, fill = fill, width = width, sloy = sloy) else: arc.c_arc(self.par, xc, yc, R = R, start = aa, extent = bb, fill = fill, width = width, sloy = sloy, temp = 'Yes') if self.par.tracingFlag and self.par.ex3 != None: self.par.trace_on = True self.par.trace_x1, self.par.trace_y1 = self.par.ex3,self.par.ey3 self.par.trace_x2, self.par.trace_y2 = self.par.ex2,self.par.ey2 if event: if delete_list: self.par.delete(elements = delete_list) self.par.edit_clone = False self.par.c.delete('temp') self.par.changeFlag = True self.par.enumerator_p() self.par.collection = [] self.par.kill()
def c_dimR(par, x1, y1, x2, y2, text=None, sloy=None, fill=None, size=None, s=None, vr_s=None, arrow_s=None, type_arrow=None, s_s=None, w_text=None, font=None, Rn=None, temp=None): if sloy == None: sloy = par.sloy fill = par.color size = par.size_f s = old_s = par.s vr_s = old_vr_s = par.vr_s arrow_s = old_arrow_s = par.arrow_s type_arrow = par.type_arrow s_s = par.s_s_dim w_text = par.w_text_dim font = par.font_dim else: old_s = s old_vr_s = vr_s old_arrow_s = arrow_s if text == 'None': text = None if not temp: par.Ndimrd += 1 par.Ndimr = 'r' + str(par.Ndimrd) dx = x2 - x1 dy = y2 - y1 R = sqrt(dx * dx + dy * dy) id_dict = {} list_arrow = [] list_lines = [] list_text_lines = [] if par.zoomOLD == 0: Rr = R else: if par.zoomOLD > 0: s *= (zoomp**par.zoomOLD) arrow_s *= (zoomp**par.zoomOLD) vr_s *= (zoomp**par.zoomOLD) Rr = R * zoomm**par.zoomOLD else: zoomOLDx = par.zoomOLD * (-1) s /= (zoomp**zoomOLDx) arrow_s /= (zoomp**zoomOLDx) vr_s /= (zoomp**zoomOLDx) Rr = R * zoomp**zoomOLDx if Rn != None: Rr = Rn R = par.coordinator2(Rn) Rrr = format(Rr, '.0f') angle = abs(calc_angle(x1, y1, x2, y2, x1 + R, y1)) i = 1 anchor = 'sw' if y2 > y1: angle = -angle if x2 < x1: i = -1 angle = angle - pi anchor = 'se' if text: textt = text else: textt = 'R ' + Rrr x1t = x1 + i * (R + arrow_s * 2.0) y1t = y1 - s list_text_lines = symbols.font(x1t, y1t, textt, size, par.zoomOLD, s_s, w_text, anchor, font, 0) e = list_text_lines.nabor[0] if i > 0: list_lines.extend([[x1, y1, e[2], y1]]) else: list_lines.extend([[x1, y1, e[0], y1]]) if type_arrow == 'Arch': L1 = [ x1 + i * (R - arrow_s), y1 + arrow_s, x1 + i * (R + arrow_s), y1 - arrow_s ] list_arrow.extend([ L1, ]) elif type_arrow == 'Arrow': L1 = [x1 + i * R, y1, x1 + i * (R - arrow_s), y1 - arrow_s / 10.0] L2 = [x1 + i * R, y1, x1 + i * (R - arrow_s), y1 + arrow_s / 10.0] list_arrow.extend([L1, L2]) list_text_lines.nabor = rotate_lines(x1, y1, list_text_lines.nabor, angle) list_arrow = rotate_lines(x1, y1, list_arrow, angle) list_lines = rotate_lines(x1, y1, list_lines, angle) for i in list_arrow: id = par.c.create_line(i, fill=fill, tags=('obj', par.Ndimr, 'sel')) id_dict[id] = ('line', ) for i in list_lines: id = par.c.create_line(i, fill=fill, tags=('obj', par.Ndimr, 'sel')) id_dict[id] = ('line', 'priv') for i in list_text_lines.nabor[1:]: try: id = par.c.create_line(i[0], i[1], i[2], i[3], fill=fill, tags=('obj', par.Ndimr, 't_LOD', 'sel')) id_dict[id] = ('line', 'dim_text') except: pass snap_text = list_text_lines.nabor[0] id = par.c.create_line( snap_text[0], snap_text[1], snap_text[2], snap_text[3], width=8, fill=fill, stipple=('@' + path.join(par.appPath, 'res', '00.xbm')), tags=('obj', par.Ndimr, 'snap_text', 'sel')) id_dict[id] = ('line', 'priv', 'dim_text', 'dim_text_priv') par.ALLOBJECT[par.Ndimr] = { 'text': text, #Записать в ALLOBJECT параметры размера 'angle': angle, 'object': 'dimr', 'fill': fill, 'size': size, 'sloy': sloy, 's': old_s, 'R': Rr, 'vr_s': old_vr_s, 'arrow_s': old_arrow_s, 'type_arrow': type_arrow, 's_s_dim': s_s, 'w_text_dim': w_text, 'font_dim': font, 'id': id_dict } else: dx = x2 - x1 dy = y2 - y1 R = sqrt(dx * dx + dy * dy) list_arrow = [] list_lines = [] list_text_lines = [] if par.zoomOLD == 0: Rr = R else: if par.zoomOLD > 0: s *= (zoomp**par.zoomOLD) arrow_s *= (zoomp**par.zoomOLD) vr_s *= (zoomp**par.zoomOLD) Rr = R * zoomm**par.zoomOLD else: zoomOLDx = par.zoomOLD * (-1) s /= (zoomp**zoomOLDx) arrow_s /= (zoomp**zoomOLDx) vr_s /= (zoomp**zoomOLDx) Rr = R * zoomp**zoomOLDx if Rn != None: Rr = Rn R = par.coordinator2(Rn) Rrr = format(Rr, '.0f') angle = abs(calc_angle(x1, y1, x2, y2, x1 + R, y1)) i = 1 anchor = 'sw' if y2 > y1: angle = -angle if x2 < x1: i = -1 angle = angle - pi anchor = 'se' if text: textt = text else: textt = 'R ' + Rrr x1t = x1 + i * (R + arrow_s * 2.0) y1t = y1 - s list_text_lines = symbols.font(x1t, y1t, textt, size, par.zoomOLD, s_s, w_text, anchor, font, 0) e = list_text_lines.nabor[0] if i > 0: list_lines.extend([[x1, y1, e[2], y1]]) else: list_lines.extend([[x1, y1, e[0], y1]]) if type_arrow == 'Arch': L1 = [ x1 + i * (R - arrow_s), y1 + arrow_s, x1 + i * (R + arrow_s), y1 - arrow_s ] list_arrow.extend([ L1, ]) elif type_arrow == 'Arrow': L1 = [x1 + i * R, y1, x1 + i * (R - arrow_s), y1 - arrow_s / 10.0] L2 = [x1 + i * R, y1, x1 + i * (R - arrow_s), y1 + arrow_s / 10.0] list_arrow.extend([L1, L2]) list_text_lines.nabor = rotate_lines(x1, y1, list_text_lines.nabor, angle) list_arrow = rotate_lines(x1, y1, list_arrow, angle) list_lines = rotate_lines(x1, y1, list_lines, angle) for i in list_arrow: par.c.create_line(i, fill=fill, tags=('obj', 'temp')) for i in list_lines: par.c.create_line(i, fill=fill, tags=('obj', 'temp')) for i in list_text_lines.nabor[1:]: try: par.c.create_line(i[0], i[1], i[2], i[3], fill=fill, tags=('obj', 'temp')) except: pass snap_text = list_text_lines.nabor[0] par.c.create_line(snap_text[0], snap_text[1], snap_text[2], snap_text[3], width=8, fill=fill, stipple=('@' + path.join(par.appPath, 'res', '00.xbm')), tags=('obj', 'temp'))
def rotate(par, x0 = None, y0 = None, px1 = None, py1 = None, px2 = None, py2 = None, delOld = 'Yes', content = None, angle = None, temp = None): if angle == None: #Если угол поворота не указан - считать по координатам angle = calc_angle(x0, y0, px1, py1, px2, py2) #Если угол указан - считать сразу msin = sin(angle) mcos = cos(angle) if not temp: if delOld == 'No': for c in content: if c[0] == 'L': fill, width, sloy, stipple, coord, factor_stip = get_line_conf(c, par) coord = rotate_lines(x0, y0, [coord,], msin = msin, mcos = mcos)[0] _line.c_line(par, coord[0], coord[1], coord[2], coord[3], width, sloy, fill, stipple, factor_stip) elif c[0] == 't': fill, text, sloy, _angle, anchor, size, line, coord, s_s, w_text, font = get_text_conf(c, par) coord = rotate_lines(x0, y0, [coord,], msin = msin, mcos = mcos)[0] text_line.c_text(par, coord[0], coord[1], text, anchor, sloy, fill, angle+_angle, size, s_s, w_text, font) elif c[0] == 'd': pass ''' x1, y1, x2, y2, x3, y3, ort, size, fill, text, sloy, text_change, text_place, s, vr_s, vv_s, arrow_s, type_arrow, s_s_dim, w_text_dim, font_dim = get_dim_conf(c, par) #coord = [y+d[0] if ind%2 == 0 else y+d[1] for ind, y in enumerate((x1, y1, x2, y2, x3, y3))] if text_change == None: text_change = [0, 0] coord = rotate_lines(x0, y0, [x1, y1, x2, y2, x3, y3, text_change[0], text_change[1]], msin = msin, mcos = mcos) dimension.c_dim(par, coord[0],coord[1],coord[2],coord[3],coord[4],coord[5],text, sloy, fill, size, ort, text_change, [coord[6], coord[7]], s, vv_s, vr_s, arrow_s, type_arrow, s_s_dim, w_text_dim, font_dim) ''' elif c[0] == 'r': pass ''' xc, yc, x1, y1, size, fill, text, sloy, s, vr_s, arrow_s, type_arrow, s_s, w_text, font, R = get_dimR_conf(c, par) coord = [y+d[0] if ind%2 == 0 else y+d[1] for ind, y in enumerate((xc, yc, x1, y1))] dimension.c_dimR(par,coord[0],coord[1],coord[2],coord[3], text, sloy, fill, size, s, vr_s, arrow_s, type_arrow, s_s, w_text, font, R) ''' elif c[0] == 'c': xc, yc, R, fill, width, sloy = get_circle_conf(c, par) coord = rotate_points(x0, y0, [[xc, yc],], msin = msin, mcos = mcos)[0] circle.c_circle(par, coord[0], coord[1], width = width, sloy = sloy, fill = fill, R = R) elif c[0] == 'a': xc, yc, dx1, dy1, dx2, dy2, fill, width, sloy = get_arc_conf(c, par) coord = rotate_points(x0, y0, [[xc, yc], [dx1, dy1], [dx2, dy2]], msin = msin, mcos = mcos) arc.c_arc(par, coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], width = width, sloy = sloy, fill = fill) else: for c in content: if c[0] in ('L', 't'): if c[0] == 't': par.ALLOBJECT[c]['angle'] += angle find = par.ALLOBJECT[c]['id'] for i in find: coord = par.c.coords(i) coord = tuple(rotate_lines(x0, y0, [coord,], msin = msin, mcos = mcos)[0]) par.c.coords(i, coord) elif c[0] == 'd': pass ''' x1, y1, x2, y2, x3, y3, ort, size, fill, text, sloy, text_change, text_place, s, vr_s, vv_s, arrow_s, type_arrow, s_s_dim, w_text_dim, font_dim = get_dim_conf(c, par) #coord = [y+d[0] if ind%2 == 0 else y+d[1] for ind, y in enumerate((x1, y1, x2, y2, x3, y3))] if text_change == None: text_change = [0, 0] coord = rotate_lines(x0, y0, [x1, y1, x2, y2, x3, y3, text_change[0], text_change[1]], msin = msin, mcos = mcos) dimension.c_dim(par, coord[0],coord[1],coord[2],coord[3],coord[4],coord[5],text, sloy, fill, size, ort, text_change, [coord[6], coord[7]], s, vv_s, vr_s, arrow_s, type_arrow, s_s_dim, w_text_dim, font_dim) ''' elif c[0] == 'r': pass ''' xc, yc, x1, y1, size, fill, text, sloy, s, vr_s, arrow_s, type_arrow, s_s, w_text, font, R = get_dimR_conf(c, par) coord = [y+d[0] if ind%2 == 0 else y+d[1] for ind, y in enumerate((xc, yc, x1, y1))] dimension.c_dimR(par,coord[0],coord[1],coord[2],coord[3], text, sloy, fill, size, s, vr_s, arrow_s, type_arrow, s_s, w_text, font, R) ''' elif c[0] == 'c': xc, yc, R, fill, width, sloy = get_circle_conf(c, par) par.c.delete(c) coord = rotate_points(x0, y0, [[xc, yc],], msin = msin, mcos = mcos)[0] circle.c_circle(par, coord[0], coord[1], width = width, sloy = sloy, fill = fill, R = R, ID = c) elif c[0] == 'a': xc, yc, dx1, dy1, dx2, dy2, fill, width, sloy = get_arc_conf(c, par) par.c.delete(c) coord = rotate_points(x0, y0, [[xc, yc], [dx1, dy1], [dx2, dy2]], msin = msin, mcos = mcos) arc.c_arc(par, coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], width = width, sloy = sloy, fill = fill, ID = c) else: for c in content: if c[0] == 'L': fill, width, sloy, stipple, coord, factor_stip = get_line_conf(c, par) coord = rotate_lines(x0, y0, [coord,], msin = msin, mcos = mcos)[0] _line.c_line(par, coord[0], coord[1], coord[2], coord[3], width, sloy, fill, stipple, factor_stip, temp = temp) elif c[0] == 't': fill, text, sloy, _angle, anchor, size, line, coord, s_s, w_text, font = get_text_conf(c, par) coord = rotate_lines(x0, y0, [coord,], msin = msin, mcos = mcos)[0] text_line.c_text(par, coord[0], coord[1], text, anchor, sloy, fill, angle+_angle, size, s_s, w_text, font, temp = temp) elif c[0] == 'c': xc, yc, R, fill, width, sloy = get_circle_conf(c, par) coord = rotate_points(x0, y0, [[xc, yc],], msin = msin, mcos = mcos)[0] circle.c_circle(par, coord[0], coord[1], width = width, sloy = sloy, fill = fill, R = R, temp = temp) elif c[0] == 'a': xc, yc, dx1, dy1, dx2, dy2, fill, width, sloy = get_arc_conf(c, par) coord = rotate_points(x0, y0, [[xc, yc], [dx1, dy1], [dx2, dy2]], msin = msin, mcos = mcos) arc.c_arc(par, coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], width = width, sloy = sloy, fill = fill, temp = temp)
def c_arc(par, x0, y0, xr1=None, yr1=None, xr2=None, yr2=None, width=None, sloy=None, fill=None, R=None, start=None, extent=None, ID=None, temp=None): if sloy == None: fill = par.color width = par.width sloy = par.sloy width = int(width) if not temp: if not ID: par.Narcd += 1 ID = par.Narc = 'a' + str(par.Narcd) if R == None: R = sqrt((xr1 - x0) * (xr1 - x0) + (yr1 - y0) * (yr1 - y0)) x1 = x0 - R x2 = x0 + R y1 = y0 - R y2 = y0 + R s = R / 20.0 R = par.n_coordinator(R) id_dict = {} if start == None: aa = degrees(calc_angle(x0, y0, x2, y0, xr1, yr1)) bb = degrees(calc_angle(x0, y0, xr1, yr1, xr2, yr2)) else: aa = start bb = extent if aa < 0: aa = 360 - abs(aa) id = par.c.create_arc( x1, y1, x2, y2, start=aa, extent=bb, outline=fill, full=None, width=width, style='arc', tags=('obj', ID)) #['arc', par.Narc, 'a', 'obj', 'priv', sloy]) id_dict[id] = ('a', 'priv') id = par.c.create_line( x0 - s, y0 - s, x0 + s, y0 + s, fill=fill, tags=('obj', ID, 'a_centr') ) #['arc', par.Narc, 'line', 'a_centr', 'obj', 'priv', sloy]) id_dict[id] = ('line', 'priv', 'a_centr') id = par.c.create_line( x0 + s, y0 - s, x0 - s, y0 + s, fill=fill, tags=('obj', ID, 'a_centr') ) #['arc', par.Narc, 'line', 'a_centr', 'obj', 'priv', sloy]) id_dict[id] = ('line', 'priv', 'a_centr') par.ALLOBJECT[ID] = { 'object': 'arc', 'fill': fill, 'width': width, 'sloy': sloy, 'start': aa, 'extent': bb, 'R': R, 'id': id_dict } else: if R == None: R = sqrt((xr1 - x0) * (xr1 - x0) + (yr1 - y0) * (yr1 - y0)) x1 = x0 - R x2 = x0 + R y1 = y0 - R y2 = y0 + R s = R / 20.0 R = par.n_coordinator(R) if start == None: aa = degrees(calc_angle(x0, y0, x2, y0, xr1, yr1)) bb = degrees(calc_angle(x0, y0, xr1, yr1, xr2, yr2)) else: aa = start bb = extent if aa < 0: aa = 360 - abs(aa) par.c.create_arc( x1, y1, x2, y2, start=aa, extent=bb, outline=fill, full=None, width=width, style='arc', tags=('obj', 'temp')) #['arc', par.Narc, 'a', 'obj', 'priv', sloy]) par.c.create_line( x0 - s, y0 - s, x0 + s, y0 + s, fill=fill, tags=('obj', 'temp') ) #['arc', par.Narc, 'line', 'a_centr', 'obj', 'priv', sloy]) par.c.create_line( x0 + s, y0 - s, x0 - s, y0 + s, fill=fill, tags=('obj', 'temp') ) #['arc', par.Narc, 'line', 'a_centr', 'obj', 'priv', sloy])
def rotate(par, x0=None, y0=None, px1=None, py1=None, px2=None, py2=None, delOld='Yes', content=None, angle=None, temp=None): if angle == None: #Если угол поворота не указан - считать по координатам angle = calc_angle(x0, y0, px1, py1, px2, py2) #Если угол указан - считать сразу msin = sin(angle) mcos = cos(angle) if not temp: if delOld == 'No': for c in content: if c[0] == 'L': fill, width, sloy, stipple, coord, factor_stip = get_line_conf( c, par) coord = rotate_lines(x0, y0, [ coord, ], msin=msin, mcos=mcos)[0] _line.c_line(par, coord[0], coord[1], coord[2], coord[3], width, sloy, fill, stipple, factor_stip) elif c[0] == 't': fill, text, sloy, _angle, anchor, size, line, coord, s_s, w_text, font = get_text_conf( c, par) coord = rotate_lines(x0, y0, [ coord, ], msin=msin, mcos=mcos)[0] text_line.c_text(par, coord[0], coord[1], text, anchor, sloy, fill, angle + _angle, size, s_s, w_text, font) elif c[0] == 'd': pass ''' x1, y1, x2, y2, x3, y3, ort, size, fill, text, sloy, text_change, text_place, s, vr_s, vv_s, arrow_s, type_arrow, s_s_dim, w_text_dim, font_dim = get_dim_conf(c, par) #coord = [y+d[0] if ind%2 == 0 else y+d[1] for ind, y in enumerate((x1, y1, x2, y2, x3, y3))] if text_change == None: text_change = [0, 0] coord = rotate_lines(x0, y0, [x1, y1, x2, y2, x3, y3, text_change[0], text_change[1]], msin = msin, mcos = mcos) dimension.c_dim(par, coord[0],coord[1],coord[2],coord[3],coord[4],coord[5],text, sloy, fill, size, ort, text_change, [coord[6], coord[7]], s, vv_s, vr_s, arrow_s, type_arrow, s_s_dim, w_text_dim, font_dim) ''' elif c[0] == 'r': pass ''' xc, yc, x1, y1, size, fill, text, sloy, s, vr_s, arrow_s, type_arrow, s_s, w_text, font, R = get_dimR_conf(c, par) coord = [y+d[0] if ind%2 == 0 else y+d[1] for ind, y in enumerate((xc, yc, x1, y1))] dimension.c_dimR(par,coord[0],coord[1],coord[2],coord[3], text, sloy, fill, size, s, vr_s, arrow_s, type_arrow, s_s, w_text, font, R) ''' elif c[0] == 'c': xc, yc, R, fill, width, sloy = get_circle_conf(c, par) coord = rotate_points(x0, y0, [ [xc, yc], ], msin=msin, mcos=mcos)[0] circle.c_circle(par, coord[0], coord[1], width=width, sloy=sloy, fill=fill, R=R) elif c[0] == 'a': xc, yc, dx1, dy1, dx2, dy2, fill, width, sloy = get_arc_conf( c, par) coord = rotate_points(x0, y0, [[xc, yc], [dx1, dy1], [dx2, dy2]], msin=msin, mcos=mcos) arc.c_arc(par, coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], width=width, sloy=sloy, fill=fill) else: for c in content: if c[0] in ('L', 't'): if c[0] == 't': par.ALLOBJECT[c]['angle'] += angle find = par.ALLOBJECT[c]['id'] for i in find: coord = par.c.coords(i) coord = tuple( rotate_lines(x0, y0, [ coord, ], msin=msin, mcos=mcos)[0]) par.c.coords(i, coord) elif c[0] == 'd': pass ''' x1, y1, x2, y2, x3, y3, ort, size, fill, text, sloy, text_change, text_place, s, vr_s, vv_s, arrow_s, type_arrow, s_s_dim, w_text_dim, font_dim = get_dim_conf(c, par) #coord = [y+d[0] if ind%2 == 0 else y+d[1] for ind, y in enumerate((x1, y1, x2, y2, x3, y3))] if text_change == None: text_change = [0, 0] coord = rotate_lines(x0, y0, [x1, y1, x2, y2, x3, y3, text_change[0], text_change[1]], msin = msin, mcos = mcos) dimension.c_dim(par, coord[0],coord[1],coord[2],coord[3],coord[4],coord[5],text, sloy, fill, size, ort, text_change, [coord[6], coord[7]], s, vv_s, vr_s, arrow_s, type_arrow, s_s_dim, w_text_dim, font_dim) ''' elif c[0] == 'r': pass ''' xc, yc, x1, y1, size, fill, text, sloy, s, vr_s, arrow_s, type_arrow, s_s, w_text, font, R = get_dimR_conf(c, par) coord = [y+d[0] if ind%2 == 0 else y+d[1] for ind, y in enumerate((xc, yc, x1, y1))] dimension.c_dimR(par,coord[0],coord[1],coord[2],coord[3], text, sloy, fill, size, s, vr_s, arrow_s, type_arrow, s_s, w_text, font, R) ''' elif c[0] == 'c': xc, yc, R, fill, width, sloy = get_circle_conf(c, par) par.c.delete(c) coord = rotate_points(x0, y0, [ [xc, yc], ], msin=msin, mcos=mcos)[0] circle.c_circle(par, coord[0], coord[1], width=width, sloy=sloy, fill=fill, R=R, ID=c) elif c[0] == 'a': xc, yc, dx1, dy1, dx2, dy2, fill, width, sloy = get_arc_conf( c, par) par.c.delete(c) coord = rotate_points(x0, y0, [[xc, yc], [dx1, dy1], [dx2, dy2]], msin=msin, mcos=mcos) arc.c_arc(par, coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], width=width, sloy=sloy, fill=fill, ID=c) else: for c in content: if c[0] == 'L': fill, width, sloy, stipple, coord, factor_stip = get_line_conf( c, par) coord = rotate_lines(x0, y0, [ coord, ], msin=msin, mcos=mcos)[0] _line.c_line(par, coord[0], coord[1], coord[2], coord[3], width, sloy, fill, stipple, factor_stip, temp=temp) elif c[0] == 't': fill, text, sloy, _angle, anchor, size, line, coord, s_s, w_text, font = get_text_conf( c, par) coord = rotate_lines(x0, y0, [ coord, ], msin=msin, mcos=mcos)[0] text_line.c_text(par, coord[0], coord[1], text, anchor, sloy, fill, angle + _angle, size, s_s, w_text, font, temp=temp) elif c[0] == 'c': xc, yc, R, fill, width, sloy = get_circle_conf(c, par) coord = rotate_points(x0, y0, [ [xc, yc], ], msin=msin, mcos=mcos)[0] circle.c_circle(par, coord[0], coord[1], width=width, sloy=sloy, fill=fill, R=R, temp=temp) elif c[0] == 'a': xc, yc, dx1, dy1, dx2, dy2, fill, width, sloy = get_arc_conf( c, par) coord = rotate_points(x0, y0, [[xc, yc], [dx1, dy1], [dx2, dy2]], msin=msin, mcos=mcos) arc.c_arc(par, coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], width=width, sloy=sloy, fill=fill, temp=temp)
def postprocess_inte(pred_path, images, labels_gt_abs, title=None, save_plot=False, automatic=False, automatic_time=10, degree=6, method1_on=True, method2_on=True, method2_ver=None, original_display=True): author = 'YB' ############################ # # plot result vector # if save_plot == True : save image to folder # Do not adjust other settings. # ############################ if True: preds_rel = read_labels(pred_path, title='labels_pred_rel') preds = [] for ind, pred_rel in enumerate(preds_rel): _img = images[ind] H, W, _ = _img.shape pred_abs = to_absolute(label=pred_rel, H=H, W=W) preds.append(pred_abs) preds = np.asarray(preds) write_labels(preds, label_location=pred_path, title='labels_pred_abs') preds = label_sort(preds) result_list = [] for ind, image in enumerate(images): print('Saved {}'.format(ind)) gt = labels_gt_abs[ind] pred = preds[ind] H, W, C = image.shape #gt = to_absolute(gt, H, W) fitted_preds, params1 = post_way1(pred, full=True, degree=degree) if method2_ver == 0: slopes, params2 = post_way2_v0(pred, full=True, degree=degree) elif method2_ver == 1: slopes, params2 = post_way2_v1(pred, full=True, degree=degree) elif method2_ver == 2: slopes, params2 = post_way2_v2(pred, full=True, degree=degree) elif method2_ver == None: slopes, params2 = post_way2(pred, full=True, degree=degree) else: slopes, params2 = post_way2(pred, full=True, degree=degree) gt_angles, gt_pos = calc_angle_old(gt, (H, W), full=True) w1_angles, w1_pos = calc_angle_old(fitted_preds, (H, W), full=True) w2_angles, w2_pos = calc_angle(slopes, get_mid_points(pred), image_H=H, full=True) #convert to smape error w1_error = np.sum( np.abs(w1_angles - gt_angles)) / np.sum(gt_angles + w1_angles) w2_error = np.sum( np.abs(w2_angles - gt_angles)) / np.sum(gt_angles + w2_angles) w1_mainerr = (np.abs(w1_angles - gt_angles) / (gt_angles + w1_angles + 1e-8))[0] w2_mainerr = (np.abs(w2_angles - gt_angles) / (gt_angles + w2_angles + 1e-8))[0] pred = pred.reshape(-1, 2, 2) delta = pred[:, 0, :] - pred[:, 1, :] deltax = np.average(np.abs(delta)[:, 0]) / W # show는 테스트 if save_plot or automatic: #make plot plt.figure() # R for w1 left_line = params1['left_line'] right_line = params1['right_line'] if method1_on: plt.plot(left_line[:, 0], left_line[:, 1], color='magenta', alpha=0.5) plt.plot(right_line[:, 0], right_line[:, 1], color='magenta', alpha=0.5) _fp = fitted_preds.reshape(-1, 2, 2).copy() for pos in w1_pos: dots = np.average(_fp[2 * pos:2 * pos + 2, :, :], axis=0) if method1_on: plt.plot(dots[:, 0], dots[:, 1], 'r') # blue for w2 middle_line = params2['line'] if method2_on: plt.plot(middle_line[:, 0], middle_line[:, 1], color='cyan', alpha=0.5) vec_center = params2['middle_vec'] for pos in w2_pos: center = vec_center[pos] _slope = slopes[pos] norm_slope = _slope / np.linalg.norm(_slope) right = center + norm_slope * 50 left = center - norm_slope * 50 if method2_on: plt.plot([left[0], right[0]], [left[1], right[1]], color='blue') if original_display: plot_image(image, coord_red=fitted_preds, coord_gr=gt) else: plot_image(image, coord_red=fitted_preds) if method1_on and not method2_on: plt_title = 'a %.1f/p1 %.1f/err%% %.2f' % \ (gt_angles[0], w1_angles[0], w1_error * 100) else: plt_title = 'a %.1f/p1 %.1f/err%% %.2f'%\ (gt_angles[0], w2_angles[0], w2_error*100) plt.title('test_{}\n'.format(ind) + plt_title) if automatic: plt.show() plt.pause(automatic_time) plt.close() if save_plot: if title is None: title = 'pred' if not os.path.exists(os.path.join(pred_path, title)): os.makedirs(os.path.join(pred_path, title)) plt.savefig( os.path.join(pred_path, title, title + '_{}'.format(ind) + '.png')) plt.close() res_dict = dict(gt_angle1=gt_angles[0], gt_angle2=gt_angles[1], gt_angle3=gt_angles[2], w1_angle1=w1_angles[0], w1_angle2=w1_angles[1], w1_angle3=w1_angles[2], w2_angle1=w2_angles[0], w2_angle2=w2_angles[1], w2_angle3=w2_angles[2], w1_mainerr=w1_mainerr, w2_mainerr=w2_mainerr, w1_error=w1_error, w2_error=w2_error, avgdx=deltax, gt_pos=gt_pos, w1_pos=w1_pos, w2_pos=w2_pos) result_list.append(res_dict) w1_errors = np.array([di['w1_error'] for di in result_list]) w2_errors = np.array([di['w2_error'] for di in result_list]) print('Avg : w1_e %.2f / w2_e %.2f ' % (np.average(w1_errors), np.average(w2_errors))) df = pd.DataFrame(result_list) df.to_csv( os.path.join( pred_path, title, 'result_' + title + '_%.2f' % (np.average(w2_errors) * 100) + '.csv')) return result_list
def tracer(par, x1, y1, x2, y2, snap_s, angle_s): angle = None x3 = x2 y3 = y1 i = 1 j = 1 if x2 > x1: i = 1 elif x2 < x1: i = -1 if y2 > y1: j = 1 elif y2 < y1: j = -1 if x1 == x2: angle = 90.0 if y1 == y2: angle = 0.0 if (x1, y1) == (x2, y2): return if angle == None: angle = abs(degrees(calc_angle(x1, y1, x3, y3, x2, y2))) a = 0 d = sqrt((x2 - x1)**2 + (y2 - y1)**2) while angle_s * a <= 90.0: if abs(angle) - snap_s / 6.0 <= abs( angle_s * a) <= abs(angle) + snap_s / 6.0: xi = cos(radians(angle_s * a)) * d * 10000.0 * i + x1 yi = sin(radians(angle_s * a)) * d * 10000.0 * j + y1 if 'trace' in par.ALLOBJECT: par.c.delete('text') par.c.create_text(x2 + snap_s * 2, y2 + snap_s * 2, fill='yellow', text=str(angle_s * a), tags=('obj', 'trace', 'text')) a = None break else: id = par.c.create_line(x1, y1, xi, yi, fill='yellow', width=1, tags=('obj', 'trace')) par.c.create_text(x2 + snap_s * 2, y2 + snap_s * 2, fill='yellow', text=str(angle_s * a), tags=('obj', 'trace', 'text')) id_dict = {id: ('line', 'priv')} par.ALLOBJECT['trace'] = {'id': id_dict} a = None break else: a += 1 if a != None and 'trace' in par.ALLOBJECT: par.c.delete('trace') del par.ALLOBJECT['trace']