--- ./ParaView3/Utilities/VTKPythonWrapping/paraview/servermanager.py 2008-04-04 12:04:38.000000000 -0400 +++ ./ParaView3.new/Utilities/VTKPythonWrapping/paraview/servermanager.py 2008-09-10 18:41:05.000000000 -0400 @@ -264,7 +264,7 @@ vtkPVDataInformation""" if self.SMProxy: return DataInformation( \ - self.SMProxy.GetDataInformation(idx, False), \ + self.SMProxy.GetDataInformation(idx), \ self.SMProxy, idx) class Property(object): @@ -330,6 +330,15 @@ val = property[2] property[1:3] = (1, 2) """ + def ConvertValue(self, value): + """Converts value to type suitable for vtSM.Property::SetElement()""" + if self.SMProperty.IsA("vtkSMIntVectorProperty") and \ + self.SMProperty.GetDomain("enum") and type(value) == str: + domain = self.SMProperty.GetDomain("enum") + if domain.HasEntryText(value): + return domain.GetEntryValueForText(value) + return value + def __len__(self): """Returns the number of elements.""" @@ -344,7 +353,7 @@ def __setitem__(self, idx, value): """Given an index and a value, sets an element.""" - self.SMProperty.SetElement(idx, value) + self.SMProperty.SetElement(idx, self.ConvertValue(value)) self._UpdateProperty() def __getslice__(self, min, max): @@ -362,7 +371,7 @@ if min < 0 or min > len(self) or max < 0 or max > len(self): raise exceptions.IndexError for i in range(min, max): - self.SMProperty.SetElement(i, values[i-min]) + self.SMProperty.SetElement(i, self.ConvertValue(values[i-min])) self._UpdateProperty() def __getattr__(self, name): @@ -386,7 +395,7 @@ not isinstance(values, list): values = (values,) for i in range(len(values)): - self.SMProperty.SetElement(i, values[i]) + self.SMProperty.SetElement(i, self.ConvertValue(values[i])) self._UpdateProperty() def Clear(self): @@ -604,11 +613,14 @@ self.Idx = idx def Update(self): - """Update the data information if necessary. Note that this + """****Deprecated**** There is no reason anymore to use this method + explicitly, it is called automatically when one gets any value from the + data information object. + Update the data information if necessary. Note that this does not cause execution of the underlying object. In certain cases, you may have to call UpdatePipeline() on the proxy.""" if self.Proxy: - self.Proxy.GetDataInformation(self.Idx, False) + self.Proxy.GetDataInformation(self.Idx) def GetDataSetType(self): """Returns the dataset type as defined in vtkDataObjectTypes.""" @@ -1105,21 +1117,16 @@ if not connection: raise exceptions.RuntimeError, "Cannot load state without a connection" loader = vtkSMPQStateLoader() - rvname = vtkSMRenderViewProxy.GetSuggestedRenderViewType(connection.ID) - if rvname: - loader.SetRenderViewXMLName(rvname) - pm = ProxyManager() - pm.LoadState(filename, ActiveConnection.ID, loader) - views = GetRenderViews() - for view in views: - # Make sure that the client window size matches the - # ViewSize property. In paraview, the GUI takes care - # of this. - if view.GetClassName() == "vtkSMIceTDesktopRenderViewProxy": - view.GetRenderWindow().SetSize(view.ViewSize[0], \ - view.ViewSize[1]) - else: - raise exceptions.RuntimeError, "Could not load state because no appropriate render view was found." + pm = ProxyManager() + pm.LoadState(filename, ActiveConnection.ID, loader) + views = GetRenderViews() + for view in views: + # Make sure that the client window size matches the + # ViewSize property. In paraview, the GUI takes care + # of this. + if view.GetClassName() == "vtkSMIceTDesktopRenderViewProxy": + view.GetRenderWindow().SetSize(view.ViewSize[0], \ + view.ViewSize[1]) def Connect(ds_host=None, ds_port=11111, rs_host=None, rs_port=11111): """ @@ -1137,6 +1144,9 @@ render server on rs_host: rs_port. """ global ActiveConnection + global fromGUI + if fromGUI: + raise exceptions.RuntimeError, "Cannot create a connection through python. Use the GUI to setup the connection." if ds_host == None: connectionId = _connectSelf() elif rs_host == None: @@ -1159,6 +1169,9 @@ The optional port specified the port to listen to. """ global ActiveConnection + global fromGUI + if fromGUI: + raise exceptions.RuntimeError, "Cannot create a connection through python. Use the GUI to setup the connection." connectionId = _connectServer("Reverse connection", port, True) if not ActiveConnection: ActiveConnection = connectionId @@ -1168,6 +1181,9 @@ """Disconnects the connection. Make sure to clear the proxy manager first.""" global ActiveConnection + global fromGUI + if fromGUI: + raise exceptions.RuntimeError, "Cannot disconnect through python. Use the GUI to disconnect." if not connection or connection == ActiveConnection: connection = ActiveConnection ActiveConnection = None @@ -1231,8 +1247,9 @@ if not connection: raise exceptions.RuntimeError, "Cannot create render window without connection." pxm = ProxyManager() - proxy_xml_name = vtkSMRenderViewProxy.GetSuggestedRenderViewType(\ - connection.ID) + prototype = pxm.GetPrototypeProxy("views", "RenderView") + + proxy_xml_name = prototype.GetSuggestedViewType(connection.ID) ren_module = None if proxy_xml_name: ren_module = CreateProxy("views", proxy_xml_name, connection) @@ -1305,7 +1322,7 @@ updateModules() -def Fetch(input, arg1=None, arg2=None): +def Fetch(input, arg1=None, arg2=None, idx=0): """ A convenience method that moves data from the server to the client, optionally performing some operation on the data as it moves. @@ -1331,31 +1348,35 @@ applied pre-gather and arg2 will be applied post-gather. In parallel runs the algorithm will be run on each processor to make intermediate results and then again on the root processor over all of the - intermediate results to create a global result. """ + intermediate results to create a global result. + + Optional argument idx is used to specify the output port number to fetch the + data from. Default is port 0. + """ import types #create the pipeline that reduces and transmits the data gvd = rendering.ClientDeliveryRepresentationBase() - gvd.AddInput(input, "DONTCARE") + gvd.AddInput(0, input, idx, "DONTCARE") if arg1 == None: print "getting appended" - cdinfo = input.GetDataInformation().GetCompositeDataInformation() + cdinfo = input.GetDataInformation(idx).GetCompositeDataInformation() if cdinfo.GetDataIsComposite(): print "use composite data append" gvd.SetReductionType(5) - elif input.GetDataInformation().GetDataClassName() == "vtkPolyData": + elif input.GetDataInformation(idx).GetDataClassName() == "vtkPolyData": print "use append poly data filter" gvd.SetReductionType(1) - elif input.GetDataInformation().GetDataClassName() == "vtkRectilinearGrid": + elif input.GetDataInformation(idx).GetDataClassName() == "vtkRectilinearGrid": print "use append rectilinear grid filter" gvd.SetReductionType(4) - elif input.GetDataInformation().IsA("vtkDataSet"): + elif input.GetDataInformation(idx).IsA("vtkDataSet"): print "use unstructured append filter" gvd.SetReductionType(2) @@ -1625,6 +1646,80 @@ mdl.__dict__[pname] = cobj return mdl + +def __determineGroup(proxy): + """Internal method""" + if not proxy: + return None + xmlgroup = proxy.GetXMLGroup() + xmlname = proxy.GetXMLName() + if xmlgroup == "sources": + return "sources" + elif xmlgroup == "filters": + return "sources" + elif xmlgroup == "views": + return "views" + elif xmlgroup == "representations": + if xmlname == "ScalarBarWidgetRepresentation": + return "scalar_bars" + return "representations"; + elif xmlgroup == "lookup_tables": + return "lookup_tables" + return None + +__nameCounter = 0 +def __determineName(proxy, group): + global __nameCounter + __nameCounter += 1 + return "%s%d" % (proxy.GetXMLName(), __nameCounter) + +def __getName(proxy, group): + pxm = ProxyManager() + if isinstance(proxy, Proxy): + proxy = proxy.SMProxy + return pxm.GetProxyName(group, proxy) + +def Register(proxy, **extraArgs): + """Registers a proxy with the proxy manager. If no 'registrationGroup' is + specified, then the group is inferred from the type of the proxy. + 'registrationName' may be specified to register with a particular name + otherwise a default name will be created.""" + # TODO: handle duplicate registration + if "registrationGroup" in extraArgs: + registrationGroup = extraArgs["registrationGroup"] + else: + registrationGroup = __determineGroup(proxy) + + if "registrationName" in extraArgs: + registrationName = extraArgs["registrationName"] + else: + registrationName = __determineName(proxy, registrationGroup) + if registrationGroup and registrationName: + pxm = ProxyManager() + pxm.RegisterProxy(registrationGroup, registrationName, proxy) + else: + raise exceptions.RuntimeError, "Registeration error." + return (registrationGroup, registrationName); + +def UnRegister(proxy, **extraArgs): + """UnRegisters proxies registered using Register().""" + if "registrationGroup" in extraArgs: + registrationGroup = extraArgs["registrationGroup"] + else: + registrationGroup = __determineGroup(proxy) + + if "registrationName" in extraArgs: + registrationName = extraArgs["registrationName"] + else: + registrationName = __getName(proxy, registrationGroup) + + if registrationGroup and registrationName: + pxm = ProxyManager() + pxm.UnRegisterProxy(registrationGroup, registrationName, proxy) + else: + raise exceptions.RuntimeError, "UnRegisteration error." + return (registrationGroup, registrationName); + def demo1(): """This simple demonstration creates a sphere, renders it and delivers it to the client using Fetch. It returns a tuple of (data, render