Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PolyLineSelectionFunctions.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 #include "PolyLineSelectionPlugin.hh"
52 
54 
55  BaseObjectData* object = 0;
56 
57  if(!PluginFunctions::getObject(_objectId, object)) {
58  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
59  return;
60  }
61 
62  PolyLine* polyline = PluginFunctions::polyLine(object);
63  if(polyline) {
64 
65  for(unsigned int i = 0; i < polyline->n_vertices(); ++i) {
66  polyline->select_vertex(i);
67  }
68  }
69 
70  emit scriptInfo("selectAllVertices(ObjectId)");
71 }
72 
74 
75  BaseObjectData* object = 0;
76 
77  if(!PluginFunctions::getObject(_objectId, object)) {
78  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
79  return;
80  }
81 
82  PolyLine* polyline = PluginFunctions::polyLine(object);
83  if(polyline) {
84 
85  for(unsigned int i = 0; i < polyline->n_vertices(); ++i) {
86  polyline->deselect_vertex(i);
87  }
88  }
89 
90  emit scriptInfo("deselectAllVertices(ObjectId)");
91 }
92 
94 
95  BaseObjectData* object = 0;
96 
97  if(!PluginFunctions::getObject(_objectId, object)) {
98  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
99  return;
100  }
101 
102  PolyLine* polyline = PluginFunctions::polyLine(object);
103  if(polyline) {
104 
105  for(unsigned int i = 0; i < polyline->n_vertices(); ++i) {
106 
107  if(polyline->vertex_selected(i))
108  polyline->deselect_vertex(i);
109  else
110  polyline->select_vertex(i);
111  }
112  }
113 
114  emit scriptInfo("invertVertexSelection(ObjectId)");
115 }
116 
118 
119  BaseObjectData* object = 0;
120 
121  if(!PluginFunctions::getObject(_objectId, object)) {
122  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
123  return;
124  }
125 
126  PolyLine* polyline = PluginFunctions::polyLine(object);
127  if(polyline) {
128 
129  bool breakWhile = false;
130  while(!breakWhile) {
131 
132  // Go over all vertices and delete the selected ones
133  bool oneFound = false;
134  unsigned int i = 0;
135  for(; i < polyline->n_vertices(); ++i) {
136 
137  if(polyline->vertex_selected(i)) {
138  polyline->delete_point(i);
139  oneFound = true;
140  }
141  if(oneFound)
142  break;
143  }
144 
145  if(i == polyline->n_vertices() && !oneFound) {
146  // We are through
147  breakWhile = true;
148  }
149  }
150  }
151 
152  emit scriptInfo("deleteSelectedVertices(ObjectId)");
153 }
154 
155 void PolyLineSelectionPlugin::selectVertices(int _objectId, const IdList& _ids, bool _deselect) {
156 
157  if(_ids.empty() ) return;
158 
159  BaseObjectData* object = 0;
160 
161  if(!PluginFunctions::getObject(_objectId, object)) {
162  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
163  return;
164  }
165 
166  PolyLine* polyline = PluginFunctions::polyLine(object);
167  if(polyline) {
168  for(IdList::const_iterator it = _ids.begin(); it != _ids.end(); ++it) {
169  if(*it < (int)polyline->n_vertices()) {
170  if(_deselect) polyline->deselect_vertex(*it);
171  else polyline->select_vertex(*it);
172  }
173  }
174  }
175 
176  QString selection = "selectVertices(ObjectId, [ " + QString::number(_ids[0]);
177 
178  for (uint i = 1 ; i < _ids.size(); ++i) {
179  selection += ", " + QString::number(_ids[i]);
180  }
181 
182  selection += " ])";
183 
184  emit scriptInfo(selection);
185 }
186 
188 
189  BaseObjectData* object = 0;
190 
191  IdList list;
192 
193  if(!PluginFunctions::getObject(_objectId, object)) {
194  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
195  return list;
196  }
197 
198  PolyLine* polyline = PluginFunctions::polyLine(object);
199  if(polyline) {
200 
201  for(unsigned int i = 0; i < polyline->n_vertices(); ++i) {
202  if(polyline->vertex_selected(i))
203  list.push_back(i);
204  }
205  }
206 
207  return list;
208 }
209 
210 //=======================================================================================
211 
213 
214  BaseObjectData* object = 0;
215 
216  if (!PluginFunctions::getObject(_objectId, object)) {
217  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
218  return;
219  }
220 
221  PolyLine* polyline = PluginFunctions::polyLine(object);
222  if (polyline) {
223 
224  for(unsigned int i = 0; i < polyline->n_edges(); ++i) {
225  polyline->select_edge(i);
226  }
227  }
228 
229  emit scriptInfo("selectAllEdges(ObjectId)");
230 }
231 
233 
234  BaseObjectData* object = 0;
235 
236  if (!PluginFunctions::getObject(_objectId, object)) {
237  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
238  return;
239  }
240 
241  PolyLine* polyline = PluginFunctions::polyLine(object);
242  if (polyline) {
243 
244  for(unsigned int i = 0; i < polyline->n_edges(); ++i) {
245  polyline->deselect_edge(i);
246  }
247  }
248 
249  emit scriptInfo("deselectAllEdges(ObjectId)");
250 }
251 
253 
254  BaseObjectData* object = 0;
255 
256  if (!PluginFunctions::getObject(_objectId, object)) {
257  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
258  return;
259  }
260 
261  PolyLine* polyline = PluginFunctions::polyLine(object);
262  if (polyline) {
263 
264  for(unsigned int i = 0; i < polyline->n_edges(); ++i) {
265  if(polyline->edge_selected(i))
266  polyline->deselect_edge(i);
267  else
268  polyline->select_edge(i);
269  }
270  }
271 
272  emit scriptInfo("deselectAllEdges(ObjectId)");
273 }
274 
276 
277  BaseObjectData* object = 0;
278 
279  if(!PluginFunctions::getObject(_objectId, object)) {
280  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
281  return;
282  }
283 
284  PolyLine* polyline = PluginFunctions::polyLine(object);
285  if(polyline) {
286 
287  bool breakWhile = false;
288  while(!breakWhile) {
289 
290  // Go over all vertices and delete the selected ones
291  bool oneFound = false;
292  unsigned int i = 0;
293  for(; i < polyline->n_edges(); ++i) {
294 
295  if(polyline->edge_selected(i)) {
296  if(i+1 < polyline->n_vertices() /*Should always be the case*/) {
297 
298  if(!polyline->is_closed() && (i == 0 || i == polyline->n_edges()-1)) {
299  // Test if we're considering a boundary edge
300  // (only in not closed polylines)
301 
302  // Only delete one point (the boundary vertex)
303  if(i == 0)
304  polyline->delete_point(i);
305  else
306  polyline->delete_point(i+1);
307 
308  oneFound = true;
309 
310  } else {
311  // Delete both incident points
312  polyline->delete_point(i);
313  // Note: Index i+1 is now i after deletion
314  polyline->delete_point(i);
315  oneFound = true;
316  }
317  }
318  }
319  if(oneFound)
320  break;
321  }
322 
323  if(i == polyline->n_edges() && !oneFound) {
324  // We are through
325  breakWhile = true;
326  }
327  }
328  }
329 
330  emit scriptInfo("deleteSelectedEdges(ObjectId)");
331 }
332 
333 void PolyLineSelectionPlugin::selectEdges(int _objectId, const IdList& _ids, bool _deselect) {
334 
335  if(_ids.empty() ) return;
336 
337  BaseObjectData* object = 0;
338 
339  if (!PluginFunctions::getObject(_objectId, object)) {
340  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
341  return;
342  }
343 
344  PolyLine* polyline = PluginFunctions::polyLine(object);
345  if (polyline) {
346  for (IdList::const_iterator it = _ids.begin(); it != _ids.end(); ++it) {
347 
348  if(*it < (int)polyline->n_edges()) {
349  if(_deselect) polyline->deselect_edge(*it);
350  else polyline->select_edge(*it);
351  }
352  }
353  }
354 
355  QString selection = "selectEdges(ObjectId, [ " + QString::number(_ids[0]);
356 
357  for (uint i = 1 ; i < _ids.size(); ++i) {
358  selection += ", " + QString::number(_ids[i]);
359  }
360 
361  selection += " ])";
362 
363  emit scriptInfo(selection);
364 }
365 
367 
368  BaseObjectData* object = 0;
369 
370  IdList list;
371 
372  if(!PluginFunctions::getObject(_objectId, object)) {
373  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
374  return list;
375  }
376 
377  PolyLine* polyline = PluginFunctions::polyLine(object);
378  if(polyline) {
379 
380  for(unsigned int i = 0; i < polyline->n_edges(); ++i) {
381  if(polyline->edge_selected(i))
382  list.push_back(i);
383  }
384  }
385 
386  return list;
387 }
size_t n_vertices() const
Get number of vertices.
Definition: PolyLineT.hh:122
void invertEdgeSelection(int _objectId)
Invert edge selection.
PolyLine * polyLine(BaseObjectData *_object)
Get a poly Line from an object.
bool getObject(int _identifier, BSplineCurveObject *&_object)
size_t n_edges() const
Get number of edges.
Definition: PolyLineT.cc:216
void selectAllEdges(int _objectId)
Select all edges of a skeleton.
bool is_closed() const
Check if the polyline is marked as closed.
Definition: PolyLineT.hh:113
void delete_point(int _idx)
Delete point at _idx.
Definition: PolyLineT.cc:417
IdList getEdgeSelection(int _objectId)
Get current edge selection.
void selectAllVertices(int _objectId)
Select all vertices of a skeleton.
void deleteSelectedEdges(int _objectId)
Delete selected edges.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
void deselectAllEdges(int _objectId)
Deselect all edges of a skeleton.
void invertVertexSelection(int _objectId)
Invert vertex selection.
void selectVertices(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific vertices of a skeleton.
void deselectAllVertices(int _objectId)
Deselect all vertices of a skeleton.
IdList getVertexSelection(int _objectId)
Get current vertex selection.
void selectEdges(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific edges of a skeleton.
void deleteSelectedVertices(int _objectId)
Delete selected vertices.