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