Commit 8feee8b0 authored by Max Lyon's avatar Max Lyon

add selection of single elements by index by pushing V, H, E, or F

parent 6e36631d
......@@ -89,6 +89,13 @@ void MeshObjectSelectionPlugin::selectEdges( int objectId , IdList _edgeList, co
//=========================================================
bool MeshObjectSelectionPlugin::selectEdge(int _objectId, int _idx, bool _fly_to_edge)
{
return selectElement(_objectId, OpenMesh::EdgeHandle(_idx), _fly_to_edge);
}
//=========================================================
void MeshObjectSelectionPlugin::unselectEdges( int objectId , IdList _edgeList ) {
if(_edgeList.empty()) return;
......
......@@ -88,6 +88,13 @@ void MeshObjectSelectionPlugin::selectFaces(int objectId , IdList _faceList) {
//=========================================================
bool MeshObjectSelectionPlugin::selectFace(int _objectId, int _idx, bool _fly_to_face)
{
return selectElement(_objectId, OpenMesh::FaceHandle(_idx), _fly_to_face);
}
//=========================================================
void MeshObjectSelectionPlugin::unselectFaces(int objectId , IdList _faceList) {
if(_faceList.empty() ) return;
......
......@@ -88,6 +88,13 @@ void MeshObjectSelectionPlugin::selectHalfedges(int objectId , IdList _halfedgeL
//=========================================================
bool MeshObjectSelectionPlugin::selectHalfedge(int _objectId, int _idx, bool _fly_to_halfedge)
{
return selectElement(_objectId, OpenMesh::HalfedgeHandle(_idx), _fly_to_halfedge);
}
//=========================================================
void MeshObjectSelectionPlugin::unselectHalfedges(int objectId , IdList _halfedgeList) {
if(_halfedgeList.empty() ) return;
......
......@@ -47,6 +47,7 @@
#include <QDesktopWidget>
#include <QColorDialog>
#include <QInputDialog>
// Primitive type icons
#define VERTEX_TYPE "selection_vertex.png"
......@@ -270,6 +271,14 @@ void MeshObjectSelectionPlugin::pluginsInitialized() {
emit registerKeyShortcut(Qt::Key_I, Qt::NoModifier);
// Delete selected entities
emit registerKeyShortcut(Qt::Key_Delete, Qt::NoModifier);
// Select a vertex by ID
emit registerKeyShortcut(Qt::Key_V, Qt::NoModifier);
// Select a halfedge by ID
emit registerKeyShortcut(Qt::Key_H, Qt::NoModifier);
// Select a edge by ID
emit registerKeyShortcut(Qt::Key_E, Qt::NoModifier);
// Select a face by ID
emit registerKeyShortcut(Qt::Key_F, Qt::NoModifier);
// load default Color values
std::string statusStr = OpenFlipperQSettings().value("SelectionMeshObject/StatusColor",QString()).toString().toStdString();
......@@ -1509,6 +1518,68 @@ void MeshObjectSelectionPlugin::slotComponentsSelection(QMouseEvent* _event, Sel
}
}
void MeshObjectSelectionPlugin::slotIndexSelection(int _key)
{
bool targetsOnly = false;
emit targetObjectsOnly(targetsOnly);
PluginFunctions::IteratorRestriction restriction =
(targetsOnly ? PluginFunctions::TARGET_OBJECTS : PluginFunctions::ALL_OBJECTS);
int visible_objects = 0;
for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH));
o_it != PluginFunctions::objectsEnd(); ++o_it)
{
if (o_it->visible()) {
++visible_objects;
}
}
bool fly = visible_objects == 1; // only fly to selection if a single object is processed
int idx;
switch (_key)
{
case Qt::Key_V:
idx = QInputDialog::getInt(nullptr, tr("Vertex to mark"), tr("Vertex idx:"), -1);
break;
case Qt::Key_H:
idx = QInputDialog::getInt(nullptr, tr("Halfedge to mark"), tr("Halfedge idx:"), -1);
break;
case Qt::Key_E:
idx = QInputDialog::getInt(nullptr, tr("Edge to mark"), tr("Edge idx:"), -1);
break;
case Qt::Key_F:
idx = QInputDialog::getInt(nullptr, tr("Face to mark"), tr("Face idx:"), -1);
break;
default:
idx = -1;
}
if (idx < 0)
return;
for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH));
o_it != PluginFunctions::objectsEnd(); ++o_it) {
bool selected_something = false;
if (o_it->visible()) {
if(_key == Qt::Key_V)
selected_something = selectVertex(o_it->id(), idx, fly);
if(_key == Qt::Key_H)
selected_something = selectHalfedge(o_it->id(), idx, fly);
if(_key == Qt::Key_E)
selected_something = selectEdge(o_it->id(), idx, fly);
if(_key == Qt::Key_F)
selected_something = selectFace(o_it->id(), idx, fly);
}
if (selected_something)
{
emit updatedObject(o_it->id(), UPDATE_SELECTION);
emit createBackup(o_it->id(), "Select Element", UPDATE_SELECTION);
}
}
}
void MeshObjectSelectionPlugin::loadSelection(int _objId, const QString& _filename) {
// Load ini file
......@@ -1744,11 +1815,15 @@ void MeshObjectSelectionPlugin::slotSaveSelection(INIFile& _file) {
}
void MeshObjectSelectionPlugin::slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers) {
if (((_key == Qt::Key_V) || (_key == Qt::Key_H) || (_key == Qt::Key_E) || (_key == Qt::Key_F)) && _modifiers == Qt::NoModifier)
slotIndexSelection(_key);
SelectionInterface::PrimitiveType type = 0u;
emit getActivePrimitiveType(type);
if((type & allSupportedTypes_) == 0) {
if((type & allSupportedTypes_) == 0)
{
// No supported type is active
return;
}
......
......@@ -169,6 +169,7 @@ private slots:
void slotClosestBoundarySelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
void slotFloodFillSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
void slotComponentsSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
void slotIndexSelection(int _key);
void slotLoadSelection(const INIFile& _file);
void slotSaveSelection(INIFile& _file);
......@@ -269,6 +270,9 @@ public slots:
/// select given vertices
void selectVertices(int objectId, IdList _vertexList);
/// select vertex with id _idx and maybe fly to it
bool selectVertex(int _objectId, int _idx, bool _fly_to_vertex);
/// unselect given vertices
void unselectVertices(int objectId, IdList _vertexList);
......@@ -354,6 +358,9 @@ public slots:
/// Select given Edges
void selectEdges(int objectId, IdList _edgeList, const double _dihedral_angle_threshold = 0.0);
/// Select edge with id _idx and maybe fly to it
bool selectEdge(int _objectId, int _idx, bool _fly_to_edge);
/// Unselect given Edges
void unselectEdges(int objectId, IdList _edgeList);
......@@ -397,6 +404,9 @@ public slots:
/// Select given Halfedges
void selectHalfedges(int objectId, IdList _vertexList);
/// Select halfedge with id _idx and maybe fly to it
bool selectHalfedge(int _objectId, int _idx, bool _fly_to_halfedge);
/// Unselect given Halfedges
void unselectHalfedges(int objectId, IdList _vertexList);
......@@ -431,6 +441,9 @@ public slots:
/// Select given faces
void selectFaces(int objectId, IdList _facesList);
/// Select face with id _idx and maybe fly to it
bool selectFace(int _objectId, int _idx, bool _fly_to_face);
/// Unselect given faces
void unselectFaces(int objectId, IdList _facesList);
......@@ -475,6 +488,15 @@ public slots:
/// Convert the selection on all target objects
void conversion(const QString& _from, const QString& _to, bool _deselect);
public:
template <typename HandleT>
bool selectElement(int _objectId, HandleT _handle, bool _fly_to_element);
private:
template <typename MeshObjectT, typename HandleT>
void getFlightData(MeshObjectT& _mesh_object, HandleT _handle,
OpenMesh::Vec3d& center, OpenMesh::Vec3d& normal, bool& handle_valid);
public:
/// set dihedral angle threshold for edge selection
......
......@@ -43,6 +43,7 @@
#include "MeshObjectSelectionPlugin.hh"
#include <MeshTools/MeshNavigationT.hh>
#include <MeshTools/MeshSelectionT.hh>
#include <OpenMesh/Core/Geometry/MathDefs.hh>
#include <set>
......@@ -974,3 +975,61 @@ void MeshObjectSelectionPlugin::selectVerticesByValue(MeshT* _mesh, QString _com
}
template <typename HandleT>
bool MeshObjectSelectionPlugin::selectElement(int _objectId, HandleT _handle, bool _fly_to_element)
{
if (!_handle.is_valid())
return false;
BaseObjectData* object = nullptr;
if (!PluginFunctions::getObject(_objectId,object)) {
emit log(LOGERR,tr("selectElement: unable to get object"));
return false;
}
IdList elementList;
elementList.push_back(_handle.idx());
OpenMesh::Vec3d center;
OpenMesh::Vec3d normal;
bool handle_valid = false;
if (object->dataType() == DATA_TRIANGLE_MESH){
MeshSelection::selectElements(PluginFunctions::triMesh(object), elementList, HandleT());
getFlightData(*PluginFunctions::triMeshObject(object), _handle, center, normal, handle_valid);
} else if (object->dataType() == DATA_POLY_MESH) {
MeshSelection::selectElements(PluginFunctions::polyMesh(object), elementList, HandleT());
getFlightData(*PluginFunctions::polyMeshObject(object), _handle, center, normal, handle_valid);
} else {
emit log(LOGERR,tr("selectElement: Unsupported object Type"));
return false;
}
if (handle_valid && _fly_to_element)
PluginFunctions::flyTo(center + normal , center, 500.0);
return handle_valid;
}
template <typename MeshObjectT, typename HandleT>
void MeshObjectSelectionPlugin::getFlightData(MeshObjectT& _mesh_object, HandleT _handle,
OpenMesh::Vec3d& center, OpenMesh::Vec3d& normal, bool& handle_valid)
{
OpenMesh::Vec3d bbMin;
OpenMesh::Vec3d bbMax;
_mesh_object.boundingBox(bbMin, bbMax);
auto& mesh = *_mesh_object.mesh();
if (_handle.is_valid() && static_cast<size_t>(_handle.idx()) < mesh.n_vertices())
{
center = mesh.calc_centroid(_handle);
normal = 0.5 * (bbMax-bbMin).length() * mesh.calc_normal(_handle);
handle_valid = true;
}
else
{
handle_valid = false;
}
}
......@@ -88,6 +88,13 @@ void MeshObjectSelectionPlugin::selectVertices(int _objectId, IdList _vertexList
//=========================================================
bool MeshObjectSelectionPlugin::selectVertex(int _objectId, int _idx, bool _fly_to_vertex)
{
return selectElement(_objectId, OpenMesh::VertexHandle(_idx), _fly_to_vertex);
}
//=========================================================
void MeshObjectSelectionPlugin::unselectVertices(int _objectId, IdList _vertexList) {
if(_vertexList.empty() ) return;
......
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