1 Star 6 Fork 5

Simon/DataWorkFlow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

简介

数据工作流设计器

编译

逻辑编辑器

逻辑编辑器负责组织描述逻辑,以工作流为基础,DataWorkFlow的工作流以插件模式加载入程序中,主要涉及以下两个基础个模块(模块顺序为依赖顺序):DAPluginDANode,同时Plugin\DAUtilNodePlugin为DataWorkFlow的基础节点插件,其他的插件编写可参考此插件编写。

插件

DAPlugin插件管理模块

DAPlugin模块是为了提供一个统一且简单的插件管理功能,此模块提供了插件的基类DAAbstractPlugin,作为DataWorkFlow的插件,只要继承此类,即可实现插件。

同时,DAPlugin模块提供了所有插件管理的单例:DAPluginManager,这是一个单例,可以用来加载和卸载插件,下面是通过此类加载插件的例子:

//加载插件
DAPluginManager& plugin = DAPluginManager::instance();

if (!plugin.isLoaded()) {
    plugin.load();
}
//获取插件
QList<DAPluginOption> plugins = plugin.getPluginOptions();

for (int i = 0; i < plugins.size(); ++i)
{
    DAPluginOption opt = plugins[i];
    if (!opt.isValid()) {
        continue;
    }
    DAAbstractPlugin *p = opt.plugin();
    //开始通过dynamic_cast判断插件的具体类型
    if (DAAbstractNodePlugin *np = dynamic_cast<DAAbstractNodePlugin *>(p)) {
        //说明是节点插件
        ...
        qDebug() << tr("succeed load plugin ") << np->getName();
    }
}

DAPluginOption维护着每个插件的内容,内部包含了此插件(dll)的一些基本信息

编写一个DAPlugin插件

要实现一个插件,必须在lib中实现两个函数,和实现一个插件类,以DAUtilNodePlugin为例,具体可参见src\Plugin\DAUtilNodePlugin

  • 首先继承DAAbstractNodePlugin实现自己的插件类,这里为了进一步抽象,定义了节点插件的基类DAAbstractNodePluginDAUtilNodePlugin继承于DAAbstractNodePlugin
class DANODE_API DAAbstractNodePlugin : public DAAbstractPlugin
{
public:
    DAAbstractNodePlugin();
    virtual ~DAAbstractNodePlugin();
    ...

};


class DAUtilNodePlugin : public DAAbstractNodePlugin
{
public:
    DAUtilNodePlugin();
    ~DAUtilNodePlugin();
};

DAUtilNodePlugin里将实现具体的功能,这里不描述

  • 导出函数plugin_createplugin_destory的实现

在实现了DAUtilNodePlugin类后,还需要实现两个C标准的导出函数,plugin_createplugin_destory

extern "C" DAUTILNODEPLUGIN_API DAAbstractPlugin *plugin_create();
extern "C" DAUTILNODEPLUGIN_API void plugin_destory(DAAbstractPlugin *p);

这两个函数是关键,插件系统在加载时需压根据c函数名来查找这两个函数

这两个函数的功能很简单, 就是生成插件,和删除插件,具体实现如下:

DAAbstractPlugin *plugin_create()
{
    return (new DAUtilNodePlugin());
}


void plugin_destory(DAAbstractPlugin *p)
{
    delete p;
}

这样,一个插件就能正常运行。

工作流

工作流主要的模块为DANode,这个模块为工作流的核心和最基本的抽象,此模块主要的几个类为:

  • 工作流的基本逻辑类: DAWorkFlow,DAAbstractNode,DAAbstractNodeFactory

  • 工作流的显示类: DAAbstractNodeGraphicsItem,DAAbstractNodeLinkGraphicsItem,DAAbstractNodeWidget,DANodeGraphicsScene,DANodeGraphicsView

工作流基于插件模式编写,后续用户可基于DANode模块实现自己的逻辑,具体可参见src\Plugin\DAUtilNodePlugin

工作流的思路

工作流由节点组成,节点间传递数据,每个节点可以运行用户定义的逻辑,一个工作流就是多个节点以及节点间的关系描述,节点有输入和输出,节点的输出可流入到下一个节点中,作为下个节点的输入。 每个节点的数据流出时,会收集输入数据,进行逻辑运算,再输出数据。

因此工作流的关键就是每个节点,每个节点可以理解为编程过程中的函数,节点的输入就是函数的传参,节点的输出就类似于函数的返回。

节点

节点作为工作流的关键,DANode模块的关键类就是DAAbstractNode,工作流都面向这个基类,具体功能的节点由用户自己继承DAAbstractNode来实现,例如src\Plugin\DAUtilNodePlugin\DAVariantValueNode.h

DAAbstractNode描述了节点的抽象信息,包括输入,输出,节点的连接,如果以一个函数为例,要通过一个节点描述一个类似函数的功能,这个节点应该具备如下要素:

  • 输入
  • 输出
  • 逻辑

因此DataWorkFlow的节点定义如下:

img

这个节点表示了一个加法函数

def add(a,b):
    return a+b

它有两个输入端a和b,他有一个输出端,由于函数的return是不需要具体描述的,但节点的输出要为其定义名称,因为后面节点的传递过程需要用到上个节点的输出,为了能知道哪个输出,所以输出也要定义名称。

因此节点的抽象类定义了输入参数名和输出参数名,对应两个接口函数:getInputKeysgetOutputKeys

//获取所有输入的参数名
virtual QList<QString> getInputKeys() const = 0;
//获取所有输出的参数名
virtual QList<QString> getOutputKeys() const = 0;

要实现一个节点,必须指定这个节点输入什么,输出什么,当然,可以没有输入,也可以没有输出。

节点的生成

上面说了节点的抽象,实际一个工作流是由多个节点组成,而DataWorkFlow是由插件组成,如何知道程序有哪些节点,这里参考程序开发的import

节点的生成由节点工厂实现,节点工厂可以理解为一个程序包,程序包里有多个函数,节点工厂正是这样一个程序包。

DAAbstractNodeFactory类就是节点的抽象工厂,此类关键的函数是create接口,工厂将通过DANodeMetaData来生成一个节点

//工厂函数,创建一个DAAbstractNode,工厂不持有DAAbstractNode的管理权
    virtual DAAbstractNode *create(const DANodeMetaData& meta) = 0;

DANodeMetaData是节点的基本信息,其关键函数是:

QString getNodePrototype() const;

DANodeMetaData通过NodePrototype来决定new哪个节点。

一个程序可以import多个包,因此工作流也应该有多个节点工厂,汇总到一个"集团"中,"集团"再生成节点

这个"集团"就是DAWorkFlow类,这个类汇总了所有工厂,其关键函数如下:

//注册工厂
void registFactory(DAAbstractNodeFactory *factory);
//创建节点,会触发信号nodeCreated,DAWorkFlow保留节点的内存管理权
DAAbstractNodeSmtPtr createNode(const DANodeMetaData& md);

"集团"汇总了所有工厂,节点通过"集团"创建,程序启动过程,先加载插件,插件生成工厂,工厂在集团中注册,最后再通过集团生成节点,具体流程如下:

img

在程序启动完成后,所有节点工厂到注册到DAWorkFlow中,通过DAWorkFlow即可生成节点。

节点的渲染

节点的渲染基于Qt的Graphics View Framework,通过Graphics View来实现渲染,整个工作流作为一个画布(QGraphicsScene),为此DANode模块提供了DANodeGraphicsScene,DANodeGraphicsViewDAAbstractNodeGraphicsItem来实现

DAAbstractNodeGraphicsItem对应一个DAAbstractNode,实际是通过DAAbstractNodecreateGraphicsItem接口来生成DAAbstractNodeGraphicsItem

因此,要实例化一个节点还需要实现接口函数DAAbstractNode::createGraphicsItem

//节点对应的item显示接口,所有node都需要提供一个供前端的显示接口
virtual DAAbstractNodeGraphicsItem *createGraphicsItem() = 0;

这个接口返回DAAbstractNode对应的GraphicsItem,DANode模块把节点的GraphicsItem抽象为DAAbstractNodeGraphicsItemDAAbstractNodeGraphicsItem实现了节点的基本渲染,结合DANodeGraphicsSceneDAAbstractNodeLinkGraphicsItem实现节点输入输出的连接工作。

对于用户来说,用户操作节点实现了节点之间的关系连接,这个要反应到逻辑层,逻辑层既为DAAbstractNode,因此,前端看到的连线动作,逻辑端实际是调用DAAbstractNodelinkTo函数,

//建立连接,如果基础的对象需要校验,可继承此函数
virtual bool linkTo(const QString& outpt, Pointer toItem, const QString& inpt);

在前端是通过DAAbstractNodeLinkGraphicsItem实现两个DAAbstractNodeGraphicsItem的连接,用户基本不需要关注DAAbstractNodeLinkGraphicsItem,用户只需要关心节点的连接点的生成。

用户实现自己的节点需要继承paintboundingRect函数

//绘图
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
//绘图相关
QRectF boundingRect() const;

DAAbstractNodeGraphicsItem已经默认实现了输入输出点的绘制,如果需要自定义,可以重写paintLinkPoint函数

//绘制某个连接点
virtual void paintLinkPoint(const DANodeLinkPoint& pl, QPainter *painter);

DANode模块提供了标准的节点渲染类DAStandardNodeGraphicsItem,此类实现了节点的名字显示和输入输出的显示。

响应Node事件

节点存在一些动作,如被传入参数等操作时,应该反映到GraphicsItem执行某些绘图操作,这时可以通过重写DAAbstractNodeGraphicsItem::nodeAction函数来实现

virtual void nodeAction(int action, const QVariant& v);

action动作参见DAAbstractNode::NodeAction枚举

标准节点渲染:DAStandardNodeGraphicsItem

标准节点渲染渲染了DAAbstractNode的输入端,输出端,和节点名,其效果如下:

img

上面演示了两种节点,一个节点只有输出,一个节点有3个输入,2个输出。

标准渲染节点具备如下特性

  • 标准节点由矩形绘制
  • 标准节点内部显示节点的名字
  • 输入端位于左侧,垂直均匀分布,以空心方块代表
  • 输出端位于右侧,垂直均匀分布,以实心方块代表
  • 点击输出端进入连线模式,鼠标点击对应的输入端实现节点与节点之间的关系建立
  • 连线过程点击鼠标右键取消连接状态
  • 选择连接线能看到连接点的名字

节点的操作

用户对节点的操作,例如赋予初始值等等需要用过界面实现,这时需要提供一个窗口给用户,DANode模块DAAbstractNodeWidget

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

基于Qt/C++,以工作流为基础的数据处理及可视化平台 展开 收起
README
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/simon1997/DataWorkFlow.git
git@gitee.com:simon1997/DataWorkFlow.git
simon1997
DataWorkFlow
DataWorkFlow
master

搜索帮助