def DumpPipeline(export_rendering, simulation_input_map, screenshot_info): global write_frequencies, cp_views, cp_writers # Initialize the write frequency map for key in simulation_input_map.values(): write_frequencies[key] = [] # Start trace smtrace.start_trace(CaptureAllProperties=True, UseGuiName=True) # update trace globals. smtrace.trace_globals.proxy_ctor_hook = staticmethod(cp_hook) smtrace.trace_globals.trace_output = [] # Get list of proxy lists proxy_lists = smstate.get_proxy_lists_ordered_by_group(WithRendering=export_rendering) # Now register the proxies with the smtrace module for proxy_list in proxy_lists: smstate.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() for view_proxy in view_proxies: # Locate which simulation input this write is connected to, if any. If so, # we update the write_frequencies datastructure accordingly. sim_inputs = cp_locate_simulation_inputs_for_view(view_proxy) proxyName = servermanager.ProxyManager().GetProxyName("views", view_proxy) image_write_frequency = screenshot_info[proxyName][1] for sim_input_name in sim_inputs: if not image_write_frequency in write_frequencies[sim_input_name]: write_frequencies[sim_input_name].append(image_write_frequency) write_frequencies[sim_input_name].sort() # Create global fields values pipelineClassDef = "write_frequencies = " + str(write_frequencies) + "\n" pipelineClassDef += "simulation_input_map = " + str(simulation_input_map) + "\n" pipelineClassDef += "\n" pipelineClassDef += "# ----------------------- Pipeline definition -----------------------\n\n" # Create the resulting string that will contains the pipeline definition pipelineClassDef += "def CreatePipeline(datadescription):\n" pipelineClassDef += " class Pipeline:\n" pipelineClassDef += " global cp_views, cp_writers\n" for original_line in smtrace.trace_globals.trace_output: for line in original_line.split("\n"): pipelineClassDef += " " + line + "\n"; smtrace.clear_trace() pipelineClassDef += " return Pipeline()\n"; return pipelineClassDef
def get_state(options=None, source_set=[], filter=None, raw=False): """Returns the state string""" if options: options = sm._getPyProxy(options) propertiesToTraceOnCreate = options.PropertiesToTraceOnCreate skipHiddenRepresentations = options.SkipHiddenDisplayProperties skipRenderingComponents = options.SkipRenderingComponents else: propertiesToTraceOnCreate = RECORD_MODIFIED_PROPERTIES skipHiddenRepresentations = True skipRenderingComponents = False # essential to ensure any obsolete accessors don't linger - can cause havoc # when saving state following a Python trace session # (paraview/paraview#18994) import gc gc.collect() if sm.vtkSMTrace.GetActiveTracer(): raise RuntimeError ("Cannot generate Python state when tracing is active.") if filter is None: filter = visible_representations() if skipHiddenRepresentations else supported_proxies() # build a set of proxies of interest if source_set: start_set = source_set else: # if nothing is specified, we save all views and sources. start_set = [x for x in simple.GetSources().values()] + simple.GetViews() start_set = [x for x in start_set if filter(x)] # now, locate dependencies for the start_set, pruning irrelevant branches consumers = set(start_set) for proxy in start_set: get_consumers(proxy, filter, consumers) producers = set() for proxy in consumers: get_producers(proxy, filter, producers) # proxies_of_interest is set of all proxies that we should trace. proxies_of_interest = producers.union(consumers) #print ("proxies_of_interest", proxies_of_interest) trace_config = smtrace.start_trace(preamble="") # this ensures that lookup tables/scalar bars etc. are fully traced. trace_config.SetFullyTraceSupplementalProxies(True) trace_config.SetSkipRenderingComponents(skipRenderingComponents) trace = smtrace.TraceOutput() trace.append("# state file generated using %s" % simple.GetParaViewSourceVersion()) trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) #-------------------------------------------------------------------------- # We trace the views and layouts, if any. if skipRenderingComponents: views = [] else: views = [x for x in proxies_of_interest if smtrace.Trace.get_registered_name(x, "views")] if views: # sort views by their names, so the state has some structure to it. views = sorted(views, key=lambda x:\ smtrace.Trace.get_registered_name(x, "views")) trace.append_separated([\ "# ----------------------------------------------------------------", "# setup views used in the visualization", "# ----------------------------------------------------------------"]) for view in views: # FIXME: save view camera positions and size. traceitem = smtrace.RegisterViewProxy(view) traceitem.finalize() del traceitem trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) trace.append_separated(["SetActiveView(None)"]) # from views, build the list of layouts of interest. layouts = set() for aview in views: l = simple.GetLayout(aview) if l: layouts.add(simple.GetLayout(aview)) # trace create of layouts if layouts: layouts = sorted(layouts, key=lambda x:\ smtrace.Trace.get_registered_name(x, "layouts")) trace.append_separated([\ "# ----------------------------------------------------------------", "# setup view layouts", "# ----------------------------------------------------------------"]) for layout in layouts: traceitem = smtrace.RegisterLayoutProxy(layout) traceitem.finalize(filter=lambda x: x in views) del traceitem trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) if views: # restore the active view after the layouts have been created. trace.append_separated([\ "# ----------------------------------------------------------------", "# restore active view", "SetActiveView(%s)" % smtrace.Trace.get_accessor(simple.GetActiveView()), "# ----------------------------------------------------------------"]) #-------------------------------------------------------------------------- # Next, trace data processing pipelines. sorted_proxies_of_interest = __toposort(proxies_of_interest) sorted_sources = [x for x in sorted_proxies_of_interest \ if smtrace.Trace.get_registered_name(x, "sources")] if sorted_sources: trace.append_separated([\ "# ----------------------------------------------------------------", "# setup the data processing pipelines", "# ----------------------------------------------------------------"]) for source in sorted_sources: traceitem = smtrace.RegisterPipelineProxy(source) traceitem.finalize() del traceitem trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) #-------------------------------------------------------------------------- # Can't decide if the representations should be saved with the pipeline # objects or afterwards, opting for afterwards for now since the topological # sort doesn't guarantee that the representations will follow their sources # anyways. sorted_representations = [x for x in sorted_proxies_of_interest \ if smtrace.Trace.get_registered_name(x, "representations")] scalarbar_representations = [x for x in sorted_proxies_of_interest\ if smtrace.Trace.get_registered_name(x, "scalar_bars")] # print ("sorted_representations", sorted_representations) # print ("scalarbar_representations", scalarbar_representations) if not skipRenderingComponents and (sorted_representations or scalarbar_representations): for view in views: view_representations = [x for x in view.Representations if x in sorted_representations] view_scalarbars = [x for x in view.Representations if x in scalarbar_representations] if view_representations or view_scalarbars: trace.append_separated([\ "# ----------------------------------------------------------------", "# setup the visualization in view '%s'" % smtrace.Trace.get_accessor(view), "# ----------------------------------------------------------------"]) for rep in view_representations: try: producer = rep.Input port = rep.Input.Port traceitem = smtrace.Show(producer, port, view, rep, comment="show data from %s" % smtrace.Trace.get_accessor(producer)) traceitem.finalize() del traceitem trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) if rep.UseSeparateColorMap: trace.append_separated([\ "# set separate color map", "%s.UseSeparateColorMap = True" % (\ smtrace.Trace.get_accessor(rep))]) except AttributeError: pass # save the scalar bar properties themselves. if view_scalarbars: trace.append_separated("# setup the color legend parameters for each legend in this view") for rep in view_scalarbars: smtrace.Trace.get_accessor(rep) trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) trace.append_separated([\ "# set color bar visibility", "%s.Visibility = %s" % (\ smtrace.Trace.get_accessor(rep), rep.Visibility)]) for rep in view_representations: try: producer = rep.Input port = rep.Input.Port if rep.IsScalarBarVisible(view): # FIXME: this will save this multiple times, right now, # if two representations use the same LUT. trace.append_separated([\ "# show color legend", "%s.SetScalarBarVisibility(%s, True)" % (\ smtrace.Trace.get_accessor(rep), smtrace.Trace.get_accessor(view))]) if not rep.Visibility: traceitem = smtrace.Hide(producer, port, view) traceitem.finalize() del traceitem trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) except AttributeError: pass #-------------------------------------------------------------------------- # Now, trace the transfer functions (color maps and opacity maps) used. ctfs = set([x for x in proxies_of_interest \ if smtrace.Trace.get_registered_name(x, "lookup_tables")]) if not skipRenderingComponents and ctfs: trace.append_separated([\ "# ----------------------------------------------------------------", "# setup color maps and opacity mapes used in the visualization", "# note: the Get..() functions create a new object, if needed", "# ----------------------------------------------------------------"]) for ctf in ctfs: smtrace.Trace.get_accessor(ctf) if ctf.ScalarOpacityFunction in proxies_of_interest: smtrace.Trace.get_accessor(ctf.ScalarOpacityFunction) trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) # Trace extract generators. exgens = set([x for x in proxies_of_interest \ if smtrace.Trace.get_registered_name(x, "extract_generators")]) if exgens: trace.append_separated([\ "# ----------------------------------------------------------------", "# setup extract generators", "# ----------------------------------------------------------------"]) for exgen in exgens: # FIXME: this currently doesn't handle multiple output ports # correctly. traceitem = smtrace.CreateExtractGenerator(\ xmlname=exgen.Writer.GetXMLName(), producer=exgen.Producer, generator=exgen, registrationName=smtrace.Trace.get_registered_name(exgen, "extract_generators")) traceitem.finalize() del traceitem trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) # restore the active source since the order in which the pipeline is created # in the state file can end up changing the active source to be different # than what it was when the state is being saved. trace.append_separated([\ "# ----------------------------------------------------------------", "# restore active source", "SetActiveSource(%s)" % smtrace.Trace.get_accessor(simple.GetActiveSource()), "# ----------------------------------------------------------------"]) if options: # add coda about extracts generation. trace.append_separated(["", "if __name__ == '__main__':", " # generate extracts", " SaveExtracts(ExtractsOutputDirectory='%s')" % options.ExtractsOutputDirectory]) del trace_config smtrace.stop_trace() #print (trace) return str(trace) if not raw else trace.raw_data()
def get_state( propertiesToTraceOnCreate=1, # sm.vtkSMTrace.RECORD_MODIFIED_PROPERTIES, skipHiddenRepresentations=True, source_set=[], filter=None, raw=False): """Returns the state string""" if sm.vtkSMTrace.GetActiveTracer(): raise RuntimeError( "Cannot generate Python state when tracing is active.") if filter is None: filter = visible_representations( ) if skipHiddenRepresentations else supported_proxies() # build a set of proxies of interest if source_set: start_set = source_set else: # if nothing is specified, we save all views and sources. start_set = [x for x in simple.GetSources().values() ] + simple.GetViews() start_set = [x for x in start_set if filter(x)] # now, locate dependencies for the start_set, pruning irrelevant branches consumers = set(start_set) for proxy in start_set: get_consumers(proxy, filter, consumers) producers = set() for proxy in consumers: get_producers(proxy, filter, producers) # proxies_of_interest is set of all proxies that we should trace. proxies_of_interest = producers.union(consumers) #print ("proxies_of_interest", proxies_of_interest) trace_config = smtrace.start_trace() # this ensures that lookup tables/scalar bars etc. are fully traced. trace_config.SetFullyTraceSupplementalProxies(True) trace = smtrace.TraceOutput() trace.append("# state file generated using %s" % simple.GetParaViewSourceVersion()) #-------------------------------------------------------------------------- # First, we trace the views and layouts, if any. # TODO: add support for layouts. views = [ x for x in proxies_of_interest if smtrace.Trace.get_registered_name(x, "views") ] if views: # sort views by their names, so the state has some structure to it. views = sorted(views, key=lambda x:\ smtrace.Trace.get_registered_name(x, "views")) trace.append_separated([\ "# ----------------------------------------------------------------", "# setup views used in the visualization", "# ----------------------------------------------------------------"]) for view in views: # FIXME: save view camera positions and size. traceitem = smtrace.RegisterViewProxy(view) traceitem.finalize() del traceitem trace.append_separated( smtrace.get_current_trace_output_and_reset(raw=True)) trace.append_separated([\ "# ----------------------------------------------------------------", "# restore active view", "SetActiveView(%s)" % smtrace.Trace.get_accessor(simple.GetActiveView()), "# ----------------------------------------------------------------"]) #-------------------------------------------------------------------------- # Next, trace data processing pipelines. sorted_proxies_of_interest = __toposort(proxies_of_interest) sorted_sources = [x for x in sorted_proxies_of_interest \ if smtrace.Trace.get_registered_name(x, "sources")] if sorted_sources: trace.append_separated([\ "# ----------------------------------------------------------------", "# setup the data processing pipelines", "# ----------------------------------------------------------------"]) for source in sorted_sources: traceitem = smtrace.RegisterPipelineProxy(source) traceitem.finalize() del traceitem trace.append_separated( smtrace.get_current_trace_output_and_reset(raw=True)) #-------------------------------------------------------------------------- # Can't decide if the representations should be saved with the pipeline # objects or afterwords, opting for afterwords for now since the topological # sort doesn't guarantee that the representations will follow their sources # anyways. sorted_representations = [x for x in sorted_proxies_of_interest \ if smtrace.Trace.get_registered_name(x, "representations")] scalarbar_representations = [x for x in sorted_proxies_of_interest\ if smtrace.Trace.get_registered_name(x, "scalar_bars")] # print ("sorted_representations", sorted_representations) # print ("scalarbar_representations", scalarbar_representations) if sorted_representations or scalarbar_representations: for view in views: view_representations = [ x for x in view.Representations if x in sorted_representations ] view_scalarbars = [ x for x in view.Representations if x in scalarbar_representations ] if view_representations or view_scalarbars: trace.append_separated([\ "# ----------------------------------------------------------------", "# setup the visualization in view '%s'" % smtrace.Trace.get_accessor(view), "# ----------------------------------------------------------------"]) for rep in view_representations: try: producer = rep.Input port = rep.Input.Port traceitem = smtrace.Show( producer, port, view, rep, comment="show data from %s" % smtrace.Trace.get_accessor(producer)) traceitem.finalize() del traceitem trace.append_separated( smtrace.get_current_trace_output_and_reset(raw=True)) if rep.UseSeparateColorMap: trace.append_separated([\ "# set separate color map", "%s.UseSeparateColorMap = True" % (\ smtrace.Trace.get_accessor(rep))]) except AttributeError: pass # save the scalar bar properties themselves. if view_scalarbars: trace.append_separated( "# setup the color legend parameters for each legend in this view" ) for rep in view_scalarbars: smtrace.Trace.get_accessor(rep) trace.append_separated( smtrace.get_current_trace_output_and_reset(raw=True)) trace.append_separated([\ "# set color bar visibility", "%s.Visibility = %s" % (\ smtrace.Trace.get_accessor(rep), rep.Visibility)]) for rep in view_representations: try: producer = rep.Input port = rep.Input.Port if rep.IsScalarBarVisible(view): # FIXME: this will save this multiple times, right now, # if two representations use the same LUT. trace.append_separated([\ "# show color legend", "%s.SetScalarBarVisibility(%s, True)" % (\ smtrace.Trace.get_accessor(rep), smtrace.Trace.get_accessor(view))]) if not rep.Visibility: traceitem = smtrace.Hide(producer, port, view) traceitem.finalize() del traceitem trace.append_separated( smtrace.get_current_trace_output_and_reset( raw=True)) except AttributeError: pass #-------------------------------------------------------------------------- # Now, trace the transfer functions (color maps and opacity maps) used. ctfs = set([x for x in proxies_of_interest \ if smtrace.Trace.get_registered_name(x, "lookup_tables")]) if ctfs: trace.append_separated([\ "# ----------------------------------------------------------------", "# setup color maps and opacity mapes used in the visualization", "# note: the Get..() functions create a new object, if needed", "# ----------------------------------------------------------------"]) for ctf in ctfs: smtrace.Trace.get_accessor(ctf) if ctf.ScalarOpacityFunction in proxies_of_interest: smtrace.Trace.get_accessor(ctf.ScalarOpacityFunction) trace.append_separated( smtrace.get_current_trace_output_and_reset(raw=True)) # restore the active source since the order in which the pipeline is created # in the state file can end up changing the active source to be different # than what it was when the state is being saved. trace.append_separated([\ "# ----------------------------------------------------------------", "# finally, restore active source", "SetActiveSource(%s)" % smtrace.Trace.get_accessor(simple.GetActiveSource()), "# ----------------------------------------------------------------"]) del trace_config smtrace.stop_trace() #print (trace) return str(trace) if not raw else trace.raw_data()
def get_state(propertiesToTraceOnCreate=1, # sm.vtkSMTrace.RECORD_MODIFIED_PROPERTIES, skipHiddenRepresentations=True, source_set=[], filter=None, raw=False): """Returns the state string""" if sm.vtkSMTrace.GetActiveTracer(): raise RuntimeError ("Cannot generate Python state when tracing is active.") if filter is None: filter = visible_representations() if skipHiddenRepresentations else supported_proxies() # build a set of proxies of interest if source_set: start_set = source_set else: # if nothing is specified, we save all views and sources. start_set = simple.GetSources().values() + simple.GetViews() start_set = [x for x in start_set if filter(x)] # now, locate dependencies for the start_set, pruning irrelevant branches consumers = set(start_set) for proxy in start_set: get_consumers(proxy, filter, consumers) producers = set() for proxy in consumers: get_producers(proxy, filter, producers) # proxies_of_interest is set of all proxies that we should trace. proxies_of_interest = producers.union(consumers) #print ("proxies_of_interest", proxies_of_interest) trace_config = smtrace.start_trace() # this ensures that lookup tables/scalar bars etc. are fully traced. trace_config.SetFullyTraceSupplementalProxies(True) trace = smtrace.TraceOutput() trace.append("# state file generated using %s" % simple.GetParaViewSourceVersion()) #-------------------------------------------------------------------------- # First, we trace the views and layouts, if any. # TODO: add support for layouts. views = [x for x in proxies_of_interest if smtrace.Trace.get_registered_name(x, "views")] if views: # sort views by their names, so the state has some structure to it. views = sorted(views, cmp=lambda x,y:\ cmp(smtrace.Trace.get_registered_name(x, "views"), smtrace.Trace.get_registered_name(y, "views"))) trace.append_separated([\ "# ----------------------------------------------------------------", "# setup views used in the visualization", "# ----------------------------------------------------------------"]) for view in views: # FIXME: save view camera positions and size. traceitem = smtrace.RegisterViewProxy(view) traceitem.finalize() del traceitem trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) #-------------------------------------------------------------------------- # Next, trace data processing pipelines. sorted_proxies_of_interest = __toposort(proxies_of_interest) sorted_sources = [x for x in sorted_proxies_of_interest \ if smtrace.Trace.get_registered_name(x, "sources")] if sorted_sources: trace.append_separated([\ "# ----------------------------------------------------------------", "# setup the data processing pipelines", "# ----------------------------------------------------------------"]) for source in sorted_sources: traceitem = smtrace.RegisterPipelineProxy(source) traceitem.finalize() del traceitem trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) #-------------------------------------------------------------------------- # Now, trace the transfer functions (color maps and opacity maps) used. ctfs = set([x for x in proxies_of_interest \ if smtrace.Trace.get_registered_name(x, "lookup_tables")]) if ctfs: trace.append_separated([\ "# ----------------------------------------------------------------", "# setup color maps and opacity mapes used in the visualization", "# note: the Get..() functions create a new object, if needed", "# ----------------------------------------------------------------"]) for ctf in ctfs: smtrace.Trace.get_accessor(ctf) if ctf.ScalarOpacityFunction in proxies_of_interest: smtrace.Trace.get_accessor(ctf.ScalarOpacityFunction) trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) #-------------------------------------------------------------------------- # Can't decide if the representations should be saved with the pipeline # objects or afterwords, opting for afterwords for now since the topological # sort doesn't guarantee that the representations will follow their sources # anyways. sorted_representations = [x for x in sorted_proxies_of_interest \ if smtrace.Trace.get_registered_name(x, "representations")] scalarbar_representations = [x for x in sorted_proxies_of_interest\ if smtrace.Trace.get_registered_name(x, "scalar_bars")] # print ("sorted_representations", sorted_representations) # print ("scalarbar_representations", scalarbar_representations) if sorted_representations or scalarbar_representations: for view in views: view_representations = [x for x in view.Representations if x in sorted_representations] view_scalarbars = [x for x in view.Representations if x in scalarbar_representations] if view_representations or view_scalarbars: trace.append_separated([\ "# ----------------------------------------------------------------", "# setup the visualization in view '%s'" % smtrace.Trace.get_accessor(view), "# ----------------------------------------------------------------"]) for rep in view_representations: try: producer = rep.Input port = rep.Input.Port traceitem = smtrace.Show(producer, port, view, rep, comment="show data from %s" % smtrace.Trace.get_accessor(producer)) traceitem.finalize() del traceitem trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) if rep.IsScalarBarVisible(view): # FIXME: this will save this multiple times, right now, # if two representations use the same LUT. trace.append_separated([\ "# show color legend", "%s.SetScalarBarVisibility(%s, True)" % (\ smtrace.Trace.get_accessor(rep), smtrace.Trace.get_accessor(view))]) except AttributeError: pass # save the scalar bar properties themselves. if view_scalarbars: trace.append_separated("# setup the color legend parameters for each legend in this view") for rep in view_scalarbars: smtrace.Trace.get_accessor(rep) trace.append_separated(smtrace.get_current_trace_output_and_reset(raw=True)) # restore the active source since the order in which the pipeline is created # in the state file can end up changing the active source to be different # than what it was when the state is being saved. trace.append_separated([\ "# ----------------------------------------------------------------", "# finally, restore active source", "SetActiveSource(%s)" % smtrace.Trace.get_accessor(simple.GetActiveSource()), "# ----------------------------------------------------------------"]) del trace_config smtrace.stop_trace() #print (trace) return str(trace) if not raw else trace.raw_data()
smtrace.trace_globals.proxy_ctor_hook = staticmethod(cp_hook) smtrace.trace_globals.trace_output = [] # Get list of proxy lists proxy_lists = smstate.get_proxy_lists_ordered_by_group(WithRendering=export_rendering) # Now register the proxies with the smtrace module for proxy_list in proxy_lists: smstate.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() for view_proxy in view_proxies: # Locate which simulation input this write is connected to, if any. If so, # we update the write_frequencies datastructure accordingly. sim_inputs = cp_locate_simulation_inputs_for_view(view_proxy) for sim_input_name in sim_inputs: if not image_write_frequency in write_frequencies[sim_input_name]: write_frequencies[sim_input_name].append(image_write_frequency) #write_frequencies['input'].append(image_write_frequency) output_contents = """ try: paraview.simple except: from paraview.simple import *
ColorBy(value=("POINTS", "RTData")) GetDisplayProperties().SetScalarBarVisibility(ren, True) Render() clip = Clip() Show() Hide(contour) Render() create_pipeline() # End build pipeline ######################################################## # Stop trace and grab the trace output string trace_string = smtrace.stop_trace() print(trace_string) # Uncomment these lines to print the trace string or save it to a file print(trace_string) #smtrace.save_trace(tempDir + "/PythonSMTraceTest1.py") # Clear all the sources for source in GetSources().values(): Delete(source) # Confirm that all the representations have been removed from the view except 1 # for the scalar bar. if len(ren.Representations) != 1: print("View should not have any representations except the scalar bar!") sys.exit(1)
# 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: smstate.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() output_contents = """ try: paraview.simple except: from paraview.simple import * cp_writers = [] def RequestDataDescription(datadescription): "Callback to populate the request for current timestep" timestep = datadescription.GetTimeStep() %s def DoCoProcessing(datadescription):
def DumpPipeline(export_rendering, simulation_input_map, screenshot_info): """ Method that will dump the current pipeline and return it as a string trace - export_rendering : boolean telling if we want to export rendering - simulation_input_map: string->string map with key being the proxyname while value being the simulation input name. - screenshot_info : map with information about screenshots key -> view proxy name value -> [filename, writefreq, fitToScreen, magnification, width, height] """ # reset the global variables. reset_cpstate_globals() cpstate_globals.export_rendering = export_rendering cpstate_globals.simulation_input_map = simulation_input_map cpstate_globals.screenshot_info = screenshot_info # Initialize the write frequency map for key in cpstate_globals.simulation_input_map.values(): cpstate_globals.write_frequencies[key] = [] # Start trace capture_modified_properties = not smstate._save_full_state smtrace.start_trace(CaptureAllProperties=True, CaptureModifiedProperties=capture_modified_properties, UseGuiName=True) # Disconnect the smtrace module's observer. It should not be # active while tracing the state. smtrace.reset_trace_observer() # update trace globals. smtrace.trace_globals.proxy_ctor_hook = staticmethod(cp_hook) smtrace.trace_globals.trace_output.clear() # Get list of proxy lists proxy_lists = smstate.get_proxy_lists_ordered_by_group(WithRendering=cpstate_globals.export_rendering) # Now register the proxies with the smtrace module for proxy_list in proxy_lists: smstate.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() # During tracing, cp_hook() will fill up the cpstate_globals.view_proxies # list with view proxies, if rendering was enabled. for view_proxy in cpstate_globals.view_proxies: # Locate which simulation input this write is connected to, if any. If so, # we update the write_frequencies datastructure accordingly. sim_inputs = locate_simulation_inputs_for_view(view_proxy) proxyName = servermanager.ProxyManager().GetProxyName("views", view_proxy) image_write_frequency = cpstate_globals.screenshot_info[proxyName][1] for sim_input_name in sim_inputs: if not image_write_frequency in cpstate_globals.write_frequencies[sim_input_name]: cpstate_globals.write_frequencies[sim_input_name].append(image_write_frequency) cpstate_globals.write_frequencies[sim_input_name].sort() # Create global fields values pipelineClassDef = "\n" pipelineClassDef += "# ----------------------- CoProcessor definition -----------------------\n\n" # Create the resulting string that will contains the pipeline definition pipelineClassDef += "def CreateCoProcessor():\n" pipelineClassDef += " def _CreatePipeline(coprocessor, datadescription):\n" pipelineClassDef += " class Pipeline:\n"; # add the traced code. for original_line in smtrace.trace_globals.trace_output.raw_data(): for line in original_line.split("\n"): pipelineClassDef += " " + line + "\n"; smtrace.clear_trace() pipelineClassDef += " return Pipeline()\n"; pipelineClassDef += "\n" pipelineClassDef += " class CoProcessor(coprocessing.CoProcessor):\n" pipelineClassDef += " def CreatePipeline(self, datadescription):\n" pipelineClassDef += " self.Pipeline = _CreatePipeline(self, datadescription)\n" pipelineClassDef += "\n" pipelineClassDef += " coprocessor = CoProcessor()\n"; pipelineClassDef += " freqs = " + str(cpstate_globals.write_frequencies) + "\n" pipelineClassDef += " coprocessor.SetUpdateFrequencies(freqs)\n" pipelineClassDef += " return coprocessor\n" return pipelineClassDef
def DumpPipeline(export_rendering, simulation_input_map, screenshot_info): """ Method that will dump the current pipeline and return it as a string trace - export_rendering : boolean telling if we want to export rendering - simulation_input_map: string->string map with key being the proxyname while value being the simulation input name. - screenshot_info : map with information about screenshots key -> view proxy name value -> [filename, writefreq, fitToScreen, magnification, width, height] """ # reset the global variables. reset_cpstate_globals() cpstate_globals.export_rendering = export_rendering cpstate_globals.simulation_input_map = simulation_input_map cpstate_globals.screenshot_info = screenshot_info # Initialize the write frequency map for key in cpstate_globals.simulation_input_map.values(): cpstate_globals.write_frequencies[key] = [] # Start trace smtrace.start_trace(CaptureAllProperties=True, UseGuiName=True) # Disconnect the smtrace module's observer. It should not be # active while tracing the state. smtrace.reset_trace_observer() # update trace globals. smtrace.trace_globals.proxy_ctor_hook = staticmethod(cp_hook) smtrace.trace_globals.trace_output = [] # Get list of proxy lists proxy_lists = smstate.get_proxy_lists_ordered_by_group( WithRendering=cpstate_globals.export_rendering) # Now register the proxies with the smtrace module for proxy_list in proxy_lists: smstate.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() # During tracing, cp_hook() will fill up the cpstate_globals.view_proxies # list with view proxies, if rendering was enabled. for view_proxy in cpstate_globals.view_proxies: # Locate which simulation input this write is connected to, if any. If so, # we update the write_frequencies datastructure accordingly. sim_inputs = locate_simulation_inputs_for_view(view_proxy) proxyName = servermanager.ProxyManager().GetProxyName( "views", view_proxy) image_write_frequency = cpstate_globals.screenshot_info[proxyName][1] for sim_input_name in sim_inputs: if not image_write_frequency in cpstate_globals.write_frequencies[ sim_input_name]: cpstate_globals.write_frequencies[sim_input_name].append( image_write_frequency) cpstate_globals.write_frequencies[sim_input_name].sort() # Create global fields values pipelineClassDef = "\n" pipelineClassDef += "# ----------------------- CoProcessor definition -----------------------\n\n" # Create the resulting string that will contains the pipeline definition pipelineClassDef += "def CreateCoProcessor():\n" pipelineClassDef += " def _CreatePipeline(coprocessor, datadescription):\n" pipelineClassDef += " class Pipeline:\n" # add the traced code. for original_line in smtrace.trace_globals.trace_output: for line in original_line.split("\n"): pipelineClassDef += " " + line + "\n" smtrace.clear_trace() pipelineClassDef += " return Pipeline()\n" pipelineClassDef += "\n" pipelineClassDef += " class CoProcessor(coprocessing.CoProcessor):\n" pipelineClassDef += " def CreatePipeline(self, datadescription):\n" pipelineClassDef += " self.Pipeline = _CreatePipeline(self, datadescription)\n" pipelineClassDef += "\n" pipelineClassDef += " coprocessor = CoProcessor()\n" pipelineClassDef += " freqs = " + str( cpstate_globals.write_frequencies) + "\n" pipelineClassDef += " coprocessor.SetUpdateFrequencies(freqs)\n" pipelineClassDef += " return coprocessor\n" return pipelineClassDef