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
VertexSelection.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 * $Author$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 #include "MeshObjectSelectionPlugin.hh"
51
52 #include <MeshTools/MeshSelectionT.hh>
53
54 //=========================================================
55 //==== Vertex selections
56 //=========================================================
57
58 void MeshObjectSelectionPlugin::selectVertices(int _objectId, IdList _vertexList) {
59
60 if(_vertexList.empty() ) return;
61
62 BaseObjectData* object = 0;
63 if (!PluginFunctions::getObject(_objectId,object)) {
64 emit log(LOGERR,tr("selectVertices: unable to get object"));
65 return;
66 }
67
68 if (object->dataType() == DATA_TRIANGLE_MESH)
69 MeshSelection::selectVertices(PluginFunctions::triMesh(object), _vertexList);
70 else if (object->dataType() == DATA_POLY_MESH)
71 MeshSelection::selectVertices(PluginFunctions::polyMesh(object), _vertexList);
72 else {
73 emit log(LOGERR,tr("selectAllVertices: Unsupported object Type"));
74 return;
75 }
76
77 QString selection = "selectVertices(ObjectId(" + QString::number(_objectId) + "), [ " + QString::number(_vertexList[0]);
78
79 for (uint i = 1 ; i < _vertexList.size(); ++i) {
80 selection += ", " + QString::number(_vertexList[i]);
81 }
82
83 selection += " ])";
84
85 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
86 emit scriptInfo(selection);
87 }
88
89 //=========================================================
90
91 void MeshObjectSelectionPlugin::unselectVertices(int _objectId, IdList _vertexList) {
92
93 if(_vertexList.empty() ) return;
94
95 BaseObjectData* object = 0;
96 if (!PluginFunctions::getObject(_objectId,object)) {
97 emit log(LOGERR,tr("unselectVertices: unable to get object"));
98 return;
99 }
100
101 if (object->dataType() == DATA_TRIANGLE_MESH)
102 MeshSelection::unselectVertices(PluginFunctions::triMesh(object), _vertexList);
103 else if (object->dataType() == DATA_POLY_MESH)
104 MeshSelection::unselectVertices(PluginFunctions::polyMesh(object), _vertexList);
105 else {
106 emit log(LOGERR,tr("unselectVertices: Unsupported object Type"));
107 return;
108 }
109
110 QString selection = "unselectVertices(ObjectId(" + QString::number(_objectId) + "), [ " + QString::number(_vertexList[0]);
111
112 for (uint i = 1 ; i < _vertexList.size(); ++i) {
113 selection += ", " + QString::number(_vertexList[i]);
114 }
115
116 selection += " ])";
117
118 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
119 emit scriptInfo(selection);
120 }
121
122
123 //=========================================================
124
125
126 void MeshObjectSelectionPlugin::selectAllVertices(int _objectId) {
127
128 BaseObjectData* object;
129 if (!PluginFunctions::getObject(_objectId,object)) {
130 emit log(LOGERR,tr("selectAllVertices: unable to get object"));
131 return;
132 }
133
134 if (object->dataType() == DATA_TRIANGLE_MESH)
135 MeshSelection::selectAllVertices(PluginFunctions::triMesh(object));
136 else if (object->dataType() == DATA_POLY_MESH)
137 MeshSelection::selectAllVertices(PluginFunctions::polyMesh(object));
138 else {
139 emit log(LOGERR,tr("selectAllVertices: Unsupported object Type"));
140 return;
141 }
142
143 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
144 emit scriptInfo("selectAllVertices(ObjectId(" + QString::number(_objectId) + "))");
145 }
146
147 //=========================================================
148
149 void MeshObjectSelectionPlugin::clearVertexSelection(int _objectId) {
150
151 BaseObjectData* object;
152 if (!PluginFunctions::getObject(_objectId,object)) {
153 emit log(LOGERR,tr("clearVertexSelection: unable to get object"));
154 return;
155 }
156
157 if (object->dataType() == DATA_TRIANGLE_MESH)
158 MeshSelection::clearVertexSelection(PluginFunctions::triMesh(object));
159 else if (object->dataType() == DATA_POLY_MESH)
160 MeshSelection::clearVertexSelection(PluginFunctions::polyMesh(object));
161 else {
162 emit log(LOGERR,tr("clearVertexSelection: Unsupported object Type"));
163 return;
164 }
165
166 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
167 emit scriptInfo("clearVertexSelection(ObjectId(" + QString::number(_objectId) + "))");
168 }
169
170 //=========================================================
171
172 void MeshObjectSelectionPlugin::invertVertexSelection(int _objectId) {
173
174 BaseObjectData* object;
175 if (!PluginFunctions::getObject(_objectId,object)) {
176 emit log(LOGERR,tr("invertVertexSelection: unable to get object"));
177 return;
178 }
179
180 if (object->dataType() == DATA_TRIANGLE_MESH)
181 MeshSelection::invertVertexSelection(PluginFunctions::triMesh(object));
182 else if (object->dataType() == DATA_POLY_MESH)
183 MeshSelection::invertVertexSelection(PluginFunctions::polyMesh(object));
184 else {
185 emit log(LOGERR,tr("invertVertexSelection: Unsupported object Type"));
186 return;
187 }
188
189 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
190 emit scriptInfo("invertVertexSelection(ObjectId(" + QString::number(_objectId) + "))");
191 }
192
193 //=========================================================
194
195 void MeshObjectSelectionPlugin::selectBoundaryVertices(int _objectId) {
196
197 BaseObjectData* object;
198 if (!PluginFunctions::getObject(_objectId,object)) {
199 emit log(LOGERR,tr("selectBoundaryVertices: unable to get object"));
200 return;
201 }
202
203 if (object->dataType() == DATA_TRIANGLE_MESH)
204 MeshSelection::selectBoundaryVertices(PluginFunctions::triMesh(object));
205 else if (object->dataType() == DATA_POLY_MESH)
206 MeshSelection::selectBoundaryVertices(PluginFunctions::polyMesh(object));
207 else {
208 emit log(LOGERR,tr("selectBoundaryVertices: Unsupported object Type"));
209 return;
210 }
211
212 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
213 emit scriptInfo("selectBoundaryVertices(ObjectId(" + QString::number(_objectId) + "))");
214 }
215
216 //=========================================================
217
218 void MeshObjectSelectionPlugin::selectClosestBoundaryVertices(int _objectId, int _vertexId) {
219
220 BaseObjectData* object;
221 if (!PluginFunctions::getObject(_objectId,object)) {
222 emit log(LOGERR,tr("selectClosestBoundaryVertices: unable to get object"));
223 return;
224 }
225
226 if (object->dataType() == DATA_TRIANGLE_MESH) {
227 closestBoundarySelection(PluginFunctions::triMesh(object),_vertexId, vertexType_, false);
228 } else if (object->dataType() == DATA_POLY_MESH) {
229 closestBoundarySelection(PluginFunctions::polyMesh(object),_vertexId, vertexType_, false);
230 } else {
231 emit log(LOGERR,tr("selectClosestBoundaryVertices: Unsupported object Type"));
232 return;
233 }
234
235 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
236 emit scriptInfo("selectClosestBoundaryVertices(ObjectId(" + QString::number(_objectId) + "), VertexId)");
237 }
238
239 //=========================================================
240
241 void MeshObjectSelectionPlugin::shrinkVertexSelection(int _objectId) {
242
243 BaseObjectData* object;
244 if (!PluginFunctions::getObject(_objectId,object)) {
245 emit log(LOGERR,tr("shrinkVertexSelection: unable to get object"));
246 return;
247 }
248
249 if (object->dataType() == DATA_TRIANGLE_MESH)
250 MeshSelection::shrinkVertexSelection(PluginFunctions::triMesh(object));
251 else if (object->dataType() == DATA_POLY_MESH)
252 MeshSelection::shrinkVertexSelection(PluginFunctions::polyMesh(object));
253 else {
254 emit log(LOGERR,tr("shrinkVertexSelection: Unsupported object Type"));
255 return;
256 }
257
258 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
259 emit scriptInfo("shrinkVertexSelection(ObjectId(" + QString::number(_objectId) + "))");
260 }
261
262 //=========================================================
263
264 void MeshObjectSelectionPlugin::growVertexSelection(int _objectId) {
265
266 BaseObjectData* object;
267 if (!PluginFunctions::getObject(_objectId,object)) {
268 emit log(LOGERR,tr("growVertexSelection: unable to get object"));
269 return;
270 }
271
272 if (object->dataType() == DATA_TRIANGLE_MESH)
273 MeshSelection::growVertexSelection(PluginFunctions::triMesh(object));
274 else if (object->dataType() == DATA_POLY_MESH)
275 MeshSelection::growVertexSelection(PluginFunctions::polyMesh(object));
276 else {
277 emit log(LOGERR,tr("growVertexSelection: Unsupported object Type"));
278 return;
279 }
280
281 emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
282 emit scriptInfo("growVertexSelection(ObjectId(" + QString::number(_objectId) + "))");
283 }
284
285 //=========================================================
286
287 IdList MeshObjectSelectionPlugin::getVertexSelection(int _objectId) {
288
289 BaseObjectData* object;
290 if (!PluginFunctions::getObject(_objectId,object)) {
291 emit log(LOGERR,tr("getVertexSelection: unable to get object"));
292 return IdList(0);
293 }
294
295 emit scriptInfo("getVertexSelection(ObjectId(" + QString::number(_objectId) + "))");
296
297 if (object->dataType() == DATA_TRIANGLE_MESH)
298 return MeshSelection::getVertexSelection(PluginFunctions::triMesh(object));
299 else if (object->dataType() == DATA_POLY_MESH)
300 return MeshSelection::getVertexSelection(PluginFunctions::polyMesh(object));
301 else {
302 emit log(LOGERR,tr("getVertexSelection: Unsupported object Type"));
303 return IdList(0);
304 }
305
306 return IdList(0);
307 }
308
309 //=========================================================
310
311 void MeshObjectSelectionPlugin::deleteVertexSelection(int _objectId) {
312
313 BaseObjectData* object;
314 if (!PluginFunctions::getObject(_objectId,object)) {
315 emit log(LOGERR,tr("deleteVertexSelection: unable to get object"));
316 return;
317 }
318
319 if (object->dataType() == DATA_TRIANGLE_MESH)
320 deleteSelection(PluginFunctions::triMesh(object), vertexType_);
321 else if (object->dataType() == DATA_POLY_MESH)
322 deleteSelection(PluginFunctions::polyMesh(object), vertexType_);
323 else {
324 emit log(LOGERR,tr("deleteVertexSelection: Unsupported object Type"));
325 return;
326 }
327
328 emit updatedObject(object->id(), UPDATE_ALL);
329 emit scriptInfo("deleteVertexSelection(ObjectId(" + QString::number(_objectId) + "))");
330 }
331
332 //=========================================================
333
334 int MeshObjectSelectionPlugin::createMeshFromVertexSelection( int _objectId) {
335 return createMeshFromSelection(_objectId, vertexType_ );
336 }
337
338 //=========================================================
339
341 void MeshObjectSelectionPlugin::colorizeVertexSelection(int _objectId, int r, int g, int b, int a) {
342
343 BaseObjectData* object;
344 if (!PluginFunctions::getObject(_objectId, object)) {
345 emit log(LOGERR,"colorizeVertexSelection: unable to get object");
346 return;
347 }
348
349 if (object->dataType() == DATA_TRIANGLE_MESH) {
350 colorizeSelection(PluginFunctions::triMesh(object), vertexType_, r, g, b, a);
351 } else if (object->dataType() == DATA_POLY_MESH) {
352 colorizeSelection(PluginFunctions::polyMesh(object), vertexType_, r, g, b, a);
353 } else {
354 emit log(LOGERR,"colorizeVertexSelection: Unsupported object Type");
355 return;
356 }
357
358 emit scriptInfo("colorizeVertexSelection(ObjectId(" + QString::number(_objectId) + "), "
359 + QString::number(r) + ", " + QString::number(g) + ", " + QString::number(b) + ")");
360
361 emit updatedObject(_objectId, UPDATE_COLOR);
362 }
363
364 //=========================================================
365 //==== Modeling Area selections
366 //=========================================================
367
368 void MeshObjectSelectionPlugin::selectHandleVertices(int _objectId, IdList _vertexList) {
369
370 BaseObjectData* object;
371 if (!PluginFunctions::getObject(_objectId,object)) {
372 emit log(LOGERR,tr("selectHandleVertices: unable to get object"));
373 return;
374 }
375
376 if (_vertexList.empty() )
377 return;
378
379 if (object->dataType() == DATA_TRIANGLE_MESH){
380 MeshSelection::setArea(PluginFunctions::triMesh(object), _vertexList, HANDLEAREA, true);
381 update_regions(PluginFunctions::triMesh(object));
382 } else if (object->dataType() == DATA_POLY_MESH){
383 MeshSelection::setArea(PluginFunctions::polyMesh(object), _vertexList, HANDLEAREA, true);
384 update_regions(PluginFunctions::polyMesh(object));
385 } else {
386 emit log(LOGERR,tr("selectHandleVertices: Unsupported object Type"));
387 return;
388 }
389
390 QString selection = "selectHandleVertices(ObjectId(" + QString::number(_objectId) + "), [ " + QString::number(_vertexList[0]);
391
392 for (uint i = 1 ; i < _vertexList.size(); ++i) {
393 selection += ", " + QString::number(_vertexList[i]);
394 }
395
396 selection += " ])";
397
398 emit updatedObject(object->id(), UPDATE_ALL);
399 emit scriptInfo(selection);
400 }
401
402 //=========================================================
403
404 void MeshObjectSelectionPlugin::unselectHandleVertices(int _objectId, IdList _vertexList) {
405
406 if(_vertexList.empty()) return;
407
408 BaseObjectData* object = 0;
409 if (!PluginFunctions::getObject(_objectId,object)) {
410 emit log(LOGERR,tr("unselectHandleVertices: unable to get object"));
411 return;
412 }
413
414 if (object->dataType() == DATA_TRIANGLE_MESH)
415 MeshSelection::setArea(PluginFunctions::triMesh(object), _vertexList, HANDLEAREA, false);
416 else if (object->dataType() == DATA_POLY_MESH)
417 MeshSelection::setArea(PluginFunctions::polyMesh(object), _vertexList, HANDLEAREA, false);
418 else {
419 emit log(LOGERR,tr("unselectHandleVertices: Unsupported object Type"));
420 return;
421 }
422
423 QString selection = "unselectHandleVertices(ObjectId(" + QString::number(_objectId) + "), [ " + QString::number(_vertexList[0]);
424
425 for (uint i = 1 ; i < _vertexList.size(); ++i) {
426 selection += ", " + QString::number(_vertexList[i]);
427 }
428
429 selection += " ])";
430
431 emit updatedObject(object->id(), UPDATE_ALL);
432 emit scriptInfo(selection);
433 }
434
435 //=========================================================
436
437 void MeshObjectSelectionPlugin::clearHandleVertices(int _objectId) {
438
439 BaseObjectData* object;
440 if (!PluginFunctions::getObject(_objectId,object)) {
441 emit log(LOGERR,tr("clearHandleVertices: unable to get object"));
442 return;
443 }
444
445 if (object->dataType() == DATA_TRIANGLE_MESH)
446 MeshSelection::setArea(PluginFunctions::triMesh(object), HANDLEAREA, false);
447 else if (object->dataType() == DATA_POLY_MESH)
448 MeshSelection::setArea(PluginFunctions::polyMesh(object), HANDLEAREA, false);
449 else {
450 emit log(LOGERR,tr("clearHandleVertices: Unsupported object Type"));
451 return;
452 }
453
454 emit updatedObject(object->id(), UPDATE_ALL);
455 emit scriptInfo("clearHandleVertices(ObjectId(" + QString::number(_objectId) + "))");
456 }
457
458 //=========================================================
459
460 void MeshObjectSelectionPlugin::setAllHandleVertices(int _objectId) {
461
462 BaseObjectData* object;
463 if (!PluginFunctions::getObject(_objectId,object)) {
464 emit log(LOGERR,tr("setAllHandleVertices: unable to get object"));
465 return;
466 }
467
468 if (object->dataType() == DATA_TRIANGLE_MESH)
469 MeshSelection::setArea(PluginFunctions::triMesh(object), HANDLEAREA, true);
470 else if (object->dataType() == DATA_POLY_MESH)
471 MeshSelection::setArea(PluginFunctions::polyMesh(object), HANDLEAREA, true);
472 else {
473 emit log(LOGERR,tr("setAllHandleVertices: Unsupported object Type"));
474 return;
475 }
476
477 emit updatedObject(object->id(), UPDATE_ALL);
478 emit scriptInfo("setAllHandleVertices(ObjectId(" + QString::number(_objectId) + "))");
479 }
480
481 //=========================================================
482
483 IdList MeshObjectSelectionPlugin::getHandleVertices(int _objectId) {
484
485 BaseObjectData* object;
486 if (!PluginFunctions::getObject(_objectId,object)) {
487 emit log(LOGERR,tr("getHandleVertices: unable to get object"));
488 return IdList(0);
489 }
490
491 emit scriptInfo("getHandleVertices(ObjectId(" + QString::number(_objectId) + "))");
492
493 if (object->dataType() == DATA_TRIANGLE_MESH)
494 return MeshSelection::getArea(PluginFunctions::triMesh(object), HANDLEAREA);
495 else if (object->dataType() == DATA_POLY_MESH)
496 return MeshSelection::getArea(PluginFunctions::polyMesh(object), HANDLEAREA);
497 else {
498 emit log(LOGERR,tr("getHandleVertices: Unsupported object Type"));
499 return IdList(0);;
500 }
501
502 return IdList(0);
503 }
504
505 //=========================================================
506 //==== Modeling Area selections
507 //=========================================================
508
509 void MeshObjectSelectionPlugin::selectModelingVertices(int _objectId, IdList _vertexList) {
510
511 if(_vertexList.empty() ) return;
512
513 BaseObjectData* object = 0;
514 if (!PluginFunctions::getObject(_objectId,object)) {
515 emit log(LOGERR,tr("selectModelingVertices: unable to get object"));
516 return;
517 }
518
519 if (object->dataType() == DATA_TRIANGLE_MESH) {
520 MeshSelection::setArea(PluginFunctions::triMesh(object), _vertexList, AREA, true);
521 update_regions(PluginFunctions::triMesh(object));
522 } else if (object->dataType() == DATA_POLY_MESH){
523 MeshSelection::setArea(PluginFunctions::polyMesh(object), _vertexList, AREA, true);
524 update_regions(PluginFunctions::polyMesh(object));
525 } else {
526 emit log(LOGERR,tr("selectModelingVertices: Unsupported object Type"));
527 return;
528 }
529
530 QString selection = "selectModelingVertices(ObjectId(" + QString::number(_objectId) + "), [ " + QString::number(_vertexList[0]);
531
532 for (uint i = 1 ; i < _vertexList.size(); ++i) {
533 selection += ", " + QString::number(_vertexList[i]);
534 }
535
536 selection += " ])";
537
538 emit updatedObject(object->id(), UPDATE_ALL);
539 emit scriptInfo(selection);
540 }
541
542 //=========================================================
543
544 void MeshObjectSelectionPlugin::unselectModelingVertices(int _objectId, IdList _vertexList) {
545
546 if(_vertexList.empty() ) return;
547
548 BaseObjectData* object = 0;
549 if (!PluginFunctions::getObject(_objectId,object)) {
550 emit log(LOGERR,tr("unselectModelingVertices: unable to get object"));
551 return;
552 }
553
554 if (object->dataType() == DATA_TRIANGLE_MESH)
555 MeshSelection::setArea(PluginFunctions::triMesh(object), _vertexList, AREA, false);
556 else if (object->dataType() == DATA_POLY_MESH)
557 MeshSelection::setArea(PluginFunctions::polyMesh(object), _vertexList, AREA, false);
558 else{
559 emit log(LOGERR,tr("unselectModelingVertices: Unsupported object Type"));
560 return;
561 }
562
563 QString selection = "unselectModelingVertices(ObjectId(" + QString::number(_objectId) + "), [ " + QString::number(_vertexList[0]);
564
565 for (uint i = 1 ; i < _vertexList.size(); ++i) {
566 selection += ", " + QString::number(_vertexList[i]);
567 }
568
569 selection += " ])";
570
571 emit updatedObject(object->id(), UPDATE_ALL);
572 emit scriptInfo(selection);
573 }
574
575 // =========================================================
576
577 void MeshObjectSelectionPlugin::selectVerticesByValue(int _objectId, QString _component, bool _greater, double _value ) {
578 BaseObjectData* object = 0;
579 if (!PluginFunctions::getObject(_objectId,object)) {
580 emit log(LOGERR,tr("selectVerticesByValue: unable to get object"));
581 return;
582 }
583
584 if (object->dataType() == DATA_TRIANGLE_MESH)
585 selectVerticesByValue(PluginFunctions::triMesh(object), _component, _greater, _value);
586 else if (object->dataType() == DATA_POLY_MESH)
587 selectVerticesByValue(PluginFunctions::polyMesh(object), _component, _greater, _value);
588 else{
589 emit log(LOGERR,tr("selectVerticesByValue: Unsupported object Type"));
590 return;
591 }
592
593 emit updatedObject(object->id(), UPDATE_SELECTION);
594
596
597 }
598
599
600 //=========================================================
601
602 void MeshObjectSelectionPlugin::clearModelingVertices(int _objectId) {
603
604 BaseObjectData* object;
605 if (!PluginFunctions::getObject(_objectId,object)) {
606 emit log(LOGERR,tr("clearModelingVertices: unable to get object"));
607 return;
608 }
609
610 if (object->dataType() == DATA_TRIANGLE_MESH)
611 MeshSelection::setArea(PluginFunctions::triMesh(object), AREA, false);
612 else if (object->dataType() == DATA_POLY_MESH)
613 MeshSelection::setArea(PluginFunctions::polyMesh(object), AREA, false);
614 else{
615 emit log(LOGERR,tr("clearModelingVertices: Unsupported object Type"));
616 return;
617 }
618
619 emit updatedObject(object->id(), UPDATE_ALL);
620 emit scriptInfo("clearModelingVertices(ObjectId(" + QString::number(_objectId) + "))");
621 }
622
623 //=========================================================
624
625 void MeshObjectSelectionPlugin::setAllModelingVertices(int _objectId) {
626
627 BaseObjectData* object;
628 if (!PluginFunctions::getObject(_objectId,object)) {
629 emit log(LOGERR,tr("setAllModelingVertices: unable to get object"));
630 return;
631 }
632
633 if (object->dataType() == DATA_TRIANGLE_MESH)
634 MeshSelection::setArea(PluginFunctions::triMesh(object), AREA, true);
635 else if (object->dataType() == DATA_POLY_MESH)
636 MeshSelection::setArea(PluginFunctions::polyMesh(object), AREA, true);
637 else{
638 emit log(LOGERR,tr("setAllModelingVertices: Unsupported object Type"));
639 return;
640 }
641
642 emit updatedObject(object->id(), UPDATE_ALL);
643 emit scriptInfo("setAllModelingVertices(ObjectId(" + QString::number(_objectId) + "))");
644 }
645
646 //=========================================================
647 IdList MeshObjectSelectionPlugin::getModelingVertices(int _objectId) {
648 BaseObjectData* object;
649 if (!PluginFunctions::getObject(_objectId,object)) {
650 emit log(LOGERR,tr("getModelingVertices: unable to get object"));
651 return IdList(0);
652 }
653
654 emit scriptInfo("getModelingVertices(ObjectId(" + QString::number(_objectId) + "))");
655
656 if (object->dataType() == DATA_TRIANGLE_MESH)
657 return MeshSelection::getArea(PluginFunctions::triMesh(object), AREA);
658 else if (object->dataType() == DATA_POLY_MESH)
659 return MeshSelection::getArea(PluginFunctions::polyMesh(object), AREA);
660 else{
661 emit log(LOGERR,tr("getModelingVertices: Unsupported object Type"));
662 return IdList(0);
663 }
664
665 return IdList(0);
666 }
667
668 //=========================================================
669
670 void MeshObjectSelectionPlugin::loadFlipperModelingSelection(int _objectId, QString _filename) {
671
672 QFile file(_filename);
673
674 if (!file.exists()) {
675 emit log(LOGERR,tr("Unable to find file: ") + _filename);
676 return;
677 }
678
679 if (file.open(QFile::ReadOnly)) {
680
681 QTextStream input(&file);
682 QString header = input.readLine();
683
684 if (!header.contains("Selection")) {
685 emit log(LOGERR,tr("Wrong file header!should be Selection but is ") + header);
686 return;
687 }
688
689 header = input.readLine();
690
691 bool ok = false;
692 uint vertexCount = header.toUInt(&ok);
693
694 if (!ok) {
695 emit log(LOGERR,tr("Unable to parse header. Cant get vertex count from string: ") + header);
696 return;
697 }
698
699 //compare VertexCount
700 BaseObjectData* object;
701 if (!PluginFunctions::getObject(_objectId, object)) {
702 emit log(LOGERR,tr("loadSelection: unable to get object"));
703 return;
704 }
705
706 if (object->dataType() == DATA_TRIANGLE_MESH) {
707 if (PluginFunctions::triMesh(object)->n_vertices() != vertexCount)
708 return;
709 } else if (object->dataType() == DATA_POLY_MESH) {
710 if (PluginFunctions::polyMesh(object)->n_vertices() != vertexCount)
711 return;
712 } else {
713 return;
714 }
715
716 //get selected handles
717 IdList handleVertices;
718 IdList modelingVertices;
719
720 uint vertexId = 0;
721
722 do {
723 // Split into two substrings
724 QStringList inputList = input.readLine().split(" ");
725
726 if (inputList.size() != 2) {
727 emit log(LOGERR,tr("Unable to parse entry at vertex index ") + QString::number(vertexId));
728 return;
729 }
730
731 if (inputList[0] == "1")
732 modelingVertices.push_back(vertexId);
733
734 if (inputList[1] == "1")
735 handleVertices.push_back(vertexId);
736
737 ++vertexId;
738
739 } while (!input.atEnd());
740
741 clearModelingVertices(_objectId);
742 selectModelingVertices(_objectId,modelingVertices);
743
744 clearHandleVertices(_objectId);
745 selectHandleVertices(_objectId,handleVertices);
746
747 } else {
748 emit log(LOGERR,tr("Unable to open selection file!"));
749 }
750 }
751
752 //=========================================================
753
754 void MeshObjectSelectionPlugin::saveFlipperModelingSelection(int _objectId, QString _filename) {
755
756 QFile file(_filename);
757
758 if (file.open(QFile::WriteOnly)) {
759 QTextStream input(&file);
760
761 //get the object
762 BaseObjectData* object;
763 if (!PluginFunctions::getObject(_objectId,object)) {
764 emit log(LOGERR,tr("saveFlipperModelingSelection: unable to get object"));
765 return;
766 }
767
768 if (object->dataType() == DATA_TRIANGLE_MESH) {
769 TriMesh* mesh = PluginFunctions::triMesh(object);
770
771 //header
772 input << "Selection" << endl;
773 input << mesh->n_vertices() << endl;
774
775 std::vector< int > modelingVertices = MeshSelection::getArea(mesh, AREA);
776 std::vector< int > handleVertices = MeshSelection::getArea(mesh, HANDLEAREA);
777
778 std::vector< bool > modelingAll(mesh->n_vertices(), false);
779 std::vector< bool > handleAll(mesh->n_vertices(), false);
780
781 for (uint i=0; i < modelingVertices.size(); i++)
782 modelingAll[ modelingVertices[i] ] = true;
783
784 for (uint i=0; i < handleVertices.size(); i++)
785 handleAll[ handleVertices[i] ] = true;
786
787 for (uint i=0; i < mesh->n_vertices(); i++)
788 input << (int) modelingAll[i] << " " << (int) handleAll[i] << endl;
789
790 } else if (object->dataType() == DATA_POLY_MESH){
791
792 PolyMesh* mesh = PluginFunctions::polyMesh(object);
793
794 //header
795 input << "Selection" << endl;
796 input << mesh->n_vertices() << endl;
797
798 std::vector< int > modelingVertices = MeshSelection::getArea(mesh, AREA);
799 std::vector< int > handleVertices = MeshSelection::getArea(mesh, HANDLEAREA);
800
801 std::vector< bool > modelingAll(mesh->n_vertices(), false);
802 std::vector< bool > handleAll(mesh->n_vertices(), false);
803
804 for (uint i=0; i < modelingVertices.size(); i++)
805 modelingAll[ modelingVertices[i] ] = true;
806
807 for (uint i=0; i < handleVertices.size(); i++)
808 handleAll[ handleVertices[i] ] = true;
809
810 for (uint i=0; i < mesh->n_vertices(); i++)
811 input << (int) modelingAll[i] << " " << (int) handleAll[i] << endl;
812
813 } else {
814 emit log(LOGERR, tr("saveFlipperModelingSelection: Unsupported Type."));
815 }
816 } else {
817 emit log(LOGERR,tr("Unable to open selection file!"));
818 }
819 }
MeshObjectSelectionPlugin::loadFlipperModelingSelection
void loadFlipperModelingSelection(int _objectId, QString _filename)
Load a selection from an Flipper selection file for the given object.
Definition: VertexSelection.cc:670
MeshObjectSelectionPlugin::colorizeSelection
void colorizeSelection(MeshT *_mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha)
Colorize the selection.
Definition: MeshObjectSelectionPluginT.cc:796
MeshObjectSelectionPlugin::selectHandleVertices
void selectHandleVertices(int objectId, IdList _vertexList)
Set vertices to be part of the handle area.
Definition: VertexSelection.cc:368
MeshObjectSelectionPlugin::selectBoundaryVertices
void selectBoundaryVertices(int _objectId)
Select all boundary vertices of the given object.
Definition: VertexSelection.cc:195
OpenMesh::PolyMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:98
MeshObjectSelectionPlugin::setAllModelingVertices
void setAllModelingVertices(int objectId)
Set all vertices to be part of the modeling area.
Definition: VertexSelection.cc:625
UPDATE_SELECTION_VERTICES
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(1)<< 5)
Vertex selection has changed.
LOGERR
Definition: LoggingInterface.hh:107
BaseObjectData
Definition: BaseObjectData.hh:105
MeshObjectSelectionPlugin::deleteSelection
bool deleteSelection(MeshT *_mesh, PrimitiveType _primitiveType)
Delete all selected elements of a mesh.
Definition: MeshObjectSelectionPluginT.cc:57
MeshObjectSelectionPlugin::unselectModelingVertices
void unselectModelingVertices(int objectId, IdList _vertexList)
Remove vertices from modeling area.
Definition: VertexSelection.cc:544
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
PluginFunctions::getObject
bool getObject(int _identifier, BSplineCurveObject *&_object)
Definition: PluginFunctionsBSplineCurve.cc:75
MeshObjectSelectionPlugin::getHandleVertices
IdList getHandleVertices(int objectId)
Get a list of all handle vertices.
Definition: VertexSelection.cc:483
PluginFunctions::polyMesh
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
Definition: PluginFunctionsPolyMesh.cc:134
MeshObjectSelectionPlugin::createMeshFromSelection
void createMeshFromSelection(MeshT &_mesh, MeshT &_newMesh, PrimitiveType _primitiveType)
Create a new mesh from the selection.
Definition: MeshObjectSelectionPluginT.cc:870
MeshObjectSelectionPlugin::selectModelingVertices
void selectModelingVertices(int objectId, IdList _vertexList)
Set vertices to be part of the modeling area.
Definition: VertexSelection.cc:509
MeshObjectSelectionPlugin::selectVerticesByValue
void selectVerticesByValue(int _objectId, QString _component, bool _greater, double _value)
Select vertices by their value.
Definition: VertexSelection.cc:577
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
UPDATE_SELECTION
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
MeshObjectSelectionPlugin::unselectHandleVertices
void unselectHandleVertices(int objectId, IdList _vertexList)
Remove vertices from handle area.
Definition: VertexSelection.cc:404
PluginFunctions::triMesh
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
Definition: PluginFunctionsTriangleMesh.cc:140
MeshObjectSelectionPlugin::setAllHandleVertices
void setAllHandleVertices(int objectId)
Set all vertices to be part of the handle area.
Definition: VertexSelection.cc:460
MeshObjectSelectionPlugin::saveFlipperModelingSelection
void saveFlipperModelingSelection(int _objectId, QString _filename)
Save a selection in Flipper Selection Format.
Definition: VertexSelection.cc:754
IdList
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
MeshObjectSelectionPlugin::clearHandleVertices
void clearHandleVertices(int objectId)
Clear handle Area.
Definition: VertexSelection.cc:437
MeshObjectSelectionPlugin::unselectVertices
void unselectVertices(int objectId, IdList _vertexList)
unselect given vertices
Definition: VertexSelection.cc:91
MeshObjectSelectionPlugin::deleteVertexSelection
void deleteVertexSelection(int _objectId)
Delete vertices and faces that are currently selected.
Definition: VertexSelection.cc:311
DATA_POLY_MESH
#define DATA_POLY_MESH
Definition: PolyMesh.hh:65
MeshObjectSelectionPlugin::growVertexSelection
void growVertexSelection(int _objectId)
Grow the current vertex selection.
Definition: VertexSelection.cc:264
MeshObjectSelectionPlugin::getModelingVertices
IdList getModelingVertices(int objectId)
Get a list of all modeling vertices.
Definition: VertexSelection.cc:647
MeshObjectSelectionPlugin::selectAllVertices
void selectAllVertices(int _objectId)
Select all Vertices.
Definition: VertexSelection.cc:126
MeshObjectSelectionPlugin::colorizeVertexSelection
void colorizeVertexSelection(int _objectId, int _r, int _g, int _b, int a)
Colorize the vertex selection.
Definition: VertexSelection.cc:341
MeshObjectSelectionPlugin::shrinkVertexSelection
void shrinkVertexSelection(int _objectId)
Shrink the current vertex selection.
Definition: VertexSelection.cc:241
MeshObjectSelectionPlugin::vertexType_
SelectionInterface::PrimitiveType vertexType_
Primitive type handles:
Definition: MeshObjectSelectionPlugin.hh:567
MeshObjectSelectionPlugin::selectClosestBoundaryVertices
void selectClosestBoundaryVertices(int _objectId, int _vertexId)
Select all vertices of the boundary close to the given vertex.
Definition: VertexSelection.cc:218
MeshSelectionT.hh
Functions for selection on a mesh.
MeshObjectSelectionPlugin::selectVertices
void selectVertices(int objectId, IdList _vertexList)
select given vertices
Definition: VertexSelection.cc:58
UPDATE_COLOR
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
MeshObjectSelectionPlugin::update_regions
void update_regions(MeshT *_mesh)
Update face selection to correspond to the vertex selection.
MeshObjectSelectionPlugin::createMeshFromVertexSelection
int createMeshFromVertexSelection(int _objectId)
select given vertices
Definition: VertexSelection.cc:334
MeshObjectSelectionPlugin::clearVertexSelection
void clearVertexSelection(int _objectId)
Unselect all vertices.
Definition: VertexSelection.cc:149
MeshObjectSelectionPlugin::invertVertexSelection
void invertVertexSelection(int _objectId)
Invert the current vertex selection.
Definition: VertexSelection.cc:172
DATA_TRIANGLE_MESH
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:66
MeshObjectSelectionPlugin::clearModelingVertices
void clearModelingVertices(int objectId)
Clear Modeling Area.
Definition: VertexSelection.cc:602
MeshObjectSelectionPlugin::getVertexSelection
IdList getVertexSelection(int _objectId)
Return a list of all selected vertices.
Definition: VertexSelection.cc:287
MeshObjectSelectionPlugin::closestBoundarySelection
void closestBoundarySelection(MeshT *_mesh, int _vh, PrimitiveType _primitiveTypes, bool _deselection)
Select all entities that are incident to closest boundary.
Definition: MeshObjectSelectionPluginT.cc:467
BaseObject::id
int id() const
Definition: BaseObject.cc:201