ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
qCloudLayers.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 #include "../include/qCloudLayers.h"
9 
10 #include "../include/ccCloudLayersDlg.h"
11 
12 // Qt
13 #include <QMainWindow>
14 #include <QtGui>
15 
16 // qCC_db
17 #include <ecvPointCloud.h>
18 
19 // system
20 #include <assert.h>
21 
22 qCloudLayers::qCloudLayers(QObject* parent)
23  : QObject(parent),
24  ccStdPluginInterface(":/CC/plugin/qCloudLayers/info.json"),
25  m_action(nullptr),
26  m_cloudLayersDlg(nullptr) {}
27 
28 void qCloudLayers::onNewSelection(
29  const ccHObject::Container& selectedEntities) {
30  if (m_action) {
31  // a single point cloud must be selected
32  m_action->setEnabled(
33  selectedEntities.size() == 1 &&
34  selectedEntities.front()->isA(CV_TYPES::POINT_CLOUD));
35  }
36 }
37 
38 QList<QAction*> qCloudLayers::getActions() {
39  // default action
40  if (!m_action) {
41  m_action = new QAction(getName(), this);
42  m_action->setToolTip(getDescription());
43  m_action->setIcon(getIcon());
44 
45  // connect signal
46  connect(m_action, &QAction::triggered, this, &qCloudLayers::doAction);
47  }
48 
49  return {m_action};
50 }
51 
53  if (!m_app) {
54  assert(false);
55  return;
56  }
57 
58  // check selection
59  const ccHObject::Container& selectedEntities = m_app->getSelectedEntities();
60  if (!m_app->haveOneSelection() ||
61  !selectedEntities.front()->isA(CV_TYPES::POINT_CLOUD)) {
62  m_app->dispToConsole("Select only one point cloud!",
64  return;
65  }
66 
67  // get first selected cloud
68  ccPointCloud* cloud = static_cast<ccPointCloud*>(selectedEntities.front());
69 
70  if (!cloud->hasScalarFields()) {
71  CVLog::Error("Cloud has no scalar field");
72  return;
73  }
74 
75  // set colors schema to RGB
76  m_app->updateUI();
77 
78  if (!m_cloudLayersDlg) {
79  m_cloudLayersDlg = new ccCloudLayersDlg(m_app, m_app->getMainWindow());
80  m_app->registerOverlayDialog(m_cloudLayersDlg, Qt::TopRightCorner);
81  }
82 
83  m_cloudLayersDlg->linkWith(m_app->getActiveWindow());
84  m_cloudLayersDlg->setPointCloud(cloud);
85 
86  if (m_cloudLayersDlg->start()) {
88  }
89 }
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
void setPointCloud(ccPointCloud *cloud)
bool start() override
inherited from ccOverlayDialog
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.
std::vector< ccHObject * > Container
Standard instances container (for children, etc.)
Definition: ecvHObject.h:337
virtual bool linkWith(QWidget *win)
Links the overlay dialog with a MDI window.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool hasScalarFields() const override
Returns whether one or more scalar fields are instantiated.
Standard ECV plugin interface.
ecvMainAppInterface * m_app
Main application interface.
virtual void updateUI()=0
virtual QMainWindow * getMainWindow()=0
Returns main window.
virtual QWidget * getActiveWindow()=0
virtual void updateOverlayDialogsPlacement()=0
Forces the update of all registered MDI 'overlay' dialogs.
virtual const ccHObject::Container & getSelectedEntities() const =0
Returns currently selected entities ("read only")
bool haveOneSelection() const
Checks if we have exactly one selection.
virtual void dispToConsole(QString message, ConsoleMessageLevel level=STD_CONSOLE_MESSAGE)=0
virtual void registerOverlayDialog(ccOverlayDialog *dlg, Qt::Corner pos)=0
Registers a MDI area 'overlay' dialog.
void doAction()
Slot called when associated action is triggered.
@ POINT_CLOUD
Definition: CVTypes.h:104