TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/attribute/OfxhParamDescriptor.cpp
Go to the documentation of this file.
00001 #include "OfxhParamDescriptor.hpp"
00002 
00003 #include <extensions/tuttle/ofxParam.h>
00004 
00005 namespace tuttle {
00006 namespace host {
00007 namespace ofx {
00008 namespace attribute {
00009 
00010 struct TypeMap
00011 {
00012         const char* paramType;
00013         property::EPropType propType;
00014         int propDimension;
00015 };
00016 
00017 bool isDoubleParam( const std::string& paramType )
00018 {
00019         return paramType == kOfxParamTypeDouble ||
00020                paramType == kOfxParamTypeDouble2D ||
00021                paramType == kOfxParamTypeDouble3D;
00022 }
00023 
00024 bool isColourParam( const std::string& paramType )
00025 {
00026         return
00027             paramType == kOfxParamTypeRGBA ||
00028             paramType == kOfxParamTypeRGB;
00029 }
00030 
00031 bool isIntParam( const std::string& paramType )
00032 {
00033         return paramType == kOfxParamTypeInteger ||
00034                paramType == kOfxParamTypeInteger2D ||
00035                paramType == kOfxParamTypeInteger3D;
00036 }
00037 
00038 static TypeMap typeMap[] = {
00039         { kOfxParamTypeInteger, property::ePropTypeInt, 1 },
00040         { kOfxParamTypeDouble, property::ePropTypeDouble, 1 },
00041         { kOfxParamTypeBoolean, property::ePropTypeInt, 1 },
00042         { kOfxParamTypeChoice, property::ePropTypeInt, 1 },
00043         { kOfxParamTypeRGBA, property::ePropTypeDouble, 4 },
00044         { kOfxParamTypeRGB, property::ePropTypeDouble, 3 },
00045         { kOfxParamTypeDouble2D, property::ePropTypeDouble, 2 },
00046         { kOfxParamTypeInteger2D, property::ePropTypeInt, 2 },
00047         { kOfxParamTypeDouble3D, property::ePropTypeDouble, 3 },
00048         { kOfxParamTypeInteger3D, property::ePropTypeInt, 3 },
00049         { kOfxParamTypeString, property::ePropTypeString, 1 },
00050         { kOfxParamTypeCustom, property::ePropTypeString, 1 },
00051         { kOfxParamTypeGroup, property::ePropTypeNone },
00052         { kOfxParamTypePage, property::ePropTypeNone },
00053         { kOfxParamTypePushButton, property::ePropTypeNone },
00054         { 0 }
00055 };
00056 
00057 /// is this a standard type
00058 bool isStandardType( const std::string& type )
00059 {
00060         TypeMap* tm = typeMap;
00061 
00062         while( tm->paramType )
00063         {
00064                 if( tm->paramType == type )
00065                         return true;
00066                 ++tm;
00067         }
00068         return false;
00069 }
00070 
00071 bool findType( const std::string& paramType, property::EPropType& propType, int& propDim )
00072 {
00073         TypeMap* tm = typeMap;
00074 
00075         while( tm->paramType )
00076         {
00077                 if( tm->paramType == paramType )
00078                 {
00079                         propType = tm->propType;
00080                         propDim  = tm->propDimension;
00081                         return true;
00082                 }
00083                 ++tm;
00084         }
00085         return false;
00086 }
00087 
00088 /**
00089  * @brief make a parameter, with the given type and name
00090  */
00091 OfxhParamDescriptor::OfxhParamDescriptor( const std::string& type, const std::string& name )
00092         : attribute::OfxhAttributeDescriptor( property::OfxhSet() )
00093 {
00094         const char* ctype = type.c_str();
00095         const char* cname = name.c_str();
00096 
00097         static const property::OfxhPropSpec paramDescriptorProps[] = {
00098                 { kOfxPropType, property::ePropTypeString, 1, true, kOfxTypeParameter },
00099                 { kOfxParamPropSecret, property::ePropTypeInt, 1, false, "0" },
00100                 { kOfxParamPropHint, property::ePropTypeString, 1, false, "" },
00101                 { kOfxParamPropParent, property::ePropTypeString, 1, false, "" },
00102                 { kOfxParamPropEnabled, property::ePropTypeInt, 1, false, "1" },
00103                 { kOfxParamPropDataPtr, property::ePropTypePointer, 1, false, 0 },
00104                 { 0 }
00105         };
00106 
00107         const property::OfxhPropSpec dynamicParamDescriptorProps[] = {
00108                 { kOfxParamPropType, property::ePropTypeString, 1, true, ctype },
00109                 { kOfxParamPropScriptName, property::ePropTypeString, 1, false, cname }, ///< @todo TUTTLE_TODO : common property for all Attributes
00110                 { 0 }
00111         };
00112 
00113         getEditableProperties().addProperties( paramDescriptorProps );
00114         getEditableProperties().addProperties( dynamicParamDescriptorProps );
00115 
00116         setAllNames( name );
00117 
00118         getEditableProperties().setStringProperty( kOfxParamPropType, type );
00119         assert( ctype );
00120 }
00121 
00122 /**
00123  * make a parameter, with the given type and name
00124  */
00125 void OfxhParamDescriptor::initStandardParamProps( const std::string& type )
00126 {
00127         property::EPropType propType = property::ePropTypeString;
00128         int propDim                 = 1;
00129 
00130         findType( type, propType, propDim );
00131 
00132 
00133         if( propType != property::ePropTypeNone )
00134                 initValueParamProps( type, propType, propDim );
00135         else
00136                 initNoValueParamProps();
00137 
00138         if( type == kOfxParamTypeString )
00139         {
00140                 static const property::OfxhPropSpec allString[] = {
00141                         { kOfxParamPropStringMode, property::ePropTypeString, 1, false, kOfxParamStringIsSingleLine },
00142                         { kOfxParamPropStringFilePathExists, property::ePropTypeInt, 1, false, "1" },
00143                         { 0 }
00144                 };
00145 
00146                 getEditableProperties().addProperties( allString );
00147         }
00148 
00149         if( isDoubleParam( type ) || isIntParam( type ) || isColourParam( type ) )
00150         {
00151                 initNumericParamProps( type, propType, propDim );
00152         }
00153 
00154         if( type != kOfxParamTypeGroup && type != kOfxParamTypePage )
00155         {
00156                 initInteractParamProps( type );
00157         }
00158 
00159         if( type == kOfxParamTypeChoice )
00160         {
00161                 static const property::OfxhPropSpec allChoice[] = {
00162                         { kOfxParamPropChoiceOption, property::ePropTypeString, 0, false, "" },
00163                         { kOfxParamPropChoiceLabelOption, property::ePropTypeString, 0, false, "" },
00164                         { 0 }
00165                 };
00166 
00167                 getEditableProperties().addProperties( allChoice );
00168         }
00169         else if( type == kOfxParamTypeCustom )
00170         {
00171                 static const property::OfxhPropSpec allCustom[] = {
00172                         { kOfxParamPropCustomInterpCallbackV1, property::ePropTypePointer, 1, false, 0 },
00173                         { 0 },
00174                 };
00175 
00176                 getEditableProperties().addProperties( allCustom );
00177         }
00178         else if( type == kOfxParamTypePage )
00179         {
00180                 static const property::OfxhPropSpec allPage[] = {
00181                         { kOfxParamPropPageChild, property::ePropTypeString, 0, false, "" },
00182                         { 0 }
00183                 };
00184                 getEditableProperties().addProperties( allPage );
00185         }
00186         else if( type == kOfxParamTypeGroup )
00187         {
00188                 static const property::OfxhPropSpec allGroup[] = {
00189                         { kOfxParamPropGroupOpen, property::ePropTypeInt, 1, false, "1" },
00190                         { 0 }
00191                 };
00192 
00193                 getEditableProperties().addProperties( allGroup );
00194         }
00195 }
00196 
00197 /**
00198  * add standard properties to a params that can take an interact
00199  */
00200 void OfxhParamDescriptor::initInteractParamProps( const std::string& type )
00201 {
00202         static const property::OfxhPropSpec allButGroupPageProps[] = {
00203                 { kOfxParamPropInteractV1, property::ePropTypePointer, 1, false, 0 },
00204                 { kOfxParamPropInteractSize, property::ePropTypeDouble, 2, false, "0" },
00205                 { kOfxParamPropInteractSizeAspect, property::ePropTypeDouble, 1, false, "1" },
00206                 { kOfxParamPropInteractMinimumSize, property::ePropTypeInt, 2, false, "10" },
00207                 { kOfxParamPropInteractPreferedSize, property::ePropTypeInt, 2, false, "10" },
00208                 { 0 }
00209         };
00210 
00211         getEditableProperties().addProperties( allButGroupPageProps );
00212 }
00213 
00214 /**
00215  * add standard properties to a value holding param
00216  */
00217 void OfxhParamDescriptor::initValueParamProps( const std::string& type, property::EPropType valueType, int dim )
00218 {
00219         static const property::OfxhPropSpec invariantProps[] = {
00220                 { kOfxParamPropAnimates, property::ePropTypeInt, 1, false, "1" },
00221                 { kOfxParamPropIsAnimating, property::ePropTypeInt, 1, false, "0" },
00222                 { kOfxParamPropIsAutoKeying, property::ePropTypeInt, 1, false, "0" },
00223                 { kOfxParamPropPersistant, property::ePropTypeInt, 1, false, "1" },
00224                 { kOfxParamPropEvaluateOnChange, property::ePropTypeInt, 1, false, "1" },
00225                 { kOfxParamPropPluginMayWrite, property::ePropTypeInt, 1, false, "0" },
00226                 { kOfxParamPropCanUndo, property::ePropTypeInt, 1, false, "1" },
00227                 { kOfxParamPropCacheInvalidation, property::ePropTypeString, 1, false, kOfxParamInvalidateValueChange },
00228                 { 0 }
00229         };
00230 
00231         property::OfxhPropSpec variantProps[] = {
00232                 { kOfxParamPropDefault, valueType, dim, false, valueType == property::ePropTypeString ? "" : "0" },
00233                 { 0 }
00234         };
00235 
00236         getEditableProperties().addProperties( invariantProps );
00237         getEditableProperties().addProperties( variantProps );
00238 }
00239 
00240 void OfxhParamDescriptor::initNoValueParamProps()
00241 {
00242         static const property::OfxhPropSpec invariantProps[] = {
00243                 { kOfxParamPropAnimates, property::ePropTypeInt, 1, false, "0" },
00244                 { kOfxParamPropIsAnimating, property::ePropTypeInt, 1, false, "0" },
00245                 { kOfxParamPropIsAutoKeying, property::ePropTypeInt, 1, false, "0" },
00246                 { kOfxParamPropPersistant, property::ePropTypeInt, 1, false, "0" },
00247                 { kOfxParamPropEvaluateOnChange, property::ePropTypeInt, 1, false, "0" },
00248                 { kOfxParamPropPluginMayWrite, property::ePropTypeInt, 1, false, "0" },
00249                 { kOfxParamPropCanUndo, property::ePropTypeInt, 1, false, "0" },
00250                 { kOfxParamPropCacheInvalidation, property::ePropTypeString, 1, false, "" },
00251                 { 0 }
00252         };
00253 
00254         getEditableProperties().addProperties( invariantProps );
00255 }
00256 
00257 /**
00258  * add standard properties to a value holding param
00259  */
00260 void OfxhParamDescriptor::initNumericParamProps( const std::string& type, property::EPropType valueType, int dim )
00261 {
00262         static std::string dbl_minstr, dbl_maxstr, int_minstr, int_maxstr;
00263 
00264         {
00265                 std::ostringstream dbl_min, dbl_max, int_min, int_max;
00266                 dbl_min << -std::numeric_limits<double>::max();
00267                 dbl_max << std::numeric_limits<double>::max();
00268                 int_min << std::numeric_limits<int>::min();
00269                 int_max << std::numeric_limits<int>::max();
00270 
00271                 dbl_minstr = dbl_min.str();
00272                 dbl_maxstr = dbl_max.str();
00273                 int_minstr = int_min.str();
00274                 int_maxstr = int_max.str();
00275         }
00276 
00277         property::OfxhPropSpec allNumeric[] = {
00278                 { kOfxParamPropDisplayMin, valueType, dim, false, isColourParam( type ) ? "0" : ( valueType == property::ePropTypeDouble ? dbl_minstr : int_minstr ).c_str() },
00279                 { kOfxParamPropDisplayMax, valueType, dim, false, isColourParam( type ) ? "1" : ( valueType == property::ePropTypeDouble ? dbl_maxstr : int_maxstr ).c_str() },
00280                 { kOfxParamPropMin, valueType, dim, false, ( valueType == property::ePropTypeDouble ? dbl_minstr : int_minstr ).c_str() },
00281                 { kOfxParamPropMax, valueType, dim, false, ( valueType == property::ePropTypeDouble ? dbl_maxstr : int_maxstr ).c_str() },
00282                 { 0 }
00283         };
00284 
00285         getEditableProperties().addProperties( allNumeric );
00286 
00287         /// if any double or a colour
00288         if( valueType == property::ePropTypeDouble )
00289         {
00290                 static const property::OfxhPropSpec allDouble[] = {
00291                         { kOfxParamPropIncrement, property::ePropTypeDouble, 1, false, "1" },
00292                         { kOfxParamPropDigits, property::ePropTypeInt, 1, false, "2" },
00293                         { 0 }
00294                 };
00295                 getEditableProperties().addProperties( allDouble );
00296         }
00297 
00298         /// if a double param type
00299         if( isDoubleParam( type ) )
00300         {
00301                 static const property::OfxhPropSpec allDouble[] = {
00302                         { kOfxParamPropDoubleType, property::ePropTypeString, 1, false, kOfxParamDoubleTypePlain },
00303                         { 0 }
00304                 };
00305                 getEditableProperties().addProperties( allDouble );
00306 
00307                 if( dim == 1 )
00308                 {
00309                         static const property::OfxhPropSpec allDouble1D[] = {
00310                                 { kOfxParamPropShowTimeMarker, property::ePropTypeInt, 1, false, "0" },
00311                                 { 0 }
00312                         };
00313 
00314                         getEditableProperties().addProperties( allDouble1D );
00315                 }
00316         }
00317 
00318         /// if a multi dimensional param
00319         if( isDoubleParam( type ) && ( dim == 2 || dim == 3 ) )
00320         {
00321                 property::OfxhPropSpec all2D3D[] = {
00322                         { kOfxParamPropDimensionLabel, property::ePropTypeString, dim, false, "" },
00323                         { 0 },
00324                 };
00325 
00326                 getEditableProperties().addProperties( all2D3D );
00327                 getEditableProperties().setStringProperty( kOfxParamPropDimensionLabel, "X", 0 );
00328                 getEditableProperties().setStringProperty( kOfxParamPropDimensionLabel, "Y", 1 );
00329                 if( dim == 3 )
00330                 {
00331                         getEditableProperties().setStringProperty( kOfxParamPropDimensionLabel, "Z", 2 );
00332                 }
00333         }
00334 
00335         /// if a multi dimensional param
00336         if( isColourParam( type ) )
00337         {
00338                 property::OfxhPropSpec allColor[] = {
00339                         { kOfxParamPropDimensionLabel, property::ePropTypeString, dim, false, "" },
00340                         { 0 },
00341                 };
00342 
00343                 getEditableProperties().addProperties( allColor );
00344                 getEditableProperties().setStringProperty( kOfxParamPropDimensionLabel, "R", 0 );
00345                 getEditableProperties().setStringProperty( kOfxParamPropDimensionLabel, "G", 1 );
00346                 getEditableProperties().setStringProperty( kOfxParamPropDimensionLabel, "B", 2 );
00347                 if( dim == 4 )
00348                 {
00349                         getEditableProperties().setStringProperty( kOfxParamPropDimensionLabel, "A", 3 );
00350                 }
00351         }
00352 }
00353 
00354 }
00355 }
00356 }
00357 }