Showing the changes to interface/src/raypick/PointerScriptingInterface.cpp (1 of 46 files). Show all
Unified · Split
| @@ -10,26 +10,54 @@ · 9 unmodified lines | ||
| 10 | 10 | |
| 11 | 11 | #include <QtCore/QVariant> |
| 12 | 12 | #include <GLMHelpers.h> |
| 13 | +#include <shared/QtHelpers.h> | |
| 13 | 14 | |
| 14 | 15 | #include "Application.h" |
| 15 | 16 | #include "LaserPointer.h" |
| 17 | +#include "StylusPointer.h" | |
| 16 | 18 | |
| 17 | 19 | void PointerScriptingInterface::setIgnoreItems(unsigned int uid, const QScriptValue& ignoreItems) const { |
| 18 | 20 | DependencyManager::get<PointerManager>()->setIgnoreItems(uid, qVectorQUuidFromScriptValue(ignoreItems)); |
| 19 | 21 | } |
| 22 | + | |
| 20 | 23 | void PointerScriptingInterface::setIncludeItems(unsigned int uid, const QScriptValue& includeItems) const { |
| 21 | 24 | DependencyManager::get<PointerManager>()->setIncludeItems(uid, qVectorQUuidFromScriptValue(includeItems)); |
| 22 | 25 | } |
| 23 | 26 | |
| 24 | −unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& type, const QVariant& properties) const { | |
| 27 | +unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& type, const QVariant& properties) { | |
| 28 | + // Interaction with managers should always happen on the main thread | |
| 29 | + if (QThread::currentThread() != qApp->thread()) { | |
| 30 | + unsigned int result; | |
| 31 | + BLOCKING_INVOKE_METHOD(this, "createPointer", Q_RETURN_ARG(unsigned int, result), Q_ARG(PickQuery::PickType, type), Q_ARG(QVariant, properties)); | |
| 32 | + return result; | |
| 33 | + } | |
| 34 | + | |
| 25 | 35 | switch (type) { |
| 26 | 36 | case PickQuery::PickType::Ray: |
| 27 | 37 | return createLaserPointer(properties); |
| 38 | + case PickQuery::PickType::Stylus: | |
| 39 | + return createStylus(properties); | |
| 28 | 40 | default: |
| 29 | 41 | return PointerEvent::INVALID_POINTER_ID; |
| 30 | 42 | } |
| 31 | 43 | } |
| 32 | 44 | |
| 45 | +unsigned int PointerScriptingInterface::createStylus(const QVariant& properties) const { | |
| 46 | + bilateral::Side side = bilateral::Side::Invalid; | |
| 47 | + { | |
| 48 | + QVariant handVar = properties.toMap()["hand"]; | |
| 49 | + if (handVar.isValid()) { | |
| 50 | + side = bilateral::side(handVar.toInt()); | |
| 51 | + } | |
| 52 | + } | |
| 53 | + | |
| 54 | + if (bilateral::Side::Invalid == side) { | |
| 55 | + return PointerEvent::INVALID_POINTER_ID; | |
| 56 | + } | |
| 57 | + | |
| 58 | + return DependencyManager::get<PointerManager>()->addPointer(std::make_shared<StylusPointer>(side)); | |
| 59 | +} | |
| 60 | + | |
| 33 | 61 | unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& properties) const { |
| 34 | 62 | QVariantMap propertyMap = properties.toMap(); |
| 35 | 63 | |
| @@ -133,4 +161,13 @@ void PointerScriptingInterface::editRenderState(unsigned int uid, const QString& · 97 unmodified lines | ||
| 133 | 161 | } |
| 134 | 162 | |
| 135 | 163 | DependencyManager::get<PointerManager>()->editRenderState(uid, renderState.toStdString(), startProps, pathProps, endProps); |
| 164 | +} | |
| 165 | + | |
| 166 | +QVariantMap PointerScriptingInterface::getPrevPickResult(unsigned int uid) const { | |
| 167 | + QVariantMap result; | |
| 168 | + auto pickResult = DependencyManager::get<PointerManager>()->getPrevPickResult(uid); | |
| 169 | + if (pickResult) { | |
| 170 | + result = pickResult->toVariantMap(); | |
| 171 | + } | |
| 172 | + return result; | |
| 136 | 173 | } |