Ejemplo n.º 1
0
bool ScriptNode::importFile( const std::string &fileName, Node *parent, bool continueOnError )
{
	DirtyPropagationScope dirtyScope;

	ScriptNodePtr script = new ScriptNode();
	script->fileNamePlug()->setValue( fileName );
	bool result = script->load( continueOnError );

	StandardSetPtr nodeSet = new StandardSet();
	nodeSet->add( NodeIterator( script.get() ), NodeIterator( script->children().end(), script->children().end() ) );
	const std::string nodeSerialisation = script->serialise( script.get(), nodeSet.get() );

	result |= execute( nodeSerialisation, parent, continueOnError );

	return result;
}
Ejemplo n.º 2
0
void Box::exportForReference( const std::string &fileName ) const
{
	const ScriptNode *script = scriptNode();
	if( !script )
	{
		throw IECore::Exception( "Box::exportForReference called without ScriptNode" );
	}

	// we only want to save out our child nodes and plugs that are visible in the UI, so we build a filter
	// to specify just the things to export.

	boost::regex invisiblePlug( "^__.*$" );
	StandardSetPtr toExport = new StandardSet;
	for( ChildIterator it = children().begin(), eIt = children().end(); it != eIt; ++it )
	{
		if( (*it)->isInstanceOf( Node::staticTypeId() ) )
		{
			toExport->add( *it );
		}
		else if( const Plug *plug = IECore::runTimeCast<Plug>( it->get() ) )
		{
			if( !boost::regex_match( plug->getName().c_str(), invisiblePlug ) )
			{
				toExport->add( *it );
			}
		}
	}

	ContextPtr context = new Context;
	context->set( "valuePlugSerialiser:resetParentPlugDefaults", true );
	context->set( "serialiser:includeParentMetadata", true );
	context->set( "serialiser:includeVersionMetadata", true );
	Context::Scope scopedContext( context.get() );

	script->serialiseToFile( fileName, this, toExport.get() );
}
Ejemplo n.º 3
0
void ScriptNode::paste( Node *parent )
{
	ApplicationRoot *app = applicationRoot();
	if( !app )
	{
		throw( "ScriptNode has no ApplicationRoot" );
	}

	IECore::ConstStringDataPtr s = IECore::runTimeCast<const IECore::StringData>( app->getClipboardContents() );
	if( s )
	{
		parent = parent ? parent : this;
		// set up something to catch all the newly created nodes
		StandardSetPtr newNodes = new StandardSet;
		parent->childAddedSignal().connect( boost::bind( (bool (StandardSet::*)( IECore::RunTimeTypedPtr ) )&StandardSet::add, newNodes.get(), ::_2 ) );

			// do the paste
			execute( s->readable(), parent );

		// transfer the newly created nodes into the selection
		selection()->clear();
		for( size_t i = 0, e = newNodes->size(); i < e; i++ )
		{
			StandardSet::Member *member = newNodes->member( i );
			if( member->isInstanceOf( Node::staticTypeId() ) )
			{
				selection()->add( member );
			}
		}
	}
}