Interactive/DisplayWalkZoneCustom.py

# (C) Copyright 2012 Autodesk, Inc.  All rights reserved.
#
# Use of this software is subject to the terms of the Autodesk license
# agreement provided at the time of installation or download, or which
# otherwise accompanies this software in either electronic or hard copy
# form.

# You will need Autodesk Showcase 2012 or later
#
# If active, this add-in will provide menu items for displaying or hiding
# the Kynapse internal walk-zone meshes.

__all__ = ['DisplayWalkZone', 'instantiate']

from MessageRegistry        import theMessageRegistry
from MessageInterpreter     import MessageInterpreter
from UserCustomization      import (UserCustomBase, CustomInfo)
from MessagingAPI           import MessageSender
from RTFapi                 import KynapseManager


DISPLAY_WALKZONE_MESH_Doc = \
[(
"""
Enable or disable the walk zone mesh display.
"""
),
[[("enable"),("True to turn it on, False to turn it off.")],
 ]
]

DISPLAY_WALKGRAPH_MESH_Doc = \
[(
"""
Enable or disable the walk graph display.
"""
),
[[("enable"),("True to turn it on, False to turn it off.")],
 ]
]


theMessageRegistry.register("DISPLAY_WALKZONE_MESH",
    (bool,), 0, DISPLAY_WALKZONE_MESH_Doc)

theMessageRegistry.register("DISPLAY_WALKGRAPH_MESH",
    (bool,), 0, DISPLAY_WALKGRAPH_MESH_Doc)


class DisplayWalkZone( UserCustomBase, MessageSender ):

    def __init__(self):
        self.__myMenu = None
        self.__myInterp = LocalInterp()
        
    def getInterpreter(self,isInteractive):
        if isInteractive:
            return self.__myInterp
        return None

    def appendMenuItems( self, id, menu ):
        if "View" == id:
            self.__myMenu = menu
            menu.appendSeparator()
            self.__myWalkZoneDisplay  = menu.appendCheckItem(_("Display Walk Zone"), self.__onWalkZoneDisplay )
            self.__myWalkGraphDisplay = menu.appendCheckItem(_("Display Walk Graph"), self.__onWalkGraphDisplay )

    def __onWalkZoneDisplay( self, *args ) :
        isOn = bool(self.__myMenu.IsChecked(self.__myWalkZoneDisplay))
        self.__myInterp.sendMessage( "DISPLAY_WALKZONE_MESH", (isOn, ) )

    def __onWalkGraphDisplay( self, *args ) :
        isOn = bool(self.__myMenu.IsChecked(self.__myWalkGraphDisplay))
        self.__myInterp.sendMessage( "DISPLAY_WALKGRAPH_MESH", (isOn, ) )

# -----------------------------------------------------------------------

class LocalInterp( MessageInterpreter ):

    def __init__( self ):
        MessageInterpreter.__init__( self )

    def DISPLAY_WALKZONE_MESH( self, message ):
        if KynapseManager.exists():
            kynapseManager = KynapseManager.instance()
            if kynapseManager.hasPathData() and kynapseManager.isEnabled():
                (enable,) = message.data
                kynapseManager.displayWalkzoneMesh( enable )

    def DISPLAY_WALKGRAPH_MESH( self, message ):
        if KynapseManager.exists():
            kynapseManager = KynapseManager.instance()
            if kynapseManager.hasPathData() and kynapseManager.isEnabled():
                (enable,) = message.data
                kynapseManager.displayGraphMesh( enable )

# --------------------------------------------------------------------

def instantiate():
    return DisplayWalkZone()

def info():
    customInfo = CustomInfo()
    customInfo.vendor = 'Autodesk'
    customInfo.version = '1.0'
    customInfo.api = '2013'
    customInfo.shortInfo = "Display the walk zone"
    customInfo.longInfo = \
"""Enable or disable the kynapse walk zone display."""
    return customInfo


if __name__ == '__main__' :
    bfu = instantiate()