Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
52 void BSplineCurveSelectionPlugin::selectAllControlPoints(int _objectId) {
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
61 BSplineCurve* curve = PluginFunctions::splineCurve(object);
62 BSplineCurveObject* co = PluginFunctions::bsplineCurveObject(object);
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)
72 co->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::CONTROLPOINT);
73
74 emit scriptInfo("selectAllControlPoints(ObjectId)");
75 }
76
77 void BSplineCurveSelectionPlugin::deselectAllControlPoints(int _objectId) {
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
86 BSplineCurve* curve = PluginFunctions::splineCurve(object);
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
96 void BSplineCurveSelectionPlugin::invertControlPointSelection(int _objectId) {
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
105 BSplineCurve* curve = PluginFunctions::splineCurve(object);
106 BSplineCurveObject* co = PluginFunctions::bsplineCurveObject(object);
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)
119 co->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::CONTROLPOINT);
120
121 emit scriptInfo("invertControlPointSelection(ObjectId)");
122 }
123
124 void BSplineCurveSelectionPlugin::deleteSelectedControlPoints(int _objectId) {
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
133 BSplineCurve* curve = PluginFunctions::splineCurve(object);
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
172 BSplineCurve* curve = PluginFunctions::splineCurve(object);
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
194 IdList BSplineCurveSelectionPlugin::getControlPointSelection(int _objectId) {
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
205 BSplineCurve* curve = PluginFunctions::splineCurve(object);
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
218 void BSplineCurveSelectionPlugin::selectAllKnots(int _objectId) {
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
227 BSplineCurve* curve = PluginFunctions::splineCurve(object);
228 BSplineCurveObject* co = PluginFunctions::bsplineCurveObject(object);
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)
238 co->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::KNOTVECTOR);
239
240 emit scriptInfo("selectAllKnots(ObjectId)");
241 }
242
243 void BSplineCurveSelectionPlugin::deselectAllKnots(int _objectId) {
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
252 BSplineCurve* curve = PluginFunctions::splineCurve(object);
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
263 void BSplineCurveSelectionPlugin::invertKnotSelection(int _objectId) {
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
272 BSplineCurve* curve = PluginFunctions::splineCurve(object);
273 BSplineCurveObject* co = PluginFunctions::bsplineCurveObject(object);
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)
286 co->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::KNOTVECTOR);
287
288 emit scriptInfo("invertKnotSelection(ObjectId)");
289 }
290
291 void BSplineCurveSelectionPlugin::deleteSelectedKnots(int _objectId) {
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
300 BSplineCurve* curve = PluginFunctions::splineCurve(object);
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
339 BSplineCurve* curve = PluginFunctions::splineCurve(object);
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
361 IdList BSplineCurveSelectionPlugin::getKnotSelection(int _objectId) {
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
372 BSplineCurve* curve = PluginFunctions::splineCurve(object);
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 }
ACG::BSplineCurveT::get_knotvector_ref
Knotvector * get_knotvector_ref()
get a reference to the knotvector
Definition: BSplineCurveT.hh:112
BSplineCurveSelectionPlugin::selectAllControlPoints
void selectAllControlPoints(int _objectId)
Select all control points of a curve.
Definition: BSplineCurveSelectionFunctions.cc:52
BSplineCurveSelectionPlugin::deselectAllControlPoints
void deselectAllControlPoints(int _objectId)
Deselect all control points of a curve.
Definition: BSplineCurveSelectionFunctions.cc:77
LOGERR
Definition: LoggingInterface.hh:107
BSplineCurveSelectionPlugin::invertKnotSelection
void invertKnotSelection(int _objectId)
Invert knot selection.
Definition: BSplineCurveSelectionFunctions.cc:263
BaseObjectData
Definition: BaseObjectData.hh:105
BSplineCurveSelectionPlugin::deselectAllKnots
void deselectAllKnots(int _objectId)
Deselect all knots of a curve.
Definition: BSplineCurveSelectionFunctions.cc:243
ACG::BSplineCurveT
Definition: BSplineCurveT.hh:88
ACG::BSplineCurveT::delete_control_point
void delete_control_point(int _idx)
delete control point at given index
Definition: BSplineCurveT.cc:211
BSplineCurveSelectionPlugin::selectAllKnots
void selectAllKnots(int _objectId)
Select all knots of a curve.
Definition: BSplineCurveSelectionFunctions.cc:218
PluginFunctions::getObject
bool getObject(int _identifier, BSplineCurveObject *&_object)
Definition: PluginFunctionsBSplineCurve.cc:75
BSplineCurveSelectionPlugin::getControlPointSelection
IdList getControlPointSelection(int _objectId)
Get current control point selection.
Definition: BSplineCurveSelectionFunctions.cc:194
BSplineCurveSelectionPlugin::getKnotSelection
IdList getKnotSelection(int _objectId)
Get current knot selection.
Definition: BSplineCurveSelectionFunctions.cc:361
IdList
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
PluginFunctions::splineCurve
BSplineCurve * splineCurve(BaseObjectData *_object)
Get a Bspline curve from an object.
Definition: PluginFunctionsBSplineCurve.cc:95
BSplineCurveSelectionPlugin::invertControlPointSelection
void invertControlPointSelection(int _objectId)
Invert control point selection.
Definition: BSplineCurveSelectionFunctions.cc:96
BSplineCurveSelectionPlugin::deleteSelectedControlPoints
void deleteSelectedControlPoints(int _objectId)
Delete selected control points.
Definition: BSplineCurveSelectionFunctions.cc:124
BSplineCurveObject::splineCurveNode
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode()
Get the scenegraph Node.
Definition: BSplineCurveObject.cc:255
BSplineCurveObject
Definition: BSplineCurveObject.hh:84
BSplineCurveSelectionPlugin::deleteSelectedKnots
void deleteSelectedKnots(int _objectId)
Delete selected knots.
Definition: BSplineCurveSelectionFunctions.cc:291
BSplineCurveSelectionPlugin::selectKnots
void selectKnots(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific knots of a curve.
Definition: BSplineCurveSelectionFunctions.cc:328
PluginFunctions::bsplineCurveObject
BSplineCurveObject * bsplineCurveObject(BaseObjectData *_object)
Cast an BaseObject to a BSplineCurveObject if possible.
Definition: PluginFunctionsBSplineCurve.cc:106
ACG::BSplineCurveT::n_knots
unsigned int n_knots() const
Returns the number of knots.
Definition: BSplineCurveT.hh:173
ACG::BSplineCurveT::n_control_points
unsigned int n_control_points() const
Returns the number of control points.
Definition: BSplineCurveT.hh:170
BSplineCurveSelectionPlugin::selectControlPoints
void selectControlPoints(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific control points of a curve.
Definition: BSplineCurveSelectionFunctions.cc:161
ACG::SceneGraph::BSplineCurveNodeT
Definition: BSplineCurveNodeT.hh:91