CloudCompare官方给出了虚拟功能QDummyPlugin,可对其进行修改完成自己的功能。
笔者以新建功能xj(单击出现弹出对话框)为例,进行功能编写。
1、修改源码
在源码的plugins目录下新建xj文件夹,新建或复制QDummyPlugin下的5个文件并修改。
(1)CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
#REPLACE ALL 'DUMMY' OCCURENCES BY YOUR PLUGIN NAME
#AND ADAPT THE CODE BELOW TO YOUR OWN NEEDS!
option( INSTALL_xj_PLUGIN "Check to install xj plugin" ON )
if (INSTALL_xj_PLUGIN)
#CloudCompare 'DUMMY' plugin
project( xj )
#load necessary libraries (see qPCV for an example)
#add_subdirectory (LIB1)
#if the plugin is an 'OpenGL filter', uncomment the line below
#set( CC_OPENGL_FILTER ON BOOL)
include( ../CMakePluginTpl.cmake )
#set dependencies to necessary libraries (see qPCV for an example)
#target_link_libraries( ${PROJECT_NAME} LIB1 )
#include_directories( ${LIB1_INCLUDE_DIR} )
endif()
(2)xj.cpp
主要算法或功能在 doAction()中填写
#include "xj.h"
//Qt
#include <QtGui>
#include <QTextCodec>
#include <QTranslator>
xj::xj(QObject* parent/*=0*/)
: QObject(parent)
, m_action(0)
{
#pragma region 中文
QTextCodec::setCodecForTr(QTextCodec::codecForName("system"));//#include <QTextCodec>
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("system"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("system"));
QTranslator translator(0);//#include <QTranslator>
translator.load("qt_zh_CN.qm");
#pragma endregion
}
void xj::onNewSelection(const ccHObject::Container& selectedEntities)
{
//if (m_action)
// m_action->setEnabled(!selectedEntities.empty());
}
void xj::getActions(QActionGroup& group)
{
//default action (if it has not been already created, it's the moment to do it)
if (!m_action)
{
//here we use the default plugin name, description and icon,
//but each action can have its own!
m_action = new QAction(getName(),this);
m_action->setToolTip(getDescription());
m_action->setIcon(getIcon());
//connect appropriate signal
connect(m_action, SIGNAL(triggered()), this, SLOT(doAction()));
}
group.addAction(m_action);
}
void xj::doAction()
{
//m_app should have already been initialized by CC when plugin is loaded!
//(--> pure internal check)
assert(m_app);
if (!m_app)
return;
/*** HERE STARTS THE ACTION ***/
//put your code here
//--> you may want to start by asking parameters (with a custom dialog, etc.)
//核心算法或功能
QMessageBox::warning(0,"dd","ddd");
//This is how you can output messages
m_app->dispToConsole("[xj] Hello world!",ccMainAppInterface::STD_CONSOLE_MESSAGE); //a standard message is displayed in the console
m_app->dispToConsole("[xj] Warning: xj plugin shouldn't be used as is!",ccMainAppInterface::WRN_CONSOLE_MESSAGE); //a warning message is displayed in the console
m_app->dispToConsole("xj plugin shouldn't be used as is!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); //an error message is displayed in the console AND an error box will pop-up!
/*** HERE ENDS THE ACTION ***/
}
QIcon xj::getIcon() const
{
//open xj.qrc (text file), update the "prefix" and the
//icon(s) filename(s). Then save it with the right name (yourPlugin.qrc).
//(eventually, remove the original xj.qrc file!)
return QIcon(":/CC/plugin/xj/bg.jpg");
}
(3)xj.h
#ifndef xj_PLUGIN_HEADER
#define xj_PLUGIN_HEADER
//qCC
#include "../ccStdPluginInterface.h"
//Qt
#include <QObject>
#include <QString>
class xj : public QObject, public ccStdPluginInterface
{
Q_OBJECT
Q_INTERFACES(ccStdPluginInterface)
#ifdef CC_QT5
//replace xj by the plugin name (IID should be unique - let's hope your plugin name is unique ;)
Q_PLUGIN_METADATA(IID "cccorp.cloudcompare.plugin.xj")
#endif
public:
//! Default constructor
explicit xj(QObject* parent = 0);
//inherited from ccPluginInterface
virtual QString getName() const { return "界面显示中文插件名称"; }
virtual QString getDescription() const { return "xj (dddddddddddddddddddddddddddd)"; }
virtual QIcon getIcon() const;
//inherited from ccStdPluginInterface
void onNewSelection(const ccHObject::Container& selectedEntities);
virtual void getActions(QActionGroup& group);
protected slots:
/*** ADD YOUR CUSTOM ACTIONS' SLOTS HERE ***/
void doAction();
protected:
QAction* m_action;
};
#endif
(4)xj.qrc
<RCC>
<qresource prefix="/CC/plugin/xj" >
<file>bg.jpg</file>
</qresource>
</RCC>
(5)图片根据个人喜好修改,笔者改成了bg.jpg。嘻嘻
2、CMAKE
按照流程,选择“INSTALL_xj_PLUGIN”,编译即可。
3、生成
VS中可以看到xj这个项目,生成解决方案即可。将…\plugins\xj\Release\xj.dll复制到…\qCC\Release\plugins目录下。
4、结果