#選択頂点・辺・面の縮小 #アルゴリズム変更 def return_henlist(face): #面番号から面を構成する辺の番号を返す #前後にsetup_winged_edgeとclean_winged_edgeが必要 tempvlist=xshade.scene().active_shape().face(face).vertex_indices henlist=[] for i in tempvlist: tempf=xshade.scene().active_shape().eccwfv(face,i,False) henlist.append(tempf) return henlist def return_naihouhen(menlist,felist): #面のリストを与えると、内包する辺の辺番号を返す henlist=[] for i in menlist: henlist+=felist[i] henlist=return_same_num(henlist) return henlist def return_edgelist(mennumber): #その面を構成する辺の辺番号をリストで返す #def return_edge_numberが必要 #def erase_same_num が必要 returnlist=[] menpoints=list(xshade.scene().active_shape().face(mennumber).vertex_indices) kumiawase=[]#頂点を組みあわせたリスト(重複分は削除する) for i in menpoints: for j in menpoints: if i!=j: tempp=[i,j] tempp.sort() kumiawase.append(tempp) erase_same_num(kumiawase) for i in kumiawase: modori=return_edge_number(i[0],i[1]) if modori!=-1: returnlist.append(modori) return returnlist def return_edge_number(pointnum1,pointnum2): #頂点二つの頂点番号を与えると、その頂点で構成される辺の辺番号を返す #エラー(辺の両端のポイントでは無い)の場合は-1を返す returnnum=-1 for i in range(xshade.scene().active_shape().number_of_edges): if xshade.scene().active_shape().edge(i).v0==pointnum1 and xshade.scene().active_shape().edge(i).v1==pointnum2: returnnum=i if xshade.scene().active_shape().edge(i).v1==pointnum1 and xshade.scene().active_shape().edge(i).v0==pointnum2: returnnum=i return returnnum def return_same_num(list1): #リスト内に同じ値が重複する場合は重複する値だけを返す関数 例[1,1,1,3,3,4]→[1,3] #def erase_same_numが必要 list1.sort() nagasa=len(list1) if nagasa>1: kesu=[] for i in range(nagasa-1): if list1[i]==list1[i+1]: kesu.append(list1[i]) erase_same_num(kesu) return kesu def erase_same_num(list1): #リスト内に同じ値が重複する場合は一つに減らす関数 例[1,1,1,3,3,4]→[1,3,4] list1.sort() nagasa=len(list1) if nagasa>1: kesu=[] for i in range(nagasa-1): if list1[i]==list1[i+1]: kesu.append(list1[i]) kesukaisuu=len(kesu) if kesukaisuu>0: for i in kesu: list1.remove(i) def return_pointlist(pointnum): #その点と接続されている頂点の頂点番号をリストで返す(引数 頂点番号) pointlist=[] totaledgesuu=xshade.scene().active_shape().number_of_edges for i in range(totaledgesuu): if xshade.scene().active_shape().edge(i).v0==pointnum: pointlist.append(xshade.scene().active_shape().edge(i).v1) if xshade.scene().active_shape().edge(i).v1==pointnum: pointlist.append(xshade.scene().active_shape().edge(i).v0) return pointlist #90行目 def return_kumiawase(list1): #リスト内の値を組み合わせたリストを返す [1,2,3,4]→[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]] #def_erase_same_numが必要 returnlist=[] for i in list1: for j in list1: if i!=j: tempp=[i,j] tempp.sort() returnlist.append(tempp) erase_same_num(returnlist) return returnlist def return_menlist(edgenumber): #その辺を共有する面の面番号をリストで返す(引数 辺番号) menlist=[] edgevertex=[xshade.scene().active_shape().edge(edgenumber).v0,xshade.scene().active_shape().edge(edgenumber).v1] totalmenmen=xshade.scene().active_shape().number_of_faces for i in range(totalmenmen): konomen=0 temppoint=list(xshade.scene().active_shape().face(i).vertex_indices) for j in temppoint: if edgevertex[0]==j: konomen+=1 if edgevertex[1]==j: konomen+=1 if konomen==2: menlist.append(i) return menlist def substract_b_from_a(lista,listb): #リストAからリストBに存在する要素を抜く a[1,2,3,4,4,5] b[3,4] 結果[1,2,5] #リストBに重複する値が存在するとエラーが出るので、あらかじめ重複する値は消しておく kesulis=[] for i in listb: for j in lista: if j==i: kesulis.append(i) for i in kesulis: lista.remove(i) return lista #選択頂点の縮小 xscene=xshade.scene() ashape=xshade.scene().active_shape() if xshade.scene().selection_mode==2 and xshade.scene().is_modify_mode==True and xshade.scene().active_shape().type==7: #選択されている頂点のリストを作成 activepointlist=[] for i in range(xshade.scene().active_shape().total_number_of_control_points): if xshade.scene().active_shape().vertex(i).active_order>0: activepointlist.append(i) #選択されている頂点が1個以上あるか if len(activepointlist)>0: #面の向きを統一 ashape.adjust_face_direction() vvlist=[]#頂点のとなりの頂点リストを頂点番号順に格納したもの velist=[]#頂点に接続されている辺リストを頂点番号順に格納したもの eflist=[]#辺の隣接面のリストを辺番号順に格納したもの for i in range(ashape.number_of_edges): eflist.append([]) for i in range(ashape.total_number_of_control_points): vvlist.append([]) velist.append([]) ashape.setup_winged_edge() for i in range(ashape.number_of_faces): henlist=return_henlist(i) for gg in henlist: templ=eflist[gg] templ.append(i) eflist[gg]=templ ashape.clean_winged_edge() for i in range(ashape.number_of_edges): vv0=ashape.edge(i).v0 vv1=ashape.edge(i).v1 tempvl=vvlist[vv0] tempvl.append(vv1) vvlist[vv0]=tempvl tempvl=vvlist[vv1] tempvl.append(vv0) vvlist[vv1]=tempvl tempvelist=velist[vv0] tempvelist.append(i) velist[vv0]=tempvelist tempvelist=velist[vv1] tempvelist.append(i) velist[vv1]=tempvelist #選択されている頂点のうち、となりの頂点が全てアクティブになっている頂点のみリストに入れていく nokosupointlist=[] for i in activepointlist: tonarilist=vvlist[i] nokosu=0 for j in tonarilist: if xshade.scene().active_shape().vertex(j).active_order>0: nokosu+=1 if nokosu==len(tonarilist): nokosupointlist.append(i) #選択されている頂点のうち、グリッドなどで端っこにある頂点のリストを作成 hazitenlist=[] for i in activepointlist: #頂点の接続辺のうち、隣接面が1以下の辺がある場合はグリッドの端の点 thenlist=velist[i] for gg in thenlist: if len(eflist[gg])<2: hazitenlist.append(i) break for i in range(xshade.scene().active_shape().total_number_of_control_points): xshade.scene().active_shape().vertex(i).active=False for i in nokosupointlist: xshade.scene().active_shape().vertex(i).active=True #端っこにあるポイントは選択除外 for i in hazitenlist: xshade.scene().active_shape().vertex(i).active=False #選択辺の縮小 if xshade.scene().selection_mode==1 and xshade.scene().is_modify_mode==True and xshade.scene().active_shape().type==7: #辺が一つでも選択状態かどうか dousasuru=0 for i in range(xshade.scene().active_shape().number_of_edges): if xshade.scene().active_shape().edge(i).active_order>0: dousasuru+=1 if dousasuru>0: #面選択モードへ移行 xshade.scene().selection_mode=0 #選択されている面リストを取得 activemenlist=[] for i in range(xshade.scene().active_shape().number_of_faces): if xshade.scene().active_shape().face(i).active_order>0: activemenlist.append(i) #面が一つでもあるか if len(activemenlist)>0: #面の向きを統一 ashape.adjust_face_direction() felist=[]#面を構成する辺のリストを面番号順に格納 ashape.setup_winged_edge() for i in range(ashape.number_of_faces): felist.append(return_henlist(i)) ashape.clean_winged_edge() #内包辺(面を構成する辺から外周の辺を抜いたもの)のリストを取得 henlist=return_naihouhen(activemenlist,felist) xshade.scene().selection_mode=1 for i in range(xshade.scene().active_shape().number_of_edges): xshade.scene().active_shape().edge(i).active=False for i in henlist: xshade.scene().active_shape().edge(i).active=True else: xshade.scene().selection_mode=1 #選択面の縮小 if xshade.scene().selection_mode==0 and xshade.scene().is_modify_mode==True and xshade.scene().active_shape().type==7: #選択されている面リストを取得 activemenlist=[] for i in range(xshade.scene().active_shape().number_of_faces): if xshade.scene().active_shape().face(i).active_order>0: activemenlist.append(i) if len(activemenlist)>0: #面の向きを統一 ashape.adjust_face_direction() felist=[]#面を構成する辺のリストを面番号順に格納 ashape.setup_winged_edge() for i in range(ashape.number_of_faces): felist.append(return_henlist(i)) ashape.clean_winged_edge() #内包辺(面を構成する辺から外周の辺を抜いたもの)のリストを取得 henlist=return_naihouhen(activemenlist,felist) xshade.scene().selection_mode=1 for i in range(xshade.scene().active_shape().number_of_edges): xshade.scene().active_shape().edge(i).active=False for i in henlist: xshade.scene().active_shape().edge(i).active=True xshade.scene().selection_mode=0 if xshade.scene().is_modify_mode==True: xshade.scene().exit_modify_mode() xshade.scene().enter_modify_mode() #画面の更新 xshade.scene().update_figure_window()