Пример #1
0
static void loadCompoundNumericParameter( Gaffer::CompoundPlug *parametersPlug, const std::string &name, const typename PlugType::ValueType &defaultValue, const CompoundData *annotations )
{
	typename PlugType::ValueType minValue( Imath::limits<float>::min() );
	typename PlugType::ValueType maxValue( Imath::limits<float>::max() );

	const StringData *minValueData = annotations->member<StringData>( name + ".min" );
	if( minValueData )
	{
		minValue = typename PlugType::ValueType( boost::lexical_cast<float>( minValueData->readable() ) );
	}

	const StringData *maxValueData = annotations->member<StringData>( name + ".max" );
	if( maxValueData )
	{
		maxValue = typename PlugType::ValueType( boost::lexical_cast<float>( maxValueData->readable() ) );
	}

	PlugType *existingPlug = parametersPlug->getChild<PlugType>( name );
	if(
		existingPlug &&
		existingPlug->defaultValue() == defaultValue &&
		existingPlug->minValue() == minValue &&
		existingPlug->maxValue() == maxValue
	)
	{
		return;
	}

	typename PlugType::Ptr plug = new PlugType( name, Plug::In, defaultValue, minValue, maxValue, Plug::Default | Plug::Dynamic );

	if( existingPlug )
	{
		for( size_t i = 0, e = existingPlug->children().size(); i < e; i++ )
		{
			FloatPlug *existingComponentPlug = static_cast<GraphComponent *>( existingPlug )->getChild<FloatPlug>( i );
			FloatPlug *componentPlug = static_cast<GraphComponent *>( plug.get() )->getChild<FloatPlug>( i );
			if( existingComponentPlug->getInput<Plug>() )
			{
				componentPlug->setInput( existingComponentPlug->getInput<Plug>() );
			}
			else
			{
				componentPlug->setValue( existingComponentPlug->getValue() );
			}
		}
	}

	parametersPlug->setChild( name, plug );
}
Пример #2
0
static Plug *loadNumericParameter( const OSLQuery::Parameter *parameter, Gaffer::CompoundPlug *parent )
{
	typedef typename PlugType::ValueType ValueType;
	
	ValueType defaultValue( 0 );
	if( parameter->idefault.size() )
	{
		defaultValue = ValueType( parameter->idefault[0] );
	}
	else if( parameter->fdefault.size() )
	{
		defaultValue = ValueType( parameter->fdefault[0] );
	}

	/// \todo Get from metadata
	ValueType minValue( Imath::limits<ValueType>::min() );
	ValueType maxValue( Imath::limits<ValueType>::max() );

	const string name = plugName( parameter );
	PlugType *existingPlug = parent->getChild<PlugType>( name );
	if(	
		existingPlug &&
		existingPlug->defaultValue() == defaultValue &&
		existingPlug->minValue() == minValue &&
		existingPlug->maxValue() == maxValue 
	)
	{
		return existingPlug;
	}
	
	typename PlugType::Ptr plug = new PlugType( name, parent->direction(), defaultValue, minValue, maxValue, Plug::Default | Plug::Dynamic );
	
	transferConnectionOrValue( existingPlug, plug.get() );
	
	parent->setChild( name, plug );
	
	return plug;
}