Skip to content

Commit 7ecbf2d

Browse files
committed
[feat] add GRegion & GCondition python version.
1 parent 37d89f5 commit 7ecbf2d

File tree

14 files changed

+92
-33
lines changed

14 files changed

+92
-33
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ int main() {
348348
* 修复辅助线程异常等待问题
349349
* 更新`tutorial`内容
350350

351-
[2025.01.26 - v2.7.0 - Chunel]
351+
[2025.01.27 - v3.0.0 - Chunel]
352352
* 提供`stage`(阶段)功能,用于`element`之间同步运行
353-
* 提供简单 Python 封装功能
353+
* 提供 Python 封装
354354
* 更新`tutorial`内容
355355

356356
</details>

python/pyCGraph.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,30 @@ PYBIND11_MODULE(pyCGraph, m) {
2323
py::arg("runTimes") = 1)
2424
.def("destroy", &GPipelinePy::destroy)
2525
.def("registerGElement", &GPipelinePy::registerGElement,
26-
py::arg("element"),
27-
py::arg("depends") = GElementPtrSet{},
28-
py::arg("name") = CGRAPH_EMPTY,
29-
py::arg("loop") = CGRAPH_DEFAULT_LOOP_TIMES,
30-
"register a GElement with dependencies, name, and loop count.");
26+
py::arg("element"),
27+
py::arg("depends") = GElementPtrSet{},
28+
py::arg("name") = CGRAPH_EMPTY,
29+
py::arg("loop") = CGRAPH_DEFAULT_LOOP_TIMES,
30+
"register a GElement with dependencies, name, and loop count.");
3131

3232
py::class_<GElement, GElementPyw, std::unique_ptr<GElement, py::nodelete> >(m, "GElement")
33-
.def(py::init<>());
33+
.def(py::init<>())
34+
.def("getName", &GElement::getName)
35+
.def("setName", &GElement::setName)
36+
.def("addDependGElements", &GElement::addDependGElements,
37+
py::arg("elements"))
38+
.def("setLoop", &GElement::setLoop);
3439

3540
py::class_<GNode, GNodePyw, GElement, std::unique_ptr<GNode, py::nodelete> >(m, "GNode")
41+
.def(py::init<>());
42+
43+
py::class_<GRegionPy, GElement, std::unique_ptr<GRegionPy, py::nodelete> >(m, "GRegion")
44+
.def(py::init<>())
45+
.def("addGElement", &GRegionPy::addGElement,
46+
py::arg("element"));
47+
48+
py::class_<GConditionPyw, GElement, std::unique_ptr<GConditionPyw, py::nodelete> >(m, "GCondition")
3649
.def(py::init<>())
37-
.def("getName", &GNode::getName);
50+
.def("addGElement", &GConditionPyw::addGElement,
51+
py::arg("element"));
3852
}

python/wrapper/GConditionPyw.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef CGRAPH_GCONDITION_PYW_H
2+
#define CGRAPH_GCONDITION_PYW_H
3+
4+
#include <pybind11/pybind11.h>
5+
6+
#include "CGraph.h"
7+
8+
namespace py = pybind11;
9+
10+
class GConditionPyw : public CGraph::GCondition {
11+
public:
12+
explicit GConditionPyw() : CGraph::GCondition() {};
13+
~GConditionPyw() override {};
14+
15+
CIndex choose() override {
16+
PYBIND11_OVERLOAD_PURE(CIndex, GConditionPyw, choose);
17+
}
18+
19+
CStatus addGElement(CGraph::GElementPtr element) {
20+
return addElement(element);
21+
}
22+
};
23+
24+
#endif // CGRAPH_GCONDITION_PYW_H

python/wrapper/GElementPyw.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef CGRAPH_GELEMENTPY_H
2-
#define CGRAPH_GELEMENTPY_H
1+
#ifndef CGRAPH_GELEMENT_PYW_H
2+
#define CGRAPH_GELEMENT_PYW_H
33

44
#include <pybind11/pybind11.h>
55

@@ -14,4 +14,4 @@ class GElementPyw : public CGraph::GElement {
1414
}
1515
};
1616

17-
#endif // CGRAPH_GELEMENTPY_H
17+
#endif // CGRAPH_GELEMENT_PYW_H

python/wrapper/GNodePyw.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef CGRAPH_GNODEPY_H
2-
#define CGRAPH_GNODEPY_H
1+
#ifndef CGRAPH_GNODE_PYW_H
2+
#define CGRAPH_GNODE_PYW_H
33

44
#include <pybind11/pybind11.h>
55

@@ -9,21 +9,25 @@ namespace py = pybind11;
99

1010
class GNodePyw : public CGraph::GNode {
1111
protected:
12-
CStatus run() override {
13-
PYBIND11_OVERLOAD_PURE(CStatus, GNode, run);
14-
}
15-
1612
CStatus init() override {
1713
PYBIND11_OVERLOAD(CStatus, GNode, init);
1814
}
1915

16+
CStatus run() override {
17+
PYBIND11_OVERLOAD_PURE(CStatus, GNode, run);
18+
}
19+
2020
CStatus destroy() override {
2121
PYBIND11_OVERLOAD(CStatus, GNode, destroy);
2222
}
2323

2424
CBool isHold() override {
2525
PYBIND11_OVERLOAD(CBool, GNode, isHold);
2626
}
27+
28+
CBool isMatch() override {
29+
PYBIND11_OVERLOAD(CBool, GNode, isMatch);
30+
}
2731
};
2832

29-
#endif // CGRAPH_GNODEPY_H
33+
#endif // CGRAPH_GNODE_PYW_H

python/wrapper/GPipelinePy.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#ifndef CGRAPH_GPIPELINEPY_H
2-
#define CGRAPH_GPIPELINEPY_H
1+
#ifndef CGRAPH_GPIPELINE_PY_H
2+
#define CGRAPH_GPIPELINE_PY_H
33

44
#include "CGraph.h"
55

66
class GPipelinePy : public CGraph::GPipeline {
77
public:
88
explicit GPipelinePy() : CGraph::GPipeline() {}
9-
virtual ~GPipelinePy() {}
9+
~GPipelinePy() override {}
1010

1111
CStatus registerGElement(CGraph::GElementPtr element,
1212
const CGraph::GElementPtrSet &depends = CGraph::GElementPtrSet{},
@@ -16,4 +16,4 @@ class GPipelinePy : public CGraph::GPipeline {
1616
}
1717
};
1818

19-
#endif // CGRAPH_GPIPELINEPY_H
19+
#endif // CGRAPH_GPIPELINE_PY_H

python/wrapper/GRegionPy.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef CGRAPH_GREGION_PY_H
2+
#define CGRAPH_GREGION_PY_H
3+
4+
#include "CGraph.h"
5+
6+
class GRegionPy : public CGraph::GRegion {
7+
public:
8+
explicit GRegionPy() : CGraph::GRegion() {};
9+
~GRegionPy() override {};
10+
11+
CStatus addGElement(CGraph::GElementPtr element) {
12+
return addElement(element);
13+
}
14+
};
15+
16+
#endif // CGRAPH_GREGION_PY_H

python/wrapper/PyWrapperInclude.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#ifndef CGRAPH_PYWRAPPERINCLUDE_H
2-
#define CGRAPH_PYWRAPPERINCLUDE_H
1+
#ifndef CGRAPH_PYWRAPPER_INCLUDE_H
2+
#define CGRAPH_PYWRAPPER_INCLUDE_H
33

44
#include "GPipelinePy.h"
55
#include "GElementPyw.h"
66
#include "GNodePyw.h"
7+
#include "GRegionPy.h"
8+
#include "GConditionPyw.h"
79

8-
#endif // CGRAPH_PYWRAPPERINCLUDE_H
10+
#endif // CGRAPH_PYWRAPPER_INCLUDE_H

src/GraphCtrl/GraphElement/GElement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ class GElement : public GElementObject,
424424
CBool visible_ { true }; // 判定可见的,如果被删除的话,则认为是不可见的
425425
CBool is_init_ { false }; // 判断是否init
426426
GElementType element_type_ { GElementType::ELEMENT }; // 用于区分element 内部类型
427-
std::atomic<GElementState> cur_state_ { GElementState::CREATE }; // 当前执行状态
427+
std::atomic<GElementState> cur_state_ { GElementState::NORMAL }; // 当前执行状态
428428
internal::GElementShape shape_ { internal::GElementShape::NORMAL }; // 元素位置类型
429429

430430
/** 配置相关信息 */

src/GraphCtrl/GraphElement/GElementDefine.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ enum class GElementType {
3737

3838

3939
enum class GElementState {
40-
CREATE = 0x0000, // 创建状态(暂未init的情况,包含 destroy之后的情况)
41-
NORMAL = 0x1000, // 正常执行状态
40+
NORMAL = 0x0000, // 正常状态
4241
CANCEL = 0x1001, // 取消状态
4342
YIELD = 0x1002, // 暂停状态
4443
TIMEOUT = 0x1010, // 超时状态

0 commit comments

Comments
 (0)