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