#選択頂点・辺・面の縮小 def return_naihouhen(menlist): #面のリストを与えると、内包する辺の辺番号を返す #return_edgelist(mennumber)が必要 #return_same_num(list1)が必要 henlist=[] for i in menlist: henlist+=return_edgelist(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 #選択頂点の縮小 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: #選択されている頂点のうち、となりの頂点が全てアクティブになっている頂点のみリストに入れていく nokosupointlist=[] for i in activepointlist: tonarilist=return_pointlist(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) #159行目 #選択されている頂点のうち、グリッドなどで端っこにある頂点のリストを作成 kumiawaselist=return_kumiawase(activepointlist) temphenlist=[] for i in kumiawaselist: edgenum=return_edge_number(i[0],i[1]) if edgenum>0: temphenlist.append(edgenum) erase_same_num(temphenlist) #端っこにある辺は隣接する面が1個 hazihenlist=[] for i in temphenlist: if len(return_menlist(i))==1: hazihenlist.append(i) hazitenlist=[] for i in hazihenlist: hazitenlist+=[xshade.scene().active_shape().edge(i).v0,xshade.scene().active_shape().edge(i).v1] erase_same_num(hazitenlist) #端っこにあるポイントは残すリストから削除する nokosupointlist=substract_b_from_a(nokosupointlist,hazitenlist) 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 #選択辺の縮小 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: #内包辺(面を構成する辺から外周の辺を抜いたもの)のリストを取得 henlist=return_naihouhen(activemenlist) 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: #内包辺(面を構成する辺から外周の辺を抜いたもの)のリストを取得 henlist=return_naihouhen(activemenlist) 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()