@@ -86,6 +86,10 @@ export namespace StageSectionPackManager {
8686 */
8787 export function textNodeTreeToSection ( rootNode : TextNode ) : void {
8888 if ( ! GraphMethods . isTree ( rootNode ) ) {
89+ Dialog . show ( {
90+ title : "非树状结构" ,
91+ content : "请选择一个树状结构的节点作为根节点" ,
92+ } ) ;
8993 return ;
9094 }
9195 const dfs = ( node : TextNode ) : Section | TextNode => {
@@ -97,21 +101,27 @@ export namespace StageSectionPackManager {
97101 for ( const childNode of childNodes ) {
98102 const transEntity = dfs ( childNode ) ;
99103 childEntityList . push ( transEntity ) ;
100- // TODO: 断开主和子之间的连线
104+
105+ const edges = GraphMethods . getEdgesBetween ( node , childNode ) ;
106+ for ( const edge of edges ) {
107+ StageManager . deleteEdge ( edge ) ;
108+ }
101109 }
102- const section = targetTextNodeToSection ( node ) ;
110+ const section = targetTextNodeToSection ( node , true ) ;
103111
104112 StageSectionInOutManager . goInSection ( childEntityList , section ) ;
105113 return section ;
106114 } ;
107115 dfs ( rootNode ) ;
116+ StageHistoryManager . recordStep ( ) ;
108117 }
109118
110119 /**
111120 * 将指定的文本节点转换成Section
112- * @param textNode
121+ * @param textNode 要转换的节点
122+ * @param ignoreEdges 是否忽略边的影响
113123 */
114- export function targetTextNodeToSection ( textNode : TextNode ) : Section {
124+ export function targetTextNodeToSection ( textNode : TextNode , ignoreEdges : boolean = false ) : Section {
115125 // 获取这个节点的父级Section
116126 const fatherSections = SectionMethods . getFatherSections ( textNode ) ;
117127 const rect = textNode . collisionBox . getRectangle ( ) . expandFromCenter ( 50 ) ;
@@ -136,13 +146,15 @@ export namespace StageSectionPackManager {
136146 StageSectionInOutManager . goInSection ( [ newSection ] , fatherSection ) ;
137147 }
138148
139- // 将所有连向它的东西连到新的Section
140- for ( const fatherConnection of fatherConnections ) {
141- StageManager . connectEntity ( fatherConnection , newSection ) ;
142- }
143- // 将所有连向新的Section的东西连到它
144- for ( const childConnection of childConnections ) {
145- StageManager . connectEntity ( newSection , childConnection ) ;
149+ if ( ! ignoreEdges ) {
150+ // 将所有连向它的东西连到新的Section
151+ for ( const fatherConnection of fatherConnections ) {
152+ StageManager . connectEntity ( fatherConnection , newSection ) ;
153+ }
154+ // 将所有连向新的Section的东西连到它
155+ for ( const childConnection of childConnections ) {
156+ StageManager . connectEntity ( newSection , childConnection ) ;
157+ }
146158 }
147159 // 更新section的碰撞箱
148160 newSection . adjustLocationAndSize ( ) ;
0 commit comments