| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "lc_coordinates_parser.h" |
| |
|
| | #include <QString> |
| |
|
| | #include "lc_convert.h" |
| | #include "lc_graphicviewport.h" |
| | #include "rs_graphicview.h" |
| | #include "rs_math.h" |
| |
|
| | LC_CoordinatesParser::LC_CoordinatesParser(RS_GraphicView* gview):m_graphicView{gview} {} |
| |
|
| | RS_CoordinateEvent LC_CoordinatesParser::parseCoordinate(const QString& inputStr, bool &stringContainsCoordinate) { |
| | RS_CoordinateEvent invalid(RS_Vector(false)); |
| |
|
| | stringContainsCoordinate = true; |
| |
|
| | |
| | if (inputStr.length() == 1) { |
| | switch (inputStr[0].toLatin1()) { |
| | case '0': { |
| | RS_Vector ucs0 = RS_Vector(0, 0, 0); |
| | RS_Vector wcs0 = toWCS(ucs0); |
| | return RS_CoordinateEvent(wcs0, true, false); |
| | } |
| | case '.': |
| | case ',': { |
| | RS_Vector wcs0 = m_graphicView->getViewPort()->getRelativeZero(); |
| | return RS_CoordinateEvent(wcs0, false, true); |
| | } |
| | default: |
| | stringContainsCoordinate = false; |
| | return invalid; |
| | } |
| | } |
| |
|
| | bool wcsCoordinates = inputStr.at(0) == '!'; |
| | if (wcsCoordinates) { |
| | |
| | QString candidate = inputStr.mid(1); |
| | bool isCartesian = inputStr.contains(','); |
| | if (isCartesian) { |
| | qsizetype separatorPos = candidate.indexOf(','); |
| | bool ok1{false}, ok2{false}; |
| | double x = RS_Math::eval(LC_Convert::updateForFraction(candidate.left(separatorPos)), &ok1); |
| | double y = RS_Math::eval(LC_Convert::updateForFraction(candidate.mid(separatorPos + 1)), &ok2); |
| | if (ok1 && ok2) { |
| | const RS_Vector& wcsCoordinate = RS_Vector(x, y); |
| | return RS_CoordinateEvent(wcsCoordinate); |
| | } |
| | return invalid; |
| | } |
| | bool isPolar = candidate.contains('<'); |
| | if (isPolar) { |
| | |
| | qsizetype separatorPos = candidate.indexOf('<'); |
| | bool ok1{false}, ok2{false}; |
| | double distance = RS_Math::eval(LC_Convert::updateForFraction(candidate.left(separatorPos)), &ok1); |
| | const QString& angleStr = candidate.mid(separatorPos + 1); |
| | double angleDegrees = LC_Convert::evalAngleValue(angleStr, ok2); |
| | if (ok1 && ok2) { |
| | double wcsAngle = RS_Math::deg2rad(angleDegrees); |
| | RS_Vector wcsCoordinate = RS_Vector(distance, wcsAngle); |
| | return RS_CoordinateEvent(wcsCoordinate); |
| | } |
| | return invalid; |
| | } |
| | return invalid; |
| | } |
| | bool absoluteCoordinates = inputStr.at(0) != '@'; |
| | bool isCartesian = inputStr.contains(','); |
| | if (isCartesian) { |
| | qsizetype separatorPos = inputStr.indexOf(','); |
| | if (absoluteCoordinates) { |
| | |
| | bool ok1{false}, ok2{false}; |
| | double x = RS_Math::eval(LC_Convert::updateForFraction(inputStr.left(separatorPos)), &ok1); |
| | double y = RS_Math::eval(LC_Convert::updateForFraction(inputStr.mid(separatorPos + 1)), &ok2); |
| | if (ok1 && ok2) { |
| | const RS_Vector& ucsCoordinate = RS_Vector(x, y); |
| | RS_Vector wcsCoordinate = toWCS(ucsCoordinate); |
| | return RS_CoordinateEvent(wcsCoordinate); |
| | } |
| | return invalid; |
| | } |
| | |
| | bool ok1{false}, ok2{false}; |
| | double x = RS_Math::eval(LC_Convert::updateForFraction(inputStr.mid(1, separatorPos - 1)), &ok1); |
| | double y = RS_Math::eval(LC_Convert::updateForFraction(inputStr.mid(separatorPos + 1)), &ok2); |
| |
|
| | if (ok1 && ok2) { |
| | const RS_Vector& ucsOffset = RS_Vector(x, y); |
| | const RS_Vector ucsRelZero = toUCS(m_graphicView->getViewPort()->getRelativeZero()); |
| | const RS_Vector ucsCoordinate = ucsOffset + ucsRelZero; |
| | const RS_Vector& wcsCoordinate = toWCS(ucsCoordinate); |
| | return RS_CoordinateEvent(wcsCoordinate); |
| | } |
| | return invalid; |
| | } |
| | |
| | bool isPolar = inputStr.contains('<'); |
| | if (isPolar) { |
| | qsizetype separatorPos = inputStr.indexOf('<'); |
| | if (absoluteCoordinates) { |
| | |
| | bool ok1{false}, ok2{false}; |
| | double ucsDistance = RS_Math::eval(LC_Convert::updateForFraction(inputStr.left(separatorPos)), &ok1); |
| | const QString& angleStr = inputStr.mid(separatorPos + 1); |
| | double ucsBasisAngleDegrees = LC_Convert::evalAngleValue(angleStr, ok2); |
| |
|
| | if (ok1 && ok2) { |
| | double ucsBasisAngleRad = RS_Math::deg2rad(ucsBasisAngleDegrees); |
| | double ucsAngle = toAbsUCSAngle(ucsBasisAngleRad); |
| | RS_Vector ucsCoordinate{RS_Vector::polar(ucsDistance, ucsAngle)}; |
| | RS_Vector wcsCoordinate = toWCS(ucsCoordinate); |
| | return RS_CoordinateEvent(wcsCoordinate); |
| | } |
| | return invalid; |
| | } |
| | |
| | qsizetype commaPos = inputStr.indexOf('<'); |
| | bool ok1{false}, ok2{false}; |
| | double ucsDistance = RS_Math::eval(LC_Convert::updateForFraction(inputStr.mid(1, commaPos - 1)), &ok1); |
| | const QString& angleStr = inputStr.mid(commaPos + 1); |
| | double ucsBasisAngleDegrees = LC_Convert::evalAngleValue(angleStr, ok2); |
| |
|
| | if (ok1 && ok2) { |
| | double ucsBasisAngleRad = RS_Math::deg2rad(ucsBasisAngleDegrees); |
| | double ucsAngle = toAbsUCSAngle(ucsBasisAngleRad); |
| | RS_Vector ucsOffset = RS_Vector::polar(ucsDistance, ucsAngle); |
| | const RS_Vector ucsRelZero = toUCS(m_graphicView->getViewPort()->getRelativeZero()); |
| | const RS_Vector ucsCoordinate = ucsOffset + ucsRelZero; |
| | const RS_Vector& wcsCoordinate = toWCS(ucsCoordinate); |
| | return RS_CoordinateEvent(wcsCoordinate); |
| | } |
| | return invalid; |
| | } |
| | stringContainsCoordinate = false; |
| | return invalid; |
| | } |
| |
|
| | RS_Vector LC_CoordinatesParser::toWCS(const RS_Vector &ucs) { |
| | return m_graphicView->getViewPort()->toWorld(ucs); |
| | } |
| |
|
| | RS_Vector LC_CoordinatesParser::toUCS(const RS_Vector &wcs) { |
| | return m_graphicView->getViewPort()->toUCS(wcs); |
| | } |
| |
|
| | double LC_CoordinatesParser::toAbsUCSAngle(double ucsBasisAngle) { |
| | return m_graphicView->getViewPort()->toAbsUCSAngle(ucsBasisAngle); |
| | } |
| |
|
| | double LC_CoordinatesParser::toWCSAngle(double ucsAngle) { |
| | return m_graphicView->getViewPort()->toWorldAngle(ucsAngle); |
| | } |
| |
|