Skip to content
Snippets Groups Projects
Commit 9c26e445 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
parents
No related branches found
No related tags found
No related merge requests found
#include "BSplineSurfaceSelectionPlugin.hh"
void BSplineSurfaceSelectionPlugin::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;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
BSplineSurfaceObject* so = PluginFunctions::bsplineSurfaceObject(object);
if(surface) {
for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
surface->select_controlpoint(i, j);
}
}
}
// Switch to control point selection mode
if(so)
so->splineSurfaceNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineSurfaceNodeT<BSplineSurface>::CONTROLPOINT);
emit scriptInfo("selectAllControlPoints(ObjectId)");
}
void BSplineSurfaceSelectionPlugin::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;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
if(surface) {
for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
surface->deselect_controlpoint(i,j);
}
}
}
emit scriptInfo("deselectAllControlPoints(ObjectId)");
}
void BSplineSurfaceSelectionPlugin::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;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
BSplineSurfaceObject* so = PluginFunctions::bsplineSurfaceObject(object);
if(surface) {
for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
if(surface->controlpoint_selected(i,j))
surface->deselect_controlpoint(i,j);
else
surface->select_controlpoint(i,j);
}
}
}
// Switch to control point selection mode
if(so)
so->splineSurfaceNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineSurfaceNodeT<BSplineSurface>::CONTROLPOINT);
emit scriptInfo("invertControlPointSelection(ObjectId)");
}
// void BSplineSurfaceSelectionPlugin::deleteSelectedControlPointsU(int _objectId) {
//
// BaseObjectData* object = 0;
//
// if(!PluginFunctions::getObject(_objectId, object)) {
// emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
// return;
// }
//
// BSplineSurface* surface = PluginFunctions::splineSurface(object);
// if(surface) {
//
// bool finished = false;
// while(!finished) {
//
// bool restartWhile = false;
// for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
// for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
// if(surface->controlpoint_selected(i,j)) {
// surface->delete_vector_n(j);
// restartWhile = true;
// break;
// }
// }
// if(restartWhile) {
// break;
// }
// }
//
// finished = true;
// }
// }
//
// emit scriptInfo("deleteSelectedControlPoints(ObjectId)");
// }
//
// void BSplineSurfaceSelectionPlugin::deleteSelectedControlPointsV(int _objectId) {
//
// BaseObjectData* object = 0;
//
// if(!PluginFunctions::getObject(_objectId, object)) {
// emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
// return;
// }
//
// BSplineSurface* surface = PluginFunctions::splineSurface(object);
// if(surface) {
//
// bool finished = false;
// while(!finished) {
//
// bool restartWhile = false;
// for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
// for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
// if(surface->controlpoint_selected(i,j)) {
// surface->delete_vector_m(i);
// restartWhile = true;
// break;
// }
// }
// if(restartWhile) {
// break;
// }
// }
//
// finished = true;
// }
// }
//
// emit scriptInfo("deleteSelectedControlPoints(ObjectId)");
// }
void BSplineSurfaceSelectionPlugin::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;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
if(surface) {
for(IdList::const_iterator it = _ids.begin(); it != _ids.end(); ++it) {
if(*it < (int)surface->n_control_points_m()*(int)surface->n_control_points_n()) {
int idx_m = *it / surface->n_control_points_n();
int idx_n = *it % surface->n_control_points_n();
if(_deselect) surface->deselect_controlpoint(idx_m, idx_n);
else surface->select_controlpoint(idx_m, idx_n);
}
}
}
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 BSplineSurfaceSelectionPlugin::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;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
if(surface) {
for(unsigned int i = 0; i < surface->n_control_points_m(); ++i) {
for(unsigned int j = 0; j < surface->n_control_points_n(); ++j) {
if(surface->controlpoint_selected(i,j))
list.push_back((int)i*surface->n_control_points_n() + (int)j);
}
}
}
return list;
}
//=====================================================================
void BSplineSurfaceSelectionPlugin::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;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
BSplineSurfaceObject* so = PluginFunctions::bsplineSurfaceObject(object);
if(surface) {
for(unsigned int i = 0; i < surface->n_knots_m(); ++i) {
surface->get_knotvector_m_ref()->select(i);
}
for(unsigned int i = 0; i < surface->n_knots_n(); ++i) {
surface->get_knotvector_n_ref()->select(i);
}
}
// Switch to control point selection mode
if(so)
so->splineSurfaceNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineSurfaceNodeT<BSplineSurface>::KNOTVECTOR);
emit scriptInfo("selectAllKnots(ObjectId)");
}
void BSplineSurfaceSelectionPlugin::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;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
if(surface) {
for(unsigned int i = 0; i < surface->n_knots_m(); ++i) {
surface->get_knotvector_m_ref()->deselect(i);
}
for(unsigned int i = 0; i < surface->n_knots_n(); ++i) {
surface->get_knotvector_n_ref()->deselect(i);
}
}
emit scriptInfo("deselectAllKnots(ObjectId)");
}
void BSplineSurfaceSelectionPlugin::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;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
BSplineSurfaceObject* so = PluginFunctions::bsplineSurfaceObject(object);
if(surface) {
for(unsigned int i = 0; i < surface->n_knots_m(); ++i) {
if(surface->get_knotvector_m_ref()->selected(i))
surface->get_knotvector_m_ref()->deselect(i);
else
surface->get_knotvector_m_ref()->select(i);
}
for(unsigned int i = 0; i < surface->n_knots_n(); ++i) {
if(surface->get_knotvector_n_ref()->selected(i))
surface->get_knotvector_n_ref()->deselect(i);
else
surface->get_knotvector_n_ref()->select(i);
}
}
// Switch to control point selection mode
if(so)
so->splineSurfaceNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineSurfaceNodeT<BSplineSurface>::KNOTVECTOR);
emit scriptInfo("invertKnotSelection(ObjectId)");
}
void BSplineSurfaceSelectionPlugin::deleteSelectedKnotsU(int _objectId) {
//
// // 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 < surface->n_knots_n(); ++i) {
// if(surface->get_knotvector_n_ref()->selected(i)) {
// surface->get_knotvector_n_ref()->deleteKnot(i);
// oneFound = true;
// break;
// }
// }
//
// if((i >= surface->n_knots_n()) && !oneFound) {
// // We are through
// breakWhile = true;
// }
// }
// }
//
// emit scriptInfo("deleteSelectedKnots(ObjectId)");
}
void BSplineSurfaceSelectionPlugin::deleteSelectedKnotsV(int _objectId) {
// BaseObjectData* object = 0;
//
// if(!PluginFunctions::getObject(_objectId, object)) {
// emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
// return;
// }
//
// BSplineSurface* surface = PluginFunctions::splineSurface(object);
// if(surface) {
//
// // 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 < surface->n_knots(); ++i) {
// if(surface->get_knotvector_ref()->selected(i)) {
// surface->get_knotvector_ref()->deleteKnot(i);
// oneFound = true;
// break;
// }
// }
//
// if((i >= surface->n_knots()) && !oneFound) {
// // We are through
// breakWhile = true;
// }
// }
// }
//
// emit scriptInfo("deleteSelectedKnots(ObjectId)");
}
void BSplineSurfaceSelectionPlugin::selectKnots(int _objectId, const IdList& _ids_u, const IdList& _ids_v, bool _deselect) {
if(_ids_u.empty()) return;
BaseObjectData* object = 0;
if(!PluginFunctions::getObject(_objectId, object)) {
emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
return;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
if(surface) {
for(IdList::const_iterator it = _ids_u.begin(); it != _ids_u.end(); ++it) {
if(*it < (int)surface->n_knots_m()) {
if(_deselect) surface->get_knotvector_m_ref()->deselect(*it);
else surface->get_knotvector_m_ref()->select(*it);
}
}
for(IdList::const_iterator it = _ids_v.begin(); it != _ids_v.end(); ++it) {
if(*it < (int)surface->n_knots_n()) {
if(_deselect) surface->get_knotvector_n_ref()->deselect(*it);
else surface->get_knotvector_n_ref()->select(*it);
}
}
}
QString selection = "selectKnots(ObjectId, [ " + QString::number(_ids_u[0]);
for (uint i = 1 ; i < _ids_u.size(); ++i) {
selection += ", " + QString::number(_ids_u[i]);
}
selection += "; ";
for (uint i = 0 ; i < _ids_v.size(); ++i) {
selection += ", " + QString::number(_ids_v[i]);
}
selection += " ])";
emit scriptInfo(selection);
}
IdList BSplineSurfaceSelectionPlugin::getKnotSelectionU(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;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
if(surface) {
for(unsigned int i = 0; i < surface->n_knots_m(); ++i) {
if(surface->get_knotvector_m_ref()->selected(i))
list.push_back((int)i);
}
}
return list;
}
IdList BSplineSurfaceSelectionPlugin::getKnotSelectionV(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;
}
BSplineSurface* surface = PluginFunctions::splineSurface(object);
if(surface) {
for(unsigned int i = 0; i < surface->n_knots_n(); ++i) {
if(surface->get_knotvector_n_ref()->selected(i))
list.push_back((int)i);
}
}
return list;
}
This diff is collapsed.
/*===========================================================================*\
* *
* 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 BSPLINESURFACESELECTIONPLUGIN_HH
#define BSPLINESURFACESELECTIONPLUGIN_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/BSplineSurface/BSplineSurface.hh>
class BSplineSurfaceSelectionPlugin : 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
BSplineSurfaceSelectionPlugin();
/// Default destructor
~BSplineSurfaceSelectionPlugin();
signals:
// BaseInterface
void updateView();
void updatedObject(int, const UpdateType&);
void nodeVisibilityChanged(int _identifier);
void setSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
// LoggingInterface
void log(Logtype _type, QString _message);
void log(QString _message);
// BackupInterface
void createBackup( int _objectid, QString _name, UpdateType _type = UPDATE_ALL);
// 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("BSplineSurface Selection")));
};
QString description() {
return (QString(tr("Allows to select B-Spline surfaces")));
};
//===========================================================================
/** @name Private methods
* @{ */
//===========================================================================
private:
enum SelectionViewMode {CP, K};
/// Change selection view mode for every B-spline surface 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 deleteSelectedControlPointsU(int _objectId);
// void deleteSelectedControlPointsV(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 deleteSelectedKnotsU(int _objectId);
void deleteSelectedKnotsV(int _objectId);
/// Select specific knots of a curve
void selectKnots(int _objectId, const IdList& _ids_u, const IdList& _ids_v, bool _deselect = false);
/// Get current knot selection
IdList getKnotSelectionU(int _objectId);
IdList getKnotSelectionV(int _objectId);
/** @} */
//===========================================================================
/** @name Member variables
* @{ */
//===========================================================================
private:
/// Handle to selection environment
QString environmentHandle_;
/// Primitive type handles:
unsigned int controlPointType_;
unsigned int knotType_;
unsigned int allSupportedTypes_;
/// Keep volume lasso points
QVector<QPoint> volumeLassoPoints_;
/** @} */
};
//=============================================================================
#endif // BSPLINESURFACESELECTIONPLUGIN_HH defined
//=============================================================================
include (plugin)
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/BSplineSurface)
openflipper_plugin (INSTALLDATA Icons)
endif()
Icons/bscontrolpointselection.png

27.2 KiB

Icons/bsknotselection.png

27.2 KiB

Icons/bsplinesurface.png

26.5 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment