File: Settings.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 (136 lines) | stat: -rw-r--r-- 4,655 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""This test is for the settings manager API."""

import sys
import paraview
paraview.compatibility.major = 3
paraview.compatibility.minor = 4
from paraview import servermanager

def Error(message):
  raise "ERROR: %s" % message

session = paraview.servermanager.vtkSMSession()
pxm = session.GetSessionProxyManager()

# Create settings from JSON description
trueRadius = 2.25
trueThetaResolution = 32
trueCenter = (1.0, 2.0, 4.0)
settingsString = """
{
  // Default settings for sources.
  "sources" : {
    // A sphere source
    "SphereSource" : {
      /* New comment
         New comment 2 */
      "Radius" : %4.2f,
      // Theta resolution


      // Theta resolution 2
      "ThetaResolution" : %d,
      // Center comment
      "Center" : [%3.1f, %3.1f, %3.1f]
    }
  }
}
""" % (trueRadius, trueThetaResolution, trueCenter[0], trueCenter[1], trueCenter[2])

settings = paraview.servermanager.vtkSMSettings.GetInstance()
settings.ClearAllSettings()
settings.AddCollectionFromString(settingsString, 2000000.0)
settings.AddCollectionFromString("{}", 1500000.0)

def check_comment(expected, settings, field):
  actual = settings.GetSettingDescription(field)
  if actual != expected:
    print "Comment for %s was not what was expected" % field
    print "expected:", expected
    print "actual  :", actual
    sys.exit(-1)

check_comment("// Default settings for sources.", settings, ".sources")
check_comment("// A sphere source", settings, ".sources.SphereSource")
check_comment("/* New comment\n         New comment 2 */", settings, ".sources.SphereSource.Radius")
check_comment("// Theta resolution\n// Theta resolution 2", settings, ".sources.SphereSource.ThetaResolution")
check_comment("// Center comment", settings, ".sources.SphereSource.Center")

# Check the setting directly
settingPath = ".sources.SphereSource.Radius"
settingValue = settings.GetSettingAsDouble(settingPath, 0, 0.0)
if settingValue != trueRadius:
  print "Direct access of setting value", settingPath, "failed"
  sys.exit(-1)

settingValue = settings.GetSettingAsDouble(settingPath, 0, 0.0)
if settingValue != trueRadius:
  print "Direct access of setting value", settingPath, "as vector element failed"
  sys.exit(-1)

settingPath = ".sources.SphereSource.ThetaResolution"
settingValue = settings.GetSettingAsInt(settingPath, 0, 0)
if settingValue != trueThetaResolution:
  print "Direct access of setting value", settingPath, "failed"
  sys.exit(-1)

settingPath = ".sources.SphereSource.Center"
if settings.GetSettingNumberOfElements(settingPath) != len(trueCenter):
  print "Number of elements query failed"
  sys.exit(-1)

for i in xrange(3):
  settingValue = settings.GetSettingAsDouble(settingPath, i, 0.0)
  if settingValue != trueCenter[i]:
    print "Direct access of setting value", settingPath, "[", i, "] failed"
    sys.exit(-1)

# The sphere source should pick up the settings from the user settings string
s = pxm.NewProxy("sources", "SphereSource")
settings.GetProxySettings(s);

radiusProperty = s.GetProperty("Radius")
radius = radiusProperty.GetElement(0)
if radius != trueRadius:
  print "Radius property does not match setting value"
  s.FastDelete()
  sys.exit(-1)
s.FastDelete()

#
#
# Now clear out the settings and test setting values
#
#
settings.ClearAllSettings()
if settings.HasSetting(".sources.SphereSource"):
  print "Setting '.sources.SphereSource' should have been cleared"
  sys.exit(-1)

settings.SetSetting(".sources.SphereSource.ints", 5)
settings.SetSetting(".sources.SphereSource.ints", 1, 2)
settings.SetSetting(".sources.SphereSource.double", 5.0)
settings.SetSetting(".sources.SphereSource.strings", "five")
settings.SetSetting(".sources.SphereSource.strings", "one")
settings.SetSetting(".sources.SphereSource.strings", 1, "two")
settings.SetSetting(".sources.SphereSource.strings", 1, "three")

if settings.GetSettingAsInt(".sources.SphereSource.ints", 0, 0) != 5:
  print "Setting '.sources.SphereSource.ints[0]' should have value 5"
  sys.exit(-1)

if settings.GetSettingAsInt(".sources.SphereSource.ints", 1, 0) != 2:
  print "Setting '.sources.SphereSource.ints[1]' should have value 2"
  sys.exit(-1)

if settings.GetSettingAsDouble(".sources.SphereSource.double", 0, 0.0) != 5.0:
  print "Setting '.sources.SphereSource.double' should have value 5.0"
  sys.exit(-1)

if settings.GetSettingAsString(".sources.SphereSource.strings", 0, "") != "one":
  print "Setting '.sources.SphereSource.strings[0]' should have value 'one'"
  sys.exit(-1)

if settings.GetSettingAsString(".sources.SphereSource.strings", 1, "") != "three":
  print "Setting '.sources.SphereSource.strings[1]' should have value 'three'"
  sys.exit(-1)