@@ -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}
0 commit comments