Commit bd93a5ea authored by Mike Kremer's avatar Mike Kremer

Changed structure of information handling:

From now on, it is necessary to implement an info plugin for each specific data type. This plugin has to override InformationInterface in order to provide information on a clicked object.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@11425 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 6a38f534
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 11147 $ *
* $LastChangedBy: kremer $ *
* $Date: 2011-03-16 16:01:09 +0100 (Wed, 16 Mar 2011) $ *
* *
\*===========================================================================*/
#ifndef INFORMATIONINTERFACE_HH_
#define INFORMATIONINTERFACE_HH_
#include <OpenFlipper/common/Types.hh>
/** \file InformationInterface.hh
*
* Interface that provides means to
* get information on specific data types in OpenFlipper. \ref informationInterfacePage
*/
/** \brief Interface class for providing information on objects
*
* \n
* \ref informationInterfacePage "Detailed description"
* \n
*
*/
class InformationInterface {
public:
/// Default destructor
virtual ~InformationInterface() {};
public slots:
/** \brief Get data type for information requests
*
* This slot is called by the core in order to identify
* the data types for which the plugin provides information.
*
* @return The supported data types (OR'ed in case of multiple types)
*/
virtual DataType supportedDataTypes() = 0;
/** \brief Show information dialog on clicked object
*
* This slot is called each time the user clicks on an object.
* The information plugin for a specific type should display
* the necessary information on all entity types and the clicked
* object itself.
*
* @param _clickedPoint The 2D point in screen coords, which the user has clicked
* @param _type Data type to be registered
*/
virtual void slotInformationRequested(const QPoint _clickedPoint, DataType _type) = 0;
};
/** \page informationInterfacePage Information Interface
\n
\image html informationInterface.png
\n
Derive from the information interface in order to provide information
on objects of a specific data type. To clarify this, we will give a short
example. Assuming we want to provide information on all mesh objects
(namely objects of type DATA_TRIANGLE_MESH and DATA_POLY_MESH).
In our plugin, we first have to override the slot that fetches the
supported data types:
\code
DataType MyInfoPlugin::supportedDataTypes() {
return DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH);
}
\endcode
It's as simple as that. Now, each time an object is clicked in
identifier mode, slot slotInformationRequested() is called.
We ovveride this slot in order to do the actual picking
and displaying the gathered information in a dialog box:
\code
void MyInfoPlugin::slotInformationRequested(const QPoint _clickedPoint, const DataType _type) {
// We only respond to requests for our data type
if((_type != DATA_TRIANGLE_MESH) && (_type != DATA_POLY_MESH)) return;
// Do the picking...
// Display dialog box with all the information...
}
\endcode
*/
Q_DECLARE_INTERFACE(InformationInterface,"OpenFlipper.InformationInterface/1.0")
#endif /* INFORMATIONINTERFACE_HH_ */
......@@ -85,17 +85,6 @@ class MouseInterface {
* @param _event Mousevent
*/
virtual void slotMouseEvent( QMouseEvent* _event ) {};
/** \brief Mouse Event from Main App ( Identify Mode )
*
* This slot is called if a mouse event occured in the Viewer
* This slot will only get called in identifyMode.
* Right button clicks will not be passed to the plugins as this is reserved for
* the context Menu.
*
* @param _event Mousevent
*/
virtual void slotMouseEventIdentify( QMouseEvent* _event ) {};
/** \brief Mouse Event from Main App ( Light Mode )
*
......@@ -129,7 +118,6 @@ There are 4 main viewer modes:
inside the viewers.
<li> <b>Picking Mode</b> events where passed through the MouseInterface::slotMouseEvent() and MouseInterface::slotMouseWheelEvent().
<li> <b>Light Mode</b> events where passed through the MouseInterface::slotMouseEventLight()
<li> <b>Identify Mode</b> events where passed through the MouseInterface::slotMouseEventIdentify()
</ul>
You can add handlers for these mouse events in your plugin. Remember that all plugins receive these signals.\n
......
......@@ -645,6 +645,9 @@ Core::slotMouseEventIdentify( QMouseEvent* _event )
// if ( _event->button() == Qt::RightButton )
// return;
// Only catch left-button clicks
if(_event->button() != Qt::LeftButton) return;
const QObject* senderPointer = sender();
unsigned int examinerId = 0;
......@@ -664,9 +667,22 @@ Core::slotMouseEventIdentify( QMouseEvent* _event )
PluginFunctions::setActiveExaminer( examinerId );
emit PluginMouseEventIdentify( _event );
// Do picking
unsigned int node_idx, target_idx;
ACG::Vec3d hit_point;
if(PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_ANYTHING, _event->pos(), node_idx, target_idx, &hit_point)) {
BaseObjectData* object = 0;
if(PluginFunctions::getPickedObject(node_idx, object)) {
// Request type information widget
InformationInterface* infoPlugin = 0;
infoPlugin = getInfoPlugin(object->dataType());
if(infoPlugin != 0)
infoPlugin->slotInformationRequested(_event->pos(), object->dataType());
}
}
}
//-----------------------------------------------------------------------------
......
......@@ -95,6 +95,7 @@
#include "OpenFlipper/BasePlugin/FileInterface.hh"
#include "OpenFlipper/BasePlugin/TypeInterface.hh"
#include "OpenFlipper/BasePlugin/MenuInterface.hh"
#include "OpenFlipper/BasePlugin/InformationInterface.hh"
#include "OpenFlipper/BasePlugin/SelectionInterface.hh" // -> for SelectionInterface::PrimitiveType
#include "OpenFlipper/BasePlugin/ContextMenuInterface.hh"
......@@ -112,6 +113,7 @@
#include <OpenFlipper/threads/JobInfo.hh>
#include <OpenFlipper/common/FileTypes.hh>
#include <OpenFlipper/common/InformationPlugins.hh>
//== CLASS DEFINITION =========================================================
......@@ -172,9 +174,6 @@ signals:
/// When this Signal is emitted when a Mouse Event occures
void PluginMouseEvent(QMouseEvent* );
/// Emitted when an identify event occurs
void PluginMouseEventIdentify( QMouseEvent* );
/// Emitted when an light event occurs
void PluginMouseEventLight( QMouseEvent* );
......
......@@ -940,16 +940,21 @@ void Core::loadPlugin(QString filename, bool silent, QString& _licenseErrors, QO
connect(this , SIGNAL(PluginMouseEvent(QMouseEvent*)),
plugin , SLOT(slotMouseEvent(QMouseEvent*)));
if ( checkSlot( plugin , "slotMouseEventIdentify(QMouseEvent*)" ) )
connect(this , SIGNAL(PluginMouseEventIdentify(QMouseEvent*)),
plugin , SLOT(slotMouseEventIdentify(QMouseEvent*)));
if ( checkSlot( plugin , "slotMouseEventLight(QMouseEvent*)" ) )
connect(this , SIGNAL(PluginMouseEventLight(QMouseEvent*)),
plugin , SLOT(slotMouseEventLight(QMouseEvent*)));
}
//Check if the plugin supports InformationInterface
InformationInterface* infoPlugin = qobject_cast< InformationInterface * >(plugin);
if ( infoPlugin && OpenFlipper::Options::gui() ) {
supported = supported + "TypeInformation ";
DataType dtype = infoPlugin->supportedDataTypes();
supportedInfoTypes().insert(std::pair<InformationInterface*,DataType>(infoPlugin,dtype));
}
//Check if the plugin supports Picking-Interface
PickingInterface* pickPlugin = qobject_cast< PickingInterface * >(plugin);
if ( pickPlugin && OpenFlipper::Options::gui() ) {
......
......@@ -154,6 +154,11 @@ can use this interface to react on selection events and add selections for diffe
Allows plugins to specify custom data types and makes them available
to other plugins ( \ref typeInterfacePage ).
\subpage informationInterfacePage
\image html informationInterface.png
Allows plugins to provide information on objects of a
specific data type ( \ref informationInterfacePage ).
*/
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 11209 $ *
* $LastChangedBy: kremer $ *
* $Date: 2011-03-24 18:02:29 +0100 (Thu, 24 Mar 2011) $ *
* *
\*===========================================================================*/
#include <OpenFlipper/common/InformationPlugins.hh>
static std::map<InformationInterface*,DataType> supportedInfoTypes_;
std::map<InformationInterface*,DataType>&
supportedInfoTypes() {
return supportedInfoTypes_;
}
InformationInterface* getInfoPlugin(DataType _type) {
for(std::map<InformationInterface*,DataType>::iterator it = supportedInfoTypes_.begin();
it != supportedInfoTypes_.end(); ++it) {
if((it->second & _type) != 0) return it->first;
}
return 0;
}
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 11209 $ *
* $LastChangedBy: kremer $ *
* $Date: 2011-03-24 18:02:29 +0100 (Thu, 24 Mar 2011) $ *
* *
\*===========================================================================*/
#ifndef INFORMATIONPLUGINS_HH_
#define INFORMATIONPLUGINS_HH_
#include <OpenFlipper/BasePlugin/InformationInterface.hh>
#include <OpenFlipper/common/DataTypes.hh>
#include <map>
// Get vector of supported types
DLLEXPORT
std::map<InformationInterface*,DataType>&
supportedInfoTypes();
// Test if information plugin is available for a specific
// data type
DLLEXPORT
InformationInterface*
getInfoPlugin(DataType _type);
#endif /* INFORMATIONPLUGINS_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