[Smtk-developers] Python log of operations

David Thompson david.thompson at kitware.com
Wed Jun 3 19:28:10 EDT 2015


Hi all,

I am working on facilities for logging operations as they occur so that we can replay them later and adapt them in scripted functions. This branch:

  https://github.com/vibraphone/SMTK/commits/operator-log

contains my current work. There are many things not yet handled (especially references to model entities being acted upon) but this Python code

    self.mgr = smtk.model.Manager.create()
    sref = self.mgr.createSession('cgm')
    sref.assignDefaultName()
    SetActiveSession(sref)

    # Create a recorder.
    # It will immediately start logging all operations on the manager
    # (and only those on the specified model manager).
    self.recorder = smtk.log.PythonOperatorLog(self.mgr)

    sph = CreateSphere(radius=1.0, inner_radius=0.2, center=[0.2, 0.2, 0.2])
    sph2 = CreateSphere(radius=0.5, center=[0.9, 0., 0.])
    su = Union([sph, sph2])
    cyl = CreateCylinder(top_radius=1.0)
    b = CreateBrick(width=2, height=3, depth=5)

now generates the log below (which works except for the union operator which has model-entity associations). I hope to make things more compact as well, but the log does currently skip attributes with default values.

	David

from uuid import UUID
import smtk
from smtk.simple import *
mgr = smtk.model.Manager.create()
session1 = mgr.createSession('cgm')
session1.setName('session 1')

# Operator create sphere
op1 = session1.op('create sphere')
item0 = smtk.attribute.to_concrete(op1.specification().find('center'))
SetVectorValue(item0, [0.2, 0.2, 0.2])
item0 = smtk.attribute.to_concrete(op1.specification().find('inner radius'))
SetVectorValue(item0, [0.2])
res = op1.operate()

# Operator create sphere
op2 = session1.op('create sphere')
item0 = smtk.attribute.to_concrete(op2.specification().find('center'))
SetVectorValue(item0, [0.9, 0.0, 0.0])
item0 = smtk.attribute.to_concrete(op2.specification().find('radius'))
SetVectorValue(item0, [0.5])
res = op2.operate()

# Operator union
op3 = session1.op('union')
res = op3.operate()

# Operator create cylinder
op4 = session1.op('create cylinder')
item0 = smtk.attribute.to_concrete(op4.specification().find('major top radius'))
SetVectorValue(item0, [1.0])
res = op4.operate()

# Operator create brick
op5 = session1.op('create brick')
item0 = smtk.attribute.to_concrete(op5.specification().find('construction method'))
item1 = smtk.attribute.to_concrete(item0.chilrenItems['height'])
SetVectorValue(item1, [3.0])
item1 = smtk.attribute.to_concrete(item0.chilrenItems['width'])
SetVectorValue(item1, [2.0])
item1 = smtk.attribute.to_concrete(item0.chilrenItems['depth'])
SetVectorValue(item1, [5.0])
res = op5.operate()



More information about the Smtk-developers mailing list