import { Tree } from "bp/content/context" ; import { Control } from "bp/design/class" ; import { ViewService } from "bp/env/service" ; import type { Sheet } from "./Sheet" ; import type { Vertex } from "./Vertex" ; import type { TreeEdge , TreeNode } from "bp/content/context" ; import type { JEdge } from "bp/content/json" ; /**
 *  Edge 是對應於樹狀結構中的  TreeEdge 的元件。
  @ shrewd export class Edge extends Control implements ISerializable < JEdge > { public get $type ( ) : string { return "Edge" ; } public get $tag ( ) : string { return "e" + this . $edge . $tag ; } public readonly $v1 : Vertex ; public readonly $v2 : Vertex ; public readonly $edge : TreeEdge ; constructor ( sheet , v1 , v2 , edge ) { super ( sheet ) ; this . $v1 = v1 ; this . $v2 = v2 ; this . $edge = edge ; ViewService . $createView ( this ) ; if ( sheet . $design . $options . get ( edge ) ?. selected ) this . $selected = true ; } protected get $shouldDispose ( ) : boolean { return super . $shouldDispose || this . $edge . $disposed ; } exports public split ( ) { this . _toVertex ( Tree . prototype . $split ) ; } exports public deleteAndMerge ( ) { if ( ! this . $edge . $isRiver ) return false ; this . _toVertex ( Tree . prototype . $deleteAndMerge ) ; return true ; } exports public get isRiver ( ) : boolean { return this . $edge . $isRiver ; } private _toVertex ( action ) { let l1 = this . $v1 . $location , l2 = this . $v2 . $location ; let x = Math . round ( ( l1 . x + l2 . x ) / 2 ) , y = Math . round ( ( l1 . y + l2 . y ) / 2 ) ; let node = action . apply ( this . $design . $tree , [ this . $edge ] ) ; this . $design . $options . set ( "v" + node . id , { id : node . id , name : node . name , x , y , selected : true , } ) ; } exports public get length ( ) : number { return this . $edge . length ; } public set length ( v ) { this . $edge . length = v ; } public toJSON ( ) { return this . $edge . toJSON ( ) ; } }