Skip to content

Commit 5a6a7e1

Browse files
author
Lucio Moser
committed
Adding getPresets() and deprecating presets() function.
1 parent f8ac4f9 commit 5a6a7e1

File tree

11 files changed

+62
-46
lines changed

11 files changed

+62
-46
lines changed

include/IECore/CompoundParameter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ class CompoundParameter : public Parameter
7171
/// of all the child objects.
7272
/// \threading It is not safe to call this from multiple concurrent threads.
7373
virtual const Object *defaultValue() const;
74+
/// \deprecated Use getPresets instead.
75+
virtual const PresetsContainer &presets() const;
7476
/// If true was passed to adoptChildPresets at construction, then update the presets
7577
/// with the intersection of the presets of all the child parameters, otherwise returns
7678
/// an empty container or the presets defined by setPresets().
7779
/// Please note that the map returned may differ between one call
7880
/// to presets() and the next.
79-
virtual const PresetsContainer &presets() const;
81+
virtual const PresetsContainer &getPresets() const;
8082
/// Defines presets for this Parameter.
8183
/// Throws an exception if true was passed to adoptChildPresets at construction.
8284
virtual void setPresets( const PresetsContainer &presets );

include/IECore/Parameter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ class Parameter : public RunTimeTyped
7878
const std::string &description() const;
7979
/// Returns the default value for this parameter.
8080
virtual const Object *defaultValue() const;
81-
/// Returns the presets for this parameter.
81+
/// \deprecated Use getPresets instead.
8282
virtual const PresetsContainer &presets() const;
83+
/// Returns the presets for this parameter.
84+
virtual const PresetsContainer &getPresets() const;
8385
/// Overrides the presets for this parameter.
8486
virtual void setPresets( const PresetsContainer &presets );
8587
/// Returns true if this parameter only accepts

src/IECore/CompoundParameter.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,32 @@ const Object *CompoundParameter::defaultValue() const
7373
}
7474

7575
const Parameter::PresetsContainer &CompoundParameter::presets() const
76+
{
77+
return getPresets();
78+
}
79+
80+
const Parameter::PresetsContainer &CompoundParameter::getPresets() const
7681
{
7782
if( !m_adoptChildPresets )
7883
{
79-
return Parameter::presets();
84+
return Parameter::getPresets();
8085
}
8186

8287
// naughty? nah! it gives the right semantics to an outside observer
83-
PresetsContainer &pr = const_cast<PresetsContainer &>( Parameter::presets() );
88+
PresetsContainer &pr = const_cast<PresetsContainer &>( Parameter::getPresets() );
8489
pr.clear();
8590
if( !m_namesToParameters.size() )
8691
{
8792
return pr;
8893
}
8994

9095
// get a references for each child preset map.
91-
// we only want to call presets() once for
96+
// we only want to call getPresets() once for
9297
// each child as the map returned may change between calls.
9398
vector<const PresetsContainer *> childPresets;
9499
for( size_t i=0; i<m_parameters.size(); i++ )
95100
{
96-
childPresets.push_back( &(m_parameters[i]->presets()) );
101+
childPresets.push_back( &(m_parameters[i]->getPresets()) );
97102
}
98103

99104
// find the intersection of all the child preset names

src/IECore/Parameter.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ const Object *Parameter::defaultValue() const
9292
}
9393

9494
const Parameter::PresetsContainer &Parameter::presets() const
95+
{
96+
return getPresets();
97+
}
98+
99+
const Parameter::PresetsContainer &Parameter::getPresets() const
95100
{
96101
return m_presets;
97102
}
@@ -150,7 +155,7 @@ bool Parameter::valueValid( const Object *value, std::string *reason ) const
150155
{
151156
return true;
152157
}
153-
const PresetsContainer &pr = presets();
158+
const PresetsContainer &pr = getPresets();
154159
for( PresetsContainer::const_iterator it = pr.begin(); it!=pr.end(); it++ )
155160
{
156161
if( it->second->isEqualTo( value ) )
@@ -206,7 +211,7 @@ void Parameter::setValidatedValue( ObjectPtr value )
206211

207212
void Parameter::setValue( const std::string &presetName )
208213
{
209-
const PresetsContainer &pr = presets();
214+
const PresetsContainer &pr = getPresets();
210215

211216
PresetsContainer::const_iterator it;
212217
for( it=pr.begin(); it != pr.end(); it++ )
@@ -256,7 +261,7 @@ std::string Parameter::getCurrentPresetName() const
256261
// didn't have to do a copy of the value. but that breaks with CompoundParameter
257262
// as it builds the value dynamically in getValue().
258263
const Object *currentValue = getValue();
259-
const PresetsContainer &pr = presets();
264+
const PresetsContainer &pr = getPresets();
260265
PresetsContainer::const_iterator it;
261266
for( it=pr.begin(); it!=pr.end(); it++ )
262267
{

src/IECoreMaya/FromMayaMeshConverter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,10 @@ IECore::PrimitivePtr FromMayaMeshConverter::doPrimitiveConversion( MFnMesh &fnMe
601601
unsigned int interpolationIndex = interpolationPlug.asInt(MDGContext::fsNormal, &st);
602602
if ( st )
603603
{
604-
if ( interpolationIndex < m_interpolation->presets().size() - 1 )
604+
if ( interpolationIndex < m_interpolation->getPresets().size() - 1 )
605605
{
606606
// convert interpolation index to the preset value
607-
interpolation = staticPointerCast< StringData >( m_interpolation->presets()[interpolationIndex].second )->readable();
607+
interpolation = staticPointerCast< StringData >( m_interpolation->getPresets()[interpolationIndex].second )->readable();
608608
}
609609
else
610610
{

src/IECoreMaya/ToMayaMeshConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ bool ToMayaMeshConverter::setMeshInterpolationAttribute( MObject &object, std::s
495495
int interpolationValue = 0;
496496

497497
FromMayaMeshConverter fromMaya(object);
498-
const IECore::Parameter::PresetsContainer &presets = fromMaya.interpolationParameter()->presets();
498+
const IECore::Parameter::PresetsContainer &presets = fromMaya.interpolationParameter()->getPresets();
499499
IECore::Parameter::PresetsContainer::const_iterator it;
500500

501501
if ( interpolation != "default" )

src/IECoreNuke/PresetsOnlyParameterHandler.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//////////////////////////////////////////////////////////////////////////
22
//
3-
// Copyright (c) 2010-2011, Image Engine Design Inc. All rights reserved.
3+
// Copyright (c) 2010-2013, Image Engine Design Inc. All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
66
// modification, are permitted provided that the following conditions are
@@ -49,7 +49,8 @@ void PresetsOnlyParameterHandler::knobs( const IECore::Parameter *parameter, con
4949
if( f.makeKnobs() )
5050
{
5151
m_names.clear();
52-
for( Parameter::PresetsContainer::const_iterator it = parameter->presets().begin(); it!=parameter->presets().end(); it++ )
52+
const Parameter::PresetsContainer &presets = parameter->getPresets();
53+
for( Parameter::PresetsContainer::const_iterator it = presets.begin(); it!=presets.end(); it++ )
5354
{
5455
if( it->second->isEqualTo( parameter->defaultValue() ) )
5556
{
@@ -79,12 +80,12 @@ void PresetsOnlyParameterHandler::setParameterValue( IECore::Parameter *paramete
7980
{
8081
presetIndex = (int)m_knob->get_value();
8182
}
82-
parameter->setValue( parameter->presets()[m_storage].second );
83+
parameter->setValue( parameter->getPresets()[m_storage].second );
8384
}
8485

8586
void PresetsOnlyParameterHandler::setKnobValue( const IECore::Parameter *parameter )
8687
{
87-
const Parameter::PresetsContainer &presets = parameter->presets();
88+
const Parameter::PresetsContainer &presets = parameter->getPresets();
8889
std::string currentPresetName = parameter->getCurrentPresetName();
8990
size_t presetIndex = 0;
9091
for( Parameter::PresetsContainer::const_iterator it = presets.begin(); it!=presets.end(); it++, presetIndex++ )

src/IECorePython/ParameterBinding.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ static void validate( Parameter &that, ObjectPtr value )
7575
that.validate( value.get() );
7676
}
7777

78-
static dict presets( Parameter &that )
78+
static dict getPresets( Parameter &that )
7979
{
8080
dict result;
81-
const Parameter::PresetsContainer &p = that.presets();
81+
const Parameter::PresetsContainer &p = that.getPresets();
8282
for( Parameter::PresetsContainer::const_iterator it=p.begin(); it!=p.end(); it++ )
8383
{
8484
result[it->first] = it->second->copy();
@@ -94,7 +94,7 @@ static void setPresets( Parameter &p, const object &presets )
9494
static boost::python::tuple presetNames( const Parameter &that )
9595
{
9696
boost::python::list result;
97-
const Parameter::PresetsContainer &p = that.presets();
97+
const Parameter::PresetsContainer &p = that.getPresets();
9898
for( Parameter::PresetsContainer::const_iterator it=p.begin(); it!=p.end(); it++ )
9999
{
100100
result.append( it->first );
@@ -105,7 +105,7 @@ static boost::python::tuple presetNames( const Parameter &that )
105105
static boost::python::tuple presetValues( const Parameter &that )
106106
{
107107
boost::python::list result;
108-
const Parameter::PresetsContainer &p = that.presets();
108+
const Parameter::PresetsContainer &p = that.getPresets();
109109
for( Parameter::PresetsContainer::const_iterator it=p.begin(); it!=p.end(); it++ )
110110
{
111111
result.append( it->second->copy() );
@@ -166,7 +166,8 @@ void bindParameter()
166166
.def( "validate", (void (Parameter::*)() const)&Parameter::validate )
167167
.def( "validate", &validate )
168168
.add_property( "presetsOnly", &Parameter::presetsOnly )
169-
.def( "presets", &presets, "Returns a dictionary containing presets for the parameter." )
169+
.def( "presets", &getPresets, "Deprecated function. Use getPresets() instead." )
170+
.def( "getPresets", &getPresets, "Returns a dictionary containing presets for the parameter." )
170171
.def( "setPresets", &setPresets, "Sets the presets for the parameter from a dictionary." )
171172
.def( "presetNames", &presetNames, "Returns a tuple containing the names of all presets for the parameter." )
172173
.def( "presetValues", &presetValues, "Returns a tuple containing the values of all presets for the parameter." )

test/IECore/CompoundParameterTest.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def testPresets( self ) :
179179

180180
self.assertEqual( p.presetsOnly, True )
181181

182-
pr = p.presets()
182+
pr = p.getPresets()
183183
self.assertEqual( len( pr ), 3 )
184184
self.assert_( "one" in pr.keys() )
185185
self.assert_( "two" in pr.keys() )
@@ -221,7 +221,7 @@ def testPresets( self ) :
221221
)
222222

223223
self.assertEqual( p.presetsOnly, False )
224-
self.assertEqual( len( p.presets() ), 0 )
224+
self.assertEqual( len( p.getPresets() ), 0 )
225225

226226
def testLateValidation( self ) :
227227

@@ -347,18 +347,18 @@ def testAddParametersPresets( self ) :
347347
members = []
348348
)
349349

350-
self.assertEqual( p.presets(), {} )
350+
self.assertEqual( p.getPresets(), {} )
351351

352352
p.addParameter( IntParameter( name = "i", description = "d", defaultValue = 10, presets = ( ( "one", 1 ), ( "two", 2 ) ) ) )
353353

354-
self.assertEqual( len( p.presets() ), 2 )
355-
self.assertEqual( p.presets(), { "one" : CompoundObject( { "i" : IntData( 1 ) } ), "two" : CompoundObject( { "i" : IntData( 2 ) } ) } )
354+
self.assertEqual( len( p.getPresets() ), 2 )
355+
self.assertEqual( p.getPresets(), { "one" : CompoundObject( { "i" : IntData( 1 ) } ), "two" : CompoundObject( { "i" : IntData( 2 ) } ) } )
356356

357357
fParam = FloatParameter( name = "f", description = "d", defaultValue = 20, presets = ( ( "one", 1 ), ) )
358358
p.addParameter( fParam )
359359

360-
self.assertEqual( len( p.presets() ), 1 )
361-
self.assertEqual( p.presets(), { "one" : CompoundObject( { "i" : IntData( 1 ), "f" : FloatData( 1 ) } ) } )
360+
self.assertEqual( len( p.getPresets() ), 1 )
361+
self.assertEqual( p.getPresets(), { "one" : CompoundObject( { "i" : IntData( 1 ), "f" : FloatData( 1 ) } ) } )
362362

363363
p.insertParameter( IntParameter( name = "x", description = "x", defaultValue = 10 ), fParam )
364364
self.assertEqual( p.keys(), [ "i", "x", "f" ] )
@@ -587,7 +587,7 @@ def testAdoptChildPresets( self ) :
587587
],
588588
)
589589

590-
self.assertEqual( len( c.presets() ), 2 )
590+
self.assertEqual( len( c.getPresets() ), 2 )
591591
self.assertEqual( c.presetsOnly, True )
592592

593593
# no adoption of presets
@@ -619,7 +619,7 @@ def testAdoptChildPresets( self ) :
619619
adoptChildPresets = False,
620620
)
621621

622-
self.assertEqual( len( c.presets() ), 0 )
622+
self.assertEqual( len( c.getPresets() ), 0 )
623623
self.assertEqual( c.presetsOnly, False )
624624

625625
# no adoption of presets without use of keyword parameters
@@ -653,7 +653,7 @@ def testAdoptChildPresets( self ) :
653653
False,
654654
)
655655

656-
self.assertEqual( len( c.presets() ), 0 )
656+
self.assertEqual( len( c.getPresets() ), 0 )
657657
self.assertEqual( c.presetsOnly, False )
658658
self.assertEqual( c.userData()["ud"].value, 10 )
659659

@@ -672,11 +672,11 @@ def testAdoptChildPresets( self ) :
672672
( "p2", p2 ),
673673
]
674674
)
675-
pr = c.presets()
675+
pr = c.getPresets()
676676
self.assertEqual( len( pr ), 2 )
677677
self.assertEqual( pr["p1"], p1 )
678678
self.assertEqual( pr["p2"], p2 )
679-
self.assertEqual( c.presetNames(), [ "p1", "p2" ] )
679+
self.assertEqual( c.presetNames(), ( "p1", "p2" ) )
680680
c.setValue("p1")
681681
self.assertEqual( c.getValue(), p1 )
682682
c.setValue("p2")

test/IECore/EXRImageWriter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ def testCompressionParameter( self ):
223223
img = r.read()
224224

225225
w = Writer.create( img, "test/IECore/data/exrFiles/output.exr" )
226-
w['compression'].setValue( w['compression'].presets()['zip'] )
226+
w['compression'].setValue( w['compression'].getPresets()['zip'] )
227227
w.write()
228228

229229
w = EXRImageWriter()
230-
w['compression'].setValue( w['compression'].presets()['zip'] )
230+
w['compression'].setValue( w['compression'].getPresets()['zip'] )
231231

232232
def testBlindDataToHeader( self ) :
233233

0 commit comments

Comments
 (0)