bool GraphGadget::dragEnd( GadgetPtr gadget, const DragDropEvent &event ) { DragMode dragMode = m_dragMode; m_dragMode = None; Pointer::setCurrent( "" ); if( !m_scriptNode ) { return false; } V3f i; if( !event.line.intersect( Plane3f( V3f( 0, 0, 1 ), 0 ), i ) ) { return false; } if( dragMode == Moving ) { if ( m_dragReconnectCandidate ) { if ( m_dragReconnectDstNodule || m_dragReconnectSrcNodule ) { Gaffer::Plug *srcPlug = m_dragReconnectCandidate->srcNodule()->plug(); Gaffer::Plug *dstPlug = m_dragReconnectCandidate->dstNodule()->plug(); Gaffer::UndoContext undoContext( m_scriptNode ); if ( m_dragReconnectDstNodule ) { m_dragReconnectDstNodule->plug()->setInput( srcPlug ); dstPlug->setInput( 0 ); } if ( m_dragReconnectSrcNodule ) { dstPlug->setInput( m_dragReconnectSrcNodule->plug() ); } } } m_dragReconnectCandidate = 0; renderRequestSignal()( this ); } else if( dragMode == Selecting ) { updateDragSelection( true ); renderRequestSignal()( this ); } return true; }
void GraphGadget::addConnectionGadget( Gaffer::Plug *dstPlug ) { Gaffer::Plug *srcPlug = dstPlug->getInput<Gaffer::Plug>(); if( !srcPlug ) { // there is no connection return; } Gaffer::Node *dstNode = dstPlug->node(); NodeGadget *dstNodeGadget = findNodeGadget( dstNode ); if( !dstNodeGadget ) { return; } Nodule *dstNodule = dstNodeGadget->nodule( dstPlug ); if( !dstNodule ) { // the destination connection point is not represented in the graph return; } Gaffer::Node *srcNode = srcPlug->node(); if( srcNode == dstNode ) { // we don't want to visualise connections between plugs // on the same node. return; } // find the input nodule for the connection if there is one NodeGadget *srcNodeGadget = findNodeGadget( srcNode ); Nodule *srcNodule = 0; if( srcNodeGadget ) { srcNodule = srcNodeGadget->nodule( srcPlug ); } ConnectionGadgetPtr connection = new ConnectionGadget( srcNodule, dstNodule ); updateConnectionGadgetMinimisation( connection.get() ); addChild( connection ); m_connectionGadgets[dstPlug] = connection.get(); }
void GraphGadget::updateDragReconnectCandidate( const DragDropEvent &event ) { m_dragReconnectCandidate = 0; m_dragReconnectSrcNodule = 0; m_dragReconnectDstNodule = 0; if ( m_scriptNode->selection()->size() != 1 ) { return; } // make sure the connection applies to this node. Gaffer::Node *node = IECore::runTimeCast<Gaffer::Node>( m_scriptNode->selection()->member( 0 ) ); NodeGadget *selNodeGadget = nodeGadget( node ); if ( !node || !selNodeGadget ) { return; } m_dragReconnectCandidate = reconnectionGadgetAt( selNodeGadget, event.line ); if ( !m_dragReconnectCandidate ) { return; } // we don't want to reconnect the selected node to itself Gaffer::Plug *srcPlug = m_dragReconnectCandidate->srcNodule()->plug(); Gaffer::Plug *dstPlug = m_dragReconnectCandidate->dstNodule()->plug(); if ( srcPlug->node() == node || dstPlug->node() == node ) { m_dragReconnectCandidate = 0; return; } Gaffer::DependencyNode *depNode = IECore::runTimeCast<Gaffer::DependencyNode>( node ); for ( Gaffer::RecursiveOutputPlugIterator cIt( node ); cIt != cIt.end(); ++cIt ) { // must be compatible Gaffer::Plug *p = cIt->get(); if ( !dstPlug->acceptsInput( p ) ) { continue; } // must have a nodule m_dragReconnectSrcNodule = selNodeGadget->nodule( p ); if ( !m_dragReconnectSrcNodule ) { continue; } // must not be connected to a nodule for ( Gaffer::Plug::OutputContainer::const_iterator oIt = p->outputs().begin(); oIt != p->outputs().end(); ++oIt ) { NodeGadget *oNodeGadget = nodeGadget( (*oIt)->node() ); if ( oNodeGadget && oNodeGadget->nodule( *oIt ) ) { m_dragReconnectSrcNodule = 0; break; } } if ( !m_dragReconnectSrcNodule ) { continue; } if ( !depNode ) { // found the best option break; } // make sure its corresponding input is also free if ( Gaffer::Plug *in = depNode->correspondingInput( p ) ) { if ( in->getInput<Gaffer::Plug>() ) { m_dragReconnectSrcNodule = 0; continue; } m_dragReconnectDstNodule = selNodeGadget->nodule( in ); if ( m_dragReconnectDstNodule ) { break; } } } // check input plugs on non-dependencyNodes if ( !depNode && !m_dragReconnectDstNodule ) { for ( Gaffer::RecursiveInputPlugIterator cIt( node ); cIt != cIt.end(); ++cIt ) { Gaffer::Plug *p = cIt->get(); if ( !p->getInput<Gaffer::Plug>() && p->acceptsInput( srcPlug ) ) { m_dragReconnectDstNodule = selNodeGadget->nodule( p ); if ( m_dragReconnectDstNodule ) { break; } } } } if ( !m_dragReconnectSrcNodule && !m_dragReconnectDstNodule ) { m_dragReconnectCandidate = 0; } }
bool GraphGadget::dragEnd( GadgetPtr gadget, const DragDropEvent &event ) { DragMode dragMode = m_dragMode; m_dragMode = None; Pointer::set( 0 ); if( !m_scriptNode ) { return false; } V3f i; if( !event.line.intersect( Plane3f( V3f( 0, 0, 1 ), 0 ), i ) ) { return false; } if( dragMode == Moving ) { if ( m_dragReconnectCandidate ) { if ( m_dragReconnectDstNodule || m_dragReconnectSrcNodule ) { Gaffer::Plug *srcPlug = m_dragReconnectCandidate->srcNodule()->plug(); Gaffer::Plug *dstPlug = m_dragReconnectCandidate->dstNodule()->plug(); Gaffer::UndoContext undoContext( m_scriptNode ); if ( m_dragReconnectDstNodule ) { m_dragReconnectDstNodule->plug()->setInput( srcPlug ); dstPlug->setInput( 0 ); } if ( m_dragReconnectSrcNodule ) { dstPlug->setInput( m_dragReconnectSrcNodule->plug() ); } } } m_dragReconnectCandidate = 0; renderRequestSignal()( this ); } else if( dragMode == Selecting ) { Box2f selectionBound; selectionBound.extendBy( m_dragStartPosition ); selectionBound.extendBy( m_lastDragPosition ); for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ ) { NodeGadgetPtr nodeGadget = runTimeCast<NodeGadget>( *it ); if( nodeGadget ) { Box3f nodeBound3 = nodeGadget->transformedBound(); Box2f nodeBound2( V2f( nodeBound3.min.x, nodeBound3.min.y ), V2f( nodeBound3.max.x, nodeBound3.max.y ) ); if( boxContains( selectionBound, nodeBound2 ) ) { m_scriptNode->selection()->add( nodeGadget->node() ); } } } renderRequestSignal()( this ); } return true; }
void AppleseedLight::setupPlugs( const std::string &shaderName, const asf::DictionaryArray &metadata ) { bool needsRadianceTexture = shaderName.find( "map" ) != std::string::npos; for( size_t i = 0, e = metadata.size(); i < e; ++i ) { const asf::Dictionary &inputMetadata = metadata[i]; std::string inputName = inputMetadata.get( "name" ); std::string inputType = inputMetadata.get( "type" ); Gaffer::Plug *plug = nullptr; // some environment lights need their radiance color input // replaced by a texture input: latlong map and mirrorball map. if( needsRadianceTexture && inputName == "radiance" ) { plug = new Gaffer::StringPlug( "radiance_map", Gaffer::Plug::In ); } else { if( inputType == "numeric" ) { float defaultValue = inputMetadata.get<float>( "default" ); float minValue = get_min_max_value( inputMetadata, "min" ); float maxValue = get_min_max_value( inputMetadata, "max" ); plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, defaultValue, minValue, maxValue ); } else if( inputType == "colormap" ) { // override the plug type for the exposure param (usually it's a color in appleseed). if ( inputName == "exposure" ) { plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, 0.0f ); } // multiplier inputs make more sense in Gaffer as float plugs. else if( inputName.find( "multiplier" ) != std::string::npos ) { plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, 1.0f, 0.0f ); } else { plug = new Gaffer::Color3fPlug( inputName, Gaffer::Plug::In, Imath::Color3f( 1.0f ) ); } } else if( inputType == "boolean" ) { bool defaultValue = strcmp( inputMetadata.get( "default" ), "true" ) == 0; plug = new Gaffer::BoolPlug( inputName, Gaffer::Plug::In, defaultValue ); } // text are non-texturable float inputs. else if( inputType == "text" ) { float defaultValue = inputMetadata.get<float>( "default" ); plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, defaultValue ); } } if( plug ) { plug->setFlags( Gaffer::Plug::Dynamic, true ); parametersPlug()->addChild( plug ); } } }
void AppleseedLight::setupPlugs( const std::string &shaderName, const asf::DictionaryArray &metadata ) { bool needsRadianceTexture = shaderName.find( "map" ) != std::string::npos; for( size_t i = 0, e = metadata.size(); i < e; ++i ) { const asf::Dictionary &inputMetadata = metadata[i]; std::string inputName = inputMetadata.get( "name" ); std::string inputType = inputMetadata.get( "type" ); Gaffer::Plug *plug = 0; // some environment lights need their radiance color input // replaced by a texture input: latlong map and mirrorball map. if( needsRadianceTexture && inputName == "radiance" ) { plug = new Gaffer::StringPlug( "radiance_map", Gaffer::Plug::In ); } else { if( inputType == "numeric" ) { float defaultValue = boost::lexical_cast<float>( inputMetadata.get( "default" ) ); float minValue = boost::lexical_cast<float>( inputMetadata.get( "min_value" ) ); float maxValue = boost::lexical_cast<float>( inputMetadata.get( "max_value" ) ); plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, defaultValue, minValue, maxValue ); } else if( inputType == "colormap" ) { // multiplier inputs make more sense is Gaffer as float plugs. if( inputName.find( "multiplier" ) != std::string::npos ) { plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, 1.0f, 0.0f ); } else { plug = new Gaffer::Color3fPlug( inputName, Gaffer::Plug::In, Imath::Color3f( 1.0f ) ); } } else if( inputType == "boolean" ) { bool defaultValue = strcmp( inputMetadata.get( "default" ), "true" ) == 0; plug = new Gaffer::BoolPlug( inputName, Gaffer::Plug::In, defaultValue ); } // text are non-texturable float inputs. else if( inputType == "text" ) { float defaultValue = boost::lexical_cast<float>( inputMetadata.get( "default" ) ); plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, defaultValue ); } // entity represent connections between entities that can work together, // like the sky environments and the sun light. else if( inputType == "entity" ) { plug = new Gaffer::StringPlug( inputName, Gaffer::Plug::In ); } } if( plug ) { plug->setFlags( Gaffer::Plug::Dynamic, true ); parametersPlug()->addChild( plug ); } } }