MCPcopy Create free account
hub / github.com/ImageEngine/cortex / setClasses

Method setClasses

python/IECore/ClassVectorParameter.py:75–115  ·  view source on GitHub ↗
( self, classes )

Source from the content-addressed store, hash-verified

73 # child class, then that class will be preserved rather than replaced with a new instance
74 # of the same thing.
75 def setClasses( self, classes ) :
76
77 # validate arguments and figure out what child parameter names we need
78
79 assert( isinstance( classes, list ) )
80
81 neededNames = set()
82 for c in classes :
83 assert( isinstance( c, tuple ) )
84 assert( len( c ) == 3 )
85 assert( isinstance( c[0], str ) )
86 assert( isinstance( c[1], str ) )
87 assert( isinstance( c[2], int ) )
88 if c[0] in neededNames :
89 raise ValueError( "Duplicate parameter name \"%s\"" % c[0] )
90 neededNames.add( c[0] )
91
92 # first remove any existing parameters which we don't need
93
94 for parameterName in self.keys() :
95 if parameterName not in neededNames :
96 self.removeClass( parameterName )
97
98 # and then create any new ones we need and reload and reorder existing
99 # ones as necessary
100
101 for i in range( 0, len( classes ) ) :
102
103 # modify or add a parameter for this class
104
105 self.setClass( classes[i][0], classes[i][1], classes[i][2] )
106 parameter = self[classes[i][0]]
107
108 # make sure the parameter has the right order within the whole
109
110 self.removeParameter( parameter )
111 if len( self ) == i :
112 self.addParameter( parameter )
113 else :
114 keys = self.keys()
115 self.insertParameter( parameter, self[keys[i]] )
116
117 ## Returns the class instance that the named parameter represents,
118 # or if withClassLoaderArgs is True, then returns a tuple of the

Callers 14

__init__Method · 0.95
testSetAndGetClassesMethod · 0.95
testInsertClassesMethod · 0.95
testRemoveClassesMethod · 0.95
testReorderClassesMethod · 0.95
testChangeClassesMethod · 0.95
testSerialiseAndParseMethod · 0.95
testNewParameterNameMethod · 0.95
testUserDataMethod · 0.95
copyClassesFunction · 0.80
_parseMethod · 0.80
testFindClassesMethod · 0.80

Calls 8

removeClassMethod · 0.95
setClassMethod · 0.95
removeParameterMethod · 0.80
lenFunction · 0.50
addMethod · 0.45
keysMethod · 0.45
addParameterMethod · 0.45
insertParameterMethod · 0.45

Tested by 10

testSetAndGetClassesMethod · 0.76
testInsertClassesMethod · 0.76
testRemoveClassesMethod · 0.76
testReorderClassesMethod · 0.76
testChangeClassesMethod · 0.76
testSerialiseAndParseMethod · 0.76
testNewParameterNameMethod · 0.76
testUserDataMethod · 0.76
testFindClassesMethod · 0.64
testCopyClassesMethod · 0.64