mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Sort nodes in GlobeBrowsing UI by whether they have URLs associated with them or not (closes #580)
This commit is contained in:
@@ -628,6 +628,11 @@ GlobeBrowsingModule::urlInfo(const std::string& globe) const
|
||||
return res;
|
||||
}
|
||||
|
||||
bool GlobeBrowsingModule::hasUrlInfo(const std::string& globe) const {
|
||||
return _urlList.find(globe) != _urlList.end();
|
||||
}
|
||||
|
||||
|
||||
#endif // GLOBEBROWSING_USE_GDAL
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
Capabilities capabilities(const std::string& name);
|
||||
|
||||
std::vector<UrlInfo> urlInfo(const std::string& globe) const;
|
||||
bool hasUrlInfo(const std::string& globe) const;
|
||||
|
||||
void removeWMSServer(const std::string& name);
|
||||
|
||||
|
||||
@@ -79,9 +79,9 @@ void GuiGlobeBrowsingComponent::render() {
|
||||
std::remove_if(
|
||||
nodes.begin(),
|
||||
nodes.end(),
|
||||
[](SceneGraphNode* n) {
|
||||
return !(n->renderable() &&
|
||||
n->renderable()->identifier() == "RenderableGlobe");
|
||||
[module](SceneGraphNode* n) {
|
||||
Renderable* r = n->renderable();
|
||||
return !r || r->identifier() != "RenderableGlobe";
|
||||
}
|
||||
),
|
||||
nodes.end()
|
||||
@@ -89,13 +89,40 @@ void GuiGlobeBrowsingComponent::render() {
|
||||
std::sort(
|
||||
nodes.begin(),
|
||||
nodes.end(),
|
||||
[](SceneGraphNode* lhs, SceneGraphNode* rhs) {
|
||||
[module](SceneGraphNode* lhs, SceneGraphNode* rhs) {
|
||||
bool lhsHasUrl = module->hasUrlInfo(lhs->identifier());
|
||||
bool rhsHasUrl = module->hasUrlInfo(rhs->identifier());
|
||||
|
||||
if (lhsHasUrl && !rhsHasUrl) {
|
||||
return true;
|
||||
}
|
||||
if (!lhsHasUrl && rhsHasUrl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lhs->guiName() < rhs->guiName();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
auto firstWithoutUrl = std::find_if(
|
||||
nodes.begin(),
|
||||
nodes.end(),
|
||||
[module](SceneGraphNode* n) {
|
||||
return !module->hasUrlInfo(n->identifier());
|
||||
}
|
||||
);
|
||||
nodes.insert(firstWithoutUrl, nullptr);
|
||||
|
||||
std::string nodeNames;
|
||||
for (SceneGraphNode* n : nodes) {
|
||||
nodeNames += n->identifier() + '\0';
|
||||
// Add separator between nodes with URL and nodes without
|
||||
if (n) {
|
||||
nodeNames += n->identifier() + '\0';
|
||||
}
|
||||
else {
|
||||
nodeNames += std::string("===== =====") + '\0';
|
||||
}
|
||||
}
|
||||
|
||||
int iNode = -1;
|
||||
@@ -116,7 +143,7 @@ void GuiGlobeBrowsingComponent::render() {
|
||||
nodes.cbegin(),
|
||||
nodes.cend(),
|
||||
[this](SceneGraphNode* lhs) {
|
||||
return lhs->identifier() == _currentNode;
|
||||
return lhs && (lhs->identifier() == _currentNode);
|
||||
}
|
||||
);
|
||||
iNode = static_cast<int>(std::distance(nodes.cbegin(), it));
|
||||
@@ -141,6 +168,12 @@ void GuiGlobeBrowsingComponent::render() {
|
||||
// or if there are no nodes
|
||||
return;
|
||||
}
|
||||
|
||||
if (!nodes[iNode]) {
|
||||
// The user selected the separator
|
||||
return;
|
||||
}
|
||||
|
||||
_currentNode = nodes[iNode]->identifier();
|
||||
|
||||
if (nodeChanged) {
|
||||
@@ -225,7 +258,7 @@ void GuiGlobeBrowsingComponent::render() {
|
||||
|
||||
}
|
||||
|
||||
if (iServer == -1) {
|
||||
if (iServer < 0) {
|
||||
return;
|
||||
}
|
||||
_currentServer = urlInfo[iServer].name;
|
||||
@@ -299,16 +332,26 @@ void GuiGlobeBrowsingComponent::render() {
|
||||
auto addFunc = [this, &l](const std::string& type) {
|
||||
std::string layerName = l.name;
|
||||
std::replace(layerName.begin(), layerName.end(), '.', '-');
|
||||
layerName.erase(
|
||||
std::remove(layerName.begin(), layerName.end(), ' '),
|
||||
layerName.end()
|
||||
);
|
||||
OsEng.scriptEngine().queueScript(
|
||||
fmt::format(
|
||||
"openspace.globebrowsing.addLayer(\
|
||||
'{}', \
|
||||
'{}', \
|
||||
{{ Name = '{}', FilePath = '{}', Enabled = true }}\
|
||||
{{ \
|
||||
Identifier = '{}',\
|
||||
Name = '{}',\
|
||||
FilePath = '{}',\
|
||||
Enabled = true\
|
||||
}}\
|
||||
);",
|
||||
_currentNode,
|
||||
type,
|
||||
layerName,
|
||||
l.name,
|
||||
l.url
|
||||
),
|
||||
scripting::ScriptEngine::RemoteScripting::Yes
|
||||
|
||||
Reference in New Issue
Block a user