Commit 4fd29369 authored by Mike Kremer's avatar Mike Kremer
Browse files

Allow selection plugins to restrict its selection metaphors to specified data...

Allow selection plugins to restrict its selection metaphors to specified data types (or all if none is given).

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14971 383ad7c9-94d9-4d36-a494-682f7c89f535
parent fb394e17
...@@ -258,6 +258,9 @@ signals: ...@@ -258,6 +258,9 @@ signals:
/// SelectionInterface: This signal is emitted when a custom selection mode is added /// SelectionInterface: This signal is emitted when a custom selection mode is added
void addCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon, void addCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon,
SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier); SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier);
void addCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon,
SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier,
DataType _objectTypeRestriction);
/// SelectionInterface: This signal is used to add non-interactive operations for a specific primitive type /// SelectionInterface: This signal is used to add non-interactive operations for a specific primitive type
void addSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type); void addSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type);
...@@ -501,6 +504,9 @@ signals: ...@@ -501,6 +504,9 @@ signals:
/// SelectionInterface: Add new selection mode for specified type /// SelectionInterface: Add new selection mode for specified type
void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon, void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon,
SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier); SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier);
void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon,
SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier,
DataType _objectTypeRestriction);
/// SelectionInterface: Called in order to add non-interactive operations for a specific primitive type /// SelectionInterface: Called in order to add non-interactive operations for a specific primitive type
void slotAddSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type); void slotAddSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type);
......
...@@ -1251,9 +1251,17 @@ void Core::loadPlugin(QString filename, bool silent, QString& _licenseErrors, QO ...@@ -1251,9 +1251,17 @@ void Core::loadPlugin(QString filename, bool silent, QString& _licenseErrors, QO
connect(plugin , SIGNAL(addCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&)), connect(plugin , SIGNAL(addCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&)),
this , SLOT(slotAddCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&)),Qt::DirectConnection); this , SLOT(slotAddCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&)),Qt::DirectConnection);
if ( checkSignal(plugin,"addCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&,DataType)") )
connect(plugin , SIGNAL(addCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&,DataType)),
this , SLOT(slotAddCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&,DataType)),Qt::DirectConnection);
if ( checkSlot( plugin , "slotAddCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&)" ) ) if ( checkSlot( plugin , "slotAddCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&)" ) )
connect(this , SIGNAL(addCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&)), connect(this , SIGNAL(addCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&)),
plugin , SLOT(slotAddCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&)),Qt::DirectConnection); plugin , SLOT(slotAddCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&)),Qt::DirectConnection);
if ( checkSlot( plugin , "slotAddCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&,DataType)" ) )
connect(this , SIGNAL(addCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&,DataType)),
plugin , SLOT(slotAddCustomSelectionMode(QString,QString,QString,QIcon,SelectionInterface::PrimitiveType,QString&,DataType)),Qt::DirectConnection);
if ( checkSignal(plugin,"addSelectionOperations(QString,QStringList,QString,SelectionInterface::PrimitiveType)") ) if ( checkSignal(plugin,"addSelectionOperations(QString,QStringList,QString,SelectionInterface::PrimitiveType)") )
connect(plugin , SIGNAL(addSelectionOperations(QString,QStringList,QString,SelectionInterface::PrimitiveType)), connect(plugin , SIGNAL(addSelectionOperations(QString,QStringList,QString,SelectionInterface::PrimitiveType)),
......
...@@ -74,6 +74,12 @@ void Core::slotAddCustomSelectionMode(QString _handleName, QString _modeName, QS ...@@ -74,6 +74,12 @@ void Core::slotAddCustomSelectionMode(QString _handleName, QString _modeName, QS
emit addCustomSelectionMode(_handleName, _modeName, _description, _icon, _associatedTypes, _customIdentifier); emit addCustomSelectionMode(_handleName, _modeName, _description, _icon, _associatedTypes, _customIdentifier);
} }
void Core::slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon,
SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier,
DataType _objectTypeRestriction) {
emit addCustomSelectionMode(_handleName, _modeName, _description, _icon, _associatedTypes, _customIdentifier, _objectTypeRestriction);
}
void Core::slotAddSelectionOperations(QString _handleName,QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type) { void Core::slotAddSelectionOperations(QString _handleName,QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type) {
emit addSelectionOperations(_handleName, _operationsList, _category, _type); emit addSelectionOperations(_handleName, _operationsList, _category, _type);
} }
......
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#ifndef HELPERCLASSES_HH_INCLUDED #ifndef HELPERCLASSES_HH_INCLUDED
#define HELPERCLASSES_HH_INCLUDED #define HELPERCLASSES_HH_INCLUDED
#include <OpenFlipper/common/DataTypes.hh>
#include <QAction> #include <QAction>
#include <QPushButton> #include <QPushButton>
#include <QGridLayout> #include <QGridLayout>
...@@ -51,20 +53,21 @@ class HandleAction : public QAction { ...@@ -51,20 +53,21 @@ class HandleAction : public QAction {
public: public:
/// Default constructor /// Default constructor
HandleAction(QIcon _icon, QString _description, QObject* _parent = 0) : HandleAction(QIcon _icon, QString _description, QObject* _parent = 0, DataType _objectTypeRestriction = DATA_ALL) :
QAction(_icon, _description, _parent), QAction(_icon, _description, _parent),
associatedTypes_(0u) {}; associatedTypes_(0u),
objectTypeRestriction_(_objectTypeRestriction) {}
/// Default destructor /// Default destructor
~HandleAction() {}; ~HandleAction() {}
/// Get/Set selection environment handle name /// Get/Set selection environment handle name
void selectionEnvironmentHandle(QString _handle) { selectionEnvHandle_ = _handle; }; void selectionEnvironmentHandle(QString _handle) { selectionEnvHandle_ = _handle; }
QString selectionEnvironmentHandle() { return selectionEnvHandle_; }; QString selectionEnvironmentHandle() { return selectionEnvHandle_; }
/// Get/Set selection mode handle name /// Get/Set selection mode handle name
void selectionModeHandle(QString _handle) { selectionModeHandle_ = _handle; }; void selectionModeHandle(QString _handle) { selectionModeHandle_ = _handle; }
QString selectionModeHandle() { return selectionModeHandle_; }; QString selectionModeHandle() { return selectionModeHandle_; }
/// Get/Set associated primitive types /// Get/Set associated primitive types
void addAssociatedType(unsigned int _associatedType) { associatedTypes_ |= _associatedType; } void addAssociatedType(unsigned int _associatedType) { associatedTypes_ |= _associatedType; }
...@@ -77,11 +80,21 @@ class HandleAction : public QAction { ...@@ -77,11 +80,21 @@ class HandleAction : public QAction {
return ((associatedTypes_ & _type) != 0); return ((associatedTypes_ & _type) != 0);
} }
void objectTypeRestriction(const DataType& _type) {
objectTypeRestriction_ = _type;
}
const DataType& objectTypeRestriction() const {
return objectTypeRestriction_;
}
private: private:
QString selectionEnvHandle_; QString selectionEnvHandle_;
QString selectionModeHandle_; QString selectionModeHandle_;
unsigned int associatedTypes_; unsigned int associatedTypes_;
DataType objectTypeRestriction_;
}; };
class PrimitiveAction : public QAction { class PrimitiveAction : public QAction {
......
...@@ -100,7 +100,8 @@ sphere_mat_node_(0), ...@@ -100,7 +100,8 @@ sphere_mat_node_(0),
sphere_node_(0), sphere_node_(0),
line_node_(0), line_node_(0),
lassoSelection_(false), lassoSelection_(false),
toolIcon_(0) toolIcon_(0),
availableObjectTypes_(0u)
{ {
// Reset active pick mode // Reset active pick mode
...@@ -460,7 +461,7 @@ void SelectionBasePlugin::slotRegisterType(QString _handleName, DataType _type) ...@@ -460,7 +461,7 @@ void SelectionBasePlugin::slotRegisterType(QString _handleName, DataType _type)
} }
void SelectionBasePlugin::updatePickModeToolBar() { void SelectionBasePlugin::updatePickModeToolBar() {
// Add newly added primitive and tool buttons // Add newly added primitive and tool buttons
QList<QAction*> primitivesList = primitivesBarGroup_->actions(); QList<QAction*> primitivesList = primitivesBarGroup_->actions();
...@@ -492,10 +493,10 @@ void SelectionBasePlugin::updatePickModeToolBar() { ...@@ -492,10 +493,10 @@ void SelectionBasePlugin::updatePickModeToolBar() {
// Only activate those tools, that are available for the current // Only activate those tools, that are available for the current
// active primitive type // active primitive type
for(std::map<QString,SelectionEnvironment>::iterator it = selectionEnvironments_.begin(); for(std::map<QString,SelectionEnvironment>::iterator it = selectionEnvironments_.begin();
it != selectionEnvironments_.end(); ++it) { it != selectionEnvironments_.end(); ++it) {
// Default selection modes // Default selection modes
toggleSelectionAction_->setEnabled(toggleSelectionAction_->isAssociated(currentPrimitiveType_, true)); toggleSelectionAction_->setEnabled(toggleSelectionAction_->isAssociated(currentPrimitiveType_, true));
lassoSelectionAction_->setEnabled(lassoSelectionAction_->isAssociated(currentPrimitiveType_, true)); lassoSelectionAction_->setEnabled(lassoSelectionAction_->isAssociated(currentPrimitiveType_, true));
...@@ -509,10 +510,10 @@ void SelectionBasePlugin::updatePickModeToolBar() { ...@@ -509,10 +510,10 @@ void SelectionBasePlugin::updatePickModeToolBar() {
// Custom selection modes // Custom selection modes
for(std::set<HandleAction*>::iterator cit = (*it).second.customSelectionModes.begin(); for(std::set<HandleAction*>::iterator cit = (*it).second.customSelectionModes.begin();
cit != (*it).second.customSelectionModes.end(); ++cit) { cit != (*it).second.customSelectionModes.end(); ++cit) {
(*cit)->setEnabled((*cit)->isAssociated(currentPrimitiveType_, true));
}
break; (*cit)->setEnabled((availableObjectTypes_ & (*cit)->objectTypeRestriction()) &&
(*cit)->isAssociated(currentPrimitiveType_, true));
}
} }
} }
...@@ -926,7 +927,7 @@ void SelectionBasePlugin::slotPickModeChanged (const std::string& _pickmode) { ...@@ -926,7 +927,7 @@ void SelectionBasePlugin::slotPickModeChanged (const std::string& _pickmode) {
void SelectionBasePlugin::showSelectionMode(QString _mode, QIcon _icon, QString _desc, QString _handleName, void SelectionBasePlugin::showSelectionMode(QString _mode, QIcon _icon, QString _desc, QString _handleName,
bool _show, SelectionInterface::PrimitiveType _associatedTypes, bool _show, SelectionInterface::PrimitiveType _associatedTypes,
QString& _customIdentifier, bool _custom) { QString& _customIdentifier, bool _custom, DataType _objectTypeRestriction) {
// Find selection environment that is associated to _handleName // Find selection environment that is associated to _handleName
std::map<QString,SelectionEnvironment>::iterator it = selectionEnvironments_.find(_handleName); std::map<QString,SelectionEnvironment>::iterator it = selectionEnvironments_.find(_handleName);
...@@ -1031,7 +1032,7 @@ void SelectionBasePlugin::showSelectionMode(QString _mode, QIcon _icon, QString ...@@ -1031,7 +1032,7 @@ void SelectionBasePlugin::showSelectionMode(QString _mode, QIcon _icon, QString
_customIdentifier = getUniqueIdentifierName(QString(_handleName + "_" + _mode).replace(" ", "_")); _customIdentifier = getUniqueIdentifierName(QString(_handleName + "_" + _mode).replace(" ", "_"));
// Create action // Create action
HandleAction* action = new HandleAction(_icon, _desc, selectionModesGroup_); HandleAction* action = new HandleAction(_icon, _desc, selectionModesGroup_, _objectTypeRestriction);
action->setCheckable(true); action->setCheckable(true);
action->selectionEnvironmentHandle(_handleName); action->selectionEnvironmentHandle(_handleName);
action->selectionModeHandle(_customIdentifier); action->selectionModeHandle(_customIdentifier);
...@@ -1076,6 +1077,16 @@ void SelectionBasePlugin::slotAddCustomSelectionMode(QString _handleName, QStrin ...@@ -1076,6 +1077,16 @@ void SelectionBasePlugin::slotAddCustomSelectionMode(QString _handleName, QStrin
//============================================================================================ //============================================================================================
void SelectionBasePlugin::slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon,
SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier,
DataType _objectTypeRestriction) {
showSelectionMode(_modeName, _icon, _description, _handleName, true, _associatedTypes, _customIdentifier, true, _objectTypeRestriction);
updatePickModeToolBar();
}
//============================================================================================
void SelectionBasePlugin::slotShowToggleSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes) { void SelectionBasePlugin::slotShowToggleSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes) {
QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator(); QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
...@@ -1459,6 +1470,10 @@ void SelectionBasePlugin::addedEmptyObject (int _id) { ...@@ -1459,6 +1470,10 @@ void SelectionBasePlugin::addedEmptyObject (int _id) {
if(found) break; if(found) break;
} }
// Keep track of all data types in the scene
availableObjectTypes_ |= obj->dataType();
} else { } else {
BaseObject* bObject = 0; BaseObject* bObject = 0;
PluginFunctions::getObject(_id, bObject); PluginFunctions::getObject(_id, bObject);
...@@ -1519,6 +1534,9 @@ void SelectionBasePlugin::objectDeleted (int _id) { ...@@ -1519,6 +1534,9 @@ void SelectionBasePlugin::objectDeleted (int _id) {
if(found) break; if(found) break;
} }
availableObjectTypes_ = (availableObjectTypes_ & ~obj->dataType().value());
} else { } else {
emit log(LOGERR, "Could not retrieve object type!"); emit log(LOGERR, "Could not retrieve object type!");
return; return;
......
...@@ -157,6 +157,9 @@ Q_INTERFACES(SelectionInterface) ...@@ -157,6 +157,9 @@ Q_INTERFACES(SelectionInterface)
void slotAddPrimitiveType(QString _handleName, QString _name, QIcon _icon, SelectionInterface::PrimitiveType& _typeHandle); void slotAddPrimitiveType(QString _handleName, QString _name, QIcon _icon, SelectionInterface::PrimitiveType& _typeHandle);
void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon, void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon,
SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier); SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier);
void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon,
SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier,
DataType _objectTypeRestriction);
void slotAddSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type = 0u); void slotAddSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type = 0u);
...@@ -258,7 +261,7 @@ Q_INTERFACES(SelectionInterface) ...@@ -258,7 +261,7 @@ Q_INTERFACES(SelectionInterface)
/// Use this method to show/hide standard selection actions (lasso, floodfill, sphere, etc.) /// Use this method to show/hide standard selection actions (lasso, floodfill, sphere, etc.)
void showSelectionMode(QString _mode, QIcon _icon, QString _desc, void showSelectionMode(QString _mode, QIcon _icon, QString _desc,
QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes, QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes,
QString& _customIdentifier, bool _custom = false); QString& _customIdentifier, bool _custom = false, DataType _objectTypeRestriction = DATA_ALL);
/// Create new type frame for tabs widget /// Create new type frame for tabs widget
SelectionTypeFrameWidget* createNewTypeFrame(SelectionEnvironment& _env); SelectionTypeFrameWidget* createNewTypeFrame(SelectionEnvironment& _env);
...@@ -342,6 +345,9 @@ Q_INTERFACES(SelectionInterface) ...@@ -342,6 +345,9 @@ Q_INTERFACES(SelectionInterface)
std::vector<ACG::Vec3d> linePoints_; std::vector<ACG::Vec3d> linePoints_;
QIcon* toolIcon_; QIcon* toolIcon_;
// Keep track of all data types in the scene
DataType availableObjectTypes_;
}; };
#endif // SELECTIONBASEPLUGIN_HH #endif // SELECTIONBASEPLUGIN_HH
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment