Exemplo n.º 1
0
MStatus BoxParameterHandler<T>::doUpdate( IECore::ConstParameterPtr parameter, MPlug &plug ) const
{
	typename IECore::TypedParameter<Box<T> >::ConstPtr p = IECore::runTimeCast<const IECore::TypedParameter<Box<T> > >( parameter );
	if( !p )
	{
		return MS::kFailure;
	}

	MObject attribute = plug.attribute();
	MFnCompoundAttribute fnCAttr( attribute );
	if( !fnCAttr.hasObj( attribute ) )
	{
		return MS::kFailure;
	}

	if( fnCAttr.numChildren()!=2 )
	{
		return MS::kFailure;
	}

	MFnNumericAttribute fnMinAttr( fnCAttr.child( 0 ) );
	if( fnMinAttr.unitType()!=NumericTraits<T>::dataType() )
	{
		return MS::kFailure;
	}

	MFnNumericAttribute fnMaxAttr( fnCAttr.child( 1 ) );
	if( fnMaxAttr.unitType()!=NumericTraits<T>::dataType() )
	{
		return MS::kFailure;
	}

	// Set the default value for the leaf attributes individually. Calling
	// the variants of setDefault that set several components at a time
	// seems to exercise a maya bug. See similar comment in CompoundNumericParameterHandler.
	Box<T> defValue = p->typedDefaultValue();
	MStatus s;
	for( unsigned i=0; i<T::dimensions(); i++ )
	{
		MObject minChildAttr = fnMinAttr.child( i, &s );
		if( !s )
		{
			return s;
		}

		MObject maxChildAttr = fnMaxAttr.child( i, &s );
		if( !s )
		{
			return s;
		}

		MFnNumericAttribute fnMinChildAttr( minChildAttr, &s );
		if( !s )
		{
			return s;
		}

		MFnNumericAttribute fnMaxChildAttr( maxChildAttr, &s );
		if( !s )
		{
			return s;
		}

		s = fnMinChildAttr.setDefault( defValue.min[i] );
		if( !s )
		{
			return s;
		}

		s = fnMaxChildAttr.setDefault( defValue.max[i] );
		if( !s )
		{
			return s;
		}

	}

	return finishUpdating( parameter, plug );
}
MStatus TransformationMatrixParameterHandler<T>::doUpdate( IECore::ConstParameterPtr parameter, MPlug &plug ) const
{
	typename IECore::TypedParameter<IECore::TransformationMatrix<T> >::ConstPtr p = IECore::runTimeCast<const IECore::TypedParameter<IECore::TransformationMatrix<T> > >( parameter );
	if( !p )
	{
		return MS::kFailure;
	}

	MObject attribute = plug.attribute();
	MFnCompoundAttribute fnCAttr( attribute );
	if( !fnCAttr.hasObj( attribute ) )
	{
		return MS::kFailure;
	}

	if( plug.numChildren() != 8 )
	{
		return MS::kFailure;
	}

	MStatus stat;
	MPlug tmpPlug;

	for( unsigned int i=0; i<8; i++ )
	{
		tmpPlug = plug.child( i, &stat );

		// Verify the naming of the child plugs.

		const MString name = tmpPlug.partialName();
		const unsigned int len = name.length() - 1;
		const unsigned int nlen = g_attributeNames[i].length() - 1;
		const MString nameEnd = name.substringW( len - nlen, len );

		if( !stat || nameEnd != g_attributeNames[i] )
		{
			return MS::kFailure;
		}

		MObject attr = tmpPlug.attribute();
		fnCAttr.setObject( attr );
		if( !fnCAttr.hasObj( attr ) )
		{
			return MS::kFailure;
		}
	}

	IECore::TransformationMatrix<T> tMatrix = p->typedDefaultValue();

	if( !setUnitVecDefaultValues( plug.child( TRANSLATE_INDEX ), tMatrix.translate ) )
		return MS::kFailure;

	if( !setUnitVecDefaultValues( plug.child( ROTATE_INDEX ), tMatrix.rotate ) )
		return MS::kFailure;

	if( !setVecDefaultValues( plug.child( SCALE_INDEX ), tMatrix.scale ) )
		return MS::kFailure;

	if( !setVecDefaultValues( plug.child( SHEAR_INDEX ), tMatrix.shear ) )
		return MS::kFailure;

	if( !setVecDefaultValues( plug.child( SCALEPIVOT_INDEX ), tMatrix.scalePivot ) )
		return MS::kFailure;

	if( !setVecDefaultValues( plug.child( SCALEPIVOTTRANS_INDEX ), tMatrix.scalePivotTranslation ) )
		 return MS::kFailure;

	if( !setVecDefaultValues( plug.child( ROTATEPIVOT_INDEX ), tMatrix.rotatePivot ) )
		return MS::kFailure;

	if( !setVecDefaultValues( plug.child( ROTATEPIVOTTRANS_INDEX ), tMatrix.rotatePivotTranslation ) )
		return MS::kFailure;

	return finishUpdating( parameter, plug );
}