TuttleOFX
1
|
00001 #ifndef _SAM_NODE_IO_HPP_ 00002 #define _SAM_NODE_IO_HPP_ 00003 00004 #include <tuttle/host/Graph.hpp> 00005 00006 #include <boost/algorithm/string/join.hpp> 00007 #include <boost/algorithm/string/split.hpp> 00008 00009 #include <extensions/tuttle/ofxParam.h> 00010 00011 #include <vector> 00012 #include <string> 00013 00014 namespace ttl = ::tuttle::host; 00015 00016 namespace sam { 00017 00018 /** 00019 * @brief Get all values of the property as a vector of strings. 00020 */ 00021 std::vector<std::string> getStringValues( const tuttle::host::ofx::property::OfxhProperty& prop ) 00022 { 00023 std::vector<std::string> s; 00024 for( std::size_t n = 0; n < prop.getDimension(); ++n ) 00025 { 00026 s.push_back( prop.getStringValue( n ) ); 00027 } 00028 return s; 00029 } 00030 00031 /** 00032 * @brief Return a string to represent the property value or values. 00033 * If multiple values, return a string like "a,b,c". 00034 */ 00035 std::string getFormattedStringValue( const tuttle::host::ofx::property::OfxhProperty& prop ) 00036 { 00037 return boost::algorithm::join( getStringValues( prop ), "," ); 00038 } 00039 00040 /** 00041 * @todo 00042 */ 00043 void coutProperties( const ttl::Graph::Node& node ) 00044 { 00045 const ttl::ofx::property::OfxhSet& props = node.getProperties(); 00046 boost::shared_ptr<tuttle::common::Color> color( tuttle::common::Color::get() ); 00047 00048 BOOST_FOREACH( ttl::ofx::property::PropertyMap::const_reference clip, props.getMap() ) 00049 { 00050 TUTTLE_LOG_INFO( 00051 "\t" << 00052 color->_green << 00053 clip.first << " " << 00054 color->_red << 00055 ( clip.second->getDimension() > 1 ? ( std::string( " x" ) + boost::lexical_cast<std::string > ( clip.second->getDimension() ) ) : "" ) << 00056 color->_std 00057 ); 00058 } 00059 } 00060 00061 /** 00062 * @todo 00063 */ 00064 void coutClipsWithDetails( const ttl::Graph::Node& node ) 00065 { 00066 const ttl::ofx::attribute::OfxhClipImageSet& clips = node.getClipImageSet(); 00067 boost::shared_ptr<tuttle::common::Color> color( tuttle::common::Color::get() ); 00068 00069 BOOST_FOREACH( const ttl::ofx::attribute::OfxhClipImage& clip, clips.getClipsByOrder() ) 00070 { 00071 std::stringstream stream; 00072 00073 stream << "\t" << color->_green << std::left << std::setw( 25 ) << clip.getName() << ": " << color->_std; 00074 00075 stream << color->_yellow; 00076 { 00077 std::vector<std::string> components = clip.getSupportedComponents(); 00078 BOOST_FOREACH( std::string& s, components ) 00079 { 00080 s = s.substr( 17 ); // remove 'OfxImageComponent' 00081 } 00082 stream << "[" << boost::algorithm::join( components, ", " ) << "]"; 00083 } 00084 if( clip.getProperties().getIntProperty( kOfxImageClipPropOptional ) ) 00085 { 00086 stream << ", optional"; 00087 } 00088 if( clip.isMask() ) 00089 { 00090 stream << ", mask"; 00091 } 00092 // if( clip.supportsTiles() ) 00093 // { 00094 // stream << " supportTiles"; 00095 // } 00096 if( clip.temporalAccess() ) 00097 { 00098 stream << ", use temporal access"; 00099 } 00100 stream << color->_std; 00101 TUTTLE_LOG_INFO( stream.str() ); 00102 } 00103 } 00104 00105 void coutClips( const ttl::Graph::Node& node ) 00106 { 00107 const ttl::ofx::attribute::OfxhClipImageSet& clips = node.getClipImageSet(); 00108 BOOST_FOREACH( const ttl::ofx::attribute::OfxhClipImage& clip, clips.getClipsByOrder() ) 00109 { 00110 TUTTLE_LOG_INFO( clip.getName() ); 00111 } 00112 } 00113 00114 void coutParameterValues( std::ostream& os, const ttl::ofx::attribute::OfxhParam& param ) 00115 { 00116 using namespace tuttle::host::ofx::property; 00117 00118 if( param.getProperties().hasProperty( kOfxParamPropChoiceOption ) ) 00119 { 00120 const OfxhProperty& prop = param.getProperties().fetchProperty( kOfxParamPropChoiceOption ); 00121 00122 for( std::size_t n = 0; n < prop.getDimension(); ++n ) 00123 { 00124 os << prop.getStringValue( n ) << " "; 00125 } 00126 } 00127 else 00128 { 00129 const OfxhProperty& prop = param.getProperties().fetchProperty( kOfxParamPropDefault ); 00130 const std::string defaultValue = getFormattedStringValue( prop ); 00131 00132 if( ! param.getProperties().hasProperty( kOfxParamPropDisplayMin ) ) 00133 { 00134 // no min/max values, we are not a numeric parameter 00135 os << defaultValue << " "; 00136 } 00137 else 00138 { 00139 // const OfxhProperty& propMin = param.getProperties().fetchProperty( kOfxParamPropMin ); 00140 // const std::string minValue = getFormattedStringValue( propMin ); 00141 const OfxhProperty& propDisplayMin = param.getProperties().fetchProperty( kOfxParamPropDisplayMin ); 00142 const std::string displayMinValue = getFormattedStringValue( propDisplayMin ); 00143 00144 // os << minValue << " "; 00145 // if( minValue != displayMinValue ) 00146 os << displayMinValue << " "; 00147 00148 os << defaultValue << " "; 00149 00150 const OfxhProperty& propDisplayMax = param.getProperties().fetchProperty( kOfxParamPropDisplayMax ); 00151 const std::string displayMaxValue = getFormattedStringValue( propDisplayMax ); 00152 // const OfxhProperty& propMax = param.getProperties().fetchProperty( kOfxParamPropMax ); 00153 // const std::string maxValue = getFormattedStringValue( propMax ); 00154 00155 os << displayMaxValue << " "; 00156 // if( minValue != displayMinValue ) 00157 // os << maxValue << " "; 00158 } 00159 00160 } 00161 } 00162 00163 /* 00164 void coutParametersWithDetails( const ttl::Graph::Node& node ) 00165 { 00166 const ttl::ofx::attribute::OfxhParamSet& params = node.getParamSet(); 00167 BOOST_FOREACH( const ttl::ofx::attribute::OfxhParam& param, params.getParamVector() ) 00168 { 00169 if( param.getSecret() ) 00170 continue; // ignore secret parameters 00171 TUTTLE_LOG_INFO( 00172 "\t" << 00173 color->_green << 00174 param.getScriptName() << ":\t" << 00175 color->_red << 00176 param.getParamType() << 00177 (param.getSize() > 1 ? (std::string(" x") + boost::lexical_cast<std::string>(param.getSize())) : "") << 00178 color->_std 00179 ); 00180 const std::string& hint = param.getHint(); 00181 if( hint.size() ) 00182 { 00183 TUTTLE_LOG_INFO( hint ); 00184 } 00185 TUTTLE_LOG_INFO(""); 00186 } 00187 }*/ 00188 00189 void coutParameterWithDetails( const ttl::ofx::attribute::OfxhParam& param ) 00190 { 00191 using namespace tuttle::host::ofx::property; 00192 boost::shared_ptr<tuttle::common::Color> color( tuttle::common::Color::get() ); 00193 00194 const std::string type = param.getParamType(); 00195 const std::string typeName = param.getParamTypeName(); 00196 00197 // don't print: group, button, page parameters 00198 if( ( type == kOfxParamTypeGroup ) || 00199 ( type == kOfxParamTypePushButton ) || 00200 ( type == kOfxParamTypePage ) ) 00201 return; 00202 00203 std::vector<std::string> defaultValues; 00204 int choiceDefaultIndexValue = 0; 00205 00206 if( param.getProperties().hasProperty( kOfxParamPropDefault ) ) 00207 { 00208 const OfxhProperty& prop = param.getProperties().fetchProperty( kOfxParamPropDefault ); 00209 defaultValues = getStringValues( prop ); 00210 if( prop.getType() == ePropTypeInt ) 00211 { 00212 choiceDefaultIndexValue = param.getProperties().getIntProperty( kOfxParamPropDefault, 0 ); 00213 } 00214 } 00215 00216 if( type == kOfxParamTypeChoice ) 00217 { 00218 std::vector<std::string> choiceValues; 00219 std::vector<std::string> choiceLabelValues; 00220 bool hasLabel = false; 00221 if( param.getProperties().hasProperty( kOfxParamPropChoiceOption ) ) 00222 { 00223 const OfxhProperty& prop = param.getProperties().fetchProperty( kOfxParamPropChoiceOption ); 00224 choiceValues = getStringValues( prop ); 00225 } 00226 if( param.getProperties().hasProperty( kOfxParamPropChoiceLabelOption ) ) 00227 { 00228 const OfxhProperty& prop = param.getProperties().fetchProperty( kOfxParamPropChoiceLabelOption ); 00229 choiceLabelValues = getStringValues( prop ); 00230 hasLabel = ( choiceValues.size() == choiceLabelValues.size() ); 00231 } 00232 if( choiceValues.size() ) // if it's a choice, we take the nth argument 00233 { 00234 static const std::string standardItem = " - "; 00235 static const std::string defaultItem = "--> "; 00236 00237 std::stringstream stream; 00238 stream << "\t" << color->_green << std::left << std::setw( 25 ) << param.getScriptName() << ": " << 00239 color->_std << std::setw( 15 ) << typeName << color->_std; 00240 00241 TUTTLE_LOG_INFO( stream.str() ); 00242 for( std::size_t i = 0; i < choiceValues.size(); ++i ) 00243 { 00244 std::stringstream stream; 00245 stream << "\t\t\t\t\t"; 00246 if( (std::size_t)(choiceDefaultIndexValue) == i ) 00247 { 00248 stream << color->_yellow << defaultItem; 00249 } 00250 else 00251 { 00252 stream << color->_red << standardItem; 00253 } 00254 stream << std::left << std::setw( 20 ) << choiceValues[i]; 00255 if( hasLabel && ! choiceLabelValues[i].empty() ) 00256 { 00257 stream << "\"" << choiceLabelValues[i] << "\""; 00258 } 00259 stream << color->_std; 00260 TUTTLE_LOG_INFO( stream.str() ); 00261 } 00262 } 00263 } 00264 else 00265 { 00266 std::stringstream stream; 00267 const std::string stringDefaultValue = boost::algorithm::join( defaultValues, "," ); 00268 stream << "\t" << 00269 color->_green << std::left << std::setw( 25 ) << param.getScriptName() << ": " << 00270 color->_std << std::setw( 15 ) << typeName << color->_yellow; 00271 00272 stream << boost::algorithm::join( defaultValues, "," ) << color->_std; 00273 00274 if( param.getProperties().hasProperty( kOfxParamPropDisplayMin ) ) 00275 { 00276 const OfxhProperty& propDisplayMin = param.getProperties().fetchProperty( kOfxParamPropDisplayMin ); 00277 const OfxhProperty& propDisplayMax = param.getProperties().fetchProperty( kOfxParamPropDisplayMax ); 00278 const std::string minDisplayValue = getFormattedStringValue( propDisplayMin ); 00279 const std::string maxDisplayValue = getFormattedStringValue( propDisplayMax ); 00280 00281 stream << " [" << minDisplayValue << " --> " << maxDisplayValue << "]"; 00282 } 00283 TUTTLE_LOG_INFO( stream.str() ); 00284 } 00285 00286 if( param.getProperties().hasProperty( kOfxParamPropHint ) ) 00287 { 00288 const std::string& hint = param.getProperties().getStringProperty( kOfxParamPropHint ); 00289 if( hint.size() ) 00290 { 00291 std::vector<std::string> hintSplitted; 00292 boost::split( hintSplitted, hint, boost::is_any_of("\n")); 00293 BOOST_FOREACH( const std::string hintString, hintSplitted ) 00294 { 00295 std::stringstream stream; 00296 stream << std::left << std::setw( 10 ) << " " << hintString; 00297 TUTTLE_LOG_INFO( stream.str() ); 00298 } 00299 } 00300 } 00301 } 00302 00303 void coutParametersWithDetails( const ttl::Graph::Node& node ) 00304 { 00305 const ttl::ofx::attribute::OfxhParamSet& params = node.getParamSet(); 00306 00307 BOOST_FOREACH( const ttl::ofx::attribute::OfxhParam& param, params.getParamVector() ) 00308 { 00309 //if( param.getSecret() ) 00310 // continue; // ignore secret parameters 00311 00312 // if it is a displayable parameter 00313 coutParameterWithDetails( param ); 00314 //TUTTLE_LOG_TRACE( color->_green << "[ " << strParamsContexts << " ]" << color->_std ); 00315 } 00316 } 00317 00318 void coutParameters( const ttl::Graph::Node& node ) 00319 { 00320 const ttl::ofx::attribute::OfxhParamSet& params = node.getParamSet(); 00321 00322 BOOST_FOREACH( const ttl::ofx::attribute::OfxhParam& param, params.getParamVector() ) 00323 { 00324 //if( param.getSecret() ) 00325 // continue; // ignore secret parameters 00326 TUTTLE_LOG_INFO( param.getScriptName() ); 00327 } 00328 } 00329 00330 } 00331 00332 #endif