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 #include "BSplineCurveSelectionPlugin.hh"
45 
47 
48  BaseObjectData* object = 0;
49 
50  if(!PluginFunctions::getObject(_objectId, object)) {
51  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
52  return;
53  }
54 
57 
58  if(curve) {
59  for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
60  curve->select_controlpoint(i);
61  }
62  }
63 
64  // Switch to control point selection mode
65  if(co)
67 
68  emit scriptInfo("selectAllControlPoints(ObjectId)");
69 }
70 
72 
73  BaseObjectData* object = 0;
74 
75  if(!PluginFunctions::getObject(_objectId, object)) {
76  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
77  return;
78  }
79 
81  if(curve) {
82  for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
83  curve->deselect_controlpoint(i);
84  }
85  }
86 
87  emit scriptInfo("deselectAllControlPoints(ObjectId)");
88 }
89 
91 
92  BaseObjectData* object = 0;
93 
94  if(!PluginFunctions::getObject(_objectId, object)) {
95  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
96  return;
97  }
98 
101 
102  if(curve) {
103  for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
104  if(curve->controlpoint_selected(i))
105  curve->deselect_controlpoint(i);
106  else
107  curve->select_controlpoint(i);
108  }
109  }
110 
111  // Switch to control point selection mode
112  if(co)
114 
115  emit scriptInfo("invertControlPointSelection(ObjectId)");
116 }
117 
119 
120  BaseObjectData* object = 0;
121 
122  if(!PluginFunctions::getObject(_objectId, object)) {
123  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
124  return;
125  }
126 
128  if(curve) {
129 
130  // I know this is a bit crappy, but control point indices
131  // change forcably after each delete operation so we have to
132  // start over each time...
133  bool breakWhile = false;
134  while(!breakWhile) {
135  bool oneFound = false;
136  unsigned int i = 0;
137  for(; i < curve->n_control_points(); ++i) {
138  if(curve->controlpoint_selected(i)) {
139  curve->delete_control_point(i);
140  oneFound = true;
141  break;
142  }
143  }
144 
145  if((i >= curve->n_control_points()) && !oneFound) {
146  // We are through
147  breakWhile = true;
148  }
149  }
150  }
151 
152  emit scriptInfo("deleteSelectedControlPoints(ObjectId)");
153 }
154 
155 void BSplineCurveSelectionPlugin::selectControlPoints(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 
167  if(curve) {
168  for(IdList::const_iterator it = _ids.begin(); it != _ids.end(); ++it) {
169  if(*it < (int)curve->n_control_points()) {
170  if(_deselect) curve->deselect_controlpoint(*it);
171  else curve->select_controlpoint(*it);
172  }
173  }
174  }
175 
176  QString selection = "selectControlPoints(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 
185  emit scriptInfo(selection);
186 }
187 
189 
190  BaseObjectData* object = 0;
191 
192  IdList list;
193 
194  if(!PluginFunctions::getObject(_objectId, object)) {
195  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
196  return list;
197  }
198 
200  if(curve) {
201  for(unsigned int i = 0; i < curve->n_control_points(); ++i) {
202  if(curve->controlpoint_selected(i))
203  list.push_back((int)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 
223 
224  if(curve) {
225  for(unsigned int i = 0; i < curve->n_knots(); ++i) {
226  curve->get_knotvector_ref()->select(i);
227  }
228  }
229 
230  // Switch to control point selection mode
231  if(co)
233 
234  emit scriptInfo("selectAllKnots(ObjectId)");
235 }
236 
238 
239  BaseObjectData* object = 0;
240 
241  if(!PluginFunctions::getObject(_objectId, object)) {
242  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
243  return;
244  }
245 
247 
248  if(curve) {
249  for(unsigned int i = 0; i < curve->n_knots(); ++i) {
250  curve->get_knotvector_ref()->deselect(i);
251  }
252  }
253 
254  emit scriptInfo("deselectAllKnots(ObjectId)");
255 }
256 
258 
259  BaseObjectData* object = 0;
260 
261  if(!PluginFunctions::getObject(_objectId, object)) {
262  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
263  return;
264  }
265 
268 
269  if(curve) {
270  for(unsigned int i = 0; i < curve->n_knots(); ++i) {
271  if(curve->get_knotvector_ref()->selected(i))
272  curve->get_knotvector_ref()->deselect(i);
273  else
274  curve->get_knotvector_ref()->select(i);
275  }
276  }
277 
278  // Switch to control point selection mode
279  if(co)
281 
282  emit scriptInfo("invertKnotSelection(ObjectId)");
283 }
284 
286 
287  BaseObjectData* object = 0;
288 
289  if(!PluginFunctions::getObject(_objectId, object)) {
290  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
291  return;
292  }
293 
295  if(curve) {
296 
297  // I know this is a bit crappy, but knot indices
298  // change forcably after each delete operation so we have to
299  // start over each time...
300  bool breakWhile = false;
301  while(!breakWhile) {
302  bool oneFound = false;
303  unsigned int i = 0;
304  for(; i < curve->n_knots(); ++i) {
305  if(curve->get_knotvector_ref()->selected(i)) {
306  curve->get_knotvector_ref()->deleteKnot(i);
307  oneFound = true;
308  break;
309  }
310  }
311 
312  if((i >= curve->n_knots()) && !oneFound) {
313  // We are through
314  breakWhile = true;
315  }
316  }
317  }
318 
319  emit scriptInfo("deleteSelectedKnots(ObjectId)");
320 }
321 
322 void BSplineCurveSelectionPlugin::selectKnots(int _objectId, const IdList& _ids, bool _deselect) {
323 
324  if(_ids.empty()) return;
325 
326  BaseObjectData* object = 0;
327 
328  if(!PluginFunctions::getObject(_objectId, object)) {
329  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
330  return;
331  }
332 
334  if(curve) {
335  for(IdList::const_iterator it = _ids.begin(); it != _ids.end(); ++it) {
336  if(*it < (int)curve->n_knots()) {
337  if(_deselect) curve->get_knotvector_ref()->deselect(*it);
338  else curve->get_knotvector_ref()->select(*it);
339  }
340  }
341  }
342 
343  QString selection = "selectKnots(ObjectId, [ " + QString::number(_ids[0]);
344 
345  for (uint i = 1 ; i < _ids.size(); ++i) {
346  selection += ", " + QString::number(_ids[i]);
347  }
348 
349  selection += " ])";
350 
351 
352  emit scriptInfo(selection);
353 }
354 
356 
357  BaseObjectData* object = 0;
358 
359  IdList list;
360 
361  if(!PluginFunctions::getObject(_objectId, object)) {
362  emit log(LOGERR, tr("Could not get object with id %1").arg(_objectId));
363  return list;
364  }
365 
367  if(curve) {
368  for(unsigned int i = 0; i < curve->n_knots(); ++i) {
369  if(curve->get_knotvector_ref()->selected(i))
370  list.push_back((int)i);
371  }
372  }
373 
374  return list;
375 }
BSplineCurve * splineCurve(BaseObjectData *_object)
Get a Bspline curve from an object.
unsigned int n_knots() const
Returns the number of knots.
BSplineCurveObject * bsplineCurveObject(BaseObjectData *_object)
Cast an BaseObject to a BSplineCurveObject if possible.
IdList getControlPointSelection(int _objectId)
Get current control point selection.
void invertKnotSelection(int _objectId)
Invert knot selection.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
void delete_control_point(int _idx)
delete control point at given index
void selectAllKnots(int _objectId)
Select all knots of a curve.
void selectAllControlPoints(int _objectId)
Select all control points of a curve.
void deselectAllKnots(int _objectId)
Deselect all knots of a curve.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:181
void deleteSelectedControlPoints(int _objectId)
Delete selected control points.
void invertControlPointSelection(int _objectId)
Invert control point selection.
void selectControlPoints(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific control points of a curve.
unsigned int n_control_points() const
Returns the number of control points.
void deselectAllControlPoints(int _objectId)
Deselect all control points of a curve.
Knotvector * get_knotvector_ref()
get a reference to the knotvector
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode()
Get the scenegraph Node.
void deleteSelectedKnots(int _objectId)
Delete selected knots.
void selectKnots(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific knots of a curve.
IdList getKnotSelection(int _objectId)
Get current knot selection.