WsParser_VS/StoryPresent/storypresent.cpp

56 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "storypresent.h"
#include <QFileInfo>
#include <QMessageBox>
using namespace dags;
using namespace xast_parse;
StoryPresent::StoryPresent(QWidget* parent)
: QMainWindow(parent), _story_present(new DAGActiveView(this))
{
setCentralWidget(_story_present);
}
StoryPresent::~StoryPresent()
{}
#include "xast_parse.h"
void StoryPresent::loadXAST(const QString& ast_path)
{
QFileInfo finfo(ast_path);
if (!finfo.exists() || !finfo.isFile()) {
QMessageBox::critical(this, u8"文件错误", QString(u8"指定文件(%1非法").arg(ast_path));
return;
}
xast_parse::XAST_Parser t(ast_path);
this->_story_graph = t.storyGraph();
QList<graph_data::Arrow> arrows;
for (auto& key : this->_story_graph.keys()) {
auto story_line = this->_story_graph[key];
auto arrow_start = story_line->name();
auto frag_temp = story_line->firstChild();
while (frag_temp) {
switch (frag_temp->type()) {
case SliceType::FragmentDefines: {
auto arrow_tail = std::dynamic_pointer_cast<FragmentDefine>(frag_temp)->name() + u8"@" + story_line->name();
arrows << graph_data::Arrow(arrow_start, arrow_tail);
arrow_start = arrow_tail;
}break;
case SliceType::FragmentRefers: {
auto conv_refer = std::dynamic_pointer_cast<FragmentRefer>(frag_temp);
auto arrow_tail = conv_refer->fragmentRefer() + u8"@" + conv_refer->storyRefer();
arrows << graph_data::Arrow(arrow_start, arrow_tail);
arrow_start = arrow_tail;
}break;
default: break;
}
frag_temp = frag_temp->nextSlice();
}
}
this->_story_present->updateWithEdges(arrows);
}