CloudCompare 插件调试

当使用cloudcompare开发新的插件功能时,同样需要像vs一样进行插件代码的逐行调试,以加快插件开发的进度。

1.创建插件文件夹

首先使用cmake+vs完成cloudcompare的插件安装,具体步骤如下:在cloudcompare源代码中的core模块中创建了qStar文件夹。


2.新建相关文件

在qStar文件夹中建立以下文件和文件夹

 (1)images文件夹下存放了插件的图标。

 (2)CMakeLists用于配置cmake编译插件的功能设置。文件的内容如下:(注:若要建立新的插件,需要将qStar全部替换为新的插件名。)
 

cmake_minimum_required( VERSION 3.0 )

option( PLUGIN_STANDARD_qStar  "Check to install example plugin" ON )

if ( PLUGIN_STANDARD_qStar )
	# Name the plugin
    project( qStar)
    

    include( ../../../CMakePluginTpl.cmake )
    
endif()

(3)info.json用于描述插件的基本信息。内容如下:(注:若要建立新的插件,需要将qStar全部替换为新的插件名。)

{
  "type": "Standard",
  "core": true,
  "name": "qStar",
  "icon": ":/CC/plugin/qStar/images/qStar.png",
  "description": "This is a description of the  qStar.",
  "authors": [
    {
      "name": "beidoustars",
      "email": "beidou_stars@163.com"
    }
  ],
  "maintainers": [
    {
      "name": "beidoustars",
      "email": ""
    },
    {
      "name": ""
    }
  ],
  "references": [
    {
      "text": "",
      "url": ""
    },
    {
      "text": "",
      "url": ""
    },
    {
      "text": ""
    }
  ]
}

(4)qStar.cpp插件的具体实现,其中的doAction函数就是用于添加和实现插件具体功能的函数。内容如下:注:若要建立新的插件,需要将qStar全部替换为新的插件名。)

//##########################################################################
//#                                                                        #
//#                CLOUDCOMPARE PLUGIN: ExamplePlugin                      #
//#                                                                        #
//#  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 'ExamplePlugin' by your own plugin class name in this file.
//	This includes the resource path to info.json in the constructor.

// Second:
//	Open ExamplePlugin.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 "qStar.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
qStar::qStar( QObject *parent )
	: QObject( parent )
	, ccStdPluginInterface( ":/CC/plugin/qStar/info.json" )
	, m_action( nullptr )
{
}

// This method should enable or disable your plugin actions
// depending on the currently selected entities ('selectedEntities').
void qStar::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 *> qStar::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, &qStar::doAction );
	}

	return { m_action };
}

// This is an example of an action's method called when the corresponding action
// is triggered (i.e. the corresponding icon or menu entry is clicked in CC's
// main interface). You can access most of CC's components (database,
// 3D views, console, etc.) via the 'm_app' variable (see the ccMainAppInterface
// class in ccMainAppInterface.h).
void qStar::doAction()
{	
	if ( m_app == nullptr )
	{
		// m_app should have already been initialized by CC when plugin is loaded
		Q_ASSERT( false );
		
		return;
	}

	/*** HERE STARTS THE ACTION ***/

	// Put your code here
	// --> you may want to start by asking for parameters (with a custom dialog, etc.)

	// This is how you can output messages
    ccLog::LogMessage("hello", 1);
	// Display a standard message in the console
	m_app->dispToConsole( "[qStar] Hello world!", ccMainAppInterface::STD_CONSOLE_MESSAGE );
	
	// Display a warning message in the console
	m_app->dispToConsole( "[qStar] Warning: example plugin shouldn't be used as is", ccMainAppInterface::WRN_CONSOLE_MESSAGE );
	
	// Display an error message in the console AND pop-up an error box
	m_app->dispToConsole( "Example plugin shouldn't be used - it doesn't do anything!", ccMainAppInterface::ERR_CONSOLE_MESSAGE );

	/*** HERE ENDS THE ACTION ***/
}

(5)qStar.h插件头文件。(注:若要建立新的插件,需要将qStar全部替换为新的插件名。)

#ifndef Q_STAR_PLUGIN_HEADER
#define Q_STAR_PLUGIN_HEADER

//##########################################################################
//#                                                                        #
//#                CLOUDCOMPARE PLUGIN: ExamplePlugin                      #
//#                                                                        #
//#  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                             #
//#                                                                        #
//##########################################################################

#include "ccStdPluginInterface.h"

//! Example qCC plugin
/** Replace 'ExamplePlugin' by your own plugin class name throughout and then
	check 'ExamplePlugin.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 qStar : public QObject, public ccStdPluginInterface
{
	Q_OBJECT
	Q_INTERFACES(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.qStar" FILE "info.json")
	
public:
	explicit qStar( QObject *parent = nullptr );
	~qStar() override = default;
	
	// inherited from ccStdPluginInterface
	void onNewSelection( const ccHObject::Container &selectedEntities ) override;
	QList<QAction *> getActions() override;
	
private:
	/*** ADD YOUR CUSTOM ACTIONS HERE ***/
	void doAction();
	
	//! 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;
};

#endif

(6)qStar.qrc用于文件的相关路径配置,内容如下:(注:若要建立新的插件,需要将qStar全部替换为新的插件名。)

<RCC>
    <qresource prefix="/CC/plugin/qStar">
        <file>images/qStar.png</file>
        <file>info.json</file>
    </qresource>
</RCC>

3.cmake编译

qStar文件夹创建完成后,采用cmake 编译生成CloudCompareProjects.sln,然后采用vs生成解决方案(具体步骤可参考我的另外一篇博客:cloudcompare插件编译)。注意vs生成解决方案时要选择Debug模式。

4.插件调试


完成上一步操作后,在prefix文件夹(该文件夹为vs的INSTALL生成目录,是在cmake编译时设置的)中生成了CloudCompare_debug文件夹,将CloudCompare_debug中的CC_CORE_LIBd.dll,

QCC_DB_LIBd.dll,QCC_IO_LIBd.dll拷贝到CloudCompare-2.11.3-build\qCC\Debug路径下。在该路径下建立plugins文件夹,并把CloudCompare-2.11.3-build\plugins\core\Standard\qStar\Debug中的qStard.dll复制到Debug中新建的plugins文件夹。
再次打开CloudCompareProjects.sln,将cloudcompare设置为启动项。
最后回到CloudCompare-2.11.3-build\qCC\Debug文件夹中,如下图所示:

 在CloudCompareProjects.sln中的qStar模块的源文件中添加断点,点击调试运行即可。一旦开始调试就会启动cloudcompare,然后加载点云文件,点击插件的图标,就可运行至断点处暂停。

 

 至此就可以进行单步调试,但每次修改代码后,需要重新点击生成,并将生成的qStard.dll进行相应的替换,否则修改的代码无法生效。

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值