예제 #1
0
void CurvedHistogram::processInteraction( ::scene2D::data::Event::sptr _event)
{
    SLM_TRACE_FUNC();

    bool updatePointedPos = false;

    // Vertical scaling
    if( _event->getType() == ::scene2D::data::Event::MouseWheelUp )
    {
        m_scale *= SCALE;
        m_layer->setTransform(QTransform::fromScale(1, SCALE), true);

        updatePointedPos = true;
    }
    else if( _event->getType() == ::scene2D::data::Event::MouseWheelDown )
    {
        m_scale /= SCALE;
        m_layer->setTransform(QTransform::fromScale(1, 1 / SCALE), true);

        updatePointedPos = true;
    }
    else if( _event->getType() == ::scene2D::data::Event::MouseMove )
    {
        updatePointedPos = true;
    }

    if( !m_histogramPointUID.empty() )
    {
        updateCurrentPoint( _event );
    }
}
bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )
{
  QgsCadUtils::AlignMapPointContext context;
  context.snappingUtils = mMapCanvas->snappingUtils();
  context.mapUnitsPerPixel = mMapCanvas->mapUnitsPerPixel();
  context.xConstraint = _constraint( mXConstraint.get() );
  context.yConstraint = _constraint( mYConstraint.get() );
  context.distanceConstraint = _constraint( mDistanceConstraint.get() );
  context.angleConstraint = _constraint( mAngleConstraint.get() );
  context.cadPointList = mCadPointList;

  context.commonAngleConstraint.locked = true;
  context.commonAngleConstraint.relative = context.angleConstraint.relative;
  context.commonAngleConstraint.value = mCommonAngleConstraint;

  QgsCadUtils::AlignMapPointOutput output = QgsCadUtils::alignMapPoint( e->originalMapPoint(), context );

  bool res = output.valid;
  QgsPointXY point = output.finalMapPoint;
  mSnappedSegment.clear();
  if ( output.edgeMatch.hasEdge() )
  {
    QgsPointXY edgePt0, edgePt1;
    output.edgeMatch.edgePoints( edgePt0, edgePt1 );
    mSnappedSegment << edgePt0 << edgePt1;
  }
  if ( mAngleConstraint->lockMode() != CadConstraint::HardLock )
  {
    if ( output.softLockCommonAngle != -1 )
    {
      mAngleConstraint->setLockMode( CadConstraint::SoftLock );
      mAngleConstraint->setValue( output.softLockCommonAngle );
    }
    else
    {
      mAngleConstraint->setLockMode( CadConstraint::NoLock );
    }
  }

  // set the point coordinates in the map event
  e->setMapPoint( point );

  // update the point list
  updateCurrentPoint( point );

  updateUnlockedConstraintValues( point );

  if ( res )
  {
    emit popWarning();
  }
  else
  {
    emit pushWarning( tr( "Some constraints are incompatible. Resulting point might be incorrect." ) );
  }

  return res;
}
예제 #3
0
파일: vplStroke.cpp 프로젝트: msahlen/vpl
    void Stroker::handleLineSegment(Segment* segment)
    {
        const Path::Segment* pathSegment = segment->getSegment();

        // Where are we going to?
        updateCurrentPoint(pathSegment);

        // Calculate stroke normal
        calculateStrokeNormal(prevPoint_,currentPoint_,normal_);

        Vector outer;
        Vector inner;

        // Join segments or begin the first segment
        if(numSegments_ == 0)
        {
            firstPoint_  = prevPoint_;
            firstNormal_ = normal_;

            outer = firstPoint_ + firstNormal_;
            inner = firstPoint_ - firstNormal_;

            addPoint(&outerPoints_,outer);
            addPoint(&innerPoints_,inner);
        }
        else
            joiner_(this,prevPoint_,prevNormal_,normal_);

        outer = currentPoint_ + normal_;
        inner = currentPoint_ - normal_;

        // Add point
        addPoint(&outerPoints_,outer);
        addPoint(&innerPoints_,inner);

        // Update state
        prevPoint_  = currentPoint_;
        prevNormal_ = normal_;
    }
예제 #4
0
void Histogram::processInteraction( ::scene2D::data::Event::sptr _event)
{
    SLM_TRACE_FUNC();

    bool updatePointedPos = false;

    // Vertical scaling
    if( _event->getType() == ::scene2D::data::Event::MouseWheelUp )
    {
        m_scale *= SCALE;
        m_layer->scale(1, SCALE);

        //_event->setAccepted( true );
        m_yAxis->setScale( m_scale );

        updatePointedPos = true;
    }
    else if( _event->getType() == ::scene2D::data::Event::MouseWheelDown )
    {
        m_scale /= SCALE;
        m_layer->scale(1, 1 / SCALE);

        //_event->setAccepted( true );
        m_yAxis->setScale( m_scale );
        
        updatePointedPos = true;
    }
    else if( _event->getType() == ::scene2D::data::Event::MouseMove )
    {
        updatePointedPos = true;
    }
    
    if( !m_histogramPointUID.empty() && updatePointedPos )
    {
        updateCurrentPoint( _event );
    }
}
예제 #5
0
bool SVGPathBlender::BlendState::blendSegments(
    const PathSegmentData& fromSeg,
    const PathSegmentData& toSeg,
    PathSegmentData& blendedSegment) {
  if (!canBlend(fromSeg, toSeg))
    return false;

  blendedSegment.command =
      m_isInFirstHalfOfAnimation ? fromSeg.command : toSeg.command;

  switch (toSeg.command) {
    case PathSegCurveToCubicRel:
    case PathSegCurveToCubicAbs:
      blendedSegment.point1 =
          blendAnimatedFloatPoint(fromSeg.point1, toSeg.point1);
    /* fall through */
    case PathSegCurveToCubicSmoothRel:
    case PathSegCurveToCubicSmoothAbs:
      blendedSegment.point2 =
          blendAnimatedFloatPoint(fromSeg.point2, toSeg.point2);
    /* fall through */
    case PathSegMoveToRel:
    case PathSegMoveToAbs:
    case PathSegLineToRel:
    case PathSegLineToAbs:
    case PathSegCurveToQuadraticSmoothRel:
    case PathSegCurveToQuadraticSmoothAbs:
      blendedSegment.targetPoint =
          blendAnimatedFloatPoint(fromSeg.targetPoint, toSeg.targetPoint);
      break;
    case PathSegLineToHorizontalRel:
    case PathSegLineToHorizontalAbs:
      blendedSegment.targetPoint.setX(blendAnimatedDimensonalFloat(
          fromSeg.targetPoint.x(), toSeg.targetPoint.x(), BlendHorizontal));
      break;
    case PathSegLineToVerticalRel:
    case PathSegLineToVerticalAbs:
      blendedSegment.targetPoint.setY(blendAnimatedDimensonalFloat(
          fromSeg.targetPoint.y(), toSeg.targetPoint.y(), BlendVertical));
      break;
    case PathSegClosePath:
      break;
    case PathSegCurveToQuadraticRel:
    case PathSegCurveToQuadraticAbs:
      blendedSegment.targetPoint =
          blendAnimatedFloatPoint(fromSeg.targetPoint, toSeg.targetPoint);
      blendedSegment.point1 =
          blendAnimatedFloatPoint(fromSeg.point1, toSeg.point1);
      break;
    case PathSegArcRel:
    case PathSegArcAbs:
      blendedSegment.targetPoint =
          blendAnimatedFloatPoint(fromSeg.targetPoint, toSeg.targetPoint);
      blendedSegment.point1 = blendAnimatedFloatPointSameCoordinates(
          fromSeg.arcRadii(), toSeg.arcRadii());
      blendedSegment.point2 =
          blendAnimatedFloatPointSameCoordinates(fromSeg.point2, toSeg.point2);
      if (m_addTypesCount) {
        blendedSegment.arcLarge = fromSeg.arcLarge || toSeg.arcLarge;
        blendedSegment.arcSweep = fromSeg.arcSweep || toSeg.arcSweep;
      } else {
        blendedSegment.arcLarge =
            m_isInFirstHalfOfAnimation ? fromSeg.arcLarge : toSeg.arcLarge;
        blendedSegment.arcSweep =
            m_isInFirstHalfOfAnimation ? fromSeg.arcSweep : toSeg.arcSweep;
      }
      break;
    default:
      ASSERT_NOT_REACHED();
  }

  updateCurrentPoint(m_fromSubPathPoint, m_fromCurrentPoint, fromSeg);
  updateCurrentPoint(m_toSubPathPoint, m_toCurrentPoint, toSeg);

  return true;
}
예제 #6
0
파일: vplStroke.cpp 프로젝트: msahlen/vpl
    void Stroker::generateStrokeOutlines(SubPath* subPath,
                                         const AffineMatrix& transform)
    {
        if(subPath->getNumberOfPoints() == 0)
            return;

        // Iterate over all segments in subpath
        Segment* segment = subPath->beginSegmentIteration();

        const Path::Segment* pathSegment = segment->getSegment();

        // Clear state varibles and helper paths for this subpath
        numSegments_ = 0;

        innerPoints_.clear();
        outerPoints_.clear();

        // Store transform
        pathTransform_ = transform;
        inversePathTransform_ = transform;
        inversePathTransform_.invert();

        float xScale;
        float yScale;

        pathTransform_.getScale(xScale,yScale);

        scale_.makeIdentity();
        scale_.scale(xScale,yScale);

        inverseScale_ = scale_;
        inverseScale_.invert();

        // Handle the case where we start with
        // a move to separetely for now
        if(pathSegment->command_ == Path::cMoveToAbs ||
            pathSegment->command_ == Path::cMoveToRel)
        {
            updateCurrentPoint(pathSegment);

            firstPoint_ = prevPoint_ = currentPoint_;

            segment = subPath->getNextSegment();
            pathSegment = segment->getSegment();
        }

        // Iterate over sub path and handle all segments
        const Path::Segment* lastSegment = pathSegment;

        while(subPath->hasMoreSegments())
        {

            if(pathSegment->command_ < Path::cQuadBezierToAbs)
                handleLineSegment(segment);

            else if(pathSegment->command_ > Path::cSmoothCubicBezierToRel)
                handleArcSegment(segment);
            else
                handleBezierSegment(segment);

            ++numSegments_;

            segment = subPath->getNextSegment();
            lastSegment = pathSegment;
            pathSegment = segment->getSegment();
        }

        // Join or add ends
        if(lastSegment->command_ == Path::cClosePath)
            joiner_(this,firstPoint_,prevNormal_,firstNormal_);

        else
            endStroke();

    }
예제 #7
0
파일: vplStroke.cpp 프로젝트: msahlen/vpl
    void Stroker::handleBezierSegment(Segment* segment)
    {
         // Where are we going to?
         updateCurrentPoint(segment->getSegment());

        // Calculate first normal
        float* points = segment->beginPointIteration();

        calculateStrokeNormal(points,normal_);

        // Join segments or begin the first segment
        Vector outer;
        Vector inner;

        if(numSegments_ == 0)
        {
            firstPoint_  = prevPoint_;
            firstNormal_ = normal_;

            outer = firstPoint_ + firstNormal_;
            inner = firstPoint_ - firstNormal_;

            addPoint(&outerPoints_,outer);
            addPoint(&innerPoints_,inner);
        }
        else
            joiner_(this,prevPoint_,prevNormal_,normal_);


        // Add points,ignoring the first
        // since it is already added
        points = segment->getNextPoint();

        Vector point;

        if(segment->getNumberOfPoints() > 2)
        {
            while(!segment->atSecondToLastPoint())
            {
                point.x_ = *points;
                point.y_ = *(points + 1);

                calculateStrokeNormal(points,normal_);

                outer = point + normal_;
                inner = point - normal_;

                addPoint(&outerPoints_,outer);
                addPoint(&innerPoints_,inner);

                points = segment->getNextPoint();
            }
        }

        // Calculate last normal
        calculateStrokeNormal(point,currentPoint_,normal_);

        // Add last point
        outer = currentPoint_ + normal_;
        inner = currentPoint_ - normal_;

        addPoint(&outerPoints_,outer);
        addPoint(&innerPoints_,inner);

        prevPoint_  = currentPoint_;
        prevNormal_ = normal_;
    }
예제 #8
0
파일: vplStroke.cpp 프로젝트: msahlen/vpl
    void Stroker::handleArcSegment(Segment* segment)
    {
        // Where are we going to?
        updateCurrentPoint(segment->getSegment());

        // First point is already added
        float* points = segment->beginPointIteration();

        points = segment->getNextPoint();

        // First normal using segment end points
        Vector firstNormal = prevPoint_ - currentPoint_;
        firstNormal.normalize();
        firstNormal *= size_ /2;

        scale_.transform(firstNormal);

        // Calculate first and second normal from points
        Vector secondNormal;
        calculateStrokeNormal(points,normal_);
        calculateStrokeNormal(points + 2,secondNormal);

        // Adjust first normal so it points
        // in the same direction as the second normal
        Winding firstWinding  = determineWinding(firstNormal,normal_);
        Winding secondWinding = determineWinding(normal_,secondNormal);

        if(firstWinding != secondWinding)
            firstNormal.invert();

        // Join segments or begin the first segment
        Vector outer;
        Vector inner;

        if(numSegments_ == 0)
        {
            firstPoint_  = prevPoint_;
            firstNormal_ = firstNormal;

            outer = firstPoint_ + firstNormal_;
            inner = firstPoint_ - firstNormal_;

            addPoint(&outerPoints_,outer);
            addPoint(&innerPoints_,inner);
        }
        else
            joiner_(this,prevPoint_,prevNormal_,firstNormal);


        // Add points
        while(segment->hasMorePoints())
        {
            Vector point(*points,*(points + 1));

            calculateStrokeNormal(points,normal_);

            outer = point + normal_;
            inner = point - normal_;

            addPoint(&outerPoints_,outer);
            addPoint(&innerPoints_,inner);

            points = segment->getNextPoint();
        }

        // Add last
        normal_ = invert(firstNormal);

        outer = currentPoint_ + normal_;
        inner = currentPoint_ - normal_;

        addPoint(&outerPoints_,outer);
        addPoint(&innerPoints_,inner);

        prevPoint_  = currentPoint_;
        prevNormal_ = normal_;
    }