Example #1
0
        def getNewActors(self):
            # return a dictionary containing all available actors that are not in the
            # scenario's director.
            vi = self.application
            director = self._director()
            autotrackDict = director.autotrackDict
            if not vi.eventListeners.has_key(AddObjectEvent):
                func = self.getNewActor_cb
                vi.registerListener(AddObjectEvent, func)
            newDict = {}
            actornames = map(lambda x: x.name, director.actors[1:])
            
            allobjects = []
            for object in vi.rootObject.AllObjects():
                ## if object.name != "root":
##                     v = hasattr(object, 'vertexSet')
##                     f = hasattr(object, 'faceSet')
##                     if v and f:
##                         numv = len(object.vertexSet)
##                         numf = len(object.faceSet)
##                         if numv == numf == 0:
##                             continue
##                     elif v:
##                         numv = len(object.vertexSet)
##                         if numv == 0:
##                             continue
##                 if not object.visible:
##                     continue
                if object.listed:
                    # FIX THIS: we probably do not need to track all of the objects (too many actors),
                    # currently, do not include Viewer's objects under 'root|misc' and 'selection' objects
                    if object.fullName.find("misc") < 0 and object.fullName.find("selection") < 0:
                        allobjects.append(object)
            for c in vi.cameras:
                allobjects.append(c)
            for lt in vi.lights:
                if lt.enabled:
                    allobjects.append(lt)
            if vi.activeClippingPlanes > 0:
                allobjects.append(vi.currentClip)
                #for cp in vi.clipP:
                #    if cp.enabled:
                #        allobjects.append(cp)
            for object in allobjects:
                #self.setCurrentObjectAttrList(object)
                props = getAnimatableAttributes(object)[0]
                #print "object : ", object, props.keys()
                for propname in props.keys():
                    descr = props[propname]
                    actorname = getActorName(object, propname)
                    if not autotrackDict.has_key(actorname):
                        if not actorname in actornames:
                            # actor 'actorname' does not exist - create it and add to
                            # newDict
                            actorClass, args, kw = descr['actor']
                            actor = actorClass( *(propname, object)+args, **kw )
                            actor.scenario = self
                            newDict[actorname] = actor
            return newDict
Example #2
0
        def setCurrentObjectAttrList(self, object, event=None):

            if not hasattr(object, 'animatableProps'):
                object.animatableProps = getAnimatableAttributes(object)
            #if not hasattr(object, 'animatedProperties'):
            #    object.animatedProperties = {}

            self.createCheckbuttons(object)
Example #3
0
def getActor(object, propname):
    """
    create an actor from a DejaVu object instance and a property name.

    Actor <- getActor(object, propname)

    object is an instance of a DejaVu obbject (e.g. Geom, Camera, etc)
    propname is the name of the attribute in object that willbe animated
    """
    animatableProps = getAnimatableAttributes(object)
    if not animatableProps[0].has_key(propname):
        print "DejaVu.scenarioInterface.getActor: cannot create %s actor for object:" % (propname,), object
        return None
    descr = animatableProps[0][propname]
    actorname = getActorName(object, propname)

    actorClass, args, kw = descr['actor']
    actor = actorClass( *(propname, object)+args, **kw )
    return actor
Example #4
0
 def getNewActor_cb(self, event):
     object = event.object
     if object.listed:
         if hasattr(object, "fullName"):
             if object.fullName.find("selection") >= 0:
                 return
         vi = self.application
         director = self._director()
         autotrackDict = director.autotrackDict
         props = getAnimatableAttributes(object)[0]
         #print "object : ", object, props.keys()
         for propname in props.keys():
             descr = props[propname]
             actorname = getActorName(object, propname)
             if not autotrackDict.has_key(actorname):
                 actorClass, args, kw = descr['actor']
                 actor = actorClass( *(propname, object)+args, **kw )
                 actor.scenario = self
                 autotrackDict[actorname] = actor
                 if actor.hasGetFunction:
                     val = actor.getValueFromObject()
                 else:
                     val = None
Example #5
0
        def createActor(self, object, propname, variable = None, check = True,
                        addToDirector = True, actorData=None,
                        redraw = True, valueGenerator = None):
            #if not object.hasBeenCurrent :
            #    self.setCurrentObjectAttrList(object)
            #if not hasattr(object, 'animatedProperties'):
            #    object.animatedProperties = {}
            if not hasattr(object, 'animatableProps'):
                object.animatableProps = getAnimatableAttributes(object)
            # create an actor for object.propname
            descr = object.animatableProps[0][propname]
            actorname = getActorName(object, propname)
            director = self._director()
            newactor = True
            if check:
                for i, a in enumerate(director.actors):
                    if a.name == actorname:
                        text = "Actor %s exists. Do you want to overwrite it?\n"%actorname
                        d = SimpleDialog(director.gui.root, text=text,
                                         buttons=["Yes", "No"],
                                         default=1, title="Overwrite Actor Dialog")
                        result = d.go()

                        if result == 1:
                            return None
                        else:
                            newactor = False #
                            actorind = i
                            break
            #create the actor
            actorClass, args, kw = descr['actor']
            if valueGenerator is not None:
                kw['interp'] = valueGenerator
            if actorData is not None:
                from scenario.actor import FileActor
                actor = FileActor(*(propname, object, actorClass, actorData)+args, **kw)
                actorname = actor.name
            else:
                actor = actorClass( *(propname, object)+args, **kw )
            actor.scenario = self
            #object.animatedProperties[actorname] = actor
            self.animatedProperties[actorname] = actor
            if not newactor: # director already has an actor with name "actorname",
                             # and the user wishes to overwrite it
                # replace existing actor whith the new one
                oldactor = director.actors.pop(actorind)
                director.gui.deleteActor(oldactor)
                director.actors.insert(actorind, actor)
                actor._director = weakref.ref(director)
                posy = oldactor._posy
                director.gui.drawActor(actor, posy)
                if oldactor.guiVar:
                    variable = oldactor.guiVar
            
            else:
                if addToDirector:
                    # add actor to the director
                    director.addActor(actor, redraw)
            if variable:
                actor.guiVar = variable
            return actor