This commit is contained in:
codeboss 2024-08-01 08:57:25 +08:00
parent 74d7f05dca
commit bbcf0921ba
4 changed files with 49 additions and 29 deletions

View File

@ -7,9 +7,7 @@
<list default="true" id="f609c0f2-cd0d-4eea-87f1-8caf02d3f04f" name="Changes" comment=""> <list default="true" id="f609c0f2-cd0d-4eea-87f1-8caf02d3f04f" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/frame/ContentView.py" beforeDir="false" afterPath="$PROJECT_DIR$/frame/ContentView.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/frame/ContentView.py" beforeDir="false" afterPath="$PROJECT_DIR$/frame/ContentView.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/DataType.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph/DataType.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/directed_acyclic_graph/DAGLayout.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph/directed_acyclic_graph/DAGLayout.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/graph/directed_acyclic_graph/DAGLayout.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph/directed_acyclic_graph/DAGLayout.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/directed_acyclic_graph/DAGPresent.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph/directed_acyclic_graph/DAGPresent.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -37,30 +35,30 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"Python.CompareViews.executor": "Run", &quot;Python.CompareViews.executor&quot;: &quot;Run&quot;,
"Python.CompareWindow.executor": "Run", &quot;Python.CompareWindow.executor&quot;: &quot;Run&quot;,
"Python.ContentView.executor": "Run", &quot;Python.ContentView.executor&quot;: &quot;Run&quot;,
"Python.DAGGraph (1).executor": "Run", &quot;Python.DAGGraph (1).executor&quot;: &quot;Run&quot;,
"Python.DAGGraph.executor": "Run", &quot;Python.DAGGraph.executor&quot;: &quot;Run&quot;,
"Python.DAGLayout (1).executor": "Run", &quot;Python.DAGLayout (1).executor&quot;: &quot;Run&quot;,
"Python.DAGLayout.executor": "Run", &quot;Python.DAGLayout.executor&quot;: &quot;Run&quot;,
"Python.DAGPresent.executor": "Run", &quot;Python.DAGPresent.executor&quot;: &quot;Run&quot;,
"Python.MergeView.executor": "Run", &quot;Python.MergeView.executor&quot;: &quot;Run&quot;,
"Python.MileStone.executor": "Run", &quot;Python.MileStone.executor&quot;: &quot;Run&quot;,
"Python.NovelManage.executor": "Debug", &quot;Python.NovelManage.executor&quot;: &quot;Debug&quot;,
"Python.ReferView.executor": "Run", &quot;Python.ReferView.executor&quot;: &quot;Run&quot;,
"Python.StoryMap.executor": "Run", &quot;Python.StoryMap.executor&quot;: &quot;Run&quot;,
"Python.ast_load.executor": "Debug", &quot;Python.ast_load.executor&quot;: &quot;Debug&quot;,
"Python.entry.executor": "Run", &quot;Python.entry.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"git-widget-placeholder": "master", &quot;git-widget-placeholder&quot;: &quot;master&quot;,
"last_opened_file_path": "D:/Projects/Python/StoryCheckTools", &quot;last_opened_file_path&quot;: &quot;D:/Projects/Python/StoryCheckTools&quot;,
"settings.editor.selected.configurable": "reference.settings.ide.settings.new.ui" &quot;settings.editor.selected.configurable&quot;: &quot;reference.settings.ide.settings.new.ui&quot;
} }
}]]></component> }</component>
<component name="RunManager" selected="Python.ContentView"> <component name="RunManager" selected="Python.ContentView">
<configuration name="CompareViews" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="CompareViews" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="StoryTools" /> <module name="StoryTools" />

View File

@ -1,12 +1,12 @@
import sys import sys
from typing import Dict, List from typing import Dict, List
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QMainWindow
from PyQt5.QtWidgets import QMenu,QAction
from PyQt5.QtCore import QPoint from PyQt5.QtCore import QPoint
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtWidgets import QMenu
from graph.DataType import Arrow, Point from graph.DataType import Arrow, Point
from graph.directed_acyclic_graph.DAGPresent import DAGActiveView, Direction from graph.directed_acyclic_graph.DAGPresent import DAGActiveView
from parse.StoryMap import StoryMap, XAST_ParseTool from parse.StoryMap import StoryMap, XAST_ParseTool
from parse.ast_load import global_ast_path from parse.ast_load import global_ast_path

View File

@ -178,6 +178,21 @@ class DAGGraph:
return max_remains + 1 return max_remains + 1
def __node_layering_adj(self, inst: DAGLayerHelper):
if inst.input_count > 1:
return inst.layer_v - 1
if len(inst.next_nodes()) == 0:
return inst.layer_v - 1
layer_number = 2**32
for cinst in inst.next_nodes():
layer_number = min(layer_number, self.__node_layering_adj(cinst))
pass
inst.layer_v = layer_number
return inst.layer_v - 1
def __tidy_graph_nodes(self) -> List[DAGOrderHelper]: def __tidy_graph_nodes(self) -> List[DAGOrderHelper]:
nodes_temp: Dict[str, DAGOrderHelper] = {} nodes_temp: Dict[str, DAGOrderHelper] = {}
@ -236,8 +251,10 @@ class DAGGraph:
# 计算排序系数 # 计算排序系数
for target_node in target_nodes_within_layer: for target_node in target_nodes_within_layer:
prev_sorts = list(map(lambda n:n.sort_number, target_node.get_upstream_nodes())) prev_sorts = list(map(lambda n:n.sort_number, target_node.get_upstream_nodes()))
if len(prev_sorts) > 0:
target_node.sort_number = sum(prev_sorts)/len(prev_sorts) target_node.sort_number = sum(prev_sorts)/len(prev_sorts)
pass pass
pass
def compare_item(a: DAGOrderHelper): def compare_item(a: DAGOrderHelper):
return a.sort_number return a.sort_number
@ -277,6 +294,11 @@ class DAGGraph:
self.max_layer_count = max(self.max_layer_count, self.__node_layering(item)) self.max_layer_count = max(self.max_layer_count, self.__node_layering(item))
pass pass
pass pass
for item in sort_seqs:
if item.input_count ==0:
self.__node_layering_adj(item)
pass
pass
# 整理数据图节点 # 整理数据图节点
rich_nodes = self.__tidy_graph_nodes() rich_nodes = self.__tidy_graph_nodes()