VertexSelection.cc 29 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/

#include "MeshObjectSelectionPlugin.hh"

#include <iostream>

#include <MeshTools/MeshSelectionT.hh>

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>

//=========================================================
//==== Vertex selections
//=========================================================

void MeshObjectSelectionPlugin::selectVertices(int _objectId, IdList _vertexList) {
    
57
    if(_vertexList.empty() ) return;
Jan Möbius's avatar
 
Jan Möbius committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    
    BaseObjectData* object = 0;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("selectVertices: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::selectVertices(PluginFunctions::triMesh(object), _vertexList);
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::selectVertices(PluginFunctions::polyMesh(object), _vertexList);
    else {
        emit log(LOGERR,tr("selectAllVertices: Unsupported object Type")); 
        return;
    }

    QString selection = "selectVertices(ObjectId, [ " + QString::number(_vertexList[0]);

    for (uint i = 1 ; i < _vertexList.size(); ++i) {
        selection +=  ", " + QString::number(_vertexList[i]);
    }

    selection += " ])";

    emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
    emit scriptInfo(selection);
}

//=========================================================

void MeshObjectSelectionPlugin::unselectVertices(int _objectId, IdList _vertexList) {
    
90
    if(_vertexList.empty() ) return;
Jan Möbius's avatar
 
Jan Möbius committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    
    BaseObjectData* object = 0;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("unselectVertices: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::unselectVertices(PluginFunctions::triMesh(object), _vertexList);
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::unselectVertices(PluginFunctions::polyMesh(object), _vertexList);
    else {
        emit log(LOGERR,tr("unselectVertices: Unsupported object Type")); 
        return;
    }

    QString selection = "unselectVertices(ObjectId, [ " + QString::number(_vertexList[0]);

    for (uint i = 1 ; i < _vertexList.size(); ++i) {
        selection +=  ", " + QString::number(_vertexList[i]);
    }

    selection += " ])";

    emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
    emit scriptInfo(selection);
}


//=========================================================


void MeshObjectSelectionPlugin::selectAllVertices(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("selectAllVertices: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::selectAllVertices(PluginFunctions::triMesh(object));
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::selectAllVertices(PluginFunctions::polyMesh(object));
    else {
        emit log(LOGERR,tr("selectAllVertices: Unsupported object Type")); 
        return;
    }

    emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
    emit scriptInfo("selectAllVertices(ObjectId)");
}

//=========================================================

void MeshObjectSelectionPlugin::clearVertexSelection(int _objectId) {
    
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("clearVertexSelection: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::clearVertexSelection(PluginFunctions::triMesh(object));
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::clearVertexSelection(PluginFunctions::polyMesh(object));
    else {
        emit log(LOGERR,tr("clearVertexSelection: Unsupported object Type")); 
        return;
    }

    emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
    emit scriptInfo("clearVertexSelection(ObjectId)");
}

//=========================================================

void MeshObjectSelectionPlugin::invertVertexSelection(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("invertVertexSelection: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::invertVertexSelection(PluginFunctions::triMesh(object));
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::invertVertexSelection(PluginFunctions::polyMesh(object));
    else {
        emit log(LOGERR,tr("invertVertexSelection: Unsupported object Type")); 
        return;
    }

    emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
    emit scriptInfo("invertVertexSelection(ObjectId)");
}

//=========================================================

void MeshObjectSelectionPlugin::selectBoundaryVertices(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("selectBoundaryVertices: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::selectBoundaryVertices(PluginFunctions::triMesh(object));
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::selectBoundaryVertices(PluginFunctions::polyMesh(object));
    else {
        emit log(LOGERR,tr("selectBoundaryVertices: Unsupported object Type")); 
        return;
    }

    emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
    emit scriptInfo("selectBoundaryVertices(ObjectId)");
}

//=========================================================

void MeshObjectSelectionPlugin::selectClosestBoundaryVertices(int _objectId, int VertexId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("selectClosestBoundaryVertices: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH) {
        // \TODO: Adapt implementation
        //closestBoundarySelection(PluginFunctions::triMesh(object), VertexId, VERTEX);
    } else if (object->dataType() == DATA_POLY_MESH) {
        // \TODO: Adapt implementation
        //closestBoundarySelection(PluginFunctions::polyMesh(object), VertexId, VERTEX);
    } else {
        emit log(LOGERR,tr("selectClosestBoundaryVertices: Unsupported object Type")); 
        return;
    }

    emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
    emit scriptInfo("selectClosestBoundaryVertices(ObjectId, VertexId)");
}

//=========================================================

void MeshObjectSelectionPlugin::shrinkVertexSelection(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("shrinkVertexSelection: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::shrinkVertexSelection(PluginFunctions::triMesh(object));
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::shrinkVertexSelection(PluginFunctions::polyMesh(object));
    else {
        emit log(LOGERR,tr("shrinkVertexSelection: Unsupported object Type")); 
        return;
    }

    emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
    emit scriptInfo("shrinkVertexSelection(ObjectId)");
}

//=========================================================

void MeshObjectSelectionPlugin::growVertexSelection(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("growVertexSelection: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::growVertexSelection(PluginFunctions::triMesh(object));
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::growVertexSelection(PluginFunctions::polyMesh(object));
    else {
        emit log(LOGERR,tr("growVertexSelection: Unsupported object Type")); 
        return;
    }

    emit updatedObject(object->id(), UPDATE_SELECTION_VERTICES);
    emit scriptInfo("growVertexSelection(ObjectId)");
}

//=========================================================

IdList MeshObjectSelectionPlugin::getVertexSelection(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("getVertexSelection: unable to get object")); 
        return IdList(0);
    }

    emit scriptInfo("getVertexSelection(ObjectId)");

    if (object->dataType() == DATA_TRIANGLE_MESH)
        return MeshSelection::getVertexSelection(PluginFunctions::triMesh(object));
    else if (object->dataType() == DATA_POLY_MESH)
        return MeshSelection::getVertexSelection(PluginFunctions::polyMesh(object));
    else {
        emit log(LOGERR,tr("getVertexSelection: Unsupported object Type")); 
        return IdList(0);
    }

    return IdList(0);
}

//=========================================================
  
Mike Kremer's avatar
Mike Kremer committed
310
void MeshObjectSelectionPlugin::deleteVertexSelection(int _objectId) {
Jan Möbius's avatar
 
Jan Möbius committed
311
312
313
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
Mike Kremer's avatar
Mike Kremer committed
314
        emit log(LOGERR,tr("deleteVertexSelection: unable to get object"));
Jan Möbius's avatar
 
Jan Möbius committed
315
316
317
318
319
320
321
322
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        deleteSelection(PluginFunctions::triMesh(object), vertexType_);
    else if (object->dataType() == DATA_POLY_MESH)
        deleteSelection(PluginFunctions::polyMesh(object), vertexType_);
    else {
Mike Kremer's avatar
Mike Kremer committed
323
        emit log(LOGERR,tr("deleteVertexSelection: Unsupported object Type"));
Jan Möbius's avatar
 
Jan Möbius committed
324
325
326
327
        return;
    }

    emit updatedObject(object->id(), UPDATE_ALL);
Mike Kremer's avatar
Mike Kremer committed
328
    emit scriptInfo("deleteVertexSelection(ObjectId)");
Jan Möbius's avatar
 
Jan Möbius committed
329
330
331
332
}

//=========================================================

333
int MeshObjectSelectionPlugin::createMeshFromVertexSelection( int _objectId) {
Jan Möbius's avatar
Jan Möbius committed
334
  return createMeshFromSelection(_objectId, vertexType_ );
335
336
337
338
}

//=========================================================

Jan Möbius's avatar
 
Jan Möbius committed
339
/// colorize the vertex selection
340
void MeshObjectSelectionPlugin::colorizeVertexSelection(int _objectId, int r, int g, int b, int a) {
Jan Möbius's avatar
 
Jan Möbius committed
341
342
343
344
345
346
347
348
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId, object)) {
        emit log(LOGERR,"colorizeVertexSelection: unable to get object");
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH) {
349
        colorizeSelection(PluginFunctions::triMesh(object), vertexType_, r, g, b, a);
Jan Möbius's avatar
 
Jan Möbius committed
350
    } else if (object->dataType() == DATA_POLY_MESH) {
351
        colorizeSelection(PluginFunctions::polyMesh(object), vertexType_, r, g, b, a);
Jan Möbius's avatar
 
Jan Möbius committed
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
    } else {
        emit log(LOGERR,"colorizeVertexSelection: Unsupported object Type");
        return;
    }

    emit scriptInfo("colorizeVertexSelection(ObjectId, "
              + QString::number(r) + ", " + QString::number(g) + ", " + QString::number(b) + ")");

    emit updatedObject(_objectId, UPDATE_COLOR);
}

//=========================================================
//==== Modeling Area selections
//=========================================================

void MeshObjectSelectionPlugin::selectHandleVertices(int _objectId, IdList _vertexList) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("selectHandleVertices: unable to get object")); 
        return;
    }

375
    if (_vertexList.empty() )
Jan Möbius's avatar
 
Jan Möbius committed
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
        return;

    if (object->dataType() == DATA_TRIANGLE_MESH){
        MeshSelection::setArea(PluginFunctions::triMesh(object), _vertexList, HANDLEAREA, true);
        update_regions(PluginFunctions::triMesh(object));
    } else if (object->dataType() == DATA_POLY_MESH){
        MeshSelection::setArea(PluginFunctions::polyMesh(object), _vertexList, HANDLEAREA, true);
        update_regions(PluginFunctions::polyMesh(object));
    } else {
        emit log(LOGERR,tr("selectHandleVertices: Unsupported object Type")); 
        return;
    }

    QString selection = "selectHandleVertices(ObjectId, [ " + QString::number(_vertexList[0]);

    for (uint i = 1 ; i < _vertexList.size(); ++i) {
        selection +=  ", " + QString::number(_vertexList[i]);
    }

    selection += " ])";

    emit updatedObject(object->id(), UPDATE_ALL);
    emit scriptInfo(selection);
}

//=========================================================

void MeshObjectSelectionPlugin::unselectHandleVertices(int _objectId, IdList _vertexList) {
    
405
    if(_vertexList.empty()) return;
Jan Möbius's avatar
 
Jan Möbius committed
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
  
    BaseObjectData* object = 0;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("unselectHandleVertices: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::setArea(PluginFunctions::triMesh(object), _vertexList, HANDLEAREA, false);
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::setArea(PluginFunctions::polyMesh(object), _vertexList, HANDLEAREA, false);
    else {
        emit log(LOGERR,tr("unselectHandleVertices: Unsupported object Type")); 
        return;
    }

    QString selection = "unselectHandleVertices(ObjectId, [ " + QString::number(_vertexList[0]);

    for (uint i = 1 ; i < _vertexList.size(); ++i) {
        selection +=  ", " + QString::number(_vertexList[i]);
    }

    selection += " ])";

    emit updatedObject(object->id(), UPDATE_ALL);
    emit scriptInfo(selection);
}

//=========================================================

void MeshObjectSelectionPlugin::clearHandleVertices(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("clearHandleVertices: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::setArea(PluginFunctions::triMesh(object), HANDLEAREA, false);
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::setArea(PluginFunctions::polyMesh(object), HANDLEAREA, false);
    else {
        emit log(LOGERR,tr("clearHandleVertices: Unsupported object Type")); 
    return;
    }

    emit updatedObject(object->id(), UPDATE_ALL);
    emit scriptInfo("clearHandleVertices(ObjectId)");
}

//=========================================================

void MeshObjectSelectionPlugin::setAllHandleVertices(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("setAllHandleVertices: unable to get object")); 
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::setArea(PluginFunctions::triMesh(object), HANDLEAREA, true);
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::setArea(PluginFunctions::polyMesh(object), HANDLEAREA, true);
    else {
        emit log(LOGERR,tr("setAllHandleVertices: Unsupported object Type")); 
        return;
    }

    emit updatedObject(object->id(), UPDATE_ALL);
    emit scriptInfo("setAllHandleVertices(ObjectId)");
}

//=========================================================

IdList MeshObjectSelectionPlugin::getHandleVertices(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("getHandleVertices: unable to get object")); 
        return IdList(0);
    }

    emit scriptInfo("getHandleVertices(ObjectId)");  

    if (object->dataType() == DATA_TRIANGLE_MESH)
        return MeshSelection::getArea(PluginFunctions::triMesh(object), HANDLEAREA);
    else if (object->dataType() == DATA_POLY_MESH)
        return MeshSelection::getArea(PluginFunctions::polyMesh(object), HANDLEAREA);
    else {
        emit log(LOGERR,tr("getHandleVertices: Unsupported object Type")); 
        return IdList(0);;
    }

    return IdList(0);
}

//=========================================================
//==== Modeling Area selections
//=========================================================

void MeshObjectSelectionPlugin::selectModelingVertices(int _objectId, IdList _vertexList) {
    
510
    if(_vertexList.empty() ) return;
Jan Möbius's avatar
 
Jan Möbius committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
  
    BaseObjectData* object = 0;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("selectModelingVertices: unable to get object"));
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH) {
        MeshSelection::setArea(PluginFunctions::triMesh(object), _vertexList, AREA, true);
        update_regions(PluginFunctions::triMesh(object));
    } else if (object->dataType() == DATA_POLY_MESH){
        MeshSelection::setArea(PluginFunctions::polyMesh(object), _vertexList, AREA, true);
        update_regions(PluginFunctions::polyMesh(object));
    } else {
        emit log(LOGERR,tr("selectModelingVertices: Unsupported object Type"));
        return;
    }

    QString selection = "selectModelingVertices(ObjectId, [ " + QString::number(_vertexList[0]);

    for (uint i = 1 ; i < _vertexList.size(); ++i) {
        selection +=  ", " + QString::number(_vertexList[i]);
    }

    selection += " ])";

    emit updatedObject(object->id(), UPDATE_ALL);
    emit scriptInfo(selection);
}

//=========================================================

void MeshObjectSelectionPlugin::unselectModelingVertices(int _objectId, IdList _vertexList) {
    
545
    if(_vertexList.empty() ) return;
Jan Möbius's avatar
 
Jan Möbius committed
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
  
    BaseObjectData* object = 0;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("unselectModelingVertices: unable to get object"));
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::setArea(PluginFunctions::triMesh(object), _vertexList, AREA, false);
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::setArea(PluginFunctions::polyMesh(object), _vertexList, AREA, false);
    else{
        emit log(LOGERR,tr("unselectModelingVertices: Unsupported object Type"));
        return;
    }

    QString selection = "unselectModelingVertices(ObjectId, [ " + QString::number(_vertexList[0]);

    for (uint i = 1 ; i < _vertexList.size(); ++i) {
        selection +=  ", " + QString::number(_vertexList[i]);
    }

    selection += " ])";

    emit updatedObject(object->id(), UPDATE_ALL);
    emit scriptInfo(selection);
}

574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
// =========================================================

void MeshObjectSelectionPlugin::selectVerticesByValue(int _objectId, QString _component, bool _greater, double _value ) {
  BaseObjectData* object = 0;
  if (!PluginFunctions::getObject(_objectId,object)) {
    emit log(LOGERR,tr("selectVerticesByValue: unable to get object"));
    return;
  }

  if (object->dataType() == DATA_TRIANGLE_MESH)
    selectVerticesByValue(PluginFunctions::triMesh(object), _component,  _greater,  _value);
  else if (object->dataType() == DATA_POLY_MESH)
    selectVerticesByValue(PluginFunctions::polyMesh(object), _component,  _greater,  _value);
  else{
    emit log(LOGERR,tr("selectVerticesByValue: Unsupported object Type"));
    return;
  }

  emit updatedObject(object->id(), UPDATE_SELECTION);

  /// \todo emit scriptinfo

}


Jan Möbius's avatar
 
Jan Möbius committed
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
//=========================================================

void MeshObjectSelectionPlugin::clearModelingVertices(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("clearModelingVertices: unable to get object"));
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::setArea(PluginFunctions::triMesh(object), AREA, false);
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::setArea(PluginFunctions::polyMesh(object), AREA, false);
    else{
        emit log(LOGERR,tr("clearModelingVertices: Unsupported object Type"));
        return;
    }

    emit updatedObject(object->id(), UPDATE_ALL);
    emit scriptInfo("clearModelingVertices(ObjectId)");
}

//=========================================================

void MeshObjectSelectionPlugin::setAllModelingVertices(int _objectId) {
  
    BaseObjectData* object;
    if (!PluginFunctions::getObject(_objectId,object)) {
        emit log(LOGERR,tr("setAllModelingVertices: unable to get object"));
        return;
    }

    if (object->dataType() == DATA_TRIANGLE_MESH)
        MeshSelection::setArea(PluginFunctions::triMesh(object), AREA, true);
    else if (object->dataType() == DATA_POLY_MESH)
        MeshSelection::setArea(PluginFunctions::polyMesh(object), AREA, true);
    else{
        emit log(LOGERR,tr("setAllModelingVertices: Unsupported object Type"));
        return;
    }

    emit updatedObject(object->id(), UPDATE_ALL);
    emit scriptInfo("setAllModelingVertices(ObjectId)");
}

//=========================================================
IdList MeshObjectSelectionPlugin::getModelingVertices(int _objectId) {
  BaseObjectData* object;
  if (!PluginFunctions::getObject(_objectId,object)) {
    emit log(LOGERR,tr("getModelingVertices: unable to get object"));
    return IdList(0);
  }

  emit scriptInfo("getModelingVertices(ObjectId)");

  if (object->dataType() == DATA_TRIANGLE_MESH)
      return MeshSelection::getArea(PluginFunctions::triMesh(object), AREA);
  else if (object->dataType() == DATA_POLY_MESH)
      return MeshSelection::getArea(PluginFunctions::polyMesh(object), AREA);
  else{
      emit log(LOGERR,tr("getModelingVertices: Unsupported object Type"));
      return IdList(0);
  }

  return IdList(0);
}

//=========================================================

void MeshObjectSelectionPlugin::loadFlipperModelingSelection(int _objectId, QString _filename) {
    
    QFile file(_filename);

    if (!file.exists()) {
        emit log(LOGERR,tr("Unable to find file: ") + _filename);
        return;
    }

    if (file.open(QFile::ReadOnly)) {
        
        QTextStream input(&file);
        QString header = input.readLine();

        if (!header.contains("Selection")) {
            emit log(LOGERR,tr("Wrong file header!should be Selection but is ") + header);
            return;
        }

        header = input.readLine();

        bool ok = false;
        uint vertexCount = header.toUInt(&ok);

        if (!ok) {
            emit log(LOGERR,tr("Unable to parse header. Cant get vertex count from string: ") + header);
            return;
        }

        //compare VertexCount
        BaseObjectData* object;
        if (!PluginFunctions::getObject(_objectId, object)) {
            emit log(LOGERR,tr("loadSelection: unable to get object"));
            return;
        }

        if (object->dataType() == DATA_TRIANGLE_MESH) {
            if (PluginFunctions::triMesh(object)->n_vertices() != vertexCount)
                return;
        } else if (object->dataType() == DATA_POLY_MESH) {
            if (PluginFunctions::polyMesh(object)->n_vertices() != vertexCount)
                return;
        } else {
            return;
        }

        //get selected handles
        IdList handleVertices;
        IdList modelingVertices;

        uint vertexId = 0;

        do {
            // Split into two substrings
            QStringList inputList = input.readLine().split(" ");

            if (inputList.size() != 2) {
                emit log(LOGERR,tr("Unable to parse entry at vertex index ") + QString::number(vertexId));
                return;
            }

            if (inputList[0] == "1")
            modelingVertices.push_back(vertexId);

            if (inputList[1] == "1")
            handleVertices.push_back(vertexId);

            ++vertexId;

        } while (!input.atEnd());

        clearModelingVertices(_objectId);
        selectModelingVertices(_objectId,modelingVertices);

        clearHandleVertices(_objectId);
        selectHandleVertices(_objectId,handleVertices);

    } else {
        emit log(LOGERR,tr("Unable to open selection file!"));
    }
}

//=========================================================

void MeshObjectSelectionPlugin::saveFlipperModelingSelection(int _objectId, QString _filename) {
  
    QFile file(_filename);

    if (file.open(QFile::WriteOnly)) {
        QTextStream input(&file);

        //get the object
        BaseObjectData* object;
        if (!PluginFunctions::getObject(_objectId,object)) {
            emit log(LOGERR,tr("saveFlipperModelingSelection: unable to get object"));
            return;
        }

        if (object->dataType() == DATA_TRIANGLE_MESH) {
            TriMesh* mesh = PluginFunctions::triMesh(object);

            //header
            input << "Selection" << endl;
            input << mesh->n_vertices() << endl;

            std::vector< int > modelingVertices = MeshSelection::getArea(mesh, AREA);
            std::vector< int > handleVertices   = MeshSelection::getArea(mesh, HANDLEAREA);

            std::vector< bool > modelingAll(mesh->n_vertices(), false);
            std::vector< bool > handleAll(mesh->n_vertices(), false);

            for (uint i=0; i < modelingVertices.size(); i++)
                modelingAll[ modelingVertices[i] ] = true;

            for (uint i=0; i < handleVertices.size(); i++)
                handleAll[ handleVertices[i] ] = true;

            for (uint i=0; i < mesh->n_vertices(); i++)
                input << (int) modelingAll[i] << " " << (int) handleAll[i] << endl;

        } else if (object->dataType() == DATA_POLY_MESH){

            PolyMesh* mesh = PluginFunctions::polyMesh(object);

            //header
            input << "Selection" << endl;
            input << mesh->n_vertices() << endl;

            std::vector< int > modelingVertices = MeshSelection::getArea(mesh, AREA);
            std::vector< int > handleVertices   = MeshSelection::getArea(mesh, HANDLEAREA);

            std::vector< bool > modelingAll(mesh->n_vertices(), false);
            std::vector< bool > handleAll(mesh->n_vertices(), false);

            for (uint i=0; i < modelingVertices.size(); i++)
                modelingAll[ modelingVertices[i] ] = true;

            for (uint i=0; i < handleVertices.size(); i++)
                handleAll[ handleVertices[i] ] = true;

            for (uint i=0; i < mesh->n_vertices(); i++)
                input << (int) modelingAll[i] << " " << (int) handleAll[i] << endl;

        } else {
            emit log(LOGERR, tr("saveFlipperModelingSelection: Unsupported Type."));
        }
    } else {
        emit log(LOGERR,tr("Unable to open selection file!"));
    }
Mike Kremer's avatar
Mike Kremer committed
818
}