基本完成渲染雏形

This commit is contained in:
codeboss 2024-07-31 14:08:22 +08:00
parent 13642c2f06
commit 30574c9e1f
4 changed files with 57 additions and 39 deletions

View File

@ -7,9 +7,7 @@
<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/DAGPresent.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph/directed_acyclic_graph/DAGPresent.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/parse/StoryMap.py" beforeDir="false" afterPath="$PROJECT_DIR$/parse/StoryMap.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@ -1,9 +1,11 @@
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
from graph.directed_acyclic_graph.DAGPresent import DAGActiveView, Direction
from parse.StoryMap import StoryMap, FragmentSlice, XAST_ParseTool
from graph.DataType import Arrow, Point
import sys
from typing import Dict,List
from typing import Dict, List
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
from graph.DataType import Arrow, Point
from graph.directed_acyclic_graph.DAGPresent import DAGActiveView, Direction
from parse.StoryMap import StoryMap, XAST_ParseTool
from parse.ast_load import global_ast_path

View File

@ -27,7 +27,7 @@ class StoryNodeType(Enum):
FragmentNode = 1,
class StoryFragmentNode(QGraphicsItem, GraphNode):
class ActivePresentNode(QGraphicsItem, GraphNode):
"""
故事情节名称节点
"""
@ -112,24 +112,28 @@ class PenetrateNode(QGraphicsItem, GraphNode):
class TransitionCurve(QGraphicsItem):
def __init__(self, start: GraphNode, end: GraphNode, parent):
def __init__(self, start: GraphNode, end: GraphNode, prev_layrer_width:float, parent):
QGraphicsItem.__init__(self, parent)
self.start_node = start
self.end_node = end
self.prev_layer_w = prev_layrer_width
self.outline = QRectF()
self.data_bind: object = None
pass
def layout_refresh(self):
gpos = self.start_node.pos() + self.start_node.boundingRect().topRight()
self.setPos(gpos)
orect = self.start_node.boundingRect()
erect = self.end_node.boundingRect()
self.outline = QRectF(0, 0,
self.end_node.pos().x() - self.start_node.pos().x() - orect.width(),
self.end_node.pos().y() + erect.height() - self.start_node.pos().y())
pass
xpos = self.start_node.pos().x() + self.start_node.boundingRect().width()
width_value = self.end_node.pos().x() - self.start_node.pos().x() - orect.width()
ypos = min(self.start_node.pos().y(), self.end_node.pos().y())
bottom_y = max(self.start_node.pos().y() + orect.height(), self.end_node.pos().y() + erect.height())
self.setPos(xpos, ypos)
self.outline = QRectF(0, 0, width_value, bottom_y - ypos)
self.update()
def boundingRect(self):
return self.outline
@ -138,22 +142,31 @@ class TransitionCurve(QGraphicsItem):
def paint(self, painter, option, widget=...):
outline = self.outline
painter.save()
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
start_rect = self.start_node.boundingRect()
end_rect = self.end_node.boundingRect()
aj_start_pos = self.start_node.pos() + QPointF(start_rect.width(), start_rect.height()/2)
aj_end_pos = self.end_node.pos() + QPointF(0, end_rect.height()/2)
line_span = self.prev_layer_w - start_rect.width()
start_pos = QPointF(0, start_rect.height() / 2)
control_pos0 = start_pos + QPointF(outline.width()/3, 0)
end_pos = QPointF(outline.width(), outline.height() - end_rect.height() / 2)
control_pos1 = end_pos + QPointF(-outline.width()/3, 0)
painter.save()
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
#if aj_start_pos.y() < aj_end_pos.y():
start_pos = aj_start_pos - self.pos()
end_pos = aj_end_pos - self.pos()
line_epos = start_pos + QPointF(line_span, 0)
control_pos0 = line_epos + QPointF((outline.width() - line_span)/3, 0)
control_pos1 = end_pos - QPointF((outline.width() - line_span)/3, 0)
npen = QPen(Qt.black)
npen.setWidthF(4)
painter.setPen(npen)
painter.drawLine(start_pos, line_epos)
path0 = QPainterPath()
path0.moveTo(start_pos)
path0.moveTo(line_epos)
path0.cubicTo(control_pos0, control_pos1, end_pos)
painter.drawPath(path0)
@ -207,26 +220,26 @@ class DAGActiveView(QGraphicsView):
# 构建当前层节点
ypos_acc = 0
all_graphics_nodes = []
current_graphics_nodes = []
for node in current_level_nodes:
if node.is_fake_node():
curr_gnode = PenetrateNode(20, None)
curr_gnode.setPos(previous_node_end, ypos_acc)
curr_gnode.attach_data(node)
ypos_acc += curr_gnode.boundingRect().height()
all_graphics_nodes.append(curr_gnode)
current_graphics_nodes.append(curr_gnode)
self.scene_bind.addItem(curr_gnode)
else:
if node.layer_bind.bind_point().is_start:
curr_gnode = StoryFragmentNode(node.layer_bind.bind_point().point_name, StoryNodeType.StoryStartNode,
self.font(), None)
curr_gnode = ActivePresentNode(node.layer_bind.bind_point().point_name, StoryNodeType.StoryStartNode,
self.font(), None)
else:
curr_gnode = StoryFragmentNode(node.layer_bind.bind_point().point_name, StoryNodeType.FragmentNode,
self.font(), None)
curr_gnode = ActivePresentNode(node.layer_bind.bind_point().point_name, StoryNodeType.FragmentNode,
self.font(), None)
curr_gnode.attach_data(node)
curr_gnode.setPos(previous_node_end, ypos_acc)
ypos_acc += curr_gnode.boundingRect().height()
all_graphics_nodes.append(curr_gnode)
current_graphics_nodes.append(curr_gnode)
self.scene_bind.addItem(curr_gnode)
pass
@ -234,23 +247,28 @@ class DAGActiveView(QGraphicsView):
pass
# 调整同层节点宽度
width_max = 0
for n in all_graphics_nodes:
width_max = max(width_max, n.boundingRect().width())
curr_layer_width = 0
for n in current_graphics_nodes:
curr_layer_width = max(curr_layer_width, n.boundingRect().width())
pass
for n in all_graphics_nodes:
for n in current_graphics_nodes:
if hasattr(n, "resize_width"):
n.resize_width(width_max)
n.resize_width(curr_layer_width)
pass
pass
previous_node_end += width_max + self.layer_span
previous_node_end += curr_layer_width + self.layer_span
if len(previous_graphics_nodes) > 0:
for curr_gnode in all_graphics_nodes:
prev_layer_width = 0
for n in previous_graphics_nodes:
prev_layer_width = max(prev_layer_width, n.boundingRect().width())
pass
for curr_gnode in current_graphics_nodes:
sort_helper: DAGOrderHelper = curr_gnode.get_data()
for prev_gnode in previous_graphics_nodes:
if prev_gnode.get_data() in sort_helper.get_upstream_nodes():
line_cmbn = TransitionCurve(prev_gnode, curr_gnode, None)
line_cmbn = TransitionCurve(prev_gnode, curr_gnode, prev_layer_width,None)
self.scene_bind.addItem(line_cmbn)
line_cmbn.layout_refresh()
pass
@ -258,7 +276,7 @@ class DAGActiveView(QGraphicsView):
pass
pass
previous_graphics_nodes = all_graphics_nodes
previous_graphics_nodes = current_graphics_nodes
pass
pass