예제 #1
0
def getProxyAsState(id):
    """
    Return a json representation of the given proxy state.

    Example of the state of the Clip filter
      {
         proxy_id: 234,
         ClipType: {
            proxy_id: 235,
            Normal: [0,0,1],
            Origin: [0,0,0],
            InsideOut: 0
         }
      }
    """
    proxy_id = int(id)
    proxy = idToProxy(proxy_id)
    state = { 'proxy_id': proxy_id , 'type': 'proxy', 'domains': getProxyDomains(proxy_id)}
    properties = {}
    allowedTypes = [int, float, list, str]
    if proxy:
       for property in proxy.ListProperties():
          propertyName = proxy.GetProperty(property).Name
          if propertyName in ["Refresh", "Input"] or propertyName.__contains__("Info"):
             continue

          data = proxy.GetProperty(property).GetData()
          if type(data) in allowedTypes:
              properties[propertyName] = data
              continue

          # Not a simple property
          # Need more investigation
          prop = proxy.GetProperty(property)
          pythonProp = servermanager._wrap_property(proxy, prop)
          proxyList = []
          try:
            proxyList = pythonProp.Available
          except:
              pass
          if len(proxyList) and prop.GetNumberOfProxies() == 1:
            listdomain = prop.GetDomain('proxy_list')
            if listdomain:
              proxyPropertyValue = prop.GetProxy(0)
              for i in xrange(listdomain.GetNumberOfProxies()):
                if listdomain.GetProxy(i) == proxyPropertyValue:
                    properties[propertyName] = proxyList[i]
                    # Add selected proxy in list of prop to edit
                    properties[propertyName + '_internal'] = getProxyAsState(listdomain.GetProxy(i).GetGlobalID())

          elif type(prop) == ProxyProperty:
              try:
                  subProxyId = proxy.GetProperty(property).GetData().GetGlobalID()
                  properties[propertyName] = getProxyAsState(subProxyId)
              except:
                  print "Error on", property, propertyName
                  print "Skip property: ", str(type(data))
                  print data
    state['properties'] = properties;
    return state
예제 #2
0
파일: helper.py 프로젝트: mathstuf/ParaView
def updateProxyProperties(proxy, properties):
   """
   Loop over the properties object and update the mapping properties
   to the given proxy.
   """
   try:
       allowedProperties = proxy.ListProperties()
       for key in properties:
          validKey = servermanager._make_name_valid(key)
          if validKey in allowedProperties:
             value = removeUnicode(properties[key])
             property = servermanager._wrap_property(proxy, proxy.GetProperty(validKey))
             if property.GetDomain('proxy_list') and len(value) == 1 and type(value[0]) == str:
                 try:
                    idx = property.GetAvailable().index(value[0])
                    proxyToSet = servermanager._getPyProxy(property.GetDomain('proxy_list').GetProxy(idx))
                    property.SetData(proxyToSet)
                 except:
                    traceback.print_stack()
                    pass
             elif value == 'vtkProcessId':
                property.SetElement(0, value)
             else:
                property.SetData(value)
   except:
        traceback.print_stack()
예제 #3
0
def updateProxyProperties(proxy, properties):
    """
   Loop over the properties object and update the mapping properties
   to the given proxy.
   """
    try:
        allowedProperties = proxy.ListProperties()
        for key in properties:
            validKey = servermanager._make_name_valid(key)
            if validKey in allowedProperties:
                value = removeUnicode(properties[key])
                property = servermanager._wrap_property(
                    proxy, proxy.GetProperty(validKey))
                if property.GetDomain('proxy_list') and len(
                        value) == 1 and type(value[0]) == str:
                    try:
                        idx = property.GetAvailable().index(value[0])
                        proxyToSet = servermanager._getPyProxy(
                            property.GetDomain('proxy_list').GetProxy(idx))
                        property.SetData(proxyToSet)
                    except:
                        traceback.print_stack()
                        pass
                elif value == 'vtkProcessId':
                    property.SetElement(0, value)
                else:
                    property.SetData(value)
    except:
        traceback.print_stack()
예제 #4
0
def getProxyAsState(id):
    """
    Return a json representation of the given proxy state.

    Example of the state of the Clip filter
      {
         proxy_id: 234,
         ClipType: {
            proxy_id: 235,
            Normal: [0,0,1],
            Origin: [0,0,0],
            InsideOut: 0
         }
      }
    """
    proxy_id = int(id)
    proxy = idToProxy(proxy_id)
    state = { 'proxy_id': proxy_id , 'type': 'proxy', 'domains': getProxyDomains(proxy_id)}
    properties = {}
    allowedTypes = [int, float, list, str]
    if proxy:
        for property in proxy.ListProperties():
            propertyName = proxy.GetProperty(property).Name
            if propertyName in ["Refresh", "Input"] or propertyName.__contains__("Info"):
                continue

            data = proxy.GetProperty(property).GetData()
            if type(data) in allowedTypes:
                properties[propertyName] = data
                continue

            # Not a simple property
            # Need more investigation
            prop = proxy.GetProperty(property)
            pythonProp = servermanager._wrap_property(proxy, prop)
            proxyList = []
            try:
                proxyList = pythonProp.Available
            except:
                pass
            if len(proxyList) and prop.GetNumberOfProxies() == 1:
                listdomain = prop.GetDomain('proxy_list')
                if listdomain:
                    proxyPropertyValue = prop.GetProxy(0)
                    for i in xrange(listdomain.GetNumberOfProxies()):
                        if listdomain.GetProxy(i) == proxyPropertyValue:
                            properties[propertyName] = proxyList[i]
                            # Add selected proxy in list of prop to edit
                            properties[propertyName + '_internal'] = getProxyAsState(listdomain.GetProxy(i).GetGlobalID())

            elif type(prop) == ProxyProperty:
                try:
                    subProxyId = proxy.GetProperty(property).GetData().GetGlobalID()
                    properties[propertyName] = getProxyAsState(subProxyId)
                except:
                    print "Error on", property, propertyName
                    print "Skip property: ", str(type(data))
                    print data
    state['properties'] = properties;
    return state