Beispiel #1
0
    /// Create a link to an object.
    void SetUp()
    {
        m_dst = sofa::core::objectmodel::New<BaseObject>() ;
        m_src = sofa::core::objectmodel::New<BaseObject>() ;

        m_dst->setName("destination") ;
        m_src->setName("source") ;
        m_src->addLink(&m_link);
        m_link.add(m_dst.get());
    }
Beispiel #2
0
void BaseObject::addSlave(BaseObject::SPtr s)
{
    BaseObject::SPtr previous = s->getMaster();
    if (previous == this) return;
    if (previous)
        previous->l_slaves.remove(s);
    l_slaves.add(s);
    if (previous)
        this->getContext()->notifyMoveSlave(previous.get(), this, s.get());
    else
        this->getContext()->notifyAddSlave(this, s.get());
}
Beispiel #3
0
/// Move an object from another node
void Node::moveObject(BaseObject::SPtr obj)
{
    Node* prev = dynamic_cast<Node*>(obj->getContext());
    if (prev==NULL)
    {
        obj->getContext()->removeObject(obj);
        addObject(obj);
    }
    else
    {
        notifyMoveObject(obj,prev);
        prev->doRemoveObject(obj);
        doAddObject(obj);
    }
}
Beispiel #4
0
void BaseObject::removeSlave(BaseObject::SPtr s)
{
    if (l_slaves.remove(s))
    {
        this->getContext()->notifyRemoveSlave(this, s.get());
    }
}
Beispiel #5
0
/// Add an object. Detect the implemented interfaces and add the object to the corresponding lists.
void Node::doAddObject(BaseObject::SPtr sobj)
{
    notifyAddObject(sobj);
    //sobj->setContext(this);
    this->setObjectContext(sobj);
    object.add(sobj);
    BaseObject* obj = sobj.get();
    int inserted=0;
    inserted+= animationManager.add(dynamic_cast< core::behavior::BaseAnimationLoop* >(obj));
    inserted+= solver.add(dynamic_cast< core::behavior::OdeSolver* >(obj));
    inserted+= linearSolver.add(dynamic_cast< core::behavior::BaseLinearSolver* >(obj));
    inserted+= constraintSolver.add(dynamic_cast< core::behavior::ConstraintSolver* >(obj));
    inserted+= visualLoop.add(dynamic_cast< core::visual::VisualLoop* >(obj));
    inserted+= state.add(dynamic_cast< core::BaseState* >(obj));
    inserted+= mechanicalState.add(dynamic_cast< core::behavior::BaseMechanicalState* >(obj));
    core::BaseMapping* bmap = dynamic_cast< core::BaseMapping* >(obj);
    bool isMechanicalMapping = false;
    if(bmap)
    {
        isMechanicalMapping = bmap->isMechanical();
        if(isMechanicalMapping)
            inserted += mechanicalMapping.add(bmap);
        else
            inserted += mapping.add(bmap);
    }

    inserted+= mass.add(dynamic_cast< core::behavior::BaseMass* >(obj));
    inserted+= topology.add(dynamic_cast< core::topology::Topology* >(obj));
    inserted+= meshTopology.add(dynamic_cast< core::topology::BaseMeshTopology* >(obj));
    inserted+= topologyObject.add(dynamic_cast< core::topology::BaseTopologyObject* >(obj));
    inserted+= shaders.add(dynamic_cast< sofa::core::visual::Shader* >(obj));

    bool isInteractionForceField = interactionForceField.add(dynamic_cast< core::behavior::BaseInteractionForceField* >(obj));
    inserted+= isInteractionForceField;
    if (!isInteractionForceField)
        forceField.add(dynamic_cast< core::behavior::BaseForceField* >(obj));
    inserted+= projectiveConstraintSet.add(dynamic_cast< core::behavior::BaseProjectiveConstraintSet* >(obj));
    inserted+= constraintSet.add(dynamic_cast< core::behavior::BaseConstraintSet* >(obj));
    inserted+= behaviorModel.add(dynamic_cast< core::BehaviorModel* >(obj));
    inserted+= visualModel.add(dynamic_cast< core::visual::VisualModel* >(obj));
    inserted+= visualManager.add(dynamic_cast< core::visual::VisualManager* >(obj));
    inserted+= collisionModel.add(dynamic_cast< core::CollisionModel* >(obj));
    inserted+= contextObject.add(dynamic_cast< core::objectmodel::ContextObject* >(obj));
    inserted+= configurationSetting.add(dynamic_cast< core::objectmodel::ConfigurationSetting* >(obj));
    inserted+= collisionPipeline.add(dynamic_cast< core::collision::Pipeline* >(obj));
    inserted+= actionScheduler.add(dynamic_cast< VisitorScheduler* >(obj));

    if ( inserted==0 )
    {
        //cerr<<"Node::doAddObject, object "<<obj->getName()<<" is unsorted"<<endl;
        unsorted.add(obj);
    }

}
Beispiel #6
0
/// Remove an object
void Node::doRemoveObject(BaseObject::SPtr sobj)
{
    //if (sobj->getContext()==this)
    //{
    //    sobj->setContext(NULL);
    //}
    this->clearObjectContext(sobj);
    object.remove(sobj);
    BaseObject* obj = sobj.get();
    animationManager.remove(dynamic_cast< core::behavior::BaseAnimationLoop* >(obj));
    solver.remove(dynamic_cast< core::behavior::OdeSolver* >(obj));
    linearSolver.remove(dynamic_cast< core::behavior::BaseLinearSolver* >(obj));
    constraintSolver.remove(dynamic_cast< core::behavior::ConstraintSolver* >(obj));
    visualLoop.remove(dynamic_cast< core::visual::VisualLoop* >(obj));
    state.remove(dynamic_cast< core::BaseState* >(obj));
    mechanicalState.remove(dynamic_cast< core::behavior::BaseMechanicalState* >(obj));
    mechanicalMapping.remove(dynamic_cast< core::BaseMapping* >(obj));
    mass.remove(dynamic_cast< core::behavior::BaseMass* >(obj));
    topology.remove(dynamic_cast< core::topology::Topology* >(obj));
    meshTopology.remove(dynamic_cast< core::topology::BaseMeshTopology* >(obj));
    topologyObject.remove(dynamic_cast< core::topology::BaseTopologyObject* >(obj));
    shaders.remove(dynamic_cast<sofa::core::visual::Shader* >(obj));

    forceField.remove(dynamic_cast< core::behavior::BaseForceField* >(obj));
    interactionForceField.remove(dynamic_cast< core::behavior::BaseInteractionForceField* >(obj));
    projectiveConstraintSet.remove(dynamic_cast< core::behavior::BaseProjectiveConstraintSet* >(obj));
    constraintSet.remove(dynamic_cast< core::behavior::BaseConstraintSet* >(obj));
    mapping.remove(dynamic_cast< core::BaseMapping* >(obj));
    behaviorModel.remove(dynamic_cast< core::BehaviorModel* >(obj));
    visualModel.remove(dynamic_cast< core::visual::VisualModel* >(obj));
    visualManager.remove(dynamic_cast< core::visual::VisualManager* >(obj));
    collisionModel.remove(dynamic_cast< core::CollisionModel* >(obj));
    contextObject.remove(dynamic_cast<core::objectmodel::ContextObject* >(obj));
    configurationSetting.remove(dynamic_cast<core::objectmodel::ConfigurationSetting* >(obj));
    collisionPipeline.remove(dynamic_cast< core::collision::Pipeline* >(obj));

    actionScheduler.remove(dynamic_cast< VisitorScheduler* >(obj));

    unsorted.remove(obj);
}