Exemplo n.º 1
0
void Square::processInteraction( ::scene2D::data::Event::sptr _event )
{
    SLM_TRACE_FUNC();
    if ( _event->getType() == ::scene2D::data::Event::MouseButtonPress && _event->getButton() == ::scene2D::data::Event::LeftButton )
    {
        if ( this->coordViewIsInItem( _event->getCoord(), m_rec ) )
        {
            SLM_TRACE("Point is captured");
            m_pointIsCaptured = true;
            m_oldCoord = this->coordViewToCoordItem( _event->getCoord(), m_rec );
            m_rec->setBrush( Qt::yellow );
            _event->setAccepted(true);
        }
    }
    else if ( m_pointIsCaptured && _event->getType() == ::scene2D::data::Event::MouseMove )
    {
        ::scene2D::data::Coord newCoord = this->coordViewToCoordItem( _event->getCoord(), m_rec );
        m_rec->moveBy( newCoord.getX() - m_oldCoord.getX(), newCoord.getY() - m_oldCoord.getY() );
        m_oldCoord = newCoord;
        _event->setAccepted(true);
    }
    else if ( m_pointIsCaptured && _event->getType() == ::scene2D::data::Event::MouseButtonRelease )
    {
        m_rec->setBrush( m_color );
        m_pointIsCaptured = false;
        _event->setAccepted(true);
    }

}
Exemplo n.º 2
0
void CurvedHistogram::updateCurrentPoint( ::scene2D::data::Event::sptr _event )
{
    SLM_TRACE_FUNC();

    SLM_ASSERT("m_histogramPointUID must be defined in order to update the related ::fwData::Point data.",
            !m_histogramPointUID.empty());

    ::fwData::Histogram::sptr histogram = this->getObject< ::fwData::Histogram>();
    ::fwData::Histogram::fwHistogramValues values = histogram->getValues();
    const float histogramMinValue = histogram->getMinValue();
    const float histogramBinsWidth = histogram->getBinsWidth();

    // Event coordinates in scene
    ::scene2D::data::Coord sceneCoord = this->getScene2DRender()->mapToScene( _event->getCoord() );

    const int histIndex = (int) sceneCoord.getX();
    const int index = histIndex - histogramMinValue;
    const int nbValues = (int)values.size() * histogramBinsWidth;

    if(index >= 0 && index < nbValues && m_positionsToPathLength.find( histIndex ) != m_positionsToPathLength.end())
    {
        double key = m_positionsToPathLength[ histIndex ];
        const double percent = m_painterPath->percentAtLength( key );
        QPointF qPoint = m_painterPath->pointAtPercent( percent );

        ::fwData::Point::sptr point =
            ::fwData::Point::dynamicCast( ::fwTools::fwID::getObject( m_histogramPointUID ) );

        SLM_ASSERT("m_histogramPointUID can't be null here.", point);

        point->getRefCoord()[0] = sceneCoord.getX();
        point->getRefCoord()[1] = qPoint.y() * m_scale;
    }
}
Exemplo n.º 3
0
void Histogram::updateCurrentPoint( ::scene2D::data::Event::sptr _event )
{
    SLM_TRACE_FUNC();
    
    SLM_ASSERT("m_histogramPointUID must be defined in order to update the related ::fwData::Point data.",
            !m_histogramPointUID.empty());
    
    ::fwData::Histogram::sptr histogram = this->getObject< ::fwData::Histogram>();
    ::fwData::Histogram::fwHistogramValues values = histogram->getValues();
    const float histogramMinValue = histogram->getMinValue();
    const float histogramBinsWidth = histogram->getBinsWidth();

    // Event coordinates in scene
    ::scene2D::data::Coord sceneCoord = this->getScene2DRender()->mapToScene( _event->getCoord() );

    const int histIndex = (int) sceneCoord.getX();
    const int index = histIndex - histogramMinValue;
    const int nbValues = (int)values.size() * histogramBinsWidth;

    if(index >= 0 && index < nbValues)
    {
        ::fwData::Point::sptr point =
            ::fwData::Point::dynamicCast( ::fwTools::fwID::getObject( m_histogramPointUID ) );

        SLM_ASSERT("m_histogramPointUID can't be null here.", point);

        point->getRefCoord()[0] = sceneCoord.getX();
        point->getRefCoord()[1] = values.at( index / histogramBinsWidth ) * m_scale;
    }
}
Exemplo n.º 4
0
void HistogramCursor::processInteraction( ::scene2D::data::Event::sptr _event )
{
    SLM_TRACE_FUNC();

    this->initializeViewSize();
    this->initializeViewportSize();

    if( _event->getType() == ::scene2D::data::Event::MouseMove )
    {
       m_coord = _event->getCoord();
    }

    doUpdate();
}