//-***************************************************************************** // // Copyright (c) 2012, // Sony Pictures Imageworks Inc. and // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. // // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Sony Pictures Imageworks, nor // Industrial Light & Magic, nor the names of their contributors may be used // to endorse or promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //-***************************************************************************** #ifndef PyAlembic_PyOGeomParam_h #define PyAlembic_PyOGeomParam_h #include #include template class SampleDerived : public AbcG::OTypedGeomParam::Sample { public: typedef typename AbcG::OTypedGeomParam::Sample super; typedef AbcU::shared_ptr > samp_type_ptr; SampleDerived() : super() {} SampleDerived( const samp_type_ptr &iValsPtr, const AbcG::GeometryScope iScope ) : super( *iValsPtr, iScope ) { m_valsPtr = iValsPtr; } SampleDerived( const samp_type_ptr &iValsPtr, const Abc::UInt32ArraySample &iIndices, const AbcG::GeometryScope iScope ) : super( *iValsPtr, iIndices, iScope ) { m_valsPtr = iValsPtr; } void setVals( const samp_type_ptr &iValsPtr ) { m_valsPtr = iValsPtr; super::setVals( *m_valsPtr ); } private: samp_type_ptr m_valsPtr; }; template struct registerMemCopyableSample { void operator()( const char* iName ) { using namespace boost::python; typedef AbcG::OTypedGeomParam OGeomParam; class_( iName, init<>() ) .def( init, AbcG::GeometryScope> () [with_custodian_and_ward<1,2>()] ) .def( init, Abc::UInt32ArraySample, AbcG::GeometryScope> () [with_custodian_and_ward<1,2, with_custodian_and_ward<1,3> >()] ) .def( "setVals", &OGeomParam::Sample::setVals, with_custodian_and_ward<1,2>() ) .def( "getVals", &OGeomParam::Sample::getVals, return_value_policy() ) .def( "setIndices", &OGeomParam::Sample::setIndices, with_custodian_and_ward<1,2>() ) .def( "getIndices", &OGeomParam::Sample::getIndices, return_value_policy() ) .def( "setScope", &OGeomParam::Sample::setScope, ( arg( "scope" ) ) ) .def( "getScope", &OGeomParam::Sample::getScope ) .def( "reset", &OGeomParam::Sample::reset ) .def( "valid", &OGeomParam::Sample::valid ) ; } }; template struct registerNonMemCopyableSample { void operator()( const char* iName ) { using namespace boost::python; typedef AbcU::shared_ptr > samp_type_ptr; class_ >( iName, init<>() ) .def( init () [with_custodian_and_ward<1,2>()] ) .def( init () [with_custodian_and_ward<1,2, with_custodian_and_ward<1,3> >()] ) .def( "setVals", &SampleDerived::setVals, with_custodian_and_ward<1,2>() ) .def( "getVals", &SampleDerived::getVals, return_value_policy() ) .def( "setIndices", &SampleDerived::setIndices, with_custodian_and_ward<1,2>() ) .def( "getIndices", &SampleDerived::getIndices, return_value_policy() ) .def( "setScope", &SampleDerived::setScope, ( arg( "scope" ) ) ) .def( "getScope", &SampleDerived::getScope ) .def( "reset", &SampleDerived::reset ) .def( "valid", &SampleDerived::valid ) ; } }; template struct Overloads { public: typedef typename AbcG::OTypedGeomParam OGeomParam; typedef typename AbcG::OTypedGeomParam::Sample Sample; /* static bool matchesMetaData( const AbcA::MetaData& iMetaData, Abc::SchemaInterpMatching iMatching ) { return OGeomParam::matches( iMetaData, iMatching ); } static bool matchesHeader( const AbcA::PropertyHeader& iHeader, Abc::SchemaInterpMatching iMatching ) { return OGeomParam::matches( iHeader, iMatching ); } */ static void set( OGeomParam& iParam, SampleDerived& iSamp ) { Sample samp( iSamp.getVals(), iSamp.getIndices(), iSamp.getScope() ); iParam.set( samp ); } }; template static void register_( const char* iName ) { using namespace boost::python; typedef typename AbcG::OTypedGeomParam OGeomParam; // Overloads // void ( OGeomParam::*setTimeSamplingByIndex )( AbcU ::uint32_t ) = &OGeomParam::setTimeSampling; void ( OGeomParam::*setTimeSamplingByTimeSamplingPtr ) ( AbcA::TimeSamplingPtr ) = &OGeomParam::setTimeSampling; // OTypedGeomParam // class_( iName, "This class is a typed geom param writer.", init<>() ) .def( "getInterpretation", &OGeomParam::getInterpretation ) .staticmethod( "getInterpretation" ) .def( "matches", &OGeomParam::matches, ( arg( "header" ), arg( "matchingSchema" ) = Abc::kStrictMatching ) ) .staticmethod( "matches" ) .def( init >( ( arg( "parent" ), arg( "name" ), arg( "isIndexed" ), arg( "scope" ), arg( "extent" ), arg( "argument" ), arg( "argument" ), arg( "argument" ) ), "doc") ) .def( "set", &Overloads::set, ( arg( "sample" ) ) ) .def( "set", &OGeomParam::set, ( arg( "sample" ) ) ) .def( "setFromPrevious", &OGeomParam::setFromPrevious ) .def( "setTimeSampling", setTimeSamplingByIndex, ( arg( "index" ) ) ) .def( "setTimeSampling", setTimeSamplingByTimeSamplingPtr, ( arg( "TimeSampling" ) ) ) .def( "getNumSamples", &OGeomParam::getNumSamples ) .def( "getDataType", &OGeomParam::getDataType ) .def( "isIndexed", &OGeomParam::isIndexed ) .def( "getScope", &OGeomParam::getScope ) .def( "getTimeSampling", &OGeomParam::getTimeSampling ) .def( "getName", &OGeomParam::getName, return_value_policy() ) .def( "getValueProperty", &OGeomParam::getValueProperty ) .def( "getIndexProperty", &OGeomParam::getIndexProperty ) .def( "valid", &OGeomParam::valid ) .def( "reset", &OGeomParam::reset ) .def( ALEMBIC_PYTHON_BOOL_NAME, &OGeomParam::valid ) ; // OGeomParam::Sample // // std::string sampleName = std::string( iName ) + "Sample"; using namespace boost::mpl; typename if_::memCopyable>, registerMemCopyableSample, registerNonMemCopyableSample >::type registerSamp; registerSamp( sampleName.c_str() ); } #endif