50 #include "PolyLineSelectionPlugin.hh" 55 #define VERTEX_TYPE "polyline_vertex.png" 56 #define EDGE_TYPE "polyline_edge.png" 61 #define V_SELECT_ALL "Select All Vertices" 62 #define V_DESELECT_ALL "Deselect All Vertices" 63 #define V_INVERT "Invert Vertex Selection" 64 #define V_DELETE "Delete Selected Vertices" 66 #define E_SELECT_ALL "Select All Edges" 67 #define E_DESELECT_ALL "Deselect All Edges" 68 #define E_INVERT "Invert Edge Selection" 69 #define E_DELETE "Delete Selected Edges" 75 allSupportedTypes_(0) {
85 void PolyLineSelectionPlugin::initializePlugin() {
93 void PolyLineSelectionPlugin::pluginsInitialized() {
97 QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
99 emit addSelectionEnvironment(
"PolyLine Selections",
"Select polyline primitives.",
115 QStringList vertexOperations;
116 vertexOperations.append(V_SELECT_ALL);
117 vertexOperations.append(V_DESELECT_ALL);
118 vertexOperations.append(V_INVERT);
119 vertexOperations.append(V_DELETE);
121 QStringList edgeOperations;
122 edgeOperations.append(E_SELECT_ALL);
123 edgeOperations.append(E_DESELECT_ALL);
124 edgeOperations.append(E_INVERT);
125 edgeOperations.append(E_DELETE);
133 emit registerKeyShortcut(Qt::Key_A, Qt::ControlModifier);
135 emit registerKeyShortcut(Qt::Key_C, Qt::NoModifier);
137 emit registerKeyShortcut(Qt::Key_I, Qt::NoModifier);
139 emit registerKeyShortcut(Qt::Key_Delete, Qt::NoModifier);
146 emit setSlotDescription(
"selectAllVertices(int)", tr(
"Select all vertices of a polyline"),
147 QStringList(
"objectId"), QStringList(
"Id of object"));
148 emit setSlotDescription(
"deselectAllVertices(int)", tr(
"Deselect all vertices of a polyline"),
149 QStringList(
"objectId"), QStringList(
"Id of object"));
150 emit setSlotDescription(
"invertVertexSelection(int)", tr(
"Invert vertex selection"),
151 QStringList(
"objectId"), QStringList(
"Id of object"));
152 emit setSlotDescription(
"deleteSelectedVertices(int)", tr(
"Delete selected vertices"),
153 QStringList(
"objectId"), QStringList(
"Id of object"));
154 emit setSlotDescription(
"selectVertices(int,IdList)", tr(
"Select the specified vertices"),
155 QString(
"objectId,vertexList").split(
","), QString(
"Id of object,List of vertices").split(
","));
157 emit setSlotDescription(
"selectAllEdges(int)", tr(
"Select all edges of a polyline"),
158 QStringList(
"objectId"), QStringList(
"Id of object"));
159 emit setSlotDescription(
"deselectAllEdges(int)", tr(
"Deselect all edges of a polyline"),
160 QStringList(
"objectId"), QStringList(
"Id of object"));
161 emit setSlotDescription(
"invertEdgeSelection(int)", tr(
"Invert edge selection"),
162 QStringList(
"objectId"), QStringList(
"Id of object"));
163 emit setSlotDescription(
"deleteSelectedEdges(int)", tr(
"Delete selected edges"),
164 QStringList(
"objectId"), QStringList(
"Id of object"));
165 emit setSlotDescription(
"selectEdges(int,IdList)", tr(
"Select the specified edges"),
166 QString(
"objectId,edgeList").split(
","), QString(
"Id of object,List of edges").split(
","));
168 emit setSlotDescription(
"loadSelection(int,QString)", tr(
"Load selection from selection file"),
169 QString(
"objectId,filename").split(
","), QString(
"Id of an object,Selection file").split(
","));
176 SelectionInterface::PrimitiveType type = 0u;
177 emit getActivePrimitiveType(type);
183 bool targetsOnly =
false;
184 emit targetObjectsOnly(targetsOnly);
188 if(_operation == V_SELECT_ALL) {
192 if (o_it->visible()) {
198 }
else if (_operation == V_DESELECT_ALL) {
202 if (o_it->visible()) {
208 }
else if (_operation == V_INVERT) {
212 if (o_it->visible()) {
218 }
else if (_operation == V_DELETE) {
222 if (o_it->visible()) {
228 }
else if(_operation == E_SELECT_ALL) {
232 if (o_it->visible()) {
238 }
else if (_operation == E_DESELECT_ALL) {
242 if (o_it->visible()) {
248 }
else if (_operation == E_INVERT) {
252 if (o_it->visible()) {
258 }
else if (_operation == E_DELETE) {
262 if (o_it->visible()) {
279 if(_event->button() != Qt::LeftButton)
return;
281 unsigned int node_idx, target_idx;
291 if(successfullyPicked) {
297 if(polyline->vertex_selected(target_idx) || _deselect)
298 polyline->deselect_vertex(target_idx);
300 polyline->select_vertex(target_idx);
311 if(successfullyPicked) {
317 if(polyline->edge_selected(target_idx) || _deselect)
318 polyline->deselect_edge(target_idx);
320 polyline->select_edge(target_idx);
336 if(_event->type() == QEvent::MouseButtonPress) {
339 QPoint p(_event->pos().x(), state.
viewport_height() - _event->pos().y());
345 }
else if(_event->type() == QEvent::MouseButtonDblClick) {
351 bool targetsOnly =
false;
352 emit targetObjectsOnly(targetsOnly);
360 if (o_it->visible()) {
372 for(
unsigned int i = 0; i < polyline->
n_vertices(); ++i) {
374 QPoint p((
int)pp[0], (
int)pp[1]);
376 if(polygon.containsPoint(p, Qt::OddEvenFill)) {
378 polyline->deselect_vertex(i);
380 polyline->select_vertex(i);
387 for(
unsigned int i = 0; i < polyline->
n_vertices(); ++i) {
392 QPoint p((
int)pp[0], (
int)pp[1]);
394 if(polygon.containsPoint(p, Qt::OddEvenFill)) {
396 polyline->deselect_edge(i);
398 polyline->select_edge(i);
417 void PolyLineSelectionPlugin::loadSelection(
int _objId,
const QString& _filename) {
422 if(!file.
connect(_filename,
false)) {
423 emit log(
LOGERR, QString(
"Could not read file '%1'!").arg(_filename));
428 loadIniFile(file, _objId);
433 void PolyLineSelectionPlugin::loadIniFile(
INIFile& _ini,
int _id) {
440 void PolyLineSelectionPlugin::saveIniFile(
INIFile& _ini,
int _id) {
456 QString section = QString(
"PolyLineSelection") +
"//" + o_it->name();
461 std::vector<int> ids;
463 _file.
get_entry(ids, section,
"VertexSelection");
467 _file.
get_entry(ids, section,
"EdgeSelection");
486 QString section = QString(
"PolyLineSelection") +
"//" + o_it->name();
498 SelectionInterface::PrimitiveType type = 0u;
499 emit getActivePrimitiveType(type);
506 bool targetsOnly =
false;
507 emit targetObjectsOnly(targetsOnly);
511 if(_key == Qt::Key_A && _modifiers == Qt::ControlModifier) {
515 if (o_it->visible()) {
523 }
else if(_key == Qt::Key_C && _modifiers == Qt::NoModifier) {
527 if (o_it->visible()) {
535 }
else if(_key == Qt::Key_I && _modifiers == Qt::NoModifier) {
539 if (o_it->visible()) {
547 }
else if(_key == Qt::Key_Delete && _modifiers == Qt::NoModifier) {
551 if (o_it->visible()) {
566 #if QT_VERSION < 0x050000 PolyLineSelectionPlugin()
Default constructor.
IdList getVertexSelection(int _objectId)
Get current vertex selection.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
QStringList IteratorRestriction
Iterable object range.
void updateSlotDescriptions()
Set slot descriptions for scripting functions.
void deleteSelectedVertices(int _objectId)
Delete selected vertices.
ACG::GLState & glState()
Get the glState of the Viewer.
void selectAllEdges(int _objectId)
Select all edges of a skeleton.
~PolyLineSelectionPlugin()
Default destructor.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void selectVertices(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific vertices of a skeleton.
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
PolyLine * line()
return a pointer to the line
const QStringList ALL_OBJECTS
Iterable object range.
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
PrimitiveType vertexType_
Primitive type handles:
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
void slotSelectionOperation(QString _operation)
A specific operation is requested.
PolyLine * polyLine(BaseObjectData *_object)
Get a poly Line from an object.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
PolyLineObject * polyLineObject(BaseObjectData *_object)
Cast an BaseObject to a PolyLineObject if possible.
Point edge_vector(unsigned int _i) const
get the i-th oriented edge vector
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
PrimitiveType allSupportedTypes_
Handle to selection environment.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
Point & point(unsigned int _i)
Get a point of the polyline.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Class for the handling of simple configuration files.
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
void deselectAllVertices(int _objectId)
Deselect all vertices of a skeleton.
void deselectAllEdges(int _objectId)
Deselect all edges of a skeleton.
PrimitiveType edgeType_
Handle to selection environment.
picks verices (may not be implemented for all nodes)
void deleteSelectedEdges(int _objectId)
Delete selected edges.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
void selectAllVertices(int _objectId)
Select all vertices of a skeleton.
IdList getEdgeSelection(int _objectId)
Get current edge selection.
picks edges (may not be implemented for all nodes)
QString environmentHandle_
Handle to selection environment.
void selectEdges(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific edges of a skeleton.
void invertVertexSelection(int _objectId)
Invert vertex selection.
void invertEdgeSelection(int _objectId)
Invert edge selection.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
size_t n_vertices() const
Get number of vertices.
int viewport_height() const
get viewport height
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
QVector< QPoint > volumeLassoPoints_
Keep volume lasso points.