Esempio n. 1
0
void NegatoOneSlice::doUpdate(::fwServices::ObjectMsg::csptr msg) throw(::fwTools::Failed)
{
    SLM_TRACE_FUNC();

    if ( msg->hasEvent( ::fwComEd::ImageMsg::CHANGE_SLICE_TYPE ))
    {
        ::fwData::Object::csptr cObjInfo = msg->getDataInfo( ::fwComEd::ImageMsg::CHANGE_SLICE_TYPE );
        ::fwData::Object::sptr objInfo = ::boost::const_pointer_cast< ::fwData::Object > ( cObjInfo );
        ::fwData::Composite::sptr info = ::fwData::Composite::dynamicCast ( objInfo );

        int fromSliceType = ::fwData::Integer::dynamicCast( info->getContainer()["fromSliceType"] )->value();
        int toSliceType =   ::fwData::Integer::dynamicCast( info->getContainer()["toSliceType"] )->value();

        if( toSliceType == static_cast<int>(m_orientation) )
        {
            setOrientation( static_cast< Orientation >( fromSliceType ));
        }
        else if(fromSliceType == static_cast<int>(m_orientation))
        {
            setOrientation( static_cast< Orientation >( toSliceType ));
        }
    }
    else
    {
        this->doStop();
        this->doStart();
        this->doUpdate();
    }
}
Esempio n. 2
0
/**
 * @brief Called by a data to notify a service.
 *
 * @param _pMsg : Incoming message
 */
void SofaCoreSrv::updating( fwServices::ObjectMsg::csptr msg ) throw ( ::fwTools::Failed )
{
    if (msg->hasEvent("NEW_SOFA_SCENE")) {

        // Delete object sofa
        delete sofa;

        // Get Path Scn
        ::fwData::String::csptr pathScn = ::fwData::String::dynamicConstCast(msg->getDataInfo("NEW_SOFA_SCENE"));

        // Get acquisition
        ::fwData::Acquisition::sptr acq = this->getObject< ::fwData::Acquisition >();

        // Create object sofa
        sofa = new SofaBusiness();
        sofa->loadScn(pathScn->value(), acq, this->getSptr());

        // Apply at sofa the number of image by second
        sofa->setTimeStepAnimation(1000/50);

        if (sofa) {
            // if animation is running
            if (sofa->isAnimate()) {
                // Stop animation
                sofa->stopThread();
            } else {
                // Start animation
                sofa->startThread();
            }
        } else {
            QMessageBox::warning(0, "Warning", "To launch animation you must first load scene file !");
        }

    }

    else if (msg->hasEvent("START_STOP_SOFA")) {
        if (sofa) {
            // if animation is running
            if (sofa->isAnimate()) {
                // Stop animation
                sofa->stopThread();
            } else {
                // Start animation
                sofa->startThread();
            }
        } else {
            QMessageBox::warning(0, "Warning", "To launch animation you must first load scene file !");
        }
    }

    else if (msg->hasEvent("EDITOR_MESH_SOFA")) {
        if (sofa) {
            ::fwData::Vector::csptr data = ::fwData::Vector::dynamicConstCast(msg->getDataInfo("EDITOR_MESH_SOFA"));
            ::fwData::String::csptr idMesh = ::fwData::String::dynamicConstCast(data->at(0));
            ::fwData::Integer::csptr strength = ::fwData::Integer::dynamicConstCast(data->at(1));
            sofa->shakeMesh(idMesh->value(), strength->value());
        }
    }

    else if (msg->hasEvent("MOVE_MESH_SOFA")) {
        if (sofa) {
            ::fwData::Vector::csptr data = ::fwData::Vector::dynamicConstCast(msg->getDataInfo("MOVE_MESH_SOFA"));
            ::fwData::String::csptr idMesh = ::fwData::String::dynamicConstCast(data->at(0));
            ::fwData::Integer::csptr x = ::fwData::Integer::dynamicConstCast(data->at(1));
            ::fwData::Integer::csptr y = ::fwData::Integer::dynamicConstCast(data->at(2));
            ::fwData::Integer::csptr z = ::fwData::Integer::dynamicConstCast(data->at(3));
            ::fwData::Float::csptr rx = ::fwData::Float::dynamicConstCast(data->at(4));
            ::fwData::Float::csptr ry = ::fwData::Float::dynamicConstCast(data->at(5));
            ::fwData::Float::csptr rz = ::fwData::Float::dynamicConstCast(data->at(6));
            sofa->moveMesh(idMesh->value(), x->value(), y->value(), z->value(), rx->value(), ry->value(), rz->value());
        }
    }

    else if (msg->hasEvent("KINECT_NEW_POSITION_HAND")) {
        if (sofa) {
            // Get the position x y z of the main and his id
            ::fwData::Vector::csptr data = ::fwData::Vector::dynamicConstCast(msg->getDataInfo("KINECT_NEW_POSITION_HAND"));
            ::fwData::Integer::csptr x = ::fwData::Integer::dynamicConstCast(data->at(0));
            ::fwData::Integer::csptr y = ::fwData::Integer::dynamicConstCast(data->at(1));
            ::fwData::Integer::csptr z = ::fwData::Integer::dynamicConstCast(data->at(2));
            ::fwData::Integer::csptr id = ::fwData::Integer::dynamicConstCast(data->at(3));

            static int idTool1 = 0;
            static int idTool2 = 0;
            static int stage = 0;

            // Allow to switch tool
            if (id->value() == idTool1) {
                // move tool 1
                sofa->moveMesh("souris_mors2", x->value()/2 + 190, y->value()/2 + 152, z->value()/2 - 200, 0, 0, 0);
            } else if (id->value() == idTool2) {
                // move tool 2
                sofa->moveMesh("souris_cam", x->value()/2 + 190, y->value()/2 + 152, z->value()/2 - 200, 0, 0, 0);
            } else {
                if (stage%2) {
                    idTool1 = id->value();
                } else {
                    idTool2 = id->value();
                }
                stage++;
            }
        }
    }
}
void DataInfoFromMsgUpdaterSrv::receiving( ::fwServices::ObjectMsg::csptr _msg ) throw ( ::fwTools::Failed )
{
    ::fwData::Composite::sptr composite = this->getObject< ::fwData::Composite >();
    for (   ManagedEvents::iterator it = m_managedEvents.begin();
            it != m_managedEvents.end();
            ++it )
    {
        std::string event         = it->get<0>();
        std::string uuid          = it->get<1>();
        std::string compositeKey  = it->get<2>();
        ctrlSelection::IUpdaterSrv::ActionType action        = it->get<3>();

        //  test if message correspond to a defined event
        if( _msg->hasEvent( event ) )
        {
            ::fwData::Object::sptr obj = ::fwData::Object::dynamicCast( _msg->getSubject().lock() );
            SLM_ASSERT("Sorry, the subject of message is not a ::fwData::Object", obj);

            // Test if we manage this event from this object message uid
            if( obj->getID() == uuid || uuid == "*")
            {
                ::fwData::Object::sptr dataInfo = ::boost::const_pointer_cast< ::fwData::Object >(_msg->getDataInfo(  event ));
                SLM_ASSERT("no dataInfo set!!!" ,  dataInfo
                        ||  action== ctrlSelection::IUpdaterSrv::REMOVE
                        ||  action== ctrlSelection::IUpdaterSrv::REMOVE_IF_PRESENT
                );
                // Udpate the composite object referenced by the composite key
                this->updateComposite(composite, dataInfo , compositeKey , action );
            }
        }
    }
}