File: Merge_point_sets_plugin.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (93 lines) | stat: -rw-r--r-- 2,654 bytes parent folder | download | duplicates (2)
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
57
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
90
91
92
93
#include "config.h"
#include "Scene_points_with_normal_item.h"
#include <CGAL/Three/CGAL_Lab_plugin_interface.h>

#include <QObject>
#include <QAction>
#include <QMainWindow>
#include <QApplication>
#include <QtPlugin>
#include <QInputDialog>
#include <QMessageBox>


using namespace CGAL::Three;
class CGAL_Lab_merge_point_sets_plugin :
  public QObject,
  public CGAL_Lab_plugin_interface
{
  Q_OBJECT
  Q_INTERFACES(CGAL::Three::CGAL_Lab_plugin_interface)
  Q_PLUGIN_METADATA(IID "com.geometryfactory.CGALLab.PluginInterface/1.0")

private:
  QAction* actionMergePointSets;

public:
  void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface*) {
    scene = scene_interface;
    actionMergePointSets = new QAction(tr("Merge"), mainWindow);
    actionMergePointSets->setObjectName("actionMergePointSets");
    connect(actionMergePointSets, SIGNAL(triggered()), this, SLOT(on_actionMergePointSets_triggered()));
  }

  QList<QAction*> actions() const {
    return QList<QAction*>() << actionMergePointSets;
  }

  bool applicable(QAction*) const {
    if (scene->selectionIndices().size() < 2)
      return false;

    for(int index : scene->selectionIndices())
      {
        if ( qobject_cast<Scene_points_with_normal_item*>(scene->item(index)) )
          return true;
      }
    return false;
  }

public Q_SLOTS:
  void on_actionMergePointSets_triggered();
private :
  Scene_interface *scene;
}; // end CGAL_Lab_merge_point_sets_plugin

void CGAL_Lab_merge_point_sets_plugin::on_actionMergePointSets_triggered()
{
  QApplication::setOverrideCursor(Qt::WaitCursor);
  CGAL::Three::Scene_interface::Item_id mainSelectionIndex
    = scene->selectionIndices().first();
  Scene_points_with_normal_item* mainSelectionItem
    = qobject_cast<Scene_points_with_normal_item*>(scene->item(mainSelectionIndex));

  QList<int> indices_to_remove;
  for(int index : scene->selectionIndices())
    {
      if (index == mainSelectionIndex)
        continue;

      Scene_points_with_normal_item* item =
        qobject_cast<Scene_points_with_normal_item*>(scene->item(index));
      if(item)
        {
          indices_to_remove.push_front(index);
          mainSelectionItem->point_set()->merge_with (*(item->point_set()));
          mainSelectionItem->setName(tr("%1 + %2").arg(mainSelectionItem->name()).arg(item->name()));
        }
    }


  mainSelectionItem->invalidateOpenGLBuffers();
  scene->itemChanged(mainSelectionIndex);

  //remove the other items
  for(int index : indices_to_remove)
  {
    scene->erase(index);
  }
  QApplication::restoreOverrideCursor();
}


#include "Merge_point_sets_plugin.moc"