PlugPtr ValuePlug::createCounterpart( const std::string &name, Direction direction ) const { PlugPtr result = new ValuePlug( name, direction, getFlags() ); for( PlugIterator it( this ); !it.done(); ++it ) { result->addChild( (*it)->createCounterpart( (*it)->getName(), direction ) ); } return result; }
PlugPtr CompoundDataPlug::MemberPlug::createCounterpart( const std::string &name, Direction direction ) const { PlugPtr result = new MemberPlug( name, direction, getFlags() ); for( PlugIterator it( this ); it != it.end(); it++ ) { result->addChild( (*it)->createCounterpart( (*it)->getName(), direction ) ); } return result; }
ColorInspector( ImageView *view ) : m_view( view ), m_sampler( new ImageSampler ) { PlugPtr plug = new Plug( "colorInspector" ); view->addChild( plug ); plug->addChild( new V2iPlug( "pixel" ) ); plug->addChild( new Color4fPlug( "color" ) ); // We want to sample the image before the display transforms // are applied. We can't simply get this image from inPlug() // because derived classes may have called insertConverter(), // so we take it from the input to the display transform chain. ImagePlug *image = view->getPreprocessor<Node>()->getChild<Clamp>( "__clamp" )->inPlug(); m_sampler->imagePlug()->setInput( image ); plug->getChild<Color4fPlug>( "color" )->setInput( m_sampler->colorPlug() ); m_view->viewportGadget()->mouseMoveSignal().connect( boost::bind( &ColorInspector::mouseMove, this, ::_2 ) ); m_view->viewportGadget()->getPrimaryChild()->buttonPressSignal().connect( boost::bind( &ColorInspector::buttonPress, this, ::_2 ) ); m_view->viewportGadget()->getPrimaryChild()->dragBeginSignal().connect( boost::bind( &ColorInspector::dragBegin, this, ::_2 ) ); m_view->viewportGadget()->getPrimaryChild()->dragEndSignal().connect( boost::bind( &ColorInspector::dragEnd, this, ::_2 ) ); }
void OSLShader::loadShader( const std::string &shaderName, bool keepExistingValues ) { Plug *existingOut = outPlug(); if( shaderName.empty() ) { parametersPlug()->clearChildren(); namePlug()->setValue( "" ); typePlug()->setValue( "" ); if( existingOut ) { existingOut->clearChildren(); } return; } const char *searchPath = getenv( "OSL_SHADER_PATHS" ); OSLQuery query; if( !query.open( shaderName, searchPath ? searchPath : "" ) ) { throw Exception( query.geterror() ); } const bool outPlugHadChildren = existingOut ? existingOut->children().size() : false; if( !keepExistingValues ) { // If we're not preserving existing values then remove all existing // parameter plugs - the various plug creators above know that if a // plug exists then they should preserve its values. parametersPlug()->clearChildren(); if( existingOut ) { existingOut->clearChildren(); } } m_metadata = NULL; namePlug()->setValue( shaderName ); typePlug()->setValue( std::string( "osl:" ) + query.shadertype().c_str() ); const IECore::CompoundData *metadata = OSLShader::metadata(); const IECore::CompoundData *parameterMetadata = NULL; if( metadata ) { parameterMetadata = metadata->member<IECore::CompoundData>( "parameter" ); } loadShaderParameters( query, parametersPlug(), parameterMetadata ); if( !existingOut || existingOut->typeId() != Plug::staticTypeId() ) { PlugPtr outPlug = new Plug( "out", Plug::Out, Plug::Default | Plug::Dynamic ); if( existingOut ) { // We had an out plug but it was the wrong type (we used // to use a CompoundPlug before that was deprecated). Move // over any existing child plugs onto our replacement. for( PlugIterator it( existingOut ); !it.done(); ++it ) { outPlug->addChild( *it ); } } setChild( "out", outPlug ); } if( query.shadertype() == "shader" ) { loadShaderParameters( query, outPlug(), parameterMetadata ); } else { outPlug()->clearChildren(); } if( static_cast<bool>( outPlug()->children().size() ) != outPlugHadChildren ) { // OSLShaderUI registers a dynamic metadata entry which depends on whether or // not the plug has children, so we must notify the world that the value will // have changed. Metadata::plugValueChangedSignal()( staticTypeId(), "out", "nodule:type", outPlug() ); } }