糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > [CC]CC插件初探

[CC]CC插件初探

时间:2024-04-23 12:02:19

相关推荐

[CC]CC插件初探

应用程序插件框架的内容包括:主程序App,插件Plugin。

1、实现一个应用程序插架框架关键点有:

一个插件的标准接口,在主程序中存在一个插件的集合。主程序通过循环读取每个插件,将插件对象通过多态的机制转换为插件接口,实现插件的装载。

主程序对象或者主程序接口需要作为参数传递到插件对象中,以方便插件对象调用主程序的内容,如主视图、工具栏、树视图、状态栏等。

2、开源点云处理软件CloudCompare也是一个插件框架,因此也必然包括这些内容。

插件接口:ccPluginInterface,每个插件对象有在ccPluginInterface基础上定义了一个新的接口类class ccStdPluginInterface : public ccPluginInterface

具体的插件则继承自ccStdPluginInterface 累,比如这样,class qMyPlugin : public QObject, public ccStdPluginInterface

主程序对象:class ccMainAppInterface,MainWindow主窗体类实现了ccMainAppInterface接口。

MainWindow::loadPlugins()方法负责插件的调用。(mainwindow.cpp文件中)

1 void MainWindow::loadPlugins() 2 { 3menuPlugins->setEnabled(false); 4menuShadersAndFilters->setEnabled(false); 5toolBarPluginTools->setVisible(false); 6toolBarGLFilters->setVisible(false); 7 8//"static" plugins 9foreach (QObject *plugin, QPluginLoader::staticInstances())10 dispatchPlugin(plugin);11 12ccConsole::Print(QString("Application path: ")+QCoreApplication::applicationDirPath());13 14 #if defined(Q_OS_MAC)15// plugins are in the bundle16QString path = QCoreApplication::applicationDirPath();17path.remove( "MacOS" );18m_pluginsPath = path + "Plugins/ccPlugins";19 #else20//plugins are in bin/plugins21m_pluginsPath = QCoreApplication::applicationDirPath()+QString("/plugins");22 #endif23 24ccConsole::Print(QString("Plugins lookup dir.: %1").arg(m_pluginsPath));25 26QStringList filters;27 #if defined(Q_OS_WIN)28filters << "*.dll";29 #elif defined(Q_OS_LINUX)30filters << "*.so";31 #elif defined(Q_OS_MAC)32filters << "*.dylib";33 #endif34QDir pluginsDir(m_pluginsPath);35pluginsDir.setNameFilters(filters);36foreach (QString filename, pluginsDir.entryList(filters))37{38 QPluginLoader loader(pluginsDir.absoluteFilePath(filename));39 QObject* plugin = loader.instance();40 if (plugin)41 {42 ccConsole::Print(QString("Found new plugin: '%1'").arg(filename));43 if (dispatchPlugin(plugin))44 {45 m_pluginFileNames += filename;46 }47 else48 {49 delete plugin;50 plugin = 0;51 ccConsole::Warning("\tUnsupported or invalid plugin type");52 }53 }54 else55 {56 delete plugin;57 plugin = 0;58 ccConsole::Warning(QString("[Plugin] %1")/*.arg(pluginsDir.absoluteFilePath(filename))*/.arg(loader.errorString()));59 }60}61 62if (menuPlugins)63{64 menuPlugins->setEnabled(!m_stdPlugins.empty());65}66 67if (toolBarPluginTools->isEnabled())68{69 actionDisplayPluginTools->setEnabled(true);70 actionDisplayPluginTools->setChecked(true);71}72else73{74 //DGM: doesn't work :(75 //actionDisplayPluginTools->setChecked(false);76}77 78if (toolBarGLFilters->isEnabled())79{80 actionDisplayGLFiltersTools->setEnabled(true);81 actionDisplayGLFiltersTools->setChecked(true);82}83else84{85 //DGM: doesn't work :(86 //actionDisplayGLFiltersTools->setChecked(false);87}88 }

主程序在加载插件时会调用插件的setMainAppInterface方法,将主程序参数传入,这样插件就可以获取主程序的内容了。

1 //! Sets application entry point2 /** Called just after plugin creation by qCC3 **/4 virtual void setMainAppInterface(ccMainAppInterface* app);

3、获取主窗体中的点云图层

在doAction中的代码:

1const ccHObject::Container& selectedEntities = m_app->getSelectedEntities(); 2size_t selNum = selectedEntities.size(); 3if (selNum!=1) 4{ 5 m_app->dispToConsole("Select only one cloud!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); 6 return; 7} 8 9ccHObject* ent = selectedEntities[0];10assert(ent);11if (!ent || !ent->isA(CC_TYPES::POINT_CLOUD))12{13 m_app->dispToConsole("Select a real point cloud!",ccMainAppInterface::ERR_CONSOLE_MESSAGE);14 return;15}16 17ccPointCloud* pc = static_cast<ccPointCloud*>(ent);18 19//input cloud20unsigned count = pc->size();21bool hasNorms = pc->hasNormals();22CCVector3 bbMin, bbMax;23pc->getBoundingBox(bbMin,bbMax);24const CCVector3d& globalShift = pc->getGlobalShift();25double globalScale = pc->getGlobalScale();

如果觉得《[CC]CC插件初探》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。