Skip to content

Commit 75e8c9a

Browse files
author
hpcdgrie
committed
Order supported formats by their plugin
1 parent f1b310b commit 75e8c9a

3 files changed

Lines changed: 62 additions & 20 deletions

File tree

src/OpenCOVER/cover/VRSceneGraph.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,9 +1707,11 @@ VRSceneGraph::saveScenegraph(const std::string &filename, bool storeWithMenu)
17071707
bool validExt = false;
17081708
if (!fileExt.empty())
17091709
{
1710-
for (const auto& ext : supportedExtentions)
1710+
for (const auto& [plugins, exts] : supportedExtentions)
17111711
{
1712-
if (osg::iequals(fileExt, ext))
1712+
if (std::find_if(exts.begin(), exts.end(), [&fileExt](const std::string& ext) {
1713+
return osg::iequals(ext, fileExt);
1714+
}) != exts.end())
17131715
{
17141716
validExt = true;
17151717
break;

src/OpenCOVER/cover/coVRFileManager.cpp

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static void preloadOsgDbPlugins()
171171
}
172172
}
173173

174-
std::vector<std::string> getSupportedOsgExtentions() {
174+
std::map<std::string, std::vector<std::string>> getSupportedOsgExtentions() {
175175
//plugins are loaded lazily on demand, so we need to preload them first
176176
opencover::config::File configFile("supportedFormats");
177177

@@ -202,15 +202,20 @@ std::vector<std::string> getSupportedOsgExtentions() {
202202
*pluginNameArray = pluginNames;
203203
if(!configFile.save()) {
204204
std::cerr << "Could not open " << configFile.pathname() << " for writing supported formats" << std::endl;
205-
return std::vector<std::string>{};
205+
return std::map<std::string, std::vector<std::string>>{};
206206
}
207207
}
208208
auto formatArray = configFile.array<std::string>("supportedOsgFormats", "suffix");
209-
return formatArray->value();
209+
auto pluginNameArray = configFile.array<std::string>("supportedOsgFormatPluginNames", "pluginName");
210+
std::map<std::string, std::vector<std::string>> formatMap;
211+
for(size_t i=0; i<formatArray->value().size(); ++i) {
212+
formatMap[(*pluginNameArray)[i]].push_back((*formatArray)[i]);
213+
}
214+
return formatMap;
210215
}
211216

212217

213-
std::string getWriteFilterList(const std::vector<std::string>& supportedExtensions)
218+
std::string getWriteFilterList(const std::map<std::string, std::vector<std::string>>& supportedExtensions)
214219
{
215220
const std::vector<std::string> popularFilters = {
216221
"*.osg", "*.ive", "*.osgb", "*.osgt", "*.osgx",
@@ -225,10 +230,13 @@ std::string getWriteFilterList(const std::vector<std::string>& supportedExtensio
225230
{
226231
std::string ext = filter.substr(2);
227232
// Check if this extension is in supportedExtensions
228-
if (std::find(supportedExtensions.begin(), supportedExtensions.end(), ext) != supportedExtensions.end())
233+
for(auto & [pluginName, exts] : supportedExtensions)
229234
{
230-
result.append(filter);
231-
result.append(";");
235+
if (std::find(exts.begin(), exts.end(), ext) != exts.end())
236+
{
237+
result.append(filter);
238+
result.append(";");
239+
}
232240
}
233241
}
234242
}
@@ -239,7 +247,7 @@ std::string getWriteFilterList(const std::vector<std::string>& supportedExtensio
239247

240248
} // namespace detail
241249

242-
const std::vector<std::string> &coVRFileManager::getSupportedOsgExtentions() const {
250+
const std::map<std::string, std::vector<std::string>> &coVRFileManager::getSupportedOsgExtentions() const {
243251
return m_supportedOsgExtentions;
244252
}
245253

@@ -1824,16 +1832,48 @@ void coVRFileManager::updateSupportedFormats()
18241832
constexpr std::array<const char*, 18> popularExtensions = {
18251833
"wrl", "osg", "ive", "osgb", "osgt", "osgx", "obj", "stl", "ply", "iv", "dxf", "3ds", "flt", "dae", "md2", "geo", "bvh", "fbx"
18261834
};
1827-
1828-
for(const auto ext : popularExtensions)
1835+
// only show plugins for popular extensions, but with all of their supported types
1836+
std::map<std::string, std::vector<std::string>> popularPlugins;
1837+
for (const auto &ext : popularExtensions)
18291838
{
1830-
if(std::find(m_supportedOsgExtentions.begin(), m_supportedOsgExtentions.end(), ext) == m_supportedOsgExtentions.end())
1831-
continue;
1832-
m_supportedReadExtentions += "*.";
1833-
m_supportedReadExtentions += ext;
1834-
m_supportedReadExtentions += ";";
1839+
for(const auto &[plugin, exts] : m_supportedOsgExtentions)
1840+
{
1841+
if(std::find(exts.begin(), exts.end(), ext) != exts.end())
1842+
{
1843+
//remove reader/writer from plugin name
1844+
const std::array<std::string, 3> toRemove = { "reader/writer", "reader", "writer" };
1845+
std::string pluginName = plugin;
1846+
auto pluginNameLower = pluginName;
1847+
std::transform(pluginNameLower.begin(), pluginNameLower.end(), pluginNameLower.begin(), ::tolower);
1848+
for (const auto &rem : toRemove)
1849+
{
1850+
size_t pos = pluginNameLower.find(rem);
1851+
if (pos != std::string::npos)
1852+
{
1853+
pluginName.erase(pos, rem.length());
1854+
pluginNameLower.erase(pos, rem.length());
1855+
}
1856+
}
1857+
popularPlugins[pluginName] = exts;
1858+
}
1859+
}
1860+
}
1861+
// build filter string
1862+
for(const auto &[plugin, exts] : popularPlugins)
1863+
{
1864+
m_supportedReadExtentions += plugin + " (";
1865+
for(const auto ext : exts)
1866+
{
1867+
m_supportedReadExtentions += "*.";
1868+
m_supportedReadExtentions += ext;
1869+
m_supportedReadExtentions += " ";
1870+
}
1871+
m_supportedReadExtentions.pop_back(); //remove last space
1872+
m_supportedReadExtentions += ");;";
18351873
}
1836-
m_supportedReadExtentions += "*";
1874+
1875+
m_supportedReadExtentions += "All files (*.*)";
1876+
18371877
if(m_fileOpen)
18381878
m_fileOpen->setFilter(getFilterList());
18391879
}

src/OpenCOVER/cover/coVRFileManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class COVEREXPORT coVRFileManager : public vrui::coUpdateable
191191
int unregisterFileHandler(const FileHandler *handler);
192192
int unregisterFileHandler(coVRIOReader *handler);
193193

194-
const std::vector<std::string> &getSupportedOsgExtentions() const;
194+
const std::map<std::string, std::vector<std::string>> &getSupportedOsgExtentions() const;
195195

196196
const std::string &getFilterList() const;
197197

@@ -246,7 +246,7 @@ class COVEREXPORT coVRFileManager : public vrui::coUpdateable
246246
std::unique_ptr<ui::Owner> m_owner;
247247
ui::Group *m_fileGroup = nullptr;
248248
int uniqueNumber = 0;
249-
const std::vector<std::string> m_supportedOsgExtentions;
249+
const std::map<std::string, std::vector<std::string>> m_supportedOsgExtentions;
250250
std::string m_supportedReadExtentions, m_supportedWriteExtentions;
251251
ui::FileBrowser* m_fileOpen = nullptr;
252252
typedef std::list<const FileHandler *> FileHandlerList;

0 commit comments

Comments
 (0)