def _create_view(view_xml_name): "Creates and returns a 3D render view." view = servermanager._create_view(view_xml_name) servermanager.ProxyManager().RegisterProxy("views", \ "my_view%d" % _funcs_internals.view_counter, view) active_objects.view = view _funcs_internals.view_counter += 1 tk = servermanager.ProxyManager().GetProxiesInGroup( "timekeeper").values()[0] views = tk.Views if not view in views: views.append(view) return view
def _disconnect(): servermanager.ProxyManager().UnRegisterProxies() active_objects.view = None active_objects.source = None import gc gc.collect() servermanager.Disconnect()
def ReverseConnect(port=11111): """Create a reverse connection to a server. Listens on port and waits for an incoming connection from the server.""" _disconnect() cid = servermanager.ReverseConnect(port) servermanager.ProxyManager().RegisterProxy("timekeeper", "tk", servermanager.misc.TimeKeeper()) return cid
def get_animation_cue_proxy_registration_name(proxy): """Assuming the give proxy is registered in the group "animation", lookup the proxy's registration name with the servermanager""" if proxy.GetXMLName() == "KeyFrameAnimationCue" or \ proxy.GetXMLName() == "CameraAnimationCue" or \ proxy.GetXMLName() == "TimeAnimationCue": return servermanager.ProxyManager().GetProxyName("animation", proxy) return None
def __get_selection_model(self, name): "Internal method." pxm = servermanager.ProxyManager() model = pxm.GetSelectionModel(name) if not model: model = servermanager.vtkSMProxySelectionModel() pxm.RegisterSelectionModel(name, model) return model
def _GetRepresentationAnimationHelper(sourceproxy): """Internal method that returns the representation animation helper for a source proxy. It creates a new one if none exists.""" # ascertain that proxy is a source proxy if not sourceproxy in GetSources().values(): return None for proxy in servermanager.ProxyManager(): if proxy.GetXMLName() == "RepresentationAnimationHelper" and\ proxy.GetProperty("Source").IsProxyAdded(sourceproxy.SMProxy): return proxy # create a new helper proxy = servermanager.misc.RepresentationAnimationHelper( Source=sourceproxy) servermanager.ProxyManager().RegisterProxy( "pq_helper_proxies.%s" % sourceproxy.GetGlobalIDAsString(), "RepresentationAnimationHelper", proxy) return proxy
def Connect(ds_host=None, ds_port=11111, rs_host=None, rs_port=11111): """Creates a connection to a server. Example usage: > Connect("amber") # Connect to a single server at default port > Connect("amber", 12345) # Connect to a single server at port 12345 > Connect("amber", 11111, "vis_cluster", 11111) # connect to data server, render server pair""" _disconnect() cid = servermanager.Connect(ds_host, ds_port, rs_host, rs_port) servermanager.ProxyManager().RegisterProxy("timekeeper", "tk", servermanager.misc.TimeKeeper()) return cid
def __init__(self, proxy): # Store the proxy, name, and group if isinstance(proxy, servermanager.Proxy): proxy = proxy.SMProxy for proxy_group in _proxy_groups: proxy_name = servermanager.ProxyManager().IsProxyInGroup(proxy, proxy_group) if proxy_name: self.proxy_name = proxy_name self.proxy_group = proxy_group self.proxy = proxy return
def _create_view(view_xml_name): "Creates and returns a 3D render view." view = servermanager._create_view(view_xml_name) servermanager.ProxyManager().RegisterProxy("views", \ "my_view%d" % _funcs_internals.view_counter, view) active_objects.view = view _funcs_internals.view_counter += 1 tk = servermanager.ProxyManager().GetProxiesInGroup( "timekeeper").values()[0] views = tk.Views if not view in views: views.append(view) try: scene = GetAnimationScene() if not view in scene.ViewModules: scene.ViewModules.append(view) except servermanager.MissingProxy: pass return view
def RenameSource(newName, proxy=None): """Renames the given source. If the given proxy is not registered in the sources group this method will have no effect. If no source is provided, the active source is used.""" if not proxy: proxy = active_objects.source pxm = servermanager.ProxyManager() oldName = pxm.GetProxyName("sources", proxy) if oldName: pxm.RegisterProxy("sources", newName, proxy) pxm.UnRegisterProxy("sources", oldName, proxy)
def get_sorted_proxies_in_group(group_name): """Returns the list of proxies registered in the given group name. The returned list of proxies will be sorted by the proxy's id.""" # GetProxiesInGroup returns a dictionary of the form: # { ('proxy_name', 'proxy_id') : proxy } # We want to return the dictionary values (list of proxies) sorted by proxy_id. dict_items = servermanager.ProxyManager().GetProxiesInGroup(group_name).items() dict_items.sort(lambda a, b: cmp(int(a[0][1]), int(b[0][1]))) sorted_proxy_list = [pair[1] for pair in dict_items] return sorted_proxy_list
def ReverseConnect(port=11111): """Create a reverse connection to a server. Listens on port and waits for an incoming connection from the server.""" _disconnect() session = servermanager.ReverseConnect(port) _add_functions(globals()) tk = servermanager.misc.TimeKeeper() servermanager.ProxyManager().RegisterProxy("timekeeper", "tk", tk) scene = AnimationScene() scene.TimeKeeper = tk return session
def AddCameraLink(viewProxy, viewProxyOther, linkName): """Create a camera link between two view proxies. A name must be given so that the link can be referred to by name. If a link with the given name already exists it will be removed first.""" if not viewProxyOther: viewProxyOther = GetActiveView() link = servermanager.vtkSMCameraLink() link.AddLinkedProxy(viewProxy.SMProxy, 1) link.AddLinkedProxy(viewProxyOther.SMProxy, 2) link.AddLinkedProxy(viewProxyOther.SMProxy, 1) link.AddLinkedProxy(viewProxy.SMProxy, 2) RemoveCameraLink(linkName) servermanager.ProxyManager().RegisterLink(linkName, link)
def LoadDistributedPlugin(pluginname, remote=True, ns=None): """Loads a plugin that's distributed with the executable. This uses the information known about plugins distributed with ParaView to locate the shared library for the plugin to load. Raises a RuntimeError if the plugin was not found.""" plm = servermanager.ProxyManager().GetSession().GetPluginManager() if remote: info = plm.GetRemoteInformation() else: info = plm.GetLocalInformation() for cc in range(0, info.GetNumberOfPlugins()): if info.GetPluginName(cc) == pluginname: return LoadPlugin(info.GetPluginFileName(cc), remote, ns) raise RuntimeError, "Plugin '%s' not found" % pluginname
def Connect(ds_host=None, ds_port=11111, rs_host=None, rs_port=11111): """Creates a connection to a server. Example usage: > Connect("amber") # Connect to a single server at default port > Connect("amber", 12345) # Connect to a single server at port 12345 > Connect("amber", 11111, "vis_cluster", 11111) # connect to data server, render server pair""" _disconnect() session = servermanager.Connect(ds_host, ds_port, rs_host, rs_port) _add_functions(globals()) tk = servermanager.misc.TimeKeeper() servermanager.ProxyManager().RegisterProxy("timekeeper", "tk", tk) scene = AnimationScene() scene.TimeKeeper = tk return session
def GetRepresentation(proxy=None, view=None): """"Given a pipeline object and view, returns the corresponding representation object. If pipeline object and view are not specified, active objects are used.""" if not view: view = active_objects.view if not proxy: proxy = active_objects.source rep = servermanager.GetRepresentation(proxy, view) if not rep: rep = servermanager.CreateRepresentation(proxy, view) servermanager.ProxyManager().RegisterProxy("representations", \ "my_representation%d" % _funcs_internals.rep_counter, rep) _funcs_internals.rep_counter += 1 return rep
def OpenDataFile(filename, **extraArgs): """Creates a reader to read the give file, if possible. This uses extension matching to determine the best reader possible. If a reader cannot be identified, then this returns None.""" reader_factor = servermanager.ProxyManager().GetReaderFactory() if reader_factor.GetNumberOfRegisteredPrototypes() == 0: reader_factor.RegisterPrototypes("sources") session = servermanager.ActiveConnection.Session first_file = filename if type(filename) == list: first_file = filename[0] if not reader_factor.TestFileReadability(first_file, session): raise RuntimeError, "File not readable: %s " % first_file if not reader_factor.CanReadFile(first_file, session): raise RuntimeError, "File not readable. No reader found for '%s' " % first_file prototype = servermanager.ProxyManager().GetPrototypeProxy( reader_factor.GetReaderGroup(), reader_factor.GetReaderName()) xml_name = paraview.make_name_valid(prototype.GetXMLLabel()) reader_func = _create_func(xml_name, servermanager.sources) if prototype.GetProperty("FileNames"): reader = reader_func(FileNames=filename, **extraArgs) else: reader = reader_func(FileName=filename, **extraArgs) return reader
def GetAnimationScene(): """Returns the application-wide animation scene. ParaView has only one global animation scene. This method provides access to that. Users are free to create additional animation scenes directly, but those scenes won't be shown in the ParaView GUI.""" animation_proxies = servermanager.ProxyManager().GetProxiesInGroup( "animation") scene = None for aProxy in animation_proxies.values(): if aProxy.GetXMLName() == "AnimationScene": scene = aProxy break if not scene: raise servermanager.MissingProxy, "Could not locate global AnimationScene." return scene
def CreateWriter(filename, proxy=None, **extraArgs): """Creates a writer that can write the data produced by the source proxy in the given file format (identified by the extension). If no source is provided, then the active source is used. This doesn't actually write the data, it simply creates the writer and returns it.""" if not filename: raise RuntimeError, "filename must be specified" writer_factory = servermanager.ProxyManager().GetWriterFactory() if writer_factory.GetNumberOfRegisteredPrototypes() == 0: writer_factory.RegisterPrototypes("writers") if not proxy: proxy = GetActiveSource() if not proxy: raise RuntimeError, "Could not locate source to write" writer_proxy = writer_factory.CreateWriter(filename, proxy.SMProxy, proxy.Port) return servermanager._getPyProxy(writer_proxy)
def GetLookupTableForArray(arrayname, num_components, **params): """Used to get an existing lookuptable for a array or to create one if none exists. Keyword arguments can be passed in to initialize the LUT if a new one is created.""" proxyName = "%d.%s.PVLookupTable" % (int(num_components), arrayname) lut = servermanager.ProxyManager().GetProxy("lookup_tables", proxyName) if lut: return lut # No LUT exists for this array, create a new one. # TODO: Change this to go a LookupTableManager that is shared with the GUI, # so that the GUI and python end up create same type of LUTs. For now, # python will create a Blue-Red LUT, unless overridden by params. lut = servermanager.rendering.PVLookupTable( ColorSpace="HSV", RGBPoints=[0, 0, 0, 1, 1, 1, 0, 0]) SetProperties(lut, **params) servermanager.Register(lut, registrationName=proxyName) return lut
def __GetLookupTableForArray(self, aArray, **kwargs): """ Set the lookup table for the given array and assign the named properties. """ proxyName = '%d.%s.PVLookupTable' % (aArray.GetNumberOfComponents(), aArray.GetName()) lut = servermanager.ProxyManager().GetProxy('lookup_tables', proxyName) if not lut: lut = servermanager.rendering.PVLookupTable( ColorSpace="HSV", RGBPoints=[0, 0, 0, 1, 1, 1, 0, 0]) servermanager.Register(lut, registrationName=proxyName) for arg in kwargs.keys(): if not hasattr(lut, arg): raise AttributeError("LUT has no property %s" % (arg)) setattr(lut, arg, kwargs[arg]) return lut
def _trace_state(): """This method using the smtrace module to trace each registered proxy and generate a python trace script. The proxies must be traced in the correct order so that no traced proxy refers to a proxy that is yet to be traced.""" # Start trace smtrace.start_trace(CaptureAllProperties=True, UseGuiName=True) # Get proxy lists by group. Order is very important here. The idea is that # we want to register groups of proxies such that when a proxy is registered # none of its properties refer to proxies that have not yet been registered. # # rules: # # scalar_bars refer to lookup_tables. # representations refer to sources and piecewise_functions # views refer to representations and scalar_bars proxy_groups = [ "implicit_functions", "piecewise_functions", "lookup_tables", "scalar_bars", "sources", "representations", "views" ] # Collect the proxies using a list comprehension get_func = servermanager.ProxyManager().GetProxiesInGroup proxy_lists = [ get_func(proxy_group).values() for proxy_group in proxy_groups ] # Now register the proxies with the smtrace module for proxy_list in proxy_lists: register_proxies_by_dependency(proxy_list) # Calling append_trace causes the smtrace module to sort out all the # registered proxies and their properties and write them as executable # python. smtrace.append_trace() # Stop trace and print it to the console smtrace.stop_trace() smtrace.print_trace()
def Delete(proxy=None): """Deletes the given pipeline object or the active source if no argument is specified.""" if not proxy: proxy = active_objects.source # Unregister any helper proxies stored by a vtkSMProxyListDomain for prop in proxy: listdomain = prop.GetDomain('proxy_list') if listdomain: if listdomain.GetClassName() != 'vtkSMProxyListDomain': continue group = "pq_helper_proxies." + proxy.GetSelfIDAsString() for i in xrange(listdomain.GetNumberOfProxies()): pm = servermanager.ProxyManager() iproxy = listdomain.GetProxy(i) name = pm.GetProxyName(group, iproxy) if iproxy and name: pm.UnRegisterProxy(group, name, iproxy) # Remove source/view from time keeper tk = servermanager.ProxyManager().GetProxiesInGroup( "timekeeper").values()[0] if isinstance(proxy, servermanager.SourceProxy): try: idx = tk.TimeSources.index(proxy) del tk.TimeSources[idx] except ValueError: pass else: try: idx = tk.Views.index(proxy) del tk.Views[idx] except ValueError: pass servermanager.UnRegister(proxy) # If this is a representation, remove it from all views. if proxy.SMProxy.IsA("vtkSMRepresentationProxy"): for view in GetRenderViews(): view.Representations.remove(proxy) # If this is a source, remove the representation iff it has no consumers # Also change the active source if necessary elif proxy.SMProxy.IsA("vtkSMSourceProxy"): sources = servermanager.ProxyManager().GetProxiesInGroup("sources") for i in range(proxy.GetNumberOfConsumers()): if proxy.GetConsumerProxy(i) in sources: raise RuntimeError( "Source has consumers. It cannot be deleted " + "until all consumers are deleted.") if proxy == GetActiveSource(): if hasattr(proxy, "Input") and proxy.Input: if isinstance(proxy.Input, servermanager.Proxy): SetActiveSource(proxy.Input) else: SetActiveSource(proxy.Input[0]) else: SetActiveSource(None) for rep in GetRepresentations().values(): if rep.Input == proxy: Delete(rep) # Change the active view if necessary elif proxy.SMProxy.IsA("vtkSMRenderViewProxy"): if proxy == GetActiveView(): if len(GetRenderViews()) > 0: SetActiveView(GetRenderViews()[0]) else: SetActiveView(None)
def get_lookuptable_proxy_registration_name(proxy): """Assuming the give proxy is registered in the group "lookup_tables", lookup the proxy's registration name with the servermanager""" return servermanager.ProxyManager().GetProxyName("lookup_tables", proxy)
def get_animation_scene_proxy_registration_name(proxy): """Assuming the give proxy is registered in the group "animation", lookup the proxy's registration name with the servermanager""" if proxy.GetXMLName() == "AnimationScene": return servermanager.ProxyManager().GetProxyName("animation", proxy) return None
def get_representation_proxy_registration_name(proxy): """Assuming the given proxy is registered in the group 'representations', lookup the proxy's registration name with the servermanager""" return servermanager.ProxyManager().GetProxyName("representations", proxy)
def GetSources(): """Given the name of a source, return its Python object.""" return servermanager.ProxyManager().GetProxiesInGroup("sources")
def GetRepresentations(): """Returns all representations (display properties).""" return servermanager.ProxyManager().GetProxiesInGroup("representations")
def RemoveCameraLink(linkName): """Remove a camera link with the given name.""" servermanager.ProxyManager().UnRegisterLink(linkName)
def CreateObject(*input, **params): """This function creates a new proxy. For pipeline objects that accept inputs, all non-keyword arguments are assumed to be inputs. All keyword arguments are assumed to be property,value pairs and are passed to the new proxy.""" # Instantiate the actual object from the given module. px = module.__dict__[key]() # Make sure non-keyword arguments are valid for inp in input: if inp != None and not isinstance(inp, servermanager.Proxy): if px.GetProperty("Input") != None: raise RuntimeError, "Expecting a proxy as input." else: raise RuntimeError, "This function does not accept non-keyword arguments." # Assign inputs if px.GetProperty("Input") != None: if len(input) > 0: px.Input = input else: # If no input is specified, try the active pipeline object if px.GetProperty("Input").GetRepeatable( ) and active_objects.get_selected_sources(): px.Input = active_objects.get_selected_sources() elif active_objects.source: px.Input = active_objects.source else: if len(input) > 0: raise RuntimeError, "This function does not expect an input." registrationName = None for nameParam in ['registrationName', 'guiName']: if nameParam in params: registrationName = params[nameParam] del params[nameParam] # Pass all the named arguments as property,value pairs for param in params.keys(): setattr(px, param, params[param]) try: # Register the proxy with the proxy manager. if registrationName: group, name = servermanager.Register( px, registrationName=registrationName) else: group, name = servermanager.Register(px) # Register pipeline objects with the time keeper. This is used to extract time values # from sources. NOTE: This should really be in the servermanager controller layer. if group == "sources": tk = servermanager.ProxyManager().GetProxiesInGroup( "timekeeper").values()[0] sources = tk.TimeSources if not px in sources: sources.append(px) active_objects.source = px except servermanager.MissingRegistrationInformation: pass return px