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" 77 void ObjectSelectionPlugin::initializePlugin() {
85 void 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(
","));
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)
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);
253 void 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);
269 void ObjectSelectionPlugin::loadIniFile(
INIFile& _ini,
int _id) {
276 void 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) {
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
void selectObjects(IdList _list)
Select specified objects.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
ObjectSelectionPlugin()
Default constructor.
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void updateSlotDescriptions()
Set slot descriptions for scripting functions.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
const QStringList ALL_OBJECTS
Iterable object range.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
QString environmentHandle_
Handle to selection environment.
pick any of the prior targets (should be implemented for all nodes)
int viewport_height() const
get viewport height
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
IdList getObjectSelection()
Get selected objects.
void invertObjectSelection()
Invert object selection.
void slotSelectionOperation(QString _operation)
A specific operation is requested.
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
void deselectAllObjects()
Deselect all objects.
void selectAllObjects()
Select all objects.
QVector< QPoint > volumeLassoPoints_
Keep volume lasso points.
Class for the handling of simple configuration files.
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
PrimitiveType objectType_
Primitive type handles:
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
~ObjectSelectionPlugin()
Default destructor.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
ACG::GLState & glState()
Get the glState of the Viewer.
void deleteSelectedObjects()
Delete selected objects.