ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
G3Point.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 // First:
9 // Replace all occurrences of 'G3PointPlugin' by your own plugin class name
10 // in this file. This includes the resource path to info.json in the
11 // constructor.
12 
13 // Second:
14 // Open G3PointPlugin.qrc, change the "prefix" and the icon filename for
15 // your plugin. Change the name of the file to <yourPluginName>.qrc
16 
17 // Third:
18 // Open the info.json file and fill in the information about the plugin.
19 // "type" should be one of: "Standard", "GL", or "I/O" (required)
20 // "name" is the name of the plugin (required)
21 // "icon" is the Qt resource path to the plugin's icon (from the .qrc
22 // file) "description" is used as a tootip if the plugin has actions and
23 // is displayed in the plugin dialog "authors", "maintainers", and
24 // "references" show up in the plugin dialog as well
25 
26 #include "G3Point.h"
27 
28 #include <QtGui>
29 
30 #include "G3PointAction.h"
31 
32 ccHObject* G3PointFactory::buildObject(const QString& metaName) {
33  if (metaName == "GrainsAsEllipsoids") {
35  "[G3PointFactory::buildObject] build a GrainsAsEllipsoids "
36  "object");
37  return new GrainsAsEllipsoids(m_app);
38  } else {
40  "[G3PointFactory::buildObject] you are asking for the building "
41  "of an unknown object: " +
42  metaName);
43  return nullptr;
44  }
45 }
46 
47 // Default constructor:
48 // - pass the Qt resource path to the info.json file (from
49 //<yourPluginName>.qrc file)
50 // - constructor should mainly be used to initialize actions and other members
51 G3PointPlugin::G3PointPlugin(QObject* parent)
52  : QObject(parent),
53  ccStdPluginInterface(":/CC/plugin/G3PointPlugin/info.json"),
54  m_action(nullptr) {}
55 
56 // This method should enable or disable your plugin actions
57 // depending on the currently selected entities ('selectedEntities').
58 void G3PointPlugin::onNewSelection(
59  const ccHObject::Container& selectedEntities) {
60  if (m_action == nullptr) {
61  return;
62  }
63 
64  // If you need to check for a specific type of object, you can use the
65  // methods in ccHObjectCaster.h or loop and check the objects' classIDs like
66  // this:
67  //
68  // for ( ccHObject *object : selectedEntities )
69  // {
70  // if ( object->getClassID() == CV_TYPES::VIEWPORT_2D_OBJECT )
71  // {
72  // // ... do something with the viewports
73  // }
74  // }
75 
76  // For example - only enable our action if something is selected.
77  m_action->setEnabled(!selectedEntities.empty());
78 }
79 
80 // This method returns all the 'actions' your plugin can perform.
81 // getActions() will be called only once, when plugin is loaded.
82 QList<QAction*> G3PointPlugin::getActions() {
85  G3PointFactory* g3PointFactory =
86  new G3PointFactory("G3Point", getMainAppInterface());
87  container->addFactory(g3PointFactory);
88 
89  // default action (if it has not been already created, this is the moment to
90  // do it)
91  if (!m_action) {
92  // Here we use the default plugin name, description, and icon,
93  // but each action should have its own.
94  m_action = new QAction(getName(), this);
95  m_action->setToolTip(getDescription());
96  m_action->setIcon(getIcon());
97 
98  // Connect appropriate signal
99  connect(m_action, &QAction::triggered, this,
101  }
102 
103  return {m_action};
104 }
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
CCPluginStub.
Definition: G3Point.h:16
virtual ccHObject * buildObject(const QString &metaName) override
Custom object building method.
Definition: G3Point.cpp:32
ecvMainAppInterface * m_app
Definition: G3Point.h:23
static void createAction(ecvMainAppInterface *appInterface)
virtual QString getName() const override
Returns (short) name (for menu entry, etc.)
virtual QString getDescription() const override
Returns long name/description (for tooltip, etc.)
virtual QIcon getIcon() const override
Returns icon.
QSharedPointer< Container > Shared
Shared pointer type.
static Container::Shared GetUniqueInstance()
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
std::vector< ccHObject * > Container
Standard instances container (for children, etc.)
Definition: ecvHObject.h:337
Standard ECV plugin interface.
virtual ecvMainAppInterface * getMainAppInterface()
A callback pointer to the main app interface for use by plugins.
ecvMainAppInterface * m_app
Main application interface.