1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2011,
4 //  Sony Pictures Imageworks, Inc. and
5 //  Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6 //
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 // *       Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // *       Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
17 // distribution.
18 // *       Neither the name of Sony Pictures Imageworks, nor
19 // Industrial Light & Magic nor the names of their contributors may be used
20 // to endorse or promote products derived from this software without specific
21 // prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //-*****************************************************************************
36 
37 #include <Alembic/Abc/OArrayProperty.h>
38 
39 namespace Alembic {
40 namespace Abc {
41 namespace ALEMBIC_VERSION_NS {
42 
43 //-*****************************************************************************
OArrayProperty(OCompoundProperty iParent,const std::string & iName,const AbcA::DataType & iDataType,const Argument & iArg0,const Argument & iArg1,const Argument & iArg2)44 OArrayProperty::OArrayProperty( OCompoundProperty iParent,
45     const std::string &iName, const AbcA::DataType &iDataType,
46     const Argument &iArg0, const Argument &iArg1, const Argument &iArg2 )
47 {
48     init( iParent.getPtr(), iName, iDataType, GetErrorHandlerPolicy( iParent ),
49           iArg0, iArg1, iArg2 );
50 }
51 
52 //-*****************************************************************************
~OArrayProperty()53 OArrayProperty::~OArrayProperty()
54 {
55     // Nothing for now.
56     // Mostly here in case we need to add reference-counting debug code.
57 }
58 
59 //-*****************************************************************************
getNumSamples() const60 size_t OArrayProperty::getNumSamples() const
61 {
62     ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArrayProperty::getNumSamples()" );
63 
64     return m_property->getNumSamples();
65 
66     ALEMBIC_ABC_SAFE_CALL_END();
67 
68     return 0;
69 }
70 
71 //-*****************************************************************************
set(const AbcA::ArraySample & iSamp)72 void OArrayProperty::set( const AbcA::ArraySample &iSamp )
73 {
74     ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArrayProperty::set()" );
75 
76     m_property->setSample( iSamp );
77 
78     ALEMBIC_ABC_SAFE_CALL_END();
79 }
80 
81 //-*****************************************************************************
setFromPrevious()82 void OArrayProperty::setFromPrevious()
83 {
84     ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArrayProperty::setFromPrevious()" );
85 
86     m_property->setFromPreviousSample();
87 
88     ALEMBIC_ABC_SAFE_CALL_END();
89 }
90 
91 //-*****************************************************************************
setTimeSampling(uint32_t iIndex)92 void OArrayProperty::setTimeSampling( uint32_t iIndex )
93 {
94     ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArrayProperty::setTimeSampling(uint32_t)" );
95 
96     m_property->setTimeSamplingIndex(iIndex);
97 
98     ALEMBIC_ABC_SAFE_CALL_END();
99 }
100 
101 //-*****************************************************************************
setTimeSampling(AbcA::TimeSamplingPtr iTime)102 void OArrayProperty::setTimeSampling(  AbcA::TimeSamplingPtr iTime )
103 {
104     ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArrayProperty::setTimeSampling()" );
105 
106     uint32_t tsIndex =
107         m_property->getParent()->getObject()->getArchive()->addTimeSampling(
108             *iTime);
109 
110     m_property->setTimeSamplingIndex(tsIndex);
111 
112     ALEMBIC_ABC_SAFE_CALL_END();
113 }
114 
115 //-*****************************************************************************
getParent() const116 OCompoundProperty OArrayProperty::getParent() const
117 {
118     ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArrayProperty::getParent()" );
119 
120     return OCompoundProperty( m_property->getParent(),
121                               getErrorHandlerPolicy() );
122 
123     ALEMBIC_ABC_SAFE_CALL_END();
124 
125     // Not all error handlers throw. Have a default.
126     return OCompoundProperty();
127 }
128 
129 //-*****************************************************************************
init(AbcA::CompoundPropertyWriterPtr iParent,const std::string & iName,const AbcA::DataType & iDataType,ErrorHandler::Policy iParentPolicy,const Argument & iArg0,const Argument & iArg1,const Argument & iArg2)130 void OArrayProperty::init( AbcA::CompoundPropertyWriterPtr iParent,
131                            const std::string &iName,
132                            const AbcA::DataType &iDataType,
133 
134                            ErrorHandler::Policy iParentPolicy,
135                            const Argument &iArg0,
136                            const Argument &iArg1,
137                            const Argument &iArg2 )
138 {
139     Arguments args( iParentPolicy );
140     iArg0.setInto( args );
141     iArg1.setInto( args );
142     iArg2.setInto( args );
143 
144     getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
145 
146     ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArrayProperty::init()" );
147 
148     AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
149     uint32_t tsIndex = args.getTimeSamplingIndex();
150 
151     // if we specified a valid TimeSamplingPtr, use it to determine the index
152     // otherwise we'll use the index, which defaults to the intrinsic 0 index
153     if (tsPtr)
154     {
155         tsIndex = iParent->getObject()->getArchive()->addTimeSampling(*tsPtr);
156     }
157 
158     m_property = iParent->createArrayProperty( iName, args.getMetaData(),
159         iDataType, tsIndex );
160 
161     ALEMBIC_ABC_SAFE_CALL_END_RESET();
162 }
163 
164 } // End namespace ALEMBIC_VERSION_NS
165 } // End namespace Abc
166 } // End namespace Alembic
167