Showing the changes to interface/src/scripting/SelectionScriptingInterface.cpp (1 of 11 files). Show all
Unified · Split
| @@ -72,28 +72,29 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& lis · 71 unmodified lines | |||
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | bool SelectionScriptingInterface::clearSelectedItemsList(const QString& listName) { | 74 | bool SelectionScriptingInterface::clearSelectedItemsList(const QString& listName) { |
| 75 | // QWriteLocker lock(&_selectionListsLock); | 75 | { |
| 76 | _selectedItemsListMap.insert(listName, GameplayObjects()); | 76 | QWriteLocker lock(&_selectionListsLock); |
| 77 | _selectedItemsListMap.insert(listName, GameplayObjects()); | ||
| 78 | } | ||
| 77 | onSelectedItemsListChanged(listName); | 79 | onSelectedItemsListChanged(listName); |
| 78 | return true; | 80 | return true; |
| 79 | } | 81 | } |
| 80 | 82 | ||
| 81 | bool SelectionScriptingInterface::enableListHighlight(const QString& listName, const QVariantMap& highlightStyleValues) { | 83 | bool SelectionScriptingInterface::enableListHighlight(const QString& listName, const QVariantMap& highlightStyleValues) { |
| 82 | // QWriteLocker lock(&_selectionListsLock); | 84 | QWriteLocker lock(&_highlightStylesLock); |
| 83 | 85 | ||
| 84 | auto highlightStyle = _highlightedListMap.find(listName); | 86 | auto highlightStyle = _highlightStyleMap.find(listName); |
| 85 | if (highlightStyle == _highlightedListMap.end()) { | 87 | if (highlightStyle == _highlightStyleMap.end()) { |
| 86 | highlightStyle = _highlightedListMap.insert(listName, SelectionHighlightStyle()); | 88 | highlightStyle = _highlightStyleMap.insert(listName, SelectionHighlightStyle()); |
| 87 | 89 | ||
| 88 | } | 90 | } |
| 89 | 91 | ||
| 90 | if (!(*highlightStyle).isBoundToList()) { | 92 | if (!(*highlightStyle).isBoundToList()) { |
| 91 | auto currentList = _selectedItemsListMap.find(listName); | 93 | /* auto currentList = _selectedItemsListMap.find(listName); |
| 92 | if (currentList == _selectedItemsListMap.end()) { | 94 | if (currentList == _selectedItemsListMap.end()) { |
| 93 | _selectedItemsListMap.insert(listName, GameplayObjects()); | 95 | _selectedItemsListMap.insert(listName, GameplayObjects()); |
| 94 | } | 96 | }*/ |
| 95 | setupHandler(listName); | 97 | setupHandler(listName); |
| 96 | |||
| 97 | (*highlightStyle).setBoundToList(true); | 98 | (*highlightStyle).setBoundToList(true); |
| 98 | } | 99 | } |
| 99 | 100 | ||
| @@ -113,33 +114,32 @@ bool SelectionScriptingInterface::enableListHighlight(const QString& listName, c · 13 unmodified lines | |||
| 113 | } | 114 | } |
| 114 | 115 | ||
| 115 | bool SelectionScriptingInterface::disableListHighlight(const QString& listName) { | 116 | bool SelectionScriptingInterface::disableListHighlight(const QString& listName) { |
| 116 | // QWriteLocker lock(&_selectionListsLock); | 117 | QWriteLocker lock(&_highlightStylesLock); |
| 117 | auto highlightStyle = _highlightedListMap.find(listName); | 118 | auto highlightStyle = _highlightStyleMap.find(listName); |
| 118 | if (highlightStyle != _highlightedListMap.end()) { | 119 | if (highlightStyle != _highlightStyleMap.end()) { |
| 119 | // if ((*highlightStyle).isBoundToList()) { | 120 | if ((*highlightStyle).isBoundToList()) { |
| 120 | _highlightedListMap.erase(highlightStyle); | 121 | } |
| 121 | 122 | ||
| 122 | auto mainScene = qApp->getMain3DScene(); | 123 | _highlightStyleMap.erase(highlightStyle); |
| 123 | if (mainScene) { | ||
| 124 | render::Transaction transaction; | ||
| 125 | transaction.removeHighlightFromSelection(listName.toStdString()); | ||
| 126 | mainScene->enqueueTransaction(transaction); | ||
| 127 | } | ||
| 128 | else { | ||
| 129 | qWarning() << "SelectionToSceneHandler::highlightStyleChanged(), Unexpected null scene, possibly during application shutdown"; | ||
| 130 | } | ||
| 131 | // emit highlightStyleRemoved(listName); | ||
| 132 | 124 | ||
| 133 | // } | 125 | auto mainScene = qApp->getMain3DScene(); |
| 126 | if (mainScene) { | ||
| 127 | render::Transaction transaction; | ||
| 128 | transaction.removeHighlightFromSelection(listName.toStdString()); | ||
| 129 | mainScene->enqueueTransaction(transaction); | ||
| 130 | } | ||
| 131 | else { | ||
| 132 | qWarning() << "SelectionToSceneHandler::highlightStyleChanged(), Unexpected null scene, possibly during application shutdown"; | ||
| 133 | } | ||
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | return true; | 136 | return true; |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | QVariantMap SelectionScriptingInterface::getListHighlightStyle(const QString& listName) const { | 139 | QVariantMap SelectionScriptingInterface::getListHighlightStyle(const QString& listName) const { |
| 140 | // QReadLocker lock(&_selectionListsLock); | 140 | QReadLocker lock(&_highlightStylesLock); |
| 141 | auto highlightStyle = _highlightedListMap.find(listName); | 141 | auto highlightStyle = _highlightStyleMap.find(listName); |
| 142 | if (highlightStyle == _highlightedListMap.end()) { | 142 | if (highlightStyle == _highlightStyleMap.end()) { |
| 143 | return QVariantMap(); | 143 | return QVariantMap(); |
| 144 | } else { | 144 | } else { |
| 145 | return (*highlightStyle).toVariantMap(); | 145 | return (*highlightStyle).toVariantMap(); |
| @@ -147,9 +147,9 @@ QVariantMap SelectionScriptingInterface::getListHighlightStyle(const QString& li · 1 unmodified line | |||
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | render::HighlightStyle SelectionScriptingInterface::getHighlightStyle(const QString& listName) const { | 149 | render::HighlightStyle SelectionScriptingInterface::getHighlightStyle(const QString& listName) const { |
| 150 | // QReadLocker lock(&_selectionListsLock); | 150 | QReadLocker lock(&_highlightStylesLock); |
| 151 | auto highlightStyle = _highlightedListMap.find(listName); | 151 | auto highlightStyle = _highlightStyleMap.find(listName); |
| 152 | if (highlightStyle == _highlightedListMap.end()) { | 152 | if (highlightStyle == _highlightStyleMap.end()) { |
| 153 | return render::HighlightStyle(); | 153 | return render::HighlightStyle(); |
| 154 | } else { | 154 | } else { |
| 155 | return (*highlightStyle).getStyle(); | 155 | return (*highlightStyle).getStyle(); |
| @@ -157,25 +157,30 @@ render::HighlightStyle SelectionScriptingInterface::getHighlightStyle(const QStr · 1 unmodified line | |||
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | template <class T> bool SelectionScriptingInterface::addToGameplayObjects(const QString& listName, T idToAdd) { | 159 | template <class T> bool SelectionScriptingInterface::addToGameplayObjects(const QString& listName, T idToAdd) { |
| 160 | // QWriteLocker lock(&_selectionListsLock); | 160 | { |
| 161 | 161 | QWriteLocker lock(&_selectionListsLock); | |
| 162 | GameplayObjects currentList = _selectedItemsListMap.value(listName); | 162 | GameplayObjects currentList = _selectedItemsListMap.value(listName); |
| 163 | currentList.addToGameplayObjects(idToAdd); | 163 | currentList.addToGameplayObjects(idToAdd); |
| 164 | _selectedItemsListMap.insert(listName, currentList); | 164 | _selectedItemsListMap.insert(listName, currentList); |
| 165 | 165 | } | |
| 166 | onSelectedItemsListChanged(listName); | 166 | onSelectedItemsListChanged(listName); |
| 167 | return true; | 167 | return true; |
| 168 | } | 168 | } |
| 169 | template <class T> bool SelectionScriptingInterface::removeFromGameplayObjects(const QString& listName, T idToRemove) { | 169 | template <class T> bool SelectionScriptingInterface::removeFromGameplayObjects(const QString& listName, T idToRemove) { |
| 170 | // QWriteLocker lock(&_selectionListsLock); | 170 | bool listExist = false; |
| 171 | GameplayObjects currentList = _selectedItemsListMap.value(listName); | 171 | { |
| 172 | if (currentList.getContainsData()) { | 172 | QWriteLocker lock(&_selectionListsLock); |
| 173 | currentList.removeFromGameplayObjects(idToRemove); | 173 | auto currentList = _selectedItemsListMap.find(listName); |
| 174 | _selectedItemsListMap.insert(listName, currentList); | 174 | if (currentList != _selectedItemsListMap.end()) { |
| 175 | 175 | listExist = true; | |
| 176 | (*currentList).removeFromGameplayObjects(idToRemove); | ||
| 177 | } | ||
| 178 | } | ||
| 179 | if (listExist) { | ||
| 176 | onSelectedItemsListChanged(listName); | 180 | onSelectedItemsListChanged(listName); |
| 177 | return true; | 181 | return true; |
| 178 | } else { | 182 | } |
| 183 | else { | ||
| 179 | return false; | 184 | return false; |
| 180 | } | 185 | } |
| 181 | } | 186 | } |
| @@ -184,12 +189,12 @@ template <class T> bool SelectionScriptingInterface::removeFromGameplayObjects(c · 2 unmodified lines | |||
| 184 | // | 189 | // |
| 185 | 190 | ||
| 186 | GameplayObjects SelectionScriptingInterface::getList(const QString& listName) { | 191 | GameplayObjects SelectionScriptingInterface::getList(const QString& listName) { |
| 187 | // QReadLocker lock(&_selectionListsLock); | 192 | QReadLocker lock(&_selectionListsLock); |
| 188 | return _selectedItemsListMap.value(listName); | 193 | return _selectedItemsListMap.value(listName); |
| 189 | } | 194 | } |
| 190 | 195 | ||
| 191 | void SelectionScriptingInterface::printList(const QString& listName) { | 196 | void SelectionScriptingInterface::printList(const QString& listName) { |
| 192 | // QReadLocker lock(&_selectionListsLock); | 197 | QReadLocker lock(&_selectionListsLock); |
| 193 | auto currentList = _selectedItemsListMap.find(listName); | 198 | auto currentList = _selectedItemsListMap.find(listName); |
| 194 | if (currentList != _selectedItemsListMap.end()) { | 199 | if (currentList != _selectedItemsListMap.end()) { |
| 195 | if ((*currentList).getContainsData()) { | 200 | if ((*currentList).getContainsData()) { |
| @@ -222,8 +227,12 @@ void SelectionScriptingInterface::printList(const QString& listName) { · 26 unmodified lines | |||
| 222 | } | 227 | } |
| 223 | 228 | ||
| 224 | bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { | 229 | bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { |
| 225 | // QWriteLocker lock(&_selectionListsLock); | 230 | bool removed = false; |
| 226 | if (_selectedItemsListMap.remove(listName)) { | 231 | { |
| 232 | QWriteLocker lock(&_selectionListsLock); | ||
| 233 | bool removed = _selectedItemsListMap.remove(listName); | ||
| 234 | } | ||
| 235 | if (removed) { | ||
| 227 | onSelectedItemsListChanged(listName); | 236 | onSelectedItemsListChanged(listName); |
| 228 | return true; | 237 | return true; |
| 229 | } else { | 238 | } else { |
| @@ -232,24 +241,25 @@ bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { · 2 unmodified lines | |||
| 232 | } | 241 | } |
| 233 | 242 | ||
| 234 | void SelectionScriptingInterface::setupHandler(const QString& selectionName) { | 243 | void SelectionScriptingInterface::setupHandler(const QString& selectionName) { |
| 235 | // QWriteLocker lock(&_selectionListsLock); | 244 | QWriteLocker lock(&_selectionHandlersLock); |
| 236 | auto handler = _handlerMap.find(selectionName); | 245 | auto handler = _handlerMap.find(selectionName); |
| 237 | if (handler == _handlerMap.end()) { | 246 | if (handler == _handlerMap.end()) { |
| 238 | handler = _handlerMap.insert(selectionName, new SelectionToSceneHandler()); | 247 | handler = _handlerMap.insert(selectionName, new SelectionToSceneHandler()); |
| 239 | } | 248 | } |
| 240 | 249 | ||
| 241 | |||
| 242 | (*handler)->initialize(selectionName); | 250 | (*handler)->initialize(selectionName); |
| 243 | // connect(this, &SelectionScriptingInterface::selectedItemsListChanged, handler.value(), &SelectionToSceneHandler::selectedItemsListChanged); | ||
| 244 | |||
| 245 | } | 251 | } |
| 246 | 252 | ||
| 247 | void SelectionScriptingInterface::onSelectedItemsListChanged(const QString& listName) { | 253 | void SelectionScriptingInterface::onSelectedItemsListChanged(const QString& listName) { |
| 248 | // QWriteLocker lock(&_selectionListsLock); | 254 | { |
| 249 | auto handler = _handlerMap.find(listName); | 255 | QWriteLocker lock(&_selectionHandlersLock); |
| 250 | if (handler != _handlerMap.end()) { | 256 | auto handler = _handlerMap.find(listName); |
| 251 | (*handler)->updateSceneFromSelectedList(); | 257 | if (handler != _handlerMap.end()) { |
| 258 | (*handler)->updateSceneFromSelectedList(); | ||
| 259 | } | ||
| 252 | } | 260 | } |
| 261 | |||
| 262 | emit selectedItemsListChanged(listName); | ||
| 253 | } | 263 | } |
| 254 | 264 | ||
| 255 | 265 | ||
| @@ -312,66 +322,65 @@ void SelectionToSceneHandler::updateSceneFromSelectedList() { · 56 unmodified lines | |||
| 312 | qWarning() << "SelectionToSceneHandler::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown"; | 322 | qWarning() << "SelectionToSceneHandler::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown"; |
| 313 | } | 323 | } |
| 314 | } | 324 | } |
| 315 | /* | 325 | |
| 316 | void SelectionToSceneHandler::highlightStyleChanged(const QString& listName) { | 326 | bool SelectionHighlightStyle::fromVariantMap(const QVariantMap& properties) { |
| 317 | if (listName == _listName) { | 327 | auto colorVariant = properties["outlineUnoccludedColor"]; |
| 318 | auto mainScene = qApp->getMain3DScene(); | 328 | if (colorVariant.isValid()) { |
| 319 | if (mainScene) { | 329 | bool isValid; |
| 320 | auto thisStyle = DependencyManager::get<SelectionScriptingInterface>()->getHighlightStyle(listName); | 330 | auto color = xColorFromVariant(colorVariant, isValid); |
| 321 | render::Transaction transaction; | 331 | if (isValid) { |
| 322 | transaction.resetSelectionHighlight(listName.toStdString(), thisStyle); | 332 | _style._outlineUnoccluded.color = toGlm(color); |
| 323 | mainScene->enqueueTransaction(transaction); | ||
| 324 | } | ||
| 325 | else { | ||
| 326 | qWarning() << "SelectionToSceneHandler::highlightStyleChanged(), Unexpected null scene, possibly during application shutdown"; | ||
| 327 | } | 333 | } |
| 328 | } | 334 | } |
| 329 | } | 335 | colorVariant = properties["outlineOccludedColor"]; |
| 330 | 336 | if (colorVariant.isValid()) { | |
| 331 | void SelectionToSceneHandler::highlightStyleRemoved(const QString& listName) { | 337 | bool isValid; |
| 332 | if (listName == _listName) { | 338 | auto color = xColorFromVariant(colorVariant, isValid); |
| 333 | auto mainScene = qApp->getMain3DScene(); | 339 | if (isValid) { |
| 334 | if (mainScene) { | 340 | _style._outlineOccluded.color = toGlm(color); |
| 335 | render::Transaction transaction; | ||
| 336 | transaction.removeHighlightFromSelection(listName.toStdString()); | ||
| 337 | mainScene->enqueueTransaction(transaction); | ||
| 338 | } | 341 | } |
| 339 | else { | 342 | } |
| 340 | qWarning() << "SelectionToSceneHandler::highlightStyleRemoved(), Unexpected null scene, possibly during application shutdown"; | 343 | colorVariant = properties["fillUnoccludedColor"]; |
| 344 | if (colorVariant.isValid()) { | ||
| 345 | bool isValid; | ||
| 346 | auto color = xColorFromVariant(colorVariant, isValid); | ||
| 347 | if (isValid) { | ||
| 348 | _style._fillUnoccluded.color = toGlm(color); | ||
| 341 | } | 349 | } |
| 342 | } | 350 | } |
| 343 | } | 351 | colorVariant = properties["fillOccludedColor"]; |
| 344 | */ | 352 | if (colorVariant.isValid()) { |
| 345 | bool SelectionHighlightStyle::fromVariantMap(const QVariantMap& properties) { | ||
| 346 | auto outlineColor = properties["outlineColor"]; | ||
| 347 | if (outlineColor.isValid()) { | ||
| 348 | bool isValid; | 353 | bool isValid; |
| 349 | auto color = xColorFromVariant(properties["outlineColor"], isValid); | 354 | auto color = xColorFromVariant(colorVariant, isValid); |
| 350 | if (isValid) { | 355 | if (isValid) { |
| 351 | _style.color = toGlm(color); | 356 | _style._fillOccluded.color = toGlm(color); |
| 352 | } | 357 | } |
| 353 | } | 358 | } |
| 354 | auto outlineWidth = properties["outlineWidth"]; | 359 | |
| 355 | if (outlineWidth.isValid()) { | 360 | auto intensityVariant = properties["outlineUnoccludedIntensity"]; |
| 356 | _style.outlineWidth = outlineWidth.toFloat(); | 361 | if (intensityVariant.isValid()) { |
| 362 | _style._outlineUnoccluded.alpha = intensityVariant.toFloat(); | ||
| 357 | } | 363 | } |
| 358 | auto isOutlineSmooth = properties["isOutlineSmooth"]; | 364 | intensityVariant = properties["outlineOccludedIntensity"]; |
| 359 | if (isOutlineSmooth.isValid()) { | 365 | if (intensityVariant.isValid()) { |
| 360 | _style.isOutlineSmooth = isOutlineSmooth.toBool(); | 366 | _style._outlineOccluded.alpha = intensityVariant.toFloat(); |
| 361 | } | 367 | } |
| 362 | 368 | intensityVariant = properties["fillUnoccludedIntensity"]; | |
| 363 | auto outlineIntensity = properties["outlineIntensity"]; | 369 | if (intensityVariant.isValid()) { |
| 364 | if (outlineIntensity.isValid()) { | 370 | _style._fillUnoccluded.alpha = intensityVariant.toFloat(); |
| 365 | _style.outlineIntensity = outlineIntensity.toFloat(); | 371 | } |
| 372 | intensityVariant = properties["fillOccludedIntensity"]; | ||
| 373 | if (intensityVariant.isValid()) { | ||
| 374 | _style._fillOccluded.alpha = intensityVariant.toFloat(); | ||
| 366 | } | 375 | } |
| 367 | 376 | ||
| 368 | auto unoccludedFillOpacity = properties["unoccludedFillOpacity"]; | 377 | auto outlineWidth = properties["outlineWidth"]; |
| 369 | if (unoccludedFillOpacity.isValid()) { | 378 | if (outlineWidth.isValid()) { |
| 370 | _style.unoccludedFillOpacity = unoccludedFillOpacity.toFloat(); | 379 | _style._outlineWidth = outlineWidth.toFloat(); |
| 371 | } | 380 | } |
| 372 | auto occludedFillOpacity = properties["occludedFillOpacity"]; | 381 | auto isOutlineSmooth = properties["isOutlineSmooth"]; |
| 373 | if (occludedFillOpacity.isValid()) { | 382 | if (isOutlineSmooth.isValid()) { |
| 374 | _style.occludedFillOpacity = occludedFillOpacity.toFloat(); | 383 | _style._isOutlineSmooth = isOutlineSmooth.toBool(); |
| 375 | } | 384 | } |
| 376 | 385 | ||
| 377 | return true; | 386 | return true; |
| @@ -380,12 +389,18 @@ bool SelectionHighlightStyle::fromVariantMap(const QVariantMap& properties) { · 2 unmodified lines | |||
| 380 | QVariantMap SelectionHighlightStyle::toVariantMap() const { | 389 | QVariantMap SelectionHighlightStyle::toVariantMap() const { |
| 381 | QVariantMap properties; | 390 | QVariantMap properties; |
| 382 | 391 | ||
| 383 | properties["outlineColor"] = xColorToVariant(xColorFromGlm(_style.color)); | 392 | properties["outlineUnoccludedColor"] = xColorToVariant(xColorFromGlm(_style._outlineUnoccluded.color)); |
| 384 | properties["outlineWidth"] = _style.outlineWidth; | 393 | properties["outlineOccludedColor"] = xColorToVariant(xColorFromGlm(_style._outlineOccluded.color)); |
| 385 | properties["isOutlineSmooth"] = _style.isOutlineSmooth; | 394 | properties["fillUnoccludedColor"] = xColorToVariant(xColorFromGlm(_style._fillUnoccluded.color)); |
| 386 | properties["outlineIntensity"] = _style.outlineIntensity; | 395 | properties["fillOccludedColor"] = xColorToVariant(xColorFromGlm(_style._fillOccluded.color)); |
| 387 | properties["unoccludedFillOpacity"] = _style.unoccludedFillOpacity; | 396 | |
| 388 | properties["occludedFillOpacity"] = _style.occludedFillOpacity; | 397 | properties["outlineUnoccludedIntensity"] = _style._outlineUnoccluded.alpha; |
| 398 | properties["outlineOccludedIntensity"] = _style._outlineOccluded.alpha; | ||
| 399 | properties["fillUnoccludedIntensity"] = _style._fillUnoccluded.alpha; | ||
| 400 | properties["fillOccludedIntensity"] = _style._fillOccluded.alpha; | ||
| 401 | |||
| 402 | properties["outlineWidth"] = _style._outlineWidth; | ||
| 403 | properties["isOutlineSmooth"] = _style._isOutlineSmooth; | ||
| 389 | 404 | ||
| 390 | return properties; | 405 | return properties; |
| 391 | } | 406 | } |