diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 0e640fdd4d..7f002ac5b4 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -161,6 +161,7 @@ set(SOURCES plugins/containers/render_plugin_container.cpp plugins/interfaces/meshlab_plugin_logger.cpp plugins/interfaces/decorate_plugin.cpp + plugins/interfaces/edit_plugin.cpp plugins/interfaces/filter_plugin.cpp plugins/interfaces/io_plugin.cpp plugins/action_searcher.cpp diff --git a/src/common/plugins/interfaces/edit_plugin.cpp b/src/common/plugins/interfaces/edit_plugin.cpp new file mode 100644 index 0000000000..59019a975c --- /dev/null +++ b/src/common/plugins/interfaces/edit_plugin.cpp @@ -0,0 +1,5 @@ +#include "edit_plugin.h" + +void EditPlugin::initGlobalParameterList(RichParameterList& globalparam) +{ +} \ No newline at end of file diff --git a/src/common/plugins/interfaces/edit_plugin.h b/src/common/plugins/interfaces/edit_plugin.h index af8d29f18e..f58cbf49f5 100644 --- a/src/common/plugins/interfaces/edit_plugin.h +++ b/src/common/plugins/interfaces/edit_plugin.h @@ -108,6 +108,8 @@ class EditPlugin : public MeshLabPlugin EditPlugin() {} virtual ~EditPlugin() {} + virtual void initGlobalParameterList(RichParameterList& defaultGlobalParamSet); + //gets a list of actions available from this plugin virtual std::list actions() const {return actionList;}; @@ -117,8 +119,14 @@ class EditPlugin : public MeshLabPlugin //get the description for the given action virtual QString getEditToolDescription(const QAction *) = 0; + void setCurrentGlobalParamSet(RichParameterList* cgp) + { + currentGlobalParamSet = cgp; + } + protected: std::list actionList; + RichParameterList* currentGlobalParamSet; }; #define EDIT_PLUGIN_IID "vcg.meshlab.EditPlugin/1.0" diff --git a/src/meshlab/mainwindow.h b/src/meshlab/mainwindow.h index 5656b2d29e..295bfdc105 100644 --- a/src/meshlab/mainwindow.h +++ b/src/meshlab/mainwindow.h @@ -113,6 +113,7 @@ class MainWindow : public QMainWindow static bool QCallBack(const int pos, const char * str); //const QString appName() const {return tr("MeshLab v")+appVer(); } //const QString appVer() const {return tr("1.3.2"); } + RichParameterList& getCurrentParameterList(); MainWindowSetting mwsettings; public slots: // callback function to execute a filter @@ -531,6 +532,9 @@ private slots: static QString getDecoratedFileName(const QString& name); MultiViewer_Container* _currviewcontainer; + +Q_SIGNALS: + void customSettingsChanged(const RichParameterList &rpl); }; /// Event filter that is installed to intercept the open events sent directly by the Operative System diff --git a/src/meshlab/mainwindow_Init.cpp b/src/meshlab/mainwindow_Init.cpp index 014a48bfd6..e2fbe1ac7d 100644 --- a/src/meshlab/mainwindow_Init.cpp +++ b/src/meshlab/mainwindow_Init.cpp @@ -922,6 +922,12 @@ void MainWindow::loadDefaultSettingsFromPlugins() } } + //edit settings + for (EditPlugin* ep : PM.editPluginFactoryIterator()) { + ep->initGlobalParameterList(defaultGlobalParams); + ep->setCurrentGlobalParamSet(¤tGlobalParams); + } + //io settings for (IOPlugin* iop : PM.ioPluginIterator()){ for (const FileFormat& ff : iop->importFormats()) { diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index edd1bbcc81..2bf46132c4 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -104,6 +104,11 @@ void MainWindow::updateCustomSettings() { mwsettings.updateGlobalParameterList(currentGlobalParams); emit dispatchCustomSettings(currentGlobalParams); + +} +RichParameterList& MainWindow::getCurrentParameterList() +{ + return currentGlobalParams; } void MainWindow::updateWindowMenu() @@ -2196,6 +2201,15 @@ void MainWindow::reloadAllMesh() { // Discards changes and reloads current file // save current file name + QMessageBox::StandardButton reply; + reply = QMessageBox::question( + this, + tr("You are reloading all mesh!"), + tr("Are You sure to Reload?"), + QMessageBox::Yes | QMessageBox::No); + if (reply == QMessageBox::No) { + return; + } qb->show(); QElapsedTimer t; t.start(); @@ -2244,6 +2258,14 @@ void MainWindow::reload() return; // Discards changes and reloads current file // save current file name + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this, + tr("You are reloading the current mesh"), + tr("Are you sure to reload?"), + QMessageBox::Yes | QMessageBox::No); + if (reply == QMessageBox::No) { + return; + } qb->show(); QString fileName = meshDoc()->mm()->fullName(); diff --git a/src/meshlabplugins/edit_align/edit_align_factory.h b/src/meshlabplugins/edit_align/edit_align_factory.h index 33ca58fe12..f5e24d35b0 100644 --- a/src/meshlabplugins/edit_align/edit_align_factory.h +++ b/src/meshlabplugins/edit_align/edit_align_factory.h @@ -38,6 +38,11 @@ class EditAlignFactory : public QObject, public EditPlugin EditAlignFactory(); virtual ~EditAlignFactory() { delete editAlign; } + void initGlobalParameterList(RichParameterList& /*paramList*/) + { + // No global parameters needed for this plugin + } + virtual QString pluginName() const; //get the edit tool for the given action diff --git a/src/meshlabplugins/edit_manipulators/edit_manipulators_factory.h b/src/meshlabplugins/edit_manipulators/edit_manipulators_factory.h index b19ef5ed9d..0aebb74cee 100644 --- a/src/meshlabplugins/edit_manipulators/edit_manipulators_factory.h +++ b/src/meshlabplugins/edit_manipulators/edit_manipulators_factory.h @@ -38,6 +38,11 @@ class EditManipulatorsFactory : public QObject, public EditPlugin EditManipulatorsFactory(); virtual ~EditManipulatorsFactory() { delete editManipulators; } + void initGlobalParameterList(RichParameterList& /*paramList*/) + { + // No global parameters needed for this plugin + } + virtual QString pluginName() const; //get the edit tool for the given action diff --git a/src/meshlabplugins/edit_measure/edit_measure_factory.h b/src/meshlabplugins/edit_measure/edit_measure_factory.h index f4d63b4d7c..6f1c4aba11 100644 --- a/src/meshlabplugins/edit_measure/edit_measure_factory.h +++ b/src/meshlabplugins/edit_measure/edit_measure_factory.h @@ -38,6 +38,11 @@ class EditMeasureFactory : public QObject, public EditPlugin EditMeasureFactory(); virtual ~EditMeasureFactory() { delete editMeasure; } + void initGlobalParameterList(RichParameterList& /*paramList*/) + { + // No global parameters needed for this plugin + } + virtual QString pluginName() const; //get the edit tool for the given action diff --git a/src/meshlabplugins/edit_mutualcorrs/edit_mutualcorrs_factory.h b/src/meshlabplugins/edit_mutualcorrs/edit_mutualcorrs_factory.h index 010d34f178..bad04a63d8 100644 --- a/src/meshlabplugins/edit_mutualcorrs/edit_mutualcorrs_factory.h +++ b/src/meshlabplugins/edit_mutualcorrs/edit_mutualcorrs_factory.h @@ -37,6 +37,11 @@ class EditMutualCorrsFactory : public QObject, public EditPlugin EditMutualCorrsFactory(); virtual ~EditMutualCorrsFactory() { delete editMutualCorrs; } + void initGlobalParameterList(RichParameterList& /*paramList*/) + { + // No global parameters needed for this plugin + } + virtual QString pluginName() const; //get the edit tool for the given action diff --git a/src/meshlabplugins/edit_paint/edit_paint_factory.h b/src/meshlabplugins/edit_paint/edit_paint_factory.h index fe02975b42..97a3010fcc 100644 --- a/src/meshlabplugins/edit_paint/edit_paint_factory.h +++ b/src/meshlabplugins/edit_paint/edit_paint_factory.h @@ -38,6 +38,11 @@ class EditPaintFactory : public QObject, public EditPlugin EditPaintFactory(); virtual ~EditPaintFactory() { delete editPaint; } + void initGlobalParameterList(RichParameterList& /*paramList*/) + { + // No global parameters needed for this plugin + } + virtual QString pluginName() const; //get the edit tool for the given action diff --git a/src/meshlabplugins/edit_pickpoints/edit_pickpoints_factory.h b/src/meshlabplugins/edit_pickpoints/edit_pickpoints_factory.h index 44b62838f4..4d71948bf3 100644 --- a/src/meshlabplugins/edit_pickpoints/edit_pickpoints_factory.h +++ b/src/meshlabplugins/edit_pickpoints/edit_pickpoints_factory.h @@ -38,6 +38,11 @@ class EditPickPointsFactory : public QObject, public EditPlugin EditPickPointsFactory(); virtual ~EditPickPointsFactory() { delete editPickPoints; } + void initGlobalParameterList(RichParameterList& /*paramList*/) + { + // No global parameters needed for this plugin + } + virtual QString pluginName() const; //get the edit tool for the given action diff --git a/src/meshlabplugins/edit_point/edit_point_factory.h b/src/meshlabplugins/edit_point/edit_point_factory.h index 632901be01..f88cd41fd3 100644 --- a/src/meshlabplugins/edit_point/edit_point_factory.h +++ b/src/meshlabplugins/edit_point/edit_point_factory.h @@ -38,6 +38,11 @@ class PointEditFactory : public QObject, public EditPlugin PointEditFactory(); virtual ~PointEditFactory() { delete editPoint; } + void initGlobalParameterList(RichParameterList& /*paramList*/) + { + // No global parameters needed for this plugin + } + virtual QString pluginName() const; //get the edit tool for the given action diff --git a/src/meshlabplugins/edit_quality/edit_quality_factory.h b/src/meshlabplugins/edit_quality/edit_quality_factory.h index 2d8ae56a7d..86518cd3ba 100644 --- a/src/meshlabplugins/edit_quality/edit_quality_factory.h +++ b/src/meshlabplugins/edit_quality/edit_quality_factory.h @@ -38,6 +38,11 @@ class QualityMapperFactory : public QObject, public EditPlugin QualityMapperFactory(); virtual ~QualityMapperFactory() { delete editQuality; } + void initGlobalParameterList(RichParameterList& /*paramList*/) + { + // No global parameters needed for this plugin + } + virtual QString pluginName() const; //get the edit tool for the given action diff --git a/src/meshlabplugins/edit_referencing/edit_referencing_factory.h b/src/meshlabplugins/edit_referencing/edit_referencing_factory.h index f2187724eb..bea6799e33 100644 --- a/src/meshlabplugins/edit_referencing/edit_referencing_factory.h +++ b/src/meshlabplugins/edit_referencing/edit_referencing_factory.h @@ -37,6 +37,11 @@ class EditReferencingFactory : public QObject, public EditPlugin EditReferencingFactory(); virtual ~EditReferencingFactory() { delete editReferencing; } + void initGlobalParameterList(RichParameterList& /*paramList*/) + { + // No global parameters needed for this plugin + } + virtual QString pluginName() const; //get the edit tool for the given action diff --git a/src/meshlabplugins/edit_sample/edit_sample_factory.h b/src/meshlabplugins/edit_sample/edit_sample_factory.h index ed14fc598e..8d6a9bbfce 100644 --- a/src/meshlabplugins/edit_sample/edit_sample_factory.h +++ b/src/meshlabplugins/edit_sample/edit_sample_factory.h @@ -38,6 +38,11 @@ class SampleEditFactory : public QObject, public EditPlugin SampleEditFactory(); virtual ~SampleEditFactory() { delete editSample; } + void initGlobalParameterList(RichParameterList& /*paramList*/) + { + // No global parameters needed for this plugin + } + //returns the name of the plugin virtual QString pluginName() const; diff --git a/src/meshlabplugins/edit_select/edit_select.cpp b/src/meshlabplugins/edit_select/edit_select.cpp index 2c4ad3d1aa..07734b270c 100644 --- a/src/meshlabplugins/edit_select/edit_select.cpp +++ b/src/meshlabplugins/edit_select/edit_select.cpp @@ -22,7 +22,12 @@ ****************************************************************************/ #include "edit_select.h" +#include + +#include +#include #include +#include #include #include #include @@ -33,8 +38,10 @@ using namespace std; using namespace vcg; -EditSelectPlugin::EditSelectPlugin(int ConnectedMode) :selectionMode(ConnectedMode) { +EditSelectPlugin::EditSelectPlugin(RichParameterList* cgp, int ConnectedMode) :selectionMode(ConnectedMode) { isDragging = false; + currentGlobalParamSet = cgp; + qApp->installEventFilter(this); } QString EditSelectPlugin::info() @@ -62,131 +69,192 @@ void EditSelectPlugin::suggestedRenderingData(MeshModel & /*m*/, MLRenderingData dt.set(opts); } +bool EditSelectPlugin::keyReleaseEventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyRelease && QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + if (m_ref && gla_ref) { + // Check if the released key is the Alt key + if (keyEvent->key() == Qt::Key_Alt) { + keyReleaseEvent(keyEvent, *m_ref, gla_ref); + } + } + } + // Pass the event to the base class event filter + return QObject::eventFilter(obj, event); +} void EditSelectPlugin::keyReleaseEvent(QKeyEvent *e, MeshModel &m, GLArea *gla) { + bool ctrlState = currentGlobalParamSet->getBool("MeshLab::Editors::InvertCTRLBehavior"); + // global "all" commands - if (e->key() == Qt::Key_A) // select all - { - if (areaMode == 0){ // vertices - tri::UpdateSelection::VertexAll(m.cm); - gla->updateSelection(m.id(), true, false); - } - else if (areaMode == 1){ //faces - tri::UpdateSelection::FaceAll(m.cm); - gla->updateSelection(m.id(), false, true); - } - gla->update(); - e->accept(); - } + switch (e->key()) { + case Qt::Key_A: // select all + if (areaMode == 0) { // vertices + tri::UpdateSelection::VertexAll(m.cm); + gla->updateSelection(m.id(), true, false); + } else if (areaMode == 1) { // faces + tri::UpdateSelection::FaceAll(m.cm); + gla->updateSelection(m.id(), false, true); + } + gla->update(); + e->accept(); + break; + + case Qt::Key_D: // deselect all + if (areaMode == 0) { // vertices + tri::UpdateSelection::VertexClear(m.cm); + gla->updateSelection(m.id(), true, false); + } else if (areaMode == 1) { // faces + tri::UpdateSelection::FaceClear(m.cm); + gla->updateSelection(m.id(), false, true); + } + gla->update(); + e->accept(); + break; + + case Qt::Key_I: // invert all + if (areaMode == 0) { // vertices + tri::UpdateSelection::VertexInvert(m.cm); + gla->updateSelection(m.id(), true, false); + } else if (areaMode == 1) { // faces + tri::UpdateSelection::FaceInvert(m.cm); + gla->updateSelection(m.id(), false, true); + } + gla->update(); + e->accept(); + break; - if (e->key() == Qt::Key_D) // deselect all - { - if (areaMode == 0){ // vertices - tri::UpdateSelection::VertexClear(m.cm); - gla->updateSelection(m.id(), true, false); - } - else if (areaMode == 1){ //faces - tri::UpdateSelection::FaceClear(m.cm); - gla->updateSelection(m.id(), false, true); - } - gla->update(); - e->accept(); + default: + break; } - if (e->key() == Qt::Key_I) // invert all - { - if (areaMode == 0){ // vertices - tri::UpdateSelection::VertexInvert(m.cm); - gla->updateSelection(m.id(), true, false); - } - else if (areaMode == 1){ //faces - tri::UpdateSelection::FaceInvert(m.cm); - gla->updateSelection(m.id(), false, true); - } - gla->update(); - e->accept(); - } + if (selectionMode == SELECT_AREA_MODE) { + switch (e->key()) { + case Qt::Key_T: // toggle pick mode + areaMode = (areaMode + 1) % 2; + gla->update(); + e->accept(); + break; + case Qt::Key_C: // clear Polyline + selPolyLine.clear(); + gla->update(); + e->accept(); + break; - if (selectionMode == SELECT_AREA_MODE) - { - if (e->key() == Qt::Key_T) // toggle pick mode - { - areaMode = (areaMode + 1) % 2; - gla->update(); - e->accept(); - } + case Qt::Key_Backspace: // remove last point Polyline + if (selPolyLine.size() > 0) + selPolyLine.pop_back(); + gla->update(); + e->accept(); + break; - if (e->key() == Qt::Key_C) // clear Polyline - { - selPolyLine.clear(); - gla->update(); - e->accept(); - } + case Qt::Key_Q: // add to selection + doSelection(m, gla, 0); + gla->update(); + e->accept(); + break; - if (e->key() == Qt::Key_Backspace) // remove last point Polyline - { - if (selPolyLine.size() > 0) - selPolyLine.pop_back(); - gla->update(); - e->accept(); - } + case Qt::Key_W: // sub from selection + doSelection(m, gla, 1); + gla->update(); + e->accept(); + break; - if (e->key() == Qt::Key_Q) // add to selection - { - doSelection(m, gla, 0); - gla->update(); - e->accept(); - } + case Qt::Key_E: // invert selection + doSelection(m, gla, 2); + gla->update(); + e->accept(); + break; - if (e->key() == Qt::Key_W) // sub from selection + default: + break; + } + gla->setCursor(QCursor(QPixmap(":/images/sel_area.png"), 1, 1)); + } else { + if (ctrlState){ + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + } else { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + } + Qt::KeyboardModifiers mod = e->modifiers(); + if (e->key() == Qt::Key_Alt) { - doSelection(m, gla, 1); - gla->update(); - e->accept(); + if (ctrlState){ + if (mod & Qt::ControlModifier){ + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + } else if (mod & Qt::ShiftModifier){ + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + } else{ + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + } + } else{ + if (mod & Qt::ControlModifier){ + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + } else if (mod & Qt::ShiftModifier){ + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + } else{ + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + } + } + e->accept(); } - if (e->key() == Qt::Key_E) // invert selection - { - doSelection(m, gla, 2); - gla->update(); - e->accept(); + switch (selectionMode) { + case SELECT_VERT_MODE: + if (ctrlState){ + if (mod & Qt::ControlModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + else if (mod & Qt::ShiftModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + } else { + if (mod & Qt::ControlModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + else if (mod & Qt::ShiftModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + } + break; + + default: + if (mod & Qt::AltModifier) { + if (ctrlState){ + if (mod & Qt::ControlModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + else if (mod & Qt::ShiftModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + else + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + } else { + if (mod & Qt::ControlModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + else if (mod & Qt::ShiftModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + else + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + } + } else { + if (ctrlState){ + if (mod & Qt::ControlModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + else if (mod & Qt::ShiftModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + } else { + if (mod & Qt::ControlModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + else if (mod & Qt::ShiftModifier) + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + } + } + break; } - gla->setCursor(QCursor(QPixmap(":/images/sel_area.png"), 1, 1)); } - else - { - gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); - Qt::KeyboardModifiers mod = QApplication::queryKeyboardModifiers(); - if(selectionMode == SELECT_VERT_MODE) - { - if (mod & Qt::ControlModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); - else if (mod & Qt::ShiftModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); - } - else - { - if (mod & Qt::AltModifier) - { - if (mod & Qt::ControlModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus_eye.png"), 1, 1)); - else if (mod & Qt::ShiftModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus_eye.png"), 1, 1)); - else - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_eye.png"), 1, 1)); - } - else - { - if (mod & Qt::ControlModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); - else if (mod & Qt::ShiftModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); - } - } - } - + if(ctrlState){ + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + } else { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + } } void EditSelectPlugin::doSelection(MeshModel &m, GLArea *gla, int mode) @@ -264,43 +332,61 @@ void EditSelectPlugin::doSelection(MeshModel &m, GLArea *gla, int mode) } -void EditSelectPlugin::keyPressEvent(QKeyEvent * /*event*/, MeshModel & /*m*/, GLArea *gla) +void EditSelectPlugin::keyPressEvent(QKeyEvent *event, MeshModel &m, GLArea *gla) { - if (selectionMode == SELECT_AREA_MODE) - return; + bool ctrlState = currentGlobalParamSet->getBool("MeshLab::Editors::InvertCTRLBehavior"); - gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); - Qt::KeyboardModifiers mod = QApplication::queryKeyboardModifiers(); - if(selectionMode == SELECT_VERT_MODE) - { - if (mod & Qt::ControlModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); - else if (mod & Qt::ShiftModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); - } - else - { - if (mod & Qt::AltModifier) - { - if (mod & Qt::ControlModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus_eye.png"), 1, 1)); - else if (mod & Qt::ShiftModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus_eye.png"), 1, 1)); - else - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_eye.png"), 1, 1)); - } - else - { - if (mod & Qt::ControlModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); - else if (mod & Qt::ShiftModifier) - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); - } - } + switch (event->key()) + { + case Qt::Key_Control: + { + if (ctrlState) { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + } else { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + } + break; + } + case Qt::Key_Shift: + { + if (ctrlState) { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + } else { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + } + break; + } + case Qt::Key_Alt: + { + if (ctrlState) { + if (event->modifiers() & Qt::ControlModifier) { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + } else if (event->modifiers() & Qt::ShiftModifier) { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + } else { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus_eye.png"), 1, 1)); + } + } else { + if (event->modifiers() & Qt::ControlModifier) { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + } else if (event->modifiers() & Qt::ShiftModifier) { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"), 1, 1)); + } else { + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_eye.png"), 1, 1)); + } + } + break; + } + default: + { + break; + } + } } void EditSelectPlugin::mousePressEvent(QMouseEvent * event, MeshModel &m, GLArea *gla) { + bool ctrlState = currentGlobalParamSet->getBool("MeshLab::Editors::InvertCTRLBehavior"); if (selectionMode == SELECT_AREA_MODE) { selPolyLine.push_back(QTLogicalToOpenGL(gla, event->pos())); @@ -310,37 +396,64 @@ void EditSelectPlugin::mousePressEvent(QMouseEvent * event, MeshModel &m, GLArea LastSelVert.clear(); LastSelFace.clear(); - if ((event->modifiers() & Qt::ControlModifier) || - (event->modifiers() & Qt::ShiftModifier)) - { - CMeshO::FaceIterator fi; - for (fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi) - if (!(*fi).IsD() && (*fi).IsS()) - LastSelFace.push_back(&*fi); - - CMeshO::VertexIterator vi; - for (vi = m.cm.vert.begin(); vi != m.cm.vert.end(); ++vi) - if (!(*vi).IsD() && (*vi).IsS()) - LastSelVert.push_back(&*vi); + int ctrl = (event->modifiers() & Qt::ControlModifier) ? 1 : 0; + int shift = (event->modifiers() & Qt::ShiftModifier) ? 1 : 0; + int alt = (event->modifiers() & Qt::AltModifier) ? 1 : 0; + + switch (ctrlState * 4 + ctrl * 2 + shift) { + case 0: // !ctrlState && !ctrl && !shift + composingSelMode = SMClear; + selectFrontFlag = false; + break; + case 1: // !ctrlState && !ctrl && shift + composingSelMode = SMSub; + selectFrontFlag = false; + break; + case 2: // !ctrlState && ctrl && !shift + composingSelMode = SMAdd; + selectFrontFlag = false; + break; + case 3: // !ctrlState && ctrl && shift + composingSelMode = SMSub; + selectFrontFlag = false; + break; + case 4: // ctrlState && !ctrl && !shift + composingSelMode = SMAdd; + selectFrontFlag = alt; + break; + case 5: // ctrlState && !ctrl && shift + composingSelMode = SMSub; + selectFrontFlag = alt; + break; + case 6: // ctrlState && ctrl && !shift + composingSelMode = SMClear; + selectFrontFlag = alt; + break; + case 7: // ctrlState && ctrl && shift + composingSelMode = SMSub; + selectFrontFlag = alt; + break; } - composingSelMode = SMClear; - if (event->modifiers() & Qt::ControlModifier) - composingSelMode = SMAdd; - else if (event->modifiers() & Qt::ShiftModifier) - composingSelMode = SMSub; - - if (event->modifiers() & Qt::AltModifier) - selectFrontFlag = true; - else - selectFrontFlag = false; - start = QTLogicalToOpenGL(gla, event->pos()); cur = start; - return; + + if (ctrlState && (!(event->modifiers() & Qt::ControlModifier) || (event->modifiers() & Qt::ShiftModifier))) { + for (CMeshO::FaceIterator fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi) { + if (!(*fi).IsD() && (*fi).IsS()) { + LastSelFace.push_back(&*fi); + } + } + + for (CMeshO::VertexIterator vi = m.cm.vert.begin(); vi != m.cm.vert.end(); ++vi) { + if (!(*vi).IsD() && (*vi).IsS()) { + LastSelVert.push_back(&*vi); + } + } + } } -void EditSelectPlugin::mouseMoveEvent(QMouseEvent * event, MeshModel & /*m*/, GLArea * gla) +void EditSelectPlugin::mouseMoveEvent(QMouseEvent * event, MeshModel &m, GLArea * gla) { if (selectionMode == SELECT_AREA_MODE) { @@ -367,7 +480,7 @@ void EditSelectPlugin::mouseMoveEvent(QMouseEvent * event, MeshModel & /*m*/, GL // } } -void EditSelectPlugin::mouseReleaseEvent(QMouseEvent * event, MeshModel &/*m*/, GLArea * gla) +void EditSelectPlugin::mouseReleaseEvent(QMouseEvent * event, MeshModel &m, GLArea * gla) { //gla->update(); if (gla == NULL) @@ -481,12 +594,13 @@ void EditSelectPlugin::DrawXORRect(GLArea * gla, bool doubleDraw) void EditSelectPlugin::decorate(MeshModel &m, GLArea * gla) { + bool ctrlState = currentGlobalParamSet->getBool("MeshLab::Editors::InvertCTRLBehavior"); if (selectionMode == SELECT_AREA_MODE) { // get proj data of last rendering glPushMatrix(); glMultMatrix(m.cm.Tr); - GLPickTri::glGetMatrixAndViewport(this->SelMatrix, this->SelViewport); + GLPickTri::glGetMatrixAndViewport(this->SelMatrix, this->SelViewport); glGetDoublev(GL_MODELVIEW_MATRIX, mvMatrix_f); glGetDoublev(GL_PROJECTION_MATRIX, prMatrix_f); glGetIntegerv(GL_VIEWPORT, viewpSize); @@ -522,16 +636,30 @@ void EditSelectPlugin::decorate(MeshModel &m, GLArea * gla) } else { - QString line1, line2, line3; + if (ctrlState){ + QString line1, line2, line3; - line1 = "Drag to select"; - if ((selectionMode == SELECT_FACE_MODE) || (selectionMode == SELECT_CONN_MODE)) - line2 = "you may hold:
- CTRL to add
- SHIFT to subtract
- ALT to select only visible"; - else + line1 = "Drag to select"; + if ((selectionMode == SELECT_FACE_MODE) || (selectionMode == SELECT_CONN_MODE)) + line2 = "you may hold:
- CTRL to NEW selection
- SHIFT to subtract
- ALT to select only visible"; + else + line2 = "you may hold:
- CTRL to NEW selection
- SHIFT to subtract"; + line3 = "
A select all, D de-select all, I invert all"; + + this->realTimeLog("Interactive Selection", m.shortName(), "%s
%s
%s", line1.toStdString().c_str(), line2.toStdString().c_str(), line3.toStdString().c_str()); + } + else{ + QString line1, line2, line3; + + line1 = "Drag to select"; + if ((selectionMode == SELECT_FACE_MODE) || (selectionMode == SELECT_CONN_MODE)) + line2 = "you may hold:
- CTRL to add
- SHIFT to subtract
- ALT to select only visible"; + else line2 = "you may hold:
- CTRL to add
- SHIFT to subtract"; - line3 = "
A select all, D de-select all, I invert all"; + line3 = "
A select all, D de-select all, I invert all"; - this->realTimeLog("Interactive Selection", m.shortName(), "%s
%s
%s", line1.toStdString().c_str(), line2.toStdString().c_str(), line3.toStdString().c_str()); + this->realTimeLog("Interactive Selection", m.shortName(), "%s
%s
%s", line1.toStdString().c_str(), line2.toStdString().c_str(), line3.toStdString().c_str()); + } } if (isDragging) @@ -629,11 +757,17 @@ void EditSelectPlugin::decorate(MeshModel &m, GLArea * gla) bool EditSelectPlugin::startEdit(MeshModel & m, GLArea * gla, MLSceneGLSharedDataContext* /*cont*/) { + bool ctrlState = currentGlobalParamSet->getBool("MeshLab::Editors::InvertCTRLBehavior"); if (gla == NULL) return false; if (!GLExtensionsManager::initializeGLextensions_notThrowing()) return false; + if (ctrlState){ + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"), 1, 1)); + } + else{ gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"), 1, 1)); + } if (selectionMode == SELECT_AREA_MODE) { diff --git a/src/meshlabplugins/edit_select/edit_select.h b/src/meshlabplugins/edit_select/edit_select.h index a5993dbcae..1a4497509a 100644 --- a/src/meshlabplugins/edit_select/edit_select.h +++ b/src/meshlabplugins/edit_select/edit_select.h @@ -24,29 +24,30 @@ #define EDITPLUGIN_H #include +#include class EditSelectPlugin : public QObject, public EditTool { Q_OBJECT - public: - enum { SELECT_FACE_MODE, SELECT_VERT_MODE, SELECT_CONN_MODE, SELECT_AREA_MODE }; - EditSelectPlugin(int _ConnectedMode); + enum { SELECT_FACE_MODE, SELECT_VERT_MODE, SELECT_CONN_MODE, SELECT_AREA_MODE }; + EditSelectPlugin(RichParameterList* cgp, int _ConnectedMode); virtual ~EditSelectPlugin() {} - static QString info(); void suggestedRenderingData(MeshModel & m, MLRenderingData& dt); bool startEdit(MeshModel &/*m*/, GLArea * /*parent*/, MLSceneGLSharedDataContext* /*cont*/); void endEdit(MeshModel &/*m*/, GLArea * /*parent*/, MLSceneGLSharedDataContext* /*cont*/) {} void decorate(MeshModel &/*m*/, GLArea * /*parent*/); - void mousePressEvent(QMouseEvent *event, MeshModel &/*m*/, GLArea *); - void mouseMoveEvent(QMouseEvent *event, MeshModel &/*m*/, GLArea *); - void mouseReleaseEvent(QMouseEvent *event, MeshModel &/*m*/, GLArea *); - void keyReleaseEvent(QKeyEvent *, MeshModel &/*m*/, GLArea *); - void keyPressEvent(QKeyEvent *, MeshModel &/*m*/, GLArea *); + void mousePressEvent(QMouseEvent *event, MeshModel &/*m*/, GLArea *gla); + void mouseMoveEvent(QMouseEvent *event, MeshModel &/*m*/, GLArea *gla); + void mouseReleaseEvent(QMouseEvent *event, MeshModel &/*m*/, GLArea *gla); + virtual void keyReleaseEvent(QKeyEvent *, MeshModel &m, GLArea *gla); + void keyPressEvent(QKeyEvent *, MeshModel &m, GLArea *gla); + EditTool* getEditTool(const QAction *action); + bool keyReleaseEventFilter(QObject *obj, QEvent *event); vcg::Point2f start; vcg::Point2f cur; @@ -71,12 +72,17 @@ class EditSelectPlugin : public QObject, public EditTool void setDecorator(QString, bool); private: + MeshModel *m_ref; + GLArea *gla_ref; + RichParameterList* currentGlobalParamSet; + bool ctrlState; typedef enum { SMAdd, SMClear, SMSub } ComposingSelMode; // How the selection are composed ComposingSelMode composingSelMode; bool selectFrontFlag; void DrawXORRect(GLArea * gla, bool doubleDraw); void DrawXORPolyLine(GLArea * gla); void doSelection(MeshModel &m, GLArea *gla, int mode); + }; #endif diff --git a/src/meshlabplugins/edit_select/edit_select_factory.cpp b/src/meshlabplugins/edit_select/edit_select_factory.cpp index be743ddce7..c3b16299f6 100644 --- a/src/meshlabplugins/edit_select/edit_select_factory.cpp +++ b/src/meshlabplugins/edit_select/edit_select_factory.cpp @@ -23,6 +23,7 @@ #include "edit_select_factory.h" #include "edit_select.h" +#include "common/parameters/rich_parameter_list.h" EditSelectFactory::EditSelectFactory() { @@ -37,7 +38,10 @@ EditSelectFactory::EditSelectFactory() actionList.push_back(editSelectArea); foreach(QAction *editAction, actionList) - editAction->setCheckable(true); + editAction->setCheckable(true); +} +void EditSelectFactory::initGlobalParameterList(RichParameterList& defaultGlobalParamSet) { + defaultGlobalParamSet.addParam(RichBool(InvertCtrlBehavior(), false,"Invert the behavior of the CTRL modifier on edit selection rectangle tools","")); } QString EditSelectFactory::pluginName() const @@ -48,17 +52,21 @@ QString EditSelectFactory::pluginName() const //get the edit tool for the given action EditTool* EditSelectFactory::getEditTool(const QAction *action) { + EditSelectPlugin* result = nullptr; if(action == editSelect) - return new EditSelectPlugin(EditSelectPlugin::SELECT_FACE_MODE); + result = new EditSelectPlugin(currentGlobalParamSet,EditSelectPlugin::SELECT_FACE_MODE); else if(action == editSelectConnected) - return new EditSelectPlugin(EditSelectPlugin::SELECT_CONN_MODE); + result = new EditSelectPlugin(currentGlobalParamSet,EditSelectPlugin::SELECT_CONN_MODE); else if(action == editSelectVert) - return new EditSelectPlugin(EditSelectPlugin::SELECT_VERT_MODE); + result = new EditSelectPlugin(currentGlobalParamSet,EditSelectPlugin::SELECT_VERT_MODE); else if (action == editSelectArea) - return new EditSelectPlugin(EditSelectPlugin::SELECT_AREA_MODE); + result = new EditSelectPlugin(currentGlobalParamSet,EditSelectPlugin::SELECT_AREA_MODE); + + if (result == nullptr) { + assert(0); + } - assert(0); //should never be asked for an action that isn't here - return nullptr; + return (EditTool*)result; } QString EditSelectFactory::getEditToolDescription(const QAction * /*a*/) diff --git a/src/meshlabplugins/edit_select/edit_select_factory.h b/src/meshlabplugins/edit_select/edit_select_factory.h index 46497cab37..71442dbe68 100644 --- a/src/meshlabplugins/edit_select/edit_select_factory.h +++ b/src/meshlabplugins/edit_select/edit_select_factory.h @@ -26,6 +26,7 @@ #define EditSelectFactoryPLUGIN_H #include +#include "common/parameters/rich_parameter_list.h" class EditSelectFactory : public QObject, public EditPlugin { @@ -37,6 +38,8 @@ class EditSelectFactory : public QObject, public EditPlugin EditSelectFactory(); virtual ~EditSelectFactory() { delete editSelect; } + virtual void initGlobalParameterList(RichParameterList& defaultGlobalParamSet); + virtual QString pluginName() const; //get the edit tool for the given action @@ -45,7 +48,13 @@ class EditSelectFactory : public QObject, public EditPlugin //get the description for the given action virtual QString getEditToolDescription(const QAction*); + inline QString InvertCtrlBehavior() const { return "MeshLab::Editors::InvertCTRLBehavior" ; } + +signals: + void setDecorator(QString, bool); + private: + bool ctrlState; QAction *editSelect; QAction *editSelectVert; QAction *editSelectConnected;