File: PythonSMTraceTest2.py

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (94 lines) | stat: -rw-r--r-- 3,090 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# This test creates a pipeline, traces the state, clears the proxies,
# then executes the python code to recreate the state, then confirms
# that the correct proxies exist with the correct property values

from paraview.simple import *
from paraview import smstate
from paraview import smtesting
import sys

# Process command line args and get temp dir
smtesting.ProcessCommandLineArguments()
tempDir = smtesting.TempDir

def fail(message):
    raise Exception(message)

def clear_proxies():
    """Method for clearing all user created proxies"""
    groups = ["sources", "representations", "views",
                  "implicit_functions", "piecewise_functions",
                  "lookup_tables", "scalar_bars", "selection_sources"]
    for g in groups:
        for p in servermanager.ProxyManager().GetProxiesInGroup(g).values():
            Delete(p)

########################################################
# Begin build pipeline
def create_pipeline():
    view = CreateRenderView()
    view.Background=[0,0,1]
    sphere = Sphere(guiName="my sphere")
    Show()
    view2 = CreateRenderView() # create a second view for the remaining sources
    glyph = Glyph(guiName="my glyph")
    Show()
    glyph.GlyphType = "Cone"
    glyph.GlyphType.Radius = 0.1
    glyph.GlyphType.Resolution = 15
    clip = Clip(guiName="my clip")
    Show()
    clip.ClipType = "Sphere"
    clip.ClipType.Radius = 0.25
    group = GroupDatasets(Input=[sphere, clip], guiName="my group")
    Show()
    GetDisplayProperties().Representation = "Surface With Edges"
    Render()
create_pipeline()
# End build pipeline
########################################################


# Trace state and grab the trace output string
state = smstate.get_state()
print state

# Clear all the proxies
clear_proxies()

# Confirm that all the representations have been removed from the view
if len(GetRepresentations()) or len(GetRenderViews()) or len(GetSources()):
    fail("Not all proxies were cleaned up.")

# Compile the trace code and run it
code = compile(state, "<string>", "exec")
exec(code)

# Get the recreated proxies
view = FindView("RenderView1")
view2 = FindView("RenderView2")
sphere = FindSource("Sphere1")
glyph = FindSource("Glyph1")
clip = FindSource("Clip1")
group = FindSource("GroupDatasets1")


# Test the results
epsilon = 0.000001
if not sphere:
    fail("Could not find sphere")
if glyph.GlyphType.Resolution != 15:
    fail("Glyph cone resolution is incorrect.")
if abs(clip.ClipType.Radius - 0.25) > epsilon:
    fail("Clip sphere radius is incorrect.")
if sphere not in group.Input or clip not in group.Input:
    fail("Group has wrong inputs.")
if GetDisplayProperties(group, view2).Representation != "Surface With Edges":
    fail("Group representation is incorrect")
if abs(view.Background[1] - 0) > epsilon or abs(view.Background[2] - 1) > epsilon:
    fail("View has incorrect background color")
if len(view.Representations) != 1:
    fail("First view has incorrect number of representations.")
if view.Representations[0].Input != sphere:
    fail("First view does not contain sphere.")