跳转至

Domain Layer - Planning Services

controller.domain.services.planning.motion_planning_domain_service

运动规划Domain服务

MotionPlanningDomainService

MotionPlanningDomainService()

运动规划Domain服务。

职责: 1. 管理多个方案(内存) 2. 维护当前激活的方案 3. 提供方案和节点的增删改查 4. 实施业务规则

属性:

名称 类型 描述
_plans List[MotionPlan]

方案列表。

_current_index int

当前激活方案的索引。

初始化服务。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
22
23
24
25
def __init__(self):
    """初始化服务。"""
    self._plans: List[MotionPlan] = []
    self._current_index: int = -1

initialize

initialize(plans: List[MotionPlan], current_index: int)

初始化数据(从Repository加载后调用)。

参数:

名称 类型 描述 默认
plans List[MotionPlan]

方案列表。

必需
current_index int

当前方案索引。

必需
源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
29
30
31
32
33
34
35
36
37
def initialize(self, plans: List[MotionPlan], current_index: int):
    """初始化数据(从Repository加载后调用)。

    Args:
        plans (List[MotionPlan]): 方案列表。
        current_index (int): 当前方案索引。
    """
    self._plans = plans
    self._current_index = current_index if plans else -1

get_all_plans

get_all_plans() -> List[MotionPlan]

获取所有方案(用于持久化)。

返回:

类型 描述
List[MotionPlan]

List[MotionPlan]: 方案列表的副本。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
39
40
41
42
43
44
45
def get_all_plans(self) -> List[MotionPlan]:
    """获取所有方案(用于持久化)。

    Returns:
        List[MotionPlan]: 方案列表的副本。
    """
    return self._plans.copy()

create_plan

create_plan(name: str) -> int

创建方案,返回索引。

参数:

名称 类型 描述 默认
name str

方案名称。

必需

返回:

名称 类型 描述
int int

新创建方案的索引。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
49
50
51
52
53
54
55
56
57
58
59
60
61
def create_plan(self, name: str) -> int:
    """创建方案,返回索引。

    Args:
        name (str): 方案名称。

    Returns:
        int: 新创建方案的索引。
    """
    plan = MotionPlan(name=name)
    self._plans.append(plan)
    self._current_index = len(self._plans) - 1
    return self._current_index

get_plan_names

get_plan_names() -> List[str]

获取所有方案名称(用于下拉框)。

返回:

类型 描述
List[str]

List[str]: 方案名称列表。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
63
64
65
66
67
68
69
def get_plan_names(self) -> List[str]:
    """获取所有方案名称(用于下拉框)。

    Returns:
        List[str]: 方案名称列表。
    """
    return [plan.name for plan in self._plans]

get_current_index

get_current_index() -> int

获取当前方案索引。

返回:

名称 类型 描述
int int

当前索引。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
71
72
73
74
75
76
77
def get_current_index(self) -> int:
    """获取当前方案索引。

    Returns:
        int: 当前索引。
    """
    return self._current_index

set_current_index

set_current_index(index: int) -> bool

切换方案。

参数:

名称 类型 描述 默认
index int

目标索引。

必需

返回:

名称 类型 描述
bool bool

是否切换成功。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
79
80
81
82
83
84
85
86
87
88
89
90
91
def set_current_index(self, index: int) -> bool:
    """切换方案。

    Args:
        index (int): 目标索引。

    Returns:
        bool: 是否切换成功。
    """
    if 0 <= index < len(self._plans):
        self._current_index = index
        return True
    return False

delete_plan

delete_plan(index: int) -> bool

删除方案。

业务规则:至少保留一个方案。

参数:

名称 类型 描述 默认
index int

方案索引。

必需

返回:

名称 类型 描述
bool bool

True=删除成功, False=删除失败(违反业务规则或索引无效)。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def delete_plan(self, index: int) -> bool:
    """删除方案。

    业务规则:至少保留一个方案。

    Args:
        index (int): 方案索引。

    Returns:
        bool: True=删除成功, False=删除失败(违反业务规则或索引无效)。
    """
    # 业务规则:至少保留一个方案
    if len(self._plans) <= 1:
        return False

    if 0 <= index < len(self._plans):
        self._plans.pop(index)
        # 调整当前索引
        if self._current_index >= len(self._plans):
            self._current_index = max(0, len(self._plans) - 1)
        if len(self._plans) == 0:
            self._current_index = -1
        return True
    return False

can_delete_plan

can_delete_plan() -> bool

检查是否可以删除方案。

返回:

名称 类型 描述
bool bool

True=可以删除, False=不能删除(只有一个方案)。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
118
119
120
121
122
123
124
def can_delete_plan(self) -> bool:
    """检查是否可以删除方案。

    Returns:
        bool: True=可以删除, False=不能删除(只有一个方案)。
    """
    return len(self._plans) > 1

rename_plan

rename_plan(index: int, new_name: str) -> bool

重命名方案。

参数:

名称 类型 描述 默认
index int

方案索引。

必需
new_name str

新名称。

必需

返回:

名称 类型 描述
bool bool

是否成功。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def rename_plan(self, index: int, new_name: str) -> bool:
    """重命名方案。

    Args:
        index (int): 方案索引。
        new_name (str): 新名称。

    Returns:
        bool: 是否成功。
    """
    if 0 <= index < len(self._plans):
        self._plans[index].name = new_name
        return True
    return False

get_current_plan

get_current_plan() -> Optional[MotionPlan]

获取当前方案。

返回:

类型 描述
Optional[MotionPlan]

Optional[MotionPlan]: 当前方案对象,无方案时返回 None。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
141
142
143
144
145
146
147
148
149
def get_current_plan(self) -> Optional[MotionPlan]:
    """获取当前方案。

    Returns:
        Optional[MotionPlan]: 当前方案对象,无方案时返回 None。
    """
    if 0 <= self._current_index < len(self._plans):
        return self._plans[self._current_index]
    return None

get_plan_count

get_plan_count() -> int

获取方案数量。

返回:

名称 类型 描述
int int

方案数量。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
151
152
153
154
155
156
157
def get_plan_count(self) -> int:
    """获取方案数量。

    Returns:
        int: 方案数量。
    """
    return len(self._plans)

add_point

add_point(point_data: dict)

添加节点到当前方案。

参数:

名称 类型 描述 默认
point_data dict

节点数据。

必需
源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
161
162
163
164
165
166
167
168
169
def add_point(self, point_data: dict):
    """添加节点到当前方案。

    Args:
        point_data (dict): 节点数据。
    """
    plan = self.get_current_plan()
    if plan:
        plan.add_point(point_data)

remove_point

remove_point(index: int)

删除节点。

参数:

名称 类型 描述 默认
index int

节点索引。

必需
源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
171
172
173
174
175
176
177
178
179
def remove_point(self, index: int):
    """删除节点。

    Args:
        index (int): 节点索引。
    """
    plan = self.get_current_plan()
    if plan:
        plan.remove_point(index)

move_point_up

move_point_up(index: int) -> bool

上移节点。

参数:

名称 类型 描述 默认
index int

节点索引。

必需

返回:

名称 类型 描述
bool bool

是否成功。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
181
182
183
184
185
186
187
188
189
190
191
def move_point_up(self, index: int) -> bool:
    """上移节点。

    Args:
        index (int): 节点索引。

    Returns:
        bool: 是否成功。
    """
    plan = self.get_current_plan()
    return plan.move_point_up(index) if plan else False

move_point_down

move_point_down(index: int) -> bool

下移节点。

参数:

名称 类型 描述 默认
index int

节点索引。

必需

返回:

名称 类型 描述
bool bool

是否成功。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
193
194
195
196
197
198
199
200
201
202
203
def move_point_down(self, index: int) -> bool:
    """下移节点。

    Args:
        index (int): 节点索引。

    Returns:
        bool: 是否成功。
    """
    plan = self.get_current_plan()
    return plan.move_point_down(index) if plan else False

update_point

update_point(index: int, point_data: dict)

更新节点。

参数:

名称 类型 描述 默认
index int

节点索引。

必需
point_data dict

新数据。

必需
源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
205
206
207
208
209
210
211
212
213
214
def update_point(self, index: int, point_data: dict):
    """更新节点。

    Args:
        index (int): 节点索引。
        point_data (dict): 新数据。
    """
    plan = self.get_current_plan()
    if plan:
        plan.update_point(index, point_data)

get_all_points

get_all_points() -> List[dict]

获取当前方案的所有节点。

返回:

类型 描述
List[dict]

List[dict]: 节点列表的副本。

源代码位于: src/controller/controller/domain/services/planning/motion_planning_domain_service.py
216
217
218
219
220
221
222
223
def get_all_points(self) -> List[dict]:
    """获取当前方案的所有节点。

    Returns:
        List[dict]: 节点列表的副本。
    """
    plan = self.get_current_plan()
    return plan.points.copy() if plan else []