Пример #1
0
void
ProjectSerialization::initialize(const Project* project)
{
    ///All the code in this function is MT-safe

    _nodes.initialize(*project);

    project->getAdditionalFormats(&_additionalFormats);

    std::vector< KnobIPtr > knobs = project->getKnobs_mt_safe();
    for (U32 i = 0; i < knobs.size(); ++i) {
        KnobGroupPtr isGroup = toKnobGroup(knobs[i]);
        KnobPagePtr isPage = toKnobPage(knobs[i]);
        KnobButtonPtr isButton = toKnobButton(knobs[i]);
        if ( knobs[i]->getIsPersistant() &&
             !isGroup && !isPage && !isButton &&
             knobs[i]->hasModificationsForSerialization() ) {
            KnobSerializationPtr newKnobSer( new KnobSerialization(knobs[i]) );
            _projectKnobs.push_back(newKnobSer);
        }
    }

    _timelineCurrent = project->currentFrame();

    _creationDate = project->getProjectCreationTime();
}
Пример #2
0
void
ProjectSerialization::initialize(const Natron::Project* project)
{
    ///All the code in this function is MT-safe

    std::vector<boost::shared_ptr<Natron::Node> > activeNodes;
    std::vector<boost::shared_ptr<Natron::Node> > nodes = project->getCurrentNodes();

    for (U32 i = 0; i < nodes.size(); ++i) {
        if ( nodes[i]->isActivated() ) {
            activeNodes.push_back(nodes[i]);
        }
    }

    _serializedNodes.clear();
    for (U32 i = 0; i < activeNodes.size(); ++i) {
        NodeSerialization state(activeNodes[i]);
        _serializedNodes.push_back(state);
    }
    project->getAdditionalFormats(&_additionalFormats);

    const std::vector< boost::shared_ptr<KnobI> > & knobs = project->getKnobs();
    for (U32 i = 0; i < knobs.size(); ++i) {
        Group_Knob* isGroup = dynamic_cast<Group_Knob*>( knobs[i].get() );
        Page_Knob* isPage = dynamic_cast<Page_Knob*>( knobs[i].get() );
        Button_Knob* isButton = dynamic_cast<Button_Knob*>( knobs[i].get() );
        if (knobs[i]->getIsPersistant() && !isGroup && !isPage && !isButton) {
            boost::shared_ptr<KnobSerialization> newKnobSer( new KnobSerialization(knobs[i],false) );
            _projectKnobs.push_back(newKnobSer);
        }
    }

    project->getNodeCounters(&_nodeCounters);

    _timelineLeft = project->leftBound();
    _timelineRight = project->rightBound();
    _timelineCurrent = project->currentFrame();

    _creationDate = project->getProjectCreationTime();
}
Пример #3
0
NodeSerialization::NodeSerialization(const boost::shared_ptr<Natron::Node>& n)
: _isNull(true)
, _hasRotoContext(false)
, _node()
, _app(NULL)
{
    
    if (n) {
        _node = n;
        _app = _node->getApp();
        
        ///All this code is MT-safe
        
        _knobsValues.clear();
        _inputs.clear();
        
        if (n->isOpenFXNode()) {
            dynamic_cast<OfxEffectInstance*>(n->getLiveInstance())->syncPrivateData_other_thread();
        }
        
        const std::vector< boost::shared_ptr<KnobI> >& knobs = n->getKnobs();
        
        for (U32 i  = 0; i < knobs.size(); ++i) {
            Group_Knob* isGroup = dynamic_cast<Group_Knob*>(knobs[i].get());
            Page_Knob* isPage = dynamic_cast<Page_Knob*>(knobs[i].get());
            Button_Knob* isButton = dynamic_cast<Button_Knob*>(knobs[i].get());
            if(knobs[i]->getIsPersistant() && !isGroup && !isPage && !isButton) {
                boost::shared_ptr<KnobSerialization> newKnobSer(new KnobSerialization(knobs[i]));
                _knobsValues.push_back(newKnobSer);
            }
        }
        _nbKnobs = (int)_knobsValues.size();
        
        _knobsAge = n->getKnobsAge();
        
        _pluginLabel = n->getName_mt_safe();
        
        _pluginID = n->pluginID();
        
        _pluginMajorVersion = n->majorVersion();
        
        _pluginMinorVersion = n->minorVersion();
        
        _inputs = n->getInputNames();
        
        boost::shared_ptr<Natron::Node> masterNode = n->getMasterNode();
        if (masterNode) {
            _masterNodeName = masterNode->getName_mt_safe();
        }
        
        boost::shared_ptr<RotoContext> roto = n->getRotoContext();
        if (roto) {
            _hasRotoContext = true;
            roto->save(&_rotoContext);
        } else {
            _hasRotoContext = false;
        }
        
        _multiInstanceParentName = n->getParentMultiInstanceName();
        
        _isNull = false;
    }
}
Пример #4
0
NodeSerialization::NodeSerialization(const NodePtr & n,
                                     bool serializeInputs)
    : _isNull(true)
      , _nbKnobs(0)
      , _knobsValues()
      , _knobsAge(0)
      , _nodeLabel()
      , _nodeScriptName()
      , _pluginID()
      , _pluginMajorVersion(-1)
      , _pluginMinorVersion(-1)
      , _hasRotoContext(false)
      , _hasTrackerContext(false)
      , _node()
      , _pythonModuleVersion(0)
{
    if (n) {
        _node = n;

        ///All this code is MT-safe

        _knobsValues.clear();
        _inputs.clear();

        if ( n->isOpenFXNode() ) {
            OfxEffectInstance* effect = dynamic_cast<OfxEffectInstance*>( n->getEffectInstance().get() );
            assert(effect);
            if (effect) {
                effect->syncPrivateData_other_thread();
            }
        }

        std::vector< KnobPtr >  knobs = n->getEffectInstance()->getKnobs_mt_safe();
        std::list<KnobPtr > userPages;
        for (U32 i  = 0; i < knobs.size(); ++i) {
            KnobGroup* isGroup = dynamic_cast<KnobGroup*>( knobs[i].get() );
            KnobPage* isPage = dynamic_cast<KnobPage*>( knobs[i].get() );

            if (isPage) {
                _pagesIndexes.push_back( knobs[i]->getName() );
                if ( knobs[i]->isUserKnob() ) {
                    userPages.push_back(knobs[i]);
                }
            }

            if ( !knobs[i]->isUserKnob() &&
                 knobs[i]->getIsPersistant() &&
                 !isGroup && !isPage
                 && knobs[i]->hasModificationsForSerialization() ) {
                ///For choice do a deepclone because we need entries
                //bool doCopyKnobs = isChoice ? true : copyKnobs;

                boost::shared_ptr<KnobSerialization> newKnobSer( new KnobSerialization(knobs[i]) );
                _knobsValues.push_back(newKnobSer);
            }
        }

        _nbKnobs = (int)_knobsValues.size();

        for (std::list<KnobPtr >::const_iterator it = userPages.begin(); it != userPages.end(); ++it) {
            boost::shared_ptr<GroupKnobSerialization> s( new GroupKnobSerialization(*it) );
            _userPages.push_back(s);
        }

        _knobsAge = n->getKnobsAge();

        _nodeLabel = n->getLabel_mt_safe();

        _nodeScriptName = n->getScriptName_mt_safe();

        _cacheID = n->getCacheID();

        _pluginID = n->getPluginID();

        if ( !n->hasPyPlugBeenEdited() ) {
            _pythonModule = n->getPluginPythonModule();
            _pythonModuleVersion = n->getMajorVersion();
        }

        _pluginMajorVersion = n->getMajorVersion();

        _pluginMinorVersion = n->getMinorVersion();

        if (serializeInputs) {
            n->getInputNames(_inputs);
        }

        NodePtr masterNode = n->getMasterNode();
        if (masterNode) {
            _masterNodeName = masterNode->getFullyQualifiedName();
        }

        boost::shared_ptr<RotoContext> roto = n->getRotoContext();
        if ( roto && !roto->isEmpty() ) {
            _hasRotoContext = true;
            roto->save(&_rotoContext);
        } else {
            _hasRotoContext = false;
        }

        boost::shared_ptr<TrackerContext> tracker = n->getTrackerContext();
        if (tracker) {
            _hasTrackerContext = true;
            tracker->save(&_trackerContext);
        } else {
            _hasTrackerContext = false;
        }


        NodeGroup* isGrp = n->isEffectGroup();
        if (isGrp) {
            NodesList nodes;
            isGrp->getActiveNodes(&nodes);

            _children.clear();

            for (NodesList::iterator it = nodes.begin(); it != nodes.end(); ++it) {
                if ( (*it)->isPartOfProject() ) {
                    boost::shared_ptr<NodeSerialization> state( new NodeSerialization(*it) );
                    _children.push_back(state);
                }
            }
        }

        _multiInstanceParentName = n->getParentMultiInstanceName();

        NodesList childrenMultiInstance;
        _node->getChildrenMultiInstance(&childrenMultiInstance);
        if ( !childrenMultiInstance.empty() ) {
            assert(!isGrp);
            for (NodesList::iterator it = childrenMultiInstance.begin(); it != childrenMultiInstance.end(); ++it) {
                assert( (*it)->getParentMultiInstance() );
                if ( (*it)->isActivated() ) {
                    boost::shared_ptr<NodeSerialization> state( new NodeSerialization(*it) );
                    _children.push_back(state);
                }
            }
        }

        n->getUserCreatedComponents(&_userComponents);

        _isNull = false;
    }
}