50#include "ObjectSelectionPlugin.hh"
55#define OBJECT_TYPE "selection_object.png"
60#define O_SELECT_ALL "Select All Objects"
61#define O_DESELECT_ALL "Deselect All Objects"
62#define O_INVERT "Invert Object Selection"
63#define O_DELETE "Delete Selected Objects"
77void ObjectSelectionPlugin::initializePlugin() {
85void ObjectSelectionPlugin::pluginsInitialized() {
89 QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
91 emit addSelectionEnvironment(
"Object Selections",
"Select objects.",
104 QStringList objectOperations;
105 objectOperations.append(O_SELECT_ALL);
106 objectOperations.append(O_DESELECT_ALL);
107 objectOperations.append(O_INVERT);
108 objectOperations.append(O_DELETE);
115 emit registerKeyShortcut(Qt::Key_A, Qt::ControlModifier);
117 emit registerKeyShortcut(Qt::Key_C, Qt::NoModifier);
119 emit registerKeyShortcut(Qt::Key_I, Qt::NoModifier);
121 emit registerKeyShortcut(Qt::Key_Delete, Qt::NoModifier);
128 emit setSlotDescription(
"selectAllObjects(int)", tr(
"Select all objects"),
129 QStringList(
"objectId"), QStringList(
"Id of object"));
130 emit setSlotDescription(
"deselectAllObjects(int)", tr(
"Deselect all objects"),
131 QStringList(
"objectId"), QStringList(
"Id of object"));
132 emit setSlotDescription(
"invertObjectSelection(int)", tr(
"Invert object selection"),
133 QStringList(
"objectId"), QStringList(
"Id of object"));
134 emit setSlotDescription(
"deleteSelectedObjects(int)", tr(
"Delete selected objects"),
135 QStringList(
"objectId"), QStringList(
"Id of object"));
136 emit setSlotDescription(
"selectObjects(int,IdList)", tr(
"Select the specified objects"),
137 QString(
"objectId,objectList").split(
","), QString(
"Id of object,List of objects").split(
","));
139 emit setSlotDescription(
"loadSelection(int,QString)", tr(
"Load selection from selection file"),
140 QString(
"objectId,filename").split(
","), QString(
"Id of an object,Selection file").split(
","));
145void ObjectSelectionPlugin::slotSelectionOperation(
const QString& _operation) {
147 SelectionInterface::PrimitiveType type = 0u;
148 emit getActivePrimitiveType(type);
153 if(_operation == O_SELECT_ALL) {
156 }
else if (_operation == O_DESELECT_ALL) {
159 }
else if (_operation == O_INVERT) {
162 }
else if (_operation == O_DELETE) {
176 if(_event->button() != Qt::LeftButton)
return;
179 size_t target_idx = 0;
187 if(successfullyPicked) {
189 if(object->
target() || _deselect)
190 object->target(
false);
192 object->target(
true);
207 if(_event->type() == QEvent::MouseButtonPress) {
210 QPoint p(_event->pos().x(), state.
viewport_height() - _event->pos().y());
216 }
else if(_event->type() == QEvent::MouseButtonDblClick) {
226 if (o_it->visible()) {
231 o_it->getBoundingBox(bbmin, bbmax);
235 QPoint p((
int)pc[0], (
int)pc[1]);
237 if(polygon.containsPoint(p, Qt::OddEvenFill)) {
238 o_it->target(!_deselect);
253void ObjectSelectionPlugin::loadSelection(
int _objId,
const QString& _filename) {
258 if(!file.
connect(_filename,
false)) {
259 emit log(
LOGERR, QString(
"Could not read file '%1'!").arg(_filename));
264 loadIniFile(file, _objId);
269void ObjectSelectionPlugin::loadIniFile(
INIFile& _ini,
int _id) {
276void ObjectSelectionPlugin::saveIniFile(
INIFile& _ini,
int _id) {
292 QString section = QString(
"ObjectSelection") +
"//" + o_it->name();
297 std::vector<int> ids;
318 QString section = QString(
"ObjectSelection") +
"//" + o_it->name();
329 SelectionInterface::PrimitiveType type = 0u;
330 emit getActivePrimitiveType(type);
337 if(_key == Qt::Key_A && _modifiers == Qt::ControlModifier) {
340 }
else if(_key == Qt::Key_C && _modifiers == Qt::NoModifier) {
343 }
else if(_key == Qt::Key_I && _modifiers == Qt::NoModifier) {
346 }
else if(_key == Qt::Key_Delete && _modifiers == Qt::NoModifier) {
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
int viewport_height() const
get viewport height
Class for the handling of simple configuration files.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
void selectObjects(IdList _list)
Select specified objects.
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
ObjectSelectionPlugin()
Default constructor.
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
PrimitiveType objectType_
Primitive type handles:
QVector< QPoint > volumeLassoPoints_
Keep volume lasso points.
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
void selectAllObjects()
Select all objects.
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
QString environmentHandle_
Handle to selection environment.
void deselectAllObjects()
Deselect all objects.
void invertObjectSelection()
Invert object selection.
void updateSlotDescriptions()
Set slot descriptions for scripting functions.
IdList getObjectSelection()
Get selected objects.
void deleteSelectedObjects()
Delete selected objects.
~ObjectSelectionPlugin()
Default destructor.
ACG::GLState & glState()
Get the glState of the Viewer.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(16))
Selection updated.
@ PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
const QStringList ALL_OBJECTS
Iterable object range.