CloudCompare插件编写

目录

一、准备

1.文件下载

二、步骤

1. 文件复制

2. 文件修改

3. 重新编译

4. 运行程序

三、总结




一、准备

1.文件下载

github下载CloudCompare源代码CloudCompare (GPL) · GitHub

下载CCCoreLib: https://github.com/CloudCompare/CCCoreLib 解压后全部文件放到 \libs\qCC_db\extern\CCCoreLib目录下

2.Cmake编译:(这里我选上了常用的CGAL和PCL)其他需要的库建议用vcpkg配置

使用新版本的VS打开项目编译成功(本人用的vs2017,2015编译会出现一些错误)



二、步骤



1. 文件复制

复制以下文件夹

 修改文件夹名称为qObor

在..\plugins\core\Standard目录下的CmkaleLists添加:

这一步骤的目的是为了在cmake编译时像其他插件那样,自动添加该插件的可选择目录



2. 文件修改

打开刚才复制和修改名字后的qObor文件夹,现在逐个修改文件

  • 修改include

将ExamplePlugin.h重命名为qObor.h。打开该文件,将所有的ExamplePlugin修改为qObor

//##########################################################################
//#                                                                        #
//#                CLOUDCOMPARE PLUGIN: qObor                      #
//#                                                                        #
//#  This program is free software; you can redistribute it and/or modify  #
//#  it under the terms of the GNU General Public License as published by  #
//#  the Free Software Foundation; version 2 of the License.               #
//#                                                                        #
//#  This program is distributed in the hope that it will be useful,       #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
//#  GNU General Public License for more details.                          #
//#                                                                        #
//#                             COPYRIGHT: XXX                             #
//#                                                                        #
//##########################################################################

#pragma once

#include "ccStdPluginInterface.h"

//! Example qCC plugin
/** Replace 'qObor' by your own plugin class name throughout and then
	check 'qObor.cpp' for more directions.

	Each plugin requires an info.json file to provide information about itself -
	the name, authors, maintainers, icon, etc..

	The one method you are required to implement is 'getActions'. This should
	return all actions (QAction objects) for the plugin. CloudCompare will
	automatically add these with their icons in the plugin toolbar and to the
	plugin menu. If	your plugin returns	several actions, CC will create a
	dedicated toolbar and a	sub-menu for your plugin. You are responsible for
	connecting these actions to	methods in your plugin.

	Use the ccStdPluginInterface::m_app variable for access to most of the CC
	components (database, 3D views, console, etc.) - see the ccMainAppInterface
	class in ccMainAppInterface.h.
**/
class qObor : public QObject, public ccStdPluginInterface
{
	Q_OBJECT
	Q_INTERFACES( ccPluginInterface ccStdPluginInterface )

	// Replace "Example" by your plugin name (IID should be unique - let's hope your plugin name is unique ;)
	// The info.json file provides information about the plugin to the loading system and
	// it is displayed in the plugin information dialog.
	Q_PLUGIN_METADATA( IID "cccorp.cloudcompare.plugin.qObor" FILE "../info.json" )

public:
	explicit qObor( QObject *parent = nullptr );
	~qObor() override = default;

	// Inherited from ccStdPluginInterface
	void onNewSelection( const ccHObject::Container &selectedEntities ) override;
	QList<QAction *> getActions() override;

protected:

	//! Slot called when associated ation is triggered
	void doAction();

private:
	//! Default action
	/** You can add as many actions as you want in a plugin.
		Each action will correspond to an icon in the dedicated
		toolbar and an entry in the plugin menu.
	**/
	QAction* m_action;
};

添加了以下代码段后可以将ActionA.h文件删掉

protected:
    void doAction();

修改CmakeLists:

target_sources( ${PROJECT_NAME}
	PRIVATE
		${CMAKE_CURRENT_LIST_DIR}/qObor.h
)

target_include_directories( ${PROJECT_NAME}
	PRIVATE
		${CMAKE_CURRENT_SOURCE_DIR}
)
  •  修改src文件夹

同上

//##########################################################################
//#                                                                        #
//#                CLOUDCOMPARE PLUGIN: qObor                      #
//#                                                                        #
//#  This program is free software; you can redistribute it and/or modify  #
//#  it under the terms of the GNU General Public License as published by  #
//#  the Free Software Foundation; version 2 of the License.               #
//#                                                                        #
//#  This program is distributed in the hope that it will be useful,       #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
//#  GNU General Public License for more details.                          #
//#                                                                        #
//#                             COPYRIGHT: XXX                             #
//#                                                                        #
//##########################################################################

// First:
//	Replace all occurrences of 'qObor' by your own plugin class name in this file.
//	This includes the resource path to info.json in the constructor.

// Second:
//	Open qObor.qrc, change the "prefix" and the icon filename for your plugin.
//	Change the name of the file to <yourPluginName>.qrc

// Third:
//	Open the info.json file and fill in the information about the plugin.
//	 "type" should be one of: "Standard", "GL", or "I/O" (required)
//	 "name" is the name of the plugin (required)
//	 "icon" is the Qt resource path to the plugin's icon (from the .qrc file)
//	 "description" is used as a tootip if the plugin has actions and is displayed in the plugin dialog
//	 "authors", "maintainers", and "references" show up in the plugin dialog as well

#include <QtGui>

#include "qObor.h"


// Default constructor:
//	- pass the Qt resource path to the info.json file (from <yourPluginName>.qrc file) 
//  - constructor should mainly be used to initialize actions and other members
qObor::qObor( QObject *parent )
	: QObject( parent )
	, ccStdPluginInterface( ":/CC/plugin/qObor/info.json" )
	, m_action( nullptr )
{
}

// This method should enable or disable your plugin actions
// depending on the currently selected entities ('selectedEntities').
void qObor::onNewSelection( const ccHObject::Container &selectedEntities )
{
	if ( m_action == nullptr )
	{
		return;
	}
	
	// If you need to check for a specific type of object, you can use the methods
	// in ccHObjectCaster.h or loop and check the objects' classIDs like this:
	//
	//	for ( ccHObject *object : selectedEntities )
	//	{
	//		if ( object->getClassID() == CC_TYPES::VIEWPORT_2D_OBJECT )
	//		{
	//			// ... do something with the viewports
	//		}
	//	}
	
	// For example - only enable our action if something is selected.
	m_action->setEnabled( !selectedEntities.empty() );
}

// This method returns all the 'actions' your plugin can perform.
// getActions() will be called only once, when plugin is loaded.
QList<QAction *> qObor::getActions()
{
	// default action (if it has not been already created, this is the moment to do it)
	if ( !m_action )
	{
		// Here we use the default plugin name, description, and icon,
		// but each action should have its own.
		m_action = new QAction( getName(), this );
		m_action->setToolTip( getDescription() );
		m_action->setIcon( getIcon() );
		
		// Connect appropriate signal
		connect( m_action, &QAction::triggered, this, &qObor::doAction);
	}

	return { m_action };
}

void qObor::doAction()
{
	if (!m_app)
	{
		assert(false);
		return;
	}

	if (!m_app->haveSelection())
	{
		assert(false);
		return;
	}
}

所有程序的实现在doAction函数中 

CmakeLists:

target_sources( ${PROJECT_NAME}
	PRIVATE
		${CMAKE_CURRENT_LIST_DIR}/qObor.cpp
)
  •  qObor文件夹下的CmakeList
option( PLUGIN_STANDARD_QOBOR "Install qObor plugin" ON )

if( PLUGIN_STANDARD_QOBOR )
	project( QOBOR_PLUGIN )

	AddPlugin( NAME ${PROJECT_NAME} )
	
	add_subdirectory( include )
	add_subdirectory( src )
endif()
  •  修改ExamplePlugin.qrc

修改ExamplePlugin.qrc为修改qObor.qrc,打开后修改为

<RCC>
  <qresource prefix="/CC/plugin/qObor" >
    <file>images/icon.png</file>
    <file>info.json</file>
  </qresource>
</RCC>
  •  修改info.json
"name" : "qObor",
"icon" : ":/CC/plugin/qObor/images/icon.png",

3. 重新编译

 

 生成QOBOR_PLUGIN.dll,在..\CloudCompareProj\qCC\Release文件夹下新建plugins文件夹,将生成的QOBOR_PLUGIN.dll放入文件夹下。

4. 运行程序

运行程序,插件显示成功





三、总结

1.名称一定要修改正确。

2.文件放到指定的位置。

3.编译正确后,运行程序才显示插件。

4.所有程序的实现在doAction函数中(后期会写一些功能实现)

5.如果编写的程序需要其他附加库,则需要将dll、lib添加到..\CloudCompareProj\qCC\Release中,否则不显示插件(简单的办法还没摸索出来)。

6.添加UI的插件可以参考qCSF等文件夹

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值