Пример #1
0
void SplinePlugGadget::splineRemoved( SetPtr splineStandardSet, IECore::RunTimeTypedPtr splinePlug )
{
	m_uis.erase( static_cast<Plug *>( splinePlug.get() ) );
	
	// remove the points from the selection
	SplineffPlugPtr p = IECore::runTimeCast<SplineffPlug>( splinePlug );
	if( p )
	{
		unsigned numPoints = p->numPoints();
		for( unsigned i = 0; i<numPoints; i++ )
		{
			m_selection->remove( p->pointPlug( i ) );
		}
	}
}
int ParameterisedHolder<BaseType>::knob_changed( DD::Image::Knob *knob )
{	
	if( knob==m_classSpecifierKnob || knob==m_classReloadKnob )
	{			
		// reload the class, or load a new class

		updateParameterised( knob==m_classReloadKnob );		
			
		// regenerate the knobs used to represent the parameters
				
		replaceKnobs();
		
		// update the version menu
		
		updateVersionChooser();

		return 1;
	}
	else if( knob==m_getParameterisedKnob )
	{
		// this is triggered by the FnParameterisedHolder.getParameterised implementation.
		// currently there's no way to get an Op * and call a method on it from
		// python, so we use the knob_changed() mechanism to simulate a function call by
		// shoving the result into g_getParameterisedResult for subsequent retrieval.
		
		g_getParameterisedResult = loadClass( false );
		if( g_getParameterisedResult )
		{
			ParameterisedInterface *parameterisedInterface = dynamic_cast<ParameterisedInterface *>( g_getParameterisedResult.get() );
			// apply current state
			ConstCompoundObjectPtr classSpecifier = runTimeCast<const CompoundObject>( m_classSpecifierKnob->getValue() );
			ConstObjectPtr handlerState = classSpecifier->member<Object>( "handlerState" );
			if( handlerState )
			{
				m_parameterHandler->setState( parameterisedInterface->parameters(), handlerState );
			}
			// get values directly from knobs as they haven't been stored at this point
			m_parameterHandler->setParameterValue( parameterisedInterface->parameters(), ParameterHandler::Knob );
		}
	
		return 1;
	}
	else if( knob==m_modifiedParametersKnob )
	{
		// this is triggered by the FnParameterisedHolder.classModificationContext() implementation.
		// as above, we use this method in lieu of being able to call a method on this class.
		
		// get the new handler state and store it so we have it for save/load copy/paste etc
		////////////////////////////////////////////////////////////////////////////////////
				
		ParameterisedInterface *inputParameterisedInterface = dynamic_cast<ParameterisedInterface *>( g_modifiedParametersInput.get() );
		ObjectPtr handlerState = m_parameterHandler->getState( inputParameterisedInterface->parameters() );
		CompoundObjectPtr classSpecifier = runTimeCast<CompoundObject>( m_classSpecifierKnob->getValue()->copy() );
		if( handlerState )
		{
			classSpecifier->members()["handlerState"] = handlerState;
		}
		else
		{
			classSpecifier->members().erase( "handlerState" );
		}
		// it seems that setting the value from inside knob_changed() doesn't emit a new knob_changed(), which
		// is fortunately what we want.
		m_classSpecifierKnob->setValue( classSpecifier ); 
		
		// apply the new state to the current parameterised object
		////////////////////////////////////////////////////////////////////////////////////
		
		ParameterisedInterface *parameterisedInterface = dynamic_cast<ParameterisedInterface *>( m_parameterised.get() );
		if( handlerState )
		{
			m_parameterHandler->setState( parameterisedInterface->parameters(), handlerState );
		}
		parameterisedInterface->parameters()->setValue( inputParameterisedInterface->parameters()->getValue() );
		
		// update the knobs using our newly updated parameterised object
		////////////////////////////////////////////////////////////////////////////////////
		
		replaceKnobs();
		setKnobValues();
		
		// forget the input 
		
		g_modifiedParametersInput = 0;
		
		return 1;
	}
	
	return BaseType::knob_changed( knob );
}
Пример #3
0
void ParameterisedHolder<BaseType>::setParameterised( IECore::RunTimeTypedPtr parameterised, bool keepExistingValues )
{
	BlockedConnection connectionBlocker( m_plugSetConnection );

	IECore::ParameterisedInterface *interface = dynamic_cast<IECore::ParameterisedInterface *>( parameterised.get() );
	if( !interface )
	{
		throw IECore::Exception( "Not a ParameterisedInterface derived type." );
	}

	m_parameterised = parameterised;
	m_parameterHandler = new CompoundParameterHandler( interface->parameters() );
	if( keepExistingValues )
	{
		m_parameterHandler->restore( this );
	}
	m_parameterHandler->setupPlug( this );
	if( !keepExistingValues )
	{
		m_parameterHandler->setPlugValue();
	}
}