Developer Documentation
BSplineCurveSelectionFunctions.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 #include "BSplineCurveSelectionPlugin.hh"
51 
53 
54  BaseObjectData* object = 0;
55 
56  if(!PluginFunctions::getObject(_objectId, object)) {
57  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
58  return;
59  }
60 
63 
64  if(curve) {
65  for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
66  curve->select_controlpoint(i);
67  }
68  }
69 
70  // Switch to control point selection mode
71  if(co)
73 
74  emit scriptInfo("selectAllControlPoints(ObjectId)");
75 }
76 
78 
79  BaseObjectData* object = 0;
80 
81  if(!PluginFunctions::getObject(_objectId, object)) {
82  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
83  return;
84  }
85 
87  if(curve) {
88  for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
89  curve->deselect_controlpoint(i);
90  }
91  }
92 
93  emit scriptInfo("deselectAllControlPoints(ObjectId)");
94 }
95 
97 
98  BaseObjectData* object = 0;
99 
100  if(!PluginFunctions::getObject(_objectId, object)) {
101  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
102  return;
103  }
104 
107 
108  if(curve) {
109  for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
110  if(curve->controlpoint_selected(i))
111  curve->deselect_controlpoint(i);
112  else
113  curve->select_controlpoint(i);
114  }
115  }
116 
117  // Switch to control point selection mode
118  if(co)
120 
121  emit scriptInfo("invertControlPointSelection(ObjectId)");
122 }
123 
125 
126  BaseObjectData* object = 0;
127 
128  if(!PluginFunctions::getObject(_objectId, object)) {
129  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
130  return;
131  }
132 
134  if(curve) {
135 
136  // I know this is a bit crappy, but control point indices
137  // change forcably after each delete operation so we have to
138  // start over each time...
139  bool breakWhile = false;
140  while(!breakWhile) {
141  bool oneFound = false;
142  unsigned int i = 0;
143  for(; i < curve->n_control_points(); ++i) {
144  if(curve->controlpoint_selected(i)) {
145  curve->delete_control_point(i);
146  oneFound = true;
147  break;
148  }
149  }
150 
151  if((i >= curve->n_control_points()) && !oneFound) {
152  // We are through
153  breakWhile = true;
154  }
155  }
156  }
157 
158  emit scriptInfo("deleteSelectedControlPoints(ObjectId)");
159 }
160 
161 void BSplineCurveSelectionPlugin::selectControlPoints(int _objectId, const IdList& _ids, bool _deselect) {
162 
163  if( _ids.empty()) return;
164 
165  BaseObjectData* object = 0;
166 
167  if(!PluginFunctions::getObject(_objectId, object)) {
168  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
169  return;
170  }
171 
173  if(curve) {
174  for(IdList::const_iterator it = _ids.begin(); it != _ids.end(); ++it) {
175  if(*it < (int)curve->n_control_points()) {
176  if(_deselect) curve->deselect_controlpoint(*it);
177  else curve->select_controlpoint(*it);
178  }
179  }
180  }
181 
182  QString selection = "selectControlPoints(ObjectId, [ " + QString::number(_ids[0]);
183 
184  for (uint i = 1 ; i < _ids.size(); ++i) {
185  selection += ", " + QString::number(_ids[i]);
186  }
187 
188  selection += " ])";
189 
190 
191  emit scriptInfo(selection);
192 }
193 
195 
196  BaseObjectData* object = 0;
197 
198  IdList list;
199 
200  if(!PluginFunctions::getObject(_objectId, object)) {
201  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
202  return list;
203  }
204 
206  if(curve) {
207  for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
208  if(curve->controlpoint_selected(i))
209  list.push_back((int)i);
210  }
211  }
212 
213  return list;
214 }
215 
216 //=====================================================================
217 
219 
220  BaseObjectData* object = 0;
221 
222  if(!PluginFunctions::getObject(_objectId, object)) {
223  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
224  return;
225  }
226 
229 
230  if(curve) {
231  for(unsigned int i = 0; i < curve->n_knots(); ++i) {
232  curve->get_knotvector_ref()->select(i);
233  }
234  }
235 
236  // Switch to control point selection mode
237  if(co)
239 
240  emit scriptInfo("selectAllKnots(ObjectId)");
241 }
242 
244 
245  BaseObjectData* object = 0;
246 
247  if(!PluginFunctions::getObject(_objectId, object)) {
248  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
249  return;
250  }
251 
253 
254  if(curve) {
255  for(unsigned int i = 0; i < curve->n_knots(); ++i) {
256  curve->get_knotvector_ref()->deselect(i);
257  }
258  }
259 
260  emit scriptInfo("deselectAllKnots(ObjectId)");
261 }
262 
264 
265  BaseObjectData* object = 0;
266 
267  if(!PluginFunctions::getObject(_objectId, object)) {
268  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
269  return;
270  }
271 
274 
275  if(curve) {
276  for(unsigned int i = 0; i < curve->n_knots(); ++i) {
277  if(curve->get_knotvector_ref()->selected(i))
278  curve->get_knotvector_ref()->deselect(i);
279  else
280  curve->get_knotvector_ref()->select(i);
281  }
282  }
283 
284  // Switch to control point selection mode
285  if(co)
287 
288  emit scriptInfo("invertKnotSelection(ObjectId)");
289 }
290 
292 
293  BaseObjectData* object = 0;
294 
295  if(!PluginFunctions::getObject(_objectId, object)) {
296  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
297  return;
298  }
299 
301  if(curve) {
302 
303  // I know this is a bit crappy, but knot indices
304  // change forcably after each delete operation so we have to
305  // start over each time...
306  bool breakWhile = false;
307  while(!breakWhile) {
308  bool oneFound = false;
309  unsigned int i = 0;
310  for(; i < curve->n_knots(); ++i) {
311  if(curve->get_knotvector_ref()->selected(i)) {
312  curve->get_knotvector_ref()->deleteKnot(i);
313  oneFound = true;
314  break;
315  }
316  }
317 
318  if((i >= curve->n_knots()) && !oneFound) {
319  // We are through
320  breakWhile = true;
321  }
322  }
323  }
324 
325  emit scriptInfo("deleteSelectedKnots(ObjectId)");
326 }
327 
328 void BSplineCurveSelectionPlugin::selectKnots(int _objectId, const IdList& _ids, bool _deselect) {
329 
330  if(_ids.empty()) return;
331 
332  BaseObjectData* object = 0;
333 
334  if(!PluginFunctions::getObject(_objectId, object)) {
335  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
336  return;
337  }
338 
340  if(curve) {
341  for(IdList::const_iterator it = _ids.begin(); it != _ids.end(); ++it) {
342  if(*it < (int)curve->n_knots()) {
343  if(_deselect) curve->get_knotvector_ref()->deselect(*it);
344  else curve->get_knotvector_ref()->select(*it);
345  }
346  }
347  }
348 
349  QString selection = "selectKnots(ObjectId, [ " + QString::number(_ids[0]);
350 
351  for (uint i = 1 ; i < _ids.size(); ++i) {
352  selection += ", " + QString::number(_ids[i]);
353  }
354 
355  selection += " ])";
356 
357 
358  emit scriptInfo(selection);
359 }
360 
362 
363  BaseObjectData* object = 0;
364 
365  IdList list;
366 
367  if(!PluginFunctions::getObject(_objectId, object)) {
368  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
369  return list;
370  }
371 
373  if(curve) {
374  for(unsigned int i = 0; i < curve->n_knots(); ++i) {
375  if(curve->get_knotvector_ref()->selected(i))
376  list.push_back((int)i);
377  }
378  }
379 
380  return list;
381 }
IdList getKnotSelection(int _objectId)
Get current knot selection.
void delete_control_point(int _idx)
delete control point at given index
bool getObject(int _identifier, BSplineCurveObject *&_object)
void selectKnots(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific knots of a curve.
void selectAllKnots(int _objectId)
Select all knots of a curve.
BSplineCurve * splineCurve(BaseObjectData *_object)
Get a Bspline curve from an object.
unsigned int n_control_points() const
Returns the number of control points.
unsigned int n_knots() const
Returns the number of knots.
void deleteSelectedKnots(int _objectId)
Delete selected knots.
IdList getControlPointSelection(int _objectId)
Get current control point selection.
BSplineCurveObject * bsplineCurveObject(BaseObjectData *_object)
Cast an BaseObject to a BSplineCurveObject if possible.
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode()
Get the scenegraph Node.
void deselectAllKnots(int _objectId)
Deselect all knots of a curve.
void selectAllControlPoints(int _objectId)
Select all control points of a curve.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
void selectControlPoints(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific control points of a curve.
Knotvector * get_knotvector_ref()
get a reference to the knotvector
void deleteSelectedControlPoints(int _objectId)
Delete selected control points.
void deselectAllControlPoints(int _objectId)
Deselect all control points of a curve.
void invertControlPointSelection(int _objectId)
Invert control point selection.
void invertKnotSelection(int _objectId)
Invert knot selection.