From bc614da393c7b3647c9d6a344db771ea06f6d75e Mon Sep 17 00:00:00 2001 From: Hans-Christian Ebke <ebke@cs.rwth-aachen.de> Date: Thu, 19 Jul 2012 07:59:59 +0000 Subject: [PATCH] Added context menu item to copy material to targeted objects. git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15071 383ad7c9-94d9-4d36-a494-682f7c89f535 --- DataControlPlugin.cc | 5 +++- DataControlPlugin.hh | 3 +++ Popup.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/DataControlPlugin.cc b/DataControlPlugin.cc index 71978f3..8fca44c 100644 --- a/DataControlPlugin.cc +++ b/DataControlPlugin.cc @@ -147,9 +147,12 @@ void DataControlPlugin::pluginsInitialized() { icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-material.png"); QAction* material = new QAction(icon, tr("Material Properties"), 0); connect (material, SIGNAL( triggered() ), this, SLOT ( slotMaterialProperties() )); - emit addContextMenuItem(material , DATA_ALL , CONTEXTOBJECTMENU); + QAction* copyMaterial = new QAction(tr("Copy Material Properties to Targeted Objects"), 0); + connect (copyMaterial, SIGNAL( triggered() ), this, SLOT ( slotCopyMaterialToTargeted() )); + emit addContextMenuItem(copyMaterial , DATA_ALL , CONTEXTOBJECTMENU); + PluginFunctions::setDefaultViewObjectMarker (&objectMarker); PluginFunctions::setViewObjectMarker (&objectMarker); diff --git a/DataControlPlugin.hh b/DataControlPlugin.hh index 7fe4a06..e75c7ab 100644 --- a/DataControlPlugin.hh +++ b/DataControlPlugin.hh @@ -224,6 +224,9 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn ///Called by the popup menu to set material properties void slotMaterialProperties(); + ///Called by the popup menu to copy material properties + void slotCopyMaterialToTargeted(); + /** \brief Called when the material properties were changed inside the material dialog * * @param _node unused diff --git a/Popup.cc b/Popup.cc index 5c44fc3..24aa452 100644 --- a/Popup.cc +++ b/Popup.cc @@ -319,16 +319,23 @@ void DataControlPlugin::slotCustomContextMenuRequested ( const QPoint & _pos ) { action = menu.addAction(tr("Zoom to object"),this,SLOT ( slotZoomTo() )); icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"zoom-in.png"); action->setIcon(icon); + action = menu.addAction(tr("Copy"),this,SLOT ( slotCopy() )); icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-copy.png"); action->setIcon(icon); + action = menu.addAction(tr("Rename"),this,SLOT ( slotRename() )); icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-rename.png"); action->setIcon(icon); + action = menu.addAction(tr("Material Properties"),this,SLOT ( slotMaterialProperties() )); icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-material.png"); action->setIcon(icon); + + menu.addAction(tr("Copy Material Properties to Targeted Objects"), this, SLOT ( slotCopyMaterialToTargeted() )); + menu.addAction(tr("Group"),this,SLOT ( slotGroup() )); + menu.addSeparator(); action = menu.addAction(tr("Remove"),this,SLOT ( slotPopupRemove() )); icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"datacontrol-delete-item.png"); @@ -482,6 +489,54 @@ void DataControlPlugin::slotRename(){ /** \brief show the material properties dialog * */ +void DataControlPlugin::slotCopyMaterialToTargeted() { + BaseObject* item = 0; + + //check if it was called from object contextMenu or from the toolBox + QAction* action = dynamic_cast< QAction* > ( sender() ); + + if ( action ){ + bool ok = false; + + int id = action->data().toInt(&ok); + + if ( ok && id > 0 ) + PluginFunctions::getObject(id,item); + } + + if ( item == 0 ){ + // the slot was called from toolbox + QItemSelectionModel* selection = view_->selectionModel(); + + // Get all selected rows + QModelIndexList indexList = selection->selectedRows ( 0 ); + int selectedRows = indexList.size(); + if (selectedRows == 1){ + int id = model_->itemId( indexList[0] ); + + if ( id > 0 ) + PluginFunctions::getObject(id,item); + } + } + + if ( item != 0 ){ + + BaseObjectData* itemData = dynamic_cast< BaseObjectData* > (item); + const ACG::SceneGraph::Material &sourceMaterial = itemData->materialNode()->material(); + + for (PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS); + o_it != PluginFunctions::objectsEnd(); ++o_it) { + + MaterialNode * const materialNode = o_it->materialNode(); + if (materialNode) { + materialNode->material() = sourceMaterial; + } + } + + emit updateView(); + } +} + void DataControlPlugin::slotMaterialProperties(){ BaseObject* item = 0; -- GitLab