一、cmake 建構 cloudcompare工程
- 打開cmake GUI 設定源代碼和輸出檔案路徑 點選configure後,設定相應配置:
- 設定QT安裝路徑
- 選擇所需插件
再次點選Configure 無誤後,再點選Generate即可
但是由于部分插件需要一些依賴庫需自行下載下傳,如
在配置時同樣需設定好相應的檔案路徑 打開工程即完成即可進行編譯二、添加自己的插件
我們希望在右邊工具欄加入自己的插件
- 在源代碼路徑\CloudCompare-master\plugins\core\Standard\下建立一個檔案夾 TestPlugin
- 在TestPlugin檔案夾下建立五個空檔案
- TestPlugin.h裡内容如下
#ifndef TestPlugin_PLUGIN_HEADER
#define TestPlugin_PLUGIN_HEADER
#include "ccStdPluginInterface.h"
class TestPlugin : public QObject, public ccStdPluginInterface
{
Q_OBJECT
Q_INTERFACES(ccStdPluginInterface)
Q_PLUGIN_METADATA(IID "cccorp.cloudcompare.plugin.TestPlugin" FILE "info.json")
public:
//! Default constructor
explicit TestPlugin(QObject* parent = nullptr);
virtual ~TestPlugin() = default;
//inherited from ccStdPluginInterface
virtual void onNewSelection(const ccHObject::Container& selectedEntities) override;
virtual QList<QAction *> getActions() override;
protected slots:
//! Slot called when associated ation is triggered
void doAction();
protected:
//! Associated action
QAction* m_action;
};
#endif //TestPlugin_PLUGIN_HEADER
TestPlugin.cpp裡内容如下
#include "TestPlugin.h"
//qCC_db
#include <ccPointCloud.h>
//Qt
#include <QMainWindow>
#include <QProgressDialog>
//system
#include <assert.h>
TestPlugin::TestPlugin(QObject* parent)
: QObject(parent)
, ccStdPluginInterface( ":/CC/plugin/TestPlugin/info.json" )
, m_action( nullptr )
{
}
void TestPlugin::onNewSelection(const ccHObject::Container& selectedEntities)
{
//此處設定是否需要有點雲時激活插件
if (m_action)
{
for (ccHObject* entity : selectedEntities)
{
//if we have found at least one cloud
if (entity && entity->isA(CC_TYPES::POINT_CLOUD))
{
m_action->setEnabled(true);
return;
}
}
//no cloud?
m_action->setEnabled(true);// 為True則不需要點雲也可以激活插件,為false則需要點雲才可以激活插件
}
}
QList<QAction *> TestPlugin::getActions()
{
//default action
if (!m_action)
{
m_action = new QAction(getName(),this);
m_action->setToolTip(getDescription());
m_action->setIcon(getIcon());
//connect signal
connect(m_action, &QAction::triggered, this, &TestPlugin::doAction);
}
return QList<QAction *>{ m_action };
}
//persistent settings during a single session
// CoamingMeasurmentDialog::Parameters s_params;
void TestPlugin::doAction()
{
ccLog::LogMessage("hello",1);//這裡設定TestPlugin點選一下,日志欄輸出hello字樣
//currently selected entities parameters may have changed!
m_app->updateUI();
//currently selected entities appearance may have changed!
m_app->refreshAll();
}
- TestPlugin.qrc裡内容如下,這是QT資源檔案添加了兩個資源(images/TestPlugin.png)和(info.json),是以需把這兩個資源補齊
<RCC>
<qresource prefix="/CC/plugin/TestPlugin" >
<file>images/TestPlugin.png</file>
<file>info.json</file>
</qresource>
</RCC>
- 在TestPlugin目錄下在建立一個目錄images,并在目錄下放置一個TestPlugin.PNG檔案,這個圖檔就是插件的圖示
- info.json内容如下,這是插件的資訊描述,在對應模闆處填寫相應資訊即可
{
"type" : "Standard",
"core" : true,
"name" : "TestPlugin",
"icon" : ":/CC/plugin/TestPlugin/images/TestPlugin.png",
"description": "",
"authors" : [
{
"name" : "",
"email" : ""
}
],
"maintainers" : [
{
"name" : "",
"email" : ""
}
],
"references" : [
{
"text": "\" \"<br/>
Talk by Alexandre Boulch & Renaud Marlet at the Symposium of Geometry Processing, 2016",
"url" : ""
},
{
"text": "TestPlugin library",
"url": ""
},
{
"text": "Documentation",
"url": ""
}
]
}
- CMakeLists.txt内容如下
cmake_minimum_required(VERSION 3.0)
option( PLUGIN_STANDARD_TestPlugin "Check to install TestPlugin plugin" ON )
if (PLUGIN_STANDARD_TestPlugin)
project( TestPlugin )
include( ../../../CMakePluginTpl.cmake )
target_link_libraries( ${PROJECT_NAME} )
target_link_libraries( ${PROJECT_NAME} ${OPENGL_LIBRARIES} )
endif()
- 傳回上一級目錄,修改此處CmakeLists.txt
在行尾追加 add_subdirectory(TestPlugin)
- 最後重複步驟一,重新建構工程檔案,打開在解決方案中即出現TestPlugin工程
編譯,插件已在工具欄中,點選運作出現hello輸出字樣