History

extend the set of interface for multi highlight

samcake committed 8 years ago

Commit 1514cdf1 parent aa163db11 files · +727 −161Browse files

Showing the changes to interface/src/scripting/SelectionScriptingInterface.cpp (1 of 11 files). Show all

Unified · Split

interface/src/scripting/SelectionScriptingInterface.cpp+124−109
@@ -72,28 +72,29 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& lis · 71 unmodified lines
7272 }
7373
7474 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+ }
7779 onSelectedItemsListChanged(listName);
7880 return true;
7981 }
8082
8183 bool SelectionScriptingInterface::enableListHighlight(const QString& listName, const QVariantMap& highlightStyleValues) {
82− // QWriteLocker lock(&_selectionListsLock);
84+ QWriteLocker lock(&_highlightStylesLock);
8385
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());
8789
8890 }
8991
9092 if (!(*highlightStyle).isBoundToList()) {
91− auto currentList = _selectedItemsListMap.find(listName);
93+ /* auto currentList = _selectedItemsListMap.find(listName);
9294 if (currentList == _selectedItemsListMap.end()) {
9395 _selectedItemsListMap.insert(listName, GameplayObjects());
94− }
96+ }*/
9597 setupHandler(listName);
96−
9798 (*highlightStyle).setBoundToList(true);
9899 }
99100
@@ -113,33 +114,32 @@ bool SelectionScriptingInterface::enableListHighlight(const QString& listName, c · 13 unmodified lines
113114 }
114115
115116 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);
132124
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+ }
134134 }
135135
136136 return true;
137137 }
138138
139139 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()) {
143143 return QVariantMap();
144144 } else {
145145 return (*highlightStyle).toVariantMap();
@@ -147,9 +147,9 @@ QVariantMap SelectionScriptingInterface::getListHighlightStyle(const QString& li · 1 unmodified line
147147 }
148148
149149 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()) {
153153 return render::HighlightStyle();
154154 } else {
155155 return (*highlightStyle).getStyle();
@@ -157,25 +157,30 @@ render::HighlightStyle SelectionScriptingInterface::getHighlightStyle(const QStr · 1 unmodified line
157157 }
158158
159159 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+ }
166166 onSelectedItemsListChanged(listName);
167167 return true;
168168 }
169169 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) {
176180 onSelectedItemsListChanged(listName);
177181 return true;
178− } else {
182+ }
183+ else {
179184 return false;
180185 }
181186 }
@@ -184,12 +189,12 @@ template <class T> bool SelectionScriptingInterface::removeFromGameplayObjects(c · 2 unmodified lines
184189 //
185190
186191 GameplayObjects SelectionScriptingInterface::getList(const QString& listName) {
187− // QReadLocker lock(&_selectionListsLock);
192+ QReadLocker lock(&_selectionListsLock);
188193 return _selectedItemsListMap.value(listName);
189194 }
190195
191196 void SelectionScriptingInterface::printList(const QString& listName) {
192− // QReadLocker lock(&_selectionListsLock);
197+ QReadLocker lock(&_selectionListsLock);
193198 auto currentList = _selectedItemsListMap.find(listName);
194199 if (currentList != _selectedItemsListMap.end()) {
195200 if ((*currentList).getContainsData()) {
@@ -222,8 +227,12 @@ void SelectionScriptingInterface::printList(const QString& listName) { · 26 unmodified lines
222227 }
223228
224229 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) {
227236 onSelectedItemsListChanged(listName);
228237 return true;
229238 } else {
@@ -232,24 +241,25 @@ bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { · 2 unmodified lines
232241 }
233242
234243 void SelectionScriptingInterface::setupHandler(const QString& selectionName) {
235− // QWriteLocker lock(&_selectionListsLock);
244+ QWriteLocker lock(&_selectionHandlersLock);
236245 auto handler = _handlerMap.find(selectionName);
237246 if (handler == _handlerMap.end()) {
238247 handler = _handlerMap.insert(selectionName, new SelectionToSceneHandler());
239248 }
240249
241−
242250 (*handler)->initialize(selectionName);
243− // connect(this, &SelectionScriptingInterface::selectedItemsListChanged, handler.value(), &SelectionToSceneHandler::selectedItemsListChanged);
244−
245251 }
246252
247253 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+ }
252260 }
261+
262+ emit selectedItemsListChanged(listName);
253263 }
254264
255265
@@ -312,66 +322,65 @@ void SelectionToSceneHandler::updateSceneFromSelectedList() { · 56 unmodified lines
312322 qWarning() << "SelectionToSceneHandler::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown";
313323 }
314324 }
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);
327333 }
328334 }
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);
338341 }
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);
341349 }
342350 }
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()) {
348353 bool isValid;
349− auto color = xColorFromVariant(properties["outlineColor"], isValid);
354+ auto color = xColorFromVariant(colorVariant, isValid);
350355 if (isValid) {
351− _style.color = toGlm(color);
356+ _style._fillOccluded.color = toGlm(color);
352357 }
353358 }
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();
357363 }
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();
361367 }
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();
366375 }
367376
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();
371380 }
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();
375384 }
376385
377386 return true;
@@ -380,12 +389,18 @@ bool SelectionHighlightStyle::fromVariantMap(const QVariantMap& properties) { · 2 unmodified lines
380389 QVariantMap SelectionHighlightStyle::toVariantMap() const {
381390 QVariantMap properties;
382391
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;
389404
390405 return properties;
391406 }