|
1 | 1 | import { Project, service } from "@/core/Project"; |
2 | 2 | import { RectangleTransformEffect } from "@/core/service/feedbackService/effectEngine/concrete/RectangleTransformEffect"; |
3 | 3 | import { ConnectableEntity } from "@/core/stage/stageObject/abstract/ConnectableEntity"; |
| 4 | +import { Edge } from "@/core/stage/stageObject/association/Edge"; |
4 | 5 | import { Section } from "@/core/stage/stageObject/entity/Section"; |
5 | 6 | import { Direction } from "@/types/directions"; |
6 | 7 | import { Vector } from "@graphif/data-structures"; |
@@ -225,6 +226,63 @@ export class SelectChangeEngine { |
225 | 226 | } |
226 | 227 | } |
227 | 228 |
|
| 229 | + /** |
| 230 | + * 扩散选择(节点和连线交替) |
| 231 | + * 正向:节点 -> 出边 -> 子节点 |
| 232 | + * 反向:节点 -> 入边 -> 父节点 |
| 233 | + */ |
| 234 | + expandSelectWithEdge(isKeepExpand = false, reversed: boolean = false) { |
| 235 | + if (!this.project.keyboardOnlyEngine.isOpenning()) { |
| 236 | + return; |
| 237 | + } |
| 238 | + |
| 239 | + const selectedEntities = this.project.stageManager |
| 240 | + .getSelectedEntities() |
| 241 | + .filter((entity) => entity instanceof ConnectableEntity); |
| 242 | + const selectedEdges = this.project.stageManager |
| 243 | + .getSelectedAssociations() |
| 244 | + .filter((association) => association instanceof Edge); |
| 245 | + |
| 246 | + if (selectedEntities.length === 0 && selectedEdges.length === 0) { |
| 247 | + return; |
| 248 | + } |
| 249 | + |
| 250 | + const nextEntities = new Set<ConnectableEntity>(); |
| 251 | + const nextEdges = new Set<Edge>(); |
| 252 | + |
| 253 | + if (reversed) { |
| 254 | + for (const selectedEntity of selectedEntities) { |
| 255 | + this.project.graphMethods.edgeParentArray(selectedEntity).map((edge) => nextEdges.add(edge)); |
| 256 | + } |
| 257 | + for (const selectedEdge of selectedEdges) { |
| 258 | + nextEntities.add(selectedEdge.source); |
| 259 | + } |
| 260 | + } else { |
| 261 | + for (const selectedEntity of selectedEntities) { |
| 262 | + this.project.graphMethods.edgeChildrenArray(selectedEntity).map((edge) => nextEdges.add(edge)); |
| 263 | + } |
| 264 | + for (const selectedEdge of selectedEdges) { |
| 265 | + nextEntities.add(selectedEdge.target); |
| 266 | + } |
| 267 | + } |
| 268 | + |
| 269 | + if (!isKeepExpand) { |
| 270 | + for (const selectedEntity of selectedEntities) { |
| 271 | + selectedEntity.isSelected = false; |
| 272 | + } |
| 273 | + for (const selectedEdge of selectedEdges) { |
| 274 | + selectedEdge.isSelected = false; |
| 275 | + } |
| 276 | + } |
| 277 | + |
| 278 | + for (const nextEntity of nextEntities) { |
| 279 | + nextEntity.isSelected = true; |
| 280 | + } |
| 281 | + for (const nextEdge of nextEdges) { |
| 282 | + nextEdge.isSelected = true; |
| 283 | + } |
| 284 | + } |
| 285 | + |
228 | 286 | private afterSelect( |
229 | 287 | selectedNodeRect: ConnectableEntity, |
230 | 288 | newSelectedConnectableEntity: ConnectableEntity | null, |
|
0 commit comments