File: CGAL_Lab_plugin_helper.h

package info (click to toggle)
cgal 6.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (89 lines) | stat: -rw-r--r-- 2,975 bytes parent folder | download
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
// Copyright (c) 2009,2014,2015  GeometryFactory Sarl (France)
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/Three/include/CGAL/Three/CGAL_Lab_plugin_helper.h $
// $Id: include/CGAL/Three/CGAL_Lab_plugin_helper.h 08b27d3db14 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s)     : Laurent RINEAU

//! \file CGAL_Lab_plugin_helper.h
#ifndef LAB_DEMO_OPERATION_HELPER_H
#define LAB_DEMO_OPERATION_HELPER_H

#include <CGAL/license/Three.h>


#include "Scene_item_config.h" //defines SCENE_ITEM_EXPORT

#include <QString>
#include <QStringList>
#include <QMap>

class QAction;
struct QMetaObject;
class QMainWindow;
class QDockWidget;

#include <CGAL/Three/CGAL_Lab_plugin_interface.h>
#include <CGAL/Three/Scene_interface.h>
namespace CGAL {
namespace Three {
  /*! \brief provides convenient functions for a plugin.
   * This class provides convenient functions to manage dock_widgets and to access a certain type of items in the scene.
   * It also provides member variables for a Scene_interface and a QMainWindow.
   */
class SCENE_ITEM_EXPORT CGAL_Lab_plugin_helper
  : public CGAL_Lab_plugin_interface
{
public:

  /*! \brief gets an item of the templated type.
   * \returns The currently selected `SceneType` item
   * \returns the first `SceneType` item found in the scene's list of items if the selected item is not a `SceneType`
   * \returns nullptr if there is no `SceneType` in the list.
   */
  template<class SceneType>
  SceneType* getSelectedItem() const{
   int item_id = scene->mainSelectionIndex();
   SceneType* scene_item = qobject_cast<SceneType*>(scene->item(item_id));
   if(!scene_item) {
     // no selected SceneType - if there is only one in list return it, otherwise nullptr
     int counter = 0;
     int last_selected = 0;
     for(CGAL::Three::Scene_interface::Item_id i = 0, end = scene->numberOfEntries(); i < end && counter < 2; ++i) {
       if(SceneType* tmp = qobject_cast<SceneType*>(scene->item(i))) {
         scene_item = tmp;
         counter++;
         last_selected=i;
       }
     }
     if(counter != 1) { return nullptr; }
     scene->setSelectedItem(last_selected);
   }
   return scene_item;
 }

  /*! \brief Adds a dock widget to the interface
   *
   * Adds a dock widget in the left section of the MainWindow. If the slot is already taken, the dock widgets will be tabified.
   */
  void addDockWidget(QDockWidget* dock);
  /*! \brief Automatically connects each action of the plugin to the corresponding slot.
   *
   * \attention Each action named `ActionName` in the plugin's `actions()` list must have a corresponding slot named `on_ActionsName_triggered()`
   * in the plugin.
   */
  void autoConnectActions();
protected:
  //!The reference to the scene
  CGAL::Three::Scene_interface* scene;
  //!The reference to the main window
  QMainWindow* mw;
};
}
}
#endif // LAB_DEMO_OPERATION_HELPER_H