From 7964180905adf14968455ec0c10be3fb57f93294 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Sep 2014 17:33:01 -0700 Subject: [PATCH] handle place creation at new API endpoint --- interface/src/avatar/MyAvatar.h | 2 +- interface/src/location/LocationManager.cpp | 147 +----------------- interface/src/location/LocationManager.h | 14 -- interface/src/location/NamedLocation.cpp | 28 ++-- interface/src/location/NamedLocation.h | 32 ++-- interface/src/ui/ChatWindow.cpp | 3 +- interface/src/ui/OAuthWebViewHandler.cpp | 2 + interface/src/ui/ScriptEditorWidget.cpp | 2 + .../src/ui/overlays/BillboardOverlay.cpp | 4 +- 9 files changed, 43 insertions(+), 191 deletions(-) diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 86c10fdbb4..01dd392465 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -155,7 +155,7 @@ public slots: void decreaseSize(); void resetSize(); - void goToLocation(const glm::vec3& newPosition, bool hasOrientation, const glm::vec3& newOrientation); + void goToLocation(const glm::vec3& newPosition, bool hasOrientation = false, const glm::vec3& newOrientation = glm::vec3()); // Set/Get update the thrust that will move the avatar around void addThrust(glm::vec3 newThrust) { _thrust += newThrust; }; diff --git a/interface/src/location/LocationManager.cpp b/interface/src/location/LocationManager.cpp index 6beb1f5527..1228791c98 100644 --- a/interface/src/location/LocationManager.cpp +++ b/interface/src/location/LocationManager.cpp @@ -9,14 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include +#include -#include "Application.h" #include "LocationManager.h" -#include - -const QString POST_PLACE_CREATE = "/api/v1/places/"; +const QString POST_LOCATION_CREATE = "/api/v1/locations/"; LocationManager& LocationManager::getInstance() { static LocationManager sharedInstance; @@ -44,145 +41,7 @@ void LocationManager::createNamedLocation(NamedLocation* namedLocation) { callbackParams.errorCallbackReceiver = this; callbackParams.errorCallbackMethod = "errorDataReceived"; - accountManager.authenticatedRequest(POST_PLACE_CREATE, QNetworkAccessManager::PostOperation, + accountManager.authenticatedRequest(POST_LOCATION_CREATE, QNetworkAccessManager::PostOperation, callbackParams, namedLocation->toJsonString().toUtf8()); } } - -void LocationManager::goToUrl(const QUrl& url) { -// if (location.startsWith(CUSTOM_URL_SCHEME + "/")) { -// QStringList urlParts = location.remove(0, CUSTOM_URL_SCHEME.length()).split('/', QString::SkipEmptyParts); -// -// if (urlParts.count() > 1) { -// // if url has 2 or more parts, the first one is domain name -// QString domain = urlParts[0]; -// -// // second part is either a destination coordinate or -// // a place name -// QString destination = urlParts[1]; -// -// // any third part is an avatar orientation. -// QString orientation = urlParts.count() > 2 ? urlParts[2] : QString(); -// -// goToDomain(domain); -// -// // goto either @user, #place, or x-xx,y-yy,z-zz -// // style co-ordinate. -// goTo(destination); -// -// if (!orientation.isEmpty()) { -// // location orientation -// goToOrientation(orientation); -// } -// } else if (urlParts.count() == 1) { -// QString destination = urlParts[0]; -// -// // If this starts with # or @, treat it as a user/location, otherwise treat it as a domain -// if (destination[0] == '#' || destination[0] == '@') { -// goTo(destination); -// } else { -// goToDomain(destination); -// } -// } -// return true; -// } -// return false; -} - -void LocationManager::goToOrientation(QString orientation) { - if (orientation.isEmpty()) { - return; - } - - QStringList orientationItems = orientation.remove(' ').split(QRegExp("_|,"), QString::SkipEmptyParts); - - const int NUMBER_OF_ORIENTATION_ITEMS = 4; - const int W_ITEM = 0; - const int X_ITEM = 1; - const int Y_ITEM = 2; - const int Z_ITEM = 3; - - if (orientationItems.size() == NUMBER_OF_ORIENTATION_ITEMS) { - - // replace last occurrence of '_' with decimal point - replaceLastOccurrence('-', '.', orientationItems[W_ITEM]); - replaceLastOccurrence('-', '.', orientationItems[X_ITEM]); - replaceLastOccurrence('-', '.', orientationItems[Y_ITEM]); - replaceLastOccurrence('-', '.', orientationItems[Z_ITEM]); - - double w = orientationItems[W_ITEM].toDouble(); - double x = orientationItems[X_ITEM].toDouble(); - double y = orientationItems[Y_ITEM].toDouble(); - double z = orientationItems[Z_ITEM].toDouble(); - - glm::quat newAvatarOrientation(w, x, y, z); - - MyAvatar* myAvatar = Application::getInstance()->getAvatar(); - glm::quat avatarOrientation = myAvatar->getOrientation(); - if (newAvatarOrientation != avatarOrientation) { - myAvatar->setOrientation(newAvatarOrientation); - emit myAvatar->transformChanged(); - } - } -} - -bool LocationManager::goToDestination(QString destination) { - - QStringList coordinateItems = destination.remove(' ').split(QRegExp("_|,"), QString::SkipEmptyParts); - - const int NUMBER_OF_COORDINATE_ITEMS = 3; - const int X_ITEM = 0; - const int Y_ITEM = 1; - const int Z_ITEM = 2; - if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) { - - // replace last occurrence of '_' with decimal point - replaceLastOccurrence('-', '.', coordinateItems[X_ITEM]); - replaceLastOccurrence('-', '.', coordinateItems[Y_ITEM]); - replaceLastOccurrence('-', '.', coordinateItems[Z_ITEM]); - - double x = coordinateItems[X_ITEM].toDouble(); - double y = coordinateItems[Y_ITEM].toDouble(); - double z = coordinateItems[Z_ITEM].toDouble(); - - glm::vec3 newAvatarPos(x, y, z); - - MyAvatar* myAvatar = Application::getInstance()->getAvatar(); - glm::vec3 avatarPos = myAvatar->getPosition(); - if (newAvatarPos != avatarPos) { - // send a node kill request, indicating to other clients that they should play the "disappeared" effect - MyAvatar::sendKillAvatar(); - - qDebug("Going To Location: %f, %f, %f...", x, y, z); - myAvatar->slamPosition(newAvatarPos); - emit myAvatar->transformChanged(); - } - - return true; - } - - // no coordinates were parsed - return false; -} - -void LocationManager::handleAddressLookupError(QNetworkReply::NetworkError networkError, - const QString& errorString) { - QString messageBoxString; - - if (networkError == QNetworkReply::ContentNotFoundError) { - messageBoxString = "That address could not be found."; - } else { - messageBoxString = errorString; - } - - QMessageBox::warning(Application::getInstance()->getWindow(), "", messageBoxString); -} - -void LocationManager::replaceLastOccurrence(const QChar search, const QChar replace, QString& string) { - int lastIndex; - lastIndex = string.lastIndexOf(search); - if (lastIndex > 0) { - lastIndex = string.lastIndexOf(search); - string.replace(lastIndex, 1, replace); - } -} diff --git a/interface/src/location/LocationManager.h b/interface/src/location/LocationManager.h index ec580dfc7a..926d5d752b 100644 --- a/interface/src/location/LocationManager.h +++ b/interface/src/location/LocationManager.h @@ -14,7 +14,6 @@ #include -#include "AccountManager.h" #include "NamedLocation.h" class LocationManager : public QObject { @@ -30,19 +29,6 @@ public: }; void createNamedLocation(NamedLocation* namedLocation); - - void goTo(QString destination); - void goToUser(QString userName); - void goToPlace(QString placeName); - void goToUrl(const QUrl& url); - void goToOrientation(QString orientation); - bool goToDestination(QString destination); - -public slots: - void handleAddressLookupError(QNetworkReply::NetworkError networkError, const QString& errorString); - -private: - void replaceLastOccurrence(const QChar search, const QChar replace, QString& string); signals: void creationCompleted(LocationManager::NamedLocationCreateResponse response); diff --git a/interface/src/location/NamedLocation.cpp b/interface/src/location/NamedLocation.cpp index ed7701a391..997c36efba 100644 --- a/interface/src/location/NamedLocation.cpp +++ b/interface/src/location/NamedLocation.cpp @@ -9,19 +9,25 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include +#include + #include "NamedLocation.h" -const QString JSON_FORMAT = "{\"address\":{\"position\":\"%1,%2,%3\"," - "\"orientation\":\"%4,%5,%6,%7\",\"domain\":\"%8\"},\"name\":\"%9\"}"; +NamedLocation::NamedLocation(const QString& name, + const glm::vec3& position, const glm::quat& orientation, + const QUuid& domainID) : + _name(name), + _position(position), + _orientation(orientation), + _domainID(domainID) +{ + +} + +const QString JSON_FORMAT = "{\"location\":{\"path\":\"%1\",\"domain_id\":\"%2\"},\"name\":\"%3\"}"; QString NamedLocation::toJsonString() { - return JSON_FORMAT.arg(QString::number(_location.x), - QString::number(_location.y), - QString::number(_location.z), - QString::number(_orientation.w), - QString::number(_orientation.x), - QString::number(_orientation.y), - QString::number(_orientation.z), - _domain, - _locationName); + return JSON_FORMAT.arg(AddressManager::pathForPositionAndOrientation(_position, true, _orientation), + uuidStringWithoutCurlyBraces(_domainID), _name); } diff --git a/interface/src/location/NamedLocation.h b/interface/src/location/NamedLocation.h index ffbd157263..fca6852062 100644 --- a/interface/src/location/NamedLocation.h +++ b/interface/src/location/NamedLocation.h @@ -22,39 +22,33 @@ class NamedLocation : public QObject { Q_OBJECT public: - NamedLocation(QString locationName, glm::vec3 location, glm::quat orientation, QString domain) { - _locationName = locationName; - _location = location; - _orientation = orientation; - _domain = domain; - } + NamedLocation(const QString& name, const glm::vec3& position, const glm::quat& orientation, const QUuid& domainID); QString toJsonString(); - bool isEmpty() { return _locationName.isNull() || _locationName.isEmpty(); } + bool isEmpty() { return _name.isNull() || _name.isEmpty(); } - void setLocationName(QString locationName) { _locationName = locationName; } - QString locationName() { return _locationName; } + void setName(QString name) { _name = name; } + const QString& getName() const { return _name; } - void setLocation(glm::vec3 location) { _location = location; } - glm::vec3 location() { return _location; } + void setLocation(glm::vec3 position) { _position = position; } + const glm::vec3& getPosition() const { return _position; } - void setOrientation(glm::quat orentation) { _orientation = orentation; } - glm::quat orientation() { return _orientation; } + void setOrientation(const glm::quat& orentation) { _orientation = orentation; } + const glm::quat& getOrientation() const { return _orientation; } - void setDomain(QString domain) { _domain = domain; } - QString domain() { return _domain; } + void setDomainID(const QUuid& domainID) { _domainID = domainID; } + const QUuid& getDomainID() const { return _domainID; } signals: void dataReceived(bool locationExists); private: - - QString _locationName; + QString _name; QString _createdBy; - glm::vec3 _location; + glm::vec3 _position; glm::quat _orientation; - QString _domain; + QUuid _domainID; }; diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 9961a84e79..cf62b75215 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -17,6 +17,8 @@ #include #include +#include + #include "Application.h" #include "ChatMessageArea.h" #include "FlowLayout.h" @@ -28,7 +30,6 @@ #include "ChatWindow.h" - const int NUM_MESSAGES_TO_TIME_STAMP = 20; const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?)|(?:hifi))://\\S+)"); diff --git a/interface/src/ui/OAuthWebViewHandler.cpp b/interface/src/ui/OAuthWebViewHandler.cpp index 8ec415584d..a1dbfe9e0b 100644 --- a/interface/src/ui/OAuthWebViewHandler.cpp +++ b/interface/src/ui/OAuthWebViewHandler.cpp @@ -11,6 +11,8 @@ #include +#include + #include "Application.h" #include "OAuthWebViewHandler.h" diff --git a/interface/src/ui/ScriptEditorWidget.cpp b/interface/src/ui/ScriptEditorWidget.cpp index f99c9d5ac4..1473e4a6a0 100644 --- a/interface/src/ui/ScriptEditorWidget.cpp +++ b/interface/src/ui/ScriptEditorWidget.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include "Application.h" #include "ScriptHighlighting.h" diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index 7d85d54fef..f29fa6ed8d 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -9,7 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "../../Application.h" +#include + +#include "Application.h" #include "BillboardOverlay.h"