2014年1月25日土曜日

vpython オブジェクトのコピー 2

window_copy.py

# coding: UTF-8
from visual import *
#ウィンドウの複製をさくせい
#http://www.nasuinfo.or.jp/FreeSpace/kenji/sf/visualj/options.html

def clone_universe( new_display, old_display):
    # Create a dictionary of frames in the old display
    # to the corresponding frames in the new display.
    #新しい display と新しい frame が作られねばなりません
    #(frame は None かもしれません)?
    #dict() 組み込み関数 下のコードでframesという空の辞書を作成
    frames = dict()


    # Initialize the lookup dictionary
    # 検索ディクショナリを初期化する
    # objects 見えているオブジェクトのリスト
    # obj.__class__ でクラス名を得る
    # ball = sphere(..)とすれば ballのクラスはsphere
    print
    print '-------------------------------------------'
    print 'for obj in old_display.objects:'
    for obj in old_display.objects:
        if obj.__class__ == frame:
            print 'old_class_frame_obj', obj
            frames[obj] = obj.__copy__( frame=None, display=new_display)
            #objをnew_displayにコピーして辞書framesのobjキーにその値を登録する
            #frame()関数で作られたフレームはすべて、この辞書に入る
            #window_copy4.pyでいえば f f0
            #frames = {'f':copy_f, 'f0':copy_f0}
        else:
            print 'old_other_obj', obj
            #window_copy4.pyでいえば f f0 以外のすべてのオブジェクト  


    # For each old reference frame that was within another reference frame,
    # place the new reference frame within the appropriate frame in the new
    # display. Here old is an object and new is its frame in the new display.
    # 古いやつを新しいやつに配置する?
    # 「辞書オブジェクト.iteritems()」はキーと値のペアのタプルのイテレータを返します。
    #下のコードはなにをしているのかわからない
    #コードをコメントアウトしても大丈夫みたいだが......
    #違った。フレームの中にさらにフレームがある場合のコード
    print '---------------------------------'
    print 'for old, new in frames.iteritems():'
    for old, new in frames.iteritems():
        print '***********'
        print 'old_class_frame_obj' ,old
        print 'new_class_frame_obj' ,new
        if old.frame:
            print 'if old.frame:文内'
            #フレームがさらにフレームを持てば。ここでは fのこと
            #old:f new:copy_f old.frame:f0 
            #frames = {'f':copy_f, 'f0':copy_f0} だから
            #copy_f.frame = frames['f0']
            #すなわち copy_f0
            #フレームのコピーされた状態でのフレームの入れ子状態
            #を作成している
            new.frame = frames[old.frame]
            print 'old.frame', old.frame

    # Copy over the universe.
    #宇宙をコピー
    for obj in old_display.objects:
        #print 'obj.frame', obj.frame
        #↑のようにコードをかいてもNoneとなる
        # if obj.frame:文のなかで書かないと表示されないかな?
        if obj.__class__ == frame:
            print 'if obj.__class__ == frame:'
            print obj
            #特にこのコードいらないと思うが......
            # Already taken care of above.
            # すでに上の世話を
            #continue文を使用すると、それ以降の処理を行わず、for文やwhile文のブロックの先頭に戻ります
            continue
        if obj.frame:
            print 'if obj.frame:'
            print obj
            #frameをもったオブジェクトをコピーする 
            #obj.frame: このオブジェクトのフレーム
            # Then initialize with the corresponding reference frame in the new
            # display.
            #次に、新しいディスプレイ内の対応する参照フレームで初期化
            obj.__copy__( display=new_display, frame=frames[obj.frame])
        else:
            print 'else:'
            print obj
            #フレームを持たないオブジェクトのコピー
            # Don't need to care about the frame attribute, since it is None.
            #それはどれもないので、フレーム属性を気にする必要はありません。
            obj.__copy__( display=new_display)







window_copy4.py
# coding: UTF-8
from visual import *
import window_copy

scene1 = display(title='old_display', x=0, y=0)
scene1.forward=(-1.0, -0.5, -1.0)
#座標の方向の矢印
f0 = frame()
f0.pos = (7, 0, 0)
f = frame(frame=f0)
f.pos = (0, 3, 0)

mybox = box(frame=f, pos=(0,0,0), length=5, height=1, width=2)
pointer2 = arrow(pos=(0,0,0), axis=(0,7,0), shaftwidth=0.1 ,color=color.blue)
#y軸 青

scene2 = display(title='new_display', x=450, y=0)
window_copy.clone_universe(scene2, scene1)

#new_pointer1 = pointer1.__copy__(display=scene2)



#for obj in scene1.objects:
#    #obj.__copy__(display=scene2)
#    #↑のコードは間違い でも動くが....下のコードがただしい
#    obj.__copy__(frame=None, display=scene2)

#ang = 0.1
#while True:
#    mybox.rotate(angle=ang, axis=(0,1,0))
#    mybox2.rotate(angle=ang, axis=(0,1,0))


0 件のコメント:

コメントを投稿

About

参加ユーザー

連絡フォーム

名前

メール *

メッセージ *

ページ

Featured Posts