mirror of https://github.com/CGAL/cgal
add a mechanism to set a default loader for a given filetype for one run only
This commit is contained in:
parent
6a0ab7f089
commit
ad7738646d
|
|
@ -98,6 +98,7 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
|||
endif(NOT EIGEN3_FOUND AND NOT LAPACK_FOUND)
|
||||
|
||||
qt4_wrap_ui( MainWindowUI_files MainWindow.ui )
|
||||
qt4_wrap_ui( FileLoaderDialogUI_files FileLoaderDialog.ui )
|
||||
qt4_wrap_ui( Show_point_dialogUI_FILES Show_point_dialog.ui )
|
||||
qt4_wrap_ui( remeshingUI_FILES Remeshing_dialog.ui)
|
||||
qt4_wrap_ui( meshingUI_FILES Meshing_dialog.ui Meshing_pause_widget.ui )
|
||||
|
|
@ -107,7 +108,9 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
|||
qt4_wrap_ui( funcUI_FILES Function_dialog.ui )
|
||||
|
||||
qt4_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" )
|
||||
qt4_generate_moc( "File_loader_dialog.h" "${CMAKE_CURRENT_BINARY_DIR}/File_loader_dialog_moc.cpp" )
|
||||
add_file_dependencies( MainWindow_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.h" )
|
||||
add_file_dependencies( File_loader_dialog_moc_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/File_loader_dialog.h" )
|
||||
|
||||
qt4_generate_moc( "Viewer.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" )
|
||||
add_file_dependencies( Viewer_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/Viewer.h" )
|
||||
|
|
@ -227,8 +230,9 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
|||
# Scene.cpp
|
||||
# MainWindow_curvature_estimation.cpp
|
||||
MainWindow_moc.cpp
|
||||
File_loader_dialog_moc.cpp
|
||||
# Viewer_moc.cpp
|
||||
${MainWindowUI_files} ${PreferencesUI_FILES} ${RESOURCE_FILES} )
|
||||
${FileLoaderDialogUI_files} ${MainWindowUI_files} ${PreferencesUI_FILES} ${RESOURCE_FILES} )
|
||||
add_to_cached_list( CGAL_EXECUTABLE_TARGETS Polyhedron_3 )
|
||||
if(EIGEN3_FOUND OR TAUCS_FOUND)
|
||||
# add_executable( Polyhedron_3 Scene_tex_rendering.cpp Scene_tex_polyhedron_operations.cpp )
|
||||
|
|
@ -236,6 +240,7 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
|||
# else(POLYHEDRON_DEMO_ENABLE_FORWARD_DECL)
|
||||
# add_file_dependencies( Polyhedron_3.cpp "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp"
|
||||
# "${CMAKE_CURRENT_BINARY_DIR}/Scene_moc.cpp"
|
||||
# "${CMAKE_CURRENT_BINARY_DIR}/File_loader_dialog_moc.cpp"
|
||||
# "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" )
|
||||
# add_executable ( Polyhedron_3 Polyhedron_3.cpp ${UI_FILES} ${RESOURCE_FILES} )
|
||||
# endif(POLYHEDRON_DEMO_ENABLE_FORWARD_DECL)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,140 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FileLoaderDialog</class>
|
||||
<widget class="QDialog" name="FileLoaderDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>353</width>
|
||||
<height>144</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Select a loader</string>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>170</x>
|
||||
<y>80</y>
|
||||
<width>181</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="pluginBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>40</y>
|
||||
<width>321</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="accessibleName">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="alwaysUse">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>120</y>
|
||||
<width>281</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>10</y>
|
||||
<width>371</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>FileLoaderDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>FileLoaderDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#include <QFileInfo>
|
||||
#include <QLayout>
|
||||
#include "ui_FileLoaderDialog.h"
|
||||
|
||||
class File_loader_dialog : public QDialog, private Ui::FileLoaderDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
File_loader_dialog()
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
static
|
||||
std::pair<QString,bool>
|
||||
getItem(QString filename, const QStringList& item_list, bool* ok)
|
||||
{
|
||||
File_loader_dialog dialog;
|
||||
dialog.pluginBox->addItems(item_list);
|
||||
dialog.label->setText(tr("Available loaders for %1 :").arg(filename));
|
||||
QFileInfo fileinfo(filename);
|
||||
dialog.alwaysUse->setText(tr("use for &all *.%1 files in this session").arg(fileinfo.completeSuffix()) );
|
||||
*ok = dialog.exec();
|
||||
return std::make_pair(
|
||||
dialog.pluginBox->currentText(),
|
||||
dialog.alwaysUse->isChecked()
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -43,6 +43,7 @@
|
|||
#include "ui_Preferences.h"
|
||||
|
||||
#include "Show_point_dialog.h"
|
||||
#include "File_loader_dialog.h"
|
||||
|
||||
#ifdef QT_SCRIPT_LIB
|
||||
# include <QScriptEngine>
|
||||
|
|
@ -713,57 +714,70 @@ void MainWindow::open(QString filename)
|
|||
return;
|
||||
}
|
||||
|
||||
//match all filters between ()
|
||||
QRegExp all_filters_rx("\\((.*)\\)");
|
||||
|
||||
// collect all io_plugins and offer them to load if the file extension match one name filter
|
||||
// also collect all available plugin in case of a no extension match
|
||||
|
||||
QStringList selected_items;
|
||||
QStringList all_items;
|
||||
Q_FOREACH(Polyhedron_demo_io_plugin_interface* io_plugin, io_plugins) {
|
||||
all_items << io_plugin->name();
|
||||
QStringList split_filters = io_plugin->nameFilters().split(";;");
|
||||
bool stop=false;
|
||||
Q_FOREACH(const QString& filter, split_filters) {
|
||||
//extract filters
|
||||
if ( all_filters_rx.indexIn(filter)!=-1 ){
|
||||
Q_FOREACH(const QString& pattern,all_filters_rx.cap(1).split(' ')){
|
||||
QRegExp rx(pattern);
|
||||
rx.setPatternSyntax(QRegExp::Wildcard);
|
||||
if ( rx.exactMatch(filename_striped) ){
|
||||
selected_items << io_plugin->name();
|
||||
stop=true;
|
||||
break;
|
||||
|
||||
QMap<QString,QString>::iterator dfs_it =
|
||||
default_plugin_selection.find( fileinfo.completeSuffix() );
|
||||
|
||||
if ( dfs_it==default_plugin_selection.end() )
|
||||
{
|
||||
//match all filters between ()
|
||||
QRegExp all_filters_rx("\\((.*)\\)");
|
||||
// collect all io_plugins and offer them to load if the file extension match one name filter
|
||||
// also collect all available plugin in case of a no extension match
|
||||
Q_FOREACH(Polyhedron_demo_io_plugin_interface* io_plugin, io_plugins) {
|
||||
all_items << io_plugin->name();
|
||||
QStringList split_filters = io_plugin->nameFilters().split(";;");
|
||||
bool stop=false;
|
||||
Q_FOREACH(const QString& filter, split_filters) {
|
||||
//extract filters
|
||||
if ( all_filters_rx.indexIn(filter)!=-1 ){
|
||||
Q_FOREACH(const QString& pattern,all_filters_rx.cap(1).split(' ')){
|
||||
QRegExp rx(pattern);
|
||||
rx.setPatternSyntax(QRegExp::Wildcard);
|
||||
if ( rx.exactMatch(filename_striped) ){
|
||||
selected_items << io_plugin->name();
|
||||
stop=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (stop) break;
|
||||
}
|
||||
if (stop) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
selected_items << *dfs_it;
|
||||
|
||||
bool ok;
|
||||
QString loader_name;
|
||||
|
||||
std::pair<QString, bool> load_pair;
|
||||
|
||||
switch( selected_items.size() )
|
||||
{
|
||||
case 1:
|
||||
loader_name=selected_items.first();
|
||||
load_pair = std::make_pair(selected_items.first(), false);
|
||||
ok=true;
|
||||
break;
|
||||
case 0:
|
||||
loader_name=QInputDialog::getItem(this, tr("Select a loader"), tr("Available loaders for %1 :").arg(fileinfo.fileName()), all_items, 0, false, &ok);
|
||||
load_pair = File_loader_dialog::getItem(fileinfo.fileName(), all_items, &ok);
|
||||
break;
|
||||
default:
|
||||
loader_name=QInputDialog::getItem(this, tr("Select a loader"), tr("Available loaders for %1 :").arg(fileinfo.fileName()), selected_items, 0, false, &ok);
|
||||
load_pair = File_loader_dialog::getItem(fileinfo.fileName(), selected_items, &ok);
|
||||
}
|
||||
|
||||
if(!ok || loader_name.isEmpty()) { return; }
|
||||
if(!ok || load_pair.first.isEmpty()) { return; }
|
||||
|
||||
if (load_pair.second)
|
||||
default_plugin_selection[fileinfo.completeSuffix()]=load_pair.first;
|
||||
|
||||
|
||||
QSettings settings;
|
||||
settings.setValue("OFF open directory",
|
||||
fileinfo.absoluteDir().absolutePath());
|
||||
|
||||
Scene_item* scene_item = load_item(fileinfo, find_loader(loader_name));
|
||||
Scene_item* scene_item = load_item(fileinfo, find_loader(load_pair.first));
|
||||
selectSceneItem(scene->addItem(scene_item));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ private:
|
|||
QTreeView* sceneView;
|
||||
Ui::MainWindow* ui;
|
||||
QVector<Polyhedron_demo_io_plugin_interface*> io_plugins;
|
||||
|
||||
QMap<QString,QString> default_plugin_selection;
|
||||
// typedef to make Q_FOREACH work
|
||||
typedef QPair<Polyhedron_demo_plugin_interface*, QString> PluginNamePair;
|
||||
QVector<PluginNamePair > plugins;
|
||||
|
|
|
|||
Loading…
Reference in New Issue