Compare commits

...

2 Commits

Author SHA1 Message Date
codeboss b7f71fb29f update 2024-08-01 10:05:05 +08:00
codeboss bbcf0921ba update 2024-08-01 08:57:25 +08:00
4 changed files with 54 additions and 33 deletions

View File

@ -6,10 +6,7 @@
<component name="ChangeListManager">
<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$/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/DAGPresent.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph/directed_acyclic_graph/DAGPresent.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -37,30 +34,30 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Python.CompareViews.executor": "Run",
"Python.CompareWindow.executor": "Run",
"Python.ContentView.executor": "Run",
"Python.DAGGraph (1).executor": "Run",
"Python.DAGGraph.executor": "Run",
"Python.DAGLayout (1).executor": "Run",
"Python.DAGLayout.executor": "Run",
"Python.DAGPresent.executor": "Run",
"Python.MergeView.executor": "Run",
"Python.MileStone.executor": "Run",
"Python.NovelManage.executor": "Debug",
"Python.ReferView.executor": "Run",
"Python.StoryMap.executor": "Run",
"Python.ast_load.executor": "Debug",
"Python.entry.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master",
"last_opened_file_path": "D:/Projects/Python/StoryCheckTools",
"settings.editor.selected.configurable": "reference.settings.ide.settings.new.ui"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Python.CompareViews.executor&quot;: &quot;Run&quot;,
&quot;Python.CompareWindow.executor&quot;: &quot;Run&quot;,
&quot;Python.ContentView.executor&quot;: &quot;Run&quot;,
&quot;Python.DAGGraph (1).executor&quot;: &quot;Run&quot;,
&quot;Python.DAGGraph.executor&quot;: &quot;Run&quot;,
&quot;Python.DAGLayout (1).executor&quot;: &quot;Run&quot;,
&quot;Python.DAGLayout.executor&quot;: &quot;Run&quot;,
&quot;Python.DAGPresent.executor&quot;: &quot;Run&quot;,
&quot;Python.MergeView.executor&quot;: &quot;Run&quot;,
&quot;Python.MileStone.executor&quot;: &quot;Run&quot;,
&quot;Python.NovelManage.executor&quot;: &quot;Debug&quot;,
&quot;Python.ReferView.executor&quot;: &quot;Run&quot;,
&quot;Python.StoryMap.executor&quot;: &quot;Run&quot;,
&quot;Python.ast_load.executor&quot;: &quot;Debug&quot;,
&quot;Python.entry.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;last_opened_file_path&quot;: &quot;D:/Projects/Python/StoryCheckTools&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;reference.settings.ide.settings.new.ui&quot;
}
}]]></component>
}</component>
<component name="RunManager" selected="Python.ContentView">
<configuration name="CompareViews" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="StoryTools" />

View File

@ -1,12 +1,12 @@
import sys
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.QtWidgets import QApplication, QMainWindow
from PyQt5.QtWidgets import QMenu
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.ast_load import global_ast_path

View File

@ -1,5 +1,6 @@
from graph.DataType import Point, Arrow
from typing import List, Dict, Tuple
from math import floor,ceil
class DAGLayerHelper:
@ -178,6 +179,21 @@ class DAGGraph:
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]:
nodes_temp: Dict[str, DAGOrderHelper] = {}
@ -226,9 +242,10 @@ class DAGGraph:
if len(target_nodes_within_layer) == 0:
return
# 初始化节点排序
if layer_index == 0:
for idx in range(0, len(target_nodes_within_layer)):
target_nodes_within_layer[idx].sort_number = idx
target_nodes_within_layer[idx].sort_number = idx + 1
pass
pass
@ -236,7 +253,9 @@ class DAGGraph:
# 计算排序系数
for target_node in target_nodes_within_layer:
prev_sorts = list(map(lambda n:n.sort_number, target_node.get_upstream_nodes()))
target_node.sort_number = sum(prev_sorts)/len(prev_sorts)
if len(prev_sorts) > 0:
target_node.sort_number = sum(prev_sorts)/len(prev_sorts)
pass
pass
def compare_item(a: DAGOrderHelper):
@ -245,9 +264,9 @@ class DAGGraph:
# 整理节点排序
target_nodes_within_layer.sort(key=compare_item)
for idx in range(0, len(target_nodes_within_layer)):
target_nodes_within_layer[idx].sort_number = idx
target_item = target_nodes_within_layer[idx]
target_item.sort_number = idx + 1
pass
pass
self.__graph_layer_nodes_sort(layer_index + 1, nodes)
@ -277,6 +296,11 @@ class DAGGraph:
self.max_layer_count = max(self.max_layer_count, self.__node_layering(item))
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()