| 1 |
#include "../include/qCloudLayers.h" |
| 2 |
#include "../include/ccCloudLayersDlg.h" |
| 3 |
|
| 4 |
//Qt |
| 5 |
#include <QtGui> |
| 6 |
#include <QMainWindow> |
| 7 |
|
| 8 |
//qCC_db |
| 9 |
#include <ccPointCloud.h> |
| 10 |
|
| 11 |
//system |
| 12 |
#include <assert.h> |
| 13 |
|
| 14 |
qCloudLayers::qCloudLayers( QObject* parent ) |
| 15 |
: QObject( parent ) |
| 16 |
, ccStdPluginInterface( ":/CC/plugin/qCloudLayers/info.json" ) |
| 17 |
, m_action( nullptr ) |
| 18 |
, m_cloudLayersDlg( nullptr ) |
| 19 |
{ |
| 20 |
} |
| 21 |
|
| 22 |
void qCloudLayers::onNewSelection( const ccHObject::Container& selectedEntities ) |
| 23 |
{ |
| 24 |
if (m_action) |
| 25 |
{ |
| 26 |
//a single point cloud must be selected |
| 27 |
m_action->setEnabled(selectedEntities.size() == 1 && selectedEntities.front()->isA(CC_TYPES::POINT_CLOUD)); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
QList<QAction*> qCloudLayers::getActions() |
| 32 |
{ |
| 33 |
//default action |
| 34 |
if (!m_action) |
| 35 |
{ |
| 36 |
m_action = new QAction(getName(),this); |
| 37 |
m_action->setToolTip(getDescription()); |
| 38 |
m_action->setIcon(getIcon()); |
| 39 |
|
| 40 |
//connect signal |
| 41 |
connect(m_action, &QAction::triggered, this, &qCloudLayers::doAction); |
| 42 |
} |
| 43 |
|
| 44 |
return { m_action }; |
| 45 |
} |
| 46 |
|
| 47 |
void qCloudLayers::doAction() |
| 48 |
{ |
| 49 |
if (!m_app) |
| 50 |
{ |
| 51 |
assert(false); |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
// check selection |
| 56 |
const ccHObject::Container& selectedEntities = m_app->getSelectedEntities(); |
| 57 |
if (!m_app->haveOneSelection() || !selectedEntities.front()->isA(CC_TYPES::POINT_CLOUD)) |
| 58 |
{ |
| 59 |
m_app->dispToConsole("Select only one point cloud!", ccMainAppInterface::ERR_CONSOLE_MESSAGE); |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
// get first selected cloud |
| 64 |
ccPointCloud* cloud = static_cast<ccPointCloud*>(selectedEntities.front()); |
| 65 |
|
| 66 |
if (!cloud->hasScalarFields()) |
| 67 |
{ |
| 68 |
ccLog::Error("Cloud has no scalar field"); |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
// set colors schema to RGB |
| 73 |
m_app->updateUI(); |
| 74 |
|
| 75 |
if (!m_cloudLayersDlg) |
| 76 |
{ |
| 77 |
m_cloudLayersDlg = new ccCloudLayersDlg(m_app, m_app->getMainWindow()); |
| 78 |
m_app->registerOverlayDialog(m_cloudLayersDlg, Qt::TopRightCorner); |
| 79 |
} |
| 80 |
|
| 81 |
//we disable all other windows |
| 82 |
m_app->disableAllBut(m_app->getActiveGLWindow()); |
| 83 |
|
| 84 |
m_cloudLayersDlg->linkWith(m_app->getActiveGLWindow()); |
| 85 |
m_cloudLayersDlg->setPointCloud(cloud); |
| 86 |
|
| 87 |
if (m_cloudLayersDlg->start()) |
| 88 |
{ |
| 89 |
m_app->updateOverlayDialogsPlacement(); |
| 90 |
} |
| 91 |
} |