基本完成渲染雏形

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=""> <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/DAGPresent.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph/directed_acyclic_graph/DAGPresent.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> </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" />

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 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 from parse.ast_load import global_ast_path

View File

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