TuttleOFX  1
SeExprPlugin.cpp
Go to the documentation of this file.
00001 #include "SeExprPlugin.hpp"
00002 #include "SeExprProcess.hpp"
00003 #include "SeExprDefinitions.hpp"
00004 
00005 #include <boost/gil/gil_all.hpp>
00006 #include <fstream>
00007 
00008 namespace tuttle {
00009 namespace plugin {
00010 namespace seExpr {
00011 
00012 
00013 SeExprPlugin::SeExprPlugin( OfxImageEffectHandle handle )
00014         : GeneratorPlugin( handle )
00015 {
00016         _paramInput         = fetchChoiceParam  ( kParamChooseInput );
00017         _paramCode          = fetchStringParam  ( kParamSeExprCode );
00018         _paramFile          = fetchStringParam  ( kTuttlePluginFilename );
00019         _paramTextureOffset = fetchDouble2DParam( kParamTextureOffset );
00020         
00021         changedParam ( _instanceChangedArgs, kParamChooseInput );
00022 }
00023 
00024 SeExprProcessParams<SeExprPlugin::Scalar> SeExprPlugin::getProcessParams( const OfxPointD& renderScale ) const
00025 {
00026         SeExprProcessParams<Scalar> params;
00027         params._inputType = static_cast<EParamChooseInput>( _paramInput->getValue() );
00028         switch( params._inputType )
00029         {
00030                 case eParamChooseInputCode:
00031                 {
00032                         params._code = _paramCode->getValue();
00033                         break;
00034                 }
00035                 case eParamChooseInputFile:
00036                 {
00037                         try
00038                         {
00039                                 std::ifstream myfile( _paramFile->getValue().c_str(), std::ifstream::in );
00040                                 if( myfile.is_open() )
00041                                 {
00042                                         while ( myfile.good() )
00043                                         {
00044                                                 std::string line;
00045                                                 getline( myfile, line );
00046                                                 params._code +=  line + "\n";
00047                                         }
00048                                         myfile.close();
00049                                 }
00050                         }
00051                         catch( ... )
00052                         {
00053                                 //BOOST_THROW_EXCEPTION( exception::File() << "unable to read file " + _paramFile->getValue() );
00054                         }
00055                         break;
00056                 }
00057         }
00058         
00059         OfxPointD textureOffset      = _paramTextureOffset->getValue();
00060         params._paramTextureOffset.x = textureOffset.x;
00061         params._paramTextureOffset.y = textureOffset.y;
00062         
00063         return params;
00064 }
00065 
00066 void SeExprPlugin::changedParam( const OFX::InstanceChangedArgs &args, const std::string &paramName )
00067 {
00068         GeneratorPlugin::changedParam( args, paramName );
00069         
00070         if( paramName == kParamChooseInput )
00071         {
00072                 EParamChooseInput input = static_cast<EParamChooseInput>( _paramInput->getValue() );
00073                 switch( input )
00074                 {
00075                         case eParamChooseInputCode:
00076                         {
00077                                 _paramCode->setIsSecretAndDisabled( false );
00078                                 _paramFile->setIsSecretAndDisabled( true );
00079                                 break;
00080                         }
00081                         case eParamChooseInputFile:
00082                         {
00083                                 _paramCode->setIsSecretAndDisabled( true );
00084                                 _paramFile->setIsSecretAndDisabled( false );
00085                                 break;
00086                         }
00087                 }
00088         }
00089         
00090         if( paramName == kParamSeExprCode )
00091         {
00092                 _paramInput->setValue( eParamChooseInputCode );
00093         }
00094         
00095         if( paramName == kTuttlePluginFilename )
00096         {
00097                 _paramInput->setValue( eParamChooseInputFile );
00098         }
00099 }
00100 
00101 void SeExprPlugin::getClipPreferences( OFX::ClipPreferencesSetter& clipPreferences )
00102 {
00103         GeneratorPlugin::getClipPreferences( clipPreferences );
00104 }
00105 
00106 /**
00107  * @brief The overridden render function
00108  * @param[in]   args     Rendering parameters
00109  */
00110 void SeExprPlugin::render( const OFX::RenderArguments &args )
00111 {
00112         doGilRender<SeExprProcess>( *this, args );
00113 }
00114 
00115 
00116 }
00117 }
00118 }