Пример #1
0
void EnhancedPathHandle::saveOdf(KoShapeSavingContext &context) const
{
    if (!hasPosition()) {
        return;
    }
    context.xmlWriter().startElement("draw:handle");
    context.xmlWriter().addAttribute("draw:handle-position", m_positionX->toString() + ' ' + m_positionY->toString());
    if (isPolar()) {
        context.xmlWriter().addAttribute("draw:handle-polar", m_polarX->toString() + ' ' + m_polarY->toString());
        if (m_minRadius) {
            context.xmlWriter().addAttribute("draw:handle-radius-range-minimum", m_minRadius->toString());
        }
        if (m_maxRadius) {
            context.xmlWriter().addAttribute("draw:handle-radius-range-maximum", m_maxRadius->toString());
        }
    } else {
        if (m_minimumX) {
            context.xmlWriter().addAttribute("draw:handle-range-x-minimum", m_minimumX->toString());
        }
        if (m_maximumX) {
            context.xmlWriter().addAttribute("draw:handle-range-x-maximum", m_maximumX->toString());
        }
        if (m_minimumY) {
            context.xmlWriter().addAttribute("draw:handle-range-y-minimum", m_minimumY->toString());
        }
        if (m_maximumY) {
            context.xmlWriter().addAttribute("draw:handle-range-y-maximum", m_maximumY->toString());
        }
    }
    context.xmlWriter().endElement(); // draw:handle
}
Пример #2
0
int MouseRelatedEvent::offsetY()
{
    if (!hasPosition())
        return 0;
    if (!m_hasCachedRelativePosition)
        computeRelativePosition();
    return roundToInt(m_offsetLocation.y());
}
Пример #3
0
JointState::MODE JointState::getMode() const
{
    if (isPosition())    return POSITION;
    else if (isSpeed())  return SPEED;
    else if (isEffort()) return EFFORT;
    else if (isRaw())    return RAW;
    else if (isAcceleration())    return ACCELERATION;
    else if (hasPosition() || hasSpeed() || hasEffort() || hasRaw() || hasAcceleration())
        throw std::runtime_error("getMode() called on a JointState that has more than one field set");
    else
        return UNSET;
}
GlobalReference& GlobalReference::setCurrentHeading(const State& state, double new_heading) {
  // get current yaw angle
  double current_yaw = state.getYaw();
  State::ConstPositionType position = state.getPosition();

  // get current position in WGS84
  double current_latitude, current_longitude;
  if (hasPosition()) {
    toWGS84(position.x(), position.y(), current_latitude, current_longitude);
  }

  // set the new reference heading
  setHeading(new_heading - (-current_yaw));

  // set the new reference position so that current position in WGS84 coordinates remains the same as before
  if (hasPosition()) {
    setCurrentPosition(state, current_latitude, current_longitude);
  }

  return *this;
}
Пример #5
0
void EnhancedPathHandle::changePosition(const QPointF &position)
{
    if (!hasPosition()) {
        return;
    }

    QPointF constrainedPosition(position);

    if (isPolar()) {
        // convert cartesian coordinates into polar coordinates
        QPointF polarCenter(m_polarX->evaluate(), m_polarY->evaluate());
        QPointF diff = constrainedPosition - polarCenter;
        // compute the polar radius
        qreal radius = sqrt(diff.x() * diff.x() + diff.y() * diff.y());
        // compute the polar angle
        qreal angle = atan2(diff.y(), diff.x());
        if (angle < 0.0) {
            angle += 2 * M_PI;
        }

        // constrain the radius
        if (m_minRadius) {
            radius = qMax(m_minRadius->evaluate(), radius);
        }
        if (m_maxRadius) {
            radius = qMin(m_maxRadius->evaluate(), radius);
        }

        constrainedPosition.setX(angle * 180.0 / M_PI);
        constrainedPosition.setY(radius);
    } else {
        // constrain x coordinate
        if (m_minimumX) {
            constrainedPosition.setX(qMax(m_minimumX->evaluate(), constrainedPosition.x()));
        }
        if (m_maximumX) {
            constrainedPosition.setX(qMin(m_maximumX->evaluate(), constrainedPosition.x()));
        }

        // constrain y coordinate
        if (m_minimumY) {
            constrainedPosition.setY(qMax(m_minimumY->evaluate(), constrainedPosition.y()));
        }
        if (m_maximumY) {
            constrainedPosition.setY(qMin(m_maximumY->evaluate(), constrainedPosition.y()));
        }
    }

    m_positionX->modify(constrainedPosition.x());
    m_positionY->modify(constrainedPosition.y());
}
Пример #6
0
QPointF EnhancedPathHandle::position()
{
    if (!hasPosition())
        return QPointF();

    QPointF position(m_positionX->evaluate(), m_positionY->evaluate());
    if (isPolar()) {
        // convert polar coordinates into cartesian coordinates
        QPointF center(m_polarX->evaluate(), m_polarY->evaluate());
        qreal angleInRadian = position.x() * M_PI / 180.0;
        position = center + position.y() * QPointF(cos(angleInRadian), sin(angleInRadian));
    }

    return position;
}
Пример #7
0
bool EnhancedPathHandle::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context)
{
    if (element.localName() != "handle" || element.namespaceURI() != KoXmlNS::draw) {
        return false;
    }

    QString position = element.attributeNS(KoXmlNS::draw, "handle-position");
#ifndef NWORKAROUND_ODF_BUGS
    KoOdfWorkaround::fixEnhancedPathPolarHandlePosition(position, element, context);
#endif
    QStringList tokens = position.simplified().split(' ');
    if (tokens.count() != 2) {
        return false;
    }

    setPosition(m_parent->parameter(tokens[0]), m_parent->parameter(tokens[1]));

    // check if we have a polar handle
    if (element.hasAttributeNS(KoXmlNS::draw, "handle-polar")) {
        QString polar = element.attributeNS(KoXmlNS::draw, "handle-polar");
        QStringList tokens = polar.simplified().split(' ');
        if (tokens.count() == 2) {
            setPolarCenter(m_parent->parameter(tokens[0]), m_parent->parameter(tokens[1]));

            QString minRadius = element.attributeNS(KoXmlNS::draw, "handle-radius-range-minimum");
            QString maxRadius = element.attributeNS(KoXmlNS::draw, "handle-radius-range-maximum");
            if (!minRadius.isEmpty() && !maxRadius.isEmpty()) {
                setRadiusRange(m_parent->parameter(minRadius), m_parent->parameter(maxRadius));
            }
        }
    } else {
        QString minX = element.attributeNS(KoXmlNS::draw, "handle-range-x-minimum");
        QString maxX = element.attributeNS(KoXmlNS::draw, "handle-range-x-maximum");
        if (!minX.isEmpty() && ! maxX.isEmpty()) {
            setRangeX(m_parent->parameter(minX), m_parent->parameter(maxX));
        }

        QString minY = element.attributeNS(KoXmlNS::draw, "handle-range-y-minimum");
        QString maxY = element.attributeNS(KoXmlNS::draw, "handle-range-y-maximum");
        if (!minY.isEmpty() && ! maxY.isEmpty()) {
            setRangeY(m_parent->parameter(minY), m_parent->parameter(maxY));
        }
    }

    return hasPosition();
}
Пример #8
0
void DPSketch::addPositionChannel()
{
    if(hasPosition())
    {
        return;
    }

    DPFloatChannel xChan;
    xChan.setName("x");
    xChan.setUnits("0.1mm");
    xChan.setMin(-3000);
    xChan.setMax(3000);
    _definitions.getTraceFormatsRef().addChannel(xChan);

    DPFloatChannel yChan;
    yChan.setName("y");
    yChan.setUnits("0.1mm");
    yChan.setMin(0);
    yChan.setMax(6000);
    _definitions.getTraceFormatsRef().addChannel(yChan);

}
Пример #9
0
MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubble, bool cancelable,
    PassRefPtrWillBeRawPtr<AbstractView> abstractView, int detail, const IntPoint& screenLocation,
    const IntPoint& rootFrameLocation, const IntPoint& movementDelta, PlatformEvent::Modifiers modifiers,
    double platformTimeStamp, PositionType positionType, InputDeviceCapabilities* sourceCapabilities)
    : UIEventWithKeyState(eventType, canBubble, cancelable, abstractView, detail, modifiers, platformTimeStamp, sourceCapabilities)
    , m_screenLocation(screenLocation)
    , m_movementDelta(movementDelta)
    , m_positionType(positionType)
{
    LayoutPoint adjustedPageLocation;
    LayoutPoint scrollPosition;

    LocalFrame* frame = view() && view()->isLocalDOMWindow() ? toLocalDOMWindow(view())->frame() : nullptr;
    if (frame && hasPosition()) {
        if (FrameView* frameView = frame->view()) {
            scrollPosition = frameView->scrollPosition();
            adjustedPageLocation = frameView->rootFrameToContents(rootFrameLocation);
            float scaleFactor = 1 / frame->pageZoomFactor();
            if (scaleFactor != 1.0f) {
                adjustedPageLocation.scale(scaleFactor, scaleFactor);
                scrollPosition.scale(scaleFactor, scaleFactor);
            }
        }
    }

    m_clientLocation = adjustedPageLocation - toLayoutSize(scrollPosition);
    m_pageLocation = adjustedPageLocation;

    // Set up initial values for coordinates.
    // Correct values are computed lazily, see computeRelativePosition.
    m_layerLocation = m_pageLocation;
    m_offsetLocation = m_pageLocation;

    computePageLocation();
    m_hasCachedRelativePosition = false;
}
Пример #10
0
bool JointState::isAcceleration() const
{
    return !hasPosition() && !hasSpeed() && !hasEffort() && !hasRaw() && hasAcceleration();
}