天天看點

CC插件開發——标準插件的建立流程

請提前準備:已經編譯好的cloudCompare,可參考這篇部落格。建立流程如下:

  1. CC中提供了示例插件,複制一份到标準插件中,如下圖所示:
    CC插件開發——标準插件的建立流程
  2. 在…/CloudCompare-2.11.3\plugins\core\Standard檔案夾下的cmakelists.txt加上add_subdirectory( TestPlugin ),TestPlugin改為你的插件名。
    CC插件開發——标準插件的建立流程
  3. 用自己的插件名替換ExamplePlugin中檔案的名字(包括該檔案夾的名字),例如建立一個TestPlugin,修改後如下圖所示:
    CC插件開發——标準插件的建立流程
  4. 修改檔案内容

    ① 如果想更換插件在CC中顯示的圖示,首先請将圖檔放至image檔案夾中;

    ② 修改cMakeLists.txt檔案的内容,它的部分資訊如下圖:

    CC插件開發——标準插件的建立流程
    修改後應為:
cmake_minimum_required( VERSION 3.0 )

option( PLUGIN_STANDARD_TESTPLUGIN "Check to install testPlugin" OFF )

if ( PLUGIN_STANDARD_TESTPLUGIN )
	
    project( TestPlugin )
    
    include( ../../../CMakePluginTpl.cmake )
    
endif()
           

③ 修改info.json的内容,這個檔案多為描述資訊,改掉name和icon,将ExamplePlugin替換成TestPlugin。如果想要更換圖檔,修改路徑即可。其餘資訊可自行更改。

{
	"type" : "Standard",
	"name" : "TestPlugin",
	"icon" : ":/CC/plugin/TestPlugin/images/icon.png",
	"description": "This is a description of the marvelous Example plugin. It does nothing.",
	"authors" : [
		{
			"name" : "Daniel Girardeau-Montaut",
			"email" : "[email protected]"
		}
	],
	"maintainers" : [
		{
			"name" : "Andy Maloney",
			"email" : "[email protected]"
		},
		{
			"name" : "Example NoEmail"
		}
	],
	"references" : [
		{
			"text" : "The unsuccessful self-treatment of a case of “writer's block”",
			"url" : "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1311997/"
		},
		{
			"text" : "Sword swallowing and its side effects",
			"url" : "http://www.bmj.com/content/333/7582/1285"
		},
		{
			"text" : "I thought of creating this wonderful plugin while I was hiking up ⛰ Mont Blanc"
		}
	]
}

           

④ 修改TestPlugin.qrc的内容,将ExamplePlugin替換成TestPlugin,如果想要更換圖檔,修改路徑即可。

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

           

⑤ 最後就是頭檔案TestPlugin.h和源檔案TestPlugin.cpp了,隻需将這兩個檔案中所有的ExamplePlugin替換成TestPlugin,按照下圖方式更改即可(ctrl+F打開搜尋替換框)。另外需要注意的是下圖中紅框中為插件的唯一表示,請将最後的Example改為插件名TestPlugin。

CC插件開發——标準插件的建立流程

4. 打開cmake,點選config,結果如下。勾選上自己的插件後再次點選config,然後點選generate即完成建構。最後點選Open Project,打開項目(也可在build目錄下找到CloudCompareProjects.sln,輕按兩下打開項目)。

CC插件開發——标準插件的建立流程

5. 這樣在項目中就可以看到我們的插件了。

CC插件開發——标準插件的建立流程

繼續閱讀