Commit 46fa1d5c authored by Jan Möbius's avatar Jan Möbius
Browse files

Added the plugin collection for selection



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15691 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 47b37ecd
#include "BSplineCurveSelectionPlugin.hh"
void BSplineCurveSelectionPlugin::selectAllControlPoints(int _objectId) {
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
BSplineCurveObject* co = PluginFunctions::bsplineCurveObject(object);
if(curve) {
for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
curve->select_controlpoint(i);
}
}
// Switch to control point selection mode
if(co)
co->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::CONTROLPOINT);
emit scriptInfo("selectAllControlPoints(ObjectId)");
}
void BSplineCurveSelectionPlugin::deselectAllControlPoints(int _objectId) {
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
if(curve) {
for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
curve->deselect_controlpoint(i);
}
}
emit scriptInfo("deselectAllControlPoints(ObjectId)");
}
void BSplineCurveSelectionPlugin::invertControlPointSelection(int _objectId) {
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
BSplineCurveObject* co = PluginFunctions::bsplineCurveObject(object);
if(curve) {
for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
if(curve->controlpoint_selected(i))
curve->deselect_controlpoint(i);
else
curve->select_controlpoint(i);
}
}
// Switch to control point selection mode
if(co)
co->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::CONTROLPOINT);
emit scriptInfo("invertControlPointSelection(ObjectId)");
}
void BSplineCurveSelectionPlugin::deleteSelectedControlPoints(int _objectId) {
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
if(curve) {
// I know this is a bit crappy, but control point indices
// change forcably after each delete operation so we have to
// start over each time...
bool breakWhile = false;
while(!breakWhile) {
bool oneFound = false;
unsigned int i = 0;
for(; i < curve->n_control_points(); ++i) {
if(curve->controlpoint_selected(i)) {
curve->delete_control_point(i);
oneFound = true;
break;
}
}
if((i >= curve->n_control_points()) && !oneFound) {
// We are through
breakWhile = true;
}
}
}
emit scriptInfo("deleteSelectedControlPoints(ObjectId)");
}
void BSplineCurveSelectionPlugin::selectControlPoints(int _objectId, const IdList& _ids, bool _deselect) {
if( _ids.empty()) return;
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
if(curve) {
for(IdList::const_iterator it = _ids.begin(); it != _ids.end(); ++it) {
if(*it < (int)curve->n_control_points()) {
if(_deselect) curve->deselect_controlpoint(*it);
else curve->select_controlpoint(*it);
}
}
}
QString selection = "selectControlPoints(ObjectId, [ " + QString::number(_ids[0]);
for (uint i = 1 ; i < _ids.size(); ++i) {
selection += ", " + QString::number(_ids[i]);
}
selection += " ])";
emit scriptInfo(selection);
}
IdList BSplineCurveSelectionPlugin::getControlPointSelection(int _objectId) {
BaseObjectData* object = 0;
IdList list;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return list;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
if(curve) {
for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
if(curve->controlpoint_selected(i))
list.push_back((int)i);
}
}
return list;
}
//=====================================================================
void BSplineCurveSelectionPlugin::selectAllKnots(int _objectId) {
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
BSplineCurveObject* co = PluginFunctions::bsplineCurveObject(object);
if(curve) {
for(unsigned int i = 0; i < curve->n_knots(); ++i) {
curve->get_knotvector_ref()->select(i);
}
}
// Switch to control point selection mode
if(co)
co->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::KNOTVECTOR);
emit scriptInfo("selectAllKnots(ObjectId)");
}
void BSplineCurveSelectionPlugin::deselectAllKnots(int _objectId) {
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
if(curve) {
for(unsigned int i = 0; i < curve->n_knots(); ++i) {
curve->get_knotvector_ref()->deselect(i);
}
}
emit scriptInfo("deselectAllKnots(ObjectId)");
}
void BSplineCurveSelectionPlugin::invertKnotSelection(int _objectId) {
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
BSplineCurveObject* co = PluginFunctions::bsplineCurveObject(object);
if(curve) {
for(unsigned int i = 0; i < curve->n_knots(); ++i) {
if(curve->get_knotvector_ref()->selected(i))
curve->get_knotvector_ref()->deselect(i);
else
curve->get_knotvector_ref()->select(i);
}
}
// Switch to control point selection mode
if(co)
co->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::KNOTVECTOR);
emit scriptInfo("invertKnotSelection(ObjectId)");
}
void BSplineCurveSelectionPlugin::deleteSelectedKnots(int _objectId) {
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
if(curve) {
// I know this is a bit crappy, but knot indices
// change forcably after each delete operation so we have to
// start over each time...
bool breakWhile = false;
while(!breakWhile) {
bool oneFound = false;
unsigned int i = 0;
for(; i < curve->n_knots(); ++i) {
if(curve->get_knotvector_ref()->selected(i)) {
curve->get_knotvector_ref()->deleteKnot(i);
oneFound = true;
break;
}
}
if((i >= curve->n_knots()) && !oneFound) {
// We are through
breakWhile = true;
}
}
}
emit scriptInfo("deleteSelectedKnots(ObjectId)");
}
void BSplineCurveSelectionPlugin::selectKnots(int _objectId, const IdList& _ids, bool _deselect) {
if(_ids.empty()) return;
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
if(curve) {
for(IdList::const_iterator it = _ids.begin(); it != _ids.end(); ++it) {
if(*it < (int)curve->n_knots()) {
if(_deselect) curve->get_knotvector_ref()->deselect(*it);
else curve->get_knotvector_ref()->select(*it);
}
}
}
QString selection = "selectKnots(ObjectId, [ " + QString::number(_ids[0]);
for (uint i = 1 ; i < _ids.size(); ++i) {
selection += ", " + QString::number(_ids[i]);
}
selection += " ])";
emit scriptInfo(selection);
}
IdList BSplineCurveSelectionPlugin::getKnotSelection(int _objectId) {
BaseObjectData* object = 0;
IdList list;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return list;
}
BSplineCurve* curve = PluginFunctions::splineCurve(object);
if(curve) {
for(unsigned int i = 0; i < curve->n_knots(); ++i) {
if(curve->get_knotvector_ref()->selected(i))
list.push_back((int)i);
}
}
return list;
}
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2010 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$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
#ifndef BSPLINECURVESELECTIONPLUGIN_HH
#define BSPLINECURVESELECTIONPLUGIN_HH
#include <QObject>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/BasePlugin/INIInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/SelectionInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/INIFile/INIFile.hh>
#include <ObjectTypes/BSplineCurve/BSplineCurve.hh>
class BSplineCurveSelectionPlugin : public QObject, BaseInterface, KeyInterface,
INIInterface, BackupInterface, LoggingInterface, ScriptInterface, SelectionInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(KeyInterface)
Q_INTERFACES(INIInterface)
Q_INTERFACES(BackupInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(ScriptInterface)
Q_INTERFACES(SelectionInterface)
public:
/// Default constructor
BSplineCurveSelectionPlugin();
/// Default destructor
~BSplineCurveSelectionPlugin();
signals:
// BaseInterface
void updateView();
void updatedObject(int, const UpdateType&);
void nodeVisibilityChanged(int _identifier);
void setSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
// BackupInterface
void createBackup( int _objectid, QString _name, UpdateType _type = UPDATE_ALL);
// LoggingInterface
void log(Logtype _type, QString _message);
void log(QString _message);
// ScriptInterface
void scriptInfo(QString _functionName);
// SelectionInterface
void addSelectionEnvironment(QString _modeName, QString _description, QIcon _icon, QString& _handleName);
void registerType(QString _handleName, DataType _type);
void addPrimitiveType(QString _handleName, QString _name, QIcon _icon, SelectionInterface::PrimitiveType& _typeHandle);
void addSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type = 0u);
void showToggleSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
void showVolumeLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
void getActiveDataTypes(SelectionInterface::TypeList& _types);
void getActivePrimitiveType(SelectionInterface::PrimitiveType& _type);
void targetObjectsOnly(bool& _targetsOnly);
void registerKeyShortcut(int _key, Qt::KeyboardModifiers _modifiers = Qt::NoModifier);
private slots:
// INIInterface
void loadIniFile(INIFile& _ini, int _id);
void saveIniFile(INIFile& _ini, int _id);
// BaseInterface
void initializePlugin();
void pluginsInitialized();
void noguiSupported() {};
// SelectionInterface
void slotSelectionOperation(QString _operation);
void slotToggleSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
void slotVolumeLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
void slotLoadSelection(const INIFile& _file);
void slotSaveSelection(INIFile& _file);
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers);
public slots:
// SelectionInterface
void loadSelection(int _objId, const QString& _filename);
public:
// BaseInterface
QString name() {
return (QString(tr("BSplineCurve Selection")));
};
QString description() {
return (QString(tr("Allows to select B-Spline curves")));
};
//===========================================================================
/** @name Private methods
* @{ */
//===========================================================================
private:
enum SelectionViewMode {CP, K};
/// Change selection view mode for every B-spline curve in the scene
void setSelectionViewMode(const SelectionViewMode _mode);
/// Set slot descriptions for scripting functions
void updateSlotDescriptions();
/** @} */
public slots:
QString version() {
return QString("1.0");
};
//===========================================================================
/** @name Scriptable slots
* @{ */
//===========================================================================
// Control point selection:
/// Select all control points of a curve
void selectAllControlPoints(int _objectId);
/// Deselect all control points of a curve
void deselectAllControlPoints(int _objectId);
/// Invert control point selection
void invertControlPointSelection(int _objectId);
/// Delete selected control points
void deleteSelectedControlPoints(int _objectId);
/// Select specific control points of a curve
void selectControlPoints(int _objectId, const IdList& _ids, bool _deselect = false);
/// Get current control point selection
IdList getControlPointSelection(int _objectId);
// Knot selection:
/// Select all knots of a curve
void selectAllKnots(int _objectId);
/// Deselect all knots of a curve
void deselectAllKnots(int _objectId);
/// Invert knot selection
void invertKnotSelection(int _objectId);
/// Delete selected knots
void deleteSelectedKnots(int _objectId);
/// Select specific knots of a curve
void selectKnots(int _objectId, const IdList& _ids, bool _deselect = false);
/// Get current knot selection
IdList getKnotSelection(int _objectId);
/** @} */
//===========================================================================
/** @name Member variables
* @{ */
//===========================================================================
private:
/// Handle to selection environment
QString environmentHandle_;